Refactor mind and ghost deletion code (#3680)
* Refactor mind and ghost deletion code * Refactor to use EventBus and clean up deletes * Fix mind eject when being deleted * Refactor entity manager calls to use IEntity.EntityManager
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#nullable enable
|
||||
#nullable enable
|
||||
using System;
|
||||
using Content.Server.Eui;
|
||||
using Content.Server.GameObjects.Components.Mobs;
|
||||
@@ -203,9 +203,6 @@ namespace Content.Server.GameObjects.Components.Medical
|
||||
{
|
||||
if (message.Sender == _capturedMind)
|
||||
{
|
||||
//If the captured mind is in a ghost, we want to get rid of it.
|
||||
_capturedMind.VisitingEntity?.Delete();
|
||||
|
||||
//Transfer the mind to the new mob
|
||||
_capturedMind.TransferTo(_bodyContainer.ContainedEntity);
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#nullable enable
|
||||
#nullable enable
|
||||
using Content.Server.GameObjects.Components.Observer;
|
||||
using Content.Server.GameTicking;
|
||||
using Content.Server.Interfaces.GameTicking;
|
||||
@@ -22,9 +22,6 @@ namespace Content.Server.GameObjects.Components.Mobs
|
||||
[RegisterComponent]
|
||||
public class MindComponent : Component, IExamine
|
||||
{
|
||||
[DataField("show_examine_info")]
|
||||
private bool _showExamineInfo;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string Name => "Mind";
|
||||
|
||||
@@ -61,6 +58,8 @@ namespace Content.Server.GameObjects.Components.Mobs
|
||||
/// </summary>
|
||||
public void InternalEjectMind()
|
||||
{
|
||||
if (!Deleted)
|
||||
Owner.EntityManager.EventBus.RaiseLocalEvent(Owner.Uid, new MindRemovedMessage());
|
||||
Mind = null;
|
||||
}
|
||||
|
||||
@@ -94,7 +93,7 @@ namespace Content.Server.GameObjects.Components.Mobs
|
||||
|
||||
Mind!.TransferTo(visiting);
|
||||
}
|
||||
else if(GhostOnShutdown)
|
||||
else if (GhostOnShutdown)
|
||||
{
|
||||
var spawnPosition = Owner.Transform.Coordinates;
|
||||
// Use a regular timer here because the entity has probably been deleted.
|
||||
@@ -153,4 +152,8 @@ namespace Content.Server.GameObjects.Components.Mobs
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class MindRemovedMessage : EntityEventArgs
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Content.Server.Mobs;
|
||||
#nullable enable
|
||||
using Content.Server.Mobs;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
@@ -18,4 +19,8 @@ namespace Content.Server.GameObjects.Components.Mobs
|
||||
Mind?.UnVisit();
|
||||
}
|
||||
}
|
||||
|
||||
public class MindUnvisitedMessage : EntityEventArgs
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,9 @@ namespace Content.Server.GameObjects.Components.Observer
|
||||
return;
|
||||
}
|
||||
|
||||
Player.ContentData()?.Mind?.TransferTo(_newMob);
|
||||
var mind = Player.ContentData()?.Mind;
|
||||
mind?.TransferTo(_newMob);
|
||||
mind?.UnVisit();
|
||||
Close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,6 +72,26 @@ namespace Content.Server.GameObjects.Components.Observer
|
||||
base.Shutdown();
|
||||
}
|
||||
|
||||
public override void OnAdd()
|
||||
{
|
||||
base.OnAdd();
|
||||
|
||||
if (Owner.TryGetComponent<MindComponent>(out var mind))
|
||||
{
|
||||
mind.GhostOnShutdown = false;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnRemove()
|
||||
{
|
||||
base.OnRemove();
|
||||
|
||||
if (Owner.TryGetComponent<MindComponent>(out var mind))
|
||||
{
|
||||
mind.GhostOnShutdown = true;
|
||||
}
|
||||
}
|
||||
|
||||
public override ComponentState GetComponentState(ICommonSession player) => new GhostComponentState(CanReturnToBody);
|
||||
|
||||
public override void HandleNetworkMessage(ComponentMessage message, INetChannel netChannel, ICommonSession? session = null!)
|
||||
@@ -92,13 +112,12 @@ namespace Content.Server.GameObjects.Components.Observer
|
||||
{
|
||||
var o = actor.playerSession.ContentData()!.Mind;
|
||||
o?.UnVisit();
|
||||
Owner.Delete();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ReturnToCloneComponentMessage _:
|
||||
|
||||
if (Owner.TryGetComponent(out VisitingMindComponent? mind))
|
||||
if (Owner.TryGetComponent(out VisitingMindComponent? mind) && mind.Mind != null)
|
||||
{
|
||||
Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new GhostReturnMessage(mind.Mind));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user