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 { /// /// Stores a on a mob. /// [RegisterComponent] public class MindComponent : Component { /// public override string Name => "Mind"; /// /// The mind controlling this mob. Can be null. /// [ViewVariables] public Mind Mind { get; private set; } /// /// True if we have a mind, false otherwise. /// [ViewVariables] public bool HasMind => Mind != null; /// /// Don't call this unless you know what the hell you're doing. /// Use instead. /// If that doesn't cover it, make something to cover it. /// public void InternalEjectMind() { Mind = null; } /// /// Don't call this unless you know what the hell you're doing. /// Use instead. /// If that doesn't cover it, make something to cover it. /// 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.CanReturnToBody = false; Mind.TransferTo(ghost); } } } } }