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

Added only_catch_better_iv and only_catch_better_cp #6162

Merged
merged 3 commits into from
Aug 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
13 changes: 13 additions & 0 deletions docs/configuration_files.md
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,19 @@ For example:
```
will stop catching Pidgey entirely.

You can set a rule to only catch better IV or CP Pokemon by setting the only_catch_better_cp or only_catch_better_iv flags.


For example:
```
"Pidgey": {
"only_catch_better_iv": true
},
"Gloom": {
"only_catch_better_cp": true
}
```

## Release Configuration
[[back to top](#table-of-contents)]

Expand Down
30 changes: 30 additions & 0 deletions pokemongo_bot/cell_workers/pokemon_catch_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ def _pokemon_matches_config(self, config, pokemon, default_logic='and'):

catch_logic = pokemon_config.get('logic', default_logic)

current_owned = [p for p in inventory.pokemons().all() if p.name == pokemon.name]
candies = inventory.candies().get(pokemon.pokemon_id).quantity
threshold = pokemon_config.get('candy_threshold', -1)
if threshold > 0 and candies >= threshold: # Got enough candies
Expand All @@ -312,6 +313,35 @@ def _pokemon_matches_config(self, config, pokemon, default_logic='and'):
if pokemon_config.get('always_catch', False):
return True

if pokemon_config.get('only_catch_better_cp', False):
# If we don't have the Pokemon, this always returns true
if len(current_owned) == 0:
return True
# Catch only if better CP
current_owned.sort(key=lambda p: p.cp)
if pokemon.cp > current_owned[0].cp:
return True
else:
return False

if pokemon_config.get('only_catch_better_iv', False):
# If we don't have the Pokemon, this always returns true
if len(current_owned) == 0:
return True
# Catch only if better CP
current_owned.sort(key=lambda p: p.iv)
if current_owned[0].iv == 1:
# Already have a perfect Pokemon, checking CP
if pokemon.cp > current_owned[0].cp:
return True
else:
return False
# Check the IV
if pokemon.iv > current_owned[0].iv:
return True
else:
return False

if pokemon_config.get('catch_above_ncp',-1) >= 0:
if pokemon.cp_percent >= pokemon_config.get('catch_above_ncp'):
catch_results['ncp'] = True
Expand Down