Files
crystall-punk-14/Content.IntegrationTests/Tests/Interaction/InRangeUnobstructed.cs

107 lines
4.5 KiB
C#
Raw Normal View History

using System.Threading.Tasks;
2021-06-09 22:19:39 +02:00
using Content.Shared.Interaction;
using NUnit.Framework;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Maths;
namespace Content.IntegrationTests.Tests.Interaction
{
[TestFixture]
[TestOf(typeof(SharedInteractionSystem))]
public sealed class InRangeUnobstructed : ContentIntegrationTest
{
private const string HumanId = "MobHumanBase";
private const float InteractionRange = SharedInteractionSystem.InteractionRange;
private const float InteractionRangeDivided15 = InteractionRange / 1.5f;
private readonly (float, float) _interactionRangeDivided15X = (InteractionRangeDivided15, 0f);
private const float InteractionRangeDivided15Times3 = InteractionRangeDivided15 * 3;
[Test]
public async Task EntityEntityTest()
{
Add test pooling (#4961) * Add test pooling * WIP test pooling changes * Fix Destructible tests * Don't pool unpooled or dummy ticker instances * Change ServerPathfindingDebugSystem to replace existing entries * Fix SaveLoadSaveTest comment * Don't pool StartTest * Comment out global setup * Fix puddle tests * Move SolarPanelComponent initialize to PowerSolarSystem OnMapInit * Update RobustToolbox * Finish fixing tests, make test threads background threads * Bring back pooling * Fix nullable * Update RobustToolbox * Set cvars on server return * Un-pool tests with custom cvars * Update RobustToolbox * Update RobustToolbox * Change where the main tile coordinates are * Remove DisposalUnitTest grid check * Fix test pooling being a fickle bitch * Fix EntitySystemExtensionsTest * Update RobustToolbox * Update RobustToolbox * Make nullable pool settings true * Update RobustToolbox * Wait other way around * We are unitystation now * Update RobustToolbox * Create global setup * Pool some more tests * Fix not properly disconnecting clients before restarting the round * Give more info on ran tests * Standardize default test cvars * Update RobustToolbox * Update RobustToolbox * Pool clients * Fix test order issue * Fix cvars in character creation test not being set properly * Update RobustToolbox * Update RobustToolbox * Rider shut * Update RobustToolbox * Format tests ran better * Update RobustToolbox * Reset RobustToolbox * Reset RobustToolbox harder * Fix one instance of test order causing destructible tests to fail
2021-11-06 11:49:59 +01:00
var server = StartServer();
await server.WaitIdleAsync();
2021-12-05 18:09:01 +01:00
var sEntities = server.ResolveDependency<IEntityManager>();
var mapManager = server.ResolveDependency<IMapManager>();
2021-12-05 18:09:01 +01:00
EntityUid origin = default;
EntityUid other = default;
IContainer container = null;
IComponent component = null;
EntityCoordinates entityCoordinates = default;
MapCoordinates mapCoordinates = default;
server.Assert(() =>
{
var mapId = mapManager.CreateMap();
var coordinates = new MapCoordinates(Vector2.Zero, mapId);
2021-12-05 18:09:01 +01:00
origin = sEntities.SpawnEntity(HumanId, coordinates);
other = sEntities.SpawnEntity(HumanId, coordinates);
container = other.EnsureContainer<Container>("InRangeUnobstructedTestOtherContainer");
component = sEntities.GetComponent<TransformComponent>(other);
entityCoordinates = sEntities.GetComponent<TransformComponent>(other).Coordinates;
mapCoordinates = sEntities.GetComponent<TransformComponent>(other).MapPosition;
});
await server.WaitIdleAsync();
var interactionSys = server.ResolveDependency<IEntitySystemManager>().GetEntitySystem<SharedInteractionSystem>();
server.Assert(() =>
{
// Entity <-> Entity
Assert.True(interactionSys.InRangeUnobstructed(origin, other));
Assert.True(interactionSys.InRangeUnobstructed(other, origin));
// Entity <-> MapCoordinates
Assert.True(interactionSys.InRangeUnobstructed(origin, mapCoordinates));
Assert.True(interactionSys.InRangeUnobstructed(mapCoordinates, origin));
// Move them slightly apart
sEntities.GetComponent<TransformComponent>(origin).LocalPosition += _interactionRangeDivided15X;
// Entity <-> Entity
// Entity <-> Entity
Assert.True(interactionSys.InRangeUnobstructed(origin, other));
Assert.True(interactionSys.InRangeUnobstructed(other, origin));
// Entity <-> MapCoordinates
Assert.True(interactionSys.InRangeUnobstructed(origin, mapCoordinates));
Assert.True(interactionSys.InRangeUnobstructed(mapCoordinates, origin));
// Move them out of range
sEntities.GetComponent<TransformComponent>(origin).LocalPosition += _interactionRangeDivided15X;
// Entity <-> Entity
Assert.False(interactionSys.InRangeUnobstructed(origin, other));
Assert.False(interactionSys.InRangeUnobstructed(other, origin));
// Entity <-> MapCoordinates
Assert.False(interactionSys.InRangeUnobstructed(origin, mapCoordinates));
Assert.False(interactionSys.InRangeUnobstructed(mapCoordinates, origin));
// Checks with increased range
// Entity <-> Entity
Assert.True(interactionSys.InRangeUnobstructed(origin, other, InteractionRangeDivided15Times3));
Assert.True(interactionSys.InRangeUnobstructed(other, origin, InteractionRangeDivided15Times3));
// Entity <-> MapCoordinates
Assert.True(interactionSys.InRangeUnobstructed(origin, mapCoordinates, InteractionRangeDivided15Times3));
Assert.True(interactionSys.InRangeUnobstructed(mapCoordinates, origin, InteractionRangeDivided15Times3));
});
await server.WaitIdleAsync();
}
}
}