InstanceZonesDataManager.cs 11 KB

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