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