﻿#Events dealing with coming of age

namespace = coming_of_age

#Learning
#Stewardship
#Martial
#Intrigue
#Diplomacy


#Learning - notification event for child
#by Linnéa Thimrén and Petter Vilberg
coming_of_age.0001 = {
	title = coming_of_age.0001.t
	desc = {
		triggered_desc = {
			trigger = {
				exists = scope:educator
			}
			desc = {
				first_valid = {
					triggered_desc = {
						trigger = {
							has_character_flag = studied_confucian_education
						}
						desc = coming_of_age.0001.educator_confucian_education
					}
					triggered_desc = {
						trigger = {
							has_character_flag = studied_at_university
						}
						desc = coming_of_age.0001.educator_university
					}
					desc = coming_of_age.0001.educator
				}
			}
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					has_trait_rank = {
						trait = education_learning
						rank = 1
					}
				}
				desc = {
					desc = coming_of_age.0001.desc1
					first_valid = {
						triggered_desc = {
							trigger = {
								has_learning_education_affinity_childhood_trait_trigger = yes
							}
							desc = coming_of_age.0001.desc1_good_trait
						}
						triggered_desc = {
							trigger = {
								has_learning_education_disaffinity_childhood_trait_trigger = yes
							}
							desc = coming_of_age.0001.desc1_bad_trait
						}
						desc = coming_of_age.0001.desc1_fallback_trait
					}
				}
			}
			triggered_desc = {
				trigger = {
					has_trait_rank = {
						trait = education_learning
						rank = 2
					}
				}
				desc = {
					desc = coming_of_age.0001.desc2
					first_valid = {
						triggered_desc = {
							trigger = {
								has_learning_education_affinity_childhood_trait_trigger = yes
							}
							desc = coming_of_age.0001.desc2_good_trait
						}
						triggered_desc = {
							trigger = {
								has_learning_education_disaffinity_childhood_trait_trigger = yes
							}
							desc = coming_of_age.0001.desc2_bad_trait
						}
						desc = coming_of_age.0001.desc2_fallback_trait
					}
				}
			}
			triggered_desc = {
				trigger = {
					has_trait_rank = {
						trait = education_learning
						rank = 3
					}
				}
				desc = {
					desc = coming_of_age.0001.desc3
					first_valid = {
						triggered_desc = {
							trigger = {
								has_learning_education_affinity_childhood_trait_trigger = yes
							}
							desc = coming_of_age.0001.desc3_good_trait
						}
						triggered_desc = {
							trigger = {
								has_learning_education_disaffinity_childhood_trait_trigger = yes
							}
							desc = coming_of_age.0001.desc3_bad_trait
						}
						desc = coming_of_age.0001.desc3_fallback_trait
					}
				}
			}
			triggered_desc = {
				trigger = {
					has_trait_rank = {
						trait = education_learning
						rank >= 4
					}
				}
				desc = {
					desc = coming_of_age.0001.desc4
					first_valid = {
						triggered_desc = {
							trigger = {
								has_learning_education_affinity_childhood_trait_trigger = yes
							}
							desc = coming_of_age.0001.desc4_good_trait
						}
						triggered_desc = {
							trigger = {
								has_learning_education_disaffinity_childhood_trait_trigger = yes
							}
							desc = coming_of_age.0001.desc4_bad_trait
						}
						desc = coming_of_age.0001.desc4_fallback_trait
					}
				}
			}
		}
		first_valid = { #If a learned court owner spouse has improved education
			triggered_desc = {
				trigger = {
					exists = scope:education_rank_patronage_bonus
					scope:education_rank_patronage_bonus = flag:1
				}
				desc = coming_of_age.0001.patronaged_spouse_plus_1.desc
			}
			triggered_desc = {
				trigger = {
					exists = scope:education_rank_patronage_bonus
					scope:education_rank_patronage_bonus = flag:2_or_more
				}
				desc = coming_of_age.0001.patronaged_spouse_plus_2_or_more.desc
			}
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					OR = {
						any_relation = { type = friend always = yes }
						exists = var:had_childhood_crush_variable
						exists = var:had_childhood_bully_variable
						exists = var:had_childhood_victim_variable
					}
				}
				desc = {
					desc = coming_of_age.0001.relationships
					triggered_desc = {
						trigger = {
							any_relation = { type = friend always = yes }
						}
						desc = coming_of_age.0001.friend
					}
					triggered_desc = {
						trigger = {
							exists = var:had_childhood_crush_variable
						}
						desc = coming_of_age.0001.crush
					}
					first_valid = {
						triggered_desc = {
							trigger = {
								AND = {
									exists = var:had_childhood_bully_variable
									NOT = { has_character_flag = bully_destroyed_toy }
								}
							}
							desc = coming_of_age.0001.bully1
						}
						triggered_desc = {
							trigger = {
								AND = {
									exists = var:had_childhood_bully_variable
									has_character_flag = bully_destroyed_toy
								}
							}
							desc = coming_of_age.0001.bully2
						}
					}
					first_valid = {
						triggered_desc = {
							trigger = {
								AND = {
									exists = var:had_childhood_victim_variable
									scope:victim = {
										NOT = { has_character_flag = bully_destroyed_toy }
									}
								}
							}
							desc = coming_of_age.0001.victim1
						}
						triggered_desc = {
							trigger = {
								AND = {
									exists = var:had_childhood_victim_variable
									scope:victim = {
										has_character_flag = bully_destroyed_toy
									}
								}
							}
							desc = coming_of_age.0001.victim2
						}
					}
					triggered_desc = {
						trigger = {
							any_relation = { type = friend always = no }
						}
						desc = coming_of_age.0001.relationships_end
					}
				}
			}
			triggered_desc = {
				trigger = {
					NOR = {
						any_relation = { type = friend always = yes }
						exists = var:had_childhood_crush_variable
						exists = var:had_childhood_bully_variable
						exists = var:had_childhood_victim_variable
					}
				}
				desc = coming_of_age.0001.no_relationships
			}
		}
	}
	theme = education
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = {
				has_focus = education_martial
			}
  			animation = marshal
  		}
		triggered_animation = {
			trigger = {
				has_focus = education_learning
			}
  			animation = personality_rational
  		}
		triggered_animation = {
			trigger = {
				has_focus = education_stewardship
			}
  			animation = steward
  		}
		triggered_animation = {
			trigger = {
				has_focus = education_intrigue
			}
  			animation = spymaster
  		}
		triggered_animation = {
			trigger = {
				has_focus = education_diplomacy
			}
  			animation = flirtation_left
  		}
		animation = idle
	}
	override_background = {
		trigger = {
			has_focus = education_martial
		}
		reference = courtyard
	}
	override_background = {
		trigger = {
			has_focus = education_diplomacy
			culture = {
				OR = {
					has_building_gfx = western_building_gfx
					has_building_gfx = mediterranean_building_gfx
				}
			}
		}
		reference = council_chamber
	}
	override_background = {
		trigger = {
			has_focus = education_diplomacy
			culture = {
				OR = {
					has_building_gfx = western_building_gfx
					has_building_gfx = mediterranean_building_gfx
				}
			}
		}
		reference = throne_room
	}
	override_background = {
		trigger = {
			has_focus = education_intrigue
			culture = {
				OR = {
					has_building_gfx = western_building_gfx
					has_building_gfx = mediterranean_building_gfx
				}
			}
		}
		reference = physicians_study
	}
	override_background = {
		trigger = {
			has_focus = education_intrigue
			culture = {
				NOR = {
					has_building_gfx = western_building_gfx
					has_building_gfx = mediterranean_building_gfx
				}
			}
		}
		reference = relaxing_room
	}
	override_background = {
		trigger = {
			has_focus = education_stewardship
		}
		reference = market
	}
	override_background = {
		trigger = {
			has_focus = education_learning
			culture = {
				NOR = {
					has_building_gfx = western_building_gfx
					has_building_gfx = mediterranean_building_gfx
				}
			}
		}
		reference = temple
	}
	
	trigger = {
		OR = {
			has_focus = education_learning
			NOR = {
				has_focus = education_learning
				has_focus = education_diplomacy
				has_focus = education_intrigue
				has_focus = education_martial
				has_focus = education_stewardship
			}
		}
		NOR = {  # In case a character start with an education trait from the ruler designer
			has_trait = education_learning
			has_trait = education_diplomacy
			has_trait = education_intrigue
			has_trait = education_martial
			has_trait = education_stewardship
		}
	}

	immediate = {
		play_music_cue = "mx_cue_positive_effect"
		save_event_targets_from_childhood_effect = yes
		if = {
			limit = {
				any_relation = {
					type = guardian
				}
			}
			random_relation = {
				type = guardian
				save_scope_as = educator
			}
		}
		else = {
			court_owner.court_position:court_tutor_court_position ?= {
				save_scope_as = educator
			}
		}
		results_of_patronage_spouse_education_points_effect = yes #patronage/high learning spouses of court owner can add points
		results_of_university_education_points_effect = yes #Did you send the child to university? Lucky them!
		results_of_confucian_education_effect = yes #Ward learned from a Confucian scholar
		dynasty_legacy_education_boost_effect = yes # Adds a few points if you have the second Kin legacy
		cultural_traditions_education_boost_effect = yes # Adds points based on Cultural Traditions
		court_tutor_education_boost_effect = yes # A Court Tutor gives a better education
		if = {
			limit= {
				NOT = {
					exists = var:education_learning_variable
				}
			}
			
			set_trait_rank = {
				trait = education_learning
				rank = 1
			}
		}
		else_if = {
			limit = {
				var:education_learning_variable <= education_level_1
			}
			
			set_trait_rank = {
				trait = education_learning
				rank = 1
			}
		}
		else_if = {
			limit = {
				var:education_learning_variable <= education_level_2
			}
			
			set_trait_rank = {
				trait = education_learning
				rank = 2
			}
		}
		else_if = {
			limit = {
				var:education_learning_variable <= education_level_3
			}
			
			set_trait_rank = {
				trait = education_learning
				rank = 3
			}
		}
		else = {
			random_list = {
				50 = {
					set_trait_rank = {
						trait = education_learning
						rank = 4
					}
				}
				50 = {
					trigger = {
						OR = {
							dynasty ?= { exists = var:ce1_legitimacy_legacy_5_education_learning_5 }
							
							# If you have an Estate with the relevant upgrade, or if your liege has one (assuming you are not a ruler yourself)
							domicile ?= { has_domicile_parameter = estate_unlock_tier_5_education }
							AND = {
								is_ruler = no
								liege ?= {
									domicile ?= { has_domicile_parameter = estate_unlock_tier_5_education }
								}
							}
						}
					}
					set_trait_rank = {
						trait = education_learning
						rank = 5
					}
				}
			}
		}

		#Chance of gaining Mystic if your religion or educator's religion is esoteric
		if = {
			limit = {
				faith = {
					has_doctrine_parameter = tenet_esotericism_mystic_education
				}
			}
			random = {
				chance = 5
				modifier = {
					add = 5
					has_trait_rank = {
						trait = education_learning
						rank > 1
					}
				}
				modifier = {
					add = 10
					has_trait_rank = {
						trait = education_learning
						rank > 2
					}
				}
				modifier = {
					add = 10
					has_trait_rank = {
						trait = education_learning
						rank > 3
					}
				}
				add_trait = lifestyle_mystic
			}
			
			#Secondary chance if your tutor also has an esoteric faith
			if = {
				limit = {
					NOT = { has_trait = lifestyle_mystic }
					exists = scope:educator
					scope:educator.faith = {
						has_doctrine_parameter = tenet_esotericism_mystic_education
					}
				}
				random = {
					chance = 5
					modifier = {
						add = 5
						scope:educator = {
							has_trait_rank = {
								trait = education_learning
								rank > 1
							}
						}
					}
					modifier = {
						add = 10
						scope:educator = {
							has_trait_rank = {
								trait = education_learning
								rank > 2
							}
						}
					}
					modifier = {
						add = 10
						scope:educator = {
							has_trait_rank = {
								trait = education_learning
								rank > 3
							}
						}
					}
					add_trait = lifestyle_mystic
				}
			}
		}
		dynasty_perk_secondary_education_trait_effect = yes
		post_education_bonuses_effect = yes
		save_childhood_trait_as_variable_effect = yes
		education_complete_notification_effect = yes
		wrap_up_education_effect = yes
		custom_tooltip_learning_coming_of_age_effect = yes

	}

	option = {
		name = coming_of_age.0001.a
	}

	after = {

		hidden_effect = { 
			apply_hold_court_grace_effect = yes
		}
	}
}

#Stewardship - notification event for child
#by Linnéa Thimrén and Petter Vilberg
coming_of_age.0002 = {
	title = coming_of_age.0001.t
	desc = {
		triggered_desc = {
			trigger = {
				exists = scope:educator
			}
			desc = {
				first_valid = {
					triggered_desc = {
						trigger = {
							has_character_flag = studied_confucian_education
						}
						desc = coming_of_age.0001.educator_confucian_education
					}
					triggered_desc = {
						trigger = {
							has_character_flag = studied_at_university
						}
						desc = coming_of_age.0001.educator_university
					}
					desc = coming_of_age.0001.educator
				}
			}
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					has_trait_rank = {
						trait = education_stewardship
						rank = 1
					}
				}
				desc = {
					desc = coming_of_age.0001.desc1
					first_valid = {
						triggered_desc = {
							trigger = {
								has_stewardship_education_affinity_childhood_trait_trigger = yes
							}
							desc = coming_of_age.0001.desc1_good_trait
						}
						triggered_desc = {
							trigger = {
								has_stewardship_education_disaffinity_childhood_trait_trigger = yes
							}
							desc = coming_of_age.0001.desc1_bad_trait
						}
						desc = coming_of_age.0001.desc1_fallback_trait
					}
				}
			}
			triggered_desc = {
				trigger = {
					has_trait_rank = {
						trait = education_stewardship
						rank = 2
					}
				}
				desc = {
					desc = coming_of_age.0001.desc2
					first_valid = {
						triggered_desc = {
							trigger = {
								has_stewardship_education_affinity_childhood_trait_trigger = yes
							}
							desc = coming_of_age.0001.desc2_good_trait
						}
						triggered_desc = {
							trigger = {
								has_stewardship_education_disaffinity_childhood_trait_trigger = yes
							}
							desc = coming_of_age.0001.desc2_bad_trait
						}
						desc = coming_of_age.0001.desc2_fallback_trait
					}
				}
			}
			triggered_desc = {
				trigger = {
					has_trait_rank = {
						trait = education_stewardship
						rank = 3
					}
				}
				desc = {
					desc = coming_of_age.0001.desc3
					first_valid = {
						triggered_desc = {
							trigger = {
								has_stewardship_education_affinity_childhood_trait_trigger = yes
							}
							desc = coming_of_age.0001.desc3_good_trait
						}
						triggered_desc = {
							trigger = {
								has_stewardship_education_disaffinity_childhood_trait_trigger = yes
							}
							desc = coming_of_age.0001.desc3_bad_trait
						}
						desc = coming_of_age.0001.desc3_fallback_trait
					}
				}
			}
			triggered_desc = {
				trigger = {
					has_trait_rank = {
						trait = education_stewardship
						rank >= 4
					}
				}
				desc = {
					desc = coming_of_age.0001.desc4
					first_valid = {
						triggered_desc = {
							trigger = {
								has_stewardship_education_affinity_childhood_trait_trigger = yes
							}
							desc = coming_of_age.0001.desc4_good_trait
						}
						triggered_desc = {
							trigger = {
								has_stewardship_education_disaffinity_childhood_trait_trigger = yes
							}
							desc = coming_of_age.0001.desc4_bad_trait
						}
						desc = coming_of_age.0001.desc4_fallback_trait
					}
				}
			}
		}
		first_valid = { #If a learned court owner spouse has improved education
			triggered_desc = {
				trigger = {
					exists = scope:education_rank_patronage_bonus
					scope:education_rank_patronage_bonus = flag:1
				}
				desc = coming_of_age.0001.patronaged_spouse_plus_1.desc
			}
			triggered_desc = {
				trigger = {
					exists = scope:education_rank_patronage_bonus
					scope:education_rank_patronage_bonus = flag:2_or_more
				}
				desc = coming_of_age.0001.patronaged_spouse_plus_2_or_more.desc
			}
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					OR = {
						any_relation = { type = friend always = yes }
						exists = var:had_childhood_crush_variable
						exists = var:had_childhood_bully_variable
						exists = var:had_childhood_victim_variable
					}
				}
				desc = {
					desc = coming_of_age.0001.relationships
					triggered_desc = {
						trigger = {
							any_relation = { type = friend always = yes }
						}
						desc = coming_of_age.0001.friend
					}
					triggered_desc = {
						trigger = {
							exists = var:had_childhood_crush_variable
						}
						desc = coming_of_age.0001.crush
					}
					first_valid = {
						triggered_desc = {
							trigger = {
								AND = {
									exists = var:had_childhood_bully_variable
									NOT = { has_character_flag = bully_destroyed_toy }
								}
							}
							desc = coming_of_age.0001.bully1
						}
						triggered_desc = {
							trigger = {
								AND = {
									exists = var:had_childhood_bully_variable
									has_character_flag = bully_destroyed_toy
								}
							}
							desc = coming_of_age.0001.bully2
						}
					}
					first_valid = {
						triggered_desc = {
							trigger = {
								AND = {
									exists = var:had_childhood_victim_variable
									scope:victim = {
										NOT = { has_character_flag = bully_destroyed_toy }
									}
								}
							}
							desc = coming_of_age.0001.victim1
						}
						triggered_desc = {
							trigger = {
								AND = {
									exists = var:had_childhood_victim_variable
									scope:victim = {
										has_character_flag = bully_destroyed_toy
									}
								}
							}
							desc = coming_of_age.0001.victim2
						}
					}
					triggered_desc = {
						trigger = {
							any_relation = { type = friend always = no }
						}
						desc = coming_of_age.0001.relationships_end
					}
				}
			}
			triggered_desc = {
				trigger = {
					NOR = {
						any_relation = { type = friend always = yes }
						exists = var:had_childhood_crush_variable
						exists = var:had_childhood_bully_variable
						exists = var:had_childhood_victim_variable
					}
				}
				desc = coming_of_age.0001.no_relationships
			}
		}
	}
	theme = education
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = {
				has_focus = education_martial
			}
  			animation = marshal
  		}
		triggered_animation = {
			trigger = {
				has_focus = education_learning
			}
  			animation = personality_rational
  		}
		triggered_animation = {
			trigger = {
				has_focus = education_stewardship
			}
  			animation = steward
  		}
		triggered_animation = {
			trigger = {
				has_focus = education_intrigue
			}
  			animation = spymaster
  		}
		triggered_animation = {
			trigger = {
				has_focus = education_diplomacy
			}
  			animation = flirtation_left
  		}
		animation = idle
	}
	override_background = {
		trigger = {
			has_focus = education_martial
		}
		reference = courtyard
	}
	override_background = {
		trigger = {
			has_focus = education_diplomacy
			culture = {
				OR = {
					has_building_gfx = western_building_gfx
					has_building_gfx = mediterranean_building_gfx
				}
			}
		}
		reference = council_chamber
	}
	override_background = {
		trigger = {
			has_focus = education_diplomacy
			culture = {
				OR = {
					has_building_gfx = western_building_gfx
					has_building_gfx = mediterranean_building_gfx
				}
			}
		}
		reference = throne_room
	}
	override_background = {
		trigger = {
			has_focus = education_intrigue
			culture = {
				OR = {
					has_building_gfx = western_building_gfx
					has_building_gfx = mediterranean_building_gfx
				}
			}
		}
		reference = physicians_study
	}
	override_background = {
		trigger = {
			has_focus = education_intrigue
			culture = {
				NOR = {
					has_building_gfx = western_building_gfx
					has_building_gfx = mediterranean_building_gfx
				}
			}
		}
		reference = relaxing_room
	}
	override_background = {
		trigger = {
			has_focus = education_stewardship
		}
		reference = market
	}
	override_background = {
		trigger = {
			has_focus = education_learning
			culture = {
				NOR = {
					has_building_gfx = western_building_gfx
					has_building_gfx = mediterranean_building_gfx
				}
			}
		}
		reference = temple
	}
	
	trigger = {
		has_focus = education_stewardship
		NOR = {  # In case a character start with an education trait from the ruler designer
			has_trait = education_learning
			has_trait = education_diplomacy
			has_trait = education_intrigue
			has_trait = education_martial
			has_trait = education_stewardship
		}
	}

	immediate = {
		play_music_cue = "mx_cue_positive_effect"
		save_event_targets_from_childhood_effect = yes
		if = {
			limit = {
				any_relation = {
					type = guardian
				}
			}
			random_relation = {
				type = guardian
				save_scope_as = educator
			}
		}
		else = {
			court_owner.court_position:court_tutor_court_position ?= {
				save_scope_as = educator
			}
		}
		results_of_patronage_spouse_education_points_effect = yes #patronage/high learning spouses of court owner can add points
		results_of_university_education_points_effect = yes #Did you send the child to university? Lucky them!
		results_of_confucian_education_effect = yes #Ward learned from a Confucian scholar
		dynasty_legacy_education_boost_effect = yes # Adds a few points if you have the second Kin legacy
		cultural_traditions_education_boost_effect = yes # Adds points based on Cultural Traditions
		court_tutor_education_boost_effect = yes # A Court Tutor gives a better education
		if = {
			limit = {
				var:education_stewardship_variable <= education_level_1
			}
			
			set_trait_rank = {
				trait = education_stewardship
				rank = 1
			}
		}
		else_if = {
			limit = {
				var:education_stewardship_variable <= education_level_2
			}
			
			set_trait_rank = {
				trait = education_stewardship
				rank = 2
			}
		}
		else_if = {
			limit = {
				var:education_stewardship_variable <= education_level_3
			}
			
			set_trait_rank = {
				trait = education_stewardship
				rank = 3
			}
		}
		else = {
			random_list = {
				50 = {
					set_trait_rank = {
						trait = education_stewardship
						rank = 4
					}
				}
				50 = {
					trigger = {
						OR = {
							dynasty ?= { exists = var:ce1_legitimacy_legacy_5_education_stewardship_5 }
							
							# If you have an Estate with the relevant upgrade, or if your liege has one (assuming you are not a ruler yourself)
							domicile ?= { has_domicile_parameter = estate_unlock_tier_5_education }
							AND = {
								is_ruler = no
								liege ?= {
									domicile ?= { has_domicile_parameter = estate_unlock_tier_5_education }
								}
							}
						}
					}
					set_trait_rank = {
						trait = education_stewardship
						rank = 5
					}
				}
			}
		}
		dynasty_perk_secondary_education_trait_effect = yes
		post_education_bonuses_effect = yes
		save_childhood_trait_as_variable_effect = yes
		education_complete_notification_effect = yes
		wrap_up_education_effect = yes
		custom_tooltip_stewardship_coming_of_age_effect = yes
	}

	option = {
		name = coming_of_age.0001.a
	}
	after = {
		hidden_effect = { 
			apply_hold_court_grace_effect = yes #start the grace period for hold court 
		}
	}
}


#Martial - notification event for child
#by Linnéa Thimrén and Petter Vilberg
coming_of_age.0003 = {
	title = coming_of_age.0001.t
	desc = {
		triggered_desc = {
			trigger = {
				exists = scope:educator
			}
			desc = {
				first_valid = {
					triggered_desc = {
						trigger = {
							has_character_flag = studied_confucian_education
						}
						desc = coming_of_age.0001.educator_confucian_education
					}
					triggered_desc = {
						trigger = {
							has_character_flag = studied_at_university
						}
						desc = coming_of_age.0001.educator_university
					}
					desc = coming_of_age.0001.educator
				}
			}
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					has_trait_rank = {
						trait = education_martial
						rank = 1
					}
				}
				desc = {
					desc = coming_of_age.0001.desc1
					first_valid = {
						triggered_desc = {
							trigger = {
								has_martial_education_affinity_childhood_trait_trigger = yes
							}
							desc = coming_of_age.0001.desc1_good_trait
						}
						triggered_desc = {
							trigger = {
								has_martial_education_disaffinity_childhood_trait_trigger = yes
							}
							desc = coming_of_age.0001.desc1_bad_trait
						}
						desc = coming_of_age.0001.desc1_fallback_trait
					}
				}
			}
			triggered_desc = {
				trigger = {
					has_trait_rank = {
						trait = education_martial
						rank = 2
					}
				}
				desc = {
					desc = coming_of_age.0001.desc2
					first_valid = {
						triggered_desc = {
							trigger = {
								has_martial_education_affinity_childhood_trait_trigger = yes
							}
							desc = coming_of_age.0001.desc2_good_trait
						}
						triggered_desc = {
							trigger = {
								has_martial_education_disaffinity_childhood_trait_trigger = yes
							}
							desc = coming_of_age.0001.desc2_bad_trait
						}
						desc = coming_of_age.0001.desc2_fallback_trait
					}
				}
			}
			triggered_desc = {
				trigger = {
					has_trait_rank = {
						trait = education_martial
						rank = 3
					}
				}
				desc = {
					desc = coming_of_age.0001.desc3
					first_valid = {
						triggered_desc = {
							trigger = {
								has_martial_education_affinity_childhood_trait_trigger = yes
							}
							desc = coming_of_age.0001.desc3_good_trait
						}
						triggered_desc = {
							trigger = {
								has_martial_education_disaffinity_childhood_trait_trigger = yes
							}
							desc = coming_of_age.0001.desc3_bad_trait
						}
						desc = coming_of_age.0001.desc3_fallback_trait
					}
				}
			}
			triggered_desc = {
				trigger = {
					has_trait_rank = {
						trait = education_martial
						rank >= 4
					}
				}
				desc = {
					desc = coming_of_age.0001.desc4
					first_valid = {
						triggered_desc = {
							trigger = {
								has_martial_education_affinity_childhood_trait_trigger = yes
							}
							desc = coming_of_age.0001.desc4_good_trait
						}
						triggered_desc = {
							trigger = {
								has_martial_education_disaffinity_childhood_trait_trigger = yes
							}
							desc = coming_of_age.0001.desc4_bad_trait
						}
						desc = coming_of_age.0001.desc4_fallback_trait
					}
				}
			}
		}
		first_valid = { #If a learned court owner spouse has improved education
			triggered_desc = {
				trigger = {
					exists = scope:education_rank_patronage_bonus
					scope:education_rank_patronage_bonus = flag:1
				}
				desc = coming_of_age.0001.patronaged_spouse_plus_1.desc
			}
			triggered_desc = {
				trigger = {
					exists = scope:education_rank_patronage_bonus
					scope:education_rank_patronage_bonus = flag:2_or_more
				}
				desc = coming_of_age.0001.patronaged_spouse_plus_2_or_more.desc
			}
		}
		triggered_desc = {
			trigger = {
				OR = {
					has_trait = education_martial_prowess_1
					has_trait = education_martial_prowess_2
					has_trait = education_martial_prowess_3
					has_trait = education_martial_prowess_4
				}
			}
			desc = coming_of_age.0003.desc_child_start
		}
		first_valid = {
			triggered_desc = {
				trigger = { has_trait = education_martial_prowess_1 }
				desc = coming_of_age.0003.desc_child_1
			}
			triggered_desc = {
				trigger = { has_trait = education_martial_prowess_2 }
				desc = coming_of_age.0003.desc_child_2
			}
			triggered_desc = {
				trigger = { has_trait = education_martial_prowess_3 }
				desc = coming_of_age.0003.desc_child_3
			}
			triggered_desc = {
				trigger = { has_trait = education_martial_prowess_4 }
				desc = coming_of_age.0003.desc_child_4
			}
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					OR = {
						any_relation = { type = friend always = yes }
						exists = var:had_childhood_crush_variable
						exists = var:had_childhood_bully_variable
						exists = var:had_childhood_victim_variable
					}
				}
				desc = {
					desc = coming_of_age.0001.relationships
					triggered_desc = {
						trigger = {
							any_relation = { type = friend always = yes }
						}
						desc = coming_of_age.0001.friend
					}
					triggered_desc = {
						trigger = {
							exists = var:had_childhood_crush_variable
						}
						desc = coming_of_age.0001.crush
					}
					first_valid = {
						triggered_desc = {
							trigger = {
								AND = {
									exists = var:had_childhood_bully_variable
									NOT = { has_character_flag = bully_destroyed_toy }
								}
							}
							desc = coming_of_age.0001.bully1
						}
						triggered_desc = {
							trigger = {
								AND = {
									exists = var:had_childhood_bully_variable
									has_character_flag = bully_destroyed_toy
								}
							}
							desc = coming_of_age.0001.bully2
						}
					}
					first_valid = {
						triggered_desc = {
							trigger = {
								AND = {
									exists = var:had_childhood_victim_variable
									scope:victim = {
										NOT = { has_character_flag = bully_destroyed_toy }
									}
								}
							}
							desc = coming_of_age.0001.victim1
						}
						triggered_desc = {
							trigger = {
								AND = {
									exists = var:had_childhood_victim_variable
									scope:victim = {
										has_character_flag = bully_destroyed_toy
									}
								}
							}
							desc = coming_of_age.0001.victim2
						}
					}
					triggered_desc = {
						trigger = {
							any_relation = { type = friend always = no }
						}
						desc = coming_of_age.0001.relationships_end
					}
				}
			}
			triggered_desc = {
				trigger = {
					NOR = {
						any_relation = { type = friend always = yes }
						exists = var:had_childhood_crush_variable
						exists = var:had_childhood_bully_variable
						exists = var:had_childhood_victim_variable
					}
				}
				desc = coming_of_age.0001.no_relationships
			}
		}
	}
	theme = education
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = {
				has_focus = education_martial
			}
  			animation = marshal
  		}
		triggered_animation = {
			trigger = {
				has_focus = education_learning
			}
  			animation = personality_rational
  		}
		triggered_animation = {
			trigger = {
				has_focus = education_stewardship
			}
  			animation = steward
  		}
		triggered_animation = {
			trigger = {
				has_focus = education_intrigue
			}
  			animation = spymaster
  		}
		triggered_animation = {
			trigger = {
				has_focus = education_diplomacy
			}
  			animation = flirtation_left
  		}
		animation = idle
	}
	override_background = {
		trigger = {
			has_focus = education_martial
		}
		reference = courtyard
	}
	override_background = {
		trigger = {
			has_focus = education_diplomacy
			culture = {
				OR = {
					has_building_gfx = western_building_gfx
					has_building_gfx = mediterranean_building_gfx
				}
			}
		}
		reference = council_chamber
	}
	override_background = {
		trigger = {
			has_focus = education_diplomacy
			culture = {
				NOR = {
					has_building_gfx = western_building_gfx
					has_building_gfx = mediterranean_building_gfx
				}
			}
		}
		reference = throne_room
	}
	override_background = {
		trigger = {
			has_focus = education_intrigue
			culture = {
				OR = {
					has_building_gfx = western_building_gfx
					has_building_gfx = mediterranean_building_gfx
				}
			}
		}
		reference = physicians_study
	}
	override_background = {
		trigger = {
			has_focus = education_intrigue
			culture = {
				NOR = {
					has_building_gfx = western_building_gfx
					has_building_gfx = mediterranean_building_gfx
				}
			}
		}
		reference = study
	}
	override_background = {
		trigger = {
			has_focus = education_stewardship
		}
		reference = market
	}
	override_background = {
		trigger = {
			has_focus = education_learning
			culture = {
				NOR = {
					has_building_gfx = indian_building_gfx
					has_building_gfx = western_building_gfx
					has_building_gfx = mediterranean_building_gfx
				}
			}
		}
		reference = temple
	}
	
	trigger = {
		has_focus = education_martial
		NOR = {  # In case a character start with an education trait from the ruler designer
			has_trait = education_learning
			has_trait = education_diplomacy
			has_trait = education_intrigue
			has_trait = education_martial
			has_trait = education_stewardship
		}
	}

	immediate = {
		play_music_cue = "mx_cue_positive_effect"
		save_event_targets_from_childhood_effect = yes
		if = {
			limit = {
				any_relation = {
					type = guardian
				}
			}
			random_relation = {
				type = guardian
				save_scope_as = educator
			}
		}
		else = {
			court_owner.court_position:court_tutor_court_position ?= {
				save_scope_as = educator
			}
		}
		results_of_patronage_spouse_education_points_effect = yes #patronage/high learning spouses of court owner can add points
		results_of_university_education_points_effect = yes #Did you send the child to university? Lucky them! Unless you wanted a knight, in which case they spend time book-learning rather than squiring.
		results_of_confucian_education_effect = yes #Ward learned from a Confucian scholar
		dynasty_legacy_education_boost_effect = yes # Adds a few points if you have the second Kin legacy
		cultural_traditions_education_boost_effect = yes # Adds points based on Cultural Traditions
		court_tutor_education_boost_effect = yes # A Court Tutor gives a better education
		huntperson_camp_officer_education_boost_effect = yes #A huntperson gives better Martial education
		tgp_japan_schoolhouse_education_boost_effect = yes #A manor building gives better educations
		#Martial trait acquisition.
		if = {
			limit = {
				var:education_martial_variable <= education_level_1
			}
			
			set_trait_rank = {
				trait = education_martial
				rank = 1
			}
		}
		else_if = {
			limit = {
				var:education_martial_variable <= education_level_2
			}
			
			set_trait_rank = {
				trait = education_martial
				rank = 2
			}
		}
		else_if = {
			limit = {
				var:education_martial_variable <= education_level_3
			}
			
			set_trait_rank = {
				trait = education_martial
				rank = 3
			}
		}
		else = {
			random_list = {
				50 = {
					set_trait_rank = {
						trait = education_martial
						rank = 4
					}
				}
				50 = {
					trigger = {
						OR = {
							dynasty ?= { exists = var:ce1_legitimacy_legacy_5_education_martial_5 }
							
							# If you have an Estate with the relevant upgrade, or if your liege has one (assuming you are not a ruler yourself)
							domicile ?= { has_domicile_parameter = estate_unlock_tier_5_education }
							AND = {
								is_ruler = no
								liege ?= {
									domicile ?= { has_domicile_parameter = estate_unlock_tier_5_education }
								}
							}
						}
					}
					set_trait_rank = {
						trait = education_martial
						rank = 5
					}
				}
			}
		}

		#Prowess trait acquisition.
		if = {
			limit = {
				can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root }
				#House Traditions
				# There is no good workaround without overriding the coming_of_age_event.txt and have inconsistent Prowess education messaging.
				NOT = {
					root.house = { has_house_modifier = trad_valor } #ZGC changed from house to root.house
					has_character_flag = parent_approved_weapon_training
					has_character_flag = training_weapons_in_secret
					has_character_flag = seen_battle
				}
				#/HouseTraditions
				OR = {
					#If the child belongs to a knightly culture, then their martial education includes squirehood.
					culture = { has_innovation = innovation_knighthood }
					AND = {	#If the child's guardian belongs to a knightly culture, then they will naturally introduce them to the rigours of squiredom.
						exists = scope:educator
						scope:educator = {
							culture = { has_innovation = innovation_knighthood }
						}
					}
				}
			}

			#House Traditions
			# Replacing vanilla code; 
			# Vanilla is too simplistic and causes a lot of double dipping/double-penalty on traits already modifying prowess
			if = {
				limit = { NOT = { exists = var:education_prowess_variable } }
				set_variable = {
					name = education_prowess_variable
					value = 0
				}
			}
			house_valor_education_abstract = yes
			#/House Traditions
			#Set a temp variable based on education level and add/subtract based on some traits
			# House Traditions
			# set_variable = {
			# 	name = education_prowess_variable
			# 	value = {
					# value = var:education_martial_variable
					# if = {
					# 	limit = { has_trait = physique_good_3 }
					# 	add = education_large_bonus
					# }
					# if = {
					# 	limit = { has_trait = physique_good_2 }
					# 	add = education_medium_bonus
					# }
					# if = {
					# 	limit = { has_trait = physique_good_1 }
					# 	add = education_small_bonus
					# }
					# if = {
					# 	limit = { has_trait = strong }
					# 	add = education_medium_bonus
					# }
					# if = {
					# 	limit = { has_trait = giant }
					# 	add = education_medium_bonus
					# }
					# if = {
					# 	limit = { has_trait = physique_bad_3 }
					# 	add = education_large_penalty
					# }
					# if = {
					# 	limit = { has_trait = physique_bad_2 }
					# 	add = education_medium_penalty
					# }
					# if = {
					# 	limit = { has_trait = physique_bad_1 }
					# 	add = education_small_penalty
					# }
					# if = {
					# 	limit = { has_trait = weak }
					# 	add = education_medium_penalty
					# }
					# if = {
					# 	limit = { has_trait = dwarf }
					# 	add = education_medium_penalty
					# }
					# if = {
					# 	limit = { has_trait = spindly }
					# 	add = education_small_penalty
					# }
					# if = {
					# 	limit = { has_trait = wheezing }
					# 	add = education_small_penalty
					# }
					# if = {
					# 	limit = { has_trait = hunchbacked }
					# 	add = education_small_penalty
					# }
					# if = {
					# 	limit = { has_trait = inbred }
					# 	add = education_small_penalty
					# }
					# if = {
					# 	limit = { has_trait = bleeder }
					# 	add = education_small_penalty
					# }
				# }
			# }

			# #Do a little randomization
			# random_list = {
			# 	100 = { # Better
			# 		ai_boldness_target_modifier = { VALUE = 50 }
			# 		ai_energy_target_modifier = { VALUE = 50 }
			# 		change_variable = {
			# 			name = education_prowess_variable
			# 			add = 2
			# 		}
			# 	}
			# 	200 = { } # Nothing
			# 	100 = { # Worse
			# 		ai_boldness_target_modifier = { VALUE = -50 }
			# 		ai_energy_target_modifier = { VALUE = -50 }
			# 		change_variable = {
			# 			name = education_prowess_variable
			# 			add = -2
			# 		}
			# 	}
			# }
			#/House Traditions

			#Set trait
			if = {
				limit = {
					var:education_prowess_variable <= education_level_1
				}
				
				set_trait_rank = {
					trait = education_martial_prowess
					rank = 1
				}
			}
			else_if = {
				limit = {
					var:education_prowess_variable <= education_level_2
				}
				
				set_trait_rank = {
					trait = education_martial_prowess
					rank = 2
				}
			}
			else_if = {
				limit = {
					var:education_prowess_variable <= education_level_3
				}
				
				set_trait_rank = {
					trait = education_martial_prowess
					rank = 3
				}
			}
			else = {
				
				set_trait_rank = {
					trait = education_martial_prowess
					rank = 4
				}
			}

			remove_variable = education_prowess_variable
		}
		
		#Other martial education things.
		hidden_effect = { #To assign a commander trait
			random_list = {
				20 = {
					modifier = {
						add = 5
						has_trait_rank = {
							trait = education_martial
							rank >= 1
						}
					}
					modifier = {
						add = 15
						has_trait_rank = {
							trait = education_martial
							rank >= 2
						}
					}
					modifier = {
						add = 20
						has_trait_rank = {
							trait = education_martial
							rank >= 3
						}
					}
					modifier = {
						add = 25
						has_trait_rank = {
							trait = education_martial
							rank >= 4
						}
					}
					assign_commander_trait_effect = yes
				}
				10 = {
					#A chance that you get no commander trait
				}
			}
		}
		dynasty_perk_secondary_education_trait_effect = yes
		post_education_bonuses_effect = yes
		save_childhood_trait_as_variable_effect = yes
		education_complete_notification_effect = yes
		wrap_up_education_effect = yes
		custom_tooltip_martial_coming_of_age_effect = yes
	}

	option = {
		name = coming_of_age.0001.a
	}
	after = {
		hidden_effect = {
			apply_hold_court_grace_effect = yes #start the grace period for hold court
		}
	}
}


#Intrigue - notification event for child
#by Linnéa Thimrén and Petter Vilberg
coming_of_age.0004 = {
	title = coming_of_age.0001.t
	desc = {
		triggered_desc = {
			trigger = {
				exists = scope:educator
			}
			desc = {
				first_valid = {
					triggered_desc = {
						trigger = {
							has_character_flag = studied_confucian_education
						}
						desc = coming_of_age.0001.educator_confucian_education
					}
					triggered_desc = {
						trigger = {
							has_character_flag = studied_at_university
						}
						desc = coming_of_age.0001.educator_university
					}
					desc = coming_of_age.0001.educator
				}
			}
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					has_trait_rank = {
						trait = education_intrigue
						rank = 1
					}
				}
				desc = {
					desc = coming_of_age.0001.desc1
					first_valid = {
						triggered_desc = {
							trigger = {
								has_intrigue_education_affinity_childhood_trait_trigger = yes
							}
							desc = coming_of_age.0001.desc1_good_trait
						}
						triggered_desc = {
							trigger = {
								has_intrigue_education_disaffinity_childhood_trait_trigger = yes
							}
							desc = coming_of_age.0001.desc1_bad_trait
						}
						desc = coming_of_age.0001.desc1_fallback_trait
					}
				}
			}
			triggered_desc = {
				trigger = {
					has_trait_rank = {
						trait = education_intrigue
						rank = 2
					}
				}
				desc = {
					desc = coming_of_age.0001.desc2
					first_valid = {
						triggered_desc = {
							trigger = {
								has_intrigue_education_affinity_childhood_trait_trigger = yes
							}
							desc = coming_of_age.0001.desc2_good_trait
						}
						triggered_desc = {
							trigger = {
								has_intrigue_education_disaffinity_childhood_trait_trigger = yes
							}
							desc = coming_of_age.0001.desc2_bad_trait
						}
						desc = coming_of_age.0001.desc2_fallback_trait
					}
				}
			}
			triggered_desc = {
				trigger = {
					has_trait_rank = {
						trait = education_intrigue
						rank = 3
					}
				}
				desc = {
					desc = coming_of_age.0001.desc3
					first_valid = {
						triggered_desc = {
							trigger = {
								has_intrigue_education_affinity_childhood_trait_trigger = yes
							}
							desc = coming_of_age.0001.desc3_good_trait
						}
						triggered_desc = {
							trigger = {
								has_intrigue_education_disaffinity_childhood_trait_trigger = yes
							}
							desc = coming_of_age.0001.desc3_bad_trait
						}
						desc = coming_of_age.0001.desc3_fallback_trait
					}
				}
			}
			triggered_desc = {
				trigger = {
					has_trait_rank = {
						trait = education_intrigue
						rank >= 4
					}
				}
				desc = {
					desc = coming_of_age.0001.desc4
					first_valid = {
						triggered_desc = {
							trigger = {
								has_intrigue_education_affinity_childhood_trait_trigger = yes
							}
							desc = coming_of_age.0001.desc4_good_trait
						}
						triggered_desc = {
							trigger = {
								has_intrigue_education_disaffinity_childhood_trait_trigger = yes
							}
							desc = coming_of_age.0001.desc4_bad_trait
						}
						desc = coming_of_age.0001.desc4_fallback_trait
					}
				}
			}
		}
		first_valid = { #If a learned court owner spouse has improved education
			triggered_desc = {
				trigger = {
					exists = scope:education_rank_patronage_bonus
					scope:education_rank_patronage_bonus = flag:1
				}
				desc = coming_of_age.0001.patronaged_spouse_plus_1.desc
			}
			triggered_desc = {
				trigger = {
					exists = scope:education_rank_patronage_bonus
					scope:education_rank_patronage_bonus = flag:2_or_more
				}
				desc = coming_of_age.0001.patronaged_spouse_plus_2_or_more.desc
			}
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					OR = {
						any_relation = { type = friend always = yes }
						exists = var:had_childhood_crush_variable
						exists = var:had_childhood_bully_variable
						exists = var:had_childhood_victim_variable
					}
				}
				desc = {
					desc = coming_of_age.0001.relationships
					triggered_desc = {
						trigger = {
							any_relation = { type = friend always = yes }
						}
						desc = coming_of_age.0001.friend
					}
					triggered_desc = {
						trigger = {
							exists = var:had_childhood_crush_variable
						}
						desc = coming_of_age.0001.crush
					}
					first_valid = {
						triggered_desc = {
							trigger = {
								AND = {
									exists = var:had_childhood_bully_variable
									NOT = { has_character_flag = bully_destroyed_toy }
								}
							}
							desc = coming_of_age.0001.bully1
						}
						triggered_desc = {
							trigger = {
								AND = {
									exists = var:had_childhood_bully_variable
									has_character_flag = bully_destroyed_toy
								}
							}
							desc = coming_of_age.0001.bully2
						}
					}
					first_valid = {
						triggered_desc = {
							trigger = {
								AND = {
									exists = var:had_childhood_victim_variable
									scope:victim = {
										NOT = { has_character_flag = bully_destroyed_toy }
									}
								}
							}
							desc = coming_of_age.0001.victim1
						}
						triggered_desc = {
							trigger = {
								AND = {
									exists = var:had_childhood_victim_variable
									scope:victim = {
										has_character_flag = bully_destroyed_toy
									}
								}
							}
							desc = coming_of_age.0001.victim2
						}
					}
					triggered_desc = {
						trigger = {
							any_relation = { type = friend always = no }
						}
						desc = coming_of_age.0001.relationships_end
					}
				}
			}
			triggered_desc = {
				trigger = {
					NOR = {
						any_relation = { type = friend always = yes }
						exists = var:had_childhood_crush_variable
						exists = var:had_childhood_bully_variable
						exists = var:had_childhood_victim_variable
					}
				}
				desc = coming_of_age.0001.no_relationships
			}
		}
	}
	theme = education
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = {
				has_focus = education_martial
			}
  			animation = marshal
  		}
		triggered_animation = {
			trigger = {
				has_focus = education_learning
			}
  			animation = personality_rational
  		}
		triggered_animation = {
			trigger = {
				has_focus = education_stewardship
			}
  			animation = steward
  		}
		triggered_animation = {
			trigger = {
				has_focus = education_intrigue
			}
  			animation = spymaster
  		}
		triggered_animation = {
			trigger = {
				has_focus = education_diplomacy
			}
  			animation = flirtation_left
  		}
		animation = idle
	}
	override_background = {
		trigger = {
			has_focus = education_martial
		}
		reference = courtyard
	}
	override_background = {
		trigger = {
			has_focus = education_diplomacy
			culture = {
				OR = {
					has_building_gfx = western_building_gfx
					has_building_gfx = mediterranean_building_gfx
				}
			}
		}
		reference = council_chamber
	}
	override_background = {
		trigger = {
			has_focus = education_diplomacy
			culture = {
				NOR = {
					has_building_gfx = western_building_gfx
					has_building_gfx = mediterranean_building_gfx
				}
			}
		}
		reference = throne_room
	}
	override_background = {
		trigger = {
			has_focus = education_intrigue
			culture = {
				OR = {
					has_building_gfx = western_building_gfx
					has_building_gfx = mediterranean_building_gfx
				}
			}
		}
		reference = physicians_study
	}
	override_background = {
		trigger = {
			has_focus = education_intrigue
			culture = {
				NOR = {
					has_building_gfx = western_building_gfx
					has_building_gfx = mediterranean_building_gfx
				}
			}
		}
		reference = study
	}
	override_background = {
		trigger = {
			has_focus = education_stewardship
		}
		reference = market
	}
	override_background = {
		trigger = {
			has_focus = education_learning
			culture = {
				NOR = {
					has_building_gfx = indian_building_gfx
					has_building_gfx = western_building_gfx
					has_building_gfx = mediterranean_building_gfx
				}
			}
		}
		reference = temple
	}
	
	trigger = {
		has_focus = education_intrigue
		NOR = {  # In case a character start with an education trait from the ruler designer
			has_trait = education_learning
			has_trait = education_diplomacy
			has_trait = education_intrigue
			has_trait = education_martial
			has_trait = education_stewardship
		}
	}

	immediate = {
		play_music_cue = "mx_cue_positive_effect"
		save_event_targets_from_childhood_effect = yes
		random_relation = {
			type = guardian
			save_scope_as = educator
		}
		results_of_patronage_spouse_education_points_effect = yes #patronage/high learning spouses of court owner can add points
		results_of_university_education_points_effect = yes #Did you send the child to university? Lucky them!
		results_of_confucian_education_effect = yes #Ward learned from a Confucian scholar
		dynasty_legacy_education_boost_effect = yes # Adds a few points if you have the second Kin legacy
		cultural_traditions_education_boost_effect = yes # Adds points based on Cultural Traditions
		court_tutor_education_boost_effect = yes # A Court Tutor gives a better education
		if = {
			limit = {
				var:education_intrigue_variable <= education_level_1
			}
			
			set_trait_rank = {
				trait = education_intrigue
				rank = 1
			}
		}
		else_if = {
			limit = {
				var:education_intrigue_variable <= education_level_2
			}
			
			set_trait_rank = {
				trait = education_intrigue
				rank = 2
			}
		}
		else_if = {
			limit = {
				var:education_intrigue_variable <= education_level_3
			}
			
			set_trait_rank = {
				trait = education_intrigue
				rank = 3
			}
		}
		else = {
			random_list = {
				50 = {
					set_trait_rank = {
						trait = education_intrigue
						rank = 4
					}
				}
				50 = {
					trigger = {
						OR = {
							dynasty ?= { exists = var:ce1_legitimacy_legacy_5_education_intrigue_5 }
							
							# If you have an Estate with the relevant upgrade, or if your liege has one (assuming you are not a ruler yourself)
							domicile ?= { has_domicile_parameter = estate_unlock_tier_5_education }
							AND = {
								is_ruler = no
								liege ?= {
									domicile ?= { has_domicile_parameter = estate_unlock_tier_5_education }
								}
							}
						}
					}
					set_trait_rank = {
						trait = education_intrigue
						rank = 5
					}
				}
			}
		}
		dynasty_perk_secondary_education_trait_effect = yes
		post_education_bonuses_effect = yes
		save_childhood_trait_as_variable_effect = yes
		education_complete_notification_effect = yes
		wrap_up_education_effect = yes
		custom_tooltip_intrigue_coming_of_age_effect = yes
	}

	option = {
		name = coming_of_age.0001.a
	}
	after = {
		hidden_effect = {
			apply_hold_court_grace_effect = yes #start the grace period for hold court
		}
	}
}

#Diplomacy - notification event for child
#by Linnéa Thimrén and Petter Vilberg
coming_of_age.0005 = {
	title = coming_of_age.0001.t
	desc = {
		triggered_desc = {
			trigger = {
				exists = scope:educator
			}
			desc = {
				first_valid = {
					triggered_desc = {
						trigger = {
							has_character_flag = studied_confucian_education
						}
						desc = coming_of_age.0001.educator_confucian_education
					}
					triggered_desc = {
						trigger = {
							has_character_flag = studied_at_university
						}
						desc = coming_of_age.0001.educator_university
					}
					desc = coming_of_age.0001.educator
				}
			}
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					has_trait_rank = {
						trait = education_diplomacy
						rank = 1
					}
				}
				desc = {
					desc = coming_of_age.0001.desc1
					first_valid = {
						triggered_desc = {
							trigger = {
								has_diplomacy_education_affinity_childhood_trait_trigger = yes
							}
							desc = coming_of_age.0001.desc1_good_trait
						}
						triggered_desc = {
							trigger = {
								has_diplomacy_education_disaffinity_childhood_trait_trigger = yes
							}
							desc = coming_of_age.0001.desc1_bad_trait
						}
						desc = coming_of_age.0001.desc1_fallback_trait
					}
				}
			}
			triggered_desc = {
				trigger = {
					has_trait_rank = {
						trait = education_diplomacy
						rank = 2
					}
				}
				desc = {
					desc = coming_of_age.0001.desc2
					first_valid = {
						triggered_desc = {
							trigger = {
								has_diplomacy_education_affinity_childhood_trait_trigger = yes
							}
							desc = coming_of_age.0001.desc2_good_trait
						}
						triggered_desc = {
							trigger = {
								has_diplomacy_education_disaffinity_childhood_trait_trigger = yes
							}
							desc = coming_of_age.0001.desc2_bad_trait
						}
						desc = coming_of_age.0001.desc2_fallback_trait
					}
				}
			}
			triggered_desc = {
				trigger = {
					has_trait_rank = {
						trait = education_diplomacy
						rank = 3
					}
				}
				desc = {
					desc = coming_of_age.0001.desc3
					first_valid = {
						triggered_desc = {
							trigger = {
								has_diplomacy_education_affinity_childhood_trait_trigger = yes
							}
							desc = coming_of_age.0001.desc3_good_trait
						}
						triggered_desc = {
							trigger = {
								has_diplomacy_education_disaffinity_childhood_trait_trigger = yes
							}
							desc = coming_of_age.0001.desc3_bad_trait
						}
						desc = coming_of_age.0001.desc3_fallback_trait
					}
				}
			}
			triggered_desc = {
				trigger = {
					has_trait_rank = {
						trait = education_diplomacy
						rank >= 4
					}
				}
				desc = {
					desc = coming_of_age.0001.desc4
					first_valid = {
						triggered_desc = {
							trigger = {
								has_diplomacy_education_affinity_childhood_trait_trigger = yes
							}
							desc = coming_of_age.0001.desc4_good_trait
						}
						triggered_desc = {
							trigger = {
								has_diplomacy_education_disaffinity_childhood_trait_trigger = yes
							}
							desc = coming_of_age.0001.desc4_bad_trait
						}
						desc = coming_of_age.0001.desc4_fallback_trait
					}
				}
			}
		}
		first_valid = { #If a learned court owner spouse has improved education
			triggered_desc = {
				trigger = {
					exists = scope:education_rank_patronage_bonus
					scope:education_rank_patronage_bonus = flag:1
				}
				desc = coming_of_age.0001.patronaged_spouse_plus_1.desc
			}
			triggered_desc = {
				trigger = {
					exists = scope:education_rank_patronage_bonus
					scope:education_rank_patronage_bonus = flag:2_or_more
				}
				desc = coming_of_age.0001.patronaged_spouse_plus_2_or_more.desc
			}
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					OR = {
						any_relation = { type = friend always = yes }
						exists = var:had_childhood_crush_variable
						exists = var:had_childhood_bully_variable
						exists = var:had_childhood_victim_variable
					}
				}
				desc = {
					desc = coming_of_age.0001.relationships
					triggered_desc = {
						trigger = {
							any_relation = { type = friend always = yes }
						}
						desc = coming_of_age.0001.friend
					}
					triggered_desc = {
						trigger = {
							exists = var:had_childhood_crush_variable
						}
						desc = coming_of_age.0001.crush
					}
					first_valid = {
						triggered_desc = {
							trigger = {
								AND = {
									exists = var:had_childhood_bully_variable
									NOT = { has_character_flag = bully_destroyed_toy }
								}
							}
							desc = coming_of_age.0001.bully1
						}
						triggered_desc = {
							trigger = {
								AND = {
									exists = var:had_childhood_bully_variable
									has_character_flag = bully_destroyed_toy
								}
							}
							desc = coming_of_age.0001.bully2
						}
					}
					first_valid = {
						triggered_desc = {
							trigger = {
								AND = {
									exists = var:had_childhood_victim_variable
									scope:victim = {
										NOT = { has_character_flag = bully_destroyed_toy }
									}
								}
							}
							desc = coming_of_age.0001.victim1
						}
						triggered_desc = {
							trigger = {
								AND = {
									exists = var:had_childhood_victim_variable
									scope:victim = {
										has_character_flag = bully_destroyed_toy
									}
								}
							}
							desc = coming_of_age.0001.victim2
						}
					}
					triggered_desc = {
						trigger = {
							any_relation = { type = friend always = no }
						}
						desc = coming_of_age.0001.relationships_end
					}
				}
			}
			triggered_desc = {
				trigger = {
					NOR = {
						any_relation = { type = friend always = yes }
						exists = var:had_childhood_crush_variable
						exists = var:had_childhood_bully_variable
						exists = var:had_childhood_victim_variable
					}
				}
				desc = coming_of_age.0001.no_relationships
			}
		}
	}
	theme = education
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = {
				has_focus = education_martial
			}
  			animation = marshal
  		}
		triggered_animation = {
			trigger = {
				has_focus = education_learning
			}
  			animation = personality_rational
  		}
		triggered_animation = {
			trigger = {
				has_focus = education_stewardship
			}
  			animation = steward
  		}
		triggered_animation = {
			trigger = {
				has_focus = education_intrigue
			}
  			animation = spymaster
  		}
		triggered_animation = {
			trigger = {
				has_focus = education_diplomacy
			}
  			animation = flirtation_left
  		}
		animation = idle
	}
	override_background = {
		trigger = {
			has_focus = education_martial
		}
		reference = courtyard
	}
	override_background = {
		trigger = {
			has_focus = education_diplomacy
			culture = {
				OR = {
					has_building_gfx = western_building_gfx
					has_building_gfx = mediterranean_building_gfx
				}
			}
		}
		reference = council_chamber
	}
	override_background = {
		trigger = {
			has_focus = education_diplomacy
			culture = {
				NOR = {
					has_building_gfx = western_building_gfx
					has_building_gfx = mediterranean_building_gfx
				}
			}
		}
		reference = throne_room
	}
	override_background = {
		trigger = {
			has_focus = education_intrigue
			culture = {
				OR = {
					has_building_gfx = western_building_gfx
					has_building_gfx = mediterranean_building_gfx
				}
			}
		}
		reference = physicians_study
	}
	override_background = {
		trigger = {
			has_focus = education_intrigue
			culture = {
				NOR = {
					has_building_gfx = western_building_gfx
					has_building_gfx = mediterranean_building_gfx
				}
			}
		}
		reference = study
	}
	override_background = {
		trigger = {
			has_focus = education_stewardship
		}
		reference = market
	}
	override_background = {
		trigger = {
			has_focus = education_learning
			culture = {
				NOR = {
					has_building_gfx = indian_building_gfx
					has_building_gfx = western_building_gfx
					has_building_gfx = mediterranean_building_gfx
				}
			}
		}
		reference = temple
	}
	
	trigger = {
		has_focus = education_diplomacy
		NOR = {  # In case a character start with an education trait from the ruler designer
			has_trait = education_learning
			has_trait = education_diplomacy
			has_trait = education_intrigue
			has_trait = education_martial
			has_trait = education_stewardship
		}
	}

	immediate = {
		play_music_cue = "mx_cue_positive_effect"
		save_event_targets_from_childhood_effect = yes
		random_relation = {
			type = guardian
			save_scope_as = educator
		}
		results_of_patronage_spouse_education_points_effect = yes #patronage/high learning spouses of court owner can add points
		results_of_university_education_points_effect = yes #Did you send the child to university? Lucky them!
		results_of_confucian_education_effect = yes #Ward learned from a Confucian scholar
		dynasty_legacy_education_boost_effect = yes # Adds a few points if you have the second Kin legacy
		cultural_traditions_education_boost_effect = yes # Adds points based on Cultural Traditions
		court_tutor_education_boost_effect = yes # A Court Tutor gives a better education
		if = {
			limit = {
				var:education_diplomacy_variable <= education_level_1
			}
			
			set_trait_rank = {
				trait = education_diplomacy
				rank = 1
			}
		}
		else_if = {
			limit = {
				var:education_diplomacy_variable <= education_level_2
			}
			
			set_trait_rank = {
				trait = education_diplomacy
				rank = 2
			}
		}
		else_if = {
			limit = {
				var:education_diplomacy_variable <= education_level_3
			}
			
			set_trait_rank = {
				trait = education_diplomacy
				rank = 3
			}
		}
		else = {
			random_list = {
				50 = {
					set_trait_rank = {
						trait = education_diplomacy
						rank = 4
					}
				}
				50 = {
					trigger = {
						OR = {
							dynasty ?= { exists = var:ce1_legitimacy_legacy_5_education_diplomacy_5 }
							
							# If you have an Estate with the relevant upgrade, or if your liege has one (assuming you are not a ruler yourself)
							domicile ?= { has_domicile_parameter = estate_unlock_tier_5_education }
							AND = {
								is_ruler = no
								liege ?= {
									domicile ?= { has_domicile_parameter = estate_unlock_tier_5_education }
								}
							}
						}
					}
					set_trait_rank = {
						trait = education_diplomacy
						rank = 5
					}
				}
			}
		}
		dynasty_perk_secondary_education_trait_effect = yes
		post_education_bonuses_effect = yes
		save_childhood_trait_as_variable_effect = yes
		education_complete_notification_effect = yes
		wrap_up_education_effect = yes
		custom_tooltip_diplomacy_coming_of_age_effect = yes
	}

	option = {
		name = coming_of_age.0001.a
	}
	after = {
		hidden_effect = {
			apply_hold_court_grace_effect = yes #start the grace period for hold court
		}
	}
}


#############################
# Coming of Age - Notification events for others
# 1000 - 1999
#############################

#Notification event for a Parent Guardian
coming_of_age.1001 = {
	type = character_event
	title = coming_of_age.1001.t
	desc = { 	
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:educated_child = {
						has_character_flag = studied_confucian_education
					}
				}
				desc = coming_of_age.0001.desc_confucian_education
			}
			triggered_desc = {
				trigger = {
					scope:educated_child = {
						has_character_flag = studied_at_university
					}
				}
				desc = coming_of_age.1001.desc_university
			}
			desc = coming_of_age.1001.desc
		}
		first_valid = { #If a learned court owner spouse has improved education
			triggered_desc = {
				trigger = {
					exists = scope:education_rank_patronage_bonus
					scope:education_rank_patronage_bonus = flag:1
					this != scope:patronage_spouse_tutor
				}
				desc = coming_of_age.1001.patronaged_spouse_plus_1.desc
			}
			triggered_desc = {
				trigger = {
					exists = scope:education_rank_patronage_bonus
					scope:education_rank_patronage_bonus = flag:2_or_more
					this != scope:patronage_spouse_tutor
				}
				desc = coming_of_age.1001.patronaged_spouse_plus_2_or_more.desc
			}
		}
	}
	theme = education
	left_portrait = {
		character = scope:educated_child
		triggered_animation = {
			trigger = {
				scope:educated_child = {
					has_trait = education_martial
				}
			}
  			animation = marshal
  		}
		triggered_animation = {
			trigger = {
				scope:educated_child = {
					has_trait = education_learning
				}
			}
  			animation = personality_rational
  		}
		triggered_animation = {
			trigger = {
				scope:educated_child = {
					has_trait = education_stewardship
				}
			}
  			animation = steward
  		}
		triggered_animation = {
			trigger = {
				scope:educated_child = {
					has_trait = education_intrigue
				}
			}
  			animation = spymaster
  		}
		triggered_animation = {
			trigger = {
				scope:educated_child = {
					has_trait = education_diplomacy
				}
			}
  			animation = flirtation_left
  		}
		animation = idle
	}
	right_portrait = {
		character = scope:guardian
		animation = admiration
	}
	override_background = {
		trigger = {
			scope:educated_child = {
				has_trait = education_martial
			}
		}
		reference = courtyard
	}
	override_background = {
		trigger = {
			scope:educated_child = {
				has_trait = education_diplomacy
				culture = {
					OR = {
						has_building_gfx = western_building_gfx
						has_building_gfx = mediterranean_building_gfx
					}
				}
			}
		}
		reference = council_chamber
	}
	override_background = {
		trigger = {
			scope:educated_child = {
				has_trait = education_diplomacy
				culture = {
					NOR = {
						has_building_gfx = western_building_gfx
						has_building_gfx = mediterranean_building_gfx
					}
				}
			}
		}
		reference = throne_room
	}
	override_background = {
		trigger = {
			scope:educated_child = {
				has_trait = education_intrigue
				culture = {
					OR = {
						has_building_gfx = western_building_gfx
						has_building_gfx = mediterranean_building_gfx
					}
				}
			}
		}
		reference = physicians_study
	}
	override_background = {
		trigger = {
			scope:educated_child = {
				has_trait = education_intrigue
				culture = {
					NOR = {
						has_building_gfx = western_building_gfx
						has_building_gfx = mediterranean_building_gfx
					}
				}
			}
		}
		reference = study
	}
	override_background = {
		trigger = {
			scope:educated_child = {
				has_trait = education_stewardship
			}
		}
		reference = market
	}
	override_background = {
		trigger = {
			scope:educated_child = {
				has_trait = education_learning
				culture = {
					NOR = {
						has_building_gfx = western_building_gfx
						has_building_gfx = indian_building_gfx
						has_building_gfx = mediterranean_building_gfx
					}
				}
			}
		}
		reference = temple
	}
	
	trigger = {
		this = scope:parent_guardian
	}

	option = {
		name = coming_of_age.1001.a
		scope:guardian ?= {
			show_as_tooltip = { remove_relation_ward = scope:educated_child }
		}
		scope:educated_child = {
			display_correct_education_trait_gain_tooltip_effect = yes
			if = {
				limit = { is_travelling = yes }
				show_as_tooltip = { return_to_court = yes }
			}
		}
	}
}

#Notification event for a non-guardian Parent
coming_of_age.1002 = {
	type = character_event
	title = coming_of_age.1002.t
	desc = { 	
		desc = coming_of_age.1002.desc
		first_valid = { #If a learned court owner spouse has improved education
			triggered_desc = {
				trigger = {
					exists = scope:education_rank_patronage_bonus
					scope:education_rank_patronage_bonus = flag:1
					this != scope:patronage_spouse_tutor
				}
				desc = coming_of_age.1002.patronaged_spouse_plus_1.desc
			}
			triggered_desc = {
				trigger = {
					exists = scope:education_rank_patronage_bonus
					scope:education_rank_patronage_bonus = flag:2_or_more
					this != scope:patronage_spouse_tutor
				}
				desc = coming_of_age.1002.patronaged_spouse_plus_2_or_more.desc
			}
		}
	}
	theme = education
	left_portrait = scope:educated_child
	right_portrait = {
		character = scope:guardian
		animation = admiration
	}

	option = {
		name = coming_of_age.1001.a
		scope:guardian ?= {
			show_as_tooltip = { remove_relation_ward = scope:educated_child }
		}
		scope:educated_child = {
			display_correct_education_trait_gain_tooltip_effect = yes
			if = {
				limit = { is_travelling = yes }
				show_as_tooltip = { return_to_court = yes }
			}
		}
	}
}

#Notification event for a non-parent Guardian when both parents are alive
coming_of_age.1003 = {
	type = character_event
	title = coming_of_age.1003.t
	desc = {
		desc = coming_of_age.1003.standard
		first_valid = { #If a learned court owner spouse has improved education
			triggered_desc = {
				trigger = {
					exists = scope:education_rank_patronage_bonus
					scope:education_rank_patronage_bonus = flag:1
					this != scope:patronage_spouse_tutor
				}
				desc = coming_of_age.1002.patronaged_spouse_plus_1.desc
			}
			triggered_desc = {
				trigger = {
					exists = scope:education_rank_patronage_bonus
					scope:education_rank_patronage_bonus = flag:2_or_more
					this != scope:patronage_spouse_tutor
				}
				desc = coming_of_age.1002.patronaged_spouse_plus_2_or_more.desc
			}
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:educated_child = {
						has_education_rank_1_trigger = yes
					}
				}
				desc = coming_of_age.1003.rank_1
			}
			triggered_desc = {
				trigger = {
					scope:educated_child = {
						has_education_rank_2_trigger = yes
					}
				}
				desc = coming_of_age.1003.rank_2
			}
			triggered_desc = {
				trigger = {
					scope:educated_child = {
						has_education_rank_3_trigger = yes
					}
				}
				desc = coming_of_age.1003.rank_3
			}
			triggered_desc = {
				trigger = {
					scope:educated_child = {
						has_education_rank_4_trigger = yes
					}
				}
				desc = coming_of_age.1003.rank_4
			}
		}
	}
	theme = education
	left_portrait = {
		character = scope:educated_child
		triggered_animation = {
			trigger = {
				scope:educated_child = {
					has_trait = education_martial
				}
			}
  			animation = marshal
  		}
		triggered_animation = {
			trigger = {
				scope:educated_child = {
					has_trait = education_learning
				}
			}
  			animation = personality_rational
  		}
		triggered_animation = {
			trigger = {
				scope:educated_child = {
					has_trait = education_stewardship
				}
			}
  			animation = steward
  		}
		triggered_animation = {
			trigger = {
				scope:educated_child = {
					has_trait = education_intrigue
				}
			}
  			animation = spymaster
  		}
		triggered_animation = {
			trigger = {
				scope:educated_child = {
					has_trait = education_diplomacy
				}
			}
  			animation = flirtation_left
  		}
		animation = idle
	}
	right_portrait = {
		character = scope:guardian
		triggered_animation = {
			trigger = {
				scope:educated_child = {
					OR = {
						has_trait_rank = {
							trait = education_martial
							rank <= 2
						}
						has_trait_rank = {
							trait = education_diplomacy
							rank <= 2
						}
						has_trait_rank = {
							trait = education_intrigue
							rank <= 2
						}
						has_trait_rank = {
							trait = education_stewardship
							rank <= 2
						}
						has_trait_rank = {
							trait = education_learning
							rank <= 2
						}
					}
				}
			}
  			animation = eyeroll
		}
		animation = happy_teacher
	}
	override_background = {
		trigger = {
			scope:educated_child = {
				has_trait = education_martial
			}
		}
		reference = courtyard
	}
	override_background = {
		trigger = {
			scope:educated_child = {
				has_trait = education_diplomacy
				culture = {
					OR = {
						has_building_gfx = western_building_gfx
						has_building_gfx = mediterranean_building_gfx
					}
				}
			}
		}
		reference = council_chamber
	}
	override_background = {
		trigger = {
			scope:educated_child = {
				has_trait = education_diplomacy
				culture = {
					NOR = {
						has_building_gfx = western_building_gfx
						has_building_gfx = mediterranean_building_gfx
					}
				}
			}
		}
		reference = throne_room
	}
	override_background = {
		trigger = {
			scope:educated_child = {
				has_trait = education_intrigue
				culture = {
					OR = {
						has_building_gfx = western_building_gfx
						has_building_gfx = mediterranean_building_gfx
					}
				}
			}
		}
		reference = physicians_study
	}
	override_background = {
		trigger = {
			scope:educated_child = {
				has_trait = education_intrigue
				culture = {
					NOR = {
						has_building_gfx = western_building_gfx
						has_building_gfx = mediterranean_building_gfx
					}
				}
			}
		}
		reference = study
	}
	override_background = {
		trigger = {
			scope:educated_child = {
				has_trait = education_stewardship
			}
		}
		reference = market
	}
	override_background = {
		trigger = {
			scope:educated_child = {
				has_trait = education_learning
				culture = {
					NOR = {
						has_building_gfx = western_building_gfx
						has_building_gfx = indian_building_gfx
						has_building_gfx = mediterranean_building_gfx
					}
				}
			}
		}
		reference = temple
	}
	
	trigger = {
		this = scope:guardian
	}

	option = {
		name = coming_of_age.1003.a
		name = {
			trigger = {
				scope:guardian = {
					has_government = landless_adventurer_government
				}
				scope:educated_child = {
					is_courtier_of = scope:guardian
				}
			}
			text = contest_events.1540.a
		}
		scope:guardian ?= {
			show_as_tooltip = { remove_relation_ward = scope:educated_child }
		}
		scope:educated_child = {
			display_correct_education_trait_gain_tooltip_effect = yes
			if = {
				limit = { is_travelling = yes }
				show_as_tooltip = { return_to_court = yes }
			}
		}
	}
}

#Notification event for a non-parent Guardian both parents are alive
coming_of_age.1004 = {
	type = character_event
	title = coming_of_age.1004.t
	desc = {
		desc = coming_of_age.1004.desc
		first_valid = { #If a learned court owner spouse has improved education
			triggered_desc = {
				trigger = {
					exists = scope:education_rank_patronage_bonus
					scope:education_rank_patronage_bonus = flag:1
					this != scope:patronage_spouse_tutor
				}
				desc = coming_of_age.1002.patronaged_spouse_plus_1.desc
			}
			triggered_desc = {
				trigger = {
					exists = scope:education_rank_patronage_bonus
					scope:education_rank_patronage_bonus = flag:2_or_more
					this != scope:patronage_spouse_tutor
				}
				desc = coming_of_age.1002.patronaged_spouse_plus_2_or_more.desc
			}
		}
	}
	theme = education
	left_portrait = {
		character = scope:educated_child
		triggered_animation = {
			trigger = {
				scope:educated_child = {
					has_trait = education_martial
				}
			}
  			animation = marshal
  		}
		triggered_animation = {
			trigger = {
				scope:educated_child = {
					has_trait = education_learning
				}
			}
  			animation = personality_rational
  		}
		triggered_animation = {
			trigger = {
				scope:educated_child = {
					has_trait = education_stewardship
				}
			}
  			animation = steward
  		}
		triggered_animation = {
			trigger = {
				scope:educated_child = {
					has_trait = education_intrigue
				}
			}
  			animation = spymaster
  		}
		triggered_animation = {
			trigger = {
				scope:educated_child = {
					has_trait = education_diplomacy
				}
			}
  			animation = flirtation_left
  		}
		animation = idle
	}
	right_portrait = {
		character = scope:guardian
		triggered_animation = {
			trigger = {
				scope:educated_child = {
					OR = {
						has_trait_rank = {
							trait = education_martial
							rank <= 2
						}
						has_trait_rank = {
							trait = education_diplomacy
							rank <= 2
						}
						has_trait_rank = {
							trait = education_intrigue
							rank <= 2
						}
						has_trait_rank = {
							trait = education_stewardship
							rank <= 2
						}
						has_trait_rank = {
							trait = education_learning
							rank <= 2
						}
					}
				}
			}
  			animation = eyeroll
		}
		animation = happy_teacher
	}
	override_background = {
		trigger = {
			scope:educated_child = {
				has_trait = education_martial
			}
		}
		reference = courtyard
	}
	override_background = {
		trigger = {
			scope:educated_child = {
				has_trait = education_diplomacy
				culture = {
					OR = {
						has_building_gfx = western_building_gfx
						has_building_gfx = mediterranean_building_gfx
					}
				}
			}
		}
		reference = council_chamber
	}
	override_background = {
		trigger = {
			scope:educated_child = {
				has_trait = education_diplomacy
				culture = {
					NOR = {
						has_building_gfx = western_building_gfx
						has_building_gfx = mediterranean_building_gfx
					}
				}
			}
		}
		reference = throne_room
	}
	override_background = {
		trigger = {
			scope:educated_child = {
				has_trait = education_intrigue
				culture = {
					OR = {
						has_building_gfx = western_building_gfx
						has_building_gfx = mediterranean_building_gfx
					}
				}
			}
		}
		reference = physicians_study
	}
	override_background = {
		trigger = {
			scope:educated_child = {
				has_trait = education_intrigue
				culture = {
					NOR = {
						has_building_gfx = western_building_gfx
						has_building_gfx = indian_building_gfx
						has_building_gfx = mediterranean_building_gfx
					}
				}
			}
		}
		reference = relaxing_room
	}
	override_background = {
		trigger = {
			scope:educated_child = {
				has_trait = education_stewardship
			}
		}
		reference = market
	}
	override_background = {
		trigger = {
			scope:educated_child = {
				has_trait = education_learning
				culture = {
					NOR = {
						has_building_gfx = western_building_gfx
						has_building_gfx = indian_building_gfx
						has_building_gfx = mediterranean_building_gfx
					}
				}
			}
		}
		reference = temple
	}
	
	trigger = {
		this = scope:guardian
	}

	option = {
		name = coming_of_age.1004.a
		name = {
			trigger = {
				scope:guardian = {
					has_government = landless_adventurer_government
				}
				scope:educated_child = {
					is_courtier_of = scope:guardian
				}
			}
			text = contest_events.1540.a
		}
		scope:guardian ?= {
			show_as_tooltip = { remove_relation_ward = scope:educated_child }
		}
		scope:educated_child = {
			display_correct_education_trait_gain_tooltip_effect = yes
			if = {
				limit = { is_travelling = yes }
				show_as_tooltip = { return_to_court = yes }
			}
		}
	}
}

#Notification event for a non-parent Guardian when both parents are dead
coming_of_age.1005 = {
	type = character_event
	title = coming_of_age.1005.t
	desc = {
		desc = coming_of_age.1005.desc
		first_valid = { #If a learned court owner spouse has improved education
			triggered_desc = {
				trigger = {
					exists = scope:education_rank_patronage_bonus
					scope:education_rank_patronage_bonus = flag:1
					this != scope:patronage_spouse_tutor
				}
				desc = coming_of_age.1002.patronaged_spouse_plus_1.desc
			}
			triggered_desc = {
				trigger = {
					exists = scope:education_rank_patronage_bonus
					scope:education_rank_patronage_bonus = flag:2_or_more
					this != scope:patronage_spouse_tutor
				}
				desc = coming_of_age.1002.patronaged_spouse_plus_2_or_more.desc
			}
		}
	}
	theme = education
	left_portrait = {
		character = scope:educated_child
		triggered_animation = {
			trigger = {
				scope:educated_child = {
					has_trait = education_martial
				}
			}
  			animation = marshal_random_weapon
  		}
		triggered_animation = {
			trigger = {
				scope:educated_child = {
					has_trait = education_learning
				}
			}
  			animation = personality_rational
  		}
		triggered_animation = {
			trigger = {
				scope:educated_child = {
					has_trait = education_stewardship
				}
			}
  			animation = steward
  		}
		triggered_animation = {
			trigger = {
				scope:educated_child = {
					has_trait = education_intrigue
				}
			}
  			animation = spymaster
  		}
		triggered_animation = {
			trigger = {
				scope:educated_child = {
					has_trait = education_diplomacy
				}
			}
  			animation = flirtation_left
  		}
		animation = idle
	}
	right_portrait = {
		character = scope:guardian
		triggered_animation = {
			trigger = {
				scope:educated_child = {
					OR = {
						has_trait_rank = {
							trait = education_martial
							rank <= 2
						}
						has_trait_rank = {
							trait = education_diplomacy
							rank <= 2
						}
						has_trait_rank = {
							trait = education_intrigue
							rank <= 2
						}
						has_trait_rank = {
							trait = education_stewardship
							rank <= 2
						}
						has_trait_rank = {
							trait = education_learning
							rank <= 2
						}
					}
				}
			}
  			animation = eyeroll
  		}
		animation = happy_teacher
	}
	override_background = {
		trigger = {
			scope:educated_child = {
				has_trait = education_martial
			}
		}
		reference = courtyard
	}
	override_background = {
		trigger = {
			scope:educated_child = {
				has_trait = education_diplomacy
				culture = {
					OR = {
						has_building_gfx = western_building_gfx
						has_building_gfx = mediterranean_building_gfx
					}
				}
			}
		}
		reference = council_chamber
	}
	override_background = {
		trigger = {
			scope:educated_child = {
				has_trait = education_diplomacy
				culture = {
					NOR = {
						has_building_gfx = western_building_gfx
						has_building_gfx = mediterranean_building_gfx
					}
				}
			}
		}
		reference = throne_room
	}
	override_background = {
		trigger = {
			scope:educated_child = {
				has_trait = education_intrigue
				culture = {
					OR = {
						has_building_gfx = western_building_gfx
						has_building_gfx = indian_building_gfx
						has_building_gfx = mediterranean_building_gfx
					}
				}
			}
		}
		reference = physicians_study
	}
	override_background = {
		trigger = {
			scope:educated_child = {
				has_trait = education_intrigue
				culture = {
					NOR = {
						has_building_gfx = western_building_gfx
						has_building_gfx = mediterranean_building_gfx
					}
				}
			}
		}
		reference = relaxing_room
	}
	override_background = {
		trigger = {
			scope:educated_child = {
				has_trait = education_stewardship
			}
		}
		reference = market
	}
	override_background = {
		trigger = {
			scope:educated_child = {
				has_trait = education_learning
				culture = {
					NOR = {
						has_building_gfx = western_building_gfx
						has_building_gfx = indian_building_gfx
						has_building_gfx = mediterranean_building_gfx
					}
				}
			}
		}
		reference = temple
	}
	
	trigger = {
		this = scope:guardian
	}

	option = {
		name = coming_of_age.1005.a
		name = {
			trigger = {
				scope:guardian = {
					has_government = landless_adventurer_government
				}
				scope:educated_child = {
					is_courtier_of = scope:guardian
				}
			}
			text = contest_events.1540.a
		}
		scope:guardian ?= {
			show_as_tooltip = { remove_relation_ward = scope:educated_child }
		}
		scope:educated_child = {
			if = {
				limit = { has_variable = hold_court_8100_fosterer }
				scope:guardian = {
					if = {
						limit = {
							can_add_hook = {
								target = scope:educated_child
								type = loyalty_hook
							}
						}
						add_hook = {
							target = scope:educated_child
							type = loyalty_hook
						}
					}
				}
				remove_variable = hold_court_8100_fosterer
			}
			display_correct_education_trait_gain_tooltip_effect = yes
			if = {
				limit = { is_travelling = yes }
				show_as_tooltip = { return_to_court = yes }
			}
		}
	}
}

# Mentor Accolade education bonus
coming_of_age.2000 = {
	hidden = yes
	trigger = {
		host ?= {
			any_active_accolade = {
				accolade_parameter = accolade_wise_educator
			}
		}
	}
	immediate = {
		add_prestige = accolade_wise_educator_prestige
		add_prowess_skill = accolade_wise_educator_prowess
	}
}
coming_of_age.2001 = {
	hidden = yes
	trigger = {
		liege ?= {
			any_active_accolade = {
				accolade_parameter = accolade_wise_educator_high
			}
		}
	}
	immediate = {
		add_prestige = accolade_wise_educator_prestige_high
		add_prowess_skill = accolade_wise_educator_prowess_high
	}
}

# House Knight Accolade inspires tournament skill
coming_of_age.3000 = {
	hidden = yes
	trigger = {
		has_dlc_feature = tours_and_tournaments
		liege ?= {
			any_active_accolade = {
				OR = {
					has_accolade_parameter = acclaimed_knight_inspires_family
					has_accolade_parameter = acclaimed_knight_inspires_family_high
				}
			}
		}
		is_child_of = liege
		exists = house
		exists = liege.house
		house = liege.house
		can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = liege }
	}
	immediate = {
		add_trait = tourney_participant
		if = {
			limit = {
				liege = {
					any_active_accolade = {
						accolade_parameter = acclaimed_knight_inspires_family_high
					}
				}
			}
			random_list = {
				10 = {
					add_trait_xp = {
						trait = tourney_participant
						track = foot
						value = tournament_hastiludes_xp_gain_minor_value
					}
				}
				10 = {
					add_trait_xp = {
						trait = tourney_participant
						track = horse
						value = tournament_hastiludes_xp_gain_minor_value
					}
				}
				10 = {
					add_trait_xp = {
						trait = tourney_participant
						track = bow
						value = tournament_hastiludes_xp_gain_minor_value
					}
				}
				10 = {
					add_trait_xp = {
						trait = tourney_participant
						track = wit
						value = tournament_hastiludes_xp_gain_minor_value
					}
				}
			}
		}
	}
}

##################################################
# Junior Emperor becomes Co-Emperor
# by Ewan Cowhig Croft
# 3011 - 3020
##################################################

scripted_trigger coming_of_age_3011_workaholic_traits_trigger = {
	OR = {
		has_trait = ambitious
		has_trait = arrogant
		has_trait = diligent
	}
}

scripted_effect coming_of_age_3011_roll_random_beneficial_skills = {
	# Skill buff 1.
	random_list = {
		100 = {
			save_scope_value_as = {
				name = skill_1
				value = flag:$VALID_SKILL_1$
			}
		}
		100 = {
			save_scope_value_as = {
				name = skill_1
				value = flag:$VALID_SKILL_2$
			}
		}
		100 = {
			save_scope_value_as = {
				name = skill_1
				value = flag:$VALID_SKILL_3$
			}
		}
		100 = {
			save_scope_value_as = {
				name = skill_1
				value = flag:$VALID_SKILL_4$
			}
		}
		100 = {
			save_scope_value_as = {
				name = skill_1
				value = flag:$VALID_SKILL_5$
			}
		}
	}
	# Skill buff 2.
	random_list = {
		100 = {
			trigger = {
				NOT = { scope:skill_1 = flag:$VALID_SKILL_1$ }
			}
			save_scope_value_as = {
				name = skill_2
				value = flag:$VALID_SKILL_1$
			}
		}
		100 = {
			trigger = {
				NOT = { scope:skill_1 = flag:$VALID_SKILL_2$ }
			}
			save_scope_value_as = {
				name = skill_2
				value = flag:$VALID_SKILL_2$
			}
		}
		100 = {
			trigger = {
				NOT = { scope:skill_1 = flag:$VALID_SKILL_3$ }
			}
			save_scope_value_as = {
				name = skill_2
				value = flag:$VALID_SKILL_3$
			}
		}
		100 = {
			trigger = {
				NOT = { scope:skill_1 = flag:$VALID_SKILL_4$ }
			}
			save_scope_value_as = {
				name = skill_2
				value = flag:$VALID_SKILL_4$
			}
		}
		100 = {
			trigger = {
				NOT = { scope:skill_1 = flag:$VALID_SKILL_5$ }
			}
			save_scope_value_as = {
				name = skill_2
				value = flag:$VALID_SKILL_5$
			}
		}
	}
}

scripted_effect junior_emperor_graduates_to_co_emperor_give_primary_skill_buffs_effect = {
	scope:senior_emp = {
		switch = {
			trigger = has_diarchy_active_parameter
			diarch_gain_skill_on_majority_t4 = {
				scope:junior_emp = { add_$SKILL$_skill = diarch_gain_skill_on_majority_t4_primary_value }
			}
			diarch_gain_skill_on_majority_t3 = {
				scope:junior_emp = { add_$SKILL$_skill = diarch_gain_skill_on_majority_t3_primary_value }
			}
			diarch_gain_skill_on_majority_t2 = {
				scope:junior_emp = { add_$SKILL$_skill = diarch_gain_skill_on_majority_t2_primary_value }
			}
			diarch_gain_skill_on_majority_t1 = {
				scope:junior_emp = { add_$SKILL$_skill = diarch_gain_skill_on_majority_t1_primary_value }
			}
		}
	}
}

scripted_effect junior_emperor_graduates_to_co_emperor_give_secondary_skill_buffs_effect = {
	# First, calc our value.
	scope:senior_emp = {
		switch = {
			trigger = has_diarchy_active_parameter
			diarch_gain_skill_on_majority_t4 = {
				save_scope_value_as = {
					name = secondary_skill_buff
					value = diarch_gain_skill_on_majority_t4_secondary_value
				}
			}
			diarch_gain_skill_on_majority_t3 = {
				save_scope_value_as = {
					name = secondary_skill_buff
					value = diarch_gain_skill_on_majority_t3_secondary_value
				}
			}
			diarch_gain_skill_on_majority_t2 = {
				save_scope_value_as = {
					name = secondary_skill_buff
					value = diarch_gain_skill_on_majority_t2_secondary_value
				}
			}
			diarch_gain_skill_on_majority_t1 = {
				save_scope_value_as = {
					name = secondary_skill_buff
					value = diarch_gain_skill_on_majority_t1_secondary_value
				}
			}
		}
	}
	# Now adjust scope:skill_1.
	switch = {
		trigger = scope:skill_1
		flag:diplomacy = { add_diplomacy_skill = scope:secondary_skill_buff }
		flag:martial = { add_martial_skill = scope:secondary_skill_buff }
		flag:stewardship = { add_stewardship_skill = scope:secondary_skill_buff }
		flag:intrigue = { add_intrigue_skill = scope:secondary_skill_buff }
		flag:learning = { add_learning_skill = scope:secondary_skill_buff }
		flag:prowess = { add_prowess_skill = scope:secondary_skill_buff }
	}
	# Now adjust scope:skill_2.
	switch = {
		trigger = scope:skill_2
		flag:diplomacy = { add_diplomacy_skill = scope:secondary_skill_buff }
		flag:martial = { add_martial_skill = scope:secondary_skill_buff }
		flag:stewardship = { add_stewardship_skill = scope:secondary_skill_buff }
		flag:intrigue = { add_intrigue_skill = scope:secondary_skill_buff }
		flag:learning = { add_learning_skill = scope:secondary_skill_buff }
		flag:prowess = { add_prowess_skill = scope:secondary_skill_buff }
	}
}

scripted_effect junior_emperor_graduates_to_co_emperor_effect = {
	# Change our diarchy type.
	## But fakesies, we just want it to appear at the top.
	### We need to stay in the old diarchy type so that our parameters stay the same.
	show_as_tooltip = {
		# For some Throne-forsaken reason if we generate the tooltip in the immediate, then it refers to the old type, so we're just gonna fake it.
		scope:senior_emp = { custom_tooltip = coming_of_age.3011.tt.fake_diarchy_transition }
	}
	# Plus apply our bonuses for our diarch.
	scope:junior_emp = {
		# Convert our SoP over.
		## Custom tooltip it so it doesn't look like a punishment.
		custom_tooltip = {
			text = coming_of_age.3011.tt.convert_sop_swing
			scope:senior_emp = {
				set_diarchy_swing = {
					value = diarchy_swing
					multiply = 0.5
					ceiling = yes
				}
			}
		}
		# Plus a reminder that there'll be more borrowed powers available now.
		custom_tooltip = coming_of_age.3011.tt.various_new_powers
		# Plus give us our skill points.
		if = {
			limit = {
				scope:senior_emp = { has_diarchy_active_parameter = diarch_gain_skill_on_majority_t1 }
			}
			switch = {
				trigger = has_trait
				education_diplomacy = {
					junior_emperor_graduates_to_co_emperor_give_primary_skill_buffs_effect = { SKILL = diplomacy }
					junior_emperor_graduates_to_co_emperor_give_secondary_skill_buffs_effect = yes
				}
				education_martial = {
					junior_emperor_graduates_to_co_emperor_give_primary_skill_buffs_effect = { SKILL = martial }
					junior_emperor_graduates_to_co_emperor_give_secondary_skill_buffs_effect = yes
				}
				education_stewardship = {
					junior_emperor_graduates_to_co_emperor_give_primary_skill_buffs_effect = { SKILL = stewardship }
					junior_emperor_graduates_to_co_emperor_give_secondary_skill_buffs_effect = yes
				}
				education_intrigue = {
					junior_emperor_graduates_to_co_emperor_give_primary_skill_buffs_effect = { SKILL = intrigue }
					junior_emperor_graduates_to_co_emperor_give_secondary_skill_buffs_effect = yes
				}
				education_learning = {
					junior_emperor_graduates_to_co_emperor_give_primary_skill_buffs_effect = { SKILL = learning }
					junior_emperor_graduates_to_co_emperor_give_secondary_skill_buffs_effect = yes
				}
			}
		}
		## ... assuming we earnt any.
		else = { custom_tooltip = coming_of_age.3011.tt.not_enough_sop_swing_to_buffs }
		# Ok, now transition for real.
		hidden_effect = {
			scope:senior_emp = { set_diarchy_type = co_emperorship }
		}
	}
}

#	Diarch POV.
coming_of_age.3011 = {
	type = character_event
	title = coming_of_age.3011.t
	desc = coming_of_age.3011.desc
	theme = emperor
	left_portrait = {
		character = scope:junior_emp
		animation = happiness
	}
	right_portrait = {
		character = scope:senior_emp
		triggered_animation = {
			trigger = {
				reverse_opinion = {
					target = scope:senior_emp
					value >= 25
				}
			}
			animation = admiration
		}
		triggered_animation = {
			trigger = {
				reverse_opinion = {
					target = scope:senior_emp
					value <= -25
				}
			}
			animation = dismissal
		}
		animation = personality_rational
	}

	trigger = {
		# Pre-filter everyone.
		is_diarch = yes
		# And _just_ in case we add more child diarchs in future.
		liege = { has_diarchy_parameter = diarchy_type_is_junior_emperorship }
	}

	immediate = {
		play_music_cue = "mx_cue_epic_sacral_moment"
		# Save scopes for loc/portrait convenience.
		save_scope_as = junior_emp
		liege = { save_scope_as = senior_emp }
		# Right, now pick which secondary traits we'll buff.
		## We do this in advance so that the scripted effect doesn't randomise different results between events.
		switch = {
			trigger = has_trait
			education_diplomacy = {
				coming_of_age_3011_roll_random_beneficial_skills = {
					VALID_SKILL_1 = martial
					VALID_SKILL_2 = stewardship
					VALID_SKILL_3 = intrigue
					VALID_SKILL_4 = learning
					VALID_SKILL_5 = prowess
				}
			}
			education_martial = {
				coming_of_age_3011_roll_random_beneficial_skills = {
					VALID_SKILL_1 = diplomacy
					VALID_SKILL_2 = stewardship
					VALID_SKILL_3 = intrigue
					VALID_SKILL_4 = learning
					VALID_SKILL_5 = prowess
				}
			}
			education_stewardship = {
				coming_of_age_3011_roll_random_beneficial_skills = {
					VALID_SKILL_1 = diplomacy
					VALID_SKILL_2 = martial
					VALID_SKILL_3 = intrigue
					VALID_SKILL_4 = learning
					VALID_SKILL_5 = prowess
				}
			}
			education_intrigue = {
				coming_of_age_3011_roll_random_beneficial_skills = {
					VALID_SKILL_1 = diplomacy
					VALID_SKILL_2 = martial
					VALID_SKILL_3 = stewardship
					VALID_SKILL_4 = learning
					VALID_SKILL_5 = prowess
				}
			}
			education_learning = {
				coming_of_age_3011_roll_random_beneficial_skills = {
					VALID_SKILL_1 = diplomacy
					VALID_SKILL_2 = martial
					VALID_SKILL_3 = stewardship
					VALID_SKILL_4 = learning
					VALID_SKILL_5 = prowess
				}
			}
		}
		# Then we show scope:junior_emp their results...
		show_as_tooltip = { junior_emperor_graduates_to_co_emperor_effect = yes }
		# ... whilst firing the actual results further down the line.
		scope:senior_emp = { trigger_event = coming_of_age.3012 }
	}

	# Workaholics are happy.
	option = {
		name = coming_of_age.3011.a
		trigger = { coming_of_age_3011_workaholic_traits_trigger = yes }

		# No further effects.

		stress_impact = {
			diligent = major_stress_impact_loss
			arrogant = major_stress_impact_loss
			ambitious = major_stress_impact_loss
		}
		#  No AI chance when you only get access to one option.
	}

	# Lazy lads are at a loss.
	option = {
		name = coming_of_age.3011.b
		trigger = {
			has_trait = lazy
			coming_of_age_3011_workaholic_traits_trigger = no
		}

		# No further effects.

		stress_impact = { lazy = major_stress_impact_gain }
		#  No AI chance when you only get access to one option.
	}

	# Everyone else is a bit nervous.
	option = {
		name = coming_of_age.3011.c
		trigger = {
			coming_of_age_3011_workaholic_traits_trigger = no
			NOT = { has_trait = lazy }
		}

		# No further effects.

		stress_impact = { base = medium_stress_impact_gain }
		#  No AI chance when you only get access to one option.
	}
}

#	Liege POV.
coming_of_age.3012 = {
	type = character_event
	title = coming_of_age.3012.t
	desc = {
		desc = coming_of_age.3012.desc.intro
		first_valid = {
			# Scope:senior_emp made scope:junior_emp into their diarch.
			triggered_desc = {
				trigger = { scope:junior_emp.var:co_emp_appointer = scope:senior_emp }
				desc = coming_of_age.3012.desc.senior_emp_appointed_junior_emp
			}
			# Else, they're different.
			desc = coming_of_age.3012.desc.junior_emp_appointed_elsewhere
		}
		desc = coming_of_age.3012.desc.outro
	}
	theme = emperor
	left_portrait = {
		character = scope:senior_emp
		triggered_animation = {
			trigger = {
				opinion = {
					target = scope:senior_emp
					value >= 25
				}
			}
			animation = admiration
		}
		triggered_animation = {
			trigger = {
				opinion = {
					target = scope:senior_emp
					value <= -25
				}
			}
			animation = dismissal
		}
		animation = personality_rational
	}
	right_portrait = {
		character = scope:junior_emp
		animation = happiness
	}

	immediate = {
		play_music_cue = "mx_cue_epic_sacral_moment"
		# Fire our actual effects.
		scope:junior_emp = { junior_emperor_graduates_to_co_emperor_effect = yes }
	}

	# Let us hope they don't fuck it up.
	option = {
		name = coming_of_age.3012.a
		
		# No further effects.
		
		# Don't hit the player with stress here, or they'll steer clear of this.
		#  No AI chance when you only get access to one option.
	}
}
