diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index 255b1afd65..21954d62bb 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -27,7 +27,7 @@ class PokemonGoBot(object): @property def position(self): - return (i2f(self.api._position_lat), i2f(self.api._position_lng), 0) + return self.api._position_lat, self.api._position_lng, 0 def __init__(self, config): self.config = config @@ -69,9 +69,9 @@ def process_cells(self, work_on_forts=True): 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 if lat == None: - lat = i2f(self.api._position_lat) + lat = self.api._position_lat if lng == None: - lng = i2f(self.api._position_lng) + lng = self.api._position_lng if alt == None: alt = 0 @@ -272,7 +272,12 @@ def _print_character_info(self): currency_1 = "0" currency_2 = "0" - player = response_dict['responses']['GET_PLAYER']['player_data'] + if response_dict: + player = response_dict['responses']['GET_PLAYER']['player_data'] + else: + logger.log("The API didn't return player info, servers are unstable - retrying.", 'red') + sleep(5) + self._print_character_info() # @@@ TODO: Convert this to d/m/Y H:M:S creation_date = datetime.datetime.fromtimestamp( @@ -426,7 +431,7 @@ def _set_starting_position(self): has_position = True return except: - logger.log('[x] The location given using -l could not be parsed. Checking for a cached location.') + logger.log('[x] The location given in the config could not be parsed. Checking for a cached location.') pass if self.config.location_cache and not has_position: @@ -460,20 +465,17 @@ def _set_starting_position(self): def _get_pos_by_name(self, location_name): # Check if the given location is already a coordinate. if ',' in location_name: - possibleCoordinates = re.findall("[-]?\d{1,3}[.]\d{6,7}", location_name) - if len(possibleCoordinates) == 2: + possible_coordinates = re.findall("[-]?\d{1,3}[.]\d{6,7}", location_name) + if len(possible_coordinates) == 2: # 2 matches, this must be a coordinate. We'll bypass the Google geocode so we keep the exact location. logger.log( '[x] Coordinates found in passed in location, not geocoding.') - return (float(possibleCoordinates[0]), float(possibleCoordinates[1]), float("0.0")) + return float(possible_coordinates[0]), float(possible_coordinates[1]), float("0.0") geolocator = GoogleV3(api_key=self.config.gmapkey) loc = geolocator.geocode(location_name, timeout=10) - #self.log.info('Your given location: %s', loc.address.encode('utf-8')) - #self.log.info('lat/long/alt: %s %s %s', loc.latitude, loc.longitude, loc.altitude) - - return (loc.latitude, loc.longitude, loc.altitude) + return float(loc.latitude), float(loc.longitude), float(loc.altitude) def heartbeat(self): # Remove forts that we can now spin again. diff --git a/pokemongo_bot/cell_workers/pokemon_catch_worker.py b/pokemongo_bot/cell_workers/pokemon_catch_worker.py index 8c9ed14483..38ede1b84f 100644 --- a/pokemongo_bot/cell_workers/pokemon_catch_worker.py +++ b/pokemongo_bot/cell_workers/pokemon_catch_worker.py @@ -20,33 +20,38 @@ def __init__(self, pokemon, bot): self.pokemon_list = bot.pokemon_list self.item_list = bot.item_list self.inventory = bot.inventory + self.spawn_point_guid = '' + self.response_key = '' + self.response_status_key = '' def work(self): + encounter_id = self.pokemon['encounter_id'] - spawnpoint_id = self.pokemon['spawnpoint_id'] - player_latitude = self.pokemon['latitude'] - player_longitude = self.pokemon['longitude'] - self.api.encounter(encounter_id=encounter_id, spawnpoint_id=spawnpoint_id, - player_latitude=player_latitude, player_longitude=player_longitude) - response_dict = self.api.call() + + response_dict = self.create_encounter_api_call() if response_dict and 'responses' in response_dict: - if 'ENCOUNTER' in response_dict['responses']: - if 'status' in response_dict['responses']['ENCOUNTER']: - if response_dict['responses']['ENCOUNTER']['status'] is 7: + if self.response_key in response_dict['responses']: + if self.response_status_key in response_dict['responses'][self.response_key]: + if response_dict['responses'][self.response_key][self.response_status_key] is 7: if self.config.initial_transfer: logger.log('Pokemon Bag is full!', 'red') return PokemonCatchWorker.BAG_FULL else: raise RuntimeError('Pokemon Bag is full!') - if response_dict['responses']['ENCOUNTER']['status'] is 1: + if response_dict['responses'][self.response_key][self.response_status_key] is 1: cp = 0 total_IV = 0 - if 'wild_pokemon' in response_dict['responses']['ENCOUNTER']: - pokemon = response_dict['responses']['ENCOUNTER']['wild_pokemon'] - catch_rate = response_dict['responses']['ENCOUNTER']['capture_probability']['capture_probability'] # 0 = pokeballs, 1 great balls, 3 ultra balls - + if 'wild_pokemon' in response_dict['responses'][self.response_key] or 'pokemon_data' in \ + response_dict['responses'][self.response_key]: + if self.response_key == 'ENCOUNTER': + pokemon = response_dict['responses'][self.response_key]['wild_pokemon'] + else: + pokemon = response_dict['responses'][self.response_key] + + catch_rate = response_dict['responses'][self.response_key]['capture_probability'][ + 'capture_probability'] # 0 = pokeballs, 1 great balls, 3 ultra balls if 'pokemon_data' in pokemon and 'cp' in pokemon['pokemon_data']: cp = pokemon['pokemon_data']['cp'] @@ -126,7 +131,7 @@ def work(self): self.api.use_item_capture( item_id=berry_id, encounter_id = encounter_id, - spawn_point_guid = spawnpoint_id + spawn_point_id = self.spawn_point_guid ) response_dict = self.api.call() if response_dict and response_dict['status_code'] is 1 and 'item_capture_mult' in response_dict['responses']['USE_ITEM_CAPTURE']: @@ -164,7 +169,7 @@ def work(self): self.api.catch_pokemon(encounter_id=encounter_id, pokeball=pokeball, normalized_reticle_size=1.950, - spawn_point_guid=spawnpoint_id, + spawn_point_id=self.spawn_point_guid, hit_pokemon=1, spin_modifier=1, NormalizedHitPosition=1) @@ -377,3 +382,26 @@ def _get_release_config_for(self, pokemon): if not release_config: release_config = {} return release_config + + def create_encounter_api_call(self): + + encounter_id = self.pokemon['encounter_id'] + player_latitude = self.pokemon['latitude'] + player_longitude = self.pokemon['longitude'] + + if 'spawn_point_id' in self.pokemon: + spawn_point_id = self.pokemon['spawn_point_id'] + self.spawn_point_guid = spawn_point_id + self.response_key = 'ENCOUNTER' + self.response_status_key = 'status' + self.api.encounter(encounter_id=encounter_id, spawn_point_id=spawn_point_id, + player_latitude=player_latitude, player_longitude=player_longitude) + else: + fort_id = self.pokemon['fort_id'] + self.spawn_point_guid = fort_id + self.response_key = 'DISK_ENCOUNTER' + self.response_status_key = 'result' + self.api.disk_encounter(encounter_id=encounter_id, fort_id=fort_id, + player_latitude=player_latitude, player_longitude=player_longitude) + + return self.api.call() \ No newline at end of file diff --git a/pokemongo_bot/cell_workers/seen_fort_worker.py b/pokemongo_bot/cell_workers/seen_fort_worker.py index a48baab781..b22a9ff264 100644 --- a/pokemongo_bot/cell_workers/seen_fort_worker.py +++ b/pokemongo_bot/cell_workers/seen_fort_worker.py @@ -6,6 +6,7 @@ from pokemongo_bot import logger from pokemongo_bot.human_behaviour import sleep +from pokemongo_bot.cell_workers import PokemonCatchWorker from utils import format_time @@ -17,6 +18,11 @@ def __init__(self, fort, bot): self.position = bot.position self.config = bot.config self.item_list = bot.item_list + self.pokemon_list = bot.pokemon_list + self.inventory = bot.inventory + self.current_inventory = bot.current_inventory + self.item_inventory_count = bot.item_inventory_count + self.metrics = bot.metrics self.rest_time = 50 def work(self): @@ -34,9 +40,28 @@ def work(self): fort_name = fort_details['name'].encode('utf8', 'replace') else: fort_name = 'Unknown' - logger.log('Now at Pokestop: ' + fort_name + ' - Spinning...', + logger.log('Now at Pokestop: ' + fort_name, 'cyan') - sleep(2) + if self.config.mode != 'farm' and 'lure_info' in self.fort: + # Check if the lure has a pokemon active + if 'encounter_id' in self.fort['lure_info']: + logger.log("Found a lure on this pokestop! Catching pokemon...", 'cyan') + + pokemon = { + 'encounter_id': self.fort['lure_info']['encounter_id'], + 'fort_id': self.fort['id'], + 'latitude': self.fort['latitude'], + 'longitude': self.fort['longitude'] + } + + self.catch_pokemon(pokemon) + + else: + logger.log('Found a lure, but there is no pokemon present.', 'yellow') + sleep(2) + + logger.log('Spinning ...', 'cyan') + self.api.fort_search(fort_id=self.fort['id'], fort_latitude=lat, fort_longitude=lng, @@ -120,6 +145,17 @@ def work(self): sleep(2) return 0 + def catch_pokemon(self, pokemon): + worker = PokemonCatchWorker(pokemon, self.bot) + return_value = worker.work() + + # Disabled for now, importing InitialTransferWorker fails. + # if return_value == PokemonCatchWorker.BAG_FULL: + # worker = InitialTransferWorker(self) + # worker.work() + + return return_value + @staticmethod def closest_fort(current_lat, current_long, forts): print x diff --git a/pokemongo_bot/polyline_stepper.py b/pokemongo_bot/polyline_stepper.py index df7157e153..b6dbd78d44 100644 --- a/pokemongo_bot/polyline_stepper.py +++ b/pokemongo_bot/polyline_stepper.py @@ -2,7 +2,6 @@ from math import ceil import logger -from cell_workers.utils import i2f from human_behaviour import sleep from polyline_walker import PolylineWalker @@ -10,7 +9,7 @@ class PolylineStepper(Stepper): def _walk_to(self, speed, lat, lng, alt): - origin = ','.join([str(i2f(self.api._position_lat)), str(i2f(self.api._position_lng))]) + origin = ','.join([str(self.api._position_lat), str(self.api._position_lng)]) destination = ','.join([str(lat), str(lng)]) polyline_walker = PolylineWalker(origin, destination, speed) proposed_origin = polyline_walker.points[0] @@ -29,7 +28,7 @@ def _walk_to(self, speed, lat, lng, alt): cLat, cLng = polyline_walker.get_pos()[0] self.api.set_position(cLat, cLng, alt) self.bot.heartbeat() - self._work_at_position(i2f(self.api._position_lat), i2f(self.api._position_lng), alt, False) + self._work_at_position(self.api._position_lat, self.api._position_lng, alt, False) sleep(1) # sleep one second plus a random delta if proposed_lat != self.api._position_lat and proposed_lng != self.api._position_lng: logger.log('[#] Using _old_walk_to to go from the proposed destination : {} to {}' diff --git a/pokemongo_bot/spiral_navigator.py b/pokemongo_bot/spiral_navigator.py index ca89b6e6ae..b07c8c2020 100644 --- a/pokemongo_bot/spiral_navigator.py +++ b/pokemongo_bot/spiral_navigator.py @@ -62,15 +62,15 @@ def take_step(self): ) dist = distance( - i2f(self.api._position_lat), - i2f(self.api._position_lng), + self.api._position_lat, + self.api._position_lng, point['lat'], point['lng'] ) if self.cnt == 1: - logger.log('Walking from ' + str((i2f(self.api._position_lat), i2f( - self.api._position_lng))) + " to " + str([point['lat'], point['lng']]) + " " + format_dist(dist, + logger.log('Walking from ' + str((self.api._position_lat, + self.api._position_lng)) + " to " + str([point['lat'], point['lng']]) + " " + format_dist(dist, self.config.distance_unit)) if step_walker.step(): @@ -79,8 +79,8 @@ def take_step(self): self.api.set_position(point['lat'], point['lng']) if distance( - i2f(self.api._position_lat), - i2f(self.api._position_lng), + self.api._position_lat, + self.api._position_lng, point['lat'], point['lng'] ) <= 1 or (self.config.walk > 0 and step_walker == None): diff --git a/requirements.txt b/requirements.txt index f8e4ae8370..cd60f8c2bd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ --e git+https://github.com/tejado/pgoapi.git@v1.1.0#egg=pgoapi +-e git+https://github.com/tejado/pgoapi.git@81e786cabf027a1c8fbd1e9a07e1c11aa3d8ee8b#egg=pgoapi geopy==1.11.0 protobuf==3.0.0b4 requests==2.10.0