Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pokemonhunter changes #6073

Merged
merged 2 commits into from
Jul 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/configuration_files.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ The behaviors of the bot are configured via the `tasks` key in the `config.json`
[[back to top](#table-of-contents)]
* CatchPokemon
* `enabled`: Default "true" | Enable/Disable the task.
* `always_catch_family_of_vip`: Default "false" | Always catch family members of a VIP, even if locked on a target.
* `always_catch_trash`: Default "false" | Always catch trash Pokemon (12 candy evolve), even if locked on a target.
* `treat_unseen_as_vip`: Default `"true"` | If true, treat new to dex as VIP
* `catch_visible_pokemon`: Default "true" | If enabled, attempts to catch "visible" pokemon that are reachable
* `catch_lured_pokemon`: Default "true" | If enabled, attempts to catch "lured" pokemon that are reachable
Expand Down Expand Up @@ -1421,6 +1423,11 @@ Hunts down nearby Pokemon. Searches for Pokemon to complete the Pokedex, or if a
* `treat_family_of_vip_as_vip`: `Default: false`. Should we see family of an VIP as a VIP (locking onto it if enabled)
* `hunt_for_trash_to_fill_bag`: `Default: false`. Should we try to fill the bag with trash if a set amount of slots is left?
* `trash_hunt_open_slots`: `Default: 25`. The amount of slots for the previous setting
* `run_to_vip`: `Default: false`. Run to a VIP Pokemon? Running sets the speed of the walker to the walk_max value!

### Hunting family members of VIPs
If enabled (`target_family_of_vip` = true), the hunter will also hunt down family members of a VIP. For example, if you marked Gyarados as a VIP Pokemon then the hunter will now also hunt down Magikarps.
When on the hunt for a family member of a VIP, and `treat_family_of_vip_as_vip` is false, the hunter will keep a look out for "real" VIPs. So when hunting for a Magikarp, if a Snorlax shows up in the sightings, the hunter will target the Snorlax.

### Hunting for trash
If enabled the hunter will start hunting down Pidgeys, Weedles and Caterpies when a set amount of slots (defaults to 25) are left in the bag to fill. The idea is simple; we are about to start evolving Pokemon. So the priority of the hunter shiftes. BUT when a VIP Pokemon is nearby, the Hunter will always start chasing that VIP first.
Expand Down
7 changes: 7 additions & 0 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,13 @@ def _register_events(self):
'longitude'
)
)
self.event_manager.register_event(
'moving_to_hunter_target',
parameters=(
'target_name',
'distance'
)
)
self.event_manager.register_event(
'moving_to_fort',
parameters=(
Expand Down
76 changes: 55 additions & 21 deletions pokemongo_bot/cell_workers/catch_pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,36 +71,54 @@ def work(self):

if hasattr(self.bot, "skipped_pokemon"):
# Skip pokemon the catcher told us to ignore
self.pokemon = [ p for p in self.pokemon if p not in self.bot.skipped_pokemon ]
self.pokemon = [p for p in self.pokemon if p not in self.bot.skipped_pokemon]

num_pokemon = len(self.pokemon)
always_catch_family_of_vip = self.config.get('always_catch_family_of_vip', False)
always_catch_trash = self.config.get('always_catch_trash', False)
trash_pokemon = ["Caterpie", "Weedle", "Pidgey", "Pidgeotto", "Pidgeot", "Kakuna", "Beedrill", "Metapod", "Butterfree"]

if num_pokemon > 0:
# try catching
mon_to_catch = self.pokemon.pop()
is_vip = hasattr(mon_to_catch, "pokemon_id") and self._is_vip_pokemon(mon_to_catch['pokemon_id'])
is_vip = self._is_vip_pokemon(mon_to_catch) # hasattr(mon_to_catch, "pokemon_id") and self._is_vip_pokemon(mon_to_catch['pokemon_id'])
# Always catch VIP Pokemons!
if hasattr(self.bot,"hunter_locked_target") and 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_name != bounty_name and is_vip == False:
# 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
else:
# We have found a vip or our target...
if bounty_name == mon_name:
self.bot.hunter_locked_target = None
self.logger.info("Found my target {}!".format(bounty_name))
family_catch = False
trash_catch = False

if always_catch_trash:
if mon_name in trash_pokemon:
self.logger.info("While on the hunt for {}, I found a {}! I want that Pokemon! Will try to catch...".format(bounty_name, mon_name))
trash_catch = True

if always_catch_family_of_vip:
if mon_name != bounty_name:
if self._is_family_of_vip(mon_to_catch['pokemon_id']):
self.logger.info("While on the hunt for {}, I found a {}! I want that Pokemon! Will try to catch...".format(bounty_name, mon_name))
family_catch = True

if not family_catch and not trash_catch:
if (mon_name != bounty_name and is_vip is False):
# 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
else:
self.logger.info("While on the hunt for {}, I found a {}! I need that Pokemon! Will try to catch...".format(bounty_name, mon_name))
# We have found a vip or our target...
if bounty_name == mon_name:
self.bot.hunter_locked_target = None
self.logger.info("Found my target {}!".format(bounty_name))
else:
self.logger.info("While on the hunt for {}, I found a {}! I want that Pokemon! Will try to catch...".format(bounty_name, mon_name))
try:
if self.catch_pokemon(mon_to_catch) == WorkerResult.ERROR:
# give up incase something went wrong in our catch worker (ran out of balls, etc)
Expand All @@ -114,15 +132,23 @@ def work(self):
# all pokemon have been processed
return WorkerResult.SUCCESS

def _is_vip_pokemon(self, pokemon_id):
def _is_vip_pokemon(self, pokemon):
if 'pokemon_id' not in pokemon:
if not 'name' in pokemon:
return False
pokemon['pokemon_id'] = Pokemons.id_for(pokemon['name'])
# having just a name present in the list makes them vip
# Not seen pokemons also will become vip if it's not disabled in config
if self.bot.config.vips.get(Pokemons.name_for(pokemon_id)) == {}:
if self.bot.config.vips.get(Pokemons.name_for(pokemon['pokemon_id'])) == {}:
return True
if (not inventory.pokedex().seen(pokemon_id)):
if (not inventory.pokedex().seen(pokemon['pokemon_id'])):
return True
# If we must treat family of VIP as VIP
if self.config.get('treat_family_of_vip_as_vip', False):
if self._is_family_of_vip(pokemon['pokemon_id']):
return True
# If we need the Pokemon for an evolution, catch it.
if any(not inventory.pokedex().seen(fid) for fid in self.get_family_ids(pokemon_id)):
if any(not inventory.pokedex().seen(fid) for fid in self.get_family_ids(pokemon['pokemon_id'])):
# self.logger.info('Found a Pokemon whoes family is not yet complete in Pokedex!')
return True

Expand Down Expand Up @@ -267,6 +293,14 @@ def _have_applied_incense(self):
return False
return False

def _is_family_of_vip(self, pokemon_id):
for fid in self.get_family_ids(pokemon_id):
name = inventory.pokemons().name_for(fid)
if self.bot.config.vips.get(name) == {}:
return True
# No, not a family member of the VIP
return False

def get_family_ids(self, pokemon_id):
family_id = inventory.pokemons().data_for(pokemon_id).first_evolution_id
ids = [family_id]
Expand Down
Loading