return false |
end |
|
local function RestackBags(loc) |
local changed = false |
for _, bag in pairs(container[loc]) do |
for slot = 1, GetContainerNumSlots(bag) do |
while true do |
local locked = select(3, GetContainerItemInfo(bag, slot)) |
if locked then |
coroutine.yield() |
--[[ main function ]] |
function kRestack(loc, nowarn, tab) |
if loc ~= "bags" and loc ~= "bank" and loc ~= "guild" then |
--[[ more slash commands ]] |
if loc == "resume" then |
if coroutine.status(restacker) == "suspended" then |
print(kR..col.w, "Resuming suspended thread.") |
coroutine.resume(restacker) |
else |
print(kR..col.w, "No suspended threads to resume.") |
end |
else |
loc = select(3, strfind(loc, "auto (%a+)")) |
if loc == "bags" or loc == "bank" or loc == "guild" then |
local togl |
if not AutoRestack[loc] then |
AutoRestack[loc] = true |
togl = col.g.."ON" |
else |
break |
AutoRestack[loc] = false |
togl = col.r.."OFF" |
end |
end |
loc = loc == "bags" and "your backpack" or loc |
loc = loc == "bank" and "your bank" or loc |
loc = loc == "guild" and "the guild vault" or loc |
print(kR, "Auto-stacking for", loc, "toggled", togl) |
else |
local bags = AutoRestack.bags and col.g or col.r |
local bank = AutoRestack.bank and col.g or col.r |
local guild = AutoRestack.guild and col.g or col.r |
|
local item = GetContainerItemLink(bag, slot) |
|
if item then |
local itemId = DecodeItemId(item) |
local stack = select(8, GetItemInfo(itemId)) |
local count = select(2, GetContainerItemInfo(bag, slot)) |
|
if stack > count then |
local locked, ok, pb, ps, pc |
|
while true do |
ok, pbag, pslot = RestackFindPartial(bag, slot, itemId, loc) |
locked = ok and select(3, GetContainerItemInfo(pbag, pslot)) or false |
|
if locked then |
coroutine.yield() |
else |
break |
end |
end |
|
if ok then |
ClearCursor() |
PickupContainerItem(pbag, pslot) |
PickupContainerItem(bag, slot) |
ClearCursor() |
changed = true |
end |
end |
print(kR, "Usage:") |
print(col.w.."- /restack [bags, bank, guild] - Run restacker manually") |
print(col.w.."- /restack auto ["..bags.."bags"..col.w..",", bank.."bank"..col.w..",", guild.."guild"..col.w.."] - Toggle auto-stacking") |
end |
end |
end |
return changed |
end |
|
function kRestack(loc, nowarn) |
if loc ~= "bags" and loc ~= "bank" then |
local col = { w = "|cffFFFFFF", g = "|cff55FF55", r = "|cffFF5555" } |
local krstr = "|cff44CCFFk|cffFFFFAARestack"..col.w |
if loc == "auto" then |
local togl |
if not AutoRestack then |
AutoRestack = true |
togl = col.g.."ON" |
else |
AutoRestack = false |
togl = col.r.."OFF" |
end |
print(krstr, "Auto-stacking toggled", togl) |
else |
local status = AutoRestack and col.g.."on" or col.r.."off" |
print(krstr, "Usage:") |
print("- /restack [bags, bank]") |
print("- /restack auto - toggles auto-stacking ("..status..col.w..")") |
end |
|
do return end |
end |
|
|
if type(restacker) ~= "thread" or coroutine.status(restacker) == "dead" then |
frame:SetScript("OnUpdate", function() |
if type(restacker) == "thread" then coroutine.resume(restacker) end |
end) |
restacker = coroutine.create(function() |
--[[ core restacking function ]] |
local changed = true |
while changed == true do |
changed = RestackBags(loc) |
end |
|
for _, bag in pairs(container[loc]) do |
local _, bt = GetContainerNumFreeSlots(bag) |
if bt ~= 0 then |
for slot = 1, GetContainerNumSlots(bag) do |
while true do |
local locked = select( 3, GetContainerItemInfo(bag, slot)) |
while changed do |
changed = false |
vault = loc == "guild" |
if vault then |
vbag = tab or GetCurrentGuildBankTab() |
local _, _, isViewable, canDeposit = GetGuildBankTabInfo(vbag) |
if not (IsGuildLeader() or (isViewable and canDeposit)) then break end |
end |
for _, bag in pairs(container[loc]) do |
bag = vault and vbag or bag |
for slot = 1, (vault and MAX_GUILDBANK_SLOTS_PER_TAB or GetContainerNumSlots(bag)) do |
while true and not vault do |
local locked = select(3, GetContainerItemInfo(bag, slot)) |
if locked then coYield(loc, bag, slot) else break end |
end |
local item = vault and GetGuildBankItemLink(bag, slot) or GetContainerItemLink(bag, slot) |
if item then |
local itemid = select(3, strfind(item, "item:(%d+)")) |
local stack = select(8, GetItemInfo(itemid)) |
local count = vault and select(2, GetGuildBankItemInfo(bag, slot)) or select(2, GetContainerItemInfo(bag, slot)) |
local moved = false |
|
if locked then |
coroutine.yield() |
else |
break |
--[[ do "special" things with "special" items by moving them to "special" bags ]] |
if not vault then |
for _, sbag in pairs(container[loc]) do |
if sbag > 0 and GetContainerNumSlots(sbag) > 0 then |
local bagID = ContainerIDToInventoryID(sbag) |
local bagType = GetItemFamily(GetInventoryItemLink("player", bagID)) |
local itemType = GetItemFamily(item) |
if bagType > 0 and bagType == itemType and bag ~= sbag then |
PickupContainerItem(bag, slot) |
PutItemInBag(bagID) |
moved = true |
end |
end |
end |
end |
end |
|
local item = GetContainerItemLink(bag, slot) |
|
if not item then |
local locked, ok, sbag, sslot |
|
while true do |
ok, sbag, sslot = RestackFindSpecial(bt, loc) |
locked = ok and select(3, GetContainerItemInfo(sbag, sslot)) or false |
|
if locked then |
coroutine.yield() |
else |
break |
|
if count < stack and not moved then |
--[[ found a partial stack ]] |
local locked, found, pbag, pslot |
while true do |
--[[ look for another partial stack ]] |
found, pbag, pslot = getPartial(bag, slot, itemid, loc) |
if vault then break end |
locked = found and select(3, GetContainerItemInfo(pbag, pslot)) or false |
if locked then coYield(loc, pbag, pslot) else break end |
end |
|
if found then |
--[[ stack 'em up ]] |
ClearCursor() |
if vault then |
PickupGuildBankItem(pbag, pslot) |
PickupGuildBankItem(bag, slot) |
ClearCursor() |
coYield(loc, bag, slot, count) |
else |
PickupContainerItem(pbag, pslot) |
PickupContainerItem(bag, slot) |
end |
changed = true |
end |
end |
|
if ok then |
ClearCursor() |
PickupContainerItem(sbag, sslot) |
PickupContainerItem(bag, slot) |
ClearCursor() |
end |
end |
end |
end |
end |
frame:SetScript("OnUpdate", function() end) |
--[[ turn off yielding function ]] |
frame:SetScript("OnUpdate", nil) |
end) |
coroutine.resume(restacker) |
else |
if not nowarn then |
print("|cff33A1DEk|cffFFFFFFRestack |cffFF5555Restacking is already in progress, please wait.") |
--[[ user is impatient or there is a stall, tell them so ]] |
print(kR..col.r, "Restacking is already in progress. (use '/restack resume' if stuck)") |
end |
end |
end |
end |