quantum-space-buddies/QSB/Events/PlayerSuitEvent.cs
2020-08-09 21:46:51 +01:00

38 lines
1.1 KiB
C#

using QSB.Messaging;
using QSB.Utility;
namespace QSB.Events
{
class PlayerSuitEvent : QSBEvent<ToggleMessage>
{
public override MessageType Type => MessageType.SuitActiveChange;
public override void SetupListener()
{
GlobalMessenger.AddListener("SuitUp", () => SendEvent(
new ToggleMessage
{
SenderId = PlayerRegistry.LocalPlayer.NetId,
ToggleValue = true
}));
GlobalMessenger.AddListener("RemoveSuit", () => SendEvent(
new ToggleMessage
{
SenderId = PlayerRegistry.LocalPlayer.NetId,
ToggleValue = false
}));
}
public override void OnReceive(ToggleMessage message)
{
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);
}
}
}