using System; using CoreGame; using GAS.Runtime; namespace CoreGame.Render { /// /// 护盾组件 /// [Serializable] public class GEComponent_HpShield : GameplayEffectComponent { public void OnWillChangeHp(object self, int eventId, object arg1) { var partSelf = (GameplayEffectComponentSpec)self; var hurtData = (HurtData)arg1; if ((hurtData.hurtRet & HurtRet.Miss) == HurtRet.Miss) return; if (hurtData.hpShieldAcc >= 0) return; var geSpec = partSelf.GESpec; var hangMagnitude = (long)(geSpec.hangMagnitude + hurtData.hpShieldAcc); geSpec.hangMagnitude = hangMagnitude; if (hangMagnitude <= 0) { hurtData.hpShieldAcc = (long)geSpec.hangMagnitude; geSpec.hangMagnitude = 0;// ??? hurtData.hurtRet |= HurtRet.ShieldBreak; // 清除护盾 geSpec.RemoveSelf(); var entity = geSpec.Owner.owner; if (entity.hasRefreshableHpShield) { entity.AddReload(entity.refreshableHpShield.refreshInterval); } } else { hurtData.hpShieldAcc = 0; } } public override void OnGameplayEffectApplied(GameplayEffectComponentSpec partSelf, GameplayEffectSpec GESpec) { var triggerSpec = SptPool.Malloc(); triggerSpec.Awake(null, GESpec); partSelf.triggerSpec = triggerSpec; triggerSpec.callbackWrapper = CallbackWrapper.New(OnWillChangeHp, partSelf); triggerSpec.owner.AddEventCallBack(ClientEvent.OnReduceHpShield, triggerSpec.callbackWrapper); } public override void OnGameplayEffectDisApplied(GameplayEffectComponentSpec partSelf, GameplayEffectSpec GESpec) { partSelf.triggerSpec.owner.RemoveCallback(ClientEvent.OnReduceHpShield, ref partSelf.triggerSpec.callbackWrapper); SptPool.Free(ref partSelf.triggerSpec); } } }