@@ -479,19 +479,50 @@ end
479
479
480
480
--- also sets a requiredSelectionReagent if not yet set
481
481
function CraftSim .RecipeData :SetNonQualityReagentsMax ()
482
+ local print = CraftSim .DEBUG :RegisterDebugID (" Classes.RecipeData.SetNonQualityReagentsMax" )
483
+ print (" SetNonQualityReagentsMax" , false , true )
482
484
for _ , reagent in pairs (self .reagentData .requiredReagents ) do
483
485
if not reagent .hasQuality then
484
486
reagent .items [1 ].quantity = reagent .requiredQuantity
485
487
end
486
488
end
487
489
488
490
if self .reagentData :HasRequiredSelectableReagent () then
491
+ print (" - HasRequiredSelectableReagent" , false , false )
489
492
if not self .reagentData .requiredSelectableReagentSlot .activeReagent then
490
- for _ , possibleRequiredSelectableReagent in pairs (self .reagentData .requiredSelectableReagentSlot .possibleReagents or {}) do
491
- if possibleRequiredSelectableReagent :IsOrderReagentIn (self ) then
492
- self .reagentData .requiredSelectableReagentSlot :SetReagent (possibleRequiredSelectableReagent .item
493
- :GetItemID ())
494
- break
493
+ print (" - No active reagent" , false , false )
494
+ local orderReagent = GUTIL :Find (self .reagentData .requiredSelectableReagentSlot .possibleReagents or {},
495
+ function (possibleOrderReagent )
496
+ if possibleOrderReagent :IsOrderReagentIn (self ) then
497
+ return true
498
+ end
499
+ return false
500
+ end )
501
+ if orderReagent then
502
+ self .reagentData .requiredSelectableReagentSlot :SetReagent (orderReagent .item :GetItemID ())
503
+ else
504
+ local cheapestReagent
505
+ local cheapestPrice
506
+ local possibleReagents = GUTIL :Filter (
507
+ self .reagentData .requiredSelectableReagentSlot .possibleReagents or {}, function (optionalReagent )
508
+ return not GUTIL :isItemSoulbound (optionalReagent .item :GetItemID ())
509
+ end )
510
+ for _ , optionalReagent in ipairs (possibleReagents ) do
511
+ local reagentPrice = CraftSim .PRICE_SOURCE :GetMinBuyoutByItemID (optionalReagent .item :GetItemID (),
512
+ true , false , true )
513
+ if not cheapestReagent then
514
+ cheapestReagent = optionalReagent
515
+ cheapestPrice = reagentPrice
516
+ else
517
+ if reagentPrice < cheapestPrice then
518
+ cheapestPrice = reagentPrice
519
+ cheapestReagent = optionalReagent
520
+ end
521
+ end
522
+ end
523
+
524
+ if cheapestReagent then
525
+ self .reagentData .requiredSelectableReagentSlot :SetReagent (cheapestReagent .item :GetItemID ())
495
526
end
496
527
end
497
528
end
0 commit comments