129 lines
3.9 KiB
C#
129 lines
3.9 KiB
C#
using System;
|
|
using Dalamud.Game.ClientState.Conditions;
|
|
using Dalamud.Plugin;
|
|
using Dalamud.Plugin.Ipc;
|
|
using Dalamud.Plugin.Services;
|
|
using Questionable.Controller;
|
|
|
|
namespace Questionable.External;
|
|
|
|
internal sealed class TextAdvanceIpc : IDisposable
|
|
{
|
|
public sealed class ExternalTerritoryConfig
|
|
{
|
|
public bool? EnableQuestAccept;
|
|
|
|
public bool? EnableQuestComplete;
|
|
|
|
public bool? EnableRewardPick;
|
|
|
|
public bool? EnableRequestHandin;
|
|
|
|
public bool? EnableCutsceneEsc;
|
|
|
|
public bool? EnableCutsceneSkipConfirm;
|
|
|
|
public bool? EnableTalkSkip;
|
|
|
|
public bool? EnableRequestFill;
|
|
|
|
public bool? EnableAutoInteract;
|
|
}
|
|
|
|
private bool _isExternalControlActivated;
|
|
|
|
private bool _lastCinemaModeState;
|
|
|
|
private bool _lastInCutsceneState;
|
|
|
|
private readonly QuestController _questController;
|
|
|
|
private readonly Configuration _configuration;
|
|
|
|
private readonly ICondition _condition;
|
|
|
|
private readonly IFramework _framework;
|
|
|
|
private readonly ICallGateSubscriber<bool> _isInExternalControl;
|
|
|
|
private readonly ICallGateSubscriber<string, ExternalTerritoryConfig, bool> _enableExternalControl;
|
|
|
|
private readonly ICallGateSubscriber<string, bool> _disableExternalControl;
|
|
|
|
private readonly string _pluginName;
|
|
|
|
public TextAdvanceIpc(IDalamudPluginInterface pluginInterface, IFramework framework, QuestController questController, Configuration configuration, ICondition condition)
|
|
{
|
|
_framework = framework;
|
|
_questController = questController;
|
|
_configuration = configuration;
|
|
_condition = condition;
|
|
_isInExternalControl = pluginInterface.GetIpcSubscriber<bool>("TextAdvance.IsInExternalControl");
|
|
_enableExternalControl = pluginInterface.GetIpcSubscriber<string, ExternalTerritoryConfig, bool>("TextAdvance.EnableExternalControl");
|
|
_disableExternalControl = pluginInterface.GetIpcSubscriber<string, bool>("TextAdvance.DisableExternalControl");
|
|
_pluginName = pluginInterface.InternalName;
|
|
_framework.Update += OnUpdate;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_framework.Update -= OnUpdate;
|
|
if (_isExternalControlActivated)
|
|
{
|
|
_disableExternalControl.InvokeFunc(_pluginName);
|
|
}
|
|
}
|
|
|
|
private void OnUpdate(IFramework framework)
|
|
{
|
|
bool flag = _questController.IsRunning || _questController.AutomationType != QuestController.EAutomationType.Manual;
|
|
if (!_configuration.General.ConfigureTextAdvance || !flag)
|
|
{
|
|
if (_isExternalControlActivated && (_disableExternalControl.InvokeFunc(_pluginName) || !_isInExternalControl.InvokeFunc()))
|
|
{
|
|
_isExternalControlActivated = false;
|
|
}
|
|
return;
|
|
}
|
|
bool cinemaMode = _configuration.General.CinemaMode;
|
|
bool flag2 = _condition[ConditionFlag.OccupiedInCutSceneEvent] || _condition[ConditionFlag.WatchingCutscene] || _condition[ConditionFlag.WatchingCutscene78];
|
|
bool flag3 = cinemaMode != _lastCinemaModeState || (cinemaMode && flag2 != _lastInCutsceneState);
|
|
if (!_isExternalControlActivated)
|
|
{
|
|
if (!_isInExternalControl.InvokeFunc())
|
|
{
|
|
ExternalTerritoryConfig arg = CreateExternalTerritoryConfig(cinemaMode, flag2);
|
|
if (_enableExternalControl.InvokeFunc(_pluginName, arg))
|
|
{
|
|
_isExternalControlActivated = true;
|
|
_lastCinemaModeState = cinemaMode;
|
|
_lastInCutsceneState = flag2;
|
|
}
|
|
}
|
|
}
|
|
else if (flag3)
|
|
{
|
|
ExternalTerritoryConfig arg2 = CreateExternalTerritoryConfig(cinemaMode, flag2);
|
|
_enableExternalControl.InvokeFunc(_pluginName, arg2);
|
|
_lastCinemaModeState = cinemaMode;
|
|
_lastInCutsceneState = flag2;
|
|
}
|
|
}
|
|
|
|
private static ExternalTerritoryConfig CreateExternalTerritoryConfig(bool cinemaMode, bool inCutscene)
|
|
{
|
|
bool flag = cinemaMode && inCutscene;
|
|
return new ExternalTerritoryConfig
|
|
{
|
|
EnableQuestAccept = true,
|
|
EnableQuestComplete = true,
|
|
EnableRewardPick = true,
|
|
EnableRequestHandin = true,
|
|
EnableCutsceneEsc = !cinemaMode,
|
|
EnableCutsceneSkipConfirm = !cinemaMode,
|
|
EnableTalkSkip = !flag,
|
|
EnableRequestFill = true,
|
|
EnableAutoInteract = false
|
|
};
|
|
}
|
|
}
|