From b5fd72f2b8e2195cb516096508961b5bded09aeb Mon Sep 17 00:00:00 2001 From: kbinani Date: Wed, 27 Jul 2016 23:09:31 +0900 Subject: [PATCH] Randomize `normalized_reticle_size` and `spin_modifier` parameter for `catch_pokemon` api --- configs/config.json.example | 2 ++ configs/config.json.pokemons.example | 2 ++ pokecli.py | 22 +++++++++++++++++++ .../cell_workers/pokemon_catch_worker.py | 9 +++++--- pokemongo_bot/human_behaviour.py | 18 +++++++++++++++ 5 files changed, 50 insertions(+), 3 deletions(-) diff --git a/configs/config.json.example b/configs/config.json.example index bc9ad9f4c0..e7fac3b229 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -32,6 +32,8 @@ "longer_eggs_first": true, "evolve_captured": false, "release_pokemon": true, + "catch_randomize_reticule_factor": 1.0, + "catch_randomize_spin_factor": 1.0, "catch": { "any": {"catch_above_cp": 0, "catch_above_iv": 0, "logic": "or"}, "// Example of always catching Rattata:": {}, diff --git a/configs/config.json.pokemons.example b/configs/config.json.pokemons.example index 819c9491ef..a983df90c3 100644 --- a/configs/config.json.pokemons.example +++ b/configs/config.json.pokemons.example @@ -32,6 +32,8 @@ "longer_eggs_first": true, "evolve_captured": false, "release_pokemon": true, + "catch_randomize_reticule_factor": 1.0, + "catch_randomize_spin_factor": 1.0, "catch": { "any": {"catch_above_cp": 0, "catch_above_iv": 0, "logic": "or" }, diff --git a/pokecli.py b/pokecli.py index f39f2b83df..9c10f8514b 100755 --- a/pokecli.py +++ b/pokecli.py @@ -188,6 +188,20 @@ def init_config(): type=bool, default=True ) + parser.add_argument( + "-crrf", + "--catch_randomize_reticule_factor", + help="Randomize factor for pokeball throwing accuracy (DEFAULT 1.0 means no randomize: always 'Excellent' throw. 0.0 randomizes between normal and 'Excellent' throw)", + type=float, + default=1.0 + ) + parser.add_argument( + "-crsf", + "--catch_randomize_spin_factor", + help="Randomize factor for pokeball curve throwing (DEFAULT 1.0 means no randomize: always perfect 'Super Spin' curve ball. 0.0 randomizes between normal and 'Super Spin' curve ball)", + type=float, + default=1.0 + ) # Start to parse other attrs config = parser.parse_args() @@ -223,6 +237,14 @@ def init_config(): parser.error("Needs either --use-location-cache or --location.") return None + if config.catch_randomize_reticule_factor < 0 or 1 < config.catch_randomize_reticule_factor: + parser.error("--catch_randomize_reticule_factor is out of range! (should be 0 <= catch_randomize_reticule_factor <= 1)") + return None + + if config.catch_randomize_spin_factor < 0 or 1 < config.catch_randomize_spin_factor: + parser.error("--catch_randomize_spin_factor is out of range! (should be 0 <= catch_randomize_spin_factor <= 1)") + return None + # create web dir if not exists try: os.makedirs(web_dir) diff --git a/pokemongo_bot/cell_workers/pokemon_catch_worker.py b/pokemongo_bot/cell_workers/pokemon_catch_worker.py index 07f813be49..8c8f6438c1 100644 --- a/pokemongo_bot/cell_workers/pokemon_catch_worker.py +++ b/pokemongo_bot/cell_workers/pokemon_catch_worker.py @@ -4,8 +4,8 @@ from sets import Set from pokemongo_bot import logger -from pokemongo_bot.human_behaviour import sleep +from pokemongo_bot.human_behaviour import sleep, normalized_reticle_size, spin_modifier class PokemonCatchWorker(object): @@ -146,12 +146,15 @@ def work(self): id_list1 = self.count_pokemon_inventory() + reticle_size_parameter = normalized_reticle_size(self.config.catch_randomize_reticule_factor) + spin_modifier_parameter = spin_modifier(self.config.catch_randomize_spin_factor) + self.api.catch_pokemon(encounter_id=encounter_id, pokeball=pokeball, - normalized_reticle_size=1.950, + normalized_reticle_size=reticle_size_parameter, spawn_point_id=self.spawn_point_guid, hit_pokemon=1, - spin_modifier=1, + spin_modifier=spin_modifier_parameter, NormalizedHitPosition=1) response_dict = self.api.call() diff --git a/pokemongo_bot/human_behaviour.py b/pokemongo_bot/human_behaviour.py index 27e95c9469..5d0415695b 100644 --- a/pokemongo_bot/human_behaviour.py +++ b/pokemongo_bot/human_behaviour.py @@ -21,3 +21,21 @@ def random_lat_long_delta(): # Return random value from [-.000025, .000025]. Since 364,000 feet is equivalent to one degree of latitude, this # should be 364,000 * .000025 = 9.1. So it returns between [-9.1, 9.1] return ((random() * 0.00001) - 0.000005) * 5 + +# Humanized `normalized_reticle_size` parameter for `catch_pokemon` API. +# 1.0 => normal, 1.950 => excellent +def normalized_reticle_size(factor): + minimum = 1.0 + maximum = 1.950 + return uniform( + minimum + (maximum - minimum) * factor, + maximum) + +# Humanized `spin_modifier` parameter for `catch_pokemon` API. +# 0.0 => normal ball, 1.0 => super spin curve ball +def spin_modifier(factor): + minimum = 0.0 + maximum = 1.0 + return uniform( + minimum + (maximum - minimum) * factor, + maximum)