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;
SubscribeLocalEvent<FollowedComponent, EntityTerminatingEvent>(OnFollowedTerminating);
SubscribeLocalEvent<BeforeSerializationEvent>(OnBeforeSave);
SubscribeLocalEvent<FollowedComponent, PolymorphedEvent>(OnFollowedPolymorphed);
+ SubscribeLocalEvent<FollowedComponent, StationAiRemoteEntityReplacementEvent>(OnFollowedStationAiRemoteEntityReplaced);
}
private void OnFollowedAttempt(Entity<FollowedComponent> ent, ref ComponentGetStateAttemptEvent args)
}
}
+ // 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>
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);
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);