Merge pull request #239 from misternebula/signal-learn-sync

Signal/frequency sync
This commit is contained in:
Mister_Nebula 2020-12-24 19:41:43 +00:00 committed by GitHub
commit cbf621e070
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 99 additions and 4 deletions

View File

@ -37,5 +37,7 @@
public static string QSBRevealFact = "QSBRevealFact";
public static string QSBSocketStateChange = "QSBSocketStateChange";
public static string QSBMultiStateChange = "QSBMultiStateChange";
public static string QSBIdentifyFrequency = "QSBIdentifyFrequency";
public static string QSBIdentifySignal = "QSBIdentifySignal";
}
}

View File

@ -27,6 +27,8 @@
DialogueCondition,
RevealFact,
SocketStateChange,
MultiStateChange
MultiStateChange,
IdentifyFrequency,
IdentifySignal
}
}

View File

@ -3,6 +3,7 @@ using QSB.Animation.Events;
using QSB.ConversationSync.Events;
using QSB.DeathSync.Events;
using QSB.ElevatorSync.Events;
using QSB.FrequencySync.Events;
using QSB.GeyserSync.Events;
using QSB.LogSync.Events;
using QSB.OrbSync.Events;
@ -48,11 +49,13 @@ namespace QSB.Events
new OrbUserEvent(),
new SocketStateChangeEvent(),
new MultiStateChangeEvent(),
// Conversation/dialogue
// Conversation/dialogue/exploration
new ConversationEvent(),
new ConversationStartEndEvent(),
new DialogueConditionEvent(),
new RevealFactEvent()
new RevealFactEvent(),
new IdentifyFrequencyEvent(),
new IdentifySignalEvent()
};
_eventList.ForEach(ev => ev.SetupListener());

View File

@ -0,0 +1,30 @@
using QSB.Events;
using QSB.Messaging;
using QSB.Player;
namespace QSB.FrequencySync.Events
{
public class IdentifyFrequencyEvent : QSBEvent<EnumMessage<SignalFrequency>>
{
public override EventType Type => EventType.IdentifyFrequency;
public override void SetupListener() => GlobalMessenger<SignalFrequency>.AddListener(EventNames.QSBIdentifyFrequency, Handler);
public override void CloseListener() => GlobalMessenger<SignalFrequency>.RemoveListener(EventNames.QSBIdentifyFrequency, Handler);
private void Handler(SignalFrequency frequency) => SendEvent(CreateMessage(frequency));
private EnumMessage<SignalFrequency> CreateMessage(SignalFrequency frequency) => new EnumMessage<SignalFrequency>
{
AboutId = QSBPlayerManager.LocalPlayerId,
Value = frequency
};
public override void OnReceiveRemote(bool server, EnumMessage<SignalFrequency> message)
{
PlayerData.LearnFrequency(message.Value);
var displayMsg = $"{UITextLibrary.GetString(UITextType.NotificationNewFreq)} <color=orange>{AudioSignal.FrequencyToString(message.Value, false)}</color>";
var data = new NotificationData(NotificationTarget.All, displayMsg, 10f, true);
NotificationManager.SharedInstance.PostNotification(data, false);
}
}
}

View File

@ -0,0 +1,31 @@
using QSB.Events;
using QSB.Messaging;
using QSB.Player;
namespace QSB.FrequencySync.Events
{
public class IdentifySignalEvent : QSBEvent<EnumMessage<SignalName>>
{
public override EventType Type => EventType.IdentifySignal;
public override void SetupListener() => GlobalMessenger<SignalName>.AddListener(EventNames.QSBIdentifySignal, Handler);
public override void CloseListener() => GlobalMessenger<SignalName>.RemoveListener(EventNames.QSBIdentifySignal, Handler);
private void Handler(SignalName name) => SendEvent(CreateMessage(name));
private EnumMessage<SignalName> CreateMessage(SignalName name) => new EnumMessage<SignalName>
{
AboutId = QSBPlayerManager.LocalPlayerId,
Value = name
};
public override void OnReceiveRemote(bool server, EnumMessage<SignalName> message)
{
PlayerData.LearnSignal(message.Value);
GlobalMessenger.FireEvent("IdentifySignal");
var displayMsg = $"{UITextLibrary.GetString(UITextType.NotificationSignalIdentified)} <color=orange>{AudioSignal.SignalNameToString(message.Value)}</color>";
var data = new NotificationData(NotificationTarget.All, displayMsg, 10f, true);
NotificationManager.SharedInstance.PostNotification(data, false);
}
}
}

View File

@ -0,0 +1,22 @@
using QSB.Events;
using QSB.Patches;
namespace QSB.FrequencySync
{
public class FrequencyPatches : QSBPatch
{
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
public override void DoPatches()
{
QSBCore.Helper.HarmonyHelper.AddPostfix<AudioSignal>("IdentifyFrequency", typeof(FrequencyPatches), nameof(IdentifyFrequency));
QSBCore.Helper.HarmonyHelper.AddPostfix<AudioSignal>("IdentifySignal", typeof(FrequencyPatches), nameof(IdentifySignal));
}
public static void IdentifyFrequency(SignalFrequency ____frequency)
=> GlobalMessenger<SignalFrequency>.FireEvent(EventNames.QSBIdentifyFrequency, ____frequency);
public static void IdentifySignal(SignalName ____name)
=> GlobalMessenger<SignalName>.FireEvent(EventNames.QSBIdentifySignal, ____name);
}
}

View File

@ -2,6 +2,7 @@
using QSB.ConversationSync;
using QSB.DeathSync;
using QSB.ElevatorSync;
using QSB.FrequencySync;
using QSB.LogSync;
using QSB.OrbSync;
using QSB.QuantumSync;
@ -33,7 +34,8 @@ namespace QSB.Patches
new LogPatches(),
new QuantumVisibilityPatches(),
new ServerQuantumStateChangePatches(),
new ClientQuantumStateChangePatches()
new ClientQuantumStateChangePatches(),
new FrequencyPatches()
};
DebugLog.DebugWrite("Patch Manager ready.", MessageType.Success);

View File

@ -163,6 +163,9 @@
<Compile Include="DeathSync\Events\PlayerDeathEvent.cs" />
<Compile Include="Events\IQSBEvent.cs" />
<Compile Include="Animation\Events\ChangeAnimTypeEvent.cs" />
<Compile Include="FrequencySync\Events\IdentifyFrequencyEvent.cs" />
<Compile Include="FrequencySync\Events\IdentifySignalEvent.cs" />
<Compile Include="FrequencySync\FrequencyPatches.cs" />
<Compile Include="Instruments\QSBCamera\CameraController.cs" />
<Compile Include="Instruments\QSBCamera\CameraManager.cs" />
<Compile Include="Instruments\QSBCamera\CameraMode.cs" />