Player post-spawn hook and player ghosting controlled by preset (#2734)

* GamePreset: Add a hook to catch all player spawns for modification.

Unless someone makes the entire job system unpluggable, this is what you get...

* GamePreset: Is now in control of voluntary ghosting

* Clean up ghost code to only rely on a player's Mind
This commit is contained in:
20kdc
2020-12-11 01:10:55 +00:00
committed by GitHub
parent adc972f9d3
commit 31b39823ad
5 changed files with 107 additions and 56 deletions

View File

@@ -27,71 +27,22 @@ namespace Content.Server.Commands.Observer
{
if (player == null)
{
shell.SendText(player, "Nah");
shell?.SendText(player, "You have no session, you can't ghost.");
return;
}
var mind = player.ContentData()?.Mind;
var mind = player!.ContentData()?.Mind;
if (mind == null)
{
shell.SendText(player, "You can't ghost here!");
shell?.SendText(player, "You have no Mind, you can't ghost.");
return;
}
var playerEntity = player.AttachedEntity;
if (playerEntity != null && playerEntity.HasComponent<GhostComponent>())
if (!IoCManager.Resolve<IGameTicker>().OnGhostAttempt(mind, CanReturn))
{
shell?.SendText(player, "You can't ghost right now.");
return;
if (mind.VisitingEntity != null)
{
mind.UnVisit();
mind.VisitingEntity.Delete();
}
var position = playerEntity?.Transform.Coordinates ?? IoCManager.Resolve<IGameTicker>().GetObserverSpawnPoint();
var canReturn = false;
if (playerEntity != null && CanReturn && playerEntity.TryGetComponent(out IMobStateComponent? mobState))
{
if (mobState.IsDead())
{
canReturn = true;
}
else if (mobState.IsCritical())
{
canReturn = true;
if (playerEntity.TryGetComponent(out IDamageableComponent? damageable))
{
//todo: what if they dont breathe lol
damageable.ChangeDamage(DamageType.Asphyxiation, 100, true);
}
}
else
{
canReturn = false;
}
}
var entityManager = IoCManager.Resolve<IEntityManager>();
var ghost = entityManager.SpawnEntity("MobObserver", position);
ghost.Name = mind.CharacterName;
var ghostComponent = ghost.GetComponent<GhostComponent>();
ghostComponent.CanReturnToBody = canReturn;
if (playerEntity != null &&
playerEntity.TryGetComponent(out ServerOverlayEffectsComponent? overlayComponent))
{
overlayComponent.RemoveOverlay(SharedOverlayID.CircleMaskOverlay);
}
if (canReturn)
mind.Visit(ghost);
else
mind.TransferTo(ghost);
}
}
}