From 0c6081fe1089522cc1a6b0f5d32c2bef6cfc2e34 Mon Sep 17 00:00:00 2001 From: slarticodefast <161409025+slarticodefast@users.noreply.github.com> Date: Thu, 27 Feb 2025 13:39:06 +0100 Subject: [PATCH] Fix egg cooking and make microwave code a little less bad (#35459) --- .../Components/ActivelyMicrowavedComponent.cs | 7 +- .../Kitchen/EntitySystems/MicrowaveSystem.cs | 98 ++++++++++--------- .../Entities/Objects/Consumable/Food/egg.yml | 12 +-- .../Recipes/Construction/Graphs/food/egg.yml | 11 +-- .../Recipes/Cooking/meal_recipes.yml | 5 +- 5 files changed, 66 insertions(+), 67 deletions(-) diff --git a/Content.Server/Kitchen/Components/ActivelyMicrowavedComponent.cs b/Content.Server/Kitchen/Components/ActivelyMicrowavedComponent.cs index 54a7edd745..c7fca5a47e 100644 --- a/Content.Server/Kitchen/Components/ActivelyMicrowavedComponent.cs +++ b/Content.Server/Kitchen/Components/ActivelyMicrowavedComponent.cs @@ -1,5 +1,3 @@ -using Content.Shared.Kitchen; - namespace Content.Server.Kitchen.Components; /// @@ -8,4 +6,9 @@ namespace Content.Server.Kitchen.Components; [RegisterComponent] public sealed partial class ActivelyMicrowavedComponent : Component { + /// + /// The microwave this entity is actively being microwaved by. + /// + [DataField] + public EntityUid? Microwave; } diff --git a/Content.Server/Kitchen/EntitySystems/MicrowaveSystem.cs b/Content.Server/Kitchen/EntitySystems/MicrowaveSystem.cs index 1ac02ac882..7f0778cbdd 100644 --- a/Content.Server/Kitchen/EntitySystems/MicrowaveSystem.cs +++ b/Content.Server/Kitchen/EntitySystems/MicrowaveSystem.cs @@ -14,6 +14,7 @@ using Content.Shared.Body.Components; using Content.Shared.Body.Part; using Content.Shared.Chemistry.Components.SolutionManager; using Content.Shared.Chemistry.EntitySystems; +using Content.Shared.Chemistry.Reaction; using Content.Shared.Construction.EntitySystems; using Content.Shared.Database; using Content.Shared.Destructible; @@ -101,6 +102,7 @@ namespace Content.Server.Kitchen.EntitySystems SubscribeLocalEvent(OnActiveMicrowaveRemove); SubscribeLocalEvent(OnConstructionTemp); + SubscribeLocalEvent>(OnReactionAttempt); SubscribeLocalEvent(OnGetSecretRecipes); } @@ -126,7 +128,8 @@ namespace Content.Server.Kitchen.EntitySystems private void OnActiveMicrowaveInsert(Entity ent, ref EntInsertedIntoContainerMessage args) { - AddComp(args.Entity); + var microwavedComp = AddComp(args.Entity); + microwavedComp.Microwave = ent.Owner; } private void OnActiveMicrowaveRemove(Entity ent, ref EntRemovedFromContainerMessage args) @@ -134,10 +137,33 @@ namespace Content.Server.Kitchen.EntitySystems EntityManager.RemoveComponentDeferred(args.Entity); } + // Stop items from transforming through constructiongraphs while being microwaved. + // They might be reserved for a microwave recipe. private void OnConstructionTemp(Entity ent, ref OnConstructionTemperatureEvent args) { args.Result = HandleResult.False; - return; + } + + // Stop reagents from reacting if they are currently reserved for a microwave recipe. + // For example Egg would cook into EggCooked, causing it to not being removed once we are done microwaving. + private void OnReactionAttempt(Entity ent, ref SolutionRelayEvent args) + { + if (!TryComp(ent.Comp.Microwave, out var activeMicrowaveComp)) + return; + + if (activeMicrowaveComp.PortionedRecipe.Item1 == null) // no recipe selected + return; + + var recipeReagents = activeMicrowaveComp.PortionedRecipe.Item1.IngredientsReagents.Keys; + + foreach (var reagent in recipeReagents) + { + if (args.Event.Reaction.Reactants.ContainsKey(reagent)) + { + args.Event.Cancelled = true; + return; + } + } } /// @@ -176,33 +202,29 @@ namespace Content.Server.Kitchen.EntitySystems // this is spaghetti ngl foreach (var item in component.Storage.ContainedEntities) { - if (!TryComp(item, out var solMan)) + // use the same reagents as when we selected the recipe + if (!_solutionContainer.TryGetDrainableSolution(item, out var solutionEntity, out var solution)) continue; - // go over every solution - foreach (var (_, soln) in _solutionContainer.EnumerateSolutions((item, solMan))) + foreach (var (reagent, _) in recipe.IngredientsReagents) { - var solution = soln.Comp.Solution; - foreach (var (reagent, _) in recipe.IngredientsReagents) - { - // removed everything - if (!totalReagentsToRemove.ContainsKey(reagent)) - continue; + // removed everything + if (!totalReagentsToRemove.ContainsKey(reagent)) + continue; - var quant = solution.GetTotalPrototypeQuantity(reagent); + var quant = solution.GetTotalPrototypeQuantity(reagent); - if (quant >= totalReagentsToRemove[reagent]) - { - quant = totalReagentsToRemove[reagent]; - totalReagentsToRemove.Remove(reagent); - } - else - { - totalReagentsToRemove[reagent] -= quant; - } - - _solutionContainer.RemoveReagent(soln, reagent, quant); + if (quant >= totalReagentsToRemove[reagent]) + { + quant = totalReagentsToRemove[reagent]; + totalReagentsToRemove.Remove(reagent); + } + else + { + totalReagentsToRemove[reagent] -= quant; } + + _solutionContainer.RemoveReagent(solutionEntity.Value, reagent, quant); } } @@ -541,7 +563,8 @@ namespace Content.Server.Kitchen.EntitySystems continue; } - AddComp(item); + var microwavedComp = AddComp(item); + microwavedComp.Microwave = uid; string? solidID = null; int amountToAdd = 1; @@ -560,33 +583,20 @@ namespace Content.Server.Kitchen.EntitySystems } if (solidID is null) - { continue; - } - - if (solidsDict.ContainsKey(solidID)) - { + if (!solidsDict.TryAdd(solidID, amountToAdd)) solidsDict[solidID] += amountToAdd; - } - else - { - solidsDict.Add(solidID, amountToAdd); - } - if (!TryComp(item, out var solMan)) + // only use reagents we have access to + // you have to break the eggs before we can use them! + if (!_solutionContainer.TryGetDrainableSolution(item, out var _, out var solution)) continue; - foreach (var (_, soln) in _solutionContainer.EnumerateSolutions((item, solMan))) + foreach (var (reagent, quantity) in solution.Contents) { - var solution = soln.Comp.Solution; - foreach (var (reagent, quantity) in solution.Contents) - { - if (reagentDict.ContainsKey(reagent.Prototype)) - reagentDict[reagent.Prototype] += quantity; - else - reagentDict.Add(reagent.Prototype, quantity); - } + if (!reagentDict.TryAdd(reagent.Prototype, quantity)) + reagentDict[reagent.Prototype] += quantity; } } diff --git a/Resources/Prototypes/Entities/Objects/Consumable/Food/egg.yml b/Resources/Prototypes/Entities/Objects/Consumable/Food/egg.yml index a4593d5006..7228a21366 100644 --- a/Resources/Prototypes/Entities/Objects/Consumable/Food/egg.yml +++ b/Resources/Prototypes/Entities/Objects/Consumable/Food/egg.yml @@ -11,7 +11,7 @@ - Egg - Meat - type: Food - trash: + trash: - Eggshells - type: Sprite sprite: Objects/Consumable/Food/egg.rsi @@ -61,13 +61,6 @@ # all below are for egg cooking/exploding - type: AtmosExposed - type: Temperature - currentTemperature: 290 - - type: InternalTemperature - # ~1mm shell and ~1cm of albumen - thickness: 0.011 - area: 0.04 - # conductivity of egg shell based on a paper from Romanoff and Romanoff (1949) - conductivity: 0.456 # Splat - type: entity @@ -135,6 +128,3 @@ - type: Temperature # preserve temperature from the boiling step currentTemperature: 344 - - type: Construction - graph: Egg - node: boiled diff --git a/Resources/Prototypes/Recipes/Construction/Graphs/food/egg.yml b/Resources/Prototypes/Recipes/Construction/Graphs/food/egg.yml index 3c3bca2585..71a4a65021 100644 --- a/Resources/Prototypes/Recipes/Construction/Graphs/food/egg.yml +++ b/Resources/Prototypes/Recipes/Construction/Graphs/food/egg.yml @@ -4,12 +4,6 @@ start: start graph: - node: start - edges: - - to: boiled - steps: - - minTemperature: 344 - - node: boiled - entity: FoodEggBoiled edges: - to: explode completed: @@ -18,6 +12,7 @@ types: Blunt: 10 steps: - # egg explodes some time after the water in it boils and increases pressure, guessing ~110C - - minTemperature: 383 + # egg explodes some time after the water in it boils and increases pressure + # high enough so you can still microwave them for 5 seconds safely + - minTemperature: 473.15 # 200°C - node: explode diff --git a/Resources/Prototypes/Recipes/Cooking/meal_recipes.yml b/Resources/Prototypes/Recipes/Cooking/meal_recipes.yml index c3a5012ac0..f8970a5119 100644 --- a/Resources/Prototypes/Recipes/Cooking/meal_recipes.yml +++ b/Resources/Prototypes/Recipes/Cooking/meal_recipes.yml @@ -262,10 +262,11 @@ result: FoodBurgerMcguffin time: 10 group: Savory + reagents: + Egg: 12 solids: FoodBreadBun: 1 FoodCheeseSlice: 1 - FoodEgg: 2 - type: microwaveMealRecipe id: RecipeBurgerMcrib @@ -348,12 +349,12 @@ group: Savory reagents: TableSalt: 5 + Egg: 12 solids: FoodBreadBun: 1 FoodMeat: 2 FoodCheeseSlice: 2 FoodTomato: 2 - FoodEgg: 2 - type: microwaveMealRecipe id: RecipeTofuBurger -- 2.51.2