705 lines
40 KiB
PHP
705 lines
40 KiB
PHP
<?php
|
||
/**
|
||
* Gear-Planer: ein Set mit einem Charakter aus dem Spiel abgleichen (Daten von aion2.plaync.com, wie die
|
||
* Live-Daten der Profilseiten in includes/armory.php). Ablauf (gear.php Dialog "Aus dem Spiel", gear_action.php):
|
||
* 1. armory_search: Charakter suchen (beliebiger Elyos-Server, Kaisinel vorgewaehlt)
|
||
* 2. gear_armory_preview: Ausruestung samt Manasteinen/Seelenpraegung, Skills und Daevanion abrufen und
|
||
* fuer das Set aufbereiten - gespeichert in armory_cache ("gear-import:u<Konto>"), damit beim Uebernehmen
|
||
* genau das gilt, was die Vorschau gezeigt hat
|
||
* 3. gear_armory_apply: die angehakten Teile ins Set schreiben
|
||
* Gegenstands-, Skill- und Daevanion-IDs von NCSoft sind dieselben wie bei aion2hub (Quelle des Planers).
|
||
*/
|
||
require_once __DIR__ . '/armory.php';
|
||
require_once __DIR__ . '/gear.php';
|
||
require_once __DIR__ . '/gear_skills.php';
|
||
require_once __DIR__ . '/gear_planner.php';
|
||
require_once __DIR__ . '/gear_planner_view.php'; // gear_daevanion_node_html, gear_plan_class_skills
|
||
|
||
// Vorschau so lange aufheben (danach neu abrufen)
|
||
const GEAR_ARMORY_TTL = 1800;
|
||
// Sprache fuer die Gegenstandsdetails: englische Wertnamen wie im Katalog von aion2hub ("Critical Hit", "MP")
|
||
const GEAR_ARMORY_ITEM_LANG = 'en-US';
|
||
// Fehlende Gegenstandsdetails (NCSoft liefert oft 404) so oft nachfragen
|
||
const GEAR_ARMORY_ITEM_ROUNDS = 5;
|
||
// Skill-Gruppen in der Vorschau: Art bei uns => [Ueberschrift, NCSoft-Kategorie]
|
||
const GEAR_ARMORY_SKILL_GROUPS = ['active' => 'Aktive Skills', 'passive' => 'Passive Skills', 'stigma' => 'Stigmen'];
|
||
|
||
/**
|
||
* Charakter bei NCSoft abrufen: Profil, Ausruestung mit Details je Gegenstand, Skills mit IDs und die
|
||
* offenen Daevanion-Felder je Brett (nur, was der Planer braucht).
|
||
*
|
||
* @return array<string, mixed>
|
||
* @throws RuntimeException wenn NCSoft nicht antwortet oder es den Charakter nicht gibt
|
||
*/
|
||
function gear_armory_fetch(string $charId, int $serverId): array
|
||
{
|
||
if (function_exists('set_time_limit')) {
|
||
@set_time_limit(90);
|
||
}
|
||
$base = 'https://' . ARMORY_API_HOST . '/api/character/';
|
||
$info = armory_request_complete($base . 'info?' . armory_query($charId, $serverId),
|
||
static fn (array $info): bool => empty($info['profile']['characterName']));
|
||
$profile = (array) ($info['profile'] ?? []);
|
||
if (empty($profile['characterName'])) {
|
||
throw new RuntimeException('Diesen Charakter gibt es im Spiel nicht (mehr).', 404);
|
||
}
|
||
$equip = armory_request_complete($base . 'equipment?' . armory_query($charId, $serverId), 'armory_equip_or_skills_hollow');
|
||
|
||
// Details je Gegenstand (Manasteine, Seelenpraegung, bei Arcana die gepraegten Skills) - NCSoft antwortet oft
|
||
// mit 404, deshalb in Runden nachfragen. Arcana-Karten stehen mit in der Ausruestung (Plaetze "Arcana1" ...).
|
||
$equipment = [];
|
||
$urls = [];
|
||
foreach ((array) ($equip['equipment']['equipmentList'] ?? []) as $item) {
|
||
$slotName = (string) ($item['slotPosName'] ?? '');
|
||
$slot = ARMORY_SLOTS[$slotName] ?? (preg_match('/^Arcana\d+$/', $slotName) ? 'arcana:' . (int) ($item['slotPos'] ?? 0) : null);
|
||
if ($slot === null || empty($item['id'])) {
|
||
continue;
|
||
}
|
||
$equipment[$slot] = [
|
||
'id' => (int) $item['id'],
|
||
'name' => (string) ($item['name'] ?? ''),
|
||
'grade' => (string) ($item['grade'] ?? ''),
|
||
'icon' => (string) ($item['icon'] ?? ''),
|
||
'enchant' => (int) ($item['enchantLevel'] ?? 0),
|
||
'exceed' => (int) ($item['exceedLevel'] ?? 0),
|
||
'detail' => null,
|
||
];
|
||
$urls[$slot] = $base . 'equipment/item?' . http_build_query([
|
||
'id' => (int) $item['id'], 'enchantLevel' => (int) ($item['enchantLevel'] ?? 0), 'characterId' => $charId,
|
||
'serverId' => $serverId, 'slotPos' => (int) ($item['slotPos'] ?? 0), 'lang' => GEAR_ARMORY_ITEM_LANG, 'region' => ARMORY_REGION,
|
||
]);
|
||
}
|
||
for ($round = 1; $urls && $round <= GEAR_ARMORY_ITEM_ROUNDS; $round++) {
|
||
foreach (armory_request_multi($urls) as $slot => $detail) {
|
||
if ((int) ($detail['id'] ?? 0) === $equipment[$slot]['id']) {
|
||
$equipment[$slot]['detail'] = [
|
||
'soul' => array_values(array_filter(array_map(static fn ($s): ?array => is_array($s) && isset($s['name'], $s['value'])
|
||
? [(string) $s['name'], (float) str_replace(['%', ',', '+'], '', (string) $s['value'])] : null, (array) ($detail['subStats'] ?? [])))),
|
||
'soul_random' => !empty($detail['subStatRandom']),
|
||
'soul_skills' => array_values(array_filter(array_map(static fn ($s): ?array => is_array($s) && !empty($s['id'])
|
||
? [(int) $s['id'], max(1, (int) ($s['level'] ?? 1)), (string) ($s['name'] ?? ''), (string) ($s['icon'] ?? '')] : null, (array) ($detail['subSkills'] ?? [])))),
|
||
'manastones' => array_values(array_filter(array_map(static fn ($s): ?array => is_array($s) && isset($s['name'], $s['value'])
|
||
? [(string) $s['name'], (int) str_replace(['+', ',', '.'], '', (string) $s['value'])] : null, (array) ($detail['magicStoneStat'] ?? [])))),
|
||
];
|
||
unset($urls[$slot]);
|
||
}
|
||
}
|
||
if ($urls) {
|
||
usleep(300000);
|
||
}
|
||
}
|
||
$arcana = [];
|
||
foreach ($equipment as $slot => $entry) {
|
||
if (str_starts_with($slot, 'arcana:')) {
|
||
$arcana[] = $entry;
|
||
unset($equipment[$slot]);
|
||
}
|
||
}
|
||
|
||
$skills = [];
|
||
foreach ((array) ($equip['skill']['skillList'] ?? []) as $skill) {
|
||
$kind = ARMORY_SKILL_KINDS[(string) ($skill['category'] ?? '')] ?? null;
|
||
if ($kind === null || empty($skill['id'])) {
|
||
continue;
|
||
}
|
||
$skills[] = [
|
||
'id' => (int) $skill['id'],
|
||
'name' => (string) ($skill['name'] ?? ''),
|
||
'kind' => $kind,
|
||
'level' => (int) ($skill['skillLevel'] ?? 0),
|
||
'equipped' => !empty($skill['equip']),
|
||
'icon' => (string) ($skill['icon'] ?? ''),
|
||
];
|
||
}
|
||
|
||
// Daevanion: nur Bretter mit offenen Feldern abfragen
|
||
$boardList = array_values(array_filter((array) ($info['daevanion']['boardList'] ?? []),
|
||
static fn ($b): bool => is_array($b) && (int) ($b['openNodeCount'] ?? 0) > 0));
|
||
$details = $boardList ? armory_request_multi(array_combine(
|
||
array_map(static fn (array $b): string => 'b' . (int) $b['id'], $boardList),
|
||
array_map(static fn (array $b): string => $base . 'daevanion/detail?' . armory_query($charId, $serverId, ['boardId' => (int) $b['id']]), $boardList)
|
||
)) : [];
|
||
$boards = [];
|
||
foreach ($boardList as $board) {
|
||
$detail = $details['b' . (int) $board['id']] ?? null;
|
||
$boards[] = [
|
||
'id' => (int) $board['id'],
|
||
'name' => (string) ($board['name'] ?? ''),
|
||
'open' => (int) ($board['openNodeCount'] ?? 0),
|
||
// null = Abfrage fehlgeschlagen
|
||
'nodes' => $detail === null ? null : array_values(array_map(static fn (array $n): int => (int) $n['nodeId'],
|
||
array_filter((array) ($detail['nodeList'] ?? []), static fn ($n): bool => is_array($n) && !empty($n['open']) && !empty($n['nodeId'])))),
|
||
];
|
||
}
|
||
|
||
return [
|
||
'char_id' => $charId,
|
||
'server_id' => $serverId,
|
||
'name' => (string) $profile['characterName'],
|
||
'level' => (int) ($profile['characterLevel'] ?? 0),
|
||
'class' => armory_class_name((string) ($profile['className'] ?? '')),
|
||
'class_label' => (string) ($profile['className'] ?? ''),
|
||
'equipment' => $equipment,
|
||
'equipment_missing' => armory_equip_hollow($equip),
|
||
'arcana' => $arcana,
|
||
'skills' => $skills,
|
||
'skills_missing' => armory_skills_hollow($equip),
|
||
'boards' => $boards,
|
||
'fetched_at' => date('Y-m-d H:i:s'),
|
||
];
|
||
}
|
||
|
||
function gear_armory_cache_key(int $userId): string
|
||
{
|
||
return 'gear-import:u' . $userId;
|
||
}
|
||
|
||
/** Abgerufenen Charakter fuer das Uebernehmen merken (einer pro Konto). */
|
||
function gear_armory_remember(int $userId, array $data): void
|
||
{
|
||
db()->prepare('INSERT INTO armory_cache (cache_key, data, fetched_at) VALUES (?, ?, ?)
|
||
ON DUPLICATE KEY UPDATE data = VALUES(data), fetched_at = VALUES(fetched_at)')
|
||
->execute([gear_armory_cache_key($userId), json_encode($data, JSON_UNESCAPED_UNICODE), date('Y-m-d H:i:s')]);
|
||
}
|
||
|
||
/** Zuletzt abgerufener Charakter (null = keiner oder abgelaufen). */
|
||
function gear_armory_remembered(int $userId): ?array
|
||
{
|
||
$stmt = db()->prepare('SELECT data FROM armory_cache WHERE cache_key = ? AND fetched_at > ?');
|
||
$stmt->execute([gear_armory_cache_key($userId), date('Y-m-d H:i:s', time() - GEAR_ARMORY_TTL)]);
|
||
$data = json_decode((string) $stmt->fetchColumn(), true);
|
||
return is_array($data) ? $data : null;
|
||
}
|
||
|
||
function gear_armory_forget(int $userId): void
|
||
{
|
||
db()->prepare('DELETE FROM armory_cache WHERE cache_key = ?')->execute([gear_armory_cache_key($userId)]);
|
||
}
|
||
|
||
/**
|
||
* Was sich von einem Charakter in das Set uebernehmen laesst, je Teil mit Grund, falls nicht.
|
||
* $class = Klasse, mit der das Set danach rechnet (die des Charakters, wenn die Klasse mit uebernommen wird).
|
||
*
|
||
* @return array{slots: array<string, array>, arcana: array<string, array>, skills: array<string, array>, boards: array<int, array>}
|
||
*/
|
||
function gear_armory_plan(array $data, ?string $class): array
|
||
{
|
||
// Ausruestung: nur Gegenstaende aus dem Katalog des Planers, passend zu Slot und Klasse
|
||
$items = gear_items_by_ids(array_column($data['equipment'], 'id'));
|
||
$manastoneStats = array_flip(gear_manastone_stats());
|
||
$slots = [];
|
||
foreach (GEAR_SLOTS as $slotKey => $unused) {
|
||
$entry = $data['equipment'][$slotKey] ?? null;
|
||
if ($entry === null) {
|
||
continue;
|
||
}
|
||
$item = $items[$entry['id']] ?? null;
|
||
$row = ['game' => $entry, 'item' => $item, 'problem' => null, 'enchant' => 0, 'exceed' => 0, 'soul' => [], 'manastones' => [], 'skipped' => 0];
|
||
if ($item === null) {
|
||
$row['problem'] = 'fehlt noch in der Gegenstandsliste des Planers';
|
||
} elseif (($mismatch = gear_item_mismatch($item, $slotKey, $class)) !== null) {
|
||
$row['problem'] = $mismatch;
|
||
} else {
|
||
$row['enchant'] = max(0, min((int) $item['enchant_max'], $entry['enchant']));
|
||
$row['exceed'] = max(0, min((int) $item['exceed_max'], $entry['exceed']));
|
||
$detail = $entry['detail'];
|
||
if ($detail !== null) {
|
||
// Seelenpraegung: nur Werte, die der Gegenstand laut Katalog wuerfeln kann, in seiner Spanne
|
||
$ranges = array_column($item['soul_imprint'], null, 0);
|
||
$inRange = static fn (?array $range, float $value): bool => $range !== null && $value >= (float) $range[1] - 0.005 && $value <= (float) $range[2] + 0.005;
|
||
foreach ($detail['soul'] as [$stat, $value]) {
|
||
$range = $ranges[$stat] ?? null;
|
||
// Flugkraft zeigt NCSoft in Hundertsteln des Katalogwerts (299 statt 29.900)
|
||
if (!$inRange($range, $value) && $inRange($range, $value * 100)) {
|
||
$value *= 100;
|
||
}
|
||
if ($inRange($range, $value)) {
|
||
$row['soul'][] = [$stat, $value];
|
||
} elseif ($detail['soul_random']) {
|
||
$row['skipped']++;
|
||
}
|
||
}
|
||
$soulSkills = gear_item_soul_skills($item, $class);
|
||
$soulSkillLevel = max(1, (int) ($item['soul_skills']['level'] ?? 1));
|
||
foreach ($detail['soul_skills'] as [$skillId]) {
|
||
if (isset($soulSkills[$skillId])) {
|
||
$row['soul'][] = [GEAR_SOUL_SKILL_PREFIX . $skillId, $soulSkillLevel];
|
||
} else {
|
||
$row['skipped']++;
|
||
}
|
||
}
|
||
$row['soul'] = array_slice($row['soul'], 0, (int) $item['soul_imprint_count']);
|
||
foreach ($detail['manastones'] as [$stat, $value]) {
|
||
// "Evasion Bonus", "Accuracy Bonus": bei NCSoft derselbe Wert wie "Evasion" bzw. "Accuracy"
|
||
if (!isset($manastoneStats[$stat]) && str_ends_with($stat, ' Bonus')) {
|
||
$stat = substr($stat, 0, -6);
|
||
}
|
||
if (isset($manastoneStats[$stat]) && $value >= 1 && $value <= 9999) {
|
||
$row['manastones'][] = [$stat, $value];
|
||
} else {
|
||
$row['skipped']++;
|
||
}
|
||
}
|
||
$row['manastones'] = array_slice($row['manastones'], 0, (int) $item['manastone_slots']);
|
||
}
|
||
}
|
||
$slots[$slotKey] = $row;
|
||
}
|
||
|
||
// Skills: nur solche, die der Planer fuer die Klasse kennt; Stigmen hoechstens GEAR_STIGMA_SLOTS (die ausgeruesteten)
|
||
$known = $class === $data['class'] ? gear_skills_for_class($class, false) : [];
|
||
$skills = [];
|
||
foreach (GEAR_ARMORY_SKILL_GROUPS as $kind => $label) {
|
||
$list = array_values(array_filter($data['skills'], static fn (array $s): bool => $s['kind'] === $kind && $s['level'] > 0));
|
||
if ($kind === 'stigma') {
|
||
usort($list, static fn (array $a, array $b): int => [!$a['equipped'], -$a['level']] <=> [!$b['equipped'], -$b['level']]);
|
||
$list = array_slice($list, 0, GEAR_STIGMA_SLOTS);
|
||
}
|
||
$usable = array_values(array_filter($list, static fn (array $s): bool => isset($known[$s['id']]) && $known[$s['id']]['kind'] === $kind));
|
||
$skills[$kind] = [
|
||
'label' => $label,
|
||
'list' => $usable,
|
||
'unknown' => count($list) - count($usable),
|
||
'problem' => $class !== $data['class'] ? 'gehören zu ' . ($data['class'] ?? $data['class_label'])
|
||
: (!$known ? 'für ' . $class . ' gibt es im Planer noch keine Skills' : null),
|
||
];
|
||
}
|
||
|
||
// Daevanion: Bretter des Planers fuer die Klasse, offene Felder nach ID
|
||
$planBoards = [];
|
||
if ($class !== null && $class === $data['class']) {
|
||
foreach (gear_daevanion_boards($class) as $board) {
|
||
$planBoards[(int) $board['id']] = $board;
|
||
}
|
||
}
|
||
$boards = [];
|
||
foreach ($data['boards'] as $board) {
|
||
$planBoard = $planBoards[$board['id']] ?? null;
|
||
$ids = $planBoard ? array_flip(array_map(static fn (array $n): int => (int) $n['id'], $planBoard['nodes'])) : [];
|
||
$nodes = array_values(array_filter((array) $board['nodes'], static fn (int $id): bool => isset($ids[$id])));
|
||
$boards[$board['id']] = [
|
||
'name' => $board['name'],
|
||
'open' => $board['open'],
|
||
'nodes' => $nodes,
|
||
'problem' => match (true) {
|
||
$class !== $data['class'] => 'gehört zu ' . ($data['class'] ?? $data['class_label']),
|
||
$planBoard === null => 'das Brett kennt der Planer (noch) nicht',
|
||
$board['nodes'] === null => 'NCSoft hat die Felder gerade nicht geliefert',
|
||
!$nodes => 'keine passenden Felder',
|
||
default => null,
|
||
},
|
||
];
|
||
}
|
||
// Arcana: Karte nach ID aus den Daten des Planers, je Art ein Platz; Skills nur aus dem Pool der Karte fuer die Klasse
|
||
$arcanaData = gear_arcana_data();
|
||
$arcana = [];
|
||
foreach ((array) ($data['arcana'] ?? []) as $entry) {
|
||
$card = $arcanaData['cards'][$entry['id']] ?? null;
|
||
$type = $card['type'] ?? null;
|
||
$row = ['game' => $entry, 'card' => $card, 'enchant' => 0, 'skills' => [], 'skipped' => 0, 'problem' => match (true) {
|
||
$arcanaData === null => 'die Arcana-Daten fehlen im Planer noch',
|
||
$card === null => 'diese Karte kennt der Planer (noch) nicht',
|
||
isset($arcana[$type]) => 'zweite Karte dieser Art',
|
||
default => null,
|
||
}];
|
||
if ($row['problem'] === null) {
|
||
$row['enchant'] = max(0, min((int) $card['max'], (int) $entry['enchant']));
|
||
$pool = gear_arcana_pool($card, $class, $arcanaData);
|
||
foreach ((array) ($entry['detail']['soul_skills'] ?? []) as $skill) {
|
||
if (isset($pool[$skill[0]])) {
|
||
$row['skills'][] = $skill;
|
||
} else {
|
||
$row['skipped']++;
|
||
}
|
||
}
|
||
}
|
||
$arcana[$type ?? 'x' . $entry['id']] = $row;
|
||
}
|
||
// Reihenfolge der Plaetze wie im Spiel
|
||
$order = array_flip($arcanaData['types'] ?? []);
|
||
uksort($arcana, static fn (string $a, string $b): int => ($order[$a] ?? 99) <=> ($order[$b] ?? 99));
|
||
|
||
return ['slots' => $slots, 'arcana' => $arcana, 'skills' => $skills, 'boards' => $boards];
|
||
}
|
||
|
||
/**
|
||
* Angehakte Teile ins Set schreiben. $choice: class (bool), slots (Slot-Schluessel), upgrades (Verzauberung/Durchbruch),
|
||
* stones (Manasteine/Seelenpraegung), arcana (Arten wie "Grail"), skills (Arten), boards (Brett-IDs).
|
||
*
|
||
* @return string[] Zusammenfassung, was uebernommen wurde
|
||
*/
|
||
function gear_armory_apply(array $set, array $data, array $choice): array
|
||
{
|
||
$pdo = db();
|
||
$setId = (int) $set['id'];
|
||
$done = [];
|
||
$class = $set['class_name'] ?: null;
|
||
if (!empty($choice['class']) && $data['class'] !== null && $data['class'] !== $class) {
|
||
$pdo->prepare('UPDATE gear_sets SET class_name = ? WHERE id = ?')->execute([$data['class'], $setId]);
|
||
$class = $data['class'];
|
||
$set['class_name'] = $class;
|
||
$done[] = 'Klasse ' . $class;
|
||
}
|
||
$plan = gear_armory_plan($data, $class);
|
||
|
||
$pdo->beginTransaction();
|
||
$slotCount = 0;
|
||
$upsert = $pdo->prepare(
|
||
'INSERT INTO gear_set_slots (set_id, slot, item_id, enchant, exceed, soul_imprint, manastones, godstone)
|
||
VALUES (?, ?, ?, ?, ?, ?, ?, NULL)
|
||
ON DUPLICATE KEY UPDATE item_id = VALUES(item_id), enchant = VALUES(enchant), exceed = VALUES(exceed),
|
||
soul_imprint = VALUES(soul_imprint), manastones = VALUES(manastones), godstone = IF(item_id <=> VALUES(item_id), godstone, NULL)'
|
||
);
|
||
foreach ((array) ($choice['slots'] ?? []) as $slotKey) {
|
||
$row = $plan['slots'][$slotKey] ?? null;
|
||
if ($row === null || $row['problem'] !== null) {
|
||
continue;
|
||
}
|
||
$upgrades = !empty($choice['upgrades']);
|
||
$stones = !empty($choice['stones']);
|
||
$upsert->execute([
|
||
$setId, $slotKey, $row['item']['id'], $upgrades ? $row['enchant'] : 0, $upgrades ? $row['exceed'] : 0,
|
||
json_encode($stones ? $row['soul'] : [], JSON_UNESCAPED_UNICODE), json_encode($stones ? $row['manastones'] : [], JSON_UNESCAPED_UNICODE),
|
||
]);
|
||
$slotCount++;
|
||
}
|
||
$pdo->commit();
|
||
if ($slotCount) {
|
||
$done[] = $slotCount . ($slotCount === 1 ? ' Slot' : ' Slots');
|
||
}
|
||
|
||
// Arcana (vor den Skills: ihre Skill-Boni zaehlen bei den Stufen mit) - angehakte Arten ersetzen die Karte im Plan
|
||
$arcanaTypes = array_values(array_filter((array) ($choice['arcana'] ?? []),
|
||
static fn ($type): bool => is_string($type) && isset($plan['arcana'][$type]) && $plan['arcana'][$type]['problem'] === null));
|
||
if ($arcanaTypes && ($arcanaData = gear_arcana_data())) {
|
||
$arcanaPlan = gear_set_plan($setId, 'arcana');
|
||
foreach ($arcanaTypes as $type) {
|
||
$row = $plan['arcana'][$type];
|
||
$arcanaPlan['slots'][$type] = [
|
||
'card' => (int) $row['card']['id'],
|
||
'enchant' => $row['enchant'],
|
||
'skills' => array_map(static fn (array $skill): array => [$skill[0], $skill[1]], $row['skills']),
|
||
];
|
||
}
|
||
[$arcanaPlan] = gear_arcana_normalize($arcanaPlan, $class, $arcanaData);
|
||
gear_set_plan_store($set, 'arcana', $arcanaPlan);
|
||
$done[] = count($arcanaTypes) . ' Arcana';
|
||
}
|
||
|
||
// Daevanion vor den Skills: dessen Boni zaehlen bei den Skillstufen mit
|
||
$boardIds = array_values(array_filter(array_map('intval', (array) ($choice['boards'] ?? [])),
|
||
static fn (int $id): bool => isset($plan['boards'][$id]) && $plan['boards'][$id]['problem'] === null));
|
||
if ($boardIds && $class !== null) {
|
||
$nodes = (array) (gear_set_plan($setId, 'daevanion')['nodes'] ?? []);
|
||
foreach ($boardIds as $boardId) {
|
||
$nodes = gear_daevanion_board_action($nodes, $class, $boardId, false);
|
||
$nodes = array_merge($nodes, $plan['boards'][$boardId]['nodes']);
|
||
}
|
||
[$daevanion] = gear_daevanion_normalize($nodes, $class);
|
||
gear_set_plan_store($set, 'daevanion', $daevanion);
|
||
$done[] = count($boardIds) . ' Daevanion-' . (count($boardIds) === 1 ? 'Brett' : 'Bretter');
|
||
}
|
||
|
||
// Skills: Stufe im Spiel enthaelt Boni (Daevanion, Arcana, Seelenpraegung) - gespeichert wird die selbst gesteigerte
|
||
$kinds = array_values(array_filter((array) ($choice['skills'] ?? []),
|
||
static fn ($kind): bool => isset($plan['skills'][$kind]) && $plan['skills'][$kind]['problem'] === null));
|
||
if ($kinds) {
|
||
$skills = gear_skills_for_class($class, false);
|
||
$current = gear_set_skill_rows($setId);
|
||
$bonuses = array_map(static fn (array $bonus): int => (int) array_sum($bonus), gear_plan_skill_bonuses($set, gear_set_plan_all($setId)));
|
||
$pdo->beginTransaction();
|
||
$remove = $pdo->prepare('DELETE FROM gear_set_skills WHERE set_id = ? AND skill_id = ?');
|
||
$insert = $pdo->prepare('INSERT INTO gear_set_skills (set_id, skill_id, level, specs) VALUES (?, ?, ?, ?)
|
||
ON DUPLICATE KEY UPDATE level = VALUES(level), specs = VALUES(specs)');
|
||
$count = 0;
|
||
foreach ($kinds as $kind) {
|
||
// Die Art wird ganz ersetzt: was der Charakter nicht gesteigert hat, faellt raus
|
||
foreach ($current as $skillId => $unused) {
|
||
if (($skills[$skillId]['kind'] ?? null) === $kind) {
|
||
$remove->execute([$setId, $skillId]);
|
||
}
|
||
}
|
||
foreach ($plan['skills'][$kind]['list'] as $skill) {
|
||
$level = max(0, min(gear_skill_level_max($kind), $skill['level'] - ($bonuses[$skill['id']] ?? 0)));
|
||
if ($level === 0) {
|
||
continue;
|
||
}
|
||
$specs = gear_skill_has_specs($kind)
|
||
? gear_skill_specs_clean((int) ($current[$skill['id']]['specs'] ?? 0), gear_skill_effective_level($kind, $level, $bonuses[$skill['id']] ?? 0)) : 0;
|
||
$insert->execute([$setId, $skill['id'], $level, $specs]);
|
||
$count++;
|
||
}
|
||
}
|
||
$pdo->commit();
|
||
$done[] = $count . ' Skills';
|
||
}
|
||
|
||
$pdo->prepare('UPDATE gear_sets SET updated_at = NOW() WHERE id = ?')->execute([$setId]);
|
||
return $done;
|
||
}
|
||
|
||
/** Alle Plaene eines Sets ([Seite => Plan]). */
|
||
function gear_set_plan_all(int $setId): array
|
||
{
|
||
return gear_set_plans([$setId])[$setId] ?? [];
|
||
}
|
||
|
||
/** Eigene, mit dem Spiel verknuepfte Profil-Charaktere (fuer die Schnellauswahl im Dialog). */
|
||
function gear_armory_own_characters(int $userId): array
|
||
{
|
||
$stmt = db()->prepare(
|
||
'SELECT name, class_name, level, aion_char_id, aion_server_id FROM member_characters
|
||
WHERE user_id = ? AND aion_char_id IS NOT NULL ORDER BY is_main DESC, name'
|
||
);
|
||
$stmt->execute([$userId]);
|
||
return $stmt->fetchAll();
|
||
}
|
||
|
||
/** Icon eines Gegenstands fuer die Vorschau: aus dem Katalog, sonst das von NCSoft. */
|
||
function gear_armory_item_icon(?array $item, array $game): ?string
|
||
{
|
||
if ($item && !empty($item['icon']) && is_file(GEAR_ICON_DIR . $item['icon'])) {
|
||
return gear_icon_url($item);
|
||
}
|
||
return armory_icon_url((string) $game['icon']);
|
||
}
|
||
|
||
/** Icon eines Skills fuer die Vorschau: aus dem Skillplaner, sonst das von NCSoft. */
|
||
function gear_armory_skill_icon(array $skill, array $known): ?string
|
||
{
|
||
$row = $known[$skill['id']] ?? null;
|
||
if ($row && !empty($row['icon']) && is_file(GEAR_SKILL_ICON_DIR . $row['icon'])) {
|
||
return gear_skill_icon_url($row);
|
||
}
|
||
return armory_icon_url((string) ($skill['icon'] ?? ''));
|
||
}
|
||
|
||
/**
|
||
* Ein Daevanion-Brett klein und nur zum Ansehen (Felder wie auf der Seite Daevanion, includes/gear_planner_view.php):
|
||
* die freigeschalteten Felder des Charakters leuchten.
|
||
*/
|
||
function gear_armory_board_html(array $board, array $nodeIds, array $skills, string $class): string
|
||
{
|
||
$chosen = array_flip($nodeIds);
|
||
foreach ($board['nodes'] as $node) {
|
||
if ($node['type'] === 'start') {
|
||
$chosen[(int) $node['id']] = true; // das Startfeld ist immer offen
|
||
}
|
||
}
|
||
$at = [];
|
||
foreach ($board['nodes'] as $node) {
|
||
$at[$node['r'] . ',' . $node['c']] = (int) $node['id'];
|
||
}
|
||
$rows = array_column($board['nodes'], 'r');
|
||
$cols = array_column($board['nodes'], 'c');
|
||
$minR = min($rows);
|
||
$minC = min($cols);
|
||
$html = '<div class="gear-dv-grid" style="--cols: ' . (max($cols) - $minC + 1) . '; --rows: ' . (max($rows) - $minR + 1) . '">';
|
||
foreach ($board['nodes'] as $node) {
|
||
$html .= gear_daevanion_node_html($node, $minR, $minC, $chosen, $at, $skills, $class, false);
|
||
}
|
||
return $html . '</div>';
|
||
}
|
||
|
||
/**
|
||
* Vorschau im Dialog "Aus dem Spiel" (gear.php) als Assistent: Ausruestung, Skills, Daevanion, Uebernehmen
|
||
* (Schritte blaettert assets/js/gear.js). Alles Passende ist angehakt. Ohne die Klasse des Charakters lassen sich
|
||
* Skills, Daevanion und fremde Waffen nicht uebernehmen (gear.js sperrt sie, sobald der Klassenwechsel abgewaehlt ist).
|
||
*/
|
||
function gear_armory_preview_html(array $set, array $data): string
|
||
{
|
||
$setClass = $set['class_name'] ?: null;
|
||
$classDiffers = $data['class'] !== null && $data['class'] !== $setClass;
|
||
$class = $classDiffers ? $data['class'] : $setClass;
|
||
$plan = gear_armory_plan($data, $class);
|
||
$known = $class !== null ? gear_skills_for_class($class, false) : [];
|
||
$planBoards = [];
|
||
if ($class !== null && $class === $data['class']) {
|
||
foreach (gear_daevanion_boards($class) as $board) {
|
||
$planBoards[(int) $board['id']] = $board;
|
||
}
|
||
}
|
||
$boardSkills = $class !== null ? gear_plan_class_skills($class) : [];
|
||
$check = static fn (string $name, string $value, bool $enabled, string $extra = ''): string =>
|
||
'<input type="checkbox" class="gear-armory-check" name="' . e($name) . '" value="' . e($value) . '"'
|
||
. ($enabled ? ' checked' : ' disabled') . $extra . '>';
|
||
$needsClass = static fn (bool $needs): string => $needs ? ' data-gear-armory-needs-class' : '';
|
||
$usableSlots = count(array_filter($plan['slots'], static fn (array $row): bool => $row['problem'] === null));
|
||
|
||
ob_start(); ?>
|
||
<form method="post" action="/gear_action.php" class="gear-armory-preview" data-gear-armory-form>
|
||
<?= csrf_field() ?>
|
||
<input type="hidden" name="action" value="armory_import">
|
||
<input type="hidden" name="set_id" value="<?= (int) $set['id'] ?>">
|
||
|
||
<div class="gear-armory-hero">
|
||
<span class="gear-armory-hero-icon"><?= class_badge_html($data['class'], 44) ?></span>
|
||
<span class="gear-armory-hero-text">
|
||
<strong><?= e($data['name']) ?></strong>
|
||
<span class="text-muted"><?= e(implode(' · ', array_filter([$data['class'] ?? $data['class_label'], 'Stufe ' . $data['level'], armory_server_name($data['server_id'])]))) ?></span>
|
||
</span>
|
||
<button type="button" class="armory-text-button" data-gear-armory-back>Anderer Charakter</button>
|
||
<?php if ($classDiffers): ?>
|
||
<label class="gear-armory-switch gear-armory-class">
|
||
<?= $check('class', '1', true, ' data-gear-armory-class') ?><span class="gear-armory-switch-track" aria-hidden="true"></span>
|
||
<span>Set auf <strong><?= e($data['class']) ?></strong> umstellen<?= $setClass !== null ? ' <span class="text-muted">(bisher ' . e($setClass) . ')</span>' : '' ?>
|
||
<small class="text-muted">Ohne Klassenwechsel keine Skills, kein Daevanion<?= $setClass !== null ? ' und nur Waffen für ' . e($setClass) : '' ?>.</small></span>
|
||
</label>
|
||
<?php endif; ?>
|
||
</div>
|
||
|
||
<section class="gear-armory-panel" data-gear-armory-panel="gear">
|
||
<?php if (!$plan['slots']): ?>
|
||
<p class="gear-armory-empty"><?= $data['equipment_missing'] ? 'NCSoft hat die Ausrüstung gerade nicht geliefert – versuch es gleich noch einmal.' : 'Der Charakter trägt nichts, was der Planer kennt.' ?></p>
|
||
<?php else: ?>
|
||
<div class="gear-armory-toolbar">
|
||
<label class="gear-armory-switch"><?= $check('upgrades', '1', true) ?><span class="gear-armory-switch-track" aria-hidden="true"></span> Verzauberung & Durchbruch</label>
|
||
<label class="gear-armory-switch"><?= $check('stones', '1', true) ?><span class="gear-armory-switch-track" aria-hidden="true"></span> Manasteine & Seelenprägung</label>
|
||
<button type="button" class="armory-text-button" data-gear-armory-toggle="slots[]">Alle an/aus</button>
|
||
</div>
|
||
<div class="gear-armory-tiles">
|
||
<?php foreach (GEAR_DOLL_ORDER as $slotKey): ?>
|
||
<?php
|
||
$row = $plan['slots'][$slotKey] ?? null;
|
||
if ($row === null) {
|
||
continue;
|
||
}
|
||
$item = $row['item'];
|
||
$game = $row['game'];
|
||
$icon = gear_armory_item_icon($item, $game);
|
||
$grade = $item ? gear_grade_class($item['grade']) : armory_grade_class($game['grade']);
|
||
?>
|
||
<label class="gear-armory-tile <?= e($grade) ?><?= $row['problem'] !== null ? ' is-off' : '' ?>">
|
||
<?= $check('slots[]', $slotKey, $row['problem'] === null, $needsClass($classDiffers && $item && !gear_item_fits_class($item, $setClass))) ?>
|
||
<span class="gear-armory-tile-icon"><?php if ($icon): ?><img src="<?= e($icon) ?>" alt="" loading="lazy"><?php endif; ?>
|
||
<?php if ($game['enchant'] > 0): ?><b class="gear-armory-enchant">+<?= (int) $game['enchant'] ?></b><?php endif; ?></span>
|
||
<span class="gear-armory-tile-text">
|
||
<small class="gear-armory-tile-slot"><?= e(GEAR_SLOTS[$slotKey][0]) ?><?= $game['exceed'] > 0 ? ' · Durchbruch ' . (int) $game['exceed'] : '' ?></small>
|
||
<span class="gear-armory-tile-name"><?= e($game['name']) ?></span>
|
||
<?php if ($row['problem'] !== null): ?>
|
||
<small class="gear-armory-problem"><?= e($row['problem']) ?></small>
|
||
<?php else: ?>
|
||
<?php if ($row['soul']): ?><small class="gear-armory-stats" data-gear-armory-stones><?= e(implode(' · ', array_map('gear_soul_entry_label', $row['soul']))) ?></small><?php endif; ?>
|
||
<?php if ($row['manastones']): ?><small class="gear-armory-stones" data-gear-armory-stones><?php foreach ($row['manastones'] as [$stat, $value]): ?><i title="Manastein"><?= e($stat) ?> <?= (int) $value ?></i><?php endforeach; ?></small><?php endif; ?>
|
||
<?php if ($game['detail'] === null): ?><small class="text-muted">Manasteine/Seelenprägung fehlen bei NCSoft gerade</small><?php endif; ?>
|
||
<?php endif; ?>
|
||
</span>
|
||
</label>
|
||
<?php endforeach; ?>
|
||
</div>
|
||
<?php endif; ?>
|
||
</section>
|
||
|
||
<section class="gear-armory-panel" data-gear-armory-panel="arcana" hidden>
|
||
<?php if (!$plan['arcana']): ?>
|
||
<p class="gear-armory-empty">Der Charakter hat keine Arcana angelegt.</p>
|
||
<?php else: ?>
|
||
<div class="gear-armory-toolbar">
|
||
<span class="text-muted">Karte mit Aufwertung und den eingeprägten Skills – eine angehakte Karte ersetzt die Karte dieser Art im Set.</span>
|
||
<button type="button" class="armory-text-button" data-gear-armory-toggle="arcana[]">Alle an/aus</button>
|
||
</div>
|
||
<div class="gear-armory-tiles">
|
||
<?php foreach ($plan['arcana'] as $type => $row): ?>
|
||
<?php $game = $row['game']; $icon = armory_icon_url((string) $game['icon']); ?>
|
||
<label class="gear-armory-tile <?= e($row['card'] ? gear_grade_class($row['card']['grade']) : armory_grade_class($game['grade'])) ?><?= $row['problem'] !== null ? ' is-off' : '' ?>">
|
||
<?= $check('arcana[]', (string) $type, $row['problem'] === null) ?>
|
||
<span class="gear-armory-tile-icon"><?php if ($icon): ?><img src="<?= e($icon) ?>" alt="" loading="lazy"><?php endif; ?>
|
||
<?php if ($game['enchant'] > 0): ?><b class="gear-armory-enchant">+<?= (int) $game['enchant'] ?></b><?php endif; ?></span>
|
||
<span class="gear-armory-tile-text">
|
||
<small class="gear-armory-tile-slot"><?= e(GEAR_ARCANA_TYPES[$type] ?? 'Arcana') ?></small>
|
||
<span class="gear-armory-tile-name"><?= e($game['name']) ?></span>
|
||
<?php if ($row['problem'] !== null): ?>
|
||
<small class="gear-armory-problem"><?= e($row['problem']) ?></small>
|
||
<?php else: ?>
|
||
<?php if ($row['skills']): ?>
|
||
<small class="gear-armory-stones">
|
||
<?php foreach ($row['skills'] as $skill): ?>
|
||
<?php $known = gear_skill((int) $skill[0]); ?>
|
||
<i class="is-skill"><?= e($known ? gear_skill_display_name($known) : $skill[2]) ?> +<?= (int) $skill[1] ?></i>
|
||
<?php endforeach; ?>
|
||
</small>
|
||
<?php elseif ($game['detail'] === null): ?>
|
||
<small class="text-muted">Die Skills der Karte hat NCSoft gerade nicht geliefert</small>
|
||
<?php endif; ?>
|
||
<?php if ($row['skipped']): ?>
|
||
<small class="text-muted"><?= (int) $row['skipped'] ?> Skill<?= $row['skipped'] === 1 ? ' gehört' : 's gehören' ?> nicht zu <?= e((string) $class) ?> und fäll<?= $row['skipped'] === 1 ? 't' : 'en' ?> weg</small>
|
||
<?php endif; ?>
|
||
<?php endif; ?>
|
||
</span>
|
||
</label>
|
||
<?php endforeach; ?>
|
||
</div>
|
||
<?php endif; ?>
|
||
</section>
|
||
|
||
<section class="gear-armory-panel" data-gear-armory-panel="skills" hidden>
|
||
<?php if ($data['skills_missing']): ?>
|
||
<p class="gear-armory-empty">NCSoft hat die Skills gerade nicht geliefert – versuch es gleich noch einmal.</p>
|
||
<?php else: ?>
|
||
<?php foreach ($plan['skills'] as $kind => $group): ?>
|
||
<?php $usable = $group['problem'] === null && $group['list']; ?>
|
||
<div class="gear-armory-card<?= $usable ? '' : ' is-off' ?>">
|
||
<label class="gear-armory-switch gear-armory-card-head">
|
||
<?= $check('skills[]', $kind, $usable, $needsClass($classDiffers)) ?><span class="gear-armory-switch-track" aria-hidden="true"></span>
|
||
<strong><?= e($group['label']) ?></strong> <span class="text-muted"><?= count($group['list']) ?></span>
|
||
</label>
|
||
<?php if ($group['problem'] !== null): ?>
|
||
<p class="gear-armory-problem"><?= e(ucfirst($group['problem'])) ?></p>
|
||
<?php elseif (!$group['list']): ?>
|
||
<p class="text-muted">Keine gesteigert.</p>
|
||
<?php else: ?>
|
||
<ul class="gear-armory-chips">
|
||
<?php foreach ($group['list'] as $skill): ?>
|
||
<?php $icon = gear_armory_skill_icon($skill, $known); ?>
|
||
<li><?php if ($icon): ?><img src="<?= e($icon) ?>" alt="" loading="lazy"><?php endif; ?><span><?= e($skill['name']) ?></span><b><?= (int) $skill['level'] ?></b></li>
|
||
<?php endforeach; ?>
|
||
</ul>
|
||
<?php endif; ?>
|
||
<?php if ($group['unknown']): ?>
|
||
<p class="text-muted gear-armory-note"><?= (int) $group['unknown'] ?> weitere kennt der Planer (noch) nicht.</p>
|
||
<?php endif; ?>
|
||
</div>
|
||
<?php endforeach; ?>
|
||
<p class="field-hint">Die Zahl ist die Stufe im Spiel samt Boni aus Daevanion, Arcana und Seelenprägung – ins Set kommt die selbst gesteigerte Stufe. Eine angehakte Art ersetzt die geplanten Skills dieser Art; Spezialisierungen bleiben, soweit die Stufe reicht.</p>
|
||
<?php endif; ?>
|
||
</section>
|
||
|
||
<section class="gear-armory-panel" data-gear-armory-panel="daevanion" hidden>
|
||
<?php if (!$plan['boards']): ?>
|
||
<p class="gear-armory-empty">Keine freigeschalteten Daevanion-Felder.</p>
|
||
<?php else: ?>
|
||
<div class="gear-armory-boards">
|
||
<?php foreach ($plan['boards'] as $boardId => $board): ?>
|
||
<?php $planBoard = $planBoards[$boardId] ?? null; ?>
|
||
<div class="gear-armory-card gear-armory-board<?= $board['problem'] === null ? '' : ' is-off' ?>">
|
||
<label class="gear-armory-switch gear-armory-card-head">
|
||
<?= $check('boards[]', (string) $boardId, $board['problem'] === null, $needsClass($classDiffers)) ?><span class="gear-armory-switch-track" aria-hidden="true"></span>
|
||
<strong><?= e($board['name']) ?></strong>
|
||
<span class="text-muted"><?= $planBoard ? count($board['nodes']) . '/' . (count(array_filter($planBoard['nodes'], static fn (array $n): bool => $n['type'] !== 'start'))) : (int) $board['open'] ?> Felder</span>
|
||
</label>
|
||
<?php if ($planBoard && $board['nodes']): ?>
|
||
<?= gear_armory_board_html($planBoard, $board['nodes'], $boardSkills, (string) $class) ?>
|
||
<?php endif; ?>
|
||
<?php if ($board['problem'] !== null): ?><p class="gear-armory-problem"><?= e(ucfirst($board['problem'])) ?></p><?php endif; ?>
|
||
</div>
|
||
<?php endforeach; ?>
|
||
</div>
|
||
<?php endif; ?>
|
||
</section>
|
||
|
||
<section class="gear-armory-panel" data-gear-armory-panel="summary" hidden>
|
||
<p class="gear-armory-summary-lead">Das kommt ins Set „<?= e($set['name']) ?>“:</p>
|
||
<ul class="gear-armory-summary" data-gear-armory-summary></ul>
|
||
<p class="field-hint">Angehakte Teile ersetzen, was im Set steht – alles andere bleibt, wie es ist.</p>
|
||
</section>
|
||
|
||
<div class="gear-armory-nav">
|
||
<button type="button" class="button button-secondary" data-gear-armory-prev>Zurück</button>
|
||
<span class="gear-armory-nav-info text-muted" data-gear-armory-info><?= $usableSlots ?>/<?= count($plan['slots']) ?> Slots übernehmbar</span>
|
||
<button type="button" class="button" data-gear-armory-next>Weiter</button>
|
||
<button type="submit" class="button" data-gear-armory-submit hidden>Ins Set übernehmen</button>
|
||
</div>
|
||
</form>
|
||
<?php
|
||
return (string) ob_get_clean();
|
||
}
|