LuminaWebsite/gear_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

340 lines
16 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
/**
* Gear-Planer: Sets anlegen, bearbeiten, kopieren, loeschen, Slots belegen und Skillstufen
* planen. Jedes Mitglied bearbeitet nur seine eigenen Sets.
*/
require_once __DIR__ . '/includes/bootstrap.php';
require_once __DIR__ . '/includes/gear.php';
require_permission('gear.view');
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
redirect('/gear.php');
}
verify_csrf();
$me = current_user();
$userId = (int) $me['id'];
$pdo = db();
$action = (string) ($_POST['action'] ?? '');
/** Eigenes Set laden oder mit Meldung zurueck. */
$ownSet = static function () use ($userId): array {
$set = gear_set((int) ($_POST['set_id'] ?? 0));
if (!$set || (int) $set['user_id'] !== $userId) {
set_flash('error', 'Dieses Set gibt es nicht (mehr).');
redirect('/gear.php');
}
return $set;
};
// Automatisches Speichern (Slot, Skills - assets/js/gear.js) schickt X-Requested-With und will JSON
$wantsJson = !empty($_SERVER['HTTP_X_REQUESTED_WITH']);
$json = static function (array $data): void {
header('Content-Type: application/json; charset=UTF-8');
echo json_encode($data, JSON_UNESCAPED_UNICODE);
exit;
};
$fail = static function (string $message, string $to) use ($wantsJson, $json): void {
if ($wantsJson) {
$json(['ok' => false, 'error' => $message]);
}
set_flash('error', $message);
redirect($to);
};
$cleanName = static fn (string $value): string => mb_substr(trim(preg_replace('/\s+/u', ' ', $value) ?? ''), 0, 80);
$cleanClass = static fn (string $value): ?string => in_array($value, AION_CLASSES, true) ? $value : null;
$touch = static function (int $setId) use ($pdo): void {
$pdo->prepare('UPDATE gear_sets SET updated_at = NOW() WHERE id = ?')->execute([$setId]);
};
switch ($action) {
case 'create':
$name = $cleanName((string) ($_POST['name'] ?? ''));
if ($name === '') {
set_flash('error', 'Bitte gib dem Set einen Namen.');
redirect('/gear.php');
}
$count = $pdo->prepare('SELECT COUNT(*) FROM gear_sets WHERE user_id = ?');
$count->execute([$userId]);
if ((int) $count->fetchColumn() >= GEAR_MAX_SETS) {
set_flash('error', 'Du hast schon ' . GEAR_MAX_SETS . ' Sets - lösche erst ein altes.');
redirect('/gear.php');
}
// "– keine Klasse –" (leer) bleibt ohne Klasse, nur wenn das Feld ganz fehlt, gilt die aus dem Profil
$class = isset($_POST['class_name']) ? $cleanClass((string) $_POST['class_name']) : ($me['class_name'] ?: null);
$pdo->prepare(
'INSERT INTO gear_sets (user_id, name, class_name, sort_order, updated_at)
SELECT ?, ?, ?, COALESCE(MAX(sort_order), 0) + 10, NOW() FROM gear_sets WHERE user_id = ?'
)->execute([$userId, $name, $class, $userId]);
redirect('/gear.php?set=' . (int) $pdo->lastInsertId());
case 'update':
$set = $ownSet();
$name = $cleanName((string) ($_POST['name'] ?? ''));
if ($name === '') {
set_flash('error', 'Der Name darf nicht leer sein.');
redirect('/gear.php?set=' . (int) $set['id']);
}
$note = mb_substr(trim((string) ($_POST['note'] ?? '')), 0, 255);
$class = $cleanClass((string) ($_POST['class_name'] ?? ''));
[$buildUrl, $buildError] = gear_build_url_input((string) ($_POST['build_url'] ?? ''));
if ($buildError !== null) {
set_flash('error', $buildError);
redirect('/gear.php?set=' . (int) $set['id']);
}
$pdo->prepare('UPDATE gear_sets SET name = ?, class_name = ?, note = ?, build_url = ?, show_on_profile = ?, updated_at = NOW() WHERE id = ?')
->execute([$name, $class, $note !== '' ? $note : null, $buildUrl, isset($_POST['show_on_profile']) ? 1 : 0, $set['id']]);
set_flash('success', 'Set gespeichert.');
// Neue Klasse: Waffen, die sie nicht tragen kann, bleiben drin (im Raster rot markiert) - nur Bescheid geben
if ($class !== null && $class !== $set['class_name']) {
$setSlots = gear_slots_for_sets([(int) $set['id']])[(int) $set['id']] ?? [];
$wrong = [];
foreach (GEAR_SLOTS as $slotKey => [$slotLabel]) {
$item = $setSlots[$slotKey]['item'] ?? null;
if ($item && !gear_item_fits_class($item, $class)) {
$wrong[] = $slotLabel . ' (' . $item['name'] . ')';
}
}
if ($wrong) {
set_flash('info', 'Passt nicht zu ' . $class . ': ' . implode(', ', $wrong) . ' – neu wählen oder Slot leeren.');
}
}
// Skillstufen gehoeren zur Klasse: die der alten bleiben gespeichert, nur ausgeblendet
if ($class !== $set['class_name'] && !empty($set['class_name'])) {
$oldSkills = gear_set_skills_for_sets([$set])[(int) $set['id']] ?? [];
if ($oldSkills) {
set_flash('info', 'Deine ' . count($oldSkills) . ' geplanten Skills für ' . $set['class_name']
. ' bleiben gespeichert – wechselst du zurück, sind sie wieder da.');
}
}
redirect('/gear.php?set=' . (int) $set['id']);
case 'duplicate':
$set = $ownSet();
$count = $pdo->prepare('SELECT COUNT(*) FROM gear_sets WHERE user_id = ?');
$count->execute([$userId]);
if ((int) $count->fetchColumn() >= GEAR_MAX_SETS) {
set_flash('error', 'Du hast schon ' . GEAR_MAX_SETS . ' Sets - lösche erst ein altes.');
redirect('/gear.php?set=' . (int) $set['id']);
}
$pdo->beginTransaction();
$pdo->prepare(
'INSERT INTO gear_sets (user_id, name, class_name, note, build_url, show_on_profile, sort_order, updated_at)
SELECT user_id, ?, class_name, note, build_url, 0, sort_order + 1, NOW() FROM gear_sets WHERE id = ?'
)->execute([mb_substr($set['name'] . ' (Kopie)', 0, 80), $set['id']]);
$newId = (int) $pdo->lastInsertId();
$pdo->prepare(
'INSERT INTO gear_set_slots (set_id, slot, item_id, enchant, exceed, soul_imprint, manastones, godstone)
SELECT ?, slot, item_id, enchant, exceed, soul_imprint, manastones, godstone FROM gear_set_slots WHERE set_id = ?'
)->execute([$newId, $set['id']]);
$pdo->prepare('INSERT INTO gear_set_skills (set_id, skill_id, level) SELECT ?, skill_id, level FROM gear_set_skills WHERE set_id = ?')
->execute([$newId, $set['id']]);
$pdo->commit();
set_flash('success', 'Set kopiert - jetzt kannst du Varianten ausprobieren.');
redirect('/gear.php?set=' . $newId);
case 'delete':
$set = $ownSet();
$pdo->prepare('DELETE FROM gear_sets WHERE id = ?')->execute([$set['id']]);
set_flash('success', 'Set „' . $set['name'] . '“ gelöscht.');
redirect('/gear.php');
case 'clear_slot':
$set = $ownSet();
$slot = (string) ($_POST['slot'] ?? '');
$pdo->prepare('DELETE FROM gear_set_slots WHERE set_id = ? AND slot = ?')->execute([$set['id'], $slot]);
$touch((int) $set['id']);
redirect('/gear.php?set=' . (int) $set['id']);
case 'save_slot':
$set = $ownSet();
$slot = (string) ($_POST['slot'] ?? '');
$back = '/gear.php?set=' . (int) $set['id'] . '&slot=' . rawurlencode($slot);
if (!isset(GEAR_SLOTS[$slot])) {
$fail('Unbekannter Slot.', '/gear.php?set=' . (int) $set['id']);
}
$item = gear_item((int) ($_POST['item_id'] ?? 0));
if (!$item) {
$fail('Bitte einen Gegenstand aus der Liste wählen.', $back);
}
// Bei einem anderen Gegenstand passen Seelenpraegung und Manasteine nicht mehr - neu anfangen.
// Der schon eingesetzte darf weiter bearbeitet werden, auch wenn er nicht mehr passt (z.B. nach
// einem Klassenwechsel); neu einsetzen laesst sich nur, was in den Slot und zur Klasse passt.
$current = $pdo->prepare('SELECT item_id FROM gear_set_slots WHERE set_id = ? AND slot = ?');
$current->execute([$set['id'], $slot]);
$sameItem = (int) $current->fetchColumn() === (int) $item['id'];
if (!$sameItem && !gear_item_fits_slot($item, $slot)) {
$fail('„' . $item['name'] . '“ passt nicht in den Slot ' . GEAR_SLOTS[$slot][0] . '.', $back);
}
if (!$sameItem && !gear_item_fits_class($item, $set['class_name'])) {
$fail('„' . $item['name'] . '“ ist keine Waffe für ' . $set['class_name'] . '.', $back);
}
$enchant = max(0, min((int) $item['enchant_max'], (int) ($_POST['enchant'] ?? 0)));
$exceed = max(0, min((int) $item['exceed_max'], (int) ($_POST['exceed'] ?? 0)));
$errors = [];
$soul = [];
if ($sameItem) {
$ranges = [];
foreach ($item['soul_imprint'] as $entry) {
$ranges[$entry[0]] = $entry;
}
$stats = (array) ($_POST['soul_stat'] ?? []);
$values = (array) ($_POST['soul_value'] ?? []);
foreach ($stats as $i => $stat) {
$stat = (string) $stat;
$raw = str_replace(',', '.', trim((string) ($values[$i] ?? '')));
if ($stat === '' || $raw === '') {
continue;
}
if (!isset($ranges[$stat])) {
$errors[] = 'Seelenprägung „' . $stat . '“ gibt es bei diesem Gegenstand nicht.';
continue;
}
if (isset(array_column($soul, 1, 0)[$stat])) {
$errors[] = 'Seelenprägung „' . $stat . '“ ist doppelt eingetragen.';
continue;
}
$value = (float) $raw;
[, $min, $max, $unit] = $ranges[$stat];
if (!is_numeric($raw) || $value < $min || $value > $max) {
$errors[] = $stat . ': ' . gear_format_value($value, $unit) . ' liegt nicht in der möglichen Spanne '
. gear_format_value((float) $min, $unit) . '–' . gear_format_value((float) $max, $unit) . '.';
continue;
}
$soul[] = [$stat, $value];
}
if (count($soul) > (int) $item['soul_imprint_count']) {
$errors[] = 'Höchstens ' . (int) $item['soul_imprint_count'] . ' Seelenprägungen.';
$soul = array_slice($soul, 0, (int) $item['soul_imprint_count']);
}
}
$manastones = [];
if ($sameItem) {
$allowed = array_flip(gear_manastone_stats());
$stats = (array) ($_POST['mana_stat'] ?? []);
$values = (array) ($_POST['mana_value'] ?? []);
foreach ($stats as $i => $stat) {
$stat = (string) $stat;
$raw = trim((string) ($values[$i] ?? ''));
if ($stat === '' || $raw === '') {
continue;
}
if (!isset($allowed[$stat]) || !ctype_digit($raw) || (int) $raw < 1 || (int) $raw > 9999) {
$errors[] = 'Manastein ' . ($i + 1) . ': bitte einen Wert aus der Liste und eine ganze Zahl eintragen.';
continue;
}
$manastones[] = [$stat, (int) $raw];
}
$manastones = array_slice($manastones, 0, (int) $item['manastone_slots']);
}
$godstone = (int) $item['godstone_slots'] > 0 ? mb_substr(trim((string) ($_POST['godstone'] ?? '')), 0, 100) : '';
$pdo->prepare(
'INSERT INTO gear_set_slots (set_id, slot, item_id, enchant, exceed, soul_imprint, manastones, godstone)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
ON DUPLICATE KEY UPDATE item_id = VALUES(item_id), enchant = VALUES(enchant), exceed = VALUES(exceed),
soul_imprint = VALUES(soul_imprint), manastones = VALUES(manastones), godstone = VALUES(godstone)'
)->execute([
$set['id'], $slot, $item['id'], $enchant, $exceed,
json_encode($soul, JSON_UNESCAPED_UNICODE), json_encode($manastones, JSON_UNESCAPED_UNICODE), $godstone !== '' ? $godstone : null,
]);
$touch((int) $set['id']);
if ($wantsJson) {
// Neuer Gegenstand: die Seite laedt neu (andere Felder fuer Seelenpraegung und Manasteine)
$json(['ok' => true, 'reload' => !$sameItem, 'errors' => $errors]);
}
if ($errors) {
set_flash('error', 'Gespeichert, aber nicht alles übernommen: ' . implode(' ', $errors));
redirect($back);
}
if (!$sameItem && ((int) $item['soul_imprint_count'] > 0 || (int) $item['manastone_slots'] > 0)) {
set_flash('success', '„' . $item['name'] . '“ eingesetzt - trag jetzt Seelenprägung und Manasteine ein.');
redirect($back);
}
set_flash('success', GEAR_SLOTS[$slot][0] . ' gespeichert.');
redirect('/gear.php?set=' . (int) $set['id']);
case 'save_skills':
// Stufen der Skills (level[<Skill-ID>] = 0 bis Hoechststufe der Art, 0 = nicht geplant) - nur
// Skills der Klasse des Sets, dazu hoechstens GEAR_STIGMA_SLOTS Stigma-Skills
$set = $ownSet();
$back = '/gear.php?set=' . (int) $set['id'] . '#skills';
$skills = gear_skills_for_class($set['class_name'], false);
if (!$skills) {
$fail('Für dieses Set gibt es keine Skills - wähle zuerst eine Klasse.', $back);
}
$current = gear_set_skill_levels((int) $set['id']);
$levels = [];
$errors = [];
foreach (is_array($_POST['level'] ?? null) ? $_POST['level'] : [] as $skillId => $raw) {
$skillId = (int) $skillId;
$raw = is_string($raw) ? trim($raw) : '';
if (!isset($skills[$skillId])) {
$errors[] = 'Skill #' . $skillId . ' gehört nicht zu ' . $set['class_name'] . '.';
continue;
}
$max = gear_skill_level_max($skills[$skillId]['kind']);
if (!ctype_digit($raw) || (int) $raw > $max) {
$errors[] = $skills[$skillId]['name'] . ': Stufe 0 bis ' . $max . '.';
continue;
}
$levels[$skillId] = (int) $raw;
}
// Stigmen: schon geplante bleiben, neue nur, solange Plaetze frei sind (die zuletzt gewaehlten fliegen zuerst)
$isStigma = static fn (int $id): bool => ($skills[$id]['kind'] ?? '') === 'stigma';
$stigmaCount = static fn (array $levels): int => count(array_filter(
array_replace($current, $levels),
static fn (int $level, int $id): bool => $level > 0 && $isStigma($id),
ARRAY_FILTER_USE_BOTH
));
foreach (array_reverse(array_keys($levels)) as $skillId) {
if ($stigmaCount($levels) <= GEAR_STIGMA_SLOTS) {
break;
}
if ($isStigma($skillId) && $levels[$skillId] > 0 && empty($current[$skillId])) {
unset($levels[$skillId]);
$errors[] = $skills[$skillId]['name'] . ': höchstens ' . GEAR_STIGMA_SLOTS . ' Stigma-Skills gleichzeitig - setz erst einen anderen auf „–“.';
}
}
$upsert = $pdo->prepare('INSERT INTO gear_set_skills (set_id, skill_id, level) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE level = VALUES(level)');
$remove = $pdo->prepare('DELETE FROM gear_set_skills WHERE set_id = ? AND skill_id = ?');
$pdo->beginTransaction();
foreach ($levels as $skillId => $level) {
if ($level === 0) {
$remove->execute([$set['id'], $skillId]);
} else {
$upsert->execute([$set['id'], $skillId, $level]);
}
}
$pdo->commit();
$touch((int) $set['id']);
if ($wantsJson) {
// Gespeicherter Stand, damit die Seite abgelehnte Aenderungen zuruecksetzen kann
$planned = gear_set_skills_for_sets([$set])[(int) $set['id']] ?? [];
$json([
'ok' => true,
'summary' => gear_skill_summary($planned),
'costs' => gear_skill_costs_text($planned),
'levels' => (object) gear_set_skill_levels((int) $set['id']),
'errors' => $errors,
]);
}
if ($errors) {
set_flash('error', 'Gespeichert, aber nicht alles übernommen: ' . implode(' ', $errors));
} else {
set_flash('success', 'Skills gespeichert.');
}
redirect($back);
}
set_flash('error', 'Unbekannte Aktion.');
redirect('/gear.php');