1
0

HandCuffTest.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #nullable enable
  2. using Content.Server.Cuffs;
  3. using Content.Shared.Body.Components;
  4. using Content.Shared.Cuffs.Components;
  5. using Content.Shared.Hands.Components;
  6. using Robust.Server.Console;
  7. using Robust.Shared.GameObjects;
  8. using Robust.Shared.Map;
  9. namespace Content.IntegrationTests.Tests.GameObjects.Components.ActionBlocking
  10. {
  11. [TestFixture]
  12. [TestOf(typeof(CuffableComponent))]
  13. [TestOf(typeof(HandcuffComponent))]
  14. public sealed class HandCuffTest
  15. {
  16. [TestPrototypes]
  17. private const string Prototypes = @"
  18. - type: entity
  19. name: HumanHandcuffDummy
  20. id: HumanHandcuffDummy
  21. components:
  22. - type: Cuffable
  23. - type: Hands
  24. - type: ComplexInteraction
  25. - type: Body
  26. prototype: Human
  27. - type: entity
  28. name: HandcuffsDummy
  29. id: HandcuffsDummy
  30. components:
  31. - type: Handcuff
  32. ";
  33. [Test]
  34. public async Task Test()
  35. {
  36. await using var pair = await PoolManager.GetServerClient();
  37. var server = pair.Server;
  38. EntityUid human;
  39. EntityUid otherHuman;
  40. EntityUid cuffs;
  41. EntityUid secondCuffs;
  42. CuffableComponent cuffed = default!;
  43. HandsComponent hands = default!;
  44. var entityManager = server.ResolveDependency<IEntityManager>();
  45. var mapManager = server.ResolveDependency<IMapManager>();
  46. var host = server.ResolveDependency<IServerConsoleHost>();
  47. var map = await pair.CreateTestMap();
  48. await server.WaitAssertion(() =>
  49. {
  50. var coordinates = map.MapCoords;
  51. var cuffableSys = entityManager.System<CuffableSystem>();
  52. var xformSys = entityManager.System<SharedTransformSystem>();
  53. // Spawn the entities
  54. human = entityManager.SpawnEntity("HumanHandcuffDummy", coordinates);
  55. otherHuman = entityManager.SpawnEntity("HumanHandcuffDummy", coordinates);
  56. cuffs = entityManager.SpawnEntity("HandcuffsDummy", coordinates);
  57. secondCuffs = entityManager.SpawnEntity("HandcuffsDummy", coordinates);
  58. var coords = xformSys.GetWorldPosition(otherHuman);
  59. xformSys.SetWorldPosition(human, coords);
  60. // Test for components existing
  61. Assert.Multiple(() =>
  62. {
  63. Assert.That(entityManager.TryGetComponent(human, out cuffed!), $"Human has no {nameof(CuffableComponent)}");
  64. Assert.That(entityManager.TryGetComponent(human, out hands!), $"Human has no {nameof(HandsComponent)}");
  65. Assert.That(entityManager.TryGetComponent(human, out BodyComponent? _), $"Human has no {nameof(BodyComponent)}");
  66. Assert.That(entityManager.TryGetComponent(cuffs, out HandcuffComponent? _), $"Handcuff has no {nameof(HandcuffComponent)}");
  67. Assert.That(entityManager.TryGetComponent(secondCuffs, out HandcuffComponent? _), $"Second handcuffs has no {nameof(HandcuffComponent)}");
  68. });
  69. // Test to ensure cuffed players register the handcuffs
  70. cuffableSys.TryAddNewCuffs(human, human, cuffs, cuffed);
  71. Assert.That(cuffed.CuffedHandCount, Is.GreaterThan(0), "Handcuffing a player did not result in their hands being cuffed");
  72. // Test to ensure a player with 4 hands will still only have 2 hands cuffed
  73. AddHand(entityManager.GetNetEntity(human), host);
  74. AddHand(entityManager.GetNetEntity(human), host);
  75. Assert.Multiple(() =>
  76. {
  77. Assert.That(cuffed.CuffedHandCount, Is.EqualTo(2));
  78. Assert.That(hands.SortedHands, Has.Count.EqualTo(4));
  79. });
  80. // Test to give a player with 4 hands 2 sets of cuffs
  81. cuffableSys.TryAddNewCuffs(human, human, secondCuffs, cuffed);
  82. Assert.That(cuffed.CuffedHandCount, Is.EqualTo(4), "Player doesn't have correct amount of hands cuffed");
  83. });
  84. await pair.CleanReturnAsync();
  85. }
  86. private static void AddHand(NetEntity to, IServerConsoleHost host)
  87. {
  88. host.ExecuteCommand(null, $"addhand {to}");
  89. }
  90. }
  91. }