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