annotate Modules/Queue.lua @ 110:67bd5057ecb7

Implemented vendor restocking with the mover. Comitting so I can always review this working version, but I?ll be disabling all part of it as it is not going to work properly without seriously compromising the code structure. Debug messages are now appended with ?Inventorium? (my MailOpener addon was making stuff difficult). Now properly removing the refill window from the displayed static popup windows list so new popups won?t be aligned at odd locations. Changed ?CreateMoverFrame? to not contain any scenario-specific info. All settings can be set with SetFrameSettings. Items that belong to speciality bags are now put there. Other items now ignore spaciality bags. Implemented test code for mailbox refill support. It has been disabled due to some issues but may be introduced later. The guild withdrawal limit is now taken into consideration. Queue is now reset before scanning again.
author Zerotorescue
date Fri, 14 Jan 2011 23:25:05 +0100
parents 252292b703ce
children 8460855e3d90
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@98 40 addon:Print(("Tried to queue items from a group named \"%s\", but no such group exists."):format(groupName), addon.Colors.Red);
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@98 61 addon:Print(("Couldn't queue %s (not part of this profession)"):format((itemLink or itemId or "???")), addon.Colors.Orange);
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@95 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@110 96 local minCraftingQueue = floor( addon:GetOptionByKey(groupName, "minCraftingQueue") * restockTarget ); -- If the minCraftingQueue is 5% and restockTarget is 60, this will result in 3
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@92 112 local value = (priceThreshold ~= 0 and addon:GetAuctionValue(itemLink, groupName));
Zerotorescue@31 113
Zerotorescue@92 114 if priceThreshold == 0 or value == -1 or value >= priceThreshold then
Zerotorescue@31 115 -- If no price threshold is set or the auction value is equal to or larger than the price threshold, then proceed
Zerotorescue@31 116
Zerotorescue@31 117 self:Queue(i, amount, groupName);
Zerotorescue@31 118
Zerotorescue@98 119 addon:Print(("Queued %d of %s"):format(amount, itemLink));
Zerotorescue@31 120 end
Zerotorescue@14 121 end
Zerotorescue@14 122 else
Zerotorescue@98 123 addon:Print("No usable itemcount addon found.");
Zerotorescue@13 124 end
Zerotorescue@13 125 end
Zerotorescue@13 126 end
Zerotorescue@13 127 end
Zerotorescue@13 128
Zerotorescue@23 129 function mod:Queue(tradeSkillIndex, amount, group)
Zerotorescue@13 130 tradeSkillIndex = tonumber(tradeSkillIndex);
Zerotorescue@13 131 amount = tonumber(amount);
Zerotorescue@13 132
Zerotorescue@13 133 if not tradeSkillIndex or not amount then return; end
Zerotorescue@13 134
Zerotorescue@23 135 local selectedExternalAddon = addon:GetOptionByKey(group, "craftingAddon");
Zerotorescue@23 136
Zerotorescue@23 137 if addon.supportedAddons.crafting[selectedExternalAddon] and addon.supportedAddons.crafting[selectedExternalAddon].IsEnabled() then
Zerotorescue@13 138 -- Try to use the default auction pricing addon
Zerotorescue@13 139
Zerotorescue@23 140 return addon.supportedAddons.crafting[selectedExternalAddon].Queue(tradeSkillIndex, amount);
Zerotorescue@13 141 else
Zerotorescue@13 142 -- Default not available, get the first one then
Zerotorescue@13 143
Zerotorescue@13 144 for name, value in pairs(addon.supportedAddons.crafting) do
Zerotorescue@13 145 if value.IsEnabled() then
Zerotorescue@13 146 return value.Queue(tradeSkillIndex, amount);
Zerotorescue@13 147 end
Zerotorescue@13 148 end
Zerotorescue@13 149 end
Zerotorescue@13 150
Zerotorescue@13 151 return -2;
Zerotorescue@13 152 end