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

45 lines
1.1 KiB
JavaScript
Raw Normal View History

2023-01-13 04:54:29 +01:00
const RARETES = [
{ code: 'Commune', label: 'Commune', frequence: 54, min: 27, max: 108 },
{ code: 'Frequente', label: 'Fréquente', frequence: 18, min: 9, max: 36 },
{ code: 'Rare', label: 'Rare', frequence: 6, min: 3, max: 12 },
{ code: 'Rarissime', label: 'Rarissime', frequence: 2, min: 1, max: 4 }]
const DEFAULT_RARETE = 1;
export class RdDRaretes {
static getRarete(code = undefined) {
return RARETES.find(it => it.code == code) ?? RARETES[DEFAULT_RARETE];
}
static getChamp(rarete, field = undefined) {
const selected = this.getRarete(rarete);
return field ? selected[field] : selected[frequence];
}
static getRareteFrequente() {
return RARETES[DEFAULT_RARETE];
}
static raretes() {
return RARETES;
}
static frequenceEquipement(item) {
return RdDRaretes.rareteEquipement(item).frequence
}
static rareteEquipement(item) {
const qualite = item.system.qualite ?? 0;
if (qualite <= 0) {
return RARETES[0]
}
if (qualite <= 3) {
return RARETES[1]
}
if (qualite <= 6) {
return RARETES[2]
}
return RARETES[3]
}
}