diff --git a/QSB/Animation/NPC/Patches/TravelerControllerPatches.cs b/QSB/Animation/NPC/Patches/TravelerControllerPatches.cs index 04a9fe85..1590dd9e 100644 --- a/QSB/Animation/NPC/Patches/TravelerControllerPatches.cs +++ b/QSB/Animation/NPC/Patches/TravelerControllerPatches.cs @@ -6,98 +6,112 @@ using UnityEngine; namespace QSB.Animation.NPC.Patches { - [HarmonyPatch(typeof(TravelerController))] public class TravelerControllerPatches : QSBPatch { public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; [HarmonyPrefix] - [HarmonyPatch(nameof(TravelerController.OnStartConversation))] + [HarmonyPatch(typeof(TravelerController), nameof(TravelerController.OnStartConversation))] public static bool OnStartConversation(TravelerController __instance) { __instance._talking = true; - - if (__instance is GabbroTravelerController gabbro) - { - if (gabbro._animator.enabled) - { - gabbro._animator.CrossFadeInFixedTime("Gabbro_Talking", 1.8f); - gabbro._hammockAnimator.CrossFadeInFixedTime("GabbroHammock_Talking", 1.8f); - } - - Locator.GetTravelerAudioManager().StopTravelerAudio(gabbro.name); - } - else - { - if (__instance._animator != null && __instance._animator.enabled) - { - __instance._playingAnimID = __instance._animator.IsInTransition(0) - ? __instance._animator.GetNextAnimatorStateInfo(0).fullPathHash - : __instance._animator.GetCurrentAnimatorStateInfo(0).fullPathHash; - - __instance._animator.SetTrigger("Talking"); - } - - Locator.GetTravelerAudioManager().StopTravelerAudio(__instance.name); - - if (__instance is ChertTravelerController chert) - { - chert._moodWeight = (float)chert._mood; - } - } + // call directly instead of firing event + __instance.StartConversation(); return false; } [HarmonyPrefix] - [HarmonyPatch(nameof(TravelerController.OnEndConversation))] + [HarmonyPatch(typeof(TravelerController), nameof(TravelerController.OnEndConversation))] public static bool OnEndConversation(TravelerController __instance) { - if (__instance is GabbroTravelerController gabbro) - { - if (gabbro._animator.enabled) - { - gabbro._animator.CrossFadeInFixedTime("Gabbro_Playing", gabbro._delayToRestartAudio, -1, -gabbro._delayToRestartAudio); - gabbro._hammockAnimator.CrossFadeInFixedTime("GabbroHammock_Playing", gabbro._delayToRestartAudio, -1, -gabbro._delayToRestartAudio); - } - - Locator.GetTravelerAudioManager().PlayTravelerAudio(gabbro.name, gabbro._delayToRestartAudio); - if (DialogueConditionManager.SharedInstance.GetConditionState("MAP_PROMPT_REMINDER") || DialogueConditionManager.SharedInstance.GetConditionState("MAP_PROMPT_ATTENTION")) - { - var conditionState = DialogueConditionManager.SharedInstance.GetConditionState("MAP_PROMPT_ATTENTION"); - DialogueConditionManager.SharedInstance.SetConditionState("MAP_PROMPT_REMINDER"); - DialogueConditionManager.SharedInstance.SetConditionState("MAP_PROMPT_ATTENTION"); - GlobalMessenger.FireEvent("TriggerMapPromptReminder", conditionState); - } - } - else - { - if (__instance._animator != null && __instance._animator.enabled) - { - if (__instance._delayToRestartAudio > 0f) - { - __instance._animator.CrossFadeInFixedTime(__instance._playingAnimID, __instance._delayToRestartAudio, -1, -__instance._delayToRestartAudio); - } - else - { - __instance._animator.SetTrigger("Playing"); - } - } - - Locator.GetTravelerAudioManager().PlayTravelerAudio(__instance.name, __instance._delayToRestartAudio); - } - + // call directly instead of firing event + __instance.EndConversation(__instance._delayToRestartAudio); __instance._talking = false; return false; } + + + [HarmonyPrefix] + [HarmonyPatch(typeof(GabbroTravelerController), nameof(GabbroTravelerController.StartConversation))] + public static bool StartConversation(GabbroTravelerController __instance) + { + if (__instance._animator.enabled) + { + __instance._animator.CrossFadeInFixedTime("Gabbro_Talking", 1.8f); + __instance._hammockAnimator.CrossFadeInFixedTime("GabbroHammock_Talking", 1.8f); + } + Locator.GetTravelerAudioManager().StopTravelerAudio(__instance); + + return false; + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(TravelerController), nameof(TravelerController.StartConversation))] + public static bool StartConversation(TravelerController __instance) + { + if (__instance._animator != null && __instance._animator.enabled) + { + __instance._playingAnimID = __instance._animator.IsInTransition(0) + ? __instance._animator.GetNextAnimatorStateInfo(0).fullPathHash + : __instance._animator.GetCurrentAnimatorStateInfo(0).fullPathHash; + __instance._animator.SetTrigger("Talking"); + } + Locator.GetTravelerAudioManager().StopTravelerAudio(__instance); + + return false; + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(TravelerController), nameof(TravelerController.EndConversation))] + public static bool EndConversation(TravelerController __instance, float audioDelay) + { + if (__instance._animator != null && __instance._animator.enabled) + { + if (audioDelay > 0f) + { + __instance._animator.CrossFadeInFixedTime(__instance._playingAnimID, audioDelay, -1, -audioDelay); + } + else + { + __instance._animator.SetTrigger("Playing"); + } + } + Locator.GetTravelerAudioManager().PlayTravelerAudio(__instance, audioDelay); + + return false; + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(GabbroTravelerController), nameof(GabbroTravelerController.EndConversation))] + public static bool EndConversation(GabbroTravelerController __instance, float audioDelay) + { + if (__instance._animator.enabled) + { + __instance._animator.CrossFadeInFixedTime("Gabbro_Playing", audioDelay, -1, -audioDelay); + __instance._hammockAnimator.CrossFadeInFixedTime("GabbroHammock_Playing", audioDelay, -1, -audioDelay); + } + Locator.GetTravelerAudioManager().PlayTravelerAudio(__instance, audioDelay); + if (DialogueConditionManager.SharedInstance.GetConditionState("MAP_PROMPT_REMINDER") || DialogueConditionManager.SharedInstance.GetConditionState("MAP_PROMPT_ATTENTION")) + { + var conditionState = DialogueConditionManager.SharedInstance.GetConditionState("MAP_PROMPT_ATTENTION"); + DialogueConditionManager.SharedInstance.SetConditionState("MAP_PROMPT_REMINDER", false); + DialogueConditionManager.SharedInstance.SetConditionState("MAP_PROMPT_ATTENTION", false); + GlobalMessenger.FireEvent("TriggerMapPromptReminder", conditionState); + } + + return false; + } } internal static class TravelerAudioManagerExtensions { /// bad, but works great - private static SignalName TravelerToSignal(string name) + private static SignalName TravelerToSignalName(TravelerController traveler) { + var name = traveler.name; + if (name.Contains("Esker")) { return SignalName.Traveler_Esker; @@ -136,27 +150,27 @@ namespace QSB.Animation.NPC.Patches throw new ArgumentOutOfRangeException(nameof(name), name, null); } - internal static void StopTravelerAudio(this TravelerAudioManager manager, string name) + internal static void StopTravelerAudio(this TravelerAudioManager manager, TravelerController traveler) { - var signalName = TravelerToSignal(name); - var audioSignal = manager._signals.First(x => x.GetName() == signalName); + var signalName = TravelerToSignalName(traveler); + var signal = manager._signals.First(x => x.GetName() == signalName); - audioSignal.GetOWAudioSource().FadeOut(0.5f); + signal.GetOWAudioSource().FadeOut(0.5f); } - internal static void PlayTravelerAudio(this TravelerAudioManager manager, string name, float audioDelay) + internal static void PlayTravelerAudio(this TravelerAudioManager manager, TravelerController traveler, float audioDelay) { - var signalName = TravelerToSignal(name); - var audioSignal = manager._signals.First(x => x.GetName() == signalName); + var signalName = TravelerToSignalName(traveler); + var signal = manager._signals.First(x => x.GetName() == signalName); manager._playAfterDelay = false; manager._playAudioTime = Time.time + audioDelay; QSBCore.UnityEvents.RunWhen(() => Time.time >= manager._playAudioTime, () => { - if (!audioSignal.IsOnlyAudibleToScope() || audioSignal.GetOWAudioSource().isPlaying) + if (!signal.IsOnlyAudibleToScope() || signal.GetOWAudioSource().isPlaying) { - audioSignal.GetOWAudioSource().FadeIn(0.5f); - audioSignal.GetOWAudioSource().timeSamples = 0; + signal.GetOWAudioSource().FadeIn(0.5f); + signal.GetOWAudioSource().timeSamples = 0; } }); }