Skip to content

Commit

Permalink
Use Ultraball If No Other Balls (With Constraint) (#3421)
Browse files Browse the repository at this point in the history
* Add Use Ultraball (#1)

* Add `use_ultraball` event to Event Manager

* Add use ultraball if pokeball + greatball = 0

* Add Use Ultraball if No Other Balls (#2)

* Add `use_ultraball` event to Event Manager

* Add use ultraball if pokeball + greatball = 0

* Add New Contributor

* Revert "Add Use Ultraball" (#4)

* Use Ultraball If No Other Balls (#3)

* Add `use_ultraball` event to Event Manager

* Add use ultraball if pokeball + greatball = 0

* Add New Contributor

* Remove 'use_ultraball' event.

* Remove `use_ultraball` event call

* Update & add avoid catching Pokemon if no pokeball

* Update conflict contributors

* Add get `min_ultraball_to_keep` from config file

* Improved `min_ultraball_to_keep` with condition

* Added `min_ultraball_to_keep` option

* Added `min_ultraball_to_keep` option

* Added `min_ultraball_to_keep` option

* Added `min_ultraball_to_keep` option

* Add `min_ultraball_to_keep` option

* Remove count all pokeballs

* Resolved Conflicts
  • Loading branch information
joaodragao authored and douglascamata committed Aug 12, 2016
1 parent 6f626fa commit 59d0865
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 1 deletion.
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 @@ -265,6 +265,12 @@ def _do_catch(self, pokemon, encounter_id, catch_rate_by_ball, is_vip=False):
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 = 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 @@ -273,7 +279,13 @@ def _do_catch(self, pokemon, encounter_id, catch_rate_by_ball, is_vip=False):
current_ball += 1
if ball_count[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:
maximum_ball = ITEM_ULTRABALL
continue
else:
break

# check future ball count
num_next_balls = 0
Expand Down

0 comments on commit 59d0865

Please sign in to comment.