Files
tbd-station-14/Content.IntegrationTests/Tests/Interaction/InRangeUnobstructed.cs
TemporalOroboros f284b43ff6 Fixes obsolete Transform warnings in Content. (#25256)
* Fix TransformComponent.MapPosition warnings in Content.Client

* Fix TransformComponent.MapPosition warnings in Content.IntegrationTests

* Fix TransformComponent.MapPosition warnings in Content.Shared

* Fix TransformComponent.MapPosition warnings in Content.Server

* Fix TransformComponent.WorldPosition warnings in Content.Shared

* Fix TransformComponent.WorldPosition warnings in Content.Client
Excepts ClickableComponent b/c that needs to be ECS'd entirely later

* Fix TransformComponent.WorldPosition warnings in Content.Server

* Fix TransformComponent.WorldRotation warnings in Content.*

* Fix TransformComponent.MapPosition warnings I missed

* Fix TransformComponent.WorldMatrix warnings in Content.*

* Fix TransformComponent.InvWorldMatrix warnings in Content.*

* Fix TransformComponent.GetWorldPositionRotationMatrixWithInv warnings in Content.*

* Fix TransformComponent.GetWorldPositionRotationMatrix warnings in Content.*

* Fix TransformComponent.GetWorldPositionRotation warnings in Content.*

* Fix TransformComponent.Anchored.set warnings in Content.*

* Fix TransformComponent.Coordinates.set warnings in Content.*

* Fix TransformComponent.LocalPosition.set warnings in Content.*

* Fix TransformComponent.AttachToGridOrMap warnings in Content.*

* Fix TransformComponent.AttachParent warnings in Content.*

* Preempt TransformComponent.LocalRotation.set warnings in Content.Shared

* Preempt TransformComponent.LocalRotation.set warnings in Content.Client

* Preempt TransformComponent.LocalRotation.set warnings in Content.IntegrationTests

* Preempt TransformComponent.LocalRotation.set warnings in Content.Server

* Fix/Preempt the remaining obsolete TransformComponent properties/methods in Content.*

* ECS ClickableComponent

* Fix obsolete SharedTransformSystem methods in Content.*

* Fix ExplosionOverlay `SharedTransformSystem` dependency

* Maybe fix null eye position breaking tests

* MGS requested changes
2024-02-27 12:06:20 +11:00

115 lines
4.9 KiB
C#

using System.Numerics;
using Content.Shared.Interaction;
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
{
private const string HumanId = "MobHuman";
private const float InteractionRange = SharedInteractionSystem.InteractionRange;
private const float InteractionRangeDivided15 = InteractionRange / 1.5f;
private static readonly Vector2 InteractionRangeDivided15X = new(InteractionRangeDivided15, 0f);
private const float InteractionRangeDivided15Times3 = InteractionRangeDivided15 * 3;
private const float HumanRadius = 0.35f;
[Test]
public async Task EntityEntityTest()
{
await using var pair = await PoolManager.GetServerClient();
var server = pair.Server;
var sEntities = server.ResolveDependency<IEntityManager>();
var mapManager = server.ResolveDependency<IMapManager>();
var conSystem = sEntities.EntitySysManager.GetEntitySystem<SharedContainerSystem>();
var xfmSystem = sEntities.EntitySysManager.GetEntitySystem<SharedTransformSystem>();
EntityUid origin = default;
EntityUid other = default;
MapCoordinates mapCoordinates = default;
await server.WaitAssertion(() =>
{
var mapId = mapManager.CreateMap();
var coordinates = new MapCoordinates(Vector2.Zero, mapId);
origin = sEntities.SpawnEntity(HumanId, coordinates);
other = sEntities.SpawnEntity(HumanId, coordinates);
conSystem.EnsureContainer<Container>(other, "InRangeUnobstructedTestOtherContainer");
mapCoordinates = xfmSystem.GetMapCoordinates(other);
});
await server.WaitIdleAsync();
var interactionSys = sEntities.System<SharedInteractionSystem>();
var xformSys = sEntities.System<SharedTransformSystem>();
var xform = sEntities.GetComponent<TransformComponent>(origin);
await server.WaitAssertion(() =>
{
Assert.Multiple(() =>
{
// Entity <-> Entity
Assert.That(interactionSys.InRangeUnobstructed(origin, other));
Assert.That(interactionSys.InRangeUnobstructed(other, origin));
// Entity <-> MapCoordinates
Assert.That(interactionSys.InRangeUnobstructed(origin, mapCoordinates));
Assert.That(interactionSys.InRangeUnobstructed(mapCoordinates, origin));
});
// Move them slightly apart
xformSys.SetLocalPosition(origin, xform.LocalPosition + InteractionRangeDivided15X, xform);
Assert.Multiple(() =>
{
// Entity <-> Entity
// Entity <-> Entity
Assert.That(interactionSys.InRangeUnobstructed(origin, other));
Assert.That(interactionSys.InRangeUnobstructed(other, origin));
// Entity <-> MapCoordinates
Assert.That(interactionSys.InRangeUnobstructed(origin, mapCoordinates));
Assert.That(interactionSys.InRangeUnobstructed(mapCoordinates, origin));
});
// Move them out of range
xformSys.SetLocalPosition(origin, xform.LocalPosition + new Vector2(InteractionRangeDivided15 + HumanRadius * 2f, 0f), xform);
Assert.Multiple(() =>
{
// Entity <-> Entity
Assert.That(interactionSys.InRangeUnobstructed(origin, other), Is.False);
Assert.That(interactionSys.InRangeUnobstructed(other, origin), Is.False);
// Entity <-> MapCoordinates
Assert.That(interactionSys.InRangeUnobstructed(origin, mapCoordinates), Is.False);
Assert.That(interactionSys.InRangeUnobstructed(mapCoordinates, origin), Is.False);
// Checks with increased range
// Entity <-> Entity
Assert.That(interactionSys.InRangeUnobstructed(origin, other, InteractionRangeDivided15Times3));
Assert.That(interactionSys.InRangeUnobstructed(other, origin, InteractionRangeDivided15Times3));
// Entity <-> MapCoordinates
Assert.That(interactionSys.InRangeUnobstructed(origin, mapCoordinates, InteractionRangeDivided15Times3));
Assert.That(interactionSys.InRangeUnobstructed(mapCoordinates, origin, InteractionRangeDivided15Times3));
});
});
await pair.CleanReturnAsync();
}
}
}