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 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
1 change: 1 addition & 0 deletions configs/config.json.cluster.example
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
"reconnecting_timeout": 15,
"catch_randomize_reticle_factor": 1.0,
"catch_randomize_spin_factor": 1.0,
"min_ultraball_to_keep": 10,
"logging_color": true,
"catch": {
"any": {"catch_above_cp": 0, "catch_above_iv": 0, "logic": "or"},
Expand Down
3 changes: 3 additions & 0 deletions configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@
"location_cache": true,
"distance_unit": "km",
"reconnecting_timeout": 15,
"catch_randomize_reticle_factor": 1.0,
"catch_randomize_spin_factor": 1.0,
"min_ultraball_to_keep": 10,
"logging_color": true,
"catch": {
"any": {"catch_above_cp": 0, "catch_above_iv": 0, "logic": "or"},
Expand Down
1 change: 1 addition & 0 deletions configs/config.json.map.example
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@
"reconnecting_timeout": 15,
"catch_randomize_reticle_factor": 1.0,
"catch_randomize_spin_factor": 1.0,
"min_ultraball_to_keep": 10,
"logging_color": true,
"catch": {
"any": {"catch_above_cp": 0, "catch_above_iv": 0, "logic": "or"},
Expand Down
1 change: 1 addition & 0 deletions configs/config.json.path.example
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
"reconnecting_timeout": 15,
"catch_randomize_reticle_factor": 1.0,
"catch_randomize_spin_factor": 1.0,
"min_ultraball_to_keep": 10,
"logging_color": true,
"catch": {
"any": {"catch_above_cp": 0, "catch_above_iv": 0, "logic": "or"},
Expand Down
1 change: 1 addition & 0 deletions configs/config.json.pokemon.example
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
"reconnecting_timeout": 15,
"catch_randomize_reticle_factor": 1.0,
"catch_randomize_spin_factor": 1.0,
"min_ultraball_to_keep": 10,
"logging_color": true,
"catch": {
"any": {"catch_above_cp": 0, "catch_above_iv": 0, "logic": "or" },
Expand Down
1 change: 1 addition & 0 deletions pokecli.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ def _json_loader(filename):
config.action_wait_min = load.get('action_wait_min', 1)
config.plugins = load.get('plugins', [])
config.raw_tasks = load.get('tasks', [])
config.min_ultraball_to_keep = load.get('min_ultraball_to_keep', None)

config.vips = load.get('vips', {})

Expand Down
14 changes: 13 additions & 1 deletion pokemongo_bot/cell_workers/pokemon_catch_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,12 @@ 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()

# use `min_ultraball_to_keep` from config if is not None
min_ultraball_to_keep = items_stock[ITEM_ULTRABALL]
if self.config.min_ultraball_to_keep is not None:
if self.config.min_ultraball_to_keep >= 0 and self.config.min_ultraball_to_keep < min_ultraball_to_keep:
min_ultraball_to_keep = self.config.min_ultraball_to_keep

while True:

# find lowest available ball
Expand All @@ -272,7 +278,13 @@ 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

# use untraball if there is no other balls with constraint to `min_ultraball_to_keep`
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
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