Check that you have the status 'OccupiedInQuestEvent' for at least a frame for interacting

This commit is contained in:
Liza 2024-08-09 23:58:19 +02:00
parent 04ac6ba9cf
commit 7dc78ed8cb
Signed by: liza
GPG Key ID: 7199F8D727D55F67
5 changed files with 75 additions and 18 deletions

View File

@ -81,6 +81,8 @@ internal sealed class QuestController : MiniTaskController<QuestController>
_configuration = configuration;
_yesAlreadyIpc = yesAlreadyIpc;
_taskFactories = taskFactories.ToList().AsReadOnly();
_condition.ConditionChange += OnConditionChange;
}
public (QuestProgress Progress, ECurrentQuestType Type)? CurrentQuestDetails
@ -730,6 +732,12 @@ internal sealed class QuestController : MiniTaskController<QuestController>
return IsRunning || DateTime.Now <= _lastTaskUpdate.Add(timeSpan);
}
private void OnConditionChange(ConditionFlag flag, bool value)
{
if (_currentTask is IConditionChangeAware conditionChangeAware)
conditionChangeAware.OnConditionChange(flag, value);
}
public sealed record StepProgress(
DateTime StartedAt,
int PointMenuCounter = 0);

View File

@ -0,0 +1,8 @@
using Dalamud.Game.ClientState.Conditions;
namespace Questionable.Controller.Steps;
public interface IConditionChangeAware
{
void OnConditionChange(ConditionFlag flag, bool value);
}

View File

@ -44,10 +44,10 @@ internal static class Interact
}
internal sealed class DoInteract(GameFunctions gameFunctions, ICondition condition, ILogger<DoInteract> logger)
: ITask
: ITask, IConditionChangeAware
{
private bool _needsUnmount;
private bool _interacted;
private EInteractionState _interactionState = EInteractionState.None;
private DateTime _continueAt = DateTime.MinValue;
private uint DataId { get; set; }
@ -84,9 +84,11 @@ internal static class Interact
return true;
}
if (IsTargetable(gameObject) && HasAnyMarker(gameObject))
if (gameObject.IsTargetable && HasAnyMarker(gameObject))
{
_interacted = gameFunctions.InteractWith(gameObject);
_interactionState = gameFunctions.InteractWith(gameObject)
? EInteractionState.InteractionTriggered
: EInteractionState.None;
_continueAt = DateTime.Now.AddSeconds(0.5);
return true;
}
@ -111,18 +113,18 @@ internal static class Interact
_needsUnmount = false;
}
if (!_interacted)
{
IGameObject? gameObject = gameFunctions.FindObjectByDataId(DataId);
if (gameObject == null || !IsTargetable(gameObject) || !HasAnyMarker(gameObject))
return ETaskResult.StillRunning;
if (_interactionState == EInteractionState.InteractionConfirmed)
return ETaskResult.TaskComplete;
_interacted = gameFunctions.InteractWith(gameObject);
_continueAt = DateTime.Now.AddSeconds(0.5);
IGameObject? gameObject = gameFunctions.FindObjectByDataId(DataId);
if (gameObject == null || !gameObject.IsTargetable || !HasAnyMarker(gameObject))
return ETaskResult.StillRunning;
}
return ETaskResult.TaskComplete;
_interactionState = gameFunctions.InteractWith(gameObject)
? EInteractionState.InteractionTriggered
: EInteractionState.None;
_continueAt = DateTime.Now.AddSeconds(0.5);
return ETaskResult.StillRunning;
}
private unsafe bool HasAnyMarker(IGameObject gameObject)
@ -134,11 +136,24 @@ internal static class Interact
return gameObjectStruct->NamePlateIconId != 0;
}
private static bool IsTargetable(IGameObject gameObject)
public override string ToString() => $"Interact({DataId})";
public void OnConditionChange(ConditionFlag flag, bool value)
{
return gameObject.IsTargetable;
logger.LogDebug("Condition change: {Flag} = {Value}", flag, value);
if (_interactionState == EInteractionState.InteractionTriggered &&
flag == ConditionFlag.OccupiedInQuestEvent && value)
{
logger.LogInformation("Interaction was most likely triggered");
_interactionState = EInteractionState.InteractionConfirmed;
}
}
public override string ToString() => $"Interact({DataId})";
private enum EInteractionState
{
None,
InteractionTriggered,
InteractionConfirmed,
}
}
}

View File

@ -1,7 +1,10 @@
using System;
using Dalamud.Game.Gui.Toast;
using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Interface.Windowing;
using Dalamud.Plugin;
using Dalamud.Plugin.Services;
using Microsoft.Extensions.Logging;
using Questionable.Controller;
using Questionable.Windows;
@ -17,6 +20,8 @@ internal sealed class DalamudInitializer : IDisposable
private readonly WindowSystem _windowSystem;
private readonly QuestWindow _questWindow;
private readonly ConfigWindow _configWindow;
private readonly IToastGui _toastGui;
private readonly ILogger<DalamudInitializer> _logger;
public DalamudInitializer(
IDalamudPluginInterface pluginInterface,
@ -31,7 +36,9 @@ internal sealed class DalamudInitializer : IDisposable
ConfigWindow configWindow,
QuestSelectionWindow questSelectionWindow,
QuestValidationWindow questValidationWindow,
JournalProgressWindow journalProgressWindow)
JournalProgressWindow journalProgressWindow,
IToastGui toastGui,
ILogger<DalamudInitializer> logger)
{
_pluginInterface = pluginInterface;
_framework = framework;
@ -41,6 +48,8 @@ internal sealed class DalamudInitializer : IDisposable
_windowSystem = windowSystem;
_questWindow = questWindow;
_configWindow = configWindow;
_toastGui = toastGui;
_logger = logger;
_windowSystem.AddWindow(questWindow);
_windowSystem.AddWindow(configWindow);
@ -54,6 +63,9 @@ internal sealed class DalamudInitializer : IDisposable
_pluginInterface.UiBuilder.OpenConfigUi += _configWindow.Toggle;
_framework.Update += FrameworkUpdate;
_framework.RunOnTick(gameUiController.HandleCurrentDialogueChoices, TimeSpan.FromMilliseconds(200));
_toastGui.Toast += OnToast;
_toastGui.ErrorToast += OnErrorToast;
_toastGui.QuestToast += OnQuestToast;
}
private void FrameworkUpdate(IFramework framework)
@ -71,8 +83,20 @@ internal sealed class DalamudInitializer : IDisposable
}
}
private void OnToast(ref SeString message, ref ToastOptions options, ref bool isHandled)
=> _logger.LogInformation("Normal Toast: {Message}", message);
private void OnErrorToast(ref SeString message, ref bool isHandled)
=> _logger.LogInformation("Error Toast: {Message}", message);
private void OnQuestToast(ref SeString message, ref QuestToastOptions options, ref bool isHandled)
=> _logger.LogInformation("Quest Toast: {Message}", message);
public void Dispose()
{
_toastGui.QuestToast -= OnQuestToast;
_toastGui.ErrorToast -= OnErrorToast;
_toastGui.Toast -= OnToast;
_framework.Update -= FrameworkUpdate;
_pluginInterface.UiBuilder.OpenConfigUi -= _configWindow.Toggle;
_pluginInterface.UiBuilder.OpenMainUi -= _questWindow.Toggle;

View File

@ -46,7 +46,8 @@ public sealed class QuestionablePlugin : IDalamudPlugin
ICommandManager commandManager,
IAddonLifecycle addonLifecycle,
IKeyState keyState,
IContextMenu contextMenu)
IContextMenu contextMenu,
IToastGui toastGui)
{
ArgumentNullException.ThrowIfNull(pluginInterface);
ArgumentNullException.ThrowIfNull(chatGui);
@ -72,6 +73,7 @@ public sealed class QuestionablePlugin : IDalamudPlugin
serviceCollection.AddSingleton(addonLifecycle);
serviceCollection.AddSingleton(keyState);
serviceCollection.AddSingleton(contextMenu);
serviceCollection.AddSingleton(toastGui);
serviceCollection.AddSingleton(new WindowSystem(nameof(Questionable)));
serviceCollection.AddSingleton((Configuration?)pluginInterface.GetPluginConfig() ?? new Configuration());