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