diff --git a/module/actor-sheet.js b/module/actor-sheet.js index e050bacf..71515a82 100644 --- a/module/actor-sheet.js +++ b/module/actor-sheet.js @@ -381,6 +381,10 @@ export class RdDActorSheet extends ActorSheet { this.actor.stressTest(); this.render(true); }); + html.find('#ethylisme-test').click((event) => { + this.actor.ethylismeTest(); + this.render(true); + }); html.find('#vie-plus').click((event) => { this.actor.santeIncDec("vie", 1); diff --git a/module/actor.js b/module/actor.js index cc9d99e0..5cb8a8ef 100644 --- a/module/actor.js +++ b/module/actor.js @@ -6,6 +6,7 @@ import { RdDUtility } from "./rdd-utility.js"; import { TMRUtility } from "./tmr-utility.js"; import { RdDRollDialog } from "./rdd-roll-dialog.js"; +import { RdDRollDialogEthylisme } from "./rdd-roll-ethylisme.js"; import { RdDTMRDialog } from "./rdd-tmr-dialog.js"; import { Misc } from "./misc.js"; @@ -1160,6 +1161,43 @@ export class RdDActor extends Actor { this.update( { "data.blessures": blessures } ); } + /* -------------------------------------------- */ + async ethylismeTest() { + let rollData = { + vieValue: this.data.data.sante.vie.value, + etat: this.data.data.compteurs.etat.value, + niveauEthylisme: this.data.data.compteurs.ethylisme.value, + nbDoses: this.data.data.compteurs.ethylisme.nb_doses || 0, + finalLevel: 0, + diffConditions: 0, + ajustementsConditions: CONFIG.RDD.ajustementsConditions, + forceAlcool: 0 + } + let html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-roll-ethylisme.html', rollData); + new RdDRollDialogEthylisme(html, rollData, this ).render(true); + } + + /* -------------------------------------------- */ + async performEthylisme( rollData ) { + let ethylisme = duplicate(this.data.data.compteurs.ethylisme); + let roll = await RdDResolutionTable.roll( rollData.vieValue, rollData.finalLevel); + let msgText; + if (roll.isSuccess ) { + ethylisme.value = ethylisme.value - 1; + msgText = "Vous avez échouez à votre jet d'éthylisme, votre niveau d'éthylisme est de " + ethylisme.value + + "(" + RdDUtility.getNomEthylisme(ethylisme.value) + ")"; + } else { + ethylisme.nb_doses = ethylisme.nb_doses + 1; + msgText = "Vous avez réussitvotre jet d'éthylisme, votre vous avez désormais " + ethylisme.nb_doses + " doses sans effet."; + } + const message = { + content: msgText, + whisper: ChatMessage.getWhisperRecipients(game.user.name) + }; + ChatMessage.create(message); + + } + /* -------------------------------------------- */ async stressTest() { const message = { @@ -1171,6 +1209,7 @@ export class RdDActor extends Actor { ChatMessage.create(message); } + /* -------------------------------------------- */ async transformerStress(message) { const stress = Misc.toInt(this.data.data.compteurs.stress.value); if (stress<=0) { diff --git a/module/rdd-roll-ethylisme.js b/module/rdd-roll-ethylisme.js new file mode 100644 index 00000000..ca8918ba --- /dev/null +++ b/module/rdd-roll-ethylisme.js @@ -0,0 +1,58 @@ +import { RdDResolutionTable } from "./rdd-resolution-table.js"; +import { Misc } from "./misc.js"; + +/** + * Extend the base Dialog entity by defining a custom window to perform roll. + * @extends {Dialog} + */ +export class RdDRollDialogEthylisme extends Dialog { + + /* -------------------------------------------- */ + constructor(html, rollData, actor) { + + let myButtons = { + rollButton: { label: "Lancer", callback: html => this.actor.performEthylisme(this.rollData) } + }; + + // Common conf + let dialogConf = { content: html, title: "Test d'éthylisme", buttons: myButtons, default: "rollButton" }; + let dialogOptions = { classes: ["rdddialog"], width: 400, height: 400, 'z-index': 99999 } + super(dialogConf, dialogOptions) + + console.log("ETH", rollData); + this.rollData = rollData; + this.actor = actor; + } + + /* -------------------------------------------- */ + activateListeners(html) { + super.activateListeners(html); + + this.bringToTop(); // Ensure top level + // Get the rollData stuff + var rollData = this.rollData; + + function updateRollResult(rollData) { + let rollLevel = Number(rollData.etat) + Number(rollData.forceAlcool) + Number(rollData.niveauEthylisme) - Number(rollData.nbDoses); + rollData.finalLevel = rollLevel; + + // Mise à jour valeurs + $("#roll-param").text(rollData.vieValue + " / " + Misc.toSignedString(rollData.finalLevel)); + $(".table-resolution").remove(); + $("#resolutionTable").append(RdDResolutionTable.buildHTMLTableExtract(rollData.vieValue, rollLevel)); + } + + // Setup everything onload + $(function () { + $("#forceAlcool").val(Misc.toInt(rollData.forceAlcool)); + updateRollResult(rollData); + }); + + // Update ! + html.find('#forceAlcool').change((event) => { + rollData.forceAlcool = Misc.toInt(event.currentTarget.value); // Update the selected bonus/malus + updateRollResult(rollData); + }); + } + +} diff --git a/module/rdd-utility.js b/module/rdd-utility.js index d35ff7c1..89a71d77 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -190,6 +190,11 @@ export class RdDUtility { return []; } + /* -------------------------------------------- */ + getNomEthylisme( niveauEthylisme ) { + + } + /* -------------------------------------------- */ static initAfficheContenu( actorId ) { // persistent handling of conteneur show/hide if ( !this.afficheContenu ) diff --git a/system.json b/system.json index c8936a38..3b2a594b 100644 --- a/system.json +++ b/system.json @@ -5,7 +5,7 @@ "version": "1.1.0", "minimumCoreVersion": "0.7.5", "compatibleCoreVersion": "0.7.7", - "templateVersion": 56, + "templateVersion": 58, "author": "LeRatierBretonnien", "esmodules": [ "module/rdd-main.js", "module/hook-renderChatLog.js" ], "styles": ["styles/simple.css"], diff --git a/template.json b/template.json index 33853851..84fe1ec5 100644 --- a/template.json +++ b/template.json @@ -488,7 +488,8 @@ "ethylisme": { "value": 0, "label": "Ethylisme", - "isInput": true + "isInput": true, + "nb_doses": 0 }, "stress": { "value": 0, diff --git a/templates/actor-sheet.html b/templates/actor-sheet.html index 621b2a45..7a6af26f 100644 --- a/templates/actor-sheet.html +++ b/templates/actor-sheet.html @@ -346,8 +346,13 @@ {{#if compteur.isStress}} Faire un jet de Stress {{else}} + {{#if (eq compteur.label 'Ethylisme')}} + Faire un jet d'Ethylisme + {{else}} - {{/if}} + {{/if}} + + {{/if}} {{else}} {{compteur.value}} diff --git a/templates/dialog-roll-ethylisme.html b/templates/dialog-roll-ethylisme.html new file mode 100644 index 00000000..2316bb2a --- /dev/null +++ b/templates/dialog-roll-ethylisme.html @@ -0,0 +1,27 @@ +
+

+ +
+ + +
+ +
+ + +
+ +
+     +
+ +
+
+ +
diff --git a/templates/dialog-roll-sort.html b/templates/dialog-roll-sort.html index 98e86d83..e52f2e5f 100644 --- a/templates/dialog-roll-sort.html +++ b/templates/dialog-roll-sort.html @@ -2,7 +2,7 @@

- +