1
0

MovementTest.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #nullable enable
  2. using System.Numerics;
  3. using Content.IntegrationTests.Tests.Interaction;
  4. using Robust.Shared.GameObjects;
  5. namespace Content.IntegrationTests.Tests.Movement;
  6. /// <summary>
  7. /// This is a variation of <see cref="InteractionTest"/> that sets up the player with a normal human entity and a simple
  8. /// linear grid with gravity and an atmosphere. It is intended to make it easier to test interactions that involve
  9. /// walking (e.g., slipping or climbing tables).
  10. /// </summary>
  11. public abstract class MovementTest : InteractionTest
  12. {
  13. protected override string PlayerPrototype => "MobHuman";
  14. /// <summary>
  15. /// Number of tiles to add either side of the player.
  16. /// </summary>
  17. protected virtual int Tiles => 3;
  18. /// <summary>
  19. /// If true, the tiles at the ends of the grid will have a wall placed on them to avoid players moving off grid.
  20. /// </summary>
  21. protected virtual bool AddWalls => true;
  22. [SetUp]
  23. public override async Task Setup()
  24. {
  25. await base.Setup();
  26. var pCoords = SEntMan.GetCoordinates(PlayerCoords);
  27. for (var i = -Tiles; i <= Tiles; i++)
  28. {
  29. await SetTile(Plating, SEntMan.GetNetCoordinates(pCoords.Offset(new Vector2(i, 0))), MapData.Grid);
  30. }
  31. AssertGridCount(1);
  32. if (AddWalls)
  33. {
  34. await SpawnEntity("WallSolid", pCoords.Offset(new Vector2(-Tiles, 0)));
  35. await SpawnEntity("WallSolid", pCoords.Offset(new Vector2(Tiles, 0)));
  36. }
  37. await AddGravity();
  38. await AddAtmosphere();
  39. }
  40. /// <summary>
  41. /// Get the relative horizontal between two entities. Defaults to using the target & player entity.
  42. /// </summary>
  43. protected float Delta(NetEntity? target = null, NetEntity? other = null)
  44. {
  45. target ??= Target;
  46. if (target == null)
  47. {
  48. Assert.Fail("No target specified");
  49. return 0;
  50. }
  51. var delta = Transform.GetWorldPosition(SEntMan.GetEntity(target.Value)) - Transform.GetWorldPosition(SEntMan.GetEntity(other ?? Player));
  52. return delta.X;
  53. }
  54. }