1
0

ItemThrowingTest.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using Content.IntegrationTests.Tests.Interaction;
  2. using Content.Shared.Damage.Components;
  3. using Content.Shared.Throwing;
  4. using Robust.Server.GameObjects;
  5. using Robust.Shared.Physics.Components;
  6. namespace Content.IntegrationTests.Tests.Physics;
  7. public sealed class ItemThrowingTest : InteractionTest
  8. {
  9. /// <summary>
  10. /// Check that an egg breaks when thrown at a wall.
  11. /// </summary>
  12. [Test]
  13. [TestOf(typeof(ThrownItemComponent))]
  14. [TestOf(typeof(DamageOnHighSpeedImpactComponent))]
  15. public async Task TestThrownEggBreaks()
  16. {
  17. // Setup entities
  18. var egg = await PlaceInHands("FoodEgg");
  19. await SpawnTarget("WallSolid");
  20. await RunTicks(5);
  21. AssertExists(egg);
  22. // Currently not a "thrown" item.
  23. AssertComp<ThrownItemComponent>(hasComp: false, egg);
  24. Assert.That(Comp<PhysicsComponent>(egg).BodyStatus, Is.Not.EqualTo(BodyStatus.InAir));
  25. // Throw it.
  26. await ThrowItem();
  27. await RunTicks(1);
  28. AssertExists(egg);
  29. AssertComp<ThrownItemComponent>(hasComp: true, egg);
  30. Assert.That(Comp<PhysicsComponent>(egg).BodyStatus, Is.EqualTo(BodyStatus.InAir));
  31. // Splat
  32. await RunTicks(30);
  33. AssertDeleted(egg);
  34. }
  35. /// <summary>
  36. /// Check that an egg thrown into space continues to be an egg.
  37. /// I.e., verify that the deletions that happen in the other two tests aren't coincidental.
  38. /// </summary>
  39. [Test]
  40. //[TestOf(typeof(Egg))]
  41. public async Task TestEggIsEgg()
  42. {
  43. // Setup entities
  44. var egg = await PlaceInHands("FoodEgg");
  45. await RunTicks(5);
  46. AssertExists(egg);
  47. // Currently not a "thrown" item.
  48. AssertComp<ThrownItemComponent>(hasComp: false, egg);
  49. Assert.That(Comp<PhysicsComponent>(egg).BodyStatus, Is.Not.EqualTo(BodyStatus.InAir));
  50. // Throw it
  51. await ThrowItem();
  52. await RunTicks(5);
  53. AssertExists(egg);
  54. AssertComp<ThrownItemComponent>(hasComp: true, egg);
  55. Assert.That(Comp<PhysicsComponent>(egg).BodyStatus, Is.EqualTo(BodyStatus.InAir));
  56. // Wait a while
  57. await RunTicks(60);
  58. // Egg is egg
  59. AssertExists(egg);
  60. AssertPrototype("FoodEgg", egg);
  61. AssertComp<ThrownItemComponent>(hasComp: false, egg);
  62. Assert.That(Comp<PhysicsComponent>(egg).BodyStatus, Is.Not.EqualTo(BodyStatus.InAir));
  63. }
  64. /// <summary>
  65. /// Check that a physics can handle deleting a thrown entity. As to why this exists, see
  66. /// https://github.com/space-wizards/RobustToolbox/pull/4746
  67. /// </summary>
  68. [Test]
  69. [TestOf(typeof(ThrownItemComponent))]
  70. [TestOf(typeof(PhysicsComponent))]
  71. public async Task TestDeleteThrownItem()
  72. {
  73. // Setup entities
  74. var pen = await PlaceInHands("Pen");
  75. var physics = Comp<PhysicsComponent>(pen);
  76. await RunTicks(5);
  77. AssertExists(pen);
  78. // Currently not a "thrown" item.
  79. AssertComp<ThrownItemComponent>(hasComp: false, pen);
  80. Assert.That(physics.BodyStatus, Is.Not.EqualTo(BodyStatus.InAir));
  81. // Throw it
  82. await ThrowItem();
  83. await RunTicks(5);
  84. AssertExists(pen);
  85. AssertComp<ThrownItemComponent>(hasComp: true, pen);
  86. Assert.That(physics.BodyStatus, Is.EqualTo(BodyStatus.InAir));
  87. Assert.That(physics.CanCollide);
  88. // Attempt to make it sleep mid-air. This happens automatically due to the sleep timer, but we just do it manually.
  89. await Server.WaitPost(() => Server.System<PhysicsSystem>().SetAwake((ToServer(pen), physics), false));
  90. // Then try and delete it
  91. await Delete(pen);
  92. await RunTicks(5);
  93. AssertDeleted(pen);
  94. }
  95. }