Make deleting a visited entity not cleaning it up in the mind.
This commit is contained in:
@@ -0,0 +1,20 @@
|
|||||||
|
using Content.Server.Mobs;
|
||||||
|
using Robust.Shared.GameObjects;
|
||||||
|
|
||||||
|
namespace Content.Server.GameObjects.Components.Mobs
|
||||||
|
{
|
||||||
|
[RegisterComponent]
|
||||||
|
public sealed class VisitingMindComponent : Component
|
||||||
|
{
|
||||||
|
public override string Name => "VisitingMind";
|
||||||
|
|
||||||
|
public Mind Mind { get; set; }
|
||||||
|
|
||||||
|
public override void OnRemove()
|
||||||
|
{
|
||||||
|
base.OnRemove();
|
||||||
|
|
||||||
|
Mind?.UnVisit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -231,6 +231,9 @@ namespace Content.Server.Mobs
|
|||||||
{
|
{
|
||||||
Session?.AttachToEntity(entity);
|
Session?.AttachToEntity(entity);
|
||||||
VisitingEntity = entity;
|
VisitingEntity = entity;
|
||||||
|
|
||||||
|
var comp = entity.AddComponent<VisitingMindComponent>();
|
||||||
|
comp.Mind = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UnVisit()
|
public void UnVisit()
|
||||||
@@ -241,7 +244,14 @@ namespace Content.Server.Mobs
|
|||||||
}
|
}
|
||||||
|
|
||||||
Session?.AttachToEntity(OwnedEntity);
|
Session?.AttachToEntity(OwnedEntity);
|
||||||
|
var oldVisitingEnt = VisitingEntity;
|
||||||
|
// Null this before removing the component to avoid any infinite loops.
|
||||||
VisitingEntity = null;
|
VisitingEntity = null;
|
||||||
|
|
||||||
|
if (oldVisitingEnt.HasComponent<VisitingMindComponent>())
|
||||||
|
{
|
||||||
|
oldVisitingEnt.RemoveComponent<VisitingMindComponent>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user