diff --git a/module/actor.js b/module/actor.js index d687af52..7f33f5a4 100644 --- a/module/actor.js +++ b/module/actor.js @@ -152,23 +152,26 @@ export class RdDActor extends RdDBaseActorSang { /* -------------------------------------------- */ async $perteRevePotionsEnchantees() { let potions = this.itemTypes[TYPES.potion] - .filter(it => it.system.categorie.toLowerCase().includes('enchant') && !potion.system.prpermanent) + .filter(it => Grammar.includesLowerCaseNoAccent(it.system.categorie, 'enchanté') && !it.system.prpermanent) - const potionUpdates = await Promise.all(potions.map(async potion => { - console.log(potion) - let nouveauReve = (potion.system.pr > 0) ? potion.system.pr - 1 : 0; - const message = await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-potionenchantee-chateaudormant.html`, { - pr: nouveauReve, - alias: this.name, - potionName: potion.name, - potionImg: potion.img - }) + const potionUpdates = await Promise.all(potions.map(async it => { + const nouveauReve = Math.max(it.system.pr - 1, 0) ChatMessage.create({ whisper: ChatUtility.getWhisperRecipientsAndGMs(this.name), - content: message - }); - return { _id: potion._id, 'system.pr': nouveauReve }; + content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-potionenchantee-chateaudormant.html`, { + pr: nouveauReve, + alias: this.name, + potionName: it.name, + potionImg: it.img + }) + }) + return { + _id: it._id, + 'system.pr': nouveauReve, + 'system.quantite': nouveauReve > 0 ? it.system.quantite : 0 + } })) + await this.updateEmbeddedDocuments('Item', potionUpdates); }