From 82f31030054f8a434c7feac6070b4cfd1c0890db Mon Sep 17 00:00:00 2001 From: David Westerink Date: Tue, 2 May 2017 15:49:14 +0200 Subject: [PATCH] Disable follow path if hunter has a Pokemon locked As requested in #6030 --- docs/configuration_files.md | 1 + pokemongo_bot/cell_workers/follow_path.py | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/docs/configuration_files.md b/docs/configuration_files.md index 610a7eedb5..2bdc2cfffd 100644 --- a/docs/configuration_files.md +++ b/docs/configuration_files.md @@ -215,6 +215,7 @@ The behaviors of the bot are configured via the `tasks` key in the `config.json` * `use_lucky_egg`: Default: `False` | Only evolve if we can use a lucky egg * FollowPath * `enable`: Disable or enable this task. + * `disable_while_hunting`: Default `true` | Disable walking when Pokemon Hunter has a target locked. * `path_mode`: Default `loop` | Set the mode for the path navigator (loop, linear or single). * `path_file`: Default `NONE` | Set the file containing the waypoints for the path navigator. * FollowSpiral diff --git a/pokemongo_bot/cell_workers/follow_path.py b/pokemongo_bot/cell_workers/follow_path.py index 6b3274c4b4..38fc476354 100644 --- a/pokemongo_bot/cell_workers/follow_path.py +++ b/pokemongo_bot/cell_workers/follow_path.py @@ -21,7 +21,7 @@ STATUS_LOITERING = 1 STATUS_WANDERING = 2 STATUS_FINISHED = 3 - + class FollowPath(BaseTask): SUPPORTED_TASK_API_VERSION = 1 @@ -47,13 +47,14 @@ def _process_config(self): self.timer_restart_min = getSeconds(self.config.get("timer_restart_min", "00:20:00")) self.timer_restart_max = getSeconds(self.config.get("timer_restart_max", "02:00:00")) self.walker = self.config.get('walker', 'StepWalker') + self.disable_while_hunting = self.config.get("disable_while_hunting", True) if self.timer_restart_min > self.timer_restart_max: raise ValueError('path timer_restart_min is bigger than path timer_restart_max') #TODO there must be a more elegant way to do it... - + #var not related to configs self.number_lap = 0 - + def load_path(self): if self.path_file is None: raise RuntimeError('You need to specify a path file (json or gpx)') @@ -103,7 +104,7 @@ def load_gpx(self): def find_closest_point_idx(self, points): return_idx = 0 min_distance = float("inf"); - + for index in range(len(points)): point = points[index] lat = point['lat'] @@ -125,7 +126,7 @@ def find_closest_point_idx(self, points): def endLaps(self): duration = int(uniform(self.timer_restart_min, self.timer_restart_max)) resume = dt.now() + timedelta(seconds=duration) - + self.emit_event( 'path_lap_end', formatted="Great job, lot of calories burned! Taking a break now for {duration}, will resume at {resume}.", @@ -134,7 +135,7 @@ def endLaps(self): 'resume': resume.strftime("%H:%M:%S") } ) - + self.number_lap = 0 # at the end of the break, start again sleep(duration) self.bot.login() @@ -144,6 +145,10 @@ def work(self): if self.status == STATUS_FINISHED: return WorkerResult.SUCCESS + if self.disable_while_hunting and hasattr(self.bot,"hunter_locked_target"): + if self.bot.hunter_locked_target != None: + return WorkerResult.SUCCESS + if time.time() < self.waiting_end_time: if self.status == STATUS_WANDERING: return WorkerResult.SUCCESS @@ -193,7 +198,7 @@ def work(self): 'distance_unit': self.distance_unit } ) - + if (self.bot.config.walk_min > 0 and is_at_destination) or (self.status in [STATUS_WANDERING, STATUS_LOITERING] and time.time() >= self.waiting_end_time): if "loiter" in point and self.status != STATUS_LOITERING: self.logger.info("Loitering for {} seconds...".format(point["loiter"])) @@ -226,6 +231,6 @@ def work(self): self.endLaps() else: self.ptr += 1 - + self.status = STATUS_MOVING return WorkerResult.RUNNING