Skip to content

Commit

Permalink
Fix internals not auto-activating for entities spawned in space (spac…
Browse files Browse the repository at this point in the history
…e-wizards#29213)

* Add organs before trying to breathe

* Add tests for auto-internals

* EntMan to the rescue
  • Loading branch information
Tayrtahn authored and aspiringLich committed Jul 21, 2024
1 parent 2250693 commit c410b3e
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 1 deletion.
89 changes: 89 additions & 0 deletions Content.IntegrationTests/Tests/Internals/AutoInternalsTests.cs
Original file line number Diff line number Diff line change
@@ -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]
";
}
4 changes: 3 additions & 1 deletion Content.Shared/Clothing/LoadoutSystem.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -27,7 +28,8 @@ public override void Initialize()
{
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)
Expand Down

0 comments on commit c410b3e

Please sign in to comment.