Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix followers getting sent to nullspace when target is polymorphed #33878

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Content.Server/Polymorph/Systems/PolymorphSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,10 @@ private void OnDestruction(Entity<PolymorphedEntityComponent> 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;
}

Expand Down Expand Up @@ -339,6 +343,10 @@ private void OnDestruction(Entity<PolymorphedEntityComponent> 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))),
Expand Down
11 changes: 11 additions & 0 deletions Content.Shared/Follower/FollowerSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -42,6 +43,7 @@ public override void Initialize()
SubscribeLocalEvent<FollowedComponent, ComponentGetStateAttemptEvent>(OnFollowedAttempt);
SubscribeLocalEvent<FollowerComponent, GotEquippedHandEvent>(OnGotEquippedHand);
SubscribeLocalEvent<FollowedComponent, EntityTerminatingEvent>(OnFollowedTerminating);
SubscribeLocalEvent<FollowedComponent, PolymorphedEvent>(OnFollowedPolymorphed);
SubscribeLocalEvent<BeforeSaveEvent>(OnBeforeSave);
}

Expand Down Expand Up @@ -142,6 +144,15 @@ private void OnFollowedTerminating(EntityUid uid, FollowedComponent component, r
StopAllFollowers(uid, component);
}

private void OnFollowedPolymorphed(Entity<FollowedComponent> 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);
}
}

/// <summary>
/// Makes an entity follow another entity, by parenting to it.
/// </summary>
Expand Down
10 changes: 10 additions & 0 deletions Content.Shared/Polymorph/PolymorphEvents.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Content.Shared.Polymorph;

/// <summary>
/// Raised locally on an entity when it polymorphs into another entity
/// </summary>
/// <param name="OldEntity">EntityUid of the entity before the polymorph</param>
/// <param name="NewEntity">EntityUid of the entity after the polymorph</param>
/// <param name="IsRevert">Whether this polymorph event was a revert back to the original entity</param>
[ByRefEvent]
public record struct PolymorphedEvent(EntityUid OldEntity, EntityUid NewEntity, bool IsRevert);
Loading