_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
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 }
CurrentQuest.SetStep(0);
}
- ExecuteNextStep(_automationType);
+ ExecuteNextStep();
return;
}
{
_startedQuest = _pendingQuest;
_pendingQuest = null;
- Stop("Pending quest accepted", continueIfAutomatic: true);
+ CheckNextTasks("Pending quest accepted");
}
}
if (_nextQuest.Step == 0 &&
_currentTask == null &&
_taskQueue.Count == 0 &&
- _automationType == EAutomationType.Automatic)
- ExecuteNextStep(_automationType);
+ AutomationType == EAutomationType.Automatic)
+ ExecuteNextStep();
}
else if (_gatheringQuest != null)
{
if (_gatheringQuest.Step == 0 &&
_currentTask == null &&
_taskQueue.Count == 0 &&
- _automationType == EAutomationType.Automatic)
- ExecuteNextStep(_automationType);
+ AutomationType == EAutomationType.Automatic)
+ ExecuteNextStep();
}
else
{
_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)
{
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;
{
DebugState = "Step completed";
if (_currentTask != null || _taskQueue.Count > 0)
- Stop("Step complete", continueIfAutomatic: true);
+ CheckNextTasks("Step complete");
return;
}
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()
_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);
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");