LuminaWebsite/admin/gear_items_action.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

188 lines
9.2 KiB
PHP

<?php
/**
* Gear-Planer, Katalog: Gegenstaende und die Skill-Listen der Klassen von aion2hub uebernehmen
* und abgleichen. Antwortet als JSON (Aufrufe aus assets/js/gear-admin.js), nur "delete" und
* "skills_prune" leiten zurueck.
*/
require_once __DIR__ . '/../includes/bootstrap.php';
require_once __DIR__ . '/../includes/gear.php';
require_permission('gear.manage');
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
redirect('/admin/gear_items.php');
}
verify_csrf();
$userId = (int) current_user()['id'];
$action = (string) ($_POST['action'] ?? '');
/** JSON-Antwort und Ende. */
$respond = static function (array $data, int $status = 200): void {
http_response_code($status);
header('Content-Type: application/json; charset=UTF-8');
echo json_encode($data, JSON_UNESCAPED_UNICODE);
exit;
};
/**
* Hoechstens ein Abruf pro Sekunde (pro Sitzung) - aion2hub soll von uns nicht mehr merken als
* von jemandem, der sich durch die Seiten klickt.
*/
$politePause = static function (): void {
$last = (float) ($_SESSION['gear_source_last_fetch'] ?? 0);
$wait = 1.0 - (microtime(true) - $last);
if ($wait > 0) {
usleep((int) ($wait * 1000000));
}
$_SESSION['gear_source_last_fetch'] = microtime(true);
};
try {
switch ($action) {
case 'plan':
// Was steckt hinter der Eingabe? Ein einzelner Gegenstand oder Listen je Kategorie.
$input = trim((string) ($_POST['url'] ?? ''));
$single = gear_source_parse_id($input);
if ($single !== null) {
$respond(['ok' => true, 'ids' => [$single], 'known' => gear_item($single) ? [$single] : []]);
}
$respond(['ok' => true, 'lists' => gear_source_list_urls($input)]);
case 'list':
// Eine Seite einer Liste (Adresse aus "plan") -> enthaltene IDs und Seitenzahl
$url = trim((string) ($_POST['url'] ?? ''));
$page = max(1, (int) ($_POST['page'] ?? 1));
if (!in_array($url, gear_source_list_urls($url), true)) {
$respond(['ok' => false, 'error' => 'Ungültige Listen-Adresse.'], 400);
}
$politePause();
$result = gear_source_list_page(gear_source_fetch($url . '&page=' . $page));
$known = $result['ids']
? db()->query('SELECT id FROM gear_items WHERE id IN (' . implode(',', $result['ids']) . ')')->fetchAll(PDO::FETCH_COLUMN)
: [];
$respond(['ok' => true, 'known' => array_map('intval', $known)] + $result);
case 'import':
case 'check':
$id = (int) ($_POST['id'] ?? 0);
if ($id <= 0) {
$respond(['ok' => false, 'error' => 'Ungültige ID.'], 400);
}
$politePause();
$parsed = gear_item_fetch($id);
$old = gear_item($id);
$diffs = gear_item_diff($old, $parsed);
// Abgleich ohne Uebernehmen: nur zeigen, was anders waere
$apply = $action === 'import' || !empty($_POST['apply']);
if ($apply) {
$result = gear_item_store($parsed, $userId);
} elseif ($old !== null) {
// Trotzdem als "geprueft" vermerken, wenn sich nichts geaendert hat
if (!$diffs) {
db()->prepare('UPDATE gear_items SET checked_at = NOW(), checked_by = ?, source_version = ? WHERE id = ?')
->execute([$userId, mb_substr($parsed['source_version'], 0, 120), $id]);
}
}
if (empty($_POST['batch']) && $apply) {
admin_log($old === null ? '🗡️ Gear-Planer: Gegenstand übernommen' : '🗡️ Gear-Planer: Gegenstand abgeglichen', [
'Gegenstand' => $parsed['name'] . ' (#' . $id . ')',
'Änderungen' => $old === null ? 'neu' : ($diffs ? implode(', ', array_column($diffs, 0)) : 'keine'),
], 'info', 'gear');
}
$respond([
'ok' => true,
'id' => $id,
'name' => $parsed['name'],
'new' => $old === null,
'applied' => $apply,
'diffs' => $old === null ? [] : $diffs,
]);
case 'batch_done':
// Eine Zusammenfassung pro Durchlauf statt eines Eintrags je Gegenstand
$summary = array_filter([
'Art' => (string) ($_POST['kind'] ?? '') === 'check' ? 'Abgleich' : 'Übernahme',
'Neu' => (int) ($_POST['new'] ?? 0) ?: null,
'Geändert' => (int) ($_POST['changed'] ?? 0) ?: null,
'Unverändert' => (int) ($_POST['same'] ?? 0) ?: null,
'Fehler' => (int) ($_POST['failed'] ?? 0) ?: null,
'Quelle' => mb_substr((string) ($_POST['source'] ?? ''), 0, 200) ?: null,
], static fn ($value): bool => $value !== null);
admin_log('🗡️ Gear-Planer: Gegenstände von aion2hub', $summary, 'info', 'gear');
$respond(['ok' => true]);
case 'skills_class':
// Skill-Liste einer Klasse von ihrer Klassenseite uebernehmen bzw. abgleichen
$className = (string) ($_POST['class_name'] ?? '');
if (!isset(GEAR_SOURCE_CLASSES[$className])) {
$respond(['ok' => false, 'error' => 'Unbekannte Klasse.'], 400);
}
[$slug, $sourceClass] = GEAR_SOURCE_CLASSES[$className];
$politePause();
$parsed = gear_source_parse_class_skills(gear_source_fetch(GEAR_SOURCE_CLASS_URL . $slug), $sourceClass);
$respond(['ok' => true, 'class_name' => $className] + gear_skills_store($className, $parsed, $userId));
case 'skill_icon':
$skill = gear_skill((int) ($_POST['id'] ?? 0));
if (!$skill) {
$respond(['ok' => false, 'error' => 'Diesen Skill gibt es nicht (mehr).'], 404);
}
if (!empty($skill['icon']) && is_file(GEAR_SKILL_ICON_DIR . $skill['icon'])) {
$respond(['ok' => true, 'icon' => $skill['icon']]);
}
$politePause();
$icon = gear_skill_icon_download((int) $skill['id']);
if ($icon === null) {
$respond(['ok' => false, 'error' => 'Icon für „' . $skill['name'] . '“ ließ sich nicht laden (bei aion2hub fehlt es evtl. noch) - der nächste Abgleich versucht es erneut.'], 422);
}
db()->prepare('UPDATE gear_skills SET icon = ? WHERE id = ?')->execute([$icon, $skill['id']]);
$respond(['ok' => true, 'icon' => $icon]);
case 'skills_done':
// Eine Zusammenfassung pro Durchlauf
$summary = array_filter([
'Klassen' => mb_substr((string) ($_POST['classes'] ?? ''), 0, 200) ?: null,
'Skills' => (int) ($_POST['total'] ?? 0) ?: null,
'Neu' => (int) ($_POST['new'] ?? 0) ?: null,
'Geändert' => (int) ($_POST['changed'] ?? 0) ?: null,
'Nicht mehr gelistet' => (int) ($_POST['unlisted'] ?? 0) ?: null,
'Icons geladen' => (int) ($_POST['icons'] ?? 0) ?: null,
'Fehler' => (int) ($_POST['failed'] ?? 0) ?: null,
], static fn ($value): bool => $value !== null);
admin_log('🗡️ Gear-Planer: Skills von aion2hub', $summary, 'info', 'gear');
$respond(['ok' => true]);
case 'skills_prune':
// Skills, die aion2hub nicht mehr listet, samt ihrer geplanten Stufen entfernen
$gone = db()->query('SELECT id, name, class_name, icon FROM gear_skills WHERE is_listed = 0')->fetchAll();
if ($gone) {
db()->exec('DELETE FROM gear_skills WHERE is_listed = 0');
foreach ($gone as $skill) {
if (!empty($skill['icon']) && strpos((string) $skill['icon'], '/') === false) {
@unlink(GEAR_SKILL_ICON_DIR . $skill['icon']);
}
}
admin_log('🗡️ Gear-Planer: alte Skills entfernt', [
'Skills' => implode(', ', array_map(static fn (array $s): string => $s['name'] . ' (' . $s['class_name'] . ')', $gone)),
], 'danger', 'gear');
set_flash('success', count($gone) . (count($gone) === 1 ? ' alter Skill entfernt.' : ' alte Skills entfernt.'));
}
redirect('/admin/gear_items.php#skills');
case 'delete':
$item = gear_item((int) ($_POST['id'] ?? 0));
if ($item) {
db()->prepare('DELETE FROM gear_items WHERE id = ?')->execute([$item['id']]);
if (!empty($item['icon']) && strpos((string) $item['icon'], '/') === false) {
@unlink(GEAR_ICON_DIR . $item['icon']);
}
admin_log('🗡️ Gear-Planer: Gegenstand gelöscht', ['Gegenstand' => $item['name'] . ' (#' . $item['id'] . ')'], 'danger', 'gear');
set_flash('success', '„' . $item['name'] . '“ gelöscht - in Sets ist der Slot jetzt leer.');
}
redirect('/admin/gear_items.php');
}
} catch (RuntimeException $e) {
$respond(['ok' => false, 'error' => $e->getMessage()], 422);
}
$respond(['ok' => false, 'error' => 'Unbekannte Aktion.'], 400);