InstanceZonesDataManager.cs 11 KB

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