qstbak/Questionable/Questionable.Controller.Steps.Interactions/AetherCurrent.cs
2025-10-09 07:47:19 +10:00

74 lines
2.3 KiB
C#

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<DoAttune> logger) : TaskExecutor<Attune>()
{
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.LogInformation("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))
{
return ETaskResult.StillRunning;
}
return ETaskResult.TaskComplete;
}
public override bool ShouldInterruptOnDamage()
{
return true;
}
}
}