import { Misc } from "../misc.js"; import { PART_APPELMORAL } from "./roll-part-appelmoral.mjs"; import { PART_COMP } from "./roll-part-comp.mjs"; import { RdDResolutionTable } from "../rdd-resolution-table.js"; import { ReglesOptionnelles } from "../settings/regles-optionnelles.js"; import { PART_OEUVRE } from "./roll-part-oeuvre.mjs"; import { RdDItemArme } from "../item/arme.js"; import { RdDBonus } from "../rdd-bonus.js"; /* -------------------------------------------- */ export class RollDialogAdapter { static async rollDice(rollData, rollTitle) { const chances = RollDialogAdapter.computeChances({ carac: rollData.current.carac.value, diff: rollData.current.totaldiff, bonus: rollData.current.bonus, sign: rollData.current.sign, showDice: rollData.options.showDice, rollMode: rollData.current.rollmode.key }) const rolled = await RollDialogAdapter.rollChances(rollData, chances) RollDialogAdapter.adjustRollDataForV1(rollData, rolled, rollTitle) return rolled } static computeChances({ carac, diff, bonus, sign, showDice, rollMode }) { const chances = foundry.utils.duplicate(RdDResolutionTable.computeChances(carac, diff)) RdDResolutionTable._updateChancesWithBonus(chances, bonus, diff) RdDResolutionTable._updateChancesFactor(chances, sign) chances.showDice = showDice chances.rollMode = rollMode return chances } static async rollChances(rollData, chances) { const rolled = await RdDResolutionTable.rollChances(chances, rollData.current.sign, rollData.current.resultat) rolled.caracValue = rollData.current.carac.value rolled.finalLevel = rollData.current.totaldiff rolled.bonus = rollData.current.bonus ?? 0 rolled.factorHtml = Misc.getFractionOneN(rollData.current.sign.diviseur) return rolled } static adjustRollDataForV1(rollData, rolled, rollTitle) { // temporaire pour être homogène roll v1 rollData.alias = rollData.active.actor.getAlias() // pour experience rollData.finalLevel = rollData.current.totaldiff if (rollData.use == undefined) { rollData.use = {} } if (rollData.show == undefined) { rollData.show = {} } if (rollData.ajustements == undefined) { rollData.ajustements = {} } rollData.selectedCarac = rollData.active.actor.system.carac[rollData.current.carac.key] const compKey = rollData.current.comp?.key if (compKey) { rollData.competence = rollData.refs[PART_COMP].all.find(it => it.key == compKey)?.comp rollData.jetResistance = rollData.type.jetResistance } const oeuvreKey = rollData.current.oeuvre?.key if (oeuvreKey) { const oeuvreCurrent = rollData.current[PART_OEUVRE]; rollData.oeuvre = oeuvreCurrent.oeuvre // rollData.oeuvre = rollData.refs[PART_OEUVRE].oeuvres.find(it => it.key == oeuvreKey)?.oeuvre rollData.art = oeuvreCurrent.art.type } // pour appel moral rollData.diviseurSignificative = rollData.current.sign if (rollData.current[PART_APPELMORAL]?.checked) { rollData.use.moral = true } rollData.rolled = rolled if (ReglesOptionnelles.isUsing("afficher-colonnes-reussite")) { rolled.niveauNecessaire = this.findNiveauNecessaire(carac, rolled.roll) rolled.ajustementNecessaire = rolled.niveauNecessaire - diff } rollData.ajustements = rollData.ajustements.map(aj => { return { used: true, label: aj.label, value: aj.diff, descr: aj.diff == undefined ? aj.label : undefined } }) rollData.show.title = rollTitle } static mapActionAttaque(attackerRoll) { if (attackerRoll.ids) { return attackerRoll.current[PART_ATTAQUE] } const label = attackerRoll.alias + ' ' + attackerRoll.arme.name; return { // correspond à l'attaque de RollPartAttaque (dans rollDta.current.attaque) label: label, attaque: { // correspond aux actions d'attaques dans RdDActor.listActionsAttaque name: label, // action: 'attaque', arme: attackerRoll.arme, comp: attackerRoll.competence, main: RdDItemArme.getMainAttaque(attackerRoll.competence), equipe: attackerRoll.arme.system.equipe, // carac: { key: caracCode, value: caracValue }, // dommagesArme: dommagesArme, }, diff: attackerRoll.diffLibre, particuliere: attackerRoll.particuliere, tactique: RdDBonus.find(attackerRoll.tactique), dmg: attackerRoll.dmg, } } }