local EventSystem = require('Event/EventSystem') local role_nobility_pb = require 'Proto/role_nobility_pb' local fuben_pb = require 'Proto/fuben_pb' local Nobility_Model = {} local private = {} local LIMIT_Nobility_LEVEL = 10 function Nobility_Model.OnStartup() NetManager.RegisterMsgCB(MessageEnums.MessageNobilityGetUIInfo, private.NobilityGetUIInfoResponse) -- 界面信息 NetManager.RegisterMsgCB(MessageEnums.MessageNobilityStageUp, private.NobilityStageUpResponse) -- 激活、晋升 NetManager.RegisterMsgCB(MessageEnums.MessageNobilitySecondStageActive, private.NobilitySecondStageActiveResponse) -- 二阶段图标激活 NetManager.RegisterMsgCB(MessageEnums.MessageNobilityHeroUp, private.NobilityHeroUpResponse) -- 武将晋升 NetManager.RegisterMsgCB(EventID.CharacterTeamGsChange, private.RefreshTownHomeBtnRedPoint) -- 武将晋升 private.currentNobilityID = 1 -- 当前爵位 private.currentStage = 0 -- 当前进爵阶段 private.currentStageParams = {} -- 当前进爵阶段完成任务ID数组 private.nobilityID = 1 -- 备份当前爵位 private.currentStage2Dic = {} private.playerChangeSyncRedPoint = false private.SplitConfig() private.maxTeamLevel = 0 for i, v in DataSheetManager.TeamLevelData:GetEnumerator() do if private.maxTeamLevel < v.TeamLevel then private.maxTeamLevel = v.TeamLevel end end end --region -- **************** 数据部分 ******************* -- --完成阶段ID Nobility_Model.Enum_Stage = { First = 1, -- 一阶段完成,进入二阶段 second = 2, -- 二阶段完成,进入三阶段 thirdly = 3 , -- 爵位晋升,进入下个爵位 } --按照爵位拆分第二阶段 function private.SplitConfig() --按照类型拆分多人副本 for _,v in DataSheetManager.NobilityStage2:GetEnumerator() do if private.currentStage2Dic[v.RankID] == nil then private.currentStage2Dic[v.RankID] = {} end private.currentStage2Dic[v.RankID][v.SubStage] = v end end --endregion 数据部分 --region -- **************** 数据获取 ******************* - function Nobility_Model.GetNobilityID() return private.currentNobilityID end function Nobility_Model.GetStage() return private.currentStage end function Nobility_Model.GetStageParams() return private.currentStageParams end function Nobility_Model.GetStage1Config() local config = {} if private.currentNobilityID == DataSheetManager.Nobility:GetDataCount() then config = DataSheetManager.NobilityStage1:GetDataByRankID(private.currentNobilityID) else config = DataSheetManager.NobilityStage1:GetDataByRankID(private.currentNobilityID + 1) end local triggerIDConfig = DataSheetManager.TriggerID:GetDataByID(config.TriggerID).Unlock_Table return config, triggerIDConfig end function Nobility_Model.GetStage2Config() local config = private.currentStage2Dic[private.currentNobilityID + 1] return config end function Nobility_Model.GetStage3Config() local config = DataSheetManager.NobilityStage3:GetDataByRankID(private.currentNobilityID + 1) return config end -- 获取当前阶段进度 function Nobility_Model.GetProgress() local currentCont, configCount = #private.currentStageParams, 1 if private.currentStage == 0 then local config, triggerID = Nobility_Model.GetStage1Config() configCount = #triggerID currentCont = 0 for i = 1, #private.currentStageParams do local _, unlock_Table = Nobility_Model.GetStage1Config() local param = unlock_Table[i].UnlockConditionParamA if private.currentStageParams[i] >= tonumber(param) then currentCont = currentCont + 1 end end elseif private.currentStage == 1 then local config = private.currentStage2Dic[private.currentNobilityID + 1] configCount = #config elseif private.currentStage == 3 then currentCont = 1 end return currentCont, configCount end -- 获取属性展示内容 function Nobility_Model.GetAttribute(stage) local attr_Table if stage == 0 then attr_Table = DataSheetManager.NobilityStage1:GetDataByRankID(private.currentNobilityID + 1).Attr_Table elseif stage == 1 then attr_Table = Nobility_Model.GetStage2Config()[#private.currentStageParams].Attr_Table elseif stage == 3 then -- 这里展示的加成属性 = 当前等级的队伍属性 - 上个爵位最大等级的队伍属性 local teamLevel = MDL.Player.GetRoleLevel() local _, rank = MDL.Nobility.GetLevelAndNobility(teamLevel) local rankMaxLevel = DataSheetManager.Nobility:GetDataByRankID(rank - 1).TeamLevelMax local lastAttr_Table = DataSheetManager.TeamLevelData:GetDataByTeamLevel(rankMaxLevel).Attr_Table attr_Table = DataSheetManager.TeamLevelData:GetDataByTeamLevel(teamLevel).Attr_Table for i, currAttr in ipairs(attr_Table) do for _, lastAttr in ipairs(lastAttr_Table) do if currAttr.AttrType == lastAttr.AttrType then currAttr.AttrNum = currAttr.AttrNum - lastAttr.AttrNum end end end end return attr_Table end -- 红点状态 function Nobility_Model.GetRedPoint() if private.currentNobilityID == DataSheetManager.Nobility:GetDataCount() then return false end local currentCont, configCount = Nobility_Model.GetProgress() if private.currentStage == 0 then return currentCont >= configCount or private.playerChangeSyncRedPoint elseif private.currentStage == 1 then local isExpend = false local curExp = MDL.Player.GetRoleLevelExp() local activityConfig = Nobility_Model.GetStage2Config() for k,v in ipairs(activityConfig) do isExpend = curExp >= activityConfig[k].UseExp and true or false end return currentCont >= configCount or isExpend elseif private.currentStage == 2 then return Nobility_Model.GetStage3RedPoint() end return currentCont >= configCount end -- 获得主城入口的显隐状态 function Nobility_Model.GetIsActive() local playerLevel = MDL.Player.GetRoleLevel() if playerLevel > private.maxTeamLevel - LIMIT_Nobility_LEVEL then return false end local teamLevel = MDL.Player.GetRoleLevel() if teamLevel then for k,v in DataSheetManager.Nobility:GetEnumerator() do if v.Function == 0 then return false end if teamLevel >= v.Function and teamLevel <= v.TeamLevelMax then return true end end end return false end -- 武将是否可以进爵 function Nobility_Model.GetCanNobilityByHeroLevel(heroLevel) for k,v in DataSheetManager.Nobility:GetEnumerator() do if heroLevel == v.TeamLevelMax then return true end end return false end -- NPC是否弹出对话框 function Nobility_Model.GetCanNobility() local teamLevel = MDL.Player.GetRoleLevel() for k,v in DataSheetManager.Nobility:GetEnumerator() do if teamLevel == v.TeamLevelMax and private.currentStage == 3 then return true end end return false end function Nobility_Model.GetStage3RedPoint() local subjugateDataId = Nobility_Model.GetStage3Config().SubjugateDataPVE local SubjugateColorType = CTL.LevelSelect.GetSubjugateColorType(subjugateDataId) return SubjugateColorType == 5 or SubjugateColorType == 6 end ---真实等级转换成等级和爵位 ---@param teamLevel 战队真实等级 ---@return level 显示等级 ---@return rank 爵位等级 function Nobility_Model.GetLevelAndNobility(teamLevel) if teamLevel <= DataSheetManager.Nobility:GetDataByRankID(1).TeamLevelMax then return teamLevel, 1 end for k, v in DataSheetManager.Nobility:GetEnumerator() do if v.TeamLevelMax == -1 or v.TeamLevelMax >= teamLevel then local level = teamLevel - DataSheetManager.Nobility:GetDataByRankID(k - 1).TeamLevelMax return level, k end end end --endregion 数据获取 --region -- **************** 数据操作 ******************* -- function private.SetNobilityInfo(info) if info then private.currentNobilityID = info.RankId private.currentStage = info.Stage private.currentStageParams = info.StageParams end end function private.RefreshTownHomeBtnRedPoint() EventSystem.Dispatch(CTL.RedPoint.RedPointKey.Nobility, Nobility_Model.GetRedPoint()) end --endregion 数据操作 --region -- **************** 协议部分 ******************* function Nobility_Model.EnterWorldSyncNobilityInfo(msgResp) --logging.log(LTAG.LOG, "EnterWorldSyncNobilityInfo", msgResp) private.SetNobilityInfo(msgResp) EventSystem.Dispatch(CTL.RedPoint.RedPointKey.Nobility, Nobility_Model.GetRedPoint()) end function Nobility_Model.PlayerChangeSyncNobilityInfo(isRedPoint) --logging.log(LTAG.LOG, "PlayerChangeSyncNobilityInfo", isRedPoint) EventSystem.Dispatch(CTL.RedPoint.RedPointKey.Nobility, isRedPoint) private.playerChangeSyncRedPoint = isRedPoint end -- 界面信息 function Nobility_Model.NobilityGetUIInfoRequest() local msg = role_nobility_pb.NobilityGetUIInfoReq() NetManager.SendMessage(MessageEnums.MessageNobilityGetUIInfo, msg) end function private.NobilityGetUIInfoResponse(msgResp) --logging.log(LTAG.LOG, "NobilityGetUIInfoResponse", msgResp.Info) if msgResp.Info then private.SetNobilityInfo(msgResp.Info) private.nobilityID = msgResp.Info.RankId EventSystem.Dispatch(EventID.UI_Nobility_RefreshPanel) EventSystem.Dispatch(CTL.RedPoint.RedPointKey.Nobility, Nobility_Model.GetRedPoint()) end end -- 爵位阶段激活|晋升 function Nobility_Model.NobilityStageUpRequest(stageID) local msg = role_nobility_pb.NobilityStageUpReq() msg.Stage = stageID NetManager.SendMessage(MessageEnums.MessageNobilityStageUp, msg) end function private.NobilityStageUpResponse(msgResp) --logging.log(LTAG.LOG, "NobilityStageUpResponse", msgResp.Info) if msgResp.Info then private.SetNobilityInfo(msgResp.Info) if msgResp.Info.Stage == 1 then EventSystem.Dispatch(EventID.UI_Nobility_RefreshStageUp) UIManager.OpenView(Const_UI_Lua.UIEnum.UIHeroAdvancedTips, {isNobility = true, stage = 0}) elseif msgResp.Info.Stage == 2 then EventSystem.Dispatch(EventID.UI_Nobility_RefreshStageUp) end if private.currentNobilityID > private.nobilityID then UIManager.OpenView(Const_UI_Lua.UIEnum.UIRankPromoteSuccess, {isNobility = true, stage = 3}) end EventSystem.Dispatch(CTL.RedPoint.RedPointKey.Nobility, Nobility_Model.GetRedPoint()) end end -- 爵位二阶段图标激活 function Nobility_Model.NobilitySecondStageActiveRequest(configID) local msg = role_nobility_pb.NobilitySecondStageActiveReq() msg.Id = configID NetManager.SendMessage(MessageEnums.MessageNobilitySecondStageActive, msg) end function private.NobilitySecondStageActiveResponse(msgResp) --logging.log(LTAG.LOG, "NobilitySecondStageActiveResponse", msgResp) if msgResp.Id then table.insert(private.currentStageParams, msgResp.Id) EventSystem.Dispatch(EventID.UI_Nobility_RefreshSecondStageActive) UIManager.OpenView(Const_UI_Lua.UIEnum.UIHeroAdvancedTips, {isNobility = true, stage = 1}) EventSystem.Dispatch(CTL.RedPoint.RedPointKey.Nobility, Nobility_Model.GetRedPoint()) end end -- 爵位-武将晋升 function Nobility_Model.NobilityHeroUpRequest(heroID) local msg = role_nobility_pb.NobilityHeroUpReq() msg.HeroId = heroID NetManager.SendMessage(MessageEnums.MessageNobilityHeroUp, msg) end function private.NobilityHeroUpResponse(msgResp) --logging.log(LTAG.LOG, "NobilityHeroUpResponse", msgResp) end -- 进爵副本 function Nobility_Model.EnterNobilityLevelRequest() if CTL.TeamMatch.IsCanGoOtherScene(LuaConst.LevelType.Nobility) == false then return end local levelId = Nobility_Model.GetStage3Config().LevelID local msg = fuben_pb.EnterFubenReq() msg.id = levelId msg.mapType = LuaConst.LevelType.Nobility --logging.log(LTAG.LOG, "EnterNobilityLevelRequest", msg, MessageEnums.MessageEnterFuben) NetManager.SendMessage(MessageEnums.MessageEnterFuben, msg) end --endregion 协议部分 return Nobility_Model