|
| 1 | +/* WD edit |
| 2 | +
|
| 3 | +#nullable enable |
| 4 | +using System.Linq; |
| 5 | +using Content.Server.Body.Components; |
| 6 | +using Content.Server.GameTicking; |
| 7 | +using Content.Server.GameTicking.Presets; |
| 8 | +using Content.Server.GameTicking.Rules.Components; |
| 9 | +using Content.Server.Mind; |
| 10 | +using Content.Server.NPC.Systems; |
| 11 | +using Content.Server.Pinpointer; |
| 12 | +using Content.Server.Roles; |
| 13 | +using Content.Server.Shuttles.Components; |
| 14 | +using Content.Server.Station.Components; |
| 15 | +using Content.Shared.CCVar; |
| 16 | +using Content.Shared.Damage; |
| 17 | +using Content.Shared.FixedPoint; |
| 18 | +using Content.Shared.GameTicking; |
| 19 | +using Content.Shared.Hands.Components; |
| 20 | +using Content.Shared.Inventory; |
| 21 | +using Content.Shared.NukeOps; |
| 22 | +using Robust.Server.GameObjects; |
| 23 | +using Robust.Shared.GameObjects; |
| 24 | +using Robust.Shared.Map.Components; |
| 25 | +
|
| 26 | +namespace Content.IntegrationTests.Tests.GameRules; |
| 27 | +
|
| 28 | +[TestFixture] |
| 29 | +public sealed class NukeOpsTest |
| 30 | +{ |
| 31 | + /// <summary> |
| 32 | + /// Check that a nuke ops game mode can start without issue. I.e., that the nuke station and such all get loaded. |
| 33 | + /// </summary> |
| 34 | + [Test] |
| 35 | + public async Task TryStopNukeOpsFromConstantlyFailing() |
| 36 | + { |
| 37 | + await using var pair = await PoolManager.GetServerClient(new PoolSettings |
| 38 | + { |
| 39 | + Dirty = true, |
| 40 | + DummyTicker = false, |
| 41 | + Connected = true, |
| 42 | + InLobby = true |
| 43 | + }); |
| 44 | +
|
| 45 | + var server = pair.Server; |
| 46 | + var client = pair.Client; |
| 47 | + var entMan = server.EntMan; |
| 48 | + var mapSys = server.System<MapSystem>(); |
| 49 | + var ticker = server.System<GameTicker>(); |
| 50 | + var mindSys = server.System<MindSystem>(); |
| 51 | + var roleSys = server.System<RoleSystem>(); |
| 52 | + var invSys = server.System<InventorySystem>(); |
| 53 | + var factionSys = server.System<NpcFactionSystem>(); |
| 54 | +
|
| 55 | + Assert.That(server.CfgMan.GetCVar(CCVars.GridFill), Is.False); |
| 56 | + server.CfgMan.SetCVar(CCVars.GridFill, true); |
| 57 | +
|
| 58 | + // Initially in the lobby |
| 59 | + Assert.That(ticker.RunLevel, Is.EqualTo(GameRunLevel.PreRoundLobby)); |
| 60 | + Assert.That(client.AttachedEntity, Is.Null); |
| 61 | + Assert.That(ticker.PlayerGameStatuses[client.User!.Value], Is.EqualTo(PlayerGameStatus.NotReadyToPlay)); |
| 62 | +
|
| 63 | + // There are no grids or maps |
| 64 | + Assert.That(entMan.Count<MapComponent>(), Is.Zero); |
| 65 | + Assert.That(entMan.Count<MapGridComponent>(), Is.Zero); |
| 66 | + Assert.That(entMan.Count<StationMapComponent>(), Is.Zero); |
| 67 | + Assert.That(entMan.Count<StationMemberComponent>(), Is.Zero); |
| 68 | + Assert.That(entMan.Count<StationCentcommComponent>(), Is.Zero); |
| 69 | +
|
| 70 | + // And no nukie related components |
| 71 | + Assert.That(entMan.Count<NukeopsRuleComponent>(), Is.Zero); |
| 72 | + Assert.That(entMan.Count<NukeopsRoleComponent>(), Is.Zero); |
| 73 | + Assert.That(entMan.Count<NukeOperativeComponent>(), Is.Zero); |
| 74 | + Assert.That(entMan.Count<NukeOpsShuttleComponent>(), Is.Zero); |
| 75 | + Assert.That(entMan.Count<NukeOperativeSpawnerComponent>(), Is.Zero); |
| 76 | +
|
| 77 | + // Ready up and start nukeops |
| 78 | + await pair.WaitClientCommand("toggleready True"); |
| 79 | + Assert.That(ticker.PlayerGameStatuses[client.User!.Value], Is.EqualTo(PlayerGameStatus.ReadyToPlay)); |
| 80 | + await pair.WaitCommand("forcepreset Nukeops"); |
| 81 | + await pair.RunTicksSync(10); |
| 82 | +
|
| 83 | + // Game should have started |
| 84 | + Assert.That(ticker.RunLevel, Is.EqualTo(GameRunLevel.InRound)); |
| 85 | + Assert.That(ticker.PlayerGameStatuses[client.User!.Value], Is.EqualTo(PlayerGameStatus.JoinedGame)); |
| 86 | + Assert.That(client.EntMan.EntityExists(client.AttachedEntity)); |
| 87 | + var player = pair.Player!.AttachedEntity!.Value; |
| 88 | + Assert.That(entMan.EntityExists(player)); |
| 89 | +
|
| 90 | + // Maps now exist |
| 91 | + Assert.That(entMan.Count<MapComponent>(), Is.GreaterThan(0)); |
| 92 | + Assert.That(entMan.Count<MapGridComponent>(), Is.GreaterThan(0)); |
| 93 | + Assert.That(entMan.Count<StationDataComponent>(), Is.EqualTo(2)); // The main station & nukie station |
| 94 | + Assert.That(entMan.Count<StationMemberComponent>(), Is.GreaterThan(3)); // Each station has at least 1 grid, plus some shuttles |
| 95 | + Assert.That(entMan.Count<StationCentcommComponent>(), Is.EqualTo(1)); |
| 96 | +
|
| 97 | + // And we now have nukie related components |
| 98 | + Assert.That(entMan.Count<NukeopsRuleComponent>(), Is.EqualTo(1)); |
| 99 | + Assert.That(entMan.Count<NukeopsRoleComponent>(), Is.EqualTo(1)); |
| 100 | + Assert.That(entMan.Count<NukeOperativeComponent>(), Is.EqualTo(1)); |
| 101 | + Assert.That(entMan.Count<NukeOpsShuttleComponent>(), Is.EqualTo(1)); |
| 102 | +
|
| 103 | + // The player entity should be the nukie commander |
| 104 | + var mind = mindSys.GetMind(player)!.Value; |
| 105 | + Assert.That(entMan.HasComponent<NukeOperativeComponent>(player)); |
| 106 | + Assert.That(roleSys.MindIsAntagonist(mind)); |
| 107 | + Assert.That(roleSys.MindHasRole<NukeopsRoleComponent>(mind)); |
| 108 | +
|
| 109 | + Assert.That(factionSys.IsMember(player, "Syndicate"), Is.True); |
| 110 | + Assert.That(factionSys.IsMember(player, "NanoTrasen"), Is.False); |
| 111 | +
|
| 112 | + var roles = roleSys.MindGetAllRoles(mind); |
| 113 | + var cmdRoles = roles.Where(x => x.Prototype == "NukeopsCommander" && x.Component is NukeopsRoleComponent); |
| 114 | + Assert.That(cmdRoles.Count(), Is.EqualTo(1)); |
| 115 | +
|
| 116 | + // The game rule exists, and all the stations/shuttles/maps are properly initialized |
| 117 | + var rule = entMan.AllComponents<NukeopsRuleComponent>().Single().Component; |
| 118 | + var mapRule = entMan.AllComponents<LoadMapRuleComponent>().Single().Component; |
| 119 | + foreach (var grid in mapRule.MapGrids) |
| 120 | + { |
| 121 | + Assert.That(entMan.EntityExists(grid)); |
| 122 | + Assert.That(entMan.HasComponent<MapGridComponent>(grid)); |
| 123 | + Assert.That(entMan.HasComponent<StationMemberComponent>(grid)); |
| 124 | + } |
| 125 | + Assert.That(entMan.EntityExists(rule.TargetStation)); |
| 126 | +
|
| 127 | + Assert.That(entMan.HasComponent<StationDataComponent>(rule.TargetStation)); |
| 128 | +
|
| 129 | + var nukieShuttlEnt = entMan.AllComponents<NukeOpsShuttleComponent>().FirstOrDefault().Uid; |
| 130 | + Assert.That(entMan.EntityExists(nukieShuttlEnt)); |
| 131 | +
|
| 132 | + EntityUid? nukieStationEnt = null; |
| 133 | + foreach (var grid in mapRule.MapGrids) |
| 134 | + { |
| 135 | + if (entMan.HasComponent<StationMemberComponent>(grid)) |
| 136 | + { |
| 137 | + nukieStationEnt = grid; |
| 138 | + break; |
| 139 | + } |
| 140 | + } |
| 141 | +
|
| 142 | + Assert.That(entMan.EntityExists(nukieStationEnt)); |
| 143 | + var nukieStation = entMan.GetComponent<StationMemberComponent>(nukieStationEnt!.Value); |
| 144 | +
|
| 145 | + Assert.That(entMan.EntityExists(nukieStation.Station)); |
| 146 | + Assert.That(nukieStation.Station, Is.Not.EqualTo(rule.TargetStation)); |
| 147 | +
|
| 148 | + Assert.That(server.MapMan.MapExists(mapRule.Map)); |
| 149 | + var nukieMap = mapSys.GetMap(mapRule.Map!.Value); |
| 150 | +
|
| 151 | + var targetStation = entMan.GetComponent<StationDataComponent>(rule.TargetStation!.Value); |
| 152 | + var targetGrid = targetStation.Grids.First(); |
| 153 | + var targetMap = entMan.GetComponent<TransformComponent>(targetGrid).MapUid!.Value; |
| 154 | + Assert.That(targetMap, Is.Not.EqualTo(nukieMap)); |
| 155 | +
|
| 156 | + Assert.That(entMan.GetComponent<TransformComponent>(player).MapUid, Is.EqualTo(nukieMap)); |
| 157 | + Assert.That(entMan.GetComponent<TransformComponent>(nukieStationEnt.Value).MapUid, Is.EqualTo(nukieMap)); |
| 158 | + Assert.That(entMan.GetComponent<TransformComponent>(nukieShuttlEnt).MapUid, Is.EqualTo(nukieMap)); |
| 159 | +
|
| 160 | + // The maps are all map-initialized, including the player |
| 161 | + // Yes, this is necessary as this has repeatedly been broken somehow. |
| 162 | + Assert.That(mapSys.IsInitialized(nukieMap)); |
| 163 | + Assert.That(mapSys.IsInitialized(targetMap)); |
| 164 | + Assert.That(mapSys.IsPaused(nukieMap), Is.False); |
| 165 | + Assert.That(mapSys.IsPaused(targetMap), Is.False); |
| 166 | +
|
| 167 | + EntityLifeStage LifeStage(EntityUid? uid) => entMan.GetComponent<MetaDataComponent>(uid!.Value).EntityLifeStage; |
| 168 | + Assert.That(LifeStage(player), Is.GreaterThan(EntityLifeStage.Initialized)); |
| 169 | + Assert.That(LifeStage(nukieMap), Is.GreaterThan(EntityLifeStage.Initialized)); |
| 170 | + Assert.That(LifeStage(targetMap), Is.GreaterThan(EntityLifeStage.Initialized)); |
| 171 | + Assert.That(LifeStage(nukieStationEnt.Value), Is.GreaterThan(EntityLifeStage.Initialized)); |
| 172 | + Assert.That(LifeStage(nukieShuttlEnt), Is.GreaterThan(EntityLifeStage.Initialized)); |
| 173 | + Assert.That(LifeStage(rule.TargetStation), Is.GreaterThan(EntityLifeStage.Initialized)); |
| 174 | +
|
| 175 | + // Make sure the player has hands. We've had fucking disarmed nukies before. |
| 176 | + Assert.That(entMan.HasComponent<HandsComponent>(player)); |
| 177 | + Assert.That(entMan.GetComponent<HandsComponent>(player).Hands.Count, Is.GreaterThan(0)); |
| 178 | +
|
| 179 | + // While we're at it, lets make sure they aren't naked. I don't know how many inventory slots all mobs will be |
| 180 | + // likely to have in the future. But nukies should probably have at least 3 slots with something in them. |
| 181 | + var enumerator = invSys.GetSlotEnumerator(player); |
| 182 | + int total = 0; |
| 183 | + while (enumerator.NextItem(out _)) |
| 184 | + { |
| 185 | + total++; |
| 186 | + } |
| 187 | + Assert.That(total, Is.GreaterThan(3)); |
| 188 | +
|
| 189 | + // Finally lets check the nukie commander passed basic training and figured out how to breathe. |
| 190 | + var totalSeconds = 30; |
| 191 | + var totalTicks = (int) Math.Ceiling(totalSeconds / server.Timing.TickPeriod.TotalSeconds); |
| 192 | + int increment = 5; |
| 193 | + var resp = entMan.GetComponent<RespiratorComponent>(player); |
| 194 | + var damage = entMan.GetComponent<DamageableComponent>(player); |
| 195 | + for (var tick = 0; tick < totalTicks; tick += increment) |
| 196 | + { |
| 197 | + await pair.RunTicksSync(increment); |
| 198 | + Assert.That(resp.SuffocationCycles, Is.LessThanOrEqualTo(resp.SuffocationCycleThreshold)); |
| 199 | + Assert.That(damage.TotalDamage, Is.EqualTo(FixedPoint2.Zero)); |
| 200 | + } |
| 201 | +
|
| 202 | + //ticker.SetGamePreset((GamePresetPrototype?)null); WD edit |
| 203 | + server.CfgMan.SetCVar(CCVars.GridFill, false); |
| 204 | + await pair.CleanReturnAsync(); |
| 205 | + } |
| 206 | +} |
| 207 | +
|
| 208 | +*/ |
0 commit comments