41 lines
1.4 KiB
C#
Raw Normal View History

2021-08-08 19:57:58 +01:00
using QSB.ClientServerStateSync;
using QSB.Events;
2020-11-03 21:33:48 +00:00
using QSB.Player;
2020-08-09 12:38:35 +01:00
using QSB.Utility;
2020-08-09 12:19:51 +01:00
2020-11-03 17:56:48 +00:00
namespace QSB.DeathSync.Events
2020-08-09 12:19:51 +01:00
{
public class PlayerDeathEvent : QSBEvent<PlayerDeathMessage>
2020-12-02 21:23:01 +00:00
{
public override EventType Type => EventType.PlayerDeath;
2020-08-09 12:38:35 +01:00
2020-12-02 21:23:01 +00:00
public override void SetupListener() => GlobalMessenger<DeathType>.AddListener(EventNames.QSBPlayerDeath, Handler);
public override void CloseListener() => GlobalMessenger<DeathType>.RemoveListener(EventNames.QSBPlayerDeath, Handler);
2020-08-15 20:32:58 +01:00
2020-12-02 21:23:01 +00:00
private void Handler(DeathType type) => SendEvent(CreateMessage(type));
2020-08-15 21:52:43 +02:00
private PlayerDeathMessage CreateMessage(DeathType type) => new PlayerDeathMessage
2020-12-02 21:23:01 +00:00
{
AboutId = LocalPlayerId,
2021-03-29 14:36:16 +01:00
EnumValue = type,
NecronomiconIndex = Necronomicon.GetRandomIndex(type)
2020-12-02 21:23:01 +00:00
};
2020-08-10 18:17:54 +02:00
2021-06-23 12:06:08 +01:00
public override void OnReceiveLocal(bool server, PlayerDeathMessage message)
{
var player = QSBPlayerManager.GetPlayer(message.AboutId);
RespawnManager.Instance.OnPlayerDeath(player);
2021-08-08 19:57:58 +01:00
ClientStateManager.Instance.OnDeath();
2021-06-23 12:06:08 +01:00
}
public override void OnReceiveRemote(bool server, PlayerDeathMessage message)
2020-12-02 21:23:01 +00:00
{
2021-06-23 12:06:08 +01:00
var player = QSBPlayerManager.GetPlayer(message.AboutId);
var playerName = player.Name;
2021-03-29 14:36:16 +01:00
var deathMessage = Necronomicon.GetPhrase(message.EnumValue, message.NecronomiconIndex);
2020-12-02 21:23:01 +00:00
DebugLog.ToAll(string.Format(deathMessage, playerName));
2021-06-23 12:06:08 +01:00
RespawnManager.Instance.OnPlayerDeath(player);
2020-12-02 21:23:01 +00:00
}
}
2020-12-03 08:28:05 +00:00
}