mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-26 09:35:26 +00:00
fix
This commit is contained in:
parent
be117ccc40
commit
c6621f715b
@ -1,23 +1,30 @@
|
|||||||
using QSB.Events;
|
using QSB.Events;
|
||||||
using QSB.Messaging;
|
using QSB.Messaging;
|
||||||
|
using QSB.Utility;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace QSB.Instruments.Events
|
namespace QSB.Instruments.Events
|
||||||
{
|
{
|
||||||
public class PlayInstrumentEvent : QSBEvent<PlayInstrumentMessage>
|
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,
|
AboutId = LocalPlayerId,
|
||||||
Type = type,
|
Type = type
|
||||||
State = state
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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 class PlayInstrumentMessage : PlayerMessage
|
||||||
{
|
{
|
||||||
public InstrumentType Type;
|
public InstrumentType Type;
|
||||||
public bool State;
|
|
||||||
|
|
||||||
public override void Deserialize(NetworkReader reader)
|
public override void Deserialize(NetworkReader reader)
|
||||||
{
|
{
|
||||||
base.Deserialize(reader);
|
base.Deserialize(reader);
|
||||||
Type = (InstrumentType)reader.ReadInt32();
|
Type = (InstrumentType)reader.ReadInt32();
|
||||||
State = reader.ReadBoolean();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Serialize(NetworkWriter writer)
|
public override void Serialize(NetworkWriter writer)
|
||||||
{
|
{
|
||||||
base.Serialize(writer);
|
base.Serialize(writer);
|
||||||
writer.Write((int)Type);
|
writer.Write((int)Type);
|
||||||
writer.Write(State);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,14 +21,20 @@ namespace QSB.Instruments
|
|||||||
if (!PlayerRegistry.LocalPlayer.PlayingInstrument)
|
if (!PlayerRegistry.LocalPlayer.PlayingInstrument)
|
||||||
{
|
{
|
||||||
CameraManager.Instance.SwitchTo3rdPerson();
|
CameraManager.Instance.SwitchTo3rdPerson();
|
||||||
GlobalMessenger<InstrumentType, bool>.FireEvent(EventNames.QSBPlayInstrument, InstrumentType.REIBECK, true);
|
SwitchToInstrument(InstrumentType.REIBECK);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CameraManager.Instance.SwitchTo1stPerson();
|
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,
|
OrbSlot,
|
||||||
OrbUser,
|
OrbUser,
|
||||||
Conversation,
|
Conversation,
|
||||||
ConversationStartEnd
|
ConversationStartEnd,
|
||||||
|
PlayInstrument
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user