Files
space-station-14/Content.IntegrationTests/Tests/Fluids/FluidSpillTest.cs
T
Moony d42adbf05d Gametest Part 2: Preliminary refactor every test to use GameTest as the framework. (#43207)
* Pass 1.

* i'm FREE

* Prevent hangups.

* okay fine here's an attribute for settings, will polish later and prolly remove the overridable thing.

* sigh.

* fix singular trigger bug so LatheTest doesn't flake.

* Remove SystemAttribute usage.

* Poke

* I used the shotgun. You know why? Cause the shot gun doesn’t miss, and unlike the shitty hybrid taser it stops a criminal in their tracks in two hits. Bang, bang, and they’re fucking done. I use four shots just to make damn sure. Because, once again, I’m not there to coddle a buncha criminal scum sucking f------, I’m there to 1) Survive the fucking round. 2) Guard the armory. So you can absolutely get fucked. If I get unbanned, which I won’t, you can guarantee I will continue to use the shotgun to apprehend criminals. Because it’s quick, clean and effective as fuck. Why in the seven hells would I fuck around with the disabler shots, which take half a clip just to bring someone down, or with the tazer bolts which are slow as balls, impossible to aim and do about next to jack shit, fuck all. The shotgun is the superior law enforcement weapon. Because it stops crime. And it stops crime by reducing the number of criminals roaming the fucking halls.

* Change the faulty store test into two tests, one of which is ignored for failing.
2026-04-01 16:06:26 +00:00

116 lines
4.2 KiB
C#

#nullable enable
using Content.IntegrationTests.Fixtures;
using Content.Server.Fluids.EntitySystems;
using Content.Server.Spreader;
using Content.Shared.Chemistry.Components;
using Content.Shared.FixedPoint;
using Content.Shared.Fluids.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Maths;
using Robust.Shared.Timing;
namespace Content.IntegrationTests.Tests.Fluids;
[TestFixture]
[TestOf(typeof(SpreaderSystem))]
public sealed class FluidSpill : GameTest
{
private static PuddleComponent? GetPuddle(IEntityManager entityManager, Entity<MapGridComponent> mapGrid, Vector2i pos)
{
return GetPuddleEntity(entityManager, mapGrid, pos)?.Comp;
}
private static Entity<PuddleComponent>? GetPuddleEntity(IEntityManager entityManager, Entity<MapGridComponent> mapGrid, Vector2i pos)
{
var mapSys = entityManager.System<SharedMapSystem>();
foreach (var uid in mapSys.GetAnchoredEntities(mapGrid, mapGrid.Comp, pos))
{
if (entityManager.TryGetComponent(uid, out PuddleComponent? puddleComponent))
return (uid, puddleComponent);
}
return null;
}
[Test]
public async Task SpillCorner()
{
var pair = Pair;
var server = pair.Server;
var mapManager = server.ResolveDependency<IMapManager>();
var entityManager = server.ResolveDependency<IEntityManager>();
var puddleSystem = server.System<PuddleSystem>();
var mapSystem = server.System<SharedMapSystem>();
var gameTiming = server.ResolveDependency<IGameTiming>();
EntityUid gridId = default;
/*
In this test, if o is spillage puddle and # are walls, we want to ensure all tiles are empty (`.`)
. . .
# . .
o # .
*/
await server.WaitPost(() =>
{
mapSystem.CreateMap(out var mapId);
var grid = mapManager.CreateGridEntity(mapId);
gridId = grid.Owner;
for (var x = 0; x < 3; x++)
{
for (var y = 0; y < 3; y++)
{
mapSystem.SetTile(grid, new Vector2i(x, y), new Tile(1));
}
}
entityManager.SpawnEntity("WallReinforced", mapSystem.GridTileToLocal(grid, grid.Comp, new Vector2i(0, 1)));
entityManager.SpawnEntity("WallReinforced", mapSystem.GridTileToLocal(grid, grid.Comp, new Vector2i(1, 0)));
});
var puddleOrigin = new Vector2i(0, 0);
await server.WaitAssertion(() =>
{
var grid = entityManager.GetComponent<MapGridComponent>(gridId);
var solution = new Solution("Blood", FixedPoint2.New(100));
var tileRef = mapSystem.GetTileRef(gridId, grid, puddleOrigin);
#pragma warning disable NUnit2045 // Interdependent tests
Assert.That(puddleSystem.TrySpillAt(tileRef, solution, out _), Is.True);
Assert.That(GetPuddle(entityManager, (gridId, grid), puddleOrigin), Is.Not.Null);
#pragma warning restore NUnit2045
});
var sTimeToWait = (int) Math.Ceiling(2f * gameTiming.TickRate);
await server.WaitRunTicks(sTimeToWait);
await server.WaitAssertion(() =>
{
var grid = entityManager.GetComponent<MapGridComponent>(gridId);
var puddle = GetPuddleEntity(entityManager, (gridId, grid), puddleOrigin);
#pragma warning disable NUnit2045 // Interdependent tests
Assert.That(puddle, Is.Not.Null);
Assert.That(puddleSystem.CurrentVolume(puddle!.Value.Owner, puddle), Is.EqualTo(FixedPoint2.New(100)));
#pragma warning restore NUnit2045
for (var x = 0; x < 3; x++)
{
for (var y = 0; y < 3; y++)
{
if (x == 0 && y == 0 || x == 0 && y == 1 || x == 1 && y == 0)
{
continue;
}
var newPos = new Vector2i(x, y);
var sidePuddle = GetPuddle(entityManager, (gridId, grid), newPos);
Assert.That(sidePuddle, Is.Null);
}
}
});
}
}