From 2c77dc479f7ee9d0fb75f406c78009a78bea44b5 Mon Sep 17 00:00:00 2001 From: Liza Carvelli Date: Sat, 10 Aug 2024 18:14:15 +0200 Subject: [PATCH] Add 'EquipRecommended' task --- QuestPaths/quest-v1.json | 1 + .../Converter/InteractionTypeConverter.cs | 1 + .../Questing/EInteractionType.cs | 1 + .../Steps/Interactions/EquipRecommended.cs | 50 +++++++++++++++++++ Questionable/QuestionablePlugin.cs | 1 + 5 files changed, 54 insertions(+) create mode 100644 Questionable/Controller/Steps/Interactions/EquipRecommended.cs diff --git a/QuestPaths/quest-v1.json b/QuestPaths/quest-v1.json index 25d083b6c..e703cd565 100644 --- a/QuestPaths/quest-v1.json +++ b/QuestPaths/quest-v1.json @@ -110,6 +110,7 @@ "Combat", "UseItem", "EquipItem", + "EquipRecommended", "Say", "Emote", "Action", diff --git a/Questionable.Model/Questing/Converter/InteractionTypeConverter.cs b/Questionable.Model/Questing/Converter/InteractionTypeConverter.cs index 2343676dc..a7c810610 100644 --- a/Questionable.Model/Questing/Converter/InteractionTypeConverter.cs +++ b/Questionable.Model/Questing/Converter/InteractionTypeConverter.cs @@ -16,6 +16,7 @@ public sealed class InteractionTypeConverter() : EnumConverter { EInteractionType.Combat, "Combat" }, { EInteractionType.UseItem, "UseItem" }, { EInteractionType.EquipItem, "EquipItem" }, + { EInteractionType.EquipRecommended, "EquipRecommended" }, { EInteractionType.Say, "Say" }, { EInteractionType.Emote, "Emote" }, { EInteractionType.Action, "Action" }, diff --git a/Questionable.Model/Questing/EInteractionType.cs b/Questionable.Model/Questing/EInteractionType.cs index 144861b75..b52458caf 100644 --- a/Questionable.Model/Questing/EInteractionType.cs +++ b/Questionable.Model/Questing/EInteractionType.cs @@ -15,6 +15,7 @@ public enum EInteractionType Combat, UseItem, EquipItem, + EquipRecommended, Say, Emote, Action, diff --git a/Questionable/Controller/Steps/Interactions/EquipRecommended.cs b/Questionable/Controller/Steps/Interactions/EquipRecommended.cs new file mode 100644 index 000000000..26af42f10 --- /dev/null +++ b/Questionable/Controller/Steps/Interactions/EquipRecommended.cs @@ -0,0 +1,50 @@ +using System; +using Dalamud.Plugin.Services; +using FFXIVClientStructs.FFXIV.Client.UI.Misc; +using Microsoft.Extensions.DependencyInjection; +using Questionable.Model; +using Questionable.Model.Questing; + +namespace Questionable.Controller.Steps.Interactions; + +internal static class EquipRecommended +{ + internal sealed class Factory(IServiceProvider serviceProvider) : ITaskFactory + { + public ITask? CreateTask(Quest quest, QuestSequence sequence, QuestStep step) + { + if (step.InteractionType != EInteractionType.EquipRecommended) + return null; + + return serviceProvider.GetRequiredService(); + } + } + + internal sealed unsafe class DoEquipRecommended(IClientState clientState) : ITask + { + private bool _equipped; + + public bool Start() + { + RecommendEquipModule.Instance()->SetupForClassJob((byte)clientState.LocalPlayer!.ClassJob.Id); + return true; + } + + public ETaskResult Update() + { + if (RecommendEquipModule.Instance()->IsUpdating) + return ETaskResult.StillRunning; + + if (!_equipped) + { + RecommendEquipModule.Instance()->EquipRecommendedGear(); + _equipped = true; + return ETaskResult.StillRunning; + } + + return ETaskResult.TaskComplete; + } + + public override string ToString() => "EquipRecommended"; + } +} diff --git a/Questionable/QuestionablePlugin.cs b/Questionable/QuestionablePlugin.cs index df2fb3575..2e88cb19c 100644 --- a/Questionable/QuestionablePlugin.cs +++ b/Questionable/QuestionablePlugin.cs @@ -151,6 +151,7 @@ public sealed class QuestionablePlugin : IDalamudPlugin .AddTaskWithFactory(); serviceCollection.AddTaskWithFactory(); + serviceCollection.AddTaskWithFactory(); serviceCollection.AddTaskWithFactory(); serviceCollection .AddTaskWithFactory