Esempio n. 1
0
        public static StartGymBattleResponse StartGymBattle(Client client, string gymId, ulong defendingPokemonId,
                                                            IEnumerable <ulong> attackingPokemonIds)
        {
            StartGymBattleResponse resp = null;
            var numTries    = 3;
            var startFailed = false;
            var deltaValue  = 0.001;

            do
            {
                resp = client.Fort.StartGymBattle(gymId, defendingPokemonId, attackingPokemonIds);
                if (resp == null)
                {
                    Logger.Debug("(Gym) - Response to start battle was null.");
                    startFailed = true;
                }
                else
                {
                    if (resp.BattleLog == null)
                    {
                        Logger.Debug("(Gym) - BatlleLog to start battle was null");
                        startFailed = true;
                    }
                }

                if (startFailed)
                {
                    RandomHelper.RandomSleep(5000);
                    if (GlobalVars.Gyms.Testing == "Fire Request Block Two")
                    {
                        client.Login.FireRequestBlockTwo().Wait();
                        RandomHelper.RandomSleep(2000);
                    }
                    else if (GlobalVars.Gyms.Testing == "Wait 2 minutes before of next try" && numTries == 3)
                    {
                        // 120 secondos
                        Logger.Info("Waiting 2 minutes before of next attack try");
                        if (GlobalVars.CatchPokemon)
                        {
                            Logger.Info("While, we will try to catch pokemons");
                        }
                        var rnd = RandomHelper.RandomNumber(50, 90) * 0.00001;
                        // 0.00001 = 1 meters
                        //http://gizmodo.com/how-precise-is-one-degree-of-longitude-or-latitude-1631241162
                        Logger.Debug("going to 50 meters far of gym");
                        LocationUtils.updatePlayerLocation(client, client.CurrentLongitude + rnd, client.CurrentLatitude, client.CurrentAltitude);
                        RandomHelper.RandomSleep(10000);
                        CatchingLogic.Execute();
                        RandomHelper.RandomSleep(10000);
                        CatchingLogic.Execute();
                        Logger.Debug("returning to gym location");
                        // go back
                        LocationUtils.updatePlayerLocation(client, client.CurrentLongitude - rnd, client.CurrentLatitude, client.CurrentAltitude);
                        RandomHelper.RandomSleep(10000);
                        CatchingLogic.Execute();
                        client.Login.FireRequestBlockTwo().Wait();
                        RandomHelper.RandomSleep(2000);
                    }
                    else
                    {
                        RandomHelper.RandomSleep(2000);
                        var gmo = client.Map.GetMapObjects().Result;
                        client.Login.FireRequestBlockTwo().Wait();
                        RandomHelper.RandomSleep(2000);
                    }
                }
                else
                {
                    Logger.Debug("StartGymBattle Response:" + resp);
                }
                numTries--;
            } while (startFailed && numTries > 0);
            return(resp);
        }