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

KeyError: 'individual_attack' #958

Merged
merged 1 commit into from
Jul 26, 2016
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,12 @@ configs/*
!configs/config.json.example
!configs/release_config.json.example
!configs/config.json.pokemons.example
config.json
release_config.json

# Virtualenv folders
bin/
include/

#Pip check file
pip-selfcheck.json
pip-selfcheck.json
51 changes: 28 additions & 23 deletions pokemongo_bot/cell_workers/pokemon_catch_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,14 @@ def work(self):
if 'pokemon_data' in pokemon and 'cp' in pokemon['pokemon_data']:
cp = pokemon['pokemon_data']['cp']
iv_stats = ['individual_attack', 'individual_defense', 'individual_stamina']
individual_attack = 0

individual_attack = pokemon['pokemon_data'].get("individual_attack", 0)
individual_stamina = pokemon['pokemon_data'].get("individual_stamina", 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is good.


iv_display = '{}/{}/{}'.format(
pokemon['pokemon_data']['individual_stamina'],
pokemon['pokemon_data']['individual_attack'],
individual_stamina,
individual_attack,
pokemon['pokemon_data']['individual_defense']
)

Expand All @@ -79,55 +84,55 @@ def work(self):
if not self.should_capture_pokemon(pokemon_name, cp, pokemon_potential, response_dict):
#logger.log('[x] Rule prevents capture.')
return False

balls_stock = self.bot.pokeball_inventory()
while(True):

## pick the most simple ball from stock
pokeball = 1 # start from 1 - PokeBalls

current_type = pokeball
while(balls_stock[current_type] is 0 and current_type < 3): # if this type's stock = 0 and not top tier yet
current_type = current_type + 1 # progress to next tier
if balls_stock[current_type] > 0: # next tier's stock > 0
pokeball = current_type

## re-check stock again
if balls_stock[pokeball] is 0:
logger.log('Out of pokeballs, switching to farming mode...', 'red')
# Begin searching for pokestops.
self.config.mode = 'farm'
return PokemonCatchWorker.NO_POKEBALLS

## Use berry to increase success chance.
berry_id = 701 # @ TODO: use better berries if possible
berries_count = self.bot.item_inventory_count(berry_id)
if(catch_rate[pokeball-1] < 0.5 and berries_count > 0): # and berry is in stock
success_percentage = '{0:.2f}'.format(catch_rate[pokeball-1]*100)
logger.log('Catch Rate with normal Pokeball is low ({}%). Throwing {}... ({} left!)'.format(success_percentage,self.item_list[str(berry_id)],berries_count-1))

if balls_stock[pokeball] is 0:
break

self.api.use_item_capture(
item_id=berry_id,
encounter_id = encounter_id,
item_id=berry_id,
encounter_id = encounter_id,
spawn_point_guid = spawnpoint_id
)
response_dict = self.api.call()
if response_dict and response_dict['status_code'] is 1 and 'item_capture_mult' in response_dict['responses']['USE_ITEM_CAPTURE']:

for i in range(len(catch_rate)):
catch_rate[i] = catch_rate[i] * response_dict['responses']['USE_ITEM_CAPTURE']['item_capture_mult']

success_percentage = '{0:.2f}'.format(catch_rate[pokeball-1]*100)
logger.log('Catch Rate with normal Pokeball has increased to {}%'.format(success_percentage))
else:
if response_dict['status_code'] is 1:
logger.log('Fail to use berry. Seem like you are softbanned.','red')
else:
logger.log('Fail to use berry. Status Code: {}'.format(response_dict['status_code']),'red')

## change ball to next tier if catch rate is too low
current_type = pokeball
while(current_type < 3):
Expand All @@ -137,12 +142,12 @@ def work(self):
pokeball = current_type # use better ball

# @TODO, use the best ball in stock to catch VIP (Very Important Pokemon: Configurable)

balls_stock[pokeball] = balls_stock[pokeball] - 1
success_percentage = '{0:.2f}'.format(catch_rate[pokeball-1]*100)
logger.log('Using {} (chance: {}%)... ({} left!)'.format(
self.item_list[str(pokeball)],
success_percentage,
self.item_list[str(pokeball)],
success_percentage,
balls_stock[pokeball]
))

Expand Down Expand Up @@ -171,15 +176,15 @@ def work(self):
logger.log(
'Oh no! {} vanished! :('.format(pokemon_name), 'red')
if status is 1:

id_list2 = self.count_pokemon_inventory()

logger.log('Captured {}! [CP {}] [{}]'.format(
pokemon_name,
pokemon_name,
cp,
iv_display
), 'blue')

if self.config.evolve_captured:
pokemon_to_transfer = list(Set(id_list2) - Set(id_list1))
self.api.evolve_pokemon(pokemon_id=pokemon_to_transfer[0])
Expand Down Expand Up @@ -276,7 +281,7 @@ def should_capture_pokemon(self, pokemon_name, cp, iv, response_dict):
'cp': False,
'iv': False,
}

if catch_config.get('never_catch', False):
return False

Expand Down Expand Up @@ -323,7 +328,7 @@ def should_release_pokemon(self, pokemon_name, cp, iv, response_dict):
'cp': False,
'iv': False,
}

if release_config.get('never_release', False):
return False

Expand Down