using System; using Dalamud.Game.ClientState.Objects.Enums; using Microsoft.Extensions.Logging; using Questionable.Functions; using Questionable.Model; using Questionable.Model.Questing; using SmartNav.Model; namespace Questionable.Controller.Steps.Interactions; internal static class AetheryteFreeOrFavored { internal sealed class Factory : SimpleTaskFactory { public override ITask? CreateTask(Quest quest, QuestSequence sequence, QuestStep step) { if (step.InteractionType != EInteractionType.RegisterFreeOrFavoredAetheryte) { return null; } ArgumentNullException.ThrowIfNull(step.Aetheryte, "step.Aetheryte"); return new Register(step.Aetheryte.Value); } } internal sealed record Register(EAetheryteLocation AetheryteLocation) : ITask { public bool ShouldRedoOnInterrupt() { return true; } public override string ToString() { return $"RegisterFreeOrFavoredAetheryte({AetheryteLocation})"; } } internal sealed class DoRegister(AetheryteFunctions aetheryteFunctions, GameFunctions gameFunctions, ILogger logger) : TaskExecutor() { protected override bool Start() { if (!aetheryteFunctions.IsAetheryteUnlocked(base.Task.AetheryteLocation)) { throw new TaskException($"Aetheryte {base.Task.AetheryteLocation} is not attuned"); } if (aetheryteFunctions.CanRegisterFreeOrFavoriteAetheryte(base.Task.AetheryteLocation) == AetheryteRegistrationResult.NotPossible) { logger.LogDebug("Could not register aetheryte {AetheryteLocation} as free or favored", base.Task.AetheryteLocation); return false; } base.ProgressContext = InteractionProgressContext.FromActionUseOrDefault(() => gameFunctions.InteractWith((uint)base.Task.AetheryteLocation, ObjectKind.Aetheryte)); return true; } public override ETaskResult Update() { if (aetheryteFunctions.CanRegisterFreeOrFavoriteAetheryte(base.Task.AetheryteLocation) == AetheryteRegistrationResult.NotPossible) { ResetProgressTimer(); return ETaskResult.TaskComplete; } if (base.ProgressContext != null) { if (base.ProgressContext.WasInterrupted()) { logger.LogDebug("Registration of {Location} was interrupted", base.Task.AetheryteLocation); return ETaskResult.StillRunning; } if (base.ProgressContext.WasSuccessful()) { ResetProgressTimer(); } } return ETaskResult.StillRunning; } public override bool ShouldInterruptOnDamage() { return true; } } }