Mercurial > wow > itemauditor
comparison Modules/Crafting.lua @ 74:71de6e86a1a4 release 2010-07-29
Fixed a bug where tradeskill that don't produce items, like Inscription Research, cause IA to crash.
Added some API enhancements.
Added ArkInventory as an optional dependency so it will be loaded before IA.
author | Asa Ayers <Asa.Ayers@Gmail.com> |
---|---|
date | Thu, 29 Jul 2010 22:33:50 -0700 |
parents | 8e9beb8a0330 |
children | a8fc802b42ba |
comparison
equal
deleted
inserted
replaced
73:cd00b87fad31 | 74:71de6e86a1a4 |
---|---|
155 data = ItemAuditor:GetCraftingRow(index) | 155 data = ItemAuditor:GetCraftingRow(index) |
156 | 156 |
157 end | 157 end |
158 end | 158 end |
159 | 159 |
160 -- ItemAuditor:GetModule('Crafting').filter_queued = false | |
161 Crafting.filter_queued = true | |
162 local function tableFilter(self, row, ...) | |
163 -- column 5 is how many should be crafted | |
164 if Crafting.filter_queued and row[5] <= 0 then | |
165 return false | |
166 end | |
167 return true | |
168 end | |
169 | |
160 local craftingContent = false | 170 local craftingContent = false |
161 local craftingTable = false | 171 local craftingTable = false |
162 local btnProcess = false | 172 local btnProcess = false |
163 local function ShowCrafting(container) | 173 local function ShowCrafting(container) |
164 if craftingContent == false then | 174 if craftingContent == false then |
289 end | 299 end |
290 | 300 |
291 local lastWinnder = "" | 301 local lastWinnder = "" |
292 local function Decide(data) | 302 local function Decide(data) |
293 local newDecision = 0 | 303 local newDecision = 0 |
304 local reason = "" | |
294 for name, decider in pairs(craftingDeciders) do | 305 for name, decider in pairs(craftingDeciders) do |
295 if not ItemAuditor.db.profile.disabled_deciders[name] and name ~= lastWinner then | 306 if not ItemAuditor.db.profile.disabled_deciders[name] and name ~= lastWinner then |
296 newDecision = decider(data) | 307 newDecision, reason = decider(data) |
308 | |
297 if newDecision > data.queue then | 309 if newDecision > data.queue then |
298 data.queue = newDecision | 310 data.queue = newDecision |
299 lastWinner = name | 311 lastWinner = (reason or name) |
300 return Decide(data) | 312 return Decide(data) |
301 elseif newDecision < 0 then | 313 elseif newDecision < 0 then |
302 lastWinner = "" | 314 lastWinner = "" |
303 return 'VETO: '..name, 0 | 315 return 'VETO: '..(reason or name), -1 |
304 end | 316 end |
305 end | 317 end |
306 end | 318 end |
307 | 319 |
308 winner = lastWinner | 320 winner = lastWinner |
318 return -1 | 330 return -1 |
319 end | 331 end |
320 | 332 |
321 Crafting.RegisterCraftingDecider('Is Profitable', isProfitable) | 333 Crafting.RegisterCraftingDecider('Is Profitable', isProfitable) |
322 | 334 |
323 local function tableFilter(self, row, ...) | 335 |
324 -- column 5 is how many should be crafted | |
325 return row[5] > 0 | |
326 end | |
327 | 336 |
328 local tableData = {} | 337 local tableData = {} |
329 function ItemAuditor:UpdateCraftingTable() | 338 function ItemAuditor:UpdateCraftingTable() |
330 if LSW == nil then | 339 if LSW == nil then |
331 self:Print("This feature requires LilSparky's Workshop.") | 340 self:Print("This feature requires LilSparky's Workshop.") |
363 local recipeLink = GetTradeSkillRecipeLink(i) | 372 local recipeLink = GetTradeSkillRecipeLink(i) |
364 local stackSize = 1 | 373 local stackSize = 1 |
365 if recipeLink ~= nil and itemId ~= nil then | 374 if recipeLink ~= nil and itemId ~= nil then |
366 local skillName, skillType, numAvailable, isExpanded, altVerb = GetTradeSkillInfo(i) | 375 local skillName, skillType, numAvailable, isExpanded, altVerb = GetTradeSkillInfo(i) |
367 local itemName, itemLink= GetItemInfo(itemId) | 376 local itemName, itemLink= GetItemInfo(itemId) |
368 | 377 |
369 local count = Altoholic:GetItemCount(itemId) | 378 -- This check has to be here for things like Inscription Research that don't produce an item. |
370 local reagents = {} | 379 if itemLink then |
371 local totalCost = 0 | 380 local count = Altoholic:GetItemCount(itemId) |
372 for reagentId = 1, GetTradeSkillNumReagents(i) do | 381 local reagents = {} |
373 local reagentName, _, reagentCount = GetTradeSkillReagentInfo(i, reagentId); | 382 local totalCost = 0 |
374 local reagentLink = GetTradeSkillReagentItemLink(i, reagentId) | 383 for reagentId = 1, GetTradeSkillNumReagents(i) do |
384 local reagentName, _, reagentCount = GetTradeSkillReagentInfo(i, reagentId); | |
385 local reagentLink = GetTradeSkillReagentItemLink(i, reagentId) | |
386 | |
387 reagents[reagentId] = { | |
388 name = reagentName, | |
389 count = reagentCount, | |
390 price = self:GetReagentCost(reagentLink, reagentCount), | |
391 } | |
392 totalCost = totalCost + self:GetReagentCost(reagentLink, reagentCount) | |
393 end | |
394 local data = { | |
395 recipeLink = recipeLink, | |
396 link = itemLink, | |
397 name = itemName, | |
398 count = count, | |
399 price = (self:GetAuctionPrice(itemLink) or 0), | |
400 cost = totalCost, | |
401 profit = (self:GetAuctionPrice(itemLink) or 0) - totalCost, | |
402 reagents = reagents, | |
403 count = count, | |
404 tradeSkillIndex = i, | |
405 queue = 0, | |
406 winner = "", | |
407 } | |
375 | 408 |
376 reagents[reagentId] = { | 409 data.winner, data.queue = Decide(data) |
377 name = reagentName, | 410 data.queue = data.queue - count |
378 count = reagentCount, | 411 |
379 price = self:GetReagentCost(reagentLink, reagentCount), | 412 -- If a tradeskill makes 5 at a time and something asks for 9, we should only |
380 } | 413 -- craft twice to get 10. |
381 totalCost = totalCost + self:GetReagentCost(reagentLink, reagentCount) | 414 data.queue = ceil(data.queue / GetTradeSkillNumMade(i)) |
382 end | 415 |
383 | 416 realData[row] = data |
384 local data = { | 417 row = row + 1 |
385 recipeLink = recipeLink, | 418 end |
386 link = itemLink, | |
387 name = itemName, | |
388 count = count, | |
389 price = (self:GetAuctionPrice(itemLink) or 0), | |
390 cost = totalCost, | |
391 profit = (self:GetAuctionPrice(itemLink) or 0) - totalCost, | |
392 reagents = reagents, | |
393 count = count, | |
394 tradeSkillIndex = i, | |
395 queue = 0, | |
396 winner = "", | |
397 } | |
398 | |
399 data.winner, data.queue = Decide(data) | |
400 data.queue = data.queue - count | |
401 | |
402 -- If a tradeskill makes 5 at a time and something asks for 9, we should only | |
403 -- craft twice to get 10. | |
404 data.queue = ceil(data.queue / GetTradeSkillNumMade(i)) | |
405 | |
406 realData[row] = data | |
407 row = row + 1 | |
408 end | 419 end |
409 end | 420 end |
410 table.sort(realData, function(a, b) return a.profit*a.queue > b.profit*b.queue end) | 421 table.sort(realData, function(a, b) return a.profit*a.queue > b.profit*b.queue end) |
411 if craftingTable then | 422 if craftingTable then |
412 craftingTable:SetFilter(tableFilter) | 423 craftingTable:SetFilter(tableFilter) |