EpigraphData.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. private Dictionary<int, EpigraphAttributes> _epiMap = new();
  13. private Dictionary<long, EpigraphAttributes> _epiUIDMap = new();
  14. public List<EpigraphAttributes> EpiList
  15. {
  16. get
  17. {
  18. var list = new List<EpigraphAttributes>();
  19. foreach (var epi in _epiMap.Values)
  20. {
  21. list.Add(epi);
  22. }
  23. return list;
  24. }
  25. }
  26. public int UpModeSelect = 0;
  27. public void UpdateEpiInfo(List<ActMingWenList> mingwen)
  28. {
  29. foreach (var mw in mingwen)
  30. {
  31. var attr = GetEpigraphAttrByTableId(mw.mwId);
  32. if (attr != null)
  33. {
  34. attr.SetData(mw.mwId, mw.star, mw.shengbing);
  35. }
  36. else
  37. {
  38. var epiAttr = CreateEpigraphAttr(mw);
  39. _epiMap.Add(mw.mwId, epiAttr);
  40. _epiUIDMap.Add(epiAttr.UID, epiAttr);
  41. }
  42. }
  43. }
  44. public void InitEpiInfo(List<ActMingWenList> mingwen)
  45. {
  46. var list = new List<EpigraphAttributes>();
  47. foreach (var mw in mingwen)
  48. {
  49. var epiAttr = CreateEpigraphAttr(mw);
  50. epiAttr.SetData(mw.mwId, mw.star, mw.shengbing);
  51. list.Add(epiAttr);
  52. }
  53. SetEpiInfo(list);
  54. }
  55. private EpigraphAttributes CreateEpigraphAttr(ActMingWenList mw)
  56. {
  57. var epiAttr = new EpigraphAttributes();
  58. epiAttr.UID = UIDDefine.New();
  59. epiAttr.SetData(mw.mwId, mw.star, mw.shengbing);
  60. return epiAttr;
  61. }
  62. public EpigraphAttributes GetEpigraphAttrByTableId(int id)
  63. {
  64. return _epiMap.GetValueOrDefault(id);
  65. }
  66. public bool TryGetEpigraphAttrByTableId(int id, out EpigraphAttributes epiAttr)
  67. {
  68. return _epiMap.TryGetValue(id, out epiAttr);
  69. }
  70. public EpigraphAttributes GetEpigraphAttrByUID(long UID)
  71. {
  72. return _epiUIDMap.GetValueOrDefault(UID);
  73. }
  74. public bool TryGetEpigraphAttrByUID(long UID, out EpigraphAttributes epigraphAttributes)
  75. {
  76. return _epiUIDMap.TryGetValue(UID, out epigraphAttributes);
  77. }
  78. public void SetEpiInfo(List<EpigraphAttributes> data)
  79. {
  80. ClearEpiInfo();
  81. foreach (var epiAttr in data)
  82. {
  83. _epiMap.Add(epiAttr.TableId, epiAttr);
  84. _epiUIDMap.Add(epiAttr.UID, epiAttr);
  85. }
  86. }
  87. /// <summary>
  88. /// 获取铭文当前的阶级
  89. /// </summary>
  90. /// <param name="starLv">当前星级</param>
  91. /// <returns></returns>
  92. public int GetStarStep(int starLv)
  93. {
  94. return Mathf.FloorToInt(starLv / 5) + 1;
  95. }
  96. /// <summary>
  97. /// 获取铭文当前阶级的星级
  98. /// </summary>
  99. /// <param name="starLv">当前星级</param>
  100. /// <returns></returns>
  101. public int GetCurCtepStarLv(int starLv)
  102. {
  103. var lv = starLv % 5;
  104. if (lv == 0)
  105. lv = 5;
  106. return lv;
  107. }
  108. private void ClearEpiInfo()
  109. {
  110. foreach (var epiAttr in _epiMap.Values)
  111. {
  112. ObjectPool.Recycle(epiAttr);
  113. }
  114. _epiMap.Clear();
  115. }
  116. void IDisposable.Dispose()
  117. {
  118. ClearEpiInfo();
  119. }
  120. }
  121. }