local FunctionNotice_Model = {} local private = {} local EventSystem = require('Event/EventSystem') local function_unlock_pb = require('Proto/function_unlock_pb') local FUNCTION_NOTICE_UNLOCK_POPUP = "FUNCTION_NOTICE_UNLOCK_POPUP" --=是否弹出过了功能解锁弹窗(k-functionId, v-true) --配置表里最大的id private.MaxFuncID = 0 --当前解锁的id private.CurFuncID = 0 --未领取奖励 private.awardUnGetDic = {} --已解锁未播动画的列表 private.UnExpList = {} --某些未解锁的功能在enterWorld不推送相应的数据了,等客户端功能解锁后,通知服务器来推送数据 private.noticeFuncDic = { [function_unlock_pb.Fight3v3] = 1, --同步3V3 [function_unlock_pb.BossChallenge] = 1, --boss挑战 [MDL.Unlock.FunctionType.SyncSolo] = 1, --同步1V1 } private.firstFuncId = 0 function FunctionNotice_Model.OnStartup() for _, v in DataSheetManager.FunctionPredictionData:GetEnumerator() do local funcID = v.FunctionPredictionID if v.FunctionDisplayType > 0 then private.awardUnGetDic[funcID] = 1 private.MaxFuncID = funcID end if private.firstFuncId == 0 and v.FunctionDisplayType > 0 then private.firstFuncId = v.FunctionPredictionID end end NetManager.RegisterMsgCB(MessageEnums.MessageUnlockFunctionReward, private.UnlockFunctionRewardResp) NetManager.RegisterMsgCB(MessageEnums.MessageAcquireFunction, private.AcquireFunctionResp) end function FunctionNotice_Model.GetFirstFuncID() return private.firstFuncId end --在Unlock模块初始化数据后再执行 function FunctionNotice_Model.ExecuteAfterUnlock() EventSystem.Regist(EventID.FunctionUnlockUpdate, private.OnFunctionUnlockUpdate) for _, v in DataSheetManager.FunctionPredictionData:GetEnumerator() do if v.FunctionDisplayType > 0 then if MDL.Unlock.IsUnlock(v.FucID) and v.FunctionPredictionID > private.CurFuncID then private.CurFuncID = v.FunctionPredictionID end end end end function FunctionNotice_Model.SyncAwardInfo(info) for _, v in ipairs(info.functionPreId) do if private.awardUnGetDic[v] ~= nil then private.awardUnGetDic[v] = nil end end EventSystem.Dispatch(EventID.UI_UpdateFunctionUnlockAward) end function FunctionNotice_Model.GetCurFuncID() return private.CurFuncID end function FunctionNotice_Model.GetNextFuncID() return FunctionNotice_Model.GetPreviewNextID(private.CurFuncID) end function FunctionNotice_Model.GetPreviewNextID(curID) local nextID = curID + 1 while true do local isSuccess, config = DataSheetManager.FunctionPredictionData:TryGetDataByFunctionPredictionID(nextID) if isSuccess then if config.FunctionDisplayType > 0 then return nextID end nextID = nextID + 1 else return 0 end end return 0 end function FunctionNotice_Model.GetPreviewBeforeID(curID) local nextID = curID - 1 while true do local config = DataSheetManager.FunctionPredictionData:GetDataByFunctionPredictionID(nextID) if config then if config.FunctionDisplayType > 0 then return nextID end nextID = nextID - 1 else return 0 end end return 0 end --是否有未领奖 function FunctionNotice_Model.GetIfAwardLeft() for k,_ in pairs(private.awardUnGetDic) do local config = DataSheetManager.FunctionPredictionData:GetDataByFunctionPredictionID(k) if MDL.Unlock.IsUnlock(config.FucID) then return true end end return false end --展示的功能ID function FunctionNotice_Model.GetShowFuncID() --是否有未领奖 for k,_ in pairs(private.awardUnGetDic) do local config = DataSheetManager.FunctionPredictionData:GetDataByFunctionPredictionID(k) if MDL.Unlock.IsUnlock(config.FucID) then return k end end --下一个配置 return FunctionNotice_Model.GetNextFuncID() end --是否奖励未领取 function FunctionNotice_Model.GetIfUnAward(funcID) return private.awardUnGetDic[funcID] ~= nil end function FunctionNotice_Model.GetIfUnAwardAfter(funcID) for i = funcID, private.MaxFuncID do if FunctionNotice_Model.GetIfUnAward(i) then local config = DataSheetManager.FunctionPredictionData:GetDataByFunctionPredictionID(i) if config.FunctionDisplayType > 0 and MDL.Unlock.IsUnlock(config.FucID) then return true end end end return false end function FunctionNotice_Model.GetIfUnAwardBefore(funcID) for i = 1, funcID do if FunctionNotice_Model.GetIfUnAward(i) then local config = DataSheetManager.FunctionPredictionData:GetDataByFunctionPredictionID(i) if config.FunctionDisplayType > 0 and MDL.Unlock.IsUnlock(config.FucID) then return true end end end return false end --入口是否开启 function FunctionNotice_Model.GetIfShowEntry() if MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.FunctionNotice) then if private.CurFuncID >= private.MaxFuncID then for _,v in pairs(private.awardUnGetDic) do return true end return false end return true end return false end --是否播完解锁动画 function FunctionNotice_Model.IsExpEnd(funcID) local funcID = tonumber(funcID) local config = DataSheetManager.FunctionPredictionData:GetDataByFunctionPredictionID(funcID) if MDL.Unlock.IsUnlock(config.FucID) then for _,v in ipairs(private.UnExpList) do if v.FunctionPredictionID == funcID then return false end end return true end return false end function FunctionNotice_Model.RemoveExpInfo(info) for i, v in ipairs(private.UnExpList) do if v == info then table.remove(private.UnExpList, i) break end end end function FunctionNotice_Model.GetExpInfoByGuideID(guideID) if #private.UnExpList == 0 then return nil end local expInfo = nil for _, v in ipairs(private.UnExpList) do if v.GuideID == guideID then expInfo = v break end end return expInfo end function FunctionNotice_Model.GetCurExpInfo() if #private.UnExpList == 0 then return nil end local expInfo = nil for _, v in ipairs(private.UnExpList) do if (v.GuideID > 0 and MDL.PlayerGuide.IsComplete(v.GuideID)) or v.GuideID == 0 then expInfo = v break end end return expInfo end --领取功能解锁奖励 function FunctionNotice_Model.UnlockFunctionRewardReq(funcID) local msg = function_unlock_pb.UnlockFunctionRewardReq() msg.functionPreId = funcID NetManager.SendMessage(MessageEnums.MessageUnlockFunctionReward, msg) end function private.UnlockFunctionRewardResp(msgResp) logging.log(LTAG.LOG, "UnlockFunctionRewardResp") end function private.OnFunctionUnlockUpdate(funcID, isComplete) --功能解锁通知服务器推送数据 if isComplete and private.noticeFuncDic[funcID] ~= nil then local msg = function_unlock_pb.AcquireFunctionReq() msg.functionType = funcID NetManager.SendMessage(MessageEnums.MessageAcquireFunction, msg) end --更新功能预告 if isComplete then for _, v in DataSheetManager.FunctionPredictionData:GetEnumerator() do if v.FucID == funcID then if not PersistentData.PlayerData:Get(FUNCTION_NOTICE_UNLOCK_POPUP..funcID) then if v.FunctionDisplayType > 0 then if v.FunctionPredictionID > private.CurFuncID then private.CurFuncID = v.FunctionPredictionID end end if v.IsFly == 1 then PersistentData.PlayerData:Set(FUNCTION_NOTICE_UNLOCK_POPUP..funcID, true, true) table.insert(private.UnExpList,v) end EventSystem.Dispatch(EventID.UI_UpdateFunctionNoticeUnlock) end break end end end end function FunctionNotice_Model.SetFunctionNoticeUnlockFalse(funcID) PersistentData.PlayerData:Set(FUNCTION_NOTICE_UNLOCK_POPUP..funcID, false, true) end function private.AcquireFunctionResp(msgResp) logging.log(LTAG.LOG, "AcquireFunctionResp") end function FunctionNotice_Model.GetUnExpList() return private.UnExpList end return FunctionNotice_Model