From 4b75388ddcdd4400b5bafa55373efe84b7d5e715 Mon Sep 17 00:00:00 2001 From: Liza Carvelli Date: Fri, 20 Sep 2024 21:52:46 +0200 Subject: [PATCH] Fix certain kinds of interactions --- Directory.Build.targets | 2 +- .../Controller/Steps/Interactions/Interact.cs | 49 ++++++++++++++++--- .../QuestComponents/CreationUtilsComponent.cs | 24 ++++++--- 3 files changed, 60 insertions(+), 15 deletions(-) diff --git a/Directory.Build.targets b/Directory.Build.targets index abb1feac..aac0b377 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -1,5 +1,5 @@ - 3.5 + 3.6 diff --git a/Questionable/Controller/Steps/Interactions/Interact.cs b/Questionable/Controller/Steps/Interactions/Interact.cs index 5dd28d20..1b7caea3 100644 --- a/Questionable/Controller/Steps/Interactions/Interact.cs +++ b/Questionable/Controller/Steps/Interactions/Interact.cs @@ -72,9 +72,10 @@ internal static class Interact GameFunctions gameFunctions, ICondition condition, ILogger logger) - : TaskExecutor + : TaskExecutor, IConditionChangeAware { private bool _needsUnmount; + private EInteractionState _interactionState = EInteractionState.None; private DateTime _continueAt = DateTime.MinValue; public Quest? Quest => Task.Quest; @@ -111,9 +112,7 @@ internal static class Interact if (gameObject.IsTargetable && HasAnyMarker(gameObject)) { - ProgressContext = - InteractionProgressContext.FromActionUseOrDefault(() => gameFunctions.InteractWith(gameObject)); - _continueAt = DateTime.Now.AddSeconds(0.5); + TriggerInteraction(gameObject); return true; } @@ -148,7 +147,7 @@ internal static class Interact } else { - if (ProgressContext != null && ProgressContext.WasSuccessful()) + if (ProgressContext != null && (ProgressContext.WasSuccessful() || _interactionState == EInteractionState.InteractionConfirmed)) return ETaskResult.TaskComplete; if (InteractionType == EInteractionType.Gather && condition[ConditionFlag.Gathering]) @@ -159,12 +158,24 @@ internal static class Interact if (gameObject == null || !gameObject.IsTargetable || !HasAnyMarker(gameObject)) return ETaskResult.StillRunning; - ProgressContext = - InteractionProgressContext.FromActionUseOrDefault(() => gameFunctions.InteractWith(gameObject)); - _continueAt = DateTime.Now.AddSeconds(0.5); + TriggerInteraction(gameObject); return ETaskResult.StillRunning; } + private void TriggerInteraction(IGameObject gameObject) + { + ProgressContext = + InteractionProgressContext.FromActionUseOrDefault(() => + { + if (gameFunctions.InteractWith(gameObject)) + _interactionState = EInteractionState.InteractionTriggered; + else + _interactionState = EInteractionState.None; + return _interactionState != EInteractionState.None; + }); + _continueAt = DateTime.Now.AddSeconds(0.5); + } + private unsafe bool HasAnyMarker(IGameObject gameObject) { if (Task.SkipMarkerCheck || gameObject.ObjectKind != ObjectKind.EventNpc) @@ -173,5 +184,27 @@ internal static class Interact var gameObjectStruct = (FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)gameObject.Address; return gameObjectStruct->NamePlateIconId != 0; } + + public void OnConditionChange(ConditionFlag flag, bool value) + { + if (ProgressContext != null && (ProgressContext.WasInterrupted() || ProgressContext.WasSuccessful())) + return; + + logger.LogDebug("Condition change: {Flag} = {Value}", flag, value); + if (_interactionState == EInteractionState.InteractionTriggered && + flag is ConditionFlag.OccupiedInQuestEvent or ConditionFlag.OccupiedInEvent && + value) + { + logger.LogInformation("Interaction was most likely triggered"); + _interactionState = EInteractionState.InteractionConfirmed; + } + } + + private enum EInteractionState + { + None, + InteractionTriggered, + InteractionConfirmed, + } } } diff --git a/Questionable/Windows/QuestComponents/CreationUtilsComponent.cs b/Questionable/Windows/QuestComponents/CreationUtilsComponent.cs index 715bc089..d8faefde 100644 --- a/Questionable/Windows/QuestComponents/CreationUtilsComponent.cs +++ b/Questionable/Windows/QuestComponents/CreationUtilsComponent.cs @@ -120,7 +120,8 @@ internal sealed class CreationUtilsComponent #endif #if false - unsafe { + unsafe + { var questManager = QuestManager.Instance(); if (questManager != null) { @@ -134,7 +135,8 @@ internal sealed class CreationUtilsComponent #endif #if false - unsafe { + unsafe + { var director = UIState.Instance()->DirectorTodo.Director; if (director != null) { @@ -143,15 +145,25 @@ internal sealed class CreationUtilsComponent ImGui.Text($"Ico: {director->IconId}"); if (director->EventHandlerInfo != null) { - ImGui.Text($" EHI CI: {director->EventHandlerInfo->EventId.ContentId}"); - ImGui.Text($" EHI EI: {director->EventHandlerInfo->EventId.Id}"); - ImGui.Text($" EHI EEI: {director->EventHandlerInfo->EventId.EntryId}"); - ImGui.Text($" EHI F: {director->EventHandlerInfo->Flags}"); + ImGui.Text($" EHI CI: {director->Info.EventId.ContentId}"); + ImGui.Text($" EHI EI: {director->Info.EventId.Id}"); + ImGui.Text($" EHI EEI: {director->Info.EventId.EntryId}"); + ImGui.Text($" EHI F: {director->Info.Flags}"); } } } #endif +#if false + unsafe + { + var actionManager = ActionManager.Instance(); + ImGui.Text( + $"A1: {actionManager->CastActionId} ({actionManager->LastUsedActionSequence} → {actionManager->LastHandledActionSequence})"); + ImGui.Text($"A2: {actionManager->CastTimeElapsed} / {actionManager->CastTimeTotal}"); + } +#endif + if (_targetManager.Target != null) { DrawTargetDetails(_targetManager.Target);