Charakterverwalter: Fertigkeiten-Attribut für eigene Einträge, Stufe ohne Vorzeichen
- eigenedefinierte Fertigkeiten bekommen ein Bezugsattribut (STR…CHA) im Selektor und lassen es im Bearbeiten-Abschnitt korrigieren - neue Spalte character_skills.attribute (Migration 2, schema.sql angepasst); character_skills() nutzt COALESCE aus Zeilen- und Katalogattribut - Fertigkeitsstufe startet bei max(0, Attributsbonus) und wird in Formular, Update und Anzeige (Web-Bogen, PDF) nie negativ bzw. nie mit Vorzeichen gezeigt - MOD- und Stufe-Spalte im Bogen auf gemeinsame Grundlinie gezogen
This commit is contained in:
parent
b4d4c53dd4
commit
929aa52c73
10 changed files with 86 additions and 30 deletions
|
|
@ -152,7 +152,7 @@ function character_seed_skills(int $characterId): int
|
|||
$count = 0;
|
||||
foreach (skills_catalog() as $skill) {
|
||||
$attribute = trim((string) ($skill['attribute'] ?? ''));
|
||||
$bonus = $attribute === '' ? 0 : attribute_bonus((int) ($character['attr_' . strtolower($attribute)] ?? 10));
|
||||
$bonus = $attribute === '' ? 0 : max(0, attribute_bonus((int) ($character['attr_' . strtolower($attribute)] ?? 10)));
|
||||
$insert->execute([$characterId, (int) $skill['id'], (string) $skill['name'], $bonus]);
|
||||
$count++;
|
||||
}
|
||||
|
|
@ -170,23 +170,15 @@ function character_reset_skills(int $characterId, bool $force = false): int
|
|||
if ($character === null) {
|
||||
return 0;
|
||||
}
|
||||
$catalog = [];
|
||||
foreach (skills_catalog() as $skill) {
|
||||
$catalog[(int) $skill['id']] = $skill;
|
||||
}
|
||||
$changed = 0;
|
||||
$update = db()->prepare('UPDATE character_skills SET bonus = ? WHERE id = ?');
|
||||
foreach (character_skills($characterId) as $row) {
|
||||
$skill = $catalog[(int) ($row['skill_id'] ?? 0)] ?? null;
|
||||
if ($skill === null) {
|
||||
continue;
|
||||
}
|
||||
$attribute = trim((string) ($skill['attribute'] ?? ''));
|
||||
$attribute = trim((string) ($row['attribute'] ?? ''));
|
||||
if ($attribute === '') {
|
||||
continue;
|
||||
}
|
||||
$target = attribute_bonus((int) ($character['attr_' . strtolower($attribute)] ?? 10));
|
||||
if ($force || (int) $row['bonus'] === $target) {
|
||||
$target = max(0, attribute_bonus((int) ($character['attr_' . strtolower($attribute)] ?? 10)));
|
||||
if ($force || (int) $row['bonus'] === $target || (int) $row['bonus'] < 0) {
|
||||
$update->execute([$target, (int) $row['id']]);
|
||||
$changed++;
|
||||
}
|
||||
|
|
@ -326,15 +318,18 @@ function skills_catalog_delete(int $id): void
|
|||
function character_skills(int $characterId): array
|
||||
{
|
||||
$stmt = db()->prepare(
|
||||
'SELECT cs.*, s.attribute, s.category FROM character_skills cs
|
||||
"SELECT cs.id, cs.character_id, cs.skill_id, cs.name, cs.bonus, cs.note,
|
||||
COALESCE(NULLIF(cs.attribute, ''), s.attribute) AS attribute,
|
||||
s.category
|
||||
FROM character_skills cs
|
||||
LEFT JOIN skills s ON s.id = cs.skill_id
|
||||
WHERE cs.character_id = ? ORDER BY cs.name'
|
||||
WHERE cs.character_id = ? ORDER BY cs.name"
|
||||
);
|
||||
$stmt->execute([$characterId]);
|
||||
return $stmt->fetchAll();
|
||||
}
|
||||
|
||||
function character_skill_add(int $characterId, ?int $skillId, string $name, int $bonus, string $note): void
|
||||
function character_skill_add(int $characterId, ?int $skillId, string $name, int $bonus, string $note, string $attribute = ''): void
|
||||
{
|
||||
if ($skillId !== null && $name === '') {
|
||||
$stmt = db()->prepare('SELECT name FROM skills WHERE id = ?');
|
||||
|
|
@ -345,9 +340,16 @@ function character_skill_add(int $characterId, ?int $skillId, string $name, int
|
|||
return;
|
||||
}
|
||||
db()->prepare(
|
||||
'INSERT INTO character_skills (character_id, skill_id, name, bonus, note) VALUES (?, ?, ?, ?, ?)
|
||||
ON DUPLICATE KEY UPDATE bonus = VALUES(bonus), note = VALUES(note), skill_id = VALUES(skill_id)'
|
||||
)->execute([$characterId, $skillId, shorten($name, 80), $bonus, shorten($note, 255)]);
|
||||
'INSERT INTO character_skills (character_id, skill_id, name, attribute, bonus, note) VALUES (?, ?, ?, ?, ?, ?)
|
||||
ON DUPLICATE KEY UPDATE attribute = VALUES(attribute), bonus = VALUES(bonus), note = VALUES(note), skill_id = VALUES(skill_id)'
|
||||
)->execute([
|
||||
$characterId,
|
||||
$skillId,
|
||||
shorten($name, 80),
|
||||
skill_attribute_code($attribute),
|
||||
max(0, min(30, $bonus)),
|
||||
shorten($note, 255),
|
||||
]);
|
||||
}
|
||||
|
||||
function character_skill_delete(int $characterId, int $id): void
|
||||
|
|
@ -647,10 +649,16 @@ function character_armor_toggle(int $characterId, int $id): void
|
|||
->execute([$id, $characterId]);
|
||||
}
|
||||
|
||||
function character_skill_update(int $characterId, int $id, int $bonus, string $note): void
|
||||
function character_skill_update(int $characterId, int $id, int $bonus, string $note, ?string $attribute = null): void
|
||||
{
|
||||
db()->prepare('UPDATE character_skills SET bonus = ?, note = ? WHERE id = ? AND character_id = ?')
|
||||
->execute([max(-10, min(30, $bonus)), shorten($note, 255), $id, $characterId]);
|
||||
db()->prepare('UPDATE character_skills SET attribute = COALESCE(?, attribute), bonus = ?, note = ? WHERE id = ? AND character_id = ?')
|
||||
->execute([
|
||||
$attribute === null ? null : skill_attribute_code($attribute),
|
||||
max(0, min(30, $bonus)),
|
||||
shorten($note, 255),
|
||||
$id,
|
||||
$characterId,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue