From d5c4b69e1d395f93225c0502758eea22f5be7156 Mon Sep 17 00:00:00 2001 From: sladecraven Date: Thu, 31 Dec 2020 10:55:40 +0100 Subject: [PATCH] =?UTF-8?q?#88=20Ajout=20auto=20ds=20pi=C3=A8ces=20si=20ma?= =?UTF-8?q?nquantes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- module/actor.js | 68 ++++++++++++++++++++++++------------------- module/rdd-utility.js | 13 +++++++++ 2 files changed, 51 insertions(+), 30 deletions(-) diff --git a/module/actor.js b/module/actor.js index 8fbe1f0c..d7a87e57 100644 --- a/module/actor.js +++ b/module/actor.js @@ -91,7 +91,6 @@ export class RdDActor extends Actor { // things organized. if (actorData.type === 'personnage') this._prepareCharacterData(actorData); if (actorData.type === 'creature') this.computeEtatGeneral(actorData); - if (actorData.type === 'humanoide') this.computeEtatGeneral(actorData); } /* -------------------------------------------- */ @@ -103,38 +102,47 @@ export class RdDActor extends Actor { RdDUtility.computeCarac(actorData.data); this.computeEncombrementTotalEtMalusArmure(); this.computeEtatGeneral(); + this.checkMonnaiePresence(); } - /* -------------------------------------------- */ - static async ajouterMonnaie( items ) { - let etain = { name: "Etain (1 denier)", type: 'monnaie', _id: randomID(), - data: { - quantite: 0, - valeur_deniers: 1, - encombrement: 0.01, - description: "" - } - } - items.push(etain); - - let bronze = duplicate(etain); - bronze.id = randomID(); - bronze.name = "Bronze (10 deniers)"; - bronze.data.valeur_deniers = 10; - items.push(bronze); - - let argent = duplicate(etain); - argent.id = randomID(); - argent.name = "Argent (1 sol)"; - argent.data.valeur_deniers = 100; - items.push(argent); - - let or = duplicate(argent); - or.id = randomID(); - or.name = "Or (10 sols)"; - or.data.valeur_deniers = 1000; - items.push(or); + /* -------------------------------------------- */ + checkMonnaiePresence( ) { // Ajout opportuniste si les pièces n'existent pas. + let piece = this.data.items.find( item => item.type =='monnaie' && Number(item.data.valeur_deniers) == 1); + if (!piece) { + let piece = RdDUtility.createMonnaie("Etain (1 denier)", 1); + this.createOwnedItem( piece ); } + piece = this.data.items.find( item => item.type =='monnaie' && Number(item.data.valeur_deniers) == 10); + if (!piece) { + let piece = RdDUtility.createMonnaie("Bronze (10 deniers)", 10); + this.createOwnedItem( piece ); + } + piece = this.data.items.find( item => item.type =='monnaie' && Number(item.data.valeur_deniers) == 100); + if (!piece) { + let piece = RdDUtility.createMonnaie("Argent (1 sol)", 100); + this.createOwnedItem( piece ); + } + piece = this.data.items.find( item => item.type =='monnaie' && Number(item.data.valeur_deniers) == 1000); + if (!piece) { + let piece = RdDUtility.createMonnaie("Or (10 sols)", 1000); + this.createOwnedItem( piece ); + } + } + + /* -------------------------------------------- */ + static async ajouterMonnaie( items ) { // Creation auto à la création du personnage + let etain = RdDUtility.createMonnaie("Etain (1 denier)", 1); + items.push(etain); + + let bronze = RdDUtility.createMonnaie("Bronze (10 deniers)", 10); + items.push(bronze); + + let argent = RdDUtility.createMonnaie("Argent (1 sol)", 100); + items.push(argent); + + let or = RdDUtility.createMonnaie("Or (10 sols)", 1000); + items.push(or); + } /* -------------------------------------------- */ isCreature() { diff --git a/module/rdd-utility.js b/module/rdd-utility.js index bab53c0d..c4672192 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -891,6 +891,19 @@ export class RdDUtility { }); } + /* -------------------------------------------- */ + static createMonnaie( name, valeur_deniers, enc = 0.01) { + let piece = { name: name, type: 'monnaie', _id: randomID(), + data: { + quantite: 0, + valeur_deniers: valeur_deniers, + encombrement: enc, + description: "" + } + } + return piece; + } + /* -------------------------------------------- */ static afficherDemandePayer(som1, som2) { som1 = (som1) ? som1.toLowerCase() : "0d";