2021-02-13 17:52:06 +01:00
|
|
|
|
#nullable enable
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using Content.Shared.Physics;
|
2021-06-09 22:19:39 +02:00
|
|
|
|
using Content.Shared.Spawning;
|
2021-02-13 17:52:06 +01:00
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
using Robust.Shared.GameObjects;
|
2021-12-03 14:20:34 +01:00
|
|
|
|
using Robust.Shared.IoC;
|
2021-02-13 17:52:06 +01:00
|
|
|
|
using Robust.Shared.Map;
|
2021-07-21 21:15:12 +10:00
|
|
|
|
using Robust.Shared.Physics;
|
2021-02-13 17:52:06 +01:00
|
|
|
|
|
|
|
|
|
|
namespace Content.IntegrationTests.Tests.Utility
|
|
|
|
|
|
{
|
|
|
|
|
|
[TestFixture]
|
|
|
|
|
|
[TestOf(typeof(EntitySystemExtensions))]
|
2022-02-16 00:23:23 -07:00
|
|
|
|
public sealed class EntitySystemExtensionsTest : ContentIntegrationTest
|
2021-02-13 17:52:06 +01:00
|
|
|
|
{
|
|
|
|
|
|
private const string BlockerDummyId = "BlockerDummy";
|
|
|
|
|
|
|
|
|
|
|
|
private static readonly string Prototypes = $@"
|
|
|
|
|
|
- type: entity
|
|
|
|
|
|
id: {BlockerDummyId}
|
|
|
|
|
|
name: {BlockerDummyId}
|
|
|
|
|
|
components:
|
|
|
|
|
|
- type: Physics
|
2021-12-01 18:32:37 +11:00
|
|
|
|
- type: Fixtures
|
2021-03-08 04:09:59 +11:00
|
|
|
|
fixtures:
|
|
|
|
|
|
- shape:
|
|
|
|
|
|
!type:PhysShapeAabb
|
|
|
|
|
|
bounds: ""-0.49,-0.49,0.49,0.49""
|
2021-02-13 17:52:06 +01:00
|
|
|
|
mask:
|
|
|
|
|
|
- Impassable
|
|
|
|
|
|
";
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
|
public async Task Test()
|
|
|
|
|
|
{
|
|
|
|
|
|
var serverOptions = new ServerContentIntegrationOption {ExtraPrototypes = Prototypes};
|
|
|
|
|
|
var server = StartServer(serverOptions);
|
|
|
|
|
|
|
|
|
|
|
|
await server.WaitIdleAsync();
|
|
|
|
|
|
|
|
|
|
|
|
var sMapManager = server.ResolveDependency<IMapManager>();
|
|
|
|
|
|
var sEntityManager = server.ResolveDependency<IEntityManager>();
|
2021-07-21 21:15:12 +10:00
|
|
|
|
var broady = server.ResolveDependency<IEntitySystemManager>().GetEntitySystem<SharedBroadphaseSystem>();
|
2021-02-13 17:52:06 +01:00
|
|
|
|
|
|
|
|
|
|
await server.WaitAssertion(() =>
|
|
|
|
|
|
{
|
2021-11-06 11:49:59 +01:00
|
|
|
|
var grid = GetMainGrid(sMapManager);
|
2021-12-05 18:09:01 +01:00
|
|
|
|
var gridEnt = grid.GridEntityId;
|
2021-12-03 15:53:09 +01:00
|
|
|
|
var gridPos = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(gridEnt).WorldPosition;
|
2021-11-06 11:49:59 +01:00
|
|
|
|
var entityCoordinates = GetMainEntityCoordinates(sMapManager);
|
2021-02-13 17:52:06 +01:00
|
|
|
|
|
|
|
|
|
|
// Nothing blocking it, only entity is the grid
|
|
|
|
|
|
Assert.NotNull(sEntityManager.SpawnIfUnobstructed(null, entityCoordinates, CollisionGroup.Impassable));
|
|
|
|
|
|
Assert.True(sEntityManager.TrySpawnIfUnobstructed(null, entityCoordinates, CollisionGroup.Impassable, out var entity));
|
|
|
|
|
|
Assert.NotNull(entity);
|
|
|
|
|
|
|
2021-11-06 11:49:59 +01:00
|
|
|
|
var mapId = GetMainMapId(sMapManager);
|
2021-08-03 18:49:25 +10:00
|
|
|
|
var mapCoordinates = new MapCoordinates(gridPos.X, gridPos.Y, mapId);
|
2021-02-13 17:52:06 +01:00
|
|
|
|
|
|
|
|
|
|
// Nothing blocking it, only entity is the grid
|
|
|
|
|
|
Assert.NotNull(sEntityManager.SpawnIfUnobstructed(null, mapCoordinates, CollisionGroup.Impassable));
|
|
|
|
|
|
Assert.True(sEntityManager.TrySpawnIfUnobstructed(null, mapCoordinates, CollisionGroup.Impassable, out entity));
|
|
|
|
|
|
Assert.NotNull(entity);
|
|
|
|
|
|
|
|
|
|
|
|
// Spawn a blocker with an Impassable mask
|
|
|
|
|
|
sEntityManager.SpawnEntity(BlockerDummyId, entityCoordinates);
|
2021-03-08 04:09:59 +11:00
|
|
|
|
broady.Update(0.016f);
|
2021-02-13 17:52:06 +01:00
|
|
|
|
|
|
|
|
|
|
// Cannot spawn something with an Impassable layer
|
|
|
|
|
|
Assert.Null(sEntityManager.SpawnIfUnobstructed(null, entityCoordinates, CollisionGroup.Impassable));
|
|
|
|
|
|
Assert.False(sEntityManager.TrySpawnIfUnobstructed(null, entityCoordinates, CollisionGroup.Impassable, out entity));
|
|
|
|
|
|
Assert.Null(entity);
|
|
|
|
|
|
|
|
|
|
|
|
Assert.Null(sEntityManager.SpawnIfUnobstructed(null, mapCoordinates, CollisionGroup.Impassable));
|
|
|
|
|
|
Assert.False(sEntityManager.TrySpawnIfUnobstructed(null, mapCoordinates, CollisionGroup.Impassable, out entity));
|
|
|
|
|
|
Assert.Null(entity);
|
|
|
|
|
|
|
|
|
|
|
|
// Other layers are fine
|
|
|
|
|
|
Assert.NotNull(sEntityManager.SpawnIfUnobstructed(null, entityCoordinates, CollisionGroup.MobImpassable));
|
|
|
|
|
|
Assert.True(sEntityManager.TrySpawnIfUnobstructed(null, entityCoordinates, CollisionGroup.MobImpassable, out entity));
|
|
|
|
|
|
Assert.NotNull(entity);
|
|
|
|
|
|
|
|
|
|
|
|
Assert.NotNull(sEntityManager.SpawnIfUnobstructed(null, mapCoordinates, CollisionGroup.MobImpassable));
|
|
|
|
|
|
Assert.True(sEntityManager.TrySpawnIfUnobstructed(null, mapCoordinates, CollisionGroup.MobImpassable, out entity));
|
|
|
|
|
|
Assert.NotNull(entity);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|