Skip to content

Commit

Permalink
Merge pull request #4810 from developerllazy/dev
Browse files Browse the repository at this point in the history
Seperate sorting for breakable and unbreakable incubator
  • Loading branch information
solderzzc authored Aug 27, 2016
2 parents f8cfc5a + cb9a6a6 commit 44307ae
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 22 deletions.
3 changes: 2 additions & 1 deletion configs/config.json.cluster.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
},
Expand Down
3 changes: 2 additions & 1 deletion configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,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]
Expand Down
3 changes: 2 additions & 1 deletion configs/config.json.map.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
},
Expand Down
3 changes: 2 additions & 1 deletion configs/config.json.optimizer.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
},
Expand Down
3 changes: 2 additions & 1 deletion configs/config.json.path.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
},
Expand Down
3 changes: 2 additions & 1 deletion configs/config.json.pokemon.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
},
Expand Down
6 changes: 4 additions & 2 deletions docs/configuration_files.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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]
}
Expand Down
48 changes: 34 additions & 14 deletions pokemongo_bot/cell_workers/incubate_eggs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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])
Expand All @@ -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:
Expand Down Expand Up @@ -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"],
Expand All @@ -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]
Expand All @@ -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", {})
Expand All @@ -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
Expand Down

0 comments on commit 44307ae

Please sign in to comment.