2021-12-26 00:53:43 -08:00
|
|
|
|
using QSB.Messaging;
|
2021-12-23 18:55:22 -08:00
|
|
|
|
using QSB.Player;
|
|
|
|
|
using QSB.Player.TransformSync;
|
|
|
|
|
|
2022-02-24 22:04:54 -08:00
|
|
|
|
namespace QSB.Tools.SignalscopeTool.Messages;
|
|
|
|
|
|
|
|
|
|
public class PlayerSignalscopeMessage : QSBMessage<bool>
|
2021-12-23 18:55:22 -08:00
|
|
|
|
{
|
2022-02-24 22:04:54 -08:00
|
|
|
|
static PlayerSignalscopeMessage()
|
2021-12-23 18:55:22 -08:00
|
|
|
|
{
|
2022-02-24 22:04:54 -08:00
|
|
|
|
GlobalMessenger<Signalscope>.AddListener(OWEvents.EquipSignalscope, _ => Handle(true));
|
|
|
|
|
GlobalMessenger.AddListener(OWEvents.UnequipSignalscope, () => Handle(false));
|
|
|
|
|
}
|
2021-12-23 18:55:22 -08:00
|
|
|
|
|
2022-02-24 22:04:54 -08:00
|
|
|
|
private static void Handle(bool equipped)
|
|
|
|
|
{
|
|
|
|
|
if (PlayerTransformSync.LocalInstance)
|
2021-12-23 18:55:22 -08:00
|
|
|
|
{
|
2022-02-24 22:04:54 -08:00
|
|
|
|
new PlayerSignalscopeMessage(equipped).Send();
|
2021-12-23 18:55:22 -08:00
|
|
|
|
}
|
2022-02-24 22:04:54 -08:00
|
|
|
|
}
|
2021-12-23 18:55:22 -08:00
|
|
|
|
|
2022-02-24 22:04:54 -08:00
|
|
|
|
private PlayerSignalscopeMessage(bool equipped) => Value = equipped;
|
2021-12-23 18:55:22 -08:00
|
|
|
|
|
2022-02-24 22:04:54 -08:00
|
|
|
|
public override void OnReceiveRemote()
|
|
|
|
|
{
|
|
|
|
|
var player = QSBPlayerManager.GetPlayer(From);
|
|
|
|
|
player.SignalscopeEquipped = Value;
|
|
|
|
|
player.Signalscope?.ChangeEquipState(Value);
|
2021-12-23 18:55:22 -08:00
|
|
|
|
}
|
2022-02-24 22:04:54 -08:00
|
|
|
|
|
|
|
|
|
public override void OnReceiveLocal() =>
|
|
|
|
|
QSBPlayerManager.LocalPlayer.SignalscopeEquipped = Value;
|
2021-12-23 18:55:22 -08:00
|
|
|
|
}
|