Charakterverwalter: Stufe aus Erfahrungspunkten und Klasse ableiten (WS_XP_TABLES)
This commit is contained in:
parent
f21b714d82
commit
b4d4c53dd4
8 changed files with 138 additions and 11 deletions
|
|
@ -94,7 +94,11 @@ zauberturm.de: Nachtblau/Schwarz/Gold, Pergament, Animationen.
|
|||
- **Ableitungen im Bogen:** Trefferwurf = Grundangriff + Attributsbonus
|
||||
(Nahkampf STR, Fernkampf DEX) + Waffenbonus; Schaden = Würfel + Bonus;
|
||||
RK = 10 + DEX-Bonus + angelegte Rüstung (Feld `characters.ac` = manueller
|
||||
Override, leer/0 = automatisch). Waffen-/Rüstungskatalog:
|
||||
Override, leer/0 = automatisch). **Stufe** wird aus `xp` + Klasse abgeleitet
|
||||
(`WS_XP_TABLES`/`WS_XP_STEP` in `app/rules.php`, OSE-Schwellen; Klassen über
|
||||
`WS_SAVE_BASE_CLASS` auf Kämpfer/Kleriker/Magier/Dieb abgebildet) und zieht
|
||||
die Rettungswürfe nach – die SL-Tabelle dort ändern, nicht in der DB.
|
||||
Waffen-/Rüstungskatalog:
|
||||
`sql/seed_equipment.sql`, Admin-Ansicht `/admin/equipment`.
|
||||
- **Zauberkatalog** wird aus dem Vault erzeugt:
|
||||
`python3 tools/build_spell_seed.py` → `westreiche_website/sql/seed_spells.sql`
|
||||
|
|
|
|||
|
|
@ -21,6 +21,12 @@ Garamond) mit Animationen.
|
|||
automatischem Attributsbonus nach Hausregel V1.1, Rettungswürfe, Gottheit,
|
||||
Alter/Größe/Gewicht, Erscheinung, Hintergrund, Notizen, Status
|
||||
(im Spiel / gefallen / Ruhestand).
|
||||
- **Stufe**: wird aus **Erfahrungspunkten + Klasse** abgeleitet
|
||||
(`WS_XP_TABLES` in `app/rules.php`, OSE-SRD-Schwellen 1–14, darüber
|
||||
linearer Schritt aus `WS_XP_STEP` bis Stufe 20 = `WS_MAX_LEVEL`). Das Feld
|
||||
im Bogen ist nur noch Anzeige; EP eintragen genügt. Eigene SL-Tabelle dort
|
||||
ändern, nicht in der DB – die Stufe wird bei jedem Speichern neu berechnet
|
||||
und zieht Rettungswürfe nach.
|
||||
- **Rettungswürfe**: kommen aus der Klassentabelle (`WS_SAVE_TABLES` in
|
||||
`app/rules.php`, OSE-SRD-Grundwerte) und werden bei Änderung von Klasse
|
||||
oder Stufe automatisch nachgezogen; einzelne Werte bleiben überschreibbar.
|
||||
|
|
|
|||
|
|
@ -54,9 +54,11 @@ function character_status_label(string $status): string
|
|||
|
||||
function character_create(int $userId, array $data): int
|
||||
{
|
||||
// Rettungswürfe starten auf dem Klassenwert der Stufe 1
|
||||
// Stufe folgt aus Erfahrungspunkten + Klasse (WS_XP_TABLES); Rettungswürfe
|
||||
// starten dann auf dem Klassenwert dieser Stufe
|
||||
// (Hausregel: Klasse + Stufe bestimmen den Grundwert).
|
||||
$data = array_merge($data, saving_throws_for((string) ($data['class_name'] ?? 'Kämpfer'), (int) ($data['level'] ?? 1)));
|
||||
$data['level'] = level_for_xp((string) ($data['class_name'] ?? 'Kämpfer'), (int) ($data['xp'] ?? 0));
|
||||
$data = array_merge($data, saving_throws_for((string) ($data['class_name'] ?? 'Kämpfer'), (int) $data['level']));
|
||||
|
||||
$stmt = db()->prepare(
|
||||
'INSERT INTO characters (user_id, name, title, class_name, level, xp, hp_max, hp_current, ac, attack_bonus,
|
||||
|
|
@ -197,12 +199,16 @@ function character_update(int $id, array $d): void
|
|||
{
|
||||
$before = character_find($id);
|
||||
|
||||
// Stufe aus Erfahrungspunkten und Klasse ableiten – sie ist die einzige
|
||||
// Quelle der Wahrheit, das Feld wird nicht mehr frei eingetragen.
|
||||
$d['level'] = level_for_xp((string) ($d['class_name'] ?? 'Kämpfer'), (int) ($d['xp'] ?? 0));
|
||||
|
||||
// Stufe oder Klasse geändert? Dann kommen die Rettungswürfe aus der Tabelle.
|
||||
if ($before !== null) {
|
||||
$levelChanged = (int) $before['level'] !== (int) ($d['level'] ?? 1);
|
||||
$levelChanged = (int) $before['level'] !== (int) $d['level'];
|
||||
$classChanged = (string) $before['class_name'] !== (string) ($d['class_name'] ?? '');
|
||||
if ($levelChanged || $classChanged) {
|
||||
$d = array_merge($d, saving_throws_for((string) ($d['class_name'] ?? 'Kämpfer'), (int) ($d['level'] ?? 1)));
|
||||
$d = array_merge($d, saving_throws_for((string) ($d['class_name'] ?? 'Kämpfer'), (int) $d['level']));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -477,7 +477,6 @@ function character_form_values(array $source): array
|
|||
$values['name'] = post_string('name', (string) ($source['name'] ?? ''));
|
||||
$values['title'] = post_string('title', (string) ($source['title'] ?? ''));
|
||||
$values['class_name'] = post_string('class_name', (string) ($source['class_name'] ?? 'Kämpfer'));
|
||||
$values['level'] = max(1, min(20, post_int('level', (int) ($source['level'] ?? 1))));
|
||||
$values['xp'] = max(0, post_int('xp', (int) ($source['xp'] ?? 0)));
|
||||
$values['hp_max'] = max(1, post_int('hp_max', (int) ($source['hp_max'] ?? 1)));
|
||||
$values['hp_current'] = post_int('hp_current', (int) ($source['hp_current'] ?? $values['hp_max']));
|
||||
|
|
@ -500,6 +499,9 @@ function character_form_values(array $source): array
|
|||
if (!in_array($values['class_name'], WS_CLASSES, true)) {
|
||||
$values['class_name'] = 'Kämpfer';
|
||||
}
|
||||
// Stufe wird aus Erfahrungspunkten und Klasse abgeleitet (WS_XP_TABLES) –
|
||||
// sie ist kein eigenes Eingabefeld mehr.
|
||||
$values['level'] = level_for_xp((string) $values['class_name'], (int) $values['xp']);
|
||||
foreach (WS_SAVES as $field => $label) {
|
||||
// Auf GET (Formular anzeigen) gilt der gespeicherte Wert; nur ein
|
||||
// tatsächlich abgeschicktes Feld überschreibt ihn.
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -354,6 +354,23 @@ main { padding-top: 2rem; }
|
|||
.badge.badge-admin { border-color: rgba(232, 199, 102, 0.8); color: #fff2c8; }
|
||||
.badge.badge-player { border-color: rgba(185, 171, 142, 0.45); color: var(--parchment-dim); background: rgba(185, 171, 142, 0.06); }
|
||||
|
||||
/* EP-Balken im Bogen: Fortschritt zur nächsten Stufe */
|
||||
.xp-bar {
|
||||
margin-top: 0.45rem;
|
||||
height: 5px;
|
||||
border-radius: 99px;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
overflow: hidden;
|
||||
border: 1px solid rgba(232, 199, 102, 0.25);
|
||||
}
|
||||
.xp-bar span {
|
||||
display: block;
|
||||
height: 100%;
|
||||
border-radius: 99px;
|
||||
background: linear-gradient(90deg, rgba(201, 162, 39, 0.55), var(--gold-bright));
|
||||
transition: width 0.6s ease;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- Formulare */
|
||||
|
||||
.btn {
|
||||
|
|
|
|||
|
|
@ -27,12 +27,22 @@
|
|||
</select>
|
||||
</label>
|
||||
<label class="field">
|
||||
<span>Stufe</span>
|
||||
<input type="number" name="level" min="1" max="20" value="<?= (int) $values['level'] ?>">
|
||||
<span>Stufe (aus EP)</span>
|
||||
<input type="text" value="<?= (int) $values['level'] ?>" readonly
|
||||
title="Wird aus Erfahrungspunkten und Klasse abgeleitet">
|
||||
<?php $xpProgress = xp_progress((string) $values['class_name'], (int) $values['xp']); ?>
|
||||
<small class="muted">
|
||||
<?= $xpProgress['next'] === null
|
||||
? 'höchste Stufe erreicht'
|
||||
: 'ab ' . number_format((int) $xpProgress['next'], 0, ',', '.') . ' EP Stufe ' . ((int) $xpProgress['level'] + 1) ?>
|
||||
</small>
|
||||
</label>
|
||||
<label class="field">
|
||||
<span>Erfahrungspunkte</span>
|
||||
<input type="number" name="xp" min="0" value="<?= (int) $values['xp'] ?>">
|
||||
<small class="muted">
|
||||
<?= number_format((int) $values['xp'], 0, ',', '.') ?> EP gesammelt
|
||||
</small>
|
||||
</label>
|
||||
<label class="field">
|
||||
<span>Gesinnung</span>
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ $equipped = array_values(array_filter($items, static fn ($item) => (int) $item['
|
|||
<?php endif; ?></h1>
|
||||
<p class="lede">
|
||||
<?= e((string) $character['class_name']) ?> · Stufe <?= (int) $character['level'] ?>
|
||||
· <?= (int) $character['xp'] ?> EP
|
||||
· <?= number_format((int) $character['xp'], 0, ',', '.') ?> EP<?php $xpProgress = xp_progress((string) $character['class_name'], (int) $character['xp']); ?><?php if ($xpProgress['next'] !== null): ?> (noch <?= number_format((int) $xpProgress['missing'], 0, ',', '.') ?> EP bis Stufe <?= (int) $xpProgress['level'] + 1 ?>)<?php endif; ?>
|
||||
<?php if ((string) $character['alignment'] !== '' && (string) $character['alignment'] !== '–'): ?>
|
||||
· <?= e((string) $character['alignment']) ?>
|
||||
<?php endif; ?>
|
||||
|
|
@ -84,6 +84,9 @@ $equipped = array_values(array_filter($items, static fn ($item) => (int) $item['
|
|||
<span style="display:block;height:100%;width:<?= (int) round($derived['hp_ratio'] * 100) ?>%;
|
||||
background: linear-gradient(90deg, <?= $derived['hp_state'] === 'healthy' ? 'var(--moss), var(--gold-bright)' : 'var(--blood), var(--ember)' ?>);"></span>
|
||||
</div>
|
||||
<div class="xp-bar" title="Erfahrung bis zur nächsten Stufe">
|
||||
<span style="width:<?= (int) round($xpProgress['ratio'] * 100) ?>%"></span>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
$saves = [];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue