Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/wizards/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
VigersRay committed Jul 1, 2024
2 parents fb1754b + 2f1bc7a commit 9d1c427
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 31 deletions.
46 changes: 34 additions & 12 deletions Content.IntegrationTests/Tests/GameRules/NukeOpsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Content.Server.Mind;
using Content.Server.Pinpointer;
using Content.Server.Roles;
using Content.Server.RoundEnd;
using Content.Server.Shuttles.Components;
using Content.Server.Station.Components;
using Content.Shared.CCVar;
Expand Down Expand Up @@ -50,6 +51,7 @@ public async Task TryStopNukeOpsFromConstantlyFailing()
var roleSys = server.System<RoleSystem>();
var invSys = server.System<InventorySystem>();
var factionSys = server.System<NpcFactionSystem>();
var roundEndSys = server.System<RoundEndSystem>();

server.CfgMan.SetCVar(CCVars.GridFill, true);

Expand All @@ -64,11 +66,11 @@ public async Task TryStopNukeOpsFromConstantlyFailing()

// Opt into the nukies role.
await pair.SetAntagPreference("NukeopsCommander", true);
await pair.SetAntagPreference( "NukeopsMedic", true, dummies[1].UserId);
await pair.SetAntagPreference("NukeopsMedic", true, dummies[1].UserId);

// Initially, the players have no attached entities
Assert.That(pair.Player?.AttachedEntity, Is.Null);
Assert.That(dummies.All(x => x.AttachedEntity == null));
Assert.That(dummies.All(x => x.AttachedEntity == null));

// There are no grids or maps
Assert.That(entMan.Count<MapComponent>(), Is.Zero);
Expand Down Expand Up @@ -151,20 +153,23 @@ void CheckDummy(int i)
}

// The game rule exists, and all the stations/shuttles/maps are properly initialized
var rule = entMan.AllComponents<NukeopsRuleComponent>().Single().Component;
var rule = entMan.AllComponents<NukeopsRuleComponent>().Single();
var ruleComp = rule.Component;
var gridsRule = entMan.AllComponents<RuleGridsComponent>().Single().Component;
foreach (var grid in gridsRule.MapGrids)
{
Assert.That(entMan.EntityExists(grid));
Assert.That(entMan.HasComponent<MapGridComponent>(grid));
Assert.That(entMan.HasComponent<StationMemberComponent>(grid));
}
Assert.That(entMan.EntityExists(rule.TargetStation));
Assert.That(entMan.EntityExists(ruleComp.TargetStation));

Assert.That(entMan.HasComponent<StationDataComponent>(rule.TargetStation));
Assert.That(entMan.HasComponent<StationDataComponent>(ruleComp.TargetStation));

var nukieShuttlEnt = entMan.AllComponents<NukeOpsShuttleComponent>().FirstOrDefault().Uid;
var nukieShuttle = entMan.AllComponents<NukeOpsShuttleComponent>().Single();
var nukieShuttlEnt = nukieShuttle.Uid;
Assert.That(entMan.EntityExists(nukieShuttlEnt));
Assert.That(nukieShuttle.Component.AssociatedRule, Is.EqualTo(rule.Uid));

EntityUid? nukieStationEnt = null;
foreach (var grid in gridsRule.MapGrids)
Expand All @@ -180,12 +185,12 @@ void CheckDummy(int i)
var nukieStation = entMan.GetComponent<StationMemberComponent>(nukieStationEnt!.Value);

Assert.That(entMan.EntityExists(nukieStation.Station));
Assert.That(nukieStation.Station, Is.Not.EqualTo(rule.TargetStation));
Assert.That(nukieStation.Station, Is.Not.EqualTo(ruleComp.TargetStation));

Assert.That(server.MapMan.MapExists(gridsRule.Map));
var nukieMap = mapSys.GetMap(gridsRule.Map!.Value);

var targetStation = entMan.GetComponent<StationDataComponent>(rule.TargetStation!.Value);
var targetStation = entMan.GetComponent<StationDataComponent>(ruleComp.TargetStation!.Value);
var targetGrid = targetStation.Grids.First();
var targetMap = entMan.GetComponent<TransformComponent>(targetGrid).MapUid!.Value;
Assert.That(targetMap, Is.Not.EqualTo(nukieMap));
Expand All @@ -207,7 +212,7 @@ void CheckDummy(int i)
Assert.That(LifeStage(targetMap), Is.GreaterThan(EntityLifeStage.Initialized));
Assert.That(LifeStage(nukieStationEnt.Value), Is.GreaterThan(EntityLifeStage.Initialized));
Assert.That(LifeStage(nukieShuttlEnt), Is.GreaterThan(EntityLifeStage.Initialized));
Assert.That(LifeStage(rule.TargetStation), Is.GreaterThan(EntityLifeStage.Initialized));
Assert.That(LifeStage(ruleComp.TargetStation), Is.GreaterThan(EntityLifeStage.Initialized));

// Make sure the player has hands. We've had fucking disarmed nukies before.
Assert.That(entMan.HasComponent<HandsComponent>(player));
Expand All @@ -223,10 +228,10 @@ void CheckDummy(int i)
}
Assert.That(total, Is.GreaterThan(3));

// Finally lets check the nukie commander passed basic training and figured out how to breathe.
// Check the nukie commander passed basic training and figured out how to breathe.
var totalSeconds = 30;
var totalTicks = (int) Math.Ceiling(totalSeconds / server.Timing.TickPeriod.TotalSeconds);
int increment = 5;
var increment = 5;
var resp = entMan.GetComponent<RespiratorComponent>(player);
var damage = entMan.GetComponent<DamageableComponent>(player);
for (var tick = 0; tick < totalTicks; tick += increment)
Expand All @@ -236,7 +241,24 @@ void CheckDummy(int i)
Assert.That(damage.TotalDamage, Is.EqualTo(FixedPoint2.Zero));
}

ticker.SetGamePreset((GamePresetPrototype?)null);
// Check that the round does not end prematurely when agents are deleted in the outpost
var nukies = dummyEnts.Where(entMan.HasComponent<NukeOperativeComponent>).Append(player).ToArray();
await server.WaitAssertion(() =>
{
for (var i = 0; i < nukies.Length - 1; i++)
{
entMan.DeleteEntity(nukies[i]);
Assert.That(roundEndSys.IsRoundEndRequested, Is.False,
$"The round ended, but {nukies.Length - i - 1} nukies are still alive!");
}
// Delete the last nukie and make sure the round ends.
entMan.DeleteEntity(nukies[^1]);

Assert.That(roundEndSys.IsRoundEndRequested,
"All nukies were deleted, but the round didn't end!");
});

ticker.SetGamePreset((GamePresetPrototype?) null);
await pair.CleanReturnAsync();
}
}
24 changes: 12 additions & 12 deletions Content.Server/GameTicking/Rules/NukeopsRuleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,12 @@ public override void Initialize()
SubscribeLocalEvent<NukeOperativeComponent, MobStateChangedEvent>(OnMobStateChanged);
SubscribeLocalEvent<NukeOperativeComponent, EntityZombifiedEvent>(OnOperativeZombified);

SubscribeLocalEvent<NukeOpsShuttleComponent, MapInitEvent>(OnMapInit);

SubscribeLocalEvent<ConsoleFTLAttemptEvent>(OnShuttleFTLAttempt);
SubscribeLocalEvent<WarDeclaredEvent>(OnWarDeclared);
SubscribeLocalEvent<CommunicationConsoleCallShuttleAttemptEvent>(OnShuttleCallAttempt);

SubscribeLocalEvent<NukeopsRuleComponent, AfterAntagEntitySelectedEvent>(OnAfterAntagEntSelected);
SubscribeLocalEvent<NukeopsRuleComponent, RuleLoadedGridsEvent>(OnRuleLoadedGrids);
}

protected override void Started(EntityUid uid, NukeopsRuleComponent component, GameRuleComponent gameRule,
Expand Down Expand Up @@ -256,17 +255,18 @@ private void OnOperativeZombified(EntityUid uid, NukeOperativeComponent componen
RemCompDeferred(uid, component);
}

private void OnMapInit(Entity<NukeOpsShuttleComponent> ent, ref MapInitEvent args)
private void OnRuleLoadedGrids(Entity<NukeopsRuleComponent> ent, ref RuleLoadedGridsEvent args)
{
var map = Transform(ent).MapID;

var rules = EntityQueryEnumerator<NukeopsRuleComponent, RuleGridsComponent>();
while (rules.MoveNext(out var uid, out _, out var grids))
// Check each nukie shuttle
var query = EntityQueryEnumerator<NukeOpsShuttleComponent>();
while (query.MoveNext(out var uid, out var shuttle))
{
if (map != grids.Map)
continue;
ent.Comp.AssociatedRule = uid;
break;
// Check if the shuttle's mapID is the one that just got loaded for this rule
if (Transform(uid).MapID == args.Map)
{
shuttle.AssociatedRule = ent;
break;
}
}
}

Expand Down Expand Up @@ -376,7 +376,7 @@ private void DistributeExtraTc(Entity<NukeopsRuleComponent> nukieRule)
if (Transform(uid).MapID != Transform(outpost).MapID) // Will receive bonus TC only on their start outpost
continue;

_store.TryAddCurrency(new () { { TelecrystalCurrencyPrototype, nukieRule.Comp.WarTcAmountPerNukie } }, uid, component);
_store.TryAddCurrency(new() { { TelecrystalCurrencyPrototype, nukieRule.Comp.WarTcAmountPerNukie } }, uid, component);

var msg = Loc.GetString("store-currency-war-boost-given", ("target", uid));
_popupSystem.PopupEntity(msg, uid);
Expand Down
15 changes: 8 additions & 7 deletions Resources/Changelog/Changelog.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
Entries:
- author: TokenStyle
changes:
- message: Lockers cannot be deconstructed with a screwdriver when locked now.
type: Fix
id: 6356
time: '2024-04-14T22:26:47.0000000+00:00'
url: https://github.com/space-wizards/space-station-14/pull/26961
- author: pissdemon
changes:
- message: Catwalks over lava are slightly less likely to catch you on fire again.
Expand Down Expand Up @@ -3820,3 +3813,11 @@
id: 6855
time: '2024-07-01T21:14:38.0000000+00:00'
url: https://github.com/space-wizards/space-station-14/pull/29476
- author: Tayrtahn
changes:
- message: Fixed NukeOps ending prematurely in some situations where operatives
were still alive.
type: Fix
id: 6856
time: '2024-07-01T22:23:36.0000000+00:00'
url: https://github.com/space-wizards/space-station-14/pull/29642

0 comments on commit 9d1c427

Please sign in to comment.