using QSB.Messaging; namespace QSB.Events { public class PlayerReadyEvent : QSBEvent { public override EventType Type => EventType.PlayerReady; public override void SetupListener() { GlobalMessenger.AddListener(EventNames.QSBPlayerReady, Handler); } public override void CloseListener() { GlobalMessenger.RemoveListener(EventNames.QSBPlayerReady, Handler); } private void Handler(bool ready) => SendEvent(CreateMessage(ready)); private ToggleMessage CreateMessage(bool ready) => new ToggleMessage { AboutId = LocalPlayerId, ToggleValue = ready }; public override void OnServerReceive(ToggleMessage message) { PlayerRegistry.GetPlayer(message.AboutId).IsReady = message.ToggleValue; PlayerState.LocalInstance.Send(); } } }