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

More items info at start #1167

Merged
merged 7 commits into from
Jul 27, 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
3 changes: 2 additions & 1 deletion CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@
* VictorChen
* AlvaroGzP
* fierysolid
* surfaace
* surfaace
* surceis
45 changes: 26 additions & 19 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def _print_character_info(self):

pokecoins = '0'
stardust = '0'
balls_stock = self.pokeball_inventory()
items_stock = self.current_inventory()

if 'amount' in player['currencies'][0]:
pokecoins = player['currencies'][0]['amount']
Expand All @@ -293,14 +293,28 @@ def _print_character_info(self):
logger.log('Pokemon Bag: {}/{}'.format(self.get_inventory_count('pokemon'), player['max_pokemon_storage']), 'cyan')
logger.log('Items: {}/{}'.format(self.get_inventory_count('item'), player['max_item_storage']), 'cyan')
logger.log('Stardust: {}'.format(stardust) + ' | Pokecoins: {}'.format(pokecoins), 'cyan')
# Pokeball Output
logger.log('PokeBalls: ' + str(balls_stock[1]) +
' | GreatBalls: ' + str(balls_stock[2]) +
' | UltraBalls: ' + str(balls_stock[3]), 'cyan')
logger.log('Razz Berries: ' + str(self.item_inventory_count(701)), 'cyan')
# Items Output
logger.log('PokeBalls: ' + str(items_stock[1]) +
' | GreatBalls: ' + str(items_stock[2]) +
' | UltraBalls: ' + str(items_stock[3]), 'cyan')
logger.log('RazzBerries: ' + str(items_stock[701]) +
' | BlukBerries: ' + str(items_stock[702]) +
' | NanabBerries: ' + str(items_stock[703]), 'cyan')
logger.log('LuckyEgg: ' + str(items_stock[301]) +
' | Incubator: ' + str(items_stock[902]) +
' | TroyDisk: ' + str(items_stock[501]), 'cyan')
logger.log('Potion: ' + str(items_stock[101]) +
' | SuperPotion: ' + str(items_stock[102]) +
' | HyperPotion: ' + str(items_stock[103]), 'cyan')
logger.log('Incense: ' + str(items_stock[401]) +
' | IncenseSpicy: ' + str(items_stock[402]) +
' | IncenseCool: ' + str(items_stock[403]), 'cyan')
logger.log('Revive: ' + str(items_stock[201]) +
' | MaxRevive: ' + str(items_stock[202]), 'cyan')

logger.log('')


def use_lucky_egg(self):
self.api.use_item_xp_boost(item_id=301)
inventory_req = self.api.call()
Expand Down Expand Up @@ -330,7 +344,7 @@ def update_inventory(self):
self.inventory.append(item['inventory_item_data'][
'item'])

def pokeball_inventory(self):
def current_inventory(self):
self.api.get_player().get_inventory()

inventory_req = self.api.call()
Expand All @@ -341,28 +355,21 @@ def pokeball_inventory(self):
with open(user_web_inventory, 'w') as outfile:
json.dump(inventory_dict, outfile)

# get player balls stock
# get player items stock
# ----------------------
balls_stock = {1: 0, 2: 0, 3: 0, 4: 0}
items_stock = {x.value:0 for x in list(Item)}

for item in inventory_dict:
try:
# print(item['inventory_item_data']['item'])
item_id = item['inventory_item_data']['item']['item_id']
item_count = item['inventory_item_data']['item']['count']

if item_id == Item.ITEM_POKE_BALL.value:
# print('Poke Ball count: ' + str(item_count))
balls_stock[1] = item_count
if item_id == Item.ITEM_GREAT_BALL.value:
# print('Great Ball count: ' + str(item_count))
balls_stock[2] = item_count
if item_id == Item.ITEM_ULTRA_BALL.value:
# print('Ultra Ball count: ' + str(item_count))
balls_stock[3] = item_count
if item_id in items_stock:
items_stock[item_id] = item_count
except:
continue
return balls_stock
return items_stock

def item_inventory_count(self, id):
self.api.get_player().get_inventory()
Expand Down
16 changes: 8 additions & 8 deletions pokemongo_bot/cell_workers/pokemon_catch_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,20 @@ def work(self):
#logger.log('[x] Rule prevents capture.')
return False

balls_stock = self.bot.pokeball_inventory()
items_stock = self.bot.current_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
while(items_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
if items_stock[current_type] > 0: # next tier's stock > 0
pokeball = current_type

## re-check stock again
if balls_stock[pokeball] is 0:
if items_stock[pokeball] is 0:
logger.log('Out of pokeballs, switching to farming mode...', 'red')
# Begin searching for pokestops.
self.config.mode = 'farm'
Expand All @@ -120,7 +120,7 @@ def work(self):
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:
if items_stock[pokeball] is 0:
break

self.api.use_item_capture(
Expand All @@ -146,18 +146,18 @@ def work(self):
current_type = pokeball
while(current_type < 3):
current_type = current_type+1
if catch_rate[pokeball-1] < 0.35 and balls_stock[current_type] > 0:
if catch_rate[pokeball-1] < 0.35 and items_stock[current_type] > 0:
# if current ball chance to catch is under 35%, and player has better ball - then use it
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
items_stock[pokeball] = items_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,
balls_stock[pokeball]
items_stock[pokeball]
))

id_list1 = self.count_pokemon_inventory()
Expand Down