quantum-space-buddies/QSB/ConversationSync/Patches/ConversationPatches.cs

73 lines
2.7 KiB
C#
Raw Normal View History

2020-10-25 13:17:01 +00:00
using OWML.Common;
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 14:32:22 +00:00
using System.Collections.Generic;
namespace QSB.ConversationSync.Patches
2020-09-18 14:32:22 +00:00
{
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
public override void DoPatches()
{
2021-06-18 20:54:32 +00:00
Postfix(nameof(DialogueNode_GetNextPage));
Prefix(nameof(CharacterDialogueTree_InputDialogueOption));
Prefix(nameof(CharacterDialogueTree_StartConversation));
Prefix(nameof(CharacterDialogueTree_EndConversation));
}
2021-06-18 20:54:32 +00: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-04-29 17:30:45 +00:00
QSBPlayerManager.LocalPlayer.CurrentCharacterDialogueTreeId = index;
2020-12-02 21:23:01 +00:00
ConversationManager.Instance.SendConvState(index, true);
}
2021-06-18 20:54:32 +00:00
public static bool CharacterDialogueTree_EndConversation(CharacterDialogueTree __instance)
2020-12-02 21:23:01 +00:00
{
if (!__instance.enabled)
{
return false;
}
2021-04-29 17:30:45 +00: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-04-29 17:30:45 +00: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 14:32:22 +00:00
2021-06-18 20:54:32 +00:00
public static bool CharacterDialogueTree_InputDialogueOption(int optionIndex, DialogueBoxVer2 ____currentDialogueBox)
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 18:42:45 +00:00
2020-12-02 21:23:01 +00:00
var selectedOption = ____currentDialogueBox.OptionFromUIIndex(optionIndex);
ConversationManager.Instance.SendPlayerOption(selectedOption.Text);
return true;
}
2020-09-22 20:11:29 +00:00
2021-06-18 20:54:32 +00:00
public static void DialogueNode_GetNextPage(string ____name, List<string> ____listPagesToDisplay, int ____currentPage)
2020-12-02 21:23:01 +00:00
{
var key = ____name + ____listPagesToDisplay[____currentPage];
// Sending key so translation can be done on client side - should make different language-d clients compatible
2021-04-29 17:30:45 +00:00
QSBCore.UnityEvents.RunWhen(() => QSBPlayerManager.LocalPlayer.CurrentCharacterDialogueTreeId != -1,
() => ConversationManager.Instance.SendCharacterDialogue(QSBPlayerManager.LocalPlayer.CurrentCharacterDialogueTreeId, key));
2020-12-02 21:23:01 +00:00
}
}
2020-12-03 08:28:05 +00:00
}