﻿#Events dealing with coming of age

namespace = coming_of_age

#Prowess
#Leadership


#Leadership - notification event for child

coming_of_age.0008 = {
	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_nht_leadership
						rank = 1
					}
				}
				desc = {
					desc = coming_of_age.0001.desc1
					first_valid = {
						triggered_desc = {
							trigger = {
								has_nht_leadership_education_affinity_childhood_trait_trigger = yes
							}
							desc = coming_of_age.0001.desc1_good_trait
						}
						triggered_desc = {
							trigger = {
								has_nht_leadership_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_nht_leadership
						rank = 2
					}
				}
				desc = {
					desc = coming_of_age.0001.desc2
					first_valid = {
						triggered_desc = {
							trigger = {
								has_nht_leadership_education_affinity_childhood_trait_trigger = yes
							}
							desc = coming_of_age.0001.desc2_good_trait
						}
						triggered_desc = {
							trigger = {
								has_nht_leadership_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_nht_leadership
						rank = 3
					}
				}
				desc = {
					desc = coming_of_age.0001.desc3
					first_valid = {
						triggered_desc = {
							trigger = {
								has_nht_leadership_education_affinity_childhood_trait_trigger = yes
							}
							desc = coming_of_age.0001.desc3_good_trait
						}
						triggered_desc = {
							trigger = {
								has_nht_leadership_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_nht_leadership
						rank >= 4
					}
				}
				desc = {
					desc = coming_of_age.0001.desc4
					first_valid = {
						triggered_desc = {
							trigger = {
								has_nht_leadership_education_affinity_childhood_trait_trigger = yes
							}
							desc = coming_of_age.0001.desc4_good_trait
						}
						triggered_desc = {
							trigger = {
								has_nht_leadership_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_nht_prowess
			}
  			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
  		}
		triggered_animation = {
			trigger = {
				has_focus = education_nht_leadership
			}
  			animation = flirtation_left
  		}
		animation = idle
	}
	override_background = {
		trigger = {
			has_focus = education_nht_prowess
		}
		reference = courtyard
	}
	override_background = {
		trigger = {
			has_focus = education_nht_leadership
			culture = {
				OR = {
					has_building_gfx = western_building_gfx
					has_building_gfx = mediterranean_building_gfx
				}
			}
		}
		reference = council_chamber
	}
	override_background = {
		trigger = {
			has_focus = education_nht_leadership
			culture = {
				NOR = {
					has_building_gfx = western_building_gfx
					has_building_gfx = mediterranean_building_gfx
				}
			}
		}
		reference = throne_room
	}
	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_nht_leadership
		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
			has_trait = education_nht_prowess
			has_trait = education_nht_leadership
		}
	}

	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_nht_leadership_variable <= education_level_1
			}
			
			set_trait_rank = {
				trait = education_nht_leadership
				rank = 1
			}
		}
		else_if = {
			limit = {
				var:education_nht_leadership_variable <= education_level_2
			}
			
			set_trait_rank = {
				trait = education_nht_leadership
				rank = 2
			}
		}
		else_if = {
			limit = {
				var:education_nht_leadership_variable <= education_level_3
			}
			
			set_trait_rank = {
				trait = education_nht_leadership
				rank = 3
			}
		}
		else = {
			random_list = {
				50 = {
					set_trait_rank = {
						trait = education_nht_leadership
						rank = 4
					}
				}
				50 = {
					trigger = {
						OR = {
							dynasty ?= { exists = var:ce1_legitimacy_legacy_5_education_nht_leadership_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_nht_leadership
						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_nht_leadership_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
		}
	}
}

#Prowess - notification event for child
coming_of_age.0009 = {
	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_nht_prowess
						rank = 1
					}
				}
				desc = {
					desc = coming_of_age.0001.desc1
					first_valid = {
						triggered_desc = {
							trigger = {
								has_prowess_education_affinity_childhood_trait_trigger = yes
							}
							desc = coming_of_age.0001.desc1_good_trait
						}
						triggered_desc = {
							trigger = {
								has_prowess_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_nht_prowess
						rank = 2
					}
				}
				desc = {
					desc = coming_of_age.0001.desc2
					first_valid = {
						triggered_desc = {
							trigger = {
								has_prowess_education_affinity_childhood_trait_trigger = yes
							}
							desc = coming_of_age.0001.desc2_good_trait
						}
						triggered_desc = {
							trigger = {
								has_prowess_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_nht_prowess
						rank = 3
					}
				}
				desc = {
					desc = coming_of_age.0001.desc3
					first_valid = {
						triggered_desc = {
							trigger = {
								has_prowess_education_affinity_childhood_trait_trigger = yes
							}
							desc = coming_of_age.0001.desc3_good_trait
						}
						triggered_desc = {
							trigger = {
								has_prowess_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_nht_prowess
						rank >= 4
					}
				}
				desc = {
					desc = coming_of_age.0001.desc4
					first_valid = {
						triggered_desc = {
							trigger = {
								has_prowess_education_affinity_childhood_trait_trigger = yes
							}
							desc = coming_of_age.0001.desc4_good_trait
						}
						triggered_desc = {
							trigger = {
								has_prowess_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_nht_prowess
			}
  			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
  		}
		triggered_animation = {
			trigger = {
				has_focus = education_nht_leadership
			}
  			animation = flirtation_left
  		}
		animation = idle
	}
	override_background = {
		trigger = {
			has_focus = education_nht_prowess
		}
		reference = courtyard
	}
	override_background = {
		trigger = {
			has_focus = education_nht_leadership
			culture = {
				OR = {
					has_building_gfx = western_building_gfx
					has_building_gfx = mediterranean_building_gfx
				}
			}
		}
		reference = council_chamber
	}
	override_background = {
		trigger = {
			has_focus = education_nht_leadership
			culture = {
				NOR = {
					has_building_gfx = western_building_gfx
					has_building_gfx = mediterranean_building_gfx
				}
			}
		}
		reference = throne_room
	}
	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 = 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_nht_prowess
		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_nht_prowess
			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_nht_prowess_variable <= education_level_1
			}
			
			set_trait_rank = {
				trait = education_nht_prowess
				rank = 1
			}
		}
		else_if = {
			limit = {
				var:education_nht_prowess_variable <= education_level_2
			}
			
			set_trait_rank = {
				trait = education_nht_prowess
				rank = 2
			}
		}
		else_if = {
			limit = {
				var:education_nht_prowess_variable <= education_level_3
			}
			
			set_trait_rank = {
				trait = education_nht_prowess
				rank = 3
			}
		}
		else = {
			random_list = {
				50 = {
					set_trait_rank = {
						trait = education_nht_prowess
						rank = 4
					}
				}
				50 = {
					trigger = {
						OR = {
							dynasty ?= { exists = var:ce1_legitimacy_legacy_5_education_nht_prowess_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_nht_prowess
						rank = 5
					}
				}
			}
		}
		
		#Other martial education things.
		hidden_effect = { #To assign a commander trait
			random_list = {
				20 = {
					modifier = {
						add = 5
						has_trait_rank = {
							trait = education_nht_prowess
							rank >= 1
						}
					}
					modifier = {
						add = 15
						has_trait_rank = {
							trait = education_nht_prowess
							rank >= 2
						}
					}
					modifier = {
						add = 20
						has_trait_rank = {
							trait = education_nht_prowess
							rank >= 3
						}
					}
					modifier = {
						add = 25
						has_trait_rank = {
							trait = education_nht_prowess
							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_nht_prowess_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
		}
	}
}