Skip to content

Commit

Permalink
[BUGFIX] Catch Pokemon while walking to fort (#979)
Browse files Browse the repository at this point in the history
Resolves: #821
  • Loading branch information
binarydepartment authored and douglascamata committed Jul 26, 2016
1 parent 1ac2926 commit ac09541
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 9 additions & 6 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@


class PokemonGoBot(object):

@property
def position(self):
return (i2f(self.api._position_lat), i2f(self.api._position_lng), 0)
Expand All @@ -40,10 +40,13 @@ def start(self):

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

def process_cells(self, work_on_forts=True):
location = self.position[0:2]
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 @@ -131,7 +134,7 @@ def find_close_cells(self, lat, lng):
self.update_web_location(map_cells)
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 @@ -201,8 +204,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 distance(i2f(self.api._position_lat), i2f(self.api._position_lng), lat, lng) > 10:
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 ac09541

Please sign in to comment.