81 lines
3.6 KiB
Lua
81 lines
3.6 KiB
Lua
|
BondManager = BondManager or {}
|
|||
|
-- 校验频率
|
|||
|
BondManager.FPS = 2
|
|||
|
-- 是否已激活
|
|||
|
BondManager.Activated = false
|
|||
|
-- 血量同步的百分比,存在大于这个百分比的队友且都未倒地时,双方同步血量
|
|||
|
BondManager.SynchronizedPercentageOfBloodVolume = 0.3
|
|||
|
-- 自动救援血量
|
|||
|
BondManager.AutoRescueHealth = 0.7 - 1e-2
|
|||
|
|
|||
|
|
|||
|
-- 激活函数
|
|||
|
function BondManager.ActiveBondSystem()
|
|||
|
if BondManager.Activated then return end
|
|||
|
BondManager.Activated = true
|
|||
|
if BondManager.BondUpdateHandle == nil then
|
|||
|
BondManager.BondUpdateHandle = UGCEventSystem.SetTimerLoop(UGCGameSystem.GameState, BondManager.Update, 1./BondManager.FPS)
|
|||
|
UGCLogSystem.Log("[BondManager_ActiveBondSystem] Finish")
|
|||
|
end
|
|||
|
end
|
|||
|
-- 暂停函数
|
|||
|
function BondManager.StopBondSystem()
|
|||
|
if not BondManager.Activated then return end
|
|||
|
BondManager.Activated = false
|
|||
|
if BondManager.BondUpdateHandle then
|
|||
|
UGCEventSystem.StopTimer(BondManager.BondUpdateHandle)
|
|||
|
BondManager.BondUpdateHandle = nil
|
|||
|
UGCLogSystem.Log("[BondManager_StopBondSystem] Finish")
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
-- 更新函数
|
|||
|
function BondManager.Update()
|
|||
|
local TeamIDs = UGCTeamSystem.GetTeamIDs()
|
|||
|
for i, TeamID in pairs(TeamIDs) do
|
|||
|
BondManager.BondFromTeamID(TeamID)
|
|||
|
end
|
|||
|
end
|
|||
|
-- 队伍羁绊触发,仅2人队伍生效
|
|||
|
function BondManager.BondFromTeamID(InTeamID)
|
|||
|
local TeamPlayers = UGCGameSystem.GameState:GetTeamPlayer(InTeamID)
|
|||
|
-- 不为2人队伍则不处理
|
|||
|
if table.getCount(TeamPlayers) ~= 2 then return end
|
|||
|
local Pawn1 = UGCGameSystem.GetPlayerPawnByPlayerKey(TeamPlayers[1])
|
|||
|
local Pawn2 = UGCGameSystem.GetPlayerPawnByPlayerKey(TeamPlayers[2])
|
|||
|
-- 判有效
|
|||
|
if not UE.IsValid(Pawn1) or not UE.IsValid(Pawn2) then return end
|
|||
|
-- 判存活
|
|||
|
if not Pawn1:IsAlive() or not Pawn2:IsAlive() then return end
|
|||
|
|
|||
|
-- 获取两个玩家的信息
|
|||
|
local PawnHealth1 = UGCPawnAttrSystem.GetHealth(Pawn1)
|
|||
|
local PawnHealth2 = UGCPawnAttrSystem.GetHealth(Pawn2)
|
|||
|
local PawnMaxHealth1 = UGCPawnAttrSystem.GetHealthMax(Pawn1)
|
|||
|
local PawnMaxHealth2 = UGCPawnAttrSystem.GetHealthMax(Pawn2)
|
|||
|
local PawnHasDying1 = UGCPawnSystem.HasPawnState(Pawn1, EPawnState.Dying)
|
|||
|
local PawnHasDying2 = UGCPawnSystem.HasPawnState(Pawn2, EPawnState.Dying)
|
|||
|
local HealthPercentage1 = PawnHealth1 / PawnMaxHealth1
|
|||
|
local HealthPercentage2 = PawnHealth2 / PawnMaxHealth2
|
|||
|
|
|||
|
|
|||
|
|
|||
|
if not PawnHasDying1 and not PawnHasDying2 then
|
|||
|
-- 同步血量
|
|||
|
if (HealthPercentage1 > BondManager.SynchronizedPercentageOfBloodVolume or HealthPercentage2 > BondManager.SynchronizedPercentageOfBloodVolume) and math.abs(PawnHealth1 - PawnHealth2) > 1 then
|
|||
|
local TargetHealth = (PawnHealth1 + PawnHealth2) / 2
|
|||
|
UGCPawnAttrSystem.SetHealth(Pawn1, TargetHealth)
|
|||
|
UGCPawnAttrSystem.SetHealth(Pawn2, TargetHealth)
|
|||
|
UGCLogSystem.Log("[BondManager_BondFromTeamID] 同步血量 PawnHealth1:%s, PawnHealth2:%s, TargetHealth:%s", tostring(PawnHealth1), tostring(PawnHealth2), tostring(TargetHealth))
|
|||
|
end
|
|||
|
elseif PawnHasDying1 ~= PawnHasDying2 then
|
|||
|
-- 自动救援
|
|||
|
if PawnHasDying1 and HealthPercentage2 >= BondManager.AutoRescueHealth then
|
|||
|
UGCLogSystem.Log("[BondManager_BondFromTeamID] 自动救援玩家:%s", tostring(TeamPlayers[1]))
|
|||
|
Pawn1:GetCharacterRescueOtherComponent():RescueSucImmediately(Pawn1, 1)
|
|||
|
elseif PawnHasDying2 and HealthPercentage1 >= BondManager.AutoRescueHealth then
|
|||
|
UGCLogSystem.Log("[BondManager_BondFromTeamID] 自动救援玩家:%s", tostring(TeamPlayers[2]))
|
|||
|
Pawn2:GetCharacterRescueOtherComponent():RescueSucImmediately(Pawn2, 1)
|
|||
|
end
|
|||
|
end
|
|||
|
end
|