using XGame.Framework.Components; namespace FL.Battle { public interface IHpContext { IEntity Entity { get; } EEntityState State { get; set; } } internal class HpComponent : Component { public override int Order => 0; protected override void OnDispose() { } public int CalculateHit(int hitValue) { if (Context.State == EEntityState.Dead) { // 已经死亡 return 0; } var lastHp = Context.Entity.Attr.Hp; var nextHp = lastHp + hitValue; if (nextHp > Context.Entity.Attr.HpLimit) { nextHp = Context.Entity.Attr.HpLimit; } else if (nextHp < 0) { nextHp = 0; } Context.Entity.Attr.Hp = nextHp; if (nextHp == 0) { Context.State = EEntityState.Dead; } return (int)(nextHp - lastHp); } } }