﻿
#Effect to identify characters for the "Education Completed" notification events
# FR: Added new scopes for romance after coming at age event.
education_complete_notification_effect = {
	save_scope_as = educated_child
	# Family romance mod
	save_scope_as = educated_child_for_romance
	# Family romance mod
	
	if = {
		limit = {
			any_relation = { type = guardian }
		}
		random_relation = {
			type = guardian
			if = {
				limit = { this = { is_parent_of = root } }
				save_scope_as = parent_guardian
				
				# Family romance mod
				save_scope_as = guardian_for_romance
				# Family romance mod
				
				trigger_event = coming_of_age.1001
			}
			else = {
				save_scope_as = guardian
				# Family romance mod
				if = {
					limit = {
						this = { is_sibling_of = root }
					}					
					save_scope_as = guardian_for_romance
				}
				else_if = {
					limit = {
						this = { is_uncle_or_aunt_of = root }
					}
					save_scope_as = guardian_for_romance
				}
				# Family romance mod
				
				if = {
					limit = {
						scope:educated_child = {
							any_parent = { is_alive = no }
							any_parent = { is_alive = yes }
						}
					}
					random_parent = {
						limit = { is_alive = yes }
						save_scope_as = living_parent
					}
					random_parent = {
						limit = { is_alive = no }
						save_scope_as = dead_parent
					}
					trigger_event = coming_of_age.1003 #Event for non-parent guardian when one parent of the child is dead
				}
				else_if = {
					limit = {
						scope:educated_child = {
							any_parent = {
								is_alive = yes
								count = 2
							}
						}
					}
					scope:educated_child.father = { save_scope_as = father }
					scope:educated_child.mother = { save_scope_as = mother }
					trigger_event = coming_of_age.1004 #Event for non-parent guardian when both parents are alive
				}
				else_if = {
					limit = {
						OR = {
							NOT = { exists = scope:educated_child.father }
							NOT = { exists = scope:educated_child.mother }
						}
					}
					if = {
						limit = {
							exists = scope:educated_child.father
						}
						scope:educated_child.father = {
							save_scope_as = parent
						}
					}
					if = {
						limit = {
							exists = scope:educated_child.mother
						}
						scope:educated_child.mother = {
							save_scope_as = parent
						}
					}
					if = {
						limit = {
							NOT = { exists = scope:parent }
						}
						trigger_event = coming_of_age.1005
					}
					else = {
						trigger_event = coming_of_age.1003
					}
				}
				else = {
					scope:educated_child.father = { save_scope_as = father }
					scope:educated_child.mother = { save_scope_as = mother }
					trigger_event = coming_of_age.1005 #Event for non-parent guardian when both parents are dead
				}
			}
			hidden_effect = { # Hidden to avoid duplicate effect messages
				#Relationship back-up clean-up
				remove_guardian_effect = {
					GUARDIAN = this
					WARD = scope:educated_child
					RETURN_WARD = no
					HIDE_OPINION = no
				}
			}		
		}
	}
	every_parent = {
		limit = {
			OR = {
				NOT = { exists = scope:parent_guardian }
				AND = {
					exists = scope:parent_guardian
					this != scope:parent_guardian
				}
			}
		}
		if = {
			limit = {
				OR = {
					has_relation_favorite_child = scope:educated_child
					scope:educated_child = {
						OR = {
							is_ruler = yes
							is_primary_heir_of = prev
							is_player_heir_of = prev
							NOT = {
								any_sibling = {
									count >= 2
									is_alive = yes
									age >= scope:educated_child.age
								}
							}
						}
					}
				}
			}
			trigger_event = coming_of_age.1002
		}
		else = {
			save_scope_as = relative
			send_interface_message = {
				type = msg_child_of_age
				title = msg_child_of_age_title
				desc = msg_child_of_age_desc
				left_icon = scope:educated_child
				scope:educated_child = { display_correct_education_trait_gain_tooltip_effect = yes }
			}
		}
	}
	# Family romance mod
	trigger_event = coming_of_age_familyromance.0001	
	# Family romance mod
	
	# Inform non-parent dynasty member players they are in the court of
	if = {
		limit = { is_lowborn = no }
		every_player = {
			limit = {
				scope:educated_child.dynasty ?= dynasty
				NOR = {
					is_parent_of = scope:educated_child
					scope:parent_guardian ?= this
				}
				OR = {
					scope:educated_child.liege ?= this
					scope:educated_child.employer ?= this
					scope:educated_child.court_owner ?= this
				}
			}
			save_scope_as = relative
			send_interface_message = {
				type = msg_dynasty_child_of_age
				title = msg_dynasty_child_of_age_title
				desc = msg_dynasty_child_of_age_desc
				left_icon = scope:educated_child
				scope:educated_child = { display_correct_education_trait_gain_tooltip_effect = yes }
			}
		}
	}
	liege ?= {
		if = {
			limit = {
				is_ai = no
				is_employer_of = scope:educated_child
				NOR = {
					scope:educated_child.dynasty ?= dynasty
					is_parent_of = scope:educated_child
					scope:parent_guardian ?= this
				}
			}
			save_scope_as = relative
			send_interface_message = {
				type = msg_courtier_child_of_age
				title = msg_courtier_child_of_age_title
				desc = msg_dynasty_child_of_age_desc
				left_icon = scope:educated_child
				scope:educated_child = { display_correct_education_trait_gain_tooltip_effect = yes }
			}
		}
	}
}


# FR: Add triggering a special event for brother/sister childhood crush
remove_variables_and_trait_coming_of_age_effect = {
	# Family romance mod
	trigger_event = coming_of_age_familyromance.0052
	# Family romance mod	
	
	if = {
		limit = {
			exists = var:had_childhood_crush_variable
		}
		remove_variable = had_childhood_crush_variable
	}
	if = {
		limit = {
			exists = var:unrequited_crush
		}
		remove_variable = unrequited_crush
	}
	if = {
		limit = {
			exists = var:had_childhood_victim_variable
		}
		remove_variable = had_childhood_victim_variable
	}
	if = {
		limit = {
			exists = var:had_childhood_bully_variable
		}
		remove_variable = had_childhood_bully_variable
	}
	if = {
		limit = { has_trait = curious }
		remove_trait = curious
	}
	if = {
		limit = { has_trait = rowdy }
		remove_trait = rowdy
	}
	if = {
		limit = { has_trait = bossy }
		remove_trait = bossy
	}
	if = {
		limit = { has_trait = charming }
		remove_trait = charming
	}
	if = {
		limit = { has_trait = pensive }
		remove_trait = pensive
	}
	if = {
		limit = {
			has_character_flag = bully_destroyed_toy
		}
		remove_character_flag = bully_destroyed_toy
	}
	if = {
		limit = {
			has_character_flag = natural_education_progression
		}
		remove_character_flag = natural_education_progression
	}
	if = {
		limit = {
			has_variable = education_point_gain_variable
		}
		remove_variable = education_point_gain_variable
	}
	if = {
		limit = {
			has_variable = childhood_trait_type
		}
		remove_variable = childhood_trait_type
	}
	if = {
		limit = {
			exists = var:education_diplomacy_variable
		}
		remove_variable = education_diplomacy_variable
	}
	if = {
		limit = {
			exists = var:education_martial_variable
		}
		remove_variable = education_martial_variable
	}
	if = {
		limit = {
			exists = var:education_stewardship_variable
		}
		remove_variable = education_stewardship_variable
	}
	if = {
		limit = {
			exists = var:education_intrigue_variable
		}
		remove_variable = education_intrigue_variable
	}
	if = {
		limit = {
			exists = var:education_learning_variable
		}
		remove_variable = education_learning_variable
	}
}


