Skip to content

Commit

Permalink
Disable follow path if hunter has a Pokemon locked
Browse files Browse the repository at this point in the history
As requested in #6030
  • Loading branch information
davidakachaos committed May 2, 2017
1 parent 8e71040 commit 82f3103
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions docs/configuration_files.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 13 additions & 8 deletions pokemongo_bot/cell_workers/follow_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
STATUS_LOITERING = 1
STATUS_WANDERING = 2
STATUS_FINISHED = 3

class FollowPath(BaseTask):
SUPPORTED_TASK_API_VERSION = 1

Expand All @@ -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)')
Expand Down Expand Up @@ -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']
Expand All @@ -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}.",
Expand All @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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"]))
Expand Down Expand Up @@ -226,6 +231,6 @@ def work(self):
self.endLaps()
else:
self.ptr += 1

self.status = STATUS_MOVING
return WorkerResult.RUNNING

0 comments on commit 82f3103

Please sign in to comment.