mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-08 18:51:19 +00:00
32 lines
1018 B
C#
32 lines
1018 B
C#
using QSB.Events;
|
|
using QSB.Messaging;
|
|
using QSB.Utility;
|
|
|
|
namespace QSB.DeathSync
|
|
{
|
|
public class PlayerDeathEvent : QSBEvent<PlayerDeathMessage>
|
|
{
|
|
public override MessageType Type => MessageType.PlayerDeath;
|
|
|
|
public override void SetupListener()
|
|
{
|
|
GlobalMessenger<DeathType>.AddListener(EventNames.QSBPlayerDeath, type => SendEvent(CreateMessage(type)));
|
|
}
|
|
|
|
private PlayerDeathMessage CreateMessage(DeathType type) => new PlayerDeathMessage
|
|
{
|
|
SenderId = LocalPlayerId,
|
|
DeathType = type
|
|
};
|
|
|
|
public override void OnReceiveRemote(PlayerDeathMessage message)
|
|
{
|
|
var playerName = PlayerRegistry.GetPlayer(message.SenderId).Name;
|
|
var deathMessage = Necronomicon.GetPhrase(message.DeathType);
|
|
DebugLog.ToAll(string.Format(deathMessage, playerName));
|
|
}
|
|
|
|
public override void OnReceiveLocal(PlayerDeathMessage message) => OnReceiveRemote(message);
|
|
}
|
|
}
|