You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
2.2 KiB
60 lines
2.2 KiB
1 month ago
|
using System;
|
||
|
using CoreGame;
|
||
|
using GAS.Runtime;
|
||
|
|
||
|
namespace CoreGame.Render
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// 护盾组件
|
||
|
/// </summary>
|
||
|
[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<TriggerSpec>.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<TriggerSpec>.Free(ref partSelf.triggerSpec);
|
||
|
}
|
||
|
}
|
||
|
}
|