diff --git a/module/actor-sheet.js b/module/actor-sheet.js index a8bc4f28..15f9adf5 100644 --- a/module/actor-sheet.js +++ b/module/actor-sheet.js @@ -257,11 +257,11 @@ export class RdDActorSheet extends ActorSheet { const li = $(ev.currentTarget).parents(".item"); RdDUtility.confirmerSuppression(this, li); }); - html.find('.item-consommer').click(ev => { + html.find('.item-action').click(ev => { const li = $(ev.currentTarget).parents(".item"); const itemId = li.data("item-id"); const item = this.actor.getObjet(itemId); - this.actor.consommerDialog(item); + this.actor.actionItem(item); }); html.find('.subacteur-delete').click(ev => { const li = $(ev.currentTarget).parents(".item"); diff --git a/module/actor.js b/module/actor.js index 22b5f7d9..a1c03135 100644 --- a/module/actor.js +++ b/module/actor.js @@ -27,7 +27,6 @@ import { EffetsDraconiques } from "./tmr/effets-draconiques.js"; import { Draconique } from "./tmr/draconique.js"; import { RdDCarac } from "./rdd-carac.js"; import { Monnaie } from "./item-monnaie.js"; -import { RdDHerbes } from "./rdd-herbes.js"; import { DialogConsommer } from "./dialog-consommer.js"; import { DialogFabriquerPotion } from "./dialog-fabriquer-potion.js"; @@ -313,7 +312,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async verifierPotionsEnchantees() { - let potionsEnchantees = this.filterItemsData(it => it.type == 'potion' && it.data.categorie.toLowerCase().includes('enchante')); + let potionsEnchantees = this.filterItemsData(it => it.type == 'potion' && it.data.isEnchante); for (let potion of potionsEnchantees) { if (!potion.prpermanent) { console.log(potion); @@ -743,7 +742,6 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async updateCreatureCompetence(compName, fieldName, compValue) { let comp = this.getCompetence(compName); - //console.log(comp); if (comp) { const update = { _id: comp.id } if (fieldName == "niveau") @@ -752,7 +750,6 @@ export class RdDActor extends Actor { update['data.dommages'] = compValue; else update['data.carac_value'] = compValue; - //console.log(update); const updated = await this.updateEmbeddedDocuments('Item', [update]); // Updates one EmbeddedEntity } } @@ -1610,8 +1607,8 @@ export class RdDActor extends Actor { } /* -------------------------------------------- */ - async consommerDialog(item) { - if (!item.isConsommable()) return; + async actionItem(item) { + if (!item.getActionPrincipale()) return; const dialog = await DialogConsommer.create(this, item); dialog.render(true) } @@ -1648,7 +1645,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async manger(item, doses, options = { diminuerQuantite: true }) { - if (!item.isConsommable()) return; + if (!item.getActionPrincipale()) return; await this.apprecierCuisine(item); const sust = Misc.templateData(item).sust; if (sust > 0) { @@ -1656,10 +1653,10 @@ export class RdDActor extends Actor { } await item.diminuerQuantite(doses, options); } - + /* -------------------------------------------- */ async boire(item, doses, options = { diminuerQuantite: true }) { - if (!item.isConsommable()) return; + if (!item.getActionPrincipale()) return; const tplData = Misc.templateData(item); const desaltere = tplData.desaltere; if (desaltere > 0) { @@ -3278,10 +3275,7 @@ export class RdDActor extends Actor { async consommerPotionSoin(potionData) { potionData.alias = this.name; - if (potionData.data.categorie.includes('Enchante')) { - potionData.pointsGuerison = RdDHerbes.calculePointsGuerison(potionData.data); - potionData.enchanteTexte = "enchantée"; - potionData.isEnchante = true; + if (potionData.data.isEnchante) { ChatMessage.create({ whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name), content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-consommer-potion-soin.html`, potionData) @@ -3291,7 +3285,7 @@ export class RdDActor extends Actor { potionData.reussiteReve = false; if (!rolled.isSuccess) { await this.reveActuelIncDec(-1); - potionData.guerisonData = await this.buildPotionGuerisonList(potionData.pointsGuerison); + potionData.guerisonData = await this.buildPotionGuerisonList(potionData.data.puissance); potionData.guerisonMinutes = potionData.guerisonData.pointsConsommes * 5; potionData.reussiteReve = true; } @@ -3300,8 +3294,6 @@ export class RdDActor extends Actor { content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-appliquer-potion-soin.html`, potionData) }); } else { - potionData.enchanteTexte = ""; - potionData.isEnchante = false; ChatMessage.create({ whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name), content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-appliquer-potion-soin.html`, potionData) @@ -3314,10 +3306,7 @@ export class RdDActor extends Actor { async consommerPotionRepos(potionData) { potionData.alias = this.name; - if (potionData.data.categorie.includes('Enchante')) { - potionData.casesRepos = RdDHerbes.calculePointsRepos(potionData.data); - potionData.enchanteTexte = "enchantée"; - potionData.isEnchante = true; + if (potionData.data.isEnchante) { ChatMessage.create({ whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name), content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-consommer-potion-repos.html`, potionData) @@ -3328,7 +3317,7 @@ export class RdDActor extends Actor { if (!rolled.isSuccess) { await this.reveActuelIncDec(-1); let fatigueActuelle = this.getFatigueActuelle(); - potionData.caseFatigueReel = (fatigueActuelle >= potionData.casesRepos) ? potionData.casesRepos : fatigueActuelle; + potionData.caseFatigueReel = Math.min(fatigueActuelle, potionData.data.puissance); potionData.guerisonDureeUnite = (potionData.data.reposalchimique) ? "rounds" : "minutes"; potionData.guerisonDureeValue = (potionData.data.reposalchimique) ? potionData.caseFatigueReel : potionData.caseFatigueReel * 5; potionData.reussiteReve = true; @@ -3346,8 +3335,6 @@ export class RdDActor extends Actor { content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-appliquer-potion-repos.html`, potionData) }); } else { - potionData.enchanteTexte = ""; - potionData.isEnchante = false; ChatMessage.create({ whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name), content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-appliquer-potion-repos.html`, potionData) @@ -3386,13 +3373,7 @@ export class RdDActor extends Actor { nbBrinsPotion: herbeData.nbBrins, nbBrinsReste: newQuantite } - // TODO: - if (newQuantite == 0) { - await this.deleteEmbeddedDocuments('Item', [herbeData._id]); - } else { - let update = { _id: herbeData._id, 'data.quantite': newQuantite }; - await this.updateEmbeddedDocuments('Item', [update]); // Updates one EmbeddedEntity - } + this.getObjet(herbeData._id).diminuerQuantite(herbeData.nbBrins); ChatMessage.create({ whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name), content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-fabriquer-potion-base.html`, messageData) @@ -3404,13 +3385,6 @@ export class RdDActor extends Actor { async consommerPotionGenerique(potionData) { potionData.alias = this.name; - if (potionData.data.categorie.includes('Enchante')) { - potionData.enchanteTexte = "enchantée"; - potionData.isEnchante = true; - } else { - potionData.enchanteTexte = ""; - potionData.isEnchante = false; - } ChatMessage.create({ whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name), content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-consommer-potion-generique.html`, potionData) diff --git a/module/dialog-consommer.js b/module/dialog-consommer.js index 37584bd5..d0bc81c5 100644 --- a/module/dialog-consommer.js +++ b/module/dialog-consommer.js @@ -48,7 +48,7 @@ export class DialogConsommer extends Dialog { consommerData.buttonName = itemData.data.boisson ? "Boire" : "Manger"; break; case 'potion': - buttonName.title = `${itemData.name}: boire la potion`; + consommerData.title = `${itemData.name}: boire la potion`; consommerData.buttonName = "Boire"; break; } diff --git a/module/item.js b/module/item.js index 38b04f82..e41bbabb 100644 --- a/module/item.js +++ b/module/item.js @@ -1,3 +1,4 @@ +import { Grammar } from "./grammar.js"; import { Misc } from "./misc.js"; import { RdDUtility } from "./rdd-utility.js"; @@ -17,9 +18,26 @@ export class RdDItem extends Item { prepareDerivedData() { super.prepareDerivedData(); - if (RdDItem.getTypeObjetsEquipement().includes(Misc.data(this).type)) { + const itemData = Misc.data(this); + if (RdDItem.getTypeObjetsEquipement().includes(itemData.type)) { this._calculsEquipement(); } + if (itemData.type == 'potion') { + this.prepareDataPotion() + } + itemData.data.actionPrincipale = this.getActionPrincipale({ warnIfNot: false }); + + } + + prepareDataPotion() { + const tplData = Misc.templateData(this); + const categorie = Grammar.toLowerCaseNoAccent(tplData.categorie); + tplData.isEnchante = categorie.includes('enchante'); + if (tplData.isEnchante) { + if (categorie.includes('soin') || categorie.includes('repos')) { + tplData.puissance = tplData.herbebonus * tplData.pr; + } + } } _calculsEquipement() { @@ -36,32 +54,30 @@ export class RdDItem extends Item { getEnc() { const itemData = Misc.data(this); - switch (itemData.type) - { + switch (itemData.type) { case 'herbe': return encBrin; } return itemData.data.encombrement } - isConsommable(options = { warnIfNot: true }) { + getActionPrincipale(options = { warnIfNot: true }) { const itemData = Misc.data(this); if ((itemData.data.quantite ?? 0) <= 0) { if (options.warnIfNot) { ui.notifications.warn(`Vous n'avez plus de ${itemData.name}.`); } - return false; + return undefined; } - switch (itemData.type) { - case 'nourritureboisson': - case 'potion': - return true; + case 'nourritureboisson': return itemData.data.boisson ? 'Boire' : 'Manger'; + case 'potion': return 'Boire'; } if (options.warnIfNot) { - ui.notifications.warn(`Impossible de consommer un ${itemData.name}, ce n'est pas commestible.`); + ui.notifications.warn(`Impossible d'utilise un ${itemData.name}, aucune action associée définie.`); } - return false; + + return undefined; } isAlcool() { diff --git a/module/rdd-herbes.js b/module/rdd-herbes.js index cded07e6..e1b31911 100644 --- a/module/rdd-herbes.js +++ b/module/rdd-herbes.js @@ -48,16 +48,6 @@ export class RdDHerbes extends Item { formData.isRepos = true; this.computeHerbeBonus(formData, this.herbesRepos, 7); } - - if (formData.data.categorie.includes('Enchante') ) { - formData.isEnchante = true; - if ( formData.isHerbe) { - formData.pointsGuerison = this.calculePointsGuerison( formData.data ); - } - if ( formData.isRepos) { - formData.caseRepos = formData.data.herbebonus * formData.data.pr; - } - } } /* -------------------------------------------- */ diff --git a/templates/actor-inventaire-conteneur.html b/templates/actor-inventaire-conteneur.html index b925a479..da3789c0 100644 --- a/templates/actor-inventaire-conteneur.html +++ b/templates/actor-inventaire-conteneur.html @@ -14,8 +14,8 @@ {{/unless}} - {{#if (eq item.type 'nourritureboisson')}} - Consommer + {{#if item.data.actionPrincipale}} + {{item.data.actionPrincipale}} {{/if}} diff --git a/templates/chat-consommer-potion-generique.html b/templates/chat-consommer-potion-generique.html index 23c1946b..8f2b5838 100644 --- a/templates/chat-consommer-potion-generique.html +++ b/templates/chat-consommer-potion-generique.html @@ -1,9 +1,9 @@