From 82cb9934970caa056421bd5efe26bacd7ed6ad8b Mon Sep 17 00:00:00 2001 From: Tayrtahn Date: Sun, 15 Dec 2024 16:05:48 -0500 Subject: [PATCH 1/2] Add an event for polymorph actions --- Content.Server/Polymorph/Systems/PolymorphSystem.cs | 8 ++++++++ Content.Shared/Polymorph/PolymorphEvents.cs | 10 ++++++++++ 2 files changed, 18 insertions(+) create mode 100644 Content.Shared/Polymorph/PolymorphEvents.cs diff --git a/Content.Server/Polymorph/Systems/PolymorphSystem.cs b/Content.Server/Polymorph/Systems/PolymorphSystem.cs index c9a71c53584f..e74c7540615b 100644 --- a/Content.Server/Polymorph/Systems/PolymorphSystem.cs +++ b/Content.Server/Polymorph/Systems/PolymorphSystem.cs @@ -267,6 +267,10 @@ private void OnDestruction(Entity ent, ref Destructi if (PausedMap != null) _transform.SetParent(uid, targetTransformComp, PausedMap.Value); + // Raise an event to inform anything that wants to know about the entity swap + var ev = new PolymorphedEvent(uid, child, false); + RaiseLocalEvent(uid, ref ev); + return child; } @@ -339,6 +343,10 @@ private void OnDestruction(Entity ent, ref Destructi // if an item polymorph was picked up, put it back down after reverting _transform.AttachToGridOrMap(parent, parentXform); + // Raise an event to inform anything that wants to know about the entity swap + var ev = new PolymorphedEvent(uid, parent, true); + RaiseLocalEvent(uid, ref ev); + _popup.PopupEntity(Loc.GetString("polymorph-revert-popup-generic", ("parent", Identity.Entity(uid, EntityManager)), ("child", Identity.Entity(parent, EntityManager))), diff --git a/Content.Shared/Polymorph/PolymorphEvents.cs b/Content.Shared/Polymorph/PolymorphEvents.cs new file mode 100644 index 000000000000..f2a478c34f5b --- /dev/null +++ b/Content.Shared/Polymorph/PolymorphEvents.cs @@ -0,0 +1,10 @@ +namespace Content.Shared.Polymorph; + +/// +/// Raised locally on an entity when it polymorphs into another entity +/// +/// EntityUid of the entity before the polymorph +/// EntityUid of the entity after the polymorph +/// Whether this polymorph event was a revert back to the original entity +[ByRefEvent] +public record struct PolymorphedEvent(EntityUid OldEntity, EntityUid NewEntity, bool IsRevert); From a6578ec4c72768e501ed9b2a67184a1255eb8ea9 Mon Sep 17 00:00:00 2001 From: Tayrtahn Date: Sun, 15 Dec 2024 16:06:27 -0500 Subject: [PATCH 2/2] Subscribe FollowerSystem to the event --- Content.Shared/Follower/FollowerSystem.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Content.Shared/Follower/FollowerSystem.cs b/Content.Shared/Follower/FollowerSystem.cs index 0c7bc99c4648..53bbd642cb0c 100644 --- a/Content.Shared/Follower/FollowerSystem.cs +++ b/Content.Shared/Follower/FollowerSystem.cs @@ -6,6 +6,7 @@ using Content.Shared.Hands; using Content.Shared.Movement.Events; using Content.Shared.Movement.Pulling.Events; +using Content.Shared.Polymorph; using Content.Shared.Tag; using Content.Shared.Verbs; using Robust.Shared.Containers; @@ -42,6 +43,7 @@ public override void Initialize() SubscribeLocalEvent(OnFollowedAttempt); SubscribeLocalEvent(OnGotEquippedHand); SubscribeLocalEvent(OnFollowedTerminating); + SubscribeLocalEvent(OnFollowedPolymorphed); SubscribeLocalEvent(OnBeforeSave); } @@ -142,6 +144,15 @@ private void OnFollowedTerminating(EntityUid uid, FollowedComponent component, r StopAllFollowers(uid, component); } + private void OnFollowedPolymorphed(Entity entity, ref PolymorphedEvent args) + { + foreach (var follower in entity.Comp.Following) + { + // Stop following the target's old entity and start following the new one + StartFollowingEntity(follower, args.NewEntity); + } + } + /// /// Makes an entity follow another entity, by parenting to it. ///