From 1251d04860899a4d16187721aa0003bf81824be5 Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Fri, 16 Sep 2022 23:27:26 +0200 Subject: [PATCH] Action Refoulement de queue --- module/actor.js | 10 +++++++++ module/item.js | 30 +++++++++++++++------------ module/rdd-utility.js | 2 ++ templates/actor-sheet-item-queue.html | 9 ++++++++ templates/actor-sheet-queues.html | 15 ++++++++++++++ templates/actor-sheet.html | 27 +----------------------- templates/item-ombre-sheet.html | 13 +----------- templates/item-queue-sheet.html | 10 ++++++++- 8 files changed, 64 insertions(+), 52 deletions(-) create mode 100644 templates/actor-sheet-item-queue.html create mode 100644 templates/actor-sheet-queues.html diff --git a/module/actor.js b/module/actor.js index b4bfe9c4..4d9a82ae 100644 --- a/module/actor.js +++ b/module/actor.js @@ -1424,6 +1424,15 @@ export class RdDActor extends Actor { } } + /* -------------------------------------------- */ + async actionRefoulement(item) { + const refoulement = item?.system.refoulement ?? 0; + if (refoulement>0){ + await this.ajouterRefoulement(refoulement); + await item.delete(); + } + } + /* -------------------------------------------- */ async ajouterRefoulement(value = 1) { let refoulement = this.system.reve.refoulement.value + value; @@ -1924,6 +1933,7 @@ export class RdDActor extends Actor { } return; } + case 'queue': case 'ombre': return await this.actionRefoulement(item); } } diff --git a/module/item.js b/module/item.js index f83cf913..7f9003d8 100644 --- a/module/item.js +++ b/module/item.js @@ -145,24 +145,28 @@ export class RdDItem extends Item { } getActionPrincipale(options = { warnIfNot: true }) { - if (!this.isConteneur() && (this.system.quantite ?? 0) <= 0) { - if (options.warnIfNot) { + const warn = options.warnIfNot; + switch (this.type) { + case 'nourritureboisson': return this._actionOrWarnQuantiteZero(this.boisson ? 'Boire' : 'Manger', warn); + case 'potion': return this._actionOrWarnQuantiteZero('Boire', warn); + case 'livre': return this._actionOrWarnQuantiteZero('Lire', warn); + case 'conteneur': return this._actionOrWarnQuantiteZero('Ouvrir', warn); + case 'herbe': return this.isHerbeAPotion() ? this._actionOrWarnQuantiteZero('Décoction', warn) : undefined; + case 'queue': case 'ombre': return this.system.refoulement>0 ? 'Refouler' : undefined; + } + return undefined; + } + + _actionOrWarnQuantiteZero(actionName, warn){ + if ((this.system.quantite ?? 0) <= 0) { + if (warn) { ui.notifications.warn(`Vous n'avez plus de ${this.name}.`); } return undefined; } - switch (this.type) { - case 'nourritureboisson': return this.boisson ? 'Boire' : 'Manger'; - case 'potion': return 'Boire'; - case 'livre': return 'Lire'; - case 'conteneur': return 'Ouvrir'; + else { + return actionName; } - if (this.isHerbeAPotion()) { return 'Décoction'; } - if (options.warnIfNot) { - ui.notifications.warn(`Impossible d'utiliser un ${this.name}, aucune action associée définie.`); - } - - return undefined; } async diminuerQuantite(nombre, options = { diminuerQuantite: true, supprimerSiZero: false }) { diff --git a/module/rdd-utility.js b/module/rdd-utility.js index 04bcb0c9..29cdb219 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -121,8 +121,10 @@ export class RdDUtility { 'systems/foundryvtt-reve-de-dragon/templates/actor-sheet-oeuvre-partial.html', 'systems/foundryvtt-reve-de-dragon/templates/actor-liste-blessures-partial.html', 'systems/foundryvtt-reve-de-dragon/templates/actor-blessure-partial.html', + 'systems/foundryvtt-reve-de-dragon/templates/actor-sheet-queues.html', // Conteneur/item in Actor sheet 'systems/foundryvtt-reve-de-dragon/templates/actor-sheet-inventaire.html', + 'systems/foundryvtt-reve-de-dragon/templates/actor-sheet-item-queue.html', 'systems/foundryvtt-reve-de-dragon/templates/actor-sheet-inventaire-item.html', "systems/foundryvtt-reve-de-dragon/templates/actor-sheet-inventaire-monnaie.html", 'systems/foundryvtt-reve-de-dragon/templates/actor-sheet-liens-animaux.html', diff --git a/templates/actor-sheet-item-queue.html b/templates/actor-sheet-item-queue.html new file mode 100644 index 00000000..bd4fdf74 --- /dev/null +++ b/templates/actor-sheet-item-queue.html @@ -0,0 +1,9 @@ +
  • + {{queue.name}} +
    + + {{#if queue.system.refoulement}} + Refouler + {{/if}} +
    +
  • diff --git a/templates/actor-sheet-queues.html b/templates/actor-sheet-queues.html new file mode 100644 index 00000000..a91a3388 --- /dev/null +++ b/templates/actor-sheet-queues.html @@ -0,0 +1,15 @@ +{{#if (or queues.length ombres.length)}} +

    + {{#if queues.length}}Queues de Dragon{{/if}} + {{#if (and queues.length ombres.length)}} et {{/if}} + {{#if ombres.length}}Ombres de Thanatos{{/if}} + :

    + +{{/if}} diff --git a/templates/actor-sheet.html b/templates/actor-sheet.html index 1b060de6..8e2e447f 100644 --- a/templates/actor-sheet.html +++ b/templates/actor-sheet.html @@ -510,32 +510,7 @@
    {{!-- Queues, Souffles, Tetes, Ombre --}} - {{#if queues.length}} -

    Queues:

    - - {{/if}} - {{#if ombres.length}} -

    Ombres de Thanatos:

    - - {{/if}} + {{> "systems/foundryvtt-reve-de-dragon/templates/actor-sheet-queues.html"}} {{#if souffles.length}}

    Souffles: