local DyeLibrary_Model = {} local private = {} local EventSystem = require('Event/EventSystem') local pictorial_book = require 'Proto.pictorial_book_pb' --region---------------------------------- 系统函数 ------------------------------------------ function DyeLibrary_Model.OnStartup() EventSystem.Regist(EventID.Illustration_AssignUpdateLevelResponse, private.ResponseUpdateLevel) EventSystem.Regist(EventID.UI_DyeAppearance_UpdateInfo, private.SetInfoDirty) EventSystem.Regist(EventID.AcquireSystemRedAfterUnlock, private.CalAttrs) EventSystem.Regist(EventID.UI_Illustration_OneKeyUpLevel, private.OnOneKeyUpLevel) private.libraryLevel = 0 private.libraryScore = 0 private.levelZeroAttrs = LuaExt.CreateTable(DataSheetManager.AttrData:GetDataCount()) local scoreData = DataSheetManager.PhantomPictorialScore:GetDataByLevelID(1) for _, attrData in ipairs(scoreData.Attr_Table) do private.levelZeroAttrs[attrData.AttrType] = 0 end private.levelScoreAttr = LuaExt.CreateTable(DataSheetManager.PhantomPictorialScore:GetDataCount()) -- 累加统计每个等级的积分属性 for _, v in DataSheetManager.PhantomPictorialScore: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 DyeLibrary_Model.OnShutdown() private.dyeAttrs = nil table.clearArray(private.levelScoreAttr) private.levelScoreAttr = nil private.levelZeroAttrs = nil end --endregion---------------------------------------------------------------------------------- --region 协议处理 function DyeLibrary_Model.SetLibraryInfo(libraryInfoArray) if not IsServerDataNotNil(libraryInfoArray) then return end local libraryInfo = {} for i, v in ipairs(libraryInfoArray) do if v.type == LuaConst.PictorialType.Dye then libraryInfo = v break end end if IsServerDataNotNil(libraryInfo) then private.libraryLevel = libraryInfo.level private.libraryScore = libraryInfo.score end -- 升级弹出提示 CTL.DyeLibrary.ShowLeveUpTipPanel(private.formerLibraryLevel, private.libraryLevel) private.formerLibraryLevel = private.libraryLevel --保存上次图鉴积分等级 EventSystem.Dispatch(EventID.UI_Illustration_DyeLibrary_RefreshBase) end function DyeLibrary_Model.RequestUpdateLevel(suitId) private.isInfoDirty = false private.formerLibraryLevel = private.libraryLevel --保存上次图鉴积分等级 local msg = NetManager.GetPB("pictorial_book").PictorialLevelUpReq() msg.id = suitId msg.type = LuaConst.PictorialType.Dye NetManager.SendMessage(MessageEnums.MessagePictorialLevelUp, msg) end function private.ResponseUpdateLevel(msgResp) if msgResp.Resp.Code ~= 0 then return end if msgResp.type ~= LuaConst.PictorialType.Dye then return end private.lastUpdateId = msgResp.id --套装id private.UpdateInfoAfterUpdateLevel() end --图鉴信息变化了 function private.SetInfoDirty() private.isInfoDirty = true private.UpdateInfoAfterUpdateLevel() CTL.DyeLibrary.CheckRedPoint() end --激活/升级后更新图鉴数据 --等升级和playerchange消息都回来以后执行 function private.UpdateInfoAfterUpdateLevel() if private.lastUpdateId == nil then return end if not private.isInfoDirty then return end --更新解锁的数量 local suitCfg = DataSheetManager.CollectionAPSuit:GetDataByID(private.lastUpdateId) local apCfg = DataSheetManager.CollectionAP:GetDataByID(suitCfg.ApperanceID) local libraryLevel = DyeLibrary_Model.GetDyeLevel(suitCfg.ApperanceID) CTL.Tips.AddTipsMsg(string.FormatByIdsKey("IDS_CollectionHandbook_Tip21", UIUtils.GetLocalizedTxt(Const_IDS[suitCfg.Name]))) --更新属性 local curCfg = DataSheetManager.PhantomPictorialType:GetDataByPhantomPictorialTypeID_PictorialLevel(apCfg.PhantomPictorial, libraryLevel) for i, v in ipairs(curCfg.Attr_Table) do if not private.dyeAttrs[v.AttrType] then private.dyeAttrs[v.AttrType] = curCfg.Attr_Table[i].AttrNum else private.dyeAttrs[v.AttrType] = private.dyeAttrs[v.AttrType] + curCfg.Attr_Table[i].AttrNum end end if libraryLevel >= 2 then local formerCfg = DataSheetManager.PhantomPictorialType:GetDataByPhantomPictorialTypeID_PictorialLevel(apCfg.PhantomPictorial, libraryLevel - 1) for i, v in ipairs(formerCfg.Attr_Table) do if private.dyeAttrs[v.AttrType] then private.dyeAttrs[v.AttrType] = private.dyeAttrs[v.AttrType] - formerCfg.Attr_Table[i].AttrNum end end end EventSystem.Dispatch(EventID.UI_Illustration_DyeLibrary_RefreshBase) EventSystem.Dispatch(EventID.UI_Illustration_DyeLibrary_RefreshPopUp, true) CTL.DyeLibrary.CheckRedPoint() private.lastUpdateId = nil private.isInfoDirty = false end --endregion function DyeLibrary_Model.GetLibraryLevelAndScore() return private.libraryLevel, private.libraryScore end function DyeLibrary_Model.GetUnlockAmount() local count, sumCount = 0, 0 for i, v in DataSheetManager.CollectionAP:GetEnumerator() do count = count + MDL.DyeAppearance.GetDyeLibraryLevel(v.ID) end for i, suitCfg in DataSheetManager.CollectionAPSuit:GetEnumerator() do if suitCfg.Quality < CTL.DyeAppearance.SuitQuality_Middle then sumCount = sumCount + 1 end end return count, sumCount end function DyeLibrary_Model.IsShowRP() for i, v in DataSheetManager.CollectionAP:GetEnumerator() do if DyeLibrary_Model.IsCanUpdate(v.ID) then return true end end return false end function DyeLibrary_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.dyeAttrs end function DyeLibrary_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.dyeAttrs[attrType] end function DyeLibrary_Model.GetScoreAttrByLevel(libraryLevel, attrType) return private.levelScoreAttr[libraryLevel][attrType] end function DyeLibrary_Model.GetDyeLevel(appearanceId) return MDL.DyeAppearance.GetDyeLibraryLevel(appearanceId) end --可激活或可升级 function DyeLibrary_Model.IsCanUpdate(appearanceId) local suitList = DataSheetManager.CollectionAP:GetDataByID(appearanceId).SuitList for _, v in ipairs(suitList) do if DyeLibrary_Model.IsSuitCanUpdate(v) then return true end end return false end function DyeLibrary_Model.IsSuitCanUpdate(suitId) local suitCfg = DataSheetManager.CollectionAPSuit:GetDataByID(suitId) if suitCfg.Quality >= CTL.DyeAppearance.SuitQuality_Middle then return false end if MDL.DyeAppearance.IsSuitActiveInDyeLibrary(suitCfg.ApperanceID, suitId) == false then local _, isAll = CTL.DyeAppearance.GetSuitActiveCount(suitId) if isAll then return true end end return false end function private.OnOneKeyUpLevel() private.CalAttrs() EventSystem.Dispatch(EventID.UI_Illustration_DyeLibrary_RefreshBase) end function private.CalAttrs() private.dyeAttrs = LuaExt.CreateTable(DataSheetManager.AttrData:GetDataCount()) --统计的总属性值 for i, apCfg in DataSheetManager.CollectionAP:GetEnumerator() do local libraryLevel = DyeLibrary_Model.GetDyeLevel(apCfg.ID) local isUnlock = libraryLevel > 0 --累加总属性加成 if isUnlock then local curCfg = DataSheetManager.PhantomPictorialType:GetDataByPhantomPictorialTypeID_PictorialLevel(apCfg.PhantomPictorial, libraryLevel) for i, v in ipairs(curCfg.Attr_Table) do if not private.dyeAttrs[v.AttrType] then private.dyeAttrs[v.AttrType] = curCfg.Attr_Table[i].AttrNum else private.dyeAttrs[v.AttrType] = private.dyeAttrs[v.AttrType] + curCfg.Attr_Table[i].AttrNum end end else -- 初始化0 local curCfg = DataSheetManager.PhantomPictorialType:GetDataByPhantomPictorialTypeID_PictorialLevel(apCfg.PhantomPictorial, 1) for i, v in ipairs(curCfg.Attr_Table) do if not private.dyeAttrs[v.AttrType] then private.dyeAttrs[v.AttrType] = 0 end end end end CTL.DyeLibrary.CheckRedPoint() end return DyeLibrary_Model