def _execute_pokemon_evolve(self, pokemon, cache): if pokemon.name in cache: return False response_dict = self.api.evolve_pokemon(pokemon_id=pokemon.id) if response_dict.get('responses', {}).get('EVOLVE_POKEMON', {}).get('result', 0) == 1: self.emit_event( 'pokemon_evolved', formatted="Successfully evolved {pokemon} with CP {cp} and IV {iv}!", data={ 'pokemon': pokemon.name, 'iv': pokemon.iv, 'cp': pokemon.cp, 'ncp': '?', 'dps': '?', 'xp': '?' } ) awarded_candies = response_dict.get('responses', {}).get('EVOLVE_POKEMON', {}).get('candy_awarded', 0) inventory.candies().get(pokemon.pokemon_id).consume(pokemon.evolution_cost - awarded_candies) inventory.pokemons().remove(pokemon.id) pokemon = Pokemon(response_dict.get('responses', {}).get('EVOLVE_POKEMON', {}).get('evolved_pokemon_data', {})) inventory.pokemons().add(pokemon) sleep(self.evolve_speed) return True else: # cache pokemons we can't evolve. Less server calls cache[pokemon.name] = 1 sleep(0.7) return False
def setUp(self): self.bot = {} self.config = {} self.task = NicknamePokemon(self.bot, self.config) self.assertIs(self.task.bot, self.bot) self.assertIs(self.task.config, self.config) self.pokemons = [ Pokemon({ "num_upgrades": 2, "move_1": 210, "move_2": 69, "pokeball": 2, "favorite": 1, "pokemon_id": 42, "battles_attacked": 4, "stamina": 76, "stamina_max": 76, "individual_attack": 9, "individual_defense": 4, "individual_stamina": 8, "cp_multiplier": 0.4627983868122101, "additional_cp_multiplier": 0.018886566162109375, "cp": 653, "nickname": "Golb", "id": 13632861873471324, "pokemon_display": { "shiny": False } }), Pokemon({ "move_1": 221, "move_2": 129, "pokemon_id": 19, "cp": 106, "individual_attack": 6, "stamina_max": 22, "individual_defense": 14, "cp_multiplier": 0.37523558735847473, "id": 7841053399, "pokemon_display": { "shiny": False } }), ]
def work(self, response_dict=None): response_dict = response_dict or self.create_encounter_api_call() # validate response if not response_dict: return WorkerResult.ERROR responses = response_dict['responses'] response = responses[self.response_key] if response[ self. response_status_key] != ENCOUNTER_STATUS_SUCCESS and response[ self.response_status_key] != INCENSE_ENCOUNTER_AVAILABLE: if response[ self.response_status_key] == ENCOUNTER_STATUS_NOT_IN_RANGE: self.emit_event('pokemon_not_in_range', formatted='Pokemon went out of range!') elif response[ self. response_status_key] == INCENSE_ENCOUNTER_NOT_AVAILABLE: self.emit_event( 'pokemon_not_in_range', formatted='Incensed Pokemon went out of range!') elif response[ self. response_status_key] == ENCOUNTER_STATUS_POKEMON_INVENTORY_FULL: self.emit_event( 'pokemon_inventory_full', formatted='Your Pokemon inventory is full! Could not catch!' ) return WorkerResult.ERROR # get pokemon data pokemon_data = response['wild_pokemon'][ 'pokemon_data'] if 'wild_pokemon' in response else response[ 'pokemon_data'] pokemon = Pokemon(pokemon_data) # check if vip pokemon is_vip = self._is_vip_pokemon(pokemon) # skip ignored pokemon if (not self._should_catch_pokemon(pokemon) and not is_vip) or self.bot.catch_disabled: if not hasattr(self.bot, 'skipped_pokemon'): self.bot.skipped_pokemon = [] # Check if pokemon already skipped and suppress alert if so for skipped_pokemon in self.bot.skipped_pokemon: if pokemon.pokemon_id == skipped_pokemon.pokemon_id and \ pokemon.cp_exact == skipped_pokemon.cp_exact and \ pokemon.ivcp == skipped_pokemon.ivcp: return WorkerResult.SUCCESS if self.bot.catch_disabled: self.logger.info( "Not catching {}. All catching tasks are currently disabled until {}." .format(pokemon, self.bot.catch_resume_at.strftime("%H:%M:%S"))) # Add the encounter_id to the Pokemon pokemon.encounter_id = self.pokemon['encounter_id'] self.bot.skipped_pokemon.append(pokemon) self.emit_event( 'pokemon_appeared', formatted= 'Skip ignored {pokemon}! (CP: {cp} IV: {iv} A/D/S {iv_display})', data={ 'pokemon': pokemon.name, 'cp': str(int(pokemon.cp)), 'iv': str(pokemon.iv), 'iv_display': str(pokemon.iv_display), }) return WorkerResult.SUCCESS if inventory.items().get(ITEM_POKEBALL).count < 1: if inventory.items().get(ITEM_GREATBALL).count < 1: if inventory.items().get(ITEM_ULTRABALL).count < 1: return WorkerResult.ERROR elif (not is_vip) and inventory.items().get( ITEM_ULTRABALL).count <= self.min_ultraball_to_keep: return WorkerResult.ERROR # log encounter self.emit_event( 'pokemon_appeared', formatted='A wild {} appeared! (CP: {} IV: {} A/D/S {} NCP: {})'. format( pokemon.name, pokemon.cp, pokemon.iv, pokemon.iv_display, round(pokemon.cp_percent, 2), ), data={ 'pokemon': pokemon.name, 'ncp': round(pokemon.cp_percent, 2), 'cp': pokemon.cp, 'iv': pokemon.iv, 'iv_display': pokemon.iv_display, 'encounter_id': self.pokemon['encounter_id'], 'latitude': self.pokemon['latitude'], 'longitude': self.pokemon['longitude'], 'pokemon_id': pokemon.pokemon_id }) # simulate app time.sleep(3) # check for VIP pokemon if is_vip: self.emit_event('vip_pokemon', formatted='This is a VIP pokemon. Catch!!!') # check catch limits before catch with self.bot.database as conn: c = conn.cursor() c.execute( "SELECT DISTINCT COUNT(encounter_id) FROM catch_log WHERE dated >= datetime('now','-1 day')" ) result = c.fetchone() while True: if result[0] < self.daily_catch_limit: # catch that pokemon! encounter_id = self.pokemon['encounter_id'] catch_rate_by_ball = [0] + response['capture_probability'][ 'capture_probability'] # offset so item ids match indces self._do_catch(pokemon, encounter_id, catch_rate_by_ball, is_vip=is_vip) break else: self.emit_event( 'catch_limit', formatted='WARNING! You have reached your daily catch limit' ) sys.exit(2) break # simulate app time.sleep(5)
def work(self, response_dict=None): response_dict = response_dict or self.create_encounter_api_call() # validate response if not response_dict: return WorkerResult.ERROR try: responses = response_dict['responses'] response = responses[self.response_key] if response[self.response_status_key] != ENCOUNTER_STATUS_SUCCESS: if response[ self. response_status_key] == ENCOUNTER_STATUS_NOT_IN_RANGE: self.emit_event('pokemon_not_in_range', formatted='Pokemon went out of range!') elif response[ self. response_status_key] == ENCOUNTER_STATUS_POKEMON_INVENTORY_FULL: self.emit_event( 'pokemon_inventory_full', formatted= 'Your Pokemon inventory is full! Could not catch!') return WorkerResult.ERROR except KeyError: return WorkerResult.ERROR # get pokemon data pokemon_data = response['wild_pokemon'][ 'pokemon_data'] if 'wild_pokemon' in response else response[ 'pokemon_data'] pokemon = Pokemon(pokemon_data) # skip ignored pokemon if not self._should_catch_pokemon(pokemon): self.emit_event( 'pokemon_appeared', formatted= 'Skip ignored {pokemon}! [CP {cp}] [Potential {iv}] [A/D/S {iv_display}]', data={ 'pokemon': pokemon.name, 'cp': pokemon.cp, 'iv': pokemon.iv, 'iv_display': pokemon.iv_display, }) return WorkerResult.SUCCESS is_vip = self._is_vip_pokemon(pokemon) if inventory.items().get(ITEM_POKEBALL).count < 1: if inventory.items().get(ITEM_GREATBALL).count < 1: if inventory.items().get(ITEM_ULTRABALL).count < 1: return WorkerResult.ERROR elif (not is_vip) and inventory.items().get( ITEM_ULTRABALL).count <= self.min_ultraball_to_keep: return WorkerResult.ERROR # log encounter self.emit_event( 'pokemon_appeared', formatted= 'A wild {pokemon} appeared! [CP {cp}] [NCP {ncp}] [Potential {iv}] [A/D/S {iv_display}]', data={ 'pokemon': pokemon.name, 'ncp': round(pokemon.cp_percent, 2), 'cp': pokemon.cp, 'iv': pokemon.iv, 'iv_display': pokemon.iv_display, 'encounter_id': self.pokemon['encounter_id'], 'latitude': self.pokemon['latitude'], 'longitude': self.pokemon['longitude'], 'pokemon_id': pokemon.pokemon_id }) # simulate app time.sleep(3) # check for VIP pokemon if is_vip: self.emit_event('vip_pokemon', formatted='This is a VIP pokemon. Catch!!!') # check catch limits before catch with self.bot.database as conn: c = conn.cursor() c.execute( "SELECT DISTINCT COUNT(encounter_id) FROM catch_log WHERE dated >= datetime('now','-1 day')" ) result = c.fetchone() self.caught_last_24_hour = result[0] while True: if self.caught_last_24_hour < self.daily_catch_limit: # catch that pokemon! encounter_id = self.pokemon['encounter_id'] catch_rate_by_ball = [0] + response['capture_probability'][ 'capture_probability'] # offset so item ids match indces self._do_catch(pokemon, encounter_id, catch_rate_by_ball, is_vip=is_vip) break else: self.emit_event( 'catch_limit', formatted='WARNING! You have reached your daily catch limit' ) sys.exit(2) break # simulate app time.sleep(5)
def work(self, response_dict=None): pokeballs = self.bot.item_inventory_count(1) superballs = self.bot.item_inventory_count(2) ultraballs = self.bot.item_inventory_count(3) response_dict = response_dict or self.create_encounter_api_call() # validate response if not response_dict: return WorkerResult.ERROR try: responses = response_dict['responses'] response = responses[self.response_key] if response[self.response_status_key] != ENCOUNTER_STATUS_SUCCESS: if response[ self. response_status_key] == ENCOUNTER_STATUS_NOT_IN_RANGE: self.emit_event('pokemon_not_in_range', formatted='Pokemon went out of range!') elif response[ self. response_status_key] == ENCOUNTER_STATUS_POKEMON_INVENTORY_FULL: self.emit_event( 'pokemon_inventory_full', formatted= 'Your Pokemon inventory is full! Could not catch!') return WorkerResult.ERROR except KeyError: return WorkerResult.ERROR # get pokemon data pokemon_data = response['wild_pokemon'][ 'pokemon_data'] if 'wild_pokemon' in response else response[ 'pokemon_data'] pokemon = Pokemon(pokemon_data) # skip ignored pokemon if not self._should_catch_pokemon(pokemon): return WorkerResult.SUCCESS is_vip = self._is_vip_pokemon(pokemon) if pokeballs < 1: if superballs < 1: if ultraballs < 1: return WorkerResult.SUCCESS if not is_vip: return WorkerResult.SUCCESS # log encounter self.emit_event( 'pokemon_appeared', formatted= 'A wild {pokemon} appeared! [CP {cp}] [Potential {iv}] [A/D/S {iv_display}]', data={ 'pokemon': pokemon.name, 'cp': pokemon.cp, 'iv': pokemon.iv, 'iv_display': pokemon.iv_display, 'encounter_id': self.pokemon['encounter_id'], 'latitude': self.pokemon['latitude'], 'longitude': self.pokemon['longitude'], 'pokemon_id': pokemon.pokemon_id }) # simulate app sleep(3) # check for VIP pokemon if is_vip: self.emit_event('vip_pokemon', formatted='This is a VIP pokemon. Catch!!!') # catch that pokemon! encounter_id = self.pokemon['encounter_id'] catch_rate_by_ball = [0] + response['capture_probability'][ 'capture_probability'] # offset so item ids match indces self._do_catch(pokemon, encounter_id, catch_rate_by_ball, is_vip=is_vip) # simulate app time.sleep(5)
def work(self, response_dict=None): if self.daily_catch_limit > 500: if not hasattr(self.bot, "no_notify_until") or self.bot.no_notify_until <= datetime.now(): self.logger.warning("BE WARNED! The total catch limit in 72 hours is 1500!") self.logger.warning("Setting your daily limit to %s might get you account flagged or banned!" % self.daily_catch_limit) sleep(5) self.bot.no_notify_until = datetime.now() + timedelta(minutes=5) response_dict = response_dict or self.create_encounter_api_call() # validate response if not response_dict: return WorkerResult.ERROR responses = response_dict['responses'] response = responses[self.response_key] if response[self.response_status_key] != ENCOUNTER_STATUS_SUCCESS and response[self.response_status_key] != INCENSE_ENCOUNTER_AVAILABLE: if response[self.response_status_key] == ENCOUNTER_STATUS_NOT_IN_RANGE: self.emit_event('pokemon_not_in_range', formatted='Pokemon went out of range!') elif response[self.response_status_key] == INCENSE_ENCOUNTER_NOT_AVAILABLE: self.emit_event('pokemon_not_in_range', formatted='Incensed Pokemon went out of range!') elif response[self.response_status_key] == ENCOUNTER_STATUS_POKEMON_INVENTORY_FULL: self.emit_event('pokemon_inventory_full', formatted='Your Pokemon inventory is full! Could not catch!') return WorkerResult.ERROR # get pokemon data pokemon_data = response['wild_pokemon']['pokemon_data'] if 'wild_pokemon' in response else response['pokemon_data'] pokemon = Pokemon(pokemon_data) # check if vip pokemon is_vip = self._is_vip_pokemon(pokemon) # skip ignored pokemon if (not self._should_catch_pokemon(pokemon) and not is_vip) or self.bot.catch_disabled: if not hasattr(self.bot,'skipped_pokemon'): self.bot.skipped_pokemon = [] # Check if pokemon already skipped and suppress alert if so for skipped_pokemon in self.bot.skipped_pokemon: if pokemon.pokemon_id == skipped_pokemon.pokemon_id and \ pokemon.cp_exact == skipped_pokemon.cp_exact and \ pokemon.ivcp == skipped_pokemon.ivcp: return WorkerResult.SUCCESS if self.bot.catch_disabled: self.logger.info("Not catching {}. All catching tasks are currently disabled until {}.".format(pokemon,self.bot.catch_resume_at.strftime("%H:%M:%S"))) # Add the encounter_id to the Pokemon pokemon.encounter_id = self.pokemon['encounter_id'] self.bot.skipped_pokemon.append(pokemon) self.emit_event( 'pokemon_appeared', formatted='Skip ignored {pokemon}! (CP: {cp} IV: {iv} A/D/S: {iv_display} Shiny: {shiny})', data={ 'pokemon': pokemon.name, 'cp': str(int(pokemon.cp)), 'iv': str(pokemon.iv), 'iv_display': str(pokemon.iv_display), 'shiny': pokemon.shiny, } ) return WorkerResult.SUCCESS if inventory.items().get(ITEM_POKEBALL).count < 1: if inventory.items().get(ITEM_GREATBALL).count < 1: if inventory.items().get(ITEM_ULTRABALL).count < 1: return WorkerResult.ERROR elif (not is_vip) and inventory.items().get(ITEM_ULTRABALL).count <= self.min_ultraball_to_keep: return WorkerResult.ERROR # log encounter self.emit_event( 'pokemon_appeared', formatted='A wild {} appeared! (CP: {} IV: {} A/D/S: {} NCP: {} Shiny: {})'.format(pokemon.name, pokemon.cp, pokemon.iv, pokemon.iv_display, round(pokemon.cp_percent, 2),pokemon.shiny, ), data={ 'pokemon': pokemon.name, 'ncp': round(pokemon.cp_percent, 2), 'cp': pokemon.cp, 'iv': pokemon.iv, 'iv_display': pokemon.iv_display, 'encounter_id': self.pokemon['encounter_id'], 'latitude': self.pokemon['latitude'], 'longitude': self.pokemon['longitude'], 'pokemon_id': pokemon.pokemon_id, 'shiny': pokemon.shiny, } ) # simulate app time.sleep(3) # check for VIP pokemon if is_vip: self.emit_event('vip_pokemon', formatted='This is a VIP pokemon. Catch!!!') # check catch limits before catch with self.bot.database as conn: c = conn.cursor() c.execute("SELECT DISTINCT COUNT(encounter_id) FROM catch_log WHERE dated >= datetime('now','-1 day')") result = c.fetchone() while True: if result[0] < self.daily_catch_limit: # catch that pokemon! encounter_id = self.pokemon['encounter_id'] catch_rate_by_ball = [0] + response['capture_probability']['capture_probability'] # offset so item ids match indces self._do_catch(pokemon, encounter_id, catch_rate_by_ball, is_vip=is_vip) #We need to continue all tasks when we are ok return WorkerResult.SUCCESS break else: self.emit_event('catch_limit', formatted='WARNING! You have reached your daily catch limit') sys.exit(2) break # simulate app time.sleep(5) #We need to continue all tasks when we are ok return WorkerResult.SUCCESS