annotate Modules/Queue.lua @ 89:a12d22ef3f39

AceSerializer has been enabled again as it?s used when exporting/importing groups. All other unused libraries are now really removed. Adjusted debug function to format only when a debug channel is available. Fixed moving from guild banks, checking if items are locked is different then with banks. Now unregistering the item locking event so it doesn?t continue to try to move every time an item is switched after the automated cycle has finished. (geeezus, this description is a total overkill) Fixed item queueing. Queue all when there?s a group without any items inside no longer crashes. Removing cached container data after closing a container.
author Zerotorescue
date Fri, 07 Jan 2011 22:19:03 +0100
parents 3bec0ea44607
children 88898c1e9e61
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@75 46 local tradeskillName, currentLevel, maxLevel = GetTradeSkillLine();
Zerotorescue@75 47
Zerotorescue@75 48 if tradeskillName ~= "UNKNOWN" then
Zerotorescue@75 49 -- Go through all trade skills for the profession
Zerotorescue@75 50 for i = 1, GetNumTradeSkills() do
Zerotorescue@75 51 -- Process every single tradeskill
Zerotorescue@75 52 self:ProcessTradeSkill(i, groupName, temp);
Zerotorescue@75 53 end
Zerotorescue@14 54 end
Zerotorescue@36 55
Zerotorescue@61 56 if addon.db.profile.groups[groupName].items then
Zerotorescue@61 57 for itemId, _ in pairs(addon.db.profile.groups[groupName].items) do
Zerotorescue@36 58 if not temp[itemId] then
Zerotorescue@36 59 local itemLink = select(2, GetItemInfo(itemId));
Zerotorescue@36 60
Zerotorescue@62 61 print("Couldn't queue " .. (itemLink or itemId or "???") .. " (not part of this profession)");
Zerotorescue@36 62 end
Zerotorescue@14 63 end
Zerotorescue@13 64 end
Zerotorescue@13 65 end
Zerotorescue@13 66
Zerotorescue@14 67 function mod:ProcessTradeSkill(i, groupName, temp)
Zerotorescue@13 68 -- Try to retrieve the itemlink, this will be nil if current item is a group instead
Zerotorescue@13 69 local itemLink = GetTradeSkillItemLink(i);
Zerotorescue@13 70
Zerotorescue@13 71 if itemLink then
Zerotorescue@89 72 local itemId = addon:GetItemID(itemLink);
Zerotorescue@13 73 if not itemId then
Zerotorescue@13 74 -- If this isn't an item, it can only be an enchant instead
Zerotorescue@13 75 itemId = tonumber(itemLink:match("|Henchant:([-0-9]+)|h"));
Zerotorescue@13 76
Zerotorescue@17 77 itemId = addon.scrollIds[itemId]; -- change enchantIds into scrollIds
Zerotorescue@13 78 end
Zerotorescue@13 79
Zerotorescue@89 80 if addon.db.profile.groups[groupName].items and addon.db.profile.groups[groupName].items[itemId] then
Zerotorescue@13 81 -- This item is in this group, queue it!
Zerotorescue@13 82
Zerotorescue@14 83 if temp then
Zerotorescue@14 84 -- Remember which items have been processed
Zerotorescue@14 85 temp[itemId] = true;
Zerotorescue@14 86 end
Zerotorescue@13 87
Zerotorescue@23 88 local currentStock = addon:GetItemCount(itemId, groupName);
Zerotorescue@31 89
Zerotorescue@14 90 if currentStock >= 0 then
Zerotorescue@14 91 -- Current stock will be -1 when no itemcount addon was found
Zerotorescue@31 92
Zerotorescue@31 93 -- Retrieve group settings
Zerotorescue@17 94 local restockTarget = addon:GetOptionByKey(groupName, "restockTarget");
Zerotorescue@17 95 local bonusQueue = addon:GetOptionByKey(groupName, "bonusQueue");
Zerotorescue@17 96 local minCraftingQueue = floor( addon:GetOptionByKey(groupName, "minCraftingQueue") * restockTarget );
Zerotorescue@13 97
Zerotorescue@31 98 -- Calculate the amount to be queued
Zerotorescue@17 99 local amount = ( restockTarget - currentStock );
Zerotorescue@17 100
Zerotorescue@17 101 if currentStock == 0 and bonusQueue > 0 then
Zerotorescue@31 102 -- If we have none left and the bonus queue is enabled, modify the amount to be queued
Zerotorescue@31 103
Zerotorescue@17 104 amount = floor( ( amount * ( bonusQueue + 1 ) ) + .5 ); -- round
Zerotorescue@17 105 end
Zerotorescue@17 106
Zerotorescue@17 107 if amount > 0 and amount >= minCraftingQueue then
Zerotorescue@31 108 -- If we are queueing at least one AND more than the minimum amount, then proceed
Zerotorescue@14 109
Zerotorescue@31 110 -- Auction value settings
Zerotorescue@31 111 local priceThreshold = addon:GetOptionByKey(groupName, "priceThreshold");
Zerotorescue@31 112
Zerotorescue@31 113 if priceThreshold == 0 or addon:GetAuctionValue(itemLink, groupName) >= priceThreshold then
Zerotorescue@31 114 -- If no price threshold is set or the auction value is equal to or larger than the price threshold, then proceed
Zerotorescue@31 115
Zerotorescue@31 116 self:Queue(i, amount, groupName);
Zerotorescue@31 117
Zerotorescue@31 118 print("Queued " .. amount .. " of " .. itemLink);
Zerotorescue@31 119 end
Zerotorescue@14 120 end
Zerotorescue@14 121 else
Zerotorescue@14 122 print("No usable itemcount addon found.");
Zerotorescue@13 123 end
Zerotorescue@13 124 end
Zerotorescue@13 125 end
Zerotorescue@13 126 end
Zerotorescue@13 127
Zerotorescue@23 128 function mod:Queue(tradeSkillIndex, amount, group)
Zerotorescue@13 129 tradeSkillIndex = tonumber(tradeSkillIndex);
Zerotorescue@13 130 amount = tonumber(amount);
Zerotorescue@13 131
Zerotorescue@13 132 if not tradeSkillIndex or not amount then return; end
Zerotorescue@13 133
Zerotorescue@23 134 local selectedExternalAddon = addon:GetOptionByKey(group, "craftingAddon");
Zerotorescue@23 135
Zerotorescue@23 136 if addon.supportedAddons.crafting[selectedExternalAddon] and addon.supportedAddons.crafting[selectedExternalAddon].IsEnabled() then
Zerotorescue@13 137 -- Try to use the default auction pricing addon
Zerotorescue@13 138
Zerotorescue@23 139 return addon.supportedAddons.crafting[selectedExternalAddon].Queue(tradeSkillIndex, amount);
Zerotorescue@13 140 else
Zerotorescue@13 141 -- Default not available, get the first one then
Zerotorescue@13 142
Zerotorescue@13 143 for name, value in pairs(addon.supportedAddons.crafting) do
Zerotorescue@13 144 if value.IsEnabled() then
Zerotorescue@13 145 return value.Queue(tradeSkillIndex, amount);
Zerotorescue@13 146 end
Zerotorescue@13 147 end
Zerotorescue@13 148 end
Zerotorescue@13 149
Zerotorescue@13 150 return -2;
Zerotorescue@13 151 end