diff --git a/Content.Server/Nyanotrasen/StationEvents/Components/MidRoundAntagRuleComponent.cs b/Content.Server/Nyanotrasen/StationEvents/Components/MidRoundAntagRuleComponent.cs index df8b687c3e1..c951e5d929b 100644 --- a/Content.Server/Nyanotrasen/StationEvents/Components/MidRoundAntagRuleComponent.cs +++ b/Content.Server/Nyanotrasen/StationEvents/Components/MidRoundAntagRuleComponent.cs @@ -6,12 +6,9 @@ namespace Content.Server.StationEvents.Components; [RegisterComponent, Access(typeof(MidRoundAntagRule))] public sealed partial class MidRoundAntagRuleComponent : Component { - [DataField("antags")] - public List MidRoundAntags = new() - { - "SpawnPointGhostRatKing", - //"SpawnPointGhostVampSpider", - //"SpawnPointGhostFugitive", - "SpawnPointGhostParadoxAnomaly" - }; + /// + /// Spawner to create at a random mid round antag marker. + /// + [DataField(required: true)] + public EntProtoId Spawner = string.Empty; } diff --git a/Content.Server/Nyanotrasen/StationEvents/Events/MidRoundAntagRule.cs b/Content.Server/Nyanotrasen/StationEvents/Events/MidRoundAntagRule.cs index 169f7575490..89fb110ae72 100644 --- a/Content.Server/Nyanotrasen/StationEvents/Events/MidRoundAntagRule.cs +++ b/Content.Server/Nyanotrasen/StationEvents/Events/MidRoundAntagRule.cs @@ -1,38 +1,54 @@ using Content.Server.GameTicking.Rules.Components; using Content.Server.StationEvents.Components; -using Robust.Shared.Random; -using System.Linq; namespace Content.Server.StationEvents.Events; public sealed class MidRoundAntagRule : StationEventSystem { - [Dependency] private readonly IRobustRandom _random = default!; - protected override void Started(EntityUid uid, MidRoundAntagRuleComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args) { base.Started(uid, component, gameRule, args); - var spawnLocations = EntityQuery().ToList(); - var backupSpawnLocations = EntityQuery().ToList(); - - TransformComponent? spawn = new(); + if (!TryGetRandomStation(out var station)) + return; - if (spawnLocations.Count > 0) - { - var spawnLoc = _random.Pick(spawnLocations); - spawn = spawnLoc.Item2; - } else if (backupSpawnLocations.Count > 0) + var spawnLocations = FindSpawns(station.Value); + if (spawnLocations.Count == 0) { - var spawnLoc = _random.Pick(backupSpawnLocations); - spawn = spawnLoc.Item2; + Log.Error("Couldn't find any midround antag spawners or vent critter spawners, not spawning an antag."); + return; } - if (spawn?.GridUid == null) - return; + var spawn = RobustRandom.Pick(spawnLocations); - var proto = _random.Pick(component.MidRoundAntags); + var proto = component.Spawner; Log.Info($"Spawning midround antag {proto} at {spawn.Coordinates}"); Spawn(proto, spawn.Coordinates); } + + private List FindSpawns(EntityUid station) + { + var spawns = new List(); + var query = EntityQueryEnumerator(); + while (query.MoveNext(out var uid, out _, out var xform)) + { + if (StationSystem.GetOwningStation(uid, xform) == station && xform.GridUid != null) + spawns.Add(xform); + } + + // if there are any midround antag spawns mapped, use them + if (spawns.Count > 0) + return spawns; + + // otherwise, fall back to vent critter spawns + Log.Info($"Station {ToPrettyString(station):station} has no midround antag spawnpoints mapped, falling back. Please map them!"); + var fallbackQuery = EntityQueryEnumerator(); + while (fallbackQuery.MoveNext(out var uid, out _, out var xform)) + { + if (StationSystem.GetOwningStation(uid, xform) == station && xform.GridUid != null) + spawns.Add(xform); + } + + return spawns; + } }