LuminaWebsite/includes/gear_skills.php
Maaxxs fab66f64d0 Gear planner: skill planner - skills of the set's class with planned level, stigma limit, point/shard costs, import from aion2hub
- Skills per class come from the aion2hub class pages (Global client core list only, Korea/Taiwan extras left out): 12 normal actives, then Dodge (no levels, dropped), then the stigma skills - matches the Global client's mastery and stigma lists for all 8 classes
- New tables gear_skills and gear_set_skills (schema version 35), skill icons stored under assets/uploads/skills/ (existing files are reused on re-import)
- Admin: "Skills" section on admin/gear_items.php imports/compares all classes (one request per second), marks skills aion2hub no longer lists and can remove them
- Set page: skill grid (active / stigma / passive) with level select and instant save; normal skills 1-10 by skill points, above that only with bonuses (Daevanion up to +4, gear and Arcana up to 20); stigmas up to 20, at most 4 at once (checked on the server too); shows skill point and stigma shard costs
- Planned skills on set cards, the profile page and in the comparison; copies take the skills along, a class change keeps the old levels hidden
- Patch notes entry, README section for the gear planner

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-23 17:17:59 +02:00

378 lines
15 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
declare(strict_types=1);
/**
* Gear-Planer, Skills: Skill-Liste je Klasse (von aion2hub, Global-Client) und die geplante
* Skillstufe je Set.
*
* Die Listen uebernehmen Admins unter /admin/gear_items.php von den Klassenseiten bei aion2hub
* (includes/gear_source.php). Jedes Set plant die Skills seiner Klasse; wechselt die Klasse,
* bleiben die alten Stufen gespeichert (ausgeblendet) und sind beim Zurueckwechseln wieder da.
*
* Drei Arten (kind): normale aktive Skills und passive Skills (Meisterschaft, mit Skillpunkten
* gesteigert) und Stigma-Skills (mit Stigma-Splittern gesteigert, nur wenige gleichzeitig).
*/
const GEAR_SKILL_ICON_DIR = __DIR__ . '/../assets/uploads/skills/';
const GEAR_SKILL_ICON_URL = '/assets/uploads/skills/';
// Stufen (Stand: Global-Client des Launch Scale Tests und offizieller KR-Guide, geprueft 23.09.2026):
// Normale aktive und passive Skills (Meisterschaft) steigert man mit Skillpunkten bis 10, darueber
// nur mit Boni - die Daevanion-Bretter geben hoechstens +4, Ausruestung und Arcana den Rest bis 20.
// Stigma-Skills steigen mit Stigma-Splittern bis 20, hoechstens 4 lassen sich gleichzeitig ausruesten
// (Korea inzwischen 6 Plaetze und Stufe 25 - fuer spaetere Seasons hier anpassen).
const GEAR_SKILL_LEVEL_SELF = 10;
const GEAR_SKILL_DAEVANION_BONUS = 4;
const GEAR_SKILL_LEVEL_MAX = 20;
const GEAR_STIGMA_LEVEL_MAX = 20;
const GEAR_STIGMA_SLOTS = 4;
const GEAR_SKILL_KINDS = ['active' => 'Aktive Skills', 'stigma' => 'Stigma-Skills', 'passive' => 'Passive Skills'];
// Art des Skills auf Deutsch (aion2hub liefert sie englisch), unbekannte bleiben, wie sie sind
const GEAR_SKILL_CATEGORIES = [
'Attack' => 'Angriff', 'Buff' => 'Stärkung', 'Heal' => 'Heilung', 'Debuff' => 'Schwächung',
'Defense' => 'Verteidigung', 'Movement' => 'Bewegung', 'Crowd Control' => 'Kontrolle',
];
function gear_skill_icon_url(?array $skill): ?string
{
return !empty($skill['icon']) ? GEAR_SKILL_ICON_URL . rawurlencode((string) $skill['icon']) : null;
}
function gear_skill_category_label(string $category): string
{
return GEAR_SKILL_CATEGORIES[$category] ?? $category;
}
/** CSS-Klasse fuer die Farbe der Art ("skill-cat-attack"). */
function gear_skill_category_class(string $category): string
{
return 'skill-cat-' . (preg_replace('/[^a-z]+/', '-', strtolower($category)) ?: 'none');
}
/** Hoechste planbare Stufe einer Art. */
function gear_skill_level_max(string $kind): int
{
return $kind === 'stigma' ? GEAR_STIGMA_LEVEL_MAX : GEAR_SKILL_LEVEL_MAX;
}
/** Liegt die Stufe nur mit Boni (Daevanion u. a.) drin? Gilt nicht fuer Stigma-Skills. */
function gear_skill_is_bonus(string $kind, int $level): bool
{
return $kind !== 'stigma' && $level > GEAR_SKILL_LEVEL_SELF;
}
/**
* Auswahl der Stufen einer Art: [Gruppe => [Stufen]] - bei normalen Skills getrennt nach dem, was
* man dafuer braucht (Gruppe '' = ohne Ueberschrift).
*/
function gear_skill_level_groups(string $kind): array
{
if ($kind === 'stigma') {
return ['' => range(1, GEAR_STIGMA_LEVEL_MAX)];
}
$daevanion = GEAR_SKILL_LEVEL_SELF + GEAR_SKILL_DAEVANION_BONUS;
return [
'Skillpunkte' => range(1, GEAR_SKILL_LEVEL_SELF),
'Mit Daevanion (bis +' . GEAR_SKILL_DAEVANION_BONUS . ')' => range(GEAR_SKILL_LEVEL_SELF + 1, $daevanion),
'Mit Ausrüstung & Arcana' => range($daevanion + 1, GEAR_SKILL_LEVEL_MAX),
];
}
/** Skillpunkte bis zu einer Stufe (Stufe 1 gibt es beim Lernen): 2-4 je 1, 5-7 je 2, 8-10 je 4. */
function gear_skill_point_cost(int $level): int
{
$cost = 0;
for ($l = 2; $l <= min($level, GEAR_SKILL_LEVEL_SELF); $l++) {
$cost += $l <= 4 ? 1 : ($l <= 7 ? 2 : 4);
}
return $cost;
}
/** Stigma-Splitter bis zu einer Stufe (Stufe 1 = Lernen): 1-5 je 1, 6-10 je 2, 11-15 je 4, 16-20 je 8. */
function gear_stigma_shard_cost(int $level): int
{
$cost = 0;
for ($l = 1; $l <= $level; $l++) {
$cost += 2 ** intdiv($l - 1, 5);
}
return $cost;
}
/**
* Was die geplanten Stufen kosten: Skillpunkte (nur der Teil bis 10, darueber sind es Boni) und
* Stigma-Splitter.
*
* @return array{points: int, shards: int}
*/
function gear_skill_costs(array $planned): array
{
$costs = ['points' => 0, 'shards' => 0];
foreach ($planned as ['skill' => $skill, 'level' => $level]) {
if ($skill['kind'] === 'stigma') {
$costs['shards'] += gear_stigma_shard_cost($level);
} else {
$costs['points'] += gear_skill_point_cost($level);
}
}
return $costs;
}
/** "142 Skillpunkte · 55 Stigma-Splitter" */
function gear_skill_costs_text(array $planned): string
{
$costs = gear_skill_costs($planned);
return number_format($costs['points'], 0, ',', '.') . ' Skillpunkte · ' . number_format($costs['shards'], 0, ',', '.') . ' Stigma-Splitter';
}
function gear_skill(int $id): ?array
{
$stmt = db()->prepare('SELECT * FROM gear_skills WHERE id = ?');
$stmt->execute([$id]);
return $stmt->fetch() ?: null;
}
/**
* Skills einer Klasse in der Reihenfolge der Klassenseite (aktive, Stigma, passive).
* $listedOnly = false nimmt auch die, die beim letzten Abgleich nicht mehr in der Liste standen.
*
* @return array<int, array> [Skill-ID => Zeile]
*/
function gear_skills_for_class(?string $className, bool $listedOnly = true): array
{
if ($className === null || $className === '') {
return [];
}
$stmt = db()->prepare(
'SELECT * FROM gear_skills WHERE class_name = ?' . ($listedOnly ? ' AND is_listed = 1' : '') . ' ORDER BY kind, sort_order, id'
);
$stmt->execute([$className]);
$skills = [];
foreach ($stmt->fetchAll() as $row) {
$skills[(int) $row['id']] = $row;
}
return $skills;
}
/** Gespeicherte Stufen eines Sets: [Skill-ID => Stufe] (auch die einer frueheren Klasse). */
function gear_set_skill_levels(int $setId): array
{
$stmt = db()->prepare('SELECT skill_id, level FROM gear_set_skills WHERE set_id = ? AND level > 0');
$stmt->execute([$setId]);
return array_map('intval', $stmt->fetchAll(PDO::FETCH_KEY_PAIR));
}
/**
* Geplante Skills mehrerer Sets - nur die der Klasse des Sets und mit Stufe, in der Reihenfolge
* der Klassenseite.
*
* @param array<int, array> $sets Zeilen aus gear_sets (id, class_name)
* @return array<int, array<int, array{skill: array, level: int}>> [Set-ID => [Skill-ID => …]]
*/
function gear_set_skills_for_sets(array $sets): array
{
$classes = [];
foreach ($sets as $set) {
$classes[(int) $set['id']] = (string) ($set['class_name'] ?? '');
}
$result = array_fill_keys(array_keys($classes), []);
if (!$classes) {
return $result;
}
$stmt = db()->prepare(
'SELECT gss.set_id, gss.level, sk.* FROM gear_set_skills gss JOIN gear_skills sk ON sk.id = gss.skill_id
WHERE gss.set_id IN (' . implode(',', array_fill(0, count($classes), '?')) . ') AND gss.level > 0
ORDER BY sk.kind, sk.sort_order, sk.id'
);
$stmt->execute(array_keys($classes));
foreach ($stmt->fetchAll() as $row) {
$setId = (int) $row['set_id'];
if ($row['class_name'] !== $classes[$setId]) {
continue; // von einer frueheren Klasse des Sets
}
$level = (int) $row['level'];
unset($row['set_id'], $row['level']);
$result[$setId][(int) $row['id']] = ['skill' => $row, 'level' => $level];
}
return $result;
}
/** "14 Skills geplant · 4/4 Stigmen · 3 über Stufe 10" */
function gear_skill_summary(array $planned): string
{
if (!$planned) {
return 'Noch keine Skills geplant';
}
$stigma = count(array_filter($planned, static fn (array $p): bool => $p['skill']['kind'] === 'stigma'));
$bonus = count(array_filter($planned, static fn (array $p): bool => gear_skill_is_bonus($p['skill']['kind'], $p['level'])));
return count($planned) . (count($planned) === 1 ? ' Skill' : ' Skills') . ' geplant'
. ($stigma ? ' · ' . $stigma . '/' . GEAR_STIGMA_SLOTS . ' Stigmen' : '')
. ($bonus ? ' · ' . $bonus . ' über Stufe ' . GEAR_SKILL_LEVEL_SELF : '');
}
/**
* Kleine Icon-Reihe der geplanten Skills fuer Set-Karten: die hoechsten Stufen zuerst, mit Stufe.
*
* @param array<int, array{skill: array, level: int}> $planned
*/
function gear_skills_mini_html(array $planned, int $limit = 8): string
{
if (!$planned) {
return '';
}
$sorted = array_values($planned);
usort($sorted, static fn (array $a, array $b): int => $b['level'] <=> $a['level']);
$html = '<span class="gear-skill-mini">';
foreach (array_slice($sorted, 0, $limit) as ['skill' => $skill, 'level' => $level]) {
$url = gear_skill_icon_url($skill);
$html .= '<span class="gear-skill-mini-icon' . (gear_skill_is_bonus($skill['kind'], $level) ? ' is-bonus' : '')
. ($skill['kind'] === 'stigma' ? ' is-stigma' : '') . '" title="'
. e($skill['name'] . ($skill['kind'] === 'stigma' ? ' (Stigma)' : '') . ' – Stufe ' . $level) . '">'
. ($url ? '<img src="' . e($url) . '" alt="" loading="lazy">' : '<span>' . e(mb_substr((string) $skill['name'], 0, 1)) . '</span>')
. '<span class="gear-skill-mini-level">' . $level . '</span></span>';
}
if (count($sorted) > $limit) {
$html .= '<span class="gear-skill-mini-more">+' . (count($sorted) - $limit) . '</span>';
}
return $html . '</span>';
}
// ---- Uebernehmen von aion2hub ----
/** Skill-Icon von aion2hub laden (einmalig). Gibt den Dateinamen zurueck oder null. */
function gear_skill_icon_download(int $id): ?string
{
return gear_image_download(GEAR_SOURCE_SKILL_ICON_URL . $id, GEAR_SKILL_ICON_DIR, (string) $id);
}
/** Schon vorhandene Icon-Datei eines Skills (z.B. nach dem Entfernen und erneuten Uebernehmen). */
function gear_skill_icon_on_disk(int $id): ?string
{
foreach (['webp', 'png', 'jpg', 'gif'] as $extension) {
if (is_file(GEAR_SKILL_ICON_DIR . $id . '.' . $extension)) {
return $id . '.' . $extension;
}
}
return null;
}
/**
* Ausgelesene Skill-Liste einer Klasse speichern (gear_source_parse_class_skills). Skills, die
* nicht mehr in der Liste stehen, bleiben fuer bestehende Plaene erhalten und werden nur markiert.
*
* @return array{total: int, new: string[], changed: string[], same: int, unlisted: string[], missing_icons: int[], source_version: string}
*/
function gear_skills_store(string $className, array $parsed, int $userId): array
{
$pdo = db();
$ids = array_column($parsed['skills'], 'id');
$stmt = $pdo->prepare(
'SELECT * FROM gear_skills WHERE class_name = ?'
. ($ids ? ' OR id IN (' . implode(',', array_fill(0, count($ids), '?')) . ')' : '')
);
$stmt->execute([$className, ...$ids]);
$old = [];
foreach ($stmt->fetchAll() as $row) {
$old[(int) $row['id']] = $row;
}
$result = [
'total' => count($parsed['skills']), 'new' => [], 'changed' => [], 'same' => 0, 'unlisted' => [],
'missing_icons' => [], 'source_version' => $parsed['source_version'],
];
$upsert = $pdo->prepare(
'INSERT INTO gear_skills (id, class_name, name, kind, category, sort_order, source_version, is_listed, checked_at, checked_by)
VALUES (?, ?, ?, ?, ?, ?, ?, 1, NOW(), ?)
ON DUPLICATE KEY UPDATE class_name = VALUES(class_name), name = VALUES(name), kind = VALUES(kind), category = VALUES(category),
sort_order = VALUES(sort_order), source_version = VALUES(source_version), is_listed = 1,
checked_at = NOW(), checked_by = VALUES(checked_by)'
);
$pdo->beginTransaction();
try {
foreach ($parsed['skills'] as $index => $skill) {
$before = $old[$skill['id']] ?? null;
$upsert->execute([
$skill['id'], $className, $skill['name'], $skill['kind'], $skill['category'], $index + 1,
mb_substr($parsed['source_version'], 0, 120), $userId,
]);
if ($before === null) {
$result['new'][] = $skill['name'];
} else {
$changes = [];
if ($before['name'] !== $skill['name']) {
$changes[] = 'Name ' . $before['name'] . ' → ' . $skill['name'];
}
if ($before['kind'] !== $skill['kind']) {
$changes[] = ['active' => 'jetzt aktiv', 'stigma' => 'jetzt Stigma', 'passive' => 'jetzt passiv'][$skill['kind']] ?? $skill['kind'];
}
if ($before['category'] !== $skill['category']) {
$changes[] = 'Art ' . ($before['category'] ?: '–') . ' → ' . ($skill['category'] ?: '–');
}
if ($before['class_name'] !== $className) {
$changes[] = 'Klasse ' . $before['class_name'] . ' → ' . $className;
}
if (!(int) $before['is_listed']) {
$changes[] = 'wieder in der Liste';
}
if ($changes) {
$result['changed'][] = $skill['name'] . ' (' . implode(', ', $changes) . ')';
} else {
$result['same']++;
}
}
if ($before === null || empty($before['icon']) || !is_file(GEAR_SKILL_ICON_DIR . $before['icon'])) {
// Liegt die Datei noch da, reicht es, sie wieder einzutragen - sonst spaeter laden
$onDisk = gear_skill_icon_on_disk($skill['id']);
if ($onDisk !== null) {
$pdo->prepare('UPDATE gear_skills SET icon = ? WHERE id = ?')->execute([$onDisk, $skill['id']]);
} else {
$result['missing_icons'][] = $skill['id'];
}
}
}
$listed = array_flip($ids);
$unlist = $pdo->prepare('UPDATE gear_skills SET is_listed = 0 WHERE id = ?');
foreach ($old as $id => $row) {
if (!isset($listed[$id]) && $row['class_name'] === $className && (int) $row['is_listed']) {
$unlist->execute([$id]);
$result['unlisted'][] = $row['name'];
}
}
$pdo->commit();
} catch (Throwable $e) {
$pdo->rollBack();
throw $e;
}
return $result;
}
/**
* Stand des Skill-Katalogs je Klasse fuer die Verwaltung.
*
* @return array<string, array{active: int, stigma: int, passive: int, unlisted: int, no_icon: int, checked_at: ?string, source_version: string}>
*/
function gear_skill_catalog_status(): array
{
$status = [];
foreach (AION_CLASSES as $class) {
$status[$class] = ['active' => 0, 'stigma' => 0, 'passive' => 0, 'unlisted' => 0, 'no_icon' => 0, 'checked_at' => null, 'source_version' => ''];
}
$rows = db()->query(
"SELECT class_name, SUM(is_listed = 1 AND kind = 'active') AS active, SUM(is_listed = 1 AND kind = 'stigma') AS stigma,
SUM(is_listed = 1 AND kind = 'passive') AS passive, SUM(is_listed = 0) AS unlisted, SUM(icon IS NULL) AS no_icon,
MAX(checked_at) AS checked_at, MAX(source_version) AS source_version
FROM gear_skills GROUP BY class_name"
)->fetchAll();
foreach ($rows as $row) {
if (isset($status[$row['class_name']])) {
$status[$row['class_name']] = [
'active' => (int) $row['active'], 'stigma' => (int) $row['stigma'], 'passive' => (int) $row['passive'],
'unlisted' => (int) $row['unlisted'], 'no_icon' => (int) $row['no_icon'], 'checked_at' => $row['checked_at'],
'source_version' => (string) $row['source_version'],
];
}
}
return $status;
}