--[[ 使用物品规则 判断物品可否使用 >> 判断物品有无指引 >> 判断物品有无读条 >> 直接使用 ItemUse_Controller.CanUseItem 物品是否可以使用 ItemUse_Controller.TryUseItem 通用的使用物品接口 ItemUse_Controller.TryUseItemByCfgId id使用物品 ]] local ItemUse_Controller = {} local private = {} --物品是否可以使用 function ItemUse_Controller.CanUseItem(itemData, itemCfgId, hasTips) local realItemCfgId = (itemCfgId and itemCfgId>0) and itemCfgId or itemData.CfgId; local itemCfgData = DataSheetManager.ItemData:GetDataByID(realItemCfgId); if itemCfgData.LimitLevelRequire_Team > 0 then if itemCfgData.LimitLevelRequire_Team > MDL.Player.GetRoleLevel() then if hasTips then local Level = UTL.Item.GetNobilityByTeamLevel(itemCfgData.LimitLevelRequire_Team) -- 爵位转换 CTL.Tips.AddTipsMsg(Const_IDS["IDS_Bag_Tips_LevelLimit"], Level); end return false; end end if itemCfgData.RelatedFunction and itemCfgData.RelatedFunction > 0 then if not MDL.Unlock.IsUnlock(itemCfgData.RelatedFunction) then if hasTips then CTL.Tips.AddTipsMsg(Const_IDS["IDS_Bag_Tips_FunctionUnlock"]); end return false; end end if itemCfgData.FirstType == LuaConst.ItemType.Materials then if itemCfgData.SecondType == LuaConst.ItemMaterialsType.GuildDonate then if not MDL.Guild.IsHasGuild() then if hasTips then CTL.Tips.AddTipsMsg(Const_IDS["IDS_Bag_Tips_NoGuild"]); end return false; end end end if itemCfgData.FirstType == LuaConst.ItemType.HeroFragment then local heroCfgId = CTL.Bag.GetHeroCfgIdByItemId(realItemCfgId); if heroCfgId > 0 then local heroInfo = MDL.HeroSelect.GetHeroInfo(heroCfgId); if heroInfo then if not MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.Break) then if hasTips then CTL.Tips.AddTipsMsg(Const_IDS["IDS_Bag_Tips_FunctionUnlock"]); end return false; end end end end if itemCfgData.FirstType == LuaConst.ItemType.GuildAllies or itemCfgData.FirstType == LuaConst.ItemType.Guild then if not MDL.Guild.IsHasGuild() then if hasTips then CTL.Tips.AddTipsMsg(Const_IDS["IDS_Bag_Tips_NoGuild"]); end return false; end if itemCfgData.FirstType == LuaConst.ItemType.GuildAllies then if itemCfgData.SecondType == LuaConst.ItemGuildAlliesType.BaiTie then if not MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.GuildAllies) then if hasTips then CTL.Tips.AddTipsMsg(Const_IDS["IDS_Bag_Tips_FunctionUnlock"]); end return false; end end end if itemCfgData.FirstType == LuaConst.ItemType.GuildAllies then if itemCfgData.SecondType == LuaConst.ItemGuildAlliesType.CeLunPu then if not MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.GuildCultivation) then if hasTips then CTL.Tips.AddTipsMsg(Const_IDS["IDS_Bag_Tips_FunctionUnlock"]); end return false; end end end end if itemCfgData.FirstType == LuaConst.ItemType.TreasureMap then if itemCfgData.SecondType ~= LuaConst.ItemTreasureMapType.Fragment and CTL.TeamMatch.IsInMatching() then CTL.Tips.AddTipsMsg(Const_IDS["IDS_DigTreasure_Matching"]) return elseif itemCfgData.SecondType ~= LuaConst.ItemTreasureMapType.Fragment and MDL.Team.IsFollowing() then CTL.Tips.AddTipsMsg(Const_IDS["IDS_DigTreasure_Following"]) return end if itemCfgData.SecondType == LuaConst.ItemTreasureMapType.Normal then local list = MDL.Task.GetTaskList(MDL.Task.Enum_TaskType.NormalTreasure) if list and next(list) then CTL.Tips.AddTipsMsg(Const_IDS.IDS_ERRORCODE_1601_InfoCode_DigTreasure_SameTypeTask) return false end elseif itemCfgData.SecondType == LuaConst.ItemTreasureMapType.Advanced then local list = MDL.Task.GetTaskList(MDL.Task.Enum_TaskType.AdvancedTreasure) if list and next(list) then CTL.Tips.AddTipsMsg(Const_IDS.IDS_ERRORCODE_1601_InfoCode_DigTreasure_SameTypeTask) return false end local taskList = MDL.Task.GetTaskList(MDL.Task.Enum_TaskType.TreasureCave) if taskList and next(taskList) then local count = 0 for k,v in pairs(taskList) do count = count + 1 end local maxCount = DataSheetManager.ConstData:GetDataByID("DigTreasureCaveTaskMax").IntValue if maxCount <= count then CTL.Tips.AddTipsMsg(Const_IDS.IDS_ERRORCODE_1608_InfoCode_DigTreasure_CaveTaskMax) return false end end end end if itemCfgData.FirstType == LuaConst.ItemType.GiftBag and itemCfgData.SecondType == LuaConst.ItemGiftBagType.RechargeGiftBag then if itemCfgData.LimitRequireRechargeScore > MDL.Currency.GetTotalRechargeCredit() then if hasTips then CTL.Tips.AddTipsMsg(Const_IDS["IDS_CDKEYGift_RechargeScoreWrongHint"]); end return false; end end return true; end --使用物品 服务器同步的物品 function ItemUse_Controller.TryUseItem(itemData, showTip) if ItemUse_Controller.CanUseItem(itemData, nil, showTip) then private.UseItemByCfgId(itemData, itemData.CfgId); end end --通过Id使用物品 notHasGuide不走指引表 默认不传 function ItemUse_Controller.TryUseItemByCfgId(itemCfgId, showTip, itemData) if ItemUse_Controller.CanUseItem(itemData, itemCfgId, showTip) then local __, useableItemData = DataSheetManager.UseableItem:TryGetDataByUseableID(itemCfgId) if useableItemData and useableItemData.Reading > 0 then UIManager.CloseView(Const_UI_Lua.UIEnum.UIBagMain) ItemUse_Controller.TryUseItemProgress(itemCfgId, useableItemData.Reading, useableItemData.ReadingIDS) else private.UseItemByRule(itemData, itemCfgId); end end end function ItemUse_Controller.TryUseItemProgress(itemCfgId, time,ids) CTL.Level.StartCommonProgressBar(function() private.UseItemByRule(nil, itemCfgId); end, UIUtils.GetLocalizedTxt(Const_IDS[ids]), time, nil, EventID.UI_VirtualController_Move) end --打开界面,通过碎片 function ItemUse_Controller.TryComposeItem(itemCfgId) UIManager.OpenView(Const_UI_Lua.UIEnum.UIBatchItemFusion, { id = itemCfgId }) end --打开界面,通过合成物品的ID function ItemUse_Controller.OpenBatchItemFusionById(batchId) local compose = DataSheetManager.ItemCompose:GetDataByID(batchId) if compose then UIManager.OpenView(Const_UI_Lua.UIEnum.UIBatchItemFusion, { id = compose.Item_Table[1].ItemID }) end end function ItemUse_Controller.GetItemComposeData(itemId) for i, v in DataSheetManager.ItemCompose:GetEnumerator() do for _, item in ipairs(v.Item_Table) do if item.ItemID == itemId then return v end end end end --private local function SortGoldHeroActivity(a, b) return a.startTime < b.startTime end function private.UseItemByRule(itemData, itemCfgId) local realItemCfgId = (itemCfgId and itemCfgId>0) and itemCfgId or itemData.CfgId; local itemCfgData = DataSheetManager.ItemData:GetDataByID(realItemCfgId); if itemCfgData.FirstType == LuaConst.ItemType.Materials then if itemCfgData.SecondType == LuaConst.ItemMaterialsType.ExpPill then private.UseExpPill(); elseif itemCfgData.SecondType == LuaConst.ItemMaterialsType.JingHunStone then if not MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.Weapon) then CTL.Tips.AddTipsMsg(Const_IDS["IDS_Bag_Tips_FunctionUnlock"]); else UIManager.OpenView(Const_UI_Lua.UIEnum.UIDivineWeapon); end elseif itemCfgData.SecondType == LuaConst.ItemMaterialsType.EnergyPill then private.UseItemByCfgId(itemCfgId); elseif itemCfgData.SecondType == LuaConst.ItemMaterialsType.DrawCard then if itemCfgData.ThirdType == MDL.DrawCard.DrawCardItemThirdTypeEnum.GoldHero then local goldHeroType = MDL.OperationActivity.ActivityType.GoldenHero local goldHeroReprintType = MDL.OperationActivity.ActivityType.GoldHeroReprint if (not MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.GoldHeroActivity) or not CTL.OperationActivity.IsOperationActivityTypeUnlock(goldHeroType)) and (not MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.GoldHeroReprint) or not CTL.OperationActivity.IsOperationActivityTypeUnlock(goldHeroReprintType)) then CTL.Tips.AddTipsMsg(Const_IDS["IDS_Bag_Tips_FunctionUnlock"]) return end local goldHeroInfoList = MDL.OperationActivity.GetOperationActivityInfo(goldHeroType) if goldHeroInfoList then local list = {} for i, v in pairs(goldHeroInfoList) do if CTL.OperationActivity.IsOperationActivityOpen(v) then table.insert(list, v) end end if #list > 0 then table.sort(list, SortGoldHeroActivity) local earlyData = list[1] CTL.GoldenHeroMain.OpenDrawCardMainPanel(earlyData.activityId) return true end end local goldHeroReprintInfoList = MDL.OperationActivity.GetOperationActivityInfo(goldHeroReprintType) if goldHeroReprintInfoList then for i, v in pairs(goldHeroReprintInfoList) do if CTL.OperationActivity.IsOperationActivityOpen(v) then UIManager.OpenView(Const_UI_Lua.UIEnum.UIGoldHeroReprint) return end end end CTL.Tips.AddTipsMsg(Const_IDS.IDS_GoldHeroActivity_No_Activited_Activity) elseif itemCfgData.ThirdType == MDL.DrawCard.DrawCardItemThirdTypeEnum.SuperGold then local superGoldActivityType = MDL.OperationActivity.ActivityType.SuperGold if (not MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.SuperGoldActivity) or not CTL.OperationActivity.IsOperationActivityTypeUnlock(superGoldActivityType)) then CTL.Tips.AddTipsMsg(Const_IDS["IDS_Bag_Tips_FunctionUnlock"]) return end local goldHeroInfoList = MDL.OperationActivity.GetOperationActivityInfo(superGoldActivityType) if goldHeroInfoList then local list = {} for i, v in pairs(goldHeroInfoList) do if CTL.OperationActivity.IsOperationActivityOpen(v) then table.insert(list, v) end end if #list > 0 then table.sort(list, SortGoldHeroActivity) local earlyData = list[1] CTL.SuperGoldMain.OpenDrawCardMainPanel(earlyData.activityId) return true end end CTL.Tips.AddTipsMsg(Const_IDS.IDS_GoldHeroActivity_No_Activited_Activity) elseif itemCfgData.ThirdType == MDL.DrawCard.DrawCardItemThirdTypeEnum.GoldHeroReprint and GameAppInfo.IsJapanesePackage() then local goldHeroReprintType = MDL.OperationActivity.ActivityType.GoldHeroReprint if not MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.GoldHeroReprint) or not CTL.OperationActivity.IsOperationActivityTypeUnlock(goldHeroReprintType) then CTL.Tips.AddTipsMsg(Const_IDS["IDS_Bag_Tips_FunctionUnlock"]) return end else UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIGachaMain) end elseif itemCfgData.SecondType == LuaConst.ItemMaterialsType.BreakPill then private.UseHeroBreakPill(itemCfgId); elseif itemCfgData.SecondType == LuaConst.ItemMaterialsType.AdvancePill then private.UseHeroAdvancePill(itemCfgId); elseif itemCfgData.SecondType == LuaConst.ItemMaterialsType.GuildDonate then UIManager.OpenView(Const_UI_Lua.UIEnum.UIGuildContribute); elseif itemCfgData.SecondType == LuaConst.ItemMaterialsType.BuTianShi then UIManager.OpenView(Const_UI_Lua.UIEnum.UIMedal) elseif itemCfgData.SecondType == LuaConst.ItemMaterialsType.HeroLightEffect then -- 使用光效激活道具 private.UseLightEffectFragment(itemData, itemCfgData) elseif itemCfgData.SecondType == LuaConst.ItemMaterialsType.SoulCrystal then -- 宝物魂晶道具 CTL.Treasure.GotoTreasureSoul() elseif itemCfgData.SecondType == LuaConst.ItemMaterialsType.GoldFragment then -- 使用金品质万能碎片 if itemCfgData.ThirdType == LuaConst.ItemGoldFragmentType.Hero then return private.UseHeroGoldFragment(LuaConst.ItemMaterialsType.GoldFragment, LuaConst.QualityColor.Gold) elseif itemCfgData.ThirdType == LuaConst.ItemGoldFragmentType.Weapon then return private.UseWeaponGoldFragment(LuaConst.ItemMaterialsType.GoldFragment, LuaConst.QualityColor.Gold) elseif itemCfgData.ThirdType == LuaConst.ItemGoldFragmentType.Horse then return private.UseHorseGoldFragment(LuaConst.ItemMaterialsType.GoldFragment, LuaConst.QualityColor.Gold) elseif itemCfgData.ThirdType == LuaConst.ItemGoldFragmentType.Treasure then return private.UseTreasureGoldFragment(LuaConst.ItemMaterialsType.GoldFragment, LuaConst.QualityColor.Gold) elseif itemCfgData.ThirdType == LuaConst.ItemGoldFragmentType.GodBeast then return private.UseGodBeastGoldFragment(LuaConst.ItemMaterialsType.GoldFragment, LuaConst.QualityColor.Gold) end elseif itemCfgData.SecondType == LuaConst.ItemMaterialsType.SuperGoldFragment then -- 使用彩金品质万能碎片 if itemCfgData.ThirdType == LuaConst.ItemGoldFragmentType.Hero then return private.UseHeroGoldFragment(LuaConst.ItemMaterialsType.SuperGoldFragment, LuaConst.QualityColor.DarkGold) elseif itemCfgData.ThirdType == LuaConst.ItemGoldFragmentType.Weapon then return private.UseWeaponGoldFragment(LuaConst.ItemMaterialsType.SuperGoldFragment, LuaConst.QualityColor.DarkGold) elseif itemCfgData.ThirdType == LuaConst.ItemGoldFragmentType.Horse then return private.UseHorseGoldFragment(LuaConst.ItemMaterialsType.SuperGoldFragment, LuaConst.QualityColor.DarkGold) elseif itemCfgData.ThirdType == LuaConst.ItemGoldFragmentType.Treasure then return private.UseTreasureGoldFragment(LuaConst.ItemMaterialsType.SuperGoldFragment, LuaConst.QualityColor.DarkGold) elseif itemCfgData.ThirdType == LuaConst.ItemGoldFragmentType.GodBeast then return private.UseGodBeastGoldFragment(LuaConst.ItemMaterialsType.SuperGoldFragment, LuaConst.QualityColor.DarkGold) end elseif itemCfgData.SecondType == LuaConst.ItemMaterialsType.HeroStrenthen then -- 使用武将修炼道具 if not MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.HeroStrenthen) then CTL.Tips.AddTipsMsg(Const_IDS["IDS_Bag_Tips_FunctionUnlock"]) else CTL.HeroStrenthen.JumpToHeroStrenthen() end elseif itemCfgData.SecondType == LuaConst.ItemMaterialsType.GoldMineToken then CTL.GuildMine.OpenGuildMineMainView() end elseif itemCfgData.FirstType == LuaConst.ItemType.HeroFragment then private.UseHeroFragment(itemCfgId); elseif itemCfgData.FirstType == LuaConst.ItemType.Horn then CTL.ChannelChat.UseSuoNaItem() elseif itemCfgData.FirstType == LuaConst.ItemType.Title then MDL.Title.TitleUseItemReq(itemCfgId) elseif itemCfgData.FirstType == LuaConst.ItemType.Portrait then MDL.Character.PortraitUseItemRequest(itemCfgId) elseif itemCfgData.FirstType == LuaConst.ItemType.Frame then MDL.Character.FrameUseItemRequest(itemCfgId) elseif itemCfgData.FirstType == LuaConst.ItemType.WeaponFragment then if not MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.Weapon) then CTL.Tips.AddTipsMsg(Const_IDS["IDS_Bag_Tips_FunctionUnlock"]); else private.UseWeaponFragment(itemCfgId, itemCfgData.SecondType, itemCfgData.ThirdType); end elseif itemCfgData.FirstType == LuaConst.ItemType.Activity then if CTL.DyeAppearance.IsDyeItem(itemCfgId) then local func = CTL.DyeAppearance.GetJumpFunc(itemCfgId) func() end elseif itemCfgData.FirstType == LuaConst.ItemType.GiftBag then private.UseGiftBag(itemCfgId); elseif itemCfgData.FirstType == LuaConst.ItemType.Horse then if not MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.WarHorse) then CTL.Tips.AddTipsMsg(Const_IDS["IDS_Bag_Tips_FunctionUnlock"]); return true end private.UseWarHorseFragment(itemCfgId, itemCfgData.SecondType); elseif itemCfgData.FirstType == LuaConst.ItemType.Treasure then private.UseTreasureFragment(itemCfgId, itemCfgData.SecondType); elseif itemCfgData.FirstType == LuaConst.ItemType.GuildAllies then if itemCfgData.SecondType == LuaConst.ItemGuildAlliesType.BaiTie then UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIGuildAlliesMapView) elseif itemCfgData.SecondType == LuaConst.ItemGuildAlliesType.CeLunPu then CTL.GuildCultivation.OpenGuildCultivation() end elseif itemCfgData.FirstType == LuaConst.ItemType.TreasureMap then private.UserTreasureMap(itemData, itemCfgData) elseif itemCfgData.FirstType == LuaConst.ItemType.Appearance then if itemCfgData.SecondType == MDL.Appearance.AppearanceType.Hero then private.UseAppearanceFragment(itemData, itemCfgData) elseif itemCfgData.SecondType == MDL.Appearance.AppearanceType.Weapon then if not MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.Weapon) then CTL.Tips.AddTipsMsg(Const_IDS["IDS_Bag_Tips_FunctionUnlock"]); else private.UseWeaponAppearanceFragment(itemData, itemCfgData) end elseif itemCfgData.SecondType == MDL.Appearance.AppearanceType.Horse then MDL.WarHorse.UseHorseAppearanceFragment(itemCfgId) end elseif itemCfgData.FirstType == LuaConst.ItemType.HeroEffect then -- 使用光效激活道具 private.UseLightEffectFragment(itemData, itemCfgData) elseif itemCfgData.FirstType == LuaConst.ItemType.DrawStraws then UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIWelfareBasePanel, {welfareId = CTL.Welfare.WelfareType.DailyDraw}) elseif itemCfgData.FirstType == LuaConst.ItemType.Stratagem then CTL.Stratagem.OpenViewByItemId(realItemCfgId) elseif itemCfgData.FirstType == LuaConst.ItemType.ItemRetinue then CTL.Appearance.UseRetinueItem(itemCfgData) elseif itemCfgData.FirstType == LuaConst.ItemType.GodBeast then CTL.GodBeast.OpenViewByItemId(realItemCfgId) elseif itemCfgData.FirstType == LuaConst.ItemType.HeroAwaken then if itemCfgData.SecondType == LuaConst.ItemMaterialsType.JingHunStone then if MDL.HeroAwaken.GetIsHeroAwaken(itemCfgData.ThirdType) then MDL.HeroSelect.curSelectHeroID = itemCfgData.ThirdType UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIHeroShowPanel, { subViewName = MDL.HeroSelect.ToggleViewNameList.Awaken }) else CTL.Tips.AddTipsMsg(Const_IDS.IDS_NoHeroAwaken_Tips) end elseif itemCfgData.SecondType == LuaConst.ItemMaterialsType.BreakPill then --觉醒武将 local heroId = CTL.HeroAwaken.GetItemUseHeroId() if heroId then MDL.HeroSelect.curSelectHeroID = heroId UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIHeroShowPanel, { subViewName = MDL.HeroSelect.ToggleViewNameList.Awaken }) else CTL.Tips.AddTipsMsg(Const_IDS.IDS_NoHeroAwaken_Tips) end elseif itemCfgData.SecondType == LuaConst.ItemMaterialsType.ExpPill then --觉醒神兵 local heroId = CTL.HeroAwaken.GetItemUseHeroId() if heroId then UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIDivineWeaponBasePanel, { data = DataSheetManager.MagicWeaponData:GetDataByMagicWeaponID(heroId) }) else CTL.Tips.AddTipsMsg(Const_IDS.IDS_NoHeroAwaken_Tips) end end elseif itemCfgData.FirstType == LuaConst.ItemType.HeroSubstitute then if itemCfgData.SecondType == LuaConst.ItemHeroSubstituteType.RegretSubstitute then UIManager.OpenView(Const_UI_Lua.UIEnum.UIHeroSubstituteMain,{isRegretSubstitute = true, itemData = itemData}) else UIManager.OpenView(Const_UI_Lua.UIEnum.UIHeroSubstituteMain,{isRegretSubstitute = false, itemData = itemData}) end elseif itemCfgData.FirstType == LuaConst.ItemType.Decoration then MDL.Decoration.UseDecorateItemReq(itemCfgId) end return true; end function private.UserTreasureMap(itemData, itemCfgData) if itemCfgData.SecondType ~= LuaConst.ItemTreasureMapType.Fragment then MDL.Bag.UseItemByCfgIdReq(itemCfgData.ID, 1) end end function private.UseHeroAdvancePill(itemCfgId) local rightHeroId = 0; MDL.HeroSelect.SortHeroOrder() local heroList = MDL.HeroSelect.GetSortedHeroData(); for __, heroData in ipairs(heroList) do if MDL.HeroSelect.IsHasHero(heroData.ID) then if CTL.Advanced.IsCouldAdvance(heroData.ID) and not CTL.Advanced.IsReachMaxAdvanceLevel(heroData.ID) and CTL.Advanced.IsHeroLevelReachLimit(heroData.ID) then local advancedStep = MDL.Advanced.GetHeroAdvancedInfo(heroData.ID); local advancedData = DataSheetManager.HeroAdvance:GetDataByAdvanceID(advancedStep); if advancedData.PointItem_Table[1].PointItemID == itemCfgId then rightHeroId = heroData.ID; break; end end end end if rightHeroId == 0 then for __, heroData in ipairs(heroList) do if MDL.HeroSelect.IsHasHero(heroData.ID) then rightHeroId = heroData.ID; break; end end end MDL.HeroSelect.curSelectHeroID = rightHeroId; UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIHeroShowPanel, {subViewName = MDL.HeroSelect.ToggleViewNameList.Advanced}) end function private.UseHeroBreakPill(itemCfgId) local rightHeroId = 0; MDL.HeroSelect.SortHeroOrder() local heroList = MDL.HeroSelect.GetSortedHeroData(); for __, heroData in ipairs(heroList) do if MDL.HeroSelect.IsHasHero(heroData.ID) then if not CTL.HeroStar.IsHeroReachMaxStar(heroData.ID) then local costItemInfoArr = MDL.HeroStar.GetHeroBreakthroughRequireItem(heroData.ID); if costItemInfoArr then for __, costData in ipairs(costItemInfoArr) do if costData.ItemID == itemCfgId then rightHeroId = heroData.ID; break; end end end end end end if rightHeroId == 0 then for __, heroData in ipairs(heroList) do if MDL.HeroSelect.IsHasHero(heroData.ID) then rightHeroId = heroData.ID; break; end end end MDL.HeroSelect.curSelectHeroID = rightHeroId; UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIHeroShowPanel, {subViewName = MDL.HeroSelect.ToggleViewNameList.Break}) end --使用经验丹 function private.UseExpPill() local lineUpHeroIds = MDL.Player.GetHeroLinUpIds() local heroMinLevelId = nil local level = 999999 for i,v in ipairs(lineUpHeroIds) do local curLevel = MDL.HeroSelect.GetHeroLevel(v) if curLevel>=0 and curLevel < level then level = curLevel heroMinLevelId = v end end if heroMinLevelId then MDL.HeroSelect.curSelectHeroID = heroMinLevelId else MDL.HeroSelect.curSelectHeroID = MDL.HeroSelect.GetSortedHeroIdByIndex(1) end UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIHeroShowPanel, {subViewName = MDL.HeroSelect.ToggleViewNameList.LevelUp}) end function private.UseItemByCfgId(itemCfgId) local count = MDL.Bag.GetItemCount(itemCfgId) --道具数量=1时直接使用 if count > 1 then UIManager.OpenView(Const_UI_Lua.UIEnum.UIBagItemUsePanel,{data = {Count = count, CfgId = itemCfgId}}) else --此处需要发送道具使用请求 MDL.Bag.UseItemByCfgIdReq(itemCfgId, count) end end function private.UseHeroFragment(itemCfgId) local heroId = CTL.Bag.GetHeroCfgIdByItemId(itemCfgId); if heroId > 0 then local heroInfo = MDL.HeroSelect.GetHeroInfo(heroId); if heroInfo then MDL.HeroSelect.curSelectHeroID = heroId UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIHeroShowPanel,{subViewName = MDL.HeroSelect.ToggleViewNameList.Break}) else UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIHeroSelectPanel,{heroID = heroId}) end end end function private.UseWeaponFragment(itemCfgId, secondType, thirdType) local rightWeaponId = 0; local toggleType if secondType == LuaConst.ItemWeaponType.WeaponFragment then rightWeaponId = CTL.Bag.GetMagicWeaponCfgIdByItemId(itemCfgId); elseif secondType == LuaConst.ItemWeaponType.ForgeItem or secondType == LuaConst.ItemWeaponType.ForgeWeaponItem then if not MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.DivineWeaponForge) then CTL.Tips.AddTipsMsg(Const_IDS.IDS_Foundry_NotOpen) return end if secondType == LuaConst.ItemWeaponType.ForgeWeaponItem then local heroInfo = MDL.HeroSelect.GetHeroInfo(thirdType) if not heroInfo or not heroInfo.isMagicWeaponActive then CTL.Tips.AddTipsMsg(Const_IDS.IDS_Foundry_MWNotOpen) return end rightWeaponId = thirdType else for __, weaponData in ipairs(MDL.DivineWeapon.GetAllData()) do local heroInfo = MDL.HeroSelect.GetHeroInfo(weaponData.MagicWeaponID) if heroInfo and heroInfo.isMagicWeaponActive then rightWeaponId = weaponData.MagicWeaponID break end end end toggleType = UTL.Toggle.ToggleType.Forge else local weaponList = MDL.DivineWeapon.GetAllData(); for __, weaponData in ipairs(weaponList) do local heroInfo = MDL.HeroSelect.GetHeroInfo(weaponData.MagicWeaponID); if heroInfo and heroInfo.isMagicWeaponActive then if heroInfo.magicWeaponLevel < MDL.DivineWeapon.GetBreakMax(weaponData.MagicWeaponID) then local dataTemp = DataSheetManager.MagicWeaponStar:GetDataByMagicWeaponID_Star(weaponData.MagicWeaponID, heroInfo.magicWeaponLevel); local breakCostDataArr = DataSheetManager.MagicWeaponStarItem:GetDataByItemRepeatID(dataTemp.Item_Table[heroInfo.magicWeaponStar+1].ItemRepeat).Item_Table; if breakCostDataArr then for __, breakCostData in ipairs(breakCostDataArr) do if breakCostData.ItemID == itemCfgId then rightWeaponId = weaponData.MagicWeaponID; break; end end end end elseif heroInfo then local costInfoArr = MDL.DivineWeapon.GetCostInfo(weaponData.Item_Table[heroInfo.magicWeaponActivePhase + 1].ItemRepeat) if costInfoArr then for __, costData in ipairs(costInfoArr) do if costData.ItemID == itemCfgId then rightWeaponId = weaponData.MagicWeaponID; break; end end end break; end end if rightWeaponId == 0 then for __, weaponData in ipairs(weaponList) do local heroInfo = MDL.HeroSelect.GetHeroInfo(weaponData.MagicWeaponID); if heroInfo and heroInfo.isMagicWeaponActive then rightWeaponId = weaponData.MagicWeaponID; break; end end end if rightWeaponId == 0 then rightWeaponId = weaponList[1].MagicWeaponID; end end if rightWeaponId > 0 then local weaponCfgData = DataSheetManager.MagicWeaponData:GetDataByMagicWeaponID(rightWeaponId); UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIDivineWeaponBasePanel,{data = weaponCfgData, toggleType = toggleType}) else UIManager.OpenView(Const_UI_Lua.UIEnum.UIDivineWeapon); end end function private.UseGiftBag(itemCfgId) local giftBagData = DataSheetManager.UseableItem:GetDataByUseableID(itemCfgId); if giftBagData then if giftBagData.UseableType == LuaConst.ItemGiftBagSelectType.Normal then private.UseItemByCfgId(itemCfgId); elseif giftBagData.UseableType == LuaConst.ItemGiftBagSelectType.HeroFilter then if CTL.Bag.TryTranslateItem(itemCfgId, giftBagData) then return end UIManager.OpenView(Const_UI_Lua.UIEnum.UISelectReward, {data = itemCfgId}) elseif giftBagData.UseableType == LuaConst.ItemGiftBagSelectType.SelfSelect then UIManager.OpenView(Const_UI_Lua.UIEnum.UISelectReward, {data = itemCfgId}); elseif giftBagData.UseableType == LuaConst.ItemGiftBagSelectType.Pet then MDL.Pet.UsePetEggReq(itemCfgId) elseif giftBagData.UseableType == LuaConst.ItemGiftBagSelectType.MonthCard or giftBagData.UseableType == LuaConst.ItemGiftBagSelectType.WeekCard then private.UseItemByCfgId(itemCfgId) end end end function private.UseWarHorseFragment(itemCfgId, secondType) local rightHorseId = 0; if secondType == LuaConst.ItemHorseType.HorseFragment then rightHorseId = CTL.Bag.GetWarHorseCfgIdByItemId(itemCfgId); else local warHorseList = MDL.WarHorse.GetSortedHorseList(); for __, horseData in ipairs(warHorseList) do if MDL.WarHorse.GetInfoByID(horseData.HorseID) then local breakCostDataArr = CTL.WarHorse.GetNextBreakItemConfig(horseData.HorseID); if breakCostDataArr then for __, breakCostData in ipairs(breakCostDataArr) do if breakCostData.ItemID == itemCfgId then rightHorseId = horseData.HorseID; break; end end end elseif not CTL.WarHorse.CheckHorseIfEnableActive(horseData) then break; end end if rightHorseId == 0 then for __, horseData in ipairs(warHorseList) do if MDL.WarHorse.GetInfoByID(horseData.HorseID) then rightHorseId = horseData.HorseID; break; end end end if rightHorseId == 0 then rightHorseId = warHorseList[1].HorseID; end end local warHorseCfgData = DataSheetManager.HorseData:GetDataByHorseID(rightHorseId); CTL.WarHorse.OpenSubPanel(CTL.WarHorse.Horse_EnterType.WarHorse, warHorseCfgData); end function private.UseTreasureFragment(itemCfgId, secondType) local rightTreasureId = 0; if secondType == LuaConst.ItemTreasureType.TreasureFragment then rightTreasureId = CTL.Bag.GetTreasureCfgIdByItemId(itemCfgId); else local treasureList = MDL.Treasure.GetSortedTreasureList(); for __, treasureData in ipairs(treasureList) do if MDL.Treasure.GetTreasureInfo(treasureData.TreasureID) then local breakCostDataArr = CTL.Treasure.GetNextBreakItemData(treasureData.TreasureID); if breakCostDataArr then for __, breakCostData in ipairs(breakCostDataArr) do if breakCostData.ItemID == itemCfgId then rightTreasureId = treasureData.TreasureID; break; end end end elseif not CTL.Treasure.IfTreasureCanActive(treasureData.TreasureID) then break; end end if rightTreasureId == 0 then for __, treasureData in ipairs(treasureList) do if MDL.Treasure.GetTreasureInfo(treasureData.TreasureID) then rightTreasureId = treasureData.TreasureID; break; end end end if rightTreasureId == 0 then rightTreasureId = treasureList[1].TreasureID; end end if rightTreasureId > 0 then UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UITreasureBasePanel, {treasureId = rightTreasureId}); else UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UITreasureMainPanel); end end function private.UseAppearanceFragment(itemData, itemCfgData) for k,appearanceCfg in DataSheetManager.HeroAppearance:GetEnumerator() do if appearanceCfg.Activation == itemCfgData.ID then if MDL.HeroSelect.IsHasHero(appearanceCfg.HeroID) then MDL.HeroSelect.curSelectHeroID = appearanceCfg.HeroID if not UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UIHeroShowPanel) then local fashionID for k,v in DataSheetManager.HeroAppearance:GetEnumerator() do if v.Activation == itemCfgData.ID then fashionID = v.ID break end end UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIHeroShowPanel, { subViewName = MDL.HeroSelect.ToggleViewNameList.Appearance, appearanceType = LuaConst.AppearanceType.Fashion, fashionID = fashionID}) end return else MDL.HeroSelect.curSelectHeroID = appearanceCfg.HeroID if not UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UIHeroShowPanel) then UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIHeroShowPanel, { subViewName = MDL.HeroSelect.ToggleViewNameList.Advanced }) end return end end end end function private.UseWeaponAppearanceFragment(itemData, itemCfgData) for k,cfg in DataSheetManager.MagicWeaponData:GetEnumerator() do for _, id in ipairs(cfg.WeaponAppearance) do local data = DataSheetManager.WeaponAppearance:GetDataByID(id) if itemCfgData.ID == data.Activation then MDL.DivineWeapon.ItemUseAppearanceId = id UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIDivineWeaponBasePanel,{data = cfg, selectIndex = 1}) end end end end -- 使用光效激活道具 function private.UseLightEffectFragment(itemData, itemCfgData) for k,cfg in DataSheetManager.LightEffect:GetEnumerator() do if itemCfgData.ID == cfg.Activation then if cfg.BelongTo ~= nil and #cfg.BelongTo > 0 then MDL.HeroSelect.curSelectHeroID = cfg.BelongTo[1] else MDL.HeroSelect.curSelectHeroID = MDL.HeroSelect.GetSortedHeroIdByIndex(1) for i, v in ipairs(MDL.HeroSelect.GetSortedHeroData()) do if MDL.HeroSelect.IsHasHero(v.ID) and not MDL.LightEffect.IsActivateByHeroID_LightEffectID(v.ID, cfg.Activation) then MDL.HeroSelect.curSelectHeroID = v.ID break end end end UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIHeroShowPanel, {subViewName = MDL.HeroSelect.ToggleViewNameList.Appearance, appearanceType = LuaConst.AppearanceType.LightEffect}) return end end end --region ------------------ 金/彩金 万能碎片 --------------------- -- 使用武将万能碎片 function private.UseHeroGoldFragment(materialsType, qualityColor) local hasGoldHero = false for _, v in ipairs(MDL.HeroSelect.GetSortedHeroData()) do if v.HeroQuality == qualityColor and MDL.HeroSelect.IsHasHero(v.ID) then hasGoldHero = true if not CTL.HeroStar.IsHeroReachMaxStar(v.ID) then MDL.HeroSelect.curSelectHeroID = v.ID UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIHeroShowPanel, { subViewName = MDL.HeroSelect.ToggleViewNameList.Break }) return true end end end if hasGoldHero then if materialsType == LuaConst.ItemMaterialsType.GoldFragment then CTL.Tips.AddTipsMsg(Const_IDS["IDS_OmnipotentFragment_Hero_Unsuited"]) -- 暂无适合使用该道具的金色武将 elseif materialsType == LuaConst.ItemMaterialsType.SuperGoldFragment then CTL.Tips.AddTipsMsg(Const_IDS["IDS_OmnipotentFragment_Hero_UnsuitedColourHero"]) -- 暂无适合使用该道具的彩金色武将 end return true else if materialsType == LuaConst.ItemMaterialsType.GoldFragment then CTL.Tips.AddTipsMsg(Const_IDS["IDS_OmnipotentFragment_Hero_NotActive"]) -- 暂无已激活的金色武将,无法使用 elseif materialsType == LuaConst.ItemMaterialsType.SuperGoldFragment then CTL.Tips.AddTipsMsg(Const_IDS["IDS_OmnipotentFragment_Hero_NotActiveColourHero"]) -- 暂无已激活的彩金色武将,无法使用 end return true end end -- 使用神兵万能碎片 function private.UseWeaponGoldFragment(materialsType, qualityColor) if not MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.Weapon) then CTL.Tips.AddTipsMsg(Const_IDS["IDS_Bag_Tips_FunctionUnlock"]) -- 功能尚未解锁,无法使用该道具 return true end local hasGoldWeapon = false for _, v in ipairs(MDL.DivineWeapon.GetHasWeaponList()) do local weaponCfg = DataSheetManager.MagicWeaponData:GetDataByMagicWeaponID(v.MagicWeaponID) if weaponCfg.MagicWeaponQuality == qualityColor then hasGoldWeapon = true if not CTL.DivineWeapon.IsWeaponReachMaxStar(v.MagicWeaponID) then UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIDivineWeaponBasePanel, { data = weaponCfg }) return true end end end if hasGoldWeapon then if materialsType == LuaConst.ItemMaterialsType.GoldFragment then CTL.Tips.AddTipsMsg(Const_IDS["IDS_OmnipotentFragment_Weapon_Unsuited"]) -- 暂无适合使用该道具的金色神兵 elseif materialsType == LuaConst.ItemMaterialsType.SuperGoldFragment then CTL.Tips.AddTipsMsg(Const_IDS["IDS_OmnipotentFragment_Hero_UnsuitedColourDivineTroops"]) -- 暂无适合使用该道具的彩金色神兵 end return true else if materialsType == LuaConst.ItemMaterialsType.GoldFragment then CTL.Tips.AddTipsMsg(Const_IDS["IDS_OmnipotentFragment_Weapon__NotActive"]) -- 暂无已激活的金色神兵,无法使用 elseif materialsType == LuaConst.ItemMaterialsType.SuperGoldFragment then CTL.Tips.AddTipsMsg(Const_IDS["IDS_OmnipotentFragment_Hero_NotActiveColourDivineTroops"]) -- 暂无已激活的彩金色神兵,无法使用 end return true end end -- 使用坐骑万能碎片 function private.UseHorseGoldFragment(materialsType, qualityColor) if not MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.WarHorse) then CTL.Tips.AddTipsMsg(Const_IDS["IDS_Bag_Tips_FunctionUnlock"]) -- 功能尚未解锁,无法使用该道具 return true end local hasGoldHorse = false for _, v in pairs(MDL.WarHorse.GetActiveHorseInfoDic()) do if v.ConfigInfo.HorseQuality == qualityColor then hasGoldHorse = true if CTL.WarHorse.GetNextBreakItemConfig(v.ID) ~= nil then CTL.WarHorse.OpenSubPanel(CTL.WarHorse.Horse_EnterType.WarHorse, v.ConfigInfo, CTL.WarHorse.Horse_TabIndex.Break) return true end end end if hasGoldHorse then if materialsType == LuaConst.ItemMaterialsType.GoldFragment then CTL.Tips.AddTipsMsg(Const_IDS["IDS_OmnipotentFragment_Hero_UnsuitedGoldMount"]) -- 暂无适合使用该道具的金色坐骑 elseif materialsType == LuaConst.ItemMaterialsType.SuperGoldFragment then CTL.Tips.AddTipsMsg(Const_IDS["IDS_OmnipotentFragment_Hero_UnsuitedColourMount"]) -- 暂无适合使用该道具的彩金色坐骑 end return true else if materialsType == LuaConst.ItemMaterialsType.GoldFragment then CTL.Tips.AddTipsMsg(Const_IDS["IDS_OmnipotentFragment_Hero_NotActiveGoldMount"]) -- 暂无已激活的金色坐骑,无法使用 elseif materialsType == LuaConst.ItemMaterialsType.SuperGoldFragment then CTL.Tips.AddTipsMsg(Const_IDS["IDS_OmnipotentFragment_Hero_NotActiveColourMount"]) -- 暂无已激活的彩金色坐骑,无法使用 end return true end end -- 使用宝物万能碎片 function private.UseTreasureGoldFragment(materialsType, qualityColor) if not MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.Treasure) then CTL.Tips.AddTipsMsg(Const_IDS["IDS_Bag_Tips_FunctionUnlock"]) -- 功能尚未解锁,无法使用该道具 return true end local hasGoldTreasure = false for _, v in pairs(MDL.Treasure.GetTreasureInfoList()) do if v.TreasureData.TreasureQuality == qualityColor then hasGoldTreasure = true if CTL.Treasure.GetNextBreakItemData(v.TreasureID) ~= nil then UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UITreasureBasePanel, {treasureId = v.TreasureID}) return true end end end if hasGoldTreasure then if materialsType == LuaConst.ItemMaterialsType.GoldFragment then CTL.Tips.AddTipsMsg(Const_IDS["IDS_OmnipotentFragment_Hero_UnsuitedGoldTreasure"]) -- 暂无适合使用该道具的金色坐骑 elseif materialsType == LuaConst.ItemMaterialsType.SuperGoldFragment then CTL.Tips.AddTipsMsg(Const_IDS["IDS_OmnipotentFragment_Hero_UnsuitedColourTreasure"]) -- 暂无适合使用该道具的彩金色坐骑 end return true else if materialsType == LuaConst.ItemMaterialsType.GoldFragment then CTL.Tips.AddTipsMsg(Const_IDS["IDS_OmnipotentFragment_Hero_NotActiveGoldTreasure"]) -- 暂无已激活的金色坐骑,无法使用 elseif materialsType == LuaConst.ItemMaterialsType.SuperGoldFragment then CTL.Tips.AddTipsMsg(Const_IDS["IDS_OmnipotentFragment_Hero_NotActiveColourTreasure"]) -- 暂无已激活的彩金色坐骑,无法使用 end return true end end function private.UseGodBeastGoldFragment(materialsType, qualityColor) if not MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.Treasure) then CTL.Tips.AddTipsMsg(Const_IDS["IDS_Bag_Tips_FunctionUnlock"]) -- 功能尚未解锁,无法使用该道具 return true end local hasGold = false for i, v in pairs(MDL.GodBeast.GetActiveBeastInfoDic()) do local godBeastData = DataSheetManager.GodBeastData:GetDataByID(v.godBeastId) if godBeastData.GodBeastQuality == qualityColor then hasGold = true if MDL.GodBeast.GetBreakStateInfo(v.godBeastId) ~= MDL.GodBeast.BreakState.max then UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIGodBeastBasePanel, {id = v.godBeastId, toggleType = CTL.GodBeast.BaseViewType.Break}) return true end end end if hasGold then if materialsType == LuaConst.ItemMaterialsType.GoldFragment then CTL.Tips.AddTipsMsg(Const_IDS["IDS_OmnipotentFragment_Hero_UnsuitedGoldGodBeast"]) -- 暂无适合使用该道具的金色坐骑 elseif materialsType == LuaConst.ItemMaterialsType.SuperGoldFragment then CTL.Tips.AddTipsMsg(Const_IDS["IDS_OmnipotentFragment_Hero_UnsuitedColourGodBeast"]) -- 暂无适合使用该道具的彩金色坐骑 end return true else if materialsType == LuaConst.ItemMaterialsType.GoldFragment then CTL.Tips.AddTipsMsg(Const_IDS["IDS_OmnipotentFragment_Hero_NotActiveGoldGodBeast"]) -- 暂无已激活的金色坐骑,无法使用 elseif materialsType == LuaConst.ItemMaterialsType.SuperGoldFragment then CTL.Tips.AddTipsMsg(Const_IDS["IDS_OmnipotentFragment_Hero_NotActiveColourGodBeast"]) -- 暂无已激活的彩金色坐骑,无法使用 end return true end end --endregion ------------------ 金/彩金 万能碎片 --------------------- return ItemUse_Controller