From b76c25182907412f4bcda72e426a6690b2b85efe Mon Sep 17 00:00:00 2001 From: themias <89101928+themias@users.noreply.github.com> Date: Thu, 14 Jul 2022 22:25:16 -0400 Subject: [PATCH] Add batch cooking (#9359) --- .../Kitchen/Components/MicrowaveComponent.cs | 46 +++++++++++-------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/Content.Server/Kitchen/Components/MicrowaveComponent.cs b/Content.Server/Kitchen/Components/MicrowaveComponent.cs index e7cb4fc128..929dcdf100 100644 --- a/Content.Server/Kitchen/Components/MicrowaveComponent.cs +++ b/Content.Server/Kitchen/Components/MicrowaveComponent.cs @@ -268,13 +268,10 @@ namespace Content.Server.Kitchen.Components } // Check recipes - FoodRecipePrototype? recipeToCook = null; - foreach (var r in _recipeManager.Recipes.Where(r => - CanSatisfyRecipe(r, solidsDict, reagentDict))) - { - recipeToCook = r; - } - + (FoodRecipePrototype, int) portionedRecipe = _recipeManager.Recipes.Select( + r => CanSatisfyRecipe(r, solidsDict, reagentDict)).Where(r => r.Item2 > 0).FirstOrDefault(); + FoodRecipePrototype? recipeToCook = portionedRecipe.Item1; + SetAppearance(MicrowaveVisualState.Cooking); var time = _currentCookTimerTime * _cookTimeMultiplier; SoundSystem.Play(_startCookingSound.GetSound(), Filter.Pvs(Owner), Owner, AudioParams.Default); @@ -289,9 +286,12 @@ namespace Content.Server.Kitchen.Components if (recipeToCook != null) { - SubtractContents(recipeToCook); - _entities.SpawnEntity(recipeToCook.Result, - _entities.GetComponent(Owner).Coordinates); + for (int i = 0; i < portionedRecipe.Item2; i++) + { + SubtractContents(recipeToCook); + _entities.SpawnEntity(recipeToCook.Result, + _entities.GetComponent(Owner).Coordinates); + } } EjectSolids(); @@ -415,32 +415,42 @@ namespace Content.Server.Kitchen.Components } } - private bool CanSatisfyRecipe(FoodRecipePrototype recipe, Dictionary solids, Dictionary reagents) + private (FoodRecipePrototype, int) CanSatisfyRecipe(FoodRecipePrototype recipe, Dictionary solids, Dictionary 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) { if (!solids.ContainsKey(solid.Key)) - return false; + return (recipe, 0); 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) { if (!reagents.ContainsKey(reagent.Key)) - return false; + return (recipe, 0); 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()