﻿# EK NOTE: added arcane education option effects

#Placeholder hostage effect
take_hostage = {
	add_visiting_courtier = $HOSTAGE$
}

#Adult Education rewards effects
#Account for the state of our variables, apply flags that are resolved in disburse_adult_education_reward_effect
resolve_adult_education_success_reward_effect = {
	involved_activity ?= {
		#Perfect studies - 75-100
		if = {
			limit = { var:activity_special_type_progression >= 75 }
			scope:host = {
				add_character_flag = perfect_studies_reward
				if = { #100% from 1 to 2
					limit = { has_level_1_education_trait_trigger = yes }
					add_character_flag = increase_education_level_1
				}
				else_if = { #100% chance from 2 to 3
					limit = { has_level_2_education_trait_trigger = yes }
					add_character_flag = increase_education_level_2
				}
				else_if = { #85% chance from 3 to 4
					limit = { has_level_3_education_trait_trigger = yes }
					random = {
						chance = 85
						add_character_flag = increase_education_level_3
					}
				}
				else_if = { #60% chance from 4 to 5
					limit = { has_level_4_education_trait_trigger = yes }
					random = {
						chance = 60
						modifier = {
							involved_activity = {
								has_activity_option = {
									category = adult_education_option_books
									option = adult_education_books_normal
								}
							}
							add = 5
						}
						add_character_flag = increase_education_level_4
					}
				}
			}
		}
		#High-end studies - 50-75
		else_if = {
			limit = { 
				var:activity_special_type_progression < 75
				var:activity_special_type_progression >= 50
			} 
			scope:host = {
				add_character_flag = high_studies_reward
				if = { #100% from 1 to 2
					limit = { has_level_1_education_trait_trigger = yes }
					add_character_flag = increase_education_level_1
				}
				else_if = { #85% from 2 to 3
					limit = { has_level_2_education_trait_trigger = yes }
					random = {
						chance = 85
						add_character_flag = increase_education_level_2
					}
				}
				else_if = { #65% from 3 to 4
					limit = { has_level_3_education_trait_trigger = yes }
					random = {
						chance = 65
						add_character_flag = increase_education_level_3
					}
				}
				else_if = { #40% chance from 4 to 5
					limit = { has_level_4_education_trait_trigger = yes }
					random = {
						chance = 40
						modifier = {
							involved_activity = {
								has_activity_option = {
									category = adult_education_option_books
									option = adult_education_books_normal
								}
							}
							add = 5
						}
						add_character_flag = increase_education_level_4
					}
				}
			}
		}
		#OK studies - 25-50
		else_if = {
			limit = {
				var:activity_special_type_progression < 50
				var:activity_special_type_progression >= 25
			}
			scope:host = {
				add_character_flag = mid_studies_reward
				if = { #85% from 1 to 2
					limit = { has_level_1_education_trait_trigger = yes }
					random = {
						chance = 85
						add_character_flag = increase_education_level_1
					}
				}
				else_if = { #65% from 2 to 3
					limit = { has_level_2_education_trait_trigger = yes }
					random = {
						chance = 65
						add_character_flag = increase_education_level_2
					}
				}
				else_if = { #40% from 3 to 4
					limit = { has_level_3_education_trait_trigger = yes }
					random = {
						chance = 40
						add_character_flag = increase_education_level_3
					}
				}
				else_if = { #15% chance from 4 to 5
					limit = { has_level_4_education_trait_trigger = yes }
					random = {
						chance = 15
						modifier = {
							involved_activity = {
								has_activity_option = {
									category = adult_education_option_books
									option = adult_education_books_normal
								}
							}
							add = 5
						}
						add_character_flag = increase_education_level_4
					}
				}
			}
		}
		#Lousy studies - 0-25
		else = {
			scope:host = {
				add_character_flag = low_studies_reward
				if = { #65% from 1 to 2
					limit = { has_level_1_education_trait_trigger = yes }
					random = {
						chance = 65
						add_character_flag = increase_education_level_1
					}
				}
				else_if = { #40% from 2 to 3
					limit = { has_level_2_education_trait_trigger = yes }
					random = {
						chance = 40
						add_character_flag = increase_education_level_2
					}
				}
				else_if = { #15% from 3 to 4
					limit = { has_level_3_education_trait_trigger = yes }
					random = {
						chance = 15
						add_character_flag = increase_education_level_3
					}
				}
			}
		}
	}
}

#EK ADDITION
resolve_arcane_education_success_reward_effect = {
	involved_activity ?= {
		#Perfect studies - 75-100
		if = {
			limit = { var:activity_special_type_progression >= 75 }
			scope:host = {
				add_character_flag = perfect_studies_reward
				if = { #100% from 0 to 1
					limit = { NOT = { has_trait = education_magic } }
					add_character_flag = increase_education_level_0
				}
				else_if = { #100% from 1 to 2
					limit = { has_trait = education_magic_1 }
					add_character_flag = increase_education_level_1
				}
				else_if = { #100% chance from 2 to 3
					limit = { has_trait = education_magic_2 }
					add_character_flag = increase_education_level_2
				}
				else_if = { #85% chance from 3 to 4
					limit = { has_trait = education_magic_3 }
					random = {
						chance = 85
						add_character_flag = increase_education_level_3
					}
				}
				else_if = { #60% chance from 4 to 5
					limit = { has_trait = education_magic_4 }
					random = {
						chance = 60
						modifier = {
							involved_activity = {
								has_activity_option = {
									category = adult_education_option_books
									option = adult_education_books_normal
								}
							}
							add = 5
						}
						add_character_flag = increase_education_level_4
					}
				}
			}
		}
		#High-end studies - 50-75
		else_if = {
			limit = { 
				var:activity_special_type_progression < 75
				var:activity_special_type_progression >= 50
			} 
			scope:host = {
				add_character_flag = high_studies_reward
				if = { #100% from 0 to 1
					limit = { NOT = { has_trait = education_magic } }
					add_character_flag = increase_education_level_0
				}
				else_if = { #100% from 1 to 2
					limit = { has_trait = education_magic_1 }
					add_character_flag = increase_education_level_1
				}
				else_if = { #85% from 2 to 3
					limit = { has_trait = education_magic_2 }
					random = {
						chance = 85
						add_character_flag = increase_education_level_2
					}
				}
				else_if = { #65% from 3 to 4
					limit = { has_trait = education_magic_3 }
					random = {
						chance = 65
						add_character_flag = increase_education_level_3
					}
				}
				else_if = { #40% chance from 4 to 5
					limit = { has_trait = education_magic_4 }
					random = {
						chance = 40
						modifier = {
							involved_activity = {
								has_activity_option = {
									category = adult_education_option_books
									option = adult_education_books_normal
								}
							}
							add = 5
						}
						add_character_flag = increase_education_level_4
					}
				}
			}
		}
		#OK studies - 25-50
		else_if = {
			limit = {
				var:activity_special_type_progression < 50
				var:activity_special_type_progression >= 25
			}
			scope:host = {
				add_character_flag = mid_studies_reward
				if = { #100% from 0 to 1
					limit = { NOT = { has_trait = education_magic } }
					add_character_flag = increase_education_level_0
				}
				else_if = { #85% from 1 to 2
					limit = { has_trait = education_magic_1 }
					random = {
						chance = 85
						add_character_flag = increase_education_level_1
					}
				}
				else_if = { #65% from 2 to 3
					limit = { has_trait = education_magic_2 }
					random = {
						chance = 65
						add_character_flag = increase_education_level_2
					}
				}
				else_if = { #40% from 3 to 4
					limit = { has_trait = education_magic_3 }
					random = {
						chance = 40
						add_character_flag = increase_education_level_3
					}
				}
				else_if = { #15% chance from 4 to 5
					limit = { has_trait = education_magic_4 }
					random = {
						chance = 15
						modifier = {
							involved_activity = {
								has_activity_option = {
									category = adult_education_option_books
									option = adult_education_books_normal
								}
							}
							add = 5
						}
						add_character_flag = increase_education_level_4
					}
				}
			}
		}
		#Lousy studies - 0-25
		else = {
			scope:host = {
				add_character_flag = low_studies_reward
				if = { #100% from 0 to 1
					limit = { NOT = { has_trait = education_magic } }
					add_character_flag = increase_education_level_0
				}
				else_if = { #65% from 1 to 2
					limit = { has_trait = education_magic_1 }
					random = {
						chance = 65
						add_character_flag = increase_education_level_1
					}
				}
				else_if = { #40% from 2 to 3
					limit = { has_trait = education_magic_2 }
					random = {
						chance = 40
						add_character_flag = increase_education_level_2
					}
				}
				else_if = { #15% from 3 to 4
					limit = { has_trait = education_magic_3 }
					random = {
						chance = 15
						add_character_flag = increase_education_level_3
					}
				}
			}
		}
	}
}

adult_education_completed_log_entry_effect = {
	involved_activity = {
		add_activity_log_entry = {
			key = adult_education_studies_completed_log
			tags = { completed }
			score = 100
			show_in_conclusion = yes
			character = root
			#Effects
			root = {
				disburse_adult_education_reward_effect = yes
			}
		}
	}
}

add_relevant_lifestyle_perk_point_effect = {
	if = {
		limit = {
			has_trait = education_diplomacy
		}
		add_diplomacy_lifestyle_perk_points = $NUMBER$
	}
	else_if = {
		limit = {
			has_trait = education_martial
		}
		add_martial_lifestyle_perk_points = $NUMBER$
	}
	else_if = {
		limit = {
			has_trait = education_stewardship
		}
		add_stewardship_lifestyle_perk_points = $NUMBER$
	}
	else_if = {
		limit = {
			has_trait = education_intrigue
		}
		add_intrigue_lifestyle_perk_points = $NUMBER$
	}
	else_if = {
		limit = {
			has_trait = education_learning
		}
		add_learning_lifestyle_perk_points = $NUMBER$
	}
}

#EK EDIT: reworked, to implement magic option
disburse_adult_education_reward_effect = {
	if = { 
		limit = { involved_activity = { activity_has_mundane_education_type_trigger = yes } }
		switch = { # Hand out education traits
			trigger = has_character_flag
			increase_education_level_1 = {
				increase_education_level_1_effect = yes
				remove_character_flag = increase_education_level_1
			}
			increase_education_level_2 = {
				increase_education_level_2_effect = yes
				remove_character_flag = increase_education_level_2
			}
			increase_education_level_3 = {
				increase_education_level_3_effect = yes
				remove_character_flag = increase_education_level_3
			}
			increase_education_level_4 = {
				increase_education_level_4_effect = yes
				remove_character_flag = increase_education_level_4
			}
		}
		switch = { # Hand out lifestyle perks/xp
			trigger = has_character_flag
			perfect_studies_reward = {
				add_relevant_lifestyle_perk_point_effect = { NUMBER = 3 }
				remove_character_flag = perfect_studies_reward
			}
			high_studies_reward = {
				add_relevant_lifestyle_perk_point_effect = { NUMBER = 2 }
				remove_character_flag = high_studies_reward
			}
			mid_studies_reward = {
				add_relevant_lifestyle_perk_point_effect = { NUMBER = 1 }
				remove_character_flag = mid_studies_reward
			}
			low_studies_reward = {
				bp2_lifestyle_xp_gain_per_type_effect = { VALUE = major }
				remove_character_flag = low_studies_reward
			}
		}
		switch = { # Hand out lifestyle perks/xp
			trigger = has_character_flag
			perfect_studies_reward = {
				add_relevant_lifestyle_perk_point_effect = { NUMBER = 3 }
				remove_character_flag = perfect_studies_reward
			}
			high_studies_reward = {
				add_relevant_lifestyle_perk_point_effect = { NUMBER = 2 }
				remove_character_flag = high_studies_reward
			}
			mid_studies_reward = {
				add_relevant_lifestyle_perk_point_effect = { NUMBER = 1 }
				remove_character_flag = mid_studies_reward
			}
			low_studies_reward = {
				bp2_lifestyle_xp_gain_per_type_effect = { VALUE = major }
				remove_character_flag = low_studies_reward
			}
		}
	}
	if = { 
		limit = { involved_activity = { activity_has_arcane_education_type_trigger = yes } }
		switch = { # Hand out education traits
			trigger = has_character_flag
			increase_education_level_0 = {
				increase_education_level_0_type_effect = { TYPE = magic }
				remove_character_flag = increase_education_level_0
			}
			increase_education_level_1 = {
				increase_education_level_1_type_effect = { TYPE = magic }
				remove_character_flag = increase_education_level_1
			}
			increase_education_level_2 = {
				increase_education_level_2_type_effect = { TYPE = magic }
				remove_character_flag = increase_education_level_2
			}
			increase_education_level_3 = {
				increase_education_level_3_type_effect = { TYPE = magic }
				remove_character_flag = increase_education_level_3
			}
			increase_education_level_4 = {
				increase_education_level_4_type_effect = { TYPE = magic }
				remove_character_flag = increase_education_level_4
			}
		}
		switch = { # Hand out lifestyle/perk xp
			trigger = has_character_flag
			perfect_studies_reward = {
				add_magic_lifestyle_xp = 3000
				remove_character_flag = perfect_studies_reward
			}
			high_studies_reward = {
				add_magic_lifestyle_xp = 2000
				remove_character_flag = high_studies_reward
			}
			mid_studies_reward = {
				add_magic_lifestyle_xp = 1000
				remove_character_flag = mid_studies_reward
			}
			low_studies_reward = {
				add_magic_lifestyle_xp = 500
				remove_character_flag = low_studies_reward
			}
		}
	}
	# Options rewards
	if = {
		limit = { involved_activity = { activity_has_mundane_education_type_trigger = yes } }
		if = {
			limit = {
				scope:activity = {
					has_activity_option = {
						category = adult_education_option_books
						option = adult_education_books_good
					}
				}
				has_dlc_feature = royal_court
				scope:host = { has_royal_court = yes }
			}
			custom_tooltip = adult_education_books_good_reward
			hidden_effect = {
				random_dummy_gender_effect = yes
				create_artifact_book_effect = {
					OWNER = scope:host
					CREATOR = scope:dummy_gender
					SET_SUBJECT = flag:no
					SET_TOPIC = flag:no
				}
				hidden_effect_new_object = {
					scope:newly_created_artifact = {
						set_artifact_rarity = illustrious
					}
				}
				scope:activity = {
					add_to_variable_list = {
						name = artifact_rewards
						target = scope:newly_created_artifact
					}
				}
			}
		}
		else_if = {
			limit = {
				scope:activity = {
					has_activity_option = {
						category = adult_education_option_books
						option = adult_education_books_good
					}
				}
			}
			custom_tooltip = adult_education_books_good_reward
			hidden_effect = {
				save_temporary_scope_value_as = {
					name = should_be_trinket
					value = yes
				}
				random_dummy_gender_effect = yes
				save_scope_value_as = {
					name = quality
					value = 50
				}
				save_scope_value_as = {
					name = wealth
					value = 50
				}
				create_artifact_book_effect = {
					OWNER = scope:host
					CREATOR = scope:dummy_gender
					SET_SUBJECT = flag:no
					SET_TOPIC = flag:no
				}
				hidden_effect_new_object = {
					scope:newly_created_artifact = {
						set_artifact_rarity = illustrious
					}
				}
				scope:activity = {
					add_to_variable_list = {
						name = artifact_rewards
						target = scope:newly_created_artifact
					}
				}
			}
			if = {
				limit = {
					has_trait = education_diplomacy
				}
				add_diplomacy_skill = 1
			}
			else_if = {
				limit = {
					has_trait = education_martial
				}
				add_martial_skill = 1
			}
			else_if = {
				limit = {
					has_trait = education_stewardship
				}
				add_stewardship_skill = 1
			}
			else_if = {
				limit = {
					has_trait = education_intrigue
				}
				add_intrigue_skill = 1
			}
			else_if = {
				limit = {
					has_trait = education_learning
				}
				add_learning_skill = 1
			}
		}
		else_if = {
			limit = {
				scope:activity = {
					has_activity_option = {
						category = adult_education_option_books
						option = adult_education_books_normal
					}
				}
			}
			if = {
				limit = {
					has_trait = education_diplomacy
				}
				add_diplomacy_skill = 1
			}
			else_if = {
				limit = {
					has_trait = education_martial
				}
				add_martial_skill = 1
			}
			else_if = {
				limit = {
					has_trait = education_stewardship
				}
				add_stewardship_skill = 1
			}
			else_if = {
				limit = {
					has_trait = education_intrigue
				}
				add_intrigue_skill = 1
			}
			else_if = {
				limit = {
					has_trait = education_learning
				}
				add_learning_skill = 1
			}
		}
	}
	if = {
		limit = { involved_activity = { activity_has_arcane_education_type_trigger = yes } }
		if = {
			limit = {
				scope:activity = {
					has_activity_option = {
						category = adult_education_option_books
						option = adult_education_books_good
					}
				}
				has_dlc_feature = royal_court
				scope:host = { has_royal_court = yes }
			}
			custom_tooltip = adult_education_books_good_reward
			set_variable = {
				name = book_artifact_subject
				value = flag:arcana
			}
			hidden_effect = {
				random_dummy_gender_effect = yes
				create_artifact_book_effect = {
					OWNER = scope:host
					CREATOR = scope:dummy_gender
					SET_SUBJECT = flag:no
					SET_TOPIC = flag:no
				}
				hidden_effect_new_object = {
					scope:newly_created_artifact = {
						set_artifact_rarity = illustrious
					}
				}
				scope:activity = {
					add_to_variable_list = {
						name = artifact_rewards
						target = scope:newly_created_artifact
					}
				}
			}
		}
		else_if = {
			limit = {
				scope:activity = {
					has_activity_option = {
						category = adult_education_option_books
						option = adult_education_books_good
					}
				}
			}
			custom_tooltip = adult_education_books_good_reward
			set_variable = {
				name = book_artifact_subject
				value = flag:arcana
			}
			hidden_effect = {
				save_temporary_scope_value_as = {
					name = should_be_trinket
					value = yes
				}
				random_dummy_gender_effect = yes
				save_scope_value_as = {
					name = quality
					value = 50
				}
				save_scope_value_as = {
					name = wealth
					value = 50
				}
				create_artifact_book_effect = {
					OWNER = scope:host
					CREATOR = scope:dummy_gender
					SET_SUBJECT = flag:no
					SET_TOPIC = flag:no
				}
				hidden_effect_new_object = {
					scope:newly_created_artifact = {
						set_artifact_rarity = illustrious
					}
				}
				scope:activity = {
					add_to_variable_list = {
						name = artifact_rewards
						target = scope:newly_created_artifact
					}
				}
			}
			add_arcana_skill = { VALUE = 1 }
		}
		else_if = {
			limit = {
				scope:activity = {
					has_activity_option = {
						category = adult_education_option_books
						option = adult_education_books_normal
					}
				}
			}
			add_arcana_skill = { VALUE = 1 }
		}
	}	
}
# EK EDIT END

#EK ADDITION
increase_education_level_0_type_effect = {
	add_trait_force_tooltip = education_$TYPE$_1
	scope:activity = {
		add_to_variable_list = {
			name = trait_rewards
			target = trait:education_$TYPE$_1
		}
	}
}
#EK ADDITION END

increase_education_level_1_type_effect = {
	hidden_effect = { remove_trait = education_$TYPE$_1 }
	add_trait_force_tooltip = education_$TYPE$_2
	scope:activity = {
		add_to_variable_list = {
			name = trait_rewards
			target = trait:education_$TYPE$_2
		}
	}
}

increase_education_level_2_type_effect = {
	hidden_effect = { remove_trait = education_$TYPE$_2 }
	add_trait_force_tooltip = education_$TYPE$_3
	scope:activity = {
		add_to_variable_list = {
			name = trait_rewards
			target = trait:education_$TYPE$_3
		}
	}
}

increase_education_level_3_type_effect = {
	hidden_effect = { remove_trait = education_$TYPE$_3 }
	add_trait_force_tooltip = education_$TYPE$_4
	scope:activity = {
		add_to_variable_list = {
			name = trait_rewards
			target = trait:education_$TYPE$_4
		}
	}
}

increase_education_level_4_type_effect = {
	hidden_effect = { remove_trait = education_$TYPE$_4 }
	add_trait_force_tooltip = education_$TYPE$_5
	scope:activity = {
		add_to_variable_list = {
			name = trait_rewards
			target = trait:education_$TYPE$_5
		}
	}
}

increase_education_level_1_effect = {
	if = {
		limit = { has_trait = education_diplomacy }
		increase_education_level_1_type_effect = { TYPE = diplomacy }
	}
	else_if = {
		limit = { has_trait = education_martial }
		increase_education_level_1_type_effect = { TYPE = martial }
	}
	else_if = {
		limit = { has_trait = education_stewardship }
		increase_education_level_1_type_effect = { TYPE = stewardship }
	}
	else_if = {
		limit = { has_trait = education_intrigue }
		increase_education_level_1_type_effect = { TYPE = intrigue }
	}
	else_if = {
		limit = { has_trait = education_learning }
		increase_education_level_1_type_effect = { TYPE = learning }
	}
}

increase_education_level_2_effect = {
	if = {
		limit = { has_trait = education_diplomacy }
		increase_education_level_2_type_effect = { TYPE = diplomacy }
	}
	else_if = {
		limit = { has_trait = education_martial }
		increase_education_level_2_type_effect = { TYPE = martial }
	}
	else_if = {
		limit = { has_trait = education_stewardship }
		increase_education_level_2_type_effect = { TYPE = stewardship }
	}
	else_if = {
		limit = { has_trait = education_intrigue }
		increase_education_level_2_type_effect = { TYPE = intrigue }
	}
	else_if = {
		limit = { has_trait = education_learning }
		increase_education_level_2_type_effect = { TYPE = learning }
	}
}

increase_education_level_3_effect = {
	if = {
		limit = { has_trait = education_diplomacy }
		increase_education_level_3_type_effect = { TYPE = diplomacy }
	}
	else_if = {
		limit = { has_trait = education_martial }
		increase_education_level_3_type_effect = { TYPE = martial }
	}
	else_if = {
		limit = { has_trait = education_stewardship }
		increase_education_level_3_type_effect = { TYPE = stewardship }
	}
	else_if = {
		limit = { has_trait = education_intrigue }
		increase_education_level_3_type_effect = { TYPE = intrigue }
	}
	else_if = {
		limit = { has_trait = education_learning }
		increase_education_level_3_type_effect = { TYPE = learning }
	}
}

increase_education_level_4_effect = {
	if = {
		limit = { has_trait = education_diplomacy }
		increase_education_level_4_type_effect = { TYPE = diplomacy }
	}
	else_if = {
		limit = { has_trait = education_martial }
		increase_education_level_4_type_effect = { TYPE = martial }
	}
	else_if = {
		limit = { has_trait = education_stewardship }
		increase_education_level_4_type_effect = { TYPE = stewardship }
	}
	else_if = {
		limit = { has_trait = education_intrigue }
		increase_education_level_4_type_effect = { TYPE = intrigue }
	}
	else_if = {
		limit = { has_trait = education_learning }
		increase_education_level_4_type_effect = { TYPE = learning }
	}
}

bp2_lifestyle_xp_gain_per_type_effect = {
	if = {
		limit = {
			has_trait = education_diplomacy
		}
		add_diplomacy_lifestyle_xp =  $VALUE$_lifestyle_xp
	}
	else_if = {
		limit = {
			has_trait = education_martial
		}
		add_martial_lifestyle_xp =  $VALUE$_lifestyle_xp
	}
	else_if = {
		limit = {
			has_trait = education_stewardship
		}
		add_stewardship_lifestyle_xp =  $VALUE$_lifestyle_xp
	}
	else_if = {
		limit = {
			has_trait = education_intrigue
		}
		add_intrigue_lifestyle_xp =  $VALUE$_lifestyle_xp
	}
	else_if = {
		limit = {
			has_trait = education_learning
		}
		add_learning_lifestyle_xp =  $VALUE$_lifestyle_xp
	}
}

bp2_goliards_potential_shenanigans_effect = {
	custom_tooltip = goliardic_shenanigans_effect_tt
	hidden_effect = {
		random_list = {
			10 = {
				modifier = {
					has_diplomacy_lifestyle_trait_trigger = yes
					add = 5
				}
				send_interface_toast = {
					title = $TITLE_VALUE$
					left_icon = root
					add_diplomacy_skill = 1
				}	
			}
			10 = {
				modifier = {
					has_intrigue_lifestyle_trait_trigger = yes
					add = 5
				}
				send_interface_toast = {
					title = $TITLE_VALUE$
					left_icon = root
					add_intrigue_skill = 1
				}					
			}
			10 = {
				send_interface_toast = {
					title = $TITLE_VALUE$
					left_icon = root
					add_prowess_skill = 1
				}
			}	
			15 = {
				trigger = {
					is_eunuch_trigger = no
					NOR = {
						has_trait = lovers_pox
						has_trait = early_great_pox
						has_trait = great_pox
						has_trait = celibate
						has_character_flag = immune_to_disease
					}
					can_contract_disease_trigger = { DISEASE = lovers_pox }
				}
				send_interface_toast = {
					title = $TITLE_VALUE$
					left_icon = root
					contract_disease_effect = { DISEASE = lovers_pox TREATMENT_EVENT = no }
				}
			}
			15 = {
				send_interface_toast = {
					title = $TITLE_VALUE$
					left_icon = root
					increase_wounds_no_death_effect = { REASON = fight }
				}
			}
			10 = {
				trigger = {
					NOT = { has_trait = poet }
				}
				send_interface_toast = {
					title = $TITLE_VALUE$
					left_icon = root
					add_trait = poet
				}
			}
			10 = {
				send_interface_toast = {
					title = $TITLE_VALUE$
					left_icon = root
					if = {
						limit = { has_trait = lifestyle_blademaster }
						add_trait_xp = {
							trait = lifestyle_blademaster
							value = 5
						}
					}
					else = { add_trait = lifestyle_blademaster }
				}
			}
			5 = {
				trigger = {
					NOT = { has_trait = drunkard }
					drinks_alcohol_trigger = yes
				}
				send_interface_toast = {
					title = $TITLE_VALUE$
					left_icon = root
					add_trait = drunkard
				}
			}
			5 = {
				trigger = { can_be_hashishiyah = yes }
				send_interface_toast = {
					title = $TITLE_VALUE$
					left_icon = root
					add_trait = hashishiyah
				}
			}
			10 = {
				send_interface_toast = {
					title = $TITLE_VALUE$
					left_icon = root
					bp2_lifestyle_xp_gain_per_type_effect = { VALUE = medium }
				}
			}
			10 = {
				trigger = {
					has_trait = tourney_participant
				}
				add_trait_xp = {
					trait = tourney_participant
					track = wit
					value = 5
				}
			}
		}
	}
}

# Set up a University Teacher
#EK EDIT: Reworked the effect to add magic options
bp2_university_teacher_setup = {
	scope:activity.activity_location = { save_scope_as = location }
	if = {
		limit = {
			scope:activity = {
				NOT = {
					any_attending_character = {
						has_character_flag = teacher_1
					}
				}
			}
		}
		if = {
			limit = {
				any_pool_character = {
					province = scope:location
					is_available_healthy_ai_adult = yes
					OR = {
						has_character_flag = teacher_1
						has_character_flag = teacher_2
					}
				}
			}
			random_pool_character = {
				province = scope:location
				limit = {
					is_available_healthy_ai_adult = yes
					OR = {
						has_character_flag = teacher_1
						has_character_flag = teacher_2
					}
				}
				save_scope_as = teacher_1
			}
		}
		else_if = {
			limit = {
				scope:activity = { activity_has_mundane_education_type_trigger = yes } 
				any_pool_character = {
					province = scope:location
					is_available_adult_education_teacher = yes
				}
			}
			random_pool_character = {
				province = scope:location
				limit = {
					is_available_adult_education_teacher = yes
				}
				save_scope_as = teacher_1
			}
		}
		else_if = {
			limit = {
				scope:activity = { activity_has_arcane_education_type_trigger = yes } 
				any_pool_character = {
					province = scope:location
					is_available_arcane_adult_education_teacher = yes
				}
			}
			random_pool_character = {
				province = scope:location
				limit = {
					is_available_arcane_adult_education_teacher = yes
				}
				save_scope_as = teacher_1
			}
		}
		else_if = {
			limit = { scope:activity = { activity_has_mundane_education_type_trigger = yes } }
			create_character = {
				template = adult_education_teacher
				dynasty = none
				location = scope:location
				save_scope_as = teacher_1
			}
		}
		else = {
			create_character = {
				template = arcane_adult_education_teacher
				dynasty = none
				location = scope:location
				save_scope_as = teacher_1
			}
		}
		scope:teacher_1 = {
			if = {
				limit = {
					has_character_flag = teacher_2
				}
				remove_character_flag = teacher_2
			}
			if = {
				limit = {
					has_character_flag = student_1
				}
				remove_character_flag = student_1
			}
			if = {
				limit = {
					has_character_flag = student_2
				}
				remove_character_flag = student_2
			}
			add_to_activity = scope:activity
			add_character_flag = teacher_1
		}
	}
	if = {
		limit = {
			scope:activity = {
				NOT = {
					any_attending_character = {
						has_character_flag = teacher_2
					}
				}
			}
		}
		if = {
			limit = {
				any_pool_character = {
					province = scope:location
					is_available_healthy_ai_adult = yes
					OR = {
						has_character_flag = teacher_1
						has_character_flag = teacher_2
					}
					trigger_if = {
						limit = { exists = scope:teacher_1 }
						NOT = { this = scope:teacher_1 }
					}
				}
			}
			random_pool_character = {
				province = scope:location
				limit = {
					is_available_healthy_ai_adult = yes
					OR = {
						has_character_flag = teacher_1
						has_character_flag = teacher_2
					}
					trigger_if = {
						limit = { exists = scope:teacher_1 }
						NOT = { this = scope:teacher_1 }
					}
				}
				save_scope_as = teacher_2
			}
		}
		else_if = {
			limit = {
				scope:activity = { activity_has_mundane_education_type_trigger = yes } 
				any_pool_character = {
					province = scope:location
					is_available_adult_education_teacher = yes
					trigger_if = {
						limit = { exists = scope:teacher_1 }
						NOT = { this = scope:teacher_1 }
					}
				}
			}
			random_pool_character = {
				province = scope:location
				limit = {
					is_available_adult_education_teacher = yes
					trigger_if = {
						limit = { exists = scope:teacher_1 }
						NOT = { this = scope:teacher_1 }
					}
				}
				save_scope_as = teacher_2						
			}
		}
		else_if = {
			limit = {
				scope:activity = { activity_has_arcane_education_type_trigger = yes } 
				any_pool_character = {
					province = scope:location
					is_available_arcane_adult_education_teacher = yes
					trigger_if = {
						limit = { exists = scope:teacher_1 }
						NOT = { this = scope:teacher_1 }
					}
				}
			}
			random_pool_character = {
				province = scope:location
				limit = {
					is_available_arcane_adult_education_teacher = yes
					trigger_if = {
						limit = { exists = scope:teacher_1 }
						NOT = { this = scope:teacher_1 }
					}
				}
				save_scope_as = teacher_2						
			}
		}
		else_if = {	
			limit = { scope:activity = { activity_has_mundane_education_type_trigger = yes } }
			create_character = {
				template = adult_education_teacher
				dynasty = none
				location = scope:location
				save_scope_as = teacher_2
			}
		}
		else = {
			create_character = {
				template = arcane_adult_education_teacher
				dynasty = none
				location = scope:location
				save_scope_as = teacher_2
			}
		}
		scope:teacher_2 = {
			if = {
				limit = {
					has_character_flag = teacher_1
				}
				remove_character_flag = teacher_1
			}
			if = {
				limit = {
					has_character_flag = student_1
				}
				remove_character_flag = student_1
			}
			if = {
				limit = {
					has_character_flag = student_2
				}
				remove_character_flag = student_2
			}
			add_to_activity = scope:activity
			add_character_flag = teacher_2
		}
	}
}
#EK EDIT END

#EK EDIT: Reworked the effect to add magic options
# Set up a University student
bp2_university_student_setup = {
	scope:activity.activity_location = { save_scope_as = location }
	if = {
		limit = {
			NOT = {
				scope:activity = {
					any_attending_character = {
						has_character_flag = student_1
					}
				}
			}
		}
		if = {
			limit = {
				scope:activity = { activity_has_mundane_education_type_trigger = yes }
				any_pool_character = {
					province = scope:location
					is_available_healthy_ai_adult = yes
					NOT = {
						exists = involved_activity
					}
					exists = this
				}
			}
			random_pool_character = {
				province = scope:location
				limit = {
					is_available_healthy_ai_adult = yes
					NOT = {
						exists = involved_activity
					}
				}
				save_scope_as = student_1
			}
		}
		else_if = {
			limit = {
				scope:activity = { activity_has_arcane_education_type_trigger = yes }
				any_pool_character = {
					province = scope:location
					is_available_healthy_ai_adult = yes
					can_magic_trigger = yes
					NOT = {
						exists = involved_activity
					}
					exists = this
				}
			}
			random_pool_character = {
				province = scope:location
				limit = {
					is_available_healthy_ai_adult = yes
					can_magic_trigger = yes
					NOT = {
						exists = involved_activity
					}
				}
				save_scope_as = student_1
			}
		}
		else_if = {
			limit = { scope:activity = { activity_has_mundane_education_type_trigger = yes } }
			create_character = {
				template = adult_education_student
				dynasty = none
				location = scope:location
				save_scope_as = student_1
			}
			scope:student_1 = {
				add_character_flag = generated_character_uni
			}
		}
		else = {
			create_character = {
				template = arcane_adult_education_student
				dynasty = none
				location = scope:location
				save_scope_as = student_1
			}
			scope:student_1 = {
				add_character_flag = generated_character_uni
			}
		}
		scope:student_1 = {
			if = {
				limit = {
					has_character_flag = teacher_1
				}
				remove_character_flag = teacher_1
			}
			if = {
				limit = {
					has_character_flag = teacher_2
				}
				remove_character_flag = teacher_2
			}
			if = {
				limit = {
					has_character_flag = student_2
				}
				remove_character_flag = student_2
			}
			add_to_activity = scope:activity
			add_character_flag = student_1
		}
	}

	if = {
		limit = {
			NOT = {
				scope:activity = {
					any_attending_character = {
						has_character_flag = student_2
					}
				}
			}
		}
		if = {
			limit = {
				scope:activity = { activity_has_mundane_education_type_trigger = yes }
				any_pool_character = {
					province = scope:location
					is_available_healthy_ai_adult = yes
					NOT = {
						exists = involved_activity
					}
					exists = this
				}
			}
			random_pool_character = {
				province = scope:location
				limit = {
					is_available_healthy_ai_adult = yes
					NOT = {
						exists = involved_activity
					}
				}
				save_scope_as = student_2
			}
		}
		else_if = {
			limit = {
				scope:activity = { activity_has_arcane_education_type_trigger = yes }
				any_pool_character = {
					province = scope:location
					can_magic_trigger = yes
					is_available_healthy_ai_adult = yes
					NOT = {
						exists = involved_activity
					}
					exists = this
				}
			}
			random_pool_character = {
				province = scope:location
				limit = {
					can_magic_trigger = yes
					is_available_healthy_ai_adult = yes
					NOT = {
						exists = involved_activity
					}
				}
				save_scope_as = student_2
			}
		}
		else_if = {
			limit = { scope:activity = { activity_has_mundane_education_type_trigger = yes } }
			create_character = {
				template = adult_education_student
				dynasty = none
				location = scope:location
				save_scope_as = student_2
			}
			scope:student_2 = {
				add_character_flag = generated_character_uni
			}
		}
		else = {
			create_character = {
				template = arcane_adult_education_student
				dynasty = none
				location = scope:location
				save_scope_as = student_2
			}
			scope:student_2 = {
				add_character_flag = generated_character_uni
			}
		}
		scope:student_2 = {
			if = {
				limit = {
					has_character_flag = teacher_1
				}
				remove_character_flag = teacher_1
			}
			if = {
				limit = {
					has_character_flag = teacher_2
				}
				remove_character_flag = teacher_2
			}
			if = {
				limit = {
					has_character_flag = student_1
				}
				remove_character_flag = student_1
			}
			add_to_activity = scope:activity
			add_character_flag = student_2
		}
	}
}
#EK EDIT END

# Adoption effect
adopt_effect = {
	$ADOPTER$ = {
		adopt = $CHILD$
		$CHILD$ = {
			set_house = $ADOPTER$.house
			# Remove bastard traits
			if = {
				limit = {
					has_any_bastard_trait_trigger = yes
				}
				remove_all_bastard_traits = yes
			}
		}
		# Parochial vassals hate this
		if = {
			limit = {
				NOR = {
					has_game_rule = adoption_always_allowed
					culture = { has_cultural_parameter = allows_adoption }
				}
			}
			every_vassal = {
				custom = every_courtly_vassal_actor
				limit = {
					has_vassal_stance = courtly
				}
				add_opinion = {
					modifier = angry_opinion
					opinion = -20
					target = $ADOPTER$
				}
			}
		}
		# Zealous vassals *hate* you adopting a heretic
		if = {
			limit = {
				faith = {
					faith_hostility_level = {
						target = $CHILD$.faith
						value >= faith_evil_level
					}
				}
			}
			every_vassal = {
				custom = every_zealot_vassal_actor
				limit = {
					has_vassal_stance = zealot
				}
				add_opinion = {
					modifier = angry_opinion
					opinion = -25
					target = $ADOPTER$
				}
			}
		}
		else_if = {
			limit = {
				faith = {
					faith_hostility_level = {
						target = $CHILD$.faith
						value >= faith_hostile_level
					}
				}
			}
			every_vassal = {
				custom = every_zealot_vassal_actor
				limit = {
					has_vassal_stance = zealot
				}
				add_opinion = {
					modifier = angry_opinion
					opinion = -20
					target = $ADOPTER$
				}
			}
		}
		else_if = {
			limit = {
				faith = {
					faith_hostility_level = {
						target = $CHILD$.faith
						value >= faith_astray_level
					}
				}
			}
			every_vassal = {
				custom = every_zealot_vassal_actor
				limit = {
					has_vassal_stance = zealot
				}
				add_opinion = {
					modifier = angry_opinion
					opinion = -10
					target = $ADOPTER$
				}
			}
		}
		# Minority vassals *love* you adopting a foreigner
		if = {
			limit = {
				OR = {
					faith = {
						faith_hostility_level = {
							target = $CHILD$.faith
							value >= faith_astray_level
						}
					}
					NOT = { culture = $CHILD$.culture }
				}
			}
			every_vassal = {
				custom = every_minority_vassal_actor
				limit = {
					has_vassal_stance = minority
				}
				add_opinion = {
					modifier = respect_opinion
					opinion = 25
					target = $ADOPTER$
				}
			}
		}
		# Your other children hate this
		every_child = {
			custom = every_non_content_child
			add_opinion = {
				modifier = angry_opinion
				opinion = -20
				target = $ADOPTER$
			}
		}
		# Player heirs *hate* you adopting someone to be your new heir
		if = {
			limit = {
				exists = player_heir
				OR = {
					player_heir.age < $CHILD$.age
					player_heir = { has_trait = ambitious }
				}
				NOT = {
					player_heir = { has_trait = humble }
					player_heir = { has_trait = content }
					player_heir = { has_trait = forgiving }
				}
			}
			player_heir = {
				progress_towards_rival_effect = {
					CHARACTER = $ADOPTER$
					REASON = rival_adopted_another_heir
					OPINION = default_rival_opinion
				}
				set_relation_rival = {
					target = $CHILD$
					reason = rival_stole_my_throne
				}
			}
		}
	}
	#adopted child should travel to new parent
	$CHILD$ = {
		if = {
			limit = { exists = $ADOPTER$.capital_province } # Ward heads to landed Guardian
			$ADOPTER$.capital_province = { save_scope_as = destination_province }
		}
		else_if = { # Ward heads to Guardian's host
			limit = { exists = $ADOPTER$.host.capital_province }
			$ADOPTER$.host.capital_province = { save_scope_as = destination_province }
		}
		else = {
			$ADOPTER$.location = { save_scope_as = destination_province }
		}
		save_scope_as = adoptee
		$ADOPTER$ = {
			save_scope_as = adopter
		}
		if = {
			limit = {
				any_relation = {
					type = guardian
					NOT = { this = $ADOPTER$ }
				}
			}
			random_relation = {
				type = guardian
				limit = { NOT = { this = $ADOPTER$ } }
				save_scope_as = old_guardian
			}
			remove_guardian_effect = {
				GUARDIAN = scope:old_guardian
				WARD = scope:adoptee
				RETURN_WARD = no
				HIDE_OPINION = no
			}
		}
		if = {
			limit = { NOT = { scope:destination_province = $CHILD$.location } }
			set_variable = {
				name = adoptee_travelling_to_adopter
				years = 2
				value = scope:adopter
			}
			start_travel_plan = {
				destination = scope:destination_province
				on_start_on_action = on_adoptee_depart_for_adopter
				on_travel_planner_cancel_on_action = on_adoptee_depart_travel_planner_exit
				on_arrival_on_action = on_adoptee_arrive_at_adopter
				on_arrival_destinations = last
				return_trip = no # One way
			}
			custom_tooltip = adoptee_leaves_for_adopter_tt
		}
		if = {
			limit = {
				$ADOPTER$ = {
					has_blood_brother = yes
					any_relation = {
						type = blood_brother
						NOT = {
							is_close_family_of = $CHILD$
						}
					}
				}
			}
			$ADOPTER$ = {
				random_relation = {
					type = blood_brother
					save_scope_as = other_blood_brother
				}
			}
			mpo_blood_brother_new_family_member_opinion_effect = yes
		}
	}
}

# Adventurer Adoption effect
adventurer_adopt_effect = {
	$ADOPTER$ = {
		hidden_effect = { adopt = $CHILD$ }
		$CHILD$ = {
			hidden_effect = {
				set_house = $ADOPTER$.house
				found_cadet_house_decision_effect = {
					CHARACTER = scope:recipient
					PRESTIGE = 0
				}
			}
			custom_tooltip = adventurer_adoption_child_tt
			# Remove bastard traits
			if = {
				limit = {
					has_any_bastard_trait_trigger = yes
				}
				remove_all_bastard_traits = yes
			}
			# Remove disinherited if you're the house head.
			if = {
				limit = {
					$ADOPTER$.house.house_head = $ADOPTER$
					has_trait = disinherited
				}
				remove_trait = disinherited
			}
		}
		# Your other children hate this
		every_child = {
			custom = every_non_content_child
			add_opinion = {
				modifier = angry_opinion
				opinion = -20
				target = $ADOPTER$
			}
		}
		# Player heirs *hate* you adopting someone to be your new heir
		if = {
			limit = {
				exists = player_heir
				OR = {
					player_heir.age < $CHILD$.age
					player_heir = { has_trait = ambitious }
				}
				NOR = {
					player_heir = { has_trait = humble }
					player_heir = { has_trait = content }
					player_heir = { has_trait = forgiving }
				}
			}
			player_heir = {
				progress_towards_rival_effect = {
					CHARACTER = $ADOPTER$
					REASON = rival_adopted_another_heir
					OPINION = default_rival_opinion
				}
				set_relation_rival = {
					target = $CHILD$
					reason = rival_stole_my_throne
				}
			}
		}
	}
	#adopted child should travel to new parent
	$CHILD$ = {
		if = {
			limit = { exists = $ADOPTER$.capital_province } # Ward heads to landed Guardian
			$ADOPTER$.capital_province = { save_scope_as = destination_province }
		}
		else_if = { # Ward heads to Guardian's host
			limit = { exists = $ADOPTER$.host.capital_province }
			$ADOPTER$.host.capital_province = { save_scope_as = destination_province }
		}
		else = {
			$ADOPTER$.location = { save_scope_as = destination_province }
		}
		save_scope_as = adoptee
		$ADOPTER$ = {
			save_scope_as = adopter
		}
		if = {
			limit = {
				any_relation = {
					type = guardian
					NOT = { this = $ADOPTER$ }
				}
			}
			random_relation = {
				type = guardian
				limit = { NOT = { this = $ADOPTER$ } }
				save_scope_as = old_guardian
			}
			remove_guardian_effect = {
				GUARDIAN = scope:old_guardian
				WARD = scope:adoptee
				RETURN_WARD = no
				HIDE_OPINION = no
			}
		}
		if = {
			limit = { NOT = { scope:destination_province = $CHILD$.location } }
			set_variable = {
				name = adoptee_travelling_to_adopter
				years = 2
				value = scope:adopter
			}
			start_travel_plan = {
				destination = scope:destination_province
				on_start_on_action = on_adoptee_depart_for_adopter
				on_travel_planner_cancel_on_action = on_adoptee_depart_travel_planner_exit
				on_arrival_on_action = on_adoptee_arrive_at_adopter
				on_arrival_destinations = last
				return_trip = no # One way
			}
			custom_tooltip = adoptee_leaves_for_adopter_tt
		}
		#Enters into blood brotherhood family bond
		if = {
			limit = {
				$ADOPTER$ = {
					has_blood_brother = yes
					any_relation = {
						type = blood_brother
						NOT = {
							is_close_family_of = $CHILD$
						}
					}
				}
			}
			$ADOPTER$ = {
				random_relation = {
					type = blood_brother
					save_scope_as = other_blood_brother
				}
			}
			mpo_blood_brother_new_family_member_opinion_effect = yes
		}
	}
}
