Skip to content

Commit

Permalink
Add lucky egg support when enough pokemon to evolve
Browse files Browse the repository at this point in the history
  • Loading branch information
julienlavergne committed Aug 8, 2016
1 parent e2e71f1 commit 4b0faaa
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions pokemongo_bot/cell_workers/pokemon_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def initialize(self):
self.lucky_egg_count = 0

self.dry_run = self.config.get("dry_run", True)
self.use_lucky_egg = self.config.get("use_lucky_egg", False)
self.use_lucky_egg = self.config.get("use_lucky_egg", True)

def get_pokemon_slot_left(self):
return self.bot._player["max_pokemon_storage"] - self.pokemon_count
Expand Down Expand Up @@ -51,9 +51,6 @@ def work(self):

evo_all_pokemons = evo_all_best_pokemons + evo_all_crap_pokemons

if (not self.use_lucky_egg) or (self.lucky_egg_count == 0) or (len(evo_all_pokemons) < 90):
del evo_all_pokemons[:]

family_changed = self.apply_optimization(transfer_all_pokemons, evo_all_pokemons)

if self.dry_run:
Expand Down Expand Up @@ -129,6 +126,12 @@ def apply_optimization(self, transfer_pokemons, evo_pokemons):
self.transfer_pokemon(pokemon)
family_changed = True

if self.use_lucky_egg:
if (self.lucky_egg_count == 0) or (len(evo_pokemons) < 90):
return family_changed

self.do_use_lucky_egg()

for pokemon in evo_pokemons:
if self.evolve_pokemon(pokemon):
family_changed = True
Expand Down Expand Up @@ -164,6 +167,31 @@ def transfer_pokemon(self, pokemon):
if not self.dry_run:
action_delay(self.bot.config.action_wait_min, self.bot.config.action_wait_max)

def do_use_lucky_egg(self):
if self.dry_run:
response_dict = {"responses": {"USE_ITEM_XP_BOOST": {"result": 1}}}
else:
response_dict = self.bot.use_lucky_egg()

if not response_dict:
self.emit_event("lucky_egg_error",
level='error',
formatted="Failed to use lucky egg!")
return False

result = response_dict.get("responses", {}).get("USE_ITEM_XP_BOOST", {}).get("result", 0)

if result == 1:
self.emit_event("used_lucky_egg",
formatted="Used lucky egg ({amount_left} left).",
data={"amount_left": self.lucky_egg_count - 1})
return True
else:
self.emit_event("lucky_egg_error",
level='error',
formatted="Failed to use lucky egg!")
return False

def evolve_pokemon(self, pokemon):
if self.dry_run:
response_dict = {"responses": {"EVOLVE_POKEMON": {"result": 1}}}
Expand Down

0 comments on commit 4b0faaa

Please sign in to comment.