示例#1
0
 def set_pokemon(self, settings):
     # Start a new dict to track filters
     pokemon = {
         'enabled': bool(parse_boolean(settings.pop('enabled', False)))
     }
     min_dist = float(settings.pop('min_dist', None) or 0)
     max_dist = float(settings.pop('max_dist', None) or 'inf')
     min_iv = float(settings.pop('min_iv', None) or 0)
     max_iv = float(settings.pop('max_iv', None) or 100)
     ignore_missing = bool(
         parse_boolean(settings.pop('ignore_missing', False)))
     if pokemon['enabled']:
         log.info(
             "Pokemon defaults: distance {:.2f} to {:.2f} / IV's {:.2f} to {:.2f}"
             .format(min_dist, max_dist, min_iv, max_iv))
     for name in settings:
         pkmn_id = get_pkmn_id(name)
         if pkmn_id is None:
             log.error("Unable to find pokemon named {}...".format(name))
             continue
         if parse_boolean(settings[name]
                          ) is False:  # If set to false, set it as false
             log.debug("{} name set to 'false'. Skipping... ".format(name))
             continue
         else:
             try:
                 info = settings[name]
                 if parse_boolean(info):  # Allow all defaults
                     info = {}
                 pokemon[pkmn_id] = {
                     "min_dist":
                     float(info.get('min_dist', None) or min_dist),
                     "max_dist":
                     float(info.get('max_dist', None) or max_dist),
                     "min_iv":
                     float(info.get('min_iv', None) or min_iv),
                     "max_iv":
                     float(info.get('max_iv', None) or max_iv),
                     "move_1":
                     self.required_moves(info.get("move_1", None)),
                     "move_2":
                     self.required_moves(info.get("move_2", None)),
                     "moveset":
                     self.required_moveset(info.get("moveset", None)),
                     "ignore_missing":
                     bool(
                         parse_boolean(
                             info.get('ignore_missing', ignore_missing)))
                 }
             except Exception as e:
                 log.error(
                     "Trying to set pokemon {} gave error: \n {}".format(
                         pkmn_id, e))
                 log.debug("Stack trace: \n {}".format(
                     traceback.format_exc()))
                 sys.exit(1)
     for key in sorted(pokemon.iterkeys()):  # Output the pokemon in order
         log.debug("#{} was set to the following: \n{}".format(
             key, json.dumps(pokemon[key], sort_keys=True, indent=4)))
     self.__pokemon_filter = pokemon
示例#2
0
def load_pokemon_filters(settings):
    # Set the defaults for "True"
    default_filt = PokemonFilter(settings.pop('default', {}), {
        "ignore_missing": False,
        "min_dist": 0.0, "max_dist": float('inf'),
        "min_cp": 0, "max_cp": 999999,
        "min_level": 0, "max_level": 40,
        "min_iv": 0.0, "max_iv": 100.0,
        "min_atk": 0, "max_atk": 15,
        "min_def": 0, "max_def": 15,
        "min_sta": 0, "max_sta": 15,
        "quick_move": None, "charge_move": None, "moveset": None,
        "size": None,
        "gender": None,
        "form": None
    }, 'default')
    default = default_filt.to_dict()

    # Add the filters to the settings
    filters = {}
    for name in settings:
        pkmn_id = get_pkmn_id(name)
        if pkmn_id is None:
            log.error("Unable to find pokemon named '{}'...".format(name))
            log.error("Please see PokeAlarm documentation for proper Filter file formatting.")
            sys.exit(1)
        if pkmn_id in filters:
            log.error("Multiple entries detected for Pokemon #{}. Please remove any extra names.")
            sys.exit(1)
        f = create_multi_filter(name, PokemonFilter, settings[name], default)
        if f is not None:
            filters[pkmn_id] = f

    return filters
示例#3
0
def load_pokemon_filters(settings):
    # Set the defaults for "True"
    default_filt = PokemonFilter(settings.pop('default', {}), {
        "ignore_missing": False,
        "min_dist": 0.0, "max_dist": float('inf'),
        "min_cp": 0, "max_cp": 999999,
        "min_level": 0, "max_level": 40,
        "min_iv": 0.0, "max_iv": 100.0,
        "min_atk": 0, "max_atk": 15,
        "min_def": 0, "max_def": 15,
        "min_sta": 0, "max_sta": 15,
        "quick_move": None, "charge_move": None, "moveset": None,
        "size": None,
        "gender": None,
        "form": None
    }, 'default')
    default = default_filt.to_dict()

    # Add the filters to the settings
    filters = {}
    for name in settings:
        pkmn_id = get_pkmn_id(name)
        if pkmn_id is None:
            log.error("Unable to find pokemon named '{}'...".format(name))
            log.error("Please see PokeAlarm documentation for proper Filter file formatting.")
            sys.exit(1)
        if pkmn_id in filters:
            log.error("Multiple entries detected for Pokemon #{}. Please remove any extra names.")
            sys.exit(1)
        f = create_multi_filter(name, PokemonFilter, settings[name], default)
        if f is not None:
            filters[pkmn_id] = f

    return filters
示例#4
0
def load_pokemon_section(settings):
    log.info("Setting Pokemon filters...")
    pokemon = {
        "enabled": bool(parse_boolean(settings.pop('enabled', None)) or False)
    }
    # Set the defaults for "True"
    default_filt = PokemonFilter(
        settings.pop('default', {}),
        {
            "ignore_missing": False,
            "min_dist": 0.0,
            "max_dist": float('inf'),
            "min_iv": 0.0,
            "max_iv": 100.0,
            "min_atk": 0,
            "max_atk": 15,
            "min_def": 0,
            "max_def": 15,
            "min_sta": 0,
            "max_sta": 15,
            "min_cp": 0,
            "max_cp": 10000,  #RightIntheH
            "min_level": 0,
            "max_level": 40,  #RightIntheH
            "quick_move": None,
            "charge_move": None,
            "moveset": None,
            "size": None
        },
        'default')
    default = default_filt.to_dict()
    # Add the filters to the settings
    filters = {}
    for name in settings:
        pkmn_id = get_pkmn_id(name)
        if pkmn_id is None:
            log.error("Unable to find pokemon named '{}'...".format(name))
            log.error(
                "Please see PokeAlarm documentation for proper Filter file formatting."
            )
            sys.exit(1)
        if pkmn_id in pokemon:
            log.error(
                "Multiple entries detected for Pokemon #{}. Please remove any extra names."
            )
            sys.exit(1)
        f = create_multi_filter(name, PokemonFilter, settings[name], default)
        if f is not None:
            filters[pkmn_id] = f
    pokemon['filters'] = filters
    # Output filters
    log.debug(filters)
    for pkmn_id in sorted(filters):
        log.debug("The following filters are set for #{}:".format(pkmn_id))
        for i in range(len(filters[pkmn_id])):
            log.debug("F#{}: ".format(i) + filters[pkmn_id][i].to_string())

    return pokemon