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

Use Ultraball If No Other Balls (With Constraint) #3421

Merged
merged 17 commits into from
Aug 12, 2016
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@
* thebigjc
* JaapMoolenaar
* eevee-github
* joaodragao
6 changes: 6 additions & 0 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,12 @@ def _register_events(self):
)
)
self.event_manager.register_event('no_pokeballs')
self.event_manager.register_event(
'use_ultraball',
parameters=(
'ultraball_count'
)
)
self.event_manager.register_event(
'pokemon_catch_rate',
parameters=(
Expand Down
15 changes: 14 additions & 1 deletion pokemongo_bot/cell_workers/pokemon_catch_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ def _do_catch(self, pokemon, encounter_id, catch_rate_by_ball, is_vip=False):
berry_count = self.bot.item_inventory_count(berry_id)
items_stock = self.bot.current_inventory()

min_ultraball_to_be_kept = self.config.get('min_ultraball_to_be_kept', items_stock[ITEM_ULTRABALL])

while True:

# find lowest available ball
Expand All @@ -290,7 +292,18 @@ def _do_catch(self, pokemon, encounter_id, catch_rate_by_ball, is_vip=False):
current_ball += 1
if items_stock[current_ball] == 0:
self.emit_event('no_pokeballs', formatted='No usable pokeballs found!')
break
if maximum_ball != ITEM_ULTRABALL and items_stock[ITEM_ULTRABALL] > min_ultraball_to_keep:
Copy link
Contributor

Choose a reason for hiding this comment

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

Line 285 min_ultraball_to_be_kept
Here min_ultraball_to_keep?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I should close this and open a new PR?

maximum_ball = ITEM_ULTRABALL
self.emit_event(
'use_ultraball',
Copy link
Member

Choose a reason for hiding this comment

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

This event is not necessary at all, we already have this:

self.emit_event(
                'threw_pokeball',
                formatted='Used {ball_name}, with chance {success_percentage} ({count_left} left)',
                data={
                    'ball_name': self.item_list[str(current_ball)],
                    'success_percentage': self._pct(catch_rate_by_ball[current_ball]),
                    'count_left': items_stock[current_ball]
                }
            )

Which is enough information for the user.

formatted='Use ultraball instead (ultraball count > {ultraball_count})',
data={
'ultraball_count': min_ultraball_to_keep
}
)
continue
Copy link

Choose a reason for hiding this comment

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

you should remove this. continue will go back to the top of the while True statement.

Copy link
Contributor Author

@joaodragao joaodragao Aug 10, 2016

Choose a reason for hiding this comment

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

Exactly, continue will go back to the while True, but the different is maximum_ball is set to ITEM_ULTRABALL while it was ITEM_GREATBALL before the while True. Then it will reset the current_ball to ITEM_ULTRABALL (I don't want to break more code and let the bot decides with maximum_ball).

Copy link

Choose a reason for hiding this comment

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

ah, ok

else:
break

# check future ball count
num_next_balls = 0
Expand Down