local LevelSelect_Model = {} local private = {} local EventSystem = require('Event/EventSystem') local fuben_pb = require('Proto/fuben_pb') local fuben_common = require('Proto/fuben_pb') local ChapterIdStartNum = 100 local LevelIdStartNum = 10000 LevelSelect_Model.Difficult = { Normal = 1, Elite = 2, Hell = 3, } --道具底色枚举 LevelSelect_Model.ItemColorName={"green","blue","purple","yellow","red","orange"} --道具底色背景枚举 LevelSelect_Model.ItemColorBgName={"greenBg","blueBg","purpleBg","yellowBg","redBg","orangeBg"} function LevelSelect_Model.OnStartup() NetManager.RegisterMsgCB(MessageEnums.MessageFinishFuben, private.RoleFinishFubenResponse) NetManager.RegisterMsgCB(MessageEnums.MessageAwardChapter, private.ClaimChapterRewardChestResponse) NetManager.RegisterMsgCB(MessageEnums.MessageEnterFuben,private.OnEnterFubenResponse) NetManager.RegisterMsgCB(MessageEnums.MessageG2CPushEnterFuben,private.OnEnterFubenResponse) NetManager.RegisterMsgCB(MessageEnums.MessageAwardChapterGoal,private.ClaimChapterAwardResponse) NetManager.RegisterMsgCB(MessageEnums.MessageFubenQuickPass,private.FubenQuickPassResp) EventSystem.Regist(EventID.Level_BattleSummary, private.RoleFinishFubenRequest) EventSystem.Regist(EventID.BossChallenge_Summary, private.RoleFinishFubenRequest) EventSystem.Regist(EventID.Biography_Summary, private.RoleFinishFubenRequest) private.unlockedLevelId = {} private.unlockedChapterId = {} private.levelInfos = {} private.chapterInfo = {} private.chapterClaimAwards = {} private.chapterShowAwards = {} private.lastAttackedDifficult = nil private.currentRewardChapterID = nil private.systemId = nil --当前关卡的系统ID,EnterFubenResp协议带的id。是系统表的ID(不是LevelInfo表的ID)。不同玩法有不同的系统表 private.maxDamage = 0 --当前关卡的最大伤害,EnterFubenResp协议带的maxDamage。 -- DLC章节屏蔽 LevelSelect_Model.DLCBlockChapterID = 0 private.InitDLCBlockChapterID() end function LevelSelect_Model:GetSystemID() return private.systemId end function LevelSelect_Model.GetMaxDamage() return private.maxDamage or 0 end function LevelSelect_Model.SaveTempLastDifficult(difficult) private.lastAttackedDifficult = difficult end function LevelSelect_Model.GetTempLastDifficult() return private.lastAttackedDifficult end function private.InitDLCBlockChapterID() for i, v in DataSheetManager.DLCCover:GetEnumerator() do if v.Area == GameAppInfo.Global_PackageType then LevelSelect_Model.DLCBlockChapterID = v.CoverChapterID return end end end function LevelSelect_Model.OnShutdown() end function LevelSelect_Model.SetStoryInfo(storyInfos, isEnterWorldInit) private.DealLevelInfoMsg(storyInfos,isEnterWorldInit) private.DealChapterInfoMsg(storyInfos) private.DealWithUnlockLevelMsg(storyInfos.unlockedLevelId) private.DealWithUnlockChapterMsg(storyInfos.unlockedChapterId) private.DealWithChapterRewards(storyInfos.receivedChapterGoalId) EventSystem.Dispatch(EventID.UI_Activity_Refresh_Single_RedPoint, LuaConst.ActivityType.MainlLine, CTL.LevelSelect.IsShowLevelSelectRedPoint()) end function private.DealLevelInfoMsg(storyInfos, isEnterWorldInit) for i = 1, #storyInfos.levelInfos do local isUpdate = false for j = 1, #private.levelInfos do if storyInfos.levelInfos[i].levelId == private.levelInfos[j].levelId then --private.levelInfos[j].star = storyInfos.levelInfos[i].star private.levelInfos[j].star = {} for i, v in ipairs(storyInfos.levelInfos[i].star) do private.levelInfos[j].star[i] = v end isUpdate = true end end if not isUpdate then local starTable = {} for i, v in ipairs(storyInfos.levelInfos[i].star) do starTable[i] = v end table.insert(private.levelInfos, { levelId = storyInfos.levelInfos[i].levelId, star = starTable }) end end if not isEnterWorldInit then EventSystem.Dispatch(EventID.OnConditionChangeFunctionUpdate, LuaConst.UnlockConditionType.PassedLevel) end end function private.DealChapterInfoMsg(storyInfos) for i = 1, #storyInfos.chapterInfo do local isUpdate = false for j = 1, #private.chapterInfo do if storyInfos.chapterInfo[i].chapterId == private.chapterInfo[j].chapterId then private.chapterInfo[j].isGot = {} for m = 1, #storyInfos.chapterInfo[i].isGot do private.chapterInfo[j].isGot[m] = storyInfos.chapterInfo[i].isGot[m] isUpdate = true end end end if not isUpdate then local isGotData = {} for m = 1, #storyInfos.chapterInfo[i].isGot do isGotData[m] = storyInfos.chapterInfo[i].isGot[m] end table.insert(private.chapterInfo, { chapterId = storyInfos.chapterInfo[i].chapterId, isGot = isGotData }) end end end function private.DealWithUnlockLevelMsg(infos) for i = 1, #infos do if infos[i] then private.unlockedLevelId[i] = infos[i] end end end function private.DealWithUnlockChapterMsg(infos) for i = 1, #infos do if infos[i] then private.unlockedChapterId[i] = infos[i] end end end function LevelSelect_Model.GetUnLockLevelIdMsg() return private.unlockedLevelId end function LevelSelect_Model.GetUnlockChapterId() return private.unlockedChapterId end function LevelSelect_Model.UpdateStoryInfo(storyInfos) if IsServerDataNotNil(storyInfos.unlockedLevelId) then private.DealWithUnlockLevelMsg(storyInfos.unlockedLevelId) end if IsServerDataNotNil(storyInfos.unlockedChapterId) then private.DealWithUnlockChapterMsg(storyInfos.unlockedChapterId) end if IsServerDataNotNil(storyInfos.levelInfos) then private.DealLevelInfoMsg(storyInfos) end if IsServerDataNotNil(storyInfos.chapterInfo) then private.DealChapterInfoMsg(storyInfos) end EventSystem.Dispatch(EventID.UI_Activity_Refresh_Single_RedPoint, LuaConst.ActivityType.MainlLine, CTL.LevelSelect.IsShowLevelSelectRedPoint()) -- 刷新剧情回顾红点 CTL.PlotReviewLibrary.CalculationMainLineRp() end function LevelSelect_Model.GetAlreadyPassedLevelInfo() return private.levelInfos end function LevelSelect_Model.GetAlreadyPassedChapterInfo() return private.chapterInfo end function LevelSelect_Model.GetUnlockLevelIdByChapter(chapterId) for i,v in ipairs(private.unlockedLevelId) do if math.floor(v / ChapterIdStartNum) == chapterId then return v end end local alreadyPassedLevelId = nil for i,v in ipairs(LevelSelect_Model.GetLevelIdByChapterId(chapterId)) do local star = LevelSelect_Model.GetLevelStarNumById(v) if star and star > 0 then alreadyPassedLevelId = v end end return alreadyPassedLevelId end function LevelSelect_Model.GetUnlockLevelIdByDifficult(difficult) return private.unlockedLevelId[(difficult or 1)] end function LevelSelect_Model.GetUnlockChapterIdByDifficult(difficult) for i, v in ipairs(private.unlockedChapterId) do local delta = v - ChapterIdStartNum * (difficult or 1) if delta > 0 and delta < ChapterIdStartNum then return v end end end function LevelSelect_Model.GetNormalUnlockChapterId() for i,v in ipairs(private.unlockedChapterId) do if v < LevelSelect_Model.Difficult.Elite * ChapterIdStartNum then return v end end end function LevelSelect_Model.GetLevelDataById(id) local levelInfos = private.levelInfos for i, v in ipairs(levelInfos) do if v.levelId == id then return v.star end end return {} end function LevelSelect_Model.GetLevelStarNumById(id) local starNum = 0 local starTable = LevelSelect_Model.GetLevelDataById(id) if starTable then for i, v in ipairs(starTable) do starNum = starNum + v end end return starNum end function LevelSelect_Model.GetChapterStarNumsById(chapterId) local starNums = 0 local levelIdList = LevelSelect_Model.GetLevelIdByChapterId(chapterId) for i, v in ipairs(levelIdList) do local star = LevelSelect_Model.GetLevelStarNumById(v) starNums = starNums + star end return starNums end function LevelSelect_Model.GetChapterDataById(id) local chapterInfos = private.chapterInfo for i, v in ipairs(chapterInfos) do if v.chapterId == id then return v.isGot end end return nil end function LevelSelect_Model.GetLevelIdByChapterId(chapterId) local levelIdList = {} local ChapterData = DataSheetManager.BarrierChapterData:GetDataByBarrierCharpterID(chapterId) for i = 1, ChapterData.BarrierNum do --举例:章节ID:101,则关卡ID为10101,10102,10103…… local levelId = chapterId * ChapterIdStartNum + i table.insert(levelIdList, levelId) end return levelIdList end --- 获取BarrierChapter所属的ChapterID function LevelSelect_Model.GetChapterIDByBarrierLevelID(barrierLevelID) return barrierLevelID / 10 % 10 * 10 end function LevelSelect_Model.GetChapterIdByLevelId(levelId) return math.floor(levelId / ChapterIdStartNum) end function LevelSelect_Model.GetIndexById(id) --若大于10000则为关卡ID,得到相应的余数为关卡ID的Index if id > LevelIdStartNum then return id % ChapterIdStartNum --若大于100则为章节ID,得到相应的余数为关卡ID的Index elseif id > ChapterIdStartNum then return id % ChapterIdStartNum end end function LevelSelect_Model.GetDifficultById(id) --若大于10000则为关卡ID,得到相应的余数为关卡ID的Index if id > LevelIdStartNum then return math.floor(id / LevelIdStartNum) --若大于100则为章节ID,得到相应的余数为关卡ID的Index elseif id > ChapterIdStartNum then return math.floor(id / ChapterIdStartNum) end end function LevelSelect_Model.IsLevelUnlock(id) local unlockId = LevelSelect_Model.GetUnlockLevelIdByDifficult(LevelSelect_Model.GetDifficultById(id)) if unlockId then return unlockId >= id else return false end end function LevelSelect_Model.GoldenFingerPassLevel() local msg = fuben_common.FinishFubenReq() msg.isWin = true for i = 1, 3 do table.insert(msg.star, 1) end msg.mapType = BattleDataGetter.GetLevelInfoData().LevelType msg.passTime = math.ceil(BattleDataGetter.GetLevelPassTime()) msg.saveRecordStr = BattleDataGetter.GetCurLevelSaveRecordBytes() if LevelManager.IsServerNeedCheckNotSyncLevel() then msg.battleFrame = LevelManager.GetRecordFrameCmds() BattleSimulator.SaveAsyncFrames(msg.battleFrame) end LevelSelect_Model.SetHpPercentResult(msg) NetManager.SendMessage(MessageEnums.MessageFinishFuben, msg) end --levelID只有在主线剧情副本是必填项,其他副本不需要填. levelID是LevelInfo表的ID function LevelSelect_Model.EnterFuben(fubenType, id, clientIntermediateParams, levelID, goldHeroInfo, freeLineUpNum) if CTL.TeamMatch.IsCanGoOtherScene(fubenType, levelID) then local msg = fuben_common.EnterFubenReq() msg.id = id msg.mapType = fubenType if msg.mapType == LuaConst.LevelType.NORMAL or msg.mapType == LuaConst.LevelType.GoldHeroExperience then if levelID then msg.mapID = levelID else logging.error(LTAG.ERROR, "HYW : 主线副本请求EnterFuben必须要传MissionID(LevelInfo表的ID)!!") end end if clientIntermediateParams then msg.clientIntermediateParams = clientIntermediateParams end if goldHeroInfo then msg.goldHeroInfo = goldHeroInfo end if freeLineUpNum then -- 自选阵容号 msg.freeLineUpNum = freeLineUpNum end NetManager.SendMessage(MessageEnums.MessageEnterFuben, msg) end end function LevelSelect_Model.EnterNormalPVEFuben(id, levelID) local msg = fuben_common.EnterFubenReq() msg.id = id msg.mapType = LuaConst.LevelType.FairNormalPVE msg.mapID = levelID NetManager.SendMessage(MessageEnums.MessageEnterFuben, msg) end function private.OnEnterFubenResponse(msgResp) -- old↓ 上阵信息挪到RoleEnterScene了,这里不用管了 -- --这条消息跟S2CRoleEnterSceneResp进入关卡消息的时序无法确定,所以这里会有缓存。如果S2CRoleEnterSceneResp消息还没过来,就要缓存本消息 -- if LevelManager.GetCurLevelID() == msgResp.mapID then -- --如果当前关卡是msg的目标关卡,则直接Set -- NotSyncBattleSetter.SetPlayerArmyTable(msgResp.heroLineUpInfos) -- else -- --如果当前关卡不是msg的目标关卡,则缓存起来,在进入目标关卡后再Set -- NotSyncBattleSetter.CacheHeroTable(msgResp.heroLineUpInfos) -- end --old↑ if msgResp.Resp.Code ~= 0 and msgResp.mapType == LuaConst.LevelType.AttackCity then CTL.GVGFight.EnterLevelError(msgResp.Resp.Code) end if msgResp.Resp.Code ~= 0 then EventSystem.Dispatch(EventID.EnterFuben_RespError, msgResp.mapType) return end private.systemId = msgResp.id CTL.LevelSelect.SetCurrentLevelId(msgResp.id) --这个不是LevelInfo表的ID if not BattleDataGetter.IsSyncLevel() then NotSyncBattleSetter.SetLevelData(CTL.LevelSelect.GetLevelCutsceneAutoPassTime(msgResp.mapType)) end -- ↓移动到RoleEnterSceneResp里去了 -- if not BattleDataGetter.ShouldKeepSyncLevel() then -- NotSyncBattleSetter.SetLevelSaveRecordBytes(msgResp.saveRecordStr) --proto传过来的改为了bytes,但是命名没改还是有str后缀 -- elseif msgResp.saveRecordStr and msgResp.saveRecordStr ~= "" then -- logging.error(LTAG.ERROR, "HYW : 在同步或者需要校验的关卡视图设置存档,这个是不支持的! LevelType : ", LevelManager.GetCurLevelType(), " LevelID : ", LevelManager.GetCurLevelID(), " msgResp.saveRecordStr : ", msgResp.saveRecordStr) -- end -- ↑ BIManager.SetBattleID(msgResp.battleID, msgResp.battleIdStr) MDL.GVGFight.SetBadgeScore(msgResp.badgeScore) private.maxDamage = msgResp.maxDamage EventSystem.Dispatch(EventID.EnterFuben_Resp) end function LevelSelect_Model.EnterRogueLikeFuben(heroId, mapId) local msg = fuben_pb.EnterFubenReq() msg.id = mapId msg.mapType = LuaConst.LevelType.RogueLike msg.mapID = mapId heroId = heroId or 6 table.insert(msg.heroIds, heroId) NetManager.SendMessage(MessageEnums.MessageEnterFuben, msg) end function LevelSelect_Model.FubenQuickPassReq(fubenType, srcLevelId, targetLevelId) local msg = NetManager.GetPB("fuben_pb").FubenQuickPassReq() msg.mapType = fubenType msg.currId = srcLevelId msg.targetId = targetLevelId NetManager.SendMessage(MessageEnums.MessageFubenQuickPass, msg) end function private.FubenQuickPassResp(msgResp) if msgResp.Resp.Code == 0 then if msgResp.mapType == LuaConst.LevelType.ClimbTower then CTL.ClimbTower.OnFubenQuickPass(msgResp) elseif msgResp.mapType == LuaConst.LevelType.NationClimbTower then CTL.ClimbTower.OnFubenQuickPass(msgResp) elseif msgResp.mapType == LuaConst.LevelType.PersonalBoss then EventSystem.Dispatch(EventID.UI_FubenQuickPass, msgResp.mapType) end end end function LevelSelect_Model.SetHpPercentResult(msg) local maxHpSum = FP.newV1(0) local hpSum = FP.newV1(0) local entityData = BattleDataGetter.GetHeroEntityTable(LuaConst.STANDALONE_PLAYER_PlayID) for i,v in pairs(entityData) do local data = fuben_pb.HeroId2Hp() local attrComp = v.components.attr data.heroId = tostring(v._logicInitData.CharacterID) data.hp = tostring(FP.tonumberV1(attrComp.hp) / FP.tonumberV1(attrComp:MaxHP())) data.totalHp = FP.tonumberV1(attrComp:MaxHP()) maxHpSum:Add(attrComp:MaxHP()) hpSum:Add(attrComp.hp) table.insert(msg.heroId2Hp, data) end if maxHpSum > FP.Const.Zero then table.insert(msg.leftHpRation, FP.tonumberV1(hpSum / maxHpSum)) else table.insert(msg.leftHpRation, 0) end maxHpSum:Reset(0) hpSum:Reset(0) local entityList = BattleDataGetter.GetHeroEntityTable(LuaConst.STANDALONE_ENEMYPLAYER1_PLAYID) if entityList then for i,v in ipairs(entityList) do maxHpSum:Add(v.components.attr:MaxHP()) hpSum:Add(v.components.attr.hp) end if maxHpSum > FP.Const.Zero then table.insert(msg.leftHpRation, FP.tonumberV1(hpSum / maxHpSum)) else table.insert(msg.leftHpRation, 0) end end end function private.OnPreLevelSucceed(clientIntermediateParams) local nextLevelID = BattleDataGetter.GetNextLevelID() local systemData = nil if nextLevelID > 0 then if LevelManager.IsGoldHeroExperience() then -- 金将体验关 systemData = MDL.GoldenHeroStory.GetCurLevelSystemData() else systemData = BattleDataGetter.GetBarrierChosenIDByLevelID(nextLevelID) end end if systemData then MDL.LevelSelect.EnterFuben(LevelManager.LevelType, systemData.ID, clientIntermediateParams, nextLevelID) end end --- 战斗结算相关协议 --- 注意:这个结算协议如果有任何修改 ,都需要同时修改 LevelFunction:GetBattleSummaryInfoForCheck function private.RoleFinishFubenRequest(isWin, needStarTable, damageToBoss, boxRewardIds, armyDmgList, bossMaxHp, awakenHeroID) if type(damageToBoss) == "table" then damageToBoss = FP.tonumberV1(damageToBoss) end local msg = fuben_common.FinishFubenReq() msg.isWin = isWin if needStarTable then local starTable = CTL.LevelSelect.GetStarTable() if starTable then for i, v in ipairs(starTable) do table.insert(msg.star, v) end end end --再次提醒注意:这个结算协议如果有任何修改 ,都需要同时修改 LevelFunction:GetBattleSummaryInfoForCheck --- local mapType = BattleDataGetter.GetLevelInfoData().LevelType msg.mapType = mapType msg.passTime = math.ceil(BattleDataGetter.GetSummaryTime() + BattleDataGetter.GetPassTimeOfPrevious()) msg.passMilTime = math.ceil((BattleDataGetter.GetSummaryTime() + BattleDataGetter.GetPassTimeOfPrevious()) * 1000) msg.BossHp = BattleDataGetter.GetBossHpLeftPercent() or 1 msg.heroDeadNum = BattleDataGetter.GetPlayerDeadHeroCount(BattleDataGetter.GetCurPlayerID()) msg.saveRecordStr = BattleDataGetter.GetCurLevelSaveRecordBytes() if damageToBoss then msg.bossDamage = damageToBoss end if awakenHeroID then msg.awakenHeroId = awakenHeroID end if bossMaxHp then msg.bossMaxHp = bossMaxHp end if armyDmgList then for i,v in ipairs(armyDmgList) do table.insert(msg.armyDamage, v) end end if boxRewardIds then for i,id in ipairs(boxRewardIds) do table.insert(msg.boxRewardIds, id) end end LevelSelect_Model.SetHpPercentResult(msg) --- 再次提醒注意:这个结算协议如果有任何修改 ,都需要同时修改 LevelFunction:GetBattleSummaryInfoForCheck --- if LevelManager.IsServerNeedCheckNotSyncLevel() then msg.CheckInfo = LevelManager.CurLevelFunc:GetBattleResultCheckStr() if damageToBoss then msg.CheckInfo = msg.CheckInfo .. ";dmg2Boss =" .. damageToBoss end if boxRewardIds then msg.CheckInfo = msg.CheckInfo .. ";boxReward:" for i,id in ipairs(boxRewardIds) do msg.CheckInfo = msg.CheckInfo .. id .."," end end logging.log(LTAG.LOG,"FinishFubenRequest CheckInfo = ", msg.CheckInfo) msg.battleFrame = LevelManager.GetRecordFrameCmds() BattleSimulator.SaveAsyncFrames(msg.battleFrame) CTL.Replay.SaveAsyncLevelFrameDatas(msg.battleFrame, BIManager.GetBattleIDStr(), msg.CheckInfo) else if LevelManager.IsBossChallenge() then local battleFrame = LevelManager.GetRecordFrameCmds() local checkInfo = LevelManager.CurLevelFunc:GetBattleResultCheckStr() CTL.Replay.SaveAsyncLevelFrameDatas(battleFrame, BIManager.GetBattleIDStr(), checkInfo) --[[elseif LevelManager.IsRogueLike() then local battleFrame = LevelManager.GetRecordFrameCmds() local checkInfo = LevelManager.CurLevelFunc:GetBattleResultCheckStr() CTL.Replay.SaveAsyncLevelFrameDatas(battleFrame, "roguelike", checkInfo)--]] end end msg.score = LevelManager.CurLevelFunc:GetLevelScore() if LevelManager.IsRogueLike() then for _, v in ipairs(BattleDataGetter.GetRogueLikeSelectSkills()) do table.insert(msg.chooseSkill, v) end end if LevelManager.IsLootMine() then msg.mineInfo.fightType = MDL.GuildMine.BattleData.fightType msg.mineInfo.mineLevel = MDL.GuildMine.BattleData.mineLevel msg.mineInfo.playerAcid = MDL.GuildMine.BattleData.playerAcid msg.mineInfo.beHelpAcid = MDL.GuildMine.BattleData.beHelpAcid msg.mineInfo.lootTime = MDL.GuildMine.BattleData.lootTime msg.mineInfo.mineBeginTime = MDL.GuildMine.BattleData.mineBeginTime end NetManager.SendMessage(MessageEnums.MessageFinishFuben, msg) private.SendBIFinishFubenEvent() end function private.SendBIFinishFubenEvent() local curLevelID = CTL.LevelSelect.GetCurrentLevelId() local starNum = nil if BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.NORMAL) then starNum = MDL.LevelSelect.GetLevelStarNumById(curLevelID) elseif BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.Biography) then starNum = MDL.Biography.GetBiographyLevelStarNumById(curLevelID) end EventSystem.Dispatch(EventID.BI_FinishFuben, curLevelID, starNum) end function private.RoleFinishFubenResponse(msgResp) logging.log(LTAG.LOG, "RoleFinishFubenResp", msgResp) if msgResp.Resp.Code == 0 then if not BattleDataGetter.IsOnlineTownLevel() then CTL.HomeMain.CloseBasicView() if not CTL.Guide.HandleGuideSummary() then if LevelManager.IsPlanesLevel() then CTL.LevelSelect.LeaveBattleDirectly(msgResp) elseif BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.ClimbTower) then CTL.ClimbTower.ShowBattleSummary(msgResp) elseif BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.NationClimbTower) then CTL.NationClimbTower.ShowBattleSummary(msgResp) elseif BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.BossChallenge) then CTL.BossChallenge.ShowBattleSummary(msgResp.bosschallengeInfo) MDL.Level.TrySendBattleEvent() elseif BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.SubjectMonthBossChallenge) then CTL.MonthBossChallenge.ShowBattleSummary(msgResp.bosschallengeInfo) elseif BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.OfficialPosition) then CTL.OfficialPosition.ShowBattleSummary(msgResp) elseif BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.DemonGod) then CTL.DemonGod.ShowBattleSummary(msgResp) elseif BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.NineVsNineFight) then CTL.ThreeTeamFight.ShowBattleSummary() elseif BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.SoloFight) then CTL.SoloFight.ShowBattleSummary(msgResp) elseif BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.Resource) then MDL.Level.SendRoleLeaveFuben() EventSystem.Dispatch(EventID.UI_LevelSelect_LevelFinished) LevelSelect_Model.TriggerNewChapterAwardEft(true) elseif BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.SyncGuildBoss) then CTL.GuildBoss.ShowBattleSummary(msgResp) elseif BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.PersonalBoss) then CTL.PersonalBoss.ShowBattleSummary(msgResp) elseif BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.Nobility) then -- 进爵副本结束打开结算界面 CTL.Nobility.ShowBattleSummary(msgResp) elseif BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.GoldHeroCooperate) then CTL.GoldenHeroBoss.ShowBattleSummary(msgResp) elseif BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.GoldHeroClimbTower) then CTL.GoldenHeroAnecdote.ShowBattleSummary(msgResp) elseif BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.Biography) then CTL.Biography.ShowHeroBioBattleSummary(msgResp) EventSystem.Dispatch(EventID.UI_LevelSelect_LevelFinished) LevelSelect_Model.TriggerNewChapterAwardEft(true) elseif BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.DigNormal) then CTL.Task.QuickUseNormalTreasure() CTL.TeamDungeon.ShowDigTreasureSummary(msgResp) elseif BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.AdvancedDigNormal) then CTL.Task.QuickUseAdvancedTreasure() CTL.TeamDungeon.ShowDigTreasureSummary(msgResp) elseif BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.GoldHeroShow) then UIManager.OpenView(Const_UI_Lua.UIEnum.UIGoldenHeroTrySummary, {Reward = msgResp.Resp.Rewards, isWin = msgResp.isWin, Time = msgResp.passTime}, "Common/UICommonSummary") elseif BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.GoldHeroTrail) then CTL.SuperGoldBoss.ShowBattleSummary(msgResp) elseif BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.StormChallenge) then CTL.Storm.ShowStormBattleSummary(msgResp) elseif BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.AttackCity) then UIManager.OpenView(Const_UI_Lua.UIEnum.UIGVGFightSummaryPanel, msgResp) elseif BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.LootMine) then CTL.GuildMine.ShowGuildMineSummary(msgResp) elseif BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.ExpelMonster) then CTL.ExpelMonster.ShowExpelMonsterSummary(msgResp) elseif BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.SlgGvE) then CTL.SlgGvE.ShowSlgGvESummaryPanel(msgResp) elseif BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.RogueLike) then CTL.Rogue.ShowRogueSummaryPanel(msgResp) elseif BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.HeroAwakePlayer) then if not msgResp.isWin then MDL.Level.SendRoleLeaveFuben() end elseif BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.HeroAwakeBoss) then CTL.AwakenActivity.ShowBattleSummary(msgResp) else if BattleDataGetter.HasNextLevel() and msgResp.isWin then private.OnPreLevelSucceed(BattleDataGetter.GetLevelClientIntermediateParamsBytes()) else if BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.GoldHeroExperience) then CTL.GoldenHeroStory.ShowBattleSummary(msgResp) elseif BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.SuperGoldHeroExperience) then CTL.SuperGoldStory.ShowBattleSummary(msgResp) else CTL.LevelSelect.ShowBattleSummary(msgResp) end EventSystem.Dispatch(EventID.UI_LevelSelect_LevelFinished) LevelSelect_Model.TriggerNewChapterAwardEft(true) end end end end if not BattleDataGetter.ShouldKeepSyncLevel() then NotSyncBattleSetter.ResetLevelData() end CTL.LevelSelect.ClearCurrentLevelId() BIManager.SetBattleID(nil, nil) else -- 这里需要处理特殊errorcode弹窗 local msgData = DataSheetManager.ErrorCode:GetDataByID(msgResp.Resp.Code) if not msgData then return end if BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.AttackCity) then -- 如果是攻城略地 则打开主界面 if UNITY_EDITOR or TAI_DEVELOPMENT_BUILD then UTL.MessageBox.ShowOnlyOkBox(Const_IDS[msgData.IDS], msgOk, CTL.GVGFight.OpenGVGFightMain) else UTL.MessageBox.ShowOnlyOkBox(Const_IDS.IDS_WARNING, Const_IDS[msgData.IDS], CTL.GVGFight.OpenGVGFightMain) end elseif BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.NineVsNineFight) then UTL.MessageBox.ShowOnlyOkBox(Const_IDS.IDS_WARNING, Const_IDS[msgData.IDS], MDL.Level.SendRoleLeaveFubenFromSetting) elseif BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.ExpelMonster) then UTL.MessageBox.ShowOnlyOkBox(Const_IDS.IDS_WARNING, Const_IDS[msgData.IDS], MDL.Level.SendRoleLeaveFubenFromSetting) elseif BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.SlgGvE) then UTL.MessageBox.ShowOnlyOkBox(Const_IDS.IDS_WARNING, Const_IDS[msgData.IDS], MDL.Level.SendRoleLeaveFubenFromSetting) elseif BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.SubjectMonthBossChallenge) then UTL.MessageBox.ShowOnlyOkBox(Const_IDS.IDS_WARNING, Const_IDS[msgData.IDS], MDL.Level.SendRoleLeaveFubenFromSetting) end end end function LevelSelect_Model.ClaimChapterRewardChestRequest(chapterId, index) local msg = fuben_pb.AwardChapterReq() msg.chapterId = chapterId msg.subId = index NetManager.SendMessage(MessageEnums.MessageAwardChapter, msg) end function private.ClaimChapterRewardChestResponse(msgResp) if msgResp.Resp.Code == 0 then EventSystem.Dispatch(EventID.UI_LevelSelect_RefreshChapterSelected) EventSystem.Dispatch(EventID.UI_LevelSelect_ClaimedReward) end end ------------------------------------------------- 章节奖励 ----------------------------------------------------- -- 初始化章节奖励缓存 function private.DealWithChapterRewards(chapterGoalIds) if chapterGoalIds and #chapterGoalIds > 0 then for _, chapterGoalId in ipairs(chapterGoalIds) do private.chapterClaimAwards[chapterGoalId] = true end end local chapterBlockID = LevelSelect_Model.DLCBlockChapterID for i, v in DataSheetManager.ChapterGoalData:GetEnumerator() do if not private.chapterClaimAwards[v.ChapterGoalID] then -- DLC屏蔽的章节 if chapterBlockID > 0 then if v.ChapterGoalID >= chapterBlockID then break end end local curChapterID = LevelSelect_Model.GetChapterIdByLevelId(v.ChapterGoalStartLevel) local endChapterID = LevelSelect_Model.GetChapterIdByLevelId(v.ChapterGoalEndLevel) local chapterShowAward = { chapterGoalId = v.ChapterGoalID, isUnlock = false, amountLevel = 0, startChapterId = curChapterID, endChapterId = endChapterID, chapterData = {}, townIsAutoDisplay = v.TownIsAutoDisplay, } while (curChapterID <= endChapterID) do local chapterData = DataSheetManager.BarrierChapterData:GetDataByBarrierCharpterID(curChapterID) chapterShowAward.amountLevel = curChapterID < endChapterID and chapterShowAward.amountLevel + chapterData.BarrierNum or chapterShowAward.amountLevel + v.ChapterGoalEndLevel - (curChapterID * ChapterIdStartNum) chapterShowAward.chapterData[curChapterID] = { startLevelId = curChapterID * ChapterIdStartNum + 1, endLevelId = curChapterID < endChapterID and curChapterID * ChapterIdStartNum + chapterData.BarrierNum or v.ChapterGoalEndLevel } curChapterID = curChapterID + 1 end local data = DataSheetManager.ChapterGoalData:GetDataByChapterGoalID(chapterShowAward.chapterGoalId) chapterShowAward.isUnlock = MDL.Unlock.IsComplete(data.Unlock_Table[1].UnlockCondition, data.Unlock_Table[1].UnlockConditionParam) table.insert(private.chapterShowAwards, chapterShowAward) end end end -- 领取章节奖励C/S协议 function LevelSelect_Model.ClaimChapterAwardRequest(goalId) local msg = fuben_pb.AwardChapterGoalReq() msg.goalId = goalId NetManager.SendMessage(MessageEnums.MessageAwardChapterGoal, msg) end function private.ClaimChapterAwardResponse(msgResp) -- 删除显示 local showIndex = nil for i, v in ipairs (private.chapterShowAwards) do if v.chapterGoalId == msgResp.goalId then showIndex = i private.chapterClaimAwards[msgResp.goalId] = true table.remove(private.chapterShowAwards, i) break end end if showIndex and showIndex > LevelSelect_Model.GetChapterGoalLength() then showIndex = nil end LevelSelect_Model.SetCurrentRewardChapterID(msgResp.goalId) LevelSelect_Model.SetChapterAwardShowIndex(showIndex) EventSystem.Dispatch(EventID.UI_Chapter_ClaimAward) end -- 根据章节奖励任务ID获取相关缓存 function LevelSelect_Model.GetChapterGoalCache(goalId) if not goalId then return nil end for i, v in ipairs (private.chapterShowAwards) do if v.chapterGoalId == goalId then return v end end return nil end function LevelSelect_Model.SetCurrentRewardChapterID(currentRewardChapterID) private.currentRewardChapterID = currentRewardChapterID end function LevelSelect_Model.GetCurrentRewardChapterID() return private.currentRewardChapterID end -- 根据章节奖励任务下标获取相关缓存 function LevelSelect_Model.GetChapterGoalCacheByIndex(index) if not index then return nil end return private.chapterShowAwards[index] end -- 根据章节奖励任务ID获取相关显示下标 function LevelSelect_Model.GetChapterGoalShowIndex(goalId) if not goalId then return 1 end for i, v in ipairs (private.chapterShowAwards) do if v.chapterGoalId == goalId then return i end end return 1 end -- 获取当前显示章节奖励任务长度 function LevelSelect_Model.GetChapterGoalLength() return #private.chapterShowAwards end -- 获取当前显示章节奖励ID function LevelSelect_Model.GetCurChapterGoalId() -- 找出未领取奖励的任务 for i, v in ipairs (private.chapterShowAwards) do if not LevelSelect_Model.IsClaimChapterGoalAward(v.chapterGoalId) then return v.chapterGoalId end end -- 找出最新正在进行的章节任务 for i, v in ipairs (private.chapterShowAwards) do if LevelSelect_Model.GetCompleteLevelCount(v.chapterGoalId) < v.amountLevel then return v.chapterGoalId end end return -1 end function LevelSelect_Model.GetUnclaimedChapterGoalData(chapterId) for i, v in ipairs (private.chapterShowAwards) do if v.startChapterId <= chapterId and v.endChapterId >= chapterId then if not LevelSelect_Model.IsClaimChapterGoalAward(v.chapterGoalId) then return v end end end end function LevelSelect_Model.IsRewardItemInChapterGoalAward(itemId) for i, v in DataSheetManager.ChapterGoalData:GetEnumerator() do if LevelSelect_Model.GetChapterGoalCache(v.ChapterGoalID) then local itemTable = DataSheetManager.ChapterGoalReward:GetDataByID(v.ChapterGoalReward).Item_Table for index, value in ipairs(itemTable) do if value.ItemID == itemId then return true end end end end return false end -- 判断当前章节奖励任务是否已领取奖励 function LevelSelect_Model.IsClaimChapterGoalAward(goalId) if not goalId then return false end return #private.chapterClaimAwards > 0 and private.chapterClaimAwards[goalId] end -- 获取当前章节奖励任务完成主线剧情关卡数量 function LevelSelect_Model.GetCompleteLevelCount(goalId) if not goalId then return 0 end for _, v in ipairs (private.chapterShowAwards) do if v.chapterGoalId == goalId then local completeCount = 0 for chapterId, chapterData in pairs (v.chapterData) do if MDL.Unlock.PassedLevel(chapterData.startLevelId) then if MDL.Unlock.PassedLevel(chapterData.endLevelId) then completeCount = completeCount + chapterData.endLevelId - chapterData.startLevelId + 1 else for i = chapterData.startLevelId, chapterData.endLevelId do if not MDL.Unlock.PassedLevel(i) then break end completeCount = completeCount + 1 end end end end return completeCount end end return 0 end function LevelSelect_Model.IsUnlockChapterGoalAward() local fuctionUnlockData = DataSheetManager.FuctionUnlock:GetDataByFucID(54) return MDL.Unlock.IsComplete(fuctionUnlockData.Unlock_Table[1].UnlockCondition, fuctionUnlockData.Unlock_Table[1].UnlockConditionParam) end -- UIChapterGoal使用 记录当前章节奖励任务显示下标 function LevelSelect_Model.SetChapterAwardShowIndex(index) private.chapterAwardShowIndex = index end function LevelSelect_Model.GetChapterAwardShowIndex() return private.chapterAwardShowIndex end -- 主城界面触发下一个章节解锁提示特效 function LevelSelect_Model.TriggerNewChapterAwardEft(isDelayToHomeTown) if not private.chapterShowAwards or #private.chapterShowAwards == 0 then return end local isHasUnlock = false local curLevelID = CTL.LevelSelect.GetCurrentLevelId() --注意这个只在结算协议下行暂时有效 for _, v in ipairs (private.chapterShowAwards) do local data = DataSheetManager.ChapterGoalData:GetDataByChapterGoalID(v.chapterGoalId) --1.自动弹出章节奖励解锁特效的判断 if not v.isUnlock and MDL.Unlock.IsComplete(data.Unlock_Table[1].UnlockCondition, data.Unlock_Table[1].UnlockConditionParam) then if not isHasUnlock then if not isDelayToHomeTown then -- 发事件 private.PlayNewUnlockOnHomeTown(v.chapterGoalId) else -- 加入延迟显示 CTL.HomeMain.AddTownHomeDelayFunc(private.PlayNewUnlockOnHomeTown, v.chapterGoalId) end isHasUnlock = true end v.isUnlock = true end --2.自动弹出章节奖励主界面的判断 if v.townIsAutoDisplay == 1 and curLevelID == data.ChapterGoalEndLevel and LevelSelect_Model.GetCompleteLevelCount(v.chapterGoalId) == v.amountLevel then --通完最后一关,按配置弹出提示 if not isDelayToHomeTown then -- 发事件 private.PlayNewUnlockEndOnHomeTown(v.chapterGoalId) else -- 加入延迟显示 CTL.HomeMain.AddTownHomeDelayFunc(private.PlayNewUnlockEndOnHomeTown, v.chapterGoalId) end end end end function private.PlayNewUnlockOnHomeTown(chapterGoalId) EventSystem.Dispatch(EventID.UI_ChapterGoal_NewUnlock, chapterGoalId) end function private.PlayNewUnlockEndOnHomeTown(chapterGoalId) EventSystem.Dispatch(EventID.UI_ChapterGoal_NewUnlockPlayEnd, chapterGoalId) end --------------------------------------------------------------------------------------------------------------- return LevelSelect_Model