quantum-space-buddies/QSB/Events/PlayerSuitEvent.cs

33 lines
1009 B
C#
Raw Normal View History

2020-08-09 21:46:51 +01:00
using QSB.Messaging;
namespace QSB.Events
{
2020-08-10 18:17:54 +02:00
public class PlayerSuitEvent : QSBEvent<ToggleMessage>
2020-08-09 21:46:51 +01:00
{
public override MessageType Type => MessageType.SuitActiveChange;
public override void SetupListener()
{
2020-08-10 18:17:54 +02:00
GlobalMessenger.AddListener("SuitUp", () => SendEvent(CreateMessage(true)));
GlobalMessenger.AddListener("RemoveSuit", () => SendEvent(CreateMessage(false)));
2020-08-09 21:46:51 +01:00
}
2020-08-10 18:17:54 +02:00
private ToggleMessage CreateMessage(bool value) => new ToggleMessage
{
SenderId = LocalPlayerId,
ToggleValue = value
};
2020-08-10 14:40:06 +01:00
public override void OnReceiveRemote(ToggleMessage message)
2020-08-09 21:46:51 +01:00
{
var player = PlayerRegistry.GetPlayer(message.SenderId);
player.UpdateState(State.Suit, message.ToggleValue);
}
public override void OnReceiveLocal(ToggleMessage message)
{
PlayerRegistry.LocalPlayer.UpdateState(State.Suit, message.ToggleValue);
}
}
}