diff --git a/Content.Server/Nuke/NukeSystem.cs b/Content.Server/Nuke/NukeSystem.cs index fa18297a64..d6cc2f4795 100644 --- a/Content.Server/Nuke/NukeSystem.cs +++ b/Content.Server/Nuke/NukeSystem.cs @@ -24,7 +24,7 @@ namespace Content.Server.Nuke [Dependency] private readonly PopupSystem _popups = default!; [Dependency] private readonly ExplosionSystem _explosions = default!; [Dependency] private readonly AlertLevelSystem _alertLevel = default!; - [Dependency] private readonly StationSystem _stationSystem = default!; + [Dependency] private readonly StationSystem _station = default!; [Dependency] private readonly ServerGlobalSoundSystem _soundSystem = default!; [Dependency] private readonly ChatSystem _chatSystem = default!; [Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!; @@ -99,7 +99,7 @@ namespace Content.Server.Nuke private void OnMapInit(EntityUid uid, NukeComponent nuke, MapInitEvent args) { - var originStation = _stationSystem.GetOwningStation(uid); + var originStation = _station.GetOwningStation(uid); if (originStation != null) nuke.OriginStation = originStation; @@ -436,14 +436,14 @@ namespace Content.Server.Nuke if (component.Status == NukeStatus.ARMED) return; - var stationUid = _stationSystem.GetOwningStation(uid); + var nukeXform = Transform(uid); + var stationUid = _station.GetStationInMap(nukeXform.MapID); // The nuke may not be on a station, so it's more important to just // let people know that a nuclear bomb was armed in their vicinity instead. // Otherwise, you could set every station to whatever AlertLevelOnActivate is. if (stationUid != null) _alertLevel.SetLevel(stationUid.Value, component.AlertLevelOnActivate, true, true, true, true); - var nukeXform = Transform(uid); var pos = nukeXform.MapPosition; var x = (int) pos.X; var y = (int) pos.Y; @@ -453,7 +453,7 @@ namespace Content.Server.Nuke var announcement = Loc.GetString("nuke-component-announcement-armed", ("time", (int) component.RemainingTime), ("position", posText)); var sender = Loc.GetString("nuke-component-announcement-sender"); - _chatSystem.DispatchStationAnnouncement(uid, announcement, sender, false, null, Color.Red); + _chatSystem.DispatchStationAnnouncement(stationUid ?? uid, announcement, sender, false, null, Color.Red); _soundSystem.PlayGlobalOnStation(uid, _audio.GetSound(component.ArmSound)); @@ -474,7 +474,7 @@ namespace Content.Server.Nuke if (component.Status != NukeStatus.ARMED) return; - var stationUid = _stationSystem.GetOwningStation(uid); + var stationUid = _station.GetOwningStation(uid); if (stationUid != null) _alertLevel.SetLevel(stationUid.Value, component.AlertLevelOnDeactivate, true, true, true); diff --git a/Content.Server/Station/Systems/StationSystem.cs b/Content.Server/Station/Systems/StationSystem.cs index 73fa592b40..c951fb1ccd 100644 --- a/Content.Server/Station/Systems/StationSystem.cs +++ b/Content.Server/Station/Systems/StationSystem.cs @@ -440,6 +440,30 @@ public sealed class StationSystem : EntitySystem { return EntityQuery().Select(x => x.Owner).ToHashSet(); } + + /// + /// Returns the first station that has a grid in a certain map. + /// If the map has no stations, null is returned instead. + /// + /// + public EntityUid? GetStationInMap(MapId map) + { + var query = EntityQueryEnumerator(); + while (query.MoveNext(out var uid, out var data)) + { + foreach (var gridUid in data.Grids) + { + if (Transform(gridUid).MapID == map) + { + return uid; + } + } + } + + return null; + } } ///