{
internal sealed class Factory(
IServiceProvider serviceProvider,
- AetheryteFunctions aetheryteFunctions,
AetheryteData aetheryteData) : ITaskFactory
{
- public IEnumerable<ITask> CreateAllTasks(Quest quest, QuestSequence sequence, QuestStep step)
+ public ITask? CreateTask(Quest quest, QuestSequence sequence, QuestStep step)
{
if (step.AetheryteShortcut == null)
- return [];
+ return null;
- var task = serviceProvider.GetRequiredService<UseAetheryteShortcut>()
+ return serviceProvider.GetRequiredService<UseAetheryteShortcut>()
.With(step, step.AetheryteShortcut.Value, aetheryteData.TerritoryIds[step.AetheryteShortcut.Value]);
- return
- [
- new WaitConditionTask(() => aetheryteFunctions.CanTeleport(step.AetheryteShortcut.Value), "CanTeleport"),
- task
- ];
}
-
- public ITask CreateTask(Quest quest, QuestSequence sequence, QuestStep step)
- => throw new InvalidOperationException();
}
internal sealed class UseAetheryteShortcut(
IChatGui chatGui,
AetheryteData aetheryteData) : ISkippableTask
{
+ private bool _teleported;
private DateTime _continueAt;
public QuestStep? Step { get; set; }
return this;
}
- public bool Start()
+ public bool Start() => !ShouldSkipTeleport();
+
+ public ETaskResult Update()
+ {
+ if (DateTime.Now < _continueAt)
+ return ETaskResult.StillRunning;
+
+ if (!_teleported)
+ {
+ _teleported = DoTeleport();
+ return ETaskResult.StillRunning;
+ }
+
+ if (clientState.TerritoryType == ExpectedTerritoryId)
+ return ETaskResult.TaskComplete;
+
+ return ETaskResult.StillRunning;
+ }
+
+ private bool ShouldSkipTeleport()
{
- _continueAt = DateTime.Now.AddSeconds(8);
ushort territoryType = clientState.TerritoryType;
if (Step != null)
{
if (skipConditions.InTerritory.Contains(territoryType))
{
logger.LogInformation("Skipping aetheryte teleport due to SkipCondition (InTerritory)");
- return false;
+ return true;
}
if (skipConditions.AetheryteLocked != null &&
!aetheryteFunctions.IsAetheryteUnlocked(skipConditions.AetheryteLocked.Value))
{
logger.LogInformation("Skipping aetheryte teleport due to SkipCondition (AetheryteLocked)");
- return false;
+ return true;
}
if (skipConditions.AetheryteUnlocked != null &&
aetheryteFunctions.IsAetheryteUnlocked(skipConditions.AetheryteUnlocked.Value))
{
logger.LogInformation("Skipping aetheryte teleport due to SkipCondition (AetheryteUnlocked)");
- return false;
+ return true;
}
}
if (skipConditions is { InSameTerritory: true })
{
logger.LogInformation("Skipping aetheryte teleport due to SkipCondition (InSameTerritory)");
- return false;
+ return true;
}
Vector3 pos = clientState.LocalPlayer!.Position;
(pos - Step.Position.Value).Length() < Step.CalculateActualStopDistance())
{
logger.LogInformation("Skipping aetheryte teleport, we're near the target");
- return false;
+ return true;
}
if (aetheryteData.CalculateDistance(pos, territoryType, TargetAetheryte) < 20 ||
aetheryteData.CalculateDistance(pos, territoryType, Step.AethernetShortcut.To) < 20)))
{
logger.LogInformation("Skipping aetheryte teleport");
- return false;
+ return true;
}
}
}
}
+ return false;
+ }
+
+ private bool DoTeleport()
+ {
+
+ if (!aetheryteFunctions.CanTeleport(TargetAetheryte))
+ {
+ if (!aetheryteFunctions.IsTeleportUnlocked())
+ throw new TaskException("Teleport is not unlocked, attune to any aetheryte first.");
+
+ return false;
+ }
+
+ _continueAt = DateTime.Now.AddSeconds(8);
+
if (!aetheryteFunctions.IsAetheryteUnlocked(TargetAetheryte))
{
chatGui.PrintError($"[Questionable] Aetheryte {TargetAetheryte} is not unlocked.");
}
}
- public ETaskResult Update()
- {
- if (DateTime.Now >= _continueAt && clientState.TerritoryType == ExpectedTerritoryId)
- return ETaskResult.TaskComplete;
-
- return ETaskResult.StillRunning;
- }
-
public override string ToString() => $"UseAetheryte({TargetAetheryte})";
}
}