52 lines
1.2 KiB
C#
Raw Normal View History

2021-12-22 20:45:25 -08:00
using QSB.ClientServerStateSync;
using QSB.Messaging;
using QSB.Player;
using QSB.RespawnSync;
using QSB.Utility;
using QuantumUNET.Transport;
2021-12-23 02:17:56 -08:00
namespace QSB.DeathSync.Messages
{
2021-12-22 20:45:25 -08:00
public class PlayerDeathMessage : QSBEnumMessage<DeathType>
{
2021-12-22 20:45:25 -08:00
private int NecronomiconIndex;
2021-12-31 11:06:16 +00:00
public PlayerDeathMessage(DeathType type)
{
Value = type;
NecronomiconIndex = Necronomicon.GetRandomIndex(type);
}
2021-12-22 20:45:25 -08:00
public override void Serialize(QNetworkWriter writer)
{
base.Serialize(writer);
writer.Write(NecronomiconIndex);
}
public override void Deserialize(QNetworkReader reader)
{
base.Deserialize(reader);
NecronomiconIndex = reader.ReadInt32();
}
2021-12-22 20:45:25 -08:00
public override void OnReceiveLocal()
{
2021-12-22 20:45:25 -08:00
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));
}
2021-12-22 20:45:25 -08:00
RespawnManager.Instance.OnPlayerDeath(player);
}
}
2021-12-22 20:45:25 -08:00
}