﻿namespace = emperor_imperial_examination

# A top candidate becomes pro-Hegemon
emperor_imperial_examination.100 = {
	type = activity_event
	title = emperor_imperial_examination.100.t
	desc = emperor_imperial_examination.100.desc
	theme = imperial_examination
	override_background = { reference = throne_room }
	left_portrait = {
		character = root
		animation = emperor
		camera = camera_event_crowd
	}
	center_portrait = {
		character = scope:examination_character_2
		animation = gongshou
		camera = camera_event_right
	}
	right_portrait = {
		character = scope:examination_character_1
		animation = gongshou
	}
	cooldown = { years = 1 }
	trigger = {
		this = scope:host
		scope:activity = {
			any_guest_subset = {
				name = palace_entrants
				is_physically_able_ai_adult = yes
				NOR = {
					has_trait = ambitious
					has_trait = arrogant
					is_consort_of = scope:host
					is_close_family_of = scope:host
					house ?= scope:host.house
					has_relation_rival = scope:host
				}
				top_participant_group:dynastic_cycle ?= {
					NOT = {
						participant_group_type = pro_hegemon_movement
					}
				}
			}
		}
	}
	immediate = {
		scope:activity = {
			random_guest_subset = {
				name = palace_entrants
				limit = {
					is_physically_able_ai_adult = yes
					NOR = {
						has_trait = ambitious
						has_trait = arrogant
						is_consort_of = scope:host
						is_close_family_of = scope:host
						house ?= scope:host.house
						has_relation_rival = scope:host
					}
					top_participant_group:dynastic_cycle ?= {
						NOT = {
							participant_group_type = pro_hegemon_movement
						}
					}
				}
				weight = {
					base = 1
					modifier = {
						add = 1000
						has_personality_submissive_trigger = yes
					}
					modifier = {
						add = 100
						has_trait_submissive_trigger = yes
					}
				}
				save_scope_as = examination_character_2
			}
		}
	}
	
	option = {
		name = emperor_imperial_examination.100.a
		scope:examination_character_2 = {
			if = {
				limit = {
					has_trait = disloyal
				}
				remove_trait = disloyal
			}
			else = {
				add_trait = loyal
			}
			change_merit = 5000
			custom_tooltip = celestial_switch_movement_to_pro_hegemon_tt
			every_relation = {
				type = disciple
				custom = every_disciple_joins_movement
				custom_tooltip = celestial_switch_movement_to_pro_hegemon_tt
				set_variable = {
					name = movement_member
					value = flag:undecided
				}
			}
			set_variable = {
				name = movement_member
				value = flag:pro_hegemon
			}
			hidden_effect = {
				recalculate_participant_group = situation:dynastic_cycle
			}
		}
	}
	
	option = {
		name = emperor_imperial_examination.100.b
		add_legitimacy = minor_legitimacy_gain
		scope:examination_character_2 = {
			add_stress = medium_stress_gain
			custom_tooltip = imperial_examination.advantage.other.tt
			imperial_examination_adjust_advantage_variable_effect = yes
		}
	}
}

# You are offered a beautiful concubine
emperor_imperial_examination.200 = {
	type = activity_event
	title = emperor_imperial_examination.200.t
	desc = emperor_imperial_examination.200.desc
	theme = imperial_examination
	override_background = { reference = throne_room }
	left_portrait = {
		character = root
		animation = emperor
		camera = camera_event_crowd
	}
	center_portrait = {
		character = scope:examination_character_2
		animation = gongshou
		camera = camera_event_right
	}
	right_portrait = {
		character = scope:examination_character_1
		animation = fanning_coyly
	}
	cooldown = { years = 1 }
	trigger = {
		this = scope:host
		allowed_concubines = yes
		allowed_more_concubines = yes
		is_adult = yes
		scope:activity = {
			any_guest_subset = {
				name = palace_entrants
				is_physically_able_ai_adult = yes
				NOR = {
					is_consort_of = scope:host
					is_close_family_of = scope:host
					house ?= scope:host.house
					has_relation_rival = scope:host
				}
			}
		}
		any_realm_border_county = {
			culture != scope:host.culture
		}
	}
	immediate = {
		scope:activity = {
			random_guest_subset = {
				name = palace_entrants
				limit = {
					is_physically_able_ai_adult = yes
					NOR = {
						is_consort_of = scope:host
						is_close_family_of = scope:host
						house ?= scope:host.house
						has_relation_rival = scope:host
					}
				}
				save_scope_as = examination_character_2
			}
		}
		random_realm_border_county = {
			limit = {
				culture != scope:host.culture
			}
			save_scope_as = concubine_origin
		}
		create_character = {
			template = tgp_concubine_template
			location = scope:host.location
			culture = scope:concubine_origin.culture
			faith = scope:concubine_origin.faith
			dynasty = generate
			save_scope_as = examination_character_1
			after_creation = {
				random_list = {
					200 = {
						# Character is of average weight, nothing happens	
					}
					25 = {
						change_current_weight = -25
					}
					25 = {
						change_current_weight = 25
					}
					25 = {
						change_current_weight = 75
					}
					5 = {
						change_current_weight = 100
					}
				}
			}
		}
	}
	
	option = {
		name = emperor_imperial_examination.200.a
		add_legitimacy = minor_legitimacy_gain
		make_concubine = scope:examination_character_1
		reverse_add_opinion = {
			target = scope:examination_character_1
			modifier = honored_opinion
			opinion = 50
		}
		reverse_add_opinion = {
			target = scope:examination_character_2
			modifier = honored_opinion
			opinion = 50
		}
		scope:examination_character_2 = {
			change_merit = 3000
		}
		stress_impact = {
			lustful = medium_stress_impact_loss
		}

		ai_chance = {
			base = 100
			modifier = {
				has_trait = chaste
				factor = 0
			}
		}
	}
	
	option = {
		name = emperor_imperial_examination.200.b
		scope:examination_character_2 = {
			change_merit = 3000
		}
		reverse_add_opinion = {
			target = scope:examination_character_2
			modifier = honored_opinion
			opinion = 50
		}
		if = {
			limit = {
				has_bp3_dlc_trigger = yes
			}
			add_wanderer_lifestyle_xp = massive_lifestyle_xp
		}
		else = {
			add_learning_lifestyle_xp = massive_lifestyle_xp
		}
		stress_impact = {
			base = medium_stress_impact_loss
			chaste = medium_stress_impact_loss
		}

		ai_chance = {
			base = 100
			modifier = {
				has_trait = lustful
				factor = 0
			}
		}
	}
	
	option = {
		name = emperor_imperial_examination.200.c
		add_legitimacy = minor_legitimacy_gain
		scope:examination_character_2 = {
			change_merit_level = -1
			add_stress = massive_stress_impact_gain
		}
		stress_impact = {
			sadistic = massive_stress_impact_loss
			callous = massive_stress_impact_loss
			paranoid = medium_stress_impact_loss
			arrogant = medium_stress_impact_loss
			irritable = medium_stress_impact_loss
		}

		ai_chance = {
			base = 0
			modifier = {
				OR = {
					has_trait = sadistic
					has_trait = callous
					has_trait = paranoid
				}
				add = 100
			}
		}
	}
	
	after = {
		scope:examination_character_1 = {
			silent_disappear_ai_if_not_hired = yes
		}
	}
}

# You are offered an artifact
emperor_imperial_examination.300 = {
	type = activity_event
	title = emperor_imperial_examination.300.t
	desc = emperor_imperial_examination.300.desc
	theme = imperial_examination
	override_background = { reference = throne_room }
	left_portrait = {
		character = root
		animation = emperor
		camera = camera_event_left_away_3_4
	}
	center_portrait = {
		character = scope:examination_character_2
		animation = prostration
		camera = shop_camera_main_angle_330
	}
	artifact = {
		target = scope:newly_created_artifact
		position = lower_right_portrait
	}
	cooldown = { years = 1 }
	trigger = {
		this = scope:host
		scope:activity = {
			any_guest_subset = {
				name = palace_entrants
				is_physically_able_ai_adult = yes
				NOR = {
					has_trait = greedy
					is_consort_of = scope:host
					is_close_family_of = scope:host
					house ?= scope:host.house
				}
			}
		}
	}
	immediate = {
		scope:activity = {
			random_guest_subset = {
				name = palace_entrants
				limit = {
					is_physically_able_ai_adult = yes
					NOR = {
						has_trait = greedy
						is_consort_of = scope:host
						is_close_family_of = scope:host
						house ?= scope:host.house
					}
				}
				weight = {
					base = 1
					modifier = {
						add = 1000
						any_character_artifact = {
							OR = {
								rarity = masterwork
								rarity = famed
								rarity = illustrious
							}
							NOR = {
								has_variable = 1025_treasure_map
								has_variable = ungiftable
								exists = scope:target.var:banner_house
								exists = scope:target.var:banner_dynasty
							}
						}
					}
				}
				save_scope_as = examination_character_2
			}
		}
		scope:examination_character_2 = {
			if = {
				limit = {
					any_character_artifact = {
						OR = {
							rarity = masterwork
							rarity = famed
							rarity = illustrious
						}
						NOR = {
							has_variable = 1025_treasure_map
							has_variable = ungiftable
							exists = scope:target.var:banner_house
							exists = scope:target.var:banner_dynasty
						}
					}
				}
				random_character_artifact = {
					limit = {
						OR = {
							rarity = masterwork
							rarity = famed
							rarity = illustrious
						}
						NOR = {
							has_variable = 1025_treasure_map
							has_variable = ungiftable
							exists = scope:target.var:banner_house
							exists = scope:target.var:banner_dynasty
						}
					}
					save_scope_as = newly_created_artifact
				}
			}
			else = {
				random_list = {
					10 = {
						trigger = {
							root = { has_royal_court = yes }
						}
						create_artifact_urn_effect = {
							OWNER = scope:examination_character_2
							POTTER = scope:examination_character_2
						}
					}
					10 = {
						trigger = {
							root = { has_royal_court = yes }
						}
						create_artifact_chest_effect = {
							OWNER = scope:examination_character_2
							CARPENTER = scope:examination_character_2
						}
					}
					10 = {
						trigger = {
							root = { has_royal_court = yes }
						}
						create_artifact_wall_narwhal_horn_effect = {
							OWNER = scope:examination_character_2
							HUNTER = scope:examination_character_2
						}
					}
					10 = {
						trigger = {
							root = { has_royal_court = yes }
						}
						create_artifact_book_effect = {
							OWNER = scope:examination_character_2
							CREATOR = scope:examination_character_2
							SET_SUBJECT = flag:no
							SET_TOPIC = flag:no
						}
					}
					10 = {
						create_artifact_brooch_effect = {
							OWNER = scope:examination_character_2
							SMITH = scope:examination_character_2
						}
					}
					10 = {
						create_artifact_necklace_effect = {
							OWNER = scope:examination_character_2
							SMITH = scope:examination_character_2
						}
					}
				}
			}
		}
	}
	
	option = {
		name = emperor_imperial_examination.300.a
		scope:newly_created_artifact = {
			set_owner = root
		}
		reverse_add_opinion = {
			target = scope:examination_character_2
			modifier = honored_opinion
			opinion = 50
		}
		scope:examination_character_2 = {
			change_merit = 3000
		}

		ai_chance = {
			base = 100
		}
	}
	
	option = {
		name = emperor_imperial_examination.300.b
		destroy_artifact = scope:newly_created_artifact
		add_dread = major_dread_gain
		scope:examination_character_2 = {
			change_merit_level = -1
			add_stress = massive_stress_impact_gain
		}
		stress_impact = {
			sadistic = massive_stress_impact_loss
			callous = massive_stress_impact_loss
		}

		ai_chance = {
			base = 0
			modifier = {
				OR = {
					has_trait = sadistic
					has_trait = callous
					has_trait = greedy
				}
				add = 100
			}
		}
	}
	
	option = {
		name = emperor_imperial_examination.300.c
		add_legitimacy = minor_legitimacy_gain
		scope:examination_character_2 = {
			add_stress = medium_stress_gain
			custom_tooltip = imperial_examination.advantage.other.tt
			imperial_examination_adjust_advantage_variable_effect = yes
		}
		stress_impact = {
			greedy = medium_stress_gain
		}

		ai_chance = {
			base = 100
			modifier = {
				has_trait = greedy
				factor = 0
			}
		}
	}
}

# Reciting the Annals
emperor_imperial_examination.400 = {
	type = activity_event
	title = emperor_imperial_examination.400.t
	desc = emperor_imperial_examination.400.desc
	theme = imperial_examination
	override_background = { reference = throne_room }
	left_portrait = {
		character = root
		animation = chancellor
		camera = camera_event_crowd
	}
	center_portrait = {
		character = scope:examination_character_2
		animation = pondering
		camera = camera_event_right
	}
	right_portrait = {
		character = scope:examination_character_1
		animation = holding_scrolls
	}
	cooldown = { years = 1 }
	trigger = {
		this = scope:host
		scope:activity = {
			any_guest_subset = {
				name = imperial_examiners
				is_physically_able_ai_adult = yes
				NOR = {
					is_consort_of = scope:host
					is_close_family_of = scope:host
					house ?= scope:host.house
				}
			}
			any_guest_subset = {
				name = palace_entrants
				is_physically_able_ai_adult = yes
				NOR = {
					is_consort_of = scope:host
					is_close_family_of = scope:host
					house ?= scope:host.house
				}
			}
		}
	}
	immediate = {
		scope:activity = {
			random_guest_subset = {
				name = imperial_examiners
				limit = {
					is_physically_able_ai_adult = yes
					NOR = {
						is_consort_of = scope:host
						is_close_family_of = scope:host
						house ?= scope:host.house
					}
				}
				save_scope_as = examination_character_1
			}
			random_guest_subset = {
				name = palace_entrants
				limit = {
					is_physically_able_ai_adult = yes
					NOR = {
						is_consort_of = scope:host
						is_close_family_of = scope:host
						house ?= scope:host.house
					}
				}
				save_scope_as = examination_character_2
			}
		}
	}
	
	option = {
		name = emperor_imperial_examination.400.a
		dynasty = { add_dynasty_prestige = minor_dynasty_prestige_gain }
		add_prestige = major_prestige_gain
	}
	
	option = {
		name = emperor_imperial_examination.400.b
		add_legitimacy = minor_legitimacy_gain
		scope:activity = {
			every_guest_subset = {
				name = palace_entrants
				custom = every_palace_entrant
				change_merit = major_merit_gain
				add_learning_lifestyle_xp = major_lifestyle_xp
				add_opinion = {
					target = scope:host
					modifier = honored_opinion
					opinion = 25
				}
			}
		}
	}
	
	option = {
		name = emperor_imperial_examination.400.c
		add_legitimacy = minor_legitimacy_gain
		scope:activity = {
			every_guest_subset = {
				name = imperial_examiners
				custom = custom_every_examiner
				change_merit = major_merit_gain
				add_prestige = major_prestige_gain
				add_opinion = {
					target = scope:host
					modifier = honored_opinion
					opinion = 25
				}
			}
		}
	}
}

# The poetry of X
emperor_imperial_examination.500 = {
	type = activity_event
	title = emperor_imperial_examination.500.t
	desc = emperor_imperial_examination.500.desc
	theme = imperial_examination
	override_background = { reference = throne_room }
	left_portrait = {
		character = root
		animation = emperor
		camera = camera_event_very_left
	}
	center_portrait = {
		character = scope:examination_character_2
		animation = page_flipping
		camera = camera_event_very_right_far
	}
	cooldown = { years = 1 }
	trigger = {
		this = scope:host
		scope:activity = {
			any_guest_subset = {
				name = palace_entrants
				is_physically_able_ai_adult = yes
				ai_sociability >= 25
				NOR = {
					is_consort_of = scope:host
					is_close_family_of = scope:host
					house ?= scope:host.house
				}
			}
		}
	}
	immediate = {
		scope:activity = {
			random_guest_subset = {
				name = palace_entrants
				limit = {
					is_physically_able_ai_adult = yes
					ai_sociability >= 25
					NOR = {
						is_consort_of = scope:host
						is_close_family_of = scope:host
						house ?= scope:host.house
					}
				}
				save_scope_as = examination_character_2
				select_poem_subject_gender_effect = {
					SUBJECT = flag:specific
					SUBJECT_TARGET = root
				}
				select_poem_theme_legacy_effect = yes
			}
		}
		random_realm_county = {
			save_scope_as = poetry_county
			title_province = {
				save_scope_as = poetry_province
			}
		}
	}
	
	option = {
		name = emperor_imperial_examination.500.a
		reverse_add_opinion = {
			target = scope:examination_character_2
			modifier = honored_opinion
			opinion = 50
		}
		scope:examination_character_2 = {
			change_merit = 3000
			if = {
				limit = {
					has_trait = lifestyle_poet
				}
				add_trait_xp = {
					trait = lifestyle_poet
					value = 25
				}
			}
			else = {
				add_trait = lifestyle_poet
			}
		}
		if = {
			limit = {
				has_trait = lifestyle_poet
			}
			add_trait_xp = {
				trait = lifestyle_poet
				value = 10
			}
		}
		else = {
			add_trait = lifestyle_poet
		}

		ai_chance = {
			base = 100
		}
	}
	
	option = {
		name = emperor_imperial_examination.500.b
		add_legitimacy = minor_legitimacy_gain
		scope:examination_character_2 = {
			change_merit_level = -1
			add_stress = massive_stress_impact_gain
			if = {
				limit = {
					has_trait = lifestyle_poet
				}
				remove_trait = lifestyle_poet
			}
		}
		stress_impact = {
			sadistic = massive_stress_impact_loss
			compassionate = medium_stress_gain
		}

		ai_chance = {
			base = 0
			modifier = {
				has_trait = sadistic
				add = 100
			}
		}
	}
}

# In good Humor
emperor_imperial_examination.600 = {
	type = activity_event
	title = emperor_imperial_examination.600.t
	desc = emperor_imperial_examination.600.desc
	theme = imperial_examination
	override_background = { reference = feast }
	left_portrait = {
		character = root
		animation = disappointed
		camera = camera_event_center_pointing_right
	}
	
	right_portrait = {
		character = scope:examination_character_2
		animation = shock
		camera = camera_event_right_pointing_left
	}
	cooldown = { years = 1 }
	trigger = {
		this = scope:host
		scope:activity = {
			any_guest_subset = {
				name = palace_entrants
				is_physically_able_ai_adult = yes
				ai_sociability >= 25
				ai_honor <= 0
				NOR = {
					is_consort_of = scope:host
					is_close_family_of = scope:host
					house ?= scope:host.house
				}
			}
		}
	}
	immediate = {
		scope:activity = {
			random_guest_subset = {
				name = palace_entrants
				limit = {
					is_physically_able_ai_adult = yes
					ai_sociability >= 25
					ai_honor <= 0
					NOR = {
						is_consort_of = scope:host
						is_close_family_of = scope:host
						house ?= scope:host.house
					}
				}
				save_scope_as = examination_character_2
			}
		}
	}
	
	option = {
		name = emperor_imperial_examination.600.a
		add_prestige = medium_prestige_gain
		add_stress = major_stress_impact_loss
		scope:examination_character_2 = {
			add_stress = massive_stress_impact_loss
		}
		scope:activity = {
			every_guest_subset = {
				name = palace_entrants
				custom = every_palace_entrant
				add_opinion = {
					target = scope:host
					modifier = relieved_opinion
					opinion = 25
				}
			}
		}

		ai_chance = {
			base = 100
			modifier = {
				OR = {
					has_trait = arrogant
					has_trait = sadistic
				}
				factor = 0
			}
		}
	}
	
	option = {
		name = emperor_imperial_examination.600.b
		
		add_legitimacy = minor_legitimacy_gain
		scope:examination_character_2 = {
			add_prestige = medium_prestige_loss
			add_stress = medium_stress_gain
			custom_tooltip = imperial_examination.advantage.other.tt
			imperial_examination_adjust_advantage_variable_effect = yes
		}

		ai_chance = {
			base = 100
			modifier = {
				OR = {
					has_trait = compassionate
					has_trait = forgiving
				}
				factor = 0
			}
		}
	}
	
	option = {
		name = emperor_imperial_examination.600.c
		add_dread = major_dread_gain
		add_legitimacy = minor_legitimacy_gain
		
		scope:examination_character_2 = {
			change_merit_level = -2
			add_stress = massive_stress_impact_gain
			remove_from_activity = involved_activity
			examination_clear_timeout_effect = yes
		}

		ai_chance = {
			base = 0
		}
	}
}

# Silver Gift
emperor_imperial_examination.700 = {
	type = activity_event
	title = emperor_imperial_examination.700.t
	desc = emperor_imperial_examination.700.desc
	theme = imperial_examination
	override_background = { reference = throne_room }
	left_portrait = {
		character = root
		animation = emperor
		camera = camera_event_left_away_3_4
	}
	center_portrait = {
		character = scope:examination_character_2
		animation = prostration
		camera = shop_camera_main_angle_330
	}
	cooldown = { years = 1 }
	trigger = {
		this = scope:host
		scope:activity = {
			any_guest_subset = {
				name = palace_entrants
				is_physically_able_ai_adult = yes
				exists = house
				gold >= 10
				NOR = {
					is_consort_of = scope:host
					is_close_family_of = scope:host
					house ?= scope:host.house
				}
			}
		}
		OR = {
			title:c_bamian.holder.top_liege != scope:host
			title:c_tsushima.holder.top_liege != scope:host
			title:c_chalkidike.holder.top_liege != scope:host
		}
	}
	immediate = {
		scope:activity = {
			random_guest_subset = {
				name = palace_entrants
				limit = {
					is_physically_able_ai_adult = yes
					exists = house
					gold >= 10
					NOR = {
						is_consort_of = scope:host
						is_close_family_of = scope:host
						house ?= scope:host.house
					}
				}
				save_scope_as = examination_character_2
				hidden_effect = {
					if = {
						limit = {
							gold < 100
						}
						add_gold = 100
					}
				}
			}
		}
		random_list = {
			10 = {
				trigger = {
					title:c_bamian.holder.top_liege != scope:host
				}
				title:c_bamian = { save_scope_as = silver_county }
			}
			10 = {
				trigger = {
					title:c_tsushima.holder.top_liege != scope:host
				}
				title:c_tsushima = { save_scope_as = silver_county }
			}
			10 = {
				trigger = {
					title:c_chalkidike.holder.top_liege != scope:host
				}
				title:c_chalkidike = { save_scope_as = silver_county }
			}
		}
		scope:silver_county.holder.top_liege = { save_scope_as = silver_county_top_liege }
	}
	
	option = {
		name = emperor_imperial_examination.700.a
		add_legitimacy = minor_legitimacy_gain
		scope:examination_character_2 = {
			change_merit = 2000
			pay_short_term_gold = {
				target = scope:host
				gold = {
					value = scope:examination_character_2.gold
					divide = 2
					min = 10
					max = 1000
				}
			}
		}
	}
	
	option = {
		name = emperor_imperial_examination.700.b
		add_stewardship_lifestyle_xp = 500
		scope:examination_character_2 = {
			change_merit = 3000
			pay_short_term_gold = {
				target = scope:host
				gold = {
					value = scope:examination_character_2.gold
					divide = 2
					min = 10
					max = 1000
				}
			}
			add_opinion = {
				target = scope:host
				modifier = honored_opinion
				opinion = 50
			}
		}

		ai_chance = {
			base = 0
		}
	}
	
	option = {
		name = emperor_imperial_examination.700.c
		add_prestige = medium_prestige_gain
		scope:examination_character_2 = {
			remove_short_term_gold = {
				gold = {
					value = scope:examination_character_2.gold
					divide = 2
					min = 10
					max = 1000
				}
			}
		}
		scope:activity = {
			every_guest_subset = {
				name = palace_entrants
				custom = every_palace_entrant
				add_opinion = {
					target = scope:host
					modifier = honored_opinion
					opinion = 25
				}
				change_merit = 250
				custom_tooltip = imperial_examination.advantage.other.tt
				imperial_examination_adjust_advantage_variable_effect = yes
			}
		}
		stress_impact = {
			greedy = medium_stress_gain
		}

		ai_chance = {
			base = 0
		}
	}
}

# A Tribute Eunuch
emperor_imperial_examination.800 = {
	type = activity_event
	title = emperor_imperial_examination.800.t
	desc = emperor_imperial_examination.800.desc
	theme = imperial_examination
	override_background = { reference = feast }
	left_portrait = {
		character = root
		animation = emperor
		camera = camera_event_crowd
	}
	center_portrait = {
		character = scope:examination_character_2
		animation = gongshou
		camera = camera_event_right
	}
	right_portrait = {
		character = scope:examination_character_1
		animation = spymaster
	}
	cooldown = { years = 1 }
	trigger = {
		this = scope:host
		scope:activity = {
			any_guest_subset = {
				name = palace_entrants
				is_physically_able_ai_adult = yes
				NOR = {
					is_consort_of = scope:host
					is_close_family_of = scope:host
					house ?= scope:host.house
				}
			}
		}
	}
	immediate = {
		random_realm_county = {
			save_scope_as = eunuch_county
			title_province = {
				save_scope_as = eunuch_province
			}
		}
		scope:activity = {
			random_guest_subset = {
				name = palace_entrants
				limit = {
					is_physically_able_ai_adult = yes
					NOR = {
						is_consort_of = scope:host
						is_close_family_of = scope:host
						house ?= scope:host.house
					}
				}
				save_scope_as = examination_character_2
			}
		}
		create_character = {
			template = very_good_eunuch_character
			location = scope:host.location
			culture = scope:eunuch_county.culture
			faith = scope:eunuch_county.faith
			dynasty = none
			save_scope_as = examination_character_1
		}
	}
	
	option = {
		name = emperor_imperial_examination.800.a
		add_courtier = scope:examination_character_1
		add_legitimacy = minor_legitimacy_gain
		reverse_add_opinion = {
			target = scope:examination_character_1
			modifier = honored_opinion
			opinion = 50
		}
		reverse_add_opinion = {
			target = scope:examination_character_2
			modifier = honored_opinion
			opinion = 50
		}
		scope:examination_character_2 = {
			change_merit = 3000
		}
	}
	
	option = {
		name = emperor_imperial_examination.800.b
		add_legitimacy = minor_legitimacy_gain
		add_courtier = scope:examination_character_1
		scope:examination_character_2 = {
			custom_tooltip = imperial_examination.advantage.other.tt
			imperial_examination_adjust_advantage_variable_effect = yes
			change_merit = 3000
		}
		scope:examination_character_1 = {
			add_to_activity = scope:activity
			add_character_flag = imperial_examiner
			change_merit = 500
			custom_tooltip = becomes_imperial_examiner.tt
		}
		scope:activity = {
			add_to_variable_list = {
				name = imperial_examiners_list
				target = scope:examination_character_1
			}
			add_to_guest_subset = {
				name = imperial_examiners
				target = scope:examination_character_1
			}
		}

		ai_chance = {
			base = 0
		}
	}
	
	option = {
		name = emperor_imperial_examination.800.c
		add_prestige = minor_prestige_gain
		
		scope:examination_character_2 = {
			add_stress = major_stress_impact_gain
		}
		
		stress_impact = {
			paranoid = major_stress_impact_loss
			humble = minor_stress_impact_gain
			compassionate = minor_stress_impact_gain
		}

		ai_chance = {
			base = 0
		}
	}
	
	after = {
		scope:examination_character_1 = {
			silent_disappear_ai_if_not_hired = yes
		}
	}
}

scripted_trigger is_excellent_courtier_offering = {
	is_physically_able_ai_adult = yes
	NOR = {
		any_consort = { is_landed = yes }
		any_heir_title = {}
	}
	OR = {
		aptitude:grand_preceptor_court_position >= 4
		aptitude:grand_mentor_court_position >= 4
		aptitude:grand_guardian_court_position >= 4
		aptitude:fire_dragon_engineer_court_position >= 4
		aptitude:keeper_of_the_harem_court_position >= 4
		aptitude:favored_minister_court_position >= 4
		aptitude:minister_bureaucrat_court_position >= 4
		aptitude:court_physician_court_position >= 4
		aptitude:travel_leader_court_position >= 4
	}
}

# A Good Servant
emperor_imperial_examination.900 = {
	type = activity_event
	title = emperor_imperial_examination.900.t
	desc = emperor_imperial_examination.900.desc
	theme = imperial_examination
	override_background = { reference = feast }
	left_portrait = {
		character = root
		animation = emperor
		camera = camera_event_crowd
	}
	center_portrait = {
		character = scope:examination_character_1
		animation = gongshou
		camera = camera_event_right
	}
	right_portrait = {
		character = scope:examination_character_2
		animation = serving_tray
	}
	cooldown = { years = 1 }
	trigger = {
		this = scope:host
		scope:activity = {
			any_guest_subset = {
				name = palace_entrants
				is_physically_able_ai_adult = yes
				is_ruler = yes
				NOR = {
					is_consort_of = scope:host
					is_close_family_of = scope:host
					house ?= scope:host.house
				}
				any_courtier = {
					is_excellent_courtier_offering = yes
				}
			}
		}
	}
	immediate = {
		scope:activity = {
			random_guest_subset = {
				name = palace_entrants
				limit = {
					is_physically_able_ai_adult = yes
					is_ruler = yes
					NOR = {
						is_consort_of = scope:host
						is_close_family_of = scope:host
						house ?= scope:host.house
					}
					any_courtier = {
						is_excellent_courtier_offering = yes
					}
				}
				save_scope_as = examination_character_1
				capital_county = { save_scope_as = origin_county }
				random_courtier = {
					limit = {
						is_excellent_courtier_offering = yes
					}
					save_scope_as = examination_character_2
				}
			}
		}
	}
	
	option = {
		name = emperor_imperial_examination.900.a
		add_courtier = scope:examination_character_2
		add_legitimacy = minor_legitimacy_gain
		reverse_add_opinion = {
			target = scope:examination_character_1
			modifier = honored_opinion
			opinion = 50
		}
		reverse_add_opinion = {
			target = scope:examination_character_2
			modifier = honored_opinion
			opinion = 50
		}
		scope:examination_character_1 = {
			change_merit = 2000
		}
	}
	
	option = {
		name = emperor_imperial_examination.900.b
		add_legitimacy = minor_legitimacy_gain
		add_prestige = minor_prestige_gain

		ai_chance = {
			base = 0
		}
	}
}

emperor_imperial_examination.1000 = {
	type = activity_event
	title = emperor_imperial_examination.1000.t
	desc = emperor_imperial_examination.1000.desc
	theme = imperial_examination
	override_background = { reference = feast }
	left_portrait = {
		character = root
		animation = emperor
		camera = camera_event_very_left
	}
	center_portrait = {
		character = scope:examination_character_2
		animation = gongshou
		camera = camera_event_right
	}
	cooldown = { years = 1 }
	trigger = {
		this = scope:host
		scope:activity = {
			any_guest_subset = {
				name = palace_entrants
				is_physically_able_ai_adult = yes
				NOR = {
					is_consort_of = scope:host
					is_close_family_of = scope:host
					house ?= scope:host.house
					culture = { has_same_culture_language = scope:host.culture }
				}
			}
		}
	}
	immediate = {
		culture:han = { save_scope_as = chinese }
		scope:activity = {
			random_guest_subset = {
				name = palace_entrants
				limit = {
					is_physically_able_ai_adult = yes
					NOR = {
						is_consort_of = scope:host
						is_close_family_of = scope:host
						house ?= scope:host.house
						culture = { has_same_culture_language = scope:host.culture }
					}
				}
				save_scope_as = examination_character_2
				hidden_effect = {
					if = {
						limit = {
							NOT = {
								knows_language_of_culture = culture:han
							}
						}
						learn_language_of_culture = culture:han
					}
				}
			}
		}
	}
	
	option = {
		name = emperor_imperial_examination.1000.a
		add_legitimacy = minor_legitimacy_gain
		scope:examination_character_2 = {
			change_merit = 5000
		}
		culture = {
			change_cultural_acceptance = {
				target = scope:examination_character_2.culture
				value = 10
				desc = cultural_acceptance_gain_event
			}
		}
	}
	
	option = {
		name = emperor_imperial_examination.1000.b
		add_prestige = major_prestige_gain
		add_dread = major_dread_gain
		scope:examination_character_2 = {
			change_merit_level = -2
			add_stress = massive_stress_impact_gain
			remove_from_activity = involved_activity
			examination_clear_timeout_effect = yes
		}
		
		ai_chance = {
			base = 0
		}
	}
}
