quantum-space-buddies/QSB/DeathSync/Messages/PlayerDeathMessage.cs

50 lines
1.2 KiB
C#
Raw Normal View History

using Mirror;
using QSB.ClientServerStateSync;
2023-05-07 20:02:29 +00:00
using QSB.HUD;
2021-12-23 04:45:25 +00:00
using QSB.Messaging;
using QSB.Player;
using QSB.RespawnSync;
using QSB.Utility;
using UnityEngine;
2022-03-03 03:46:33 +00:00
namespace QSB.DeathSync.Messages;
public class PlayerDeathMessage : QSBMessage<DeathType>
{
2022-03-03 03:46:33 +00:00
private int NecronomiconIndex;
2022-03-11 01:57:50 +00:00
public PlayerDeathMessage(DeathType type) : base(type) =>
2022-03-03 03:46:33 +00:00
NecronomiconIndex = Necronomicon.GetRandomIndex(type);
2021-12-23 04:45:25 +00:00
2022-03-03 03:46:33 +00:00
public override void Serialize(NetworkWriter writer)
{
base.Serialize(writer);
writer.Write(NecronomiconIndex);
}
2021-12-23 04:45:25 +00:00
2022-03-03 03:46:33 +00:00
public override void Deserialize(NetworkReader reader)
{
base.Deserialize(reader);
NecronomiconIndex = reader.Read<int>();
}
2022-03-03 03:46:33 +00:00
public override void OnReceiveLocal()
{
var player = QSBPlayerManager.GetPlayer(From);
RespawnManager.Instance.OnPlayerDeath(player);
ClientStateManager.Instance.OnDeath();
}
2022-03-03 03:46:33 +00:00
public override void OnReceiveRemote()
{
var player = QSBPlayerManager.GetPlayer(From);
var playerName = player.Name;
var deathMessage = Necronomicon.GetPhrase(Data, NecronomiconIndex);
if (deathMessage != null)
{
MultiplayerHUDManager.Instance.WriteSystemMessage(string.Format(deathMessage, playerName), Color.grey);
2021-12-23 04:45:25 +00:00
}
2022-03-03 03:46:33 +00:00
RespawnManager.Instance.OnPlayerDeath(player);
}
2021-12-23 04:45:25 +00:00
}