MainStoryDataManager.cs 7.9 KB

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