LuminaWebsite/gear_action.php
Maaxxs 3cc60c7f7e Skill planner: set pages Ausrüstung / Skills / Stigmen, specializations and stigma bonuses with their effects from the aion2hub build planner
- Each set has three pages (tabs with counters): equipment, skills (active and passive) and stigmas; the skill pages live in includes/gear_skills_view.php
- Specializations of active skills like in the aion2hub planner: collapsible list with unlock level and effect, three from level 8, one from 12, one from 16; one slot at 8, two at 12, three at 20; locked options are disabled, lowering the level drops options that no longer fit (checked on the server too, stored as bitmask gear_set_skills.specs)
- Stigmas: the chosen ones as the 4 slots on top, each stigma lists its four bonuses at 5/10/15/20 with effect, reached ones are highlighted
- Admin: "Spezialisierungen & Stigma-Boni übernehmen" reads the build planner page, finds the JavaScript file with the data set (one request per second, remembers the file) and stores the effects of all classes (gear_skills.spec_effects); new page "Namen & Spezialisierungen" (admin/gear_skills.php) for German skill names and texts
- Autosave sends level and specializations per skill card, the tab counter updates live; compare shows specializations, copies keep them
- Schema version 39 (gear_skills.name_de, spec_effects, spec_names; gear_set_skills.specs), patch notes, README

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

382 lines
19 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 samt
* Spezialisierungen planen. Jedes Mitglied bearbeitet nur seine eigenen Sets.
*/
require_once __DIR__ . '/includes/bootstrap.php';
require_once __DIR__ . '/includes/gear.php';
require_once __DIR__ . '/includes/gear_skills_view.php'; // GEAR_SET_TABS
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, specs) SELECT ?, skill_id, level, specs 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 (level[<Skill-ID>] = 0 bis Hoechststufe der Art, 0 = nicht geplant) und Spezialisierungen
// (spec_sent[<ID>] = 1, spec[<ID>][] = 1-5, nur aktive Skills) - nur Skills der Klasse des Sets,
// hoechstens GEAR_STIGMA_SLOTS Stigma-Skills. Geschickt wird nur, was sich geaendert hat (gear.js)
// bzw. ohne JavaScript das ganze Formular einer Unterseite.
$set = $ownSet();
$tab = ($_POST['tab'] ?? '') === 'stigma' ? 'stigma' : 'skills';
$back = '/gear.php?set=' . (int) $set['id'] . '&tab=' . $tab;
$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_rows((int) $set['id']);
$levels = [];
$specs = [];
$errors = [];
$belongs = static function (int $skillId) use ($skills, $set, &$errors): bool {
if (!isset($skills[$skillId])) {
$errors[] = 'Skill #' . $skillId . ' gehört nicht zu ' . $set['class_name'] . '.';
return false;
}
return true;
};
foreach (is_array($_POST['level'] ?? null) ? $_POST['level'] : [] as $skillId => $raw) {
$skillId = (int) $skillId;
$raw = is_string($raw) ? trim($raw) : '';
if (!$belongs($skillId)) {
continue;
}
$max = gear_skill_level_max($skills[$skillId]['kind']);
if (!ctype_digit($raw) || (int) $raw > $max) {
$errors[] = gear_skill_display_name($skills[$skillId]) . ': Stufe 0 bis ' . $max . '.';
continue;
}
$levels[$skillId] = (int) $raw;
}
$specInput = is_array($_POST['spec'] ?? null) ? $_POST['spec'] : [];
foreach (is_array($_POST['spec_sent'] ?? null) ? $_POST['spec_sent'] : [] as $skillId => $unused) {
$skillId = (int) $skillId;
if (!$belongs($skillId) || !gear_skill_has_specs($skills[$skillId]['kind'])) {
continue;
}
$numbers = is_array($specInput[$skillId] ?? null) ? array_filter($specInput[$skillId], 'is_string') : [];
$specs[$skillId] = gear_skill_spec_mask(array_map('intval', $numbers));
}
// Stigmen: schon geplante bleiben, neue nur, solange Plaetze frei sind (die zuletzt gewaehlten fliegen zuerst)
$currentLevels = array_map(static fn (array $row): int => $row['level'], $current);
$isStigma = static fn (int $id): bool => ($skills[$id]['kind'] ?? '') === 'stigma';
$stigmaCount = static fn (array $levels): int => count(array_filter(
array_replace($currentLevels, $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($currentLevels[$skillId])) {
unset($levels[$skillId]);
$errors[] = gear_skill_display_name($skills[$skillId]) . ': höchstens ' . GEAR_STIGMA_SLOTS . ' Stigma-Skills gleichzeitig - setz erst einen anderen auf „–“.';
}
}
// Jeder betroffene Skill: neue oder bisherige Stufe, dazu nur Spezialisierungen, die bei dieser
// Stufe gehen (sinkt die Stufe, fallen zu hohe weg)
$upsert = $pdo->prepare(
'INSERT INTO gear_set_skills (set_id, skill_id, level, specs) VALUES (?, ?, ?, ?)
ON DUPLICATE KEY UPDATE level = VALUES(level), specs = VALUES(specs)'
);
$remove = $pdo->prepare('DELETE FROM gear_set_skills WHERE set_id = ? AND skill_id = ?');
$pdo->beginTransaction();
foreach (array_unique(array_merge(array_keys($levels), array_keys($specs))) as $skillId) {
$level = $levels[$skillId] ?? ($current[$skillId]['level'] ?? 0);
$wanted = $specs[$skillId] ?? ($current[$skillId]['specs'] ?? 0);
$clean = gear_skill_has_specs($skills[$skillId]['kind']) ? gear_skill_specs_clean($wanted, $level) : 0;
if (isset($specs[$skillId]) && $clean !== $wanted) {
$slots = gear_skill_spec_slots($level);
$errors[] = gear_skill_display_name($skills[$skillId]) . ': ' . match (true) {
$level === 0 => 'erst eine Stufe wählen, dann die Spezialisierungen.',
$slots === 0 => 'Spezialisierungen gibt es erst ab Stufe 8.',
default => 'bei Stufe ' . $level . ' gehen höchstens ' . ['', 'eine', 'zwei', 'drei'][$slots] . ' (I–III ab Stufe 8, IV ab 12, V ab 16).',
};
}
if ($level === 0) {
$remove->execute([$set['id'], $skillId]);
} else {
$upsert->execute([$set['id'], $skillId, $level, $clean]);
}
}
$pdo->commit();
$touch((int) $set['id']);
if ($wantsJson) {
// Gespeicherter Stand, damit die Seite abgelehnte Aenderungen zuruecksetzen kann
$planned = gear_skills_of_tab(gear_set_skills_for_sets([$set])[(int) $set['id']] ?? [], $tab);
[$summary, $costs] = gear_skill_tab_summary($planned, $tab);
$rows = gear_set_skill_rows((int) $set['id']);
$json([
'ok' => true,
'summary' => $summary,
'costs' => $costs,
// Zahl im Reiter der Unterseite (wie in gear.php)
'count' => $tab === 'stigma' ? count($planned) . '/' . GEAR_STIGMA_SLOTS : (string) count($planned),
'levels' => (object) array_map(static fn (array $row): int => $row['level'], $rows),
'specs' => (object) array_map(static fn (array $row): array => gear_skill_spec_numbers($row['specs']), $rows),
'errors' => $errors,
]);
}
if ($errors) {
set_flash('error', 'Gespeichert, aber nicht alles übernommen: ' . implode(' ', $errors));
} else {
set_flash('success', GEAR_SET_TABS[$tab] . ' gespeichert.');
}
redirect($back);
}
set_flash('error', 'Unbekannte Aktion.');
redirect('/gear.php');