Fix NPC prototype reloads (#13981)

This commit is contained in:
metalgearsloth
2023-02-08 08:27:34 +11:00
committed by GitHub
parent bfedfd0abb
commit 6b6c6b1c9f
4 changed files with 39 additions and 15 deletions

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Threading.Tasks;
using Content.Server.NPC.HTN;
using NUnit.Framework;
using Robust.Shared.GameObjects;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
@@ -19,6 +20,7 @@ public sealed class NPCTest
await server.WaitIdleAsync();
var htnSystem = server.ResolveDependency<IEntitySystemManager>().GetEntitySystem<HTNSystem>();
var protoManager = server.ResolveDependency<IPrototypeManager>();
await server.WaitAssertion(() =>
@@ -27,7 +29,7 @@ public sealed class NPCTest
foreach (var compound in protoManager.EnumeratePrototypes<HTNCompoundTask>())
{
Count(compound, counts);
Count(compound, counts, htnSystem);
counts.Clear();
}
});
@@ -35,11 +37,13 @@ public sealed class NPCTest
await pool.CleanReturnAsync();
}
private static void Count(HTNCompoundTask compound, Dictionary<string, int> counts)
private static void Count(HTNCompoundTask compound, Dictionary<string, int> counts, HTNSystem htnSystem)
{
foreach (var branch in compound.Branches)
var compoundBranches = htnSystem.CompoundBranches[compound];
for (var i = 0; i < compound.Branches.Count; i++)
{
foreach (var task in branch.Tasks)
foreach (var task in compoundBranches[i])
{
if (task is HTNCompoundTask compoundTask)
{
@@ -48,7 +52,7 @@ public sealed class NPCTest
Assert.That(count, Is.LessThan(50));
counts[compound.ID] = count;
Count(compoundTask, counts);
Count(compoundTask, counts, htnSystem);
}
}
}