From ef621fa92f4255e121c6e67b1f08b43b98cdcf08 Mon Sep 17 00:00:00 2001 From: Vince Date: Mon, 15 Aug 2016 04:25:10 +0100 Subject: [PATCH 01/13] CatchPokemon calls CatchLuredPokemon and CatchVisiblePokemon methods. Config now only needs one catch related worker. All catch related config including option to catch lured and/or visible can be kept with the task. --- pokemongo_bot/cell_workers/__init__.py | 1 + .../cell_workers/catch_lured_pokemon.py | 3 +- pokemongo_bot/cell_workers/catch_pokemon.py | 21 +++++++++++ .../cell_workers/catch_visible_pokemon.py | 2 +- .../cell_workers/pokemon_catch_worker.py | 36 ++++++++++++------- 5 files changed, 48 insertions(+), 15 deletions(-) create mode 100644 pokemongo_bot/cell_workers/catch_pokemon.py 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..302199c2f7 --- /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['catch_visible_pokemon']: + self.catch_workers.append(CatchVisiblePokemon(self.bot, self.config)) + if self.config['catch_lured_pokemon']: + 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 49a96690fe..eaebacde99 100644 --- a/pokemongo_bot/cell_workers/pokemon_catch_worker.py +++ b/pokemongo_bot/cell_workers/pokemon_catch_worker.py @@ -29,17 +29,27 @@ 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', None) + self.catch_throw_parameters = config.get('catch_throw_parameters', {}) + self.catch_throw_parameters_spin_success_rate = self.catch_throw_parameters.get('spin_success_rate', 1) + self.catch_throw_parameters_excellent_rate = self.catch_throw_parameters.get('excellent_rate', 1) + self.catch_throw_parameters_great_rate = self.catch_throw_parameters.get('great_rate', 0) + self.catch_throw_parameters_nice_rate = self.catch_throw_parameters.get('nice_rate', 0) + self.catch_throw_parameters_normal_rate = self.catch_throw_parameters.get('normal_rate', 0) + ############################################################################ # public methods @@ -166,13 +176,13 @@ 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) @@ -254,9 +264,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: @@ -411,17 +421,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 \ From ade7ffeeacb6602918a4c7f8184ff342a6649333 Mon Sep 17 00:00:00 2001 From: Vince Date: Mon, 15 Aug 2016 04:29:45 +0100 Subject: [PATCH 02/13] example config --- configs/config.json.example | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/configs/config.json.example b/configs/config.json.example index 7727fd0c8b..99f330fc9f 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -74,12 +74,21 @@ } } }, - { - "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 + } + } + }, { "type": "SpinFort" }, @@ -114,22 +123,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 - }, "release": { "any": {"release_below_cp": 0, "release_below_iv": 0, "logic": "or"}, "// Example of always releasing Rattata:": {}, From 1b14c55fc10d0872a8626d9e1859babf37af08d1 Mon Sep 17 00:00:00 2001 From: Vince Date: Mon, 15 Aug 2016 22:04:13 +0100 Subject: [PATCH 03/13] indentation --- pokemongo_bot/cell_workers/catch_pokemon.py | 24 ++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/pokemongo_bot/cell_workers/catch_pokemon.py b/pokemongo_bot/cell_workers/catch_pokemon.py index 302199c2f7..cd095ae275 100644 --- a/pokemongo_bot/cell_workers/catch_pokemon.py +++ b/pokemongo_bot/cell_workers/catch_pokemon.py @@ -5,17 +5,17 @@ class CatchPokemon(BaseTask): - SUPPORTED_TASK_API_VERSION = 1 + SUPPORTED_TASK_API_VERSION = 1 - def initialize(self): - self.catch_workers = [] - if self.config['catch_visible_pokemon']: - self.catch_workers.append(CatchVisiblePokemon(self.bot, self.config)) - if self.config['catch_lured_pokemon']: - self.catch_workers.append(CatchLuredPokemon(self.bot, self.config)) + def initialize(self): + self.catch_workers = [] + if self.config['catch_visible_pokemon']: + self.catch_workers.append(CatchVisiblePokemon(self.bot, self.config)) + if self.config['catch_lured_pokemon']: + 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 + def work(self): + for cw in self.catch_workers: + if cw.work() == WorkerResult.RUNNING: + return WorkerResult.RUNNING + return WorkerResult.SUCCESS From d3bb0375b3e44d39260668e8c9fadb0cb72dfbf9 Mon Sep 17 00:00:00 2001 From: Vince Date: Tue, 16 Aug 2016 01:25:05 +0100 Subject: [PATCH 04/13] defaults for catch_lured/visible_pokemon --- pokemongo_bot/cell_workers/catch_pokemon.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pokemongo_bot/cell_workers/catch_pokemon.py b/pokemongo_bot/cell_workers/catch_pokemon.py index cd095ae275..b0500f6d1a 100644 --- a/pokemongo_bot/cell_workers/catch_pokemon.py +++ b/pokemongo_bot/cell_workers/catch_pokemon.py @@ -9,9 +9,9 @@ class CatchPokemon(BaseTask): def initialize(self): self.catch_workers = [] - if self.config['catch_visible_pokemon']: + if self.config.get('catch_visible_pokemon', True): self.catch_workers.append(CatchVisiblePokemon(self.bot, self.config)) - if self.config['catch_lured_pokemon']: + if self.config.get('catch_lured_pokemon', True): self.catch_workers.append(CatchLuredPokemon(self.bot, self.config)) def work(self): From 6f1251582edcc9aea283278006833ac277171b54 Mon Sep 17 00:00:00 2001 From: Vince Date: Tue, 16 Aug 2016 01:25:29 +0100 Subject: [PATCH 05/13] deprecated command line options for throw parameters --- pokecli.py | 53 +++++------------------------------------------------ 1 file changed, 5 insertions(+), 48 deletions(-) diff --git a/pokecli.py b/pokecli.py index e88b21c55b..c4d056d6b9 100644 --- a/pokecli.py +++ b/pokecli.py @@ -437,51 +437,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 - ) # Start to parse other attrs config = parser.parse_args() @@ -490,14 +445,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) config.vips = load.get('vips', {}) @@ -521,7 +475,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) From b8969abfb58e98e0318e18341da8bc41ab4abc98 Mon Sep 17 00:00:00 2001 From: Vince Date: Tue, 16 Aug 2016 01:49:37 +0100 Subject: [PATCH 06/13] catch_throw_parameters defaults match config.json.example --- pokemongo_bot/cell_workers/pokemon_catch_worker.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pokemongo_bot/cell_workers/pokemon_catch_worker.py b/pokemongo_bot/cell_workers/pokemon_catch_worker.py index eaebacde99..c4b9fd61ff 100644 --- a/pokemongo_bot/cell_workers/pokemon_catch_worker.py +++ b/pokemongo_bot/cell_workers/pokemon_catch_worker.py @@ -44,11 +44,11 @@ def __init__(self, pokemon, bot, config): self.config = config self.min_ultraball_to_keep = config.get('min_ultraball_to_keep', None) self.catch_throw_parameters = config.get('catch_throw_parameters', {}) - self.catch_throw_parameters_spin_success_rate = self.catch_throw_parameters.get('spin_success_rate', 1) - self.catch_throw_parameters_excellent_rate = self.catch_throw_parameters.get('excellent_rate', 1) - self.catch_throw_parameters_great_rate = self.catch_throw_parameters.get('great_rate', 0) - self.catch_throw_parameters_nice_rate = self.catch_throw_parameters.get('nice_rate', 0) - self.catch_throw_parameters_normal_rate = self.catch_throw_parameters.get('normal_rate', 0) + 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) ############################################################################ From 9c2a400cbb3a0aba18ba563374bba3553b001676 Mon Sep 17 00:00:00 2001 From: Vince Date: Tue, 16 Aug 2016 03:07:48 +0100 Subject: [PATCH 07/13] added deprecation functionality for CatchVisiblePokemon and CatchLuredPokemon --- pokemongo_bot/tree_config_builder.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pokemongo_bot/tree_config_builder.py b/pokemongo_bot/tree_config_builder.py index 57dc9da33c..e366f6930c 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,15 @@ 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 = {} + # Best way to show deprecation message? + if self._is_plugin_task(task_type): worker = self.plugin_loader.get_class(task_type) else: @@ -65,4 +75,3 @@ def build(self): workers.append(instance) return workers - From 38fdd6baad665f476c598ac7933aece89a741ecb Mon Sep 17 00:00:00 2001 From: Vince Date: Tue, 16 Aug 2016 03:22:40 +0100 Subject: [PATCH 08/13] min_ultraball_to_keep default reflects example config --- pokemongo_bot/cell_workers/pokemon_catch_worker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pokemongo_bot/cell_workers/pokemon_catch_worker.py b/pokemongo_bot/cell_workers/pokemon_catch_worker.py index c4b9fd61ff..837d51e800 100644 --- a/pokemongo_bot/cell_workers/pokemon_catch_worker.py +++ b/pokemongo_bot/cell_workers/pokemon_catch_worker.py @@ -42,7 +42,7 @@ def __init__(self, pokemon, bot, config): #Config self.config = config - self.min_ultraball_to_keep = config.get('min_ultraball_to_keep', None) + 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) From 60351ac635512adbc02b38cd1bf89e324a8e2914 Mon Sep 17 00:00:00 2001 From: Vince Date: Wed, 17 Aug 2016 02:35:04 +0100 Subject: [PATCH 09/13] tree_config_builder_test uses CatchPokemon instead of CatchLuredPokemon --- tests/tree_config_builder_test.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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') From f25d7b20cec723920458eba6b00e06ed61b631dd Mon Sep 17 00:00:00 2001 From: Vince Date: Wed, 17 Aug 2016 02:53:48 +0100 Subject: [PATCH 10/13] deprecation warning message --- pokemongo_bot/tree_config_builder.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pokemongo_bot/tree_config_builder.py b/pokemongo_bot/tree_config_builder.py index e366f6930c..a237482fef 100644 --- a/pokemongo_bot/tree_config_builder.py +++ b/pokemongo_bot/tree_config_builder.py @@ -45,7 +45,8 @@ def build(self): deprecated_pokemon_task = True task_type = 'CatchPokemon' task_config = {} - # Best way to show deprecation message? + 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) From bfc0e8c8c3ef398fba851bb3b9ee82802d565d33 Mon Sep 17 00:00:00 2001 From: Vince Date: Wed, 17 Aug 2016 03:41:55 +0100 Subject: [PATCH 11/13] catchsim config moved to CatchPokemon --- pokecli.py | 10 --------- .../cell_workers/pokemon_catch_worker.py | 21 ++++++++++++++----- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/pokecli.py b/pokecli.py index edb050ed32..729a5a2318 100644 --- a/pokecli.py +++ b/pokecli.py @@ -470,16 +470,6 @@ def _json_loader(filename): config.plugins = load.get('plugins', []) config.raw_tasks = load.get('tasks', []) - 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', {}) if config.map_object_cache_time < 0.0: diff --git a/pokemongo_bot/cell_workers/pokemon_catch_worker.py b/pokemongo_bot/cell_workers/pokemon_catch_worker.py index f976109648..1846cd2a66 100644 --- a/pokemongo_bot/cell_workers/pokemon_catch_worker.py +++ b/pokemongo_bot/cell_workers/pokemon_catch_worker.py @@ -43,6 +43,7 @@ def __init__(self, pokemon, bot, config): #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) @@ -50,6 +51,16 @@ def __init__(self, pokemon, bot, config): 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 @@ -189,7 +200,7 @@ def _pct(self, rate_by_ball): 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', @@ -327,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 @@ -343,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)', @@ -380,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 From 040a5f4c97cdbb87a5a8e617c401c6865de45bb3 Mon Sep 17 00:00:00 2001 From: Vince Date: Wed, 17 Aug 2016 03:52:33 +0100 Subject: [PATCH 12/13] updated example configs --- configs/config.json.cluster.example | 34 +++++++++++++++------ configs/config.json.example | 12 +++++++- configs/config.json.map.example | 44 +++++++++++++++------------ configs/config.json.optimizer.example | 42 ++++++++++++++----------- configs/config.json.path.example | 31 +++++++++++++++---- configs/config.json.pokemon.example | 37 ++++++++++++++-------- 6 files changed, 136 insertions(+), 64 deletions(-) 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 bff2d5b974..6b9fe42e0f 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -92,7 +92,17 @@ "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 + }, } }, { 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" }, From a7da045eb3ab7f0b4f6f7ec68ddc24973fda8668 Mon Sep 17 00:00:00 2001 From: Vince Date: Wed, 17 Aug 2016 04:03:20 +0100 Subject: [PATCH 13/13] updated docs --- docs/configuration_files.md | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) 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.