2021-04-27 21:49:12 +00:00
|
|
|
|
using QSB.Events;
|
2020-12-14 16:28:03 +00:00
|
|
|
|
using QSB.Messaging;
|
2020-11-03 21:33:48 +00:00
|
|
|
|
using QSB.Player;
|
2020-08-09 20:46:51 +00:00
|
|
|
|
|
2021-04-26 13:30:21 +00:00
|
|
|
|
namespace QSB.Animation.Player.Events
|
2020-08-09 20:46:51 +00:00
|
|
|
|
{
|
2020-12-02 21:23:01 +00:00
|
|
|
|
public class PlayerSuitEvent : QSBEvent<ToggleMessage>
|
|
|
|
|
{
|
|
|
|
|
public override EventType Type => EventType.SuitActiveChange;
|
|
|
|
|
|
|
|
|
|
public override void SetupListener()
|
|
|
|
|
{
|
|
|
|
|
GlobalMessenger.AddListener(EventNames.SuitUp, HandleSuitUp);
|
|
|
|
|
GlobalMessenger.AddListener(EventNames.RemoveSuit, HandleSuitDown);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void CloseListener()
|
|
|
|
|
{
|
|
|
|
|
GlobalMessenger.RemoveListener(EventNames.SuitUp, HandleSuitUp);
|
|
|
|
|
GlobalMessenger.RemoveListener(EventNames.RemoveSuit, HandleSuitDown);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void HandleSuitUp() => SendEvent(CreateMessage(true));
|
|
|
|
|
private void HandleSuitDown() => SendEvent(CreateMessage(false));
|
|
|
|
|
|
|
|
|
|
private ToggleMessage CreateMessage(bool value) => new ToggleMessage
|
|
|
|
|
{
|
|
|
|
|
AboutId = LocalPlayerId,
|
|
|
|
|
ToggleValue = value
|
|
|
|
|
};
|
|
|
|
|
|
2020-12-11 22:42:21 +00:00
|
|
|
|
public override void OnReceiveRemote(bool server, ToggleMessage message)
|
2020-12-02 21:23:01 +00:00
|
|
|
|
{
|
|
|
|
|
var player = QSBPlayerManager.GetPlayer(message.AboutId);
|
2021-04-18 17:42:22 +00:00
|
|
|
|
player.PlayerStates.SuitedUp = message.ToggleValue;
|
2020-12-02 21:23:01 +00:00
|
|
|
|
|
2021-05-08 15:57:01 +00:00
|
|
|
|
if (!QSBCore.WorldObjectsReady || !player.PlayerStates.IsReady)
|
2020-12-02 21:23:01 +00:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var animator = player.AnimationSync;
|
|
|
|
|
var type = message.ToggleValue ? AnimationType.PlayerSuited : AnimationType.PlayerUnsuited;
|
|
|
|
|
animator.SetAnimationType(type);
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-11 22:42:21 +00:00
|
|
|
|
public override void OnReceiveLocal(bool server, ToggleMessage message)
|
2020-12-02 21:23:01 +00:00
|
|
|
|
{
|
2021-04-18 17:42:22 +00:00
|
|
|
|
QSBPlayerManager.LocalPlayer.PlayerStates.SuitedUp = message.ToggleValue;
|
2020-12-02 21:23:01 +00:00
|
|
|
|
var animator = QSBPlayerManager.LocalPlayer.AnimationSync;
|
|
|
|
|
var type = message.ToggleValue ? AnimationType.PlayerSuited : AnimationType.PlayerUnsuited;
|
|
|
|
|
animator.CurrentType = type;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-11-08 16:13:10 +00:00
|
|
|
|
}
|