63 lines
2.3 KiB
Lua
63 lines
2.3 KiB
Lua
local Action_RespiratoryRegurgitation = {
|
||
-- 可配置参数定义,参数将显示在Action配置面板
|
||
-- 例:
|
||
-- MyIntParameter = 0
|
||
AddHealthFrequency = 5;
|
||
ReplyPerSecond = 10.; -- 每一秒增加的血量
|
||
WaitAddHealthTime = 3.;
|
||
}
|
||
|
||
-- 触发器激活时,将执行Action的Execute
|
||
function Action_RespiratoryRegurgitation:Execute(...)
|
||
UGCEventSystem.AddListener(EventTypes.PlayerCause, self.PlayerVictim, self);
|
||
self.UpdateAddTime = 0.
|
||
self.PlayerVictimTime = {}
|
||
self.EnableAddHealth = true; -- 默认开启呼吸回血
|
||
UGCLogSystem.Log("[Action_RespiratoryRegurgitation_Execute]")
|
||
self.bEnableActionTick = true
|
||
return true
|
||
end
|
||
|
||
|
||
function Action_RespiratoryRegurgitation:Update(DeltaSeconds)
|
||
if not self.EnableAddHealth then
|
||
return;
|
||
end
|
||
self.UpdateAddTime = self.UpdateAddTime + DeltaSeconds
|
||
if self.UpdateAddTime >= (1. / self.AddHealthFrequency) then
|
||
self.UpdateAddTime = self.UpdateAddTime - 1. / self.AddHealthFrequency
|
||
self:AddPlayerHealth();
|
||
end
|
||
end
|
||
|
||
function Action_RespiratoryRegurgitation:PlayerVictim(Damage, IsKill, CauserKey, VictimKey)
|
||
self.PlayerVictimTime[VictimKey] = KismetSystemLibrary.GetGameTimeInSeconds(UGCGameSystem.GameState)
|
||
end
|
||
|
||
function Action_RespiratoryRegurgitation:AddPlayerHealth()
|
||
local AllPlayer = UGCGameSystem.GetAllPlayerPawn()
|
||
local NowTime = KismetSystemLibrary.GetGameTimeInSeconds(UGCGameSystem.GameState)
|
||
for k, Player in pairs(AllPlayer) do
|
||
if UE.IsValid(Player) and Player.PlayerKey ~= nil and Player:IsAlive() then
|
||
if self.PlayerVictimTime[Player.PlayerKey] == nil then
|
||
if NowTime - self.PlayerVictimTime[Player.PlayerKey] > self.WaitAddHealthTime then
|
||
UGCPawnAttrSystem.SetHealth(Player, Player.GetHealth(Player) + self.ReplyPerSecond / self.AddHealthFrequency);
|
||
end
|
||
end
|
||
end
|
||
end
|
||
end
|
||
|
||
-- 打断
|
||
function Action_RespiratoryRegurgitation:Interrupt(InTime)
|
||
self.EnableAddHealth = false; -- 不会被启动了
|
||
if InTime > 0 then
|
||
else
|
||
self.EnableAddHealth = false; -- 不会被启动了
|
||
UGCEventSystem.SetTimer(self, function()
|
||
self.EnableAddHealth = true; -- 隔这段时间之后会恢复
|
||
end, InTime);
|
||
end
|
||
end
|
||
|
||
return Action_RespiratoryRegurgitation |