예제 #1
0
def build_charms(session: sqlalchemy.orm.Session, mhdata):
    item_map = mhdata.item_map
    skill_map = mhdata.skill_map
    charm_map = mhdata.charm_map

    # Store next recipe id ahead of time
    next_recipe_id = calculate_next_recipe_id(session)

    for order_id, entry in enumerate(charm_map.values()):
        # Note: previous is ok to be None
        previous = charm_map.id_of('en', entry['previous_en'])

        charm = db.Charm(id=entry.id,
                         order_id=order_id,
                         previous_id=previous,
                         rarity=entry['rarity'])

        for language in cfg.supported_languages:
            charm.translations.append(
                db.CharmText(lang_id=language,
                             name=get_translated(entry, 'name', language)))

        # Add charm skills
        for skill_en, level in datafn.iter_skill_levels(entry, amount=2):
            skill_id = skill_map.id_of('en', skill_en)
            ensure(
                skill_id, f"Charm {entry.name('en')} refers to " +
                f"skill {skill_en}, which doesn't exist.")

            charm.skills.append(
                db.CharmSkill(skilltree_id=skill_id, level=level))

        # Add Charm Recipe
        if entry.get('craft'):
            for item_en, quantity in datafn.iter_recipe(entry['craft'][0]):
                item_id = item_map.id_of('en', item_en)
                ensure(
                    item_id, f"Charm {entry.name('en')} refers to " +
                    f"item {item_en}, which doesn't exist.")

                charm.craft_items.append(
                    db.RecipeItem(recipe_id=next_recipe_id,
                                  item_id=item_id,
                                  quantity=quantity))
            next_recipe_id += 1

        session.add(charm)

    print("Built Charms")
예제 #2
0
def build_decorations(session: sqlalchemy.orm.Session, mhdata):
    "Performs the build process for decorations. Must be done after skills"

    skill_map = mhdata.skill_map
    decoration_map = mhdata.decoration_map

    for decoration_id, entry in decoration_map.items():
        skills = list(datafn.iter_skill_levels(entry, amount=2, pad=True))
        ensure("chances" in entry,
               "Missing chance data for " + entry.name('en'))

        decoration = db.Decoration(
            id=decoration_id,
            rarity=entry['rarity'],
            slot=entry['slot'],
            icon_color=entry['icon_color'],
            skilltree_id=skill_map.id_of('en', skills[0][0]),
            skilltree_level=skills[0][1],
            skilltree2_id=skill_map.id_of('en', skills[1][0]),
            skilltree2_level=skills[1][1],
            mysterious_feystone_percent=entry['chances']['mysterious'],
            glowing_feystone_percent=entry['chances']['glowing'],
            worn_feystone_percent=entry['chances']['worn'],
            warped_feystone_percent=entry['chances']['warped'],
            ancient_feystone_percent=entry['chances']['ancient'],
            carved_feystone_percent=entry['chances']['carved'],
            sealed_feystone_percent=entry['chances']['sealed'],
        )

        for language in cfg.supported_languages:
            decoration.translations.append(
                db.DecorationText(lang_id=language,
                                  name=get_translated(entry, 'name',
                                                      language)))

        session.add(decoration)

    print("Built Decorations")
예제 #3
0
def build_armor(session: sqlalchemy.orm.Session, mhdata):
    item_map = mhdata.item_map
    skill_map = mhdata.skill_map
    armorset_map = mhdata.armorset_map
    armorset_bonus_map = mhdata.armorset_bonus_map
    armor_map = mhdata.armor_map

    # Create reverse mapping. In SQL, armor links to armorset instead
    armor_to_armorset = {}
    armorset_to_bonus = {}

    # Write entries from armor set bonuses
    # These are written first as they are "linked to"
    for bonus_entry in armorset_bonus_map.values():
        for language in cfg.supported_languages:
            session.add(
                db.ArmorSetBonusText(id=bonus_entry.id,
                                     lang_id=language,
                                     name=get_translated(
                                         bonus_entry, 'name', language)))

        for skill_name, required in datafn.iter_setbonus_skills(bonus_entry):
            skill_id = skill_map.id_of('en', skill_name)
            session.add(
                db.ArmorSetBonusSkill(setbonus_id=bonus_entry.id,
                                      skilltree_id=skill_id,
                                      required=required))

    # Write entries for armor sets
    for set_id, entry in armorset_map.items():
        armorset_bonus_id = None

        if entry['bonus']:
            armorset_bonus_id = armorset_bonus_map.id_of('en', entry['bonus'])
            ensure(
                armorset_bonus_id,
                f"Armorset bonus {entry['bonus']} in armorsets doesn't exist")
            armorset_to_bonus[set_id] = armorset_bonus_id

        armorset = db.ArmorSet(id=set_id,
                               rank=entry['rank'],
                               armorset_bonus_id=armorset_bonus_id)

        if entry['monster']:
            armorset.monster_id = mhdata.monster_map.id_of(
                'en', entry['monster'])

        for language in cfg.supported_languages:
            armorset.translations.append(
                db.ArmorSetText(lang_id=language,
                                name=get_translated(entry, 'name', language)))

        session.add(armorset)

        # Populate reverse map (to allow armor to link to armorset)
        for part in cfg.armor_parts:
            if not entry[part]:
                continue

            armor_reverse_id = mhdata.armor_map.id_of('en', entry[part])
            armor_to_armorset[armor_reverse_id] = set_id

    # Store recipe id to start from for armor
    next_recipe_id = calculate_next_recipe_id(session)

    # Write entries for armor
    for order_id, entry in enumerate(armor_map.values()):
        armor_name_en = entry.name('en')

        armor = db.Armor(id=entry.id)
        armor.order_id = order_id
        armor.rarity = entry['rarity']
        armor.armor_type = entry['type']
        armor.male = entry['gender'] in ('male', 'both')
        armor.female = entry['gender'] in ('female', 'both')
        armor.slot_1 = entry['slot_1']
        armor.slot_2 = entry['slot_2']
        armor.slot_3 = entry['slot_3']
        armor.defense_base = entry['defense_base']
        armor.defense_max = entry['defense_max']
        armor.defense_augment_max = entry['defense_augment_max']
        armor.fire = entry['defense_fire']
        armor.water = entry['defense_water']
        armor.thunder = entry['defense_thunder']
        armor.ice = entry['defense_ice']
        armor.dragon = entry['defense_dragon']

        armorset_id = armor_to_armorset.get(entry.id, None)
        armorset_entry = armorset_map[armorset_id]
        armor.rank = armorset_entry['rank']
        armor.armorset_id = armorset_id
        armor.armorset_bonus_id = armorset_to_bonus.get(armorset_id, None)

        for language in cfg.supported_languages:
            armor.translations.append(
                db.ArmorText(
                    lang_id=language,
                    name=get_translated(entry, 'name', language),
                ))

        # Armor Skills
        for skill, level in datafn.iter_skill_levels(entry['skills']):
            skill_id = skill_map.id_of('en', skill)
            armor.skills.append(
                db.ArmorSkill(skilltree_id=skill_id, level=level))

        # Armor Crafting
        for item_name, quantity in datafn.iter_armor_recipe(entry):
            item_id = item_map.id_of('en', item_name)
            armor.craft_items.append(
                db.RecipeItem(recipe_id=next_recipe_id,
                              item_id=item_id,
                              quantity=quantity))

        next_recipe_id += 1

        session.add(armor)

    print("Built Armor")