36 lines
1.2 KiB
JavaScript
36 lines
1.2 KiB
JavaScript
/* ============================================================
|
||
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 };
|