From 946dcc1fe61999a544b5b66b152a681f14300354 Mon Sep 17 00:00:00 2001 From: Liza Carvelli Date: Fri, 26 Jul 2024 10:41:35 +0200 Subject: [PATCH] Only use combat-starting items until in combat --- .../Controller/Steps/Interactions/Combat.cs | 2 +- .../Controller/Steps/Interactions/UseItem.cs | 27 ++++++++++++++----- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/Questionable/Controller/Steps/Interactions/Combat.cs b/Questionable/Controller/Steps/Interactions/Combat.cs index a26272486..1f3c90020 100644 --- a/Questionable/Controller/Steps/Interactions/Combat.cs +++ b/Questionable/Controller/Steps/Interactions/Combat.cs @@ -47,7 +47,7 @@ internal static class Combat ArgumentNullException.ThrowIfNull(step.ItemId); yield return serviceProvider.GetRequiredService() - .With(step.DataId.Value, step.ItemId.Value); + .With(step.DataId.Value, step.ItemId.Value, true); yield return CreateTask(quest, sequence, step); break; } diff --git a/Questionable/Controller/Steps/Interactions/UseItem.cs b/Questionable/Controller/Steps/Interactions/UseItem.cs index c0beee00e..f451c3555 100644 --- a/Questionable/Controller/Steps/Interactions/UseItem.cs +++ b/Questionable/Controller/Steps/Interactions/UseItem.cs @@ -2,6 +2,8 @@ using System.Collections.Generic; using System.Globalization; using System.Numerics; +using Dalamud.Game.ClientState.Conditions; +using Dalamud.Plugin.Services; using FFXIVClientStructs.FFXIV.Client.Game; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; @@ -88,13 +90,14 @@ internal static class UseItem } } - internal abstract class UseItemBase(ILogger logger) : ITask + internal abstract class UseItemBase(ICondition condition, ILogger logger) : ITask { private bool _usedItem; private DateTime _continueAt; private int _itemCount; public uint ItemId { get; set; } + public bool StartingCombat { get; set; } protected abstract bool UseItem(); @@ -118,6 +121,9 @@ internal static class UseItem if (DateTime.Now <= _continueAt) return ETaskResult.StillRunning; + if (StartingCombat && condition[ConditionFlag.InCombat]) + return ETaskResult.TaskComplete; + if (ItemId == VesperBayAetheryteTicket && _usedItem) { InventoryManager* inventoryManager = InventoryManager.Instance(); @@ -150,7 +156,8 @@ internal static class UseItem } - internal sealed class UseOnGround(GameFunctions gameFunctions, ILogger logger) : UseItemBase(logger) + internal sealed class UseOnGround(GameFunctions gameFunctions, ICondition condition, ILogger logger) + : UseItemBase(condition, logger) { public uint DataId { get; set; } @@ -166,8 +173,11 @@ internal static class UseItem public override string ToString() => $"UseItem({ItemId} on ground at {DataId})"; } - internal sealed class UseOnPosition(GameFunctions gameFunctions, ILogger logger) - : UseItemBase(logger) + internal sealed class UseOnPosition( + GameFunctions gameFunctions, + ICondition condition, + ILogger logger) + : UseItemBase(condition, logger) { public Vector3 Position { get; set; } @@ -184,14 +194,16 @@ internal static class UseItem $"UseItem({ItemId} on ground at {Position.ToString("G", CultureInfo.InvariantCulture)})"; } - internal sealed class UseOnObject(GameFunctions gameFunctions, ILogger logger) : UseItemBase(logger) + internal sealed class UseOnObject(GameFunctions gameFunctions, ICondition condition, ILogger logger) + : UseItemBase(condition, logger) { public uint DataId { get; set; } - public ITask With(uint dataId, uint itemId) + public ITask With(uint dataId, uint itemId, bool startingCombat = false) { DataId = dataId; ItemId = itemId; + StartingCombat = startingCombat; return this; } @@ -200,7 +212,8 @@ internal static class UseItem public override string ToString() => $"UseItem({ItemId} on {DataId})"; } - internal sealed class Use(GameFunctions gameFunctions, ILogger logger) : UseItemBase(logger) + internal sealed class Use(GameFunctions gameFunctions, ICondition condition, ILogger logger) + : UseItemBase(condition, logger) { public ITask With(uint itemId) {