|
|
|
@ -499,6 +499,7 @@ function Inbox:CollectItems(items, callback) |
|
|
|
|
|
|
|
|
|
|
|
local remaining = CopyTable(items) |
|
|
|
local remaining = CopyTable(items) |
|
|
|
local collected = false |
|
|
|
local collected = false |
|
|
|
|
|
|
|
local candidates = {} |
|
|
|
for i = GetInboxNumItems(), 1, -1 do |
|
|
|
for i = GetInboxNumItems(), 1, -1 do |
|
|
|
local _, _, _, _, _, cod, _, hasItem = GetInboxHeaderInfo(i) |
|
|
|
local _, _, _, _, _, cod, _, hasItem = GetInboxHeaderInfo(i) |
|
|
|
if hasItem and hasItem > 0 and (not cod or cod == 0) then |
|
|
|
if hasItem and hasItem > 0 and (not cod or cod == 0) then |
|
|
|
@ -508,10 +509,33 @@ function Inbox:CollectItems(items, callback) |
|
|
|
local need = itemString and remaining[itemString] |
|
|
|
local need = itemString and remaining[itemString] |
|
|
|
if need and need > 0 then |
|
|
|
if need and need > 0 then |
|
|
|
local quantity = select(3, GetInboxItem(i, j)) or 0 |
|
|
|
local quantity = select(3, GetInboxItem(i, j)) or 0 |
|
|
|
if quantity > 0 and (quantity <= need or not HasFittableStack(itemString, need)) then |
|
|
|
if quantity > 0 then |
|
|
|
if CanLootItem(itemString, quantity) then |
|
|
|
if not candidates[itemString] then |
|
|
|
TakeInboxItem(i, j) |
|
|
|
candidates[itemString] = {} |
|
|
|
remaining[itemString] = max(need - quantity, 0) |
|
|
|
end |
|
|
|
|
|
|
|
tinsert(candidates[itemString], { index = i, itemIndex = j, quantity = quantity }) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for itemString, entries in pairs(candidates) do |
|
|
|
|
|
|
|
table.sort(entries, function(a, b) |
|
|
|
|
|
|
|
if a.quantity ~= b.quantity then |
|
|
|
|
|
|
|
return a.quantity < b.quantity |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
return a.index > b.index |
|
|
|
|
|
|
|
end) |
|
|
|
|
|
|
|
for _, entry in ipairs(entries) do |
|
|
|
|
|
|
|
local need = remaining[itemString] |
|
|
|
|
|
|
|
if not need or need <= 0 then |
|
|
|
|
|
|
|
break |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
if entry.quantity > 0 and (entry.quantity <= need or not HasFittableStack(itemString, need)) then |
|
|
|
|
|
|
|
if CanLootItem(itemString, entry.quantity) then |
|
|
|
|
|
|
|
TakeInboxItem(entry.index, entry.itemIndex) |
|
|
|
|
|
|
|
remaining[itemString] = max(need - entry.quantity, 0) |
|
|
|
collected = true |
|
|
|
collected = true |
|
|
|
elseif callback then |
|
|
|
elseif callback then |
|
|
|
callback(L["Cannot finish auto looting, inventory is full or too many unique items."]) |
|
|
|
callback(L["Cannot finish auto looting, inventory is full or too many unique items."]) |
|
|
|
@ -520,8 +544,6 @@ function Inbox:CollectItems(items, callback) |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- Keep looting as new mail indexes shift, while preserving 1 free slot. |
|
|
|
-- Keep looting as new mail indexes shift, while preserving 1 free slot. |
|
|
|
if collected then |
|
|
|
if collected then |
|
|
|
|