StoryDataManager.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System;
  4. using UnityEngine;
  5. using ET;
  6. namespace GFGGame
  7. {
  8. public class StoryDataManager
  9. {
  10. public static string priorId = "prior";//首次登录前置剧情id
  11. public static int currentChapter = 0;
  12. public static int currentLevel = 0;
  13. //配置表的id
  14. public static int currentLevelCfgId;
  15. public static int currentScoreType;
  16. public static int currentCardId = 0;
  17. public static bool usedRecommend;
  18. public static int _passChapter = 0;
  19. public static int _passLevel = 0;
  20. private static int _passChapterJY = 10000;
  21. private static int _passLevelJY = 0;
  22. //关卡最高分数记录
  23. private static Dictionary<int, int> _highestScoreDic = new Dictionary<int, int>();
  24. //关卡星数记录
  25. private static Dictionary<int, int> _starDic = new Dictionary<int, int>();
  26. //关卡宝箱状态记录
  27. private static Dictionary<int, int[]> _chapterBonusDic = new Dictionary<int, int[]>();
  28. public static void InitScoreList(List<int> ks, List<int> vs)
  29. {
  30. usedRecommend = false;
  31. _highestScoreDic.Clear();
  32. for (var i = 0; i < ks.Count; ++i)
  33. {
  34. _highestScoreDic.Add(ks[i], vs[i]);
  35. }
  36. }
  37. public static void InitStarList(List<int> ks, List<int> vs)
  38. {
  39. _starDic.Clear();
  40. for(var i = 0; i < ks.Count; ++i)
  41. {
  42. _starDic.Add(ks[i], vs[i]);
  43. }
  44. }
  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 void TryUpdateScore(int levelCfgId, int score)
  67. {
  68. _highestScoreDic.TryGetValue(levelCfgId, out var scoreHighest);
  69. if (score > scoreHighest)
  70. {
  71. _highestScoreDic[currentLevelCfgId] = score;
  72. }
  73. }
  74. //检查并更新关卡星数
  75. public static void TryUpdateLevelStar(int levelCfgId, int star)
  76. {
  77. _starDic.TryGetValue(levelCfgId, out var OldStar);
  78. if(star > OldStar)
  79. {
  80. _starDic[levelCfgId] = star;
  81. }
  82. }
  83. //获取宝箱奖励状态
  84. public static int GetChapterBonusStatus(int chapterID, int index)
  85. {
  86. if (_chapterBonusDic.ContainsKey(chapterID))
  87. {
  88. var states = _chapterBonusDic[chapterID];
  89. if (states != null)
  90. {
  91. return states[index];
  92. }
  93. }
  94. return ConstBonusStatus.CAN_NOT_GET;
  95. }
  96. public static List<ItemData> GetChapterBonus(int chapterID, int index)
  97. {
  98. List<ItemData> bonusList = StoryBonusDataCache.GetChapterBonusList(chapterID, index);
  99. //foreach (ItemData itemData in bonusList)
  100. //{
  101. // ItemDataManager.Add(itemData.id, itemData.num);
  102. //}
  103. //Dictionary<int, int> statusDic = null;
  104. //if (_chapterBonusDic.ContainsKey(chapterID))
  105. //{
  106. // statusDic = _chapterBonusDic[chapterID];
  107. //}
  108. //else
  109. //{
  110. // statusDic = new Dictionary<int, int>();
  111. // _chapterBonusDic.Add(chapterID, statusDic);
  112. // statusDic[0] = ConstBonusStatus.CAN_NOT_GET;
  113. // statusDic[1] = ConstBonusStatus.CAN_NOT_GET;
  114. // statusDic[2] = ConstBonusStatus.CAN_NOT_GET;
  115. //}
  116. //statusDic[index] = ConstBonusStatus.GOT;
  117. //string boxStatus = GetBoxStatus(currentChapter);
  118. //int starCountChapter = GetChapterStarCount(currentChapter);
  119. //GameProxy.ReqUpdateStoryStar(currentChapter, starCountChapter, boxStatus);
  120. return bonusList;
  121. }
  122. public static bool CheckOpenMainUI()
  123. {
  124. return CheckLevelPass(1, 4) && GuideDataManager.GetGuideCountCopy(ConstGuideId.SINGLE_FIGHT) > 0;
  125. }
  126. //检查指定章节对应的普通章节是否通关
  127. public static bool CheckNormalChapterPass(int chapterId)
  128. {
  129. int normalChapterId = StoryUtil.GetNormalChapterId(chapterId);
  130. return normalChapterId <= GameGlobal.myNumericComponent.GetAsInt(NumericType.Chapter);
  131. }
  132. public static bool CheckChapterUnlock(int chapterId)
  133. {
  134. StoryChapterCfg chapterCfg = StoryChapterCfgArray.Instance.GetCfg(chapterId);
  135. if (GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl) < chapterCfg.lvl)
  136. {
  137. return false;
  138. }
  139. if (CalculateHelper.CheckChapterIsHard(chapterId))
  140. {
  141. //对应普通剧情的章需要开启
  142. if (!CheckNormalChapterPass(chapterId))
  143. {
  144. return false;
  145. }
  146. //前一精英章需要通关
  147. if (chapterId - 1 > GameGlobal.myNumericComponent.GetAsInt(NumericType.ChapterJY))
  148. {
  149. return false;
  150. }
  151. }
  152. else
  153. {
  154. if (chapterId - 1 > GameGlobal.myNumericComponent.GetAsInt(NumericType.Chapter))
  155. {
  156. return false;
  157. }
  158. }
  159. return true;
  160. }
  161. public static bool CheckLevelPass(int chapterId, int level)
  162. {
  163. int passChapter = GetPassChapter(chapterId);
  164. int passLevel = GetPassLevel(chapterId);
  165. return CalculateHelper.CheckLevelPass(chapterId, level, passChapter, passLevel);
  166. }
  167. public static bool CheckLevelUnlock(int chapterId, int level)
  168. {
  169. int passChapter = GetPassChapter(chapterId);
  170. int passLevel = GetPassLevel(chapterId);
  171. if (chapterId <= passChapter)
  172. {
  173. return true;
  174. }
  175. if (chapterId == passChapter + 1 && level <= passLevel + 1)
  176. {
  177. return true;
  178. }
  179. return false;
  180. }
  181. public static bool CheckCurrentLevelPass()
  182. {
  183. return CheckLevelPass(currentChapter, currentLevel);
  184. }
  185. public static int GetScoreHighest(int levelID)
  186. {
  187. if (_highestScoreDic.ContainsKey(levelID))
  188. {
  189. return _highestScoreDic[levelID];
  190. }
  191. return 0;
  192. }
  193. public static bool GetFightResult(int score, out int npcScore)
  194. {
  195. npcScore = 0;
  196. bool equipedNeeded = EquipDataCache.cacher.CheckEquipedFightNeeded();
  197. if (!equipedNeeded)
  198. {
  199. PromptController.Instance.ShowFloatTextPrompt("未穿必需物品");
  200. return false;//没穿必需品
  201. }
  202. int starCount = StoryDataManager.GetResultStarCount(score);
  203. if (starCount <= 0)
  204. {
  205. return false;//低于一星
  206. }
  207. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(StoryDataManager.currentLevelCfgId);
  208. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  209. bool hasFightTarget = fightCfg.targetName != null && fightCfg.targetName.Length > 0;
  210. if (hasFightTarget)
  211. {
  212. npcScore = EquipDataCache.cacher.npcTotalScore;
  213. if(score < npcScore)
  214. {
  215. return false;//分数低于对战对象
  216. }
  217. }
  218. return true;
  219. }
  220. public static int GetResultStarCount(int score)
  221. {
  222. return CalculateHelper.GetStoryChapterStar(currentLevelCfgId, score);
  223. }
  224. public static int GetStarCountHistory(int levelID)
  225. {
  226. _starDic.TryGetValue(levelID, out var star);
  227. return star;
  228. }
  229. public static bool CheckCurrentScoreEnough(int score)
  230. {
  231. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(currentLevelCfgId);
  232. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  233. return (score > fightCfg.score1);
  234. }
  235. public static int GetPassChapter(int fromChapter)
  236. {
  237. if (CalculateHelper.CheckChapterIsHard(fromChapter))
  238. {
  239. return GameGlobal.myNumericComponent.GetAsInt(NumericType.ChapterJY);
  240. }
  241. return GameGlobal.myNumericComponent.GetAsInt(NumericType.Chapter);
  242. }
  243. public static int GetPassLevel(int fromChapter)
  244. {
  245. if (CalculateHelper.CheckChapterIsHard(fromChapter))
  246. {
  247. return GameGlobal.myNumericComponent.GetAsInt(NumericType.ChapterLvlJY);
  248. }
  249. return GameGlobal.myNumericComponent.GetAsInt(NumericType.ChapterLvl);
  250. }
  251. public static List<ItemData> PassCurrentLevel(out bool fistPassLastLvl, out bool curLvfirstPass)
  252. {
  253. fistPassLastLvl = false;
  254. curLvfirstPass = false;
  255. List<ItemData> currentBonusList = new List<ItemData>();
  256. //if (!CheckCurrentLevelPass())
  257. //{
  258. // curLvfirstPass = true;
  259. // int tempPassLevel = currentLevel;
  260. // int tempPassChapter = GetPassChapter(currentChapter);
  261. // int nextLevel = currentLevel + 1;
  262. // int nextLevelID = currentChapter*GameConst.STORY_LEVEL_KEY_NUM + nextLevel;
  263. // StoryLevelCfg nextLevelCfg = StoryLevelCfgArray.Instance.GetCfg(nextLevelID);
  264. // if (nextLevelCfg == null)
  265. // {
  266. // tempPassChapter = currentChapter;
  267. // tempPassLevel = 0;
  268. // fistPassLastLvl = true;
  269. // }
  270. // SetPassData(tempPassChapter, tempPassLevel);
  271. // GameProxy.ReqUpdateStoryProgress(_passChapter, _passLevel, _passChapterJY, _passLevelJY);
  272. // currentBonusList = StoryBonusDataCache.GetBonusList(currentLevelID, true, true);
  273. //}
  274. //else
  275. //{
  276. //currentBonusList = StoryBonusDataCache.GetBonusList(currentLevelID, false, true);
  277. //}
  278. //StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(StoryDataManager.currentLevelID);
  279. ////消耗体力
  280. //if (currentBonusList != null && currentBonusList.Count > 0)
  281. //{
  282. // if (GameGlobal.myNumericComponent.GetAsInt(NumericType.Power) >= levelCfg.power)
  283. // {
  284. // RoleDataManager.power -= levelCfg.power;
  285. // }
  286. // else
  287. // {
  288. // RoleDataManager.power = 0;
  289. // }
  290. //}
  291. //消耗推荐次数
  292. //if (usedRecommend)
  293. //{
  294. // usedRecommend = false;
  295. // //_recommendCount--;
  296. // //GameProxy.ReqUpdateRecommendCount(_recommendCount);
  297. //}
  298. //经验奖励
  299. //if (levelCfg.fightID != null && levelCfg.fightID.Length > 0)
  300. //{
  301. // StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  302. // RoleDataManager.exp += fightCfg.exp;
  303. //}
  304. //foreach (ItemData itemData in currentBonusList)
  305. //{
  306. // ItemDataManager.Add(itemData.id, itemData.num);
  307. //}
  308. return currentBonusList;
  309. }
  310. public static int GetChapterStarCount(int chapterID)
  311. {
  312. var star = 0;
  313. foreach(var item in _starDic)
  314. {
  315. var tempChapter = item.Key / GameConst.STORY_LEVEL_KEY_NUM;
  316. if(tempChapter == chapterID)
  317. {
  318. star += item.Value;
  319. }
  320. }
  321. return star;
  322. }
  323. public static int GetCanFightTime(int levelID)
  324. {
  325. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(levelID);
  326. int times = (int)Math.Floor((float)GameGlobal.myNumericComponent.GetAsInt(NumericType.Power) / levelCfg.power);
  327. return times;
  328. }
  329. }
  330. }