Skip to content

Commit

Permalink
Merge pull request #5964 from PokemonGoF/dev
Browse files Browse the repository at this point in the history
Dev to Master
  • Loading branch information
pogarek authored Mar 15, 2017
2 parents 10b8895 + 74058c2 commit 7e17370
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 57 deletions.
5 changes: 4 additions & 1 deletion configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@
"mode": "social",
"bullets": 1,
"homing_shots": true,
"cooldown_enabled": false,
"loiter_after_snipe": false,
"special_iv": 100,
"order": [
"missing",
Expand Down Expand Up @@ -402,7 +404,8 @@
"catch_lured_pokemon": true,
"catch_incensed_pokemon": true,
"min_ultraball_to_keep": 5,
"berry_threshold": 0.35,
"berry_threshold": 0.35,
"use_pinap_on_vip": false,
"vip_berry_threshold": 0.9,
"treat_unseen_as_vip": true,
"daily_catch_limit": 800,
Expand Down
4 changes: 4 additions & 0 deletions docs/configuration_files.md
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@ The default settings are 'safe' settings intended to simulate human and app beha
"catch_lured_pokemon": true,
"min_ultraball_to_keep": 5,
"berry_threshold": 0.35,
"use_pinap_on_vip": false,
"vip_berry_threshold": 0.9,
"catch_throw_parameters": {
"excellent_rate": 0.1,
Expand Down Expand Up @@ -631,6 +632,7 @@ Setting | Description
---- | ----
`min_ultraball_to_keep` | Allows the bot to use ultraballs on non-VIP pokemon as long as number of ultraballs is above this setting
`berry_threshold` | The ideal catch rate threshold before using a razz berry on normal pokemon (higher threshold means using razz berries more frequently, for example if we raise `berry_threshold` to 0.5, any pokemon that has an initial catch rate between 0 to 0.5 will initiate a berry throw)
`use_pinap_on_vip` | Use pinap berry instead of razz berry on on VIP pokemon. The bot will use razz berry if pinap berry has run out
`vip_berry_threshold` | The ideal catch rate threshold before using a razz berry on VIP pokemon
`flee_count` | The maximum number of times catching animation will play before the pokemon breaks free
`flee_duration` | The length of time for each animation
Expand Down Expand Up @@ -781,6 +783,8 @@ This task is an upgrade version of the MoveToMapPokemon task. It will fetch poke
* `homing_shots` - This will ensure that each bullet **will catch** a target. If disabled, a target might not exist and thus it wont be caught. When enabled, this will jump to the next target (if any) and try again to catch it. This will be repeated untill you've spent all the bullets. (default: true)
* `special_iv` - This will skip the catch list if the value is greater than or equal to the target's IV. This currently does not work with `social` mode and only works if the given `url` has this information. (default: 100)
* `time_mask` - The time mask used (if `expiration.format` is a full date). The default mask is '%Y-%m-%d %H:%M:%S'.
* `cooldown_enabled` - Do we set the sniper on a cool down of a random time after snipping? This might help avoiding bans.
* `loiter_after_snipe` - Do we wait a random time after sniping (aside of the above cooldown)? This might also help avoiding bans.
* `order` - The order on which you want to snipe. This can be one or multiple of the following values (default: [`missing`, `vip`, `priority`]):
- `iv` - Order by IV, if any. See `special_iv`.
- `vip` - Order by VIP.
Expand Down
2 changes: 1 addition & 1 deletion pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ def _register_events(self):
self.event_manager.register_event('skip_evolve')
self.event_manager.register_event('threw_berry_failed', parameters=('status_code',))
self.event_manager.register_event('vip_pokemon')
self.event_manager.register_event('gained_candy', parameters=('quantity', 'type'))
self.event_manager.register_event('gained_candy', parameters=('gained_candy', 'quantity', 'type'))
self.event_manager.register_event('catch_limit')
self.event_manager.register_event('spin_limit')
self.event_manager.register_event('show_best_pokemon', parameters=('pokemons'))
Expand Down
57 changes: 41 additions & 16 deletions pokemongo_bot/cell_workers/pokemon_catch_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
ITEM_GREATBALL = 2
ITEM_ULTRABALL = 3
ITEM_RAZZBERRY = 701
ITEM_PINAPBERRY = 705

DEFAULT_UNSEEN_AS_VIP = True

Expand Down Expand Up @@ -78,6 +79,7 @@ def initialize(self):
self.vip_berry_threshold = self.config.get('vip_berry_threshold', 0.9)
self.treat_unseen_as_vip = self.config.get('treat_unseen_as_vip', DEFAULT_UNSEEN_AS_VIP)
self.daily_catch_limit = self.config.get('daily_catch_limit', 800)
self.use_pinap_on_vip = self.config.get('use_pinap_on_vip', False)

self.vanish_settings = self.config.get('vanish_settings', {})
self.consecutive_vanish_limit = self.vanish_settings.get('consecutive_vanish_limit', 10)
Expand Down Expand Up @@ -389,19 +391,19 @@ def _use_berry(self, berry_id, berry_count, encounter_id, catch_rate_by_ball, cu
}
)

response_dict = self.bot.api.use_item_capture(
item_id=berry_id,
response_dict = self.bot.api.use_item_encounter(
item=berry_id,
encounter_id=encounter_id,
spawn_point_id=self.spawn_point_guid
spawn_point_guid=self.spawn_point_guid
)
responses = response_dict['responses']

if response_dict and response_dict['status_code'] == 1:
if response_dict['status_code'] == 1:

# update catch rates using multiplier
if 'item_capture_mult' in responses['USE_ITEM_CAPTURE']:
if 'capture_probability' in responses['USE_ITEM_ENCOUNTER']:
for rate in catch_rate_by_ball:
new_catch_rate_by_ball.append(rate * responses['USE_ITEM_CAPTURE']['item_capture_mult'])
new_catch_rate_by_ball.append(float(responses['USE_ITEM_ENCOUNTER']['capture_probability']['capture_probability'][current_ball-1]))
self.emit_event(
'threw_berry',
formatted="Threw a {berry_name}! Catch rate with {ball_name} is now: {new_catch_rate}",
Expand Down Expand Up @@ -439,7 +441,6 @@ def _use_berry(self, berry_id, berry_count, encounter_id, catch_rate_by_ball, cu
level='info',
formatted="softban_log table not found, skipping log"
)

# unknown status code
else:
new_catch_rate_by_ball = catch_rate_by_ball
Expand All @@ -459,7 +460,14 @@ def _do_catch(self, pokemon, encounter_id, catch_rate_by_ball, is_vip=False):
:type pokemon: Pokemon
"""
berry_count = self.inventory.get(ITEM_RAZZBERRY).count

if self.use_pinap_on_vip and is_vip:
berry_id = ITEM_PINAPBERRY
else:
berry_id = ITEM_RAZZBERRY

berry_count = self.inventory.get(berry_id).count

ball_count = {}
for ball_id in [ITEM_POKEBALL, ITEM_GREATBALL, ITEM_ULTRABALL]:
ball_count[ball_id] = self.inventory.get(ball_id).count
Expand All @@ -468,8 +476,7 @@ def _do_catch(self, pokemon, encounter_id, catch_rate_by_ball, is_vip=False):
min_ultraball_to_keep = ball_count[ITEM_ULTRABALL]
if self.min_ultraball_to_keep is not None and self.min_ultraball_to_keep >= 0:
min_ultraball_to_keep = self.min_ultraball_to_keep

berry_id = ITEM_RAZZBERRY

maximum_ball = ITEM_GREATBALL if ball_count[ITEM_ULTRABALL] < min_ultraball_to_keep else ITEM_ULTRABALL
ideal_catch_rate_before_throw = self.vip_berry_threshold if is_vip else self.berry_threshold

Expand All @@ -491,17 +498,34 @@ def _do_catch(self, pokemon, encounter_id, catch_rate_by_ball, is_vip=False):
while next_ball < maximum_ball:
next_ball += 1
num_next_balls += ball_count[next_ball]

# If pinap berry is not enough, use razz berry
if berry_count == 0 and self.use_pinap_on_vip:
if berry_id == ITEM_PINAPBERRY:
berry_id = ITEM_RAZZBERRY
berry_count = self.inventory.get(berry_id).count
else:
berry_id = ITEM_PINAPBERRY
berry_count = self.inventory.get(berry_id).count

# check if we've got berries to spare
berries_to_spare = berry_count > 0 if is_vip else berry_count > num_next_balls + 30

# use a berry if we are under our ideal rate and have berries to spare

changed_ball = False

# use pinap if config set to true
if self.use_pinap_on_vip and is_vip and berries_to_spare and not used_berry:
self._use_berry(berry_id, berry_count, encounter_id, catch_rate_by_ball, current_ball)
self.inventory.get(berry_id).remove(1)
berry_count -= 1
used_berry = True

# use a berry if we are under our ideal rate and have berries to spare
if catch_rate_by_ball[current_ball] < ideal_catch_rate_before_throw and berries_to_spare and not used_berry:
new_catch_rate_by_ball = self._use_berry(berry_id, berry_count, encounter_id, catch_rate_by_ball, current_ball)
if new_catch_rate_by_ball != catch_rate_by_ball:
catch_rate_by_ball = new_catch_rate_by_ball
self.inventory.get(ITEM_RAZZBERRY).remove(1)
self.inventory.get(berry_id).remove(1)
berry_count -= 1
used_berry = True

Expand All @@ -519,7 +543,7 @@ def _do_catch(self, pokemon, encounter_id, catch_rate_by_ball, is_vip=False):
new_catch_rate_by_ball = self._use_berry(berry_id, berry_count, encounter_id, catch_rate_by_ball, current_ball)
if new_catch_rate_by_ball != catch_rate_by_ball:
catch_rate_by_ball = new_catch_rate_by_ball
self.inventory.get(ITEM_RAZZBERRY).remove(1)
self.inventory.get(berry_id).remove(1)
berry_count -= 1
used_berry = True

Expand Down Expand Up @@ -703,10 +727,11 @@ def _do_catch(self, pokemon, encounter_id, catch_rate_by_ball, is_vip=False):

self.emit_event(
'gained_candy',
formatted='You now have {quantity} {type} candy!',
formatted='Candy gained: {gained_candy}. You now have {quantity} {type} candy!',
data = {
'gained_candy': str(candy_gain),
'quantity': candy.quantity,
'type': candy.type,
'type': candy.type
},
)

Expand Down
Loading

0 comments on commit 7e17370

Please sign in to comment.