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

41 lines
920 B
C#
Raw Normal View History

2021-12-23 06:09:00 +00:00
using QSB.ClientServerStateSync;
using QSB.Messaging;
using QSB.Player;
using QuantumUNET.Transport;
namespace QSB.RespawnSync.Events
{
internal class PlayerRespawnMessage : QSBMessage
{
private uint PlayerId;
public PlayerRespawnMessage(uint playerId) => PlayerId = playerId;
public PlayerRespawnMessage() { }
public override void Serialize(QNetworkWriter writer)
{
base.Serialize(writer);
writer.Write(PlayerId);
}
public override void Deserialize(QNetworkReader reader)
{
base.Deserialize(reader);
PlayerId = reader.ReadUInt32();
}
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));
}
}
}