66 lines
2.2 KiB
JavaScript
66 lines
2.2 KiB
JavaScript
import { Misc } from "./misc.js";
|
|
import { LOG_HEAD, SYSTEM_RDD } from "./constants.js";
|
|
|
|
const MONNAIES_STANDARD = [
|
|
{
|
|
name: "Etain (1 denier)", type: 'monnaie',
|
|
img: "systems/foundryvtt-reve-de-dragon/icons/objets/piece_etain_poisson.webp",
|
|
system: { quantite: 0, valeur_deniers: 1, encombrement: 0.001, description: "" }
|
|
},
|
|
{
|
|
name: "Bronze (10 deniers)", type: 'monnaie',
|
|
img: "systems/foundryvtt-reve-de-dragon/icons/objets/piece_bronze_epees.webp",
|
|
system: { quantite: 0, valeur_deniers: 10, encombrement: 0.002, description: "" }
|
|
},
|
|
{
|
|
name: "Argent (1 sol)", type: 'monnaie',
|
|
img: "systems/foundryvtt-reve-de-dragon/icons/objets/piece_argent_sol.webp",
|
|
system: { quantite: 0, valeur_deniers: 100, encombrement: 0.003, description: "" }
|
|
},
|
|
{
|
|
name: "Or (10 sols)", type: 'monnaie',
|
|
img: "systems/foundryvtt-reve-de-dragon/icons/objets/piece_or_sol.webp",
|
|
system: { quantite: 0, valeur_deniers: 1000, encombrement: 0.004, description: "" }
|
|
}
|
|
]
|
|
const VALEURS_STANDARDS = MONNAIES_STANDARD.map(it =>it.system.valeur_deniers);
|
|
|
|
export class Monnaie {
|
|
|
|
static isSystemMonnaie(item, items) {
|
|
if (item.type == 'monnaie') {
|
|
const valeur = item.system.valeur_deniers;
|
|
if (VALEURS_STANDARDS.includes(valeur)) {
|
|
const monnaiesDeValeur = items.filter(it => it.type == 'monnaie' && it.system.valeur_deniers == valeur)
|
|
return monnaiesDeValeur.length<=1;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
static monnaiesData() {
|
|
return MONNAIES_STANDARD;
|
|
}
|
|
|
|
static monnaiesManquantes(actor) {
|
|
const disponibles = actor.itemTypes['monnaie'];
|
|
const manquantes = MONNAIES_STANDARD.filter(standard => !disponibles.find(disponible => Monnaie.deValeur(disponible, standard.system?.valeur_deniers)));
|
|
if (manquantes.length > 0) {
|
|
console.error(`${LOG_HEAD} monnaiesManquantes pour ${actor.name}`, manquantes, ' avec monnaies', disponibles, MONNAIES_STANDARD);
|
|
}
|
|
return manquantes;
|
|
}
|
|
|
|
static deValeur(monnaie, valeur) {
|
|
return valeur == monnaie.system.valeur_deniers
|
|
}
|
|
|
|
static arrondiDeniers(sols) {
|
|
return sols.toFixed(2);
|
|
}
|
|
|
|
static triValeurDenier() {
|
|
return Misc.ascending(item => item.system.valeur_deniers)
|
|
}
|
|
}
|