From b91ec50de8996942ffd901c0c135ea5734ba5920 Mon Sep 17 00:00:00 2001 From: kbinani Date: Sat, 30 Jul 2016 02:08:27 +0900 Subject: [PATCH] Randomize `normalized_reticle_size` and `spin_modifier` parameter for `catch_pokemon` api (#1205) --- CONTRIBUTORS.md | 1 + configs/config.json.example | 2 ++ configs/config.json.pokemon.example | 2 ++ pokecli.py | 24 +++++++++++++++++++ .../cell_workers/pokemon_catch_worker.py | 10 ++++---- pokemongo_bot/human_behaviour.py | 18 ++++++++++++++ 6 files changed, 53 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 005c5d5727..d23ba72805 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -42,3 +42,4 @@ * SpaceWhale * klingan * reddivision + * kbinani diff --git a/configs/config.json.example b/configs/config.json.example index 59d21b49ef..2e7cd45433 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -37,6 +37,8 @@ "longer_eggs_first": true, "evolve_captured": "NONE", "release_pokemon": true, + "catch_randomize_reticle_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.pokemon.example b/configs/config.json.pokemon.example index 830b96f1b7..3409003ee3 100644 --- a/configs/config.json.pokemon.example +++ b/configs/config.json.pokemon.example @@ -36,6 +36,8 @@ "longer_eggs_first": true, "evolve_captured": "NONE", "release_pokemon": true, + "catch_randomize_reticle_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 b8f4e5f995..669f8416c2 100755 --- a/pokecli.py +++ b/pokecli.py @@ -324,6 +324,22 @@ def init_config(): type=int, default=10, ) + add_config( + parser, + load, + long_flag="--catch_randomize_reticle_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 + ) + add_config( + parser, + load, + long_flag="--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() @@ -361,6 +377,14 @@ def init_config(): parser.error("Needs either --use-location-cache or --location.") return None + if config.catch_randomize_reticle_factor < 0 or 1 < config.catch_randomize_reticle_factor: + parser.error("--catch_randomize_reticle_factor is out of range! (should be 0 <= catch_randomize_reticle_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 d09cc960fe..f36ed09ab2 100644 --- a/pokemongo_bot/cell_workers/pokemon_catch_worker.py +++ b/pokemongo_bot/cell_workers/pokemon_catch_worker.py @@ -4,8 +4,7 @@ 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 +145,15 @@ def work(self): id_list1 = self.count_pokemon_inventory() + reticle_size_parameter = normalized_reticle_size(self.config.catch_randomize_reticle_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)