def __init__(self, parent, inventory_items): self._parent = parent self.inventory_items = inventory_items self._last_egg_use_time = 0 self._log = create_logger( __name__, self._parent.config.log_colors["inventory".upper()]) self.ultra_balls = 0 self.great_balls = 0 self.poke_balls = 0 self.master_balls = 0 self.potion = 0 self.hyper_potion = 0 self.super_potion = 0 self.max_potion = 0 self.lucky_eggs = 0 self.razz_berries = 0 self.pokeball_percent = self._parent.config.ball_priorities[0] / 100.0 self.greatball_percent = self._parent.config.ball_priorities[1] / 100.0 self.ultraball_percent = self._parent.config.ball_priorities[2] / 100.0 self.use_masterball = self._parent.config.ball_priorities[3] self.pokemon_candy = defaultdict() self.eggs_available = [] self.incubators_available = [] self.incubators_busy = [] self.setup_inventory()
def __init__(self, parent): self.parent = parent self.encountered_pokemons = TTLCache( maxsize=120, ttl=self.parent.map_objects.get_api_rate_limit() * 2) self.log = create_logger( __name__, self.parent.config.log_colors["poke_catcher".upper()])
def __init__(self, parent): self.parent = parent self.log = create_logger( __name__, self.parent.config.log_colors["release".upper()]) self.release_method_factory = ReleaseMethodFactory( self.parent.config.config_data)
def __init__(self, parent): self.parent = parent self.log = create_logger(__name__) self._map_objects_rate_limit = 5.0 self._last_got_map_objects = 0 # cache self._objects = {}
def main(): # log settings # log format logging.basicConfig( level=logging.INFO, format='%(asctime)s [%(module)10s] [%(levelname)5s] s%(message)s') # log level for http request class create_logger("requests", log_level=logging.WARNING) # log level for pgoapi class create_logger("pgoapi", log_level=logging.WARNING) # log level for internal pgoapi class create_logger("rpc_api", log_level=logging.INFO) args = init_arguments() if not args: return poketrainer = Poketrainer(args) # auto-start bot poketrainer.start() # because the bot spawns 'threads' so it can start / stop we're making an infinite lop here while True: try: gevent.sleep(1.0) except KeyboardInterrupt: logger.info('Exiting...') exit(0)
def __init__(self, args): self.thread = None self.socket = None self.cli_args = args self.force_debug = args['debug'] # timers, counters and triggers self.pokemon_caught = 0 self._error_counter = 0 self._error_threshold = 10 self.start_time = time() self.exp_start = None self._heartbeat_number = 1 # setting this back to one because we make parse a full heartbeat during login! self._heartbeat_frequency = 3 # 1 = always self._full_heartbeat_frequency = 15 # 10 = as before (every 10th heartbeat) self._farm_mode_triggered = False # objects, order is important! self.config = None self._load_config() self.log = create_logger(__name__, self.config.log_colors["poketrainer".upper()]) self._open_socket() self.player = Player({}) self.player_stats = PlayerStats({}) self.inventory = Inventory(self, []) self.fort_walker = FortWalker(self) self.map_objects = MapObjects(self) self.poke_catcher = PokeCatcher(self) self.incubate = Incubate(self) self.evolve = Evolve(self) self.release = Release(self) self.sniper = Sniper(self) self._origPosF = (0, 0, 0) self.api = None self._load_api() # config values that might be changed during runtime self.step_size = self.config.step_size self.should_catch_pokemon = self.config.should_catch_pokemon # threading / locking self.sem = BoundedSemaphore(1) # gevent self.persist_lock = False self.locker = None
def __init__(self, args): self.thread = None self.socket = None self.cli_args = args self.force_debug = args['debug'] # timers, counters and triggers self.pokemon_caught = 0 self._error_counter = 0 self._error_threshold = 10 self.start_time = time() self.exp_start = None self._heartbeat_number = 1 # setting this back to one because we make parse a full heartbeat during login! self._heartbeat_frequency = 3 # 1 = always self._full_heartbeat_frequency = 15 # 10 = as before (every 10th heartbeat) self._farm_mode_triggered = False # objects, order is important! self.config = None self._load_config() self.log = create_logger(__name__, self.config.log_colors["poketrainer".upper()]) self._open_socket() self.player = Player({}) self.player_stats = PlayerStats({}) self.inventory = Inventory(self, []) self.fort_walker = FortWalker(self) self.map_objects = MapObjects(self) self.poke_catcher = PokeCatcher(self) self.incubate = Incubate(self) self.evolve = Evolve(self) self.release = Release(self) self.sniper = Sniper(self) self._origPosF = (0, 0, 0) self.api = None self._load_api() # config values that might be changed during runtime self.step_size = self.config.step_size self.should_catch_pokemon = self.config.should_catch_pokemon # threading / locking self.sem = BoundedSemaphore(1) # gevent self.persist_lock = False self.locker = None
def __init__(self, parent): self.parent = parent self.visited_forts = TTLCache( maxsize=120, ttl=self.parent.config.skip_visited_fort_duration) self.route = { 'steps': [], 'total_distance': 0 } # route should contain the complete path we're planning to go self.route_only_forts = False self.steps = [] # steps contain all steps to the next route target self.next_step = None self.wander_steps = [] # only set when we want to wander self.total_distance_traveled = 0 self.total_trip_distance = 0 self.base_travel_link = '' self._error_counter = 0 self._error_threshold = 10 self.all_cached_forts = [] self.spinnable_cached_forts = [] self.cache_is_sorted = self.parent.config.cache_is_sorted self.use_cache = self.parent.config.use_cache self.log = create_logger( __name__, self.parent.config.log_colors["fort_walker".upper()])
def __init__(self, parent): self.parent = parent self.encountered_pokemons = TTLCache(maxsize=120, ttl=self.parent.map_objects.get_api_rate_limit() * 2) self.log = create_logger(__name__, self.parent.config.log_colors["poke_catcher".upper()])
def __init__(self, parent): self.parent = parent self.log = create_logger(__name__)
def __init__(self, config, cli_args): self.log = create_logger(__name__) self.__config_data = config self.config_data = config self.__password = self.config_data.pop("password", 'NA') self.location = config["location"] self.auth_service = config["auth_service"] self.username = config["username"] self.gmaps_api_key = config.get("GMAPS_API_KEY", "") self.step_size = config.get("BEHAVIOR", {}).get("STEP_SIZE", 200) self.wander_steps = config.get("BEHAVIOR", {}).get("WANDER_STEPS", 0) self.extra_wait = config.get("BEHAVIOR", {}).get("EXTRA_WAIT", 0.3) self.sleep_mult = config.get("BEHAVIOR", {}).get("SLEEP_MULT", 1.5) self.use_lucky_egg = config.get("BEHAVIOR", {}).get("AUTO_USE_LUCKY_EGG", False) self.use_google = config.get("BEHAVIOR", {}).get("USE_GOOGLE", False) self.skip_visited_fort_duration = config.get("BEHAVIOR", {}).get( "SKIP_VISITED_FORT_DURATION", 600) self.spin_all_forts = config.get("BEHAVIOR", {}).get("SPIN_ALL_FORTS", False) self.stay_within_proximity = config.get("BEHAVIOR", {}).get( "STAY_WITHIN_PROXIMITY", 9999999) # Stay within proximity self.should_catch_pokemon = config.get("CAPTURE", {}).get("CATCH_POKEMON", True) self.max_catch_attempts = config.get("CAPTURE", {}).get("MAX_CATCH_ATTEMPTS", 10) self.min_failed_attempts_before_using_berry = config.get( "CAPTURE", {}).get("MIN_FAILED_ATTEMPTS_BEFORE_USING_BERRY", 3) pokeball_percent = config.get("CAPTURE", {}).get("USE_POKEBALL_IF_PERCENT", 50) greatball_percent = config.get("CAPTURE", {}).get("USE_GREATBALL_IF_PERCENT", 50) ultraball_percent = config.get("CAPTURE", {}).get("USE_ULTRABALL_IF_PERCENT", 50) use_masterball = config.get("CAPTURE", {}).get("USE_MASTERBALL", False) self.only_to_keep = config.get("CAPTURE", {}).get("ONLY_TO_KEEP", False) self.ball_priorities = [ pokeball_percent, greatball_percent, ultraball_percent, use_masterball ] self.min_items = {} for k, v in config.get("MIN_ITEMS", {}).items(): self.min_items[getattr(Item_Enums, k)] = v self.pokemon_evolution = {} self.pokemon_evolution_family = {} for k, v in config.get("POKEMON_EVOLUTION", {}).items(): self.pokemon_evolution[getattr(Enums, k)] = v self.pokemon_evolution_family[getattr(Enums, k)] = getattr( Enums, "FAMILY_" + k) self.experimental = config.get("BEHAVIOR", {}).get("EXPERIMENTAL", False) self.pokemon_cleanup_testing_mode = config.get( 'POKEMON_CLEANUP', {}).get('TESTING_MODE', False) self.min_similar_pokemon = config.get("POKEMON_CLEANUP", {}).get( "MIN_SIMILAR_POKEMON", 1) # Keep atleast one of everything. self.keep_pokemon_ids = map( lambda x: getattr(Enums, x), config.get("POKEMON_CLEANUP", {}).get("KEEP_POKEMON_NAMES", [])) self.release_method = config.get("POKEMON_CLEANUP", {}).get("RELEASE_METHOD", "CLASSIC") self.release_method_conf = config.get("POKEMON_CLEANUP", {}).get( "RELEASE_METHOD_" + self.release_method, {}) self.score_method = config.get("POKEMON_CLEANUP", {}).get("SCORE_METHOD", "CP") self.score_settings = config.get("POKEMON_CLEANUP", {}).get( "SCORE_METHOD_" + self.score_method, {}) self.egg_incubation_enabled = config.get("EGG_INCUBATION", {}).get("ENABLE", True) self.use_disposable_incubators = config.get("EGG_INCUBATION", {}).get( "USE_DISPOSABLE_INCUBATORS", False) self.incubate_big_eggs_first = config.get("EGG_INCUBATION", {}).get( "BIG_EGGS_FIRST", True) self.farm_items_enabled = config.get("NEEDY_ITEM_FARMING", {}).get( "ENABLE", True and self.experimental) # be concious of pokeball/item limits self.pokeball_continue_threshold = config.get( "NEEDY_ITEM_FARMING", {} ).get( "POKEBALL_CONTINUE_THRESHOLD", 50 ) # keep at least 10 pokeballs of any assortment, otherwise go farming self.pokeball_farm_threshold = config.get( "NEEDY_ITEM_FARMING", {}).get("POKEBALL_FARM_THRESHOLD", 10) # at this point, go collect pokeballs self.farm_ignore_pokeball_count = config.get( "NEEDY_ITEM_FARMING", {}).get("FARM_IGNORE_POKEBALL_COUNT", False) # ignore pokeballs in the continue tally self.farm_ignore_greatball_count = config.get( "NEEDY_ITEM_FARMING", {}).get("FARM_IGNORE_GREATBALL_COUNT", False) # ignore greatballs in the continue tally self.farm_ignore_ultraball_count = config.get( "NEEDY_ITEM_FARMING", {}).get("FARM_IGNORE_ULTRABALL_COUNT", False) # ignore ultraballs in the continue tally self.farm_ignore_masterball_count = config.get( "NEEDY_ITEM_FARMING", {}).get("FARM_IGNORE_MASTERBALL_COUNT", True) # ignore masterballs in the continue tally self.farm_override_step_size = config.get( "NEEDY_ITEM_FARMING", {} ).get( "FARM_OVERRIDE_STEP_SIZE", -1 ) # should the step size be overriden when looking for more inventory, -1 to disable self._sanity_check_needy_item_farming() self.explain_evolution_before_cleanup = config.get( "CONSOLE_OUTPUT", {}).get("EXPLAIN_EVOLUTION_BEFORE_CLEANUP", False) # explain individual evolution criteria in console self.list_pokemon_before_cleanup = config.get( "CONSOLE_OUTPUT", {}).get("LIST_POKEMON_BEFORE_CLEANUP", False) # list pokemon in console self.list_inventory_before_cleanup = config.get( "CONSOLE_OUTPUT", {}).get("LIST_INVENTORY_BEFORE_CLEANUP", True) # list inventory in console self.show_steps = config.get("CONSOLE_OUTPUT", {}).get( "SHOW_STEPS", True) # show steps walked in console self.show_travel_link_with_steps = config.get( "CONSOLE_OUTPUT", {}).get("SHOW_TRAVEL_LINK_WITH_STEPS", True) self.show_distance_traveled = config.get("CONSOLE_OUTPUT", {}).get( "SHOW_DISTANCE_TRAVELED", True) self.show_nearest_fort_distance = config.get("CONSOLE_OUTPUT", {}).get( "SHOW_NEAREST_FORT_DISTANCE", True) self.notify_no_nearby_pokemon = config.get("CONSOLE_OUTPUT", {}).get( "NOTIFY_NO_NEARBY_POKEMON", False) self.log_colors = config.get("CONSOLE_OUTPUT", {}).get( "COLORLOG", { "FORT_WALKER": "blue", "POKE_CATCHER": "green", "RELEASE": "cyan", "EVOLVE": "cyan", "POKETRAINER": "yellow", "INVENTORY": "purple" }) if cli_args['location']: start_location = cli_args['location'] else: start_location = self.location self.cache_filename = './cache/cache ' + (hashlib.md5( start_location.encode())).hexdigest() + str( self.stay_within_proximity) self.use_cache = config.get("BEHAVIOR", {}).get("USE_CACHED_FORTS", False) self.cache_is_sorted = config.get("BEHAVIOR", {}).get("CACHED_FORTS_SORTED", False) self.enable_caching = config.get("BEHAVIOR", {}).get("ENABLE_CACHING", False)
def __init__(self, parent): self.parent = parent self.log = create_logger(__name__, self.parent.config.log_colors["release".upper()]) self.release_method_factory = ReleaseMethodFactory(self.parent.config.config_data)
def __init__(self, parent): self.parent = parent self.log = create_logger(__name__)
def __init__(self, config, cli_args): self.log = create_logger(__name__) self.__config_data = config self.config_data = config self.__password = self.config_data.pop("password", 'NA') self.location = config["location"] self.auth_service = config["auth_service"] self.username = config["username"] self.gmaps_api_key = config.get("GMAPS_API_KEY", "") self.step_size = config.get("BEHAVIOR", {}).get("STEP_SIZE", 200) self.wander_steps = config.get("BEHAVIOR", {}).get("WANDER_STEPS", 0) self.extra_wait = config.get("BEHAVIOR", {}).get("EXTRA_WAIT", 0.3) self.sleep_mult = config.get("BEHAVIOR", {}).get("SLEEP_MULT", 1.5) self.use_lucky_egg = config.get("BEHAVIOR", {}).get("AUTO_USE_LUCKY_EGG", False) self.use_google = config.get("BEHAVIOR", {}).get("USE_GOOGLE", False) self.skip_visited_fort_duration = config.get("BEHAVIOR", {}).get("SKIP_VISITED_FORT_DURATION", 600) self.spin_all_forts = config.get("BEHAVIOR", {}).get("SPIN_ALL_FORTS", False) self.stay_within_proximity = config.get("BEHAVIOR", {}).get("STAY_WITHIN_PROXIMITY", 9999999) # Stay within proximity self.should_catch_pokemon = config.get("CAPTURE", {}).get("CATCH_POKEMON", True) self.max_catch_attempts = config.get("CAPTURE", {}).get("MAX_CATCH_ATTEMPTS", 10) self.min_failed_attempts_before_using_berry = config.get("CAPTURE", {}).get("MIN_FAILED_ATTEMPTS_BEFORE_USING_BERRY", 3) pokeball_percent = config.get("CAPTURE", {}).get("USE_POKEBALL_IF_PERCENT", 50) greatball_percent = config.get("CAPTURE", {}).get("USE_GREATBALL_IF_PERCENT", 50) ultraball_percent = config.get("CAPTURE", {}).get("USE_ULTRABALL_IF_PERCENT", 50) use_masterball = config.get("CAPTURE", {}).get("USE_MASTERBALL", False) self.ball_priorities = [pokeball_percent, greatball_percent, ultraball_percent, use_masterball] self.min_items = {} for k, v in config.get("MIN_ITEMS", {}).items(): self.min_items[getattr(Item_Enums, k)] = v self.pokemon_evolution = {} self.pokemon_evolution_family = {} for k, v in config.get("POKEMON_EVOLUTION", {}).items(): self.pokemon_evolution[getattr(Enums, k)] = v self.pokemon_evolution_family[getattr(Enums, k)] = getattr(Enums, "FAMILY_" + k) self.experimental = config.get("BEHAVIOR", {}).get("EXPERIMENTAL", False) self.pokemon_cleanup_testing_mode = config.get('POKEMON_CLEANUP', {}).get('TESTING_MODE', False) self.min_similar_pokemon = config.get("POKEMON_CLEANUP", {}).get("MIN_SIMILAR_POKEMON", 1) # Keep atleast one of everything. self.keep_pokemon_ids = map(lambda x: getattr(Enums, x), config.get("POKEMON_CLEANUP", {}).get("KEEP_POKEMON_NAMES", [])) self.release_method = config.get("POKEMON_CLEANUP", {}).get("RELEASE_METHOD", "CLASSIC") self.release_method_conf = config.get("POKEMON_CLEANUP", {}).get("RELEASE_METHOD_" + self.release_method, {}) self.score_method = config.get("POKEMON_CLEANUP", {}).get("SCORE_METHOD", "CP") self.score_settings = config.get("POKEMON_CLEANUP", {}).get("SCORE_METHOD_" + self.score_method, {}) self.egg_incubation_enabled = config.get("EGG_INCUBATION", {}).get("ENABLE", True) self.use_disposable_incubators = config.get("EGG_INCUBATION", {}).get("USE_DISPOSABLE_INCUBATORS", False) self.incubate_big_eggs_first = config.get("EGG_INCUBATION", {}).get("BIG_EGGS_FIRST", True) self.farm_items_enabled = config.get("NEEDY_ITEM_FARMING", {}).get("ENABLE", True and self.experimental) # be concious of pokeball/item limits self.pokeball_continue_threshold = config.get("NEEDY_ITEM_FARMING", {}).get("POKEBALL_CONTINUE_THRESHOLD", 50) # keep at least 10 pokeballs of any assortment, otherwise go farming self.pokeball_farm_threshold = config.get("NEEDY_ITEM_FARMING", {}).get("POKEBALL_FARM_THRESHOLD", 10) # at this point, go collect pokeballs self.farm_ignore_pokeball_count = config.get("NEEDY_ITEM_FARMING", {}).get("FARM_IGNORE_POKEBALL_COUNT", False) # ignore pokeballs in the continue tally self.farm_ignore_greatball_count = config.get("NEEDY_ITEM_FARMING", {}).get("FARM_IGNORE_GREATBALL_COUNT", False) # ignore greatballs in the continue tally self.farm_ignore_ultraball_count = config.get("NEEDY_ITEM_FARMING", {}).get("FARM_IGNORE_ULTRABALL_COUNT", False) # ignore ultraballs in the continue tally self.farm_ignore_masterball_count = config.get("NEEDY_ITEM_FARMING", {}).get("FARM_IGNORE_MASTERBALL_COUNT", True) # ignore masterballs in the continue tally self.farm_override_step_size = config.get("NEEDY_ITEM_FARMING", {}).get("FARM_OVERRIDE_STEP_SIZE", -1) # should the step size be overriden when looking for more inventory, -1 to disable self._sanity_check_needy_item_farming() self.explain_evolution_before_cleanup = config.get("CONSOLE_OUTPUT", {}).get("EXPLAIN_EVOLUTION_BEFORE_CLEANUP", False) # explain individual evolution criteria in console self.list_pokemon_before_cleanup = config.get("CONSOLE_OUTPUT", {}).get("LIST_POKEMON_BEFORE_CLEANUP", False) # list pokemon in console self.list_inventory_before_cleanup = config.get("CONSOLE_OUTPUT", {}).get("LIST_INVENTORY_BEFORE_CLEANUP", True) # list inventory in console self.show_steps = config.get("CONSOLE_OUTPUT", {}).get("SHOW_STEPS", True) # show steps walked in console self.show_travel_link_with_steps = config.get("CONSOLE_OUTPUT", {}).get("SHOW_TRAVEL_LINK_WITH_STEPS", True) self.show_distance_traveled = config.get("CONSOLE_OUTPUT", {}).get("SHOW_DISTANCE_TRAVELED", True) self.show_nearest_fort_distance = config.get("CONSOLE_OUTPUT", {}).get("SHOW_NEAREST_FORT_DISTANCE", True) self.notify_no_nearby_pokemon = config.get("CONSOLE_OUTPUT", {}).get("NOTIFY_NO_NEARBY_POKEMON", False) self.log_colors = config.get("CONSOLE_OUTPUT", {}).get("COLORLOG", {"FORT_WALKER": "blue", "POKE_CATCHER": "green", "RELEASE": "cyan", "EVOLVE": "cyan", "POKETRAINER": "yellow", "INVENTORY": "purple"}) if cli_args['location']: start_location = cli_args['location'] else: start_location = self.location self.cache_filename = './cache/cache ' + (hashlib.md5(start_location.encode())).hexdigest() + str(self.stay_within_proximity) self.use_cache = config.get("BEHAVIOR", {}).get("USE_CACHED_FORTS", False) self.cache_is_sorted = config.get("BEHAVIOR", {}).get("CACHED_FORTS_SORTED", False) self.enable_caching = config.get("BEHAVIOR", {}).get("ENABLE_CACHING", False)
OR OTHER DEALINGS IN THE SOFTWARE. Author: tjado <https://github.com/tejado> Modifications by: j-e-k <https://github.com/j-e-k> Modifications by: Brad Smith <https://github.com/infinitewarp> """ import argparse import logging import gevent from helper.colorlogger import create_logger from poketrainer.poketrainer import Poketrainer logger = create_logger(__name__, color='red') def init_arguments(): parser = argparse.ArgumentParser() # Read passed in Arguments parser.add_argument("-i", "--config_index", help="Index of account to start in config.json", default=0, type=int) parser.add_argument( "-l", "--location", help= "Location. Only applies if an account was selected through config_index parameter"
def __init__(self, parent): self.parent = parent self.log = create_logger( __name__, self.parent.config.log_colors["evolve".upper()])