using System; using Dalamud.Game.ClientState.Objects.Enums; using Dalamud.Plugin.Services; using Microsoft.Extensions.Logging; using Questionable.Data; using Questionable.Functions; using Questionable.Model; using Questionable.Model.Questing; namespace Questionable.Controller.Steps.Interactions; internal static class AetherCurrent { internal sealed class Factory(AetherCurrentData aetherCurrentData, IChatGui chatGui) : SimpleTaskFactory() { public override ITask? CreateTask(Quest quest, QuestSequence sequence, QuestStep step) { if (step.InteractionType != EInteractionType.AttuneAetherCurrent) { return null; } ArgumentNullException.ThrowIfNull(step.DataId, "step.DataId"); ArgumentNullException.ThrowIfNull(step.AetherCurrentId, "step.AetherCurrentId"); if (!aetherCurrentData.IsValidAetherCurrent(step.TerritoryId, step.AetherCurrentId.Value)) { chatGui.PrintError($"Aether current with id {step.AetherCurrentId} is referencing an invalid aether current, will skip attunement", "Questionable", 576); return null; } return new Attune(step.DataId.Value, step.AetherCurrentId.Value); } } internal sealed record Attune(uint DataId, uint AetherCurrentId) : ITask { public bool ShouldRedoOnInterrupt() { return true; } public override string ToString() { return $"AttuneAetherCurrent({AetherCurrentId})"; } } internal sealed class DoAttune(GameFunctions gameFunctions, ILogger logger) : TaskExecutor() { protected override bool Start() { if (!GameFunctions.IsAetherCurrentUnlocked(base.Task.AetherCurrentId)) { logger.LogInformation("Attuning to aether current {AetherCurrentId} / {DataId}", base.Task.AetherCurrentId, base.Task.DataId); base.ProgressContext = InteractionProgressContext.FromActionUseOrDefault(() => gameFunctions.InteractWith(base.Task.DataId, ObjectKind.EventObj)); return true; } logger.LogDebug("Already attuned to aether current {AetherCurrentId} / {DataId}", base.Task.AetherCurrentId, base.Task.DataId); return false; } public override ETaskResult Update() { if (GameFunctions.IsAetherCurrentUnlocked(base.Task.AetherCurrentId)) { ResetProgressTimer(); return ETaskResult.TaskComplete; } if (base.ProgressContext != null) { if (base.ProgressContext.WasInterrupted()) { logger.LogDebug("Aether current {AetherCurrentId} attunement was interrupted", base.Task.AetherCurrentId); return ETaskResult.StillRunning; } if (base.ProgressContext.WasSuccessful()) { ResetProgressTimer(); } } return ETaskResult.StillRunning; } public override bool ShouldInterruptOnDamage() { return true; } } }