]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix internals not auto-activating for entities spawned in space (#29213)
authorTayrtahn <tayrtahn@gmail.com>
Tue, 25 Jun 2024 06:28:48 +0000 (02:28 -0400)
committerGitHub <noreply@github.com>
Tue, 25 Jun 2024 06:28:48 +0000 (16:28 +1000)
* Add organs before trying to breathe

* Add tests for auto-internals

* EntMan to the rescue

Content.IntegrationTests/Tests/Internals/AutoInternalsTests.cs [new file with mode: 0644]
Content.Shared/Clothing/LoadoutSystem.cs

diff --git a/Content.IntegrationTests/Tests/Internals/AutoInternalsTests.cs b/Content.IntegrationTests/Tests/Internals/AutoInternalsTests.cs
new file mode 100644 (file)
index 0000000..dbd612c
--- /dev/null
@@ -0,0 +1,89 @@
+using Content.Server.Atmos.EntitySystems;
+using Content.Server.Body.Systems;
+using Content.Server.Station.Systems;
+using Content.Shared.Preferences;
+using Content.Shared.Roles.Jobs;
+
+namespace Content.IntegrationTests.Tests.Internals;
+
+[TestFixture]
+[TestOf(typeof(InternalsSystem))]
+public sealed class AutoInternalsTests
+{
+    [Test]
+    public async Task TestInternalsAutoActivateInSpaceForStationSpawn()
+    {
+        await using var pair = await PoolManager.GetServerClient();
+        var server = pair.Server;
+
+        var testMap = await pair.CreateTestMap();
+
+        var stationSpawning = server.System<StationSpawningSystem>();
+        var atmos = server.System<AtmosphereSystem>();
+        var internals = server.System<InternalsSystem>();
+
+        await server.WaitAssertion(() =>
+        {
+            var profile = new HumanoidCharacterProfile();
+            var dummy = stationSpawning.SpawnPlayerMob(testMap.GridCoords, new JobComponent()
+            {
+                Prototype = "TestInternalsDummy"
+            }, profile, station: null);
+
+            Assert.That(atmos.HasAtmosphere(testMap.Grid), Is.False, "Test map has atmosphere - test needs adjustment!");
+            Assert.That(internals.AreInternalsWorking(dummy), "Internals did not automatically connect!");
+
+            server.EntMan.DeleteEntity(dummy);
+        });
+
+        await pair.CleanReturnAsync();
+    }
+
+    [Test]
+    public async Task TestInternalsAutoActivateInSpaceForEntitySpawn()
+    {
+        await using var pair = await PoolManager.GetServerClient();
+        var server = pair.Server;
+
+        var testMap = await pair.CreateTestMap();
+
+        var atmos = server.System<AtmosphereSystem>();
+        var internals = server.System<InternalsSystem>();
+
+        await server.WaitAssertion(() =>
+        {
+            var dummy = server.EntMan.Spawn("TestInternalsDummyEntity", testMap.MapCoords);
+
+            Assert.That(atmos.HasAtmosphere(testMap.Grid), Is.False, "Test map has atmosphere - test needs adjustment!");
+            Assert.That(internals.AreInternalsWorking(dummy), "Internals did not automatically connect!");
+
+            server.EntMan.DeleteEntity(dummy);
+        });
+
+        await pair.CleanReturnAsync();
+    }
+
+    [TestPrototypes]
+    private const string Prototypes = @"
+- type: playTimeTracker
+  id: PlayTimeInternalsDummy
+
+- type: startingGear
+  id: InternalsDummyGear
+  equipment:
+    mask: ClothingMaskBreath
+    suitstorage: OxygenTankFilled
+
+- type: job
+  id: TestInternalsDummy
+  playTimeTracker: PlayTimeInternalsDummy
+  startingGear: InternalsDummyGear
+
+- type: entity
+  id: TestInternalsDummyEntity
+  parent: MobHuman
+  components:
+    - type: Loadout
+      prototypes: [InternalsDummyGear]
+";
+}
index f1b1dc36d907200442ecd2abd97bda9bee140260..1bab86e90fdf4753aac8a534b1da059c06a5d35d 100644 (file)
@@ -1,4 +1,5 @@
 using System.Linq;
+using Content.Shared.Body.Systems;
 using Content.Shared.Clothing.Components;
 using Content.Shared.Humanoid;
 using Content.Shared.Preferences;
@@ -27,7 +28,8 @@ public sealed class LoadoutSystem : EntitySystem
     {
         base.Initialize();
 
-        SubscribeLocalEvent<LoadoutComponent, MapInitEvent>(OnMapInit);
+        // Wait until the character has all their organs before we give them their loadout
+        SubscribeLocalEvent<LoadoutComponent, MapInitEvent>(OnMapInit, after: [typeof(SharedBodySystem)]);
     }
 
     public static string GetJobPrototype(string? loadout)