local Biography_Controller = {} local EventSystem = require('Event/EventSystem') local private = {} function Biography_Controller.OnStartup() EventSystem.Regist(EventID.UI_LevelSelect_LevelFinished, private.RefreshRedPoint) EventSystem.Regist(EventID.AcquireSystemRedAfterUnlock, private.RefreshRedPoint) EventSystem.Regist(EventID.UI_HeroBiography_UpdateInfo, private.RefreshRedPoint) EventSystem.Regist(EventID.FunctionUnlockUpdate, private.AutoRefineRefreshByGMS) private.tempBiographyId = nil private.sortedHeroBiographyLevel = DataSheetUtil.CreateSortedDataSheet("HeroBiographyLevel") end function private.AutoRefineRefreshByGMS(funcID, isUnlock) if funcID == MDL.Unlock.FunctionType.HeroBiographyAutoRefine then if not isUnlock then UIManager.CloseView(Const_UI_Lua.UIEnum.UIHeroBiographySweepSetPanel) UIManager.CloseView(Const_UI_Lua.UIEnum.UIHeroBiographySweepSelectPanel) end end end function Biography_Controller.GetTempBiographyId() return private.tempBiographyId end function Biography_Controller.SetTempBiographyId(biographyId) private.tempBiographyId = biographyId end function Biography_Controller.GetTempBiographyLevelId() return private.tempBiographyLevelId end function Biography_Controller.SetTempBiographyLevelId(levelId) private.tempBiographyLevelId = levelId end function Biography_Controller.GetLatestBiographyIndex() local unlockBiographyId = MDL.Biography.GetUnlockBiographyId() if not unlockBiographyId then return 0 end for i, v in DataSheetManager.HeroBiographyData:GetEnumerator() do if v.ID == unlockBiographyId then return i - 1 end end return 0 end function Biography_Controller.GetLatestBiographyLevelIndex(biographyId) local index = 0 for i, v in DataSheetManager.HeroBiographyLevel:GetEnumerator() do if v.BelongToBiography == biographyId then local starNum = MDL.Biography.GetBiographyLevelStarNumById(v.ID) if not starNum or starNum == 0 then return index end index = index + 1 end if v.BelongToBiography > biographyId then break end end return index end function Biography_Controller.GetHeroBiographyUnlockText(id) local unlockTable = DataSheetManager.HeroBiographyData:GetDataByID(id).Unlock_Table for k, v in pairs(unlockTable) do if LuaConst.UnlockConditionType.PassedLevel == v.UnlockCondition then--此处判断是活动添加的特殊版本需求后续可能会删掉 local levelId = tonumber(v.UnlockConditionParam) local isUnlock = MDL.Unlock.PassedLevel(levelId) if not isUnlock then local barrierData = DataSheetManager.BarrierChosenData:GetDataByID(levelId) local levelName = barrierData.BelongToChapter % 100 .."-"..barrierData.BarrierID levelName = CTL.LevelSelect.CommonDifficultIDS[barrierData.DifficultyDegree] .. levelName local text = string.FormatByIdsId(Const_IDS[v.UnlockDes], levelName) return text end else local tmpIsUnlock , tmpContent = MDL.Unlock.IsComplete(v.UnlockCondition, v.UnlockConditionParam, v.UnlockDes) if tmpIsUnlock == false then return tmpContent end end end return "" end function Biography_Controller.IsHeroBiographyUnlock(id) return CTL.Unlock.JudgeIfSatisfiedUnlockTable(DataSheetManager.HeroBiographyData:GetDataByID(id).Unlock_Table) end function Biography_Controller.IsHeroBiographyLevelUnlock(levelId) return CTL.Unlock.JudgeIfSatisfiedUnlockTable(DataSheetManager.HeroBiographyLevel:GetDataByID(levelId).Unlock_Table) end function Biography_Controller.IsHeroBiographyPassed(id) for i, v in DataSheetManager.HeroBiographyLevel:GetEnumerator() do if id == v.BelongToBiography then local starNum = MDL.Biography.GetBiographyLevelStarNumById(v.ID) if not starNum or starNum == 0 then return false end end end return true end function Biography_Controller.ClickAddTimes() if MDL.Purchase.GetAvailablePurchaseTimes(LuaConst.ActivityType.HeroBiography) > 0 then UIManager.OpenView(Const_UI_Lua.UIEnum.UIItemBuyPanel, {type = LuaConst.ActivityType.HeroBiography}) else local desc = MDL.OfficialPosition.GetPurchaseTimesDesc(LuaConst.ActivityType.HeroBiography) if desc then CTL.Tips.AddTipsMsg(desc) else CTL.Tips.AddTipsMsg(Const_IDS["IDS_HeroBiography_NoPayTime"]) end end end function Biography_Controller.IsCanEnterSingleBiography(biographyId, id) if Biography_Controller.IsHeroBiographyUnlock(biographyId) then if Biography_Controller.IsHeroBiographyLevelUnlock(id) then --首次打不用判断次数 if MDL.Biography.GetBiographyLevelStarNumById(id) <= 0 then return true end --总次数够且该列传的次数够 local curTimes = MDL.Biography.GetEnterNums() if curTimes > 0 and MDL.Biography.GetBiographyIfDailyCountLeft(biographyId) then return true end end end return false end function Biography_Controller.IsCanEnterBiography(biographyId) for i, v in DataSheetManager.HeroBiographyLevel:GetEnumerator() do if v.BelongToBiography == biographyId then if Biography_Controller.IsCanEnterSingleBiography(biographyId, v.ID) then return true end end end return false end function private.RefreshRedPoint() if Biography_Controller.IsShowBiographyHeroRedPoint() then CTL.RedPoint.AddRedPoint(CTL.RedPoint.RedPointKey.Biography) EventSystem.Dispatch(EventID.UI_Activity_Refresh_Single_RedPoint, LuaConst.ActivityType.HeroBiography, true) else CTL.RedPoint.RemoveRedPoint(CTL.RedPoint.RedPointKey.Biography) EventSystem.Dispatch(EventID.UI_Activity_Refresh_Single_RedPoint, LuaConst.ActivityType.HeroBiography, false) end end function Biography_Controller.IsShowBiographyHeroRedPoint() for i, v in DataSheetManager.HeroBiographyData:GetEnumerator() do local biographyId = v.ID if Biography_Controller.IsRecommendEnterBiography(biographyId) or Biography_Controller.IsCanEnterBiography(biographyId) then return true end end return false end function Biography_Controller.IsRecommendEnterBiography(biographyId) for i, v in DataSheetManager.HeroBiographyLevel:GetEnumerator() do if v.BelongToBiography == biographyId then if Biography_Controller.IsRecommendBiographyLevel(v.ID) then return true end end end return false end function Biography_Controller.IsRecommendBiographyLevel(biographyLevelId) if MDL.Biography.GetUnlockBiographyLevelId() and biographyLevelId <= MDL.Biography.GetUnlockBiographyLevelId() then --是否解锁 if MDL.Biography.GetBiographyLevelStarNumById(biographyLevelId) <= 0 then --是否未通关 return true end end return false end -- 打开结算界面 function Biography_Controller.ShowHeroBioBattleSummary(msg) CTL.HomeMain.CloseOpenView() UIManager.OpenView( Const_UI_Lua.UIEnum.UIHeroBiographySummary, { Reward = msg.Resp.Rewards, isWin = msg.isWin, Time = msg.passTime}, "Common/UICommonSummary" ) end -- 获取当前武将挑战下一关数据 -- 当前挑战为英雄最后一关或无数据 返回nil function Biography_Controller.GetNextLevelConfig() local biographyId = Biography_Controller.GetTempBiographyId() --获取进入副本前的英雄ID local levelNum = DataSheetManager.HeroBiographyData:GetDataByID(biographyId).LevelNum --当前英雄关卡数 local level = MDL.Biography.GetLastestSweepIndex(biographyId) -- 英雄可扫荡关卡 if level > 0 then local dataIndex = 1 local count = 0 for i, v in ipairs(private.sortedHeroBiographyLevel) do if v.BelongToBiography == biographyId then count = count + 1 end if v.ID == level then dataIndex = i break end end if count == levelNum then return nil end return private.sortedHeroBiographyLevel[dataIndex + 1] end end -- 判断下一关是否可以在副本挑战结算页面展示自动下一关 function Biography_Controller.CanChallengeNextLevel() local nextConfig = Biography_Controller.GetNextLevelConfig() logging.log(LTAG.LOG, "Biography_Model[CanChallengeNextLevel]", nextConfig) if nextConfig then local ifSatisfied, unlockText = CTL.Unlock.JudgeIfSatisfiedUnlockTable(nextConfig.Unlock_Table) local levelId = Biography_Controller.GetTempBiographyLevelId() local hasNum = MDL.Biography.GetBiographyIfDailyCountLeft(Biography_Controller.GetTempBiographyId()) local nextLeveId = nextConfig[1] -- 下一levelId if ifSatisfied and hasNum and nextLeveId ~= levelId then return true,nextConfig,nil else return false,nextConfig,unlockText end end --没有下一关 return false, nil, Const_IDS["IDS_ClimbTower_MaxLevel"] end return Biography_Controller