qstbak/Questionable/Questionable.Controller/CommandHandler.cs
2026-08-17 20:29:32 +10:00

220 lines
8.5 KiB
C#

using System;
using System.Runtime.CompilerServices;
using Dalamud.Game.Command;
using Dalamud.Plugin.Services;
using Questionable.Functions;
using Questionable.Windows;
namespace Questionable.Controller;
internal sealed class CommandHandler : IDisposable
{
public const string MessageTag = "Questionable";
public const ushort TagColor = 576;
private readonly ICommandManager _commandManager;
private readonly IChatGui _chatGui;
private readonly QuestController _questController;
private readonly MovementController _movementController;
private readonly ConfigWindow _configWindow;
private readonly OneTimeSetupWindow _oneTimeSetupWindow;
private readonly QuestWindow _questWindow;
private readonly QuestSelectionWindow _questSelectionWindow;
private readonly JournalProgressWindow _journalProgressWindow;
private readonly FateController _fateController;
private readonly SeasonalDutyController _seasonalDutyController;
private readonly AttunementController _attunementController;
private readonly CustomDeliveryController _customDeliveryController;
private readonly FishingController _fishingController;
private readonly FateSelectionWindow _fateSelectionWindow;
private readonly SeasonalDutySelectionWindow _seasonalDutySelectionWindow;
private readonly ITargetManager _targetManager;
private readonly IClientState _clientState;
private readonly Configuration _configuration;
private readonly ChangelogWindow _changelogWindow;
public CommandHandler(ICommandManager commandManager, IChatGui chatGui, QuestController questController, MovementController movementController, FateController fateController, SeasonalDutyController seasonalDutyController, AttunementController attunementController, CustomDeliveryController customDeliveryController, FishingController fishingController, QuestRegistry questRegistry, ConfigWindow configWindow, OneTimeSetupWindow oneTimeSetupWindow, QuestWindow questWindow, QuestSelectionWindow questSelectionWindow, QuestSequenceWindow questSequenceWindow, JournalProgressWindow journalProgressWindow, FateSelectionWindow fateSelectionWindow, SeasonalDutySelectionWindow seasonalDutySelectionWindow, ITargetManager targetManager, QuestFunctions questFunctions, GameFunctions gameFunctions, AetheryteFunctions aetheryteFunctions, IDataManager dataManager, IClientState clientState, IObjectTable objectTable, Configuration configuration, ChangelogWindow changelogWindow)
{
_commandManager = commandManager;
_chatGui = chatGui;
_questController = questController;
_movementController = movementController;
_fateController = fateController;
_seasonalDutyController = seasonalDutyController;
_attunementController = attunementController;
_customDeliveryController = customDeliveryController;
_fishingController = fishingController;
_configWindow = configWindow;
_oneTimeSetupWindow = oneTimeSetupWindow;
_questWindow = questWindow;
_questSelectionWindow = questSelectionWindow;
_journalProgressWindow = journalProgressWindow;
_fateSelectionWindow = fateSelectionWindow;
_seasonalDutySelectionWindow = seasonalDutySelectionWindow;
_targetManager = targetManager;
_clientState = clientState;
_configuration = configuration;
_changelogWindow = changelogWindow;
_clientState.Logout += OnLogout;
ICommandManager commandManager2 = _commandManager;
CommandInfo commandInfo = new CommandInfo(ProcessCommand);
string separator = Environment.NewLine + "\t";
InlineArray7<string> buffer = default(InlineArray7<string>);
global::_003CPrivateImplementationDetails_003E.InlineArrayElementRef<InlineArray7<string>, string>(ref buffer, 0) = "Opens the Questing window";
global::_003CPrivateImplementationDetails_003E.InlineArrayElementRef<InlineArray7<string>, string>(ref buffer, 1) = "/qst help - displays simplified commands";
global::_003CPrivateImplementationDetails_003E.InlineArrayElementRef<InlineArray7<string>, string>(ref buffer, 2) = "/qst help-all - displays all available commands";
global::_003CPrivateImplementationDetails_003E.InlineArrayElementRef<InlineArray7<string>, string>(ref buffer, 3) = "/qst config - opens the configuration window";
global::_003CPrivateImplementationDetails_003E.InlineArrayElementRef<InlineArray7<string>, string>(ref buffer, 4) = "/qst changelog - opens the changelog window";
global::_003CPrivateImplementationDetails_003E.InlineArrayElementRef<InlineArray7<string>, string>(ref buffer, 5) = "/qst start - starts doing quests";
global::_003CPrivateImplementationDetails_003E.InlineArrayElementRef<InlineArray7<string>, string>(ref buffer, 6) = "/qst stop - stops doing quests";
commandInfo.HelpMessage = string.Join(separator, global::_003CPrivateImplementationDetails_003E.InlineArrayAsReadOnlySpan<InlineArray7<string>, string>(in buffer, 7));
commandManager2.AddHandler("/qst", commandInfo);
}
private void ProcessCommand(string command, string arguments)
{
if (arguments.Trim() == "setup")
{
_oneTimeSetupWindow.IsOpenAndUncollapsed = true;
}
else if (!OpenSetupIfNeeded(arguments))
{
string[] array = arguments.Split(' ');
switch (array[0])
{
case "h":
case "help":
PrintHelp(showAll: false);
break;
case "ha":
case "help-all":
PrintHelp(showAll: true);
break;
case "c":
case "config":
_configWindow.ToggleOrUncollapse();
break;
case "cl":
case "changelog":
_changelogWindow.ToggleOrUncollapse();
break;
case "start":
_questWindow.IsOpenAndUncollapsed = true;
_questController.Start("Start command");
break;
case "stop":
_movementController.Stop();
_questController.Stop("Stop command");
_fateController.Stop("Stop command");
_seasonalDutyController.Stop("Stop command");
_attunementController.Stop("Stop command");
_customDeliveryController.Stop("Stop command");
_fishingController.Stop("Stop command");
break;
case "reload":
_questWindow.Reload();
break;
case "which":
_questSelectionWindow.OpenForTarget(_targetManager.Target);
break;
case "z":
case "zone":
_questSelectionWindow.OpenForCurrentZone();
break;
case "j":
case "journal":
_journalProgressWindow.ToggleOrUncollapse();
break;
case "f":
case "fate":
_fateSelectionWindow.ToggleOrUncollapse();
break;
case "d":
case "duty":
_seasonalDutySelectionWindow.ToggleOrUncollapse();
break;
case "handle-interrupt":
_questController.InterruptQueueWithCombat();
break;
case "":
_questWindow.ToggleOrUncollapse();
break;
default:
_chatGui.PrintError("Unknown subcommand " + array[0], "Questionable", 576);
break;
}
}
}
private void PrintHelp(bool showAll)
{
_chatGui.Print("Available commands:", "Questionable", 576);
_chatGui.Print("/qst - toggles the Questing window", "Questionable", 576);
_chatGui.Print("/qst help - displays simplified commands", "Questionable", 576);
_chatGui.Print("/qst help-all - displays all available commands", "Questionable", 576);
_chatGui.Print("/qst config - opens the configuration window", "Questionable", 576);
_chatGui.Print("/qst setup - re-opens the first-time setup wizard", "Questionable", 576);
_chatGui.Print("/qst changelog - opens the changelog window", "Questionable", 576);
_chatGui.Print("/qst start - starts doing quests", "Questionable", 576);
_chatGui.Print("/qst stop - stops doing quests", "Questionable", 576);
_chatGui.Print("/qst reload - reload all quest data", "Questionable", 576);
if (showAll)
{
_chatGui.Print("/qst which - shows all quests starting with your selected target", "Questionable", 576);
_chatGui.Print("/qst zone - shows all quests starting in the current zone (only includes quests with a known quest path, and currently visible unaccepted quests)", "Questionable", 576);
_chatGui.Print("/qst journal - toggles the Journal Progress window", "Questionable", 576);
}
_chatGui.Print("/qst fate / duty - toggles the farming window", "Questionable", 576);
if (showAll)
{
_chatGui.Print("/qst handle-interrupt - makes Questionable handle queued interrupts immediately (useful if you manually start combat)", "Questionable", 576);
}
}
private bool OpenSetupIfNeeded(string arguments)
{
if (!_configuration.IsPluginSetupComplete())
{
if (string.IsNullOrEmpty(arguments))
{
_oneTimeSetupWindow.IsOpenAndUncollapsed = true;
}
else
{
_chatGui.PrintError("Please complete the one-time setup first.", "Questionable", 576);
}
return true;
}
return false;
}
private void OnLogout(int type, int code)
{
}
public void Dispose()
{
_commandManager.RemoveHandler("/qst");
_clientState.Logout -= OnLogout;
}
}