2020-10-24 14:31:20 +00:00
|
|
|
|
using QSB.WorldSync;
|
2020-09-18 14:32:22 +00:00
|
|
|
|
using System.Collections.Generic;
|
2020-10-24 14:31:20 +00:00
|
|
|
|
using UnityEngine;
|
2020-09-18 14:32:22 +00:00
|
|
|
|
|
|
|
|
|
namespace QSB.ConversationSync
|
|
|
|
|
{
|
|
|
|
|
public static class ConversationPatches
|
|
|
|
|
{
|
2020-09-22 20:11:29 +00:00
|
|
|
|
public static void StartConversation(CharacterDialogueTree __instance)
|
2020-09-18 14:32:22 +00:00
|
|
|
|
{
|
2020-09-22 20:11:29 +00:00
|
|
|
|
var index = WorldRegistry.OldDialogueTrees.FindIndex(x => x == __instance);
|
2020-10-23 18:06:11 +00:00
|
|
|
|
PlayerRegistry.LocalPlayer.CurrentDialogueID = index;
|
2020-10-24 14:31:20 +00:00
|
|
|
|
ConversationManager.Instance.SendStart(index);
|
2020-10-23 18:06:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void EndConversation()
|
|
|
|
|
{
|
2020-10-24 14:31:20 +00:00
|
|
|
|
ConversationManager.Instance.SendEnd(PlayerRegistry.LocalPlayer.CurrentDialogueID);
|
2020-10-24 10:20:45 +00:00
|
|
|
|
ConversationManager.Instance.CloseBoxCharacter(PlayerRegistry.LocalPlayer.CurrentDialogueID);
|
2020-10-23 18:06:11 +00:00
|
|
|
|
PlayerRegistry.LocalPlayer.CurrentDialogueID = -1;
|
2020-10-24 10:20:45 +00:00
|
|
|
|
ConversationManager.Instance.CloseBoxPlayer();
|
2020-09-22 20:11:29 +00:00
|
|
|
|
}
|
2020-09-18 14:32:22 +00:00
|
|
|
|
|
2020-09-22 20:11:29 +00:00
|
|
|
|
public static bool InputDialogueOption(int optionIndex, DialogueBoxVer2 ____currentDialogueBox)
|
|
|
|
|
{
|
2020-09-29 18:42:45 +00:00
|
|
|
|
if (optionIndex < 0)
|
2020-09-18 14:32:22 +00:00
|
|
|
|
{
|
2020-10-23 18:06:11 +00:00
|
|
|
|
// in a page where there is no selectable options
|
2020-10-24 10:20:45 +00:00
|
|
|
|
ConversationManager.Instance.CloseBoxPlayer();
|
2020-09-29 18:42:45 +00:00
|
|
|
|
return true;
|
2020-09-18 14:32:22 +00:00
|
|
|
|
}
|
2020-09-29 18:42:45 +00:00
|
|
|
|
|
|
|
|
|
var selectedOption = ____currentDialogueBox.OptionFromUIIndex(optionIndex);
|
|
|
|
|
ConversationManager.Instance.SendPlayerOption(selectedOption.Text);
|
2020-09-22 20:11:29 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-23 18:06:11 +00:00
|
|
|
|
public static void GetNextPage(string ____name, List<string> ____listPagesToDisplay, int ____currentPage)
|
2020-09-22 20:11:29 +00:00
|
|
|
|
{
|
|
|
|
|
var key = ____name + ____listPagesToDisplay[____currentPage];
|
2020-10-23 18:06:11 +00:00
|
|
|
|
// Sending key so translation can be done on client side - should make different language-d clients compatible
|
|
|
|
|
QSB.Helper.Events.Unity.RunWhen(() => PlayerRegistry.LocalPlayer.CurrentDialogueID != -1,
|
|
|
|
|
() => ConversationManager.Instance.SendCharacterDialogue(PlayerRegistry.LocalPlayer.CurrentDialogueID, key));
|
2020-09-22 20:11:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-24 14:31:20 +00:00
|
|
|
|
public static bool OnAnimatorIK(float ___headTrackingWeight,
|
|
|
|
|
bool ___lookOnlyWhenTalking,
|
|
|
|
|
bool ____playerInHeadZone,
|
|
|
|
|
bool ____inConversation,
|
|
|
|
|
ref float ____currentLookWeight,
|
|
|
|
|
ref Vector3 ____currentLookTarget,
|
|
|
|
|
DampedSpring3D ___lookSpring,
|
|
|
|
|
Animator ____animator,
|
|
|
|
|
CharacterDialogueTree ____dialogueTree)
|
|
|
|
|
{
|
|
|
|
|
var playerId = ConversationManager.Instance.GetPlayerTalkingToTree(____dialogueTree);
|
|
|
|
|
Vector3 position;
|
|
|
|
|
if (playerId == uint.MaxValue)
|
|
|
|
|
{
|
|
|
|
|
position = Locator.GetActiveCamera().transform.position;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
position = PlayerRegistry.GetPlayer(playerId).Camera.transform.position;
|
|
|
|
|
}
|
2020-10-24 18:04:50 +00:00
|
|
|
|
float b = ___headTrackingWeight * Mathf.Min(1, (!___lookOnlyWhenTalking) ? ((!____playerInHeadZone) ? 0 : 1) : ((!____inConversation || !____playerInHeadZone) ? 0 : 1));
|
2020-10-24 14:31:20 +00:00
|
|
|
|
____currentLookWeight = Mathf.Lerp(____currentLookWeight, b, Time.deltaTime * 2f);
|
|
|
|
|
____currentLookTarget = ___lookSpring.Update(____currentLookTarget, position, Time.deltaTime);
|
|
|
|
|
____animator.SetLookAtPosition(____currentLookTarget);
|
|
|
|
|
____animator.SetLookAtWeight(____currentLookWeight);
|
|
|
|
|
return false;
|
2020-10-24 18:04:50 +00:00
|
|
|
|
}
|
2020-10-24 14:31:20 +00:00
|
|
|
|
|
2020-10-24 18:04:50 +00:00
|
|
|
|
public static bool OnZoneExit(CharacterDialogueTree ____dialogueTree)
|
|
|
|
|
{
|
|
|
|
|
var playerId = ConversationManager.Instance.GetPlayerTalkingToTree(____dialogueTree);
|
|
|
|
|
if (playerId == uint.MaxValue)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2020-10-24 14:31:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-22 20:11:29 +00:00
|
|
|
|
public static void AddPatches()
|
|
|
|
|
{
|
|
|
|
|
QSB.Helper.HarmonyHelper.AddPostfix<DialogueNode>("GetNextPage", typeof(ConversationPatches), nameof(GetNextPage));
|
|
|
|
|
QSB.Helper.HarmonyHelper.AddPrefix<CharacterDialogueTree>("InputDialogueOption", typeof(ConversationPatches), nameof(InputDialogueOption));
|
|
|
|
|
QSB.Helper.HarmonyHelper.AddPostfix<CharacterDialogueTree>("StartConversation", typeof(ConversationPatches), nameof(StartConversation));
|
2020-10-23 18:06:11 +00:00
|
|
|
|
QSB.Helper.HarmonyHelper.AddPostfix<CharacterDialogueTree>("EndConversation", typeof(ConversationPatches), nameof(EndConversation));
|
2020-10-24 14:31:20 +00:00
|
|
|
|
QSB.Helper.HarmonyHelper.AddPrefix<CharacterAnimController>("OnAnimatorIK", typeof(ConversationPatches), nameof(OnAnimatorIK));
|
2020-10-24 18:04:50 +00:00
|
|
|
|
QSB.Helper.HarmonyHelper.AddPrefix<CharacterAnimController>("OnZoneExit", typeof(ConversationPatches), nameof(OnZoneExit));
|
2020-09-18 14:32:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|