Fix follower recursion
This commit is contained in:
@@ -1,13 +1,16 @@
|
||||
using System.Collections.Generic;
|
||||
using Robust.Shared.Analyzers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Follower.Components;
|
||||
|
||||
// TODO properly network this and followercomp.
|
||||
/// <summary>
|
||||
/// Attached to entities that are currently being followed by a ghost.
|
||||
/// </summary>
|
||||
[RegisterComponent, Friend(typeof(FollowerSystem))]
|
||||
[NetworkedComponent]
|
||||
public sealed class FollowedComponent : Component
|
||||
{
|
||||
public HashSet<EntityUid> Following = new();
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
using Robust.Shared.Analyzers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Follower.Components;
|
||||
|
||||
[RegisterComponent]
|
||||
[Friend(typeof(FollowerSystem))]
|
||||
[NetworkedComponent]
|
||||
public sealed class FollowerComponent : Component
|
||||
{
|
||||
public EntityUid Following;
|
||||
|
||||
@@ -63,11 +63,16 @@ public sealed class FollowerSystem : EntitySystem
|
||||
/// <param name="entity">The entity to be followed</param>
|
||||
public void StartFollowingEntity(EntityUid follower, EntityUid entity)
|
||||
{
|
||||
// No recursion for you
|
||||
if (Transform(entity).ParentUid == follower)
|
||||
return;
|
||||
|
||||
var followerComp = EnsureComp<FollowerComponent>(follower);
|
||||
followerComp.Following = entity;
|
||||
|
||||
var followedComp = EnsureComp<FollowedComponent>(entity);
|
||||
followedComp.Following.Add(follower);
|
||||
if (!followedComp.Following.Add(follower))
|
||||
return;
|
||||
|
||||
var xform = Transform(follower);
|
||||
xform.AttachParent(entity);
|
||||
|
||||
Reference in New Issue
Block a user