StoryDataManager.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  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 GetStarCount(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 GetStarCount(levelID, score);
  279. }
  280. public static int GetStarCount(string levelID, int score)
  281. {
  282. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(levelID);
  283. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  284. int starCount = 0;
  285. if (score > fightCfg.score1)
  286. {
  287. if (score > fightCfg.score3)
  288. {
  289. starCount = 3;
  290. }
  291. else if (score > fightCfg.score2)
  292. {
  293. starCount = 2;
  294. }
  295. else
  296. {
  297. starCount = 1;
  298. }
  299. }
  300. return starCount;
  301. }
  302. public static bool CheckCurrentScoreEnough(int score)
  303. {
  304. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(currentLevelID);
  305. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  306. return (score > fightCfg.score1);
  307. }
  308. public static void SetScore(int score, int starCount)
  309. {
  310. int scoreHighest = 0;
  311. if (_highestScoreDic.ContainsKey(currentLevelID))
  312. {
  313. scoreHighest = _highestScoreDic[currentLevelID];
  314. }
  315. if (score > scoreHighest)
  316. {
  317. _highestScoreDic[currentLevelID] = score;
  318. GameProxy.ReqUpdateStoryScore(currentLevelID, score);
  319. int starCountSaved = GetStarCountHistory(currentLevelID, scoreHighest);
  320. int starCountChapter = 0;
  321. if (_chapterStarCountDic.ContainsKey(currentChapter))
  322. {
  323. starCountChapter = _chapterStarCountDic[currentChapter];
  324. }
  325. if (starCount > starCountSaved)
  326. {
  327. starCountChapter = starCountChapter + starCount - starCountSaved;
  328. _chapterStarCountDic[currentChapter] = starCountChapter;
  329. UpdateChapterBonusStatus(currentChapter, starCountChapter);
  330. string boxStatus = GetBoxStatus(currentChapter);
  331. GameProxy.ReqUpdateStoryStar(currentChapter, starCountChapter, boxStatus);
  332. }
  333. }
  334. }
  335. public static int GetPassChapter(int fromChapter)
  336. {
  337. if (StoryUtil.CheckChapterIsHard(fromChapter))
  338. {
  339. return GameGlobal.myNumericComponent.GetAsInt(NumericType.ChapterJY);
  340. }
  341. return GameGlobal.myNumericComponent.GetAsInt(NumericType.Chapter);
  342. }
  343. public static int GetPassLevel(int fromChapter)
  344. {
  345. if (StoryUtil.CheckChapterIsHard(fromChapter))
  346. {
  347. return GameGlobal.myNumericComponent.GetAsInt(NumericType.ChapterLvlJY);
  348. }
  349. return GameGlobal.myNumericComponent.GetAsInt(NumericType.ChapterLvl);
  350. }
  351. public static List<ItemData> PassCurrentLevel(out bool fistPassLastLvl, out bool curLvfirstPass)
  352. {
  353. fistPassLastLvl = false;
  354. curLvfirstPass = false;
  355. List<ItemData> currentBonusList = new List<ItemData>();
  356. if (!CheckCurrentLevelPass())
  357. {
  358. curLvfirstPass = true;
  359. int tempPassLevel = currentLevel;
  360. int tempPassChapter = GetPassChapter(currentChapter);
  361. int nextLevel = currentLevel + 1;
  362. string nextLevelID = currentChapter + "_" + nextLevel;
  363. StoryLevelCfg nextLevelCfg = StoryLevelCfgArray.Instance.GetCfg(nextLevelID);
  364. if (nextLevelCfg == null)
  365. {
  366. tempPassChapter = currentChapter;
  367. tempPassLevel = 0;
  368. fistPassLastLvl = true;
  369. }
  370. SetPassData(tempPassChapter, tempPassLevel);
  371. // FunctionOpenDataManager.Instance.CheckHasChapterFunOpen(_passChapter + 1, _passLevel);//首次通过要检查是否有功能开启
  372. //GameProxy.ReqUpdateStoryProgress(_passChapter, _passLevel, _passChapterJY, _passLevelJY);
  373. currentBonusList = StoryBonusDataCache.GetBonusList(currentLevelID, true, true);
  374. }
  375. else
  376. {
  377. currentBonusList = StoryBonusDataCache.GetBonusList(currentLevelID, false, true);
  378. }
  379. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(StoryDataManager.currentLevelID);
  380. //消耗体力
  381. if (currentBonusList != null && currentBonusList.Count > 0)
  382. {
  383. if (GameGlobal.myNumericComponent.GetAsInt(NumericType.Power) >= levelCfg.power)
  384. {
  385. RoleDataManager.power -= levelCfg.power;
  386. }
  387. else
  388. {
  389. RoleDataManager.power = 0;
  390. }
  391. }
  392. //消耗推荐次数
  393. if (usedRecommend)
  394. {
  395. usedRecommend = false;
  396. _recommendCount--;
  397. GameProxy.ReqUpdateRecommendCount(_recommendCount);
  398. }
  399. //经验奖励
  400. if (levelCfg.fightID != null && levelCfg.fightID.Length > 0)
  401. {
  402. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  403. RoleDataManager.exp += fightCfg.exp;
  404. }
  405. foreach (ItemData itemData in currentBonusList)
  406. {
  407. ItemDataManager.Add(itemData.id, itemData.num);
  408. }
  409. return currentBonusList;
  410. }
  411. public static int GetChapterStarCount(int chapterID)
  412. {
  413. if (_chapterStarCountDic.ContainsKey(chapterID))
  414. {
  415. return _chapterStarCountDic[chapterID];
  416. }
  417. return 0;
  418. }
  419. public static int GetCanFightTime(string levelID)
  420. {
  421. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(levelID);
  422. int time = (int)Math.Floor((float)GameGlobal.myNumericComponent.GetAsInt(NumericType.Power) / levelCfg.power);
  423. return time;
  424. }
  425. private static string GetBoxStatus(int chapterId)
  426. {
  427. string boxStatus = "0;0;0";
  428. if (_chapterBonusDic.ContainsKey(chapterId))
  429. {
  430. boxStatus = "{0};{1};{2}";
  431. Dictionary<int, int> tempDic = _chapterBonusDic[chapterId];
  432. int value0 = GetChapterBonusStatus(chapterId, 0);
  433. int value1 = GetChapterBonusStatus(chapterId, 1);
  434. int value2 = GetChapterBonusStatus(chapterId, 2);
  435. boxStatus = string.Format(boxStatus, value0, value1, value2);
  436. }
  437. return boxStatus;
  438. }
  439. }
  440. }