Add batch cooking (#9359)

This commit is contained in:
themias
2022-07-14 22:25:16 -04:00
committed by GitHub
parent 2b726617cd
commit b76c251829

View File

@@ -268,13 +268,10 @@ namespace Content.Server.Kitchen.Components
} }
// Check recipes // Check recipes
FoodRecipePrototype? recipeToCook = null; (FoodRecipePrototype, int) portionedRecipe = _recipeManager.Recipes.Select(
foreach (var r in _recipeManager.Recipes.Where(r => r => CanSatisfyRecipe(r, solidsDict, reagentDict)).Where(r => r.Item2 > 0).FirstOrDefault();
CanSatisfyRecipe(r, solidsDict, reagentDict))) FoodRecipePrototype? recipeToCook = portionedRecipe.Item1;
{
recipeToCook = r;
}
SetAppearance(MicrowaveVisualState.Cooking); SetAppearance(MicrowaveVisualState.Cooking);
var time = _currentCookTimerTime * _cookTimeMultiplier; var time = _currentCookTimerTime * _cookTimeMultiplier;
SoundSystem.Play(_startCookingSound.GetSound(), Filter.Pvs(Owner), Owner, AudioParams.Default); SoundSystem.Play(_startCookingSound.GetSound(), Filter.Pvs(Owner), Owner, AudioParams.Default);
@@ -289,9 +286,12 @@ namespace Content.Server.Kitchen.Components
if (recipeToCook != null) if (recipeToCook != null)
{ {
SubtractContents(recipeToCook); for (int i = 0; i < portionedRecipe.Item2; i++)
_entities.SpawnEntity(recipeToCook.Result, {
_entities.GetComponent<TransformComponent>(Owner).Coordinates); SubtractContents(recipeToCook);
_entities.SpawnEntity(recipeToCook.Result,
_entities.GetComponent<TransformComponent>(Owner).Coordinates);
}
} }
EjectSolids(); EjectSolids();
@@ -415,32 +415,42 @@ namespace Content.Server.Kitchen.Components
} }
} }
private bool CanSatisfyRecipe(FoodRecipePrototype recipe, Dictionary<string, int> solids, Dictionary<string, FixedPoint2> reagents) private (FoodRecipePrototype, int) CanSatisfyRecipe(FoodRecipePrototype recipe, Dictionary<string, int> solids, Dictionary<string, FixedPoint2> reagents)
{ {
if (_currentCookTimerTime != recipe.CookTime) int portions = 0;
if(_currentCookTimerTime % recipe.CookTime != 0)
{ {
return false; //can't be a multiple of this recipe
return (recipe, 0);
} }
foreach (var solid in recipe.IngredientsSolids) foreach (var solid in recipe.IngredientsSolids)
{ {
if (!solids.ContainsKey(solid.Key)) if (!solids.ContainsKey(solid.Key))
return false; return (recipe, 0);
if (solids[solid.Key] < solid.Value) if (solids[solid.Key] < solid.Value)
return false; return (recipe, 0);
else
portions = portions == 0 ? solids[solid.Key] / solid.Value.Int()
: Math.Min(portions, solids[solid.Key] / solid.Value.Int());
} }
foreach (var reagent in recipe.IngredientsReagents) foreach (var reagent in recipe.IngredientsReagents)
{ {
if (!reagents.ContainsKey(reagent.Key)) if (!reagents.ContainsKey(reagent.Key))
return false; return (recipe, 0);
if (reagents[reagent.Key] < reagent.Value) if (reagents[reagent.Key] < reagent.Value)
return false; return (recipe, 0);
else
portions = portions == 0 ? reagents[reagent.Key].Int() / reagent.Value.Int()
: Math.Min(portions, reagents[reagent.Key].Int() / reagent.Value.Int());
} }
return true; //cook only as many of those portions as time allows
return (recipe, (int)Math.Min(portions, _currentCookTimerTime / recipe.CookTime));
} }
public void ClickSound() public void ClickSound()