From 3a29c25b093832e3d3042a92eb6dd133c66abf82 Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Fri, 23 Sep 2022 02:23:20 +0200 Subject: [PATCH] Fix: calculs des bonus de potions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Le calcul du bonus d'herbe d'une potion dépend des brins manquants. La fabrication de potion propose les nombres de brins pour avoir un effet. Impossible de faire une potion si on n'a pas assez de brins. La puissance/points de guérison des potions magiques sont affichées lors de la consomation --- module/actor.js | 3 ++- module/dialog-fabriquer-potion.js | 24 +++++++++++++++++++--- templates/chat-consommer-potion-repos.html | 2 +- templates/chat-consommer-potion-soin.html | 2 +- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/module/actor.js b/module/actor.js index f416259f..c09e2a44 100644 --- a/module/actor.js +++ b/module/actor.js @@ -4019,11 +4019,12 @@ export class RdDActor extends Actor { name: `Potion de ${herbeData.system.categorie} (${herbeData.name})`, type: 'potion', img: "systems/foundryvtt-reve-de-dragon/icons/objets/fiole_verre.webp", system: { - quantite: 1, valeur_deniers: 1, encombrement: 0.01, + quantite: 1, cout: 0, encombrement: 0.1, categorie: herbeData.system.categorie, herbe: herbeData.name, rarete: herbeData.system.rarete, herbebrins: herbeData.nbBrins, + herbebonus: herbeData.herbebonus, description: "" } } diff --git a/module/dialog-fabriquer-potion.js b/module/dialog-fabriquer-potion.js index fe4d1744..a8571c5a 100644 --- a/module/dialog-fabriquer-potion.js +++ b/module/dialog-fabriquer-potion.js @@ -6,6 +6,11 @@ export class DialogFabriquerPotion extends Dialog { /* -------------------------------------------- */ static async create(actor, item, dialogConfig) { + const min = DialogFabriquerPotion.nombreBrinsMinimum(item); + if (item.system.quantite < min) { + ui.notifications.warn(`Vous avez ${item.system.quantite} brins de ${item.name}, il en faut au moins ${min} pour faire une potion!`); + return; + } let potionData = DialogFabriquerPotion.prepareData(actor, item); let conf = { @@ -25,8 +30,11 @@ export class DialogFabriquerPotion extends Dialog { /* -------------------------------------------- */ static prepareData(actor, item) { let potionData = duplicate(item) - potionData.nbBrinsSelect = RdDUtility.buildListOptions(1, potionData.system.quantite); - potionData.nbBrins = Math.min(potionData.system.quantite, DialogFabriquerPotion.getNombreBrinOptimal(potionData)); + potionData.nbBrinsSelect = RdDUtility.buildListOptions( + DialogFabriquerPotion.nombreBrinsMinimum(item), + DialogFabriquerPotion.nombreBrinsOptimal(item)); + potionData.nbBrins = Math.min(potionData.system.quantite, DialogFabriquerPotion.nombreBrinsOptimal(potionData)); + potionData.herbebonus = item.system.niveau; potionData.buttonName = "Fabriquer"; return potionData; } @@ -45,7 +53,15 @@ export class DialogFabriquerPotion extends Dialog { this.potionData = potionData; } - static getNombreBrinOptimal(herbeData) { + static nombreBrinsMinimum(herbeData) { + switch (herbeData.system.categorie ?? '') { + case "Soin": return 1 + Math.max(0, 12 - 2 * herbeData.system.niveau); + case "Repos": return 1 + Math.max(0, 7 - 2 * herbeData.system.niveau); + } + return 1; + } + + static nombreBrinsOptimal(herbeData) { switch (herbeData.system.categorie ?? '') { case "Soin": return 12 - herbeData.system.niveau; case "Repos": return 7 - herbeData.system.niveau; @@ -59,6 +75,8 @@ export class DialogFabriquerPotion extends Dialog { html.find("#nbBrins").change(event => { this.potionData.nbBrins = Misc.toInt(event.currentTarget.value); + const brinsManquants = Math.max(0, DialogFabriquerPotion.nombreBrinsOptimal(this.potionData) - this.potionData.nbBrins); + this.potionData.herbebonus = Math.max(0, this.potionData.system.niveau - brinsManquants) }); } diff --git a/templates/chat-consommer-potion-repos.html b/templates/chat-consommer-potion-repos.html index e8c37969..047eac78 100644 --- a/templates/chat-consommer-potion-repos.html +++ b/templates/chat-consommer-potion-repos.html @@ -1,6 +1,6 @@ potion de repos

- {{alias}} a bu une {{name}}{{#if system.magique}} enchantée{{/if}} + {{alias}} a bu une {{name}}{{#if system.magique}} enchantée de puissance {{system.puissance}}{{/if}}.


diff --git a/templates/chat-consommer-potion-soin.html b/templates/chat-consommer-potion-soin.html index d691fc48..f5bf828c 100644 --- a/templates/chat-consommer-potion-soin.html +++ b/templates/chat-consommer-potion-soin.html @@ -1,6 +1,6 @@ potion de soin

- {{alias}} a bu une {{name}}{{#if system.magique}} enchantée{{/if}} + {{alias}} a bu une {{name}}{{#if system.magique}} enchantée de {{system.puissance}} points de guérison{{/if}}