Mercurial > wow > itemauditor
comparison Modules/Crafting.lua @ 159:fbfd9dfa6d2b tip
[mq]: minorStuff
author | Asa Ayers <Asa.Ayers@Gmail.com> |
---|---|
date | Sun, 09 Jan 2011 07:38:22 -0800 |
parents | d108b0112be3 |
children |
comparison
equal
deleted
inserted
replaced
158:7ebe0a85d539 | 159:fbfd9dfa6d2b |
---|---|
12 local realData = {} | 12 local realData = {} |
13 local nameMap = nil | 13 local nameMap = nil |
14 | 14 |
15 function Crafting:OnInitialize() | 15 function Crafting:OnInitialize() |
16 self:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED") | 16 self:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED") |
17 self:RegisterEvent("UNIT_SPELLCAST_FAILED") | |
17 end | 18 end |
18 | 19 |
19 local function getQueueLocation(name) | 20 local function getQueueLocation(name) |
21 -- this is supposed to cache, but it isn't working. its easier to just | |
22 -- disable the cache for now. | |
23 nameMap = nil | |
20 if not nameMap then | 24 if not nameMap then |
21 nameMap = {} | 25 nameMap = {} |
22 for key, data in pairs(realData) do | 26 for key, data in pairs(realData) do |
27 -- TODO: Fix the cache and remove this. | |
28 if data.skillName == name then | |
29 return key | |
30 end | |
23 nameMap[data.skillName] = key | 31 nameMap[data.skillName] = key |
24 end | 32 end |
25 end | 33 end |
26 return nameMap[name] | 34 return nameMap[name] |
27 end | 35 end |
39 | 47 |
40 function Crafting:UNIT_SPELLCAST_SUCCEEDED(event, unit, spell) | 48 function Crafting:UNIT_SPELLCAST_SUCCEEDED(event, unit, spell) |
41 if unit == "player" and getQueueLocation(spell) then | 49 if unit == "player" and getQueueLocation(spell) then |
42 local data = realData[getQueueLocation(spell)] | 50 local data = realData[getQueueLocation(spell)] |
43 data.queue = data.queue - 1 | 51 data.queue = data.queue - 1 |
52 ItemAuditor:RefreshCraftingTable() | |
53 end | |
54 end | |
55 | |
56 --[[ | |
57 If the craft failed, probably because you're missing an item, remove it and move on. | |
58 ]] | |
59 function Crafting:UNIT_SPELLCAST_FAILED(event, unit, spell) | |
60 if unit == "player" and getQueueLocation(spell) then | |
61 local data = realData[getQueueLocation(spell)] | |
62 data.queue = 0 | |
44 ItemAuditor:RefreshCraftingTable() | 63 ItemAuditor:RefreshCraftingTable() |
45 end | 64 end |
46 end | 65 end |
47 | 66 |
48 local queueDestinations = {} | 67 local queueDestinations = {} |
495 local totalCost = 0 | 514 local totalCost = 0 |
496 for reagentId = 1, GetTradeSkillNumReagents(i) do | 515 for reagentId = 1, GetTradeSkillNumReagents(i) do |
497 local reagentName, _, reagentCount = GetTradeSkillReagentInfo(i, reagentId); | 516 local reagentName, _, reagentCount = GetTradeSkillReagentInfo(i, reagentId); |
498 local reagentLink = GetTradeSkillReagentItemLink(i, reagentId) | 517 local reagentLink = GetTradeSkillReagentItemLink(i, reagentId) |
499 local reagentTotalCost = self:GetReagentCost(reagentLink, reagentCount) | 518 local reagentTotalCost = self:GetReagentCost(reagentLink, reagentCount) |
519 if not reagentLink then | |
520 -- we can't continue without a link, but sometimes blizzard just fails to return one.z | |
521 self:Print("GetItemInfo failed to return an item link for %s. Retrying in 1 second.", tostring(reagentName)) | |
522 return self:ScheduleTimer("UpdateCraftingTable", 1) | |
523 end | |
524 | |
525 assert(reagentLink, format("GetItemInfo failed to return an item link for %s (skill: %s) (ReagentID: %s)", tostring(reagentName), tostring(i), tostring(reagentId))) | |
500 | 526 |
501 reagents[reagentId] = { | 527 reagents[reagentId] = { |
502 link = reagentLink, | 528 link = reagentLink, |
503 itemID = Utils.GetItemID(reagentLink), | 529 itemID = Utils.GetItemID(reagentLink), |
504 name = reagentName, | 530 name = reagentName, |
510 totalCost = totalCost + reagentTotalCost | 536 totalCost = totalCost + reagentTotalCost |
511 end | 537 end |
512 if vellumID then | 538 if vellumID then |
513 reagentId = GetTradeSkillNumReagents(i) + 1 | 539 reagentId = GetTradeSkillNumReagents(i) + 1 |
514 local reagentName, reagentLink = GetItemInfo(vellumID) | 540 local reagentName, reagentLink = GetItemInfo(vellumID) |
541 assert(reagentLink, format("GetItemInfo failed to return an item link %s:%s", tostring(vellumID), tostring(reagentName))) | |
515 reagents[reagentId] = { | 542 reagents[reagentId] = { |
516 link = reagentLink, | 543 link = reagentLink, |
517 itemID = vellumID, | 544 itemID = vellumID, |
518 name = reagentName, | 545 name = reagentName, |
519 count = 1, | 546 count = 1, |