From 52b691fe4bacca609a06dea0024d23856a9ca976 Mon Sep 17 00:00:00 2001 From: joaodragao Date: Wed, 10 Aug 2016 10:20:40 +0100 Subject: [PATCH 01/15] Add Use Ultraball (#1) * Add `use_ultraball` event to Event Manager * Add use ultraball if pokeball + greatball = 0 --- pokemongo_bot/__init__.py | 6 ++++++ .../cell_workers/pokemon_catch_worker.py | 15 ++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index 31e7eb0bd1..8f87023f4e 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -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=( diff --git a/pokemongo_bot/cell_workers/pokemon_catch_worker.py b/pokemongo_bot/cell_workers/pokemon_catch_worker.py index d551a68632..98da938a53 100644 --- a/pokemongo_bot/cell_workers/pokemon_catch_worker.py +++ b/pokemongo_bot/cell_workers/pokemon_catch_worker.py @@ -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 @@ -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: + maximum_ball = ITEM_ULTRABALL + self.emit_event( + 'use_ultraball', + formatted='Use ultraball instead (ultraball count > {ultraball_count})', + data={ + 'ultraball_count': min_ultraball_to_keep + } + ) + continue + else: + break # check future ball count num_next_balls = 0 From b3b62c5fcfc658b06232d3b45aa6fec9ba87c995 Mon Sep 17 00:00:00 2001 From: joaodragao Date: Wed, 10 Aug 2016 10:29:22 +0100 Subject: [PATCH 02/15] 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 --- CONTRIBUTORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index bb0ac15b7b..6f75a7c676 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -60,3 +60,4 @@ * thebigjc * JaapMoolenaar * eevee-github + * joaodragao From 72e6ce38483dc74e9144e5b9501701282b5d5e13 Mon Sep 17 00:00:00 2001 From: joaodragao Date: Wed, 10 Aug 2016 18:33:48 +0100 Subject: [PATCH 03/15] Revert "Add Use Ultraball" (#4) --- pokemongo_bot/__init__.py | 6 ------ .../cell_workers/pokemon_catch_worker.py | 15 +-------------- 2 files changed, 1 insertion(+), 20 deletions(-) diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index 8f87023f4e..31e7eb0bd1 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -241,12 +241,6 @@ 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=( diff --git a/pokemongo_bot/cell_workers/pokemon_catch_worker.py b/pokemongo_bot/cell_workers/pokemon_catch_worker.py index 98da938a53..d551a68632 100644 --- a/pokemongo_bot/cell_workers/pokemon_catch_worker.py +++ b/pokemongo_bot/cell_workers/pokemon_catch_worker.py @@ -282,8 +282,6 @@ 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 @@ -292,18 +290,7 @@ 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!') - if maximum_ball != ITEM_ULTRABALL and items_stock[ITEM_ULTRABALL] > min_ultraball_to_keep: - maximum_ball = ITEM_ULTRABALL - self.emit_event( - 'use_ultraball', - formatted='Use ultraball instead (ultraball count > {ultraball_count})', - data={ - 'ultraball_count': min_ultraball_to_keep - } - ) - continue - else: - break + break # check future ball count num_next_balls = 0 From 2137f110a1f0e58d9c254c6004f6e713220139db Mon Sep 17 00:00:00 2001 From: joaodragao Date: Wed, 10 Aug 2016 18:34:04 +0100 Subject: [PATCH 04/15] 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 --- pokemongo_bot/cell_workers/pokemon_catch_worker.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pokemongo_bot/cell_workers/pokemon_catch_worker.py b/pokemongo_bot/cell_workers/pokemon_catch_worker.py index d551a68632..bae008ef48 100644 --- a/pokemongo_bot/cell_workers/pokemon_catch_worker.py +++ b/pokemongo_bot/cell_workers/pokemon_catch_worker.py @@ -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 @@ -290,7 +292,11 @@ 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: + maximum_ball = ITEM_ULTRABALL + continue + else: + break # check future ball count num_next_balls = 0 From 6f14c2fad26a0c2503f2f1adc00c8195282e2d95 Mon Sep 17 00:00:00 2001 From: joaodragao Date: Thu, 11 Aug 2016 19:20:17 +0100 Subject: [PATCH 05/15] Update & add avoid catching Pokemon if no pokeball --- pokemongo_bot/cell_workers/pokemon_catch_worker.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pokemongo_bot/cell_workers/pokemon_catch_worker.py b/pokemongo_bot/cell_workers/pokemon_catch_worker.py index 5fe54242cc..f2b960ac52 100644 --- a/pokemongo_bot/cell_workers/pokemon_catch_worker.py +++ b/pokemongo_bot/cell_workers/pokemon_catch_worker.py @@ -84,6 +84,18 @@ def work(self, response_dict=None): # get pokemon data pokemon_data = response['wild_pokemon']['pokemon_data'] if 'wild_pokemon' in response else response['pokemon_data'] pokemon = Pokemon(self.pokemon_list, pokemon_data) + + # get all available pokeballs + items_stock = self.bot.current_inventory() + current_ball = ITEM_POKEBALL + num_ball = 0 + while current_ball < ITEM_ULTRABALL: + num_ball += items_stock[current_ball] + current_ball += 1 + + # skip if no available pokeballs + if num_ball <= 0: + return WorkerResult.SUCCESS # skip ignored pokemon if not self._should_catch_pokemon(pokemon): @@ -262,7 +274,7 @@ 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]) + min_ultraball_to_keep = self.config.get('min_ultraball_to_be_kept', items_stock[ITEM_ULTRABALL]) while True: From b08f6306ceb165b97d0baab008f4aff75399775c Mon Sep 17 00:00:00 2001 From: joaodragao Date: Thu, 11 Aug 2016 19:25:38 +0100 Subject: [PATCH 06/15] Update conflict contributors --- CONTRIBUTORS.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 245ca63163..7606647a3c 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -60,11 +60,8 @@ * thebigjc * JaapMoolenaar * eevee-github -<<<<<<< HEAD -======= * g0vanish * cmezh * Nivong * kestel ->>>>>>> PokemonGoF/dev * joaodragao From 940402ae55905ed36bbbe61863f5a198dca2a47c Mon Sep 17 00:00:00 2001 From: joaodragao Date: Thu, 11 Aug 2016 21:31:28 +0100 Subject: [PATCH 07/15] Add get `min_ultraball_to_keep` from config file --- pokecli.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pokecli.py b/pokecli.py index 4544ccf124..3b24be67c1 100644 --- a/pokecli.py +++ b/pokecli.py @@ -409,6 +409,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', {}) From 0d5e9fa61393ee009f3eeee801c1ecc986da2a74 Mon Sep 17 00:00:00 2001 From: joaodragao Date: Thu, 11 Aug 2016 21:34:23 +0100 Subject: [PATCH 08/15] Improved `min_ultraball_to_keep` with condition --- pokemongo_bot/cell_workers/pokemon_catch_worker.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pokemongo_bot/cell_workers/pokemon_catch_worker.py b/pokemongo_bot/cell_workers/pokemon_catch_worker.py index f2b960ac52..e01c350f2e 100644 --- a/pokemongo_bot/cell_workers/pokemon_catch_worker.py +++ b/pokemongo_bot/cell_workers/pokemon_catch_worker.py @@ -274,7 +274,11 @@ 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_keep = self.config.get('min_ultraball_to_be_kept', items_stock[ITEM_ULTRABALL]) + # 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: @@ -284,6 +288,8 @@ 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!') + + # 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 From 2534f58d1ddff80c22d2754502d6c4169c906b88 Mon Sep 17 00:00:00 2001 From: joaodragao Date: Thu, 11 Aug 2016 21:35:45 +0100 Subject: [PATCH 09/15] Added `min_ultraball_to_keep` option --- configs/config.json.example | 1 + 1 file changed, 1 insertion(+) diff --git a/configs/config.json.example b/configs/config.json.example index d2f28cf18e..70cee04f0e 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -115,6 +115,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"}, From d0b76b4e80c1b73a22e957f86492d574f2b70123 Mon Sep 17 00:00:00 2001 From: joaodragao Date: Thu, 11 Aug 2016 21:36:17 +0100 Subject: [PATCH 10/15] Added `min_ultraball_to_keep` option --- configs/config.json.cluster.example | 1 + 1 file changed, 1 insertion(+) diff --git a/configs/config.json.cluster.example b/configs/config.json.cluster.example index bb01bb44f3..0fb3aa58b4 100644 --- a/configs/config.json.cluster.example +++ b/configs/config.json.cluster.example @@ -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"}, From 5c4cf9b6b1488e132a6938d3f701c90e6fd69ec6 Mon Sep 17 00:00:00 2001 From: joaodragao Date: Thu, 11 Aug 2016 21:37:00 +0100 Subject: [PATCH 11/15] Added `min_ultraball_to_keep` option --- configs/config.json.map.example | 1 + 1 file changed, 1 insertion(+) diff --git a/configs/config.json.map.example b/configs/config.json.map.example index acb6b2f5ea..bdef75259a 100644 --- a/configs/config.json.map.example +++ b/configs/config.json.map.example @@ -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"}, From 00daaf86c6c35025016b48ad79d731616c7a3d73 Mon Sep 17 00:00:00 2001 From: joaodragao Date: Thu, 11 Aug 2016 21:37:33 +0100 Subject: [PATCH 12/15] Added `min_ultraball_to_keep` option --- configs/config.json.path.example | 1 + 1 file changed, 1 insertion(+) diff --git a/configs/config.json.path.example b/configs/config.json.path.example index 52286b2809..56cad87a6d 100644 --- a/configs/config.json.path.example +++ b/configs/config.json.path.example @@ -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"}, From 90c023d9c3dc4c59eabe86958f0727ec09047f63 Mon Sep 17 00:00:00 2001 From: joaodragao Date: Thu, 11 Aug 2016 21:38:00 +0100 Subject: [PATCH 13/15] Add `min_ultraball_to_keep` option --- configs/config.json.pokemon.example | 1 + 1 file changed, 1 insertion(+) diff --git a/configs/config.json.pokemon.example b/configs/config.json.pokemon.example index c271f21fcc..a98074bf1b 100644 --- a/configs/config.json.pokemon.example +++ b/configs/config.json.pokemon.example @@ -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" }, From 165aa99d0c751e4096617d5a5a80a834c6cd4d01 Mon Sep 17 00:00:00 2001 From: joaodragao Date: Fri, 12 Aug 2016 11:36:58 +0100 Subject: [PATCH 14/15] Remove count all pokeballs --- pokemongo_bot/cell_workers/pokemon_catch_worker.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/pokemongo_bot/cell_workers/pokemon_catch_worker.py b/pokemongo_bot/cell_workers/pokemon_catch_worker.py index e01c350f2e..8205479885 100644 --- a/pokemongo_bot/cell_workers/pokemon_catch_worker.py +++ b/pokemongo_bot/cell_workers/pokemon_catch_worker.py @@ -84,18 +84,6 @@ def work(self, response_dict=None): # get pokemon data pokemon_data = response['wild_pokemon']['pokemon_data'] if 'wild_pokemon' in response else response['pokemon_data'] pokemon = Pokemon(self.pokemon_list, pokemon_data) - - # get all available pokeballs - items_stock = self.bot.current_inventory() - current_ball = ITEM_POKEBALL - num_ball = 0 - while current_ball < ITEM_ULTRABALL: - num_ball += items_stock[current_ball] - current_ball += 1 - - # skip if no available pokeballs - if num_ball <= 0: - return WorkerResult.SUCCESS # skip ignored pokemon if not self._should_catch_pokemon(pokemon): From 844284e85768ebf58a673fbda7de3f77182fcefa Mon Sep 17 00:00:00 2001 From: joaodragao Date: Fri, 12 Aug 2016 11:45:40 +0100 Subject: [PATCH 15/15] Resolved Conflicts --- configs/config.json.example | 3 --- 1 file changed, 3 deletions(-) diff --git a/configs/config.json.example b/configs/config.json.example index 6532929181..f306d3a920 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -113,12 +113,9 @@ "location_cache": true, "distance_unit": "km", "reconnecting_timeout": 15, -<<<<<<< HEAD "catch_randomize_reticle_factor": 1.0, "catch_randomize_spin_factor": 1.0, "min_ultraball_to_keep": 10, -======= ->>>>>>> PokemonGoF/dev "logging_color": true, "catch": { "any": {"catch_above_cp": 0, "catch_above_iv": 0, "logic": "or"},