From 2c10e123042df5bc8e62f77fb28a508cb35a5d76 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Tue, 25 Jan 2022 22:58:07 -0800 Subject: [PATCH] clean up RemoteDialogueTrigger a bit --- .../Messages/EnterRemoteDialogueMessage.cs | 18 +++----- .../Patches/ConversationPatches.cs | 44 ++++++++----------- .../WorldObjects/QSBRemoteDialogueTrigger.cs | 7 +-- 3 files changed, 29 insertions(+), 40 deletions(-) diff --git a/QSB/ConversationSync/Messages/EnterRemoteDialogueMessage.cs b/QSB/ConversationSync/Messages/EnterRemoteDialogueMessage.cs index 3f659189..1004ecc3 100644 --- a/QSB/ConversationSync/Messages/EnterRemoteDialogueMessage.cs +++ b/QSB/ConversationSync/Messages/EnterRemoteDialogueMessage.cs @@ -6,30 +6,24 @@ namespace QSB.ConversationSync.Messages { internal class EnterRemoteDialogueMessage : QSBWorldObjectMessage { - private int ActivatedDialogueIndex; - private int ListDialoguesIndex; + private int DialogueIndex; - public EnterRemoteDialogueMessage(int activatedIndex, int listIndex) - { - ActivatedDialogueIndex = activatedIndex; - ListDialoguesIndex = listIndex; - } + public EnterRemoteDialogueMessage(int dialogueIndex) + => DialogueIndex = dialogueIndex; public override void Serialize(NetworkWriter writer) { base.Serialize(writer); - writer.Write(ActivatedDialogueIndex); - writer.Write(ListDialoguesIndex); + writer.Write(DialogueIndex); } public override void Deserialize(NetworkReader reader) { base.Deserialize(reader); - ActivatedDialogueIndex = reader.Read(); - ListDialoguesIndex = reader.Read(); + DialogueIndex = reader.Read(); } public override void OnReceiveRemote() - => WorldObject.RemoteEnterDialogue(ActivatedDialogueIndex, ListDialoguesIndex); + => WorldObject.RemoteEnterDialogue(DialogueIndex); } } \ No newline at end of file diff --git a/QSB/ConversationSync/Patches/ConversationPatches.cs b/QSB/ConversationSync/Patches/ConversationPatches.cs index 718e0b43..39945070 100644 --- a/QSB/ConversationSync/Patches/ConversationPatches.cs +++ b/QSB/ConversationSync/Patches/ConversationPatches.cs @@ -100,66 +100,60 @@ namespace QSB.ConversationSync.Patches public static bool ConversationTriggeredReplacement(RemoteDialogueTrigger __instance, ref bool __result, out RemoteDialogueTrigger.RemoteDialogueCondition dialogue) { dialogue = default; - var maxValue = int.MaxValue; - var num = -1; - var sharedInstance = DialogueConditionManager.SharedInstance; + var dialogueIndex = -1; for (var i = 0; i < __instance._listDialogues.Length; i++) { if (!__instance._activatedDialogues[i]) { - var flag = true; - var flag2 = false; - if (__instance._listDialogues[i].prereqConditions.Length == 0) - { - flag2 = true; - } + var allConditionsMet = true; + var anyConditionsMet = __instance._listDialogues[i].prereqConditions.Length == 0; - for (int j = 0; j < __instance._listDialogues[i].prereqConditions.Length; j++) + foreach (var prereqCondition in __instance._listDialogues[i].prereqConditions) { - if (sharedInstance.GetConditionState(__instance._listDialogues[i].prereqConditions[j])) + if (DialogueConditionManager.SharedInstance.GetConditionState(prereqCondition)) { - flag2 = true; + anyConditionsMet = true; } else { - flag = false; + allConditionsMet = false; } } - bool flag3 = false; - RemoteDialogueTrigger.MultiConditionType prereqConditionType = __instance._listDialogues[i].prereqConditionType; + var conditionsMet = false; + var prereqConditionType = __instance._listDialogues[i].prereqConditionType; if (prereqConditionType != RemoteDialogueTrigger.MultiConditionType.OR) { - if (prereqConditionType == RemoteDialogueTrigger.MultiConditionType.AND && flag) + if (prereqConditionType == RemoteDialogueTrigger.MultiConditionType.AND && allConditionsMet) { - flag3 = true; + conditionsMet = true; } } - else if (flag2) + else if (anyConditionsMet) { - flag3 = true; + conditionsMet = true; } - if (flag3 && __instance._listDialogues[i].priority < maxValue) + if (conditionsMet && __instance._listDialogues[i].priority < int.MaxValue) { dialogue = __instance._listDialogues[i]; - num = i; + dialogueIndex = i; } } } - if (num == -1) + if (dialogueIndex == -1) { __result = false; return false; } - __instance._activatedDialogues[num] = true; + __instance._activatedDialogues[dialogueIndex] = true; + __result = true; __instance.GetWorldObject() - .SendMessage(new EnterRemoteDialogueMessage(num, __instance._listDialogues.IndexOf(dialogue))); + .SendMessage(new EnterRemoteDialogueMessage(dialogueIndex)); - __result = true; return false; } diff --git a/QSB/ConversationSync/WorldObjects/QSBRemoteDialogueTrigger.cs b/QSB/ConversationSync/WorldObjects/QSBRemoteDialogueTrigger.cs index 8fd3e6e6..10fcb503 100644 --- a/QSB/ConversationSync/WorldObjects/QSBRemoteDialogueTrigger.cs +++ b/QSB/ConversationSync/WorldObjects/QSBRemoteDialogueTrigger.cs @@ -9,12 +9,13 @@ namespace QSB.ConversationSync.WorldObjects // todo SendResyncInfo } - public void RemoteEnterDialogue(int activatedIndex, int listIndex) + public void RemoteEnterDialogue(int dialogueIndex) { - var dialogueCondition = AttachedObject._listDialogues[listIndex]; + var dialogueCondition = AttachedObject._listDialogues[dialogueIndex]; AttachedObject._activeRemoteDialogue = dialogueCondition.dialogue; AttachedObject._inRemoteDialogue = true; - AttachedObject._activatedDialogues[activatedIndex] = true; + + AttachedObject._activatedDialogues[dialogueIndex] = true; } } }