Only use combat-starting items until in combat

This commit is contained in:
Liza 2024-07-26 10:41:35 +02:00
parent 09be2a3604
commit 946dcc1fe6
Signed by: liza
GPG Key ID: 7199F8D727D55F67
2 changed files with 21 additions and 8 deletions

View File

@ -47,7 +47,7 @@ internal static class Combat
ArgumentNullException.ThrowIfNull(step.ItemId); ArgumentNullException.ThrowIfNull(step.ItemId);
yield return serviceProvider.GetRequiredService<UseItem.UseOnObject>() yield return serviceProvider.GetRequiredService<UseItem.UseOnObject>()
.With(step.DataId.Value, step.ItemId.Value); .With(step.DataId.Value, step.ItemId.Value, true);
yield return CreateTask(quest, sequence, step); yield return CreateTask(quest, sequence, step);
break; break;
} }

View File

@ -2,6 +2,8 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Numerics; using System.Numerics;
using Dalamud.Game.ClientState.Conditions;
using Dalamud.Plugin.Services;
using FFXIVClientStructs.FFXIV.Client.Game; using FFXIVClientStructs.FFXIV.Client.Game;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; 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 bool _usedItem;
private DateTime _continueAt; private DateTime _continueAt;
private int _itemCount; private int _itemCount;
public uint ItemId { get; set; } public uint ItemId { get; set; }
public bool StartingCombat { get; set; }
protected abstract bool UseItem(); protected abstract bool UseItem();
@ -118,6 +121,9 @@ internal static class UseItem
if (DateTime.Now <= _continueAt) if (DateTime.Now <= _continueAt)
return ETaskResult.StillRunning; return ETaskResult.StillRunning;
if (StartingCombat && condition[ConditionFlag.InCombat])
return ETaskResult.TaskComplete;
if (ItemId == VesperBayAetheryteTicket && _usedItem) if (ItemId == VesperBayAetheryteTicket && _usedItem)
{ {
InventoryManager* inventoryManager = InventoryManager.Instance(); InventoryManager* inventoryManager = InventoryManager.Instance();
@ -150,7 +156,8 @@ internal static class UseItem
} }
internal sealed class UseOnGround(GameFunctions gameFunctions, ILogger<UseOnGround> logger) : UseItemBase(logger) internal sealed class UseOnGround(GameFunctions gameFunctions, ICondition condition, ILogger<UseOnGround> logger)
: UseItemBase(condition, logger)
{ {
public uint DataId { get; set; } public uint DataId { get; set; }
@ -166,8 +173,11 @@ internal static class UseItem
public override string ToString() => $"UseItem({ItemId} on ground at {DataId})"; public override string ToString() => $"UseItem({ItemId} on ground at {DataId})";
} }
internal sealed class UseOnPosition(GameFunctions gameFunctions, ILogger<UseOnPosition> logger) internal sealed class UseOnPosition(
: UseItemBase(logger) GameFunctions gameFunctions,
ICondition condition,
ILogger<UseOnPosition> logger)
: UseItemBase(condition, logger)
{ {
public Vector3 Position { get; set; } public Vector3 Position { get; set; }
@ -184,14 +194,16 @@ internal static class UseItem
$"UseItem({ItemId} on ground at {Position.ToString("G", CultureInfo.InvariantCulture)})"; $"UseItem({ItemId} on ground at {Position.ToString("G", CultureInfo.InvariantCulture)})";
} }
internal sealed class UseOnObject(GameFunctions gameFunctions, ILogger<UseOnObject> logger) : UseItemBase(logger) internal sealed class UseOnObject(GameFunctions gameFunctions, ICondition condition, ILogger<UseOnObject> logger)
: UseItemBase(condition, logger)
{ {
public uint DataId { get; set; } public uint DataId { get; set; }
public ITask With(uint dataId, uint itemId) public ITask With(uint dataId, uint itemId, bool startingCombat = false)
{ {
DataId = dataId; DataId = dataId;
ItemId = itemId; ItemId = itemId;
StartingCombat = startingCombat;
return this; return this;
} }
@ -200,7 +212,8 @@ internal static class UseItem
public override string ToString() => $"UseItem({ItemId} on {DataId})"; public override string ToString() => $"UseItem({ItemId} on {DataId})";
} }
internal sealed class Use(GameFunctions gameFunctions, ILogger<Use> logger) : UseItemBase(logger) internal sealed class Use(GameFunctions gameFunctions, ICondition condition, ILogger<Use> logger)
: UseItemBase(condition, logger)
{ {
public ITask With(uint itemId) public ITask With(uint itemId)
{ {