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

62 lines
1.7 KiB
JavaScript
Raw Normal View History

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 getRarete(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.getRarete(rarete);
return field ? selected[field] : selected[frequence];
}
static rareteFrequente() {
return RARETE_FREQUENTE;
2023-01-13 04:54:29 +01:00
}
static raretes() {
return RARETES;
}
static frequenceEquipement(item) {
return RdDRaretes.rareteEquipement(item).frequence
}
static rareteEnvironnement(item, milieux = undefined) {
const list = item.getEnvironnements(milieux);
const freqMax = Math.max(0, ...list.map(env => env.frequence));
const env = list.find(env => env.frequence == freqMax);
return env ? RdDRaretes.getRarete(env.rarete) : RARETE_INEXISTANT;
}
2023-01-13 04:54:29 +01:00
static rareteEquipement(item) {
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
}
}