annotate Queue.lua @ 17:8f5c02113c5c

Reduced the softmax of most ranges from 1.000 to 100. This should make them actually useful. You can still manually enter an amount below the sliders of up to 100.000. The help text for the ?Replenishing stock? category now includes bonus queue information. Added an option to the ?add items? tab called ?Import premade data? which allows a user to import item data from a premade group shipped with the addon. If this premade data ever changes, the user will be notified and queried for an update. Added a ?mass remove? option to the ?current items? tab. Item data should be imported again when importing a complete group. Added ?DataStore (current account only)?, ?DataStore (with guilds)? and ?DataStore (without guilds)? item count options. One might prefer these over Altoholic for a few reasons. Scroll IDs are now stored in a seperate file in a new ?data? folder. Premade groups data can be found there too. Bonus queue and min crafting queue options should now be fully functional. Enchanting scrolls should now work properly. Text in the summary of the value of items below the price threshold window will now be colored completely grey.
author Zerotorescue
date Wed, 20 Oct 2010 01:30:51 +0200
parents 0fc8a54516d7
children 7d7aaa3fbe94
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@13 4 function mod:OnEnable()
Zerotorescue@13 5 -- Register our own slash commands
Zerotorescue@13 6 addon:RegisterSlash(function()
Zerotorescue@13 7 self:QueueAll();
Zerotorescue@13 8 end, "q", "que", "queue");
Zerotorescue@14 9
Zerotorescue@14 10 self:RegisterMessage("IM_QUEUE_ALL");
Zerotorescue@14 11 self:RegisterMessage("IM_QUEUE_GROUP");
Zerotorescue@14 12 end
Zerotorescue@14 13
Zerotorescue@14 14 function mod:IM_QUEUE_ALL()
Zerotorescue@14 15 self:QueueAll();
Zerotorescue@14 16 end
Zerotorescue@14 17
Zerotorescue@14 18 function mod:IM_QUEUE_GROUP(event, groupName)
Zerotorescue@14 19 self:QueueGroup(groupName);
Zerotorescue@13 20 end
Zerotorescue@13 21
Zerotorescue@13 22 function mod:QueueAll()
Zerotorescue@14 23 local playerName = UnitName("player");
Zerotorescue@14 24
Zerotorescue@14 25 -- Go through all groups
Zerotorescue@14 26 for groupName, values in pairs(addon.db.global.groups) do
Zerotorescue@14 27 local trackAt = (values.trackAtCharacters or (values.trackAtCharacters == nil and addon.db.global.defaults.trackAtCharacters));
Zerotorescue@14 28
Zerotorescue@14 29 if trackAt[playerName] then
Zerotorescue@14 30 self:QueueGroup(groupName);
Zerotorescue@13 31 end
Zerotorescue@13 32 end
Zerotorescue@13 33 end
Zerotorescue@13 34
Zerotorescue@13 35 function mod:QueueGroup(groupName)
Zerotorescue@14 36 if not addon.db.global.groups[groupName] then
Zerotorescue@14 37 print(("Tried to queue items from a group named \"%s\", but no such group exists."):format(groupName));
Zerotorescue@14 38 return;
Zerotorescue@14 39 end
Zerotorescue@14 40
Zerotorescue@14 41 local temp = {};
Zerotorescue@13 42
Zerotorescue@13 43 -- Go through all trade skills for the profession
Zerotorescue@13 44 for i = 1, GetNumTradeSkills() do
Zerotorescue@13 45 -- Process every single tradeskill
Zerotorescue@14 46 self:ProcessTradeSkill(i, groupName, temp);
Zerotorescue@14 47 end
Zerotorescue@14 48
Zerotorescue@14 49 for itemId, _ in pairs(addon.db.global.groups[groupName].items) do
Zerotorescue@14 50 if not temp[itemId] then
Zerotorescue@14 51 local itemLink = select(2, GetItemInfo(itemId));
Zerotorescue@17 52 print("Couldn't queue " .. itemLink .. " (not part of this profession)");
Zerotorescue@14 53 end
Zerotorescue@13 54 end
Zerotorescue@13 55 end
Zerotorescue@13 56
Zerotorescue@14 57 function mod:ProcessTradeSkill(i, groupName, temp)
Zerotorescue@13 58 -- Try to retrieve the itemlink, this will be nil if current item is a group instead
Zerotorescue@13 59 local itemLink = GetTradeSkillItemLink(i);
Zerotorescue@13 60
Zerotorescue@13 61 if itemLink then
Zerotorescue@13 62 local itemId = addon:GetItemId(itemLink);
Zerotorescue@13 63 if not itemId then
Zerotorescue@13 64 -- If this isn't an item, it can only be an enchant instead
Zerotorescue@13 65 itemId = tonumber(itemLink:match("|Henchant:([-0-9]+)|h"));
Zerotorescue@13 66
Zerotorescue@17 67 itemId = addon.scrollIds[itemId]; -- change enchantIds into scrollIds
Zerotorescue@13 68 end
Zerotorescue@13 69
Zerotorescue@13 70 if addon.db.global.groups[groupName].items[itemId] then
Zerotorescue@13 71 -- This item is in this group, queue it!
Zerotorescue@13 72
Zerotorescue@14 73 if temp then
Zerotorescue@14 74 -- Remember which items have been processed
Zerotorescue@14 75 temp[itemId] = true;
Zerotorescue@14 76 end
Zerotorescue@13 77
Zerotorescue@14 78 local currentStock = addon:GetItemCount(itemId);
Zerotorescue@14 79 if currentStock >= 0 then
Zerotorescue@14 80 -- Current stock will be -1 when no itemcount addon was found
Zerotorescue@17 81 local restockTarget = addon:GetOptionByKey(groupName, "restockTarget");
Zerotorescue@17 82 local bonusQueue = addon:GetOptionByKey(groupName, "bonusQueue");
Zerotorescue@17 83 local minCraftingQueue = floor( addon:GetOptionByKey(groupName, "minCraftingQueue") * restockTarget );
Zerotorescue@13 84
Zerotorescue@17 85 local amount = ( restockTarget - currentStock );
Zerotorescue@17 86
Zerotorescue@17 87 if currentStock == 0 and bonusQueue > 0 then
Zerotorescue@17 88 amount = floor( ( amount * ( bonusQueue + 1 ) ) + .5 ); -- round
Zerotorescue@17 89 end
Zerotorescue@17 90
Zerotorescue@17 91 if amount > 0 and amount >= minCraftingQueue then
Zerotorescue@14 92 self:Queue(i, amount);
Zerotorescue@14 93
Zerotorescue@14 94 print("Queued " .. amount .. " of " .. itemLink);
Zerotorescue@14 95 end
Zerotorescue@14 96 else
Zerotorescue@14 97 print("No usable itemcount addon found.");
Zerotorescue@13 98 end
Zerotorescue@13 99 end
Zerotorescue@13 100 end
Zerotorescue@13 101 end
Zerotorescue@13 102
Zerotorescue@13 103 function mod:Queue(tradeSkillIndex, amount)
Zerotorescue@13 104 tradeSkillIndex = tonumber(tradeSkillIndex);
Zerotorescue@13 105 amount = tonumber(amount);
Zerotorescue@13 106
Zerotorescue@13 107 if not tradeSkillIndex or not amount then return; end
Zerotorescue@13 108
Zerotorescue@13 109 if addon.supportedAddons.crafting[addon.db.global.defaults.craftingAddon] then
Zerotorescue@13 110 -- Try to use the default auction pricing addon
Zerotorescue@13 111
Zerotorescue@13 112 return addon.supportedAddons.crafting[addon.db.global.defaults.craftingAddon].Queue(tradeSkillIndex, amount);
Zerotorescue@13 113 else
Zerotorescue@13 114 -- Default not available, get the first one then
Zerotorescue@13 115
Zerotorescue@13 116 for name, value in pairs(addon.supportedAddons.crafting) do
Zerotorescue@13 117 if value.IsEnabled() then
Zerotorescue@13 118 return value.Queue(tradeSkillIndex, amount);
Zerotorescue@13 119 end
Zerotorescue@13 120 end
Zerotorescue@13 121 end
Zerotorescue@13 122
Zerotorescue@13 123 return -2;
Zerotorescue@13 124 end