diff --git a/QSB/Animation/NPC/Events/NpcAnimationEvent.cs b/QSB/Animation/NPC/Events/NpcAnimationEvent.cs index 2316e2fa..3a4fe5dc 100644 --- a/QSB/Animation/NPC/Events/NpcAnimationEvent.cs +++ b/QSB/Animation/NPC/Events/NpcAnimationEvent.cs @@ -1,5 +1,6 @@ using QSB.Animation.NPC.WorldObjects; using QSB.Events; +using QSB.Utility; using QSB.WorldSync; namespace QSB.Animation.NPC.Events @@ -26,9 +27,11 @@ namespace QSB.Animation.NPC.Events switch (message.AnimationEvent) { case AnimationEvent.StartConversation: + DebugLog.DebugWrite($"Start conversation"); qsbObj.StartConversation(); break; case AnimationEvent.EndConversation: + DebugLog.DebugWrite($"End conversation"); qsbObj.EndConversation(); break; } diff --git a/QSB/Animation/NPC/Patches/TravelerControllerPatches.cs b/QSB/Animation/NPC/Patches/TravelerControllerPatches.cs new file mode 100644 index 00000000..b050707a --- /dev/null +++ b/QSB/Animation/NPC/Patches/TravelerControllerPatches.cs @@ -0,0 +1,58 @@ +using HarmonyLib; +using QSB.Patches; +using QSB.Utility; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace QSB.Animation.NPC.Patches +{ + [HarmonyPatch(typeof(TravelerController))] + public class TravelerControllerPatches : QSBPatch + { + public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; + + [HarmonyPrefix] + [HarmonyPatch(nameof(TravelerController.OnStartConversation))] + public static bool OnStartConversation(TravelerController __instance) + { + DebugLog.DebugWrite($"{__instance.name} OnStartConversation"); + __instance._talking = true; + + 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"); + } + + return false; + } + + [HarmonyPrefix] + [HarmonyPatch(nameof(TravelerController.OnEndConversation))] + public static bool OnEndConversation(TravelerController __instance) + { + DebugLog.DebugWrite($"{__instance.name} OnEndConversation"); + 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"); + } + } + + __instance._talking = false; + + return false; + } + } +} diff --git a/QSB/Animation/NPC/WorldObjects/QSBCharacterAnimController.cs b/QSB/Animation/NPC/WorldObjects/QSBCharacterAnimController.cs index 368717e4..c5cda468 100644 --- a/QSB/Animation/NPC/WorldObjects/QSBCharacterAnimController.cs +++ b/QSB/Animation/NPC/WorldObjects/QSBCharacterAnimController.cs @@ -32,9 +32,9 @@ namespace QSB.Animation.NPC.WorldObjects } public override CharacterDialogueTree GetDialogueTree() - => AttachedObject.GetValue("_dialogueTree"); + => AttachedObject._dialogueTree; public override bool InConversation() - => AttachedObject.GetValue("_inConversation"); + => AttachedObject._inConversation; } } diff --git a/QSB/Patches/QSBPatchManager.cs b/QSB/Patches/QSBPatchManager.cs index 72a234aa..49a0c1d2 100644 --- a/QSB/Patches/QSBPatchManager.cs +++ b/QSB/Patches/QSBPatchManager.cs @@ -76,7 +76,8 @@ namespace QSB.Patches new LightSensorPatches(), new AnglerPatches(), new MeteorClientPatches(), - new MeteorServerPatches() + new MeteorServerPatches(), + new TravelerControllerPatches() }; TypeToInstance = new Dictionary diff --git a/QSB/QSB.csproj b/QSB/QSB.csproj index c1fa15bb..8d5a085b 100644 --- a/QSB/QSB.csproj +++ b/QSB/QSB.csproj @@ -53,6 +53,7 @@ +