From abfdb5904207d1898debc0fda0765cd6b79168f2 Mon Sep 17 00:00:00 2001 From: Cody Baldwin Date: Sun, 24 Jul 2016 21:39:20 -0400 Subject: [PATCH] Lucky Egg - Evolve All Provides the ability to use a lucky egg before evolve_all. This will maximize xp gain. --- README.md | 7 ++++++- config.json.example | 3 ++- pokecli.py | 5 +++++ pokemongo_bot/__init__.py | 43 +++++++++++++++++++++++++++++++++++---- 4 files changed, 52 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 4c0d8f4b44..816284c9c5 100644 --- a/README.md +++ b/README.md @@ -191,11 +191,15 @@ To update your project do: `git pull` in the project folder - `distance_unit` : - `item_filter` : - `evolve_all` : Set to true to evolve pokemon if possible +- `use_lucky_egg` : Set to true to use lucky egg (if available) before evolve_all ### Evolve All Configuration By setting the `evolve_all` attribute in config.json, you can instruct the bot to automatically 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). + a lucky egg. + + A lucky egg can be used before evolving by setting the `use_lucky_egg` to true in config.json. If a + lucky egg is not available and "use_lucky_egg" is set to true, evolving will be skipped. The evolve all mechanism evolves only higher CP pokemons. It does this by first ordering them from high-to-low CP. It will also automatically transfer the evolved pokemons based on the release configuration. @@ -338,6 +342,7 @@ If using multiple usernames format like this: * riberod07 * th3w4y * Leaklessgfy + * codybaldwin ------- ## Credits diff --git a/config.json.example b/config.json.example index 3245708e6d..e6863521c9 100644 --- a/config.json.example +++ b/config.json.example @@ -13,5 +13,6 @@ "location_cache": true, "distance_unit": "km", "item_filter": "101,102,103,104", - "evolve_all": "NONE" + "evolve_all": "NONE", + "use_lucky_egg": false } diff --git a/pokecli.py b/pokecli.py index 07cf746c06..dfd4506ae2 100755 --- a/pokecli.py +++ b/pokecli.py @@ -144,6 +144,11 @@ def init_config(): help="(Ad-hoc mode) Bot will attempt to evolve all the pokemons captured!", type=bool, default=False) + parser.add_argument("-le", + "--use_lucky_egg", + help="Uses lucky egg when using evolve_all", + type=bool, + default=False) config = parser.parse_args() if not config.username and 'username' not in load: diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index d6df1a38d7..90194921b5 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -38,10 +38,38 @@ def take_step(self): def work_on_cell(self, cell, position, include_fort_on_path): if self.config.evolve_all: - # Run evolve all once. Flip the bit. - print('[#] Attempting to evolve all pokemons ...') - worker = EvolveAllWorker(self) - worker.work() + # Will skip evolving if user wants to use an egg and there is none + skip_evolves = False + + # Pop lucky egg before evolving to maximize xp gain + if self.config.use_lucky_egg: + if self.item_inventory_count(Item.ITEM_LUCKY_EGG.value) > 0: + logger.log('[#] Using lucky egg ... you have {}' + .format(self.item_inventory_count(Item.ITEM_LUCKY_EGG.value))) + response_dict_lucky_egg = self.use_lucky_egg() + if response_dict_lucky_egg and \ + 'responses' in response_dict_lucky_egg and \ + 'USE_ITEM_XP_BOOST' in response_dict_lucky_egg['responses'] and \ + 'result' in response_dict_lucky_egg['responses']['USE_ITEM_XP_BOOST']: + result = response_dict_lucky_egg['responses']['USE_ITEM_XP_BOOST']['result'] + if result is 1: # Request success + logger.log('[+] Successfully used lucky egg... ({} left!)' + .format(self.item_inventory_count(Item.ITEM_LUCKY_EGG.value)), 'green') + else: + logger.log('[+] Failed to use lucky egg!', 'red') + skip_evolves = True + else: + # Skipping evolve so they aren't wasted + logger.log('[#] No lucky eggs... skipping evolve!', 'yellow') + skip_evolves = True + + if not skip_evolves: + # Run evolve all once. + print('[#] Attempting to evolve all pokemons ...') + worker = EvolveAllWorker(self) + worker.work() + + # Flip the bit. self.config.evolve_all = [] self._filter_ignored_pokemons(cell) @@ -204,6 +232,13 @@ def drop_item(self, item_id, count): # Example of good request response #{'responses': {'RECYCLE_INVENTORY_ITEM': {'result': 1, 'new_count': 46}}, 'status_code': 1, 'auth_ticket': {'expire_timestamp_ms': 1469306228058L, 'start': '/HycFyfrT4t2yB2Ij+yoi+on778aymMgxY6RQgvrGAfQlNzRuIjpcnDd5dAxmfoTqDQrbz1m2dGqAIhJ+eFapg==', 'end': 'f5NOZ95a843tgzprJo4W7Q=='}, 'request_id': 8145806132888207460L} return inventory_req + + def use_lucky_egg(self): + self.api.use_item_xp_boost(item_id=301) + inventory_req = self.api.call() + + return inventory_req + def update_inventory(self): self.api.get_inventory()