local Treasure_Controller = {} local private = {} local EventSystem = require('Event/EventSystem') local cacheRecommendSoulTypeDic = {} local cacheRecommendSoulType = {} function Treasure_Controller.OnStartup() EventSystem.Regist(EventID.BagItem_Update, private.CheckTreasureRedPoint) EventSystem.Regist(EventID.UI_UpdateTreasureInfo, private.CheckTreasureRedPoint) EventSystem.Regist(EventID.AcquireSystemRedAfterUnlock, private.CheckTreasureRedPoint) EventSystem.Regist(EventID.TreasureSoulCrystal_UpdateBag, private.CheckTreasureRedPoint) private.treasurePreciousCrystalAdd = DataSheetManager.ConstData:GetDataByID("TreasurePreciousCrystalAdd").IntListValue private.treasureSoulPitOpenCondition = DataSheetManager.ConstData:GetDataByID("TreasureSoulPitOpenCondition").IntListValue private.treasureSoulDropAttrConfirm = DataSheetManager.ConstData:GetDataByID("TreasureSoulDropAttrConfirm").IntValue end Treasure_Controller.RelationState = { NoRelation = 0, -- 宝物没有羁绊 NoHero = 1, -- 没有武将 NotActiveRelation = 2, --未激活宝物羁绊 ActiveRelation = 3, -- 已激活宝物羁绊 } function Treasure_Controller.OpenTreasureUI(treasureId) if treasureId then UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UITreasureBasePanel, { treasureId = treasureId, isFormation = false }) return end local treasures = MDL.Treasure.GetTreasureInfoList() local activeTreasure for _, v in pairs (treasures) do activeTreasure = v if v.EquipHeroId then UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UITreasureBasePanel, { treasureId = v.TreasureID, isFormation = false }) return end end if activeTreasure then UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UITreasureBasePanel, { treasureId = activeTreasure.TreasureID, isFormation = false }) else UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UITreasureBasePanel, { treasureId = 1, isFormation = false }) end end function Treasure_Controller.IsTreasureActive(treasureId) return MDL.Treasure.GetTreasureInfo(treasureId) ~= nil end function Treasure_Controller.IfTreasureCanActive(treasureId) local data = DataSheetManager.TreasureData:GetDataByTreasureID(treasureId) if data then if Treasure_Controller.IsTreasureActive(treasureId) then return false end local costItem = data.Item_Table[1] --目前为1个材料 if MDL.Bag.GetItemCount(costItem.ItemID) >= costItem.ItemNum then return true end end return false end function Treasure_Controller.IfHeroHasTreasureToEquip(heroId) local list = MDL.Treasure.GetTreasureInfoList() if list then local info = MDL.Treasure.GetTreasureInfoByHeroId(heroId) if info == nil then for i, v in pairs(list) do if v.EquipHeroId == nil then return true end end end end return false end -- 是否为宝物被动技能最大等级 function Treasure_Controller.IsTreasureSkillMaxLevel(treasureId, treasureSkillId) local count = 0 local curStar = 0 for _, v in DataSheetManager.TreasureStar:GetDataByTreasureID_Star(treasureId) do if v.TreasureSkill ~= treasureSkillId then curStar = curStar + 1 end count = count + 1 end return curStar == count - 1 end function Treasure_Controller.GetBreakSkillDataAndType(treasureId, starLevel) local starData = DataSheetManager.TreasureStar:GetDataByTreasureID_Star(treasureId, starLevel) local starType = starData.StarType if not starType then starData = DataSheetManager.TreasureStar:GetDataByTreasureID_Star(treasureId, starLevel - 1) starType = starData.StarType end return starData, starType end --获取下一个突破所需的材料 function Treasure_Controller.GetNextBreakItemData(treasureId) local info = MDL.Treasure.GetTreasureInfo(treasureId) if info and info.TreasureInfo then local curStarConfig = DataSheetManager.TreasureStar:GetDataByTreasureID_Star(treasureId, info.TreasureInfo.starLevel) local nextStage = info.TreasureInfo.starStage + 1 if nextStage > #curStarConfig.ItemRepeat then --下一个突破阶段 local isSuccess, nextStarConfig = DataSheetManager.TreasureStar:TryGetDataByTreasureID_Star(treasureId, info.TreasureInfo.starLevel + 1) if isSuccess then return DataSheetManager.TreasureStarItem:GetDataByItemRepeatID(nextStarConfig.ItemRepeat[1]).Item_Table end else return DataSheetManager.TreasureStarItem:GetDataByItemRepeatID(curStarConfig.ItemRepeat[nextStage]).Item_Table end end return nil end function Treasure_Controller.GetAttrItemShow(starConfig, index) local content = "" local attrID = starConfig.AttrRepeat[index] local starAttrData = DataSheetManager.TreasureStarAttr:GetDataByAttrRepeatID(attrID) if starAttrData then --只有1条属性 local attr = starAttrData.Attr_Table[1] local attrName = DataSheetManager.AttrData:GetDataByID(attr.AttrType).Name local attrValue = attr.AttrNum return UIUtils.GetLocalizedTxt(Const_IDS[attrName])..UTL.Color.FormatGreenColor("+"..attrValue) end return content end ---@return string 返回一个包含所有属性的字符串 function Treasure_Controller.GetTreasureBreakAttrText(treasureId, treasureStar) local breakAttrText = "" local starBreakAttrId = DataSheetManager.TreasureStar:GetDataByTreasureID_Star(treasureId, treasureStar).AttrSpecial if starBreakAttrId and starBreakAttrId > 0 then local attrTable = DataSheetManager.TreasureStarAttrSpecial:GetDataByAttrRepeatID(starBreakAttrId).Attr_Table for i, v in ipairs(attrTable) do local attrText = UTL.Attr.GetAttrText(v.AttrType, v.AttrNum) if i == 1 then breakAttrText = attrText else breakAttrText = breakAttrText .. "," .. attrText end end end return breakAttrText end ---@return table 返回属性数组 function Treasure_Controller.GetTreasureBreakAttrTextList(treasureId, treasureStar, NumColor) local starBreakAttrId = DataSheetManager.TreasureStar:GetDataByTreasureID_Star(treasureId, treasureStar).AttrSpecial if starBreakAttrId and starBreakAttrId > 0 then local attrTable = DataSheetManager.TreasureStarAttrSpecial:GetDataByAttrRepeatID(starBreakAttrId).Attr_Table if attrTable and #attrTable > 0 then local breakAttrTextList = {} for i, v in ipairs(attrTable) do local attrText = UTL.Attr.GetAttrText(v.AttrType, v.AttrNum, NumColor) table.insert(breakAttrTextList, attrText) end return breakAttrTextList end end return nil end function Treasure_Controller.IfHasBetterTreasureToEquip(treasureId) local infoList = MDL.Treasure.GetTreasureInfoList() if infoList then local fight = 0 local info = MDL.Treasure.GetTreasureInfo(treasureId) if info and info.EquipHeroId then fight = info.TreasureInfo.gs for i, v in pairs(infoList) do if v.EquipHeroId == nil and v.TreasureInfo.gs > fight then return true end end end end return false end -- 获取宝物当前突破等级下技能数据 function Treasure_Controller.GetTreasureSkillData(treasureID) local activeInfo = MDL.Treasure.GetTreasureInfo(treasureID) local treasureSkillID if activeInfo and activeInfo.TreasureInfo.starLevel > 0 then local treasureInfo = activeInfo.TreasureInfo local treasureStarData = DataSheetManager.TreasureStar:GetDataByTreasureID_Star(treasureID, treasureInfo.starLevel - 1) treasureSkillID = treasureStarData.TreasureSkill else local treasureData = DataSheetManager.TreasureData:GetDataByTreasureID(treasureID) treasureSkillID = treasureData.TreasureSkill end local treasureSkillData = DataSheetManager.TreasureSkillData:GetDataByTreasureSkill(treasureSkillID) return treasureSkillData end --宝物是否可突破 function Treasure_Controller.IfTreasureCanBreak(treasureId) local info = MDL.Treasure.GetTreasureInfo(treasureId) if info then local itemData = Treasure_Controller.GetNextBreakItemData(treasureId) if itemData then local isNotEnough = false for i, v in ipairs(itemData) do local costNum = v.ItemNum local costID = v.ItemID if MDL.Bag.GetItemCount(costID) < costNum then isNotEnough = true break end end if isNotEnough == false then return true end end end return false end function Treasure_Controller.GetTreasureStarLevel(id) local info = MDL.Treasure.GetTreasureInfo(id) if info and info.TreasureInfo then return info.TreasureInfo.starLevel else return 0 end end function private.CheckTreasureRedPoint() CTL.RedPoint.AddOneRedPointFunc(private.RealCheckTreasureRedPoint) end function private.RealCheckTreasureRedPoint() private.CheckTreasureTownRedPoint() private.CheckFormationTreasureRedPoint() end ---宝物红点 function private.CheckTreasureTownRedPoint() local isRed = false if MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.Treasure) then for i, v in DataSheetManager.TreasureData:GetEnumerator() do if Treasure_Controller.IfTreasureCanActive(v.TreasureID) then --激活红点 isRed = true break end if Treasure_Controller.IfTreasureCanBreak(v.TreasureID) then --突破红点 isRed = true break end if Treasure_Controller.IfTreasureCanSoulPanel(v.TreasureID) then -- 魂晶红点 isRed = true end end end if isRed then CTL.RedPoint.AddRedPoint(CTL.RedPoint.RedPointKey.Treasure) else CTL.RedPoint.RemoveRedPoint(CTL.RedPoint.RedPointKey.Treasure) end end function private.CheckFormationTreasureRedPoint() if MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.Treasure) then local isRed = false local slotIds = MDL.Formation.GetSlotHeroIds() for i = 1, #slotIds do if MDL.HeroSelect.IsHasHero(slotIds[i]) and Treasure_Controller.CheckHeroTreasureRedPoint(slotIds[i]) then isRed = true break end end if isRed then CTL.RedPoint.AddRedPoint(CTL.RedPoint.RedPointKey.Formation_Treasure) else CTL.RedPoint.RemoveRedPoint(CTL.RedPoint.RedPointKey.Formation_Treasure) end else CTL.RedPoint.RemoveRedPoint(CTL.RedPoint.RedPointKey.Formation_Treasure) end end function Treasure_Controller.CheckHeroTreasureRedPoint(heroId) local treasureInfo = MDL.Treasure.GetTreasureInfoByHeroId(heroId) if treasureInfo then if Treasure_Controller.IfHasBetterTreasureToEquip(treasureInfo.TreasureID) then --替换红点 return true end if Treasure_Controller.IfTreasureCanBreak(treasureInfo.TreasureID) then --激活红点 return true end if Treasure_Controller.IfTreasureCanSoulPanel(treasureInfo.TreasureID) then -- 魂晶红点 return true end else return Treasure_Controller.IfHeroHasTreasureToEquip(heroId) --穿戴红点 end return false end function Treasure_Controller.SetTreasureItem(img_Treasure, img_Quaility, lab_Break, bg_Break, info, qualityType) UIUtils.SetImageByAssetBundle(img_Treasure, info.TreasureIcon) UTL.Color.SetQualityImageByType(img_Quaility, info.TreasureQuality, qualityType) if lab_Break then UIUtils.SetActive(lab_Break, false) end if bg_Break then UIUtils.SetActive(bg_Break, false) end end --region-------------------------------------------宝物羁绊-------------------------------------------- function Treasure_Controller.GetTreasureBreakRelation(treasureID, heroID, isNextBreak) -- 获取HorseID对应的宝物突破等级 local treasureBreakLv = MDL.Treasure.GetTreasureInfo(treasureID).TreasureInfo.starLevel local relationData local __, relation = DataSheetManager.TreasureRelation:TryGetDataByTreasureID_HeroID(treasureID, heroID) if not relation then return relationData end -- 如果表中该宝物没有英雄数据直接返回 for _, data in ipairs(relation.Relation_Table) do if isNextBreak then if treasureBreakLv < data.RelationLevel and relationData == nil then relationData = data end else if treasureBreakLv >= data.RelationLevel then relationData = data end end end return relationData end function Treasure_Controller.GetTreasureRelationHero(treasureID) local relationData = Treasure_Controller.GetTreasureRelationData(treasureID) if relationData then return relationData.HeroID end return 0 end function Treasure_Controller.GetTreasureRelationData(treasureID) for i, data in DataSheetManager.TreasureRelation:GetEnumerator() do if data.TreasureID == treasureID then return data end end end function Treasure_Controller.GetRelationSkillDesc(treasureID, startLevel) local relationData = Treasure_Controller.GetTreasureRelationData(treasureID) if relationData then local treasureSkillData for i, v in ipairs(relationData.Relation_Table) do if startLevel >= v.RelationLevel then treasureSkillData = DataSheetManager.TreasureSkillData:GetDataByTreasureSkill(v.RelationSkill) end end return UTL.String.FormatCombineTextByID(treasureSkillData.TreasureSkillDes) end return "" end function Treasure_Controller.IsBreakRelationUp(treasureID) local relationData = Treasure_Controller.GetTreasureRelationData(treasureID) local starLevel = MDL.Treasure.GetTreasureInfo(treasureID).TreasureInfo.starLevel if relationData then for i, data in ipairs(relationData.Relation_Table) do if starLevel == data.RelationLevel then return true end end end return false end function Treasure_Controller.GetTreasureHeroRelationState(treasureID, equipHeroID) local relationHeroID = Treasure_Controller.GetTreasureRelationHero(treasureID) if relationHeroID <= 0 then return Treasure_Controller.RelationState.NoRelation end --未激活武将 if not MDL.HeroSelect.IsHasHero(relationHeroID) then return Treasure_Controller.RelationState.NoHero end if relationHeroID == equipHeroID then return Treasure_Controller.RelationState.ActiveRelation else return Treasure_Controller.RelationState.NotActiveRelation end end function Treasure_Controller.ChangeEquipTreasure(heroAID, heroBID) Treasure_Controller.PushTreasureRelationActiveShow(heroAID) Treasure_Controller.PushTreasureRelationActiveShow(heroBID) CTL.Tips.PopRelationShowPanel() end function Treasure_Controller.PushTreasureRelationActiveShow(heroID) local info = MDL.Treasure.GetTreasureInfoByHeroId(heroID) if not info then return end local curRelation = Treasure_Controller.GetTreasureBreakRelation(info.TreasureID, heroID, false) if not curRelation then return end table.insert(MDL.Tips.RelationShowUpPanelQueue, {heroID = heroID, treasureID = info.TreasureID, RelationPanelType = CTL.Tips.RelationPanelType.TreasureRelation}) end --endregion --region-------------------------------------------宝物魂晶-------------------------------------------- Treasure_Controller.SoulCrystalShowPlace = { Equip = 0, Bag = 1, Advanced = 2, Reborn = 3, } Treasure_Controller.SoulCrystalEffect = { ConstAssetPathConfig.AssetPath107, ConstAssetPathConfig.AssetPath108, ConstAssetPathConfig.AssetPath109, ConstAssetPathConfig.AssetPath110, ConstAssetPathConfig.Path15, } function Treasure_Controller.GotoTreasureSoul() if MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.TreasureSoul) then local treasures = MDL.Treasure.GetTreasureInfoList() if treasures then for _, v in pairs(treasures) do if v.EquipHeroId then UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UITreasureBasePanel, {treasureId = v.TreasureID, isFormation = true, selectIndex = 1}) return end end end CTL.Tips.AddTipsMsg(Const_IDS.IDS_Resonance_Treasure_NoOne) else CTL.Tips.AddTipsMsg(Const_IDS.IDS_ERRORCODE_1317_InfoCode_Guild_GuildInviteTargetFunctionLock) end end function Treasure_Controller.IfTreasureCanSoulPanel(treasureId) -- 只有已经开启了魂晶 & 该宝物已经装备了 才会判断红点。 local equipHeroId = MDL.Treasure.GetTreasureEquipHeroId(treasureId) if (not MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.TreasureSoul)) or (not equipHeroId) then return false end local treasureInfo = MDL.Treasure.GetTreasureInfo(treasureId) if not treasureInfo then return false end local level = MDL.TreasureLibrary.GetLibraryLevelAndScore() for i, v in ipairs(treasureInfo.TreasureInfo.soulSlotInfos) do -- 判断已将装备魂晶的孔位是否有新的属性可以替换老的 if Treasure_Controller.CheckTreasureSoulSlotAttr(treasureId, i) then return true end if not string.isNilOrEmpty(v.soulCrystalId) then -- 判断升阶道具是否足够 if Treasure_Controller.CheckTreasureSoulAdvanced(v.soulCrystalId) then return true end end if level >= private.treasureSoulPitOpenCondition[i] then -- 判断是否有更好的魂晶 if Treasure_Controller.CheckTreasureSoulHasBetter(treasureId, v.soulCrystalId) then return true end end end return false end function Treasure_Controller.IfTreasureCanSoulRefined(treasureId) -- 只有已经开启了魂晶 & 该宝物已经装备了 才会判断红点。 local equipHeroId = MDL.Treasure.GetTreasureEquipHeroId(treasureId) if (not MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.TreasureSoul)) or (not equipHeroId) then return false end local treasureInfo = MDL.Treasure.GetTreasureInfo(treasureId) if not treasureInfo then return false end local level = MDL.TreasureLibrary.GetLibraryLevelAndScore() for i, v in ipairs(treasureInfo.TreasureInfo.soulSlotInfos) do if not string.isNilOrEmpty(v.soulCrystalId) then -- 判断洗练道具是否足够 if Treasure_Controller.CheckTreasureSoulRefined(v.soulCrystalId) then return true end end end return false end -- 根据宝物Id、魂晶镶嵌位置,判断该魂晶是否有新的洗练属性&新的洗练属性战力更高 function Treasure_Controller.CheckTreasureSoulSlotAttr(treasureId, posIndex) local treasureInfo = MDL.Treasure.GetTreasureInfo(treasureId) if not treasureInfo then return false end local slotInfo = treasureInfo.TreasureInfo.soulSlotInfos[posIndex] if string.isNilOrEmpty(slotInfo.soulCrystalId) then return false end if slotInfo.newSlotAttrs and #slotInfo.newSlotAttrs > 0 then -- 计算新孔位属性总战力 local newPowerNumber = 0 for _, v in ipairs(slotInfo.newSlotAttrs[1]) do if v.state == MDL.Treasure.SoulSlotAttrState.Effective then newPowerNumber = newPowerNumber + UTL.Attr.CalculateSingleFight(v.attrType, v.attrValue) end end newPowerNumber = math.floor(newPowerNumber + 0.5) -- 计算当前孔位战力 local curPowerNumber = 0 for _, v in ipairs(slotInfo.slotAttrs) do if v.state == MDL.Treasure.SoulSlotAttrState.Effective then curPowerNumber = curPowerNumber + UTL.Attr.CalculateSingleFight(v.attrType, v.attrValue) end end curPowerNumber = math.floor(curPowerNumber + 0.5) return newPowerNumber > curPowerNumber end return false end -- 根据魂晶Id 判断洗练道具是否足够 function Treasure_Controller.CheckTreasureSoulRefined(id) -- 洗练道具是否足够(普通洗练、高级洗练都要判断,都按照不锁定判断) local soulInfo = MDL.Treasure.GetSoulCrystalById(id) if not soulInfo then return false end for _, v in DataSheetManager.TreasureSoulRefineItem:GetEnumerator() do if v.LockNum == 0 then local isEnough = true for _, cost in ipairs(v.Item_Table) do local ownItemCount = UTL.Item.GetItemStockCount(cost.ItemID) if ownItemCount < cost.ItemNum then isEnough = false break end end if isEnough then return true end end end return false end -- 根据魂晶Id 判断升阶道具是否足够 function Treasure_Controller.CheckTreasureSoulAdvanced(id) -- 洗练道具是否足够(普通洗练、高级洗练都要判断,都按照不锁定判断) local soulInfo = MDL.Treasure.GetSoulCrystalById(id) if not soulInfo then return false end -- 已经是最高阶不可在升阶 if soulInfo.soulData.ColorUpTarget == 0 then return false end -- 升阶道具是否足够 -- 第一步判断需要的副魂晶数量够不够 local costSoulCount = soulInfo.soulData.ColorUpNum for _, v in MDL.Treasure.GetSoulCrystalIteratorByCrystalGroup(soulInfo.soulData.ColorUpConsume) do if v.id ~= id and not v.equip then costSoulCount = costSoulCount - 1 if costSoulCount == 0 then break end end end if costSoulCount > 0 then return false end -- 第二步判断需要的道具是否足够 local isEnough = true for _, cost in ipairs(soulInfo.soulData.ColorUp_Table) do local ownItemCount = UTL.Item.GetItemStockCount(cost.ItemID) if ownItemCount < cost.ItemNum then isEnough = false break end end return isEnough end -- 根据宝物Id 判断背包中魂晶 是否有比 当前已经镶嵌的魂晶中战力最低的魂晶更好的 function Treasure_Controller.CheckTreasureSoulHasBetter(treasureId, id) local treasureInfo = MDL.Treasure.GetTreasureInfo(treasureId) if not treasureInfo then return false end -- 获取宝物装备的最低战力魂晶id local minGSSoulInfo local minGS = 0 for _, v in ipairs(treasureInfo.TreasureInfo.soulSlotInfos) do if not string.isNilOrEmpty(v.soulCrystalId) then local soulInfo = MDL.Treasure.GetSoulCrystalById(v.soulCrystalId) if minGS == 0 or soulInfo.attrGS < minGS then minGSSoulInfo = soulInfo minGS = soulInfo.attrGS end end end -- 如果传了Id 先判断传入Id是否是镶嵌的战力最低id if id and minGSSoulInfo and id ~= minGSSoulInfo.id then return false end -- 判断背包中是否有魂晶 比 装备中战力最低的魂晶 更合适 for _, v in MDL.Treasure.GetSoulCrystalIterator(true) do if not v.equip then if Treasure_Controller.IsBetterSoulCrystal(treasureId, v.id) then return true end end end return false end -- 根据魂晶type 获取对应的类型名字 function Treasure_Controller.GetSoulCrystalTypeName(soulCrystalType) local soulCrystalTypeData = DataSheetManager.TreasureSoulCrystalType:GetDataByCrystalType(soulCrystalType) if soulCrystalTypeData then return UIUtils.GetLocalizedTxt(Const_IDS[soulCrystalTypeData.TypeName]) else logging.error(LTAG.ERROR, "宝物赋魂[UITreasureSoulCrystalEquip:InitPanel] : 没有找到在表TreasureSoulCrystalType中找到 CrystalType = ", soulCrystalType, " 的数据") end return "" end -- 根据宝物Id、倾好属性的位置,判断该倾好是否被激活 function Treasure_Controller.RecommendIndexIsActive(treasureId, index) local treasureData = DataSheetManager.TreasureData:GetDataByTreasureID(treasureId) if not treasureData then return false end local targetRecommend = treasureData.CrystalPour[index] -- 计算目标孔位之前相同类别魂晶数量 local targetRecommendCount = 0 for i = 1, index do local recommend = treasureData.CrystalPour[i] if targetRecommend == recommend then targetRecommendCount = targetRecommendCount + 1 end end -- 计算宝物装备相同类别魂晶数量 local equipDic = MDL.Treasure.GetEquipDicByTreasureId(treasureId) local equipCount = 0 local soulInfo for id, _ in pairs(equipDic) do soulInfo = MDL.Treasure.GetSoulCrystalById(id) if soulInfo.soulData.CrystalType == targetRecommend then equipCount = equipCount + 1 end end return equipCount >= targetRecommendCount end -- 根据宝物Id、魂晶镶嵌位置,判断该魂晶是否激活了倾好 function Treasure_Controller.SoulCrystalEnoughRecommend(treasureId, posIndex) local treasureInfo = MDL.Treasure.GetTreasureInfo(treasureId) if not treasureInfo then return false end local targetId = treasureInfo.TreasureInfo.soulSlotInfos[posIndex].soulCrystalId local targetSoulInfo = MDL.Treasure.GetSoulCrystalById(id) local soulInfo local equipCount = 0 for i = 1, #treasureInfo.TreasureInfo.soulSlotInfos do soulInfo = MDL.Treasure.GetSoulCrystalById(treasureInfo.TreasureInfo.soulSlotInfos[i].soulCrystalId) if soulInfo.soulData.CrystalType == targetSoulInfo.soulData.CrystalType then equipCount = equipCount + 1 end end local recommendCount = 0 for _, v in ipairs(treasureInfo.TreasureData.CrystalPour) do if v == targetSoulInfo.soulData.CrystalType then recommendCount = recommendCount + 1 end end return equipCount <= targetRecommendCount end -- 缓存一下玩家选择的洗练道具index function Treasure_Controller.SetLastSelectRefinedMaterialIndex(index) private.refinedMaterialIndex = index end -- 获取缓存的玩家选择的洗练道具index function Treasure_Controller.GetLastSelectRefinedMaterialIndex() if private.refinedMaterialIndex then return private.refinedMaterialIndex else return 0 end end -- 根据属性权重Id 获取对应属性的颜色展示 function Treasure_Controller.GetQualityStrByPercentBlockId(str, percentBlockId) local blockChart = DataSheetManager.TreasureSoulBlockChart:GetDataByPercentBlockId(percentBlockId) local quality = 1 if blockChart then quality = blockChart.EnchantColor end return UTL.Color.FormatQualityText(str, quality) end -- 根据玩家拥有数量获取 道具数量显示 function Treasure_Controller.GetCostStr(itemID, needItemNum) local ownItemCount = UTL.Item.GetItemStockCount(itemID) if ownItemCount < needItemNum then return UTL.Color.FormatRedColor(ownItemCount .. "/" .. needItemNum) else return UTL.Color.FormatGreenColor(ownItemCount .. "/" .. needItemNum) end end -- 根据洗练ID、属性类型,获取RefineAttrWeight table --[[ RefineAttrWeight 包含: AttrType 属性类型 AttrWeight 权重 AttrMinNum 最小属性值 AttrMaxNum 最大属性值 --]] function Treasure_Controller.GetRefineAttrWeight(refineID, attrType) local refineAttrWeight = DataSheetManager.TreasureSoulRefineAttrWeight:GetDataByRefineID(refineID) for _, v in ipairs(refineAttrWeight.Attr_Table) do if v.AttrType == attrType then return v end end return nil end -- 根据魂晶id、魂晶等阶、属性类型 获取BasicAttrWeight table --[[ BasicAttrWeight 包含: AttrType 属性类型 AttrWeight 权重 AttrMinNum 最小属性值 AttrMaxNum 最大属性值 --]] function Treasure_Controller.GetBasicAttrWeight(soulId, color, attrType) local basicAttrWeight = DataSheetManager.TreasureSoulBasicAttrWeight:GetDataBySoulID_Color(soulId, color) for _, v in ipairs(basicAttrWeight.Attr_Table) do if v.AttrType == attrType then return v end end return nil end -- 判断是否可以升阶 function Treasure_Controller.CheckTreasureSoulQualityUp(crystalId, otherIdDic, treasureId, posIndex) -- 计算是否满足消耗 local soulInfo = MDL.Treasure.GetSoulCrystalById(crystalId) for _, cost in ipairs(soulInfo.soulData.ColorUp_Table) do local ownItemCount = UTL.Item.GetItemStockCount(cost.ItemID) if ownItemCount < cost.ItemNum then CTL.Tips.AddTipsMsg(Const_IDS.IDS_ERRORCODE_1011_InfoCode_Item_Not_Enough) return end end -- 是否满足符魂晶全部放入了 if table.getDictCount(otherIdDic) < soulInfo.soulData.ColorUpNum then CTL.Tips.AddTipsMsg(Const_IDS.IDS_ERRORCODE_1011_InfoCode_Item_Not_Enough) return end -- 检测是否有高级魂晶 local hasHighColorSoul = false local blockChart for _, id in pairs(otherIdDic) do soulInfo = MDL.Treasure.GetSoulCrystalById(id) for _, attr in ipairs(soulInfo.baseAttrList) do blockChart = DataSheetManager.TreasureSoulBlockChart:GetDataByPercentBlockId(attr.PercentBlockId) if blockChart.EnchantColor >= private.treasureSoulDropAttrConfirm then hasHighColorSoul = true break end end if hasHighColorSoul then break end end if hasHighColorSoul then UTL.MessageBox.ShowOKCancelBox(nil, Const_IDS.IDS_TreasureSoul_GoldenAttrDropConfirm, function() MDL.Treasure.TreasureSoulQualityUpReq(crystalId, otherIdDic, treasureId, posIndex) end) else MDL.Treasure.TreasureSoulQualityUpReq(crystalId, otherIdDic, treasureId, posIndex) end end -- 获取魂晶的最佳搭配 function Treasure_Controller.GetBestSoulCrystalInfoList(treasureId) table.clear(cacheRecommendSoulType) local recommendSoulTypeDic = private.GetRecommendSoulCrystalTypeDic(treasureId, cacheRecommendSoulType) -- 计算已经解锁孔位 local level = MDL.TreasureLibrary.GetLibraryLevelAndScore() local unlockNum = 0 for _, unlockLevel in ipairs(private.treasureSoulPitOpenCondition) do if level >= unlockLevel then unlockNum = unlockNum + 1 end end local bestSoulCrystalIdList = {} -- 按照战力顺序,战力越高,越靠前 local equipDic = MDL.Treasure.GetEquipDicByTreasureId(treasureId) -- 第一遍查找 将符合偏好的 战力最高的组合找出 for _, soulInfo in MDL.Treasure.GetSoulCrystalIterator(true) do if equipDic[soulInfo.id] or not soulInfo.equip then -- 只计算自身装备 & 背包里的 local recommendTypeCount = recommendSoulTypeDic[soulInfo.soulData.CrystalType] if recommendTypeCount and recommendTypeCount > 0 then table.insert(bestSoulCrystalIdList, soulInfo.id) recommendSoulTypeDic[soulInfo.soulData.CrystalType] = recommendTypeCount - 1 end if #bestSoulCrystalIdList == unlockNum then break end end end -- 第二遍 如果最佳数组没有装满,则取未装备最高战力的魂晶进行填充 if #bestSoulCrystalIdList < unlockNum then for _, soulInfo in MDL.Treasure.GetSoulCrystalIterator(true) do if equipDic[soulInfo.id] or not soulInfo.equip then -- 只计算自身装备 & 背包里的 local include = false for _, id in ipairs(bestSoulCrystalIdList) do if id == soulInfo.id then include = true break end end if not include then table.insert(bestSoulCrystalIdList, soulInfo.id) end if #bestSoulCrystalIdList == unlockNum then break end end end end -- 如果根据前两次填充完。最佳选项依旧没有满,说明 背包中的魂晶不足。此时直接返回最佳列表 if #bestSoulCrystalIdList < unlockNum then return bestSoulCrystalIdList end -- 第三遍 当前已经把左右满足倾好,& 战力较高的魂晶放入了列表中,此时需要按照战力重新计算打破偏好后 会不会出现战力更高者 local curAllAttrGS = private.CalculateAllGS(treasureId, bestSoulCrystalIdList) local newAllAttrGS = 0 for _, soulInfo in MDL.Treasure.GetSoulCrystalIterator(true) do if equipDic[soulInfo.id] or not soulInfo.equip then -- 只计算自身装备 & 背包里的 local include = false for _, id in ipairs(bestSoulCrystalIdList) do if id == soulInfo.id then include = true break end end if not include then for i, id in ipairs(bestSoulCrystalIdList) do bestSoulCrystalIdList[i] = soulInfo.id newAllAttrGS = private.CalculateAllGS(treasureId, bestSoulCrystalIdList) if newAllAttrGS > curAllAttrGS then curAllAttrGS = newAllAttrGS break else bestSoulCrystalIdList[i] = id end end end end end return bestSoulCrystalIdList end -- 当前目标魂晶 是否比宝物身上的魂晶战力高 function Treasure_Controller.IsBetterSoulCrystal(treasureId, targetId) local treasureInfo = MDL.Treasure.GetTreasureInfo(treasureId) local curSoulCrystalIdList = {} for index, slotInfo in ipairs(treasureInfo.TreasureInfo.soulSlotInfos) do if not string.isNilOrEmpty(slotInfo.soulCrystalId) then table.insert(curSoulCrystalIdList, slotInfo.soulCrystalId) end end local level = MDL.TreasureLibrary.GetLibraryLevelAndScore() local unlockNum = 0 for _, unlockLevel in ipairs(private.treasureSoulPitOpenCondition) do if level >= unlockLevel then unlockNum = unlockNum + 1 end end if #curSoulCrystalIdList < unlockNum then return true end local curAllAttrGS = private.CalculateAllGS(treasureId, curSoulCrystalIdList) local newAllAttrGS = 0 local targeSoulInfo = MDL.Treasure.GetSoulCrystalById(targetId) for i, id in ipairs(curSoulCrystalIdList) do local soulInfo = MDL.Treasure.GetSoulCrystalById(curSoulCrystalIdList[i]) ---只有当等级品质比现有的高才计算 低了不计算 if targeSoulInfo.soulData.Color - soulInfo.soulData.Color >= -1 then curSoulCrystalIdList[i] = targetId newAllAttrGS = private.CalculateAllGS(treasureId, curSoulCrystalIdList) if newAllAttrGS > curAllAttrGS then return true else curSoulCrystalIdList[i] = id end end end return false end -- 当目标宝物装满魂晶是点击装备 返回替换那个位置的魂晶 function Treasure_Controller.GetChangeSoulCrystalIndex(treasureId, targetId) local treasureInfo = MDL.Treasure.GetTreasureInfo(treasureId) local curSoulCrystalIdList = {} for _, slotInfo in ipairs(treasureInfo.TreasureInfo.soulSlotInfos) do if not string.isNilOrEmpty(slotInfo.soulCrystalId) then table.insert(curSoulCrystalIdList, slotInfo.soulCrystalId) end end local curAllAttrGS = private.CalculateAllGS(treasureId, curSoulCrystalIdList) local newAllAttrGS = 0 local index = 0 for i, id in ipairs(curSoulCrystalIdList) do curSoulCrystalIdList[i] = targetId newAllAttrGS = private.CalculateAllGS(treasureId, curSoulCrystalIdList) if newAllAttrGS > curAllAttrGS then index = i curAllAttrGS = newAllAttrGS end curSoulCrystalIdList[i] = id end return index end -- 根据宝物Id 获取倾好type 对应的count, K为type, v为所需数量 function private.GetRecommendSoulCrystalTypeDic(treasureId, outParam) if not cacheRecommendSoulTypeDic[treasureId] then local recommendSoulTypeDic = {} -- K为type, v为所需数量 local treasureData = DataSheetManager.TreasureData:GetDataByTreasureID(treasureId) if treasureData then for _, v in ipairs(treasureData.CrystalPour) do if recommendSoulTypeDic[v] then recommendSoulTypeDic[v] = recommendSoulTypeDic[v] + 1 else recommendSoulTypeDic[v] = 1 end end cacheRecommendSoulTypeDic[treasureId] = recommendSoulTypeDic end end if outParam and cacheRecommendSoulTypeDic[treasureId] then for k, v in pairs(cacheRecommendSoulTypeDic[treasureId]) do outParam[k] = v end return outParam else return cacheRecommendSoulTypeDic[treasureId] end end -- 根据魂晶列表计算 宝物总战力(仅包含 魂晶基础战力 + 倾好战力) function private.CalculateAllGS(treasureId, soulCrystalIdList) table.clear(cacheRecommendSoulType) local recommendSoulTypeDic = private.GetRecommendSoulCrystalTypeDic(treasureId, cacheRecommendSoulType) -- 计算满足倾好数量 local enoughRecommendCount = 0 local soulInfo local curAllAttrGS = 0 for _, id in ipairs(soulCrystalIdList) do soulInfo = MDL.Treasure.GetSoulCrystalById(id) local recommendTypeCount = recommendSoulTypeDic[soulInfo.soulData.CrystalType] if recommendTypeCount and recommendTypeCount > 0 then recommendSoulTypeDic[soulInfo.soulData.CrystalType] = recommendTypeCount - 1 enoughRecommendCount = enoughRecommendCount + 1 end curAllAttrGS = curAllAttrGS + soulInfo.attrGS end local percentage = private.treasurePreciousCrystalAdd[enoughRecommendCount] percentage = percentage and percentage or 0 return curAllAttrGS * (1 + percentage / 100) end --endregion return Treasure_Controller