This commit is contained in:
Mister_Nebula 2020-11-01 15:56:48 +00:00
parent be117ccc40
commit c6621f715b
4 changed files with 24 additions and 13 deletions

View File

@ -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)}");
}
}
}

View File

@ -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);
}
}
}

View File

@ -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);
}
}
}

View File

@ -23,6 +23,7 @@
OrbSlot,
OrbUser,
Conversation,
ConversationStartEnd
ConversationStartEnd,
PlayInstrument
}
}