Register second event to make sure item is in bag before we attempt to stack.

This commit is contained in:
Andrew Tomaka 2011-06-29 18:28:19 -04:00
parent dd51c58cac
commit e10f186b3c

View file

@ -1,16 +1,16 @@
GemStacker = LibStub('AceAddon-3.0'):NewAddon('GemStacker','AceConsole-3.0','AceEvent-3.0');
local core = GemStacker;
core.gems = {};
core.lastGem = false;
function core:OnInitialize()
print('GemStacker: Initialized');
end
function core:OnEnable()
print('GemStacker: Enabled');
core.gems['Puissant Dream Emerald'] = true;
--use chat_msg_loot later
self:RegisterEvent('UNIT_SPELLCAST_SUCCEEDED','FindGemCast');
end
@ -18,47 +18,41 @@ function core:FindGemCast(_,unitId,spell,...)
print('GemStacker: Casted ',spell);
--should receive something like "player","Reckless Ember Topaz","",2,73369
if(unitId ~= 'player') then return end;
print('GemStacker: Player casted spell.');
if(not core.gems[spell]) then return end;
print('GemStacker: Gem found');
core.lastGem = spell;
self:RegisterEvent('BAG_UPDATE','StackGem');
end
function core:StackGem(...)
print('GemStacker: StackGem');
if(not core.lastGem) then return end;
local sourceContainer,sourceSlot,destContainer,destSlot = -1,-1,-1,-1;
for bag = 0,1 do
for bag = 0,4 do
for slot = 1,GetContainerNumSlots(bag) do
print('GemStacker: Checking ',bag,slot);
itemId = GetContainerItemID(bag,slot)
if(itemId) then
itemName = GetItemInfo(itemId);
if(spell == itemName) then
print('GemStacker: Found gem in bag: ',bag,slot);
if(core.lastGem == itemName) then
local _,count = GetContainerItemInfo(bag,slot);
if(count == 1 and sourceContainer < 0) then
print('GemStacker: Found source');
sourceContainer = bag;
sourceSlot = slot;
elseif(count < 20 and (count > 1 or destContainer < 0)) then
print('GemStacker: Found dest');
destContainer = bag;
destSlot = slot;
end
end
else
print('GemStacker: ',bag,slot,'emptry');
end
end
end
if(sourceContainer < 0 and destContainer < 0) then
print('GemStacker: Stacking');
if(sourceContainer ~= -1 and destContainer ~= -1) then
PickupContainerItem(sourceContainer,sourceSlot);
PickupContainerItem(destContainer,destSlot)
end
--self:RegisterEvent('BAG_UPDATE','StackGem');
end
function core:StackGem(...)
end
core.lastGem = false;
self:UnregisterEvent('BAG_UPDATE');
end