#107 : Correction sur boucle de re-entrance sur la creation des monnaies

This commit is contained in:
sladecraven 2021-01-05 11:25:28 +01:00
parent 544c0ba94b
commit 4e391104f3

View File

@ -106,31 +106,32 @@ export class RdDActor extends Actor {
RdDUtility.computeCarac(actorData.data); RdDUtility.computeCarac(actorData.data);
this.computeEncombrementTotalEtMalusArmure(); this.computeEncombrementTotalEtMalusArmure();
this.computeEtatGeneral(); this.computeEtatGeneral();
await this.checkMonnaiePresence(); // Sanity check
let newMonnaie = this.checkMonnaiePresence();
if ( newMonnaie.length > 0 )
await this.createOwnedItem( newMonnaie );
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
async checkMonnaiePresence( ) { // Ajout opportuniste si les pièces n'existent pas. checkMonnaiePresence( ) { // Ajout opportuniste si les pièces n'existent pas.
let newMonnaie = [];
let piece = this.data.items.find( item => item.type =='monnaie' && Number(item.data.valeur_deniers) == 1); let piece = this.data.items.find( item => item.type =='monnaie' && Number(item.data.valeur_deniers) == 1);
if (!piece) { if (!piece) {
let piece = RdDUtility.createMonnaie("Etain (1 denier)", 1, "systems/foundryvtt-reve-de-dragon/icons/objets/piece_etain_poisson.webp" ); newMonnaie.push( RdDUtility.createMonnaie("Etain (1 denier)", 1, "systems/foundryvtt-reve-de-dragon/icons/objets/piece_etain_poisson.webp" ) );
const updated = await this.createOwnedItem( piece );
} }
piece = this.data.items.find( item => item.type =='monnaie' && Number(item.data.valeur_deniers) == 10); piece = this.data.items.find( item => item.type =='monnaie' && Number(item.data.valeur_deniers) == 10);
if (!piece) { if (!piece) {
let piece = RdDUtility.createMonnaie("Bronze (10 deniers)", 10, "systems/foundryvtt-reve-de-dragon/icons/objets/piece_bronze_epees.webp"); newMonnaie.push(RdDUtility.createMonnaie("Bronze (10 deniers)", 10, "systems/foundryvtt-reve-de-dragon/icons/objets/piece_bronze_epees.webp") );
const updated = await this.createOwnedItem( piece );
} }
piece = this.data.items.find( item => item.type =='monnaie' && Number(item.data.valeur_deniers) == 100); piece = this.data.items.find( item => item.type =='monnaie' && Number(item.data.valeur_deniers) == 100);
if (!piece) { if (!piece) {
let piece = RdDUtility.createMonnaie("Argent (1 sol)", 100, "systems/foundryvtt-reve-de-dragon/icons/objets/piece_argent_sol.webp"); newMonnaie.push(RdDUtility.createMonnaie("Argent (1 sol)", 100, "systems/foundryvtt-reve-de-dragon/icons/objets/piece_argent_sol.webp"));
const updated = await this.createOwnedItem( piece );
} }
piece = this.data.items.find( item => item.type =='monnaie' && Number(item.data.valeur_deniers) == 1000); piece = this.data.items.find( item => item.type =='monnaie' && Number(item.data.valeur_deniers) == 1000);
if (!piece) { if (!piece) {
let piece = RdDUtility.createMonnaie("Or (10 sols)", 1000, "systems/foundryvtt-reve-de-dragon/icons/objets/piece_or_sol.webp"); newMonnaie.push(RdDUtility.createMonnaie("Or (10 sols)", 1000, "systems/foundryvtt-reve-de-dragon/icons/objets/piece_or_sol.webp") );
const updated = await this.createOwnedItem( piece );
} }
return newMonnaie;
} }
/* -------------------------------------------- */ /* -------------------------------------------- */