StoryDataManager.cs 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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 StoryDataManager
  10. {
  11. public static string priorId = "prior";//首次登录前置剧情id
  12. public static int currentChapterCfgId = 0;
  13. public static int currentLevelOrder = 0;
  14. //关卡配置表的id
  15. public static int currentLevelCfgId;
  16. //当前关卡序号,从1开始
  17. public static int CurrentChapterOrder
  18. {
  19. get
  20. {
  21. var chapterCfg = StoryChapterCfgArray.Instance.GetCfg(currentChapterCfgId);
  22. if(chapterCfg != null)
  23. {
  24. return chapterCfg.order;
  25. }
  26. return 0;
  27. }
  28. }
  29. public static int currentScoreType;
  30. public static int currentCardId = 0;
  31. public static bool usedRecommend;
  32. //关卡最高分数记录
  33. private static Dictionary<int, int> _highestScoreDic = new Dictionary<int, int>();
  34. //关卡星数记录
  35. private static Dictionary<int, int> _starDic = new Dictionary<int, int>();
  36. //关卡宝箱状态记录
  37. private static Dictionary<int, int[]> _chapterBonusDic = new Dictionary<int, int[]>();
  38. public static void InitScoreList(List<int> ks, List<int> vs)
  39. {
  40. usedRecommend = false;
  41. _highestScoreDic.Clear();
  42. for (var i = 0; i < ks.Count; ++i)
  43. {
  44. _highestScoreDic.Add(ks[i], vs[i]);
  45. }
  46. }
  47. public static void InitStarList(List<int> ks, List<int> vs)
  48. {
  49. _starDic.Clear();
  50. for(var i = 0; i < ks.Count; ++i)
  51. {
  52. _starDic.Add(ks[i], vs[i]);
  53. }
  54. }
  55. public static void InitBoxBonusStates(List<int> ks, List<int> vs)
  56. {
  57. _chapterBonusDic.Clear();
  58. for (var i = 0; i < ks.Count; ++i)
  59. {
  60. var states = new int[] { 0, 0, 0 };
  61. var value = vs[i];
  62. CalculateHelper.GenerateChapterBoxStates(states, value);
  63. _chapterBonusDic.Add(ks[i], states);
  64. }
  65. }
  66. public static void UpdateBoxBonusStates(int chapter, int stateInt)
  67. {
  68. if (!_chapterBonusDic.TryGetValue(chapter, out var states))
  69. {
  70. states = new int[] { 0, 0, 0 };
  71. _chapterBonusDic.Add(chapter, states);
  72. }
  73. CalculateHelper.GenerateChapterBoxStates(states, stateInt);
  74. }
  75. //检查更新最高分
  76. public static void TryUpdateScore(int levelCfgId, int score)
  77. {
  78. _highestScoreDic.TryGetValue(levelCfgId, out var scoreHighest);
  79. if (score > scoreHighest)
  80. {
  81. _highestScoreDic[currentLevelCfgId] = score;
  82. }
  83. }
  84. //检查并更新关卡星数
  85. public static void TryUpdateLevelStar(int levelCfgId, int star)
  86. {
  87. _starDic.TryGetValue(levelCfgId, out var OldStar);
  88. if(star > OldStar)
  89. {
  90. _starDic[levelCfgId] = star;
  91. }
  92. }
  93. //获取宝箱奖励状态
  94. public static int GetChapterBonusStatus(int chapterID, int index)
  95. {
  96. if (_chapterBonusDic.ContainsKey(chapterID))
  97. {
  98. var states = _chapterBonusDic[chapterID];
  99. if (states != null)
  100. {
  101. return states[index];
  102. }
  103. }
  104. return ConstBonusStatus.CAN_NOT_GET;
  105. }
  106. public static List<ItemData> GetChapterBonus(int chapterID, int index)
  107. {
  108. List<ItemData> bonusList = StoryBonusDataCache.GetChapterBonusList(chapterID, index);
  109. //foreach (ItemData itemData in bonusList)
  110. //{
  111. // ItemDataManager.Add(itemData.id, itemData.num);
  112. //}
  113. //Dictionary<int, int> statusDic = null;
  114. //if (_chapterBonusDic.ContainsKey(chapterID))
  115. //{
  116. // statusDic = _chapterBonusDic[chapterID];
  117. //}
  118. //else
  119. //{
  120. // statusDic = new Dictionary<int, int>();
  121. // _chapterBonusDic.Add(chapterID, statusDic);
  122. // statusDic[0] = ConstBonusStatus.CAN_NOT_GET;
  123. // statusDic[1] = ConstBonusStatus.CAN_NOT_GET;
  124. // statusDic[2] = ConstBonusStatus.CAN_NOT_GET;
  125. //}
  126. //statusDic[index] = ConstBonusStatus.GOT;
  127. //string boxStatus = GetBoxStatus(currentChapter);
  128. //int starCountChapter = GetChapterStarCount(currentChapter);
  129. //GameProxy.ReqUpdateStoryStar(currentChapter, starCountChapter, boxStatus);
  130. return bonusList;
  131. }
  132. public static bool CheckOpenMainUI()
  133. {
  134. return InstanceZonesDataManager.CheckLevelPass(10004) && GuideDataManager.GetGuideCountCopy(ConstGuideId.SINGLE_FIGHT) > 0;
  135. }
  136. //检查指定章节对应的普通章节是否通关
  137. public static bool CheckNeedChapterPass(int chapterId, out int needChapterId)
  138. {
  139. StoryChapterCfg chapterCfg = StoryChapterCfgArray.Instance.GetCfg(chapterId);
  140. needChapterId = chapterCfg.needChapterId;
  141. if (chapterCfg.needChapterId > 0)
  142. {
  143. var preChapterCfg = StoryChapterCfgArray.Instance.GetCfg(chapterCfg.needChapterId);
  144. if (preChapterCfg != null)
  145. {
  146. return InstanceZonesDataManager.CheckChapterPass(preChapterCfg.type, preChapterCfg.subType, preChapterCfg.id, preChapterCfg.levelCount);
  147. }
  148. }
  149. return true;
  150. }
  151. public static bool CheckChapterUnlock(int chapterId)
  152. {
  153. StoryChapterCfg chapterCfg = StoryChapterCfgArray.Instance.GetCfg(chapterId);
  154. if (GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl) < chapterCfg.lvl)
  155. {
  156. return false;
  157. }
  158. //上一关卡
  159. int preChapterId = chapterId - 1;
  160. var preChapterCfg = StoryChapterCfgArray.Instance.GetCfg(preChapterId);
  161. if(preChapterCfg != null)
  162. {
  163. return InstanceZonesDataManager.CheckChapterPass(preChapterCfg.type, preChapterCfg.subType, preChapterCfg.id, preChapterCfg.levelCount);
  164. }
  165. //前置关卡
  166. return CheckNeedChapterPass(chapterId, out var needChapterId);
  167. }
  168. public static bool CheckLevelUnlock(int levelCfgId)
  169. {
  170. var levelCfg = StoryLevelCfgArray.Instance.GetCfg(levelCfgId);
  171. if (levelCfg != null)
  172. {
  173. if (!CheckChapterUnlock(levelCfg.chapterId))
  174. {
  175. return false;
  176. }
  177. var passLevelOrder = InstanceZonesDataManager.GetPassLevelOrder(levelCfg.type, levelCfg.subType, levelCfg.chapterId);
  178. return levelCfg.order <= passLevelOrder + 1;
  179. }
  180. return false;
  181. }
  182. public static bool CheckCurrentLevelPass()
  183. {
  184. return InstanceZonesDataManager.CheckLevelPass(currentLevelCfgId);
  185. }
  186. public static int GetScoreHighest(int levelID)
  187. {
  188. if (_highestScoreDic.ContainsKey(levelID))
  189. {
  190. return _highestScoreDic[levelID];
  191. }
  192. return 0;
  193. }
  194. public static bool GetFightResult(int score, out int npcScore)
  195. {
  196. npcScore = 0;
  197. bool equipedNeeded = EquipDataCache.cacher.CheckEquipedFightNeeded();
  198. if (!equipedNeeded)
  199. {
  200. PromptController.Instance.ShowFloatTextPrompt("未穿必需物品");
  201. return false;//没穿必需品
  202. }
  203. int starCount = StoryDataManager.GetResultStarCount(score);
  204. if (starCount <= 0)
  205. {
  206. return false;//低于一星
  207. }
  208. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(StoryDataManager.currentLevelCfgId);
  209. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  210. bool hasFightTarget = fightCfg.targetName != null && fightCfg.targetName.Length > 0;
  211. if (hasFightTarget)
  212. {
  213. npcScore = EquipDataCache.cacher.npcTotalScore;
  214. if(score < npcScore)
  215. {
  216. return false;//分数低于对战对象
  217. }
  218. }
  219. return true;
  220. }
  221. public static int GetResultStarCount(int score)
  222. {
  223. return CalculateHelper.GetStoryChapterStar(currentLevelCfgId, score);
  224. }
  225. public static int GetStarCountHistory(int levelID)
  226. {
  227. _starDic.TryGetValue(levelID, out var star);
  228. return star;
  229. }
  230. public static bool CheckCurrentScoreEnough(int score)
  231. {
  232. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(currentLevelCfgId);
  233. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  234. return (score > fightCfg.score1);
  235. }
  236. public static int GetChapterStarCount(int chapterID)
  237. {
  238. var star = 0;
  239. foreach(var item in _starDic)
  240. {
  241. CalculateHelper.GetStoryChapterLevel(item.Key, out var tempChapter, out var levelOrder);
  242. if(tempChapter == chapterID)
  243. {
  244. star += item.Value;
  245. }
  246. }
  247. return star;
  248. }
  249. public static int GetCanFightTime(int levelID)
  250. {
  251. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(levelID);
  252. int times = (int)Math.Floor((float)GameGlobal.myNumericComponent.GetAsInt(NumericType.Power) / levelCfg.power);
  253. return times;
  254. }
  255. }
  256. }