StoryDataManager.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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)
  138. {
  139. var chapterCfg = StoryChapterCfgArray.Instance.GetCfg(chapterId);
  140. if (chapterCfg != null)
  141. {
  142. var passLevelOrder = InstanceZonesDataManager.GetPassLevelOrder(chapterCfg.type, chapterCfg.subType, chapterCfg.id);
  143. return chapterCfg.levelCount <= passLevelOrder;
  144. }
  145. return false;
  146. }
  147. public static bool CheckChapterUnlock(int chapterId)
  148. {
  149. StoryChapterCfg chapterCfg = StoryChapterCfgArray.Instance.GetCfg(chapterId);
  150. if (GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl) < chapterCfg.lvl)
  151. {
  152. return false;
  153. }
  154. if (CalculateHelper.CheckChapterIsHard(chapterId))
  155. {
  156. //对应普通剧情的章需要开启
  157. if (!CheckNeedChapterPass(chapterId))
  158. {
  159. return false;
  160. }
  161. //前一精英章需要通关
  162. if (chapterId - 1 > GameGlobal.myNumericComponent.GetAsInt(NumericType.ChapterJY))
  163. {
  164. return false;
  165. }
  166. }
  167. else
  168. {
  169. if (chapterId - 1 > GameGlobal.myNumericComponent.GetAsInt(NumericType.Chapter))
  170. {
  171. return false;
  172. }
  173. }
  174. return true;
  175. }
  176. public static bool CheckLevelUnlock(int chapterId, int level)
  177. {
  178. int passChapter = GetPassChapter(chapterId);
  179. int passLevel = GetPassLevel(chapterId);
  180. if (chapterId <= passChapter)
  181. {
  182. return true;
  183. }
  184. if (chapterId == passChapter + 1 && level <= passLevel + 1)
  185. {
  186. return true;
  187. }
  188. return false;
  189. }
  190. public static bool CheckCurrentLevelPass()
  191. {
  192. return InstanceZonesDataManager.CheckLevelPass(currentLevelCfgId);
  193. }
  194. public static int GetScoreHighest(int levelID)
  195. {
  196. if (_highestScoreDic.ContainsKey(levelID))
  197. {
  198. return _highestScoreDic[levelID];
  199. }
  200. return 0;
  201. }
  202. public static bool GetFightResult(int score, out int npcScore)
  203. {
  204. npcScore = 0;
  205. bool equipedNeeded = EquipDataCache.cacher.CheckEquipedFightNeeded();
  206. if (!equipedNeeded)
  207. {
  208. PromptController.Instance.ShowFloatTextPrompt("未穿必需物品");
  209. return false;//没穿必需品
  210. }
  211. int starCount = StoryDataManager.GetResultStarCount(score);
  212. if (starCount <= 0)
  213. {
  214. return false;//低于一星
  215. }
  216. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(StoryDataManager.currentLevelCfgId);
  217. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  218. bool hasFightTarget = fightCfg.targetName != null && fightCfg.targetName.Length > 0;
  219. if (hasFightTarget)
  220. {
  221. npcScore = EquipDataCache.cacher.npcTotalScore;
  222. if(score < npcScore)
  223. {
  224. return false;//分数低于对战对象
  225. }
  226. }
  227. return true;
  228. }
  229. public static int GetResultStarCount(int score)
  230. {
  231. return CalculateHelper.GetStoryChapterStar(currentLevelCfgId, score);
  232. }
  233. public static int GetStarCountHistory(int levelID)
  234. {
  235. _starDic.TryGetValue(levelID, out var star);
  236. return star;
  237. }
  238. public static bool CheckCurrentScoreEnough(int score)
  239. {
  240. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(currentLevelCfgId);
  241. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  242. return (score > fightCfg.score1);
  243. }
  244. public static int GetPassChapter(int fromChapter)
  245. {
  246. if (CalculateHelper.CheckChapterIsHard(fromChapter))
  247. {
  248. return GameGlobal.myNumericComponent.GetAsInt(NumericType.ChapterJY);
  249. }
  250. return GameGlobal.myNumericComponent.GetAsInt(NumericType.Chapter);
  251. }
  252. public static int GetPassLevel(int fromChapter)
  253. {
  254. if (CalculateHelper.CheckChapterIsHard(fromChapter))
  255. {
  256. return GameGlobal.myNumericComponent.GetAsInt(NumericType.ChapterLvlJY);
  257. }
  258. return GameGlobal.myNumericComponent.GetAsInt(NumericType.ChapterLvl);
  259. }
  260. public static List<ItemData> PassCurrentLevel(out bool fistPassLastLvl, out bool curLvfirstPass)
  261. {
  262. fistPassLastLvl = false;
  263. curLvfirstPass = false;
  264. List<ItemData> currentBonusList = new List<ItemData>();
  265. //if (!CheckCurrentLevelPass())
  266. //{
  267. // curLvfirstPass = true;
  268. // int tempPassLevel = currentLevel;
  269. // int tempPassChapter = GetPassChapter(currentChapter);
  270. // int nextLevel = currentLevel + 1;
  271. // int nextLevelID = currentChapter*GameConst.STORY_LEVEL_KEY_NUM + nextLevel;
  272. // StoryLevelCfg nextLevelCfg = StoryLevelCfgArray.Instance.GetCfg(nextLevelID);
  273. // if (nextLevelCfg == null)
  274. // {
  275. // tempPassChapter = currentChapter;
  276. // tempPassLevel = 0;
  277. // fistPassLastLvl = true;
  278. // }
  279. // SetPassData(tempPassChapter, tempPassLevel);
  280. // GameProxy.ReqUpdateStoryProgress(_passChapter, _passLevel, _passChapterJY, _passLevelJY);
  281. // currentBonusList = StoryBonusDataCache.GetBonusList(currentLevelID, true, true);
  282. //}
  283. //else
  284. //{
  285. //currentBonusList = StoryBonusDataCache.GetBonusList(currentLevelID, false, true);
  286. //}
  287. //StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(StoryDataManager.currentLevelID);
  288. ////消耗体力
  289. //if (currentBonusList != null && currentBonusList.Count > 0)
  290. //{
  291. // if (GameGlobal.myNumericComponent.GetAsInt(NumericType.Power) >= levelCfg.power)
  292. // {
  293. // RoleDataManager.power -= levelCfg.power;
  294. // }
  295. // else
  296. // {
  297. // RoleDataManager.power = 0;
  298. // }
  299. //}
  300. //消耗推荐次数
  301. //if (usedRecommend)
  302. //{
  303. // usedRecommend = false;
  304. // //_recommendCount--;
  305. // //GameProxy.ReqUpdateRecommendCount(_recommendCount);
  306. //}
  307. //经验奖励
  308. //if (levelCfg.fightID != null && levelCfg.fightID.Length > 0)
  309. //{
  310. // StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  311. // RoleDataManager.exp += fightCfg.exp;
  312. //}
  313. //foreach (ItemData itemData in currentBonusList)
  314. //{
  315. // ItemDataManager.Add(itemData.id, itemData.num);
  316. //}
  317. return currentBonusList;
  318. }
  319. public static int GetChapterStarCount(int chapterID)
  320. {
  321. var star = 0;
  322. foreach(var item in _starDic)
  323. {
  324. CalculateHelper.GetStoryChapterLevel(item.Key, out var tempChapter, out var levelOrder);
  325. if(tempChapter == chapterID)
  326. {
  327. star += item.Value;
  328. }
  329. }
  330. return star;
  331. }
  332. public static int GetCanFightTime(int levelID)
  333. {
  334. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(levelID);
  335. int times = (int)Math.Floor((float)GameGlobal.myNumericComponent.GetAsInt(NumericType.Power) / levelCfg.power);
  336. return times;
  337. }
  338. }
  339. }