Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…o dev
  • Loading branch information
solderzzc committed Sep 3, 2016
2 parents e7e8422 + 471c2a3 commit 829ae31
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 10 deletions.
2 changes: 1 addition & 1 deletion configs/config.json.optimizer.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"type": "PokemonOptimizer",
"config": {
"enabled": true,
"min_slots_left": 5,
"transfer": true,
"transfer_wait_min": 3,
"transfer_wait_max": 5,
Expand All @@ -15,7 +16,6 @@
"may_use_lucky_egg": true,
"upgrade": true,
"upgrade_level": 60,
"min_slots_left": 5,
"groups": {
"gym": ["Dragonite", "Snorlax", "Lapras", "Arcanine"]
},
Expand Down
16 changes: 15 additions & 1 deletion docs/pokemon_optimizer.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- [Default configuration](#default-configuration)
- [Understand parameters](#understand-parameters)
- [enabled](#enabled)
- [min_slots_left](#min_slots_left)
- [transfer](#transfer)
- [transfer_wait_min](#transfer_wait_min)
- [transfer_wait_max](#transfer_wait_max)
Expand All @@ -26,10 +27,13 @@
- [Eevee case](#eevee-case)

# About
The Pokemon Optimizer manage transfer and evolution of your Pokemon.
The Pokemon Optimizer manage transfer, evolution and upgrade of your Pokemon.
<br>It can replace or complement the classical Evolve and Transfer tasks.
<br>It will be triggered when you bag of Pokemon is full and has no effect until it happens.

The Pokemon Optimizer will first Transfer, then Evolve, then Upgrade.
There is only one pass at each action.

[[back to top](#pokemon-optimizer)]

# Configuration
Expand All @@ -41,6 +45,7 @@ The Pokemon Optimizer manage transfer and evolution of your Pokemon.
"type": "PokemonOptimizer",
"config": {
"enabled": true,
"min_slots_left": 5,
"transfer": true,
"transfer_wait_min": 3,
"transfer_wait_max": 5,
Expand Down Expand Up @@ -104,6 +109,15 @@ Enable or disable the task.

[[back to top](#pokemon-optimizer)]

### min_slots_left
| Parameter | Possible values | Default |
|------------------|-----------------|---------|
| `min_slots_left` | `[0-N]` | `5` |

The Pokemon Optimizer will be triggered when you have that number (or less) empty slots in your Pokemon Bag.

[[back to top](#pokemon-optimizer)]

### transfer
| Parameter | Possible values | Default |
|------------|-----------------|---------|
Expand Down
5 changes: 3 additions & 2 deletions pokemongo_bot/cell_workers/pokemon_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def initialize(self):
with open(pokemon_upgrade_cost_file, "r") as fd:
self.pokemon_upgrade_cost = json.load(fd)

self.config_min_slots_left = self.config.get("min_slots_left", 5)
self.config_transfer = self.config.get("transfer", False)
self.config_transfer_wait_min = self.config.get("transfer_wait_min", 3)
self.config_transfer_wait_max = self.config.get("transfer_wait_max", 5)
Expand Down Expand Up @@ -68,7 +69,7 @@ def get_pokemon_slot_left(self):
return inventory.Pokemons.get_space_left()

def work(self):
if (not self.enabled) or self.get_pokemon_slot_left() > self.config.get("min_slots_left", 5):
if (not self.enabled) or (self.get_pokemon_slot_left() > self.config_min_slots_left):
return WorkerResult.SUCCESS

self.open_inventory()
Expand Down Expand Up @@ -437,7 +438,7 @@ def apply_optimization(self, transfer, evolve, upgrade, xp):
skip_evolve = True
self.emit_event("skip_evolve",
formatted="Skipping evolution step. Not enough Pokemon to evolve with lucky egg: %s/%s" % (len(evolve) + len(xp), self.config_evolve_count_for_lucky_egg))
elif self.get_pokemon_slot_left() > self.config.get("min_slots_left", 5):
elif self.get_pokemon_slot_left() > self.config_min_slots_left:
skip_evolve = True
self.emit_event("skip_evolve",
formatted="Waiting for more Pokemon to evolve with lucky egg: %s/%s" % (len(evolve) + len(xp), self.config_evolve_count_for_lucky_egg))
Expand Down
4 changes: 2 additions & 2 deletions pokemongo_bot/event_handlers/telegram_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ def run(self):
self.bot.event_manager._handlers = filter(lambda x: not isinstance(x, TelegramHandler), self.bot.event_manager._handlers)
# add new handler (passing newconfig as parameter)
self.bot.event_manager.add_handler(TelegramHandler(self.bot, newconfig))


if update.message.text == "/info":
self.send_player_stats_to_chat(update.message.chat_id)
elif update.message.text == "/start" or update.message.text == "/help":
Expand Down Expand Up @@ -145,6 +143,8 @@ def handle_event(self, event, sender, level, formatted_msg, data):
msg = "Caught {} CP: {}, IV: {}".format(data["pokemon"], data["cp"], data["iv"])
else:
return
elif event == 'egg_hatched':
msg = "Egg hatched with a {} CP: {}, IV: {}".format(data["pokemon"], data["cp"], data["iv"])
elif event == 'catch_limit':
self.tbot.send_player_stats_to_chat(master)
msg = "*You have reached your daily catch limit, quitting.*"
Expand Down
12 changes: 9 additions & 3 deletions pokemongo_bot/walkers/polyline_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class PolylineObjectHandler:
_run = False

@staticmethod
def cached_polyline(origin, destination, speed):
def cached_polyline(origin, destination, speed, google_map_api_key=None):
'''
Google API has limits, so we can't generate new Polyline at every tick...
'''
Expand All @@ -44,7 +44,7 @@ def cached_polyline(origin, destination, speed):
PolylineObjectHandler._run = True
PolylineObjectHandler._instability = 20 # next N moves use same cache

PolylineObjectHandler._cache = Polyline(origin, destination, speed)
PolylineObjectHandler._cache = Polyline(origin, destination, speed, google_map_api_key)
else:
# valid cache found
PolylineObjectHandler._instability -= 1
Expand All @@ -54,13 +54,15 @@ def cached_polyline(origin, destination, speed):


class Polyline(object):
def __init__(self, origin, destination, speed):
def __init__(self, origin, destination, speed, google_map_api_key=None):
self.DIRECTIONS_API_URL='https://maps.googleapis.com/maps/api/directions/json?mode=walking'
self.origin = origin
self.destination = tuple(destination)
self.DIRECTIONS_URL = '{}&origin={}&destination={}'.format(self.DIRECTIONS_API_URL,
'{},{}'.format(*self.origin),
'{},{}'.format(*self.destination))
if google_map_api_key:
self.DIRECTIONS_URL = '{}&key={}'.format(self.DIRECTIONS_URL, google_map_api_key)

self.directions_response = requests.get(self.DIRECTIONS_URL).json()
try:
Expand Down Expand Up @@ -88,6 +90,10 @@ def __init__(self, origin, destination, speed):
self.ELEVATION_API_URL='https://maps.googleapis.com/maps/api/elevation/json?path=enc:'
self.ELEVATION_URL = '{}{}&samples={}'.format(self.ELEVATION_API_URL,
self.polyline, self.elevation_samples)

if google_map_api_key:
self.ELEVATION_URL = '{}&key={}'.format(self.ELEVATION_URL, google_map_api_key)

self.elevation_response = requests.get(self.ELEVATION_URL).json()
self.polyline_elevations = [x['elevation'] for x in self.elevation_response['results']] or [None]
self._timestamp = time.time()
Expand Down
2 changes: 1 addition & 1 deletion pokemongo_bot/walkers/polyline_walker.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __init__(self, bot, dest_lat, dest_lng):
self.actual_pos = tuple(self.bot.position[:2])
self.polyline = PolylineObjectHandler.cached_polyline(self.actual_pos,
(self.dest_lat, self.dest_lng),
self.speed)
self.speed, google_map_api_key=self.bot.config.gmapkey)
self.pol_lat, self.pol_lon = self.polyline.get_pos()
self.pol_alt = self.polyline.get_alt() or uniform(self.bot.config.alt_min, self.bot.config.alt_max)
super(PolylineWalker, self).__init__(self.bot, self.pol_lat, self.pol_lon,
Expand Down

0 comments on commit 829ae31

Please sign in to comment.