From 0e93d13cb78b86136d11daeec06464ef26ccff65 Mon Sep 17 00:00:00 2001 From: blueDev2 <89804215+blueDev2@users.noreply.github.com> Date: Tue, 4 Jun 2024 13:12:01 -0400 Subject: [PATCH] Microwave recipes now uses stacktype id instead of entity prototype id for stacked entities (#28225) --- .../Kitchen/EntitySystems/MicrowaveSystem.cs | 66 ++++++++++++++++--- .../Recipes/Cooking/medical_recipes.yml | 4 +- 2 files changed, 58 insertions(+), 12 deletions(-) diff --git a/Content.Server/Kitchen/EntitySystems/MicrowaveSystem.cs b/Content.Server/Kitchen/EntitySystems/MicrowaveSystem.cs index 8938aa8b1d..c69ed49d50 100644 --- a/Content.Server/Kitchen/EntitySystems/MicrowaveSystem.cs +++ b/Content.Server/Kitchen/EntitySystems/MicrowaveSystem.cs @@ -35,6 +35,7 @@ using Robust.Shared.Player; using System.Linq; using Robust.Shared.Prototypes; using Robust.Shared.Timing; +using Content.Shared.Stacks; namespace Content.Server.Kitchen.EntitySystems { @@ -58,6 +59,8 @@ namespace Content.Server.Kitchen.EntitySystems [Dependency] private readonly UserInterfaceSystem _userInterface = default!; [Dependency] private readonly HandsSystem _handsSystem = default!; [Dependency] private readonly SharedItemSystem _item = default!; + [Dependency] private readonly SharedStackSystem _stack = default!; + [Dependency] private readonly IPrototypeManager _prototype = default!; [ValidatePrototypeId] private const string MalfunctionSpark = "Spark"; @@ -199,16 +202,41 @@ namespace Content.Server.Kitchen.EntitySystems { foreach (var item in component.Storage.ContainedEntities) { - var metaData = MetaData(item); - if (metaData.EntityPrototype == null) + string? itemID = null; + + // If an entity has a stack component, use the stacktype instead of prototype id + if (TryComp(item, out var stackComp)) + { + itemID = _prototype.Index(stackComp.StackTypeId).Spawn; + } + else + { + var metaData = MetaData(item); + if (metaData.EntityPrototype == null) + { + continue; + } + itemID = metaData.EntityPrototype.ID; + } + + if (itemID != recipeSolid.Key) { continue; } - if (metaData.EntityPrototype.ID == recipeSolid.Key) + if (stackComp is not null) + { + if (stackComp.Count == 1) + { + _container.Remove(item, component.Storage); + } + _stack.Use(item, 1, stackComp); + break; + } + else { _container.Remove(item, component.Storage); - EntityManager.DeleteEntity(item); + Del(item); break; } } @@ -448,17 +476,35 @@ namespace Content.Server.Kitchen.EntitySystems AddComp(item); - var metaData = MetaData(item); //this simply begs for cooking refactor - if (metaData.EntityPrototype == null) - continue; + string? solidID = null; + int amountToAdd = 1; - if (solidsDict.ContainsKey(metaData.EntityPrototype.ID)) + // If a microwave recipe uses a stacked item, use the default stack prototype id instead of prototype id + if (TryComp(item, out var stackComp)) { - solidsDict[metaData.EntityPrototype.ID]++; + solidID = _prototype.Index(stackComp.StackTypeId).Spawn; + amountToAdd = stackComp.Count; } else { - solidsDict.Add(metaData.EntityPrototype.ID, 1); + var metaData = MetaData(item); //this simply begs for cooking refactor + if (metaData.EntityPrototype is not null) + solidID = metaData.EntityPrototype.ID; + } + + if (solidID is null) + { + continue; + } + + + if (solidsDict.ContainsKey(solidID)) + { + solidsDict[solidID] += amountToAdd; + } + else + { + solidsDict.Add(solidID, amountToAdd); } if (!TryComp(item, out var solMan)) diff --git a/Resources/Prototypes/Recipes/Cooking/medical_recipes.yml b/Resources/Prototypes/Recipes/Cooking/medical_recipes.yml index 9d1947f03e..3bc9e22b0e 100644 --- a/Resources/Prototypes/Recipes/Cooking/medical_recipes.yml +++ b/Resources/Prototypes/Recipes/Cooking/medical_recipes.yml @@ -13,7 +13,7 @@ time: 10 solids: FoodPoppy: 1 - Brutepack: 1 + Brutepack: 10 MaterialCloth1: 1 reagents: TranexamicAcid: 20 @@ -26,7 +26,7 @@ time: 10 solids: FoodAloe: 1 - Ointment: 1 + Ointment: 10 MaterialCloth1: 1 reagents: Sigynate: 20