view Queue.lua @ 14:0fc8a54516d7

Altoholic is now marked as an optional dependency. Fixed the queue button so it doesn?t get recreated when a widget is re-used from the pool. Queue all button and queue single group buttons are now working. Items within a group being queued that couldn?t be found in the current profession will be announced. The goal is to put these into a new window from which you can queue these.
author Zerotorescue
date Mon, 18 Oct 2010 19:31:52 +0200
parents 5006cb0e97c6
children 8f5c02113c5c
line wrap: on
line source
local addon = LibStub("AceAddon-3.0"):GetAddon("Inventorium");
local mod = addon:NewModule("Queue", "AceEvent-3.0", "AceTimer-3.0");

local scrollIds = {
	[27951] = 37603,
	[7418] = 38679,
	[7420] = 38766,
	[7426] = 38767,
	[7428] = 38768,
	[7443] = 38769,
	[7454] = 38770,
	[7457] = 38771,
	[7745] = 38772,
	[7748] = 38773,
	[7766] = 38774,
	[7771] = 38775,
	[7776] = 38776,
	[7779] = 38777,
	[7782] = 38778,
	[7786] = 38779,
	[7788] = 38780,
	[7793] = 38781,
	[7857] = 38782,
	[7859] = 38783,
	[7861] = 38784,
	[7863] = 38785,
	[7867] = 38786,
	[13378] = 38787,
	[13380] = 38788,
	[13419] = 38789,
	[13421] = 38790,
	[13464] = 38791,
	[13485] = 38792,
	[13501] = 38793,
	[13503] = 38794,
	[13522] = 38795,
	[13529] = 38796,
	[13536] = 38797,
	[13538] = 38798,
	[13607] = 38799,
	[13612] = 38800,
	[13617] = 38801,
	[13620] = 38802,
	[13622] = 38803,
	[13626] = 38804,
	[13631] = 38805,
	[13635] = 38806,
	[13637] = 38807,
	[13640] = 38808,
	[13642] = 38809,
	[13644] = 38810,
	[13646] = 38811,
	[13648] = 38812,
	[13653] = 38813,
	[13655] = 38814,
	[13657] = 38815,
	[13659] = 38816,
	[13661] = 38817,
	[13663] = 38818,
	[13687] = 38819,
	[13689] = 38820,
	[13693] = 38821,
	[13695] = 38822,
	[13698] = 38823,
	[13700] = 38824,
	[13746] = 38825,
	[13794] = 38826,
	[13815] = 38827,
	[13817] = 38828,
	[13822] = 38829,
	[13836] = 38830,
	[13841] = 38831,
	[13846] = 38832,
	[13858] = 38833,
	[13868] = 38834,
	[13882] = 38835,
	[13887] = 38836,
	[13890] = 38837,
	[13898] = 38838,
	[13905] = 38839,
	[13915] = 38840,
	[13917] = 38841,
	[13931] = 38842,
	[13933] = 38843,
	[13935] = 38844,
	[13937] = 38845,
	[13939] = 38846,
	[13941] = 38847,
	[13943] = 38848,
	[13945] = 38849,
	[13947] = 38850,
	[13948] = 38851,
	[20008] = 38852,
	[20009] = 38853,
	[20010] = 38854,
	[20011] = 38855,
	[20012] = 38856,
	[20013] = 38857,
	[20014] = 38858,
	[20015] = 38859,
	[20016] = 38860,
	[20017] = 38861,
	[20020] = 38862,
	[20023] = 38863,
	[20024] = 38864,
	[20025] = 38865,
	[20026] = 38866,
	[20028] = 38867,
	[20029] = 38868,
	[20030] = 38869,
	[20031] = 38870,
	[20032] = 38871,
	[20033] = 38872,
	[20034] = 38873,
	[20035] = 38874,
	[20036] = 38875,
	[21931] = 38876,
	[22749] = 38877,
	[22750] = 38878,
	[23799] = 38879,
	[23800] = 38880,
	[23801] = 38881,
	[23802] = 38882,
	[23803] = 38883,
	[23804] = 38884,
	[25072] = 38885,
	[25073] = 38886,
	[25074] = 38887,
	[25078] = 38888,
	[25079] = 38889,
	[25080] = 38890,
	[25081] = 38891,
	[25082] = 38892,
	[25083] = 38893,
	[25084] = 38894,
	[25086] = 38895,
	[27837] = 38896,
	[27899] = 38897,
	[27905] = 38898,
	[27906] = 38899,
	[27911] = 38900,
	[27913] = 38901,
	[27914] = 38902,
	[27917] = 38903,
	[27944] = 38904,
	[27945] = 38905,
	[27946] = 38906,
	[27947] = 38907,
	[27948] = 38908,
	[27950] = 38909,
	[27954] = 38910,
	[27957] = 38911,
	[27958] = 38912,
	[27960] = 38913,
	[27961] = 38914,
	[27962] = 38915,
	[27967] = 38917,
	[27968] = 38918,
	[27971] = 38919,
	[27972] = 38920,
	[27975] = 38921,
	[27977] = 38922,
	[27981] = 38923,
	[27982] = 38924,
	[27984] = 38925,
	[28003] = 38926,
	[28004] = 38927,
	[33990] = 38928,
	[33991] = 38929,
	[33992] = 38930,
	[33993] = 38931,
	[33994] = 38932,
	[33995] = 38933,
	[33996] = 38934,
	[33997] = 38935,
	[33999] = 38936,
	[34001] = 38937,
	[34002] = 38938,
	[34003] = 38939,
	[34004] = 38940,
	[34005] = 38941,
	[34006] = 38942,
	[34007] = 38943,
	[34008] = 38944,
	[34009] = 38945,
	[34010] = 38946,
	[42620] = 38947,
	[42974] = 38948,
	[44383] = 38949,
	[44483] = 38950,
	[44484] = 38951,
	[44488] = 38953,
	[44489] = 38954,
	[44492] = 38955,
	[44494] = 38956,
	[44500] = 38959,
	[44506] = 38960,
	[44508] = 38961,
	[44509] = 38962,
	[44510] = 38963,
	[44513] = 38964,
	[44524] = 38965,
	[44528] = 38966,
	[44529] = 38967,
	[44555] = 38968,
	[44556] = 38969,
	[60616] = 38971,
	[44576] = 38972,
	[44582] = 38973,
	[44584] = 38974,
	[44588] = 38975,
	[44589] = 38976,
	[44590] = 38977,
	[44591] = 38978,
	[44592] = 38979,
	[44593] = 38980,
	[44595] = 38981,
	[44596] = 38982,
	[44598] = 38984,
	[60623] = 38986,
	[44616] = 38987,
	[44621] = 38988,
	[44623] = 38989,
	[44625] = 38990,
	[44629] = 38991,
	[44630] = 38992,
	[44631] = 38993,
	[44633] = 38995,
	[44635] = 38997,
	[46578] = 38998,
	[46594] = 38999,
	[47051] = 39000,
	[47672] = 39001,
	[47766] = 39002,
	[47898] = 39003,
	[47899] = 39004,
	[47900] = 39005,
	[47901] = 39006,
	[59625] = 43987,
	[60606] = 44449,
	[60621] = 44453,
	[60653] = 44455,
	[60609] = 44456,
	[60663] = 44457,
	[60668] = 44458,
	[60691] = 44463,
	[60692] = 44465,
	[60707] = 44466,
	[60714] = 44467,
	[60763] = 44469,
	[60767] = 44470,
	[59621] = 44493,
	[59619] = 44497,
	[44575] = 44815,
	[62256] = 44947,
	[62948] = 45056,
	[62959] = 45060,
	[63746] = 45628,
	[64441] = 46026,
	[64579] = 46098,
	[71692] = 50816,
};--enchantId=scrollId

function mod:OnEnable()
	-- Register our own slash commands
	addon:RegisterSlash(function()
		self:QueueAll();
	end, "q", "que", "queue");
	
	self:RegisterMessage("IM_QUEUE_ALL");
	self:RegisterMessage("IM_QUEUE_GROUP");
end

function mod:IM_QUEUE_ALL()
	self:QueueAll();
end

function mod:IM_QUEUE_GROUP(event, groupName)
	self:QueueGroup(groupName);
end

function mod:QueueAll()
	local playerName = UnitName("player");
	
	-- Go through all groups
	for groupName, values in pairs(addon.db.global.groups) do
		local trackAt = (values.trackAtCharacters or (values.trackAtCharacters == nil and addon.db.global.defaults.trackAtCharacters));
		
		if trackAt[playerName] then
			self:QueueGroup(groupName);
		end
	end
end

function mod:QueueGroup(groupName)
	if not addon.db.global.groups[groupName] then
		print(("Tried to queue items from a group named \"%s\", but no such group exists."):format(groupName));
		return;
	end
	
	local temp = {};
	
	-- Go through all trade skills for the profession
	for i = 1, GetNumTradeSkills() do
		-- Process every single tradeskill
		self:ProcessTradeSkill(i, groupName, temp);
	end
		
	for itemId, _ in pairs(addon.db.global.groups[groupName].items) do
		if not temp[itemId] then
			local itemLink = select(2, GetItemInfo(itemId));
			print("Couldn't queue " .. itemLink);
		end
	end
end

function mod:ProcessTradeSkill(i, groupName, temp)
	-- Try to retrieve the itemlink, this will be nil if current item is a group instead
	local itemLink = GetTradeSkillItemLink(i);
	
	if itemLink then
		local itemId = addon:GetItemId(itemLink);
		if not itemId then
			-- If this isn't an item, it can only be an enchant instead
			itemId = tonumber(itemLink:match("|Henchant:([-0-9]+)|h"));
			
			itemId = scrollIds[itemId]; -- change enchantIds into scrollIds
		end
		
		if addon.db.global.groups[groupName].items[itemId] then
			-- This item is in this group, queue it!
			
			if temp then
				-- Remember which items have been processed
				temp[itemId] = true;
			end
			
			local currentStock = addon:GetItemCount(itemId);
			if currentStock >= 0 then
				-- Current stock will be -1 when no itemcount addon was found
				local amount = ( addon:GetOptionByKey(groupName, "restockTarget") - currentStock );
				
				if amount > 0 then
					self:Queue(i, amount);
					
					print("Queued " .. amount .. " of " .. itemLink);
				end
			else
				print("No usable itemcount addon found.");
			end
		end
	end
end

function mod:Queue(tradeSkillIndex, amount)
	tradeSkillIndex = tonumber(tradeSkillIndex);
	amount = tonumber(amount);
	
	if not tradeSkillIndex or not amount then return; end
	
	if addon.supportedAddons.crafting[addon.db.global.defaults.craftingAddon] then
		-- Try to use the default auction pricing addon
		
		return addon.supportedAddons.crafting[addon.db.global.defaults.craftingAddon].Queue(tradeSkillIndex, amount);
	else
		-- Default not available, get the first one then
		
		for name, value in pairs(addon.supportedAddons.crafting) do
			if value.IsEnabled() then
				return value.Queue(tradeSkillIndex, amount);
			end
		end
	end
	
	return -2;
end