Add chasm integration tests (#40286)
* add chasm integration test * fix assert * fix * more fixes * review
This commit is contained in:
@@ -10,6 +10,7 @@ using Content.Server.Construction.Components;
|
||||
using Content.Server.Gravity;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Shared.Atmos;
|
||||
using Content.Shared.CombatMode;
|
||||
using Content.Shared.Construction.Prototypes;
|
||||
using Content.Shared.Gravity;
|
||||
using Content.Shared.Item;
|
||||
@@ -85,7 +86,7 @@ public abstract partial class InteractionTest
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Spawn an entity entity and set it as the target.
|
||||
/// Spawn an entity at the target coordinates and set it as the target.
|
||||
/// </summary>
|
||||
[MemberNotNull(nameof(Target), nameof(STarget), nameof(CTarget))]
|
||||
#pragma warning disable CS8774 // Member must have a non-null value when exiting.
|
||||
@@ -103,6 +104,22 @@ public abstract partial class InteractionTest
|
||||
}
|
||||
#pragma warning restore CS8774 // Member must have a non-null value when exiting.
|
||||
|
||||
/// <summary>
|
||||
/// Spawn an entity entity at the target coordinates without setting it as the target.
|
||||
/// </summary>
|
||||
protected async Task<NetEntity> Spawn(string prototype)
|
||||
{
|
||||
var entity = NetEntity.Invalid;
|
||||
await Server.WaitPost(() =>
|
||||
{
|
||||
entity = SEntMan.GetNetEntity(SEntMan.SpawnAtPosition(prototype, SEntMan.GetCoordinates(TargetCoords)));
|
||||
});
|
||||
|
||||
await RunTicks(5);
|
||||
AssertPrototype(prototype, entity);
|
||||
return entity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Spawn an entity in preparation for deconstruction
|
||||
/// </summary>
|
||||
@@ -386,6 +403,119 @@ public abstract partial class InteractionTest
|
||||
|
||||
#endregion
|
||||
|
||||
# region Combat
|
||||
/// <summary>
|
||||
/// Returns if the player is currently in combat mode.
|
||||
/// </summary>
|
||||
protected bool IsInCombatMode()
|
||||
{
|
||||
if (!SEntMan.TryGetComponent(SPlayer, out CombatModeComponent? combat))
|
||||
{
|
||||
Assert.Fail($"Entity {SEntMan.ToPrettyString(SPlayer)} does not have a CombatModeComponent");
|
||||
return false;
|
||||
}
|
||||
|
||||
return combat.IsInCombatMode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the combat mode for the player.
|
||||
/// </summary>
|
||||
protected async Task SetCombatMode(bool enabled)
|
||||
{
|
||||
if (!SEntMan.TryGetComponent(SPlayer, out CombatModeComponent? combat))
|
||||
{
|
||||
Assert.Fail($"Entity {SEntMan.ToPrettyString(SPlayer)} does not have a CombatModeComponent");
|
||||
return;
|
||||
}
|
||||
|
||||
await Server.WaitPost(() => SCombatMode.SetInCombatMode(SPlayer, enabled, combat));
|
||||
await RunTicks(1);
|
||||
|
||||
Assert.That(combat.IsInCombatMode, Is.EqualTo(enabled), $"Player could not set combate mode to {enabled}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Make the player shoot with their currently held gun.
|
||||
/// The player needs to be able to enter combat mode for this.
|
||||
/// This does not pass a target entity into the GunSystem, meaning that targets that
|
||||
/// need to be aimed at directly won't be hit.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Guns have a cooldown when picking them up.
|
||||
/// So make sure to wait a little after spawning a gun in the player's hand or this will fail.
|
||||
/// </remarks>
|
||||
/// <param name="target">The target coordinates to shoot at. Defaults to the current <see cref="TargetCoords"/>.</param>
|
||||
/// <param name="assert">If true this method will assert that the gun was successfully fired.</param>
|
||||
protected async Task AttemptShoot(NetCoordinates? target = null, bool assert = true)
|
||||
{
|
||||
var actualTarget = SEntMan.GetCoordinates(target ?? TargetCoords);
|
||||
|
||||
if (!SEntMan.TryGetComponent(SPlayer, out CombatModeComponent? combat))
|
||||
{
|
||||
Assert.Fail($"Entity {SEntMan.ToPrettyString(SPlayer)} does not have a CombatModeComponent");
|
||||
return;
|
||||
}
|
||||
|
||||
// Enter combat mode before shooting.
|
||||
var wasInCombatMode = IsInCombatMode();
|
||||
await SetCombatMode(true);
|
||||
|
||||
Assert.That(SGun.TryGetGun(SPlayer, out var gunUid, out var gunComp), "Player was not holding a gun!");
|
||||
|
||||
await Server.WaitAssertion(() =>
|
||||
{
|
||||
var success = SGun.AttemptShoot(SPlayer, gunUid, gunComp!, actualTarget);
|
||||
if (assert)
|
||||
Assert.That(success, "Gun failed to shoot.");
|
||||
});
|
||||
await RunTicks(1);
|
||||
|
||||
// If the player was not in combat mode before then disable it again.
|
||||
await SetCombatMode(wasInCombatMode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Make the player shoot with their currently held gun.
|
||||
/// The player needs to be able to enter combat mode for this.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Guns have a cooldown when picking them up.
|
||||
/// So make sure to wait a little after spawning a gun in the player's hand or this will fail.
|
||||
/// </remarks>
|
||||
/// <param name="target">The target entity to shoot at. Defaults to the current <see cref="Target"/> entity.</param>
|
||||
/// <param name="assert">If true this method will assert that the gun was successfully fired.</param>
|
||||
protected async Task AttemptShoot(NetEntity? target = null, bool assert = true)
|
||||
{
|
||||
var actualTarget = target ?? Target;
|
||||
Assert.That(actualTarget, Is.Not.Null, "No target to shoot at!");
|
||||
|
||||
if (!SEntMan.TryGetComponent(SPlayer, out CombatModeComponent? combat))
|
||||
{
|
||||
Assert.Fail($"Entity {SEntMan.ToPrettyString(SPlayer)} does not have a CombatModeComponent");
|
||||
return;
|
||||
}
|
||||
|
||||
// Enter combat mode before shooting.
|
||||
var wasInCombatMode = IsInCombatMode();
|
||||
await SetCombatMode(true);
|
||||
|
||||
Assert.That(SGun.TryGetGun(SPlayer, out var gunUid, out var gunComp), "Player was not holding a gun!");
|
||||
|
||||
await Server.WaitAssertion(() =>
|
||||
{
|
||||
var success = SGun.AttemptShoot(SPlayer, gunUid, gunComp!, Position(actualTarget!.Value), ToServer(actualTarget));
|
||||
if (assert)
|
||||
Assert.That(success, "Gun failed to shoot.");
|
||||
});
|
||||
await RunTicks(1);
|
||||
|
||||
// If the player was not in combat mode before then disable it again.
|
||||
await SetCombatMode(wasInCombatMode);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Wait for any currently active DoAfters to finish.
|
||||
/// </summary>
|
||||
@@ -746,6 +876,18 @@ public abstract partial class InteractionTest
|
||||
return SEntMan.GetComponent<T>(ToServer(target!.Value));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convenience method to check if the target has a component on the server.
|
||||
/// </summary>
|
||||
protected bool HasComp<T>(NetEntity? target = null) where T : IComponent
|
||||
{
|
||||
target ??= Target;
|
||||
if (target == null)
|
||||
Assert.Fail("No target specified");
|
||||
|
||||
return SEntMan.HasComponent<T>(ToServer(target));
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Comp{T}"/>
|
||||
protected bool TryComp<T>(NetEntity? target, [NotNullWhen(true)] out T? comp) where T : IComponent
|
||||
{
|
||||
@@ -1013,7 +1155,7 @@ public abstract partial class InteractionTest
|
||||
}
|
||||
|
||||
Assert.That(control.GetType().IsAssignableTo(typeof(TControl)));
|
||||
return (TControl) control;
|
||||
return (TControl)control;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1177,8 +1319,8 @@ public abstract partial class InteractionTest
|
||||
{
|
||||
var atmosSystem = SEntMan.System<AtmosphereSystem>();
|
||||
var moles = new float[Atmospherics.AdjustedNumberOfGases];
|
||||
moles[(int) Gas.Oxygen] = 21.824779f;
|
||||
moles[(int) Gas.Nitrogen] = 82.10312f;
|
||||
moles[(int)Gas.Oxygen] = 21.824779f;
|
||||
moles[(int)Gas.Nitrogen] = 82.10312f;
|
||||
atmosSystem.SetMapAtmosphere(target, false, new GasMixture(moles, Atmospherics.T20C));
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user