Register second event to make sure item is in bag before we attempt to stack.
This commit is contained in:
parent
dd51c58cac
commit
e10f186b3c
1 changed files with 16 additions and 22 deletions
|
@ -1,16 +1,16 @@
|
||||||
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;
|
||||||
core.gems = {};
|
core.gems = {};
|
||||||
|
core.lastGem = false;
|
||||||
|
|
||||||
function core:OnInitialize()
|
function core:OnInitialize()
|
||||||
print('GemStacker: Initialized');
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function core:OnEnable()
|
function core:OnEnable()
|
||||||
print('GemStacker: Enabled');
|
|
||||||
|
|
||||||
core.gems['Puissant Dream Emerald'] = true;
|
core.gems['Puissant Dream Emerald'] = true;
|
||||||
|
|
||||||
|
--use chat_msg_loot later
|
||||||
self:RegisterEvent('UNIT_SPELLCAST_SUCCEEDED','FindGemCast');
|
self:RegisterEvent('UNIT_SPELLCAST_SUCCEEDED','FindGemCast');
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -18,47 +18,41 @@ function core:FindGemCast(_,unitId,spell,...)
|
||||||
print('GemStacker: Casted ',spell);
|
print('GemStacker: Casted ',spell);
|
||||||
--should receive something like "player","Reckless Ember Topaz","",2,73369
|
--should receive something like "player","Reckless Ember Topaz","",2,73369
|
||||||
if(unitId ~= 'player') then return end;
|
if(unitId ~= 'player') then return end;
|
||||||
print('GemStacker: Player casted spell.');
|
|
||||||
if(not core.gems[spell]) then return end;
|
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;
|
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
|
for slot = 1,GetContainerNumSlots(bag) do
|
||||||
print('GemStacker: Checking ',bag,slot);
|
|
||||||
itemId = GetContainerItemID(bag,slot)
|
itemId = GetContainerItemID(bag,slot)
|
||||||
if(itemId) then
|
if(itemId) then
|
||||||
itemName = GetItemInfo(itemId);
|
itemName = GetItemInfo(itemId);
|
||||||
if(spell == itemName) then
|
if(core.lastGem == itemName) then
|
||||||
print('GemStacker: Found gem in bag: ',bag,slot);
|
|
||||||
local _,count = GetContainerItemInfo(bag,slot);
|
local _,count = GetContainerItemInfo(bag,slot);
|
||||||
if(count == 1 and sourceContainer < 0) then
|
if(count == 1 and sourceContainer < 0) then
|
||||||
print('GemStacker: Found source');
|
|
||||||
sourceContainer = bag;
|
sourceContainer = bag;
|
||||||
sourceSlot = slot;
|
sourceSlot = slot;
|
||||||
elseif(count < 20 and (count > 1 or destContainer < 0)) then
|
elseif(count < 20 and (count > 1 or destContainer < 0)) then
|
||||||
print('GemStacker: Found dest');
|
|
||||||
destContainer = bag;
|
destContainer = bag;
|
||||||
destSlot = slot;
|
destSlot = slot;
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
|
||||||
print('GemStacker: ',bag,slot,'emptry');
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if(sourceContainer < 0 and destContainer < 0) then
|
if(sourceContainer ~= -1 and destContainer ~= -1) then
|
||||||
print('GemStacker: Stacking');
|
|
||||||
PickupContainerItem(sourceContainer,sourceSlot);
|
PickupContainerItem(sourceContainer,sourceSlot);
|
||||||
PickupContainerItem(destContainer,destSlot)
|
PickupContainerItem(destContainer,destSlot)
|
||||||
end
|
end
|
||||||
|
|
||||||
--self:RegisterEvent('BAG_UPDATE','StackGem');
|
|
||||||
end
|
|
||||||
|
|
||||||
function core:StackGem(...)
|
|
||||||
|
|
||||||
|
|
||||||
|
core.lastGem = false;
|
||||||
self:UnregisterEvent('BAG_UPDATE');
|
self:UnregisterEvent('BAG_UPDATE');
|
||||||
end
|
end
|
Loading…
Reference in a new issue