using System; using System.Collections.Generic; using Dalamud.Plugin.Services; using Microsoft.Extensions.Logging; using Questionable.Controller.Steps; using Questionable.Functions; namespace Questionable.Controller; internal sealed class AttunementController : MiniTaskController { private readonly MovementController _movementController; private readonly GameFunctions _gameFunctions; private string? _currentTargetName; public bool IsRunning => _currentTargetName != null; public string? CurrentTargetName => _currentTargetName; public bool CompletedSuccessfully { get; private set; } public AttunementController(IChatGui chatGui, ICondition condition, IServiceProvider serviceProvider, InterruptHandler interruptHandler, IDataManager dataManager, Configuration configuration, ILogger logger, MovementController movementController, GameFunctions gameFunctions) : base(chatGui, condition, serviceProvider, interruptHandler, dataManager, configuration, logger) { _movementController = movementController; _gameFunctions = gameFunctions; } public void Start(string targetName, IEnumerable tasks) { _currentTargetName = targetName; _logger.LogInformation("Starting attunement: {Target}", targetName); foreach (ITask task in tasks) { _taskQueue.Enqueue(task); } } public void Update() { if (_currentTargetName != null && !_movementController.IsPathfinding && !_movementController.IsPathRunning && !_gameFunctions.IsOccupied()) { if (_taskQueue.AllTasksComplete) { _logger.LogInformation("Attunement complete: {Target}", _currentTargetName); Stop("Attunement complete"); } else { UpdateCurrentTask(); } } } public override void Stop(string label) { base.Stop(label); if (_currentTargetName != null) { CompletedSuccessfully = _taskQueue.AllTasksComplete; _logger.LogInformation("Stopping attunement: {Label}", label); _currentTargetName = null; _taskQueue.Reset(); } } }