Neaten code

This commit is contained in:
Andrew Tomaka 2011-07-20 16:21:03 -04:00
parent 81a43d74d4
commit 3422a7a4f9

View file

@ -1,40 +1,40 @@
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
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','StackGems')
end end
function core:StackGems(_,message) function core:StackGems(_,message)
if(not string.find(message,'You create')) then return end; local lastTradeskill = message:match("%[(.-)%]")
local gem = message:match("%[(.-)%]"); local combineSlots = {}
local sourceContainer,sourceSlot,destContainer,destSlot = -1,-1,-1,-1; --loop through bags in reverse
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(gem == itemName and maxStack ~= 1) then
local _,count = GetContainerItemInfo(bag,slot); if lastTradeskill == itemName and maxStack ~= 1 then
if(count == 1 and sourceContainer < 0) then print('Found', itemName)
sourceContainer = bag; local _, count = GetContainerItemInfo(bag, slot)
sourceSlot = slot;
elseif(count < 20 and (count > 1 or destContainer < 0)) then if count < 20 and #combineSlots < 2 then
destContainer = bag; combineSlots[#combineSlots + 1] = { bag, slot }
destSlot = slot;
end end
end end
end end
end end
end end
if(sourceContainer ~= -1 and destContainer ~= -1) then --and then stack the gems
PickupContainerItem(sourceContainer,sourceSlot); if #combineSlots > 1 then
PickupContainerItem(destContainer,destSlot) PickupContainerItem(combineSlots[1][1], combineSlots[1][2])
PickupContainerItem(combineSlots[2][1], combineSlots[2][2])
end end
end end