Example #1
0
def build_monsters(session : sqlalchemy.orm.Session, mhdata):
    item_map = mhdata.item_map
    location_map = mhdata.location_map
    monster_map = mhdata.monster_map
    monster_reward_conditions_map = mhdata.monster_reward_conditions_map

    # Save conditions first
    for condition_id, entry in monster_reward_conditions_map.items():
        for language in cfg.supported_languages:
            session.add(db.MonsterRewardConditionText(
                id=condition_id,
                lang_id=language,
                name=get_translated(entry, 'name', language),
            ))

    # Save monsters
    for order_id, entry in enumerate(monster_map.values()):
        monster = db.Monster(
            id=entry.id,
            order_id=order_id,
            size=entry['size']
        )

        # Save basic weakness summary data
        if 'weaknesses' in entry and entry['weaknesses']:
            monster.has_weakness = True
            weaknesses = entry['weaknesses']
            for key, value in weaknesses['normal'].items():
                setattr(monster, 'weakness_'+key, value)

            if 'alt' in weaknesses:
                monster.has_alt_weakness = True
                for key, value in weaknesses['alt'].items():
                    setattr(monster, 'alt_weakness_'+key, value)

        # Save language data
        for language in cfg.supported_languages:
            alt_state_description = None
            if 'alt_description' in entry.get('weaknesses', {}):
                alt_state_description = get_translated(entry['weaknesses'], 'alt_description', language)

            monster.translations.append(db.MonsterText(
                lang_id=language,
                name=get_translated(entry, 'name', language),
                ecology=get_translated(entry, 'ecology', language),
                description=get_translated(entry, 'description', language),
                alt_state_description=alt_state_description
            ))

        # Save hitzones
        for hitzone_data in entry.get('hitzones', []):
            hitzone = db.MonsterHitzone(
                cut=hitzone_data['cut'],
                impact=hitzone_data['impact'],
                shot=hitzone_data['shot'],
                fire=hitzone_data['fire'],
                water=hitzone_data['water'],
                thunder=hitzone_data['thunder'],
                ice=hitzone_data['ice'],
                dragon=hitzone_data['dragon'],
                ko=hitzone_data['ko'])

            for language in cfg.supported_languages:
                part_name = get_translated(hitzone_data, 'hitzone', language)
                hitzone.translations.append(db.MonsterHitzoneText(
                    lang_id=language,
                    name=part_name
                ))

            monster.hitzones.append(hitzone)

        # Save breaks
        for break_data in entry.get('breaks', []):
            breakzone = db.MonsterBreak(
                flinch=break_data['flinch'],
                wound=break_data['wound'],
                sever=break_data['sever'],
                extract=break_data['extract']
            )

            for language in cfg.supported_languages:
                breakzone.translations.append(db.MonsterBreakText(
                    lang_id=language,
                    part_name=get_translated(break_data, 'part', language),
                ))

            monster.breaks.append(breakzone)

        # Save ailments
        ailments = entry.get('ailments', None)
        if ailments:
            monster.ailment_roar = ailments['roar']
            monster.ailment_wind = ailments['wind']
            monster.ailment_tremor = ailments['tremor']
            monster.ailment_defensedown = ailments['defense_down']
            monster.ailment_fireblight = ailments['fireblight']
            monster.ailment_waterblight = ailments['waterblight']
            monster.ailment_thunderblight = ailments['thunderblight']
            monster.ailment_iceblight = ailments['iceblight']
            monster.ailment_dragonblight = ailments['dragonblight']
            monster.ailment_blastblight = ailments['blastblight']
            monster.ailment_poison = ailments['poison']
            monster.ailment_sleep = ailments['sleep']
            monster.ailment_paralysis = ailments['paralysis']
            monster.ailment_bleed = ailments['bleed']
            monster.ailment_stun = ailments['stun']
            monster.ailment_mud = ailments['mud']
            monster.ailment_effluvia = ailments['effluvia']

        # Create a temp base map of the conditions
        # This temp map extends the global map with monster-specific conditions
        #monster_conditions = DataMap(reward_conditions_map)
        #monster_conditions.extend(entry.get('break_conditions', []))

        # Save hunting rewards
        for reward in entry.get('rewards', []):
            condition_en = reward['condition_en']
            rank = reward['rank']
            item_name = reward['item_en']

            condition_id = monster_reward_conditions_map.id_of('en', condition_en)
            item_id = item_map.id_of('en', item_name)

            monster.rewards.append(db.MonsterReward(
                condition_id=condition_id,
                rank=rank,
                item_id=item_id,
                stack=reward['stack'],
                percentage=reward['percentage']
            ))

        # Save Habitats
        for habitat_data in entry.get('habitats', []):
            location_name = habitat_data['map_en']
            location_id = location_map.id_of("en", location_name)
            ensure(location_id, "Invalid location name " + location_name)

            monster.habitats.append(db.MonsterHabitat(
                location_id=location_id,
                start_area=habitat_data['start_area'],
                move_area=habitat_data['move_area'],
                rest_area=habitat_data['rest_area']
            ))

        # Complete - add to session
        session.add(monster)

    print("Built Monsters")
Example #2
0
def build_monsters(session: sqlalchemy.orm.Session, mhdata,
                   item_tracker: ItemTracker):
    item_map = mhdata.item_map
    location_map = mhdata.location_map
    monster_map = mhdata.monster_map
    monster_reward_conditions_map = mhdata.monster_reward_conditions_map

    # Save conditions first
    for condition_id, entry in monster_reward_conditions_map.items():
        for language in cfg.supported_languages:
            session.add(
                db.MonsterRewardConditionText(
                    id=condition_id,
                    lang_id=language,
                    name=get_translated(entry, 'name', language),
                ))

    # Save monsters
    for order_id, entry in enumerate(monster_map.values()):
        monster = db.Monster(id=entry.id,
                             order_id=order_id,
                             size=entry['size'],
                             pitfall_trap=entry['pitfall_trap'],
                             shock_trap=entry['shock_trap'],
                             vine_trap=entry['vine_trap'])

        # todo: refactor to allow translations. Currently set when weaknesses are read
        alt_state_description = None

        # Save basic weakness summary data
        if 'weaknesses' in entry and entry['weaknesses']:
            elements = [
                'fire', 'water', 'ice', 'thunder', 'dragon', 'poison', 'sleep',
                'paralysis', 'blast', 'stun'
            ]

            weaknesses = {e['form']: e for e in entry['weaknesses']}
            form_normal = weaknesses.get('normal')
            form_alt = weaknesses.get('alt')

            invalid_keys = [
                k for k in weaknesses.keys() if k not in ('normal', 'alt')
            ]
            if invalid_keys:
                raise Exception(
                    f"Monster {entry.name('en')} has invalid form(s) {', '.join(invalid_keys)}"
                )

            if form_normal:
                monster.has_weakness = True
                for element in elements:
                    setattr(monster, 'weakness_' + element,
                            form_normal[element])

            if form_alt:
                monster.has_alt_weakness = True
                alt_state_description = form_alt['alt_description']

                for element in elements:
                    value = form_alt[element]
                    if value is None:
                        value = form_normal[element]
                    setattr(monster, 'alt_weakness_' + element, value)

        # Save language data
        for language in cfg.supported_languages:
            monster.translations.append(
                db.MonsterText(lang_id=language,
                               name=get_translated(entry, 'name', language),
                               ecology=entry['ecology_en'],
                               description=get_translated(
                                   entry, 'description', language),
                               alt_state_description=alt_state_description))

        # Save hitzones
        for hitzone_data in entry.get('hitzones', []):
            hitzone = db.MonsterHitzone(cut=hitzone_data['cut'],
                                        impact=hitzone_data['impact'],
                                        shot=hitzone_data['shot'],
                                        fire=hitzone_data['fire'],
                                        water=hitzone_data['water'],
                                        thunder=hitzone_data['thunder'],
                                        ice=hitzone_data['ice'],
                                        dragon=hitzone_data['dragon'],
                                        ko=hitzone_data['ko'])

            for language in cfg.supported_languages:
                part_name = get_translated(hitzone_data, 'hitzone', language)
                hitzone.translations.append(
                    db.MonsterHitzoneText(lang_id=language, name=part_name))

            monster.hitzones.append(hitzone)

        # Save breaks
        for break_data in entry.get('breaks', []):
            breakzone = db.MonsterBreak(flinch=break_data['flinch'],
                                        wound=break_data['wound'],
                                        sever=break_data['sever'],
                                        extract=break_data['extract'])

            for language in cfg.supported_languages:
                breakzone.translations.append(
                    db.MonsterBreakText(
                        lang_id=language,
                        part_name=get_translated(break_data, 'part', language),
                    ))

            monster.breaks.append(breakzone)

        # Save ailments
        ailments = entry.get('ailments', None)
        if ailments:
            monster.ailment_roar = ailments['roar']
            monster.ailment_wind = ailments['wind']
            monster.ailment_tremor = ailments['tremor']
            monster.ailment_defensedown = ailments['defense_down']
            monster.ailment_fireblight = ailments['fireblight']
            monster.ailment_waterblight = ailments['waterblight']
            monster.ailment_thunderblight = ailments['thunderblight']
            monster.ailment_iceblight = ailments['iceblight']
            monster.ailment_dragonblight = ailments['dragonblight']
            monster.ailment_blastblight = ailments['blastblight']
            monster.ailment_regional = ailments['regional']
            monster.ailment_poison = ailments['poison']
            monster.ailment_sleep = ailments['sleep']
            monster.ailment_paralysis = ailments['paralysis']
            monster.ailment_bleed = ailments['bleed']
            monster.ailment_stun = ailments['stun']
            monster.ailment_mud = ailments['mud']
            monster.ailment_effluvia = ailments['effluvia']

        # Create a temp base map of the conditions
        # This temp map extends the global map with monster-specific conditions
        #monster_conditions = DataMap(reward_conditions_map)
        #monster_conditions.extend(entry.get('break_conditions', []))

        # Save hunting rewards
        for reward in entry.get('rewards', []):
            condition_en = reward['condition_en']
            rank = reward['rank']
            item_name = reward['item_en']

            condition_id = monster_reward_conditions_map.id_of(
                'en', condition_en)
            item_id = item_map.id_of('en', item_name)

            item_tracker.mark_encountered_id(item_id)

            monster.rewards.append(
                db.MonsterReward(condition_id=condition_id,
                                 rank=rank,
                                 item_id=item_id,
                                 stack=reward['stack'],
                                 percentage=reward['percentage'] or 0))

        # Save Habitats
        for habitat_data in entry.get('habitats', []):
            location_name = habitat_data['map_en']
            location_id = location_map.id_of("en", location_name)
            ensure(location_id, "Invalid location name " + location_name)

            monster.habitats.append(
                db.MonsterHabitat(location_id=location_id,
                                  start_area=habitat_data['start_area'],
                                  move_area=habitat_data['move_area'],
                                  rest_area=habitat_data['rest_area']))

        # Complete - add to session
        session.add(monster)

    print("Built Monsters")
Example #3
0
def build_monsters(session: sqlalchemy.orm.Session, mhdata):
    item_map = mhdata.item_map
    location_map = mhdata.location_map
    monster_map = mhdata.monster_map
    monster_reward_conditions_map = mhdata.monster_reward_conditions_map

    # Save conditions first
    for condition_id, entry in monster_reward_conditions_map.items():
        for language in cfg.supported_languages:
            session.add(
                db.MonsterRewardConditionText(id=condition_id,
                                              lang_id=language,
                                              name=entry.name(language)))

    # Save monsters
    for order_id, entry in enumerate(monster_map.values()):
        monster = db.Monster(id=entry.id,
                             order_id=order_id,
                             size=entry['size'])

        # Save basic weakness summary data
        if 'weaknesses' in entry and entry['weaknesses']:
            monster.has_weakness = True
            weaknesses = entry['weaknesses']
            for key, value in weaknesses['normal'].items():
                setattr(monster, 'weakness_' + key, value)

            if 'alt' in weaknesses:
                monster.has_alt_weakness = True
                for key, value in weaknesses['normal'].items():
                    setattr(monster, 'alt_weakness_' + key, value)

        # Save language data
        for language in cfg.supported_languages:
            alt_state_description = None
            if 'alt_description' in entry.get('weaknesses', {}):
                alt_state_description = entry['weaknesses']['alt_description'][
                    language]

            monster.translations.append(
                db.MonsterText(lang_id=language,
                               name=entry.name(language),
                               ecology=entry['ecology'][language],
                               description=entry['description'][language],
                               alt_state_description=alt_state_description))

        # Save hitzones
        for hitzone_data in entry.get('hitzones', []):
            hitzone = db.MonsterHitzone(cut=hitzone_data['cut'],
                                        impact=hitzone_data['impact'],
                                        shot=hitzone_data['shot'],
                                        fire=hitzone_data['fire'],
                                        water=hitzone_data['water'],
                                        thunder=hitzone_data['thunder'],
                                        dragon=hitzone_data['dragon'],
                                        ko=hitzone_data['ko'])

            for lang, part_name in hitzone_data['hitzone'].items():
                hitzone.translations.append(
                    db.MonsterHitzoneText(lang_id=lang, name=part_name))

            monster.hitzones.append(hitzone)

        # Save breaks
        for break_data in entry.get('breaks', []):
            breakzone = db.MonsterBreak(flinch=break_data['flinch'],
                                        wound=break_data['wound'],
                                        sever=break_data['sever'],
                                        extract=break_data['extract'])

            for lang, part_name in break_data['part'].items():
                breakzone.translations.append(
                    db.MonsterBreakText(lang_id=lang, part_name=part_name))

            monster.breaks.append(breakzone)

        # Create a temp base map of the conditions
        # This temp map extends the global map with monster-specific conditions
        #monster_conditions = DataMap(reward_conditions_map)
        #monster_conditions.extend(entry.get('break_conditions', []))

        # Save hunting rewards
        for reward in entry.get('rewards', []):
            condition_en = reward['condition_en']
            rank = reward['rank']
            item_name = reward['item_en']

            condition_id = monster_reward_conditions_map.id_of(
                'en', condition_en)
            item_id = item_map.id_of('en', item_name)

            monster.rewards.append(
                db.MonsterReward(condition_id=condition_id,
                                 rank=rank,
                                 item_id=item_id,
                                 stack=reward['stack'],
                                 percentage=reward['percentage']))

        # Save Habitats
        for location_name, habitat_values in entry.get('habitats', {}).items():
            location_id = location_map.id_of("en", location_name)
            ensure(location_id, "Invalid location name " + location_name)

            monster.habitats.append(
                db.MonsterHabitat(location_id=location_id, **habitat_values))

        # Complete - add to session
        session.add(monster)

    print("Built Monsters")