annotate Queue.lua @ 24:db57cd9273f1

Fixed premade item data update check.
author Zerotorescue
date Thu, 28 Oct 2010 19:20:33 +0200
parents 7d7aaa3fbe94
children e732843b16d2
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@23 78 local currentStock = addon:GetItemCount(itemId, groupName);
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@23 92 self:Queue(i, amount, groupName);
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@23 103 function mod:Queue(tradeSkillIndex, amount, group)
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@23 109 local selectedExternalAddon = addon:GetOptionByKey(group, "craftingAddon");
Zerotorescue@23 110
Zerotorescue@23 111 if addon.supportedAddons.crafting[selectedExternalAddon] and addon.supportedAddons.crafting[selectedExternalAddon].IsEnabled() then
Zerotorescue@13 112 -- Try to use the default auction pricing addon
Zerotorescue@13 113
Zerotorescue@23 114 return addon.supportedAddons.crafting[selectedExternalAddon].Queue(tradeSkillIndex, amount);
Zerotorescue@13 115 else
Zerotorescue@13 116 -- Default not available, get the first one then
Zerotorescue@13 117
Zerotorescue@13 118 for name, value in pairs(addon.supportedAddons.crafting) do
Zerotorescue@13 119 if value.IsEnabled() then
Zerotorescue@13 120 return value.Queue(tradeSkillIndex, amount);
Zerotorescue@13 121 end
Zerotorescue@13 122 end
Zerotorescue@13 123 end
Zerotorescue@13 124
Zerotorescue@13 125 return -2;
Zerotorescue@13 126 end