quantum-space-buddies/QSB/Events/PlayerReadyEvent.cs
Mister_Nebula c43ef10962 cleanup
2020-08-10 17:30:12 +01:00

27 lines
754 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("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();
}
}
}