diff --git a/module/actor.js b/module/actor.js index a1c03135..e98339a8 100644 --- a/module/actor.js +++ b/module/actor.js @@ -1609,8 +1609,18 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async actionItem(item) { if (!item.getActionPrincipale()) return; + switch (Misc.data(item).type) { + case 'nourritureboisson': return await this.actionNourritureboisson(item); + case 'potion': return await this.actionPotion(item); + } + } + + async actionNourritureboisson(item) { const dialog = await DialogConsommer.create(this, item); - dialog.render(true) + dialog.render(true); + } + async actionPotion(item) { + return await this.consommerPotion(item) } /* -------------------------------------------- */ @@ -1653,7 +1663,7 @@ export class RdDActor extends Actor { } await item.diminuerQuantite(doses, options); } - + /* -------------------------------------------- */ async boire(item, doses, options = { diminuerQuantite: true }) { if (!item.getActionPrincipale()) return; @@ -3274,6 +3284,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async consommerPotionSoin(potionData) { potionData.alias = this.name; + potionData.supprimer = true; if (potionData.data.isEnchante) { ChatMessage.create({ @@ -3305,6 +3316,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async consommerPotionRepos(potionData) { potionData.alias = this.name; + potionData.supprimer = true; if (potionData.data.isEnchante) { ChatMessage.create({ @@ -3373,7 +3385,8 @@ export class RdDActor extends Actor { nbBrinsPotion: herbeData.nbBrins, nbBrinsReste: newQuantite } - this.getObjet(herbeData._id).diminuerQuantite(herbeData.nbBrins); + this.diminuerQuantiteObjet(herbeData._id, 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) @@ -3381,6 +3394,13 @@ export class RdDActor extends Actor { } + async diminuerQuantiteObjet(id, nb, options = { supprimerSiZero: false }) { + const item = this.getObjet(id); + if (item){ + await item.diminuerQuantite(nb, options); + } + } + /* -------------------------------------------- */ async consommerPotionGenerique(potionData) { potionData.alias = this.name; @@ -3402,7 +3422,7 @@ export class RdDActor extends Actor { } else { this.consommerPotionGenerique(potionData); } - await this.deleteEmbeddedDocuments('Item', [potion.id]); + this.diminuerQuantiteObjet(potion.id, 1, { supprimerSiZero: potionData.supprimer }); } /* -------------------------------------------- */ diff --git a/module/item.js b/module/item.js index e41bbabb..ffe491a8 100644 --- a/module/item.js +++ b/module/item.js @@ -85,16 +85,23 @@ export class RdDItem extends Item { return itemData.type == 'nourritureboisson' && itemData.data.boisson && itemData.data.alcoolise; } - async diminuerQuantite(nombre, options = { diminuerQuantite: true }) { - if (!options.diminuerQuantite) return; + async diminuerQuantite(nombre, options = { diminuerQuantite: true, supprimerSiZero: false }) { + if (options.diminuerQuantite == false) return; const itemData = Misc.data(this); const quantite = itemData.data.quantite; if (quantite != undefined) { const reste = Math.max(quantite - nombre, 0); - ui.notifications.notify(`Quantité de ${itemData.name} réduite de ${nombre}.${reste == 0 - ? "Il ne vous en reste plus, vous pouvez le supprimer de votre équipement, ou trouver un moyen de vous en procurer." - : ""}`); - await this.update({ "data.quantite": reste }); + + if (options.supprimerSiZero && reste == 0) { + ui.notifications.notify(`${itemData.name} supprimé de votre équipement`); + await this.delete(); + } + else { + ui.notifications.notify(`Quantité de ${itemData.name} réduite de ${nombre}.${reste == 0 + ? "Il ne vous en reste plus, vous pouvez le supprimer de votre équipement, ou trouver un moyen de vous en procurer." + : ""}`); + await this.update({ "data.quantite": reste }); + } } } diff --git a/styles/simple.css b/styles/simple.css index 1f8d248d..845bc07e 100644 --- a/styles/simple.css +++ b/styles/simple.css @@ -935,7 +935,7 @@ ul, li { background: rgba(220,220,210,0.75); border: 2px solid #545469; } -.chat-message .chat-icon { +.chat-icon { border: 0; padding: 2px 6px 2px 2px; float: left; diff --git a/templates/consommer/dialog-potion.html b/templates/consommer/dialog-potion.html deleted file mode 100644 index ae07e9eb..00000000 --- a/templates/consommer/dialog-potion.html +++ /dev/null @@ -1,14 +0,0 @@ -
- {{oeuvre.data.competence}} -
- -
-
- {{#if (eq item.data.categorie 'SoinEnchante')}} -

C'est une potion enchantée de {{item.data.herbe}} de {{item.data.pr}} points de rêve, - sa puissance de guérison est de {{data.puissance}}

- {{/if}} - -
- -
\ No newline at end of file