Skip to content

Commit

Permalink
Merge pull request #6162 from davidakachaos/dev
Browse files Browse the repository at this point in the history
Added only_catch_better_iv and only_catch_better_cp
  • Loading branch information
Jcolomar authored Aug 9, 2017
2 parents fa7d41f + 1770805 commit 55e910a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
13 changes: 13 additions & 0 deletions docs/configuration_files.md
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,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

0 comments on commit 55e910a

Please sign in to comment.