1
0
Fork 0
forked from aly/qstbak
qstbak/Questionable/Questionable.External/PandorasBoxIpc.cs
2026-08-17 20:29:32 +10:00

122 lines
4.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using Dalamud.Plugin;
using Dalamud.Plugin.Services;
using LLib.External;
using Microsoft.Extensions.Logging;
using Questionable.Controller;
using Questionable.Data;
namespace Questionable.External;
internal sealed class PandorasBoxIpc : IDisposable
{
internal static readonly ImmutableHashSet<string> ConflictingFeatures = new HashSet<string>
{
"Auto-Collect", "Auto-Cordial", "Auto-Meditation", "Auto-Motif (Out of Combat)", "Auto-Mount After Combat", "Auto-Mount after Gathering", "Auto-Mount on Zone Change", "Auto-Peleton", "Auto-Prospect/Triangulate", "Auto-Sprint in Sanctuaries",
"Auto-Summon Chocobo", "Auto-Summon Fairy/Carbuncle", "Auto-Tank Stance", "Action Combat Targeting", "Auto-interact with Gathering Nodes", "Auto-interact with Objects in Instances", "Automatically Open Chests", "FATE Targeting Mode", "Auto-Teleport to Map Coords", "Auto-select Turn-ins",
"Auto-Equip Recommended Gear", "Auto-Sync FATEs", "Pandora Quick Gather", "Switch Gatherers Automatically"
}.ToImmutableHashSet();
internal const string AutoActiveTimeManeuverFeature = "Auto Active Time Maneuver";
private readonly Configuration _configuration;
private readonly QuestController _questController;
private readonly FateController _fateController;
private readonly SeasonalDutyController _seasonalDutyController;
private readonly CustomDeliveryController _customDeliveryController;
private readonly TerritoryData _territoryData;
private readonly IClientState _clientState;
private readonly IFramework _framework;
private readonly PluginFeaturePauser _pauser;
private readonly ILogger<PandorasBoxIpc> _logger;
private bool _wasFateRunning;
public PandorasBoxIpc(Configuration configuration, IDalamudPluginInterface pluginInterface, QuestController questController, FateController fateController, SeasonalDutyController seasonalDutyController, CustomDeliveryController customDeliveryController, TerritoryData territoryData, IClientState clientState, IFramework framework, ILogger<PandorasBoxIpc> logger)
{
_configuration = configuration;
_questController = questController;
_fateController = fateController;
_seasonalDutyController = seasonalDutyController;
_customDeliveryController = customDeliveryController;
_territoryData = territoryData;
_clientState = clientState;
_framework = framework;
_logger = logger;
_pauser = new PluginFeaturePauser(pluginInterface, "PandorasBox.GetFeatureEnabled", "PandorasBox.SetFeatureEnabled", logger);
_questController.AutomationTypeChanged += OnAutomationTypeChanged;
_framework.Update += OnFrameworkUpdate;
}
private void OnAutomationTypeChanged(object sender, QuestController.EAutomationType automationType)
{
if (automationType != QuestController.EAutomationType.Manual && !_territoryData.IsDutyInstance(_clientState.TerritoryType))
{
InvokeGuarded(DisableConflictingFeatures);
}
else if (!_fateController.IsRunning && !_seasonalDutyController.IsRunning && !_customDeliveryController.IsRunning)
{
InvokeGuarded(delegate
{
_pauser.Restore();
});
}
}
private void OnFrameworkUpdate(IFramework framework)
{
bool flag = _fateController.IsRunning || _seasonalDutyController.IsRunning || _customDeliveryController.IsRunning;
if (flag == _wasFateRunning)
{
return;
}
_wasFateRunning = flag;
if (flag && !_territoryData.IsDutyInstance(_clientState.TerritoryType))
{
InvokeGuarded(DisableConflictingFeatures);
}
else if (_questController.AutomationType == QuestController.EAutomationType.Manual)
{
InvokeGuarded(delegate
{
_pauser.Restore();
});
}
}
private void InvokeGuarded(Action action)
{
try
{
action();
}
catch (Exception exception)
{
_logger.LogError(exception, "PandorasBox IPC call failed");
}
}
private void DisableConflictingFeatures()
{
ImmutableHashSet<string> immutableHashSet = (_configuration.General.AutoSolveQte ? ConflictingFeatures.Add("Auto Active Time Maneuver") : ConflictingFeatures);
_pauser.Disable(immutableHashSet.Except(_configuration.Advanced.PandoraFeatureExclusions));
}
public void Dispose()
{
_framework.Update -= OnFrameworkUpdate;
_questController.AutomationTypeChanged -= OnAutomationTypeChanged;
_pauser.Dispose();
}
}