2021-02-01 16:49:43 -08:00
|
|
|
#nullable enable
|
2023-03-13 19:34:26 -04:00
|
|
|
using Content.Server.Cuffs;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Body.Components;
|
2023-03-13 19:34:26 -04:00
|
|
|
using Content.Shared.Cuffs.Components;
|
2023-04-07 11:21:12 -07:00
|
|
|
using Content.Shared.Hands.Components;
|
2021-02-01 16:49:43 -08:00
|
|
|
using Robust.Server.Console;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.GameObjects;
|
2020-08-25 08:54:23 -04:00
|
|
|
using Robust.Shared.Map;
|
|
|
|
|
|
|
|
|
|
namespace Content.IntegrationTests.Tests.GameObjects.Components.ActionBlocking
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
[TestOf(typeof(CuffableComponent))]
|
|
|
|
|
[TestOf(typeof(HandcuffComponent))]
|
2022-06-19 20:22:28 -07:00
|
|
|
public sealed class HandCuffTest
|
2020-08-25 08:54:23 -04:00
|
|
|
{
|
2023-08-05 16:16:48 +12:00
|
|
|
[TestPrototypes]
|
2021-02-09 22:04:47 +01:00
|
|
|
private const string Prototypes = @"
|
2020-11-18 15:30:36 +01:00
|
|
|
- type: entity
|
2023-08-05 16:16:48 +12:00
|
|
|
name: HumanHandcuffDummy
|
|
|
|
|
id: HumanHandcuffDummy
|
2020-11-18 15:30:36 +01:00
|
|
|
components:
|
|
|
|
|
- type: Cuffable
|
|
|
|
|
- type: Hands
|
2024-05-31 16:26:19 -04:00
|
|
|
- type: ComplexInteraction
|
2020-11-18 15:30:36 +01:00
|
|
|
- type: Body
|
2022-10-23 00:46:28 +02:00
|
|
|
prototype: Human
|
2020-11-18 15:30:36 +01:00
|
|
|
|
|
|
|
|
- type: entity
|
|
|
|
|
name: HandcuffsDummy
|
|
|
|
|
id: HandcuffsDummy
|
|
|
|
|
components:
|
|
|
|
|
- type: Handcuff
|
|
|
|
|
";
|
2022-10-23 00:46:28 +02:00
|
|
|
|
2020-08-25 08:54:23 -04:00
|
|
|
[Test]
|
|
|
|
|
public async Task Test()
|
|
|
|
|
{
|
2023-08-25 02:56:51 +02:00
|
|
|
await using var pair = await PoolManager.GetServerClient();
|
|
|
|
|
var server = pair.Server;
|
2020-08-25 08:54:23 -04:00
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
EntityUid human;
|
|
|
|
|
EntityUid otherHuman;
|
|
|
|
|
EntityUid cuffs;
|
|
|
|
|
EntityUid secondCuffs;
|
2023-07-05 21:54:25 -07:00
|
|
|
CuffableComponent cuffed = default!;
|
|
|
|
|
HandsComponent hands = default!;
|
2020-08-25 08:54:23 -04:00
|
|
|
|
2023-06-07 21:08:52 +10:00
|
|
|
var entityManager = server.ResolveDependency<IEntityManager>();
|
|
|
|
|
var mapManager = server.ResolveDependency<IMapManager>();
|
|
|
|
|
var host = server.ResolveDependency<IServerConsoleHost>();
|
|
|
|
|
|
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-25 08:54:23 -04:00
|
|
|
{
|
2024-07-02 20:01:37 -04:00
|
|
|
var coordinates = map.MapCoords;
|
2020-08-25 08:54:23 -04:00
|
|
|
|
2023-03-13 19:34:26 -04:00
|
|
|
var cuffableSys = entityManager.System<CuffableSystem>();
|
2023-07-05 21:54:25 -07:00
|
|
|
var xformSys = entityManager.System<SharedTransformSystem>();
|
2020-08-25 08:54:23 -04:00
|
|
|
|
|
|
|
|
// Spawn the entities
|
2023-08-05 16:16:48 +12:00
|
|
|
human = entityManager.SpawnEntity("HumanHandcuffDummy", coordinates);
|
|
|
|
|
otherHuman = entityManager.SpawnEntity("HumanHandcuffDummy", coordinates);
|
2021-04-13 13:17:10 +02:00
|
|
|
cuffs = entityManager.SpawnEntity("HandcuffsDummy", coordinates);
|
|
|
|
|
secondCuffs = entityManager.SpawnEntity("HandcuffsDummy", coordinates);
|
2020-08-25 08:54:23 -04:00
|
|
|
|
2024-03-29 17:26:30 +11:00
|
|
|
var coords = xformSys.GetWorldPosition(otherHuman);
|
|
|
|
|
xformSys.SetWorldPosition(human, coords);
|
2020-08-25 08:54:23 -04:00
|
|
|
|
|
|
|
|
// Test for components existing
|
2023-07-05 21:54:25 -07:00
|
|
|
Assert.Multiple(() =>
|
|
|
|
|
{
|
|
|
|
|
Assert.That(entityManager.TryGetComponent(human, out cuffed!), $"Human has no {nameof(CuffableComponent)}");
|
|
|
|
|
Assert.That(entityManager.TryGetComponent(human, out hands!), $"Human has no {nameof(HandsComponent)}");
|
|
|
|
|
Assert.That(entityManager.TryGetComponent(human, out BodyComponent? _), $"Human has no {nameof(BodyComponent)}");
|
|
|
|
|
Assert.That(entityManager.TryGetComponent(cuffs, out HandcuffComponent? _), $"Handcuff has no {nameof(HandcuffComponent)}");
|
|
|
|
|
Assert.That(entityManager.TryGetComponent(secondCuffs, out HandcuffComponent? _), $"Second handcuffs has no {nameof(HandcuffComponent)}");
|
|
|
|
|
});
|
2020-08-25 08:54:23 -04:00
|
|
|
|
|
|
|
|
// Test to ensure cuffed players register the handcuffs
|
2023-03-13 19:34:26 -04:00
|
|
|
cuffableSys.TryAddNewCuffs(human, human, cuffs, cuffed);
|
2023-07-05 21:54:25 -07:00
|
|
|
Assert.That(cuffed.CuffedHandCount, Is.GreaterThan(0), "Handcuffing a player did not result in their hands being cuffed");
|
2020-08-25 08:54:23 -04:00
|
|
|
|
|
|
|
|
// Test to ensure a player with 4 hands will still only have 2 hands cuffed
|
2023-09-11 09:42:41 +10:00
|
|
|
AddHand(entityManager.GetNetEntity(human), host);
|
|
|
|
|
AddHand(entityManager.GetNetEntity(human), host);
|
2021-06-21 02:21:20 -07:00
|
|
|
|
2023-07-05 21:54:25 -07:00
|
|
|
Assert.Multiple(() =>
|
|
|
|
|
{
|
|
|
|
|
Assert.That(cuffed.CuffedHandCount, Is.EqualTo(2));
|
|
|
|
|
Assert.That(hands.SortedHands, Has.Count.EqualTo(4));
|
|
|
|
|
});
|
2020-08-25 08:54:23 -04:00
|
|
|
|
|
|
|
|
// Test to give a player with 4 hands 2 sets of cuffs
|
2023-03-13 19:34:26 -04:00
|
|
|
cuffableSys.TryAddNewCuffs(human, human, secondCuffs, cuffed);
|
2023-07-05 21:54:25 -07:00
|
|
|
Assert.That(cuffed.CuffedHandCount, Is.EqualTo(4), "Player doesn't have correct amount of hands cuffed");
|
2020-08-25 08:54:23 -04:00
|
|
|
});
|
|
|
|
|
|
2023-08-25 02:56:51 +02:00
|
|
|
await pair.CleanReturnAsync();
|
2020-08-25 08:54:23 -04:00
|
|
|
}
|
|
|
|
|
|
2023-09-11 09:42:41 +10:00
|
|
|
private static void AddHand(NetEntity to, IServerConsoleHost host)
|
2020-08-25 08:54:23 -04:00
|
|
|
{
|
2021-12-03 15:53:09 +01:00
|
|
|
host.ExecuteCommand(null, $"addhand {to}");
|
2020-08-25 08:54:23 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|