using System;
using System.Linq;
using Game.Plugins.App.Sync;
using Pathfinding;
using UnityEngine;
using Game.Script.battle.mode;
using Plugins.JNGame.Sync.Frame.game.Time;
using Plugins.JNGame.Util;

namespace Game.Script.battle.mode.GWorldSync01ModeScript
{
    public class PlayerBotInput
    {
        //移动
        public Boolean IsPos;
        public float x;
        public float y;
        public float z;
    }
    public class PlayerBot : JNGSyncFrame<PlayerBotInput>
    {

        //移动控制
        private AIDestinationSetter move;
        public long key;
        public Boolean isRobot = false;
        public Vector3 target;

        public override void OnSyncLoad()
        {
            base.OnSyncLoad();
            this.move = this.GetComponent<AIDestinationSetter>();
            //一秒中自动寻路
            SingletonUtil<JNFrameTime>.Instance.SetTimeout(() =>
            {
                if(this.isRobot)
                    this.SetTarget(new Vector3(GetSync().nRandomInt(-30,50),1,GetSync().nRandomInt(-60,20)));
            },1000);
        }

        //设置目标位置
        public void SetTarget(Vector3 pos)
        {
            this.target = pos;
            this.move.SetTarget(pos);
        }

        public override void OnSyncUpdate(int dt, JNFrameInfo frame, PlayerBotInput input)
        {
            base.OnSyncUpdate(dt, frame, input);
            if (input != null && input.IsPos)
            {
                //设置位置
                this.SetTarget(new Vector3(input.x,input.y,input.z));
            }
            
        }

    }
}
