#88 Ajout auto ds pièces si manquantes

This commit is contained in:
sladecraven 2020-12-31 10:55:40 +01:00
parent 2355406546
commit d5c4b69e1d
2 changed files with 51 additions and 30 deletions

View File

@ -91,7 +91,6 @@ export class RdDActor extends Actor {
// things organized. // things organized.
if (actorData.type === 'personnage') this._prepareCharacterData(actorData); if (actorData.type === 'personnage') this._prepareCharacterData(actorData);
if (actorData.type === 'creature') this.computeEtatGeneral(actorData); if (actorData.type === 'creature') this.computeEtatGeneral(actorData);
if (actorData.type === 'humanoide') this.computeEtatGeneral(actorData);
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
@ -103,36 +102,45 @@ export class RdDActor extends Actor {
RdDUtility.computeCarac(actorData.data); RdDUtility.computeCarac(actorData.data);
this.computeEncombrementTotalEtMalusArmure(); this.computeEncombrementTotalEtMalusArmure();
this.computeEtatGeneral(); this.computeEtatGeneral();
this.checkMonnaiePresence();
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
static async ajouterMonnaie( items ) { checkMonnaiePresence( ) { // Ajout opportuniste si les pièces n'existent pas.
let etain = { name: "Etain (1 denier)", type: 'monnaie', _id: randomID(), let piece = this.data.items.find( item => item.type =='monnaie' && Number(item.data.valeur_deniers) == 1);
data: { if (!piece) {
quantite: 0, let piece = RdDUtility.createMonnaie("Etain (1 denier)", 1);
valeur_deniers: 1, this.createOwnedItem( piece );
encombrement: 0.01, }
description: "" 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); items.push(etain);
let bronze = duplicate(etain); let bronze = RdDUtility.createMonnaie("Bronze (10 deniers)", 10);
bronze.id = randomID();
bronze.name = "Bronze (10 deniers)";
bronze.data.valeur_deniers = 10;
items.push(bronze); items.push(bronze);
let argent = duplicate(etain); let argent = RdDUtility.createMonnaie("Argent (1 sol)", 100);
argent.id = randomID();
argent.name = "Argent (1 sol)";
argent.data.valeur_deniers = 100;
items.push(argent); items.push(argent);
let or = duplicate(argent); let or = RdDUtility.createMonnaie("Or (10 sols)", 1000);
or.id = randomID();
or.name = "Or (10 sols)";
or.data.valeur_deniers = 1000;
items.push(or); items.push(or);
} }

View File

@ -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) { static afficherDemandePayer(som1, som2) {
som1 = (som1) ? som1.toLowerCase() : "0d"; som1 = (som1) ? som1.toLowerCase() : "0d";