-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from PokemonGoF/dev
update branch
- Loading branch information
Showing
3 changed files
with
57 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
pokemongo_bot/cell_workers/catch_visible_pokmeon_worker.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |