Ejemplo n.º 1
0
        private ulong TrySnipeGym(GeoCoordinate pokeCoords, GeoCoordinate returnCoords)
        {
            var   found  = false;
            var   tries  = 1;
            ulong caught = 0;

            do
            {
                var mapObjectsResponse = _client.Map.GetMapObjects(true).Result.Item1;
                var pokeGyms           = mapObjectsResponse.MapCells.SelectMany(i => i.Forts)
                                         .Where(i => i.Type == POGOProtos.Map.Fort.FortType.Gym);
                Logger.Debug("pokeCoords:" + pokeCoords);
                foreach (var element in pokeGyms)
                {
                    if (Math.Abs(element.Latitude - pokeCoords.Latitude) < Epsilon && Math.Abs(element.Longitude - pokeCoords.Longitude) < Epsilon)
                    {
                        SendToLog("Found Gym to Snipe");
                        var profile = _client.Player.GetPlayer();
                        var buddyid = 0UL;
                        if (profile.PlayerData.BuddyPokemon != null)
                        {
                            buddyid = profile.PlayerData.BuddyPokemon.Id;
                        }
                        var gymDet = _client.Fort.GetGymDetails(element.Id, element.Latitude, element.Longitude);
                        if (gymDet.Result == GetGymDetailsResponse.Types.Result.Success)
                        {
                            found = true;
                            var pokeToDeploy = GymsLogic.getPokeToPut(_client, buddyid);
                            if (pokeToDeploy != null)
                            {
                                var res = _client.Fort.FortDeployPokemon(element.Id, pokeToDeploy.Id);
                                if (res.Result == FortDeployPokemonResponse.Types.Result.Success)
                                {
                                    caught = pokeToDeploy.Id;
                                    SendToLog(GymsLogic.strPokemon(pokeToDeploy) + " Deployed!");
                                }
                                else
                                {
                                    SendToLog(res.Result.ToString());
                                }
                            }
                            break;
                        }
                    }
                }
                if (!found)
                {
                    SendToLog($"No Gym Found!");
                    if ((tries <= GlobalVars.SnipeOpts.NumTries))
                    {
                        SendToLog($"Waiting {GlobalVars.SnipeOpts.WaitSecond} seconds to check again...");
                        RandomHelper.RandomSleep(GlobalVars.SnipeOpts.WaitSecond * 1200);
                    }
                }
                tries++;
            } while ((tries <= GlobalVars.SnipeOpts.NumTries) && caught == 0);
            if (caught == 0)
            {
                SendToLog("Gym not found or Pokemon not deployed!");
            }

            return(caught);
        }
Ejemplo n.º 2
0
        public static BattleState AttackGym(FortData gym, Client client)
        {
            GymsLogic.StopAttack = false;
            GymGetInfoResponse      gymGetInfoResponse      = null;
            GymStartSessionResponse gymStartSessionResponse = null;

            gymGetInfoResponse = client.Fort.GymGetInfo(gym.Id, gym.Latitude, gym.Longitude);

            // Get defenders info
            int currentDefender = 0;
            var defenders       = gymGetInfoResponse.GymStatusAndDefenders.GymDefender.Select(x => x.MotivatedPokemon.Pokemon).ToList();
            var defender        = gymGetInfoResponse.GymStatusAndDefenders.GymDefender[currentDefender];

            for (int i = 0; i < defenders.Count(); i++)
            {
                Logger.Debug($"(Gym) Defender {i + 1}: {gymGetInfoResponse.GymStatusAndDefenders.GymDefender[i].MotivatedPokemon.Pokemon.PokemonId}" +
                             $" | CpNow: {gymGetInfoResponse.GymStatusAndDefenders.GymDefender[i].MotivatedPokemon.CpNow}" +
                             $" | MotivationNow: {gymGetInfoResponse.GymStatusAndDefenders.GymDefender[i].MotivatedPokemon.MotivationNow}" +
                             $" | Id: {gymGetInfoResponse.GymStatusAndDefenders.GymDefender[i].MotivatedPokemon.Pokemon.Id}");
            }

            // Get atackers
            IEnumerable <PokemonData> selectedAttackers = getPokeAttackers(defender.MotivatedPokemon.Pokemon, GlobalVars.Gyms.Attackers);
            var pokeAttackers    = selectedAttackers as PokemonData[] ?? selectedAttackers.ToArray();
            var pokeAttackersIds = selectedAttackers.Select(x => x.Id);

            if (selectedAttackers.Count() < 6)
            {
                Logger.ColoredConsoleWrite(gymColorLog, "(Gym) Not enougth pokemons to fight.");
                return(BattleState.StateUnset);
            }

            Logger.ColoredConsoleWrite(gymColorLog, "(Gym) Defender: " + GymsLogic.strPokemon(defender.MotivatedPokemon.Pokemon) + $" [{defender.TrainerPublicProfile.Name} ({defender.TrainerPublicProfile.Level})]");
            GymsLogic.ShowPokemons(selectedAttackers);

            while (currentDefender < defenders.Count())
            {
                try
                {
                    // Initialization of attach agains a defender
                    gymStartSessionResponse = GymBattleStartSession(client, gym, defenders[currentDefender].Id, pokeAttackersIds);
                }
                catch (Exception ex)
                {
                    Logger.ExceptionInfo($"Can't start battle against defender {currentDefender}: " + ex.Message);
                    break;
                }

                if (gymStartSessionResponse == null || gymStartSessionResponse.Battle == null || gymStartSessionResponse.Result != GymStartSessionResponse.Types.Result.Success)
                {
                    return(BattleState.StateUnset);
                }

                // Battle loop
                if (gymStartSessionResponse.Battle.BattleLog.State == BattleState.Active)
                {
                    //Logger.ColoredConsoleWrite(gymColorLog, "(Gym) Battle Started");
                    RandomHelper.RandomSleep(2000);

                    // Attack each defender
                    BattleState attackDefender = AttackDefender(gymStartSessionResponse, client, gym);
                    if (attackDefender == BattleState.Victory)
                    {
                        currentDefender++;
                    }
                    else
                    {
                        return(attackDefender);
                    }
                }
            }
            return(BattleState.Victory);
        }