annotate Modules/Queue.lua @ 142:56f33abee1e3

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