StoryDataManager.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  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 currentChapterCfgId = 0;
  12. public static int currentLevelOrder = 0;
  13. //关卡配置表的id
  14. public static int currentLevelCfgId;
  15. //当前关卡序号,从1开始
  16. public static int CurrentChapterOrder
  17. {
  18. get
  19. {
  20. var chapterCfg = StoryChapterCfgArray.Instance.GetCfg(currentChapterCfgId);
  21. if(chapterCfg != null)
  22. {
  23. return chapterCfg.order;
  24. }
  25. return 0;
  26. }
  27. }
  28. public static int currentScoreType;
  29. public static int currentCardId = 0;
  30. public static bool usedRecommend;
  31. //关卡最高分数记录
  32. private static Dictionary<int, int> _highestScoreDic = new Dictionary<int, int>();
  33. //关卡星数记录
  34. private static Dictionary<int, int> _starDic = new Dictionary<int, int>();
  35. //关卡宝箱状态记录
  36. private static Dictionary<int, int[]> _chapterBonusDic = new Dictionary<int, int[]>();
  37. public static void InitScoreList(List<int> ks, List<int> vs)
  38. {
  39. usedRecommend = false;
  40. _highestScoreDic.Clear();
  41. for (var i = 0; i < ks.Count; ++i)
  42. {
  43. _highestScoreDic.Add(ks[i], vs[i]);
  44. }
  45. }
  46. public static void InitStarList(List<int> ks, List<int> vs)
  47. {
  48. _starDic.Clear();
  49. for(var i = 0; i < ks.Count; ++i)
  50. {
  51. _starDic.Add(ks[i], vs[i]);
  52. }
  53. }
  54. public static void InitBoxBonusStates(List<int> ks, List<int> vs)
  55. {
  56. _chapterBonusDic.Clear();
  57. for (var i = 0; i < ks.Count; ++i)
  58. {
  59. var states = new int[] { 0, 0, 0 };
  60. var value = vs[i];
  61. CalculateHelper.GenerateChapterBoxStates(states, value);
  62. _chapterBonusDic.Add(ks[i], states);
  63. }
  64. }
  65. public static void UpdateBoxBonusStates(int chapter, int stateInt)
  66. {
  67. if (!_chapterBonusDic.TryGetValue(chapter, out var states))
  68. {
  69. states = new int[] { 0, 0, 0 };
  70. _chapterBonusDic.Add(chapter, states);
  71. }
  72. CalculateHelper.GenerateChapterBoxStates(states, stateInt);
  73. }
  74. //检查更新最高分
  75. public static void TryUpdateScore(int levelCfgId, int score)
  76. {
  77. _highestScoreDic.TryGetValue(levelCfgId, out var scoreHighest);
  78. if (score > scoreHighest)
  79. {
  80. _highestScoreDic[currentLevelCfgId] = score;
  81. }
  82. }
  83. //检查并更新关卡星数
  84. public static void TryUpdateLevelStar(int levelCfgId, int star)
  85. {
  86. _starDic.TryGetValue(levelCfgId, out var OldStar);
  87. if(star > OldStar)
  88. {
  89. _starDic[levelCfgId] = star;
  90. }
  91. }
  92. //获取宝箱奖励状态
  93. public static int GetChapterBonusStatus(int chapterID, int index)
  94. {
  95. if (_chapterBonusDic.ContainsKey(chapterID))
  96. {
  97. var states = _chapterBonusDic[chapterID];
  98. if (states != null)
  99. {
  100. return states[index];
  101. }
  102. }
  103. return ConstBonusStatus.CAN_NOT_GET;
  104. }
  105. public static List<ItemData> GetChapterBonus(int chapterID, int index)
  106. {
  107. List<ItemData> bonusList = StoryBonusDataCache.GetChapterBonusList(chapterID, index);
  108. //foreach (ItemData itemData in bonusList)
  109. //{
  110. // ItemDataManager.Add(itemData.id, itemData.num);
  111. //}
  112. //Dictionary<int, int> statusDic = null;
  113. //if (_chapterBonusDic.ContainsKey(chapterID))
  114. //{
  115. // statusDic = _chapterBonusDic[chapterID];
  116. //}
  117. //else
  118. //{
  119. // statusDic = new Dictionary<int, int>();
  120. // _chapterBonusDic.Add(chapterID, statusDic);
  121. // statusDic[0] = ConstBonusStatus.CAN_NOT_GET;
  122. // statusDic[1] = ConstBonusStatus.CAN_NOT_GET;
  123. // statusDic[2] = ConstBonusStatus.CAN_NOT_GET;
  124. //}
  125. //statusDic[index] = ConstBonusStatus.GOT;
  126. //string boxStatus = GetBoxStatus(currentChapter);
  127. //int starCountChapter = GetChapterStarCount(currentChapter);
  128. //GameProxy.ReqUpdateStoryStar(currentChapter, starCountChapter, boxStatus);
  129. return bonusList;
  130. }
  131. public static bool CheckOpenMainUI()
  132. {
  133. return CheckLevelPass(1, 4) && GuideDataManager.GetGuideCountCopy(ConstGuideId.SINGLE_FIGHT) > 0;
  134. }
  135. //检查指定章节对应的普通章节是否通关
  136. public static bool CheckNormalChapterPass(int chapterId)
  137. {
  138. int normalChapterId = StoryUtil.GetChapterOrder(chapterId);
  139. return normalChapterId <= GameGlobal.myNumericComponent.GetAsInt(NumericType.Chapter);
  140. }
  141. public static bool CheckChapterUnlock(int chapterId)
  142. {
  143. StoryChapterCfg chapterCfg = StoryChapterCfgArray.Instance.GetCfg(chapterId);
  144. if (GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl) < chapterCfg.lvl)
  145. {
  146. return false;
  147. }
  148. if (CalculateHelper.CheckChapterIsHard(chapterId))
  149. {
  150. //对应普通剧情的章需要开启
  151. if (!CheckNormalChapterPass(chapterId))
  152. {
  153. return false;
  154. }
  155. //前一精英章需要通关
  156. if (chapterId - 1 > GameGlobal.myNumericComponent.GetAsInt(NumericType.ChapterJY))
  157. {
  158. return false;
  159. }
  160. }
  161. else
  162. {
  163. if (chapterId - 1 > GameGlobal.myNumericComponent.GetAsInt(NumericType.Chapter))
  164. {
  165. return false;
  166. }
  167. }
  168. return true;
  169. }
  170. public static bool CheckLevelPass(int chapterId, int levelOrder)
  171. {
  172. int passChapterOrder = GetPassChapter(chapterId);
  173. int passLevelOrder = GetPassLevel(chapterId);
  174. return CalculateHelper.CheckLevelPass(chapterId, levelOrder, passChapterOrder, passLevelOrder);
  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. }