'Leicht', 'mittel' => 'Mittel', 'schwer' => 'Schwer']; const GEAR_GUIDE_TAGS_MAX = 4; const GEAR_GUIDE_TAG_LENGTH = 30; const GEAR_GUIDE_POINTS_MAX = 6; // Staerken bzw. Schwaechen const GEAR_GUIDE_POINT_LENGTH = 240; const GEAR_GUIDE_TIPS_MAX = 5; const GEAR_GUIDE_TIP_TITLE_LENGTH = 160; const GEAR_GUIDE_TIP_TEXT_LENGTH = 1200; const GEAR_GUIDE_ORDER_MAX = 99; // Reihenfolge beim Steigern je Skill (0 = keine) const GEAR_GUIDE_PRIO_MAX = 20; // Prioritaet je Stigma bzw. passivem Skill (0 = keine) const GEAR_GUIDE_PRIO_KINDS = ['stigma' => 'Stigma', 'passive' => 'Passiv']; // Skill-Arten mit eigener Prioritaet const GEAR_GUIDE_STYLES_MAX = 4; // Spielweisen (z.B. Tank, DPS) mit eigener Prioritaet der Stigmen und Passiven const GEAR_GUIDE_STYLE_LENGTH = 16; const GEAR_GUIDE_WHY_LENGTH = 1200; // Begruendung je Skill const GEAR_GUIDE_KEY_LENGTH = 600; // Erklaerung je Taste der Skill-Leiste const GEAR_GUIDE_DAEVANION_LENGTH = 1200; // Erklaerung zu den Daevanion-Brettern // Stats-Prioritaet: Gruppen (Slot-Gruppen aus GEAR_SLOTS plus allgemein und Manasteine) => [Name, Slot fuer das Symbol] const GEAR_GUIDE_STAT_GROUPS = [ 'all' => ['Allgemein', null], 'weapon' => ['Waffen', 'main_hand'], 'armor' => ['Rüstung', 'torso'], 'jewelry' => ['Schmuck', 'necklace'], 'manastone' => ['Manasteine', null], ]; // Slot-Gruppe in GEAR_SLOTS => Gruppe der Stats-Prioritaet const GEAR_GUIDE_SLOT_GROUPS = ['Waffen' => 'weapon', 'Rüstung' => 'armor', 'Schmuck' => 'jewelry']; const GEAR_GUIDE_STATS_MAX = 6; // Werte je Gruppe const GEAR_GUIDE_STAT_LENGTH = 40; // Gegenstaende in Guide-Texten: [[Item:Name]] bzw. [[Item:ID]] (Name/ID wie bei aion2hub), auch mit "Flügel:" - // beim Speichern nachgeschlagen (hoechstens so viele neue je Speichern, aion2hub hat ein Tempolimit) const GEAR_GUIDE_ITEM_PREFIXES = ['item', 'gegenstand', 'flügel', 'fluegel', 'wings', 'wing']; const GEAR_GUIDE_ITEM_LOOKUPS = 8; // Deutsche Namen von aion2.app (dieselbe Quelle wie die deutschen Skill-Beschreibungen): Suche und Gegenstandsseite const GEAR_GUIDE_ITEM_DE_URL = 'https://' . GEAR_SOURCE_INFO_HOST . '/de/db/items'; const GEAR_GUIDE_ITEM_DE_LIMIT = 20; // Abrufe pro Minute fuer die ganze Website const GEAR_GUIDE_STAT_NOTE_LENGTH = 160; /** Einzeiliger Text: Leerraum zusammengefasst und gekuerzt. */ function gear_guide_line(mixed $value, int $max): string { return mb_substr(trim((string) preg_replace('/\s+/u', ' ', is_string($value) ? $value : '')), 0, $max); } /** * Guide aus Formular oder Datenbank bereinigen. * * @return array{difficulty: string, tags: string[], strengths: string[], weaknesses: string[], tips: array, * skills: array, level: int, why: string}>, styles: array, preset: int, keys: array} */ function gear_guide_normalize(array $raw): array { $list = static function (mixed $value, int $count, int $length): array { $items = is_array($value) ? $value : preg_split('/\R/u', (string) $value); $items = array_values(array_filter(array_map(static fn ($item): string => gear_guide_line($item, $length), $items ?: []), 'strlen')); return array_slice(array_values(array_unique($items)), 0, $count); }; $tags = $raw['tags'] ?? []; $tips = []; foreach (is_array($raw['tips'] ?? null) ? $raw['tips'] : [] as $tip) { if (!is_array($tip)) { continue; } $title = gear_guide_line($tip['title'] ?? '', GEAR_GUIDE_TIP_TITLE_LENGTH); $text = gear_guide_text($tip['text'] ?? '', GEAR_GUIDE_TIP_TEXT_LENGTH); if ($title !== '' || $text !== '') { $tips[] = ['title' => $title, 'text' => $text]; } } // Spielweisen (z.B. Tank, DPS): feste Plaetze 1-4, damit die Zuordnung der Skills beim Umbenennen bzw. Leeren bleibt $styles = []; foreach (is_array($raw['styles'] ?? null) ? $raw['styles'] : [] as $styleId => $name) { $name = gear_guide_line($name, GEAR_GUIDE_STYLE_LENGTH); if (ctype_digit((string) $styleId) && (int) $styleId >= 1 && (int) $styleId <= GEAR_GUIDE_STYLES_MAX && $name !== '') { $styles[(int) $styleId] = $name; } } ksort($styles); // Je Skill: Reihenfolge beim Steigern und Begruendung - leere fallen weg $skills = []; foreach (is_array($raw['skills'] ?? null) ? $raw['skills'] : [] as $skillId => $note) { if (!is_array($note) || !ctype_digit((string) $skillId) || (int) $skillId <= 0) { continue; } $order = is_numeric($note['order'] ?? null) ? max(0, min(GEAR_GUIDE_ORDER_MAX, (int) $note['order'])) : 0; // Prioritaet unter den Stigmen bzw. passiven Skills (welche am wichtigsten sind) $prio = is_numeric($note['prio'] ?? null) ? max(0, min(GEAR_GUIDE_PRIO_MAX, (int) $note['prio'])) : 0; // ... und je Spielweise: [Spielweise => Prioritaet, -1 = dort ausgeblendet], nur fuer vorhandene Spielweisen; // ohne Eintrag gilt in der Spielweise die allgemeine Prioritaet $stylePrio = []; $hidden = is_array($note['hide'] ?? null) ? $note['hide'] : []; foreach (is_array($note['styles'] ?? null) ? $note['styles'] : [] as $styleId => $value) { if (isset($styles[(int) $styleId]) && is_numeric($value) && ((int) $value > 0 || (int) $value === -1)) { $stylePrio[(int) $styleId] = min(GEAR_GUIDE_PRIO_MAX, (int) $value); } } foreach ($hidden as $styleId => $on) { if (isset($styles[(int) $styleId]) && $on) { $stylePrio[(int) $styleId] = -1; } } ksort($stylePrio); // Ziel-Stufe eines alternativen Stigmas (im Skill-Plan nicht gesteigert, nur fuer Spielweisen) - 0 = keine $altLevel = is_numeric($note['level'] ?? null) ? max(0, min(GEAR_STIGMA_LEVEL_MAX, (int) $note['level'])) : 0; $why = gear_guide_text($note['why'] ?? '', GEAR_GUIDE_WHY_LENGTH); // Reihenfolge der Spezialisierungen: [Nr => Prioritaet] $specOrder = []; foreach (is_array($note['specs'] ?? null) ? $note['specs'] : [] as $no => $priority) { if (isset(GEAR_SKILL_SPECS[(int) $no]) && is_numeric($priority) && (int) $priority > 0) { $specOrder[(int) $no] = min(9, (int) $priority); } } ksort($specOrder); if ($order > 0 || $prio > 0 || $stylePrio || $altLevel > 0 || $why !== '' || $specOrder) { $skills[(int) $skillId] = ['order' => $order, 'prio' => $prio, 'styles' => $stylePrio, 'level' => $altLevel, 'why' => $why, 'specs' => $specOrder]; } } // Je Taste der Skill-Leiste: Erklaerung $keys = []; foreach (is_array($raw['keys'] ?? null) ? $raw['keys'] : [] as $key => $text) { $key = gear_macro_key($key); $text = gear_guide_text($text, GEAR_GUIDE_KEY_LENGTH); if ($key !== null && $text !== '') { $keys[$key] = $text; } } // Stats-Prioritaet je Gruppe: [['stat' => Wert, 'note' => Hinweis], …] in Reihenfolge $stats = []; foreach (GEAR_GUIDE_STAT_GROUPS as $group => $unused) { $entries = []; foreach (is_array($raw['stats'][$group] ?? null) ? $raw['stats'][$group] : [] as $entry) { $stat = gear_guide_line(is_array($entry) ? ($entry['stat'] ?? '') : '', GEAR_GUIDE_STAT_LENGTH); if ($stat !== '') { $entries[] = ['stat' => $stat, 'note' => gear_guide_line($entry['note'] ?? '', GEAR_GUIDE_STAT_NOTE_LENGTH)]; } } if ($entries) { $stats[$group] = array_slice($entries, 0, GEAR_GUIDE_STATS_MAX); } } return [ 'difficulty' => isset(GEAR_GUIDE_DIFFICULTIES[$raw['difficulty'] ?? '']) ? (string) $raw['difficulty'] : '', 'tags' => $list(is_array($tags) ? $tags : explode(',', (string) $tags), GEAR_GUIDE_TAGS_MAX, GEAR_GUIDE_TAG_LENGTH), 'strengths' => $list($raw['strengths'] ?? [], GEAR_GUIDE_POINTS_MAX, GEAR_GUIDE_POINT_LENGTH), 'weaknesses' => $list($raw['weaknesses'] ?? [], GEAR_GUIDE_POINTS_MAX, GEAR_GUIDE_POINT_LENGTH), 'tips' => array_slice($tips, 0, GEAR_GUIDE_TIPS_MAX), 'skills' => $skills, 'styles' => $styles, 'preset' => in_array((int) ($raw['preset'] ?? 1), GEAR_MACRO_PRESETS, true) ? (int) ($raw['preset'] ?? 1) : 1, 'keys' => $keys, 'daevanion' => gear_guide_text($raw['daevanion'] ?? '', GEAR_GUIDE_DAEVANION_LENGTH), 'stats' => $stats, ]; } /** * Werte, die bei Gegenstaenden einer Gruppe als Seelenpraegung vorkommen (Vorschlaege im Dialog "Stats-Prioritaet"), * Manasteine wie im Slot-Editor, "Allgemein" alle zusammen. * * @return array [Gruppe => Wertnamen] */ function gear_guide_stat_options(): array { $groups = array_fill_keys(array_keys(GEAR_GUIDE_STAT_GROUPS), []); // gear_items.slot ist der Slot aus dem Spiel ("Torso", "Necklace" …) - dritter Eintrag in GEAR_SLOTS $slotGroups = []; foreach (GEAR_SLOTS as $slotKey => [, $slotGroup, $gameSlots]) { foreach (array_merge([$slotKey], $gameSlots) as $name) { $slotGroups[$name] = GEAR_GUIDE_SLOT_GROUPS[$slotGroup] ?? null; } } foreach (db()->query('SELECT slot, data FROM gear_items')->fetchAll() as $row) { $group = $slotGroups[$row['slot']] ?? null; if ($group === null) { continue; } foreach ((json_decode((string) $row['data'], true)['soul_imprint'] ?? []) as $entry) { $name = (string) ($entry[0] ?? ''); if ($name !== '' && !str_contains($name, '[')) { $groups[$group][$name] = true; $groups['all'][$name] = true; } } } $groups['manastone'] = array_fill_keys(gear_manastone_stats(), true); $sort = static function (string $a, string $b): int { $ia = array_search($a, GEAR_STAT_ORDER, true); $ib = array_search($b, GEAR_STAT_ORDER, true); return [$ia === false ? 99 : $ia, $a] <=> [$ib === false ? 99 : $ib, $b]; }; return array_map(static function (array $names) use ($sort): array { $names = array_map('strval', array_keys($names)); usort($names, $sort); return $names; }, $groups); } /** Slots einer Gruppe der Stats-Prioritaet als Text: "Kopf, Schultern, Brust, …" (Ring 1/2 nur einmal) */ function gear_guide_stat_group_slots(string $group): string { $names = []; foreach (GEAR_SLOTS as [$label, $slotGroup]) { if ((GEAR_GUIDE_SLOT_GROUPS[$slotGroup] ?? '') === $group) { $names[(string) preg_replace('/ \d$/', '', $label)] = true; } } return implode(', ', array_keys($names)); } /** * Skills einer Klasse fuer die Skill-Chips: [kleingeschriebener Name (deutsch und englisch) => Skill]. * * @return array */ function gear_guide_chip_skills(?string $className): array { static $cache = []; $className = (string) $className; if (!isset($cache[$className])) { $cache[$className] = []; foreach ($className !== '' ? gear_skills_for_class($className, false) : [] as $skill) { foreach ([(string) $skill['name'], (string) ($skill['name_de'] ?? '')] as $name) { if ($name !== '') { $cache[$className][mb_strtolower($name, 'UTF-8')] ??= $skill; } } } } return $cache[$className]; } /** * Info-Blase eines Skills (wie im Skills-Reiter, assets/js/gear.js): gibt die Attribute fuer das Element zurueck und * merkt sich den Skill - die Beschreibung steht einmal je Skill versteckt am Ende des Reiters (gear_guide_tip_sources), * so passt sie auch in Absaetze (

darf keine

enthalten). Leer, wenn der Skill keine Beschreibung hat. */ function gear_guide_tip_attrs(array $skill): string { if (gear_skill_info($skill) === null) { return ''; } gear_guide_tip_registry($skill); return ' data-skill data-skill-tip data-tip-ref="gear-guide-tip-' . (int) $skill['id'] . '"'; } /** Gemerkte Skills fuer die Info-Blasen (mit $skill: merken, ohne: alle zurueckgeben und vergessen). */ function gear_guide_tip_registry(?array $skill = null): array { static $skills = []; if ($skill !== null) { $skills[(int) $skill['id']] = $skill; return []; } $all = $skills; $skills = []; return $all; } /** * Versteckte Beschreibungen aller gemerkten Skills - Werte bei der geplanten Stufe (sonst Stufe 1). * * @param array $levels geplante Stufe je Skill-ID */ function gear_guide_tip_sources(array $levels): string { $html = ''; foreach (gear_guide_tip_registry() as $id => $skill) { $tip = gear_skill_tip_html($skill, $levels[$id] ?? 0); // Spezialisierungen (Stigmen: Boni) fuer [[Skill:N]] - die Info-Blase zeigt sie nur dort und hebt die gemeinte // hervor (assets/js/gear.js, data-tip-spec); ohne uebernommene Beschreibung nur Name und Spezialisierungen $parts = ''; foreach (gear_skill_parts($skill) as $no => $part) { $parts .= '
' . ($skill['kind'] === 'stigma' ? '' . (int) $no . '' : gear_guide_spec_icon(true, (int) $no)) . 'ab ' . (int) $part['t'] . '' . e($part['text']) . '
'; } if ($parts !== '') { $parts = '
' . ($skill['kind'] === 'stigma' ? 'Boni' : 'Spezialitäten') . '
' . $parts . '
'; $tip = $tip !== '' ? substr($tip, 0, -strlen('
')) . $parts . '' : ''; } $html .= ''; } return $html !== '' ? '' : ''; } /** Skill-Chip: Icon und Name, beim Drueberfahren die Info-Blase des Skills (sonst der englische Name). */ function gear_guide_skill_chip(array $skill): string { $url = gear_skill_icon_url($skill); $tip = gear_guide_tip_attrs($skill); $other = !empty($skill['name_de']) && $skill['name_de'] !== $skill['name'] ? (string) $skill['name'] : ''; return '' . ($url ? '' : '') . e(gear_skill_display_name($skill)) . ''; } /** * [[Skill:N]] im Text: Symbol der Spezialisierung (aktive Skills: I-V in ihren Farben, Stigmen: Icon des Skills) und * ihr Text - beim Drueberfahren die Info-Blase des Skills mit der hervorgehobenen Spezialisierung (assets/js/gear.js). * null = diese Nummer hat der Skill nicht. */ function gear_guide_spec_chip(array $skill, int $no): ?string { $part = gear_skill_parts($skill)[$no] ?? null; if ($part === null) { return null; } gear_guide_tip_registry($skill); $isStigma = $skill['kind'] === 'stigma'; $url = $isStigma ? gear_skill_icon_url($skill) : null; $icon = $isStigma ? ($url ? '' : '') : ''; $label = gear_skill_display_name($skill) . ' – ' . ($isStigma ? 'Bonus ' . $no : 'Spezialisierung ' . GEAR_SKILL_SPEC_NUMERALS[$no]); return '' . $icon . '' . e($part['text']) . ''; } /** Muster fuer [[Item:Name]] / [[Flügel:ID]] - Gruppe 1: Name oder ID (im Rohtext wie im maskierten HTML). */ function gear_guide_item_pattern(): string { return '/\[\[\s*(?:' . implode('|', array_map(static fn (string $p): string => preg_quote($p, '/'), GEAR_GUIDE_ITEM_PREFIXES)) . ')\s*:\s*([^\[\]<>]{1,150}?)\s*\]\]/iu'; } /** Gegenstands-Verweise in einem Text (Namen bzw. IDs, ohne Doppelte). */ function gear_guide_item_refs(string $text): array { preg_match_all(gear_guide_item_pattern(), $text, $m); $refs = []; foreach ($m[1] as $ref) { $refs[mb_strtolower(trim($ref))] = trim($ref); } return array_values($refs); } /** Schon nachgeschlagener Gegenstand zu einem Verweis (ID oder Name wie bei aion2hub) - null = (noch) unbekannt. */ function gear_guide_item_cached(string $ref): ?array { require_once __DIR__ . '/item_db.php'; if (ctype_digit($ref)) { return item_db_get((int) $ref); } $stmt = db()->prepare('SELECT item_id FROM item_db_names WHERE name = ? AND item_id IS NOT NULL'); $stmt->execute([$ref]); $id = $stmt->fetchColumn(); return $id !== false ? item_db_get((int) $id) : null; } /** Seite von aion2.app (deutsch) - hoechstens GEAR_GUIDE_ITEM_DE_LIMIT pro Minute fuer die ganze Website. */ function gear_guide_item_de_fetch(string $url): string { if (rate_limit_count('aion2app', 'site', 60) >= GEAR_GUIDE_ITEM_DE_LIMIT) { throw new ItemDbBusyException('Gerade werden viele Gegenstände abgerufen.'); } rate_limit_add('aion2app', 'site'); return gear_source_fetch($url); } /** Name ohne " (Gebunden)" - so heisst der Gegenstand im Spiel, die gebundene Fassung ist dieselbe. */ function gear_guide_item_de_plain(string $name): string { return trim((string) preg_replace('/\s*\((?:gebunden|bound)\)\s*$/iu', '', $name)); } /** Gegenstand per deutschem Namen bei aion2.app suchen: ID des Treffers mit genau diesem Namen (auch "(Gebunden)"). */ function gear_guide_item_de_search(string $name): ?int { $html = gear_guide_item_de_fetch(GEAR_GUIDE_ITEM_DE_URL . '?q=' . rawurlencode($name)); preg_match_all('#]*href="/de/db/items/(\d{6,12})"[^>]*>(.*?)#s', $html, $links, PREG_SET_ORDER); $wanted = item_db_normalize(gear_guide_item_de_plain($name)); foreach ($links as [, $id, $inner]) { foreach (gear_source_tokens($inner) as $token) { if (item_db_normalize(gear_guide_item_de_plain($token)) === $wanted) { return (int) $id; } } } return null; } /** Deutscher Name eines Gegenstands laut aion2.app (Seitentitel "Name — Aion 2 …"), null = unbekannt. */ function gear_guide_item_de_name(int $id): ?string { $html = gear_guide_item_de_fetch(GEAR_GUIDE_ITEM_DE_URL . '/' . $id); if (!preg_match('#(.*?)#s', $html, $m)) { return null; } $title = trim(explode(' — ', html_entity_decode($m[1], ENT_QUOTES | ENT_HTML5, 'UTF-8'))[0]); return $title !== '' && mb_strlen($title) <= 150 && !str_starts_with($title, 'Aion 2') ? gear_guide_item_de_plain($title) : null; } /** * Gegenstaende eines Guides bei aion2hub nachschlagen (beim Speichern): Daten in item_db, Bild unter * assets/uploads/gear. Schon bekannte zaehlen nicht mit. Liefert die Verweise, die es nicht gibt bzw. die * diesmal nicht drankamen (Tempolimit) - fuer den Hinweis nach dem Speichern. * * @return array{missing: string[], later: string[]} */ function gear_guide_items_lookup(string $text): array { require_once __DIR__ . '/item_db.php'; $result = ['missing' => [], 'later' => []]; $fetched = 0; foreach (gear_guide_item_refs($text) as $ref) { $item = gear_guide_item_cached($ref); if ($item !== null && !empty($item['name_de']) && gear_guide_item_icon_url((int) $item['id']) !== null) { continue; // alles schon da } if ($fetched >= GEAR_GUIDE_ITEM_LOOKUPS) { $result['later'][] = $ref; continue; } $fetched++; try { if ($item === null && ctype_digit($ref)) { $item = item_db_parse(item_db_fetch(GEAR_SOURCE_ITEM_URL . (int) $ref), (int) $ref); item_db_store($item); } elseif ($item === null) { // Englisch bei aion2hub, sonst deutsch bei aion2.app - die Daten kommen dann ueber die ID von aion2hub $found = item_db_lookup($ref); if ($found['status'] === 'busy') { throw new ItemDbBusyException('aion2hub'); } $item = $found['status'] === 'ok' ? $found['item'] : null; if ($item === null && ($id = gear_guide_item_de_search($ref)) !== null) { $item = item_db_parse(item_db_fetch(GEAR_SOURCE_ITEM_URL . $id), $id); item_db_store($item); item_db_map($ref, $id); } } if ($item === null) { $result['missing'][] = $ref; continue; } if (empty($item['name_de']) && ($german = gear_guide_item_de_name((int) $item['id'])) !== null) { $item['name_de'] = $german; item_db_store($item); } } catch (ItemDbBusyException $e) { $result['later'][] = $ref; continue; } catch (RuntimeException $e) { if ($item === null) { $result['missing'][] = $ref; continue; } } if (gear_guide_item_icon_url((int) $item['id']) === null) { gear_icon_download((int) $item['id']); } } return $result; } /** Bild eines Gegenstands (assets/uploads/gear/.*), null = nicht geladen. */ function gear_guide_item_icon_url(int $id): ?string { foreach (['png', 'webp', 'jpg', 'gif'] as $ext) { $file = GEAR_ICON_DIR . $id . '.' . $ext; if (is_file($file)) { return GEAR_ICON_URL . $id . '.' . $ext . '?v=' . filemtime($file); } } return null; } /** * [[Item:...]] im Text: Bild und Name in der Farbe der Seltenheit, beim Drueberfahren die Info-Blase wie im Lagerhaus * (Werte, Effekte, Infos von aion2hub; assets/js/gear.js). Unbekannt: nur der Name, gedaempft. */ function gear_guide_item_chip(string $ref): string { require_once __DIR__ . '/item_db.php'; $item = gear_guide_item_cached($ref); if ($item === null) { return '' . e($ref) . ''; } $grade = strtolower((string) $item['grade']); $icon = gear_guide_item_icon_url((int) $item['id']); // Deutscher Name (aion2.app), sonst der englische von aion2hub - in der Info-Blase der englische klein darunter $english = (string) $item['name']; if (!empty($item['name_de'])) { $item['name'] = (string) $item['name_de']; $item['tags'] = array_merge([$english], (array) ($item['tags'] ?? [])); } $iconHtml = $icon !== null ? '' : ''; return '' . ($icon !== null ? '' : '') . e((string) $item['name']) //