55 lines
1.6 KiB
C#
Raw Normal View History

2021-04-27 22:49:12 +01: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 21:46:51 +01:00
2021-04-26 14:30:21 +01:00
namespace QSB.Animation.Player.Events
2020-08-09 21:46:51 +01:00
{
2020-12-02 21:23:01 +00:00
public class PlayerSuitEvent : QSBEvent<ToggleMessage>
{
public override bool RequireWorldObjectsReady => true;
2020-12-02 21:23:01 +00:00
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));
2021-11-20 19:49:50 +00:00
private ToggleMessage CreateMessage(bool value) => new()
2020-12-02 21:23:01 +00:00
{
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);
player.SuitedUp = message.ToggleValue;
2020-12-02 21:23:01 +00:00
if (!player.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
{
QSBPlayerManager.LocalPlayer.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
}