diff --git a/configs/config.json.hunter.example b/configs/config.json.hunter.example index f937ae1c45..fc3205ec95 100644 --- a/configs/config.json.hunter.example +++ b/configs/config.json.hunter.example @@ -7,7 +7,8 @@ "max_distance": 1500, "hunt_all": false, "hunt_vip": true, - "hunt_pokedex": true + "hunt_pokedex": true, + "lock_on_target": false } }, { diff --git a/pokemongo_bot/cell_workers/catch_pokemon.py b/pokemongo_bot/cell_workers/catch_pokemon.py index d7ab841e98..c9f21c448e 100644 --- a/pokemongo_bot/cell_workers/catch_pokemon.py +++ b/pokemongo_bot/cell_workers/catch_pokemon.py @@ -21,6 +21,7 @@ class CatchPokemon(BaseTask): def initialize(self): self.pokemon = [] + self.ignored_while_looking = [] def work(self): # make sure we have SOME balls @@ -50,11 +51,34 @@ def work(self): random.shuffle(self.pokemon) + # Filter out already ignored mons + if self.bot.hunter_locked_target != None: + self.pokemon = filter(lambda x: x["pokemon_id"] not in self.ignored_while_looking, self.pokemon) + elif len(self.ignored_while_looking) > 0: + self.logger.info("No longer hunting for a Pokémon, resuming normal operations.") + # Reset the ignored list when no longer needed. + self.ignored_while_looking = [] + num_pokemon = len(self.pokemon) if num_pokemon > 0: # try catching + mon_to_catch = self.pokemon.pop() + + if self.bot.hunter_locked_target != None: + bounty = self.bot.hunter_locked_target + mon_name = Pokemons.name_for(mon_to_catch['pokemon_id']) + bounty_name = Pokemons.name_for(bounty['pokemon_id']) + if mon_to_catch['encounter_id'] != bounty['encounter_id']: + # This is not the Pokémon you are looking for... + self.logger.info("[Hunter locked a {}] Ignoring a {}".format(bounty_name, mon_name)) + self.ignored_while_looking.append(mon_to_catch['pokemon_id']) + if num_pokemon > 1: + return WorkerResult.RUNNING + else: + return WorkerResult.SUCCESS + try: - if self.catch_pokemon(self.pokemon.pop()) == WorkerResult.ERROR: + if self.catch_pokemon(mon_to_catch) == WorkerResult.ERROR: # give up incase something went wrong in our catch worker (ran out of balls, etc) return WorkerResult.ERROR elif num_pokemon > 1: diff --git a/pokemongo_bot/cell_workers/pokemon_hunter.py b/pokemongo_bot/cell_workers/pokemon_hunter.py index 010149cfb0..4b60c0d9fe 100644 --- a/pokemongo_bot/cell_workers/pokemon_hunter.py +++ b/pokemongo_bot/cell_workers/pokemon_hunter.py @@ -32,6 +32,9 @@ def initialize(self): self.config_hunt_all = self.config.get("hunt_all", False) self.config_hunt_vip = self.config.get("hunt_vip", True) self.config_hunt_pokedex = self.config.get("hunt_pokedex", True) + # Lock on Target; ignore all other Pokémon until we found our target. + self.config_lock_on_target = self.config.get("lock_on_target", False) + self.bot.hunter_locked_target = None def work(self): if not self.enabled: @@ -63,6 +66,8 @@ def work(self): self.logger.info("New destination at %(distance).2f meters: %(name)s", self.destination) self.no_log_until = now + 60 + if self.config_lock_on_target: + self.bot.hunter_locked_target = self.destination if self.destination["s2_cell_id"] != self.search_cell_id: self.search_points = self.get_search_points(self.destination["s2_cell_id"]) @@ -87,6 +92,8 @@ def work(self): self.lost_counter = 0 if self.lost_counter >= 3: + self.logger.info("I haven't found %(name)s", self.destination) + self.bot.hunter_locked_target = None self.destination = None else: self.logger.info("Now searching for %(name)s", self.destination) @@ -96,6 +103,8 @@ def work(self): elif self.no_log_until < now: distance = great_circle(self.bot.position, (self.walker.dest_lat, self.walker.dest_lng)).meters self.logger.info("Moving to destination at %s meters: %s", round(distance, 2), self.destination["name"]) + if self.config_lock_on_target: + self.bot.hunter_locked_target = self.destination self.no_log_until = now + 30 return WorkerResult.RUNNING