From 78adc99aceae0628839772c5bc3cb768ec74944a Mon Sep 17 00:00:00 2001 From: Nemanja <98561806+EmoGarbage404@users.noreply.github.com> Date: Mon, 19 Jun 2023 00:02:27 -0400 Subject: [PATCH] Artifact crafting fix (#17454) * Fix tag steps double counting entities * oauhg --- .../Construction/ConstructionSystem.Initial.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Content.Server/Construction/ConstructionSystem.Initial.cs b/Content.Server/Construction/ConstructionSystem.Initial.cs index 7bb5422945..9c50b3d9a4 100644 --- a/Content.Server/Construction/ConstructionSystem.Initial.cs +++ b/Content.Server/Construction/ConstructionSystem.Initial.cs @@ -107,8 +107,8 @@ namespace Content.Server.Construction // But I'd rather do this shit than risk having collisions with other containers. Container GetContainer(string name) { - if (containers.ContainsKey(name)) - return containers[name]; + if (containers.TryGetValue(name, out var container1)) + return container1; while (true) { @@ -154,6 +154,7 @@ namespace Content.Server.Construction var failed = false; var steps = new List(); + var used = new HashSet(); foreach (var step in edge.Steps) { @@ -169,6 +170,9 @@ namespace Content.Server.Construction if (!materialStep.EntityValid(entity, out var stack)) continue; + if (used.Contains(entity)) + continue; + // TODO allow taking from several stacks. // Also update crafting steps to check if it works. var splitStack = _stackSystem.Split(entity, materialStep.Amount, user.ToCoordinates(0, 0), stack); @@ -182,7 +186,7 @@ namespace Content.Server.Construction continue; } else if (!GetContainer(materialStep.Store).Insert(splitStack.Value)) - continue; + continue; handled = true; break; @@ -191,11 +195,14 @@ namespace Content.Server.Construction break; case ArbitraryInsertConstructionGraphStep arbitraryStep: - foreach (var entity in EnumerateNearby(user)) + foreach (var entity in new HashSet(EnumerateNearby(user))) { if (!arbitraryStep.EntityValid(entity, EntityManager, _factory)) continue; + if (used.Contains(entity)) + continue; + if (string.IsNullOrEmpty(arbitraryStep.Store)) { if (!container.Insert(entity)) @@ -205,6 +212,7 @@ namespace Content.Server.Construction continue; handled = true; + used.Add(entity); break; }