2021-10-15 21:06:51 +01:00
|
|
|
|
using HarmonyLib;
|
|
|
|
|
using OWML.Common;
|
2021-12-23 22:59:53 -08:00
|
|
|
|
using QSB.ConversationSync.Messages;
|
2021-12-20 11:48:50 +00:00
|
|
|
|
using QSB.ConversationSync.WorldObjects;
|
2021-12-23 22:59:53 -08:00
|
|
|
|
using QSB.Messaging;
|
2020-12-14 21:20:53 +00:00
|
|
|
|
using QSB.Patches;
|
2020-11-03 21:33:48 +00:00
|
|
|
|
using QSB.Player;
|
2020-10-25 13:17:01 +00:00
|
|
|
|
using QSB.Utility;
|
|
|
|
|
using QSB.WorldSync;
|
2020-09-18 15:32:22 +01:00
|
|
|
|
|
2020-12-31 12:10:55 +00:00
|
|
|
|
namespace QSB.ConversationSync.Patches
|
2020-09-18 15:32:22 +01:00
|
|
|
|
{
|
2021-10-15 21:06:51 +01:00
|
|
|
|
[HarmonyPatch]
|
2020-12-02 21:23:01 +00:00
|
|
|
|
public class ConversationPatches : QSBPatch
|
|
|
|
|
{
|
|
|
|
|
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
|
2020-11-03 21:11:10 +00:00
|
|
|
|
|
2021-10-15 21:06:51 +01:00
|
|
|
|
[HarmonyPrefix]
|
|
|
|
|
[HarmonyPatch(typeof(CharacterDialogueTree), nameof(CharacterDialogueTree.StartConversation))]
|
2021-06-18 21:54:32 +01:00
|
|
|
|
public static void CharacterDialogueTree_StartConversation(CharacterDialogueTree __instance)
|
2020-12-02 21:23:01 +00:00
|
|
|
|
{
|
2020-12-11 13:14:58 +00:00
|
|
|
|
var index = QSBWorldSync.OldDialogueTrees.FindIndex(x => x == __instance);
|
2020-12-02 21:23:01 +00:00
|
|
|
|
if (index == -1)
|
|
|
|
|
{
|
|
|
|
|
DebugLog.ToConsole($"Warning - Index for tree {__instance.name} was -1.", MessageType.Warning);
|
|
|
|
|
}
|
2021-06-18 22:38:32 +01:00
|
|
|
|
|
2021-04-29 18:30:45 +01:00
|
|
|
|
QSBPlayerManager.LocalPlayer.CurrentCharacterDialogueTreeId = index;
|
2020-12-02 21:23:01 +00:00
|
|
|
|
ConversationManager.Instance.SendConvState(index, true);
|
|
|
|
|
}
|
2020-10-23 19:06:11 +01:00
|
|
|
|
|
2021-10-15 21:06:51 +01:00
|
|
|
|
[HarmonyPrefix]
|
|
|
|
|
[HarmonyPatch(typeof(CharacterDialogueTree), nameof(CharacterDialogueTree.EndConversation))]
|
2021-06-18 21:54:32 +01:00
|
|
|
|
public static bool CharacterDialogueTree_EndConversation(CharacterDialogueTree __instance)
|
2020-12-02 21:23:01 +00:00
|
|
|
|
{
|
|
|
|
|
if (!__instance.enabled)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2021-06-18 22:38:32 +01:00
|
|
|
|
|
2021-04-29 18:30:45 +01:00
|
|
|
|
if (QSBPlayerManager.LocalPlayer.CurrentCharacterDialogueTreeId == -1)
|
2020-12-02 21:23:01 +00:00
|
|
|
|
{
|
|
|
|
|
DebugLog.ToConsole($"Warning - Ending conversation with CurrentDialogueId of -1! Called from {__instance.name}", MessageType.Warning);
|
2020-12-19 18:52:36 +00:00
|
|
|
|
return true;
|
2020-12-02 21:23:01 +00:00
|
|
|
|
}
|
2021-06-18 22:38:32 +01:00
|
|
|
|
|
2021-04-29 18:30:45 +01:00
|
|
|
|
ConversationManager.Instance.SendConvState(QSBPlayerManager.LocalPlayer.CurrentCharacterDialogueTreeId, false);
|
|
|
|
|
ConversationManager.Instance.CloseBoxCharacter(QSBPlayerManager.LocalPlayer.CurrentCharacterDialogueTreeId);
|
|
|
|
|
QSBPlayerManager.LocalPlayer.CurrentCharacterDialogueTreeId = -1;
|
2020-12-02 21:23:01 +00:00
|
|
|
|
ConversationManager.Instance.CloseBoxPlayer();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2020-09-18 15:32:22 +01:00
|
|
|
|
|
2021-10-15 21:06:51 +01:00
|
|
|
|
[HarmonyPrefix]
|
|
|
|
|
[HarmonyPatch(typeof(CharacterDialogueTree), nameof(CharacterDialogueTree.InputDialogueOption))]
|
2021-12-26 21:25:26 -08:00
|
|
|
|
public static bool CharacterDialogueTree_InputDialogueOption(CharacterDialogueTree __instance, int optionIndex)
|
2020-12-02 21:23:01 +00:00
|
|
|
|
{
|
|
|
|
|
if (optionIndex < 0)
|
|
|
|
|
{
|
|
|
|
|
// in a page where there is no selectable options
|
|
|
|
|
ConversationManager.Instance.CloseBoxPlayer();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2020-09-29 20:42:45 +02:00
|
|
|
|
|
2021-12-26 21:25:26 -08:00
|
|
|
|
var selectedOption = __instance._currentDialogueBox.OptionFromUIIndex(optionIndex);
|
2020-12-02 21:23:01 +00:00
|
|
|
|
ConversationManager.Instance.SendPlayerOption(selectedOption.Text);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2020-09-22 21:11:29 +01:00
|
|
|
|
|
2021-10-15 21:06:51 +01:00
|
|
|
|
[HarmonyPostfix]
|
|
|
|
|
[HarmonyPatch(typeof(DialogueNode), nameof(DialogueNode.GetNextPage))]
|
2021-12-26 21:25:26 -08:00
|
|
|
|
public static void DialogueNode_GetNextPage(DialogueNode __instance)
|
2020-12-02 21:23:01 +00:00
|
|
|
|
{
|
2021-12-26 21:25:26 -08:00
|
|
|
|
var key = __instance._name + __instance._listPagesToDisplay[__instance._currentPage];
|
2020-12-02 21:23:01 +00:00
|
|
|
|
// Sending key so translation can be done on client side - should make different language-d clients compatible
|
2021-04-29 18:30:45 +01:00
|
|
|
|
QSBCore.UnityEvents.RunWhen(() => QSBPlayerManager.LocalPlayer.CurrentCharacterDialogueTreeId != -1,
|
|
|
|
|
() => ConversationManager.Instance.SendCharacterDialogue(QSBPlayerManager.LocalPlayer.CurrentCharacterDialogueTreeId, key));
|
2020-12-02 21:23:01 +00:00
|
|
|
|
}
|
2021-12-20 11:48:50 +00:00
|
|
|
|
|
|
|
|
|
[HarmonyPrefix]
|
|
|
|
|
[HarmonyPatch(typeof(RemoteDialogueTrigger), nameof(RemoteDialogueTrigger.ConversationTriggered))]
|
|
|
|
|
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;
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int j = 0; j < __instance._listDialogues[i].prereqConditions.Length; j++)
|
|
|
|
|
{
|
|
|
|
|
if (sharedInstance.GetConditionState(__instance._listDialogues[i].prereqConditions[j]))
|
|
|
|
|
{
|
|
|
|
|
flag2 = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
flag = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool flag3 = false;
|
|
|
|
|
RemoteDialogueTrigger.MultiConditionType prereqConditionType = __instance._listDialogues[i].prereqConditionType;
|
|
|
|
|
if (prereqConditionType != RemoteDialogueTrigger.MultiConditionType.OR)
|
|
|
|
|
{
|
|
|
|
|
if (prereqConditionType == RemoteDialogueTrigger.MultiConditionType.AND && flag)
|
|
|
|
|
{
|
|
|
|
|
flag3 = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (flag2)
|
|
|
|
|
{
|
|
|
|
|
flag3 = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (flag3 && __instance._listDialogues[i].priority < maxValue)
|
|
|
|
|
{
|
|
|
|
|
dialogue = __instance._listDialogues[i];
|
|
|
|
|
num = i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (num == -1)
|
|
|
|
|
{
|
|
|
|
|
__result = false;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
__instance._activatedDialogues[num] = true;
|
|
|
|
|
|
2021-12-25 22:37:20 -08:00
|
|
|
|
__instance.GetWorldObject<QSBRemoteDialogueTrigger>()
|
2021-12-23 22:59:53 -08:00
|
|
|
|
.SendMessage(new EnterRemoteDialogueMessage(num, __instance._listDialogues.IndexOf(dialogue)));
|
2021-12-20 11:48:50 +00:00
|
|
|
|
|
|
|
|
|
__result = true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2020-12-02 21:23:01 +00:00
|
|
|
|
}
|
2020-12-03 08:28:05 +00:00
|
|
|
|
}
|