Skip to content

Commit

Permalink
Merge pull request #2 from PokemonGoF/dev
Browse files Browse the repository at this point in the history
update
  • Loading branch information
Surceis authored Jul 27, 2016
2 parents 182047e + 72b1218 commit 202a9a5
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 103 deletions.
18 changes: 9 additions & 9 deletions pokecli.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,21 +257,21 @@ def main():
metrics = bot.metrics
metrics.capture_stats()
logger.log('')
logger.log('Ran for {}'.format(metrics.runtime()), 'red')
logger.log('Total XP Earned: {} Average: {:.2f}/h'.format(metrics.xp_earned, metrics.xp_per_hour()), 'red')
logger.log('Travelled {:.2f}km'.format(metrics.distance_travelled()), 'red')
logger.log('Visited {} stops'.format(metrics.visits['latest'] - metrics.visits['start']), 'red')
logger.log('Ran for {}'.format(metrics.runtime()), 'cyan')
logger.log('Total XP Earned: {} Average: {:.2f}/h'.format(metrics.xp_earned(), metrics.xp_per_hour()), 'cyan')
logger.log('Travelled {:.2f}km'.format(metrics.distance_travelled()), 'cyan')
logger.log('Visited {} stops'.format(metrics.visits['latest'] - metrics.visits['start']), 'cyan')
logger.log('Encountered {} pokemon, {} caught, {} released, {} evolved, {} never seen before'
.format(metrics.num_encounters(), metrics.num_captures(), metrics.releases,
metrics.num_evolutions(), metrics.num_new_mons()), 'red')
metrics.num_evolutions(), metrics.num_new_mons()), 'cyan')
logger.log('Threw {} pokeball{}'.format(metrics.num_throws(), '' if metrics.num_throws() == 1 else 's'),
'red')
logger.log('Earned {} Stardust'.format(metrics.earned_dust()), 'red')
'cyan')
logger.log('Earned {} Stardust'.format(metrics.earned_dust()), 'cyan')
logger.log('')
if metrics.highest_cp is not None:
logger.log('Highest CP Pokemon: {}'.format(metrics.highest_cp['desc']), 'red')
logger.log('Highest CP Pokemon: {}'.format(metrics.highest_cp['desc']), 'cyan')
if metrics.most_perfect is not None:
logger.log('Most Perfect Pokemon: {}'.format(metrics.most_perfect['desc']), 'red')
logger.log('Most Perfect Pokemon: {}'.format(metrics.most_perfect['desc']), 'cyan')


except NotLoggedInException:
Expand Down
76 changes: 24 additions & 52 deletions pokemongo_bot/cell_workers/pokemon_catch_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,33 @@ def __init__(self, pokemon, bot):
self.pokemon_list = bot.pokemon_list
self.item_list = bot.item_list
self.inventory = bot.inventory
self.spawn_point_guid = ''
self.response_key = ''
self.response_status_key = ''

def work(self):

encounter_id = self.pokemon['encounter_id']

response_dict = self.create_encounter_api_call()
spawnpoint_id = self.pokemon['spawnpoint_id']
player_latitude = self.pokemon['latitude']
player_longitude = self.pokemon['longitude']
self.api.encounter(encounter_id=encounter_id, spawnpoint_id=spawnpoint_id,
player_latitude=player_latitude, player_longitude=player_longitude)
response_dict = self.api.call()

if response_dict and 'responses' in response_dict:
if self.response_key in response_dict['responses']:
if self.response_status_key in response_dict['responses'][self.response_key]:
if response_dict['responses'][self.response_key][self.response_status_key] is 7:
if 'ENCOUNTER' in response_dict['responses']:
if 'status' in response_dict['responses']['ENCOUNTER']:
if response_dict['responses']['ENCOUNTER']['status'] is 7:
if self.config.initial_transfer:
logger.log('Pokemon Bag is full!', 'red')
return PokemonCatchWorker.BAG_FULL
else:
raise RuntimeError('Pokemon Bag is full!')

if response_dict['responses'][self.response_key][self.response_status_key] is 1:
if response_dict['responses']['ENCOUNTER']['status'] is 1:
cp = 0
total_IV = 0
if 'wild_pokemon' in response_dict['responses'][self.response_key] or 'pokemon_data' in \
response_dict['responses'][self.response_key]:
if self.response_key == 'ENCOUNTER':
pokemon = response_dict['responses'][self.response_key]['wild_pokemon']
else:
pokemon = response_dict['responses'][self.response_key]

catch_rate = response_dict['responses'][self.response_key]['capture_probability'][
'capture_probability'] # 0 = pokeballs, 1 great balls, 3 ultra balls
if 'wild_pokemon' in response_dict['responses']['ENCOUNTER']:
pokemon = response_dict['responses']['ENCOUNTER']['wild_pokemon']
catch_rate = response_dict['responses']['ENCOUNTER']['capture_probability']['capture_probability'] # 0 = pokeballs, 1 great balls, 3 ultra balls

if 'pokemon_data' in pokemon and 'cp' in pokemon['pokemon_data']:
cp = pokemon['pokemon_data']['cp']

Expand Down Expand Up @@ -96,13 +91,13 @@ def work(self):
sleep(3)

if not self.should_capture_pokemon(pokemon_name, cp, pokemon_potential, response_dict):
# logger.log('[x] Rule prevents capture.')
#logger.log('[x] Rule prevents capture.')
return False

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

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

current_type = pokeball
Expand All @@ -111,14 +106,14 @@ def work(self):
if balls_stock[current_type] > 0: # next tier's stock > 0
pokeball = current_type

# re-check stock again
## 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.
## 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
Expand All @@ -130,8 +125,8 @@ def work(self):

self.api.use_item_capture(
item_id=berry_id,
encounter_id=encounter_id,
spawn_point_guid=self.spawn_point_guid
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']:
Expand All @@ -147,7 +142,7 @@ def work(self):
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
## change ball to next tier if catch rate is too low
current_type = pokeball
while(current_type < 3):
current_type = current_type+1
Expand All @@ -169,7 +164,7 @@ def work(self):
self.api.catch_pokemon(encounter_id=encounter_id,
pokeball=pokeball,
normalized_reticle_size=1.950,
spawn_point_guid=self.spawn_point_guid,
spawn_point_guid=spawnpoint_id,
hit_pokemon=1,
spin_modifier=1,
NormalizedHitPosition=1)
Expand Down Expand Up @@ -221,8 +216,8 @@ def work(self):
if len(pokemon_to_transfer) == 0:
raise RuntimeError(
'Trying to transfer 0 pokemons!')
self.transfer_pokemon(
pokemon_to_transfer[0])
self.transfer_pokemon(pokemon_to_transfer[0])
self.bot.metrics.released_pokemon()
logger.log(
'{} has been exchanged for candy!'.format(pokemon_name), 'green')

Expand Down Expand Up @@ -383,26 +378,3 @@ def _get_release_config_for(self, pokemon):
if not release_config:
release_config = {}
return release_config

def create_encounter_api_call(self):

encounter_id = self.pokemon['encounter_id']
player_latitude = self.pokemon['latitude']
player_longitude = self.pokemon['longitude']

if 'spawnpoint_id' in self.pokemon:
spawnpoint_id = self.pokemon['spawnpoint_id']
self.spawn_point_guid = spawnpoint_id
self.response_key = 'ENCOUNTER'
self.response_status_key = 'status'
self.api.encounter(encounter_id=encounter_id, spawn_point_id=spawnpoint_id,
player_latitude=player_latitude, player_longitude=player_longitude)
else:
fort_id = self.pokemon['fort_id']
self.spawn_point_guid = fort_id
self.response_key = 'DISK_ENCOUNTER'
self. response_status_key = 'result'
self.api.disk_encounter(encounter_id=encounter_id, fort_id=fort_id,
player_latitude=player_latitude, player_longitude=player_longitude)

return self.api.call()
38 changes: 2 additions & 36 deletions pokemongo_bot/cell_workers/seen_fort_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from pokemongo_bot import logger
from pokemongo_bot.human_behaviour import sleep
from pokemongo_bot.cell_workers import PokemonCatchWorker
from utils import format_time


Expand All @@ -17,11 +16,7 @@ def __init__(self, fort, bot):
self.bot = bot
self.position = bot.position
self.config = bot.config
self.pokemon_list = bot.pokemon_list
self.item_list = bot.item_list
self.inventory = bot.inventory
self.pokeball_inventory = bot.pokeball_inventory
self.item_inventory_count = bot.item_inventory_count
self.rest_time = 50

def work(self):
Expand All @@ -39,28 +34,9 @@ def work(self):
fort_name = fort_details['name'].encode('utf8', 'replace')
else:
fort_name = 'Unknown'
logger.log('Now at Pokestop: ' + fort_name,
logger.log('Now at Pokestop: ' + fort_name + ' - Spinning...',
'cyan')
if self.config.mode != 'farm' and 'lure_info' in self.fort:
# Check if the lure has a pokemon active
if 'encounter_id' in self.fort['lure_info']:
logger.log("Found a lure on this pokestop! Catching pokemon...", 'cyan')

pokemon = {
'encounter_id': self.fort['lure_info']['encounter_id'],
'fort_id': self.fort['id'],
'latitude': self.fort['latitude'],
'longitude': self.fort['longitude']
}

self.catch_pokemon(pokemon)

else:
logger.log('Found a lure, but there is no pokemon present.', 'yellow')
sleep(2)

logger.log('Spinning ...', 'cyan')

sleep(2)
self.api.fort_search(fort_id=self.fort['id'],
fort_latitude=lat,
fort_longitude=lng,
Expand Down Expand Up @@ -168,16 +144,6 @@ def work(self):
sleep(8)
return 0

def catch_pokemon(self, pokemon):
worker = PokemonCatchWorker(pokemon, self)
return_value = worker.work()

if return_value == PokemonCatchWorker.BAG_FULL:
worker = InitialTransferWorker(self)
worker.work()

return return_value

@staticmethod
def closest_fort(current_lat, current_long, forts):
print x
11 changes: 5 additions & 6 deletions pokemongo_bot/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Metrics(object):

def __init__(self, bot):
self.bot = bot
self.start_time = None
self.start_time = time.time()
self.dust = {'start': None, 'latest': None}
self.xp = {'start': None, 'latest': None}
self.distance = {'start': None, 'latest': None}
Expand All @@ -23,13 +23,13 @@ def __init__(self, bot):
self.most_perfect = {'potential': 0, 'desc': ''}

def runtime(self):
return str(timedelta(seconds=round(time.time() - self.start_time)))
return timedelta(seconds=round(time.time() - self.start_time))

def xp_earned(self):
return self.xp['latest'] - self.xp['start']

def xp_per_hour(self):
return self.xp_earned/(time.time() - self.start_time/60/60)
return self.xp_earned()/(time.time() - self.start_time)*3600

def distance_travelled(self):
return self.distance['latest'] - self.distance['start']
Expand Down Expand Up @@ -63,15 +63,14 @@ def captured_pokemon(self, name, cp, iv_display, potential):

if potential > self.most_perfect['potential']:
self.most_perfect = \
{'potential': cp, 'desc': '{} [CP: {}] [IV: {}] Potential: {} '
{'potential': potential, 'desc': '{} [CP: {}] [IV: {}] Potential: {} '
.format(name, cp, iv_display, potential)}
return

def released_pokemon(self, count=1):
self.releases += count

def capture_stats(self):
if self.start_time is None: self.start_time = time.time()
self.bot.api.get_inventory()
self.bot.api.get_player()
response_dict = self.bot.api.call()
Expand Down Expand Up @@ -111,4 +110,4 @@ def capture_stats(self):
if self.evolutions['start'] is None: self.evolutions['start'] = self.evolutions['latest']
except KeyError:
# Nothing we can do if there's no player info.
return
return

0 comments on commit 202a9a5

Please sign in to comment.