Esempio n. 1
0
def items_clouds():
    with open(
            'resources/original-mod-files/Cl0uds/Types V9.1 - sorted by camos.xml'
    ) as f:
        raw = '<types>' + f.read() + '</types>'
        new_types = ElementTree.fromstring(raw)
    types.get().getroot().extend(new_types)
Esempio n. 2
0
def items_cpb_weapons():
    with open(
            'resources/original-mod-files/CPBWeapons/types(NOT A REPLACE).xml'
    ) as f:
        new_types = ElementTree.fromstring(f.read())

    for new_type in new_types:
        for value in new_type.findall('.//value'):
            new_type.remove(value)
        ElementTree.SubElement(new_type, 'value', attrib=dict(name='Tier4'))
        ElementTree.SubElement(new_type, 'value', attrib=dict(name='Tier3'))

    types.get().getroot().extend(new_types)
Esempio n. 3
0
def remove(matching=None, modification=None):
    match = matching_model.Match(matching)
    count = 0
    to_remove = list()
    for t in types.get().getroot():
        if match.match(t):
            count += 1
            log.debug('removing ' + t.attrib.get('name'))
            to_remove.append(t)
            # types.get().getroot().remove(t)
            # apply_modification(t, _REMOVE_MODIFICATION)
    for t in to_remove:
        types.get().getroot().remove(t)
    log.info('removed {} items matching {}'.format(count, matching))
Esempio n. 4
0
def simple_base_profile(directory):
    with open('resources/original-mod-files/Simple Base/types.xml') as f:
        raw = '<types>' + f.read() + '</types>'
        new_types = ElementTree.fromstring(raw)
    types.get().getroot().extend(new_types)
    with open('resources/original-mod-files/Simple Base/ServerProfileFolder/SimpleBase/config.txt') as f:
        lines = f.readlines()
    config = model.Config()
    config.parse_defaults(lines)
    with open(pathlib.Path(resourcesdir.get(), 'modifications/mods/simple_base/config.json')) as f:
        changes = json.load(f)
    for k, v in changes.items():
        config.set(k, v)
    with file_writing.f_open(pathlib.Path(directory, 'config.txt'), mode='w') as f:
        f.write(config.generate())
def spawnable_types_config(directory):
    """
    This configuration operates in an overriding fashion. That is, if a preset or list of items is specified
    for a type in the config, any existing entries for that type with the same tag and attribute will be erased.
    """
    p = pathlib.Path(deploydir.get(), 'mpmissions', mission.get(), 'cfgspawnabletypes.xml')
    with open(p) as f:
        # The parser in ElementTree was having trouble with the comments in the xml file
        # So, we're removing them manually beforehand
        raw = f.read()
        raw = re.sub(r'<!--.*-->', '', raw)
        spawnable_xml = ElementTree.fromstring(raw)
    with open(pathlib.Path(resourcesdir.get(), 'modifications/server/spawnable_types.json')) as f:
        spawnable_modifications = json.load(f)
    for type_config in spawnable_modifications:
        if len(db_types.get().getroot().findall('.//type[@name="{}"]'.format(type_config.get('type')))) == 0:
            continue
        types = spawnable_xml.findall('.//type[@name="{}"]'.format(type_config.get('type')))
        if len(types) == 0:
            new_type = ElementTree.SubElement(spawnable_xml, 'type', dict(name=type_config.get('type')))
            types = [new_type]
        for t in types:
            if 'cargo_presets' in type_config:
                handle_presets(t, 'cargo', type_config.get('cargo_presets'))
            if 'attachments_presets' in type_config:
                handle_presets(t, 'attachments', type_config.get('attachments_presets'))
            if 'cargo_items' in type_config:
                handle_items(t, 'cargo', type_config.get('cargo_items'))
            if 'attachments' in type_config:
                handle_items(t, 'attachments', type_config.get('attachments'))
    with file_writing.f_open(pathlib.Path(directory, 'cfgspawnabletypes.xml'), mode='w') as f:
        f.write(file_writing.convert_to_string(spawnable_xml))
Esempio n. 6
0
def modify_types(directory):
    with open(
            pathlib.Path(resourcesdir.get(),
                         'modifications/server/types_config.json')) as f:
        type_config = json.load(f)
    for action in type_config:
        log.info(action.get('description'))
        matching = action.get('matching')
        if action['action'] == 'remove':
            process_type = remove
        elif action['action'] == 'ratio':
            process_type = ratio
        else:
            process_type = modify
        for m in matching:
            process_type(matching=m,
                         modification=action.get('modification', dict()))

    with open(
            pathlib.Path(resourcesdir.get(),
                         'modifications/server/types_universal.json')) as f:
        type_universal_config = json.load(f)
    ratio_modifier = type_universal_config.get('ratio', 1)
    matching = {"nominal": "^[^0]"}
    m = matching_model.Match(matching)
    count = 0
    for t in types.get().getroot():
        if m.match(t) and t.find('nominal') is not None:
            count += 1
            t.find('nominal').text = str(
                max(1, int(ratio_modifier * int(t.find('nominal').text))))
            t.find('min').text = str(
                max(1, int(ratio_modifier * int(t.find('min').text))))
    log.info('modified {} items with ratio {}'.format(count, ratio_modifier))
Esempio n. 7
0
def add_dynamic(traders):
    with open(
            pathlib.Path(
                resourcesdir.get(),
                'modifications/mods/trader/inventory_dynamic.json')) as f:
        trader_config = json.load(f)
    temp_traders = {}
    for entry in trader_config:
        current_traders = entry.get('trader')
        if not isinstance(current_traders, list):
            current_traders = [current_traders]
        for trader_name in current_traders:
            if trader_name not in temp_traders:
                temp_traders[trader_name] = list()
            category_name = entry.get('category')
            log.info('processing {}'.format((trader_name, category_name)))
            categories = {}
            temp_traders[trader_name].append(categories)
            for item in entry.get('items'):
                expanded = {}
                matching = item.get('matching')
                buy = item.get('buy')
                sell = item.get('sell')
                quantity = item.get('quantity', None)
                item_type = get_item_type_for_name(item.get('item_class'))
                if matching is not None:
                    match = matching_model.Match(matching)
                    for t in types.get().getroot():
                        result = match.match(t)
                        if result:
                            items = expanded.get(result.groups.get('captured'),
                                                 list())
                            items.append(
                                item_type(t.get('name'), buy, sell, quantity))
                            expanded[result.groups.get('captured')] = items
                else:
                    name = item.get('name')
                    expanded[None] = [item_type(name, buy, sell, quantity)]
                for key in expanded:
                    current_cat_name = category_name.format(captured=key)
                    current_cat = categories.get(
                        current_cat_name, config.Category(current_cat_name))
                    if quantity is not None:
                        current_cat.items += [
                            item_type(i.name, buy, sell, quantity)
                            for i in expanded[key] if i not in current_cat
                        ]
                    else:
                        current_cat.items += [
                            item_type(i.name, buy, sell) for i in expanded[key]
                            if i not in current_cat
                        ]
                    categories[current_cat_name] = current_cat
    for key in temp_traders:
        for cat_set in temp_traders[key]:
            for c in cat_set.values():
                log.info('added {} dynamic items to {}'.format(
                    len(c.items), (key, c.name)))
            traders[key].categories += cat_set.values()
Esempio n. 8
0
def items_remastered_arma():
    raw = '<types>'
    with open(
            'resources/original-mod-files/[Remastered] Arma Weapon Pack/class_names.txt'
    ) as f:
        for line in f:
            type_name = line.strip()
            if 'Ammo' in type_name:
                raw += (
                    f'<type name="{type_name}">'
                    '<nominal>16</nominal>'
                    '<lifetime>10800</lifetime>'
                    '<restock>0</restock>'
                    '<min>8</min>'
                    '<quantmin>20</quantmin>'
                    '<quantmax>80</quantmax>'
                    '<cost>100</cost>'
                    '<flags count_in_cargo="0" count_in_hoarder="0" count_in_map="1" count_in_player="0" crafted="0" deloot="0"/>'
                    '<category name="weapons"/>'
                    '<usage name="Military"/>'
                    '<value name="Tier4"/>'
                    '<value name="Tier3"/>'
                    '</type>')
            else:
                raw += (
                    f'<type name="{type_name}">'
                    '<nominal>5</nominal>'
                    '<lifetime>10800</lifetime>'
                    '<restock>0</restock>'
                    '<min>3</min>'
                    '<quantmin>-1</quantmin>'
                    '<quantmax>-1</quantmax>'
                    '<cost>100</cost>'
                    '<flags count_in_cargo="0" count_in_hoarder="0" count_in_map="1" count_in_player="0" crafted="0" deloot="0"/>'
                    '<category name="weapons"/>'
                    '<usage name="Military"/>'
                    '<value name="Tier4"/>'
                    '<value name="Tier3"/>'
                    '</type>')
    raw += '</types>'
    new_types = ElementTree.fromstring(raw)
    types.get().getroot().extend(new_types)
Esempio n. 9
0
def modify(matching=None, modification=None):
    if modification is None:
        return
    match = matching_model.Match(matching)
    count = 0
    for t in types.get().getroot():
        if match.match(t):
            count += 1
            log.debug('modifying ' + t.attrib.get('name'))
            apply_modification(t, modification)
    log.info('modified {} items matching {} with {}'.format(
        count, matching, json.dumps(modification)))
Esempio n. 10
0
def code_lock(directory):
    new_type = ElementTree.parse('resources/original-mod-files/Code lock/types.xml')
    types.get().getroot().append(new_type.getroot())

    with open('resources/original-mod-files/Code lock/CodeLockConfig.json') as f:
        code_lock_config = json.load(f)
    code_lock_config['CanAttachToTents'] = 'true'
    code_lock_config['DestroyTool'] = 'true'
    with file_writing.f_open(pathlib.Path(directory, 'CodeLockConfig.json'), mode='w') as f:
        json.dump(code_lock_config, f, indent=2)
    users = []
    for superuser in auth.get().get('superusers', []):
        users.append({
            'playerId': superuser['steam64'],
            'playerPerms': {
                'CanOpenLocks': "true",
                'CanChangePasscodes': "true",
                'CanRemoveLocks': "true"
            }
        })
        log.info('adding {} as code lock admin'.format(superuser['name']))
    with file_writing.f_open(pathlib.Path(directory, 'CodeLockPerms.json'), mode='w') as f:
        json.dump(users, f, indent=2)
Esempio n. 11
0
def ratio(matching=None, modification=None):
    match = matching_model.Match(matching)
    count = 0
    ratio_modifier = modification.get('ratio')
    for t in types.get().getroot():
        if match.match(t) and t.find('nominal') is not None:
            count += 1
            t.find('nominal').text = str(
                max(1, int(ratio_modifier * int(t.find('nominal').text))))
            t.find('min').text = str(
                max(1, int(ratio_modifier * int(t.find('min').text))))
            count += 1
            log.debug('applying ratio to ' + t.attrib.get('name'))
    log.info('modified {} items with ratio {}'.format(count, ratio_modifier))
def items_base_fortifications():
    with open('resources/original-mod-files/Base Fortifications/types.xml') as f:
        raw = '<types>' + f.read() + '</types>'
        new_types = ElementTree.fromstring(raw)
    types.get().getroot().extend(new_types)
Esempio n. 13
0
def items_notes():
    with open('resources/original-mod-files/Notes/types.xml') as f:
        raw = '<types>' + f.read() + '</types>'
        new_types = ElementTree.fromstring(raw)
    types.get().getroot().extend(new_types)
Esempio n. 14
0
def items_msfc():
    for p in pathlib.Path('resources/original-mod-files/MSF-C').glob('*.xml'):
        with open(p) as f:
            raw = '<types>' + f.read() + '</types>'
            new_types = ElementTree.fromstring(raw)
        types.get().getroot().extend(new_types)
def item_lock_pick():
    with open('resources/original-mod-files/SchanaModLockPick/types.xml') as f:
        raw = '<types>' + f.read() + '</types>'
        new_types = ElementTree.fromstring(raw)
    types.get().getroot().extend(new_types)
Esempio n. 16
0
def sort_and_write_types_config(directory):
    types.get().getroot()[:] = sorted(types.get().getroot(), key=lambda child: child.get('name').lower())
    with file_writing.f_open(pathlib.Path(directory, 'types.xml'), mode='w') as f:
        f.write(file_writing.convert_to_string(types.get().getroot()))
Esempio n. 17
0
def items_dayz_weapons_painting():
    with open(
            'resources/original-mod-files/DayzWeaponsPainting/types.xml') as f:
        raw = '<types>' + f.read() + '</types>'
        new_types = ElementTree.fromstring(raw)
    types.get().getroot().extend(new_types)
Esempio n. 18
0
def items_munghards():
    new_types = ElementTree.parse(
        'resources/original-mod-files/MunghardsItemPack/types/types.xml')
    types.get().getroot().extend(new_types.getroot())
Esempio n. 19
0
def items_mass():
    new_types = ElementTree.parse(
        'resources/original-mod-files/MasssManyItemOverhaul/types(NOT A REPLACER).xml'
    )
    types.get().getroot().extend(new_types.getroot())
Esempio n. 20
0
def crsk_bmw_types():
    new_types = ElementTree.parse(
        'resources/original-mod-files/[CrSk] BMW 525i E34/types.xml')
    types.get().getroot().extend(new_types.getroot())