From c361f58f51670b232899b767938234e65f42426c Mon Sep 17 00:00:00 2001 From: David Westerink Date: Sun, 4 Sep 2016 20:02:01 +0200 Subject: [PATCH] Added catching of Pokemon from incense Added documentation and new function Solving issue #5151 - part 1 --- configs/config.json.example | 1 + docs/configuration_files.md | 3 ++- pokemongo_bot/__init__.py | 10 +++++++++ pokemongo_bot/cell_workers/catch_pokemon.py | 22 +++++++++++++++++++ .../cell_workers/pokemon_catch_worker.py | 14 ++++++++++-- 5 files changed, 47 insertions(+), 3 deletions(-) diff --git a/configs/config.json.example b/configs/config.json.example index 95a998a938..22d158b8ff 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -187,6 +187,7 @@ "enabled": true, "catch_visible_pokemon": true, "catch_lured_pokemon": true, + "catch_incensed_pokemon": true, "min_ultraball_to_keep": 5, "berry_threshold": 0.35, "vip_berry_threshold": 0.9, diff --git a/docs/configuration_files.md b/docs/configuration_files.md index 1c613fcc11..c645d8a7ea 100644 --- a/docs/configuration_files.md +++ b/docs/configuration_files.md @@ -112,6 +112,7 @@ The behaviors of the bot are configured via the `tasks` key in the `config.json` * `treat_unseen_as_vip`: Default `"true"` | If true, treat new to dex as VIP * `catch_visible_pokemon`: Default "true" | If enabled, attempts to catch "visible" pokemon that are reachable * `catch_lured_pokemon`: Default "true" | If enabled, attempts to catch "lured" pokemon that are reachable + * `catch_incensed_pokemon`: Default "true" | If enabled, attempts to catch pokemon that are found because of an active incense * `min_ultraball_to_keep`: Default 5 | Minimum amount of reserved ultraballs to have on hand (for VIP) * `berry_threshold`: Default 0.35 | Catch percentage we start throwing berries * `vip_berry_threshold`: Default 0.9 | Something similar? @@ -1062,4 +1063,4 @@ Available `team` : "team": 2 } } -``` \ No newline at end of file +``` diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index d635479886..9984842aca 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -359,6 +359,16 @@ def _register_events(self): 'pokemon_name' ) ) + self.event_manager.register_event( + 'lured_pokemon_found', + parameters=( + 'pokemon_id', + 'spawn_point_id', + 'encounter_id', + 'latitude', + 'longitude' + ) + ) self.event_manager.register_event( 'pokemon_appeared', parameters=( diff --git a/pokemongo_bot/cell_workers/catch_pokemon.py b/pokemongo_bot/cell_workers/catch_pokemon.py index f9ad7ef4a5..5d7ea656e4 100644 --- a/pokemongo_bot/cell_workers/catch_pokemon.py +++ b/pokemongo_bot/cell_workers/catch_pokemon.py @@ -35,6 +35,8 @@ def work(self): self.get_visible_pokemon() if self.config.get('catch_lured_pokemon', True): self.get_lured_pokemon() + if self.config.get('catch_incensed_pokemon', True): + self.get_incensed_pokemon() random.shuffle(self.pokemon) @@ -129,6 +131,26 @@ def get_lured_pokemon(self): self.add_pokemon(pokemon) + def get_incensed_pokemon(self): + # call self.bot.api.get_incense_pokemon + pokemon_to_catch = self.bot.api.get_incense_pokemon + + if len(pokemon_to_catch) > 0: + for pokemon in pokemon_to_catch: + + # Update web UI + with open(user_web_catchable, 'w') as outfile: + json.dump(pokemon, outfile) + + self.emit_event( + 'incensed_pokemon_found', + level='info', + formatted='Incense attracted a pokemon at {encounter_location}', + data=pokemon + ) + + self.add_pokemon(pokemon) + def add_pokemon(self, pokemon): if pokemon['encounter_id'] not in self.pokemon: self.pokemon.append(pokemon) diff --git a/pokemongo_bot/cell_workers/pokemon_catch_worker.py b/pokemongo_bot/cell_workers/pokemon_catch_worker.py index 1628476a5e..bf0ac31758 100644 --- a/pokemongo_bot/cell_workers/pokemon_catch_worker.py +++ b/pokemongo_bot/cell_workers/pokemon_catch_worker.py @@ -105,9 +105,11 @@ def work(self, response_dict=None): 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_SUCCESS && response[self.response_status_key] != INCENSE_ENCOUNTER_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] == 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 @@ -204,7 +206,7 @@ def create_encounter_api_call(self): player_latitude=player_latitude, player_longitude=player_longitude ) - else: + elif 'fort_id' in self.pokemon: fort_id = self.pokemon['fort_id'] self.spawn_point_guid = fort_id self.response_key = 'DISK_ENCOUNTER' @@ -215,6 +217,14 @@ def create_encounter_api_call(self): player_latitude=player_latitude, player_longitude=player_longitude ) + else + # This must be a incensed mon + self.response_key = 'INCENSE_ENCOUNTER' + self.response_status_key = 'result' + request.incense_encounter( + encounter_id=encounter_id, + encounter_location=self.pokemon['encounter_location'] + ) return request.call() ############################################################################