diff --git a/configs/config.json.cluster.example b/configs/config.json.cluster.example index 5c90d8f4b2..87552dec59 100644 --- a/configs/config.json.cluster.example +++ b/configs/config.json.cluster.example @@ -67,12 +67,31 @@ } } }, - { - "type": "CatchVisiblePokemon" - }, - { - "type": "CatchLuredPokemon" - }, + { + "type": "CatchPokemon", + "config": { + "catch_visible_pokemon": true, + "catch_lured_pokemon": true, + "min_ultraball_to_keep": 5, + "catch_throw_parameters": { + "excellent_rate": 0.1, + "great_rate": 0.5, + "nice_rate": 0.3, + "normal_rate": 0.1, + "spin_success_rate" : 0.6 + }, + "catch_simulation": { + "flee_count": 3, + "flee_duration": 2, + "catch_wait_min": 2, + "catch_wait_max": 6, + "berry_wait_min": 2, + "berry_wait_max": 3, + "changeball_wait_min": 2, + "changeball_wait_max": 3 + }, + } + }, { "type": "SpinFort" }, @@ -99,9 +118,6 @@ "location_cache": true, "distance_unit": "km", "reconnecting_timeout": 15, - "catch_randomize_reticle_factor": 1.0, - "catch_randomize_spin_factor": 1.0, - "min_ultraball_to_keep": 10, "logging_color": true, "catch": { "any": {"catch_above_cp": 0, "catch_above_iv": 0, "logic": "or"}, diff --git a/configs/config.json.example b/configs/config.json.example index 8d968c9b38..6b9fe42e0f 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -80,12 +80,31 @@ } } }, - { - "type": "CatchVisiblePokemon" - }, - { - "type": "CatchLuredPokemon" - }, + { + "type": "CatchPokemon", + "config": { + "catch_visible_pokemon": true, + "catch_lured_pokemon": true, + "min_ultraball_to_keep": 5, + "catch_throw_parameters": { + "excellent_rate": 0.1, + "great_rate": 0.5, + "nice_rate": 0.3, + "normal_rate": 0.1, + "spin_success_rate" : 0.6 + }, + "catch_simulation": { + "flee_count": 3, + "flee_duration": 2, + "catch_wait_min": 2, + "catch_wait_max": 6, + "berry_wait_min": 2, + "berry_wait_max": 3, + "changeball_wait_min": 2, + "changeball_wait_max": 3 + }, + } + }, { "type": "SpinFort" }, @@ -120,32 +139,12 @@ "location_cache": true, "distance_unit": "km", "reconnecting_timeout": 15, - "catch_randomize_reticle_factor": 1.0, - "catch_randomize_spin_factor": 1.0, - "min_ultraball_to_keep": 10, "logging_color": true, "catch": { "any": {"catch_above_cp": 0, "catch_above_iv": 0, "logic": "or"}, "// Example of always catching Rattata:": {}, "// Rattata": { "always_catch" : true } }, - "catch_throw_parameters": { - "excellent_rate": 0.1, - "great_rate": 0.5, - "nice_rate": 0.3, - "normal_rate": 0.1, - "spin_success_rate" : 0.6 - }, - "catch_simulation": { - "flee_count": 3, - "flee_duration": 2, - "catch_wait_min": 2, - "catch_wait_max": 6, - "berry_wait_min": 2, - "berry_wait_max": 3, - "changeball_wait_min": 2, - "changeball_wait_max": 3 - }, "release": { "any": {"release_below_cp": 0, "release_below_iv": 0, "logic": "or"}, "// Example of always releasing Rattata:": {}, diff --git a/configs/config.json.map.example b/configs/config.json.map.example index 4f0cbda093..52481df53f 100644 --- a/configs/config.json.map.example +++ b/configs/config.json.map.example @@ -65,12 +65,31 @@ } } }, - { - "type": "CatchVisiblePokemon" - }, - { - "type": "CatchLuredPokemon" - }, + { + "type": "CatchPokemon", + "config": { + "catch_visible_pokemon": true, + "catch_lured_pokemon": true, + "min_ultraball_to_keep": 5, + "catch_throw_parameters": { + "excellent_rate": 0.1, + "great_rate": 0.5, + "nice_rate": 0.3, + "normal_rate": 0.1, + "spin_success_rate" : 0.6 + }, + "catch_simulation": { + "flee_count": 3, + "flee_duration": 2, + "catch_wait_min": 2, + "catch_wait_max": 6, + "berry_wait_min": 2, + "berry_wait_max": 3, + "changeball_wait_min": 2, + "changeball_wait_max": 3 + }, + } + }, { "type": "SpinFort" }, @@ -341,19 +360,6 @@ "location_cache": true, "distance_unit": "km", "reconnecting_timeout": 15, - "catch_randomize_reticle_factor": 1.0, - "catch_randomize_spin_factor": 1.0, - "min_ultraball_to_keep": 10, - "catch_simulation": { - "flee_count": 3, - "flee_duration": 2, - "catch_wait_min": 2, - "catch_wait_max": 6, - "berry_wait_min": 2, - "berry_wait_max": 3, - "changeball_wait_min": 2, - "changeball_wait_max": 3 - }, "logging_color": true, "catch": { "any": {"catch_above_cp": 0, "catch_above_iv": 0, "logic": "or"}, diff --git a/configs/config.json.optimizer.example b/configs/config.json.optimizer.example index 1880e23d4a..0e24656a23 100644 --- a/configs/config.json.optimizer.example +++ b/configs/config.json.optimizer.example @@ -112,12 +112,31 @@ } } }, - { - "type": "CatchVisiblePokemon" - }, - { - "type": "CatchLuredPokemon" - }, + { + "type": "CatchPokemon", + "config": { + "catch_visible_pokemon": true, + "catch_lured_pokemon": true, + "min_ultraball_to_keep": 5, + "catch_throw_parameters": { + "excellent_rate": 0.1, + "great_rate": 0.5, + "nice_rate": 0.3, + "normal_rate": 0.1, + "spin_success_rate" : 0.6 + }, + "catch_simulation": { + "flee_count": 3, + "flee_duration": 2, + "catch_wait_min": 2, + "catch_wait_max": 6, + "berry_wait_min": 2, + "berry_wait_max": 3, + "changeball_wait_min": 2, + "changeball_wait_max": 3 + }, + } + }, { "type": "SpinFort", "config": { @@ -143,23 +162,12 @@ "walk_min": 2.16, "action_wait_min": 1, "action_wait_max": 4, - "catch_simulation": { - "flee_count": 3, - "flee_duration": 2, - "catch_wait_min": 2, - "catch_wait_max": 6, - "berry_wait_min": 2, - "berry_wait_max": 3, - "changeball_wait_min": 2, - "changeball_wait_max": 3 - }, "debug": false, "test": false, "health_record": false, "location_cache": true, "distance_unit": "km", "reconnecting_timeout": 15, - "min_ultraball_to_keep": 10, "logging_color": true, "catch": { "any": { diff --git a/configs/config.json.path.example b/configs/config.json.path.example index 8b253cafcf..1d07361c27 100644 --- a/configs/config.json.path.example +++ b/configs/config.json.path.example @@ -67,12 +67,31 @@ } } }, - { - "type": "CatchVisiblePokemon" - }, - { - "type": "CatchLuredPokemon" - }, + { + "type": "CatchPokemon", + "config": { + "catch_visible_pokemon": true, + "catch_lured_pokemon": true, + "min_ultraball_to_keep": 5, + "catch_throw_parameters": { + "excellent_rate": 0.1, + "great_rate": 0.5, + "nice_rate": 0.3, + "normal_rate": 0.1, + "spin_success_rate" : 0.6 + }, + "catch_simulation": { + "flee_count": 3, + "flee_duration": 2, + "catch_wait_min": 2, + "catch_wait_max": 6, + "berry_wait_min": 2, + "berry_wait_max": 3, + "changeball_wait_min": 2, + "changeball_wait_max": 3 + }, + } + }, { "type": "SpinFort" }, diff --git a/configs/config.json.pokemon.example b/configs/config.json.pokemon.example index 8c9e3a83f2..7ac7c122ea 100644 --- a/configs/config.json.pokemon.example +++ b/configs/config.json.pokemon.example @@ -68,12 +68,31 @@ } } }, - { - "type": "CatchVisiblePokemon" - }, - { - "type": "CatchLuredPokemon" - }, + { + "type": "CatchPokemon", + "config": { + "catch_visible_pokemon": true, + "catch_lured_pokemon": true, + "min_ultraball_to_keep": 5, + "catch_throw_parameters": { + "excellent_rate": 0.1, + "great_rate": 0.5, + "nice_rate": 0.3, + "normal_rate": 0.1, + "spin_success_rate" : 0.6 + }, + "catch_simulation": { + "flee_count": 3, + "flee_duration": 2, + "catch_wait_min": 2, + "catch_wait_max": 6, + "berry_wait_min": 2, + "berry_wait_max": 3, + "changeball_wait_min": 2, + "changeball_wait_max": 3 + }, + } + }, { "type": "SpinFort" }, @@ -102,18 +121,12 @@ "walk_min": 2.16, "action_wait_min": 1, "action_wait_max": 4, - "catch_wait_min": 1, - "catch_wait_max": 4, "debug": false, "test": false, "health_record": true, "location_cache": true, "distance_unit": "km", "reconnecting_timeout": 15, - "catch_randomize_reticle_factor": 1.0, - "catch_randomize_spin_factor": 1.0, - "randomize_flee_duration": true, - "min_ultraball_to_keep": 10, "logging_color": true, "catch": { "any": {"catch_above_cp": 0, "catch_above_iv": 0, "logic": "or" }, diff --git a/docs/configuration_files.md b/docs/configuration_files.md index eee7c6db1e..706904e44d 100644 --- a/docs/configuration_files.md +++ b/docs/configuration_files.md @@ -24,8 +24,7 @@ The behaviors of the bot are configured via the `tasks` key in the `config.json`. This enables you to list what you want the bot to do and change the priority of those tasks by reordering them in the list. This list of tasks is run repeatedly and in order. For more information on why we are moving config to this format, check out the [original proposal](https://github.com/PokemonGoF/PokemonGo-Bot/issues/142). ### Task Options: -* CatchLuredPokemon -* CatchVisiblePokemon +* CatchPokemon * EvolvePokemon * `evolve_all`: Default `NONE` | Set to `"all"` to evolve Pokémon if possible when the bot starts. Can also be set to individual Pokémon as well as multiple separated by a comma. e.g "Pidgey,Rattata,Weedle,Zubat" * `evolve_speed`: Default `20` @@ -69,10 +68,7 @@ The following configuration tells the bot to transfer all the Pokemon that match "type": "RecycleItems" }, { - "type": "CatchVisiblePokemon" - }, - { - "type": "CatchLuredPokemon" + "type": "CatchPokemon" }, { "type": "SpinFort" @@ -290,9 +286,9 @@ Key | Info } ``` -## `catch_simulation` Settings +## CatchPokemon `catch_simulation` Settings -These settings determine how the bot will simulate the app by adding pauses to throw the ball and navigate menus. All times are in seconds. +These settings determine how the bot will simulate the app by adding pauses to throw the ball and navigate menus. All times are in seconds. To configure these settings add them to the config in the CatchPokemon task. ### Default Settings The default settings are 'safe' settings intended to simulate human and app behaviour. diff --git a/pokecli.py b/pokecli.py index 312ef1fe2b..729a5a2318 100644 --- a/pokecli.py +++ b/pokecli.py @@ -447,51 +447,6 @@ def _json_loader(filename): type=bool, default=True ) - add_config( - parser, - load, - short_flag="-cte", - long_flag="--catch_throw_parameters.excellent_rate", - help="Define the odd of performing an excellent throw", - type=float, - default=1 - ) - add_config( - parser, - load, - short_flag="-ctg", - long_flag="--catch_throw_parameters.great_rate", - help="Define the odd of performing a great throw", - type=float, - default=0 - ) - add_config( - parser, - load, - short_flag="-ctn", - long_flag="--catch_throw_parameters.nice_rate", - help="Define the odd of performing a nice throw", - type=float, - default=0 - ) - add_config( - parser, - load, - short_flag="-ctm", - long_flag="--catch_throw_parameters.normal_rate", - help="Define the odd of performing a normal throw", - type=float, - default=0 - ) - add_config( - parser, - load, - short_flag="-cts", - long_flag="--catch_throw_parameters.spin_success_rate", - help="Define the odds of performing a spin throw (Value between 0 (never) and 1 (always))", - type=float, - default=1 - ) add_config( parser, load, @@ -507,24 +462,13 @@ def _json_loader(filename): if not config.password and 'password' not in load: config.password = getpass("Password: ") - config.encrypt_location = load.get('encrypt_location','') + config.encrypt_location = load.get('encrypt_location', '') config.catch = load.get('catch', {}) config.release = load.get('release', {}) config.action_wait_max = load.get('action_wait_max', 4) config.action_wait_min = load.get('action_wait_min', 1) config.plugins = load.get('plugins', []) config.raw_tasks = load.get('tasks', []) - config.min_ultraball_to_keep = load.get('min_ultraball_to_keep', None) - - catchsim_config = load.get('catch_simulation', {}) - config.catchsim_catch_wait_min = catchsim_config.get('catch_wait_min', 2) - config.catchsim_catch_wait_max = catchsim_config.get('catch_wait_max', 6) - config.catchsim_flee_count = int(catchsim_config.get('flee_count', 3)) - config.catchsim_flee_duration = catchsim_config.get('flee_duration', 2) - config.catchsim_berry_wait_min = catchsim_config.get('berry_wait_min', 2) - config.catchsim_berry_wait_max = catchsim_config.get('berry_wait_max', 3) - config.catchsim_changeball_wait_min = catchsim_config.get('changeball_wait_min', 2) - config.catchsim_changeball_wait_max = catchsim_config.get('changeball_wait_max', 3) config.vips = load.get('vips', {}) @@ -548,8 +492,10 @@ def task_configuration_error(flag_name): """.format(flag_name)) old_flags = ['mode', 'catch_pokemon', 'spin_forts', 'forts_spin', 'hatch_eggs', 'release_pokemon', 'softban_fix', - 'longer_eggs_first', 'evolve_speed', 'use_lucky_egg', 'item_filter', 'evolve_all', 'evolve_cp_min', - 'max_steps'] + 'longer_eggs_first', 'evolve_speed', 'use_lucky_egg', 'item_filter', 'evolve_all', 'evolve_cp_min', + 'max_steps', 'catch_throw_parameters.excellent_rate', 'catch_throw_parameters.great_rate', + 'catch_throw_parameters.nice_rate', 'catch_throw_parameters.normal_rate', + 'catch_throw_parameters.spin_success_rate'] for flag in old_flags: if flag in load: task_configuration_error(flag) diff --git a/pokemongo_bot/cell_workers/__init__.py b/pokemongo_bot/cell_workers/__init__.py index 538673cfe7..217eebbebf 100644 --- a/pokemongo_bot/cell_workers/__init__.py +++ b/pokemongo_bot/cell_workers/__init__.py @@ -19,3 +19,4 @@ from follow_cluster import FollowCluster from sleep_schedule import SleepSchedule from update_live_stats import UpdateLiveStats +from catch_pokemon import CatchPokemon diff --git a/pokemongo_bot/cell_workers/catch_lured_pokemon.py b/pokemongo_bot/cell_workers/catch_lured_pokemon.py index afddeb53d5..5c1456b88f 100644 --- a/pokemongo_bot/cell_workers/catch_lured_pokemon.py +++ b/pokemongo_bot/cell_workers/catch_lured_pokemon.py @@ -60,13 +60,14 @@ def get_lured_pokemon(self): self.emit_event( 'lured_pokemon_found', + level='info', formatted='Lured pokemon at fort {fort_name} ({fort_id})', data=result ) return pokemon_to_catch def catch_pokemon(self, pokemon): - worker = PokemonCatchWorker(pokemon, self.bot) + worker = PokemonCatchWorker(pokemon, self.bot, self.config) return_value = worker.work() return return_value diff --git a/pokemongo_bot/cell_workers/catch_pokemon.py b/pokemongo_bot/cell_workers/catch_pokemon.py new file mode 100644 index 0000000000..b0500f6d1a --- /dev/null +++ b/pokemongo_bot/cell_workers/catch_pokemon.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +from pokemongo_bot.base_task import BaseTask +from pokemongo_bot.worker_result import WorkerResult +from pokemongo_bot.cell_workers import CatchVisiblePokemon, CatchLuredPokemon + + +class CatchPokemon(BaseTask): + SUPPORTED_TASK_API_VERSION = 1 + + def initialize(self): + self.catch_workers = [] + if self.config.get('catch_visible_pokemon', True): + self.catch_workers.append(CatchVisiblePokemon(self.bot, self.config)) + if self.config.get('catch_lured_pokemon', True): + self.catch_workers.append(CatchLuredPokemon(self.bot, self.config)) + + def work(self): + for cw in self.catch_workers: + if cw.work() == WorkerResult.RUNNING: + return WorkerResult.RUNNING + return WorkerResult.SUCCESS diff --git a/pokemongo_bot/cell_workers/catch_visible_pokemon.py b/pokemongo_bot/cell_workers/catch_visible_pokemon.py index 0203459c28..9c9dfb8024 100644 --- a/pokemongo_bot/cell_workers/catch_visible_pokemon.py +++ b/pokemongo_bot/cell_workers/catch_visible_pokemon.py @@ -66,7 +66,7 @@ def work(self): return WorkerResult.SUCCESS def catch_pokemon(self, pokemon): - worker = PokemonCatchWorker(pokemon, self.bot) + worker = PokemonCatchWorker(pokemon, self.bot, self.config) return_value = worker.work() return return_value diff --git a/pokemongo_bot/cell_workers/pokemon_catch_worker.py b/pokemongo_bot/cell_workers/pokemon_catch_worker.py index a4ae70e216..1846cd2a66 100644 --- a/pokemongo_bot/cell_workers/pokemon_catch_worker.py +++ b/pokemongo_bot/cell_workers/pokemon_catch_worker.py @@ -29,17 +29,38 @@ class PokemonCatchWorker(BaseTask): - def __init__(self, pokemon, bot): + def __init__(self, pokemon, bot, config): self.pokemon = pokemon self.api = bot.api self.bot = bot self.position = bot.position - self.config = bot.config self.pokemon_list = bot.pokemon_list self.inventory = inventory.items() self.spawn_point_guid = '' self.response_key = '' self.response_status_key = '' + + #Config + self.config = config + self.min_ultraball_to_keep = config.get('min_ultraball_to_keep', 10) + + self.catch_throw_parameters = config.get('catch_throw_parameters', {}) + self.catch_throw_parameters_spin_success_rate = self.catch_throw_parameters.get('spin_success_rate', 0.6) + self.catch_throw_parameters_excellent_rate = self.catch_throw_parameters.get('excellent_rate', 0.1) + self.catch_throw_parameters_great_rate = self.catch_throw_parameters.get('great_rate', 0.5) + self.catch_throw_parameters_nice_rate = self.catch_throw_parameters.get('nice_rate', 0.3) + self.catch_throw_parameters_normal_rate = self.catch_throw_parameters.get('normal_rate', 0.1) + + self.catchsim_config = config.get('catch_simulation', {}) + self.catchsim_catch_wait_min = self.catchsim_config.get('catch_wait_min', 2) + self.catchsim_catch_wait_max = self.catchsim_config.get('catch_wait_max', 6) + self.catchsim_flee_count = int(self.catchsim_config.get('flee_count', 3)) + self.catchsim_flee_duration = self.catchsim_config.get('flee_duration', 2) + self.catchsim_berry_wait_min = self.catchsim_config.get('berry_wait_min', 2) + self.catchsim_berry_wait_max = self.catchsim_config.get('berry_wait_max', 3) + self.catchsim_changeball_wait_min = self.catchsim_config.get('changeball_wait_min', 2) + self.catchsim_changeball_wait_max = self.catchsim_config.get('changeball_wait_max', 3) + ############################################################################ # public methods @@ -166,20 +187,20 @@ def _pokemon_matches_config(self, config, pokemon, default_logic='and'): return LOGIC_TO_FUNCTION[pokemon_config.get('logic', default_logic)](*catch_results.values()) def _should_catch_pokemon(self, pokemon): - return self._pokemon_matches_config(self.config.catch, pokemon) + return self._pokemon_matches_config(self.bot.config.catch, pokemon) def _is_vip_pokemon(self, pokemon): # having just a name present in the list makes them vip - if self.config.vips.get(pokemon.name) == {}: + if self.bot.config.vips.get(pokemon.name) == {}: return True - return self._pokemon_matches_config(self.config.vips, pokemon, default_logic='or') + return self._pokemon_matches_config(self.bot.config.vips, pokemon, default_logic='or') def _pct(self, rate_by_ball): return '{0:.2f}'.format(rate_by_ball * 100) def _use_berry(self, berry_id, berry_count, encounter_id, catch_rate_by_ball, current_ball): # Delay to simulate selecting berry - action_delay(self.config.catchsim_berry_wait_min, self.config.catchsim_berry_wait_max) + action_delay(self.catchsim_berry_wait_min, self.catchsim_berry_wait_max) new_catch_rate_by_ball = [] self.emit_event( 'pokemon_catch_rate', @@ -256,9 +277,9 @@ def _do_catch(self, pokemon, encounter_id, catch_rate_by_ball, is_vip=False): # use `min_ultraball_to_keep` from config if is not None min_ultraball_to_keep = ball_count[ITEM_ULTRABALL] - if self.config.min_ultraball_to_keep is not None: - if self.config.min_ultraball_to_keep >= 0 and self.config.min_ultraball_to_keep < min_ultraball_to_keep: - min_ultraball_to_keep = self.config.min_ultraball_to_keep + if self.min_ultraball_to_keep is not None: + if self.min_ultraball_to_keep >= 0 and self.min_ultraball_to_keep < min_ultraball_to_keep: + min_ultraball_to_keep = self.min_ultraball_to_keep while True: @@ -317,7 +338,7 @@ def _do_catch(self, pokemon, encounter_id, catch_rate_by_ball, is_vip=False): # If we change ball then wait to simulate user selecting it if changed_ball: - action_delay(self.config.catchsim_changeball_wait_min, self.config.catchsim_changeball_wait_max) + action_delay(self.catchsim_changeball_wait_min, self.catchsim_changeball_wait_max) # Randomize the quality of the throw # Default structure @@ -333,7 +354,7 @@ def _do_catch(self, pokemon, encounter_id, catch_rate_by_ball, is_vip=False): ball_count[current_ball] -= 1 self.inventory.get(current_ball).remove(1) # Take some time to throw the ball from config options - action_delay(self.config.catchsim_catch_wait_min, self.config.catchsim_catch_wait_max) + action_delay(self.catchsim_catch_wait_min, self.catchsim_catch_wait_max) self.emit_event( 'threw_pokeball', formatted='Used {ball_name}, with chance {success_percentage} ({count_left} left)', @@ -370,8 +391,8 @@ def _do_catch(self, pokemon, encounter_id, catch_rate_by_ball, is_vip=False): # sleep according to flee_count and flee_duration config settings # randomly chooses a number of times to 'show' wobble animation between 1 and flee_count # multiplies this by flee_duration to get total sleep - if self.config.catchsim_flee_count: - sleep((randrange(self.config.catchsim_flee_count)+1) * self.config.catchsim_flee_duration) + if self.catchsim_flee_count: + sleep((randrange(self.catchsim_flee_count)+1) * self.catchsim_flee_duration) continue @@ -428,17 +449,17 @@ def _do_catch(self, pokemon, encounter_id, catch_rate_by_ball, is_vip=False): break def generate_spin_parameter(self, throw_parameters): - spin_success_rate = self.config.catch_throw_parameters_spin_success_rate + spin_success_rate = self.catch_throw_parameters_spin_success_rate if random() <= spin_success_rate: throw_parameters['spin_modifier'] = 0.5 + 0.5 * random() else: throw_parameters['spin_modifier'] = 0.499 * random() def generate_throw_quality_parameters(self, throw_parameters): - throw_excellent_chance = self.config.catch_throw_parameters_excellent_rate - throw_great_chance = self.config.catch_throw_parameters_great_rate - throw_nice_chance = self.config.catch_throw_parameters_nice_rate - throw_normal_throw_chance = self.config.catch_throw_parameters_normal_rate + throw_excellent_chance = self.catch_throw_parameters_excellent_rate + throw_great_chance = self.catch_throw_parameters_great_rate + throw_nice_chance = self.catch_throw_parameters_nice_rate + throw_normal_throw_chance = self.catch_throw_parameters_normal_rate # Total every chance types, pick a random number in the range and check what type of throw we got total_chances = throw_excellent_chance + throw_great_chance \ diff --git a/pokemongo_bot/tree_config_builder.py b/pokemongo_bot/tree_config_builder.py index 57dc9da33c..a237482fef 100644 --- a/pokemongo_bot/tree_config_builder.py +++ b/pokemongo_bot/tree_config_builder.py @@ -27,6 +27,7 @@ def _is_plugin_task(self, name): def build(self): workers = [] + deprecated_pokemon_task = False for task in self.tasks_raw: task_type = task.get('type', None) @@ -37,6 +38,16 @@ def build(self): task_config = task.get('config', {}) + if task_type in ['CatchVisiblePokemon', 'CatchLuredPokemon']: + if deprecated_pokemon_task: + continue + else: + deprecated_pokemon_task = True + task_type = 'CatchPokemon' + task_config = {} + self.bot.logger.warning('The CatchVisiblePokemon & CatchLuredPokemon tasks have been replaced with ' + 'CatchPokemon. CatchPokemon has been enabled with default settings.') + if self._is_plugin_task(task_type): worker = self.plugin_loader.get_class(task_type) else: @@ -65,4 +76,3 @@ def build(self): workers.append(instance) return workers - diff --git a/tests/tree_config_builder_test.py b/tests/tree_config_builder_test.py index f8982cbfad..e8b5829d49 100644 --- a/tests/tree_config_builder_test.py +++ b/tests/tree_config_builder_test.py @@ -2,7 +2,7 @@ import json import os from pokemongo_bot import PokemonGoBot, ConfigException, MismatchTaskApiVersion, TreeConfigBuilder, PluginLoader, BaseTask -from pokemongo_bot.cell_workers import HandleSoftBan, CatchLuredPokemon +from pokemongo_bot.cell_workers import HandleSoftBan, CatchPokemon from pokemongo_bot.test.resources.plugin_fixture import FakeTask, UnsupportedApiTask def convert_from_json(str): @@ -63,7 +63,7 @@ def test_creating_two_workers(self): obj = convert_from_json("""[{ "type": "HandleSoftBan" }, { - "type": "CatchLuredPokemon" + "type": "CatchPokemon" }]""") builder = TreeConfigBuilder(self.bot, obj) @@ -71,7 +71,7 @@ def test_creating_two_workers(self): self.assertIsInstance(tree[0], HandleSoftBan) self.assertIs(tree[0].bot, self.bot) - self.assertIsInstance(tree[1], CatchLuredPokemon) + self.assertIsInstance(tree[1], CatchPokemon) self.assertIs(tree[1].bot, self.bot) def test_task_with_config(self): @@ -93,7 +93,7 @@ def test_disabling_task(self): "enabled": false } }, { - "type": "CatchLuredPokemon", + "type": "CatchPokemon", "config": { "enabled": true } @@ -103,7 +103,7 @@ def test_disabling_task(self): tree = builder.build() self.assertTrue(len(tree) == 1) - self.assertIsInstance(tree[0], CatchLuredPokemon) + self.assertIsInstance(tree[0], CatchPokemon) def test_load_plugin_task(self): package_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'resources', 'plugin_fixture')