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