import { Grammar } from "./grammar.js"; import { RdDUtility } from "./rdd-utility.js"; export class RdDCarac { static isAgiliteOuDerivee(selectedCarac) { return selectedCarac?.label.match(/(Agilité|Dérobée)/); } static isVolonte(selectedCarac) { return selectedCarac?.label == 'Volonté'; } static isChance(selectedCarac) { return selectedCarac?.label?.toLowerCase()?.match(/chance( actuelle)?/); } static isReve(selectedCarac) { return selectedCarac?.label?.toLowerCase()?.match(/r(e|ê)ve(( |-)actuel)?/); } static isIgnoreEtatGeneral(selectedCarac, competence) { return !selectedCarac || RdDCarac.isChance(selectedCarac) || (RdDCarac.isReve(selectedCarac) && !competence); } static computeTotal(carac, beaute=undefined) { const total = Object.values(carac).filter(c => !c.derivee) .map(it => parseInt(it.value)) .reduce((a, b) => a + b, 0); const beauteSuperieur10 = Math.max((beaute ?? 10) - 10, 0); return total + beauteSuperieur10; } static setLevelUp(carac) { Object.values(carac).forEach(it => { it.xpNext = RdDUtility.getCaracNextXp(it.value); it.isLevelUp = (it.xp >= it.xpNext); }); } /** * L’appel à la chance n’est possible que pour recommencer les jets d’actions physiques : * tous les jets de combat, de FORCE, d’AGILITÉ, de DEXTÉRITÉ, de Dérobée, d’APPARENCE, * ainsi que de Perception active et volontaire. */ static isActionPhysique(selectedCarac) { return Grammar.toLowerCaseNoAccent(selectedCarac?.label).match(/(apparence|force|agilite|dexterite|vue|ouie|odorat|empathie|melee|tir|lancer|derobee)/); } }