diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index c1b4763c6e..19ad62380a 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -46,4 +46,5 @@ * kbinani * MFizz * NamPNQ + * z4ppy.bbc * matheussampaio diff --git a/configs/config.json.example b/configs/config.json.example index 3ae35099ec..3442c233d9 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -52,7 +52,10 @@ "type": "SpinFort" }, { - "type": "MoveToFort" + "type": "MoveToFort", + "config": { + "lure_attraction": true, + "lure_max_distance": 2000 }, { "type": "FollowSpiral" diff --git a/pokemongo_bot/cell_workers/move_to_fort.py b/pokemongo_bot/cell_workers/move_to_fort.py index dcb4c8d4fd..d5797be603 100644 --- a/pokemongo_bot/cell_workers/move_to_fort.py +++ b/pokemongo_bot/cell_workers/move_to_fort.py @@ -7,12 +7,21 @@ class MoveToFort(BaseTask): + + def initialize(self): + self.lure_distance = 0 + self.lure_attraction = self.config.get("lure_attraction", True) + self.lure_max_distance = self.config.get("lure_max_distance", 2000) + def should_run(self): has_space_for_loot = self.bot.has_space_for_loot() if not has_space_for_loot: logger.log("Not moving to any forts as there aren't enough space. You might want to change your config to recycle more items if this message appears consistently.", 'yellow') return has_space_for_loot or self.bot.softban + def is_attracted(self): + return (self.lure_distance > 0) + def work(self): if not self.should_run(): return WorkerResult.SUCCESS @@ -38,7 +47,12 @@ def work(self): ) if dist > Constants.MAX_DISTANCE_FORT_IS_REACHABLE: - logger.log('Moving towards fort {}, {} left'.format(fort_name, format_dist(dist, unit))) + if self.is_attracted() > 0: + add_str = ' (attraction of lure {})'.format(format_dist(self.lure_distance, unit)) + else: + add_str = '' + + logger.log('Moving towards fort {}, {} left{}'.format(fort_name, format_dist(dist, unit), add_str)) step_walker = StepWalker( self.bot, @@ -53,16 +67,63 @@ def work(self): logger.log('Arrived at pokestop.') return WorkerResult.SUCCESS + def _get_nearest_fort_on_lure_way(self, forts): + + if not self.lure_attraction: + return None, 0 + + lures = filter(lambda x: True if x.get('lure_info', None) != None else False, forts) + + if (len(lures)): + dist_lure_me = distance(self.bot.position[0], self.bot.position[1], + lures[0]['latitude'],lures[0]['longitude']) + else: + dist_lure_me = 0 + + if dist_lure_me > 0 and dist_lure_me < self.lure_max_distance: + + self.lure_distance = dist_lure_me + + for fort in forts: + dist_lure_fort = distance( + fort['latitude'], + fort['longitude'], + lures[0]['latitude'], + lures[0]['longitude']) + dist_fort_me = distance( + fort['latitude'], + fort['longitude'], + self.bot.position[0], + self.bot.position[1]) + + if dist_lure_fort < dist_lure_me and dist_lure_me > dist_fort_me: + return fort, dist_lure_me + + if dist_fort_me > dist_lure_me: + break + + return lures[0], dist_lure_me + + else: + return None, 0 + def get_nearest_fort(self): forts = self.bot.get_forts(order_by_distance=True) # Remove stops that are still on timeout forts = filter(lambda x: x["id"] not in self.bot.fort_timeouts, forts) + next_attracted_pts, lure_distance = self._get_nearest_fort_on_lure_way(forts) + # Remove all forts which were spun in the last ticks to avoid circles if set if self.bot.config.forts_avoid_circles: forts = filter(lambda x: x["id"] not in self.bot.recent_forts, forts) + self.lure_distance = lure_distance + + if (lure_distance > 0): + return next_attracted_pts + if len(forts) > 0: return forts[0] else: