Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,9 @@ will release all Pidgey caught.
evolve specified pokemons on startup. This is especially useful for batch-evolving after popping up
a lucky egg (currently this needs to be done manually).

The evolve all mechanism evolves only higher CP pokemons. It does this by first ordering them from high-to-low CP.
The evolve all mechanism evolves only higher IV/CP pokemons. It works by sorting the high CP pokemons (default: 300 CP or higher)
based on their IV values. After evolving all high CP pokemons, the mechanism will move on to evolving lower CP pokemons
only based on their CP (if it can).
It will also automatically transfer the evolved pokemons based on the release configuration.

Examples on how to use (set in config.json):
Expand All @@ -220,6 +222,10 @@ will release all Pidgey caught.
2. "evolve_all": "Pidgey,Weedle"
Will only evolve Pidgey and Weedle.
3. Not setting evolve_all or having any other string would not evolve any pokemons on startup.

If you wish to change the default threshold of 300 CP, simply add the following to the config file:
"cp_min": <number>


## How to run with Docker

Expand Down
3 changes: 2 additions & 1 deletion configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
"distance_unit": "km",
"item_filter": "",
"evolve_all": "NONE",
"cp_min": 300,
"use_lucky_egg": false,
"catch": {
"any": {"catch_above_cp": 0, "catch_above_iv": 0, "logic": "or"}
},
"release": {
"any": {"release_under_cp": 0, "release_under_iv": 0, "logic": "or"}
}
}
}
8 changes: 8 additions & 0 deletions pokecli.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ def init_config():
help="(Batch mode) Pass \"all\" or a list of pokemons to evolve (e.g., \"Pidgey,Weedle,Caterpie\"). Bot will start by attempting to evolve all pokemons. Great after popping a lucky egg!",
type=str,
default=[])

parser.add_argument(
"-cm",
"--cp_min",
help=
"Minimum CP for evolve all. Bot will attempt to first evolve highest IV pokemons with CP larger than this.",
type=int,
default=300)

parser.add_argument("-ec",
"--evolve_captured",
Expand Down
49 changes: 31 additions & 18 deletions pokemongo_bot/cell_workers/evolve_all_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ def work(self):
except KeyError:
pass
else:
evolve_list = self._sort_by_cp(response_dict['responses']['GET_INVENTORY']['inventory_delta']['inventory_items'])
evolve_list = self._sort_by_cp_iv(response_dict['responses']['GET_INVENTORY']['inventory_delta']['inventory_items'])
if self.config.evolve_all[0] != 'all':
# filter out non-listed pokemons
evolve_list = [x for x in evolve_list if str(x[1]) in self.config.evolve_all]

## enable to limit number of pokemons to evolve. Useful for testing.
# nn = 1
# enable to limit number of pokemons to evolve. Useful for testing.
# nn = 3
# if len(evolve_list) > nn:
# evolve_list = evolve_list[:nn]
##
#

id_list1 = self.count_pokemon_inventory()
for pokemon in evolve_list:
Expand Down Expand Up @@ -58,7 +58,7 @@ def _release_evolved(self, release_cand_list_ids):
except KeyError:
pass
else:
release_cand_list = self._sort_by_cp(response_dict['responses']['GET_INVENTORY']['inventory_delta']['inventory_items'])
release_cand_list = self._sort_by_cp_iv(response_dict['responses']['GET_INVENTORY']['inventory_delta']['inventory_items'])
release_cand_list = [x for x in release_cand_list if x[0] in release_cand_list_ids]

## at this point release_cand_list contains evolved pokemons data
Expand All @@ -74,8 +74,9 @@ def _release_evolved(self, release_cand_list_ids):
logger.log(
'[#] {} has been exchanged for candy!'.format(pokemon_name), 'green')

def _sort_by_cp(self, inventory_items):
pokemons = []
def _sort_by_cp_iv(self, inventory_items):
pokemons1 = []
pokemons2 = []
for item in inventory_items:
try:
reduce(dict.__getitem__, [
Expand All @@ -87,22 +88,32 @@ def _sort_by_cp(self, inventory_items):
pokemon = item['inventory_item_data']['pokemon_data']
pokemon_num = int(pokemon['pokemon_id']) - 1
pokemon_name = self.bot.pokemon_list[int(pokemon_num)]['Name']
pokemons.append([
pokemon['id'],
pokemon_name,
pokemon['cp'],
self._compute_iv(pokemon)
])
v = [
pokemon['id'],
pokemon_name,
pokemon['cp'],
self._compute_iv(pokemon)
]
if pokemon['cp'] > self.config.cp_min:
pokemons1.append(v)
else:
pokemons2.append(v)
except:
pass

pokemons.sort(key=lambda x: x[2], reverse=True)
return pokemons
## Sort larger CP pokemons by IV, tie breaking by CP
pokemons1.sort(key=lambda x: (x[3], x[2]), reverse=True)

## Sort smaller CP pokemons by CP, tie breaking by IV
pokemons2.sort(key=lambda x: (x[2], x[3]), reverse=True)

return pokemons1 + pokemons2

def _execute_pokemon_evolve(self, pokemon, cache):
pokemon_id = pokemon[0]
pokemon_name = pokemon[1]
pokemon_cp = pokemon[2]
pokemon_iv = pokemon[3]

if pokemon_name in cache:
return
Expand All @@ -111,13 +122,15 @@ def _execute_pokemon_evolve(self, pokemon, cache):
response_dict = self.api.call()
status = response_dict['responses']['EVOLVE_POKEMON']['result']
if status == 1:
print('[#] Successfully evolved {} with {} cp!'.format(
pokemon_name, pokemon_cp
print('[#] Successfully evolved {} with {} CP and {} IV!'.format(
pokemon_name, pokemon_cp, pokemon_iv
))
sleep(3.7)
else:
# cache pokemons we can't evolve. Less server calls
cache[pokemon_name] = 1
sleep(5.7)
sleep(0.7)


# TODO: move to utils. These methods are shared with other workers.
def transfer_pokemon(self, pid):
Expand Down