using FL.Battle;
using FL.Battle.Components;
using Spine.Unity;
using UnityEngine;
using XGame.Framework.Map;
using XGame.Framework.ObjectCollection;

namespace FL.Map
{
    public class PlayerEntityView : BattleEntityView<PlayerEntityVM>, ISkillContext, ISpineContext, IVfxContext, IStatesContext
    {
        public override Transform UIPoint => VM.UIPoint;
        protected override EEntityType DefaultTargetType => EEntityType.Monster;
        //public void FindTarget(int skillId)
        //{
        //    Selector.FindAsync(this, EEntityType.Monster, (target) =>
        //    {
        //        SelectTarget(target, skillId);
        //    });
        //}
        public IAnimator Animator => GetComponent<SpineComponent>();
        #region ISkillContext
        Transform ISkillContext.ActionRoot => VM.ActionRoot;
        #endregion
        #region ISpineContext
        SkeletonAnimation ISpineContext.Skeleton => VM.PlayerSkeleton;
        #endregion
        #region IVfxContext
        Transform IVfxContext.WorldTr => null;
        Transform IVfxContext.CenterTr => VM.Tr;
        Transform IVfxContext.CastTr => VM.VfxRoot;
        #endregion
        public override EpigraphicsComponent Epigraphics => null;
    }
    public class PlayerEntityVM : EntityViewModel
    {
        public Transform ActionRoot { get; private set; }
        public SkeletonAnimation PlayerSkeleton { get; private set; }
        public Transform VfxRoot { get; private set; }
        public Transform UIPoint { get; private set; }
        protected override void OnInit(IObjectCollector collector)
        {
            ActionRoot = collector.GetGameObject("ActionRoot").transform;
            PlayerSkeleton = collector.GetComponent<SkeletonAnimation>("PlayerSkeleton");
            VfxRoot = collector.GetGameObject("VfxRoot").transform;
            UIPoint = collector.GetGameObject("UIPoint").transform;
        }
    }
}