Cleanup more follower leaks (#20902)
* Cleanup more follower leaks Rather than check stop everywhere we'll just check it on start and cleanup the old following. If someone were already following and followed something new the FollowedComponent would never get cleaned up and would never have its ref to the entity removed. * Don't cause archetype changes
This commit is contained in:
@@ -138,7 +138,20 @@ public sealed class FollowerSystem : EntitySystem
|
|||||||
targetXform = Transform(targetXform.ParentUid);
|
targetXform = Transform(targetXform.ParentUid);
|
||||||
}
|
}
|
||||||
|
|
||||||
var followerComp = EnsureComp<FollowerComponent>(follower);
|
// Cleanup old following.
|
||||||
|
if (TryComp<FollowerComponent>(follower, out var followerComp))
|
||||||
|
{
|
||||||
|
// Already following you goob
|
||||||
|
if (followerComp.Following == entity)
|
||||||
|
return;
|
||||||
|
|
||||||
|
StopFollowingEntity(follower, followerComp.Following, deparent: false, removeComp: false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
followerComp = AddComp<FollowerComponent>(follower);
|
||||||
|
}
|
||||||
|
|
||||||
followerComp.Following = entity;
|
followerComp.Following = entity;
|
||||||
|
|
||||||
var followedComp = EnsureComp<FollowedComponent>(entity);
|
var followedComp = EnsureComp<FollowedComponent>(entity);
|
||||||
@@ -167,14 +180,14 @@ public sealed class FollowerSystem : EntitySystem
|
|||||||
|
|
||||||
RaiseLocalEvent(follower, followerEv);
|
RaiseLocalEvent(follower, followerEv);
|
||||||
RaiseLocalEvent(entity, entityEv);
|
RaiseLocalEvent(entity, entityEv);
|
||||||
Dirty(followedComp);
|
Dirty(entity, followedComp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Forces an entity to stop following another entity, if it is doing so.
|
/// Forces an entity to stop following another entity, if it is doing so.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="deparent">Should the entity deparent itself</param>
|
/// <param name="deparent">Should the entity deparent itself</param>
|
||||||
public void StopFollowingEntity(EntityUid uid, EntityUid target, FollowedComponent? followed = null, bool deparent = true)
|
public void StopFollowingEntity(EntityUid uid, EntityUid target, FollowedComponent? followed = null, bool deparent = true, bool removeComp = true)
|
||||||
{
|
{
|
||||||
if (!Resolve(target, ref followed, false))
|
if (!Resolve(target, ref followed, false))
|
||||||
return;
|
return;
|
||||||
@@ -186,8 +199,12 @@ public sealed class FollowerSystem : EntitySystem
|
|||||||
if (followed.Following.Count == 0)
|
if (followed.Following.Count == 0)
|
||||||
RemComp<FollowedComponent>(target);
|
RemComp<FollowedComponent>(target);
|
||||||
|
|
||||||
|
if (removeComp)
|
||||||
|
{
|
||||||
RemComp<FollowerComponent>(uid);
|
RemComp<FollowerComponent>(uid);
|
||||||
RemComp<OrbitVisualsComponent>(uid);
|
RemComp<OrbitVisualsComponent>(uid);
|
||||||
|
}
|
||||||
|
|
||||||
var uidEv = new StoppedFollowingEntityEvent(target, uid);
|
var uidEv = new StoppedFollowingEntityEvent(target, uid);
|
||||||
var targetEv = new EntityStoppedFollowingEvent(target, uid);
|
var targetEv = new EntityStoppedFollowingEvent(target, uid);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user