Skip to content

Commit

Permalink
Merge branch 'dev' into map_synergy
Browse files Browse the repository at this point in the history
* dev:
  Re-enable item ID's in the item_filter. (PokemonGoF#1986)
  Adding a task base class (PokemonGoF#1983)
  Supporting task level configuration (PokemonGoF#1979)
  Removing config for forts.move_to_spin
  Removing config for forts.spin
  Removing config for softban_fix
  One more for release_pokemon
  Removing config for release_pokemon
  • Loading branch information
mhdasding committed Jul 31, 2016
2 parents b74b8fe + dc2fa60 commit cf5528b
Show file tree
Hide file tree
Showing 21 changed files with 125 additions and 78 deletions.
9 changes: 4 additions & 5 deletions configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
"type": "HandleSoftBan"
},
{
"type": "IncubateEggs"
"type": "IncubateEggs",
"config": {
"longer_eggs_first": true
}
},
{
"type": "TransferPokemon"
Expand Down Expand Up @@ -41,8 +44,6 @@
],
"max_steps": 5,
"forts": {
"spin": true,
"move_to_spin": true,
"avoid_circles": true,
"max_circle_size": 50
},
Expand Down Expand Up @@ -80,9 +81,7 @@
"evolve_speed": 20,
"evolve_cp_min": 300,
"use_lucky_egg": false,
"longer_eggs_first": true,
"evolve_captured": "NONE",
"release_pokemon": true,
"catch_randomize_reticle_factor": 1.0,
"catch_randomize_spin_factor": 1.0,
"catch": {
Expand Down
9 changes: 4 additions & 5 deletions configs/config.json.path.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
"type": "HandleSoftBan"
},
{
"type": "IncubateEggs"
"type": "IncubateEggs",
"config": {
"longer_eggs_first": true
}
},
{
"type": "TransferPokemon"
Expand Down Expand Up @@ -38,8 +41,6 @@
],
"max_steps": 5,
"forts": {
"spin": true,
"move_to_spin": false,
"avoid_circles": true,
"max_circle_size": 50
},
Expand Down Expand Up @@ -70,9 +71,7 @@
"evolve_speed": 20,
"evolve_cp_min": 300,
"use_lucky_egg": false,
"longer_eggs_first": true,
"evolve_captured": "NONE",
"release_pokemon": true,
"catch_randomize_reticle_factor": 1.0,
"catch_randomize_spin_factor": 1.0,
"catch": {
Expand Down
9 changes: 4 additions & 5 deletions configs/config.json.pokemon.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
"type": "HandleSoftBan"
},
{
"type": "IncubateEggs"
"type": "IncubateEggs",
"config": {
"longer_eggs_first": true
}
},
{
"type": "TransferPokemon"
Expand Down Expand Up @@ -38,8 +41,6 @@
],
"max_steps": 5,
"forts": {
"spin": true,
"move_to_spin": true,
"avoid_circles": true,
"max_circle_size": 50
},
Expand Down Expand Up @@ -67,9 +68,7 @@
"evolve_speed": 20,
"evolve_cp_min": 300,
"use_lucky_egg": false,
"longer_eggs_first": true,
"evolve_captured": "NONE",
"release_pokemon": true,
"catch_randomize_reticle_factor": 1.0,
"catch_randomize_spin_factor": 1.0,
"catch": {
Expand Down
51 changes: 15 additions & 36 deletions pokecli.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,15 +246,6 @@ def init_config():
default=None
)

add_config(
parser,
load,
short_flag="-rp",
long_flag="--release_pokemon",
help="Allow transfer pokemon to professor based on release configuration. Default is false",
type=bool,
default=False
)
add_config(
parser,
load,
Expand Down Expand Up @@ -327,15 +318,6 @@ def init_config():
type=float,
default=15.0
)
add_config(
parser,
load,
short_flag="-bf",
long_flag="--softban_fix",
help="Fix softban automatically",
type=bool,
default=False
)
add_config(
parser,
load,
Expand Down Expand Up @@ -363,15 +345,6 @@ def init_config():
type=int,
default=10,
)
add_config(
parser,
load,
short_flag="-mts",
long_flag="--forts.move_to_spin",
help="Moves to forts nearby ",
type=bool,
default=True
)
add_config(
parser,
load,
Expand Down Expand Up @@ -444,8 +417,6 @@ def init_config():

config.raw_tasks = load.get('tasks', [])

config.longer_eggs_first = load.get("longer_eggs_first", True)

config.vips = load.get('vips', {})
config.map_priority = load.get('map', {}).get('priority', {})

Expand All @@ -464,12 +435,19 @@ def task_configuration_error(flag_name):
Read https://github.com/PokemonGoF/PokemonGo-Bot/wiki/Configuration-files#configuring-tasks for more information.
""".format(flag_name))

old_flags = ['mode', 'catch_pokemon', 'spin_forts', 'forts_spin', 'hatch_eggs']
old_flags = ['mode', 'catch_pokemon', 'spin_forts', 'forts_spin', 'hatch_eggs', 'release_pokemon', 'softban_fix',
'longer_eggs_first']
for flag in old_flags:
if flag in load:
task_configuration_error(flag)
return None

nested_old_flags = [('forts', 'spin'), ('forts', 'move_to_spin')]
for outer, inner in nested_old_flags:
if load.get(outer, {}).get(inner, None):
task_configuration_error('{}.{}'.format(outer, inner))
return None

if (config.evolve_captured
and (not isinstance(config.evolve_captured, str)
or str(config.evolve_captured).lower() in ["true", "false"])):
Expand All @@ -489,12 +467,13 @@ def task_configuration_error(flag_name):
parser.error("--catch_randomize_spin_factor is out of range! (should be 0 <= catch_randomize_spin_factor <= 1)")
return None

# item list config verification
item_list = json.load(open(os.path.join('data', 'items.json')))
for config_item_name, bag_count in config.item_filter.iteritems():
if config_item_name not in item_list.viewvalues():
parser.error('item "' + config_item_name + '" does not exist, spelling mistake? (check for valid item names in data/items.json)')
return None
# item list config verification
item_list = json.load(open(os.path.join('data', 'items.json')))
for config_item_name, bag_count in config.item_filter.iteritems():
if config_item_name not in item_list.viewvalues():
if config_item_name not in item_list:
parser.error('item "' + config_item_name + '" does not exist, spelling mistake? (check for valid item names in data/items.json)')
return None

# create web dir if not exists
try:
Expand Down
1 change: 1 addition & 0 deletions pokemongo_bot/cell_workers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
from handle_soft_ban import HandleSoftBan
from follow_path import FollowPath
from follow_spiral import FollowSpiral
from base_task import BaseTask
14 changes: 14 additions & 0 deletions pokemongo_bot/cell_workers/base_task.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class BaseTask(object):
def __init__(self, bot, config):
self.bot = bot
self.config = config
self._validate_work_exists()
self.initialize()

def _validate_work_exists(self):
method = getattr(self, 'work', None)
if not method or not callable(method):
raise NotImplementedError('Missing "work" method')

def initialize(self):
pass
2 changes: 1 addition & 1 deletion pokemongo_bot/cell_workers/catch_lured_pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


class CatchLuredPokemon(object):
def __init__(self, bot):
def __init__(self, bot, config):
self.bot = bot

def work(self):
Expand Down
2 changes: 1 addition & 1 deletion pokemongo_bot/cell_workers/catch_visible_pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


class CatchVisiblePokemon(object):
def __init__(self, bot):
def __init__(self, bot, config):
self.bot = bot

def work(self):
Expand Down
2 changes: 1 addition & 1 deletion pokemongo_bot/cell_workers/evolve_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


class EvolveAll(object):
def __init__(self, bot):
def __init__(self, bot, config):
self.api = bot.api
self.bot = bot

Expand Down
2 changes: 1 addition & 1 deletion pokemongo_bot/cell_workers/follow_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

class FollowPath(object):

def __init__(self, bot):
def __init__(self, bot, config):
self.bot = bot
self.ptr = 0
self.points = self.load_path()
Expand Down
2 changes: 1 addition & 1 deletion pokemongo_bot/cell_workers/follow_spiral.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


class FollowSpiral(object):
def __init__(self, bot):
def __init__(self, bot, config):
self.bot = bot

self.steplimit = self.bot.config.max_steps
Expand Down
4 changes: 2 additions & 2 deletions pokemongo_bot/cell_workers/handle_soft_ban.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class HandleSoftBan(object):

def __init__(self, bot):
def __init__(self, bot, config):
self.bot = bot

def work(self):
Expand Down Expand Up @@ -56,4 +56,4 @@ def spin_fort(self, fort):
self.bot.api.call()

def should_run(self):
return self.bot.config.softban_fix and self.bot.softban
return self.bot.softban
10 changes: 8 additions & 2 deletions pokemongo_bot/cell_workers/incubate_eggs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,21 @@
class IncubateEggs(object):
last_km_walked = 0

def __init__(self, bot):
def __init__(self, bot, config):
self.bot = bot
self.config = config
self.ready_incubators = []
self.used_incubators = []
self.eggs = []
self.km_walked = 0
self.hatching_animation_delay = 4.20
self.max_iv = 45.0

self._process_config()

def _process_config(self):
self.longer_eggs_first = self.config.get("longer_eggs_first", True)

def work(self):
try:
self._check_inventory()
Expand All @@ -29,7 +35,7 @@ def work(self):
logger.log('[x] Next egg incubates in {:.2f} km'.format(km_left),'yellow')
IncubateEggs.last_km_walked = self.km_walked

sorting = self.bot.config.longer_eggs_first
sorting = self.longer_eggs_first
self.eggs.sort(key=lambda x: x.get("km"), reverse=sorting)

if self.ready_incubators:
Expand Down
5 changes: 2 additions & 3 deletions pokemongo_bot/cell_workers/move_to_fort.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@

class MoveToFort(object):

def __init__(self, bot):
def __init__(self, bot, config):
self.bot = bot

def should_run(self):
return (self.bot.config.forts_move_to_spin and \
self.bot.has_space_for_loot()) or self.bot.softban
return (self.bot.has_space_for_loot()) or self.bot.softban

def work(self):
if not self.should_run():
Expand Down
4 changes: 0 additions & 4 deletions pokemongo_bot/cell_workers/pokemon_catch_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ def work(self):
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 self.config.release_pokemon:
raise RuntimeError('Pokemon Bag is full!')

if response_dict['responses'][self.response_key][self.response_status_key] is 1:
cp = 0
if 'wild_pokemon' in response_dict['responses'][self.response_key] or 'pokemon_data' in \
Expand Down
8 changes: 6 additions & 2 deletions pokemongo_bot/cell_workers/recycle_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class RecycleItems(object):

def __init__(self, bot):
def __init__(self, bot, config):
self.bot = bot

def work(self):
Expand All @@ -15,9 +15,13 @@ def work(self):
id_filter = self.bot.config.item_filter.get(item_name, 0)
if id_filter is not 0:
id_filter_keep = id_filter.get('keep', 20)
else:
id_filter = self.bot.config.item_filter.get(str(item_id), 0)
if id_filter is not 0:
id_filter_keep = id_filter.get('keep', 20)

bag_count = self.bot.item_inventory_count(item_id)
if item_name in self.bot.config.item_filter and bag_count > id_filter_keep:
if (item_name in self.bot.config.item_filter or str(item_id) in self.bot.config.item_filter) and bag_count > id_filter_keep:
items_recycle_count = bag_count - id_filter_keep
response_dict_recycle = self.send_recycle_item_request(item_id=item_id, count=items_recycle_count)
result = response_dict_recycle.get('responses', {}).get('RECYCLE_INVENTORY_ITEM', {}).get('result', 0)
Expand Down
2 changes: 1 addition & 1 deletion pokemongo_bot/cell_workers/spin_fort.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


class SpinFort(object):
def __init__(self, bot):
def __init__(self, bot, config):
self.bot = bot

def should_run(self):
Expand Down
5 changes: 1 addition & 4 deletions pokemongo_bot/cell_workers/transfer_pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@

class TransferPokemon(object):

def __init__(self, bot):
def __init__(self, bot, config):
self.bot = bot

def work(self):
if not self.bot.config.release_pokemon:
return

pokemon_groups = self._release_pokemon_get_groups()
for pokemon_id in pokemon_groups:
group = pokemon_groups[pokemon_id]
Expand Down
Loading

0 comments on commit cf5528b

Please sign in to comment.