Questionable/Questionable/QuestionablePlugin.cs

258 lines
12 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-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>();
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>();
}
2024-06-08 19:16:57 +00:00
private static void AddTaskFactories(ServiceCollection serviceCollection)
{
// individual tasks
serviceCollection.AddTransient<MountTask>();
serviceCollection.AddTransient<UnmountTask>();
2024-08-03 09:17:20 +00:00
serviceCollection.AddTransient<MoveToLandingLocation>();
2024-08-03 15:26:49 +00:00
serviceCollection.AddTransient<DoGather>();
serviceCollection.AddTransient<DoGatherCollectable>();
serviceCollection.AddTransient<SwitchClassJob>();
// task factories
serviceCollection.AddTaskWithFactory<StepDisabled.Factory, StepDisabled.Task>();
serviceCollection.AddSingleton<ITaskFactory, EquipRecommended.BeforeDutyOrInstance>();
2024-08-17 23:55:38 +00:00
serviceCollection.AddTaskWithFactory<GatheringRequiredItems.Factory, GatheringRequiredItems.StartGathering, GatheringRequiredItems.SkipMarker>();
serviceCollection.AddTaskWithFactory<AetheryteShortcut.Factory, AetheryteShortcut.UseAetheryteShortcut>();
2024-07-27 15:37:08 +00:00
serviceCollection.AddTaskWithFactory<SkipCondition.Factory, SkipCondition.CheckSkip>();
serviceCollection.AddTaskWithFactory<AethernetShortcut.Factory, AethernetShortcut.UseAethernetShortcut>();
2024-06-18 15:51:23 +00:00
serviceCollection.AddTaskWithFactory<WaitAtStart.Factory, WaitAtStart.WaitDelay>();
2024-07-12 21:58:48 +00:00
serviceCollection.AddTaskWithFactory<Move.Factory, Move.MoveInternal, Move.ExpectToBeNearDataId, Move.Land>();
serviceCollection.AddTransient<Move.MoveBuilder>();
2024-07-11 11:11:50 +00:00
serviceCollection.AddTaskWithFactory<NextQuest.Factory, NextQuest.SetQuest>();
serviceCollection.AddTaskWithFactory<AetherCurrent.Factory, AetherCurrent.DoAttune>();
serviceCollection.AddTaskWithFactory<AethernetShard.Factory, AethernetShard.DoAttune>();
serviceCollection.AddTaskWithFactory<Aetheryte.Factory, Aetheryte.DoAttune>();
serviceCollection.AddTaskWithFactory<Combat.Factory, Combat.HandleCombat>();
serviceCollection.AddTaskWithFactory<Duty.Factory, Duty.OpenDutyFinder>();
serviceCollection.AddTaskWithFactory<Emote.Factory, Emote.UseOnObject, Emote.Use>();
serviceCollection.AddTaskWithFactory<Action.Factory, Action.UseOnObject>();
serviceCollection.AddTaskWithFactory<Interact.Factory, Interact.DoInteract>();
2024-07-24 18:47:08 +00:00
serviceCollection.AddTaskWithFactory<Jump.Factory, Jump.SingleJump, Jump.RepeatedJumps>();
serviceCollection.AddTaskWithFactory<Dive.Factory, Dive.DoDive>();
serviceCollection.AddTaskWithFactory<Say.Factory, Say.UseChat>();
2024-08-07 23:49:14 +00:00
serviceCollection
.AddTaskWithFactory<UseItem.Factory, UseItem.UseOnGround, UseItem.UseOnObject, UseItem.Use,
UseItem.UseOnPosition>();
serviceCollection.AddTaskWithFactory<EquipItem.Factory, EquipItem.DoEquip>();
2024-08-10 16:14:15 +00:00
serviceCollection.AddTaskWithFactory<EquipRecommended.Factory, EquipRecommended.DoEquipRecommended>();
serviceCollection.AddTaskWithFactory<Craft.Factory, Craft.DoCraft>();
serviceCollection.AddTaskWithFactory<TurnInDelivery.Factory, TurnInDelivery.SatisfactionSupplyTurnIn>();
2024-08-07 23:49:14 +00:00
serviceCollection
2024-08-11 16:59:42 +00:00
.AddTaskWithFactory<InitiateLeve.Factory,
InitiateLeve.SkipInitiateIfActive,
InitiateLeve.OpenJournal,
InitiateLeve.Initiate,
2024-08-07 23:49:14 +00:00
InitiateLeve.SelectDifficulty>();
serviceCollection
.AddTaskWithFactory<WaitAtEnd.Factory,
WaitAtEnd.WaitDelay,
WaitAtEnd.WaitNextStepOrSequence,
WaitAtEnd.WaitForCompletionFlags,
WaitAtEnd.WaitObjectAtPosition>();
serviceCollection.AddTransient<WaitAtEnd.WaitQuestAccepted>();
serviceCollection.AddTransient<WaitAtEnd.WaitQuestCompleted>();
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, 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-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-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<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<DalamudInitializer>();
}
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
}
}