using CommonAI.Zone;
using ET.Client;
using ET.EventType;

namespace ET
{
    [Event(SceneType.None)]
    public class BattleFuncHandler : BEvent<BattleFunc>
    {
        public override void OnEvent(BattleFunc a)
        {
            Log.Debug($"Battle Func:{a.FuncIndex}");
            asyncHandler(a.FuncIndex).Coroutine();
        }
        private async ETTask asyncHandler(BattleFunc.Index index)
        {
            var session = PlayerComponent.Instance.ClientScene().GetComponent<SessionComponent>().Session;
            switch (index)
            {
                case BattleFunc.Index.Func2:
                    var ret = await session.Call(new C2G_AddUnitsToMap()
                    {
                        UnitId = 102,
                        Force = 1,
                        X = 2,
                        Y = 30
                    });

                    if (ret.Error != 0)
                    {
                        Log.Error(ret.Message);
                    }
                    break;
                default:
                    break;
            }
        }
    }

    //发送战斗服指令相关
    public partial class BattleMgr
    {
        private bool autoFight;
        public bool AutoFight
        {
            get
            {
                return autoFight;
            }
            set
            {
                if(value == autoFight) return;
                else
                {
                    autoFight = value;
                }
            }
        }

        public CommonAI.Zone.Action SetAutoFight(bool flag)
        {
            return new UnitGuardAction(UnitMgr.Instance.ActorId, flag, CommonAI.XmdsConstConfig.AUTO_GUARD_MODE_POINT);
        }
    }

}