Fix certain kinds of interactions v3.6
authorLiza Carvelli <liza@carvel.li>
Fri, 20 Sep 2024 19:52:46 +0000 (21:52 +0200)
committerLiza Carvelli <liza@carvel.li>
Fri, 20 Sep 2024 20:00:02 +0000 (22:00 +0200)
Directory.Build.targets
Questionable/Controller/Steps/Interactions/Interact.cs
Questionable/Windows/QuestComponents/CreationUtilsComponent.cs

index abb1feac6f33137f344141880dc512b834dbc195..aac0b377798c7266975d786be7f18c24cc686706 100644 (file)
@@ -1,5 +1,5 @@
 <Project>
     <PropertyGroup>
-        <Version>3.5</Version>
+        <Version>3.6</Version>
     </PropertyGroup>
 </Project>
index 5dd28d206765655c20fe10d7f3cd4acd840f5523..1b7caea312c64d7b8754cd90b555d5c2512eb4f0 100644 (file)
@@ -72,9 +72,10 @@ internal static class Interact
         GameFunctions gameFunctions,
         ICondition condition,
         ILogger<DoInteract> logger)
-        : TaskExecutor<Task>
+        : TaskExecutor<Task>, 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,10 +158,22 @@ internal static class Interact
             if (gameObject == null || !gameObject.IsTargetable || !HasAnyMarker(gameObject))
                 return ETaskResult.StillRunning;
 
+            TriggerInteraction(gameObject);
+            return ETaskResult.StillRunning;
+        }
+
+        private void TriggerInteraction(IGameObject gameObject)
+        {
             ProgressContext =
-                InteractionProgressContext.FromActionUseOrDefault(() => gameFunctions.InteractWith(gameObject));
+                InteractionProgressContext.FromActionUseOrDefault(() =>
+                {
+                    if (gameFunctions.InteractWith(gameObject))
+                        _interactionState = EInteractionState.InteractionTriggered;
+                    else
+                        _interactionState = EInteractionState.None;
+                    return _interactionState != EInteractionState.None;
+                });
             _continueAt = DateTime.Now.AddSeconds(0.5);
-            return ETaskResult.StillRunning;
         }
 
         private unsafe bool HasAnyMarker(IGameObject gameObject)
@@ -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,
+        }
     }
 }
index 715bc089b163886b29e2046019d17d3092e1bc4f..d8faefdea8406b3d73f8e0b9181fbee6bf4468f2 100644 (file)
@@ -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);