using System.Collections.Generic;
using Fantasy;
using Fantasy.Async;
using NBF.Fishing2;
using RootMotion.FinalIK;
using Log = NBC.Log;

namespace NBF
{
    public class Fishing
    {
        public FPlayer Player { get; private set; }
        private static Fishing _instance;

        public static Fishing Instance
        {
            get
            {
                _instance ??= new Fishing();

                return _instance;
            }
        }


        public async FTask<bool> Go(int mapId, string roomCode = "")
        {
            if (mapId == 0)
            {
                Log.Warning("账号没有进入过地图，进入新手引导地图");
                mapId = 99;
            }

            var response = (G2C_EnterMapResponse)await Net.Call(new C2G_EnterMapRequest()
            {
                MapId = mapId,
                RoomCode = roomCode
            });
            Log.Info($"进入地图请求返回={response.ErrorCode}");
            LoadingPanel.Show();
            await ChangeMap(response.MapId, response.RoomCode, response.Units);
            LoadingPanel.Hide();
            return true;
        }


        public async FTask ChangeMap(int mapId, string roomCode, List<MapUnitInfo> units)
        {
            var sceneName = "Map1";
            //加载场景==
            await SceneHelper.LoadScene(sceneName);
            CreateUnit();
        }


        private void CreateUnit()
        {
            var gameObject = PrefabsHelper.CreatePlayer(SceneSettings.Instance.Node);
            Player = gameObject.GetComponent<FPlayer>();
            CameraManager.Instance.Mode = CameraShowMode.FPP;
        }
    }
}