using System.Collections; using System.Collections.Generic; using System; using UnityEngine; using ET; namespace GFGGame { public class StoryDataManager { public static string priorId = "prior";//首次登录前置剧情id public static int currentChapter = 0; public static int currentLevel = 0; //配置表的id public static int currentLevelCfgId; public static int currentScoreType; public static int currentCardId = 0; public static bool usedRecommend; public static int _passChapter = 0; public static int _passLevel = 0; private static int _passChapterJY = 10000; private static int _passLevelJY = 0; public static int recommendDay = -1; //关卡最高分数记录 private static Dictionary _highestScoreDic = new Dictionary(); //关卡星数记录 private static Dictionary _starDic = new Dictionary(); //关卡宝箱状态记录 private static Dictionary _chapterBonusDic = new Dictionary(); public static void InitScoreList(List ks, List vs) { usedRecommend = false; _highestScoreDic.Clear(); for (var i = 0; i < ks.Count; ++i) { _highestScoreDic.Add(ks[i], vs[i]); } } public static void InitStarList(List ks, List vs) { _starDic.Clear(); for(var i = 0; i < ks.Count; ++i) { _starDic.Add(ks[i], vs[i]); } } 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 void TryUpdateScore(int levelCfgId, int score) { _highestScoreDic.TryGetValue(levelCfgId, out var scoreHighest); if (score > scoreHighest) { _highestScoreDic[currentLevelCfgId] = score; } } //检查并更新关卡星数 public static void TryUpdateLevelStar(int levelCfgId, int star) { _starDic.TryGetValue(levelCfgId, out var OldStar); if(star > OldStar) { _starDic[levelCfgId] = star; } } public static void ResetDailyData() { //_recommendCount = GameConst.MAX_COUNT_RECOMMEND; int day = ServerDataManager.CurrentDay; //recommendDay = day; //GameProxy.ReqUpdateRecommendCount(_recommendCount); } //获取宝箱奖励状态 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); //foreach (ItemData itemData in bonusList) //{ // ItemDataManager.Add(itemData.id, itemData.num); //} //Dictionary statusDic = null; //if (_chapterBonusDic.ContainsKey(chapterID)) //{ // statusDic = _chapterBonusDic[chapterID]; //} //else //{ // statusDic = new Dictionary(); // _chapterBonusDic.Add(chapterID, statusDic); // statusDic[0] = ConstBonusStatus.CAN_NOT_GET; // statusDic[1] = ConstBonusStatus.CAN_NOT_GET; // statusDic[2] = ConstBonusStatus.CAN_NOT_GET; //} //statusDic[index] = ConstBonusStatus.GOT; //string boxStatus = GetBoxStatus(currentChapter); //int starCountChapter = GetChapterStarCount(currentChapter); //GameProxy.ReqUpdateStoryStar(currentChapter, starCountChapter, boxStatus); return bonusList; } public static bool CheckOpenMainUI() { return CheckLevelPass(1, 4) && GuideDataManager.GetGuideCountCopy(ConstGuideId.SINGLE_FIGHT) > 0; } //检查指定章节对应的普通章节是否通关 public static bool CheckNormalChapterPass(int chapterId) { int normalChapterId = StoryUtil.GetNormalChapterId(chapterId); return normalChapterId <= GameGlobal.myNumericComponent.GetAsInt(NumericType.Chapter); } public static bool CheckChapterUnlock(int chapterId) { StoryChapterCfg chapterCfg = StoryChapterCfgArray.Instance.GetCfg(chapterId); if (GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl) < chapterCfg.lvl) { return false; } if (CalculateHelper.CheckChapterIsHard(chapterId)) { //对应普通剧情的章需要开启 if (!CheckNormalChapterPass(chapterId)) { return false; } //前一精英章需要通关 if (chapterId - 1 > GameGlobal.myNumericComponent.GetAsInt(NumericType.ChapterJY)) { return false; } } else { if (chapterId - 1 > GameGlobal.myNumericComponent.GetAsInt(NumericType.Chapter)) { return false; } } return true; } public static bool CheckLevelPass(int chapterId, int level) { int passChapter = GetPassChapter(chapterId); int passLevel = GetPassLevel(chapterId); return CalculateHelper.CheckLevelPass(chapterId, level, passChapter, passLevel); } public static bool CheckLevelUnlock(int chapterId, int level) { int passChapter = GetPassChapter(chapterId); int passLevel = GetPassLevel(chapterId); if (chapterId <= passChapter) { return true; } if (chapterId == passChapter + 1 && level <= passLevel + 1) { return true; } return false; } public static bool CheckCurrentLevelPass() { return CheckLevelPass(currentChapter, currentLevel); } public static int GetScoreHighest(int levelID) { if (_highestScoreDic.ContainsKey(levelID)) { return _highestScoreDic[levelID]; } return 0; } public static bool GetFightResult(int score, out int npcScore) { npcScore = 0; bool equipedNeeded = EquipDataCache.cacher.CheckEquipedFightNeeded(); if (!equipedNeeded) { PromptController.Instance.ShowFloatTextPrompt("未穿必需物品"); return false;//没穿必需品 } int starCount = StoryDataManager.GetResultStarCount(score); if (starCount <= 0) { return false;//低于一星 } StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(StoryDataManager.currentLevelCfgId); StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID); bool hasFightTarget = fightCfg.targetName != null && fightCfg.targetName.Length > 0; if (hasFightTarget) { npcScore = EquipDataCache.cacher.npcTotalScore; if(score < npcScore) { return false;//分数低于对战对象 } } return true; } public static int GetResultStarCount(int score) { return CalculateHelper.GetStoryChapterStar(currentLevelCfgId, score); } public static int GetStarCountHistory(int levelID) { _starDic.TryGetValue(levelID, out var star); return star; } public static bool CheckCurrentScoreEnough(int score) { StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(currentLevelCfgId); StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID); return (score > fightCfg.score1); } public static int GetPassChapter(int fromChapter) { if (CalculateHelper.CheckChapterIsHard(fromChapter)) { return GameGlobal.myNumericComponent.GetAsInt(NumericType.ChapterJY); } return GameGlobal.myNumericComponent.GetAsInt(NumericType.Chapter); } public static int GetPassLevel(int fromChapter) { if (CalculateHelper.CheckChapterIsHard(fromChapter)) { return GameGlobal.myNumericComponent.GetAsInt(NumericType.ChapterLvlJY); } return GameGlobal.myNumericComponent.GetAsInt(NumericType.ChapterLvl); } public static List PassCurrentLevel(out bool fistPassLastLvl, out bool curLvfirstPass) { fistPassLastLvl = false; curLvfirstPass = false; List currentBonusList = new List(); //if (!CheckCurrentLevelPass()) //{ // curLvfirstPass = true; // int tempPassLevel = currentLevel; // int tempPassChapter = GetPassChapter(currentChapter); // int nextLevel = currentLevel + 1; // int nextLevelID = currentChapter*GameConst.STORY_LEVEL_KEY_NUM + nextLevel; // StoryLevelCfg nextLevelCfg = StoryLevelCfgArray.Instance.GetCfg(nextLevelID); // if (nextLevelCfg == null) // { // tempPassChapter = currentChapter; // tempPassLevel = 0; // fistPassLastLvl = true; // } //SetPassData(tempPassChapter, tempPassLevel); //GameProxy.ReqUpdateStoryProgress(_passChapter, _passLevel, _passChapterJY, _passLevelJY); //currentBonusList = StoryBonusDataCache.GetBonusList(currentLevelID, true, true); //} //else //{ //currentBonusList = StoryBonusDataCache.GetBonusList(currentLevelID, false, true); //} //StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(StoryDataManager.currentLevelID); ////消耗体力 //if (currentBonusList != null && currentBonusList.Count > 0) //{ // if (GameGlobal.myNumericComponent.GetAsInt(NumericType.Power) >= levelCfg.power) // { // RoleDataManager.power -= levelCfg.power; // } // else // { // RoleDataManager.power = 0; // } //} //消耗推荐次数 //if (usedRecommend) //{ // usedRecommend = false; // //_recommendCount--; // //GameProxy.ReqUpdateRecommendCount(_recommendCount); //} //经验奖励 //if (levelCfg.fightID != null && levelCfg.fightID.Length > 0) //{ // StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID); // RoleDataManager.exp += fightCfg.exp; //} //foreach (ItemData itemData in currentBonusList) //{ // ItemDataManager.Add(itemData.id, itemData.num); //} return currentBonusList; } public static int GetChapterStarCount(int chapterID) { var star = 0; foreach(var item in _starDic) { var tempChapter = item.Key / GameConst.STORY_LEVEL_KEY_NUM; if(tempChapter == chapterID) { star += item.Value; } } return star; } public static int GetCanFightTime(int levelID) { StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(levelID); int times = (int)Math.Floor((float)GameGlobal.myNumericComponent.GetAsInt(NumericType.Power) / levelCfg.power); return times; } } }