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@132
|
4 local _G = _G;
|
Zerotorescue@132
|
5 local tonumber, pairs, sformat, smatch, floor, ceil, tinsert, twipe = _G.tonumber, _G.pairs, _G.string.format, _G.string.match, _G.floor, _G.ceil, _G.table.insert, _G.table.wipe;
|
Zerotorescue@132
|
6
|
Zerotorescue@132
|
7 local queue, skipped = {}, {};
|
Zerotorescue@132
|
8
|
Zerotorescue@132
|
9 -- strings are passed by reference, so it takes no additional memory if one string was used in a thousand tables compared to any other reference type
|
Zerotorescue@132
|
10 local skipReasons = {
|
Zerotorescue@132
|
11 ["LOW_VALUE"] = { "|cffff6633Underpriced|r", "The recorded auction value of this item is below your price threshold." },
|
Zerotorescue@132
|
12 ["CAPPED"] = { "|cff66ff33Fully stocked|r", "The recorded item count is above or equal to your minimum global stock setting." },
|
Zerotorescue@132
|
13 ["MIN_CRAFTING_QUEUE"] = { "|cffffff00Min crafting queue|r", "The amount of missing items is below or equal to your \"don't queue if I only miss\"-setting." },
|
Zerotorescue@132
|
14 ["NO_ITEMCOUNT_ADDON"] = { "|cffff0000No itemcount addon|r", "No compatible item count could be found." },
|
Zerotorescue@132
|
15 ["NOT_CRAFTABLE"] = { "|cff3d3d3dNot in profession|r", "This item is not part of this profession." },
|
Zerotorescue@132
|
16 };
|
Zerotorescue@132
|
17
|
Zerotorescue@132
|
18 local function OnQueueCancel()
|
Zerotorescue@132
|
19 twipe(queue);
|
Zerotorescue@132
|
20 twipe(skipped);
|
Zerotorescue@132
|
21
|
Zerotorescue@132
|
22 InventoriumQueuer:Hide();
|
Zerotorescue@132
|
23 end
|
Zerotorescue@132
|
24
|
Zerotorescue@132
|
25 local function OnQueueAccept()
|
Zerotorescue@132
|
26 -- Prepare a table with all possible tradeskill craftables
|
Zerotorescue@132
|
27 local craftables = mod:GetTradeskillCraftables();
|
Zerotorescue@132
|
28
|
Zerotorescue@132
|
29 for _, q in pairs(queue) do
|
Zerotorescue@132
|
30 if craftables[q.itemId] then
|
Zerotorescue@132
|
31 if mod:QueueWithAddon(craftables[q.itemId].no, ceil(q.amount / craftables[q.itemId].quantity), q.groupName) == -1 then
|
Zerotorescue@132
|
32 addon:Print("Couldn't queue, no supported crafting addon found.", addon.Colors.Red);
|
Zerotorescue@132
|
33
|
Zerotorescue@132
|
34 OnQueueCancel();
|
Zerotorescue@132
|
35 return;
|
Zerotorescue@132
|
36 end
|
Zerotorescue@132
|
37 else
|
Zerotorescue@132
|
38 addon:Debug("Lost %s", IdToItemLink(q.itemId));
|
Zerotorescue@132
|
39 end
|
Zerotorescue@132
|
40 end
|
Zerotorescue@132
|
41
|
Zerotorescue@132
|
42 twipe(queue);
|
Zerotorescue@132
|
43 twipe(skipped);
|
Zerotorescue@132
|
44
|
Zerotorescue@132
|
45 InventoriumQueuer:Hide();
|
Zerotorescue@132
|
46 end
|
Zerotorescue@132
|
47
|
Zerotorescue@132
|
48 local function MakeQueueWindow()
|
Zerotorescue@132
|
49 do
|
Zerotorescue@132
|
50 local frame = InventoriumQueuer; -- both for speed as code-consistency
|
Zerotorescue@132
|
51
|
Zerotorescue@132
|
52 -- Scrolling table with a list of items to be moved
|
Zerotorescue@132
|
53 local scrollTableWidth = ( frame.frmMeasureDummy:GetWidth() - 30 ); -- adjust width by the scrollbar size
|
Zerotorescue@132
|
54 local headers = {
|
Zerotorescue@132
|
55 {
|
Zerotorescue@132
|
56 ["name"] = "Item",
|
Zerotorescue@132
|
57 ["width"] = (scrollTableWidth * .60),
|
Zerotorescue@132
|
58 ["defaultsort"] = "asc",
|
Zerotorescue@132
|
59 ["comparesort"] = function(this, aRow, bRow, column)
|
Zerotorescue@132
|
60 local aName, _, aRarity = GetItemInfo(this:GetRow(aRow).rowData.itemId);
|
Zerotorescue@132
|
61 local bName, _, bRarity = GetItemInfo(this:GetRow(bRow).rowData.itemId);
|
Zerotorescue@132
|
62 local template = "%d%s";
|
Zerotorescue@132
|
63 aName = template:format((10 - (aRarity or 10)), (aName or ""):lower());
|
Zerotorescue@132
|
64 bName = template:format((10 - (bRarity or 10)), (bName or ""):lower());
|
Zerotorescue@132
|
65
|
Zerotorescue@132
|
66 if this.cols[column].sort == "dsc" then
|
Zerotorescue@132
|
67 return aName > bName;
|
Zerotorescue@132
|
68 else
|
Zerotorescue@132
|
69 return aName < bName;
|
Zerotorescue@132
|
70 end
|
Zerotorescue@132
|
71 end,
|
Zerotorescue@132
|
72 ["sort"] = "asc", -- when the data is set, use this column so sort the default data
|
Zerotorescue@132
|
73 ["tooltipTitle"] = (not addon.db.profile.defaults.hideHelp and "Item"),
|
Zerotorescue@132
|
74 ["tooltip"] = (not addon.db.profile.defaults.hideHelp and "Click to sort the list by item quality then item name."),
|
Zerotorescue@132
|
75 },
|
Zerotorescue@132
|
76 {
|
Zerotorescue@132
|
77 ["name"] = "Amount",
|
Zerotorescue@132
|
78 ["width"] = (scrollTableWidth * .20),
|
Zerotorescue@132
|
79 ["align"] = "RIGHT",
|
Zerotorescue@132
|
80 ["defaultsort"] = "dsc",
|
Zerotorescue@132
|
81 ["sortnext"] = 1,
|
Zerotorescue@132
|
82 ["tooltipTitle"] = (not addon.db.profile.defaults.hideHelp and "Amount"),
|
Zerotorescue@132
|
83 ["tooltip"] = (not addon.db.profile.defaults.hideHelp and "Click to sort the list by the amount of items to be queued."),
|
Zerotorescue@132
|
84 },
|
Zerotorescue@132
|
85 {
|
Zerotorescue@132
|
86 ["name"] = "Extra",
|
Zerotorescue@132
|
87 ["width"] = (scrollTableWidth * .20),
|
Zerotorescue@132
|
88 ["align"] = "RIGHT",
|
Zerotorescue@132
|
89 ["defaultsort"] = "dsc",
|
Zerotorescue@132
|
90 ["sortnext"] = 1,
|
Zerotorescue@132
|
91 ["tooltipTitle"] = (not addon.db.profile.defaults.hideHelp and "Extra"),
|
Zerotorescue@132
|
92 ["tooltip"] = (not addon.db.profile.defaults.hideHelp and "Click to sort the list by the amount of bonus items."),
|
Zerotorescue@132
|
93 },
|
Zerotorescue@132
|
94 };
|
Zerotorescue@132
|
95
|
Zerotorescue@132
|
96 local scrollTableWidth = ( InventoriumQueuerUnqueueables.frmMeasureDummy:GetWidth() - 30 ); -- adjust width by the scrollbar size
|
Zerotorescue@132
|
97 local unqueueablesHeaders = {
|
Zerotorescue@132
|
98 {
|
Zerotorescue@132
|
99 ["name"] = "Item",
|
Zerotorescue@132
|
100 ["width"] = (scrollTableWidth * .6),
|
Zerotorescue@132
|
101 ["defaultsort"] = "asc",
|
Zerotorescue@132
|
102 ["comparesort"] = function(this, aRow, bRow, column)
|
Zerotorescue@132
|
103 local aName, _, aRarity = GetItemInfo(this:GetRow(aRow).rowData.itemId);
|
Zerotorescue@132
|
104 local bName, _, bRarity = GetItemInfo(this:GetRow(bRow).rowData.itemId);
|
Zerotorescue@132
|
105 local template = "%d%s";
|
Zerotorescue@132
|
106 aName = template:format((10 - (aRarity or 10)), (aName or ""):lower());
|
Zerotorescue@132
|
107 bName = template:format((10 - (bRarity or 10)), (bName or ""):lower());
|
Zerotorescue@132
|
108
|
Zerotorescue@132
|
109 if this.cols[column].sort == "dsc" then
|
Zerotorescue@132
|
110 return aName > bName;
|
Zerotorescue@132
|
111 else
|
Zerotorescue@132
|
112 return aName < bName;
|
Zerotorescue@132
|
113 end
|
Zerotorescue@132
|
114 end,
|
Zerotorescue@132
|
115 ["sort"] = "asc", -- when the data is set, use this column so sort the default data
|
Zerotorescue@132
|
116 ["tooltipTitle"] = (not addon.db.profile.defaults.hideHelp and "Item"),
|
Zerotorescue@132
|
117 ["tooltip"] = (not addon.db.profile.defaults.hideHelp and "Click to sort the list by item quality then item name."),
|
Zerotorescue@132
|
118 },
|
Zerotorescue@132
|
119 {
|
Zerotorescue@132
|
120 ["name"] = "Reason",
|
Zerotorescue@132
|
121 ["width"] = (scrollTableWidth * .4),
|
Zerotorescue@132
|
122 ["defaultsort"] = "dsc",
|
Zerotorescue@132
|
123 ["sortnext"] = 1,
|
Zerotorescue@132
|
124 ["tooltipTitle"] = (not addon.db.profile.defaults.hideHelp and "Reason"),
|
Zerotorescue@132
|
125 ["tooltip"] = (not addon.db.profile.defaults.hideHelp and "Click to sort the list by the reason the items couldn't be queued."),
|
Zerotorescue@132
|
126 },
|
Zerotorescue@132
|
127 };
|
Zerotorescue@132
|
128
|
Zerotorescue@132
|
129 local proceedButton = {
|
Zerotorescue@132
|
130 text = "Queue",
|
Zerotorescue@132
|
131 tooltipTitle = (not addon.db.profile.defaults.hideHelp and "Queue"),
|
Zerotorescue@132
|
132 tooltip = (not addon.db.profile.defaults.hideHelp and "Add these items to the queue of your crafting addon."),
|
Zerotorescue@132
|
133 onClick = OnQueueAccept,
|
Zerotorescue@132
|
134 };
|
Zerotorescue@132
|
135 local cancelButton = {
|
Zerotorescue@132
|
136 text = "Cancel",
|
Zerotorescue@132
|
137 tooltipTitle = (not addon.db.profile.defaults.hideHelp and "Cancel"),
|
Zerotorescue@132
|
138 tooltip = (not addon.db.profile.defaults.hideHelp and "Do not queue anything and close the window."),
|
Zerotorescue@132
|
139 onClick = OnQueueCancel,
|
Zerotorescue@132
|
140 };
|
Zerotorescue@132
|
141
|
Zerotorescue@132
|
142 addon:SetQueueFrameSettings("Inventorium Queue", "The following items can be added to the queue of your crafting addon. Do you wish to proceed?", proceedButton, cancelButton, headers, unqueueablesHeaders);
|
Zerotorescue@132
|
143 end
|
Zerotorescue@132
|
144 end
|
Zerotorescue@132
|
145
|
Zerotorescue@132
|
146 local function DisplayQueue()
|
Zerotorescue@132
|
147 MakeQueueWindow();
|
Zerotorescue@132
|
148
|
Zerotorescue@132
|
149 -- This table is never copied, just referenced. It is the same for every row.
|
Zerotorescue@132
|
150 local queueablesColumns = {
|
Zerotorescue@132
|
151 {
|
Zerotorescue@132
|
152 ["value"] = function(data, cols, realrow, column, table)
|
Zerotorescue@132
|
153 return IdToItemLink(data[realrow].rowData.itemId);
|
Zerotorescue@132
|
154 end,
|
Zerotorescue@132
|
155 }, -- item
|
Zerotorescue@132
|
156 {
|
Zerotorescue@132
|
157 ["value"] = function(data, cols, realrow, column, table)
|
Zerotorescue@132
|
158 return data[realrow].rowData.amount;
|
Zerotorescue@132
|
159 end,
|
Zerotorescue@132
|
160 }, -- amount
|
Zerotorescue@132
|
161 {
|
Zerotorescue@132
|
162 ["value"] = function(data, cols, realrow, column, table)
|
Zerotorescue@132
|
163 return (data[realrow].rowData.bonus == 0 and 0) or "+" .. data[realrow].rowData.bonus;
|
Zerotorescue@132
|
164 end,
|
Zerotorescue@132
|
165 ["color"] = function(data, cols, realrow, column, table)
|
Zerotorescue@132
|
166 return ((data[realrow].rowData.bonus == 0) and { r = 1, g = 1, b = 1, a = 0.5 }) or { r = 0, g = 1, b = 0, a = 1 };
|
Zerotorescue@132
|
167 end,
|
Zerotorescue@132
|
168 }, -- extra
|
Zerotorescue@132
|
169 };
|
Zerotorescue@132
|
170
|
Zerotorescue@132
|
171 -- Store the list with rows in this
|
Zerotorescue@132
|
172 local queueables = {};
|
Zerotorescue@132
|
173
|
Zerotorescue@132
|
174 for _, q in pairs(queue) do
|
Zerotorescue@132
|
175 tinsert(queueables, {
|
Zerotorescue@132
|
176 ["rowData"] = q, -- this is not a key usually found in a row item and ignored by the library
|
Zerotorescue@132
|
177 ["cols"] = queueablesColumns,
|
Zerotorescue@132
|
178 });
|
Zerotorescue@132
|
179 end
|
Zerotorescue@132
|
180
|
Zerotorescue@132
|
181 -- This table is never copied, just referenced. It is the same for every row.
|
Zerotorescue@132
|
182 local unqueueablesColumns = {
|
Zerotorescue@132
|
183 {
|
Zerotorescue@132
|
184 ["value"] = function(data, cols, realrow, column, table)
|
Zerotorescue@132
|
185 return IdToItemLink(data[realrow].rowData.itemId);
|
Zerotorescue@132
|
186 end,
|
Zerotorescue@132
|
187 }, -- item
|
Zerotorescue@132
|
188 {
|
Zerotorescue@132
|
189 ["value"] = function(data, cols, realrow, column, table)
|
Zerotorescue@132
|
190 return data[realrow].rowData.reason[1];
|
Zerotorescue@132
|
191 end,
|
Zerotorescue@132
|
192 }, -- reason
|
Zerotorescue@132
|
193 };
|
Zerotorescue@132
|
194
|
Zerotorescue@132
|
195 -- Store the list with rows in this
|
Zerotorescue@132
|
196 local unqueueables = {};
|
Zerotorescue@132
|
197
|
Zerotorescue@132
|
198 for _, s in pairs(skipped) do
|
Zerotorescue@132
|
199 tinsert(unqueueables, {
|
Zerotorescue@132
|
200 ["rowData"] = s, -- this is not a key usually found in a row item and ignored by the library
|
Zerotorescue@132
|
201 ["cols"] = unqueueablesColumns,
|
Zerotorescue@132
|
202 });
|
Zerotorescue@132
|
203 end
|
Zerotorescue@132
|
204
|
Zerotorescue@132
|
205 addon:SetQueueFrameData(queueables, unqueueables);
|
Zerotorescue@132
|
206 end
|
Zerotorescue@62
|
207
|
Zerotorescue@13
|
208 function mod:OnEnable()
|
Zerotorescue@13
|
209 -- Register our own slash commands
|
Zerotorescue@62
|
210 -- /im queue
|
Zerotorescue@13
|
211 addon:RegisterSlash(function()
|
Zerotorescue@36
|
212 mod:QueueAll();
|
Zerotorescue@36
|
213 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
|
214
|
Zerotorescue@14
|
215 self:RegisterMessage("IM_QUEUE_ALL");
|
Zerotorescue@14
|
216 self:RegisterMessage("IM_QUEUE_GROUP");
|
Zerotorescue@132
|
217
|
Zerotorescue@132
|
218 if not InventoriumQueuer then
|
Zerotorescue@132
|
219 addon:CreateQueueFrame(OnMoveAccept, OnMoveCancel);
|
Zerotorescue@132
|
220 end
|
Zerotorescue@14
|
221 end
|
Zerotorescue@14
|
222
|
Zerotorescue@14
|
223 function mod:IM_QUEUE_ALL()
|
Zerotorescue@14
|
224 self:QueueAll();
|
Zerotorescue@14
|
225 end
|
Zerotorescue@14
|
226
|
Zerotorescue@14
|
227 function mod:IM_QUEUE_GROUP(event, groupName)
|
Zerotorescue@14
|
228 self:QueueGroup(groupName);
|
Zerotorescue@13
|
229 end
|
Zerotorescue@13
|
230
|
Zerotorescue@13
|
231 function mod:QueueAll()
|
Zerotorescue@132
|
232 -- Prepare a table with all possible tradeskill craftables
|
Zerotorescue@132
|
233 local craftables = self:GetTradeskillCraftables();
|
Zerotorescue@132
|
234
|
Zerotorescue@132
|
235 -- Forget old queue
|
Zerotorescue@132
|
236 twipe(queue);
|
Zerotorescue@132
|
237 twipe(skipped);
|
Zerotorescue@132
|
238
|
Zerotorescue@14
|
239 local playerName = UnitName("player");
|
Zerotorescue@14
|
240
|
Zerotorescue@14
|
241 -- Go through all groups
|
Zerotorescue@61
|
242 for groupName, values in pairs(addon.db.profile.groups) do
|
Zerotorescue@62
|
243 local trackAt = addon:GetOptionByKey(groupName, "trackAtCharacters");
|
Zerotorescue@14
|
244
|
Zerotorescue@14
|
245 if trackAt[playerName] then
|
Zerotorescue@132
|
246 self:QueueGroup(groupName, craftables);
|
Zerotorescue@13
|
247 end
|
Zerotorescue@13
|
248 end
|
Zerotorescue@132
|
249
|
Zerotorescue@132
|
250 DisplayQueue();
|
Zerotorescue@13
|
251 end
|
Zerotorescue@13
|
252
|
Zerotorescue@132
|
253 function mod:QueueGroup(groupName, craftables)
|
Zerotorescue@132
|
254 -- Prepare a table with all possible tradeskill craftables
|
Zerotorescue@132
|
255 if not craftables then
|
Zerotorescue@132
|
256 craftables = self:GetTradeskillCraftables(); -- nil when no tradeskill window is open
|
Zerotorescue@132
|
257 end
|
Zerotorescue@132
|
258
|
Zerotorescue@132
|
259 if not craftables then
|
Zerotorescue@132
|
260 addon:Print("No tradeskill window detected.", addon.Colors.Red);
|
Zerotorescue@132
|
261 return;
|
Zerotorescue@132
|
262 elseif not addon.db.profile.groups[groupName] then
|
Zerotorescue@132
|
263 addon:Print(sformat("Tried to queue items from a group named \"%s\", but no such group exists.", groupName), addon.Colors.Red);
|
Zerotorescue@132
|
264 return;
|
Zerotorescue@132
|
265 elseif not addon.db.profile.groups[groupName].items then
|
Zerotorescue@132
|
266 addon:Debug("This group (%s) has no items.", groupName);
|
Zerotorescue@14
|
267 return;
|
Zerotorescue@14
|
268 end
|
Zerotorescue@14
|
269
|
Zerotorescue@132
|
270 -- Retrieve group settings
|
Zerotorescue@132
|
271 local restockTarget = addon:GetOptionByKey(groupName, "restockTarget");
|
Zerotorescue@132
|
272 local bonusQueue = addon:GetOptionByKey(groupName, "bonusQueue");
|
Zerotorescue@132
|
273 local minCraftingQueue = floor( addon:GetOptionByKey(groupName, "minCraftingQueue") * restockTarget ); -- If the minCraftingQueue is 5% and restockTarget is 60, this will result in 3
|
Zerotorescue@132
|
274 local priceThreshold = addon:GetOptionByKey(groupName, "priceThreshold");
|
Zerotorescue@13
|
275
|
Zerotorescue@132
|
276 for itemId in pairs(addon.db.profile.groups[groupName].items) do
|
Zerotorescue@132
|
277 if craftables[itemId] then
|
Zerotorescue@23
|
278 local currentStock = addon:GetItemCount(itemId, groupName);
|
Zerotorescue@31
|
279
|
Zerotorescue@14
|
280 if currentStock >= 0 then
|
Zerotorescue@14
|
281 -- Current stock will be -1 when no itemcount addon was found
|
Zerotorescue@31
|
282
|
Zerotorescue@31
|
283 -- Calculate the amount to be queued
|
Zerotorescue@17
|
284 local amount = ( restockTarget - currentStock );
|
Zerotorescue@132
|
285 local bonus = 0;
|
Zerotorescue@17
|
286
|
Zerotorescue@17
|
287 if currentStock == 0 and bonusQueue > 0 then
|
Zerotorescue@31
|
288 -- If we have none left and the bonus queue is enabled, modify the amount to be queued
|
Zerotorescue@31
|
289
|
Zerotorescue@132
|
290 bonus = floor( ( amount * ( bonusQueue ) ) + .5 ); -- round
|
Zerotorescue@132
|
291
|
Zerotorescue@132
|
292 -- Update amount
|
Zerotorescue@132
|
293 amount = (amount + bonus);
|
Zerotorescue@17
|
294 end
|
Zerotorescue@17
|
295
|
Zerotorescue@17
|
296 if amount > 0 and amount >= minCraftingQueue then
|
Zerotorescue@136
|
297 -- If we are queuing at least one AND more than the minimum amount, then proceed
|
Zerotorescue@14
|
298
|
Zerotorescue@31
|
299 -- Auction value settings
|
Zerotorescue@92
|
300 local value = (priceThreshold ~= 0 and addon:GetAuctionValue(itemLink, groupName));
|
Zerotorescue@31
|
301
|
Zerotorescue@92
|
302 if priceThreshold == 0 or value == -1 or value >= priceThreshold then
|
Zerotorescue@31
|
303 -- If no price threshold is set or the auction value is equal to or larger than the price threshold, then proceed
|
Zerotorescue@31
|
304
|
Zerotorescue@132
|
305 self:Queue(itemId, amount, bonus, groupName);
|
Zerotorescue@132
|
306 else
|
Zerotorescue@132
|
307 self:Skip(itemId, skipReasons.LOW_VALUE);
|
Zerotorescue@132
|
308 end
|
Zerotorescue@132
|
309 else
|
Zerotorescue@132
|
310 if amount <= 0 then
|
Zerotorescue@132
|
311 self:Skip(itemId, skipReasons.CAPPED);
|
Zerotorescue@132
|
312 else
|
Zerotorescue@132
|
313 self:Skip(itemId, skipReasons.MIN_CRAFTING_QUEUE);
|
Zerotorescue@31
|
314 end
|
Zerotorescue@14
|
315 end
|
Zerotorescue@14
|
316 else
|
Zerotorescue@132
|
317 self:Skip(itemId, skipReasons.NO_ITEMCOUNT_ADDON);
|
Zerotorescue@98
|
318 addon:Print("No usable itemcount addon found.");
|
Zerotorescue@132
|
319 return;
|
Zerotorescue@13
|
320 end
|
Zerotorescue@132
|
321 else
|
Zerotorescue@132
|
322 self:Skip(itemId, skipReasons.NOT_CRAFTABLE);
|
Zerotorescue@13
|
323 end
|
Zerotorescue@13
|
324 end
|
Zerotorescue@13
|
325 end
|
Zerotorescue@13
|
326
|
Zerotorescue@132
|
327 function mod:Queue(itemId, amount, bonus, groupName)
|
Zerotorescue@132
|
328 tinsert(queue, {
|
Zerotorescue@132
|
329 ["itemId"] = itemId,
|
Zerotorescue@132
|
330 ["amount"] = amount,
|
Zerotorescue@132
|
331 ["bonus"] = bonus,
|
Zerotorescue@132
|
332 ["groupName"] = groupName,
|
Zerotorescue@132
|
333 });
|
Zerotorescue@132
|
334 end
|
Zerotorescue@132
|
335
|
Zerotorescue@132
|
336 function mod:Skip(itemId, reason)
|
Zerotorescue@132
|
337 tinsert(skipped, {
|
Zerotorescue@132
|
338 ["itemId"] = itemId,
|
Zerotorescue@132
|
339 ["reason"] = reason,
|
Zerotorescue@132
|
340 });
|
Zerotorescue@132
|
341 end
|
Zerotorescue@132
|
342
|
Zerotorescue@132
|
343 function mod:QueueWithAddon(tradeSkillIndex, amount, group)
|
Zerotorescue@132
|
344 -- Sanity check
|
Zerotorescue@13
|
345 tradeSkillIndex = tonumber(tradeSkillIndex);
|
Zerotorescue@13
|
346 amount = tonumber(amount);
|
Zerotorescue@13
|
347
|
Zerotorescue@23
|
348 local selectedExternalAddon = addon:GetOptionByKey(group, "craftingAddon");
|
Zerotorescue@23
|
349
|
Zerotorescue@23
|
350 if addon.supportedAddons.crafting[selectedExternalAddon] and addon.supportedAddons.crafting[selectedExternalAddon].IsEnabled() then
|
Zerotorescue@13
|
351 -- Try to use the default auction pricing addon
|
Zerotorescue@13
|
352
|
Zerotorescue@23
|
353 return addon.supportedAddons.crafting[selectedExternalAddon].Queue(tradeSkillIndex, amount);
|
Zerotorescue@13
|
354 else
|
Zerotorescue@13
|
355 -- Default not available, get the first one then
|
Zerotorescue@13
|
356
|
Zerotorescue@13
|
357 for name, value in pairs(addon.supportedAddons.crafting) do
|
Zerotorescue@13
|
358 if value.IsEnabled() then
|
Zerotorescue@13
|
359 return value.Queue(tradeSkillIndex, amount);
|
Zerotorescue@13
|
360 end
|
Zerotorescue@13
|
361 end
|
Zerotorescue@13
|
362 end
|
Zerotorescue@13
|
363
|
Zerotorescue@132
|
364 return -1;
|
Zerotorescue@13
|
365 end
|
Zerotorescue@132
|
366
|
Zerotorescue@132
|
367 -- Expand all categories
|
Zerotorescue@132
|
368 local function ExpandSubClasses()
|
Zerotorescue@132
|
369 for i = GetNumTradeSkills(), 1, -1 do
|
Zerotorescue@132
|
370 local _, skillType, _, isExpanded = GetTradeSkillInfo(i);
|
Zerotorescue@132
|
371
|
Zerotorescue@132
|
372 if skillType == "header" and not isExpanded then
|
Zerotorescue@132
|
373 ExpandTradeSkillSubClass(i);
|
Zerotorescue@132
|
374 end
|
Zerotorescue@132
|
375 end
|
Zerotorescue@132
|
376 end
|
Zerotorescue@132
|
377
|
Zerotorescue@132
|
378 function mod:GetTradeskillCraftables()
|
Zerotorescue@132
|
379 local craftables = {};
|
Zerotorescue@132
|
380
|
Zerotorescue@132
|
381 if GetTradeSkillLine() ~= "UNKNOWN" then
|
Zerotorescue@132
|
382 ExpandSubClasses();
|
Zerotorescue@132
|
383
|
Zerotorescue@132
|
384 -- Cache all craftable items
|
Zerotorescue@132
|
385 for i = 1, GetNumTradeSkills() do
|
Zerotorescue@132
|
386 local itemLink = GetTradeSkillItemLink(i);
|
Zerotorescue@132
|
387
|
Zerotorescue@132
|
388 if itemLink then
|
Zerotorescue@132
|
389 local itemId = addon:GetItemId(itemLink);
|
Zerotorescue@132
|
390 if not itemId then
|
Zerotorescue@132
|
391 -- If this isn't an item, it can only be an enchant instead
|
Zerotorescue@132
|
392 itemId = tonumber(smatch(itemLink, "|Henchant:([-0-9]+)|h"));
|
Zerotorescue@132
|
393
|
Zerotorescue@132
|
394 itemId = addon.scrollIds[itemId]; -- change enchantIds into scrollIds
|
Zerotorescue@132
|
395 end
|
Zerotorescue@132
|
396
|
Zerotorescue@132
|
397 -- Remember the average amount of items created per craft (doesn't need to be a round number, since we multiply this by the amount of items to be queued we're better off rounding at that time)
|
Zerotorescue@132
|
398 local minMade, maxMade = GetTradeSkillNumMade(i);
|
Zerotorescue@132
|
399 local average = ((minMade == maxMade) and minMade) or ((minMade + maxMade) / 2);
|
Zerotorescue@132
|
400
|
Zerotorescue@132
|
401 craftables[itemId] = {
|
Zerotorescue@132
|
402 ["no"] = i,
|
Zerotorescue@132
|
403 ["quantity"] = average,
|
Zerotorescue@132
|
404 };
|
Zerotorescue@132
|
405 end
|
Zerotorescue@132
|
406 end
|
Zerotorescue@132
|
407 else
|
Zerotorescue@132
|
408 return;
|
Zerotorescue@132
|
409 end
|
Zerotorescue@132
|
410
|
Zerotorescue@132
|
411 return craftables;
|
Zerotorescue@132
|
412 end
|