diff --git a/configs/config.json.example b/configs/config.json.example index 3527fad4ba..8c82d4b178 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -153,6 +153,7 @@ "type": "EvolvePokemon", "config": { "enabled": false, + "interval": 60, "// evolve only pidgey and drowzee": "", "// evolve_list": "pidgey, drowzee", diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index dddff7da51..afa016b233 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -117,7 +117,7 @@ def __init__(self, db, config): self.heartbeat_counter = 0 self.last_heartbeat = time.time() self.hb_locked = False # lock hb on snip - + # Inventory refresh limiting self.inventory_refresh_threshold = 10 self.inventory_refresh_counter = 0 @@ -477,6 +477,10 @@ def _register_events(self): 'pokemon_evolved', parameters=('pokemon', 'iv', 'cp', 'candy', 'xp') ) + self.event_manager.register_event( + 'pokemon_evolve_check', + parameters=('has', 'needs', 'message') + ) self.event_manager.register_event( 'pokemon_upgraded', parameters=('pokemon', 'iv', 'cp', 'candy', 'stardust') @@ -1476,4 +1480,4 @@ def _refresh_inventory(self): inventory.refresh_inventory() self.last_inventory_refresh = now self.inventory_refresh_counter += 1 - + diff --git a/pokemongo_bot/cell_workers/evolve_pokemon.py b/pokemongo_bot/cell_workers/evolve_pokemon.py index f21c6d9251..668ce6da5c 100644 --- a/pokemongo_bot/cell_workers/evolve_pokemon.py +++ b/pokemongo_bot/cell_workers/evolve_pokemon.py @@ -17,6 +17,8 @@ def __init__(self, bot, config): def initialize(self): self.start_time = 0 + self.next_update = None + self.interval = self.config.get('interval', 60) self.evolve_list = self.config.get('evolve_list', []) self.donot_evolve_list = self.config.get('donot_evolve_list', []) self.min_evolve_speed = self.config.get('min_evolve_speed', 25) @@ -41,7 +43,7 @@ def initialize(self): def _validate_config(self): if isinstance(self.evolve_list, basestring): self.evolve_list = [str(pokemon_name).lower().strip() for pokemon_name in self.evolve_list.split(',')] - + if isinstance(self.donot_evolve_list, basestring): self.donot_evolve_list = [str(pokemon_name).lower().strip() for pokemon_name in self.donot_evolve_list.split(',')] @@ -55,6 +57,9 @@ def work(self): if not self._should_run(): return + self._compute_next_update() + + result_message = "" filtered_list, filtered_dict = self._sort_and_filter() pokemon_to_be_evolved = 0 @@ -65,7 +70,10 @@ def work(self): candy = inventory.candies().get(pokemon.pokemon_id) pokemon_to_be_evolved = pokemon_to_be_evolved + min(candy.quantity / (pokemon.evolution_cost - 1), filtered_dict[pokemon.pokemon_id]) - if pokemon_to_be_evolved >= self.min_pokemon_to_be_evolved: + self._print_check(pokemon_to_be_evolved) + + has_minimum_to_evolve = pokemon_to_be_evolved >= self.min_pokemon_to_be_evolved + if has_minimum_to_evolve: if self.use_lucky_egg: self._use_lucky_egg() cache = {} @@ -73,11 +81,27 @@ def work(self): if pokemon.can_evolve_now(): self._execute_pokemon_evolve(pokemon, cache) + def _print_check(self, pokemon_to_be_evolved): + has_minimum_to_evolve = pokemon_to_be_evolved >= self.min_pokemon_to_be_evolved + result_message = ("Gotta catch`em all!", "Gotta evolv`em all!")[has_minimum_to_evolve] + self.emit_event( + 'pokemon_evolve_check', + formatted='Checking... Has {has}, needs {needs}. {message}', + data={ + 'has': pokemon_to_be_evolved, + 'needs': self.min_pokemon_to_be_evolved, + 'message': result_message + } + ) + def _should_run(self): if not self.evolve_list or self.evolve_list[0] == 'none': return False - return True - + return self.next_update is None or datetime.now() >= self.next_update + + def _compute_next_update(self): + self.next_update = datetime.now() + timedelta(seconds=self.interval) + def _use_lucky_egg(self): using_lucky_egg = time.time() - self.start_time < 1800 if using_lucky_egg: diff --git a/pokemongo_bot/event_handlers/logging_handler.py b/pokemongo_bot/event_handlers/logging_handler.py index b433b7e4b6..d0291c0f0e 100644 --- a/pokemongo_bot/event_handlers/logging_handler.py +++ b/pokemongo_bot/event_handlers/logging_handler.py @@ -61,6 +61,7 @@ class LoggingHandler(EventHandler): 'pokemon_capture_failed': 'red', 'pokemon_caught': 'blue', 'pokemon_evolved': 'green', + 'pokemon_evolve_check': 'green', 'pokemon_fled': 'red', 'pokemon_inventory_full': 'red', 'pokemon_nickname_invalid': 'red',