Files
Delta-v/Content.IntegrationTests/Tests/GameRules/FailAndStartPresetTest.cs
Moony 6656adc083 Gametest Part 2: Preliminary refactor every test to use GameTest as the framework. (#43207)
* Pass 1.

* i'm FREE

* Prevent hangups.

* okay fine here's an attribute for settings, will polish later and prolly remove the overridable thing.

* sigh.

* fix singular trigger bug so LatheTest doesn't flake.

* Remove SystemAttribute usage.

* Poke

* I used the shotgun. You know why? Cause the shot gun doesn’t miss, and unlike the shitty hybrid taser it stops a criminal in their tracks in two hits. Bang, bang, and they’re fucking done. I use four shots just to make damn sure. Because, once again, I’m not there to coddle a buncha criminal scum sucking f------, I’m there to 1) Survive the fucking round. 2) Guard the armory. So you can absolutely get fucked. If I get unbanned, which I won’t, you can guarantee I will continue to use the shotgun to apprehend criminals. Because it’s quick, clean and effective as fuck. Why in the seven hells would I fuck around with the disabler shots, which take half a clip just to bring someone down, or with the tazer bolts which are slow as balls, impossible to aim and do about next to jack shit, fuck all. The shotgun is the superior law enforcement weapon. Because it stops crime. And it stops crime by reducing the number of criminals roaming the fucking halls.

* Change the faulty store test into two tests, one of which is ignored for failing.
2026-06-29 12:44:18 +02:00

157 lines
4.8 KiB
C#

#nullable enable
using Content.IntegrationTests.Fixtures;
using Content.Server.GameTicking;
using Content.Server.GameTicking.Presets;
using Content.Shared.CCVar;
using Content.Shared.GameTicking;
using Content.Shared.GameTicking.Components;
using Robust.Shared.GameObjects;
namespace Content.IntegrationTests.Tests.GameRules;
[TestFixture]
public sealed class FailAndStartPresetTest : GameTest
{
[TestPrototypes]
private const string Prototypes = @"
- type: gamePreset
id: TestPreset
alias:
- nukeops
name: Test Preset
description: """"
showInVote: false
rules:
- TestRule
- type: gamePreset
id: TestPresetTenPlayers
alias:
- nukeops
name: Test Preset 10 players
description: """"
showInVote: false
rules:
- TestRuleTenPlayers
- type: entity
id: TestRule
parent: BaseGameRule
categories: [ GameRules ]
components:
- type: GameRule
minPlayers: 0
- type: TestRule
- type: entity
id: TestRuleTenPlayers
parent: BaseGameRule
categories: [ GameRules ]
components:
- type: GameRule
minPlayers: 10
- type: TestRule
";
public override PoolSettings PoolSettings => new()
{
Dirty = true,
DummyTicker = false,
Connected = true,
InLobby = true
};
/// <summary>
/// Test that a nuke ops gamemode can start after failing to start once.
/// </summary>
[Test]
public async Task FailAndStartTest()
{
var pair = Pair;
var server = pair.Server;
var client = pair.Client;
var entMan = server.EntMan;
var ticker = server.System<GameTicker>();
server.System<TestRuleSystem>().Run = true;
Assert.That(server.CfgMan.GetCVar(CCVars.GridFill), Is.False);
Assert.That(server.CfgMan.GetCVar(CCVars.GameLobbyFallbackEnabled), Is.True);
Assert.That(server.CfgMan.GetCVar(CCVars.GameLobbyDefaultPreset), Is.EqualTo("secret"));
server.CfgMan.SetCVar(CCVars.GridFill, true);
server.CfgMan.SetCVar(CCVars.GameLobbyFallbackEnabled, false);
server.CfgMan.SetCVar(CCVars.GameLobbyDefaultPreset, "TestPreset");
// Initially in the lobby
Assert.That(ticker.RunLevel, Is.EqualTo(GameRunLevel.PreRoundLobby));
Assert.That(client.AttachedEntity, Is.Null);
Assert.That(ticker.PlayerGameStatuses[client.User!.Value], Is.EqualTo(PlayerGameStatus.NotReadyToPlay));
// Try to start nukeops without readying up
await pair.WaitCommand("setgamepreset TestPresetTenPlayers 9999");
await pair.WaitCommand("startround");
await pair.RunTicksSync(10);
// Game should not have started
Assert.That(ticker.RunLevel, Is.EqualTo(GameRunLevel.PreRoundLobby));
Assert.That(ticker.PlayerGameStatuses[client.User!.Value], Is.EqualTo(PlayerGameStatus.NotReadyToPlay));
Assert.That(!client.EntMan.EntityExists(client.AttachedEntity));
var player = pair.Player!.AttachedEntity;
Assert.That(!entMan.EntityExists(player));
// Ready up and start nukeops
await pair.WaitClientCommand("toggleready True");
Assert.That(ticker.PlayerGameStatuses[client.User!.Value], Is.EqualTo(PlayerGameStatus.ReadyToPlay));
await pair.WaitCommand("setgamepreset TestPreset 9999");
await pair.WaitCommand("startround");
await pair.RunTicksSync(10);
// Game should have started
Assert.That(ticker.RunLevel, Is.EqualTo(GameRunLevel.InRound));
Assert.That(ticker.PlayerGameStatuses[client.User!.Value], Is.EqualTo(PlayerGameStatus.JoinedGame));
Assert.That(client.EntMan.EntityExists(client.AttachedEntity));
player = pair.Player!.AttachedEntity!.Value;
Assert.That(entMan.EntityExists(player));
ticker.SetGamePreset((GamePresetPrototype?) null);
server.CfgMan.SetCVar(CCVars.GridFill, false);
server.CfgMan.SetCVar(CCVars.GameLobbyFallbackEnabled, true);
server.CfgMan.SetCVar(CCVars.GameLobbyDefaultPreset, "secret");
server.System<TestRuleSystem>().Run = false;
}
}
public sealed class TestRuleSystem : EntitySystem
{
public bool Run;
public override void Initialize()
{
SubscribeLocalEvent<RoundStartAttemptEvent>(OnRoundStartAttempt);
}
private void OnRoundStartAttempt(RoundStartAttemptEvent args)
{
if (!Run)
return;
if (args.Forced || args.Cancelled)
return;
var query = EntityQueryEnumerator<TestRuleComponent, GameRuleComponent>();
while (query.MoveNext(out _, out _, out var gameRule))
{
var minPlayers = gameRule.MinPlayers;
if (!gameRule.CancelPresetOnTooFewPlayers)
continue;
if (args.Players.Length >= minPlayers)
continue;
args.Cancel();
}
}
}
[RegisterComponent]
public sealed partial class TestRuleComponent : Component;