Fix follower recursion

This commit is contained in:
Kara D
2022-02-19 16:55:29 -07:00
parent fe6e7cf1fd
commit 99d44ee388
3 changed files with 11 additions and 1 deletions

View File

@@ -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();

View File

@@ -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;

View File

@@ -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);