StoryDataManager.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  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. public static string currentLevelID;
  14. public static int currentScoreType;
  15. public static int currentCardId = 0;
  16. public static bool usedRecommend;
  17. public static int _passChapter = 0;
  18. public static int _passLevel = 0;
  19. private static int _passChapterJY = 10000;
  20. private static int _passLevelJY = 0;
  21. private static int _recommendCount = 0;
  22. public static int recommendDay = -1;
  23. public static int recommendCount
  24. {
  25. get
  26. {
  27. return _recommendCount;
  28. }
  29. }
  30. private static Dictionary<string, int> _highestScoreDic = new Dictionary<string, int>();
  31. private static Dictionary<int, int> _chapterStarCountDic = new Dictionary<int, int>();
  32. private static Dictionary<int, Dictionary<int, int>> _chapterBonusDic = new Dictionary<int, Dictionary<int, int>>();
  33. public static void InitServerData(RoleInfo roleInfo)
  34. {
  35. usedRecommend = false;
  36. _recommendCount = roleInfo.recommendCount;
  37. recommendDay = roleInfo.recommendDay;
  38. }
  39. public static void InitScoreList(List<StoryScore> list)
  40. {
  41. _highestScoreDic.Clear();
  42. if (list != null)
  43. {
  44. foreach (StoryScore value in list)
  45. {
  46. _highestScoreDic[value.lvlId] = value.score;
  47. }
  48. }
  49. }
  50. public static void InitStarList(List<StoryStar> list)
  51. {
  52. _chapterStarCountDic.Clear();
  53. _chapterBonusDic.Clear();
  54. if (list != null)
  55. {
  56. foreach (StoryStar value in list)
  57. {
  58. int chapterID = value.chapterId;
  59. _chapterStarCountDic[chapterID] = value.star;
  60. if (value.boxStatus != null && value.boxStatus.Length > 0)
  61. {
  62. Dictionary<int, int> statusDic = null;
  63. if (_chapterBonusDic.ContainsKey(chapterID))
  64. {
  65. statusDic = _chapterBonusDic[chapterID];
  66. }
  67. else
  68. {
  69. statusDic = new Dictionary<int, int>();
  70. _chapterBonusDic.Add(chapterID, statusDic);
  71. }
  72. string[] statusStrs = value.boxStatus.Split(';');
  73. for (int i = 0; i < statusStrs.Length; i++)
  74. {
  75. string statusStr = statusStrs[i];
  76. int status = int.Parse(statusStr);
  77. statusDic[i] = status;
  78. }
  79. }
  80. }
  81. }
  82. }
  83. public static void ResetDailyData()
  84. {
  85. _recommendCount = GameConst.MAX_COUNT_RECOMMEND;
  86. int day = ServerDataManager.CurrentDay;
  87. recommendDay = day;
  88. GameProxy.ReqUpdateRecommendCount(_recommendCount);
  89. }
  90. public static void SetPassData(int chapter, int chapterLvl)
  91. {
  92. if (StoryUtil.CheckChapterIsHard(chapter))
  93. {
  94. //_passChapterJY = chapter;
  95. //_passLevelJY = chapterLvl;
  96. }
  97. else
  98. {
  99. //_passChapter = chapter;
  100. //_passLevel = chapterLvl;
  101. }
  102. }
  103. public static int GetChapterBonusStatus(int chapterID, int index)
  104. {
  105. if (_chapterBonusDic.ContainsKey(chapterID))
  106. {
  107. Dictionary<int, int> statusDic = _chapterBonusDic[chapterID];
  108. if (statusDic != null)
  109. {
  110. if (statusDic.ContainsKey(index))
  111. {
  112. return statusDic[index];
  113. }
  114. }
  115. }
  116. return ConstBonusStatus.CAN_NOT_GET;
  117. }
  118. public static List<ItemData> GetChapterBonus(int chapterID, int index)
  119. {
  120. List<ItemData> bonusList = StoryBonusDataCache.GetChapterBonusList(chapterID, index);
  121. foreach (ItemData itemData in bonusList)
  122. {
  123. ItemDataManager.Add(itemData.id, itemData.num);
  124. }
  125. Dictionary<int, int> statusDic = null;
  126. if (_chapterBonusDic.ContainsKey(chapterID))
  127. {
  128. statusDic = _chapterBonusDic[chapterID];
  129. }
  130. else
  131. {
  132. statusDic = new Dictionary<int, int>();
  133. _chapterBonusDic.Add(chapterID, statusDic);
  134. statusDic[0] = ConstBonusStatus.CAN_NOT_GET;
  135. statusDic[1] = ConstBonusStatus.CAN_NOT_GET;
  136. statusDic[2] = ConstBonusStatus.CAN_NOT_GET;
  137. }
  138. statusDic[index] = ConstBonusStatus.GOT;
  139. string boxStatus = GetBoxStatus(currentChapter);
  140. int starCountChapter = GetChapterStarCount(currentChapter);
  141. GameProxy.ReqUpdateStoryStar(currentChapter, starCountChapter, boxStatus);
  142. return bonusList;
  143. }
  144. public static void UpdateChapterBonusStatus(int chapterID, int starCount)
  145. {
  146. StoryChapterCfg storyChapterCfg = StoryChapterCfgArray.Instance.GetCfg(chapterID);
  147. if (starCount >= storyChapterCfg.bonusStar1)
  148. {
  149. Dictionary<int, int> statusDic = null;
  150. if (_chapterBonusDic.ContainsKey(chapterID))
  151. {
  152. statusDic = _chapterBonusDic[chapterID];
  153. }
  154. else
  155. {
  156. statusDic = new Dictionary<int, int>();
  157. _chapterBonusDic.Add(chapterID, statusDic);
  158. statusDic[0] = ConstBonusStatus.CAN_NOT_GET;
  159. statusDic[1] = ConstBonusStatus.CAN_NOT_GET;
  160. statusDic[2] = ConstBonusStatus.CAN_NOT_GET;
  161. }
  162. if (statusDic[0] == ConstBonusStatus.CAN_NOT_GET)
  163. {
  164. statusDic[0] = ConstBonusStatus.CAN_GET;
  165. }
  166. if (starCount >= storyChapterCfg.bonusStar2 && statusDic[1] == ConstBonusStatus.CAN_NOT_GET)
  167. {
  168. statusDic[1] = ConstBonusStatus.CAN_GET;
  169. }
  170. if (starCount >= storyChapterCfg.bonusStar3 && statusDic[2] == ConstBonusStatus.CAN_NOT_GET)
  171. {
  172. statusDic[2] = ConstBonusStatus.CAN_GET;
  173. }
  174. }
  175. }
  176. public static bool CheckOpenMainUI()
  177. {
  178. return CheckLevelPass(1, 4) && GuideDataManager.GetGuideCountCopy(ConstGuideId.SINGLE_FIGHT) > 0;
  179. }
  180. //检查指定章节对应的普通章节是否通关
  181. public static bool CheckNormalChapterPass(int chapterId)
  182. {
  183. int normalChapterId = StoryUtil.GetNormalChapterId(chapterId);
  184. return normalChapterId <= GameGlobal.myNumericComponent.GetAsInt(NumericType.Chapter);
  185. }
  186. public static bool CheckChapterUnlock(int chapterId)
  187. {
  188. StoryChapterCfg chapterCfg = StoryChapterCfgArray.Instance.GetCfg(chapterId);
  189. if (GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl) < chapterCfg.lvl)
  190. {
  191. return false;
  192. }
  193. if (StoryUtil.CheckChapterIsHard(chapterId))
  194. {
  195. //对应普通剧情的章需要开启
  196. if (!CheckNormalChapterPass(chapterId))
  197. {
  198. return false;
  199. }
  200. //前一精英章需要通关
  201. if (chapterId - 1 > GameGlobal.myNumericComponent.GetAsInt(NumericType.ChapterJY))
  202. {
  203. return false;
  204. }
  205. }
  206. else
  207. {
  208. if (chapterId - 1 > GameGlobal.myNumericComponent.GetAsInt(NumericType.Chapter))
  209. {
  210. return false;
  211. }
  212. }
  213. return true;
  214. }
  215. public static bool CheckLevelPass(int chapterId, int level)
  216. {
  217. int passChapter = GetPassChapter(chapterId);
  218. int passLevel = GetPassLevel(chapterId);
  219. if (chapterId <= passChapter)
  220. {
  221. return true;
  222. }
  223. if (chapterId == passChapter + 1 && level <= passLevel)
  224. {
  225. return true;
  226. }
  227. return false;
  228. }
  229. public static bool CheckLevelUnlock(int chapterId, int level)
  230. {
  231. int passChapter = GetPassChapter(chapterId);
  232. int passLevel = GetPassLevel(chapterId);
  233. if (chapterId <= passChapter)
  234. {
  235. return true;
  236. }
  237. if (chapterId == passChapter + 1 && level <= passLevel + 1)
  238. {
  239. return true;
  240. }
  241. return false;
  242. }
  243. public static bool CheckCurrentLevelPass()
  244. {
  245. return CheckLevelPass(currentChapter, currentLevel);
  246. }
  247. public static int GetScoreHighest(string levelID)
  248. {
  249. if (_highestScoreDic.ContainsKey(levelID))
  250. {
  251. return _highestScoreDic[levelID];
  252. }
  253. return 0;
  254. }
  255. public static void GetStoryId(string levelIdStr, out int chapterIdP, out int levelIdP)
  256. {
  257. string[] ids = levelIdStr.Split('_');
  258. chapterIdP = int.Parse(ids[0]);
  259. levelIdP = int.Parse(ids[1]);
  260. }
  261. public static int GetResultStarCount(int score)
  262. {
  263. if (!EquipDataCache.cacher.CheckEquipedFightNeeded())
  264. {
  265. return 0;
  266. }
  267. return CalculateHelper.GetStoryChapterStar(currentLevelID, score);
  268. }
  269. public static int GetStarCountHistory(string levelID, int score)
  270. {
  271. int chapterIdT = 0;
  272. int levelIdT = 0;
  273. GetStoryId(levelID, out chapterIdT, out levelIdT);
  274. if (!CheckLevelPass(chapterIdT, levelIdT))
  275. {
  276. return 0;
  277. }
  278. return CalculateHelper.GetStoryChapterStar(levelID, score);
  279. }
  280. public static bool CheckCurrentScoreEnough(int score)
  281. {
  282. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(currentLevelID);
  283. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  284. return (score > fightCfg.score1);
  285. }
  286. public static void SetScore(int score, int starCount)
  287. {
  288. int scoreHighest = 0;
  289. if (_highestScoreDic.ContainsKey(currentLevelID))
  290. {
  291. scoreHighest = _highestScoreDic[currentLevelID];
  292. }
  293. if (score > scoreHighest)
  294. {
  295. _highestScoreDic[currentLevelID] = score;
  296. GameProxy.ReqUpdateStoryScore(currentLevelID, score);
  297. int starCountSaved = GetStarCountHistory(currentLevelID, scoreHighest);
  298. int starCountChapter = 0;
  299. if (_chapterStarCountDic.ContainsKey(currentChapter))
  300. {
  301. starCountChapter = _chapterStarCountDic[currentChapter];
  302. }
  303. if (starCount > starCountSaved)
  304. {
  305. starCountChapter = starCountChapter + starCount - starCountSaved;
  306. _chapterStarCountDic[currentChapter] = starCountChapter;
  307. UpdateChapterBonusStatus(currentChapter, starCountChapter);
  308. string boxStatus = GetBoxStatus(currentChapter);
  309. GameProxy.ReqUpdateStoryStar(currentChapter, starCountChapter, boxStatus);
  310. }
  311. }
  312. }
  313. public static int GetPassChapter(int fromChapter)
  314. {
  315. if (StoryUtil.CheckChapterIsHard(fromChapter))
  316. {
  317. return GameGlobal.myNumericComponent.GetAsInt(NumericType.ChapterJY);
  318. }
  319. return GameGlobal.myNumericComponent.GetAsInt(NumericType.Chapter);
  320. }
  321. public static int GetPassLevel(int fromChapter)
  322. {
  323. if (StoryUtil.CheckChapterIsHard(fromChapter))
  324. {
  325. return GameGlobal.myNumericComponent.GetAsInt(NumericType.ChapterLvlJY);
  326. }
  327. return GameGlobal.myNumericComponent.GetAsInt(NumericType.ChapterLvl);
  328. }
  329. public static List<ItemData> PassCurrentLevel(out bool fistPassLastLvl, out bool curLvfirstPass)
  330. {
  331. fistPassLastLvl = false;
  332. curLvfirstPass = false;
  333. List<ItemData> currentBonusList = new List<ItemData>();
  334. if (!CheckCurrentLevelPass())
  335. {
  336. curLvfirstPass = true;
  337. int tempPassLevel = currentLevel;
  338. int tempPassChapter = GetPassChapter(currentChapter);
  339. int nextLevel = currentLevel + 1;
  340. string nextLevelID = currentChapter + "_" + nextLevel;
  341. StoryLevelCfg nextLevelCfg = StoryLevelCfgArray.Instance.GetCfg(nextLevelID);
  342. if (nextLevelCfg == null)
  343. {
  344. tempPassChapter = currentChapter;
  345. tempPassLevel = 0;
  346. fistPassLastLvl = true;
  347. }
  348. SetPassData(tempPassChapter, tempPassLevel);
  349. //GameProxy.ReqUpdateStoryProgress(_passChapter, _passLevel, _passChapterJY, _passLevelJY);
  350. currentBonusList = StoryBonusDataCache.GetBonusList(currentLevelID, true, true);
  351. }
  352. else
  353. {
  354. currentBonusList = StoryBonusDataCache.GetBonusList(currentLevelID, false, true);
  355. }
  356. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(StoryDataManager.currentLevelID);
  357. //消耗体力
  358. if (currentBonusList != null && currentBonusList.Count > 0)
  359. {
  360. if (GameGlobal.myNumericComponent.GetAsInt(NumericType.Power) >= levelCfg.power)
  361. {
  362. RoleDataManager.power -= levelCfg.power;
  363. }
  364. else
  365. {
  366. RoleDataManager.power = 0;
  367. }
  368. }
  369. //消耗推荐次数
  370. if (usedRecommend)
  371. {
  372. usedRecommend = false;
  373. _recommendCount--;
  374. GameProxy.ReqUpdateRecommendCount(_recommendCount);
  375. }
  376. //经验奖励
  377. if (levelCfg.fightID != null && levelCfg.fightID.Length > 0)
  378. {
  379. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  380. RoleDataManager.exp += fightCfg.exp;
  381. }
  382. foreach (ItemData itemData in currentBonusList)
  383. {
  384. ItemDataManager.Add(itemData.id, itemData.num);
  385. }
  386. return currentBonusList;
  387. }
  388. public static int GetChapterStarCount(int chapterID)
  389. {
  390. if (_chapterStarCountDic.ContainsKey(chapterID))
  391. {
  392. return _chapterStarCountDic[chapterID];
  393. }
  394. return 0;
  395. }
  396. public static int GetCanFightTime(string levelID)
  397. {
  398. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(levelID);
  399. int time = (int)Math.Floor((float)GameGlobal.myNumericComponent.GetAsInt(NumericType.Power) / levelCfg.power);
  400. return time;
  401. }
  402. private static string GetBoxStatus(int chapterId)
  403. {
  404. string boxStatus = "0;0;0";
  405. if (_chapterBonusDic.ContainsKey(chapterId))
  406. {
  407. boxStatus = "{0};{1};{2}";
  408. Dictionary<int, int> tempDic = _chapterBonusDic[chapterId];
  409. int value0 = GetChapterBonusStatus(chapterId, 0);
  410. int value1 = GetChapterBonusStatus(chapterId, 1);
  411. int value2 = GetChapterBonusStatus(chapterId, 2);
  412. boxStatus = string.Format(boxStatus, value0, value1, value2);
  413. }
  414. return boxStatus;
  415. }
  416. }
  417. }