Automatically equip recommended gear for duty/singleplayerduty/combat

This commit is contained in:
Liza 2024-08-14 09:28:41 +02:00
parent 82c8826e0f
commit 2dfc774da1
Signed by: liza
GPG Key ID: 7199F8D727D55F67
2 changed files with 50 additions and 3 deletions

View File

@ -1,5 +1,6 @@
using System;
using Dalamud.Plugin.Services;
using FFXIVClientStructs.FFXIV.Client.Game;
using FFXIVClientStructs.FFXIV.Client.UI.Misc;
using Microsoft.Extensions.DependencyInjection;
using Questionable.Model;
@ -20,7 +21,20 @@ internal static class EquipRecommended
}
}
internal sealed unsafe class DoEquipRecommended(IClientState clientState) : ITask
internal sealed class BeforeDutyOrInstance(IServiceProvider serviceProvider) : ITaskFactory
{
public ITask? CreateTask(Quest quest, QuestSequence sequence, QuestStep step)
{
if (step.InteractionType != EInteractionType.Duty &&
step.InteractionType != EInteractionType.SinglePlayerDuty &&
step.InteractionType != EInteractionType.Combat)
return null;
return serviceProvider.GetRequiredService<DoEquipRecommended>();
}
}
internal sealed unsafe class DoEquipRecommended(IClientState clientState, IChatGui chatGui) : ITask
{
private bool _equipped;
@ -32,12 +46,43 @@ internal static class EquipRecommended
public ETaskResult Update()
{
if (RecommendEquipModule.Instance()->IsUpdating)
var recommendedEquipModule = RecommendEquipModule.Instance();
if (recommendedEquipModule->IsUpdating)
return ETaskResult.StillRunning;
if (!_equipped)
{
RecommendEquipModule.Instance()->EquipRecommendedGear();
InventoryManager* inventoryManager = InventoryManager.Instance();
InventoryContainer* equippedItems =
inventoryManager->GetInventoryContainer(InventoryType.EquippedItems);
bool isAllEquipped = true;
foreach (var recommendedItemPtr in recommendedEquipModule->RecommendedItems)
{
var recommendedItem = recommendedItemPtr.Value;
if (recommendedItem == null || recommendedItem->ItemId == 0)
continue;
bool isEquipped = false;
for (int i = 0; i < equippedItems->Size; ++i)
{
var equippedItem = equippedItems->Items[i];
if (equippedItem.ItemId != 0 && equippedItem.ItemId == recommendedItem->ItemId)
{
isEquipped = true;
break;
}
}
if (!isEquipped)
isAllEquipped = false;
}
if (!isAllEquipped)
{
chatGui.Print("Equipping recommended gear.", "Questionable");
recommendedEquipModule->EquipRecommendedGear();
}
_equipped = true;
return ETaskResult.StillRunning;
}

View File

@ -11,6 +11,7 @@ using Microsoft.Extensions.Logging;
using Questionable.Controller;
using Questionable.Controller.CombatModules;
using Questionable.Controller.NavigationOverrides;
using Questionable.Controller.Steps;
using Questionable.Controller.Steps.Shared;
using Questionable.Controller.Steps.Common;
using Questionable.Controller.Steps.Gathering;
@ -128,6 +129,7 @@ public sealed class QuestionablePlugin : IDalamudPlugin
// task factories
serviceCollection.AddTaskWithFactory<StepDisabled.Factory, StepDisabled.Task>();
serviceCollection.AddSingleton<ITaskFactory, EquipRecommended.BeforeDutyOrInstance>();
serviceCollection.AddTaskWithFactory<GatheringRequiredItems.Factory, GatheringRequiredItems.StartGathering>();
serviceCollection.AddTaskWithFactory<AetheryteShortcut.Factory, AetheryteShortcut.UseAetheryteShortcut>();
serviceCollection.AddTaskWithFactory<SkipCondition.Factory, SkipCondition.CheckSkip>();