From 6cb8da9d5644ac6c812e52ee39f41f7cee2052ef Mon Sep 17 00:00:00 2001 From: kozhilya Date: Mon, 15 Sep 2025 17:47:44 +0400 Subject: [PATCH] =?UTF-8?q?=D0=91=D0=BE=D0=B6=D0=B5=D1=81=D1=82=D0=B2?= =?UTF-8?q?=D0=B0=D0=BC=D0=B8=20=D0=BD=D0=B0=20=D0=A4=D0=B0=D1=83=D0=BD?= =?UTF-8?q?=D0=B4=D1=80=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Processors/Entities/DeityProcessor.cs | 89 +++++++++++++++++++ .../Processors/FoundryEnAbstractProcessor.cs | 24 ++--- 2 files changed, 103 insertions(+), 10 deletions(-) create mode 100644 Pf2eDataScrapper/Importers/Implementations/FoundryEn/Processors/Entities/DeityProcessor.cs diff --git a/Pf2eDataScrapper/Importers/Implementations/FoundryEn/Processors/Entities/DeityProcessor.cs b/Pf2eDataScrapper/Importers/Implementations/FoundryEn/Processors/Entities/DeityProcessor.cs new file mode 100644 index 0000000..fc6944c --- /dev/null +++ b/Pf2eDataScrapper/Importers/Implementations/FoundryEn/Processors/Entities/DeityProcessor.cs @@ -0,0 +1,89 @@ +using System.Collections.Generic; +using System.Linq; +using Newtonsoft.Json.Linq; +using Pf2eDataScrapper.Helpers; +using Pf2eDataScrapper.Importers.Implementations.FoundryEn.Helpers; +using Pf2eDataScrapper.Processors; +using Pf2eDataScrapper.Processors.Attributes; +using Pf2eModel; +using Pf2eModel.Model.Enum; +using Pf2eModel.Model.Structure; +using Pf2eModel.Model.Structure.DeityRelation; + +namespace Pf2eDataScrapper.Importers.Implementations.FoundryEn.Processors.Entities; + +[ProcessorCollection( + "foundry-en:deity", + InnerType = "deity", + CompendiumType = ProcessorCompendiumEnum.FoundryEn, + Description = "Божества", + Group = ProcessorGroupEnum.FoundryEnEntities, + Active = true +)] +[ProcessorDependencies(["foundry-en:compendium", "foundry-en:external"])] +internal class DeityProcessor( + DatabaseHelper databaseHelper, + Pf2eDbContext context, + FoundryEnGlobals globals, + ProcessorInput input +) : FoundryEnAbstractProcessor(databaseHelper, context, globals, input) +{ + public override EntityType Type => EntityType.Deity; + + public override void Process() + { + base.Process(); + + ProcessSanctification(); + ProcessWeapons(); + } + + private void ProcessSanctification() + { + JObject? sanctification = Input.GetOptional("system.sanctification"); + if (sanctification == null) + { + Object.Sanctification = DeitySanctification.Any; + Object.SanctificationMust = false; + return; + } + + if ( + sanctification["what"] is not JArray sanctificationArray + || sanctificationArray.Count == 0 + || sanctificationArray.Count == 2 + && sanctificationArray.Any(t => t.ToString() == "holy") + && sanctificationArray.Any(t => t.ToString() == "unholy") + ) + { + Object.Sanctification = DeitySanctification.Any; + } + else if (sanctificationArray.Any(t => t.ToString() == "holy")) + { + Object.Sanctification = DeitySanctification.Holy; + } + else if (sanctificationArray.Any(t => t.ToString() == "unholy")) + { + Object.Sanctification = DeitySanctification.Unholy; + } + else + { + Object.Sanctification = DeitySanctification.Any; + } + + Object.SanctificationMust = sanctification["modal"]?.ToString() == "must"; + } + + private void ProcessWeapons() + { + List weapons = Input + .GetRequired("system.weapons") + .Select(token => token.ToString()) + .ToList(); + + foreach (string weapon in weapons) + { + Object.DeityWeapons.Add(new() { DeityId = Object.Id, Weapon = weapon }); + } + } +} diff --git a/Pf2eDataScrapper/Importers/Implementations/FoundryEn/Processors/FoundryEnAbstractProcessor.cs b/Pf2eDataScrapper/Importers/Implementations/FoundryEn/Processors/FoundryEnAbstractProcessor.cs index 3057261..00281a0 100644 --- a/Pf2eDataScrapper/Importers/Implementations/FoundryEn/Processors/FoundryEnAbstractProcessor.cs +++ b/Pf2eDataScrapper/Importers/Implementations/FoundryEn/Processors/FoundryEnAbstractProcessor.cs @@ -126,22 +126,26 @@ internal abstract class FoundryEnAbstractProcessor( return entities[0].Id; } - List inputTraits = Input - .GetRequired("system.traits.value") - .Select(token => token.ToString()) - .Order() - .ToList(); + JArray? traitArray = Input.GetOptional("system.traits.value"); - foreach (Entity entity in entities) + if (traitArray is not null) { - List entityTraits = entity - .Traits.Select(t => t.Entity.Name[LocaleType.English]) + List inputTraits = traitArray + .Select(token => token.ToString()) .Order() .ToList(); - if (entityTraits.SequenceEqual(inputTraits)) + foreach (Entity entity in entities) { - return entity.Id; + List entityTraits = entity + .Traits.Select(t => t.Entity.Name[LocaleType.English]) + .Order() + .ToList(); + + if (entityTraits.SequenceEqual(inputTraits)) + { + return entity.Id; + } } } }