Files
crystall-punk-14/Content.IntegrationTests/Tests/Payload/ModularGrenadeTests.cs

76 lines
2.5 KiB
C#
Raw Normal View History

2023-04-15 07:41:25 +12:00
using Content.IntegrationTests.Tests.Interaction;
2025-08-03 21:20:37 +02:00
using Content.Shared.Trigger.Components;
using Content.Shared.Trigger.Systems;
2023-04-15 07:41:25 +12:00
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
namespace Content.IntegrationTests.Tests.Payload;
public sealed class ModularGrenadeTests : InteractionTest
{
public const string Trigger = "TimerTrigger";
public const string Payload = "ExplosivePayload";
/// <summary>
/// Test that a modular grenade can be fully crafted and detonated.
/// </summary>
[Test]
public async Task AssembleAndDetonateGrenade()
{
await PlaceInHands(Steel, 5);
await CraftItem("ModularGrenadeRecipe");
Target = SEntMan.GetNetEntity(await FindEntity("ModularGrenade"));
2023-04-15 07:41:25 +12:00
await Drop();
2024-06-04 09:05:51 +12:00
await InteractUsing(Cable);
2023-04-15 07:41:25 +12:00
// Insert & remove trigger
2025-08-03 21:20:37 +02:00
AssertComp<TimerTriggerComponent>(false);
2024-06-04 09:05:51 +12:00
await InteractUsing(Trigger);
2025-08-03 21:20:37 +02:00
AssertComp<TimerTriggerComponent>();
2023-04-15 07:41:25 +12:00
await FindEntity(Trigger, LookupFlags.Uncontained, shouldSucceed: false);
2024-06-04 09:05:51 +12:00
await InteractUsing(Pry);
2025-08-03 21:20:37 +02:00
AssertComp<TimerTriggerComponent>(false);
2023-04-15 07:41:25 +12:00
// Trigger was dropped to floor, not deleted.
await FindEntity(Trigger, LookupFlags.Uncontained);
// Re-insert
2024-06-04 09:05:51 +12:00
await InteractUsing(Trigger);
2025-08-03 21:20:37 +02:00
AssertComp<TimerTriggerComponent>();
2023-04-15 07:41:25 +12:00
// Insert & remove payload.
2024-06-04 09:05:51 +12:00
await InteractUsing(Payload);
2023-04-15 07:41:25 +12:00
await FindEntity(Payload, LookupFlags.Uncontained, shouldSucceed: false);
2024-06-04 09:05:51 +12:00
await InteractUsing(Pry);
2023-04-15 07:41:25 +12:00
var ent = await FindEntity(Payload, LookupFlags.Uncontained);
await Delete(ent);
// successfully insert a second time
2024-06-04 09:05:51 +12:00
await InteractUsing(Payload);
2023-04-15 07:41:25 +12:00
ent = await FindEntity(Payload);
var sys = SEntMan.System<SharedContainerSystem>();
Assert.That(sys.IsEntityInContainer(ent));
// Activate trigger.
await Pickup();
AssertComp<ActiveTimerTriggerComponent>(false);
await UseInHand();
2025-08-03 21:20:37 +02:00
AssertComp<ActiveTimerTriggerComponent>(true);
2023-04-15 07:41:25 +12:00
// So uhhh grenades in hands don't destroy themselves when exploding. Maybe that will be fixed eventually.
await Drop();
// Wait until grenade explodes
2025-08-03 21:20:37 +02:00
var triggerSys = SEntMan.System<TriggerSystem>();
while (Target != null && triggerSys.GetRemainingTime(SEntMan.GetEntity(Target.Value))?.TotalSeconds >= 0.0)
2023-04-15 07:41:25 +12:00
{
await RunTicks(10);
}
// Grenade has exploded.
await RunTicks(30);
2023-04-15 07:41:25 +12:00
AssertDeleted();
}
}