Skip to content

Commit

Permalink
Fixes: Evolve (#4389)
Browse files Browse the repository at this point in the history
- Add parameter `candy` to `pokemon_evolved` event.

- Fix PokemonOptimizer evolve problem with `pokemon_evolved` event.

- EvolvePokemon now correctly updates inventory even if evolve_log fails.

- EvolvePokemon now emits evolved event with xp & candy.
  • Loading branch information
novadev94 authored and solderzzc committed Aug 20, 2016
1 parent 0fdd90c commit 9ee2515
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
6 changes: 3 additions & 3 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ def _register_events(self):
)
self.event_manager.register_event(
'pokemon_evolved',
parameters=('pokemon', 'iv', 'cp', 'xp')
parameters=('pokemon', 'iv', 'cp', 'xp', 'candy')
)
self.event_manager.register_event('skip_evolve')
self.event_manager.register_event('threw_berry_failed', parameters=('status_code',))
Expand Down Expand Up @@ -519,7 +519,7 @@ def _register_events(self):
self.event_manager.register_event('transfer_log')
self.event_manager.register_event('pokestop_log')
self.event_manager.register_event('softban_log')

def tick(self):
self.health_record.heartbeat()
self.cell = self.get_meta_cell()
Expand Down Expand Up @@ -726,7 +726,7 @@ def login(self):
c = conn.cursor()
c.execute("SELECT COUNT(name) FROM sqlite_master WHERE type='table' AND name='login'")

result = c.fetchone()
result = c.fetchone()

while True:
if result[0] == 1:
Expand Down
41 changes: 26 additions & 15 deletions pokemongo_bot/cell_workers/evolve_pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,21 +105,42 @@ def _execute_pokemon_evolve(self, pokemon, cache):

response_dict = self.api.evolve_pokemon(pokemon_id=pokemon.unique_id)
if response_dict.get('responses', {}).get('EVOLVE_POKEMON', {}).get('result', 0) == 1:
xp = response_dict.get("responses", {}).get("EVOLVE_POKEMON", {}).get("experience_awarded", 0)
evolution = response_dict.get("responses", {}).get("EVOLVE_POKEMON", {}).get("evolved_pokemon_data", {})
awarded_candies = response_dict.get('responses', {}).get('EVOLVE_POKEMON', {}).get('candy_awarded', 0)
candy = inventory.candies().get(pokemon.pokemon_id)

candy.consume(pokemon.evolution_cost - awarded_candies)

self.emit_event(
'pokemon_evolved',
formatted="Successfully evolved {pokemon} with CP {cp} and IV {iv}!",
formatted="Evolved {pokemon} [IV {iv}] [CP {cp}] [{candy} candies] [+{xp} xp]",
data={
'pokemon': pokemon.name,
'iv': pokemon.iv,
'cp': pokemon.cp,
'xp': '?'
'candy': candy.quantity,
'xp': xp,
}
)

inventory.pokemons().remove(pokemon.unique_id)
new_pokemon = inventory.Pokemon(evolution)
inventory.pokemons().add(new_pokemon)

sleep(self.evolve_speed)
evolve_result = True
else:
# cache pokemons we can't evolve. Less server calls
cache[pokemon.name] = 1
sleep(0.7)
evolve_result = False

with self.bot.database as conn:
c = conn.cursor()
c.execute("SELECT COUNT(name) FROM sqlite_master WHERE type='table' AND name='evolve_log'")

result = c.fetchone()
result = c.fetchone()

while True:
if result[0] == 1:
Expand All @@ -133,15 +154,5 @@ def _execute_pokemon_evolve(self, pokemon, cache):
formatted="evolve_log table not found, skipping log"
)
break
awarded_candies = response_dict.get('responses', {}).get('EVOLVE_POKEMON', {}).get('candy_awarded', 0)
inventory.candies().get(pokemon.pokemon_id).consume(pokemon.evolution_cost - awarded_candies)
inventory.pokemons().remove(pokemon.unique_id)
pokemon = Pokemon(response_dict.get('responses', {}).get('EVOLVE_POKEMON', {}).get('evolved_pokemon_data', {}))
inventory.pokemons().add(pokemon)
sleep(self.evolve_speed)
return True
else:
# cache pokemons we can't evolve. Less server calls
cache[pokemon.name] = 1
sleep(0.7)
return False

return evolve_result

0 comments on commit 9ee2515

Please sign in to comment.