From a27e3894a0d6f93331b61cc03c729b40ac60ec3d Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Mon, 2 Dec 2024 21:59:55 +0100 Subject: [PATCH] =?UTF-8?q?Fix=20Import=20entit=C3=A9s=20de=20cauchemar&cr?= =?UTF-8?q?=C3=A9atures?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - utiliser les carac liées au type d'entités - fix: +dom&protection 0 ou négatifs - fix compétences (qui peuvent ne pas avoir d'init) --- module/apps/rdd-import-stats.js | 109 +++++++++++++++++++++----------- 1 file changed, 72 insertions(+), 37 deletions(-) diff --git a/module/apps/rdd-import-stats.js b/module/apps/rdd-import-stats.js index a6c6494a..0f938010 100644 --- a/module/apps/rdd-import-stats.js +++ b/module/apps/rdd-import-stats.js @@ -4,6 +4,7 @@ import { SystemCompendiums } from "../settings/system-compendiums.js"; import { RdDBaseActorReve } from "../actor/base-actor-reve.js"; import { Grammar } from "../grammar.js"; import { Misc } from "../misc.js"; +import { ENTITE_INCARNE, ENTITE_NONINCARNE } from "../constants.js"; /************************************************************************************/ // Some internal test strings @@ -291,17 +292,13 @@ export class RdDStatBlockParser { // Remove all leading and trailing spaces statString = statString.trim(); - let actorType = "personnage"; // TODO: check for entite - let perception = XRegExp.exec(statString, XRegExp("perception\\s+(?\\d+)", 'giu')) - if (perception?.value) { - actorType = "creature"; - } + let actorType = RdDStatBlockParser.parseActorType(statString); // Now start carac let actorData = foundry.utils.deepClone(game.model.Actor[actorType]); - for (let key in game.model.Actor.personnage.carac) { - let caracDef = game.model.Actor.personnage.carac[key]; + for (let key in actorData.carac) { + let caracDef = actorData.carac[key]; // Parse the stat string for each caracteristic let carac = XRegExp.exec(statString, XRegExp(caracDef.label + "\\s+(?\\d+)", 'giu')); if (carac?.value) { @@ -310,29 +307,13 @@ export class RdDStatBlockParser { } // If creature we need to setup additionnal fields - if (actorType == "creature") { - let plusDom = XRegExp.exec(statString, XRegExp("\\+dom\\s+(?\\+\\d+)", 'giu')); - if (plusDom?.values) { - actorData.attributs.plusdom.value = Number(plusDom.value); - } - let protection = XRegExp.exec(statString, XRegExp("protection\\s+(?\\d+)", 'giu')); - if (protection?.value) { - actorData.attributs.protection.value = Number(protection.value); - } - let endurance = XRegExp.exec(statString, XRegExp("endurance\\s+(?\\d+)", 'giu')); - if (endurance?.value) { - actorData.sante.endurance.value = Number(endurance.value); - actorData.sante.endurance.max = Number(endurance.value); - } - let vie = XRegExp.exec(statString, XRegExp("vie\\s+(?\\d+)", 'giu')); - if (vie.value) { - actorData.sante.vie.value = Number(vie.value); - actorData.sante.vie.max = Number(vie.value); - } - let vitesse = XRegExp.exec(statString, XRegExp("vitesse\\s+(?[\\d\\/]+)", 'giu')); - if (vitesse?.value) { - actorData.attributs.vitesse.value = vitesse.value; - } + switch (actorType) { + case "creature": + RdDStatBlockParser.parseCreature(statString, actorData) + break + case "entite": + RdDStatBlockParser.parseEntite(statString, actorData) + break } let items = []; @@ -353,11 +334,8 @@ export class RdDStatBlockParser { } } } - if (actorType == "creature" && skill.init) { - items.push(comp); // Only selective push - } - if (actorType == "personnage") { - items.push(comp); // Always push + if (actorType == "personnage" || skill!= undefined){ + items.push(comp) } } @@ -418,10 +396,10 @@ export class RdDStatBlockParser { items.push(sort); } }); - if (hautRevant) { + if (hautRevant) { let tetes = await SystemCompendiums.getWorldOrCompendiumItems("tete", "tetes-de-dragon-pour-tous-personnages") let donHR = tetes.find(t => Grammar.equalsInsensitive(t.name, "Don de Haut-Rêve")) - if (donHR) { + if (donHR) { items.push(donHR.toObject()); } } @@ -474,6 +452,63 @@ export class RdDStatBlockParser { console.log(actorData); } + static parseCreature(statString, actorData) { + let plusDom = XRegExp.exec(statString, XRegExp("\\+dom\\s+(?[\\+\\-]?\\d+)", 'giu')); + if (plusDom?.values) { + actorData.attributs.plusdom.value = Number(plusDom.value); + } + let protection = XRegExp.exec(statString, XRegExp("protection\\s+(?[\\-]?\\d+)", 'giu')); + if (protection?.value) { + actorData.attributs.protection.value = Number(protection.value); + } + let endurance = XRegExp.exec(statString, XRegExp("endurance\\s+(?\\d+)", 'giu')); + if (endurance?.value) { + actorData.sante.endurance.value = Number(endurance.value); + actorData.sante.endurance.max = Number(endurance.value); + } + let vie = XRegExp.exec(statString, XRegExp("vie\\s+(?\\d+)", 'giu')); + if (vie.value) { + actorData.sante.vie.value = Number(vie.value); + actorData.sante.vie.max = Number(vie.value); + } + let vitesse = XRegExp.exec(statString, XRegExp("vitesse\\s+(?[\\d\\/]+)", 'giu')); + if (vitesse?.value) { + actorData.attributs.vitesse.value = vitesse.value; + } + } + + static parseEntite(statString, actorData) { + let plusDom = XRegExp.exec(statString, XRegExp("\\+dom\\s+(?[\\+\\-]?\\d+)", 'giu')); + if (plusDom?.values) { + actorData.attributs.plusdom.value = Number(plusDom.value); + } + + actorData.definition.categorieentite = 'cauchemar' + actorData.definition.typeentite = ENTITE_NONINCARNE + let endurance = XRegExp.exec(statString, XRegExp("endurance\\s+(?\\d+)", 'giu')); + if (endurance?.value) { + actorData.sante.endurance.value = Number(endurance.value); + actorData.sante.endurance.max = Number(endurance.value); + actorData.definition.typeentite = ENTITE_INCARNE + } + let vitesse = XRegExp.exec(statString, XRegExp("vitesse\\s+(?[\\d\\/]+)", 'giu')); + if (vitesse?.value) { + actorData.attributs.vitesse.value = vitesse.value; + } + } + + static parseActorType(statString) { + let niveau = XRegExp.exec(statString, XRegExp("Niveau\\s+(?[\\+\\-]?\\d+)", 'giu')) + let perception = XRegExp.exec(statString, XRegExp("perception\\s+(?\\d+)", 'giu')) + if (perception?.value) { + return "creature" + } + if (niveau?.value) { + return "entite" + } + return "personnage" + } + static extractName(actorType, statString) { switch (actorType) { case "personnage": return RdDStatBlockParser.extractNamePersonnage(statString);