Artifact crafting fix (#17454)

* Fix tag steps double counting entities

* oauhg
This commit is contained in:
Nemanja
2023-06-19 00:02:27 -04:00
committed by GitHub
parent 1026bb17af
commit 78adc99ace

View File

@@ -107,8 +107,8 @@ namespace Content.Server.Construction
// But I'd rather do this shit than risk having collisions with other containers. // But I'd rather do this shit than risk having collisions with other containers.
Container GetContainer(string name) Container GetContainer(string name)
{ {
if (containers.ContainsKey(name)) if (containers.TryGetValue(name, out var container1))
return containers[name]; return container1;
while (true) while (true)
{ {
@@ -154,6 +154,7 @@ namespace Content.Server.Construction
var failed = false; var failed = false;
var steps = new List<ConstructionGraphStep>(); var steps = new List<ConstructionGraphStep>();
var used = new HashSet<EntityUid>();
foreach (var step in edge.Steps) foreach (var step in edge.Steps)
{ {
@@ -169,6 +170,9 @@ namespace Content.Server.Construction
if (!materialStep.EntityValid(entity, out var stack)) if (!materialStep.EntityValid(entity, out var stack))
continue; continue;
if (used.Contains(entity))
continue;
// TODO allow taking from several stacks. // TODO allow taking from several stacks.
// Also update crafting steps to check if it works. // Also update crafting steps to check if it works.
var splitStack = _stackSystem.Split(entity, materialStep.Amount, user.ToCoordinates(0, 0), stack); var splitStack = _stackSystem.Split(entity, materialStep.Amount, user.ToCoordinates(0, 0), stack);
@@ -182,7 +186,7 @@ namespace Content.Server.Construction
continue; continue;
} }
else if (!GetContainer(materialStep.Store).Insert(splitStack.Value)) else if (!GetContainer(materialStep.Store).Insert(splitStack.Value))
continue; continue;
handled = true; handled = true;
break; break;
@@ -191,11 +195,14 @@ namespace Content.Server.Construction
break; break;
case ArbitraryInsertConstructionGraphStep arbitraryStep: case ArbitraryInsertConstructionGraphStep arbitraryStep:
foreach (var entity in EnumerateNearby(user)) foreach (var entity in new HashSet<EntityUid>(EnumerateNearby(user)))
{ {
if (!arbitraryStep.EntityValid(entity, EntityManager, _factory)) if (!arbitraryStep.EntityValid(entity, EntityManager, _factory))
continue; continue;
if (used.Contains(entity))
continue;
if (string.IsNullOrEmpty(arbitraryStep.Store)) if (string.IsNullOrEmpty(arbitraryStep.Store))
{ {
if (!container.Insert(entity)) if (!container.Insert(entity))
@@ -205,6 +212,7 @@ namespace Content.Server.Construction
continue; continue;
handled = true; handled = true;
used.Add(entity);
break; break;
} }