using FL.Battle; using FL.Battle.Components; using FL.Battle.Components.AI; using System; using UnityEngine; using XGame.Framework.Map; using XGame.Framework.Time; namespace FL.Map { /// /// 玩家、随从、怪物等有IEntity的战斗对象基类 /// /// public abstract class BattleEntityView : EntityView, IMoveContext, IBuffsContext, ICombatContext, IBattleEntityAIContext, ITarget where TViewModel : EntityViewModel { public IMapAssetModule Asset => Context.Asset; public ITimeModule Time => Context.Time; private IEntity _entity; public IEntity Entity { get => _entity; set { _entity = value; LocalPosition = value?.BirthPosition ?? Vector3.zero; States.Reset(); } } public bool IsDead => _entity.IsDead; #region 状态 //private ITimer _deadTimer; //public EEntityState State //{ // get => _entity.State; // set // { // if (value != EEntityState.Idle && value == _entity.State) // { // return; // } // if (_entity.State == EEntityState.Dead) // { // 已经死亡,不能再修改状态 // return; // } // _entity.State = value; // //VM.StateText.text = value.ToString(); // //Animation // if (value == EEntityState.Dead) // { // //TODO 死亡动作 停止所有组件 // _deadTimer = Context.Time.AddDelayTimer(500, () => // { // 死亡事件通知 // _deadTimer = null; // EventSingle.Instance.Notify(EventDefine.GameMainMapRemoveEntity, _entity.EntityId); // }); // } // OnStateChanged(); // } //} //protected abstract void OnStateChanged(); #endregion #region IMoveContext public bool IsMoving => Move.IsMoving; public Transform OwnerTr => VM.Tr; #endregion #region 目标选择 public abstract Transform UIPoint { get; } /// /// 默认的目标类型 /// protected abstract EEntityType DefaultTargetType { get; } public ITargetSelector Selector { get; set; } public void FindTargetAsync(Action onSelected) { Selector.FindAsync(this, DefaultTargetType, ETargetFindType.Nearest, onSelected); } #endregion #region 组件 public VfxComponent Vfx => GetComponent(); public MoveComponent Move => GetComponent(); public SkillComponent Skill => GetComponent(); public BuffsComponent Buffs => GetComponent(); public BattleEntityAI CommonAI => GetComponent(); public StatesComponent States => GetComponent(); public ICombatCalculation Calculation => GetComponent(); public abstract EpigraphicsComponent Epigraphics { get; } #endregion protected override void OnEnable(object intent) { } protected override void OnDisable() { Selector = null; } /// /// 重置状态 /// /// 是否只重置Component public void Reset(bool isOnlyComponent = false) { Group.Reset(); //States.State = EEntityState.Idle; if (isOnlyComponent) return; LocalPosition = _entity.BirthPosition; } } }