local HorseLibrary_Model = {} local private = {} local EventSystem = require('Event/EventSystem') local pictorial_book = require 'Proto.pictorial_book_pb' --region---------------------------------- 系统函数 ------------------------------------------ function HorseLibrary_Model.OnStartup() EventSystem.Regist(EventID.Illustration_AssignUpdateLevelResponse, private.ResponseUpdateLevel) EventSystem.Regist(EventID.UI_UpdateWarHorseInfo, private.SetInfoDirty) EventSystem.Regist(EventID.UI_Reborn_Recast_RecastSuccess, private.OnRecastSuccess) EventSystem.Regist(EventID.UI_Illustration_OneKeyUpLevel, private.OnOneKeyUpLevel) private.isInit = false private.libraryLevel = 0 private.libraryScore = 0 private.unlockHorseCount = 0 private.levelZeroAttrs = LuaExt.CreateTable(DataSheetManager.AttrData:GetDataCount()) local scoreData = DataSheetManager.HorsePictorialScore:GetDataByLevelID(1) for _, attrData in ipairs (scoreData.Attr_Table) do private.levelZeroAttrs[attrData.AttrType] = 0 end private.levelScoreAttr = LuaExt.CreateTable(DataSheetManager.HorsePictorialScore:GetDataCount()) -- 累加统计每个等级的积分属性 for _, v in DataSheetManager.HorsePictorialScore: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 HorseLibrary_Model.OnShutdown() private.horseAttrs = nil table.clearArray(private.levelScoreAttr) private.levelScoreAttr = nil private.levelZeroAttrs = nil end --endregion---------------------------------------------------------------------------------- --region 协议处理 function HorseLibrary_Model.SetLibraryInfo(libraryInfoArray) if not IsServerDataNotNil(libraryInfoArray) then return end --获取坐骑图鉴信息 local libraryInfo = {} for i,v in ipairs(libraryInfoArray) do if v.type == LuaConst.PictorialType.Horse then libraryInfo = v break end end if IsServerDataNotNil(libraryInfo) then private.libraryLevel = libraryInfo.level private.libraryScore = libraryInfo.score end -- 初始化 if not private.isInit then private.isInit = true private.CalAttrs() end -- 升级弹出提示 CTL.HorseLibrary.ShowLeveUpTipPanel(private.formerLibraryLevel, private.libraryLevel) private.formerLibraryLevel = private.libraryLevel --保存上次图鉴积分等级 EventSystem.Dispatch(EventID.UI_Illustration_HorseLibrary_RefreshBase) end function HorseLibrary_Model.RequestUpdateLevel(horseId) private.isInfoDirty = false private.formerLibraryLevel = private.libraryLevel --保存上次图鉴积分等级 local msg = pictorial_book.PictorialLevelUpReq() msg.id = horseId msg.type = LuaConst.PictorialType.Horse NetManager.SendMessage(MessageEnums.MessagePictorialLevelUp, msg) end function private.ResponseUpdateLevel(msgResp) if msgResp.Resp.Code ~= 0 then return end if msgResp.type ~= LuaConst.PictorialType.Horse then return end private.lastUpdateId = msgResp.id private.UpdateInfoAfterUpdateLevel() end --图鉴信息变化了 function private.SetInfoDirty() private.isInfoDirty = true private.UpdateInfoAfterUpdateLevel() CTL.HorseLibrary.CheckRedPoint() end --激活/升级后更新图鉴数据 --等升级和playerchange消息都回来以后执行 function private.UpdateInfoAfterUpdateLevel() if private.lastUpdateId ==nil then return end if not private.isInfoDirty then return end --更新解锁的数量 local horseCfgData = DataSheetManager.HorseData:GetDataByHorseID(private.lastUpdateId) local libraryLevel = HorseLibrary_Model.GetHorseLevel(private.lastUpdateId) if libraryLevel == 0 then -- 解锁 private.unlockHorseCount = private.unlockHorseCount + 1 CTL.Tips.AddTipsMsg(string.FormatByIdsKey("IDS_Handbook_Horse_Activate_Tips", UIUtils.GetLocalizedTxt(Const_IDS[horseCfgData.HorseName]))) else CTL.Tips.AddTipsMsg(string.FormatByIdsKey("IDS_Handbook_Horse_LevelUp_Tips", UIUtils.GetLocalizedTxt(Const_IDS[horseCfgData.HorseName]))) end --更新属性 local curCfg = DataSheetManager.HorsePictorialType:GetDataByHorsePictorialTypeID_PictorialLevel(horseCfgData.HorsePrictorialType, libraryLevel) for i, v in ipairs (curCfg.Attr_Table) do if not private.horseAttrs[v.AttrType] then private.horseAttrs[v.AttrType] = curCfg.Attr_Table[i].AttrNum else private.horseAttrs[v.AttrType] = private.horseAttrs[v.AttrType] + curCfg.Attr_Table[i].AttrNum end end if libraryLevel >= 1 then local formerCfg = DataSheetManager.HorsePictorialType:GetDataByHorsePictorialTypeID_PictorialLevel(horseCfgData.HorsePrictorialType, libraryLevel - 1) for i, v in ipairs (formerCfg.Attr_Table) do if private.horseAttrs[v.AttrType] then private.horseAttrs[v.AttrType] = private.horseAttrs[v.AttrType] - formerCfg.Attr_Table[i].AttrNum end end end EventSystem.Dispatch(EventID.UI_Illustration_HorseLibrary_RefreshBase) EventSystem.Dispatch(EventID.UI_Illustration_HorseLibrary_RefreshPopUp, true) CTL.HorseLibrary.CheckRedPoint() private.lastUpdateId = nil private.isInfoDirty = false end --endregion function HorseLibrary_Model.GetLibraryLevelAndScore() return private.libraryLevel, private.libraryScore end function HorseLibrary_Model.GetUnlockAndAmountHorseCount() local sortedList = MDL.WarHorse.GetSortedHorseList() return private.unlockHorseCount,#sortedList end function HorseLibrary_Model.IsShowRP() local list = MDL.WarHorse.GetSortedHorseList() for _, v in ipairs (list) do if HorseLibrary_Model.IsHorseCanUpdate(v.HorseID) then return true end end return false end function HorseLibrary_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.horseAttrs end function HorseLibrary_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.horseAttrs[attrType] end function HorseLibrary_Model.GetScoreAttrByLevel(libraryLevel, attrType) return private.levelScoreAttr[libraryLevel][attrType] end --获取坐骑图鉴等级 function HorseLibrary_Model.GetHorseLevel(horseId) if not horseId then return -1 end local horseInfo = MDL.WarHorse.GetInfoByID(horseId) if not horseInfo then return -1 end return horseInfo.HorseInfo.pictorialLevel end --可激活或可升级 function HorseLibrary_Model.IsHorseCanUpdate(horseId) local libraryLevel = HorseLibrary_Model.GetHorseLevel(horseId) if libraryLevel == -1 then -- 可激活 local horseInfo = MDL.WarHorse.GetInfoByID(horseId) if horseInfo then return true end return false else --超过突破等级 local horseCfg = DataSheetManager.HorseData:GetDataByHorseID(horseId) local isSuccess, nextCfg = DataSheetManager.HorsePictorialType:TryGetDataByHorsePictorialTypeID_PictorialLevel(horseCfg.HorsePrictorialType, libraryLevel + 1) if isSuccess then local horseInfo = MDL.WarHorse.GetInfoByID(horseId) return horseInfo.HorseInfo.starLevel >= nextCfg.StarLevel end end return false end function private.OnRecastSuccess(typeId) if typeId == MDL.Reborn.RebornType.Horse then private.CalAttrs() end end function private.OnOneKeyUpLevel(type) if type == LuaConst.PictorialType.Horse then private.unlockHorseCount = 0 private.CalAttrs() EventSystem.Dispatch(EventID.UI_Illustration_HorseLibrary_RefreshBase) end end function private.CalAttrs() private.horseAttrs = LuaExt.CreateTable(DataSheetManager.AttrData:GetDataCount()) --统计的总属性值 local list = MDL.WarHorse.GetSortedHorseList() for _, t in ipairs(list) do local libraryLevel = HorseLibrary_Model.GetHorseLevel(t.HorseID) local isUnlock = libraryLevel >= 0 private.unlockHorseCount = isUnlock and private.unlockHorseCount + 1 or private.unlockHorseCount --累加总属性加成 if isUnlock then local curCfg = DataSheetManager.HorsePictorialType:GetDataByHorsePictorialTypeID_PictorialLevel(t.HorsePrictorialType, libraryLevel) for i, v in ipairs (curCfg.Attr_Table) do if not private.horseAttrs[v.AttrType] then private.horseAttrs[v.AttrType] = curCfg.Attr_Table[i].AttrNum else private.horseAttrs[v.AttrType] = private.horseAttrs[v.AttrType] + curCfg.Attr_Table[i].AttrNum end end else -- 初始化0 local curCfg = DataSheetManager.HorsePictorialType:GetDataByHorsePictorialTypeID_PictorialLevel(t.HorsePrictorialType, 0) for i, v in ipairs (curCfg.Attr_Table) do if not private.horseAttrs[v.AttrType] then private.horseAttrs[v.AttrType] = 0 end end end end CTL.HorseLibrary.CheckRedPoint() end return HorseLibrary_Model