StoryDataManager.cs 17 KB

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