UGCProjects/Counterattack/Script/Global/BuffSystem/BuffAction/BuffAction_RespiratoryRecovery.lua
2025-01-04 23:00:19 +08:00

66 lines
2.6 KiB
Lua
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

local BuffActionBase = require('Script.Global.BuffSystem.BuffActionBase')
local BuffAction_RespiratoryRecovery = setmetatable(
{
-- Param ---------------------------
-- 每秒恢复量
ReplyPerSecond = 10.;
-- 受击延迟恢复
WaitAddHealthTime = 3.;
-- Param End -----------------------
-- 恢复频率
AddHealthFrequency = 10;
UpdateAddTime = 0;
},
{ __index = BuffActionBase, __metatable = BuffActionBase }
);
function BuffAction_RespiratoryRecovery:LuaDoAction()
BuffActionBase.LuaDoAction(self)
if not UGCGameSystem.IsServer() then return true end
UGCLogSystem.Log("[BuffAction_RespiratoryRecovery_LuaDoAction]Params:%s, %s", self.ReplyPerSecond, self.WaitAddHealthTime)
-- 绑定Event传入的self可能有点问题需要与存储OwnerPawn才能获取到正确的OwnerPawn
UGCEventSystem.AddListener(EventEnum.PlayerInjuryInfo, self.PlayerInjuryInfo, self)
-- 启用Tick
self:EnableTick()
end
function BuffAction_RespiratoryRecovery:LuaUndoAction()
BuffActionBase.LuaUndoAction(self)
if not UGCGameSystem.IsServer() then return true end
UGCLogSystem.Log("[BuffAction_RespiratoryRecovery_LuaUndoAction]")
UGCEventSystem.RemoveListener(EventEnum.PlayerInjuryInfo, self.PlayerInjuryInfo, self)
end
function BuffAction_RespiratoryRecovery:LuaUpdateAction(DeltaSeconds)
BuffActionBase.LuaUpdateAction(self, 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 BuffAction_RespiratoryRecovery:PlayerInjuryInfo(VictimKey)
if UE.IsValid(self:GetOwnerPawn()) and self:GetOwnerPawn():IsAlive() then
if VictimKey == self:GetOwnerPawn().PlayerKey then
self.PlayerVictimTime = UGCSystemLibrary.GetGameTime()
UGCLogSystem.Log("[BuffAction_RespiratoryRecovery_PlayerInjuryInfo] Succeed")
end
end
end
function BuffAction_RespiratoryRecovery:AddPlayerHealth()
local NowTime = UGCSystemLibrary.GetGameTime()
if UE.IsValid(self:GetOwnerPawn()) and self:GetOwnerPawn():IsAlive()
and (self.PlayerVictimTime == nil or (NowTime - self.PlayerVictimTime >= self.WaitAddHealthTime)) then
UGCPawnAttrSystem.SetHealth(self:GetOwnerPawn(), UGCPawnAttrSystem.GetHealth(self:GetOwnerPawn()) + self.ReplyPerSecond / self.AddHealthFrequency)
end
end
return BuffAction_RespiratoryRecovery;