Merge branch 'working' into 'master'

Encaissement non mortel et petits fixes

See merge request LeRatierBretonnien/foundryvtt-reve-de-dragon!7
This commit is contained in:
Leratier Bretonnien 2020-11-11 08:34:39 +00:00
commit c7dc3b95eb
6 changed files with 164 additions and 141 deletions

View File

@ -204,8 +204,8 @@ export class RdDActor extends Actor {
rollData.domArmePlusDom += parseInt(this.data.data.attributs.plusdom.value); rollData.domArmePlusDom += parseInt(this.data.data.attributs.plusdom.value);
if ( rollData.selectedCarac.label == "Lancer" ) { // +dom only for Melee/Lancer if ( rollData.selectedCarac.label == "Lancer" ) { // +dom only for Melee/Lancer
let bdom = parseInt(this.data.data.attributs.plusdom.value); let bdom = parseInt(this.data.data.attributs.plusdom.value);
if ( bdom > parseInt(rollData.arme.data.dommages)*2 ) if ( bdom > parseInt(rollData.arme.data.dommages))
bdom = parseInt(rollData.arme.data.dommages)*2; bdom = parseInt(rollData.arme.data.dommages);
rollData.domArmePlusDom += bdom rollData.domArmePlusDom += bdom
} }
rollData.degats = parseInt(myroll.result) + rollData.domArmePlusDom; rollData.degats = parseInt(myroll.result) + rollData.domArmePlusDom;
@ -717,7 +717,7 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */ /* -------------------------------------------- */
rollArme( armeName ) 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 ) if ( armeItem && armeItem.data.competence )
this.rollCompetence( armeItem.data.competence, armeItem ); this.rollCompetence( armeItem.data.competence, armeItem );
else else
@ -815,51 +815,32 @@ export class RdDActor extends Actor {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
encaisserDommages( attackerRoll ) encaisserDommages( attackerRoll ) {
{ console.log("encaisserDommages", attackerRoll )
//let attackerRoll = rollData.attackerRoll; const armure = this.computeArmure( attackerRoll.loc, attackerRoll.domArmePlusDom);
let degatsReel = attackerRoll.degats - this.computeArmure(attackerRoll.loc, attackerRoll.domArmePlusDom); let degatsReel = attackerRoll.degats - armure;
console.log("RollData from attacker!", attackerRoll, degatsReel);
let result = RdDUtility.computeBlessuresSante(degatsReel); let result = RdDUtility.computeBlessuresSante(degatsReel, attackerRoll.mortalite);
this.santeIncDec("vie", result.vie); this.santeIncDec("vie", result.vie);
this.santeIncDec("endurance", result.endurance); this.santeIncDec("endurance", result.endurance);
result.locName = attackerRoll.loc.label;
result.locName = attackerRoll.loc.label; // Add the localisation namme this.manageBlessures(result); // Will upate the result table
this.manageBlessures( result ); // Will upate the result table const blessureLegere = (result.legeres > 0 ? "une blessure légère" : "");
ChatMessage.create( {title: "Blessures !", content: this.data.name + " a encaissé : " + const blessureGrave = (result.graves > 0 ? "une blessure grave" : "");
"<br>Encaissement final : " + degatsReel + const blessureCritique = (result.critiques > 0 ? "une blessure critique" : "");
"<br>" + result.legeres + " légères, " + result.graves + " graves et " + ChatMessage.create({
result.critiques + " critique." + title: "Blessures !", content: this.data.name + " a encaissé : " +
"<br>Et perdu : " + "<br>Encaissement final : " + degatsReel +
"<br>" + result.endurance + " Endurance et " + result.vie + " Points de Vie" } ); "<br>" + blessureLegere + blessureGrave + blessureCritique +
"<br>Et a perdu : " +
"<br>" + result.endurance + " Endurance et " + result.vie + " Points de Vie"
});
this.computeEtatGeneral(); this.computeEtatGeneral();
this.sheet.render(true); 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é : " +
"<br>Encaissement final : " + degatsReel +
"<br>" + result.legeres + " légères, " + result.graves + " graves et " +
result.critiques + " critique." +
"<br>Et perdu : " +
"<br>" + result.endurance + " Endurance et " + result.vie + " Points de Vie" } );
this.computeEtatGeneral();
this.sheet.render(true);
}
/* -------------------------------------------- */ /* -------------------------------------------- */
parerAttaque( attackerRoll, armeId ) parerAttaque( attackerRoll, armeId )

View File

@ -2,49 +2,52 @@
* Extend the base Dialog entity by defining a custom window to perform roll. * Extend the base Dialog entity by defining a custom window to perform roll.
* @extends {Dialog} * @extends {Dialog}
*/ */
export class RdDEncaisser extends Dialog { export class RdDEncaisser extends Dialog {
/* -------------------------------------------- */ /* -------------------------------------------- */
constructor(html, actor) { constructor(html, actor) {
let myButtons = { rollButton: {
label: "Lancer",
callback: html => this.performEncaisser(html, false)
} };
// Common conf // Common conf
let dialogConf = { let dialogConf = {
title: "Jet d'Encaissement",
content: html, content: html,
buttons: myButtons, buttons: {
default: "rollButton" "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"],
width: 320,
height: 240
} }
let dialogOptions = { classes: [ "rdddialog"] }
// Select proper roll dialog template and stuff // Select proper roll dialog template and stuff
dialogConf.title = "Jet d'Encaissement",
dialogOptions.width = 320;
dialogOptions.height = 160;
super(dialogConf, dialogOptions); super(dialogConf, dialogOptions);
this.actor = actor; this.actor = actor;
this.modifier = 0; this.modifier = 0;
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
performEncaisser (html, isReserve=false) { performEncaisser(html, mortalite = "mortel") {
//console.log("On va encaisser !!", this.modifier); this.actor.encaisserDommages({
let result = Number(new Roll("2d10").roll().result); degats: new Roll("2d10").roll().total,
result += Number(this.modifier); domArmePlusDom: Number(this.modifier),
this.actor.encaisserDommagesHorsCombat(result); loc: { result: 0, label: "Corps" },
//console.log("ENCAISSER:", result); mortalite: mortalite
});
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
activateListeners(html) { activateListeners(html) {
super.activateListeners(html); super.activateListeners(html);
// Setup everything onload // Setup everything onload
$(function() { $(function () {
$("#modificateurDegats").val( "0" ); $("#modificateurDegats").val("0");
}); });
html.find('#modificateurDegats').click((event) => { html.find('#modificateurDegats').click((event) => {

45
module/rdd-rolltables.js Normal file
View File

@ -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);
}
}

View File

@ -4,6 +4,7 @@
*/ */
import { RdDUtility } from "./rdd-utility.js"; import { RdDUtility } from "./rdd-utility.js";
import { TMRUtility } from "./tmr-utility.js"; import { TMRUtility } from "./tmr-utility.js";
import { RdDRollTables } from "./rdd-rolltables.js";
/** Helper functions */ /** Helper functions */
export class RdDTMRDialog extends Dialog { export class RdDTMRDialog extends Dialog {
@ -119,7 +120,7 @@ export class RdDTMRDialog extends Dialog {
let result = await this.actor.ajouterRefoulement(1); let result = await this.actor.ajouterRefoulement(1);
this.updatePreviousRencontres(); this.updatePreviousRencontres();
if (result == "souffle") { if (result == "souffle") {
let souffle = TMRUtility.getSouffle(); let souffle = RdDRollTables.getSouffle();
} }
console.log("-> refouler", this.currentRencontre) console.log("-> refouler", this.currentRencontre)
this.updateValuesDisplay(); this.updateValuesDisplay();
@ -245,7 +246,7 @@ export class RdDTMRDialog extends Dialog {
if ( result > scoreDef.score ) { if ( result > scoreDef.score ) {
content = "Vous êtes entré sur une case humide, et vous avez <strong>raté</strong> votre maîtrise ! Vous <strong>quittez les Terres Médianes</strong> ! ("+ draconic.name +") :" + carac + " / " + level + " -> " + result + " / " + scoreDef.score; content = "Vous êtes entré sur une case humide, et vous avez <strong>raté</strong> votre maîtrise ! Vous <strong>quittez les Terres Médianes</strong> ! ("+ draconic.name +") :" + carac + " / " + level + " -> " + result + " / " + scoreDef.score;
if ( result >= scoreDef.etotal ) { if ( result >= scoreDef.etotal ) {
let souffle = TMRUtility.getSouffle(true); let souffle = RdDRollTables.getSouffle(true);
content += "<br>Vous avez fait un Echec Total. Vous subissez un Souffle de Dragon : " + souffle.name ; content += "<br>Vous avez fait un Echec Total. Vous subissez un Souffle de Dragon : " + souffle.name ;
this.actor.createOwnedItem( souffle ); this.actor.createOwnedItem( souffle );
} }

View File

@ -2,6 +2,7 @@
import { RdDActor } from "./actor.js"; import { RdDActor } from "./actor.js";
import { TMRUtility } from "./tmr-utility.js"; import { TMRUtility } from "./tmr-utility.js";
import { RdDRollTables } from "./rdd-rolltables.js";
const level_category = { const level_category = {
"generale": "-4", "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 }, "difficile": { "4":3, "6":4, "8":6 },
"tresdifficile": { "4":4, "6":6 } } "tresdifficile": { "4":4, "6":6 } }
/* Static tables for commands /table */ /* Static tables for commands /table */
const table2func = { "queues": {descr: "queues : Tire une queue de Dragon", func: TMRUtility.getQueue}, const table2func = { "queues": {descr: "queues : Tire une queue de Dragon", func: RdDRollTables.getQueue},
"ombre": { descr: "ombre: Tire une Ombre de Dragon", func: TMRUtility.getOmbre }, "ombre": { descr: "ombre: Tire une Ombre de Dragon", func: RdDRollTables.getOmbre },
"tetehr": {descr: "tetehr: Tire une Tête de Dragon pour Hauts Revants", fund: TMRUtility.getTeteHR}, "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: TMRUtility.getTete}, "tete" : { descr: "tete: Tire une Tête de Dragon", func: RdDRollTables.getTete},
"souffle": { descr: "souffle: Tire un Souffle de Dragon", func: TMRUtility.getSouffle} }; "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 { export class RdDUtility {
@ -402,39 +428,31 @@ export class RdDUtility {
return { result: result, label: txt }; return { result: result, label: txt };
} }
/* -------------------------------------------- */ static computeBlessuresSante( degats, mortalite="mortel" ) {
static computeBlessuresSante( degats ) let encaissement = RdDUtility.selectEncaissement(degats, mortalite)
{ let over20 = degats > 20 ? degats - 20 : 0
console.log("Degats !!", degats); encaissement.endurance = - RdDUtility._evaluatePerte(encaissement.endurance, over20)
let result = { vie: 0, encaissement.vie = - RdDUtility._evaluatePerte(encaissement.vie, degats, over20)
endurance: 0, return encaissement;
legeres: 0, }
graves: 0,
critiques: 0
};
if ( degats < 11 ) { static selectEncaissement( degats, mortalite ) {
result.type = "contusion"; const table = definitionsEncaissement[mortalite] === undefined ? definitionsEncaissement["mortel"] : definitionsEncaissement[mortalite];
let myroll = new Roll("1d4").roll(); for (let encaissement of table) {
result.endurance = -myroll.result; if ((encaissement.minimum === undefined || encaissement.minimum <= degats)
} else if ( degats < 16 ) { && (encaissement.maximum === undefined || degats <= encaissement.maximum)) {
result.type = "blessure légère"; return duplicate(encaissement);
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;
} }
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
} }
/* -------------------------------------------- */ /* -------------------------------------------- */

View File

@ -375,31 +375,6 @@ export class TMRUtility {
return 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 * Retourne une recontre en fonction de la case ou du tirage