From 5d0406357983761a956210c1c30d909815580cfa Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Wed, 25 Nov 2020 00:46:11 +0100 Subject: [PATCH 1/4] =?UTF-8?q?Correction=20choix=20carac=20comp=C3=A9tenc?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Distinction entre "carac" qui représente la liste des caractéristiques et "caracValue, la valeur selectionnée --- module/actor.js | 4 ++-- module/rdd-resolution-table.js | 30 +++++++++++++++--------------- module/rdd-roll-dialog.js | 2 +- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/module/actor.js b/module/actor.js index 53ac2d52..5f7cc623 100644 --- a/module/actor.js +++ b/module/actor.js @@ -127,7 +127,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async performRoll(rollData) { - let rolled = await RdDResolutionTable.roll(rollData.carac, rollData.finalLevel); + let rolled = await RdDResolutionTable.roll(rollData.caracValue, rollData.finalLevel); //rolled.isPart = true; // Pour tester le particulières rollData.rolled = rolled; // garder le résultat console.log("performRoll", rollData, rolled) @@ -973,7 +973,7 @@ export class RdDActor extends Actor { { let carac; if ( caracName == "reveActuel") { // Fake carac for Reve Actuel - carac = {type: "number", + carac = {type: "number", value: this.getReveActuel(), label: "Rêve Actuel" } diff --git a/module/rdd-resolution-table.js b/module/rdd-resolution-table.js index 7e769c01..7af9777c 100644 --- a/module/rdd-resolution-table.js +++ b/module/rdd-resolution-table.js @@ -61,8 +61,8 @@ export class RdDResolutionTable { /* -------------------------------------------- */ static build() { let table = [] - for (var carac = 0; carac <= 30; carac++) { - table[carac] = this._computeRow(carac); + for (var caracValue = 0; caracValue <= 60; caracValue++) { + table[caracValue] = this._computeRow(caracValue); } return table; } @@ -78,18 +78,18 @@ export class RdDResolutionTable { static explain(rolled) { let message = "
Jet : " + rolled.roll + " sur " + rolled.score + "%"; - if (rolled.carac != null && rolled.finalLevel!= null) { - message += " (" + rolled.carac + " à " + Misc.toSignedString(rolled.finalLevel) + ")"; + if (rolled.caracValue != null && rolled.finalLevel!= null) { + message += " (" + rolled.caracValue + " à " + Misc.toSignedString(rolled.finalLevel) + ")"; } return message; } /* -------------------------------------------- */ - static async roll(carac, finalLevel) { - let chances = this.computeChances(carac, finalLevel); + static async roll(caracValue, finalLevel) { + let chances = this.computeChances(caracValue, finalLevel); chances.showDice = true; let rolled = await this.rollChances(chances); - rolled.carac = carac; + rolled.caracValue = caracValue; rolled.finalLevel = finalLevel; return rolled; } @@ -105,14 +105,14 @@ export class RdDResolutionTable { } /* -------------------------------------------- */ - static computeChances(carac, difficulte) { + static computeChances(caracValue, difficulte) { if (difficulte < -16) { return duplicate(levelImpossible); } if (difficulte < -10) { return duplicate(levelDown.find(levelData => levelData.level == difficulte)); } - return duplicate(this.resolutionTable[carac][difficulte + 10]); + return duplicate(this.resolutionTable[caracValue][difficulte + 10]); } /* -------------------------------------------- */ @@ -142,13 +142,13 @@ export class RdDResolutionTable { } /* -------------------------------------------- */ - static _computeRow(carac) { + static _computeRow(caracValue) { let dataRow = [ - this._computeCell(-10, Math.max(Math.floor(carac / 4), 1)), - this._computeCell(-9, Math.max(Math.floor(carac / 2), 1)) + this._computeCell(-10, Math.max(Math.floor(caracValue / 4), 1)), + this._computeCell(-9, Math.max(Math.floor(caracValue / 2), 1)) ] for (var diff = -8; diff <= 22; diff++) { - dataRow[diff + 10] = this._computeCell(diff, Math.max(Math.floor(carac * (diff + 10) / 2), 1)); + dataRow[diff + 10] = this._computeCell(diff, Math.max(Math.floor(caracValue * (diff + 10) / 2), 1)); } return dataRow; } @@ -205,8 +205,8 @@ export class RdDResolutionTable { let table = $("") .append(this._buildHTMLHeader(this.resolutionTable[0], minLevel, maxLevel)); - for (var carac = minCarac; carac <= maxCarac; carac++) { - table.append(this._buildHTMLRow(this.resolutionTable[carac], carac, caracValue, levelValue, minLevel, maxLevel)); + for (var caracValue = minCarac; caracValue <= maxCarac; caracValue++) { + table.append(this._buildHTMLRow(this.resolutionTable[caracValue], caracValue, caracValue, levelValue, minLevel, maxLevel)); } return table; } diff --git a/module/rdd-roll-dialog.js b/module/rdd-roll-dialog.js index 60cb82a3..057d60db 100644 --- a/module/rdd-roll-dialog.js +++ b/module/rdd-roll-dialog.js @@ -67,7 +67,7 @@ export class RdDRollDialog extends Dialog { let rollLevel = RdDRollDialog._computeFinalLevel(rollData); rollData.finalLevel = rollLevel; - rollData.carac = rollData.selectedCarac.value + rollData.caracValue = caracValue // Sort management if ( rollData.selectedSort ) { From 6ccc5b8d1bacd7a190079c8474e50fdf3896251c Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Wed, 25 Nov 2020 00:49:21 +0100 Subject: [PATCH 2/4] Jet de Stress utilise le reve actuel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit renommage de updateReveActuel pour indiquer que ça applique une difference (comme santeIncDec) --- module/actor.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/module/actor.js b/module/actor.js index 5f7cc623..bbff45af 100644 --- a/module/actor.js +++ b/module/actor.js @@ -396,9 +396,9 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async recuperationReve(message) { const seuil = this.data.data.reve.seuil.value; - const reve = this.getReveActuel(); - if (reve >= seuil) { - message.content += "
Vous avez suffisament rêvé (seuil " + seuil + ", rêve actuel "+reve+")"; + const reveActuel = this.getReveActuel(); + if (reveActuel >= seuil) { + message.content += "
Vous avez suffisament rêvé (seuil " + seuil + ", rêve actuel "+reveActuel+")"; } else { let deRecuperation = await RdDDice.deDraconique(); @@ -407,11 +407,11 @@ export class RdDActor extends Actor { { // Rêve de Dragon ! message.content += "
Vous faites un Rêve de Dragon de " + deRecuperation + " Points de rêve"; - message.content += this.combattreReveDeDragon(deRecuperation); + message.content += await this.combattreReveDeDragon(deRecuperation); } else{ message.content += "
Vous récupérez " + deRecuperation + " Points de rêve"; - this.updatePointsDeReve(deRecuperation); + await this.reveActuelIncDec(deRecuperation); } } } @@ -435,7 +435,7 @@ export class RdDActor extends Actor { if (roll.isSuccess) { message += "
Vous gagnez " + force + " points de Rêve"; this.updatePointDeSeuil(); - this.updatePointsDeReve(force); + this.reveActuelIncDec(force); } if (roll.isPart) { // TODO: Dialog pour choix entre HR opu général? @@ -723,7 +723,7 @@ export class RdDActor extends Actor { } /* -------------------------------------------- */ - async updatePointsDeReve( value ) { + async reveActuelIncDec( value ) { let reve = duplicate(this.data.data.reve.reve); reve.value = Math.max(reve.value + value, 0); await this.update( {"data.reve.reve": reve } ); @@ -921,7 +921,8 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async _stressRoll() { - let result = await RdDResolutionTable.roll(this.data.data.carac.reve.value, 0); + let reveActuel = this.getReveActuel(); + 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 + "%" } @@ -931,7 +932,7 @@ export class RdDActor extends Actor { case "etotal": return { factor: 0, comment: " (0%): " + result.quality + " - " + result.roll + " sur " + result.score + "%" } case "part": { - let second = await RdDResolutionTable.roll(this.data.data.carac.reve.value, 0); + let second = await RdDResolutionTable.roll(reveActuel, 0); console.log("_stressRoll", second); switch (second.code) { case "part": case "sign": From f77a0bf20b5dbdca5e2ca7cf17fddf941d3d14de Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Wed, 25 Nov 2020 00:50:20 +0100 Subject: [PATCH 3/4] renommage countBlessures --- module/actor-creature-sheet.js | 6 +++--- module/actor-humanoide-sheet.js | 6 +++--- module/actor-sheet.js | 6 +++--- module/actor.js | 12 ++++-------- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/module/actor-creature-sheet.js b/module/actor-creature-sheet.js index f6f91d02..f4a31783 100644 --- a/module/actor-creature-sheet.js +++ b/module/actor-creature-sheet.js @@ -42,9 +42,9 @@ export class RdDActorCreatureSheet extends ActorSheet { data.data.caracSum = sum; data.data.carac.taille.isTaille = true; // To avoid button link; - data.data.nbLegeres = this.actor.GetNumberBlessures(data.data.blessures.legeres.liste ); - data.data.nbGraves = this.actor.GetNumberBlessures(data.data.blessures.graves.liste ); - data.data.nbCritiques = this.actor.GetNumberBlessures(data.data.blessures.critiques.liste ); + data.data.nbLegeres = this.actor.countBlessures(data.data.blessures.legeres.liste ); + data.data.nbGraves = this.actor.countBlessures(data.data.blessures.graves.liste ); + data.data.nbCritiques = this.actor.countBlessures(data.data.blessures.critiques.liste ); data.data.competencecreature = data.itemsByType["competencecreature"]; diff --git a/module/actor-humanoide-sheet.js b/module/actor-humanoide-sheet.js index f41fd603..a889877e 100644 --- a/module/actor-humanoide-sheet.js +++ b/module/actor-humanoide-sheet.js @@ -41,9 +41,9 @@ export class RdDActorHumanoideSheet extends ActorSheet { data.data.caracSum = sum; data.data.carac.taille.isTaille = true; // To avoid button link; - data.data.nbLegeres = this.actor.GetNumberBlessures(data.data.blessures.legeres.liste ); - data.data.nbGraves = this.actor.GetNumberBlessures(data.data.blessures.graves.liste ); - data.data.nbCritiques = this.actor.GetNumberBlessures(data.data.blessures.critiques.liste ); + data.data.nbLegeres = this.actor.countBlessures(data.data.blessures.legeres.liste ); + data.data.nbGraves = this.actor.countBlessures(data.data.blessures.graves.liste ); + data.data.nbCritiques = this.actor.countBlessures(data.data.blessures.critiques.liste ); data.data.competencecreature = data.itemsByType["competencecreature"]; RdDUtility.filterItemsPerTypeForSheet(data ); diff --git a/module/actor-sheet.js b/module/actor-sheet.js index 2bffabb6..ee4d3d94 100644 --- a/module/actor-sheet.js +++ b/module/actor-sheet.js @@ -85,9 +85,9 @@ export class RdDActorSheet extends ActorSheet { } data.data.carac.taille.isTaille = true; // To avoid button link; - data.data.nbLegeres = this.actor.GetNumberBlessures(data.data.blessures.legeres.liste ); - data.data.nbGraves = this.actor.GetNumberBlessures(data.data.blessures.graves.liste ); - data.data.nbCritiques = this.actor.GetNumberBlessures(data.data.blessures.critiques.liste ); + data.data.nbLegeres = this.actor.countBlessures(data.data.blessures.legeres.liste ); + data.data.nbGraves = this.actor.countBlessures(data.data.blessures.graves.liste ); + data.data.nbCritiques = this.actor.countBlessures(data.data.blessures.critiques.liste ); // Mise à jour de l'encombrement total this.actor.computeEncombrementTotal(); diff --git a/module/actor.js b/module/actor.js index bbff45af..f34d0e96 100644 --- a/module/actor.js +++ b/module/actor.js @@ -762,13 +762,9 @@ export class RdDActor extends Actor { } /* -------------------------------------------- */ - GetNumberBlessures( blessuresListe ) + countBlessures( blessuresListe ) { - let nbB = 0; - for ( let b of blessuresListe) { - nbB += ( b.active) ? 1 : 0; - } - return nbB; + return blessuresListe.filter(b => b.active).length } /* -------------------------------------------- */ @@ -817,8 +813,8 @@ export class RdDActor extends Actor { let blessures = this.data.data.blessures; let diffVie = this.data.data.sante.vie.max - this.data.data.sante.vie.value; let maxEndVie = this.data.data.sante.endurance.max - (diffVie * 2); - let nbGraves = this.GetNumberBlessures(blessures.graves.liste); - let nbCritiques = this.GetNumberBlessures(blessures.critiques.liste); + let nbGraves = this.countBlessures(blessures.graves.liste); + let nbCritiques = this.countBlessures(blessures.critiques.liste); let maxEndGraves = Math.floor(this.data.data.sante.endurance.max / (2 * nbGraves)); let maxEndCritiques = nbCritiques > 0 ? 1 : this.data.data.sante.endurance.max; return Math.max(0, Math.min(maxEndVie, maxEndGraves, maxEndCritiques)); From e82eaa2ad714fc19ff291f883c8963ed2142c062 Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Tue, 24 Nov 2020 18:54:13 +0100 Subject: [PATCH 4/4] Dormir Chateau dormant MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Gestion de l'heure de chateau dormant. inclus * récupération blessures * récupération vie * conversion de stress * descente vers seuil de rêve --- module/actor-sheet.js | 5 +- module/actor.js | 132 ++++++++++++++++++++++++++++++++++--- module/rdd-utility.js | 9 +++ templates/actor-sheet.html | 2 +- 4 files changed, 136 insertions(+), 12 deletions(-) diff --git a/module/actor-sheet.js b/module/actor-sheet.js index ee4d3d94..12f5330b 100644 --- a/module/actor-sheet.js +++ b/module/actor-sheet.js @@ -250,7 +250,10 @@ export class RdDActorSheet extends ActorSheet { html.find('.dormir-une-heure').click((event) => { this.actor.dormir(1); - } ); + }); + html.find('.dormir-chateau-dormant').click((event) => { + this.actor.dormirChateauDormant(); + }); // Display info about queue html.find('.queuesouffle-label a').click((event) => { diff --git a/module/actor.js b/module/actor.js index f34d0e96..ff80ba4a 100644 --- a/module/actor.js +++ b/module/actor.js @@ -331,6 +331,100 @@ export class RdDActor extends Actor { return explications } + async dormirChateauDormant() { + let message = { + whisper: ChatUtility.getWhisperRecipientsAndGMs( this.name ), + content : "" + + }; + const blessures = duplicate(this.data.data.blessures); + console.log("dormirChateauDormant", blessures) + await this._recupererBlessures(message, "legere", blessures.legeres.liste.filter(b => b.active), []); + await this._recupererBlessures(message, "grave", blessures.graves.liste.filter(b => b.active), blessures.legeres.liste); + await this._recupererBlessures(message,"legere", blessures.critiques.liste.filter(b => b.active), blessures.graves.liste); + await this.update( {"data.blessures": blessures } ); + await this._recupererVie(message); + await this.transformerStress(message); + await this.retourSeuilDeReve(message); + message.content = "A la fin Chateau Dormant, " + message.content +"
Un nouveau jour se lève"; + ChatMessage.create( message ); + } + + async _recupererBlessures(message, type, liste, moindres) { + let count = 0; + const definitions = RdDUtility.getDefinitionsBlessures(); + let definition = definitions.find( d => d.type == type); + for (let blessure of liste) { + if (blessure.jours >= definition.facteur) { + let rolled = await this._jetRecuperationConstitution(Misc.toInt(blessure.soins_complets), message); + blessure.soins_complets = 0; + if (rolled.isSuccess && this._retrograderBlessure(type, blessure, moindres)) { + message.content += " -- une blessure " + type + " cicatrise"; + count++; + } + else if (rolled.isETotal) { + message.content += " -- une blessure " + type + " s'infecte (temps de guérison augmenté de " + definition.facteur + " jours, perte de vie)"; + blessure.jours = 0; + await this.santeIncDec("vie", -1); + } + else { + message.content += " -- une blessure " + type + " reste stable"; + } + } + else { + blessure.jours++; + } + } + } + + _retrograderBlessure(type, blessure, blessuresMoindres) + { + if (type != "legere") { + let retrograde = blessuresMoindres.find(b => !b.active); + if (!retrograde) { + return false; + } + mergeObject(retrograde, { "active": true, "premiers_soins": 0, "soins_complets": 0, "jours": 0, "localisation": blessure.localisation }); + } + mergeObject(blessure, { "active": false, "premiers_soins": 0, "soins_complets": 0, "jours": 0, "localisation": "" }); + return true; + } + + async _recupererVie(message) { + let blessures = [].concat(this.data.data.blessures.legeres.liste).concat(this.data.data.blessures.graves.liste).concat(this.data.data.blessures.critiques.liste); + let nbBlessures = blessures.filter(b => b.active); + let vieManquante = this.data.data.sante.vie.max - this.data.data.sante.vie.value; + if (nbBlessures == 0 && vieManquante>0) { + let bonusSoins = 0; + for (let b of blessures) + { + bonusSoins = Math.max(bonusSoins, Misc.toInt(b.soins_complets)); + } + let rolled = await this._jetRecuperationConstitution(bonusSoins, message) + if (rolled.isSuccess) { + const gain = Math.min(rolled.isPart ? 2 : 1, vieManquante); + message.content += " -- récupération de vie: " + gain; + await this.santeIncDec("vie", gain); + } + else if (rolled.isETotal) { + message.content += " -- perte de vie: 1"; + await this.santeIncDec("vie", -1); + } + else{ + message.content +=" -- vie stationnaire "; + } + } + } + + async _jetRecuperationConstitution(bonusSoins, message = undefined) { + let difficulte = Misc.toInt(bonusSoins) + Math.min(0, this.data.data.sante.vie.value - this.data.data.sante.vie.max); + let rolled = await RdDResolutionTable.roll(this.data.data.carac.constitution.value, difficulte); + if (message) { + message.content += RdDResolutionTable.explain(rolled).replace(/Jet :/, "Constitution :"); + } + return rolled; + } + /* -------------------------------------------- */ async dormir(heures=1) { let message = { @@ -415,6 +509,14 @@ export class RdDActor extends Actor { } } } + async retourSeuilDeReve(message) { + const seuil = this.data.data.reve.seuil.value; + const reveActuel = this.getReveActuel(); + if (reveActuel > seuil) { + message.content += "
Votre rêve redescend vers son seuil naturel (seuil " + seuil + ", nouveau rêve actuel "+(reveActuel-1)+")"; + await this.reveActuelIncDec(-1); + } + } /* -------------------------------------------- */ async combattreReveDeDragon(force){ @@ -901,17 +1003,27 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async stressTest() { - let stressRoll = this._stressRoll(); - let compteurs = duplicate(this.data.data.compteurs); - let convertion = Math.floor(compteurs.stress.value * stressRoll.factor); - - compteurs.experience.value += convertion; - compteurs.stress.value = Math.max(compteurs.stress.value - convertion - 1, 0); - - ChatMessage.create({ - content: "Vous avez transformé " + convertion + " points de Stress en Expérience" + stressRoll.comment, + const message = { + content: "", whisper: ChatMessage.getWhisperRecipients(game.user.name) - }); + }; + await this.transformerStress(message); + + ChatMessage.create(message); + } + + async transformerStress(message) { + const stress = Misc.toInt(this.data.data.compteurs.stress.value); + if (stress<=0) { + return; + } + let stressRoll = await this._stressRoll(); + let convertis = Math.floor(stress * stressRoll.factor); + + let compteurs = duplicate(this.data.data.compteurs); + compteurs.experience.value += convertis; + compteurs.stress.value = Math.max(stress - convertis - 1, 0); + message.content += "
Vous transformez " + convertis + " points de Stress en Expérience" + stressRoll.comment; await this.update({ "data.compteurs": compteurs }); } diff --git a/module/rdd-utility.js b/module/rdd-utility.js index 60fcd3d2..7ab7f419 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -75,6 +75,12 @@ const table2func = { "queues": {descr: "queues : Tire une queue de Dragon", fun "souffle": { descr: "souffle: Tire un Souffle de Dragon", func: RdDRollTables.getSouffle}, "tarot" : { descr: "tarot: Tire une carte de Tarot Dracnique", func: RdDRollTables.getTarot} }; +const definitionsBlessures = [ + { type: "legere", facteur: 2 }, + { type: "grave", facteur : 4 }, + { type: "critique", facteur : 6 } +] + const definitionsEncaissement = { "mortel": [ { minimum: undefined, maximum: 0, endurance: "0", vie: "0", legeres: 0, graves: 0, critiques: 0 }, @@ -289,6 +295,9 @@ export class RdDUtility { return ajustementsConditions; } + static getDefinitionsBlessures() { + return definitionsBlessures; + } /* -------------------------------------------- */ static isTronc( compName ) { diff --git a/templates/actor-sheet.html b/templates/actor-sheet.html index d4708cb3..2765b7cd 100644 --- a/templates/actor-sheet.html +++ b/templates/actor-sheet.html @@ -60,7 +60,7 @@
Encaisser des dommages Dormir une heure - Chateau Dormant + Chateau Dormant Montée dans les Terres Médianes ! Montée accélérée dans les Terres Médianes ! Regarder les Terres Médianes