PartnersData.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. using FL.Network;
  2. using System;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using XGame.Framework.Data;
  6. namespace FL.Data
  7. {
  8. public class PartnersData : DataSingleton<PartnersData>, IDisposable
  9. {
  10. /// <summary>
  11. /// 激活上限
  12. /// </summary>
  13. public const byte GoneUpLimit = 6;
  14. /// <summary>
  15. /// 每个星级(黄|紫|红)最多拥有5个星星数量
  16. /// </summary>
  17. public const int MaxStarNum = 5;
  18. /// <summary>
  19. /// 最大星星阶级(颜色)
  20. /// </summary>
  21. public const int MaxStarStep = 8;
  22. /// <summary>
  23. /// 圣兵待下阵特殊状态(圣兵主界面中)
  24. /// </summary>
  25. public bool IsWaitForDownState = false;
  26. /// <summary>
  27. /// 当前使用的(圣兵)方案索引
  28. /// </summary>
  29. public int usePlanIndex;
  30. /// <summary>
  31. /// 圣兵方案存放的圣兵id列表
  32. /// </summary>
  33. private List<List<long>> _lineupPlanList;
  34. public List<List<long>> LineupPlanList => _lineupPlanList ??= new List<List<long>>();
  35. /// <summary>
  36. /// 圣兵方案名称列表
  37. /// </summary>
  38. private List<string> _lineupPlanNameList;
  39. public List<string> LineupPlanNameList => _lineupPlanNameList ??= new List<string>();
  40. private Dictionary<long, int> _goneUpMap;
  41. /// <summary>
  42. /// 已上阵的随从->位置
  43. /// key:随从的uid
  44. /// value:位置索引(0-5)
  45. /// </summary>
  46. public Dictionary<long, int> GoneUpMap => _goneUpMap ??= new Dictionary<long, int>();
  47. private Dictionary<long, PartnerAttributes> _partnersMap;
  48. /// <summary>
  49. /// 拥有的所有随从
  50. /// </summary>
  51. public Dictionary<long, PartnerAttributes> PartnersMap => _partnersMap ??= new Dictionary<long, PartnerAttributes>();
  52. /// <summary>
  53. /// 剑的偏移值,只记录左边的,右边对称获取
  54. /// </summary>
  55. 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) };
  56. #region 圣兵方案
  57. /// <summary>
  58. /// 使用方案id
  59. /// </summary>
  60. public int UsePlanId { get; set; }
  61. /// <summary>
  62. /// 更新当前已上阵随从位置
  63. /// </summary>
  64. public void UpdateUpPartnerMap()
  65. {
  66. var plan = GetPlanById(UsePlanId);
  67. _upPartnerMap.Clear();
  68. if (plan == null) return;
  69. foreach (var partnerSlot in plan.planValues)
  70. {
  71. _upPartnerMap.Add(partnerSlot.sbId, partnerSlot.caoId);
  72. }
  73. }
  74. /// <summary>
  75. /// 已上阵的随从->位置
  76. /// key:随从的uid
  77. /// value:位置索引(0-5)
  78. /// 没有上阵为-1
  79. /// </summary>
  80. private Dictionary<int, int> _upPartnerMap = new Dictionary<int, int>();
  81. /// <summary>
  82. /// 获取已上阵的随从->位置
  83. /// key:随从的uid
  84. /// value:位置索引(0-5)
  85. /// 没有上阵为-1
  86. /// </summary>
  87. public int GetPartnerUpPosById(int id)
  88. {
  89. return _upPartnerMap.GetValueOrDefault(id, -1);
  90. }
  91. /// <summary>
  92. /// 圣兵方案
  93. /// </summary>
  94. private Dictionary<int, PartnerPlan> _planMap = new Dictionary<int, PartnerPlan>();
  95. /// <summary>
  96. /// 当前使用的圣兵方案
  97. /// </summary>
  98. public PartnerPlan CurUsePlan
  99. {
  100. get
  101. {
  102. return GetPlanById(UsePlanId);
  103. }
  104. }
  105. /// <summary>
  106. /// 获取方案信息
  107. /// </summary>
  108. /// <param name="cao">方案id</param>
  109. /// <returns></returns>
  110. ///
  111. public PartnerPlan GetPlanById(int cao)
  112. {
  113. return _planMap.GetValueOrDefault(cao);
  114. }
  115. /// <summary>
  116. /// 更新所有方案
  117. /// </summary>
  118. /// <param name="useId">使用方案的id</param>
  119. /// <param name="list">方案列表</param>
  120. public void UpdatePlanMap(List<ActShengBingSuit> suitList)
  121. {
  122. var planList = new List<PartnerPlan>();
  123. foreach (var suit in suitList)
  124. {
  125. var caoList = new List<PartnerPlanSlot>();
  126. foreach (var cao in suit.cao)
  127. {
  128. var slot = new PartnerPlanSlot();
  129. slot.Init(cao.caoId, cao.mwId, cao.sbId);
  130. caoList.Add(slot);
  131. }
  132. var plan = new PartnerPlan();
  133. plan.Init(suit.id, suit.name, caoList);
  134. planList.Add(plan);
  135. }
  136. SetPlanMap(planList);
  137. }
  138. public void SetPlanMap(List<PartnerPlan> list)
  139. {
  140. _planMap.Clear();
  141. foreach (var plan in list)
  142. {
  143. _planMap.Add(plan.id, plan);
  144. }
  145. }
  146. #endregion
  147. #region 圣兵库
  148. private Dictionary<int, PartnerAttributes> partnerMap = new Dictionary<int, PartnerAttributes>();
  149. public PartnerAttributes GetPartnerAttrById(int id)
  150. {
  151. return partnerMap.GetValueOrDefault(id);
  152. }
  153. /// <summary>
  154. /// 更新拥有圣兵信息
  155. /// </summary>
  156. /// <param name="list"></param>
  157. public void UpdatePartnerMap(List<ActShengBingList> list)
  158. {
  159. ClearPartnerMap();
  160. foreach (var shengBing in list)
  161. {
  162. var attr = new PartnerAttributes()
  163. {
  164. TableId = shengBing.sbId,
  165. Level = shengBing.level,
  166. RisingStarLv = shengBing.star,
  167. EpigraphId = shengBing.mingwen,
  168. };
  169. partnerMap.Add(attr.TableId, attr);
  170. }
  171. }
  172. private void ClearPartnerMap()
  173. {
  174. foreach (var partner in partnerMap.Values)
  175. {
  176. (partner as IDisposable).Dispose();
  177. }
  178. partnerMap.Clear();
  179. }
  180. #endregion
  181. public Vector3 GetPartnerOffset(long partnerUID)
  182. {
  183. var index = GoneUpMap[partnerUID];
  184. var tmpIdx = index % 3;
  185. tmpIdx = index >= 3 ? 2 - tmpIdx : tmpIdx;
  186. var offset = _partnerOffsets[tmpIdx];
  187. if (index >= 3)
  188. {
  189. offset.x *= -1;
  190. }
  191. //XGame.Log.Info($"PartnerOffset UID:{partnerUID} index:{index} offset:{tmpIdx}");
  192. return offset;
  193. }
  194. /// <summary>
  195. /// 是否达到激活上限
  196. /// </summary>
  197. public bool IsReachedLimit => GoneUpMap.Count == GoneUpLimit;
  198. /// <summary>
  199. /// 获取星星的色阶
  200. /// </summary>
  201. /// <param name="starLv"></param>
  202. /// <returns></returns>
  203. public int GetStarStep(int starLevel)
  204. {
  205. int step = MaxStarStep - 1;
  206. for (int i = step; starLevel >= 0; i--)
  207. {
  208. if (starLevel > i * MaxStarNum)
  209. {
  210. return i + 1;
  211. }
  212. }
  213. return 1;
  214. }
  215. void IDisposable.Dispose()
  216. {
  217. _goneUpMap?.Clear();
  218. if (_partnersMap != null)
  219. {
  220. foreach (var val in _partnersMap.Values)
  221. {
  222. (val as IDisposable)?.Dispose();
  223. }
  224. _partnersMap.Clear();
  225. }
  226. _planMap.Clear();
  227. }
  228. }
  229. }