From cb9a6a66602ce130d32ca2f610655ba804b3d90d Mon Sep 17 00:00:00 2001 From: Roy Loo Date: Sat, 27 Aug 2016 21:46:06 +0800 Subject: [PATCH] Seperate sorting for breakable and unbreakable incubator --- configs/config.json.cluster.example | 3 +- configs/config.json.example | 3 +- configs/config.json.map.example | 3 +- configs/config.json.optimizer.example | 3 +- configs/config.json.path.example | 3 +- configs/config.json.pokemon.example | 3 +- docs/configuration_files.md | 6 ++- pokemongo_bot/cell_workers/incubate_eggs.py | 48 +++++++++++++++------ 8 files changed, 50 insertions(+), 22 deletions(-) diff --git a/configs/config.json.cluster.example b/configs/config.json.cluster.example index 77fc049df3..b48b3cfd0e 100644 --- a/configs/config.json.cluster.example +++ b/configs/config.json.cluster.example @@ -40,7 +40,8 @@ "type": "IncubateEggs", "config": { "enabled": true, - "longer_eggs_first": true, + "infinite_longer_eggs_first": false, + "breakable_longer_eggs_first": true, "min_interval": 120 } }, diff --git a/configs/config.json.example b/configs/config.json.example index a0878aabb0..94f0051f1c 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -50,7 +50,8 @@ "type": "IncubateEggs", "config": { "enabled": true, - "longer_eggs_first": true, + "infinite_longer_eggs_first": false, + "breakable_longer_eggs_first": true, "min_interval": 120, "infinite": [2,5,10], "breakable": [2,5,10] diff --git a/configs/config.json.map.example b/configs/config.json.map.example index 9cfcd34f37..914b9682a3 100644 --- a/configs/config.json.map.example +++ b/configs/config.json.map.example @@ -40,7 +40,8 @@ "type": "IncubateEggs", "config": { "enabled": true, - "longer_eggs_first": true, + "infinite_longer_eggs_first": false, + "breakable_longer_eggs_first": true, "min_interval": 120 } }, diff --git a/configs/config.json.optimizer.example b/configs/config.json.optimizer.example index bd0bab43bc..80031964a9 100644 --- a/configs/config.json.optimizer.example +++ b/configs/config.json.optimizer.example @@ -40,7 +40,8 @@ "type": "IncubateEggs", "config": { "enabled": true, - "longer_eggs_first": true, + "infinite_longer_eggs_first": false, + "breakable_longer_eggs_first": true, "min_interval": 120 } }, diff --git a/configs/config.json.path.example b/configs/config.json.path.example index 51927b1c33..04b17c2f2f 100644 --- a/configs/config.json.path.example +++ b/configs/config.json.path.example @@ -40,7 +40,8 @@ "type": "IncubateEggs", "config": { "enabled": true, - "longer_eggs_first": true, + "infinite_longer_eggs_first": false, + "breakable_longer_eggs_first": true, "min_interval": 120 } }, diff --git a/configs/config.json.pokemon.example b/configs/config.json.pokemon.example index 4dda53e0f0..c67930479c 100644 --- a/configs/config.json.pokemon.example +++ b/configs/config.json.pokemon.example @@ -40,7 +40,8 @@ "type": "IncubateEggs", "config": { "enabled": true, - "longer_eggs_first": true, + "infinite_longer_eggs_first": false, + "breakable_longer_eggs_first": true, "min_interval": 120 } }, diff --git a/docs/configuration_files.md b/docs/configuration_files.md index 4cc300db0b..ef47e7d07d 100644 --- a/docs/configuration_files.md +++ b/docs/configuration_files.md @@ -836,7 +836,8 @@ Simulates the random pause of the day (speaking to someone, getting into a store Configure how the bot should use the incubators. -- `longer_eggs_first`: (True | False ) should the bot start by the longer eggs first. If set to true, the bot first use the 10km eggs, then the 5km eggs, then the 2km eggs. +- `infinite_longer_eggs_first`: (True | False ) should the bot start by the longer eggs first for the unbreakable incubator. If set to true, the bot first use the 10km eggs, then the 5km eggs, then the 2km eggs. +- `breakable_longer_eggs_first`: (True | False ) should the bot start by the longer eggs first for the breakable incubator. If set to true, the bot first use the 10km eggs, then the 5km eggs, then the 2km eggs. - `infinite`: ([2], [2,5], [2,5,10], []) the type of egg the infinite (ie. unbreakable) incubator(s) can incubate. If set to [2,5], the incubator(s) can only incubate the 2km and 5km eggs. If set to [], the incubator(s) will not incubate any type of egg. - `breakable`: ([2], [2,5], [2,5,10], []) the type of egg the breakable incubator(s) can incubate. If set to [2,5], the incubator(s) can only incubate the 2km and 5km eggs. If set to [], the incubator(s) will not incubate any type of egg. @@ -845,7 +846,8 @@ Configure how the bot should use the incubators. { "type": "IncubateEggs", "config": { - "longer_eggs_first": true, + "infinite_longer_eggs_first": false, + "breakable_longer_eggs_first": true, "infinite": [2,5], "breakable": [10] } diff --git a/pokemongo_bot/cell_workers/incubate_eggs.py b/pokemongo_bot/cell_workers/incubate_eggs.py index 4b161df97f..76f9885018 100644 --- a/pokemongo_bot/cell_workers/incubate_eggs.py +++ b/pokemongo_bot/cell_workers/incubate_eggs.py @@ -11,7 +11,8 @@ class IncubateEggs(BaseTask): def initialize(self): self.next_update = None - self.ready_incubators = [] + self.ready_incubators_breakable = [] + self.ready_incubators_infinite = [] self.used_incubators = [] self.eggs = [] self.km_walked = 0 @@ -21,7 +22,8 @@ def initialize(self): self._process_config() def _process_config(self): - self.longer_eggs_first = self.config.get("longer_eggs_first", True) + self.infinite_longer_eggs_first = self.config.get("infinite_longer_eggs_first", False) + self.breakable_longer_eggs_first = self.config.get("breakable_longer_eggs_first", True) self.min_interval = self.config.get('min_interval', 120) self.breakable_incubator = self.config.get("breakable", [2,5,10]) @@ -47,14 +49,23 @@ def work(self): IncubateEggs.last_km_walked = self.km_walked - sorting = self.longer_eggs_first + sorting = self.breakable_longer_eggs_first self.eggs.sort(key=lambda x: x.get("km"), reverse=sorting) + if self.ready_incubators_breakable: + self._apply_incubators('breakable') - if self.ready_incubators: - self._apply_incubators() + sorting = self.infinite_longer_eggs_first + self.eggs.sort(key=lambda x: x.get("km"), reverse=sorting) + if self.ready_incubators_infinite: + self._apply_incubators('infinite') - def _apply_incubators(self): - for incubator in self.ready_incubators: + def _apply_incubators(self, type_of_incubator): + if type_of_incubator == 'breakable': + temp_ready_incubators = self.ready_incubators_breakable + elif type_of_incubator == 'infinite': + temp_ready_incubators = self.ready_incubators_infinite + + for incubator in temp_ready_incubators: if incubator.get('used', False): continue for egg in self.eggs: @@ -120,7 +131,8 @@ def _check_inventory(self, lookup_ids=[]): matched_pokemon = [] temp_eggs = [] temp_used_incubators = [] - temp_ready_incubators = [] + temp_ready_incubators_breakable = [] + temp_ready_incubators_infinite = [] inv = reduce( dict.__getitem__, ["responses", "GET_INVENTORY", "inventory_delta", "inventory_items"], @@ -130,7 +142,8 @@ def _check_inventory(self, lookup_ids=[]): inv_data = inv_data.get("inventory_item_data", {}) if "egg_incubators" in inv_data: temp_used_incubators = [] - temp_ready_incubators = [] + temp_ready_incubators_breakable = [] + temp_ready_incubators_infinite = [] incubators = inv_data.get("egg_incubators", {}).get("egg_incubator",[]) if isinstance(incubators, basestring): # checking for old response incubators = [incubators] @@ -144,9 +157,14 @@ def _check_inventory(self, lookup_ids=[]): "km_needed": (km_walked - start_km) }) else: - temp_ready_incubators.append({ - "id": incubator.get('id', -1) - }) + if incubator.get('uses_remaining') is not None: + temp_ready_incubators_breakable.append({ + "id": incubator.get('id', -1) + }) + else: + temp_ready_incubators_infinite.append({ + "id": incubator.get('id', -1) + }) continue if "pokemon_data" in inv_data: pokemon = inv_data.get("pokemon_data", {}) @@ -169,8 +187,10 @@ def _check_inventory(self, lookup_ids=[]): self.km_walked = inv_data.get("player_stats", {}).get("km_walked", 0) if temp_used_incubators: self.used_incubators = temp_used_incubators - if temp_ready_incubators: - self.ready_incubators = temp_ready_incubators + if temp_ready_incubators_breakable: + self.ready_incubators_breakable = temp_ready_incubators_breakable + if temp_ready_incubators_infinite: + self.ready_incubators_infinite = temp_ready_incubators_infinite if temp_eggs: self.eggs = temp_eggs return matched_pokemon