diff --git a/pokecli.py b/pokecli.py index 36d76d04cd..0dd0cb6142 100755 --- a/pokecli.py +++ b/pokecli.py @@ -208,6 +208,17 @@ def init_config(): type=int, default=50 ) + + add_config( + parser, + load, + short_flag="-n", + long_flag="--navigator", + help="Set the navigator to be used(DEFAULT spiral)", + type=str, + default='spiral' + ) + add_config( parser, load, @@ -309,6 +320,7 @@ def init_config(): config.catch = load.get('catch', {}) config.release = load.get('release', {}) config.item_filter = load.get('item_filter', {}) + config.path_navigator = load.get('path_navigator', {}) config.action_wait_max = load.get('action_wait_max', 4) config.action_wait_min = load.get('action_wait_min', 1) diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index 3a2068bf8c..881f65fc5f 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -20,6 +20,7 @@ from item_list import Item from metrics import Metrics from spiral_navigator import SpiralNavigator +from path_navigator import PathNavigator from worker_result import WorkerResult @@ -41,7 +42,12 @@ def __init__(self, config): def start(self): self._setup_logging() self._setup_api() - self.navigator = SpiralNavigator(self) + + if self.config.navigator == 'spiral': + self.navigator = SpiralNavigator(self) + elif self.config.navigator == 'path': + self.navigator = PathNavigator(self) + random.seed() def tick(self): diff --git a/pokemongo_bot/cell_workers/spin_nearest_fort_worker.py b/pokemongo_bot/cell_workers/spin_nearest_fort_worker.py index b241acf830..09d5c96af1 100644 --- a/pokemongo_bot/cell_workers/spin_nearest_fort_worker.py +++ b/pokemongo_bot/cell_workers/spin_nearest_fort_worker.py @@ -20,9 +20,15 @@ def work(self): nearest_fort = self.get_nearest_fort() if nearest_fort: + dist = distance(self.position[0], self.position[1], nearest_fort['latitude'], nearest_fort['longitude']) + # Move to and spin the nearest stop. - if MoveToFortWorker(nearest_fort, self.bot).work() == WorkerResult.RUNNING: + if self.config.navigator != 'path' and MoveToFortWorker(nearest_fort, self.bot).work() == WorkerResult.RUNNING: return WorkerResult.RUNNING + + if (dist > 10): + return WorkerResult.SUCCESS + if SeenFortWorker(nearest_fort, self.bot).work() == WorkerResult.RUNNING: return WorkerResult.RUNNING diff --git a/pokemongo_bot/path_navigator.py b/pokemongo_bot/path_navigator.py new file mode 100644 index 0000000000..75adb91ac8 --- /dev/null +++ b/pokemongo_bot/path_navigator.py @@ -0,0 +1,72 @@ +# -*- coding: utf-8 -*- +import logger +from cell_workers.utils import distance, i2f, format_dist +from human_behaviour import sleep +from step_walker import StepWalker +from pgoapi.utilities import f2i + + +class PathNavigator(object): + def __init__(self, bot): + self.bot = bot + self.api = bot.api + self.config = bot.config + self.ptr = 0 + self.mode = self.get_mode() + + if not self.config.path_navigator: + raise RuntimeError('path_navigator config missing') + + self.points = self.get_points() + + def get_points(self): + if not self.config.path_navigator.has_key('points') or len(self.config.path_navigator['points']) < 2: + raise RuntimeError('You need to specify at least two points in the path_navigator config') + + points = [point.split(',') for point in self.config.path_navigator['points']] + return points + + def get_mode(self): + mode = 'linear' + if self.config.path_navigator.has_key('mode'): + if self.config.path_navigator['mode'] == 'loop': + mode = 'loop' + + return mode + + def take_step(self): + point = self.points[self.ptr] + lat = float(point[0]) + lng = float(point[1]) + + if self.config.walk > 0: + step_walker = StepWalker( + self.bot, + self.config.walk, + lat, + lng + ) + + is_at_destination = False + if step_walker.step(): + is_at_destination = True + + else: + self.api.set_position(point['lat'], point['lng']) + + dist = distance( + self.api._position_lat, + self.api._position_lng, + lat, + lng + ) + + if dist <= 1 or (self.config.walk > 0 and is_at_destination): + if (self.ptr + 1) == len(self.points): + self.ptr = 0 + if self.mode == 'linear': + self.points = list(reversed(self.points)) + else: + self.ptr += 1 + + return [lat, lng] \ No newline at end of file