namespace = HF

###########################
# Child of Destiny Events #
###########################

# Extra chance for player children to become Children of Destiny
character_event = {
	id = HF.199

	is_triggered_only = yes # on_yearly_pulse, random_events
	hide_window = yes

	has_dlc = "Holy Fury"
	max_age = 8
	only_capable = yes
	prisoner = no

	trigger = {
		trigger_if = {
			limit = { ai = yes }

			any_player = {
				is_parent_of = ROOT
			}
		}

		has_game_rule = {
			name = child_of_destiny
			value = on
		}

		OR = {
			is_tribal = yes
			is_feudal = yes
			is_nomadic = yes

			# is_patrician = yes # CleanSlate: Dangerous, since the CoD could become landed, meaning can't inherit the patrician house and other titles
		}

		was_conceived_a_bastard = no
		is_ill = no
		is_inaccessible_trigger = no
		has_negative_congenital_trigger = no

		# Should be able to legally inherit
		trigger_if = {
			limit = { is_female = yes }

			NOR = {
				has_religion_feature = religion_patriarchal
				has_law = agnatic_succession
			}
		}
		trigger_else = {
			NOR = {
				has_religion_feature = religion_matriarchal
				has_law = enatic_succession
			}
		}

		NOR = {
			trait = bastard
			trait = legit_bastard

			any_owned_bloodline = { # Must not already have a Child of Destiny bloodline
				has_bloodline_flag = bloodline_ambition
				bloodline_is_active_for = PREV
			}

			any_dynasty_member = { # Only one per dynasty at any one time
				has_character_flag = is_child_of_destiny
			}
		}
	}

	immediate = {
		save_event_target_as = child_of_destiny
		set_character_flag = is_child_of_destiny
		set_character_flag = ai_flag_refuse_concubinage
		set_character_flag = no_court_invites

		any_player = {
			limit = { is_parent_of = ROOT }

			narrative_event = {
				id = HF.201
				days = 15
			}
		}

		character_event = {
			id = HF.210 # The journey begins...
			days = 200
			random = 200
		}

		health = 1
		character_event = { id = HF.306 }

		if = {
			limit = { has_global_flag = cod_test_events }

			any_player = {
				character_event = { id = HF.307 }
			}
		}

		change_variable = {
			which = global_children_of_destiny_childhood_pulse_player
			value = 1
		}
	}

	weight_multiplier = {
		factor = 1

		mult_modifier = { # Having a super-parent boosts the chance
			factor = 3

			any_player = {
				is_parent_of = ROOT

				OR = {
					has_top_tier_education_trait_trigger = yes
					is_attractive_trigger = yes
					has_pleasant_personality_trigger = yes
				}
			}
		}

		mult_modifier = {
			factor = 3
			trait = strong
		}

		mult_modifier = {
			factor = 3

			OR = {
				trait = genius
				trait = quick
			}
		}

		mult_modifier = {
			factor = 3
			trait = attractive
		}

		mult_modifier = {
			factor = 0.25

			any_owned_bloodline = { # Let's try to avoid stacking created bloodlines
				has_bloodline_flag = created_bloodline
				bloodline_is_active_for = PREV
			}
		}

		mult_modifier = {
			factor = 5000
			has_global_flag = cod_test_values_spawns
		}
	}
}

# Child becomes Child of Destiny
character_event = {
	id = HF.200

	is_triggered_only = yes # on_birth, random_events
	hide_window = yes

	has_dlc = "Holy Fury"
	only_capable = yes
	prisoner = no

	trigger = {
		has_game_rule = {
			name = child_of_destiny
			value = on
		}

		liege = {
			is_parent_of = ROOT
			is_playable = yes
		}

		OR = {
			is_tribal = yes
			is_feudal = yes
			is_nomadic = yes

			# is_patrician = yes # CleanSlate: Dangerous, since the CoD could become landed, meaning can't inherit the patrician house and other titles
		}

		was_conceived_a_bastard = no
		is_primary_heir = no
		is_ill = no
		has_negative_congenital_trigger = no

		# Should be able to legally inherit
		trigger_if = {
			limit = { is_female = yes }

			NOR = {
				has_religion_feature = religion_patriarchal
				has_law = agnatic_succession
			}
		}
		trigger_else = {
			NOR = {
				has_religion_feature = religion_matriarchal
				has_law = enatic_succession
			}
		}

		NOR = {
			trait = bastard
			trait = legit_bastard

			any_owned_bloodline = { # Let's not stack created bloodlines
				has_bloodline_flag = created_bloodline
				bloodline_is_active_for = PREV
			}

			any_dynasty_member = { # Only one per dynasty at any one time
				has_character_flag = is_child_of_destiny
			}
		}
	}

	immediate = {
		save_event_target_as = child_of_destiny
		set_character_flag = is_child_of_destiny
		set_character_flag = ai_flag_refuse_concubinage
		set_character_flag = no_court_invites

		any_close_relative = {
			limit = { is_parent_of = ROOT }

			narrative_event = {
				id = HF.201
				days = 15
			}
		}

		character_event = {
			id = HF.210 # The journey begins...
			days = 200
			random = 200
		}

		health = 1
		set_global_flag = child_of_destiny_@ROOT

		change_variable = {
			which = global_children_of_destiny_on_birth
			value = 1
		}

		if = {
			limit = {
				any_player = { ai = no }
			}

			change_variable = {
				which = global_children_of_destiny_on_birth_player
				value = 1
			}
		}

		if = {
			limit = { has_global_flag = cod_test_events }

			any_player = {
				character_event = { id = HF.307 }
			}
		}
	}

	weight_multiplier = {
		factor = 1

		mult_modifier = {
			factor = 10
			any_player = { is_parent_of = ROOT }
		}

		mult_modifier = { # Having a super-parent boosts the chance
			factor = 3

			any_player = {
				is_parent_of = ROOT

				OR = {
					has_top_tier_education_trait_trigger = yes
					is_attractive_trigger = yes
					has_pleasant_personality_trigger = yes
				}
			}
		}

		mult_modifier = {
			factor = 3
			trait = strong
		}

		mult_modifier = {
			factor = 3

			OR = {
				trait = genius
				trait = quick
			}
		}

		mult_modifier = {
			factor = 3
			trait = attractive
		}

		mult_modifier = {
			factor = 5

			total_years_played >= 150

			check_variable = {
				which = global_children_of_destiny_bloodlines_founded
				value < 1
			}
		}

		mult_modifier = {
			factor = 2

			total_years_played >= 200

			check_variable = {
				which = global_children_of_destiny_bloodlines_founded
				value < 1
			}
		}

		mult_modifier = {
			factor = 2

			total_years_played >= 250

			check_variable = {
				which = global_children_of_destiny_bloodlines_founded
				value < 1
			}
		}

		mult_modifier = {
			factor = 5000
			has_global_flag = cod_test_values_spawns
		}
	}
}

# Parents notified of the ominous birth
narrative_event = {
	id = HF.201
	title = HF_201_TITLE
	desc = HF_201_DESC
	picture = GFX_evt_birth
	border = GFX_event_narrative_frame_war

	is_triggered_only = yes

	ai = no

	option = {
		name = HF_201_OPTA
	}
}

character_event = { # Child of Destiny journey randomization tombola
	id = HF.210

	is_triggered_only = yes
	hide_window = yes

	has_character_flag = is_child_of_destiny

	immediate = {
		save_event_target_as = child_of_destiny

		if = {
			# Perhaps it was not destined after all...
			limit = { is_incapable = yes }
			clr_character_flag = is_child_of_destiny
		}
		else = {
			random_list = { # Main 'journey' events
				########
				# BABY #
				########
				10 = { # Snake in the Crib
					trigger = {
						age < 6
						prisoner = no
						NOT = { has_character_flag = child_of_destiny_snek }
					}

					character_event = { id = HF.211 }
				}

				10 = { # Accidently drink poison and survive
					trigger = {
						age < 6
						prisoner = no
						NOT = { has_character_flag = child_of_destiny_poison }

						trigger_if = {
							limit = { is_ruler = yes }

							job_spymaster = {
								is_inaccessible_or_incapable_trigger = no
							}
						}
						trigger_else = {
							liege = {
								job_spymaster = {
									is_inaccessible_or_incapable_trigger = no
								}
							}
						}
					}

					character_event = { id = HF.215 }
				}

				###############
				# YOUNG CHILD #
				###############
				10 = { # Vision from highgod
					trigger = {
						age >= 6
						is_adult = no
						is_inaccessible_trigger = no
						prisoner = no
						NOT = { has_character_flag = child_of_destiny_highgod_vision }

						any_realm_character = {
							is_priest = yes
							religion = event_target:child_of_destiny
							is_inaccessible_or_incapable_trigger = no
						}

						any_realm_province = {
							held_under_PREV = yes

							any_province_holding = {
								holding_type = temple

								holder_scope = {
									religion = event_target:child_of_destiny
								}
							}
						}
					}

					character_event = { id = HF.217 }
				}

				10 = { # Meeting with Great Warrior
					trigger = {
						age >= 6
						is_adult = no
						prisoner = no
						is_inaccessible_trigger = no
						NOT = { has_character_flag = child_of_destiny_warrior }
					}

					character_event = { id = HF.219 }
				}

				10 = { # Meeting with Wandering Wise Man
					trigger = {
						age >= 6
						is_adult = no
						prisoner = no
						is_inaccessible_trigger = no
						NOT = { has_character_flag = child_of_destiny_wise_man }
					}

					character_event = { id = HF.221 }
				}

				10 = { # Attempted murder!
					trigger = {
						age >= 6
						is_adult = no
						prisoner = no
						is_inaccessible_trigger = no
						NOT = { has_character_flag = child_of_destiny_attempted_murder }
					}

					character_event = { id = HF.225 }
				}

				10 = { # Encounter Wild Beast
					trigger = {
						age >= 10
						is_adult = no
						prisoner = no
						is_inaccessible_trigger = no
						NOT = { has_character_flag = child_of_destiny_wild_beast }

						trigger_if = {
							limit = { is_ruler = yes }
							job_marshal = { is_inaccessible_or_incapable_trigger = no }
						}
						trigger_else = {
							liege = {
								job_marshal = {
									is_inaccessible_or_incapable_trigger = no
								}
							}
						}
					}

					character_event = { id = HF.228 }
				}

				##############
				# ADOLESCENT #
				##############
				10 = { # Swarmed by admirers
					trigger = {
						age >= 12
						is_adult = no
						prisoner = no
						is_inaccessible_trigger = no
						has_ugly_trait_trigger = no
						NOT = { has_character_flag = child_of_destiny_admirers }
					}

					character_event = { id = HF.223 }
				}

				10 = { # Gain 'Posse'
					trigger = {
						age >= 12
						is_adult = no
						prisoner = no
						is_inaccessible_trigger = no
						NOT = { has_character_flag = child_of_destiny_posse }

						top_liege = {
							any_realm_character = {
								count = 3

								same_sex = event_target:child_of_destiny
								age >= 10
								is_adult = no
								ai = yes
								is_inaccessible_or_incapable_trigger = no
								NOT = { is_friend = event_target:child_of_destiny }
							}
						}
					}

					character_event = { id = HF.235 }
				}

				#########
				# ADULT #
				#########
				10 = { # Player Destiny - choose!
					trigger = {
						ai = no # Only if player
						age >= 20
						lower_real_tier_than = KING
						war = no
						in_revolt = no
						prisoner = no
						is_inaccessible_trigger = no
						NOT = { has_character_flag = child_of_destiny_made_player_choice }

						any_independent_ruler = {
							realm_size >= 25
							is_landed = yes
							ai = yes
							is_tributary = no
							NOT = { is_liege_or_above_of = event_target:child_of_destiny }

							event_target:child_of_destiny = {
								NOR = {
									obedient = PREV
									non_interference = PREV
									has_non_aggression_pact_with = PREV
								}
							}
						}

						NOT = {
							any_liege = {
								in_revolt = yes
							}
						}
					}

					character_event = { id = HF.231 }
				}

				10 = { # Gain a lover
					trigger = {
						is_adult = yes
						num_of_lovers < 2
						prisoner = no
						is_inaccessible_trigger = no

						top_liege = {
							any_realm_character = {
								is_attractive_trigger = yes
								is_adult = yes
								practical_age < 40
								root_attraction_trigger = yes
								attracted_to_root_trigger = yes
								is_inaccessible_or_incapable_trigger = no
								is_infertile_trigger = no
								ai = yes

								NOR = {
									is_close_relative = event_target:child_of_destiny
									is_rival = event_target:child_of_destiny
									is_lover = event_target:child_of_destiny
									character = event_target:child_of_destiny
								}
							}
						}
					}

					character_event = { id = HF.227 }
				}

				10 = { # Gain a friend
					trigger = {
						is_adult = yes
						num_of_friends < 5
						prisoner = no
						is_inaccessible_trigger = no

						top_liege = {
							any_realm_character = {
								is_adult = yes
								ai = yes
								is_inaccessible_or_incapable_trigger = no

								NOR = {
									is_liege_or_above_of = event_target:child_of_destiny
									is_close_relative = event_target:child_of_destiny
									is_rival = event_target:child_of_destiny
									is_lover = event_target:child_of_destiny
									is_friend = event_target:child_of_destiny
									character = event_target:child_of_destiny
								}
							}
						}
					}

					character_event = { id = HF.240 }
				}

				10 = { # Overcome hardship (depressed, stressed)
					trigger = {
						OR = {
							trait = stressed
							trait = depressed
						}

						is_adult = yes
						prisoner = no
					}

					character_event = { id = HF.234 }
				}

				10 = { # Goes on an adventure
					trigger = {
						age >= 20
						ai = yes
						lower_real_tier_than = KING
						prisoner = no
						is_inaccessible_trigger = no

						# There must be a valid target
						any_independent_ruler = {
							realm_size >= 25
							is_landed = yes
							ai = yes
							is_tributary = no
							NOT = { is_vassal_or_below = event_target:child_of_destiny }

							event_target:child_of_destiny = {
								top_liege = {
									distance_from_realm = {
										who = PREVPREV
										value < 1200
									}
								}

								NOR = {
									obedient = PREV
									non_interference = PREV
									has_non_aggression_pact_with = PREV
								}
							}
						}

						NOR = {
							has_game_rule = {
								name = adventurers
								value = none
							}

							has_character_flag = child_of_destiny_adventure
						}
					}

					character_event = { id = HF.290 }
				}
				###########
				# Any Age #
				###########
				10 = { # Prison Escape (not for babies though)
					trigger = {
						prisoner = yes
						age >= 6

						host = {
							any_realm_character = {
								is_adult = yes
								is_ruler = no
								is_inaccessible_or_incapable_trigger = no

								NOR = {
									is_rival = event_target:child_of_destiny
									is_married = event_target:child_of_destiny
									is_consort = event_target:child_of_destiny
								}
							}
						}
					}

					character_event = { id = HF.237 }
				}

				fallback = {
					character_event = {
						id = HF.210
						days = 365
						random = 500
					}
				}
			}
		}
	}
}

character_event = { # Snake in Crib
	id = HF.211
	desc = HF_211_DESC
	picture = GFX_evt_birth

	is_triggered_only = yes
	hide_new = yes

	immediate = {
		set_character_flag = child_of_destiny_snek
	}

	option = { # Strangle the snake
		name = HF_211_OPTA

		random_list = {
			95 = { # Success
				add_character_modifier = {
					name = strangled_snake
					duration = -1
				}

				any_player = {
					limit = {
						NOT = { character = event_target:child_of_destiny }

						OR = {
							is_parent_of = event_target:child_of_destiny
							is_liege_of = event_target:child_of_destiny
						}
					}

					character_event = { id = HF.212 }
				}
			}

			5 = {
				death = { death_reason = death_accident_snakes }

				any_player = {
					limit = {
						NOT = { character = event_target:child_of_destiny }

						OR = {
							is_parent_of = event_target:child_of_destiny
							is_liege_of = event_target:child_of_destiny
						}
					}

					character_event = { id = HF.214 }
				}
			}
		}

		ai_chance = { factor = 90 }
	}

	option = { # Befriend the snake
		name = HF_211_OPTB

		random_list = {
			95 = { # Success
				add_character_modifier = {
					name = friend_of_snakes
					duration = -1
				}

				any_player = {
					limit = {
						NOT = { character = event_target:child_of_destiny }

						OR = {
							is_parent_of = event_target:child_of_destiny
							is_liege_of = event_target:child_of_destiny
						}
					}

					character_event = { id = HF.213 }
				}
			}

			5 = {
				death = { death_reason = death_accident_snakes }

				any_player = {
					limit = {
						NOT = { character = event_target:child_of_destiny }

						OR = {
							is_parent_of = event_target:child_of_destiny
							is_liege_of = event_target:child_of_destiny
						}
					}

					character_event = { id = HF.214 }
				}
			}
		}

		ai_chance = { factor = 10 }
	}

	after = {
		# Back to the journey tombola!
		character_event = {
			id = HF.210
			days = 365
			random = 500
		}
	}
}

# Notification - Snake in Crib, Baby strangles snake
character_event = {
	id = HF.212
	desc = HF_212_DESC
	picture = GFX_evt_birth

	is_triggered_only = yes
	hide_new = yes

	option = {
		name = {
			text = HF_OPT_MORE_GUARDS
			trigger = { is_parent_of = FROM }
		}
		name = {
			text = HF_OPT_NOT_MY_CHILD
			trigger = { NOT = { is_parent_of = FROM } }
		}

		custom_tooltip = { text = childs_power_increases_tt }
	}
}

character_event = { # Notification - Snake in Crib, Baby befriends snake
	id = HF.213
	desc = HF_213_DESC
	picture = GFX_evt_birth

	is_triggered_only = yes
	hide_new = yes

	option = {
		name = {
			text = HF_OPT_MORE_GUARDS
			trigger = { is_parent_of = FROM }
		}
		name = {
			text = HF_OPT_NOT_MY_CHILD
			trigger = { NOT = { is_parent_of = FROM } }
		}

		custom_tooltip = { text = childs_power_increases_tt }
	}
}

character_event = { # Notification - Snake in Crib, Baby dies
	id = HF.214
	desc = HF_214_DESC
	picture = GFX_evt_birth

	is_triggered_only = yes
	hide_new = yes

	option = {
		name = {
			text = HF_OPT_MY_CHILD
			trigger = { is_parent_of = FROM }
		}
		name = {
			text = HF_OPT_NOT_MY_CHILD
			trigger = {
				NOT = { is_parent_of = FROM }
			}
		}

		tooltip = {
			event_target:child_of_destiny = {
				show_scope_change = no

				death = { death_reason = death_accident_snakes }
			}
		}
	}
}


# Drink Poison
character_event = {
	id = HF.215
	desc = HF_215_DESC
	picture = GFX_evt_council
	portrait = event_target:spymaster_target

	is_triggered_only = yes
	hide_new = yes

	immediate = {
		set_character_flag = child_of_destiny_poison

		if = {
			limit = { is_ruler = yes }
			job_spymaster = { save_event_target_as = spymaster_target }
		}
		else = {
			liege = {
				job_spymaster = {
					save_event_target_as = spymaster_target
				}
			}
		}
	}

	option = { # I feel strong
		name = HF_215_OPTA

		add_character_modifier = {
			name = child_of_mithridates
			duration = -1
		}

		ai_chance = { factor = 90 }
	}

	option = { # I feel strange
		name = HF_215_OPTB

		add_character_modifier = {
			name = strange_mind
			duration = -1
		}

		ai_chance = { factor = 10 }
	}

	after = {
		any_player = {
			limit = {
				NOT = { character = event_target:child_of_destiny }

				OR = {
					is_parent_of = event_target:child_of_destiny
					is_liege_of = event_target:child_of_destiny
				}
			}

			character_event = { id = HF.216 }
		}

		# Back to the journey tombola!
		clear_event_target = spymaster_target

		character_event = {
			id = HF.210
			days = 365
			random = 500
		}
	}
}

# Notification - Drinking poison
character_event = {
	id = HF.216
	desc = HF_216_DESC
	picture = GFX_evt_council

	is_triggered_only = yes
	hide_new = yes

	option = {
		name = {
			text = HF_216_OPTA
			trigger = { is_parent_of = FROM }
		}
		name = {
			text = HF_216_OPTB
			trigger = { NOT = { is_parent_of = FROM } }
		}

		custom_tooltip = { text = childs_power_increases_tt }
	}
}

# Vision from Highgod
character_event = {
	id = HF.217
	desc = HF_217_DESC
	picture = GFX_evt_bishop
	border = GFX_event_normal_frame_religion
	portrait = event_target:priest_target

	is_triggered_only = yes
	hide_new = yes

	immediate = {
		set_character_flag = child_of_destiny_highgod_vision

		random_realm_character = {
			limit = {
				is_priest = yes
				religion = event_target:child_of_destiny
				NOT = { is_inaccessible_or_incapable_trigger = yes }
			}

			preferred_limit = {
				OR = {
					trait = zealous
					trait = theologian
				}
			}

			save_event_target_as = priest_target
		}

		random_realm_province = {
			limit = {
				held_under_PREV = yes

				any_province_holding = {
					holding_type = temple

					holder_scope = {
						religion = event_target:child_of_destiny
					}
				}
			}

			random_province_holding = {
				limit = {
					holding_type = temple

					holder_scope = {
						religion = event_target:child_of_destiny
					}
				}

				save_event_target_as = temple_target
			}
		}
	}

	option = { # Perhaps I, too, will be a god one day?
		name = HF_217_OPTA

		add_trait_fully_silently_cynical_effect = yes
		add_trait = inspiring_leader

		add_character_modifier = {
			name = aspiring_for_godhood
			duration = -1
		}

		if = {
			limit = {
				OR = {
					religion_group = christian
					religion_group = muslim
					religion_group = jewish_group
				}
			}

			add_character_modifier = {
				name = annoyed_religious
				years = 10
			}
		}

		ai_chance = { factor = 90 }
	}

	option = { # I must honor highgod's teachings
		name = HF_217_OPTB

		add_trait_fully_silently_zealous_effect = yes
		add_trait = holy_warrior

		add_character_modifier = {
			name = devoted_to_highgod
			duration = -1
		}

		ai_chance = { factor = 10 }
	}

	after = {
		any_player = {
			limit = {
				NOT = { character = event_target:child_of_destiny }

				OR = {
					is_parent_of = event_target:child_of_destiny
					is_liege_of = event_target:child_of_destiny
				}
			}

			character_event = { id = HF.218 }
		}

		# Back to the journey tombola!
		clear_event_target = priest_target
		clear_event_target = temple_target

		character_event = {
			id = HF.210
			days = 365
			random = 500
		}
	}
}

# Notification - Vision from highgod
character_event = {
	id = HF.218
	desc = HF_218_DESC
	picture = GFX_evt_bishop

	is_triggered_only = yes
	hide_new = yes

	option = {
		name = {
			text = HF_218_OPTA
			trigger = { is_parent_of = FROM }
		}
		name = {
			text = HF_218_OPTB
			trigger = { NOT = { is_parent_of = FROM } }
		}

		show_portrait = event_target:priest_target
		custom_tooltip = { text = childs_power_increases_tt }
	}
}

character_event = { # Meet Warrior
	id = HF.219
	desc = HF_219_DESC
	picture = GFX_evt_child_sword
	portrait = event_target:great_warrior_target

	is_triggered_only = yes
	hide_new = yes

	immediate = {
		set_character_flag = child_of_destiny_warrior

		random_realm_character = {
			limit = {
				has_education_martial_trigger = yes
				martial >= 14
				is_inaccessible_or_incapable_trigger = no
				ai = yes

				NOR = {
					is_parent_of = event_target:child_of_destiny
					is_liege_of = event_target:child_of_destiny
				}
			}

			save_event_target_as = great_warrior_target
		}

		if = {
			limit = {
				NOT = { event_target:great_warrior_target = { always = yes } }
			}

			spawn_fantastic_commander_effect = yes
			new_character = { save_event_target_as = great_warrior_target }
		}
	}

	option = { # I was eager to learn about personal combat
		name = HF_219_OPTA

		add_character_modifier = {
			name = tenacious_duelist
			duration = -1
		}

		add_friend = event_target:great_warrior_target
		add_trait = brawny
		add_trait_fully_silently_wroth_effect = yes

		ai_chance = { factor = 90 }
	}

	option = { # I was eager to learn about strategy
		name = HF_219_OPTB

		add_character_modifier = {
			name = clever_planner
			duration = -1
		}

		add_friend = event_target:great_warrior_target
		add_trait = brawny
		add_trait_fully_silently_patient_effect = yes

		ai_chance = { factor = 10 }
	}

	after = {
		if = {
			limit = {
				NOT = { trait = brawny }
			}

			add_trait = brawny
		}

		add_friend = event_target:great_warrior_target

		any_player = {
			limit = {
				NOT = { character = event_target:child_of_destiny }

				OR = {
					is_parent_of = event_target:child_of_destiny
					is_liege_of = event_target:child_of_destiny
				}
			}

			character_event = { id = HF.220 }
		}

		# Back to the journey tombola!
		clear_event_target = invited_character
		clear_event_target = great_warrior_target

		character_event = {
			id = HF.210
			days = 365
			random = 500
		}
	}
}

# Notification - Meet Warrior
character_event = {
	id = HF.220
	desc = HF_220_DESC
	picture = GFX_evt_child_sword
	portrait = event_target:child_of_destiny

	is_triggered_only = yes
	hide_new = yes

	option = {
		name = {
			text = HF_220_OPTA
			trigger = { is_parent_of = FROM }
		}
		name = {
			text = HF_220_OPTB
			trigger = { NOT = { is_parent_of = FROM } }
		}

		show_portrait = event_target:great_warrior_target
		custom_tooltip = { text = childs_power_increases_tt }
	}
}

# Meet Wandering Wise Man
character_event = {
	id = HF.221
	desc = HF_221_DESC
	picture = GFX_evt_child_reading
	portrait = event_target:wise_man_target

	is_triggered_only = yes
	hide_new = yes

	immediate = {
		set_character_flag = child_of_destiny_wise_man

		random_realm_character = {
			limit = {
				has_character_flag = physician_wandering_genius
				is_inaccessible_or_incapable_trigger = no
				ai = yes

				NOR = {
					is_parent_of = event_target:child_of_destiny
					is_liege_of = event_target:child_of_destiny
				}
			}

			save_event_target_as = wise_man_target
		}

		if = {
			limit = {
				NOT = { event_target:wise_man_target = { always = yes } }
			}

			create_character = {
				religion = event_target:child_of_destiny
				culture = random
				dynasty = none
				age = 43
				random_traits = yes
				female = no
				health = 6
				flag = is_court_physician
				flag = physician_wandering_genius
				flag = ai_flag_refuse_conversion
				flag = no_court_invites

				attributes = {
					learning = 12
				}
			}

			new_character = {
				clear_education_trait = yes
				remove_trait = dull
				remove_trait = slow
				remove_trait = imbecile
				remove_trait = quick
				remove_trait = lustful
				add_trait = mastermind_theologian
				add_trait = genius
				add_trait = adventurer
				add_trait = one_eyed
				add_trait = celibate
				give_nickname = nick_the_wise

				if = {
					limit = { religion_group = muslim }
					remove_trait = scholar
					add_trait = mutazilite
				}
				else_if = {
					limit = { has_dharmic_religion_trigger = yes }

					add_trait = brahmin
					character_event = { id = RoI.30121 }
				}

				save_event_target_as = wise_man_target
			}
		}
	}

	option = { # I learned how to inspire
		name = HF_221_OPTA

		add_character_modifier = {
			name = inspiring_presence
			duration = -1
		}

		add_trait_fully_silently_gregarious_effect = yes
		add_trait_fully_silently_diligent_effect = yes

		ai_chance = { factor = 90 }
	}

	option = { # I learned how to rule
		name = HF_221_OPTB

		add_character_modifier = {
			name = motivated_ruler
			duration = -1
		}

		add_trait_fully_silently_temperate_effect = yes
		add_trait_fully_silently_just_effect = yes

		ai_chance = { factor = 10 }
	}

	after = {
		add_friend = event_target:wise_man_target

		# Back to the journey tombola!
		clear_event_target = wise_man_target

		character_event = {
			id = HF.210
			days = 365
			random = 500
		}

		any_player = {
			limit = {
				NOT = { character = event_target:child_of_destiny }

				OR = {
					is_parent_of = event_target:child_of_destiny
					is_liege_of = event_target:child_of_destiny
				}
			}

			character_event = { id = HF.222 }
		}
	}
}

# Notification - Meet Wandering Wise Man
character_event = {
	id = HF.222
	desc = HF_222_DESC
	picture = GFX_evt_child_reading

	is_triggered_only = yes
	hide_new = yes

	option = {
		name = {
			text = HF_222_OPTA
			trigger = { is_parent_of = FROM }
		}
		name = {
			text = HF_222_OPTB
			trigger = {
				NOT = { is_parent_of = FROM }
			}
		}

		show_portrait = event_target:wise_man_target
		custom_tooltip = { text = childs_power_increases_tt }
	}
}

# Swarmed by Admirers
character_event = {
	id = HF.223
	desc = HF_223_DESC
	picture = GFX_evt_child_talking

	is_triggered_only = yes
	hide_new = yes

	immediate = {
		set_character_flag = child_of_destiny_admirers

		top_liege = {
			any_realm_character = {
				count = 3

				limit = {
					is_opposite_sex = event_target:child_of_destiny
					age >= 12
					is_adult = no
					ai = yes
					is_inaccessible_or_incapable_trigger = no

					NOR = {
						trait = homosexual
						trait = celibate
						trait = eunuch
						is_close_relative = event_target:child_of_destiny
						has_character_flag = admirer@event_target:child_of_destiny
					}
				}

				set_character_flag = admirer@event_target:child_of_destiny
			}

			any_realm_character = {
				count = 2

				limit = {
					trait = homosexual
					same_sex = event_target:child_of_destiny
					age = 12
					is_adult = no
					ai = yes
					is_inaccessible_or_incapable_trigger = no

					NOR = {
						trait = celibate
						trait = eunuch
						is_close_relative = event_target:child_of_destiny
						has_character_flag = admirer@event_target:child_of_destiny
						has_character_flag = homosexual_admirer@event_target:child_of_destiny
					}
				}

				set_character_flag = homosexual_admirer@event_target:child_of_destiny
			}
		}
	}

	option = { # I understand why they love me, I *am* magnificent!
		name = HF_223_OPTA

		add_character_modifier = {
			name = irresistible
			duration = -1
		}

		add_trait_fully_silently_lustful_effect = yes

		any_realm_character = {
			show_scope_change = no

			limit = { has_character_flag = admirer@event_target:child_of_destiny }

			opinion = {
				name = teenage_infatuation
				who = event_target:child_of_destiny
				years = 20
			}
		}

		ai_chance = { factor = 90 }
	}

	option = { # I was never one to limit my options...
		name = HF_223_OPTB

		add_character_modifier = {
			name = irresistible
			duration = -1
		}

		add_trait_fully_silently_lustful_effect = yes

		if = {
			limit = {
				NOT = { trait = homosexual }
			}

			add_trait = homosexual
		}

		any_realm_character = {
			show_scope_change = no

			limit = { has_character_flag = admirer@event_target:child_of_destiny }

			opinion = {
				name = teenage_infatuation
				who = event_target:child_of_destiny
				years = 20
			}
		}

		any_realm_character = {
			show_scope_change = no

			limit = { has_character_flag = homosexual_admirer@event_target:child_of_destiny }

			opinion = {
				name = teenage_infatuation
				who = event_target:child_of_destiny
				years = 20
			}
		}

		ai_chance = { factor = 10 }
	}

	after = {
		any_player = {
			limit = {
				NOT = { character = event_target:child_of_destiny }

				OR = {
					is_parent_of = event_target:child_of_destiny
					is_liege_of = event_target:child_of_destiny
				}
			}

			character_event = { id = HF.224 }
		}

		# Back to the journey tombola!
		character_event = {
			id = HF.210
			days = 365
			random = 500
		}
	}
}

# Notification - Swarmed by Admirers
character_event = {
	id = HF.224
	desc = HF_224_DESC
	picture = GFX_evt_child_talking

	is_triggered_only = yes
	hide_new = yes

	option = {
		name = {
			text = HF_224_OPTA
			trigger = { is_parent_of = FROM }
		}
		name = {
			text = HF_224_OPTB
			trigger = { NOT = { is_parent_of = FROM } }
		}

		custom_tooltip = { text = childs_power_increases_tt }
	}
}

character_event = { # Attempted Murder
	id = HF.225
	desc = HF_225_DESC
	picture = GFX_evt_shadow
	portrait = event_target:attempted_murderer

	is_triggered_only = yes
	hide_new = yes

	immediate = {
		set_character_flag = child_of_destiny_attempted_murder

		top_liege = {
			random_realm_character = {
				limit = {
					OR = {
						is_devil_worshiper_trigger = yes
						trait = lunatic
						trait = possessed
					}

					is_adult = yes
					ai = yes
					is_inaccessible_or_incapable_trigger = no

					NOR = {
						is_parent_of = event_target:child_of_destiny
						is_liege_of = event_target:child_of_destiny
					}
				}

				preferred_limit = { is_devil_worshiper_trigger = yes }

				save_event_target_as = attempted_murderer
				add_blood_splatter_effect = yes
			}

			if = {
				limit = {
					NOT = { event_target:attempted_murderer = { always = yes } }
				}

				create_character = {
					religion = event_target:child_of_destiny
					culture = event_target:child_of_destiny
					dynasty = none
					age = 33
					random_traits = yes
					female = 50
					add_trait = lunatic
					add_trait = possessed
					add_trait = ugly
				}

				new_character = {
					remove_trait = attractive
					add_scarred_high_effect = yes
					save_event_target_as = attempted_murderer
					add_blood_splatter_effect = yes
				}
			}
		}
	}

	option = { # I must always keep a close eye on those around me
		name = HF_225_OPTA

		event_target:attempted_murderer = {
			show_scope_change = no

			death = {
				death_reason = death_duel
				killer = event_target:child_of_destiny
			}
		}

		add_character_modifier = {
			name = lightning_reflexes
			duration = -1
		}

		add_trait_fully_silently_paranoid_effect = yes

		ai_chance = { factor = 90 }
	}

	option = { # This is proof that Evilgod holds no sway over me
		name = HF_225_OPTB

		event_target:attempted_murderer = {
			show_scope_change = no

			death = {
				death_reason = death_duel
				killer = event_target:child_of_destiny
			}
		}

		add_character_modifier = {
			name = protected_from_evil
			duration = -1
		}

		add_trait_fully_silently_humble_effect = yes

		ai_chance = { factor = 10 }
	}

	after = {
		any_player = {
			limit = {
				NOT = { character = event_target:child_of_destiny }

				OR = {
					is_parent_of = event_target:child_of_destiny
					is_liege_of = event_target:child_of_destiny
				}
			}

			character_event = { id = HF.226 }
		}

		# Back to the journey tombola!
		clear_event_target = attempted_murderer

		character_event = {
			id = HF.210
			days = 365
			random = 500
		}
	}
}

# Notification - Attempted Murder
character_event = {
	id = HF.226
	desc = HF_226_DESC
	picture = GFX_evt_shadow
	portrait = event_target:attempted_murderer

	is_triggered_only = yes
	hide_new = yes

	option = {
		name = {
			text = HF_226_OPTA
			trigger = { is_parent_of = FROM }
		}
		name = {
			text = HF_226_OPTB
			trigger = { NOT = { is_parent_of = FROM } }
		}

		show_portrait = event_target:attempted_murderer
		custom_tooltip = { text = childs_power_increases_tt }
	}
}

# Gain a lover
character_event = {
	id = HF.227
	desc = HF_227_DESC
	picture = GFX_evt_lovers

	is_triggered_only = yes
	hide_new = yes

	immediate = {
		top_liege = {
			random_realm_character = {
				limit = {
					is_attractive_trigger = yes
					root_attraction_trigger = yes
					attracted_to_root_trigger = yes
					is_adult = yes
					practical_age < 40
					is_inaccessible_or_incapable_trigger = no
					is_infertile_trigger = no
					ai = yes

					NOR = {
						is_close_relative = event_target:child_of_destiny
						is_rival = event_target:child_of_destiny
						is_lover = event_target:child_of_destiny
						character = event_target:child_of_destiny
					}
				}

				preferred_limit = {
					trait = attractive
					practical_age < 30
					is_married = no
					is_consort = no

					has_opinion_modifier = {
						name = teenage_infatuation
						who = event_target:child_of_destiny
					}
				}

				preferred_limit = {
					trait = attractive
					practical_age < 30
					is_married = no
					is_consort = no
				}

				preferred_limit = {
					has_opinion_modifier = {
						who = event_target:child_of_destiny
						name = teenage_infatuation
					}

					practical_age < 30
					is_married = no
					is_consort = no
				}

				preferred_limit = {
					practical_age < 30
					is_married = no
					is_consort = no
				}

				preferred_limit = {
					is_married = no
					is_consort = no
				}

				save_event_target_as = sex_partner
			}
		}
	}

	option = {
		name = HF_227_OPTA

		add_lover = event_target:sex_partner

		hidden_effect = {
			unprotected_sex_effect_event_target = yes
		}
	}

	option = {
		name = HF_227_OPTB

		ai_chance = { factor = 0 }
	}

	after = {
		# Back to the journey tombola!
		clear_event_target = sex_partner

		character_event = {
			id = HF.210
			days = 365
			random = 500
		}
	}
}

character_event = { # Encounter Wild Beast
	id = HF.228
	desc = HF_228_DESC
	picture = GFX_evt_child_play
	portrait = event_target:marshal_target

	is_triggered_only = yes
	hide_new = yes

	immediate = {
		set_character_flag = child_of_destiny_wild_beast

		if = {
			limit = { is_ruler = yes }
			job_marshal = { save_event_target_as = marshal_target }
		}
		else = {
			liege = {
				job_marshal = {
					save_event_target_as = marshal_target
				}
			}
		}
	}

	option = { # Fight the beast!
		name = HF_228_OPTA

		random_list = {
			95 = { # Success
				add_character_modifier = {
					name = slain_legendary_beast
					duration = -1
				}

				add_trait_fully_silently_brave_effect = yes

				any_player = {
					limit = {
						NOT = { character = event_target:child_of_destiny }

						OR = {
							is_parent_of = event_target:child_of_destiny
							is_liege_of = event_target:child_of_destiny
						}
					}

					character_event = { id = HF.229 }
				}
			}

			5 = {
				death = { death_reason = death_accident_generic_beast }

				any_player = {
					limit = {
						NOT = { character = event_target:child_of_destiny }

						OR = {
							is_parent_of = event_target:child_of_destiny
							is_liege_of = event_target:child_of_destiny
						}
					}

					character_event = { id = HF.230 }
				}
			}
		}

		ai_chance = { factor = 90 }
	}

	option = { # Outsmart the beast
		name = HF_228_OPTB

		random_list = {
			95 = { # Success
				add_character_modifier = {
					name = outsmarted_legendary_beast
					duration = -1
				}

				add_trait_fully_silently_deceitful_effect = yes

				any_player = {
					limit = {
						NOT = { character = event_target:child_of_destiny }

						OR = {
							is_parent_of = event_target:child_of_destiny
							is_liege_of = event_target:child_of_destiny
						}
					}

					character_event = { id = HF.229 }
				}
			}

			5 = {
				death = { death_reason = death_accident_generic_beast }

				any_player = {
					limit = {
						NOT = { character = event_target:child_of_destiny }

						OR = {
							is_parent_of = event_target:child_of_destiny
							is_liege_of = event_target:child_of_destiny
						}
					}

					character_event = { id = HF.230 }
				}
			}
		}

		ai_chance = { factor = 10 }
	}

	after = {
		# Back to the journey tombola!
		clear_event_target = marshal_target

		character_event = {
			id = HF.210
			days = 365
			random = 500
		}
	}
}

# Notification - Child defeats wild beast
character_event = {
	id = HF.229
	desc = HF_229_DESC
	picture = GFX_evt_child_play
	portrait = event_target:marshal_target

	is_triggered_only = yes
	hide_new = yes

	option = {
		name = {
			text = HF_229_OPTA
			trigger = { is_parent_of = FROM }
		}
		name = {
			text = HF_229_OPTB
			trigger = { NOT = { is_parent_of = FROM } }
		}

		show_portrait = event_target:child_of_destiny
		custom_tooltip = { text = childs_power_increases_tt }
	}
}

# Notification - Child is killed by wild beast
character_event = {
	id = HF.230
	desc = HF_230_DESC
	picture = GFX_evt_child_play
	portrait = event_target:marshal_target

	is_triggered_only = yes
	hide_new = yes

	option = {
		name = {
			text = HF_OPT_MY_CHILD
			trigger = { is_parent_of = FROM }
		}
		name = {
			text = HF_OPT_NOT_MY_CHILD
			trigger = { NOT = { is_parent_of = FROM } }
		}

		tooltip = {
			event_target:child_of_destiny = {
				show_scope_change = no

				death = { death_reason = death_accident_generic_beast }
			}
		}
	}
}

character_event = { # Player - Choose Destiny, inwards or outwards
	id = HF.231
	picture = GFX_evt_throne_room
	portrait = event_target:great_warrior_target

	desc = {
		text = HF_231_DESC
		trigger = { independent = no }
	}
	desc = {
		text = HF_231_ALT_DESC
		trigger = { independent = yes }
	}

	is_triggered_only = yes
	hide_new = yes

	immediate = {
		set_character_flag = child_of_destiny_made_player_choice

		top_liege = {
			save_event_target_as = top_liege_match_target
		}

		random_independent_ruler = {
			limit = {
				realm_size >= 25
				is_landed = yes
				is_tributary = no
				ai = yes
				NOT = { is_liege_or_above_of = event_target:child_of_destiny }

				event_target:child_of_destiny = {
					NOR = {
						obedient = PREV
						non_interference = PREV
						has_non_aggression_pact_with = PREV
					}
				}
			}

			preferred_limit = {
				distance_from_realm = {
					who = PREV
					value >= 200
				}

				distance_from_realm = {
					who = PREV
					value < 800
				}

				NOT = {
					any_player = {
						same_realm = PREV
					}
				}

				is_nomadic = no
			}

			preferred_limit = {
				distance_from_realm = {
					who = PREV
					value >= 200
				}

				distance_from_realm = {
					who = PREV
					value < 800
				}

				is_nomadic = no
			}

			preferred_limit = {
				distance_from_realm = {
					who = PREV
					value >= 200
				}

				distance_from_realm = {
					who = PREV
					value < 800
				}

				NOT = {
					any_player = {
						same_realm = PREV
					}
				}
			}

			preferred_limit = {
				distance_from_realm = {
					who = PREV
					value >= 200
				}

				distance_from_realm = {
					who = PREV
					value < 800
				}
			}

			save_event_target_as = target_invasion_character
			capital_scope = { save_event_target_as = target_invasion_capital }
		}
	}

	option = { # Looking Inwards
		name = HF_231_OPTA

		trigger = { independent = no }

		custom_tooltip = { text = may_found_bloodline_tt }

		any_liege = {
			show_scope_change = no

			if = {
				limit = {
					event_target:child_of_destiny = {
						lower_real_tier_than = KING
					}
				}

				any_demesne_title = {
					show_scope_change = no

					limit = { higher_real_tier_than = COUNT }

					add_claim = event_target:child_of_destiny
				}
			}
			else = {
				any_demesne_title = {
					show_scope_change = no

					limit = { higher_tier_than = DUKE }

					add_claim = event_target:child_of_destiny
				}
			}

			add_rival = event_target:child_of_destiny
		}

		custom_tooltip = {
			text = army_of_destiny_tt

			while = {
				count = 3

				spawn_unit = {
					province = capital_scope
					home = capital_scope
					owner = THIS
					match_character = event_target:top_liege_match_target
					match_mult = 0.66
					match_min = 1000
					match_max = 10000
					reinforce_rate_multiplier = 0.25
					attrition = 0.25
					reinforces = yes
					merge = yes
					cannot_inherit = yes
				}

				spawn_unit = {
					province = capital_scope
					home = capital_scope
					owner = THIS
					match_character = event_target:top_liege_match_target
					match_mult = 0.66
					match_min = 1000
					match_max = 10000
					reinforce_rate_multiplier = 0.25
					attrition = 0.25
					reinforces = yes
					merge = yes
					cannot_inherit = yes
				}

				spawn_unit = {
					province = capital_scope
					home = capital_scope
					owner = THIS
					match_character = event_target:top_liege_match_target
					match_mult = 0.66
					match_min = 1000
					match_max = 10000
					reinforce_rate_multiplier = 0.25
					attrition = 0.25
					reinforces = yes
					merge = yes
					cannot_inherit = yes
				}
			}

			spawn_fleet = {
				province = closest # closest sea zone
				owner = THIS
				cannot_inherit = yes

				troops = {
					galleys = { 150 150 }
				}
			}
		}

		custom_tooltip = { text = no_inheritance_troops_tt }

		any_player = {
			limit = {
				NOT = { character = event_target:child_of_destiny }

				OR = {
					is_parent_of = event_target:child_of_destiny
					is_liege_or_above_of = event_target:child_of_destiny
				}
			}

			character_event = { id = HF.232 }
		}

		ai_chance = { factor = 90 }
	}

	option = { # Looking outwards
		name = HF_231_OPTB
		show_portrait = event_target:target_invasion_character

		trigger = { event_target:target_invasion_character = { always = yes } }

		custom_tooltip = { text = may_found_bloodline_tt }

		custom_tooltip = {
			text = disinherit_you_tt
			add_trait = disinherited
		}

		set_character_flag = child_of_destiny_outwards_focus

		custom_tooltip = {
			text = army_of_destiny_tt

			while = {
				count = 3

				spawn_unit = {
					province = capital_scope
					home = capital_scope
					owner = THIS
					match_character = event_target:target_invasion_character
					match_mult = 0.66
					match_min = 1000
					match_max = 10000
					reinforce_rate_multiplier = 0.25
					attrition = 0.25
					reinforces = yes
					merge = yes
					cannot_inherit = yes
				}
			}

			spawn_fleet = {
				province = closest # closest sea zone
				owner = THIS
				cannot_inherit = yes

				troops = {
					galleys = { 150 150 }
				}
			}
		}

		custom_tooltip = { text = no_inheritance_troops_tt }

		unsafe_war = {
			target = event_target:target_invasion_character
			casus_belli = kingdom_adventure
			thirdparty_title = event_target:target_invasion_capital
		}

		any_player = {
			limit = {
				NOT = { character = event_target:child_of_destiny }

				OR = {
					is_parent_of = event_target:child_of_destiny
					is_liege_or_above_of = event_target:child_of_destiny
				}
			}

			character_event = { id = HF.233 }
		}

		ai_chance = { factor = 10 }
	}

	option = { # Delay
		name = HF_231_OPTC

		clr_character_flag = child_of_destiny_made_player_choice

		ai_chance = { factor = 0 }
	}

	after = {
		# Back to the journey tombola!
		clear_event_target = target_invasion_character
		clear_event_target = top_liege_match_target

		character_event = {
			id = HF.210
			days = 365
			random = 500
		}
	}
}

character_event = { # Notification - Looking Inward
	id = HF.232
	desc = HF_232_DESC
	picture = GFX_evt_throne_room

	is_triggered_only = yes
	hide_new = yes

	option = {
		name = {
			text = HF_232_OPTA
			trigger = { is_parent_of = FROM }
		}
		name = {
			text = HF_232_OPTB
			trigger = { NOT = { is_parent_of = FROM } }
		}

		custom_tooltip = { text = child_claims_realm_tt }

		tooltip = {
			event_target:child_of_destiny = {
				show_scope_change = no

				any_liege = {
					show_scope_change = no

					add_rival = event_target:child_of_destiny
				}
			}
		}
	}
}

character_event = { # Notification - Looking Outward
	id = HF.233
	desc = HF_233_DESC
	picture = GFX_evt_throne_room

	is_triggered_only = yes
	hide_new = yes

	option = {
		name = {
			text = HF_233_OPTA
			trigger = { is_parent_of = FROM }
		}
		name = {
			text = HF_233_OPTB
			trigger = { NOT = { is_parent_of = FROM } }
		}

		custom_tooltip = { text = child_adventures_tt }
	}
}

# Overcome Hardship
character_event = {
	id = HF.234
	desc = HF_234_DESC
	picture = GFX_evt_recovery

	is_triggered_only = yes
	hide_new = yes

	option = {
		name = HF_234_OPTA

		remove_trait_silently_depressed_effect = yes
		remove_trait_silently_stressed_effect = yes
	}

	after = {
		# Back to the journey tombola!
		character_event = {
			id = HF.210
			days = 365
			random = 500
		}
	}
}

# Gain a Posse
character_event = {
	id = HF.235
	desc = HF_235_DESC
	picture = GFX_evt_child_talking

	is_triggered_only = yes
	hide_new = yes

	immediate = {
		set_character_flag = child_of_destiny_posse

		top_liege = {
			any_realm_character = {
				count = 3

				limit = {
					same_sex = event_target:child_of_destiny
					age >= 10
					is_adult = no
					ai = yes
					is_inaccessible_or_incapable_trigger = no

					NOR = {
						is_friend = event_target:child_of_destiny
						has_character_flag = posse@event_target:child_of_destiny
					}
				}

				set_character_flag = posse@event_target:child_of_destiny
			}
		}
	}

	option = { # They shall praise my name!
		name = HF_235_OPTA

		add_character_modifier = {
			name = charismatic_leader
			duration = -1
		}

		add_trait_fully_silently_proud_effect = yes

		ai_chance = { factor = 50 }
	}

	option = { # They shall die for me!
		name = HF_235_OPTB

		add_character_modifier = {
			name = ruthless_commander
			duration = -1
		}

		add_trait_fully_silently_cruel_effect = yes

		ai_chance = { factor = 50 }
	}

	after = {
		any_realm_character = {
			show_scope_change = no

			limit = { has_character_flag = posse@event_target:child_of_destiny }

			add_friend = event_target:child_of_destiny
			clr_character_flag = posse@event_target:child_of_destiny

			opinion = {
				name = opinion_loyal_servant
				who = event_target:child_of_destiny
				years = 100
			}
		}

		any_player = {
			limit = {
				NOT = { character = event_target:child_of_destiny }

				OR = {
					is_parent_of = event_target:child_of_destiny
					is_liege_of = event_target:child_of_destiny
				}
			}

			character_event = { id = HF.236 }
		}

		# Back to the journey tombola!
		character_event = {
			id = HF.210
			days = 365
			random = 500
		}
	}
}

# Notification - Gain a Posse
character_event = {
	id = HF.236
	desc = HF_236_DESC
	picture = GFX_evt_child_talking

	is_triggered_only = yes
	hide_new = yes

	option = {
		name = {
			text = HF_236_OPTA
			trigger = { is_parent_of = FROM }
		}
		name = {
			text = HF_236_OPTB
			trigger = { NOT = { is_parent_of = FROM } }
		}

		custom_tooltip = { text = childs_power_increases_tt }
	}
}

# Escape from Prison
character_event = {
	id = HF.237
	desc = HF_237_DESC
	picture = GFX_evt_into_the_dungeon
	portrait = event_target:jailer_target

	is_triggered_only = yes
	hide_new = yes

	immediate = {
		host = {
			save_event_target_as = jailer_target

			random_realm_character = {
				limit = {
					is_adult = yes
					is_ruler = no
					is_inaccessible_or_incapable_trigger = no

					NOR = {
						is_rival = event_target:child_of_destiny
						is_married = event_target:child_of_destiny
						is_consort = event_target:child_of_destiny
					}
				}

				preferred_limit = {
					is_rival = event_target:jailer_target

					NOR = {
						dynasty = event_target:jailer_target
						is_friend = event_target:jailer_target
						liege = { ai = yes }
					}
				}

				preferred_limit = {
					NOR = {
						dynasty = event_target:jailer_target
						is_friend = event_target:jailer_target
						liege = { ai = yes }
					}
				}

				preferred_limit = {
					is_rival = event_target:jailer_target

					NOR = {
						dynasty = event_target:jailer_target
						is_friend = event_target:jailer_target
					}
				}

				preferred_limit = {
					NOR = {
						dynasty = event_target:jailer_target
						is_friend = event_target:jailer_target
					}
				}

				save_event_target_as = savior_target
			}
		}
	}

	option = { # Escape!
		name = HF_237_OPTA

		imprison = no
		add_friend = event_target:savior_target

		if = {
			limit = { is_landed = yes }

			event_target:savior_target = {
				show_scope_change = no

				move_character = event_target:child_of_destiny
			}
		}

		event_target:jailer_target = {
			character_event = { id = HF.238 }
		}

		any_player = {
			limit = {
				NOR = {
					character = event_target:child_of_destiny
					character = event_target:jailer_target
				}

				OR = {
					is_parent_of = event_target:child_of_destiny
					is_liege_of = event_target:child_of_destiny
				}
			}

			character_event = { id = HF.239 }
		}
	}

	option = { # I will bide my time.
		name = HF_237_OPTB

		ai_chance = { factor = 0 }
	}

	after = {
		# Back to the journey tombola!
		clear_event_target = jailer_target
		clear_event_target = savior_target

		character_event = {
			id = HF.210
			days = 365
			random = 500
		}
	}
}

# Notification - Jailer gets to know of escape
character_event = {
	id = HF.238
	desc = HF_238_DESC
	picture = GFX_evt_into_the_dungeon
	portrait = event_target:child_of_destiny

	is_triggered_only = yes
	hide_new = yes

	ai = no

	option = {
		name = HF_238_OPTA

		show_portrait = event_target:savior_target

		tooltip = {
			event_target:child_of_destiny = {
				show_scope_change = no

				imprison = no
			}
		}
	}
}

# Notification - Child Escapes Prison
character_event = {
	id = HF.239
	picture = GFX_evt_into_the_dungeon
	portrait = event_target:child_of_destiny

	desc = {
		text = HF_239_DESCA
		trigger = {
			event_target:child_of_destiny = { is_landed = yes }
		}
	}
	desc = {
		text = HF_239_DESCB
		trigger = {
			event_target:child_of_destiny = { is_landed = no }
		}
	}

	is_triggered_only = yes
	hide_new = yes

	option = {
		name = HF_239_OPTA
		show_portrait = event_target:savior_target

		tooltip = {
			event_target:child_of_destiny = {
				show_scope_change = no

				imprison = no
			}
		}
	}
}

# Gain a friend
character_event = {
	id = HF.240
	desc = HF_240_DESC
	picture = GFX_evt_courtiers_talking

	is_triggered_only = yes
	hide_new = yes

	immediate = {
		top_liege = {
			# A Powerful Ruler
			random_realm_lord = {
				limit = {
					is_adult = yes
					ai = yes
					is_inaccessible_or_incapable_trigger = no

					NOR = {
						is_vassal_or_below_of = event_target:child_of_destiny
						is_close_relative = event_target:child_of_destiny
						is_rival = event_target:child_of_destiny
						is_lover = event_target:child_of_destiny
						is_friend = event_target:child_of_destiny
						character = event_target:child_of_destiny
					}
				}

				preferred_limit = { higher_real_tier_than = DUKE }
				preferred_limit = { higher_real_tier_than = COUNT }

				save_event_target_as = friend_target_1
			}

			# Someone who can help me further my goals
			random_realm_character = {
				limit = {
					is_adult = yes
					ai = yes
					is_inaccessible_or_incapable_trigger = no

					NOR = {
						is_vassal_or_below_of = event_target:child_of_destiny
						is_close_relative = event_target:child_of_destiny
						is_rival = event_target:child_of_destiny
						is_lover = event_target:child_of_destiny
						is_friend = event_target:child_of_destiny
						character = event_target:child_of_destiny
					}
				}

				preferred_limit = {
					has_job_title = job_spymaster
					same_liege = event_target:child_of_destiny
				}

				preferred_limit = {
					has_job_title = job_spymaster

					liege = {
						is_liege_or_above_of = event_target:child_of_destiny
					}
				}

				preferred_limit = {
					has_job_title = job_spymaster
					vassal_of = event_target:child_of_destiny
				}

				save_event_target_as = friend_target_2
			}

			# A competent character
			random_realm_character = {
				limit = {
					is_adult = yes
					ai = yes
					is_inaccessible_or_incapable_trigger = no

					NOR = {
						is_liege_or_above_of = event_target:child_of_destiny
						family = event_target:child_of_destiny
						is_rival = event_target:child_of_destiny
						is_lover = event_target:child_of_destiny
						is_friend = event_target:child_of_destiny
						character = event_target:child_of_destiny
						character = event_target:friend_target_1
						character = event_target:friend_target_2
					}
				}

				preferred_limit = {
					is_ruler = no
					diplomacy >= 12
					martial >= 12
					stewardship >= 12
					intrigue >= 12
					learning >= 12
				}

				preferred_limit = {
					is_ruler = no

					calc_true_if = {
						amount >= 4

						diplomacy >= 12
						martial >= 12
						stewardship >= 12
						intrigue >= 12
						learning >= 12
					}
				}

				preferred_limit = {
					is_ruler = no

					calc_true_if = {
						amount >= 3

						diplomacy >= 12
						martial >= 12
						stewardship >= 12
						intrigue >= 12
						learning >= 12
					}
				}

				preferred_limit = {
					diplomacy >= 12
					martial >= 12
					stewardship >= 12
					intrigue >= 12
					learning >= 12
				}

				preferred_limit = {
					calc_true_if = {
						amount >= 4

						diplomacy >= 12
						martial >= 12
						stewardship >= 12
						intrigue >= 12
						learning >= 12
					}
				}

				preferred_limit = {
					calc_true_if = {
						amount >= 3

						diplomacy >= 12
						martial >= 12
						stewardship >= 12
						intrigue >= 12
						learning >= 12
					}
				}

				save_event_target_as = friend_target_3
			}
		}
	}

	option = {
		name = HF_240_OPTA

		add_friend = event_target:friend_target_1
	}

	option = {
		name = HF_240_OPTB

		add_friend = event_target:friend_target_2

		event_target:friend_target_2 = {
			show_scope_change = no

			if = {
				limit = {
					is_ruler = no

					event_target:child_of_destiny = {
						is_ruler = yes
						NOT = { is_liege_of = PREV }
					}
				}

				move_character = event_target:child_of_destiny # CleanSlate: Doesn't this defeat the purpose of befriending your liege's spymaster?
			}
		}
	}

	option = {
		name = HF_240_OPTC

		add_friend = event_target:friend_target_3

		event_target:friend_target_3 = {
			show_scope_change = no

			if = {
				limit = {
					is_ruler = no

					event_target:child_of_destiny = {
						is_ruler = yes
						NOT = { is_liege_of = PREV }
					}
				}

				move_character = event_target:child_of_destiny
			}
		}
	}

	option = {
		name = HF_240_OPTD

		ai_chance = { factor = 0 }
	}

	after = {
		# Back to the journey tombola!
		clear_event_target = friend_target_1
		clear_event_target = friend_target_2
		clear_event_target = friend_target_3

		character_event = {
			id = HF.210
			days = 365
			random = 500
		}
	}
}

# Child of Destiny launches Adventure
character_event = {
	id = HF.290

	is_triggered_only = yes
	hide_window = yes
	hide_new = yes

	immediate = {
		set_character_flag = child_of_destiny_adventure
		save_event_target_as = child_of_destiny

		random_independent_ruler = {
			limit = {
				is_landed = yes
				realm_size >= 25
				is_tributary = no
				NOT = { is_vassal_or_below = event_target:child_of_destiny }
				ai = yes

				event_target:child_of_destiny = {
					top_liege = {
						distance_from_realm = {
							who = PREVPREV
							value < 1200
						}
					}

					NOR = {
						obedient = PREV
						non_interference = PREV
						has_non_aggression_pact_with = PREV
					}
				}
			}

			preferred_limit = {
				distance_from_realm = { who = PREV value >= 200 }
				distance_from_realm = { who = PREV value <  800 }
				is_nomadic = no

				NOT = {
					any_player = {
						same_realm = PREV
					}
				}
			}

			preferred_limit = {
				distance_from_realm = { who = PREV value >= 200 }
				distance_from_realm = { who = PREV value <  800 }
				is_nomadic = no
			}

			preferred_limit = {
				distance_from_realm = { who = PREV value >= 200 }
				distance_from_realm = { who = PREV value < 1000 }
				is_nomadic = no

				NOT = {
					any_player = {
						same_realm = PREV
					}
				}
			}

			preferred_limit = {
				distance_from_realm = { who = PREV value >= 200 }
				distance_from_realm = { who = PREV value < 1000 }
				is_nomadic = no
			}

			preferred_limit = {
				distance_from_realm = { who = PREV value >= 150 }
				distance_from_realm = { who = PREV value < 1100 }
				is_nomadic = no

				NOT = {
					any_player = {
						same_realm = PREV
					}
				}
			}

			preferred_limit = {
				distance_from_realm = { who = PREV value >= 150 }
				distance_from_realm = { who = PREV value < 1100 }
				is_nomadic = no
			}

			preferred_limit = {
				distance_from_realm = { who = PREV value >= 200 }
				distance_from_realm = { who = PREV value <  800 }

				NOT = {
					any_player = {
						same_realm = PREV
					}
				}
			}

			preferred_limit = {
				distance_from_realm = { who = PREV value >= 200 }
				distance_from_realm = { who = PREV value <  800 }
			}

			preferred_limit = {
				distance_from_realm = { who = PREV value >= 200 }
				distance_from_realm = { who = PREV value < 1000 }

				NOT = {
					any_player = {
						same_realm = PREV
					}
				}
			}

			preferred_limit = {
				distance_from_realm = { who = PREV value >= 200 }
				distance_from_realm = { who = PREV value < 1000 }
			}

			preferred_limit = {
				distance_from_realm = { who = PREV value >= 150 }
				distance_from_realm = { who = PREV value < 1100 }

				NOT = {
					any_player = {
						same_realm = PREV
					}
				}
			}

			preferred_limit = {
				distance_from_realm = { who = PREV value >= 150 }
				distance_from_realm = { who = PREV value < 1100 }
			}

			save_event_target_as = target_character

			random_realm_province = {
				limit = { held_under_PREV = yes }

				kingdom = {
					save_event_target_as = target_kingdom
				}
			}
		}

		if = {
			limit = { is_landed = yes }

			if = {
				limit = { independent = no }

				liege = { save_event_target_as = liege_title_target }
				any_demesne_title = {
					grant_title = event_target:liege_title_target
				}
				any_vassal = {
					set_defacto_liege = event_target:liege_title_target
				}
			}
			else = {
				transfer_crown_on_abdication_effect = yes
				abdicate = yes
			}
		}
		else = {
			liege = { save_event_target_as = liege_title_target }
		}

		liege = {
			capital_scope = {
				save_event_target_as = liege_capital
			}
		}

		set_defacto_liege = event_target:child_of_destiny

		create_title = {
			tier = DUKE
			landless = yes
			temporary = yes
			adventurer = yes
			culture = event_target:child_of_destiny
			name = CLAIMANT_ADVENTURE
			holder = event_target:child_of_destiny
		}

		set_character_flag = duchy_adventurer

		while = {
			count = 3

			spawn_unit = {
				province = event_target:liege_capital
				home = event_target:liege_capital
				owner = THIS
				match_character = event_target:target_character
				match_mult = 0.66
				match_min = 1000
				match_max = 10000
				reinforce_rate_multiplier = 0.25
				attrition = 0.25
				reinforces = yes
				merge = yes
				cannot_inherit = yes
			}
		}

		spawn_fleet = {
			province = closest # closest sea zone
			owner = THIS
			cannot_inherit = yes

			troops = {
				galleys = { 150 150 }
			}
		}

		unsafe_war = {
			target = event_target:target_character
			casus_belli = kingdom_adventure
			thirdparty_title = event_target:target_kingdom
		}

		if = { # If the war starts
			limit = {
				any_war = {
					using_cb = kingdom_adventure
				}
			}

			# Create some fantastic commander characters
			spawn_fantastic_commander_effect = yes
			spawn_fantastic_commander_effect = yes
			spawn_fantastic_commander_effect = yes
			add_trait = disinherited

			# Notify Parents
			any_player = {
				limit = {
					NOT = { character = event_target:child_of_destiny }

					OR = {
						is_parent_of = event_target:child_of_destiny
						character = event_target:liege_title_target
					}
				}

				character_event = { id = HF.291 }
			}
		}
		else = {
			# If the entire thing somehow fails, remove the flag and try again
			clr_character_flag = child_of_destiny_adventure
		}
	}

	after = { # Back to the journey tombola!
		character_event = {
			id = HF.210
			days = 365
			random = 500
		}
	}
}

# Notification - Launched Adventure
character_event = {
	id = HF.291
	desc = HF_291_DESC
	picture = GFX_evt_large_army
	portrait = event_target:child_of_destiny

	is_triggered_only = yes
	hide_new = yes

	option = {
		name = {
			text = HF_291_OPTA
			trigger = { is_parent_of = FROM }
		}
		name = {
			text = HF_291_OPTB
			trigger = { NOT = { is_parent_of = FROM } }
		}

		show_portrait = event_target:target_character
		custom_tooltip = { text = disinherit_tt }
	}
}

# Child of Destiny reaches adulthood
character_event = {
	id = HF.300
	desc = HF_300_DESC
	picture = GFX_evt_throne_room

	is_triggered_only = yes # on_adulthood

	has_character_flag = is_child_of_destiny

	immediate = {
		save_event_target_as = child_of_destiny
		clear_education_trait = yes
	}

	option = {
		name = HF_300_OPTA

		add_trait = brilliant_strategist
		add_trait_fully_silently_ambitious_effect = yes

		prestige = 500

		# Notify Parents
		any_player = {
			limit = {
				NOT = { character = event_target:child_of_destiny }

				OR = {
					is_parent_of = event_target:child_of_destiny
					is_liege_of = event_target:child_of_destiny
				}
			}

			character_event = { id = HF.301 }
		}
	}
}

# Notification - Reached Adulthood
character_event = {
	id = HF.301
	desc = HF_301_DESC
	picture = GFX_evt_throne_room
	portrait = event_target:child_of_destiny

	is_triggered_only = yes
	hide_new = yes

	option = {
		name = {
			text = HF_301_OPTA
			trigger = { is_parent_of = FROM }
		}
		name = {
			text = HF_301_OPTB
			trigger = { NOT = { is_parent_of = FROM } }
		}

		show_portrait = event_target:target_character
		custom_tooltip = { text = childs_power_increases_tt }
	}
}

# Child of Destiny gets extra stats
character_event = {
	id = HF.302

	is_triggered_only = yes # on_yearly_childhood_pulse
	hide_window = yes

	has_character_flag = is_child_of_destiny
	max_age = 16

	immediate = {
		random_list = {
			10 = { change_diplomacy = 2 }
			10 = { change_diplomacy = 1 }
			10 = { change_martial = 2 }
			10 = { change_martial = 1 }
			10 = { change_stewardship = 2 }
			10 = { change_stewardship = 1 }
			10 = { change_intrigue = 2 }
			10 = { change_intrigue = 1 }
			10 = { change_learning = 2 }
			10 = { change_learning = 1 }
		}
	}
}

# Child of Destiny can choose to adopt culture/religion of newly conquered land.
character_event = {
	id = HF.303
	desc = HF_303_DESC
	picture = GFX_evt_emissary

	is_triggered_only = yes # kingdom_adventure CB
	hide_new = yes
	hide_from = yes

	trigger = {
		NAND = {
			religion = capital_scope
			culture = capital_scope
		}
	}

	option = { # Adopt culture and religion
		name = HF_303_OPTA

		trigger = {
			NOR = {
				religion = capital_scope
				culture = capital_scope
			}
		}

		custom_tooltip = {
			text = adopt_culture_and_religion_tt

			culture = capital_scope
			religion = capital_scope

			any_child = {
				limit = {
					is_ruler = no
					ai = yes
				}

				culture = ROOT
				religion = ROOT
			}

			any_courtier = {
				limit = {
					is_ruler = no
					ai = yes
				}

				culture = ROOT
				religion = ROOT
			}
		}

		ai_chance = {
			factor = 50

			trigger = {
				NOT = { has_character_flag = ai_flag_refuse_conversion }
			}
		}
	}

	option = { # Adopt Culture
		name = HF_303_OPTB

		trigger = {
			NOT = { culture = capital_scope }
		}

		custom_tooltip = {
			text = adopt_culture_tt

			culture = capital_scope

			any_child = {
				limit = {
					is_ruler = no
					ai = yes
				}

				culture = ROOT
			}

			any_courtier = {
				limit = {
					is_ruler = no
					ai = yes
				}

				culture = ROOT
			}
		}

		ai_chance = { factor = 40 }
	}

	option = { # Adopt Religion
		name = HF_303_OPTC

		trigger = {
			NOT = { religion = capital_scope }
		}

		custom_tooltip = {
			text = adopt_religion_tt

			religion = capital_scope

			any_child = {
				limit = {
					is_ruler = no
					ai = yes
				}

				religion = ROOT
			}

			any_courtier = {
				limit = {
					is_ruler = no
					ai = yes
				}

				religion = ROOT
			}
		}

		ai_chance = {
			factor = 10

			trigger = {
				NOT = { has_character_flag = ai_flag_refuse_conversion }
			}
		}
	}

	option = { # Stay the same
		name = HF_303_OPTD

		ai_chance = { factor = 0 }
	}
}

# Child of Destiny gains bloodline
character_event = {
	id = HF.304
	desc = HF_304_DESC
	picture = GFX_evt_throne_room

	is_triggered_only = yes # on_yearly_pulse

	only_independent = yes
	has_character_flag = is_child_of_destiny

	trigger = {
		higher_real_tier_than = DUKE

		NOT = {
			any_owned_bloodline = {
				has_bloodline_flag = bloodline_ambition
				bloodline_is_active_for = PREV
			}
		}
	}

	immediate = {
		save_event_target_as = child_of_destiny
		set_global_flag = child_of_destiny_founded_bloodline_@ROOT

		change_variable = {
			which = global_children_of_destiny_bloodlines_founded
			value = 1
		}
	}

	option = {
		name = HF_304_OPTA

		if = {
			limit = { is_female = yes }

			create_bloodline = {
				type = child_of_destiny_bloodline
				inheritance = matrilineal
			}
		}
		else = {
			create_bloodline = { type = child_of_destiny_bloodline }
		}

		if = {
			limit = {
				this_has_cool_nickname_trigger = no
				this_has_super_cool_nickname_trigger = no
			}

			give_nickname = nick_the_great
		}

		prestige = 1000

		custom_tooltip = {
			text = invasions_limited_lifetime_tt

			if = {
				limit = { has_character_flag = child_of_destiny_outwards_focus }

				any_player = {
					narrative_event = { id = HF.305 }
				}
			}
		}
	}
}

narrative_event = {
	id = HF.305
	title = HF_305_TIT
	desc = HF_305_DESC
	picture = GFX_evt_spymaster
	border = GFX_event_narrative_frame_war
	portrait = event_target:child_of_destiny

	is_triggered_only = yes

	trigger = {
		NOT = { has_character_flag = is_child_of_destiny }
	}

	option = {
		name = HF_305_OPTA
	}
}

character_event = {
	id = HF.306
	desc = HF_306_DESC
	picture = GFX_evt_comet
	portrait = event_target:child_of_destiny

	is_triggered_only = yes

	option = {
		name = HF_306_OPTA

		custom_tooltip = { text = journey_begins_tt }
	}
}

# Debug event
character_event = {
	id = HF.307
	desc = HF_307_DESC
	picture = GFX_evt_comet

	is_triggered_only = yes
	portrait = event_target:child_of_destiny

	option = {
		name = HF_307_OPTA
	}
}