local Equipment_Model = {} local private = {} local EventSystem = require('Event/EventSystem') local EquipmentHintToggleKey = "EquipmentHintToggleKey" local EquipmentStarToggleKey = "EquipmentStarToggleKey" Equipment_Model.MainTabType = { EquipWhole = 0, --装备主界面 EquipDebris = 1, --装备碎片 } Equipment_Model.MaxEquipNum = 4 --对应配置的部位ID Equipment_Model.EquipTabType = { All = 0, --全部 Helmet = 1, --帽子 Clothes = 2, --衣服 Trousers = 3, --裤子 Boots = 4, --鞋子 } Equipment_Model.EquipTypeNameIDS = { [Equipment_Model.EquipTabType.All] = Const_IDS.IDS_Equip_AllType_Button, --全部 [Equipment_Model.EquipTabType.Helmet] = Const_IDS.IDS_Equip_Type_Helmet, --帽子 [Equipment_Model.EquipTabType.Clothes] = Const_IDS.IDS_Equip_Type_Armour, --衣服 [Equipment_Model.EquipTabType.Trousers] = Const_IDS.IDS_Equip_Type_Wrister, --裤子 [Equipment_Model.EquipTabType.Boots] = Const_IDS.IDS_Equip_Type_Boot, --鞋子 } Equipment_Model.DetailType = { Base = 0, Info = 1, --信息界面 Strengthen = 2, --强化界面 Compose = 3,--合成界面 Star = 4, --升星 } private.sortedAllTypeList = {} --所有种类的装备列表,缓存排序结果,不用每次切到全部的时候再去重复排序 function Equipment_Model.OnStartup() NetManager.RegisterMsgCB(MessageEnums.MessageEquipCombine, private.CombineEquipResponse) NetManager.RegisterMsgCB(MessageEnums.MessageEquipWear, private.WearEquipResponse) NetManager.RegisterMsgCB(MessageEnums.MessageEquipEnhance, private.EnhanceEquipResponse) NetManager.RegisterMsgCB(MessageEnums.MessageEquipRefine, private.OnEquipRefineResp) NetManager.RegisterMsgCB(MessageEnums.MessageEquipQuickWear, private.OnEquipQuickWear) NetManager.RegisterMsgCB(MessageEnums.MessageEquipStarLevelUp, private.OnEquipStarLevelUp) NetManager.RegisterMsgCB(MessageEnums.MessageEquipStarSkillOpt, private.OnEquipStarSkillOpt) NetManager.RegisterMsgCB(MessageEnums.MessageEquipQuickRefine, private.EquipQuickRefineResp) NetManager.RegisterMsgCB(MessageEnums.MessageEquipSetRefinePriority, private.EquipSetRefinePriorityResp) NetManager.RegisterMsgCB(MessageEnums.MessageEquipGetRefinePriority, private.EquipGetRefinePriorityResp) EventSystem.Regist(EventID.UI_HeroFormation_ChangeHero, private.UpdateEquipmentToHero) --[[ 存储所有的装备信息 RefineAttrs:服务器随机出的洗炼属性 k:ID,v:EquipmentInfo[ItemData,EquipData,RefineAttrs,ID,ClientEquipmentFight] ]]-- private.equipmentInfoDic = {} --[[ 存储所有的碎片信息 k:ID,v:DebrisInfo[ItemData,EquipData,ID,Num] ]]-- private.debrisInfoDic = {} --标识是否发送了装备的协议 private.equipRequestHeroId = nil --按照套装存储该套装的装备ID,暂时不用,先注释掉 --private.suitEquipmentsIdList = {} private.equipRefinePriority = {} private.quickRefineConfirmShowFlag = true --装备id对应的heroid private.formationEquipToHeroId = {} --按照类型存储装备,1,2,3,4 private.equipmentInfoByType = {{},{},{},{}} --装备位置是否开放 private.equipTypeUnlock = {false, false, false, false} end --EnterWorld 初始化 --务必保证时序在HeroSelect_Model中的heroInfoList初始化之后 function Equipment_Model.SetEquipInfo(equips, equipExtras, equipShreds) Equipment_Model.UpdateOrAddEquip(equips, equipExtras, true) Equipment_Model.UpdateOrAddEquipDebris(equipShreds, true) end function Equipment_Model.UpdateOrAddEquip(equips, equipExtras, isInit) for _, serverEquip in ipairs(equips) do local clientEquip = private.equipmentInfoDic[serverEquip.id] if clientEquip == nil then clientEquip = { ID = serverEquip.id, ItemData = DataSheetManager.ItemData:GetDataByID(serverEquip.cfgId), EquipData = DataSheetManager.EquipData:GetDataByID(serverEquip.cfgId), ClientEquipmentFight = 0, } private.equipmentInfoDic[serverEquip.id] = clientEquip table.insert(private.equipmentInfoByType[clientEquip.EquipData.EquipType], clientEquip) end --拓展参数 local refineAttrs --洗炼属性 if equipExtras and table.getn(equipExtras)> 0 then for _,extra in ipairs(equipExtras) do if extra.id == serverEquip.id then refineAttrs = extra.refineAttrs break end end end clientEquip.RefineAttrs = refineAttrs clientEquip.ClientEquipmentFight = UTL.Attr.CalculateFight(CTL.Equipment.GetEquipAttr(clientEquip, true, false)) clientEquip.BaseEquipmentFight = UTL.Attr.CalculateFight(CTL.Equipment.GetEquipAttr(clientEquip, false, false)) end if not isInit then EventSystem.Dispatch(EventID.UI_UpdateEquipmentInfo) end end function Equipment_Model.UpdateOrAddEquipDebris(equipShreds, isInit) for _, item in ipairs(equipShreds) do local addNum = 0 --碎片飘字的数量 local resetData = false local debrisInfo = private.debrisInfoDic[item.id] if debrisInfo then --配置的ID一致,只更新数量 if item.cfgId == debrisInfo.EquipData.ID then debrisInfo.Num = item.count else resetData = true end addNum = item.count - debrisInfo.Num else resetData = true debrisInfo = {} addNum = item.count end if resetData then debrisInfo.ID = item.id debrisInfo.Num = item.count for _,v in DataSheetManager.EquipData:GetEnumerator() do if v.ItemID == item.cfgId then debrisInfo.EquipData = v break end end debrisInfo.ItemData = DataSheetManager.ItemData:GetDataByID(item.cfgId) private.debrisInfoDic[item.id] = debrisInfo end end if not isInit then EventSystem.Dispatch(EventID.UI_UpdateDebrisInfo) end end function Equipment_Model.DeleteEquip(deleteEquipIds) for i = 1, #deleteEquipIds do local deleteEquip = private.equipmentInfoDic[deleteEquipIds[i]] if deleteEquip then for index, typeEquip in ipairs(private.equipmentInfoByType[deleteEquip.EquipData.EquipType]) do if typeEquip.ID == deleteEquipIds[i] then table.remove(private.equipmentInfoByType[deleteEquip.EquipData.EquipType], index) break end end end private.equipmentInfoDic[deleteEquipIds[i]] = nil end EventSystem.Dispatch(EventID.UI_UpdateEquipmentInfo) end function Equipment_Model.DeleteEquipDebris(equipShreds) if not equipShreds or table.getn(equipShreds)==0 then return end for i = 1, #equipShreds do if private.debrisInfoDic[equipShreds[i]] then private.debrisInfoDic[equipShreds[i]] = nil end end EventSystem.Dispatch(EventID.UI_UpdateDebrisInfo) end function private.UpdateDebrisInfo(item) local addNum = 0 --碎片飘字的数量 local resetData = false local debrisInfo = private.debrisInfoDic[item.id] if debrisInfo then --配置的ID一致,只更新数量 if item.cfgId == debrisInfo.EquipData.ID then debrisInfo.Num = item.count else resetData = true end addNum = item.count - debrisInfo.Num else resetData = true debrisInfo = {} addNum = item.count end if resetData then debrisInfo.ID = item.id debrisInfo.Num = item.count for _,v in DataSheetManager.EquipData:GetEnumerator() do if v.ItemID == item.cfgId then debrisInfo.EquipData = v break end end debrisInfo.ItemData = DataSheetManager.ItemData:GetDataByID(item.cfgId) private.debrisInfoDic[item.id] = debrisInfo end end function Equipment_Model.OnInitServerDataOver() private.UpdateEquipmentToHero() end --装备id对应的heroid function private.UpdateEquipmentToHero() table.clear(private.formationEquipToHeroId) local formationHeroIdList = MDL.Formation.GetSlotHeroIds() for index, heroId in ipairs(formationHeroIdList) do local heroInfo = MDL.HeroSelect.GetHeroInfo(heroId) if heroId>0 then for index, serverEquipData in ipairs(heroInfo.equipInfos) do if not string.isNilOrEmpty(serverEquipData.Id) then private.formationEquipToHeroId[serverEquipData.Id] = heroId private.equipTypeUnlock[index] = true end end end end end --装备排序规则:穿戴>等级>品质>部位>装备战力 function private.EquipSortRule(equipInfo_1, equipInfo_2) local wear_1 = Equipment_Model.GetEquipHeroInfo(equipInfo_1.ID) ~= nil and 1 or 0 local wear_2 = Equipment_Model.GetEquipHeroInfo(equipInfo_2.ID) ~= nil and 1 or 0 if wear_1 == wear_2 then local equipLevel_1 = equipInfo_1.EquipData.EquipLevel local equipLevel_2 = equipInfo_2.EquipData.EquipLevel if equipLevel_1 == equipLevel_2 then local quality_1 = equipInfo_1.ItemData.Color local quality_2 = equipInfo_2.ItemData.Color if quality_1 == quality_2 then if equipInfo_1.EquipData.EquipType == equipInfo_2.EquipData.EquipType then local fight_1 = equipInfo_1.ClientEquipmentFight local fight_2 = equipInfo_2.ClientEquipmentFight return fight_1 > fight_2 else return equipInfo_1.EquipData.EquipType < equipInfo_2.EquipData.EquipType end else return quality_1 > quality_2 end else return equipLevel_1 > equipLevel_2 end else return wear_1 > wear_2 end end function Equipment_Model.UpdateSortedAllTypeList() table.clearArray(private.sortedAllTypeList) for _,info in pairs(private.equipmentInfoDic) do table.insert(private.sortedAllTypeList,info) end table.sort(private.sortedAllTypeList, private.EquipSortRule) end --根据部位查找装备列表 function Equipment_Model.GetSortedEquipmentsByType(type, equipInfos) if type == Equipment_Model.EquipTabType.All then return private.sortedAllTypeList end table.clearArray(equipInfos) for _,info in pairs(private.equipmentInfoDic) do if info.EquipData.EquipType == type then table.insert(equipInfos,info) end end table.sort(equipInfos, private.EquipSortRule) return equipInfos end --碎片排序规则:可合成>品质>部位 function private.DebrisSortRule(debrisInfo_1, debrisInfo_2) local red_1 = CTL.Equipment.CheckDebrisIfRed(debrisInfo_1) and 1 or 0 local red_2 = CTL.Equipment.CheckDebrisIfRed(debrisInfo_2) and 1 or 0 if red_1 == red_2 then local quality_1 = debrisInfo_1.ItemData.Color local quality_2 = debrisInfo_2.ItemData.Color if debrisInfo_1.EquipData.EquipStage == debrisInfo_2.EquipData.EquipStage then if quality_1 == quality_2 then return debrisInfo_1.EquipData.EquipType < debrisInfo_2.EquipData.EquipType else return quality_1 > quality_2 end else return debrisInfo_1.EquipData.EquipStage > debrisInfo_2.EquipData.EquipStage end else return red_1 > red_2 end end --根据部位查找碎片列表 function Equipment_Model.GetSortedDebrisListByType(type, debrisList) table.clearArray(debrisList) for _,info in pairs(private.debrisInfoDic) do if type == Equipment_Model.EquipTabType.All or info.EquipData.EquipType == type then table.insert(debrisList,info) end end table.sort(debrisList, private.DebrisSortRule) return debrisList end --根据武将ID查找装备列表(上阵武将) function Equipment_Model.GetEquipmentsByHeroId(heroId) local equipInfos local heroInfo = MDL.HeroSelect.GetHeroInfo(heroId) if heroInfo then if heroInfo.equipInfos and #heroInfo.equipInfos > 0 then for i = 1, #heroInfo.equipInfos do local equipInfo = private.equipmentInfoDic[heroInfo.equipInfos[i].Id] if equipInfo then if equipInfos == nil then equipInfos = {} end table.insert(equipInfos,equipInfo) end end end end return equipInfos end --获取身上穿戴的第一件装备类型(按类型遍历) function Equipment_Model.GetFirstEquipInfoByHeroId(heroId) local heroInfo = MDL.HeroSelect.GetHeroInfo(heroId) if heroInfo then for _, v in ipairs(heroInfo.equipInfos) do if string.isNilOrEmpty(v.Id) == false then return private.equipmentInfoDic[v.Id] end end end return nil end --由唯一ID获取装备信息 function Equipment_Model.GetEquipmentInfoByID(equipId) return private.equipmentInfoDic[equipId] end --由唯一ID获取碎片信息 function Equipment_Model.GetDebrisInfoByID(debrisId) return private.debrisInfoDic[debrisId] end --强化装备请求,单个 function Equipment_Model.StrengthenEquipRequest(equipInfo) local msg = NetManager.GetPB("equip_pb").EquipEnhanceReq() local heroId = Equipment_Model.GetEquipHeroId(equipInfo.ID) if heroId == nil then return end msg.heroId = heroId local enhanceInfo = NetManager.GetPB("equip_pb").EquipEnhanceInfo() enhanceInfo.equipType = equipInfo.EquipData.EquipType enhanceInfo.times = 1 table.insert(msg.equipEnhanceInfo,enhanceInfo) msg.isOneKey = false NetManager.SendMessage(MessageEnums.MessageEquipEnhance, msg) end --一键强化装备,可能有多个 --strengthDir[equipId,times] function Equipment_Model.QuickStrengthenEquipRequest(heroId,strengthDir) local msg = NetManager.GetPB("equip_pb").EquipEnhanceReq() msg.heroId = heroId for equipId,times in pairs(strengthDir) do local equipData = DataSheetManager.EquipData:GetDataByID(equipId) local enhanceInfo = NetManager.GetPB("equip_pb").EquipEnhanceInfo() enhanceInfo.equipType = equipData.EquipType enhanceInfo.times = times table.insert(msg.equipEnhanceInfo,enhanceInfo) end msg.isOneKey = true NetManager.SendMessage(MessageEnums.MessageEquipEnhance, msg) end function private.EnhanceEquipResponse(msgResp) if msgResp.Resp.Code == 0 then BIManager.DispatchBIClientEvent(BIManager.EventName.EquipStrengthen) CTL.Tips.AddTipsMsg(Const_IDS["IDS_Equip_Enchance_Success"]) CTL.Sound.PlayGameSound("UI_strengthen") EventSystem.Dispatch(EventID.UI_EquipEnhance_Success) end end --合成装备请求 function Equipment_Model.CombineEquipRequest(debrisInfo,num) if num == 0 then CTL.Tips.AddTipsMsg(Const_IDS["IDS_Equip_EquipChipNotEnough"]) return end local perNum = debrisInfo.EquipData.ItemNum local totalNum = debrisInfo.Num if totalNum >= perNum * num then local msg = NetManager.GetPB("equip_pb").EquipCombineReq() msg.equipCfgId = debrisInfo.EquipData.ID msg.combineNum = num NetManager.SendMessage(MessageEnums.MessageEquipCombine, msg) else CTL.Tips.AddTipsMsg(Const_IDS["IDS_Equip_EquipChipNotEnough"]) end end function private.CombineEquipResponse(msgResp) logging.log(LTAG.LOG, "EquipCombineResp") end --穿戴/替换装备请求 function Equipment_Model.WearEquipRequest(heroId, equipType, equipId, resultCode) --穿戴等级是否符合 local info = MDL.Equipment.GetEquipmentInfoByID(equipId) if info == nil then return end if CTL.Equipment.CheckIfCanEquip(equipType, info, true) == false then CTL.Tips.AddTipsMsg(Const_IDS["IDS_EquipRefine_WrongHint2"]) return end local msg = NetManager.GetPB("equip_pb").EquipWearReq() msg.heroId = heroId msg.equipType = equipType msg.equipId = equipId private.equipMsgCode = resultCode or Const_IDS["IDS_HeroAdvanceTip1"] private.equipRequestHeroId = heroId NetManager.SendMessage(MessageEnums.MessageEquipWear, msg) end function private.WearEquipResponse(msgResp) if msgResp.Resp.Code == 0 then CTL.Sound.PlayGameSound("UI_equipment_01") CTL.Tips.AddTipsMsg(private.equipMsgCode) private.equipMsgCode = nil private.UpdateEquipmentToHero() EventSystem.Dispatch(EventID.UI_EquipWear_Success) end end function Equipment_Model.EquipRefineReq(leftId, leftAttrId, rightId, rightAttrId) local info = Equipment_Model.GetEquipmentInfoByID(leftId) if info == nil then logging.error(LTAG.ERROR, "EquipRefineReq Fail", leftId) return end if MDL.Currency.IsMoneyEnough(info.EquipData.RefineItem, info.EquipData.RefineItemNum) == false then CTL.Tips.AddTipsMsg(Const_IDS["IDS_EquipRefine_WrongHint1"]) return end local heroId = Equipment_Model.GetEquipHeroId(leftId) local msg = NetManager.GetPB("equip_pb").EquipRefineReq() msg.leftId = leftId msg.leftAttrId = leftAttrId msg.rightId = rightId msg.rightAttrId = rightAttrId msg.heroId = heroId NetManager.SendMessage(MessageEnums.MessageEquipRefine, msg) end function Equipment_Model.SetEquipAttrIteratorData(refineAttrs, emptyAttr, refineMaxNum) private.refineAttrList = refineAttrs private.EMPTY_ATTR_TYPE = emptyAttr private.enumNextIndex = 1 private.refineMaxNum = refineMaxNum private.refineNum = private.refineAttrList and #private.refineAttrList or 0 end function Equipment_Model.EnumEquipAttrIterator() local data if private.refineNum >= private.enumNextIndex then data = private.refineAttrList[private.enumNextIndex] else data = private.EMPTY_ATTR_TYPE end private.enumNextIndex = private.enumNextIndex + 1 if private.enumNextIndex > private.refineMaxNum + 1 then return nil end return data end function private.OnEquipRefineResp(msgResp) if msgResp.Resp.Code == 0 then EventSystem.Dispatch(EventID.UI_Refine_Success) CTL.Sound.PlayGameSound("UI_equipment_02") end end function Equipment_Model.EquipQuickWearReq() local msg = NetManager.GetPB("equip_pb").EquipQuickWearReq() NetManager.SendMessage(MessageEnums.MessageEquipQuickWear, msg) end function private.OnEquipQuickWear(msgResp) if msgResp.Resp.Code == 0 then CTL.Sound.PlayGameSound("UI_equipment_02") CTL.Tips.AddTipsMsg(Const_IDS["IDS_HeroAdvanceTip1"]) private.UpdateEquipmentToHero() EventSystem.Dispatch(EventID.UI_EquipWear_Success) end end -- 一键洗练 function Equipment_Model.EquipQuickRefineReq() local msg = NetManager.GetPB("equip_pb").EquipQuickRefineReq() NetManager.SendMessage(MessageEnums.MessageEquipQuickRefine, msg) end function private.EquipQuickRefineResp() end function Equipment_Model.EquipGetRefinePriorityReq() local msg = NetManager.GetPB("equip_pb").EquipGetRefinePriorityReq() NetManager.SendMessage(MessageEnums.MessageEquipGetRefinePriority, msg) end -- 获取洗练优先级 function private.EquipGetRefinePriorityResp(msg) for _, v in ipairs(msg.priority) do local equipType = v.equipType if private.equipRefinePriority[equipType] then table.clearArray(private.equipRefinePriority[equipType]) else private.equipRefinePriority[equipType] = {} end local equipAttrs = private.equipRefinePriority[equipType] for __, attrID in ipairs(v.attrId) do table.insert(equipAttrs, attrID) end end EventSystem.Dispatch(EventID.UI_RefreshEquipRefinePriority, private.equipRefinePriority, msg.priority) end --- 设置一键洗练优先级 --- @param priorities table 洗练优先度 function Equipment_Model.EquipSetRefinePriorityReq() local priorities = private.equipRefinePriority local msg = NetManager.GetPB("equip_pb").EquipSetRefinePriorityReq() for type, v in ipairs(priorities) do local temp = msg.priority:add() for k, attrID in ipairs(v) do temp.equipType = type temp.attrId:append(attrID) end end NetManager.SendMessage(MessageEnums.MessageEquipSetRefinePriority, msg) end function private.EquipSetRefinePriorityResp() -- 无需处理playerChange end function Equipment_Model.GetEquipmentInfoDic() return private.equipmentInfoDic end function Equipment_Model.GetEquipmentListByType(equipType) return private.equipmentInfoByType[equipType] end function Equipment_Model.GetDebrisInfoDic() return private.debrisInfoDic end function Equipment_Model.SetSkipHintToggle(state) if state then --因为%w是0-6,没有值默认取0,所以无法分辨0的时候是没有值还是存的值为0,所以+1进行存储 local timeValue = UTL.Time.OsDateOriginal("%w", UTL.Time.GetServerTimestamp()) + 1 PersistentData.PlayerData:Set(EquipmentHintToggleKey, timeValue, true) else PersistentData.PlayerData:Set(EquipmentHintToggleKey, -1, true) end end function Equipment_Model.GetSkipHintToggle() local oldValue = PersistentData.PlayerData:Get(EquipmentHintToggleKey,0) local newValue = UTL.Time.OsDateOriginal("%w", UTL.Time.GetServerTimestamp()) + 1 if oldValue ~= newValue then --说明当时勾选了跳过,检查时间是否为同一天 return false, oldValue --如果大于0,说明上次的失效了。如果小于0,说明是主动取消了勾选。 else return true, oldValue end end function Equipment_Model.SetSkipStarToggle(state) if state then local timeValue = UTL.Time.OsDateOriginal("%w", UTL.Time.GetServerTimestamp()) + 1 PersistentData.PlayerData:Set(EquipmentStarToggleKey, timeValue, true) else PersistentData.PlayerData:Set(EquipmentStarToggleKey, -1, true) end end function Equipment_Model.GetSkipStarToggle() local oldValue = PersistentData.PlayerData:Get(EquipmentStarToggleKey,0) local newValue = UTL.Time.OsDateOriginal("%w", UTL.Time.GetServerTimestamp()) + 1 if oldValue ~= newValue then return false, oldValue else return true, oldValue end end function Equipment_Model.IsEquipTypeUnlock(equipType) return private.equipTypeUnlock[equipType] end --获取穿戴装备的武将信息,传装备唯一id function Equipment_Model.GetEquipHeroInfo(equipServerID) if not private.formationEquipToHeroId[equipServerID] or not private.equipmentInfoDic[equipServerID] then return nil end local heroInfo = MDL.HeroSelect.GetHeroInfo(private.formationEquipToHeroId[equipServerID]) local clientEquip = private.equipmentInfoDic[equipServerID] if not string.isNilOrEmpty(heroInfo.equipInfos[clientEquip.EquipData.EquipType].Id) then return heroInfo, heroInfo.equipInfos[clientEquip.EquipData.EquipType].level end return nil end function Equipment_Model.GetEquipHeroId(equipServerID) local info, lev = Equipment_Model.GetEquipHeroInfo(equipServerID) if info ~= nil then return info.heroId end return nil end --获取穿戴装备的武将信息,传装备唯一id function Equipment_Model.GetEquipStrengthenData(equipServerID) local heroInfo, lev = Equipment_Model.GetEquipHeroInfo(equipServerID) if heroInfo == nil then return nil end if lev > 0 then local equipInfo = private.equipmentInfoDic[equipServerID] return DataSheetManager.EquipEnhance:GetDataByID_EnhanceLevel(equipInfo.EquipData.EquipType, lev) end end --获取装备数量 function Equipment_Model.GetEquipNumByItemId(itemID) local num = 0 for _,info in pairs(private.equipmentInfoDic) do if info.ItemData.ID == itemID then num = num + 1 end end return num end function Equipment_Model.OneKeyEquipStarLevelUpReq(heroId, equipList) local msg = NetManager.GetPB("equip_pb").EquipStarLevelUpReq() for _, data in ipairs(equipList) do if data.times > 0 then local enhanceInfo = NetManager.GetPB("equip_pb").EquipEnhanceInfo() local equipData = DataSheetManager.EquipData:GetDataByID(data.CfgId) enhanceInfo.equipType = equipData.EquipType enhanceInfo.times = data.times table.insert(msg.equipEnhanceInfo, enhanceInfo) end end if #msg.equipEnhanceInfo == 0 then CTL.Tips.AddTipsMsg(Const_IDS.IDS_Equip_Enchance_CoinNotEnough) return end msg.heroId = heroId msg.isOneKey = true NetManager.SendMessage(MessageEnums.MessageEquipStarLevelUp, msg) end function Equipment_Model.EquipStarLevelUpReq(equipInfo) local msg = NetManager.GetPB("equip_pb").EquipStarLevelUpReq() local heroId = Equipment_Model.GetEquipHeroId(equipInfo.ID) if heroId == nil then return end msg.heroId = heroId local enhanceInfo = NetManager.GetPB("equip_pb").EquipEnhanceInfo() enhanceInfo.equipType = equipInfo.EquipData.EquipType enhanceInfo.times = 1 table.insert(msg.equipEnhanceInfo, enhanceInfo) msg.isOneKey = false NetManager.SendMessage(MessageEnums.MessageEquipStarLevelUp, msg) end function Equipment_Model.EquipStarSkillOptReq(opt, heroId, isLock) local msg = NetManager.GetPB("equip_pb").EquipStarSkillOptReq() msg.opt = opt msg.heroId = heroId msg.isLock = isLock or false NetManager.SendMessage(MessageEnums.MessageEquipStarSkillOpt, msg) end function Equipment_Model.GetHeroStageAndStar(heroId) local heroInfo = MDL.HeroSelect.GetHeroInfo(heroId) local minStage, minStar for i, v in ipairs(heroInfo.equipInfos) do if minStage == nil then minStage = v.starStage minStar = v.starNum else if minStage > v.starStage or (minStage == v.starStage and minStar > v.starNum) then minStage = v.starStage minStar = v.starNum end end end return minStage, minStar end function Equipment_Model.GetEquipStarInfo(equipServerID) local heroList = MDL.HeroSelect.GetHasHeroList() local starStage, starNum, starLevel = 0, 0, 0 for _, heroInfo in ipairs(heroList) do if heroInfo.equipInfos and #heroInfo.equipInfos > 0 then for i = 1, #heroInfo.equipInfos do if heroInfo.equipInfos[i].Id == equipServerID then starStage = heroInfo.equipInfos[i].starStage starNum = heroInfo.equipInfos[i].starNum end end end end return starStage, starNum end --获取装备的套装件数 function Equipment_Model.GetEquipStarCount(equipServerID) local heroList = MDL.HeroSelect.GetHasHeroList() local equipHeroInfo = nil for _, heroInfo in ipairs(heroList) do if heroInfo.equipInfos and #heroInfo.equipInfos > 0 then for i = 1, #heroInfo.equipInfos do if heroInfo.equipInfos[i].Id == equipServerID then equipHeroInfo = heroInfo break end end end if equipHeroInfo then break end end local dict = private.GetEquipStarCount(equipHeroInfo) return dict[equipServerID] or 0 end function private.SortEquipStar(a, b) if a.starStage == b.starStage then return a.starNum > b.starNum else return a.starStage > b.starStage end end --活动装备套装几件套属性 key 装备id value 几件套 --描述起来比较复杂 就是装备套装几件套 --当7星装备 6 星装备 5星装备 4星装备时 7星装备1件套 6星两件套 4星四件套 3星为0 --简单就是取最大的是至少一件套 如果最大的有两个 曾这两件都是 1件套 2件套都激活 --如果四件一样 则四件 1套 2套 4套都激活 --不足四件的情况也要考虑 Equipment_Model.EquipStarCountType = { None = 0, One = 1, Two = 2, OneAndTwo = 3, Four = 4, FourAndTwo = 5, All = 6, } function private.GetEquipStarCount(heroInfo) local sortList = {} local equipStarDict = {} local EquipStarCountType = Equipment_Model.EquipStarCountType for i, v in ipairs(heroInfo.equipInfos) do if v.starStage > 0 then table.insert(sortList, v) end end if #sortList == 0 then return equipStarDict end table.sort(sortList, private.SortEquipStar) local equipStarDict = {} if #sortList == 1 then equipStarDict[sortList[1].Id] = EquipStarCountType.One return equipStarDict elseif #sortList == 2 then if sortList[1].starStage ~= sortList[2].starStage or sortList[1].starNum ~= sortList[2].starNum then equipStarDict[sortList[1].Id] = EquipStarCountType.One equipStarDict[sortList[2].Id] = EquipStarCountType.Two else equipStarDict[sortList[1].Id] = EquipStarCountType.OneAndTwo equipStarDict[sortList[2].Id] = EquipStarCountType.OneAndTwo end return equipStarDict end local max = sortList[1] local min = sortList[#sortList] local second = nil for i, v in ipairs(sortList) do local isBigger = max.starStage > v.starStage or (max.starStage == v.starStage and max.starNum >= v.starNum) if v.Id ~= max.Id and second == nil and isBigger then second = v end end local listCount = #sortList --如果第一个和最后一个相等 那就是n件一样的 if max.starNum == min.starNum and max.starStage == min.starStage then for i, v in ipairs(sortList) do --如果只有三件装备 套装只有两件 其它 1 2 4正常 if #sortList == 1 then equipStarDict[v.Id] = EquipStarCountType.One elseif #sortList <= 3 then equipStarDict[v.Id] = EquipStarCountType.OneAndTwo else equipStarDict[v.Id] = EquipStarCountType.All end end --如果最大有两件那显示一件套和二件套 elseif max.starNum == second.starNum and max.starStage == second.starStage then equipStarDict[max.Id] = EquipStarCountType.OneAndTwo equipStarDict[second.Id] = EquipStarCountType.OneAndTwo for index=3,#sortList do if #sortList == 3 then equipStarDict[sortList[index].Id] = EquipStarCountType.None else if sortList[index].starNum == min.starNum and sortList[index].starStage == min.starStage then equipStarDict[sortList[index].Id] = EquipStarCountType.Four elseif sortList[index].starNum == second.starNum and sortList[index].starStage == second.starStage then equipStarDict[sortList[index].Id] = EquipStarCountType.OneAndTwo else equipStarDict[sortList[index].Id] = EquipStarCountType.None end end end else equipStarDict[max.Id] = EquipStarCountType.One if min.starNum == second.starNum and min.starStage == second.starStage then equipStarDict[second.Id] = EquipStarCountType.FourAndTwo for index=3,#sortList do if #sortList == 3 then equipStarDict[second.Id] = EquipStarCountType.Two equipStarDict[sortList[index].Id] = EquipStarCountType.Two else equipStarDict[sortList[index].Id] = EquipStarCountType.FourAndTwo equipStarDict[second.Id] = EquipStarCountType.FourAndTwo end end else equipStarDict[second.Id] = EquipStarCountType.Two for index=3,#sortList do if #sortList == 3 then equipStarDict[sortList[index].Id] = EquipStarCountType.None else if sortList[index].starNum == second.starNum and sortList[index].starStage == second.starStage then equipStarDict[sortList[index].Id] = EquipStarCountType.Two elseif sortList[index].starNum == min.starNum and sortList[index].starStage == min.starStage then equipStarDict[sortList[index].Id] = EquipStarCountType.Four else equipStarDict[sortList[index].Id] = EquipStarCountType.None end end end end end return equipStarDict end function private.OnEquipStarLevelUp(msgResp) if msgResp.Resp.Code == 0 then CTL.Sound.PlayGameSound("UI_equipment_02") CTL.Tips.AddTipsMsg(Const_IDS.IDS_EquipStar_Tittle12) EventSystem.Dispatch(EventID.UI_EquipStarLevelUpSuccess) end end function private.OnEquipStarSkillOpt(msgResp) if msgResp.Resp.Code == 0 then if msgResp.opt == NetManager.GetPB("equip_pb").ESLevelUp then CTL.Tips.AddTipsMsg(Const_IDS.IDS_EquipStar_Tittle12) UIManager.OpenView(Const_UI_Lua.UIEnum.UIEquipStarAttrLevelUp, msgResp) elseif msgResp.opt == NetManager.GetPB("equip_pb").ESReplace then CTL.Tips.AddTipsMsg(Const_IDS.IDS_EquipStar_Tips16) UIManager.OpenView(Const_UI_Lua.UIEnum.UIEquipStarAttrLevelUp, msgResp) elseif msgResp.opt == NetManager.GetPB("equip_pb").ESChange then CTL.Tips.AddTipsMsg(Const_IDS.IDS_EquipStar_Tips15) end EventSystem.Dispatch(EventID.UI_EquipStarSkillOpt, msgResp) end end function Equipment_Model.GetWearEquipInfoByEquipServerID(equipServerID) local heroList = MDL.HeroSelect.GetHasHeroList() for _, heroInfo in ipairs(heroList) do if heroInfo.equipInfos and #heroInfo.equipInfos > 0 then for i, equipInfo in ipairs(heroInfo.equipInfos) do if equipInfo.Id == equipServerID then return equipInfo end end end end end function Equipment_Model.EquipStarEquail(heroId) local heroInfo = MDL.HeroSelect.GetHeroInfo(heroId) if #heroInfo.equipInfos == 4 then local starStage, starNum = heroInfo.equipInfos[1].starStage, heroInfo.equipInfos[1].starNum if starStage > 0 then for i, v in ipairs(heroInfo.equipInfos) do if starStage ~= v.starStage or v.starNum ~= starNum then return false end end return true end end return false end function Equipment_Model.GetQuickRefineConfirmFlag() return private.quickRefineConfirmShowFlag end function Equipment_Model.SetQuickRefineConfirmFlag(isShow) private.quickRefineConfirmShowFlag = not isShow end --region 装备套装相关,暂时废弃,先注释掉 --暂时废弃不用,先注释掉 --function Equipment_Model.UpdateIfSuitChange(newHeroInfos) -- if not private.equipRequestHeroId then -- return -- end -- local newSuit = {} -- for i, v in ipairs(newHeroInfos) do -- if v.heroId == private.equipRequestHeroId then -- local oldHeroInfo = MDL.HeroSelect.GetHeroInfo(v.heroId) -- local oldSuitInfo = oldHeroInfo.suitActiveInfo -- local nowSuitInfo = v.suitActiveInfo -- for i, val in ipairs(nowSuitInfo) do -- local nowSuitId = val.suitId -- local nowEquipCount = val.equipCount -- if IsServerDataNotNil(oldSuitInfo) then -- local isNotHas = true -- for index, value in ipairs(oldSuitInfo) do -- if nowSuitId == value.suitId and nowEquipCount == value.equipCount then -- isNotHas = false -- end -- end -- if isNotHas then -- table.insert(newSuit, {suitId = nowSuitId, equipCount = nowEquipCount}) -- end -- isNotHas = true -- else -- table.insert(newSuit, {suitId = nowSuitId, equipCount = nowEquipCount}) -- end -- end -- end -- end -- if #newSuit > 0 then -- --打开显示的界面,传入newSuit -- end -- private.equipRequestHeroId = nil --end -- --function Equipment_Model.GetSuitInfoByHeroId(heroId) -- local heroInfo = MDL.HeroSelect.GetHeroInfo(heroId) -- return heroInfo and heroInfo.suitActiveInfo or nil --end -- --function Equipment_Model.GetSuitIdListByHeroId(heroId) -- local equipInfos = Equipment_Model.GetEquipmentsByHeroId(heroId) -- if equipInfos then -- local activeSuitIdList = {} -- local lockSuitIdList = {} -- for i, v in ipairs(equipInfos) do -- local suitId = v.EquipData.SuitID -- if suitId and suitId > 0 then -- if CTL.Equipment.IsSuitIdActive(heroId, suitId) then -- if not table.containValue(activeSuitIdList, suitId) then -- table.insert(activeSuitIdList, suitId) -- end -- else -- if not table.containValue(lockSuitIdList, suitId) then -- table.insert(lockSuitIdList, suitId) -- end -- end -- end -- end -- if #activeSuitIdList + #lockSuitIdList == 0 then -- return {1} --直接返回最低等的套装ID -- end -- table.sort(activeSuitIdList, private.SortSuitIdList) -- table.sort(lockSuitIdList, private.SortSuitIdList) -- for i, v in ipairs(lockSuitIdList) do -- table.insert(activeSuitIdList, v) -- end -- return activeSuitIdList -- else -- return {1} --直接返回最低等的套装ID -- end --end -- ----SuitID高的在前 --function private.SortSuitIdList(a, b) -- return a > b --end -- --function Equipment_Model.GetEquippedSuitNumBySuitID(heroId, suitId) -- local suitNums = 0 -- local equipInfos = Equipment_Model.GetEquipmentsByHeroId(heroId) -- if equipInfos then -- for i, v in ipairs(equipInfos) do -- if v.EquipData.SuitID == suitId then -- suitNums = suitNums + 1 -- end -- end -- end -- return suitNums --end -- --function Equipment_Model.GetEquipmentsBySuitID(suitId) -- if private.suitEquipmentsIdList[suitId] then -- return private.suitEquipmentsIdList[suitId] -- else -- private.suitEquipmentsIdList[suitId] = {} -- end -- for i, v in DataSheetManager.EquipData:GetEnumerator() do -- if v.SuitID == suitId then -- table.insert(private.suitEquipmentsIdList[suitId], v.ID) -- end -- end -- return private.suitEquipmentsIdList[suitId] --end --endregion return Equipment_Model