34 lines
876 B
C#
Raw Normal View History

using QSB.Messaging;
2021-12-23 17:24:05 -08:00
using QSB.Player;
using QSB.Player.TransformSync;
namespace QSB.Tools.TranslatorTool.Messages;
public class PlayerTranslatorMessage : QSBMessage<bool>
2021-12-23 17:24:05 -08:00
{
static PlayerTranslatorMessage()
2021-12-23 17:24:05 -08:00
{
GlobalMessenger.AddListener(OWEvents.EquipTranslator, () => Handle(true));
GlobalMessenger.AddListener(OWEvents.UnequipTranslator, () => Handle(false));
}
2021-12-23 17:24:05 -08:00
private static void Handle(bool equipped)
{
if (PlayerTransformSync.LocalInstance)
2021-12-23 17:24:05 -08:00
{
new PlayerTranslatorMessage(equipped).Send();
2021-12-23 17:24:05 -08:00
}
}
2021-12-23 17:24:05 -08:00
private PlayerTranslatorMessage(bool equipped) => Value = equipped;
2021-12-23 17:24:05 -08:00
public override void OnReceiveRemote()
{
var player = QSBPlayerManager.GetPlayer(From);
player.TranslatorEquipped = Value;
player.Translator?.ChangeEquipState(Value);
2021-12-23 17:24:05 -08:00
}
public override void OnReceiveLocal() =>
QSBPlayerManager.LocalPlayer.TranslatorEquipped = Value;
2021-12-23 17:24:05 -08:00
}