InstanceZonesDataManager.cs 10 KB

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