comparison Modules/Queue.lua @ 146:ebe6f90c4bb9

Fixed IM crafting so the bonus queue isn?t reset after an item is created.
author Zerotorescue
date Thu, 20 Jan 2011 00:15:09 +0100
parents 6a52272a0e5a
children 4e5d8033ed5f
comparison
equal deleted inserted replaced
145:6a52272a0e5a 146:ebe6f90c4bb9
316 function mod:SpellCastComplete(_, unit, _, _, _, spellId) 316 function mod:SpellCastComplete(_, unit, _, _, _, spellId)
317 -- Sadly the item isn't put in our inventory yet so we don't know how many were made. 317 -- Sadly the item isn't put in our inventory yet so we don't know how many were made.
318 -- Because of that we assume the average amount was made, this isn't really the best solution, but it's pretty-est - for now. 318 -- Because of that we assume the average amount was made, this isn't really the best solution, but it's pretty-est - for now.
319 319
320 if unit == "player" and currentQueueItem and spellId == currentQueueItem.craft.spellId then 320 if unit == "player" and currentQueueItem and spellId == currentQueueItem.craft.spellId then
321 -- Make sure the old amount is accurate, this won't be updated by the spell we just finished, that item hasn't been received yet
322 currentQueueItem.amount = mod:GetRestockAmount(currentQueueItem.itemId, currentQueueItem.groupName);
323
324 -- Decrease amount remaining by one quantity 321 -- Decrease amount remaining by one quantity
325 currentQueueItem.amount = ( currentQueueItem.amount - currentQueueItem.craft.quantity ); 322 currentQueueItem.amount = ( currentQueueItem.amount - currentQueueItem.craft.quantity );
326 323
327 if currentQueueItem.amount < 1 then 324 if currentQueueItem.amount < 1 then
328 -- We finished crafting this item 325 -- We finished crafting this item
456 addon:Debug("This group (%s) has no items.", groupName); 453 addon:Debug("This group (%s) has no items.", groupName);
457 return; 454 return;
458 end 455 end
459 456
460 -- Retrieve group settings 457 -- Retrieve group settings
458 local restockTarget = addon:GetOptionByKey(groupName, "restockTarget");
459 local bonusQueue = addon:GetOptionByKey(groupName, "bonusQueue");
461 local minCraftingQueue = floor( addon:GetOptionByKey(groupName, "minCraftingQueue") * addon:GetOptionByKey(groupName, "restockTarget") ); -- If the minCraftingQueue is 5% and restockTarget is 60, this will result in 3 460 local minCraftingQueue = floor( addon:GetOptionByKey(groupName, "minCraftingQueue") * addon:GetOptionByKey(groupName, "restockTarget") ); -- If the minCraftingQueue is 5% and restockTarget is 60, this will result in 3
462 local priceThreshold = addon:GetOptionByKey(groupName, "priceThreshold"); 461 local priceThreshold = addon:GetOptionByKey(groupName, "priceThreshold");
463 462
464 for itemId, count in pairs(addon.db.profile.groups[groupName].items) do 463 for itemId, count in pairs(addon.db.profile.groups[groupName].items) do
465 if craftables[itemId] then 464 if craftables[itemId] then
466 local amount, bonus = self:GetRestockAmount(itemId, groupName); 465 local currentStock = addon:GetItemCount(itemId, groupName);
467 466
468 if amount and amount >= minCraftingQueue then 467 if currentStock >= 0 then
469 -- If we are queuing at least one AND more than the minimum amount, then proceed 468 -- Current stock will be -1 when no itemcount addon was found
470 469
471 -- Auction value settings 470 -- Calculate the amount to be queued
472 local value = (priceThreshold ~= 0 and addon:GetAuctionValue(IdToItemLink(itemId), groupName)); 471 local amount = ( restockTarget - currentStock );
473 472 local bonus = 0;
474 if priceThreshold == 0 or value == -1 or value >= priceThreshold then 473
475 -- If no price threshold is set or the auction value is equal to or larger than the price threshold, then proceed 474 if currentStock == 0 and bonusQueue > 0 then
476 475 -- If we have none left and the bonus queue is enabled, modify the amount to be queued
477 self:Queue(itemId, amount, bonus, craftables[itemId], groupName); 476
477 bonus = floor( ( amount * ( bonusQueue ) ) + .5 ); -- round
478
479 -- Update amount
480 amount = (amount + bonus);
481 end
482
483 if amount >= minCraftingQueue then
484 -- If we are queuing at least one AND more than the minimum amount, then proceed
485
486 -- Get auction value when it is relevant
487 local value = (priceThreshold ~= 0 and addon:GetAuctionValue(IdToItemLink(itemId), groupName));
488
489 if priceThreshold == 0 or value == -1 or value >= priceThreshold then
490 -- If no price threshold is set or the auction value is equal to or larger than the price threshold, then proceed
491
492 self:Queue(itemId, amount, bonus, craftables[itemId], groupName);
493 else
494 self:Skip(itemId, skipReasons.LOW_VALUE);
495 --addon:Debug("%s is valued at %s while %s is needed", IdToItemLink(itemId), tostring(value), tostring(priceThreshold));
496 end
478 else 497 else
479 self:Skip(itemId, skipReasons.LOW_VALUE); 498 if amount <= 0 then
480 --addon:Debug("%s is valued at %s while %s is needed", IdToItemLink(itemId), tostring(value), tostring(priceThreshold)); 499 -- less than 0 = (over)capped
500 self:Skip(itemId, skipReasons.CAPPED);
501 else
502 -- more than 0 = below min crafting queue
503 self:Skip(itemId, skipReasons.MIN_CRAFTING_QUEUE);
504 end
481 end 505 end
482 else 506 else
483 if not amount then 507 -- No item count addon
484 -- nil = no item count addon 508 self:Skip(itemId, skipReasons.NO_ITEMCOUNT_ADDON);
485 self:Skip(itemId, skipReasons.NO_ITEMCOUNT_ADDON); 509 addon:Print("No usable itemcount addon found.");
486 addon:Print("No usable itemcount addon found."); 510 return;
487 return;
488 elseif amount <= 0 then
489 -- less than 0 = (over)capped
490 self:Skip(itemId, skipReasons.CAPPED);
491 else
492 -- more than 0 = below min crafting queue
493 self:Skip(itemId, skipReasons.MIN_CRAFTING_QUEUE);
494 end
495 end 511 end
496 else 512 else
497 self:Skip(itemId, skipReasons.NOT_CRAFTABLE); 513 self:Skip(itemId, skipReasons.NOT_CRAFTABLE);
498 end 514 end
499 end
500 end
501
502 function mod:GetRestockAmount(itemId, groupName)
503 local currentStock = addon:GetItemCount(itemId, groupName);
504
505 if currentStock >= 0 then
506 -- Current stock will be -1 when no itemcount addon was found
507
508 local restockTarget = addon:GetOptionByKey(groupName, "restockTarget");
509 local bonusQueue = addon:GetOptionByKey(groupName, "bonusQueue");
510
511 -- Calculate the amount to be queued
512 local amount = ( restockTarget - currentStock );
513 local bonus = 0;
514
515 if currentStock == 0 and bonusQueue > 0 then
516 -- If we have none left and the bonus queue is enabled, modify the amount to be queued
517
518 bonus = floor( ( amount * ( bonusQueue ) ) + .5 ); -- round
519
520 -- Update amount
521 amount = (amount + bonus);
522 end
523
524 return amount, bonus;
525 else
526 return;
527 end 515 end
528 end 516 end
529 517
530 function mod:Queue(itemId, amount, bonus, craft, groupName) 518 function mod:Queue(itemId, amount, bonus, craft, groupName)
531 tinsert(queue, { 519 tinsert(queue, {