Improve logging for changes in QuestController.AutomationType and clean up some related methods
This commit is contained in:
parent
7e9eb212e3
commit
ec2a8a15fc
@ -14,7 +14,6 @@ internal sealed class Configuration : IPluginConfiguration
|
|||||||
|
|
||||||
internal sealed class GeneralConfiguration
|
internal sealed class GeneralConfiguration
|
||||||
{
|
{
|
||||||
public bool AutoAcceptNextQuest { get; set; }
|
|
||||||
public uint MountId { get; set; } = 71;
|
public uint MountId { get; set; } = 71;
|
||||||
public GrandCompany GrandCompany { get; set; } = GrandCompany.None;
|
public GrandCompany GrandCompany { get; set; } = GrandCompany.None;
|
||||||
public bool HideInAllInstances { get; set; } = true;
|
public bool HideInAllInstances { get; set; } = true;
|
||||||
|
@ -75,7 +75,7 @@ internal sealed class CommandHandler : IDisposable
|
|||||||
|
|
||||||
case "start":
|
case "start":
|
||||||
_questWindow.IsOpen = true;
|
_questWindow.IsOpen = true;
|
||||||
_questController.ExecuteNextStep(QuestController.EAutomationType.Automatic);
|
_questController.Start("Start command");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "stop":
|
case "stop":
|
||||||
|
@ -146,7 +146,7 @@ internal sealed class ContextMenuController : IDisposable
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
_questController.SetGatheringQuest(quest);
|
_questController.SetGatheringQuest(quest);
|
||||||
_questController.ExecuteNextStep(QuestController.EAutomationType.CurrentQuestOnly);
|
_questController.StartSingleQuest("SatisfactionSupply prepare gathering");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
_chatGui.PrintError($"No associated quest ({info.QuestId}).", "Questionable");
|
_chatGui.PrintError($"No associated quest ({info.QuestId}).", "Questionable");
|
||||||
|
@ -417,7 +417,7 @@ internal sealed class GameUiController : IDisposable
|
|||||||
return null;
|
return null;
|
||||||
|
|
||||||
_questController.GatheringQuest.SetSequence(1);
|
_questController.GatheringQuest.SetSequence(1);
|
||||||
_questController.ExecuteNextStep(QuestController.EAutomationType.CurrentQuestOnly);
|
_questController.StartSingleQuest("SatisfactionSupply turn in");
|
||||||
}
|
}
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
|
@ -93,6 +93,20 @@ internal sealed class QuestController : MiniTaskController<QuestController>, IDi
|
|||||||
_toastGui.ErrorToast += OnErrorToast;
|
_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
|
public (QuestProgress Progress, ECurrentQuestType Type)? CurrentQuestDetails
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@ -185,7 +199,7 @@ internal sealed class QuestController : MiniTaskController<QuestController>, IDi
|
|||||||
if (CurrentQuest != null && CurrentQuest.Quest.Root.TerritoryBlacklist.Contains(_clientState.TerritoryType))
|
if (CurrentQuest != null && CurrentQuest.Quest.Root.TerritoryBlacklist.Contains(_clientState.TerritoryType))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_automationType == EAutomationType.Automatic &&
|
if (AutomationType == EAutomationType.Automatic &&
|
||||||
((_currentTask == null && _taskQueue.Count == 0) ||
|
((_currentTask == null && _taskQueue.Count == 0) ||
|
||||||
_currentTask is WaitAtEnd.WaitQuestAccepted)
|
_currentTask is WaitAtEnd.WaitQuestAccepted)
|
||||||
&& CurrentQuest is { Sequence: 0, Step: 0 } or { Sequence: 0, Step: 255 }
|
&& 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);
|
CurrentQuest.SetStep(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
ExecuteNextStep(_automationType);
|
ExecuteNextStep();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,7 +235,7 @@ internal sealed class QuestController : MiniTaskController<QuestController>, IDi
|
|||||||
{
|
{
|
||||||
_startedQuest = _pendingQuest;
|
_startedQuest = _pendingQuest;
|
||||||
_pendingQuest = null;
|
_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 &&
|
if (_nextQuest.Step == 0 &&
|
||||||
_currentTask == null &&
|
_currentTask == null &&
|
||||||
_taskQueue.Count == 0 &&
|
_taskQueue.Count == 0 &&
|
||||||
_automationType == EAutomationType.Automatic)
|
AutomationType == EAutomationType.Automatic)
|
||||||
ExecuteNextStep(_automationType);
|
ExecuteNextStep();
|
||||||
}
|
}
|
||||||
else if (_gatheringQuest != null)
|
else if (_gatheringQuest != null)
|
||||||
{
|
{
|
||||||
@ -270,8 +284,8 @@ internal sealed class QuestController : MiniTaskController<QuestController>, IDi
|
|||||||
if (_gatheringQuest.Step == 0 &&
|
if (_gatheringQuest.Step == 0 &&
|
||||||
_currentTask == null &&
|
_currentTask == null &&
|
||||||
_taskQueue.Count == 0 &&
|
_taskQueue.Count == 0 &&
|
||||||
_automationType == EAutomationType.Automatic)
|
AutomationType == EAutomationType.Automatic)
|
||||||
ExecuteNextStep(_automationType);
|
ExecuteNextStep();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -294,12 +308,14 @@ internal sealed class QuestController : MiniTaskController<QuestController>, IDi
|
|||||||
_logger.LogInformation("New quest: {QuestName}", quest.Info.Name);
|
_logger.LogInformation("New quest: {QuestName}", quest.Info.Name);
|
||||||
_startedQuest = new QuestProgress(quest, currentSequence);
|
_startedQuest = new QuestProgress(quest, currentSequence);
|
||||||
|
|
||||||
bool continueAutomatically = _configuration.General.AutoAcceptNextQuest;
|
if (_clientState.LocalPlayer!.Level < quest.Info.Level)
|
||||||
|
{
|
||||||
if (_clientState.LocalPlayer?.Level < quest.Info.Level)
|
_logger.LogInformation("Stopping automation, player level ({PlayerLevel}) < quest level ({QuestLevel}",
|
||||||
continueAutomatically = false;
|
_clientState.LocalPlayer!.Level, quest.Info.Level);
|
||||||
|
Stop("Quest level too high");
|
||||||
Stop("Different Quest", continueAutomatically);
|
}
|
||||||
|
else
|
||||||
|
CheckNextTasks("Different Quest");
|
||||||
}
|
}
|
||||||
else if (_startedQuest != null)
|
else if (_startedQuest != null)
|
||||||
{
|
{
|
||||||
@ -348,8 +364,7 @@ internal sealed class QuestController : MiniTaskController<QuestController>, IDi
|
|||||||
if (questToRun.Sequence != currentSequence)
|
if (questToRun.Sequence != currentSequence)
|
||||||
{
|
{
|
||||||
questToRun.SetSequence(currentSequence);
|
questToRun.SetSequence(currentSequence);
|
||||||
Stop($"New sequence {questToRun == _startedQuest}/{_questFunctions.GetCurrentQuestInternal()}",
|
CheckNextTasks($"New sequence {questToRun == _startedQuest}/{_questFunctions.GetCurrentQuestInternal()}");
|
||||||
continueIfAutomatic: true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var q = questToRun.Quest;
|
var q = questToRun.Quest;
|
||||||
@ -365,7 +380,7 @@ internal sealed class QuestController : MiniTaskController<QuestController>, IDi
|
|||||||
{
|
{
|
||||||
DebugState = "Step completed";
|
DebugState = "Step completed";
|
||||||
if (_currentTask != null || _taskQueue.Count > 0)
|
if (_currentTask != null || _taskQueue.Count > 0)
|
||||||
Stop("Step complete", continueIfAutomatic: true);
|
CheckNextTasks("Step complete");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -429,8 +444,9 @@ internal sealed class QuestController : MiniTaskController<QuestController>, IDi
|
|||||||
CurrentQuest.SetStep(255);
|
CurrentQuest.SetStep(255);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldContinue && _automationType != EAutomationType.Manual)
|
using var scope = _logger.BeginScope("IncStepCt");
|
||||||
ExecuteNextStep(_automationType);
|
if (shouldContinue && AutomationType != EAutomationType.Manual)
|
||||||
|
ExecuteNextStep();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ClearTasksInternal()
|
private void ClearTasksInternal()
|
||||||
@ -446,33 +462,38 @@ internal sealed class QuestController : MiniTaskController<QuestController>, IDi
|
|||||||
_gatheringController.Stop("ClearTasksInternal");
|
_gatheringController.Stop("ClearTasksInternal");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Stop(string label, bool continueIfAutomatic)
|
public override void Stop(string label)
|
||||||
{
|
{
|
||||||
using var scope = _logger.BeginScope(label);
|
using var scope = _logger.BeginScope($"Stop/{label}");
|
||||||
|
if (IsRunning || AutomationType != EAutomationType.Manual)
|
||||||
ClearTasksInternal();
|
|
||||||
|
|
||||||
// reset task queue
|
|
||||||
if (continueIfAutomatic && _automationType == EAutomationType.Automatic)
|
|
||||||
{
|
|
||||||
if (CurrentQuest?.Step is >= 0 and < 255)
|
|
||||||
ExecuteNextStep(_automationType);
|
|
||||||
else
|
|
||||||
_logger.LogInformation("Couldn't execute next step during Stop() call");
|
|
||||||
|
|
||||||
_lastTaskUpdate = DateTime.Now;
|
|
||||||
}
|
|
||||||
else if (_automationType != EAutomationType.Manual)
|
|
||||||
{
|
{
|
||||||
|
ClearTasksInternal();
|
||||||
_logger.LogInformation("Stopping automatic questing");
|
_logger.LogInformation("Stopping automatic questing");
|
||||||
_automationType = EAutomationType.Manual;
|
AutomationType = EAutomationType.Manual;
|
||||||
_nextQuest = null;
|
_nextQuest = null;
|
||||||
_gatheringQuest = null;
|
_gatheringQuest = null;
|
||||||
_lastTaskUpdate = DateTime.Now;
|
_lastTaskUpdate = DateTime.Now;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Stop(string label) => Stop(label, false);
|
private void CheckNextTasks(string label)
|
||||||
|
{
|
||||||
|
if (AutomationType == EAutomationType.Automatic)
|
||||||
|
{
|
||||||
|
using var scope = _logger.BeginScope(label);
|
||||||
|
|
||||||
|
ClearTasksInternal();
|
||||||
|
|
||||||
|
if (CurrentQuest?.Step is >= 0 and < 255)
|
||||||
|
ExecuteNextStep();
|
||||||
|
else
|
||||||
|
_logger.LogInformation("Couldn't execute next step during Stop() call");
|
||||||
|
|
||||||
|
_lastTaskUpdate = DateTime.Now;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Stop(label);
|
||||||
|
}
|
||||||
|
|
||||||
public void SimulateQuest(Quest? quest)
|
public void SimulateQuest(Quest? quest)
|
||||||
{
|
{
|
||||||
@ -526,10 +547,30 @@ internal sealed class QuestController : MiniTaskController<QuestController>, IDi
|
|||||||
IncreaseStepCount(task.ElementId, task.Sequence, true);
|
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();
|
ClearTasksInternal();
|
||||||
_automationType = automatic;
|
|
||||||
|
|
||||||
if (TryPickPriorityQuest())
|
if (TryPickPriorityQuest())
|
||||||
_logger.LogInformation("Using priority quest over current quest");
|
_logger.LogInformation("Using priority quest over current quest");
|
||||||
|
@ -221,7 +221,7 @@ internal sealed class ActiveQuestComponent
|
|||||||
if (questProgressInfo == null)
|
if (questProgressInfo == null)
|
||||||
_questController.SetNextQuest(currentQuest.Quest);
|
_questController.SetNextQuest(currentQuest.Quest);
|
||||||
|
|
||||||
_questController.ExecuteNextStep(QuestController.EAutomationType.Automatic);
|
_questController.Start("UI start");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isMinimized)
|
if (!isMinimized)
|
||||||
@ -230,7 +230,7 @@ internal sealed class ActiveQuestComponent
|
|||||||
|
|
||||||
if (ImGuiComponents.IconButtonWithText(FontAwesomeIcon.StepForward, "Step"))
|
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))
|
if (ImGuiComponents.IconButton(FontAwesomeIcon.Stop))
|
||||||
{
|
{
|
||||||
_movementController.Stop();
|
_movementController.Stop();
|
||||||
_questController.Stop("Manual");
|
_questController.Stop("UI stop");
|
||||||
_gatheringController.Stop("Manual");
|
_gatheringController.Stop("UI stop");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isMinimized)
|
if (isMinimized)
|
||||||
@ -279,13 +279,6 @@ internal sealed class ActiveQuestComponent
|
|||||||
_commandManager.DispatchCommand("/questinfo",
|
_commandManager.DispatchCommand("/questinfo",
|
||||||
currentQuest.Quest.Id.ToString() ?? string.Empty, commandInfo);
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,7 +237,7 @@ internal sealed class QuestSelectionWindow : LWindow
|
|||||||
if (startNextQuest)
|
if (startNextQuest)
|
||||||
{
|
{
|
||||||
_questController.SetNextQuest(knownQuest);
|
_questController.SetNextQuest(knownQuest);
|
||||||
_questController.ExecuteNextStep(QuestController.EAutomationType.Automatic);
|
_questController.Start("QuestSelectionWindow");
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui.SameLine();
|
ImGui.SameLine();
|
||||||
|
Loading…
Reference in New Issue
Block a user