local EffectLibrary_Model = {} local EventSystem = require("Event/EventSystem") local private = {} local pictorial_book = require 'Proto.pictorial_book_pb' local private = {} EffectLibrary_Model.PictorialType = { SingleEffect = 1, -- 环绕或脚底 Suit = 2, -- 套装 Decoration = 3, -- 装扮 } EffectLibrary_Model.EffectTabEnum = { Init = -1, Encircle = 0, -- 环绕 FootPrint = 1, -- 脚底 Suit = 2, -- 套装 Decoration = 3, --装扮 } function EffectLibrary_Model.OnStartup() EventSystem.Regist(EventID.Illustration_AssignUpdateLevelResponse, private.ResponseUpdateLevel) EventSystem.Regist(EventID.UI_LightEffect_ResetLightEffect, private.CalEffectAttr) EventSystem.Regist(EventID.Effect_Pictorial_Update, private.SetInfoDirty) EventSystem.Regist(EventID.UI_Illustration_OneKeyUpLevel, private.OnOneKeyUpLevel) private.isInit = false private.libraryLevel = 0 private.libraryScore = 0 local scoreCfg = DataSheetManager.LightEffectPictorialScore local attrCfg = DataSheetManager.AttrData 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.LightEffect then private.CalEffectAttr() end end function EffectLibrary_Model.OnShutdown() private.attrs = nil table.clearArray(private.levelScoreAttr) private.levelScoreAttr = nil private.levelZeroAttrs = nil end function EffectLibrary_Model.IsShowRPByTab(effectTabEnum) if not effectTabEnum then return end local infoList, effectPictorialType if effectTabEnum == EffectLibrary_Model.EffectTabEnum.Encircle then local effectList = MDL.LightEffect.GetLightEffectSortedList() infoList = effectList[MDL.LightEffect.LightEffectType.Encircle] effectPictorialType = EffectLibrary_Model.PictorialType.SingleEffect elseif effectTabEnum == EffectLibrary_Model.EffectTabEnum.FootPrint then local effectList = MDL.LightEffect.GetLightEffectSortedList() infoList = effectList[MDL.LightEffect.LightEffectType.Foot] effectPictorialType = EffectLibrary_Model.PictorialType.SingleEffect elseif effectTabEnum == EffectLibrary_Model.EffectTabEnum.Suit then infoList = MDL.LightEffect.GetLightEffectSuitInfoList() effectPictorialType = EffectLibrary_Model.PictorialType.Suit elseif effectTabEnum == EffectLibrary_Model.EffectTabEnum.Decoration then return CTL.Decoration.HasDecorationThemeCanActive() end for i, v in ipairs(infoList) do if EffectLibrary_Model.CanUnlockOrUpdate(v.ID, effectPictorialType) then return true end end return false end function EffectLibrary_Model.IsShowRP() local effectList = MDL.LightEffect.GetLightEffectSortedList() for _, effectInfo in pairs(effectList) do for i, v in ipairs(effectInfo) do if EffectLibrary_Model.CanUnlockOrUpdate(v.ID, EffectLibrary_Model.PictorialType.SingleEffect) then return true end end end local effectSuitList = MDL.LightEffect.GetLightEffectSuitInfoList() for _, v in ipairs(effectSuitList) do if EffectLibrary_Model.CanUnlockOrUpdate(v.ID, EffectLibrary_Model.PictorialType.Suit) then return true end end -- 主题装扮 if CTL.Decoration.HasDecorationThemeCanActive() then return true end return false end function EffectLibrary_Model.Init() if not private.isInit then private.isInit = true private.CalEffectAttr() end end function private.CalEffectAttr() private.attrs = {} local list = MDL.LightEffect.GetLightEffectSortedList() for type, effectList in ipairs(list) do for i, v in ipairs(effectList) do local libraryLevel = EffectLibrary_Model.GetEffectLevel(v.ID, EffectLibrary_Model.PictorialType.SingleEffect) local isUnlock = libraryLevel > 0 if v.PictorialType ~= 0 then if isUnlock then local curCfg = DataSheetManager.LightEffectPictorialType:GetDataByLightEffectPictorialTypeID_PictorialLevel(v.PictorialType, 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 local curCfg = DataSheetManager.LightEffectPictorialType:GetDataByLightEffectPictorialTypeID_PictorialLevel(v.PictorialType, 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 end -- 套装是另外一个表,需要再算一遍 list = MDL.LightEffect.GetLightEffectSuitInfoList() for _, v in ipairs(list) do local libraryLevel = EffectLibrary_Model.GetEffectLevel(v.ID, EffectLibrary_Model.PictorialType.Suit) local isUnlock = libraryLevel > 0 if isUnlock then local curCfg = DataSheetManager.LightEffectSuitPictorialType:GetDataByLightEffectSuitPictorialTypeID_PictorialLevel(v.PictorialType, 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 local curCfg = DataSheetManager.LightEffectSuitPictorialType:GetDataByLightEffectSuitPictorialTypeID_PictorialLevel(v.PictorialType, 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 --主题装扮 for id, v in pairs(MDL.Decoration.GetActiveDecorationSuitInfoMap()) do local curCfg = DataSheetManager.DecoratePictorialType:GetDataByDecoratePictorialTypeID(id) 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 end end function EffectLibrary_Model.GetLibraryLevelAndScore() return private.libraryLevel, private.libraryScore end function EffectLibrary_Model.GetScoreAttrByLevel(levelID, attrType) return private.levelScoreAttr[levelID][attrType] end function EffectLibrary_Model.CanUnlockOrUpdate(id, effectType) local effectLevel = EffectLibrary_Model.GetEffectLevel(id, effectType) if effectLevel < 1 then --是否可以激活 if effectLevel == 0 then return true else return false end else --是否可以升级 local effectCfg if effectType == EffectLibrary_Model.PictorialType.SingleEffect then effectCfg = DataSheetManager.LightEffect:GetDataByID(id) elseif effectType == EffectLibrary_Model.PictorialType.Suit then effectCfg = DataSheetManager.LightEffectSuit:GetDataByID(id) end local isSuccess, nextLevelCfg = DataSheetManager.LightEffectPictorialType:TryGetDataByLightEffectPictorialTypeID_PictorialLevel(effectCfg.PictorialType, effectLevel + 1) if isSuccess then if effectType == EffectLibrary_Model.PictorialType.SingleEffect then local activateCount = MDL.LightEffect.GetLightEffectActivateCount(id) return activateCount >= nextLevelCfg.StarLevel elseif effectType == EffectLibrary_Model.PictorialType.Suit then local leftActivateCount = MDL.LightEffect.GetLightEffectActivateCount(effectCfg.LightEffectList[1]) local rightActivateCount = MDL.LightEffect.GetLightEffectActivateCount(effectCfg.LightEffectList[2]) if leftActivateCount >= nextLevelCfg.StarLevel and rightActivateCount >= nextLevelCfg.StarLevel then return true end end end return false end end function EffectLibrary_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 EffectLibrary_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 EffectLibrary_Model.SetLibraryInfo(libraryInfoArray) if not IsServerDataNotNil(libraryInfoArray) then return end local libraryInfo = {} for i, v in ipairs(libraryInfoArray) do if v.type == LuaConst.PictorialType.LightEffect then libraryInfo = v break end end if IsServerDataNotNil(libraryInfo) then private.libraryLevel = libraryInfo.level private.libraryScore = libraryInfo.score end -- 弹出升级提示 CTL.EffectLibrary.ShowLevelUpTipPanel(private.formerLibraryLevel, private.libraryLevel) private.formerLibraryLevel = private.libraryLevel EventSystem.Dispatch(EventID.UI_Illustration_LightEffect_RefreshBase) end function EffectLibrary_Model.RequestUpdateLevel(effectId, lightEffectType) private.formerLibraryLevel = private.libraryLevel local msg = pictorial_book.PictorialLevelUpReq() msg.id = effectId msg.type = LuaConst.PictorialType.LightEffect msg.lightEffectType = lightEffectType --光效图鉴专用,设置是否为套装/主題装饰 NetManager.SendMessage(MessageEnums.MessagePictorialLevelUp, msg) end function EffectLibrary_Model.GetEffectLevel(effectId, effectType) if not effectId or not effectType then return -1 end return MDL.LightEffect.GetLightEffectPictorialLevel(effectType, effectId) end function private.ResponseUpdateLevel(msgResp) if msgResp.Resp.Code ~= 0 then return end if msgResp.type ~= LuaConst.PictorialType.LightEffect then return end private.lastUpdateType = msgResp.lightEffectType private.lastUpdateId = msgResp.id private.UpdateInfoAfterUpdateLevel() end function private.UpdateInfoAfterUpdateLevel() if private.lastUpdateId == nil or private.lastUpdateType == nil then return end local libraryLevel local pictorialType if private.lastUpdateType == EffectLibrary_Model.PictorialType.SingleEffect then libraryLevel = EffectLibrary_Model.GetEffectLevel(private.lastUpdateId, private.lastUpdateType) local lightEffectCfgData = DataSheetManager.LightEffect:GetDataByID(private.lastUpdateId) pictorialType = lightEffectCfgData.PictorialType if libraryLevel == 1 then -- 解锁新的光效图鉴 -- TODO IDS更新后再修改为对应光效类型(套装或非套装)的IDS CTL.Tips.AddTipsMsg(UIUtils.GetLocalizedTxt(Const_IDS[lightEffectCfgData.LightEffectName])..UIUtils.GetLocalizedTxt(Const_IDS.IDS_Store_Opt_Activated)) else CTL.Tips.AddTipsMsg(UIUtils.GetLocalizedTxt(Const_IDS[lightEffectCfgData.LightEffectName])..UIUtils.GetLocalizedTxt(Const_IDS.IDS_Appearance_ShengJiChengGong)) end elseif private.lastUpdateType == EffectLibrary_Model.PictorialType.Suit then libraryLevel = EffectLibrary_Model.GetEffectLevel(private.lastUpdateId, private.lastUpdateType) local lightSuitCfgData = DataSheetManager.LightEffectSuit:GetDataByID(private.lastUpdateId) pictorialType = lightSuitCfgData.PictorialType if libraryLevel == 1 then CTL.Tips.AddTipsMsg(UIUtils.GetLocalizedTxt(Const_IDS[lightSuitCfgData.LightEffectSetName]) .. UIUtils.GetLocalizedTxt(Const_IDS.IDS_Store_Opt_Activated)) else CTL.Tips.AddTipsMsg(UIUtils.GetLocalizedTxt(Const_IDS[lightSuitCfgData.LightEffectSetName]) .. UIUtils.GetLocalizedTxt(Const_IDS.IDS_Appearance_ShengJiChengGong)) end elseif private.lastUpdateType == EffectLibrary_Model.PictorialType.Decoration then local decorateSuitSuitCfgData = DataSheetManager.DecorateSuit:GetDataByID(private.lastUpdateId) pictorialType = decorateSuitSuitCfgData.PictorialType CTL.Tips.AddTipsMsg(UIUtils.GetLocalizedTxt(Const_IDS[decorateSuitSuitCfgData.Name]) .. UIUtils.GetLocalizedTxt(Const_IDS.IDS_Store_Opt_Activated)) end -- 更新属性 local curCfg = nil if private.lastUpdateType == EffectLibrary_Model.PictorialType.Suit then curCfg = DataSheetManager.LightEffectSuitPictorialType:GetDataByLightEffectSuitPictorialTypeID_PictorialLevel(pictorialType, libraryLevel) elseif private.lastUpdateType == EffectLibrary_Model.PictorialType.SingleEffect then curCfg = DataSheetManager.LightEffectPictorialType:GetDataByLightEffectPictorialTypeID_PictorialLevel(pictorialType, libraryLevel) elseif private.lastUpdateType == EffectLibrary_Model.PictorialType.Decoration then curCfg = DataSheetManager.DecoratePictorialType:GetDataByDecoratePictorialTypeID(pictorialType) end 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 --local curCfg = DataSheetManager.LightEffectSuitPictorialType:GetDataByLightEffectSuitPictorialTypeID_PictorialLevel(v.PictorialType, libraryLevel) if libraryLevel and libraryLevel > 1 then local formerCfg = DataSheetManager.LightEffectPictorialType:GetDataByLightEffectPictorialTypeID_PictorialLevel(pictorialType, 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_LightEffect_RefreshBase) EventSystem.Dispatch(EventID.UI_Illustration_LightEffect_RefreshPopUp, true) -- TODO 检查红点 CTL.EffectLibrary.CheckRedPoint() end return EffectLibrary_Model