quantum-space-buddies/QSB/Events/PlayerReadyEvent.cs
2020-08-10 19:24:28 +02:00

27 lines
763 B
C#

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