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")
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 armor_parts = ['head', 'chest', 'arms', 'waist', 'legs'] # 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 entry in armorset_bonus_map.values(): for language in supported_languages: session.add( db.ArmorSetBonusText(id=entry.id, lang_id=language, name=entry.name(language))) for skill_entry in entry['skills']: skill_id = skill_map.id_of('en', skill_entry['skill']) ensure( skill_id, f"Skill {skill_entry['skill']} in armorset bonuses doesn't exist" ) session.add( db.ArmorSetBonusSkill(id=entry.id, skilltree_id=skill_id, points=skill_entry['points'], threshold=skill_entry['threshold'])) # Write entries for armor sets for set_id, entry in armorset_map.items(): armor_lang = entry['armor_lang'] armorset_bonus_id = None if entry['bonus']: armorset_bonus_id = armorset_bonus_map.id_of( armor_lang, 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, armorset_bonus_id=armorset_bonus_id) for language in supported_languages: armorset.translations.append( db.ArmorSetText(lang_id=language, name=entry.name(language))) session.add(armorset) # Populate reverse map (to allow armor to link to armorset) for part in armor_parts: if not entry[part]: continue armor_id = mhdata.armor_map.id_of(armor_lang, entry[part]) ensure(armor_id, f"Armor {entry[part]} in armorset does not exist") armor_to_armorset[armor_id] = set_id # Write entries for armor for armor_id, entry in armor_map.items(): armor_name_en = entry.name('en') armor = db.Armor(id=armor_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(armor_id, None) ensure(armorset_id, f"Armor {armor_name_en} is not in an armor set") armor.armorset_id = armorset_id armor.armorset_bonus_id = armorset_to_bonus.get(armorset_id, None) for language in supported_languages: armor.translations.append( db.ArmorText(lang_id=language, name=entry.name(language))) # Armor Skills for skill, level in entry['skills'].items(): skill_id = skill_map.id_of('en', skill) ensure(skill_id, f"Skill {skill} in Armor {armor_name_en} does not exist") armor.skills.append( db.ArmorSkill(skilltree_id=skill_id, level=level)) # Armor Crafting for item, quantity in entry['craft'].items(): item_id = item_map.id_of('en', item) ensure(item_id, f"Item {item} in Armor {armor_name_en} does not exist") armor.craft_items.append( db.ArmorRecipe(item_id=item_id, quantity=quantity)) session.add(armor) print("Built Armor")