Simplification monnaies

Note: bug étrange causé par la 12.0.34, mais le code était bon
This commit is contained in:
Vincent Vandemeulebrouck 2025-01-17 01:08:27 +01:00
parent ac29e1410e
commit 14391daa0b
2 changed files with 12 additions and 9 deletions

View File

@ -27,7 +27,7 @@ export class RdDBaseActorSheet extends ActorSheet {
/* -------------------------------------------- */ /* -------------------------------------------- */
async getData() { async getData() {
Monnaie.validerMonnaies(this.actor.itemTypes['monnaie']); Monnaie.validerMonnaies(this.actor)
this.actor.computeEtatGeneral(); this.actor.computeEtatGeneral();
let formData = { let formData = {
@ -55,6 +55,7 @@ export class RdDBaseActorSheet extends ActorSheet {
formData.conteneurs = RdDUtility.conteneursRacine(formData.conteneurs); formData.conteneurs = RdDUtility.conteneursRacine(formData.conteneurs);
formData.competences.filter(it => it.type == ITEM_TYPES.competencecreature) formData.competences.filter(it => it.type == ITEM_TYPES.competencecreature)
.forEach(it => it.isdommages = RdDItemCompetenceCreature.isDommages(it)) .forEach(it => it.isdommages = RdDItemCompetenceCreature.isDommages(it))
return formData; return formData;
} }

View File

@ -1,5 +1,5 @@
import { Misc } from "./misc.js"; import { Misc } from "./misc.js";
import { LOG_HEAD } from "./constants.js"; import { ITEM_TYPES, LOG_HEAD } from "./constants.js";
const MONNAIE_ETAIN = { const MONNAIE_ETAIN = {
name: "Denier (étain)", type: 'monnaie', name: "Denier (étain)", type: 'monnaie',
@ -76,12 +76,11 @@ export class Monnaie {
} }
static async optimiserFortune(actor, fortune) { static async optimiserFortune(actor, fortune) {
Monnaie.validerMonnaies(actor)
let resteEnDeniers = Math.round(fortune * 100); let resteEnDeniers = Math.round(fortune * 100);
let monnaies = actor.itemTypes['monnaie']; const updates = []
let updates = [];
Monnaie.validerMonnaies(monnaies, actor);
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]) { for (let valeurDeniers of [1000, 100, 10, 1]) {
const itemPiece = parValeur[valeurDeniers]; const itemPiece = parValeur[valeurDeniers];
if (itemPiece) { if (itemPiece) {
@ -102,8 +101,11 @@ export class Monnaie {
} }
} }
static validerMonnaies(monnaies, actor = undefined) { static validerMonnaies(actor) {
monnaies.filter(it => VALEUR_DENIERS(it.system.cout) == 0) 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!`) .map(it => `La monnaie ${it.name} de l'acteur ${actor?.name ?? 'sélectionné'} a une valeur de 0!`)
.forEach(message => { .forEach(message => {
ui.notifications.warn(message); ui.notifications.warn(message);