Skip to content

Commit

Permalink
Features/missed throws (#4107)
Browse files Browse the repository at this point in the history
* Adds a missed shot opportunity. This will reduce the 100% hit rate and humanise the throwing behaviour.

* * Added the new value to config.json.example.
* A little house cleaning

* Fixing error in logic

* Changing sleep for action_delay

* * Updated config example
* Fixed simulation changes

* Fixes bugs
  • Loading branch information
rdeeb authored and elicwhite committed Aug 19, 2016
1 parent b60cefd commit 198510b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
3 changes: 2 additions & 1 deletion configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@
"great_rate": 0.5,
"nice_rate": 0.3,
"normal_rate": 0.1,
"spin_success_rate" : 0.6
"spin_success_rate" : 0.6,
"hit_rate": 0.75
},
"catch_simulation": {
"flee_count": 3,
Expand Down
21 changes: 19 additions & 2 deletions pokemongo_bot/cell_workers/pokemon_catch_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
CATCH_STATUS_SUCCESS = 1
CATCH_STATUS_FAILED = 2
CATCH_STATUS_VANISHED = 3
CATCH_STATUS_MISSED = 4

ENCOUNTER_STATUS_SUCCESS = 1
ENCOUNTER_STATUS_NOT_IN_RANGE = 5
Expand Down Expand Up @@ -58,6 +59,7 @@ def initialize(self):
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.catch_throw_parameters_hit_rate = self.catch_throw_parameters.get('hit_rate', 0.8)

self.catchsim_config = self.config.get('catch_simulation', {})
self.catchsim_catch_wait_min = self.catchsim_config.get('catch_wait_min', 2)
Expand Down Expand Up @@ -124,7 +126,7 @@ def work(self, response_dict=None):
)

# simulate app
sleep(3)
time.sleep(3)

# check for VIP pokemon
if is_vip:
Expand Down Expand Up @@ -393,12 +395,16 @@ def _do_catch(self, pokemon, encounter_id, catch_rate_by_ball, is_vip=False):
}
)

hit_pokemon = 1
if random() >= self.catch_throw_parameters_hit_rate:
hit_pokemon = 0

response_dict = self.api.catch_pokemon(
encounter_id=encounter_id,
pokeball=current_ball,
normalized_reticle_size=throw_parameters['normalized_reticle_size'],
spawn_point_id=self.spawn_point_guid,
hit_pokemon=1,
hit_pokemon=hit_pokemon,
spin_modifier=throw_parameters['spin_modifier'],
normalized_hit_position=throw_parameters['normalized_hit_position']
)
Expand Down Expand Up @@ -493,6 +499,17 @@ def _do_catch(self, pokemon, encounter_id, catch_rate_by_ball, is_vip=False):
)

self.bot.softban = False

elif catch_pokemon_status == CATCH_STATUS_MISSED:
self.emit_event(
'pokemon_capture_failed',
formatted='Pokeball thrown to {pokemon} missed.. trying again!',
data={'pokemon': pokemon.name}
)
# Take some time to throw the ball from config options
action_delay(self.catchsim_catch_wait_min, self.catchsim_catch_wait_max)
continue

break

def get_candy_gained_count(self, response_dict):
Expand Down

1 comment on commit 198510b

@YvesHenri
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure how the python's random() work, but I believe this isn't the best approach to reach that hit chance effect. random() >= hit_chance doesnt guarantee the hit chance percentage defined. I can't come up with a better solution now, but will surely do right when I have time for it.

Please sign in to comment.