From a4418cfd5206910fe2b088d173b027197c054728 Mon Sep 17 00:00:00 2001 From: Nova Date: Sun, 21 Aug 2016 00:23:56 +0700 Subject: [PATCH] Fixes: Evolve - 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. --- pokemongo_bot/__init__.py | 6 +-- pokemongo_bot/cell_workers/evolve_pokemon.py | 41 +++++++++++++------- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index 3927ccfa1a..df0082055b 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -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',)) @@ -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() @@ -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: diff --git a/pokemongo_bot/cell_workers/evolve_pokemon.py b/pokemongo_bot/cell_workers/evolve_pokemon.py index b91ecd2895..d94bd5467f 100644 --- a/pokemongo_bot/cell_workers/evolve_pokemon.py +++ b/pokemongo_bot/cell_workers/evolve_pokemon.py @@ -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: @@ -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