From 45328c1082831c377bf2b9e719b196dc4575b5a9 Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Sat, 13 Aug 2022 11:29:25 +0100 Subject: [PATCH] reworked respawn stuff --- QSB/RespawnSync/RespawnManager.cs | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/QSB/RespawnSync/RespawnManager.cs b/QSB/RespawnSync/RespawnManager.cs index 17a6880d..82a84a7d 100644 --- a/QSB/RespawnSync/RespawnManager.cs +++ b/QSB/RespawnSync/RespawnManager.cs @@ -139,15 +139,16 @@ internal class RespawnManager : MonoBehaviour, IAddComponentOnStart public void OnPlayerDeath(PlayerInfo player) { + player.IsDead = true; + if (_playersPendingRespawn.Contains(player)) { DebugLog.ToConsole($"Warning - Received death message for player who is already in _playersPendingRespawn!", OWML.Common.MessageType.Warning); - return; } - - player.IsDead = true; - - _playersPendingRespawn.Add(player); + else + { + _playersPendingRespawn.Add(player); + } var deadPlayersCount = QSBPlayerManager.PlayerList.Count(x => x.IsDead); @@ -162,15 +163,16 @@ internal class RespawnManager : MonoBehaviour, IAddComponentOnStart public void OnPlayerRespawn(PlayerInfo player) { + player.IsDead = false; + if (!_playersPendingRespawn.Contains(player)) { DebugLog.ToConsole($"Warning - Received respawn message for player who is not in _playersPendingRespawn!", OWML.Common.MessageType.Warning); - return; } - - player.IsDead = false; - - _playersPendingRespawn.Remove(player); + else + { + _playersPendingRespawn.Remove(player); + } player.SetVisible(true, 1); } @@ -178,6 +180,14 @@ internal class RespawnManager : MonoBehaviour, IAddComponentOnStart public void RespawnSomePlayer() { var playerToRespawn = _playersPendingRespawn.First(); + + if (!playerToRespawn.IsDead) + { + DebugLog.ToConsole($"Warning - Tried to respawn player {playerToRespawn.PlayerId} who isn't dead!", OWML.Common.MessageType.Warning); + _playersPendingRespawn.Remove(playerToRespawn); + return; + } + new PlayerRespawnMessage(playerToRespawn.PlayerId).Send(); } } \ No newline at end of file