local Equipment_Controller = {} local private = {} local EventSystem = require('Event/EventSystem') local ItemIconPath = ConstAssetPathConfig.ItemIconPath Equipment_Controller.EquipActionFlag = { HasEquipped = 0, --已穿戴 Equip = 1, --可穿戴 Replace = 2,--可替换 Refine = 3, --可洗炼 ReplaceRefine = 4, --可替换洗炼 None = 5, CannotEquip = -1, --不可装备(目前只在熔铸系统使用) } local EquipStarTriggerType = { Normal = 1, --正常 CostNotEnough = 2, --物品不够 Unlock = 3, --未解锁 } local GuideDefaultWearType = 1 function Equipment_Controller.OnStartup() EventSystem.Regist(EventID.UI_UpdateEquipmentInfo, private.RefreshFormationEquipRedPoint) EventSystem.Regist(EventID.TeamLevelUpdate, private.RefreshFormationEquipRedPoint) EventSystem.Regist(EventID.AcquireSystemRedAfterUnlock, private.InitServerDataOver) EventSystem.Regist(EventID.UI_UpdateDebrisInfo, Equipment_Controller.RefreshEquipRedPoint) --金钱 CTL.Currency.RegisteEventByCurrencyType(MDL.Currency.CurrencyType.SilverCoin, private.RefreshFormationEquipRedPoint) --强化石 18 CTL.Currency.RegisteEventByCurrencyType(18, private.RefreshFormationEquipRedPoint) --升星石 CTL.Currency.RegisteEventByCurrencyType(155, private.RefreshFormationEquipRedPoint) --星技石 CTL.Currency.RegisteEventByCurrencyType(156, private.RefreshFormationEquipRedPoint) end function private.InitServerDataOver() MDL.Equipment.OnInitServerDataOver() private.RefreshFormationEquipRedPoint() Equipment_Controller.RefreshEquipRedPoint() end --打开装备主界面 function Equipment_Controller.OpenEquipMainPanel(mainIndex, subIndex) local context = nil if mainIndex then context = { MainTabType = mainIndex, EquipTabType = subIndex } end UIManager.OpenView(Const_UI_Lua.UIEnum.UIEquipmentMain, context) end --默认选中第一个上阵武将的第一个装备 function Equipment_Controller.OpenDetailByDetailType(detailType) local heroId = MDL.Formation.GetSlotHeroIdByIndex(1) local equipInfo = MDL.Equipment.GetFirstEquipInfoByHeroId(heroId) if equipInfo then Equipment_Controller.OpenDetailByEquipInfo(equipInfo, detailType) else Equipment_Controller.OpenDetailByHeroId(heroId, 1, detailType) end end --打开装备界面 --detailType不传 默认选中优先可养成的页签 function Equipment_Controller.OpenDetailByEquipInfo(equipInfo, detailType, isPushOpen) local context = { equipInfo = equipInfo, index = detailType, isPushOpen = isPushOpen } if isPushOpen then UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIEquipmentDetail, context) else UIManager.OpenView(Const_UI_Lua.UIEnum.UIEquipmentDetail, context) end end function Equipment_Controller.OpenDetailByHeroId(heroId, equipType, detailType, isPushOpen) local context = { heroId = heroId, equipType = equipType, index = detailType, isPushOpen = isPushOpen } if isPushOpen then UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIEquipmentDetail, context) else UIManager.OpenView(Const_UI_Lua.UIEnum.UIEquipmentDetail, context) end end --打开洗炼界面 function Equipment_Controller.OpenRefinePopUp(equippedEquipInfo, tarEquipInfo) UIManager.OpenView(Const_UI_Lua.UIEnum.UIEquipmentRefinePopUp, { equippedEquipInfo = equippedEquipInfo, tarEquipInfo = tarEquipInfo }) end --打开tips界面 function Equipment_Controller.OpenBagTips(heroId, equipType, tarEquipInfo, equippedEquipInfo) UIManager.OpenView(Const_UI_Lua.UIEnum.UIEquipmentBagTips, { heroId = heroId, equipType = equipType, tarEquipInfo = tarEquipInfo, equippedEquipInfo = equippedEquipInfo }) end --一键强化 function Equipment_Controller.OpenEquipQuickStrengthen(equipInfoList) if equipInfoList and #equipInfoList > 0 then local lv = MDL.Player.GetRoleInfo() for i = #equipInfoList, 1, -1 do local heroInfo, strengthLv = MDL.Equipment.GetEquipHeroInfo(equipInfoList[i].ID) if strengthLv >= lv then --达到等级上限移除 table.remove(equipInfoList,i) else local nextConfig = DataSheetManager.EquipEnhance:GetDataByID_EnhanceLevel(equipInfoList[i].EquipData.EquipType, strengthLv + 1) if nextConfig == nil then --达到满级移除 table.remove(equipInfoList,i) end end end if #equipInfoList > 0 then local isCanEnhance = false for i, v in ipairs(equipInfoList) do local heroInfo, strengthLv = MDL.Equipment.GetEquipHeroInfo(equipInfoList[i].ID) if Equipment_Controller.IsStrengthItemEnough(v.EquipData.EquipType, strengthLv + 1) then isCanEnhance = true break end end if isCanEnhance then if MDL.Equipment.GetSkipHintToggle() then local heroInfo, strengthLv = MDL.Equipment.GetEquipHeroInfo(equipInfoList[1].ID) MDL.Equipment.QuickStrengthenEquipRequest(heroInfo.heroId, CTL.Equipment.GetEquipmentStrengthDirAndCost(equipInfoList)) else local context = { equipInfos = equipInfoList } UIManager.OpenView(Const_UI_Lua.UIEnum.UIEquipmentQuickStrengthen, context) end else CTL.Tips.AddTipsMsg(Const_IDS["IDS_Equip_Enchance_CoinNotEnough"]) end else CTL.Tips.AddTipsMsg(Const_IDS["IDS_Equip_Enchance_CanNotPassTeamLevel"]) end end end --引导用:自动给第一个上阵武将穿戴装备 function Equipment_Controller.GuideWearEquip() local unEquipID = nil --是否有剩余未穿戴的装备 for k,v in pairs(MDL.Equipment.GetEquipmentInfoDic()) do if v.EquipData.EquipType == GuideDefaultWearType then if MDL.Equipment.GetEquipHeroInfo(k) == nil then unEquipID = k break end end end if unEquipID then local lineUpIds = MDL.Formation.GetSlotHeroIds() local heroId = lineUpIds[1] if not Equipment_Controller.IsHeroEquipType(heroId, GuideDefaultWearType) then --第一个武将该部位是否未穿戴 MDL.Equipment.WearEquipRequest(heroId, GuideDefaultWearType, unEquipID) return true end end return false end --equipInfo[EquipData,ID] --isRefine:是否加上洗炼 --isStrength:是否加上强化等级 function Equipment_Controller.GetEquipAttr(equipInfo, isRefine, isStrength) local attrList if (equipInfo.EquipData ~= nil) then attrList = {} for i = 1, #equipInfo.EquipData.Attr_Table do --这里的attrTable防止外部修改,修改到源数据,新建个table local attr = { AttrType = equipInfo.EquipData.Attr_Table[i].AttrType, AttrNum = equipInfo.EquipData.Attr_Table[i].AttrNum } attrList[i] = attr end if isStrength then local strengthenData = MDL.Equipment.GetEquipStrengthenData(equipInfo.ID) if strengthenData then UTL.Attr.CombineAttr(attrList, strengthenData.Attr_Table) end end if isRefine then if equipInfo.RefineAttrs then UTL.Attr.CombineAttr(attrList, equipInfo.RefineAttrs) end end end return attrList end --显示装备/底图 function Equipment_Controller.SetEquipShow(img_equip, img_quality, itemData) UIUtils.SetImageByAssetBundle(img_equip, string.format(ItemIconPath, itemData.Icon)) if img_quality then UTL.Color.SetQualityImageByType(img_quality,itemData.Color, UTL.Color.QualityType.EquipFragmentBase) end end -- 阵容, 阵容弹窗界面显示装备/底图 function Equipment_Controller.SetUIFormationEquipShow(img_equip, img_quality, itemData) UIUtils.SetImageByAssetBundle(img_equip, string.format(ItemIconPath, itemData.Icon)) if img_quality then UTL.Color.SetQualityImageByType(img_quality,itemData.Color, UTL.Color.QualityType.FormationHorseTreasureEquipBg) end end --返回装备的穿戴等级,等级不足标红 function Equipment_Controller.GetEquipLevel(equipData) local teamLevel = MDL.Player.GetRoleInfo() local equipLev = UTL.Item.GetNobilityByTeamLevel(equipData.EquipLevel) -- 爵位转换 local result = teamLevel >= equipData.EquipLevel and equipLev or UTL.Color.FormatRedColor(equipLev) return result end function Equipment_Controller.StrengthenEquip(equipInfo) if equipInfo == nil then return end local playerLv = MDL.Player.GetRoleInfo() local heroInfo, strengthLv = MDL.Equipment.GetEquipHeroInfo(equipInfo.ID) if heroInfo == nil then return end if playerLv <= strengthLv then --超过上限 CTL.Tips.AddTipsMsg(Const_IDS["IDS_Equip_Enchance_CanNotPassTeamLevel"]) else local strengthData = DataSheetManager.EquipEnhance:GetDataByID_EnhanceLevel(equipInfo.EquipData.EquipType, strengthLv + 1) if strengthData then if Equipment_Controller.IsStrengthItemEnough(equipInfo.EquipData.EquipType, strengthLv + 1) then MDL.Equipment.StrengthenEquipRequest(equipInfo) else CTL.Tips.AddTipsMsg(Const_IDS["IDS_Equip_Enchance_CoinNotEnough"]) end else --满级 CTL.Tips.AddTipsMsg(Const_IDS["IDS_Equip_Enchance_MaxLevel"]) end end end --获取身上穿戴装备的武将数 function Equipment_Controller.GetEquippedHeroNum() local heroNum = 0 local lineUpIds = MDL.Player.GetHeroLinUpIds() for i = 1, #lineUpIds do if Equipment_Controller.IsHeroEquip(lineUpIds[i]) then heroNum = heroNum + 1 end end return heroNum end --上阵武将是否穿戴某个类型装备 function Equipment_Controller.IsHeroEquipType(heroId,equipType) local heroInfo = MDL.HeroSelect.GetHeroInfo(heroId) if heroInfo then if heroInfo.equipInfos and #heroInfo.equipInfos > 0 then for j = 1, #heroInfo.equipInfos do if heroInfo.equipInfos[j].Id~="" then local equipInfo = MDL.Equipment.GetEquipmentInfoByID(heroInfo.equipInfos[j].Id) if equipInfo and equipInfo.EquipData.EquipType == equipType then return true end end end end end return false end --上阵武将是否有穿戴装备 function Equipment_Controller.IsHeroEquip(heroId) local heroInfo = MDL.HeroSelect.GetHeroInfo(heroId) if heroInfo then if heroInfo.equipInfos and #heroInfo.equipInfos > 0 then for j = 1, #heroInfo.equipInfos do if heroInfo.equipInfos[j].Id~="" then return true end end end end return false end --region 装备红点 --刷新总阵容装备红点 function private.RefreshFormationEquipRedPoint() CTL.RedPoint.AddOneRedPointFunc(private.RealRefreshFormationEquipRedPoint) end function private.RealRefreshFormationEquipRedPoint() local isFormationRed = private.CheckFormationEquipIfRed() if isFormationRed then CTL.RedPoint.AddRedPoint(CTL.RedPoint.RedPointKey.Formation_Equipment) else CTL.RedPoint.RemoveRedPoint(CTL.RedPoint.RedPointKey.Formation_Equipment) end end --刷新装备红点 function Equipment_Controller.RefreshEquipRedPoint() local debrisInfoDir = MDL.Equipment.GetDebrisInfoDic() if debrisInfoDir then local isEquipRed = Equipment_Controller.CheckEquipIfRed() if isEquipRed then CTL.RedPoint.AddRedPoint(CTL.RedPoint.RedPointKey.Equipment_Debris) else CTL.RedPoint.RemoveRedPoint(CTL.RedPoint.RedPointKey.Equipment_Debris) end end end --总阵容红点:装备(穿戴、替换、强化、洗炼) function private.CheckFormationEquipIfRed() local lineUpIDs = MDL.Formation.GetSlotHeroIds() for i = 1, #lineUpIDs do local heroId = lineUpIDs[i] if Equipment_Controller.CheckFormationEquipIfRedByHeroId(heroId) then return true end end return false end function Equipment_Controller.CheckFormationEquipIfRedByHeroId(heroId) --穿戴/替换红点 local heroInfo = MDL.HeroSelect.GetHeroInfo(heroId) if not heroInfo then return false end for index, formationEquip in ipairs(heroInfo.equipInfos) do if not string.isNilOrEmpty(formationEquip.Id) then local bagFormationEquip = MDL.Equipment.GetEquipmentInfoByID(formationEquip.Id) if Equipment_Controller.CheckHasBetterBetterEquip(formationEquip, index) then return true end if Equipment_Controller.CheckEquipIfStrength(bagFormationEquip) then return true end if Equipment_Controller.CheckIfRefine(bagFormationEquip) then return true end if Equipment_Controller.CheckEquipIfLevelUp(bagFormationEquip) then return true end end end return false end --装备界面红点:合成 function Equipment_Controller.CheckEquipIfRed() --合成红点 if not MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.Equipment) then return false end local debrisInfoDir = MDL.Equipment.GetDebrisInfoDic() if debrisInfoDir then for _, debrisInfo in pairs(debrisInfoDir) do if Equipment_Controller.CheckDebrisIfRed(debrisInfo) then return true end end end return false end --空装备可穿戴、高品质装备可替换 --needReturn true:需要返回部位列表 false:返回是否有红点 --equipTypeTab k:equipType v:equipInfo function Equipment_Controller.CheckEquipIfWear(heroId) if not MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.Equipment) then return false end local heroInfo = MDL.HeroSelect.GetHeroInfo(heroId) if heroInfo then for i = 1, 4 do local isRed = Equipment_Controller.CheckHasBetterBetterEquip(heroInfo.equipInfos[i], i) if isRed then return true end end end return false end --判断是否有更好的装备,一种是身上没有穿戴装备,包里有更好的,一种是包里有比身上更好的 function Equipment_Controller.CheckHasBetterBetterEquip(formationEquipInfo, equipType) local isRed = false if not string.isNilOrEmpty(formationEquipInfo.Id) then local bagEquipInfo = MDL.Equipment.GetEquipmentInfoByID(formationEquipInfo.Id) for __, v in ipairs(MDL.Equipment.GetEquipmentListByType(equipType)) do if private.CheckIfReplaceByInfo(bagEquipInfo, v) then isRed = true break end end elseif Equipment_Controller.CheckIfEquipTypeUnlock(equipType) then for __, v in ipairs(MDL.Equipment.GetEquipmentListByType(equipType)) do if not MDL.Equipment.GetEquipHeroId(v.ID) then if Equipment_Controller.CheckIfCanEquip(equipType, v, false) then isRed = true break end end end end return isRed end --判断装备部位是否解锁 function Equipment_Controller.CheckIfEquipTypeUnlock(equipType) local isUnlock = MDL.Equipment.IsEquipTypeUnlock(equipType) if isUnlock then return true end local config = DataSheetManager.EquipType:GetDataByID(equipType) if config then for _, v in pairs(config.Unlock_Table) do local tmpIsUnlock , tmpContent = MDL.Unlock.IsComplete(v.UnlockCondition, v.UnlockConditionParam, "IDS_Equip_OpenConditionTip") if tmpIsUnlock == false then return false, tmpContent end end end return true end --装备可强化 function Equipment_Controller.CheckEquipIfStrength(equipInfo) if not MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.Equipment) then return false end if not Equipment_Controller.CheckIfEquipTypeUnlock(equipInfo.EquipData.EquipType) then return false end local heroInfo, strengthLv = MDL.Equipment.GetEquipHeroInfo(equipInfo.ID) if heroInfo then local playerLv = MDL.Player.GetRoleInfo() if strengthLv < playerLv then --不超过等级上限 return Equipment_Controller.IsStrengthItemEnough(equipInfo.EquipData.EquipType, strengthLv + 1) end end return false end function Equipment_Controller.IsStrengthItemEnough(equipType, strengthLv) local strengthData = DataSheetManager.EquipEnhance:GetDataByID_EnhanceLevel(equipType, strengthLv) if strengthData then return private.IsItemTableEnough(strengthData.Item_Table) end return false end function Equipment_Controller.CheckEquipIfStrengthByHeroID(heroId) if not MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.Equipment) then return false end local heroInfo = MDL.HeroSelect.GetHeroInfo(heroId) if heroInfo then for _, v in ipairs(heroInfo.equipInfos) do local equipInfo = MDL.Equipment.GetEquipmentInfoByID(v.Id) if equipInfo and Equipment_Controller.CheckEquipIfStrength(equipInfo) then return true end end end return false end function Equipment_Controller.CheckEquipIfRefineByHeroID(heroId) if not MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.Equipment) then return false end local heroInfo = MDL.HeroSelect.GetHeroInfo(heroId) if heroInfo then for _, v in ipairs(heroInfo.equipInfos) do local equipInfo = MDL.Equipment.GetEquipmentInfoByID(v.Id) if equipInfo and Equipment_Controller.CheckIfRefine(equipInfo) then return true end end end return false end --碎片可合成 function Equipment_Controller.CheckDebrisIfRed(debrisInfo) if not MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.Equipment) then return false end if debrisInfo then return debrisInfo.Num >= debrisInfo.EquipData.ItemNum end return false end function Equipment_Controller.GetCombineRedTypeTab() if not MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.Equipment) then return nil end local debrisInfoDir = MDL.Equipment.GetDebrisInfoDic() if debrisInfoDir then local redTypeTab = {} for _, debrisInfo in pairs(debrisInfoDir) do if Equipment_Controller.CheckDebrisIfRed(debrisInfo) then redTypeTab[debrisInfo.EquipData.EquipType] = true end end return redTypeTab end return nil end local OneClickEnhancement = DataSheetManager.ConstData:GetDataByID("OneClickEnhancement").IntValue function private.IsItemTableEnough(itemTable) for i, v in ipairs(itemTable) do local itemId = v.ItemID local itemNum = v.ItemNum local count = MDL.Currency.IsMoneyTypeByItemID(itemId) and MDL.Currency.GetMoneyCount(itemId) or MDL.Bag.GetItemCount(itemId) if count < itemNum then return false end end return true end function private.CombineItemTable(tableA, tableB) local dict = {} local list = {} if tableA then for i, v in ipairs(tableA) do dict[v.ItemID] = v.ItemNum end end if tableB then for i, v in ipairs(tableB) do local itemId = v.ItemID local itemNum = v.ItemNum dict[itemId] = dict[itemId] and (dict[itemId] + itemNum) or itemNum end end for id, num in pairs(dict) do table.insert(list, {ItemID = id, ItemNum = num}) end return list end function Equipment_Controller.GetEquipmentStrengthDirAndCost(equipInfos) local equipList = {} --预先处理一下原数据,只复制出来必要部分(不能直接修改原数据) for i, v in ipairs(equipInfos) do local heroInfo, lev = MDL.Equipment.GetEquipHeroInfo(v.ID) equipList[equipInfos[i].EquipData.ID] = heroInfo ~= nil and lev or 0 end local strengthList = {} local needItemTable = nil local teamLevel = MDL.Player.GetRoleInfo() while (needItemTable == nil or private.IsItemTableEnough(needItemTable)) do --用数组的原因是因为,有可能会出现同等级,但是某个装备没办法强化,而其他可以的情况 local lowCostEquipId = {} local lowStrengthLv = 0 --遍历装备,找到符合条件的最低等级的装备ID for equipId, curStrengthLv in pairs(equipList) do local times = strengthList[equipId] or 0 --不超过等级上限且不超过战队等级 if not ((times + 1) > OneClickEnhancement or (curStrengthLv + times + 1) > teamLevel) then --比较目前最低的等级(现等级+已经记录好一会要升级的等级数+1) if lowStrengthLv == 0 or (lowStrengthLv > 0 and lowStrengthLv > (curStrengthLv + times + 1)) then lowStrengthLv = curStrengthLv + times + 1 lowCostEquipId[1] = equipId else --如果不属于上边的情况,判断是否是一样的,一样的则加入表中 if lowStrengthLv == curStrengthLv + times + 1 then lowCostEquipId[#lowCostEquipId + 1] = equipId end end end end --四个装备里没有可以强化的了,退出循环 if #lowCostEquipId == 0 and lowStrengthLv == 0 then break end --遍历等级最低的几个装备 for i, v in ipairs(lowCostEquipId) do local equipData = DataSheetManager.EquipData:GetDataByID(v) local costTable = DataSheetManager.EquipEnhance:GetDataByID_EnhanceLevel(equipData.EquipType, lowStrengthLv).Item_Table local tempTotal = private.CombineItemTable(needItemTable, costTable) if private.IsItemTableEnough(tempTotal) then --如果有一个可以强化的,就直接记录,并跳出这个循环,进入下一次寻找 needItemTable = tempTotal strengthList[v] = strengthList[v] and strengthList[v] + 1 or 1 break else --如果该装备在此(最低)等级的时候都无法强化,默认这个装备的强化等级已经到头了,就从equipList删除该装备,不再考虑 equipList[v] = nil end end --如果equipList为空,则直接跳出循环即可 if next(equipList) == nil then break end end return strengthList, needItemTable end --endregion function Equipment_Controller.CheckTypeRedByHeroID(detailType,heroId) if detailType == MDL.Equipment.DetailType.Base then return CTL.Equipment.CheckEquipIfWear(heroId) or CTL.Equipment.CheckEquipIfRefineByHeroID(heroId) elseif detailType == MDL.Equipment.DetailType.Strengthen then return CTL.Equipment.CheckEquipIfStrengthByHeroID(heroId) elseif detailType == MDL.Equipment.DetailType.Compose then return MDL.GemCompose.QuickEquipGemInfoByHero(heroId) or MDL.GemCompose.RedpointEquipGemInfoByHero(heroId) elseif detailType == MDL.Equipment.DetailType.Star then return CTL.Equipment.EquipStarHasRed(heroId) end end --红点:装备是否可洗炼 function Equipment_Controller.CheckIfRefine(equipInfo) --先判断材料是否满足 local itemId = equipInfo.EquipData.RefineItem local itemNum = equipInfo.EquipData.RefineItemNum if MDL.Currency.IsMoneyEnough(itemId, itemNum) == false then return false end local equipId = equipInfo.ID for id, v in ipairs(MDL.Equipment.GetEquipmentListByType(equipInfo.EquipData.EquipType)) do if equipId ~= id and Equipment_Controller.CheckIfRefineByInfo(equipInfo, v) then return true end end return false end --是否有空属性词条 function Equipment_Controller.GetIfRefineAttrEmpty(equipInfo) local maxNum = equipInfo.EquipData.MaxRefineNum local curNum = equipInfo.RefineAttrs and #equipInfo.RefineAttrs or 0 return maxNum > curNum end function private.CommonCheckRefineRule(equipInfo, compareInfo) if equipInfo.ID == compareInfo.ID then return false end if Equipment_Controller.CheckIfEquipTypeUnlock(equipInfo.EquipData.EquipType) == false then return false end if equipInfo.EquipData.EquipType ~= compareInfo.EquipData.EquipType then return false end if equipInfo.EquipData.MaxRefineNum == 0 or compareInfo.EquipData.MaxRefineNum == 0 then return false end if Equipment_Controller.CheckIfLevelFit(compareInfo) == false then return false end local heroId = MDL.Equipment.GetEquipHeroId(compareInfo.ID) if heroId then return false end local bagRefineAttr = compareInfo.RefineAttrs if bagRefineAttr == nil or #bagRefineAttr == 0 then return false end return true end --是否可洗炼 function Equipment_Controller.CheckIfRefineByInfo(equipInfo, compareInfo) if private.CommonCheckRefineRule(equipInfo, compareInfo) == false then return false end local equipRefineAttr = equipInfo.RefineAttrs if equipRefineAttr == nil then --身上一条洗炼属性都没有 return true end --region 存在相同属性且属性值较高 local bagRefineAttr = compareInfo.RefineAttrs for _, bagRefine in ipairs(bagRefineAttr) do for __, equipRefine in ipairs(equipRefineAttr) do if bagRefine.AttrType == equipRefine.AttrType and bagRefine.AttrNum > equipRefine.AttrNum then return true end end end --endregion --region 身上有空属性且被洗炼装备有其他属性 local isEmpty = Equipment_Controller.GetIfRefineAttrEmpty(equipInfo) if isEmpty == false then return false end for _, bagRefine in ipairs(bagRefineAttr) do local hasExtra = true for __, equipRefine in ipairs(equipRefineAttr) do if bagRefine.AttrType == equipRefine.AttrType then hasExtra = false break end end if hasExtra then return true end end --endregion return false end --是否可替换洗炼:被洗炼装备是否存在预洗炼装备的洗炼属性额外的洗炼属性,需要注意是否有重复属性 function Equipment_Controller.CheckIfReplaceRefineByInfo(equipInfo, compareInfo) if private.CommonCheckRefineRule(equipInfo, compareInfo) == false then return false end local equipRefineAttr = equipInfo.RefineAttrs if equipRefineAttr ~= nil then local bagRefineAttr = compareInfo.RefineAttrs for _, bagRefine in ipairs(bagRefineAttr) do local hasExtra = true for __, equipRefine in ipairs(equipRefineAttr) do if bagRefine.AttrType == equipRefine.AttrType then hasExtra = false break end end if hasExtra then return true end end end return false end function Equipment_Controller.CheckIfCanEquip(equipType, compareInfo, checkUnlock) if checkUnlock and Equipment_Controller.CheckIfEquipTypeUnlock(equipType) == false then return false end if equipType ~= compareInfo.EquipData.EquipType then return false end return Equipment_Controller.CheckIfLevelFit(compareInfo) end --判断等级是否满足 function Equipment_Controller.CheckIfLevelFit(equipInfo) local teamLevel = MDL.Player.GetRoleInfo() if teamLevel < equipInfo.EquipData.EquipLevel then return false end return true end --是否可替换:战队等级满足且基础属性比当前已穿戴装备高的 function private.CheckIfReplaceByInfo(equipInfo, compareInfo) if equipInfo.ID == compareInfo.ID then return false end local heroId = MDL.Equipment.GetEquipHeroId(compareInfo.ID) if heroId then return false end if Equipment_Controller.CheckIfCanEquip(equipInfo.EquipData.EquipType, compareInfo, true) == false then return false end return compareInfo.BaseEquipmentFight>equipInfo.BaseEquipmentFight end function Equipment_Controller.UpdateSpecificTypeEquipList(equipInfo, equipType, equipInfos) table.clearArray(equipInfos) for id, info in ipairs(MDL.Equipment.GetEquipmentListByType(equipType)) do info.ActionFlag = nil if equipInfo then if equipInfo.ID ~= id then local heroId = MDL.Equipment.GetEquipHeroId(info.ID) if heroId then --已穿戴 info.ActionFlag = Equipment_Controller.EquipActionFlag.HasEquipped table.insert(equipInfos,info) elseif private.CheckIfReplaceByInfo(equipInfo, info) then --可替换 info.ActionFlag = Equipment_Controller.EquipActionFlag.Replace table.insert(equipInfos,info) elseif Equipment_Controller.CheckIfRefineByInfo(equipInfo, info) then info.ActionFlag = Equipment_Controller.EquipActionFlag.Refine table.insert(equipInfos,info) elseif Equipment_Controller.CheckIfReplaceRefineByInfo(equipInfo, info) then info.ActionFlag = Equipment_Controller.EquipActionFlag.ReplaceRefine table.insert(equipInfos,info) else info.ActionFlag = Equipment_Controller.EquipActionFlag.None table.insert(equipInfos,info) end end else local heroId = MDL.Equipment.GetEquipHeroId(info.ID) if heroId then --已穿戴 info.ActionFlag = Equipment_Controller.EquipActionFlag.HasEquipped table.insert(equipInfos,info) else if Equipment_Controller.CheckIfCanEquip(equipType, info, true) then info.ActionFlag = Equipment_Controller.EquipActionFlag.Equip else info.ActionFlag = Equipment_Controller.EquipActionFlag.None end table.insert(equipInfos,info) end end end end function Equipment_Controller.SetEquipmentIteratorData(sortedEquipInfos, isShowEquipped) private.sortedEquipInfos = sortedEquipInfos private.enumNextIndex = 1 private.isShowEquipped = isShowEquipped end function Equipment_Controller.GetEnumIndex() return private.enumNextIndex end function Equipment_Controller.EnumEquipmentIterator() local data = private.sortedEquipInfos[private.enumNextIndex] if data then private.enumNextIndex = private.enumNextIndex + 1 if private.isShowEquipped or (private.isShowEquipped == false and data.ActionFlag ~= Equipment_Controller.EquipActionFlag.HasEquipped) then return data else return Equipment_Controller.EnumEquipmentIterator() end end return nil end --获取洗炼属性品质 --找不到对应的品质的情况下,需要判断是最低品或者最高品 function Equipment_Controller.GetRefineAttrQuality(refineID, tarAttr) local refineData = DataSheetManager.EquipRefineData:GetDataByRefineID(refineID) local minColor local maxColor for i,v in DataSheetManager.EquipRefineAttrData:GetDataByAttrModeID_Color(refineData.AttrModeID) do if i == 1 then minColor = v.Color maxColor = v.Color elseif v.Color > maxColor then maxColor = v.Color end local attrs = v.Attr_Table for _, attr in ipairs(attrs) do if attr.AttrType == tarAttr.AttrType then if tarAttr.AttrNum >= attr.AttrMinNum and tarAttr.AttrNum <= attr.AttrMaxNum then return v.Color end end end end --是否是最低品 local minData = DataSheetManager.EquipRefineAttrData:GetDataByAttrModeID_Color(refineData.AttrModeID, minColor) for _, attr in ipairs(minData.Attr_Table) do if attr.AttrType == tarAttr.AttrType then if tarAttr.AttrNum < attr.AttrMinNum then return minColor end end end --是否是最高品 local maxData = DataSheetManager.EquipRefineAttrData:GetDataByAttrModeID_Color(refineData.AttrModeID, maxColor) for _, attr in ipairs(maxData.Attr_Table) do if attr.AttrType == tarAttr.AttrType then if tarAttr.AttrNum > attr.AttrMaxNum then return maxColor end end end --找不到,大概率是因为数据表不一致 logging.error(LTAG.ERROR, "GetRefineAttrQuality Fail", refineID, tarAttr) return minColor end --获取该装备(装备类型)的第一个红点页签 function Equipment_Controller.GetFirstRedDetailType(equipInfo, heroId) --Base穿戴、洗炼 if equipInfo == nil then return MDL.Equipment.DetailType.Base end for _, v in ipairs(MDL.Equipment.GetEquipmentListByType(equipInfo.EquipData.EquipType)) do if private.CheckIfReplaceByInfo(equipInfo, v) or Equipment_Controller.CheckIfRefineByInfo(equipInfo, v) then return MDL.Equipment.DetailType.Base end end --Strengthen强化 if Equipment_Controller.CheckEquipIfStrength(equipInfo) then return MDL.Equipment.DetailType.Strengthen end --Compose宝石 local gemRedPoints = MDL.GemCompose.RedpointEquipGemInfoInFunction(heroId) if gemRedPoints[equipInfo.EquipData.EquipType] then return MDL.Equipment.DetailType.Compose end local quickCompose = MDL.GemCompose.QuickEquipGemInfoInFunction(heroId) if quickCompose[equipInfo.EquipData.EquipType] then return MDL.Equipment.DetailType.Compose end --无养成红点,默认第一个 return MDL.Equipment.DetailType.Base end --region --洗练相关-- function Equipment_Controller.UpdateSpecificTypeEquipListForSmelt(equipInfos) table.clearArray(equipInfos) local formationHeroList = MDL.Formation.GetSlotHeroIds() local EquipActionFlag = Equipment_Controller.EquipActionFlag for id, info in pairs(MDL.Equipment.GetEquipmentInfoDic()) do --所有装备 info.SmeltFlag = nil for index, heroId in ipairs(formationHeroList) do --所有上阵英雄 if heroId > 0 then local heroInfo = MDL.HeroSelect.GetHeroInfo(heroId) local equipInfos = heroInfo.equipInfos for i = 1, #equipInfos do --这个上阵英雄的所有装备的信息 if info.EquipData.EquipType == i then --判断同类型 local equippedId = equipInfos[i].Id local equipInfo = MDL.Equipment.GetEquipmentInfoByID(equippedId) if equipInfo then if equippedId == info.ID then --已装备 info.SmeltFlag = EquipActionFlag.HasEquipped break else if private.CheckIfReplaceByInfo(equipInfo, info) then --可替换 info.SmeltFlag = private.ReplaceTypeBySorting(info.SmeltFlag, EquipActionFlag.Replace) elseif Equipment_Controller.CheckIfRefineByInfo(equipInfo, info) then --可洗练 info.SmeltFlag = private.ReplaceTypeBySorting(info.SmeltFlag, EquipActionFlag.Refine) elseif Equipment_Controller.CheckIfReplaceRefineByInfo(equipInfo, info) then --可替换洗练 info.SmeltFlag = private.ReplaceTypeBySorting(info.SmeltFlag, EquipActionFlag.ReplaceRefine) else if Equipment_Controller.CheckIfCanEquip(info.EquipData.EquipType, info, true) then --能穿 info.SmeltFlag = private.ReplaceTypeBySorting(info.SmeltFlag, EquipActionFlag.None) else --不能穿 info.SmeltFlag = private.ReplaceTypeBySorting(info.SmeltFlag, EquipActionFlag.CannotEquip) end end end else local heroId = MDL.Equipment.GetEquipHeroId(info.ID) if heroId then --已穿戴 info.SmeltFlag = EquipActionFlag.HasEquipped break else if Equipment_Controller.CheckIfCanEquip(info.EquipData.EquipType, info, true) then info.SmeltFlag = EquipActionFlag.Equip --可穿戴 else info.SmeltFlag = EquipActionFlag.CannotEquip --不能穿 end end end end end end if info.SmeltFlag == EquipActionFlag.HasEquipped then --已穿戴则不用继续比较,往下走 break end end if info.SmeltFlag ~= EquipActionFlag.HasEquipped then --已穿戴则不加入数组 table.insert(equipInfos, info) end end table.sort(equipInfos, private.SortEquipBySmeltFlag) end function private.ReplaceTypeBySorting(oldType, newType) return (not oldType or newType < oldType) and newType or oldType end function private.SortEquipBySmeltFlag(equipInfoA, equipInfoB) local aFlag = equipInfoA.SmeltFlag local bFlag = equipInfoB.SmeltFlag if aFlag ~= bFlag then return aFlag > bFlag else return private.EquipmentSmeltSortRule(equipInfoA, equipInfoB) end end --装备排序规则:等级>品质>部位>装备战力 function private.EquipmentSmeltSortRule(equipInfo_1, equipInfo_2) 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 end --endregion --region 装备Tips相关 Equipment_Controller.TipsBtnEnum = { Smelt = 1, --熔炼 Equip = 2, --穿戴 Change = 3, --更换 Refine = 4, --洗练 } private.TipsBtnIDS = { [Equipment_Controller.TipsBtnEnum.Equip] = Const_IDS.IDS_Equip_Equiped, [Equipment_Controller.TipsBtnEnum.Change] = Const_IDS.IDS_Equip_Change, [Equipment_Controller.TipsBtnEnum.Refine] = Const_IDS.IDS_EquipRefine_Button, [Equipment_Controller.TipsBtnEnum.Smelt] = Const_IDS.IDS_EquipMelting_Melting_Title, } function Equipment_Controller.GetTipsBtnEnum(selectEquipInfo, equippedEquipInfo) local btnEnumList= {} if equippedEquipInfo then table.insert(btnEnumList, Equipment_Controller.TipsBtnEnum.Change) local isRefine = CTL.Equipment.CheckIfRefineByInfo(equippedEquipInfo, selectEquipInfo) or CTL.Equipment.CheckIfReplaceRefineByInfo(equippedEquipInfo, selectEquipInfo) if isRefine then table.insert(btnEnumList, Equipment_Controller.TipsBtnEnum.Refine) end else if CTL.Equipment.CheckIfLevelFit(selectEquipInfo) then table.insert(btnEnumList, Equipment_Controller.TipsBtnEnum.Equip) end end if not MDL.Equipment.GetEquipHeroId(selectEquipInfo.ID) then table.insert(btnEnumList, Equipment_Controller.TipsBtnEnum.Smelt) end table.sort(btnEnumList, private.SortTipsBtn) return btnEnumList end function Equipment_Controller.GetTipsBtnIds(btnEnum) return private.TipsBtnIDS[btnEnum] end ---数字大的枚举,优先级低,往前排的目的是因为在界面显示的时候,前面的会显示在最上面。优先级显示从下往上依次递减。 function private.SortTipsBtn(tipsBtnEnumA, tipsBtnEnumB) return tipsBtnEnumA > tipsBtnEnumB end --endregion function Equipment_Controller.CanOneKeyEquipStarLevelUp(equipId) local heroId = MDL.Equipment.GetEquipHeroId(equipId) local equipInfoList = MDL.Equipment.GetEquipmentsByHeroId(heroId) if equipInfoList and #equipInfoList > 0 then local list = private.GetStarLevelUpList(equipInfoList) return list and #list > 0 end return false end ---找到等级最低的 加+1 然后循环 function Equipment_Controller.OneKeyEquipStarLevelUp(equipId) local heroId = MDL.Equipment.GetEquipHeroId(equipId) local equipInfoList = MDL.Equipment.GetEquipmentsByHeroId(heroId) if equipInfoList and #equipInfoList > 0 then local list = private.GetStarLevelUpList(equipInfoList) if list and #list > 0 then local isCanEnhance = false for i, v in ipairs(list) do if v.times > 0 then isCanEnhance = true end end if isCanEnhance then if MDL.Equipment.GetSkipStarToggle() then MDL.Equipment.OneKeyEquipStarLevelUpReq(heroId, list) else local context = { equipInfos = list } UIManager.OpenView(Const_UI_Lua.UIEnum.UIEquipStarQuickStrengthen, context) end else for i, v in ipairs(list) do if v.condition == EquipStarTriggerType.CostNotEnough then CTL.Tips.AddTipsMsg(Const_IDS.IDS_EquipStar_Tips11) return end end CTL.Tips.AddTipsMsg(Const_IDS.IDS_EquipStar_Tips11) end else if private.IsUnlockStar(equipInfoList) then CTL.Tips.AddTipsMsg(Const_IDS.IDS_EquipStar_Tips19) else CTL.Tips.AddTipsMsg(Const_IDS["IDS_Equip_Enchance_CoinNotEnough"]) end end else CTL.Tips.AddTipsMsg(Const_IDS["IDS_Equip_Enchance_CanNotPassTeamLevel"]) end end function Equipment_Controller.IsEquipStarItemEnough(starStage, starLevel) local __, data = DataSheetManager.EquipStar:TryGetDataByStarStage_StarLevel(starStage, starLevel) if data then local triggerData = DataSheetManager.TriggerID:GetDataByID(data.TriggerID) return MDL.Unlock.IsTriggerIdComplete(data.TriggerID) and private.IsItemTableEnough(data.item_Table) end 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 function private.OrderlinessStarLevelUpList(equipList, costItemList) for i = 1, #equipList do local firstEquip = equipList[1] local needOrderList = { firstEquip } for _, v in ipairs(equipList) do if firstEquip.Id ~= v.Id and v.willStarStage == firstEquip.willStarStage and v.willStarNum == firstEquip.willStarNum then table.insert(needOrderList, v) elseif v.willStarStage > firstEquip.willStarStage or (v.willStarStage == firstEquip.willStarStage and v.willStarNum > firstEquip.willStarNum) then for _, data in ipairs(needOrderList) do if data.willStarStage == 0 then data.willStarStage = 1 end for i=1,10 do local curStage, curStar = data.willStarStage , data.willStarNum + 1 if curStar > 10 then curStage = data.starStage + 1 curStar = curStar - 10 end if curStage == 0 then curStage = 1 end local curStarData = DataSheetManager.EquipStar:GetDataByStarStage_StarLevel(curStage, curStar) local curEnough = private.TotalEnough(curStarData, costItemList) if curEnough == EquipStarTriggerType.Normal then data.times = data.times + 1 if data.times > 10 then data.times = 10 break end data.willStarStage = curStage data.willStarNum = curStar else return true end if curStage > v.willStarStage or (curStage == v.willStarStage and curStar >= v.willStarNum) then break end end end break end end end return true end function private.IsUnlockStar(equipInfoList) for index, equipInfo in ipairs(equipInfoList) do local wearEquipInfo = MDL.Equipment.GetWearEquipInfoByEquipServerID(equipInfo.ID) local nextStage, nextStar = Equipment_Controller.GetNextStageAndNum(wearEquipInfo.starStage, wearEquipInfo.starNum) local __, nextData = DataSheetManager.EquipStar:TryGetDataByStarStage_StarLevel(nextStage, nextStar) if nextData then local triggerData = DataSheetManager.TriggerID:GetDataByID(nextData.TriggerID) if not private.IsItemTableEnough(nextData.item_Table) then return false end end end return true end function private.GetStarLevelUpList(equipInfoList) local costItemList = {} local equipList = {} for index, equipInfo in ipairs(equipInfoList) do local wearEquipInfo = MDL.Equipment.GetWearEquipInfoByEquipServerID(equipInfo.ID) local nextStage, nextStar = Equipment_Controller.GetNextStageAndNum(wearEquipInfo.starStage, wearEquipInfo.starNum) local __, nextData = DataSheetManager.EquipStar:TryGetDataByStarStage_StarLevel(nextStage, nextStar) if nextData then local levelUpData = {} levelUpData.Id = wearEquipInfo.Id levelUpData.CfgId = wearEquipInfo.CfgId levelUpData.starStage = wearEquipInfo.starStage levelUpData.starNum = wearEquipInfo.starNum levelUpData.willStarStage = wearEquipInfo.starStage levelUpData.willStarNum = wearEquipInfo.starNum levelUpData.times = 0 table.insert(equipList, levelUpData) end end if #equipList == 0 then CTL.Tips.AddTipsMsg(Const_IDS.IDS_EquipStar_Tips9) return end table.sort(equipList, private.SortEquipStar) local isEnough = private.OrderlinessStarLevelUpList(equipList, costItemList) for i, v in ipairs(equipList) do if v.times > 0 then private.RemoveTimes(equipList) return equipList end end if isEnough then for i = 1, 10 do for _, v in ipairs(equipList) do if v.times < 10 then local nextStage, nextStar = Equipment_Controller.GetNextStageAndNum(v.willStarStage, v.willStarNum) local __, nextData = DataSheetManager.EquipStar:TryGetDataByStarStage_StarLevel(nextStage, nextStar) if nextData then local enough = private.TotalEnough(nextData, costItemList) if enough == EquipStarTriggerType.Normal then v.willStarStage = nextStage v.willStarNum = nextStar v.times = v.times + 1 else v.condition = enough private.RemoveTimes(equipList) return equipList end end end end end else CTL.Tips.AddTipsMsg(Const_IDS.IDS_EquipStar_Tips11) end return equipList end function private.RemoveTimes(equipList) for i = #equipList, 1, -1 do if equipList[i].times == 0 then table.remove(equipList, i) end end end function private.TotalEnough(equipStarData, costItemList) if MDL.Unlock.IsTriggerIdComplete(equipStarData.TriggerID) then for j, cost in ipairs(equipStarData.item_Table) do costItemList[cost.ItemID] = costItemList[cost.ItemID] or 0 costItemList[cost.ItemID] = costItemList[cost.ItemID] + cost.ItemNum end local enough = EquipStarTriggerType.Normal for j, costCount in pairs(costItemList) do local hasCount = CTL.Bag.GetHasCountByItemCfgID(j) if hasCount < costCount then enough = EquipStarTriggerType.CostNotEnough end end return enough else return EquipStarTriggerType.Unlock end end function Equipment_Controller.GetNextStageAndNum(starStage, starLevel) if starLevel + 1 > 10 then return starStage + 1, 1 else if starStage == 0 then return 1, 1 else return starStage, starLevel + 1 end end end function Equipment_Controller.CheckEquipIfLevelUp(equipInfo) local wearEquipInfo = MDL.Equipment.GetWearEquipInfoByEquipServerID(equipInfo.ID) local stage, starNum = wearEquipInfo.starStage, wearEquipInfo.starNum local nextStage, nextStarNum = Equipment_Controller.GetNextStageAndNum(stage, starNum) return Equipment_Controller.IsEquipStarItemEnough(nextStage, nextStarNum) end function Equipment_Controller.CheckEquipSkillIfLevelUp(equipInfo, heroId) local stage, starNum = MDL.Equipment.GetHeroStageAndStar(heroId) local _, data = DataSheetManager.EquipStar:TryGetDataByStarStage_StarLevel(stage, starNum) local heroInfo = MDL.HeroSelect.GetHeroInfo(heroId) local libStarLevelData = nil local _, skillLibData = DataSheetManager.EquipSkillLib:TryGetDataByEquipSkillID(heroInfo.equipStarSkillId) if skillLibData then for i, v in DataSheetManager.EquipStarStage:GetEnumerator() do if v.EquipSkillLibID > skillLibData.EquipSkillLibID then libStarLevelData = v break end end if libStarLevelData then if libStarLevelData.StarStage < stage or (libStarLevelData.StarStage == stage and libStarLevelData.LibStarLevel <= starNum) then for i, v in ipairs(libStarLevelData.LibUPCostItemID) do local itemId = v local itemNum = libStarLevelData.LibUPCostItemNum[i] local count = MDL.Currency.IsMoneyTypeByItemID(itemId) and MDL.Currency.GetMoneyCount(itemId) or MDL.Bag.GetItemCount(itemId) if count < itemNum then return false end end return true end end end return false end function Equipment_Controller.EquipStarHasRed(heroId) local heroInfo = MDL.HeroSelect.GetHeroInfo(heroId) if heroInfo then for i, v in ipairs(heroInfo.equipInfos) do if not string.isNilOrEmpty(v.Id) then local nextStage, nextStar = Equipment_Controller.GetNextStageAndNum(v.starStage, v.starNum) local isSuccess, nextData = DataSheetManager.EquipStar:TryGetDataByStarStage_StarLevel(nextStage, nextStar) if isSuccess and MDL.Unlock.IsTriggerIdComplete(nextData.TriggerID) then if Equipment_Controller.IsEquipStarItemEnough(nextStage, nextStar) then return true end end end end end return false end function Equipment_Controller.GetStageRichStr(id, ids) local stageData = DataSheetManager.EquipStarStage:GetDataByStarStage(id) local iconPath = string.split(string.split(stageData.Icon, ConstAssetPathConfig.AssetPath53)[2], ".")[1] local imgTxt = string.format("%s", stageData.LibStarLevel, iconPath) return string.FormatByIdsId(ids, imgTxt) end function Equipment_Controller.GetStageDesc(equipItemId) local equipData = DataSheetManager.EquipData:GetDataByID(equipItemId) local desc = string.FormatByIdsId(Const_IDS.IDS_EquipData_StageShow, UIUtils.GetLocalizedTxt(Const_IDS["IDS_Number_Written_"..equipData.EquipStage])) return desc end function Equipment_Controller.GetStageDescByFragmentId(itemId) for i, v in DataSheetManager.EquipData:GetEnumerator() do if v.ItemID == itemId then local desc = string.FormatByIdsId(Const_IDS.IDS_EquipData_StageShow, UIUtils.GetLocalizedTxt(Const_IDS["IDS_Number_Written_"..v.EquipStage])) return desc end end end function Equipment_Controller.SetEquipmentStage(label, equipItemId, isFragmentId) if isFragmentId then label.text = Equipment_Controller.GetStageDescByFragmentId(equipItemId) else label.text = Equipment_Controller.GetStageDesc(equipItemId) end end return Equipment_Controller