Skip to content

Commit

Permalink
Update: hopefully fixed respawn timers for real this time
Browse files Browse the repository at this point in the history
  • Loading branch information
AWF committed Mar 31, 2024
1 parent 03f5243 commit a276fbe
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Content.Server/Ghost/Components/GhostComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public sealed class GhostComponent : SharedGhostComponent
{
public TimeSpan TimeOfDeath { get; set; } = TimeSpan.Zero;

public float TimeSinceDeath = 0f;

[DataField("respawnTime")]
public float RespawnTime = 600f;

Expand Down
19 changes: 16 additions & 3 deletions Content.Server/Ghost/GhostSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,22 @@ public override void Update(float frameTime)
{
foreach (var ghost in EntityManager.EntityQuery<GhostComponent, SharedGhostComponent>(true))
{
var elapsedSinceDeath = _gameTiming.CurTime - ghost.Item1.TimeOfDeath;
var timeRemaining = ghost.Item1.RespawnTime - (float)elapsedSinceDeath.TotalSeconds;

if (!EntityManager.TryGetComponent(ghost.Item1.Owner, out ActorComponent? actor))
var timeRemaining = 0f;

if (EntityManager.TryGetComponent(ghost.Item1.Owner, out ActorComponent? actor))
{
var playerData = actor.PlayerSession.ContentData();
if (playerData is not null && playerData.Mind is not null)
{
playerData.Mind.TimeSinceGhost += frameTime;
timeRemaining = ghost.Item1.RespawnTime - playerData.Mind.TimeSinceGhost;
}
}
else
{
SetCanGhostRespawn(ghost.Item2, false, 0);
}

var autoClonerAvailable = false;

Expand Down Expand Up @@ -258,6 +269,8 @@ private void OnGhostRespawnRequest(GhostRespawnRequest msg, EntitySessionEventAr
break;
}
}

mind.TimeSinceGhost = 0f;
}

private void OnGhostWarpToTargetRequest(GhostWarpToTargetRequestEvent msg, EntitySessionEventArgs args)
Expand Down
1 change: 1 addition & 0 deletions Content.Server/Mind/Components/MindComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public sealed class MindComponent : Component
[ViewVariables(VVAccess.ReadWrite)]
[DataField("ghostOnShutdown")]
public bool GhostOnShutdown { get; set; } = true;

}

public sealed class MindRemovedMessage : EntityEventArgs
Expand Down
3 changes: 3 additions & 0 deletions Content.Server/Mind/Mind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ public Mind(NetUserId userId)
[ViewVariables]
public TimeSpan? TimeOfDeath { get; set; } = null;

[ViewVariables]
public float TimeSinceGhost = 0f;

/// <summary>
/// The component currently owned by this mind.
/// Can be null.
Expand Down

0 comments on commit a276fbe

Please sign in to comment.