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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 4 deletions

View File

@ -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<ConstructionGraphStep>();
var used = new HashSet<EntityUid>();
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<EntityUid>(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;
}