local GodBeastLibrary_Model = {} local EventSystem = require('Event/EventSystem') local private = {} local pictorial_book = require 'Proto.pictorial_book_pb' function GodBeastLibrary_Model.OnStartup() EventSystem.Regist(EventID.Illustration_AssignUpdateLevelResponse, private.ResponseUpdateLevel) EventSystem.Regist(EventID.GodBeast_Pictorial_Update, private.SetInfoDirty) EventSystem.Regist(EventID.UI_Illustration_OneKeyUpLevel, private.OnOneKeyUpLevel) private.isInit = false private.libraryLevel = 0 private.libraryScore = 0 private.unlockBeastCount = 0 private.godBeastAttrs = LuaExt.CreateTable(DataSheetManager.AttrData:GetDataCount()) --统计的总属性值 private.levelZeroAttrs = LuaExt.CreateTable(DataSheetManager.AttrData:GetDataCount()) local scoreData = DataSheetManager.GodBeastPictorialScore:GetDataByLevelID(1) for _, attrData in ipairs(scoreData.Attr_Table) do private.levelZeroAttrs[attrData.AttrType] = 0 end private.levelScoreAttr = LuaExt.CreateTable(DataSheetManager.GodBeastPictorialScore:GetDataCount()) -- 累加统计每个等级的积分属性 for _, v in DataSheetManager.GodBeastPictorialScore:GetEnumerator() do local attrs = LuaExt.CreateTable(DataSheetManager.AttrData: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 GodBeastLibrary_Model.OnShutdown() private.godBeastAttrs = nil table.clearArray(private.levelScoreAttr) private.levelScoreAttr = nil private.levelZeroAttrs = nil end --获取神兽等级 function GodBeastLibrary_Model.GetGodBeastLevel(godBeastID) if not godBeastID then return -1 end local beastInfo = MDL.GodBeast.GetGodBeastInfoByID(godBeastID) if not beastInfo then return -1 end return beastInfo.pictorialLevel end function GodBeastLibrary_Model.GetLibraryLevelAndScore() return private.libraryLevel, private.libraryScore end function GodBeastLibrary_Model.GetUnlockAndAmountTreasureCount() local sortedList = MDL.GodBeast.GetSortedList() return private.unlockBeastCount, #sortedList end function GodBeastLibrary_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.godBeastAttrs end function GodBeastLibrary_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.godBeastAttrs[attrType] end function GodBeastLibrary_Model.GetScoreAttrByLevel(libraryLevel, attrType) return private.levelScoreAttr[libraryLevel][attrType] end --可激活或可升级 function GodBeastLibrary_Model.CanUnlockOrUpdate(godBeastID) local libraryLevel = GodBeastLibrary_Model.GetGodBeastLevel(godBeastID) if libraryLevel == -1 then -- 可激活 local beastInfo = MDL.GodBeast.GetGodBeastInfoByID(godBeastID) if beastInfo then return true end return false else --超过突破等级 local curCfg = DataSheetManager.GodBeastData:GetDataByID(godBeastID) local ok, nextCfg = DataSheetManager.GodBeastPictorialType:TryGetDataByGodBeastPictorialTypeID_PictorialLevel(curCfg.PictorialID, libraryLevel + 1) if ok then local beastInfo = MDL.GodBeast.GetGodBeastInfoByID(godBeastID) return beastInfo.starLevel >= nextCfg.StarLevel end end return false end function GodBeastLibrary_Model.IsShowRP() local list = MDL.GodBeast.GetSortedList() for _, v in ipairs(list) do if GodBeastLibrary_Model.CanUnlockOrUpdate(v.ID) then return true end end return false end --图鉴信息变化了 function private.SetInfoDirty() private.isInfoDirty = true private.UpdateInfoAfterUpdateLevel() CTL.GodBeastLibrary.CheckRedPoint() end function private.OnOneKeyUpLevel(type) if type == LuaConst.PictorialType.GodBeast then private.unlockBeastCount = 0 private.godBeastAttrs = LuaExt.CreateTable(DataSheetManager.AttrData:GetDataCount()) private.CalcuAttrs() EventSystem.Dispatch(EventID.UI_Illustration_GodBeast_RefreshBase) end end --region -------------------------------------------------- 网络协议同步 ----------------------------------------------------- --enterWorld和升级协议触发的playerChange处理,注意计略系统本身的激活和钻研不会触发这里 function GodBeastLibrary_Model.SetLibraryInfo(libraryInfoArray) if not IsProtoDataNotNil(libraryInfoArray) then return end --获取计略图鉴信息 local libraryInfo = {} for i, v in ipairs(libraryInfoArray) do if v.type == LuaConst.PictorialType.GodBeast then libraryInfo = v break end end if IsProtoDataNotNil(libraryInfo) then private.libraryLevel = libraryInfo.level private.libraryScore = libraryInfo.score end -- 初始化 if not private.isInit then private.isInit = true private.CalcuAttrs() CTL.GodBeastLibrary.CheckRedPoint() end -- 升级弹出提示 CTL.GodBeastLibrary.ShowLeveUpTipPanel(private.formerLibraryLevel, private.libraryLevel) private.formerLibraryLevel = private.libraryLevel --保存上次图鉴积分等级 EventSystem.Dispatch(EventID.UI_Illustration_GodBeast_RefreshBase) end function private.CalcuAttrs() local list = MDL.GodBeast.GetSortedList() for _, t in ipairs(list) do local libraryLevel = GodBeastLibrary_Model.GetGodBeastLevel(t.ID) local isUnlock = libraryLevel >= 0 private.unlockBeastCount = isUnlock and private.unlockBeastCount + 1 or private.unlockBeastCount --累加总属性加成 if isUnlock then local curCfg = DataSheetManager.GodBeastPictorialType:GetDataByGodBeastPictorialTypeID_PictorialLevel(t.PictorialID, libraryLevel) for i, v in ipairs(curCfg.Attr_Table) do if not private.godBeastAttrs[v.AttrType] then private.godBeastAttrs[v.AttrType] = curCfg.Attr_Table[i].AttrNum else private.godBeastAttrs[v.AttrType] = private.godBeastAttrs[v.AttrType] + curCfg.Attr_Table[i].AttrNum end end else -- 初始化0 local curCfg = DataSheetManager.GodBeastPictorialType:GetDataByGodBeastPictorialTypeID_PictorialLevel(t.PictorialID, 0) for i, v in ipairs(curCfg.Attr_Table) do if not private.godBeastAttrs[v.AttrType] then private.godBeastAttrs[v.AttrType] = 0 end end end end end --激活/升级后更新图鉴数据 --等升级和playerchange消息都回来以后执行 function private.UpdateInfoAfterUpdateLevel() if private.lastUpdateId == nil then return end if not private.isInfoDirty then return end --更新解锁的数量 local godBeastCfgData = DataSheetManager.GodBeastData:GetDataByID(private.lastUpdateId) local libraryLevel = GodBeastLibrary_Model.GetGodBeastLevel(private.lastUpdateId) if libraryLevel == 0 then -- 解锁 private.unlockBeastCount = private.unlockBeastCount + 1 CTL.Tips.AddTipsMsg(string.FormatByIdsKey("IDS_Handbook_GodBeast_Activate_Tips", UIUtils.GetLocalizedTxt(Const_IDS[godBeastCfgData.GodBeastName]))) else CTL.Tips.AddTipsMsg(string.FormatByIdsKey("IDS_Handbook_GodBeast_LevelUp_Tips", UIUtils.GetLocalizedTxt(Const_IDS[godBeastCfgData.GodBeastName]))) end --更新属性 local curCfg = DataSheetManager.GodBeastPictorialType:GetDataByGodBeastPictorialTypeID_PictorialLevel(godBeastCfgData.PictorialID, libraryLevel) for i, v in ipairs(curCfg.Attr_Table) do if not private.godBeastAttrs[v.AttrType] then private.godBeastAttrs[v.AttrType] = curCfg.Attr_Table[i].AttrNum else private.godBeastAttrs[v.AttrType] = private.godBeastAttrs[v.AttrType] + curCfg.Attr_Table[i].AttrNum end end if libraryLevel >= 1 then local formerCfg = DataSheetManager.GodBeastPictorialType:GetDataByGodBeastPictorialTypeID_PictorialLevel(godBeastCfgData.PictorialID, libraryLevel - 1) for i, v in ipairs(formerCfg.Attr_Table) do if private.godBeastAttrs[v.AttrType] then private.godBeastAttrs[v.AttrType] = private.godBeastAttrs[v.AttrType] - formerCfg.Attr_Table[i].AttrNum end end end EventSystem.Dispatch(EventID.UI_Illustration_GodBeast_RefreshBase) EventSystem.Dispatch(EventID.UI_Illustration_GodBeastLibrary_RefreshPopUp, true) CTL.GodBeastLibrary.CheckRedPoint() private.lastUpdateId = nil private.isInfoDirty = false end --- 更新request function GodBeastLibrary_Model.RequestUpdateLevel(godBeastID) private.isInfoDirty = false private.formerLibraryLevel = private.libraryLevel --保存上次图鉴积分等级 local msg = pictorial_book.PictorialLevelUpReq() msg.id = godBeastID msg.type = LuaConst.PictorialType.GodBeast NetManager.SendMessage(MessageEnums.MessagePictorialLevelUp, msg) end function private.ResponseUpdateLevel(msgResp) if msgResp.Resp.Code ~= 0 then return end if msgResp.type ~= LuaConst.PictorialType.GodBeast then return end private.lastUpdateId = msgResp.id private.UpdateInfoAfterUpdateLevel() end --endregion return GodBeastLibrary_Model