diff --git a/Content.Shared/Follower/FollowerSystem.cs b/Content.Shared/Follower/FollowerSystem.cs index 75310a6737..d8e34fb3ee 100644 --- a/Content.Shared/Follower/FollowerSystem.cs +++ b/Content.Shared/Follower/FollowerSystem.cs @@ -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(OnFollowedTerminating); SubscribeLocalEvent(OnBeforeSave); SubscribeLocalEvent(OnFollowedPolymorphed); + SubscribeLocalEvent(OnFollowedStationAiRemoteEntityReplaced); } private void OnFollowedAttempt(Entity 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 entity, ref StationAiRemoteEntityReplacementEvent args) + { + if (args.NewRemoteEntity == null) + return; + + foreach (var follower in entity.Comp.Following) + StartFollowingEntity(follower, args.NewRemoteEntity.Value); + } + /// /// Makes an entity follow another entity, by parenting to it. /// diff --git a/Content.Shared/Silicons/StationAi/SharedStationAiSystem.cs b/Content.Shared/Silicons/StationAi/SharedStationAiSystem.cs index 4cf36f560e..372a758f80 100644 --- a/Content.Shared/Silicons/StationAi/SharedStationAiSystem.cs +++ b/Content.Shared/Silicons/StationAi/SharedStationAiSystem.cs @@ -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); diff --git a/Content.Shared/Silicons/StationAi/StationAiCoreComponent.cs b/Content.Shared/Silicons/StationAi/StationAiCoreComponent.cs index e97e7626b8..a795c9eda6 100644 --- a/Content.Shared/Silicons/StationAi/StationAiCoreComponent.cs +++ b/Content.Shared/Silicons/StationAi/StationAiCoreComponent.cs @@ -40,3 +40,10 @@ public sealed partial class StationAiCoreComponent : Component public const string Container = "station_ai_mind_slot"; } + +/// +/// This event is raised on a station AI 'eye' that is being replaced with a new one +/// +/// The entity UID of the replacement entity +[ByRefEvent] +public record struct StationAiRemoteEntityReplacementEvent(EntityUid? NewRemoteEntity);