comparison Modules/Queue.lua @ 84:3bec0ea44607

Cleaned the Inventorium folder; moved all classes to classes directory, modules to modules directory and support addons to plugins directory. In addition support addons are now references within XML files rather than inside the TOC. Fixed the default local item count setting, you can now exclude bag and AH data from it. Fixed some mover algorithm bugs. Mover can no longer freeze the game but instead will terminate the process after a 1000 passes. Now reversing the moves table after making it, rather than every single time it is used. Fixed guild bank support. Now displaying the amount of items moved. Scanner now scans all guild bank tabs rather than only the current. Fixed a bug with local item data not being retrieved properly. Disabled ?enterClicksFirstButton? within dialogs as this causes the dialog to consume all keypress. Events are now at the addon object rather than local.
author Zerotorescue
date Thu, 06 Jan 2011 20:05:30 +0100
parents Queue.lua@2127ab01ed4a
children a12d22ef3f39
comparison
equal deleted inserted replaced
83:6b60f7a1410c 84:3bec0ea44607
1 local addon = select(2, ...);
2 local mod = addon:NewModule("Queue", "AceEvent-3.0", "AceTimer-3.0");
3
4 local pairs = pairs;
5
6 function mod:OnEnable()
7 -- Register our own slash commands
8 -- /im queue
9 addon:RegisterSlash(function()
10 mod:QueueAll();
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.");
12
13 self:RegisterMessage("IM_QUEUE_ALL");
14 self:RegisterMessage("IM_QUEUE_GROUP");
15 end
16
17 function mod:IM_QUEUE_ALL()
18 self:QueueAll();
19 end
20
21 function mod:IM_QUEUE_GROUP(event, groupName)
22 self:QueueGroup(groupName);
23 end
24
25 function mod:QueueAll()
26 local playerName = UnitName("player");
27
28 -- Go through all groups
29 for groupName, values in pairs(addon.db.profile.groups) do
30 local trackAt = addon:GetOptionByKey(groupName, "trackAtCharacters");
31
32 if trackAt[playerName] then
33 self:QueueGroup(groupName);
34 end
35 end
36 end
37
38 function mod:QueueGroup(groupName)
39 if not addon.db.profile.groups[groupName] then
40 print(("Tried to queue items from a group named \"%s\", but no such group exists."):format(groupName));
41 return;
42 end
43
44 local temp = {};
45
46 local tradeskillName, currentLevel, maxLevel = GetTradeSkillLine();
47
48 if tradeskillName ~= "UNKNOWN" then
49 -- Go through all trade skills for the profession
50 for i = 1, GetNumTradeSkills() do
51 -- Process every single tradeskill
52 self:ProcessTradeSkill(i, groupName, temp);
53 end
54 end
55
56 if addon.db.profile.groups[groupName].items then
57 for itemId, _ in pairs(addon.db.profile.groups[groupName].items) do
58 if not temp[itemId] then
59 local itemLink = select(2, GetItemInfo(itemId));
60
61 print("Couldn't queue " .. (itemLink or itemId or "???") .. " (not part of this profession)");
62 end
63 end
64 end
65 end
66
67 function mod:ProcessTradeSkill(i, groupName, temp)
68 -- Try to retrieve the itemlink, this will be nil if current item is a group instead
69 local itemLink = GetTradeSkillItemLink(i);
70
71 if itemLink then
72 local itemId = addon:GetItemId(itemLink);
73 if not itemId then
74 -- If this isn't an item, it can only be an enchant instead
75 itemId = tonumber(itemLink:match("|Henchant:([-0-9]+)|h"));
76
77 itemId = addon.scrollIds[itemId]; -- change enchantIds into scrollIds
78 end
79
80 if addon.db.profile.groups[groupName].items[itemId] then
81 -- This item is in this group, queue it!
82
83 if temp then
84 -- Remember which items have been processed
85 temp[itemId] = true;
86 end
87
88 local currentStock = addon:GetItemCount(itemId, groupName);
89
90 if currentStock >= 0 then
91 -- Current stock will be -1 when no itemcount addon was found
92
93 -- Retrieve group settings
94 local restockTarget = addon:GetOptionByKey(groupName, "restockTarget");
95 local bonusQueue = addon:GetOptionByKey(groupName, "bonusQueue");
96 local minCraftingQueue = floor( addon:GetOptionByKey(groupName, "minCraftingQueue") * restockTarget );
97
98 -- Calculate the amount to be queued
99 local amount = ( restockTarget - currentStock );
100
101 if currentStock == 0 and bonusQueue > 0 then
102 -- If we have none left and the bonus queue is enabled, modify the amount to be queued
103
104 amount = floor( ( amount * ( bonusQueue + 1 ) ) + .5 ); -- round
105 end
106
107 if amount > 0 and amount >= minCraftingQueue then
108 -- If we are queueing at least one AND more than the minimum amount, then proceed
109
110 -- Auction value settings
111 local priceThreshold = addon:GetOptionByKey(groupName, "priceThreshold");
112
113 if priceThreshold == 0 or addon:GetAuctionValue(itemLink, groupName) >= priceThreshold then
114 -- If no price threshold is set or the auction value is equal to or larger than the price threshold, then proceed
115
116 self:Queue(i, amount, groupName);
117
118 print("Queued " .. amount .. " of " .. itemLink);
119 end
120 end
121 else
122 print("No usable itemcount addon found.");
123 end
124 end
125 end
126 end
127
128 function mod:Queue(tradeSkillIndex, amount, group)
129 tradeSkillIndex = tonumber(tradeSkillIndex);
130 amount = tonumber(amount);
131
132 if not tradeSkillIndex or not amount then return; end
133
134 local selectedExternalAddon = addon:GetOptionByKey(group, "craftingAddon");
135
136 if addon.supportedAddons.crafting[selectedExternalAddon] and addon.supportedAddons.crafting[selectedExternalAddon].IsEnabled() then
137 -- Try to use the default auction pricing addon
138
139 return addon.supportedAddons.crafting[selectedExternalAddon].Queue(tradeSkillIndex, amount);
140 else
141 -- Default not available, get the first one then
142
143 for name, value in pairs(addon.supportedAddons.crafting) do
144 if value.IsEnabled() then
145 return value.Queue(tradeSkillIndex, amount);
146 end
147 end
148 end
149
150 return -2;
151 end