Mercurial > wow > itemauditor
comparison Modules/Crafting.lua @ 134:7f81764aa03a
Backed out changeset 451d8a19edea
author | Asa Ayers <Asa.Ayers@Gmail.com> |
---|---|
date | Thu, 30 Sep 2010 17:43:43 -0700 |
parents | 451d8a19edea |
children | a529a4a4ccbe |
comparison
equal
deleted
inserted
replaced
128:451d8a19edea | 134:7f81764aa03a |
---|---|
8 | 8 |
9 local validateMoney = ItemAuditor.validateMoney | 9 local validateMoney = ItemAuditor.validateMoney |
10 local parseMoney = ItemAuditor.parseMoney | 10 local parseMoney = ItemAuditor.parseMoney |
11 | 11 |
12 local realData = {} | 12 local realData = {} |
13 local nameMap = nil | |
14 local shoppingList = nil | |
15 | 13 |
16 local vellumLevelMap = { | 14 local vellumLevelMap = { |
17 [38682] = 37602, -- Armor Vellum => Armor Vellum II | 15 [38682] = 37602, -- Armor Vellum => Armor Vellum II |
18 [37602] = 43145, -- Armor Vellum II => Armor Vellum III | 16 [37602] = 43145, -- Armor Vellum II => Armor Vellum III |
19 [39349] = 39350, -- Weapon Vellum => Weapon Vellum II | 17 [39349] = 39350, -- Weapon Vellum => Weapon Vellum II |
20 [39350] = 43146, -- Weapon Vellum II => Weapon Vellum III | 18 [39350] = 43146, -- Weapon Vellum II => Weapon Vellum III |
21 } | 19 } |
22 | |
23 function Crafting:OnInitialize() | |
24 local allQueues = ItemAuditor.db.factionrealm.queue | |
25 if not allQueues[UnitName("player")] then | |
26 allQueues[UnitName("player")] = {} | |
27 end | |
28 realData = allQueues[UnitName("player")] | |
29 | |
30 self:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED") | |
31 end | |
32 | |
33 local function getQueueLocation(name) | |
34 if not nameMap then | |
35 nameMap = {} | |
36 for key, data in pairs(realData) do | |
37 nameMap[data.skillName] = key | |
38 end | |
39 end | |
40 return nameMap[name] | |
41 end | |
42 | |
43 --@debug@ | |
44 Crafting.getQueueLocation = getQueueLocation | |
45 function Crafting.getNameMap() | |
46 return nameMap | |
47 end | |
48 | |
49 function Crafting.getRealData() | |
50 return realData | |
51 end | |
52 --@end-debug@ | |
53 | |
54 function Crafting:UNIT_SPELLCAST_SUCCEEDED(event, unit, spell) | |
55 if unit == "player" and getQueueLocation(spell) then | |
56 local data = realData[getQueueLocation(spell)] | |
57 data.queue = data.queue - 1 | |
58 ItemAuditor:RefreshCraftingTable() | |
59 end | |
60 end | |
61 | 20 |
62 local queueDestinations = {} | 21 local queueDestinations = {} |
63 local displayCraftingDestinations = {} | 22 local displayCraftingDestinations = {} |
64 function Crafting.RegisterQueueDestination(name, destination) | 23 function Crafting.RegisterQueueDestination(name, destination) |
65 queueDestinations[name] = destination | 24 queueDestinations[name] = destination |
191 | 150 |
192 -- ItemAuditor:GetModule('Crafting').filter_queued = false | 151 -- ItemAuditor:GetModule('Crafting').filter_queued = false |
193 Crafting.filter_have_mats = false | 152 Crafting.filter_have_mats = false |
194 Crafting.filter_show_all = false | 153 Crafting.filter_show_all = false |
195 local function tableFilter(self, row, ...) | 154 local function tableFilter(self, row, ...) |
196 if Crafting.nameFilter then | |
197 return string.find(row[1], Crafting.nameFilter) ~= nil | |
198 end | |
199 | |
200 if Crafting.filter_show_all then | 155 if Crafting.filter_show_all then |
201 return true | 156 return true |
202 end | 157 end |
203 | 158 |
204 -- column 5 is how many should be crafted | 159 -- column 5 is how many should be crafted |
232 craftingTable.frame:SetPoint("BOTTOMRIGHT", craftingContent, 0, 30) | 187 craftingTable.frame:SetPoint("BOTTOMRIGHT", craftingContent, 0, 30) |
233 | 188 |
234 craftingTable:RegisterEvents({ | 189 craftingTable:RegisterEvents({ |
235 ["OnEnter"] = function (rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...) | 190 ["OnEnter"] = function (rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...) |
236 if realrow then | 191 if realrow then |
237 if column == 1 then | 192 local data = realData[realrow] |
238 local data = realData[realrow] | 193 |
239 | 194 GameTooltip:SetOwner(rowFrame, "ANCHOR_CURSOR") |
240 GameTooltip:SetOwner(rowFrame, "ANCHOR_CURSOR") | 195 GameTooltip:SetHyperlink(data.link) |
241 GameTooltip:SetHyperlink(data.link) | 196 GameTooltip:Show() |
242 GameTooltip:Show() | |
243 elseif column == 2 then | |
244 local data = realData[realrow] | |
245 GameTooltip:SetOwner(rowFrame, "ANCHOR_CURSOR") | |
246 GameTooltip:SetText(format('Create %sx%s', data.link, data.queue)) | |
247 for i, reagent in pairs(data.reagents) do | |
248 GameTooltip:AddDoubleLine("\124cffffffff"..reagent.link, format("\124cffffffff%s/%s", reagent.count-reagent.need, reagent.count)) | |
249 --[[ | |
250 reagents[reagentId] = { | |
251 link = reagentLink, | |
252 itemID = vellumID, | |
253 name = reagentName, | |
254 count = 1, | |
255 price = self:GetReagentCost(reagentLink, 1), | |
256 need = 0, -- This will get populated after the decisions have been made. it can't | |
257 -- be done before that because highest profit items get priority on materials. | |
258 }]] | |
259 end | |
260 GameTooltip:Show() | |
261 end | |
262 end | 197 end |
263 end, | 198 end, |
264 ["OnLeave"] = function (rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...) | 199 ["OnLeave"] = function (rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...) |
265 GameTooltip:Hide() | 200 GameTooltip:Hide() |
266 end, | 201 end, |
337 end | 272 end |
338 | 273 |
339 btnProcess:SetScript("OnClick", function (self, button, down) | 274 btnProcess:SetScript("OnClick", function (self, button, down) |
340 local data = ItemAuditor:GetCraftingRow(1) | 275 local data = ItemAuditor:GetCraftingRow(1) |
341 if data then | 276 if data then |
342 -- This will make sure the correct tradeskill window is open. | |
343 local tradeskillName = GetTradeSkillLine() | |
344 if data.tradeskillName ~= tradeskillName then | |
345 CastSpellByName(data.tradeskillName) | |
346 end | |
347 | |
348 local queue = data.queue | 277 local queue = data.queue |
349 local vellumID = nil | 278 local vellumID = nil |
350 _, _, _, _, altVerb = GetTradeSkillInfo(data.tradeSkillIndex) | 279 _, _, _, _, altVerb = GetTradeSkillInfo(data.tradeSkillIndex) |
351 if altVerb == 'Enchant' and LSW.scrollData[data.recipeID] ~= nil then | 280 if altVerb == 'Enchant' and LSW.scrollData[data.recipeID] ~= nil then |
352 vellumID = LSW.scrollData[data.recipeID]["vellumID"] | 281 vellumID = LSW.scrollData[data.recipeID]["vellumID"] |
356 DoTradeSkill(data.tradeSkillIndex, queue) | 285 DoTradeSkill(data.tradeSkillIndex, queue) |
357 if vellumID then | 286 if vellumID then |
358 useVellum(vellumID) | 287 useVellum(vellumID) |
359 end | 288 end |
360 | 289 |
290 data.queue = data.queue - queue | |
291 ItemAuditor:RefreshCraftingTable() | |
361 UpdateProcessTooltip() | 292 UpdateProcessTooltip() |
362 end | 293 end |
363 end) | 294 end) |
364 | 295 |
365 btnProcess:SetScript("OnEnter", UpdateProcessTooltip) | 296 btnProcess:SetScript("OnEnter", UpdateProcessTooltip) |
485 }, | 416 }, |
486 } | 417 } |
487 | 418 |
488 Crafting.RegisterCraftingDecider('Is Profitable', isProfitable, isProfitableOptions) | 419 Crafting.RegisterCraftingDecider('Is Profitable', isProfitable, isProfitableOptions) |
489 | 420 |
490 function Crafting.ClearProfession(tradeskillName) | 421 |
491 -- This will initialize nameMap if it isn't already. | |
492 getQueueLocation('') | |
493 | |
494 for key = #(realData), 1, -1 do | |
495 if realData[key].tradeskillName == tradeskillName then | |
496 nameMap[realData[key].tradeskillName] = nil | |
497 tremove(realData, key) | |
498 end | |
499 end | |
500 end | |
501 | 422 |
502 local tableData = {} | 423 local tableData = {} |
503 function ItemAuditor:UpdateCraftingTable() | 424 function ItemAuditor:UpdateCraftingTable() |
504 if LSW == nil then | 425 if LSW == nil then |
505 self:Print("This feature requires LilSparky's Workshop.") | 426 self:Print("This feature requires LilSparky's Workshop.") |
509 elseif AucAdvanced and AucAdvanced.Version then | 430 elseif AucAdvanced and AucAdvanced.Version then |
510 else | 431 else |
511 self:Print("This feature requires Auctionator, Auctioneer, AuctionLite, or AuctionMaster.") | 432 self:Print("This feature requires Auctionator, Auctioneer, AuctionLite, or AuctionMaster.") |
512 return | 433 return |
513 end | 434 end |
514 local tradeskillName = GetTradeSkillLine() | 435 wipe(realData) |
515 Crafting.ClearProfession(tradeskillName) | |
516 shoppingList = nil | |
517 | |
518 wipe(tableData) | 436 wipe(tableData) |
519 | 437 |
520 local profitableItems = {} | 438 local profitableItems = {} |
521 local profitableIndex = 1 | 439 local profitableIndex = 1 |
522 local numChecked = 0 | 440 local numChecked = 0 |
523 local row = #(realData)+1 | 441 local row = 1 |
524 local numTradeSkills = GetNumTradeSkills() | 442 |
525 if tradeskillName == 'UNKNOWN' then | 443 for i = 1, GetNumTradeSkills() do |
526 numTradeSkills = 0 | |
527 end | |
528 | |
529 for i = 1, numTradeSkills do | |
530 local itemLink = GetTradeSkillItemLink(i) | 444 local itemLink = GetTradeSkillItemLink(i) |
531 local itemId = Utils.GetItemID(itemLink) | 445 local itemId = Utils.GetItemID(itemLink) |
532 local vellumID = nil | 446 local vellumID = nil |
533 | |
534 local spellName = itemName | |
535 | 447 |
536 --Figure out if its an enchant or not | 448 --Figure out if its an enchant or not |
537 _, _, _, _, altVerb = GetTradeSkillInfo(i) | 449 _, _, _, _, altVerb = GetTradeSkillInfo(i) |
538 if LSW.scrollData[itemId] ~= nil and altVerb == 'Enchant' then | 450 if LSW.scrollData[itemId] ~= nil and altVerb == 'Enchant' then |
539 -- Ask LSW for the correct scroll | 451 -- Ask LSW for the correct scroll |
589 local data = { | 501 local data = { |
590 recipeLink = recipeLink, | 502 recipeLink = recipeLink, |
591 recipeID = Utils.GetItemID(recipeLink), | 503 recipeID = Utils.GetItemID(recipeLink), |
592 link = itemLink, | 504 link = itemLink, |
593 name = itemName, | 505 name = itemName, |
594 skillName = skillName, | |
595 count = count, | 506 count = count, |
596 price = price, | 507 price = price, |
597 cost = totalCost, | 508 cost = totalCost, |
598 profit = price - totalCost, | 509 profit = price - totalCost, |
599 reagents = reagents, | 510 reagents = reagents, |
600 count = count, | 511 count = count, |
601 tradeSkillIndex = i, | 512 tradeSkillIndex = i, |
602 queue = 0, | 513 queue = 0, |
603 winner = "", | 514 winner = "", |
604 tradeskillName = tradeskillName, | |
605 } | 515 } |
606 | 516 |
607 data.winner, data.queue = Decide(data) | 517 data.winner, data.queue = Decide(data) |
608 --[[ | 518 --[[ |
609 If it wasn't vetoed we need to reduce the number by how many are owned | 519 If it wasn't vetoed we need to reduce the number by how many are owned |
614 end | 524 end |
615 | 525 |
616 -- If a tradeskill makes 5 at a time and something asks for 9, we should only | 526 -- If a tradeskill makes 5 at a time and something asks for 9, we should only |
617 -- craft twice to get 10. | 527 -- craft twice to get 10. |
618 data.queue = ceil(data.queue / GetTradeSkillNumMade(i)) | 528 data.queue = ceil(data.queue / GetTradeSkillNumMade(i)) |
619 | 529 |
620 realData[row] = data | 530 realData[row] = data |
621 nameMap[skillName] = row | |
622 row = row + 1 | 531 row = row + 1 |
623 end | 532 end |
624 end | 533 end |
625 end | 534 end |
626 table.sort(realData, function(a, b) return a.profit*max(1, a.queue) > b.profit*max(1, b.queue) end) | 535 table.sort(realData, function(a, b) return a.profit*max(1, a.queue) > b.profit*max(1, b.queue) end) |
653 craftingTable:SetFilter(tableFilter) | 562 craftingTable:SetFilter(tableFilter) |
654 self:RefreshCraftingTable() | 563 self:RefreshCraftingTable() |
655 end | 564 end |
656 end | 565 end |
657 | 566 |
658 | |
659 local numOwned = {} | |
660 | |
661 local function BuildShoppingList(character, queue) | |
662 for key, data in pairs(queue) do | |
663 if data.queue > 0 then | |
664 for id, reagent in pairs(data.reagents) do | |
665 if not numOwned[reagent.link] then | |
666 numOwned[reagent.link] = ItemAuditor:GetItemCount(Utils.GetItemID(reagent.link)) | |
667 end | |
668 numOwned[reagent.link] = numOwned[reagent.link] - reagent.count | |
669 | |
670 shoppingList[reagent.itemID] = shoppingList[reagent.itemID] or { | |
671 total = 0, | |
672 need = 0, | |
673 characters = {} | |
674 } | |
675 local slItem = shoppingList[reagent.itemID] | |
676 | |
677 | |
678 if numOwned[reagent.link] < 0 and not vellumLevelMap[reagent.itemID] then | |
679 reagent.need = min(reagent.count, abs(numOwned[reagent.link])) | |
680 elseif numOwned[reagent.link] >= 0 then | |
681 reagent.need = 0 | |
682 end | |
683 shoppingList[reagent.itemID].total = shoppingList[reagent.itemID].total + reagent.count | |
684 shoppingList[reagent.itemID].need = shoppingList[reagent.itemID].need + reagent.need | |
685 | |
686 slItem.characters[UnitName("player")] = slItem.characters[UnitName("player")] or {} | |
687 slItem.characters[UnitName("player")][data.recipeLink] = { | |
688 count = reagent.count, | |
689 need = reagent.need, | |
690 } | |
691 end | |
692 end | |
693 end | |
694 end | |
695 | |
696 function Crafting.GetShoppingList(itemID) | |
697 if not shoppingList then | |
698 shoppingList = {} | |
699 wipe(numOwned) | |
700 | |
701 -- This is done here instead of in the loop to make sure the current | |
702 -- character gets the first pick of materials. | |
703 local me = UnitName("player") | |
704 BuildShoppingList(me, realData) | |
705 | |
706 for alt, queue in pairs(ItemAuditor.db.factionrealm.queue) do | |
707 if alt ~= me then | |
708 BuildShoppingList(alt, queue) | |
709 end | |
710 end | |
711 elseif shoppingList[itemID] then | |
712 local data = shoppingList[itemID] | |
713 if data.need ~= max(0, data.total - ItemAuditor:GetItemCount(itemID)) then | |
714 shoppingList = nil | |
715 -- I'm rebuilding the list instead of just the item because | |
716 -- it will be eaiser than tracking down the queued recipes that | |
717 -- need to change. If this becomes a problem, I may change it. | |
718 return Crafting.GetShoppingList(itemID) | |
719 end | |
720 end | |
721 | |
722 return shoppingList[itemID] | |
723 end | |
724 | |
725 function ItemAuditor:RefreshCraftingTable() | 567 function ItemAuditor:RefreshCraftingTable() |
726 tableData = {} | |
727 nameMap = {} | |
728 for key, data in pairs(realData) do | 568 for key, data in pairs(realData) do |
729 nameMap[data.name] = key | |
730 | |
731 tableData[key] = { | 569 tableData[key] = { |
732 data.name, | 570 data.name, |
733 data.cost, | 571 data.cost, |
734 data.price, | 572 data.price, |
735 data.winner, | 573 data.winner, |