local StratagemLibrary_Model = {} local private = {} local EventSystem = require('Event/EventSystem') local pictorial_book = require 'Proto.pictorial_book_pb' function StratagemLibrary_Model.OnStartup() EventSystem.Regist(EventID.Illustration_AssignUpdateLevelResponse, private.ResponseUpdateLevel) EventSystem.Regist(EventID.UI_Illustration_OneKeyUpLevel, private.OnOneKeyUpLevel) private.isInit = false private.libraryLevel = 0 private.libraryScore = 0 local scoreCfg = DataSheetManager.StratagemPictorialScore local attrCfg = DataSheetManager.AttrData private.attrs = LuaExt.CreateTable(attrCfg:GetDataCount()) --统计的总属性值 private.levelZeroAttrs = LuaExt.CreateTable(attrCfg:GetDataCount()) local scoreData = scoreCfg:GetDataByLevelID(1) for _, attrData in ipairs(scoreData.Attr_Table) do private.levelZeroAttrs[attrData.AttrType] = 0 end private.levelScoreAttr = LuaExt.CreateTable(scoreCfg:GetDataCount()) -- 累加统计每个等级的积分属性 for _, v in scoreCfg:GetEnumerator() do local attrs = LuaExt.CreateTable(attrCfg:GetDataCount()) local formerAttrs = private.levelScoreAttr[v.LevelID - 1] if formerAttrs then for attrType, attrNum in pairs(formerAttrs) do if not attrs[attrType] then attrs[attrType] = attrNum else attrs[attrType] = attrs[attrType] + attrNum end end end for _, attrData in ipairs(v.Attr_Table) do if not attrs[attrData.AttrType] then attrs[attrData.AttrType] = attrData.AttrNum else attrs[attrData.AttrType] = attrs[attrData.AttrType] + attrData.AttrNum end end table.insert(private.levelScoreAttr, attrs) end end function private.OnOneKeyUpLevel(type) if type == LuaConst.PictorialType.Stratagem then private.attrs = LuaExt.CreateTable(DataSheetManager.AttrData:GetDataCount()) private.CalcuAttrs() CTL.StratagemLibrary.CheckRedPoint() end end function StratagemLibrary_Model.OnShutdown() private.attrs = nil table.clearArray(private.levelScoreAttr) private.levelScoreAttr = nil private.levelZeroAttrs = nil end --region 协议处理 --enterWorld和升级协议触发的playerChange处理,注意计略系统本身的激活和钻研不会触发这里 function StratagemLibrary_Model.SetLibraryInfo(libraryInfoArray, stratagemPictorialInfo) if not IsServerDataNotNil(libraryInfoArray) then return end --获取计略图鉴信息 local libraryInfo = {} for i, v in ipairs(libraryInfoArray) do if v.type == LuaConst.PictorialType.Stratagem then libraryInfo = v break end end if IsServerDataNotNil(libraryInfo) then private.libraryLevel = libraryInfo.level private.libraryScore = libraryInfo.score end if IsServerDataNotNil(stratagemPictorialInfo) then --playerChange会更新下 for _, v in ipairs(stratagemPictorialInfo) do MDL.Stratagem.SyncPictorialLevelInfo(v.StratagemID,v.pictorialLevel) end end -- 升级弹出提示 CTL.StratagemLibrary.ShowLeveUpTipPanel(private.formerLibraryLevel, private.libraryLevel) private.formerLibraryLevel = private.libraryLevel --保存上次图鉴积分等级 EventSystem.Dispatch(EventID.UI_Illustration_Stratagem_RefreshBase) end function private.CalcuAttrs() local list = MDL.Stratagem.GetSortList() for _, t in ipairs(list) do local libraryLevel = MDL.Stratagem.GetPictorialLevel(t.ID) local isUnlock = libraryLevel > 0 --累加总属性加成 if isUnlock then local curCfg = DataSheetManager.StratagemPictorialType:GetDataByStratagemPictorialTypeID_PictorialLevel(t.PictorialID, libraryLevel) for i, v in ipairs(curCfg.Attr_Table) do if not private.attrs[v.AttrType] then private.attrs[v.AttrType] = curCfg.Attr_Table[i].AttrNum else private.attrs[v.AttrType] = private.attrs[v.AttrType] + curCfg.Attr_Table[i].AttrNum end end else -- 初始化1 local curCfg = DataSheetManager.StratagemPictorialType:GetDataByStratagemPictorialTypeID_PictorialLevel(t.PictorialID, 1) for i, v in ipairs(curCfg.Attr_Table) do if not private.attrs[v.AttrType] then private.attrs[v.AttrType] = 0 end end end end end function StratagemLibrary_Model.Init() if not private.isInit then private.isInit = true private.CalcuAttrs() CTL.StratagemLibrary.CheckRedPoint() end end function StratagemLibrary_Model.RequestUpdateLevel(id) private.formerLibraryLevel = private.libraryLevel --保存上次图鉴积分等级 local msg = pictorial_book.PictorialLevelUpReq() msg.id = id msg.type = LuaConst.PictorialType.Stratagem NetManager.SendMessage(MessageEnums.MessagePictorialLevelUp, msg) end --升级协议消息.时机晚于上面的playerChange function private.ResponseUpdateLevel(msgResp) if msgResp.Resp.Code ~= 0 then return end if msgResp.type ~= LuaConst.PictorialType.Stratagem then return end private.UpdateInfoAfterUpdateLevel(msgResp.id) end --图鉴升级,或计略的激活、钻研会刷。跟其他图鉴系统不太一样 function private.UpdateInfoAfterUpdateLevel(id) --更新解锁的数量 local cfgData = DataSheetManager.StratagemData:GetDataByID(id) local libraryLevel = MDL.Stratagem.GetPictorialLevel(id) if libraryLevel == 1 then -- 解锁 CTL.Tips.AddTipsMsg(string.FormatByIdsKey("IDS_Handbook_Stratagem_Activate_Tips", UIUtils.GetLocalizedTxt(Const_IDS[cfgData.StratagemName]))) else CTL.Tips.AddTipsMsg(string.FormatByIdsKey("IDS_Handbook_Stratagem_LevelUp_Tips", UIUtils.GetLocalizedTxt(Const_IDS[cfgData.StratagemName]))) end --更新属性 local curCfg = DataSheetManager.StratagemPictorialType:GetDataByStratagemPictorialTypeID_PictorialLevel(cfgData.PictorialID, libraryLevel) for i, v in ipairs(curCfg.Attr_Table) do if not private.attrs[v.AttrType] then private.attrs[v.AttrType] = curCfg.Attr_Table[i].AttrNum else private.attrs[v.AttrType] = private.attrs[v.AttrType] + curCfg.Attr_Table[i].AttrNum end end if libraryLevel > 1 then local formerCfg = DataSheetManager.StratagemPictorialType:GetDataByStratagemPictorialTypeID_PictorialLevel(cfgData.PictorialID, libraryLevel - 1) for i, v in ipairs(formerCfg.Attr_Table) do if private.attrs[v.AttrType] then private.attrs[v.AttrType] = private.attrs[v.AttrType] - formerCfg.Attr_Table[i].AttrNum end end end EventSystem.Dispatch(EventID.UI_Illustration_Stratagem_RefreshBase) EventSystem.Dispatch(EventID.UI_Illustration_Stratagem_RefreshPopUp, true) CTL.StratagemLibrary.CheckRedPoint() end --endregion function StratagemLibrary_Model.GetLibraryLevelAndScore() return private.libraryLevel, private.libraryScore end function StratagemLibrary_Model.IsShowRP() local list = MDL.Stratagem.GetSortList() for _, v in ipairs(list) do if StratagemLibrary_Model.CanUnlockOrUpdate(v.ID) then return true end end return false end function StratagemLibrary_Model.GetAttrs(isGetScore) if isGetScore then if not private.levelScoreAttr[private.libraryLevel] then return private.levelZeroAttrs end return private.levelScoreAttr[private.libraryLevel] end return private.attrs end function StratagemLibrary_Model.GetAttrValue(attrType, isGetScore) if isGetScore then if not private.levelScoreAttr[private.libraryLevel] then return private.levelZeroAttrs[attrType] end return private.levelScoreAttr[private.libraryLevel][attrType] end return private.attrs[attrType] end function StratagemLibrary_Model.GetScoreAttrByLevel(libraryLevel, attrType) return private.levelScoreAttr[libraryLevel][attrType] end --可激活或可升级 function StratagemLibrary_Model.CanUnlockOrUpdate(id) local libraryLevel = MDL.Stratagem.GetPictorialLevel(id) local info = MDL.Stratagem.GetStratagemInfo(id) if libraryLevel < 1 then -- 可激活判断 if info then return true end return false else --可升级判断 local cfg = DataSheetManager.StratagemData:GetDataByID(id) local isSuccess, nextCfg = DataSheetManager.StratagemPictorialType:TryGetDataByStratagemPictorialTypeID_PictorialLevel(cfg.PictorialID, libraryLevel + 1) if isSuccess then --图鉴还有下一级可升 local curLearnLevel = info.Learn.CurrLvID local pointId = info.Learn.CurrPointID local maxPointCount = DataSheetManager.StratagemLearn:GetDataLengthByID_LevelID_PointId(id, curLearnLevel) if pointId >= maxPointCount then curLearnLevel = curLearnLevel +1 --非最大等级,满点算作加一级 end return curLearnLevel >= nextCfg.StarLevel end end return false end return StratagemLibrary_Model