Skip to content

Commit

Permalink
Merging some unnecessary methods and renaming take_step on the bot to… (
Browse files Browse the repository at this point in the history
#1360)

* Merging some unnecessary methods and renaming take_step on the bot to tick

* Merging variable definition
  • Loading branch information
elicwhite authored and douglascamata committed Jul 28, 2016
1 parent 8f77214 commit 41ccf9e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 27 deletions.
2 changes: 1 addition & 1 deletion pokecli.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def main():
logger.log('Starting PokemonGo Bot....', 'green')

while True:
bot.take_step()
bot.tick()

except KeyboardInterrupt:
logger.log('Exiting PokemonGo Bot', 'red')
Expand Down
51 changes: 25 additions & 26 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,27 @@ def start(self):
self.navigator = SpiralNavigator(self)
random.seed()

def take_step(self):
self.process_cells()
def tick(self):
self.cell = self.get_meta_cell()

def process_cells(self):
# Check if session token has expired
self.check_session(self.position[0:2])

workers = [
PokemonTransferWorker,
EvolveAllWorker,
RecycleItemsWorker,
CatchVisiblePokemonWorker,
SpinNearestFortWorker
]

for worker in workers:
if worker(self).work() == WorkerResult.RUNNING:
return

self.navigator.take_step()

def get_meta_cell(self):
location = self.position[0:2]
cells = self.find_close_cells(*location)

Expand All @@ -63,9 +80,11 @@ def process_cells(self):
if "catchable_pokemons" in cell and len(cell["catchable_pokemons"]):
catchable_pokemons += cell["catchable_pokemons"]

# Have the worker treat the whole area as a single cell.
self.work_on_cell({"forts": forts, "wild_pokemons": wild_pokemons,
"catchable_pokemons": catchable_pokemons}, location)
return {
"forts": forts,
"wild_pokemons": wild_pokemons,
"catchable_pokemons": catchable_pokemons
}

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 @@ -157,26 +176,6 @@ def find_close_cells(self, lat, lng):
)
return map_cells

def work_on_cell(self, cell, position):
self.cell = cell

# Check if session token has expired
self.check_session(position)

workers = [
PokemonTransferWorker,
EvolveAllWorker,
RecycleItemsWorker,
CatchVisiblePokemonWorker,
SpinNearestFortWorker
]

for worker in workers:
if worker(self).work() == WorkerResult.RUNNING:
return

self.navigator.take_step()

def _setup_logging(self):
self.log = logging.getLogger(__name__)
# log settings
Expand Down

0 comments on commit 41ccf9e

Please sign in to comment.