From 1a1d34ad713a4cbae732983a675c9f2ce19aaee3 Mon Sep 17 00:00:00 2001 From: FN Date: Sat, 1 Jun 2024 13:03:30 +0700 Subject: [PATCH 1/2] Fixed visual bug --- .../Corvax/Respawn/RespawnSystem.cs | 34 ++++++++++++------- .../_NF/Commands/GhostRespawnCommand.cs | 2 +- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/Content.Server/Corvax/Respawn/RespawnSystem.cs b/Content.Server/Corvax/Respawn/RespawnSystem.cs index 5b9b84bbe4a..c83abac8b0e 100644 --- a/Content.Server/Corvax/Respawn/RespawnSystem.cs +++ b/Content.Server/Corvax/Respawn/RespawnSystem.cs @@ -5,7 +5,7 @@ using Content.Shared.Mobs; using Content.Shared.Mobs.Components; using Robust.Server.Player; -using Robust.Shared.Network; +using Robust.Shared.Player; using Robust.Shared.Timing; namespace Content.Server.Corvax.Respawn; @@ -15,13 +15,15 @@ public sealed class RespawnSystem : EntitySystem [Dependency] private readonly IPlayerManager _player = default!; [Dependency] private readonly IGameTiming _timing = default!; - private readonly Dictionary _respawnResetTimes = []; + private readonly Dictionary _respawnResetTimes = []; public override void Initialize() { SubscribeLocalEvent(OnMobStateChanged); SubscribeLocalEvent(OnMindRemoved); SubscribeLocalEvent(OnRoundRestartCleanup); + + _player.PlayerStatusChanged += OnPlayerStatusChanged; } private void OnMobStateChanged(MobStateChangedEvent e) @@ -32,7 +34,7 @@ private void OnMobStateChanged(MobStateChangedEvent e) if (!_player.TryGetSessionByEntity(e.Target, out var session)) return; - ResetRespawnTime(e.Target, session.UserId); + ResetRespawnTime(e.Target, session); } private void OnMindRemoved(EntityUid entity, MindContainerComponent component, MindRemovedMessage e) @@ -43,36 +45,42 @@ private void OnMindRemoved(EntityUid entity, MindContainerComponent component, M if (TryComp(entity, out var state) && state.CurrentState == MobState.Dead) return; - ResetRespawnTime(entity, e.Mind.Comp.UserId.Value); + ResetRespawnTime(entity, _player.GetSessionById(e.Mind.Comp.UserId.Value)); } private void OnRoundRestartCleanup(RoundRestartCleanupEvent e) { - foreach (var player in _respawnResetTimes.Keys) - SendRespawnResetTime(player, null); + foreach (var session in _respawnResetTimes.Keys) + SendRespawnResetTime(session, null); _respawnResetTimes.Clear(); } - private void ResetRespawnTime(EntityUid entity, NetUserId player) + private void OnPlayerStatusChanged(object? sender, SessionStatusEventArgs e) + { + if (e.NewStatus == Robust.Shared.Enums.SessionStatus.Connected) + SendRespawnResetTime(e.Session, GetRespawnResetTime(e.Session)); + } + + private void ResetRespawnTime(EntityUid entity, ICommonSession session) { if (!HasComp(entity)) return; - ref var respawnTime = ref CollectionsMarshal.GetValueRefOrAddDefault(_respawnResetTimes, player, out _); + ref var respawnTime = ref CollectionsMarshal.GetValueRefOrAddDefault(_respawnResetTimes, session, out _); respawnTime = _timing.CurTime; - SendRespawnResetTime(player, _timing.CurTime); + SendRespawnResetTime(session, _timing.CurTime); } - private void SendRespawnResetTime(NetUserId player, TimeSpan? time) + private void SendRespawnResetTime(ICommonSession session, TimeSpan? time) { - RaiseNetworkEvent(new RespawnResetEvent(time), _player.GetSessionById(player)); + RaiseNetworkEvent(new RespawnResetEvent(time), session); } - public TimeSpan? GetRespawnResetTime(NetUserId user) + public TimeSpan? GetRespawnResetTime(ICommonSession session) { - return _respawnResetTimes.TryGetValue(user, out var time) ? time : null; + return _respawnResetTimes.TryGetValue(session, out var time) ? time : null; } } diff --git a/Content.Server/_NF/Commands/GhostRespawnCommand.cs b/Content.Server/_NF/Commands/GhostRespawnCommand.cs index b9dd6b069f2..b926617d6c9 100644 --- a/Content.Server/_NF/Commands/GhostRespawnCommand.cs +++ b/Content.Server/_NF/Commands/GhostRespawnCommand.cs @@ -60,7 +60,7 @@ public void Execute(IConsoleShell shell, string argStr, string[] args) return; } - var respawnResetTime = _entity.GetEntitySystem().GetRespawnResetTime(shell.Player.UserId); + var respawnResetTime = _entity.GetEntitySystem().GetRespawnResetTime(shell.Player); if (respawnResetTime is not null) { From 0e613c56afc7290f4785b198395775a373bf2b8f Mon Sep 17 00:00:00 2001 From: FN Date: Tue, 9 Jul 2024 09:47:27 +0700 Subject: [PATCH 2/2] Removed possibly redundant time send --- Content.Server/Corvax/Respawn/RespawnSystem.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/Content.Server/Corvax/Respawn/RespawnSystem.cs b/Content.Server/Corvax/Respawn/RespawnSystem.cs index c83abac8b0e..6037ee716a8 100644 --- a/Content.Server/Corvax/Respawn/RespawnSystem.cs +++ b/Content.Server/Corvax/Respawn/RespawnSystem.cs @@ -50,9 +50,6 @@ private void OnMindRemoved(EntityUid entity, MindContainerComponent component, M private void OnRoundRestartCleanup(RoundRestartCleanupEvent e) { - foreach (var session in _respawnResetTimes.Keys) - SendRespawnResetTime(session, null); - _respawnResetTimes.Clear(); }