GuideDataManager.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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 bool CheckGuideIsCompletedAtThisLogin(int guideId)
  66. {
  67. if (_guideDicAtThisLogin.ContainsKey(guideId))
  68. {
  69. return _guideDicAtThisLogin[guideId];
  70. }
  71. return false;
  72. }
  73. public static int _currentGuideIdIndex;
  74. public static int currentGuideIdIndex
  75. {
  76. get
  77. {
  78. return _currentGuideIdIndex;
  79. }
  80. set
  81. {
  82. _currentGuideIdIndex = value;
  83. }
  84. }
  85. public static void SetGuideIndex(int guideId, int index)
  86. {
  87. if (!_guideDicIndex.ContainsKey(guideId))
  88. {
  89. _guideDicIndex.Add(guideId, new Dictionary<int, int>());
  90. }
  91. if (_guideDicIndex[guideId].ContainsKey(index)) return;
  92. _guideDicIndex[guideId][index] = 0;
  93. }
  94. public static int GetGuideCountCopy(string guideKey)
  95. {
  96. if (!GuideController.useNewGuide) return 1;
  97. GuideCfg cfg = GuideCfgArray.Instance.GetCfg(guideKey);
  98. if (_dataDic.ContainsKey(cfg.id))
  99. {
  100. GuideData guideData = _dataDic[cfg.id];
  101. return guideData.count;
  102. }
  103. return 0;
  104. }
  105. public static int GetGuideCountCopy(int guideId)
  106. {
  107. if (!GuideController.useNewGuide) return 1;
  108. if (_dataDic.ContainsKey(guideId))
  109. {
  110. GuideData guideData = _dataDic[guideId];
  111. return guideData.count;
  112. }
  113. return 0;
  114. }
  115. public static bool TryCompleteGuideIndex(int guideId, int index, bool checkInde = true)
  116. {
  117. if (GameGlobal.skipGuide)
  118. {
  119. return false;
  120. }
  121. if (!checkInde && guideId == currentGuideId || checkInde && guideId == currentGuideId && index == currentGuideIdIndex && !IsGuideIndexFinish(guideId, index))
  122. {
  123. _guideDicIndex[guideId][index] = 1;
  124. return true;
  125. }
  126. return false;
  127. }
  128. public static void SetGuideIndexState(int guideId, int index, int state)
  129. {
  130. if (guideId == currentGuideId && index == currentGuideIdIndex && _guideDicIndex.ContainsKey(guideId) && _guideDicIndex[guideId].ContainsKey(index))
  131. {
  132. _guideDicIndex[guideId][index] = state;
  133. }
  134. }
  135. public static bool CheckAllIndexFinish(int guideId, int count)
  136. {
  137. for (int i = 1; i <= count; i++)
  138. {
  139. if (!IsGuideIndexFinish(guideId, i)) return false;
  140. }
  141. return true;
  142. }
  143. public static bool IsGuideIndexFinish(int guideId, int index)
  144. {
  145. if (index == 0) return true;
  146. if (_guideDicIndex.ContainsKey(guideId) && _guideDicIndex[guideId].ContainsKey(index) && _guideDicIndex[guideId][index] == 1)
  147. {
  148. return true;
  149. }
  150. return false;
  151. }
  152. }
  153. }