Foundry: Roll#evaluate sera async

This commit is contained in:
Vincent Vandemeulebrouck 2021-05-11 21:45:43 +02:00
parent d1ac4b3d59
commit f87efee2fe
20 changed files with 160 additions and 147 deletions

View File

@ -651,8 +651,7 @@ export class RdDActor extends Actor {
} }
} }
else { else {
const roll = new Roll("1dr").evaluate(); let deRecuperation = await RdDDice.rollTotal("1dr");
let deRecuperation = roll.total;
console.log("recuperationReve", deRecuperation); console.log("recuperationReve", deRecuperation);
if (deRecuperation >= 7) { if (deRecuperation >= 7) {
// Rêve de Dragon ! // Rêve de Dragon !
@ -744,7 +743,7 @@ export class RdDActor extends Actor {
// TODO: un dialogue pour demander le type de tête? // TODO: un dialogue pour demander le type de tête?
rollData.tete = true; rollData.tete = true;
} }
rollData.poesie = Poetique.getExtrait(); rollData.poesie = await Poetique.getExtrait();
ChatMessage.create({ ChatMessage.create({
whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name), whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name),
@ -1089,7 +1088,7 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */ /* -------------------------------------------- */
computeIsHautRevant() { computeIsHautRevant() {
if (this.isPersonnage()){ if (this.isPersonnage()) {
Misc.templateData(this).attributs.hautrevant.value = this.hasItemNamed('tete', 'don de haut-reve') Misc.templateData(this).attributs.hautrevant.value = this.hasItemNamed('tete', 'don de haut-reve')
? "Haut rêvant" ? "Haut rêvant"
: ""; : "";
@ -1191,7 +1190,7 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */ /* -------------------------------------------- */
async ajouterRefoulement(value = 1) { async ajouterRefoulement(value = 1) {
let refoulement = Misc.templateData(this).reve.refoulement.value + value; 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) { if (total <= refoulement) {
refoulement = 0; refoulement = 0;
await this.ajouterSouffle({ chat: true }); await this.ajouterSouffle({ chat: true });
@ -1273,7 +1272,7 @@ export class RdDActor extends Actor {
whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name) whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name)
}); });
const innaccessible = this.buildTMRInnaccessible(); 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.updateCoordTMR(tmr.coord);
this.cacheTMR(); this.cacheTMR();
return tmr; return tmr;
@ -1402,25 +1401,6 @@ export class RdDActor extends Actor {
return RdDCarac.calculSConst(Misc.templateData(this).carac.constitution.value); 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) { async ajoutXpConstitution(xp) {
await this.update({ "data.carac.constitution.xp": Misc.toInt(Misc.templateData(this).carac.constitution.xp) + 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); 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() { async jetEndurance() {
let myRoll = new Roll("1d20").roll();
myRoll.showDice = true;
await RdDDice.show(myRoll);
const actorData = Misc.data(this); const actorData = Misc.data(this);
let msgText = "Jet d'Endurance : " + myRoll.total + " / " + actorData.data.sante.endurance.value + "<br>"; const endurance = 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 !`; const result = await this._jetEndurance(actorData.data.sante.endurance.value)
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 message = { const message = {
content: msgText, content: "Jet d'Endurance : " + result.roll.total + " / " + endurance + "<br>",
whisper: ChatMessage.getWhisperRecipients(game.user.name) 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); 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() { async jetVie() {
let myRoll = new Roll("1d20").roll(); let roll = await RdDDice.roll("1d20", { showDice: true });
myRoll.showDice = true;
await RdDDice.show(myRoll);
const actorData = Misc.data(this); const actorData = Misc.data(this);
let msgText = "Jet de Vie : " + myRoll.total + " / " + actorData.data.sante.vie.value + "<br>"; let msgText = "Jet de Vie : " + roll.total + " / " + actorData.data.sante.vie.value + "<br>";
if (myRoll.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)"; 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)"; 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 { } else {
msgText += "Jet échoué, vous perdez 1 point de vie"; msgText += "Jet échoué, vous perdez 1 point de vie";
await this.santeIncDec("vie", -1); await this.santeIncDec("vie", -1);
if (myRoll.total == 20) { if (roll.total == 20) {
msgText += "Votre personnage est mort !!!!!"; msgText += "Votre personnage est mort !!!!!";
} }
} }
@ -1589,8 +1592,7 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */ /* -------------------------------------------- */
async jetDeMoral(situation, messageReussi = undefined, messageManque = undefined) { async jetDeMoral(situation, messageReussi = undefined, messageManque = undefined) {
let jetMoral = new Roll("1d20").roll(); let jetMoral = await RdDDice.roll("1d20", { showDice: true });
RdDDice.show(jetMoral);
let moralActuel = Misc.toInt(Misc.templateData(this).compteurs.moral.value); let moralActuel = Misc.toInt(Misc.templateData(this).compteurs.moral.value);
const difficulte = 10 + moralActuel; const difficulte = 10 + moralActuel;
const succes = jetMoral.total <= difficulte; const succes = jetMoral.total <= difficulte;
@ -1694,7 +1696,7 @@ export class RdDActor extends Actor {
RdDResolutionTable.displayRollData(jetVieView, this, 'chat-resultat-ethylisme.html'); RdDResolutionTable.displayRollData(jetVieView, this, 'chat-resultat-ethylisme.html');
if (rollEthylisme.isEchec) { if (rollEthylisme.isEchec) {
let enduranceLostRoll = new Roll("1d6").roll(); let enduranceLostRoll = await RdDDice.roll("1d6");
// enduranceLostRoll.showDice = true; // enduranceLostRoll.showDice = true;
RdDDice.show(enduranceLostRoll); RdDDice.show(enduranceLostRoll);
let enduranceLost = enduranceLostRoll.total; let enduranceLost = enduranceLostRoll.total;
@ -2326,7 +2328,7 @@ export class RdDActor extends Actor {
}); });
dialog.render(true); dialog.render(true);
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
async _competenceResult(rollData) { async _competenceResult(rollData) {
RdDResolutionTable.displayRollData(rollData, this, 'chat-resultat-competence.html') 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 dmg = (attackerRoll.dmg.dmgArme ?? 0) + (attackerRoll.dmg.dmgActor ?? 0);
let armeData = attackerRoll.arme; let armeData = attackerRoll.arme;
let protection = 0; let protection = 0;
const armures = this.items.map(it => Misc.data(it)) const armures = this.items.map(it => Misc.data(it))
.filter(it => it.type == "armure" && it.data.equipe); .filter(it => it.type == "armure" && it.data.equipe);
for (const itemData of armures) { 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) { if (dmg > 0) {
this._deteriorerArmure(itemData, dmg); this._deteriorerArmure(itemData, dmg);
dmg = 0; dmg = 0;
@ -3041,7 +3043,7 @@ export class RdDActor extends Actor {
console.log("encaisserDommages", rollData) console.log("encaisserDommages", rollData)
let santeOrig = duplicate(Misc.templateData(this).sante); 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 this.ajouterBlessure(encaissement); // Will upate the result table
const perteVie = this.isEntiteCauchemar() const perteVie = this.isEntiteCauchemar()
@ -3080,29 +3082,34 @@ export class RdDActor extends Actor {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
jetEncaissement(rollData) { async jetEncaissement(rollData) {
const roll = new Roll("2d10").roll(); const roll = await RdDDice.roll("2d10", { showDice: true });
roll.showDice = true;
RdDDice.show(roll, game.settings.get("core", "rollMode"));
const armure = this.computeArmure(rollData); const armure = await this.computeArmure(rollData);
const jetTotal = roll.total + rollData.dmg.total - armure; const jetTotal = roll.total + rollData.dmg.total - armure;
let encaissement = RdDUtility.selectEncaissement(jetTotal, rollData.dmg.mortalite) let encaissement = RdDUtility.selectEncaissement(jetTotal, rollData.dmg.mortalite)
let over20 = Math.max(jetTotal - 20, 0); let over20 = Math.max(jetTotal - 20, 0);
encaissement.dmg = rollData.dmg; 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.dmg.loc.label = encaissement.dmg.loc.label ?? 'Corps;'
encaissement.roll = roll; encaissement.roll = roll;
encaissement.armure = armure; encaissement.armure = armure;
encaissement.total = jetTotal; encaissement.total = jetTotal;
encaissement.vie = RdDUtility._evaluatePerte(encaissement.vie, over20); encaissement.vie = await RdDActor._evaluatePerte(encaissement.vie, over20);
encaissement.endurance = RdDUtility._evaluatePerte(encaissement.endurance, over20); encaissement.endurance = await RdDActor._evaluatePerte(encaissement.endurance, over20);
encaissement.penetration = rollData.arme?.data.penetration ?? 0; encaissement.penetration = rollData.arme?.data.penetration ?? 0;
return encaissement; return encaissement;
} }
/* -------------------------------------------- */
static async _evaluatePerte(formula, over20) {
let perte = new Roll(formula, { over20: over20 });
await perte.evaluate({ async: true });
return perte.total;
}
/* -------------------------------------------- */ /* -------------------------------------------- */
ajouterBlessure(encaissement) { ajouterBlessure(encaissement) {
const actorData = Misc.data(this); const actorData = Misc.data(this);
@ -3684,7 +3691,7 @@ export class RdDActor extends Actor {
potionData.reussiteReve = true; potionData.reussiteReve = true;
potionData.aphasiePermanente = false; potionData.aphasiePermanente = false;
if (potionData.data.reposalchimique) { if (potionData.data.reposalchimique) {
let chanceAphasie = new Roll("1d100").evaluate({ async: false }).total; let chanceAphasie = await RdDDice.rollTotal("1d100");
if (chanceAphasie <= potionData.data.pr) { if (chanceAphasie <= potionData.data.pr) {
potionData.aphasiePermanente = true; potionData.aphasiePermanente = true;
} }

View File

@ -1,4 +1,5 @@
import { Misc } from "./misc.js"; import { Misc } from "./misc.js";
import { RdDDice } from "./rdd-dice.js";
import { RdDRollTables } from "./rdd-rolltables.js"; import { RdDRollTables } from "./rdd-rolltables.js";
import { TMRType } from "./tmr-utility.js"; import { TMRType } from "./tmr-utility.js";
@ -68,7 +69,7 @@ export class RdDItemSigneDraconique {
} }
static async randomSigneDraconique() { static async randomSigneDraconique() {
let modele = await Misc.rollOneOf(tableSignesIndicatifs); let modele = await RdDDice.rollOneOf(tableSignesIndicatifs);
return { return {
name: await RdDItemSigneDraconique.randomSigneDescription(), name: await RdDItemSigneDraconique.randomSigneDescription(),
type: "signedraconique", type: "signedraconique",
@ -85,9 +86,9 @@ export class RdDItemSigneDraconique {
static async randomTmrs(nbTmr = undefined) { static async randomTmrs(nbTmr = undefined) {
let tmrs = Object.values(TMRType).map(value => Misc.upperFirst(value.name)); 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--) { 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; return tmrs;
} }

View File

@ -1,3 +1,4 @@
import { RdDDice } from "./rdd-dice.js";
/** /**
* This class is intended as a placeholder for utility methods unrelated * This class is intended as a placeholder for utility methods unrelated
@ -22,13 +23,13 @@ export class Misc {
return (a, b) => a + b; return (a, b) => a + b;
} }
static ascending(orderFunction = x=>x) { static ascending(orderFunction = x => x) {
return (a, b) => Misc.sortingBy(orderFunction(a), orderFunction(b)); 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)); return (a, b) => Misc.sortingBy(orderFunction(b), orderFunction(a));
} }
static sortingBy(a, b) { static sortingBy(a, b) {
if (a > b) return 1; if (a > b) return 1;
@ -49,7 +50,7 @@ export class Misc {
} }
static keepDecimals(num, decimals) { 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)); const decimal = Math.pow(10, parseInt(decimals));
return Math.round(num * decimal) / decimal; 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) { static distinct(array) {
return [...new Set(array)]; return [...new Set(array)];
} }
@ -112,7 +109,7 @@ export class Misc {
} }
static connectedGMOrUser(ownerId = undefined) { static connectedGMOrUser(ownerId = undefined) {
if (ownerId && game.user.id == ownerId){ if (ownerId && game.user.id == ownerId) {
return ownerId; return ownerId;
} }
return (game.user.isGM ? game.user.id : game.users.entities.find(u => u.isGM && u.active)?.id) ?? game.user.id; return (game.user.isGM ? game.user.id : game.users.entities.find(u => u.isGM && u.active)?.id) ?? game.user.id;

View File

@ -1,4 +1,5 @@
import { Misc } from "./misc.js" import { Misc } from "./misc.js"
import { RdDDice } from "./rdd-dice.js";
const poesieHautReve = [ const poesieHautReve = [
{ {
@ -64,8 +65,8 @@ const poesieHautReve = [
] ]
export class Poetique { export class Poetique {
static getExtrait(){ static async getExtrait(){
return Misc.rollOneOf(poesieHautReve); return await RdDDice.rollOneOf(poesieHautReve);
} }
} }

View File

@ -5,6 +5,8 @@ import { HtmlUtility } from "./html-utility.js";
import { RdDResolutionTable } from "./rdd-resolution-table.js"; import { RdDResolutionTable } from "./rdd-resolution-table.js";
import { RdDUtility } from "./rdd-utility.js"; import { RdDUtility } from "./rdd-utility.js";
import { Grammar } from "./grammar.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/' const dossierIconesHeures = 'systems/foundryvtt-reve-de-dragon/icons/heures/'
@ -124,9 +126,9 @@ export class RdDCalendrier extends Application {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
ajouterNombreAstral(index) { async ajouterNombreAstral(index) {
return { return {
nombreAstral: new Roll("1d12").evaluate( {async:false} ).total, nombreAstral: await RdDDice.rollTotal("1dh"),
valeursFausses: [], valeursFausses: [],
index: index index: index
} }
@ -278,11 +280,10 @@ export class RdDCalendrier extends Application {
request.isValid = true; request.isValid = true;
if (!request.rolled.isSuccess) { if (!request.rolled.isSuccess) {
request.isValid = false; request.isValid = false;
let nbAstralFaux = new Roll("1d11").evaluate( { async: false} ).total; nbAstral = await RdDDice.rollTotal("1dhr"+nbAstral);
nbAstral = nbAstral==nbAstralFaux ? 12 : nbAstralFaux;
// Mise à jour des nombres astraux du joueur // Mise à jour des nombres astraux du joueur
let astralData = this.listeNombreAstral.find((nombreAstral, i) => nombreAstral.index == request.date); 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); game.settings.set("foundryvtt-reve-de-dragon", "liste-nombre-astral", this.listeNombreAstral);
} }
request.nbAstral = nbAstral; request.nbAstral = nbAstral;

View File

@ -283,16 +283,14 @@ export class RdDCommands {
/* -------------------------------------------- */ /* -------------------------------------------- */
async rollDeDraconique(msg) { async rollDeDraconique(msg) {
let ddr = new Roll("1dr + 7").evaluate(); let ddr = await RdDDice.rollTotal("1dr + 7", { showDice:true });
ddr.showDice = true; RdDCommands._chatAnswer(msg, `Lancer d'un Dé draconique: ${ddr}`);
await RdDDice.showDiceSoNice(ddr);
RdDCommands._chatAnswer(msg, `Lancer d'un Dé draconique: ${ddr.total}`);
} }
getTMRAleatoire(msg, params) { async getTMRAleatoire(msg, params) {
if (params.length < 2) { if (params.length < 2) {
let type = params[0]; 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}`); RdDCommands._chatAnswer(msg, `Case aléatoire: ${tmr.coord} - ${tmr.label}`);
} }
else { else {

View File

@ -25,7 +25,7 @@ export class De7 extends Die {
return { return {
type: "d7", type: "d7",
font: "HeuresDraconiques", font: "HeuresDraconiques",
fontScale : 0.7, fontScale: 0.7,
labels: ['1', '2', '3', '4', '5', '6', 'd', '0'], labels: ['1', '2', '3', '4', '5', '6', 'd', '0'],
system: system system: system
} }
@ -36,7 +36,7 @@ export class De7 extends Die {
super(termData); super(termData);
} }
evaluate() { async evaluate() {
super.evaluate(); super.evaluate();
this.explode("x=8"); this.explode("x=8");
return this; return this;
@ -62,7 +62,7 @@ export class DeDraconique extends Die {
return { return {
type: "dr", type: "dr",
font: "HeuresDraconiques", font: "HeuresDraconiques",
fontScale : 0.7, fontScale: 0.7,
labels: ['1', '2', '3', '4', '5', '6', 'd', '0'], labels: ['1', '2', '3', '4', '5', '6', 'd', '0'],
system: system system: system
} }
@ -73,7 +73,7 @@ export class DeDraconique extends Die {
super(termData); super(termData);
} }
evaluate() { async evaluate() {
super.evaluate(); super.evaluate();
this.explode("x=7"); this.explode("x=7");
return this; return this;
@ -113,7 +113,7 @@ export class DeHeure extends Die {
} }
static getResultLabel(result) { 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; 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) { static diceSoNiceReady(dice3d) {
for (const system of Object.keys(dice3d.DiceFactory.systems)) { for (const system of Object.keys(dice3d.DiceFactory.systems)) {
dice3d.addDicePreset(De7.diceSoNiceData(system)); dice3d.addDicePreset(De7.diceSoNiceData(system));

View File

@ -1,5 +1,5 @@
import { Grammar } from "./grammar.js";
import { Misc } from "./misc.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', 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' ]; '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 { export class RdDNameGen {
static getName( msg, params ) { static async getName( msg, params ) {
let name = Misc.upperFirst( Misc.rollOneOf(words) + Misc.rollOneOf(words) ) let name = Misc.upperFirst( await RdDDice.rollOneOf(words) + await RdDDice.rollOneOf(words) )
//console.log(name); //console.log(name);
ChatMessage.create( { content: `Nom : ${name}`, whisper: ChatMessage.getWhisperRecipients("GM") } ); ChatMessage.create( { content: `Nom : ${name}`, whisper: ChatMessage.getWhisperRecipients("GM") } );
} }

View File

@ -149,10 +149,7 @@ export class RdDResolutionTable {
/* -------------------------------------------- */ /* -------------------------------------------- */
static async rollChances(chances, diviseur) { static async rollChances(chances, diviseur) {
let myRoll = new Roll("1d100").evaluate( {async: false} ); chances.roll = await RdDDice.rollTotal("1d100", {showDice:chances.showDice});
myRoll.showDice = chances.showDice;
await RdDDice.show(myRoll);
chances.roll = myRoll.total;
mergeObject(chances, this.computeReussite(chances, chances.roll, diviseur), { overwrite: true }); mergeObject(chances, this.computeReussite(chances, chances.roll, diviseur), { overwrite: true });
return chances; return chances;
} }

View File

@ -13,6 +13,7 @@ import { Draconique } from "./tmr/draconique.js";
import { Misc } from "./misc.js"; import { Misc } from "./misc.js";
import { HtmlUtility } from "./html-utility.js"; import { HtmlUtility } from "./html-utility.js";
import { ReglesOptionelles } from "./regles-optionelles.js"; import { ReglesOptionelles } from "./regles-optionelles.js";
import { RdDDice } from "./rdd-dice.js";
/* -------------------------------------------- */ /* -------------------------------------------- */
export class RdDTMRDialog extends Dialog { export class RdDTMRDialog extends Dialog {
@ -535,7 +536,7 @@ export class RdDTMRDialog extends Dialog {
if (rencontre) { if (rencontre) {
return rencontre; return rencontre;
} }
let myRoll = new Roll("1d7").evaluate({ async: false }).total; let myRoll = await RdDDice.rollTotal("1d7");
if (TMRUtility.isForceRencontre() || myRoll == 7) { if (TMRUtility.isForceRencontre() || myRoll == 7) {
return await this.rencontreTMRRoll(tmr, this.actor.isRencontreSpeciale()); return await this.rencontreTMRRoll(tmr, this.actor.isRencontreSpeciale());
} }
@ -596,7 +597,7 @@ export class RdDTMRDialog extends Dialog {
await this._rollMaitriseCaseHumide(rollData); await this._rollMaitriseCaseHumide(rollData);
return; return;
} }
rollData.poesie = Poetique.getExtrait(); rollData.poesie = await Poetique.getExtrait();
ChatMessage.create({ ChatMessage.create({
whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name), whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name),
content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-resultat-maitrise-tmr.html`, rollData) 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; this.toclose = rollData.rolled.isEchec;
rollData.poesie = Poetique.getExtrait(); rollData.poesie = await Poetique.getExtrait();
ChatMessage.create({ ChatMessage.create({
whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name), whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name),
content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-resultat-maitrise-tmr.html`, rollData) content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-resultat-maitrise-tmr.html`, rollData)

View File

@ -7,6 +7,7 @@ import { Grammar } from "./grammar.js";
import { TMRUtility } from "./tmr-utility.js"; import { TMRUtility } from "./tmr-utility.js";
import { DialogItemAchat } from "./dialog-item-achat.js"; import { DialogItemAchat } from "./dialog-item-achat.js";
import { ReglesOptionelles } from "./regles-optionelles.js"; import { ReglesOptionelles } from "./regles-optionelles.js";
import { RdDDice } from "./rdd-dice.js";
/* -------------------------------------------- */ /* -------------------------------------------- */
// This table starts at 0 -> niveau -10 // This table starts at 0 -> niveau -10
@ -444,8 +445,8 @@ export class RdDUtility {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
static getLocalisation(type = 'personnage') { static async getLocalisation(type = 'personnage') {
let result = new Roll("1d20").roll().total; let result = await RdDDice.rollTotal("1d20");
let txt = "" let txt = ""
if (type == 'personnage') { if (type == 'personnage') {
if (result <= 3) txt = "Jambe, genou, pied, jarret"; if (result <= 3) txt = "Jambe, genou, pied, jarret";
@ -477,15 +478,6 @@ export class RdDUtility {
return duplicate(table[0]); 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) { static currentFatigueMalus(value, max) {
if (ReglesOptionelles.isUsing("appliquer-fatigue")) { if (ReglesOptionelles.isUsing("appliquer-fatigue")) {

View File

@ -1,5 +1,6 @@
import { Grammar } from "./grammar.js"; import { Grammar } from "./grammar.js";
import { Misc } from "./misc.js"; import { Misc } from "./misc.js";
import { RdDDice } from "./rdd-dice.js";
import { TMRUtility } from "./tmr-utility.js"; import { TMRUtility } from "./tmr-utility.js";
import { TMRType } 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: "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: "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: "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 = [ const rencontresPresentCite = [
@ -324,7 +325,7 @@ export class TMRRencontres {
return false; return false;
} }
if (!roll || roll <= 0 || roll > 100) { if (!roll || roll <= 0 || roll > 100) {
roll = new Roll("1d100").evaluate().total; roll = await RdDDice.rollTotal("1d100");
} }
let rencontre = await TMRRencontres.getRencontreAleatoire(terrain, roll); let rencontre = await TMRRencontres.getRencontreAleatoire(terrain, roll);
ChatMessage.create({ ChatMessage.create({
@ -356,15 +357,13 @@ export class TMRRencontres {
/* -------------------------------------------- */ /* -------------------------------------------- */
static async getRencontreAleatoire(terrain, roll = undefined) { static async getRencontreAleatoire(terrain, roll = undefined) {
if (!roll || roll <= 0 || roll > 100) { if (!roll || roll <= 0 || roll > 100) {
roll = new Roll("1d100").evaluate({ async: false }).total; roll = await RdDDice.rollTotal("1d100");
} }
terrain = Grammar.toLowerCaseNoAccent(terrain); 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 code = tableRencontres[terrain].find(it => it.range[0] <= roll && roll <= it.range[1]).code;
const rencontre = duplicate(rencontresStandard.find(it => it.code == code)); const rencontre = duplicate(rencontresStandard.find(it => it.code == code));
rencontre.roll = roll; rencontre.roll = roll;
await TMRRencontres.evaluerForceRencontre(rencontre); await TMRRencontres.evaluerForceRencontre(rencontre);
//console.log(rencontre);
return rencontre; return rencontre;
} }
@ -373,20 +372,14 @@ export class TMRRencontres {
const rencontre = duplicate( const rencontre = duplicate(
(index && index >= 0 && index < mauvaisesRencontres.length) (index && index >= 0 && index < mauvaisesRencontres.length)
? mauvaisesRencontres[index] ? mauvaisesRencontres[index]
: Misc.rollOneOf(mauvaisesRencontres)); : await RdDDice.rollOneOf(mauvaisesRencontres));
await TMRRencontres.evaluerForceRencontre(rencontre); await TMRRencontres.evaluerForceRencontre(rencontre);
return rencontre; return rencontre;
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
static async evaluerForceRencontre(rencontre) { static async evaluerForceRencontre(rencontre) {
if (TMRRencontres.isReveDeDragon(rencontre)) { rencontre.force = await new Roll(rencontre.force).evaluate().total;
const ddr = new Roll("1dr + 7").evaluate();
rencontre.force = 7 + ddr.total;
}
else {
rencontre.force = new Roll(rencontre.force).evaluate({ async: false }).total;
}
return rencontre.force; 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]; tmrData.sortReserve = Misc.templateData(tmrData.actor).reve.reserve.list[0];
if (tmrData.sortReserve) { 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 // 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); tmrData.newTMR = TMRUtility.getTMR(tmrData.sortReserve.coord);
} else { } else {
// Déplacement aléatoire de la force du Passeur Fou // 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); tmrData.newTMR = TMRUtility.getTMR(newCoord);
} }
if (tmrData.sortReserve) { if (tmrData.sortReserve) {
@ -472,7 +465,7 @@ export class TMRRencontres {
static async _toubillonner(tmrDialog, actor, cases) { static async _toubillonner(tmrDialog, actor, cases) {
let coord = Misc.templateData(actor).reve.tmrpos.coord; let coord = Misc.templateData(actor).reve.tmrpos.coord;
for (let i = 0; i < cases; i++) { for (let i = 0; i < cases; i++) {
coord = TMRUtility.deplaceTMRAleatoire(actor, coord).coord; coord = await TMRUtility.deplaceTMRAleatoire(actor, coord).coord;
} }
await tmrDialog.forceDemiRevePosition(coord) await tmrDialog.forceDemiRevePosition(coord)
} }

View File

@ -1,6 +1,7 @@
import { TMRRencontres } from "./tmr-rencontres.js"; import { TMRRencontres } from "./tmr-rencontres.js";
import { Misc } from "./misc.js"; import { Misc } from "./misc.js";
import { Grammar } from "./grammar.js"; import { Grammar } from "./grammar.js";
import { RdDDice } from "./rdd-dice.js";
/* -------------------------------------------- */ /* -------------------------------------------- */
const TMRMapping = { const TMRMapping = {
@ -386,13 +387,13 @@ export class TMRUtility {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
static getDirectionPattern() { static async getDirectionPattern() {
return Misc.rollOneOf(tmrRandomMovePatten); return await RdDDice.rollOneOf(tmrRandomMovePatten);
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
static deplaceTMRAleatoire(actor, coord) { static async deplaceTMRAleatoire(actor, coord) {
return TMRUtility.deplaceTMRSelonPattern(actor, coord, TMRUtility.getDirectionPattern(), 1); return TMRUtility.deplaceTMRSelonPattern(actor, coord, await TMRUtility.getDirectionPattern(), 1);
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
@ -424,8 +425,8 @@ export class TMRUtility {
return TMRUtility.filterTMR(filter).map(it => it.coord); return TMRUtility.filterTMR(filter).map(it => it.coord);
} }
static getTMRAleatoire(filter = it => true) { static async getTMRAleatoire(filter = it => true) {
return Misc.rollOneOf(TMRUtility.filterTMR(filter)) return await RdDDice.rollOneOf(TMRUtility.filterTMR(filter))
} }
/* -------------------------------------------- */ /* -------------------------------------------- */

View File

@ -1,5 +1,6 @@
import { Grammar } from "../grammar.js"; import { Grammar } from "../grammar.js";
import { Misc } from "../misc.js"; import { Misc } from "../misc.js";
import { RdDDice } from "../rdd-dice.js";
import { tmrColors, tmrConstants, tmrTokenZIndex, TMRUtility } from "../tmr-utility.js"; import { tmrColors, tmrConstants, tmrTokenZIndex, TMRUtility } from "../tmr-utility.js";
import { Draconique } from "./draconique.js"; import { Draconique } from "./draconique.js";
@ -31,7 +32,7 @@ export class Conquete extends Draconique {
async _creerConquete(actor, queue) { async _creerConquete(actor, queue) {
let existants = actor.data.items.filter(it => this.isCase(it)).map(it => Misc.data(it).data.coord); 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 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); await this.createCaseTmr(actor, 'Conquête: ' + conquete.label, conquete, queue.id);
} }

View File

@ -13,7 +13,7 @@ export class Debordement extends Draconique {
manualMessage() { return false } manualMessage() { return false }
async onActorCreateOwned(actor, souffle) { async onActorCreateOwned(actor, souffle) {
const existants = actor.data.items.filter(it => this.isCase(it)).map(it => it.data.coord); 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); await this.createCaseTmr(actor, 'Debordement: ' + tmr.label, tmr, souffle.id);
} }

View File

@ -1,5 +1,6 @@
import { Grammar } from "../grammar.js"; import { Grammar } from "../grammar.js";
import { Misc } from "../misc.js"; import { Misc } from "../misc.js";
import { RdDDice } from "../rdd-dice.js";
import { tmrColors, tmrConstants, tmrTokenZIndex, TMRType, TMRUtility } from "../tmr-utility.js"; import { tmrColors, tmrConstants, tmrTokenZIndex, TMRType, TMRUtility } from "../tmr-utility.js";
import { Draconique } from "./draconique.js"; import { Draconique } from "./draconique.js";
@ -13,7 +14,7 @@ export class Desorientation extends Draconique {
manualMessage() { return false } manualMessage() { return false }
async onActorCreateOwned(actor, souffle) { async onActorCreateOwned(actor, souffle) {
const type = Misc.rollOneOf(this._typesPossibles(actor)); const type = await RdDDice.rollOneOf(this._typesPossibles(actor));
console.log("désorientation", type); console.log("désorientation", type);
souffle.name += ": " + TMRType[type].name; souffle.name += ": " + TMRType[type].name;
await this._creerCasesTmr(actor, type, souffle); await this._creerCasesTmr(actor, type, souffle);

View File

@ -13,7 +13,7 @@ export class Pelerinage extends Draconique {
manualMessage() { return false } manualMessage() { return false }
async onActorCreateOwned(actor, queue) { async onActorCreateOwned(actor, queue) {
let tmr = TMRUtility.getTMRAleatoire(); let tmr = await TMRUtility.getTMRAleatoire();
await this.createCaseTmr(actor, 'Pèlerinage: ' + tmr.label, tmr, queue.id); await this.createCaseTmr(actor, 'Pèlerinage: ' + tmr.label, tmr, queue.id);
} }

View File

@ -1,5 +1,6 @@
import { Grammar } from "../grammar.js"; 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"; import { Draconique } from "./draconique.js";
export class Periple extends Draconique { export class Periple extends Draconique {
@ -13,7 +14,7 @@ export class Periple extends Draconique {
manualMessage() { return false } manualMessage() { return false }
async onActorCreateOwned(actor, souffle) { 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); let tmrs = TMRUtility.getListTMR(terrain);
for (let tmr of tmrs) { for (let tmr of tmrs) {
await this.createCaseTmr(actor, 'Périple: ' + tmr.label, tmr, souffle.id); await this.createCaseTmr(actor, 'Périple: ' + tmr.label, tmr, souffle.id);

View File

@ -12,7 +12,7 @@ export class ReserveExtensible extends Draconique {
manualMessage() { return "Vous pouvez re-configurer votre Réserve extensible" } manualMessage() { return "Vous pouvez re-configurer votre Réserve extensible" }
async onActorCreateOwned(actor, tete) { async onActorCreateOwned(actor, tete) {
const existants = actor.data.items.filter(it => this.isCase(it)).map(it => it.data.coord); 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); await this.createCaseTmr(actor, "Nouvelle Réserve extensible", tmr, tete.id);
} }

View File

@ -13,7 +13,7 @@ export class TrouNoir extends Draconique {
async onActorCreateOwned(actor, souffle) { async onActorCreateOwned(actor, souffle) {
const existants = actor.data.items.filter(it => this.isCase(it)).map(it => it.data.coord); 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); await this.createCaseTmr(actor, 'Trou noir: ' + tmr.label, tmr, souffle.id);
} }