mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-04 02:47:22 +00:00
52 lines
1.2 KiB
C#
52 lines
1.2 KiB
C#
using Mirror;
|
|
using QSB.ClientServerStateSync;
|
|
using QSB.Messaging;
|
|
using QSB.Player;
|
|
using QSB.RespawnSync;
|
|
using QSB.Utility;
|
|
|
|
namespace QSB.DeathSync.Messages
|
|
{
|
|
public class PlayerDeathMessage : QSBEnumMessage<DeathType>
|
|
{
|
|
private int NecronomiconIndex;
|
|
|
|
public PlayerDeathMessage(DeathType type)
|
|
{
|
|
Value = type;
|
|
NecronomiconIndex = Necronomicon.GetRandomIndex(type);
|
|
}
|
|
|
|
public override void Serialize(NetworkWriter writer)
|
|
{
|
|
base.Serialize(writer);
|
|
writer.Write(NecronomiconIndex);
|
|
}
|
|
|
|
public override void Deserialize(NetworkReader reader)
|
|
{
|
|
base.Deserialize(reader);
|
|
NecronomiconIndex = reader.Read<int>();
|
|
}
|
|
|
|
public override void OnReceiveLocal()
|
|
{
|
|
var player = QSBPlayerManager.GetPlayer(From);
|
|
RespawnManager.Instance.OnPlayerDeath(player);
|
|
ClientStateManager.Instance.OnDeath();
|
|
}
|
|
|
|
public override void OnReceiveRemote()
|
|
{
|
|
var player = QSBPlayerManager.GetPlayer(From);
|
|
var playerName = player.Name;
|
|
var deathMessage = Necronomicon.GetPhrase(Value, NecronomiconIndex);
|
|
if (deathMessage != null)
|
|
{
|
|
DebugLog.ToAll(string.Format(deathMessage, playerName));
|
|
}
|
|
|
|
RespawnManager.Instance.OnPlayerDeath(player);
|
|
}
|
|
}
|
|
} |