quantum-space-buddies/QSB/Events/PlayerSuitEvent.cs
2020-08-10 18:17:54 +02:00

33 lines
1009 B
C#

using QSB.Messaging;
namespace QSB.Events
{
public class PlayerSuitEvent : QSBEvent<ToggleMessage>
{
public override MessageType Type => MessageType.SuitActiveChange;
public override void SetupListener()
{
GlobalMessenger.AddListener("SuitUp", () => SendEvent(CreateMessage(true)));
GlobalMessenger.AddListener("RemoveSuit", () => SendEvent(CreateMessage(false)));
}
private ToggleMessage CreateMessage(bool value) => new ToggleMessage
{
SenderId = LocalPlayerId,
ToggleValue = value
};
public override void OnReceiveRemote(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);
}
}
}