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

Incubate eggs fix #4881

Merged
merged 10 commits into from
Aug 29, 2016
16 changes: 11 additions & 5 deletions pokemongo_bot/cell_workers/incubate_eggs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from datetime import datetime, timedelta

from pokemongo_bot import inventory
from pokemongo_bot.human_behaviour import sleep
from pokemongo_bot.base_task import BaseTask

Expand Down Expand Up @@ -35,15 +36,18 @@ def work(self):
except:
return

should_print = self._should_print()

if self.used_incubators and IncubateEggs.last_km_walked != self.km_walked:
self.used_incubators.sort(key=lambda x: x.get("km"))
km_left = self.used_incubators[0]['km']-self.km_walked
if km_left <= 0:
self._hatch_eggs()
should_print = False
else:
self.bot.metrics.next_hatching_km(km_left)

if self._should_print():
if should_print:
self._print_eggs()
self._compute_next_update()

Expand All @@ -58,9 +62,9 @@ def work(self):

if self.ready_breakable_incubators:
# get available eggs
eggs = self._filter_sort_eggs(self.infinite_incubator,
self.infinite_longer_eggs_first)
self._apply_incubators(eggs, self.ready_infinite_incubators)
eggs = self._filter_sort_eggs(self.breakable_incubator,
self.breakable_longer_eggs_first)
self._apply_incubators(eggs, self.ready_breakable_incubators)


def _filter_sort_eggs(self, allowed, sorting):
Expand Down Expand Up @@ -203,13 +207,15 @@ def _hatch_eggs(self):
candy = result.get('candy_awarded', "error")
xp = result.get('experience_awarded', "error")
sleep(self.hatching_animation_delay)
self.bot.latest_inventory = None
try:
pokemon_data = self._check_inventory(pokemon_ids)
for pokemon in pokemon_data:
# pokemon ids seem to be offset by one
if pokemon['pokemon_id']!=-1:
pokemon['name'] = self.bot.pokemon_list[(pokemon.get('pokemon_id')-1)]['Name']
#remove as egg and add as pokemon
inventory.pokemons().remove(pokemon['id'])
inventory.pokemons().add(inventory.Pokemon(pokemon))
else:
pokemon['name'] = "error"
except:
Expand Down