using System.Collections; using System.Collections.Generic; using System; using System.Linq; using cfg.GfgCfg; using UnityEngine; using ET; using ProtoBuf.Meta; namespace GFGGame { public class MainStoryDataManager { public static string priorId = "prior"; //首次登录前置剧情id //剧情副本专用当前章节 public static int currentChapterCfgId = 0; //剧情副本专用当前关卡序号,从1开始 public static int CurrentChapterOrder { get { var chapterCfg = CommonDataManager.Tables.TblStoryChapterCfg.GetOrDefault(currentChapterCfgId); if (chapterCfg != null) { return chapterCfg.Order; } return 0; } } //剧情副本专用关卡编号 private static int _currentLevelCfgId; public static int currentLevelCfgId { get { return _currentLevelCfgId; } set { int lastLevelCfgId = _currentLevelCfgId; var lastLevelCfg = CommonDataManager.Tables.TblStoryLevelCfg.GetOrDefault(_currentLevelCfgId); _currentLevelCfgId = value; var levelCfg = CommonDataManager.Tables.TblStoryLevelCfg.GetOrDefault(_currentLevelCfgId); currentChapterCfgId = levelCfg == null ? lastLevelCfg.ChapterId : levelCfg.ChapterId; } } //剧情副本专用关卡宝箱状态记录 private static Dictionary _chapterBonusDic = new Dictionary(); public static void InitBoxBonusStates(List ks, List vs) { _chapterBonusDic.Clear(); for (var i = 0; i < ks.Count; ++i) { var states = new int[] { 0, 0, 0 }; var value = vs[i]; CalculateHelper.GenerateChapterBoxStates(states, value); _chapterBonusDic.Add(ks[i], states); } } public static void UpdateBoxBonusStates(int chapter, int stateInt) { if (!_chapterBonusDic.TryGetValue(chapter, out var states)) { states = new int[] { 0, 0, 0 }; _chapterBonusDic.Add(chapter, states); } CalculateHelper.GenerateChapterBoxStates(states, stateInt); } //获取宝箱奖励状态 public static int GetChapterBonusStatus(int chapterID, int index) { if (_chapterBonusDic.ContainsKey(chapterID)) { var states = _chapterBonusDic[chapterID]; if (states != null) { return states[index]; } } return ConstBonusStatus.CAN_NOT_GET; } public static List GetChapterBonus(int chapterID, int index) { List bonusList = StoryBonusDataCache.GetChapterBonusList(chapterID, index); return bonusList; } public static bool CheckOpenMainUI() { return InstanceZonesDataManager.CheckLevelPass(100001002); } //检查指定章节对应的普通章节是否通关 public static bool CheckNeedChapterPass(int chapterId, out int needChapterId) { StoryChapterCfg chapterCfg = CommonDataManager.Tables.TblStoryChapterCfg.GetOrDefault(chapterId); needChapterId = chapterCfg.NeedChapterId; if (chapterCfg.NeedChapterId > 0) { var preChapterCfg = CommonDataManager.Tables.TblStoryChapterCfg.GetOrDefault(chapterCfg.NeedChapterId); if (preChapterCfg != null) { return InstanceZonesDataManager.CheckChapterPass(preChapterCfg.Type, preChapterCfg.SubType, preChapterCfg.Id, preChapterCfg.LevelCount); } } return true; } public static int CheckChapterPassIndex(int subtype) { int count = 2; List chapList = CommonDataManager.Tables.TblStoryChapterCfg.DataList .Where(a => a.SubType == subtype).ToList(); foreach (StoryChapterCfg item in chapList) { var preChapterCfg = CommonDataManager.Tables.TblStoryChapterCfg.GetOrDefault(item.Id); if (preChapterCfg != null) { if (InstanceZonesDataManager.CheckChapterPass(preChapterCfg.Type, preChapterCfg.SubType, preChapterCfg.Id, preChapterCfg.LevelCount)) { count++; } } } if (count > chapList.Count) { count = chapList.Count; } return count; } public static bool CheckChapterUnlock(int chapterId, bool checkRoleLv = true) { StoryChapterCfg chapterCfg = CommonDataManager.Tables.TblStoryChapterCfg.GetOrDefault(chapterId); if (checkRoleLv && GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl) < chapterCfg.Lvl) { return false; } //上一关卡 int preChapterId = chapterId - 1; var preChapterCfg = CommonDataManager.Tables.TblStoryChapterCfg.GetOrDefault(preChapterId); if (preChapterCfg != null) { if (!InstanceZonesDataManager.CheckChapterPass(preChapterCfg.Type, preChapterCfg.SubType, preChapterCfg.Id, preChapterCfg.LevelCount)) { return false; } } //前置关卡 return CheckNeedChapterPass(chapterId, out var needChapterId); } public static bool CheckLevelUnlock(int levelCfgId, bool checkRoleLv = true) { var levelCfg = CommonDataManager.Tables.TblStoryLevelCfg.GetOrDefault(levelCfgId); if (levelCfg != null) { if (!CheckChapterUnlock(levelCfg.ChapterId, checkRoleLv)) { return false; } var passLevelOrder = InstanceZonesDataManager.GetPassLevelOrder(levelCfg.Type, levelCfg.SubType, levelCfg.ChapterId); return levelCfg.Order <= passLevelOrder + 1; } return false; } public static bool CheckCurrentLevelPass() { return InstanceZonesDataManager.CheckLevelPass(currentLevelCfgId); } //判断章节是否是精英关卡 public static bool CheckChapterIsHard(int chapterId) { return GetChapterSubType(chapterId) == ConstInstanceZonesSubType.Hard; } //获取章节难度(普通或者精英) public static int GetChapterSubType(int chapterId) { var chapterCfg = CommonDataManager.Tables.TblStoryChapterCfg.GetOrDefault(chapterId); if (chapterCfg != null) { return chapterCfg.SubType; } return ConstInstanceZonesSubType.Normal; } //章节奖励状态 public static Dictionary ChapterRewardStatusDic = new Dictionary(); public static bool GetChapterRewardStatus() { foreach (var item in ChapterRewardStatusDic) { StoryChapterCfg chapterRewardCfg = CommonDataManager.Tables.TblStoryChapterCfg.GetOrDefault(item.Key); if (chapterRewardCfg.Type == 1 && chapterRewardCfg.SubType == 1) { continue; } if (item.Value == 1) { return true; } } return false; } //关卡当前难度类型 public static int currentChapterType = 0; } }