123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- using FL.Network;
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- using XGame.Framework.Data;
- namespace FL.Data
- {
- public class PartnersData : DataSingleton<PartnersData>, IDisposable
- {
- /// <summary>
- /// 激活上限
- /// </summary>
- public const byte GoneUpLimit = 6;
- /// <summary>
- /// 每个星级(黄|紫|红)最多拥有5个星星数量
- /// </summary>
- public const int MaxStarNum = 5;
- /// <summary>
- /// 最大星星阶级(颜色)
- /// </summary>
- public const int MaxStarStep = 8;
- /// <summary>
- /// 圣兵待下阵特殊状态(圣兵主界面中)
- /// </summary>
- public bool IsWaitForDownState = false;
- /// <summary>
- /// 当前使用的(圣兵)方案索引
- /// </summary>
- public int usePlanIndex;
- /// <summary>
- /// 圣兵方案存放的圣兵id列表
- /// </summary>
- private List<List<long>> _lineupPlanList;
- public List<List<long>> LineupPlanList => _lineupPlanList ??= new List<List<long>>();
- /// <summary>
- /// 圣兵方案名称列表
- /// </summary>
- private List<string> _lineupPlanNameList;
- public List<string> LineupPlanNameList => _lineupPlanNameList ??= new List<string>();
- private Dictionary<long, int> _goneUpMap;
- /// <summary>
- /// 已上阵的随从->位置
- /// key:随从的uid
- /// value:位置索引(0-5)
- /// </summary>
- public Dictionary<long, int> GoneUpMap => _goneUpMap ??= new Dictionary<long, int>();
- private Dictionary<long, PartnerAttributes> _partnersMap;
- /// <summary>
- /// 拥有的所有随从
- /// </summary>
- public Dictionary<long, PartnerAttributes> PartnersMap => _partnersMap ??= new Dictionary<long, PartnerAttributes>();
- /// <summary>
- /// 剑的偏移值,只记录左边的,右边对称获取
- /// </summary>
- private Vector3[] _partnerOffsets = new Vector3[] { new Vector3(-4.5f, 1.5f, 0), new Vector3(-3.5f, 0.6f, 0), new Vector3(-2.5f, -0.3f, 0) };
- #region 圣兵方案
- /// <summary>
- /// 使用方案id
- /// </summary>
- public int UsePlanId { get; set; }
- /// <summary>
- /// 更新当前已上阵随从位置
- /// </summary>
- public void UpdateUpPartnerMap()
- {
- var plan = GetPlanById(UsePlanId);
- _upPartnerMap.Clear();
- if (plan == null) return;
- foreach (var partnerSlot in plan.planValues)
- {
- _upPartnerMap.Add(partnerSlot.sbId, partnerSlot.caoId);
- }
- }
- /// <summary>
- /// 已上阵的随从->位置
- /// key:随从的uid
- /// value:位置索引(0-5)
- /// 没有上阵为-1
- /// </summary>
- private Dictionary<int, int> _upPartnerMap = new Dictionary<int, int>();
- /// <summary>
- /// 获取已上阵的随从->位置
- /// key:随从的uid
- /// value:位置索引(0-5)
- /// 没有上阵为-1
- /// </summary>
- public int GetPartnerUpPosById(int id)
- {
- return _upPartnerMap.GetValueOrDefault(id, -1);
- }
- /// <summary>
- /// 圣兵方案
- /// </summary>
- private Dictionary<int, PartnerPlan> _planMap = new Dictionary<int, PartnerPlan>();
- /// <summary>
- /// 当前使用的圣兵方案
- /// </summary>
- public PartnerPlan CurUsePlan
- {
- get
- {
- return GetPlanById(UsePlanId);
- }
- }
- /// <summary>
- /// 获取方案信息
- /// </summary>
- /// <param name="cao">方案id</param>
- /// <returns></returns>
- ///
- public PartnerPlan GetPlanById(int cao)
- {
- return _planMap.GetValueOrDefault(cao);
- }
- /// <summary>
- /// 更新所有方案
- /// </summary>
- /// <param name="useId">使用方案的id</param>
- /// <param name="list">方案列表</param>
- public void UpdatePlanMap(List<ActShengBingSuit> suitList)
- {
- var planList = new List<PartnerPlan>();
- foreach (var suit in suitList)
- {
- var caoList = new List<PartnerPlanSlot>();
- foreach (var cao in suit.cao)
- {
- var slot = new PartnerPlanSlot();
- slot.Init(cao.caoId, cao.mwId, cao.sbId);
- caoList.Add(slot);
- }
- var plan = new PartnerPlan();
- plan.Init(suit.id, suit.name, caoList);
- planList.Add(plan);
- }
- SetPlanMap(planList);
- }
- public void SetPlanMap(List<PartnerPlan> list)
- {
- _planMap.Clear();
- foreach (var plan in list)
- {
- _planMap.Add(plan.id, plan);
- }
- }
- #endregion
- #region 圣兵库
- private Dictionary<int, PartnerAttributes> partnerMap = new Dictionary<int, PartnerAttributes>();
- public PartnerAttributes GetPartnerAttrById(int id)
- {
- return partnerMap.GetValueOrDefault(id);
- }
- /// <summary>
- /// 更新拥有圣兵信息
- /// </summary>
- /// <param name="list"></param>
- public void UpdatePartnerMap(List<ActShengBingList> list)
- {
- ClearPartnerMap();
- foreach (var shengBing in list)
- {
- var attr = new PartnerAttributes()
- {
- TableId = shengBing.sbId,
- Level = shengBing.level,
- RisingStarLv = shengBing.star,
- EpigraphId = shengBing.mingwen,
- };
- partnerMap.Add(attr.TableId, attr);
- }
- }
- private void ClearPartnerMap()
- {
- foreach (var partner in partnerMap.Values)
- {
- (partner as IDisposable).Dispose();
- }
- partnerMap.Clear();
- }
- #endregion
- public Vector3 GetPartnerOffset(long partnerUID)
- {
- var index = GoneUpMap[partnerUID];
- var tmpIdx = index % 3;
- tmpIdx = index >= 3 ? 2 - tmpIdx : tmpIdx;
- var offset = _partnerOffsets[tmpIdx];
- if (index >= 3)
- {
- offset.x *= -1;
- }
- //XGame.Log.Info($"PartnerOffset UID:{partnerUID} index:{index} offset:{tmpIdx}");
- return offset;
- }
- /// <summary>
- /// 是否达到激活上限
- /// </summary>
- public bool IsReachedLimit => GoneUpMap.Count == GoneUpLimit;
- /// <summary>
- /// 获取星星的色阶
- /// </summary>
- /// <param name="starLv"></param>
- /// <returns></returns>
- public int GetStarStep(int starLevel)
- {
- int step = MaxStarStep - 1;
- for (int i = step; starLevel >= 0; i--)
- {
- if (starLevel > i * MaxStarNum)
- {
- return i + 1;
- }
- }
- return 1;
- }
- void IDisposable.Dispose()
- {
- _goneUpMap?.Clear();
- if (_partnersMap != null)
- {
- foreach (var val in _partnersMap.Values)
- {
- (val as IDisposable)?.Dispose();
- }
- _partnersMap.Clear();
- }
- _planMap.Clear();
- }
- }
- }
|