Trefferpunkte aus Einzelwuerfen berechnen (1W4 + 1W je Stufe + KON)
This commit is contained in:
parent
216a62191e
commit
6a6ce7b197
11 changed files with 277 additions and 11 deletions
|
|
@ -539,6 +539,13 @@ function character_form_values(array $source): array
|
|||
$values['gender'] = character_gender(post_string('gender', (string) ($source['gender'] ?? WS_DEFAULT_GENDER)));
|
||||
$values['class_name'] = post_string('class_name', (string) ($source['class_name'] ?? 'Kämpfer'));
|
||||
$values['xp'] = max(0, post_int('xp', (int) ($source['xp'] ?? 0)));
|
||||
// Trefferpunkte: Einzelwürfe sind die Quelle, hp_max wird daraus berechnet
|
||||
// (nur ohne erfasste Würfe gilt ein manuell gesetzter Wert).
|
||||
$values['hp_rolls'] = hp_rolls_format(hp_rolls_parse(
|
||||
array_key_exists('hp_rolls', $_POST) && is_string($_POST['hp_rolls'])
|
||||
? (string) $_POST['hp_rolls']
|
||||
: ($source['hp_rolls'] ?? '')
|
||||
));
|
||||
$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']));
|
||||
$acRaw = post_string('ac', $source['ac'] === null ? '' : (string) $source['ac']);
|
||||
|
|
@ -563,6 +570,7 @@ function character_form_values(array $source): array
|
|||
// 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']);
|
||||
$values['hp_max'] = hp_max_for($values);
|
||||
foreach (WS_SAVES as $field => $label) {
|
||||
// Auf GET (Formular anzeigen) gilt der gespeicherte Wert; nur ein
|
||||
// tatsächlich abgeschicktes Feld überschreibt ihn.
|
||||
|
|
@ -581,6 +589,11 @@ function page_character_new(string $method, array $user): void
|
|||
{
|
||||
$error = '';
|
||||
$values = character_form_values(['attr_str' => 14, 'attr_dex' => 12, 'attr_con' => 11, 'attr_int' => 10, 'attr_wis' => 9, 'attr_cha' => 7]);
|
||||
// Neue Bögen starten mit ausgewürfelten Trefferpunkten (nachwürfelbar).
|
||||
if ($values['hp_rolls'] === '') {
|
||||
$values['hp_rolls'] = hp_rolls_format(hp_rolls_roll((string) $values['class_name'], (int) $values['level']));
|
||||
$values['hp_max'] = hp_max_for($values);
|
||||
}
|
||||
if ($method === 'POST') {
|
||||
if (!csrf_valid()) {
|
||||
$error = 'Die Sitzung ist abgelaufen. Bitte erneut versuchen.';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue