2020-08-10 11:45:24 +01:00
|
|
|
|
using QSB.Messaging;
|
|
|
|
|
|
|
|
|
|
namespace QSB.Events
|
|
|
|
|
{
|
2020-08-10 18:17:54 +02:00
|
|
|
|
public class PlayerReadyEvent : QSBEvent<ToggleMessage>
|
2020-08-10 11:45:24 +01:00
|
|
|
|
{
|
|
|
|
|
public override MessageType Type => MessageType.PlayerReady;
|
|
|
|
|
|
|
|
|
|
public override void SetupListener()
|
|
|
|
|
{
|
2020-08-10 18:17:54 +02:00
|
|
|
|
GlobalMessenger<bool>.AddListener("QSBPlayerReady", ready => SendEvent(CreateMessage(ready)));
|
2020-08-10 11:45:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-10 18:17:54 +02:00
|
|
|
|
private ToggleMessage CreateMessage(bool ready) => new ToggleMessage
|
|
|
|
|
{
|
|
|
|
|
SenderId = LocalPlayerId,
|
|
|
|
|
ToggleValue = ready
|
|
|
|
|
};
|
|
|
|
|
|
2020-08-10 11:45:24 +01:00
|
|
|
|
public override void OnServerReceive(ToggleMessage message)
|
|
|
|
|
{
|
|
|
|
|
PlayerRegistry.GetPlayer(message.SenderId).IsReady = message.ToggleValue;
|
|
|
|
|
PlayerState.LocalInstance.Send();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|