diff --git a/module/apps/rdd-import-stats.js b/module/apps/rdd-import-stats.js index b91c973b..b1a9f0be 100644 --- a/module/apps/rdd-import-stats.js +++ b/module/apps/rdd-import-stats.js @@ -33,16 +33,22 @@ const XREGEXP_WEAPON_MANIEMENT = "(?(" + Misc.join(Object.keys(MANIEM const XREGEXP_SORT_VOIE = "(?[OHNT](\\/[OHNT])*)" const XREGEXP_SORT_NAME = "(?[^\\(]+)" -const XREGEXP_SORT_CASE = "\\((?([A-Za-zÀ-ÖØ-öø-ÿ\\s\\-]+|[A-M]\\d{1,2})+)\\)"; +// const XREGEXP_SORT_CASE = "(?([A-Za-zÀ-ÖØ-öø-ÿ\\s\\-]+|[A-M]\\d{1,2})+)" +const XREGEXP_SORT_CASE = "(?([A-Za-zÀ-ÖØ-öø-ÿ\\s\\-]+|[A-M]\\d{1,2}))" const XREGEXP_SORT = "(" + XREGEXP_SORT_VOIE + WHITESPACES + XREGEXP_SORT_NAME - + WHITESPACES + XREGEXP_SORT_CASE + + WHITESPACES + "\\(" + XREGEXP_SORT_CASE + "\\)" + WHITESPACES + "R(?([\\-\\d]+|(\\w|\\s)+))" + WHITESPACES + "r(?(\\d+(\\+)?|\\s\\w+))" + "(" + WHITESPACES + "\\+(?\\d+)\\s?%" + WHITESPACES + "en" + WHITESPACES + "(?[A-M]\\d{1,2})" + ")?" + ")" +const XREGEXP_SORTRESERVE_CASE = "(?[A-M]\\d{1,2})"; + +const XREGEXP_SORT_RESERVE = XREGEXP_SORTRESERVE_CASE + + WHITESPACES + XREGEXP_SORT_NAME + + WHITESPACES + "(\\((?[^\\)]+)\\))?" // Main class for parsing a stat block export class RdDStatBlockParser { @@ -324,10 +330,10 @@ export class RdDStatBlockParser { XRegExp.forEach(statString, XRegExp(XREGEXP_SORT, 'gu' /* keep case sensitive to match the spell draconic skill */), function (matchSort, i) { + actorData.flags.hautRevant = true const sortName = Grammar.toLowerCaseNoAccent(matchSort.name).trim().replace("’", "'"); let sort = sorts.find(s => Grammar.toLowerCaseNoAccent(s.name) == sortName) if (sort) { - actorData.flags.hautRevant = true sort = sort.toObject(); if (matchSort.bonus && matchSort.bonuscase) { sort.system.bonuscase = `${matchSort.bonuscase}:${matchSort.bonus}`; @@ -337,7 +343,38 @@ export class RdDStatBlockParser { else { ui.notifications.warn(`Impossible de trouver le sort ${matchSort.name} / ${sortName}`) } - }); + }) + const sortsReserve = XRegExp.exec(statString, XRegExp('En réserve\\s+(?.*)', 'gu' /* keep case sensitive to match the spell draconic skill */)) + if (sortsReserve?.reserve) { + actorData.flags.hautRevant = true + XRegExp.forEach(sortsReserve.reserve, XRegExp(XREGEXP_SORT_RESERVE, 'giu'), + function (matchSortReserve, i) { + const name = Grammar.toLowerCaseNoAccent(matchSortReserve.name).trim().replace("’", "'"); + const sort = sorts.find(s => Grammar.toLowerCaseNoAccent(s.name) == name) + if (sort) { + if (!items.find(it => it._id == sort.id)) { + const nouveauSort = sort.toObject() + nouveauSort.system.bonuscase = `${matchSortReserve.coord}:1`; + items.push(sort.toObject()) + } + items.push({ + name: sort.name, + type: 'sortreserve', + img: sort.img, + system: { + sortid: sort.id, + draconic: sort.system.draconic, + coord: matchSortReserve.coord, + ptreve: Number(sort.system.ptreve.match(/\d+/)), + }, + description: matchSortReserve.description + }) + } + else { + ui.notifications.warn(`Impossible de mettre ${matchSortReserve.name} en réserve en ${matchSortReserve.coord}`) + } + }) + } if (actorData.flags.hautRevant) { const donHR = await RdDItemTete.teteDonDeHautReve();