Skip to content

Commit cdb15f4

Browse files
committed
Item Equipped: Force "exact match" mode
Unfortunately the wow api's C_Item.IsEquippedItem does not work correctly if passed an item name. If there are multiple items with the same name, it only checks one item id. A previous commit checked each slot, but that lead to performance problems due to how many checks that needs. Fix this, by removing support for "names" and only support item ids. Thus the user has full control on which item ids are checked. Fixes: #5710
1 parent 632c69b commit cdb15f4

File tree

3 files changed

+14
-21
lines changed

3 files changed

+14
-21
lines changed

WeakAuras/GenericTrigger.lua

+1-5
Original file line numberDiff line numberDiff line change
@@ -5133,11 +5133,7 @@ WeakAuras.CheckForItemEquipped = function(itemId, specificSlot)
51335133
else
51345134
local item = Item:CreateFromEquipmentSlot(specificSlot)
51355135
if item and not item:IsItemEmpty() then
5136-
if type(itemId) == "number" then
5137-
return itemId == item:GetItemID()
5138-
else
5139-
return itemId == item:GetItemName()
5140-
end
5136+
return itemId == item:GetItemID()
51415137
end
51425138
end
51435139
end

WeakAuras/Prototypes.lua

+11-16
Original file line numberDiff line numberDiff line change
@@ -2042,8 +2042,9 @@ Private.load_prototype = {
20422042
multiEntry = {
20432043
operator = "or"
20442044
},
2045-
test = "C_Item.IsEquippedItem(C_Item.GetItemInfo(%s) or '')",
2046-
events = { "UNIT_INVENTORY_CHANGED", "PLAYER_EQUIPMENT_CHANGED"}
2045+
test = "C_Item.IsEquippedItem(%s or '')",
2046+
events = { "UNIT_INVENTORY_CHANGED", "PLAYER_EQUIPMENT_CHANGED"},
2047+
only_exact = true,
20472048
},
20482049
{
20492050
name = "not_itemequiped",
@@ -2052,8 +2053,9 @@ Private.load_prototype = {
20522053
multiEntry = {
20532054
operator = "or"
20542055
},
2055-
test = "not C_Item.IsEquippedItem(C_Item.GetItemInfo(%s) or '')",
2056-
events = { "UNIT_INVENTORY_CHANGED", "PLAYER_EQUIPMENT_CHANGED"}
2056+
test = "not C_Item.IsEquippedItem(%s or '')",
2057+
events = { "UNIT_INVENTORY_CHANGED", "PLAYER_EQUIPMENT_CHANGED"},
2058+
only_exact = true,
20572059
},
20582060
{
20592061
name = "itemtypeequipped",
@@ -8742,17 +8744,10 @@ Private.event_prototypes = {
87428744
local itemSlot = %s
87438745
]]
87448746

8745-
if trigger.use_exact_itemName then
8746-
ret = ret ..[[
8747-
local itemName = triggerItemName
8748-
local equipped = WeakAuras.CheckForItemEquipped(triggerItemName, itemSlot)
8749-
]]
8750-
else
8751-
ret = ret ..[[
8752-
local itemName = C_Item.GetItemInfo(triggerItemName)
8753-
local equipped = WeakAuras.CheckForItemEquipped(itemName, itemSlot)
8754-
]]
8755-
end
8747+
ret = ret ..[[
8748+
local itemName = triggerItemName
8749+
local equipped = WeakAuras.CheckForItemEquipped(triggerItemName, itemSlot)
8750+
]]
87568751

87578752
return ret:format(trigger.use_inverse and "true" or "false", itemName, trigger.use_itemSlot and trigger.itemSlot or "nil");
87588753
end,
@@ -8769,7 +8764,7 @@ Private.event_prototypes = {
87698764
type = "item",
87708765
required = true,
87718766
test = "true",
8772-
showExactOption = true
8767+
only_exact = true
87738768
},
87748769
{
87758770
name = "itemId",

WeakAurasOptions/LoadOptions.lua

+2
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,7 @@ function OptionsPrivate.ConstructOptions(prototype, data, startorder, triggernum
703703
local value = getValue(trigger, "use_"..realname, realname, multiEntry, entryNumber)
704704
if(arg.type == "item") then
705705
local useExactSpellId = (arg.showExactOption and getValue(trigger, nil, "use_exact_"..realname, multiEntry, entryNumber))
706+
or arg.only_exact
706707
if value and value ~= "" then
707708
if useExactSpellId then
708709
local itemId = tonumber(value)
@@ -725,6 +726,7 @@ function OptionsPrivate.ConstructOptions(prototype, data, startorder, triggernum
725726
end
726727
elseif(arg.type == "spell") then
727728
local useExactSpellId = (arg.showExactOption and getValue(trigger, nil, "use_exact_"..realname, multiEntry, entryNumber))
729+
or arg.only_exact
728730
if value and value ~= "" and (type(value) == "number" or type(value) == "string") then
729731
local spellID = WeakAuras.SafeToNumber(value)
730732
if spellID then

0 commit comments

Comments
 (0)