StoryDataManager.cs 17 KB

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