quantum-space-buddies/QSB/DeathSync/Events/PlayerDeathEvent.cs

33 lines
1.1 KiB
C#
Raw Normal View History

2020-08-13 19:46:16 +00:00
using QSB.Events;
using QSB.Messaging;
2020-08-09 11:38:35 +00:00
using QSB.Utility;
2020-08-09 11:19:51 +00:00
2020-11-03 17:56:48 +00:00
namespace QSB.DeathSync.Events
2020-08-09 11:19:51 +00:00
{
2020-08-10 16:17:54 +00:00
public class PlayerDeathEvent : QSBEvent<PlayerDeathMessage>
2020-08-09 11:19:51 +00:00
{
2020-08-22 17:08:25 +00:00
public override EventType Type => EventType.PlayerDeath;
2020-08-09 11:38:35 +00:00
2020-10-22 15:46:01 +00:00
public override void SetupListener() => GlobalMessenger<DeathType>.AddListener(EventNames.QSBPlayerDeath, Handler);
2020-08-15 19:55:25 +00:00
2020-10-22 15:46:01 +00:00
public override void CloseListener() => GlobalMessenger<DeathType>.RemoveListener(EventNames.QSBPlayerDeath, Handler);
2020-08-15 19:32:58 +00:00
2020-08-15 19:52:43 +00:00
private void Handler(DeathType type) => SendEvent(CreateMessage(type));
2020-08-10 16:17:54 +00:00
private PlayerDeathMessage CreateMessage(DeathType type) => new PlayerDeathMessage
{
2020-08-17 15:51:56 +00:00
AboutId = LocalPlayerId,
2020-08-10 16:17:54 +00:00
DeathType = type
};
2020-08-10 13:40:06 +00:00
public override void OnReceiveRemote(PlayerDeathMessage message)
2020-08-09 11:38:35 +00:00
{
2020-08-17 15:51:56 +00:00
var playerName = PlayerRegistry.GetPlayer(message.AboutId).Name;
2020-08-09 11:38:35 +00:00
var deathMessage = Necronomicon.GetPhrase(message.DeathType);
2020-08-24 15:01:33 +00:00
DebugLog.ToAll(string.Format(deathMessage, playerName));
2020-08-09 11:38:35 +00:00
}
2020-08-13 16:44:27 +00:00
2020-08-13 17:27:12 +00:00
public override void OnReceiveLocal(PlayerDeathMessage message) => OnReceiveRemote(message);
2020-08-09 11:19:51 +00:00
}
}