More remote dialogue stuff (#493)

## Improvements
- Add `remoteTriggerPrereqCondition` to only show a remote dialogue
trigger once a condition has been met.

## Bug fixes
- Stop RemoteDialogueTrigger from softlocking you if you disable its
CharacterDialogueTree.
This commit is contained in:
Nick 2023-01-18 01:11:27 -05:00 committed by GitHub
commit b0fbf56882
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 56 additions and 1 deletions

View File

@ -80,7 +80,9 @@ namespace NewHorizons.Builder.Props
priority = 1,
dialogue = dialogue,
prereqConditionType = RemoteDialogueTrigger.MultiConditionType.AND,
prereqConditions = new string[]{ },
// Base game never uses more than one condition anyone so we'll keep it simple
prereqConditions = string.IsNullOrEmpty(info.remoteTriggerPrereqCondition) ? new string[]{ } : new string[] { info.remoteTriggerPrereqCondition },
// Just set your enter conditions in XML instead of complicating it with this
onTriggerEnterConditions = new string[]{ }
}
};

View File

@ -508,6 +508,11 @@ namespace NewHorizons.External.Modules
/// </summary>
public float remoteTriggerRadius;
/// <summary>
/// If setting up a remote trigger volume, this conditions must be met for it to trigger. Note: This is a dialogue condition, not a persistent condition.
/// </summary>
public string remoteTriggerPrereqCondition;
/// <summary>
/// Relative path to the xml file defining the dialogue.
/// </summary>

View File

@ -0,0 +1,44 @@
using HarmonyLib;
using NewHorizons.Utility;
using System;
namespace NewHorizons.Patches
{
/// <summary>
/// Should fix a bug where disabled a CharacterDialogueTree makes its related RemoteDialogueTriggers softlock your game
/// </summary>
[HarmonyPatch]
public static class RemoteDialogueTriggerPatches
{
private static bool _wasLastDialogueInactive = false;
[HarmonyPostfix]
[HarmonyPatch(typeof(RemoteDialogueTrigger), nameof(RemoteDialogueTrigger.OnTriggerEnter))]
public static void RemoteDialogueTrigger_OnTriggerEnter(RemoteDialogueTrigger __instance)
{
if (__instance._inRemoteDialogue && __instance._activeRemoteDialogue?.gameObject != null)
{
_wasLastDialogueInactive = __instance._activeRemoteDialogue.gameObject.activeInHierarchy;
if (!_wasLastDialogueInactive)
{
__instance._activeRemoteDialogue.gameObject.SetActive(true);
}
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(RemoteDialogueTrigger), nameof(RemoteDialogueTrigger.OnEndConversation))]
public static void RemoteDialogueTrigger_OnEndConversation(RemoteDialogueTrigger __instance)
{
if (__instance._inRemoteDialogue && __instance._activeRemoteDialogue != null)
{
if (_wasLastDialogueInactive)
{
__instance._activeRemoteDialogue.gameObject.SetActive(false);
}
}
_wasLastDialogueInactive = false;
}
}
}

View File

@ -1134,6 +1134,10 @@
"description": "The radius of the remote trigger volume.",
"format": "float"
},
"remoteTriggerPrereqCondition": {
"type": "string",
"description": "If setting up a remote trigger volume, this conditions must be met for it to trigger. Note: This is a dialogue condition, not a persistent condition."
},
"xmlFile": {
"type": "string",
"description": "Relative path to the xml file defining the dialogue."