43 lines
1.3 KiB
C#
Raw Normal View History

using QSB.ClientServerStateSync;
using QSB.Events;
2021-07-31 09:44:56 +01:00
using QSB.Messaging;
using QSB.Utility;
namespace QSB.DeathSync.Events
{
2021-08-09 11:49:58 +01:00
internal class EndLoopEvent : QSBEvent<EnumMessage<EndLoopReason>>
2021-07-31 09:44:56 +01:00
{
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
};
2021-08-22 16:54:48 +01:00
public override void OnReceiveLocal(bool server, EnumMessage<EndLoopReason> message)
2021-07-31 09:44:56 +01:00
=> OnReceiveRemote(server, message);
public override void OnReceiveRemote(bool server, EnumMessage<EndLoopReason> message)
{
DebugLog.DebugWrite($" ~~~~ END LOOP - Reason:{message.EnumValue} ~~~~ ");
2021-07-31 09:44:56 +01:00
switch (message.EnumValue)
{
case EndLoopReason.AllPlayersDead:
Locator.GetDeathManager().KillPlayer(DeathType.TimeLoop);
if (QSBCore.IsHost)
{
QSBEventManager.FireEvent(EventNames.QSBServerState, ServerState.WaitingForAllPlayersToDie);
}
2021-08-22 17:17:46 +01:00
2021-07-31 09:44:56 +01:00
break;
}
}
}
}