local HorseSoul_Model = {} local private = {} local EventSystem = require('Event/EventSystem') local horse_soul_pb = require "Proto.horse_soul_pb" local draw_horse_soul_pb = require "Proto.draw_horse_soul_pb" local HorseSoulLevelGeneralItem = DataSheetManager.ConstData:GetDataByID("HorseSoulLevelGeneralItem").IntValue local HorseSoulLevelGeneralItemExp = DataSheetManager.ConstData:GetDataByID("HorseSoulLevelGeneralItemExp").IntValue local HorseSoulDailyDrawNum = DataSheetManager.ConstData:GetDataByID("HorseSoulDailyDrawNum").IntValue -- 魂珠抽卡每日限制次数 local HorseSoullargeDrawNum = 100---DataSheetManager.ConstData:GetDataByID("HorseSoullargeDrawNum").IntValue -- 大量抽取按键抽x次 local CostNumShowStr = "x%d" HorseSoul_Model.HorseSoulOptType = { LevelUp = horse_soul_pb.LEVLEUP, Break = horse_soul_pb.BREAK, Star = horse_soul_pb.STAR, } HorseSoul_Model.HorseSoulEquipType = { Equip = horse_soul_pb.Equip, Disboard = horse_soul_pb.Disboard, AutoEquip = horse_soul_pb.AutoEquip, } HorseSoul_Model.HorseSoulWishOpt = { Cancel = draw_horse_soul_pb.Cancel, Wish = draw_horse_soul_pb.Wish, } function HorseSoul_Model.OnStartup() NetManager.RegisterMsgCB(MessageEnums.MessageHorseSoulEquip, private.HorseSoulEquipResp) NetManager.RegisterMsgCB(MessageEnums.MessageHorseSoulOpt, private.HorseSoulOptResp) NetManager.RegisterMsgCB(MessageEnums.MessageGetDrawSoulNumReward, private.GetDrawSoulNumRewardResp) NetManager.RegisterMsgCB(MessageEnums.MessageDrawHorseSoul, private.DrawHorseSoulResp) NetManager.RegisterMsgCB(MessageEnums.MessageSoulDrawWishOpt, private.SoulDrawWishOptResp) EventSystem.Regist(EventID.UI_Illustration_HorseLibrary_RefreshBase, private.RefreshHorsePictorialAdd) --[[private.soulPearlInfoDic[id] = { id, --背包唯一实例Id cfgId, --魂珠道具Id,映射魂珠表和道具表 equipHorseId, --被装备上的马Id soulData, --魂珠表数据 itemData, --道具表数据 levelInfo = {level, curExp, breakLevel}, star, -- 启魂等级 gs, }]]-- private.soulPearlInfoDic = {} private.soulPearlIdList = {} private.soulMaterialIdList = {} --按照魂珠材料的规则排序,这里不做已装备魂珠的筛选 private.soulPearlEquipDic = {} --做预处理,存储套装类型,虽然策划说套装id是连续的,但是为了防止意外,做一步处理 local temp = {} private.soulSuitDataList = {} for i, v in DataSheetManager.HorseSoulSuitData:GetEnumerator() do local suitId = v.HorseSoulSuitID if not temp[suitId] then temp[suitId] = {suitId = suitId, suitName = v.HorseSoulSuitName, skillName = v.HorseSoulSkillName, icon = v.HorseSoulSuitIcon} end end for suitId, suitData in pairs(temp) do table.insert(private.soulSuitDataList, suitData) end table.sort(private.soulSuitDataList, private.SortSuitList) private.DrawHorseSoulInfo = {} -- 魂珠抽卡总数据 private.DrawHorseSoulOpenResetState = 0 -- 是否重置回初始卡池;0不变,1升级,2重置 HorseSoul_Model.RedWishUnLockRedPoint = false -- 红色心愿解锁红点 HorseSoul_Model.GoldWishUnLockRedPoint = false -- 金色心愿解锁红点 HorseSoul_Model.SelectSoulBaseType = 0 -- 当前选择的魂珠养成页签,方便跳回界面找到页签 HorseSoul_Model.SelectSoulBaseSoulPearl = "" -- 养成界面当前选择的魂珠ID,方便跳回界面找到魂珠 end ---不要轻易修改,魂珠中有通用材料道具,可以通过此方法取到空判断 function HorseSoul_Model.GetSoulInfoById(id) return private.soulPearlInfoDic[id] end function HorseSoul_Model.GetSoulSlotInfoByHorseId(horseId) local info = MDL.WarHorse.GetInfoByID(horseId) if info then return info.HorseInfo.soulSlotInfos or {} else logging.error(LTAG.ERROR, "没有找到HorseId:", horseId, "的坐骑信息,请检查!!!") end end function HorseSoul_Model.GetSoulItemList() return private.soulPearlIdList end function HorseSoul_Model.GetSoulMaterialList() return private.soulMaterialIdList end function HorseSoul_Model.GetSoulSuitDataList() return private.soulSuitDataList end function HorseSoul_Model.GetGeneralMaterialItem() return HorseSoulLevelGeneralItem, HorseSoulLevelGeneralItemExp end ---@return number 返回图鉴加成(浮点数,例:0.05) function HorseSoul_Model.GetHorsePictorialAdd() if not private.horseSoulAddition then private.RefreshHorsePictorialAdd() end return 1 + private.horseSoulAddition end function private.RefreshHorsePictorialAdd() local level = MDL.HorseLibrary.GetLibraryLevelAndScore() private.horseSoulAddition = level > 0 and DataSheetManager.HorsePictorialScore:GetDataByLevelID(level).HorseSoulAddition or 0 end function HorseSoul_Model.InitBagSoulPearl(soulPearls, soulPearlsExtras) --背包数据 for i, v in ipairs(soulPearls) do local soulPearlData = private.soulPearlInfoDic[v.id] if not soulPearlData then private.soulPearlInfoDic[v.id] = { id = v.id, cfgId = v.cfgId, equipHorseId = false, soulData = DataSheetManager.HorseSoulData:GetDataByHorseSoulID(v.cfgId), itemData = DataSheetManager.ItemData:GetDataByID(v.cfgId), } table.insert(private.soulPearlIdList, v.id) table.insert(private.soulMaterialIdList, v.id) end end --魂珠等级 for i, v in ipairs(soulPearlsExtras) do local soulPearlData = private.soulPearlInfoDic[v.id] if soulPearlData then soulPearlData.levelInfo = {level = v.level, curExp = v.curExp, breakLevel = v.breakLevel} soulPearlData.star = v.starLevel or 1 soulPearlData.gs = CTL.HorseSoul.CalculateSoulGs(v.id) end end --排序,待补充 table.sort(private.soulPearlIdList, private.SortSoulPearl) table.sort(private.soulMaterialIdList, private.SortSoulMaterial) EventSystem.Dispatch(EventID.HorseSoulPearl_UpdateBag) end function HorseSoul_Model.UpdateSoulPearlEquipDic(horseInfoList) for _, v in ipairs(horseInfoList) do local horseEquip = private.soulPearlEquipDic[v.Id] if horseEquip then for soulId, pos in pairs(horseEquip) do if private.soulPearlInfoDic[soulId] then private.soulPearlInfoDic[soulId].equipHorseId = false end end table.clear(horseEquip) else horseEquip = {} private.soulPearlEquipDic[v.Id] = horseEquip end for i, info in ipairs(v.soulSlotInfos) do if CTL.HorseSoul.JudgeSoulId(info.soulPearl) then horseEquip[info.soulPearl] = i end end end for horseId, horseEquip in pairs(private.soulPearlEquipDic) do for soulId, pos in pairs(horseEquip) do if private.soulPearlInfoDic[soulId] then private.soulPearlInfoDic[soulId].equipHorseId = horseId -- 设置装备状态 end end CTL.HorseSoul.CalculateHorseSoulGs(horseId) end table.sort(private.soulPearlIdList, private.SortSoulPearl) EventSystem.Dispatch(EventID.UI_HorseSoul_EquipUpdate) end function HorseSoul_Model.UpdateBagSoulPearl(soulPearls, soulPearlsExtras) --背包数据 for i, v in ipairs(soulPearls) do local soulPearlData = private.soulPearlInfoDic[v.id] if not soulPearlData then private.soulPearlInfoDic[v.id] = { id = v.id, cfgId = v.cfgId, equipHorseId = HorseSoul_Model.JudgeIfEquip(v.id), soulData = DataSheetManager.HorseSoulData:GetDataByHorseSoulID(v.cfgId), itemData = DataSheetManager.ItemData:GetDataByID(v.cfgId), } table.insert(private.soulPearlIdList, v.id) table.insert(private.soulMaterialIdList, v.id) end end for i, v in ipairs(soulPearlsExtras) do local soulPearlData = private.soulPearlInfoDic[v.id] if soulPearlData then soulPearlData.levelInfo = {level = v.level, curExp = v.curExp, breakLevel = v.breakLevel} soulPearlData.star = v.starLevel or 1 soulPearlData.gs = CTL.HorseSoul.CalculateSoulGs(v.id) soulPearlData.equipHorseId = HorseSoul_Model.JudgeIfEquip(v.id) end end --排序,待补充 table.sort(private.soulPearlIdList, private.SortSoulPearl) table.sort(private.soulMaterialIdList, private.SortSoulMaterial) EventSystem.Dispatch(EventID.HorseSoulPearl_UpdateBag) end function HorseSoul_Model.DelBagSoulPearl(delSoulPearl) -- 移除(排序列表)对应魂晶 for i, id in ipairs(delSoulPearl) do private.soulPearlInfoDic[id] = nil local index = 0 for i, v in ipairs(private.soulPearlIdList) do if v == id then index = i break end end table.remove(private.soulPearlIdList, index) for i, v in ipairs(private.soulMaterialIdList) do if v == id then index = i break end end table.remove(private.soulMaterialIdList, index) end table.sort(private.soulPearlIdList, private.SortSoulPearl) table.sort(private.soulMaterialIdList, private.SortSoulMaterial) EventSystem.Dispatch(EventID.HorseSoulPearl_UpdateBag) end function HorseSoul_Model.JudgeIfEquip(soulId) for horseId, equipDic in pairs(private.soulPearlEquipDic) do for id, pos in pairs(equipDic) do if id == soulId then return horseId end end end return false end function HorseSoul_Model.HorseSoulEquipReq(type, soulPearlId, horseId, posNum, suitId) local msg = horse_soul_pb.HorseSoulEquipReq() msg.type = type msg.soulPearlId = soulPearlId msg.horseId = horseId msg.posNum = posNum msg.suitId = suitId and suitId or 0 local level, suitId = CTL.HorseSoul.GetSoulSkillLevel(horseId) private.tempSkillData = {level = level or 0, suitId = suitId} NetManager.SendMessage(MessageEnums.MessageHorseSoulEquip, msg) end function private.HorseSoulEquipResp(msgResp) if msgResp.Resp.Code == 0 then if msgResp.type == HorseSoul_Model.HorseSoulEquipType.Equip or msgResp.type == HorseSoul_Model.HorseSoulEquipType.AutoEquip then EventSystem.Dispatch(EventID.UI_HorseSoul_EquipOpt, private.tempSkillData) private.tempSkillData = nil if msgResp.type == HorseSoul_Model.HorseSoulEquipType.AutoEquip then CTL.Tips.AddTipsMsg(Const_IDS.IDS_HorseSoul_Hint_QuickEquip) end end end end local soulOptType = 0 function HorseSoul_Model.HorseSoulOptReq(optType, soulPearlId, itemList) local msg = horse_soul_pb.HorseSoulOptReq() msg.opType = optType msg.soulPearlId = soulPearlId soulOptType = optType if itemList then for i, v in ipairs(itemList) do --id,物品实例id;count,数量 local id = v.id if type(id) == "number" then --有可能是通用材料,id为number local selectCount = v.count local itemBagList = MDL.Bag.GetItemsByCfgId(id) for _, item in ipairs(itemBagList) do local msgItem = horse_soul_pb.HSItemCosts() msgItem.id = item.Id local cellCount = item.Count --一个背包格内的数量 msgItem.count = cellCount >= selectCount and selectCount or cellCount msgItem.bagTyp = v.bagTyp selectCount = selectCount - cellCount table.insert(msg.itemInfos, msgItem) if selectCount <= 0 then break end end else local msgItem = horse_soul_pb.HSItemCosts() msgItem.id = id msgItem.count = v.count msgItem.bagTyp = v.bagTyp table.insert(msg.itemInfos, msgItem) end end end if HorseSoul_Model.GetSoulInfoById(soulPearlId).equipHorseId then local level, suitId = CTL.HorseSoul.GetSoulSkillLevel(HorseSoul_Model.GetSoulInfoById(soulPearlId).equipHorseId) private.tempSkillData = {level = level or 0, suitId = suitId} else private.tempSkillData = nil end private.tempLevelData = {soulId = soulPearlId, levelInfo = HorseSoul_Model.GetSoulInfoById(soulPearlId).levelInfo} NetManager.SendMessage(MessageEnums.MessageHorseSoulOpt, msg) end function private.HorseSoulOptResp(msgResp) if msgResp.Resp.Code == 0 then EventSystem.Dispatch(EventID.UI_HorseSoul_Upgrade, private.tempLevelData) if soulOptType == MDL.HorseSoul.HorseSoulOptType.Star and private.tempSkillData ~= nil then EventSystem.Dispatch(EventID.UI_HorseSoul_EquipOpt, private.tempSkillData) end private.tempLevelData = nil soulOptType = 0 end end --已装备>高品质>高启魂等级>高等级>高战力>id靠前 function private.SortSoulPearl(a, b) local soulInfoA = private.soulPearlInfoDic[a] local soulInfoB = private.soulPearlInfoDic[b] local isEquipA = soulInfoA.equipHorseId and true local isEquipB = soulInfoB.equipHorseId and true if isEquipA and not isEquipB then return true elseif not isEquipA and isEquipB then return false else local qualityA = soulInfoA.itemData.Color local qualityB = soulInfoB.itemData.Color if qualityA ~= qualityB then return qualityA > qualityB else if soulInfoA.star ~= soulInfoB.star then return soulInfoA.star > soulInfoB.star else local levelInfoA = soulInfoA.levelInfo local levelInfoB = soulInfoB.levelInfo local levelA = levelInfoA.level local levelB = levelInfoB.level if levelA ~= levelB then return levelA > levelB else local breakLevelA = levelInfoA.breakLevel local breakLevelB = levelInfoB.breakLevel if breakLevelA ~= breakLevelB then return breakLevelA > breakLevelB else local gsA = soulInfoA.gs local gsB = soulInfoB.gs if gsA ~= gsB then return gsA > gsB else return soulInfoA.cfgId < soulInfoB.cfgId end end end end end end end function private.SortSoulMaterial(a, b) local soulInfoA = private.soulPearlInfoDic[a] local soulInfoB = private.soulPearlInfoDic[b] local qualityA = soulInfoA.itemData.Color local qualityB = soulInfoB.itemData.Color if qualityA ~= qualityB then return qualityA < qualityB else if soulInfoA.star ~= soulInfoB.star then return soulInfoA.star < soulInfoB.star else local levelInfoA = soulInfoA.levelInfo local levelInfoB = soulInfoB.levelInfo local levelA = levelInfoA.level local levelB = levelInfoB.level if levelA ~= levelB then return levelA < levelB else local breakLevelA = levelInfoA.breakLevel local breakLevelB = levelInfoB.breakLevel if breakLevelA ~= breakLevelB then return breakLevelA < breakLevelB else return soulInfoA.cfgId < soulInfoB.cfgId end end end end end function private.SortSuitList(a, b) return a.suitId < b.suitId end -- 背包中是否有未装备的魂珠 function HorseSoul_Model.CanEquip() for k,v in pairs(private.soulPearlInfoDic) do if not v.equipHorseId then return true end end return false end --region ********************* 魂珠抽卡 ************************** -- 获取当前聚魂服务器数据 function HorseSoul_Model.GetDrawHorseSoulInfo() return private.DrawHorseSoulInfo end -- 获取心愿魂珠数据 function HorseSoul_Model.GetSelectWishInfo(wishType) for k,v in ipairs(private.DrawHorseSoulInfo.wishInfo) do if v.wishType == wishType then return v end end return nil end function HorseSoul_Model.GetHorseSoulDailyDrawNum() return HorseSoulDailyDrawNum end -- 每日抽卡上限判断 function HorseSoul_Model.CanDrawCardByCount(count) if private.DrawHorseSoulInfo.todayDrawNum > HorseSoulDailyDrawNum then return false, Const_IDS.IDS_HorseSoul_DrawHint9 end if HorseSoulDailyDrawNum - private.DrawHorseSoulInfo.todayDrawNum >= count then return true end return false, Const_IDS.IDS_HorseSoul_DrawHint9 end -- 是否变更卡池 function HorseSoul_Model.CanOpenResetView() if private.DrawHorseSoulOpenResetState == 2 then UIManager.OpenView(Const_UI_Lua.UIEnum.UIHorseSoulGachaUnlockAndReset, {isReSet = true}) elseif private.DrawHorseSoulOpenResetState == 1 then UIManager.OpenView(Const_UI_Lua.UIEnum.UIHorseSoulGachaUnlockAndReset, {isReSet = false, lastPoolID = private.lastPoolID, curPoolID = private.DrawHorseSoulInfo.drawPoolID}) end end function HorseSoul_Model.GetGachaCostNumShow(itemId, needCount) local costStr = string.format(CostNumShowStr, needCount) return UTL.Color.FormatTextByColor(UTL.Item.GetItemStockCount(itemId) >= needCount and UTL.Color.ModelNameColor.White or UTL.Color.Red, costStr) end function HorseSoul_Model.IsShowDrawTenCardRP() local drawCardData = DataSheetManager.HorseSoulDrawData:GetDataByID(private.DrawHorseSoulInfo.drawPoolID) local haveDrawNum, _ = HorseSoul_Model.CanDrawCardByCount(10) local haveDrawHunNum, _ = HorseSoul_Model.CanDrawCardByCount(HorseSoullargeDrawNum) if drawCardData and (haveDrawNum or haveDrawHunNum) then return UTL.Item.GetItemStockCount(drawCardData.Item) >= drawCardData.TenDrawItemNum or UTL.Item.GetItemStockCount(drawCardData.Item) >= drawCardData.TenDrawItemNum * (HorseSoullargeDrawNum / 10) end return false end ---@public 同步聚魂服务器数据 function HorseSoul_Model.SyncDrawHorseSoulInfo(msgResp) -- logging.log(LTAG.LOG, "[dtf]: 聚魂服务器数据 ", msgResp) if msgResp.drawPoolID > 0 then if private.DrawHorseSoulInfo.drawPoolID then if private.DrawHorseSoulInfo.drawPoolID > msgResp.drawPoolID then private.DrawHorseSoulOpenResetState = 2 elseif private.DrawHorseSoulInfo.drawPoolID < msgResp.drawPoolID then private.DrawHorseSoulOpenResetState = 1 private.lastPoolID = private.DrawHorseSoulInfo.drawPoolID else private.DrawHorseSoulOpenResetState = 0 end for _, c_WishInfo in ipairs(private.DrawHorseSoulInfo.wishInfo) do if not c_WishInfo.isUnlock then for _, s_WishInfo in ipairs(msgResp.wishInfo) do if c_WishInfo.wishType == s_WishInfo.wishType and s_WishInfo.isUnlock == true then if c_WishInfo.wishType == 1 then -- 红色心愿解锁红点 HorseSoul_Model.RedWishUnLockRedPoint = true elseif c_WishInfo.wishType == 2 then -- 金色心愿解锁红点 HorseSoul_Model.GoldWishUnLockRedPoint = true end end end end end end private.DrawHorseSoulInfo = msgResp end end ---@public 领取聚魂次数奖励 ------@param stageID 领取奖励阶段ID function HorseSoul_Model.GetDrawSoulNumRewardReq(stageID) local msg = draw_horse_soul_pb.GetDrawSoulNumRewardReq() msg.stageID = stageID NetManager.SendMessage(MessageEnums.MessageGetDrawSoulNumReward, msg) end function private.GetDrawSoulNumRewardResp(msgResp) if msgResp.stageID > 0 then private.DrawHorseSoulInfo.numRewardStageID = msgResp.stageID private.DrawHorseSoulInfo.numRewardRemainNum = msgResp.remainDrawNum EventSystem.Dispatch(EventID.UI_HorseSoul_Gacha_RefreshUI) end end ---@public 聚魂 ---@param drawPoolID 抽取卡池ID ---@param drawNum 抽取次数 function HorseSoul_Model.DrawHorseSoulReq(drawPoolID, drawNum) -- 拦截奖励提示 因为奖励在抽卡协议数据执行前执行 所以请求时就拦截 MDL.Reward.SetCloseRewardTipShow(true) local msg = draw_horse_soul_pb.DrawHorseSoulReq() msg.drawPoolID = drawPoolID msg.drawNum = drawNum NetManager.SendMessage(MessageEnums.MessageDrawHorseSoul, msg) end function private.DrawHorseSoulResp(msgResp) -- logging.log(LTAG.LOG, "[dtf]: 抽卡结果 ", msgResp.rewardItems) if msgResp.Resp.Code == 0 then UIManager.OpenView(Const_UI_Lua.UIEnum.UIHorseSoulGachaResult, {rewardList = msgResp.rewardItems}) end MDL.Reward.SetCloseRewardTipShow(false) end ---@public 聚魂许愿 ---@param wishType 心愿类型 ---@param wishSoulID 心愿魂珠ID function HorseSoul_Model.SoulDrawWishOptReq(wishOpt, wishType, wishSoulID) local msg = draw_horse_soul_pb.SoulDrawWishOptReq() msg.wishOpt = wishOpt msg.wishType = wishType msg.wishSoulID = wishSoulID NetManager.SendMessage(MessageEnums.MessageSoulDrawWishOpt, msg) end function private.SoulDrawWishOptResp(msgResp) -- logging.log(LTAG.LOG, "[dtf]: 选择心愿 ", msgResp.wishInfo) if msgResp.wishInfo and msgResp.wishInfo.wishType > 0 then for k,v in ipairs(private.DrawHorseSoulInfo.wishInfo) do if v.wishType == msgResp.wishInfo.wishType then v.wishSoulID = msgResp.wishInfo.wishSoulID v.isMustGet = msgResp.wishInfo.isMustGet v.isUnlock = msgResp.wishInfo.isUnlock end end EventSystem.Dispatch(EventID.UI_HorseSoul_Gacha_RefreshUI) end end --endregion ********************* 魂珠抽卡 ************************** return HorseSoul_Model