mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 18:31:17 +03:00
* Scope creep my ass * why was this shit not pushed???? * gone... * fix that * review plus buildd * asfsafsafsafsafas * grug * burber * I'll fix this later * shrimply die * also this * it's snerf or snuthin * assaads * round snend * aaaa * fix this shit for real * actually, don't start GameRules until MapInit now that I think aboot it. * forgot u * don't actually need this part nullable * Deffer comp removal * one liner * do that too * chungus * Honestly makes more sense here, plus WHY are we doing all that shit on "GameRuleAdded" rather than GameRuleStarted(?) * deferred removal :V * aaaaaaaaaaaaaaa * whhop * Whoop * better * landmine that I placed for myself then forgot about lmao * cleanup * FUCKING `!` * gotovo * amogus * please don't check by metadata I beg * waawsasfdfsasfa * sfafsasfafsas * fdsaasffsasfa * code * fix * fasasffasfasfsad * chungaas * I may be stupid * gra * graaaaaaaaaaaaaaaaa * comment * gra * clearing is not predicted and would require major refactors, so don't cache on client. * lame shit :P * last holes * nukeopsfsafsasafsfafsa * why was that shit public bruh * bubrbgwahrghfaka * dynamic * revert change that did nothing lmao
137 lines
5.8 KiB
C#
137 lines
5.8 KiB
C#
using System.Linq;
|
|
using Content.IntegrationTests.Fixtures;
|
|
using Content.Server.Antag.Components;
|
|
using Content.Server.GameTicking;
|
|
using Content.Server.GameTicking.Rules;
|
|
using Content.Server.GameTicking.Rules.Components;
|
|
using Content.Server.Mind;
|
|
using Content.Server.Roles;
|
|
using Content.Shared.GameTicking;
|
|
using Content.Shared.GameTicking.Components;
|
|
using Content.Shared.GameTicking.Rules.Components;
|
|
using Content.Shared.Mind;
|
|
using Content.Shared.NPC.Prototypes;
|
|
using Content.Shared.NPC.Systems;
|
|
using Content.Shared.Objectives.Components;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.Prototypes;
|
|
|
|
namespace Content.IntegrationTests.Tests.GameRules;
|
|
|
|
[TestFixture]
|
|
public sealed class TraitorRuleTest : GameTest
|
|
{
|
|
private const string TraitorGameRuleProtoId = "Traitor";
|
|
private const string TraitorAntagRoleName = "Traitor";
|
|
private static readonly ProtoId<NpcFactionPrototype> SyndicateFaction = "Syndicate";
|
|
private static readonly ProtoId<NpcFactionPrototype> NanotrasenFaction = "NanoTrasen";
|
|
|
|
public override PoolSettings PoolSettings => new()
|
|
{
|
|
Dirty = true,
|
|
DummyTicker = false,
|
|
Connected = true,
|
|
InLobby = true,
|
|
};
|
|
|
|
[Test]
|
|
public async Task TestTraitorObjectives()
|
|
{
|
|
var pair = Pair;
|
|
var server = pair.Server;
|
|
var client = pair.Client;
|
|
var entMan = server.EntMan;
|
|
var protoMan = server.ProtoMan;
|
|
var compFact = server.ResolveDependency<IComponentFactory>();
|
|
var ticker = server.System<ServerGameTicker>();
|
|
var mindSys = server.System<MindSystem>();
|
|
var roleSys = server.System<RoleSystem>();
|
|
var factionSys = server.System<NpcFactionSystem>();
|
|
|
|
// Look up the minimum player count and max total objective difficulty for the game rule
|
|
var minPlayers = 1;
|
|
var maxDifficulty = 0f;
|
|
await server.WaitAssertion(() =>
|
|
{
|
|
Assert.That(protoMan.TryIndex<EntityPrototype>(TraitorGameRuleProtoId, out var gameRuleEnt),
|
|
$"Failed to lookup traitor game rule entity prototype with ID \"{TraitorGameRuleProtoId}\"!");
|
|
|
|
Assert.That(gameRuleEnt.TryComp<GameRuleComponent>(out var gameRule, compFact),
|
|
$"Game rule entity {TraitorGameRuleProtoId} does not have a GameRuleComponent!");
|
|
|
|
Assert.That(gameRuleEnt.TryComp<AntagRandomObjectivesComponent>(out var randomObjectives, compFact),
|
|
$"Game rule entity {TraitorGameRuleProtoId} does not have an AntagRandomObjectivesComponent!");
|
|
|
|
minPlayers = gameRule.MinPlayers;
|
|
maxDifficulty = randomObjectives.MaxDifficulty;
|
|
});
|
|
|
|
// 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));
|
|
|
|
// Add enough dummy players for the game rule
|
|
var dummies = await pair.Server.AddDummySessions(minPlayers);
|
|
await pair.RunTicksSync(5);
|
|
|
|
// Initially, the players have no attached entities
|
|
Assert.That(pair.Player?.AttachedEntity, Is.Null);
|
|
Assert.That(dummies.All(x => x.AttachedEntity == null));
|
|
|
|
// Opt-in the player for the traitor role
|
|
await pair.SetAntagPreference(TraitorAntagRoleName, true);
|
|
|
|
// Add the game rule
|
|
TraitorRuleComponent traitorRule = null;
|
|
await server.WaitPost(() =>
|
|
{
|
|
var gameRuleEnt = ticker.AddGameRule(TraitorGameRuleProtoId);
|
|
Assert.That(entMan.TryGetComponent(gameRuleEnt, out traitorRule));
|
|
|
|
// Ready up
|
|
ticker.ToggleReadyAll(true);
|
|
Assert.That(ticker.PlayerGameStatuses.Values.All(x => x == PlayerGameStatus.ReadyToPlay));
|
|
|
|
// Start the round
|
|
ticker.StartRound();
|
|
// Force traitor mode to start (skip the delay)
|
|
ticker.StartGameRule(gameRuleEnt!.Value);
|
|
});
|
|
await pair.RunTicksSync(10);
|
|
|
|
// Game should have started
|
|
Assert.That(ticker.RunLevel, Is.EqualTo(GameRunLevel.InRound));
|
|
Assert.That(ticker.PlayerGameStatuses.Values.All(x => x == PlayerGameStatus.JoinedGame));
|
|
Assert.That(client.EntMan.EntityExists(client.AttachedEntity));
|
|
|
|
// Check the player and dummies are spawned
|
|
var dummyEnts = dummies.Select(x => x.AttachedEntity ?? default).ToArray();
|
|
var player = pair.Player!.AttachedEntity!.Value;
|
|
Assert.That(entMan.EntityExists(player));
|
|
Assert.That(dummyEnts.All(entMan.EntityExists));
|
|
|
|
// Make sure the player is a traitor.
|
|
var mind = mindSys.GetMind(player)!.Value;
|
|
Assert.That(roleSys.MindIsAntagonist(mind));
|
|
Assert.That(factionSys.IsMember(player, SyndicateFaction), Is.True);
|
|
Assert.That(factionSys.IsMember(player, NanotrasenFaction), Is.False);
|
|
Assert.That(traitorRule.TotalTraitors, Is.EqualTo(1));
|
|
Assert.That(traitorRule.TraitorMinds[0], Is.EqualTo(mind));
|
|
|
|
// Check total objective difficulty
|
|
Assert.That(entMan.TryGetComponent<MindComponent>(mind, out var mindComp));
|
|
var totalDifficulty = mindComp.Objectives.Sum(o => entMan.GetComponent<ObjectiveComponent>(o).Difficulty);
|
|
Assert.That(totalDifficulty, Is.AtMost(maxDifficulty),
|
|
$"MaxDifficulty exceeded! Objectives: {string.Join(", ", mindComp.Objectives.Select(o => FormatObjective(o, entMan)))}");
|
|
Assert.That(mindComp.Objectives, Is.Not.Empty,
|
|
$"No objectives assigned!");
|
|
}
|
|
|
|
private static string FormatObjective(Entity<ObjectiveComponent> entity, IEntityManager entMan)
|
|
{
|
|
var meta = entMan.GetComponent<MetaDataComponent>(entity);
|
|
var objective = entMan.GetComponent<ObjectiveComponent>(entity);
|
|
return $"{meta.EntityName} ({objective.Difficulty})";
|
|
}
|
|
}
|