local MaterialLevel_Model = {} local private = {} local resourceLevelInfos = {} local sweep_pb = require("Proto/sweep_pb") MaterialLevel_Model.LevelState = { NoPass = 1, --未通关 MaxStars = 2, -- 满星 Stars = 3, -- 不满星 } local fuben_common = require('Proto/fuben_pb') local EventSystem = require('Event/EventSystem') MaterialLevel_Model.CurLevelId = nil local hasEnterNumsDic = {} local officialPosNumsDic = {} function MaterialLevel_Model.OnStartup() EventSystem.Regist(EventID.MaterialLevel_Summary, private.RoleFinishFuben) NetManager.RegisterMsgCB(MessageEnums.MessageSweepResourceLevel,private.OnSweepResourceLevel) NetManager.RegisterMsgCB(MessageEnums.MessageOneKeySweepResourceLevel, nil) NetManager.RegisterMsgCB(MessageEnums.MessageSetSweepResourceLevelConfig, private.SetSweepResourceLevelConfigResp) NetManager.RegisterMsgCB(MessageEnums.MessageGetSweepResourceLevelConfig,private.GetSweepResourceLevelConfigResp) EventSystem.Regist(EventID.UI_RefreshOfficialPositionInfo, private.OnOfficialPositionUpdate) EventSystem.Regist(EventID.AcquireSystemRedAfterUnlock, private.OnEnterWorldPostprocess) private.AutoSweepSetting = {} end function private.OnEnterWorldPostprocess() local count = MaterialLevel_Model.GetTotalCount(true) EventSystem.Dispatch(EventID.UI_Activity_Refresh_Single_RedPoint, LuaConst.ActivityType.ResourcesChapter, count > 0) end function MaterialLevel_Model.GetTotalCount(isUnlock) local count1,totalCount1, payCount1 = MaterialLevel_Model.GetCount(LuaConst.ActivityType.ResourcesChapterChild1, isUnlock) local count2,totalCount2, payCount2 = MaterialLevel_Model.GetCount(LuaConst.ActivityType.ResourcesChapterChild2, isUnlock) local count3,totalCount3, payCount3 = MaterialLevel_Model.GetCount(LuaConst.ActivityType.ResourcesChapterChild3, isUnlock) return count1 + count2 + count3, totalCount1 + totalCount2 + totalCount3, payCount1 + payCount2 + payCount3 end --需要监听官职变化,修改挑战次数 function private.OnOfficialPositionUpdate() local hasChange = false if resourceLevelInfos.resourceChapterInfo then for i, v in ipairs(resourceLevelInfos.resourceChapterInfo) do local hasEnterNums = hasEnterNumsDic[v.chapterId] or 0 local officialPosNums = officialPosNumsDic[v.chapterId] or 0 local newNums = CTL.Activities.GetLeftTimesByType(v.chapterId, hasEnterNums, officialPosNums) if newNums ~= v.nums then v.nums = newNums hasChange = true end end end if hasChange then EventSystem.Dispatch(EventID.UI_PurchaseNumsSuccess) end end function MaterialLevel_Model.SetInfo(info) resourceLevelInfos.resourceChapterInfo = resourceLevelInfos.resourceChapterInfo or {} for i,v in ipairs(info.resourceChapterInfo) do local isExist = false for index, value in ipairs(resourceLevelInfos.resourceChapterInfo) do if v.chapterId == value.chapterId then resourceLevelInfos.resourceChapterInfo[index] = v isExist = true end end if not isExist then table.insert( resourceLevelInfos.resourceChapterInfo, v) end --协议里nums的意义由原来的剩余次数改成已使用次数,在源数据改成原来的意义,不影响原来的调用逻辑 hasEnterNumsDic[v.chapterId] = v.nums officialPosNumsDic[v.chapterId] = v.usedNum local leftNums = CTL.Activities.GetLeftTimesByType(v.chapterId, v.nums, v.usedNum) v.nums = leftNums end EventSystem.Dispatch(EventID.UI_MaterialLevel_Refresh) local count = MaterialLevel_Model.GetTotalCount(true) EventSystem.Dispatch(EventID.UI_Activity_Refresh_Single_RedPoint, LuaConst.ActivityType.ResourcesChapter, count > 0) end function MaterialLevel_Model.IsThreeStars(levelId) local stars = MaterialLevel_Model.GetLevelStars(levelId) local threeStars = false if stars then threeStars = stars[1] == 1 and stars[2] == 1 and stars[3] == 1 end local excelData = DataSheetManager.ResourcesChapterStage:GetDataByID(levelId) local stageName = string.FormatByIdsId(Const_IDS[excelData.StageName], UIUtils.GetLocalizedTxt(Const_IDS["IDS_Number_Written_"..excelData.StageNum])) return threeStars , string.FormatByIdsId(Const_IDS.IDS_ResourcesChapter_UnlockReminder_4, stageName) end function MaterialLevel_Model.GetLevelStars(levelId) for i, v in ipairs(resourceLevelInfos.resourceChapterInfo) do for j, k in ipairs(v.resourceLevel) do if k.levelId == levelId then if k.star[1] ~= nil then return k.star end end end end return {0,0,0} end function MaterialLevel_Model.IsPass(levelId) local stars = MaterialLevel_Model.GetLevelStars(levelId) if stars then return stars[1] == 1 or stars[2] == 1 or stars[3] == 1 end end function MaterialLevel_Model.IsUnlock(levelId) local stars = MaterialLevel_Model.GetLevelStars(levelId) local excelData = DataSheetManager.ResourcesChapterStage:GetDataByID(levelId) return MDL.Unlock.IsComplete(excelData.StageUnlockType,excelData.StageUnlockValue) end function MaterialLevel_Model.CanChallenge(levelId) local __, excelData = DataSheetManager.ResourcesChapterStage:TryGetDataByID(levelId) if excelData then local value , str = MDL.Unlock.IsComplete(excelData.StageChallengeType,excelData.StageChallengeValue) return value and MDL.Unlock.IsComplete(excelData.StageUnlockType,excelData.StageUnlockValue) , str end end -- 返回 当前可用次数,配置次数,可用购买次数 function MaterialLevel_Model.GetCount(id, isUnlock) if isUnlock then local materialData = DataSheetManager.ResourcesChapterBase:GetDataByID(id) local isOpen = MDL.Unlock.IsComplete(materialData.UnlockCondition,materialData.UnlockConditionParam) if not isOpen then return 0, 0, 0 end end local activityData = DataSheetManager.ActivityData:GetDataByID(id) local materialInfo = MaterialLevel_Model.GetDataBychapterId(id) if materialInfo then local totalTimes = activityData.DailyRefreshTimes --只显示基础次数 local payCount = MDL.Purchase.GetAvailablePurchaseTimes(id) return materialInfo.nums , totalTimes, payCount else return activityData.DailyRefreshTimes,activityData.DailyRefreshTimes, #activityData.PayNum end end function MaterialLevel_Model.GetDataBychapterId(id) if not resourceLevelInfos or not resourceLevelInfos.resourceChapterInfo then return end for i, v in ipairs(resourceLevelInfos.resourceChapterInfo) do if v.chapterId == id then return v end end end function MaterialLevel_Model.IsNewOpen(id) local info = MaterialLevel_Model.GetDataBychapterId(id) for i,v in DataSheetManager.ResourcesChapterStage:GetEnumerator() do if v.DungeonType == id then if MaterialLevel_Model.IsUnlock(v.ID) then local stars = MaterialLevel_Model.GetLevelStars(v.ID) if stars == nil or (stars[1] == 0 and stars[2] == 0 and stars[3] == 0) then return true end end end end return false end function MaterialLevel_Model.GetAutomateSweepSetting() return private.AutoSweepSetting end function private.SetAutoSweepSetting(config) if IsProtoDataNotNil(config) and #config > 0 then for i, v in ipairs(config) do if not private.AutoSweepSetting[i] then private.AutoSweepSetting[i] = {} end private.AutoSweepSetting[i].levelId = v.levelId private.AutoSweepSetting[i].buyNums = v.buyNums end else local count = 0 for i, v in DataSheetManager.ResourcesChapterBase:GetEnumerator() do count = count + 1 if count > 3 then break end private.AutoSweepSetting[i] = { levelId = v.ID, buyNums = 0 } end end end function private.IsValidSweepSetting() local isValid = false if MaterialLevel_Model.IsNoFirstLevelPassed() then return false, Const_IDS.IDS_HeroBiography_NotClear end if #private.AutoSweepSetting > 0 then for i, v in ipairs(private.AutoSweepSetting) do local count, totalCount, availableBuyCount = MDL.MaterialLevel.GetCount(v.levelId) if count > 0 or availableBuyCount > 0 then isValid = true end end if not isValid then return false, Const_IDS["IDS_ResourcesChapter_Sweep9"] end return true else return false, Const_IDS["IDS_HeroBiography_Sweep11"] end end function MaterialLevel_Model.IsNoFirstLevelPassed() for i, v in DataSheetManager.ResourcesChapterBase:GetEnumerator() do local count = 0 for _, subData in DataSheetManager.ResourcesChapterStage:GetEnumerator() do if subData.DungeonType == v.ID then count = count + 1 if count == 1 and not MaterialLevel_Model.IsPass(subData.ID) then return true end end end end return false end function MaterialLevel_Model.CheckAutomateSweep() for i, chapterData in DataSheetManager.ResourcesChapterBase:GetEnumerator() do for _, subData in DataSheetManager.ResourcesChapterStage:GetEnumerator() do local isOpen = MDL.Unlock.IsComplete(subData.StageUnlockType, subData.StageUnlockValue) if chapterData.ID == subData.DungeonType and not MaterialLevel_Model.IsPass(subData.ID) and isOpen then -- 有可挑战的关卡 CTL.MaterialLevel.PopSweepChallengeConfirm(chapterData.ID) return false end end end local isValid, tips = private.IsValidSweepSetting() if not isValid then CTL.Tips.AddTipsMsg(tips) return false end return true end function MaterialLevel_Model.Challenge(levelId,chapterId) if not CTL.TeamMatch.IsCanGoOtherScene(LuaConst.LevelType.Resource) then return end local msg = fuben_common.EnterFubenReq() msg.mapType = LuaConst.LevelType.Resource msg.id = levelId MaterialLevel_Model.CurLevelId = chapterId NetManager.SendMessage(MessageEnums.MessageEnterFuben, msg) end function private.RoleFinishFuben(isWin, needStarTable) local id = CTL.LevelSelect.GetCurrentLevelId() CTL.LevelSelect.ClearCurrentLevelId() local excelData = DataSheetManager.ResourcesChapterStage:GetDataByID(id) local stars = 0; for i,v in ipairs(CTL.LevelSelect.GetStarTable()) do if v == 1 then stars = stars + 1 end end CTL.HomeMain.CloseBasicView() local rewardList = {DataSheetManager.ResourcesChapterStageReward:GetDataByID(excelData.StageUnlockReward).Item_Table[stars]} UIManager.OpenView(Const_UI_Lua.UIEnum.UIMaterialLevelSummary, {Reward = rewardList, Win = isWin,MaterialId = excelData.DungeonType,isThreeStars = stars==3, Time = BattleDataGetter.GetSummaryTime()}) end function MaterialLevel_Model.GetReward(isWin) local msg = fuben_common.FinishFubenReq() if isWin then local starTable = CTL.LevelSelect.GetStarTable() if starTable then for i, v in ipairs(starTable) do table.insert(msg.star, v) end end end msg.isWin = isWin msg.mapType = BattleDataGetter.GetLevelInfoData().LevelType msg.passTime = math.ceil(BattleDataGetter.GetSummaryTime()) msg.saveRecordStr = BattleDataGetter.GetCurLevelSaveRecordBytes() if LevelManager.IsNeedCheckNotSyncLevel() then msg.battleFrame = LevelManager.GetRecordFrameCmds() end MDL.LevelSelect.SetHpPercentResult(msg) NetManager.SendMessage(MessageEnums.MessageFinishFuben, msg) end function MaterialLevel_Model.Sweep(levelId) local msg = sweep_pb.SweepResourceLevelReq() msg.levelId = levelId NetManager.SendMessage(MessageEnums.MessageSweepResourceLevel,msg) end function private.OnSweepResourceLevel() end --- 一键扫荡 function MaterialLevel_Model.OneKeySweepResourceLevelReq() local msg = sweep_pb.OneKeySweepResourceLevelReq() local isValid, tips = private.IsValidSweepSetting() if not isValid then CTL.Tips.AddTipsMsg(tips) return false end NetManager.SendMessage(MessageEnums.MessageOneKeySweepResourceLevel, msg) end --- 获取一键扫荡设置 function MaterialLevel_Model.GetSweepResourceLevelConfigReq() local msg = sweep_pb.GetSweepResourceLevelConfigReq() NetManager.SendMessage(MessageEnums.MessageGetSweepResourceLevelConfig, msg) end function private.GetSweepResourceLevelConfigResp(msg) if msg.Resp.Code == 0 then private.SetAutoSweepSetting(msg.config) EventSystem.Dispatch(EventID.UI_MaterialLevel_SweepRefresh) end end --- 设置一键扫荡设置 function MaterialLevel_Model.SetSweepResourceLevelConfigReq(sweepList) local msg = sweep_pb.SetSweepResourceLevelConfigReq() for i, v in ipairs(sweepList) do local tt = msg.config:add() tt.levelId = v.levelId tt.buyNums = v.buyNums end NetManager.SendMessage(MessageEnums.MessageSetSweepResourceLevelConfig, msg) end function private.SetSweepResourceLevelConfigResp(msg) if msg.Resp.Code == 0 then private.SetAutoSweepSetting(msg.config) CTL.Tips.AddTipsMsg(Const_IDS.IDS_ResourcesChapter_Sweep12) end end return MaterialLevel_Model