Fix mind unvisit crash (#8682)

This commit is contained in:
metalgearsloth
2022-06-09 04:01:37 +10:00
committed by GitHub
parent 90744c1b2e
commit 08e1d3cd66

View File

@@ -279,7 +279,7 @@ namespace Content.Server.Mind
if (entity != null)
{
if (!entMan.TryGetComponent<MindComponent>(entity.Value, out component))
if (!entMan.TryGetComponent(entity.Value, out component))
{
component = entMan.AddComponent<MindComponent>(entity.Value);
}
@@ -309,10 +309,18 @@ namespace Content.Server.Mind
if(OwnedComponent != null)
mindSystem.InternalAssignMind(OwnedComponent.Owner, this, OwnedComponent);
if (VisitingEntity != null
&& (ghostCheckOverride // to force mind transfer, for example from ControlMobVerb
|| !entMan.TryGetComponent(VisitingEntity!, out GhostComponent? ghostComponent) // visiting entity is not a Ghost
|| !ghostComponent.CanReturnToBody)) // it is a ghost, but cannot return to body anyway, so it's okay
// Don't do the full deletion cleanup if we're transferring to our visitingentity
if (alreadyAttached)
{
// Set VisitingEntity null first so the removal of VisitingMind doesn't get through Unvisit() and delete what we're visiting.
// Yes this control flow sucks.
VisitingEntity = null;
IoCManager.Resolve<IEntityManager>().RemoveComponent<VisitingMindComponent>(entity!.Value);
}
else if (VisitingEntity != null
&& (ghostCheckOverride // to force mind transfer, for example from ControlMobVerb
|| !entMan.TryGetComponent(VisitingEntity!, out GhostComponent? ghostComponent) // visiting entity is not a Ghost
|| !ghostComponent.CanReturnToBody)) // it is a ghost, but cannot return to body anyway, so it's okay
{
RemoveVisitingEntity();
}
@@ -402,11 +410,7 @@ namespace Content.Server.Mind
DebugTools.AssertNotNull(oldVisitingEnt);
var entities = IoCManager.Resolve<IEntityManager>();
if (entities.HasComponent<VisitingMindComponent>(oldVisitingEnt))
{
entities.RemoveComponent<VisitingMindComponent>(oldVisitingEnt);
}
entities.RemoveComponent<VisitingMindComponent>(oldVisitingEnt);
entities.EventBus.RaiseLocalEvent(oldVisitingEnt, new MindUnvisitedMessage());
}