LegTest.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System.Numerics;
  2. using Content.Server.Body.Systems;
  3. using Content.Shared.Body.Components;
  4. using Content.Shared.Body.Part;
  5. using Content.Shared.Rotation;
  6. using Robust.Shared.GameObjects;
  7. using Robust.Shared.Map;
  8. namespace Content.IntegrationTests.Tests.Body
  9. {
  10. [TestFixture]
  11. [TestOf(typeof(BodyPartComponent))]
  12. [TestOf(typeof(BodyComponent))]
  13. public sealed class LegTest
  14. {
  15. [TestPrototypes]
  16. private const string Prototypes = @"
  17. - type: entity
  18. name: HumanBodyAndAppearanceDummy
  19. id: HumanBodyAndAppearanceDummy
  20. components:
  21. - type: Appearance
  22. - type: Body
  23. prototype: Human
  24. - type: StandingState
  25. ";
  26. [Test]
  27. public async Task RemoveLegsFallTest()
  28. {
  29. await using var pair = await PoolManager.GetServerClient();
  30. var server = pair.Server;
  31. EntityUid human = default!;
  32. AppearanceComponent appearance = null;
  33. var entityManager = server.ResolveDependency<IEntityManager>();
  34. var mapManager = server.ResolveDependency<IMapManager>();
  35. var appearanceSystem = entityManager.System<SharedAppearanceSystem>();
  36. var xformSystem = entityManager.System<SharedTransformSystem>();
  37. var map = await pair.CreateTestMap();
  38. await server.WaitAssertion(() =>
  39. {
  40. BodyComponent body = null;
  41. human = entityManager.SpawnEntity("HumanBodyAndAppearanceDummy",
  42. new MapCoordinates(Vector2.Zero, map.MapId));
  43. Assert.Multiple(() =>
  44. {
  45. Assert.That(entityManager.TryGetComponent(human, out body));
  46. Assert.That(entityManager.TryGetComponent(human, out appearance));
  47. });
  48. Assert.That(!appearanceSystem.TryGetData(human, RotationVisuals.RotationState, out RotationState _, appearance));
  49. var bodySystem = entityManager.System<BodySystem>();
  50. var legs = bodySystem.GetBodyChildrenOfType(human, BodyPartType.Leg, body);
  51. foreach (var leg in legs)
  52. {
  53. xformSystem.DetachEntity(leg.Id, entityManager.GetComponent<TransformComponent>(leg.Id));
  54. }
  55. });
  56. await server.WaitAssertion(() =>
  57. {
  58. #pragma warning disable NUnit2045
  59. // Interdependent assertions.
  60. Assert.That(appearanceSystem.TryGetData(human, RotationVisuals.RotationState, out RotationState state, appearance));
  61. Assert.That(state, Is.EqualTo(RotationState.Horizontal));
  62. #pragma warning restore NUnit2045
  63. });
  64. await pair.CleanReturnAsync();
  65. }
  66. }
  67. }