EpigraphData.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. using System;
  2. using System.Collections.Generic;
  3. using FL.Network;
  4. using UnityEngine;
  5. using XGame;
  6. using XGame.Framework;
  7. using XGame.Framework.Data;
  8. namespace FL.Data
  9. {
  10. public class EpigraphData : DataSingleton<EpigraphData>, IDisposable
  11. {
  12. #region 铭文库
  13. private Dictionary<int, EpigraphAttributes> _epiMap = new();
  14. private Dictionary<long, EpigraphAttributes> _epiUIDMap = new();
  15. public List<EpigraphAttributes> EpiList
  16. {
  17. get
  18. {
  19. var list = new List<EpigraphAttributes>();
  20. foreach (var epi in _epiMap.Values)
  21. {
  22. list.Add(epi);
  23. }
  24. return list;
  25. }
  26. }
  27. public int UpModeSelect = 0;
  28. public void UpdateEpiInfo(List<ActMingWenList> mingwen)
  29. {
  30. foreach (var mw in mingwen)
  31. {
  32. var attr = GetEpigraphAttrByTableId(mw.mwId);
  33. if (attr != null)
  34. {
  35. attr.SetData(mw.mwId, mw.star, mw.shengbing);
  36. }
  37. else
  38. {
  39. var epiAttr = CreateEpigraphAttr(mw);
  40. _epiMap.Add(mw.mwId, epiAttr);
  41. _epiUIDMap.Add(epiAttr.UID, epiAttr);
  42. }
  43. }
  44. }
  45. public void InitEpiInfo(List<ActMingWenList> mingwen)
  46. {
  47. var list = new List<EpigraphAttributes>();
  48. foreach (var mw in mingwen)
  49. {
  50. var epiAttr = CreateEpigraphAttr(mw);
  51. epiAttr.SetData(mw.mwId, mw.star, mw.shengbing);
  52. list.Add(epiAttr);
  53. }
  54. SetEpiInfo(list);
  55. }
  56. private EpigraphAttributes CreateEpigraphAttr(ActMingWenList mw)
  57. {
  58. var epiAttr = new EpigraphAttributes();
  59. epiAttr.UID = UIDDefine.New();
  60. epiAttr.SetData(mw.mwId, mw.star, mw.shengbing);
  61. return epiAttr;
  62. }
  63. public EpigraphAttributes GetEpigraphAttrByTableId(int id)
  64. {
  65. return _epiMap.GetValueOrDefault(id);
  66. }
  67. public bool TryGetEpigraphAttrByTableId(int id, out EpigraphAttributes epiAttr)
  68. {
  69. return _epiMap.TryGetValue(id, out epiAttr);
  70. }
  71. public EpigraphAttributes GetEpigraphAttrByUID(long UID)
  72. {
  73. return _epiUIDMap.GetValueOrDefault(UID);
  74. }
  75. public bool TryGetEpigraphAttrByUID(long UID, out EpigraphAttributes epigraphAttributes)
  76. {
  77. return _epiUIDMap.TryGetValue(UID, out epigraphAttributes);
  78. }
  79. public void SetEpiInfo(List<EpigraphAttributes> data)
  80. {
  81. ClearEpiInfo();
  82. foreach (var epiAttr in data)
  83. {
  84. _epiMap.Add(epiAttr.TableId, epiAttr);
  85. _epiUIDMap.Add(epiAttr.UID, epiAttr);
  86. }
  87. }
  88. #endregion
  89. #region 羁绊
  90. public readonly Dictionary<int, bool> JibanMap = new Dictionary<int, bool>();
  91. public void ClearJibanActive()
  92. {
  93. JibanMap.Clear();
  94. }
  95. public void SetJibanActiveState(int jibanId, int level)
  96. {
  97. var id = 100000 + jibanId * 1000 + level;
  98. if (JibanMap.ContainsKey(jibanId))
  99. {
  100. JibanMap.Remove(id);
  101. }
  102. JibanMap.Add(id, true);
  103. }
  104. public bool GetJibaIsActive(int jibanId, int level)
  105. {
  106. var id = 100000 + jibanId * 1000 + level;
  107. return JibanMap.GetValueOrDefault(id, false);
  108. }
  109. #endregion
  110. /// <summary>
  111. /// 获取铭文当前的阶级
  112. /// </summary>
  113. /// <param name="starLv">当前星级</param>
  114. /// <returns></returns>
  115. public int GetStarStep(int starLv)
  116. {
  117. return Mathf.FloorToInt(starLv / 5) + 1;
  118. }
  119. /// <summary>
  120. /// 获取铭文当前阶级的星级
  121. /// </summary>
  122. /// <param name="starLv">当前星级</param>
  123. /// <returns></returns>
  124. public int GetCurCtepStarLv(int starLv)
  125. {
  126. var lv = starLv % 5;
  127. if (lv == 0)
  128. lv = 5;
  129. return lv;
  130. }
  131. private void ClearEpiInfo()
  132. {
  133. foreach (var epiAttr in _epiMap.Values)
  134. {
  135. ObjectPool.Recycle(epiAttr);
  136. }
  137. _epiMap.Clear();
  138. }
  139. void IDisposable.Dispose()
  140. {
  141. ClearEpiInfo();
  142. }
  143. }
  144. }