2024-07-11 00:56:42 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Dalamud.Game.ClientState.Objects;
|
|
|
|
|
using Dalamud.Game.Command;
|
|
|
|
|
using Dalamud.Plugin.Services;
|
2024-09-01 13:14:28 +00:00
|
|
|
|
using Lumina.Excel.GeneratedSheets;
|
2024-08-05 15:09:49 +00:00
|
|
|
|
using Questionable.Functions;
|
2024-08-03 18:30:18 +00:00
|
|
|
|
using Questionable.Model.Questing;
|
2024-07-11 00:56:42 +00:00
|
|
|
|
using Questionable.Windows;
|
2024-07-22 08:09:23 +00:00
|
|
|
|
using Questionable.Windows.QuestComponents;
|
2024-09-01 13:14:28 +00:00
|
|
|
|
using Quest = Questionable.Model.Quest;
|
2024-07-11 00:56:42 +00:00
|
|
|
|
|
|
|
|
|
namespace Questionable.Controller;
|
|
|
|
|
|
|
|
|
|
internal sealed class CommandHandler : IDisposable
|
|
|
|
|
{
|
2024-09-19 22:35:33 +00:00
|
|
|
|
public const string MessageTag = "Questionable";
|
|
|
|
|
public const ushort TagColor = 576;
|
2024-09-01 13:14:28 +00:00
|
|
|
|
|
2024-07-11 00:56:42 +00:00
|
|
|
|
private readonly ICommandManager _commandManager;
|
|
|
|
|
private readonly IChatGui _chatGui;
|
|
|
|
|
private readonly QuestController _questController;
|
|
|
|
|
private readonly MovementController _movementController;
|
|
|
|
|
private readonly QuestRegistry _questRegistry;
|
|
|
|
|
private readonly ConfigWindow _configWindow;
|
|
|
|
|
private readonly DebugOverlay _debugOverlay;
|
|
|
|
|
private readonly QuestWindow _questWindow;
|
2024-07-14 19:31:07 +00:00
|
|
|
|
private readonly QuestSelectionWindow _questSelectionWindow;
|
|
|
|
|
private readonly ITargetManager _targetManager;
|
2024-08-05 15:09:49 +00:00
|
|
|
|
private readonly QuestFunctions _questFunctions;
|
2024-09-01 13:14:28 +00:00
|
|
|
|
private readonly GameFunctions _gameFunctions;
|
|
|
|
|
private readonly IDataManager _dataManager;
|
2024-07-11 00:56:42 +00:00
|
|
|
|
|
2024-07-22 08:09:23 +00:00
|
|
|
|
public CommandHandler(
|
|
|
|
|
ICommandManager commandManager,
|
|
|
|
|
IChatGui chatGui,
|
|
|
|
|
QuestController questController,
|
|
|
|
|
MovementController movementController,
|
|
|
|
|
QuestRegistry questRegistry,
|
|
|
|
|
ConfigWindow configWindow,
|
|
|
|
|
DebugOverlay debugOverlay,
|
|
|
|
|
QuestWindow questWindow,
|
|
|
|
|
QuestSelectionWindow questSelectionWindow,
|
|
|
|
|
ITargetManager targetManager,
|
2024-09-01 13:14:28 +00:00
|
|
|
|
QuestFunctions questFunctions,
|
|
|
|
|
GameFunctions gameFunctions,
|
|
|
|
|
IDataManager dataManager)
|
2024-07-11 00:56:42 +00:00
|
|
|
|
{
|
|
|
|
|
_commandManager = commandManager;
|
|
|
|
|
_chatGui = chatGui;
|
|
|
|
|
_questController = questController;
|
|
|
|
|
_movementController = movementController;
|
|
|
|
|
_questRegistry = questRegistry;
|
|
|
|
|
_configWindow = configWindow;
|
|
|
|
|
_debugOverlay = debugOverlay;
|
|
|
|
|
_questWindow = questWindow;
|
2024-07-14 19:31:07 +00:00
|
|
|
|
_questSelectionWindow = questSelectionWindow;
|
|
|
|
|
_targetManager = targetManager;
|
2024-08-05 15:09:49 +00:00
|
|
|
|
_questFunctions = questFunctions;
|
2024-09-01 13:14:28 +00:00
|
|
|
|
_gameFunctions = gameFunctions;
|
|
|
|
|
_dataManager = dataManager;
|
2024-07-11 00:56:42 +00:00
|
|
|
|
|
|
|
|
|
_commandManager.AddHandler("/qst", new CommandInfo(ProcessCommand)
|
|
|
|
|
{
|
2024-07-22 08:09:23 +00:00
|
|
|
|
HelpMessage = string.Join($"{Environment.NewLine}\t",
|
|
|
|
|
"Opens the Questing window",
|
|
|
|
|
"/qst config - opens the configuration window",
|
|
|
|
|
"/qst start - starts doing quests",
|
|
|
|
|
"/qst stop - stops doing quests",
|
|
|
|
|
"/qst reload - reload all quest data",
|
|
|
|
|
"/qst which - shows all quests starting with your selected target",
|
|
|
|
|
"/qst zone - shows all quests starting in the current zone (only includes quests with a known quest path, and currently visible unaccepted quests)")
|
2024-07-11 00:56:42 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ProcessCommand(string command, string arguments)
|
|
|
|
|
{
|
|
|
|
|
string[] parts = arguments.Split(' ');
|
|
|
|
|
switch (parts[0])
|
|
|
|
|
{
|
|
|
|
|
case "c":
|
|
|
|
|
case "config":
|
|
|
|
|
_configWindow.Toggle();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "start":
|
2024-07-22 08:09:23 +00:00
|
|
|
|
_questWindow.IsOpen = true;
|
2024-08-10 18:36:43 +00:00
|
|
|
|
_questController.Start("Start command");
|
2024-07-11 00:56:42 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "stop":
|
|
|
|
|
_movementController.Stop();
|
|
|
|
|
_questController.Stop("Stop command");
|
|
|
|
|
break;
|
|
|
|
|
|
2024-07-22 08:09:23 +00:00
|
|
|
|
case "reload":
|
2024-08-09 22:57:09 +00:00
|
|
|
|
_questWindow.Reload();
|
2024-07-22 08:09:23 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2024-07-11 00:56:42 +00:00
|
|
|
|
case "do":
|
|
|
|
|
ConfigureDebugOverlay(parts.Skip(1).ToArray());
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "next":
|
|
|
|
|
SetNextQuest(parts.Skip(1).ToArray());
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "sim":
|
|
|
|
|
SetSimulatedQuest(parts.Skip(1).ToArray());
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "which":
|
2024-07-15 18:20:46 +00:00
|
|
|
|
_questSelectionWindow.OpenForTarget(_targetManager.Target);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "z":
|
|
|
|
|
case "zone":
|
2024-07-16 09:15:28 +00:00
|
|
|
|
_questSelectionWindow.OpenForCurrentZone();
|
2024-07-11 00:56:42 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2024-09-01 13:14:28 +00:00
|
|
|
|
case "mountid":
|
|
|
|
|
PrintMountId();
|
|
|
|
|
break;
|
|
|
|
|
|
2024-09-17 17:37:28 +00:00
|
|
|
|
case "handle-interrupt":
|
|
|
|
|
_questController.InterruptQueueWithCombat();
|
|
|
|
|
break;
|
|
|
|
|
|
2024-07-22 08:09:23 +00:00
|
|
|
|
case "":
|
2024-07-11 00:56:42 +00:00
|
|
|
|
_questWindow.Toggle();
|
|
|
|
|
break;
|
2024-07-22 08:09:23 +00:00
|
|
|
|
|
|
|
|
|
default:
|
2024-09-01 13:14:28 +00:00
|
|
|
|
_chatGui.PrintError($"Unknown subcommand {parts[0]}", MessageTag, TagColor);
|
2024-07-22 08:09:23 +00:00
|
|
|
|
break;
|
2024-07-11 00:56:42 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ConfigureDebugOverlay(string[] arguments)
|
|
|
|
|
{
|
|
|
|
|
if (!_debugOverlay.DrawConditions())
|
|
|
|
|
{
|
2024-09-01 13:14:28 +00:00
|
|
|
|
_chatGui.PrintError("You don't have the debug overlay enabled.", MessageTag, TagColor);
|
2024-07-11 00:56:42 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-04 14:03:23 +00:00
|
|
|
|
if (arguments.Length >= 1 && ElementId.TryFromString(arguments[0], out ElementId? questId) && questId != null)
|
2024-07-11 00:56:42 +00:00
|
|
|
|
{
|
2024-08-04 14:03:23 +00:00
|
|
|
|
if (_questRegistry.TryGetQuest(questId, out Quest? quest))
|
2024-07-11 00:56:42 +00:00
|
|
|
|
{
|
2024-08-04 14:03:23 +00:00
|
|
|
|
_debugOverlay.HighlightedQuest = quest.Id;
|
2024-09-01 13:14:28 +00:00
|
|
|
|
_chatGui.Print($"Set highlighted quest to {questId} ({quest.Info.Name}).", MessageTag, TagColor);
|
2024-07-11 00:56:42 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2024-09-01 13:14:28 +00:00
|
|
|
|
_chatGui.PrintError($"Unknown quest {questId}.", MessageTag, TagColor);
|
2024-07-11 00:56:42 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_debugOverlay.HighlightedQuest = null;
|
2024-09-01 13:14:28 +00:00
|
|
|
|
_chatGui.Print("Cleared highlighted quest.", MessageTag, TagColor);
|
2024-07-11 00:56:42 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetNextQuest(string[] arguments)
|
|
|
|
|
{
|
2024-08-04 14:03:23 +00:00
|
|
|
|
if (arguments.Length >= 1 && ElementId.TryFromString(arguments[0], out ElementId? questId) && questId != null)
|
2024-07-11 00:56:42 +00:00
|
|
|
|
{
|
2024-08-05 15:09:49 +00:00
|
|
|
|
if (_questFunctions.IsQuestLocked(questId))
|
2024-09-01 13:14:28 +00:00
|
|
|
|
_chatGui.PrintError($"Quest {questId} is locked.", MessageTag, TagColor);
|
2024-08-04 14:03:23 +00:00
|
|
|
|
else if (_questRegistry.TryGetQuest(questId, out Quest? quest))
|
2024-07-11 00:56:42 +00:00
|
|
|
|
{
|
|
|
|
|
_questController.SetNextQuest(quest);
|
2024-09-01 13:14:28 +00:00
|
|
|
|
_chatGui.Print($"Set next quest to {questId} ({quest.Info.Name}).", MessageTag, TagColor);
|
2024-07-11 00:56:42 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-09-01 13:14:28 +00:00
|
|
|
|
_chatGui.PrintError($"Unknown quest {questId}.", MessageTag, TagColor);
|
2024-07-11 00:56:42 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_questController.SetNextQuest(null);
|
2024-09-01 13:14:28 +00:00
|
|
|
|
_chatGui.Print("Cleared next quest.", MessageTag, TagColor);
|
2024-07-11 00:56:42 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetSimulatedQuest(string[] arguments)
|
|
|
|
|
{
|
2024-08-04 14:03:23 +00:00
|
|
|
|
if (arguments.Length >= 1 && ElementId.TryFromString(arguments[0], out ElementId? questId) && questId != null)
|
2024-07-11 00:56:42 +00:00
|
|
|
|
{
|
2024-08-04 14:03:23 +00:00
|
|
|
|
if (_questRegistry.TryGetQuest(questId, out Quest? quest))
|
2024-07-11 00:56:42 +00:00
|
|
|
|
{
|
|
|
|
|
_questController.SimulateQuest(quest);
|
2024-09-01 13:14:28 +00:00
|
|
|
|
_chatGui.Print($"Simulating quest {questId} ({quest.Info.Name}).", MessageTag, TagColor);
|
2024-07-11 00:56:42 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2024-09-01 13:14:28 +00:00
|
|
|
|
_chatGui.PrintError($"Unknown quest {questId}.", MessageTag, TagColor);
|
2024-07-11 00:56:42 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_questController.SimulateQuest(null);
|
2024-09-01 13:14:28 +00:00
|
|
|
|
_chatGui.Print("Cleared simulated quest.", MessageTag, TagColor);
|
2024-07-11 00:56:42 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-01 13:14:28 +00:00
|
|
|
|
private void PrintMountId()
|
|
|
|
|
{
|
|
|
|
|
ushort? mountId = _gameFunctions.GetMountId();
|
|
|
|
|
if (mountId != null)
|
|
|
|
|
{
|
|
|
|
|
var row = _dataManager.GetExcelSheet<Mount>()!.GetRow(mountId.Value);
|
|
|
|
|
_chatGui.Print(
|
|
|
|
|
$"Mount ID: {mountId}, Name: {row?.Singular}, Obtainable: {(row?.Order == -1 ? "No" : "Yes")}",
|
|
|
|
|
MessageTag, TagColor);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
_chatGui.Print("You are not mounted.", MessageTag, TagColor);
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-11 00:56:42 +00:00
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
_commandManager.RemoveHandler("/qst");
|
|
|
|
|
}
|
|
|
|
|
}
|