Skip to content

Commit

Permalink
Poke hunter lockon (#5902)
Browse files Browse the repository at this point in the history
* Lock on target!

* Default to false

* Small fix, reset the lock when not found

* Adjustments when to lock on
  • Loading branch information
davidakachaos authored and solderzzc committed Feb 7, 2017
1 parent 80668cb commit a03ad63
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
3 changes: 2 additions & 1 deletion configs/config.json.hunter.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"max_distance": 1500,
"hunt_all": false,
"hunt_vip": true,
"hunt_pokedex": true
"hunt_pokedex": true,
"lock_on_target": false
}
},
{
Expand Down
26 changes: 25 additions & 1 deletion pokemongo_bot/cell_workers/catch_pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
9 changes: 9 additions & 0 deletions pokemongo_bot/cell_workers/pokemon_hunter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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"])
Expand All @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit a03ad63

Please sign in to comment.