diff --git a/QSB/Events/EventList.cs b/QSB/Events/EventList.cs index 39aeac52..cb848797 100644 --- a/QSB/Events/EventList.cs +++ b/QSB/Events/EventList.cs @@ -3,6 +3,7 @@ using QSB.ConversationSync; using QSB.DeathSync; using QSB.ElevatorSync; using QSB.GeyserSync; +using QSB.Instruments.Events; using QSB.OrbSync; using QSB.TimeSync; using QSB.Tools; @@ -11,9 +12,6 @@ using System.Collections.Generic; namespace QSB.Events { - /// - /// Creates instances of all of the events QSB uses. - /// public static class EventList { public static bool Ready { get; private set; } @@ -43,7 +41,8 @@ namespace QSB.Events new OrbSlotEvent(), new OrbUserEvent(), new ConversationEvent(), - new ConversationStartEndEvent() + new ConversationStartEndEvent(), + new PlayInstrumentEvent() }; _eventList.ForEach(ev => ev.SetupListener()); diff --git a/QSB/Events/EventNames.cs b/QSB/Events/EventNames.cs index 23a60a4e..8d687c31 100644 --- a/QSB/Events/EventNames.cs +++ b/QSB/Events/EventNames.cs @@ -34,5 +34,6 @@ public static string QSBOrbUser = "QSBOrbUser"; public static string QSBConversation = "QSBConversation"; public static string QSBConversationStartEnd = "QSBConversationStartEnd"; + public static string QSBPlayInstrument = "QSBPlayInstrument"; } } diff --git a/QSB/Instruments/Events/PlayInstrumentEvent.cs b/QSB/Instruments/Events/PlayInstrumentEvent.cs new file mode 100644 index 00000000..db0312dc --- /dev/null +++ b/QSB/Instruments/Events/PlayInstrumentEvent.cs @@ -0,0 +1,23 @@ +using QSB.Events; +using QSB.Messaging; + +namespace QSB.Instruments.Events +{ + public class PlayInstrumentEvent : QSBEvent + { + public override EventType Type => EventType.FullStateRequest; + + public override void SetupListener() => GlobalMessenger.AddListener(EventNames.QSBPlayerStatesRequest, Handler); + + public override void CloseListener() => GlobalMessenger.RemoveListener(EventNames.QSBPlayerStatesRequest, Handler); + + private void Handler(InstrumentType type, bool state) => SendEvent(CreateMessage(type, state)); + + private PlayInstrumentMessage CreateMessage(InstrumentType type, bool state) => new PlayInstrumentMessage + { + AboutId = LocalPlayerId, + Type = type, + State = state + }; + } +} diff --git a/QSB/Instruments/Events/PlayInstrumentMessage.cs b/QSB/Instruments/Events/PlayInstrumentMessage.cs new file mode 100644 index 00000000..0f4c3627 --- /dev/null +++ b/QSB/Instruments/Events/PlayInstrumentMessage.cs @@ -0,0 +1,25 @@ +using QSB.Messaging; +using UnityEngine.Networking; + +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); + } + } +} diff --git a/QSB/Instruments/InstrumentType.cs b/QSB/Instruments/InstrumentType.cs new file mode 100644 index 00000000..9401d84a --- /dev/null +++ b/QSB/Instruments/InstrumentType.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace QSB.Instruments +{ + public enum InstrumentType + { + CHERT, + ESKER, + FELDSPAR, + GABBRO, + REIBECK, + SOLANUM + } +} \ No newline at end of file diff --git a/QSB/QSB.csproj b/QSB/QSB.csproj index 68c9ca7a..404297f2 100644 --- a/QSB/QSB.csproj +++ b/QSB/QSB.csproj @@ -148,6 +148,9 @@ + + +