local AppearanceLibrary_Model = {} local EventSystem = require('Event/EventSystem') local private = {} local pictorial_book = require 'Proto.pictorial_book_pb' function AppearanceLibrary_Model.OnStartup() EventSystem.Regist(EventID.Illustration_AssignUpdateLevelResponse, private.ResponseUpdateLevel) EventSystem.Regist(EventID.UI_Appearance_Refresh, private.SetInfoDirty) EventSystem.Regist(EventID.UI_DyeAppearance_UpdateInfo, private.SetInfoDirty) private.isInit = false private.libraryLevel = 0 private.libraryScore = 0 private.appearanceAttrs = LuaExt.CreateTable(DataSheetManager.AttrData:GetDataCount()) --统计的总属性值 private.levelZeroAttrs = LuaExt.CreateTable(DataSheetManager.AttrData:GetDataCount()) local scoreData = DataSheetManager.CollectorPictorialScore:GetDataByLevelID(1) for _, attrData in ipairs(scoreData.Attr_Table) do private.levelZeroAttrs[attrData.AttrType] = 0 end private.levelScoreAttr = LuaExt.CreateTable(DataSheetManager.CollectorPictorialScore:GetDataCount()) -- 累加统计每个等级的积分属性 for _, v in DataSheetManager.CollectorPictorialScore: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 AppearanceLibrary_Model.OnShutdown() private.appearanceAttrs = nil table.clearArray(private.levelScoreAttr) private.levelScoreAttr = nil private.levelZeroAttrs = nil end --获取神兽等级 function AppearanceLibrary_Model.GetAppearanceLevel(appearanceId) if not appearanceId then return -1 end return MDL.DyeAppearance.GetAppearanceLibraryLevel(appearanceId) end function AppearanceLibrary_Model.GetLibraryLevelAndScore() return private.libraryLevel, private.libraryScore end function AppearanceLibrary_Model.GetUnlockAmount() return MDL.DyeAppearance.GetDyeAppearanceCount() end function AppearanceLibrary_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.appearanceAttrs end function AppearanceLibrary_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.appearanceAttrs[attrType] end function AppearanceLibrary_Model.GetScoreAttrByLevel(libraryLevel, attrType) return private.levelScoreAttr[libraryLevel][attrType] end --可激活或可升级 function AppearanceLibrary_Model.CanUnlockOrUpdate(appearanceId) local libraryLevel = AppearanceLibrary_Model.GetAppearanceLevel(appearanceId) if libraryLevel == -1 then -- 可激活 if MDL.DyeAppearance.GetIsAppearanceActive(appearanceId) then return true end return false else --超过突破等级 local curCfg = DataSheetManager.CollectionAP:GetDataByID(appearanceId) local ok, nextCfg = DataSheetManager.CollectorPictorialType:TryGetDataByCollectorPictorialTypeID_PictorialLevel(curCfg.CollectorPictorial, libraryLevel + 1) if ok then local appearanceCfg = DataSheetManager.HeroAppearance:GetDataByID(appearanceId) local curLevel = MDL.Appearance.GetAppearanceLevel(appearanceCfg.HeroID, appearanceId, MDL.Appearance.AppearanceType.Hero) return curLevel >= nextCfg.StarLevel end end return false end function AppearanceLibrary_Model.IsShowRP() for i, v in DataSheetManager.CollectionAP:GetEnumerator() do if AppearanceLibrary_Model.CanUnlockOrUpdate(v.ID) then return true end end return false end --图鉴信息变化了 function private.SetInfoDirty() private.isInfoDirty = true private.UpdateInfoAfterUpdateLevel() CTL.AppearanceLibrary.CheckRedPoint() end --region -------------------------------------------------- 网络协议同步 ----------------------------------------------------- --enterWorld和升级协议触发的playerChange处理,注意计略系统本身的激活和钻研不会触发这里 function AppearanceLibrary_Model.SetLibraryInfo(libraryInfoArray) if not IsProtoDataNotNil(libraryInfoArray) then return end --获取计略图鉴信息 local libraryInfo = {} for i, v in ipairs(libraryInfoArray) do if v.type == LuaConst.PictorialType.Appearance 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 for i, v in DataSheetManager.CollectionAP:GetEnumerator() do local libraryLevel = AppearanceLibrary_Model.GetAppearanceLevel(v.ID) local isUnlock = libraryLevel >= 0 --累加总属性加成 if isUnlock then local curCfg = DataSheetManager.CollectorPictorialType:GetDataByCollectorPictorialTypeID_PictorialLevel(v.CollectorPictorial, libraryLevel) for i, v in ipairs(curCfg.Attr_Table) do if not private.appearanceAttrs[v.AttrType] then private.appearanceAttrs[v.AttrType] = curCfg.Attr_Table[i].AttrNum else private.appearanceAttrs[v.AttrType] = private.appearanceAttrs[v.AttrType] + curCfg.Attr_Table[i].AttrNum end end else -- 初始化0 local curCfg = DataSheetManager.CollectorPictorialType:GetDataByCollectorPictorialTypeID_PictorialLevel(v.CollectorPictorial, 0) for i, v in ipairs(curCfg.Attr_Table) do if not private.appearanceAttrs[v.AttrType] then private.appearanceAttrs[v.AttrType] = 0 end end end end CTL.AppearanceLibrary.CheckRedPoint() end -- 升级弹出提示 CTL.AppearanceLibrary.ShowLeveUpTipPanel(private.formerLibraryLevel, private.libraryLevel) private.formerLibraryLevel = private.libraryLevel --保存上次图鉴积分等级 EventSystem.Dispatch(EventID.UI_Illustration_AppearanceLibrary_RefreshBase) end --激活/升级后更新图鉴数据 --等升级和playerchange消息都回来以后执行 function private.UpdateInfoAfterUpdateLevel() if private.lastUpdateId == nil then return end if not private.isInfoDirty then return end --更新解锁的数量 local apCfg = DataSheetManager.CollectionAP:GetDataByID(private.lastUpdateId) local heroAppearanceCfg = DataSheetManager.HeroAppearance:GetDataByID(private.lastUpdateId) local libraryLevel = AppearanceLibrary_Model.GetAppearanceLevel(private.lastUpdateId) if libraryLevel == 0 then -- 解锁 CTL.Tips.AddTipsMsg(string.FormatByIdsKey("IDS_CollectionHandbook_Tip11", UIUtils.GetLocalizedTxt(Const_IDS[heroAppearanceCfg.AppearanceName]))) else CTL.Tips.AddTipsMsg(string.FormatByIdsKey("IDS_CollectionHandbook_Tip12", UIUtils.GetLocalizedTxt(Const_IDS[heroAppearanceCfg.AppearanceName]))) end --更新属性 local curCfg = DataSheetManager.CollectorPictorialType:GetDataByCollectorPictorialTypeID_PictorialLevel(apCfg.CollectorPictorial, libraryLevel) for i, v in ipairs(curCfg.Attr_Table) do if not private.appearanceAttrs[v.AttrType] then private.appearanceAttrs[v.AttrType] = curCfg.Attr_Table[i].AttrNum else private.appearanceAttrs[v.AttrType] = private.appearanceAttrs[v.AttrType] + curCfg.Attr_Table[i].AttrNum end end if libraryLevel >= 1 then local formerCfg = DataSheetManager.CollectorPictorialType:GetDataByCollectorPictorialTypeID_PictorialLevel(apCfg.CollectorPictorial, libraryLevel - 1) for i, v in ipairs(formerCfg.Attr_Table) do if private.appearanceAttrs[v.AttrType] then private.appearanceAttrs[v.AttrType] = private.appearanceAttrs[v.AttrType] - formerCfg.Attr_Table[i].AttrNum end end end EventSystem.Dispatch(EventID.UI_Illustration_AppearanceLibrary_RefreshBase) EventSystem.Dispatch(EventID.UI_Illustration_AppearanceLibrary_RefreshPopUp, true) CTL.AppearanceLibrary.CheckRedPoint() private.lastUpdateId = nil private.isInfoDirty = false end --- 更新request function AppearanceLibrary_Model.RequestUpdateLevel(appearanceId) private.isInfoDirty = false private.formerLibraryLevel = private.libraryLevel --保存上次图鉴积分等级 local msg = NetManager.GetPB("pictorial_book").PictorialLevelUpReq() msg.id = appearanceId msg.type = LuaConst.PictorialType.Appearance NetManager.SendMessage(MessageEnums.MessagePictorialLevelUp, msg) end function private.ResponseUpdateLevel(msgResp) if msgResp.Resp.Code ~= 0 then return end if msgResp.type ~= LuaConst.PictorialType.Appearance then return end private.lastUpdateId = msgResp.id private.UpdateInfoAfterUpdateLevel() end --endregion return AppearanceLibrary_Model