From 81dc92ce9bf74a2447fdb43a6d605d9dff0b74ab Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 11 Nov 2021 11:17:23 -0400 Subject: [PATCH] Fix for death timer resetting after returning to body. (#5174) --- Content.Server/Body/BodySystem.cs | 7 +++++++ Content.Server/GameTicking/Presets/GamePreset.cs | 6 ++++++ Content.Server/Mind/Mind.cs | 7 +++++++ 3 files changed, 20 insertions(+) diff --git a/Content.Server/Body/BodySystem.cs b/Content.Server/Body/BodySystem.cs index cb96f3edb4..be7d62b46c 100644 --- a/Content.Server/Body/BodySystem.cs +++ b/Content.Server/Body/BodySystem.cs @@ -4,12 +4,14 @@ using Content.Shared.MobState.Components; using Content.Shared.Movement.EntitySystems; using Robust.Shared.GameObjects; using Robust.Shared.IoC; +using Robust.Shared.Timing; namespace Content.Server.Body { public sealed class BodySystem : EntitySystem { [Dependency] private readonly GameTicker _ticker = default!; + [Dependency] private readonly IGameTiming _gameTiming = default!; public override void Initialize() { @@ -24,6 +26,11 @@ namespace Content.Server.Body EntityManager.TryGetComponent(uid, out var mind) && mind.HasMind) { + if (!mind.Mind!.TimeOfDeath.HasValue) + { + mind.Mind.TimeOfDeath = _gameTiming.RealTime; + } + _ticker.OnGhostAttempt(mind.Mind!, true); } } diff --git a/Content.Server/GameTicking/Presets/GamePreset.cs b/Content.Server/GameTicking/Presets/GamePreset.cs index 7f290ed31b..28f2650238 100644 --- a/Content.Server/GameTicking/Presets/GamePreset.cs +++ b/Content.Server/GameTicking/Presets/GamePreset.cs @@ -83,6 +83,12 @@ namespace Content.Server.GameTicking.Presets ghost.Name = mind.Session.Name; var ghostComponent = ghost.GetComponent(); + + if (mind.TimeOfDeath.HasValue) + { + ghostComponent.TimeOfDeath = mind.TimeOfDeath!.Value; + } + EntitySystem.Get().SetCanReturnToBody(ghostComponent, canReturn); if (canReturn) diff --git a/Content.Server/Mind/Mind.cs b/Content.Server/Mind/Mind.cs index 6a6e5db730..b4986b0808 100644 --- a/Content.Server/Mind/Mind.cs +++ b/Content.Server/Mind/Mind.cs @@ -63,6 +63,12 @@ namespace Content.Server.Mind [ViewVariables(VVAccess.ReadWrite)] public string? CharacterName { get; set; } + /// + /// The time of death for this Mind. + /// Can be null - will be null if the Mind is not considered "dead". + /// + [ViewVariables] public TimeSpan? TimeOfDeath { get; set; } = null; + /// /// The component currently owned by this mind. /// Can be null. @@ -116,6 +122,7 @@ namespace Content.Server.Mind /// [ViewVariables] public bool CharacterDeadIC => CharacterDeadPhysically; + /// /// True if the OwnedEntity of this mind is physically dead. /// This specific definition, as opposed to CharacterDeadIC, is used to determine if ghosting should allow return.