Skip to content

Commit

Permalink
Merge branch 'dev' into map_synergy
Browse files Browse the repository at this point in the history
* dev:
  Refactor (PokemonGoF#1587)
  Move follow path task config (PokemonGoF#2044)
  Avoid transferring favorite pokemons (PokemonGoF#2038)
  Removing unused navigator switch
  Fixing bug in evolve all. Fixes PokemonGoF#2019
  Moving use_lucky_egg to be a task configuration
  Moving evolve_speed to task configuration
  • Loading branch information
mhdasding committed Jul 31, 2016
2 parents 29ef124 + a7523a1 commit f63e619
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 138 deletions.
3 changes: 2 additions & 1 deletion CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@
* klingan
* reddivision
* kbinani
* mhdasding
* mhdasding
* NamPNQ
8 changes: 5 additions & 3 deletions configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
"type": "TransferPokemon"
},
{
"type": "EvolveAll"
"type": "EvolveAll",
"config": {
"evolve_speed": 20,
"use_lucky_egg": true
}
},
{
"type": "RecycleItems"
Expand Down Expand Up @@ -87,9 +91,7 @@
"Razz Berry": { "keep" : 100 }
},
"evolve_all": "NONE",
"evolve_speed": 20,
"evolve_cp_min": 300,
"use_lucky_egg": false,
"evolve_captured": "NONE",
"catch_randomize_reticle_factor": 1.0,
"catch_randomize_spin_factor": 1.0,
Expand Down
19 changes: 10 additions & 9 deletions configs/config.json.path.example
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
"type": "TransferPokemon"
},
{
"type": "EvolveAll"
"type": "EvolveAll",
"config": {
"evolve_speed": 20,
"use_lucky_egg": true
}
},
{
"type": "RecycleItems"
Expand All @@ -39,19 +43,18 @@
"type": "MoveToFort"
},
{
"type": "FollowSpiral"
"type": "FollowPath",
"config": {
"path_mode": "loop",
"path_file": "configs/path.example.json"
}
}
],
"max_steps": 5,
"forts": {
"avoid_circles": true,
"max_circle_size": 50
},
"navigator": {
"type": "path",
"path_mode": "loop",
"path_file": "configs/path.example.json"
},
"websocket_server": false,
"walk": 4.16,
"action_wait_min": 1,
Expand All @@ -71,9 +74,7 @@
"701": { "keep" : 100 }
},
"evolve_all": "NONE",
"evolve_speed": 20,
"evolve_cp_min": 300,
"use_lucky_egg": false,
"evolve_captured": "NONE",
"catch_randomize_reticle_factor": 1.0,
"catch_randomize_spin_factor": 1.0,
Expand Down
8 changes: 5 additions & 3 deletions configs/config.json.pokemon.example
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
"type": "TransferPokemon"
},
{
"type": "EvolveAll"
"type": "EvolveAll",
"config": {
"evolve_speed": 20,
"use_lucky_egg": true
}
},
{
"type": "RecycleItems"
Expand Down Expand Up @@ -68,9 +72,7 @@
"701": { "keep" : 100 }
},
"evolve_all": "NONE",
"evolve_speed": 20,
"evolve_cp_min": 300,
"use_lucky_egg": false,
"evolve_captured": "NONE",
"catch_randomize_reticle_factor": 1.0,
"catch_randomize_spin_factor": 1.0,
Expand Down
11 changes: 1 addition & 10 deletions pokecli.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,15 +315,6 @@ def init_config():
type=str,
default=[]
)
add_config(
parser,
load,
short_flag="-le",
long_flag="--use_lucky_egg",
help="Uses lucky egg when using evolve_all",
type=bool,
default=False
)
add_config(
parser,
load,
Expand Down Expand Up @@ -409,7 +400,7 @@ def task_configuration_error(flag_name):
""".format(flag_name))

old_flags = ['mode', 'catch_pokemon', 'spin_forts', 'forts_spin', 'hatch_eggs', 'release_pokemon', 'softban_fix',
'longer_eggs_first']
'longer_eggs_first', 'evolve_speed', 'use_lucky_egg']
for flag in old_flags:
if flag in load:
task_configuration_error(flag)
Expand Down
141 changes: 49 additions & 92 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ def start(self):
self._setup_logging()
self._setup_api()

if self.config.navigator_type == 'spiral':
self.navigator = cell_workers.FollowSpiral
elif self.config.navigator_type == 'path':
self.navigator = cell_workers.FollowPath

random.seed()

def _setup_event_system(self):
Expand Down Expand Up @@ -139,7 +134,7 @@ def update_web_location(self, cells=[], lat=None, lng=None, alt=None):
status = map_objects.get('status', None)
cells = map_objects['map_cells']

#insert detail info about gym to fort
# insert detail info about gym to fort
for cell in cells:
if 'forts' in cell:
for fort in cell['forts']:
Expand All @@ -165,7 +160,7 @@ def update_web_location(self, cells=[], lat=None, lng=None, alt=None):
)
# alt is unused atm but makes using *location easier
try:
with open(user_web_location,'w') as outfile:
with open(user_web_location, 'w') as outfile:
json.dump({
'lat': lat,
'lng': lng,
Expand Down Expand Up @@ -395,25 +390,13 @@ def get_inventory(self):
def update_inventory(self):
response = self.get_inventory()
self.inventory = list()
if 'responses' in response:
if 'GET_INVENTORY' in response['responses']:
if 'inventory_delta' in response['responses']['GET_INVENTORY']:
if 'inventory_items' in response['responses'][
'GET_INVENTORY']['inventory_delta']:
for item in response['responses']['GET_INVENTORY'][
'inventory_delta']['inventory_items']:
if not 'inventory_item_data' in item:
continue
if not 'item' in item['inventory_item_data']:
continue
if not 'item_id' in item['inventory_item_data'][
'item']:
continue
if not 'count' in item['inventory_item_data'][
'item']:
continue
self.inventory.append(item['inventory_item_data'][
'item'])
inventory_items = response.get('responses', {}).get('GET_INVENTORY', {}).get(
'inventory_delta', {}).get('inventory_items', {})
if inventory_items:
for item in inventory_items:
item_info = item.get('inventory_item_data', {}).get('item')
if {"item_id", "count"}.issubset(set(item_info.keys())):
self.inventory.append(item['inventory_item_data']['item'])

def current_inventory(self):
inventory_req = self.get_inventory()
Expand Down Expand Up @@ -458,7 +441,7 @@ def _item_inventory_count_per_id(self, id, inventory_dict):
item_dict = item.get('inventory_item_data', {}).get('item', {})
item_id = item_dict.get('item_id', False)
item_count = item_dict.get('count', False)
if item_id == int(id) and item_count:
if item_id == int(id) and item_count:
return item_count

def _all_items_inventory_count(self, inventory_dict):
Expand Down Expand Up @@ -553,8 +536,7 @@ def get_pos_by_name(self, location_name):
'[x] Coordinates found in passed in location, '
'not geocoding.'
)
return float(possible_coordinates[0]), \
float(possible_coordinates[1]), float("0.0")
return float(possible_coordinates[0]), float(possible_coordinates[1]), float("0.0")

geolocator = GoogleV3(api_key=self.config.gmapkey)
loc = geolocator.geocode(location_name, timeout=10)
Expand All @@ -573,28 +555,16 @@ def heartbeat(self):

def get_inventory_count(self, what):
response_dict = self.get_inventory()
if 'responses' in response_dict:
if 'GET_INVENTORY' in response_dict['responses']:
if 'inventory_delta' in response_dict['responses'][
'GET_INVENTORY']:
if 'inventory_items' in response_dict['responses'][
'GET_INVENTORY']['inventory_delta']:
pokecount = 0
itemcount = 1
for item in response_dict['responses'][
'GET_INVENTORY']['inventory_delta'][
'inventory_items']:
# print('item {}'.format(item))
if 'inventory_item_data' in item:
if 'pokemon_data' in item[
'inventory_item_data']:
pokecount += 1
if 'item' in item['inventory_item_data']:
if 'count' in item['inventory_item_data'][
'item']:
itemcount = itemcount + \
item['inventory_item_data'][
'item']['count']
inventory_items = response_dict.get('responses', {}).get('GET_INVENTORY', {}).get(
'inventory_delta', {}).get('inventory_items', {})
if inventory_items:
pokecount = 0
itemcount = 1
for item in inventory_items:
if 'inventory_item_data' in item:
if 'pokemon_data' in item['inventory_item_data']:
pokecount += 1
itemcount += item['inventory_item_data'].get('item', {}).get('count', 0)
if 'pokemon' in what:
return pokecount
if 'item' in what:
Expand All @@ -603,47 +573,34 @@ def get_inventory_count(self, what):

def get_player_info(self):
response_dict = self.get_inventory()
if 'responses' in response_dict:
if 'GET_INVENTORY' in response_dict['responses']:
if 'inventory_delta' in response_dict['responses'][
'GET_INVENTORY']:
if 'inventory_items' in response_dict['responses'][
'GET_INVENTORY']['inventory_delta']:
pokecount = 0
itemcount = 1
for item in response_dict['responses'][
'GET_INVENTORY']['inventory_delta'][
'inventory_items']:
#print('item {}'.format(item))
if 'inventory_item_data' in item:
if 'player_stats' in item[
'inventory_item_data']:
playerdata = item['inventory_item_data'][
'player_stats']

nextlvlxp = (
int(playerdata.get('next_level_xp', 0)) -
int(playerdata.get('experience', 0)))

if 'level' in playerdata:
if 'experience' in playerdata:
logger.log(
'Level: {level}'.format(
**playerdata) +
' (Next Level: {} XP)'.format(
nextlvlxp) +
' (Total: {experience} XP)'
''.format(**playerdata), 'cyan')

if 'pokemons_captured' in playerdata:
if 'poke_stop_visits' in playerdata:
logger.log(
'Pokemon Captured: '
'{pokemons_captured}'.format(
**playerdata) +
' | Pokestops Visited: '
'{poke_stop_visits}'.format(
**playerdata), 'cyan')
inventory_items = response_dict.get('responses', {}).get('GET_INVENTORY', {}).get(
'inventory_delta', {}).get('inventory_items', {})
if inventory_items:
pokecount = 0
itemcount = 1
for item in inventory_items:
# print('item {}'.format(item))
playerdata = item.get('inventory_item_data', {}).get('player_stats')
if playerdata:
nextlvlxp = (int(playerdata.get('next_level_xp', 0)) - int(playerdata.get('experience', 0)))

if 'level' in playerdata and 'experience' in playerdata:
logger.log(
'Level: {level}'.format(
**playerdata) +
' (Next Level: {} XP)'.format(
nextlvlxp) +
' (Total: {experience} XP)'
''.format(**playerdata), 'cyan')

if 'pokemons_captured' in playerdata and 'poke_stop_visits' in playerdata:
logger.log(
'Pokemon Captured: '
'{pokemons_captured}'.format(
**playerdata) +
' | Pokestops Visited: '
'{poke_stop_visits}'.format(
**playerdata), 'cyan')

def has_space_for_loot(self):
number_of_things_gained_by_stop = 5
Expand Down
19 changes: 10 additions & 9 deletions pokemongo_bot/cell_workers/evolve_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
from pokemongo_bot.cell_workers.base_task import BaseTask

class EvolveAll(BaseTask):
def initialize(self):
self.evolve_speed = self.config.get('evolve_speed', 3.7)
self.use_lucky_egg = self.config.get('use_lucky_egg', False)

def work(self):
if not self._should_run():
return
Expand Down Expand Up @@ -50,7 +54,7 @@ def _should_run(self):
return False

# Evolve all is used - Don't run after the first tick or if the config flag is false
if self.bot.tick_count is not 1 or not self.bot.config.use_lucky_egg:
if self.bot.tick_count is not 1 or not self.use_lucky_egg:
return True

lucky_egg_count = self.bot.item_inventory_count(Item.ITEM_LUCKY_EGG.value)
Expand Down Expand Up @@ -146,18 +150,15 @@ def _execute_pokemon_evolve(self, pokemon, cache):
if pokemon_name in cache:
return

self.api.evolve_pokemon(pokemon_id=pokemon_id)
response_dict = self.api.call()
self.bot.api.evolve_pokemon(pokemon_id=pokemon_id)
response_dict = self.bot.api.call()
status = response_dict['responses']['EVOLVE_POKEMON']['result']
if status == 1:
print('[#] Successfully evolved {} with {} CP and {} IV!'.format(
pokemon_name, pokemon_cp, pokemon_iv
))

if self.bot.config.evolve_speed:
sleep(self.bot.config.evolve_speed)
else:
sleep(3.7)
sleep(self.evolve_speed)

else:
# cache pokemons we can't evolve. Less server calls
Expand All @@ -166,8 +167,8 @@ def _execute_pokemon_evolve(self, pokemon, cache):

# TODO: move to utils. These methods are shared with other workers.
def transfer_pokemon(self, pid):
self.api.release_pokemon(pokemon_id=pid)
response_dict = self.api.call()
self.bot.api.release_pokemon(pokemon_id=pid)
response_dict = self.bot.api.call()

def count_pokemon_inventory(self):
response_dict = self.bot.get_inventory()
Expand Down
Loading

0 comments on commit f63e619

Please sign in to comment.