コード例 #1
0
ファイル: sql.py プロジェクト: kkkkyue/MHWorldData
def build_weapons(session: sqlalchemy.orm.Session, mhdata):
    item_map = mhdata.item_map
    weapon_map = mhdata.weapon_map

    # Prepass to determine which weapons are "final"
    # All items that are a previous to another are "not final"
    all_final = set(weapon_map.keys())
    for entry in weapon_map.values():
        if not entry.get('previous_en', None):
            continue
        try:
            prev_id = weapon_map.id_of('en', entry['previous_en'])
            all_final.remove(prev_id)
        except KeyError:
            pass

    # now iterate over actual weapons
    for weapon_id, entry in weapon_map.items():
        weapon = db.Weapon(id=weapon_id)

        # Add language translations
        for language in cfg.supported_languages:
            weapon.translations.append(
                db.WeaponText(lang_id=language, name=entry.name(language)))

        weapon.weapon_type = entry['weapon_type']
        weapon.rarity = entry['rarity']
        weapon.attack = entry['attack']
        weapon.defense = entry['defense'] or 0
        weapon.slot_1 = entry['slot_1']
        weapon.slot_2 = entry['slot_2']
        weapon.slot_3 = entry['slot_3']

        weapon.element1 = entry['element1']
        weapon.element1_attack = entry['element1_attack']
        weapon.element2 = entry['element2']
        weapon.element2_attack = entry['element2_attack']
        weapon.element_hidden = entry['element_hidden']

        weapon.sharpness = entry['sharpness']
        weapon.sharpness_complete = entry['sharpness_complete']
        weapon.kinsect_bonus = entry.get('kinsect_bonus', None)

        weapon.craftable = False  # set to true later if it can be crafted
        weapon.final = weapon_id in all_final

        if entry.get('previous', None):
            previous_weapon_id = weapon_map.id_of("en", entry['previous'])
            ensure(previous_weapon_id,
                   f"Weapon {entry['previous']} does not exist")
            weapon.previous_weapon_id = previous_weapon_id

        # Add crafting/upgrade recipes
        for recipe in entry.get('craft', {}):
            recipe_type = recipe['type']
            if recipe_type == "Create":
                weapon.craftable = True

            for item, quantity in datafn.iter_weapon_recipe(recipe):
                item_id = item_map.id_of("en", item)
                session.add(
                    db.WeaponRecipe(weapon_id=weapon_id,
                                    item_id=item_id,
                                    quantity=quantity,
                                    recipe_type=recipe_type))

        # Bow data (if any)
        if entry.get("bow", None):
            bow_data = entry['bow']
            weapon.coating_close = bow_data['close']
            weapon.coating_power = bow_data['power']
            weapon.coating_poison = bow_data['poison']
            weapon.coating_paralysis = bow_data['paralysis']
            weapon.coating_sleep = bow_data['sleep']
            weapon.coating_blast = bow_data['blast']

        # Gun data
        if entry.get("gun", None):
            gun_data = entry['gun']
            weapon.deviation = gun_data['deviation']
            weapon.special_ammo = gun_data['special']
            weapon.ammo_normal_1 = gun_data['normal_1']
            weapon.ammo_normal_2 = gun_data['normal_2']
            weapon.ammo_normal_3 = gun_data['normal_3']
            weapon.ammo_pierce_1 = gun_data['pierce_1']
            weapon.ammo_pierce_2 = gun_data['pierce_2']
            weapon.ammo_pierce_3 = gun_data['pierce_3']
            weapon.ammo_spread_1 = gun_data['spread_1']
            weapon.ammo_spread_2 = gun_data['spread_2']
            weapon.ammo_spread_3 = gun_data['spread_3']
            weapon.ammo_sticky_1 = gun_data['sticky_1']
            weapon.ammo_sticky_2 = gun_data['sticky_2']
            weapon.ammo_sticky_3 = gun_data['sticky_3']
            weapon.ammo_cluster_1 = gun_data['cluster_1']
            weapon.ammo_cluster_2 = gun_data['cluster_2']
            weapon.ammo_cluster_3 = gun_data['cluster_3']
            weapon.ammo_recover_1 = gun_data['recover_1']
            weapon.ammo_recover_2 = gun_data['recover_2']
            weapon.ammo_poison_1 = gun_data['poison_1']
            weapon.ammo_poison_2 = gun_data['poison_2']
            weapon.ammo_paralysis_1 = gun_data['paralysis_1']
            weapon.ammo_paralysis_2 = gun_data['paralysis_2']
            weapon.ammo_sleep_1 = gun_data['sleep_1']
            weapon.ammo_sleep_2 = gun_data['sleep_2']
            weapon.ammo_exhaust_1 = gun_data['exhaust_1']
            weapon.ammo_exhaust_2 = gun_data['exhaust_2']
            weapon.ammo_flaming = gun_data['flaming']
            weapon.ammo_water = gun_data['water']
            weapon.ammo_freeze = gun_data['freeze']
            weapon.ammo_thunder = gun_data['thunder']
            weapon.ammo_dragon = gun_data['dragon']
            weapon.ammo_slicing = gun_data['slicing']
            weapon.ammo_wyvern = gun_data['wyvern']
            weapon.ammo_demon = gun_data['demon']
            weapon.ammo_armor = gun_data['armor']
            weapon.ammo_tranq = gun_data['tranq']

        session.add(weapon)

    print("Built Weapons")
コード例 #2
0
def build_weapons(session: sqlalchemy.orm.Session, mhdata):
    item_map = mhdata.item_map
    weapon_map = mhdata.weapon_map

    # Save all weapon ammo configurations
    for entry in mhdata.weapon_ammo_map.values():
        ammo = db.WeaponAmmo(id=entry.id,
                             deviation=entry['deviation'],
                             special_ammo=entry['special'])

        # helper to assign the entirety of a group to the db
        def assign_group(ammotype):
            group = entry[ammotype]
            setattr(ammo, ammotype + "_clip", group['clip'])
            setattr(ammo, ammotype + "_rapid", group['rapid'])
            setattr(ammo, ammotype + "_recoil", group.get('recoil', None) or 0)
            setattr(ammo, ammotype + "_reload", group.get('reload', None))

        assign_group('normal1')
        assign_group('normal2')
        assign_group('normal3')
        assign_group('pierce1')
        assign_group('pierce2')
        assign_group('pierce3')
        assign_group('spread1')
        assign_group('spread2')
        assign_group('spread3')
        assign_group('sticky1')
        assign_group('sticky2')
        assign_group('sticky3')
        assign_group('cluster1')
        assign_group('cluster2')
        assign_group('recover1')
        assign_group('recover2')
        assign_group('poison1')
        assign_group('poison2')
        assign_group('paralysis1')
        assign_group('paralysis2')
        assign_group('sleep1')
        assign_group('sleep2')
        assign_group('exhaust1')
        assign_group('exhaust2')
        assign_group('flaming')
        assign_group('water')
        assign_group('freeze')
        assign_group('thunder')
        assign_group('dragon')

        assign_group('slicing')
        assign_group('demon')
        assign_group('armor')
        assign_group('tranq')

        ammo.wyvern_clip = entry['wyvern']['clip']
        ammo.wyvern_reload = entry['wyvern']['reload']

        session.add(ammo)

    # Save all weapon melodies
    for melody_entry in mhdata.weapon_melodies.values():
        melody = db.WeaponMelody(base_duration=melody_entry['base_duration'],
                                 base_extension=melody_entry['base_extension'],
                                 m1_duration=melody_entry['m1_duration'],
                                 m1_extension=melody_entry['m1_extension'],
                                 m2_duration=melody_entry['m2_duration'],
                                 m2_extension=melody_entry['m2_extension'])

        for language in cfg.supported_languages:
            melody.translations.append(
                db.WeaponMelodyText(
                    lang_id=language,
                    name=get_translated(melody_entry, 'name', language),
                    effect1=get_translated(melody_entry, 'effect1', language),
                    effect2=get_translated(melody_entry, 'effect2', language)))

        for note_entry in melody_entry['notes']:
            melody.notes.append(
                db.WeaponMelodyNotes(notes=note_entry['notes']))

        session.add(melody)

    # Prepass to determine which weapons are "final"
    # All items that are a previous to another are "not final"
    all_final = set(weapon_map.keys())
    for entry in weapon_map.values():
        if not entry.get('previous_en', None):
            continue
        try:
            prev_id = weapon_map.id_of('en', entry['previous_en'],
                                       entry['weapon_type'])
            all_final.remove(prev_id)
        except KeyError:
            pass

    # Query next recipe id beforehand
    next_recipe_id = calculate_next_recipe_id(session)

    # now iterate over actual weapons
    for idx, entry in enumerate(weapon_map.values()):
        weapon_id = entry.id
        weapon_type = entry['weapon_type']

        weapon = db.Weapon(
            id=weapon_id,
            order_id=idx,
            weapon_type=weapon_type,
        )

        # Add language translations
        for language in cfg.supported_languages:
            weapon.translations.append(
                db.WeaponText(lang_id=language,
                              name=get_translated(entry, 'name', language)))

        weapon.category = entry['category']
        weapon.rarity = entry['rarity']
        weapon.attack = entry['attack']
        weapon.attack_true = int(entry['attack'] /
                                 cfg.weapon_multiplier[weapon_type])
        weapon.affinity = entry['affinity']
        weapon.defense = entry['defense'] or 0
        weapon.slot_1 = entry['slot_1']
        weapon.slot_2 = entry['slot_2']
        weapon.slot_3 = entry['slot_3']

        weapon.element1 = entry['element1']
        weapon.element1_attack = entry['element1_attack']
        weapon.element2 = entry['element2']
        weapon.element2_attack = entry['element2_attack']
        weapon.element_hidden = entry['element_hidden']
        weapon.elderseal = entry['elderseal']

        if entry.get('sharpness', None):
            weapon.sharpness = datafn.merge_sharpness(entry)
            weapon.sharpness_maxed = entry['sharpness']['maxed']

        weapon.kinsect_bonus = entry['kinsect_bonus']
        weapon.phial = entry['phial']
        weapon.phial_power = entry['phial_power']
        weapon.shelling = entry['shelling']
        weapon.shelling_level = entry['shelling_level']
        weapon.notes = entry['notes']

        weapon.craftable = False  # set to true later if it can be crafted
        weapon.final = weapon_id in all_final

        previous_weapon_name = entry.get('previous_en', None)
        if previous_weapon_name:
            previous_weapon_id = weapon_map.id_of("en", previous_weapon_name,
                                                  weapon_type)
            ensure(previous_weapon_id,
                   f"Weapon {previous_weapon_name} does not exist")
            weapon.previous_weapon_id = previous_weapon_id

        # Add crafting/upgrade recipes
        for recipe in entry.get('craft', {}):
            recipe_type = recipe['type']
            if recipe_type == "Create":
                weapon.craftable = True
                weapon.create_recipe_id = next_recipe_id
            else:
                weapon.upgrade_recipe_id = next_recipe_id

            for item, quantity in datafn.iter_recipe(recipe):
                item_id = item_map.id_of("en", item)
                session.add(
                    db.RecipeItem(recipe_id=next_recipe_id,
                                  item_id=item_id,
                                  quantity=quantity))

            next_recipe_id += 1

        # Bow data (if any)
        if entry.get("bow", None):
            bow_data = entry['bow']
            weapon.coating_close = bow_data['close']
            weapon.coating_power = bow_data['power']
            weapon.coating_poison = bow_data['poison']
            weapon.coating_paralysis = bow_data['paralysis']
            weapon.coating_sleep = bow_data['sleep']
            weapon.coating_blast = bow_data['blast']

        # Gun data mapping (if any)
        ammo_config_name = entry.get('ammo_config', None)
        if ammo_config_name:
            weapon.ammo_id = mhdata.weapon_ammo_map[ammo_config_name].id

        # Skills
        if entry['skill']:
            skill_id = mhdata.skill_map.id_of('en', entry['skill'])
            weapon.skills.append(db.WeaponSkill(skilltree_id=skill_id,
                                                level=1))

        session.add(weapon)

    print("Built Weapons")
コード例 #3
0
ファイル: sql.py プロジェクト: kevinn/MHWorldData
def build_weapons(session: sqlalchemy.orm.Session, mhdata):
    item_map = mhdata.item_map
    weapon_data = mhdata.weapon_data
    weapon_map = mhdata.weapon_map

    # Prepass to determine which weapons are "final"
    # All items that are a previous to another are "not final"
    all_final = set(weapon_data.keys())
    for entry in weapon_data.values():
        if not entry.get('previous', None):
            continue
        try:
            prev_id = weapon_map.id_of('en', entry['previous'])
            all_final.remove(prev_id)
        except KeyError:
            pass

    for weapon_id, entry in weapon_data.items():
        weapon = db.Weapon(id=weapon_id)
        weapon.weapon_type = entry['weapon_type']
        weapon.rarity = entry['rarity']
        weapon.attack = entry['attack']
        weapon.slot_1 = entry['slots'][0]
        weapon.slot_2 = entry['slots'][1]
        weapon.slot_3 = entry['slots'][2]

        weapon.element_type = entry['element_type']
        weapon.element_damage = entry['element_damage']
        weapon.element_hidden = entry['element_hidden']

        # todo: sharpness, coatings, ammo

        # Note: High probably the way this is stored in data will be refactored
        # Possibilities are either split weapon_data files, or separated sub-data files
        weapon.glaive_boost_type = entry.get('glaive_boost_type', None)
        weapon.deviation = entry.get('deviation', None)
        weapon.special_ammo = entry.get('special_ammo', None)

        weapon.craftable = bool(entry.get('craft', False))
        weapon.final = weapon_id in all_final

        if entry.get('previous', None):
            previous_weapon_id = weapon_map.id_of("en", entry['previous'])
            ensure(previous_weapon_id,
                   f"Weapon {entry['previous']} does not exist")
            weapon.previous_weapon_id = previous_weapon_id

        # Add language translations
        for language in supported_languages:
            weapon.translations.append(
                db.WeaponText(lang_id=language, name=entry.name(language)))

        # Add crafting/upgrade recipes
        for recipe_type in ('craft', 'upgrade'):
            recipe = entry.get(recipe_type, {}) or {}
            for item, quantity in recipe.items():
                item_id = item_map.id_of("en", item)
                ensure(
                    item_id,
                    f"Item {item_id} in weapon {entry.name('en')} does not exist"
                )
                session.add(
                    db.WeaponRecipe(weapon_id=weapon_id,
                                    item_id=item_id,
                                    quantity=quantity,
                                    recipe_type=recipe_type))

        session.add(weapon)

    print("Built Weapons")