Make followed session-specific (#30770)

* Make followed session-specific

* misimport
This commit is contained in:
metalgearsloth
2024-08-11 12:26:32 +10:00
committed by GitHub
parent 84217011a9
commit 9be61bfaa5
2 changed files with 19 additions and 0 deletions

View File

@@ -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<EntityUid> Following = new();
}

View File

@@ -9,6 +9,7 @@ using Content.Shared.Movement.Pulling.Events;
using Content.Shared.Tag;
using Content.Shared.Verbs;
using Robust.Shared.Containers;
using Robust.Shared.GameStates;
using Robust.Shared.Map;
using Robust.Shared.Map.Events;
using Robust.Shared.Network;
@@ -38,11 +39,27 @@ public sealed class FollowerSystem : EntitySystem
SubscribeLocalEvent<FollowerComponent, PullStartedMessage>(OnPullStarted);
SubscribeLocalEvent<FollowerComponent, EntityTerminatingEvent>(OnFollowerTerminating);
SubscribeLocalEvent<FollowedComponent, ComponentGetStateAttemptEvent>(OnFollowedAttempt);
SubscribeLocalEvent<FollowerComponent, GotEquippedHandEvent>(OnGotEquippedHand);
SubscribeLocalEvent<FollowedComponent, EntityTerminatingEvent>(OnFollowedTerminating);
SubscribeLocalEvent<BeforeSaveEvent>(OnBeforeSave);
}
private void OnFollowedAttempt(Entity<FollowedComponent> ent, ref ComponentGetStateAttemptEvent args)
{
if (args.Cancelled)
return;
// Clientside VV stay losing
var playerEnt = args.Player?.AttachedEntity;
if (playerEnt == null ||
!ent.Comp.Following.Contains(playerEnt.Value) && !HasComp<GhostComponent>(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