GuideDataManager.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. namespace GFGGame
  4. {
  5. public class GuideDataManager
  6. {
  7. //public static int currentGuideId;
  8. private static Dictionary<int, GuideData> _dataDic = new Dictionary<int, GuideData>();
  9. //本次登录引导的id缓存
  10. private static Dictionary<int, bool> _guideDicAtThisLogin = new Dictionary<int, bool>();
  11. private static Dictionary<int, Dictionary<int, int>> _guideDicIndex = new Dictionary<int, Dictionary<int, int>>();
  12. public static int _currentGuideId;
  13. public static int currentGuideId
  14. {
  15. get
  16. {
  17. return _currentGuideId;
  18. }
  19. set
  20. {
  21. _currentGuideId = value;
  22. }
  23. }
  24. public static void InitServerData(List<GuideData> list)
  25. {
  26. currentGuideId = 0;
  27. _dataDic.Clear();
  28. _guideDicAtThisLogin.Clear();
  29. if (list != null)
  30. {
  31. foreach (GuideData data in list)
  32. {
  33. _dataDic.Add(data.guideId, data);
  34. }
  35. }
  36. }
  37. public static bool TryCompleteGuide(int guideId)
  38. {
  39. if (GameGlobal.skipGuide)
  40. {
  41. return false;
  42. }
  43. if (currentGuideId == guideId)
  44. {
  45. GuideData guideData = null;
  46. if (_dataDic.ContainsKey(guideId))
  47. {
  48. guideData = _dataDic[guideId];
  49. }
  50. else
  51. {
  52. guideData = new GuideData();
  53. guideData.guideId = guideId;
  54. guideData.count = 0;
  55. _dataDic.Add(guideId, guideData);
  56. }
  57. guideData.count++;
  58. currentGuideId = 0;
  59. GameProxy.ReqUpdateRoleGuide(guideData);
  60. _guideDicAtThisLogin[guideId] = true;
  61. return true;
  62. }
  63. return false;
  64. }
  65. public static int GetGuideCount(int guideId)
  66. {
  67. if (GuideController.useNewGuide) return 1;
  68. if (_dataDic.ContainsKey(guideId))
  69. {
  70. GuideData guideData = _dataDic[guideId];
  71. return guideData.count;
  72. }
  73. return 0;
  74. }
  75. public static bool CheckGuideIsCompletedAtThisLogin(int guideId)
  76. {
  77. if (_guideDicAtThisLogin.ContainsKey(guideId))
  78. {
  79. return _guideDicAtThisLogin[guideId];
  80. }
  81. return false;
  82. }
  83. public static int _currentGuideIdIndex;
  84. public static int currentGuideIdIndex
  85. {
  86. get
  87. {
  88. return _currentGuideIdIndex;
  89. }
  90. set
  91. {
  92. _currentGuideIdIndex = value;
  93. }
  94. }
  95. public static void SetGuideIndex(int guideId, int index)
  96. {
  97. if (!_guideDicIndex.ContainsKey(guideId))
  98. {
  99. _guideDicIndex.Add(guideId, new Dictionary<int, int>());
  100. }
  101. if (_guideDicIndex[guideId].ContainsKey(index)) return;
  102. _guideDicIndex[guideId][index] = 0;
  103. }
  104. public static int GetGuideCountCopy(string guideKey)
  105. {
  106. if (!GuideController.useNewGuide) return 1;
  107. GuideCfg cfg = GuideCfgArray.Instance.GetCfg(guideKey);
  108. if (_dataDic.ContainsKey(cfg.id))
  109. {
  110. GuideData guideData = _dataDic[cfg.id];
  111. return guideData.count;
  112. }
  113. return 0;
  114. }
  115. public static int GetGuideCountCopy(int guideId)
  116. {
  117. if (!GuideController.useNewGuide) return 1;
  118. if (_dataDic.ContainsKey(guideId))
  119. {
  120. GuideData guideData = _dataDic[guideId];
  121. return guideData.count;
  122. }
  123. return 0;
  124. }
  125. public static bool TryCompleteGuideIndex(int guideId, int index, bool checkInde = true)
  126. {
  127. if (GameGlobal.skipGuide)
  128. {
  129. return false;
  130. }
  131. if (!checkInde && guideId == currentGuideId || checkInde && guideId == currentGuideId && index == currentGuideIdIndex && !IsGuideIndexFinish(guideId, index))
  132. {
  133. _guideDicIndex[guideId][index] = 1;
  134. return true;
  135. }
  136. return false;
  137. }
  138. public static void SetGuideIndexState(int guideId, int index, int state)
  139. {
  140. if (guideId == currentGuideId && index == currentGuideIdIndex && _guideDicIndex.ContainsKey(guideId) && _guideDicIndex[guideId].ContainsKey(index))
  141. {
  142. _guideDicIndex[guideId][index] = state;
  143. }
  144. }
  145. public static bool CheckAllIndexFinish(int guideId, int count)
  146. {
  147. for (int i = 1; i <= count; i++)
  148. {
  149. if (!IsGuideIndexFinish(guideId, i)) return false;
  150. }
  151. return true;
  152. }
  153. public static bool IsGuideIndexFinish(int guideId, int index)
  154. {
  155. if (index == 0) return true;
  156. if (_guideDicIndex.ContainsKey(guideId) && _guideDicIndex[guideId].ContainsKey(index) && _guideDicIndex[guideId][index] == 1)
  157. {
  158. return true;
  159. }
  160. return false;
  161. }
  162. }
  163. }