Skip to content

Commit

Permalink
Randomize normalized_reticle_size and spin_modifier parameter for…
Browse files Browse the repository at this point in the history
… `catch_pokemon` api (#1205)
  • Loading branch information
kbinani authored and douglascamata committed Jul 29, 2016
1 parent aff8e76 commit b91ec50
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 4 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@
* SpaceWhale
* klingan
* reddivision
* kbinani
2 changes: 2 additions & 0 deletions configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -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:": {},
Expand Down
2 changes: 2 additions & 0 deletions configs/config.json.pokemon.example
Original file line number Diff line number Diff line change
Expand Up @@ -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" },

Expand Down
24 changes: 24 additions & 0 deletions pokecli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 6 additions & 4 deletions pokemongo_bot/cell_workers/pokemon_catch_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down Expand Up @@ -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()

Expand Down
18 changes: 18 additions & 0 deletions pokemongo_bot/human_behaviour.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit b91ec50

Please sign in to comment.