LuminaWebsite/gear_action.php
Maaxxs 247dad4cf4 Gear planner: macro entries point to a key of the skill bar, like in the game
Reported in the bug tracker: "Es stehen die einzelnen Skills zur Auswahl. Das ist so falsch. Richtig kann
man lediglich die Schnellzugriffstaste auswählen." In Aion 2 a macro entry chains buttons, not skills: it
points to a slot of the skill bar, and when the macro gets there, the game uses the skills stacked on that
slot (rows 0-3) one after another.

- Skill bar per skill preset (includes/gear_macro.php): the 12 slots of the game with their default keys
  (GEAR_MACRO_KEYS: 1-8, Q, E, left and right mouse button, in three groups of four) and up to
  GEAR_MACRO_KEY_ROWS = 4 active or stigma skills per key in rows 0-3 (row 0 is the one the bar shows).
  Drawn like the skill window: one column per key with rows 3 to 0 and the key below; on narrow screens
  (container query) two lines of six keys.
- A click on a field opens the skill picker below the bar: place, replace (a skill already on the key
  swaps rows), use earlier/later, remove. Skills that are already on a key carry its label. "Leiste von
  Preset N übernehmen" copies the bar of another preset (asks first if the bar is not empty). Without
  JavaScript the field submits cell=Key:Row and the page comes back with the picker open.
- Macro entries are {"k": key, "d": delay}. "Makro hinzufügen" and the icon of an entry open the key
  picker (the 12 keys with their row 0 skill and "+N" for the stacked ones, empty keys disabled). An entry
  shows the key, the row 0 skill and "dann ..." with the other skills of the key; "Als Text kopieren"
  writes each key with all its skills.
- gear_action.php save_macro: entries from key[] and delay[], new ops slot, unslot, slotup, slotdown and
  copybar; skills of other classes drop off the bar with a note.
- Stored in gear_set_plans "macro" as presets + bars. Macros from before (entries with a skill "s") are
  converted when read: each skill goes to the key where it already is in row 0, else to the next free key,
  and is saved that way with the next change.
- Patch notes (with thanks for the report) and README.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-26 22:50:09 +02:00

593 lines
31 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, Skillstufen samt
* Spezialisierungen planen, die Makros und die Seiten Arcana, Pets, Daevanion, Pantheon und Closet speichern,
* Sets per Link/Buildcode teilen und geteilte Sets uebernehmen. 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_once __DIR__ . '/includes/gear_planner_view.php'; // gear_plan_fragments
require_once __DIR__ . '/includes/gear_macro.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]);
};
$setCount = static function () use ($pdo, $userId): int {
$count = $pdo->prepare('SELECT COUNT(*) FROM gear_sets WHERE user_id = ?');
$count->execute([$userId]);
return (int) $count->fetchColumn();
};
switch ($action) {
case 'create':
$name = $cleanName((string) ($_POST['name'] ?? ''));
if ($name === '') {
set_flash('error', 'Bitte gib dem Set einen Namen.');
redirect('/gear.php');
}
if ($setCount() >= 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();
if ($setCount() >= 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']);
}
$newId = gear_set_copy($set, $userId, mb_substr($set['name'] . ' (Kopie)', 0, 80), (int) $set['sort_order'] + 1);
set_flash('success', 'Set kopiert - jetzt kannst du Varianten ausprobieren.');
redirect('/gear.php?set=' . $newId);
case 'share':
// Link und Buildcode erzeugen - mit renew einen neuen, der alte gilt dann nicht mehr. Der Dialog "Teilen" geht
// nach dem Neuladen wieder auf (#teilen) und zeigt beides zum Kopieren.
$set = $ownSet();
if (empty($set['share_code']) || !empty($_POST['renew'])) {
$store = $pdo->prepare('UPDATE gear_sets SET share_code = ? WHERE id = ?');
for ($attempt = 1; ; $attempt++) {
try {
$store->execute([gear_share_code_new(), $set['id']]);
break;
} catch (PDOException $e) {
if ($attempt >= 5) { // derselbe Code wie bei einem anderen Set - neu wuerfeln
throw $e;
}
}
}
}
redirect('/gear.php?set=' . (int) $set['id'] . '#teilen');
case 'unshare':
$set = $ownSet();
$pdo->prepare('UPDATE gear_sets SET share_code = NULL WHERE id = ?')->execute([$set['id']]);
set_flash('success', 'Das Set wird nicht mehr geteilt – Link und Buildcode gelten nicht mehr.');
redirect('/gear.php?set=' . (int) $set['id']);
case 'import':
// Ein geteiltes Set (Buildcode oder Link aus "Build importieren") bzw. ein fremdes, das man gerade ansieht
// (Knopf beim Set: geteilt oder aufs Profil gestellt), als eigenes uebernehmen
if (isset($_POST['code'])) {
$code = gear_share_code_input((string) $_POST['code']);
$source = $code !== null ? gear_set_by_share_code($code) : null;
if (!$source) {
set_flash('error', $code === null
? 'Das ist kein Buildcode – er hat 10 Zeichen wie K7QX2-M9FRT. Du kannst auch den ganzen Link einfügen.'
: 'Diesen Buildcode gibt es nicht (mehr) – vielleicht wird das Set nicht mehr geteilt.');
redirect('/gear.php#import');
}
} else {
$source = gear_set((int) ($_POST['set_id'] ?? 0));
if (!$source || !gear_can_view_set($source)) {
set_flash('error', 'Dieses Set gibt es nicht (mehr).');
redirect('/gear.php');
}
}
if ($setCount() >= GEAR_MAX_SETS) {
set_flash('error', 'Du hast schon ' . GEAR_MAX_SETS . ' Sets - lösche erst ein altes.');
redirect(isset($_POST['code']) ? '/gear.php#import' : '/gear.php?set=' . (int) $source['id']);
}
$isOwnSource = (int) $source['user_id'] === $userId;
$newId = gear_set_copy($source, $userId, mb_substr($source['name'] . ($isOwnSource ? ' (Kopie)' : ' (' . $source['owner_name'] . ')'), 0, 80));
set_flash('success', $isOwnSource
? 'Das war dein eigenes Set – hier ist eine Kopie davon.'
: '„' . $source['name'] . '“ von ' . $source['owner_name'] . ' übernommen – das ist jetzt dein eigenes Set, Änderungen betreffen nur dich.');
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: aktiv/passiv 10, Stigma 20 - darueber gibt es
// nur Boni von den Seiten Daevanion und Arcana), die Knoepfe - und + ohne JavaScript (step[<ID>] = -1/1)
// und Spezialisierungen (spec_sent[<ID>] = 1, spec[<ID>][] = 1-5, nur aktive Skills). Nur Skills der
// Klasse des Sets, hoechstens GEAR_STIGMA_SLOTS Stigmen, hoechstens GEAR_SKILL_POINTS Skillpunkte und
// GEAR_STIGMA_POINTS Stigma-Punkte. 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
. ($skills[$skillId]['kind'] === 'stigma' ? '.' : ' – mehr gibt es nur mit Boni (Daevanion, Arcana).');
continue;
}
$levels[$skillId] = (int) $raw;
}
// - und + ohne JavaScript: eine Stufe runter bzw. rauf
foreach (is_array($_POST['step'] ?? null) ? $_POST['step'] : [] as $skillId => $step) {
$skillId = (int) $skillId;
if ($belongs($skillId) && in_array((string) $step, ['1', '-1'], true)) {
$base = $levels[$skillId] ?? ($current[$skillId]['level'] ?? 0);
$levels[$skillId] = max(0, min(gear_skill_level_max($skills[$skillId]['kind']), $base + (int) $step));
}
}
$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 gesteigerte bleiben, neue nur, solange weniger als GEAR_STIGMA_SLOTS gesteigert sind;
// dazu die Punkte: was das Budget sprengt, faellt zurueck (die zuletzt geaenderten zuerst)
$currentLevels = array_map(static fn (array $row): int => min($row['level'], GEAR_STIGMA_LEVEL_MAX), $current);
$isStigma = static fn (int $id): bool => ($skills[$id]['kind'] ?? '') === 'stigma';
$tally = static function (array $levels) use ($currentLevels, $skills, $isStigma): array {
$all = array_replace($currentLevels, $levels);
$result = ['stigmas' => 0, 'points' => 0, 'stigma_points' => 0];
foreach ($all as $id => $level) {
if ($level <= 0 || !isset($skills[$id])) {
continue; // Skills einer frueheren Klasse zaehlen nicht mit
}
if ($isStigma($id)) {
$result['stigmas']++;
$result['stigma_points'] += gear_stigma_shard_cost($level);
} else {
$result['points'] += gear_skill_point_cost(min($level, GEAR_SKILL_LEVEL_SELF));
}
}
return $result;
};
foreach (array_reverse(array_keys($levels)) as $skillId) {
$counts = $tally($levels);
if ($counts['stigmas'] <= GEAR_STIGMA_SLOTS && $counts['points'] <= GEAR_SKILL_POINTS && $counts['stigma_points'] <= GEAR_STIGMA_POINTS) {
break;
}
$before = $currentLevels[$skillId] ?? 0;
if ($levels[$skillId] <= $before) {
continue; // gesenkte Stufen bleiben immer erlaubt
}
$name = gear_skill_display_name($skills[$skillId]);
if ($isStigma($skillId) && $before === 0 && $counts['stigmas'] > GEAR_STIGMA_SLOTS) {
$errors[] = $name . ': höchstens ' . GEAR_STIGMA_SLOTS . ' Stigmen lassen sich steigern - setz erst ein anderes auf 0.';
} else {
$errors[] = $name . ': dafür reichen die ' . ($isStigma($skillId) ? 'Stigma-Punkte' : 'Skillpunkte') . ' nicht.';
}
$levels[$skillId] = $before;
}
// Spezialisierungen richten sich nach der erreichten Stufe (selbst gesteigert + Boni aus Daevanion und
// Arcana); sinkt sie, fallen zu hohe wieder weg
$bonuses = array_map(static fn (array $bonus): int => (int) array_sum($bonus), gear_plan_skill_bonuses($set, gear_set_plans([(int) $set['id']])[(int) $set['id']] ?? []));
$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) {
$kind = $skills[$skillId]['kind'];
$level = min($levels[$skillId] ?? ($current[$skillId]['level'] ?? 0), gear_skill_level_max($kind));
$effective = gear_skill_effective_level($kind, $level, $bonuses[$skillId] ?? 0);
$wanted = $specs[$skillId] ?? ($current[$skillId]['specs'] ?? 0);
$clean = gear_skill_has_specs($kind) ? gear_skill_specs_clean($wanted, $effective) : 0;
if (isset($specs[$skillId]) && $clean !== $wanted) {
$slots = gear_skill_spec_slots($effective);
$errors[] = gear_skill_display_name($skills[$skillId]) . ': ' . match (true) {
$effective === 0 => 'erst eine Stufe wählen, dann die Spezialisierungen.',
$slots === 0 => 'Spezialisierungen gibt es erst ab Stufe 8.',
default => 'bei Stufe ' . $effective . ' gehen höchstens ' . ['', 'eine', 'zwei', 'drei'][$slots] . ' (I–III ab Stufe 8, IV ab 12, V ab 16 – Stufen über '
. GEAR_SKILL_LEVEL_SELF . ' kommen von Daevanion und Arcana).',
};
}
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, $bonuses);
$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));
} elseif (empty($_POST['step'])) {
set_flash('success', GEAR_SET_TABS[$tab] . ' gespeichert.');
}
redirect($back);
case 'save_plan':
// Eine der Seiten Arcana, Pets, Daevanion, Pantheon, Closet (Formularfelder: includes/gear_planner_view.php,
// Pruefung: gear_plan_input in includes/gear_planner.php). Mit JavaScript kommen der gepruefte Plan und
// die neu berechneten Kaesten zurueck (assets/js/gear-plans.js).
$set = $ownSet();
$section = (string) ($_POST['section'] ?? '');
if (!isset(GEAR_PLAN_SECTIONS[$section])) {
$fail('Unbekannte Seite.', '/gear.php?set=' . (int) $set['id']);
}
$back = '/gear.php?set=' . (int) $set['id'] . '&tab=' . $section
. ($section === 'closet' && is_string($_POST['cat'] ?? null) ? '&cat=' . rawurlencode($_POST['cat']) : '')
. (($_POST['part'] ?? '') === 'skins' ? '#closet-skins' : '');
$class = !empty($set['class_name']) ? (string) $set['class_name'] : null;
if (!gear_plan_ready($section, $class)) {
$fail($section === 'daevanion' && $class === null ? 'Wähle zuerst eine Klasse für das Set.' : 'Die Daten für ' . GEAR_PLAN_SECTIONS[$section] . ' fehlen noch.', $back);
}
[$plan, $notes] = gear_plan_input($section, $_POST, gear_set_plan((int) $set['id'], $section), $set);
gear_set_plan_store($set, $section, $plan);
$touch((int) $set['id']);
if ($wantsJson) {
$json([
'ok' => true,
'state' => $plan,
'count' => gear_plan_tab_count(gear_set_plans([(int) $set['id']])[(int) $set['id']], $section),
'fragments' => gear_plan_fragments($section, $set, $plan),
'errors' => $notes,
]);
}
if ($notes) {
set_flash('error', 'Gespeichert, aber nicht alles übernommen: ' . implode(' ', $notes));
} else {
set_flash('success', GEAR_PLAN_SECTIONS[$section] . ' gespeichert.');
}
redirect($back);
case 'save_macro':
// Ein Preset des Makros (includes/gear_macro.php): die Eintraege, wie sie im Formular stehen (key[] und delay[] -
// so bleiben auch noch nicht gespeicherte Verzoegerungen erhalten), dazu hoechstens eine Aenderung op an Eintraegen
// oder Skill-Leiste (gear_macro_apply). Ohne JavaScript oeffnet cell=Taste:Reihe die Skill-Auswahl fuer ein Feld der
// Leiste. Mit JavaScript kommt das neu gezeichnete Preset zurueck (assets/js/gear-macro.js).
$set = $ownSet();
$preset = (int) ($_POST['preset'] ?? 0);
$back = '/gear.php?set=' . (int) $set['id'] . '&tab=macro&preset=' . $preset . '#makro';
if (!in_array($preset, GEAR_MACRO_PRESETS, true)) {
$fail('Unbekanntes Preset.', '/gear.php?set=' . (int) $set['id'] . '&tab=macro');
}
$skills = gear_macro_skills(!empty($set['class_name']) ? (string) $set['class_name'] : null);
if (!$skills) {
$fail('Für dieses Set gibt es keine Skills - wähle zuerst eine Klasse.', $back);
}
$macro = gear_set_macro((int) $set['id']);
$entries = $macro['presets'][$preset];
if (is_array($_POST['key'] ?? null)) {
$delays = is_array($_POST['delay'] ?? null) ? array_values($_POST['delay']) : [];
$entries = [];
foreach (array_values($_POST['key']) as $i => $key) {
if (($key = gear_macro_key($key)) !== null) {
$entries[] = ['k' => $key, 'd' => gear_macro_delay($delays[$i] ?? GEAR_MACRO_DELAY_DEFAULT)];
}
}
}
$errors = [];
// Erst die Aenderung (die Nummern beziehen sich auf das Formular), dann fallen Skills anderer Klassen von der Leiste
$op = is_string($_POST['op'] ?? null) ? $_POST['op'] : '';
$bar = $macro['bars'][$preset];
if ($op !== '') {
[$entries, $bar, $note] = gear_macro_apply($entries, $bar, $op, $skills, $macro['bars']);
if ($note !== null) {
$errors[] = $note;
}
}
[$bar, $dropped] = gear_macro_bar_keep($bar, $skills);
if ($dropped > 0) {
$errors[] = ($dropped === 1 ? 'Ein Skill der Leiste gehörte' : $dropped . ' Skills der Leiste gehörten') . ' nicht zur Klasse des Sets und '
. ($dropped === 1 ? 'ist' : 'sind') . ' weggefallen.';
}
$macro['presets'][$preset] = array_slice($entries, 0, GEAR_MACRO_MAX_ENTRIES);
$macro['bars'][$preset] = $bar;
gear_set_macro_store((int) $set['id'], $macro);
$touch((int) $set['id']);
if ($wantsJson) {
$levels = gear_macro_levels($set, $skills, gear_set_plans([(int) $set['id']])[(int) $set['id']] ?? []);
$count = gear_macro_count($macro);
$json([
'ok' => true,
'html' => gear_macro_preset_html($set, $preset, $macro, $skills, $levels, true, true),
'entries' => $macro['presets'][$preset],
// Zahl im Reiter (wie in gear.php) und ob das Preset Eintraege hat (Punkt am Preset-Knopf)
'count' => $count > 0 ? (string) $count : '',
'filled' => $macro['presets'][$preset] !== [],
'errors' => $errors,
]);
}
$cell = gear_macro_cell($_POST['cell'] ?? null);
if ($cell !== null) {
// Feld der Leiste angeklickt: zurueck mit der Skill-Auswahl fuer dieses Feld
$back = '/gear.php?set=' . (int) $set['id'] . '&tab=macro&preset=' . $preset . '&cell=' . rawurlencode($cell[0] . ':' . $cell[1]) . '#leiste-' . $preset;
} elseif (preg_match('/^(slot|unslot|slotup|slotdown|copybar):/', $op)) {
$back = '/gear.php?set=' . (int) $set['id'] . '&tab=macro&preset=' . $preset . '#leiste-' . $preset;
}
if ($errors) {
set_flash('error', implode(' ', $errors));
} elseif ($op === '' && $cell === null) {
set_flash('success', 'Makro gespeichert.');
}
redirect($back);
case 'copy_plan':
// Seite aus einem anderen eigenen Set uebernehmen (ersetzt die bisherige), passend gemacht fuer dieses Set
$set = $ownSet();
$section = (string) ($_POST['section'] ?? '');
$from = gear_set((int) ($_POST['from_set'] ?? 0));
if (!isset(GEAR_PLAN_SECTIONS[$section])) {
$fail('Unbekannte Seite.', '/gear.php?set=' . (int) $set['id']);
}
$back = '/gear.php?set=' . (int) $set['id'] . '&tab=' . $section;
if (!$from || (int) $from['user_id'] !== $userId || (int) $from['id'] === (int) $set['id']) {
$fail('Dieses Set gibt es nicht (mehr).', $back);
}
if (!gear_plan_ready($section, !empty($set['class_name']) ? (string) $set['class_name'] : null)) {
$fail('Die Daten für ' . GEAR_PLAN_SECTIONS[$section] . ' fehlen noch.', $back);
}
gear_set_plan_store($set, $section, gear_plan_normalize($section, gear_set_plan((int) $from['id'], $section), $set));
$touch((int) $set['id']);
set_flash('success', GEAR_PLAN_SECTIONS[$section] . ' aus „' . $from['name'] . '“ übernommen.'
. ($from['class_name'] !== $set['class_name'] && in_array($section, ['arcana', 'daevanion'], true) ? ' Was nicht zur Klasse passt, ist weggefallen.' : ''));
redirect($back);
}
set_flash('error', 'Unbekannte Aktion.');
redirect('/gear.php');