Skip to content

Commit

Permalink
Merge pull request #3 from PokemonGoF/dev
Browse files Browse the repository at this point in the history
update branch
  • Loading branch information
Surceis authored Jul 27, 2016
2 parents 202a9a5 + 519f77a commit 59cf520
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 41 deletions.
44 changes: 3 additions & 41 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from pgoapi.utilities import f2i

import logger
from cell_workers import PokemonCatchWorker, SeenFortWorker, MoveToFortWorker, InitialTransferWorker, EvolveAllWorker
from cell_workers import CatchVisiblePokemonWorker, PokemonCatchWorker, SeenFortWorker, MoveToFortWorker, InitialTransferWorker, EvolveAllWorker
from cell_workers.utils import distance, get_cellid, encode, i2f
from human_behaviour import sleep
from item_list import Item
Expand Down Expand Up @@ -164,37 +164,9 @@ def work_on_cell(self, cell, position, work_on_forts=1):
worker.work()
self.config.evolve_all = []

worker = CatchVisiblePokemonWorker(self, cell)
worker.work()

if (self.config.mode == "all" or self.config.mode ==
"poke") and 'catchable_pokemons' in cell and len(cell[
'catchable_pokemons']) > 0:
logger.log('Something rustles nearby!')
# Sort all by distance from current pos- eventually this should
# build graph & A* it
cell['catchable_pokemons'].sort(
key=
lambda x: distance(self.position[0], self.position[1], x['latitude'], x['longitude']))

user_web_catchable = 'web/catchable-%s.json' % (self.config.username)
for pokemon in cell['catchable_pokemons']:
with open(user_web_catchable, 'w') as outfile:
json.dump(pokemon, outfile)

with open(user_web_catchable, 'w') as outfile:
json.dump({}, outfile)

self.catch_pokemon(cell['catchable_pokemons'][0])
return

if (self.config.mode == "all" or self.config.mode == "poke"
) and 'wild_pokemons' in cell and len(cell['wild_pokemons']) > 0:
# Sort all by distance from current pos- eventually this should
# build graph & A* it
cell['wild_pokemons'].sort(
key=
lambda x: distance(self.position[0], self.position[1], x['latitude'], x['longitude']))
self.catch_pokemon(cell['wild_pokemons'][0])
return
if ((self.config.mode == "all" or
self.config.mode == "farm") and work_on_forts):
if 'forts' in cell:
Expand Down Expand Up @@ -318,16 +290,6 @@ def _print_character_info(self):

logger.log('')

def catch_pokemon(self, pokemon):
worker = PokemonCatchWorker(pokemon, self)
return_value = worker.work()

if return_value == PokemonCatchWorker.BAG_FULL:
worker = InitialTransferWorker(self)
worker.work()

return return_value

def drop_item(self, item_id, count):
self.api.recycle_inventory_item(item_id=item_id, count=count)
inventory_req = self.api.call()
Expand Down
1 change: 1 addition & 0 deletions pokemongo_bot/cell_workers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
from move_to_fort_worker import MoveToFortWorker
from initial_transfer_worker import InitialTransferWorker
from evolve_all_worker import EvolveAllWorker
from catch_visible_pokmeon_worker import CatchVisiblePokemonWorker
53 changes: 53 additions & 0 deletions pokemongo_bot/cell_workers/catch_visible_pokmeon_worker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

import json
from utils import distance, format_dist, i2f
from pokemongo_bot.human_behaviour import sleep
from pokemongo_bot import logger
from pokemongo_bot.step_walker import StepWalker
from pokemongo_bot.cell_workers import PokemonCatchWorker

class CatchVisiblePokemonWorker(object):
def __init__(self, bot, cell):
self.bot = bot
self.cell = cell;
self.api = bot.api
self.config = bot.config
self.position = bot.position

def work(self):
config_wants_pokmeon = self.config.mode == "all" or self.config.mode == "poke"

if not config_wants_pokmeon:
return

if 'catchable_pokemons' in self.cell and len(self.cell['catchable_pokemons']) > 0:
logger.log('Something rustles nearby!')
# Sort all by distance from current pos- eventually this should
# build graph & A* it
self.cell['catchable_pokemons'].sort(
key=
lambda x: distance(self.position[0], self.position[1], x['latitude'], x['longitude']))

user_web_catchable = 'web/catchable-%s.json' % (self.config.username)
for pokemon in self.cell['catchable_pokemons']:
with open(user_web_catchable, 'w') as outfile:
json.dump(pokemon, outfile)

with open(user_web_catchable, 'w') as outfile:
json.dump({}, outfile)

return self.catch_pokemon(self.cell['catchable_pokemons'][0])

if 'wild_pokemons' in self.cell and len(self.cell['wild_pokemons']) > 0:
# Sort all by distance from current pos- eventually this should
# build graph & A* it
self.cell['wild_pokemons'].sort(
key=
lambda x: distance(self.position[0], self.position[1], x['latitude'], x['longitude']))
return self.catch_pokemon(self.cell['wild_pokemons'][0])

def catch_pokemon(self, pokemon):
worker = PokemonCatchWorker(pokemon, self.bot)
return_value = worker.work()

return return_value

0 comments on commit 59cf520

Please sign in to comment.