local BuffActionBase = require('Script.Global.BuffSystem.BuffActionBase') local BuffAction_BeFatedNotToDie = setmetatable( { -- Param --------------------------- -- 命不该绝次数上限 MaxCount = 1; -- 伤害修改函数的层级 ModifyDamageFuncLayer = 1e4; -- 触发回血比例 AddHealthPercentage = -1; -- 触发无敌时间 InvincibleTime = -1; -- Param End ----------------------- -- 已使用次数 UsedBuffCount = 0; }, { __index = BuffActionBase, __metatable = BuffActionBase } ); function BuffAction_BeFatedNotToDie:LuaDoAction() BuffActionBase.LuaDoAction(self) if not UGCGameSystem.IsServer() then return true end UGCLogSystem.Log("[BuffAction_BeFatedNotToDie_LuaDoAction]") self:GetOwnerPawn():AddDamageModifyFunc(self.BeFatedNotToDieFunc, self, self.ModifyDamageFuncLayer) end function BuffAction_BeFatedNotToDie:LuaUndoAction() BuffActionBase.LuaUndoAction(self) if not UGCGameSystem.IsServer() then return true end UGCLogSystem.Log("[BuffAction_BeFatedNotToDie_LuaUndoAction]") if UE.IsValid(self:GetOwnerPawn()) then self:GetOwnerPawn():RemoveDamageModifyFunc(self.BeFatedNotToDieFunc, self, self.ModifyDamageFuncLayer) end end function BuffAction_BeFatedNotToDie:LuaResetAction() BuffActionBase.LuaResetAction(self) self.UsedBuffCount = 0 end function BuffAction_BeFatedNotToDie:BeFatedNotToDieFunc(TargetPawn, DamageAmount, DamageType, EventInstigator, DamageCauser, Hit) if self.UsedBuffCount < self.MaxCount then local PlayerHealth = UGCPawnAttrSystem.GetHealth(TargetPawn) if PlayerHealth - DamageAmount < 1 then local OwnerPawn = self:GetOwnerPawn() if self:AddPlayerHealthPercentage(OwnerPawn) then DamageAmount = 0 else DamageAmount = PlayerHealth - 1 end self:AddInvincible(OwnerPawn) self.UsedBuffCount = self.UsedBuffCount + 1 UGCSendRPCSystem.RPCEvent(TargetPawn.PlayerKey, EventEnum.AddTip, TipConfig.TipType.BeFatedNotToDieOwner, self.UsedBuffCount) if EventInstigator and EventInstigator.PlayerKey then UGCSendRPCSystem.RPCEvent(EventInstigator.PlayerKey, EventEnum.AddTip, TipConfig.TipType.BeFatedNotToDieCauser) end end end return DamageAmount end function BuffAction_BeFatedNotToDie:AddPlayerHealthPercentage(TargetPawn) if self.AddHealthPercentage > 0 then if UE.IsValid(TargetPawn) then UGCPawnAttrSystem.SetHealth(TargetPawn, UGCPawnAttrSystem.GetHealthMax(TargetPawn) * self.AddHealthPercentage) end return true end return false end function BuffAction_BeFatedNotToDie:AddInvincible(TargetPawn) if self.InvincibleTime > 0 then UGCPawnSystem.SetIsInvincible(TargetPawn, true) UGCEventSystem.SetTimer(UGCGameSystem.GameState, function() if UE.IsValid(TargetPawn) then UGCPawnSystem.SetIsInvincible(TargetPawn, false) end end, self.InvincibleTime) end end return BuffAction_BeFatedNotToDie;