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
|
|
@ -60,12 +60,20 @@ function character_create(int $userId, array $data): int
|
|||
$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']));
|
||||
|
||||
// Trefferpunkte: neue Bögen starten mit ausgewürfelten Einzelwürfen,
|
||||
// hp_max ergibt sich daraus (Stufe 0: 1W4, je Stufe 1W<Klassenwürfel>).
|
||||
$data['hp_rolls'] = hp_rolls_format(hp_rolls_parse($data['hp_rolls'] ?? ''));
|
||||
if ($data['hp_rolls'] === '') {
|
||||
$data['hp_rolls'] = hp_rolls_format(hp_rolls_roll((string) ($data['class_name'] ?? 'Kämpfer'), (int) $data['level']));
|
||||
}
|
||||
$data['hp_max'] = hp_max_for($data);
|
||||
|
||||
$stmt = db()->prepare(
|
||||
'INSERT INTO characters (user_id, name, title, gender, class_name, level, xp, hp_max, hp_current, ac, attack_bonus,
|
||||
'INSERT INTO characters (user_id, name, title, gender, class_name, level, xp, hp_max, hp_rolls, hp_current, ac, attack_bonus,
|
||||
attr_str, attr_dex, attr_con, attr_int, attr_wis, attr_cha,
|
||||
save_death, save_wand, save_paralysis, save_breath, save_spell,
|
||||
alignment, created_at, updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'
|
||||
);
|
||||
$stmt->execute([
|
||||
$userId,
|
||||
|
|
@ -76,6 +84,7 @@ function character_create(int $userId, array $data): int
|
|||
$data['level'] ?? 1,
|
||||
$data['xp'] ?? 0,
|
||||
$data['hp_max'] ?? 1,
|
||||
$data['hp_rolls'] ?? '',
|
||||
$data['hp_current'] ?? $data['hp_max'] ?? 1,
|
||||
character_ac_value($data['ac'] ?? null),
|
||||
$data['attack_bonus'] ?? 0,
|
||||
|
|
@ -207,8 +216,13 @@ function character_update(int $id, array $d): void
|
|||
}
|
||||
}
|
||||
|
||||
// Trefferpunkte sind berechnet: einzelne Würfe speichern, hp_max daraus
|
||||
// ableiten (ohne erfasste Würfe bleibt hp_max der manuelle Wert).
|
||||
$d['hp_rolls'] = hp_rolls_format(hp_rolls_parse($d['hp_rolls'] ?? ($before['hp_rolls'] ?? '')));
|
||||
$d['hp_max'] = hp_max_for($d);
|
||||
|
||||
$stmt = db()->prepare(
|
||||
'UPDATE characters SET name = ?, title = ?, gender = ?, class_name = ?, level = ?, xp = ?, hp_max = ?, hp_current = ?,
|
||||
'UPDATE characters SET name = ?, title = ?, gender = ?, class_name = ?, level = ?, xp = ?, hp_max = ?, hp_rolls = ?, hp_current = ?,
|
||||
ac = ?, attack_bonus = ?, attr_str = ?, attr_dex = ?, attr_con = ?, attr_int = ?, attr_wis = ?, attr_cha = ?,
|
||||
save_death = ?, save_wand = ?, save_paralysis = ?, save_breath = ?, save_spell = ?,
|
||||
alignment = ?, deity = ?, age = ?, height = ?, weight = ?, gold_coins = ?,
|
||||
|
|
@ -223,6 +237,7 @@ function character_update(int $id, array $d): void
|
|||
$d['level'] ?? 1,
|
||||
$d['xp'] ?? 0,
|
||||
$d['hp_max'] ?? 1,
|
||||
$d['hp_rolls'] ?? '',
|
||||
$d['hp_current'] ?? 1,
|
||||
character_ac_value($d['ac'] ?? null),
|
||||
$d['attack_bonus'] ?? 0,
|
||||
|
|
@ -298,7 +313,7 @@ function character_derived(array $c): array
|
|||
$bonuses[$field] = attribute_bonus((int) ($c[$field] ?? 10));
|
||||
}
|
||||
$hp = max(0, (int) $c['hp_current']);
|
||||
$hpMax = max(1, (int) $c['hp_max']);
|
||||
$hpMax = max(1, hp_max_for($c));
|
||||
return [
|
||||
'bonuses' => $bonuses,
|
||||
'hp_ratio' => min(1.0, $hp / $hpMax),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue