250 lines
7.8 KiB
PHP
250 lines
7.8 KiB
PHP
|
|
<?php
|
|||
|
|
declare(strict_types=1);
|
|||
|
|
|
|||
|
|
/** Westreiche – Regelkonstanten (Hausregeln V1.1, OSE-alike). */
|
|||
|
|
|
|||
|
|
const WS_ATTRIBUTES = [
|
|||
|
|
'attr_str' => ['STR', 'Stärke'],
|
|||
|
|
'attr_dex' => ['DEX', 'Geschicklichkeit'],
|
|||
|
|
'attr_con' => ['CON', 'Konstitution'],
|
|||
|
|
'attr_int' => ['INT', 'Intelligenz'],
|
|||
|
|
'attr_wis' => ['WIS', 'Weisheit'],
|
|||
|
|
'attr_cha' => ['CHA', 'Charisma'],
|
|||
|
|
];
|
|||
|
|
|
|||
|
|
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', '–'];
|
|||
|
|
|
|||
|
|
const WS_ITEM_CATEGORIES = ['Waffe', 'Rüstung', 'Schild', 'Ausrüstung', 'Verbrauch', 'Schatz', 'Sonstiges'];
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 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' => ['CON', 'Körper'],
|
|||
|
|
'Balancieren' => ['DEX', 'Körper'],
|
|||
|
|
'Fliegen' => ['DEX', 'Körper'],
|
|||
|
|
'Klettern' => ['STR', 'Körper'],
|
|||
|
|
'Reiten & Wagenführung' => ['DEX', 'Körper'],
|
|||
|
|
'Schleichen' => ['DEX', 'Körper'],
|
|||
|
|
'Schwimmen' => ['CON', 'Körper'],
|
|||
|
|
'Wahrnehmung' => ['WIS', 'Körper'],
|
|||
|
|
|
|||
|
|
'Wildniskunde' => ['WIS', 'Wildnis'],
|
|||
|
|
'Nahrung finden' => ['WIS', 'Wildnis'],
|
|||
|
|
'Navigation' => ['WIS', 'Wildnis'],
|
|||
|
|
'Orientierung' => ['INT', 'Wildnis'],
|
|||
|
|
'Pflanzenkunde' => ['INT', 'Wildnis'],
|
|||
|
|
'Segeln + Schiffahrt' => ['INT', 'Wildnis'],
|
|||
|
|
'Seilkunde' => ['DEX', 'Wildnis'],
|
|||
|
|
'Spurenlesen' => ['WIS', 'Wildnis'],
|
|||
|
|
|
|||
|
|
'Anführen' => ['CHA', 'Sozial'],
|
|||
|
|
'Aufführung' => ['CHA', 'Sozial'],
|
|||
|
|
'Einschüchtern' => ['STR', 'Sozial'],
|
|||
|
|
'Etikette' => ['CHA', 'Sozial'],
|
|||
|
|
'Handeln & Schätzen' => ['WIS', 'Sozial'],
|
|||
|
|
'Überzeugen' => ['CHA', 'Sozial'],
|
|||
|
|
'Verstellen' => ['INT', 'Sozial'],
|
|||
|
|
|
|||
|
|
'Alchimie' => ['INT', 'Wissen'],
|
|||
|
|
'Geschichts + Sagenkunde' => ['INT', 'Wissen'],
|
|||
|
|
'Handwerk' => ['DEX', 'Wissen'],
|
|||
|
|
'Heilkunde: Geist' => ['WIS', 'Wissen'],
|
|||
|
|
'Heilkunde: Gift' => ['INT', 'Wissen'],
|
|||
|
|
'Heilkunde: Krankheiten' => ['INT', 'Wissen'],
|
|||
|
|
'Heilkunde: Wunden' => ['WIS', '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');
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/** 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',
|
|||
|
|
];
|
|||
|
|
|
|||
|
|
/** 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;
|
|||
|
|
$table = WS_SAVE_TABLES[$base] ?? WS_SAVE_TABLES['Kämpfer'];
|
|||
|
|
$level = max(1, $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,
|
|||
|
|
];
|
|||
|
|
}
|