Import compétences avec spécialisations

ie: Musique (Harpe) +6
This commit is contained in:
Vincent Vandemeulebrouck 2024-12-07 19:20:01 +01:00
parent a896fdb166
commit c6feac41c6

View File

@ -144,7 +144,7 @@ export class RdDStatBlockParser {
let actorData = foundry.utils.deepClone(game.model.Actor[type]); let actorData = foundry.utils.deepClone(game.model.Actor[type]);
let items = []; let items = [];
actorData.flags = { hautRevant: false, malusArmure: 0 } actorData.flags = { hautRevant: false, malusArmure: 0, type }
for (let key in actorData.carac) { for (let key in actorData.carac) {
let caracDef = actorData.carac[key]; let caracDef = actorData.carac[key];
// Parse the stat string for each caracteristic // Parse the stat string for each caracteristic
@ -169,7 +169,7 @@ export class RdDStatBlockParser {
} }
// Get skills from compendium // Get skills from compendium
await RdDStatBlockParser.parseCompetences(type, statString, actorData, items); await RdDStatBlockParser.parseCompetences(statString, actorData, items);
if (type == "personnage") { if (type == "personnage") {
@ -191,35 +191,48 @@ export class RdDStatBlockParser {
await newActor?.sheet.render(true) await newActor?.sheet.render(true)
} }
static async parseCompetences(type, statString, actorData, items) { static async parseCompetences(statString, actorData, items) {
const competences = await SystemCompendiums.getCompetences(type); const competences = await SystemCompendiums.getCompetences(actorData.flags.type);
//console.log("Competences : ", competences); //console.log("Competences : ", competences);
for (let comp of competences) { for (let competence of competences) {
let compNameToSearch = RdDStatBlockParser.fixCompName(comp.name); let pushed = actorData.flags.type != "personnage"
let compMatch = XRegExp.exec(statString, XRegExp("\\s" + compNameToSearch + compParser[type], 'giu')); let compNameToSearch = RdDStatBlockParser.fixCompName(competence.name)
if (compMatch) { XRegExp.forEach(statString, XRegExp("\\s" + compNameToSearch + compParser[actorData.flags.type], 'giu'),
comp = comp.toObject() function (compMatch, i) {
comp.system.niveau = Number(compMatch.value) items.push(RdDStatBlockParser.prepareCompetence(actorData, competence, compMatch))
if (compMatch.malus) { if (!compMatch.special) {
comp.system.niveau = Number(compMatch.value) - actorData.flags.malusArmure pushed = true
}
if (comp.system.categorie == 'draconic' && comp.system.niveau > -11) {
actorData.flags.hautRevant = true
}
if (type == "creature" || type == "entite") {
comp.system.carac_value = Number(compMatch.carac);
if (compMatch.dommages != undefined) {
comp.system.dommages = Number(compMatch.dommages);
comp.system.iscombat = true;
} }
} })
items.push(comp); if (!pushed) {
// ajout niveau de base
items.push(competence.toObject())
} }
else if (type == "personnage") {
comp = comp.toObject(); }
items.push(comp); }
static prepareCompetence(actorData, competence, compMatch) {
const comp = competence.toObject();
if (compMatch.special) {
comp._id = undefined
comp.name = `${comp.name} (${compMatch.special})`
}
comp.system.niveau = Number(compMatch.value);
if (compMatch.malus) {
comp.system.niveau = Number(compMatch.value) - actorData.flags.malusArmure
}
if (comp.system.categorie == 'draconic' && comp.system.niveau > -11) {
actorData.flags.hautRevant = true
}
if (["creature", "entite"].includes(actorData.flags.type)) {
comp.system.carac_value = Number(compMatch.carac);
if (compMatch.dommages != undefined) {
comp.system.dommages = Number(compMatch.dommages)
comp.system.iscombat = true
} }
} }
return comp
} }
static async parseArmors(statString, actorData, items) { static async parseArmors(statString, actorData, items) {