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

This commit is contained in:
sladecraven 2021-01-05 11:47:22 +01:00
parent 4e391104f3
commit bc0e307959

View File

@ -45,6 +45,9 @@ export class RdDActor extends Actor {
} }
// If the created actor has items (only applicable to duplicated actors) bypass the new actor creation logic // If the created actor has items (only applicable to duplicated actors) bypass the new actor creation logic
if (data.items) { if (data.items) {
if (data.type == "personnage") {
await RdDActor.checkMonnaiePresence( data.items );
}
return super.create(data, options); return super.create(data, options);
} }
@ -107,45 +110,42 @@ export class RdDActor extends Actor {
this.computeEncombrementTotalEtMalusArmure(); this.computeEncombrementTotalEtMalusArmure();
this.computeEtatGeneral(); this.computeEtatGeneral();
// Sanity check // Sanity check
let newMonnaie = this.checkMonnaiePresence(); RdDActor.checkMonnaiePresence(actorData.items);
if ( newMonnaie.length > 0 )
await this.createOwnedItem( newMonnaie );
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
checkMonnaiePresence( ) { // Ajout opportuniste si les pièces n'existent pas. static checkMonnaiePresence( items ) { // Ajout opportuniste si les pièces n'existent pas.
let newMonnaie = []; if( !items) return; // Sanity check during import
let piece = this.data.items.find( item => item.type =='monnaie' && Number(item.data.valeur_deniers) == 1); let piece = items.find( item => item.type =='monnaie' && Number(item.data.valeur_deniers) == 1);
if (!piece) { if (!piece) {
newMonnaie.push( RdDUtility.createMonnaie("Etain (1 denier)", 1, "systems/foundryvtt-reve-de-dragon/icons/objets/piece_etain_poisson.webp" ) ); items.push( RdDUtility.createMonnaie("Etain (1 denier)", 1, "systems/foundryvtt-reve-de-dragon/icons/objets/piece_etain_poisson.webp" ) );
} }
piece = this.data.items.find( item => item.type =='monnaie' && Number(item.data.valeur_deniers) == 10); piece = items.find( item => item.type =='monnaie' && Number(item.data.valeur_deniers) == 10);
if (!piece) { if (!piece) {
newMonnaie.push(RdDUtility.createMonnaie("Bronze (10 deniers)", 10, "systems/foundryvtt-reve-de-dragon/icons/objets/piece_bronze_epees.webp") ); items.push(RdDUtility.createMonnaie("Bronze (10 deniers)", 10, "systems/foundryvtt-reve-de-dragon/icons/objets/piece_bronze_epees.webp") );
} }
piece = this.data.items.find( item => item.type =='monnaie' && Number(item.data.valeur_deniers) == 100); piece = items.find( item => item.type =='monnaie' && Number(item.data.valeur_deniers) == 100);
if (!piece) { if (!piece) {
newMonnaie.push(RdDUtility.createMonnaie("Argent (1 sol)", 100, "systems/foundryvtt-reve-de-dragon/icons/objets/piece_argent_sol.webp")); items.push(RdDUtility.createMonnaie("Argent (1 sol)", 100, "systems/foundryvtt-reve-de-dragon/icons/objets/piece_argent_sol.webp"));
} }
piece = this.data.items.find( item => item.type =='monnaie' && Number(item.data.valeur_deniers) == 1000); piece = items.find( item => item.type =='monnaie' && Number(item.data.valeur_deniers) == 1000);
if (!piece) { if (!piece) {
newMonnaie.push(RdDUtility.createMonnaie("Or (10 sols)", 1000, "systems/foundryvtt-reve-de-dragon/icons/objets/piece_or_sol.webp") ); items.push(RdDUtility.createMonnaie("Or (10 sols)", 1000, "systems/foundryvtt-reve-de-dragon/icons/objets/piece_or_sol.webp") );
} }
return newMonnaie;
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
static async ajouterMonnaie( items ) { // Creation auto à la création du personnage static async ajouterMonnaie( items ) { // Creation auto à la création du personnage
let etain = RdDUtility.createMonnaie("Etain (1 denier)", 1); let etain = RdDUtility.createMonnaie("Etain (1 denier)", 1, "systems/foundryvtt-reve-de-dragon/icons/objets/piece_etain_poisson.webp);
items.push(etain); items.push(etain);
let bronze = RdDUtility.createMonnaie("Bronze (10 deniers)", 10); let bronze = RdDUtility.createMonnaie("Bronze (10 deniers)", 10, "systems/foundryvtt-reve-de-dragon/icons/objets/piece_bronze_epees.webp");
items.push(bronze); items.push(bronze);
let argent = RdDUtility.createMonnaie("Argent (1 sol)", 100); let argent = RdDUtility.createMonnaie("Argent (1 sol)", 100, "systems/foundryvtt-reve-de-dragon/icons/objets/piece_argent_sol.webp");
items.push(argent); items.push(argent);
let or = RdDUtility.createMonnaie("Or (10 sols)", 1000); let or = RdDUtility.createMonnaie("Or (10 sols)", 1000, "systems/foundryvtt-reve-de-dragon/icons/objets/piece_or_sol.webp");
items.push(or); items.push(or);
} }