Charakterverwalter: Stufe aus Erfahrungspunkten und Klasse ableiten (WS_XP_TABLES)

This commit is contained in:
torsten 2026-11-21 10:15:56 +01:00
parent f21b714d82
commit b4d4c53dd4
8 changed files with 138 additions and 11 deletions

View file

@ -178,12 +178,91 @@ const WS_SAVE_BASE_CLASS = [
'Barde' => 'Dieb',
];
/* ----------------------------------------------- Stufen aus Erfahrung */
/** Höchste Stufe, die die App kennt (Formular, EP-Tabellen). */
const WS_MAX_LEVEL = 20;
/**
* Erfahrungspunkte, ab denen eine Stufe erreicht ist (OSE-SRD, Stufe 1–14).
* Index 0 = Stufe 1. Die Westreiche-Klassen laufen über
* WS_SAVE_BASE_CLASS auf der passenden Grundklasse.
*/
const WS_XP_TABLES = [
'Kämpfer' => [0, 2000, 4000, 8000, 16000, 32000, 64000, 120000, 240000, 360000, 480000, 600000, 720000, 840000],
'Kleriker' => [0, 1500, 3000, 6000, 12000, 25000, 50000, 100000, 200000, 300000, 400000, 500000, 600000, 700000],
'Magier' => [0, 2500, 5000, 10000, 20000, 40000, 80000, 150000, 300000, 450000, 600000, 750000, 900000, 1050000],
'Dieb' => [0, 1250, 2500, 5000, 10000, 20000, 40000, 80000, 160000, 280000, 400000, 520000, 640000, 760000],
];
/**
* EP-Zuwachs je weiterer Stufe oberhalb der OSE-Tabelle – damit die
* epische Leiter bis Stufe 20 weiterläuft (Namenstufe + fester Schritt).
*/
const WS_XP_STEP = [
'Kämpfer' => 120000,
'Kleriker' => 100000,
'Magier' => 150000,
'Dieb' => 120000,
];
/** EP-Schwellen je Stufe (Index 0 = Stufe 1) bis WS_MAX_LEVEL. */
function xp_thresholds_for(string $className): array
{
$base = class_base_class($className);
$thresholds = WS_XP_TABLES[$base] ?? WS_XP_TABLES['Kämpfer'];
$step = WS_XP_STEP[$base] ?? 120000;
while (count($thresholds) < WS_MAX_LEVEL) {
$thresholds[] = $thresholds[count($thresholds) - 1] + $step;
}
return array_slice($thresholds, 0, WS_MAX_LEVEL);
}
/** Stufe aus Erfahrungspunkten und Klasse ableiten (1 … WS_MAX_LEVEL). */
function level_for_xp(string $className, int $xp): int
{
$level = 1;
foreach (xp_thresholds_for($className) as $index => $threshold) {
if ($xp >= $threshold) {
$level = $index + 1;
}
}
return $level;
}
/**
* EP-Stand für die Anzeige: aktuelle Stufe, Schwelle der Stufe, Schwelle der
* nächsten Stufe, fehlende EP und Füllstand (0 … 1) für Balken.
*/
function xp_progress(string $className, int $xp): array
{
$xp = max(0, $xp);
$thresholds = xp_thresholds_for($className);
$level = level_for_xp($className, $xp);
$current = $thresholds[$level - 1];
$next = $thresholds[$level] ?? null;
$span = $next === null ? 0 : $next - $current;
return [
'level' => $level,
'current' => $current,
'next' => $next,
'missing' => $next === null ? 0 : max(0, $next - $xp),
'ratio' => $span > 0 ? min(1.0, max(0.0, ($xp - $current) / $span)) : 1.0,
];
}
/** Klasse → Grundklasse (für Rettungswürfe und EP-Tabellen). */
function class_base_class(string $className): string
{
return WS_SAVE_BASE_CLASS[$className] ?? $className;
}
/** Rettungswürfe für Klasse + Stufe als Feld → Wert. */
function saving_throws_for(string $className, int $level): array
{
$base = WS_SAVE_BASE_CLASS[$className] ?? $className;
$base = class_base_class($className);
$table = WS_SAVE_TABLES[$base] ?? WS_SAVE_TABLES['Kämpfer'];
$level = max(1, $level);
$level = max(1, min(WS_MAX_LEVEL, $level));
$values = $table[count($table) - 1][1];
foreach ($table as [$maxLevel, $row]) {
if ($level <= $maxLevel) {