dok/utils/rarity.js
2026-04-14 09:12:29 +01:00

36 lines
1.2 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* ============================================================
utils/rarity.js
Zentrale Rarity-Logik wird überall per require eingebunden
============================================================ */
'use strict';
/* ── Tabelle: ab welchem Level ist welche Rarity erlaubt ────
Einträge: { minLevel, maxRarity }
Wird von oben nach unten geprüft erster passender Treffer gilt.
────────────────────────────────────────────────────────────── */
const RARITY_TABLE = [
{ minLevel: 1, maxRarity: 2 },
{ minLevel: 10, maxRarity: 3 },
{ minLevel: 20, maxRarity: 4 },
{ minLevel: 30, maxRarity: 5 },
{ minLevel: 40, maxRarity: 6 },
];
/**
* Gibt die maximale erlaubte Rarity für ein Spielerlevel zurück.
* @param {number} playerLevel
* @returns {number} maxRarity
*/
function getMaxRarity(playerLevel) {
const level = Math.max(1, playerLevel || 1);
let result = RARITY_TABLE[0].maxRarity;
for (const entry of RARITY_TABLE) {
if (level >= entry.minLevel) result = entry.maxRarity;
else break;
}
return result;
}
module.exports = { getMaxRarity, RARITY_TABLE };