Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow use of ultraball on non-vip #5555

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 8 additions & 15 deletions pokemongo_bot/cell_workers/pokemon_catch_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,20 +453,19 @@ def _do_catch(self, pokemon, encounter_id, catch_rate_by_ball, is_vip=False):

:type pokemon: Pokemon
"""
berry_id = ITEM_RAZZBERRY
maximum_ball = ITEM_ULTRABALL if is_vip else ITEM_GREATBALL
ideal_catch_rate_before_throw = self.vip_berry_threshold if is_vip else self.berry_threshold

berry_count = self.inventory.get(ITEM_RAZZBERRY).count
ball_count = {}
for ball_id in [ITEM_POKEBALL, ITEM_GREATBALL, ITEM_ULTRABALL]:
ball_count[ball_id] = self.inventory.get(ball_id).count

# use `min_ultraball_to_keep` from config if is not None
min_ultraball_to_keep = ball_count[ITEM_ULTRABALL]
if self.min_ultraball_to_keep is not None:
if self.min_ultraball_to_keep >= 0 and self.min_ultraball_to_keep < min_ultraball_to_keep:
min_ultraball_to_keep = self.min_ultraball_to_keep
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

used_berry = False
original_catch_rate_by_ball = catch_rate_by_ball
Expand All @@ -477,14 +476,8 @@ def _do_catch(self, pokemon, encounter_id, catch_rate_by_ball, is_vip=False):
while ball_count[current_ball] == 0 and current_ball < maximum_ball:
current_ball += 1
if ball_count[current_ball] == 0:
# use untraball if there is no other balls with constraint to `min_ultraball_to_keep`
if maximum_ball != ITEM_ULTRABALL and ball_count[ITEM_ULTRABALL] > min_ultraball_to_keep:
maximum_ball = ITEM_ULTRABALL
self.emit_event('enough_ultraballs', formatted='No regular balls left! Trying ultraball.')
continue
else:
self.emit_event('no_pokeballs', formatted='No pokeballs left! Fleeing...')
return WorkerResult.ERROR
self.emit_event('no_pokeballs', formatted='No pokeballs left! Fleeing...')
return WorkerResult.ERROR

# check future ball count
num_next_balls = 0
Expand Down