Beispiel #1
0
        public static bool IsPlayerInGame(RiotApi api, out RootObject GameInfo, long player, string plat, Region reg)
        {
            try
            {
                if (reg == Region.pbe)
                {
                    GameInfo = api.GetCurrentGamePBE(Region.pbe, player, "PBE1");
                }
                else
                {
                    GameInfo = api.GetCurrentGame(reg, player, plat);
                }


                if (GameInfo != null)
                {
                    return(true);
                }
            }
            catch
            {
            }
            GameInfo = null;
            return(false);
        }
        public static int getData()
        {
            eventtrigger.onStartedUpdate();
            Properties.Settings.Default.Save();
            RiotSharp.CurrentGameEndpoint.CurrentGame gameinfo;
            string retval = "error";

            try
            {
                gameinfo = api.GetCurrentGame(Platform.EUW1, CURRENT_SUMMONER);
                GameQueueType qType = gameinfo.GameQueueType;

                if (isTeamRanked(qType))
                {
                    Console.WriteLine("Teamranked");
                    GameFetcher fetcher = new TeamRankedFetcher();
                    retval = fetcher.getQueueData(gameinfo, CURRENT_SUMMONER);
                }
                else if (isSoloQueue(qType))
                {
                    Console.WriteLine("SoloQueue");
                    GameFetcher fetcher = new SoloQueueFetcher();
                    retval = fetcher.getQueueData(gameinfo, CURRENT_SUMMONER);
                }
                else
                {
                    Console.WriteLine("Normal or Custom");
                    GameFetcher fetcher = new NormalCustomFetcher();
                    retval = fetcher.getQueueData(gameinfo, CURRENT_SUMMONER);
                }
                eventtrigger.onFinishedUpdate(retval);
                return(0);
            } catch (RiotSharpException e)
            {
                Console.WriteLine(e);
                FileWriter.WriteToFile("Not Ingame");
                eventtrigger.onFinishedUpdate("Not Ingame");
                return(-1);
            } catch (JsonSerializationException e)
            {
                Console.WriteLine(e);
                eventtrigger.onFinishedUpdate("Unknown Gamemode");
                FileWriter.WriteToFile("Unknown Gamemode");
                return(-2);
            }
        }
        /// <summary>
        /// Fetches the given Summoner's current game from the RiotAPI for the given region.
        /// </summary>
        /// <param name="e">The command event which was executed.</param>
        /// <returns>A message in the channel with information about the current game of the Summoner in the region.</returns>
        public async Task GetCurrentGameStats(CommandEventArgs e)
        {
            var    input        = Utils.ReturnInputParameterStringArray(e);
            string regionString = input[0];
            string summonerName = "";

            if (input.Length == 2)
            {
                summonerName = input[1];
            }
            else
            {
                summonerName = input[1];
                for (int i = 2; i < input.Length; i++)
                {
                    summonerName = String.Format("{0} {1}", summonerName, input[i]);
                }
            }

            try
            {
                var      summoner    = GetSummoner(regionString, summonerName);
                var      currentGame = api.GetCurrentGame(GetPlatform(regionString), summoner.Id);
                string[] summoners   = new string[10];
                Region   region      = GetRegion(regionString);

                List <Participant> blueTeam = new List <Participant>();
                List <Participant> redTeam  = new List <Participant>();
                for (int i = 0; i < currentGame.Participants.Count; i++)
                {
                    if (currentGame.Participants[i].TeamId == 100)
                    {
                        blueTeam.Add(currentGame.Participants[i]);
                    }
                    else if (currentGame.Participants[i].TeamId == 200)
                    {
                        redTeam.Add(currentGame.Participants[i]);
                    }

                    string champion = "";
                    if (currentGame.Participants[i].ChampionId != 0)
                    {
                        champion = " (" + staticApi.GetChampion(region, (Int32)currentGame.Participants[i].ChampionId).Name + ")";
                    }
                    summoners[i] = currentGame.Participants[i].SummonerName.PadRight(20) + champion;
                }

                //Fill up empty slots.
                if (currentGame.Participants.Count < 10)
                {
                    int emptySlots = 10;
                    emptySlots -= redTeam.Count;
                    emptySlots -= blueTeam.Count;
                    Participant emptyParticipant = new Participant();

                    for (int i = 0; i < emptySlots / 2; i++)
                    {
                        redTeam.Add(emptyParticipant);
                        blueTeam.Add(emptyParticipant);
                    }
                }

                int minutes = (Int32)currentGame.GameLength / 60;
                int seconds = (Int32)currentGame.GameLength % 60;

                //Information to display.
                string output = String.Format("*{0}* is currently in a **{1}** game on {2}. ({3})", summoner.Name, currentGame.GameMode, currentGame.MapType, currentGame.GameQueueType) + "\n"
                                + String.Format("This match started at *{0}* and has been going on for **{1}:{2}** (+ ~ 5 minutes).",
                                                currentGame.GameStartTime.ToShortTimeString(),
                                                minutes.ToString().PadLeft(2, '0'),
                                                seconds.ToString().PadLeft(2, '0'),
                                                currentGame.GameLength) + "\n"
                                + "```"
                                + "".PadLeft(13) + "Blue Team".PadRight(22) + " - " + "".PadLeft(13) + "Red Team".PadRight(22) + "\n"
                                + "".PadRight(75, '~') + "\n";

                for (int i = 0; i < currentGame.Participants.Count / 2; i++)
                {
                    output += summoners[i].PadRight(35);
                    output += " - ";
                    output += summoners[i + 5].PadRight(35);
                    output += " \n";
                }

                output += "```";
                await e.Channel.SendMessage(output);
            }
            catch (RiotSharpException ex)
            {
                Console.WriteLine(String.Format("Get current game - {0}", ex.Message));
                await e.Channel.SendMessage("This Summoner is currently not in a game.");
            }
            catch (IndexOutOfRangeException)
            {
                await Utils.InproperCommandUsageMessage(e, "currentgame", "currentgame <REGION> <SUMMONERNAME>");
            }
            catch (Exception ex) when(ex is SummonerNotFoundException || ex is RegionNotFoundException)
            {
                Console.WriteLine(String.Format("Get current game - {0}", ex.Message));
                await e.Channel.SendMessage(ex.Message);
            }
        }
Beispiel #4
0
        public async Task job()
        {
            string reponse = "Pas en game";

            for (int j = 0; j < user.Count; j++)
            {
                Console.WriteLine("Recherche de " + user[j] + ".");
                try
                {
                    var summoner = api.GetSummoner(Region.euw, user[j]);
                    var match    = api.GetCurrentGame(Platform.EUW1, summoner.Id);
                    if (matchIDs.Contains(match.GameId))
                    {
                        throw new Exception();
                    }
                    matchIDs.Add(match.GameId);
                    var             participants = match.Participants;
                    List <string>   sumId        = new List <string>();
                    List <Summoner> sum          = new List <Summoner>();
                    foreach (var item in participants)
                    {
                        sumId.Add(item.SummonerName);
                    }
                    sum = api.GetSummoners(Region.euw, sumId);
                    //Console.WriteLine("Début du formattage du KDA");
                    var lStats = statsByParticipants(participants, sum);
                    Console.WriteLine("Fin du formattage du KDA");
                    var bans = match.BannedChampions;
                    bans.Sort(delegate(BannedChampion x, BannedChampion y)
                    {
                        return(x.TeamId.CompareTo(y.TeamId));
                    });
                    string[] ban = { championByID(bans[0].ChampionId), championByID(bans[1].ChampionId), championByID(bans[2].ChampionId), championByID(bans[3].ChampionId), championByID(bans[4].ChampionId), championByID(bans[5].ChampionId) };

                    reponse = "```Red Team-- Bans[" + ban[0] + ", " + ban[1] + ", " + ban[2] + "]" + Environment.NewLine + Environment.NewLine;
                    //Console.WriteLine("Debut de recup du rang");
                    var l = rangBySummoner(participants, sum);
                    Console.WriteLine("Fin de récup du rang");
                    int i = 0;
                    IEnumerable <Tuple <string, string, string, string, string, string> > authors =
                        new[]
                    {
                        Tuple.Create(participants[0].SummonerName, l[0], championByID(participants[0].ChampionId), lStats[i], spellByID(participants[0].SummonuerSpell1), spellByID(participants[0].SummonerSpell2)),
                        Tuple.Create(participants[1].SummonerName, l[1], championByID(participants[1].ChampionId), lStats[i + 1], spellByID(participants[1].SummonuerSpell1), spellByID(participants[1].SummonerSpell2)),
                        Tuple.Create(participants[2].SummonerName, l[2], championByID(participants[2].ChampionId), lStats[i + 2], spellByID(participants[2].SummonuerSpell1), spellByID(participants[2].SummonerSpell2)),
                        Tuple.Create(participants[3].SummonerName, l[3], championByID(participants[3].ChampionId), lStats[i + 3], spellByID(participants[3].SummonuerSpell1), spellByID(participants[3].SummonerSpell2)),
                        Tuple.Create(participants[4].SummonerName, l[4], championByID(participants[4].ChampionId), lStats[i + 4], spellByID(participants[4].SummonuerSpell1), spellByID(participants[4].SummonerSpell2))
                    };

                    reponse += authors.ToStringTable(
                        new[] { "Pseudo", "Rang", "Champion", "KDA", "Spell 1", "Spell 2" },
                        a => a.Item1, a => a.Item2, a => a.Item3, a => a.Item4, a => a.Item5, a => a.Item6) + Environment.NewLine + Environment.NewLine;
                    reponse += "Blue Team-- Bans[" + ban[3] + ", " + ban[4] + ", " + ban[5] + "]" + Environment.NewLine + Environment.NewLine;
                    i        = 5;
                    authors  =
                        new[]
                    {
                        Tuple.Create(participants[5].SummonerName, l[i + 0], championByID(participants[5].ChampionId), lStats[i], spellByID(participants[5].SummonuerSpell1), spellByID(participants[5].SummonerSpell2)),
                        Tuple.Create(participants[6].SummonerName, l[i + 1], championByID(participants[6].ChampionId), lStats[i + 1], spellByID(participants[6].SummonuerSpell1), spellByID(participants[6].SummonerSpell2)),
                        Tuple.Create(participants[7].SummonerName, l[i + 2], championByID(participants[7].ChampionId), lStats[i + 2], spellByID(participants[7].SummonuerSpell1), spellByID(participants[7].SummonerSpell2)),
                        Tuple.Create(participants[8].SummonerName, l[i + 3], championByID(participants[8].ChampionId), lStats[i + 3], spellByID(participants[8].SummonuerSpell1), spellByID(participants[8].SummonerSpell2)),
                        Tuple.Create(participants[9].SummonerName, l[i + 4], championByID(participants[9].ChampionId), lStats[i + 4], spellByID(participants[9].SummonuerSpell1), spellByID(participants[9].SummonerSpell2))
                    };
                    reponse += authors.ToStringTable(
                        new[] { "Pseudo", "Rang", "Champion", "KDA", "Spell 1", "Spell 2" },
                        a => a.Item1, a => a.Item2, a => a.Item3, a => a.Item4, a => a.Item5, a => a.Item6) + Environment.NewLine + "```";
                    var channel = await client.GetChannelByID(255746001724243968);

                    await client.SendMessage(channel, reponse);
                }
                catch (RiotSharpException)
                {
                    reponse = "Pas en game";
                    Console.WriteLine(reponse);
                }
                catch (Exception)
                {
                    reponse = "Même game !!";
                    Console.WriteLine(reponse);
                }
            }
        }
Beispiel #5
0
 public static CurrentGame TryGetCurrentGame(this RiotApi api, Platform platform, long summonerId,
                                             int checkRate = 1, int maxRetries = -1)
 {
     return(TryApi(() => api.GetCurrentGame(platform, summonerId), checkRate, maxRetries));
 }
        private void SummonerNameTextBox_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key == System.Windows.Input.Key.Return)
            {
                string summonerName = SummonerNameTextBox.Text;

                Summoner summoner;
                RiotSharp.CurrentGameEndpoint.CurrentGame currentGame;
                try
                {
                    summoner = api.GetSummoner(Region.na, summonerName);
                }
                catch (RiotSharpException ex)
                {
                    System.Windows.Forms.MessageBox.Show("That Summoner does not exist");
                    return;
                }
                try
                {
                    currentGame = api.GetCurrentGame(Platform.NA1, summoner.Id);
                }
                catch (RiotSharp.RiotSharpException ex)
                {
                    //Handle the exception however you want.

                    System.Windows.Forms.MessageBox.Show("Could not find that summoner in a game");
                    return;
                }
                List <RiotSharp.CurrentGameEndpoint.Participant> team1 = new List <RiotSharp.CurrentGameEndpoint.Participant>();
                List <RiotSharp.CurrentGameEndpoint.Participant> team2 = new List <RiotSharp.CurrentGameEndpoint.Participant>();
                int teamIDofSummoner = -1;
                //split the participants into their teams, ally and enemy
                foreach (var p in currentGame.Participants)
                {
                    if (summoner.Name.Equals(p.SummonerName))
                    {
                        teamIDofSummoner = (int)p.TeamId;
                    }
                    if (p.TeamId == 100) //ids are 100 or 200
                    {
                        team1.Add(p);
                    }
                    else
                    {
                        team2.Add(p);
                    }
                }

                Console.WriteLine("Main summoner's enemies are: ");
                List <RiotSharp.CurrentGameEndpoint.Participant> enemyTeam;
                if (teamIDofSummoner == 100)
                {
                    enemyTeam = team2;
                }
                else
                {
                    enemyTeam = team1;
                }

                int i = 0;
                foreach (var p in enemyTeam)
                {
                    string championName = staticApi.GetChampion(Region.na, (int)p.ChampionId).Name;
                    Console.WriteLine("Player " + p.SummonerName + " is playing " + championName);

                    if (staticApi.GetSummonerSpell(Region.na,
                                                   (RiotSharp.StaticDataEndpoint.SummonerSpell)p.SummonuerSpell1).Name.Equals("Flash") ||
                        staticApi.GetSummonerSpell(Region.na,
                                                   (RiotSharp.StaticDataEndpoint.SummonerSpell)p.SummonerSpell2).Name.Equals("Flash"))
                    {
                        Console.WriteLine("and they have Flash.");
                    }

                    /**
                     * masteryId	long	The ID of the mastery
                     * rank	        int	    The number of points put into this mastery by the user
                     */
                    var  m          = p.Masteries;
                    bool hasInsight = false;
                    foreach (var mastery in m)
                    {
                        var masteryDetail = staticApi.GetMastery(Region.na, (int)mastery.MasteryId);
                        if (masteryDetail.Name.Equals("Insight")) //also id == 6241
                        {
                            int id = masteryDetail.Id;
                            Console.WriteLine("And they have the insight mastery.");
                            hasInsight = true;
                        }
                    }
                    championPanelPresenters[i].LoadFromRiotAPI(p.SummonerName, championName, hasInsight);
                    i++;
                }
            }
        }