DoAfterCancellationTests.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. using System.Linq;
  2. using Content.IntegrationTests.Tests.Construction.Interaction;
  3. using Content.IntegrationTests.Tests.Interaction;
  4. using Content.IntegrationTests.Tests.Weldable;
  5. using Content.Shared.Tools.Components;
  6. namespace Content.IntegrationTests.Tests.DoAfter;
  7. /// <summary>
  8. /// This class has various tests that verify that cancelled DoAfters do not complete construction or other interactions.
  9. /// It also checks that cancellation of a DoAfter does not block future DoAfters.
  10. /// </summary>
  11. public sealed class DoAfterCancellationTests : InteractionTest
  12. {
  13. [Test]
  14. public async Task CancelWallDeconstruct()
  15. {
  16. await StartDeconstruction(WallConstruction.WallSolid);
  17. await InteractUsing(Weld, awaitDoAfters: false);
  18. // Failed do-after has no effect
  19. await CancelDoAfters();
  20. AssertPrototype(WallConstruction.WallSolid);
  21. // Second attempt works fine
  22. await InteractUsing(Weld);
  23. AssertPrototype(WallConstruction.Girder);
  24. // Repeat for wrenching interaction
  25. AssertAnchored();
  26. await InteractUsing(Wrench, awaitDoAfters: false);
  27. await CancelDoAfters();
  28. AssertAnchored();
  29. AssertPrototype(WallConstruction.Girder);
  30. await InteractUsing(Wrench);
  31. AssertAnchored(false);
  32. // Repeat for screwdriver interaction.
  33. AssertExists();
  34. await InteractUsing(Screw, awaitDoAfters: false);
  35. await CancelDoAfters();
  36. AssertExists();
  37. await InteractUsing(Screw);
  38. AssertDeleted();
  39. }
  40. [Test]
  41. public async Task CancelWallConstruct()
  42. {
  43. await StartConstruction(WallConstruction.Wall);
  44. await InteractUsing(Steel, 5, awaitDoAfters: false);
  45. await CancelDoAfters();
  46. await InteractUsing(Steel, 5);
  47. ClientAssertPrototype(WallConstruction.Girder, Target);
  48. await InteractUsing(Steel, 5, awaitDoAfters: false);
  49. await CancelDoAfters();
  50. AssertPrototype(WallConstruction.Girder);
  51. await InteractUsing(Steel, 5);
  52. AssertPrototype(WallConstruction.WallSolid);
  53. }
  54. [Test]
  55. public async Task CancelTilePry()
  56. {
  57. await SetTile(Floor);
  58. await InteractUsing(Pry, awaitDoAfters: false);
  59. await CancelDoAfters();
  60. await AssertTile(Floor);
  61. await InteractUsing(Pry);
  62. await AssertTile(Plating);
  63. }
  64. [Test]
  65. public async Task CancelRepeatedTilePry()
  66. {
  67. await SetTile(Floor);
  68. await InteractUsing(Pry, awaitDoAfters: false);
  69. await RunTicks(1);
  70. Assert.That(ActiveDoAfters.Count(), Is.EqualTo(1));
  71. await AssertTile(Floor);
  72. // Second DoAfter cancels the first.
  73. await Server.WaitPost(() => InteractSys.UserInteraction(SEntMan.GetEntity(Player), SEntMan.GetCoordinates(TargetCoords), SEntMan.GetEntity(Target)));
  74. Assert.That(ActiveDoAfters.Count(), Is.EqualTo(0));
  75. await AssertTile(Floor);
  76. // Third do after will work fine
  77. await InteractUsing(Pry);
  78. Assert.That(ActiveDoAfters.Count(), Is.EqualTo(0));
  79. await AssertTile(Plating);
  80. }
  81. [Test]
  82. public async Task CancelRepeatedWeld()
  83. {
  84. await SpawnTarget(WeldableTests.Locker);
  85. var comp = Comp<WeldableComponent>();
  86. Assert.That(comp.IsWelded, Is.False);
  87. await InteractUsing(Weld, awaitDoAfters: false);
  88. await RunTicks(1);
  89. Assert.Multiple(() =>
  90. {
  91. Assert.That(ActiveDoAfters.Count(), Is.EqualTo(1));
  92. Assert.That(comp.IsWelded, Is.False);
  93. });
  94. // Second DoAfter cancels the first.
  95. // Not using helper, because it runs too many ticks & causes the do-after to finish.
  96. await Server.WaitPost(() => InteractSys.UserInteraction(SEntMan.GetEntity(Player), SEntMan.GetCoordinates(TargetCoords), SEntMan.GetEntity(Target)));
  97. Assert.Multiple(() =>
  98. {
  99. Assert.That(ActiveDoAfters.Count(), Is.EqualTo(0));
  100. Assert.That(comp.IsWelded, Is.False);
  101. });
  102. // Third do after will work fine
  103. await InteractUsing(Weld);
  104. Assert.Multiple(() =>
  105. {
  106. Assert.That(ActiveDoAfters.Count(), Is.EqualTo(0));
  107. Assert.That(comp.IsWelded, Is.True);
  108. });
  109. // Repeat test for un-welding
  110. await InteractUsing(Weld, awaitDoAfters: false);
  111. await RunTicks(1);
  112. Assert.Multiple(() =>
  113. {
  114. Assert.That(ActiveDoAfters.Count(), Is.EqualTo(1));
  115. Assert.That(comp.IsWelded, Is.True);
  116. });
  117. await Server.WaitPost(() => InteractSys.UserInteraction(SEntMan.GetEntity(Player), SEntMan.GetCoordinates(TargetCoords), SEntMan.GetEntity(Target)));
  118. Assert.Multiple(() =>
  119. {
  120. Assert.That(ActiveDoAfters.Count(), Is.EqualTo(0));
  121. Assert.That(comp.IsWelded, Is.True);
  122. });
  123. await InteractUsing(Weld);
  124. Assert.Multiple(() =>
  125. {
  126. Assert.That(ActiveDoAfters.Count(), Is.EqualTo(0));
  127. Assert.That(comp.IsWelded, Is.False);
  128. });
  129. }
  130. }