﻿namespace = magic_seer_event

#################################
#          Dreams Event         #
#################################

magic_seer_event.9000 = {  # "Recurring Dreams" #
    type = character_event
    title = magic_seer_event.9000.t  # "Recurring Dreams" #
    desc = magic_seer_event.9000.d   # "You are plagued by vivid, mysterious dreams..." #
    override_background = { reference = bedchamber_log }

    trigger = {
        is_ai = no
        has_global_variable = log_title
        NOR = {
            has_trait = god_blood
            has_trait = demi_god
            has_trait = angel_full_god
            has_trait = fallen_god
            has_trait = angel_blood
            has_trait = angel
            has_trait = dark_angel
            has_trait = archangel
            has_trait = dark_archangel
            has_trait = young_god_light
            has_trait = young_god_dark

            has_character_modifier = seer_dreams_mod       # "Recurring Dreams" (modifier) #
            has_character_modifier = seer_visits_mod       # "Visited by the Seer" #
            has_character_modifier = seer_training_1_mod   # "Seer's Training: The First Step" #
            has_character_modifier = seer_training_2_mod   # "Seer's Training: Awakening" #
            has_character_modifier = seer_training_3_mod   # "Seer's Training: Godbound" #
            has_character_modifier = has_personal_seer_mod # "Personal Seer" #
        }
        age >= 16
    }

    immediate = {
        add_character_modifier = {
            modifier = seer_dreams_mod  # "Recurring Dreams" (modifier applied on trigger) #
        }
    }

    right_portrait = {
        character = root
        animation = worry
    }

    option = {
        name = OK_1  # "These dreams are not mine alone..."
        
        add_learning_skill = 2
        stress_impact = {
            base = medium_stress_impact_gain
            zealous = minor_stress_impact_loss
            patient = minor_stress_impact_loss
            cynical = minor_stress_impact_gain
            callous = minor_stress_impact_gain
        }
    }

    option = {
        name = OK_2  # "Each night it grows clearer..."

        add_stewardship_skill = 2
        stress_impact = {
            base = medium_stress_impact_gain
            diligent = minor_stress_impact_loss
            ambitious = minor_stress_impact_loss
            lazy = minor_stress_impact_gain
            arbitrary = minor_stress_impact_gain
        }
    }

    option = {
        name = OK_3  # "Perhaps it's a sign..."

        add_diplomacy_skill = 2
        stress_impact = {
            base = minor_stress_impact_gain
            content = miniscule_stress_impact_loss
            trusting = minor_stress_impact_loss
            compassionate = minor_stress_impact_loss
            paranoid = minor_stress_impact_gain
        }
    }

    option = {
        name = OK_4  # "If something seeks me..."

        add_intrigue_skill = 2
        stress_impact = {
            base = medium_stress_impact_gain
            ambitious = minor_stress_impact_loss
            brave = minor_stress_impact_loss
            paranoid = minor_stress_impact_loss
            humble = minor_stress_impact_gain
        }
    }

    option = {
        name = OK_5  # "It feels ancient, immense..."

        add_martial_skill = 2
        stress_impact = {
            base = medium_stress_impact_gain
            temperate = minor_stress_impact_loss
            patient = minor_stress_impact_loss
            craven = medium_stress_impact_gain
            arrogant = minor_stress_impact_gain
        }
    }
}

#################################
#        Meet Seer Event        #
#################################

magic_seer_event.0001 = {  # "An Unexpected Visitor" #
    type = character_event
    title = magic_seer_event.0001.t  # "An Unexpected Visitor" #
    desc = magic_seer_event.0001.d   # "While traveling through a quiet meadow..." #
    override_background = { reference = ep2_hunt_foggy_forest_log }

    trigger = {
        is_ai = no
        has_character_modifier = seer_dreams_mod       # "Recurring Dreams" #
        NOT = { has_character_modifier = seer_visits_mod }  # "Visited by the Seer" #
        age >= 18
    }

    weight_multiplier = {
        base = 100

        modifier = {
            factor = 0
            NOT = { has_character_modifier = seer_dreams_mod }
        }

        modifier = {
            factor = 1.0
            has_character_modifier = seer_dreams_mod
        }
    }

    immediate = {
        
        # Check if the seer already exists in the court
        if = {
            limit = {
                NOT = {
                    any_courtier = { has_character_flag = is_the_seer }
                }
            }

            # Create a new Seer only if one isn't already present
            create_character = {
                save_scope_as = seer_character
                template = magic_seer_character_template
                name = Magic_Seer
                dynasty = none
                gender = male
                age = { 55 70 }
                location = root.capital_province
            }

            scope:seer_character = {
                add_character_flag = is_the_seer
            }
            
            set_global_variable = {
                name = log_seer
                value = scope:seer_character
            }
        }

        # Store reference to the Seer (either new or existing)
        if = {
            limit = {
                any_courtier = { has_character_flag = is_the_seer }
            }

            # Save existing Seer
            random_courtier = {
                limit = { has_character_flag = is_the_seer }
                save_scope_as = seer_character
            }
        }

        # Always apply the same player effects
        add_character_modifier = {
            modifier = seer_visits_mod
        }
        remove_character_modifier = seer_dreams_mod
    }

    left_portrait = {
        character = scope:seer_character
        animation = chaplain
    }

    right_portrait = {
        character = root
        animation = eyeroll
    }

    option = {
        name = magic_seer_event.0001.a  # "Go away." #
        remove_courtier_or_guest = scope:seer_character

        stress_impact = {
            base = minor_stress_impact_gain
            cynical = minor_stress_impact_loss
            arrogant = minor_stress_impact_loss
            compassionate = minor_stress_impact_gain
            trusting = minor_stress_impact_gain
        }
    }

    option = {
        name = magic_seer_event.0001.b  # "Join my Court." #
        add_courtier = scope:seer_character
        add_character_modifier = {
            modifier = has_personal_seer_mod  # "Personal Seer" #
        }
        stress_impact = {
            base = medium_stress_impact_gain
            forgiving = minor_stress_impact_loss
            compassionate = minor_stress_impact_loss
            callous = minor_stress_impact_gain
            arrogant = minor_stress_impact_gain
        }
    }

    option = {
        name = magic_seer_event.0001.c  # "Start Event Chain." #
        add_courtier = scope:seer_character
        add_character_modifier = {
            modifier = seer_training_1_mod    # "Seer's Training: The First Step" #
        }
        add_character_modifier = {
            modifier = has_personal_seer_mod  # "Personal Seer" #
        }
        remove_character_modifier = seer_visits_mod     # "Visited by the Seer" #
        trigger_event = { id = magic_seer_event.0002 }  # "The Seer's Offer" #
        stress_impact = {
            base = medium_stress_impact_gain
            zealous = minor_stress_impact_loss
            curious = minor_stress_impact_loss
            paranoid = minor_stress_impact_gain
            cynical = minor_stress_impact_gain
        }
    }
}

#################################
#    Seer Training Event 01     #
#################################

magic_seer_event.0010 = {  # "The Seer's Invitation" #
    type = character_event
    title = magic_seer_event.0010.t  # "The Seer's Invitation" #
    desc = magic_seer_event.0010.d   # "The Magic Seer, now quietly observing you..." #
    override_background = { reference = wilderness_forest }

    trigger = {
        is_ai = no
        has_character_modifier = seer_visits_mod         # "Visited by the Seer" #
        has_character_modifier = has_personal_seer_mod   # "Personal Seer" #
    }

    immediate = {
        global_var:log_seer = {
            save_scope_as = seer_character
        }
    }

    left_portrait = {
        character = scope:seer_character
        animation = chaplain
    }

    right_portrait = {
        character = root
        animation = thinking
    }

    option = {
        name = magic_seer_event.0010.a  # "Yes. I am ready to begin the path." #
        add_character_modifier = {
            modifier = seer_training_1_mod              # "Seer's Training: The First Step" #
        }
        stress_impact = {
           base = minor_stress_impact_gain
            zealous = miniscule_stress_impact_loss
            ambitious = minor_stress_impact_loss
            content = minor_stress_impact_gain
            chaste = minor_stress_impact_gain
        }
        remove_character_modifier = seer_visits_mod     # "Visited by the Seer" #
    }

    option = {
        name = magic_seer_event.0010.b  # "No. Not yet." #
        stress_impact = {
            base = medium_stress_impact_loss
            diligent = minor_stress_impact_gain
            impatient = minor_stress_impact_gain
            content = minor_stress_impact_loss
            calm = minor_stress_impact_loss
        }
    }

    option = {
        name = magic_seer_event.0010.c  # "No, I have tolerated your presence long enough!" #
        remove_courtier_or_guest = scope:seer_character
        stress_impact = {
           base = medium_stress_impact_gain
            compassionate = minor_stress_impact_gain
            forgiving = minor_stress_impact_gain
            callous = minor_stress_impact_loss
            arrogant = minor_stress_impact_loss
            vengeful = miniscule_stress_impact_loss
        }

        remove_character_modifier = seer_dreams_mod      # "Recurring Dreams" #
        remove_character_modifier = seer_training_1_mod  # "Seer's Training: The First Step" #
        remove_character_modifier = seer_training_2_mod  # "Seer's Training: Awakening" #
        remove_character_modifier = seer_training_3_mod  # "Seer's Training: Godbound" #
        remove_character_modifier = has_personal_seer_mod  # "Personal Seer" #
    }
}

#################################
#    Seer Training Event 02     #
#################################

magic_seer_event.0002 = {  # "The Sensing Trial" #
    type = character_event
    title = magic_seer_event.0002.t  # "The Sensing Trial" #
    desc = magic_seer_event.0002.d   # "The Seer stands in the quiet field..." #
    override_background = { reference = riverside_log }
    
    trigger = {
        is_ai = no
        has_character_modifier = seer_training_1_mod     # "Seer's Training: The First Step" #
        has_character_modifier = has_personal_seer_mod   # "Personal Seer" #
    }

    immediate = {
        global_var:log_seer = {
            save_scope_as = seer_character
        }
    }

    left_portrait = {
        character = scope:seer_character
        animation = chaplain  # Replaces invalid "preach"
    }

    right_portrait = {
        character = root
        animation = thinking
    }

    option = {
        name = magic_seer_event.0002.a  # "Focus with everything I have." #
        add_stress = 40
        random = {
            chance = 80
            add_learning_skill = 1
            add_martial_skill = 1
            remove_character_modifier = seer_training_1_mod  # "Seer's Training: The First Step" #
            add_character_modifier = seer_training_2_mod     # "Seer's Training: Awakening" #
        }
    }

    option = {
        name = magic_seer_event.0002.b  # "I'll trust my instincts." #
        add_stress = 20
        random = {
            chance = 50
            remove_character_modifier = seer_training_1_mod
            add_character_modifier = seer_training_2_mod
        }
    }

    option = {
        name = magic_seer_event.0002.c  # "Now's not the best time..." #
        add_stress = -25
        random = {
            chance = 1
            remove_character_modifier = seer_training_1_mod
            add_character_modifier = seer_training_2_mod
        }
    }
}

#################################
#    Seer Training Event 03     #
#################################

magic_seer_event.0003 = {  # "Awakening" #
    type = character_event
    title = magic_seer_event.0003.t  # "Awakening" #
    desc = magic_seer_event.0003.d   # "The Seer stands firm in the firelit chamber..." #
    override_background = { reference = sittingroom_log }

    trigger = {
        is_ai = no
        has_character_modifier = seer_training_2_mod     # "Seer's Training: Awakening" #
        has_character_modifier = has_personal_seer_mod   # "Personal Seer" #
    }

    immediate = {
        global_var:log_seer = {
            save_scope_as = seer_character
        }
    }

    left_portrait = {
        character = scope:seer_character
        animation = personality_compassionate
    }

    right_portrait = {
        character = root
        animation = war_over_win
    }

    option = {
        name = magic_seer_event.0003.a  # "I draw from within. All of it." #
        random = {
            chance = 80
            add_intrigue_skill = 1
            add_stewardship_skill = 1
            remove_character_modifier = seer_training_2_mod  # "Seer's Training: Awakening" #
            add_character_modifier = seer_training_3_mod     # "Seer's Training: Godbound" #
        }
        stress_impact = {
            base = medium_stress_impact_gain
            ambitious = minor_stress_impact_loss
            brave = minor_stress_impact_loss
            wrathful = minor_stress_impact_loss
            calm = medium_stress_impact_gain
            patient = minor_stress_impact_gain
            humble = minor_stress_impact_gain
        }
    }

    option = {
        name = magic_seer_event.0003.b  # "Let the energy move through me naturally." #
        random = {
            chance = 50
            remove_character_modifier = seer_training_2_mod
            add_character_modifier = seer_training_3_mod
        }
        stress_impact = {
            base = minor_stress_impact_gain
            calm = minor_stress_impact_loss
            content = minor_stress_impact_loss
            temperate = minor_stress_impact_loss
            impatient = minor_stress_impact_gain
            wrathful = minor_stress_impact_gain
        }
    }

    option = {
        name = magic_seer_event.0003.c  # "This pressure... it's too much right now." #
        random = {
            chance = 25
            remove_character_modifier = seer_training_2_mod
            add_character_modifier = seer_training_3_mod
        }
        stress_impact = {
            base = miniscule_stress_impact_gain
            craven = minor_stress_impact_loss
            humble = minor_stress_impact_loss
            patient = minor_stress_impact_loss
            brave = medium_stress_impact_gain
            ambitious = minor_stress_impact_gain
            arrogant = minor_stress_impact_gain
        }
    }
}

#################################
#    Seer Training Event 04     #
#################################

magic_seer_event.0004 = {  # "The Final Trial" #
    type = character_event
    title = magic_seer_event.0004.t  # "The Final Trial" #
    desc = magic_seer_event.0004.d   # "Choose how your path ends..." #
    override_background = { reference = godbound_log }

    trigger = {
        is_ai = no
        has_character_modifier = seer_training_3_mod   # "Seer's Training: Godbound" #
        has_character_modifier = has_personal_seer_mod # "Personal Seer" #
    }

    immediate = {
        global_var:log_seer = {
            save_scope_as = seer_character
        }
    }

    left_portrait = {
        character = scope:seer_character
        animation = go_to_your_room  # Seer calmly awaits the decision #
    }

    right_portrait = {
        character = root
        animation = thinking  # Player is empowered and resolute #
    }

    option = {
        name = magic_seer_event.0004.option_a  # "Step into the Light" #
        remove_character_modifier = seer_training_3_mod
        add_trait = young_god_light
        add_character_flag = flag_became_young_god_light
        add_character_flag = divine_eye_gold
        trigger_event = { id = magic_seer_event.0005 }  # Light aftermath #
    }

    option = {
        name = magic_seer_event.0004.option_b  # "Accept the Darkness" #
        remove_character_modifier = seer_training_3_mod
        add_trait = young_god_dark
        add_character_flag = flag_became_young_god_dark
        add_character_flag = divine_eye_frenzy
        trigger_event = { id = magic_seer_event.0006 }  # Dark aftermath #
    }

    option = {
        name = magic_seer_event.0004.option_c  # "Let fate decide" #
        custom_tooltip = magic_seer_event.0004.option_c.tooltip
        remove_character_modifier = seer_training_3_mod

        hidden_effect = {
            # Initialize score variable #
            set_variable = { name = total_trait_score value = 0 }

            # Good traits (weighted positively) #
            if = { limit = { has_trait = brave } change_variable = { name = total_trait_score add = 2 } }
            if = { limit = { has_trait = calm } change_variable = { name = total_trait_score add = 1 } }
            if = { limit = { has_trait = chaste } change_variable = { name = total_trait_score add = 1 } }
            if = { limit = { has_trait = compassionate } change_variable = { name = total_trait_score add = 2 } }
            if = { limit = { has_trait = content } change_variable = { name = total_trait_score add = 1 } }
            if = { limit = { has_trait = diligent } change_variable = { name = total_trait_score add = 2 } }
            if = { limit = { has_trait = forgiving } change_variable = { name = total_trait_score add = 1 } }
            if = { limit = { has_trait = generous } change_variable = { name = total_trait_score add = 2 } }
            if = { limit = { has_trait = gregarious } change_variable = { name = total_trait_score add = 2 } }
            if = { limit = { has_trait = honest } change_variable = { name = total_trait_score add = 1 } }
            if = { limit = { has_trait = humble } change_variable = { name = total_trait_score add = 1 } }
            if = { limit = { has_trait = just } change_variable = { name = total_trait_score add = 2 } }
            if = { limit = { has_trait = patient } change_variable = { name = total_trait_score add = 2 } }
            if = { limit = { has_trait = temperate } change_variable = { name = total_trait_score add = 2 } }
            if = { limit = { has_trait = trusting } change_variable = { name = total_trait_score add = 1 } }

            # Bad traits (weighted negatively) #
            if = { limit = { has_trait = ambitious } change_variable = { name = total_trait_score subtract = 2 } }
            if = { limit = { has_trait = arbitrary } change_variable = { name = total_trait_score subtract = 2 } }
            if = { limit = { has_trait = arrogant } change_variable = { name = total_trait_score subtract = 2 } }
            if = { limit = { has_trait = callous } change_variable = { name = total_trait_score subtract = 2 } }
            if = { limit = { has_trait = craven } change_variable = { name = total_trait_score subtract = 2 } }
            if = { limit = { has_trait = deceitful } change_variable = { name = total_trait_score subtract = 1 } }
            if = { limit = { has_trait = gluttonous } change_variable = { name = total_trait_score subtract = 1 } }
            if = { limit = { has_trait = greedy } change_variable = { name = total_trait_score subtract = 1 } }
            if = { limit = { has_trait = impatient } change_variable = { name = total_trait_score subtract = 1 } }
            if = { limit = { has_trait = lazy } change_variable = { name = total_trait_score subtract = 2 } }
            if = { limit = { has_trait = lustful } change_variable = { name = total_trait_score subtract = 2 } }
            if = { limit = { has_trait = paranoid } change_variable = { name = total_trait_score subtract = 1 } }
            if = { limit = { has_trait = shy } change_variable = { name = total_trait_score subtract = 1 } }
            if = { limit = { has_trait = vengeful } change_variable = { name = total_trait_score subtract = 1 } }
            if = { limit = { has_trait = wrathful } change_variable = { name = total_trait_score subtract = 2 } }

            # Final outcome: score > 0 = Light, < 0 = Dark, = 0 = Random #
            if = {
                limit = { var:total_trait_score > 0 }
                add_trait = young_god_light
                add_character_flag = flag_became_young_god_light
                add_character_flag = divine_eye_gold
                trigger_event = { id = magic_seer_event.0005 }
            }
            else_if = {
                limit = { var:total_trait_score < 0 }
                add_trait = young_god_dark
                add_character_flag = flag_became_young_god_dark
                add_character_flag = divine_eye_frenzy
                trigger_event = { id = magic_seer_event.0006 }
            }
            else = {
                random_list = {
                    50 = {
                        add_trait = young_god_light
                        add_character_flag = flag_became_young_god_light
                        add_character_flag = divine_eye_gold
                        trigger_event = { id = magic_seer_event.0005 }
                    }
                    50 = {
                        add_trait = young_god_dark
                        add_character_flag = flag_became_young_god_dark
                        add_character_flag = divine_eye_frenzy
                        trigger_event = { id = magic_seer_event.0006 }
                    }
                }
            }

            # Reset temporary variable #
            remove_variable = total_trait_score
        }
    }

    option = {
        name = magic_seer_event.0004.option_d  # "Refuse godhood, keep the Seer" #
        custom_tooltip = magic_seer_event.0004.option_d.tooltip
        remove_character_modifier = seer_training_3_mod
        add_character_flag = flag_denied_godhood

        # Make Seer a best friend #
        set_relation_best_friend = {
            target = scope:seer_character
            reason = magic_seer_bond
        }
    }
}

magic_seer_event.0005 = {  # "Dawn of Ascension" #
    type = character_event
    title = magic_seer_event.0005.t  # "Dawn of Ascension" #
    desc = magic_seer_event.0005.d   # "You are a promise — a new age begins." #
    override_background = { reference = godbound_light_log }

    trigger = {
        has_trait = young_god_light  # Triggered only for Light outcome #
    }

    right_portrait = {
        character = root
        animation = survey_staff  # You appear triumphant and radiant #
    }

    option = {
        name = magic_seer_event.0005.a  # "Let them see the light." #
        add_character_flag = become_full_god_light
    }
}

magic_seer_event.0006 = {  # "The Unmaking Begins" #
    type = character_event
    title = magic_seer_event.0006.t  # "The Unmaking Begins" #
    desc = magic_seer_event.0006.d   # "Power festers — no turning back." #
    override_background = { reference = godbound_dark_log }

    trigger = {
        has_trait = young_god_dark  # Triggered only for Dark outcome #
    }

    right_portrait = {
        character = root
        animation = manic  # You loom with ominous, divine menace #
    }

    option = {
        name = magic_seer_event.0006.a  # "Let them kneel or burn." #
        add_character_flag = become_full_god_dark
    }
}
