diff --git a/module/actor.js b/module/actor.js
index 6a77d702..bb657e23 100644
--- a/module/actor.js
+++ b/module/actor.js
@@ -204,8 +204,8 @@ export class RdDActor extends Actor {
rollData.domArmePlusDom += parseInt(this.data.data.attributs.plusdom.value);
if ( rollData.selectedCarac.label == "Lancer" ) { // +dom only for Melee/Lancer
let bdom = parseInt(this.data.data.attributs.plusdom.value);
- if ( bdom > parseInt(rollData.arme.data.dommages)*2 )
- bdom = parseInt(rollData.arme.data.dommages)*2;
+ if ( bdom > parseInt(rollData.arme.data.dommages))
+ bdom = parseInt(rollData.arme.data.dommages);
rollData.domArmePlusDom += bdom
}
rollData.degats = parseInt(myroll.result) + rollData.domArmePlusDom;
@@ -716,8 +716,8 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */
rollArme( armeName )
- {
- let armeItem = RdDUtility.findCompetence( this.data.items, armeName );
+ {
+ let armeItem = this.data.items.find(item=>item.type==="arme" && (item.name === armeName));
if ( armeItem && armeItem.data.competence )
this.rollCompetence( armeItem.data.competence, armeItem );
else
@@ -813,53 +813,34 @@ export class RdDActor extends Actor {
console.log("Final protect", protection);
return protection;
}
-
- /* -------------------------------------------- */
- encaisserDommages( attackerRoll )
- {
- //let attackerRoll = rollData.attackerRoll;
- let degatsReel = attackerRoll.degats - this.computeArmure(attackerRoll.loc, attackerRoll.domArmePlusDom);
- console.log("RollData from attacker!", attackerRoll, degatsReel);
-
- let result = RdDUtility.computeBlessuresSante(degatsReel);
+
+ /* -------------------------------------------- */
+ encaisserDommages( attackerRoll ) {
+ console.log("encaisserDommages", attackerRoll )
+ const armure = this.computeArmure( attackerRoll.loc, attackerRoll.domArmePlusDom);
+ let degatsReel = attackerRoll.degats - armure;
+
+ let result = RdDUtility.computeBlessuresSante(degatsReel, attackerRoll.mortalite);
this.santeIncDec("vie", result.vie);
this.santeIncDec("endurance", result.endurance);
-
- result.locName = attackerRoll.loc.label; // Add the localisation namme
- this.manageBlessures( result ); // Will upate the result table
- ChatMessage.create( {title: "Blessures !", content: this.data.name + " a encaissé : " +
- "
Encaissement final : " + degatsReel +
- "
" + result.legeres + " légères, " + result.graves + " graves et " +
- result.critiques + " critique." +
- "
Et perdu : " +
- "
" + result.endurance + " Endurance et " + result.vie + " Points de Vie" } );
-
+ result.locName = attackerRoll.loc.label;
+
+ this.manageBlessures(result); // Will upate the result table
+ const blessureLegere = (result.legeres > 0 ? "une blessure légère" : "");
+ const blessureGrave = (result.graves > 0 ? "une blessure grave" : "");
+ const blessureCritique = (result.critiques > 0 ? "une blessure critique" : "");
+ ChatMessage.create({
+ title: "Blessures !", content: this.data.name + " a encaissé : " +
+ "
Encaissement final : " + degatsReel +
+ "
" + blessureLegere + blessureGrave + blessureCritique +
+ "
Et a perdu : " +
+ "
" + result.endurance + " Endurance et " + result.vie + " Points de Vie"
+ });
+
this.computeEtatGeneral();
this.sheet.render(true);
}
- /* -------------------------------------------- */
- encaisserDommagesHorsCombat( degats )
- {
- let degatsReel = degats - this.computeArmure("Corps", 0);
- console.log("Enciasser dommages", degatsReel, this.computeArmure("Corps", 0), degats);
-
- let result = RdDUtility.computeBlessuresSante(degatsReel);
- this.santeIncDec("vie", result.vie);
- this.santeIncDec("endurance", result.endurance);
-
- result.locName = "Corps"; // Add the localisation namme
- this.manageBlessures( result ); // Will upate the result table
- ChatMessage.create( {title: "Blessures !", content: this.data.name + " a encaissé : " +
- "
Encaissement final : " + degatsReel +
- "
" + result.legeres + " légères, " + result.graves + " graves et " +
- result.critiques + " critique." +
- "
Et perdu : " +
- "
" + result.endurance + " Endurance et " + result.vie + " Points de Vie" } );
-
- this.computeEtatGeneral();
- this.sheet.render(true);
- }
/* -------------------------------------------- */
parerAttaque( attackerRoll, armeId )
diff --git a/module/rdd-roll-encaisser.js b/module/rdd-roll-encaisser.js
index 32369235..d0f17708 100644
--- a/module/rdd-roll-encaisser.js
+++ b/module/rdd-roll-encaisser.js
@@ -2,54 +2,57 @@
* Extend the base Dialog entity by defining a custom window to perform roll.
* @extends {Dialog}
*/
-
export class RdDEncaisser extends Dialog {
-
- /* -------------------------------------------- */
+
+ /* -------------------------------------------- */
constructor(html, actor) {
- let myButtons = { rollButton: {
- label: "Lancer",
- callback: html => this.performEncaisser(html, false)
- } };
// Common conf
- let dialogConf = {
+ let dialogConf = {
+ title: "Jet d'Encaissement",
content: html,
- buttons: myButtons,
- default: "rollButton"
+ buttons: {
+ "mortel": { label: "mortel", callback: html => this.performEncaisser(html, "mortel") },
+ "non-mortel": { label: "non-mortel", callback: html => this.performEncaisser(html, "non-mortel") },
+ "cauchemar": { label: "cauchemar", callback: html => this.performEncaisser(html, "cauchemar") }
+ },
+ default: "coupMortel"
}
- let dialogOptions = { classes: [ "rdddialog"] }
-
+
+ let dialogOptions = {
+ classes: ["rdddialog"],
+ width: 320,
+ height: 240
+ }
+
// Select proper roll dialog template and stuff
- dialogConf.title = "Jet d'Encaissement",
- dialogOptions.width = 320;
- dialogOptions.height = 160;
super(dialogConf, dialogOptions);
- this.actor = actor;
+ this.actor = actor;
this.modifier = 0;
- }
-
- /* -------------------------------------------- */
- performEncaisser (html, isReserve=false) {
- //console.log("On va encaisser !!", this.modifier);
- let result = Number(new Roll("2d10").roll().result);
- result += Number(this.modifier);
- this.actor.encaisserDommagesHorsCombat(result);
- //console.log("ENCAISSER:", result);
}
- /* -------------------------------------------- */
- activateListeners(html) {
+ /* -------------------------------------------- */
+ performEncaisser(html, mortalite = "mortel") {
+ this.actor.encaisserDommages({
+ degats: new Roll("2d10").roll().total,
+ domArmePlusDom: Number(this.modifier),
+ loc: { result: 0, label: "Corps" },
+ mortalite: mortalite
+ });
+ }
+
+ /* -------------------------------------------- */
+ activateListeners(html) {
super.activateListeners(html);
// Setup everything onload
- $(function() {
- $("#modificateurDegats").val( "0" );
+ $(function () {
+ $("#modificateurDegats").val("0");
});
- html.find('#modificateurDegats').click((event) => {
+ html.find('#modificateurDegats').click((event) => {
this.modifier = event.currentTarget.value; // Update the selected bonus/malus
});
}
-
+
}
diff --git a/module/rdd-rolltables.js b/module/rdd-rolltables.js
new file mode 100644
index 00000000..0cf0a1cb
--- /dev/null
+++ b/module/rdd-rolltables.js
@@ -0,0 +1,45 @@
+export class RdDRollTables {
+
+ /* -------------------------------------------- */
+ static async genericGetTableResult( tableName, toChat)
+ {
+ let pack = game.packs.get("foundryvtt-reve-de-dragon.tables-diverses");
+ await pack.getIndex();
+ let entry = pack.index.find(e => e.name === tableName);
+ let rollQueues = await pack.getEntity(entry._id);
+ let result = await rollQueues.draw( { displayChat: toChat } );
+ console.log("CAT", result);
+ return result;
+ }
+
+ /* -------------------------------------------- */
+ static async getSouffle( toChat ) {
+ return genericGetTableResult( "Souffles de Dragon", toChat);
+ }
+
+ /* -------------------------------------------- */
+ static async getQueue( toChat = true) {
+ return genericGetTableResult( "Queues de dragon", toChat);
+ }
+
+ /* -------------------------------------------- */
+ static async getTete( toChat = true ) {
+ return genericGetTableResult( "Têtes de Dragon pour haut-rêvants", toChat);
+ }
+
+ /* -------------------------------------------- */
+ static async getTeteHR( toChat = true ) {
+ return genericGetTableResult( "Têtes de Dragon pour tous personnages", toChat);
+ }
+
+ /* -------------------------------------------- */
+ static async getOmbre( toChat = true ) {
+ return genericGetTableResult( "Ombre de Thanatos", toChat);
+ }
+
+ /* -------------------------------------------- */
+ static async getTarot( toChat = true ) {
+ return genericGetTableResult( "Tarot Draconique", toChat);
+ }
+
+}
\ No newline at end of file
diff --git a/module/rdd-tmr-dialog.js b/module/rdd-tmr-dialog.js
index a417457b..b6dbea2c 100644
--- a/module/rdd-tmr-dialog.js
+++ b/module/rdd-tmr-dialog.js
@@ -4,6 +4,7 @@
*/
import { RdDUtility } from "./rdd-utility.js";
import { TMRUtility } from "./tmr-utility.js";
+import { RdDRollTables } from "./rdd-rolltables.js";
/** Helper functions */
export class RdDTMRDialog extends Dialog {
@@ -119,7 +120,7 @@ export class RdDTMRDialog extends Dialog {
let result = await this.actor.ajouterRefoulement(1);
this.updatePreviousRencontres();
if (result == "souffle") {
- let souffle = TMRUtility.getSouffle();
+ let souffle = RdDRollTables.getSouffle();
}
console.log("-> refouler", this.currentRencontre)
this.updateValuesDisplay();
@@ -245,7 +246,7 @@ export class RdDTMRDialog extends Dialog {
if ( result > scoreDef.score ) {
content = "Vous êtes entré sur une case humide, et vous avez raté votre maîtrise ! Vous quittez les Terres Médianes ! ("+ draconic.name +") :" + carac + " / " + level + " -> " + result + " / " + scoreDef.score;
if ( result >= scoreDef.etotal ) {
- let souffle = TMRUtility.getSouffle(true);
+ let souffle = RdDRollTables.getSouffle(true);
content += "
Vous avez fait un Echec Total. Vous subissez un Souffle de Dragon : " + souffle.name ;
this.actor.createOwnedItem( souffle );
}
diff --git a/module/rdd-utility.js b/module/rdd-utility.js
index cbab70fe..884e0d4a 100644
--- a/module/rdd-utility.js
+++ b/module/rdd-utility.js
@@ -2,6 +2,7 @@
import { RdDActor } from "./actor.js";
import { TMRUtility } from "./tmr-utility.js";
+import { RdDRollTables } from "./rdd-rolltables.js";
const level_category = {
"generale": "-4",
@@ -78,11 +79,36 @@ const fatigueMarche = { "aise": { "4":1, "6":2, "8":3, "10":4, "12":6 },
"difficile": { "4":3, "6":4, "8":6 },
"tresdifficile": { "4":4, "6":6 } }
/* Static tables for commands /table */
-const table2func = { "queues": {descr: "queues : Tire une queue de Dragon", func: TMRUtility.getQueue},
- "ombre": { descr: "ombre: Tire une Ombre de Dragon", func: TMRUtility.getOmbre },
- "tetehr": {descr: "tetehr: Tire une Tête de Dragon pour Hauts Revants", fund: TMRUtility.getTeteHR},
- "tete" : { descr: "tete: Tire une Tête de Dragon", func: TMRUtility.getTete},
- "souffle": { descr: "souffle: Tire un Souffle de Dragon", func: TMRUtility.getSouffle} };
+const table2func = { "queues": {descr: "queues : Tire une queue de Dragon", func: RdDRollTables.getQueue},
+ "ombre": { descr: "ombre: Tire une Ombre de Dragon", func: RdDRollTables.getOmbre },
+ "tetehr": {descr: "tetehr: Tire une Tête de Dragon pour Hauts Revants", fund: RdDRollTables.getTeteHR},
+ "tete" : { descr: "tete: Tire une Tête de Dragon", func: RdDRollTables.getTete},
+ "souffle": { descr: "souffle: Tire un Souffle de Dragon", func: RdDRollTables.getSouffle},
+ "tarot" : { descr: "tarot: Tire une carte de Tarot Dracnique", func: RdDRollTables.getTarot} };
+
+const definitionsEncaissement = {
+ "mortel": [
+ { minimum: undefined, maximum: 0, endurance: "0", vie: "0", legeres: 0, graves: 0, critiques: 0 },
+ { minimum: 1, maximum: 10, endurance: "1d4", vie: "0", legeres: 0, graves: 0, critiques: 0 },
+ { minimum: 11, maximum: 15, endurance: "1d6", vie: "0", legeres: 1, graves: 0, critiques: 0 },
+ { minimum: 16, maximum: 19, endurance: "2d6", vie: "2", legeres: 0, graves: 1, critiques: 0 },
+ { minimum: 20, maximum: undefined, endurance: "100", vie: "4 + @over20", legeres: 0, graves: 0, critiques: 1 },
+ ],
+ "non-mortel": [
+ { minimum: undefined, maximum: 0, endurance: "0", vie: "0", legeres: 0, graves: 0, critiques: 0 },
+ { minimum: 1, maximum: 10, endurance: "1d4", vie: "0", legeres: 0, graves: 0, critiques: 0 },
+ { minimum: 11, maximum: 15, endurance: "1d6", vie: "0", legeres: 0, graves: 0, critiques: 0 },
+ { minimum: 16, maximum: 19, endurance: "2d6", vie: "0", legeres: 1, graves: 0, critiques: 0 },
+ { minimum: 20, maximum: undefined, endurance: "100", vie: "1", legeres: 1, graves: 0, critiques: 0 },
+ ],
+ "cauchemar": [
+ { minimum: undefined, maximum: 0, gravite: "frayeur", endurance: "0", vie: "0", legeres: 0, graves: 0, critiques: 0 },
+ { minimum: 1, maximum: 10, endurance: "1d4", vie: "0", legeres: 0, graves: 0, critiques: 0 },
+ { minimum: 11, maximum: 15, endurance: "1d6", vie: "0", legeres: 0, graves: 0, critiques: 0 },
+ { minimum: 16, maximum: 19, endurance: "2d6", vie: "0", legeres: 0, graves: 0, critiques: 0 },
+ { minimum: 20, maximum: undefined, endurance: "3d6 + @over20", vie: "0", legeres: 0, graves: 0, critiques: 0 },
+ ]
+};
/* -------------------------------------------- */
export class RdDUtility {
@@ -401,40 +427,32 @@ export class RdDUtility {
return { result: result, label: txt };
}
-
- /* -------------------------------------------- */
- static computeBlessuresSante( degats )
- {
- console.log("Degats !!", degats);
- let result = { vie: 0,
- endurance: 0,
- legeres: 0,
- graves: 0,
- critiques: 0
- };
-
- if ( degats < 11 ) {
- result.type = "contusion";
- let myroll = new Roll("1d4").roll();
- result.endurance = -myroll.result;
- } else if ( degats < 16 ) {
- result.type = "blessure légère";
- let myroll = new Roll("1d6").roll();
- result.endurance = -myroll.result;
- result.legeres = 1;
- } else if (degats < 20 ) {
- result.type = "blessure grave";
- let myroll = new Roll("2d6").roll();
- result.endurance = -myroll.result;
- result.vie = -2;
- result.graves = 1;
- } else {
- result.type = "critique";
- result.endurance = -100; // Force endurance to 0
- result.vie = -4 - (degats - 20);
- result.critiques = 1;
+
+ static computeBlessuresSante( degats, mortalite="mortel" ) {
+ let encaissement = RdDUtility.selectEncaissement(degats, mortalite)
+ let over20 = degats > 20 ? degats - 20 : 0
+ encaissement.endurance = - RdDUtility._evaluatePerte(encaissement.endurance, over20)
+ encaissement.vie = - RdDUtility._evaluatePerte(encaissement.vie, degats, over20)
+ return encaissement;
+ }
+
+ static selectEncaissement( degats, mortalite ) {
+ const table = definitionsEncaissement[mortalite] === undefined ? definitionsEncaissement["mortel"] : definitionsEncaissement[mortalite];
+ for (let encaissement of table) {
+ if ((encaissement.minimum === undefined || encaissement.minimum <= degats)
+ && (encaissement.maximum === undefined || degats <= encaissement.maximum)) {
+ return duplicate(encaissement);
+ }
}
- return result;
+ 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
}
/* -------------------------------------------- */
diff --git a/module/tmr-utility.js b/module/tmr-utility.js
index c920d3b2..b3df2293 100644
--- a/module/tmr-utility.js
+++ b/module/tmr-utility.js
@@ -374,32 +374,7 @@ export class TMRUtility {
console.log("CAT", result);
return result;
}
-
- /* -------------------------------------------- */
- static async getSouffle( toChat ) {
- return TMRUtility.genericGetTableResult( "Souffles de Dragon", toChat);
- }
- /* -------------------------------------------- */
- static async getQueue( toChat = true) {
- return TMRUtility.genericGetTableResult( "Queues de dragon", toChat);
- }
-
- /* -------------------------------------------- */
- static async getTete( toChat = true ) {
- return TMRUtility.genericGetTableResult( "Têtes de Dragon pour haut-rêvants", toChat);
- }
-
- /* -------------------------------------------- */
- static async getTeteHR( toChat = true ) {
- return TMRUtility.genericGetTableResult( "Têtes de Dragon pour tous personnages", toChat);
- }
-
- /* -------------------------------------------- */
- static async getOmbre( toChat = true ) {
- return TMRUtility.genericGetTableResult( "Ombre de Thanatos", toChat);
- }
-
/* -------------------------------------------- */
/**
* Retourne une recontre en fonction de la case ou du tirage