]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Hotfix: Fix AntagRandomSpawn location preview (#35864)
authorslarticodefast <161409025+slarticodefast@users.noreply.github.com>
Sun, 16 Mar 2025 23:50:23 +0000 (00:50 +0100)
committerGitHub <noreply@github.com>
Sun, 16 Mar 2025 23:50:23 +0000 (00:50 +0100)
fix AntagRandomSpawn location preview

Content.Server/Antag/AntagRandomSpawnRule.cs
Content.Server/Antag/AntagSelectionSystem.cs
Content.Server/Antag/Components/AntagRandomSpawnComponent.cs

index 499761a8df2872e18a8ef5b7e9e471e84d997499..58fab5414c8e6f43947b9c4e292a2f3cccba1526 100644 (file)
@@ -1,4 +1,5 @@
 using Content.Server.Antag.Components;
+using Content.Shared.GameTicking.Components;
 using Content.Server.GameTicking.Rules;
 
 namespace Content.Server.Antag;
@@ -14,9 +15,20 @@ public sealed class AntagRandomSpawnSystem : GameRuleSystem<AntagRandomSpawnComp
         SubscribeLocalEvent<AntagRandomSpawnComponent, AntagSelectLocationEvent>(OnSelectLocation);
     }
 
-    private void OnSelectLocation(Entity<AntagRandomSpawnComponent> ent, ref AntagSelectLocationEvent args)
+    protected override void Added(EntityUid uid, AntagRandomSpawnComponent comp, GameRuleComponent gameRule, GameRuleAddedEvent args)
     {
+        base.Added(uid, comp, gameRule, args);
+
+        // we have to select this here because AntagSelectLocationEvent is raised twice because MakeAntag is called twice
+        // once when a ghost role spawner is created and once when someone takes the ghost role
+
         if (TryFindRandomTile(out _, out _, out _, out var coords))
-            args.Coordinates.Add(_transform.ToMapCoordinates(coords));
+            comp.Coords = coords;
+    }
+
+    private void OnSelectLocation(Entity<AntagRandomSpawnComponent> ent, ref AntagSelectLocationEvent args)
+    {
+        if (ent.Comp.Coords != null)
+            args.Coordinates.Add(_transform.ToMapCoordinates(ent.Comp.Coords.Value));
     }
 }
index c8b2a7d4bb6c821dc31414693c0be93c486cd0ff..62fbeefb65657dcbda1a5a1b6fc0a5375899b806 100644 (file)
@@ -393,6 +393,11 @@ public sealed partial class AntagSelectionSystem : GameRuleSystem<AntagSelection
             return;
         }
 
+        // TODO: This is really messy because this part runs twice for midround events.
+        // Once when the ghostrole spawner is created and once when a player takes it.
+        // Therefore any component subscribing to this has to make sure both subscriptions return the same value
+        // or the ghost role raffle location preview will be wrong.
+
         var getPosEv = new AntagSelectLocationEvent(session, ent);
         RaiseLocalEvent(ent, ref getPosEv, true);
         if (getPosEv.Handled)
index 16edd256a2eefe7b5a6e841be22688cbac7c2a96..b73d5cdb6845d377e3fda912aea55e54c85d00de 100644 (file)
@@ -1,3 +1,5 @@
+using Robust.Shared.Map;
+
 namespace Content.Server.Antag.Components;
 
 /// <summary>
@@ -5,4 +7,11 @@ namespace Content.Server.Antag.Components;
 /// Requires <see cref="AntagSelectionComponent"/>.
 /// </summary>
 [RegisterComponent]
-public sealed partial class AntagRandomSpawnComponent : Component;
+public sealed partial class AntagRandomSpawnComponent : Component
+{
+    /// <summary>
+    /// Location that was picked.
+    /// </summary>
+    [DataField]
+    public EntityCoordinates? Coords;
+}