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 }; const RARETES = [ RARETE_COMMUNE, RARETE_FREQUENTE, RARETE_RARE, RARETE_RARISSIME, RARETE_INEXISTANT, ] export class RdDRaretes { static getRarete(code = undefined) { return RARETES.find(it => it.code == code) ?? RARETE_FREQUENTE; } static getChamp(rarete, field = undefined) { const selected = this.getRarete(rarete); return field ? selected[field] : selected[frequence]; } static rareteFrequente() { return RARETE_FREQUENTE; } 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; } static rareteEquipement(item) { const qualite = item.system.qualite ?? 0; if (qualite <= 0) { return RARETE_COMMUNE } if (qualite <= 3) { return RARETE_FREQUENTE } if (qualite <= 6) { return RARETE_RARE } if (qualite <= 9) { return RARETE_RARISSIME } return RARETE_INEXISTANT } }