UGCProjects/TrainingCamp/Script/gamemode/Action_AutoHealing.lua
2025-01-04 23:00:19 +08:00

59 lines
2.5 KiB
Lua
Raw 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 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)
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] = { StartTime = 0, } 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.StartTime + 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);
self.PlayerList[InjuryKey].StartTime = UE.GetServerTime() + self.InjuryDelay;
end
--[[
-- 需要勾选Action的EnableTick才会执行Update
-- 触发器激活后将在每个tick执行Action的Update直到self.bEnableActionTick为false
function Action_AutoHealing:Update(DeltaSeconds)
end
]]
return Action_AutoHealing