2023-07-08 14:08:32 +10:00
|
|
|
using System.Numerics;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Interaction;
|
2024-05-12 07:31:54 -07:00
|
|
|
using Robust.Server.GameObjects;
|
2021-03-01 15:24:46 -08:00
|
|
|
using Robust.Shared.Containers;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.GameObjects;
|
2020-08-30 11:37:06 +02:00
|
|
|
using Robust.Shared.Map;
|
2021-04-13 13:17:10 +02:00
|
|
|
using Robust.Shared.Maths;
|
2020-08-30 11:37:06 +02:00
|
|
|
|
|
|
|
|
namespace Content.IntegrationTests.Tests.Interaction
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
[TestOf(typeof(SharedInteractionSystem))]
|
2022-06-19 20:22:28 -07:00
|
|
|
public sealed class InRangeUnobstructed
|
2020-08-30 11:37:06 +02:00
|
|
|
{
|
2022-07-27 20:54:23 +10:00
|
|
|
private const string HumanId = "MobHuman";
|
2020-08-30 11:37:06 +02:00
|
|
|
|
|
|
|
|
private const float InteractionRange = SharedInteractionSystem.InteractionRange;
|
|
|
|
|
|
|
|
|
|
private const float InteractionRangeDivided15 = InteractionRange / 1.5f;
|
|
|
|
|
|
2023-07-08 14:08:32 +10:00
|
|
|
private static readonly Vector2 InteractionRangeDivided15X = new(InteractionRangeDivided15, 0f);
|
2020-08-30 11:37:06 +02:00
|
|
|
|
|
|
|
|
private const float InteractionRangeDivided15Times3 = InteractionRangeDivided15 * 3;
|
|
|
|
|
|
2022-10-07 00:37:21 +11:00
|
|
|
private const float HumanRadius = 0.35f;
|
|
|
|
|
|
2020-08-30 11:37:06 +02:00
|
|
|
[Test]
|
|
|
|
|
public async Task EntityEntityTest()
|
|
|
|
|
{
|
2023-08-25 02:56:51 +02:00
|
|
|
await using var pair = await PoolManager.GetServerClient();
|
|
|
|
|
var server = pair.Server;
|
2020-08-30 11:37:06 +02:00
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
var sEntities = server.ResolveDependency<IEntityManager>();
|
2020-08-30 11:37:06 +02:00
|
|
|
var mapManager = server.ResolveDependency<IMapManager>();
|
2022-07-20 14:48:44 +10:00
|
|
|
var conSystem = sEntities.EntitySysManager.GetEntitySystem<SharedContainerSystem>();
|
2024-05-12 07:31:54 -07:00
|
|
|
var tSystem = sEntities.EntitySysManager.GetEntitySystem<TransformSystem>();
|
2020-08-30 11:37:06 +02:00
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
EntityUid origin = default;
|
|
|
|
|
EntityUid other = default;
|
2020-08-30 11:37:06 +02:00
|
|
|
MapCoordinates mapCoordinates = default;
|
|
|
|
|
|
2024-07-02 20:01:37 -04:00
|
|
|
var map = await pair.CreateTestMap();
|
|
|
|
|
|
2022-06-19 20:22:28 -07:00
|
|
|
await server.WaitAssertion(() =>
|
2020-08-30 11:37:06 +02:00
|
|
|
{
|
2024-07-02 20:01:37 -04:00
|
|
|
var coordinates = map.MapCoords;
|
2020-08-30 11:37:06 +02:00
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
origin = sEntities.SpawnEntity(HumanId, coordinates);
|
|
|
|
|
other = sEntities.SpawnEntity(HumanId, coordinates);
|
2022-07-20 14:48:44 +10:00
|
|
|
conSystem.EnsureContainer<Container>(other, "InRangeUnobstructedTestOtherContainer");
|
2024-05-12 07:31:54 -07:00
|
|
|
mapCoordinates = tSystem.GetMapCoordinates(other);
|
2020-08-30 11:37:06 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await server.WaitIdleAsync();
|
|
|
|
|
|
2023-07-05 21:54:25 -07:00
|
|
|
var interactionSys = sEntities.System<SharedInteractionSystem>();
|
|
|
|
|
var xformSys = sEntities.System<SharedTransformSystem>();
|
|
|
|
|
var xform = sEntities.GetComponent<TransformComponent>(origin);
|
2022-02-17 15:40:03 +13:00
|
|
|
|
2022-06-19 20:22:28 -07:00
|
|
|
await server.WaitAssertion(() =>
|
2020-08-30 11:37:06 +02:00
|
|
|
{
|
2023-07-05 21:54:25 -07:00
|
|
|
Assert.Multiple(() =>
|
|
|
|
|
{
|
|
|
|
|
// Entity <-> Entity
|
|
|
|
|
Assert.That(interactionSys.InRangeUnobstructed(origin, other));
|
|
|
|
|
Assert.That(interactionSys.InRangeUnobstructed(other, origin));
|
2020-08-30 11:37:06 +02:00
|
|
|
|
2023-07-05 21:54:25 -07:00
|
|
|
// Entity <-> MapCoordinates
|
|
|
|
|
Assert.That(interactionSys.InRangeUnobstructed(origin, mapCoordinates));
|
|
|
|
|
Assert.That(interactionSys.InRangeUnobstructed(mapCoordinates, origin));
|
|
|
|
|
});
|
2020-08-30 11:37:06 +02:00
|
|
|
|
|
|
|
|
// Move them slightly apart
|
2023-07-08 14:08:32 +10:00
|
|
|
xformSys.SetLocalPosition(origin, xform.LocalPosition + InteractionRangeDivided15X, xform);
|
2020-08-30 11:37:06 +02:00
|
|
|
|
2023-07-05 21:54:25 -07:00
|
|
|
Assert.Multiple(() =>
|
|
|
|
|
{
|
|
|
|
|
// Entity <-> Entity
|
|
|
|
|
// Entity <-> Entity
|
|
|
|
|
Assert.That(interactionSys.InRangeUnobstructed(origin, other));
|
|
|
|
|
Assert.That(interactionSys.InRangeUnobstructed(other, origin));
|
2020-08-30 11:37:06 +02:00
|
|
|
|
2023-07-05 21:54:25 -07:00
|
|
|
// Entity <-> MapCoordinates
|
|
|
|
|
Assert.That(interactionSys.InRangeUnobstructed(origin, mapCoordinates));
|
|
|
|
|
Assert.That(interactionSys.InRangeUnobstructed(mapCoordinates, origin));
|
|
|
|
|
});
|
2020-08-30 11:37:06 +02:00
|
|
|
|
|
|
|
|
// Move them out of range
|
2023-07-05 21:54:25 -07:00
|
|
|
xformSys.SetLocalPosition(origin, xform.LocalPosition + new Vector2(InteractionRangeDivided15 + HumanRadius * 2f, 0f), xform);
|
2020-08-30 11:37:06 +02:00
|
|
|
|
2023-07-05 21:54:25 -07:00
|
|
|
Assert.Multiple(() =>
|
|
|
|
|
{
|
|
|
|
|
// Entity <-> Entity
|
|
|
|
|
Assert.That(interactionSys.InRangeUnobstructed(origin, other), Is.False);
|
|
|
|
|
Assert.That(interactionSys.InRangeUnobstructed(other, origin), Is.False);
|
2020-08-30 11:37:06 +02:00
|
|
|
|
2023-07-05 21:54:25 -07:00
|
|
|
// Entity <-> MapCoordinates
|
|
|
|
|
Assert.That(interactionSys.InRangeUnobstructed(origin, mapCoordinates), Is.False);
|
|
|
|
|
Assert.That(interactionSys.InRangeUnobstructed(mapCoordinates, origin), Is.False);
|
2020-08-30 11:37:06 +02:00
|
|
|
|
2023-07-05 21:54:25 -07:00
|
|
|
// Checks with increased range
|
2020-08-30 11:37:06 +02:00
|
|
|
|
2023-07-05 21:54:25 -07:00
|
|
|
// Entity <-> Entity
|
|
|
|
|
Assert.That(interactionSys.InRangeUnobstructed(origin, other, InteractionRangeDivided15Times3));
|
|
|
|
|
Assert.That(interactionSys.InRangeUnobstructed(other, origin, InteractionRangeDivided15Times3));
|
2020-08-30 11:37:06 +02:00
|
|
|
|
2023-07-05 21:54:25 -07:00
|
|
|
// Entity <-> MapCoordinates
|
|
|
|
|
Assert.That(interactionSys.InRangeUnobstructed(origin, mapCoordinates, InteractionRangeDivided15Times3));
|
|
|
|
|
Assert.That(interactionSys.InRangeUnobstructed(mapCoordinates, origin, InteractionRangeDivided15Times3));
|
|
|
|
|
});
|
2020-08-30 11:37:06 +02:00
|
|
|
});
|
|
|
|
|
|
2023-08-25 02:56:51 +02:00
|
|
|
await pair.CleanReturnAsync();
|
2020-08-30 11:37:06 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|