﻿on_birthday = {
	on_actions = {
		AuGu_all_on_action
		AuGu_only_children_on_action
		AuGu_only_close_familly_on_action
	}
}

on_death = {
	on_actions = {
		AuGu_death_on_action
	}
}

AuGu_death_on_action = {
	trigger = {
		is_ai = no
		OR = {
			has_variable = AuGu_setting_all_var
			has_variable = AuGu_setting_no_close_familly_var
			has_variable = AuGu_setting_no_children_var
			has_variable = AuGu_setting_no_heir_var
			has_variable = AuGu_setting_only_children_var
			has_variable = AuGu_setting_only_close_familly_var
			has_variable = AuGu_setting_tutor_var
		}
	}
	effect = {
		if = {
			limit = { has_variable = AuGu_setting_all_var }
			remove_variable = AuGu_setting_all_var
			player_heir = {
				set_variable = {
					name = AuGu_setting_all_var
					value = flag:yes
				}
			}
		}
		else_if = {
			limit = { has_variable = AuGu_setting_only_children_var }
			remove_variable = AuGu_setting_only_children_var
			player_heir = {
				set_variable = {
					name = AuGu_setting_only_children_var
					value = flag:yes
				}
			}
		}
		else_if = {
			limit = { has_variable = AuGu_setting_only_close_familly_var }
			remove_variable = AuGu_setting_only_close_familly_var
			player_heir = {
				set_variable = {
					name = AuGu_setting_only_close_familly_var
					value = flag:yes
				}
			}
		}
		if = {
			limit = { has_variable = AuGu_setting_no_close_familly_var }
			remove_variable = AuGu_setting_no_close_familly_var
			player_heir = {
				set_variable = {
					name = AuGu_setting_no_close_familly_var
					value = flag:yes
				}
			}
		}
		else_if = {
			limit = { has_variable = AuGu_setting_no_children_var }
			remove_variable = AuGu_setting_no_children_var
			player_heir = {
				set_variable = {
					name = AuGu_setting_no_children_var
					value = flag:yes
				}
			}
		}
		else_if = {
			limit = { has_variable = AuGu_setting_no_heir_var }
			remove_variable = AuGu_setting_no_heir_var
			player_heir = {
				set_variable = {
					name = AuGu_setting_no_heir_var
					value = flag:yes
				}
			}
		}
		if = {
			limit = { has_variable = AuGu_setting_tutor_var }
			remove_variable = AuGu_setting_tutor_var
			player_heir = {
				set_variable = {
					name = AuGu_setting_tutor_var
					value = flag:yes
				}
			}
		}		
	}
}

AuGu_all_on_action = {
	trigger = {
		liege ?= { 
			is_ai = no 
			has_variable = AuGu_setting_all_var
		}
		is_adult = no
		age >= 6
		age < 16
		is_human = yes ## compat agot
		num_of_relation_guardian = 0
		trigger_if = {
			limit = {
				liege ?= {
					has_variable = AuGu_setting_no_heir_var
				}
			}
			NOT = { is_player_heir_of = liege }
		}
		trigger_if = {
			limit = {
				liege ?= {
					has_variable = AuGu_setting_no_children_var
				}
			}
			NOT = { is_child_of = liege }
		}
		trigger_if = {
			limit = {
				liege ?= {
					has_variable = AuGu_setting_no_close_familly_var
				}
			}
			NOT = { is_close_family_of = liege }
		}
	}
	effect = {
		if = {
			limit = { has_education_focus_trigger = no }
			add_character_flag = natural_education_progression
			set_default_education = yes
		}
		liege = {
			save_scope_as = AuGu_liege
			if = {
				limit = {
					any_courtier = {
						exists = this
						is_physically_able_adult = yes
						num_of_relation_ward < 2
						is_human = yes ## compat agot
						this.AuGu_check_weight_value > AuGu_check_weight_value_ts
						AuGu_tutor_trigger = yes
					}
				}
				ordered_courtier = {
					limit = {
						is_physically_able_adult = yes
						num_of_relation_ward < 2
						is_human = yes ## compat agot
						this.AuGu_check_weight_value > AuGu_check_weight_value_ts
						AuGu_tutor_trigger = yes
					}				
					order_by = AuGu_check_weight_value
					max = 1
					
					save_scope_as = AuGu_guardian
					scope:AuGu_liege = {
						send_interface_toast = {
							type = msg_child_language
							title = AuGu_guardian_tt
							left_icon = root
							right_icon = scope:AuGu_guardian
							scope:AuGu_guardian = { set_relation_ward = root }
						}
					}
				}
			}
		}
	}
}

AuGu_only_children_on_action = {
	trigger = {
		liege ?= { 
			is_ai = no 
			has_variable = AuGu_setting_only_children_var
		}
		is_adult = no
		age >= 6
		age < 16
		is_human = yes ## compat agot
		num_of_relation_guardian = 0
		is_child_of = liege
		trigger_if = {
			limit = {
				liege ?= {
					has_variable = AuGu_setting_no_heir_var
				}
			}
			NOT = { is_player_heir_of = liege }
		}
	}
	effect = {
		if = {
			limit = { has_education_focus_trigger = no }
			add_character_flag = natural_education_progression
			set_default_education = yes
		}
		liege = {
			save_scope_as = AuGu_liege
			if = {
				limit = {
					any_courtier = {
						exists = this
						is_physically_able_adult = yes
						num_of_relation_ward < 2
						is_human = yes ## compat agot
						this.AuGu_check_weight_value > AuGu_check_weight_value_ts
						AuGu_tutor_trigger = yes
					}
				}
				ordered_courtier = {
					limit = {
						is_physically_able_adult = yes
						num_of_relation_ward < 2
						is_human = yes ## compat agot
						this.AuGu_check_weight_value > AuGu_check_weight_value_ts
						AuGu_tutor_trigger = yes
					}
					order_by = AuGu_check_weight_value
					max = 1
					
					save_scope_as = AuGu_guardian
					scope:AuGu_liege = {
						send_interface_toast = {
							type = msg_child_language
							title = AuGu_guardian_tt
							left_icon = root
							right_icon = scope:AuGu_guardian
							scope:AuGu_guardian = { set_relation_ward = root }
						}
					}
				}
			}
		}
	}
}

AuGu_only_close_familly_on_action = {
	trigger = {
		liege ?= { 
			is_ai = no 
			has_variable = AuGu_setting_only_close_familly_var
		}
		is_adult = no
		age >= 6
		age < 16
		is_human = yes ## compat agot
		num_of_relation_guardian = 0
		is_close_family_of = liege
		trigger_if = {
			limit = {
				liege ?= {
					has_variable = AuGu_setting_no_heir_var
				}
			}
			NOT = { is_player_heir_of = liege }
		}
		trigger_if = {
			limit = {
				liege ?= {
					has_variable = AuGu_setting_no_children_var
				}
			}
			NOT = { is_child_of = liege }
		}
	}
	effect = {
		if = {
			limit = { has_education_focus_trigger = no }
			add_character_flag = natural_education_progression
			set_default_education = yes
		}
		liege = {
			save_scope_as = AuGu_liege
			if = {
				limit = {
					any_courtier = {
						exists = this
						is_physically_able_adult = yes
						num_of_relation_ward < 2
						is_human = yes ## compat agot
						this.AuGu_check_weight_value > AuGu_check_weight_value_ts
						AuGu_tutor_trigger = yes
					}
				}
				ordered_courtier = {
					limit = {
						is_physically_able_adult = yes
						num_of_relation_ward < 2
						is_human = yes ## compat agot
						this.AuGu_check_weight_value > AuGu_check_weight_value_ts
						AuGu_tutor_trigger = yes
					}
					order_by = AuGu_check_weight_value
					max = 1
					
					save_scope_as = AuGu_guardian
					scope:AuGu_liege = {
						send_interface_toast = {
							type = msg_child_language
							title = AuGu_guardian_tt
							left_icon = root
							right_icon = scope:AuGu_guardian
							scope:AuGu_guardian = { set_relation_ward = root }
						}
					}
				}
			}
		}
	}
}

