annotate Queue.lua @ 62:fee06221176f

Seperated the config from Core.lua. Many other code cleaning up for readability. Added local references for much used globals. Moved widgets to a different file for readability. Re-added global function for slash command handling since we do need it for our chat-hyperlinks. Fixed queueing to properly use the track at property of virtual groups. Fixed queueing to display the item id instead of the item link if the item link could not be loaded. Speed slider at the summary now has an interval of 1% down from 5% and rounds rather than ceils it?s value so 101% will become 100% rather than 105%. Now using the right stock properties at the summary. Added a help group to the config.
author Zerotorescue
date Wed, 22 Dec 2010 19:56:55 +0100
parents d903b0a151d3
children 2127ab01ed4a
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@62 4 local pairs = pairs;
Zerotorescue@62 5
Zerotorescue@13 6 function mod:OnEnable()
Zerotorescue@13 7 -- Register our own slash commands
Zerotorescue@62 8 -- /im queue
Zerotorescue@13 9 addon:RegisterSlash(function()
Zerotorescue@36 10 mod:QueueAll();
Zerotorescue@36 11 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 12
Zerotorescue@14 13 self:RegisterMessage("IM_QUEUE_ALL");
Zerotorescue@14 14 self:RegisterMessage("IM_QUEUE_GROUP");
Zerotorescue@14 15 end
Zerotorescue@14 16
Zerotorescue@14 17 function mod:IM_QUEUE_ALL()
Zerotorescue@14 18 self:QueueAll();
Zerotorescue@14 19 end
Zerotorescue@14 20
Zerotorescue@14 21 function mod:IM_QUEUE_GROUP(event, groupName)
Zerotorescue@14 22 self:QueueGroup(groupName);
Zerotorescue@13 23 end
Zerotorescue@13 24
Zerotorescue@13 25 function mod:QueueAll()
Zerotorescue@14 26 local playerName = UnitName("player");
Zerotorescue@14 27
Zerotorescue@14 28 -- Go through all groups
Zerotorescue@61 29 for groupName, values in pairs(addon.db.profile.groups) do
Zerotorescue@62 30 local trackAt = addon:GetOptionByKey(groupName, "trackAtCharacters");
Zerotorescue@14 31
Zerotorescue@14 32 if trackAt[playerName] then
Zerotorescue@14 33 self:QueueGroup(groupName);
Zerotorescue@13 34 end
Zerotorescue@13 35 end
Zerotorescue@13 36 end
Zerotorescue@13 37
Zerotorescue@13 38 function mod:QueueGroup(groupName)
Zerotorescue@61 39 if not addon.db.profile.groups[groupName] then
Zerotorescue@14 40 print(("Tried to queue items from a group named \"%s\", but no such group exists."):format(groupName));
Zerotorescue@14 41 return;
Zerotorescue@14 42 end
Zerotorescue@14 43
Zerotorescue@14 44 local temp = {};
Zerotorescue@13 45
Zerotorescue@13 46 -- Go through all trade skills for the profession
Zerotorescue@13 47 for i = 1, GetNumTradeSkills() do
Zerotorescue@13 48 -- Process every single tradeskill
Zerotorescue@14 49 self:ProcessTradeSkill(i, groupName, temp);
Zerotorescue@14 50 end
Zerotorescue@36 51
Zerotorescue@61 52 if addon.db.profile.groups[groupName].items then
Zerotorescue@61 53 for itemId, _ in pairs(addon.db.profile.groups[groupName].items) do
Zerotorescue@36 54 if not temp[itemId] then
Zerotorescue@36 55 local itemLink = select(2, GetItemInfo(itemId));
Zerotorescue@36 56
Zerotorescue@62 57 print("Couldn't queue " .. (itemLink or itemId or "???") .. " (not part of this profession)");
Zerotorescue@36 58 end
Zerotorescue@14 59 end
Zerotorescue@13 60 end
Zerotorescue@13 61 end
Zerotorescue@13 62
Zerotorescue@14 63 function mod:ProcessTradeSkill(i, groupName, temp)
Zerotorescue@13 64 -- Try to retrieve the itemlink, this will be nil if current item is a group instead
Zerotorescue@13 65 local itemLink = GetTradeSkillItemLink(i);
Zerotorescue@13 66
Zerotorescue@13 67 if itemLink then
Zerotorescue@13 68 local itemId = addon:GetItemId(itemLink);
Zerotorescue@13 69 if not itemId then
Zerotorescue@13 70 -- If this isn't an item, it can only be an enchant instead
Zerotorescue@13 71 itemId = tonumber(itemLink:match("|Henchant:([-0-9]+)|h"));
Zerotorescue@13 72
Zerotorescue@17 73 itemId = addon.scrollIds[itemId]; -- change enchantIds into scrollIds
Zerotorescue@13 74 end
Zerotorescue@13 75
Zerotorescue@61 76 if addon.db.profile.groups[groupName].items[itemId] then
Zerotorescue@13 77 -- This item is in this group, queue it!
Zerotorescue@13 78
Zerotorescue@14 79 if temp then
Zerotorescue@14 80 -- Remember which items have been processed
Zerotorescue@14 81 temp[itemId] = true;
Zerotorescue@14 82 end
Zerotorescue@13 83
Zerotorescue@23 84 local currentStock = addon:GetItemCount(itemId, groupName);
Zerotorescue@31 85
Zerotorescue@14 86 if currentStock >= 0 then
Zerotorescue@14 87 -- Current stock will be -1 when no itemcount addon was found
Zerotorescue@31 88
Zerotorescue@31 89 -- Retrieve group settings
Zerotorescue@17 90 local restockTarget = addon:GetOptionByKey(groupName, "restockTarget");
Zerotorescue@17 91 local bonusQueue = addon:GetOptionByKey(groupName, "bonusQueue");
Zerotorescue@17 92 local minCraftingQueue = floor( addon:GetOptionByKey(groupName, "minCraftingQueue") * restockTarget );
Zerotorescue@13 93
Zerotorescue@31 94 -- Calculate the amount to be queued
Zerotorescue@17 95 local amount = ( restockTarget - currentStock );
Zerotorescue@17 96
Zerotorescue@17 97 if currentStock == 0 and bonusQueue > 0 then
Zerotorescue@31 98 -- If we have none left and the bonus queue is enabled, modify the amount to be queued
Zerotorescue@31 99
Zerotorescue@17 100 amount = floor( ( amount * ( bonusQueue + 1 ) ) + .5 ); -- round
Zerotorescue@17 101 end
Zerotorescue@17 102
Zerotorescue@17 103 if amount > 0 and amount >= minCraftingQueue then
Zerotorescue@31 104 -- If we are queueing at least one AND more than the minimum amount, then proceed
Zerotorescue@14 105
Zerotorescue@31 106 -- Auction value settings
Zerotorescue@31 107 local priceThreshold = addon:GetOptionByKey(groupName, "priceThreshold");
Zerotorescue@31 108
Zerotorescue@31 109 if priceThreshold == 0 or addon:GetAuctionValue(itemLink, groupName) >= priceThreshold then
Zerotorescue@31 110 -- If no price threshold is set or the auction value is equal to or larger than the price threshold, then proceed
Zerotorescue@31 111
Zerotorescue@31 112 self:Queue(i, amount, groupName);
Zerotorescue@31 113
Zerotorescue@31 114 print("Queued " .. amount .. " of " .. itemLink);
Zerotorescue@31 115 end
Zerotorescue@14 116 end
Zerotorescue@14 117 else
Zerotorescue@14 118 print("No usable itemcount addon found.");
Zerotorescue@13 119 end
Zerotorescue@13 120 end
Zerotorescue@13 121 end
Zerotorescue@13 122 end
Zerotorescue@13 123
Zerotorescue@23 124 function mod:Queue(tradeSkillIndex, amount, group)
Zerotorescue@13 125 tradeSkillIndex = tonumber(tradeSkillIndex);
Zerotorescue@13 126 amount = tonumber(amount);
Zerotorescue@13 127
Zerotorescue@13 128 if not tradeSkillIndex or not amount then return; end
Zerotorescue@13 129
Zerotorescue@23 130 local selectedExternalAddon = addon:GetOptionByKey(group, "craftingAddon");
Zerotorescue@23 131
Zerotorescue@23 132 if addon.supportedAddons.crafting[selectedExternalAddon] and addon.supportedAddons.crafting[selectedExternalAddon].IsEnabled() then
Zerotorescue@13 133 -- Try to use the default auction pricing addon
Zerotorescue@13 134
Zerotorescue@23 135 return addon.supportedAddons.crafting[selectedExternalAddon].Queue(tradeSkillIndex, amount);
Zerotorescue@13 136 else
Zerotorescue@13 137 -- Default not available, get the first one then
Zerotorescue@13 138
Zerotorescue@13 139 for name, value in pairs(addon.supportedAddons.crafting) do
Zerotorescue@13 140 if value.IsEnabled() then
Zerotorescue@13 141 return value.Queue(tradeSkillIndex, amount);
Zerotorescue@13 142 end
Zerotorescue@13 143 end
Zerotorescue@13 144 end
Zerotorescue@13 145
Zerotorescue@13 146 return -2;
Zerotorescue@13 147 end