33 lines
1.1 KiB
C#
Raw Normal View History

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