diff --git a/Content.Server/StationEvents/Events/PirateRadioSpawnRule.cs b/Content.Server/StationEvents/Events/PirateRadioSpawnRule.cs index e0803132044..1597f3fe4ee 100644 --- a/Content.Server/StationEvents/Events/PirateRadioSpawnRule.cs +++ b/Content.Server/StationEvents/Events/PirateRadioSpawnRule.cs @@ -10,6 +10,9 @@ using System.Linq; using Content.Server.GameTicking.Components; using Content.Shared.CCVar; +using Robust.Shared.Serialization.Manager; +using Content.Shared.Parallax.Biomes; +using Robust.Shared.Map; namespace Content.Server.StationEvents.Events; @@ -21,25 +24,43 @@ public sealed class PirateRadioSpawnRule : StationEventSystem(Transform(station).MapUid)) + stations.Remove(station); + + // _random forces Test Fails if given an empty list. which is guaranteed to happen during Tests. + if (stations.Count <= 0) return; var targetStation = _random.Pick(stations); - var randomOffset = _random.NextVector2(component.MinimumDistance, component.MaximumDistance); + var targetMapId = Transform(targetStation).MapID; + if (!_mapSystem.MapExists(targetMapId)) + return; + + var randomOffset = _random.NextVector2(component.MinimumDistance, component.MaximumDistance); var outpostOptions = new MapLoadOptions { Offset = _xform.GetWorldPosition(targetStation) + randomOffset, LoadMap = false, }; - if (!_map.TryLoad(GameTicker.DefaultMap, _random.Pick(component.PirateRadioShuttlePath), out var outpostids, outpostOptions)) + if (!_map.TryLoad(Transform(targetStation).MapID, _random.Pick(component.PirateRadioShuttlePath), out var outpostids, outpostOptions)) return; SpawnDebris(component, outpostids); @@ -55,6 +76,7 @@ private void SpawnDebris(PirateRadioSpawnRuleComponent component, IReadOnlyList< { var outpostaabb = _xform.GetWorldPosition(id); var k = 0; + while (k < component.DebrisCount) { var debrisRandomOffset = _random.NextVector2(component.MinimumDebrisDistance, component.MaximumDebrisDistance); @@ -65,7 +87,16 @@ private void SpawnDebris(PirateRadioSpawnRuleComponent component, IReadOnlyList< LoadMap = false, }; - var salvageProto = _random.Pick(_prototypeManager.EnumeratePrototypes().ToList()); + var salvPrototypes = _prototypeManager.EnumeratePrototypes().ToList(); + var salvageProto = _random.Pick(salvPrototypes); + + if (!_mapSystem.MapExists(GameTicker.DefaultMap)) + return; + + // Round didn't start before running this, leading to a null-space test fail. + if (GameTicker.DefaultMap == MapId.Nullspace) + return; + if (!_map.TryLoad(GameTicker.DefaultMap, salvageProto.MapPath.ToString(), out _, debrisOptions)) return; @@ -81,4 +112,4 @@ protected override void Ended(EntityUid uid, PirateRadioSpawnRuleComponent compo if (component.AdditionalRule != null) GameTicker.EndGameRule(component.AdditionalRule.Value); } -} +} \ No newline at end of file