From abfc111a7833fff617e2b4409d8bf92549d7ca54 Mon Sep 17 00:00:00 2001 From: atomaka Date: Mon, 25 Jul 2011 14:34:44 -0400 Subject: [PATCH] Revert to last released version --- GemStacker.lua | 85 +++++++++++++++----------------------------------- 1 file changed, 25 insertions(+), 60 deletions(-) diff --git a/GemStacker.lua b/GemStacker.lua index d16291c..abb7412 100644 --- a/GemStacker.lua +++ b/GemStacker.lua @@ -1,77 +1,42 @@ -GemStacker = LibStub('AceAddon-3.0'):NewAddon('GemStacker','AceConsole-3.0','AceEvent-3.0') -local core = GemStacker -local queue = {} +GemStacker = LibStub('AceAddon-3.0'):NewAddon('GemStacker','AceConsole-3.0','AceEvent-3.0'); +local core = GemStacker; function core:OnInitialize() end function core:OnEnable() - self:RegisterEvent('CHAT_MSG_LOOT','TrackGems') - self:RegisterEvent('ITEM_PUSH','StackGems') + self:RegisterEvent('CHAT_MSG_LOOT','StackGems') end -function core:TrackGems(_,message) - print('track gems') - -- Get the gem we just cut - local tradeskill = message:match("%[(.-)%]") +function core:StackGems(_,message) + --LOOT_ITEM_CREATED_SELF = "You create: %s."; + print('stack gems') + --local gem = message:match(LOOT_ITEM_CREATED_SELF) + print('found gem',gem) - local destination = {false,false}; - -- Find the biggest, non-full stack we can find - 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 tradeskill == itemName and maxStack ~= 1 then - local _, count = GetContainerItemInfo(bag, slot) - - -- Find the biggest, non-full stack we can - if(count < maxStack) then - table.insert(queue, itemID) + local sourceContainer,sourceSlot,destContainer,destSlot = -1,-1,-1,-1; + 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 gem == itemName and maxStack ~= 1 then + local _,count = GetContainerItemInfo(bag,slot) + if count == 1 and sourceContainer < 0 then + sourceContainer = bag + sourceSlot = slot + elseif count < 20 and (count > 1 or destContainer < 0) then + destContainer = bag + destSlot = slot 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) - - if count < 20 and #combineSlots < 2 then - combineSlots[#combineSlots + 1] = { bag, slot } - end - end - end - end - end - - --and then stack the gems - if #combineSlots > 1 then - PickupContainerItem(combineSlots[1][1], combineSlots[1][2]) - PickupContainerItem(combineSlots[2][1], combineSlots[2][2]) - - queue[stackItemID] = nil - elseif #combineSlots == 0 then - queue[stackItemID] = nil + if sourceContainer ~= -1 and destContainer ~= -1 then + PickupContainerItem(sourceContainer,sourceSlot) + PickupContainerItem(destContainer,destSlot) end end \ No newline at end of file