Skip to content
This repository has been archived by the owner on Oct 2, 2021. It is now read-only.

Commit

Permalink
Added catching of Pokemon from incense
Browse files Browse the repository at this point in the history
Added documentation and new function
Solving issue PokemonGoF#5151 - part 1
  • Loading branch information
davidakachaos committed Sep 4, 2016
1 parent 8265d16 commit c361f58
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 3 deletions.
1 change: 1 addition & 0 deletions configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@
"enabled": true,
"catch_visible_pokemon": true,
"catch_lured_pokemon": true,
"catch_incensed_pokemon": true,
"min_ultraball_to_keep": 5,
"berry_threshold": 0.35,
"vip_berry_threshold": 0.9,
Expand Down
3 changes: 2 additions & 1 deletion docs/configuration_files.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ The behaviors of the bot are configured via the `tasks` key in the `config.json`
* `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
* `catch_incensed_pokemon`: Default "true" | If enabled, attempts to catch pokemon that are found because of an active incense
* `min_ultraball_to_keep`: Default 5 | Minimum amount of reserved ultraballs to have on hand (for VIP)
* `berry_threshold`: Default 0.35 | Catch percentage we start throwing berries
* `vip_berry_threshold`: Default 0.9 | Something similar?
Expand Down Expand Up @@ -1062,4 +1063,4 @@ Available `team` :
"team": 2
}
}
```
```
10 changes: 10 additions & 0 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,16 @@ def _register_events(self):
'pokemon_name'
)
)
self.event_manager.register_event(

This comment has been minimized.

Copy link
@askovpen

askovpen Sep 4, 2016

incensed_pokemon_found?

This comment has been minimized.

Copy link
@davidakachaos

davidakachaos Sep 5, 2016

Author Owner

👍 Yes

'lured_pokemon_found',
parameters=(
'pokemon_id',
'spawn_point_id',
'encounter_id',
'latitude',
'longitude'
)
)
self.event_manager.register_event(
'pokemon_appeared',
parameters=(
Expand Down
22 changes: 22 additions & 0 deletions pokemongo_bot/cell_workers/catch_pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ def work(self):
self.get_visible_pokemon()
if self.config.get('catch_lured_pokemon', True):
self.get_lured_pokemon()
if self.config.get('catch_incensed_pokemon', True):
self.get_incensed_pokemon()

random.shuffle(self.pokemon)

Expand Down Expand Up @@ -129,6 +131,26 @@ def get_lured_pokemon(self):

self.add_pokemon(pokemon)

def get_incensed_pokemon(self):
# call self.bot.api.get_incense_pokemon
pokemon_to_catch = self.bot.api.get_incense_pokemon

if len(pokemon_to_catch) > 0:
for pokemon in pokemon_to_catch:

# Update web UI
with open(user_web_catchable, 'w') as outfile:

This comment has been minimized.

Copy link
@LLNet

LLNet Sep 4, 2016

where are "user_web_catchable" defined ?
user_web_catchable = os.path.join(_base_dir, 'web', 'catchable-{}.json'.format(self.bot.config.username))

?

This comment has been minimized.

Copy link
@davidakachaos

davidakachaos Sep 5, 2016

Author Owner

Yes, I removed this, it's not needed to push it out. Incense only works for the player, nobody else.

json.dump(pokemon, outfile)

self.emit_event(
'incensed_pokemon_found',
level='info',
formatted='Incense attracted a pokemon at {encounter_location}',
data=pokemon
)

self.add_pokemon(pokemon)

def add_pokemon(self, pokemon):
if pokemon['encounter_id'] not in self.pokemon:
self.pokemon.append(pokemon)
Expand Down
14 changes: 12 additions & 2 deletions pokemongo_bot/cell_workers/pokemon_catch_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,11 @@ def work(self, response_dict=None):
try:
responses = response_dict['responses']
response = responses[self.response_key]
if response[self.response_status_key] != ENCOUNTER_STATUS_SUCCESS:
if response[self.response_status_key] != ENCOUNTER_STATUS_SUCCESS && response[self.response_status_key] != INCENSE_ENCOUNTER_SUCCESS:
if response[self.response_status_key] == ENCOUNTER_STATUS_NOT_IN_RANGE:
self.emit_event('pokemon_not_in_range', formatted='Pokemon went out of range!')
elif response[self.response_status_key] == INCENSE_ENCOUNTER_NOT_AVAILABLE:
self.emit_event('pokemon_not_in_range', formatted='Incensed Pokemon went out of range!')
elif response[self.response_status_key] == ENCOUNTER_STATUS_POKEMON_INVENTORY_FULL:
self.emit_event('pokemon_inventory_full', formatted='Your Pokemon inventory is full! Could not catch!')
return WorkerResult.ERROR
Expand Down Expand Up @@ -204,7 +206,7 @@ def create_encounter_api_call(self):
player_latitude=player_latitude,
player_longitude=player_longitude
)
else:
elif 'fort_id' in self.pokemon:
fort_id = self.pokemon['fort_id']
self.spawn_point_guid = fort_id
self.response_key = 'DISK_ENCOUNTER'
Expand All @@ -215,6 +217,14 @@ def create_encounter_api_call(self):
player_latitude=player_latitude,
player_longitude=player_longitude
)
else
# This must be a incensed mon
self.response_key = 'INCENSE_ENCOUNTER'
self.response_status_key = 'result'
request.incense_encounter(
encounter_id=encounter_id,
encounter_location=self.pokemon['encounter_location']
)
return request.call()

############################################################################
Expand Down

0 comments on commit c361f58

Please sign in to comment.