2022-01-14 07:38:45 +00:00
|
|
|
|
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;
|
2023-06-23 18:22:56 +00:00
|
|
|
|
using UnityEngine;
|
2021-03-07 22:55:56 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
namespace QSB.DeathSync.Messages;
|
|
|
|
|
|
|
|
|
|
public class PlayerDeathMessage : QSBMessage<DeathType>
|
2021-03-07 22:55:56 +00:00
|
|
|
|
{
|
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>();
|
|
|
|
|
}
|
2021-03-07 22:55:56 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
public override void OnReceiveLocal()
|
|
|
|
|
{
|
|
|
|
|
var player = QSBPlayerManager.GetPlayer(From);
|
|
|
|
|
RespawnManager.Instance.OnPlayerDeath(player);
|
|
|
|
|
ClientStateManager.Instance.OnDeath();
|
|
|
|
|
}
|
2021-03-07 22:55:56 +00:00
|
|
|
|
|
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)
|
2021-03-07 22:55:56 +00:00
|
|
|
|
{
|
2023-07-27 18:34:45 +00:00
|
|
|
|
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-03-07 22:55:56 +00:00
|
|
|
|
}
|
2021-12-23 04:45:25 +00:00
|
|
|
|
}
|