2020-08-13 21:46:16 +02:00
|
|
|
|
using QSB.Events;
|
|
|
|
|
using QSB.Messaging;
|
2020-08-09 21:46:51 +01:00
|
|
|
|
|
2020-08-13 21:46:16 +02:00
|
|
|
|
namespace QSB.Animation
|
2020-08-09 21:46:51 +01:00
|
|
|
|
{
|
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-15 21:52:43 +02:00
|
|
|
|
GlobalMessenger.AddListener(EventNames.SuitUp, HandleSuitUp);
|
|
|
|
|
GlobalMessenger.AddListener(EventNames.RemoveSuit, HandleSuitDown);
|
2020-08-09 21:46:51 +01:00
|
|
|
|
}
|
2020-08-15 21:52:43 +02:00
|
|
|
|
|
2020-08-15 20:32:58 +01:00
|
|
|
|
public override void CloseListener()
|
|
|
|
|
{
|
2020-08-15 21:52:43 +02:00
|
|
|
|
GlobalMessenger.RemoveListener(EventNames.SuitUp, HandleSuitUp);
|
|
|
|
|
GlobalMessenger.RemoveListener(EventNames.RemoveSuit, HandleSuitDown);
|
2020-08-15 20:32:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-15 21:52:43 +02:00
|
|
|
|
private void HandleSuitUp() => SendEvent(CreateMessage(true));
|
|
|
|
|
private void HandleSuitDown() => SendEvent(CreateMessage(false));
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|