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

31 lines
1.1 KiB
C#
Raw Normal View History

2020-12-14 16:24:52 +00:00
using QSB.Events;
2020-12-14 16:28:03 +00:00
using QSB.Messaging;
2020-11-03 21:33:48 +00:00
using QSB.Player;
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-12-02 21:23:01 +00:00
public class PlayerDeathEvent : QSBEvent<EnumMessage<DeathType>>
{
public override EventType Type => EventType.PlayerDeath;
2020-08-09 11:38:35 +00: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 19:32:58 +00:00
2020-12-02 21:23:01 +00:00
private void Handler(DeathType type) => SendEvent(CreateMessage(type));
2020-08-15 19:52:43 +00:00
2020-12-02 21:23:01 +00:00
private EnumMessage<DeathType> CreateMessage(DeathType type) => new EnumMessage<DeathType>
{
AboutId = LocalPlayerId,
Value = type
};
2020-08-10 16:17:54 +00:00
2020-12-11 22:42:21 +00:00
public override void OnReceiveRemote(bool server, EnumMessage<DeathType> message)
2020-12-02 21:23:01 +00:00
{
var playerName = QSBPlayerManager.GetPlayer(message.AboutId).Name;
2021-02-07 11:26:13 +00:00
// TODO : this is random per client! change this event so it sends the message index and the deathtype?
2020-12-02 21:23:01 +00:00
var deathMessage = Necronomicon.GetPhrase(message.Value);
DebugLog.ToAll(string.Format(deathMessage, playerName));
}
}
2020-12-03 08:28:05 +00:00
}