From 14391daa0be7d264bd2f21d5d33e7bff7104d600 Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Fri, 17 Jan 2025 01:08:27 +0100 Subject: [PATCH] Simplification monnaies MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Note: bug étrange causé par la 12.0.34, mais le code était bon --- module/actor/base-actor-sheet.js | 3 ++- module/item-monnaie.js | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/module/actor/base-actor-sheet.js b/module/actor/base-actor-sheet.js index a5edbd09..0106ff96 100644 --- a/module/actor/base-actor-sheet.js +++ b/module/actor/base-actor-sheet.js @@ -27,7 +27,7 @@ export class RdDBaseActorSheet extends ActorSheet { /* -------------------------------------------- */ async getData() { - Monnaie.validerMonnaies(this.actor.itemTypes['monnaie']); + Monnaie.validerMonnaies(this.actor) this.actor.computeEtatGeneral(); let formData = { @@ -55,6 +55,7 @@ export class RdDBaseActorSheet extends ActorSheet { formData.conteneurs = RdDUtility.conteneursRacine(formData.conteneurs); formData.competences.filter(it => it.type == ITEM_TYPES.competencecreature) .forEach(it => it.isdommages = RdDItemCompetenceCreature.isDommages(it)) + return formData; } diff --git a/module/item-monnaie.js b/module/item-monnaie.js index 366983ca..4d324444 100644 --- a/module/item-monnaie.js +++ b/module/item-monnaie.js @@ -1,5 +1,5 @@ import { Misc } from "./misc.js"; -import { LOG_HEAD } from "./constants.js"; +import { ITEM_TYPES, LOG_HEAD } from "./constants.js"; const MONNAIE_ETAIN = { name: "Denier (étain)", type: 'monnaie', @@ -70,18 +70,17 @@ export class Monnaie { } static getFortune(monnaies) { - return (monnaies??[]) + return (monnaies ?? []) .map(m => Number(m.system.cout) * Number(m.system.quantite)) .reduce(Misc.sum(), 0); } static async optimiserFortune(actor, fortune) { + Monnaie.validerMonnaies(actor) let resteEnDeniers = Math.round(fortune * 100); - let monnaies = actor.itemTypes['monnaie']; - let updates = []; - Monnaie.validerMonnaies(monnaies, actor); + const updates = [] - let parValeur = Misc.classifyFirst(monnaies, it => VALEUR_DENIERS(it.system.cout)); + const parValeur = Misc.classifyFirst(actor.itemTypes[ITEM_TYPES.monnaie], it => VALEUR_DENIERS(it.system.cout)); for (let valeurDeniers of [1000, 100, 10, 1]) { const itemPiece = parValeur[valeurDeniers]; if (itemPiece) { @@ -102,8 +101,11 @@ export class Monnaie { } } - static validerMonnaies(monnaies, actor = undefined) { - monnaies.filter(it => VALEUR_DENIERS(it.system.cout) == 0) + static validerMonnaies(actor) { + if (!actor) { + return + } + actor.itemTypes[ITEM_TYPES.monnaie]?.filter(it => VALEUR_DENIERS(it.system.cout) == 0) .map(it => `La monnaie ${it.name} de l'acteur ${actor?.name ?? 'sélectionné'} a une valeur de 0!`) .forEach(message => { ui.notifications.warn(message);