57 lines
2.2 KiB
Lua
57 lines
2.2 KiB
Lua
|
local Action_AutoHealing = {
|
|||
|
-- 可配置参数定义,参数将显示在Action配置面板
|
|||
|
-- 例:
|
|||
|
-- MyIntParameter = 0
|
|||
|
InjuryDelay = 1;
|
|||
|
LimitPercent = 0.8;
|
|||
|
HealingNum = 12.5; -- 每秒钟回血量百分比
|
|||
|
HealingInterval = 0.3
|
|||
|
}
|
|||
|
|
|||
|
-- 触发器激活时,将执行Action的Execute
|
|||
|
function Action_AutoHealing:Execute(...)
|
|||
|
if DefaultSettings.EnableHealing then
|
|||
|
GlobalTickTool:AddTick(self, self.CustomTick, self.HealingInterval);
|
|||
|
-- 绑定伤害
|
|||
|
UGCEventSystem.AddListener(EventTypes.PlayerInjury, self.OnPlayerTakeDamage, self)
|
|||
|
--UGCEventSystem.AddListener(EventTypes.AddPlayer, self.OnAddPlayer, self)
|
|||
|
UGCEventSystem.AddListener(EventTypes.AddAutoHealing, self.OnAddPlayer, self)
|
|||
|
end
|
|||
|
return true
|
|||
|
end
|
|||
|
|
|||
|
function Action_AutoHealing:OnAddPlayer(InPlayerKey, InTeamID, IsAdd)
|
|||
|
if self.PlayerList == nil then self.PlayerList = {}; end
|
|||
|
if IsAdd then
|
|||
|
self.PlayerList[InPlayerKey] = UE.GetServerTime();
|
|||
|
else
|
|||
|
self.PlayerList[InPlayerKey] = nil;
|
|||
|
end
|
|||
|
UGCLogSystem.LogTree(string.format("[Action_AutoHealing:OnAddPlayer] self.PlayerList ="), self.PlayerList)
|
|||
|
end
|
|||
|
|
|||
|
--- 每 0.3 秒检测一次
|
|||
|
function Action_AutoHealing:CustomTick(dt, ServerTime)
|
|||
|
if not table.isEmpty(self.PlayerList) then
|
|||
|
for i, v in pairs(self.PlayerList) do
|
|||
|
--UGCLogSystem.Log("[Action_AutoHealing:CustomTick] 执行, ServerTime = %f, PlayerKey = %s", ServerTime, tostring(i));
|
|||
|
local Pawn = UGCGameSystem.GetPlayerPawnByPlayerKey(i);
|
|||
|
local CurrHealth = UGCPawnAttrSystem.GetHealth(Pawn);
|
|||
|
local MaxHealth = UGCPawnAttrSystem.GetHealthMax(Pawn);
|
|||
|
local TargetHealth = MaxHealth * self.LimitPercent;
|
|||
|
if Pawn and v + self.InjuryDelay <= ServerTime and CurrHealth <= TargetHealth then
|
|||
|
local Health = math.clamp(self.HealingNum * 0.01 * self.HealingInterval * MaxHealth + CurrHealth, 0, TargetHealth)
|
|||
|
UGCLogSystem.Log("[BuffAction_AutoHealing:CustomTick] Health = %f", Health);
|
|||
|
UGCPawnAttrSystem.SetHealth(Pawn, Health);
|
|||
|
end
|
|||
|
end
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
function Action_AutoHealing:OnPlayerTakeDamage(InjuryKey, CauserKey, Damage)
|
|||
|
UGCLogSystem.Log("[Action_AutoHealing:OnPlayerTakeDamage] Injury = %s", InjuryKey);
|
|||
|
if self.PlayerList[InjuryKey] == nil then return; end
|
|||
|
self.PlayerList[InjuryKey] = UE.GetServerTime() + self.InjuryDelay;
|
|||
|
end
|
|||
|
|
|||
|
return Action_AutoHealing
|