Gestion des signes draconiques #455

Closed
vincent.vandeme wants to merge 233 commits from v1.4-signes-draconiques into master
3 changed files with 34 additions and 24 deletions
Showing only changes of commit e8626f3566 - Show all commits

View File

@ -546,7 +546,7 @@ export class RdDActorSheet extends ActorSheet {
this.render(true); this.render(true);
}); });
html.find('#ethylisme-test').click((event) => { html.find('#ethylisme-test').click((event) => {
this.actor.ethylismeTest(); this.actor.jetEthylisme();
this.render(true); this.render(true);
}); });

View File

@ -227,8 +227,14 @@ export class RdDActor extends Actor {
return Misc.toInt(Misc.templateData(this).attributs.protection.value); return Misc.toInt(Misc.templateData(this).attributs.protection.value);
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
getEtatGeneral() { getEtatGeneral(options = { ethylisme: false }) {
return Misc.toInt(Misc.templateData(this).compteurs.etat?.value); const tplData = Misc.templateData(this);
let etatGeneral = Misc.toInt(tplData.compteurs.etat?.value);
if (options.ethylisme) {
// Pour les jets d'Ethylisme, on ignore le degré d'éthylisme (p.162)
etatGeneral -= Math.min(0, tplData.compteurs.ethylisme.value);
}
return etatGeneral;
} }
getMalusArmure() { getMalusArmure() {
return Misc.toInt(Misc.templateData(this).attributs?.malusarmure?.value); return Misc.toInt(Misc.templateData(this).attributs?.malusarmure?.value);
@ -1461,8 +1467,8 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */ /* -------------------------------------------- */
_calculAjustementMoral(succes, moral, situation) { _calculAjustementMoral(succes, moral, situation) {
switch (situation) { switch (situation) {
case 'heureuse': return succes ? 1 : 0; case 'heureux': case 'heureuse': return succes ? 1 : 0;
case 'malheureuse': return succes ? 0 : -1; case 'malheureuse': case 'malheureux': return succes ? 0 : -1;
case 'neutre': case 'neutre':
if (succes && moral <= 0) return 1; if (succes && moral <= 0) return 1;
if (!succes && moral > 0) return -1; if (!succes && moral > 0) return -1;
@ -1482,19 +1488,18 @@ export class RdDActor extends Actor {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
async ethylismeTest() { async jetEthylisme(forceAlcool = 0) {
const actorData = Misc.data(this); const actorData = Misc.data(this);
let rollData = { let rollData = {
vieValue: actorData.data.sante.vie.value, vieValue: actorData.data.sante.vie.value,
etat: this.getEtatGeneral() - Math.min(0, actorData.data.compteurs.ethylisme.value), // Pour les jets d'Ethylisme, on ignore le degré d'éthylisme (p.162) forceAlcool: forceAlcool,
etat: this.getEtatGeneral({ ethylisme: true }),
diffNbDoses: -Number(actorData.data.compteurs.ethylisme.nb_doses || 0), diffNbDoses: -Number(actorData.data.compteurs.ethylisme.nb_doses || 0),
finalLevel: 0, finalLevel: 0,
diffConditions: 0, diffConditions: 0
ajustementsConditions: CONFIG.RDD.ajustementsConditions,
forceAlcool: 0
} }
let html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-roll-ethylisme.html', rollData); let html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-roll-ethylisme.html', rollData);
new RdDRollDialogEthylisme(html, rollData, this).render(true); new RdDRollDialogEthylisme(html, rollData, this, r => this.performEthylisme(r)).render(true);
} }
/* -------------------------------------------- */ /* -------------------------------------------- */

View File

@ -8,34 +8,39 @@ import { Misc } from "./misc.js";
export class RdDRollDialogEthylisme extends Dialog { export class RdDRollDialogEthylisme extends Dialog {
/* -------------------------------------------- */ /* -------------------------------------------- */
constructor(html, rollData, actor) { constructor(html, rollData, actor, onRoll) {
let myButtons = {
rollButton: { label: "Test d'éthylisme", callback: html => this.actor.performEthylisme(this.rollData) }
};
// Common conf // Common conf
let dialogConf = { content: html, title: "Test d'éthylisme", buttons: myButtons, default: "rollButton" }; let dialogConf = {
let dialogOptions = { classes: ["rdddialog"], width: 400, height: 220, 'z-index': 99999 } title: "Test d'éthylisme",
content: html,
default: "rollButton",
buttons: { "rollButton": { label: "Test d'éthylisme", callback: html => this.onButton(html) } }
};
let dialogOptions = { classes: ["rdddialog"], width: 400, height: 220, 'z-index': 99999 }
super(dialogConf, dialogOptions) super(dialogConf, dialogOptions)
//console.log("ETH", rollData); //console.log("ETH", rollData);
this.onRoll = onRoll;
this.rollData = rollData; this.rollData = rollData;
this.actor = actor; this.actor = actor;
} }
async onButton(html) {
this.onRoll(this.rollData);
}
/* -------------------------------------------- */ /* -------------------------------------------- */
activateListeners(html) { activateListeners(html) {
super.activateListeners(html); super.activateListeners(html);
this.bringToTop(); // Ensure top level this.bringToTop(); // Ensure top level
// Get the rollData stuff // Get the rollData stuff
var rollData = this.rollData; var rollData = this.rollData;
function updateRollResult(rollData) { function updateRollResult(rollData) {
rollData.finalLevel = Number(rollData.etat) + Number(rollData.forceAlcool) + rollData.diffNbDoses; rollData.finalLevel = Number(rollData.etat) + Number(rollData.forceAlcool) + rollData.diffNbDoses;
// Mise à jour valeurs // Mise à jour valeurs
$("#roll-param").text(rollData.vieValue + " / " + Misc.toSignedString(rollData.finalLevel)); $("#roll-param").text(rollData.vieValue + " / " + Misc.toSignedString(rollData.finalLevel));
$(".table-resolution").remove(); $(".table-resolution").remove();
@ -47,7 +52,7 @@ export class RdDRollDialogEthylisme extends Dialog {
$("#forceAlcool").val(Misc.toInt(rollData.forceAlcool)); $("#forceAlcool").val(Misc.toInt(rollData.forceAlcool));
updateRollResult(rollData); updateRollResult(rollData);
}); });
// Update ! // Update !
html.find('#forceAlcool').change((event) => { html.find('#forceAlcool').change((event) => {
rollData.forceAlcool = Misc.toInt(event.currentTarget.value); // Update the selected bonus/malus rollData.forceAlcool = Misc.toInt(event.currentTarget.value); // Update the selected bonus/malus