quantum-space-buddies/QSB/DeathSync/Events/EndLoopEvent.cs
2021-07-31 09:44:56 +01:00

37 lines
1.1 KiB
C#

using QSB.Events;
using QSB.Messaging;
using QSB.Utility;
namespace QSB.DeathSync.Events
{
class EndLoopEvent : QSBEvent<EnumMessage<EndLoopReason>>
{
public override EventType Type => EventType.EndLoop;
public override void SetupListener() => GlobalMessenger<EndLoopReason>.AddListener(EventNames.QSBEndLoop, Handler);
public override void CloseListener() => GlobalMessenger<EndLoopReason>.RemoveListener(EventNames.QSBEndLoop, Handler);
private void Handler(EndLoopReason type) => SendEvent(CreateMessage(type));
private EnumMessage<EndLoopReason> CreateMessage(EndLoopReason type) => new EnumMessage<EndLoopReason>
{
AboutId = LocalPlayerId,
EnumValue = type
};
public override void OnReceiveLocal(bool server, EnumMessage<EndLoopReason> message)
=> OnReceiveRemote(server, message);
public override void OnReceiveRemote(bool server, EnumMessage<EndLoopReason> message)
{
switch (message.EnumValue)
{
case EndLoopReason.AllPlayersDead:
DebugLog.DebugWrite($"all players dead");
Locator.GetDeathManager().KillPlayer(DeathType.TimeLoop);
break;
}
}
}
}