annotate Queue.lua @ 36:58fb38f0b447

The list of possible commands when you write /im without any arguement will now include commands inserted by modules with their own descriptions. Clicking a command in this list will now execute it. The slash command handler function is now a global so you can invoke these through other methods. Added an optional event function to registering auction pricing addons, when defined this will be executed when the pricing addon gets selected. Removed the unused ?Override local item data? option. Added ?AuctionProfitMaster? and ?ZeroAuctions? pricing support. The pricing info displayed in the summary window will be used for this. Trying to queue without any items in the summary should no longer give an error.
author Zerotorescue
date Sat, 20 Nov 2010 17:24:16 +0100
parents e732843b16d2
children d903b0a151d3
rev   line source
Zerotorescue@17 1 local addon = select(2, ...);
Zerotorescue@13 2 local mod = addon:NewModule("Queue", "AceEvent-3.0", "AceTimer-3.0");
Zerotorescue@13 3
Zerotorescue@13 4 function mod:OnEnable()
Zerotorescue@13 5 -- Register our own slash commands
Zerotorescue@13 6 addon:RegisterSlash(function()
Zerotorescue@36 7 mod:QueueAll();
Zerotorescue@36 8 end, { "q", "que", "queue" }, "|Hfunction:InventoriumCommandHandler:queue|h|cff00fff7/im queue|r|h (or /im q) - Queue all items found in the currently opened profession that are within the groups tracked at this current character.");
Zerotorescue@14 9
Zerotorescue@14 10 self:RegisterMessage("IM_QUEUE_ALL");
Zerotorescue@14 11 self:RegisterMessage("IM_QUEUE_GROUP");
Zerotorescue@14 12 end
Zerotorescue@14 13
Zerotorescue@14 14 function mod:IM_QUEUE_ALL()
Zerotorescue@14 15 self:QueueAll();
Zerotorescue@14 16 end
Zerotorescue@14 17
Zerotorescue@14 18 function mod:IM_QUEUE_GROUP(event, groupName)
Zerotorescue@14 19 self:QueueGroup(groupName);
Zerotorescue@13 20 end
Zerotorescue@13 21
Zerotorescue@13 22 function mod:QueueAll()
Zerotorescue@14 23 local playerName = UnitName("player");
Zerotorescue@14 24
Zerotorescue@14 25 -- Go through all groups
Zerotorescue@14 26 for groupName, values in pairs(addon.db.global.groups) do
Zerotorescue@14 27 local trackAt = (values.trackAtCharacters or (values.trackAtCharacters == nil and addon.db.global.defaults.trackAtCharacters));
Zerotorescue@14 28
Zerotorescue@14 29 if trackAt[playerName] then
Zerotorescue@14 30 self:QueueGroup(groupName);
Zerotorescue@13 31 end
Zerotorescue@13 32 end
Zerotorescue@13 33 end
Zerotorescue@13 34
Zerotorescue@13 35 function mod:QueueGroup(groupName)
Zerotorescue@14 36 if not addon.db.global.groups[groupName] then
Zerotorescue@14 37 print(("Tried to queue items from a group named \"%s\", but no such group exists."):format(groupName));
Zerotorescue@14 38 return;
Zerotorescue@14 39 end
Zerotorescue@14 40
Zerotorescue@14 41 local temp = {};
Zerotorescue@13 42
Zerotorescue@13 43 -- Go through all trade skills for the profession
Zerotorescue@13 44 for i = 1, GetNumTradeSkills() do
Zerotorescue@13 45 -- Process every single tradeskill
Zerotorescue@14 46 self:ProcessTradeSkill(i, groupName, temp);
Zerotorescue@14 47 end
Zerotorescue@36 48
Zerotorescue@36 49 if addon.db.global.groups[groupName].items then
Zerotorescue@36 50 for itemId, _ in pairs(addon.db.global.groups[groupName].items) do
Zerotorescue@36 51 if not temp[itemId] then
Zerotorescue@36 52 local itemLink = select(2, GetItemInfo(itemId));
Zerotorescue@36 53
Zerotorescue@36 54 print("Couldn't queue " .. itemLink .. " (not part of this profession)");
Zerotorescue@36 55 end
Zerotorescue@14 56 end
Zerotorescue@13 57 end
Zerotorescue@13 58 end
Zerotorescue@13 59
Zerotorescue@14 60 function mod:ProcessTradeSkill(i, groupName, temp)
Zerotorescue@13 61 -- Try to retrieve the itemlink, this will be nil if current item is a group instead
Zerotorescue@13 62 local itemLink = GetTradeSkillItemLink(i);
Zerotorescue@13 63
Zerotorescue@13 64 if itemLink then
Zerotorescue@13 65 local itemId = addon:GetItemId(itemLink);
Zerotorescue@13 66 if not itemId then
Zerotorescue@13 67 -- If this isn't an item, it can only be an enchant instead
Zerotorescue@13 68 itemId = tonumber(itemLink:match("|Henchant:([-0-9]+)|h"));
Zerotorescue@13 69
Zerotorescue@17 70 itemId = addon.scrollIds[itemId]; -- change enchantIds into scrollIds
Zerotorescue@13 71 end
Zerotorescue@13 72
Zerotorescue@13 73 if addon.db.global.groups[groupName].items[itemId] then
Zerotorescue@13 74 -- This item is in this group, queue it!
Zerotorescue@13 75
Zerotorescue@14 76 if temp then
Zerotorescue@14 77 -- Remember which items have been processed
Zerotorescue@14 78 temp[itemId] = true;
Zerotorescue@14 79 end
Zerotorescue@13 80
Zerotorescue@23 81 local currentStock = addon:GetItemCount(itemId, groupName);
Zerotorescue@31 82
Zerotorescue@14 83 if currentStock >= 0 then
Zerotorescue@14 84 -- Current stock will be -1 when no itemcount addon was found
Zerotorescue@31 85
Zerotorescue@31 86 -- Retrieve group settings
Zerotorescue@17 87 local restockTarget = addon:GetOptionByKey(groupName, "restockTarget");
Zerotorescue@17 88 local bonusQueue = addon:GetOptionByKey(groupName, "bonusQueue");
Zerotorescue@17 89 local minCraftingQueue = floor( addon:GetOptionByKey(groupName, "minCraftingQueue") * restockTarget );
Zerotorescue@13 90
Zerotorescue@31 91 -- Calculate the amount to be queued
Zerotorescue@17 92 local amount = ( restockTarget - currentStock );
Zerotorescue@17 93
Zerotorescue@17 94 if currentStock == 0 and bonusQueue > 0 then
Zerotorescue@31 95 -- If we have none left and the bonus queue is enabled, modify the amount to be queued
Zerotorescue@31 96
Zerotorescue@17 97 amount = floor( ( amount * ( bonusQueue + 1 ) ) + .5 ); -- round
Zerotorescue@17 98 end
Zerotorescue@17 99
Zerotorescue@17 100 if amount > 0 and amount >= minCraftingQueue then
Zerotorescue@31 101 -- If we are queueing at least one AND more than the minimum amount, then proceed
Zerotorescue@14 102
Zerotorescue@31 103 -- Auction value settings
Zerotorescue@31 104 local priceThreshold = addon:GetOptionByKey(groupName, "priceThreshold");
Zerotorescue@31 105
Zerotorescue@31 106 if priceThreshold == 0 or addon:GetAuctionValue(itemLink, groupName) >= priceThreshold then
Zerotorescue@31 107 -- If no price threshold is set or the auction value is equal to or larger than the price threshold, then proceed
Zerotorescue@31 108
Zerotorescue@31 109 self:Queue(i, amount, groupName);
Zerotorescue@31 110
Zerotorescue@31 111 print("Queued " .. amount .. " of " .. itemLink);
Zerotorescue@31 112 end
Zerotorescue@14 113 end
Zerotorescue@14 114 else
Zerotorescue@14 115 print("No usable itemcount addon found.");
Zerotorescue@13 116 end
Zerotorescue@13 117 end
Zerotorescue@13 118 end
Zerotorescue@13 119 end
Zerotorescue@13 120
Zerotorescue@23 121 function mod:Queue(tradeSkillIndex, amount, group)
Zerotorescue@13 122 tradeSkillIndex = tonumber(tradeSkillIndex);
Zerotorescue@13 123 amount = tonumber(amount);
Zerotorescue@13 124
Zerotorescue@13 125 if not tradeSkillIndex or not amount then return; end
Zerotorescue@13 126
Zerotorescue@23 127 local selectedExternalAddon = addon:GetOptionByKey(group, "craftingAddon");
Zerotorescue@23 128
Zerotorescue@23 129 if addon.supportedAddons.crafting[selectedExternalAddon] and addon.supportedAddons.crafting[selectedExternalAddon].IsEnabled() then
Zerotorescue@13 130 -- Try to use the default auction pricing addon
Zerotorescue@13 131
Zerotorescue@23 132 return addon.supportedAddons.crafting[selectedExternalAddon].Queue(tradeSkillIndex, amount);
Zerotorescue@13 133 else
Zerotorescue@13 134 -- Default not available, get the first one then
Zerotorescue@13 135
Zerotorescue@13 136 for name, value in pairs(addon.supportedAddons.crafting) do
Zerotorescue@13 137 if value.IsEnabled() then
Zerotorescue@13 138 return value.Queue(tradeSkillIndex, amount);
Zerotorescue@13 139 end
Zerotorescue@13 140 end
Zerotorescue@13 141 end
Zerotorescue@13 142
Zerotorescue@13 143 return -2;
Zerotorescue@13 144 end