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

39 lines
1.2 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-08-13 19:46:16 +00:00
namespace QSB.DeathSync
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
{
public override MessageType Type => MessageType.PlayerDeath;
2020-08-09 11:38:35 +00:00
public override void SetupListener()
{
2020-08-15 19:52:43 +00:00
GlobalMessenger<DeathType>.AddListener(EventNames.QSBPlayerDeath, Handler);
2020-08-09 11:38:35 +00:00
}
2020-08-15 19:55:25 +00:00
2020-08-15 19:32:58 +00:00
public override void CloseListener()
{
2020-08-15 19:52:43 +00:00
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);
DebugLog.ToAll(string.Format(deathMessage, playerName));
}
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
}
}