﻿# On very rare occasion, one of your courtiers which is on good terms with you could suggest to adopt your bastard, that was born from one of your close relatives, if it is possible.
# In that case, your bastard would not be considered as your child, but as his.
# This courtier should be patrilineary married, not landed, a noble, but not from your house, and not one of your relatives. His wife also should not be one of your relatives.

namespace = adoption_familyromance


adoption_familyromance.0001 = {
    type = character_event
    title = fr_adoption_familyromance.1001.t

    desc = {
		desc = fr_adoption_familyromance.1001.desc
	}

    theme = bastardy

    override_background = {
		reference = council_chamber
	}

    left_portrait = {
		character = scope:familiromance_courtier_who_wants_adoption
		animation = personality_honorable
	}	

	right_portrait = {
		character = root
		animation = personality_rational
	}

    lower_left_portrait = {
		character = scope:familiromance_bastard_from_close_family
	}
	
	cooldown = { years = 100 }

    trigger = {
        is_ai = no
        NOT = { 
			has_game_rule = no_adoption
		}

        any_child = {
            is_adult = no
			is_available_ai_child = yes
		    exists = real_father
		    exists = mother
            real_father = root            
            is_courtier_of = root
            is_ruler = no
            house = root.house

            mother = {
                is_close_family_of = root
            }
            
            age < 10
		    has_trait = bastard
		}

        any_courtier = {
			is_available_ai_adult = yes
            is_male = yes
            is_married = yes
            NOT = { is_close_or_extended_family_of = root }
            is_lowborn = no
            is_ruler = no
            patrilinear_marriage = yes
            NOT = { house = root.house }
            familyromance_character_not_rival = yes
            opinion = {
				value >= low_positive_opinion
				target = root
			}
            
            primary_spouse = {
                NOT = { is_close_or_extended_family_of = root }
            }
		}
    }


    immediate = {
        random_child = {
            limit = {
                is_adult = no
                is_available_ai_child = yes
                exists = real_father
                real_father = root
		        exists = mother
                is_courtier_of = root
                is_ruler = no
                                
                house = root.house

                mother = {
                    is_close_family_of = root
                }
            
                age < 10
		        has_trait = bastard
            }
            save_scope_as = familiromance_bastard_from_close_family
        }
		
		scope:familiromance_bastard_from_close_family.mother = { save_scope_as = familiromance_bastards_mother }

        random_courtier = {
            limit = {
                is_available_ai_adult = yes
                is_male = yes
                is_married = yes
                NOT = { is_close_or_extended_family_of = root }
                is_lowborn = no
                is_ruler = no
                patrilinear_marriage = yes
                NOT = { house = root.house }
                familyromance_character_not_rival = yes
                opinion = {
                    value >= low_positive_opinion
                    target = root
			    }
                
                primary_spouse = {
                    NOT = { is_close_or_extended_family_of = root }
                }
            }
            save_scope_as = familiromance_courtier_who_wants_adoption
        }
    }

    # Yes, adopt the bastard of mine
    option = {
        name = fr_adoption_familyromance.1001.a
        custom_tooltip = fr_adoption_familyromance.1001.a.t
        
        play_music_cue = "mx_cue_touching_moment"
        adopt_effect = {
            CHILD = scope:familiromance_bastard_from_close_family
            ADOPTER = scope:familiromance_courtier_who_wants_adoption
        }

        scope:familiromance_courtier_who_wants_adoption = {
            create_character_memory = {
                type = adopted_a_child
                participants = {
                    child = scope:familiromance_bastard_from_close_family
                }
            }
            
            add_piety = medium_piety_gain
        }
        scope:familiromance_bastard_from_close_family = {
            create_character_memory = {
                type = was_adopted
                participants = {
                    parent = scope:familiromance_courtier_who_wants_adoption
                }
            }
        }            

        add_piety = major_piety_gain
        add_prestige = minor_prestige_gain
		root.dynasty = {
			add_dynasty_prestige = minor_dynasty_prestige_gain
		}
    }

    # No, it's my child
    option = {
        name = fr_adoption_familyromance.1001.b
    }


}


