forked from aly/qstbak
121 lines
3.7 KiB
C#
121 lines
3.7 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 AutomatonIpc : IDisposable
|
|
{
|
|
internal static readonly ImmutableHashSet<string> ConflictingTweaks = new HashSet<string>
|
|
{
|
|
"DateWithDestiny", "AutoFollow", "ClickToMove", "AutoPillion", "AutoInvite", "AutoBusy", "FateToolKit", "AutoQueue", "EnhancedDutyStartEnd", "EnhancedLoginLogout",
|
|
"GettingTooAttached", "RetrieveMateria"
|
|
}.ToImmutableHashSet();
|
|
|
|
internal const string AutoSnipeTweak = "AutoSnipeQuests";
|
|
|
|
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<AutomatonIpc> _logger;
|
|
|
|
private bool _wasFateRunning;
|
|
|
|
public AutomatonIpc(Configuration configuration, IDalamudPluginInterface pluginInterface, QuestController questController, FateController fateController, SeasonalDutyController seasonalDutyController, CustomDeliveryController customDeliveryController, TerritoryData territoryData, IClientState clientState, IFramework framework, ILogger<AutomatonIpc> logger)
|
|
{
|
|
_configuration = configuration;
|
|
_questController = questController;
|
|
_fateController = fateController;
|
|
_seasonalDutyController = seasonalDutyController;
|
|
_customDeliveryController = customDeliveryController;
|
|
_territoryData = territoryData;
|
|
_clientState = clientState;
|
|
_framework = framework;
|
|
_logger = logger;
|
|
_pauser = new PluginFeaturePauser(pluginInterface, "Automaton.IsTweakEnabled", "Automaton.SetTweakState", 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(DisableConflictingTweaks);
|
|
}
|
|
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(DisableConflictingTweaks);
|
|
}
|
|
else if (_questController.AutomationType == QuestController.EAutomationType.Manual)
|
|
{
|
|
InvokeGuarded(delegate
|
|
{
|
|
_pauser.Restore();
|
|
});
|
|
}
|
|
}
|
|
|
|
private void InvokeGuarded(Action action)
|
|
{
|
|
try
|
|
{
|
|
action();
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
_logger.LogError(exception, "Automaton IPC call failed");
|
|
}
|
|
}
|
|
|
|
private void DisableConflictingTweaks()
|
|
{
|
|
ImmutableHashSet<string> immutableHashSet = (_configuration.General.AutoSnipe ? ConflictingTweaks.Add("AutoSnipeQuests") : ConflictingTweaks);
|
|
_pauser.Disable(immutableHashSet.Except(_configuration.Advanced.AutomatonTweakExclusions));
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_framework.Update -= OnFrameworkUpdate;
|
|
_questController.AutomationTypeChanged -= OnAutomationTypeChanged;
|
|
_pauser.Dispose();
|
|
}
|
|
}
|