Questionable/Questionable/QuestionablePlugin.cs

291 lines
16 KiB
C#
Raw Normal View History

2024-05-26 19:45:26 +00:00
using System;
2024-06-08 19:16:57 +00:00
using System.Diagnostics.CodeAnalysis;
using Dalamud.Extensions.MicrosoftLogging;
2024-05-25 21:51:37 +00:00
using Dalamud.Game;
using Dalamud.Game.ClientState.Objects;
using Dalamud.Interface.Windowing;
using Dalamud.Plugin;
using Dalamud.Plugin.Services;
2024-06-08 19:16:57 +00:00
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
2024-05-25 21:51:37 +00:00
using Questionable.Controller;
using Questionable.Controller.CombatModules;
2024-08-17 23:55:38 +00:00
using Questionable.Controller.GameUi;
using Questionable.Controller.NavigationOverrides;
using Questionable.Controller.Steps;
using Questionable.Controller.Steps.Shared;
using Questionable.Controller.Steps.Common;
2024-08-03 09:17:20 +00:00
using Questionable.Controller.Steps.Gathering;
using Questionable.Controller.Steps.Interactions;
2024-08-07 23:49:14 +00:00
using Questionable.Controller.Steps.Leves;
2024-09-11 14:58:07 +00:00
using Questionable.Controller.Utils;
2024-05-27 19:54:34 +00:00
using Questionable.Data;
2024-05-25 21:51:37 +00:00
using Questionable.External;
using Questionable.Functions;
2024-07-15 22:18:10 +00:00
using Questionable.Validation;
using Questionable.Validation.Validators;
2024-05-25 21:51:37 +00:00
using Questionable.Windows;
using Questionable.Windows.JournalComponents;
using Questionable.Windows.QuestComponents;
using Action = Questionable.Controller.Steps.Interactions.Action;
2024-05-25 21:51:37 +00:00
namespace Questionable;
2024-06-08 19:16:57 +00:00
[SuppressMessage("ReSharper", "UnusedType.Global")]
2024-05-27 19:54:34 +00:00
public sealed class QuestionablePlugin : IDalamudPlugin
2024-05-25 21:51:37 +00:00
{
2024-06-08 19:16:57 +00:00
private readonly ServiceProvider? _serviceProvider;
2024-07-03 19:00:04 +00:00
public QuestionablePlugin(IDalamudPluginInterface pluginInterface,
2024-06-08 19:16:57 +00:00
IClientState clientState,
ITargetManager targetManager,
IFramework framework,
IGameGui gameGui,
IDataManager dataManager,
ISigScanner sigScanner,
IObjectTable objectTable,
IPluginLog pluginLog,
ICondition condition,
IChatGui chatGui,
ICommandManager commandManager,
IAddonLifecycle addonLifecycle,
IKeyState keyState,
IContextMenu contextMenu,
2024-08-17 23:55:38 +00:00
IToastGui toastGui,
IGameInteropProvider gameInteropProvider)
2024-05-25 21:51:37 +00:00
{
2024-05-26 19:45:26 +00:00
ArgumentNullException.ThrowIfNull(pluginInterface);
ArgumentNullException.ThrowIfNull(chatGui);
try
{
ServiceCollection serviceCollection = new();
serviceCollection.AddLogging(builder => builder.SetMinimumLevel(LogLevel.Trace)
.ClearProviders()
.AddDalamudLogger(pluginLog, t => t[(t.LastIndexOf('.') + 1)..]));
serviceCollection.AddSingleton<IDalamudPlugin>(this);
serviceCollection.AddSingleton(pluginInterface);
serviceCollection.AddSingleton(clientState);
serviceCollection.AddSingleton(targetManager);
serviceCollection.AddSingleton(framework);
serviceCollection.AddSingleton(gameGui);
serviceCollection.AddSingleton(dataManager);
serviceCollection.AddSingleton(sigScanner);
serviceCollection.AddSingleton(objectTable);
serviceCollection.AddSingleton(pluginLog);
serviceCollection.AddSingleton(condition);
serviceCollection.AddSingleton(chatGui);
serviceCollection.AddSingleton(commandManager);
serviceCollection.AddSingleton(addonLifecycle);
serviceCollection.AddSingleton(keyState);
serviceCollection.AddSingleton(contextMenu);
serviceCollection.AddSingleton(toastGui);
2024-08-17 23:55:38 +00:00
serviceCollection.AddSingleton(gameInteropProvider);
serviceCollection.AddSingleton(new WindowSystem(nameof(Questionable)));
serviceCollection.AddSingleton((Configuration?)pluginInterface.GetPluginConfig() ?? new Configuration());
AddBasicFunctionsAndData(serviceCollection);
AddTaskFactories(serviceCollection);
AddControllers(serviceCollection);
AddWindows(serviceCollection);
AddQuestValidators(serviceCollection);
serviceCollection.AddSingleton<CommandHandler>();
serviceCollection.AddSingleton<DalamudInitializer>();
_serviceProvider = serviceCollection.BuildServiceProvider();
Initialize(_serviceProvider);
}
catch (Exception)
{
chatGui.PrintError("Unable to load plugin, check /xllog for details", "Questionable");
throw;
}
}
private static void AddBasicFunctionsAndData(ServiceCollection serviceCollection)
{
serviceCollection.AddSingleton<AetheryteFunctions>();
serviceCollection.AddSingleton<ExcelFunctions>();
2024-06-08 19:16:57 +00:00
serviceCollection.AddSingleton<GameFunctions>();
serviceCollection.AddSingleton<ChatFunctions>();
serviceCollection.AddSingleton<QuestFunctions>();
2024-09-11 14:58:07 +00:00
serviceCollection.AddSingleton<AutoSnipeHandler>();
serviceCollection.AddSingleton<AetherCurrentData>();
2024-06-08 19:16:57 +00:00
serviceCollection.AddSingleton<AetheryteData>();
2024-08-03 09:17:20 +00:00
serviceCollection.AddSingleton<GatheringData>();
2024-08-07 23:49:14 +00:00
serviceCollection.AddSingleton<LeveData>();
2024-07-29 14:54:18 +00:00
serviceCollection.AddSingleton<JournalData>();
serviceCollection.AddSingleton<QuestData>();
2024-06-08 19:16:57 +00:00
serviceCollection.AddSingleton<TerritoryData>();
serviceCollection.AddSingleton<NavmeshIpc>();
serviceCollection.AddSingleton<LifestreamIpc>();
2024-06-16 15:43:42 +00:00
serviceCollection.AddSingleton<YesAlreadyIpc>();
serviceCollection.AddSingleton<ArtisanIpc>();
serviceCollection.AddSingleton<QuestionableIpc>();
}
2024-06-08 19:16:57 +00:00
private static void AddTaskFactories(ServiceCollection serviceCollection)
{
// individual tasks
2024-09-18 22:00:16 +00:00
serviceCollection.AddTaskExecutor<MoveToLandingLocation.Task, MoveToLandingLocation.MoveToLandingLocationExecutor>();
serviceCollection.AddTaskExecutor<DoGather.Task, DoGather.GatherExecutor>();
serviceCollection.AddTaskExecutor<DoGatherCollectable.Task, DoGatherCollectable.GatherCollectableExecutor>();
serviceCollection.AddTaskExecutor<SwitchClassJob.Task, SwitchClassJob.SwitchClassJobExecutor>();
serviceCollection.AddTaskExecutor<Mount.MountTask, Mount.MountExecutor>();
serviceCollection.AddTaskExecutor<Mount.UnmountTask, Mount.UnmountExecutor>();
// task factories
serviceCollection
2024-09-18 22:00:16 +00:00
.AddTaskFactoryAndExecutor<StepDisabled.SkipRemainingTasks, StepDisabled.Factory, StepDisabled.SkipDisabledStepsExecutor>();
2024-08-20 00:48:06 +00:00
serviceCollection.AddTaskFactory<EquipRecommended.BeforeDutyOrInstance>();
serviceCollection.AddTaskFactoryAndExecutor<Gather.GatheringTask, Gather.Factory, Gather.StartGathering>();
serviceCollection.AddTaskExecutor<Gather.SkipMarker, Gather.DoSkip>();
serviceCollection
.AddTaskFactoryAndExecutor<AetheryteShortcut.Task, AetheryteShortcut.Factory,
AetheryteShortcut.UseAetheryteShortcut>();
serviceCollection
.AddTaskFactoryAndExecutor<SkipCondition.SkipTask, SkipCondition.Factory, SkipCondition.CheckSkip>();
serviceCollection
.AddTaskFactoryAndExecutor<AethernetShortcut.Task, AethernetShortcut.Factory,
AethernetShortcut.UseAethernetShortcut>();
serviceCollection
.AddTaskFactoryAndExecutor<WaitAtStart.WaitDelay, WaitAtStart.Factory, WaitAtStart.WaitDelayExecutor>();
serviceCollection.AddTaskFactoryAndExecutor<MoveTo.MoveTask, MoveTo.Factory, MoveTo.MoveExecutor>();
serviceCollection.AddTaskExecutor<MoveTo.WaitForNearDataId, MoveTo.WaitForNearDataIdExecutor>();
serviceCollection.AddTaskExecutor<MoveTo.LandTask, MoveTo.LandExecutor>();
2024-09-18 22:00:16 +00:00
serviceCollection.AddTaskFactoryAndExecutor<NextQuest.SetQuestTask, NextQuest.Factory, NextQuest.NextQuestExecutor>();
serviceCollection
.AddTaskFactoryAndExecutor<AetherCurrent.Attune, AetherCurrent.Factory, AetherCurrent.DoAttune>();
serviceCollection
.AddTaskFactoryAndExecutor<AethernetShard.Attune, AethernetShard.Factory, AethernetShard.DoAttune>();
serviceCollection.AddTaskFactoryAndExecutor<Aetheryte.Attune, Aetheryte.Factory, Aetheryte.DoAttune>();
serviceCollection.AddTaskFactoryAndExecutor<Combat.Task, Combat.Factory, Combat.HandleCombat>();
2024-09-18 22:00:16 +00:00
serviceCollection.AddTaskFactoryAndExecutor<Duty.Task, Duty.Factory, Duty.OpenDutyWindowExecutor>();
2024-08-20 00:48:06 +00:00
serviceCollection.AddTaskFactory<Emote.Factory>();
serviceCollection.AddTaskExecutor<Emote.UseOnObject, Emote.UseOnObjectExecutor>();
serviceCollection.AddTaskExecutor<Emote.UseOnSelf, Emote.UseOnSelfExecutor>();
serviceCollection.AddTaskFactoryAndExecutor<Action.UseOnObject, Action.Factory, Action.UseOnObjectExecutor>();
serviceCollection.AddTaskFactoryAndExecutor<Interact.Task, Interact.Factory, Interact.DoInteract>();
2024-08-20 00:48:06 +00:00
serviceCollection.AddTaskFactory<Jump.Factory>();
serviceCollection.AddTaskExecutor<Jump.SingleJumpTask, Jump.DoSingleJump>();
serviceCollection.AddTaskExecutor<Jump.RepeatedJumpTask, Jump.DoRepeatedJumps>();
serviceCollection.AddTaskFactoryAndExecutor<Dive.Task, Dive.Factory, Dive.DoDive>();
serviceCollection.AddTaskFactoryAndExecutor<Say.Task, Say.Factory, Say.UseChat>();
2024-08-20 00:48:06 +00:00
serviceCollection.AddTaskFactory<UseItem.Factory>();
serviceCollection.AddTaskExecutor<UseItem.UseOnGround, UseItem.UseOnGroundExecutor>();
serviceCollection.AddTaskExecutor<UseItem.UseOnPosition, UseItem.UseOnPositionExecutor>();
serviceCollection.AddTaskExecutor<UseItem.UseOnObject, UseItem.UseOnObjectExecutor>();
serviceCollection.AddTaskExecutor<UseItem.UseOnSelf, UseItem.UseOnSelfExecutor>();
2024-09-18 22:00:16 +00:00
serviceCollection.AddTaskFactoryAndExecutor<EquipItem.Task, EquipItem.Factory, EquipItem.DoEquip>();
serviceCollection
.AddTaskFactoryAndExecutor<EquipRecommended.EquipTask, EquipRecommended.Factory,
EquipRecommended.DoEquipRecommended>();
serviceCollection.AddTaskFactoryAndExecutor<Craft.CraftTask, Craft.Factory, Craft.DoCraft>();
serviceCollection
.AddTaskFactoryAndExecutor<TurnInDelivery.Task, TurnInDelivery.Factory,
TurnInDelivery.SatisfactionSupplyTurnIn>();
2024-08-20 00:48:06 +00:00
serviceCollection.AddTaskFactory<InitiateLeve.Factory>();
serviceCollection.AddTaskExecutor<InitiateLeve.SkipInitiateIfActive, InitiateLeve.SkipInitiateIfActiveExecutor>();
serviceCollection.AddTaskExecutor<InitiateLeve.OpenJournal, InitiateLeve.OpenJournalExecutor>();
serviceCollection.AddTaskExecutor<InitiateLeve.Initiate, InitiateLeve.InitiateExecutor>();
serviceCollection.AddTaskExecutor<InitiateLeve.SelectDifficulty, InitiateLeve.SelectDifficultyExecutor>();
2024-09-18 22:00:16 +00:00
serviceCollection.AddTaskExecutor<WaitCondition.Task, WaitCondition.WaitConditionExecutor>();
2024-08-20 00:48:06 +00:00
serviceCollection.AddTaskFactory<WaitAtEnd.Factory>();
serviceCollection.AddTaskExecutor<WaitAtEnd.WaitDelay, WaitAtEnd.WaitDelayExecutor>();
serviceCollection.AddTaskExecutor<WaitAtEnd.WaitNextStepOrSequence, WaitAtEnd.WaitNextStepOrSequenceExecutor>();
serviceCollection.AddTaskExecutor<WaitAtEnd.WaitForCompletionFlags, WaitAtEnd.WaitForCompletionFlagsExecutor>();
serviceCollection.AddTaskExecutor<WaitAtEnd.WaitObjectAtPosition, WaitAtEnd.WaitObjectAtPositionExecutor>();
serviceCollection.AddTaskExecutor<WaitAtEnd.WaitQuestAccepted, WaitAtEnd.WaitQuestAcceptedExecutor>();
serviceCollection.AddTaskExecutor<WaitAtEnd.WaitQuestCompleted, WaitAtEnd.WaitQuestCompletedExecutor>();
serviceCollection.AddTaskExecutor<WaitAtEnd.NextStep, WaitAtEnd.NextStepExecutor>();
serviceCollection.AddTaskExecutor<WaitAtEnd.EndAutomation, WaitAtEnd.EndAutomationExecutor>();
serviceCollection.AddSingleton<TaskCreator>();
}
private static void AddControllers(ServiceCollection serviceCollection)
{
2024-06-08 19:16:57 +00:00
serviceCollection.AddSingleton<MovementController>();
serviceCollection.AddSingleton<MovementOverrideController>();
serviceCollection.AddSingleton<GatheringPointRegistry>();
2024-06-08 19:16:57 +00:00
serviceCollection.AddSingleton<QuestRegistry>();
serviceCollection.AddSingleton<QuestController>();
serviceCollection.AddSingleton<CombatController>();
2024-08-03 09:17:20 +00:00
serviceCollection.AddSingleton<GatheringController>();
serviceCollection.AddSingleton<ContextMenuController>();
2024-08-17 23:55:38 +00:00
serviceCollection.AddSingleton<CraftworksSupplyController>();
serviceCollection.AddSingleton<CreditsController>();
serviceCollection.AddSingleton<HelpUiController>();
serviceCollection.AddSingleton<InteractionUiController>();
serviceCollection.AddSingleton<LeveUiController>();
serviceCollection.AddSingleton<ICombatModule, Mount128Module>();
serviceCollection.AddSingleton<ICombatModule, RotationSolverRebornModule>();
}
2024-06-08 19:16:57 +00:00
private static void AddWindows(ServiceCollection serviceCollection)
{
serviceCollection.AddSingleton<UiUtils>();
serviceCollection.AddSingleton<ActiveQuestComponent>();
serviceCollection.AddSingleton<ARealmRebornComponent>();
serviceCollection.AddSingleton<CreationUtilsComponent>();
2024-08-19 13:19:15 +00:00
serviceCollection.AddSingleton<EventInfoComponent>();
2024-07-29 14:54:18 +00:00
serviceCollection.AddSingleton<QuestTooltipComponent>();
serviceCollection.AddSingleton<QuickAccessButtonsComponent>();
serviceCollection.AddSingleton<RemainingTasksComponent>();
serviceCollection.AddSingleton<QuestJournalComponent>();
serviceCollection.AddSingleton<GatheringJournalComponent>();
2024-06-18 15:51:23 +00:00
serviceCollection.AddSingleton<QuestWindow>();
2024-06-12 16:03:48 +00:00
serviceCollection.AddSingleton<ConfigWindow>();
2024-06-18 15:51:23 +00:00
serviceCollection.AddSingleton<DebugOverlay>();
serviceCollection.AddSingleton<QuestSelectionWindow>();
2024-07-15 22:18:10 +00:00
serviceCollection.AddSingleton<QuestValidationWindow>();
2024-07-29 14:54:18 +00:00
serviceCollection.AddSingleton<JournalProgressWindow>();
2024-08-24 23:30:42 +00:00
serviceCollection.AddSingleton<PriorityWindow>();
}
2024-07-15 22:18:10 +00:00
private static void AddQuestValidators(ServiceCollection serviceCollection)
{
2024-07-15 22:18:10 +00:00
serviceCollection.AddSingleton<QuestValidator>();
serviceCollection.AddSingleton<IQuestValidator, QuestDisabledValidator>();
serviceCollection.AddSingleton<IQuestValidator, BasicSequenceValidator>();
serviceCollection.AddSingleton<IQuestValidator, UniqueStartStopValidator>();
2024-07-16 12:43:31 +00:00
serviceCollection.AddSingleton<IQuestValidator, NextQuestValidator>();
2024-07-15 22:18:10 +00:00
serviceCollection.AddSingleton<IQuestValidator, CompletionFlagsValidator>();
2024-07-27 22:13:52 +00:00
serviceCollection.AddSingleton<IQuestValidator, AethernetShortcutValidator>();
serviceCollection.AddSingleton<IQuestValidator, DialogueChoiceValidator>();
serviceCollection.AddSingleton<IQuestValidator, ClassQuestShouldHaveShortcutValidator>();
serviceCollection.AddSingleton<JsonSchemaValidator>();
serviceCollection.AddSingleton<IQuestValidator>(sp => sp.GetRequiredService<JsonSchemaValidator>());
2024-05-25 21:51:37 +00:00
}
private static void Initialize(IServiceProvider serviceProvider)
{
serviceProvider.GetRequiredService<QuestRegistry>().Reload();
serviceProvider.GetRequiredService<GatheringPointRegistry>().Reload();
serviceProvider.GetRequiredService<CommandHandler>();
serviceProvider.GetRequiredService<ContextMenuController>();
2024-08-17 23:55:38 +00:00
serviceProvider.GetRequiredService<CraftworksSupplyController>();
serviceProvider.GetRequiredService<CreditsController>();
serviceProvider.GetRequiredService<HelpUiController>();
serviceProvider.GetRequiredService<LeveUiController>();
serviceProvider.GetRequiredService<QuestionableIpc>();
serviceProvider.GetRequiredService<DalamudInitializer>();
2024-09-11 14:58:07 +00:00
serviceProvider.GetRequiredService<AutoSnipeHandler>().Enable();
}
2024-05-25 21:51:37 +00:00
public void Dispose()
{
2024-06-08 19:16:57 +00:00
_serviceProvider?.Dispose();
2024-05-25 21:51:37 +00:00
}
}