Skip to content

Commit

Permalink
Simplify equippable check - circumvent tooltip bug
Browse files Browse the repository at this point in the history
  • Loading branch information
eTzmNcbkrng committed Feb 2, 2023
1 parent 3b25e71 commit f7fb4d9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 50 deletions.
5 changes: 3 additions & 2 deletions wardrobe/appearance_collector.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ 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;
Expand All @@ -50,7 +51,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 S.PlayerCanEquip(link)) then
if (link and S.ItemIsValidTransmogrifySource(link) and not select(2, S.PlayerHasTransmog(link)) and S.IsBagItemTradable(bag, slot) and IsEquippableItem(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;
Expand Down Expand Up @@ -144,7 +145,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 S.PlayerCanEquip(link)) then
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 (InCombatLockdown()) then
showAfterCombat = true;
else
Expand Down
48 changes: 0 additions & 48 deletions wardrobe/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@
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
Expand Down Expand Up @@ -291,47 +284,6 @@ 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;
Expand Down

0 comments on commit f7fb4d9

Please sign in to comment.