Example #1
0
        public async Task <bool> Connect(string login, string password)
        {
            Data["login"]    = login;
            Data["password"] = password;
            try
            {
                Uri url = new Uri(Url + "farmer/login-token/" + login + "/" + password);
                Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                var authenticationResponse = await Client.GetStringAsync(url);

                var responseCookies = _cookiesContainer.GetCookies(url).Cast <Cookie>();

                JObject json = JObject.Parse(authenticationResponse);
                if (json.Root["success"].ToString() == "True")
                {
                    Cookies = new List <Cookie>();
                    foreach (var cookie in (IEnumerable <Cookie>)responseCookies.GetEnumerator())
                    {
                        Cookies.Add(cookie);
                    }

                    UpdateCookie();
                    player.Id     = int.Parse(json.Root["farmer"]["id"].ToString());
                    player.Talent = int.Parse(json.Root["farmer"]["talent"].ToString());
                    player.Login  = login;
                    player.Leeks  = new List <Leek>();
                    var  leeks = json.Root["farmer"]["leeks"].First;
                    bool isEnd = false;
                    while (!isEnd)
                    {
                        try
                        {
                            Leek leek = new Leek();
                            leek.Id     = int.Parse(leeks.First["id"].ToString());
                            leek.Name   = leeks.First["name"].ToString();
                            leek.Level  = int.Parse(leeks.First["level"].ToString());
                            leek.Talent = int.Parse(leeks.First["talent"].ToString());
                            player.Leeks.Add(leek);
                            leeks = leeks.Next;
                        }
                        catch (Exception e)
                        {
                            isEnd = true;
                        }
                    }
                    Console.WriteLine("[API]: connected to " + player.Login);
                    return(true);
                }
                else
                {
                    Console.WriteLine("[API]: FAILED connected to " + player.Login);
                    return(false);
                }
            }
            catch (Exception)
            {
                Console.WriteLine("[API]: FAILED connected to " + player.Login);
                return(false);
            }
        }
Example #2
0
        public async Task <bool> GardenGetOpponents(int leekId)
        {
            Uri url = new Uri(Url + "garden/get-leek-opponents/" + player.Leeks[leekId].Id.ToString() + "/" + Data["token"]);

            try
            {
                Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                var authenticationResponse = await Client.GetStringAsync(url);

                JObject json = JObject.Parse(authenticationResponse);
                if (json.Root["success"].ToString() == "True")
                {
                    var  leeks = json.Root["opponents"].First;
                    bool isEnd = false;
                    garden.Opponents = new List <Leek>();
                    while (!isEnd)
                    {
                        try
                        {
                            Leek leek = new Leek();
                            leek.Id     = int.Parse(leeks["id"].ToString());
                            leek.Name   = leeks["name"].ToString();
                            leek.Level  = int.Parse(leeks["level"].ToString());
                            leek.Talent = int.Parse(leeks["talent"].ToString());
                            garden.Opponents.Add(leek);
                            leeks = leeks.Next;
                        }
                        catch (Exception e)
                        {
                            isEnd = true;
                        }
                    }
                    garden.GetWeakestOpponent();
                    Console.WriteLine("[GARDEN][OPPONENTS]: Success | Found: " + garden.Opponents.Count.ToString() + " opponents for " + player.Leeks[leekId].Name);
                    foreach (var opponent in garden.Opponents)
                    {
                        Console.WriteLine("[GARDEN][OPPONENTS][LIST]: " + opponent.Name + " | level: " + opponent.Level + " | talent: " + opponent.Talent);
                    }
                    return(true);
                }
                else
                {
                    Console.WriteLine("[GARDEN][OPPONENTS]: FAILED");
                    return(false);
                }
            }
            catch (Exception)
            {
                Console.WriteLine("[GARDEN][OPPONENTS]: FAILED");
                return(false);
            }
        }