def level_up_rewards_request(api, account): time.sleep(random.uniform(2, 3)) try: req = api.create_request() req.level_up_rewards(level=account['level']) req.check_challenge() req.get_hatched_eggs() add_get_inventory_request(req, account) req.check_awarded_badges() req.download_settings() req.get_buddy_walked() rewards_response = req.call() update_account_from_response(account, rewards_response) if ('responses' in rewards_response) and ('LEVEL_UP_REWARDS' in rewards_response['responses']): reward_details = rewards_response['responses']['LEVEL_UP_REWARDS'] return reward_details.get('result', -1) except Exception as e: log.error('Exception while requesting level up rewards: %s', repr(e)) return False
def release(api, cpid, account): try: req = api.create_request() req.release_pokemon(pokemon_id=cpid) req.check_challenge() req.get_hatched_eggs() add_get_inventory_request(req, account) req.check_awarded_badges() req.download_settings() req.get_buddy_walked() release_result = req.call() update_account_from_response(account, release_result) if (release_result is not None and 'RELEASE_POKEMON' in release_result['responses']): release_result = release_result['responses']['RELEASE_POKEMON'][ 'result'] if int(release_result) == 1: return True else: log.error('Failed to release Pokemon with result code: %s.', release_result) except Exception as e: log.error('Exception while releasing Pokemon. Error: %s', repr(e)) return False
def level_up_rewards_request(pgacc, level): time.sleep(random.uniform(2, 3)) try: rewards_response = pgacc.req_level_up_rewards(level) if 'LEVEL_UP_REWARDS' in rewards_response: reward_details = rewards_response['LEVEL_UP_REWARDS'] return reward_details.get('result', -1) except Exception as e: log.error('Exception while requesting level up rewards: %s', repr(e)) return False
def release(pgacc, cpid): try: release_result = pgacc.req_release_pokemon(cpid) if (release_result is not None and 'RELEASE_POKEMON' in release_result): release_result = release_result['RELEASE_POKEMON']['result'] if int(release_result) == 1: return True else: log.error('Failed to release Pokemon with result code: %s.', release_result) except Exception as e: log.error('Exception while releasing Pokemon. Error: %s', repr(e)) return False
def level_up_rewards_request(api, level, username, inventory): time.sleep(random.uniform(2, 3)) try: req = api.create_request() req.level_up_rewards(level=level) req.check_challenge() req.get_hatched_eggs() req.get_inventory() req.check_awarded_badges() req.download_settings() req.get_buddy_walked() rewards_response = req.call() if ('responses' in rewards_response) and ('LEVEL_UP_REWARDS' in rewards_response['responses']): inventory.update(get_player_inventory(rewards_response)) reward_details = rewards_response['responses']['LEVEL_UP_REWARDS'] return reward_details.get('result', -1) except Exception as e: log.error('Exception while requesting level up rewards: %s', repr(e)) return False
def catch(api, encounter_id, spawn_point_id, account): # Try to catch pokemon, but don't get stuck. rv = {'catch_status': 'fail', 'reason': "Unknown reason.", 'attempts': 1} while rv['attempts'] < 3: time.sleep(random.uniform(2, 3)) try: # Randomize throwing parameters. Some stuff to read: # https://pokemongo.gamepress.gg/catch-mechanics # https://www.reddit.com/r/pokemongodev/comments/4vlnwj/pokemon_go_catch_mechanicsformula_discussion/ normalized_reticle_size = 1.1 + 0.70 * random.random() spin_modifier = 0.4 + 0.4 * random.random() # Determine best ball - we know for sure that we have at least one inventory = account.get('inventory', {}) ball = ITEM_ULTRA_BALL if inventory.get( ITEM_ULTRA_BALL, 0) > 0 else (ITEM_GREAT_BALL if inventory.get( ITEM_GREAT_BALL, 0) > 0 else ITEM_POKE_BALL) req = api.create_request() req.catch_pokemon(encounter_id=encounter_id, pokeball=ball, normalized_reticle_size=normalized_reticle_size, spawn_point_id=spawn_point_id, hit_pokemon=1, spin_modifier=spin_modifier, normalized_hit_position=1.0) req.check_challenge() req.get_hatched_eggs() add_get_inventory_request(req, account) req.check_awarded_badges() req.download_settings() req.get_buddy_walked() catch_result = req.call() # Inventory changed on throwing a ball. update_account_from_response(account, catch_result) if (catch_result is not None and 'CATCH_POKEMON' in catch_result['responses']): catch_status = catch_result['responses']['CATCH_POKEMON'][ 'status'] # Success! if catch_status == 1: # Check inventory for caught Pokemon capture_id = catch_result['responses']['CATCH_POKEMON'][ 'captured_pokemon_id'] pid = get_captured_pokemon_id_from_inventory( capture_id, catch_result) if pid: # Set ID of caught Pokemon rv['catch_status'] = 'success' rv['pid'] = pid rv['capture_id'] = capture_id else: rv['reason'] = "Could not find caught Pokemon in inventory." return rv # Broke free! if catch_status == 2: log.debug('Catch attempt %s failed. It broke free!', rv['attempts']) # Ran away! if catch_status == 3: rv['reason'] = "Pokemon ran away!" return rv # Dodged! if catch_status == 4: log.debug('Catch attempt %s failed. It dodged the ball!', rv['attempts']) else: log.error( 'Catch attempt %s failed. The api response was empty!', rv['attempts']) except Exception as e: log.error('Catch attempt %s failed. API exception: %s', rv['attempts'], repr(e)) rv['attempts'] += 1 if rv['attempts'] >= 3: rv['attempts'] -= 1 rv['reason'] = "Giving up." return rv
def catch(pgacc, encounter_id, spawn_point_id): # Try to catch pokemon, but don't get stuck. rv = {'catch_status': 'fail', 'reason': "Unknown reason.", 'attempts': 1} while rv['attempts'] < 3 and pgacc.inventory_balls > 0: time.sleep(random.uniform(2, 3)) try: # Randomize throwing parameters. Some stuff to read: # https://pokemongo.gamepress.gg/catch-mechanics # https://www.reddit.com/r/pokemongodev/comments/4vlnwj/pokemon_go_catch_mechanicsformula_discussion/ normalized_reticle_size = 1.1 + 0.70 * random.random() spin_modifier = 0.4 + 0.4 * random.random() # Determine best ball - we know for sure that we have at least one inventory = pgacc.inventory ball = ITEM_ULTRA_BALL if inventory.get( ITEM_ULTRA_BALL, 0) > 0 else (ITEM_GREAT_BALL if inventory.get( ITEM_GREAT_BALL, 0) > 0 else ITEM_POKE_BALL) catch_result = pgacc.req_catch_pokemon(encounter_id, spawn_point_id, ball, normalized_reticle_size, spin_modifier) if (catch_result is not None and 'CATCH_POKEMON' in catch_result): catch_status = catch_result['CATCH_POKEMON'].status # Success! if catch_status == 1: rv['catch_status'] = 'success' if pgacc.last_caught_pokemon: # Set ID of caught Pokemon rv['pid'] = pgacc.last_caught_pokemon['pokemon_id'] return rv # Broke free! if catch_status == 2: log.debug('GXP: Catch attempt %s failed. It broke free!', rv['attempts']) # Ran away! if catch_status == 3: rv['reason'] = "Pokemon ran away!" return rv # Dodged! if catch_status == 4: log.debug( 'GXP: Catch attempt %s failed. It dodged the ball!', rv['attempts']) else: log.error( 'GXP: Catch attempt %s failed. The api response was empty!', rv['attempts']) except Exception as e: log.error('GXP: Catch attempt %s failed. API exception: %s', rv['attempts'], repr(e)) rv['attempts'] += 1 if rv['attempts'] >= 3: rv['attempts'] -= 1 rv['reason'] = "Giving up." return rv