Improve logging for changes in QuestController.AutomationType and clean up some relat...
authorLiza Carvelli <liza@carvel.li>
Sat, 10 Aug 2024 18:36:43 +0000 (20:36 +0200)
committerLiza Carvelli <liza@carvel.li>
Sat, 10 Aug 2024 18:52:41 +0000 (20:52 +0200)
Questionable/Configuration.cs
Questionable/Controller/CommandHandler.cs
Questionable/Controller/ContextMenuController.cs
Questionable/Controller/GameUiController.cs
Questionable/Controller/QuestController.cs
Questionable/Windows/QuestComponents/ActiveQuestComponent.cs
Questionable/Windows/QuestSelectionWindow.cs

index 4424db236bfc20a943f171f900cc0de05d82bee0..2e8339957e06f35265f22e8e5afaec1b12c9fdf9 100644 (file)
@@ -14,7 +14,6 @@ internal sealed class Configuration : IPluginConfiguration
 
     internal sealed class GeneralConfiguration
     {
-        public bool AutoAcceptNextQuest { get; set; }
         public uint MountId { get; set; } = 71;
         public GrandCompany GrandCompany { get; set; } = GrandCompany.None;
         public bool HideInAllInstances { get; set; } = true;
index 52f7fa4db03d773093ff1e03fa3fd552f24f837f..dbf8ade5ee5680053175493ceb9f5872068e8b58 100644 (file)
@@ -75,7 +75,7 @@ internal sealed class CommandHandler : IDisposable
 
             case "start":
                 _questWindow.IsOpen = true;
-                _questController.ExecuteNextStep(QuestController.EAutomationType.Automatic);
+                _questController.Start("Start command");
                 break;
 
             case "stop":
index bd7aef2d1c655cca76d856765b0f39a10319afc6..3f65d097abee36e0843dc0229617cdc7d1829006 100644 (file)
@@ -146,7 +146,7 @@ internal sealed class ContextMenuController : IDisposable
                 }
             ];
             _questController.SetGatheringQuest(quest);
-            _questController.ExecuteNextStep(QuestController.EAutomationType.CurrentQuestOnly);
+            _questController.StartSingleQuest("SatisfactionSupply prepare gathering");
         }
         else
             _chatGui.PrintError($"No associated quest ({info.QuestId}).", "Questionable");
index e57aef5fe53ec44eec093b4c5892e9a4e44f09ee..9e1bd62c404b6715f2ca0189a09dea57fb24cde9 100644 (file)
@@ -417,7 +417,7 @@ internal sealed class GameUiController : IDisposable
                             return null;
 
                         _questController.GatheringQuest.SetSequence(1);
-                        _questController.ExecuteNextStep(QuestController.EAutomationType.CurrentQuestOnly);
+                        _questController.StartSingleQuest("SatisfactionSupply turn in");
                     }
 
                     return i;
index 420c236013e7103c739523a0d64e03199f7a6093..562c7e52cd9cde3a88536546283bf16dd36ed24d 100644 (file)
@@ -93,6 +93,20 @@ internal sealed class QuestController : MiniTaskController<QuestController>, IDi
         _toastGui.ErrorToast += OnErrorToast;
     }
 
+    public EAutomationType AutomationType
+    {
+        get => _automationType;
+        set
+        {
+            if (value == _automationType)
+                return;
+
+            _logger.LogInformation("Setting automation type to {NewAutomationType} (previous: {OldAutomationType})",
+                value, _automationType);
+            _automationType = value;
+        }
+    }
+
     public (QuestProgress Progress, ECurrentQuestType Type)? CurrentQuestDetails
     {
         get
@@ -185,7 +199,7 @@ internal sealed class QuestController : MiniTaskController<QuestController>, IDi
         if (CurrentQuest != null && CurrentQuest.Quest.Root.TerritoryBlacklist.Contains(_clientState.TerritoryType))
             return;
 
-        if (_automationType == EAutomationType.Automatic &&
+        if (AutomationType == EAutomationType.Automatic &&
             ((_currentTask == null && _taskQueue.Count == 0) ||
              _currentTask is WaitAtEnd.WaitQuestAccepted)
             && CurrentQuest is { Sequence: 0, Step: 0 } or { Sequence: 0, Step: 255 }
@@ -197,7 +211,7 @@ internal sealed class QuestController : MiniTaskController<QuestController>, IDi
                 CurrentQuest.SetStep(0);
             }
 
-            ExecuteNextStep(_automationType);
+            ExecuteNextStep();
             return;
         }
 
@@ -221,7 +235,7 @@ internal sealed class QuestController : MiniTaskController<QuestController>, IDi
                 {
                     _startedQuest = _pendingQuest;
                     _pendingQuest = null;
-                    Stop("Pending quest accepted", continueIfAutomatic: true);
+                    CheckNextTasks("Pending quest accepted");
                 }
             }
 
@@ -260,8 +274,8 @@ internal sealed class QuestController : MiniTaskController<QuestController>, IDi
                 if (_nextQuest.Step == 0 &&
                     _currentTask == null &&
                     _taskQueue.Count == 0 &&
-                    _automationType == EAutomationType.Automatic)
-                    ExecuteNextStep(_automationType);
+                    AutomationType == EAutomationType.Automatic)
+                    ExecuteNextStep();
             }
             else if (_gatheringQuest != null)
             {
@@ -270,8 +284,8 @@ internal sealed class QuestController : MiniTaskController<QuestController>, IDi
                 if (_gatheringQuest.Step == 0 &&
                     _currentTask == null &&
                     _taskQueue.Count == 0 &&
-                    _automationType == EAutomationType.Automatic)
-                    ExecuteNextStep(_automationType);
+                    AutomationType == EAutomationType.Automatic)
+                    ExecuteNextStep();
             }
             else
             {
@@ -294,12 +308,14 @@ internal sealed class QuestController : MiniTaskController<QuestController>, IDi
                         _logger.LogInformation("New quest: {QuestName}", quest.Info.Name);
                         _startedQuest = new QuestProgress(quest, currentSequence);
 
-                        bool continueAutomatically = _configuration.General.AutoAcceptNextQuest;
-
-                        if (_clientState.LocalPlayer?.Level < quest.Info.Level)
-                            continueAutomatically = false;
-
-                        Stop("Different Quest", continueAutomatically);
+                        if (_clientState.LocalPlayer!.Level < quest.Info.Level)
+                        {
+                            _logger.LogInformation("Stopping automation, player level ({PlayerLevel}) < quest level ({QuestLevel}",
+                                _clientState.LocalPlayer!.Level, quest.Info.Level);
+                            Stop("Quest level too high");
+                        }
+                        else
+                            CheckNextTasks("Different Quest");
                     }
                     else if (_startedQuest != null)
                     {
@@ -348,8 +364,7 @@ internal sealed class QuestController : MiniTaskController<QuestController>, IDi
             if (questToRun.Sequence != currentSequence)
             {
                 questToRun.SetSequence(currentSequence);
-                Stop($"New sequence {questToRun == _startedQuest}/{_questFunctions.GetCurrentQuestInternal()}",
-                    continueIfAutomatic: true);
+                CheckNextTasks($"New sequence {questToRun == _startedQuest}/{_questFunctions.GetCurrentQuestInternal()}");
             }
 
             var q = questToRun.Quest;
@@ -365,7 +380,7 @@ internal sealed class QuestController : MiniTaskController<QuestController>, IDi
             {
                 DebugState = "Step completed";
                 if (_currentTask != null || _taskQueue.Count > 0)
-                    Stop("Step complete", continueIfAutomatic: true);
+                    CheckNextTasks("Step complete");
                 return;
             }
 
@@ -429,8 +444,9 @@ internal sealed class QuestController : MiniTaskController<QuestController>, IDi
                 CurrentQuest.SetStep(255);
         }
 
-        if (shouldContinue && _automationType != EAutomationType.Manual)
-            ExecuteNextStep(_automationType);
+        using var scope = _logger.BeginScope("IncStepCt");
+        if (shouldContinue && AutomationType != EAutomationType.Manual)
+            ExecuteNextStep();
     }
 
     private void ClearTasksInternal()
@@ -446,34 +462,39 @@ internal sealed class QuestController : MiniTaskController<QuestController>, IDi
         _gatheringController.Stop("ClearTasksInternal");
     }
 
-    public void Stop(string label, bool continueIfAutomatic)
+    public override void Stop(string label)
     {
-        using var scope = _logger.BeginScope(label);
-
-        ClearTasksInternal();
+        using var scope = _logger.BeginScope($"Stop/{label}");
+        if (IsRunning || AutomationType != EAutomationType.Manual)
+        {
+            ClearTasksInternal();
+            _logger.LogInformation("Stopping automatic questing");
+            AutomationType = EAutomationType.Manual;
+            _nextQuest = null;
+            _gatheringQuest = null;
+            _lastTaskUpdate = DateTime.Now;
+        }
+    }
 
-        // reset task queue
-        if (continueIfAutomatic && _automationType == EAutomationType.Automatic)
+    private void CheckNextTasks(string label)
+    {
+        if (AutomationType == EAutomationType.Automatic)
         {
+            using var scope = _logger.BeginScope(label);
+
+            ClearTasksInternal();
+
             if (CurrentQuest?.Step is >= 0 and < 255)
-                ExecuteNextStep(_automationType);
+                ExecuteNextStep();
             else
                 _logger.LogInformation("Couldn't execute next step during Stop() call");
 
             _lastTaskUpdate = DateTime.Now;
         }
-        else if (_automationType != EAutomationType.Manual)
-        {
-            _logger.LogInformation("Stopping automatic questing");
-            _automationType = EAutomationType.Manual;
-            _nextQuest = null;
-            _gatheringQuest = null;
-            _lastTaskUpdate = DateTime.Now;
-        }
+        else
+            Stop(label);
     }
 
-    public override void Stop(string label) => Stop(label, false);
-
     public void SimulateQuest(Quest? quest)
     {
         _logger.LogInformation("SimulateQuest: {QuestId}", quest?.Id);
@@ -526,10 +547,30 @@ internal sealed class QuestController : MiniTaskController<QuestController>, IDi
         IncreaseStepCount(task.ElementId, task.Sequence, true);
     }
 
-    public void ExecuteNextStep(EAutomationType automatic)
+    public void Start(string label)
+    {
+        using var scope = _logger.BeginScope($"Q/{label}");
+        AutomationType = EAutomationType.Automatic;
+        ExecuteNextStep();
+    }
+
+    public void StartSingleQuest(string label)
+    {
+        using var scope = _logger.BeginScope($"SQ/{label}");
+        AutomationType = EAutomationType.CurrentQuestOnly;
+        ExecuteNextStep();
+    }
+
+    public void StartSingleStep(string label)
+    {
+        using var scope = _logger.BeginScope($"SS/{label}");
+        AutomationType = EAutomationType.Manual;
+        ExecuteNextStep();
+    }
+
+    private void ExecuteNextStep()
     {
         ClearTasksInternal();
-        _automationType = automatic;
 
         if (TryPickPriorityQuest())
             _logger.LogInformation("Using priority quest over current quest");
index e36fe2a1df28ec5d7e08191d28cea06b939d36ed..2e7b3e76a7400345613c6e4bf6dd3666c391d0cd 100644 (file)
@@ -221,7 +221,7 @@ internal sealed class ActiveQuestComponent
             if (questProgressInfo == null)
                 _questController.SetNextQuest(currentQuest.Quest);
 
-            _questController.ExecuteNextStep(QuestController.EAutomationType.Automatic);
+            _questController.Start("UI start");
         }
 
         if (!isMinimized)
@@ -230,7 +230,7 @@ internal sealed class ActiveQuestComponent
 
             if (ImGuiComponents.IconButtonWithText(FontAwesomeIcon.StepForward, "Step"))
             {
-                _questController.ExecuteNextStep(QuestController.EAutomationType.Manual);
+                _questController.StartSingleStep("UI step");
             }
         }
 
@@ -240,8 +240,8 @@ internal sealed class ActiveQuestComponent
         if (ImGuiComponents.IconButton(FontAwesomeIcon.Stop))
         {
             _movementController.Stop();
-            _questController.Stop("Manual");
-            _gatheringController.Stop("Manual");
+            _questController.Stop("UI stop");
+            _gatheringController.Stop("UI stop");
         }
 
         if (isMinimized)
@@ -279,13 +279,6 @@ internal sealed class ActiveQuestComponent
                     _commandManager.DispatchCommand("/questinfo",
                         currentQuest.Quest.Id.ToString() ?? string.Empty, commandInfo);
             }
-
-            bool autoAcceptNextQuest = _configuration.General.AutoAcceptNextQuest;
-            if (ImGui.Checkbox("Automatically accept next quest", ref autoAcceptNextQuest))
-            {
-                _configuration.General.AutoAcceptNextQuest = autoAcceptNextQuest;
-                _pluginInterface.SavePluginConfig(_configuration);
-            }
         }
     }
 
index 1f7c47057e283244193ea2e5c51b61b92d1f6a95..48e0b333210fec8f0dad4d0325120fb722ff9fdd 100644 (file)
@@ -237,7 +237,7 @@ internal sealed class QuestSelectionWindow : LWindow
                     if (startNextQuest)
                     {
                         _questController.SetNextQuest(knownQuest);
-                        _questController.ExecuteNextStep(QuestController.EAutomationType.Automatic);
+                        _questController.Start("QuestSelectionWindow");
                     }
 
                     ImGui.SameLine();