Skip to content

Commit 1d70e72

Browse files
committed
Fix issues with mailing packaged battle pets and possibly other items.
1 parent 5eb1cdb commit 1d70e72

1 file changed

Lines changed: 41 additions & 13 deletions

File tree

BulkMail.lua

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,13 @@ end
180180
--[[----------------------------------------------------------------------------
181181
Local Processing
182182
------------------------------------------------------------------------------]]
183+
184+
-- utility method to get item id.
185+
local function linkToId(itemLink)
186+
return type(item) == 'number' and item or tonumber(strmatch(itemLink, "|H[^:]+:(%d+)"))
187+
end
188+
189+
183190
-- Bag iterator, shamelessly stolen from PeriodicTable-2.0 (written by Tekkub)
184191
local iterbag, iterslot
185192
local function iter()
@@ -267,7 +274,7 @@ end
267274
local function rulesCacheDest(item)
268275
if not item then return end
269276
local rdest
270-
local itemID = type(item) == 'number' and item or tonumber(strmatch(item, "item:(%d+)"))
277+
local itemID = linkToId(item)
271278
if not itemID then return end
272279
for _, xID in ipairs(globalExclude.items) do if itemID == xID then return end end
273280
for _, xset in ipairs(globalExclude.pt31Sets) do
@@ -277,17 +284,29 @@ local function rulesCacheDest(item)
277284
local quality = select(3, GetItemInfo(itemID))
278285
local equippable = IsEquippableItem(itemID)
279286

280-
if (equippable and quality < self.db.char.minItemLevel)
281-
or (not equippable and quality < self.db.char.minItemLevelMisc) then
287+
if quality and ((equippable and quality < self.db.char.minItemLevel)
288+
or (not equippable and quality < self.db.char.minItemLevelMisc)) then
282289
return nil
283290
end
284291
local itype, isubtype = select(6, GetItemInfo(itemID)) -- old string based lookup
285292
local iclass, isubclass = select(12, GetItemInfo(itemID)) -- new class id based lookup
293+
294+
if C_PetJournal and not iclass then
295+
local name, icon, petType, creatureID, sourceText, description, isWild, canBattle, isTradeable, isUnique, obtainable, displayID, speciesID = C_PetJournal.GetPetInfoByItemID(itemID)
296+
if name then
297+
iclass, isubclass = speciesID, creatureID
298+
itype, isubtype = petType, name
299+
print(iclass, isubclass, itype, isubtype)
300+
end
301+
end
302+
if not itype or not iclass then
303+
return nil
304+
end
286305
for dest, rules in pairs(rulesCache) do
287306
local canddest
288307
if string.lower(dest) ~= string.lower(UnitName('player')) and (rules[itemID] or
289-
(rules[itype] and rules[itype][isubtype]) or
290-
(rules[iclass] and rules[iclass][isubclass])) then
308+
(itype and rules[itype] and rules[itype][isubtype]) or
309+
(iclass and rules[iclass] and rules[iclass][isubclass])) then
291310
canddest = dest
292311
end
293312
if canddest then
@@ -470,11 +489,11 @@ local function bulkToggleBagItem(bag, slot, itemLink)
470489
itemLink = itemLink or GetContainerItemLink(bag, slot)
471490

472491
if not itemLink then return end
473-
local itemId = tonumber(strmatch(itemLink, "item:(%d+)"))
492+
local itemId = linkToId(itemLink)
474493
local shouldRemove = sendCache and sendCache[bag] and sendCache[bag][slot]
475494
mod:Print(fmt(L["Attempting to %s all %s."], shouldRemove and L["remove"] or L["add"], itemLink))
476495
for addlBag, addlSlot, item in bagIter() do
477-
if tonumber(strmatch(item, "item:(%d+)")) == itemId then
496+
if linkToId(item) == itemId then
478497
if shouldRemove then
479498
sendCacheRemove(addlBag, addlSlot, true)
480499
elseif not sendCacheAdd(addlBag, addlSlot, true) then
@@ -1545,19 +1564,29 @@ function mod:ShowSendQueueGUI()
15451564
tooltip:SetCell(y, 1, L["Item Send Queue"], tooltip:GetFont(), "CENTER", 2)
15461565

15471566
tooltip:AddLine(" ")
1548-
15491567
if sendCache and next(sendCache) then
1550-
local itemLink, itemText, texture, qty
1568+
local itemLink, itemText, texture, qty, info
15511569
for bag, slots in pairs(sendCache) do
15521570
for slot in pairs(slots) do
15531571
itemLink = GetContainerItemLink(bag, slot)
15541572
if itemLink then
1555-
itemText = GetItemInfo(itemLink)
1556-
texture, qty = GetContainerItemInfo(bag, slot)
1573+
if C_Container then
1574+
info = C_Container.GetContainerItemInfo(bag, slot)
1575+
itemText = info.itemName
1576+
texture = info.iconFileID
1577+
qty = info.stackCount
1578+
else
1579+
if itemLink then
1580+
itemText = GetItemInfo(itemLink)
1581+
texture, qty = GetContainerItemInfo(bag, slot)
1582+
end
1583+
end
15571584
if qty and qty > 1 then
15581585
itemText = fmt("|T%s:18|t |cffffd200%s (%d)|r", texture, itemText, qty)
1559-
else
1586+
elseif itemText then
15601587
itemText = fmt("|T%s:18|t |cffffd200%s|r", texture, itemText)
1588+
else
1589+
itemText = itemLink -- shouldn't happen
15611590
end
15621591
local y = _addIndentedCell(tooltip, itemText, 5, function(self)
15631592
onSendQueueItemSelect(bag, slot)
@@ -1581,7 +1610,6 @@ function mod:ShowSendQueueGUI()
15811610
_addIndentedCell(tooltip, color(L["No items selected"], "ffd200"), 5)
15821611
end
15831612

1584-
15851613
tooltip:AddLine(" ")
15861614
local y = tooltip:AddLine();
15871615
tooltip:SetCell(y, 1, color(L["Drop items here for Sending"], "ffd200"), tooltip:GetFont(), "CENTER", 2)

0 commit comments

Comments
 (0)