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

34 lines
1.0 KiB
C#
Raw Normal View History

2020-08-13 19:46:16 +00:00
using QSB.Events;
using QSB.Messaging;
2020-08-09 20:46:51 +00:00
2020-08-13 19:46:16 +00:00
namespace QSB.Animation
2020-08-09 20:46:51 +00:00
{
2020-08-10 16:17:54 +00:00
public class PlayerSuitEvent : QSBEvent<ToggleMessage>
2020-08-09 20:46:51 +00:00
{
public override MessageType Type => MessageType.SuitActiveChange;
public override void SetupListener()
{
2020-08-10 17:24:28 +00:00
GlobalMessenger.AddListener(EventNames.SuitUp, () => SendEvent(CreateMessage(true)));
GlobalMessenger.AddListener(EventNames.RemoveSuit, () => SendEvent(CreateMessage(false)));
2020-08-09 20:46:51 +00:00
}
2020-08-10 16:17:54 +00:00
private ToggleMessage CreateMessage(bool value) => new ToggleMessage
{
SenderId = LocalPlayerId,
ToggleValue = value
};
2020-08-10 13:40:06 +00:00
public override void OnReceiveRemote(ToggleMessage message)
2020-08-09 20:46:51 +00: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);
}
}
}