public static CurrentGameInfo GetCurrentGameBySummonerId(long id, string platform) { Logger.Instance.WriteLog(string.Format("Get current game for summoner id {0} in {1}", id, platform)); CurrentGameInfo result = Request.GetData(platform, String.Format("observer-mode/rest/consumer/getSpectatorGameInfo/{0}/{1}?", platform.ToUpperInvariant(), id), typeof(CurrentGameInfo)); return(result); }
internal List <string> GenerateKeyList(CurrentGameInfo CGI) { string SymbolToAdd; for (var x = 0; x < CGI.PlayerSolution.Count; x++) { if (CGI.Solution.Any(y => y.Equals(CGI.PlayerSolution[x]))) { SymbolToAdd = "-"; if (CGI.PlayerSolution[x] == CGI.Solution[x]) { SymbolToAdd = "+"; } } else { SymbolToAdd = " "; } CGI.KeyList.Add(SymbolToAdd); } return(CGI.KeyList); }
private async void GetInGameData(Friend friend) { long summonerId = ChatUtils.GetSummonerId(friend.User); CurrentGameInfo game = null; while (friend.Status?.GameStatus == GameStatus.inGame) { try { game = await Session.RiotAPI.CurrentGameAPI.BySummoner(summonerId); } catch { // ignored } if (game?.gameMode != null) { friend.OnGame(game); OnStatus(friend); } if (game != null && game.gameStartTime > 0) { break; } await Task.Delay(20 * 1000); } }
static void Cmd() { string cmd = Console.ReadLine(); if (cmd.StartsWith("getCurGame")) { string[] pieces = cmd.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); if (pieces.Length == 2) { string ID = pieces[1]; SummonerDto Chuvak = GetData.GetSummonerByName(ID); if (Chuvak == null) { Out("Cant find that dude", ConsoleColor.DarkYellow); } else { CurrentGameInfo Data = GetData.GetCurrentGameInfo(Chuvak.id.ToString()); if (Data == null) { Out("Cant find game", ConsoleColor.DarkYellow); } else { Out(Data.gameMode + " " + Data.gameType, ConsoleColor.DarkCyan); foreach (CurrentGameParticipant Chelik in Data.participants) { if (Chelik.summonerId == Chuvak.id) { try { Static.ChampionDto Champ = GetData.GetChampById(Chelik.championId.ToString()); Static.TempRune Rune = RitoPls.OfflineData.OfflineData.GetRune(Chelik.perks.perkIds[0]); Out(Champ.name + " with " + Rune.name, ConsoleColor.DarkGreen); } catch (Exception e) { Out(@"\\\\\ Exception \\\\\", ConsoleColor.DarkGray); Out(e.ToString()); Out(@"/////////////////////", ConsoleColor.DarkGray); break; } break; } } } } } else { Ebanuty(); } } else { Ebanuty(); } Cmd(); }
//Get current game information for the given summoner ID public async Task <CurrentGameInfo> GetCurrentGameAsync(long summonerID) { CurrentGameInfo current = null; string request = "/lol/spectator/" + SP_VERSION + "/active-games/by-summoner/" + summonerID; string response = await GET(request); current = JsonConvert.DeserializeObject <CurrentGameInfo>(response); return(current); }
private long[] GetChampionIDsFromCurrentGame(CurrentGameInfo spectators) { int playerCount = spectators.Participants.Length; long[] championIds = new long[playerCount]; for (int i = 0; i < playerCount; ++i) { championIds[i] = spectators.Participants[i].ChampionId; } return(championIds); }
public CurrentGameInfo GetStartModel() { CurrentGameInfo CGI = new CurrentGameInfo(); CGI.Solution = GetSolution(); CGI.PlayerSolution = new List <int>(); CGI.KeyList = new List <string>(); CGI.Tries = 10; return(CGI); }
public async Task ingame(string target) { await Context.Channel.TriggerTypingAsync(); Summoner targetSumm = null; CurrentGameInfo runningGame = null; try { targetSumm = await _rapi.RAPI.SummonerV4.GetBySummonerNameAsync(Region.NA, target) ?? throw new InvalidDataException(); runningGame = await _rapi.RAPI.SpectatorV4.GetCurrentGameInfoBySummonerAsync(Region.NA, targetSumm.Id) ?? throw new InvalidOperationException(); } catch (InvalidDataException) { await ReplyAsync($"{target} not found!"); return; } catch (InvalidOperationException) { await ReplyAsync($"{target} not currently in a game!"); return; } List <EmbedFieldBuilder> fields = new List <EmbedFieldBuilder>(); for (int i = 0; i < runningGame.Participants.Length; i++) { EmbedFieldBuilder field = new EmbedFieldBuilder(); field.IsInline = true; field.Name = $"{(runningGame.Participants[i].TeamId == 100 ? ":small_red_triangle:" : ":small_blue_diamond:")}{((Champion)runningGame.Participants[i].ChampionId).Name()}"; field.Value = $"{runningGame.Participants[i].SummonerName}\n"; LeaguePosition[] positions = await _rapi.RAPI.LeagueV4.GetAllLeaguePositionsForSummonerAsync(Region.NA, runningGame.Participants[i].SummonerId); foreach (LeaguePosition pos in positions) { string queue = pos.QueueType == "RANKED_SOLO_5x5" ? "Solo/Duo" : pos.QueueType == "RANKED_FLEX_SR" ? "Flex" : pos.QueueType == "RANKED_FLEX_TT" ? "Treeline" : (pos.QueueType[0] + pos.QueueType.Substring(1).ToLower()); field.Value += $"{queue}: {pos.Tier[0] + pos.Tier.Substring(1).ToLower()} {pos.Rank}\n"; } fields.Add(field); } EmbedBuilder toReply = new EmbedBuilder().WithTimestamp(DateTimeOffset.FromUnixTimeMilliseconds(runningGame.GameStartTime)); toReply.WithColor(0xff69b4); toReply.WithFooter("Game started"); toReply.WithAuthor(new EmbedAuthorBuilder() .WithName(targetSumm.Name) .WithIconUrl($"http://ddragon.leagueoflegends.com/cdn/{_rapi.patchNum}/img/profileicon/{targetSumm.ProfileIconId}.png")); toReply.WithFields(fields); await ReplyAsync(embed : toReply.Build()); }
private string GetProfileIcon(CurrentGameInfo spectators, string DDChampion, List <Champions.Champion> champions, string name) { int playerCount = spectators.Participants.Length; string result = string.Empty; for (int i = 0; i < playerCount; ++i) { if (spectators.Participants[i].SummonerName.ToLower() == name.ToLower()) { result = $"http://ddragon.leagueoflegends.com/cdn/{DDChampion}/img/champion/{champions[i].id}.png"; } } return(result); }
private string PrintRedTeam(CurrentGameInfo spectators, List <Champions.Champion> champions, string[] rank) { int playerCount = spectators.Participants.Length; string result = string.Empty; for (int i = 0; i < playerCount; ++i) { if (spectators.Participants[i].TeamId == 200) { result = result + $"**Player:** {spectators.Participants[i].SummonerName}\n **Champ:** {champions[i].name}\n **Rank:** {rank[i]}\n\n"; } } return(result); }
public CurrentGameInfo GetCurrentGameInfo(String host, regions.Platform_ID region, int summonerId) { try { String requestUrl = host + Endpoints.CURRENT_GAME + region + "/" + summonerId + "?" + Endpoints.API_KEY; var requestResult = request.MakeRequest(requestUrl); CurrentGameInfo returnInfo = JsonConvert.DeserializeObject <CurrentGameInfo>(requestResult.Result); return(returnInfo); } catch (Exception e) { return(null); } }
public void GetCurrentGameInformationForSummonerIdBehaviour() { //Arrange _mockClient.Setup(x => x.CurrentGame.GetCurrentGameInformationForSummonerId(It.IsAny <RiotApiConfig.Platforms>(), It.IsAny <long>())) .Returns(new CurrentGameInfo()); //Act IRiotClient client = _mockClient.Object; CurrentGameInfo dto = client.CurrentGame.GetCurrentGameInformationForSummonerId( RiotApiConfig.Platforms.EUN1, 1); //Assert Assert.IsInstanceOf <CurrentGameInfo>(dto); Assert.NotNull(dto); }
public async Task GetLiveMatchDataAsync(params string[] objects) { StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i <= objects.Length - 2; i++) { stringBuilder.Append(objects[i] + " "); } string summonerName = stringBuilder.ToString().Substring(0, stringBuilder.ToString().Length - 1); string reigon = objects[objects.Length - 1]; if (RiotApiService.ValidReigon(reigon) == false) { throw new ArgumentException("Arguments should be the following:\n1: Summoner Name\n" + "2: Reigon\n"); } await ReplyAsync("Obtaining summoner info for summoner : " + summonerName + " ..."); CurrentGameInfo currentGameInfo = await RiotApiService.GetLiveMatchDataAsync(summonerName, reigon); var blueSide = currentGameInfo.Participants.Where(player => player.TeamId == 100); var redSide = currentGameInfo.Participants.Where(player => player.TeamId == 200); var summonerIcon = currentGameInfo.Participants.First(player => player.SummonerName == summonerName).ProfileIconId; StringBuilder blueStringBuilder = new StringBuilder(); foreach (var participant in blueSide) { blueStringBuilder.AppendLine(participant.SummonerName + " : " + RiotApiService.MakeBold(((Champion)participant.ChampionId).Name())); } StringBuilder redStringBuilder = new StringBuilder(); foreach (var participant in redSide) { redStringBuilder.AppendLine(participant.SummonerName + " : " + RiotApiService.MakeBold(((Champion)participant.ChampionId).Name())); } var embed = new EmbedBuilder { Title = $"Live Match Data for {summonerName}", Color = Color.Green, ThumbnailUrl = DataDragonService.GetMapURL(currentGameInfo.MapId.ToString()), }; embed.AddField("Game Type", currentGameInfo.GameMode); embed.AddField("Blue Side", blueStringBuilder.ToString(), true); embed.AddField("Red Side", redStringBuilder.ToString(), true); embed.WithCurrentTimestamp(); await ReplyAsync(embed : embed.Build()); }
public async Task <CurrentGameInfo> GetLiveMatchDataAsync(string summonerName, string reigon) { var summonerData = await riotApi.SummonerV4.GetBySummonerNameAsync(Region.Get(reigon), summonerName); if (summonerData == null) { await Task.Run(() => throw new RiotApiException($"Summoner '{summonerName} not found.")); } CurrentGameInfo currentGameInfo = await riotApi.SpectatorV4.GetCurrentGameInfoBySummonerAsync(Region.Get(reigon), summonerData.Id); if (currentGameInfo == null) { await Task.Run(() => throw new RiotApiException($"Summoner '{summonerName} is not currently in a game.")); } return(currentGameInfo); }
private void LoadData(CurrentGameStateService gs) { RootObject ro = gs.ParsedData; if (gs.ParsedData.Map == null) { return; } var steamIds = FindAllSteamIds(gs.ParsedData); CurrentGameInfo matchInfo = new CurrentGameInfo(); matchInfo.MatchID = gs.ParsedData.Map.MatchId; matchInfo.RadiantGold = gs.ParsedData.MainPlayer.RadiantTeam.Player0.NetWorth; matchInfo.DireGold = gs.ParsedData.MainPlayer.DireTeam.Player5.NetWorth; matchInfo.WinProbability = gs.ParsedData.Map.RadiantWinChance; matchInfo.RadiantKills = gs.ParsedData.MainPlayer.RadiantTeam.GetAllPlayers.Sum(p => p.Kills); matchInfo.DireKills = gs.ParsedData.MainPlayer.DireTeam.GetAllPlayers.Sum(p => p.Kills); TimeSpan t = TimeSpan.FromSeconds(gs.ParsedData.Map.ClockTime); matchInfo.MatchTime = string.Format("{0:D2}:{1:D2}", t.Minutes, t.Seconds); //All players matchInfo.RadiantTeam = gs.ParsedData.MainPlayer.RadiantTeam.GetAllPlayers; matchInfo.DireTeam = gs.ParsedData.MainPlayer.DireTeam.GetAllPlayers; //All players current networth matchInfo.HeroesNetWorth.AddRange(gs.ParsedData.MainPlayer.RadiantTeam.GetAllPlayers.Select(gap => gap.NetWorth)); matchInfo.HeroesNetWorth.AddRange(gs.ParsedData.MainPlayer.DireTeam.GetAllPlayers.Select(gap => gap.NetWorth)); //All players current gold matchInfo.HeroesCurrentGold.AddRange(gs.ParsedData.MainPlayer.RadiantTeam.GetAllPlayers.Select(gap => gap.Gold)); matchInfo.HeroesCurrentGold.AddRange(gs.ParsedData.MainPlayer.DireTeam.GetAllPlayers.Select(gap => gap.Gold)); //All players reliable gold matchInfo.HeroesReliableGold.AddRange(gs.ParsedData.MainPlayer.RadiantTeam.GetAllPlayers.Select(gap => gap.GoldReliable)); matchInfo.HeroesReliableGold.AddRange(gs.ParsedData.MainPlayer.DireTeam.GetAllPlayers.Select(gap => gap.GoldReliable)); //All players buybackcost matchInfo.HeroesBuybackCost.AddRange(gs.ParsedData.Hero.RadiantTeam.AllPlayers.Select(p => p.BuybackCost)); matchInfo.HeroesBuybackCost.AddRange(gs.ParsedData.Hero.DireTeam.AllPlayers.Select(p => p.BuybackCost)); //All players buyback cooldown matchInfo.HeroesBuybackCooldown.AddRange(gs.ParsedData.Hero.RadiantTeam.AllPlayers.Select(p => p.BuybackCooldown)); matchInfo.HeroesBuybackCooldown.AddRange(gs.ParsedData.Hero.DireTeam.AllPlayers.Select(p => p.BuybackCooldown)); matchInfo.HeroesImages = ImagesConverter.LoadImages(gs.ParsedData.Hero.AllHeroes.Select(ah => ah.Id).ToList()); CurrentMatchInfo = matchInfo; }
private void OnNewGameState(CurrentGameStateService gs) { CurrentGameViewModel currentGameViewModel = new CurrentGameViewModel(gs); CurrentMatchInfo = currentGameViewModel.CurrentMatchInfo; }
internal void OnGame(CurrentGameInfo game) { this.CurrentGame = game; }
private async Task <string[]> GetSummonerRanksAsync(RiotApi riotApi, Region platform, CurrentGameInfo spectators) { int playerCount = spectators.Participants.Length; string[] rank = new string[playerCount]; for (int i = 0; i < playerCount; ++i) { LeagueEntry[] Entries = await riotApi.LeagueV4.GetLeagueEntriesForSummonerAsync(platform, spectators.Participants[i].SummonerId); for (int j = 0; j < Entries.Length; j++) { if (Entries[j].QueueType == "RANKED_SOLO_5x5") { rank[i] = $"{Entries[j].Tier} {Entries[j].Rank}"; } } if (string.IsNullOrEmpty(rank[i])) { rank[i] = $"Unranked"; } } return(rank); }
public void ResetLevel() { CurrentLevel = new Level(GameFiles.CurrentLevel); CurrentLevel.Player = new Player(CurrentLevel.LevelInform.StartPlayerLocation); CurrentGameInfo.Reset(); }