Exemple #1
0
def get_names_by_match():
    mag_pattern = "(Mag.*|.*_[Mm]agazine.*|.*[Mm]ag$|.*MAG$)"
    matching = [{"name": ".*", "nominal": r"^[^0]"}]
    items = []
    for match in matching:
        m = matching_model.Match(match)
        for t in types.getroot():
            if m.match(t) and t.find('nominal') is not None:
                items.append(t.get('name'))
                # print('"' + t.get('name') + '",' + '\t' + str(list(v.get('name') for v in t.findall('value'))))
    items = sorted(list(set(items)))
    print(json.dumps(items, indent=2))
    print(len(items))
    spawnables = [{
        'type':
        item,
        'attachments': [{
            'chance':
            '1.00',
            'items': [{
                'name': find_mag_name(item, items, mag_pattern),
                'chance': '1.00'
            }]
        }]
    } for item in items if not re.match(mag_pattern, item)]
    print(json.dumps(spawnables, indent=2))
Exemple #2
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))
Exemple #3
0
def get_items_for_airdrop():
    matching = [{
        "name":
        "(?!.*(Bu?ttsto?ck|Light|Bayonet|Hndgrd|Knife|Compensator|LRS|Scope|Muzzle|Holo|Binocs|STANAG|Mushroom).*)",
        "category": {
            "name": "weapons"
        },
        "value": [{
            "name": "Tier4"
        }],
        "flags": [{
            "name": "deloot",
            "value": False
        }]
    }, {
        "name":
        ".*(CodeLock|Tent|GhillieSuitBox(?!Winter)|NVG(?!Headstrap)).*"
    }, {
        "name": "(csmcmillan_mung|MSFC_Barret50BMG_Black|MSFC_OSV96)"
    }]
    for match in matching:
        m = matching_model.Match(match)
        for t in types.getroot():
            if m.match(t):
                print('"' + t.get('name') + '",')
Exemple #4
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()
Exemple #5
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)))
Exemple #6
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))
Exemple #7
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))
Exemple #8
0
def get_names_by_match_old():
    matching = [{
        "name":
        "(?!.*(Pelt|Firewood|katana|kv5|Belt|Seeds|Rag|teddyhead|TannedLeather|Wolf|CourierBag|PlateCarrier|Improvised)).*",
        "nominal": r"^[^0]",
        "value": [],
        "category": {
            "name": "clothes"
        }
    }]
    items = []
    for match in matching:
        m = matching_model.Match(match)
        for t in types.getroot():
            if m.match(t) and t.find('nominal') is not None:
                items.append(t.get('name'))
                # print('"' + t.get('name') + '",' + '\t' + str(list(v.get('name') for v in t.findall('value'))))
    items = sorted(list(set(items)))
    print(json.dumps(items, indent=2))
    print(len(items))
    shoes = r'.*(Shoes|Boots|Wellies|Sneakers).*'
    hats = r'.*(Cap|Hat|[Hh]elmet|strawhat|Beret|shawl|Gloves|Ushanka).*'
    masks = r'.*(Mask|Glasses|Balaclava|[Bb]andana|[Gg]oggles|Hood[^i]).*'
    shirts = r'(?!.*Mini).*([Cc]oat|Shirt|Jacket|[Mm]anSuit|Blouse|Hoodie|[Vv]est|Dress(?!Shoes)|Sweater|Chest).*'
    pants = r'.*(Pants|Slacks|Jeans|Skirt|MiniDress|Breeches).*'
    groups = (shoes, hats, masks, shirts, pants)

    new_items = []
    for group in groups:
        to_add = list(filter(lambda item: re.match(group, item), items))
        print(group)
        print('new', len(to_add))
        print(sorted(list(set(to_add) & set(new_items))))
        new_items += to_add
        print('set', len(set(new_items)))
    print(len(new_items))
    print(json.dumps(sorted(list(set(items) - set(new_items))), indent=2))
Exemple #9
0
def get_stats(types_et=None):
    if types_et is None:
        types_et = types.getroot()
    sum_nominal = 0
    count_items = 0
    sum_min = 0
    nominals = {}
    mins = {}
    restocks = {}
    matching = [{
        "nominal": "^[^0]",
        # "restock": "^0$",
        "flags": [{
            "name": "deloot",
            "value": False
        }]
    }]
    for match in matching:
        for usage in ('Firefighter', 'Prison', 'Industrial', 'Hunting',
                      'Military', 'Police', 'Village', 'Coast', 'Medic',
                      'Farm', 'Town'):
            match['usage'] = [{"name": usage}]
            sum_nominal = 0
            count_items = 0
            sum_min = 0
            nominals = {}
            mins = {}
            restocks = {}
            m = matching_model.Match(match)
            for t in types_et:
                if m.match(t) and t.find('nominal') is not None:
                    nominal = int(t.find('nominal').text)
                    min_value = int(t.find('min').text)
                    restock = int(t.find('restock').text)
                    # print(t.get('name'), nominal, min_value, restock)
                    sum_nominal += nominal
                    if nominal not in nominals:
                        nominals[nominal] = 0
                    nominals[nominal] += 1
                    sum_min += min_value
                    if min_value not in mins:
                        mins[min_value] = 0
                    mins[min_value] += 1
                    if restock not in restocks:
                        restocks[restock] = 0
                    restocks[restock] += 1
                    count_items += 1
            # print('''vanilla stats
            # items 1285
            # sum nominal 20128
            # avg nominal 15.663813229571984
            # sum min 12571
            # avg min 9.782879377431907''')
            print(usage)
            print('items', count_items)
            print('sum nominal', sum_nominal)
            print('avg nominal', sum_nominal / max(1, count_items))
            # print('nominal values')
            # print(json.dumps([str((k, v)) for k, v in sorted(nominals.items())], indent=2))
            print('sum min', sum_min)
            print('avg min', sum_min / max(1, count_items))
            # print('min values')
            # print(json.dumps([str((k, v)) for k, v in sorted(mins.items())], indent=2))
            # print('restock values')
            # print(json.dumps([str((k, v)) for k, v in sorted(restocks.items())], indent=2))
            print()