public override async Task <Champion[]> GetCountersFor(int championId, Position position, int maxCount = 5) { var doc = new HtmlDocument(); doc.LoadHtml(await WebCache.String(await GetChampionURL(championId), soft: true)); return(await doc.DocumentNode .QuerySelectorAll(".row._yq1p7n._cu8r22._gzehfc") .ElementAt(1) .QuerySelectorAll("img") .Select(o => { var imgUrl = o.GetAttributeValue("src", ""); if (string.IsNullOrEmpty(imgUrl)) { return null; } var champKey = Path.GetFileNameWithoutExtension(new Uri(imgUrl).Segments.ArrayLast()); return Riot.GetChampionAsync(champKey); }) .Where(o => o != null) .Take(maxCount) .ToArray() .AwaitAll()); }
public override async Task <Champion[]> GetCountersFor(int championId, Position position, int maxCount = 5) { var json = JObject.Parse(await WebCache.String($"https://stats2.u.gg/lol/{UGGApiVersion}/matchups/{await GetLolUGGVersion()}/ranked_solo_5x5/{championId}/{UGGOverviewVersion}.json")); var ret = await Task.WhenAll(json["1"]["1"][IdToPosition.Invert()[position].ToString()][0] .Take(maxCount) .Select(o => Riot.GetChampionAsync(o[0].Value <int>())).ToArray()); return(ret); }
public override async Task <Champion[]> GetCountersFor(int championId, Position position, int maxCount = 5) { var doc = new HtmlDocument(); doc.LoadHtml(await WebCache.String(GetRoleUrl(championId, position), soft: false)); var rows = doc.DocumentNode.QuerySelectorAll(".champion-stats-header-matchup__table--strong > tbody > tr"); var ids = rows.Select(o => o.GetAttributeValue("data-champion-id", 0)); var champs = new List <Champion>(); foreach (var item in ids.Take(maxCount)) { champs.Add(await Riot.GetChampionAsync(item)); } return(champs.ToArray()); }
private async Task UpdateTeam(LolChampSelectChampSelectSession data) { int[] team = data.theirTeam.Select(o => o.championId).ToArray(); if (PreviousTeam != null && team.SequenceEqual(PreviousTeam)) { return; } var myPosition = data.myTeam.Single(o => o.cellId == data.localPlayerCellId).assignedPosition.ToPosition(); var guessedPositions = Guesser.Guess(team.Where(o => o != 0).ToArray()); for (int i = EnemySummoners.Count; i < team.Length; i++) { EnemySummoners.Add(null); } for (int i = 0; i < team.Length; i++) { var theirChamp = team[i]; if (theirChamp != 0) { var enemyPosition = guessedPositions.Invert()[theirChamp]; EnemySummoners[i] = new Enemy( await Riot.GetChampionAsync(theirChamp), await new METAsrcProvider().GetCountersFor(theirChamp, Position.Fill), null, enemyPosition.ToString().ToUpper(), enemyPosition == myPosition); } } PreviousTeam = team; }
private async Task <string> GetChampionURL(int championId, Position?pos = null) => $"https://www.metasrc.com/5v5/champion/{(await Riot.GetChampionAsync(championId)).Key}/{(pos == null ? null : PositionNames[pos.Value])}";