2020-03-03 20:37:26 +01:00
|
|
|
using Content.Server.GameObjects;
|
2020-04-05 02:29:04 +02:00
|
|
|
using Content.Server.GameObjects.Components.Observer;
|
2020-07-06 14:27:03 -07:00
|
|
|
using Content.Server.Interfaces.GameObjects.Components.Interaction;
|
2020-03-03 20:37:26 +01:00
|
|
|
using Content.Server.Interfaces.GameTicking;
|
|
|
|
|
using Content.Server.Players;
|
|
|
|
|
using Content.Shared.GameObjects;
|
|
|
|
|
using Robust.Server.Interfaces.Console;
|
|
|
|
|
using Robust.Server.Interfaces.Player;
|
|
|
|
|
using Robust.Shared.Interfaces.GameObjects;
|
|
|
|
|
using Robust.Shared.IoC;
|
2020-04-05 02:29:04 +02:00
|
|
|
using Robust.Shared.Log;
|
2020-03-03 20:37:26 +01:00
|
|
|
using Robust.Shared.Map;
|
2020-04-17 19:19:37 +02:00
|
|
|
using Robust.Shared.Timers;
|
2020-03-03 20:37:26 +01:00
|
|
|
|
|
|
|
|
namespace Content.Server.Observer
|
|
|
|
|
{
|
|
|
|
|
public class Ghost : IClientCommand
|
|
|
|
|
{
|
|
|
|
|
public string Command => "ghost";
|
|
|
|
|
public string Description => "Give up on life and become a ghost.";
|
|
|
|
|
public string Help => "ghost";
|
|
|
|
|
|
|
|
|
|
public void Execute(IConsoleShell shell, IPlayerSession player, string[] args)
|
|
|
|
|
{
|
|
|
|
|
if (player == null)
|
|
|
|
|
{
|
|
|
|
|
shell.SendText((IPlayerSession) null, "Nah");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var mind = player.ContentData().Mind;
|
|
|
|
|
var canReturn = player.AttachedEntity != null;
|
2020-03-30 01:16:44 +02:00
|
|
|
var name = player.AttachedEntity?.Name ?? player.Name;
|
|
|
|
|
|
|
|
|
|
if (player.AttachedEntity != null && player.AttachedEntity.HasComponent<GhostComponent>())
|
|
|
|
|
return;
|
2020-03-03 20:37:26 +01:00
|
|
|
|
|
|
|
|
if (mind.VisitingEntity != null)
|
|
|
|
|
{
|
|
|
|
|
mind.UnVisit();
|
2020-04-17 19:23:06 +02:00
|
|
|
mind.VisitingEntity.Delete();
|
2020-03-03 20:37:26 +01:00
|
|
|
}
|
|
|
|
|
|
2020-03-30 01:16:44 +02:00
|
|
|
var position = player.AttachedEntity?.Transform.GridPosition ?? IoCManager.Resolve<IGameTicker>().GetObserverSpawnPoint();
|
2020-03-03 20:37:26 +01:00
|
|
|
|
|
|
|
|
if (canReturn && player.AttachedEntity.TryGetComponent(out SpeciesComponent species))
|
|
|
|
|
{
|
|
|
|
|
switch (species.CurrentDamageState)
|
|
|
|
|
{
|
|
|
|
|
case DeadState _:
|
|
|
|
|
canReturn = true;
|
|
|
|
|
break;
|
|
|
|
|
case CriticalState _:
|
|
|
|
|
canReturn = true;
|
|
|
|
|
if (!player.AttachedEntity.TryGetComponent(out DamageableComponent damageable)) break;
|
|
|
|
|
damageable.TakeDamage(DamageType.Total, 100); // TODO: Use airloss/oxyloss instead
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
canReturn = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var entityManager = IoCManager.Resolve<IEntityManager>();
|
|
|
|
|
var ghost = entityManager.SpawnEntity("MobObserver", position);
|
2020-04-18 00:38:19 +02:00
|
|
|
ghost.Name = mind.CharacterName;
|
|
|
|
|
|
2020-03-03 20:37:26 +01:00
|
|
|
var ghostComponent = ghost.GetComponent<GhostComponent>();
|
|
|
|
|
ghostComponent.CanReturnToBody = canReturn;
|
|
|
|
|
|
|
|
|
|
if(canReturn)
|
|
|
|
|
mind.Visit(ghost);
|
|
|
|
|
else
|
|
|
|
|
mind.TransferTo(ghost);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|