Allow using pathToAnimController for recorders #520 (#619)

<!-- Some improvement that requires no action on the part of add-on
creators i.e., improved star graphics -->
## Improvements
- Can now use `pathToAnimController` on a character dialogue to link it
to a Hearthian recorder so that it's visual effects will be triggered
during the dialogue #520
This commit is contained in:
Nick 2023-07-01 19:31:18 -04:00 committed by GitHub
commit e6d479e52e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 58 additions and 2 deletions

View File

@ -147,6 +147,7 @@ namespace NewHorizons.Builder.Props
var controller = character.GetComponent<CharacterAnimController>();
var traveler = character.GetComponent<TravelerController>();
var travelerEye = character.GetComponent<TravelerEyeController>();
var hearthianRecorder = character.GetComponent<HearthianRecorderEffects>();
var lookOnlyWhenTalking = info.lookAtRadius <= 0;
@ -196,6 +197,34 @@ namespace NewHorizons.Builder.Props
dialogue.OnEndConversation += nomaiController.StopWatchingPlayer;
}
}
else if (hearthianRecorder != null)
{
Delay.FireOnNextUpdate(() =>
{
// #520
if (hearthianRecorder._characterDialogueTree != null)
{
hearthianRecorder._characterDialogueTree.OnStartConversation -= hearthianRecorder.OnPlayRecorder;
hearthianRecorder._characterDialogueTree.OnEndConversation -= hearthianRecorder.OnStopRecorder;
}
// Recorder props have their own dialogue on them already
// Make sure to delete it when we're trying to connect new dialogue to it
var existingDialogue = hearthianRecorder.GetComponent<CharacterDialogueTree>();
if (existingDialogue != dialogue && existingDialogue != null)
{
// Can't delete the existing dialogue because its a required component but we can make it unable to select at least
GameObject.Destroy(hearthianRecorder.GetComponent<OWCollider>());
GameObject.Destroy(hearthianRecorder.GetComponent<SphereCollider>());
GameObject.Destroy(existingDialogue._interactVolume);
existingDialogue.enabled = false;
}
hearthianRecorder._characterDialogueTree = dialogue;
hearthianRecorder._characterDialogueTree.OnStartConversation += hearthianRecorder.OnPlayRecorder;
hearthianRecorder._characterDialogueTree.OnEndConversation += hearthianRecorder.OnStopRecorder;
});
}
else
{
// If they have nothing else just put the face player when talking thing on them

View File

@ -22,7 +22,10 @@ namespace NewHorizons.External.Modules.Props.Dialogue
/// <summary>
/// If this dialogue is meant for a character, this is the relative path from the planet to that character's
/// CharacterAnimController, TravelerController, TravelerEyeController (eye of the universe), FacePlayerWhenTalking, or SolanumAnimController.
/// CharacterAnimController, TravelerController, TravelerEyeController (eye of the universe), FacePlayerWhenTalking,
/// HearthianRecorderEffects or SolanumAnimController.
///
/// If it's a Recorder this will also delete the existing dialogue already attached to that prop.
///
/// If none of those components are present it will add a FacePlayerWhenTalking component.
/// </summary>

View File

@ -0,0 +1,24 @@
using HarmonyLib;
namespace NewHorizons.Patches.DialoguePatches
{
[HarmonyPatch(typeof(HearthianRecorderEffects))]
public static class HearthianRecorderEffectsPatches
{
[HarmonyPrefix]
[HarmonyPatch(nameof(HearthianRecorderEffects.Awake))]
public static bool HearthianRecorderEffects_Awake(HearthianRecorderEffects __instance)
{
// If we're adding custom dialogue to a recorder the CharacterDialogueTree isn't going to be on the object
if (__instance.GetComponent<CharacterDialogueTree>() == null)
{
__instance.enabled = false;
return false;
}
else
{
return true;
}
}
}
}

View File

@ -1323,7 +1323,7 @@
},
"pathToAnimController": {
"type": "string",
"description": "If this dialogue is meant for a character, this is the relative path from the planet to that character's\nCharacterAnimController, TravelerController, TravelerEyeController (eye of the universe), FacePlayerWhenTalking, or SolanumAnimController.\n\nIf none of those components are present it will add a FacePlayerWhenTalking component."
"description": "If this dialogue is meant for a character, this is the relative path from the planet to that character's\nCharacterAnimController, TravelerController, TravelerEyeController (eye of the universe), FacePlayerWhenTalking, \nHearthianRecorderEffects or SolanumAnimController.\n\nIf it's a Recorder this will also delete the existing dialogue already attached to that prop.\n\nIf none of those components are present it will add a FacePlayerWhenTalking component."
},
"radius": {
"type": "number",