From a12f9bbf01f54badd0394cc3c2ec9867afb4325d Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Fri, 29 Jan 2021 12:08:02 +0100 Subject: [PATCH] =?UTF-8?q?Am=C3=A9lioration=20messages=20de=20stress?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- module/actor-sheet.js | 2 +- module/actor.js | 107 +++++++++--------- module/rdd-commands.js | 2 +- module/rdd-utility.js | 6 +- .../chat-resultat-transformer-stress.html | 18 +++ 5 files changed, 78 insertions(+), 57 deletions(-) create mode 100644 templates/chat-resultat-transformer-stress.html diff --git a/module/actor-sheet.js b/module/actor-sheet.js index f8836363..ae6a0d3b 100644 --- a/module/actor-sheet.js +++ b/module/actor-sheet.js @@ -459,7 +459,7 @@ export class RdDActorSheet extends ActorSheet { this.actor.setEthylisme(parseInt(event.target.value)); }); html.find('#stress-test').click((event) => { - this.actor.stressTest(); + this.actor.transformerStress(); this.render(true); }); html.find('#moral-malheureux').click((event) => { diff --git a/module/actor.js b/module/actor.js index b7224b7f..1e3aaa73 100644 --- a/module/actor.js +++ b/module/actor.js @@ -321,7 +321,7 @@ export class RdDActor extends Actor { await this._recupererVie(message); await this.jetDeMoral('neutre'); await this.chanceActuelleIncDec(1); - await this.transformerStress(message); + this.transformerStress(); await this.retourSeuilDeReve(message); message.content = `A la fin Chateau Dormant, ${message.content}
Un nouveau jour se lève`; ChatMessage.create(message); @@ -1417,69 +1417,72 @@ export class RdDActor extends Actor { } /* -------------------------------------------- */ - async stressTest() { - const message = { - content: "", - whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name) - }; - await this.transformerStress(message); - ChatMessage.create(message); - } - - /* -------------------------------------------- */ - async transformerStress(message) { - let compteurs = duplicate(this.data.data.compteurs); - const stress = Misc.toInt(compteurs.stress.value); - + async transformerStress() { + const stress = Misc.toInt(this.data.data.compteurs.stress.value); if (stress <= 0) { - return false; + return; } - - let stressRoll = await this._stressRoll(); - let convertis = Math.floor(stress * stressRoll.factor); - compteurs.stress.value = Math.max(stress - convertis - 1, 0); - - let dissolution = Math.max(0, Misc.toInt(compteurs.dissolution.value)); - let exaltation = Math.max(0, Misc.toInt(compteurs.exaltation.value)); + + const stressRoll = await this._stressRoll(this.getReveActuel()); + + const conversion = Math.floor(stress * stressRoll.factor / 100); + let dissolution = Math.max(0, Misc.toInt(this.data.data.compteurs.dissolution.value)); + let exaltation = Math.max(0, Misc.toInt(this.data.data.compteurs.exaltation.value)); const annule = Math.min(dissolution, exaltation); dissolution -= annule; exaltation -= annule; - if (dissolution > 0) { - const perdus = Math.min(dissolution, convertis); - convertis -= perdus; - dissolution -= perdus; - } - compteurs.experience.value += convertis + exaltation; - compteurs.dissolution.value = dissolution; + const perteDissolution = Math.max(0, Math.min(dissolution, conversion)); + + let stressRollData = { + alias: this.name, + selectedCarac: this.data.data.carac.reve, + rolled: stressRoll, + stress: stress, + perte: Math.min(conversion, stress), + convertis: conversion - perteDissolution, + xp: conversion - perteDissolution + exaltation, + dissolution: dissolution, + exaltation: exaltation + }; + + ChatMessage.create({ + whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name), + content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-resultat-transformer-stress.html`, stressRollData) + }); + + let compteurs = duplicate(this.data.data.compteurs); + compteurs.stress.value = Math.max(stress - stressRollData.perte - 1, 0); + compteurs.experience.value += stressRollData.xp; + compteurs.dissolution.value = dissolution - perteDissolution; compteurs.exaltation.value = 0; - message.content += "
Vous transformez " + convertis + " points de Stress en Expérience" + stressRoll.comment; await this.update({ "data.compteurs": compteurs }); - return true; } /* -------------------------------------------- */ - async _stressRoll() { - let reveActuel = this.getReveActuel(); + async _stressRoll(reveActuel) { let result = await RdDResolutionTable.roll(reveActuel, 0); - console.log("_stressRoll", result); - switch (result.code) { - case "sign": return { factor: 0.75, comment: " (75%): " + result.quality + " - " + result.roll + " sur " + result.score + "%" } - case "norm": return { factor: 0.5, comment: " (50%): " + result.quality + " - " + result.roll + " sur " + result.score + "%" } - case "echec": return { factor: 0.2, comment: " (20%): " + result.quality + " - " + result.roll + " sur " + result.score + "%" } - 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 + "%" } - case "part": - { - let second = await RdDResolutionTable.roll(reveActuel, 0); - console.log("_stressRoll", second); - switch (second.code) { - case "part": case "sign": - return { factor: 1.5, comment: " (150%): Double Particulière - " + result.roll + " puis " + second.roll + " sur " + result.score + "%" } - default: - return { factor: 1, comment: " (100%): " + result.quality + " - " + result.roll + " puis " + second.roll + " sur " + result.score + "%" } - } - } + if (result.isPart) { + result.second = await RdDResolutionTable.roll(reveActuel, 0); } + result.factor = this._getFacteurStress(result); + return result; + } + + _getFacteurStress(stressRoll) { + switch (stressRoll.code) { + case "sign": return 75; + case "norm": return 50; + case "echec": return 20; + case "epart": return 10; + case "etotal": return 0; + case "part": + if (stressRoll.second.isSign) { + stressRoll.quality = "Double Particulière"; + return 150; + } + return 100; + } + return 0; } /* -------------------------------------------- */ diff --git a/module/rdd-commands.js b/module/rdd-commands.js index 1523cb26..8190042c 100644 --- a/module/rdd-commands.js +++ b/module/rdd-commands.js @@ -249,7 +249,7 @@ export class RdDCommands { getCoutXpCarac(msg, params) { if (params && params.length == 1) { let to = Number(params[0]); - RdDCommands._chatAnswer(msg, `Coût pour passer une caractéristique de ${to - 1} à ${to}: ${RdDUtility.getCaractXp(to)}`); + RdDCommands._chatAnswer(msg, `Coût pour passer une caractéristique de ${to - 1} à ${to}: ${RdDUtility.getCaracXp(to)}`); } else { return false; diff --git a/module/rdd-utility.js b/module/rdd-utility.js index 8e51d62e..98dd7db5 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -412,11 +412,11 @@ export class RdDUtility { static getCaracNextXp(value) { const nextValue = Number(value) + 1; // xp est le coût pour atteindre cette valeur, on regarde donc le coût de la valeur+1 - return RdDUtility.getCaractXp(nextValue); + return RdDUtility.getCaracXp(nextValue); } - static getCaractXp(targetValue) { - return tableCaracDerivee[targetValue].xp; + static getCaracXp(targetValue) { + return tableCaracDerivee[targetValue]?.xp ?? 200 ; } /* -------------------------------------------- */ diff --git a/templates/chat-resultat-transformer-stress.html b/templates/chat-resultat-transformer-stress.html new file mode 100644 index 00000000..0bef2112 --- /dev/null +++ b/templates/chat-resultat-transformer-stress.html @@ -0,0 +1,18 @@ +

+ {{alias}} transforme {{rolled.factor}}% de son stress +

+{{> "systems/foundryvtt-reve-de-dragon/templates/chat-infojet.html"}} +{{#if rolled.isPart}} +
+ + Deuxième jet: {{rolled.second.roll}} {{rolled.second.quality}} + +
+{{/if}} +
+ + Transformation de {{perte}} points de stress sur {{stress}} + {{~#if (gt dissolution 0)}}; {{dissolution}} points perdus par la dissolution{{/if~}} + {{~#if (gt exaltation 0)}}; {{exaltation}} points gagnés par l'exaltation{{/if~}} + , gain de {{xp}} points d'expérience +