foundryvtt-reve-de-dragon/module/item-monnaie.js

66 lines
2.2 KiB
JavaScript
Raw Permalink Normal View History

2021-03-25 03:18:27 +01:00
import { Misc } from "./misc.js";
import { LOG_HEAD, SYSTEM_RDD } from "./constants.js";
2021-03-19 22:20:01 +01:00
const MONNAIES_STANDARD = [
2021-03-19 22:20:01 +01:00
{
2021-03-25 03:18:27 +01:00
name: "Etain (1 denier)", type: 'monnaie',
2021-03-19 22:20:01 +01:00
img: "systems/foundryvtt-reve-de-dragon/icons/objets/piece_etain_poisson.webp",
system: { quantite: 0, valeur_deniers: 1, encombrement: 0.001, description: "" }
2021-03-19 22:20:01 +01:00
},
{
2021-03-25 03:18:27 +01:00
name: "Bronze (10 deniers)", type: 'monnaie',
2021-03-19 22:20:01 +01:00
img: "systems/foundryvtt-reve-de-dragon/icons/objets/piece_bronze_epees.webp",
system: { quantite: 0, valeur_deniers: 10, encombrement: 0.002, description: "" }
2021-03-19 22:20:01 +01:00
},
{
2021-03-25 03:18:27 +01:00
name: "Argent (1 sol)", type: 'monnaie',
2021-03-19 22:20:01 +01:00
img: "systems/foundryvtt-reve-de-dragon/icons/objets/piece_argent_sol.webp",
system: { quantite: 0, valeur_deniers: 100, encombrement: 0.003, description: "" }
2021-03-19 22:20:01 +01:00
},
{
2021-03-25 03:18:27 +01:00
name: "Or (10 sols)", type: 'monnaie',
2021-03-19 22:20:01 +01:00
img: "systems/foundryvtt-reve-de-dragon/icons/objets/piece_or_sol.webp",
system: { quantite: 0, valeur_deniers: 1000, encombrement: 0.004, description: "" }
2021-03-19 22:20:01 +01:00
}
]
const VALEURS_STANDARDS = MONNAIES_STANDARD.map(it =>it.system.valeur_deniers);
2021-03-19 22:20:01 +01:00
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;
2021-06-02 17:39:16 +02:00
}
2021-03-19 22:20:01 +01:00
static monnaiesData() {
return MONNAIES_STANDARD;
2021-03-19 22:20:01 +01:00
}
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;
2021-03-25 03:18:27 +01:00
}
static deValeur(monnaie, valeur) {
return valeur == monnaie.system.valeur_deniers
2021-03-19 22:20:01 +01:00
}
2021-05-07 17:27:02 +02:00
static arrondiDeniers(sols) {
return sols.toFixed(2);
}
2021-06-05 02:05:51 +02:00
static triValeurDenier() {
2022-05-01 00:38:09 +02:00
return Misc.ascending(item => item.system.valeur_deniers)
2021-06-05 02:05:51 +02:00
}
2021-03-19 22:20:01 +01:00
}