Last active
November 29, 2022 13:54
-
-
Save mikaeldui/e1ac083696424b6ac6c0173ba67a25ec to your computer and use it in GitHub Desktop.
Show enemy details in League of Legends champ select
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Net.Http.Json; | |
using System.Text; | |
using System.Threading.Tasks; | |
internal class DataDragonClient : IDisposable | |
{ | |
private HttpClient _client; | |
public DataDragonClient() | |
{ | |
_client= new HttpClient(); | |
} | |
public async Task<DataDragonChampion[]> GetChampionFullAsync() | |
{ | |
var result = await _client.GetFromJsonAsync<DataDragonData<Dictionary<string, DataDragonChampion>>>( | |
"https://ddragon.leagueoflegends.com/cdn/12.22.1/data/en_US/championFull.json"); | |
return result!.Data.Values.ToArray(); | |
} | |
public void Dispose() | |
{ | |
((IDisposable)_client).Dispose(); | |
} | |
} | |
internal class DataDragonData<TData> | |
{ | |
public string Type { get; set; } | |
public string Format { get; set; } | |
public string Version { get; set; } | |
public TData Data { get; set; } | |
} | |
internal class DataDragonChampion | |
{ | |
public string Id { get; set; } | |
public string Key { get; set; } | |
public string Name { get; set; } | |
public DataDragonSkin[] Skins { get; set; } | |
} | |
public class DataDragonSkin | |
{ | |
public string Id { get; set; } | |
public string Name { get; set; } | |
public bool Chromas { get; set; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using MikaelDui.RiotGames.LeagueOfLegends.ChampSelect.Session.Watcher; | |
using DataDragonClient dd = new(); | |
DataDragonChampion[] champions = await dd.GetChampionFullAsync(); | |
Console.WriteLine($"Loaded {champions.Count()} champions with {champions.SelectMany(c => c.Skins).Count()} skins."); | |
global::RiotGames.LeagueOfLegends.LeagueClient.LeagueClient client = new global::RiotGames.LeagueOfLegends.LeagueClient.LeagueClient(); | |
client.LeagueOfLegends.ChampSelect.SessionChanged += ChampSelect_SessionChanged; | |
Console.ReadKey(); | |
void ChampSelect_SessionChanged(object sender, global::RiotGames.LeagueOfLegends.LeagueClient.LeagueClientEventArgs<global::RiotGames.LeagueOfLegends.LeagueClient.LolChampSelectChampSelectSession> args) | |
{ | |
Console.Clear(); | |
foreach(var enemy in args.Data.TheirTeam) | |
{ | |
if (enemy.SelectedSkinId== 0) | |
Console.WriteLine($"Enemy {enemy.CellId}"); | |
else | |
Console.WriteLine($"Enemy {enemy.CellId}: {champions.Single(c => c.Key == enemy.ChampionId.ToString()).Name} ({champions.SelectMany(c => c.Skins).Single(s => s.Id == enemy.SelectedSkinId.ToString()).Name})"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment