quantum-space-buddies/QSB/RespawnSync/Messages/PlayerRespawnMessage.cs

39 lines
868 B
C#
Raw Normal View History

using Mirror;
using QSB.ClientServerStateSync;
2021-12-23 06:09:00 +00:00
using QSB.Messaging;
using QSB.Player;
2021-12-23 21:57:33 +00:00
namespace QSB.RespawnSync.Messages
2021-12-23 06:09:00 +00:00
{
internal class PlayerRespawnMessage : QSBMessage
{
private uint PlayerId;
public PlayerRespawnMessage(uint playerId) => PlayerId = playerId;
public override void Serialize(NetworkWriter writer)
2021-12-23 06:09:00 +00:00
{
base.Serialize(writer);
writer.Write(PlayerId);
}
public override void Deserialize(NetworkReader reader)
2021-12-23 06:09:00 +00:00
{
base.Deserialize(reader);
PlayerId = reader.Read<uint>();
2021-12-23 06:09:00 +00:00
}
public override void OnReceiveLocal() => OnReceiveRemote();
public override void OnReceiveRemote()
{
if (PlayerId == QSBPlayerManager.LocalPlayerId)
{
RespawnManager.Instance.Respawn();
ClientStateManager.Instance.OnRespawn();
}
RespawnManager.Instance.OnPlayerRespawn(QSBPlayerManager.GetPlayer(PlayerId));
}
}
}