public async Task <bool> CheckIfPlaysChampion(Region region, string summonerName, string championName) { Summoner summoner = await GetSummonerByName(region, summonerName); if (summoner is null) { return(false); } CurrentGame match = await GetCurrentMatchId(region, summoner.Id); if (match is null) { return(false); } CurrentGameParticipant participant = match.Participants.SingleOrDefault(x => x.SummonerId == summoner.Id); Champions.TryGetValue(championName, out long championId); if (participant.ChampionId == championId) { return(true); } return(false); }
public LiveGame(object accountId) { HttpClient client = new HttpClient(); var t = client.GetAsync($"https://na1.api.riotgames.com/lol/spectator/v4/active-games/by-summoner/{accountId}?api_key={API.apiKey}"); HttpResponseMessage response = t.Result; if (response.Content.ToString().Contains("404")) { live = false; } else { dynamic liveGameJson = JObject.Parse(t.Result.Content.ReadAsStringAsync().Result.ToString()); dynamic currentParticipantsJson = JArray.Parse(liveGameJson.participants.ToString()); List <GameCustomizationObject> gameCustomizationObjects = new List <GameCustomizationObject>(); foreach (var participant in currentParticipantsJson) { dynamic participantGameCusomizationObjectsJson = JArray.Parse(participant.gameCustomizationObjects.ToString()); foreach (var gameCustomizaionObjectJson in participantGameCusomizationObjectsJson) { GameCustomizationObject gameCustomizationObject = new GameCustomizationObject(gameCustomizaionObjectJson.category.Value.ToString(), gameCustomizaionObjectJson.content.Value.ToString()); gameCustomizationObjects.Add(gameCustomizationObject); } CurrentGameParticipant currentGameParticipant = new CurrentGameParticipant(participant.summonerName.Value.ToString(), participant.championId.Value.ToString(), participant.summonerId.Value.ToString(), gameCustomizationObjects); currentGameParticipants.Add(currentGameParticipant); } dynamic bannedChampionsJson = JArray.Parse(liveGameJson.bannedChampions.ToString()); foreach (var ban in bannedChampionsJson) { BannedChampion bannedChampion = new BannedChampion(ban.championId.Value.ToString(), ban.teamId.Value.ToString(), (Int32)ban.pickTurn.Value); bannedChampions.Add(bannedChampion); } live = true; } }
public JogadorPartidaAtual(EstatisticasJogador estatisticasJogador, CurrentGameParticipant participante, bool aliado, ChampionListStatic campeoes, string versao, bool jogadorPrincipal = false) { var campeao = campeoes .Champions .FirstOrDefault(c => c.Value.Id == participante.ChampionId).Value; decimal taxaVitoria = estatisticasJogador.CampeoesXTaxaVitoria?.FirstOrDefault(x => x.ID == participante.ChampionId)?.TaxaVitoria ?? 0; IconeCampeao = Util.RetornarIconeCampeao(versao, campeao); Nome = estatisticasJogador.Nome; Campeao = campeao.Name; Divisao = estatisticasJogador.Elo; ChanceVitoria = taxaVitoria; LanePrincipal = estatisticasJogador.Lanes?.OrderByDescending(x => x.PercentualUtilizacao).FirstOrDefault()?.Descricao ?? "Sem lane principal"; ConfiabilidadePericulosidade = CalculaConfiabilidadePericulosidade(taxaVitoria, aliado); var idCampeaoPrincipal = estatisticasJogador.CampeoesXTaxaVitoria.OrderByDescending(x => x.PartidasTotais).FirstOrDefault()?.ID; if (idCampeaoPrincipal.HasValue) { CampeaoPrincipal = campeoes .Champions .FirstOrDefault(c => c.Value.Id == idCampeaoPrincipal).Value?.Name ?? "Sem campeão principal"; } else { CampeaoPrincipal = "Sem campeão principal"; } JogadorPrincipal = jogadorPrincipal; Participante = participante; TaxaPrimeiroBarao = estatisticasJogador.TaxaPrimeiroBarao; TaxaFirstBlood = estatisticasJogador.TaxaFirstBlood; }