using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Options; using NeonSprawl.Server.Game.Crafting; using NeonSprawl.Server.Game.Encounters; using NeonSprawl.Server.Game.Items; using NeonSprawl.Server.Game.Skills; namespace NeonSprawl.Server.Game.Quests; /// DI registration for the fail-fast quest catalog and registry (NEO-113, NEO-114). public static class QuestCatalogServiceCollectionExtensions { /// Binds and registers and as singletons. public static IServiceCollection AddQuestDefinitionCatalog(this IServiceCollection services, IConfiguration configuration) { services.AddOptions() .Bind(configuration.GetSection(ContentPathsOptions.SectionName)); services.AddSingleton(sp => { var hostEnv = sp.GetRequiredService(); var opts = sp.GetRequiredService>().Value; var itemCatalog = sp.GetRequiredService(); var recipeCatalog = sp.GetRequiredService(); var encounterCatalog = sp.GetRequiredService(); var skillCatalog = sp.GetRequiredService(); var logger = sp.GetRequiredService() .CreateLogger("NeonSprawl.Server.Game.Quests.QuestCatalog"); var questsDir = QuestCatalogPathResolution.ResolveQuestsDirectory( opts.QuestsDirectory, hostEnv.ContentRootPath); var questDefSchemaPath = QuestCatalogPathResolution.ResolveQuestDefSchemaPath( questsDir, opts.QuestDefSchemaPath, hostEnv.ContentRootPath); var questStepDefSchemaPath = QuestCatalogPathResolution.ResolveQuestStepDefSchemaPath( questsDir, opts.QuestStepDefSchemaPath, hostEnv.ContentRootPath); var questObjectiveDefSchemaPath = QuestCatalogPathResolution.ResolveQuestObjectiveDefSchemaPath( questsDir, opts.QuestObjectiveDefSchemaPath, hostEnv.ContentRootPath); var rewardGrantRowSchemaPath = QuestCatalogPathResolution.ResolveRewardGrantRowSchemaPath(questsDir); var questSkillXpGrantSchemaPath = QuestCatalogPathResolution.ResolveQuestSkillXpGrantSchemaPath(questsDir); var questRewardBundleSchemaPath = QuestCatalogPathResolution.ResolveQuestRewardBundleSchemaPath(questsDir); var knownItemIds = itemCatalog.ById.Keys.ToHashSet(StringComparer.Ordinal); var knownRecipeIds = recipeCatalog.ById.Keys.ToHashSet(StringComparer.Ordinal); var knownEncounterIds = encounterCatalog.ById.Keys.ToHashSet(StringComparer.Ordinal); return QuestDefinitionCatalogLoader.Load( questsDir, questDefSchemaPath, questStepDefSchemaPath, questObjectiveDefSchemaPath, rewardGrantRowSchemaPath, questSkillXpGrantSchemaPath, questRewardBundleSchemaPath, knownItemIds, knownRecipeIds, knownEncounterIds, skillCatalog.ById, logger); }); services.AddSingleton(sp => new QuestDefinitionRegistry(sp.GetRequiredService())); return services; } }