2021-02-18 20:45:45 -08:00
|
|
|
using System;
|
2020-12-14 06:18:37 +01:00
|
|
|
using System.Threading.Tasks;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.Fluids.Components;
|
2021-12-05 04:18:30 +01:00
|
|
|
using Content.Server.Fluids.EntitySystems;
|
2021-09-06 15:49:44 +02:00
|
|
|
using Content.Shared.Chemistry.Components;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Coordinates;
|
2021-11-03 16:48:03 -07:00
|
|
|
using Content.Shared.FixedPoint;
|
2020-09-02 01:31:47 +02:00
|
|
|
using NUnit.Framework;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.GameObjects;
|
2021-12-03 11:30:03 +01:00
|
|
|
using Robust.Shared.IoC;
|
2020-09-02 01:31:47 +02:00
|
|
|
using Robust.Shared.Map;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.Timing;
|
2020-09-02 01:31:47 +02:00
|
|
|
|
|
|
|
|
namespace Content.IntegrationTests.Tests.Fluids
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
[TestOf(typeof(PuddleComponent))]
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class PuddleTest : ContentIntegrationTest
|
2020-09-02 01:31:47 +02:00
|
|
|
{
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task TilePuddleTest()
|
|
|
|
|
{
|
2021-11-06 11:49:59 +01:00
|
|
|
var server = StartServer();
|
2020-09-02 01:31:47 +02:00
|
|
|
|
|
|
|
|
await server.WaitIdleAsync();
|
|
|
|
|
|
|
|
|
|
var mapManager = server.ResolveDependency<IMapManager>();
|
2021-12-05 04:18:30 +01:00
|
|
|
var entitySystemManager = server.ResolveDependency<IEntitySystemManager>();
|
|
|
|
|
var spillSystem = entitySystemManager.GetEntitySystem<SpillableSystem>();
|
2020-09-02 01:31:47 +02:00
|
|
|
|
|
|
|
|
server.Assert(() =>
|
|
|
|
|
{
|
2021-11-22 18:01:51 -07:00
|
|
|
var solution = new Solution("Water", FixedPoint2.New(20));
|
2021-11-06 11:49:59 +01:00
|
|
|
var grid = GetMainGrid(mapManager);
|
|
|
|
|
var (x, y) = GetMainTile(grid).GridIndices;
|
|
|
|
|
var coordinates = new EntityCoordinates(grid.GridEntityId, x, y);
|
2021-12-05 04:18:30 +01:00
|
|
|
var puddle = spillSystem.SpillAt(solution, coordinates, "PuddleSmear");
|
2021-11-06 11:49:59 +01:00
|
|
|
|
2020-09-02 01:31:47 +02:00
|
|
|
Assert.NotNull(puddle);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await server.WaitIdleAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task SpaceNoPuddleTest()
|
|
|
|
|
{
|
2021-11-06 11:49:59 +01:00
|
|
|
var server = StartServer();
|
2020-09-02 01:31:47 +02:00
|
|
|
|
|
|
|
|
await server.WaitIdleAsync();
|
2021-11-06 11:49:59 +01:00
|
|
|
|
2020-09-02 01:31:47 +02:00
|
|
|
var mapManager = server.ResolveDependency<IMapManager>();
|
2021-12-05 04:18:30 +01:00
|
|
|
var entitySystemManager = server.ResolveDependency<IEntitySystemManager>();
|
|
|
|
|
var spillSystem = entitySystemManager.GetEntitySystem<SpillableSystem>();
|
2021-11-06 11:49:59 +01:00
|
|
|
|
2020-09-06 16:11:53 +02:00
|
|
|
IMapGrid grid = null;
|
2020-09-02 01:31:47 +02:00
|
|
|
|
2021-11-06 11:49:59 +01:00
|
|
|
// Remove all tiles
|
2020-09-02 01:31:47 +02:00
|
|
|
server.Post(() =>
|
|
|
|
|
{
|
2021-11-06 11:49:59 +01:00
|
|
|
grid = GetMainGrid(mapManager);
|
2020-09-02 01:31:47 +02:00
|
|
|
|
2021-11-06 11:49:59 +01:00
|
|
|
foreach (var tile in grid.GetAllTiles())
|
2020-09-02 01:31:47 +02:00
|
|
|
{
|
2021-11-06 11:49:59 +01:00
|
|
|
grid.SetTile(tile.GridIndices, Tile.Empty);
|
2020-09-02 01:31:47 +02:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await server.WaitIdleAsync();
|
|
|
|
|
|
|
|
|
|
server.Assert(() =>
|
|
|
|
|
{
|
2020-09-06 16:11:53 +02:00
|
|
|
var coordinates = grid.ToCoordinates();
|
2021-11-22 18:01:51 -07:00
|
|
|
var solution = new Solution("Water", FixedPoint2.New(20));
|
2021-12-05 04:18:30 +01:00
|
|
|
var puddle = spillSystem.SpillAt(solution, coordinates, "PuddleSmear");
|
2020-09-02 01:31:47 +02:00
|
|
|
Assert.Null(puddle);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await server.WaitIdleAsync();
|
|
|
|
|
}
|
2020-12-14 06:18:37 +01:00
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task PuddlePauseTest()
|
|
|
|
|
{
|
|
|
|
|
var server = StartServer();
|
|
|
|
|
|
|
|
|
|
await server.WaitIdleAsync();
|
|
|
|
|
|
|
|
|
|
var sMapManager = server.ResolveDependency<IMapManager>();
|
|
|
|
|
var sTileDefinitionManager = server.ResolveDependency<ITileDefinitionManager>();
|
|
|
|
|
var sGameTiming = server.ResolveDependency<IGameTiming>();
|
2021-12-08 12:43:38 +01:00
|
|
|
var entityManager = server.ResolveDependency<IEntityManager>();
|
2020-12-14 06:18:37 +01:00
|
|
|
|
|
|
|
|
MapId sMapId = default;
|
2021-02-09 22:04:47 +01:00
|
|
|
IMapGrid sGrid;
|
2020-12-14 06:18:37 +01:00
|
|
|
GridId sGridId = default;
|
2021-12-05 18:09:01 +01:00
|
|
|
EntityUid sGridEntity = default;
|
2020-12-14 06:18:37 +01:00
|
|
|
EntityCoordinates sCoordinates = default;
|
|
|
|
|
|
|
|
|
|
// Spawn a paused map with one tile to spawn puddles on
|
|
|
|
|
await server.WaitPost(() =>
|
|
|
|
|
{
|
|
|
|
|
sMapId = sMapManager.CreateMap();
|
2022-02-21 14:41:50 +11:00
|
|
|
sMapManager.SetMapPaused(sMapId, true);
|
2020-12-14 06:18:37 +01:00
|
|
|
sGrid = sMapManager.CreateGrid(sMapId);
|
|
|
|
|
sGridId = sGrid.Index;
|
2021-12-05 18:09:01 +01:00
|
|
|
sGridEntity = sGrid.GridEntityId;
|
2021-12-08 12:43:38 +01:00
|
|
|
entityManager.GetComponent<MetaDataComponent>(sGridEntity).EntityPaused = true; // See https://github.com/space-wizards/RobustToolbox/issues/1444
|
2020-12-14 06:18:37 +01:00
|
|
|
|
|
|
|
|
var tileDefinition = sTileDefinitionManager["underplating"];
|
|
|
|
|
var tile = new Tile(tileDefinition.TileId);
|
|
|
|
|
sCoordinates = sGrid.ToCoordinates();
|
|
|
|
|
|
|
|
|
|
sGrid.SetTile(sCoordinates, tile);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Check that the map and grid are paused
|
|
|
|
|
await server.WaitAssertion(() =>
|
|
|
|
|
{
|
2022-02-21 14:41:50 +11:00
|
|
|
Assert.True(sMapManager.IsGridPaused(sGridId));
|
|
|
|
|
Assert.True(sMapManager.IsMapPaused(sMapId));
|
2020-12-14 06:18:37 +01:00
|
|
|
});
|
|
|
|
|
|
2021-10-27 09:24:18 +01:00
|
|
|
float evaporateTime = default;
|
|
|
|
|
PuddleComponent puddle = null;
|
2021-12-08 12:43:38 +01:00
|
|
|
MetaDataComponent meta = null;
|
2021-10-27 09:24:18 +01:00
|
|
|
EvaporationComponent evaporation;
|
2021-12-08 12:43:38 +01:00
|
|
|
|
2021-10-27 09:24:18 +01:00
|
|
|
var amount = 2;
|
2021-12-08 12:43:38 +01:00
|
|
|
|
2021-12-05 04:18:30 +01:00
|
|
|
var entitySystemManager = server.ResolveDependency<IEntitySystemManager>();
|
|
|
|
|
var spillSystem = entitySystemManager.GetEntitySystem<SpillableSystem>();
|
2020-12-14 06:18:37 +01:00
|
|
|
|
|
|
|
|
// Spawn a puddle
|
|
|
|
|
await server.WaitAssertion(() =>
|
|
|
|
|
{
|
2021-11-22 18:01:51 -07:00
|
|
|
var solution = new Solution("Water", FixedPoint2.New(amount));
|
2021-12-05 04:18:30 +01:00
|
|
|
puddle = spillSystem.SpillAt(solution, sCoordinates, "PuddleSmear");
|
2021-12-08 12:43:38 +01:00
|
|
|
meta = entityManager.GetComponent<MetaDataComponent>(puddle.Owner);
|
2020-12-14 06:18:37 +01:00
|
|
|
|
|
|
|
|
// Check that the puddle was created
|
2021-10-27 09:24:18 +01:00
|
|
|
Assert.NotNull(puddle);
|
|
|
|
|
|
2021-12-08 12:43:38 +01:00
|
|
|
evaporation = entityManager.GetComponent<EvaporationComponent>(puddle.Owner);
|
2020-12-14 06:18:37 +01:00
|
|
|
|
2021-12-08 12:43:38 +01:00
|
|
|
meta.EntityPaused = true; // See https://github.com/space-wizards/RobustToolbox/issues/1445
|
2020-12-14 06:18:37 +01:00
|
|
|
|
2021-12-08 12:43:38 +01:00
|
|
|
Assert.True(meta.EntityPaused);
|
2020-12-14 06:18:37 +01:00
|
|
|
|
|
|
|
|
// Check that the puddle is going to evaporate
|
2021-10-27 09:24:18 +01:00
|
|
|
Assert.Positive(evaporation.EvaporateTime);
|
2020-12-14 06:18:37 +01:00
|
|
|
|
|
|
|
|
// Should have a timer component added to it for evaporation
|
2021-10-27 09:24:18 +01:00
|
|
|
Assert.That(evaporation.Accumulator, Is.EqualTo(0f));
|
2020-12-14 06:18:37 +01:00
|
|
|
|
2021-10-27 09:24:18 +01:00
|
|
|
evaporateTime = evaporation.EvaporateTime;
|
2020-12-14 06:18:37 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Wait enough time for it to evaporate if it was unpaused
|
2021-10-27 09:24:18 +01:00
|
|
|
var sTimeToWait = (5 + (int)Math.Ceiling(amount * evaporateTime * sGameTiming.TickRate));
|
2020-12-14 06:18:37 +01:00
|
|
|
await server.WaitRunTicks(sTimeToWait);
|
|
|
|
|
|
|
|
|
|
// No evaporation due to being paused
|
|
|
|
|
await server.WaitAssertion(() =>
|
|
|
|
|
{
|
2021-12-08 12:43:38 +01:00
|
|
|
Assert.True(meta.EntityPaused);
|
2020-12-14 06:18:37 +01:00
|
|
|
|
|
|
|
|
// Check that the puddle still exists
|
2021-12-08 12:43:38 +01:00
|
|
|
Assert.False(meta.EntityDeleted);
|
2020-12-14 06:18:37 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Unpause the map
|
2022-02-21 14:41:50 +11:00
|
|
|
await server.WaitPost(() => { sMapManager.SetMapPaused(sMapId, false); });
|
2020-12-14 06:18:37 +01:00
|
|
|
|
|
|
|
|
// Check that the map, grid and puddle are unpaused
|
|
|
|
|
await server.WaitAssertion(() =>
|
|
|
|
|
{
|
2022-02-21 14:41:50 +11:00
|
|
|
Assert.False(sMapManager.IsMapPaused(sMapId));
|
|
|
|
|
Assert.False(sMapManager.IsGridPaused(sGridId));
|
2021-12-08 12:43:38 +01:00
|
|
|
Assert.False(meta.EntityPaused);
|
2020-12-14 06:18:37 +01:00
|
|
|
|
|
|
|
|
// Check that the puddle still exists
|
2021-12-08 12:43:38 +01:00
|
|
|
Assert.False(meta.EntityDeleted);
|
2020-12-14 06:18:37 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Wait enough time for it to evaporate
|
|
|
|
|
await server.WaitRunTicks(sTimeToWait);
|
|
|
|
|
|
|
|
|
|
// Puddle evaporation should have ticked
|
|
|
|
|
await server.WaitAssertion(() =>
|
|
|
|
|
{
|
2021-10-27 09:24:18 +01:00
|
|
|
// Check that puddle has been deleted
|
|
|
|
|
Assert.True(puddle.Deleted);
|
2020-12-14 06:18:37 +01:00
|
|
|
});
|
|
|
|
|
}
|
2020-09-02 01:31:47 +02:00
|
|
|
}
|
2021-12-08 12:43:38 +01:00
|
|
|
}
|