qstbak/Questionable/Questionable.Controller.Steps.Interactions/Aetheryte.cs
2026-08-17 20:29:32 +10:00

96 lines
2.7 KiB
C#

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 Aetheryte
{
internal sealed class Factory : SimpleTaskFactory
{
public override ITask? CreateTask(Quest quest, QuestSequence sequence, QuestStep step)
{
if (step.InteractionType != EInteractionType.AttuneAetheryte)
{
return null;
}
ArgumentNullException.ThrowIfNull(step.Aetheryte, "step.Aetheryte");
return new Attune(step.Aetheryte.Value);
}
}
internal sealed record Attune(EAetheryteLocation AetheryteLocation) : ITask
{
public bool ShouldRedoOnInterrupt()
{
return true;
}
public override string ToString()
{
return $"AttuneAetheryte({AetheryteLocation})";
}
}
internal abstract class DoAttuneBase<T>(AetheryteFunctions aetheryteFunctions, GameFunctions gameFunctions, ILogger logger, string label) : TaskExecutor<T>() where T : class, ITask
{
protected abstract EAetheryteLocation GetLocation();
protected override bool Start()
{
EAetheryteLocation location = GetLocation();
if (!_003CaetheryteFunctions_003EP.IsAetheryteUnlocked(location))
{
_003Clogger_003EP.LogInformation("Attuning to {Label} {Location}", _003Clabel_003EP, location);
base.ProgressContext = InteractionProgressContext.FromActionUseOrDefault(() => _003CgameFunctions_003EP.InteractWith((uint)location, ObjectKind.Aetheryte));
return true;
}
_003Clogger_003EP.LogDebug("Already attuned to {Label} {Location}", _003Clabel_003EP, location);
return false;
}
public override ETaskResult Update()
{
if (_003CaetheryteFunctions_003EP.IsAetheryteUnlocked(GetLocation()))
{
ResetProgressTimer();
return ETaskResult.TaskComplete;
}
if (base.ProgressContext != null)
{
if (base.ProgressContext.WasInterrupted())
{
_003Clogger_003EP.LogDebug("Attunement to {Label} {Location} was interrupted", _003Clabel_003EP, GetLocation());
return ETaskResult.StillRunning;
}
if (base.ProgressContext.WasSuccessful())
{
ResetProgressTimer();
}
}
return ETaskResult.StillRunning;
}
public override bool ShouldInterruptOnDamage()
{
return true;
}
}
internal sealed class DoAttune : DoAttuneBase<Attune>
{
public DoAttune(AetheryteFunctions aetheryteFunctions, GameFunctions gameFunctions, ILogger<DoAttune> logger)
: base(aetheryteFunctions, gameFunctions, (ILogger)logger, "aetheryte")
{
}
protected override EAetheryteLocation GetLocation()
{
return base.Task.AetheryteLocation;
}
}
}