2020-11-03 21:42:14 +00:00
|
|
|
|
using QSB.EventsCore;
|
2020-11-10 09:05:27 +00:00
|
|
|
|
using QSB.MessagesCore;
|
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-11-10 09:05:27 +00:00
|
|
|
|
public class PlayerDeathEvent : QSBEvent<EnumMessage<DeathType>>
|
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-11-10 09:05:27 +00:00
|
|
|
|
private EnumMessage<DeathType> CreateMessage(DeathType type) => new EnumMessage<DeathType>
|
2020-08-10 18:17:54 +02:00
|
|
|
|
{
|
2020-08-17 16:51:56 +01:00
|
|
|
|
AboutId = LocalPlayerId,
|
2020-11-10 09:05:27 +00:00
|
|
|
|
Value = type
|
2020-08-10 18:17:54 +02:00
|
|
|
|
};
|
|
|
|
|
|
2020-11-10 09:05:27 +00:00
|
|
|
|
public override void OnReceiveRemote(EnumMessage<DeathType> 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-11-10 09:05:27 +00:00
|
|
|
|
var deathMessage = Necronomicon.GetPhrase(message.Value);
|
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-11-10 09:05:27 +00:00
|
|
|
|
public override void OnReceiveLocal(EnumMessage<DeathType> message) => OnReceiveRemote(message);
|
2020-08-09 12:19:51 +01:00
|
|
|
|
}
|
|
|
|
|
}
|