You now get turned into a ghost if it happens, or return to body gets disabled if you were already ghosted.
79 lines
2.4 KiB
C#
79 lines
2.4 KiB
C#
using Content.Server.GameObjects.Components.Observer;
|
|
using Content.Server.Mobs;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.Interfaces.GameObjects;
|
|
using Robust.Shared.ViewVariables;
|
|
|
|
namespace Content.Server.GameObjects.Components.Mobs
|
|
{
|
|
/// <summary>
|
|
/// Stores a <see cref="Server.Mobs.Mind"/> on a mob.
|
|
/// </summary>
|
|
[RegisterComponent]
|
|
public class MindComponent : Component
|
|
{
|
|
/// <inheritdoc />
|
|
public override string Name => "Mind";
|
|
|
|
/// <summary>
|
|
/// The mind controlling this mob. Can be null.
|
|
/// </summary>
|
|
[ViewVariables]
|
|
public Mind Mind { get; private set; }
|
|
|
|
/// <summary>
|
|
/// True if we have a mind, false otherwise.
|
|
/// </summary>
|
|
[ViewVariables]
|
|
public bool HasMind => Mind != null;
|
|
|
|
/// <summary>
|
|
/// Don't call this unless you know what the hell you're doing.
|
|
/// Use <see cref="Mind.TransferTo(IEntity)"/> instead.
|
|
/// If that doesn't cover it, make something to cover it.
|
|
/// </summary>
|
|
public void InternalEjectMind()
|
|
{
|
|
Mind = null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Don't call this unless you know what the hell you're doing.
|
|
/// Use <see cref="Mind.TransferTo(IEntity)"/> instead.
|
|
/// If that doesn't cover it, make something to cover it.
|
|
/// </summary>
|
|
public void InternalAssignMind(Mind value)
|
|
{
|
|
Mind = value;
|
|
}
|
|
|
|
protected override void Shutdown()
|
|
{
|
|
base.Shutdown();
|
|
|
|
if (HasMind)
|
|
{
|
|
var visiting = Mind.VisitingEntity;
|
|
if (visiting != null)
|
|
{
|
|
if (visiting.TryGetComponent(out GhostComponent ghost))
|
|
{
|
|
ghost.CanReturnToBody = false;
|
|
}
|
|
|
|
Mind.TransferTo(visiting);
|
|
}
|
|
else
|
|
{
|
|
var ghost = Owner.EntityManager.SpawnEntity("MobObserver", Owner.Transform.GridPosition);
|
|
ghost.Name = Mind.CharacterName;
|
|
|
|
var ghostComponent = ghost.GetComponent<GhostComponent>();
|
|
ghostComponent.CanReturnToBody = false;
|
|
Mind.TransferTo(ghost);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|