using QSB.ClientServerStateSync; using QSB.Events; using QSB.Messaging; using QSB.Patches; using QSB.Utility; namespace QSB.DeathSync.Events { internal class EndLoopEvent : QSBEvent> { public override bool RequireWorldObjectsReady => false; 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() { AboutId = LocalPlayerId, EnumValue = type }; public override void OnReceiveLocal(bool server, EnumMessage message) => OnReceiveRemote(server, message); public override void OnReceiveRemote(bool server, EnumMessage message) { DebugLog.DebugWrite($" ~~~~ END LOOP - Reason:{message.EnumValue} ~~~~ "); switch (message.EnumValue) { case EndLoopReason.AllPlayersDead: if (ServerStateManager.Instance.GetServerState() == ServerState.WaitingForAllPlayersToDie) { break; } QSBPatchManager.DoUnpatchType(QSBPatchTypes.RespawnTime); Locator.GetDeathManager().KillPlayer(DeathType.TimeLoop); if (QSBCore.IsHost) { ServerStateManager.Instance.FireChangeServerStateEvent(ServerState.WaitingForAllPlayersToDie); } break; } } } }