]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix for ghosts being unable to follow the AI when it uses a holopad (#36355)
authorchromiumboy <50505512+chromiumboy@users.noreply.github.com>
Fri, 25 Apr 2025 10:30:39 +0000 (05:30 -0500)
committerGitHub <noreply@github.com>
Fri, 25 Apr 2025 10:30:39 +0000 (12:30 +0200)
* Initial commit

* Added to-do

Content.Shared/Follower/FollowerSystem.cs
Content.Shared/Silicons/StationAi/SharedStationAiSystem.cs
Content.Shared/Silicons/StationAi/StationAiCoreComponent.cs

index 75310a6737906bbf6a714d1ef2f101688f701d80..d8e34fb3ee9fd8fb19576cc8b64b203ced93fccc 100644 (file)
@@ -8,6 +8,7 @@ using Content.Shared.Hands;
 using Content.Shared.Movement.Events;
 using Content.Shared.Movement.Pulling.Events;
 using Content.Shared.Polymorph;
+using Content.Shared.Silicons.StationAi;
 using Content.Shared.Tag;
 using Content.Shared.Verbs;
 using Robust.Shared.Containers;
@@ -50,6 +51,7 @@ public sealed class FollowerSystem : EntitySystem
         SubscribeLocalEvent<FollowedComponent, EntityTerminatingEvent>(OnFollowedTerminating);
         SubscribeLocalEvent<BeforeSerializationEvent>(OnBeforeSave);
         SubscribeLocalEvent<FollowedComponent, PolymorphedEvent>(OnFollowedPolymorphed);
+        SubscribeLocalEvent<FollowedComponent, StationAiRemoteEntityReplacementEvent>(OnFollowedStationAiRemoteEntityReplaced);
     }
 
     private void OnFollowedAttempt(Entity<FollowedComponent> ent, ref ComponentGetStateAttemptEvent args)
@@ -169,6 +171,17 @@ public sealed class FollowerSystem : EntitySystem
         }
     }
 
+    // TODO: Slartibarfast mentioned that ideally this should be generalized and made part of SetRelay in SharedMoverController.Relay.cs.
+    // This would apply to polymorphed entities as well
+    private void OnFollowedStationAiRemoteEntityReplaced(Entity<FollowedComponent> entity, ref StationAiRemoteEntityReplacementEvent args)
+    {
+        if (args.NewRemoteEntity == null)
+            return;
+
+        foreach (var follower in entity.Comp.Following)
+            StartFollowingEntity(follower, args.NewRemoteEntity.Value);
+    }
+
     /// <summary>
     ///     Makes an entity follow another entity, by parenting to it.
     /// </summary>
index 4cf36f560ee2f530bb2458ce67787bf2cead37fb..372a758f80caaca652d880bc9a55f4f06396aacf 100644 (file)
@@ -360,11 +360,20 @@ public abstract partial class SharedStationAiSystem : EntitySystem
         EntityCoordinates? coords = ent.Comp.RemoteEntity != null ? Transform(ent.Comp.RemoteEntity.Value).Coordinates : null;
 
         // Attach new eye
+        var oldEye = ent.Comp.RemoteEntity;
+
         ClearEye(ent);
 
         if (SetupEye(ent, coords))
             AttachEye(ent);
 
+        if (oldEye != null)
+        {
+            // Raise the following event on the old eye before it's deleted
+            var ev = new StationAiRemoteEntityReplacementEvent(ent.Comp.RemoteEntity);
+            RaiseLocalEvent(oldEye.Value, ref ev);
+        }
+
         // Adjust user FoV
         var user = GetInsertedAI(ent);
 
index e97e7626b88348320271248e19f30cc88da7188f..a795c9eda635c7107e9b2b9d3fec638bbb54c182 100644 (file)
@@ -40,3 +40,10 @@ public sealed partial class StationAiCoreComponent : Component
 
     public const string Container = "station_ai_mind_slot";
 }
+
+/// <summary>
+/// This event is raised on a station AI 'eye' that is being replaced with a new one 
+/// </summary>
+/// <param name="NewRemoteEntity">The entity UID of the replacement entity</param>
+[ByRefEvent]
+public record struct StationAiRemoteEntityReplacementEvent(EntityUid? NewRemoteEntity);