diff --git a/Content.Server/GameObjects/Components/Kitchen/MicrowaveComponent.cs b/Content.Server/GameObjects/Components/Kitchen/MicrowaveComponent.cs index d5402489ec..1c22da42b9 100644 --- a/Content.Server/GameObjects/Components/Kitchen/MicrowaveComponent.cs +++ b/Content.Server/GameObjects/Components/Kitchen/MicrowaveComponent.cs @@ -278,9 +278,21 @@ namespace Content.Server.GameObjects.Components.Kitchen } } + var failState = MicrowaveSuccessState.RecipeFail; + foreach(var id in solidsDict.Keys) + { + if(_recipeManager.SolidAppears(id)) + { + continue; + } + + failState = MicrowaveSuccessState.UnwantedForeignObject; + break; + } + // Check recipes FoodRecipePrototype recipeToCook = null; - foreach (var r in _recipeManager.Recipes.Where(r => CanSatisfyRecipe(r, solidsDict))) + foreach (var r in _recipeManager.Recipes.Where(r => CanSatisfyRecipe(r, solidsDict) == MicrowaveSuccessState.RecipePass)) { recipeToCook = r; } @@ -288,7 +300,6 @@ namespace Content.Server.GameObjects.Components.Kitchen var goodMeal = (recipeToCook != null) && (_currentCookTimerTime == (uint)recipeToCook.CookTime); - SetAppearance(MicrowaveVisualState.Cooking); _audioSystem.Play(_startCookingSound, Owner, AudioParams.Default); Timer.Spawn((int)(_currentCookTimerTime * _cookTimeMultiplier), () => @@ -297,21 +308,31 @@ namespace Content.Server.GameObjects.Components.Kitchen { return; } - if (goodMeal) + + if(failState == MicrowaveSuccessState.UnwantedForeignObject) { - SubtractContents(recipeToCook); + VaporizeReagents(); + EjectSolids(); } else { - VaporizeReagents(); - VaporizeSolids(); + if (goodMeal) + { + SubtractContents(recipeToCook); + } + else + { + VaporizeReagents(); + VaporizeSolids(); + } + + if (recipeToCook != null) + { + var entityToSpawn = goodMeal ? recipeToCook.Result : _badRecipeName; + _entityManager.SpawnEntity(entityToSpawn, Owner.Transform.GridPosition); + } } - if (recipeToCook != null) - { - var entityToSpawn = goodMeal ? recipeToCook.Result : _badRecipeName; - _entityManager.SpawnEntity(entityToSpawn, Owner.Transform.GridPosition); - } _audioSystem.Play(_cookingCompleteSound, Owner, AudioParams.Default.WithVolume(-1f)); SetAppearance(MicrowaveVisualState.Idle); _busy = false; @@ -385,18 +406,18 @@ namespace Content.Server.GameObjects.Components.Kitchen } - private bool CanSatisfyRecipe(FoodRecipePrototype recipe, Dictionary solids) + private MicrowaveSuccessState CanSatisfyRecipe(FoodRecipePrototype recipe, Dictionary solids) { foreach (var reagent in recipe.IngredientsReagents) { if (!_solution.ContainsReagent(reagent.Key, out var amount)) { - return false; + return MicrowaveSuccessState.RecipeFail; } if (amount.Int() < reagent.Value) { - return false; + return MicrowaveSuccessState.RecipeFail; } } @@ -404,16 +425,17 @@ namespace Content.Server.GameObjects.Components.Kitchen { if (!solids.ContainsKey(solid.Key)) { - return false; + return MicrowaveSuccessState.RecipeFail; } if (solids[solid.Key] < solid.Value) { - return false; + return MicrowaveSuccessState.RecipeFail; } } - return true; + + return MicrowaveSuccessState.RecipePass; } private void ClickSound() diff --git a/Content.Server/GameObjects/Components/Kitchen/MicrowaveSuccessState.cs b/Content.Server/GameObjects/Components/Kitchen/MicrowaveSuccessState.cs new file mode 100644 index 0000000000..48c33a5409 --- /dev/null +++ b/Content.Server/GameObjects/Components/Kitchen/MicrowaveSuccessState.cs @@ -0,0 +1,10 @@ +namespace Content.Server.GameObjects.Components.Kitchen +{ + public enum MicrowaveSuccessState + { + RecipePass, + RecipeFail, + UnwantedForeignObject + + } +} diff --git a/Content.Shared/Kitchen/RecipeManager.cs b/Content.Shared/Kitchen/RecipeManager.cs index 5ac01ad64f..c731d8994f 100644 --- a/Content.Shared/Kitchen/RecipeManager.cs +++ b/Content.Shared/Kitchen/RecipeManager.cs @@ -6,7 +6,7 @@ using Robust.Shared.Prototypes; namespace Content.Shared.Kitchen { - + public class RecipeManager { #pragma warning disable 649 @@ -24,6 +24,24 @@ namespace Content.Shared.Kitchen Recipes.Sort(new RecipeComparer()); } + /// + /// Check if a prototype ids appears in any of the recipes that exist. + /// + /// + /// + public bool SolidAppears(string solidId) + { + foreach(var recipe in Recipes) + { + if(recipe.IngredientsSolids.ContainsKey(solidId)) + { + return true; + } + } + + return false; + } + private class RecipeComparer : Comparer { public override int Compare(FoodRecipePrototype x, FoodRecipePrototype y) @@ -32,7 +50,7 @@ namespace Content.Shared.Kitchen { return 0; } - + return -x.IngredientsReagents.Count.CompareTo(y.IngredientsReagents.Count); } }