comparison Modules/Crafting.lua @ 135:a529a4a4ccbe

I removed the persistent queue (Ticket 33) It caused to many bugs and was blocking me from getting other things done. I think its something that will get implemented again once I figure out the best way to do it.
author Asa Ayers <Asa.Ayers@Gmail.com>
date Sat, 02 Oct 2010 11:38:22 -0700
parents 5eefa40e2a29 7f81764aa03a
children 106c1523777e
comparison
equal deleted inserted replaced
133:5eefa40e2a29 135:a529a4a4ccbe
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 13 local nameMap = nil
14 local shoppingList = nil
15 14
16 local vellumLevelMap = { 15 local vellumLevelMap = {
17 [38682] = 37602, -- Armor Vellum => Armor Vellum II 16 [38682] = 37602, -- Armor Vellum => Armor Vellum II
18 [37602] = 43145, -- Armor Vellum II => Armor Vellum III 17 [37602] = 43145, -- Armor Vellum II => Armor Vellum III
19 [39349] = 39350, -- Weapon Vellum => Weapon Vellum II 18 [39349] = 39350, -- Weapon Vellum => Weapon Vellum II
20 [39350] = 43146, -- Weapon Vellum II => Weapon Vellum III 19 [39350] = 43146, -- Weapon Vellum II => Weapon Vellum III
21 } 20 }
22 21
23 function Crafting:OnInitialize() 22 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") 23 self:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
31 end 24 end
32 25
33 local function getQueueLocation(name) 26 local function getQueueLocation(name)
34 if not nameMap then 27 if not nameMap then
232 craftingTable.frame:SetPoint("BOTTOMRIGHT", craftingContent, 0, 30) 225 craftingTable.frame:SetPoint("BOTTOMRIGHT", craftingContent, 0, 30)
233 226
234 craftingTable:RegisterEvents({ 227 craftingTable:RegisterEvents({
235 ["OnEnter"] = function (rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...) 228 ["OnEnter"] = function (rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...)
236 if realrow then 229 if realrow then
237 if column == 1 then 230 local data = realData[realrow]
238 local data = realData[realrow] 231
239 232 GameTooltip:SetOwner(rowFrame, "ANCHOR_CURSOR")
240 GameTooltip:SetOwner(rowFrame, "ANCHOR_CURSOR") 233 GameTooltip:SetHyperlink(data.link)
241 GameTooltip:SetHyperlink(data.link) 234 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 235 end
263 end, 236 end,
264 ["OnLeave"] = function (rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...) 237 ["OnLeave"] = function (rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...)
265 GameTooltip:Hide() 238 GameTooltip:Hide()
266 end, 239 end,
485 }, 458 },
486 } 459 }
487 460
488 Crafting.RegisterCraftingDecider('Is Profitable', isProfitable, isProfitableOptions) 461 Crafting.RegisterCraftingDecider('Is Profitable', isProfitable, isProfitableOptions)
489 462
490 function Crafting.ClearProfession(tradeskillName) 463
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 464
502 local tableData = {} 465 local tableData = {}
503 function ItemAuditor:UpdateCraftingTable() 466 function ItemAuditor:UpdateCraftingTable()
504 if LSW == nil then 467 if LSW == nil then
505 self:Print("This feature requires LilSparky's Workshop.") 468 self:Print("This feature requires LilSparky's Workshop.")
510 else 473 else
511 self:Print("This feature requires Auctionator, Auctioneer, AuctionLite, or AuctionMaster.") 474 self:Print("This feature requires Auctionator, Auctioneer, AuctionLite, or AuctionMaster.")
512 return 475 return
513 end 476 end
514 local tradeskillName = GetTradeSkillLine() 477 local tradeskillName = GetTradeSkillLine()
515 Crafting.ClearProfession(tradeskillName)
516 shoppingList = nil
517 478
518 wipe(tableData) 479 wipe(tableData)
519 480
520 local profitableItems = {} 481 local profitableItems = {}
521 local profitableIndex = 1 482 local profitableIndex = 1
522 local numChecked = 0 483 local numChecked = 0
523 local row = #(realData)+1
524 local numTradeSkills = GetNumTradeSkills() 484 local numTradeSkills = GetNumTradeSkills()
525 if tradeskillName == 'UNKNOWN' then 485 if tradeskillName == 'UNKNOWN' then
526 numTradeSkills = 0 486 numTradeSkills = 0
527 end 487 end
528 488
489 local row = 1
490
529 for i = 1, numTradeSkills do 491 for i = 1, numTradeSkills do
530 local itemLink = GetTradeSkillItemLink(i) 492 local itemLink = GetTradeSkillItemLink(i)
531 local itemId = Utils.GetItemID(itemLink) 493 local itemId = Utils.GetItemID(itemLink)
532 local vellumID = nil 494 local vellumID = nil
533
534 local spellName = itemName
535 495
536 --Figure out if its an enchant or not 496 --Figure out if its an enchant or not
537 _, _, _, _, altVerb = GetTradeSkillInfo(i) 497 _, _, _, _, altVerb = GetTradeSkillInfo(i)
538 if LSW.scrollData[itemId] ~= nil and altVerb == 'Enchant' then 498 if LSW.scrollData[itemId] ~= nil and altVerb == 'Enchant' then
539 -- Ask LSW for the correct scroll 499 -- Ask LSW for the correct scroll
653 craftingTable:SetFilter(tableFilter) 613 craftingTable:SetFilter(tableFilter)
654 self:RefreshCraftingTable() 614 self:RefreshCraftingTable()
655 end 615 end
656 end 616 end
657 617
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() 618 function ItemAuditor:RefreshCraftingTable()
726 -- If the crafting table hasn't been created/displayed, there is no 619 -- If the crafting table hasn't been created/displayed, there is no
727 -- reason to try to update it. 620 -- reason to try to update it.
728 if not craftingTable then 621 if not craftingTable then
729 return 622 return