annotate Queue.lua @ 31:e732843b16d2 v0.1.6-BETA

Added an info box to the top of the general group. Removed the ?Don't queue when below threshold?, this is now default (can?t make it too complicated). Implemented working functionality for virtual groups. ?Include in local item data? can now be overridden in every group. Added help text at the replenishing stock indicating how auction values are used when queueing. The tabs ?add items? and ?current items? will now be hidden rather than disabled when you have a virtual group selected. The auction value/price threshold for items will now be used when queueing items.
author Zerotorescue
date Sat, 30 Oct 2010 23:04:45 +0200
parents 7d7aaa3fbe94
children 58fb38f0b447
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@13 7 self:QueueAll();
Zerotorescue@13 8 end, "q", "que", "queue");
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@14 48
Zerotorescue@14 49 for itemId, _ in pairs(addon.db.global.groups[groupName].items) do
Zerotorescue@14 50 if not temp[itemId] then
Zerotorescue@14 51 local itemLink = select(2, GetItemInfo(itemId));
Zerotorescue@17 52 print("Couldn't queue " .. itemLink .. " (not part of this profession)");
Zerotorescue@14 53 end
Zerotorescue@13 54 end
Zerotorescue@13 55 end
Zerotorescue@13 56
Zerotorescue@14 57 function mod:ProcessTradeSkill(i, groupName, temp)
Zerotorescue@13 58 -- Try to retrieve the itemlink, this will be nil if current item is a group instead
Zerotorescue@13 59 local itemLink = GetTradeSkillItemLink(i);
Zerotorescue@13 60
Zerotorescue@13 61 if itemLink then
Zerotorescue@13 62 local itemId = addon:GetItemId(itemLink);
Zerotorescue@13 63 if not itemId then
Zerotorescue@13 64 -- If this isn't an item, it can only be an enchant instead
Zerotorescue@13 65 itemId = tonumber(itemLink:match("|Henchant:([-0-9]+)|h"));
Zerotorescue@13 66
Zerotorescue@17 67 itemId = addon.scrollIds[itemId]; -- change enchantIds into scrollIds
Zerotorescue@13 68 end
Zerotorescue@13 69
Zerotorescue@13 70 if addon.db.global.groups[groupName].items[itemId] then
Zerotorescue@13 71 -- This item is in this group, queue it!
Zerotorescue@13 72
Zerotorescue@14 73 if temp then
Zerotorescue@14 74 -- Remember which items have been processed
Zerotorescue@14 75 temp[itemId] = true;
Zerotorescue@14 76 end
Zerotorescue@13 77
Zerotorescue@23 78 local currentStock = addon:GetItemCount(itemId, groupName);
Zerotorescue@31 79
Zerotorescue@14 80 if currentStock >= 0 then
Zerotorescue@14 81 -- Current stock will be -1 when no itemcount addon was found
Zerotorescue@31 82
Zerotorescue@31 83 -- Retrieve group settings
Zerotorescue@17 84 local restockTarget = addon:GetOptionByKey(groupName, "restockTarget");
Zerotorescue@17 85 local bonusQueue = addon:GetOptionByKey(groupName, "bonusQueue");
Zerotorescue@17 86 local minCraftingQueue = floor( addon:GetOptionByKey(groupName, "minCraftingQueue") * restockTarget );
Zerotorescue@13 87
Zerotorescue@31 88 -- Calculate the amount to be queued
Zerotorescue@17 89 local amount = ( restockTarget - currentStock );
Zerotorescue@17 90
Zerotorescue@17 91 if currentStock == 0 and bonusQueue > 0 then
Zerotorescue@31 92 -- If we have none left and the bonus queue is enabled, modify the amount to be queued
Zerotorescue@31 93
Zerotorescue@17 94 amount = floor( ( amount * ( bonusQueue + 1 ) ) + .5 ); -- round
Zerotorescue@17 95 end
Zerotorescue@17 96
Zerotorescue@17 97 if amount > 0 and amount >= minCraftingQueue then
Zerotorescue@31 98 -- If we are queueing at least one AND more than the minimum amount, then proceed
Zerotorescue@14 99
Zerotorescue@31 100 -- Auction value settings
Zerotorescue@31 101 local priceThreshold = addon:GetOptionByKey(groupName, "priceThreshold");
Zerotorescue@31 102
Zerotorescue@31 103 if priceThreshold == 0 or addon:GetAuctionValue(itemLink, groupName) >= priceThreshold then
Zerotorescue@31 104 -- If no price threshold is set or the auction value is equal to or larger than the price threshold, then proceed
Zerotorescue@31 105
Zerotorescue@31 106 self:Queue(i, amount, groupName);
Zerotorescue@31 107
Zerotorescue@31 108 print("Queued " .. amount .. " of " .. itemLink);
Zerotorescue@31 109 end
Zerotorescue@14 110 end
Zerotorescue@14 111 else
Zerotorescue@14 112 print("No usable itemcount addon found.");
Zerotorescue@13 113 end
Zerotorescue@13 114 end
Zerotorescue@13 115 end
Zerotorescue@13 116 end
Zerotorescue@13 117
Zerotorescue@23 118 function mod:Queue(tradeSkillIndex, amount, group)
Zerotorescue@13 119 tradeSkillIndex = tonumber(tradeSkillIndex);
Zerotorescue@13 120 amount = tonumber(amount);
Zerotorescue@13 121
Zerotorescue@13 122 if not tradeSkillIndex or not amount then return; end
Zerotorescue@13 123
Zerotorescue@23 124 local selectedExternalAddon = addon:GetOptionByKey(group, "craftingAddon");
Zerotorescue@23 125
Zerotorescue@23 126 if addon.supportedAddons.crafting[selectedExternalAddon] and addon.supportedAddons.crafting[selectedExternalAddon].IsEnabled() then
Zerotorescue@13 127 -- Try to use the default auction pricing addon
Zerotorescue@13 128
Zerotorescue@23 129 return addon.supportedAddons.crafting[selectedExternalAddon].Queue(tradeSkillIndex, amount);
Zerotorescue@13 130 else
Zerotorescue@13 131 -- Default not available, get the first one then
Zerotorescue@13 132
Zerotorescue@13 133 for name, value in pairs(addon.supportedAddons.crafting) do
Zerotorescue@13 134 if value.IsEnabled() then
Zerotorescue@13 135 return value.Queue(tradeSkillIndex, amount);
Zerotorescue@13 136 end
Zerotorescue@13 137 end
Zerotorescue@13 138 end
Zerotorescue@13 139
Zerotorescue@13 140 return -2;
Zerotorescue@13 141 end