1
0

PullingTest.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #nullable enable
  2. using Content.Shared.Alert;
  3. using Content.Shared.Input;
  4. using Content.Shared.Movement.Pulling.Components;
  5. using Robust.Shared.Maths;
  6. namespace Content.IntegrationTests.Tests.Movement;
  7. public sealed class PullingTest : MovementTest
  8. {
  9. protected override int Tiles => 4;
  10. [Test]
  11. public async Task PullTest()
  12. {
  13. var cAlert = Client.System<AlertsSystem>();
  14. var sAlert = Server.System<AlertsSystem>();
  15. await SpawnTarget("MobHuman");
  16. var puller = Comp<PullerComponent>(Player);
  17. var pullable = Comp<PullableComponent>(Target);
  18. // Player is initially to the left of the target and not pulling anything
  19. Assert.That(Delta(), Is.InRange(0.9f, 1.1f));
  20. Assert.That(puller.Pulling, Is.Null);
  21. Assert.That(pullable.Puller, Is.Null);
  22. Assert.That(pullable.BeingPulled, Is.False);
  23. Assert.That(cAlert.IsShowingAlert(CPlayer, puller.PullingAlert), Is.False);
  24. Assert.That(sAlert.IsShowingAlert(SPlayer, puller.PullingAlert), Is.False);
  25. // Start pulling
  26. await PressKey(ContentKeyFunctions.TryPullObject);
  27. await RunTicks(5);
  28. Assert.That(puller.Pulling, Is.EqualTo(STarget));
  29. Assert.That(pullable.Puller, Is.EqualTo(SPlayer));
  30. Assert.That(pullable.BeingPulled, Is.True);
  31. Assert.That(cAlert.IsShowingAlert(CPlayer, puller.PullingAlert), Is.True);
  32. Assert.That(sAlert.IsShowingAlert(SPlayer, puller.PullingAlert), Is.True);
  33. // Move to the left and check that the target moves with the player and is still being pulled.
  34. await Move(DirectionFlag.West, 1);
  35. Assert.That(Delta(), Is.InRange(0.9f, 1.3f));
  36. Assert.That(puller.Pulling, Is.EqualTo(STarget));
  37. Assert.That(pullable.Puller, Is.EqualTo(SPlayer));
  38. Assert.That(pullable.BeingPulled, Is.True);
  39. Assert.That(cAlert.IsShowingAlert(CPlayer, puller.PullingAlert), Is.True);
  40. Assert.That(sAlert.IsShowingAlert(SPlayer, puller.PullingAlert), Is.True);
  41. // Move in the other direction
  42. await Move(DirectionFlag.East, 2);
  43. Assert.That(Delta(), Is.InRange(-1.3f, -0.9f));
  44. Assert.That(puller.Pulling, Is.EqualTo(STarget));
  45. Assert.That(pullable.Puller, Is.EqualTo(SPlayer));
  46. Assert.That(pullable.BeingPulled, Is.True);
  47. Assert.That(cAlert.IsShowingAlert(CPlayer, puller.PullingAlert), Is.True);
  48. Assert.That(sAlert.IsShowingAlert(SPlayer, puller.PullingAlert), Is.True);
  49. // Stop pulling
  50. await PressKey(ContentKeyFunctions.ReleasePulledObject);
  51. await RunTicks(5);
  52. Assert.That(Delta(), Is.InRange(-1.3f, -0.9f));
  53. Assert.That(puller.Pulling, Is.Null);
  54. Assert.That(pullable.Puller, Is.Null);
  55. Assert.That(pullable.BeingPulled, Is.False);
  56. Assert.That(cAlert.IsShowingAlert(CPlayer, puller.PullingAlert), Is.False);
  57. Assert.That(sAlert.IsShowingAlert(SPlayer, puller.PullingAlert), Is.False);
  58. // Move back to the left and ensure the target is no longer following us.
  59. await Move(DirectionFlag.West, 2);
  60. Assert.That(Delta(), Is.GreaterThan(2f));
  61. }
  62. }