Skip to content

Commit

Permalink
Task EvolvePokemon should give us a status updates so we know it is w…
Browse files Browse the repository at this point in the history
…orking
  • Loading branch information
ch1ago committed Sep 22, 2016
1 parent 120a20d commit f76b84a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
1 change: 1 addition & 0 deletions configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
"type": "EvolvePokemon",
"config": {
"enabled": false,
"interval": 60,

"// evolve only pidgey and drowzee": "",
"// evolve_list": "pidgey, drowzee",
Expand Down
8 changes: 6 additions & 2 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -1476,4 +1480,4 @@ def _refresh_inventory(self):
inventory.refresh_inventory()
self.last_inventory_refresh = now
self.inventory_refresh_counter += 1

32 changes: 28 additions & 4 deletions pokemongo_bot/cell_workers/evolve_pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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(',')]

Expand All @@ -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
Expand All @@ -65,19 +70,38 @@ 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 = {}
for pokemon in filtered_list:
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:
Expand Down
1 change: 1 addition & 0 deletions pokemongo_bot/event_handlers/logging_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit f76b84a

Please sign in to comment.