Skip to content

Commit

Permalink
[BUGFIX] Catch Pokemon while walking to fort
Browse files Browse the repository at this point in the history
Resolves: #821
  • Loading branch information
binarydepartment committed Jul 26, 2016
1 parent 4555466 commit 525aaf3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
20 changes: 14 additions & 6 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@

import logger
from cell_workers import PokemonCatchWorker, SeenFortWorker, MoveToFortWorker, InitialTransferWorker, EvolveAllWorker
from cell_workers.utils import distance, get_cellid, encode
from cell_workers.utils import distance, get_cellid, encode, i2f
from human_behaviour import sleep
from item_list import Item
from spiral_navigator import SpiralNavigator


class PokemonGoBot(object):

@property
def current_coordinates_as_float(self):
return i2f(self.api._position_lat), i2f(self.api._position_lng)

def __init__(self, config):
self.config = config
self.pokemon_list = json.load(open('data/pokemon.json'))
Expand All @@ -34,10 +39,13 @@ def start(self):

def take_step(self):
location = self.navigator.take_step()
cells = self.find_close_cells(*location[0:2])
self.process_cells(work_on_forts=True)

def process_cells(self, work_on_forts=True):
location = self.current_coordinates_as_float
cells = self.find_close_cells(*location)
for cell in cells:
self.work_on_cell(cell, location)
self.work_on_cell(cell, location, work_on_forts)

def update_web_location(self, cells=[], lat=None, lng=None, alt=None):
# we can call the function with no arguments and still get the position and map_cells
Expand Down Expand Up @@ -119,7 +127,7 @@ def find_close_cells(self, lat, lng):
self.update_web_location(map_cells,lat,lng)
return map_cells

def work_on_cell(self, cell, position):
def work_on_cell(self, cell, position, work_on_forts=1):
# Check if session token has expired
self.check_session(position)

Expand Down Expand Up @@ -189,8 +197,8 @@ def work_on_cell(self, cell, position):
for pokemon in cell['wild_pokemons']:
if self.catch_pokemon(pokemon) == PokemonCatchWorker.NO_POKEBALLS:
break
if (self.config.mode == "all" or
self.config.mode == "farm"):
if ((self.config.mode == "all" or
self.config.mode == "farm") and work_on_forts):
if 'forts' in cell:
# Only include those with a lat/long
forts = [fort
Expand Down
2 changes: 2 additions & 0 deletions pokemongo_bot/cell_workers/move_to_fort_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ def work(self):
while True:
if step_walker.step():
break
else:
self.bot.process_cells(work_on_forts=False)

else:
self.api.set_position(*position)
Expand Down

0 comments on commit 525aaf3

Please sign in to comment.