ClimbingTest.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #nullable enable
  2. using Content.IntegrationTests.Tests.Interaction;
  3. using Content.IntegrationTests.Tests.Movement;
  4. using Robust.Shared.Maths;
  5. using ClimbingComponent = Content.Shared.Climbing.Components.ClimbingComponent;
  6. using ClimbSystem = Content.Shared.Climbing.Systems.ClimbSystem;
  7. namespace Content.IntegrationTests.Tests.Climbing;
  8. public sealed class ClimbingTest : MovementTest
  9. {
  10. [Test]
  11. public async Task ClimbTableTest()
  12. {
  13. // Spawn a table to the right of the player.
  14. await SpawnTarget("Table");
  15. Assert.That(Delta(), Is.GreaterThan(0));
  16. // Player is not initially climbing anything.
  17. var comp = Comp<ClimbingComponent>(Player);
  18. Assert.Multiple(() =>
  19. {
  20. Assert.That(comp.IsClimbing, Is.False);
  21. Assert.That(comp.DisabledFixtureMasks, Has.Count.EqualTo(0));
  22. });
  23. // Attempt (and fail) to walk past the table.
  24. await Move(DirectionFlag.East, 1f);
  25. Assert.That(Delta(), Is.GreaterThan(0));
  26. // Try to start climbing
  27. var sys = SEntMan.System<ClimbSystem>();
  28. await Server.WaitPost(() => sys.TryClimb(SEntMan.GetEntity(Player), SEntMan.GetEntity(Player), SEntMan.GetEntity(Target.Value), out _));
  29. await AwaitDoAfters();
  30. // Player should now be climbing
  31. Assert.Multiple(() =>
  32. {
  33. Assert.That(comp.IsClimbing, Is.True);
  34. Assert.That(comp.DisabledFixtureMasks, Has.Count.GreaterThan(0));
  35. });
  36. // Can now walk over the table.
  37. await Move(DirectionFlag.East, 1f);
  38. Assert.Multiple(() =>
  39. {
  40. Assert.That(Delta(), Is.LessThan(0));
  41. // After walking away from the table, player should have stopped climbing.
  42. Assert.That(comp.IsClimbing, Is.False);
  43. Assert.That(comp.DisabledFixtureMasks, Has.Count.EqualTo(0));
  44. });
  45. // Try to walk back to the other side (and fail).
  46. await Move(DirectionFlag.West, 1f);
  47. Assert.That(Delta(), Is.LessThan(0));
  48. // Start climbing
  49. await Server.WaitPost(() => sys.TryClimb(SEntMan.GetEntity(Player), SEntMan.GetEntity(Player), SEntMan.GetEntity(Target.Value), out _));
  50. await AwaitDoAfters();
  51. Assert.Multiple(() =>
  52. {
  53. Assert.That(comp.IsClimbing, Is.True);
  54. Assert.That(comp.DisabledFixtureMasks, Has.Count.GreaterThan(0));
  55. });
  56. // Walk past table and stop climbing again.
  57. await Move(DirectionFlag.West, 1f);
  58. Assert.Multiple(() =>
  59. {
  60. Assert.That(Delta(), Is.GreaterThan(0));
  61. Assert.That(comp.IsClimbing, Is.False);
  62. Assert.That(comp.DisabledFixtureMasks, Has.Count.EqualTo(0));
  63. });
  64. }
  65. }