['STR', 'Stärke'], 'attr_dex' => ['GES', 'Geschicklichkeit'], 'attr_con' => ['KON', 'Konstitution'], 'attr_int' => ['INT', 'Intelligenz'], 'attr_wis' => ['WEI', 'Weisheit'], 'attr_cha' => ['CHA', 'Charisma'], ]; /** * Attributkürzel → Spaltenname am Charakterbogen. Die Kürzel sind deutsch * (GES, KON, WEI), die Spalten bleiben historisch attr_dex/attr_con/attr_wis. */ const WS_ATTRIBUTE_CODES = [ 'STR' => 'attr_str', 'GES' => 'attr_dex', 'KON' => 'attr_con', 'INT' => 'attr_int', 'WEI' => 'attr_wis', 'CHA' => 'attr_cha', ]; const WS_CLASSES = [ 'Kämpfer', 'Ritter', 'Paladin', 'Barbar', 'Waldläufer', 'Dieb', 'Assassine', 'Barde', 'Magier', 'Illusionist', 'Kleriker', 'Druide', ]; const WS_SAVES = [ 'save_death' => 'Tod & Gift', 'save_wand' => 'Zauberstäbe', 'save_paralysis' => 'Lähmung', 'save_breath' => 'Atemwaffen', 'save_spell' => 'Zauber', ]; const WS_ALIGNMENTS = ['Rechtschaffen', 'Neutral', 'Chaotisch', 'Gut', 'Böse', '–']; /** * Geschlecht: bestimmt das Platzhalterporträt (…-weiblich.webp). Der erste * Eintrag ist der Standardwert für neue und bestehende Charaktere. */ const WS_DEFAULT_GENDER = 'männlich'; const WS_GENDERS = ['männlich', 'weiblich']; const WS_ITEM_CATEGORIES = ['Waffe', 'Rüstung', 'Schild', 'Ausrüstung', 'Verbrauch', 'Schatz', 'Sonstiges']; /** * Verfügbarkeit im Ausrüstungskatalog: Methaven (Dorf) und Garana (Kleinstadt) * sind Stufen – was in Methaven zu haben ist, gibt es auch in Garana. Mächtige * oder seltene Ware führt nur der Filter „Alle“. */ const WS_ITEM_AVAILABILITY = [ 'methaven' => 'Methaven (Dorf)', 'garana' => 'Garana (Kleinstadt)', 'selten' => 'nur Alle', ]; /** * Fertigkeitengruppen wie auf dem Westreiche-Charakterbogen * (RPG/6-Dokumente/Charakterbogen.pdf): KÖRPER, WILDNIS, SOZIAL, WISSEN. */ const WS_SKILL_GROUPS = ['Körper', 'Wildnis', 'Sozial', 'Wissen']; const WS_SKILL_CATEGORIES = WS_SKILL_GROUPS; /** * Offizieller Fertigkeitenkatalog des Charakterbogens: * Name => [Attribut, Gruppe]. Startwert ist der Attributsbonus. */ const WS_SKILL_CATALOG = [ 'Ausdauer' => ['KON', 'Körper'], 'Balancieren' => ['GES', 'Körper'], 'Fliegen' => ['GES', 'Körper'], 'Klettern' => ['STR', 'Körper'], 'Reiten & Wagenführung' => ['GES', 'Körper'], 'Schleichen' => ['GES', 'Körper'], 'Schwimmen' => ['KON', 'Körper'], 'Wahrnehmung' => ['WEI', 'Körper'], 'Wildniskunde' => ['WEI', 'Wildnis'], 'Nahrung finden' => ['WEI', 'Wildnis'], 'Navigation' => ['WEI', 'Wildnis'], 'Orientierung' => ['INT', 'Wildnis'], 'Pflanzenkunde' => ['INT', 'Wildnis'], 'Segeln + Schiffahrt' => ['INT', 'Wildnis'], 'Seilkunde' => ['GES', 'Wildnis'], 'Spurenlesen' => ['WEI', 'Wildnis'], 'Anführen' => ['CHA', 'Sozial'], 'Aufführung' => ['CHA', 'Sozial'], 'Einschüchtern' => ['STR', 'Sozial'], 'Etikette' => ['CHA', 'Sozial'], 'Handeln & Schätzen' => ['WEI', 'Sozial'], 'Überzeugen' => ['CHA', 'Sozial'], 'Verstellen' => ['INT', 'Sozial'], 'Alchimie' => ['INT', 'Wissen'], 'Geschichts + Sagenkunde' => ['INT', 'Wissen'], 'Handwerk' => ['GES', 'Wissen'], 'Heilkunde: Geist' => ['WEI', 'Wissen'], 'Heilkunde: Gift' => ['INT', 'Wissen'], 'Heilkunde: Krankheiten' => ['INT', 'Wissen'], 'Heilkunde: Wunden' => ['WEI', 'Wissen'], 'Religionskunde' => ['INT', 'Wissen'], 'Verwaltung' => ['INT', 'Wissen'], 'Zauberkunde' => ['INT', 'Wissen'], ]; const WS_CHARACTER_STATUS = [ 'active' => 'im Spiel', 'dead' => 'gefallen', 'retired' => 'im Ruhestand', ]; /** * Attributsbonus nach Hausregel V1.1: * 3 → −3, 4–5 → −2, 6–8 → −1, 9–12 → 0, 13–15 → +1, 16–17 → +2, 18 → +3. * Werte über 18 werden wie 18 behandelt. */ function attribute_bonus(int $value): int { return match (true) { $value <= 3 => -3, $value <= 5 => -2, $value <= 8 => -1, $value <= 12 => 0, $value <= 15 => 1, $value <= 17 => 2, default => 3, }; } function signed(int $value): string { return $value > 0 ? '+' . $value : (string) $value; } /** * CSS-Klasse für einen Bonus: positive Werte grün, Null grau, negative rot. */ function bonus_class(int $value): string { return $value > 0 ? 'bonus-pos' : ($value < 0 ? 'bonus-neg' : 'bonus-zero'); } /** Attributkürzel (STR, GES, …) prüfen; unbekannte Werte werden zu ''. */ function skill_attribute_code(string $value): string { $code = strtoupper(trim($value)); return isset(WS_ATTRIBUTE_CODES[$code]) ? $code : ''; } /** Spaltenname (attr_dex …) zu einem Attributkürzel; unbekannt → ''. */ function attribute_field_for_code(string $code): string { return WS_ATTRIBUTE_CODES[skill_attribute_code($code)] ?? ''; } /** * Rettungswurf-Feld formatieren; leere Werte bleiben ein Gedankenstrich. */ function save_display(mixed $value): string { if ($value === null || $value === '') { return '–'; } return (string) (int) $value; } /* ------------------------------------------------------- Rettungswürfe */ /** * Rettungswurf-Grundwerte je Klasse und Stufe (Würfelwurf ≥ Wert, OSE-SRD). * * Aufbau: Klassenname → Liste aus [bis Stufe, [Tod & Gift, Zauberstäbe, * Lähmung, Atemwaffen, Zauber]]. Der erste Eintrag, dessen Stufengrenze * erreicht ist, gilt. Die Westreiche-Klassen ohne eigene Tabelle laufen auf * der passenden Grundklasse: Kämpfer, Ritter, Paladin, Barbar und Waldläufer * auf der Kämpfer-Tabelle, Druide auf der Kleriker-, Assassine und Barde auf * der Diebes-Tabelle. */ const WS_SAVE_TABLES = [ 'Kämpfer' => [ [3, [12, 13, 14, 15, 16]], [6, [10, 11, 12, 13, 14]], [9, [8, 9, 10, 11, 12]], [12, [6, 7, 8, 9, 10]], [99, [4, 5, 6, 7, 8]], ], 'Kleriker' => [ [3, [11, 12, 14, 16, 15]], [6, [9, 10, 12, 14, 13]], [9, [6, 7, 9, 11, 10]], [12, [3, 5, 7, 8, 8]], [99, [2, 3, 5, 6, 6]], ], 'Magier' => [ [5, [13, 14, 13, 16, 15]], [10, [11, 12, 11, 14, 12]], [99, [8, 9, 8, 11, 8]], ], 'Dieb' => [ [4, [13, 14, 13, 16, 15]], [8, [12, 13, 11, 14, 13]], [12, [11, 10, 9, 12, 10]], [99, [9, 8, 7, 10, 8]], ], ]; /** Klasse → Grundklasse für Rettungswürfe. */ const WS_SAVE_BASE_CLASS = [ 'Ritter' => 'Kämpfer', 'Paladin' => 'Kämpfer', 'Barbar' => 'Kämpfer', 'Waldläufer' => 'Kämpfer', 'Druide' => 'Kleriker', 'Illusionist' => 'Magier', 'Assassine' => 'Dieb', '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 = class_base_class($className); $table = WS_SAVE_TABLES[$base] ?? WS_SAVE_TABLES['Kämpfer']; $level = max(1, min(WS_MAX_LEVEL, $level)); $values = $table[count($table) - 1][1]; foreach ($table as [$maxLevel, $row]) { if ($level <= $maxLevel) { $values = $row; break; } } $fields = array_keys(WS_SAVES); $result = []; foreach ($fields as $index => $field) { $result[$field] = $values[$index]; } return $result; } /* ----------------------------------------- Waffen und Rüstungen (Ableitung) */ /** Trefferwurf mit einer Waffe: Grundangriff + Attributsbonus + Waffenbonus. */ function weapon_attack_total(array $character, array $weapon): int { $attribute = ($weapon['category'] ?? 'Nahkampf') === 'Fernkampf' ? 'attr_dex' : 'attr_str'; return (int) ($character['attack_bonus'] ?? 0) + attribute_bonus((int) ($character[$attribute] ?? 10)) + (int) ($weapon['attack_bonus'] ?? 0); } /** Schaden mit Waffe: Würfelausdruck + Attributsbonus (bei Fernkampf Geschick). */ function weapon_damage_total(array $character, array $weapon): string { $damage = trim((string) ($weapon['damage'] ?? '')); if ($damage === '') { return '–'; } $attribute = ($weapon['category'] ?? 'Nahkampf') === 'Fernkampf' ? 'attr_dex' : 'attr_str'; $bonus = attribute_bonus((int) ($character[$attribute] ?? 10)); return $bonus === 0 ? $damage : $damage . signed($bonus); } /** * Rüstungsklasse: 10 + Geschicklichkeitsbonus + alle angelegten Rüstungsteile. * Ein manueller Wert in characters.ac (nicht NULL) überschreibt das. */ function armor_class_total(array $character, array $armors): array { $dexterity = attribute_bonus((int) ($character['attr_dex'] ?? 10)); $armorBonus = 0; foreach ($armors as $armor) { if ((int) ($armor['equipped'] ?? 0) === 1) { $armorBonus += (int) ($armor['ac_bonus'] ?? 0); } } $derived = 10 + $dexterity + $armorBonus; $manual = $character['ac'] ?? null; $isManual = $manual !== null && $manual !== '' && (int) $manual > 0; return [ 'derived' => $derived, 'manual' => $isManual ? (int) $manual : null, 'total' => $isManual ? (int) $manual : $derived, 'dexterity' => $dexterity, 'armor' => $armorBonus, 'manual_active' => $isManual, ]; }