Exemple #1
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
Exemple #2
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
Exemple #3
0
import es, esc
from gamethread import queue
from .. import aliases, stack
from . import Command, Alias
from ..val import sv

from cvars import cvar

if cvar.find_command('alias') is None:

    @Command(syntax='[commandname] [[commands]]',
             pre=False,
             argsfrom=1,
             desc='Alias a command.')
    def alias(argv, args):
        if not argv:
            es.dbgmsg(0, 'Current alias commands:\n')
            for alias in aliases:
                cmdstring = '; '.join(
                    '%s %s' % (cmdname, args)
                    for cmdname, argv, args in aliases[alias])
                es.dbgmsg(0, '%s : %s\n' % (alias, cmdstring))
        else:
            name = argv[0]
            if name in aliases:
                aliases[name].getcode(args, stack.currentline)
            elif not es.exists('command', argv[0]):
                Alias(name).getcode(args, stack.currentline)
            else:
                raise RuntimeError(
                    'Attempt to alias over an already registered command failed (current ESC limitation)'