namespace = HF

# Written by Joachim
# HF.40100 - HF.40199

# Check if a character is eligible for Worshipping
character_event = {
	id = HF.40100

	is_triggered_only = yes # on_death
	hide_window = yes

	only_playable = yes
	has_dlc = "Holy Fury"
	min_age = 16

	trigger = {
		death_in_china_trigger = no
		death_no_trace_trigger = no
		prestige >= 1000

		OR = {
			has_religion_feature = religion_beatification
			has_religion_feature = religion_feature_egyptian
		}

		OR = {
			has_religion_feature = religion_temporal_head
			has_religion_feature = religion_theocratic_head
			has_religion_feature = religion_autocephaly
		}
	}

	immediate = {
		save_event_target_as = saint_person
		check_if_ancestor_worship_worthy_effect = yes
	}
}

# Religious Head is notified about potential Ancestor material
character_event = {
	id = HF.40101
	desc = EVTDESC_HF_40020_B
	picture = GFX_evt_council
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes # check_if_ancestor_worship_worthy_effect, through HF.40100

	immediate = {
		sound_effect = saint_proclaimed
		save_event_target_as = canonizer_person
	}

	option = {
		name = EVTOPTA_HF_40020

		custom_tooltip = {
			text = pagan_pope_cannonize_choice_TT

			# Titles and Bloodlines
			event_target:saint_person = {
				set_special_character_title = BLESSED_TITLE

				random_list = {
					10 = {
						mult_modifier = {
							factor = 0.4

							any_owned_bloodline = {
								has_bloodline_flag = bloodline_heroes
								bloodline_is_active_for = PREV
							}
						}

						if = {
							limit = { is_female = yes }

							create_bloodline = {
								type = ancestor_worship_bloodline_01
								religion = event_target:saint_person
								inheritance = matrilineal
							}
						}
						else = {
							create_bloodline = {
								type = ancestor_worship_bloodline_01
								religion = event_target:saint_person
							}
						}

						if = {
							limit = { can_apply_average_nickname_trigger = yes }
							give_nickname = nick_the_great
						}
					}

					30 = {
						trigger = {
							OR = {
								trait = bastard
								trait = legit_bastard
							}
						}

						mult_modifier = {
							factor = 0.1

							any_owned_bloodline = {
								has_bloodline_flag = bloodline_legitimize
								bloodline_is_active_for = PREV
							}
						}

						if = {
							limit = { is_female = yes }

							create_bloodline = {
								type = ancestor_worship_bloodline_02
								religion = event_target:saint_person
								inheritance = matrilineal
							}
						}
						else = {
							create_bloodline = {
								type = ancestor_worship_bloodline_02
								religion = event_target:saint_person
							}
						}

						if = {
							limit = { can_apply_lame_nickname_trigger = yes }
							give_nickname = nick_the_bastard
						}
					}

					20 = {
						trigger = {
							OR = {
								religion_openly_bon_or_reformed_trigger = yes

								trigger_if = {
									limit = { is_nomadic = yes }
									religion_openly_tengri_or_reformed_trigger = yes
								}
							}
						}

						mult_modifier = {
							factor = 0.2

							any_owned_bloodline = {
								has_bloodline_flag = bloodline_sky_burial
								bloodline_is_active_for = PREV
							}
						}

						if = {
							limit = { is_female = yes }

							create_bloodline = {
								type = ancestor_worship_bloodline_03
								religion = event_target:saint_person
								inheritance = matrilineal
							}
						}
						else = {
							create_bloodline = {
								type = ancestor_worship_bloodline_03
								religion = event_target:saint_person
							}
						}

						if = {
							limit = { can_apply_average_nickname_trigger = yes }
							give_nickname = nick_the_guide
						}
					}

					20 = {
						trigger = { is_nomadic = yes }

						mult_modifier = {
							factor = 0.1

							any_owned_bloodline = {
								has_bloodline_flag = bloodline_mercenary_traditions
								bloodline_is_active_for = PREV
							}
						}

						if = {
							limit = { is_female = yes }

							create_bloodline = {
								type = ancestor_worship_bloodline_04
								religion = event_target:saint_person
								inheritance = matrilineal
							}
						}
						else = {
							create_bloodline = {
								type = ancestor_worship_bloodline_04
								religion = event_target:saint_person
							}
						}

						if = {
							limit = { can_apply_cool_nickname_trigger = yes }
							give_nickname = nick_the_scourge
						}
					}

					30 = {
						trigger = { has_law = succ_tanistry}

						mult_modifier = {
							factor = 0.1

							any_owned_bloodline = {
								has_bloodline_flag = bloodline_tanistry
								bloodline_is_active_for = PREV
							}
						}

						if = {
							limit = { is_female = yes }

							create_bloodline = {
								type = ancestor_worship_bloodline_05
								religion = event_target:saint_person
								inheritance = matrilineal
							}
						}
						else = {
							create_bloodline = {
								type = ancestor_worship_bloodline_05
								religion = event_target:saint_person
							}
						}

						if = {
							limit = { can_apply_cool_nickname_trigger = yes }
							give_nickname = nick_the_lawgiver
						}
					}

					30 = {
						trigger = { this_is_sea_raider_trigger = yes }

						mult_modifier = {
							factor = 0.1

							any_owned_bloodline = {
								has_bloodline_flag = more_raiders_bloodline
								bloodline_is_active_for = PREV
							}
						}

						if = {
							limit = { is_female = yes }

							create_bloodline = {
								type = ancestor_worship_bloodline_06
								religion = event_target:saint_person
								inheritance = matrilineal
							}

							if = {
								limit = { can_apply_cool_nickname_trigger = yes }
								give_nickname = nick_the_valkyrie
							}
						}
						else = {
							create_bloodline = {
								type = ancestor_worship_bloodline_06
								religion = event_target:saint_person
							}

							if = {
								limit = { can_apply_cool_nickname_trigger = yes }
								give_nickname = the_unrestrained
							}
						}
					}

					20 = {
						trigger = { trait = duelist}

						mult_modifier = {
							factor = 0.1

							any_owned_bloodline = {
								has_bloodline_flag = duelist_bloodline
								bloodline_is_active_for = PREV
							}
						}

						if = {
							limit = { is_female = yes }

							create_bloodline = {
								type = ancestor_worship_bloodline_07
								religion = event_target:saint_person
								inheritance = matrilineal
							}
						}
						else = {
							create_bloodline = {
								type = ancestor_worship_bloodline_07
								religion = event_target:saint_person
							}
						}

						if = {
							limit = { can_apply_average_nickname_trigger = yes }
							give_nickname = nick_bloodaxe
						}
					}
				}

				new_bloodline = {
					set_name = blessed_bloodline_name
					set_description = blessed_bloodline_description
				}
			}

			# Messages
			any_playable_ruler = {
				limit = {
					religion = ROOT
					NOT = { dynasty = event_target:saint_person }
				}

				narrative_event = { id = HF.40025 }
			}

			event_target:saint_person = {
				any_dynasty_member = {
					limit = { religion_group = ROOT }
					narrative_event = { id = HF.40025 }
				}
			}

			narrative_event = { id = HF.40025 }
		}
	}

	option = {
		name = EVTOPTB_HF_40020
	}
}