namespace = HF

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

# Check if a character is eligible for Worshipping 
character_event = {
	id = HF.40100
	hide_window = yes
	is_triggered_only = yes
	has_dlc = "Holy Fury"
	only_playable = yes
	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_trailwalker
			has_religion_feature = religion_feature_revelationist
		}
		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
	trigger = {
	
	}

	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 = {
						modifier = {
							factor = 0.4
							any_owned_bloodline = {
								has_bloodline_flag = bloodline_heroes
							}
						}
						if = {
							limit = {
								is_female = yes
							}
							create_bloodline = {
								type = ancestor_worship_bloodline_01
								religion = event_target:saint_person
								inheritance = all_descendants
							}
						}
						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
							}
						}
						modifier = {
							factor = 0.1
							any_owned_bloodline = {
								has_bloodline_flag = bloodline_legitimize
							}
						}
						if = {
							limit = {
								is_female = yes
							}
							create_bloodline = {
								type = ancestor_worship_bloodline_02
								religion = event_target:saint_person
								inheritance = all_descendants
							}
						}
						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 = {
								AND = {
									government = nomadic_government
									OR = {
										religion = trailwalker
										religion = trailwalker_reformed
									}
								}
								religion = gaian
							}
						}
						modifier = {
							factor = 0.2
							any_owned_bloodline = {
								has_bloodline_flag = bloodline_sky_burial
							}
						}
						if = {
							limit = {
								is_female = yes
							}
							create_bloodline = {
								type = ancestor_worship_bloodline_03
								religion = event_target:saint_person
								inheritance = all_descendants
							}
						}
						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 = {
							government = nomadic_government
						}
						modifier = {
							factor = 0.1
							any_owned_bloodline = {
								has_bloodline_flag = bloodline_mercenary_traditions
							}
						}
						if = {
							limit = {
								is_female = yes
							}
							create_bloodline = {
								type = ancestor_worship_bloodline_04
								religion = event_target:saint_person
								inheritance = all_descendants
							}
						}
						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
						}
						modifier = {
							factor = 0.1
							any_owned_bloodline = {
								has_bloodline_flag = bloodline_tanistry
							}
						}
						if = {
							limit = {
								is_female = yes
							}
							create_bloodline = {
								type = ancestor_worship_bloodline_05
								religion = event_target:saint_person
								inheritance = all_descendants
							}
						}
						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 = {
							OR = {
								trait = pirate
								trait = viking
								trait = ravager
								trait = sea_queen
								trait = seaking
							}
						}
						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 = all_descendants
							}
						}
						else = {
							create_bloodline = {
								type = ancestor_worship_bloodline_06
								religion = event_target:saint_person
							}
						}
						if = {
							limit = {
								can_apply_cool_nickname_trigger = yes
								is_female = yes
							}
							give_nickname = nick_the_valkyrie
						}
						if = {
							limit = {
								can_apply_cool_nickname_trigger = yes
								is_female = no
							}
							give_nickname = the_unrestrained
						}
					}
					20 = {
						trigger = {
							trait = duelist 
						}
						modifier = {
							factor = 0.1
							any_owned_bloodline = {
								has_bloodline_flag = duelist_bloodline
							}
						}
						if = {
							limit = {
								is_female = yes
							}
							create_bloodline = {
								type = ancestor_worship_bloodline_07
								religion = event_target:saint_person
								inheritance = all_descendants
							}
						}
						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
				}
			}
			hidden_tooltip = {
				# Messages
				any_playable_ruler = {
					limit = {
						NOT = {
							family = event_target:saint_person
						}
						religion = ROOT
					}
					narrative_event = { id = HF.40025 }
				}
				event_target:saint_person = {
					any_dynasty_member = {
						limit = {
							religion_group = ROOT
						}
						narrative_event = { id = HF.40025 }
					}
				}
				ROOT = {
					narrative_event = { id = HF.40025 }
				}
			}
		}
	}
	option = {	
		name = EVTOPTB_HF_40020
	}
}

# Test Script
character_event = {
	id = HF.40105
	hide_window = yes
	is_triggered_only = yes
	trigger = {
	
	}

	immediate = {
		save_event_target_as = saint_person

		character_event = { id = HF.40101 }
	}
}

