mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-18 13:23:05 +00:00
fix
This commit is contained in:
parent
be117ccc40
commit
c6621f715b
@ -1,23 +1,30 @@
|
||||
using QSB.Events;
|
||||
using QSB.Messaging;
|
||||
using QSB.Utility;
|
||||
using System;
|
||||
|
||||
namespace QSB.Instruments.Events
|
||||
{
|
||||
public class PlayInstrumentEvent : QSBEvent<PlayInstrumentMessage>
|
||||
{
|
||||
public override EventType Type => EventType.FullStateRequest;
|
||||
public override EventType Type => EventType.PlayInstrument;
|
||||
|
||||
public override void SetupListener() => GlobalMessenger<InstrumentType, bool>.AddListener(EventNames.QSBPlayerStatesRequest, Handler);
|
||||
public override void SetupListener() => GlobalMessenger<InstrumentType>.AddListener(EventNames.QSBPlayInstrument, Handler);
|
||||
|
||||
public override void CloseListener() => GlobalMessenger<InstrumentType, bool>.RemoveListener(EventNames.QSBPlayerStatesRequest, Handler);
|
||||
public override void CloseListener() => GlobalMessenger<InstrumentType>.RemoveListener(EventNames.QSBPlayInstrument, Handler);
|
||||
|
||||
private void Handler(InstrumentType type, bool state) => SendEvent(CreateMessage(type, state));
|
||||
private void Handler(InstrumentType type) => SendEvent(CreateMessage(type));
|
||||
|
||||
private PlayInstrumentMessage CreateMessage(InstrumentType type, bool state) => new PlayInstrumentMessage
|
||||
private PlayInstrumentMessage CreateMessage(InstrumentType type) => new PlayInstrumentMessage
|
||||
{
|
||||
AboutId = LocalPlayerId,
|
||||
Type = type,
|
||||
State = state
|
||||
Type = type
|
||||
};
|
||||
|
||||
public override void OnReceiveRemote(PlayInstrumentMessage message)
|
||||
{
|
||||
PlayerRegistry.GetPlayer(message.AboutId).CurrentInstrument = message.Type;
|
||||
DebugLog.DebugWrite($"Player ID {message.AboutId} now playing instrument {Enum.GetName(typeof(InstrumentType), message.Type)}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,20 +6,17 @@ namespace QSB.Instruments.Events
|
||||
public class PlayInstrumentMessage : PlayerMessage
|
||||
{
|
||||
public InstrumentType Type;
|
||||
public bool State;
|
||||
|
||||
public override void Deserialize(NetworkReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
Type = (InstrumentType)reader.ReadInt32();
|
||||
State = reader.ReadBoolean();
|
||||
}
|
||||
|
||||
public override void Serialize(NetworkWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
writer.Write((int)Type);
|
||||
writer.Write(State);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,14 +21,20 @@ namespace QSB.Instruments
|
||||
if (!PlayerRegistry.LocalPlayer.PlayingInstrument)
|
||||
{
|
||||
CameraManager.Instance.SwitchTo3rdPerson();
|
||||
GlobalMessenger<InstrumentType, bool>.FireEvent(EventNames.QSBPlayInstrument, InstrumentType.REIBECK, true);
|
||||
SwitchToInstrument(InstrumentType.REIBECK);
|
||||
}
|
||||
else
|
||||
{
|
||||
CameraManager.Instance.SwitchTo1stPerson();
|
||||
GlobalMessenger<InstrumentType, bool>.FireEvent(EventNames.QSBPlayInstrument, InstrumentType.REIBECK, false);
|
||||
SwitchToInstrument(InstrumentType.NONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SwitchToInstrument(InstrumentType type)
|
||||
{
|
||||
PlayerRegistry.LocalPlayer.CurrentInstrument = type;
|
||||
GlobalMessenger<InstrumentType>.FireEvent(EventNames.QSBPlayInstrument, type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,7 @@
|
||||
OrbSlot,
|
||||
OrbUser,
|
||||
Conversation,
|
||||
ConversationStartEnd
|
||||
ConversationStartEnd,
|
||||
PlayInstrument
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user