Attributkuerzel deutsch: GES, KON, WEI (Migration 5 inkl. Daten)
This commit is contained in:
parent
a79e7e7781
commit
be55f9c3f5
6 changed files with 62 additions and 35 deletions
|
|
@ -153,7 +153,8 @@ function character_seed_skills(int $characterId): int
|
||||||
$count = 0;
|
$count = 0;
|
||||||
foreach (skills_catalog() as $skill) {
|
foreach (skills_catalog() as $skill) {
|
||||||
$attribute = trim((string) ($skill['attribute'] ?? ''));
|
$attribute = trim((string) ($skill['attribute'] ?? ''));
|
||||||
$bonus = $attribute === '' ? 0 : max(0, attribute_bonus((int) ($character['attr_' . strtolower($attribute)] ?? 10)));
|
$field = attribute_field_for_code($attribute);
|
||||||
|
$bonus = $field === '' ? 0 : max(0, attribute_bonus((int) ($character[$field] ?? 10)));
|
||||||
$insert->execute([$characterId, (int) $skill['id'], (string) $skill['name'], $bonus]);
|
$insert->execute([$characterId, (int) $skill['id'], (string) $skill['name'], $bonus]);
|
||||||
$count++;
|
$count++;
|
||||||
}
|
}
|
||||||
|
|
@ -175,10 +176,11 @@ function character_reset_skills(int $characterId, bool $force = false): int
|
||||||
$update = db()->prepare('UPDATE character_skills SET bonus = ? WHERE id = ?');
|
$update = db()->prepare('UPDATE character_skills SET bonus = ? WHERE id = ?');
|
||||||
foreach (character_skills($characterId) as $row) {
|
foreach (character_skills($characterId) as $row) {
|
||||||
$attribute = trim((string) ($row['attribute'] ?? ''));
|
$attribute = trim((string) ($row['attribute'] ?? ''));
|
||||||
if ($attribute === '') {
|
$field = attribute_field_for_code($attribute);
|
||||||
|
if ($field === '') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$target = max(0, attribute_bonus((int) ($character['attr_' . strtolower($attribute)] ?? 10)));
|
$target = max(0, attribute_bonus((int) ($character[$field] ?? 10)));
|
||||||
if ($force || (int) $row['bonus'] === $target || (int) $row['bonus'] < 0) {
|
if ($force || (int) $row['bonus'] === $target || (int) $row['bonus'] < 0) {
|
||||||
$update->execute([$target, (int) $row['id']]);
|
$update->execute([$target, (int) $row['id']]);
|
||||||
$changed++;
|
$changed++;
|
||||||
|
|
@ -1024,9 +1026,9 @@ function skills_grouped(array $skills): array
|
||||||
/** Attributsbonus (MOD) einer Fertigkeit für einen Charakter. */
|
/** Attributsbonus (MOD) einer Fertigkeit für einen Charakter. */
|
||||||
function skill_attribute_modifier(array $character, array $skill): ?int
|
function skill_attribute_modifier(array $character, array $skill): ?int
|
||||||
{
|
{
|
||||||
$attribute = strtolower(trim((string) ($skill['attribute'] ?? '')));
|
$field = attribute_field_for_code((string) ($skill['attribute'] ?? ''));
|
||||||
if ($attribute === '') {
|
if ($field === '') {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return attribute_bonus((int) ($character['attr_' . $attribute] ?? 10));
|
return attribute_bonus((int) ($character[$field] ?? 10));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,17 @@ const WS_MIGRATIONS = [
|
||||||
4 => [
|
4 => [
|
||||||
"ALTER TABLE characters ADD COLUMN IF NOT EXISTS gender VARCHAR(20) NOT NULL DEFAULT 'männlich' AFTER title",
|
"ALTER TABLE characters ADD COLUMN IF NOT EXISTS gender VARCHAR(20) NOT NULL DEFAULT 'männlich' AFTER title",
|
||||||
],
|
],
|
||||||
|
// 5: Attributkürzel deutsch (GES/KON/WEI statt DEX/CON/WIS). Erst die
|
||||||
|
// Daten umschlüsseln, dann den ENUM der Katalogtabelle nachziehen.
|
||||||
|
5 => [
|
||||||
|
"UPDATE skills SET attribute = 'GES' WHERE attribute = 'DEX'",
|
||||||
|
"UPDATE skills SET attribute = 'KON' WHERE attribute = 'CON'",
|
||||||
|
"UPDATE skills SET attribute = 'WEI' WHERE attribute = 'WIS'",
|
||||||
|
"UPDATE character_skills SET attribute = 'GES' WHERE attribute = 'DEX'",
|
||||||
|
"UPDATE character_skills SET attribute = 'KON' WHERE attribute = 'CON'",
|
||||||
|
"UPDATE character_skills SET attribute = 'WEI' WHERE attribute = 'WIS'",
|
||||||
|
"ALTER TABLE skills MODIFY attribute ENUM('STR', 'GES', 'KON', 'INT', 'WEI', 'CHA', '') NOT NULL DEFAULT ''",
|
||||||
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
function ws_migrations_apply(PDO $pdo): void
|
function ws_migrations_apply(PDO $pdo): void
|
||||||
|
|
|
||||||
|
|
@ -878,7 +878,7 @@ function page_admin_skills(string $method, array $user): void
|
||||||
$category = post_string('category', 'Allgemein');
|
$category = post_string('category', 'Allgemein');
|
||||||
if ($name === '') {
|
if ($name === '') {
|
||||||
$error = 'Bitte einen Namen angeben.';
|
$error = 'Bitte einen Namen angeben.';
|
||||||
} elseif (!in_array($attribute, ['STR', 'DEX', 'CON', 'INT', 'WIS', 'CHA', ''], true)) {
|
} elseif (!in_array($attribute, array_merge(array_keys(WS_ATTRIBUTE_CODES), ['']), true)) {
|
||||||
$attribute = '';
|
$attribute = '';
|
||||||
} else {
|
} else {
|
||||||
skills_catalog_add($name, $attribute, $category);
|
skills_catalog_add($name, $attribute, $category);
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,26 @@ declare(strict_types=1);
|
||||||
|
|
||||||
const WS_ATTRIBUTES = [
|
const WS_ATTRIBUTES = [
|
||||||
'attr_str' => ['STR', 'Stärke'],
|
'attr_str' => ['STR', 'Stärke'],
|
||||||
'attr_dex' => ['DEX', 'Geschicklichkeit'],
|
'attr_dex' => ['GES', 'Geschicklichkeit'],
|
||||||
'attr_con' => ['CON', 'Konstitution'],
|
'attr_con' => ['KON', 'Konstitution'],
|
||||||
'attr_int' => ['INT', 'Intelligenz'],
|
'attr_int' => ['INT', 'Intelligenz'],
|
||||||
'attr_wis' => ['WIS', 'Weisheit'],
|
'attr_wis' => ['WEI', 'Weisheit'],
|
||||||
'attr_cha' => ['CHA', 'Charisma'],
|
'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 = [
|
const WS_CLASSES = [
|
||||||
'Kämpfer', 'Ritter', 'Paladin', 'Barbar', 'Waldläufer',
|
'Kämpfer', 'Ritter', 'Paladin', 'Barbar', 'Waldläufer',
|
||||||
'Dieb', 'Assassine', 'Barde',
|
'Dieb', 'Assassine', 'Barde',
|
||||||
|
|
@ -60,39 +73,39 @@ const WS_SKILL_CATEGORIES = WS_SKILL_GROUPS;
|
||||||
* Name => [Attribut, Gruppe]. Startwert ist der Attributsbonus.
|
* Name => [Attribut, Gruppe]. Startwert ist der Attributsbonus.
|
||||||
*/
|
*/
|
||||||
const WS_SKILL_CATALOG = [
|
const WS_SKILL_CATALOG = [
|
||||||
'Ausdauer' => ['CON', 'Körper'],
|
'Ausdauer' => ['KON', 'Körper'],
|
||||||
'Balancieren' => ['DEX', 'Körper'],
|
'Balancieren' => ['GES', 'Körper'],
|
||||||
'Fliegen' => ['DEX', 'Körper'],
|
'Fliegen' => ['GES', 'Körper'],
|
||||||
'Klettern' => ['STR', 'Körper'],
|
'Klettern' => ['STR', 'Körper'],
|
||||||
'Reiten & Wagenführung' => ['DEX', 'Körper'],
|
'Reiten & Wagenführung' => ['GES', 'Körper'],
|
||||||
'Schleichen' => ['DEX', 'Körper'],
|
'Schleichen' => ['GES', 'Körper'],
|
||||||
'Schwimmen' => ['CON', 'Körper'],
|
'Schwimmen' => ['KON', 'Körper'],
|
||||||
'Wahrnehmung' => ['WIS', 'Körper'],
|
'Wahrnehmung' => ['WEI', 'Körper'],
|
||||||
|
|
||||||
'Wildniskunde' => ['WIS', 'Wildnis'],
|
'Wildniskunde' => ['WEI', 'Wildnis'],
|
||||||
'Nahrung finden' => ['WIS', 'Wildnis'],
|
'Nahrung finden' => ['WEI', 'Wildnis'],
|
||||||
'Navigation' => ['WIS', 'Wildnis'],
|
'Navigation' => ['WEI', 'Wildnis'],
|
||||||
'Orientierung' => ['INT', 'Wildnis'],
|
'Orientierung' => ['INT', 'Wildnis'],
|
||||||
'Pflanzenkunde' => ['INT', 'Wildnis'],
|
'Pflanzenkunde' => ['INT', 'Wildnis'],
|
||||||
'Segeln + Schiffahrt' => ['INT', 'Wildnis'],
|
'Segeln + Schiffahrt' => ['INT', 'Wildnis'],
|
||||||
'Seilkunde' => ['DEX', 'Wildnis'],
|
'Seilkunde' => ['GES', 'Wildnis'],
|
||||||
'Spurenlesen' => ['WIS', 'Wildnis'],
|
'Spurenlesen' => ['WEI', 'Wildnis'],
|
||||||
|
|
||||||
'Anführen' => ['CHA', 'Sozial'],
|
'Anführen' => ['CHA', 'Sozial'],
|
||||||
'Aufführung' => ['CHA', 'Sozial'],
|
'Aufführung' => ['CHA', 'Sozial'],
|
||||||
'Einschüchtern' => ['STR', 'Sozial'],
|
'Einschüchtern' => ['STR', 'Sozial'],
|
||||||
'Etikette' => ['CHA', 'Sozial'],
|
'Etikette' => ['CHA', 'Sozial'],
|
||||||
'Handeln & Schätzen' => ['WIS', 'Sozial'],
|
'Handeln & Schätzen' => ['WEI', 'Sozial'],
|
||||||
'Überzeugen' => ['CHA', 'Sozial'],
|
'Überzeugen' => ['CHA', 'Sozial'],
|
||||||
'Verstellen' => ['INT', 'Sozial'],
|
'Verstellen' => ['INT', 'Sozial'],
|
||||||
|
|
||||||
'Alchimie' => ['INT', 'Wissen'],
|
'Alchimie' => ['INT', 'Wissen'],
|
||||||
'Geschichts + Sagenkunde' => ['INT', 'Wissen'],
|
'Geschichts + Sagenkunde' => ['INT', 'Wissen'],
|
||||||
'Handwerk' => ['DEX', 'Wissen'],
|
'Handwerk' => ['GES', 'Wissen'],
|
||||||
'Heilkunde: Geist' => ['WIS', 'Wissen'],
|
'Heilkunde: Geist' => ['WEI', 'Wissen'],
|
||||||
'Heilkunde: Gift' => ['INT', 'Wissen'],
|
'Heilkunde: Gift' => ['INT', 'Wissen'],
|
||||||
'Heilkunde: Krankheiten' => ['INT', 'Wissen'],
|
'Heilkunde: Krankheiten' => ['INT', 'Wissen'],
|
||||||
'Heilkunde: Wunden' => ['WIS', 'Wissen'],
|
'Heilkunde: Wunden' => ['WEI', 'Wissen'],
|
||||||
'Religionskunde' => ['INT', 'Wissen'],
|
'Religionskunde' => ['INT', 'Wissen'],
|
||||||
'Verwaltung' => ['INT', 'Wissen'],
|
'Verwaltung' => ['INT', 'Wissen'],
|
||||||
'Zauberkunde' => ['INT', 'Wissen'],
|
'Zauberkunde' => ['INT', 'Wissen'],
|
||||||
|
|
@ -135,16 +148,17 @@ function bonus_class(int $value): string
|
||||||
return $value > 0 ? 'bonus-pos' : ($value < 0 ? 'bonus-neg' : 'bonus-zero');
|
return $value > 0 ? 'bonus-pos' : ($value < 0 ? 'bonus-neg' : 'bonus-zero');
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Attributkürzel (STR, DEX, …) prüfen; unbekannte Werte werden zu ''. */
|
/** Attributkürzel (STR, GES, …) prüfen; unbekannte Werte werden zu ''. */
|
||||||
function skill_attribute_code(string $value): string
|
function skill_attribute_code(string $value): string
|
||||||
{
|
{
|
||||||
$code = strtoupper(trim($value));
|
$code = strtoupper(trim($value));
|
||||||
foreach (WS_ATTRIBUTES as $attribute) {
|
return isset(WS_ATTRIBUTE_CODES[$code]) ? $code : '';
|
||||||
if ($attribute[0] === $code) {
|
|
||||||
return $code;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return '';
|
/** Spaltenname (attr_dex …) zu einem Attributkürzel; unbekannt → ''. */
|
||||||
|
function attribute_field_for_code(string $code): string
|
||||||
|
{
|
||||||
|
return WS_ATTRIBUTE_CODES[skill_attribute_code($code)] ?? '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -128,7 +128,7 @@ CREATE TABLE IF NOT EXISTS characters (
|
||||||
CREATE TABLE IF NOT EXISTS skills (
|
CREATE TABLE IF NOT EXISTS skills (
|
||||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
name VARCHAR(80) NOT NULL,
|
name VARCHAR(80) NOT NULL,
|
||||||
attribute ENUM('STR', 'DEX', 'CON', 'INT', 'WIS', 'CHA', '') NOT NULL DEFAULT '',
|
attribute ENUM('STR', 'GES', 'KON', 'INT', 'WEI', 'CHA', '') NOT NULL DEFAULT '',
|
||||||
category VARCHAR(40) NOT NULL DEFAULT 'Allgemein',
|
category VARCHAR(40) NOT NULL DEFAULT 'Allgemein',
|
||||||
description VARCHAR(255) NOT NULL DEFAULT '',
|
description VARCHAR(255) NOT NULL DEFAULT '',
|
||||||
sort_order INT NOT NULL DEFAULT 0,
|
sort_order INT NOT NULL DEFAULT 0,
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@
|
||||||
<span>Attribut</span>
|
<span>Attribut</span>
|
||||||
<select name="attribute">
|
<select name="attribute">
|
||||||
<option value="">–</option>
|
<option value="">–</option>
|
||||||
<?php foreach (['STR', 'DEX', 'CON', 'INT', 'WIS', 'CHA'] as $attribute): ?>
|
<?php foreach (array_keys(WS_ATTRIBUTE_CODES) as $attribute): ?>
|
||||||
<option value="<?= e($attribute) ?>"><?= e($attribute) ?></option>
|
<option value="<?= e($attribute) ?>"><?= e($attribute) ?></option>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</select>
|
</select>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue