35 lines
898 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
2021-12-23 17:24:05 -08:00
{
public class PlayerTranslatorMessage : QSBMessage<bool>
2021-12-23 17:24:05 -08:00
{
static PlayerTranslatorMessage()
{
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)
2021-12-23 17:24:05 -08:00
{
if (PlayerTransformSync.LocalInstance)
{
new PlayerTranslatorMessage(equipped).Send();
}
2021-12-23 17:24:05 -08:00
}
private PlayerTranslatorMessage(bool equipped) => Data = equipped;
2021-12-23 17:24:05 -08:00
public override void OnReceiveRemote()
{
var player = QSBPlayerManager.GetPlayer(From);
player.TranslatorEquipped = Data;
player.Translator?.ChangeEquipState(Data);
}
public override void OnReceiveLocal() =>
QSBPlayerManager.LocalPlayer.TranslatorEquipped = Data;
}
2021-12-23 17:24:05 -08:00
}