Files
ss14-wl/Content.IntegrationTests/Tests/Interaction/Click/InteractionSystemTests.cs
T
Moony d42adbf05d Gametest Part 2: Preliminary refactor every test to use GameTest as the framework. (#43207)
* Pass 1.

* i'm FREE

* Prevent hangups.

* okay fine here's an attribute for settings, will polish later and prolly remove the overridable thing.

* sigh.

* fix singular trigger bug so LatheTest doesn't flake.

* Remove SystemAttribute usage.

* Poke

* I used the shotgun. You know why? Cause the shot gun doesn’t miss, and unlike the shitty hybrid taser it stops a criminal in their tracks in two hits. Bang, bang, and they’re fucking done. I use four shots just to make damn sure. Because, once again, I’m not there to coddle a buncha criminal scum sucking f------, I’m there to 1) Survive the fucking round. 2) Guard the armory. So you can absolutely get fucked. If I get unbanned, which I won’t, you can guarantee I will continue to use the shotgun to apprehend criminals. Because it’s quick, clean and effective as fuck. Why in the seven hells would I fuck around with the disabler shots, which take half a clip just to bring someone down, or with the tazer bolts which are slow as balls, impossible to aim and do about next to jack shit, fuck all. The shotgun is the superior law enforcement weapon. Because it stops crime. And it stops crime by reducing the number of criminals roaming the fucking halls.

* Change the faulty store test into two tests, one of which is ignored for failing.
2026-04-01 16:06:26 +00:00

411 lines
17 KiB
C#

#nullable enable annotations
using System.Numerics;
using Content.IntegrationTests.Fixtures;
using Content.Server.Interaction;
using Content.Shared.Hands.Components;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Components;
using Content.Shared.Item;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Reflection;
namespace Content.IntegrationTests.Tests.Interaction.Click
{
[TestFixture]
[TestOf(typeof(InteractionSystem))]
public sealed class InteractionSystemTests : GameTest
{
[TestPrototypes]
private const string Prototypes = @"
- type: entity
id: DummyDebugWall
components:
- type: Physics
bodyType: Dynamic
- type: Fixtures
fixtures:
fix1:
shape:
!type:PhysShapeAabb
bounds: ""-0.25,-0.25,0.25,0.25""
layer:
- MobMask
mask:
- MobMask
";
[Test]
public async Task InteractionTest()
{
var pair = Pair;
var server = pair.Server;
var sEntities = server.ResolveDependency<IEntityManager>();
var mapManager = server.ResolveDependency<IMapManager>();
var sysMan = server.ResolveDependency<IEntitySystemManager>();
var handSys = sysMan.GetEntitySystem<SharedHandsSystem>();
var map = await pair.CreateTestMap();
var mapId = map.MapId;
var coords = map.MapCoords;
await server.WaitIdleAsync();
EntityUid user = default;
EntityUid target = default;
EntityUid item = default;
await server.WaitAssertion(() =>
{
user = sEntities.SpawnEntity(null, coords);
sEntities.EnsureComponent<HandsComponent>(user);
sEntities.EnsureComponent<ComplexInteractionComponent>(user);
handSys.AddHand(user, "hand", HandLocation.Left);
target = sEntities.SpawnEntity(null, coords);
item = sEntities.SpawnEntity(null, coords);
sEntities.EnsureComponent<ItemComponent>(item);
});
await server.WaitRunTicks(1);
var entitySystemManager = server.ResolveDependency<IEntitySystemManager>();
InteractionSystem interactionSystem = default!;
TestInteractionSystem testInteractionSystem = default!;
Assert.Multiple(() =>
{
Assert.That(entitySystemManager.TryGetEntitySystem(out interactionSystem));
Assert.That(entitySystemManager.TryGetEntitySystem(out testInteractionSystem));
});
var interactUsing = false;
var interactHand = false;
await server.WaitAssertion(() =>
{
testInteractionSystem.InteractUsingEvent = (ev) => { Assert.That(ev.Target, Is.EqualTo(target)); interactUsing = true; };
testInteractionSystem.InteractHandEvent = (ev) => { Assert.That(ev.Target, Is.EqualTo(target)); interactHand = true; };
interactionSystem.UserInteraction(user, sEntities.GetComponent<TransformComponent>(target).Coordinates, target);
Assert.Multiple(() =>
{
Assert.That(interactUsing, Is.False);
Assert.That(interactHand);
});
Assert.That(handSys.TryPickup(user, item));
interactionSystem.UserInteraction(user, sEntities.GetComponent<TransformComponent>(target).Coordinates, target);
Assert.That(interactUsing);
});
testInteractionSystem.ClearHandlers();
}
[Test]
public async Task InteractionObstructionTest()
{
var pair = Pair;
var server = pair.Server;
var sEntities = server.ResolveDependency<IEntityManager>();
var mapManager = server.ResolveDependency<IMapManager>();
var sysMan = server.ResolveDependency<IEntitySystemManager>();
var handSys = sysMan.GetEntitySystem<SharedHandsSystem>();
var map = await pair.CreateTestMap();
var mapId = map.MapId;
var coords = map.MapCoords;
await server.WaitIdleAsync();
EntityUid user = default;
EntityUid target = default;
EntityUid item = default;
EntityUid wall = default;
await server.WaitAssertion(() =>
{
user = sEntities.SpawnEntity(null, coords);
sEntities.EnsureComponent<HandsComponent>(user);
handSys.AddHand(user, "hand", HandLocation.Left);
target = sEntities.SpawnEntity(null, new MapCoordinates(new Vector2(1.9f, 0), mapId));
item = sEntities.SpawnEntity(null, coords);
sEntities.EnsureComponent<ItemComponent>(item);
wall = sEntities.SpawnEntity("DummyDebugWall", new MapCoordinates(new Vector2(1, 0), sEntities.GetComponent<TransformComponent>(user).MapID));
});
await server.WaitRunTicks(1);
var entitySystemManager = server.ResolveDependency<IEntitySystemManager>();
InteractionSystem interactionSystem = default!;
TestInteractionSystem testInteractionSystem = default!;
Assert.Multiple(() =>
{
Assert.That(entitySystemManager.TryGetEntitySystem(out interactionSystem));
Assert.That(entitySystemManager.TryGetEntitySystem(out testInteractionSystem));
});
var interactUsing = false;
var interactHand = false;
await server.WaitAssertion(() =>
{
testInteractionSystem.InteractUsingEvent = (ev) => { Assert.That(ev.Target, Is.EqualTo(target)); interactUsing = true; };
testInteractionSystem.InteractHandEvent = (ev) => { Assert.That(ev.Target, Is.EqualTo(target)); interactHand = true; };
interactionSystem.UserInteraction(user, sEntities.GetComponent<TransformComponent>(target).Coordinates, target);
Assert.Multiple(() =>
{
Assert.That(interactUsing, Is.False);
Assert.That(interactHand, Is.False);
});
Assert.That(handSys.TryPickup(user, item));
interactionSystem.UserInteraction(user, sEntities.GetComponent<TransformComponent>(target).Coordinates, target);
Assert.That(interactUsing, Is.False);
});
testInteractionSystem.ClearHandlers();
}
[Test]
public async Task InteractionInRangeTest()
{
var pair = Pair;
var server = pair.Server;
var sEntities = server.ResolveDependency<IEntityManager>();
var mapManager = server.ResolveDependency<IMapManager>();
var sysMan = server.ResolveDependency<IEntitySystemManager>();
var handSys = sysMan.GetEntitySystem<SharedHandsSystem>();
var map = await pair.CreateTestMap();
var mapId = map.MapId;
var coords = map.MapCoords;
await server.WaitIdleAsync();
EntityUid user = default;
EntityUid target = default;
EntityUid item = default;
await server.WaitAssertion(() =>
{
user = sEntities.SpawnEntity(null, coords);
sEntities.EnsureComponent<HandsComponent>(user);
sEntities.EnsureComponent<ComplexInteractionComponent>(user);
handSys.AddHand(user, "hand", HandLocation.Left);
target = sEntities.SpawnEntity(null, new MapCoordinates(new Vector2(SharedInteractionSystem.InteractionRange - 0.1f, 0), mapId));
item = sEntities.SpawnEntity(null, coords);
sEntities.EnsureComponent<ItemComponent>(item);
});
await server.WaitRunTicks(1);
var entitySystemManager = server.ResolveDependency<IEntitySystemManager>();
InteractionSystem interactionSystem = default!;
TestInteractionSystem testInteractionSystem = default!;
Assert.Multiple(() =>
{
Assert.That(entitySystemManager.TryGetEntitySystem(out interactionSystem));
Assert.That(entitySystemManager.TryGetEntitySystem(out testInteractionSystem));
});
var interactUsing = false;
var interactHand = false;
await server.WaitAssertion(() =>
{
testInteractionSystem.InteractUsingEvent = (ev) => { Assert.That(ev.Target, Is.EqualTo(target)); interactUsing = true; };
testInteractionSystem.InteractHandEvent = (ev) => { Assert.That(ev.Target, Is.EqualTo(target)); interactHand = true; };
interactionSystem.UserInteraction(user, sEntities.GetComponent<TransformComponent>(target).Coordinates, target);
Assert.Multiple(() =>
{
Assert.That(interactUsing, Is.False);
Assert.That(interactHand);
});
Assert.That(handSys.TryPickup(user, item));
interactionSystem.UserInteraction(user, sEntities.GetComponent<TransformComponent>(target).Coordinates, target);
Assert.That(interactUsing);
});
testInteractionSystem.ClearHandlers();
}
[Test]
public async Task InteractionOutOfRangeTest()
{
var pair = Pair;
var server = pair.Server;
var sEntities = server.ResolveDependency<IEntityManager>();
var mapManager = server.ResolveDependency<IMapManager>();
var sysMan = server.ResolveDependency<IEntitySystemManager>();
var handSys = sysMan.GetEntitySystem<SharedHandsSystem>();
var map = await pair.CreateTestMap();
var mapId = map.MapId;
var coords = map.MapCoords;
await server.WaitIdleAsync();
EntityUid user = default;
EntityUid target = default;
EntityUid item = default;
await server.WaitAssertion(() =>
{
user = sEntities.SpawnEntity(null, coords);
sEntities.EnsureComponent<HandsComponent>(user);
handSys.AddHand(user, "hand", HandLocation.Left);
target = sEntities.SpawnEntity(null, new MapCoordinates(new Vector2(SharedInteractionSystem.InteractionRange + 0.01f, 0), mapId));
item = sEntities.SpawnEntity(null, coords);
sEntities.EnsureComponent<ItemComponent>(item);
});
await server.WaitRunTicks(1);
var entitySystemManager = server.ResolveDependency<IEntitySystemManager>();
InteractionSystem interactionSystem = default!;
TestInteractionSystem testInteractionSystem = default!;
Assert.Multiple(() =>
{
Assert.That(entitySystemManager.TryGetEntitySystem(out interactionSystem));
Assert.That(entitySystemManager.TryGetEntitySystem(out testInteractionSystem));
});
var interactUsing = false;
var interactHand = false;
await server.WaitAssertion(() =>
{
testInteractionSystem.InteractUsingEvent = (ev) => { Assert.That(ev.Target, Is.EqualTo(target)); interactUsing = true; };
testInteractionSystem.InteractHandEvent = (ev) => { Assert.That(ev.Target, Is.EqualTo(target)); interactHand = true; };
interactionSystem.UserInteraction(user, sEntities.GetComponent<TransformComponent>(target).Coordinates, target);
Assert.Multiple(() =>
{
Assert.That(interactUsing, Is.False);
Assert.That(interactHand, Is.False);
});
Assert.That(handSys.TryPickup(user, item));
interactionSystem.UserInteraction(user, sEntities.GetComponent<TransformComponent>(target).Coordinates, target);
Assert.That(interactUsing, Is.False);
});
testInteractionSystem.ClearHandlers();
}
[Test]
public async Task InsideContainerInteractionBlockTest()
{
var pair = Pair;
var server = pair.Server;
var sEntities = server.ResolveDependency<IEntityManager>();
var mapManager = server.ResolveDependency<IMapManager>();
var sysMan = server.ResolveDependency<IEntitySystemManager>();
var handSys = sysMan.GetEntitySystem<SharedHandsSystem>();
var conSystem = sysMan.GetEntitySystem<SharedContainerSystem>();
var map = await pair.CreateTestMap();
var mapId = map.MapId;
var coords = map.MapCoords;
await server.WaitIdleAsync();
EntityUid user = default;
EntityUid target = default;
EntityUid item = default;
EntityUid containerEntity = default;
BaseContainer container = null;
await server.WaitAssertion(() =>
{
user = sEntities.SpawnEntity(null, coords);
sEntities.EnsureComponent<HandsComponent>(user);
sEntities.EnsureComponent<ComplexInteractionComponent>(user);
handSys.AddHand(user, "hand", HandLocation.Left);
target = sEntities.SpawnEntity(null, coords);
item = sEntities.SpawnEntity(null, coords);
sEntities.EnsureComponent<ItemComponent>(item);
containerEntity = sEntities.SpawnEntity(null, coords);
container = conSystem.EnsureContainer<Container>(containerEntity, "InteractionTestContainer");
});
await server.WaitRunTicks(1);
var entitySystemManager = server.ResolveDependency<IEntitySystemManager>();
InteractionSystem interactionSystem = default!;
TestInteractionSystem testInteractionSystem = default!;
Assert.Multiple(() =>
{
Assert.That(entitySystemManager.TryGetEntitySystem(out interactionSystem));
Assert.That(entitySystemManager.TryGetEntitySystem(out testInteractionSystem));
});
await server.WaitIdleAsync();
var interactUsing = false;
var interactHand = false;
await server.WaitAssertion(() =>
{
#pragma warning disable NUnit2045 // Interdependent assertions.
Assert.That(conSystem.Insert(user, container));
Assert.That(sEntities.GetComponent<TransformComponent>(user).ParentUid, Is.EqualTo(containerEntity));
#pragma warning restore NUnit2045
testInteractionSystem.InteractUsingEvent = (ev) => { Assert.That(ev.Target, Is.EqualTo(containerEntity)); interactUsing = true; };
testInteractionSystem.InteractHandEvent = (ev) => { Assert.That(ev.Target, Is.EqualTo(containerEntity)); interactHand = true; };
interactionSystem.UserInteraction(user, sEntities.GetComponent<TransformComponent>(target).Coordinates, target);
Assert.Multiple(() =>
{
Assert.That(interactUsing, Is.False);
Assert.That(interactHand, Is.False);
});
interactionSystem.UserInteraction(user, sEntities.GetComponent<TransformComponent>(containerEntity).Coordinates, containerEntity);
Assert.Multiple(() =>
{
Assert.That(interactUsing, Is.False);
Assert.That(interactHand);
});
Assert.That(handSys.TryPickup(user, item));
interactionSystem.UserInteraction(user, sEntities.GetComponent<TransformComponent>(target).Coordinates, target);
Assert.That(interactUsing, Is.False);
interactionSystem.UserInteraction(user, sEntities.GetComponent<TransformComponent>(containerEntity).Coordinates, containerEntity);
Assert.That(interactUsing, Is.True);
});
testInteractionSystem.ClearHandlers();
}
public sealed class TestInteractionSystem : EntitySystem
{
public EntityEventHandler<InteractUsingEvent>? InteractUsingEvent;
public EntityEventHandler<InteractHandEvent>? InteractHandEvent;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<InteractUsingEvent>((e) => InteractUsingEvent?.Invoke(e));
SubscribeLocalEvent<InteractHandEvent>((e) => InteractHandEvent?.Invoke(e));
}
public void ClearHandlers()
{
InteractUsingEvent = null;
InteractHandEvent = null;
}
}
}
}