public async Task <Summoner> GetSummoner()
        {
            if (League == null)
            {
                League = await LeagueClient.Connect();
            }
            try
            {
                var region = await League.MakeApiRequest(HttpMethod.Get, "/riotclient/get_region_locale");

                var locals = JsonConvert.DeserializeObject <Region>(region.Content.ReadAsStringAsync().Result);

                Summoners sum    = new Summoners(League);
                var       player = await sum.GetCurrentSummoner();

                if (player == null || player.SummonerId == null)
                {
                    return(null);
                }

                Summoner user = new Summoner();
                user.SummonerID   = player.SummonerId.ToString();
                user.SummonerName = player.DisplayName;
                user.Region       = (Regions)Enum.Parse(typeof(Regions), locals.RegionRegion);
                return(user);
            }

            catch
            {
                return(null);
            }
        }
        public async Task JoinGame(string enemyId, string match)
        {
            bool matchAccepted = false;

            if (League == null)
            {
                League = await LeagueClient.Connect();
            }
            while (!matchAccepted)
            {
                var response = await League.MakeApiRequest(HttpMethod.Get, "/lol-lobby/v2/received-invitations");

                var invites = JsonConvert.DeserializeObject <List <InviteModel> >(await response.Content.ReadAsStringAsync());

                foreach (var item in invites)
                {
                    if (item.FromSummonerId == enemyId && item.State == "Pending")
                    {
                        await League.MakeApiRequest(HttpMethod.Post, "/lol-lobby/v2/received-invitations/" + item.InvitationId + "/accept");

                        System.Net.Http.HttpClient http = new System.Net.Http.HttpClient();
                        matchAccepted = true;
                    }
                }
                await Task.Delay(100);
            }
        }
Exemple #3
0
        public async Task <Tuple <bool, int> > WatchMatch(Match match)
        {
            if (lc == null)
            {
                lc = await LeagueClient.Connect();
            }
            RedChamp  = "";
            BlueChamp = "";
            IsInGame  = true;
            var summoner = await lc.GetSummonersModule().GetCurrentSummoner();

            var dodged = await CheckForDodge();

            bool result;

            if (dodged.Item1)
            {
                result = dodged.Item2;
            }
            else
            {
                result = await MatchParser(match, summoner);
            }

            var elo = await SaveMatchResult(result, match, summoner);

            return(new Tuple <bool, int>(result, elo));
        }
        public static async Task <ILeagueClient> Connect(string path)
        {
            var ret = new LeagueClient();

            ret.LeaguePath = path;

            await ret.WatchLockFileAsync();

            var process = Process.GetProcessById(ret.LeaguePid);

            process.EnableRaisingEvents = true;
            process.Exited += ret.League_Exited;

            return(ret);
        }
        public async Task CreateOneOnOneGame(string LobbyName, string enemyId)
        {
            if (League == null)
            {
                League = await LeagueClient.Connect();
            }
            ApiObject api      = new ApiObject();
            var       obj      = api.createCustomGameOneOnOne(LobbyName);
            var       response = await League.MakeApiRequest(HttpMethod.Post, "/lol-lobby/v2/lobby", obj);

            while (true)
            {
                if (response.StatusCode != System.Net.HttpStatusCode.OK)
                {
                    obj      = api.createCustomGameOneOnOne(LobbyName);
                    response = League.MakeApiRequest(HttpMethod.Post, "/lol-lobby/v2/lobby", obj).Result;
                }
                else
                {
                    break;
                }
            }

            var invites = new List <LobbyInvitation>();

            invites.Add(new LobbyInvitation
            {
                ToSummonerId = enemyId
            });
            await League.MakeApiRequest(HttpMethod.Post, "/lol-lobby/v2/lobby/invitations", invites);

            bool AllIn = false;

            while (!AllIn)
            {
                LobbyPlayerInfo[] players = await League.MakeApiRequestAs <LobbyPlayerInfo[]>(HttpMethod.Get, "/lol-lobby/v2/lobby/members");

                foreach (var item in players)
                {
                    if (item.SummonerId == enemyId)
                    {
                        AllIn = true;
                    }
                }
            }
            await League.MakeApiRequest(HttpMethod.Post, "/lol-lobby/v1/lobby/custom/start-champ-select", new StartGame());
        }
        public async Task <bool> CheckIfLeagueIsOpen()
        {
            try
            {
                League = await LeagueClient.Connect();

                if (League != null)
                {
                    League.LeagueClosed += () => CheckIfLeagueOpens.Invoke();
                }
            }
            catch (Exception e)
            {
                return(false);
            }
            return(true);
        }