InstanceZonesDataManager.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace GFGGame
  5. {
  6. //本类为通用关卡数据类,特殊副本类型数据请写到各自的管理器里
  7. public class InstanceZonesDataManager
  8. {
  9. //所有副本关卡通用换装战斗是否使用推荐
  10. public static bool usedRecommend;
  11. //所有副本关卡通用
  12. public static int currentScoreType;
  13. //所有副本关卡通用
  14. public static int currentCardId = 0;
  15. //快速挑战挑战次数
  16. public static int FightTimes = 10;
  17. //是否速刷中
  18. public static bool isQuicklyFighting = false;
  19. //是否结算中
  20. public static bool isResultFighting = false;
  21. //战斗场景
  22. public static int FightScene;
  23. public static string[] currentFightTags;
  24. private static int _currentLevelCfgId;
  25. //所有副本关卡通用配置表的id
  26. public static int currentLevelCfgId
  27. {
  28. get
  29. {
  30. return _currentLevelCfgId;
  31. }
  32. set
  33. {
  34. _currentLevelCfgId = value;
  35. var levelCfg = StoryLevelCfgArray.Instance.GetCfg(_currentLevelCfgId);
  36. if (levelCfg.type == ConstInstanceZonesType.Story)
  37. {
  38. MainStoryDataManager.currentLevelCfgId = _currentLevelCfgId;
  39. }
  40. if (string.IsNullOrEmpty(levelCfg.fightID))
  41. {
  42. currentFightTags = null;
  43. }
  44. else
  45. {
  46. StoryFightCfg storyFightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  47. currentFightTags = storyFightCfg.needTagsArr;
  48. }
  49. }
  50. }
  51. //所有副本关卡通用
  52. public static int currentLevelOrder
  53. {
  54. get
  55. {
  56. var levelCfg = StoryLevelCfgArray.Instance.GetCfg(_currentLevelCfgId);
  57. return levelCfg.order;
  58. }
  59. }
  60. private static FightData _roleData = new FightData();
  61. public static FightData roleData
  62. {
  63. get
  64. {
  65. return GetMyFightRoleData();
  66. }
  67. }
  68. private static FightData _targetData = new FightData();
  69. public static FightData targetData
  70. {
  71. get
  72. {
  73. return GetFightTargetData();
  74. }
  75. }
  76. //获取玩家战斗数据
  77. private static FightData GetMyFightRoleData()
  78. {
  79. _roleData.name = RoleDataManager.roleName;
  80. _roleData.scoreType = InstanceZonesDataManager.currentScoreType;
  81. _roleData.baseScore = RoleLevelCfgArray.Instance.GetCfg(RoleDataManager.lvl).baseScore;
  82. _roleData.leagueSkillScore = LeagueDataManager.Instance.GetAllSkillScore(_roleData.scoreType);
  83. _roleData.cardId = InstanceZonesDataManager.currentCardId; ;//卡牌id
  84. CardData cardData = CardDataManager.GetCardDataById(_roleData.cardId);
  85. _roleData.cardScore = _roleData.cardId <= 0 || cardData == null ? 0 : cardData.scores[_roleData.scoreType];//卡牌对应主题的属性分数
  86. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(InstanceZonesDataManager.currentLevelCfgId);
  87. if (!string.IsNullOrEmpty(levelCfg.fightID))
  88. {
  89. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  90. _roleData.tags = fightCfg.needTagsArr;////本次战斗要求的标签
  91. }
  92. if (_roleData.cardId > 0)
  93. {
  94. _roleData.skillLvs = SkillDataManager.Instance.GetCardSkillLvs(_roleData.cardId);
  95. }
  96. _roleData.type = FightTargetType.PLAYER;
  97. _roleData.headId = RoleDataManager.headId;
  98. _roleData.itemList = MyDressUpHelper.dressUpObj.itemList;
  99. FightDataManager.Instance.SetItemScoreList(_roleData);
  100. ScoreSystemData.Instance.SetEquipScoresWithPartId(_roleData);
  101. return _roleData;
  102. }
  103. //获取副本机器人战斗数据
  104. public static FightData GetFightTargetData()
  105. {
  106. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(InstanceZonesDataManager.currentLevelCfgId);
  107. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  108. _targetData.name = fightCfg.targetName;
  109. _targetData.scoreType = InstanceZonesDataManager.currentScoreType; //本次战斗的主题
  110. _targetData.baseScore = fightCfg.targetBaseScore;
  111. _targetData.leagueSkillScore = 0;
  112. _targetData.cardId = fightCfg.targetCardId;
  113. _targetData.cardScore = fightCfg.targetCardScore;
  114. _targetData.tags = fightCfg.needTagsArr;
  115. List<PassivitySkillCfg> skillCfgs = PassivitySkillCfgArray.Instance.GetCfgsBycardId(_targetData.cardId);
  116. _targetData.skillLvs.Clear();
  117. for (int i = 0; i < skillCfgs.Count; i++)
  118. {
  119. _targetData.skillLvs.Add(fightCfg.targetSkillLvs);
  120. }
  121. _targetData.itemScoreList.Clear();
  122. for (int i = 0; i < fightCfg.targetPartsScoreArr.Length; i++)
  123. {
  124. _targetData.itemScoreList.Add(fightCfg.targetPartsScoreArr[i]);
  125. }
  126. _targetData.type = FightTargetType.ROBOT;
  127. _targetData.res = fightCfg.targetRes;
  128. return _targetData;
  129. }
  130. //副本通关状态,key为CalculateHelper.GenerateInstanceZonesLevelStateKey,值为通到关卡编号
  131. private static Dictionary<int, int> _passLevelDic = new Dictionary<int, int>();
  132. //关卡最高分数记录
  133. private static Dictionary<int, int> _highestScoreDic = new Dictionary<int, int>();
  134. //关卡星数记录
  135. private static Dictionary<int, int> _starDic = new Dictionary<int, int>();
  136. public static void InitScoreList(List<int> ks, List<int> vs)
  137. {
  138. usedRecommend = false;
  139. _highestScoreDic.Clear();
  140. for (var i = 0; i < ks.Count; ++i)
  141. {
  142. _highestScoreDic.Add(ks[i], vs[i]);
  143. }
  144. }
  145. public static void InitStarList(List<int> ks, List<int> vs)
  146. {
  147. _starDic.Clear();
  148. for (var i = 0; i < ks.Count; ++i)
  149. {
  150. _starDic.Add(ks[i], vs[i]);
  151. }
  152. }
  153. //检查更新最高分
  154. public static void TryUpdateScore(int levelCfgId, int score)
  155. {
  156. _highestScoreDic.TryGetValue(levelCfgId, out var scoreHighest);
  157. if (score > scoreHighest)
  158. {
  159. _highestScoreDic[levelCfgId] = score;
  160. }
  161. }
  162. public static int GetScoreHighest(int levelID)
  163. {
  164. if (_highestScoreDic.ContainsKey(levelID))
  165. {
  166. return _highestScoreDic[levelID];
  167. }
  168. return 0;
  169. }
  170. //检查并更新关卡星数
  171. public static void TryUpdateLevelStar(int levelCfgId, int star)
  172. {
  173. _starDic.TryGetValue(levelCfgId, out var OldStar);
  174. if (star > OldStar)
  175. {
  176. _starDic[levelCfgId] = star;
  177. }
  178. }
  179. public static int GetStarCountHistory(int levelCfgId)
  180. {
  181. _starDic.TryGetValue(levelCfgId, out var star);
  182. return star;
  183. }
  184. public static int GetChapterStarCount(int chapterID, int type, int subType)
  185. {
  186. var star = 0;
  187. foreach (var item in _starDic)
  188. {
  189. var levelCfg = StoryLevelCfgArray.Instance.GetCfg(item.Key);
  190. if (levelCfg.chapterId == chapterID && levelCfg.type == type && levelCfg.subType == subType)
  191. {
  192. star += item.Value;
  193. }
  194. }
  195. return star;
  196. }
  197. public static void InitLevelPass(List<int> ks, List<int> vs)
  198. {
  199. _passLevelDic.Clear();
  200. for (var i = 0; i < ks.Count; ++i)
  201. {
  202. _passLevelDic[ks[i]] = vs[i];
  203. }
  204. }
  205. /// <summary>
  206. /// 设置某关卡通过,参数为关卡配置id
  207. /// </summary>
  208. /// <param name="levelCfgId"></param>
  209. public static void TrySetLevelPass(int levelCfgId)
  210. {
  211. if (!CheckLevelPass(levelCfgId))
  212. {
  213. var levelCfg = StoryLevelCfgArray.Instance.GetCfg(levelCfgId);
  214. var key = CalculateHelper.GenerateInstanceZonesLevelStateKey(levelCfg.type, levelCfg.subType, levelCfg.chapterId);
  215. _passLevelDic[key] = levelCfgId;
  216. }
  217. }
  218. /// <summary>
  219. /// 获取副本通关关卡
  220. /// </summary>
  221. /// <param name="type" value="副本类型"></param>
  222. /// <param name="subType" value="章节id"></param>
  223. /// <returns></returns>
  224. public static int GetPassLevelCfgId(int type, int subType, int chapterId)
  225. {
  226. var key = CalculateHelper.GenerateInstanceZonesLevelStateKey(type, subType, chapterId);
  227. if (_passLevelDic.TryGetValue(key, out var value))
  228. {
  229. return value;
  230. }
  231. return 0;
  232. }
  233. /// <summary>
  234. /// 获取通关关卡的编号
  235. /// </summary>
  236. /// <param name="type"></param>
  237. /// <param name="subType"></param>
  238. /// <param name="chapterId"></param>
  239. /// <returns></returns>
  240. public static int GetPassLevelOrder(int type, int subType, int chapterId)
  241. {
  242. Debug.Log("GetPassLevelOrder_ 222 _:" + type + " " + subType + " " + chapterId);
  243. var levelCfgId = GetPassLevelCfgId(type, subType, chapterId);
  244. Debug.Log("GetPassLevelOrder_ 333 _:" + type + " " + subType + " " + chapterId);
  245. if (levelCfgId == 0)
  246. {
  247. Debug.Log("GetPassLevelOrder_ 444 _:");
  248. return 0;
  249. }
  250. Debug.Log("GetPassLevelOrder_ 555 _:" + levelCfgId);
  251. var levelCfg = StoryLevelCfgArray.Instance.GetCfg(levelCfgId);
  252. Debug.Log("GetPassLevelOrder_ 666 _:" + levelCfgId);
  253. if (levelCfg != null)
  254. {
  255. Debug.Log("GetPassLevelOrder_ 777 _:");
  256. Debug.Log("GetPassLevelOrder_ 777 _:" + levelCfg.order);
  257. return levelCfg.order;
  258. }
  259. Debug.Log("GetPassLevelOrder_ 888 _:");
  260. return 0;
  261. }
  262. /// <summary>
  263. /// 检查某关卡是否通过,参数为关卡配置id
  264. /// </summary>
  265. /// <param name="levelCfgId"></param>
  266. /// <returns></returns>
  267. public static bool CheckLevelPass(int levelCfgId)
  268. {
  269. var levelCfg = StoryLevelCfgArray.Instance.GetCfg(levelCfgId);
  270. Debug.Log("CheckLevelPass_ 000 _:" + levelCfg);
  271. if (levelCfg != null)
  272. {
  273. Debug.Log("CheckLevelPass_ 111 _:" + levelCfg);
  274. var passLevelOrder = GetPassLevelOrder(levelCfg.type, levelCfg.subType, levelCfg.chapterId);
  275. Debug.Log("CheckLevelPass_ 333 _:" + levelCfg);
  276. Debug.Log("CheckLevelPass_ 222 _:" + passLevelOrder);
  277. Debug.Log("CheckLevelPass_ 444 _:" + levelCfg.order);
  278. return levelCfg.order <= passLevelOrder;
  279. }
  280. return false;
  281. }
  282. /// <summary>
  283. /// 检查某章是否通关
  284. /// </summary>
  285. /// <param name="type"></param>
  286. /// <param name="subType"></param>
  287. /// <param name="chapterId"></param>
  288. /// <param name="levelCount"></param>
  289. /// <returns></returns>
  290. public static bool CheckChapterPass(int type, int subType, int chapterId, int levelCount)
  291. {
  292. var chapterCfg = StoryChapterCfgArray.Instance.GetCfg(chapterId);
  293. if (chapterCfg != null)
  294. {
  295. var passLevelOrder = InstanceZonesDataManager.GetPassLevelOrder(type, subType, chapterId);
  296. if (levelCount <= passLevelOrder)
  297. {
  298. return true;
  299. }
  300. }
  301. return false;
  302. }
  303. public static int GetResultStarCount(int score)
  304. {
  305. return CalculateHelper.GetStoryChapterStar(currentLevelCfgId, score);
  306. }
  307. public static bool GetFightResult(int score, out int npcScore)
  308. {
  309. npcScore = 0;
  310. bool equipedNeeded = MyDressUpHelper.CheckEquipedFightNeeded();
  311. if (!equipedNeeded)
  312. {
  313. PromptController.Instance.ShowFloatTextPrompt("未穿必需物品");
  314. return false;//没穿必需品
  315. }
  316. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(currentLevelCfgId);
  317. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  318. bool hasFightTarget = fightCfg.targetName != null && fightCfg.targetName.Length > 0;
  319. if (hasFightTarget)
  320. {
  321. npcScore = FightDataManager.Instance.npcTotalScore;
  322. if (score > npcScore)
  323. {
  324. return true;//分数低于对战对象
  325. }
  326. }
  327. else
  328. {
  329. int starCount = GetResultStarCount(score);
  330. if (starCount > 0)
  331. {
  332. return true;//低于一星
  333. }
  334. }
  335. return false;
  336. }
  337. public static void GetCanFightTime(int type, int subType, int levelCfgId, out int times, out string title)
  338. {
  339. var levelCfg = StoryLevelCfgArray.Instance.GetCfg(levelCfgId);
  340. if (levelCfg.power == 0)
  341. {
  342. times = GameConst.MAX_COUNT_FIGHT_QUICKLY;
  343. }
  344. else
  345. {
  346. times = (int)Math.Floor((float)RoleDataManager.power / levelCfg.power);//体力次数
  347. }
  348. times = Math.Min(GameConst.MAX_COUNT_FIGHT_QUICKLY, times);
  349. title = "";
  350. if (type == ConstInstanceZonesType.Studio)
  351. {
  352. var studioCfg = StudioCfgArray.Instance.GetCfg(levelCfg.chapterId);
  353. var limitData = RoleLimitDataManager.GetLimitData(studioCfg.limit);
  354. times = Math.Min(times, limitData.TotalPlayMax - limitData.PlayTimes);
  355. }
  356. title = string.Format("挑战{0}次", NumberUtil.GetChiniseNumberText(times));
  357. }
  358. public static void GetTotalProgress(out int count, out int totalCount)
  359. {
  360. List<StoryChapterCfg> storyChapters = StoryChapterCfgArray.Instance.GetCfgsBysubType(ConstInstanceZonesSubType.Normal);
  361. totalCount = storyChapters.Count - 1;
  362. count = 0;
  363. for (int i = 1; i < storyChapters.Count; i++)
  364. {
  365. bool isPass = InstanceZonesDataManager.CheckChapterPass(storyChapters[i].type, storyChapters[i].subType, storyChapters[i].id, storyChapters[i].levelCount);
  366. if (isPass)
  367. {
  368. count++;
  369. }
  370. else
  371. {
  372. break;
  373. }
  374. }
  375. }
  376. }
  377. }