Skip to content

Open-source download manager & offline media toolbox for YouTube, music, social media, learning platforms & 1,800+ sites. Built with Tauri 2.0, Rust & Svelte.

feat(league): item build derived from local match history

tonhowtf94db10e500f5
diff --git a/src-tauri/src/commands/league/mod.rs b/src-tauri/src/commands/league/mod.rs
index 406f9b14..0de5d8f8 100644
--- a/src-tauri/src/commands/league/mod.rs
+++ b/src-tauri/src/commands/league/mod.rs
@@ -1970,6 +1970,153 @@ pub async fn league_champion_tiers(
Ok(json!({ "region": region, "bracket": bracket, "champions": entries }))
}
+/// Item build for a champion, derived from games this client can actually see.
+///
+/// Third-party build sites either forbid third-party use of their API or ask
+/// crawlers to stay out, and Riot's own `recommended` blocks ship empty, so the
+/// sample here is the player's own recent matches: every participant on that
+/// champion across those games contributes their finished items. The response
+/// always reports how many games backed it so a thin sample is obvious.
+#[tauri::command]
+pub async fn league_champion_build(
+ champion_id: i64,
+ sample: Option<u32>,
+) -> Result<Value, String> {
+ ensure_enabled()?;
+ if champion_id <= 0 {
+ return Err("invalid champion".to_string());
+ }
+ let client = get_client().await?;
+ let me = lcu_get_raw(&client, "/lol-summoner/v1/current-summoner").await?;
+ let my_puuid = me
+ .get("puuid")
+ .and_then(Value::as_str)
+ .unwrap_or("")
+ .to_string();
+ let count = sample.unwrap_or(20).clamp(5, 40);
+ let history = lcu_get_raw(
+ &client,
+ &format!(
+ "/lol-match-history/v1/products/lol/{}/matches?begIndex=0&endIndex={}",
+ my_puuid,
+ count.saturating_sub(1)
+ ),
+ )
+ .await?;
+ let game_ids: Vec<i64> = history
+ .get("games")
+ .and_then(|g| g.get("games"))
+ .and_then(Value::as_array)
+ .map(|arr| {
+ arr.iter()
+ .filter_map(|g| g.get("gameId").and_then(Value::as_i64))
+ .collect()
+ })
+ .unwrap_or_default();
+
+ let mut tasks = Vec::new();
+ for game_id in game_ids {
+ let task_client = client.clone();
+ tasks.push(tauri::async_runtime::spawn(async move {
+ lcu_get_raw(
+ &task_client,
+ &format!("/lol-match-history/v1/games/{}", game_id),
+ )
+ .await
+ .ok()
+ }));
+ }
+
+ // (games seen, games won) per item and per summoner-spell pair.
+ let mut items: std::collections::HashMap<i64, (u32, u32)> = std::collections::HashMap::new();
+ let mut spells: std::collections::HashMap<(i64, i64), (u32, u32)> =
+ std::collections::HashMap::new();
+ let mut seen = 0u32;
+ let mut wins = 0u32;
+
+ for task in tasks {
+ let detail = match task.await {
+ Ok(Some(d)) => d,
+ _ => continue,
+ };
+ let participants = detail
+ .get("participants")
+ .and_then(Value::as_array)
+ .cloned()
+ .unwrap_or_default();
+ for p in &participants {
+ if p.get("championId").and_then(Value::as_i64) != Some(champion_id) {
+ continue;
+ }
+ let stats = p.get("stats").cloned().unwrap_or(Value::Null);
+ let won = stats.get("win").and_then(Value::as_bool).unwrap_or(false);
+ seen += 1;
+ if won {
+ wins += 1;
+ }
+ // Slot 6 is the trinket, which is not part of a build.
+ for slot in 0..6 {
+ let item = stats
+ .get(format!("item{}", slot))
+ .and_then(Value::as_i64)
+ .unwrap_or(0);
+ if item > 0 {
+ let e = items.entry(item).or_insert((0, 0));
+ e.0 += 1;
+ if won {
+ e.1 += 1;
+ }
+ }
+ }
+ let s1 = p.get("spell1Id").and_then(Value::as_i64).unwrap_or(0);
+ let s2 = p.get("spell2Id").and_then(Value::as_i64).unwrap_or(0);
+ if s1 > 0 && s2 > 0 {
+ let key = if s1 <= s2 { (s1, s2) } else { (s2, s1) };
+ let e = spells.entry(key).or_insert((0, 0));
+ e.0 += 1;
+ if won {
+ e.1 += 1;
+ }
+ }
+ }
+ }
+
+ let mut item_rows: Vec<(i64, u32, u32)> =
+ items.into_iter().map(|(id, (g, w))| (id, g, w)).collect();
+ item_rows.sort_by(|a, b| b.1.cmp(&a.1).then(b.2.cmp(&a.2)));
+ let core: Vec<Value> = item_rows
+ .iter()
+ .take(8)
+ .map(|(id, games, wins)| {
+ json!({
+ "itemId": id,
+ "games": games,
+ "wins": wins,
+ "pickRate": if seen > 0 { ((*games as f64 / seen as f64) * 1000.0).round() / 10.0 } else { 0.0 },
+ })
+ })
+ .collect();
+
+ let mut spell_rows: Vec<((i64, i64), u32, u32)> =
+ spells.into_iter().map(|(k, (g, w))| (k, g, w)).collect();
+ spell_rows.sort_by(|a, b| b.1.cmp(&a.1));
+ let spell_list: Vec<Value> = spell_rows
+ .iter()
+ .take(2)
+ .map(|((a, b), games, _)| json!({ "spellIds": [a, b], "games": games }))
+ .collect();
+
+ Ok(json!({
+ "championId": champion_id,
+ "gamesSeen": seen,
+ "wins": wins,
+ "winrate": if seen > 0 { ((wins as f64 / seen as f64) * 1000.0).round() / 10.0 } else { 0.0 },
+ "items": core,
+ "spells": spell_list,
+ "source": "local-history",
+ }))
+}
+
#[tauri::command]
pub async fn league_auto_accept_set(enabled: bool) -> Result<(), String> {
ensure_enabled()?;
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs
index ea1c5080..6f80939e 100644
--- a/src-tauri/src/lib.rs
+++ b/src-tauri/src/lib.rs
@@ -733,6 +733,7 @@ pub fn run() {
commands::league::league_send_chat,
commands::league::league_rune_recommendations,
commands::league::league_champion_tiers,
+ commands::league::league_champion_build,
commands::bilibili_auth::bilibili_qr_generate,
commands::bilibili_auth::bilibili_qr_poll,
commands::bilibili_auth::bilibili_captcha_challenge,
diff --git a/src/lib/i18n/el.json b/src/lib/i18n/el.json
index 017a4435..de1e90a1 100644
--- a/src/lib/i18n/el.json
+++ b/src/lib/i18n/el.json
@@ -37,6 +37,11 @@
"nav_downloads": "Μετάβαση στις Λήψεις"
},
"league": {
+ "build_title": "Build αντικειμένων",
+ "build_desc": "Υπολογίζεται από τους αγώνες αυτού του ήρωα μέσα στο δικό σου πρόσφατο ιστορικό — χωρίς site build τρίτων, οπότε το δείγμα είναι μικρό και δηλώνεται.",
+ "build_champion": "Διάλεξε ήρωα",
+ "build_samples": "αγώνες",
+ "build_empty": "Δεν υπάρχουν ακόμα αγώνες με αυτόν τον ήρωα στο δείγμα.",
"tab_meta": "Μέτα",
"runes_title": "Runes",
"runes_desc": "Σελίδες runes και summoner spells που προτείνει ο ίδιος ο client του παιχνιδιού για τον ήρωα που κλείδωσες, πάντα στο τρέχον patch.",
diff --git a/src/lib/i18n/en.json b/src/lib/i18n/en.json
index 303b2922..6a1e9eb2 100644
--- a/src/lib/i18n/en.json
+++ b/src/lib/i18n/en.json
@@ -37,6 +37,11 @@
"nav_downloads": "Go to Downloads"
},
"league": {
+ "build_title": "Item build",
+ "build_desc": "Built from the champion's games inside your own recent matches — no third-party build site involved, so the sample is small and honest about it.",
+ "build_champion": "Pick a champion",
+ "build_samples": "games seen",
+ "build_empty": "No games with this champion in the sample yet.",
"tab_meta": "Meta",
"runes_title": "Runes",
"runes_desc": "Rune pages and summoner spells recommended by the game client itself for the champion you locked, so they always match the current patch.",
diff --git a/src/lib/i18n/es.json b/src/lib/i18n/es.json
index 3f2ac6b7..171c2054 100644
--- a/src/lib/i18n/es.json
+++ b/src/lib/i18n/es.json
@@ -37,6 +37,11 @@
"nav_downloads": "Ir a Descargas"
},
"league": {
+ "build_title": "Build de objetos",
+ "build_desc": "Construida con las partidas de ese campeón dentro de tu propio historial reciente — sin sitios de builds de terceros, así que la muestra es pequeña y se indica.",
+ "build_champion": "Elige un campeón",
+ "build_samples": "partidas vistas",
+ "build_empty": "Aún no hay partidas con este campeón en la muestra.",
"tab_meta": "Meta",
"runes_title": "Runas",
"runes_desc": "Páginas de runas y hechizos recomendados por el propio cliente del juego para el campeón que bloqueaste, siempre del parche actual.",
diff --git a/src/lib/i18n/fr.json b/src/lib/i18n/fr.json
index 3b043ba6..1b970c67 100644
--- a/src/lib/i18n/fr.json
+++ b/src/lib/i18n/fr.json
@@ -37,6 +37,11 @@
"nav_downloads": "Aller aux Téléchargements"
},
"league": {
+ "build_title": "Build d'objets",
+ "build_desc": "Construite à partir des parties de ce champion dans votre propre historique récent — sans site de build tiers, donc l'échantillon est petit et annoncé comme tel.",
+ "build_champion": "Choisir un champion",
+ "build_samples": "parties vues",
+ "build_empty": "Aucune partie avec ce champion dans l'échantillon.",
"tab_meta": "Méta",
"runes_title": "Runes",
"runes_desc": "Pages de runes et sorts recommandés par le client du jeu lui-même pour le champion verrouillé, toujours au patch actuel.",
diff --git a/src/lib/i18n/it.json b/src/lib/i18n/it.json
index 4a92e1a7..f27a8d50 100644
--- a/src/lib/i18n/it.json
+++ b/src/lib/i18n/it.json
@@ -37,6 +37,11 @@
"nav_downloads": "Vai ai Download"
},
"league": {
+ "build_title": "Build di oggetti",
+ "build_desc": "Costruita dalle partite di quel campione nella tua cronologia recente — nessun sito di build di terze parti, quindi il campione è piccolo e dichiarato.",
+ "build_champion": "Scegli un campione",
+ "build_samples": "partite viste",
+ "build_empty": "Nessuna partita con questo campione nel campione.",
"tab_meta": "Meta",
"runes_title": "Rune",
"runes_desc": "Pagine rune e incantesimi consigliati dal client del gioco per il campione bloccato, sempre alla patch corrente.",
diff --git a/src/lib/i18n/ja.json b/src/lib/i18n/ja.json
index d3f5b09d..8e0b4aaf 100644
--- a/src/lib/i18n/ja.json
+++ b/src/lib/i18n/ja.json
@@ -37,6 +37,11 @@
"nav_downloads": "ダウンロードへ移動"
},
"league": {
+ "build_title": "アイテムビルド",
+ "build_desc": "あなた自身の直近の試合に含まれるそのチャンピオンの試合から算出。外部ビルドサイトは使っていないため、サンプルは小さくその旨を明示します。",
+ "build_champion": "チャンピオンを選択",
+ "build_samples": "試合を参照",
+ "build_empty": "サンプル内にこのチャンピオンの試合がまだありません。",
"tab_meta": "メタ",
"runes_title": "ルーン",
"runes_desc": "ロックしたチャンピオン向けにゲームクライアント自身が推奨するルーンページとサモナースペル。常に現行パッチ準拠です。",
diff --git a/src/lib/i18n/keys.ts b/src/lib/i18n/keys.ts
index 22628d55..9bcc22f4 100644
--- a/src/lib/i18n/keys.ts
+++ b/src/lib/i18n/keys.ts
@@ -376,6 +376,11 @@ export type TranslationKeys =
| 'league.automation_title'
| 'league.ban_list'
| 'league.bench_title'
+ | 'league.build_champion'
+ | 'league.build_desc'
+ | 'league.build_empty'
+ | 'league.build_samples'
+ | 'league.build_title'
| 'league.champ_select_title'
| 'league.chat_build'
| 'league.chat_placeholder'
diff --git a/src/lib/i18n/pt.json b/src/lib/i18n/pt.json
index 7fc21ec1..bab23fcf 100644
--- a/src/lib/i18n/pt.json
+++ b/src/lib/i18n/pt.json
@@ -37,6 +37,11 @@
"nav_downloads": "Ir para Downloads"
},
"league": {
+ "build_title": "Build de itens",
+ "build_desc": "Montada a partir das partidas desse campeão dentro do seu próprio histórico recente — sem site de build de terceiros, então a amostra é pequena e assumida como tal.",
+ "build_champion": "Escolha um campeão",
+ "build_samples": "partidas vistas",
+ "build_empty": "Nenhuma partida com esse campeão na amostra ainda.",
"tab_meta": "Meta",
"runes_title": "Runas",
"runes_desc": "Páginas de runas e feitiços recomendados pelo próprio cliente do jogo para o campeão que você travou, sempre no patch atual.",
diff --git a/src/lib/i18n/ru.json b/src/lib/i18n/ru.json
index 774773c6..474af3ba 100644
--- a/src/lib/i18n/ru.json
+++ b/src/lib/i18n/ru.json
@@ -37,6 +37,11 @@
"nav_downloads": "Перейти к загрузкам"
},
"league": {
+ "build_title": "Сборка предметов",
+ "build_desc": "Собрана по играм этого чемпиона в вашей недавней истории — без сторонних сайтов сборок, поэтому выборка мала и это указано честно.",
+ "build_champion": "Выберите чемпиона",
+ "build_samples": "игр учтено",
+ "build_empty": "Игр с этим чемпионом в выборке пока нет.",
"tab_meta": "Мета",
"runes_title": "Руны",
"runes_desc": "Страницы рун и заклинания, рекомендованные самим клиентом игры для выбранного чемпиона — всегда для текущего патча.",
diff --git a/src/lib/i18n/zh-TW.json b/src/lib/i18n/zh-TW.json
index 6c96835c..6b29d087 100644
--- a/src/lib/i18n/zh-TW.json
+++ b/src/lib/i18n/zh-TW.json
@@ -37,6 +37,11 @@
"nav_downloads": "前往下載"
},
"league": {
+ "build_title": "出裝",
+ "build_desc": "根據你自己近期對戰中該英雄的出裝統計得出——不使用第三方出裝網站,因此樣本較小且如實標註。",
+ "build_champion": "選擇英雄",
+ "build_samples": "場對戰",
+ "build_empty": "樣本中還沒有該英雄的對戰。",
"tab_meta": "版本",
"runes_title": "符文",
"runes_desc": "由遊戲客戶端本身為你鎖定的英雄推薦的符文頁與召喚師技能,始終對應目前版本。",
diff --git a/src/lib/i18n/zh.json b/src/lib/i18n/zh.json
index f2b7941c..10a05570 100644
--- a/src/lib/i18n/zh.json
+++ b/src/lib/i18n/zh.json
@@ -37,6 +37,11 @@
"nav_downloads": "前往下载"
},
"league": {
+ "build_title": "出装",
+ "build_desc": "根据你自己近期对局中该英雄的出装统计得出——不使用第三方出装网站,因此样本较小且如实标注。",
+ "build_champion": "选择英雄",
+ "build_samples": "场对局",
+ "build_empty": "样本中还没有该英雄的对局。",
"tab_meta": "版本",
"runes_title": "符文",
"runes_desc": "由游戏客户端本身为你锁定的英雄推荐的符文页与召唤师技能,始终对应当前版本。",
diff --git a/src/routes/league/+page.svelte b/src/routes/league/+page.svelte
index d480b572..459399e7 100644
--- a/src/routes/league/+page.svelte
+++ b/src/routes/league/+page.svelte
@@ -458,6 +458,22 @@
}
});
+ let buildChampionId = $state<number>(0);
+ let buildInfo = $state<any>(null);
+ let buildLoading = $state(false);
+
+ async function loadBuild(championId: number) {
+ if (championId <= 0 || buildLoading) return;
+ buildLoading = true;
+ try {
+ buildInfo = await invoke<any>("league_champion_build", { championId, sample: 20 });
+ } catch {
+ buildInfo = null;
+ } finally {
+ buildLoading = false;
+ }
+ }
+
const PHASE_KEYS: Record<string, string> = {
Lobby: "league.phase_lobby",
Matchmaking: "league.phase_matchmaking",
@@ -1070,6 +1086,44 @@
{/if}
</section>
+ <section class="card">
+ <div class="card-head">
+ <h3>{$t("league.build_title")}</h3>
+ <button
+ class="button"
+ onclick={() => loadBuild(champSelectChampionId || (buildChampionId ?? 0))}
+ disabled={buildLoading || (!champSelectChampionId && !buildChampionId)}
+ >{$t("league.refresh")}</button>
+ </div>
+ <p class="win-disclaimer">{$t("league.build_desc")}</p>
+ <div class="build-picker">
+ <select class="select-role" bind:value={buildChampionId} aria-label={$t("league.build_champion") as string}>
+ <option value={0}>{$t("league.build_champion")}</option>
+ {#each champions as ch (ch.id)}
+ <option value={ch.id}>{ch.name}</option>
+ {/each}
+ </select>
+ </div>
+ {#if buildInfo && buildInfo.gamesSeen > 0}
+ <p class="win-note">
+ {buildInfo.gamesSeen} {$t("league.build_samples")} · {buildInfo.winrate}% {$t("league.stat_winrate")}
+ </p>
+ <div class="build-items">
+ {#each buildInfo.items as it (it.itemId)}
+ <span class="build-item">
+ <img class="item-icon" src={`${CDRAGON}/../../game/assets/items/icons2d/${it.itemId}.png`} alt="" loading="lazy" onerror={(e) => { (e.currentTarget as HTMLImageElement).style.visibility = "hidden"; }} />
+ <span class="dim">{it.pickRate}%</span>
+ </span>
+ {/each}
+ </div>
+ {#if buildInfo.spells?.length}
+ <p class="win-note">{$t("league.runes_spells")}: {buildInfo.spells.map((s: any) => s.spellIds.map(spellName).join(" + ")).join(" / ")}</p>
+ {/if}
+ {:else if buildInfo}
+ <p class="empty-hint">{$t("league.build_empty")}</p>
+ {/if}
+ </section>
+
<section class="card">
<div class="card-head">
<h3>{$t("league.tiers_title")}</h3>
@@ -2399,6 +2453,32 @@
color: var(--text);
}
+ .build-picker {
+ margin: 8px 0;
+ }
+
+ .build-items {
+ display: flex;
+ gap: 8px;
+ flex-wrap: wrap;
+ margin: 8px 0;
+ }
+
+ .build-item {
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ gap: 2px;
+ font-size: 10.5px;
+ }
+
+ .item-icon {
+ width: 34px;
+ height: 34px;
+ border-radius: 6px;
+ background: var(--button);
+ }
+
.scout-teams {
display: grid;
grid-template-columns: 1fr 1fr;