Use CHAT_MSG_LOOT as event.

This commit is contained in:
Andrew Tomaka 2011-06-29 19:42:08 -04:00
parent e10f186b3c
commit 5e8578454a

View file

@ -1,40 +1,27 @@
GemStacker = LibStub('AceAddon-3.0'):NewAddon('GemStacker','AceConsole-3.0','AceEvent-3.0');
local core = GemStacker;
core.gems = {};
core.lastGem = false;
function core:OnInitialize()
end
function core:OnEnable()
core.gems['Puissant Dream Emerald'] = true;
--use chat_msg_loot later
self:RegisterEvent('UNIT_SPELLCAST_SUCCEEDED','FindGemCast');
self:RegisterEvent('CHAT_MSG_LOOT','StackGems');
end
function core:FindGemCast(_,unitId,spell,...)
print('GemStacker: Casted ',spell);
function core:StackGems(_,message)
--should receive something like "player","Reckless Ember Topaz","",2,73369
if(unitId ~= 'player') then return end;
if(not core.gems[spell]) then return end;
core.lastGem = spell;
self:RegisterEvent('BAG_UPDATE','StackGem');
end
if(not string.find(message,'You create')) then return end;
local gem = message:match("%[(.-)%]");
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,4 do
for slot = 1,GetContainerNumSlots(bag) do
itemId = GetContainerItemID(bag,slot)
if(itemId) then
itemName = GetItemInfo(itemId);
if(core.lastGem == itemName) then
if(gem == itemName) then
local _,count = GetContainerItemInfo(bag,slot);
if(count == 1 and sourceContainer < 0) then
sourceContainer = bag;
@ -51,8 +38,5 @@ function core:StackGem(...)
if(sourceContainer ~= -1 and destContainer ~= -1) then
PickupContainerItem(sourceContainer,sourceSlot);
PickupContainerItem(destContainer,destSlot)
end
core.lastGem = false;
self:UnregisterEvent('BAG_UPDATE');
end
end