Mercurial > wow > itemauditor
comparison Modules/Crafting.lua @ 124:060d1c45afab
[mq]: Vellums
| author | Asa Ayers <Asa.Ayers@Gmail.com> |
|---|---|
| date | Thu, 02 Sep 2010 22:22:51 -0700 |
| parents | 4aa521a2a7e7 |
| children | e8d3c299542c |
comparison
equal
deleted
inserted
replaced
| 123:4aa521a2a7e7 | 124:060d1c45afab |
|---|---|
| 1 local ItemAuditor = select(2, ...) | 1 local ItemAuditor = select(2, ...) |
| 2 local Crafting = ItemAuditor:NewModule("Crafting") | 2 local Crafting = ItemAuditor:NewModule("Crafting", 'AceEvent-3.0') |
| 3 | 3 |
| 4 local Utils = ItemAuditor:GetModule("Utils") | 4 local Utils = ItemAuditor:GetModule("Utils") |
| 5 | 5 |
| 6 local AceGUI = LibStub("AceGUI-3.0") | 6 local AceGUI = LibStub("AceGUI-3.0") |
| 7 local ScrollingTable = LibStub("ScrollingTable") | 7 local ScrollingTable = LibStub("ScrollingTable") |
| 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 | 13 |
| 14 local vellumLevelMap = { | |
| 15 [38682] = 37602, -- Armor Vellum => Armor Vellum II | |
| 16 [37602] = 43145, -- Armor Vellum II => Armor Vellum III | |
| 17 [39349] = 39350, -- Weapon Vellum => Weapon Vellum II | |
| 18 [39350] = 43146, -- Weapon Vellum II => Weapon Vellum III | |
| 19 } | |
| 14 | 20 |
| 15 local queueDestinations = {} | 21 local queueDestinations = {} |
| 16 local displayCraftingDestinations = {} | 22 local displayCraftingDestinations = {} |
| 17 function Crafting.RegisterQueueDestination(name, destination) | 23 function Crafting.RegisterQueueDestination(name, destination) |
| 18 queueDestinations[name] = destination | 24 queueDestinations[name] = destination |
| 236 GameTooltip:SetOwner(this, "ANCHOR_CURSOR") | 242 GameTooltip:SetOwner(this, "ANCHOR_CURSOR") |
| 237 GameTooltip:SetText(format('Create %sx%s', data.link, data.queue)) | 243 GameTooltip:SetText(format('Create %sx%s', data.link, data.queue)) |
| 238 GameTooltip:Show() | 244 GameTooltip:Show() |
| 239 end | 245 end |
| 240 end | 246 end |
| 247 | |
| 248 --[[ | |
| 249 When enchanting UseContainerItem seems to be protected, so the enchants | |
| 250 have to be done one at a time. | |
| 251 ]] | |
| 252 local function useVellum(vellumID, idealVellum) | |
| 253 for bagID = 0, NUM_BAG_SLOTS do | |
| 254 for slotID = 0, GetContainerNumSlots(bagID) do | |
| 255 local link = GetContainerItemLink(bagID, slotID) | |
| 256 local id = Utils.GetItemID(link); | |
| 257 if id == vellumID then | |
| 258 if idealVellum then | |
| 259 ItemAuditor:Print("Using %s instead of %s.", | |
| 260 select(2, GetItemInfo(vellumID)), | |
| 261 select(2, GetItemInfo(idealVellum)) | |
| 262 ) | |
| 263 end | |
| 264 UseContainerItem(bagID, slotID) | |
| 265 return | |
| 266 end | |
| 267 end | |
| 268 end | |
| 269 if vellumLevelMap[vellumID] then | |
| 270 return useVellum(vellumLevelMap[vellumID], idealVellum or vellumID) | |
| 271 end | |
| 272 end | |
| 273 | |
| 241 btnProcess:SetScript("OnClick", function (self, button, down) | 274 btnProcess:SetScript("OnClick", function (self, button, down) |
| 242 local data = ItemAuditor:GetCraftingRow(1) | 275 local data = ItemAuditor:GetCraftingRow(1) |
| 243 if data then | 276 if data then |
| 244 ItemAuditor:Print('Crafting %sx%s', data.link, data.queue) | 277 local queue = data.queue |
| 245 DoTradeSkill(data.tradeSkillIndex, data.queue) | 278 local vellumID = nil |
| 246 data.queue = 0 | 279 _, _, _, _, altVerb = GetTradeSkillInfo(data.tradeSkillIndex) |
| 280 if altVerb == 'Enchant' and LSW.scrollData[data.recipeID] ~= nil then | |
| 281 vellumID = LSW.scrollData[data.recipeID]["vellumID"] | |
| 282 queue = 1 | |
| 283 end | |
| 284 ItemAuditor:Print('Crafting %sx%s', data.link, queue) | |
| 285 DoTradeSkill(data.tradeSkillIndex, queue) | |
| 286 if vellumID then | |
| 287 useVellum(vellumID) | |
| 288 end | |
| 289 | |
| 290 data.queue = data.queue - queue | |
| 247 ItemAuditor:RefreshCraftingTable() | 291 ItemAuditor:RefreshCraftingTable() |
| 248 UpdateProcessTooltip() | 292 UpdateProcessTooltip() |
| 249 end | 293 end |
| 250 end) | 294 end) |
| 251 | 295 |
| 285 end) | 329 end) |
| 286 ItemAuditor:UpdateCraftingTable() | 330 ItemAuditor:UpdateCraftingTable() |
| 287 | 331 |
| 288 return craftingContent | 332 return craftingContent |
| 289 end | 333 end |
| 290 | |
| 291 | |
| 292 | 334 |
| 293 ItemAuditor:RegisterTab('Crafting', 'tab_crafting', ShowCrafting) | 335 ItemAuditor:RegisterTab('Crafting', 'tab_crafting', ShowCrafting) |
| 294 function ItemAuditor:DisplayCrafting() | 336 function ItemAuditor:DisplayCrafting() |
| 295 self:CreateFrame('tab_crafting') | 337 self:CreateFrame('tab_crafting') |
| 296 end | 338 end |
| 399 local row = 1 | 441 local row = 1 |
| 400 | 442 |
| 401 for i = 1, GetNumTradeSkills() do | 443 for i = 1, GetNumTradeSkills() do |
| 402 local itemLink = GetTradeSkillItemLink(i) | 444 local itemLink = GetTradeSkillItemLink(i) |
| 403 local itemId = Utils.GetItemID(itemLink) | 445 local itemId = Utils.GetItemID(itemLink) |
| 446 local vellumID = nil | |
| 404 | 447 |
| 405 --Figure out if its an enchant or not | 448 --Figure out if its an enchant or not |
| 406 _, _, _, _, altVerb = GetTradeSkillInfo(i) | 449 _, _, _, _, altVerb = GetTradeSkillInfo(i) |
| 407 if LSW.scrollData[itemId] ~= nil and altVerb == 'Enchant' then | 450 if LSW.scrollData[itemId] ~= nil and altVerb == 'Enchant' then |
| 408 -- Ask LSW for the correct scroll | 451 -- Ask LSW for the correct scroll |
| 409 itemId = LSW.scrollData[itemId]["scrollID"] | 452 local sd = LSW.scrollData[itemId] |
| 453 itemId = sd.scrollID | |
| 454 vellumID = sd.vellumID | |
| 410 end | 455 end |
| 411 | 456 |
| 412 local recipeLink = GetTradeSkillRecipeLink(i) | 457 local recipeLink = GetTradeSkillRecipeLink(i) |
| 413 local stackSize = 1 | 458 local stackSize = 1 |
| 414 if recipeLink ~= nil and itemId ~= nil then | 459 if recipeLink ~= nil and itemId ~= nil then |
| 425 local reagentLink = GetTradeSkillReagentItemLink(i, reagentId) | 470 local reagentLink = GetTradeSkillReagentItemLink(i, reagentId) |
| 426 local reagentTotalCost = self:GetReagentCost(reagentLink, reagentCount) | 471 local reagentTotalCost = self:GetReagentCost(reagentLink, reagentCount) |
| 427 | 472 |
| 428 reagents[reagentId] = { | 473 reagents[reagentId] = { |
| 429 link = reagentLink, | 474 link = reagentLink, |
| 475 itemID = Utils.GetItemID(reagentLink), | |
| 430 name = reagentName, | 476 name = reagentName, |
| 431 count = reagentCount, | 477 count = reagentCount, |
| 432 price = reagentTotalCost / reagentCount, | 478 price = reagentTotalCost / reagentCount, |
| 433 need = 0, -- This will get populated after the decisions have been made. it can't | 479 need = 0, -- This will get populated after the decisions have been made. it can't |
| 434 -- be done before that because highest profit items get priority on materials. | 480 -- be done before that because highest profit items get priority on materials. |
| 435 } | 481 } |
| 436 totalCost = totalCost + reagentTotalCost | 482 totalCost = totalCost + reagentTotalCost |
| 483 end | |
| 484 if vellumID then | |
| 485 reagentId = GetTradeSkillNumReagents(i) + 1 | |
| 486 local reagentName, reagentLink = GetItemInfo(vellumID) | |
| 487 reagents[reagentId] = { | |
| 488 link = reagentLink, | |
| 489 itemID = vellumID, | |
| 490 name = reagentName, | |
| 491 count = 1, | |
| 492 price = self:GetReagentCost(reagentLink, 1), | |
| 493 need = 0, -- This will get populated after the decisions have been made. it can't | |
| 494 -- be done before that because highest profit items get priority on materials. | |
| 495 } | |
| 496 totalCost = totalCost + self:GetReagentCost(reagentLink, 1) | |
| 437 end | 497 end |
| 438 | 498 |
| 439 local price = (self:GetAuctionPrice(itemLink) or 0) | 499 local price = (self:GetAuctionPrice(itemLink) or 0) |
| 440 totalCost = totalCost + (price * ItemAuditor:GetAHCut()) | 500 totalCost = totalCost + (price * ItemAuditor:GetAHCut()) |
| 441 local data = { | 501 local data = { |
| 473 end | 533 end |
| 474 end | 534 end |
| 475 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) |
| 476 | 536 |
| 477 local numOwned = {} | 537 local numOwned = {} |
| 538 | |
| 478 for key, data in pairs(realData) do | 539 for key, data in pairs(realData) do |
| 479 data.haveMaterials = true | 540 data.haveMaterials = true |
| 480 for id, reagent in pairs(data.reagents) do | 541 for id, reagent in pairs(data.reagents) do |
| 481 reagent.count = reagent.count * data.queue | 542 reagent.count = reagent.count * data.queue |
| 482 | 543 |
| 483 if not numOwned[reagent.link] then | 544 if not numOwned[reagent.link] then |
| 484 numOwned[reagent.link] = ItemAuditor:GetItemCount(ItemAuditor:GetIDFromLink(reagent.link)) | 545 numOwned[reagent.link] = ItemAuditor:GetItemCount(ItemAuditor:GetIDFromLink(reagent.link)) |
| 485 end | 546 end |
| 486 numOwned[reagent.link] = numOwned[reagent.link] - reagent.count | 547 numOwned[reagent.link] = numOwned[reagent.link] - reagent.count |
| 487 | 548 |
| 488 if numOwned[reagent.link] < 0 then | 549 -- Vellums count in cost, but not against whether or not you have the mats. |
| 550 -- I chose to do it this way because you can use a higher level of vellum | |
| 551 -- and I'm not sure the best way to determine cost and materials in that situation. | |
| 552 if numOwned[reagent.link] < 0 and not vellumLevelMap[reagent.itemID] then | |
| 489 data.haveMaterials = false | 553 data.haveMaterials = false |
| 490 reagent.need = min(reagent.count, abs(numOwned[reagent.link])) | 554 reagent.need = min(reagent.count, abs(numOwned[reagent.link])) |
| 491 end | 555 end |
| 492 end | 556 end |
| 493 end | 557 end |
