From 288350603a9ea7fc5f13b535f965bcdd10fb6a8d Mon Sep 17 00:00:00 2001 From: sleepyyapril Date: Wed, 20 Nov 2024 17:45:21 -0400 Subject: [PATCH 1/2] Fix PirateRadioSpawnRule heisentest. --- .../Events/PirateRadioSpawnRule.cs | 43 ++++++++++++++++--- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/Content.Server/StationEvents/Events/PirateRadioSpawnRule.cs b/Content.Server/StationEvents/Events/PirateRadioSpawnRule.cs index e0803132044..410b4b0a024 100644 --- a/Content.Server/StationEvents/Events/PirateRadioSpawnRule.cs +++ b/Content.Server/StationEvents/Events/PirateRadioSpawnRule.cs @@ -8,8 +8,11 @@ using Content.Shared.Salvage; using Content.Shared.Random.Helpers; using System.Linq; -using Content.Server.GameTicking.Components; +using Content.Shared.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 From ac22152598a4d7194f1648899da900466883c66f Mon Sep 17 00:00:00 2001 From: sleepyyapril Date: Wed, 20 Nov 2024 17:50:32 -0400 Subject: [PATCH 2/2] Fix engine-update-specific using. --- Content.Server/StationEvents/Events/PirateRadioSpawnRule.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Content.Server/StationEvents/Events/PirateRadioSpawnRule.cs b/Content.Server/StationEvents/Events/PirateRadioSpawnRule.cs index 410b4b0a024..1597f3fe4ee 100644 --- a/Content.Server/StationEvents/Events/PirateRadioSpawnRule.cs +++ b/Content.Server/StationEvents/Events/PirateRadioSpawnRule.cs @@ -8,7 +8,7 @@ using Content.Shared.Salvage; using Content.Shared.Random.Helpers; using System.Linq; -using Content.Shared.GameTicking.Components; +using Content.Server.GameTicking.Components; using Content.Shared.CCVar; using Robust.Shared.Serialization.Manager; using Content.Shared.Parallax.Biomes;