StoryDataManager.cs 13 KB

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