namespace = canonisation
######################################
####### Vatican				   #######
######################################

#A character is eligible for Beatification
character_event = {
	id = canonisation.1
	hide_window = yes
	is_triggered_only = yes
	min_age = 16
    only_playable = yes
	religion_group = christian

	trigger = {
		death_in_china_trigger = no
		death_no_trace_trigger = no
		NOR = {
			trait = excommunicated
			trait = cannibal_trait
			has_claim = k_papal_state
		}
		religion = catholic
		trait = trait_canonisation
		k_papal_state = {
			holder_scope = {
				ai = no
			}
		}
	}

	immediate = {
        #Beatification
        save_event_target_as = saint_person_Vatican
        save_event_target_as = saint_person
        event_target:saint_person_Vatican = {
        	capital_scope = {
        		save_event_target_as = saint_capital_Vatican
        	}
        }
        if = {
            limit = {
                religion = catholic
            }
            random_realm_character = {
                limit = {
                    is_theocracy = yes
                    religion = event_target:saint_person_Vatican
                    trait = Eveque-Catholic
                    is_landed = yes
                }
                random = {
                    chance = 100
                    random_realm_province = {
                        province_event = { id = canonisation.2 }
                    }
                }
            }
        }
        #Potential for sainthood
	}
}

#Decision if to be Beatified
province_event = {
	id = canonisation.2
    hide_window = yes
	is_triggered_only = yes

	immediate = {
        province_event = { id = canonisation.3 days = 365 }
	}
}

#Decision has been made to be Beatified
province_event = {
    id = canonisation.3
    hide_window = yes
    is_triggered_only = yes

    immediate = {
        holder_scope = {
        	if = {
        		limit = {
        			event_target:saint_person_Vatican = {
        				religion = catholic
						trait = trait_canonisation
        			}
        		}
				k_papal_state = {
					holder_scope = {
						character_event = { id = canonisation.4 }
					}
        		}
        	}
        }
    }
}

#Pope sends out letters declaring beatification
character_event = {
    id = canonisation.4
    is_triggered_only = yes
    hide_window = yes

    immediate = {
        event_target:saint_person_Vatican = {
            add_trait = beatified
            if = {
                limit = {
                    is_female = yes
                }
                set_special_character_title = BLESSED_TITLE_FEMALE
            }
            else = {
                set_special_character_title = BLESSED_TITLE
            }
			deciding_upon_saint_effect = yes
        }
		k_papal_state = {
			holder_scope = {
				narrative_event = { id = canonisation.5 }
            }
        }
    }
}

#Papal beatification Event
narrative_event = {
    id = canonisation.5
    desc = EVTDESC_HF_40006
    title = TITLEHF.40006
    picture = GFX_evt_beatification
    border = GFX_event_narrative_frame_religion
    is_triggered_only = yes
	portrait = event_target:saint_person_Vatican
	
    option = {
        name = EVTOPTA_HF_40020
		event_target:saint_person_Vatican = {
			show_portrait = yes
        }
        if = {
            limit = {
                religion_group = christian
            }
            custom_tooltip = {
                text = pope_cannonize_choice_TT
            }
        }

        hidden_tooltip = {
            # Find Miracle - Christian only
            if = {
                limit = {
                    event_target:saint_person_Vatican = {
                        religion_group = christian
                    }
                }
                random_list = {
                    #Stigmata
                    100 = {
                        set_variable = { which = global_miracle value = 1 }
                        event_target:saint_person_Vatican = {
                            give_nickname = nick_the_god_bearing
                        }
                    }
                    #Incorruptible body
                    100 = {
                        set_variable = { which = global_miracle value = 2 }
                        event_target:saint_person_Vatican = {
                            give_nickname = nick_the_myrrh_streaming
                        }
                    }
                    #Miraculous healing
                    800 = {
                        trigger = {
                            event_target:saint_person_Vatican = {
                                trait = physician
                            }
                        }
                        set_variable = { which = global_miracle value = 3 }
                        if = {
                            limit = {
                                event_target:saint_person_Vatican = {
                                    trait = charitable
                                }
                            }
                            event_target:saint_person_Vatican = {
                                give_nickname = nick_the_unmercenary_healer
                            }
                        }
                        else = {
                            event_target:saint_person_Vatican = {
                                give_nickname = nick_the_healer
                            }
                        }
                    }
                    #Prophetic Foresight
                    200 = {
                        trigger = {
                            event_target:saint_person_Vatican = {
                                OR = {
                                    trait = mystic
                                    trait = possessed
                                }
                            }
                        }
                        set_variable = { which = global_miracle value = 4 }
                        event_target:saint_person_Vatican = {
                            give_nickname = nick_the_prophet
                        }
                    }
                    #Mindreading
                    100 = {
                        set_variable = { which = global_miracle value = 5 }
                        event_target:saint_person_Vatican = {
                            give_nickname = nick_the_understanding
                        }
                    }
                    #Exorciser
                    100 = {
                        trigger = {
                            event_target:saint_person_Vatican = {
                                trait = zealous
                            }
                        }
                        set_variable = { which = global_miracle value = 6 }
                        event_target:saint_person_Vatican = {
                            give_nickname = nick_the_righteous
                        }
                    }
                    #Angel talker
                    100 = {
                        set_variable = { which = global_miracle value = 7 }
                        event_target:saint_person_Vatican = {
                            give_nickname = nick_the_apostle
                        }
                    }
                    #Waterwalker
                    50 = {
                        set_variable = { which = global_miracle value = 8 }
                        event_target:saint_person_Vatican = {
                            give_nickname = nick_the_confessor
                        }
                    }
                    #Heard after death
                    50 = {
                        set_variable = { which = global_miracle value = 9 }
                        event_target:saint_person_Vatican = {
                            give_nickname = nick_the_venerable
                        }
                    }
                    #Creating fire
                    25 = {
                        set_variable = { which = global_miracle value = 10 }
                        event_target:saint_person_Vatican = {
                            give_nickname = nick_the_spark_of_god
                        }
                    }
                    #Praying heavy object away
                    50 = {
                        set_variable = { which = global_miracle value = 11 }
                        event_target:saint_person_Vatican = {
                            give_nickname = nick_the_right_believing
                        }
                    }
                    #Being seen after death
                    25 = {
                        trigger = {
                            event_target:saint_person_Vatican = {
                                martyrs_death_trigger = yes
                            }
                        }
                        set_variable = { which = global_miracle value = 12 }
                        event_target:saint_person_Vatican = {
                            give_nickname = nick_the_martyr
                        } 
                    }
                    #Blessing local water with the power of love
                    25 = {
                        set_variable = { which = global_miracle value = 13 }
                        event_target:saint_person_Vatican = {
                            give_nickname = nick_the_miracle_worker 
                        }
                    }
                    #Rats
                    25 = {
                        trigger = {
                            event_target:saint_person_Vatican = {
                                trait = lunatic
                            }
                        }
                        set_variable = { which = global_miracle value = 14 }
                        event_target:saint_person_Vatican = {
                            give_nickname = nick_the_fool_for_christ
                        }
                    }
                    #Wise dog
                    25 = {
                        set_variable = { which = global_miracle value = 15 }
                        event_target:saint_person_Vatican = {
                            give_nickname = nick_the_merciful 
                        }
                    }
                    #Flying
                    25 = {
                        set_variable = { which = global_miracle value = 16 }
                        event_target:saint_person_Vatican = {
                            give_nickname = nick_the_pious
                        }
                    }
                }
            }
            # Messages
            any_playable_ruler = {
                limit = {
                    NOT = {
                        family = event_target:saint_person_Vatican
                    }
                    religion = ROOT
                }
                narrative_event = { id = canonisation.6 }
            }
            event_target:saint_person_Vatican = {
                any_dynasty_member = {
                    limit = {
                        religion_group = ROOT
                    }
                    narrative_event = { id = canonisation.6 }
                }
            }
			event_target:saint_person_Vatican = {
				remove_trait = trait_canonisation
			}
            ROOT = {
                narrative_event = { id = canonisation.6 }
            }
            # Trait change
            event_target:saint_person_Vatican = {
                if = {
                    limit = {
                        religion_group = christian
                    }
                    remove_trait = beatified
                    add_trait = saint   
                    if = {
                        limit = {
                            is_female = yes
                        }
                        set_special_character_title = SAINT_TITLE_FEMALE
                    }
                    else = {
                        set_special_character_title = SAINT_TITLE
                    }
                }
            }
            # Burial Site setting - Christian only
            if = {
                limit = {
                    event_target:saint_person_Vatican = {
                        religion_group = christian
                    }
                }
                #Confirm that a burial site exists, for pilgrimage
                set_global_flag = saintly_burial_sites_exist
                event_target:saint_capital_Vatican = {
                    owner = {
                        save_event_target_as = saint_capital_Vatican_owner
                    }
                }
                if = {
                    limit = {
                        NOR = {
                            event_target:saint_capital_Vatican = {
                                has_province_modifier = tomb_of_a_saint
                            }
                            event_target:saint_capital_Vatican = {
                                has_province_modifier = pillaged_tomb_of_a_saint
                            }
                        }
                    }
                    event_target:saint_capital_Vatican = {
                        setting_up_saintly_burial_site_effect = yes
                    }
                }
                else_if = {
                    limit = {
                        event_target:saint_capital_Vatican = {
                            any_neighbor_province = {
                                owner = {
                                    character = event_target:saint_capital_Vatican_owner
                                }
                                NOR = {
                                    has_province_modifier = tomb_of_a_saint
                                    has_province_modifier = pillaged_tomb_of_a_saint
                                }
                            }
                        }
                    }
                    event_target:saint_capital_Vatican = {
                        random_neighbor_province = {
                            limit = {
                                owner = {
                                    character = event_target:saint_capital_Vatican_owner
                                }
                                NOR = {
                                    has_province_modifier = tomb_of_a_saint
                                    has_province_modifier = pillaged_tomb_of_a_saint
                                }
                            }
                            setting_up_saintly_burial_site_effect = yes
                        }
                    }
                }
                else_if = {
                    limit = {
                        NOR = {
                            event_target:random_saint_demesne_province = {
                                has_province_modifier = tomb_of_a_saint
                            }
                            event_target:random_saint_demesne_province = {
                                has_province_modifier = pillaged_tomb_of_a_saint
                            }
                        }
                    }
                    event_target:random_saint_demesne_province = {
                        setting_up_saintly_burial_site_effect = yes
                    }
                }
                else_if = {
                    limit = {
                        NOR = {
                            event_target:random_saint_realm_province = {
                                has_province_modifier = tomb_of_a_saint
                            }
                            event_target:random_saint_realm_province = {
                                has_province_modifier = pillaged_tomb_of_a_saint
                            }
                        }
                    }
                    event_target:random_saint_realm_province = {
                        setting_up_saintly_burial_site_effect = yes             
                    }
                }
            }
            # Bloodline creation
            random_list = {
                20 = {
                    trigger = {
                        event_target:saint_person_Vatican = {
                            OR = {
                                trait = zealous
                                trait = holy_warrior
                            }
                        }
                    }
                    event_target:saint_person_Vatican = {
                        if = {
                            limit = {
                                religion = catholic
                            }
                            create_bloodline = {
                                type = saintly_bloodline_catholic_01
                                religion = event_target:saint_person_Vatican
                                inheritance = patrilineal
                            }
                        }
                        if = {
                            limit = {
                                event_target:saint_person_Vatican = {
                                    religion_group = christian
                                }
                            }
                            new_bloodline = {
                                set_name = saintly_bloodline_name
                                set_description = saintly_bloodline_description
                            }
                        }
                    }
                }
                20 = {
                    trigger = {
                        has_dlc = "Mystics"
                        OR = {
                            event_target:saint_person_Vatican = {
                                trait = celibate
                            }
                            event_target:saint_person_Vatican = {
                                trait = monk
                            }
                            event_target:saint_person_Vatican = {
                                trait = nun
                            }
                        }
                        event_target:saint_person_Vatican = {
                            religion_group = christian
                        }
                    }
                    event_target:saint_person_Vatican = {
                         if = {
                            limit = {
                                religion = catholic
                            }
                            create_bloodline = {
                                type = saintly_bloodline_catholic_02
                                religion = event_target:saint_person_Vatican
                                inheritance = patrilineal
                            }
                        }
                        if = {
                            limit = {
                                event_target:saint_person_Vatican = {
                                    religion_group = christian
                                }
                            }
                            new_bloodline = {
                                set_name = saintly_bloodline_name
                                set_description = saintly_bloodline_description
                            }
                        }
                    }
                }
                5 = {
                    event_target:saint_person_Vatican = {
                        if = {
                            limit = {
                                religion = catholic
                            }
                            create_bloodline = {
                                type = saintly_bloodline_catholic_03
                                religion = event_target:saint_person_Vatican
                                inheritance = patrilineal
                            }
                        }
                        if = {
                            limit = {
                                event_target:saint_person_Vatican = {
                                    religion_group = christian
                                }
                            }
                            new_bloodline = {
                                set_name = saintly_bloodline_name
                                set_description = saintly_bloodline_description
                            }
                        }
                    }
                }
                5 = {
                    modifier = {
                        factor = 4
                        OR = {
                            event_target:saint_person_Vatican = {
                                trait = zealous
                            }
                            event_target:saint_person_Vatican = {
                                trait = holy_warrior
                            }
                        }
                    }
                    event_target:saint_person_Vatican = {
                        if = {
                            limit = {
                                religion = catholic
                            }
                            create_bloodline = {
                                type = saintly_bloodline_catholic_04
                                religion = event_target:saint_person_Vatican
                                inheritance = patrilineal
                            }
                        }
                        if = {
                            limit = {
                                event_target:saint_person_Vatican = {
                                    religion_group = christian
                                }
                            }
                            new_bloodline = {
                                set_name = saintly_bloodline_name
                                set_description = saintly_bloodline_description
                            }
                        }
                    }
                }
                30 = {
                    trigger = {
                        event_target:saint_person_Vatican = {
                            trait = sympathy_judaism
                        }
                    }
                    event_target:saint_person_Vatican = {
                        if = {
                            limit = {
                                religion = catholic
                            }
                            create_bloodline = {
                                type = saintly_bloodline_catholic_05
                                religion = event_target:saint_person_Vatican
                                inheritance = patrilineal
                            }
                        }
                        if = {
                            limit = {
                                event_target:saint_person_Vatican = {
                                    religion_group = christian
                                }
                            }
                            new_bloodline = {
                                set_name = saintly_bloodline_name
                                set_description = saintly_bloodline_description
                            }
                        }
                    }
                }
                5 = {
                    event_target:saint_person_Vatican = {
                        if = {
                            limit = {
                                religion = catholic
                            }
                            create_bloodline = {
                                type = saintly_bloodline_catholic_06
                                religion = event_target:saint_person_Vatican
                                inheritance = patrilineal
                            }
                        }
                        if = {
                            limit = {
                                event_target:saint_person_Vatican = {
                                    religion_group = christian
                                }
                            }
                            new_bloodline = {
                                set_name = saintly_bloodline_name
                                set_description = saintly_bloodline_description
                            }
                        }
                    }
                }
            }
        }

        ai_chance = {
            factor = 1
        }
    }
	option = {
		name = EVTOPTB_HF_40020
	#	event_target:saint_person_Vatican = { # deja présent
	#		show_portrait = yes
    #    }
		event_target:saint_person_Vatican = {
			remove_trait = beatified
			remove_trait = trait_canonisation
			remove_special_character_title = BLESSED_TITLE_FEMALE
			remove_special_character_title = BLESSED_TITLE
		}
		ai_chance = {
			factor = 0
		}
    }
}

#Canonization Official
narrative_event = {
    id = canonisation.6
    desc = {
        trigger = {
            event_target:saint_person_Vatican = {
                religion_group = christian
            }
        }
        text = EVTDESC_HF_40025
        picture = GFX_evt_beatification
    }
    title = EVTTITLE_HF_40025
    portrait = event_target:saint_person_Vatican
	picture = GFX_evt_beatification
	border = GFX_event_narrative_frame_religion
    is_triggered_only = yes
    
    immediate = {
        if = {
            limit = {
                event_target:saint_person_Vatican = {
                    religion_group = christian
                }
            }
            sound_effect = saint_proclaimed
        }
        opinion = {
            name = opinion_very_grateful_donation
            who = FROM
            years = 30
        }
    }

    option = {      
        name = EVTOPTA_HF_40025
        show_portrait = FROM
        if = {
            limit = {
                event_target:saint_person_Vatican = {
                    family = ROOT
                }
            }
            piety = 100
            if = {
                limit = {
                    religion_group = christian
                }
                custom_tooltip = { text = TT_CANONIZATION_FAMILY }
            }
        }
    }
}
######################################################################################
#Vatican patch fixed vanilla
character_event = {
	id = canonisation.7
	hide_window = yes
	only_rulers = yes
	mean_time_to_happen = { 
		days = 1
	}
	trigger = {
		trait = trait_canonisation
		OR = {
			trait = excommunicated
			tier = BARON
			is_landed = no
			NOT = {
				religion = catholic
			}
			any_liege = {
				has_claim = k_papal_state
			}
			has_claim = k_papal_state
			any_vassal = {
				has_claim = k_papal_state
			}
			top_liege = {
				any_realm_character = {
					has_claim = k_papal_state
				}
			}
		}
	}
	immediate = {
		remove_trait = trait_canonisation
	}
}

character_event = {
	id = canonisation.8
	hide_window = yes
	is_triggered_only = yes	
	only_rulers = yes
	trigger = {
		trait = trait_canonisation
		OR = {
			trait = excommunicated
			tier = BARON
			is_landed = no
			NOT = {
				religion = catholic
			}
			any_liege = {
				has_claim = k_papal_state
			}
			has_claim = k_papal_state
			any_vassal = {
				has_claim = k_papal_state
			}
			top_liege = {
				any_realm_character = {
					has_claim = k_papal_state
				}
			}
		}
	}
	immediate = {
		remove_trait = trait_canonisation
	}
}

character_event = {
	id = canonisation.9
	hide_window = yes
	only_rulers = yes
	mean_time_to_happen = { 
		days = 1
	}
	trigger = {
		trait = trait_canonisation
		is_landed = no
	}
	immediate = {
		remove_trait = trait_canonisation
	}
}

character_event = {
	id = canonisation.10
	hide_window = yes
	is_triggered_only = yes	
	only_rulers = yes
	trigger = {
		trait = trait_canonisation
		is_landed = no
	}
	immediate = {
		remove_trait = trait_canonisation
	}
}
######################################################################################