MainStoryDataManager.cs 7.9 KB

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