Beginning of queue messing around. NYF

This commit is contained in:
Andrew Tomaka 2011-07-21 15:26:34 -04:00
parent 3422a7a4f9
commit 3cebb8ffb8

View file

@ -1,27 +1,60 @@
GemStacker = LibStub('AceAddon-3.0'):NewAddon('GemStacker','AceConsole-3.0','AceEvent-3.0') GemStacker = LibStub('AceAddon-3.0'):NewAddon('GemStacker','AceConsole-3.0','AceEvent-3.0')
local core = GemStacker local core = GemStacker
local queue = {}
function core:OnInitialize() function core:OnInitialize()
end end
function core:OnEnable() function core:OnEnable()
self:RegisterEvent('CHAT_MSG_LOOT','StackGems') self:RegisterEvent('CHAT_MSG_LOOT','TrackGems')
self:RegisterEvent('ITEM_PUSH','StackGems')
end end
function core:StackGems(_,message) function core:TrackGems(_,message)
local lastTradeskill = message:match("%[(.-)%]") print('track gems')
local combineSlots = {} -- Get the gem we just cut
local tradeskill = message:match("%[(.-)%]")
--loop through bags in reverse
local destination = {false,false};
-- Find the biggest, non-full stack we can find
for bag = 0, NUM_BAG_SLOTS do for bag = 0, NUM_BAG_SLOTS do
for slot = 1, GetContainerNumSlots(bag) do for slot = 1, GetContainerNumSlots(bag) do
local itemID = GetContainerItemID(bag, slot) local itemID = GetContainerItemID(bag, slot)
if(itemID) then if(itemID) then
local itemName, _, _, _, _, _, _, maxStack = GetItemInfo(itemID) local itemName, _, _, _, _, _, _, maxStack = GetItemInfo(itemID)
if lastTradeskill == itemName and maxStack ~= 1 then if tradeskill == itemName and maxStack ~= 1 then
print('Found', itemName) local _, count = GetContainerItemInfo(bag, slot)
-- Find the biggest, non-full stack we can
if(count < maxStack) then
table.insert(queue, itemID)
end
end
end
end
end
core:StackGems()
end
function core:StackGems()
print('stackgems:')
local _, stackItemID = next(queue)
if not stackItemID then return end
print('stacking gem',stackItemID)
local combineSlots = {}
for bag = 0, NUM_BAG_SLOTS do
for slot = 1, GetContainerNumSlots(bag) do
local itemID = GetContainerItemID(bag, slot)
if(itemID) then
local itemName, _, _, _, _, _, _, maxStack = GetItemInfo(itemID)
if itemID == stackItemID and maxStack ~= 1 then
print('Found', itemName,bag,slot)
local _, count = GetContainerItemInfo(bag, slot) local _, count = GetContainerItemInfo(bag, slot)
if count < 20 and #combineSlots < 2 then if count < 20 and #combineSlots < 2 then
@ -34,7 +67,11 @@ function core:StackGems(_,message)
--and then stack the gems --and then stack the gems
if #combineSlots > 1 then if #combineSlots > 1 then
PickupContainerItem(combineSlots[1][1], combineSlots[1][2]) PickupContainerItem(combineSlots[1][1], combineSlots[1][2])
PickupContainerItem(combineSlots[2][1], combineSlots[2][2]) PickupContainerItem(combineSlots[2][1], combineSlots[2][2])
queue[stackItemID] = nil
elseif #combineSlots == 0 then
queue[stackItemID] = nil
end end
end end