Correction async pas utiles

This commit is contained in:
Vincent Vandemeulebrouck 2020-11-17 11:35:05 +01:00
parent 803b340ad0
commit fbe70e42ea
6 changed files with 69 additions and 56 deletions

View File

@ -122,7 +122,7 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */ /* -------------------------------------------- */
async performRoll(rollData) { async performRoll(rollData) {
let rolled = await RdDResolutionTable.roll(rollData.carac, rollData.finalLevel, true); let rolled = RdDResolutionTable.roll(rollData.carac, rollData.finalLevel);
//rolled.isPart = true; // Pour tester le particulières //rolled.isPart = true; // Pour tester le particulières
rollData.rolled = rolled; // garder le résultat rollData.rolled = rolled; // garder le résultat
console.log("performRoll", rollData, rolled) console.log("performRoll", rollData, rolled)
@ -363,24 +363,23 @@ export class RdDActor extends Actor {
ChatMessage.create( message ); ChatMessage.create( message );
} }
async combattreReveDeDragon(force){ combattreReveDeDragon(force){
let draconic = this.getBestDraconic(); let draconic = this.getBestDraconic();
let niveau = Math.max(0, draconic.data.niveau); let niveau = Math.max(0, draconic.data.niveau);
let etat = this.data.data.compteurs.etat.value; let etat = this.data.data.compteurs.etat.value;
let difficulte = niveau - etat - force; let difficulte = niveau - etat - force;
let reveActuel = this.getReveActuel(); let reveActuel = this.getReveActuel();
let roll = await RdDResolutionTable.roll(reveActuel, difficulte); let rolled = RdDResolutionTable.roll(reveActuel, difficulte);
let message = "" consome.log("combattreReveDeDragon", rolled );
const resultatRdD = await this.appliquerReveDeDragon(roll, force); return this.appliquerReveDeDragon(rolled, force);
return resultatRdD;
} }
async appliquerReveDeDragon(roll, force) { appliquerReveDeDragon(roll, force) {
let message = ""; let message = "";
if (roll.isSuccess) { if (roll.isSuccess) {
message += "<br>Vous gagnez " + force + " points de Rêve"; message += "<br>Vous gagnez " + force + " points de Rêve";
this.updatePointDeSeuil(); this.updatePointDeSeuil();
await this.updatePointsDeReve(force); this.updatePointsDeReve(force);
} }
if (roll.isPart) { if (roll.isPart) {
// TODO: Dialog pour choix entre HR opu général? // TODO: Dialog pour choix entre HR opu général?
@ -716,9 +715,9 @@ export class RdDActor extends Actor {
if ( data.value < 0 ) data.value = 0; if ( data.value < 0 ) data.value = 0;
if (name == "endurance" && this.data.type != 'entite' ) { if (name == "endurance" && this.data.type != 'entite' ) {
if ( sante.fatigue && inc < 0 ) // Each endurance lost -> fatigue lost if ( sante.fatigue && inc < 0 ) { // Each endurance lost -> fatigue lost
sante.fatigue.value = sante.fatigue.value - inc sante.fatigue.value = sante.fatigue.value - inc
}
// If endurance is 0 -> -1 vie // If endurance is 0 -> -1 vie
if ( data.value == 0 && sante.vie.value > 0) { if ( data.value == 0 && sante.vie.value > 0) {
sante.vie.value = sante.vie.value - 1; sante.vie.value = sante.vie.value - 1;
@ -829,9 +828,7 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */ /* -------------------------------------------- */
async stressTest() { async stressTest() {
let target = RdDResolutionTable.computeChances(this.data.data.carac.reve.value, 0); let stressRoll = this._stressRoll();
let stressRoll = this._stressRoll(target);
let compteurs = duplicate(this.data.data.compteurs); let compteurs = duplicate(this.data.data.compteurs);
let convertion = Math.floor(compteurs.stress.value * stressRoll.factor); let convertion = Math.floor(compteurs.stress.value * stressRoll.factor);
@ -839,28 +836,33 @@ export class RdDActor extends Actor {
compteurs.stress.value = Math.max(compteurs.stress.value - convertion - 1, 0); compteurs.stress.value = Math.max(compteurs.stress.value - convertion - 1, 0);
ChatMessage.create({ ChatMessage.create({
title: "Jet de Stress", content: "Vous avez transformé " + convertion + " points de Stress en Expérience avec une réussite " + stressRoll.comment, title: "Jet de Stress", content: "Vous avez transformé " + convertion + " points de Stress en Expérience" + stressRoll.comment,
whisper: ChatMessage.getWhisperRecipients(game.user.name) whisper: ChatMessage.getWhisperRecipients(game.user.name)
}); });
await this.update({ "data.compteurs": compteurs }); await this.update({ "data.compteurs": compteurs });
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
async _stressRoll(target) { _stressRoll() {
let result = await RdDResolutionTable.rollChances(target) let result = RdDResolutionTable.roll(this.data.data.carac.reve.value, 0);
switch (result.quality) { console.log("_stressRoll", result);
case "sign": return { factor: 0.75, comment: "Significative (75%) - " + result.roll } switch (result.code) {
case "norm": return { factor: 0.5, comment: "Normale (50%) - " + result.roll } case "sign": return { factor: 0.75, comment: " (75%): " + result.quality + " - " + result.roll + " sur " + result.score + "%" }
case "echec": return { factor: 0.2, comment: "Echec (20%) - " + result.roll } case "norm": return { factor: 0.5, comment: " (50%): " + result.quality + " - " + result.roll + " sur " + result.score + "%" }
case "epart": return { factor: 0.1, comment: "Echec particulier(10%) - " + result.roll } case "echec": return { factor: 0.2, comment: " (20%): " + result.quality + " - " + result.roll + " sur " + result.score + "%" }
case "etotal": return { factor: 0, comment: "Echec Total (0%) - " + result.roll } case "epart": return { factor: 0.1, comment: " (10%): " + result.quality + " - " + result.roll + " sur " + result.score + "%" }
} case "etotal": return { factor: 0, comment: " (0%): " + result.quality + " - " + result.roll + " sur " + result.score + "%" }
let second = await RdDResolutionTable.rollChances(target) case "part":
switch (second.quality) { {
let second = RdDResolutionTable.roll(this.data.data.carac.reve.value, 0);
console.log("_stressRoll", second);
switch (second.code) {
case "part": case "sign": case "part": case "sign":
return { factor: 1.5, comment: "Double Particulière (150%) - " + result.roll + " puis " + second.roll } return { factor: 1.5, comment: " (150%): Double Particulière - " + result.roll + " puis " + second.roll + " sur " + result.score + "%" }
default: default:
return { factor: 1, comment: "Particulière (100%) - " + result.roll + " puis " + second.roll } return { factor: 1, comment: " (150%): " + result.quality + " - " + result.roll + " puis " + second.roll + " sur " + result.score + "%" }
}
}
} }
} }

View File

@ -1,13 +1,16 @@
export class RdDDice { export class RdDDice {
static async deDraconique() { static deDraconique(rollMode="selfroll") {
let roll = new Roll("1d8x8").evaluate(); let roll = new Roll("1d8x8").evaluate();
await this.show(roll); this.show(roll, rollMode);
return roll.total - Math.ceil(roll.total / 8); return roll.total - Math.ceil(roll.total / 8);
} }
static async show(roll, rollMode = "roll") {
await this.showDiceSoNice(roll, rollMode); static show(roll, rollMode = "roll") {
if (roll.showDice || game.settings.get("foundryvtt-reve-de-dragon", "dice-so-nice") == true) {
this.showDiceSoNice(roll, rollMode);
}
return roll; return roll;
} }

View File

@ -103,11 +103,19 @@ Hooks.once("init", async function() {
rollDataHandler: {} rollDataHandler: {}
} }
// Create specific settings // Create specific settings
game.settings.register("foundryvtt-reve-de-dragon", "configuration", { // game.settings.register("foundryvtt-reve-de-dragon", "configuration", {
name: "configuration", // name: "configuration",
scope: "world", // scope: "world",
config: false, // config: false,
type: Object // type: Object
// });
game.settings.register("foundryvtt-reve-de-dragon", "dice-so-nice", {
name: "Montrer les dés pour toutes les jets",
hint: "Utilise Dice So Nice pour tous les jets de dés possibles. Décocher pour limiter à la table de résolution",
scope: "client",
config: true,
default: false,
type: Boolean
}); });
//game.settings.get("<systemName>","<settingName>") to retrieve it and game.settings.set("<systemName>","<settingName>", <newValue>) //game.settings.get("<systemName>","<settingName>") to retrieve it and game.settings.set("<systemName>","<settingName>", <newValue>)

View File

@ -85,21 +85,20 @@ export class RdDResolutionTable {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
static async roll(carac, finalLevel, showDice=false) { static roll(carac, finalLevel) {
let chances = this.computeChances(carac, finalLevel); let chances = this.computeChances(carac, finalLevel);
chances.showDice = showDice; chances.showDice = true;
let rolled = await this.rollChances(chances); let rolled = this.rollChances(chances);
rolled.carac = carac; rolled.carac = carac;
rolled.finalLevel = finalLevel; rolled.finalLevel = finalLevel;
return rolled; return rolled;
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
static async rollChances(chances) { static rollChances(chances) {
let myRoll = new Roll("d100").roll(); let myRoll = new Roll("d100").roll();
if (chances.showDice) { myRoll.showDice = chances.showDice;
await RdDDice.showDiceSoNice(myRoll); RdDDice.show(myRoll);
}
chances.roll = myRoll.total; chances.roll = myRoll.total;
mergeObject(chances, this._computeReussite(chances, chances.roll)); mergeObject(chances, this._computeReussite(chances, chances.roll));
return chances; return chances;

View File

@ -137,9 +137,8 @@ export class RdDTMRDialog extends Dialog {
} }
this.currentRencontre = undefined; this.currentRencontre = undefined;
let rencontre = this.rencontresExistantes.find(prev => prev.coord == coordTMR); let rencontre = this.rencontresExistantes.find(prev => prev.coord == coordTMR);
let deRencontre = new Roll("d7").roll();
console.log("manageRencontre", deRencontre, rencontre);
if (rencontre == undefined) { if (rencontre == undefined) {
let deRencontre = new Roll("d7").roll();
if (deRencontre.total == 7) { if (deRencontre.total == 7) {
rencontre = await TMRUtility.rencontreTMRRoll(coordTMR, cellDescr); rencontre = await TMRUtility.rencontreTMRRoll(coordTMR, cellDescr);
} }

View File

@ -271,7 +271,7 @@ export class TMRUtility {
let rencontre = this.rencontreTMRTypeCase(cellDescr.type); let rencontre = this.rencontreTMRTypeCase(cellDescr.type);
if (rencontre){ if (rencontre){
rencontre = duplicate(rencontre); rencontre = duplicate(rencontre);
rencontre.force = await this.evaluerForceRencontre(rencontre); rencontre.force = this.evaluerForceRencontre(rencontre);
rencontre.coord = coordTMR; rencontre.coord = coordTMR;
} }
return rencontre; return rencontre;
@ -280,13 +280,15 @@ export class TMRUtility {
static rencontreTMRTypeCase(typeTMR, roll=undefined) { static rencontreTMRTypeCase(typeTMR, roll=undefined) {
if (!roll) if (!roll)
{ {
roll = new Roll("d100").roll().total; roll = RdDDice.show(new Roll("d100").evaluate()).total;
console.log("rencontreTMRTypeCase", roll);
} }
typeTMR = typeTMR.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, ""); typeTMR = typeTMR.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "");
for( let rencontre of rencontresTable) { for( let rencontre of rencontresTable) {
let scoreDef = rencontre.data[typeTMR]; let scoreDef = rencontre.data[typeTMR];
let min = scoreDef.substr(0,2); let min = scoreDef.substr(0,2);
let max = scoreDef.substr(3,2); let max = scoreDef.substr(3,2);
if (min=="00") min = 101;
if (max=="00") max = 100; if (max=="00") max = 100;
if (roll >= min && roll <= max) { if (roll >= min && roll <= max) {
return rencontre; return rencontre;
@ -300,7 +302,7 @@ export class TMRUtility {
* @param {*} caseName * @param {*} caseName
* @param {*} roll * @param {*} roll
*/ */
static async getRencontre( caseName, roll ) { static getRencontre( caseName, roll ) {
if (!roll) { if (!roll) {
roll = new Roll("1d100").roll().total; roll = new Roll("1d100").roll().total;
} }
@ -311,7 +313,7 @@ export class TMRUtility {
let rencontre = this.rencontreTMRTypeCase(caseName, roll); let rencontre = this.rencontreTMRTypeCase(caseName, roll);
if (rencontre) { if (rencontre) {
let force = await this.evaluerForceRencontre(rencontre); let force = this.evaluerForceRencontre(rencontre);
ChatMessage.create({ content: "Rencontre en " + caseName + "(jet : " + roll + "%)<br>Vous rencontrez un " + rencontre.name + " d'une force de " + force + " Points de Rêve" }); ChatMessage.create({ content: "Rencontre en " + caseName + "(jet : " + roll + "%)<br>Vous rencontrez un " + rencontre.name + " d'une force de " + force + " Points de Rêve" });
} }
return false; return false;
@ -323,9 +325,9 @@ export class TMRUtility {
// TODO random get same type // TODO random get same type
} }
static async evaluerForceRencontre(rencontre) { static evaluerForceRencontre(rencontre) {
if (this.isReveDeDragon(rencontre)) { if (this.isReveDeDragon(rencontre)) {
let ddr = await RdDDice.deDraconique(); let ddr = RdDDice.deDraconique();
return ddr + 7; return ddr + 7;
} }
else { else {