MainStoryDataManager.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System;
  4. using UnityEngine;
  5. using ET;
  6. using ProtoBuf.Meta;
  7. namespace GFGGame
  8. {
  9. public class MainStoryDataManager
  10. {
  11. public static string priorId = "prior";//首次登录前置剧情id
  12. //剧情副本专用当前章节
  13. public static int currentChapterCfgId = 0;
  14. //剧情副本专用当前关卡序号,从1开始
  15. public static int CurrentChapterOrder
  16. {
  17. get
  18. {
  19. var chapterCfg = StoryChapterCfgArray.Instance.GetCfg(currentChapterCfgId);
  20. if (chapterCfg != null)
  21. {
  22. return chapterCfg.order;
  23. }
  24. return 0;
  25. }
  26. }
  27. //剧情副本专用关卡编号
  28. private static int _currentLevelCfgId;
  29. public static int currentLevelCfgId
  30. {
  31. get
  32. {
  33. return _currentLevelCfgId;
  34. }
  35. set
  36. {
  37. int lastLevelCfgId = _currentLevelCfgId;
  38. var lastLevelCfg = StoryLevelCfgArray.Instance.GetCfg(_currentLevelCfgId);
  39. _currentLevelCfgId = value;
  40. var levelCfg = StoryLevelCfgArray.Instance.GetCfg(_currentLevelCfgId);
  41. currentChapterCfgId = levelCfg == null ? lastLevelCfg.chapterId : levelCfg.chapterId;
  42. }
  43. }
  44. //剧情副本专用关卡宝箱状态记录
  45. private static Dictionary<int, int[]> _chapterBonusDic = new Dictionary<int, int[]>();
  46. public static void InitBoxBonusStates(List<int> ks, List<int> vs)
  47. {
  48. _chapterBonusDic.Clear();
  49. for (var i = 0; i < ks.Count; ++i)
  50. {
  51. var states = new int[] { 0, 0, 0 };
  52. var value = vs[i];
  53. CalculateHelper.GenerateChapterBoxStates(states, value);
  54. _chapterBonusDic.Add(ks[i], states);
  55. }
  56. }
  57. public static void UpdateBoxBonusStates(int chapter, int stateInt)
  58. {
  59. if (!_chapterBonusDic.TryGetValue(chapter, out var states))
  60. {
  61. states = new int[] { 0, 0, 0 };
  62. _chapterBonusDic.Add(chapter, states);
  63. }
  64. CalculateHelper.GenerateChapterBoxStates(states, stateInt);
  65. }
  66. //获取宝箱奖励状态
  67. public static int GetChapterBonusStatus(int chapterID, int index)
  68. {
  69. if (_chapterBonusDic.ContainsKey(chapterID))
  70. {
  71. var states = _chapterBonusDic[chapterID];
  72. if (states != null)
  73. {
  74. return states[index];
  75. }
  76. }
  77. return ConstBonusStatus.CAN_NOT_GET;
  78. }
  79. public static List<ItemData> GetChapterBonus(int chapterID, int index)
  80. {
  81. List<ItemData> bonusList = StoryBonusDataCache.GetChapterBonusList(chapterID, index);
  82. return bonusList;
  83. }
  84. public static bool CheckOpenMainUI()
  85. {
  86. return InstanceZonesDataManager.CheckLevelPass(100001002);
  87. }
  88. //检查指定章节对应的普通章节是否通关
  89. public static bool CheckNeedChapterPass(int chapterId, out int needChapterId)
  90. {
  91. StoryChapterCfg chapterCfg = StoryChapterCfgArray.Instance.GetCfg(chapterId);
  92. needChapterId = chapterCfg.needChapterId;
  93. if (chapterCfg.needChapterId > 0)
  94. {
  95. var preChapterCfg = StoryChapterCfgArray.Instance.GetCfg(chapterCfg.needChapterId);
  96. if (preChapterCfg != null)
  97. {
  98. return InstanceZonesDataManager.CheckChapterPass(preChapterCfg.type, preChapterCfg.subType, preChapterCfg.id, preChapterCfg.levelCount);
  99. }
  100. }
  101. return true;
  102. }
  103. public static int CheckChapterPassIndex(int subtype)
  104. {
  105. int count = 2;
  106. List<StoryChapterCfg> chapList = StoryChapterCfgArray.Instance.GetCfgsBysubType(subtype);
  107. foreach (StoryChapterCfg item in chapList)
  108. {
  109. var preChapterCfg = StoryChapterCfgArray.Instance.GetCfg(item.id);
  110. if (preChapterCfg != null)
  111. {
  112. if(InstanceZonesDataManager.CheckChapterPass(preChapterCfg.type, preChapterCfg.subType, preChapterCfg.id, preChapterCfg.levelCount))
  113. {
  114. count++;
  115. }
  116. }
  117. }
  118. if(count> chapList.Count)
  119. {
  120. count = chapList.Count;
  121. }
  122. return count;
  123. }
  124. public static bool CheckChapterUnlock(int chapterId, bool checkRoleLv = true)
  125. {
  126. StoryChapterCfg chapterCfg = StoryChapterCfgArray.Instance.GetCfg(chapterId);
  127. if (checkRoleLv && GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl) < chapterCfg.lvl)
  128. {
  129. return false;
  130. }
  131. //上一关卡
  132. int preChapterId = chapterId - 1;
  133. var preChapterCfg = StoryChapterCfgArray.Instance.GetCfg(preChapterId);
  134. if (preChapterCfg != null)
  135. {
  136. if(!InstanceZonesDataManager.CheckChapterPass(preChapterCfg.type, preChapterCfg.subType, preChapterCfg.id, preChapterCfg.levelCount))
  137. {
  138. return false;
  139. }
  140. }
  141. //前置关卡
  142. return CheckNeedChapterPass(chapterId, out var needChapterId);
  143. }
  144. public static bool CheckLevelUnlock(int levelCfgId, bool checkRoleLv = true)
  145. {
  146. var levelCfg = StoryLevelCfgArray.Instance.GetCfg(levelCfgId);
  147. if (levelCfg != null)
  148. {
  149. if (!CheckChapterUnlock(levelCfg.chapterId, checkRoleLv))
  150. {
  151. return false;
  152. }
  153. var passLevelOrder = InstanceZonesDataManager.GetPassLevelOrder(levelCfg.type, levelCfg.subType, levelCfg.chapterId);
  154. return levelCfg.order <= passLevelOrder + 1;
  155. }
  156. return false;
  157. }
  158. public static bool CheckCurrentLevelPass()
  159. {
  160. return InstanceZonesDataManager.CheckLevelPass(currentLevelCfgId);
  161. }
  162. //判断章节是否是精英关卡
  163. public static bool CheckChapterIsHard(int chapterId)
  164. {
  165. return GetChapterSubType(chapterId) == ConstInstanceZonesSubType.Hard;
  166. }
  167. //获取章节难度(普通或者精英)
  168. public static int GetChapterSubType(int chapterId)
  169. {
  170. var chapterCfg = StoryChapterCfgArray.Instance.GetCfg(chapterId);
  171. if (chapterCfg != null)
  172. {
  173. return chapterCfg.subType;
  174. }
  175. return ConstInstanceZonesSubType.Normal;
  176. }
  177. //章节奖励状态
  178. public static Dictionary<int, int> ChapterRewardStatusDic = new Dictionary<int, int>();
  179. public static bool GetChapterRewardStatus()
  180. {
  181. foreach(var item in ChapterRewardStatusDic)
  182. {
  183. if(item.Value == 1)
  184. {
  185. return true;
  186. }
  187. }
  188. return false;
  189. }
  190. }
  191. }