1 QuestHelper_File
["collect_equip.lua"] = "Development Version"
2 QuestHelper_Loadtime
["collect_equip.lua"] = GetTime()
4 local debug_output
= false
5 if QuestHelper_File
["collect_equip.lua"] == "Development Version" then debug_output
= true end
14 -- why does this need to exist
15 local invloc_lookup_proto
= {
16 INVTYPE_HEAD
= {"HeadSlot"},
17 INVTYPE_NECK
= {"NeckSlot"},
18 INVTYPE_SHOULDER
= {"ShoulderSlot"},
19 INVTYPE_CHEST
= {"ChestSlot"},
20 INVTYPE_ROBE
= {"ChestSlot"},
21 INVTYPE_WAIST
= {"WaistSlot"},
22 INVTYPE_LEGS
= {"LegsSlot"},
23 INVTYPE_FEET
= {"FeetSlot"},
24 INVTYPE_WRIST
= {"WristSlot"},
25 INVTYPE_HAND
= {"HandsSlot"},
26 INVTYPE_FINGER
= {"Finger0Slot", "Finger1Slot"},
27 INVTYPE_TRINKET
= {"Trinket0Slot", "Trinket1Slot"},
28 INVTYPE_CLOAK
= {"BackSlot"},
29 INVTYPE_WEAPON
= {"MainHandSlot", "SecondaryHandSlot"},
30 INVTYPE_SHIELD
= {"SecondaryHandSlot"},
31 INVTYPE_2HWEAPON
= {"MainHandSlot"},
32 INVTYPE_WEAPONMAINHAND
= {"MainHandSlot"},
33 INVTYPE_WEAPONOFFHAND
= {"SecondaryHandSlot"},
34 INVTYPE_HOLDABLE
= {"RangedSlot"},
35 INVTYPE_RANGED
= {"RangedSlot"},
36 INVTYPE_THROWN
= {"RangedSlot"},
37 INVTYPE_RANGEDRIGHT
= {"RangedSlot"},
38 INVTYPE_RELIC
= {"RangedSlot"},
41 local invloc_lookup
= {}
43 for k
, v
in pairs(invloc_lookup_proto
) do
45 for _
, tv
in pairs(v
) do
46 table.insert(temp
, (GetInventorySlotInfo(tv
)))
48 invloc_lookup
[k
] = temp
51 local function Recheck(item
, location
, competing
)
53 local confused
= false
55 for i
, v
in pairs(invloc_lookup
[location
]) do
57 local ilink
= GetInventoryItemLink("player", v
)
59 local itype
= GetItemType(ilink
)
62 replaced
= competing
[i
]
63 elseif itype
== competing
[i
] then
72 if debug_output
then QuestHelper
:TextOut(string.format("Confused about %s", GetItemInfo(item
))) end
76 if not QHCI
[item
] then QHCI
[item
] = {} end
78 if debug_output
then QuestHelper
:TextOut(string.format("Equipped %s over %s", GetItemInfo(item
), GetItemInfo(replaced
))) end
79 QHCI
[item
].equip_yes
= (QHCI
[item
].equip_yes
or "") .. string.format("I%di%s", replaced
, GetSpecBolus())
81 for _
, v
in pairs(competing
) do
82 if debug_output
then QuestHelper
:TextOut(string.format("Did not equip %s over %s", GetItemInfo(item
), GetItemInfo(v
))) end
83 QHCI
[item
].equip_no
= (QHCI
[item
].equip_no
or "") .. string.format("I%di%s", v
, GetSpecBolus())
88 local function Looted(message
)
89 item
= string.match(message
, Patterns
.LOOT_ITEM_PUSHED_SELF
)
90 if not item
then item
= string.match(message
, Patterns
.LOOT_ITEM_SELF
) end
91 if not item
then return end
93 local item
= GetItemType(message
, true)
95 local name
, _
, quality
, ilvl
, min, itype
, isubtype
, _
, equiploc
, _
= GetItemInfo(item
)
97 if name
and IsEquippableItem(item
) and min <= UnitLevel("player") and invloc_lookup
[equiploc
] then -- The level comparison may be redundant
99 local nonempty
= false
100 for i
, v
in pairs(invloc_lookup
[equiploc
]) do
101 local litem
= GetInventoryItemLink("player", v
)
102 if litem
then litem
= GetItemType(litem
) end
103 if litem
and litem
~= item
then competing
[i
] = litem nonempty
= true end
106 if not nonempty
then return end -- congratulations you are better than nothing, we do not care
108 Notifier(GetTime() + 5 * 60, function () Recheck(item
, equiploc
, competing
) end)
112 function QH_Collect_Equip_Init(QHCData
, API
)
113 if not QHCData
.item
then QHCData
.item
= {} end
116 Patterns
= API
.Patterns
117 QuestHelper
: Assert(Patterns
)
119 API
.Patterns_Register("LOOT_ITEM_PUSHED_SELF", "|c.*|r")
120 API
.Patterns_Register("LOOT_ITEM_SELF", "|c.*|r")
122 QH_Event("CHAT_MSG_LOOT", Looted
)
124 GetItemType
= API
.Utility_GetItemType
125 Notifier
= API
.Utility_Notifier
126 GetSpecBolus
= API
.Utility_GetSpecBolus
127 QuestHelper
: Assert(GetItemType
)
128 QuestHelper
: Assert(Notifier
)
129 QuestHelper
: Assert(GetSpecBolus
)