2021-12-23 04:45:25 +00:00
|
|
|
|
using QSB.ClientServerStateSync;
|
|
|
|
|
using QSB.Messaging;
|
|
|
|
|
using QSB.Player;
|
|
|
|
|
using QSB.RespawnSync;
|
|
|
|
|
using QSB.Utility;
|
2021-03-07 22:55:56 +00:00
|
|
|
|
using QuantumUNET.Transport;
|
|
|
|
|
|
2021-12-23 10:17:56 +00:00
|
|
|
|
namespace QSB.DeathSync.Messages
|
2021-03-07 22:55:56 +00:00
|
|
|
|
{
|
2021-12-23 04:45:25 +00:00
|
|
|
|
public class PlayerDeathMessage : QSBEnumMessage<DeathType>
|
2021-03-07 22:55:56 +00:00
|
|
|
|
{
|
2021-12-23 04:45:25 +00:00
|
|
|
|
private int NecronomiconIndex;
|
|
|
|
|
|
|
|
|
|
public PlayerDeathMessage(DeathType type) => NecronomiconIndex = Necronomicon.GetRandomIndex(type);
|
|
|
|
|
|
|
|
|
|
public override void Serialize(QNetworkWriter writer)
|
|
|
|
|
{
|
|
|
|
|
base.Serialize(writer);
|
|
|
|
|
writer.Write(NecronomiconIndex);
|
|
|
|
|
}
|
2021-03-07 22:55:56 +00:00
|
|
|
|
|
|
|
|
|
public override void Deserialize(QNetworkReader reader)
|
|
|
|
|
{
|
|
|
|
|
base.Deserialize(reader);
|
|
|
|
|
NecronomiconIndex = reader.ReadInt32();
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-23 04:45:25 +00:00
|
|
|
|
public override void OnReceiveLocal()
|
2021-03-07 22:55:56 +00:00
|
|
|
|
{
|
2021-12-23 04:45:25 +00: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);
|
2021-12-23 20:16:41 +00:00
|
|
|
|
if (deathMessage != string.Empty)
|
|
|
|
|
{
|
|
|
|
|
DebugLog.ToAll(string.Format(deathMessage, playerName));
|
|
|
|
|
}
|
2021-12-23 04:45:25 +00:00
|
|
|
|
|
|
|
|
|
RespawnManager.Instance.OnPlayerDeath(player);
|
2021-03-07 22:55:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-12-23 04:45:25 +00:00
|
|
|
|
}
|