From 5294e8421e0a5e475f284528cf9979c4ab69c095 Mon Sep 17 00:00:00 2001 From: Tobias Stumm Date: Thu, 28 Jul 2016 15:18:49 +0200 Subject: [PATCH 01/13] Added worker for incubating eggs --- pokecli.py | 3 + pokemongo_bot/__init__.py | 3 +- pokemongo_bot/cell_workers/__init__.py | 1 + .../cell_workers/incubate_eggs_worker.py | 65 +++++++++++++++++++ 4 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 pokemongo_bot/cell_workers/incubate_eggs_worker.py diff --git a/pokecli.py b/pokecli.py index c912eecb2a..f39f2b83df 100755 --- a/pokecli.py +++ b/pokecli.py @@ -207,6 +207,9 @@ def init_config(): config.action_wait_max = load.get('action_wait_max', 4) config.action_wait_min = load.get('action_wait_min', 1) + config.hatch_eggs = load.get("hatch_eggs", True) + config.longer_eggs_first = load.get("longer_eggs_first", True) + if config.auth_service not in ['ptc', 'google']: logging.error("Invalid Auth service specified! ('ptc' or 'google')") return None diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index e813655f79..f76d065792 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -14,7 +14,7 @@ from pgoapi.utilities import f2i import logger -from cell_workers import SpinNearestFortWorker, CatchVisiblePokemonWorker, PokemonCatchWorker, SeenFortWorker, MoveToFortWorker, PokemonTransferWorker, EvolveAllWorker, RecycleItemsWorker +from cell_workers import SpinNearestFortWorker, CatchVisiblePokemonWorker, PokemonCatchWorker, SeenFortWorker, MoveToFortWorker, PokemonTransferWorker, EvolveAllWorker, RecycleItemsWorker, IncubateEggsWorker from cell_workers.utils import distance, get_cellid, encode, i2f from human_behaviour import sleep from item_list import Item @@ -51,6 +51,7 @@ def tick(self): self.check_session(self.position[0:2]) workers = [ + IncubateEggsWorker, PokemonTransferWorker, EvolveAllWorker, RecycleItemsWorker, diff --git a/pokemongo_bot/cell_workers/__init__.py b/pokemongo_bot/cell_workers/__init__.py index 858f54d7c2..b0a614e42a 100644 --- a/pokemongo_bot/cell_workers/__init__.py +++ b/pokemongo_bot/cell_workers/__init__.py @@ -8,3 +8,4 @@ from catch_visible_pokmeon_worker import CatchVisiblePokemonWorker from recycle_items_worker import RecycleItemsWorker from spin_nearest_fort_worker import SpinNearestFortWorker +from incubate_eggs_worker import IncubateEggsWorker diff --git a/pokemongo_bot/cell_workers/incubate_eggs_worker.py b/pokemongo_bot/cell_workers/incubate_eggs_worker.py new file mode 100644 index 0000000000..c81173d5a4 --- /dev/null +++ b/pokemongo_bot/cell_workers/incubate_eggs_worker.py @@ -0,0 +1,65 @@ +from utils import distance, format_dist +from pokemongo_bot.human_behaviour import sleep +from pokemongo_bot import logger + + +class IncubateEggsWorker(object): + def __init__(self, bot): + self.api = bot.api + self.config = bot.config + self.bot = bot + # self.position = bot.position + + def work(self): + if not self.config.hatch_eggs: + return + + self.api.get_inventory() + response_dict = self.api.call() + inv = {} + incubators = [] + eggs = [] + + try: + inv = reduce(dict.__getitem__, [ + "responses", "GET_INVENTORY", "inventory_delta", "inventory_items"], response_dict) + except KeyError: + pass + else: + for inv_data in inv: + inv_data = inv_data.get("inventory_item_data", {}) + + if "egg_incubators" in inv_data: + for incubator in inv_data.get("egg_incubators", {}).get("egg_incubator", []): + incubators.append({"id":incubator.get("item_id", -1), "used":False}) + + if "pokemon_data" in inv_data: + pokemon = inv_data.get("pokemon_data", {}) + if pokemon.get("is_egg", False): + eggs.append({"id": pokemon.get("id", -1), "km": pokemon.get("egg_km_walked_target", -1), "used": False}) + + sorting = self.config.longer_eggs_first + eggs.sort(key=lambda x: x.get("km"), reverse=sorting) + + for incubator in incubators: + if incubator["used"]: + continue + + for egg in eggs: + if egg["used"]: + continue + + self.api.use_item_egg_incubator(item_inc=incubator["id"], pokemon_id=egg["id"]) + ret = self.api.call() + if ret: + code = ret.get("responses", {}).get("USE_ITEM_EGG_INCUBATOR", {}).get("result", 0) + if code == 1: + egg["used"] = True + incubator["used"] = True + elif code == 5 or code == 7: + incubator["used"] = True + break + elif code == 6: + egg["used"] = True + elif code == 2: + logger.log('Successfully incubated a ' + str(egg["km"]) + "km egg", 'green') From e3f7d9e7f5343829c0ae8ff2419c8313dfe39c2d Mon Sep 17 00:00:00 2001 From: Tobias Stumm Date: Thu, 28 Jul 2016 15:22:14 +0200 Subject: [PATCH 02/13] Added options to configuration --- configs/config.json.example | 2 ++ configs/config.json.pokemons.example | 2 ++ 2 files changed, 4 insertions(+) diff --git a/configs/config.json.example b/configs/config.json.example index fe6d995900..41c0a78d23 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -28,6 +28,8 @@ "evolve_speed": 20, "cp_min": 300, "use_lucky_egg": false, + "hatch_eggs": true, + "longer_eggs_first": true, "evolve_captured": false, "release_pokemon": true, "catch": { diff --git a/configs/config.json.pokemons.example b/configs/config.json.pokemons.example index 55e1be1472..5d91fb5534 100644 --- a/configs/config.json.pokemons.example +++ b/configs/config.json.pokemons.example @@ -28,6 +28,8 @@ "evolve_all": "NONE", "evolve_speed": 20, "use_lucky_egg": false, + "hatch_eggs": true, + "longer_eggs_first": true, "evolve_captured": false, "release_pokemon": true, "catch": { From 50f8e972b18986bc1989163f59f12fb31f6cf3aa Mon Sep 17 00:00:00 2001 From: Tobias Stumm Date: Thu, 28 Jul 2016 15:50:30 +0200 Subject: [PATCH 03/13] Bugfix --- pokemongo_bot/cell_workers/incubate_eggs_worker.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/pokemongo_bot/cell_workers/incubate_eggs_worker.py b/pokemongo_bot/cell_workers/incubate_eggs_worker.py index c81173d5a4..a43d2f1bdc 100644 --- a/pokemongo_bot/cell_workers/incubate_eggs_worker.py +++ b/pokemongo_bot/cell_workers/incubate_eggs_worker.py @@ -31,11 +31,12 @@ def work(self): if "egg_incubators" in inv_data: for incubator in inv_data.get("egg_incubators", {}).get("egg_incubator", []): - incubators.append({"id":incubator.get("item_id", -1), "used":False}) + if "start_km_walked" not in incubator: + incubators.append({"id":incubator.get("id", -1), "used":False}) if "pokemon_data" in inv_data: pokemon = inv_data.get("pokemon_data", {}) - if pokemon.get("is_egg", False): + if pokemon.get("is_egg", False) and "egg_km_walked_target" in pokemon: eggs.append({"id": pokemon.get("id", -1), "km": pokemon.get("egg_km_walked_target", -1), "used": False}) sorting = self.config.longer_eggs_first @@ -46,20 +47,21 @@ def work(self): continue for egg in eggs: - if egg["used"]: + if egg["used"] or egg["km"] == -1: continue - self.api.use_item_egg_incubator(item_inc=incubator["id"], pokemon_id=egg["id"]) + self.api.use_item_egg_incubator(item_id=incubator["id"], pokemon_id=egg["id"]) ret = self.api.call() if ret: code = ret.get("responses", {}).get("USE_ITEM_EGG_INCUBATOR", {}).get("result", 0) if code == 1: + logger.log('Successfully incubated a ' + str(egg["km"]) + "km egg", 'green') egg["used"] = True incubator["used"] = True + break elif code == 5 or code == 7: incubator["used"] = True break elif code == 6: egg["used"] = True - elif code == 2: - logger.log('Successfully incubated a ' + str(egg["km"]) + "km egg", 'green') + From 06dac53271c49ad03c6e0b7c53727d5431aaac39 Mon Sep 17 00:00:00 2001 From: Tobias Stumm Date: Thu, 28 Jul 2016 15:52:40 +0200 Subject: [PATCH 04/13] Ignoring used eggs and incubators --- pokemongo_bot/cell_workers/incubate_eggs_worker.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pokemongo_bot/cell_workers/incubate_eggs_worker.py b/pokemongo_bot/cell_workers/incubate_eggs_worker.py index a43d2f1bdc..933228686a 100644 --- a/pokemongo_bot/cell_workers/incubate_eggs_worker.py +++ b/pokemongo_bot/cell_workers/incubate_eggs_worker.py @@ -31,12 +31,12 @@ def work(self): if "egg_incubators" in inv_data: for incubator in inv_data.get("egg_incubators", {}).get("egg_incubator", []): - if "start_km_walked" not in incubator: + if "pokemon_id" not in incubator: incubators.append({"id":incubator.get("id", -1), "used":False}) if "pokemon_data" in inv_data: pokemon = inv_data.get("pokemon_data", {}) - if pokemon.get("is_egg", False) and "egg_km_walked_target" in pokemon: + if pokemon.get("is_egg", False) and "egg_incubator_id" not in pokemon: eggs.append({"id": pokemon.get("id", -1), "km": pokemon.get("egg_km_walked_target", -1), "used": False}) sorting = self.config.longer_eggs_first From f03d781a4bf081e0ba606875c3f500b938f7cde7 Mon Sep 17 00:00:00 2001 From: Tobias Stumm Date: Thu, 28 Jul 2016 16:04:08 +0200 Subject: [PATCH 05/13] Using cached inventory instead of getting a fresh copy --- pokemongo_bot/cell_workers/incubate_eggs_worker.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pokemongo_bot/cell_workers/incubate_eggs_worker.py b/pokemongo_bot/cell_workers/incubate_eggs_worker.py index 933228686a..44370b3cb6 100644 --- a/pokemongo_bot/cell_workers/incubate_eggs_worker.py +++ b/pokemongo_bot/cell_workers/incubate_eggs_worker.py @@ -14,8 +14,7 @@ def work(self): if not self.config.hatch_eggs: return - self.api.get_inventory() - response_dict = self.api.call() + response_dict = self.bot.get_inventory() inv = {} incubators = [] eggs = [] From cbf89bd0bddffce911ee959e76a1890975c46e2d Mon Sep 17 00:00:00 2001 From: Tobias Stumm Date: Mon, 1 Aug 2016 10:13:40 +0200 Subject: [PATCH 06/13] Lowered the stepsize in Spiral navigator to more accurate 70m --- pokemongo_bot/cell_workers/follow_spiral.py | 29 +++++++++++++++------ 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/pokemongo_bot/cell_workers/follow_spiral.py b/pokemongo_bot/cell_workers/follow_spiral.py index a77363403d..2ab4698cae 100644 --- a/pokemongo_bot/cell_workers/follow_spiral.py +++ b/pokemongo_bot/cell_workers/follow_spiral.py @@ -1,24 +1,28 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import, unicode_literals + +import math + import pokemongo_bot.logger as logger from pokemongo_bot.cell_workers.utils import distance, format_dist from pokemongo_bot.step_walker import StepWalker from pokemongo_bot.cell_workers.base_task import BaseTask - class FollowSpiral(BaseTask): def initialize(self): self.steplimit = self.bot.config.max_steps self.origin_lat = self.bot.position[0] self.origin_lon = self.bot.position[1] + self.diameter_to_steps = (self.steplimit+1) ** 2 self.points = self._generate_spiral( - self.origin_lat, self.origin_lon, 0.0018, self.steplimit + self.origin_lat, self.origin_lon, 70, self.diameter_to_steps ) self.ptr = 0 self.direction = 1 self.cnt = 0 + @staticmethod def _generate_spiral(starting_lat, starting_lng, step_size, step_limit): """ @@ -34,18 +38,24 @@ def _generate_spiral(starting_lat, starting_lng, step_size, step_limit): coords = [{'lat': starting_lat, 'lng': starting_lng}] steps, x, y, d, m = 1, 0, 0, 1, 1 + rlat = starting_lat * math.pi + latdeg = 111132.93 - 559.82 * math.cos(2*rlat) + 1.175*math.cos(4*rlat) + lngdeg = 111412.84 * math.cos(rlat) - 93.5 * math.cos(3*rlat) + step_size_lat = step_size / latdeg + step_size_lng = step_size / lngdeg + while steps < step_limit: while 2 * x * d < m and steps < step_limit: x = x + d steps += 1 - lat = x * step_size + starting_lat - lng = y * step_size + starting_lng + lat = x * step_size_lat + starting_lat + lng = y * step_size_lng + starting_lng coords.append({'lat': lat, 'lng': lng}) while 2 * y * d < m and steps < step_limit: y = y + d steps += 1 - lat = x * step_size + starting_lat - lng = y * step_size + starting_lng + lat = x * step_size_lat + starting_lat + lng = y * step_size_lng + starting_lng coords.append({'lat': lat, 'lng': lng}) d *= -1 @@ -88,9 +98,12 @@ def work(self): point['lat'], point['lng'] ) <= 1 or (self.bot.config.walk > 0 and step_walker == None): - if self.ptr + self.direction == len(self.points) or self.ptr + self.direction == -1: + if self.ptr + self.direction >= len(self.points) or self.ptr + self.direction <= -1: self.direction *= -1 - self.ptr += self.direction + if len(self.points != 1): + self.ptr += self.direction + else: + self.ptr = 0 self.cnt = 0 return [point['lat'], point['lng']] From fea92bc876d638bdfe7b45b1d36fe9996a25e760 Mon Sep 17 00:00:00 2001 From: Tobias Stumm Date: Mon, 1 Aug 2016 10:23:00 +0200 Subject: [PATCH 07/13] Moved max_steps to task configuration and changed it to diameter --- pokemongo_bot/cell_workers/follow_spiral.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pokemongo_bot/cell_workers/follow_spiral.py b/pokemongo_bot/cell_workers/follow_spiral.py index 2ab4698cae..d0df652716 100644 --- a/pokemongo_bot/cell_workers/follow_spiral.py +++ b/pokemongo_bot/cell_workers/follow_spiral.py @@ -10,7 +10,7 @@ class FollowSpiral(BaseTask): def initialize(self): - self.steplimit = self.bot.config.max_steps + self.steplimit = self.config.get("diameter", 3) self.origin_lat = self.bot.position[0] self.origin_lon = self.bot.position[1] @@ -18,6 +18,7 @@ def initialize(self): self.points = self._generate_spiral( self.origin_lat, self.origin_lon, 70, self.diameter_to_steps ) + self.ptr = 0 self.direction = 1 self.cnt = 0 From 0cb10f4fdcc869c386fae2adba64a4fadb90bfc8 Mon Sep 17 00:00:00 2001 From: Tobias Stumm Date: Mon, 1 Aug 2016 10:26:02 +0200 Subject: [PATCH 08/13] Added diameter to configuration example --- configs/config.json.example | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/configs/config.json.example b/configs/config.json.example index ccc06aa190..2a1939df0e 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -43,10 +43,12 @@ "type": "MoveToFort" }, { - "type": "FollowSpiral" + "type": "FollowSpiral", + "config": { + "diameter": 4 + } } ], - "max_steps": 5, "forts": { "avoid_circles": true, "max_circle_size": 50 From 1c8416e3a4d6c7f88d9f8c0fc84581638585e951 Mon Sep 17 00:00:00 2001 From: Tobias Stumm Date: Mon, 1 Aug 2016 10:45:39 +0200 Subject: [PATCH 09/13] Bugfix --- pokemongo_bot/cell_workers/follow_spiral.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pokemongo_bot/cell_workers/follow_spiral.py b/pokemongo_bot/cell_workers/follow_spiral.py index d0df652716..fb177ade48 100644 --- a/pokemongo_bot/cell_workers/follow_spiral.py +++ b/pokemongo_bot/cell_workers/follow_spiral.py @@ -101,7 +101,7 @@ def work(self): ) <= 1 or (self.bot.config.walk > 0 and step_walker == None): if self.ptr + self.direction >= len(self.points) or self.ptr + self.direction <= -1: self.direction *= -1 - if len(self.points != 1): + if len(self.points) != 1: self.ptr += self.direction else: self.ptr = 0 From 4d55cd90c258f6ff35923fd869080a24d0dc6070 Mon Sep 17 00:00:00 2001 From: Tobias Stumm Date: Tue, 2 Aug 2016 09:14:55 +0200 Subject: [PATCH 10/13] Removed max_steps from cli --- pokecli.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/pokecli.py b/pokecli.py index d37bc16313..12afb627aa 100755 --- a/pokecli.py +++ b/pokecli.py @@ -225,16 +225,6 @@ def init_config(): type=str, default=None ) - add_config( - parser, - load, - short_flag="-ms", - long_flag="--max_steps", - help= - "Set the steps around your initial location(DEFAULT 5 mean 25 cells around your location)", - type=int, - default=50 - ) add_config( parser, From 6168a7d2ed7a2a321396e32156b74d5dffbb1857 Mon Sep 17 00:00:00 2001 From: Tobias Stumm Date: Tue, 2 Aug 2016 09:16:58 +0200 Subject: [PATCH 11/13] Added max_steps as legacy configuration --- pokecli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pokecli.py b/pokecli.py index 12afb627aa..e0c982f5e3 100755 --- a/pokecli.py +++ b/pokecli.py @@ -357,7 +357,7 @@ def task_configuration_error(flag_name): """.format(flag_name)) old_flags = ['mode', 'catch_pokemon', 'spin_forts', 'forts_spin', 'hatch_eggs', 'release_pokemon', 'softban_fix', - 'longer_eggs_first', 'evolve_speed', 'use_lucky_egg', 'item_filter', 'evolve_all', 'evolve_cp_min'] + 'longer_eggs_first', 'evolve_speed', 'use_lucky_egg', 'item_filter', 'evolve_all', 'evolve_cp_min', 'max_steps'] for flag in old_flags: if flag in load: task_configuration_error(flag) From 49b4e953ae59d93c8988774c7d1850acc2cd7890 Mon Sep 17 00:00:00 2001 From: Tobias Stumm Date: Tue, 2 Aug 2016 09:23:34 +0200 Subject: [PATCH 12/13] Made step size of follow_spiral more configureable --- configs/config.json.example | 3 ++- pokemongo_bot/cell_workers/follow_spiral.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/configs/config.json.example b/configs/config.json.example index b4e63149b8..5fe25d3291 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -61,7 +61,8 @@ { "type": "FollowSpiral", "config": { - "diameter": 4 + "diameter": 4, + "step_size": 70 } } ], diff --git a/pokemongo_bot/cell_workers/follow_spiral.py b/pokemongo_bot/cell_workers/follow_spiral.py index fb177ade48..65ed59d1e2 100644 --- a/pokemongo_bot/cell_workers/follow_spiral.py +++ b/pokemongo_bot/cell_workers/follow_spiral.py @@ -11,12 +11,13 @@ class FollowSpiral(BaseTask): def initialize(self): self.steplimit = self.config.get("diameter", 3) + self.step_size = self.config.get("step_size", 70) self.origin_lat = self.bot.position[0] self.origin_lon = self.bot.position[1] self.diameter_to_steps = (self.steplimit+1) ** 2 self.points = self._generate_spiral( - self.origin_lat, self.origin_lon, 70, self.diameter_to_steps + self.origin_lat, self.origin_lon, self.step_size, self.diameter_to_steps ) self.ptr = 0 From dfc1fe6ffeee716e5c674e9d0d1419680dbaefc5 Mon Sep 17 00:00:00 2001 From: Tobias Stumm Date: Tue, 2 Aug 2016 09:27:04 +0200 Subject: [PATCH 13/13] Changed default value for diameter --- pokemongo_bot/cell_workers/follow_spiral.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pokemongo_bot/cell_workers/follow_spiral.py b/pokemongo_bot/cell_workers/follow_spiral.py index 65ed59d1e2..bda348490a 100644 --- a/pokemongo_bot/cell_workers/follow_spiral.py +++ b/pokemongo_bot/cell_workers/follow_spiral.py @@ -10,7 +10,7 @@ class FollowSpiral(BaseTask): def initialize(self): - self.steplimit = self.config.get("diameter", 3) + self.steplimit = self.config.get("diameter", 4) self.step_size = self.config.get("step_size", 70) self.origin_lat = self.bot.position[0] self.origin_lon = self.bot.position[1]