diff --git a/module/actor.js b/module/actor.js index e97805d8..5cc15454 100644 --- a/module/actor.js +++ b/module/actor.js @@ -651,8 +651,7 @@ export class RdDActor extends Actor { } } else { - const roll = new Roll("1dr").evaluate(); - let deRecuperation = roll.total; + let deRecuperation = await RdDDice.rollTotal("1dr"); console.log("recuperationReve", deRecuperation); if (deRecuperation >= 7) { // Rêve de Dragon ! @@ -744,7 +743,7 @@ export class RdDActor extends Actor { // TODO: un dialogue pour demander le type de tête? rollData.tete = true; } - rollData.poesie = Poetique.getExtrait(); + rollData.poesie = await Poetique.getExtrait(); ChatMessage.create({ whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name), @@ -1089,7 +1088,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ computeIsHautRevant() { - if (this.isPersonnage()){ + if (this.isPersonnage()) { Misc.templateData(this).attributs.hautrevant.value = this.hasItemNamed('tete', 'don de haut-reve') ? "Haut rêvant" : ""; @@ -1191,7 +1190,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async ajouterRefoulement(value = 1) { let refoulement = Misc.templateData(this).reve.refoulement.value + value; - let total = new Roll("1d20").evaluate({ async: false }).total; + let total = await RdDDice.rollTotal("1d20"); if (total <= refoulement) { refoulement = 0; await this.ajouterSouffle({ chat: true }); @@ -1273,7 +1272,7 @@ export class RdDActor extends Actor { whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name) }); const innaccessible = this.buildTMRInnaccessible(); - let tmr = TMRUtility.getTMRAleatoire(tmr => !innaccessible.includes(tmr.coord)); + let tmr = await TMRUtility.getTMRAleatoire(tmr => !innaccessible.includes(tmr.coord)); this.updateCoordTMR(tmr.coord); this.cacheTMR(); return tmr; @@ -1402,25 +1401,6 @@ export class RdDActor extends Actor { return RdDCarac.calculSConst(Misc.templateData(this).carac.constitution.value); } - /* -------------------------------------------- */ - async testSiSonne(sante, endurance) { - const roll = new Roll("1d20").evaluate(); - roll.showDice = true; - RdDDice.show(roll); - let result = { - roll: roll, - sonne: roll.total > endurance || roll.total == 20 // 20 is always a failure - } - if (roll.total == 1) { - await this.ajoutXpConstitution(1); // +1 XP ! - ChatMessage.create({ content: `${this.name} a obenu 1 sur son Jet d'Endurance et a gagné 1 point d'Expérience en Constitution. Ce point d'XP a été ajouté automatiquement).` }); - } - if (result.sonne) { - await this.setSonne(); - sante.sonne.value = true; - } - return result; - } async ajoutXpConstitution(xp) { await this.update({ "data.carac.constitution.xp": Misc.toInt(Misc.templateData(this).carac.constitution.xp) + xp }); @@ -1435,48 +1415,71 @@ export class RdDActor extends Actor { return this.countBlessures(Misc.templateData(this).blessures[name].liste); } + + /* -------------------------------------------- */ + async testSiSonne(sante, endurance) { + const result = await this._jetEndurance(endurance); + if (result.roll.total == 1) { + ChatMessage.create({ content: await this._gainXpConstitutionJetEndurance() }); + } + sante.sonne.value ||= result.sonne; + return result; + } + /* -------------------------------------------- */ async jetEndurance() { - let myRoll = new Roll("1d20").roll(); - myRoll.showDice = true; - await RdDDice.show(myRoll); - const actorData = Misc.data(this); - let msgText = "Jet d'Endurance : " + myRoll.total + " / " + actorData.data.sante.endurance.value + "
"; - if (myRoll.total == 1 || (myRoll.total != 20 && myRoll.total <= actorData.data.sante.endurance.value)) { - msgText += `${this.name} a réussi son Jet d'Endurance !`; - if (myRoll.total == 1) { - await this.ajoutXpConstitution(); - msgText += `et gagne 1 Point d'Experience en Constitution`; - } - } else { - await this.setSonne(); - msgText += `${this.name} a échoué son Jet d'Endurance et devient Sonné`; - } + const endurance = actorData.data.sante.endurance.value; + + const result = await this._jetEndurance(actorData.data.sante.endurance.value) const message = { - content: msgText, + content: "Jet d'Endurance : " + result.roll.total + " / " + endurance + "
", whisper: ChatMessage.getWhisperRecipients(game.user.name) }; + if (result.sonne) { + message.content += `${this.name} a échoué son Jet d'Endurance et devient Sonné`; + } + else if (result.roll.total == 1) { + message.content += await this._gainXpConstitutionJetEndurance(); + } + else { + message.content += `${this.name} a réussi son Jet d'Endurance !`; + } + ChatMessage.create(message); } + async _gainXpConstitutionJetEndurance() { + await this.ajoutXpConstitution(1); // +1 XP ! + return `${this.name} a obtenu 1 sur son Jet d'Endurance et a gagné 1 point d'Expérience en Constitution. Ce point d'XP a été ajouté automatiquement.`; + } + + async _jetEndurance(endurance) { + const roll = await RdDDice.roll("1d20", { showDice: true }); + let result = { + roll: roll, + sonne: roll.total > endurance || roll.total == 20 // 20 is always a failure + } + if (result.sonne) { + await this.setSonne(); + } + return result; + } + /* -------------------------------------------- */ async jetVie() { - let myRoll = new Roll("1d20").roll(); - myRoll.showDice = true; - await RdDDice.show(myRoll); - + let roll = await RdDDice.roll("1d20", { showDice: true }); const actorData = Misc.data(this); - let msgText = "Jet de Vie : " + myRoll.total + " / " + actorData.data.sante.vie.value + "
"; - if (myRoll.total <= actorData.data.sante.vie.value) { + let msgText = "Jet de Vie : " + roll.total + " / " + actorData.data.sante.vie.value + "
"; + if (roll.total <= actorData.data.sante.vie.value) { msgText += "Jet réussi, pas de perte de point de vie (prochain jet dans 1 round pour 1 critique, SC minutes pour une grave)"; - if (myRoll.total == 1) { + if (roll.total == 1) { msgText += "La durée entre 2 jets de vie est multipliée par 20 (20 rounds pour une critique, SCx20 minutes pour une grave)"; } } else { msgText += "Jet échoué, vous perdez 1 point de vie"; await this.santeIncDec("vie", -1); - if (myRoll.total == 20) { + if (roll.total == 20) { msgText += "Votre personnage est mort !!!!!"; } } @@ -1589,8 +1592,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async jetDeMoral(situation, messageReussi = undefined, messageManque = undefined) { - let jetMoral = new Roll("1d20").roll(); - RdDDice.show(jetMoral); + let jetMoral = await RdDDice.roll("1d20", { showDice: true }); let moralActuel = Misc.toInt(Misc.templateData(this).compteurs.moral.value); const difficulte = 10 + moralActuel; const succes = jetMoral.total <= difficulte; @@ -1694,7 +1696,7 @@ export class RdDActor extends Actor { RdDResolutionTable.displayRollData(jetVieView, this, 'chat-resultat-ethylisme.html'); if (rollEthylisme.isEchec) { - let enduranceLostRoll = new Roll("1d6").roll(); + let enduranceLostRoll = await RdDDice.roll("1d6"); // enduranceLostRoll.showDice = true; RdDDice.show(enduranceLostRoll); let enduranceLost = enduranceLostRoll.total; @@ -2326,7 +2328,7 @@ export class RdDActor extends Actor { }); dialog.render(true); } - + /* -------------------------------------------- */ async _competenceResult(rollData) { RdDResolutionTable.displayRollData(rollData, this, 'chat-resultat-competence.html') @@ -2973,14 +2975,14 @@ export class RdDActor extends Actor { } /* -------------------------------------------- */ - computeArmure(attackerRoll) { + async computeArmure(attackerRoll) { let dmg = (attackerRoll.dmg.dmgArme ?? 0) + (attackerRoll.dmg.dmgActor ?? 0); let armeData = attackerRoll.arme; let protection = 0; const armures = this.items.map(it => Misc.data(it)) .filter(it => it.type == "armure" && it.data.equipe); for (const itemData of armures) { - protection += new Roll(itemData.data.protection.toString()).roll().total; + protection += await RdDDice.rollTotal(itemData.data.protection.toString()); if (dmg > 0) { this._deteriorerArmure(itemData, dmg); dmg = 0; @@ -3041,7 +3043,7 @@ export class RdDActor extends Actor { console.log("encaisserDommages", rollData) let santeOrig = duplicate(Misc.templateData(this).sante); - let encaissement = this.jetEncaissement(rollData); + let encaissement = await this.jetEncaissement(rollData); this.ajouterBlessure(encaissement); // Will upate the result table const perteVie = this.isEntiteCauchemar() @@ -3080,29 +3082,34 @@ export class RdDActor extends Actor { } /* -------------------------------------------- */ - jetEncaissement(rollData) { - const roll = new Roll("2d10").roll(); - roll.showDice = true; - RdDDice.show(roll, game.settings.get("core", "rollMode")); + async jetEncaissement(rollData) { + const roll = await RdDDice.roll("2d10", { showDice: true }); - const armure = this.computeArmure(rollData); + const armure = await this.computeArmure(rollData); const jetTotal = roll.total + rollData.dmg.total - armure; let encaissement = RdDUtility.selectEncaissement(jetTotal, rollData.dmg.mortalite) let over20 = Math.max(jetTotal - 20, 0); encaissement.dmg = rollData.dmg; - encaissement.dmg.loc = rollData.dmg.loc ?? RdDUtility.getLocalisation(this.data.type); + encaissement.dmg.loc = rollData.dmg.loc ?? await RdDUtility.getLocalisation(this.data.type); encaissement.dmg.loc.label = encaissement.dmg.loc.label ?? 'Corps;' encaissement.roll = roll; encaissement.armure = armure; encaissement.total = jetTotal; - encaissement.vie = RdDUtility._evaluatePerte(encaissement.vie, over20); - encaissement.endurance = RdDUtility._evaluatePerte(encaissement.endurance, over20); + encaissement.vie = await RdDActor._evaluatePerte(encaissement.vie, over20); + encaissement.endurance = await RdDActor._evaluatePerte(encaissement.endurance, over20); encaissement.penetration = rollData.arme?.data.penetration ?? 0; return encaissement; } + /* -------------------------------------------- */ + static async _evaluatePerte(formula, over20) { + let perte = new Roll(formula, { over20: over20 }); + await perte.evaluate({ async: true }); + return perte.total; + } + /* -------------------------------------------- */ ajouterBlessure(encaissement) { const actorData = Misc.data(this); @@ -3684,7 +3691,7 @@ export class RdDActor extends Actor { potionData.reussiteReve = true; potionData.aphasiePermanente = false; if (potionData.data.reposalchimique) { - let chanceAphasie = new Roll("1d100").evaluate({ async: false }).total; + let chanceAphasie = await RdDDice.rollTotal("1d100"); if (chanceAphasie <= potionData.data.pr) { potionData.aphasiePermanente = true; } diff --git a/module/item-signedraconique.js b/module/item-signedraconique.js index 10f0cfff..2cba4175 100644 --- a/module/item-signedraconique.js +++ b/module/item-signedraconique.js @@ -1,4 +1,5 @@ import { Misc } from "./misc.js"; +import { RdDDice } from "./rdd-dice.js"; import { RdDRollTables } from "./rdd-rolltables.js"; import { TMRType } from "./tmr-utility.js"; @@ -68,7 +69,7 @@ export class RdDItemSigneDraconique { } static async randomSigneDraconique() { - let modele = await Misc.rollOneOf(tableSignesIndicatifs); + let modele = await RdDDice.rollOneOf(tableSignesIndicatifs); return { name: await RdDItemSigneDraconique.randomSigneDescription(), type: "signedraconique", @@ -85,9 +86,9 @@ export class RdDItemSigneDraconique { static async randomTmrs(nbTmr = undefined) { let tmrs = Object.values(TMRType).map(value => Misc.upperFirst(value.name)); - let keep = nbTmr ?? (await new Roll("1d" + TMRType.length).evaluate().total + 1); + let keep = nbTmr ?? (await RdDDice.rollTotal("1d" + TMRType.length) + 1); for (let i = tmrs.length; i > keep; i--) { - tmrs.splice(await new Roll("1d" + i).evaluate().total, 1); + tmrs.splice(await RdDDice.rollTotal("1d" + i), 1); } return tmrs; } diff --git a/module/misc.js b/module/misc.js index 68269af3..09114a98 100644 --- a/module/misc.js +++ b/module/misc.js @@ -1,3 +1,4 @@ +import { RdDDice } from "./rdd-dice.js"; /** * This class is intended as a placeholder for utility methods unrelated @@ -22,13 +23,13 @@ export class Misc { return (a, b) => a + b; } - static ascending(orderFunction = x=>x) { + static ascending(orderFunction = x => x) { return (a, b) => Misc.sortingBy(orderFunction(a), orderFunction(b)); - } + } - static descending(orderFunction = x=>x) { + static descending(orderFunction = x => x) { return (a, b) => Misc.sortingBy(orderFunction(b), orderFunction(a)); - } + } static sortingBy(a, b) { if (a > b) return 1; @@ -49,7 +50,7 @@ export class Misc { } static keepDecimals(num, decimals) { - if (decimals<=0 || decimals>6) return num; + if (decimals <= 0 || decimals > 6) return num; const decimal = Math.pow(10, parseInt(decimals)); return Math.round(num * decimal) / decimal; } @@ -92,10 +93,6 @@ export class Misc { } } - static rollOneOf(array) { - return array[new Roll("1d" + array.length).evaluate({ async: false }).total - 1]; - } - static distinct(array) { return [...new Set(array)]; } @@ -112,7 +109,7 @@ export class Misc { } static connectedGMOrUser(ownerId = undefined) { - if (ownerId && game.user.id == ownerId){ + if (ownerId && game.user.id == ownerId) { return ownerId; } return (game.user.isGM ? game.user.id : game.users.entities.find(u => u.isGM && u.active)?.id) ?? game.user.id; diff --git a/module/poetique.js b/module/poetique.js index ec2e55b2..7edde996 100644 --- a/module/poetique.js +++ b/module/poetique.js @@ -1,4 +1,5 @@ import { Misc } from "./misc.js" +import { RdDDice } from "./rdd-dice.js"; const poesieHautReve = [ { @@ -64,8 +65,8 @@ const poesieHautReve = [ ] export class Poetique { - static getExtrait(){ - return Misc.rollOneOf(poesieHautReve); + static async getExtrait(){ + return await RdDDice.rollOneOf(poesieHautReve); } } \ No newline at end of file diff --git a/module/rdd-calendrier.js b/module/rdd-calendrier.js index bcb6cd0d..4c8ced8a 100644 --- a/module/rdd-calendrier.js +++ b/module/rdd-calendrier.js @@ -5,6 +5,8 @@ import { HtmlUtility } from "./html-utility.js"; import { RdDResolutionTable } from "./rdd-resolution-table.js"; import { RdDUtility } from "./rdd-utility.js"; import { Grammar } from "./grammar.js"; +import { Misc } from "./misc.js"; +import {RdDDice } from "./rdd-dice.js"; /* -------------------------------------------- */ const dossierIconesHeures = 'systems/foundryvtt-reve-de-dragon/icons/heures/' @@ -124,9 +126,9 @@ export class RdDCalendrier extends Application { } /* -------------------------------------------- */ - ajouterNombreAstral(index) { + async ajouterNombreAstral(index) { return { - nombreAstral: new Roll("1d12").evaluate( {async:false} ).total, + nombreAstral: await RdDDice.rollTotal("1dh"), valeursFausses: [], index: index } @@ -278,11 +280,10 @@ export class RdDCalendrier extends Application { request.isValid = true; if (!request.rolled.isSuccess) { request.isValid = false; - let nbAstralFaux = new Roll("1d11").evaluate( { async: false} ).total; - nbAstral = nbAstral==nbAstralFaux ? 12 : nbAstralFaux; + nbAstral = await RdDDice.rollTotal("1dhr"+nbAstral); // Mise à jour des nombres astraux du joueur let astralData = this.listeNombreAstral.find((nombreAstral, i) => nombreAstral.index == request.date); - astralData.valeursFausses.push({ actorId: request.id, nombreAstral: nbAstralFaux }); + astralData.valeursFausses.push({ actorId: request.id, nombreAstral: nbAstral }); game.settings.set("foundryvtt-reve-de-dragon", "liste-nombre-astral", this.listeNombreAstral); } request.nbAstral = nbAstral; diff --git a/module/rdd-commands.js b/module/rdd-commands.js index 5d858288..f7d5bb4c 100644 --- a/module/rdd-commands.js +++ b/module/rdd-commands.js @@ -283,16 +283,14 @@ export class RdDCommands { /* -------------------------------------------- */ async rollDeDraconique(msg) { - let ddr = new Roll("1dr + 7").evaluate(); - ddr.showDice = true; - await RdDDice.showDiceSoNice(ddr); - RdDCommands._chatAnswer(msg, `Lancer d'un Dé draconique: ${ddr.total}`); + let ddr = await RdDDice.rollTotal("1dr + 7", { showDice:true }); + RdDCommands._chatAnswer(msg, `Lancer d'un Dé draconique: ${ddr}`); } - getTMRAleatoire(msg, params) { + async getTMRAleatoire(msg, params) { if (params.length < 2) { let type = params[0]; - const tmr = TMRUtility.getTMRAleatoire(type ? (it => it.type == type) : (it => true)); + const tmr = await TMRUtility.getTMRAleatoire(type ? (it => it.type == type) : (it => true)); RdDCommands._chatAnswer(msg, `Case aléatoire: ${tmr.coord} - ${tmr.label}`); } else { diff --git a/module/rdd-dice.js b/module/rdd-dice.js index 4a9d42fb..27ee6c3e 100644 --- a/module/rdd-dice.js +++ b/module/rdd-dice.js @@ -25,7 +25,7 @@ export class De7 extends Die { return { type: "d7", font: "HeuresDraconiques", - fontScale : 0.7, + fontScale: 0.7, labels: ['1', '2', '3', '4', '5', '6', 'd', '0'], system: system } @@ -36,7 +36,7 @@ export class De7 extends Die { super(termData); } - evaluate() { + async evaluate() { super.evaluate(); this.explode("x=8"); return this; @@ -62,7 +62,7 @@ export class DeDraconique extends Die { return { type: "dr", font: "HeuresDraconiques", - fontScale : 0.7, + fontScale: 0.7, labels: ['1', '2', '3', '4', '5', '6', 'd', '0'], system: system } @@ -73,7 +73,7 @@ export class DeDraconique extends Die { super(termData); } - evaluate() { + async evaluate() { super.evaluate(); this.explode("x=7"); return this; @@ -113,7 +113,7 @@ export class DeHeure extends Die { } static getResultLabel(result) { - return img(imagesHeures[result-1]); + return img(imagesHeures[result - 1]); } } @@ -124,6 +124,27 @@ export class RdDDice { CONFIG.Dice.terms[DeHeure.DENOMINATION] = DeHeure; } + static async roll(formula, options = { showDice: false }) { + const roll = new Roll(formula); + await roll.evaluate({ async: true }); + if (options.showDice) { + roll.showDice = options.showDice; + } + await RdDDice.show(roll, game.settings.get("core", "rollMode")); + return roll; + } + + static async rollTotal(formula) { + const roll = new Roll(formula); + await roll.evaluate({ async: true }); + return roll.total; + } + + static async rollOneOf(array) { + const roll = await RdDDice.rollTotal(`1d${array.length}`); + return array[roll-1]; + } + static diceSoNiceReady(dice3d) { for (const system of Object.keys(dice3d.DiceFactory.systems)) { dice3d.addDicePreset(De7.diceSoNiceData(system)); diff --git a/module/rdd-namegen.js b/module/rdd-namegen.js index a5e6d05c..cdea6579 100644 --- a/module/rdd-namegen.js +++ b/module/rdd-namegen.js @@ -1,5 +1,5 @@ -import { Grammar } from "./grammar.js"; import { Misc } from "./misc.js"; +import { RdDDice } from "./rdd-dice.js"; const words = [ 'pore', 'pre', 'flor', 'lane', 'turlu', 'pin', 'a', 'alph', 'i', 'onse', 'iane', 'ane', 'zach', 'arri', 'ba', 'bo', 'bi', 'alta', 'par', 'pir', 'zor', 'zir', 'de', 'pol', 'tran', 'no', 'la','al' , 'pul', 'one', 'ner', 'nur' ]; @@ -7,8 +7,8 @@ const words = [ 'pore', 'pre', 'flor', 'lane', 'turlu', 'pin', 'a', 'alph', 'i', /* -------------------------------------------- */ export class RdDNameGen { - static getName( msg, params ) { - let name = Misc.upperFirst( Misc.rollOneOf(words) + Misc.rollOneOf(words) ) + static async getName( msg, params ) { + let name = Misc.upperFirst( await RdDDice.rollOneOf(words) + await RdDDice.rollOneOf(words) ) //console.log(name); ChatMessage.create( { content: `Nom : ${name}`, whisper: ChatMessage.getWhisperRecipients("GM") } ); } diff --git a/module/rdd-resolution-table.js b/module/rdd-resolution-table.js index 23a6e2c8..c128668a 100644 --- a/module/rdd-resolution-table.js +++ b/module/rdd-resolution-table.js @@ -149,10 +149,7 @@ export class RdDResolutionTable { /* -------------------------------------------- */ static async rollChances(chances, diviseur) { - let myRoll = new Roll("1d100").evaluate( {async: false} ); - myRoll.showDice = chances.showDice; - await RdDDice.show(myRoll); - chances.roll = myRoll.total; + chances.roll = await RdDDice.rollTotal("1d100", {showDice:chances.showDice}); mergeObject(chances, this.computeReussite(chances, chances.roll, diviseur), { overwrite: true }); return chances; } diff --git a/module/rdd-tmr-dialog.js b/module/rdd-tmr-dialog.js index af19ef43..f761d3a4 100644 --- a/module/rdd-tmr-dialog.js +++ b/module/rdd-tmr-dialog.js @@ -13,6 +13,7 @@ import { Draconique } from "./tmr/draconique.js"; import { Misc } from "./misc.js"; import { HtmlUtility } from "./html-utility.js"; import { ReglesOptionelles } from "./regles-optionelles.js"; +import { RdDDice } from "./rdd-dice.js"; /* -------------------------------------------- */ export class RdDTMRDialog extends Dialog { @@ -535,7 +536,7 @@ export class RdDTMRDialog extends Dialog { if (rencontre) { return rencontre; } - let myRoll = new Roll("1d7").evaluate({ async: false }).total; + let myRoll = await RdDDice.rollTotal("1d7"); if (TMRUtility.isForceRencontre() || myRoll == 7) { return await this.rencontreTMRRoll(tmr, this.actor.isRencontreSpeciale()); } @@ -596,7 +597,7 @@ export class RdDTMRDialog extends Dialog { await this._rollMaitriseCaseHumide(rollData); return; } - rollData.poesie = Poetique.getExtrait(); + rollData.poesie = await Poetique.getExtrait(); ChatMessage.create({ whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name), content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-resultat-maitrise-tmr.html`, rollData) @@ -713,7 +714,7 @@ export class RdDTMRDialog extends Dialog { } this.toclose = rollData.rolled.isEchec; - rollData.poesie = Poetique.getExtrait(); + rollData.poesie = await Poetique.getExtrait(); ChatMessage.create({ whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name), content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-resultat-maitrise-tmr.html`, rollData) diff --git a/module/rdd-utility.js b/module/rdd-utility.js index ba46ca35..4011417d 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -7,6 +7,7 @@ import { Grammar } from "./grammar.js"; import { TMRUtility } from "./tmr-utility.js"; import { DialogItemAchat } from "./dialog-item-achat.js"; import { ReglesOptionelles } from "./regles-optionelles.js"; +import { RdDDice } from "./rdd-dice.js"; /* -------------------------------------------- */ // This table starts at 0 -> niveau -10 @@ -444,8 +445,8 @@ export class RdDUtility { } /* -------------------------------------------- */ - static getLocalisation(type = 'personnage') { - let result = new Roll("1d20").roll().total; + static async getLocalisation(type = 'personnage') { + let result = await RdDDice.rollTotal("1d20"); let txt = "" if (type == 'personnage') { if (result <= 3) txt = "Jambe, genou, pied, jarret"; @@ -477,15 +478,6 @@ export class RdDUtility { return duplicate(table[0]); } - - /* -------------------------------------------- */ - static _evaluatePerte(formula, over20) { - console.log("_evaluatePerte", formula, over20); - let perte = new Roll(formula, { over20: over20 }); - perte.evaluate(); - return perte.total; - } - /* -------------------------------------------- */ static currentFatigueMalus(value, max) { if (ReglesOptionelles.isUsing("appliquer-fatigue")) { diff --git a/module/tmr-rencontres.js b/module/tmr-rencontres.js index 4c03dd19..eea11c27 100644 --- a/module/tmr-rencontres.js +++ b/module/tmr-rencontres.js @@ -1,5 +1,6 @@ import { Grammar } from "./grammar.js"; import { Misc } from "./misc.js"; +import { RdDDice } from "./rdd-dice.js"; import { TMRUtility } from "./tmr-utility.js"; import { TMRType } from "./tmr-utility.js"; @@ -268,7 +269,7 @@ const rencontresStandard = [ { code: "reflet", name: "Reflet d'ancien Rêve", type: "reflet", genre: "m", force: "2d6", isPersistant: true }, { code: "tbblanc", name: "Tourbillon blanc", type: "tbblanc", genre: "m", force: "2d6", isPersistant: true }, { code: "tbnoir", name: "Tourbillon noir", type: "tbnoir", genre: "m", force: "2d8", isPersistant: true }, - { code: "rdd", name: "Rêve de Dragon", type: "rdd", genre: "m", force: "1ddr + 7", refoulement: 2, quitterTMR: true } + { code: "rdd", name: "Rêve de Dragon", type: "rdd", genre: "m", force: "1dr + 7", refoulement: 2, quitterTMR: true } ]; const rencontresPresentCite = [ @@ -324,7 +325,7 @@ export class TMRRencontres { return false; } if (!roll || roll <= 0 || roll > 100) { - roll = new Roll("1d100").evaluate().total; + roll = await RdDDice.rollTotal("1d100"); } let rencontre = await TMRRencontres.getRencontreAleatoire(terrain, roll); ChatMessage.create({ @@ -356,15 +357,13 @@ export class TMRRencontres { /* -------------------------------------------- */ static async getRencontreAleatoire(terrain, roll = undefined) { if (!roll || roll <= 0 || roll > 100) { - roll = new Roll("1d100").evaluate({ async: false }).total; + roll = await RdDDice.rollTotal("1d100"); } terrain = Grammar.toLowerCaseNoAccent(terrain); - //console.log("getRencontreAleatoire", terrain, roll); const code = tableRencontres[terrain].find(it => it.range[0] <= roll && roll <= it.range[1]).code; const rencontre = duplicate(rencontresStandard.find(it => it.code == code)); rencontre.roll = roll; await TMRRencontres.evaluerForceRencontre(rencontre); - //console.log(rencontre); return rencontre; } @@ -373,20 +372,14 @@ export class TMRRencontres { const rencontre = duplicate( (index && index >= 0 && index < mauvaisesRencontres.length) ? mauvaisesRencontres[index] - : Misc.rollOneOf(mauvaisesRencontres)); + : await RdDDice.rollOneOf(mauvaisesRencontres)); await TMRRencontres.evaluerForceRencontre(rencontre); return rencontre; } /* -------------------------------------------- */ static async evaluerForceRencontre(rencontre) { - if (TMRRencontres.isReveDeDragon(rencontre)) { - const ddr = new Roll("1dr + 7").evaluate(); - rencontre.force = 7 + ddr.total; - } - else { - rencontre.force = new Roll(rencontre.force).evaluate({ async: false }).total; - } + rencontre.force = await new Roll(rencontre.force).evaluate().total; return rencontre.force; } @@ -426,14 +419,14 @@ export class TMRRencontres { } /* -------------------------------------------- */ - static msgEchecPasseurFou(tmrData) { + static async msgEchecPasseurFou(tmrData) { tmrData.sortReserve = Misc.templateData(tmrData.actor).reve.reserve.list[0]; if (tmrData.sortReserve) { // Passeur fou positionne sur la case d'un ort en réserve // TODO : Choisir le sort le plus loin ou au hasard tmrData.newTMR = TMRUtility.getTMR(tmrData.sortReserve.coord); } else { // Déplacement aléatoire de la force du Passeur Fou - const newCoord = Misc.rollOneOf(TMRUtility.getTMRPortee(tmrData.tmr.coord, tmrData.rencontre.force)); + const newCoord = await RdDDice.rollOneOf(TMRUtility.getTMRPortee(tmrData.tmr.coord, tmrData.rencontre.force)); tmrData.newTMR = TMRUtility.getTMR(newCoord); } if (tmrData.sortReserve) { @@ -472,7 +465,7 @@ export class TMRRencontres { static async _toubillonner(tmrDialog, actor, cases) { let coord = Misc.templateData(actor).reve.tmrpos.coord; for (let i = 0; i < cases; i++) { - coord = TMRUtility.deplaceTMRAleatoire(actor, coord).coord; + coord = await TMRUtility.deplaceTMRAleatoire(actor, coord).coord; } await tmrDialog.forceDemiRevePosition(coord) } diff --git a/module/tmr-utility.js b/module/tmr-utility.js index 94bbbfc0..d7a397fc 100644 --- a/module/tmr-utility.js +++ b/module/tmr-utility.js @@ -1,6 +1,7 @@ import { TMRRencontres } from "./tmr-rencontres.js"; import { Misc } from "./misc.js"; import { Grammar } from "./grammar.js"; +import { RdDDice } from "./rdd-dice.js"; /* -------------------------------------------- */ const TMRMapping = { @@ -386,13 +387,13 @@ export class TMRUtility { } /* -------------------------------------------- */ - static getDirectionPattern() { - return Misc.rollOneOf(tmrRandomMovePatten); + static async getDirectionPattern() { + return await RdDDice.rollOneOf(tmrRandomMovePatten); } /* -------------------------------------------- */ - static deplaceTMRAleatoire(actor, coord) { - return TMRUtility.deplaceTMRSelonPattern(actor, coord, TMRUtility.getDirectionPattern(), 1); + static async deplaceTMRAleatoire(actor, coord) { + return TMRUtility.deplaceTMRSelonPattern(actor, coord, await TMRUtility.getDirectionPattern(), 1); } /* -------------------------------------------- */ @@ -424,8 +425,8 @@ export class TMRUtility { return TMRUtility.filterTMR(filter).map(it => it.coord); } - static getTMRAleatoire(filter = it => true) { - return Misc.rollOneOf(TMRUtility.filterTMR(filter)) + static async getTMRAleatoire(filter = it => true) { + return await RdDDice.rollOneOf(TMRUtility.filterTMR(filter)) } /* -------------------------------------------- */ diff --git a/module/tmr/conquete.js b/module/tmr/conquete.js index b1cf1862..b8c0ac53 100644 --- a/module/tmr/conquete.js +++ b/module/tmr/conquete.js @@ -1,5 +1,6 @@ import { Grammar } from "../grammar.js"; import { Misc } from "../misc.js"; +import { RdDDice } from "../rdd-dice.js"; import { tmrColors, tmrConstants, tmrTokenZIndex, TMRUtility } from "../tmr-utility.js"; import { Draconique } from "./draconique.js"; @@ -31,7 +32,7 @@ export class Conquete extends Draconique { async _creerConquete(actor, queue) { let existants = actor.data.items.filter(it => this.isCase(it)).map(it => Misc.data(it).data.coord); let possibles = TMRUtility.filterTMR(tmr => !TMRUtility.isCaseHumide(tmr) && !existants.includes(tmr.coord)); - let conquete = Misc.rollOneOf(possibles); + let conquete =await RdDDice.rollOneOf(possibles); await this.createCaseTmr(actor, 'Conquête: ' + conquete.label, conquete, queue.id); } diff --git a/module/tmr/debordement.js b/module/tmr/debordement.js index 0aa9feb2..a9b3a998 100644 --- a/module/tmr/debordement.js +++ b/module/tmr/debordement.js @@ -13,7 +13,7 @@ export class Debordement extends Draconique { manualMessage() { return false } async onActorCreateOwned(actor, souffle) { const existants = actor.data.items.filter(it => this.isCase(it)).map(it => it.data.coord); - const tmr = TMRUtility.getTMRAleatoire(it => !(TMRUtility.isCaseHumide(it) || existants.includes(it.coord))); + const tmr = await TMRUtility.getTMRAleatoire(it => !(TMRUtility.isCaseHumide(it) || existants.includes(it.coord))); await this.createCaseTmr(actor, 'Debordement: ' + tmr.label, tmr, souffle.id); } diff --git a/module/tmr/desorientation.js b/module/tmr/desorientation.js index 0fc1d46c..e1fc7855 100644 --- a/module/tmr/desorientation.js +++ b/module/tmr/desorientation.js @@ -1,5 +1,6 @@ import { Grammar } from "../grammar.js"; import { Misc } from "../misc.js"; +import { RdDDice } from "../rdd-dice.js"; import { tmrColors, tmrConstants, tmrTokenZIndex, TMRType, TMRUtility } from "../tmr-utility.js"; import { Draconique } from "./draconique.js"; @@ -13,7 +14,7 @@ export class Desorientation extends Draconique { manualMessage() { return false } async onActorCreateOwned(actor, souffle) { - const type = Misc.rollOneOf(this._typesPossibles(actor)); + const type = await RdDDice.rollOneOf(this._typesPossibles(actor)); console.log("désorientation", type); souffle.name += ": " + TMRType[type].name; await this._creerCasesTmr(actor, type, souffle); diff --git a/module/tmr/pelerinage.js b/module/tmr/pelerinage.js index d30c10b6..a8cdea37 100644 --- a/module/tmr/pelerinage.js +++ b/module/tmr/pelerinage.js @@ -13,7 +13,7 @@ export class Pelerinage extends Draconique { manualMessage() { return false } async onActorCreateOwned(actor, queue) { - let tmr = TMRUtility.getTMRAleatoire(); + let tmr = await TMRUtility.getTMRAleatoire(); await this.createCaseTmr(actor, 'Pèlerinage: ' + tmr.label, tmr, queue.id); } diff --git a/module/tmr/periple.js b/module/tmr/periple.js index e33aad91..9ad0d83f 100644 --- a/module/tmr/periple.js +++ b/module/tmr/periple.js @@ -1,5 +1,6 @@ import { Grammar } from "../grammar.js"; -import { tmrColors, tmrConstants, tmrTokenZIndex, TMRUtility } from "../tmr-utility.js"; +import { RdDDice } from "../rdd-dice.js"; +import { tmrConstants, tmrTokenZIndex, TMRUtility } from "../tmr-utility.js"; import { Draconique } from "./draconique.js"; export class Periple extends Draconique { @@ -13,7 +14,7 @@ export class Periple extends Draconique { manualMessage() { return false } async onActorCreateOwned(actor, souffle) { - let terrain = new Roll("1d2").evaluate().total == 1 ? 'sanctuaire' : 'necropole'; + let terrain = (await RdDDice.rollTotal("1d2")) == 1 ? 'sanctuaire' : 'necropole'; let tmrs = TMRUtility.getListTMR(terrain); for (let tmr of tmrs) { await this.createCaseTmr(actor, 'Périple: ' + tmr.label, tmr, souffle.id); diff --git a/module/tmr/reserve-extensible.js b/module/tmr/reserve-extensible.js index d28bc239..35ba770c 100644 --- a/module/tmr/reserve-extensible.js +++ b/module/tmr/reserve-extensible.js @@ -12,7 +12,7 @@ export class ReserveExtensible extends Draconique { manualMessage() { return "Vous pouvez re-configurer votre Réserve extensible" } async onActorCreateOwned(actor, tete) { const existants = actor.data.items.filter(it => this.isCase(it)).map(it => it.data.coord); - const tmr = TMRUtility.getTMRAleatoire(it => !(it.type == 'fleuve' || existants.includes(it.coord))); + const tmr = await TMRUtility.getTMRAleatoire(it => !(it.type == 'fleuve' || existants.includes(it.coord))); await this.createCaseTmr(actor, "Nouvelle Réserve extensible", tmr, tete.id); } diff --git a/module/tmr/trou-noir.js b/module/tmr/trou-noir.js index 95a09e04..454746be 100644 --- a/module/tmr/trou-noir.js +++ b/module/tmr/trou-noir.js @@ -13,7 +13,7 @@ export class TrouNoir extends Draconique { async onActorCreateOwned(actor, souffle) { const existants = actor.data.items.filter(it => this.isCase(it)).map(it => it.data.coord); - const tmr = TMRUtility.getTMRAleatoire(it => !(TMRUtility.isCaseHumide(it) || existants.includes(it.coord))); + const tmr = await TMRUtility.getTMRAleatoire(it => !(TMRUtility.isCaseHumide(it) || existants.includes(it.coord))); await this.createCaseTmr(actor, 'Trou noir: ' + tmr.label, tmr, souffle.id); }