Microwave recipes now uses stacktype id instead of entity prototype id for stacked entities (#28225)

This commit is contained in:
blueDev2
2024-06-04 13:12:01 -04:00
committed by GitHub
parent 627187988e
commit 0e93d13cb7
2 changed files with 58 additions and 12 deletions

View File

@@ -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<EntityPrototype>]
private const string MalfunctionSpark = "Spark";
@@ -198,17 +201,42 @@ namespace Content.Server.Kitchen.EntitySystems
for (var i = 0; i < recipeSolid.Value; i++)
{
foreach (var item in component.Storage.ContainedEntities)
{
string? itemID = null;
// If an entity has a stack component, use the stacktype instead of prototype id
if (TryComp<StackComponent>(item, out var stackComp))
{
itemID = _prototype.Index<StackPrototype>(stackComp.StackTypeId).Spawn;
}
else
{
var metaData = MetaData(item);
if (metaData.EntityPrototype == null)
{
continue;
}
itemID = metaData.EntityPrototype.ID;
}
if (metaData.EntityPrototype.ID == recipeSolid.Key)
if (itemID != recipeSolid.Key)
{
continue;
}
if (stackComp is not null)
{
if (stackComp.Count == 1)
{
_container.Remove(item, component.Storage);
EntityManager.DeleteEntity(item);
}
_stack.Use(item, 1, stackComp);
break;
}
else
{
_container.Remove(item, component.Storage);
Del(item);
break;
}
}
@@ -448,17 +476,35 @@ namespace Content.Server.Kitchen.EntitySystems
AddComp<ActivelyMicrowavedComponent>(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<StackComponent>(item, out var stackComp))
{
solidsDict[metaData.EntityPrototype.ID]++;
solidID = _prototype.Index<StackPrototype>(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<SolutionContainerManagerComponent>(item, out var solMan))

View File

@@ -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