From c5fa970c58abbc449ee53b66bcdbb1ee84cb45de Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Sun, 11 Aug 2024 12:26:32 +1000 Subject: [PATCH] Make followed session-specific (#30770) * Make followed session-specific * misimport (cherry picked from commit 9be61bfaa5a4bee1ca4f3d5e5c40a69d66e4cc2a) --- .../Follower/Components/FollowedComponent.cs | 2 ++ Content.Shared/Follower/FollowerSystem.cs | 32 ++++++++++++------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/Content.Shared/Follower/Components/FollowedComponent.cs b/Content.Shared/Follower/Components/FollowedComponent.cs index 7c2ca0efbf..b06e445417 100644 --- a/Content.Shared/Follower/Components/FollowedComponent.cs +++ b/Content.Shared/Follower/Components/FollowedComponent.cs @@ -10,6 +10,8 @@ namespace Content.Shared.Follower.Components; [Access(typeof(FollowerSystem))] public sealed partial class FollowedComponent : Component { + public override bool SessionSpecific => true; + [DataField, AutoNetworkedField] public HashSet Following = new(); } diff --git a/Content.Shared/Follower/FollowerSystem.cs b/Content.Shared/Follower/FollowerSystem.cs index 3827bd0dd5..0c7bc99c46 100644 --- a/Content.Shared/Follower/FollowerSystem.cs +++ b/Content.Shared/Follower/FollowerSystem.cs @@ -1,4 +1,3 @@ -using System.Linq; using System.Numerics; using Content.Shared.Administration.Managers; using Content.Shared.Database; @@ -40,21 +39,31 @@ public sealed class FollowerSystem : EntitySystem SubscribeLocalEvent(OnPullStarted); SubscribeLocalEvent(OnFollowerTerminating); + SubscribeLocalEvent(OnFollowedAttempt); SubscribeLocalEvent(OnGotEquippedHand); SubscribeLocalEvent(OnFollowedTerminating); - SubscribeLocalEvent(OnBeforeSave); + SubscribeLocalEvent(OnBeforeSave); } - private void OnBeforeSave(BeforeSerializationEvent ev) + private void OnFollowedAttempt(Entity ent, ref ComponentGetStateAttemptEvent args) { - // Some followers will not be map savable. This ensures that maps don't get saved with some entities that have - // empty/invalid followers, by just stopping any following happening on the map being saved. - // I hate this so much. - // TODO WeakEntityReference - // We need some way to store entity references in a way that doesn't imply that the entity still exists. - // Then we wouldn't have to deal with this shit. + if (args.Cancelled) + return; - var maps = ev.Entities.Select(x => Transform(x).MapUid).ToHashSet(); + // Clientside VV stay losing + var playerEnt = args.Player?.AttachedEntity; + + if (playerEnt == null || + !ent.Comp.Following.Contains(playerEnt.Value) && !HasComp(playerEnt.Value)) + { + args.Cancelled = true; + } + } + + private void OnBeforeSave(BeforeSaveEvent ev) + { + // Some followers will not be map savable. This ensures that maps don't get saved with empty/invalid + // followers, but just stopping any following on the map being saved. var query = AllEntityQuery(); while (query.MoveNext(out var uid, out var follower, out var xform, out var meta)) @@ -62,7 +71,7 @@ public sealed class FollowerSystem : EntitySystem if (meta.EntityPrototype == null || meta.EntityPrototype.MapSavable) continue; - if (!maps.Contains(xform.MapUid)) + if (xform.MapUid != ev.Map) continue; StopFollowingEntity(uid, follower.Following); @@ -193,7 +202,6 @@ public sealed class FollowerSystem : EntitySystem RaiseLocalEvent(follower, followerEv); RaiseLocalEvent(entity, entityEv); Dirty(entity, followedComp); - Dirty(follower, followerComp); } ///