From 5d223297918fcd02668217c5c1c048cfb50b6761 Mon Sep 17 00:00:00 2001 From: eTzmNcbkrng Date: Fri, 3 Feb 2023 01:57:44 +1300 Subject: [PATCH] Revert "Simplify equippable check - circumvent tooltip bug" This reverts commit f7fb4d930a119feb927dc77e64ece77b72acc9ca. --- wardrobe/appearance_collector.lua | 5 ++-- wardrobe/core.lua | 48 +++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/wardrobe/appearance_collector.lua b/wardrobe/appearance_collector.lua index db28775..264f4f8 100644 --- a/wardrobe/appearance_collector.lua +++ b/wardrobe/appearance_collector.lua @@ -31,7 +31,6 @@ local GetContainerNumSlots = GetContainerNumSlots or (C_Container and C_Containe local GetContainerItemInfo = GetContainerItemInfo or (C_Container and C_Container.GetContainerItemInfo) local InCombatLockdown, SetOverrideBindingClick, ClearOverrideBindings, GetItemInfo = InCombatLockdown, SetOverrideBindingClick, ClearOverrideBindings, GetItemInfo; local SaveEquipmentSet, DeleteEquipmentSet, CreateEquipmentSet, UseEquipmentSet = C_EquipmentSet.SaveEquipmentSet, C_EquipmentSet.DeleteEquipmentSet, C_EquipmentSet.CreateEquipmentSet, C_EquipmentSet.UseEquipmentSet; -local IsEquippableItem = IsEquippableItem local LE_ITEM_CLASS_ARMOR = LE_ITEM_CLASS_ARMOR or Enum.ItemClass.Armor or 4 local LE_ITEM_CLASS_WEAPON = LE_ITEM_CLASS_WEAPON or Enum.ItemClass.Weapon or 2 local GameTooltip_Hide = GameTooltip_Hide; @@ -51,7 +50,7 @@ local GetNextItem = function() for slot = 1, GetContainerNumSlots(bag) do local link = GetContainerItemLink(bag, slot); - if (link and S.ItemIsValidTransmogrifySource(link) and not select(2, S.PlayerHasTransmog(link)) and S.IsBagItemTradable(bag, slot) and IsEquippableItem(link)) then + if (link and S.ItemIsValidTransmogrifySource(link) and not select(2, S.PlayerHasTransmog(link)) and S.IsBagItemTradable(bag, slot) and S.PlayerCanEquip(link)) then local _, _, _, _, reqLevel, _, _, _, equipSlot, _, _, itemClassID = GetItemInfo(link); if ((itemClassID == LE_ITEM_CLASS_ARMOR or itemClassID == LE_ITEM_CLASS_WEAPON) and (not reqLevel or (reqLevel == 0 and equipSlot == "INVTYPE_BODY") or (reqLevel > 0 and reqLevel <= S.myLevel))) then return bag, slot, equipSlot; @@ -145,7 +144,7 @@ end addon.CHAT_MSG_LOOT = function(self, event, message) local link = select(3, strfind(message, lootPattern)) or select(3, strfind(message, receivePattern)); - if (link and not self.enabledState and S.ItemIsValidTransmogrifySource(link) and not select(2, S.PlayerHasTransmog(link)) and S.IsItemTradable(link) and IsEquippableItem(link)) then + if (link and not self.enabledState and S.ItemIsValidTransmogrifySource(link) and not select(2, S.PlayerHasTransmog(link)) and S.IsItemTradable(link) and S.PlayerCanEquip(link)) then if (InCombatLockdown()) then showAfterCombat = true; else diff --git a/wardrobe/core.lua b/wardrobe/core.lua index 5102742..ee6ea2b 100644 --- a/wardrobe/core.lua +++ b/wardrobe/core.lua @@ -19,6 +19,13 @@ canBeSource (boolean) noSourceReason (string, optional) - error code if canBeSource (from C_Transmog.GetItemInfo) is false + PlayerCanEquip(itemLink) + Returns if the player can equip an item. + NB: Fails for spec-requirements. + + Return values: + canEquip (boolean) + IsBagItemTradable(containerID, slotID, allowBindOnAccount) Returns if a item isn't soulbound If allowBindOnAccount is true it treats BoA items like unbound BoE items @@ -284,6 +291,47 @@ elseif (S.myClass == "SHAMAN" or S.myClass == "HUNTER" or S.myClass == "EVOKER") classArmor = LE_ITEM_ARMOR_MAIL; end +local PlayerCanEquip = function(itemLink) + if (not classArmor) then return false; end + + -- Level + local _, _, _, _, reqLevel, _, _, _, equipSlot, _, _, itemClassID, itemSubClassID = GetItemInfo(itemLink); + if (reqLevel > S.myLevel) then return false; end + + -- Armor type + if (itemClassID == LE_ITEM_CLASS_ARMOR and (equipSlot ~= "INVTYPE_CLOAK") and (itemSubClassID == LE_ITEM_ARMOR_CLOTH or itemSubClassID == LE_ITEM_ARMOR_LEATHER or itemSubClassID == LE_ITEM_ARMOR_PLATE or itemSubClassID == LE_ITEM_ARMOR_MAIL) and itemSubClassID ~= classArmor) then return false; end + + -- Scan tooltip for other restrictions + local textL, textR; + + tooltip:SetHyperlink(itemLink); + for i = tooltip:NumLines(), 1, -1 do + -- Left: Class/Race/... + textL = tooltip.L[i]; + if (textL) then + local r, g, b = _G[tooltipName.."TextLeft"..i]:GetTextColor(); + if (r > 0.99 and floor(g * 1000) == 125 and floor(b * 1000) == 125 and not strmatch(textL, durabilityPattern) and not strmatch(textL, reqLevelPattern)) then + return false; + end + end + + -- Right: Weapon/Armor type + if (itemClassID == LE_ITEM_CLASS_WEAPON or itemClassID == LE_ITEM_CLASS_ARMOR) then + textR = tooltip.R[i]; + if (textR) then + local r, g, b = _G[tooltipName.."TextRight"..i]:GetTextColor(); + if (r > 0.99 and floor(g * 1000) == 125 and floor(b * 1000) == 125 and not strmatch(textR, durabilityPattern)) then + return false; + end + end + end + end + + return true; +end + +S.PlayerCanEquip = PlayerCanEquip; + ----------------------------------------------------------------------------- local ITEM_SOULBOUND, ITEM_ACCOUNTBOUND, ITEM_BIND_TO_BNETACCOUNT, ITEM_BNETACCOUNTBOUND, ITEM_BIND_ON_PICKUP = ITEM_SOULBOUND, ITEM_ACCOUNTBOUND, ITEM_BIND_TO_BNETACCOUNT, ITEM_BNETACCOUNTBOUND, ITEM_BIND_ON_PICKUP;