forked from liza/Questionable
Check that you have the status 'OccupiedInQuestEvent' for at least a frame for interacting
This commit is contained in:
parent
04ac6ba9cf
commit
7dc78ed8cb
@ -81,6 +81,8 @@ internal sealed class QuestController : MiniTaskController<QuestController>
|
|||||||
_configuration = configuration;
|
_configuration = configuration;
|
||||||
_yesAlreadyIpc = yesAlreadyIpc;
|
_yesAlreadyIpc = yesAlreadyIpc;
|
||||||
_taskFactories = taskFactories.ToList().AsReadOnly();
|
_taskFactories = taskFactories.ToList().AsReadOnly();
|
||||||
|
|
||||||
|
_condition.ConditionChange += OnConditionChange;
|
||||||
}
|
}
|
||||||
|
|
||||||
public (QuestProgress Progress, ECurrentQuestType Type)? CurrentQuestDetails
|
public (QuestProgress Progress, ECurrentQuestType Type)? CurrentQuestDetails
|
||||||
@ -730,6 +732,12 @@ internal sealed class QuestController : MiniTaskController<QuestController>
|
|||||||
return IsRunning || DateTime.Now <= _lastTaskUpdate.Add(timeSpan);
|
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(
|
public sealed record StepProgress(
|
||||||
DateTime StartedAt,
|
DateTime StartedAt,
|
||||||
int PointMenuCounter = 0);
|
int PointMenuCounter = 0);
|
||||||
|
8
Questionable/Controller/Steps/IConditionChangeAware.cs
Normal file
8
Questionable/Controller/Steps/IConditionChangeAware.cs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
using Dalamud.Game.ClientState.Conditions;
|
||||||
|
|
||||||
|
namespace Questionable.Controller.Steps;
|
||||||
|
|
||||||
|
public interface IConditionChangeAware
|
||||||
|
{
|
||||||
|
void OnConditionChange(ConditionFlag flag, bool value);
|
||||||
|
}
|
@ -44,10 +44,10 @@ internal static class Interact
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal sealed class DoInteract(GameFunctions gameFunctions, ICondition condition, ILogger<DoInteract> logger)
|
internal sealed class DoInteract(GameFunctions gameFunctions, ICondition condition, ILogger<DoInteract> logger)
|
||||||
: ITask
|
: ITask, IConditionChangeAware
|
||||||
{
|
{
|
||||||
private bool _needsUnmount;
|
private bool _needsUnmount;
|
||||||
private bool _interacted;
|
private EInteractionState _interactionState = EInteractionState.None;
|
||||||
private DateTime _continueAt = DateTime.MinValue;
|
private DateTime _continueAt = DateTime.MinValue;
|
||||||
|
|
||||||
private uint DataId { get; set; }
|
private uint DataId { get; set; }
|
||||||
@ -84,9 +84,11 @@ internal static class Interact
|
|||||||
return true;
|
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);
|
_continueAt = DateTime.Now.AddSeconds(0.5);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -111,18 +113,18 @@ internal static class Interact
|
|||||||
_needsUnmount = false;
|
_needsUnmount = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_interacted)
|
if (_interactionState == EInteractionState.InteractionConfirmed)
|
||||||
{
|
return ETaskResult.TaskComplete;
|
||||||
IGameObject? gameObject = gameFunctions.FindObjectByDataId(DataId);
|
|
||||||
if (gameObject == null || !IsTargetable(gameObject) || !HasAnyMarker(gameObject))
|
|
||||||
return ETaskResult.StillRunning;
|
|
||||||
|
|
||||||
_interacted = gameFunctions.InteractWith(gameObject);
|
IGameObject? gameObject = gameFunctions.FindObjectByDataId(DataId);
|
||||||
_continueAt = DateTime.Now.AddSeconds(0.5);
|
if (gameObject == null || !gameObject.IsTargetable || !HasAnyMarker(gameObject))
|
||||||
return ETaskResult.StillRunning;
|
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)
|
private unsafe bool HasAnyMarker(IGameObject gameObject)
|
||||||
@ -134,11 +136,24 @@ internal static class Interact
|
|||||||
return gameObjectStruct->NamePlateIconId != 0;
|
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,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using Dalamud.Game.Gui.Toast;
|
||||||
|
using Dalamud.Game.Text.SeStringHandling;
|
||||||
using Dalamud.Interface.Windowing;
|
using Dalamud.Interface.Windowing;
|
||||||
using Dalamud.Plugin;
|
using Dalamud.Plugin;
|
||||||
using Dalamud.Plugin.Services;
|
using Dalamud.Plugin.Services;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Questionable.Controller;
|
using Questionable.Controller;
|
||||||
using Questionable.Windows;
|
using Questionable.Windows;
|
||||||
|
|
||||||
@ -17,6 +20,8 @@ internal sealed class DalamudInitializer : IDisposable
|
|||||||
private readonly WindowSystem _windowSystem;
|
private readonly WindowSystem _windowSystem;
|
||||||
private readonly QuestWindow _questWindow;
|
private readonly QuestWindow _questWindow;
|
||||||
private readonly ConfigWindow _configWindow;
|
private readonly ConfigWindow _configWindow;
|
||||||
|
private readonly IToastGui _toastGui;
|
||||||
|
private readonly ILogger<DalamudInitializer> _logger;
|
||||||
|
|
||||||
public DalamudInitializer(
|
public DalamudInitializer(
|
||||||
IDalamudPluginInterface pluginInterface,
|
IDalamudPluginInterface pluginInterface,
|
||||||
@ -31,7 +36,9 @@ internal sealed class DalamudInitializer : IDisposable
|
|||||||
ConfigWindow configWindow,
|
ConfigWindow configWindow,
|
||||||
QuestSelectionWindow questSelectionWindow,
|
QuestSelectionWindow questSelectionWindow,
|
||||||
QuestValidationWindow questValidationWindow,
|
QuestValidationWindow questValidationWindow,
|
||||||
JournalProgressWindow journalProgressWindow)
|
JournalProgressWindow journalProgressWindow,
|
||||||
|
IToastGui toastGui,
|
||||||
|
ILogger<DalamudInitializer> logger)
|
||||||
{
|
{
|
||||||
_pluginInterface = pluginInterface;
|
_pluginInterface = pluginInterface;
|
||||||
_framework = framework;
|
_framework = framework;
|
||||||
@ -41,6 +48,8 @@ internal sealed class DalamudInitializer : IDisposable
|
|||||||
_windowSystem = windowSystem;
|
_windowSystem = windowSystem;
|
||||||
_questWindow = questWindow;
|
_questWindow = questWindow;
|
||||||
_configWindow = configWindow;
|
_configWindow = configWindow;
|
||||||
|
_toastGui = toastGui;
|
||||||
|
_logger = logger;
|
||||||
|
|
||||||
_windowSystem.AddWindow(questWindow);
|
_windowSystem.AddWindow(questWindow);
|
||||||
_windowSystem.AddWindow(configWindow);
|
_windowSystem.AddWindow(configWindow);
|
||||||
@ -54,6 +63,9 @@ internal sealed class DalamudInitializer : IDisposable
|
|||||||
_pluginInterface.UiBuilder.OpenConfigUi += _configWindow.Toggle;
|
_pluginInterface.UiBuilder.OpenConfigUi += _configWindow.Toggle;
|
||||||
_framework.Update += FrameworkUpdate;
|
_framework.Update += FrameworkUpdate;
|
||||||
_framework.RunOnTick(gameUiController.HandleCurrentDialogueChoices, TimeSpan.FromMilliseconds(200));
|
_framework.RunOnTick(gameUiController.HandleCurrentDialogueChoices, TimeSpan.FromMilliseconds(200));
|
||||||
|
_toastGui.Toast += OnToast;
|
||||||
|
_toastGui.ErrorToast += OnErrorToast;
|
||||||
|
_toastGui.QuestToast += OnQuestToast;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FrameworkUpdate(IFramework framework)
|
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()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
_toastGui.QuestToast -= OnQuestToast;
|
||||||
|
_toastGui.ErrorToast -= OnErrorToast;
|
||||||
|
_toastGui.Toast -= OnToast;
|
||||||
_framework.Update -= FrameworkUpdate;
|
_framework.Update -= FrameworkUpdate;
|
||||||
_pluginInterface.UiBuilder.OpenConfigUi -= _configWindow.Toggle;
|
_pluginInterface.UiBuilder.OpenConfigUi -= _configWindow.Toggle;
|
||||||
_pluginInterface.UiBuilder.OpenMainUi -= _questWindow.Toggle;
|
_pluginInterface.UiBuilder.OpenMainUi -= _questWindow.Toggle;
|
||||||
|
@ -46,7 +46,8 @@ public sealed class QuestionablePlugin : IDalamudPlugin
|
|||||||
ICommandManager commandManager,
|
ICommandManager commandManager,
|
||||||
IAddonLifecycle addonLifecycle,
|
IAddonLifecycle addonLifecycle,
|
||||||
IKeyState keyState,
|
IKeyState keyState,
|
||||||
IContextMenu contextMenu)
|
IContextMenu contextMenu,
|
||||||
|
IToastGui toastGui)
|
||||||
{
|
{
|
||||||
ArgumentNullException.ThrowIfNull(pluginInterface);
|
ArgumentNullException.ThrowIfNull(pluginInterface);
|
||||||
ArgumentNullException.ThrowIfNull(chatGui);
|
ArgumentNullException.ThrowIfNull(chatGui);
|
||||||
@ -72,6 +73,7 @@ public sealed class QuestionablePlugin : IDalamudPlugin
|
|||||||
serviceCollection.AddSingleton(addonLifecycle);
|
serviceCollection.AddSingleton(addonLifecycle);
|
||||||
serviceCollection.AddSingleton(keyState);
|
serviceCollection.AddSingleton(keyState);
|
||||||
serviceCollection.AddSingleton(contextMenu);
|
serviceCollection.AddSingleton(contextMenu);
|
||||||
|
serviceCollection.AddSingleton(toastGui);
|
||||||
serviceCollection.AddSingleton(new WindowSystem(nameof(Questionable)));
|
serviceCollection.AddSingleton(new WindowSystem(nameof(Questionable)));
|
||||||
serviceCollection.AddSingleton((Configuration?)pluginInterface.GetPluginConfig() ?? new Configuration());
|
serviceCollection.AddSingleton((Configuration?)pluginInterface.GetPluginConfig() ?? new Configuration());
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user