InstanceZonesDataManager.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. using System;
  2. using System.Collections.Generic;
  3. namespace GFGGame
  4. {
  5. //本类为通用关卡数据类,特殊副本类型数据请写到各自的管理器里
  6. public class InstanceZonesDataManager
  7. {
  8. //所有副本关卡通用换装战斗是否使用推荐
  9. public static bool usedRecommend;
  10. //所有副本关卡通用
  11. public static int currentScoreType;
  12. //所有副本关卡通用
  13. public static int currentCardId = 0;
  14. //快速挑战挑战次数
  15. public static int FightTimes = 10;
  16. //是否速刷中
  17. public static bool isQuicklyFighting = false;
  18. //是否结算中
  19. public static bool isResultFighting = false;
  20. private static int _currentLevelCfgId;
  21. //所有副本关卡通用配置表的id
  22. public static int currentLevelCfgId
  23. {
  24. get
  25. {
  26. return _currentLevelCfgId;
  27. }
  28. set
  29. {
  30. _currentLevelCfgId = value;
  31. var levelCfg = StoryLevelCfgArray.Instance.GetCfg(_currentLevelCfgId);
  32. if (levelCfg.type == ConstInstanceZonesType.Story)
  33. {
  34. MainStoryDataManager.currentLevelCfgId = _currentLevelCfgId;
  35. }
  36. }
  37. }
  38. //所有副本关卡通用
  39. public static int currentLevelOrder
  40. {
  41. get
  42. {
  43. var levelCfg = StoryLevelCfgArray.Instance.GetCfg(_currentLevelCfgId);
  44. return levelCfg.order;
  45. }
  46. }
  47. //副本通关状态,key为CalculateHelper.GenerateInstanceZonesLevelStateKey,值为通到关卡编号
  48. private static Dictionary<int, int> _passLevelDic = new Dictionary<int, int>();
  49. //关卡最高分数记录
  50. private static Dictionary<int, int> _highestScoreDic = new Dictionary<int, int>();
  51. //关卡星数记录
  52. private static Dictionary<int, int> _starDic = new Dictionary<int, int>();
  53. public static void InitScoreList(List<int> ks, List<int> vs)
  54. {
  55. usedRecommend = false;
  56. _highestScoreDic.Clear();
  57. for (var i = 0; i < ks.Count; ++i)
  58. {
  59. _highestScoreDic.Add(ks[i], vs[i]);
  60. }
  61. }
  62. public static void InitStarList(List<int> ks, List<int> vs)
  63. {
  64. _starDic.Clear();
  65. for (var i = 0; i < ks.Count; ++i)
  66. {
  67. _starDic.Add(ks[i], vs[i]);
  68. }
  69. }
  70. //检查更新最高分
  71. public static void TryUpdateScore(int levelCfgId, int score)
  72. {
  73. _highestScoreDic.TryGetValue(levelCfgId, out var scoreHighest);
  74. if (score > scoreHighest)
  75. {
  76. _highestScoreDic[levelCfgId] = score;
  77. }
  78. }
  79. public static int GetScoreHighest(int levelID)
  80. {
  81. if (_highestScoreDic.ContainsKey(levelID))
  82. {
  83. return _highestScoreDic[levelID];
  84. }
  85. return 0;
  86. }
  87. //检查并更新关卡星数
  88. public static void TryUpdateLevelStar(int levelCfgId, int star)
  89. {
  90. _starDic.TryGetValue(levelCfgId, out var OldStar);
  91. if (star > OldStar)
  92. {
  93. _starDic[levelCfgId] = star;
  94. }
  95. }
  96. public static int GetStarCountHistory(int levelCfgId)
  97. {
  98. _starDic.TryGetValue(levelCfgId, out var star);
  99. return star;
  100. }
  101. public static int GetChapterStarCount(int chapterID, int type, int subType)
  102. {
  103. var star = 0;
  104. foreach (var item in _starDic)
  105. {
  106. var levelCfg = StoryLevelCfgArray.Instance.GetCfg(item.Key);
  107. if (levelCfg.chapterId == chapterID && levelCfg.type == type && levelCfg.subType == subType)
  108. {
  109. star += item.Value;
  110. }
  111. }
  112. return star;
  113. }
  114. public static void InitLevelPass(List<int> ks, List<int> vs)
  115. {
  116. _passLevelDic.Clear();
  117. for (var i = 0; i < ks.Count; ++i)
  118. {
  119. _passLevelDic[ks[i]] = vs[i];
  120. }
  121. }
  122. /// <summary>
  123. /// 设置某关卡通过,参数为关卡配置id
  124. /// </summary>
  125. /// <param name="levelCfgId"></param>
  126. public static void TrySetLevelPass(int levelCfgId)
  127. {
  128. if (!CheckLevelPass(levelCfgId))
  129. {
  130. var levelCfg = StoryLevelCfgArray.Instance.GetCfg(levelCfgId);
  131. var key = CalculateHelper.GenerateInstanceZonesLevelStateKey(levelCfg.type, levelCfg.subType, levelCfg.chapterId);
  132. _passLevelDic[key] = levelCfgId;
  133. }
  134. }
  135. /// <summary>
  136. /// 获取副本通关关卡
  137. /// </summary>
  138. /// <param name="type" value="副本类型"></param>
  139. /// <param name="subType" value="章节id"></param>
  140. /// <returns></returns>
  141. public static int GetPassLevelCfgId(int type, int subType, int chapterId)
  142. {
  143. var key = CalculateHelper.GenerateInstanceZonesLevelStateKey(type, subType, chapterId);
  144. if (_passLevelDic.TryGetValue(key, out var value))
  145. {
  146. return value;
  147. }
  148. return 0;
  149. }
  150. /// <summary>
  151. /// 获取通关关卡的编号
  152. /// </summary>
  153. /// <param name="type"></param>
  154. /// <param name="subType"></param>
  155. /// <param name="chapterId"></param>
  156. /// <returns></returns>
  157. public static int GetPassLevelOrder(int type, int subType, int chapterId)
  158. {
  159. var levelCfgId = GetPassLevelCfgId(type, subType, chapterId);
  160. var levelCfg = StoryLevelCfgArray.Instance.GetCfg(levelCfgId);
  161. if (levelCfg != null)
  162. {
  163. return levelCfg.order;
  164. }
  165. return 0;
  166. }
  167. /// <summary>
  168. /// 检查某关卡是否通过,参数为关卡配置id
  169. /// </summary>
  170. /// <param name="levelCfgId"></param>
  171. /// <returns></returns>
  172. public static bool CheckLevelPass(int levelCfgId)
  173. {
  174. var levelCfg = StoryLevelCfgArray.Instance.GetCfg(levelCfgId);
  175. if (levelCfg != null)
  176. {
  177. var passLevelOrder = GetPassLevelOrder(levelCfg.type, levelCfg.subType, levelCfg.chapterId);
  178. return levelCfg.order <= passLevelOrder;
  179. }
  180. return false;
  181. }
  182. /// <summary>
  183. /// 检查某章是否通关
  184. /// </summary>
  185. /// <param name="type"></param>
  186. /// <param name="subType"></param>
  187. /// <param name="chapterId"></param>
  188. /// <param name="levelCount"></param>
  189. /// <returns></returns>
  190. public static bool CheckChapterPass(int type, int subType, int chapterId, int levelCount)
  191. {
  192. var chapterCfg = StoryChapterCfgArray.Instance.GetCfg(chapterId);
  193. if (chapterCfg != null)
  194. {
  195. var passLevelOrder = InstanceZonesDataManager.GetPassLevelOrder(type, subType, chapterId);
  196. if (levelCount <= passLevelOrder)
  197. {
  198. return true;
  199. }
  200. }
  201. return false;
  202. }
  203. public static int GetResultStarCount(int score)
  204. {
  205. return CalculateHelper.GetStoryChapterStar(currentLevelCfgId, score);
  206. }
  207. public static bool GetFightResult(int score, out int npcScore)
  208. {
  209. npcScore = 0;
  210. bool equipedNeeded = EquipDataCache.cacher.CheckEquipedFightNeeded();
  211. if (!equipedNeeded)
  212. {
  213. PromptController.Instance.ShowFloatTextPrompt("未穿必需物品");
  214. return false;//没穿必需品
  215. }
  216. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(currentLevelCfgId);
  217. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  218. bool hasFightTarget = fightCfg.targetName != null && fightCfg.targetName.Length > 0;
  219. if (hasFightTarget)
  220. {
  221. npcScore = EquipDataCache.cacher.npcTotalScore;
  222. if (score > npcScore)
  223. {
  224. return true;//分数低于对战对象
  225. }
  226. }
  227. else
  228. {
  229. int starCount = GetResultStarCount(score);
  230. if (starCount > 0)
  231. {
  232. return true;//低于一星
  233. }
  234. }
  235. return false;
  236. }
  237. public static void GetCanFightTime(int type, int subType, int levelCfgId, out int times, out string title)
  238. {
  239. var levelCfg = StoryLevelCfgArray.Instance.GetCfg(levelCfgId);
  240. if (levelCfg.power == 0)
  241. {
  242. times = GameConst.MAX_COUNT_FIGHT_QUICKLY;
  243. }
  244. else
  245. {
  246. times = (int)Math.Floor((float)RoleDataManager.power / levelCfg.power);//体力次数
  247. }
  248. times = Math.Min(GameConst.MAX_COUNT_FIGHT_QUICKLY, times);
  249. title = "";
  250. if (type == ConstInstanceZonesType.Studio || type == ConstInstanceZonesType.Filing)
  251. {
  252. StudioData studioData = StudioDataManager.Instance.GetStudioDataById(levelCfg.chapterId, type);
  253. times = Math.Min(times, studioData.TotalPlayTimes - studioData.PlayTimes);
  254. }
  255. title = string.Format("挑战{0}次", NumberUtil.GetChiniseNumberText(times));
  256. }
  257. public static void GetTotalProgress(out int count, out int totalCount)
  258. {
  259. List<StoryChapterCfg> storyChapters = StoryChapterCfgArray.Instance.GetCfgsBysubType(ConstInstanceZonesSubType.Normal);
  260. totalCount = storyChapters.Count - 1;
  261. count = 0;
  262. for (int i = 1; i < storyChapters.Count; i++)
  263. {
  264. bool isPass = InstanceZonesDataManager.CheckChapterPass(storyChapters[i].type, storyChapters[i].subType, storyChapters[i].id, storyChapters[i].levelCount);
  265. if (isPass)
  266. {
  267. count++;
  268. }
  269. else
  270. {
  271. break;
  272. }
  273. }
  274. }
  275. }
  276. }