using System.Collections.Generic;
using Unity.Mathematics;
using UnityEngine;
using Random = UnityEngine.Random;

namespace NBF
{
    /// <summary>
    /// 钓鱼数据源基类
    /// </summary>
    public class FishingDatasource
    {
        public readonly Dictionary<int, FPlayerData> Players = new Dictionary<int, FPlayerData>();

        public void Init()
        {
            for (int i = 0; i < 1; i++)
            {
                var p = GetTestPlayer(i);
                AddPlayer(p);
            }
        }

        public void Update()
        {
            
        }

        public void AddPlayer(FPlayerData player)
        {
            Players[player.PlayerID] = player;
        }

        public FPlayerData GetPlayer(int playerID)
        {
            return Players.GetValueOrDefault(playerID);
        }

        public FPlayerData GetSelfPlayer()
        {
            return GetPlayer(GameModel.RoleID);
        }


        #region 测试数据

        public void SetSelfTestGear(int slot)
        {
            var player = GetSelfPlayer();
            if (player != null)
            {
                player.currentGear = new FPlayerGearData();
                var gear = player.currentGear;

                if (slot == 1)
                {
                    player.lineLength = 3.6f;
                    gear.Type = GearType.Pole;
                    gear.rod = new FRodData()
                    {
                        id = Random.Range(1, 100000),
                        configId = 100001,
                    };
                    gear.line = new FLineData()
                    {
                        id = Random.Range(1, 100000),
                        configId = 400001
                    };
                    gear.bobber = new FBobberData()
                    {
                        id = Random.Range(1, 100000),
                        configId = 300001
                    };
                    gear.hook = new FHookData()
                    {
                        id = Random.Range(1, 100000),
                        configId = 700001
                    };
                    gear.bait = new FBaitData()
                    {
                        id = Random.Range(1, 100000),
                        configId = 500002
                    };
                    gear.weight = new FWeightData()
                    {
                        id = Random.Range(1, 100000),
                        configId = 800001
                    };
                    gear.reel = null;
                }
                else if (slot == 2)
                {
                    player.lineLength = 0.4f;
                    gear.Type = GearType.SpinningFloat;
                    gear.rod = new FRodData()
                    {
                        id = Random.Range(1, 100000),
                        configId = 100002
                    };
                    gear.reel = new FReelData()
                    {
                        id = Random.Range(1, 100000),
                        configId = 200001
                    };
                    gear.line = new FLineData()
                    {
                        id = Random.Range(1, 100000),
                        configId = 400001
                    };
                    gear.bait = new FBaitData()
                    {
                        id = Random.Range(1, 100000),
                        configId = 500002
                    };
                    gear.bobber = new FBobberData()
                    {
                        id = Random.Range(1, 100000),
                        configId = 300001
                    };
                    gear.hook = new FHookData()
                    {
                        id = Random.Range(1, 100000),
                        configId = 700001
                    };
                    gear.weight = new FWeightData()
                    {
                        id = Random.Range(1, 100000),
                        configId = 800001
                    };
                }
                else if (slot == 3)
                {
                    player.lineLength = 0.4f;
                    gear.Type = GearType.Spinning;
                    gear.bobber = null;
                    gear.rod = new FRodData()
                    {
                        id = Random.Range(1, 100000),
                        configId = 100003,
                    };
                    gear.reel = new FReelData()
                    {
                        id = Random.Range(1, 100000),
                        configId = 200001
                    };
                    gear.line = new FLineData()
                    {
                        id = Random.Range(1, 100000),
                        configId = 400001
                    };
                    gear.leader = new FLeaderData()
                    {
                        id = Random.Range(1, 100000),
                        configId = 0
                    };
                    gear.lure = new FLureData()
                    {
                        id = Random.Range(1, 100000),
                        configId = 600001
                    };
                }
            }
        }

        private FPlayerData GetTestPlayer(int index)
        {
            FPlayerData player = new FPlayerData
            {
                PlayerID = 100 + index
            };

            var add = 0;//Random.Range(0, 5f) + index * 0.5f;

            player.position = new Vector3(325.04f + add, 11, 606.28f);
            player.rotation = quaternion.identity;


            if (index == 0)
            {
                player.currentGear = new FPlayerGearData();
            }
            else if (index == 1)
            {
            }
            else if (index == 2)
            {
                player.currentGear = new FPlayerGearData();
            }
            else
            {
            }


            return player;
        }

        #endregion
    }
}