-
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.
Extract CatchLuredPokemonWorker from PokemonCatchWorker and improved …
…worker order (#1627) * extracted lure catch worker from pokemon catch * removing information less logs
- Loading branch information
1 parent
9bc0abe
commit 4a8bde0
Showing
7 changed files
with
65 additions
and
39 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
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,57 @@ | ||
|
||
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 CatchLuredPokemonWorker(object): | ||
def __init__(self, bot): | ||
self.bot = bot | ||
self.cell = bot.cell; | ||
self.api = bot.api | ||
self.config = bot.config | ||
self.position = bot.position | ||
|
||
def work(self): | ||
if not self.config.catch_pokemon: | ||
return | ||
|
||
lured_pokemon = self.get_lured_pokemon() | ||
if lured_pokemon: | ||
self.catch_pokemon(lured_pokemon) | ||
|
||
def get_lured_pokemon(self): | ||
forts = self.bot.get_forts(order_by_distance=True) | ||
|
||
if len(forts) == 0: | ||
return False | ||
|
||
fort = forts[0] | ||
|
||
self.api.fort_details(fort_id=fort['id'], | ||
latitude=fort['latitude'], | ||
longitude=fort['longitude']) | ||
|
||
response_dict = self.api.call() | ||
fort_details = response_dict.get('responses', {}).get('FORT_DETAILS', {}) | ||
fort_name = fort_details.get('name', 'Unknown').encode('utf8', 'replace') | ||
|
||
encounter_id = fort.get('lure_info', {}).get('encounter_id', None) | ||
|
||
pokemon = { | ||
'encounter_id': encounter_id, | ||
'fort_id': fort['id'], | ||
'latitude': fort['latitude'], | ||
'longitude': fort['longitude'] | ||
} | ||
|
||
return pokemon | ||
|
||
def catch_pokemon(self, pokemon): | ||
worker = PokemonCatchWorker(pokemon, self.bot) | ||
return_value = worker.work() | ||
|
||
return return_value |
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
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
Creates an unnecessary blank log line every time the bot walks.