StoryDataManager.cs 13 KB

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