示例#1
0
def parse_key_items():
    items = OrderedDict()

    if (CFG_PATH / 'es_WCSshop_db.txt').isfile():
        def _get_string(text):
            if text.startswith('wcs_lng_s_'):
                if _languages:
                    return _languages['en'][text]

            return text

        imported = KeyValues.load_from_file(CFG_PATH / 'es_WCSshop_db.txt').as_dict()

        if not _languages:
            warn(f'Unable to find the "es_WCSlanguage_db" file.')

        if (CFG_PATH / 'es_WCSshop_cat_db.txt').isfile():
            categories = KeyValues.load_from_file(CFG_PATH / 'es_WCSshop_cat_db.txt').as_dict()
        else:
            warn(f'Unable to find the "es_WCSshop_cat_db" file.')
            categories = {}

        for data in categories.values():
            fixed_category = FIX_NAME.sub('', data['name'].lower().replace(' ', '_'))

            if fixed_category not in item_manager._category_max_items:
                # TODO: Maybe it'd be set to 3 by default?
                item_manager._category_max_items[fixed_category] = 999

            if fixed_category not in categories_strings:
                categories_strings[fixed_category] = _LanguageString(_get_string(data['name']))

            data['items'] = []
            data['id'] = fixed_category

        no_category = []

        for name, data in imported.items():
            for alias, value in data.items():
                if alias.startswith('shopalias_'):
                    if cvar.find_command(alias) is None:
                        ServerCommand(alias)(_command)

                        _aliases[alias] = value
                    else:
                        if cfg_debug_alias_duplicate.get_float():
                            warn(f'Alias "{alias}" is already registered')

            try:
                fixed_name = FIX_NAME.sub('', name.lower().replace(' ', '_'))
                settings = ImportedItem(fixed_name, ModuleType.ESS_KEY)

                settings.cmds['activatecmd'] = data['cmdactivate']
                settings.cmds['buycmd'] = data['cmdbuy']

                settings.config['cost'] = int(data['cost'])
                settings.config['required'] = int(data['level'])
                settings.config['dab'] = int(data['dab'])
                settings.config['duration'] = int(data['duration'])
                settings.config['count'] = int(data['maxamount'])
                settings.config['event'] = [data['itemconfig']]

                settings.strings['name'] = _LanguageString(_get_string(data['name']))
                settings.strings['description'] = _LanguageString(_get_string(data['description']).replace(r'\n', '') if data['description'] else '')

                if categories and isinstance(data['category'], int):
                    categories[str(data['category'])]['items'].append(settings)
                else:
                    no_category.append(settings)
            except:
                warn(f'Unable to properly parse the item "{name}" due to the following exception:')
                except_hooks.print_exception()
                continue
            else:
                items[fixed_name] = settings

        for data in categories.values():
            for settings in data['items']:
                settings.add_to_category(data['id'])

        for settings in no_category:
            settings.add_to_category(None)

    return items
示例#2
0
_aliases = {}

if (TRANSLATION_PATH / 'strings.ini').isfile():
    _strings = LangStrings(TRANSLATION_PATH / 'strings')

    for key in _strings:
        for language, message in _strings[key].items():
            _strings[key][language] = message.replace('#default', COLOR_DEFAULT).replace('#green', COLOR_GREEN).replace('#lightgreen', COLOR_LIGHTGREEN).replace('#darkgreen', COLOR_DARKGREEN)
else:
    _strings = None

_restrictions = WeaponRestrictionHandler()
_all_weapons = set([x.basename for x in WeaponClassIter('all', ['melee', 'objective'])])

if (CFG_PATH / 'es_WCSlanguage_db.txt').isfile():
    _languages = KeyValues.load_from_file(CFG_PATH / 'es_WCSlanguage_db.txt').as_dict()
else:
    _languages = {}

_repeats = defaultdict(list)


# ============================================================================
# >> HELPER FUNCTIONS
# ============================================================================
def validate_userid_after_delay(callback, userid, *args, validator=convert_userid_to_player):
    callback(None, validator(userid), *args)


def _format_message(userid, name, args):
    if _strings is None:
示例#3
0
def parse_key_races():
    races = OrderedDict()

    if (CFG_PATH / 'es_WCSraces_db.txt').isfile():
        def _get_string(text):
            if text.startswith('wcs_lng_r_'):
                if _languages:
                    return _languages['en'][text]

            return text

        imported = KeyValues.load_from_file(CFG_PATH / 'es_WCSraces_db.txt').as_dict()

        if not _languages:
            warn(f'Unable to find the "es_WCSlanguage_db" file.')

        for data in imported.values():
            for alias, value in data.items():
                if alias.startswith('racealias_'):
                    if cvar.find_command(alias) is None:
                        ServerCommand(alias)(_command)

                        _aliases[alias] = value
                    else:
                        if cfg_debug_alias_duplicate.get_float():
                            warn(f'Alias "{alias}" is already registered')

            try:
                name = _get_string(data['name'])

                fixed_name = FIX_NAME.sub('', name.lower().replace(' ', '_'))
                settings = ImportedRace(fixed_name, ModuleType.ESS_KEY)

                settings.cmds['preloadcmd'] = data['preloadcmd'] or None
                settings.cmds['roundstartcmd'] = data['round_start_cmd'] or None
                settings.cmds['roundendcmd'] = data['round_end_cmd'] or None
                settings.cmds['spawncmd'] = data['player_spawn_cmd'] or None
                settings.cmds['deathcmd'] = data.get('deathcmd') or None
                settings.cmds['changeintocmd'] = data.get('changeintocmd') or None
                settings.cmds['changefromcmd'] = data.get('changefromcmd') or None

                settings.config['required'] = data['required_level']
                settings.config['maximum'] = data['maximum_level']
                settings.config['maximum_race_level'] = int(data.get('maximum_race_level', 0))

                settings.config['restrictbot'] = int(data.get('restrictbot', 0))
                settings.config['restrictmap'] = data['restrictmap'].split('|') if data.get('restrictmap') else []
                settings.config['restrictitem'] = data['restrict_shop'].replace('<', '').split('>')[:-1] if 'restrict_shop' in data and data['restrict_shop'] else []
                settings.config['restrictweapon'] = data['restrictweapon'].split('|') if data.get('restrictweapon') else []
                settings.config['restrictteam'] = int(data.get('restrictteam', 0))
                settings.config['teamlimit'] = data['teamlimit']

                settings.config['author'] = data['author']
                settings.config['allowonly'] = data['allow_only'].split('|') if data['allow_only'] else []

                skillnames = _get_string(data['skillnames']).split('|')
                skilldescr = _get_string(data['skilldescr']).split('|')
                skillcfg = data['skillcfg'].split('|')
                skillneeded = [8 if x == 'player_ultimate' else 0 for x in skillcfg]
                numberoflevels = data['numberoflevels']

                skills = settings.config['skills'] = {}

                for i, skill_name in enumerate(skillnames):
                    fixed_skill_name = FIX_NAME.sub('', skill_name.lower().replace(' ', '_'))

                    settings.strings[fixed_skill_name] = _LanguageString(skill_name)
                    settings.strings[f'{fixed_skill_name} description'] = _LanguageString(skilldescr[i].replace(r'\n', ''))

                    skill = skills[fixed_skill_name] = {}

                    skill['event'] = [skillcfg[i]]

                    if skillcfg[i] == 'player_ultimate':
                        skill['cooldown'] = [data['ultimate_cooldown']] * numberoflevels

                    skill['required'] = [skillneeded[i]] * numberoflevels

                    skill['variables'] = {}

                    skill['cmds'] = {}
                    skill['cmds']['setting'] = data[f'skill{i + 1}_setting'].split('|')

                    cmd = data[f'skill{i + 1}_cmd']
                    skill['cmds']['cmd'] = None if cmd == '0' else cmd

                    cmd = data[f'skill{i + 1}_sfx']
                    skill['cmds']['sfx'] = None if cmd == '0' else cmd

                    skill['maximum'] = numberoflevels

                settings.strings['name'] = _LanguageString(name)
                settings.strings['description'] = _LanguageString(_get_string(data['shortdescription']).replace(r'\n', '') if data['shortdescription'] else '')

                settings.add_to_category(None)
            except:
                warn(f'Unable to properly parse the race "{name}" due to the following exception:')
                except_hooks.print_exception()
                continue
            else:
                races[fixed_name] = settings

    return races
示例#4
0
文件: oldesc.py 项目: Idleless/WCS
def parse_key_items():
    items = OrderedDict()

    if (CFG_PATH / 'es_WCSshop_db.txt').isfile():
        def _get_string(text):
            if text.startswith('wcs_lng_s_'):
                if _languages:
                    return _languages['en'][text]

            return text

        imported = KeyValues.load_from_file(CFG_PATH / 'es_WCSshop_db.txt').as_dict()

        if not _languages:
            warn(f'Unable to find the "es_WCSlanguage_db" file.')

        if (CFG_PATH / 'es_WCSshop_cat_db.txt').isfile():
            categories = KeyValues.load_from_file(CFG_PATH / 'es_WCSshop_cat_db.txt').as_dict()
        else:
            warn(f'Unable to find the "es_WCSshop_cat_db" file.')
            categories = {}

        for number, data in categories.items():
            fixed_category = FIX_NAME.sub('', data['name'].lower().replace(' ', '_'))

            if fixed_category not in item_manager._category_max_items:
                # TODO: Maybe it'd be set to 3 by default?
                item_manager._category_max_items[fixed_category] = 999

            if fixed_category not in categories_strings:
                categories_strings[fixed_category] = _LanguageString(_get_string(data['name']))

            data['items'] = []
            data['id'] = fixed_category

        no_category = []

        for name, data in imported.items():
            for alias, value in data.items():
                if alias.startswith('shopalias_'):
                    _aliases[alias] = value

                    ServerCommand(alias)(_command)

            fixed_name = FIX_NAME.sub('', name.lower().replace(' ', '_'))
            settings = items[fixed_name] = ImportedItem(fixed_name, ModuleType.ESS_KEY)

            settings.cmds['activatecmd'] = data['cmdactivate']
            settings.cmds['buycmd'] = data['cmdbuy']

            settings.config['cost'] = int(data['cost'])
            settings.config['required'] = int(data['level'])
            settings.config['dab'] = int(data['dab'])
            settings.config['duration'] = int(data['duration'])
            settings.config['count'] = int(data['maxamount'])
            settings.config['event'] = [data['itemconfig']]

            settings.strings['name'] = _LanguageString(_get_string(data['name']))
            settings.strings['description'] = _LanguageString(_get_string(data['description']).replace(r'\n', ''))

            if isinstance(data['category'], int):
                categories[str(data['category'])]['items'].append(settings)
            else:
                no_category.append(settings)

        for number, data in categories.items():
            for settings in data['items']:
                settings.add_to_category(data['id'])

        for settings in no_category:
            settings.add_to_category(None)

    return items