74 lines
3.1 KiB
Lua
74 lines
3.1 KiB
Lua
|
local Buff_RespiratoryRecovery = {
|
|||
|
AddHealthFrequency = 5;
|
|||
|
ReplyPerSecond = 10.;
|
|||
|
WaitAddHealthTime = 3.;
|
|||
|
UpdateAddTime = 0;
|
|||
|
};
|
|||
|
-- Script.Blueprint.UGCBuffs.BuffAction.Buff_RespiratoryRecovery
|
|||
|
function Buff_RespiratoryRecovery:LuaDoAction()
|
|||
|
if not UGCGameSystem.IsServer() then return true end
|
|||
|
UGCLogSystem.Log("[Buff_RespiratoryRecovery_LuaDoAction]Params:%s, %s, %s", self.Params[1], self.Params[2], self.Params[3])
|
|||
|
|
|||
|
-- 初始化参数
|
|||
|
self.AddHealthFrequency = tonumber(self.Params[1]); -- 恢复频率
|
|||
|
self.ReplyPerSecond = tonumber(self.Params[2]); -- 每秒回复
|
|||
|
self.WaitAddHealthTime = tonumber(self.Params[3]); -- 受伤等待恢复时间
|
|||
|
self.OwnerPawn = self:GetOwnerPawn()
|
|||
|
|
|||
|
if UE.IsValid(self.OwnerPawn) and self.OwnerPawn:IsAlive() then
|
|||
|
UGCLogSystem.Log("[Buff_RespiratoryRecovery_LuaDoAction] IsValid")
|
|||
|
end
|
|||
|
|
|||
|
-- 绑定Event传入的self可能有点问题,需要与存储OwnerPawn才能获取到正确的OwnerPawn
|
|||
|
UGCEventSystem.AddListener(EventEnum.PlayerInjuryInfo, self.PlayerInjuryInfo, self)
|
|||
|
--local Causer = self:GetBuffCauserActor()
|
|||
|
--if Causer then
|
|||
|
-- UGCLogSystem.Log("[Buff_RespiratoryRecovery_LuaDoAction] Succeed")
|
|||
|
--else
|
|||
|
-- UGCLogSystem.Log("[Buff_RespiratoryRecovery_LuaDoAction] Failure")
|
|||
|
--end
|
|||
|
return true
|
|||
|
end
|
|||
|
|
|||
|
function Buff_RespiratoryRecovery:LuaUndoAction()
|
|||
|
if not UGCGameSystem.IsServer() then return true end
|
|||
|
UGCLogSystem.Log("[Buff_RespiratoryRecovery_LuaUndoAction]")
|
|||
|
UGCEventSystem.RemoveListener(EventEnum.PlayerInjuryInfo, self.PlayerInjuryInfo, self)
|
|||
|
return true
|
|||
|
end
|
|||
|
|
|||
|
function Buff_RespiratoryRecovery:LuaResetAction()
|
|||
|
UGCLogSystem.Log("[Buff_RespiratoryRecovery_LuaResetAction]")
|
|||
|
return true
|
|||
|
end
|
|||
|
|
|||
|
function Buff_RespiratoryRecovery:LuaUpdateAction(DeltaSeconds)
|
|||
|
if not UGCGameSystem.IsServer() then return true end
|
|||
|
self.UpdateAddTime = self.UpdateAddTime + DeltaSeconds
|
|||
|
if self.UpdateAddTime >= (1. / self.AddHealthFrequency) then
|
|||
|
self.UpdateAddTime = self.UpdateAddTime - 1. / self.AddHealthFrequency
|
|||
|
self:AddPlayerHealth()
|
|||
|
end
|
|||
|
return true
|
|||
|
end
|
|||
|
|
|||
|
function Buff_RespiratoryRecovery:PlayerInjuryInfo(VictimKey)
|
|||
|
if UE.IsValid(self.OwnerPawn) and self.OwnerPawn:IsAlive() then
|
|||
|
UGCLogSystem.Log("[Buff_RespiratoryRecovery_PlayerInjuryInfo] VictimKey:%s, OwnerPlayerKey:%s",tostring(VictimKey), tostring(self.OwnerPawn.PlayerKey))
|
|||
|
if VictimKey == self.OwnerPawn.PlayerKey then
|
|||
|
self.PlayerVictimTime = UGCSystemLibrary.GetGameTime()
|
|||
|
UGCLogSystem.Log("[Buff_RespiratoryRecovery_PlayerInjuryInfo] Succeed")
|
|||
|
end
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
function Buff_RespiratoryRecovery:AddPlayerHealth()
|
|||
|
local NowTime = UGCSystemLibrary.GetGameTime()
|
|||
|
local PlayerPawn = self:GetOwnerPawn()
|
|||
|
if UE.IsValid(PlayerPawn) and PlayerPawn:IsAlive()
|
|||
|
and (self.PlayerVictimTime == nil or (NowTime - self.PlayerVictimTime >= self.WaitAddHealthTime)) then
|
|||
|
UGCPawnAttrSystem.SetHealth(PlayerPawn, UGCPawnAttrSystem.GetHealth(PlayerPawn) + self.ReplyPerSecond / self.AddHealthFrequency)
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
return Buff_RespiratoryRecovery;
|