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

64 lines
1.7 KiB
JavaScript
Raw Normal View History

2023-01-18 00:11:10 +01:00
const RARETE_COMMUNE = { code: 'Commune', label: 'Commune', frequence: 54, min: 27, max: 108 };
const RARETE_FREQUENTE = { code: 'Frequente', label: 'Fréquente', frequence: 18, min: 9, max: 36 };
const RARETE_RARE = { code: 'Rare', label: 'Rare', frequence: 6, min: 3, max: 12 };
const RARETE_RARISSIME = { code: 'Rarissime', label: 'Rarissime', frequence: 2, min: 1, max: 4 };
const RARETE_INEXISTANT = { code: 'Inexistant', label: 'Inexistant', frequence: 0, min: 0, max: 0 };
2023-01-13 04:54:29 +01:00
const RARETES = [
RARETE_COMMUNE,
RARETE_FREQUENTE,
RARETE_RARE,
RARETE_RARISSIME,
RARETE_INEXISTANT,
]
2023-01-13 04:54:29 +01:00
export class RdDRaretes {
static getRareteByCode(code = undefined) {
return RARETES.find(it => it.code == code) ?? RARETE_FREQUENTE;
2023-01-13 04:54:29 +01:00
}
static getChamp(rarete, field = undefined) {
const selected = this.getRareteByCode(rarete);
2023-01-13 04:54:29 +01:00
return field ? selected[field] : selected[frequence];
}
static rareteFrequente() {
return RARETE_FREQUENTE;
2023-01-13 04:54:29 +01:00
}
static raretes() {
return RARETES;
}
2023-01-18 00:11:10 +01:00
static selonEnvironnement(item, milieux = undefined) {
const list = item.getEnvironnement(milieux);
const freqMax = Math.max(0, ...list.map(env => env.frequence));
const env = list.find(env => env.frequence == freqMax);
2023-01-18 00:11:10 +01:00
if (env) {
return RdDRaretes.getRareteByCode(env.rarete)
2023-01-18 00:11:10 +01:00
}
if (milieux == undefined) {
return RdDRaretes.selonQualite(item)
}
return RARETE_INEXISTANT;
}
2023-01-18 00:11:10 +01:00
static selonQualite(item) {
2023-01-13 04:54:29 +01:00
const qualite = item.system.qualite ?? 0;
if (qualite <= 0) {
return RARETE_COMMUNE
2023-01-13 04:54:29 +01:00
}
if (qualite <= 3) {
return RARETE_FREQUENTE
2023-01-13 04:54:29 +01:00
}
if (qualite <= 6) {
return RARETE_RARE
}
if (qualite <= 9) {
return RARETE_RARISSIME
2023-01-13 04:54:29 +01:00
}
return RARETE_INEXISTANT
2023-01-13 04:54:29 +01:00
}
}