﻿namespace = court

##################################################
# # RANGES
# 0001 - 0099		Misc Events
# 0100 - 0999 		James
# 1000 - 2000		Shoes
# 2001 - 2999		Ewan
# 3000 - 4000		Bianca
# 4001 - 5000		Isabella
# 5001 - 5999		Linnea
# 6000 - 6999		Claudia
# 7000 - 8000		George
# 8001 - 8999		Joe
# 9000 - 9999		Oltner
# 
##################################################



##################################################
# Example

##################################################
# 0001 - 0010	Example Event
##################################################

##################################################
# Example Event
# by Ewan Cowhig Croft
# 0001 - 0010
##################################################

# Example court event for studying.
#court.0001 = {
#	# Court-type events only appear in the Royal Court view, and are optional to interact with.
#	type = court_event
#	# Desc and theming rules are as normal, but since there's no background, there's no need for background overrides.
#	title = court.0001.t
#	desc = court.0001.desc
#	theme = court
#	# Main portraits are unnecessary: we define this stuff via the court_scene block instead.
#	# Secondary portraits may be used as usual.
#	lower_left_portrait = scope:character_c
#
#	# Court events should be fired from one of their on_actions, but since this is an example, it's left orphaned.
#	orphan = yes
#
#	# Here, we define how the event appears inside the court view.
#	## This block exists in the root scope, so you can just define anyone you'd normally have access to/set up in the immediate block here.
#	court_scene = {
#		# Define which character will have the button for starting the event appear over the top of 'em.
#		button_position_character = scope:character_a
#		# Roles defined in \ck3\game\gfx\court_scene\character_roles\, if you want to change them or add new ones.
#		roles = {
#			# First, we take each scoped relevant scoped character.
#			scope:character_a = {
#				# Then we define their role, where they're positioned in the scene. The first character defines always takes the first slot and so on. Slot 1 and 2 look at each other. Slot 3 is beside Slot 2 and facing Slot 1 as well.
#				group = event_group
#				# Next, we select their animation override (if applicable: you can leave it to the generic default/role default if defined, though generally you'll want to define this).
#
#				# This can be a scripted animation block for animation selection based on triggers
#				# scripted_animation = {
#				# 	triggered_animation = {
#				# 		trigger = {
#				# 			scope:ruler = {
#				# 				is_female = no
#				# 			}
#				# 		}
#				# 
#				# 		both syntaxes are supported
#				# 		animation = { rage anger sadness } # randomly chooses one of these animations
#				# 		animation = sadness # selects just one animation
#				# You can set a default animation if all triggers fail. Convention is to always have some always-valid trigger and not use this field if using triggered animations.
#				animation = anger
#			}
#			scope:character_b = {
#				group = event_group
#				animation = rage
#			}
#			# Characters who are not physically present are referred to only via copy links or lower portraits, so we don't bother putting them here.
#		}
#	}
#
#	weight_multiplier = {
#		base = 1
#		
#		# Court weightings: plug in a court type that should see this event more often.
#		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_diplomatic }
#	}
#
#	immediate = {
#		# As with portraits, we do our general character setup stuff in this event.
#		random_courtier_or_guest = { save_scope_as = character_a }
#		random_courtier_or_guest = {
#			limit = {
#				NOT = { this = scope:character_a }
#			}
#			save_scope_as = character_b
#		}
#	}
#
#	# Court events, as with all events, require at least one option to display.
#	option = {
#		name = court.0001.a
#	}
#}











##################################################
# James

##################################################
# 0107			Court tutor reading a boring book to your ward
# 0108			Copyright-friendly foreign Prince/Princess arrives in your court
# 0109			Executioner multiclasses to physician
# 0111			Intervention for your sex addiction
# 0112			Executioner tries their hand at interior decoration
##################################################

#####################################
# Boring book						#
# by James Beaumont					#
# 0107								#
#####################################

# Tutor reads a boring book to a ward
court.0107 = {
	type = court_event
	title = court.0107.t
	desc = court.0107.desc

	theme = court
	court_scene = {
		button_position_character = scope:tutor
		roles = {
			scope:tutor = {
				group = event_group
				animation = anger
			}
			scope:unruly_child = {
				group = event_group
				animation = boredom
			}
		}
	}

	cooldown = { years = 5 }

	trigger = {
		#AGOT Modified to account for tutor or maester
		# employs_court_position = court_tutor_court_position
		# is_available_adult = yes
		# court_position:court_tutor_court_position = {
		# 	is_available_ai_adult = yes
		# 	has_court_event_flag = no
		# }
		is_available_adult = yes
		OR = {
			AND = {
				employs_court_position = court_tutor_court_position
				court_position:court_tutor_court_position = {
					is_available_ai_adult = yes
					has_court_event_flag = no
				}
			}
			AND = {
				employs_court_position = maester_court_position
				court_position:maester_court_position = {
					is_available_ai_adult = yes
					has_court_event_flag = no
				}
			}
		}
		any_child = {
			is_available_child = yes
			age >= 6
			has_court_event_flag = no
		}
	}
	
	# More likely to trigger if the tutor likes writing things
	weight_multiplier = {
		base = 1
		modifier = { 
			add = 0.5
			#AGOT Modified to account for tutor or maester
			# court_position:court_tutor_court_position = { has_trait = journaller }
			OR = {
				court_position:court_tutor_court_position ?= { has_trait = journaller }
				court_position:maester_court_position ?= { has_trait = journaller }
			}
		}
		modifier = { 
			add = 0.5
			#AGOT Modified to account for tutor or maester
			# court_position:court_tutor_court_position = {
			# 	OR = {
			# 		has_trait = intellect_good_1
			# 		has_trait = intellect_good_2
			# 		has_trait = intellect_good_3
			# 	}
			# }
			OR = {
				court_position:court_tutor_court_position ?= {
					OR = {
						has_trait = intellect_good_1
						has_trait = intellect_good_2
						has_trait = intellect_good_3
					}
				}
				court_position:maester_court_position ?= {
					OR = {
						has_trait = intellect_good_1
						has_trait = intellect_good_2
						has_trait = intellect_good_3
					}
				}
			}
		}
		modifier = { 
			add = -0.5
			#AGOT Modified to account for tutor or maester
			# court_position:court_tutor_court_position = {
			# 	OR = {
			# 		has_trait = intellect_bad_1
			# 		has_trait = intellect_bad_2
			# 		has_trait = intellect_bad_3
			# 	}
			# }
			OR = {
				court_position:court_tutor_court_position ?= {
					OR = {
						has_trait = intellect_bad_1
						has_trait = intellect_bad_2
						has_trait = intellect_bad_3
					}
				}
				court_position:maester_court_position ?= {
					OR = {
						has_trait = intellect_bad_1
						has_trait = intellect_bad_2
						has_trait = intellect_bad_3
					}
				}
			}
		}
	}

	immediate = {
		if = {
			limit = {
				any_court_position_holder = {
					type = court_tutor_court_position
				}
			}
			random_court_position_holder = {
				type = court_tutor_court_position
				save_scope_as = tutor
				court_event_character_flag_effect = yes
			}
		}
		#AGOT Added to account for tutor or maester
		else_if = {
			limit = {
				any_court_position_holder = {
					type = maester_court_position
				}
			}
			random_court_position_holder = {
				type = maester_court_position
				save_scope_as = tutor
				court_event_character_flag_effect = yes
			}
		}
		if = {
			limit = {
				any_child = {
					is_available_child = yes
					age >= 6
					OR = {
						has_trait = bossy
						has_trait = rowdy
					}
				}
			}
			random_child = {
				limit = {
					is_available_child = yes
					age >= 6
					OR = {
						has_trait = bossy
						has_trait = rowdy
					}
				}
				save_scope_as = unruly_child
				add_character_flag = {
					flag = in_court_event
					days = 180
				}
			}
		}
		else = {
			random_child = {
				limit = {
					is_available_child = yes
					age >= 6
				}
				save_scope_as = unruly_child
				court_event_character_flag_effect = yes
			}
		}
	}

	# Option A: Scold the child for being brazen
	option = { 
		name = court.0107.a
		progress_towards_friend_effect = {
			REASON = friend_upheld_educational_tactics
			CHARACTER = scope:tutor
			OPINION = default_friend_opinion
		}
		progress_towards_rival_effect = {
			CHARACTER = scope:unruly_child
			REASON = rival_child_scolded
			OPINION = default_rival_opinion
		}
		hidden_effect = {
			scope:unruly_child = {
				education_point_acquisition_effect = yes
			}
		}
		stress_impact = {
			vengeful = minor_stress_impact_gain
			sadistic = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = -0.5
				ai_vengefulness = 0.5
			}
		}
	}

	#Option B: Buy the book yourself
	option = { 
		name = court.0107.b
		trigger = {
			scope:tutor = { has_education_rank_trigger = { RANK = 2 OPERATOR = greater } }
		}
		add_opinion = {
	 		target = scope:tutor
	 		modifier = flattered_opinion
	 		opinion = 15
	 	}
		pay_short_term_gold = {
			target = scope:tutor
			gold = medium_gold_value
		}
		custom_tooltip = court.0107.b.tt
		if = { 
			limit = {
				scope:tutor = {
					has_trait = education_martial
				}
			}
			create_artifact_book_effect = {
				OWNER = root
				CREATOR = scope:tutor
				SET_SUBJECT = flag:martial
				SET_TOPIC = flag:no
			}
		}
		else_if = { 
			limit = {
				scope:tutor = {
					has_trait = education_stewardship
				}
			}
			create_artifact_book_effect = {
				OWNER = root
				CREATOR = scope:tutor
				SET_SUBJECT = flag:stewardship
				SET_TOPIC = flag:no
			}
		}
		else_if = { 
			limit = {
				scope:tutor = {
					has_trait = education_diplomacy
				}
			}
			create_artifact_book_effect = {
				OWNER = root
				CREATOR = scope:tutor
				SET_SUBJECT = flag:diplomacy
				SET_TOPIC = flag:no
			}
		}
		else_if = { 
			limit = {
				scope:tutor = {
					has_trait = education_intrigue
				}
			}
			create_artifact_book_effect = {
				OWNER = root
				CREATOR = scope:tutor
				SET_SUBJECT = flag:intrigue
				SET_TOPIC = flag:no
			}
		}
		else_if = { 
			limit = {
				scope:tutor = {
					has_trait = education_learning
				}
			}
			create_artifact_book_effect = {
				OWNER = root
				CREATOR = scope:tutor
				SET_SUBJECT = flag:learning
				SET_TOPIC = flag:no
			}
		}
		custom_tooltip = buy_book_artifact
		scope:newly_created_artifact = {
			save_scope_as = this_artifact
		}
		scope:tutor = {
			save_scope_as = old_owner
		}
		hidden_effect = {
			send_interface_toast = {	
				title = artifact.0012.t
				left_icon = scope:this_artifact
				right_icon = scope:old_owner
				custom_tooltip = artifact.0012.tooltip
			}
		}
		stress_impact = {
			intellect_good_1 = minor_stress_impact_loss
			intellect_good_2 = minor_stress_impact_loss
			intellect_good_3 = minor_stress_impact_loss
			scholar = minor_stress_impact_loss
			greedy = minor_stress_impact_gain
			intellect_bad_1 = minor_stress_impact_gain
			intellect_bad_2 = medium_stress_impact_gain
			intellect_bad_3 = major_stress_impact_gain
		}
		ai_chance = {
			base = 50
			modifier = {
				short_term_gold < medium_gold_value
				factor = 0
			}
		}
	}

	#Option C: Suggest another book
	option = { 
		name = court.0107.c
		add_opinion = {
	 		target = scope:tutor
	 		modifier = insult_opinion
	 		opinion = -15
	 	}
		progress_towards_friend_effect = {
			REASON = friend_saved_from_boredom
			CHARACTER = scope:unruly_child
			OPINION = default_friend_opinion
		}
		stress_impact = {
			compassionate = minor_stress_impact_loss
			diligent = minor_stress_impact_gain
			stubborn = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = -0.5
			}
		}
	}
	after = {
		scope:tutor = {
			clear_court_event_participation = yes
		}
		scope:unruly_child = {
			clear_court_event_participation = yes
		}
	}
}

#####################################
# A Spectacular Courtier			#
# by James Beaumont					#
# 0108								#
#####################################

scripted_effect spawn_foreign_prince_effect = {
	random_kingdom = {
		limit = {
			exists = holder
			holder = {
				is_ai = yes
				NOT = {
					in_diplomatic_range = root 
				} 
			}
		}
		holder = { save_scope_as = foreign_realm_target }
	}
	scope:available_child = {
		if = {
			limit = { is_female = no }
			create_character = {
				location = root.capital_province
				template = prince_ali_template
				gender = female
				culture = scope:foreign_realm_target.culture
				faith = scope:foreign_realm_target.faith
				save_scope_as = foreign_prince
			}
		}
		else = {
			create_character = {
				location = root.capital_province
				template = prince_ali_template
				gender = male
				culture = scope:foreign_realm_target.culture
				faith = scope:foreign_realm_target.faith
				save_scope_as = foreign_prince
			}
		}
	}
	scope:foreign_prince = {
		random_list = {
			50 = { set_sexuality = heterosexual }
			50 = { set_sexuality = bisexual }
		}
		random_list = {
			3 = { add_gold = 100 }
			3 = { add_gold = 250 }
			3 = { add_gold = 500 }
			3 = { add_gold = 750 }
			3 = { add_gold = 1000 }
			2 = { add_gold = 1500 }
			1 = { add_gold = 2500 }
		}
		set_relation_lover = { reason = lover_magnificently_seduced target = scope:available_child involved_character = root }
		give_nickname = nick_fabulous_she_he
		visit_court_of = root
	}
}

# Foreign Prince comes to propose to an available daughter/son
court.0108 = {
	type = court_event
	title = court.0108.t
	desc = court.0108.desc

	theme = court
	court_scene = {
		button_position_character = scope:sceptical_courtier
		roles = {
			scope:sceptical_courtier = {
				group = event_group
				animation = personality_cynical
			}
			scope:available_child = {
				group = event_group
				animation = love
			}
			scope:foreign_prince = {
				group = event_group
				animation = flirtation_left
			}
		}
	}

	cooldown = { years = 50 }

	trigger = {
		is_available_adult = yes
		any_child = {
			is_available_ai_adult = yes
			allowed_more_spouses = yes
			is_concubine = no
			OR = {
				has_sexuality = heterosexual
				has_sexuality = bisexual
			}
			has_court_event_flag = no
			#AGOT Added, allowed more spouses doesn't check common marriage blockers
			can_marry_trigger = yes
		}
		any_kingdom = {
			exists = holder
			holder = {
				is_ai = yes
				NOT = {
					in_diplomatic_range = root 
				} 
			}
		}
		court_grandeur_current_level >= medium_court_grandeur_level
	}
	
	#AGOT Disabled
	# weight_multiplier = {
	# 	base = 1
	# 	modifier = {
	# 		add = 1
	# 		root.faith = {
	# 			OR = {
	# 				religion_tag = islam_religion
	# 				has_doctrine_parameter = islamic_syncretic_actor_opinion_active
	# 			}
	# 		}
	# 	}
	# }

	immediate = {
		hidden_effect = {
			if = {
				limit = {
					any_court_position_holder = {
						has_trait = cynical
						is_available_adult = yes
					}
				}
				random_court_position_holder = {
					limit = {
						has_trait = cynical
						is_available_adult = yes
					}
					save_scope_as = sceptical_courtier
					court_event_character_flag_effect = yes
				}
			}
			else_if = {
				limit = {
					any_courtier = {
						has_trait = cynical
						is_available_adult = yes
					}
				}
				random_courtier = {
					limit = {
						has_trait = cynical
						is_available_adult = yes
					}
					save_scope_as = sceptical_courtier
					court_event_character_flag_effect = yes
				}
			}
			else = {
				random_courtier = {
					limit = { is_available_adult = yes }
					save_scope_as = sceptical_courtier
					court_event_character_flag_effect = yes
				}
			}
			random_child = {
				limit = {
					is_available_ai_adult = yes
					allowed_more_spouses = yes
					is_concubine = no
					OR = { #They need to be attracted to the Prince
						has_sexuality = heterosexual
						has_sexuality = bisexual
					}
					#AGOT Added, allowed more spouses doesn't check common marriage blockers
					can_marry_trigger = yes
				}
				save_scope_as = available_child
				court_event_character_flag_effect = yes
			}
			spawn_foreign_prince_effect = yes
		}
	}

	# Option A: Get them married!
	option = {
		name = court.0108.a
		add_gold = minor_gold_value
		scope:available_child = {
			add_opinion = {
				modifier = grateful_opinion
				target = root
				opinion = 40
			}
		}
		progress_towards_friend_effect = {
			REASON = friend_approved_marriage_proposal
			CHARACTER = scope:foreign_prince
			OPINION = default_friend_opinion
		}
		progress_towards_rival_effect = {
			CHARACTER = scope:sceptical_courtier
			REASON = rival_concerns_dismissed
			OPINION = default_rival_opinion
		}
		if = {
			limit = {
				has_ep2_dlc_trigger = yes
			}
			create_grand_wedding_betrothal = {
				SPOUSE_1 = scope:available_child
				SPOUSE_2 = scope:foreign_prince
				HOST = root
				PROMISEE = scope:foreign_realm_target
			}
		}
		else_if = {
			limit = {
				scope:available_child = {
					is_female = no
				}
			}
			scope:available_child = { marry = scope:foreign_prince }
		}
		else = {
			scope:available_child = { marry_matrilineal = scope:foreign_prince }
		}
		change_current_court_grandeur = minor_court_grandeur_gain
		stress_impact = {
			paranoid = major_stress_impact_gain
			cynical = minor_stress_impact_gain
			compassionate = minor_stress_impact_loss
			trusting = minor_stress_impact_loss
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = 2
				ai_vengefulness = -0.5
			}
		}
	}

	#Option B: Imprison the Prince
	option = { 
		name = court.0108.b
		progress_towards_rival_effect = {
			CHARACTER = scope:foreign_prince
			REASON = rival_foreign_prince
			OPINION = default_rival_opinion
		}
		progress_towards_rival_effect = {
			CHARACTER = scope:available_child
			REASON = rival_disallowed_marrying
			OPINION = default_rival_opinion
		}
		progress_towards_friend_effect = {
			REASON = friend_believed_claim
			CHARACTER = scope:sceptical_courtier
			OPINION = default_friend_opinion
		}
		rightfully_imprison_character_effect = {
			TARGET = scope:foreign_prince
			IMPRISONER = root
 		}
		stress_impact = {
			compassionate = minor_stress_impact_gain
			trusting = minor_stress_impact_gain
			sadistic = minor_stress_impact_loss
			cynical = major_stress_impact_loss
			paranoid = major_stress_impact_loss
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = -0.5
				ai_vengefulness = 1
			}
		}
	}

	#Option C: Send them away
	option = { 
		name = court.0108.c
		scope:available_child = {
			add_opinion = {
				modifier = hurt_opinion
				target = root
				opinion = -25
			}
		}
		scope:foreign_prince = {
			hidden_effect = { select_and_move_to_pool_effect = yes }
		}
		show_as_tooltip = {
			remove_courtier_or_guest = scope:foreign_prince
		}
		ai_chance = {
			base = 10
		}
	}
	after = {
		scope:available_child = {
			clear_court_event_participation = yes
		}
		scope:sceptical_courtier = {
			clear_court_event_participation = yes
		}
	}
}

#####################################
# An Anatomical Expert				#
# by James Beaumont					#
# 0109								#
#####################################

# Executioner knows medicine, wants to be a doctor
court.0109 = {
	type = court_event
	title = court.0109.t
	desc = court.0109.desc

	theme = court
	court_scene = {
		button_position_character = scope:executioner
		roles = {
			scope:executioner = {
				group = event_group
				animation = personality_rational
			}
			scope:learned_courtier = {
				group = event_group
				animation = admiration
			}
		}
	}

	cooldown = { years = 5 }

	trigger = { 
		employs_court_position = executioner_court_position
		court_position:executioner_court_position = {
			is_available_ai_adult = yes
			has_court_event_flag = no
			NOT = { has_court_position = court_physician_court_position }
			save_temporary_scope_as = executioner_temp
		}
		any_courtier = {
			exists = yes
			is_available_adult = yes
			learning >= 10
			has_court_event_flag = no
			NOR = {
				has_court_position = executioner_court_position
				this = scope:executioner_temp
			}
		}
		is_available_adult = yes
	}
	
	# More likely to trigger if the executioner is smart and cares about other humans
	weight_multiplier = {
		base = 1
		modifier = { 
			add = 0.5
			court_position:executioner_court_position = { has_trait = scholar }
		}
		modifier = { 
			add = 0.5
			court_position:executioner_court_position = { has_trait = compassionate }
		}
		modifier = { 
			add = 0.5
			court_position:executioner_court_position = { has_trait = education_learning }
		}
		modifier = { 
			add = 0.5
			court_position:executioner_court_position = { has_trait = lifestyle_herbalist }
		}
		modifier = { 
			add = 0.5
			court_position:executioner_court_position = { has_trait = lifestyle_physician }
		}
		modifier = { 
			add = 0.5
			court_position:executioner_court_position = {
				OR = {
					has_trait = intellect_good_1
					has_trait = intellect_good_2
					has_trait = intellect_good_3
				}
			}
		}
		modifier = { 
			add = -0.5
			court_position:executioner_court_position = {
				OR = {
					has_trait = intellect_bad_1
					has_trait = intellect_bad_2
					has_trait = intellect_bad_3
				}
			}
		}
		#Executioner less likely to help the sick and needy if they don't care about the sick and needy
		modifier = { 
			add = -0.5
			court_position:executioner_court_position = { has_trait = sadistic }
		}
		modifier = { 
			add = -0.5
			court_position:executioner_court_position = { has_trait = callous }
		}
		modifier = { 
			add = 0.5
			court_position:executioner_court_position = { has_trait = compassionate }
		}
	}

	immediate = {
		random_court_position_holder = {
			type = executioner_court_position
			limit = {
				is_available_ai_adult = yes
				has_court_event_flag = no
				NOT = { has_court_position = court_physician_court_position }
			}
			save_scope_as = executioner
			court_event_character_flag_effect = yes
			if = {
				limit = {
					NOT = { has_trait = lifestyle_physician }
				}
				add_trait = lifestyle_physician
				add_random_tiered_trait_xp_effect = {
					TRAIT = lifestyle_physician
					LEVEL_1 = yes
					LEVEL_3 = yes
				}
			}
		}
		if = {
			limit = {
				cp:councillor_court_chaplain = {
					exists = yes
					learning >= 10
					is_available_ai_adult = yes
					NOR = {
						has_court_position = executioner_court_position
						this = scope:executioner
					}
				}
			}
			cp:councillor_court_chaplain = {
				save_scope_as = learned_courtier
				court_event_character_flag_effect = yes
			}
		}
		else = {
			random_courtier = {
				limit = {
					learning >= 10
					is_available_adult = yes
					has_court_event_flag = no
					NOR = {
						has_court_position = executioner_court_position
						this = scope:executioner
					}
				}
				save_scope_as = learned_courtier
				court_event_character_flag_effect = yes
			}
		}
		if = {
			limit = {
				employs_court_position = court_physician_court_position
				court_position:court_physician_court_position = {
					NOT = { this = scope:executioner }
				}
			}
			random_court_position_holder = {
				type = court_physician_court_position
				limit = { NOT = { this = scope:executioner } }
				save_scope_as = current_physician
			}
		}
	}

	# Option A: Employ executioner as physician
	option = { 
		name = court.0109.a
		progress_towards_friend_effect = {
			REASON = friend_hired_physician
			CHARACTER = scope:executioner
			OPINION = 0
		}
		reverse_add_opinion = {
	 		target = scope:executioner
	 		modifier = grateful_opinion
	 		opinion = 25
	 	}
	 	revoke_court_position = {
	 		recipient = scope:executioner
			court_position = executioner_court_position
	 	}
		
		if = {
			limit = { exists = scope:current_physician }
			replace_court_position = {
				recipient = scope:executioner
				holder = scope:current_physician
				court_position = court_physician_court_position
			}
		}
		else = {
			appoint_court_position = {
				recipient = scope:executioner
				court_position = court_physician_court_position
			}
		}
		
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = 0.5
				ai_vengefulness = -0.5
			}
			modifier = {
				factor = 2
				scope:executioner = {
					has_trait = lifestyle_physician
					has_trait_xp = {
						trait = lifestyle_physician
						value >= 100
					}
				}
			}
		}
	}

	#Option B: Repremand the executioner for tending to prisoners
	option = { 
		name = court.0109.b
		progress_towards_rival_effect = {
			CHARACTER = scope:executioner
			REASON = rival_tended_prisoners
			OPINION = default_rival_opinion
		}
		scope:executioner = {
			add_stress = minor_stress_gain
		}
		stress_impact = {
			vengeful = minor_stress_impact_loss
			sadistic = minor_stress_impact_loss
			compassionate = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_vengefulness = 0.5
				ai_compassion = -0.5
			}
		}
	}

	#Option C: Learn from the executioner
	option = { 
		name = court.0109.c
		trigger = {
			OR = {
				has_trait = scholar
				has_trait = education_learning
				has_lifestyle = learning_lifestyle
			}
		}
		if = {
			limit = {
				scope:executioner = {
					has_trait = lifestyle_physician
					has_trait_xp = {
						trait = lifestyle_physician
						value >= 100
					}
				}
			}
			add_learning_lifestyle_xp = major_lifestyle_xp
		}
		else_if = {
			limit = {
				scope:executioner = {
					has_trait = lifestyle_physician
					has_trait_xp = {
						trait = lifestyle_physician
						value >= 50
					}
				}
			}
			add_learning_lifestyle_xp = medium_lifestyle_xp
		}
		else = {
			add_learning_lifestyle_xp = minor_lifestyle_xp
		}
		stress_impact = {
			arrogant = medium_stress_impact_gain
			lazy = medium_stress_impact_gain
			impatient = medium_stress_impact_gain
			shy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50
		}
	}

	#Option D: Tell them to continue tending to the sick and needy
	option = { 
		name = court.0109.d
		primary_title.title_capital_county = {
			change_development_progress = medium_development_progress_gain
		}
		reverse_add_opinion = {
	 		target = scope:executioner
	 		modifier = disappointed_opinion
	 		opinion = -5
	 	}
	 	scope:executioner = {
	 		give_nickname = nick_health_god_mercy
	 	}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = 0.5
				ai_vengefulness = -0.5
			}
		}
	}
	after = {
		scope:learned_courtier = {
			clear_court_event_participation = yes
		}
		scope:executioner = {
			clear_court_event_participation = yes
		}
	}
}

#####################################
# A Relic of Revenge				#
# by James Beaumont					#
# 0111								#
#####################################

# Executioner wants to turn the skull of your rival into an artefact
scripted_trigger enticingly_skulled_prisoner = {
	is_ai = yes
	is_adult = yes
	#root = { has_execute_reason = prev }
	OR = {
		has_relation_rival = root
		NOT = { has_faith = root.faith }
		has_hook = root
		num_sinful_traits >= 2
	}
}

court.0111 = {
	type = court_event
	title = court.0111.t
	desc = court.0111.desc

	theme = court
	court_scene = {
		button_position_character = scope:executioner
		roles = {
			scope:executioner = {
				group = event_group
				animation = scheme
			}
			scope:antiquarian = {
				group = event_group
				animation = anger
			}
		}
	}
	
	cooldown = { years = 50 }

	trigger = {
		employs_court_position = executioner_court_position
		employs_court_position = antiquarian_court_position
		court_position:executioner_court_position = {
			is_available_ai_adult = yes
			has_court_event_flag = no
			NOT = {
				has_court_position = antiquarian_court_position
			}
		}
		court_position:antiquarian_court_position = {
			is_available_ai_adult = yes
			has_court_event_flag = no
			NOT = {
				has_court_position = executioner_court_position
			}
		}
		any_prisoner = { enticingly_skulled_prisoner = yes }
	}
	
	# More likely to trigger if the executioner is kind of evil
	weight_multiplier = {
		base = 1
		modifier = { 
			add = 0.5
			court_position:executioner_court_position = {
				has_trait = sadistic
			}
		}
		modifier = { 
			add = 0.5
			court_position:executioner_court_position = {
				has_trait = callous
			}
		}
	}

	immediate = {
		if = {
			limit = {
				court_position:executioner_court_position = {
					is_available_ai_adult = yes
					NOT = {
						has_court_position = antiquarian_court_position
					}
				}
			}
			court_position:executioner_court_position = {
				save_scope_as = executioner
				court_event_character_flag_effect = yes
			}
		}
		if = {
			limit = {
				court_position:antiquarian_court_position = {
					is_available_ai_adult = yes
					NOT = {
						has_court_position = executioner_court_position
					}
				}
			}
			court_position:antiquarian_court_position = {
				save_scope_as = antiquarian
				court_event_character_flag_effect = yes
				}
		}
		random_prisoner = {
			limit = { enticingly_skulled_prisoner = yes }
			save_scope_as = rival
		}
	}

	# Option A: Give me their skull
	option = {
		name = court.0111.a
		progress_towards_friend_effect = {
			REASON = friend_took_side_in_dispute
			CHARACTER = scope:executioner
			OPINION = default_friend_opinion
		}
		reverse_add_opinion = {
	 		target = scope:antiquarian
	 		modifier = disgusted_opinion
	 		opinion = -30
	 	}
	 	save_scope_as = owner
		if = {
			limit = {
				scope:rival = {
					OR = {
						has_relation_rival = root
						has_hook = root
					}
				}
			}
			create_artifact = {
				name = artifact_pedestal_skull_of_the_enemy_name
				description = artifact_pedestal_skull_of_the_enemy_description
				visuals = human_skull
				type = pedestal
				modifier = artifact_dread_baseline_add_2_modifier
				save_scope_as = newly_created_artifact
			}
		}
		
		else_if = {
		 	limit = {
		 		scope:rival = {
		 			OR = {
						NOT = { has_faith = root.faith }
						num_sinful_traits >= 2
		 			}
		 		}
		 	}
		 	create_artifact = {
		 		name = artifact_pedestal_skull_of_the_apostate_name
		 		description = artifact_pedestal_skull_of_the_apostate_description
		 		visuals = human_skull
		 		type = pedestal
		 		modifier = artifact_dread_baseline_add_2_modifier
		 		save_scope_as = newly_created_artifact
		 	}
		}
		
		hidden_effect = {
			scope:newly_created_artifact = {
				add_artifact_modifier = artifact_dread_gain_mult_3_modifier
				add_artifact_modifier = artifact_intrigue_per_stress_level_1_modifier
				add_artifact_modifier = artifact_hostile_scheme_power_add_3_modifier
			}
		}
		scope:newly_created_artifact = {
			save_scope_as = this_artifact
		}
		scope:rival = {
			save_scope_as = old_owner
		}
		hidden_effect = {
			send_interface_toast = {	
				title = artifact.0012.t
				left_icon = scope:this_artifact
				right_icon = scope:old_owner
				custom_tooltip = artifact.0012.tooltip
			}
		}
		scope:rival = {
			death = {
				death_reason = death_skull_removed
				killer = scope:executioner
			}
		}
		stress_impact = {
			compassionate = medium_stress_impact_gain
			just = major_stress_impact_gain
			forgiving = major_stress_impact_gain
			arbitrary = minor_stress_impact_loss
			callous = minor_stress_impact_loss
			vengeful = minor_stress_impact_loss
			wrathful = minor_stress_impact_loss
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_vengefulness = 0.5
				ai_honor = -1
			}
		}
	}

	#Option B: Refuse the "artifact"
	option = {
		name = court.0111.b
		reverse_add_opinion = {
	 		target = scope:executioner
	 		modifier = disappointed_opinion
	 		opinion = -15
	 	}
		reverse_add_opinion = {
	 		target = scope:antiquarian
	 		modifier = relieved_opinion
	 		opinion = 15
	 	}
		stress_impact = {
			vengeful = minor_stress_impact_gain
			wrathful = medium_stress_impact_gain
			forgiving = minor_stress_impact_loss
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = 0.5
				ai_vengefulness = -0.5
				ai_zeal = -0.5
			}
		}
	}
	after = {
		scope:executioner = {
			clear_court_event_participation = yes
		}
		scope:antiquarian = {
			clear_court_event_participation = yes
		}
	}
}

#####################################
# A Closeted Cadaver				#
# by James Beaumont					#
# 0112								#
#####################################

# Lady-in-Waiting has been hiding a cadaver in the closet
court.0112 = {
	type = court_event
	title = court.0112.t
	desc = court.0112.desc

	theme = court
	court_scene = {
		button_position_character = scope:guilty_courtier
		roles = {
			scope:guilty_courtier = {
				group = event_group
				animation = fear
			}
		}
	}
	
	cooldown = { years = 5 }

	trigger = {
		employs_court_position = lady_in_waiting_court_position
		court_position:lady_in_waiting_court_position = {
			is_available_ai_adult = yes
			has_court_event_flag = no
		}
		amenity_level = {
			type = court_fashion
			value > medium_amenity_level
		}
		any_pool_character = {
            province = root.capital_province
			is_available_ai_adult = yes
			NOT = { exists = scope:inspiration }
		}
		is_available_adult = yes
	}
	
	# More likely to trigger if the lady-in-waiting is a bit murder-y or jumpy
	weight_multiplier = {
		base = 1
		modifier = { 
			add = 0.5
			court_position:lady_in_waiting_court_position = {
				has_trait = sadistic
			}
		}
		modifier = { 
			add = 0.5
			court_position:lady_in_waiting_court_position = {
				has_trait = callous
			}
		}
		modifier = { 
			add = 0.5
			court_position:lady_in_waiting_court_position = {
				has_trait = wrathful
			}
		}
		modifier = { 
			add = 0.5
			court_position:lady_in_waiting_court_position = {
				has_trait = craven
			}
		}
	}

	immediate = {
      	court_position:lady_in_waiting_court_position = {
      		save_scope_as = guilty_courtier
			court_event_character_flag_effect = yes
      	}
        hidden_effect = {
            random_pool_character = {
				limit = {
					is_available_ai_adult = yes
	            	NOT = { exists = scope:inspiration }
	            }
            	province = root.capital_province
                save_scope_as = corpse
            }
            unknown_murder_effect = {
                VICTIM = scope:corpse
                MURDERER = scope:guilty_courtier
                REASON = death_murder
            }
            if = {
            	limit = {
            		any_character_artifact = {
						OR = {
							has_variable = cabinet
							has_variable = big_chest
						}
            			NOT = { has_variable = ghost_cabinet }
            		}
            	}
            	random_character_artifact = {
            		limit = {
            			OR = {
							has_variable = cabinet
							has_variable = big_chest
						}
            			NOT = { has_variable = ghost_cabinet }
            		}
            		set_variable = {
            			name = ghost_cabinet
            			years = 50
            		}
            	}
            }
        }
    }

	# Option A: I'll forget I saw this, for the good of fashion
	option = { 
		name = court.0112.a
		scope:guilty_courtier = {
			random_secret = {
				limit = {
					secret_type = secret_murder
					secret_target = scope:corpse
					NOT = { any_secret_knower = { this = root } }
				}
				disable_exposure_by = root
			}
		}
		hidden_effect = {
			create_artifact_regalia_effect = {
				OWNER = root
				SMITH = scope:guilty_courtier
			}
		}
		custom_tooltip = get_regalia_artifact
		scope:newly_created_artifact = {
			save_scope_as = this_artifact
		}
		scope:guilty_courtier = {
			save_scope_as = old_owner
		}
		hidden_effect = {
			send_interface_toast = {	
				title = artifact.0012.t
				left_icon = scope:this_artifact
				right_icon = scope:old_owner
				custom_tooltip = artifact.0012.tooltip
			}
		}
		reverse_add_opinion = {
	 		target = scope:guilty_courtier
	 		modifier = grateful_opinion
	 		opinion = 50
	 	}
		stress_impact = {
			zealous = medium_stress_impact_gain
			vengeful = minor_stress_impact_gain
			wrathful = minor_stress_impact_gain
			just = major_stress_impact_gain
			trusting = minor_stress_impact_loss
			callous = minor_stress_impact_loss
			greedy = minor_stress_impact_loss
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_compassion = 0.5
				ai_greed = 0.5
				ai_honor = -0.5
			}
		}
	}

	#Option B: Expose the murder
	option = { 
		name = court.0112.b
		reverse_add_opinion = {
	 		target = scope:guilty_courtier
	 		modifier = hate_opinion
	 		opinion = -50
	 	}
	 	scope:guilty_courtier = {
			random_secret = {
				limit = {
					secret_type = secret_murder
					secret_target = scope:corpse
					NOT = { any_secret_knower = { this = root } }
				}
				expose_secret = root
			}
		}
		stress_impact = {
			greedy = major_stress_impact_gain
			vengeful = minor_stress_impact_gain
			wrathful = medium_stress_impact_gain
			forgiving = minor_stress_impact_loss
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = -0.5
				ai_greed = -0.5
				ai_honor = 0.5
			}
		}
	}

	#Option C: Leave without saying anything
	option = { 
		name = court.0112.c
		reverse_add_opinion = {
	 		target = scope:guilty_courtier
	 		modifier = scared_opinion
	 		opinion = -15
	 	}
	 	show_as_tooltip = {
		 	scope:guilty_courtier = {
				random_secret = {
					limit = {
						secret_type = secret_murder
						secret_target = scope:corpse
						NOT = { any_secret_knower = { this = root } }
					}
					reveal_to = root
				}
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = -0.5
				ai_greed = -0.5
				ai_honor = -0.5
			}
		}
	}
	after = {
		scope:guilty_courtier = {
			clear_court_event_participation = yes
		}
	}
}











##################################################
# Shoes

##################################################
# 1010 - 1019	Daydrinking
# 1030 - 1039	Poor Manners
##################################################

#####################################
# Daydrinking		 				#
# by Sean Hughes					#
# 1010								#
#####################################

scripted_trigger court_1010_valid_drunkard = {
	has_trait = drunkard
	NOT = {
		has_trait = disinherited
	}
}

court.1010 = {
	type = court_event
	title = court.1010.t
	desc = court.1010.desc
	theme = court

	court_scene = {
		button_position_character = scope:courtier
		roles = {
			scope:courtier = {
				group = event_group
				animation = disbelief
			}
		}
	}
	
	cooldown = { years = 10 }
	
	trigger = {
		any_courtier = {
			court_1010_valid_drunkard = yes
			is_available_ai_adult = yes
			has_court_event_flag = no
		}
	}

	weight_multiplier = {
		base = 1

		# Court weightings.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_warlike }
	}

	immediate = {
		random_courtier = {
			limit = {
				court_1010_valid_drunkard = yes
				is_available_ai_adult = yes
			}
			save_scope_as = courtier
			court_event_character_flag_effect = yes
		}
		if = {
			limit = {
				any_court_position_holder = {
					type = court_jester_court_position
				}
			}
			random_court_position_holder = {
				type = court_jester_court_position
				save_scope_as = jester
			}
		}
	}

	# Option A: [Restricted — courtier is your child] Disinherit them, as they will never amount to anything... especially after you do this.
	option = { 
		name = court.1010.a
		trigger = { scope:courtier = { is_heir_of = root } }
		scope:courtier = {
			add_trait = disinherited
			if = {
				limit = { NOT = { has_trait = dull } }
				add_trait = dull
			}
		}
		dynasty = { 
			add_dynasty_prestige = minor_dynasty_prestige_loss
		}
		stress_impact = {
			forgiving = major_stress_impact_gain
			trusting = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
			family_first = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				OR = {
					has_trait = forgiving
					has_trait = trusting
					has_trait = compassionate
					has_trait = family_first
				}
				factor = 0
			}
		}
	}

	# Option B: Arrest the courtier for their indecent behavior
	option = {
		name = court.1010.b
		rightfully_imprison_character_effect = {
  			TARGET = scope:courtier
  			IMPRISONER = root
		}
		add_dread = minor_dread_gain
		stress_impact = {
			forgiving = major_stress_impact_gain
			trusting = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				OR = {
					has_trait = forgiving
					has_trait = trusting
					has_trait = compassionate
				}
				factor = 0
			}
		}
	}
	
	# Option C: Convince the courtier to ease up on the sauce, at least in public
	option = {
		name = court.1010.c
		duel = {
			skill = diplomacy
			target = scope:courtier
			50 = {
				desc = court.1010.c.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				send_interface_message = {
					type = event_generic_good
					title = court.1010.c.success

					scope:courtier = {
						remove_trait = drunkard
						add_opinion = {
							modifier = respect_opinion
							target = root
							opinion = 30
						}
					}
				}
				
			}
			50 = {
				desc = court.1010.c.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				send_interface_message = {
					type = event_generic_bad
					title = court.1010.c.failure

					scope:courtier = {
						add_prestige = medium_prestige_loss
					}
				}
			}
		}
		stress_impact = {
			impatient = major_stress_impact_gain
			wrathful = medium_stress_impact_gain
			callous = medium_stress_impact_gain
			sadistic = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				OR = {
					has_trait = impatient
					has_trait = wrathful
					has_trait = callous
					has_trait = sadistic
				}
				factor = 0
			}
		}
	}

	# Option D: Enjoy courtier making a fool of themselves, then make them into your actual fool
	option = {
		name = court.1010.d
		trigger = {
			scope:courtier = { can_be_employed_as = court_jester_court_position }
			can_employ_court_position_type = court_jester_court_position
		}
		if = {
			limit = {
				exists = scope:jester
			}
			revoke_court_position = {
				recipient = scope:jester
				court_position = court_jester_court_position
			}
		}
		appoint_court_position = {
			recipient = scope:courtier
			court_position = court_jester_court_position
		}
		stress_impact = {
			forgiving = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				OR = {
					has_trait = forgiving
					has_trait = compassionate
				}
				factor = 0
			}
			modifier = {
				exists = scope:jester
				factor = 0
			}
		}
	}

	# Option E: Enjoy courtier making a fool of themselves and let the behavior go unpunished
	option = {
		name = court.1010.e
		change_current_court_grandeur = major_court_grandeur_loss
		stress_impact = {
			base = medium_stress_loss
			forgiving = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				OR = {
					has_trait = forgiving
					has_trait = compassionate
				}
				factor = 0
			}
		}
	}
	after = {
		scope:courtier = {
			clear_court_event_participation = yes
		}
	}
}

#####################################
# Unpious Behaviour	 				#
# based on event by Sean Hughes		#
# 1030								#
#####################################

scripted_trigger unpious_check = {
	is_available_ai_adult = yes
	OR = {
		this.religion = { NOT = { this = root.religion } }
		AND = {
			OR = {
				has_trait = cynical
				num_sinful_traits >= 1
			}
			NOT = { has_trait = zealous }	
		}	
	}
}



court.1030 = {
	type = court_event
	title = court.1030.t
	desc = court.1030.desc
	theme = court
	override_background = {
		reference = throne_room
	}

	court_scene = {
		button_position_character = scope:chaplain
		roles = {
			scope:chaplain = {
				group = event_group
				animation = disapproval
			}
			scope:courtier = {
				group = event_group
				animation = personality_cynical
			}
		}
	}
	
	cooldown = { years = 15 }

	trigger = {
		NOT = {
			root.faith = { has_doctrine = doctrine_pluralism_pluralistic }
		}
		exists = cp:councillor_court_chaplain
		cp:councillor_court_chaplain = {
			is_available_ai_adult = yes
			has_court_event_flag = no
			save_temporary_scope_as = chaplain_check
			NOT = { has_trait = cynical }
			NOT = { has_trait = shy }
		}
		any_courtier = {
			is_lowborn = no
			has_court_event_flag = no
			unpious_check = yes
			NOT = { this = scope:chaplain_check }
		}
	}

	weight_multiplier = {
		base = 0.5
		modifier = {
			add = 2
			cp:councillor_court_chaplain = { has_trait = zealous }
		}
		
		modifier = {
			add = 1
			cp:councillor_court_chaplain = { has_trait = arrogant }
		}

		# Court weightings.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_diplomatic }
	}

	immediate = {
		cp:councillor_court_chaplain = {
			save_scope_as = chaplain
			court_event_character_flag_effect = yes
		}
		random_courtier = {
			limit = {
				is_lowborn = no
				has_court_event_flag = no
				unpious_check = yes
				NOT = { this = scope:chaplain }
			}
			save_scope_as = courtier
			court_event_character_flag_effect = yes
		}
	}

	# Option A: Back your chaplain
	option = {
		name = court.1030.a
		change_current_court_grandeur = major_court_grandeur_loss
		add_piety = medium_piety_gain
		scope:chaplain = {
			add_opinion = {
				modifier = pleased_opinion
				target = root
				opinion = 20
			}
		}
		scope:courtier = {
			add_opinion = {
				modifier = insult_opinion
				target = root
				opinion = -20
			}
		}
		stress_impact = {
			cynical = major_stress_impact_gain
			arrogant = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				OR = {
					has_trait = cynical
					has_trait = arrogant
				}
				factor = 0.2
			}
		}
	}

	# Option B: Stop the preaching forcefully
	option = {
		name = court.1030.b
		flavor = court.1030.b.flavor
		add_dread = minor_dread_gain
		add_piety = major_piety_loss
		scope:chaplain = {
			add_opinion = {
				modifier = insult_opinion
				target = root
				opinion = -40
			}
		}
		every_courtier = {
			limit = {
				unpious_check = yes
				NOT = { this = scope:chaplain }
			}
			custom = court.1030.b.custom
			add_opinion = {
				modifier = respect_opinion
				target = root
				opinion = 20
			}
		}
		stress_impact = {
			zealous = major_stress_impact_gain
			humble = medium_stress_impact_gain
			arrogant = medium_stress_impact_loss
			impatient = medium_stress_impact_loss
		}
		ai_chance = {
			base = 50
			modifier = {
				OR = {
					has_trait = zealous
					has_trait = humble
				}
				factor = 0
			}
		}
	}
	
	# Option C: privately discourage chaplain
	option = {
		name = court.1030.c
		scope:courtier = {
			add_opinion = {
				modifier = pleased_opinion
				target = root
				opinion = 10
			}
		}
		duel = {
			target = scope:chaplain
			skills = { learning diplomacy }
			20 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 1
				}
				desc = court.1030.c.a
				root = {
					send_interface_toast = {
						title = court.1030.c.a
						reverse_add_opinion = {
							target = scope:chaplain
							modifier = humbled_opinion
							opinion = 10
						}
						change_current_court_grandeur = minor_court_grandeur_gain
						add_piety = minor_piety_gain
					}
				}
			}
			20 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -1
				}
				modifier = {
					add = 50
					scope:chaplain = {
						has_trait = zealous
					}
				}
				desc = court.1030.c.b
				root = {
					send_interface_toast = {
						title = court.1030.c.b
						reverse_add_opinion = {
							target = scope:chaplain
							modifier = insulted_opinion
							opinion = -20
						}
						change_current_court_grandeur = minor_court_grandeur_loss
						add_piety = minor_piety_loss
					}
				}
			}
		}
		stress_impact = {
			patient = minor_stress_impact_loss
			impatient = medium_stress_impact_gain
			arrogant = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				OR = {
					has_trait = zealous
					has_trait = impatient
				}
				factor = 0.3
			}
		}
	}
	after = {
		scope:chaplain = {
			clear_court_event_participation = yes
		}
		scope:courtier = {
			clear_court_event_participation = yes
		} 
	}
}










##################################################
# Ewan

##################################################
# 2201 - 2210	A Slice of the Pie - Your heirs debate the merits of partition. At length.
# 2401 - 2410	Second-Hand Glamour - Your lacklustre approach to fashion sees courtiers turn elsewhere.
# 2411 - 2420	Labyrinthine Halls - A guest gets lost in your huge, and understaffed, halls.
##################################################

	##################################################
	# PATRONAGE



	##################################################
	# MAJESTY SUB-SECTION

##################################################
# A Slice of the Pie
# by Ewan Cowhig Croft
# 2201 - 2210
##################################################

scripted_trigger court_2201_valid_basic_heir_child_trigger = {
	# Can't be landed yet.
	is_landed = no
	# Is your child of your dynasty.
	is_child_of = root
	exists = root.dynasty
	dynasty = root.dynasty
	# Must be available, and at least a teenager.
	is_available_ai = yes
	OR = {
		is_adult = yes
		child_is_teen_trigger = yes
	}
	# Finally, has to be chilling in the capital.
	location = root.capital_province
}

scripted_trigger court_2201_valid_eldest_heir_child_trigger = {
	# Basic checks.
	court_2201_valid_basic_heir_child_trigger = yes
	# Must be something of a standard player-avatar.
	NOR = {
		has_trait = honest
		has_trait = compassionate
		has_trait = patient
		has_trait = forgiving
	}
	# Is the eldest heir of root.
	save_temporary_scope_as = eldest_heir_temp
	root = {
		player_heir_position = {
			value = 0
			target = scope:eldest_heir_temp
		}
	}
}

scripted_trigger court_2201_valid_younger_heir_child_trigger = {
	# Basic checks.
	court_2201_valid_basic_heir_child_trigger = yes
	# Is getting *some* kind of inheritance through partition.
	any_heir_title = {
		exists = holder
		holder = root
	}
	# Is *NOT* the eldest heir of root.
	save_temporary_scope_as = younger_heir_temp
	root = {
		player_heir_position = {
			value >= 1
			target = scope:younger_heir_temp
		}
	}
}

court.2201 = {
	type = court_event
	title = court.2201.t
	desc = court.2201.desc
	theme = court

	cooldown = { years = 10 }

	court_scene = {
		button_position_character = scope:eldest_heir
		roles = {
			scope:eldest_heir = {
				group = event_group
				animation = anger
			}
			scope:younger_heir = {
				group = event_group
				animation = dismissal
			}
		}
	}

	trigger = {
		# DLC check.
		has_royal_court = yes
		# Standard checks.
		is_available_at_peace_adult = yes
		is_landed = yes
		# Is using a form of partition succession.
		has_partition_succession_realm_law_trigger = yes
		# Has a suitable eldest heir/child.
		any_player_heir = {
			court_2201_valid_eldest_heir_child_trigger = yes
			has_court_event_flag = no
		}
		# Has a suitable younger heir/child.
		any_player_heir = {
			court_2201_valid_younger_heir_child_trigger = yes
			has_court_event_flag = no
		}
	}

	weight_multiplier = {
		base = 1
		
		# Court weightings.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_administrative }
	}

	immediate = {
		# Grab our heirs.
		random_player_heir = {
			limit = { court_2201_valid_eldest_heir_child_trigger = yes }
			save_scope_as = eldest_heir
			court_event_character_flag_effect = yes
		}
		random_player_heir = {
			limit = { court_2201_valid_younger_heir_child_trigger = yes }
			save_scope_as = younger_heir
			court_event_character_flag_effect = yes
		}
	}

	# Entitled to more, scope:eldest_heir? How about *nothing*!
	option = {
		name = court.2201.a

		# Disinherit scope:eldest_heir for free.
		scope:eldest_heir = {
			disinherit_effect = { DISINHERITOR = root }
		}
		# Friendship & hook with scope:younger_heir.
		progress_towards_friend_effect = {
			REASON = friend_disinherited_other_child
			CHARACTER = scope:younger_heir
			OPINION = 50
		}
		if = {
			limit = {
				can_add_hook = {
					target = scope:younger_heir
					type = favor_hook
				}
			}
			add_hook = {
				target = scope:younger_heir
				type = favor_hook
			}
		}
		# Insta-rivalry with scope:eldest_heir and between the siblings.
		scope:eldest_heir = {
			if = {
				limit = {
					can_set_relation_rival_even_if_teen_trigger = { CHARACTER = root }
				}
				set_relation_rival = {
					target = root
					reason = rival_parent_rivalry
				}
			}
			if = {
				limit = {
					can_set_relation_nemesis_even_if_teen_trigger = { CHARACTER = scope:younger_heir }
				}
				set_relation_nemesis = {
					reason = nemesis_parent_rivalry
					copy_reason = rival
					target = scope:younger_heir
				}
			}
			else_if = {
				limit = {
					can_set_relation_rival_even_if_teen_trigger = { CHARACTER = scope:younger_heir }
				}
				set_relation_rival = {
					target = scope:younger_heir
					reason = rival_inter_heir_rivalry
				}
			}
			else = {
				add_opinion = {
					target = scope:younger_heir
					modifier = hate_opinion
					opinion = -50
				}
				reverse_add_opinion = {
					target = scope:younger_heir
					modifier = hate_opinion
					opinion = -50
				}
			}
		}

		stress_impact = {
			vengeful = miniscule_stress_impact_loss
			arbitrary = miniscule_stress_impact_loss
			irritable = minor_stress_impact_loss
			forgiving = medium_stress_impact_gain
			just = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_vengefulness = 0.5
				ai_compassion = 0.25
			}
		}
	}
	
	# Sad to say, scope:younger_heir, GetSheHe makes a good point.
	option = {
		name = court.2201.b

		# Disinherit scope:younger_heir for free.
		scope:younger_heir = {
			disinherit_effect = { DISINHERITOR = root }
		}
		# Friendship & hook with scope:eldest_heir.
		progress_towards_friend_effect = {
			REASON = friend_disinherited_other_child
			CHARACTER = scope:eldest_heir
			OPINION = 50
		}
		if = {
			limit = {
				can_add_hook = {
					target = scope:eldest_heir
					type = favor_hook
				}
			}
			add_hook = {
				target = scope:eldest_heir
				type = favor_hook
			}
		}
		# Insta-rivalry with scope:younger_heir and between the siblings.
		scope:younger_heir = {
			if = {
				limit = {
					can_set_relation_rival_even_if_teen_trigger = { CHARACTER = root }
				}
				set_relation_rival = {
					target = root
					reason = rival_parent_rivalry
				}
			}
			if = {
				limit = {
					can_set_relation_nemesis_even_if_teen_trigger = { CHARACTER = scope:eldest_heir }
				}
				set_relation_nemesis = {
					reason = nemesis_parent_rivalry
					copy_reason = rival
					target = scope:eldest_heir
				}
			}
			else_if = {
				limit = {
					can_set_relation_rival_even_if_teen_trigger = { CHARACTER = scope:eldest_heir }
				}
				set_relation_rival = {
					target = scope:eldest_heir
					reason = rival_inter_heir_rivalry
				}
			}
			else = {
				add_opinion = {
					target = scope:eldest_heir
					modifier = hate_opinion
					opinion = -50
				}
				reverse_add_opinion = {
					target = scope:eldest_heir
					modifier = hate_opinion
					opinion = -50
				}
			}
		}

		stress_impact = {
			vengeful = miniscule_stress_impact_loss
			arbitrary = miniscule_stress_impact_loss
			irritable = minor_stress_impact_loss
			forgiving = medium_stress_impact_gain
			just = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 0.25
				ai_compassion = -0.5
			}
		}
	}

	# They're siblings, I'm sure they'll get along fine without me.
	option = {
		name = court.2201.c
		trigger = {
			NOT = { has_trait = family_first }
		}

		# Hidden potential rivalry in the future.
		hidden_effect = {
			scope:eldest_heir = {
				progress_towards_rival_effect = {
					CHARACTER = scope:younger_heir
					REASON = rival_argued_succession
					OPINION = -20
				}
			}
		}
		# And some diplomacy lifestyle XP for your wisdom.
		add_diplomacy_lifestyle_xp = medium_lifestyle_xp

		stress_impact = {
			trusting = miniscule_stress_impact_loss
			lazy = miniscule_stress_impact_loss
			arbitrary = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_sociability = -0.25
				ai_rationality = -0.25
				ai_energy = -0.5
			}
		}
	}

	# Let me tell you two about *family*...
	option = {
		name = court.2201.d
		trigger = { has_trait = family_first }
		trait = family_first

		# Try to step friendship between the characters.
		scope:eldest_heir = {
			root = { save_scope_as = relationship_reason_involved_character }
			progress_towards_friend_effect = {
				REASON = friend_parent_brought_together
				CHARACTER = scope:younger_heir
				OPINION = 50
			}
			clear_saved_scope = relationship_reason_involved_character
		}
		# And some diplomacy lifestyle XP for your *actual* wisdom.
		add_diplomacy_lifestyle_xp = major_lifestyle_xp

		stress_impact = {
			diligent = miniscule_stress_impact_loss
			gregarious = miniscule_stress_impact_loss
			lazy = medium_stress_impact_gain
			trusting = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_energy = 0.5
				ai_sociability = 0.25
				ai_rationality = 0.25
			}
		}
	}
	after = {
		scope:younger_heir = {
			clear_court_event_participation = yes
		}
		scope:eldest_heir = {
			clear_court_event_participation = yes
		}
	}
}

	##################################################
	# FOREIGN GUESTS SUB-SECTION

##################################################
# Second-Hand Glamour
# by Ewan Cowhig Croft
# 2401 - 2410
##################################################

scripted_trigger court_2401_valid_neighbouring_ruler_trigger = {
	# Isn't at war with root.
	NOT = {
		any_war_enemy = { this = root }
	}
	# Has a royal court, and therefore amenities.
	has_royal_court = yes
	# Is more fashionable.
	amenity_level = {
		type = court_fashion
		value > medium_amenity_level
	}
}

scripted_trigger court_2401_valid_scope_seller_trigger = {
	OR = {
		has_personality_malicious_trigger = yes
		has_trait_dominant_trigger = yes
	}
}

scripted_trigger court_2401_valid_scope_buyer_trigger = {
	court_2401_valid_scope_seller_trigger = no
	OR = {
		has_trait_submissive_trigger = yes
		has_trait_extroverted_trigger = yes
		has_trait_emotional_trigger = yes
	}
}

scripted_trigger court_2401_valid_courtiers_trigger = {
	is_available_ai_adult = yes
}

court.2401 = {
	type = court_event
	title = court.2401.t
	desc = court.2401.desc
	theme = court

	cooldown = { years = 10 }

	court_scene = {
		button_position_character = scope:seller
		roles = {
			scope:seller = {
				group = event_group
				animation = flirtation
			}
			scope:buyer = {
				group = event_group
				animation = worry
			}
		}
	}

	trigger = {
		# DLC check.
		has_royal_court = yes
		# Standard checks.
		is_available_adult = yes
		is_landed = yes
		# Low fashion amenity.
		amenity_level = {
			type = court_fashion
			value <= medium_amenity_level
		}
		# Any neighbour with a better fashion amenity.
		any_neighboring_and_across_water_realm_same_rank_owner = { court_2401_valid_neighbouring_ruler_trigger = yes }
		# Available courtier to become scope:seller.
		any_courtier = {
			court_2401_valid_scope_seller_trigger = yes
			court_2401_valid_courtiers_trigger = yes
			has_court_event_flag = no
		}
		# Available courtier to become scope:buyer.
		any_courtier = {
			court_2401_valid_scope_buyer_trigger = yes
			court_2401_valid_courtiers_trigger = yes
			has_court_event_flag = no	
		}
	}

	weight_multiplier = {
		base = 1
		
		# Court weightings.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_diplomatic }
	}

	immediate = {
		# Grab an appropriate neighbouring realm.
		random_neighboring_and_across_water_realm_same_rank_owner = {
			limit = { court_2401_valid_neighbouring_ruler_trigger = yes }
			save_scope_as = grander_ruler
		}
		# Grab a scope:seller.
		random_courtier = {
			limit = {
				court_2401_valid_scope_seller_trigger = yes
				court_2401_valid_courtiers_trigger = yes
			}
			weight = {
				base = 1
				is_of_minor_interest_to_weight_up_modifier = { CHARACTER = root }
				is_of_major_interest_to_weight_up_modifier = { CHARACTER = root }
			}
			save_scope_as = seller
			court_event_character_flag_effect = yes
		}
		# Grab a scope:buyer.
		random_courtier = {
			limit = {
				court_2401_valid_scope_buyer_trigger = yes
				court_2401_valid_courtiers_trigger = yes
			}
			weight = {
				base = 1
				is_of_major_interest_to_weight_up_modifier = { CHARACTER = root }
				is_of_minor_interest_to_weight_up_modifier = { CHARACTER = root }
			}
			save_scope_as = buyer
			court_event_character_flag_effect = yes
		}
	}

	# My, those *do* look enticing...
	option = {
		name = court.2401.a
		trigger = {
			can_make_expensive_purchase_trigger = { PRICE = medium_gold_value }
		}

		# Pay gold to copy the fashions.
		pay_short_term_gold = {
			target = scope:seller
			gold = medium_gold_value
		}
		# Gain some corresponding CGV.
		change_current_court_grandeur = major_court_grandeur_gain
		# And opinion.
		reverse_add_opinion = {
			target = scope:seller
			modifier = pleased_opinion
			opinion = 30
		}
		# But lose a little prestige.
		add_prestige = minor_prestige_loss

		stress_impact = {
			humble = miniscule_stress_impact_loss
			fickle = miniscule_stress_impact_loss
			arrogant = medium_stress_impact_gain
			stubborn = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_sociability = 0.5
				ai_vengefulness = -0.25
			}
		}
	}
	
	# Get those out of here! We don't need foreign nonsense in my court!
	option = {
		name = court.2401.b

		# Gain prestige!
		add_prestige = medium_prestige_gain
		# And respect with scope:buyer!
		reverse_add_opinion = {
			target = scope:buyer
			modifier = respect_opinion
			opinion = 30
		}
		# But upset scope:seller & scope:grander_ruler.
		reverse_add_opinion = {
			target = scope:seller
			modifier = angry_opinion
			opinion = -30
		}
		reverse_add_opinion = {
			target = scope:grander_ruler
			modifier = insult_opinion
			opinion = -10
		}
		#And loss a little CGV.
		change_current_court_grandeur = minor_court_grandeur_loss

		stress_impact = {
			arrogant = miniscule_stress_impact_loss
			stubborn = miniscule_stress_impact_loss
			humble = medium_stress_impact_gain
			fickle = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_vengefulness = 0.5
				ai_sociability = -0.25
			}
		}
	}
	
	# Who cares what people wear?
	option = {
		name = court.2401.c

		# Gain a little consolation prestige.
		add_prestige = miniscule_prestige_gain

		stress_impact = {
			lazy = miniscule_stress_impact_loss
			shy = minor_stress_impact_loss
			gregarious = minor_stress_impact_gain
			arrogant = medium_stress_impact_gain
			stubborn = medium_stress_impact_gain
			humble = medium_stress_impact_gain
			fickle = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_sociability = -0.25
				ai_vengefulness = -0.25
				ai_energy = -0.5
			}
		}
	}
	after = {
		scope:buyer = {
			clear_court_event_participation = yes
		}
		scope:seller = {
			clear_court_event_participation = yes
		}
	}
}

##################################################
# Labyrinthine Halls
# by Ewan Cowhig Croft
# 2411 - 2420
##################################################

scripted_trigger court_2411_valid_guest_to_get_lost_trigger = {
	# Make sure they're around.
	is_available_ai_adult = yes
}

court.2411 = {
	type = court_event
	title = court.2411.t
	desc = court.2411.desc
	theme = court

	cooldown = { years = 25 }

	court_scene = {
		button_position_character = scope:lost_guest
		roles = {
			scope:lost_guest = {
				group = event_group
				animation = fear
			}
			root = {
				group = event_group
				animation = shock
			}
		}
	}

	trigger = {
		# DLC check.
		has_royal_court = yes
		# Standard checks.
		is_available_at_peace_adult = yes
		is_landed = yes
		has_court_event_flag = no
		# Must have very high lodgings, but comparatively few servants.
		OR = {
			# Bigger quarters require more servants.
			AND = {
				amenity_level = {
					type = court_lodging_standards
					value >= max_amenity_level
				}
				amenity_level = {
					type = court_servants
					value <= medium_amenity_level
				}
			}
			# And the inverse.
			AND = {
				amenity_level = {
					type = court_lodging_standards
					value >= very_high_amenity_level
				}
				amenity_level = {
					type = court_servants
					value <= low_amenity_level
				}
			}
		}
		# And a valid guest who may have gotten lost and died.
		any_pool_guest = {
			court_2411_valid_guest_to_get_lost_trigger = yes
			has_court_event_flag = no
		}
	}

	weight_multiplier = {
		base = 1
		
		# Court weightings.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_intrigue }
	}

	immediate = {
		court_event_character_flag_effect = yes
		# Designate an appropriate pool guest.
		random_pool_guest = {
			limit = { court_2411_valid_guest_to_get_lost_trigger = yes }
			weight = {
				base = 1
				is_of_minor_interest_to_weight_up_modifier = { CHARACTER = root }
				is_of_major_interest_to_weight_up_modifier = { CHARACTER = root }

				# Weight up stubborn characters.
				modifier = {
					add = 0.25
					has_trait = stubborn
				}
				# Weight up wrathful characters who get too angry to track where they're going.
				modifier = {
					add = 0.25
					has_trait = wrathful
				}
			}
			save_scope_as = lost_guest
			court_event_character_flag_effect = yes
		}
		# ... aaaaaand stress 'em out.
		scope:lost_guest = { add_stress = massive_stress_gain }
	}

	# By [HighGodName], let me show you the way!
	option = {
		name = court.2411.a
		
		# Gain opinion with scope:lost_guest.
		reverse_add_opinion = {
			target = scope:lost_guest
			modifier = grateful_opinion
			opinion = 30
		}
		# Gain some prestige.
		add_prestige = minor_prestige_gain

		stress_impact = {
			compassionate = miniscule_stress_impact_loss
			callous = medium_stress_impact_gain
			sadistic = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 0.5
				ai_sociability = 0.25
			}
		}
	}
	
	# How in the... How *stupid* can you possibly be?
	option = {
		name = court.2411.b

		# Lose opinion with scope:lost_guest.
		reverse_add_opinion = {
			target = scope:lost_guest
			modifier = respect_opinion
			opinion = -50
		}
		# Gain a little dread.
		add_dread = minor_dread_gain

		stress_impact = {
			callous = miniscule_stress_impact_loss
			sadistic = miniscule_stress_impact_loss
			forgiving = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_sociability = -0.25
				ai_compassion = -0.5
			}
		}
	}
	
	# What a honeycomb of halls I keep...
	option = {
		name = court.2411.c

		# Guests and courtiers lose some respect for you.
		every_courtier_or_guest = {
			limit = { is_available_ai_adult = yes }
			custom = all_courtiers_and_guests
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = -20
			}
		}
		# But you _do_ gain a little CGV out of this.
		change_current_court_grandeur = medium_court_grandeur_gain

		stress_impact = {
			arrogant = miniscule_stress_impact_loss
			callous = miniscule_stress_impact_loss
			sadistic = miniscule_stress_impact_loss
			humble = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 0.5
				ai_compassion = -0.75
			}
		}
	}

	after = {
		scope:lost_guest = {
			clear_court_event_participation = yes
		}
		clear_court_event_participation = yes
	}
}

	##################################################
	# RELATIONSHIPS SUB-SECTION

	##################################################
	# PERSONAL SUB-SECTION









##################################################
# Bianca

##################################################
# 3000 - 3009	Distrust of Friendship
# 3010 - 3019	Inspired Work
# 3020 - 3029	A Foul Smell
# 3030 - 3039	Lady-in-Waiting Events
# 3040 - 3049	Homesick MotherFather
# 3050 - 3059	Letter of Defamation
# 3060 - 3069	A Feline Hunter
# 3070 - 3079	The Unknown TitleTier
##################################################

#####################################
# Sus about a budding friend(?)ship	#
# by Bianca Savazzi					#
# 3000								#
#####################################

scripted_trigger court_3000_valid_courtier_trigger = {
	basic_is_available_ai = yes
	is_adult = yes
	is_close_family_or_spouse_of_root_trigger = yes
}
scripted_trigger court_3000_valid_guest_trigger = {
	exists = $FAMILY_MEMBER$
	basic_is_available_ai = yes
	is_adult = yes
	NOR = {	
		has_relation_rival = $FAMILY_MEMBER$
		has_relation_potential_rival = $FAMILY_MEMBER$
		has_relation_nemesis = $FAMILY_MEMBER$
		has_relation_best_friend = $FAMILY_MEMBER$
		has_relation_soulmate = $FAMILY_MEMBER$
	}
	opinion = {
		target = $FAMILY_MEMBER$
		value >= 10
	}
}
scripted_effect court_3000_budding_friendship_effect = {
	reverse_add_opinion = {
		target = scope:family_member
		modifier = friendly_interaction
		opinion = 30
	}
	add_opinion = {
		target = scope:family_member
		modifier = friendly_interaction
		opinion = 30
	}

	if = {
		limit = {
			NOT = { has_relation_potential_friend = scope:family_member }
		}
		root = {
			send_interface_toast = {
				title = court.3000.c.tt.success
				left_icon = scope:family_member
				right_icon = scope:foreign_guest
				scope:foreign_guest = { set_relation_potential_friend = scope:family_member }
			}
		}
	}
	else_if = {
		limit = {
			NOT = { has_relation_friend = scope:family_member }
		}
		root = {
			send_interface_toast = {
				title = court.3000.c.tt.success
				left_icon = scope:family_member
				right_icon = scope:foreign_guest
				scope:foreign_guest = { set_relation_friend = { reason = friend_bonding_at_court target = scope:family_member involved_character = root } }
			}
		}
	}
	else = {
		root = {
			send_interface_toast = {
				title = court.3000.c.tt.success
				left_icon = scope:family_member
				right_icon = scope:foreign_guest
				show_as_tooltip = {
					reverse_add_opinion = {
						target = scope:family_member
						modifier = friendly_interaction
						opinion = 30
					}
					add_opinion = {
						target = scope:family_member
						modifier = friendly_interaction
						opinion = 30
					}
				}
			}
		}
	}		
}
scripted_effect court_3000_budding_romance_effect = {
	random = {
		chance = 40 # We don't want it to be 100% for them to become lovers
		if = {
			limit = {
				can_set_relation_potential_lover_trigger = { CHARACTER =  scope:family_member }
				scope:family_member = { might_cheat_on_partner_trigger = { PARTNER = root } }
			}
			set_relation_potential_lover = scope:family_member
		}
		else_if = {
			limit = {
				can_set_relation_lover_trigger = { CHARACTER =  scope:family_member }
				scope:family_member = { might_cheat_on_partner_trigger = { PARTNER = root } }
			}
			set_random_lover_reason = { TARGET = scope:family_member }
		}
	}
}
scripted_effect court_3000_blossoming_friendship_effect = {
	reverse_add_opinion = {
		target = scope:family_member
		modifier = friendly_interaction
		opinion = 40
	}
	add_opinion = {
		target = scope:family_member
		modifier = friendly_interaction
		opinion = 40
	}

	if = {
		limit = {
			NOT = { has_relation_friend = scope:family_member }
		}
		root = {
			send_interface_toast = {
				title = court.3000.c.tt.success
				left_icon = scope:family_member
				right_icon = scope:foreign_guest
				scope:foreign_guest = { set_relation_friend = { reason = friend_approves_methods target = scope:family_member } }
			}
		}
	}
	else_if = {
		limit = {
			NOT = { has_relation_best_friend = scope:family_member }
		}
		root = {
			send_interface_toast = {
				title = court.3000.c.tt.success
				left_icon = scope:family_member
				right_icon = scope:foreign_guest
				scope:foreign_guest = {
					set_relation_best_friend = {
						reason = best_friend_encouraged_bonding_at_court
						copy_reason = friend
						target = scope:family_member
						involved_character = root
					}
				}
			}
		}
	}
	else = {
		root = {
			send_interface_toast = {
				title = court.3000.c.tt.success
				left_icon = scope:family_member
				right_icon = scope:foreign_guest
				show_as_tooltip = {
					reverse_add_opinion = {
						target = scope:family_member
						modifier = friendly_interaction
						opinion = 40
					}
					add_opinion = {
						target = scope:family_member
						modifier = friendly_interaction
						opinion = 40
					}
				}
			}
		}
	}	
}
scripted_effect court_3000_blossoming_romance_effect = {
	random = {
		chance = 70 # Gotta keep the players in suspense and paranoid even if they look at the script
		if = {
			limit = {
				can_set_relation_lover_trigger = { CHARACTER = scope:family_member }
				scope:family_member = { might_cheat_on_partner_trigger = { PARTNER = root } }
			}
			set_random_lover_reason = { TARGET = scope:family_member }
		}
		else_if = {
			limit = {
				can_set_relation_soulmate_trigger = { CHARACTER = scope:family_member }
				scope:family_member = { might_cheat_on_partner_trigger = { PARTNER = root } }
			}
			set_relation_soulmate = { reason = soulmate_love_during_visit_at_court copy_reason = lover target = scope:family_member }
		}
	}
}

# You're sus (and jealous) that a foreign diplomat is all buddy-buddy with your family member
court.3000 = {
	type = court_event
	title = court.3000.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { 
					OR = {
						has_trait = calm
						has_trait = trusting
						has_trait = humble
						has_trait = compassionate
					}
				} 
				desc = court.3000.desc.opening.trustful
			}
			desc = court.3000.desc.opening
		}
 		desc = court.3000.desc
	}
	theme = court

	court_scene = {
		button_position_character = scope:foreign_guest
		roles = {
			scope:foreign_guest = {
				group = event_group
				animation = admiration
			}
			scope:family_member = {
				group = event_group
				animation = happiness
			}
		}
	}
	
	# More likely to trigger if you are a distrustful person 
	weight_multiplier = {
		base = 1
		modifier = { 
			add = 0.5
			has_trait = paranoid
		}
		modifier = { 
			add = 0.5
			has_trait = callous
		}
		modifier = { 
			add = 0.5
			has_trait = arrogant
		}
		modifier = { 
			add = 0.5
			has_trait = cynical
		}

		# Court weightings.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_intrigue }
	}

	trigger = {
		any_courtier = {
			court_3000_valid_courtier_trigger = yes

			save_temporary_scope_as = family_member_temp
			# Break into a sub-block so we can keep the temporary scope.
			root = {
				any_pool_guest = {
					court_3000_valid_guest_trigger = { FAMILY_MEMBER = scope:family_member_temp }
					has_court_event_flag = no
				}
			}
			has_court_event_flag = no
		}
		age >= 14
		NOT = { has_character_flag = court_3000_distrust_of_friendship }
	}

	immediate = {
		random_courtier = {
			limit = {
				court_3000_valid_courtier_trigger = yes
				save_temporary_scope_as = family_member_temp
				
				root = {
					any_pool_guest = {
						court_3000_valid_guest_trigger = { FAMILY_MEMBER = scope:family_member_temp }
					}
				}
			}
			save_scope_as = family_member
			court_event_character_flag_effect = yes
		}

		random_pool_guest = {
			limit = {
				court_3000_valid_guest_trigger = { FAMILY_MEMBER = scope:family_member }
			}
			save_scope_as = foreign_guest
			court_event_character_flag_effect = yes
		}
	}

	# Option A: Stop them
	option = { 
		name = court.3000.a
		reverse_add_opinion = {
			target = scope:foreign_guest
			modifier = rude_opinion
			opinion = -10
		}
		reverse_add_opinion = {
			target = scope:family_member
			modifier = rude_opinion
			opinion = -10
		}

		random_list = {
			50 = {
				modifier = {
					add = 15
					has_trait = family_first
				}
				modifier = {
					add = 15
					intrigue >= high_skill_rating
				}
				modifier = {
					add = 15
					dread >= medium_dread
				}
				modifier = {
					add = 15
					dread >= high_dread
				}

				desc = court.3000.a.tt.success

				send_interface_toast = {
					title = court.3000.a.tt.success
					left_icon = scope:family_member
					right_icon = scope:foreign_guest
					custom_tooltip = court.3000.neutral_outcome
				}
			}
			50 = {
				modifier = {
					add = 5
					intrigue <= medium_skill_rating
				}
				modifier = {
					add = 15
					intrigue <= low_skill_rating
				}
				modifier = {
					add = 10
					dread >= low_dread
				}
				modifier = {
					add = 10
					reverse_opinion = {
						target = scope:foreign_guest
						value < -1
					}
				}
				modifier = {
					add = 10
					reverse_opinion = {
						target = scope:family_member
						value < -1
					}
				}
				modifier = {
					add = 10
					scope:foreign_guest = {
						opinion = {
							target = scope:family_member
							value > 20
						}
					}
				}
				modifier = {
					add = 10
					scope:family_member = {
						opinion = {
							target = scope:foreign_guest
							value > 20
						}
					}
				}
				modifier = {
					add = 20
					has_relation_rival = scope:foreign_guest
				}
				modifier = {
					add = 20
					has_relation_rival = scope:family_member
				}

				desc = court.3000.a.tt.failure
				custom_tooltip = court.3000.friendly_outcome

				hidden_effect = {
					scope:foreign_guest = {	
						court_3000_budding_romance_effect = yes
						court_3000_budding_friendship_effect = yes
					}
				}
			}
		}
	}

	# Option B: Encourage them
	option = {
		name = court.3000.b
			
		random_list = {
			50 = {
				modifier = {
					add = 15
					has_trait = diplomat
				}
				modifier = {
					add = 15
					has_trait = gregarious
				}
				modifier = {
					add = 15
					diplomacy > high_skill_rating
				}
				modifier = {
					add = 10
					scope:foreign_guest = {
						opinion = {
							target = scope:family_member
							value > 20
						}
					}
				}
				modifier = {
					add = 10
					scope:family_member = {
						opinion = {
							target = scope:foreign_guest
							value > 20
						}
					}
				}
				modifier = {
					add = 10
					reverse_opinion = {
						target = scope:foreign_guest
						value > 20
					}
				}
				modifier = {
					add = 10
					reverse_opinion = {
						target = scope:family_member
						value > 20
					}
				}

				desc = court.3000.b.tt.success
				custom_tooltip = court.3000.better_friends_outcome
				reverse_add_opinion = {
					target = scope:foreign_guest
					modifier = friendliness_opinion
					opinion = 20
				}
				reverse_add_opinion = {
					target = scope:family_member
					modifier = friendliness_opinion
					opinion = 20
				}
				hidden_effect = {
					scope:foreign_guest = {	
						court_3000_blossoming_romance_effect = yes
						court_3000_blossoming_friendship_effect = yes
					}
				}
			}
			50 = {
				modifier = {
					add = 5
					diplomacy <= medium_skill_rating
				}
				modifier = {
					add = 15
					diplomacy <= low_skill_rating
				}
				modifier = {
					add = 10
					reverse_opinion = {
						target = scope:foreign_guest
						value < -1
					}
				}
				modifier = {
					add = 10
					reverse_opinion = {
						target = scope:family_member
						value < -1
					}
				}
				modifier = {
					add = 20
					has_relation_rival = scope:foreign_guest
				}
				modifier = {
					add = 20
					has_relation_rival = scope:family_member
				}
				desc = court.3000.b.tt.failure
				reverse_add_opinion = {
					target = scope:foreign_guest
					modifier = rude_opinion
					opinion = -20
				}
				reverse_add_opinion = {
					target = scope:family_member
					modifier = rude_opinion
					opinion = -20
				}
				send_interface_toast = {
					title = court.3000.a.tt.success
					left_icon = scope:family_member
					right_icon = scope:foreign_guest
					custom_tooltip = court.3000.neutral_outcome
				}
			}
		}
	}
	
	# Option C: Let them be
	option = {
		name = court.3000.c
		
		random_list = {
			33 = {
				desc = court.3000.c.tt.success
				custom_tooltip = court.3000.better_friends_outcome
				hidden_effect = {
					scope:foreign_guest = {	
						court_3000_blossoming_romance_effect = yes
						court_3000_blossoming_friendship_effect = yes
					}
				}
			}
			33 = {
				desc = court.3000.c.tt.neutral
				custom_tooltip = court.3000.friendly_outcome
				hidden_effect = {
					scope:foreign_guest = {	
						court_3000_budding_romance_effect = yes
						court_3000_budding_friendship_effect = yes
					}
				}
			}
			33 = {
				desc = court.3000.a.tt.success
				send_interface_toast = {
					title = court.3000.a.tt.success
					left_icon = scope:family_member
					right_icon = scope:foreign_guest
					custom_tooltip = court.3000.neutral_outcome
				}
			}
		}			
	}
	# Option D: Toss out the foreigner but lose CGV
	option = {
		name = court.3000.d
		stress_impact = {
			arbitrary = medium_stress_impact_loss
			callous = minor_stress_impact_loss
			generous = medium_stress_impact_gain
		}

		add_character_modifier = {
			modifier = inhospitable_court
			years = 5
		}
		scope:foreign_guest = {
			add_opinion = {
				modifier = kicked_out_opinion
				target = root
				opinion = -15
			}
		}
		remove_courtier_or_guest = scope:foreign_guest

		change_current_court_grandeur = minor_court_grandeur_loss

		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = 5
				ai_vengefulness = 5
				ai_honor = -2
				ai_rationality = 5
			}
		}
	}

	after = {
		add_character_flag = {
			flag = court_3000_distrust_of_friendship
			years = 5
		}
		scope:foreign_guest = {
			clear_court_event_participation = yes
		}
		scope:family_member = {
			clear_court_event_participation = yes
		}
	}
}

#####################################
# A courtier's inspired work		#
# by Bianca Savazzi					#
# 3010								#
#####################################

scripted_effect court_3010_inspired_work_neutral_toast_effect = {
	hidden_effect = { 
		send_interface_toast = {
			title = court.3010.t
			right_icon = scope:inspired_writer
			custom_tooltip = court.3010.c.neutral
		}
	}
}
scripted_effect court_3010_inspired_work_stress_toast_effect = {
	if = {
		limit = {
			OR = {
				has_trait = arrogant
				has_trait = wrathful
				has_trait = impatient
				has_trait = sadistic
			}
		}
		stress_impact = {
			arrogant = medium_stress_impact_gain
			wrathful = medium_stress_impact_gain
			impatient = medium_stress_impact_gain
			sadistic = medium_stress_impact_gain
		}
	}
	else = { add_stress = minor_stress_gain }
	
	hidden_effect = {
		root = { 
			send_interface_toast = {
				title = court.3010.t
				right_icon = scope:inspired_writer
				custom_tooltip = court.3010.c.stress
				show_as_tooltip = {
					scope:inspired_writer = {
						if = {
							limit = {
								OR = {
									has_trait = arrogant
									has_trait = wrathful
									has_trait = impatient
									has_trait = sadistic
								}
							}
							stress_impact = {
								arrogant = major_stress_impact_gain
								wrathful = major_stress_impact_gain
								impatient = major_stress_impact_gain
								sadistic = major_stress_impact_gain
							}
						}
						else = { add_stress = medium_stress_gain }
					}
				}
			}
		}
	}
}
scripted_effect court_3010_inspired_work_depression_toast_effect = {
	scope:inspired_writer = {
		add_character_modifier = {
			modifier = mocked_for_creative_burst_roco_modifier
			years = 5
		}
	}
	hidden_effect = {
		root = {
			send_interface_toast = {
				title = court.3010.t
				right_icon = scope:inspired_writer
				custom_tooltip = court.3010.c.depression
				show_as_tooltip = {
					scope:inspired_writer = {
						add_character_modifier = {
							modifier = mocked_for_creative_burst_roco_modifier
							years = 5
						}
					}
				}
			}
		}
	}
}
scripted_trigger court_3010_inspired_work_courtier_trigger = {
	basic_is_available_ai = yes
	age >= 14
	trigger_if = {
		limit = { has_ep1_dlc_trigger = yes }
		NOT = { exists = scope:inspiration }
	}
	NOR = {	
		has_trait = blind
		has_relation_rival = root
		has_relation_potential_rival = root
		has_relation_nemesis = root
	}
}

# A courtier approaches you with their work of fiction
court.3010 = {
	type = court_event
	title = court.3010.t
	desc = {
		desc = court.3010.desc.opening
		first_valid = {
			triggered_desc = {
				trigger = { 
					OR = {
						scope:inspired_writer = {
							has_trait = shy
							has_trait = chaste
						}
					}
				} 
				desc = court.3010.desc.shy_or_chaste
			}
			triggered_desc = {
				trigger = { 
					scope:inspired_writer = { has_trait = lustful }
				}
				desc = court.3010.desc.lustful
			}
			triggered_desc = {
				trigger = { 
					scope:inspired_writer = { learning <= low_skill_rating }
				}
				desc = court.3010.desc.low_learning
			}
			triggered_desc = {
				trigger = { 
					scope:inspired_writer = { 
						OR = {
							has_trait = adventurer
							has_trait = pilgrim
						}
					}
				}
				desc = court.3010.desc.adventurer_or_pilgrim
			}
			triggered_desc = {
				trigger = { 
					scope:inspired_writer = { 
						has_trait = sadistic
					}
				}
				desc = court.3010.desc.sadistic
			}
			triggered_desc = {
				desc = court.3010.desc.generic_fallback
			}
		}
 		desc = court.3010.desc.ending
	}
	theme = court

	court_scene = {
		button_position_character = scope:inspired_writer
		roles = {
			scope:inspired_writer = {
				group = event_group
				animation = happiness
			}
			root = {
				group = event_group
				animation = personality_rational
			}
		}
	}
	
	# More likely to trigger if you are a writer yourself
	weight_multiplier = {
		base = 1
		modifier = { 
			add = 0.5
			has_trait = journaller
		}
		modifier = { 
			add = 0.5
			has_trait = scholar
		}

		# Court weightings.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_administrative }
	}

	trigger = {
		has_court_event_flag = no
		any_courtier = {
			court_3010_inspired_work_courtier_trigger = yes
			has_court_event_flag = no
		}

		age >= 14
		NOR = { 
			has_trait = blind 
			has_character_flag = court_3010_inspired_work 
		}

		OR = {
			any_courtier = {
				AND = {
					exists = var:created_artifact_type
					var:created_artifact_type = flag:book
					has_court_event_flag = no
				}
			}
		}
	}

	immediate = {
		court_event_character_flag_effect = yes
		random_courtier = {
			limit = {
				court_3010_inspired_work_courtier_trigger = yes
			}
			weight = {
				base = 1
				#More likely to pick a friend to up the stakes of the outcome
				modifier = { 
					add = 5
					has_relation_friend = root
				}
				modifier = { 
					add = 15
					has_relation_best_friend = root
				}
				#More likely to pick a writer as well
				modifier = { 
					add = 5
					has_trait = journaller
				}
				modifier = { 
					add = 5
					has_trait = scholar
				}
				modifier = { 
					add = 5
					has_trait = pensive
				}
			}
			save_scope_as = inspired_writer
			court_event_character_flag_effect = yes
		}
	}

	# Option A: Strongly encourage them to keep writing
	option = { 
		name = court.3010.a
		custom_tooltip = court.3010.a.tt
		scope:inspired_writer = {
			add_character_modifier = {
				modifier = creative_burst_roco_modifier
				years = 5
			}
		}
		hidden_effect = {
			trigger_event = {
				id = court.3011 # Courtier writes more stuff and shows it off once again
				days = { 20 40 }
			}
		}
		stress_impact = {
			arrogant = major_stress_impact_gain #What why are we complimenting others when we're superior? 
			sadistic = major_stress_impact_gain #Why are we not being mean?
			honest = major_stress_impact_gain #is this true though?

			base = medium_stress_impact_gain #expectations of you to read future manuscripts
		}
		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_compassion = 2
				ai_honor = 1
			}
		}
	}

	# Option B: Strongly discourage them to keep writing
	option = { 
		name = court.3010.b
		progress_towards_rival_effect = {
			CHARACTER = scope:inspired_writer
			REASON = rival_discouraged_writing
			OPINION = -25
		}

		scope:inspired_writer = {
			court_3010_inspired_work_depression_toast_effect = yes 
		}
		stress_impact = {
			compassionate = major_stress_impact_gain # :(
			honest = major_stress_impact_gain #is this true though?
		}
		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_compassion = -2
			}
		}
	}

	# Option C: You offer them feedback
	option = { 
		name = court.3010.c

		scope:inspired_writer = {
			random_list = {
				65 = {
					#They take the feedback into account to get better
					desc = court.3010.c.neutral
					root = {
						court_3010_inspired_work_neutral_toast_effect = yes
						add_learning_lifestyle_xp = minor_lifestyle_xp
						hidden_effect = {
							trigger_event = {
								id = court.3011 # Courtier writes more stuff and shows it off once again
								days = { 20 40 }
							}
						}
					}
				}
				35 = {
				# They're upset because they don't want to agree with the feedback
					modifier = {
						add = 5
						ai_compassion >= low_positive_compassion
					}
					modifier = {
						add = 5
						ai_compassion >= medium_positive_compassion
					}
					desc = court.3010.c.stress
					
					root = { 
						progress_towards_rival_effect = {
							CHARACTER = scope:inspired_writer
							REASON = rival_discouraged_writing
							OPINION = 0
						}
					}
				}
			}
		}
		stress_impact = {
			arrogant = medium_stress_impact_gain #What why are we complimenting others when we're superior? 
			sadistic = medium_stress_impact_gain #Why are we not being mean?
		}
		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_compassion = -1
				ai_honor = 2
			}
		}
	}

	after = {
		add_character_flag = {
			flag = court_3010_inspired_work
			years = 5
		}
		clear_court_event_participation = yes
		scope:inspired_writer = {
			clear_court_event_participation = yes
		}
	}
}

scripted_effect court_3011_inspired_work_random_outcome_effect = {
	random_list = {
		30 = {
			trigger = {
				has_ep1_dlc_trigger = yes
				scope:inspired_writer = { ep1_is_valid_character_for_inspiration_trigger = yes }				
			}
			modifier = {
				factor = 1.2
				has_trait = gregarious
			}
			custom_tooltip = court.3011.c.tt.gain_inspiration
			scope:inspired_writer = {
				create_inspiration = book_inspiration
			}
		}
		30 = {
			modifier = {
				factor = 2
				OR = {
					has_ep1_dlc_trigger = no
					scope:inspired_writer = { ep1_is_valid_character_for_inspiration_trigger = no }				
				}
			}
			modifier = {
				factor = 1.2
				has_trait = gregarious
			}
			scope:inspired_writer = {
				add_character_modifier = {
					modifier = trying_new_things_modifier
					years = 5
				}
			}
			custom_tooltip = court.3011.c.tt.stop
		}
		30 = {
			custom_tooltip = court.3011.c.tt.hurt
			reverse_add_opinion = {
				target = scope:inspired_writer
				modifier = insult_opinion
				opinion = -20
			}
		}
	}
}

# The inspired courtier returns with more fiction
court.3011 = {
	type = character_event
	title = court.3010.t
	desc = {
		desc = court.3011.desc.opening
		first_valid = {
			triggered_desc = {
				trigger = { 
					OR = {
						scope:inspired_writer = {
							has_trait = shy
							has_trait = chaste
						}
					}
				} 
				desc = court.3011.desc.shy_or_chaste
			}
			triggered_desc = {
				trigger = { 
					scope:inspired_writer = { has_trait = lustful }
				}
				desc = court.3011.desc.lustful
			}
			triggered_desc = {
				trigger = { 
					scope:inspired_writer = { learning <= low_skill_rating }
				}
				desc = court.3011.desc.low_learning
			}
			triggered_desc = {
				trigger = { 
					scope:inspired_writer = { 
						OR = {
							has_trait = adventurer
							has_trait = pilgrim
						}
					}
				}
				desc = court.3011.desc.adventurer_or_pilgrim
			}
			triggered_desc = {
				trigger = { 
					scope:inspired_writer = { 
						has_trait = sadistic
					}
				}
				desc = court.3011.desc.sadistic
			}
			triggered_desc = {
				desc = court.3011.desc.generic_fallback
			}
		}
 		desc = court.3011.desc.ending
	}
	theme = court
	left_portrait = {
		character = root
		animation = personality_rational
	}
	right_portrait = {
		character = scope:inspired_writer
		animation = happiness
	}
	
	trigger = {
		exists = scope:inspired_writer
		scope:inspired_writer = {
			court_3010_inspired_work_courtier_trigger = yes
		}

		NOT = { has_trait = blind }
	}

	# Option A: Encourage them to keep writing
	option = { 
		name = court.3011.a
		progress_towards_friend_effect = {
			REASON = friend_believed_in_my_writing
			CHARACTER = scope:inspired_writer
			OPINION = 20
		}
		scope:inspired_writer = {
			add_character_modifier = {
				modifier = found_their_focus_modifier
				years = 5
			}
		}
	}

	# Option B - Greg variant: Suggest that they write something else
	option = { 
		trigger = { has_trait = gregarious } 
		name = court.3011.b.gregarious
		trait = gregarious
		court_3011_inspired_work_random_outcome_effect = yes
	}

	# Option B - Normal variant: Suggest that they write something else
	option = { 
		trigger = { NOT = { has_trait = gregarious } }
		name = court.3011.b.blunt
		court_3011_inspired_work_random_outcome_effect = yes
	}

	# Option C: You tell them to stop
	option = { 
		name = court.3011.c
		custom_tooltip = court.3011.c.tt.hurt

		reverse_add_opinion = {
			target = scope:inspired_writer
			modifier = cruelty_opinion
			opinion = -20
		}
	}
}

#####################################
# Architectural improvements 3020
# and Latrine Disaster 3021
# and Guard Duty 3022
# based on event by Bianca Savazzi
#####################################

# works go out as planned
court.3020 = {
	type = court_event
	title = court.3020.t
	desc = {
		desc = court.3020.desc.opening
		first_valid = {
			triggered_desc = {
				trigger = {
					capital_province = {
						has_holding_type = castle_holding
					}
				}
				desc = court.3020.desc.castle
			}
			triggered_desc = {
				trigger = {
					capital_province = {
						has_holding_type = city_holding
					}
				}
				desc = court.3020.desc.city
			}
			triggered_desc = {
				trigger = {
					capital_province = {
						has_holding_type = church_holding
					}
				}
				desc = court.3020.desc.temple
			}
		}
		desc = court.3020.desc.ending
	}
	theme = court
	cooldown = { years = 50 }
	court_scene = {
		button_position_character = cp:councillor_steward
		roles = {
			cp:councillor_steward = {
				group = event_group
				animation = personality_content
			}
			root = {
				group = event_group
				animation = personality_rational
			}
		}
	}
	
	weight_multiplier = {
		base = 1

		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_administrative }
	}

	trigger = {
		exists = cp:councillor_steward
		cp:councillor_steward = {
			basic_is_available_ai = yes
			has_court_event_flag = no
		}

		exists = capital_province
		capital_province = {
			OR = {
				has_holding_type = castle_holding
				has_holding_type = city_holding
				has_holding_type = church_holding
			}
		}

		is_adult = yes
		has_court_event_flag = no
	}

	immediate = {
		court_event_character_flag_effect = yes
		cp:councillor_steward = {
		 	save_scope_as = improvement_steward
		 	court_event_character_flag_effect = yes
		}
		capital_province = {
			save_scope_as = capital
		}
		#Save Royal Architect
		if = {
			limit = {
				employs_court_position = royal_architect_court_position
				any_court_position_holder = {
					type = royal_architect_court_position
					is_physically_able = yes
				}
			}
			random_court_position_holder = {
				type = royal_architect_court_position
				limit = {
					is_physically_able = yes
				}
				save_scope_as = royal_architect
			}
		}
	}

	# Option A: carry on!
	option = { 
		name = court.3020.a
		
		change_current_court_grandeur = miniscule_court_grandeur_gain
		
		reverse_add_opinion = {
			target = scope:improvement_steward
			modifier = pleased_opinion
			opinion = 10
		}
		stress_impact = {
			lazy = medium_stress_impact_loss
			diligent = minor_stress_impact_gain
			ambitious = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
			modifier = {
				factor = 2
				OR = {
					has_trait = lazy
				}
			}
		}
	}

	# Option B: Personal oversight
	option = {
		name = court.3020.b
		duel = {
			skill = stewardship
			value = average_skill_rating
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 0.25
				}
				desc = court.3020.b.success
				root = {
					send_interface_toast = {
						title = court.3020.b.success
						change_current_court_grandeur = medium_court_grandeur_gain
					}
				}
			}
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -0.25
					min = -9
				}
				desc = court.3020.b.failure
				root = {
					send_interface_toast = {
						title = court.3020.b.failure
						change_current_court_grandeur = minor_court_grandeur_loss 
					}
				}
			}
		}
		

		stress_impact = {
			lazy = medium_stress_impact_gain
			diligent = minor_stress_impact_loss
			ambitious = minor_stress_impact_loss
			arrogant = minor_stress_impact_loss
		}
		ai_chance = {
			base = 30
		}
	}

	# Option C: My Royal Architect can improve this
	option = {
		name = court.3020.c

		trigger = {
			exists = scope:royal_architect
		}
		scope:royal_architect = {	
			duel = {
				skill = stewardship
				value = average_skill_rating
				8 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = 0.25
					}
					desc = court.3020.c.success
					root = {
						send_interface_toast = {
							title = court.3020.c.success
							change_current_court_grandeur = medium_court_grandeur_gain
						}
					}
				}
				12 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = -0.25
						min = -9
					}
					desc = court.3020.c.failure
					root = {
						send_interface_toast = {
							title = court.3020.c.failure

						}
					}
				}
			}
		}

		stress_impact = {
			trusting = minor_stress_impact_loss
		}
		ai_chance = {
			base = 50
		}
	}

	# Option D: Extra? Yoink
	option = {
		name = court.3020.d
		reverse_add_opinion = {
			target = scope:improvement_steward
			modifier = annoyed_opinion
			opinion = -10
		}
		stress_impact = {
			greedy = medium_stress_impact_loss
			generous = medium_stress_impact_gain
		}
		add_gold = minor_gold_value
		
		add_character_modifier = {
			modifier = greedy_court_roco_modifier
			years = 10
		}

		ai_chance = {
			base = 30
			modifier = {
				factor = 0
				has_trait = generous
			}
			modifier = {
				factor = 3
				has_trait = greedy
			}
		}
	}
	after = {
		clear_court_event_participation = yes
		scope:improvement_steward = {
			clear_court_event_participation = yes
		}
	}
}

# The floor collapses
court.3021 = {
	type = character_event
	title = court.3021.t
	desc = court.3021.desc
	theme = court
	left_portrait = {
		character = scope:courtier1
		animation = shock
	}
	right_portrait = {
		character = scope:courtier2
		animation = fear
	}
	 
	weight_multiplier = {
		base = 1
	}

	trigger = {
		any_courtier = {
			basic_is_available_ai = yes
			age > 14
			count >= 2
		}
		gold <=0
		root.stewardship <=8
		exists = capital_province
		NOT = { has_character_flag = court_3021_latrine_disaster }
		has_royal_court = yes
	}

	immediate = {
		capital_province = {
			save_scope_as = capital
		}

		random_courtier = {
			limit = {
				basic_is_available_ai = yes
				age > 14
			}
			weight = {
				modifier = {
					add = 15
					root = { is_of_major_or_minor_interest_trigger = { CHARACTER = prev } }	
				}
			}
			save_scope_as = courtier1
		}

		random_courtier = {
			limit = {
				basic_is_available_ai = yes
				age > 14
				NOT = { THIS = scope:courtier1 }
			}
			weight = { #More likely to pick one that that dislikes courtier 1
				opinion_modifier = {
					opinion_target = scope:courtier1
					multiplier = -0.5
				}
				modifier = {
					add = 15
					OR = {
						has_relation_rival = scope:courtier1
						has_relation_nemesis = scope:courtier1
						has_relation_potential_rival = scope:courtier1
					}
				}
				modifier = {
					add = 15
					root = { is_of_major_or_minor_interest_trigger = { CHARACTER = prev } }	
				}
			}
			save_scope_as = courtier2
		}
	}

	# Option A: Save courtier #1
	option = { 
		name = court.3021.a

		reverse_add_opinion = {
			target = scope:courtier1
			modifier = hero_of_the_moment_opinion
			opinion = 40
		}
		reverse_add_opinion = {
			target = scope:courtier2
			modifier = abandoned_me_opinion
			opinion = -40
		}

		random_list = {
			90 = {
				send_interface_toast = {
					title = court.3021.latrine_disaster
					left_icon = scope:courtier2
					scope:courtier2 = {
						add_character_modifier = {
							modifier = drenched_in_excrement_roco_modifier
							years = 2
						}
					}
				}
			}
			10 = {
				send_interface_toast = {
					title = court.3021.latrine_disaster
					left_icon = scope:courtier2
					scope:courtier2 = {
						death = { death_reason = death_drowned_in_excrement }
					}
				}
			}
		}
	}

	# Option B: Save courtier #2
	option = {
		name = court.3021.b

		reverse_add_opinion = {
			target = scope:courtier2
			modifier = hero_of_the_moment_opinion
			opinion = 40
		}	
		reverse_add_opinion = {
			target = scope:courtier1
			modifier = abandoned_me_opinion
			opinion = -40
		}

		random_list = {
			90 = {
				send_interface_toast = {
					title = court.3021.latrine_disaster
					left_icon = scope:courtier1
					scope:courtier1 = {
						add_character_modifier = {
							modifier = drenched_in_excrement_roco_modifier
							years = 2
						}
					}
				}
			}
			10 = {
				send_interface_toast = {
					title = court.3021.latrine_disaster
					left_icon = scope:courtier1
					scope:courtier1 = {
						death = { death_reason = death_drowned_in_excrement }
					}
				}
			}
		}
	}
	
	# Option C: Save neither
	option = {
		name = court.3021.c

		reverse_add_opinion = {
			target = scope:courtier1
			modifier = abandoned_me_opinion
			opinion = -30
		}
		reverse_add_opinion = {
			target = scope:courtier2
			modifier = abandoned_me_opinion
			opinion = -30
		}
		stress_impact = {
			trusting = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
		}

		random_list = {
			95 = {
				send_interface_toast = {
					title = court.3021.latrine_disaster
					left_icon = scope:courtier1
					right_icon = scope:courtier2
					scope:courtier1 = {
						add_character_modifier = {
							modifier = drenched_in_excrement_roco_modifier
							years = 2
						}
					}
					scope:courtier2 = {
						add_character_modifier = {
							modifier = drenched_in_excrement_roco_modifier
							years = 2
						}
					}
				}
			}
			5 = {
				send_interface_toast = {
					title = court.3021.latrine_disaster
					left_icon = scope:courtier1
					right_icon = scope:courtier2
					scope:courtier1 = {
						death = { death_reason = death_drowned_in_excrement }
					}
					scope:courtier2 = {
						death = { death_reason = death_drowned_in_excrement }
					}
				}
			}
		}
	}

	after = {
		add_character_flag = {
			flag = court_3021_latrine_disaster
			years = 5
		}
	}
}

scripted_trigger valid_decorator = {
	OR = {
		has_trait = fickle
		has_trait = arrogant
		has_trait = arbitrary
		has_focus = martial_chivalry_focus
	}
	NOR = {
		has_trait = shy
		has_trait = temperate
	}
}

#Guard duty
court.3022 = {
	type = court_event
	title = court.3022.t
	desc = court.3022.desc
	theme = court
	override_background = { reference = throne_room }
    cooldown = { years = 50 }
	court_scene = {
        button_position_character = scope:decorator
        roles = {
            scope:decorator = {
                group = event_group
                animation = personality_irrational
            }
            scope:serious_marshal = {
                group = event_group
                animation = disapproval
            }
        }
    }
	
	trigger = {
		exists = cp:councillor_marshal
		cp:councillor_marshal = {
			has_court_event_flag = no
			basic_is_available_ai = yes
			NOT = {
				has_trait = compassionate
			}
			save_temporary_scope_as = temp_marsh
		}
		any_knight = {
			NOT = { this = scope:temp_marsh }
			is_ai = yes
            has_court_event_flag = no		
			is_physically_able_adult = yes
			valid_decorator = yes
		}
	}
	 
	weight_multiplier = {
		base = 1
		
		# Court weightings.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_warlike }
	}

	immediate = {
		cp:councillor_marshal = {
			save_scope_as = serious_marshal
			court_event_character_flag_effect = yes
		}
		every_knight = {
    		limit = { 
				valid_decorator = yes
				NOT = { this = scope:serious_marshal }
				is_ai = yes
				has_court_event_flag = no		
				is_physically_able_adult = yes
			}
    		add_to_list = knight_list
    	}
 		ordered_in_list = {
 			list = knight_list
 			order_by = martial
 			save_scope_as = decorator
 			court_event_character_flag_effect = yes
 		}
	}

	# Option A: Keep status-quo
	option = { 
		name = court.3022.a
		add_dread = minor_dread_gain
		scope:serious_marshal = {
			add_opinion = {
				target = root
				opinion = -15
				modifier = disappointed_opinion
			}
		}
		scope:decorator = {
			add_opinion = {
				target = root
				opinion = -15
				modifier = disappointed_opinion
			}
		}
		stress_impact = {
			wrathful = medium_stress_impact_loss
			impatient = medium_stress_impact_loss
		}
		ai_chance = {
			base = 50
		}	
	}
	
	# Option B: Mediate and keep status quo
	option = { 
		name = court.3022.b
		duel = {
			skill = diplomacy
			value = average_skill_rating
			8 = {
				custom_tooltip = court.3022.b.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 0.5
				}
				hidden_effect = {
					send_interface_toast = {
						left_icon = scope:decorator
						title = court.3022.b.success
						add_prestige = medium_prestige_gain
						change_current_court_grandeur = medium_court_grandeur_gain
						scope:serious_marshal = {
							add_opinion = {
							target = root
							opinion = 15
							modifier = pleased_opinion
							}
						}
						scope:decorator = {
							add_opinion = {
							target = root
							opinion = 15
							modifier = pleased_opinion
							}
						}
					}
				}
			}
			12 = {
				custom_tooltip = court.3022.b.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -0.5
					min = -9
				}
				hidden_effect = {
					send_interface_toast = {
						left_icon = scope:decorator
						title = court.3022.b.failure
						add_prestige = minor_prestige_loss
						scope:serious_marshal = {
							add_opinion = {
							target = root
							opinion = -15
							modifier = disappointed_opinion
							}
						}
						scope:decorator = {
							add_opinion = {
							target = root
							opinion = -15
							modifier = disappointed_opinion
							}
						}
					}
				}
			}
		}
		stress_impact = {
			calm = medium_stress_impact_loss
			patient = medium_stress_impact_loss
			impatient = medium_stress_impact_gain
			wrathful = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_sociability = 0.5
			}
		}
	}
	
	# Option С: Agree with marshal
	
	option = {
		name = court.3022.c
		scope:decorator = {
			add_opinion = {
				target = root
				opinion = -30
				modifier = scared_opinion
			}
			add_opinion = {
				target = scope:serious_marshal
				opinion = -30
				modifier = scared_opinion
			}
		}
		scope:serious_marshal = {
			add_opinion = {
				target = root
				opinion = 30
				modifier = pleased_opinion
			}
			add_opinion = {
				target = scope:decorator
				opinion = -30
				modifier = disgusted_opinion
			}
		}
		scope:serious_marshal = {
			duel = {
				skill = martial
				value = average_skill_rating
				8 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = 0.5
					}
					desc = court.3022.c.success
					root = {
						send_interface_toast = {
							title = court.3022.c.success
							add_character_modifier = {
								modifier = disciplined_court_roco_modifier
								years = 10
							}
						}
					}
				}
				12 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = -0.5
						min = -9
					}
					desc = court.3022.c.failure
					root = {
						send_interface_toast = {
							title = court.3022.c.failure
							add_character_modifier = {
								modifier = brutish_court_roco_modifier
								years = 10
							}
						}
					}
				}
			}
		}
		stress_impact = {
			paranoid = medium_stress_impact_loss
			cynical = medium_stress_impact_loss
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_rationality = 0.2
			}
		}
	}
	
	# Option D: Allow decorator free reign
	
	option = {
		name = court.3022.d
		scope:decorator = {
			add_opinion = {
				target = root
				opinion = 30
				modifier = pleased_opinion
			}
			add_opinion = {
				target = scope:serious_marshal
				opinion = -30
				modifier = disgusted_opinion
			}
		}
		scope:serious_marshal = {
			add_opinion = {
				target = root
				opinion = -30
				modifier = disappointed_opinion
			}
			add_opinion = {
				target = scope:decorator
				opinion = -30
				modifier = disgusted_opinion
			}
		}
		scope:decorator = {
			duel = {
				skill = martial
				value = average_skill_rating
				8 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = 0.4
					}
					desc = court.3022.d.success
					root = {
						send_interface_toast = {
							title = court.3022.d.success
							add_character_modifier = {
								modifier = fancy_court_roco_modifier
								years = 10
							}
						}
					}
				}
				12 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = -0.4
						min = -9
					}
					desc = court.3022.d.failure
					root = {
						send_interface_toast = {
							title = court.3022.d.failure
							add_character_modifier = {
								modifier = fancish_court_roco_modifier
								years = 10
							}
						}
					}
				}
			}
		}
		stress_impact = {
			trusting = medium_stress_impact_loss
			cynical = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_rationality = -0.5
			}
		}
		
	}
	after = {
		clear_court_event_participation = yes
		scope:decorator = {
			clear_court_event_participation = yes
		}
		scope:serious_marshal = {
			clear_court_event_participation = yes
		}
	}
}

#####################################
# Lady-in-Waiting Events			#
# by Bianca Savazzi					#
# 3030 - 3031						#
#####################################

# Fussy Lady-in-waiting
court.3030 = {
	type = court_event
	title = court.3030.t
	desc = {
		desc = court.3030.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = { 
					scope:fussy_liw = { has_relation_lover = root }
				}
				desc = court.3030.desc.lovers
			}
			desc = court.3030.desc.generic
		}
		desc = court.3030.desc.ending
	}
	theme = court
	cooldown = { years = 5 }
	court_scene = {
		button_position_character = scope:fussy_liw
		roles = {
			scope:fussy_liw = {
				group = event_group
				animation = worry
			}
			root = {
				group = event_group
				animation = worry
			}
		}
	}
	 
	weight_multiplier = {
		base = 1
		# Court weightings.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_diplomatic }
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_intrigue }
	}

	trigger = {
		has_court_event_flag = no
		employs_court_position = lady_in_waiting_court_position
		any_court_position_holder = {
			type = lady_in_waiting_court_position
			is_available_ai_adult = yes
			has_court_event_flag = no
			NOT = { has_trait = blind }
		}
		#Event desc doesn't work if naked
		NOT = {
			should_be_naked_trigger = yes
		}
	}

	immediate = {
		court_event_character_flag_effect = yes
		random_court_position_holder = {
			type = lady_in_waiting_court_position
			#prioritize lovers
			limit = {
				is_available_ai_adult = yes
				NOT = { has_trait = blind } 
				has_relation_lover = root
			}
			alternative_limit = {
				is_available_ai_adult = yes
				NOT = { has_trait = blind }
			}
			save_scope_as = fussy_liw
			court_event_character_flag_effect = yes
		}
	}

	# Option A: Make a scene
	option = { 
		name = court.3030.a
		# Lose opinion 
		reverse_add_opinion = {
			target = scope:fussy_liw
			modifier = cruelty_opinion
			opinion = -30
		}
		# Gain a little dread.
		add_dread = minor_dread_gain
		stress_impact = {
			arrogant = miniscule_stress_impact_loss
			sadistic = miniscule_stress_impact_loss
			shy = major_stress_impact_gain
			compassionate = medium_stress_impact_gain
			forgiving = major_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_boldness = 0.5
				ai_compassion = -0.75
			}
		}
	}

	# Option B: Tell her to hurry
	option = {
		name = court.3030.b
		scope:fussy_liw = {
			add_stress = medium_stress_gain
		}
		add_prestige = minor_prestige_gain
		stress_impact = {
			arrogant = miniscule_stress_impact_loss
			callous = miniscule_stress_impact_loss
			shy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_boldness = 1
				ai_compassion = -0.75
			}
		}
	}
	
	# Option C: Say nothing
	option = {
		name = court.3030.c
		reverse_add_opinion = {
			target = scope:fussy_liw
			modifier = pleased_opinion
			opinion = 20
		}
		# Lose a little dread.
		add_dread = minor_dread_loss
		stress_impact = {
			arrogant = major_stress_impact_gain
			callous = medium_stress_impact_gain
			impatient = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_boldness = -0.75
			}
		}
	}

	# Option D: Dismiss
	option = {
		name = court.3030.d
		reverse_add_opinion = {
			target = scope:fussy_liw
			modifier = dismissive_opinion
			opinion = -15
		}
		add_prestige = minor_prestige_gain
		stress_impact = {
			humble = miniscule_stress_impact_loss
			content = miniscule_stress_impact_loss
			diligent = medium_stress_impact_gain
		}
		ai_chance = {
			base = 20
			ai_value_modifier = {
				ai_boldness = 0.5
			}
		}
	}

	after = {
		change_current_court_grandeur = minor_court_grandeur_gain
		clear_court_event_participation = yes
		scope:fussy_liw = {
			clear_court_event_participation = yes
		}
	}
}

# Lady-in-waiting smooths things over with courtiers
court.3031 = {
	type = court_event
	title = court.3031.t
	desc = court.3031.desc
	theme = court
	cooldown = { years = 10 }
	court_scene = {
		button_position_character = scope:liw
		roles = {
			scope:liw = {
				group = event_group
				animation = happiness
			}
			root = {
				group = event_group
				animation = personality_rational
			}
		}
	}
	 
	weight_multiplier = {
		base = 1
		# Court weightings.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_diplomatic }
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_intrigue }
	}

	trigger = {
		has_court_event_flag = no
		employs_court_position = lady_in_waiting_court_position
		any_court_position_holder = {
			type = lady_in_waiting_court_position
			is_available_ai_adult = yes
			has_court_event_flag = no
		}
		any_vassal = {
			count > 0
		}
		any_courtier = {
			count > 0
		}
	}

	immediate = {
		court_event_character_flag_effect = yes
		random_court_position_holder = {
			type = lady_in_waiting_court_position
			limit = {
				is_available_ai_adult = yes
			}
			save_scope_as = liw
			court_event_character_flag_effect = yes
			assign_quirk_effect = yes
		}
	}

	# Option A: The women
	option = { 
		name = court.3031.a
		trigger = {
			any_courtier = {
				is_female = yes
			}
		}
		every_courtier = {
			custom = custom.every_female_courtier
			limit = {
				is_female = yes
			}
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = 10
			}
		}
		ai_chance = {
			base = 10
			
			modifier = {
				is_attracted_to_women = yes
				add = 10 
			}
			modifier = {
				faith = { has_doctrine = doctrine_gender_female_dominated }
				add = 5 
			}
		}
	}

	# Option B: The men
	option = {
		name = court.3031.b
		trigger = {
			any_courtier = {
				is_male = yes
			}
		}
		every_courtier = {
			custom = custom.every_male_courtier
			limit = {
				is_male = yes
			}
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = 10
			}
		}
		ai_chance = {
			base = 10

			modifier = {
				is_attracted_to_men = yes
				add = 10 
			}
			modifier = {
				faith = { has_doctrine = doctrine_gender_male_dominated }
				add = 5 
			}
		}
	}
	
	# Option C: Vassals
	option = {
		name = court.3031.c
		every_vassal = {
			custom = custom.every_vassal
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = 5
			}
		}
		ai_chance = {
			base = 15

			modifier = {
				has_trait = ambitious
				add = 10 
			}
		}
	}

	# Option D: Nah
	option = {
		name = court.3031.d
		add_prestige = miniscule_prestige_gain
		stress_impact = {
			ambitious = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			modifier ={
				has_trait = lazy
				add = 10 
			}
			modifier ={
				has_trait = content
				add = 10 
			}
		}
	}
	after = {
		clear_court_event_participation = yes
		scope:liw = {
			clear_court_event_participation = yes
		}
	}
}

#####################################
# Homesick MotherFather				#
# by Bianca Savazzi					#
# 3040 - 3041						#
#####################################

# Your parent of a different culture is caught feeling homesick
court.3040 = {
	type = court_event
	title = court.3040.t
	desc = court.3040.desc
	theme = court
	cooldown = { years = 10 }
	court_scene = {
		button_position_character = scope:homesick_parent
		roles = {
			scope:homesick_parent = {
				group = event_group
				animation = sadness
			}
			root = {
				group = event_group
				animation = personality_rational
			}
		}
	}
	 
	weight_multiplier = {
		base = 1
		# Court weightings.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_warlike }
	}

	trigger = {
		has_court_event_flag = no
		any_parent = {
			has_court_event_flag = no
			NOT = { 
				culture = root.culture 
			}
			save_temporary_scope_as = temp_parent_scope
		}
		capital_province.culture = root.culture 	
		root.culture = {
			NOT = { has_same_culture_language = scope:temp_parent_scope.culture }
		}
		NOR = {
			root.culture = { any_parent_culture = { this = scope:temp_parent_scope.culture  } }
			scope:temp_parent_scope.culture = { any_parent_culture = { this = root.culture } }
		}
	}

	immediate = {
		court_event_character_flag_effect = yes
		random_parent = {
			limit = {
				NOT = { 
					culture = root.culture 
				}
			}
			save_scope_as = homesick_parent
			court_event_character_flag_effect = yes
		}
	}

	# Option A: Leave then
	option = { 
		name = court.3040.a
		scope:homesick_parent = {
			add_opinion = {
				target = root
				modifier = cruelty_opinion
				opinion = -30
			}
		}
		add_dread = minor_dread_gain
		stress_impact = {
			sadistic = miniscule_stress_impact_loss
			arrogant = miniscule_stress_impact_loss
			compassionate = massive_stress_impact_gain
			patient = major_stress_impact_gain
			forgiving = major_stress_impact_gain
		}
		ai_chance = {
			base = 10
			
			ai_value_modifier = {
				ai_compassion = -2
			}
			modifier ={
				has_trait = sadistic
				add = 10 
			}
			modifier ={
				has_trait = arrogant
				add = 10 
			}
		}
	}

	# Option B: Learn language
	option = {
		name = court.3040.b
		trigger = {
			can_start_scheme = {
				type = learn_language
				target = scope:homesick_parent
			}
			scope:homesick_parent.culture = {
				NOT = { has_same_culture_language = root.culture }
			}
		}

		start_scheme = {
			type = learn_language
			target = scope:homesick_parent
		}
		scope:homesick_parent = {
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = 10
			}
		}
		stress_impact = {
			impatient = medium_stress_impact_gain
			arrogant = medium_stress_impact_gain
			lazy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_compassion = 1
			}
			modifier ={
				has_trait = scholar
				add = 10 
			}
		}
	}
	
	# Option C: Food
	option = {
		name = court.3040.c
		remove_short_term_gold = medium_gold_value
		add_prestige = minor_prestige_gain
		change_current_court_grandeur = minor_court_grandeur_gain
		scope:homesick_parent = {
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = 5
			}
		}
		stress_impact = {
			inappetetic = medium_stress_impact_gain
			comfort_eater = miniscule_stress_impact_loss
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_compassion = 2
			}
			modifier = {
				short_term_gold < medium_gold_value
				factor = 0
			}
			modifier ={
				has_trait = gluttonous
				add = 10 
			}
		}
	}

	# Option D: Don't care, go sulk elsewhere 
	option = {
		name = court.3040.d
		scope:homesick_parent = {
			add_opinion = {
				target = root
				modifier = cruelty_opinion
				opinion = -10
			}
		}
		add_prestige = miniscule_prestige_gain
		stress_impact = {
			compassionate = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_compassion = -1
			}
		}
	}
	after = {
		clear_court_event_participation = yes
		scope:homesick_parent = {
			clear_court_event_participation = yes
		}
	}
}

#####################################
# Letter of Defamation				#
# by Bianca Savazzi					#
# 3050 - 3051						#
#####################################

# Chief Eunuch suggests stirring up some drama
court.3050 = {
	type = court_event
	title = court.3050.t
	desc = court.3050.desc
	theme = court
	cooldown = { years = 10 }
	court_scene = {
		button_position_character = scope:chief_eunuch
		roles = {
			scope:chief_eunuch = {
				group = event_group
				animation = schadenfreude
			}
			root = {
				group = event_group
				animation = personality_rational
			}
		}
	}
	 
	weight_multiplier = {
		base = 1
		# Court weightings.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_intrigue }
	}

	trigger = {
		has_court_event_flag = no
		employs_court_position = chief_eunuch_court_position
		any_court_position_holder = {
			type = chief_eunuch_court_position
			is_available_ai_adult = yes
			has_court_event_flag = no
			NOT = { has_trait = blind }
		}
		# Needs a target
		OR = {
			any_relation = {
				type = nemesis
				liege = root 
				is_available_ai_adult = yes
			}
			any_relation = {
				type = rival
				liege = root 
				is_available_ai_adult = yes
			}
			any_relation = {
				type = potential_rival
				liege = root 
				is_available_ai_adult = yes
			}
		}
	}

	immediate = {
		court_event_character_flag_effect = yes
		random_court_position_holder = {
			type = chief_eunuch_court_position
			limit = {
				is_available_ai_adult = yes
			}
			save_scope_as = chief_eunuch
			court_event_character_flag_effect = yes
			assign_quirk_effect = yes
		}
		#Pick available detractor
		if = {
			limit = {
				any_relation = {
					type = nemesis
					liege = root 
					is_available_ai_adult = yes
				}
			}
			random_relation = {
				type = nemesis
				limit = {
					is_available_ai_adult = yes
					liege = root 
				}
				save_scope_as = target
			}
		}
		else_if = {
			limit = {
				any_relation = {
					type = rival
					liege = root 
					is_available_ai_adult = yes
				}
			}
			random_relation = {
				type = rival
				limit = {
					is_available_ai_adult = yes
					liege = root 
				}
				save_scope_as = target
			}
		}
		else_if = {
			limit = {
				any_relation = {
					type = potential_rival
					liege = root 
					is_available_ai_adult = yes
				}
			}
			random_relation = {
				type = potential_rival
				limit = {
					is_available_ai_adult = yes
					liege = root 
				}
				save_scope_as = target
			}
		}

		#OPTION C: Save possible rival to rival 
		if = {
			limit = {
				any_vassal = { #More fun if you can pit someone with a little bite 
					OR = {
						can_set_relation_rival_trigger = { CHARACTER = scope:target } 
						can_set_relation_potential_rival_trigger = { CHARACTER = scope:target } 
					}
					NOT = { this = scope:chief_eunuch }
					is_available_ai_adult = yes
				}
			}
			random_vassal = {
				limit = {
					OR = {
						can_set_relation_rival_trigger = { CHARACTER = scope:target } 
						can_set_relation_potential_rival_trigger = { CHARACTER = scope:target } 
					}
					NOT = { this = scope:chief_eunuch }
					is_available_ai_adult = yes
				}
				weight = {
					modifier = {
						is_powerful_vassal_of = root	
						factor = 5
					}
				}
				save_scope_as = possible_rival_to_rival
			}
		}
	}

	# Option A: Threaten them
	option = { 
		name = court.3050.a
		trigger = {
			any_known_secret = {
				secret_owner = scope:target
				can_be_exposed_by = root
			}
		}
		add_dread = minor_dread_gain
		add_character_modifier = {
			modifier = made_a_fool_of_rival_roco_modifier
			years = 5
		}
		stress_impact = {
			compassionate = massive_stress_impact_gain #This isn't very nice...
			forgiving = major_stress_impact_gain #I shouldn't judge them for their secrets...
			craven = medium_stress_impact_gain #I don't like confronting people
			shy = major_stress_impact_gain # People and confrontations are 2 stress factors
		}
		ai_chance = {
			base = 10
			
			ai_value_modifier = {
				ai_compassion = -1
				ai_vengefulness = 2
				ai_boldness = 1
			}
		}
	}

	# Option B: Make a fake rejection letter
	option = {
		name = court.3050.b
		stress_impact = {
			honest = medium_stress_impact_gain
		}
		add_character_modifier = {
			modifier = made_a_fool_of_rival_roco_modifier
			years = 5
		}
		scope:target = {
			if = {
				limit = { 
					OR = {
						has_trait = lustful 
						has_trait = seducer
					}
				}
				add_stress = massive_stress_gain #AAAA, I LOOK LIKE A LOSER!!
			}
			else = {
				add_stress = medium_stress_gain
			}

			if = {
				limit = { is_male = yes }
				add_character_modifier = {
					modifier = lecher_modifier
					years = 10
				}
			}
			else = {
				add_character_modifier = {
					modifier = strumpet_modifier
					years = 10
				}
			}
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_compassion = -1
				ai_vengefulness = 1
			}
			modifier ={
				has_trait = lustful
				add = 10 
			}
			modifier ={
				has_trait = seducer
				add = 10 
			}
		}
	}
	
	# Option C: Give em another rival 
	option = {
		name = court.3050.c
		trigger = {
			exists = scope:possible_rival_to_rival
		}
		scope:possible_rival_to_rival = {
		 add_opinion = {
				modifier = stood_by_me_opinion
				target = root
				opinion = 20
			}
		}
		scope:target = {
			progress_towards_rival_effect = {
				CHARACTER = scope:possible_rival_to_rival
				REASON = rival_slandered_rival
				OPINION = -30
			}
		}
		stress_impact = {
			honest = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_vengefulness = 2
				ai_boldness = -1
			}
			modifier ={
				has_trait = shy
				add = 10 
			}
		}
	}

	# Option D: Nah, let's not
	option = {
		name = court.3050.d

		if = {
			limit = {
				faith = { 
					OR = {
						trait_is_virtue = forgiving 
						trait_is_virtue = honest
						trait_is_virtue = compassionate
					}
				}
			}
			add_piety = minor_piety_gain
		} 
		
		add_character_modifier = {
			modifier = moment_of_calm_and_clarity_roco_modifier
			years = 5
		}
		
		stress_impact = {
			vengeful = major_stress_impact_gain
			deceitful = major_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_compassion = 2
			}
		}
	}
	after = {
		clear_court_event_participation = yes
		scope:chief_eunuch = {
			clear_court_event_participation = yes
		}
	}
}

#####################################
# A Feline Hunter					#
# by Bianca Savazzi					#
# 3060 - 3061						#
#####################################

# Court Cat
court.3060 = {
	type = court_event
	title = court.3060.t
	desc = court.3060.desc
	theme = court
	cooldown = { years = 10 }
	court_scene = {
		button_position_character = scope:cat_finder
		roles = {
			scope:cat_finder = {
				group = event_group
				animation = happiness
			}
		}
	}
	 
	weight_multiplier = {
		base = 0.5

		modifier = {
			has_royal_court = yes
			court_grandeur_current_level > 0
			add = {
				value = 1
				divide = court_grandeur_current_level
			}
		}
		# Court weightings.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_administrative }
	}

	trigger = {
		NOR = {
			any_owned_story = { story_type = story_cycle_pet_cat }
			has_character_modifier = cat_story_modifier
		}
		OR = {
			any_vassal = {
				is_available_ai_adult = yes
				has_court_event_flag = no
			}
			any_courtier = {
				is_available_ai_adult = yes
				has_court_event_flag = no
			}
		}
	}

	immediate = {
		#Pick cat finder
		if = {
			limit = {
				employs_court_position = master_of_hunt_court_position
				any_court_position_holder = {
					type = master_of_hunt_court_position #Primary choice as they are also used for dog option
					is_available_ai_adult = yes
				}
			}
			random_court_position_holder = {
				type = master_of_hunt_court_position
				limit = {
					is_available_ai_adult = yes
				}
				save_scope_as = cat_finder
				court_event_character_flag_effect = yes
			}
		}
		else_if = {
			limit = {
				any_vassal = {
					is_available_ai_adult = yes
				}
			}
			random_vassal = {
				limit = {
					is_available_ai_adult = yes
				}
				save_scope_as = cat_finder
				court_event_character_flag_effect = yes
			}
		}
		else = {
			limit = {
				any_courtier = {
					is_available_ai_adult = yes
				}
			}
			random_courtier = {
				limit = {
					is_available_ai_adult = yes
				}
				save_scope_as = cat_finder
				court_event_character_flag_effect = yes
			}
		}
	}

	# Option A: Adopt!
	option = { 
		name = court.3060.a
		start_cat_story_cycle_effect = yes
		hidden_effect = { add_character_modifier = rat_hunting_cat_modifier }

		ai_chance = {
			base = 20
			
			ai_value_modifier = {
				ai_compassion = 1
			}
		}
	}

	# Option B: Finder gets cat
	option = {
		name = court.3060.b
		trigger = {
			scope:cat_finder = {
				NOR = {
					any_owned_story = { story_type = story_cycle_pet_cat }
					has_character_modifier = cat_story_modifier
				}
			}
		}
		scope:cat_finder = {
			start_cat_story_cycle_effect = yes
			add_opinion = {
				modifier = grateful_opinion
				target = root
				opinion = 30
			}
			hidden_effect = { add_character_modifier = rat_hunting_cat_modifier }
		}
		
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_compassion = 1
			}
		}
	}
	
	# Option C: I want a dog! >:C
	option = {
		name = court.3060.c
		trigger = {
			scope:cat_finder = { has_court_position = master_of_hunt_court_position }
			NOR = {
				any_owned_story = { story_type = story_cycle_pet_dog }
				has_character_modifier = dog_story_modifier
			}
		}
		start_dog_story_cycle_effect = yes
		hidden_effect = { 
			add_character_modifier = rat_hunting_dog_modifier 
			#Silently takes cat if possible
			scope:cat_finder = {
				if = {
					limit = {
						NOR = {
							any_owned_story = { story_type = story_cycle_pet_cat }
							has_character_modifier = cat_story_modifier
						}
					}
					start_cat_story_cycle_effect = yes
				}
			}
		}
		scope:cat_finder = {
			add_opinion = {
				modifier = annoyed_opinion
				target = root
				opinion = -10
			}
		}
		
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_boldness = 1
			}
			modifier ={
				has_trait = stubborn
				add = 10 
			}
			modifier ={
				has_trait = arrogant
				add = 10 
			}
		}
	}

	# Option D: No cat
	option = {
		name = court.3060.d
		scope:cat_finder = {
			add_opinion = {
				modifier = disappointed_opinion
				target = root
				opinion = -10
			}
		}
		
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_compassion = -2
			}
		}
	}
	after = {
		scope:cat_finder = {
			clear_court_event_participation = yes
		}
	}
}

#####################################
# The Unknown TitleTier				#
# by Bianca Savazzi					#
# 3070 - 3071						#
#####################################

# Court
#The Unknown Ruler: Low fame, High court amenities 
court.3070 = {
	type = court_event
	title = court.3070.t
	desc = {
		desc = court.3070.desc.opening
		random_valid = {
			triggered_desc = {
				trigger = { 
					amenity_level = { type = court_food_quality value >= high_amenity_level }
				}
				desc = court.3070.desc.opening_food
			}
			triggered_desc = {
				trigger = { 
					amenity_level = { type = court_servants value >= high_amenity_level }
				}
				desc = court.3070.desc.opening_servants
			}
			triggered_desc = {
				trigger = { 
					amenity_level = { type = court_lodging_standards value >= high_amenity_level }
				}
				desc = court.3070.desc.opening_lodging
			}
			triggered_desc = {
				trigger = { 
					amenity_level = { type = court_fashion value >= high_amenity_level }
				}
				desc = court.3070.desc.opening_fashion
			}
		}
		desc = court.3070.desc.middle
		random_valid = {
			triggered_desc = {
				trigger = { 
					amenity_level = { type = court_food_quality value >= high_amenity_level }
				}
				desc = court.3070.desc.closing_food
			}
			triggered_desc = {
				trigger = { 
					amenity_level = { type = court_servants value >= high_amenity_level }
				}
				desc = court.3070.desc.closing_servants
			}
			triggered_desc = {
				trigger = { 
					amenity_level = { type = court_lodging_standards value >= high_amenity_level }
				}
				desc = court.3070.desc.closing_lodging
			}
			triggered_desc = {
				trigger = { 
					amenity_level = { type = court_fashion value >= high_amenity_level }
				}
				desc = court.3070.desc.closing_fashion
			}
		}
		desc = court.3070.desc.closing
	}
	theme = court
	cooldown = { years = 10 }
	court_scene = {
		button_position_character = scope:court_enjoyer
		roles = {
			scope:court_enjoyer = {
				group = event_group
				animation = shock
			}
		}
	}
	 
	weight_multiplier = {
		base = 1

		modifier = {
			add = {
				value = 0.1
				multiply = court_grandeur_current_level #More likely to try and trigger the higher court grandeur you have
			}
		}
		# Court weightings.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_administrative }
	}

	trigger = {
		OR = {
			amenity_level = { type = court_food_quality value >= high_amenity_level }
			amenity_level = { type = court_servants value >= high_amenity_level }
			amenity_level = { type = court_lodging_standards value >= high_amenity_level }
			amenity_level = { type = court_fashion value >= high_amenity_level }
		}
		dynasty = { dynasty_prestige_level <= medium_dynasty_prestige_level }
		any_pool_guest = {
			is_available_ai_adult = yes
			has_court_event_flag = no
			NOR = { 
				has_relation_friend = root
				has_relation_best_friend = root
			}
		}
	}

	immediate = {
		#Pick court enjoyer
		random_pool_guest = {
			limit = {
				is_available_ai_adult = yes
				NOR = { 
					has_relation_friend = root
					has_relation_best_friend = root
				}
			}
			save_scope_as = court_enjoyer
			court_event_character_flag_effect = yes
		}
	}

	# Option A: Make an example out of them!
	option = { 
		name = court.3070.a
		save_scope_as = actor #for the kick effect below
		scope:court_enjoyer = {
			kick_from_court_interaction_effect = yes
		}
		add_dread = minor_dread_gain
		add_prestige = miniscule_prestige_gain
		every_pool_guest = {
			custom = every_guest_scope_tt
			add_opinion = {
				modifier = cruelty_opinion
				target = root
				opinion = -20
			}
		}
		stress_impact = {
			compassionate = major_stress_impact_gain
			gregarious = major_stress_impact_gain
			forgiving = major_stress_impact_gain
			content = medium_stress_impact_gain
			just = medium_stress_impact_gain
		}
		ai_chance = {
			base = 20
			
			ai_value_modifier = {
				ai_compassion = -2
				ai_boldness = 1
				ai_vengefulness = 1
			}
		}
	}

	# Option B: Spread the word!
	option = {
		name = court.3070.b
		change_current_court_grandeur = minor_court_grandeur_gain
		dynasty ?= {
			add_dynasty_prestige = miniscule_dynasty_prestige_gain
		}
		remove_short_term_gold = medium_gold_value
		every_pool_guest = {
			custom = every_guest_scope_tt
			add_opinion = {
				modifier = pleased_opinion
				target = root
				opinion = 30
			}
		}

		stress_impact = {
			shy = major_stress_impact_gain
			greedy = major_stress_impact_gain
			humble = major_stress_impact_gain
			wrathful = major_stress_impact_gain
		}
		
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_compassion = 0.5
				ai_boldness = 1
				ai_greed = -2
			}
			modifier = {
				short_term_gold < medium_gold_value
				factor = 0
			}
		}
	}
	
	# Option C: Mandatory tests!
	option = {
		name = court.3070.c
		
		save_scope_as = actor #for the kick effect below
		scope:court_enjoyer = {
			kick_from_court_interaction_effect = yes
		}
		add_prestige = miniscule_prestige_gain
		dynasty ?= {
			add_dynasty_prestige = miniscule_dynasty_prestige_gain
		}
		every_pool_guest = {
			custom = every_guest_scope_tt
			add_opinion = {
				modifier = annoyed_opinion
				target = root
				opinion = -30
			}
		}
		stress_impact = {
			shy = major_stress_impact_gain
			forgiving = major_stress_impact_gain
			humble = major_stress_impact_gain
		}
		
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_boldness = 2
				ai_vengefulness = 1
			}
			modifier ={
				has_trait = stubborn
				add = 10 
			}
			modifier ={
				has_trait = arrogant
				add = 10 
			}
		}
	}

	# Option D: I... don't mind actually
	option = {
		name = court.3070.d
		scope:court_enjoyer = {
			add_opinion = {
				modifier = kindness_opinion
				target = root
				opinion = 30
			}
		}
		progress_towards_friend_effect = {
			REASON = friend_graceful_recovery
			CHARACTER = scope:court_enjoyer
			OPINION = 0
		}
		stress_impact = {
			shy = miniscule_stress_impact_loss
			content = miniscule_stress_impact_loss
			ambitious = major_stress_impact_gain
			arrogant = medium_stress_impact_gain
			vengeful = major_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_compassion = 2
				ai_boldness = -1
			}
		}
	}
	after = {
		scope:court_enjoyer = {
			clear_court_event_participation = yes
		}
	}
}










##################################################
# Isabella

##################################################
# 4001			A diplomat who is injured and bleeding out is too polite to ask for any help.
# 4100			The Court Musician tries to convince you to fund their medieval boyband, sorry I mean all-male-choir
# 4200			A sneaky figure offers to build secret passages in your castle
# 4250			You and your rival have a tower building competition
# 4251			You successfully build the tower
# 4400 - 4402	Recruit an antiquarian from some crazy monks
# 4500			Dodgy artifacts for sale
# 4600			Cupbearer drinking all your wine
# 4700 - 4701	Trepanning!
# 4750 - 4751	Your court poet is writing a heroic book
# 4801			Low servants ruler has to change their own baby's diaper
# 4802			Court Tutor annoyed by questioning children
# 4803			Court poet offers to ghostwrite for you
# 4804			Low lodgings - courtiers don't enjoy sleeping in the same room
# 4805			Court architect steals your rival's castle cornerstone
# 4806			Your high-amenities palace attracts extreme fans
##################################################

##################################################
# A Flesh Wound
# by Isabella Welch
# 4001 - 4010
##################################################

court.4001 = {
	type = court_event
	title = court.4001.t
	desc = court.4001.desc
	theme = court

	court_scene = {
		button_position_character = scope:bleeding_diplomat
		roles = {
			scope:bleeding_diplomat = {
				group = event_group
				animation = pain
			}
			root = {
				group = event_group
				animation = shock
			}
		}
	}
	
	trigger = {
		has_court_event_flag = no
		NOT = { has_character_flag = has_had_bleeding_diplomat_event }
		any_ally = {
			highest_held_title_tier >= tier_kingdom
			is_ai = yes
		}
	}

	weight_multiplier = {
		base = 1

		# Court weightings.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_diplomatic }
	}

	immediate = {
		random_ally = {
			limit = {
				is_ai = yes
			}
			save_scope_as = bleeding_diplomat_liege
		}
		create_character = {
			location = root.capital_province
			template = bleeding_diplomat_character
			faith = scope:bleeding_diplomat_liege.faith
			culture = scope:bleeding_diplomat_liege.culture
			save_scope_as = bleeding_diplomat
		}
		add_character_flag = {
			flag = has_had_bleeding_diplomat_event
			days = 1825
		}
		court_event_character_flag_effect = yes
	}

	option = { 
		name = court.4001.a
		trigger = { court_physician_available_trigger = yes }
		save_court_physician_as_effect = { SCOPE_NAME = physician }
		random_list = {
			50 = {
				modifier = {
					factor = scope:physician.physician_safe_treatment_skill_factor
				}
				scope:bleeding_diplomat = {
					wound_treatment_results_effect = { TREATMENT = safe OUTCOME = success }
				}
				scope:bleeding_diplomat_liege = {
					add_opinion = {
						target = root
						modifier = grateful_opinion
						opinion = 25
					}
				}
				hidden_effect = {
					send_interface_toast = {
						left_icon = scope:bleeding_diplomat
						title = court.4001.cure_toast
						show_as_tooltip = {
							scope:bleeding_diplomat = {
								wound_treatment_results_effect = { TREATMENT = safe OUTCOME = success }
							}
						}
						show_as_tooltip = { add_diplomacy_lifestyle_xp = medium_lifestyle_xp }
					}
				}
			}
			50 = {
				scope:bleeding_diplomat = {
					death = {
						death_reason = death_wounds
					}
				}
				remove_short_term_gold = minor_gold_value
				custom_tooltip = court.4001.carpet
				hidden_effect = {
					send_interface_toast = {
						left_icon = scope:bleeding_diplomat
						title = court.4001.toast
						custom_tooltip = court.4001.toast_desc
					}
				}
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = 0.5
			}
		}
	}

	option = {
		name = court.4001.b
		custom_tooltip = court.4001.new_carpet
		remove_short_term_gold = minor_gold_value
		if = {
			limit = {
				root = { has_trait = sadistic }
			}
			add_stress = medium_stress_loss
		}
		scope:bleeding_diplomat_liege = {
			add_opinion = {
				target = root
				modifier = annoyed_opinion
				opinion = -15
			}
		}
		trigger_event = {
			id = court.4002
			days = { 4 7 }
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_energy = -0.5
			}
		}
	}
	
	option = {
		name = court.4001.c
		scope:bleeding_diplomat_liege = {
			add_opinion = {
				target = root
				modifier = annoyed_opinion
				opinion = -30
			}
		}
		add_diplomacy_lifestyle_xp = medium_lifestyle_xp
		add_gold = tiny_gold_value
		trigger_event = {
			id = court.4002
			days = { 4 7 }
		}
		change_current_court_grandeur = medium_court_grandeur_gain
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = 0.25
			}
		}
	}
	after = {
		clear_court_event_participation = yes
	}
}

court.4002 = {
	hidden = yes
	immediate = {
		scope:bleeding_diplomat = {
			if = {
				limit = {
					is_alive = yes
				}
				death = {
					death_reason = death_wounds
				}
			}
		}
		send_interface_message = {
			left_icon = scope:bleeding_diplomat
			title = court.4001.toast
			scope:bleeding_diplomat = {
				show_as_tooltip = {
					death = {
						death_reason = death_wounds
					}
				}
			}
		}
	}
}

##################################################
# Squires to Knights
# by Isabella Welch
# 4100 - 4109
##################################################

scripted_trigger court_4100_court_musician_trigger = {
	has_court_position = court_musician_court_position
	is_available_ai_adult = yes
	NOT = { has_trait = chaste }
}

court.4100 = {
	type = court_event
	title = court.4100.t
	desc = court.4100.desc
	theme = court
	
 	cooldown = { years = 5 }
	
	court_scene = {
		button_position_character = scope:court_musician
		roles = {
			scope:court_musician = {
				group = event_group
				animation = flirtation
			}
		}
	}

	trigger = {
		any_court_position_holder = {
			court_4100_court_musician_trigger = yes
			has_court_event_flag = no
		}
	}

	weight_multiplier = {
		base = 1

		# Court weightings.
		## ... uhhh, I wouldn't even know where to begin...
	}

	immediate = {
		random_court_position_holder = {
			limit = { court_4100_court_musician_trigger = yes }
			save_scope_as = court_musician
			court_event_character_flag_effect = yes
		}
		hidden_effect = { scope:court_musician = { add_trait = deviant } }
	}

	option = { 
		name = court.4100.a
		imprison_character_effect = {
			TARGET = scope:court_musician
			IMPRISONER = root
		}
		add_piety = minor_piety_gain
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_zeal = 0.5
				ai_boldness = 0.25
			}
		}
	}

	option = {
		name = court.4100.b

		every_courtier = {
			limit = {
				is_female = yes
				is_attracted_to_men = yes
				NOT = { has_trait = lustful }
			}
			custom = all_ladies_of_the_court
			add_opinion = {
				target = root
				modifier = insulted_opinion
				opinion = -10
			}
		}
		every_courtier = {
			limit = {
				is_attracted_to_men = yes
				has_trait = lustful
			}
			custom = all_lustful_in_the_court
			add_opinion = {
				target = root
				modifier = insulted_opinion
				opinion = -20
			}
		}
		change_current_court_grandeur = miniscule_court_grandeur_loss
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_sociability = -0.5
			}
		}
	}
	
	option = {
		name = court.4100.c
		every_courtier = {
			limit = {
				is_female = yes
				is_attracted_to_men = yes
				NOR = {
					has_trait = chaste 
					has_trait = lustful
				}
			}
			custom = all_ladies_of_the_court
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 10
			}
		}
		every_courtier = {
			limit = {
				is_attracted_to_men = yes
				has_trait = lustful
			}
			custom = all_lustful_in_the_court
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 20
			}
		}
		remove_short_term_gold = medium_gold_value
		capital_province.county = {
			add_county_modifier = {
				modifier = all_male_choirs_modifier
 				days = 2000
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_greed = 0.5
			}
		}
	}
	after = {
		scope:court_musician = {
			clear_court_event_participation = yes
		}
	}
}

##################################################
# Focus of Attention
# based on event by Isabella Welch
# 4200 - 4209
##################################################

court.4200 = {
	type = court_event
	title = court.4200.t
	desc = {
		desc = court.4200.desc
	}
	theme = intrigue
	cooldown = { years = 50 }
	court_scene = {
		button_position_character = cp:councillor_spymaster
		roles = {
			cp:councillor_spymaster = {
				group = event_group
				animation = scheme
			}
			root = {
				group = event_group
				animation = personality_rational
			}
		}
	}
	
	trigger = {
		has_court_event_flag = no
		is_adult = yes
		exists = cp:councillor_spymaster
		cp:councillor_spymaster = {
			basic_is_available_ai = yes
			has_court_event_flag = no
		}
	}

	weight_multiplier = {
		base = 1

		# Court weightings.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_intrigue }
	}

	immediate = {
		court_event_character_flag_effect = yes
		cp:councillor_spymaster= {
		 	save_scope_as = report_spymaster
		 	court_event_character_flag_effect = yes
		}
	}
	
	option = {
		name = court.4200.a
		add_piety = minor_piety_gain
		reverse_add_opinion = {
			target = scope:report_spymaster
			modifier = pleased_opinion
			opinion = 10
		}
		scope:report_spymaster = {
			add_character_modifier = {
				modifier = int_free_reign
				days = 1000
			}
		}
		stress_impact = {
			lazy = minor_stress_loss
			trusting = minor_stress_loss
			paranoid = major_stress_gain
		}
		ai_chance = {
			base = 50
		}
	}

	option = {
		name = court.4200.b
		add_character_modifier = {
			modifier = spying_inside_modifier
			days = 2000
		}
		change_current_court_grandeur = minor_court_grandeur_loss
		stress_impact = {
			trusting = medium_stress_gain
			paranoid = medium_stress_loss
			craven = medium_stress_loss
			brave = medium_stress_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_honor = -0.5
			}
		}
	}
	
	option = {
		name = court.4200.c
		add_character_modifier = {
			modifier = spying_outside_modifier
			days = 2000
		}
		change_current_court_grandeur = minor_court_grandeur_loss
		stress_impact = {
			trusting = medium_stress_gain
			paranoid = medium_stress_loss
			craven = medium_stress_loss
			brave = medium_stress_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_vengefulness = 0.5
				ai_honor = -0.25
			}
		}
	}

	option = { 
		name = court.4200.d
		add_prestige = minor_prestige_gain
		change_current_court_grandeur = minor_court_grandeur_gain
		reverse_add_opinion = {
			target = scope:report_spymaster
			modifier = disappointed_opinion
			opinion = -20
		}
		stress_impact = {
			paranoid = minor_stress_gain
			craven = medium_stress_gain
			brave = medium_stress_loss
			honest = medium_stress_loss
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = 1
			}
		}
	}


	after = {
		clear_court_event_participation = yes
		scope:report_spymaster = {
			clear_court_event_participation = yes
		}
	}
}

##################################################
# My Spire is Bigger than Yours!
# by Isabella Welch
# 4250 - 4259
##################################################

court.4250 = {
	type = court_event
	title = court.4250.t
	desc = court.4250.desc
	theme = rival_relation
	
	court_scene = {
		button_position_character = scope:tower_challenger_rival
		roles = {
			scope:tower_challenger_rival = {
				group = event_group
				animation = personality_bold
			}
			root = {
				group = event_group
				animation = rage
			}
			scope:concerned_steward = {
				group = event_group
				animation = worry
			}
		}
	}
	trigger = {
		has_court_event_flag = no
		any_powerful_vassal = {
			has_relation_rival = root
			has_court_event_flag = no
		}
		exists = cp:councillor_steward
		NOT = { has_character_flag = has_had_tower_competition_event }
		cp:councillor_steward = {
			has_court_event_flag = no
			NOT = { has_relation_rival = root }
		}
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		court_event_character_flag_effect = yes
		add_character_flag = has_had_tower_competition_event
		random_powerful_vassal = { 
			limit = { 
				has_relation_rival = root 
			}
			save_scope_as = tower_challenger_rival
			court_event_character_flag_effect = yes
		}
		cp:councillor_steward = {
			save_scope_as = concerned_steward
			court_event_character_flag_effect = yes
		}
	}

	option = { 
		name = court.4250.a
		add_prestige = medium_prestige_loss
		stress_impact = {
			arrogant = major_stress_gain
			ambitious = major_stress_gain
			stubborn = major_stress_gain
			humble = medium_stress_loss
			content = medium_stress_loss
		}
		change_current_court_grandeur = major_court_grandeur_loss
		ai_chance = {
			base = 75
			ai_value_modifier = {
				ai_vengefulness = -0.25
			}
		}
	}

	option = {
		name = court.4250.b
		custom_tooltip = court.4250.b.tt
		remove_short_term_gold = minor_gold_value
		add_prestige = minor_prestige_gain
		scope:tower_challenger_rival = {
			add_opinion = {
				target = root
				modifier = annoyed_opinion
				opinion = -20
			}
		}
		stress_impact = {
			arrogant = medium_stress_gain
			ambitious = medium_stress_gain
			stubborn = medium_stress_gain
		}
		change_current_court_grandeur = minor_court_grandeur_gain
		ai_chance = {
			base = 75
			ai_value_modifier = {
				ai_vengefulness = -0.25
			}
		}
	}
	
	option = {
		name = court.4250.c
		remove_short_term_gold = major_gold_value
		random_list = {
			20 = {
				desc = court.4250.c.success.tt
				modifier = {
					factor = 3
					has_trait = architect
				}
				compare_modifier  = {
					value = stewardship
					multiplier = 0.4
				}
				add_character_flag = succeeded_building_tower
				trigger_event = {
					id = court.4251
					days = { 3 6 }	
				}
				change_current_court_grandeur = massive_court_grandeur_gain
			}
			60 = {
				desc = court.4250.c.failure.tt
				send_interface_toast = {
					left_icon = scope:tower_challenger_rival
					title = court.4250.c.failure.tt
					add_prestige = major_prestige_loss
					change_current_court_grandeur = major_court_grandeur_loss
				}
			}
			60 = {
				desc = court.4250.c.accident.tt
				custom_tooltip = court.4250.c.accident.tt.flavour
				add_character_flag = terrible_accident
				trigger_event = {
					id = court.4251
					days = { 3 6 }	
				}
			}
		}
		stress_impact = {
			humble = major_stress_gain
			content = major_stress_gain
		}
		ai_chance = {
			base = 5
			ai_value_modifier = {
				ai_vengefulness = 0.25
			}
		}
	}
	after = {
		clear_court_event_participation = yes
		scope:concerned_steward = {
			clear_court_event_participation = yes
		}
		scope:tower_challenger_rival = {
			clear_court_event_participation = yes
		}
	}
}

### Follow-up if you build the tower
court.4251 = {
	type = character_event
	title = court.4250.t
	desc = {
		desc = court.4251.desc
		first_valid = {
			triggered_desc = {
				trigger = { has_character_flag = child_accident }
				desc = court.4251.desc_child_accident
			}
			triggered_desc = {
				trigger = { has_character_flag = rival_accident }
				desc = court.4251.desc_rival_accident
			}
			triggered_desc = {
				trigger = { has_character_flag = succeeded_building_tower }
				desc = court.4251.desc_success
			}
		}
	}
	theme = stewardship_domain_focus
	left_portrait = { 
		character = root
		animation = personality_rational
  	}
  	right_portrait = {
  		character = scope:tower_challenger_rival_alive
  		animation = rage
  	}
  	lower_right_portrait = scope:lower_right_portrait_character
	override_background = { reference = garden }

	trigger = {
		NOT = { has_character_flag = has_had_tower_competition_follow_up }
	}

	weight_multiplier = {
		base = 1

		# Court weightings.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_administrative }
	}

	immediate = {
		add_character_flag = has_had_tower_competition_follow_up
		if = {
			limit = {
				has_character_flag = terrible_accident
			}
			if = {
				limit = { 
					any_child = {
						is_child_of = root
						NOT = { is_primary_heir_of = root }
						age < 6
					}
				}
				add_character_flag = child_accident
				random_child = {
					limit = {
						is_child_of = root
						NOT = { is_primary_heir_of = root }
						age < 6
					}
					save_scope_as = crushed_child
					death = {
						death_reason = death_crushed
					}
				}
			}
			else = {
				add_character_flag = rival_accident
				scope:tower_challenger_rival = {
					death = {
						death_reason = death_fall
					}
				}
			}
		}
	  	if = {
  			limit = {
  				has_character_flag = child_accident
  			}
  			scope:crushed_child = {
  				save_scope_as = lower_right_portrait_character
  			}
  		}
  		else_if = {
  			limit = {
  				has_character_flag = rival_accident
  			}
  			scope:tower_challenger_rival = {
  				save_scope_as = lower_right_portrait_character
  			}
  		}
  		else_if = {
  			limit = {
  				has_character_flag = succeeded_building_tower
  			}
  			scope:tower_challenger_rival = {
  				save_scope_as = tower_challenger_rival_alive
  			}
  		}
	}

	option = { 
		name = court.4251.a
		trigger = { has_character_flag = child_accident }
		add_stress = massive_stress_gain
	}

	option = {
		name = court.4251.b
		trigger = { has_character_flag = rival_accident }
		add_stress = medium_stress_loss
		add_dread = minor_dread_gain
		scope:tower_challenger_rival = {
			every_close_family_member = {
				limit = { NOT = { this = root } }
				add_to_list = family_of_tower_challenger
			}
			every_in_list = {
				list = family_of_tower_challenger
				custom = all_close_family_and_spouses
				add_opinion = {
					target = root
					modifier = angry_opinion
					opinion = -25
				}
			}
		}
	}
	
	option = {
		name = court.4251.c
		trigger = {
			AND = {
		 		has_character_flag = succeeded_building_tower 
		 		NOT = { has_character_flag = rival_accident } 
		 		NOT = { has_character_flag = child_accident }
		 	}
		 }
		add_prestige = massive_prestige_gain
		stress_impact = {
			forgiving = medium_stress_gain
			vengeful = medium_stress_loss
		}
	}
	after = {
		remove_character_flag = rival_accident
		remove_character_flag = terrible_accident
		remove_character_flag = child_accident
		remove_character_flag = succeeded_building_tower
	}
}

##################################################
# Getting A Head
# based on event by Isabella Welch
# 4400 - 4409
##################################################

scripted_trigger valid_coin_searcher = {
	OR = {
		has_trait = trusting
		has_trait = greedy
		has_trait = dull
		has_trait = intellect_bad_1
		has_trait = intellect_bad_2
		has_trait = intellect_bad_3
		has_trait = stubborn
	}
	NOR = {
		has_trait = callous
		has_trait = sadistic
		has_trait = torturer
	}
}

scripted_trigger valid_coin_unsearcher = {
	OR = {
		has_trait = cynical
		has_trait = lazy
		has_trait = honest
	}
}



court.4400 = {
	type = court_event
	title = court.4400.t
	desc = court.4400.desc
	theme = court
	
	court_scene = {
		button_position_character = scope:coin_searcher
		roles = {
			scope:coin_searcher = {
				group = event_group
				animation = happiness
			}
			scope:coin_unsearcher = {
				group = event_group
				animation = disapproval
			}
		}
	}
	
	trigger = {
		any_courtier = {
			valid_coin_searcher = yes
			has_court_event_flag = no
			is_available_ai_adult = yes
		}
		any_courtier = {
			valid_coin_searcher = no
			has_court_event_flag = no
			valid_coin_unsearcher = yes
			is_available_ai_adult = yes
		}
		NOT = { has_character_flag = has_had_head_coin_event }	
	}

	weight_multiplier = {
		base = 1

		# Court weightings.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_scholarly }
	}

	immediate = {
		add_character_flag = {
			flag = has_had_head_coin_event
		}
		random_courtier = {
			limit = { valid_coin_searcher = yes }
			save_scope_as = coin_searcher
			court_event_character_flag_effect = yes
		}
		random_courtier = {
			limit = { valid_coin_unsearcher = yes }
			save_scope_as = coin_unsearcher
			court_event_character_flag_effect = yes
		}
	}

	option = { 
		name = court.4400.a
		scope:coin_searcher = {
			add_opinion = {
				target = root
				opinion = 20
				modifier = grateful_opinion
			}
		}
		scope:coin_unsearcher = {
			add_opinion = {
				target = root
				opinion = -20
				modifier = disgusted_opinion
			}
		}
		change_current_court_grandeur = minor_court_grandeur_loss
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_greed = -0.5
				ai_compassion = 0.5
			}
		}	
	}

	option = {
		name = court.4400.b
		scope:coin_unsearcher = {
			add_opinion = {
				target = root
				opinion = -30
				modifier = disgusted_opinion
			}
		}
		random_list = {
			20 = {
				custom_tooltip = court.4400.b.discovery
				add_character_flag = finds_strange_object
				trigger_event = {
					id = court.4401
					days = { 1 5 }
				}
				change_current_court_grandeur = minor_court_grandeur_gain
			}

			60 = {
				custom_tooltip = court.4400.b.failure
				modifier = {
					has_trait = cynical
					factor = 2
				}
				change_current_court_grandeur = medium_court_grandeur_loss
				hidden_effect = {
					send_interface_toast = {
						left_icon = scope:coin_searcher
						title = court.4400.b.failure
						change_current_court_grandeur = medium_court_grandeur_loss
					}
				}
			}
			20 = {
				modifier = {
					OR = { 
						has_trait = torturer
						has_trait = sadistic
					}
					factor = 5
				}
				custom_tooltip = court.4400.b.severed_head
				add_character_flag = finds_severed_head
				trigger_event = {
					id = court.4402
					days = { 1 5 }
				}
			}
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_boldness = 0.5
			}
		}	
	}
	
	option = {
		name = court.4400.c
		change_current_court_grandeur = minor_court_grandeur_gain
		scope:coin_unsearcher = {
			add_opinion = {
				target = root
				opinion = 20
				modifier = respect_opinion
			}
		}
		scope:coin_searcher = {
			add_opinion = {
				target = root
				opinion = -20
				modifier = respect_opinion
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_rationality = 0.5
			}
		}		
	}
	after = {
		scope:coin_searcher = {
			clear_court_event_participation = yes
		}
		scope:coin_unsearcher = {
			clear_court_event_participation = yes
		}
	}
}

#Rummaging through the castle 1
court.4401 = {
	type = character_event
	title = court.4400.t
	theme = stewardship_domain_focus
	override_background = {
		reference = dungeon
	}
	desc = {
		desc = court.4401.desc
		first_valid = {
			triggered_desc = {
				trigger = { has_trait = arbitrary }
				desc = court.4401.desc_arbitrary
			}
			desc = court.4401.desc_default
		}
		desc = court.4401.desc_object
	}
	left_portrait = {
		character = root
		animation = happiness
	}
	right_portrait = {
		character = scope:coin_searcher
		animation = happiness
	}
	
	trigger = {
		NOT = {
			government_has_flag = government_is_tribal
		}
	}
	
	option = {
		name = court.4401.a
		scope:coin_searcher = {
			add_opinion = {
				target = root
				opinion = 20
				modifier = grateful_opinion
				
			}
			add_gold = minor_gold_value
		}
		add_gold = minor_gold_value
		stress_impact = {
			just = medium_stress_impact_loss
			greedy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_greed = -0.5
			}
		}
	}
	
	option = {
		name = court.4401.b
		scope:coin_searcher = {
			add_opinion = {
				target = root
				opinion = -40
				modifier = respect_opinion
			}
		}
		add_gold = minor_gold_value
		add_gold = minor_gold_value
		stress_impact = {
			just = medium_stress_impact_gain
			greedy = medium_stress_impact_loss
			arbitrary = minor_stress_impact_loss
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_greed = 0.5
			}
		}
	}
	
	option = {
		name = court.4401.c
		scope:coin_searcher = {
			add_opinion = {
				target = root
				opinion = 40
				modifier = grateful_opinion
			}
			add_gold = minor_gold_value
			add_gold = minor_gold_value
		}
		stress_impact = {
			generous = minor_stress_impact_loss
			greedy = major_stress_impact_gain
			compassionate = medium_stress_impact_loss
			callous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_greed = -0.5
				ai_compassion = 0.5
			}
		}
	}
		
}

#Rummaging through the castle 2
court.4402 = {
	type = character_event
	title = court.4400.t
	theme = stewardship_domain_focus
	override_background = {
		reference = dungeon
	}
	desc = {
		desc = court.4402.desc
		first_valid = {
			triggered_desc = {
				trigger = { has_trait = arbitrary }
				desc = court.4402.desc_arbitrary
			}
			desc = court.4402.desc_default
		}
		desc = court.4402.desc_head
	}
	left_portrait = {
		character = root
		animation = disbelief
	}
	right_portrait = {
		character = scope:coin_searcher
		animation = shock
	}
	
	trigger = {
		NOT = {
			government_has_flag = government_is_tribal
		}
	}
	
	option = {
		name = court.4402.a
		scope:coin_searcher = {
			add_opinion = {
				target = root
				opinion = 20
				modifier = grateful_opinion
			}
		}
		stress_impact = {
			compassionate = minor_stress_impact_loss
			forgiving = minor_stress_impact_loss
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = 0.5
			}
		}
	}
	
	option = {
		name = court.4402.b
		scope:coin_searcher = {
			add_opinion = {
				target = root
				opinion = -10
				modifier = respect_opinion
			}
		}
		add_dread = minor_dread_gain
		stress_impact = {
			just = minor_stress_impact_loss
			cynical = minor_stress_impact_loss
		}
		ai_chance = {
			base = 50
		}
	}
	
	option = {
		name = court.4402.c
		scope:coin_searcher = {
			add_opinion = {
				target = root
				opinion = -40
				modifier = shamed_me_opinion
			}
		}
		add_gold = minor_gold_value
		stress_impact = {
			vengeful = medium_stress_impact_loss
			wrathful = medium_stress_impact_loss
			forgiving = medium_stress_impact_gain
			calm = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_vengefulness = 0.5
				ai_compassion = -0.5
			}
		}
	}
		
}

##################################################
# Question of Balance
# modified based on event by Isabella Welch
# 4500 - 4509
##################################################

scripted_trigger court4500_valid_knight = {
	is_landed = no
	opinion = {
		target = root
		value >= 0
	}
	is_available_ai_adult = yes
}


scripted_trigger court4500_valid_place = {
	NOT = {
		government_has_flag = government_is_tribal
	}
	capital_province = {
		OR = {
			geographical_region = world_westeros
		}
	}
}

court.4500 = {
	type = court_event
	title = court.4500.t
	desc = {
		desc = court.4500.desc
	}
	theme = learning_medicine_focus
	cooldown = { years = 30 }
	court_scene = {
		button_position_character = scope:lucky_knight
		roles = {
		    scope:lucky_knight = {
				group = petitioners_group
				animation = throne_room_kneel_1
		    }
		}
	}
	trigger = {
		has_court_event_flag = no
		any_knight = {
			has_court_event_flag = no
			court4500_valid_knight = yes
		}
		court4500_valid_place = yes
	}

	weight_multiplier = {
		base = 1

		# Court weightings.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_scholarly }
	}

	immediate = {
		court_event_character_flag_effect = yes
		random_knight = {
			limit = { 
				court4500_valid_knight = yes
				has_court_event_flag = no
			}
			court_event_character_flag_effect = yes
			save_scope_as = lucky_knight
		}
	}
	
	option = {#knowledge
		name = court.4500.a
		add_learning_lifestyle_xp = major_lifestyle_xp
		scope:lucky_knight = {
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = 10
			}
		}
		stress_impact = {
			content = minor_stress_loss
			scholar = minor_stress_loss
		}
		ai_chance = {
			base = 100
		}
	}
	option = {#blood
		name = court.4500.b
		random_list = {
			10 = {
				modifier = {
					add = 5
					scope:lucky_knight.learning >= 6
				}
				show_chance = no
				desc = court4500.b_success
				send_interface_toast = {
					title = court4500.b_success
					add_character_modifier = { modifier =
						humor_blood_modifier
						days = 2000						
					}
				}
			}
			10 = {
				modifier = {
					factor = 0
					scope:lucky_knight.learning >= 12
				}
				show_chance = no
				desc = court4500.b_failure
				send_interface_toast = {
					title = court4500.b_failure
					add_character_modifier = { 
						modifier = wrong_potion_modifier 
						days = 2000
					}
				}
			}
		}
		ai_chance = {
			base = 50
		}
	}
	option = {#yellow bile
		name = court.4500.c
		random_list = {
			10 = {
				modifier = {
					add = 5
					scope:lucky_knight = { learning >= 6 }
				}
				show_chance = no
				desc = court4500.b_success
				send_interface_toast = {
					title = court4500.b_success
					add_character_modifier = { modifier =
						humor_yellowbile_modifier
						days = 2000						
					}
				}
			}
			10 = {
				modifier = {
					factor = 0
					scope:lucky_knight = { learning >= 12 }
				}
				show_chance = no
				desc = court4500.b_failure
				send_interface_toast = {
					title = court4500.b_failure
					add_character_modifier = { 
						modifier = wrong_potion_modifier 
						days = 2000
					}
				}
			}
		}
		ai_chance = {
			base = 50
		}
	}
	option = {#black bile
		name = court.4500.d
		random_list = {
			10 = {
				modifier = {
					add = 5
					scope:lucky_knight = { learning >= 6 }
				}
				show_chance = no
				desc = court4500.b_success
				send_interface_toast = {
					title = court4500.b_success
					add_character_modifier = { modifier =
						humor_blackbile_modifier
						days = 2000						
					}
				}
			}
			10 = {
				modifier = {
					factor = 0
					scope:lucky_knight = { learning >= 12 }
				}
				show_chance = no
				desc = court4500.b_failure
				send_interface_toast = {
					title = court4500.b_failure
					add_character_modifier = { 
						modifier = wrong_potion_modifier 
						days = 2000
					}
				}
			}
		}
		ai_chance = {
			base = 50
		}
	}
	option = {#phlegm
		name = court.4500.e
		random_list = {
			10 = {
				modifier = {
					add = 5
					scope:lucky_knight = { learning >= 6 }
				}
				show_chance = no
				desc = court4500.b_success
				send_interface_toast = {
					title = court4500.b_success
					add_character_modifier = { modifier =
						humor_phlegm_modifier
						days = 2000						
					}
				}
			}
			10 = {
				modifier = {
					factor = 0
					scope:lucky_knight = { learning >= 12 }
				}
				show_chance = no
				desc = court4500.b_failure
				send_interface_toast = {
					title = court4500.b_failure
					add_character_modifier = { 
						modifier = wrong_potion_modifier 
						days = 2000
					}
				}
			}
		}
		ai_chance = {
			base = 50
		}
	}
	option = {#NEVER
		name = court.4500.f
		add_piety = minor_piety_gain
		scope:lucky_knight = {
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = -20
			}
		}
		stress_impact = {
			paranoid = medium_stress_loss
			trusting = medium_stress_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = -0.5
			}
		}
	}
}

##################################################
# The Finest Booze Available to Humanity
# by Isabella Welch
# 4600 - 4609
##################################################

scripted_trigger court_4600_cupbearer_trigger = {
	is_available_ai_adult = yes
	drinks_alcohol_trigger = yes
}

scripted_trigger court_4600_cupbearer_friend_trigger = {
	is_available_ai_adult = yes
	OR = {
		opinion = {
			target = scope:cupbearer
			value >= low_negative_opinion
		}
		has_relation_friend = scope:cupbearer
		has_relation_lover = scope:cupbearer
	}
	NOT = { this = scope:cupbearer }
	drinks_alcohol_trigger = yes
}

court.4600 = {
	type = court_event
	title = court.4600.t
	desc = {
		desc = court.4600.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:cupbearer_friend = { has_relation_lover = scope:cupbearer }
				}
				desc = court.4600.desc_lover
			}
			desc = court.4600.desc_friend
		}
		desc = court.4600.desc_ending
	}
	theme = diplomacy
	
	cooldown = { years = 10 }
	court_scene = {
		button_position_character = scope:cupbearer
		roles = {
			scope:cupbearer = {
				group = event_group
				animation = scheme
			}
			scope:cupbearer_friend = {
				group = event_group
				animation = flirtation
			}
		}
	}
	
	trigger = {
		employs_court_position = cupbearer_court_position
		any_court_position_holder = {
			type = cupbearer_court_position
			court_4600_cupbearer_trigger = yes
			has_court_event_flag = no
			save_temporary_scope_as = cupbearer
		}
		any_courtier_or_guest = {
			court_4600_cupbearer_friend_trigger = yes
			has_court_event_flag = no
		}
	}

	weight_multiplier = {
		base = 1

		# Court weightings.
		## Those academics, amirite?
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_scholarly }
	}

	
	immediate = {
		random_court_position_holder = {
			limit = {
				court_4600_cupbearer_trigger = yes
				has_court_position = cupbearer_court_position
			}
			save_scope_as = cupbearer
			court_event_character_flag_effect = yes
		}
		random_courtier_or_guest = {
			limit = {
				court_4600_cupbearer_friend_trigger = yes
			}
			weight = {
				base = 1
				modifier = {
					has_trait = drunkard
					factor = 50
				}
				modifier = {
					has_trait = rakish
					factor = 25
				}
				modifier = {
					has_trait = gluttonous
					factor = 25
				}
				modifier = {
					has_relation_friend = scope:cupbearer
					factor = 25
				}
				modifier = {
					has_relation_lover = scope:cupbearer
					factor = 25
				}
			}
			save_scope_as = cupbearer_friend
			court_event_character_flag_effect = yes
		}
		scope:cupbearer = {
			if = {
				limit = { NOT = { has_trait = drunkard } }
				add_trait = drunkard
			}
		}
	}

	option = { 
		name = court.4600.a
		trigger = {
			NOR = {
				has_focus = intrigue_skulduggery_focus
				has_focus = intrigue_intimidation_focus 
				has_trait = torturer
				has_trait = schemer
			}
		}
		every_courtier_or_guest = {
			limit = {
				NOT = { has_trait = temperate }
			}
			custom = all_courtiers_and_guests
			add_opinion = {
				target = root
				modifier = given_luxuries_opinion
				opinion = 10
			}
		}
		stress_impact = {
			drunkard = minor_stress_loss
			greedy = minor_stress_gain
		}
		change_current_court_grandeur = minor_court_grandeur_gain
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = 0.5
				ai_greed = -0.5
				ai_sociability = 0.75
			}
		}
	}

	option = {
		name = court.4600.b
		trigger = {
			NOR = {
				has_focus = intrigue_skulduggery_focus
				has_focus = intrigue_intimidation_focus 
				has_trait = torturer
				has_trait = schemer
				has_trait = temperate
			}
		}
		revoke_court_position = {
			recipient = scope:cupbearer
			court_position = cupbearer_court_position
		}
		custom_tooltip = court.4600.b.tt
		set_variable = {
			name = protected_alcohol_stores
			value = 1
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = -0.5
				ai_greed = 0.75
				ai_sociability = -0.5
			}
		}
	}
	
	option = {
		name = court.4600.c
		flavor = court.4600.c.tt
		trigger = {
			OR = {
				has_focus = intrigue_skulduggery_focus
				has_focus = intrigue_intimidation_focus 
				has_trait = torturer
				has_trait = schemer
			}
		}
		trait = torturer
		trait = schemer
		add_dread = major_dread_gain
		random_list = {
			10 = {
				compare_modifier = {
					value = intrigue
					multiplier = 0.4
				}
				hidden_effect = {
					send_interface_toast = {
						left_icon = scope:cupbearer
						title = court.4600.c.t
						show_as_tooltip = {
							scope:cupbearer = {
								add_character_modifier = {
									modifier = poisonous_gold_modifier
								}
							}
							scope:cupbearer_friend = {
								add_character_modifier = {
									modifier = poisonous_gold_modifier
								}
							}
						}
					}
				}
				scope:cupbearer = {
					add_character_modifier = {
						modifier = poisonous_gold_modifier
					}
				}
				scope:cupbearer_friend = {
					add_character_modifier = {
						modifier = poisonous_gold_modifier
					}
				}
			}
			10 = {
				hidden_effect = {
					send_interface_toast = {
						title = court.4600.c.t
						left_icon = scope:cupbearer
						show_as_tooltip = {
							scope:cupbearer = {
								death = {
									death_reason = death_poison
								}
							}
							scope:cupbearer_friend = {
								death = {
									death_reason = death_poison
								}
							}
						}
					}
				}
				scope:cupbearer = {
					death = {
						death_reason = death_poison
					}
				}
				scope:cupbearer_friend = {
					death = {
						death_reason = death_poison
					}
				}
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_honor = -0.5
				ai_boldness = 0.5
			}
		}
	}
	option = {
		name = court.4600.d
		custom_tooltip = court.4600.d.tt
		trigger = {
			OR = {
				has_focus = intrigue_skulduggery_focus
				has_focus = intrigue_intimidation_focus 
				has_trait = torturer
				has_trait = schemer
			}
		}
		trait = torturer
		trait = schemer
		duel = {
			skill = intrigue
			value = 10
			8 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 0.3
				}
				hidden_effect = {
					send_interface_toast = {
						left_icon = scope:cupbearer
						left_icon = scope:head_chasing_monk
						title = court.4600.d.cure.t
						custom_tooltip = court.4600.d.cure.tt
					}
				}
				add_intrigue_lifestyle_xp = major_lifestyle_xp 
				add_character_modifier = {
					modifier = poisoned_wine_cellar
					years = 5
				}
			}
			5 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -0.3
				}
				random_list = {
					10 = {
						compare_modifier = {
							value = intrigue
							multiplier = 0.4
						}
						hidden_effect = {
							send_interface_toast = {
								left_icon = scope:cupbearer
								title = court.4600.c.t
								show_as_tooltip = {
									scope:cupbearer = {
										add_character_modifier = {
											modifier = poisonous_gold_modifier
										}
									}
									scope:cupbearer_friend = {
										add_character_modifier = {
											modifier = poisonous_gold_modifier
										}
									}
								}
							}
						}
						scope:cupbearer = {
							add_character_modifier = {
								modifier = poisonous_gold_modifier
							}
						}
						scope:cupbearer_friend = {
							add_character_modifier = {
								modifier = poisonous_gold_modifier
							}
						}
					}
					10 = {
						hidden_effect = {
							send_interface_toast = {
								left_icon = scope:cupbearer
								title = court.4600.c.t
								show_as_tooltip = {
									scope:cupbearer = {
										death = {
											death_reason = death_poison
											killer = root
										}
									}
									scope:cupbearer_friend = {
										death = {
											death_reason = death_poison
											killer = root
										}
									}
								}
							}
						}
						scope:cupbearer = {
							death = {
								death_reason = death_poison
								killer = root
							}
						}
						scope:cupbearer_friend = {
							death = {
								death_reason = death_poison
								killer = root
							}
						}
					}
				}
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = 0.5
				ai_honor = 0.5
			}
		}
	}
	option = {
		name = court.4600.e
		trigger = { has_trait = temperate }
		trait = temperate
		every_courtier_or_guest = {
			limit = { drinks_alcohol_trigger = yes }
			custom = all_courtiers_and_guests
			add_character_modifier = {
				modifier = court_no_wine_modifier
				years = 3
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_honor = 0.5
				ai_sociability = -0.75
			}
		}
	}
	after = {
		scope:cupbearer = {
			clear_court_event_participation = yes
		}
		scope:cupbearer_friend = {
			clear_court_event_participation = yes
		}
	}
}

##################################################
# The Trepanning of the Soul
# by Isabella Welch
# 4700 - 4709
##################################################

scripted_trigger trepanning_vices_trigger = {
	OR = {
		AND = {
			is_cannibal_trigger = yes
			trait_is_criminal_in_faith_trigger = { TRAIT = cannibal FAITH = root.faith GENDER_CHARACTER = root }
		}
		AND = {
			has_trait = adulterer
			trait_is_criminal_in_faith_trigger = { TRAIT = adulterer FAITH = root.faith GENDER_CHARACTER = root }
		}
		AND = {
			has_trait = fornicator
			trait_is_criminal_in_faith_trigger = { TRAIT = fornicator FAITH = root.faith GENDER_CHARACTER = root }
		}
		AND = {
			is_incestuous_trigger = yes
			trait_is_criminal_in_faith_trigger = { TRAIT = incestuous FAITH = root.faith GENDER_CHARACTER = root }
		}
		AND = {
			is_deviant_trigger = yes
			trait_is_criminal_in_faith_trigger = { TRAIT = deviant FAITH = root.faith GENDER_CHARACTER = root }
		}
	}
}

scripted_trigger trepanning_default_trigger = {
	OR = {
		has_trait = possessed_1
		has_trait = possessed
		has_trait = possessed_genetic
		stress_level >= 3
		has_trait = depressed_1
		has_trait = depressed_genetic
		is_witch_trigger = no
		has_trait = lunatic_genetic
		has_trait = lunatic_1
		has_trait = incapable
		has_trait = dull
		has_trait = blind
		trepanning_vices_trigger = no
	}
}

court.4700 = {
	type = court_event
	title = court.4700.t 
	theme = learning_medicine_focus
	desc = {
		first_valid = { #is there trepanning in your realm region?
			triggered_desc = {
				trigger = {
					native_trepanning_trigger = yes
				}
				desc = court.4700.desc_native_trepanning
			}
			triggered_desc = {
				trigger = {
					native_trepanning_trigger = no
				}
				desc = court.4700.desc_foreign_medicine
			}
		}
		first_valid = {
			triggered_desc = { #trepanner suggests a reason you might be inhabited by spirits
				trigger = {
					OR = {
						has_trait = possessed
						has_trait = possessed_genetic
						has_trait = possessed_1
					}
				}
				desc = court.4700.desc_possessed
			}
			triggered_desc = {
				trigger = {
					is_witch_trigger = yes
				}
				desc = court.4700.desc_witch
			}
			triggered_desc = {
				trigger = {
					OR = {
						has_trait = depressed_1
						has_trait = depressed_genetic
					}
				}
				desc = court.4700.desc_melancholic
			}
			triggered_desc = {
				trigger = {
					OR = {
						has_trait = incapable
						has_trait = dull
					}
				}
				desc = court.4700.desc_heavy_mind
			}
			triggered_desc = {
				trigger = {
					has_trait = blind
				}
				desc = court.4700.desc_blind
			}
			triggered_desc = {
				trigger = {
					OR = {
						has_trait = lunatic_genetic
						has_trait = lunatic_1
					}
				}
				desc = court.4700.desc_lunatic
			}
			triggered_desc = {
				trigger = {
					stress_level >= 3
				}
				desc = court.4700.desc_headache
			}
			triggered_desc = {
				trigger = {
					trepanning_vices_trigger = yes
				}
				desc = court.4700.desc_trepanning_vices
			}
		}
	}
	court_scene = {
		button_position_character = scope:trepanner
		roles = {
			scope:trepanner = {
				group = event_group
				animation = scheme
			}
			root = {
				group = event_group
				animation = shock
			}
		}
	}
	
	trigger = {
		has_court_event_flag = no
		NOT = { has_character_flag = has_had_trepanning_event_court_4700 }
		OR = {
			has_trait = possessed
			stress_level >= 2
			has_trait = depressed_1
			has_trait = depressed_genetic
			is_witch_trigger = yes
			has_trait = lunatic_genetic
			has_trait = lunatic_1
			has_trait = incapable
			has_trait = dull
			has_trait = blind
			trepanning_vices_trigger = yes
		}
		OR = {
			native_trepanning_trigger = yes
			AND = {
				native_trepanning_trigger = no
				OR = {
					any_courtier_or_guest = {
						native_trepanning_trigger = yes
					}
					any_vassal = {
						native_trepanning_trigger = yes
					}
				}
			}
		}
	}

	weight_multiplier = {
		base = 1

		# Court weightings.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_scholarly }
	}

	immediate = {
		court_event_character_flag_effect = yes
		add_character_flag = has_had_trepanning_event_court_4700
		if = { #is there trepanning in your realm region? if not, get someone from your vassal's culture
			limit = { native_trepanning_trigger = no }
			if = {
				limit = {
					any_vassal_or_below = {
						native_trepanning_trigger = yes
					}
				}
				random_vassal_or_below = {
					limit = { native_trepanning_trigger = yes }
					weight = {
						base = 1
						modifier = {
							NOR = {
								culture = root.culture
								faith = root.faith
							}
							factor = 2
						}
					}
					save_scope_as = trepanner_foreign_template
				}
			}
			else_if = {
				limit = {
					any_courtier_or_guest = {
						native_trepanning_trigger = yes
					}
				}
				random_courtier_or_guest = {
					limit = {
						native_trepanning_trigger = yes	
					}
					weight = {
						base = 1
						modifier = {
							NOR = {
								culture = root.culture
								faith = root.faith
							}
							factor = 2
						}
					}
					save_scope_as = trepanner_foreign_template
				}
			}
		}
		if = { # trepanner is either your culture or the culture of one with trepanning
			limit = { native_trepanning_trigger = yes }
			create_character = {
				location = root.capital_province
				template = trepanner_character
				faith = root.faith
				culture = root.culture
				save_scope_as = trepanner
			}
		}
		else = {
			create_character = {
				location = root.capital_province
				template = trepanner_character
				faith = scope:trepanner_foreign_template.faith
				culture = scope:trepanner_foreign_template.culture
				save_scope_as = trepanner
			}
		}
		scope:trepanner = {
			add_character_flag = {
    			flag = use_stealth_clothes
				days = 1
			}
			court_event_character_flag_effect = yes
		}
	}

	option = { #stand up for yourself and say this is ludicrous
		name = court.4700.a
		trigger = { trepanning_vices_trigger = no }
		add_stress = medium_stress_gain
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = 0.5
			}
		}
	}

	option = { #attempt the operation
		name = court.4700.b
		flavor = court.4700.b.tt
		if = {
			limit = {
				trepanning_vices_trigger = yes
			}
			every_vassal = { #if you are a criminal, people think you are attempting to do good by altering your twisted mind. It isn't actually going to do anything
				custom = all_vassals
				add_opinion = {
					target = root
					opinion = 10
					modifier = repentant_opinion
				}
			}
		}
		if = {
			limit = { #cannot trepan away genetic or non injury related health conditions
				OR = {
					has_trait = possessed_genetic
					has_trait = depressed_genetic
					has_trait = depressed_1
					has_trait = lunatic_genetic
				}
			}
			custom_tooltip = court.4700.success
			add_character_flag = mental_health_cannot_be_trepanned_away

		}
		else = {
			random_list = {
				10 = { #chance it might help
					trigger = {
						trepanning_default_trigger = yes
						stress_level < 2
					}
					modifier = {
						has_trait = whole_of_body
						add = 4
					}
					modifier = {
						court_physician_available_trigger = yes
						add = 2
					}
					if = {
						limit = {
							OR = {
								has_trait = possessed_1
								has_trait = lunatic_1
								has_trait = incapable
								has_trait = dull
								has_trait = blind
							}
						}
						custom_tooltip = court.4700.removal
					}
					else = {
						custom_tooltip = court.4700.success
					}	
					add_character_flag = trepanning_success
				}
				10 = {
					trigger = { #it won't really help your witch power but the witch god will laugh
						is_witch_trigger = yes
						trepanning_vices_trigger = no
						trepanning_default_trigger = no
					}
					custom_tooltip = court.4700.witch_power
					add_character_flag = trepanning_witch_power
					modifier = {
						has_trait = whole_of_body
						add = 4
					}
					modifier = {
						court_physician_available_trigger = yes
						add = 2
					}
				}
				10 = { # you cannot trepan away your mental state if you are a criminal, even if people thought vice was an illness in the past
					trigger = {
						is_witch_trigger = no
						trepanning_vices_trigger = yes
						trepanning_default_trigger = no
					}
					custom_tooltip = court.4700.success
					add_character_flag = trepanning_vices_operation
					modifier = {
						has_trait = whole_of_body
						add = 4
					}
					modifier = {
						court_physician_available_trigger = yes
						add = 2
					}
				}
				10 = {
					trigger = { #might get rid of stress headaches
						stress_level >= 2
					}
					custom_tooltip = court.4700.headache
					add_character_flag = trepanning_headache_operation
					show_as_tooltip = {
						add_stress = massive_stress_loss
					}
					modifier = {
						has_trait = whole_of_body
						add = 4
					}
					modifier = {
						court_physician_available_trigger = yes
						add = 2
					}
				}
				10 = { #good chance there will be no effect
					add_character_flag = trepanning_no_result
					custom_tooltip = court.4700.no_success
				}
				10 = { #might cause you brain damage
					add_character_flag = trepanning_mental_injury
					custom_tooltip = court.4700.mental_faculties
					compare_modifier = {
						value = health
						multiplier = -0.4
					}
					modifier = {
						has_trait = whole_of_body
						add = -4
					}
					modifier = {
						court_physician_available_trigger = yes
						add = -2
					}
				}
				10 = { #might just hurt you physically
					add_character_flag = trepanning_physical_injury
					custom_tooltip = court.4700.physical_faculties
					compare_modifier = {
						value = health
						multiplier = -0.4
					}
					modifier = {
						has_trait = whole_of_body
						add = -4
					}
					modifier = {
						court_physician_available_trigger = yes
						add = -2
					}
				}
			}
		}
		trigger_event = {
			id = court.4701
			days = { 15 30 }
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = -0.5
				ai_rationality = 0.5
			}
		}
	}
	option = { #stand up for yourself criminal version
		name = court.4700.c
		trigger = { trepanning_vices_trigger = yes }
		add_stress = medium_stress_gain
		every_vassal = {
			limit = { NOT = { has_trait = compassionate } }
			custom = all_vassals
			add_opinion = {
				target = root
				opinion = -5
				modifier = unrepentant_opinion
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = 0.5
			}
		}
	}
	option = { #politely decline but get your physician to learn from this practice
		name = court.4700.d
		trigger = { court_physician_available_trigger = yes }
		add_courtier = scope:trepanner
		save_court_physician_as_effect = { SCOPE_NAME = court_physician }
		scope:court_physician = {
			add_character_modifier = {
				modifier = medicine_student_modifier
				years = 10
			}
		}
		hidden_effect = {  #trepanner joins the court and a chance for future hijinks
			random_list = {
				10 = {
					scope:trepanner = {
						set_relation_friend = { reason = friend_approves_methods target = scope:court_physician }
					}
				}
				10 = {
					scope:trepanner = {
						set_relation_rival = {
							target = scope:court_physician
							reason = rival_trepanning
						}
					}
				}
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = -0.5
				ai_greed = 0.5
				ai_rationality = 0.75
			}
		}
	}
	after = {
		clear_court_event_participation = yes
		scope:trepanner = {
			clear_court_event_participation = yes
		}
	}
}

# Anything which could feasibly be linked to a brain injury has a chance of getting cured. This means some non genetic issues
scripted_effect trepanning_removal_scripted_effect = {
	if = {
		limit = {
			has_trait = possessed_1
		}
		remove_trait = possessed_1
	}
	if = {
		limit = {
			has_trait = depressed_1
		}
		remove_trait = depressed_1
	}
	if = {
		limit = {
			has_trait = lunatic_1
		
		}
		remove_trait = lunatic_1
	}
	if = {
		limit = {
			has_trait = incapable
		
		}
		remove_trait = incapable
	}
	if = {
		limit = {
			has_trait = dull
		}
		remove_trait = dull
	}
	if = {
		limit = {
			has_trait = blind
		}
		remove_trait = blind
	}
}

court.4701 = {
	type = character_event
	title = court.4700.t
	desc = { 
		first_valid = { #physician reacts, is it in their study?
			triggered_desc = {
				trigger = {
					court_physician_available_trigger = yes
				}
				desc = court.4701.physician_study
			}
			desc = court.4701.no_physician
		}
		first_valid = { #physician reacts, are they worried or do they not care?
			triggered_desc = {
				trigger = {
					court_physician_available_trigger = yes
					native_trepanning_trigger = yes
					scope:court_physician = {
						NOR = {
							has_trait = compassionate
							opinion = {
								target = root
								value >= medium_positive_opinion
							}
						}
					}
				}
				desc = court.4701.physician_excited
			}
			triggered_desc = {
				trigger = {
					court_physician_available_trigger = yes
					native_trepanning_trigger = no
					scope:court_physician = {
						NOR = {
							has_trait = compassionate
							opinion = {
								target = root
								value >= medium_positive_opinion
							}
						}
					}
				}
				desc = court.4701.physician_excited_2
			}
			triggered_desc = {
				trigger = {
					court_physician_available_trigger = yes
					native_trepanning_trigger = yes
					scope:court_physician = {
						OR = {
							has_trait = compassionate
							opinion = {
								target = root
								value >= medium_positive_opinion
							}
						}
					}
				}
				desc = court.4701.physician_concerned
			}
			triggered_desc = {
				trigger = {
					court_physician_available_trigger = yes
					native_trepanning_trigger = no
					scope:court_physician = {
						OR = {
							has_trait = compassionate
							opinion = {
								target = root
								value >= medium_positive_opinion
							}
						}
					}
				}
				desc = court.4701.physician_concerned_2
			}
		}
		first_valid = { #how is the trepanning conducted?
			triggered_desc = {
				trigger = {
					has_character_flag = mental_health_cannot_be_trepanned_away
				}
				desc = court.4701.mental_health_cannot_be_trepanned_away
			}
			triggered_desc = {
				trigger = {
					has_character_flag = trepanning_success
				}
				desc = court.4701.trepanning_success
			}
			triggered_desc = {
				trigger = {
					has_character_flag = trepanning_witch_power
				}
				desc = court.4701.trepanning_witch_power
			}
			triggered_desc = {
				trigger = {
					has_character_flag = trepanning_vices_operation
				}
				desc = court.4701.trepanning_vices_operation
			}
			triggered_desc = {
				trigger = {
					has_character_flag = trepanning_headache_operation
				}
				desc = court.4701.trepanning_headache_operation
			}
			triggered_desc = {
				trigger = {
					has_character_flag = trepanning_mental_injury
				}
				desc = court.4701.trepanning_mental_injury
			}
			triggered_desc = {
				trigger = {
					OR = {
						has_character_flag = trepanning_physical_injury
						has_character_flag = trepanning_no_result
					}		
				}
				desc = court.4701.trepanning_physical_injury
			}
		}
		first_valid = { #what is the outcome?
			triggered_desc = {
				trigger = {
					has_character_flag = incapable_mental_injury
				}
				desc = court.4701.trepanning_incapable_injury
			}
			triggered_desc = {
				trigger = {
					has_character_flag = possessed_mental_injury
				}
				desc = court.4701.trepanning_possessed_injury
			}
			triggered_desc = {
				trigger = {
					has_character_flag = deviant_mental_injury
				}
				desc = court.4701.trepanning_deviant_injury
			}
			triggered_desc = {
				trigger = {
					has_character_flag = trepanning_learning_penalty
				}
				desc = court.4701.trepanning_learning_penalty
			}
			triggered_desc = {
				trigger = {
					OR = {
						has_character_flag = scarred_physical_injury
						has_character_flag = trepanning_no_result
					}
				}
				desc = court.4701.trepanning_no_result
			}
			triggered_desc = {
				trigger = {
					has_character_flag = infirm_physical_injury
				}
				desc = court.4701.trepanning_coordination_penalty
			}
			triggered_desc = {
				trigger = {
					has_character_flag = blind_physical_injury
				}
				desc = court.4701.trepanning_blind_injury
			}
			triggered_desc = {
				trigger = {
					has_character_flag = trepanning_coordination_penalty
				}
				desc = court.4701.trepanning_coordination_penalty
			}
		}
	}
	theme = learning_medicine_focus
	override_background = {
		reference = physicians_study
	}
	left_portrait = { 
		character = root
		animation = worry
	}
	right_portrait = {
		character = scope:trepanner
		animation = flirtation
	}
	lower_right_portrait = {
		character = scope:court_physician
	}

	on_trigger_fail = {
		remove_character_flag = trepanning_success
		remove_character_flag = trepanning_witch_power
		remove_character_flag = trepanning_vices_operation
		remove_character_flag = trepanning_headache_operation
		remove_character_flag = trepanning_mental_injury
		remove_character_flag = trepanning_physical_injury
		remove_character_flag = incapable_mental_injury
		remove_character_flag = possessed_mental_injury
		remove_character_flag = deviant_mental_injury
		remove_character_flag = incapable_mental_injury
		remove_character_flag = scarred_physical_injury
		remove_character_flag = infirm_physical_injury
		remove_character_flag = blind_physical_injury
		remove_character_flag = trepanning_coordination_penalty
		remove_character_flag = mental_health_cannot_be_trepanned_away
		remove_character_flag = trepanning_no_result
	}

	trigger = {
		has_royal_court = yes
		OR = {
			has_trait = possessed
			stress_level >= 2
			has_trait = depressed_1
			has_trait = depressed_genetic
			is_witch_trigger = yes
			has_trait = lunatic_genetic
			has_trait = lunatic_1
			has_trait = incapable
			has_trait = dull
			has_trait = blind
			trepanning_vices_trigger = yes
		}
		has_character_flag = has_had_trepanning_event_court_4700
		scope:trepanner = {
			is_available_ai_adult = yes
		}
	}

	immediate = {
		if = {
			limit = { court_physician_available_trigger = yes }
			save_court_physician_as_effect = { SCOPE_NAME = court_physician }
		}
		if = {
			limit = { has_character_flag = trepanning_mental_injury }
			increase_wounds_no_death_effect = { REASON = treatment }
			random_list = { #random list of which negative mental effect you might get
				10 = {
					trigger = { NOT = { has_trait = incapable } }
					add_trait = incapable
					add_character_flag = incapable_mental_injury
				}
				10 = {
					trigger = {
						NOR = { 
							has_trait = possessed_1
							has_trait = possessed_genetic
						}
					}
					add_trait = possessed_1
					add_character_flag = possessed_mental_injury
				}
				100 = {
					trigger = { 
						NOT = { 
							has_trait = deviant
						}
					}
					add_trait = deviant
					add_character_flag = deviant_mental_injury
				}
				10 = {
					add_character_modifier = trepanning_learning_penalty_modifier
					add_character_flag = trepanning_learning_penalty
				}
			}
		}
		if = {
			limit = { has_character_flag = trepanning_physical_injury }
			increase_wounds_no_death_effect = { REASON = treatment }
			random_list = { #random list of which negative physical health effect you might get
				10 = {
					trigger = { NOT = { has_trait = scarred } }
					add_trait = scarred
					add_trait_xp = {
		                trait = scarred
		                value = {
		                    integer_range = {
		                        min = 5
		                        max = 25
		                    }
		                }
		            }
					add_character_flag = scarred_physical_injury
				}
				10 = {
					trigger = { NOT = { has_trait = blind } }
					add_trait = blind
					add_character_flag = blind_physical_injury
					}
				10 = {
					trigger = { NOT = { has_trait = infirm } }
					add_trait = infirm
					add_character_flag = infirm_physical_injury
				}
				10 = {
					add_character_modifier = {
						modifier = trepanning_coordination_penalty_modifier
					}
					add_character_flag = trepanning_coordination_penalty
				}
			}
		}
		if = {
			limit = { #get slightly damaged no matter what
				has_character_flag = trepanning_no_result
			}
			increase_wounds_no_death_effect = { REASON = treatment }
		}
		if = {
			limit = { #can actually help if you got the right outcome in the previous event
				has_character_flag = trepanning_success
			}
			trepanning_removal_scripted_effect = yes
		}
		if = {
			limit = { #get wounded but lose stress if you had the stress version
				has_character_flag = trepanning_headache_operation
			}
			increase_wounds_no_death_effect = { REASON = treatment }
			add_stress = major_stress_loss
		}
	}

	option = { #almost all of these are just options informing you of what has happened, rather than consequential results
		name = court.4701.a
		trigger = {
			has_character_flag = trepanning_mental_injury
		}
		ai_chance = {
			base = 50
		}
	}

	option = {
		name = court.4701.b
		trigger = {
			has_character_flag = trepanning_physical_injury
			NOT = { has_character_flag = scarred_physical_injury }
		}
		ai_chance = {
			base = 75
		}
	}
	
	option = {
		name = court.4701.c
		trigger = {
			OR = {
				has_character_flag = trepanning_physical_injury
				has_character_flag = trepanning_no_result
				is_witch_trigger = yes
			}
		}
		if = {
			limit = { is_witch_trigger = yes }
			every_vassal = {
				limit = { is_witch_trigger = yes }
				custom = custom.every_witch
				add_opinion = {
					target = root
					modifier = respect_opinion
					opinion = 10
				}
			}
		}
		ai_chance = {
			base = 50
		}
	}
	option = { 
		name = court.4701.d
		trigger = {
			has_character_flag = possessed_mental_injury
		}
		ai_chance = {
			base = 50
		}
	}
	option = { 
		name = court.4701.e
		trigger = {
			has_character_flag = deviant_mental_injury
		}
		ai_chance = {
			base = 50
		}
	}
	option = { 
		name = court.4701.f
		trigger = {
			has_character_flag = trepanning_success
		}
		ai_chance = {
			base = 50
		}
	}

	option = { 
		name = court.4701.g
		trigger = {
			has_character_flag = trepanning_vices_operation
		}
		ai_chance = {
			base = 50
		}
	}
	option = { 
		name = court.4701.h
		trigger = {
			has_character_flag = trepanning_success
		}
		ai_chance = {
			base = 50
		}
	}
	option = { 
		name = court.4701.i
		trigger = {
			has_character_flag = mental_health_cannot_be_trepanned_away
		}
		ai_chance = {
			base = 50
		}	
	}

	after = {
		remove_character_flag = trepanning_success
		remove_character_flag = trepanning_witch_power
		remove_character_flag = trepanning_vices_operation
		remove_character_flag = trepanning_headache_operation
		remove_character_flag = trepanning_mental_injury
		remove_character_flag = trepanning_physical_injury
		remove_character_flag = incapable_mental_injury
		remove_character_flag = possessed_mental_injury
		remove_character_flag = deviant_mental_injury
		remove_character_flag = incapable_mental_injury
		remove_character_flag = scarred_physical_injury
		remove_character_flag = infirm_physical_injury
		remove_character_flag = blind_physical_injury
		remove_character_flag = trepanning_coordination_penalty
		remove_character_flag = mental_health_cannot_be_trepanned_away
		remove_character_flag = trepanning_no_result
	}
}

##################################################
# I Need a Hero
# by Isabella Welch
# 4750 - 4759
##################################################

scripted_trigger pope_joan_trigger = {
	#AGOT Disabled, Zhea Zorseface
	# faith = faith:catholic
	is_female = yes
	any_held_title = { is_head_of_faith = no }
}

scripted_trigger lady_godiva_trigger = {
	#AGOT Modified, Jonquil the Maid
	# OR = {
	# 	root.culture = culture:anglo_saxon
	# 	root.culture = {
	# 		any_parent_culture = { this = culture:anglo_saxon }
	# 	}
	# 	root.culture = culture:english
	# 	root.culture = {
	# 		any_parent_culture = { this = culture:english }
	# 	}
	# }
	is_female = yes
}

scripted_trigger sinbad_trigger = {
	capital_province = {
		OR = {
			#AGOT Modified, Lomas Longstrider
			# geographical_region = world_middle_east
			# geographical_region = world_africa_east
			# geographical_region = world_africa_north
			geographical_region = world_westeros
		}
	}
}

scripted_trigger caligula_trigger = {
	OR = {
		has_trait = sadistic
		has_trait = torturer
		has_focus = intrigue_intimidation_focus
		has_trait = deviant
		has_trait = lunatic_1
	}
	#AGOT Disabled, Tyrion II
	# OR = {
	# 	has_title = title:k_italy
	# 	has_title = title:k_romagna
	# 	has_title = title:k_sardinia
	# 	has_title = title:e_italy
	# 	has_title = title:e_roman_empire
	# 	capital_province = {
	# 		geographical_region = world_europe_west_britannia
	# 		geographical_region = world_europe_west_germania
	# 		geographical_region = world_europe_west_francia
	# 		geographical_region = world_europe_west_iberia
	# 		geographical_region = world_europe_west
	# 		geographical_region = world_europe_south_italy
	# 		geographical_region = world_europe_south
	# 	}
	# 	culture = { has_cultural_pillar = heritage_byzantine }
	# }
}

scripted_trigger nasreddin_trigger = {
	#AGOT Modified, Mushroom
	# OR = {
	# 	culture = culture:uyghur
	# 	culture = culture:afghan
	# 	root.culture = {
	# 		has_cultural_pillar = heritage_indo_aryan
	# 		has_cultural_pillar = heritage_dravidian
	# 	}
	# 	capital_province = {
	# 		geographical_region = world_middle_east
	# 		geographical_region = world_middle_east_persia
	# 		geographical_region = world_middle_east_arabia
	# 		geographical_region = world_india
	# 		geographical_region = world_asia_minor
	# 	}
	# }
	# current_year >1230
	capital_province = { geographical_region = world_westeros }
}

scripted_trigger valmiki_trigger = {
	#AGOT Modified, Bael the Bard
	# root.culture = {
	# 	has_cultural_pillar = heritage_indo_aryan
	# }
	capital_province = { geographical_region = world_westeros }
}

court.4750 = {
	type = court_event
	title = court.4750.t
	desc = court.4750.desc
	theme = court

	trigger = {
		has_court_event_flag = no
		NOT = { has_trait = blind }
		employs_court_position = court_poet_court_position
		any_court_position_holder = {
			type = court_poet_court_position
			is_available_ai_adult = yes
			has_court_event_flag = no
		}
	}
	cooldown = { years = 10 }
	court_scene = {
		button_position_character = scope:poet
		roles = {
			scope:poet = {
				group = event_group
				animation = happiness
			}
			root = {
				group = event_group
				animation = personality_bold
			}
		}
	}

	weight_multiplier = {
		base = 1

		# Court weightings.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_warlike }
	}

	immediate = {
		court_event_character_flag_effect = yes
		random_court_position_holder = {
			type = court_poet_court_position
			limit = {
				is_available_ai_adult = yes
			}
			save_scope_as = poet
			court_event_character_flag_effect = yes
		}
	}

	option = { 
		name = court.4750.a
		add_character_flag = pope_joan
		trigger = {
			pope_joan_trigger = yes
		}
		change_current_court_grandeur = minor_court_grandeur_gain
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_zeal = 0.5
				ai_vengefulness = -0.5
			}
		}
	}

	option = {
		name = court.4750.b
		add_character_flag = lady_godiva
		trigger = {
			lady_godiva_trigger = yes
		}
		change_current_court_grandeur = minor_court_grandeur_gain
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = 0.5
			}
		}
	}
	
	option = {
		name = court.4750.c
		add_character_flag = sinbad
		add_character_flag = ruler_character
		trigger = {
			sinbad_trigger = yes
			lady_godiva_trigger = no
		}
		change_current_court_grandeur = minor_court_grandeur_gain
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = 0.25
				ai_rationality = -0.5
			}
		}
	}
	option = {
		name = court.4750.d
		add_character_flag = caligula
		trigger = {
			caligula_trigger = yes
		}
		change_current_court_grandeur = minor_court_grandeur_gain
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_vengefulness = 0.75
				ai_rationality = -0.5
			}
		}
	}

	option = {
		name = court.4750.e
		add_character_flag = nasreddin
		add_character_flag = ruler_character
		trigger = {
			nasreddin_trigger = yes
			lady_godiva_trigger = no
			pope_joan_trigger = no
		}
		change_current_court_grandeur = minor_court_grandeur_gain
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_honor = 0.75
				ai_rationality = 0.5
			}
		}
	}

	option = {
		name = court.4750.f
		add_character_flag = valmiki
		trigger = {
			valmiki_trigger = yes
			lady_godiva_trigger = no
			pope_joan_trigger = no
		}
		change_current_court_grandeur = minor_court_grandeur_gain
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_honor = 0.75
				ai_rationality = 0.5
			}
		}
	}
	option = {
		name = court.4750.g
		add_character_flag = ruler_hero	
		change_current_court_grandeur = minor_court_grandeur_gain
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = 0.5
				ai_greed = 0.75
			}
		}
	}

	option = {
		name = court.4750.h
		add_character_flag = rejected_poet
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = -0.5
				ai_greed = -0.75
			}
		}
		reverse_add_opinion = {
			target = scope:poet
			modifier = insulted_opinion
		}
	}

	after = {
		if = {
			limit = { NOT = { has_character_flag = rejected_poet } }
			trigger_event = {
				id = court.4751
				days = 30
			}
		}
		remove_character_flag = rejected_poet
		clear_court_event_participation = yes
		scope:poet = {
			clear_court_event_participation = yes
		}
	}
}

scripted_effect court_4751_flag_removal_effect = {
	remove_character_flag = ruler_character
	remove_character_flag = pope_joan
	remove_character_flag = ruler_hero
	remove_character_flag = lady_godiva
	remove_character_flag = sinbad
	remove_character_flag = caligula
	remove_character_flag = nasreddin
	remove_character_flag = valmiki
}

court.4751 = {
	type = character_event
	title = court.4750.t
	desc = {
		desc = court.4751.intro
		first_valid = {
			triggered_desc = {
				trigger = {
					has_character_flag = pope_joan
				}
				desc = court.4751.topic.pope_joan
			}
			triggered_desc = {
				trigger = {
					has_character_flag = lady_godiva
				}
				desc = court.4751.topic.lady_godiva
			}
			triggered_desc = {
				trigger = {
					has_character_flag = sinbad
				}
				desc = court.4751.topic.sinbad
			}
			triggered_desc = {
				trigger = {
					has_character_flag = caligula
				}
				desc = court.4751.topic.caligula
			}
			triggered_desc = {
				trigger = {
					has_character_flag = nasreddin
				}
				desc = court.4751.topic.nasreddin
			}
			triggered_desc = {
				trigger = {
					has_character_flag = valmiki
				}
				desc = court.4751.topic.valmiki
			}
			triggered_desc = {
				trigger = {
					has_character_flag = ruler_hero
				}
				desc = court.4751.topic.ruler_hero
			}
		}
		desc = court.4751.topic.unexpected
		first_valid = {
			triggered_desc = {
				trigger = {
					has_character_flag = ruler_character
				}
				desc = court.4751.ruler_character
			}
			triggered_desc = {
				trigger = {
					has_character_flag = pope_joan
				}
				desc = court.4701.pope_joan_desc
			}
			triggered_desc = {
				trigger = {
					has_character_flag = ruler_hero
				}
				desc = court.4701.ruler_hero_desc
			}
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					has_character_flag = lady_godiva
				}
				desc = court.4751.topic.lady_godiva_desc
			}
			triggered_desc = {
				trigger = {
					has_character_flag = sinbad
				}
				desc = court.4751.topic.sinbad_desc
			}
			triggered_desc = {
				trigger = {
					has_character_flag = caligula
				}
				desc = court.4751.topic.caligula_desc
			}
			triggered_desc = {
				trigger = {
					has_character_flag = nasreddin
				}
				desc = court.4751.topic.nasreddin_desc
			}
			triggered_desc = {
				trigger = {
					has_character_flag = valmiki
				}
				desc = court.4751.topic.valmiki_desc
			}
		}
	}
	theme = diplomacy_majesty_focus
	trigger = {
		scope:poet = {
			is_alive = yes
			is_available = yes
		}
		is_available = yes
		OR = {
			NOT = { has_character_flag = pope_joan }
			AND = {
				has_character_flag = pope_joan
				pope_joan_trigger = yes
			}
		}
	}
	on_trigger_fail = {
		court_4751_flag_removal_effect = yes
	}

	immediate = {
		hidden_effect = {
			if = {
				limit = {
					has_character_flag = pope_joan
					scope:poet = { NOT = { has_trait = zealous } }
				}
				scope:poet = {
					add_secret = {
						type = secret_non_believer
					}
				}
				faith.religious_head = {
					save_scope_as = current_head_of_faith
				}
			}
		}
	
		save_scope_as = owner
	}

	option = { 
		name = court.4751.a
		trigger = {
			has_character_flag = pope_joan
			is_attracted_to_gender_of = scope:poet
		}
		if = {
			limit = {
				can_set_relation_potential_lover_trigger = { CHARACTER = scope:poet }
			}
			set_relation_potential_lover = scope:poet
		}
		create_artifact = {
			name = pope_joan_book_name
			description = pope_joan_book_desc
			type = book
			visuals = book
			modifier = artifact_monthly_piety_2_modifier
			save_scope_as = pope_joan_book
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = 0.75
				ai_rationality = -0.5
				ai_zeal = -0.75
			}
		}
	}

	option = {
		name = court.4751.b
		trigger = {
			has_character_flag = pope_joan
			NOT = { root = scope:current_head_of_faith }
		}
		create_artifact = {
			name = pope_joan_book_name
			description = pope_joan_book_desc
			type = book
			visuals = book
			modifier = artifact_monthly_piety_2_modifier
			save_scope_as = pope_joan_book
		}
		hidden_effect = {
			scope:current_head_of_faith = {
				if = {
					limit = { is_ai = yes }
					random_list = {
						10 = {
							trigger = {
								is_cannibal_trigger = no
							}
							add_secret = {
								type = secret_cannibal
							}
						}
						10 = {
							trigger = {
								is_deviant_trigger = no
							}
							add_secret = {
								type = secret_deviant
							}
						}
						10 = {
							trigger = {
								NOT = { any_secret = { secret_type = secret_non_believer } }
							}
							give_non_believer_secret_effect = yes
						}
						10 = {
							trigger = {
								NOT = { has_trait = fornicator }
							}
							add_trait = fornicator
						}
					}
				}
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = 0.75
				ai_rationality = -0.5
				ai_zeal = 0.75
			}
		}
	}
	
	option = {
		name = court.4751.c
		flavor = court.4751.c.tt
		add_character_modifier = {
			modifier = compared_to_lady_godiva
			years = 5
		}
		trigger = {
			has_character_flag = lady_godiva
		}
		if = {
			limit = {
				any_relation = {
					type = potential_lover
				}
			}
			random_relation = {
				type = potential_lover
				save_scope_as = potential_lover
			}
			progress_towards_lover_effect = {
				CHARACTER = scope:potential_lover
				REASON = lover_court_godiva
				OPINION = 0
			}
		}
		random_courtier_or_guest = {
			limit = {
				is_attracted_to_gender_of = root
				root = { is_attracted_to_gender_of = prev }
			}
			weight = {
				base = 1
				modifier = {
					has_trait = lustful
					add = 50
				}
				modifier = {
					has_trait = beauty_good 
					add = 50
				}
			}
			set_relation_potential_lover = root
		}
		random_vassal = {
			limit = {
				is_attracted_to_gender_of = root
				root = { is_attracted_to_gender_of = prev }
			}
			set_relation_potential_lover = root
			weight = {
				base = 1
				modifier = {
					has_trait = lustful
					add = 50
				}
				modifier = {
					has_trait = beauty_good 
					add = 50
				}
			}
		}
		create_artifact = {
			name = lady_godiva_book_name
			description = lady_godiva_book_desc
			type = book
			visuals = book
			modifier = artifact_attraction_opinion_3_modifier
			save_scope_as = lady_godiva_book
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_greed = 0.75
			}
		}
	}
	option = {
		name = court.4751.d
		trigger = {
			has_character_flag = caligula
		}
		add_trait = flagellant
		create_artifact = {
			name = caligula_book_name
			description = caligula_book_desc
			type = book
			visuals = book
			modifier = artifact_dread_gain_mult_1_modifier
			save_scope_as = caligula_book
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_vengefulness = 0.75
				ai_rationality = -0.5
				ai_honor = -0.75
			}
		}
	}

	option = {
		name = court.4751.e
		trigger = {
			has_character_flag = nasreddin
		}
		add_character_modifier = {
			modifier = compared_to_nasreddin
			years = 5
		}
		create_artifact = {
			name = nasreddin_book_name
			description = nasreddin_book_desc
			type = book
			visuals = book
			modifier = artifact_monthly_diplomacy_lifestyle_xp_1_modifier
			save_scope_as = nasreddin_book
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_honor = 0.75
			}
		}
	}
	option = {
		name = court.4751.f
		trigger = {
			NOT = {
				has_character_flag = pope_joan
			}
		}
		if = {
			limit = { has_character_flag = valmiki }
			add_character_modifier = {
				modifier = compared_to_valmiki
				years = 5
			}
			create_artifact = {
				name = valmiki_book_name
				description = valmiki_book_desc
				type = book
				visuals = book
				modifier = artifact_monthly_diplomacy_lifestyle_xp_1_modifier
				save_scope_as = valmiki_book
			}
		}
		if = {
			limit = { has_character_flag = caligula }
			add_character_modifier = {
				modifier = compared_to_caligula
				years = 5
			}
			create_artifact = {
				name = caligula_book_name
				description = caligula_book_desc
				type = book
				visuals = book
				modifier = artifact_monthly_diplomacy_lifestyle_xp_1_modifier
				save_scope_as = caligula_book
			}
		}
		if = {
			limit = {
				has_character_flag = ruler_hero
			}
			create_artifact = {
				name = ruler_hero_book_name
				description = ruler_hero_book_desc
				type = book
				visuals = book
				modifier = artifact_monthly_diplomacy_lifestyle_xp_1_modifier
				save_scope_as = ruler_hero_book
			}
		}
		if = {
			limit = {
				has_character_flag = sinbad
			}
			add_character_modifier = {
				modifier = compared_to_sinbad
				years = 5
			}
			create_artifact = {
				name = sinbad_book_name
				description = sinbad_book_desc
				type = book
				visuals = book
				modifier = artifact_monthly_martial_lifestyle_xp_1_modifier
				save_scope_as = sinbad_hero_book
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_sociability = 0.75
			}
		}
	}
	option = {
		name = court.4751.g
		trigger = { has_character_flag = ruler_hero }
		create_artifact = {
			name = ruler_hero_book_name
			description = ruler_hero_book_desc
			type = book
			visuals = book
			modifier = artifact_monthly_diplomacy_lifestyle_xp_1_modifier
			save_scope_as = ruler_hero_book
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_honor = 0.75
			}
		}
	}
	option = {
		name = court.4751.h
		scope:poet = {
			add_opinion = {
				modifier = insulted_opinion
				years = 5
				target = root
			}
		}
		if = {
			limit = { has_character_flag = lady_godiva }
			every_courtier_or_guest = {
				limit = { has_trait = lustful }
				custom = all_lustful_in_the_court
				add_opinion = {
					modifier = disappointed_opinion
					opinion = -10
					target = root
				}
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_vengefulness = 0.75
			}
		}
	}
}

##################################################
# Ready to Burst
# by Isabella Welch
# 4801
##################################################

scripted_trigger court_4801_poopy_child_trigger = {
	is_child_of = root
	age < 5
	age > 2
}

court.4801 = {
	type = court_event
	title = court.4801.t
	desc = court.4801.desc
	cooldown = { years = 10 }
	theme = court
	
	trigger = {
		has_court_event_flag = no
		any_child = {
			court_4801_poopy_child_trigger = yes
			has_court_event_flag = no
		}
		has_royal_court = yes
		court_owner = {
			amenity_level = { 
				type = court_servants
				value < medium_amenity_level
			}
		}
	}
	court_scene = {
		button_position_character = scope:poopy_child
		roles = {
			scope:poopy_child = {
				group = event_group
				animation = happiness
			}
			root = {
				group = event_group
				animation = shock
			}
		}
	}

	weight_multiplier = {
		base = 1

		# Court weightings.
		## Tbh this one is probably a fairly universal experience.
	}

	immediate = {
		court_event_character_flag_effect = yes
		random_child = {
			limit = {
				court_4801_poopy_child_trigger = yes
			}
			save_scope_as = poopy_child
			court_event_character_flag_effect = yes
		}
		root = { save_scope_as = parent }
	}

	option = { 
		name = court.4801.a
		change_current_court_grandeur = minor_court_grandeur_loss
		add_character_modifier = {
			modifier = drenched_in_excrement_roco_modifier
			days = 30
		}
		reverse_add_opinion = {
			target = scope:poopy_child
			opinion = 40
			modifier = supportive_parent
			years = 10
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = 0.5
			}
		}
	}

	option = {
		name = court.4801.b
		add_prestige = miniscule_prestige_gain
		reverse_add_opinion = {
			target = scope:poopy_child
			opinion = -15
			modifier = insulted_opinion
			years = 5
		}
		change_current_court_grandeur = minor_court_grandeur_gain
		scope:poopy_child = {
			add_character_modifier = {
				modifier = overflowing_diaper
				years = 2
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = -0.5
			}
		}
	}
	after = {
		clear_court_event_participation = yes
		scope:poopy_child = {
			clear_court_event_participation = yes
		}
	}
}

##################################################
# Education under Duress
# by Isabella Welch
# 4802
##################################################

court.4802 = {
	type = court_event
	title = court.4802.t
	desc = court.4802.desc
	theme = court
	cooldown = { years = 10 }
	trigger = {
		any_courtier_or_guest = {
			age < 15
			count > 3
			has_court_event_flag = no
		}
		any_court_position_holder = {
			type = court_tutor_court_position
			is_available_ai_adult = yes
			has_court_event_flag = no
		}
	}
	court_scene = {
		button_position_character = scope:court_tutor
		roles = {
			scope:court_tutor = {
				group = event_group
				animation = fear
			}
			scope:child_1 = {
				group = event_group
				animation = happiness
			}
			scope:child_2 = {
				group = event_group
				animation = happiness
			}
		}
	}

	weight_multiplier = {
		base = 1

		# Court weightings.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_scholarly }
	}

	immediate = {
		random_courtier_or_guest = {
			limit = { 
				age < 15
			}
			weight = {
				base = 1
				modifier = {
					is_child_of = root
					factor = 5
				}
			}
			save_scope_as = child_1
			court_event_character_flag_effect = yes
		}
		random_courtier_or_guest = {
			limit = { 
				age < 15
				NOT = {
					this = scope:child_1
				}
			}
			weight = {
				base = 1
				modifier = {
					is_child_of = root
					factor = 5
				}
			}
			save_scope_as = child_2
			court_event_character_flag_effect = yes
		}
		random_courtier_or_guest = {
			limit = { 
				age < 15
				NOR = {
					this = scope:child_1
					this = scope:child_2
				}
			}
			weight = {
				base = 1
				modifier = {
					is_child_of = root
					factor = 5
				}
			}
			save_scope_as = child_3
			court_event_character_flag_effect = yes
		}
		random_courtier_or_guest = {
			limit = { 
				age < 15
				NOR = {
					this = scope:child_1
					this = scope:child_2
					this = scope:child_3
				}
			}
			weight = {
				base = 1
				modifier = {
					is_child_of = root
					factor = 5
				}
			}
			save_scope_as = child_4
			court_event_character_flag_effect = yes
		}
		random_court_position_holder = {
			type = court_tutor_court_position
			limit = { is_available_ai_adult = yes }
			save_scope_as = court_tutor
			court_event_character_flag_effect = yes
		}
		random_list = {
			9 = {
				scope:court_tutor = {
					every_courtier_or_guest = {
						limit = {
							age < 15
						}
						custom = custom.every_child_in_court
						reverse_add_opinion = {
							target = scope:court_tutor
							modifier = hate_opinion
							opinion = -30
						}
					}
				}
			}
			1 = {
				scope:court_tutor = {
					add_trait = irritable
				}
			}
		}
	}

	option = { 
		name = court.4802.a
		if = {
			limit = {
				exists = scope:child_1 
			}
			reverse_add_opinion = {
				target = scope:child_1
				opinion = 10
				modifier = compliment_opinion
			}
		}
		if = {
			limit = {
				exists = scope:child_2
			}
			reverse_add_opinion = {
				target = scope:child_2
				opinion = 10
				modifier = compliment_opinion
			}
		}
		if = {
			limit = {
				exists = scope:child_3 
			}
			reverse_add_opinion = {
				target = scope:child_3
				opinion = 10
				modifier = compliment_opinion
			}
		}
		if = {
			limit = {
				exists = scope:child_4
			}
			reverse_add_opinion = {
				target = scope:child_4
				opinion = 10
				modifier = compliment_opinion
			}
		}
		scope:court_tutor = {
			add_stress = major_stress_gain
			add_learning_skill = -2
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = 0.5
			}
		}
	}

	option = { 
		name = court.4802.b
		remove_short_term_gold = tiny_gold_value
		stress_impact = {
			sadistic = minor_stress_loss
			compassionate = minor_stress_gain
			impatient = minor_stress_gain
		}
		reverse_add_opinion = {
			target = scope:child_2
			opinion = 30
			modifier = grateful_opinion
		}
		reverse_add_opinion = {
			target = scope:court_tutor
			opinion = -30
			modifier = hate_opinion
		}
		#your trumpet has dooted its last doot
		hidden_effect = {
			if = {
				limit = {
					scope:court_tutor = {
						can_start_scheme = {
							type = murder
							target = scope:child_2
						}
					}
				}
				scope:court_tutor = {
					start_scheme = {
						type = murder
						target = scope:child_2
					}
				}
			}
		}
		scope:court_tutor = {
			add_stress = massive_stress_gain
			set_relation_potential_rival = scope:child_2
			add_learning_skill = -2
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_rationality = -0.5
				ai_vengefulness = 0.5
			}
		}
	}

	option = {
		name = court.4802.c
		revoke_court_position = {
			recipient = scope:court_tutor
			court_position = court_tutor_court_position
		}
		reverse_add_opinion = {
			target = scope:court_tutor
			opinion = 30
			modifier = grateful_opinion
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_rationality = 0.5
				ai_compassion = 0.25
			}
		}
	}
	after = {
		scope:court_tutor = {
			clear_court_event_participation = yes
		}
		scope:child_1 = {
			clear_court_event_participation = yes
		}
		scope:child_2 = {
			clear_court_event_participation = yes
		}
		scope:child_3 = {
			clear_court_event_participation = yes
		}
		scope:child_4 = {
			clear_court_event_participation = yes
		}
	}
}

##################################################
# A Ghostly Pen
# by Isabella Welch
# 4803
##################################################

court.4803 = {
	type = court_event
	title = court.4803.t
	desc = court.4803.desc
	cooldown = { years = 10 }
	theme = court
	
	trigger = {
		any_court_position_holder = {
			type = court_poet_court_position
			is_available_ai_adult = yes
			has_court_event_flag = no
		}
	}
	court_scene = {
		button_position_character = scope:court_poet
		roles = {
			scope:court_poet = {
				group = event_group
				animation = flirtation
			}
		}
	}

	weight_multiplier = {
		base = 1

		# Court weightings.
		## Weighting due to the body copy.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_warlike }
	}

	immediate = {
		random_court_position_holder = {
			type = court_poet_court_position
			limit = { is_available_ai_adult = yes }
			save_scope_as = court_poet
			court_event_character_flag_effect = yes
		}
		if = {
			limit = { 
				any_relation = {
					type = lover
				}
			}
			random_relation = {
				type = lover
				save_scope_as = lover
			}
		}
	}

	option = { 
		name = court.4803.a
		add_diplomacy_lifestyle_xp = medium_lifestyle_xp
		reverse_add_opinion = {
			target = scope:court_poet
			opinion = 25
			modifier = pleased_opinion
		}
		add_character_modifier = {
			modifier = ghost_writer_modifier
			years = 5
		}
		scope:court_poet = {
			add_hook = {
				target = root
				type = favor_hook
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_greed = 0.5
				ai_sociability = 0.5
			}
		}
	}

	option = {
		name = court.4803.b
		trigger = { has_trait = poet }
		trait = poet
		if = {
			limit = { has_any_nickname = no }
			give_nickname = nick_the_poet	
		}
		set_relation_potential_rival = scope:court_poet
		add_prestige = medium_prestige_gain
		every_vassal_or_below = {
			limit = { has_trait = poet }
			custom = custom.every_poet
			add_opinion = {
				target = root
				modifier = also_poet_opinion
			}
		}
		ai_chance = {
			base = 75
			ai_value_modifier = {
				ai_honor = 0.5
			}
		}
	}
	
	option = {
		name = court.4803.c
		flavor = court.4803.c.tt
		trigger = {
			exists = scope:lover
		}
		if = {
			limit = {
				scope:lover = {
					intrigue >= high_skill_rating
				}
			}
			custom_tooltip = court.4803.c.intrigue.tt
			random_list = {
				40 = {
					send_interface_toast = {
						left_icon = scope:lover
						right_icon = scope:court_poet
						title = court.4803.c.realize.tt
						scope:lover = {
							if = {
								limit = {
									can_set_relation_potential_lover_trigger = { CHARACTER = scope:court_poet }
								}
								set_relation_potential_lover = scope:court_poet
							}
							else = {
								add_opinion = {
									target = scope:court_poet
									opinion = 25
									modifier = flattered_opinion
								}
							}
						}
					}
				}
				60 = {
					send_interface_toast = {
						left_icon = scope:lover
						right_icon = scope:court_poet
						title = court.4803.c.fooled.tt
						reverse_add_opinion = {
							target = scope:lover
							opinion = 25
							modifier = flattered_opinion
						}
					}
				}
			}		
		}
		else = {
			send_interface_toast = {
				left_icon = scope:lover
				right_icon = scope:court_poet
				title = court.4803.c.fooled.tt
				reverse_add_opinion = {
					target = scope:lover
					opinion = 15
					modifier = flattered_opinion
				}
			}
		}
		hidden_effect = {
			if = {
				limit = {
					has_secret_relation_lover = scope:lover
				}
				random_secret = {
					limit = {
						secret_type = secret_lover
						secret_target = { this = root }
					}
					reveal_to = scope:court_poet
				}
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_honor = -0.5
			}
		}
	}

	option = {
		name = court.4803.d
		trigger = {
			NOT = {
				has_trait = poet
			}
		}
		stress_impact = {
			arrogant = minor_stress_gain
			ambitious = minor_stress_gain
		}
		add_character_modifier = {
			modifier = honest_speaker_modifier
			years = 2
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = 0.5
				ai_sociability = 0.5
			}
		}
	}
	after = {
		scope:court_poet = {
			clear_court_event_participation = yes
		}
	}
}

##################################################
# Foul Bedfellows
# by Isabella Welch
# 4804
##################################################

court.4804 = {
	type = court_event
	title = court.4804.t
	theme = court
	desc = court.4804.desc
	court_scene = {
		button_position_character = scope:roomate_1
		roles = {
			scope:roomate_1 = {
				group = event_group
				animation = pain
			}
			scope:roomate_2 = {
				group = event_group
				animation = pain
			}
		}
	}

	cooldown = { years = 10 }
	
	trigger = {
		any_courtier = {
			is_available_ai_adult = yes
			has_court_event_flag = no
			NOT = {
				is_close_family_of = root
			}
			save_temporary_scope_as = roomate_check
		}
		any_courtier = {
			count > 2
			is_available_ai_adult = yes
			has_court_event_flag = no
			NOR = {
				is_close_family_of = root
				this = scope:roomate_check
				has_relation_rival = scope:roomate_check
			}
		}
		has_royal_court = yes
		court_owner = {
			amenity_level = { 
				type = court_lodging_standards
				value < medium_amenity_level
			}
		}
		NOT = {
			government_has_flag = government_is_tribal
		}
	}

	weight_multiplier = {
		base = 1

		# Court weightings.
		## Also a pretty general life experience.
	}

	immediate = {
		random_courtier = {
			limit = {
				is_available_ai_adult = yes
				NOR = {
					is_close_family_of = root
					is_consort_of = root
				}
			}
			save_scope_as = roomate_1
			court_event_character_flag_effect = yes
		}
		random_courtier = {	
			limit = {
				NOR = {
					is_close_family_of = root
					is_consort_of = root
					this = scope:roomate_1
				}
				is_available_ai_adult = yes
			}
			save_scope_as = roomate_2
			court_event_character_flag_effect = yes
		}
		scope:roomate_1 = {
			add_character_modifier = {
				modifier = sleep_deprived_modifier
			}
		}
		scope:roomate_2 = {
			add_character_modifier = {
				modifier = sleep_deprived_modifier
			}
		}
	}

	option = { 
		name = court.4804.a
		reverse_add_opinion = {
			target = scope:roomate_1
			modifier = grateful_opinion
			opinion = 15
		}
		reverse_add_opinion = {
			target = scope:roomate_2
			modifier = grateful_opinion
			opinion = 15
		}
		add_prestige = minor_prestige_loss
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_rationality = 0.5
				ai_compassion = 0.5
			}
		}
	}

	option = {
		name = court.4804.b
		reverse_add_opinion = {
			target = scope:roomate_1
			modifier = grateful_opinion
			opinion = 15
		}
		reverse_add_opinion = {
			target = scope:roomate_2
			modifier = grateful_opinion
			opinion = 15
		}
		set_amenity_level = { type = court_lodging_standards value = 3 }
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = 0.5
				ai_greed = -0.5
			}
		}
	}
	
	option = {
		name = court.4804.c
		scope:roomate_1 = {
			set_relation_rival = {
				target = scope:roomate_2
				reason = rival_foul_bedfellows
			}
		}
		reverse_add_opinion = {
			target = scope:roomate_1
			modifier = disappointed_opinion
			opinion = -10
		}
		reverse_add_opinion = {
			target = scope:roomate_2
			modifier = disappointed_opinion
			opinion = -10
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_greed = 0.75
			}
		}
	}
	after = {
		scope:roomate_1 = {
			clear_court_event_participation = yes
		}
		scope:roomate_2 = {
			clear_court_event_participation = yes
		}
	}
}

##################################################
# Cutting Corners
# by Isabella Welch
# 4805
##################################################

scripted_trigger court_4805_architect_trigger = {
	is_available_ai_adult = yes
	NOR = { 
		has_relation_rival = root
		has_trait = compassionate
	}
}

scripted_trigger court_4805_rival_trigger = {
	has_relation_rival = root
	is_landed = yes
	is_ai = yes
}

court.4805 = {
	type = court_event
	title = court.4805.t
	desc = court.4805.desc
	theme = court
	
	cooldown = { years = 10 }
	court_scene = {
		button_position_character = scope:royal_architect
		roles = {
			scope:royal_architect = {
				group = event_group
				animation = scheme
			}
		}
	}
	trigger = {
		any_vassal_or_below = {
			court_4805_rival_trigger = yes
		}
		any_court_position_holder = {
			type = royal_architect_court_position
			court_4805_architect_trigger = yes
			has_court_event_flag = no
		}
	}

	weight_multiplier = {
		base = 1

		# Court weightings.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_administrative }
	}

	immediate = {
		random_court_position_holder = {
			type = royal_architect_court_position
			limit = { court_4805_architect_trigger = yes }
			save_scope_as = royal_architect
			court_event_character_flag_effect = yes
		}
		random_vassal_or_below = {
			limit = { court_4805_rival_trigger = yes }
			weight = {
				base = 1
				modifier = {
					is_powerful_vassal = yes
					factor = 5
				}
			}
			save_scope_as = rival
		}
		hidden_effect = {
			scope:rival = {
				create_artifact = {
					name = artifact_pedestal_cornerstone_name
					description = artifact_pedestal_cornerstone_name_desc
					type = pedestal
					visuals = rock
					modifier = artifact_powerful_vassal_opinion_1_modifier
					save_scope_as = rock
				}
			}
			scope:rock = {
				 set_owner = {
					target = root
					history = {
						location = scope:rival.capital_province
						actor = scope:rival
						recipient = root
						type = stolen
					}
				}
			}
		}
	}

	option = { 
		name = court.4805.a
		stress_impact = {
			arbitrary = minor_stress_loss
		}
		root.capital_county = {
			add_county_modifier = {
				modifier = opulent_pigsty_modifier
				years = 15
			}
		}
		reverse_add_opinion = {
			target = scope:rival
			opinion = -10
			modifier = insulted_opinion
		}
		hidden_effect = {
			destroy_artifact = scope:rock
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_vengefulness = 0.75
				ai_rationality = -0.5
			}
		}
	}

	option = {
		name = court.4805.b
		show_as_tooltip = {
			scope:rock = {
				 set_owner = {
					target = root
					history = {
						location = scope:rival.capital_province
						actor = scope:rival
						recipient = root
						type = stolen
					}
				}
			}
		}
		reverse_add_opinion = {
			target = scope:rival
			opinion = -20
			modifier = insulted_opinion
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_vengefulness = 0.75
				ai_rationality = -0.5
				ai_greed = 0.5
			}
		}
	}
	
	option = {
		name = court.4805.c
		reverse_add_opinion = {
			target = scope:rival
			opinion = 10
			modifier = respect_opinion
		}
		remove_relation_rival = scope:rival
		scope:rock = {
			 set_owner = {
				target = scope:rival
				history = {
					location = scope:rival.capital_province
					actor = root
					recipient = scope:rival
					type = given
				}
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_vengefulness = -0.75
				ai_rationality = 0.5
			}
		}
	}
	option = {
		name = court.4805.d
		reverse_add_opinion = {
			target = scope:royal_architect
			opinion = -10
			modifier = insulted_opinion
		}
		scope:rock = {
			 set_owner = {
				target = scope:royal_architect
				history = {
					location = scope:rival.capital_province
					actor = scope:rival
					recipient = scope:royal_architect
					type = stolen
				}
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_greed = -0.75
				ai_rationality = 0.5
			}
		}
	}
	after = {
		scope:royal_architect = {
			clear_court_event_participation = yes
		}
	}
}

##################################################
# GetTitleAsNameophile
# by Isabella Welch
# 4806
##################################################

scripted_trigger adoring_fan_liege_trigger = {
	is_ai = yes
	this.liege = { NOT = { this = root } }
	this.culture = { NOT = { this = root.culture } }
}

#HREaboo, byzaboo, or insert-your-realmaboo appears by Isabella Welch
court.4806 = {
	type = court_event
	title = court.4806.t
	desc = {
		desc = court.4806.intro
		first_valid = {
			#AGOT Disabled
			# triggered_desc = {
			# 	trigger = { primary_title = title:e_hre }
			# 	desc = court.4806.hre_desc
			# }
			# triggered_desc = {
			# 	trigger = { primary_title = title:e_byzantium }
			# 	desc = court.4806.byzantine_desc
			# }
			desc = court.4806.general_desc
		}
	}
	theme = court
	cooldown = { years = 10 }
	court_scene = {
		button_position_character = scope:adoring_fan
		roles = {
			scope:adoring_fan = {
				group = event_group
				animation = throne_room_bow_1
			}
		}
	}

	trigger = {
		amenity_level = { 
			type = court_lodging_standards
			value >= high_amenity_level
		}
		amenity_level = { 
			type = court_servants
			value >= high_amenity_level
		}
		amenity_level = { 
			type = court_fashion
			value >= high_amenity_level
		}
		amenity_level = { 
			type = court_food_quality
			value >= high_amenity_level
		}
		any_ally = { adoring_fan_liege_trigger = yes }
	}

	weight_multiplier = {
		base = 1

		# Court weightings.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_scholarly }
	}

	immediate = {
		set_signature_weapon_effect = yes
		random_ally = {
			limit = { adoring_fan_liege_trigger = yes }
			save_scope_as = adoring_fan_liege
		}
		if = {
			limit = {
				any_pool_character = {
					province = scope:adoring_fan_liege.capital_province
					NOT = { culture = root.culture }
					has_trait = trusting
				}
			}
			random_pool_character = {
				province = scope:adoring_fan_liege.capital_province
				limit = {
					NOT = { culture = root.culture }
					has_trait = trusting
				}
				save_scope_as = adoring_fan
				scope:adoring_fan = { move_to_pool_at = root.capital_province }
			}
		}
		else = {
			create_character = {
				location = root.capital_province
				template = adoring_fan_character
				faith = scope:adoring_fan_liege.faith
				culture = scope:adoring_fan_liege.culture
				save_scope_as = adoring_fan
			}
			scope:adoring_fan = {
				add_character_flag = was_created_flag
			}
		}
	}

	option = { 
		name = court.4806.a
		change_current_court_grandeur = miniscule_court_grandeur_gain
		add_prestige = minor_prestige_gain
		add_diplomacy_lifestyle_xp = medium_lifestyle_xp
		stress_impact = {
			humble = minor_stress_gain
			eccentric = minor_stress_gain
			wrathful = minor_stress_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_greed = 0.25
				ai_rationality = 0.5
			}
		}
	}

	#AGOT Disabled
	# option = {
	# 	name = court.4806.b
	# 	trigger = { primary_title = title:e_hre }
	# 	scope:adoring_fan = {
	# 		set_artifact_rarity_common = yes
	# 		create_artifact = {
	# 			name = fake_reichskrone_name
	# 			description = fake_reichskrone_description
	# 			type = helmet
	# 			visuals = hre_crown
	# 			modifier = artifact_attraction_opinion_1_modifier
	# 			modifier = artifact_monthly_prestige_penalty_modifier
	# 			save_scope_as = fake_reichskrone
	# 		}
	# 	}
	# 	scope:fake_reichskrone = {
	# 		set_owner = root
	# 	}
	# 	stress_impact = {
	# 		arrogant = minor_stress_gain
	# 		generous = minor_stress_gain
	# 	}
	# 	ai_chance = {
	# 		base = 50
	# 		ai_value_modifier = {
	# 			ai_greed = 0.5
	# 			ai_rationality = -0.5
	# 			ai_boldness = 0.5
	# 		}
	# 	}
	# }

	#AGOT Disabled
	# option = {
	# 	name = {
	# 		trigger = { primary_title = title:e_byzantium }
	# 		text = court.4806.c.byz
	# 	}
	# 	name = court.4806.c
	# 	change_current_court_grandeur = miniscule_court_grandeur_loss
	# 	add_prestige = minor_prestige_loss
	# 	add_courtier = scope:adoring_fan
	# 	reverse_add_opinion = {
	# 		target = scope:adoring_fan
	# 		opinion = 20
	# 		modifier = flattered_opinion
	# 	}
	# 	stress_impact = {
	#		eccentric = minor_stress_loss
	# 		greedy = minor_stress_gain
	# 		arrogant = minor_stress_gain
	# 	}
	# 	ai_chance = {
	# 		base = 50
	# 		ai_value_modifier = {
	# 			ai_compassion = 0.5
	# 			ai_greed = -0.5
	# 		}
	# 	}
	# }
	#AGOT Disabled
	# option = {
	# 	name = court.4806.d
	# 	trigger = { primary_title = title:e_byzantium }
	# 	scope:adoring_fan = {
	# 		set_artifact_rarity_common = yes
	# 		create_artifact = {
	# 			name = purple_underwear_name
	# 			description = purple_underwear_description
	# 			type = miscellaneous
	# 			visuals = pouch
	# 			modifier = artifact_attraction_opinion_2_modifier
	# 			modifier = artifact_monthly_prestige_2_modifier
	# 			save_scope_as = purple_underwear
	# 		}
	# 	}
	# 	scope:purple_underwear = {
	# 		set_owner = root
	# 	}
	# 	add_prestige = minor_prestige_gain
	# 	rightfully_imprison_character_effect = {
	# 		TARGET = scope:adoring_fan
	# 		IMPRISONER = root
	# 	}
	# 	stress_impact = {
	# 		compassionate = minor_stress_gain
	# 		humble = minor_stress_gain
	# 		generous = minor_stress_gain
	# 	}
	# 	ai_chance = {
	# 		base = 50
	# 		ai_value_modifier = {
	# 			ai_vengefulness = 0.75
	# 			ai_boldness = 0.5
	# 		}
	# 	}
	# }
	option = {
		name = court.4806.e
		#AGOT Disabled
		# trigger = {
		# 	NOR = {
		# 		primary_title = title:e_hre
		# 		primary_title = title:e_byzantium
		# 	}
		# }
		reverse_add_opinion = {
			target = scope:adoring_fan
			opinion = -20
			modifier = rejected_opinion
		}
		add_prestige = minor_prestige_loss
		stress_impact = {
			arrogant = minor_stress_gain
			content = minor_stress_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_greed = 0.5
				ai_boldness = 0.5
			}
		}
	}
	after = {
		hidden_effect = {
			if = {
				limit = {
					scope:adoring_fan = {
						NOR = {
							is_courtier_of = root
							is_imprisoned = yes
						}
					}
				}
				if = {
					limit = {
						scope:adoring_fan = { has_character_flag = was_created_flag }
					}
					scope:adoring_fan = {
						death = {
							death_reason = death_vanished
						}
					}
				}
				else = {
					scope:adoring_fan = {
						move_to_pool_at = scope:adoring_fan_liege.capital_province
					}
				}
			}
		}
	}
}









##################################################
# Linnea

##################################################
# 5025			A foreign diplomat wants to buy your cat
# 5026			A foreign diplomat wants to buy your dog
# 5030 - 5039	Playtime
# 5040 - 5049	Pranking Spree
# 5050 - 5054	A Courtier Scorned
# 5055 - 5059	Colorful Talent
# 5060 - 5069	The Gallant Knight
# 5070 - 5074	Dedicated Tutor
# 5075 - 5079	Gift From Neigh-bor
##################################################

#####################################
# Proposed Deal (cat)               #
# by Linnéa Thimrén                 #
#####################################
scripted_trigger court_5025_basic_buyer_trigger = {
	is_adult = yes
	NOT = {
		any_owned_story = {
			story_type = story_cycle_pet_cat
		}
	}
}

# A foreign diplomat wants to buy your cat
court.5025 = {
	type = court_event
	title = court.5025.t
	desc = court.5025.desc
	theme = court

	court_scene = {
		button_position_character = scope:buyer
		roles = {
			scope:buyer = {
				group = event_group
				animation = flirtation
			}
		}
	}
	
	trigger = {
		NOT = { has_character_flag = had_event_court_5025 }
		any_owned_story = {
			story_type = story_cycle_pet_cat
		}
		any_courtier_or_guest = {
			court_5025_basic_buyer_trigger = yes
			has_court_event_flag = no
		}
	}

	weight_multiplier = {
		base = 0.5
		modifier = { #Make it more likely to happen if the same asshole can buy both a cat and a dog from you
			add = 0.75
			any_courtier_or_guest = {
				court_5025_basic_buyer_trigger = yes
				save_temporary_scope_as = buyer_check
			}
			exists = var:bought_my_dog
			var:bought_my_dog = {
				this = scope:buyer_check
			}
		}

		# Court weightings.
		## Money court makes people consider things...
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_administrative }
	}

	immediate = {
		add_character_flag = {
			flag = had_event_court_5025
			years = 10
		}
		random_courtier_or_guest = {
			limit = {
				court_5025_basic_buyer_trigger = yes
			}
			weight = {
				base = 1
				ai_value_modifier = {
					ai_greed = medium_chance_impact_positive_ai_value
					ai_boldness = medium_chance_impact_positive_ai_value
					ai_energy = low_chance_impact_negative_ai_value
				}
			}
			save_scope_as = buyer
			court_event_character_flag_effect = yes
			hidden_effect = {
				if = {
					limit = {
						short_term_gold < root.minor_gold_value
					}
					add_gold = root.minor_gold_value
				}
			}
		}
		random_owned_story = {
			limit = {
				story_type = story_cycle_pet_cat
			}
			save_scope_as = story
		}
		set_variable = { #We save the value here so that it stays consistent
			name = price_for_pet
			value = minor_gold_value
			years = 1
		}
	}

	option = { #Sell the pet
		name = court.5025.a

		transfer_cat_story_cycle_to_effect = {
			CHARACTER = scope:buyer
			STORY = scope:story
		}
		scope:buyer = {
			pay_short_term_gold = {
				target = root
				gold = root.var:price_for_pet
			}
		}
		if = {
			limit = {
				NOT = { has_relation_friend = scope:buyer }
			}
			progress_towards_friend_effect = {
				REASON = friend_sold_pet
				CHARACTER = scope:buyer
				OPINION = default_friend_opinion
			}
		}
		else = {
			scope:buyer = {
				add_opinion = {
					target = root
					modifier = friendliness_opinion
					opinion = 15
				}
			}
		}
		set_variable = {
			name = bought_my_cat
			value = scope:buyer
			years = 10
		}
	}

	option = { #Back off!!
		name = court.5025.b

		#Lose some court grandeur.
		change_current_court_grandeur = minor_court_grandeur_loss

		scope:buyer = {
			add_opinion = {
				target = root
				modifier = refusal_opinion
				opinion = -20
			}
		}
	}
	after = {
		scope:buyer = {
			clear_court_event_participation = yes
		}
	}
}

#####################################
# Proposed Deal (dog)               #
# by Linnéa Thimrén                 #
#####################################

scripted_trigger court_5026_basic_buyer_trigger = {
	is_adult = yes
	NOT = {
		any_owned_story = {
			story_type = story_cycle_pet_dog
		}
	}
}

# A foreign diplomat wants to buy your dog
court.5026 = {
	type = court_event
	title = court.5025.t
	desc = court.5026.desc
	theme = court

	court_scene = {
		button_position_character = scope:buyer
		roles = {
			scope:buyer = {
				group = event_group
				animation = flirtation
			}
		}
	}
	
	trigger = {
		NOT = { has_character_flag = had_event_court_5026 }
		any_owned_story = {
			story_type = story_cycle_pet_dog
		}
		any_courtier_or_guest = {
			court_5026_basic_buyer_trigger = yes
			has_court_event_flag = no
		}
	}

	weight_multiplier = {
		base = 0.5
		modifier = { #Make it more likely to happen if the same asshole can buy both a cat and a dog from you
			add = 0.75
			any_courtier_or_guest = {
				court_5026_basic_buyer_trigger = yes
				save_temporary_scope_as = buyer_check
			}
			exists = var:bought_my_cat
			var:bought_my_cat = {
				this = scope:buyer_check
			}
		}

		# Court weightings.
		## Money court makes people consider things...
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_administrative }
	}

	immediate = {
		add_character_flag = {
			flag = had_event_court_5026
			years = 10
		}
		random_courtier_or_guest = {
			limit = {
				court_5026_basic_buyer_trigger = yes
			}
			weight = {
				base = 1
				ai_value_modifier = {
					ai_greed = medium_chance_impact_positive_ai_value
					ai_boldness = medium_chance_impact_positive_ai_value
					ai_energy = low_chance_impact_negative_ai_value
				}
			}
			save_scope_as = buyer
			court_event_character_flag_effect = yes
			hidden_effect = { add_gold = root.minor_gold_value }
		}
		random_owned_story = {
			limit = {
				story_type = story_cycle_pet_dog
			}
			save_scope_as = story
		}
		set_variable = { #We save the value here so that it stays consistent
			name = price_for_pet
			value = minor_gold_value
			years = 1
		}
	}

	option = { #Sell the pet
		name = court.5026.a

		transfer_dog_story_cycle_to_effect = {
			CHARACTER = scope:buyer
			STORY = scope:story
		}
		scope:buyer = {
			pay_short_term_gold = {
				target = root
				gold = root.var:price_for_pet
			}
		}
		if = {
			limit = {
				NOT = { has_relation_friend = scope:buyer }
			}
			progress_towards_friend_effect = {
				REASON = friend_sold_pet
				CHARACTER = scope:buyer
				OPINION = default_friend_opinion
			}
		}
		else = {
			scope:buyer = {
				add_opinion = {
					target = root
					modifier = friendliness_opinion
					opinion = 15
				}
			}
		}
		set_variable = {
			name = bought_my_dog
			value = scope:buyer
			years = 10
		}
	}

	option = { #Back off!!
		name = court.5026.b

		#Lose some court grandeur.
		change_current_court_grandeur = minor_court_grandeur_loss

		scope:buyer = {
			add_opinion = {
				target = root
				modifier = refusal_opinion
				opinion = -20
			}
			hidden_effect = { remove_short_term_gold = minor_gold_value }
		}
	}
	after = {
		scope:buyer = {
			clear_court_event_participation = yes
		}
	}
}

#####################################
# Playtime                          #
# by Linnéa Thimrén                 #
#####################################

#A child is struggling to focus on ruling
court.5030 = {
	type = court_event
	title = court.5030.t
	desc = {
		desc = court.5030.desc_opening
		first_valid = {
			triggered_desc = {
				trigger = { age <= 10 }
				desc = court.5030.desc_young
			}
			desc = court.5030.desc
		}
		desc = court.5030.desc_ending
	}
	theme = court

	court_scene = {
		button_position_character = scope:child
		roles = {
			scope:child = {
				group = event_group
				animation = boredom
			}
		}
	}
	
	trigger = {
		NOT = { has_character_flag = had_event_court_5030 }
		is_adult = no
		age >= 4
		any_courtier = {
			is_adult = no
			age >= 3
			has_court_event_flag = no
		}
	}

	weight_multiplier = {
		base = 1

		# Court weightings.
		## Admin courts are extra boring.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_administrative }
	}

	immediate = {
		add_character_flag = {
			flag = had_event_court_5030
			years = 10
		}
		set_favorite_toy_effect = yes
		random_courtier = {
			limit = {
				is_adult = no
			}
			weight = {
				base = 1
				modifier = { #More likely to pick someone closer in age
					add = 5
					age >= root.age_dif_child_down
					age <=  root.age_dif_child_up
				}
			}
			save_scope_as = child
			court_event_character_flag_effect = yes
			set_favorite_toy_effect = yes
		}
	}

	option = { #Join in the game
		name = court.5030.a

		#Lose some court grandeur
		change_current_court_grandeur = minor_court_grandeur_loss

		if = {
			limit = {
				NOT = { has_relation_friend = scope:child }
			}
			progress_towards_friend_effect = {
				REASON = friend_played_with_child
				CHARACTER = scope:child
				OPINION = default_friend_opinion
			}
		}
		else = {
			scope:child = {
				add_opinion = {
					target = root
					modifier = friendliness_opinion
					opinion = 15
				}
			}
		}
		add_stress = minor_stress_loss
	}

	option = { #I have to be serious.
		name = {
			trigger = { age <= 10 }
			text = court.5030.b_young
		}
		name = {
			trigger = { age > 10 }
			text = court.5030.b
		}
		#Get some court grandeur
		change_current_court_grandeur = minor_court_grandeur_gain
		add_stress = medium_stress_gain
		scope:child = {
			add_opinion = {
				target = root
				modifier = refusal_opinion
				opinion = -10
			}
		}
	}
	after = {
		scope:child = {
			clear_court_event_participation = yes
		}
	}
}

#####################################
# Pranking Spree                    #
# by Linnéa Thimrén                 #
#####################################

#Prank a courtier?
court.5040 = {
	type = court_event
	title = court.5040.t
	desc = court.5040.desc
	theme = court

	court_scene = {
		button_position_character = scope:prank_alternative_1
		roles = {
			scope:prank_alternative_1 = {
				group = event_group
				animation = shock
			}
			scope:prank_alternative_2 = {
				group = event_group
				animation = worry
			}
			scope:prank_alternative_3 = {
				group = event_group
				animation = pain
			}
		}
	}
	
	trigger = {
		NOT = { has_character_flag = had_event_court_5040 }
		is_adult = no
		age >= 4
		any_courtier = {
			age >= 10
			count >= 3
			has_court_event_flag = no
		}
	}

	weight_multiplier = {
		base = 0.5
		modifier = {
			add = 0.75
			has_trait = rowdy
		}

		# Court weightings.
		## Prank fussy scholars? Don't mind if I do!
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_scholarly }
	}

	immediate = {
		add_character_flag = {
			flag = had_event_court_5040
			years = 10
		}

		#To save down alternative targets for your prank (if you have enough courtiers to be picky)
		random_courtier = {
			limit = {
				age >= 10
			}
			weight = {
				base = 1
				modifier = { #More likely to pick someone you don't like
					add = 2
					OR = {
						has_relation_rival = root
						has_relation_potential_rival = root
					}
				}
				modifier = { #More likely to pick someone who might want attention
					add = 4
					OR = {
						has_personality_dominant_trigger = yes
						has_personality_extroverted_trigger = yes
						has_personality_annoying_trigger = yes
					}
				}
			}
			save_scope_as = prank_alternative_1
			court_event_character_flag_effect = yes
		}
		if = {
			limit = {
				any_courtier = {
					age >= 10
					NOT = { this = scope:prank_alternative_1 }
				}
			}
			random_courtier = {
				limit = {
					age >= 10
					NOT = { this = scope:prank_alternative_1 }
				}
				weight = {
					base = 1
					modifier = { #More likely to pick someone you don't like
						add = 2
						OR = {
							has_relation_rival = root
							has_relation_potential_rival = root
						}
					}
					modifier = { #More likely to pick someone who wants more fun
						add = 4
						OR = {
							has_personality_extroverted_trigger = yes
							has_trait = lifestyle_reveler
						}
					}
				}
				save_scope_as = prank_alternative_2
				court_event_character_flag_effect = yes
			}
		}
		if = {
			limit = {
				any_courtier = {
					age >= 10
					NOR = {
						this = scope:prank_alternative_1
						this = scope:prank_alternative_2
					}
					is_human = yes
				}
			}
			random_courtier = {
				limit = {
					age >= 10
					NOR = {
						this = scope:prank_alternative_1
						this = scope:prank_alternative_2
					}
					is_human = yes
				}
				weight = {
					base = 1
					modifier = { #More likely to pick someone you don't like
						add = 2
						OR = {
							has_relation_rival = root
							has_relation_potential_rival = root
						}
					}
					modifier = { #More likely to pick someone a bit weird 
						add = 4
						OR = {
							has_personality_annoying_trigger = yes
							probably_unintelligent_trigger = yes
						}
					}
				}
				save_scope_as = prank_alternative_3
				court_event_character_flag_effect = yes
			}
		}
	}

	option = { #I will behave.
		name = court.5040.a
		add_stress = minor_stress_gain
	}

	option = { #Alternative 1
		name = court.5040.b
		scope:prank_alternative_1 = {
			add_character_modifier = {
				modifier = victim_of_whoopee_cushion_modififer
				years = 5
			}
			save_scope_as = prank_target
		}
		stress_impact = {
			base = miniscule_stress_impact_loss
			compassionate = minor_stress_impact_gain
		}
	}

	option = { #Alternative 2
		name = court.5040.c
		trigger = { exists = scope:prank_alternative_2 }
		scope:prank_alternative_2 = {
			add_character_modifier = {
				modifier = victim_of_whoopee_cushion_modififer
				years = 5
			}
			save_scope_as = prank_target
		}
		stress_impact = {
			base = miniscule_stress_impact_loss
			compassionate = minor_stress_impact_gain
		}
	}

	option = { #Alternative 3
		name = court.5040.d
		trigger = { exists = scope:prank_alternative_3 }
		scope:prank_alternative_3 = {
			add_character_modifier = {
				modifier = victim_of_whoopee_cushion_modififer
				years = 5
			}
			save_scope_as = prank_target
		}
		stress_impact = {
			base = miniscule_stress_impact_loss
			compassionate = minor_stress_impact_gain
		}
	}

	after = {
		scope:prank_alternative_1 = {
			clear_court_event_participation = yes
		}
		scope:prank_alternative_2 = {
			clear_court_event_participation = yes
		}
		scope:prank_alternative_3 = {
			clear_court_event_participation = yes
		}
		if = {
			limit = {
				exists = scope:prank_target
			}
			trigger_event = {
				id = court.5041
				days = { 3 5 }
			}
		}
	}
}

#warning: going bananas with scripted effects
scripted_effect court_5041_handling_of_flags_effect = {
	if = {
		limit = {
			has_character_flag = option_1_chosen
		}
		court_5041_flag_juggling_effect = {
			NUMBER = 1
		}
	}
	if = {
		limit = {
			has_character_flag = option_2_chosen
		}
		court_5041_flag_juggling_effect = {
			NUMBER = 2
		}
	}
	if = {
		limit = {
			has_character_flag = option_3_chosen
		}
		court_5041_flag_juggling_effect = {
			NUMBER = 3
		}
	}
	if = {
		limit = {
			has_character_flag = option_4_chosen
		}
		court_5041_flag_juggling_effect = {
			NUMBER = 4
		}
	}
	if = {
		limit = {
			has_character_flag = option_5_chosen
		}
		court_5041_flag_juggling_effect = {
			NUMBER = 5
		}
	}
}

scripted_effect court_5041_flag_juggling_effect = {
	remove_character_flag = option_$NUMBER$_chosen
	add_character_flag = {
		flag = option_$NUMBER$_to_display
		days = 10
	}
	add_character_flag = {
		flag = option_$NUMBER$_has_been_taken
		days = 100
	}
}

scripted_effect court_5041_pick_option_effect = {
	#bless Secretum Philosophorum
	random_list = {
		1 = { #"Maggots" in their food
			trigger = {
				NOR = {
					has_character_flag = option_1
					has_character_flag = option_1_has_been_taken
				}
			}
			add_character_flag = {
				flag = option_1
				days = 10
			}
		}
		1 = { #"Raw" meat
			trigger = {
				NOR = {
					has_character_flag = option_2
					has_character_flag = option_2_has_been_taken
				}
			}
			add_character_flag = {
				flag = option_2
				days = 10
			}
		}
		1 = { #Let loose snakes (looking at you, Elagabalus)
			trigger = {
				NOR = {
					has_character_flag = option_3
					has_character_flag = option_3_has_been_taken
				}
			}
			add_character_flag = {
				flag = option_3
				days = 10
			}
		}
		1 = { #Flammable powder
			trigger = {
				NOR = {
					has_character_flag = option_4
					has_character_flag = option_4_has_been_taken
				}
			}
			add_character_flag = {
				flag = option_4
				days = 10
			}
		}
		1 = { #Chamber pot above door
			trigger = {
				NOR = {
					has_character_flag = option_5
					has_character_flag = option_5_has_been_taken
				}
			}
			add_character_flag = {
				flag = option_5
				days = 10
			}
		}
	}
}

scripted_effect court_5041_option_effect = {
	change_variable = {
		name = escalation_level
		add = $ESCALATION$
	}

	court_5041_remove_option_flags_effect = yes
	court_5041_remove_display_option_flags_effect = yes
	add_character_flag = {
		flag = option_$OPTION_NUMBER$_chosen
		days = 10
	}

	if = { #Effect of first prank
		limit = {
			NOR = {
				has_character_flag = option_1_has_been_taken
				has_character_flag = option_2_has_been_taken
				has_character_flag = option_3_has_been_taken
				has_character_flag = option_4_has_been_taken
				has_character_flag = option_5_has_been_taken
			}
		}
		add_stress = medium_stress_loss
	}
	else_if = { #Effect of second prank
		limit = {
			NOT = {
				has_character_modifier = lively_court_modifier
			}
		}
		add_character_modifier = {
			modifier = lively_court_modifier
			years = 10
		}
	}
	else_if = { #Effect of third prank
		limit = {
			NOT = {
				has_character_modifier = had_hearty_laugh_modifier
			}
		}
		add_character_modifier = {
			modifier = had_hearty_laugh_modifier
			years = 10
		}
	}
	else = {
		add_stress = miniscule_stress_impact_loss
	}

	scope:prank_target = {
		add_stress = minor_stress_gain   
	}

	if = {
		limit = {
			var:escalation_level < 4
		}
		trigger_event = {
			id = court.5041
			days = { 3 5 }
		}
	}
	else = {
		trigger_event = {
			id = court.5042
			days = { 3 5 }
		}
	}
}

scripted_effect court_5041_remove_option_flags_effect = {
	remove_character_flag = option_1
	remove_character_flag = option_2
	remove_character_flag = option_3
	remove_character_flag = option_4
	remove_character_flag = option_5
}

scripted_effect court_5041_remove_display_option_flags_effect = {
	remove_character_flag = option_1_to_display
	remove_character_flag = option_2_to_display
	remove_character_flag = option_3_to_display
	remove_character_flag = option_4_to_display
	remove_character_flag = option_5_to_display
}

scripted_effect court_5041_remove_taken_option_flags_effect = {
	remove_character_flag = option_1_has_been_taken
	remove_character_flag = option_2_has_been_taken
	remove_character_flag = option_3_has_been_taken
	remove_character_flag = option_4_has_been_taken
	remove_character_flag = option_5_has_been_taken
}

scripted_effect court_5041_end_of_chain_cleanup_effect = {
	remove_variable = escalation_level
	court_5041_remove_option_flags_effect = yes
	court_5041_remove_display_option_flags_effect = yes
	court_5041_remove_taken_option_flags_effect = yes
}

#Escalate?
court.5041 = {
	type = character_event
	title = court.5040.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					has_character_flag = option_1_to_display
				}
				desc = court.5041.desc_option_1
			}
			triggered_desc = {
				trigger = {
					has_character_flag = option_2_to_display
				}
				desc = court.5041.desc_option_2
			}
			triggered_desc = {
				trigger = {
					has_character_flag = option_3_to_display
				}
				desc = court.5041.desc_option_3
			}
			triggered_desc = {
				trigger = {
					has_character_flag = option_4_to_display
				}
				desc = court.5041.desc_option_4
			}
			triggered_desc = {
				trigger = {
					has_character_flag = option_5_to_display
				}
				desc = court.5041.desc_option_5
			}
			desc = court.5041.desc_opening
		}
	}
	theme = court
	override_background = {
		trigger = {
			OR = {
				has_character_flag = option_1_to_display
				has_character_flag = option_2_to_display
				has_character_flag = option_4_to_display
			}
		}
		reference = feast
	}
	override_background = {
		trigger = { has_character_flag = option_3_to_display }
		reference = corridor_night
	}
	override_background = {
		trigger = { has_character_flag = option_5_to_display }
		reference = corridor_day
	}
	left_portrait = {
		character = scope:prank_target
		animation = shock
	}
	
	trigger = {
		scope:prank_target = {
			is_alive = yes
			is_courtier_of = root
		}
		trigger_if = {
			limit = { exists = var:escalation_level }
			var:escalation_level < 4
		}
	}

	immediate = {
		if = {
			limit = {
				NOT = { exists = var:escalation_level }
			}
			set_variable = {
				name = escalation_level
				value = 0
				years = 2
			}
		}

		#You went for the snakes? Auch
		if = {
			limit = {
				has_character_flag = option_3_chosen
			}
			scope:prank_target = {
				increase_wounds_effect = { REASON = snakes }
			}
		}

		#Juggling with flags to make sure we display the correct reaction desc and also keep track of what options have been picked
		court_5041_handling_of_flags_effect = yes

		#Lets pick out what pranks we can choose between
		hidden_effect = {
			court_5041_pick_option_effect = yes
			court_5041_pick_option_effect = yes
		}
	}

	option = { #I'm done
		name = court.5041.a
		court_5041_end_of_chain_cleanup_effect = yes
		scope:prank_target = {
			add_opinion = {
				target = root
				modifier = friendliness_opinion
				opinion = 15
			}
		}
	}

	option = { 
		name = court.5041.option_1
		trigger = { has_character_flag = option_1 }
		
		court_5041_option_effect = {
			OPTION_NUMBER = 1
			ESCALATION = 1
		}
	}

	option = { 
		name = court.5041.option_2
		trigger = { has_character_flag = option_2 }

		court_5041_option_effect = {
			OPTION_NUMBER = 2
			ESCALATION = 1
		}
	}

	option = { 
		name = court.5041.option_3
		trigger = { has_character_flag = option_3 }

		court_5041_option_effect = {
			OPTION_NUMBER = 3
			ESCALATION = 4 #This is going a bit far 
		}
	}

	option = { 
		name = court.5041.option_4
		trigger = { has_character_flag = option_4 }

		court_5041_option_effect = {
			OPTION_NUMBER = 4
			ESCALATION = 2
		}
	}

	option = { 
		name = court.5041.option_5
		trigger = { has_character_flag = option_5 }

		court_5041_option_effect = {
			OPTION_NUMBER = 5
			ESCALATION = 1
		}
	}
}

scripted_trigger court_5042_basic_chastiser_trigger = {
	is_alive = yes
	dread_modified_ai_boldness = {
		dreaded_character = root
		value >= -75
	}
}

#Consequences? For MY actions? It's more likely than you think
court.5042 = {
	type = character_event
	title = court.5040.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					has_character_flag = option_1_to_display
				}
				desc = court.5041.desc_option_1
			}
			triggered_desc = {
				trigger = {
					has_character_flag = option_2_to_display
				}
				desc = court.5041.desc_option_2
			}
			triggered_desc = {
				trigger = {
					has_character_flag = option_3_to_display
				}
				desc = court.5041.desc_option_3
			}
			triggered_desc = {
				trigger = {
					has_character_flag = option_4_to_display
				}
				desc = court.5041.desc_option_4
			}
			triggered_desc = {
				trigger = {
					has_character_flag = option_5_to_display
				}
				desc = court.5041.desc_option_5
			}
		}
		desc = {
			first_valid = {
				triggered_desc = {
					trigger = {
						exists = scope:chastiser
					}
					desc = {
						desc = court.5042.desc_chastiser
						first_valid = {
							triggered_desc = {
								trigger = {
									has_character_flag = option_3_has_been_taken                            
								}
								desc = court.5042.desc_chastiser_snake
							}
							desc = court.5042.desc_chastiser_no_snake
						}
					}
				}
				desc = court.5042.desc_no_chastiser
			}
		}
	}
	theme = court
	override_background = {
		trigger = {
			OR = {
				has_character_flag = option_1_to_display
				has_character_flag = option_2_to_display
				has_character_flag = option_4_to_display
			}
		}
		reference = feast
	}
	override_background = {
		trigger = { has_character_flag = option_3_to_display }
		reference = corridor_night
	}
	override_background = {
		trigger = { has_character_flag = option_5_to_display }
		reference = corridor_day
	}
	left_portrait = {
		character = scope:prank_target
		animation = shock
	}
	right_portrait = {
		character = scope:chastiser
		animation = anger
	}
	
	trigger = {
		scope:prank_target = {
			is_alive = yes
			is_courtier_of = root
		}
		exists = var:escalation_level
		var:escalation_level >= 4
	}

	immediate = {
		#Let's pick a good character to chastise you
		if = { #Liege?
			limit = {
				exists = liege
				liege = {
					NOT = { this = root }
					court_5042_basic_chastiser_trigger = yes
				}
			}
			liege = {
				save_scope_as = chastiser
			}
		}
		else_if = { #A parent (that's not terrified of you)?
			limit = {
				any_parent = {
					court_5042_basic_chastiser_trigger = yes
				}
			}
			random_parent = {
				limit = {
					court_5042_basic_chastiser_trigger = yes
				}
				save_scope_as = chastiser
			}
		}
		else_if = { #Older sibling (that's not terrified of you)?
			limit = {
				any_sibling = {
					court_5042_basic_chastiser_trigger = yes
					age > root.age
				}
			}
			random_sibling = {
				limit = {
					court_5042_basic_chastiser_trigger = yes
					age > root.age
				}
				save_scope_as = chastiser
			}
		}
		else_if = { #Court chaplain?
			limit = {
				exists = cp:councillor_court_chaplain
				cp:councillor_court_chaplain = {
					court_5042_basic_chastiser_trigger = yes
				}
			}
			cp:councillor_court_chaplain = {
				save_scope_as = chastiser
			}
		}
		else_if = { #Powerful vassal?
			limit = {
				any_powerful_vassal = {
					court_5042_basic_chastiser_trigger = yes
				}
			}
			random_powerful_vassal = {
				limit = {
					court_5042_basic_chastiser_trigger = yes
				}
				save_scope_as = chastiser
			}
		}

		#You went for the snakes? Auch
		if = {
			limit = {
				has_character_flag = option_3_chosen
			}
			scope:prank_target = {
				increase_wounds_effect = { REASON = snakes }
			}
		}

		#Juggling with flags to make sure we display the correct reaction desc and also keep track of what options have been picked
		court_5041_handling_of_flags_effect = yes

		#Lose a lot CGV
		change_current_court_grandeur = major_court_grandeur_loss

		every_courtier = {
			custom = yearly.4031.b_every_courtier
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = -15
			}
		}
	}

	option = { #Twas just a prank
		name = court.5042.a
	}

	after = { #Time to clean up, boys
		court_5041_end_of_chain_cleanup_effect = yes
	}
}

#####################################
# A Courtier Scorned                #
# by Linnéa Thimrén                 #
#####################################

scripted_trigger court_5050_courtier_trigger = {
	is_adult = yes
	has_any_court_position = no
	root = {
		character_can_be_employed_in_a_court_position_trigger = {
			CHARACTER = prev
		}
	}
	is_human = yes
}

# A courtier feels slighted that they were passed over for a minor title
## Is triggered from basic_gained_court_position_effect
court.5050 = {
	type = court_event
	title = court.5050.t
	desc = court.5050.desc
	theme = court

	court_scene = {
		button_position_character = scope:courtier
		roles = {
			scope:courtier = {
				group = event_group
				animation = anger
			}
			scope:courtier_given_title = {
				group = event_group
				animation = dismissal
			}
		}
	}

	trigger = {
		has_royal_court = yes
		NOT = { has_character_flag = had_event_court_5050 }
		scope:courtier = {
			ai_greed >= 50
			ai_vengefulness >= 50
			has_relation_potential_rival = root
			is_alive = yes
			has_any_court_position = no
			can_be_employed_in_any_court_position_trigger = yes
			is_courtier_of = root
			has_court_event_flag = no
		}
		exists = scope:courtier_given_title
		scope:courtier_given_title = {
			is_alive = yes
			has_any_court_position = yes
			has_court_event_flag = no
			OR = {
				# Don't complain about doctors...
				scope:courtier_given_title = {
					NOR = {
						has_court_position = executioner_court_position
						has_court_position = court_physician_court_position
						has_court_position = court_jester_court_position
						#AGOT Added
						has_court_position = maester_court_position
					}
				}
			}
			is_courtier_of = root
		}
	}

	immediate = {
		add_character_flag = {
			flag = had_event_court_5050
		}
		if = { #Will always exists, but is throwing errors about not being set, so we add this check to avoid that
			limit = {
				NOT = { exists = scope:courtier_given_title }
				exists = scope:employee
			}
			scope:employee = {
				save_scope_as = courtier_given_title
				court_event_character_flag_effect = yes
			}
		}

		if = {
			limit = {
				character_can_be_employed_in_a_court_position_trigger = {
					CHARACTER = scope:courtier
				}
			}
			mark_court_position_for_employment_effect = {
				CHARACTER = scope:courtier
			}
		}
	}

	option = { #Tell them off
		name = court.5050.a

		if = {
			limit = {
				NOT = { has_relation_rival = scope:courtier }
			}
			progress_towards_rival_effect = {
				CHARACTER = scope:courtier
				REASON = rival_courtier_title
				OPINION = default_rival_opinion
			}
		}
		else = {
			scope:courtier = {
				add_opinion = {
					target = root
					modifier = refusal_opinion
					opinion = -15
				}
			}
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = -0.25
			}
			opinion_modifier = {
				opinion_target = scope:courtier_given_title
			}
		}
	}

	option = { #Give them a minor title
		name = court.5050.b
		trigger = {
			exists = scope:court_position_to_fill
		}

		employ_character_as_marked_court_position_effect = { 
			CHARACTER = scope:courtier
			POSITION = scope:court_position_to_fill
		}
			
		scope:courtier = {
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 20
			}
		}

		scope:courtier_given_title = {
			add_opinion = {
				target = root
				modifier = insult_opinion
				opinion = -30
			}
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = 0.5
			}
			opinion_modifier = {
				opinion_target = scope:courtier
			}
		}
	}

	option = { #If you're gonna act like a clown...
		name = court.5050.c
		trigger = {
			can_appoint_char_to_court_position = {
				CHAR = scope:courtier
				COURT_POS = court_jester_court_position
			}
		}
		appoint_court_position = {
			recipient = scope:courtier
			court_position = court_jester_court_position
		}
		progress_towards_rival_effect = {
			CHARACTER = scope:courtier
			REASON = rival_courtier_clown
			OPINION = default_rival_opinion
		}

		scope:courtier_given_title = {
			add_opinion = {
				target = root
				modifier = humorous_opinion
				opinion = 10
			}
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_vengefulness = 0.5
				ai_compassion = -0.5
			}
			opinion_modifier = {
				opinion_target = scope:courtier
			}
		}
	}
	after = {
		scope:courtier_given_title = {
			clear_court_event_participation = yes
		}
	}
}

#####################################
# Colorful Talent                   #
# by Linnéa Thimrén                 #
#####################################

scripted_trigger court_5055_child_painter_trigger = {
	is_available_child = yes
	age >= 6
	NOT = { is_player_heir_of = root }
}

#A young courtier is exploring their artistic side - encourage or dissuade? 
court.5055 = {
	type = court_event
	title = court.5055.t
	desc = court.5055.desc
	theme = court

	court_scene = {
		button_position_character = scope:painter
		roles = {
			scope:painter = {
				group = event_group
				animation = admiration
			}
		}
	}
	
	trigger = {
		NOT = { has_character_flag = had_event_court_5055 }
		age >= 10
		any_courtier = {
			court_5055_child_painter_trigger = yes
			has_court_event_flag = no
		}
	}

	weight_multiplier = {
		base = 1

		# Court weightings.
		## More likely at courts with more time for non-active pursuits.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_scholarly }
	}

	immediate = {
		add_character_flag = {
			flag = had_event_court_5055
			years = 10
		}
		random_courtier = {
			limit = {
				court_5055_child_painter_trigger = yes
			}
			save_scope_as = painter
			court_event_character_flag_effect = yes
			hidden_effect = {
				random_list = {
					75 = { #They're the real deal
						save_scope_value_as = {
							name = real_talent
							value = yes
						}
					}
					25 = { #They were just faking it
						modifier = {
							add = 50
							OR = {
								ai_greed >= medium_positive_greed
								ai_honor <= low_negative_honor
								has_trait = deceitful
							}
						}
						modifier = {
							add = 15
							has_focus = education_intrigue
						}
					}
				}
			}
		}
	}

	option = { #Make them stop
		name = court.5055.a
		#Lose some court grandeur
		change_current_court_grandeur = minor_court_grandeur_loss
		scope:painter = {
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = -20
			}
		}
	}

	option = { #Encourage them
		name = court.5055.b
		custom_tooltip = court.5055.b_tt

		#Follow-up
		if = {
			limit = {
				exists = scope:real_talent
			}
			trigger_event = {
				id = court.5056
				years = { 10 12 }
			}
		}
		else = {
			trigger_event = {
				id = court.5057
				years = { 8 12 }
			}
		}
	}
	after = {
		scope:painter = {
			clear_court_event_participation = yes
		}
	}
}

#They're actually talented
court.5056 = {
	type = character_event
	title = court.5055.t
	desc = {
		desc = court.5056.desc_opening
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:painter = { is_close_family_of = root }
				}
				desc = court.5056.desc_family
			}
			desc = court.5056.desc
		}
		desc = court.5056.desc_ending
	}
	theme = court
	left_portrait = {
		character = scope:painter
		animation = happiness
	}
	
	trigger = {
		scope:painter = {
			is_alive = yes
			is_courtier_of = root
			OR = {
				ep1_is_valid_character_for_inspiration_trigger = yes
				AND = {
					exists = scope:painter.inspiration
					scope:painter.inspiration = {
						exists = inspiration_sponsor
						inspiration_sponsor = root
					}
				}
			}
		}
	}

	on_trigger_fail = {
		# If it's just because they can't have an inspiration we trigger the "failure" event
		if = {
			limit = {
				scope:painter = {
					is_alive = yes
					is_courtier_of = root
					ep1_is_valid_character_for_inspiration_trigger = no
				}
			}
			trigger_event = court.5057
		}
	}

	immediate = {
		hidden_effect = { grant_inspiration_to_character_effect = { CHARACTER = scope:painter } }
		if = {
			limit = { has_royal_court = yes }
			change_current_court_grandeur = medium_court_grandeur_gain
		}
		#We need to save the scopes to be able to use the fund inspiration effect properly
		save_scope_as = actor
		scope:painter = { save_scope_as = recipient }
	}

	option = { #Sponsor them
		name = court.5056.a
		trigger = {
			scope:painter = {
				inspiration = {
					NOT = { exists = inspiration_sponsor }
				}
			}
		}
		fund_inspiration_effect = yes
	}

	option = { #Don't sponsor
		name = court.5056.b
		scope:painter = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -20
			}
		}
	}
}


#They were a scam all along
court.5057 = {
	type = character_event
	title = court.5055.t
	desc = court.5057.desc
	theme = court
	left_portrait = {
		character = scope:painter
		animation = schadenfreude
	}
	
	trigger = {
		scope:painter ?= {
			is_alive = yes
			is_courtier_of = root
		}
	}

	immediate = {
		#Lose some court grandeur
		if = {
			limit = { has_royal_court = yes }
			change_current_court_grandeur = minor_court_grandeur_loss
		}
	}

	option = { #Forgive
		name = court.5057.a
		stress_impact = {
			compassionate = minor_stress_impact_loss
		}
	}

	option = { #Imprison
		name = court.5057.b
		imprison_character_effect = {
			TARGET = scope:painter
			IMPRISONER = root
		}
		stress_impact = {
			vengeful = medium_stress_impact_loss
		}
	}
}

#####################################
# The Gallant Knight                #
# by Linnéa Thimrén                 #
#####################################

scripted_trigger court_5060_knight_trigger = {
	is_knight_of = root
	basic_is_available_ai = yes
	NOT = { has_character_flag = was_the_target_of_event_court_5060 }
	exists = var:number_of_impressive_knight_things
}

#A knight has excelled during recent battles (injured or killed enemies) and you are expected to reward them
court.5060 = {
	type = court_event
	title = court.5060.t
	desc = court.5060.desc
	theme = court

	court_scene = {
		button_position_character = scope:knight
		roles = {
			scope:knight = {
				group = event_group
				animation = personality_honorable
			}
		}
	}
	
	trigger = {
		NOT = { has_character_flag = had_event_court_5060 }
		age >= 10
		has_variable_list = impressive_knights
		any_in_list = {
			variable = impressive_knights
			court_5060_knight_trigger = yes
			has_court_event_flag = no
		}
		any_held_title = {
			tier = tier_county
			NOT = { this = root.capital_county }
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = 0.5
			any_in_list = {
				variable = impressive_knights
				court_5060_knight_trigger = yes
				var:number_of_impressive_knight_things >= 2
			}
		}
		modifier = {
			add = 1
			any_in_list = {
				variable = impressive_knights
				court_5060_knight_trigger = yes
				var:number_of_impressive_knight_things >= 4
			}
		}

		# Court weightings.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_warlike }
	}

	immediate = {
		add_character_flag = {
			flag = had_event_court_5060
			years = 10
		}
		random_in_list = {
			variable = impressive_knights
			limit = {
				court_5060_knight_trigger = yes
			}
			add_character_flag = {
				flag = was_the_target_of_event_court_5060
				years = 10
			}
			
			weight = {
				base = 1
				modifier = {
					add = {
						add = var:number_of_impressive_knight_things
						multiply = 2
					}
				}
			}
			save_scope_as = knight
			court_event_character_flag_effect = yes
		}

		random_held_title = {
			limit = {
				tier = tier_county
				NOT = { this = root.capital_county }
			}
			save_scope_as = title_to_grant
		}
	}

	option = { #Pat on the shoulder
		name = court.5060.a
		#Lose some court grandeur
		change_current_court_grandeur = minor_court_grandeur_loss

		scope:knight = {
			add_prestige = medium_prestige_gain
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -20
			}
		}
	}

	option = { #Give title
		name = court.5060.b
		#AGOT Added
		trigger = {
			NOT = { has_trait = nightswatch }
			NOT = { has_trait = kingsguard }
			NOT = { has_trait = maester }
			NOT = { has_trait = septon }
		}
		#Get a lot court grandeur
		change_current_court_grandeur = medium_court_grandeur_gain
		create_title_and_vassal_change = {
			type = granted
			save_scope_as = change
		}
		scope:title_to_grant = {
			change_title_holder = {
				holder = scope:knight
				change = scope:change
			}
		}
		resolve_title_and_vassal_change = scope:change
		if = {
			limit = {
				NOT = { has_relation_friend = scope:knight }
			}
			progress_towards_friend_effect = {
				REASON = friend_landed
				CHARACTER = scope:knight
				OPINION = default_friend_opinion
			}
		}
		else = {
			scope:knight = {
				add_opinion = {
					target = root
					modifier = friendliness_opinion
					opinion = 30
				}
			}
		}
		stress_impact = {
			generous = major_stress_impact_loss
			arrogant = medium_stress_impact_gain
		}
	}

	option = { #Give gold
		name = court.5060.c
		trigger = {
			short_term_gold >= medium_gold_value
		}
		#Get some court grandeur
		change_current_court_grandeur = minor_court_grandeur_gain
		pay_short_term_gold = {
			target = scope:knight
			gold = medium_gold_value
		}

		if = {
			limit = {
				NOT = { has_relation_friend = scope:knight }
			}
			progress_towards_friend_effect = {
				REASON = friend_gave_gold
				CHARACTER = scope:knight
				OPINION = 0
			}
		}
		else = {
			scope:knight = {
				add_opinion = {
					target = root
					modifier = friendliness_opinion
					opinion = 20
				}
			}
		}
		stress_impact = {
			generous = major_stress_impact_loss
			greedy = medium_stress_impact_gain
		}
	}

	option = { #Give minor title
		trigger = {
			OR = {
				can_appoint_char_to_court_position = {
					CHAR = scope:knight
					COURT_POS = bodyguard_court_position
				}
				can_appoint_char_to_court_position = {
					CHAR = scope:knight
					COURT_POS = champion_court_position
				}
			}
		}
		# employ them as champion or bodyguard
		name = {
			trigger = { 
				can_appoint_char_to_court_position = {
					CHAR = scope:knight
					COURT_POS = champion_court_position
				}
			}
			text = court.5060.d.champion 
		}
		name = {
			trigger = { 
				NOT = { 
					can_appoint_char_to_court_position = {
						CHAR = scope:knight
						COURT_POS = champion_court_position
					}
				}
			}
			text = court.5060.d.bodyguard
		}
		if = {
			limit = {
				can_appoint_char_to_court_position = {
					CHAR = scope:knight
					COURT_POS = champion_court_position
				}
			}
			employ_character_as_position_in_current_scope_court_effect = { 
				CHARACTER = scope:knight 
				POSITION = champion_court_position
			}
		}
		else_if = {
			limit  = {
				can_appoint_char_to_court_position = {
					CHAR = scope:knight 
					COURT_POS = bodyguard_court_position
				}
			}
			employ_character_as_position_in_current_scope_court_effect = { 
				CHARACTER = scope:knight 
				POSITION = bodyguard_court_position
			}
		}

		if = {
			limit = {
				NOT = { has_relation_friend = scope:knight }
			}
			progress_towards_friend_effect = {
				REASON = friend_gave_court_position
				CHARACTER = scope:knight
				OPINION = 0
			}
		}
		else = {
			scope:knight = {
				add_opinion = {
				target = root
					modifier = friendliness_opinion
					opinion = 20
				}
			}
		}
	}
	after = {
		scope:knight = {
			clear_court_event_participation = yes
		}
	}
}

#Maintenance event for the impressive knight variables - variables decrease over time or is removed
court.5061 = {
	hidden = yes
	
	trigger = {
		exists = var:number_of_impressive_knight_things
	}

	immediate = {
		if = {
			limit = {
				liege = {
					has_variable_list = impressive_knights
					any_in_list = {
						variable = impressive_knights
						this = root
					}
				}
			}
			change_variable = {
				name = number_of_impressive_knight_things
				subtract = 1
			}
			if = {
				limit = {
					var:number_of_impressive_knight_things = 0
				}
				remove_variable = number_of_impressive_knight_things
				liege = {
					remove_list_variable = {
						name = impressive_knights
						target = root
					}
				}
			}
			else = {
				trigger_event = {
					id = court.5061
					years = 4
				}
			}
		}
		else = {
			remove_variable = number_of_impressive_knight_things
		}
	}
}

#####################################
# Dedicated Tutor                   #
# by Linnéa Thimrén                 #
#####################################

#Court tutor asks for more funds
court.5070 = {
	type = court_event
	title = court.5070.t
	desc = court.5070.desc
	theme = court

	court_scene = {
		button_position_character = scope:court_tutor
		roles = {
			scope:court_tutor = {
				group = event_group
				animation = admiration
			}
		}
	}
	
	trigger = {
		NOT = { has_character_flag = had_event_court_5070 }
		age >= 10
		short_term_gold > medium_gold_value
		employs_court_position = court_tutor_court_position
		any_court_position_holder = {
			type = court_tutor_court_position
			is_available_ai = yes
			has_court_event_flag = no
		}
	}

	weight_multiplier = {
		base = 1

		# Court weightings.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_administrative }
	}

	immediate = {
		add_character_flag = {
			flag = had_event_court_5070
			years = 10
		}
		random_court_position_holder = {
			type = court_tutor_court_position
			limit = {
				is_available_ai = yes
			}
			save_scope_as = court_tutor
			court_event_character_flag_effect = yes
		}
	}

	option = { #nah
		name = court.5070.a
		scope:court_tutor = {
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = -10
			}
		}
	}

	option = { #Pay to improve the education of all courtiers
		name = court.5070.b
		custom_tooltip = court.5070.b.tt
		every_courtier = {
			limit = {
				is_adult = no
				any_relation = {
					type = guardian
					OR = {
						is_courtier_of = root
						this = root
					}
				}
			}
			hidden_effect = {
				education_point_acquisition_effect = yes
				education_point_acquisition_effect = yes
			}
		}

		remove_short_term_gold = medium_gold_value
		scope:court_tutor = {
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = 15
			}
		}
	}
	after = {
		scope:court_tutor = {
			clear_court_event_participation = yes
		}
	}
}

#####################################
# Gift From Neigh-bor               #
# by Linnéa Thimrén                 #
#####################################

# You receive a gift of two palfreys
scripted_trigger court_5075_neighbor_trigger = {
	NOR = {
		has_relation_potential_rival = root
		has_relation_rival = root
		is_at_war_with = root
	}
}

court.5075 = {
	type = court_event
	title = court.5075.t
	desc = {
		desc = court.5075.desc_opening
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:master_of_the_horse
				}
				desc = court.5075.desc_horse_master
			}
			desc = court.5075.desc
		}
		desc = court.5075.desc_ending
	}
	theme = court
	override_background = {
		reference = courtyard
	}

	court_scene = {
		button_position_character = scope:master_of_the_horse
		roles = {
			scope:neighbor = {
				group = event_group
				animation = admiration
			}
			scope:master_of_the_horse = {
				group = event_group
				animation = happiness
			}
		}
	}
	
	trigger = {
		has_royal_court = yes
		employs_court_position = master_of_horse_court_position
		any_court_position_holder = {
			type = master_of_horse_court_position
			is_available_ai = yes
			has_court_event_flag = no
		}
		NOT = { has_character_flag = had_event_court_5075 }
		age >= 14
		OR = {
			AND = {
				is_independent_ruler = yes
				any_neighboring_top_liege_realm_owner = {
					court_5075_neighbor_trigger = yes
					has_court_event_flag = no
				}
			}
			AND = {
				is_independent_ruler = no
				any_neighboring_realm_same_rank_owner = {
					court_5075_neighbor_trigger = yes
					has_court_event_flag = no
				}
			}
		}
	}

	weight_multiplier = {
		base = 0.5
		modifier = { #More likely to trigger if you have a Master of the Horse
			add = 0.5
			employs_court_position = master_of_horse_court_position
			any_court_position_holder = {
				type = master_of_horse_court_position
				is_available_ai = yes
				has_court_event_flag = no
			}
		}

		# Court weightings.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_warlike }
	}

	immediate = {
		add_character_flag = {
			flag = had_event_court_5075
			years = 10
		}
		if = {
			limit = {
				is_independent_ruler = yes
			}
			random_neighboring_top_liege_realm_owner = {
				limit = {
					court_5075_neighbor_trigger = yes
				}
				save_scope_as = neighbor
				court_event_character_flag_effect = yes
			}
		}
		else = {
			random_neighboring_realm_same_rank_owner = {
				limit = {
					court_5075_neighbor_trigger = yes
				}
				save_scope_as = neighbor
				court_event_character_flag_effect = yes
			}
		}
		hidden_effect = {
			if = {
				limit = {
					can_set_relation_potential_friend_trigger = { CHARACTER = scope:neighbor }
				}
				set_relation_potential_friend = scope:neighbor
			}
		}
		if = {
			limit = {
				has_royal_court = yes
				employs_court_position = master_of_horse_court_position
				any_court_position_holder = {
					type = master_of_horse_court_position
					is_available_ai = yes
				}
			}
			random_court_position_holder = {
				type = master_of_horse_court_position
				limit = {
					is_available_ai = yes
				}
				save_scope_as = master_of_the_horse
				court_event_character_flag_effect = yes
			}
		}

		random_dummy_gender_effect = yes #for horse gender
	}

	option = { # All horses at court will be better equipped - gain CGV
		name = court.5075.a
		#Gain some court grandeur
		change_current_court_grandeur = minor_court_grandeur_gain
		stress_impact = {
			humble = minor_stress_impact_loss
		}
	}

	option = { # Sell them
		name = court.5075.b
		add_gold = medium_gold_value
		scope:neighbor = {
			add_opinion = {
				target = root
				modifier = insulted_opinion
				opinion = -20
			}
		}
		stress_impact = {
			greedy = medium_stress_impact_loss
		}
	}

	option = { # Warhorse
		name = court.5075.c
		trigger = {
			NOT = {
				any_owned_story = { story_type = story_cycle_martial_lifestyle_warhorse }
			}
		}
		add_prestige = medium_prestige_gain
		duel = {
			skill = prowess
			value = average_skill_rating
			15 = { # You tame the horse
				desc = court.5075.c.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 2
				}
				send_interface_toast = {
					title = court.5075.c.success
					left_icon = root
					start_warhorse_story_cycle_effect = yes
				}
				#To assign the correct gender to the horse
				random_owned_story = {
					limit = { story_type = story_cycle_martial_lifestyle_warhorse }
					if = {
						limit = { scope:dummy_gender = { is_female = yes } }
						assign_horse_gender_effect = { GENDER = female }
					}
					else = {
						assign_horse_gender_effect = { GENDER = male }
					}
				}
			}
			6 = { # The horse kicks your ass
				desc = court.5075.c.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -0.5
				}
				send_interface_toast = {
					title = court.5075.c.failure
					left_icon = root
					increase_wounds_effect = {
						REASON = horse_riding_accident
					}
				}
			}
		}
		stress_impact = {
			ambitious = minor_stress_impact_loss
			brave = minor_stress_impact_loss
		}
	}
	after = {
		scope:neighbor = {
			clear_court_event_participation = yes
		}
		scope:master_of_the_horse = {
			clear_court_event_participation = yes
		}
	}
}

##################################################
# Claudia

##################################################
# 6000 - 6009	Secret History
# 6010 - 6019	Prophet in the Halls
# 6020 - 6029	Possession at Court
# 6030 - 6039	The Ballad of the Garlic King
# 6040 - 6049	Scrounger Life
# 6050 - 6059	Saucy Readings
# 6060 - 6069	The Joys of Wine
# 6070 - 6079	The Value of Letters
# 6080			The Munificence of X
# 6090			The Art of Rhetoric
##################################################

#########################
# Secret History		#
# by Claudia Baldassi	#
# 6000-6003				#
#########################

scripted_trigger court_6000_has_valid_secret_trigger = {
	NOT = { is_known_by = root }
	OR = {
		secret_type = secret_lover
		secret_type = secret_deviant
		secret_type = secret_murder
	}
}

# A book detailing the nefarious deeds of your predecessor and their court is being circulated at your court. #
	
court.6000 = {
	type = court_event
	title = court.6000.t
	desc = {
		desc = court.6000.desc_opening
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:courtier = {
						is_close_or_extended_family_of = root
					}
				}
				desc = court.6000.desc_family
			}
			desc = court.6000.desc_liege
		}
		desc = court.6000.desc_ending
	}
	theme = court

	court_scene = {
		button_position_character = scope:courtier
		roles = {
			scope:courtier = {
				group = event_group
				animation = shame
			}
			root = {
				group = event_group
				animation = shock
			}
		}
	}

	trigger = {
		has_court_event_flag = no
		primary_title.tier >= tier_duchy
		exists = primary_title.previous_holder
		primary_title.previous_holder = {
			is_alive = no
			dynasty = root.dynasty
			prestige_level >= 3
			highest_held_title_tier >= tier_duchy
		}
		age >= 14
		any_courtier = {
			count >= 2
			age >= 14
			has_court_event_flag = no
		}
		any_courtier = {
			learning >= 12
			intrigue >= 7
			is_adult = yes
		}
		NOR = {
			has_trait = blind
			has_character_flag = court_6000_cooldown
		}
	}

	weight_multiplier = {
		base = 1

		# Court weightings.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_scholarly }
	}

	immediate = {
		court_event_character_flag_effect = yes
		add_character_flag = {
			flag = court_6000_cooldown
			years = 20
		}
		random_courtier = {
			limit = {
				learning >= 12
				intrigue >= 7
				is_adult = yes
			}
			save_scope_as = author
		}
		random_courtier_or_guest = {
			limit = {
				age >= 14
				NOT = {
					THIS = scope:author
				}
			}
			save_scope_as = courtier
			court_event_character_flag_effect = yes
		}
		if = {
			limit = {
				primary_title.previous_holder = {
					NOT = {
						THIS = root
					}
				}
			}
			primary_title.previous_holder = {
				save_scope_as = predecessor
			}
		}
		if = {
			limit = {
				exists = cp:councillor_spymaster
			}
			cp:councillor_spymaster = {
				save_scope_as = spymaster
			}
		}
	}

	# Option A: Outrageous! Investigate who wrote it (has spymaster)
	option = {
		trigger = {
			exists = scope:spymaster
		}
		name = court.6000.a
		custom_tooltip = court.6000.a.tt
		add_stress = minor_stress_gain
		scope:spymaster = {
			set_council_task = {
				task_type = task_find_secrets
				target = root
			}
		}
		trigger_event = {
			id = court.6001
			days = { 96 196 }
		}
		ai_chance = {
			base = 100
		}
	}

	# Option E: Outrageous, but without a sypmaster
	option = {
		name = court.6000.a
		trigger = {
			NOT = {
				exists = cp:councillor_spymaster
			}
		}
		add_stress = minor_stress_gain
		custom_tooltip = court.6000.e.tt
		trigger_event = {
			id = court.6004
			days = { 96 196 }
		}
		ai_chance = {
			base = 100
		}
	}

	# Option B: Juicy! Get into the gossiping
	option = {
		trigger = {
			OR = {
				has_trait = deceitful
				has_education_intrigue_trigger = yes
				has_trait = contrite
			}
		}
		name = court.6000.b
		add_stress = medium_stress_loss
		add_intrigue_skill = 1
		if = {
			limit = {
				any_courtier = {
					any_secret = {
						court_6000_has_valid_secret_trigger = yes
					}
				}
			}
			custom_tooltip = court.6000.b.tt
			random_courtier = {
				limit = {
					any_secret = {
						court_6000_has_valid_secret_trigger = yes
					}
				}
				random_secret = {
					limit = {
						court_6000_has_valid_secret_trigger = yes
					}
					reveal_to = root
				}
			}
		}
		ai_chance = {
			base = 150
			modifier = {
				has_trait = honest
				add = -100
			}
		}
	}

	# Option C: Your predecessor deserved it and more!
	option = {
		name = court.6000.c
		custom_tooltip = court.6000.c.tt
		add_dread = medium_dread_gain
		stress_impact = {
			honest = minor_stress_impact_gain
			just = medium_stress_impact_gain
			forgiving = major_stress_impact_gain
			compassionate = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_vengefulness = 1
			}
		}
	}

	# Option D: You really don't care - restricted to lazy etc
	option = {
		name = court.6000.d
		trigger = {
			OR = {
				has_trait = lazy
				has_trait = content
				has_trait = arbitrary
				has_trait = callous
				has_trait = fickle
				has_trait = reclusive
				has_trait = irritable
				has_trait = depressed_1
				has_trait = depressed_genetic
			}
		}
		dynasty = { 
			add_dynasty_prestige = minor_dynasty_prestige_loss
		}
		change_current_court_grandeur = medium_court_grandeur_loss
		stress_impact = {
			base = minor_stress_impact_loss
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_energy = -0.5
			}
		}
	}

	# Optione F: Accept it and move on - restricted to calm etc
	option = {
		name = court.6000.f
		trigger = {
			OR = {
				has_trait = diplomat
				has_trait = calm
				has_trait = patient
				has_trait = humble
				has_trait = honest
				has_trait = shy
				has_trait = just
				has_trait = compassionate
				has_trait = forgiving
			}
		}
		add_dread = minor_dread_loss
		change_current_court_grandeur = medium_court_grandeur_gain
		stress_impact = {
			arrogant = medium_stress_impact_gain
			vengeful = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = arrogant
				add = -25
			}
			modifier = {
				has_trait = vengeful
				add = -50
			}
		}
	}
	after = {
		scope:courtier = {
			clear_court_event_participation = yes
		}
		clear_court_event_participation = yes
	}
}

court.6001 = {
	type = character_event
	hidden = yes

	immediate = {
		scope:spymaster = {
			duel = {
				skill = intrigue
				target = scope:author
				50 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = 0.5
					}
					trigger_event = court.6002
				}
				50 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = -0.5
					}
					trigger_event = court.6003
				}
			}
		}
	}
}
	
court.6002 = {
	title = court.6000.t
	type = character_event
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:spymaster
				}
				desc = court.6002.desc
			}
			desc = court.6002.b.desc_opening
		}
		desc = court.6002.b.desc_ending
	}
	theme = court
	left_portrait = {
		character = root
		animation = anger
	}
	right_portrait = {
		character = scope:author
		animation = shame
	}

	# Option A: Shame the author
	option = {
		name = court.6002.a
		custom_tooltip = court.6002.a.tt
		dynasty = { 
			add_dynasty_prestige = minor_dynasty_prestige_gain
		}
		change_current_court_grandeur = minor_court_grandeur_gain
		scope:author = {
			add_opinion = {
				target = root
				modifier = shamed_me_opinion
			}
		}
		every_courtier_or_guest = {
			custom = court_6000_all_courtiers_and_guests
			add_opinion = {
				target = root
				modifier = impressed_opinion
				opinion = 10
			}
		}
		every_courtier_or_guest = {
			custom = court_6000_all_courtiers_and_guests
			add_opinion = {
				target = scope:author
				modifier = suspicion_opinion
				opinion = -10
			}
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = gregarious
				add = 25
			}
		}
	}

	#Option B: Imprison the author
	option = {
		name = court.6002.b
		imprison = {
			target = scope:author
			type = house_arrest
		}
		add_dread = minor_dread_gain
		add_stress = minor_stress_loss
		ai_chance = {
			base = 100
			modifier = {
				has_trait = just
				add = 25
			}
		}
	}

	#Option C: Kill the author
	option = {
		name = court.6002.c
		trigger = {
			OR = {
				has_trait = wrathful
				has_trait = sadistic
				has_trait = torturer
				has_trait = arrogant
				has_trait = arbitrary
				has_trait = vengeful
			}
		}
		every_courtier_or_guest = {
			custom = court_6000_all_courtiers_and_guests
			add_opinion = {
				target = root
				modifier = cruelty_opinion
				opinion = -20
			}
		}
		add_dread = medium_dread_gain
		add_stress = medium_stress_loss
		ai_chance = {
			base = 150
		}
	}

	#Option D: forgive the author -limited if you are forgiving
	option = {
		name = court.6002.d
		trigger = {
			has_trait = forgiving
		}
		add_dread = medium_dread_loss
		scope:author = {
			add_opinion = {
				target = root
				modifier = forgiven_opinion
			}
		}
		every_courtier_or_guest = {
			custom = court_6000_all_courtiers_and_guests
			duel = {
				skill = diplomacy
				target = root
				50 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = 3
					}
					random_list = {
						1 = {
							add_opinion = {
								target = root
								modifier = weak_opinion
								opinion = -15
							}
						}
						5 = {
							trigger = {
								faith = { trait_is_virtue = forgiving }
							}
							add_opinion = {
								target = root
								modifier = kindness_opinion
								opinion = 15
							}
						}
					}
				}
				50 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = -3
					}
					random_list = {
						1 = {
							add_opinion = {
								target = root
								modifier = kindness_opinion
								opinion = 15
							}
						}
						5 = {
							trigger = {
								faith = { trait_is_sin = forgiving }
							}
							add_opinion = {
								target = root
								modifier = weak_opinion
								opinion = -15
							}
						}
					}	
				}
			}
		}
		ai_chance = {
			base = 200
		}
	}
}

court.6003 = {
	title = court.6000.t
	type = character_event
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:spymaster
				}
				desc = court.6003.desc
			}
			desc = court.6002.b.desc_opening
		}
		desc = court.6003.b.desc_ending
	}
	theme = court
	left_portrait = {
		character = root
		animation = disapproval
	}
	right_portrait = {
		character = scope:spymaster
		animation = shame
	}

	# Option A: no spymaster - nevermind - limited if you are fickle etc
	option = {
		name = court.6003.a
		trigger = {
			NOT = {
				exists = scope:spymaster
			}
			OR = {
				has_trait = fickle
				has_trait = arbitrary
				has_trait = depressed_1
				has_trait = depressed_genetic
				has_trait = lazy
				has_trait = impatient
			}
		}
		add_prestige = minor_prestige_loss
		change_current_court_grandeur = minor_court_grandeur_loss
		ai_chance = {
			base = 150
		}
	}

	#Option B: no spymaster - disappointed with yourself
	option = {
		name = court.6003.b
		trigger = {
			NOT = {
				exists = scope:spymaster
			}
		}
		add_stress = medium_stress_gain
		ai_chance = {
			base = 100
		}
	}

	#Option C: lash out at court
	option = {
		name = court.6003.c
		trigger = {
			OR = {
				has_trait = wrathful
				has_trait = impatient
				has_trait = arbitrary
				has_trait = irritable
			}
		}
		add_dread = major_dread_gain
		stress_impact = {
			patient = medium_stress_impact_gain
			calm = major_stress_impact_gain
			compassionate = major_stress_impact_gain
		}
		ai_chance = {
			base = 150
			modifier = {
				has_trait = patient
				add = -25
			}
			modifier = {
				has_trait = calm
				add = -50
			}
			modifier = {
				has_trait = compassionate
				add = -50
			}
		}
	}

	#Option D: spymaster tried their best...
	option = {
		name = court.6003.d
		trigger = {
			exists = scope:spymaster
		}
		scope:spymaster = {
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 20
			}
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = forgiving
				add = 25
			}
			modifier = {
				has_trait = compassionate
				add = 25
			}
		}
	}

	#Option E: spymaster takes all the blame
	option = {
		name = court.6003.e
		trigger = {
			exists = scope:spymaster
		}
		imprison = {
			target = scope:spymaster
			type = house_arrest
		}
		stress_impact = {
			just = medium_stress_impact_gain
			forgiving = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = just
				add = -25
			}
			modifier = {
				has_trait = forgiving
				add = -50
			}
		}
	}
}

court.6004 = {
	type = character_event
	hidden = yes

	immediate = {
		duel = {
			skill = intrigue
			target = scope:author
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 0.5
				}
				trigger_event = court.6002
			}
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -0.5
				}
				trigger_event = court.6003
			}
		}
	}
}

#############################
# Prophet in the Halls		#
# by Claudia Baldassi		#
# 6010-6011					#
#############################

scripted_trigger court_6010_valid_preacher_trigger = {
	is_adult = yes
	has_trait = zealous
	NOR = {
		faith = root.faith
		faith = { has_doctrine = doctrine_pluralism_pluralistic }
	}
}

# A guest of a different faith has been preaching their beliefs at court a bit too enthusiastically. #

court.6010 = {
	type = court_event
	title = court.6010.t
	desc = court.6010.desc
	theme = court

	court_scene = {
		button_position_character = scope:preacher
		roles = {
			scope:preacher = {
				group = event_group
				animation = personality_zealous
			}
			root = {
				group = event_group
				animation = disapproval
			}
		}
	}

	trigger = {
		has_court_event_flag = no
		any_courtier_or_guest = {
			court_6010_valid_preacher_trigger = yes
			has_court_event_flag = no
		}
		NOT = {
			has_character_flag = court_6010_cooldown
		}
	}

	weight_multiplier = {
		base = 1

		# Court weightings.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_scholarly }
	}

	immediate = {
		court_event_character_flag_effect = yes
		add_character_flag = {
			flag = court_6010_cooldown
			years = 20
		}
		random_courtier_or_guest = {
			limit = {
				court_6010_valid_preacher_trigger = yes
			}
			save_scope_as = preacher
			court_event_character_flag_effect = yes
		}
		if = {
			limit = {
				exists = scope:preacher.liege
				NOT = {
					scope:preacher.liege = root
				}
			}
			scope:preacher.liege = {
				save_scope_as = preacher_liege
			}
		}
	}

	#OPTION A: Let them be
	option = {
		name = court.6010.a
		every_courtier_or_guest = {
			limit = {
				NOT = {
					faith = scope:preacher.faith
				}
			}
			custom = court_6010_all_courtiers_and_guests_faith
			add_opinion = {
				target = root
				modifier = annoyed_opinion
				opinion = -10
			}
		}
		if = { # You can add a favour hook to the preacher
			limit = {
				can_add_hook = {
					type = favor_hook
					target = scope:preacher
				}
			}
			add_hook = {
				target = scope:preacher
				type = favor_hook
			}
		}
		if = {	#you are tolerant and open-minded
			limit = {
				OR = {
					has_court_type = court_scholarly
					has_court_type = court_diplomatic
				}
			}
			change_current_court_grandeur = medium_court_grandeur_gain
		}
		stress_impact = {
			zealous = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = zealous
				add = -100
			}
		}
	}

	#OPTION B: Send them away/back home
	option = {
		name = court.6010.b
		if = {
			limit = {
				exists = scope:preacher_liege
			}
			remove_courtier_or_guest = {
				character = scope:preacher
				new_location = scope:preacher_liege.capital_province
			}
			if = {
				limit = {
					scope:preacher_liege.faith = scope:preacher.faith
				}
				scope:preacher_liege = {
					add_opinion = {
						target = root
						modifier = annoyed_opinion
						opinion = -10
					}
					progress_towards_rival_effect = {
						CHARACTER = root
						REASON = rival_dismissed_preacher
						OPINION = 0
					}
				}
			}
		}
		else = {
			remove_courtier_or_guest = {
				character = scope:preacher
			}
		}
		every_courtier_or_guest = {
			limit = {
				NOT = {
					faith = scope:preacher.faith
				}
			}
			custom = court_6010_all_courtiers_and_guests_faith
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 20
			}
		}
		add_stress = minor_stress_loss
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = 0.5
			}
		}
	}

	#OPTION C: Imprison them - their liege might protest
	option = {
		name = court.6010.c
		imprison = {
			target = scope:preacher
			type = house_arrest
		}
		if = {
			limit = {
				exists = scope:preacher_liege
			}
			custom_tooltip = court.6010.c.tt
			if = {
				limit = {
					scope:preacher_liege.faith = scope:preacher.faith
				}
				scope:preacher_liege = {
					add_opinion = {
						target = root
						modifier = insult_opinion
						opinion = -30
					}
				}
				trigger_event = {
					id = court.6011
					days = 15
				}
			}
		}
		if = {	#you are not tolerant and open-minded
			limit = {
				OR = {
					has_court_type = court_scholarly
					has_court_type = court_diplomatic
				}
			}
			change_current_court_grandeur = medium_court_grandeur_loss
		}
		every_courtier_or_guest = {
			limit = {
				NOT = {
					faith = scope:preacher.faith
				}
			}
			custom = court_6010_all_courtiers_and_guests_faith
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 20
			}
		}
		add_stress = minor_stress_loss
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = 1
			}
		}
	}

	#OPTION D: Kill them -  limited to cruel/zealous - if they are foreigner, their liege might be very displeased
	option = {
		name = court.6010.d
		trigger = {
			OR = {
				has_trait = zealous
				has_trait = torturer
				has_trait = sadistic
			}
		}
		scope:preacher = {
			death = {
				death_reason = death_execution
				killer = root
			}
		}
		add_stress = medium_stress_loss
		add_dread = major_dread_gain
		if = {
			limit = {
				exists = scope:preacher_liege
			}
			custom_tooltip = court.6010.c.tt
			if = {
				limit = {
					scope:preacher_liege.faith = scope:preacher.faith
				}
				scope:preacher_liege = {
					add_opinion = {
						target = root
						modifier = angry_opinion
						opinion = -50
					}
				}
				trigger_event = {
					id = court.6011
					days = 15
				}
			}
			add_character_flag = court_6010_executed
		}
		ai_chance = {
			base = 150
		}
	}
	after = {
		clear_court_event_participation = yes
		scope:preacher = {
			clear_court_event_participation = yes
		}
	}
}

court.6011 = {
	type = letter_event
	opening = {
		desc = court.6011.desc_opening
	}
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					has_character_flag = court_6010_executed
				}
				desc = court.6011.desc_executed
			}
			desc = court.6011.desc_prisoner
		}
	}
	sender = scope:preacher_liege

	#Option A: sorry for the diplomatic blunder - offer repayment
	option = {
		name = court.6011.a
		add_prestige = minor_prestige_loss
		if = {
			limit = {
				scope:preacher = { 
					is_alive = yes
					is_imprisoned = yes
				}
			}
			scope:preacher = { release_from_prison = yes }
			remove_courtier_or_guest = {
				character = scope:preacher
				new_location = scope:preacher_liege.capital_province
			}
			pay_short_term_gold = {
				target = scope:preacher_liege
				gold = tiny_gold_value
			}
		}
		else = {
			pay_short_term_gold = {
				target = scope:preacher_liege
				gold = minor_gold_value
			}
		}
		scope:preacher_liege = {
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 50
			}
		}
		stress_impact = {
			greedy = medium_stress_impact_gain
			arrogant = medium_stress_impact_gain
			zealous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = greedy
				add = -25
			}
			modifier = {
				has_trait = arrogant
				add = -25
			}
			modifier = {
				has_trait = zealous
				add = -25
			}
			modifier = {
				has_trait = humble
				add = 50
			}
			modifier = {
				gold < minor_gold_value
				add = -100
			}
		}
	}

	#Option B: reiterate that their religion is not welcome at your court
	option = {
		name = court.6011.b
		add_piety = minor_piety_gain
		scope:preacher_liege = {
			add_opinion = {
				target = root
				modifier = insult_opinion
				opinion = -30
			}
		}
		stress_impact = {
			humble = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = humble
				add = -25
			}
			modifier = {
				has_trait = compassionate
				add = -25
			}
			modifier = {
				has_trait = zealous
				add = 25
			}
			modifier = {
				has_trait = arrogant
				add = 25
			}
		}
	}
}

#############################
# Possession at Court		#
# by Claudia Baldassi		#
# 6020						#
#############################

# A possessed courtier is scaring your more religion-oriented courtiers. #

court.6020 = {
	type = court_event
	title = court.6020.t
	desc = {
		desc = court.6020.desc_opening
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:court_chaplain
				}
				desc = court.6020.desc_chaplain
			}
			desc = court.6020.desc_no_chaplain
		}
		desc = court.6020.desc_middle
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:court_physician
				}
				desc = court.6020.desc_physician
			}
			desc = court.6020.desc_no_physician
		}
		desc = court.6020.desc_ending
	}
	theme = court

	court_scene = {
		button_position_character = scope:possessed_char
		roles = {
			scope:possessed_char = {
				group = event_group
				animation = worry
			}
			scope:court_chaplain = {
				group = event_group
				animation = disgust
			}
			scope:court_physician = {
				group = event_group
				animation = disbelief
			}
		}
	}

	trigger = {
		any_courtier_or_guest = {
			has_trait = possessed
			has_court_event_flag = no
		}
		NOT = {
			has_character_flag = court_6020_cooldown
		}
		# Chaplain & physician don't both have to exist, but can't be the same thing.
		OR = {
			NOT = { exists = cp:councillor_court_chaplain }
			court_physician_available_trigger = no
			NOT = {
				cp:councillor_court_chaplain = { has_court_position = court_physician_court_position }
			}
		}
	}

	weight_multiplier = {
		base = 1

		# Court weightings.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_scholarly }
	}

	immediate = {
		add_character_flag = {
			flag = court_6020_cooldown
			years = 20
		}
		random_courtier_or_guest = {
			limit = {
				has_trait = possessed
			}
			save_scope_as = possessed_char
			court_event_character_flag_effect = yes
		}
		if = {
			limit = {
				exists = cp:councillor_court_chaplain
			}
			cp:councillor_court_chaplain = {
				save_scope_as = court_chaplain
				court_event_character_flag_effect = yes
			}
		}
		if = {
			limit = {
				court_physician_available_trigger = yes
			}
			save_court_physician_as_effect = { SCOPE_NAME = court_physician }
			scope:court_physician = {
				court_event_character_flag_effect = yes
			}
		}
		if = {
			limit = {
				has_any_artifact = yes
				any_character_artifact = { artifact_type = pedestal } #yes, someone will be "healed" by the magic power of a fancy box - why don't we have a specific category for reliquaries??
			}
			random_character_artifact = {
				limit = { artifact_type = pedestal }
				save_scope_as = 6020_relic
			}
		}
	}

	#AGOT Disabled, no exorcisms
	# Option A: Court chaplain exorcizes them - limited to christians
	# option = {
	# 	name = court.6020.a
	# 	trigger = {
	# 		exists = scope:court_chaplain
	# 		scope:court_chaplain.religion = religion:christianity_religion
	# 		root.religion = religion:christianity_religion
	# 	}
	# 	add_piety = minor_piety_gain
	# 	scope:court_chaplain = {
	# 		duel = {
	# 			skill = learning
	# 			target = scope:possessed_char
	# 			10 = {
	# 				desc = court.6020.a.success
	# 				compare_modifier = {
	# 					value = scope:duel_value
	# 					multiplier = 1
	# 				}
	# 				send_interface_toast = {
	# 					title = court.6020.a.success
	# 					custom_tooltip = court.6020.a.success.tt
	# 				}
	# 				every_courtier_or_guest = {
	# 					limit = {
	# 						religion = religion:christianity_religion
	# 					}
	# 					custom = court_6020_all_courtiers_and_guests_christian
	# 					add_opinion = {
	# 						target = root
	# 						modifier = pious_opinion
	# 						opinion = 15
	# 					}
	# 				}
	# 				every_courtier_or_guest = {
	# 					limit = {
	# 						religion = religion:christianity_religion
	# 					}
	# 					custom = court_6020_all_courtiers_and_guests_christian
	# 					add_opinion = {
	# 						target = scope:possessed_char
	# 						modifier = trust_opinion
	# 						opinion = 10
	# 					}
	# 				}
	# 				root = {
	# 					if = {
	# 						limit = {
	# 							has_court_type = court_scholarly
	# 						}
	# 						change_current_court_grandeur = major_court_grandeur_gain
	# 					}
	# 					else = { change_current_court_grandeur = medium_court_grandeur_gain }
	# 				}
	# 			}
	# 			15 = {
	# 				desc = court.6020.a.failure
	# 				compare_modifier = {
	# 					value = scope:duel_value
	# 					multiplier = -1
	# 				}
	# 				send_interface_toast = {
	# 					title = court.6020.a.failure
	# 					custom_tooltip = court.6020.a.failure.tt
	# 				}
	# 				every_courtier_or_guest = {
	# 					custom = court_6000_all_courtiers_and_guests
	# 					add_opinion = {
	# 						target = root
	# 						modifier = disappointed_opinion
	# 						opinion = -15
	# 					}
	# 				}
	# 				root = { change_current_court_grandeur = medium_court_grandeur_loss }
	# 			}
	# 		}
	# 	}
	# 	ai_chance = {
	# 		base = 150
	# 		modifier = {
	# 			has_trait = zealous
	# 			add = 50
	# 		}
	# 		modifier = {
	# 			has_trait = cynical
	# 			add = -100
	# 		}
	# 	}
	# }

	# Option B: it is a sign of the favor of the gods - limited to non-monotheistic
	option = {
		name = court.6020.b
		trigger = {
			NOR = {
				#AGOT Modified
				# root.religion = { is_in_family = rf_abrahamic }
				# scope:court_chaplain.religion = { is_in_family = rf_abrahamic }
				root.religion = religion:rhllor_religion
				root.religion = religion:drowned_god_religion
				has_trait = cynical
			}
		}
		add_piety = medium_piety_gain
		scope:possessed_char = {
			add_character_modifier = possessed_prophetic_visions
		}
		every_courtier_or_guest = {
			limit = {
				#AGOT Modified
				# NOR = {
				# 	religion = { is_in_family = rf_abrahamic }
				# 	has_trait = cynical
				# }
				NOT = { has_trait = cynical }
			}
			custom = court_6020_all_courtiers_or_guests_polith
			add_opinion = {
				target = root
				modifier = pious_opinion
				opinion = 15
			}
		}
		every_courtier_or_guest = {
			limit = {
				#AGOT Modified
				# NOR = {
				# 	religion = { is_in_family = rf_abrahamic }
				# 	has_trait = cynical
				# }
				NOT = { has_trait = cynical }
			}
			custom = court_6020_all_courtiers_or_guests_polith
			add_opinion = {
				target = scope:possessed_char
				modifier = respect_opinion
				opinion = 10
			}
		}
		change_current_court_grandeur = medium_court_grandeur_gain
		ai_chance = {
			base = 150
			modifier = {
				has_trait = zealous
				add = 50
			}
		}
	}

	# Option C: use relics/amulets 
	option = {
		trigger = {
			exists = scope:6020_relic
		}
		name = court.6020.c
		custom_tooltip = court.6020.c.tt
		add_piety = medium_piety_gain
		every_courtier_or_guest = {
			custom = court_6000_all_courtiers_and_guests
			add_opinion = {
				target = root
				modifier = pious_opinion
				opinion = 15
			}
		}
		every_courtier_or_guest = {
			custom = court_6000_all_courtiers_and_guests
			limit = { NOT = { this = scope:possessed_char } }
			add_opinion = {
				target = scope:possessed_char
				modifier = trust_opinion
				opinion = 5
			}
		}
		ai_chance = {
			base = 150
			modifier = {
				has_trait = cynical
				add = -100
			}
		}
	}

	# Option D: plant therapy by court physician
	option = {
		name = court.6020.d
		trigger = {
			exists = scope:court_physician
		}
		if = {
			limit = {
				scope:court_physician = {
					OR = {
						has_trait = lifestyle_herbalist
						AND = {
							has_trait = lifestyle_physician
							has_trait_xp = {
								trait = lifestyle_physician
								value >= 50
							}
						}
					}
				}
			}
			custom_tooltip = court.6020.d.tt
			scope:possessed_char = {
				add_character_modifier = court_possessed_improved_condition_modifier
			}
			every_courtier_or_guest = {
				custom = court_6000_all_courtiers_and_guests
				add_opinion = {
					target = root
					modifier = impressed_opinion
					opinion = 15
				}
			}
			if = {
				limit = {
					has_court_type = court_scholarly
				}
				change_current_court_grandeur = major_court_grandeur_gain
			}
			else = { change_current_court_grandeur = medium_court_grandeur_gain }
		}
		else = {
			custom_tooltip = court.6020.d.tt.2
			every_courtier_or_guest = {
				limit = {
					NOT = { this = scope:possessed_char }
				}
				custom = court_6000_all_courtiers_and_guests
				limit = { NOT = { this = scope:possessed_char } }
				add_opinion = {
					target = root
					modifier = pleased_opinion
					opinion = 5
				}
				add_opinion = {
					target = scope:possessed_char
					modifier = trust_opinion
					opinion = 5
				}
			}
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = cynical
				add = 50
			}
			modifier = {
				has_trait = lifestyle_herbalist
				add = 50
			}
			modifier = {
				scope:court_physician = { has_trait = lifestyle_herbalist }
				add = 100
			}
			modifier = {
				has_trait = zealous
				add = -100
			}
		}
	}

	#AGOT Disabled
	# Option E: it's just a disease - limited to islamic and indian
	# option = {
	# 	name = court.6020.e
	# 	trigger = {
	# 		OR = {
	# 			root.religion = religion:islam_religion
	# 			root.religion = { is_in_family = rf_eastern }
	# 		}
	# 	}
	# 	if = {
	# 		limit = {
	# 			OR = {
	# 				has_trait = education_learning
	# 				has_lifestyle = learning_lifestyle
	# 			}
	# 		}
	# 		add_learning_lifestyle_xp = major_lifestyle_xp
	# 	}
	# 	scope:possessed_char = {
	# 		add_character_modifier = court_possessed_improved_condition_modifier
	# 	}
	# 	scope:possessed_char = {
	# 		add_opinion = {
	# 			target = root
	# 			modifier = grateful_opinion
	# 			opinion = 60
	# 		}
	# 	}
	# 	if = {
	# 		limit = {
	# 			has_court_type = court_scholarly
	# 		}
	# 		change_current_court_grandeur = major_court_grandeur_gain
	# 	}
	# 	else = { change_current_court_grandeur = medium_court_grandeur_gain }
	# 	ai_chance = {
	# 		base = 150
	# 		modifier = {
	# 			has_trait = zealous
	# 			add = -100
	# 		}
	# 	}
	# }

	# Option F: don't bother me
	option = {
		name = court.6020.f
		add_prestige = minor_prestige_loss
		scope:possessed_char = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -10
			}
		}
		ai_chance = {
			base = 75
			modifier = {
				has_trait = callous
				add = 50
			}
			modifier = {
				has_trait = lazy
				add = 50
			}
		}
	}
	after = {
		scope:possessed_char = {
			clear_court_event_participation = yes
		}
		if = {
			limit = { exists = scope:court_chaplain }
			scope:court_chaplain = {
				clear_court_event_participation = yes
			}
		}
		if = {
			limit = { exists = scope:court_physician }
			scope:court_physician = {
				clear_court_event_participation = yes
			}
		}
	}
}

#########################
# Saucy Readings		#
# by Claudia Baldassi	#
# 6050					#
#########################

scripted_trigger court_6050_valid_courtier_trigger = {
	is_available_ai_adult = yes
	has_court_event_flag = no
	NOR = {
		has_trait = chaste
		is_councillor_of = root
	}
	NOT = {
		faith = { trait_is_virtue = lustful }
	}
	might_cheat_on_every_partner_trigger = yes
}

# Some "compromising" literature is circulating at court #

court.6050 = {
	type = court_event
	title = court.6050.t
	desc = {
		desc = court.6050.desc_opening
		first_valid = {
			triggered_desc = {
				trigger = {
					#AGOT Modified
					# OR = {
					# 	root.culture = { has_cultural_pillar = language_greek }
					# 	root.culture = { has_cultural_pillar = heritage_byzantine }
					# }
					root.culture = { has_cultural_pillar = heritage_first_man }
				}
				desc = court.6050.desc_byz
			}
			triggered_desc = {
				trigger = {
					#AGOT Modified
					# OR = {
					# 	root.culture = { has_cultural_pillar = language_arabic }
					# 	root.culture = { has_cultural_pillar = language_iranian }
					# 	root.culture = { has_cultural_pillar = heritage_iranian }
					# 	root.culture = { has_cultural_pillar = heritage_arabic }
					# }
					capital_county.title_province ?= {
						OR = {
							geographical_region = world_essos
							#geographical_region = world_stepstones
						}
					}
				}
				desc = court.6050.desc_islam
			}
			triggered_desc = {
				trigger = {
					#AGOT Modified
					# OR = {
					# 	root.culture = { has_cultural_pillar = language_french }
					# 	root.culture = { has_cultural_pillar = language_occitano_romance }
					# 	root.culture = { has_cultural_pillar = heritage_latin }
					# }
					root.culture = { has_cultural_pillar = heritage_rhoynish }
				}
				desc = court.6050.desc_sonetti
			}
			triggered_desc = {
				trigger = {
					#AGOT Modified
					# OR = {
					# 	root.culture = { has_cultural_pillar = language_anglic }
					# 	root.culture = { has_cultural_pillar = language_saxon }
					# }
					root.culture = { has_cultural_pillar = heritage_andal }
				}
				desc = court.6050.desc_chaucer
			}
			triggered_desc = {
				trigger = { always = yes }
				desc = court.6050.desc_generic		#fallback option (mostly for other christians)
			}
		}
		desc = court.6050.desc_ending
	}
	theme = court

	court_scene = {
		button_position_character = scope:courtier
		roles = {
			scope:courtier = {
				group = event_group
				animation = throne_room_writer
			}
			root = {
				group = event_group
				animation = shock
			}
			scope:court_chaplain = {
				group = event_group
				animation = disapproval
			}
		}
	}

	trigger = {
		has_court_event_flag = no
		exists = cp:councillor_court_chaplain
		cp:councillor_court_chaplain = {
			is_available_ai_adult = yes
			has_court_event_flag = no
		}
		is_adult = yes
		NOT = {
			faith = { trait_is_virtue = lustful }
		}
		any_courtier = { court_6050_valid_courtier_trigger = yes }
	}

	weight_multiplier = {
		base = 1

		# Court weightings.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_scholarly }
	}

	immediate = {
		court_event_character_flag_effect = yes
		cp:councillor_court_chaplain = {
			save_scope_as = court_chaplain
			court_event_character_flag_effect = yes
		}
		random_courtier = {
			limit = {
				has_trait = lustful
				court_6050_valid_courtier_trigger = yes
			}
			alternative_limit = { court_6050_valid_courtier_trigger = yes }
			save_scope_as = courtier
			court_event_character_flag_effect = yes
		}
	}

	# Option A: you are scandalized
	option = {
		name = court.6050.a
		trigger = {
			OR = {
				has_trait = chaste
				has_trait = celibate
			}
		}
		add_piety = medium_piety_gain
		scope:court_chaplain = {
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 20
			}
		}
		scope:courtier = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -20
			}
		}
		stress_impact = {
			base = medium_stress_impact_gain
		}
		ai_chance = {
			base = 200
		}
	}

	# Option B: purify them all with fire!
	option = {
		name = court.6050.b
		trigger = {
			OR = {
				has_trait = wrathful
				has_trait = celibate
				has_trait = zealous
				has_trait = theologian
			}
		}
		custom_tooltip = court.6050.b.tt
		add_dread = major_dread_gain
		add_piety = major_piety_gain
		scope:court_chaplain = {
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 30
			}
		}
		every_courtier_or_guest = {
			limit = {
				NOT = {
					has_trait = chaste
				}
			}
			custom = court_6050_courtiers_or_guests
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -20
			}
		}
		stress_impact = {
			compassionate = medium_stress_impact_gain
			patient = medium_stress_impact_gain
			scholar = major_stress_impact_gain
			cynical = major_stress_impact_gain
		}
		ai_chance = {
			base = 200
			modifier = {
				has_trait = compassionate
				add = -25
			}
			modifier = {
				has_trait = patient
				add = -25
			}
			modifier = {
				has_trait = scholar
				add = -50
			}
			modifier = {
				has_trait = cynical
				add = -50
			}
		}
	}

	# Option C: culture is culture - let them read
	option = {
		name = court.6050.c
		trigger = {
			OR = {
				learning >= 12
				has_education_learning_trigger = yes
			}
		}
		trait = education_learning_1
		trait = education_learning_2
		trait = education_learning_3
		trait = education_learning_4
		add_learning_lifestyle_xp = major_lifestyle_xp
		if = {
			limit = {
				learning >= 12
			}
			custom_tooltip = court.6050.c.unlock_text
		}
		if = {
			limit = {
				has_court_type = court_scholarly
			}
			change_current_court_grandeur = major_court_grandeur_gain
		}
		else = {
			change_current_court_grandeur = minor_court_grandeur_gain
		}
		every_courtier_or_guest = {
			limit = {
				NOT = {
					has_trait = chaste
				}
			}
			custom = court_6050_courtiers_or_guests
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 10
			}
		}
		stress_impact = {
			zealous = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = -1
			}
		}
	}

	# Option D: you really get into it
	option = {
		name = court.6050.d
		add_character_modifier = {
			modifier = confident_lover
			years = 10
		}
		scope:court_chaplain = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -20
			}
		}
		stress_impact = {
			chaste = major_stress_impact_gain
			zealous = major_stress_impact_gain
			celibate = massive_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = -0.5
			}
			modifier = {
				has_trait = chaste
				add = -75
			}
			modifier = {
				has_trait = celibate
				add = -100
			}
		}
	}

	# Option E: you take example
	option = {
		name = court.6050.e
		trigger = {
			OR = {
				has_trait = lustful
				has_trait = rakish
				has_trait = seducer
				has_focus = intrigue_temptation_focus
			}
			is_attracted_to_gender_of = scope:courtier
			might_cheat_on_every_partner_trigger = yes
			scope:courtier = {
				is_attracted_to_gender_of = root
				might_cheat_on_every_partner_trigger = yes
			}
		}
		custom_tooltip = court.6050.e.tt
		if = {
			limit = {
				OR = {
					has_relation_lover = scope:courtier
					is_spouse_of = scope:courtier
					scope:courtier = { is_concubine_of = root }
					is_consort_of = scope:courtier
					has_relation_soulmate = scope:courtier
				}
			}
			had_sex_with_effect = {
				CHARACTER = scope:courtier
				PREGNANCY_CHANCE = pregnancy_chance
			}
		}
		else_if = {
			limit = {
				has_relation_potential_lover = scope:courtier
				can_set_relation_lover_trigger = { CHARACTER = scope:courtier }
			}
			set_relation_lover = { reason = lover_erotic_literature target = scope:courtier }
		}
		else = {
			set_relation_potential_lover = scope:courtier
		}
		add_intrigue_lifestyle_xp = major_lifestyle_xp
		add_character_modifier = {
			modifier = 6050_juicy_readings_modifier
			years = 10
		}
		scope:court_chaplain = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -30
			}
		}
		hidden_effect = {
			if = {
				limit = {
					NOR = {
						has_trait = great_pox
						has_trait = lovers_pox
						has_trait = early_great_pox
					}
				}
				random_list = {
					85 = {}
					14 = {
						contract_disease_effect = { DISEASE = lovers_pox TREATMENT_EVENT = yes }
					}
					1 = {
						contract_disease_effect = { DISEASE = great_pox TREATMENT_EVENT = yes }
					}
				}
			}
		}
		stress_impact = {
			chaste = major_stress_impact_gain
			zealous = major_stress_impact_gain
		}
		ai_chance = {
			base = 150
			modifier = {
				has_trait = chaste
				add = -200
			}
			ai_value_modifier = {
				ai_zeal = -0.5
			}
		}
	}

	#Option F: move on
	option = {
		name = court.6050.f
		scope:courtier = {
			add_opinion = {
				target = root
				modifier = relieved_opinion
				opinion = 10
			}
		}
		stress_impact = {
			zealous = medium_stress_impact_gain
			chaste = medium_stress_impact_gain
		}
		ai_chance = {
			base = 75
			modifier = {
				has_trait = zealous
				add = -25
			}
			modifier = {
				has_trait = chaste
				add = -25
			}
			modifier = {
				has_trait = lazy
				add = 25
			}
		}
	}
	after = {
		clear_court_event_participation = yes
		scope:courtier = {
			clear_court_event_participation = yes
		}
		scope:court_chaplain = {
			clear_court_event_participation = yes
		}
	}
}

#########################
# The Joys of Wine		#
# by Claudia Baldassi	#
# 6060					#
#########################

# Your chaplain preaches against wine; your physician (and the court drunkard!) disagrees #
	
court.6060 = {
	type = court_event
	title = court.6060.t
	desc = {
		desc = court.6060.desc_opening
		triggered_desc = {
			trigger = {
				exists = scope:courtier_drunkard
			}
			desc = court.6060.desc_drunkard_courtier
		}
		desc = court.6060.desc_ending
	}
	theme = court

	court_scene = {
		button_position_character = scope:court_chaplain
		roles = {
			scope:court_chaplain = {
				group = event_group
				animation = disapproval
			}
			scope:courtier_drunkard = {
				group = event_group
				animation = rage
			}
			scope:court_physician = {
				group = event_group
				animation = anger
			}
		}
	}

	trigger = {
		is_adult = yes
		OR = {
			#AGOT Modified
			# religion = religion:christianity_religion
			# AND = {
			# 	religion = religion:islam_religion
			# 	culture = { has_cultural_pillar = heritage_iranian }
			# }
			religion = religion:faith_of_the_seven_religion
		}
		#AGOT Modified
		#employs_court_position = court_physician_court_position
		OR = {
			employs_court_position = court_physician_court_position
			employs_court_position = maester_court_position
		}
		#AGOT Disabled, Paradox bug? The tutor doesn't show up anywhere...
		# employs_court_position = court_tutor_court_position
		exists = cp:councillor_court_chaplain
		cp:councillor_court_chaplain = {
			has_court_event_flag = no
			NOT = { has_court_position = court_physician_court_position }
		}
		#AGOT Disabled, Paradox bug? The tutor doesn't show up anywhere...
		# court_position:court_tutor_court_position = { has_court_event_flag = no }
	}

	weight_multiplier = {
		base = 1

		# Court weightings.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_scholarly }
	}

	immediate = {
		cp:councillor_court_chaplain = {
			save_scope_as = court_chaplain
		}
		save_court_physician_as_effect = { SCOPE_NAME = court_physician }
		scope:court_physician = {
			court_event_character_flag_effect = yes
		}
		if = {
			limit = {
				any_courtier_or_guest = {
					has_trait = drunkard
					NOR = {
						this = scope:court_physician
						this = scope:court_chaplain
					}
				}
			}
			random_courtier_or_guest = {
				limit = {
					has_trait = drunkard
					NOR = {
						this = scope:court_physician
						this = scope:court_chaplain
					}
				}
				save_scope_as = courtier_drunkard
				court_event_character_flag_effect = yes
			}
		}
	}

	#Option A: side with the chaplain
	option = {
		name = court.6060.a
		scope:court_chaplain = {
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 30
			}
		}
		scope:court_physician = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -15
			}
		}
		if = {
			limit = {
				exists = scope:courtier_drunkard
			}
			scope:courtier_drunkard = {
				add_opinion = {
					target = root
					modifier = disappointed_opinion
					opinion = -30
				}
			}
		}
		add_character_modifier = {
			modifier = court_no_wine_modifier
			days = 3650
		}
		add_piety = medium_piety_gain
		stress_impact = {
			cynical = medium_stress_impact_gain
			gluttonous = major_stress_impact_gain
			lifestyle_reveler = major_stress_impact_gain
			drunkard = massive_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = cynical
				add = -25
			}
			modifier = {
				has_trait = gluttonous
				add = -50
			}
			modifier = {
				has_trait = lifestyle_reveler
				add = -75
			}
			modifier = {
				has_trait = drunkard
				add = -100
			}
		}
	}

	#Option B: side with the physician
	option = {
		name = court.6060.b
		scope:court_physician = {
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 30
			}
		}
		scope:court_chaplain = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -15
			}
		}
		if = {
			limit = {
				exists = scope:courtier_drunkard
			}
			scope:courtier_drunkard = {
				add_opinion = {
					target = root
					modifier = disappointed_opinion
					opinion = -15
				}
			}
		}
		add_character_modifier = {
			modifier = court_moderate_drinking_modifier
			days = 3650
		}
		add_prestige = medium_prestige_gain
		stress_impact = {
			zealous = medium_stress_impact_gain
			gluttonous = medium_stress_impact_gain
			lifestyle_reveler = medium_stress_impact_gain
			drunkard = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = zealous
				add = -25
			}
			modifier = {
				has_trait = gluttonous
				add = -25
			}
			modifier = {
				has_trait = lifestyle_reveler
				add = -25
			}
			modifier = {
				has_trait = drunkard
				add = -75
			}
			modifier = {
				has_trait = lifestyle_physician
				add = 75
			}
			modifier = {
				has_trait = temperate
				add = 75
			}
		}
	}

	#Option C: side with the drunkard
	option = {
		name = court.6060.c
		trigger = {
			exists = scope:courtier_drunkard
		}
		if = {
			limit = {
				can_be_drunkard = yes
			}
			random = {
				chance = 25
				add_trait = drunkard
			}
		}
		scope:courtier_drunkard = {
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 30
			}
		}
		if = {
			limit = {
			    NOT = { has_relation_friend = scope:courtier_drunkard }
			}
			progress_towards_friend_effect = {
				REASON = friend_took_side_in_dispute
			    CHARACTER = scope:courtier_drunkard
			    OPINION = 0
			}
		}
		scope:court_chaplain = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -30
			}
		}
		scope:court_physician = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -30
			}
		}
		stress_impact = {
			base = medium_stress_impact_loss
			zealous = medium_stress_impact_gain
			temperate = major_stress_impact_gain
			lifestyle_physician = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = drunkard
				add = 100
			}
			modifier = {
				has_trait = zealous
				add = -25
			}
			modifier = {
				has_trait = temperate
				add = -50
			}
			modifier = {
				has_trait = lifestyle_physician
				add = -50
			}
		}
	}

	#Option D: you are already a drunkard
	option = {
		name = court.6060.d
		trigger = {
			has_trait = drunkard
			NOT = {
				exists = scope:courtier_drunkard
			}
		}
		scope:court_chaplain = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -30
			}
		}
		scope:court_physician = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -30
			}
		}
		stress_impact = {
			base = medium_stress_impact_loss
			zealous = medium_stress_impact_gain
			temperate = major_stress_impact_gain
			lifestyle_physician = major_stress_impact_gain
		}
		ai_chance = {
			base = 200
			modifier = {
				has_trait = zealous
				add = -25
			}
			modifier = {
				has_trait = temperate
				add = -50
			}
			modifier = {
				has_trait = lifestyle_physician
				add = -50
			}
		}
	}

	#Option E: no drunkards, but might become one!
	option = {
		name = court.6060.d
		trigger = {
			NOR = {
				exists = scope:courtier_drunkard
				has_trait = drunkard
			}
		}
		random = {
			chance = 25
			add_trait = drunkard
		}
		scope:court_chaplain = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -30
			}
		}
		scope:court_physician = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -30
			}
		}
		stress_impact = {
			base = medium_stress_impact_loss
			zealous = medium_stress_impact_gain
			temperate = major_stress_impact_gain
			lifestyle_physician = major_stress_impact_gain
		}
		ai_chance = {
			base = 200
			modifier = {
				has_trait = zealous
				add = -25
			}
			modifier = {
				has_trait = temperate
				add = -50
			}
			modifier = {
				has_trait = lifestyle_physician
				add = -50
			}
		}
	}
	after = {
		if = {
			limit = {
				exists = scope:courtier_drunkard
			}
			scope:courtier_drunkard = {
				clear_court_event_participation = yes
			}
		}
		scope:court_chaplain = {
			clear_court_event_participation = yes
		}
		scope:court_physician = {
			clear_court_event_participation = yes
		}
	}
}

#############################
# The Value of Letters		#
# by Claudia Baldassi		#
# 6070-6072					#
#############################

# Your courtiers are dissatisfied with you being completely illiterate. How do you react? #
	
court.6070 = {
	type = court_event
	title = court.6070.t
	desc = court.6070.desc
	theme = court

	court_scene = {
		button_position_character = scope:tutor_6070
		roles = {
			scope:tutor_6070 = {
				group = event_group
				animation = personality_rational
			}
			root = {
				group = event_group
				triggered_animation = {
					trigger = {
						OR = {
							has_trait = arrogant
							has_trait = stubborn
						}
					}
					animation = personality_bold
				}
				triggered_animation = {
					trigger = {
						NOR = {
							has_trait = arrogant
							has_trait = stubborn
						}
					}
					animation = shame
				}
				animation = shame
			}
		}
	}

	trigger = {
		has_court_event_flag = no
		OR = {
			learning < low_skill_rating
			has_trait = intellect_bad
			has_trait = dull
		}
		NOT = {
			has_trait = blind
		}
		is_adult = yes
		OR = {
			exists = cp:councillor_court_chaplain
			AND = {
				employs_court_position = court_tutor_court_position
				any_court_position_holder = {
					type = court_tutor_court_position
					is_available_ai_adult = yes
					has_court_event_flag = no
				}
			}
		}
	}

	weight_multiplier = {
		base = 1

		# Court weightings.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_scholarly }
	}

	immediate = {
		court_event_character_flag_effect = yes
		if = {
			limit = {
				employs_court_position = court_tutor_court_position
				any_court_position_holder = {
					type = court_tutor_court_position
					is_available_ai_adult = yes
				}
			}
			random_court_position_holder = {
				type = court_tutor_court_position
				limit = { is_available_ai_adult = yes }
				save_scope_as = tutor_6070
				court_event_character_flag_effect = yes
			}
		}
		else = {
			cp:councillor_court_chaplain = {
				save_scope_as = tutor_6070
				court_event_character_flag_effect = yes
			}
		}
	}

	#Option A: Get your court chaplain/court tutor to teach you (or try to...)
	option = {
		name = court.6070.a
		random_list = {
			1 = {
				desc = court.6070.a.success
				modifier = {
					factor = 2
					scope:tutor_6070.learning > root.learning
				}
				modifier = {
					factor = 3
					has_trait = diligent
				}
				modifier = {
					factor = 3
					scope:tutor_6070 = { has_trait = scholar }
				}
				modifier = {
					factor = 2
					scope:tutor_6070 = {
						has_education_learning_trigger = yes
					}
				}
				modifier = {
					factor = 1.5
					has_trait = patient
				}
				modifier = {
					factor = 2
					has_trait = ambitious
				}
				modifier = {
					factor = 1.5
					has_trait = intellect_good_1
				}
				modifier = {
					factor = 2
					has_trait = intellect_good_2
				}
				modifier = {
					factor = 3
					has_trait = intellect_good_3
				}
				trigger_event = {
					id = court.6071
					days = 100
				}
				custom_tooltip = court.6070.a.tt.1
				show_as_tooltip = {
					add_stress = minor_stress_loss
					add_prestige = medium_prestige_gain
					add_learning_skill = 1
				}
			}
			1 = {
				desc = court.6070.a.failure
				modifier = {
					factor = 2
					scope:tutor_6070.learning <= root.learning
				}
				modifier = {
					factor = 4
					has_trait = lazy
				}
				modifier = {
					factor = 2
					has_trait = fickle
				}
				modifier = {
					factor = 2
					has_trait = impatient
				}
				modifier = {
					factor = 2
					has_trait = content
				}
				modifier = {
					factor = 4
					has_trait = irritable
				}
				modifier = {
					factor = 1.5
					has_trait = intellect_bad_1
				}
				modifier = {
					factor = 2
					has_trait = intellect_bad_2
				}
				modifier = {
					factor = 3
					has_trait = intellect_bad_3
				}
				modifier = {
					factor = 2
					has_trait = dull
				}
				trigger_event = {
					id = court.6072
					days = 100
				}
				custom_tooltip = court.6070.a.tt.2
				show_as_tooltip = {
					every_courtier_or_guest = {
						custom = court_6000_all_courtiers_and_guests
						add_opinion = {
							target = root
							modifier = disappointed_opinion
							opinion = -20
						}
					}
				}
			}
		}
		ai_chance = {
			base = 150
			modifier = {
				has_trait = diligent
				add = 25
			}
			modifier = {
				has_trait = lazy
				add = -50
			}
			modifier = {
				has_trait = content
				add = -25
			}
			modifier = {
				has_trait = ambitious
				add = 50
			}
		}
	}

	#Option B: Yes, and you are proud of it!
	option = {
		name = court.6070.b
		trigger = {
			OR = {
				has_trait = arrogant
				has_trait = stubborn
			}
		}
		every_courtier_or_guest = {
			limit = {
				learning >= low_skill_rating
			}
			custom = every_courtier_or_guest_6070_learning
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -20
			}
		}
		change_current_court_grandeur = medium_court_grandeur_loss
		stress_impact = {
			base = medium_stress_impact_loss
			diligent = medium_stress_impact_gain
			ambitious = major_stress_impact_gain
		}
		ai_chance = {
			base = 200
			modifier = {
				has_trait = ambitious
				add = -75
			}
			modifier = {
				has_trait = diligent
				add = -25
			}
		}
	}

	#Option D: I KNOW how to write, ok??
	option = {
		name = court.6070.d
		stress_impact = {
			honest = major_stress_gain
			deceitful = medium_stress_loss
		}
		custom_tooltip = court.6070.d.tt
		duel = {
			skill = intrigue
			value = average_skill_rating
			40 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3
				}
				custom_tooltip = court.6070.d.tt.success
				send_interface_toast = {
					title = court.6070.d.tt.success
					every_courtier_or_guest = {
						custom = court_6000_all_courtiers_and_guests
						add_opinion = {
							target = root
							modifier = respect_opinion
							opinion = 15
						}
					}
					add_intrigue_lifestyle_xp = medium_lifestyle_xp
				}
			}
			60 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3
				}
				custom_tooltip = court.6070.d.tt.failure
				send_interface_toast = {
					title = court.6070.d.tt.failure
					every_courtier_or_guest = {
						custom = court_6000_all_courtiers_and_guests
						add_opinion = {
							target = root
							modifier = disgusted_opinion
							opinion = -15
						}
					}
					change_current_court_grandeur = medium_court_grandeur_loss
				}
			}
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = deceitful
				add = 50
			}
			modifier = {
				has_lifestyle = intrigue_lifestyle
				add = 100
			}
		}
	}

	#Option C: pretend you don't notice
	option = {
		name = court.6070.c
		add_prestige = medium_prestige_loss
		stress_impact = {
			shy = medium_stress_impact_gain
			irritable = medium_stress_impact_gain
			wrathful = medium_stress_impact_gain
			ambitious = major_stress_impact_gain
			arrogant = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = lazy
				add = 50
			}
			modifier = {
				has_trait = content
				add = 50
			}
			modifier = {
				has_trait = shy
				add = -25
			}
			modifier = {
				has_trait = irritable
				add = -25
			}
			modifier = {
				has_trait = wrathful
				add = -25
			}
			modifier = {
				has_trait = ambitious
				add = -50
			}
			modifier = {
				has_trait = arrogant
				add = -50
			}
		}
	}
	after = {
		clear_court_event_participation = yes
		scope:tutor_6070 = {
			clear_court_event_participation = yes
		}
	}
}

court.6071 = {
	type = character_event
	title = court.6070.t
	desc = court.6071.desc
	theme = court
	left_portrait = {
		character = root
		animation = happiness
	}
	right_portrait = {
		character = scope:tutor_6070
		animation = happiness
	}

	immediate = {
		if = {
			limit = {
				scope:tutor_6070 = {
					OR = {
						is_alive = no
						NOT = {
							is_courtier_of = root
						}
					}
				}
			}
			if = {
				limit = {
			 		employs_court_position = court_tutor_court_position
			 		any_court_position_holder = {
			 			type = court_tutor_court_position
			 			is_available_ai_adult = yes
			 		}
				}
				random_court_position_holder = {
			 		type = court_tutor_court_position
			 		limit = { is_available_ai_adult = yes }
					save_scope_as = tutor_6070
				}
			}		
			else_if = {
				limit = {
					exists = cp:councillor_court_chaplain
				}
				cp:councillor_court_chaplain = {
					save_scope_as = tutor_6070
				}
			}
			else_if = {
				limit = {
					any_courtier_or_guest = {
						is_available_ai_adult = yes
						learning > low_skill_rating
					}
				}
				random_courtier_or_guest = {
					limit = {
						is_available_ai_adult = yes
						learning > low_skill_rating
					}
					save_scope_as = tutor_6070
				}
			}
			else = {
				create_character = {
					location = root.location
					template = scholar_character
					save_scope_as = tutor_6070			
				}
			}
		}	
		add_stress = minor_stress_loss
		add_prestige = medium_prestige_gain
		add_learning_skill = 1
	}

	#Option A: excellent
	option = {
		name = court.6071.a
		ai_chance = {
			base = 100
		}
	}
	#Option B: my tutor deserves compensation
	option = {
		name = court.6071.b
		pay_short_term_gold = {
			gold = minor_gold_value
			target = scope:tutor_6070
		}
		reverse_add_opinion = {
			target = scope:tutor_6070
			modifier = grateful_opinion
			opinion = 20
		}
		if = {
		    limit = {
		        NOT = { has_relation_friend = scope:tutor_6070 }
		    }
		    progress_towards_friend_effect = {
				REASON = friend_gave_gold
		        CHARACTER = scope:tutor_6070
		        OPINION = default_friend_opinion
		    }
		}
		stress_impact = {
			greedy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = -0.5
			}
		}
	}
}

court.6072 = {
	type = character_event
	title = court.6070.t
	desc = court.6072.desc
	theme = court
	left_portrait = {
		character = root
		animation = shame
	}
	right_portrait = {
		character = scope:tutor_6070
		animation = disapproval
	}

	immediate = {
		every_courtier_or_guest = {
			custom = court_6000_all_courtiers_and_guests
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -20
			}
		}
	}

	#Option A: too bad...
	option = {
		name = court.6072.a
		custom_tooltip = court.6072.a.tt
		add_prestige = medium_prestige_loss
		add_stress = minor_stress_loss
		ai_chance = {
			base = 100
		}
	}

	#Option B: you use a seal instead of signing
	option = {
		name = court.6072.b
		add_prestige = minor_prestige_loss
		add_character_modifier = {
			modifier = court_fancy_seal_modifier
			years = 20
		}
		custom_tooltip = court.6072.b.tt
		ai_chance = {
			base = 100
			modifier = {
				has_trait = ambitious
				add = 25
			}
			modifier = {
				has_trait = deceitful
				add = 25
			}
		}
	}

	#Option C: my tutor is useless!
	option = {
		name = court.6072.c
		add_prestige = minor_prestige_gain
		reverse_add_opinion = {
			target = scope:tutor_6070
			modifier = insult_opinion
			opinion = -30
		}
		if = {
			limit = {
			    NOT = { has_relation_rival = scope:tutor_6070 }
			}
			progress_towards_rival_effect = {
			    CHARACTER = scope:tutor_6070
			    REASON = rival_tutor_blamed
			    OPINION = default_rival_opinion
			}
		}
		if = {
			limit = {
				scope:tutor_6070 = {
					has_court_position = court_tutor_court_position
				}
			}
			revoke_court_position = {
				target = scope:tutor_6070
				court_position = court_tutor_court_position
			}
		}
		stress_impact = {
			diligent = medium_stress_impact_gain
			honest = major_stress_impact_gain
			compassionate = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = deceitful
				add = 25
			}
			modifier = {
				has_trait = wrathful
				add = 25
			}
			modifier = {
				has_trait = diligent
				add = -25
			}
			modifier = {
				has_trait = honest
				add = -50
			}
			modifier = {
				has_trait = compassionate
				add = -50
			}
		}
	}
}

#########################
# The Munificence of X  #
# 6080					#
# Claudia Baldassi		#
#########################

# A visiting king, or foreign prince is spending a lot of money in your court and is making you look bad (Mansa Musa's pilgrimage) - do you attempt to match the visitor's generosity or profit from it? #

scripted_trigger court_6080_valid_visitor_trigger = {
	is_available_healthy_ai_adult = yes
	OR = {
		has_trait = generous
		has_trait = improvident
		has_trait = profligate
	}
	NOR = {
		has_trait = greedy
		this = root
	}
	gold >= 100
}

court.6080 = {
	type = court_event
	title = court.6080.t
	desc = {
		desc = court.6080.desc
		triggered_desc = {
			trigger = {
				exists = scope:beneficiary_2
			}
			desc = court.6080.desc_2
		}
		triggered_desc = {
			trigger = {
				exists = scope:beneficiary_child
			}
			desc = court.6080.desc_3
		}
		desc = court.6080.desc_end
	}
	theme = court

	court_scene = {
		button_position_character = scope:6080_visitor
		roles = {
			scope:6080_visitor = {
				group = event_group
				animation = personality_compassionate
			}
			scope:beneficiary_1 = {
				group = event_group
				animation = admiration
			}
			scope:beneficiary_2 = {
				group = event_group
				animation = admiration
			}
		}
	}

	trigger = {
		any_neighboring_top_liege_realm_owner = {
			OR = {
				court_6080_valid_visitor_trigger = yes
				any_child = {
					court_6080_valid_visitor_trigger = yes
					has_court_event_flag = no
				}
				any_vassal = {
					court_6080_valid_visitor_trigger = yes
					has_court_event_flag = no
				}				
			}
		}
		any_courtier_or_guest = {
			is_available_ai_adult = yes
			has_court_event_flag = no
		}
	}

	immediate = {
		random_neighboring_top_liege_realm_owner = {
			limit = {
				OR = {
					court_6080_valid_visitor_trigger = yes
					any_child = { court_6080_valid_visitor_trigger = yes }
					any_vassal = { court_6080_valid_visitor_trigger = yes }
				}
			}
			if = {
				limit = { court_6080_valid_visitor_trigger = yes }
				save_scope_as = 6080_visitor
				court_event_character_flag_effect = yes
			}
			else_if = {
				limit = {
					any_child = { court_6080_valid_visitor_trigger = yes }
				}
				random_child = {
					limit = { court_6080_valid_visitor_trigger = yes }
					save_scope_as = 6080_visitor
					court_event_character_flag_effect = yes
				}
			}
			else = {
				random_vassal = {
					limit = { court_6080_valid_visitor_trigger = yes }
					save_scope_as = 6080_visitor
					court_event_character_flag_effect = yes
				}
			}
		}
		random_courtier_or_guest = {
			limit = {
				is_available_ai_adult = yes
			}
			save_scope_as = beneficiary_1
			court_event_character_flag_effect = yes
		}
		if = {
			limit = {
				any_courtier_or_guest = {
					is_available_ai_adult = yes
					NOT = { this = scope:beneficiary_1 }
				}
			}
			random_courtier_or_guest = {
				limit = {
					is_available_ai_adult = yes
					NOT = { this = scope:beneficiary_1 }
				}
				save_scope_as = beneficiary_2
				court_event_character_flag_effect = yes
			}
		}
		if = {
			limit = {
				any_courtier_or_guest = {
					is_available_ai_child = yes
					age >= 3
				}
			}
			random_courtier_or_guest = {
				limit = { is_available_ai_child = yes }
				save_scope_as = beneficiary_child
			}
		}
		scope:6080_visitor = {
			pay_short_term_gold = {
				target = scope:beneficiary_1
				gold = tiny_gold_value
			}
		}
		if = {
			limit = {
				exists = scope:beneficiary_2
			}
			scope:6080_visitor = {
				pay_short_term_gold = {
					target = scope:beneficiary_2
					gold = tiny_gold_value
				}
			}
		}
	}

	#Option A: I can be even more generous!
	option = {
		name = court.6080.a
		pay_short_term_gold = {
			target = scope:beneficiary_1
			gold = minor_gold_value
		}
		reverse_add_opinion = {
			target = scope:beneficiary_1
			modifier = grateful_opinion
			opinion = 30
		}
		if = {
			limit = {
				exists = scope:beneficiary_2
			}
			pay_short_term_gold = {
				target = scope:beneficiary_2
				gold = minor_gold_value
			}
			reverse_add_opinion = {
				target = scope:beneficiary_2
				modifier = grateful_opinion
				opinion = 30
			}
		}
		if = {
			limit = {
				exists = scope:beneficiary_child
			}
			reverse_add_opinion = {
				target = scope:beneficiary_child
				modifier = grateful_opinion
				opinion = 30
			}
		}
		change_current_court_grandeur = medium_court_grandeur_gain
		stress_impact = {
			content = medium_stress_impact_gain
			humble = major_stress_impact_gain
			greedy = massive_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = -1
			}
			modifier = {
				gold < medium_gold_value
				factor = 0
			}
			modifier = {
				has_trait = ambitious
				add = 25
			}
			modifier = {
				has_trait = humble
				add = -25
			}
			modifier = {
				has_trait = content
				add = -25
			}
		}
	}

	#Option B: shamelessly ask for money too
	option = {
		name = court.6080.b
		duel = {
			target = scope:6080_visitor
			skill = intrigue
			50 = {
				desc = court.6080.b.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3
				}
				send_interface_toast = {
					title = court.6080.b.success.tt
					scope:6080_visitor = {
						pay_short_term_gold = {
							target = root
							gold = medium_gold_value
						}
					}
				}
			}
			50 = {
				desc = court.6080.b.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3
				}
				send_interface_toast = {
					title = court.6080.b.failure.tt
					scope:6080_visitor = {
						add_opinion = {
							target = root
							modifier = disappointed_opinion
							opinion = -30
						}
					}
				}
			}
		}
		stress_impact = {
			honest = medium_stress_impact_gain
			generous = major_stress_impact_gain
			improvident = massive_stress_impact_gain
			profligate = massive_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 1
				ai_honor = -0.5
			}
		}
	}

	#Option C: "gently" invite them to leave
	option = {
		name = court.6080.c
		add_prestige = medium_prestige_gain
		reverse_add_opinion = {
			target = scope:6080_visitor
			modifier = insulted_opinion
			opinion = -40
		}
		stress_impact = {
			humble = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = arrogant
				add = 50
			}
			modifier = {
				has_trait = humble
				add = -50
			}
		}
	}

	#Option D: Better him spending than me
	option = {
		name = court.6080.d
		change_current_court_grandeur = miniscule_court_grandeur_gain
		stress_impact = {
			greedy = minor_stress_impact_loss
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = greedy
				add = 10
			}
			modifier = {
				has_trait = content
				add = 25
			}
		}
	}
	after = { 
		scope:6080_visitor = {
			clear_court_event_participation = yes
		}
		scope:beneficiary_1 = {
			clear_court_event_participation = yes
		}
		if = {
			limit = {
				exists = scope:beneficiary_2
			}
			scope:beneficiary_2 = {
				clear_court_event_participation = yes
			}
		}
	}
}

#########################
# The Art of Rhetoric 	#
# 6090					#
# Claudia Baldassi		#
#########################

# Your Court Poet is giving a lecture to your children on the finer arts of rhetoric and they aren't having any of it #

court.6090 = {
	type = court_event
	title = court.6090.t
	desc = {
		desc = court.6090.desc
		triggered_desc = {
			trigger = {
				exists = scope:6090_child_c
			}
			desc = court.6090.desc_other
		}
		desc = court.6090.desc_end
	}
	theme = court

	court_scene = {
		button_position_character = scope:6090_poet
		roles = {
			scope:6090_poet = {
				group = event_group
				animation = beg
			}
			scope:6090_child_a = {
				group = event_group
				animation = dismissal
			}
			scope:6090_child_b = {
				group = event_group
				animation = dismissal
			}
		}
	}

	trigger = {
		employs_court_position = court_poet_court_position
		any_court_position_holder = {
			type = court_poet_court_position
			is_available_ai_adult = yes
			has_court_event_flag = no
		}
		any_child = {
			count >= 2
			is_available_ai_child = yes
			has_court_event_flag = no
			age >= 8
		}
	}

	immediate = {
		random_court_position_holder = {
			type = court_poet_court_position
			limit = { is_available_ai_adult = yes }
			save_scope_as = 6090_poet
			court_event_character_flag_effect = yes
		}
		every_child = {
			limit = {
				is_available_ai_child = yes
				age >= 8
			}
			add_to_list = rhetoric_children
		}
		ordered_in_list = {
			list = rhetoric_children
			order_by = age
			max = 3
			check_range_bounds = no
			if = {
				limit = {
					NOT = { exists = scope:6090_child_a }
				}
				save_scope_as = 6090_child_a
				court_event_character_flag_effect = yes
			}
			else_if = {
				limit = {
					NOT = { exists = scope:6090_child_b }
				}
				save_scope_as = 6090_child_b
				court_event_character_flag_effect = yes
			}
			else = {
				save_scope_as = 6090_child_c
			}
		}
	}

	#Option A: Reprimand them
	option = {
		name = court.6090.a
		scope:6090_poet = {
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 30
			}
		}
		scope:6090_child_a = {
			add_opinion = {
				target = root
				modifier = annoyed_opinion
				opinion = -10
			}
			random = {
				chance = 20
				add_diplomacy_skill = 1
			}
		}
		scope:6090_child_b = {
			add_opinion = {
				target = root
				modifier = annoyed_opinion
				opinion = -10
			}
			random = {
				chance = 20
				add_diplomacy_skill = 1
			}
		}
		if = {
			limit = {
				exists = scope:6090_child_c
			}
			scope:6090_child_c = {
				add_opinion = {
					target = root
					modifier = annoyed_opinion
					opinion = -10
				}
				random = {
					chance = 20
					add_diplomacy_skill = 1
				}
			}
		}
		stress_impact = {
			lazy = medium_stress_impact_gain
			arrogant = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = diligent
				add = 100
			}
			modifier = {
				has_trait = lazy
				add = -50
			}
			modifier = {
				has_trait = arrogant
				add = -50
			}
		}
	}

	#Option B: Teach them yourself
	option = {
		name = court.6090.b
		duel = {
			skill = diplomacy
			value = average_skill_rating
			50 = {
				desc = court.6090.b.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3
				}
				send_interface_toast = {
					title = court.6090.b.success
					random = {
						chance = 30
						add_diplomacy_skill = 1
					}
					scope:6090_child_a = {
						add_opinion = {
							target = root
							modifier = impressed_opinion
							opinion = 10
						}
						random = {
							chance = 30
							add_diplomacy_skill = 1
						}
					}
					scope:6090_child_b = {
						add_opinion = {
							target = root
							modifier = impressed_opinion
							opinion = 10
						}
						random = {
							chance = 30
							add_diplomacy_skill = 1
						}
					}
					if = {
						limit = {
							exists = scope:6090_child_c
						}
						scope:6090_child_c = {
							add_opinion = {
								target = root
								modifier = impressed_opinion
								opinion = 10
							}
							random = {
								chance = 30
								add_diplomacy_skill = 1
							}
						}
					}
				}
			}
			50 = {
				desc = court.6090.b.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3
				}
				send_interface_toast = {
					title = court.6090.b.failure.tt
					scope:6090_child_a = {
						add_opinion = {
							target = root
							modifier = bored_opinion
							opinion = -20
						}
					}
					scope:6090_child_b = {
						add_opinion = {
							target = root
							modifier = bored_opinion
							opinion = -20
						}
					}
					if = {
						limit = {
							exists = scope:6090_child_c
						}
						scope:6090_child_c = {
							add_opinion = {
								target = root
								modifier = bored_opinion
								opinion = -20
							}
						}
					}
				}
			}
		}
		stress_impact = {
			humble = medium_stress_impact_gain
			shy = major_stress_impact_gain
			lazy = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = humble
				add = -50
			}
			modifier = {
				has_trait = shy
				add = -75
			}
			modifier = {
				has_trait = arrogant
				add = 50
			}
			modifier = {
				has_trait = gregarious
				add = 50
			}
			modifier = {
				has_trait = lazy
				add = -75
			}
			modifier = {
				diplomacy < 6
				add = -100
			}
		}
	}

	#Option C: Side with them - court poet is booooring
	option = {
		name = court.6090.c
		scope:6090_poet = {
			add_opinion = {
				target = root
				modifier = insulted_opinion
				opinion = -30
			}
		}
		scope:6090_child_a = {
			add_opinion = {
				target = root
				modifier = amused_opinion
				opinion = 10
			}
		}
		scope:6090_child_b = {
			add_opinion = {
				target = root
				modifier = amused_opinion
				opinion = 10
			}
		}
		if = {
			limit = {
				exists = scope:6090_child_c
			}
			scope:6090_child_c = {
				add_opinion = {
					target = root
					modifier = amused_opinion
					opinion = 10
				}
			}
		}
		stress_impact = {
			ambitious = medium_stress_impact_gain
			diligent = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = ambitious
				add = -25
			}
			modifier = {
				has_trait = diligent
				add = -75
			}
			modifier = {
				has_trait = lazy
				add = 25
			}
			modifier = {
				has_trait = callous
				add = 25
			}
		}
	}
	after = {
		scope:6090_poet = {
			clear_court_event_participation = yes
		}
		scope:6090_child_a = {
			clear_court_event_participation = yes
		}
		scope:6090_child_b = {
			clear_court_event_participation = yes
		}
	}	
}











##################################################
# George

##################################################
# 7300			Where's the Lamb Sauce?
# 7400			Overstaying their Welcome
# 7600			Wild at Heart
# 7610			Child asks for a destrier
# 7620			Master of the Hunt and Falconer in negotations over a falcon
# 7630			Hunt master and Horse master argue about a kill
# 7649			Courtier has harmed their bird
# 7700			Chief Eunuch trains a pigeon to steal things
##################################################

#########################
# Where's the Lamb Sauce?
# by George Luff
# 7300
#########################

scripted_trigger court_7300_court_food_taster_trigger = {
	has_court_position = food_taster_court_position
	is_available_healthy_ai_adult = yes
}

## Food Taster QUITS
court.7300 = {
	type = court_event
	title = court.7300.title
	desc = court.7300.desc
	theme = court
	
	court_scene = {
		button_position_character = scope:taster
		roles = {
			scope:taster = {
				group = event_group
				#AGOT MODIFIED
				#animation = disgusted
				animation = disgust
			}
			root = {
				group = event_group
				animation = worry
			}
		}
	}

	cooldown = { years = 5 }

	weight_multiplier = {
		base = 1

		# Court weightings.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_intrigue }
	}

	trigger = {
		has_court_event_flag = no
		# Employs a food taster
		any_court_position_holder = {
			court_7300_court_food_taster_trigger = yes
			has_court_event_flag = no
		}
		# The level of food amenities are crap
		amenity_level = {
			type = court_food_quality
			value <= medium_amenity_level
		}
		NOT = {
			government_has_flag = government_is_tribal
		}
	}

	immediate = {
		court_event_character_flag_effect = yes
		# Save Food Taster
		random_court_position_holder = {
			limit = {
				court_7300_court_food_taster_trigger = yes
			}
			save_scope_as = taster
			court_event_character_flag_effect = yes
		}
	}

	# Persuade them to stay by investing in more food, minor plot defence buff
	option = {
		name = court.7300.a

		stress_impact = {
			gluttonous = medium_stress_impact_loss
			greedy = major_stress_impact_gain
			generous = medium_stress_impact_loss
		}

		set_amenity_level = { type = court_food_quality value = 3 }
		scope:taster = {
			add_opinion = {
				modifier = grateful_opinion
				target = root
				opinion = 10
			}
		}
		add_character_modifier = {
			modifier = incentivized_food_taster
			years = 5
		}
		ai_chance = {
			base = 40
			ai_value_modifier = {
				ai_rationality = 5
				ai_honor = 2
				ai_compassion = 5
				ai_greed = -10
			}
		}
	}

	# Refuse to accept their resignation, if a plot exists they will join it.
	option = {
		name = court.7300.b

		stress_impact = {
			compassionate = medium_stress_impact_gain
			stubborn = medium_stress_impact_loss
			callous = medium_stress_impact_loss
		}

		scope:taster = {
			add_opinion = {
				modifier = disgusted_opinion
				target = root
				opinion = -15
			}
		}
		hidden_effect = {
			if = {
				limit = {
					any_targeting_scheme = {
						scheme_type = murder
						save_temporary_scope_as = scheme_check
					}
					scope:taster = {
						is_valid_as_agent_in_scheme = scope:scheme_check
					}
				}
				random_targeting_scheme = {
					limit = {
						scheme_type = murder
					}
					save_scope_as = scheme
					scope:taster = {
						force_add_to_scheme = {
							scheme = scope:scheme
							years = 5
						}
					}
				}
			}
		}
		ai_chance = {
			base = 20
			ai_value_modifier = {
				ai_honor = -1
				ai_greed = 2
			}
		}
	}

	# Fine, I relieve of this burden
	option = {
		name = court.7300.c

		stress_impact = {
			impatient = medium_stress_impact_loss
			lazy = medium_stress_impact_loss
			paranoid = major_stress_impact_gain
		}

		revoke_court_position = {
			court_position = food_taster_court_position
			recipient = scope:taster
		}
		scope:taster = {
			add_opinion = {
				modifier = relieved_opinion
				target = root
				opinion = 50
			}
		}
		ai_chance = {
			base = 20
			ai_value_modifier = {
				ai_greed = 2
				ai_vengefulness = 2
			}
		}
	}
	after = {
		clear_court_event_participation = yes
		scope:taster = {
			clear_court_event_participation = yes
		}
	}
}

#########################
# Overstaying their Welcome
# by George Luff
# 7400
#########################

scripted_trigger court_7400_courtier_trigger = {
	is_available_healthy_ai_adult = yes
	is_landed = no
	is_hostage = no
	NOR = {
		is_close_or_extended_family_of = prev
		is_spouse_of = prev
		is_councillor = yes
		is_knight = yes
		has_relation_lover = prev
		has_relation_soulmate = prev
	}
	any_claim = {
		tier < root.highest_held_title_tier
	}
}

court.7400 = {
	type = court_event
	title = court.7400.title
	desc = court.7400.desc
	theme = court
	
	court_scene = {
		button_position_character = scope:guest
		roles = {
			scope:guest = {
				group = event_group
				animation = ecstasy
			}
			root = {
				group = event_group
				animation = anger
			}
		}
	}

	cooldown = { years = 10 }

	weight_multiplier = {
		base = 1

		# Court weightings.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_diplomatic }
	}

	trigger = {
		has_court_event_flag = no
		# Has high lodgings and food amenities
		amenity_level = {
			type = court_lodging_standards
			value >= 4
		}

		amenity_level = {
			type = court_food_quality
			value >= 4
		}

		# Has a neighbouring realm with available character
		any_neighboring_top_liege_realm_owner = {
			any_courtier = {
				court_7400_courtier_trigger = yes
				has_court_event_flag = no
			}
		}
	}

	immediate = {
		court_event_character_flag_effect = yes
		# Identify courtier from foreign court and move them to this court
		random_neighboring_top_liege_realm_owner = {
			limit = {
				any_courtier = {
					court_7400_courtier_trigger = yes
				}
			}
			save_scope_as = guest_liege
			random_courtier = {
				limit = {
					court_7400_courtier_trigger = yes
				}
				save_scope_as = guest
				court_event_character_flag_effect = yes
			}
		}
		add_visiting_courtier = scope:guest
	}

	# Allow them to stay and deal with the amenities cost increase
	option = {
		name = court.7400.a
		custom_tooltip = court.7400.a.tt

		stress_impact = {
			greedy = medium_stress_impact_gain
			gluttonous = medium_stress_impact_gain
			temperate = medium_stress_impact_loss
			calm = minor_stress_impact_loss
		}

		add_character_modifier = {
			modifier = expensive_guests
			years = 5
		}

		scope:guest = {
			add_opinion = {
				modifier = grateful_opinion
				target = root
				opinion = 30
			}
		}

		ai_chance = {
			base = 90
			ai_value_modifier = {
				ai_honor = 5
				ai_compassion = 5
				ai_vengefulness = -5
				ai_rationality = 1
			}
		}
	}

	# If a menial court position is empty, employ them instead.
	option = {
		name = court.7400.b
		custom_tooltip = court.7400.b.tt

		stress_impact = {
			ambitious = minor_stress_impact_loss
			diligent = minor_stress_impact_loss
			wrathful = medium_stress_impact_gain
		}

		trigger = {
			OR = {
				AND = {
					NOT = { employs_court_position = court_jester_court_position }
					can_employ_court_position_type = court_jester_court_position
				}
				AND = {
					NOT = { employs_court_position = food_taster_court_position }
					can_employ_court_position_type = food_taster_court_position
				}
			}
		}

		if = {
			limit = {
				can_appoint_char_to_court_position = {
					CHAR = scope:guest
					COURT_POS = court_jester_court_position
				}
			}
			scope:guest = {
				set_employer = ROOT
			}
			appoint_court_position = {
				recipient = scope:guest
				court_position = court_jester_court_position
			}
		}
		else_if = {
			limit = {
				can_appoint_char_to_court_position = {
					CHAR = scope:guest
					COURT_POS = food_taster_court_position
				}
			}
			scope:guest = {
				set_employer = ROOT
			}
			appoint_court_position = {
				recipient = scope:guest
				court_position = food_taster_court_position
			}
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 50
			}
		}
	}

	# Kick them out and lose a bit of CGV
	option = {
		name = court.7400.c

		stress_impact = {
			arbitrary = medium_stress_impact_loss
			callous = minor_stress_impact_loss
			generous = medium_stress_impact_gain
		}

		add_character_modifier = {
			modifier = inhospitable_court
			years = 5
		}
		scope:guest = {
			add_opinion = {
				modifier = kicked_out_opinion
				target = root
				opinion = -15
			}
			return_to_court = yes
		}
		scope:guest.top_liege = {
			add_opinion = {
				modifier = angry_opinion
				target = root
				opinion = -5
			}
		}

		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = 5
				ai_vengefulness = 5
				ai_honor = -2
				ai_rationality = 5
			}
		}
	}
	after = {
		clear_court_event_participation = yes
		scope:guest = {
			clear_court_event_participation = yes
		}
	}
}

#########################
# Wild at Heart
# by George Luff
# 7600
#########################

scripted_trigger active_child_trigger = {
	age > 7
	age < 14
	is_landed = no
	host = root
	is_healthy = yes
}

court.7600 = {
	type = court_event
	title = court.7600.title
	desc = court.7600.desc
	theme = court

	court_scene = {
		button_position_character = scope:child
		roles = {
			scope:child = {
				group = event_group
				animation = ecstasy
			}
			scope:huntmaster = {
				group = event_group
				animation = happiness
			}
		}
	}

	cooldown = { years = 5 }

	weight_multiplier = {
		base = 1

		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_warlike }
	}

	trigger = {
		any_child = {
			active_child_trigger = yes
			has_court_event_flag = no
			NOT = { has_character_flag = child_goes_hunting }
		}
		employs_court_position = master_of_hunt_court_position
		any_court_position_holder = {
			type = master_of_hunt_court_position
			is_available_healthy_ai_adult = yes
			has_court_event_flag = no
		}
		NOT = {
			culture = { has_cultural_tradition = tradition_vegetarianism }
		}
	}

	immediate = {
		random_child = {
			limit = {
				active_child_trigger = yes
				NOT = { has_character_flag = child_goes_hunting }
			}
			save_scope_as = child
			court_event_character_flag_effect = yes
			add_character_flag = child_goes_hunting
			select_local_animal_effect = { TYPE = any } # Save scope to limit possible animals: any/big/small/dangerous/harmless/prowling
		}
		random_court_position_holder = {
			type = master_of_hunt_court_position
			limit = {
				is_available_healthy_ai_adult = yes
			}
			save_scope_as = huntmaster
			court_event_character_flag_effect = yes
		}
	}

	# Ban the outings
	option = {
		name = court.7600.a

		stress_impact = {
			lifestyle_hunter = major_stress_impact_gain
			craven = medium_stress_impact_loss
		}

		scope:huntmaster = {
			add_opinion = {
				modifier = disappointed_opinion
				target = root
				opinion = -10
			}
		}

		scope:child = {
			add_opinion = {
				modifier = hate_opinion
				target = root
				opinion = -30
			}

		}

		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_zeal = 0.5
				ai_honor = 0.5
				ai_boldness = 0.5
				ai_compassion = 2
			}
		}
	}

	# Test the child, huntmaster!
	option = {
		name = court.7600.b
		custom_tooltip = court.7600.b.tt

		stress_impact = {
			compassionate = medium_stress_impact_gain
			lifestyle_hunter = medium_stress_impact_loss
		}

		scope:huntmaster = {
			add_opinion = {
				modifier = impressed_opinion
				target = root
				opinion = 10
			}
		}

		scope:child = {
			add_prowess_skill = 1
			add_opinion = {
				modifier = scared_opinion
				target = root
				opinion = -5
			}

			duel = {
				skill = prowess
				value = 6

				50 = {
					desc = court.7600.b.victory
					compare_modifier = {
						value = scope:duel_value
						multiplier = 0.5
					}
					send_interface_toast = {
						title = court.7600.b.victory
						left_icon = scope:huntmaster
						right_icon = scope:child
						add_prowess_skill = 1
					}
				}
				40 = {
					desc = court.7600.b.wounding
					compare_modifier = {
						value = scope:duel_value
						multiplier = -0.5
					}
					send_interface_toast = {
						title = court.7600.b.wounding
						left_icon = scope:huntmaster
						right_icon = scope:child
						increase_wounds_no_death_effect = { REASON = hunting_accident }
					}
				}
				10 = {
					desc = court.7600.b.death
					compare_modifier = {
						value = scope:duel_value
						multiplier = -0.25
					}
					send_interface_toast = {
						title = court.7600.b.death
						left_icon = scope:huntmaster
						right_icon = scope:child
						death = { death_reason = death_hunting_accident }
					}
					
				}
			}
		}

		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_honor = 1
				ai_vengefulness = 1
				ai_boldness = 1.2
				ai_rationality = 0.5
				ai_compassion = 0.1
			}
		}
	}

	# Approve the outings
	option = {
		name = court.7600.c

		stress_impact = {
			lifestyle_hunter = medium_stress_impact_loss
		}

		scope:huntmaster = {
			add_opinion = {
				modifier = respect_opinion
				target = root
				opinion = 15
			}
		}

		scope:child = {
			add_prowess_skill = 1
			add_opinion = {
				modifier = love_opinion
				target = root
				opinion = 30
			}
		}

		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_zeal = 1
				ai_honor = 2
				ai_boldness = 1
				ai_rationality = 1
				ai_compassion = 0.5
			}
		}
	}
	after = {
		scope:huntmaster = {
			clear_court_event_participation = yes
		}
		scope:child = {
			clear_court_event_participation = yes
		}
	}
}

#########################
# Child asks for a destrier
# by George Luff
# 7610
#########################

court.7610 = {
	type = court_event
	title = court.7610.title
	desc = court.7610.desc
	theme = court

	court_scene = {
		button_position_character = scope:child
		roles = {
			scope:child = {
				group = event_group
				animation = beg
			}
			scope:horsemaster = {
				group = event_group
				animation = scheme
			}
		}
	}

	cooldown = { years = 10 }

	weight_multiplier = {
		base = 1

		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_warlike }
	}

	trigger = {
		any_child = {
			active_child_trigger = yes
			has_court_event_flag = no
		}
		employs_court_position = master_of_horse_court_position
		any_court_position_holder = {
			type = master_of_horse_court_position
			is_available_healthy_ai_adult = yes
			has_court_event_flag = no
		}
	}

	immediate = {
		random_child = {
			limit = {
				active_child_trigger = yes
			}
			save_scope_as = child
			court_event_character_flag_effect = yes
		}
		random_court_position_holder = {
			type = master_of_horse_court_position
			limit = {
				is_available_healthy_ai_adult = yes
			}
			save_scope_as = horsemaster
			court_event_character_flag_effect = yes
		}
	}

	# Approve the request
	option = {
		name = court.7610.a

		pay_short_term_gold = {
			target = scope:horsemaster
			gold = medium_gold_value
		}

		scope:horsemaster = {
			add_opinion = {
				modifier = pleased_opinion
				target = root
				opinion = 15
			}
		}

		scope:child = {
			add_character_modifier = {
				modifier = struggling_with_destrier
				years = 10
			}
			add_opinion = {
				modifier = love_opinion
				target = root
				opinion = 25
			}
		}

		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_zeal = 1.5
				ai_honor = 1.5
				ai_rationality = 0.9
				ai_greed = 0.1
			}
		}
	}

	# Get the child something more appropriate
	option = {
		name = court.7610.b

		pay_short_term_gold = {
			target = scope:horsemaster
			gold = minor_gold_value
		}

		scope:horsemaster = {
			add_opinion = {
				modifier = disappointed_opinion
				target = root
				opinion = -5
			}
		}

		scope:child = {
			add_character_modifier = {
				modifier = practicing_with_palfrey
				years = 10
			}
			add_opinion = {
				modifier = disappointed_opinion
				target = root
				opinion = -5
			}
		}

		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_zeal = 0.9
				ai_honor = 1
				ai_rationality = 2
				ai_greed = 1.5
			}
		}
	}

	# Reject the request
	option = {
		name = court.7610.c

		scope:horsemaster = {
			add_opinion = {
				modifier = disappointed_opinion
				target = root
				opinion = -15
			}
		}

		scope:child = {
			add_opinion = {
				modifier = hurt_opinion
				target = root
				opinion = -20
			}
		}

		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_zeal = 0.5
				ai_honor = 0.5
				ai_rationality = 1
				ai_greed = 2
				ai_compassion = 0.5
			}
		}
	}
	after = {
		scope:child = {
			clear_court_event_participation = yes
		}
		scope:horsemaster = {
			clear_court_event_participation = yes
		}
	}
}

#########################
# Master of the Hunt and Falconer in negotations over a falcon
# by George Luff
# 7620
#########################

scripted_trigger court_7620_pool_character_trigger = {
	is_physically_able_adult = yes
	age <= 50
}

court.7620 = {
	type = court_event
	title = court.7620.title
	desc = court.7620.desc
	theme = court


	court_scene = {
		button_position_character = scope:falconer
		roles = {
			scope:falconer = {
				group = event_group
				animation = scheme
			}
			scope:huntmaster = {
				group = event_group
				animation = anger
			}
		}
	}

	cooldown = { years = 5 }

	weight_multiplier = {
		base = 1

		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_warlike }
	}

	trigger = {
		employs_court_position = master_of_hunt_court_position
		any_court_position_holder = {
			type = master_of_hunt_court_position
			is_available_healthy_ai_adult = yes
			has_court_event_flag = no
		}
		# Check pool characters
		OR = {
			any_pool_character = {
				province = root.capital_province
				court_7620_pool_character_trigger = yes
				has_court_event_flag = no
			}
			any_courtier_or_guest = {
				ep1_spare_courtier_trigger = yes
				has_court_event_flag = no
			}
		}
	}

	immediate = {
		root = {
			set_variable = {
				name = falcon_price
				value = medium_gold_value
			}
		}
		random_court_position_holder = {
			type = master_of_hunt_court_position
			limit = {
				is_available_healthy_ai_adult = yes
			}
			save_scope_as = huntmaster
			court_event_character_flag_effect = yes
			hidden_effect = {
				add_gold = root.var:falcon_price
			}
		}
		# Select pool character
		if = {
			limit = {
				any_pool_character = {
					province = root.capital_province
					court_7620_pool_character_trigger = yes
				}
			}
			random_pool_character = {
				province = root.capital_province
				limit = {
					court_7620_pool_character_trigger = yes
				}
				save_scope_as = falconer
				court_event_character_flag_effect = yes
			}
		}
		else = {
			random_courtier_or_guest = {
				limit = {
					ep1_spare_courtier_trigger = yes
				}
				save_scope_as = falconer
				court_event_character_flag_effect = yes
			}
		}
	}

	# Help with the negotiation
	option = {
		name = court.7620.a

		stress_impact = {
			compassionate = minor_stress_impact_gain
		}

		duel = {
			skill = stewardship
			target = scope:falconer
			50 = {
				desc = court.7620.a.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 0.5
				}
				scope:huntmaster = {
					add_opinion = {
						modifier = helped_negotiation_opinion
						target = root
						opinion = 35
					}
					pay_short_term_gold = {
						target = scope:falconer
						gold = root.var:falcon_price
					}
					add_character_modifier = {
						modifier = peregrine_falcon
						years = 5
					}
				}
				send_interface_toast = {
					title = court.7620.a.success
					add_stewardship_lifestyle_xp = medium_lifestyle_xp
					scope:falconer = {
						add_opinion = {
							modifier = pleased_opinion
							target = root
							opinion = 15
						}
					}
				}
			}

			50 = {
				desc = court.7620.a.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -0.5
				}
				scope:huntmaster = {
					add_opinion = {
						modifier = grateful_opinion
						target = root
						opinion = 10
					}
					hidden_effect = { # Cleanup
						pay_short_term_gold = {
							target = scope:falconer
							gold = root.var:falcon_price
						}
					}
				}
				send_interface_toast = {
					title = court.7620.a.failure
					scope:falconer = {
						add_opinion = {
							modifier = disappointed_opinion
							target = root
							opinion = -5
						}
					}
				}
			}
		}

		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_greed = 0.5
				ai_honor = 1.5
				ai_boldness = 1
				ai_compassion = 1
			}
			modifier = {
				add = 20
				has_perk = diplomat_perk
			}
		}
	}

	# Beat the huntmaster's price!
	option = {
		name = court.7620.b

		stress_impact = {
			greedy = major_stress_impact_gain
			ambitious = minor_stress_impact_loss
			lifestyle_hunter = minor_stress_impact_loss
			fickle = minor_stress_impact_loss
		}

		pay_short_term_gold = {
			target = scope:falconer
			gold = {
				value = root.var:falcon_price
				add = minor_gold_value
			}
		}

		add_character_modifier = {
			modifier = peregrine_falcon
			years = 5
		}

		scope:falconer = {
			add_opinion = {
				modifier = pleased_opinion
				target = root
				opinion = 25
			}
		}

		scope:huntmaster = {
			add_opinion = {
				modifier = outbid_opinion
				target = root
				opinion = -15
			}
			hidden_effect = { # Cleanup
				pay_short_term_gold = {
					target = scope:falconer
					gold = root.var:falcon_price
				}
			}
		}

		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_honor = 0.5
				ai_greed = 0.25
				ai_boldness = 1
				ai_rationality = 1
			}
			modifier = {
				add = 5
				has_trait = lifestyle_hunter
			}
			modifier = {
				add = 10
				hunt_lifestyle_track_greater_equal_trigger = { TRACK = hunter GREATER_EQUAL = 50 }
			}
			modifier = {
				add = 10
				hunt_lifestyle_track_greater_equal_trigger = { TRACK = hunter GREATER_EQUAL = 100 }
			}
		}
	}

	# Don't get involved
	option = {
		name = court.7620.c

		stress_impact = {
			arbitrary = medium_stress_impact_loss
			lifestyle_hunter = minor_stress_impact_gain
		}

		scope:falconer = {
			add_opinion = {
				modifier = disappointed_opinion
				target = scope:huntmaster
				opinion = -15
			}
		}

		scope:huntmaster = {
			add_opinion = {
				modifier = disappointed_opinion
				target = scope:falconer
				opinion = -15
			}
			hidden_effect = { # Cleanup
				remove_short_term_gold = {
					value = root.var:falcon_price
				}
			}
		}

		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_honor = 0.1
				ai_boldness = 0.1
				ai_greed = 2
				ai_compassion = 0.1
			}
			modifier = {
				add = 10
				has_trait = arbitrary
			}
		}
	}
	after = {
		scope:falconer = {
			clear_court_event_participation = yes
		}
		scope:huntmaster = {
			clear_court_event_participation = yes
		}
	}
}

#########################
# Hunt master and Horse master argue about a kill
# by George Luff
# 7630
#########################

court.7630 = {
	type = court_event
	title = court.7630.title
	desc = court.7630.desc
	theme = court

	court_scene = {
	 	button_position_character = scope:huntmaster
	 	roles = {
	 		scope:huntmaster = {
	 			group = event_group
	 			animation = rage
	 		}
	 		scope:horsemaster = {
	 			group = event_group
	 			animation = anger
	 		}
	 	}
	}

	cooldown = { years = 5 }

	trigger = {
		employs_court_position = master_of_hunt_court_position
		any_court_position_holder = {
			type = master_of_hunt_court_position
			is_available_healthy_ai_adult = yes
			has_court_event_flag = no
			save_temporary_scope_as = court_position_check
		}
		employs_court_position = master_of_horse_court_position
		any_court_position_holder = {
			type = master_of_horse_court_position
			is_available_healthy_ai_adult = yes
			has_court_event_flag = no
			NOT = { this = scope:court_position_check }
		}
	}

	immediate = {
		random_court_position_holder = {
			type = master_of_hunt_court_position
			limit = {
				is_available_healthy_ai_adult = yes
			}
			save_scope_as = huntmaster
			court_event_character_flag_effect = yes
		}
		random_court_position_holder = {
			type = master_of_horse_court_position
			limit = {
				is_available_healthy_ai_adult = yes
				NOT = { this = scope:huntmaster }
			}
			save_scope_as = horsemaster
			court_event_character_flag_effect = yes
		}
	}

	# It was horsemaster
	option = {
		name = court.7630.a

		scope:horsemaster = {
			progress_towards_friend_effect = {
				REASON = friend_took_side_in_dispute
				CHARACTER = root
				OPINION = default_friend_opinion
			}
		}

		scope:huntmaster = {
			add_opinion = {
				modifier = angry_opinion
				target = root
				opinion = -25
			}
			progress_towards_rival_effect = {
				CHARACTER = scope:horsemaster
				REASON = rival_hunt_dispute
				OPINION = default_rival_opinion
			}
		}

		# Better Cavalry
		add_character_modifier = {
			modifier = master_of_horse_cavalry_bonus
			years = 5
		}

		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_honor = 1
				ai_rationality = 1
			}
		}
	}

	# It was huntmaster
	option = {
		name = court.7630.b

		scope:horsemaster = {
			add_opinion = {
				modifier = angry_opinion
				target = root
				opinion = -25
			}
			progress_towards_rival_effect = {
				CHARACTER = scope:huntmaster
				REASON = rival_hunt_dispute
				OPINION = default_rival_opinion
			}
		}

		scope:huntmaster = {
			progress_towards_friend_effect = {
				REASON = friend_took_side_in_dispute
				CHARACTER = root
				OPINION = default_friend_opinion
			}
		}

		# Cheaper Hunts
		add_character_modifier = {
			modifier = master_of_hunt_activity_bonus
			years = 5
		}

		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_honor = 1
				ai_rationality = 1
			}
		}
	}

	# You both get credit ok?
	option = {
		name = court.7630.c
		custom_tooltip = court.7630.c.tt

		duel = {
			skill = diplomacy
			value = medium_skill_rating
			60 = {
				desc = court.7630.c.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 0.5
				}
				add_diplomacy_lifestyle_xp = medium_lifestyle_xp
				send_interface_toast = {
					title = court.7630.c.success
					left_icon = scope:horsemaster
					right_icon = scope:huntmaster
					scope:horsemaster = {
						set_relation_friend = { reason = friend_shared_hunt_credit target = scope:huntmaster }
					}
				}
				scope:horsemaster = {
					add_opinion = {
						modifier = respect_opinion
						target = root
						opinion = 20
					}
				}
				scope:huntmaster = {
					add_opinion = {
						modifier = respect_opinion
						target = root
						opinion = 20
					}
				}
			}
			40 = {
				desc = court.7630.c.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -0.5
				}
				send_interface_toast = {
					title = court.7630.c.failure
					left_icon = root
					right_icon = scope:horsemaster
					scope:horsemaster = {
						add_opinion = {
							modifier = insulted_opinion
							target = root
							opinion = -10
						}
						set_relation_rival = {
							target = scope:huntmaster
							reason = rival_hunting_rivalry
						}
					}
					scope:huntmaster = {
						add_opinion = {
							modifier = insulted_opinion
							target = root
							opinion = -10
						}
					}
				}
			}
		}

		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_honor = 2
				ai_rationality = 1
				ai_compassion = 1
			}
		}
	}

	after = {
		scope:huntmaster = {
			clear_court_event_participation = yes
		}
		scope:horsemaster = {
			clear_court_event_participation = yes
		}
	}
}

#########################
# Courtier has harmed their bird
# by George Luff
# 7640
#########################

court.7640 = {
	type = court_event
	title = court.7640.title
	desc = court.7640.desc
	theme = court

	court_scene = {
		button_position_character = scope:huntmaster
		roles = {
			scope:huntmaster = {
				group = event_group
				animation = worry
			}
			scope:avian_abuser = {
				group = event_group
				animation = fear
			}
		}
	}

	cooldown = { years = 5 }

	weight_multiplier = {
		base = 1

		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_warlike}
	}

	trigger = {
		employs_court_position = master_of_hunt_court_position
		any_court_position_holder = {
			type = master_of_hunt_court_position
			is_available_healthy_ai_adult = yes
			has_court_event_flag = no
		}
		# Check random courtier
		any_courtier_or_guest = {
			is_available_healthy_ai_adult = yes
			is_councillor = no
			has_court_event_flag = no
			NOT = {
				has_court_position = master_of_hunt_court_position
			}
		}
	}

	immediate = {
		random_court_position_holder = {
			type = master_of_hunt_court_position
			limit = {
				is_available_healthy_ai_adult = yes
			}
			save_scope_as = huntmaster
			court_event_character_flag_effect = yes
		}
		# Select random courtier
		random_courtier_or_guest = {
			limit = {
				is_available_healthy_ai_adult = yes
				is_councillor = no
				NOT = { this = scope:huntmaster }
			}
			save_scope_as = avian_abuser
			court_event_character_flag_effect = yes
		}
		scope:huntmaster = {
			add_opinion = {
				modifier = villain_opinion
				target = scope:avian_abuser
				opinion = -40
			}
		}

		set_variable = {
			name = fine_gold
			value = minor_gold_value
		}
	}

	# Let them go I guess?
	option = {
		name = court.7640.a

		stress_impact = {
			arbitrary = major_stress_impact_loss
			just = major_stress_impact_gain
		}

		scope:huntmaster = {
			add_opinion = {
				modifier = villain_opinion
				target = root
				opinion = -40
			}
		}

		if = {
			limit = {
				can_add_hook = {
					target = scope:avian_abuser
					type = favor_hook
				}
			}
			add_hook = {
				target = scope:avian_abuser
				type = favor_hook
			}
		}

		scope:avian_abuser = {
			progress_towards_friend_effect = {
				REASON = friend_showed_mercy
				CHARACTER = root
				OPINION = 0
			}
			add_opinion = {
				modifier = relieved_opinion
				target = root
				opinion = 60
			}
		}

		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_boldness = 0.1
				ai_vengefulness = 0.1
				ai_honor = 0.1
				ai_rationality = 0.5
				ai_compassion = 0.75
			}
			modifier = {
				add = -10
				has_trait = just
			}
			modifier = {
				add = 10
				has_trait = arbitrary
			}
		}
	}

	# Imprison the wrongdoer!
	option = {
		name = court.7640.b

		stress_impact = {
			just = medium_stress_impact_loss
		}

		imprison = {
			target = scope:avian_abuser
			type = dungeon
		}

		add_prestige = minor_prestige_gain

		scope:huntmaster = {
			add_opinion = {
				modifier = just_opinion
				target = root
				opinion = 25
			}
		}

		scope:avian_abuser = {
			add_opinion = {
				modifier = angry_opinion
				target = root
				opinion = -25
			}
		}

		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_boldness = 1
				ai_honor = 1
				ai_rationality = 1
				ai_compassion = 1
			}
			modifier = {
				add = 10
				has_trait = just
			}
			modifier = {
				add = -10
				has_trait = arbitrary
			}
		}
	}

	# Fine the wrongdoer!
	option = {
		name = court.7640.c

		stress_impact = {
			just = medium_stress_impact_loss
		}

		scope:huntmaster = {
			add_opinion = {
				modifier = just_opinion
				target = root
				opinion = 15
			}
		}

		scope:avian_abuser = {
			add_opinion = {
				modifier = angry_opinion
				target = root
				opinion = -15
			}
			pay_short_term_gold = {
				target = root
				gold = root.var:fine_gold
			}
		}

		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_boldness = 0.5
				ai_honor = 0.5
				ai_compassion = 1
				ai_rationality = 1
				ai_greed = 2.0
			}
			modifier = {
				add = 10
				has_trait = just
			}
			modifier = {
				add = -10
				has_trait = arbitrary
			}
		}
	}

	# Torture the wrongdoer!
	option = {
		name = court.7640.d

		stress_impact = {
			just = medium_stress_impact_loss
		}

		add_dread = minor_dread_gain

		scope:huntmaster = {
			add_opinion = {
				modifier = just_opinion
				target = root
				opinion = 25
			}
		}

		scope:avian_abuser = {
			add_opinion = {
				modifier = tortured_me
				target = root
			}
			add_character_modifier = {
				modifier = recently_tortured
				years = 5
			}
			if = {
				limit = {
					NOR = {
						has_trait = craven
						has_trait = brave
					}
				}
				add_stress = massive_stress_impact_gain
			}
			else = {
				stress_impact = {
					craven = monumental_stress_gain
					brave = medium_stress_impact_gain
				}
			}
		}

		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_boldness = 1
				ai_vengefulness = 2.0
				ai_honor = 0.5
				ai_rationality = 0.5
				ai_compassion = 0.1
			}
			modifier = {
				add = 10
				has_trait = just
			}
			modifier = {
				add = -10
				has_trait = arbitrary
			}
			modifier = {
				add = 20
				has_trait = sadistic
			}
			modifier = {
				add = 20
				has_trait = torturer
			}
		}
	}
	after = {
		scope:huntmaster = {
			clear_court_event_participation = yes
		}
		scope:avian_abuser = {
			clear_court_event_participation = yes
		}
	}
}

#########################
# Chief Eunuch trains a pigeon to steal things
# by George Luff
# 7700
#########################

scripted_trigger pigeon_assistance_scheme_trigger = {
	OR = {
		scheme_type = fabricate_hook
		scheme_type = abduct
		scheme_type = sway
		scheme_type = murder
		scheme_type = convert_to_witchcraft
	}
}

court.7700 = {
	type = court_event
	title = court.7700.title
	desc = court.7700.desc
	theme = court
	court_scene = {
		button_position_character = scope:eunuch
		roles = {
			scope:eunuch = {
				group = event_group
				animation = scheme
			}
		}
	}

	weight_multiplier = {
		base = 1

		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_intrigue }
	}

	trigger = {
		employs_court_position = chief_eunuch_court_position
		any_court_position_holder = {
			type = chief_eunuch_court_position
			is_available_healthy_ai_adult = yes
			has_court_event_flag = no
			# There is a secret to be known
			any_courtier_or_guest = {
				any_secret = {
					NOT = { is_known_by = root}
				}
			}
		}
	}

	immediate = {
		random_court_position_holder = {
			type = chief_eunuch_court_position
			limit = {
				is_available_healthy_ai_adult = yes
			}
			save_scope_as = eunuch
			court_event_character_flag_effect = yes
		}
		random_courtier_or_guest = {
			limit = {
				any_secret = {
					NOT = { is_known_by = root }
				}
			}
			save_scope_as = courtier
			random_secret = {
				limit = {
					NOT = { is_known_by = root }
				}
				save_scope_as = secret
			}
		}

		# For option d
		if = {
			limit = {
				any_scheme = {
					pigeon_assistance_scheme_trigger = yes
				}
			}
			random_scheme = {
				limit = {
					pigeon_assistance_scheme_trigger = yes
				}
				save_scope_as = scheme
			}
		}
	}

	# 'Out' the eunuch for their dishonourable practices
	option = {
		name = court.7700.a

		# Strip the court eunuch of their position
		if = {
			limit = {
				exists = scope:eunuch
			}
			revoke_court_position = {
				recipient = scope:eunuch
				court_position = chief_eunuch_court_position
			}
		}

		# Imprison them
		imprison = {
			target = scope:eunuch
			type = house_arrest
		}

		scope:eunuch = {
			progress_towards_rival_effect = {
				CHARACTER = root
				REASON = rival_thief_accused
				OPINION = default_rival_opinion
			}
		}

		add_character_modifier = {
			modifier = honorable_ruler
			years = 5
		}

		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_boldness = 0.1
				ai_vengefulness = 0.1
				ai_honor = 2
				ai_rationality = 0.5
				ai_greed = 0.5
			}
		}
	}

	# Just this once, ok?
	option = {
		name = court.7700.b

		# Has a valid active scheme in progress
		trigger = {
			any_scheme = {
				pigeon_assistance_scheme_trigger = yes
			}
		}

		scope:scheme = {
			add_scheme_progress = 20
		}

		# You've told them you need help, they are in on it now!
		scope:eunuch = {
			if = {
				limit = {
					scope:scheme = {
						NOT = { scheme_is_character_agent = prev }
					}
					is_valid_as_agent_in_scheme = scope:scheme
				}
				force_add_to_scheme = {
					scheme = scope:scheme
					years = 5
				}
			}
		}

		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_boldness = 1
				ai_honor = 0.5
				ai_rationality = 1
				ai_greed = 2
				ai_compassion = 0.5
			}
		}
	}

	# Secretly back this skulduggery
	option = {
		name = court.7700.c

		scope:eunuch = {
			add_character_modifier = {
				modifier = pigeon_thief
				years = 5
			}
		}

		add_character_modifier = {
			modifier = profiting_from_pigeon_thievery
			years = 5
		}

		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_boldness = 1.5
				ai_honor = 0.1
				ai_compassion = 0.1
				ai_rationality = 1
				ai_greed = 1.5
			}
		}
	}

	# Turn the eunuch away
	option = {
		name = court.7700.d

		scope:eunuch = {
			add_character_modifier = {
				modifier = pigeon_thief
				years = 5
			}
			add_opinion = {
				modifier = disappointed_opinion
				target = root
				opinion = -15
			}
		}

		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_boldness = 0.5
				ai_vengefulness = 0.2
				ai_honor = 1.5
				ai_rationality = 0.75
				ai_greed = 0.5
			}
		}
	}
	after = {
		scope:eunuch = {
			clear_court_event_participation = yes
		}
	}
}










##################################################
# Joe Parkin

# 8001 - Trampled Underfoot
# 8010 - Underequipped
# 8020 - Sartorial Sting
# 8030 - Pawful of Pooches
# 8040 - Aristocratic Pretensions
# 8050 - A Little Bird
# 8060 - Scornful Sycophants
# 8070 - Feeling Useful
# 8080 - Maternal Reproach
# 8090 - Building Blocks
# 8100 - Questionable Concoction
# 8110 - Upon the Block
# 8120 - Novel Perspectives
# 8130 - Contrived Conflicts
# 8140 - Royal Lapse
# 8150 - Prandial Excess
# 8160 - Foremost Knight
# 8170 - Black Sheep
# 8180 - Secrets and Lies

#########################
# Trampled Underfoot	#
# by Joe Parkin 		#
#########################

scripted_trigger court_8001_child_trigger = {
	is_available = yes
	is_healthy = yes
	age > 3
	age < 12
	NOT = { has_variable = court_8001_child_flag }
}

court.8001 = {
	type = court_event
	title = court.8001.t
	desc = {
		desc = court.8001.desc.intro
		random_valid = {
			triggered_desc = {
		        trigger = {
		        	scope:child_1 = {
		        		OR = {
		        			has_trait = curious
		        			has_focus = education_diplomacy
		        		}
		        	}
		        }
		        desc = court.8001.desc.diplomacy
		    }
		    triggered_desc = {
		        trigger = {
		        	scope:child_1 = {
		        		OR = {
		        			has_trait = rowdy
		        			has_focus = education_martial
		        		}
		        	}
		        }
		        desc = court.8001.desc.martial
		    }
		    triggered_desc = {
		        trigger = {
		        	scope:child_1 = {
		        		OR = {
		        			has_trait = bossy
		        			has_focus = education_stewardship
		        		}
		        	}
		        }
		        desc = court.8001.desc.stewardship
		    }
		    triggered_desc = {
		        trigger = {
		        	scope:child_1 = {
		        		OR = {
		        			has_trait = charming
		        			has_focus = education_intrigue
		        		}
		        	}
		        }
		        desc = court.8001.desc.intrigue
		    }
		    triggered_desc = {
		        trigger = {
		        	scope:child_1 = {
		        		OR = {
		        			has_trait = pensive
		        			has_focus = education_learning
		        		}
		        	}
		        }
		        desc = court.8001.desc.learning
		    }
		    desc = court.8001.desc.fallback
		}
	}
	theme = court
	cooldown = { years = 10 }
	court_scene = {
		button_position_character = scope:gardener
		roles = {
			scope:gardener = {
				group = event_group
				animation = rage
			}
			scope:child_1 = {
				group = event_group
				animation = shame
			}
		}
	}
	
	trigger = {
		employs_court_position = court_gardener_court_position
		any_court_position_holder = {
			type = court_gardener_court_position
			is_available_healthy_ai_adult = yes
			has_court_event_flag = no
		}
		any_courtier_or_guest = {
			count >= 1
			court_8001_child_trigger = yes
			has_court_event_flag = no
		}
	}

	weight_multiplier = {
		base = 1
		# Court weightings.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_administrative }
	}

	immediate = {
		random_court_position_holder = {
			type = court_gardener_court_position
			limit = { is_available_healthy_ai_adult = yes }
			save_scope_as = gardener
			court_event_character_flag_effect = yes
		}
		random_courtier_or_guest = {
			limit = { court_8001_child_trigger = yes }
			save_scope_as = child_1
			court_event_character_flag_effect = yes
			set_variable = {
				name = court_8001_child_flag
				days = 3650
			}
		}
	}

	option = { # Encourage the child's interests
		name = {
			trigger = {
				scope:child_1 = { has_focus = education_diplomacy }
			}
			text = court.8001.a.diplomacy
		}
		name = {
			trigger = {
				scope:child_1 = { has_focus = education_martial }
			}
			text = court.8001.a.martial
		}
		name = {
			trigger = {
				scope:child_1 = { has_focus = education_stewardship }
			}
			text = court.8001.a.stewardship
		}
		name = {
			trigger = {
				scope:child_1 = { has_focus = education_intrigue }
			}
			text = court.8001.a.intrigue
		}
		name = {
			trigger = {
				scope:child_1 = { has_focus = education_learning }
			}
			text = court.8001.a.learning
		}
		trigger = {
			scope:child_1 = {
				OR = {
					AND = {
						OR = {
							has_trait = curious
        					has_focus = education_diplomacy
	        			}
	        			ROOT.diplomacy >= medium_skill_rating
					}
					AND = {
						OR = {
							has_trait = rowdy
		        			has_focus = education_martial
			        	}
	        			ROOT.martial >= medium_skill_rating
					}
					AND = {
						OR = {
							has_trait = bossy
		        			has_focus = education_stewardship
	        			}
	        			ROOT.stewardship >= medium_skill_rating
					}
					AND = {
						OR = {
							has_trait = charming
		        			has_focus = education_intrigue
	        			}
	        			ROOT.intrigue >= medium_skill_rating
					}
					AND = {
						OR = {
							has_trait = pensive
        					has_focus = education_learning
	        			}
	        			ROOT.learning >= medium_skill_rating
					}
				}
			}
		}
		scope:child_1 = {
			if = {
				limit = {
					OR = {
						has_trait = curious
	        			has_focus = education_diplomacy
		        	}
		        	ROOT.diplomacy >= medium_skill_rating
				}
				random = {
					chance = 50
					ROOT = {
						send_interface_toast = {
							left_icon = scope:child_1
							title = court.8001.a.lesson_tt
							scope:child_1 = { add_diplomacy_skill = 1 }
						}
					}
				}
			}
			else_if = {
				limit = {
					OR = {
						has_trait = rowdy
		        		has_focus = education_martial
		        	}
		        	ROOT.martial >= medium_skill_rating
				}
				random = {
					chance = 50
					ROOT = {
						send_interface_toast = {
							left_icon = scope:child_1
							title = court.8001.a.lesson_tt
							scope:child_1 = { add_martial_skill = 1 }
						}
					}
				}
			}
			else_if = {
				limit = {
					OR = {
						has_trait = bossy
	        			has_focus = education_stewardship
		        	}
		        	ROOT.stewardship >= medium_skill_rating
				}
				random = {
					chance = 50
					ROOT = {
						send_interface_toast = {
							left_icon = scope:child_1
							title = court.8001.a.lesson_tt
							scope:child_1 = { add_stewardship_skill = 1 }
						}
					}
				}
			}
			else_if = {
				limit = {
					OR = {
						has_trait = charming
	        			has_focus = education_intrigue
		        	}
					ROOT.intrigue >= medium_skill_rating
				}
				random = {
					chance = 50
					ROOT = {
						send_interface_toast = {
							left_icon = scope:child_1
							title = court.8001.a.lesson_tt
							scope:child_1 = { add_intrigue_skill = 1 }
						}
					}
				}
			}
			else = {
				random = {
					chance = 50
					ROOT = {
						send_interface_toast = {
							left_icon = scope:child_1
							title = court.8001.a.lesson_tt
							scope:child_1 = { add_learning_skill = 1 }
						}
					}
				}
			}
		}
		scope:gardener = {
			add_opinion = {
				target = ROOT
				modifier = respect_opinion
				opinion = 5
			}
		}
		stress_impact = {
			lazy = medium_stress_impact_gain
			callous = medium_stress_impact_gain
			base = miniscule_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 2
				ai_energy = 1
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = lazy
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = callous
			}
		}
	}

	option = { # Lament the lost flowers
		name = {
			trigger = {
				scope:child_1 = { has_trait = poet }
			}
			text = court.8001.b.poet
		}
		name = {
			trigger = {
				scope:child_1 = {
					OR = {
						has_trait = lifestyle_gardener
						has_trait = lifestyle_herbalist
		    		}
	    		}
			}
			text = court.8001.b.gardener
		}
		trigger = {
			OR = {
				has_trait = lifestyle_gardener
				has_trait = lifestyle_herbalist
				has_trait = poet
			}
		}
		change_current_court_grandeur = minor_court_grandeur_gain
		scope:gardener = {
			add_opinion = {
				target = ROOT
				modifier = respect_opinion
				opinion = 20
			}
		}
		scope:child_1 = {
			add_opinion = {
				target = ROOT
				modifier = annoyed_opinion
				opinion = -10
			}
		}
		stress_impact = {
			compassionate = medium_stress_impact_gain
			forgiving = medium_stress_impact_gain
			lifestyle_gardener = minor_stress_impact_loss
			lifestyle_herbalist = minor_stress_impact_loss
			poet = minor_stress_impact_loss
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 1
				ai_compassion = -1
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = compassionate
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = forgiving
			}
			modifier = {	#Weight up.
				add = 30
				has_trait = lifestyle_gardener
			}
			modifier = {	#Weight up.
				add = 30
				has_trait = lifestyle_herbalist
			}
			modifier = {	#Weight up.
				add = 30
				has_trait = poet
			}
		}
	}

	option = { # Replant them
		name = court.8001.c
		remove_short_term_gold = medium_gold_value
		scope:gardener = {
			add_opinion = {
				target = ROOT
				modifier = respect_opinion
				opinion = 10
			}
		}
		scope:child_1 = {
			random_list = {
				2 = {
					trigger = {
						NOT = { has_trait = lifestyle_gardener }
					}
					modifier = {
						factor = 1.5
		        		OR = {
		        			has_trait = bossy
		        			has_focus = education_stewardship
		        		}
					}
					modifier = {
						factor = 1.5
		        		OR = {
		        			has_trait = pensive
		        			has_focus = education_learning
		        		}
					}
					ROOT = {
						send_interface_toast = {
							left_icon = scope:child_1
							title = court.8001.c.gardener_tt
							scope:child_1 = { add_trait = lifestyle_gardener }
						}
					}
				}
				2 = {
					trigger = {
						NOT = { has_trait = lifestyle_herbalist }
					}
					modifier = {
						factor = 1.5
		        		OR = {
		        			has_trait = bossy
		        			has_focus = education_stewardship
		        		}
					}
					modifier = {
						factor = 1.5
		        		OR = {
		        			has_trait = pensive
		        			has_focus = education_learning
		        		}
					}
					ROOT = {
						send_interface_toast = {
							left_icon = scope:child_1
							title = court.8001.c.gardener_tt
							scope:child_1 = { add_trait = lifestyle_herbalist }
						}
					}
				}
				2 = {
					modifier = {
						factor = 1.5
		        		OR = {
		        			has_trait = bossy
		        			has_focus = education_stewardship
		        		}
					}
					modifier = {
						factor = 1.5
		        		OR = {
		        			has_trait = pensive
		        			has_focus = education_learning
		        		}
					}
					ROOT = {
						send_interface_toast = {
							left_icon = scope:child_1
							title = court.8001.c.gardener_tt
							scope:child_1 = { add_stewardship_skill = 1 }
						}
					}
				}
				8 = {
					add_opinion = {
						target = ROOT
						modifier = annoyed_opinion
						opinion = -10
					}
				}
			}
		}
		stress_impact = {
			vengeful = medium_stress_impact_gain
			greedy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = -1
				ai_greed = -1
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = vengeful
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = greedy
			}
		}
	}

	option = { # Fire the gardener
		name = court.8001.d
		add_prestige = minor_prestige_gain
		add_dread = miniscule_dread_gain
		scope:gardener = {
			add_opinion = {
				target = ROOT
				modifier = angry_opinion
				opinion = -20
			}
		}
		revoke_court_position = {
			court_position = court_gardener_court_position
			recipient = scope:gardener
		}
		scope:child_1 = {
			add_opinion = {
				target = ROOT
				modifier = pleased_opinion
				opinion = 20
			}
		}
		stress_impact = {
			forgiving = medium_stress_impact_gain
			patient = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 1
				ai_vengefulness = 1
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = forgiving
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = patient
			}
		}
	}

	option = { # Dismiss the gardener
		name = court.8001.e
		scope:gardener = {
			add_opinion = {
				target = ROOT
				modifier = annoyed_opinion
				opinion = -10
			}
		}
		scope:child_1 = {
			add_opinion = {
				target = ROOT
				modifier = pleased_opinion
				opinion = 10
			}
		}
		stress_impact = {
			vengeful = medium_stress_impact_gain
			arbitrary = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 1
				ai_boldness = 1
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = vengeful
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = arbitrary
			}
		}
	}
	after = {
		scope:gardener = {
			clear_court_event_participation = yes
		}
		scope:child_1 = {
			clear_court_event_participation = yes
		}

	}
}

#########################
# Underequipped			#
# by Joe Parkin 		#
#########################

scripted_trigger court_8010_underequipped_trigger = {
	is_available_healthy_ai_adult = yes
	OR = {
		NOT = {
			any_character_artifact = { artifact_slot_type = primary_armament }
		}
		any_character_artifact = {
			count = all
			artifact_slot_type = primary_armament
			OR = {
				var:quality < 25
				ep1_artifact_durability_lower_equal_percent_trigger = { PERCENT = 0.24 } # could be replaced by checking LOW_DURATION
			}
		}
	}
}

court.8010 = {
    type = court_event
    title = court.8010.t
    desc = {
    	desc = court.8010.desc.intro
    	random_valid = {
    	    triggered_desc = {
    	        trigger = {
    				scope:underequipped = { has_court_position = bodyguard_court_position }
    	        }
    	        desc = court.8010.desc.bodyguard
    	    }
    	    triggered_desc = {
    	        trigger = {
    				scope:underequipped = { has_court_position = champion_court_position }
    	        }
    	        desc = court.8010.desc.champion
    	    }
    	}
    	first_valid = {
    	    triggered_desc = {
    	        trigger = {
    				scope:underequipped = {
    					OR = {
    						has_trait = brave
    						has_trait = wrathful
    						has_trait = arrogant
    						has_trait = impatient
    						has_trait = ambitious
    					}
    				}
    	        }
    	        desc = court.8010.desc.bold
    	    }
    	    desc = court.8010.desc.meek
    	}
    	desc = court.8010.desc.body
    	random_valid = {
    	    triggered_desc = {
    	        trigger = {
    				scope:underequipped = { has_court_position = bodyguard_court_position }
    	        }
    	        desc = court.8010.desc.bodyguard_end
    	    }
    	    triggered_desc = {
    	        trigger = {
    				scope:underequipped = { has_court_position = champion_court_position }
    	        }
    	        desc = court.8010.desc.champion_end
    	    }
    	}
    }
    theme = court
    cooldown = { years = 10 }
    court_scene = {
        button_position_character = scope:underequipped
        roles = {
            scope:underequipped = {
                group = event_group
                animation = sadness
            }
            root = {
                group = event_group
                animation = idle
            }
        }
    }

    trigger = {
    	has_court_event_flag = no
    	OR = {
    		employs_court_position = bodyguard_court_position
    		employs_court_position = champion_court_position
    	}
        OR = {
        	any_court_position_holder = {
				type = bodyguard_court_position
				court_8010_underequipped_trigger = yes
				has_court_event_flag = no
			}
			any_court_position_holder = {
				type = champion_court_position
				court_8010_underequipped_trigger = yes
				has_court_event_flag = no
			}
        }
    }

    weight_multiplier = {
		base = 1
		# Court weightings.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_warlike }
	}

    immediate = {
    	court_event_character_flag_effect = yes
        hidden_effect = {
        	random_list = {
        		2 = {
        			trigger = {
        				any_court_position_holder = {
							type = bodyguard_court_position
							court_8010_underequipped_trigger = yes
						}
        			}
		        	random_court_position_holder = {
						type = bodyguard_court_position
						limit = { court_8010_underequipped_trigger = yes }
						save_scope_as = underequipped
						court_event_character_flag_effect = yes
					}
				}
				2 = {
					trigger = {
        				any_court_position_holder = {
							type = champion_court_position
							court_8010_underequipped_trigger = yes
						}
        			}
					random_court_position_holder = {
						type = champion_court_position
						limit = { court_8010_underequipped_trigger = yes }
						save_scope_as = underequipped
						court_event_character_flag_effect = yes
					}
		        }
        	}
        }
        random_dummy_gender_effect = yes #To feed to the weapon effect since we don't have a creator
		scope:underequipped = { set_signature_weapon_effect = yes } #To create an artifact of the "signature weapon" type
		if = {
			limit = {
	        	any_character_artifact = {
	        		count > 1
	        		artifact_slot_type = primary_armament
	        	}
	        }
	        ordered_character_artifact = {
	        	limit = {
	        		is_equipped = no
	        		artifact_slot_type = primary_armament
					#AGOT Added
	        		agot_valid_ai_gift = yes
	        	}
	        	order_by = {
	        		value = 0
	        		subtract = var:quality
	        	}
	        	save_scope_as = my_weapon
	        }
		}
    }

    option = { # Have a sword made
        name = court.8010.a
        change_current_court_grandeur = minor_court_grandeur_gain
        remove_short_term_gold = medium_gold_value#
        custom_tooltip = court.8010.a.tt
        hidden_effect = {
        	scope:underequipped = {
	        	if = {
					limit = { var:signature_weapon = flag:axe }
					create_artifact_weapon_effect = {
						OWNER = scope:underequipped
						CREATOR = scope:dummy_gender
						SET_WEAPON_TYPE = flag:artifact_weapon_type_axe
					}
				}
				else_if = {
					limit = { var:signature_weapon = flag:hammer }
					create_artifact_weapon_effect = {
						OWNER = scope:underequipped
						CREATOR = scope:dummy_gender
						SET_WEAPON_TYPE = flag:artifact_weapon_type_hammer
					}
				}
				else_if = {
					limit = { var:signature_weapon = flag:spear }
					create_artifact_weapon_effect = {
						OWNER = scope:underequipped
						CREATOR = scope:dummy_gender
						SET_WEAPON_TYPE = flag:artifact_weapon_type_spear
					}
				}
				else_if = {
					limit = { var:signature_weapon = flag:mace }
					create_artifact_weapon_effect = {
						OWNER = scope:underequipped
						CREATOR = scope:dummy_gender
						SET_WEAPON_TYPE = flag:artifact_weapon_type_mace
					}
				}
				else = { #For swords, but also as fallback - no daggers here
					create_artifact_weapon_effect = {
						OWNER = scope:underequipped
						CREATOR = scope:dummy_gender
						SET_WEAPON_TYPE = flag:artifact_weapon_type_sword
					}
				}
			}
	        if = {
	        	limit = { exists = scope:newly_created_artifact } # To avoid errors
	        	send_interface_toast = {
		        	title = court.8010.a.equipped_tt
		        	left_icon = scope:underequipped
		        	right_icon = scope:newly_created_artifact
		        	scope:newly_created_artifact = {
		        		set_owner = {
		        			target = scope:underequipped
							history = {
								location = ROOT.capital_province
								actor = root
								recipient = scope:underequipped
								type = given
							}
						}
		        	}
		        }
	        }
	    }
	    scope:underequipped = {
	    	add_opinion = {
	    		target = ROOT
	    		modifier = grateful_opinion
	    		opinion = 10
	    	}
	    }
        stress_impact = {
			greedy = medium_stress_impact_gain # It's too espensive
			callous = medium_stress_impact_gain # So?
		}
        ai_chance = {
            base = 100
            ai_value_modifier = {
            	ai_greed = -1
            	ai_compassion = 1
            }
            modifier = {	#Weight down for stress.
            	add = -15
            	has_trait = greedy            	
            }
            modifier = {	#Weight down for stress.
            	add = -15
            	has_trait = callous            	
            }
        }
    }

    option = { # Give lesser owned sword
        name = court.8010.c
        trigger = { exists = scope:my_weapon }
        add_prestige = minor_prestige_gain
        scope:underequipped = {
	    	add_opinion = {
	    		target = ROOT
	    		modifier = grateful_opinion
	    		opinion = 20
	    	}
	    }
        send_interface_toast = {
        	title = court.8010.c.equipped_tt
        	left_icon = scope:underequipped
        	right_icon = scope:my_weapon
	        scope:my_weapon = {
	    		set_owner = {
	    			target = scope:underequipped
					history = {
						location = ROOT.capital_province
						actor = root
						recipient = scope:underequipped
						type = given
					}
				}
	    	}
	    }
	    stress_impact = {
			greedy = major_stress_impact_gain # My precious?!
			arrogant = medium_stress_impact_gain # My swords are too strong for you traveler
		}
        ai_chance = {
            base = 100
            ai_value_modifier = {
            	ai_greed = -2
            	ai_compassion = 1
            }
            modifier = {	#Weight down for stress.
            	add = -30
            	has_trait = greedy            	
            }
            modifier = {	#Weight down for stress.
            	add = -15
            	has_trait = arrogant            	
            }
        }
    }

    option = { # Give a sword from the armory
        name = court.8010.d
        change_current_court_grandeur = minor_court_grandeur_loss
        custom_tooltip = court.8010.d.tt
        scope:underequipped = {
	    	add_opinion = {
	    		target = ROOT
	    		modifier = disappointed_opinion
	    		opinion = -5
	    	}
	        if = {
	        	limit = {
	    			any_character_artifact = {
	    				is_equipped = yes
	        			artifact_slot_type = primary_armament
	        			ep1_artifact_durability_lower_equal_percent_trigger = { PERCENT = 0.99 }
	    			}
	        	}
	    		random_character_artifact = {
	    			limit = {
	    				is_equipped = yes
	        			artifact_slot_type = primary_armament
	        			ep1_artifact_durability_lower_equal_percent_trigger = { PERCENT = 0.49 }
	    			}
	        		add_durability = {
	    				value = artifact_max_durability
	    				multiply = 0.25
	    			}
	    		}
	        }
		}
		stress_impact = {
			generous = medium_stress_impact_gain # I have so much to give!
			paranoid = medium_stress_impact_gain # My fighters are ineffective!
		}
        ai_chance = {
            base = 100
            ai_value_modifier = {
            	ai_greed = 2
            }
            modifier = {	#Weight down for stress.
            	add = -15
            	has_trait = generous            	
            }
            modifier = {	#Weight down for stress.
            	add = -15
            	has_trait = paranoid            	
            }

        }
    }

    option = { # Angry
        name = court.8010.e
        trigger = {
        	OR = {
        		has_trait = wrathful
        		has_trait = irritable
        	}
        }
        add_dread = miniscule_dread_gain
        scope:underequipped = {
        	add_opinion = {
	    		target = ROOT
	    		modifier = insulted_opinion
	    		opinion = -15
	    	}
        	switch = {
        		trigger = has_court_position
        		bodyguard_court_position = {
        			ROOT = {
        				revoke_court_position = {
        					court_position = bodyguard_court_position
        					recipient = scope:underequipped
        				}
        			}
        		}
        		champion_court_position = {
        			ROOT = {
        				revoke_court_position = {
        					court_position = champion_court_position
        					recipient = scope:underequipped
        				}
        			}
        		}
        	}
		}
		stress_impact = {
			wrathful = medium_stress_impact_loss # It feels good to shout
			generous = medium_stress_impact_gain # I have so much to give!
			humble = medium_stress_impact_gain # I am no better than anyone else
		}
        ai_chance = {
            base = 100
            ai_value_modifier = {
            	ai_vengefulness = 2
            }
            modifier = {	#Weight up.
            	add = 15
            	has_trait = wrathful            	
            }
            modifier = {	#Weight down for stress.
            	add = -15
            	has_trait = generous            	
            }
            modifier = {	#Weight down for stress.
            	add = -15
            	has_trait = humble            	
            }
        }
    }
    after = {
    	clear_court_event_participation = yes
    	scope:underequipped = {
    		clear_court_event_participation = yes
    	}
    }
}

#########################
# Sartorial Sting		#
# by Joe Parkin 		#
#########################

court.8020 = {
    type = court_event
    title = court.8020.t
    desc = court.8020.desc
    theme = court
    cooldown = { years = 10 }
    court_scene = {
        button_position_character = scope:couture_spouse
        roles = {
            scope:couture_spouse = {
                group = event_group
                animation = anger
            }
            scope:couture_guest = {
                group = event_group
                animation = schadenfreude
            }
        }
    }

    trigger = {
    	amenity_level = { type = court_fashion value <= medium_amenity_level }
        is_married = yes
        primary_spouse = {
        	is_alive = yes
        	has_court_event_flag = no
		}
        any_pool_guest = {
        	is_available_ai_adult = yes
        	has_court_event_flag = no
		}
		
		NOT = {
			government_has_flag = government_is_tribal # No changing amenities above what's legal for tribals
		}
    }

    weight_multiplier = {
        base = 1
        ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_diplomatic }
    }

    immediate = {
    	primary_spouse = {
    		save_scope_as = couture_spouse
    		court_event_character_flag_effect = yes
    	}
    	random_pool_guest = {
    		limit = { is_available_ai_adult = yes }
    		weight = {
    			base = 1
    			modifier = {
    				factor = 20
    				NOT = { culture = ROOT.culture }
    			}
    			modifier = {
    				factor = 10
    				sex_same_as = ROOT.primary_spouse
    			}
    		}
    		save_scope_as = couture_guest
    		court_event_character_flag_effect = yes
    	}
    	primary_spouse = {
    		progress_towards_rival_effect = {
  				CHARACTER = scope:couture_guest
  				REASON = rival_couture_criticised
  				OPINION = 0
 			}
    	}
    }

    option = { # Laugh it off
        name = court.8020.a
        add_prestige = minor_prestige_gain
        change_current_court_grandeur = minor_court_grandeur_loss
        primary_spouse = {
    		add_opinion = {
    			target = ROOT
    			modifier = annoyed_opinion
    			opinion = -10
    		}
    	}
    	stress_impact = {
    		arrogant = medium_stress_impact_gain # How dare they mock us
    		wrathful = medium_stress_impact_gain # Why I 'oughta
    		vengeful = medium_stress_impact_gain # They said what?!
    	}
		ai_chance = {
            base = 100
            ai_value_modifier = {
            	ai_vengefulness = -2
            	ai_rationality = 1
            }
            modifier = {	#Weight down for stress.
            	add = -15
            	has_trait = arrogant            	
            }
            modifier = {	#Weight down for stress.
            	add = -15
            	has_trait = wrathful            	
            }
            modifier = {	#Weight down for stress.
            	add = -15
            	has_trait = vengeful            	
            }
        }
    }

    option = { # Make an effort
        name = court.8020.b
        set_amenity_level = { type = court_fashion value = high_amenity_level }
        primary_spouse = {
    		add_opinion = {
    			target = ROOT
    			modifier = annoyed_opinion
    			opinion = -5
    		}
    	}
    	scope:couture_guest = {
    		add_opinion = {
    			target = ROOT
    			modifier = respect_opinion
    			opinion = 10
    		}
    	}
    	stress_impact = {
    		greedy = medium_stress_impact_gain # It's too espensive
    		content = medium_stress_impact_gain # What's wrong with our clothes?
    		humble = medium_stress_impact_gain # These clothes are good enough
    		improvident = medium_stress_impact_loss # Shopping!
    	}
		ai_chance = {
            base = 100
            ai_value_modifier = {
            	ai_greed = -1
            	ai_rationality = 1
            }
            modifier = {	#Weight down for stress.
            	add = -15
            	has_trait = greedy            	
            }
            modifier = {	#Weight down for stress.
            	add = -15
            	has_trait = content            	
            }
            modifier = {	#Weight down for stress.
            	add = -15
            	has_trait = humble            	
            }
        }
    }

    option = { # Kick guest out
        name = court.8020.d
        scope:couture_guest = {
        	select_and_move_to_pool_effect = yes
        	add_opinion = {
    			target = ROOT
    			modifier = insulted_opinion
    			opinion = -10
    		}	
    	}
        primary_spouse = {
    		add_opinion = {
    			target = ROOT
    			modifier = pleased_opinion
    			opinion = 15
    		}
    	}
    	add_character_modifier = {
    		modifier = poor_host_modifier
    		years = 3
    	}
    	stress_impact = {
    		wrathful = medium_stress_impact_loss # It feels good to shout
    		calm = medium_stress_impact_gain # I am in control
    		humble = medium_stress_impact_gain # Let them say what they like
    		forgiving = medium_stress_impact_gain # No skin off my nose
    		patient = medium_stress_impact_gain # Let's not be hasty
    		gregarious = medium_stress_impact_gain # Let's all just get along!
    	}
		ai_chance = {
            base = 100
            ai_value_modifier = {
            	ai_vengefulness = 2
            }
            modifier = {	#Weight down for stress.
            	add = 30
            	has_trait = wrathful            	
            }
            modifier = {	#Weight down for stress.
            	add = -30
            	has_trait = calm            	
            }
            modifier = {	#Weight down for stress.
            	add = -15
            	has_trait = humble            	
            }
            modifier = {	#Weight down for stress.
            	add = -15
            	has_trait = forgiving            	
            }
        }
    }
    after = {
    	scope:couture_guest = {
    		clear_court_event_participation = yes
		}
		scope:couture_spouse = {
			clear_court_event_participation = yes
		}
    }
}

#########################
# Pawful of Pooches		#
# by Joe Parkin 		#
#########################

scripted_trigger court_8030_child_trigger = {
	age >= 6
	is_adult = no
	is_available = yes
	NOT = { has_character_modifier = dog_story_modifier }
}

court.8030 = {
    type = court_event
    title = court.8030.t
    desc = {
    	desc = court.8030.desc.intro
    	first_valid = {
    	    triggered_desc = {
    	        trigger = { exists = scope:child_2 }
    	        desc = court.8030.desc.two
    	    }
    	    desc = court.8030.desc.one
    	}
    	desc = court.8030.desc.body
    }
    theme = court
    cooldown = { years = 10 }
    court_scene = {
        button_position_character = scope:huntmaster
        roles = {
            scope:huntmaster = {
                group = event_group
                animation = happiness
            }
            scope:child_1 = {
                group = event_group
                animation = beg
            }
            scope:child_2 = {
                group = event_group
                animation = approval
            }
        }
    }

    trigger = {
    	employs_court_position = master_of_hunt_court_position
    	any_court_position_holder = {
    		type = master_of_hunt_court_position
    		is_available_ai_adult = yes
    		has_court_event_flag = no
    	}
    	any_child = {
    		court_8030_child_trigger = yes
    		has_court_event_flag = no
    	}
    }

    weight_multiplier = {
        base = 1
    }

    immediate = {
    	random_court_position_holder = {
    		type = master_of_hunt_court_position
    		limit = { is_available_ai_adult = yes }
    		save_scope_as = huntmaster
    		court_event_character_flag_effect = yes
    	}
    	random_child = {
    		limit = { court_8030_child_trigger = yes }
    		weight = {
    			base = 1
    			modifier = {
    				factor = 2
    				has_trait = curious
    			}
    			modifier = {
    				factor = 2
    				has_trait = charming
    			}
    			modifier = {
    				factor = 2
    				has_focus = education_diplomacy
    			}
    		}
    		save_scope_as = child_1
    		court_event_character_flag_effect = yes
    	}
    	if = {
    		limit = {
    			any_child = {
    				court_8030_child_trigger = yes
    				NOT = { THIS = scope:child_1 }
    			}
    		}
    		random_child = {
    			limit = {
    				court_8030_child_trigger = yes
    				NOT = { THIS = scope:child_1 }
    			}
	    		weight = {
	    			base = 1
	    			modifier = {
	    				factor = 2
	    				has_trait = curious
	    			}
	    			modifier = {
	    				factor = 2
	    				has_trait = charming
	    			}
	    			modifier = {
	    				factor = 2
	    				has_focus = education_diplomacy
	    			}
	    		}
	    		save_scope_as = child_2
	    		court_event_character_flag_effect = yes
    		}
    	}
    }

    option = { 
        name = court.8030.a
        change_current_court_grandeur = medium_court_grandeur_gain
        add_character_modifier = {
        	modifier = hunting_pooches_modifier
        	years = 10
        }
        scope:child_1 = {
        	add_opinion = {
        		target = ROOT
        		modifier = disappointed_opinion
        		opinion = -10
        	}
        }
        if = {
        	limit = { exists = scope:child_2 }
        	scope:child_2 = {
	        	add_opinion = {
	        		target = ROOT
	        		modifier = disappointed_opinion
	        		opinion = -10
	        	}
	        }
        }
        stress_impact = {
        	lifestyle_hunter = major_stress_impact_loss
		}
        ai_chance = {
            base = 100
            ai_value_modifier = {
            	ai_greed = -1
            	ai_energy = 1
            	ai_honor = 1
            }
            modifier = {	#Weight up.
            	add = 30
            	has_trait = lifestyle_hunter       	
            }
        }
    }

    option = { 
        name = court.8030.b
        scope:child_1 = {
        	start_dog_story_cycle_effect = yes
        	add_opinion = {
        		target = ROOT
        		modifier = pleased_opinion
        		opinion = 15
        	}
        }
        scope:huntmaster = {
        	add_opinion = {
        		target = ROOT
        		modifier = annoyed_opinion
        		opinion = -10
        	}
        }
        if = {
        	limit = { exists = scope:child_2 }
        	scope:child_2 = {
	        	add_opinion = {
	        		target = ROOT
	        		modifier = annoyed_opinion
	        		opinion = -10
	        	}
	        }
        }
        stress_impact = {
        	lifestyle_hunter = medium_stress_impact_gain
        	just = minor_stress_impact_gain
        	callous = medium_stress_impact_gain
        }
        ai_chance = {
            base = 100
            ai_value_modifier = {
            	ai_greed = 0.5
            	ai_compassion = 1
            }
            modifier = {	#Weight up.
            	add = -15
            	has_trait = lifestyle_hunter       	
            }
            modifier = {	#Weight up.
            	add = -5
            	has_trait = just       	
            }
            modifier = {	#Weight up.
            	add = -15
            	has_trait = callous       	
            }
        }
    }

    option = { 
        name = court.8030.c
        trigger = { exists = scope:child_2 }
        scope:child_2 = {
        	start_dog_story_cycle_effect = yes
        	add_opinion = {
        		target = ROOT
        		modifier = pleased_opinion
        		opinion = 15
        	}
        }
        scope:huntmaster = {
        	add_opinion = {
        		target = ROOT
        		modifier = annoyed_opinion
        		opinion = -10
        	}
        }
    	scope:child_1 = {
        	add_opinion = {
        		target = ROOT
        		modifier = annoyed_opinion
        		opinion = -10
        	}
        }
        stress_impact = {
        	lifestyle_hunter = medium_stress_impact_gain
        	just = minor_stress_impact_gain
        	callous = medium_stress_impact_gain
        }
        ai_chance = {
            base = 100
            ai_value_modifier = {
            	ai_greed = 0.5
            	ai_compassion = 1
            }
            modifier = {	#Weight up.
            	add = -15
            	has_trait = lifestyle_hunter       	
            }
            modifier = {	#Weight up.
            	add = -5
            	has_trait = just       	
            }
            modifier = {	#Weight up.
            	add = -15
            	has_trait = callous       	
            }
        }
    }

    option = { 
        name = court.8030.d
        trigger = {
        	NOT = { has_character_modifier = dog_story_modifier }
        }
        start_dog_story_cycle_effect = yes
        scope:huntmaster = {
        	add_opinion = {
        		target = ROOT
        		modifier = annoyed_opinion
        		opinion = -10
        	}
        }
        scope:child_1 = {
        	add_opinion = {
        		target = ROOT
        		modifier = annoyed_opinion
        		opinion = -15
        	}
        }
        if = {
        	limit = { exists = scope:child_2 }
        	scope:child_2 = {
	        	add_opinion = {
	        		target = ROOT
	        		modifier = annoyed_opinion
	        		opinion = -15
	        	}
	        }
        }
        stress_impact = {
        	lifestyle_hunter = medium_stress_impact_gain
        	just = minor_stress_impact_gain
        	generous = medium_stress_impact_gain
        }
        ai_chance = {
            base = 100
            ai_value_modifier = {
            	ai_greed = 2
            	ai_compassion = 1
            }
            modifier = {	#Weight up.
            	add = -15
            	has_trait = lifestyle_hunter       	
            }
            modifier = {	#Weight up.
            	add = -5
            	has_trait = just       	
            }
            modifier = {	#Weight up.
            	add = -15
            	has_trait = generous       	
            }
        }
    }
    after = {
    	scope:huntmaster = {
    		clear_court_event_participation = yes
		}
		scope:child_1 = {
    		clear_court_event_participation = yes
		}
		if = {
			limit = { exists = scope:child_2 }
			scope:child_2 = {
	    		clear_court_event_participation = yes
			}
		}
    }
}
############################
# Aristocratic Pretensions #
# by Joe Parkin 		   #
############################

scripted_trigger court_8040_courtier_trigger = {
	is_available_healthy_ai_adult = yes
	any_held_title = { count = 0 }
	NOT = { is_close_family_of = ROOT }
	NOT = { has_trait = content }
	NOT = { has_trait = humble }
	trigger_if = {
		limit = { is_female = yes }
		ROOT = { faith_dominant_gender_female_or_equal = yes }
	}
	trigger_else = { faith_dominant_gender_male_or_equal = yes }
}

scripted_effect court_8040_grant_effect = {
	send_interface_toast = {
		left_icon = scope:new_noble
		title = court.8040.grant_tt
		ROOT = {
			create_title_and_vassal_change = {
				type = granted
				save_scope_as = change
				add_claim_on_loss = no
			}
			scope:worst_title = {
				change_title_holder = {
					holder = scope:new_noble
					change = scope:change
				}
			}
			resolve_title_and_vassal_change = scope:change
			scope:new_noble = {
				if = {
					limit = { scope:worst_title.tier = tier_barony }
					add_opinion = {
						target = ROOT
						modifier = received_title_barony
						opinion = 30
					}
				}
				else = {
					add_opinion = {
						target = ROOT
						modifier = received_title_county
						opinion = 50
					}
				}
			}
			if = {
				limit = {
					can_add_hook = {
						target = scope:new_noble
						type = indebted_hook
					}
				}
				add_hook = {
					target = scope:new_noble
					type = indebted_hook
				}
			}
			every_in_list = {
				list = court_8040_list
				limit = {
					NOT = { THIS = scope:new_noble }
				}
				add_opinion = {
					target = ROOT
					modifier = disappointed_opinion
					opinion = -10
				}
			}
		}
	}
}

scripted_effect court_8040_desc_effect = {
	if = {
		limit = {
			has_any_court_position = yes
			NOT = { exists = scope:position_holder }
		}
		save_scope_as = position_holder
	}
	else_if = {
		limit = {
			is_knight = yes
			NOT = { exists = scope:knight }
		}
		save_scope_as = knight
	}
	else_if = {
		limit = {
			is_close_or_extended_family_of = ROOT
			NOT = { exists = scope:relative }
		}
		save_scope_as = relative
	}
	else_if = {
		limit = {
			has_trait = ambitious
			NOT = { exists = scope:ambitious }
		}
		save_scope_as = ambitious
	}
	else_if = {
		limit = {
			has_trait = arrogant
			NOT = { exists = scope:arrogant }
		}
		save_scope_as = arrogant
	}
	else_if = {
		limit = {
			is_lowborn = yes
			NOT = { exists = scope:lowborn }
		}
		save_scope_as = lowborn
	}
	else_if = {
		limit = {
			is_lowborn = no
			NOT = { exists = scope:gentry }
		}
		save_scope_as = gentry
	}
	else = {
		if = {
	 		limit = { NOT = { exists = scope:generic_1 } }
	 		save_scope_as = generic_1
	 	}
	 	else_if = {
     		limit = { NOT = { exists = scope:generic_2 } }
     		save_scope_as = generic_2
     	}
     	else = { save_scope_as = generic_3 }
	}
}

court.8040 = {
    type = court_event
    title = court.8040.t
    desc = {
    	desc = court.8040.desc.intro
	    triggered_desc = {
	        trigger = { exists = scope:position_holder }
	        desc = court.8040.desc.position_holder
	    }
	    triggered_desc = {
	        trigger = { exists = scope:knight }
	        desc = court.8040.desc.knight
	    }
	    triggered_desc = {
	        trigger = { exists = scope:relative }
	        desc = court.8040.desc.relative
	    }
    	triggered_desc = {
	        trigger = { exists = scope:ambitious }
	        desc = court.8040.desc.ambitious
	    }
	    triggered_desc = {
	        trigger = { exists = scope:arrogant }
	        desc = court.8040.desc.arrogant
	    }
	    triggered_desc = {
	        trigger = { exists = scope:lowborn }
	        desc = court.8040.desc.lowborn
	    }
	    triggered_desc = {
	        trigger = { exists = scope:gentry }
	        desc = court.8040.desc.gentry
	    }
	    triggered_desc = {
	        trigger = { exists = scope:generic_1 }
	        desc = court.8040.desc.generic_1
	    }
	    triggered_desc = {
	        trigger = { exists = scope:generic_2 }
	        desc = court.8040.desc.generic_2
	    }
	    triggered_desc = {
	        trigger = { exists = scope:generic_3 }
	        desc = court.8040.desc.generic_3
	    }
	    desc = court.8040.desc.body
    }
    theme = court
    override_background = { reference = throne_room }
    cooldown = { years = 10 }
    court_scene = {
        button_position_character = scope:courtier_3
        roles = {
            scope:courtier_1 = {
                group = event_group
                animation = personality_irrational
            }
            scope:courtier_2 = {
                group = event_group
                animation = personality_coward
            }
            scope:courtier_3 = {
                group = event_group
                animation = personality_dishonorable
            }
        }
    }

    trigger = {
    	has_royal_court = yes
        any_courtier = {
        	count >= 3
        	court_8040_courtier_trigger = yes
        	has_court_event_flag = no
        }
        OR = {
        	any_held_title = {
	        	tier = tier_barony
	        	is_capital_barony = no
	        	is_leased_out = no
	        	NOT = { THIS = ROOT.capital_barony }
	        }
	        any_held_title = {
	        	count >= 4
	        	tier = tier_county
	        	
	        }
	    }
	    domain_limit_available = 0
    }

    weight_multiplier = {
        base = 1
        modifier = {
        	factor = 10
        	domain_limit_available < 0
        }
    }

    immediate = {
        ordered_courtier = { # Find 3 courtiers and determine their flaws
         	limit = { court_8040_courtier_trigger = yes }
         	max = 3
         	check_range_bounds = no
         	order_by = prestige
         	if = {
         		limit = { NOT = { exists = scope:courtier_1 } }
         		save_scope_as = courtier_1
         		court_event_character_flag_effect = yes
         		court_8040_desc_effect = yes
         	}
         	else_if = {
         		limit = { NOT = { exists = scope:courtier_2 } }
         		save_scope_as = courtier_2
         		court_event_character_flag_effect = yes
         		court_8040_desc_effect = yes
         	}
         	else = {
         		save_scope_as = courtier_3
         		court_event_character_flag_effect = yes
         		court_8040_desc_effect = yes
         	}
         	add_to_list = court_8040_list
         	if = {
         		limit = { NOT = { exists = scope:button } }
         		save_scope_as = button # For button character
         	}
        }
        if = { # Find a valid barony to give away
        	limit = {
        		any_held_title = {
        			tier = tier_barony
        			is_capital_barony = no
        			is_leased_out = no
        			NOT = { THIS = ROOT.capital_barony }
        		}
        	}
        	ordered_held_title = {
	        	limit = {
	        		tier = tier_barony
	        		is_capital_barony = no
        			is_leased_out = no
        			NOT = { THIS = ROOT.capital_barony }
	        	}
	        	order_by = {
	        		value = 0
	        		subtract = title_province.combined_building_level
	        	}
	        	save_scope_as = worst_title
	        }
        }
        else = { # Find a valid county to give away
	        ordered_held_title = {
	        	limit = {
	        		tier = tier_county
	        		NOT = { THIS = ROOT.capital_county }
	        	}
	        	order_by = {
	        		value = 0
	        		subtract = development_level
	        	}
	        	save_scope_as = worst_title
	        }
	    }
    }

    option = { # Give to 1
        name = court.8040.a
        scope:courtier_1 = { save_scope_as = new_noble }
		court_8040_grant_effect = yes
		stress_impact = {
			greedy = medium_stress_impact_gain # But, titles
			diligent = medium_stress_impact_gain # But, I like managing stuff
			arrogant = medium_stress_impact_gain # But, my titles
		}
        ai_chance = {
            base = 100
            ai_value_modifier = {
   				ai_rationality = 0.5
   				ai_greed = -1
   			}
            modifier = { # Weight up for family members.
            	factor = 2
            	scope:courtier_1 = { is_close_or_extended_family_of = ROOT }
            }
            modifier = { # Weight up for dynasty members.
            	factor = 2
            	scope:courtier_1.dynasty = ROOT.dynasty
            }
            modifier = { # Weight up for opinion.
            	factor = 2
            	opinion = {
            		target = scope:courtier_1
            		value >= 50
            	}
            }
            modifier = {	#Weight down for stress.
				add = -15
				has_trait = greedy
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = diligent
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = arrogant
			}
        }
    }

    option = { # Give to 2
        name = court.8040.b
        scope:courtier_2 = { save_scope_as = new_noble }
        court_8040_grant_effect = yes
        stress_impact = {
			greedy = medium_stress_impact_gain # But, titles
			diligent = medium_stress_impact_gain # But, I like managing stuff
			arrogant = medium_stress_impact_gain # But, my titles
		}
        ai_chance = {
            base = 100
            ai_value_modifier = {
   				ai_rationality = 0.5
   				ai_greed = -1
   			}
            modifier = { # Weight up for family members.
            	factor = 2
            	scope:courtier_2 = { is_close_or_extended_family_of = ROOT }
            }
            modifier = { # Weight up for dynasty members.
            	factor = 2
            	scope:courtier_2.dynasty = ROOT.dynasty
            }
            modifier = { # Weight up for opinion.
            	factor = 2
            	opinion = {
            		target = scope:courtier_2
            		value >= 50
            	}
            }
            modifier = {	#Weight down for stress.
				add = -15
				has_trait = greedy
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = diligent
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = arrogant
			}
        }
    }

    option = { # Give to 3
        name = court.8040.c
        scope:courtier_3 = { save_scope_as = new_noble }
        court_8040_grant_effect = yes
        stress_impact = {
			greedy = medium_stress_impact_gain # But, titles
			diligent = medium_stress_impact_gain # But, I like managing stuff
			arrogant = medium_stress_impact_gain # But, my titles
		}
        ai_chance = {
            base = 100
            ai_value_modifier = {
   				ai_rationality = 0.5
   				ai_greed = -1
   			}
            modifier = { # Weight up for family members.
            	factor = 2
            	scope:courtier_3 = { is_close_or_extended_family_of = ROOT }
            }
            modifier = { # Weight up for dynasty members.
            	factor = 2
            	scope:courtier_3.dynasty = ROOT.dynasty
            }
            modifier = { # Weight up for opinion.
            	factor = 2
            	opinion = {
            		target = scope:courtier_3
            		value >= 50
            	}
            }
            modifier = {	#Weight down for stress.
				add = -15
				has_trait = greedy
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = diligent
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = arrogant
			}
        }
    }

    option = { # Best courtier wins - fight
        name = court.8040.d
        trigger = {
        	NOT = {
				faith = { has_doctrine = tenet_pacifism }
			}
        }
        flavor = court.8040.d.flavor_tt
        random_list = {
        	2 = {
        		desc = court.8040.d.courtier_1_tt
        		modifier = {
        			add = scope:courtier_1.prowess
        		}
        		scope:courtier_1 = { save_scope_as = new_noble }
        		show_as_tooltip = {
			        create_title_and_vassal_change = {
						type = granted
						save_scope_as = change
						add_claim_on_loss = no
					}
					scope:worst_title = {
						change_title_holder = {
							holder = scope:new_noble
							change = scope:change
						}
					}
					resolve_title_and_vassal_change = scope:change
		        }
        	}
        	2 = {
        		desc = court.8040.d.courtier_2_tt
        		modifier = {
        			add = scope:courtier_2.prowess
        		}
        		scope:courtier_2 = { save_scope_as = new_noble }
        		show_as_tooltip = {
			        create_title_and_vassal_change = {
						type = granted
						save_scope_as = change
						add_claim_on_loss = no
					}
					scope:worst_title = {
						change_title_holder = {
							holder = scope:new_noble
							change = scope:change
						}
					}
					resolve_title_and_vassal_change = scope:change
		        }
        	}
        	2 = {
        		desc = court.8040.d.courtier_3_tt
        		modifier = {
        			add = scope:courtier_3.prowess
        		}
        		scope:courtier_3 = { save_scope_as = new_noble }
        		show_as_tooltip = {
			        create_title_and_vassal_change = {
						type = granted
						save_scope_as = change
						add_claim_on_loss = no
					}
					scope:worst_title = {
						change_title_holder = {
							holder = scope:new_noble
							change = scope:change
						}
					}
					resolve_title_and_vassal_change = scope:change
		        }
        	}
        }
        every_in_list = {
        	list = court_8040_list
			increase_wounds_effect = { REASON = duel }
		}
		hidden_effect = { court_8040_grant_effect = yes }
		stress_impact = {
			lifestyle_blademaster = medium_stress_impact_loss # Yay fighty slash
			viking = medium_stress_impact_loss # Yay fighty slash
			#AGOT Disabled
			# varangian = medium_stress_impact_loss # Yay fighty slash
			berserker = medium_stress_impact_loss # Yay fighty slash
			brave = medium_stress_impact_loss # Yay fighty slash
			greedy = medium_stress_impact_gain # But, titles
			diligent = medium_stress_impact_gain # But, I like managing stuff
			arrogant = medium_stress_impact_gain # But, my titles
		}
		ai_chance = {
            base = 100
            ai_value_modifier = {
   				ai_energy = 2
   				ai_greed = -0.5
   			}
            ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_warlike }
            modifier = {	#Weight up for stress.
				add = 15
				has_trait = lifestyle_blademaster
			}
			modifier = {	#Weight up for stress.
				add = 15
				has_trait = viking
			}
			#AGOT Disabled
			# modifier = {	#Weight up for stress.
			# 	add = 15
			# 	has_trait = varangian
			# }
			modifier = {	#Weight up for stress.
				add = 15
				has_trait = berserker
			}
			modifier = {	#Weight up for stress.
				add = 15
				has_trait = berserker
			}
			modifier = {	#Weight up for stress.
				add = 15
				has_trait = brave
			}
            modifier = {	#Weight down for stress.
				add = -15
				has_trait = greedy
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = diligent
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = arrogant
			}
        }
    }

    option = { # Best courtier wins - persuasion
        name = court.8040.e
        change_current_court_grandeur = medium_court_grandeur_gain
        random_list = {
        	2 = {
        		desc = court.8040.e.courtier_1_tt
        		modifier = {
        			add = scope:courtier_1.diplomacy
        		}
        		scope:courtier_1 = { save_scope_as = new_noble }
        		show_as_tooltip = {
			        create_title_and_vassal_change = {
						type = granted
						save_scope_as = change
						add_claim_on_loss = no
					}
					scope:worst_title = {
						change_title_holder = {
							holder = scope:new_noble
							change = scope:change
						}
					}
					resolve_title_and_vassal_change = scope:change
		        }
        	}
        	2 = {
        		desc = court.8040.e.courtier_2_tt
        		modifier = {
        			add = scope:courtier_2.diplomacy
        		}
        		scope:courtier_2 = { save_scope_as = new_noble }
        		show_as_tooltip = {
			        create_title_and_vassal_change = {
						type = granted
						save_scope_as = change
						add_claim_on_loss = no
					}
					scope:worst_title = {
						change_title_holder = {
							holder = scope:new_noble
							change = scope:change
						}
					}
					resolve_title_and_vassal_change = scope:change
		        }
        	}
        	2 = {
        		desc = court.8040.e.courtier_3_tt
        		modifier = {
        			add = scope:courtier_3.diplomacy
        		}
        		scope:courtier_3 = { save_scope_as = new_noble }
        		show_as_tooltip = {
			        create_title_and_vassal_change = {
						type = granted
						save_scope_as = change
						add_claim_on_loss = no
					}
					scope:worst_title = {
						change_title_holder = {
							holder = scope:new_noble
							change = scope:change
						}
					}
					resolve_title_and_vassal_change = scope:change
		        }
        	}
        }
        stress_impact = {
			poet = medium_stress_impact_loss # Poetry duels are my jam
			gregarious = medium_stress_impact_loss # Having fun with friends was the real reward
			diplomat = medium_stress_impact_loss # Solving problems with words is the coolest
			greedy = medium_stress_impact_gain # But, titles
			diligent = medium_stress_impact_gain # But, I like managing stuff
			arrogant = medium_stress_impact_gain # But, my titles
		}
		hidden_effect = { court_8040_grant_effect = yes }
		ai_chance = {
            base = 100
            ai_value_modifier = {
   				ai_rationality = 1
   				ai_greed = -0.5
   			}
            ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_diplomatic }
            modifier = {	#Weight up for stress.
				add = 15
				has_trait = poet
			}
			modifier = {	#Weight up for stress.
				add = 15
				has_trait = gregarious
			}
			modifier = {	#Weight up for stress.
				add = 15
				has_trait = diplomat
			}
            modifier = {	#Weight down for stress.
				add = -15
				has_trait = greedy
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = diligent
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = arrogant
			}
        }
    }

    option = { # You get nothing!
        name = court.8040.f
        every_in_list = {
        	list = court_8040_list
        	add_opinion = {
        		target = ROOT
        		modifier = annoyed_opinion
        		opinion = -10
        	}
        }
        stress_impact = {
        	generous = medium_stress_impact_gain # But I have so much to give
        	lazy = medium_stress_impact_gain # I would rather have someone else do it
        	humble = medium_stress_impact_gain # Who am I to deny them?
        }
        ai_chance = {
            base = 100
            ai_value_modifier = {
   				ai_boldness = 1
   				ai_greed = 1
   			}
            modifier = { # Weight up for NO family members.
            	factor = 2
            	NOR = {
            		scope:courtier_1 = { is_close_or_extended_family_of = ROOT }
            		scope:courtier_2 = { is_close_or_extended_family_of = ROOT }
            		scope:courtier_3 = { is_close_or_extended_family_of = ROOT }
            	}
            }
            modifier = { # Weight up for NO dynasty members.
            	factor = 2
            	NOR = {
            		scope:courtier_1.dynasty = ROOT.dynasty
            		scope:courtier_2.dynasty = ROOT.dynasty
            		scope:courtier_3.dynasty = ROOT.dynasty
            	}
            }
            modifier = { # Weight up for NO opinion.
            	factor = 2
            	NOR = {
	            	opinion = {
	            		target = scope:courtier_1
	            		value >= 50
	            	}
	            	opinion = {
	            		target = scope:courtier_2
	            		value >= 50
	            	}
	            	opinion = {
	            		target = scope:courtier_3
	            		value >= 50
	            	}
	            }
            }
            modifier = {	#Weight down for stress.
				add = -15
				has_trait = generous
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = lazy
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = humble
			}
        }
    }
    after = {
    	scope:courtier_1 = {
    		clear_court_event_participation = yes
    	}
    	scope:courtier_2 = {
    		clear_court_event_participation = yes
    	}
    	scope:courtier_3 = {
    		clear_court_event_participation = yes
    	}
    }
}

#########################
# A Little Bird			#
# by Joe Parkin 		#
#########################

scripted_trigger court_8050_secrets_trigger = {
	is_ai = yes
	has_any_secrets = yes
	any_secret = {
		NOT = {
			any_secret_knower = { THIS = ROOT }
		}
	}
	is_human = yes
}

court.8050 = {
    type = court_event
    title = court.8050.t
    desc = court.8050.desc
    theme = court
    override_background = { reference = throne_room }
    cooldown = { years = 10 }
    court_scene = {
        button_position_character = scope:servant
        roles = {
            ROOT = {
                group = event_group
                animation = throne_room_conversation_4 
            }
            scope:servant = {
                group = event_group
                animation = throne_room_conversation_1
            }
        }
    }

    trigger = {
    	has_royal_court = yes
    	has_court_event_flag = no
    	OR = {
    		any_vassal = { 
    			court_8050_secrets_trigger = yes
    			has_court_event_flag = no
			}
    		any_courtier_or_guest = {
    			court_8050_secrets_trigger = yes
    			has_court_event_flag = no
    		}
    	}
		amenity_level = {
			type = court_servants
			value > high_amenity_level
		}
    }

    weight_multiplier = {
        base = 1
        modifier = {
        	factor = 2
        	amenity_level = {
				type = court_servants
				value = max_amenity_level
			}
		}
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_intrigue }
    }

    immediate = {
    	court_event_character_flag_effect = yes
    	every_vassal = {
    		limit = { court_8050_secrets_trigger = yes }
    		add_to_list = court_8050_secret_list
    	}
    	every_courtier_or_guest = {
    		limit = { court_8050_secrets_trigger = yes }
    		add_to_list = court_8050_secret_list
    	}
    	random_in_list = {
    		list = court_8050_secret_list
    		weight = {
    			base = 1
    			modifier = {
    				factor = primary_title.tier
    			}
    			modifier = {
    				factor = 2
    				any_secret = {
    					any_secret_knower = { count > 2 }
    				}
    			}
    		}
    		save_scope_as = vassal
    		random_secret = {
    			limit = {
    				NOT = {
						any_secret_knower = { THIS = ROOT }
					}
    			}
    			weight = {
	    			modifier = {
	    				factor = 2
	    				any_secret_knower = { count > 2 }
	    			}
	    		}
    			save_scope_as = vassal_secret
    			reveal_to = ROOT
    		}
    	}
    	if = {
    		limit = {
	        	any_in_list = {
	        		list = court_8050_secret_list
	        		NOT = { THIS = scope:vassal }
	        	}
	        }
	        random_in_list = {
	        	list = court_8050_secret_list
	        	save_scope_as = vassal_2
	        	random_secret = {
	        		limit = {
	    				NOT = {
							any_secret_knower = { THIS = ROOT }
						}
	    			}
	    			weight = {
		    			modifier = {
		    				factor = 2
		    				any_secret_knower = { count > 2 }
		    			}
		    		}
	    			save_scope_as = secret_2
	        	}
	        }
        }
    	hidden_effect = {
			create_character = {
				template = servant_character
				dynasty = none
				location = root.capital_province
				gender_female_chance = root_soldier_female_chance
				save_scope_as = servant
			}
		}
    }

    option = { # You have earned a place at court
        name = court.8050.a
        scope:servant = {
        	add_opinion = {
        		target = ROOT
        		modifier = grateful_opinion
        		opinion = 20
        	}
        }
        add_courtier = scope:servant
        stress_impact = {
        	paranoid = medium_stress_impact_gain # Hiring rando makes me nervous
        	arrogant = medium_stress_impact_gain # I don't surround myself with commoners
			shy = medium_stress_impact_gain # A new person to embarrass my self in front of
        }
        ai_chance = {
        	base = 100
            ai_value_modifier = {
   				ai_compassion = 1
   				ai_greed = 2
   			}
            modifier = { # Weight down for stress.
            	add = -15
            	has_trait = paranoid
            }
            modifier = { # Weight down for stress.
            	add = -15
            	has_trait = arrogant
            }
            modifier = { # Weight down for stress.
            	add = -15
            	has_trait = shy
            }
        }
    }

    option = { # What else have you heard?
        name = court.8050.b
        trigger = { exists = scope:secret_2 }
        remove_short_term_gold = tiny_gold_value
        custom_tooltip = court.8050.b.tt
        hidden_effect = {
        	send_interface_toast = {
        		title = court.8050.b.tt_secret
        		left_icon = scope:vassal_2
        		scope:secret_2 = { reveal_to = ROOT }
        	}
        }
        scope:servant = { silent_disappearance_effect = yes }
        stress_impact = {
        	schemer = medium_stress_impact_loss
        	trusting = medium_stress_impact_gain # What if people spy on me too?!
        	honest = medium_stress_impact_gain # This isn't above board
        	humble = medium_stress_impact_gain # It is not my business
        	lazy = medium_stress_impact_gain # Sounds like effort
        }
        ai_chance = {
        	base = 100
            ai_value_modifier = {
   				ai_honor = -2
   				ai_energy = 2
   			}
            modifier = { # Weight down for stress.
            	add = 15
            	has_trait = schemer
            }
            modifier = { # Weight down for stress.
            	add = -15
            	has_trait = trusting
            }
            modifier = { # Weight down for stress.
            	add = -15
            	has_trait = honest
            }
             modifier = { # Weight down for stress.
            	add = -15
            	has_trait = humble
            }
            modifier = { # Weight down for stress.
            	add = -15
            	has_trait = lazy
            }
        }
    }

    option = { # Keep me informed
        name = court.8050.c
        remove_short_term_gold = minor_gold_value
        add_character_modifier = {
        	modifier = servant_informants_modifier
        	years = 5
        }
        custom_tooltip = court.8050.c.tt
        scope:servant = { silent_disappearance_effect = yes }
        stress_impact = {
        	schemer = medium_stress_impact_loss # Sweet, sweet scheming
        	trusting = medium_stress_impact_gain # What if people spy on me too?!
        	honest = medium_stress_impact_gain # This isn't above board
        	humble = medium_stress_impact_gain # It is not my business
        	lazy = medium_stress_impact_gain # Sounds like effort
        }
        ai_chance = {
        	base = 100
            ai_value_modifier = {
   				ai_honor = -2
   				ai_energy = 2
   			}
            modifier = { # Weight down for stress.
            	add = 15
            	has_trait = schemer
            }
            modifier = { # Weight down for stress.
            	add = -15
            	has_trait = trusting
            }
            modifier = { # Weight down for stress.
            	add = -15
            	has_trait = honest
            }
             modifier = { # Weight down for stress.
            	add = -15
            	has_trait = humble
            }
            modifier = { # Weight down for stress.
            	add = -15
            	has_trait = lazy
            }
        }
    }

    option = { # Lies!
        name = court.8050.d
        change_current_court_grandeur = minor_court_grandeur_gain
        send_interface_toast = {
			title = court.8050.d.tt_imprison
			left_icon = scope:servant
			rightfully_imprison_character_effect = {
				TARGET = scope:servant
				IMPRISONER = ROOT
			}
		}
		stress_impact = {
        	compassionate = medium_stress_impact_loss # Imagine if I were accused of such a thing!
        	deceitful = major_stress_impact_gain # So much to be gained here...
        	just = medium_stress_impact_gain # Ignoring evidence makes me sad
        	trusting = medium_stress_impact_gain # People lie?!
        }
        ai_chance = {
        	base = 100
            ai_value_modifier = {
            	ai_honor = -1
   				ai_boldness = 1
   			}
            modifier = { # Weight down for stress.
            	add = 15
            	has_trait = compassionate
            }
            modifier = { # Weight down for stress.
            	add = -15
            	has_trait = deceitful
            }
             modifier = { # Weight down for stress.
            	add = -15
            	has_trait = just
            }
            modifier = { # Weight down for stress.
            	add = -15
            	has_trait = paranoid
            }
        }
    }
    after = {
    	clear_court_event_participation = yes
    	scope:servant = {
    		clear_court_event_participation = yes
    	}
    }
}

#########################
# Scornful Sycophants	#
# by Joe Parkin 		#
#########################

scripted_trigger court_8060_trigger = {
	is_ai = yes
	is_adult = yes
	NOR = {
		is_close_or_extended_family_of = ROOT
		is_spouse_of = ROOT
		is_concubine_of = ROOT
	}
	is_human = yes
}

scripted_trigger court_8060_snooty_trigger = {
	court_8060_trigger = yes
	OR = {
		NOR = {
			has_trait = humble
			has_trait = content
			has_trait = zealous
		}
		has_trait = lifestyle_reveler
		has_relation_rival = ROOT
	}
}

court.8060 = {
    type = court_event
    title = court.8060.t
    desc = {
    	desc = court.8060.desc.intro
    	first_valid = { # 1st char
    	    triggered_desc = {
    	        trigger = {
					amenity_level = { type = court_fashion value < high_amenity_level }	
    	        }
    	        desc = court.8060.desc.fashion
    	    }
    	    triggered_desc = {
    	        trigger = {
    				amenity_level = { type = court_servants value < high_amenity_level }
    	        }
    	        desc = court.8060.desc.servants_1
    	    }
    	    desc = court.8060.desc.food_1
    	}
    	desc = court.8060.desc.body
    	first_valid = { # 2nd char
    	    triggered_desc = {
    	        trigger = {
    				amenity_level = { type = court_lodging_standards value < high_amenity_level }
    	        }
    	        desc = court.8060.desc.lodgings
    	    }
    	    triggered_desc = {
    	        trigger = {
	    			amenity_level = { type = court_food_quality value < high_amenity_level }
    	        }
    	        desc = court.8060.desc.food_2
    	    }
    	    desc = court.8060.desc.servants_2
    	}
    	desc = court.8060.desc.outro
    }
    theme = court
    override_background = { reference = throne_room }
    cooldown = { years = 10 }
    court_scene = {
        button_position_character = scope:snooty_1
        roles = {
            scope:snooty_1 = {
                group = event_group
                animation = throne_room_conversation_3 
            }
            scope:snooty_2 = {
                group = event_group
                animation = throne_room_conversation_2
            }
        }
    }

    trigger = {
    	has_royal_court = yes
    	any_courtier_or_guest = {
    		count >= 2
    		court_8060_trigger = yes
    	}
    	any_courtier_or_guest = { court_8060_snooty_trigger = yes }
		average_amenity_level < high_amenity_level
		calc_true_if = {
			amount = 2
			amenity_level = { type = court_fashion value < high_amenity_level }
			amenity_level = { type = court_servants value < high_amenity_level }
			amenity_level = { type = court_food_quality value < high_amenity_level }
			amenity_level = { type = court_lodging_standards value < high_amenity_level }
		}
		
		NOT = {
			government_has_flag = government_is_tribal # No changing amenities above what's legal for tribals
		}
    }

    weight_multiplier = {
        base = 1
        modifier = {
        	factor = 2
        	average_amenity_level < medium_amenity_level
		}
		modifier = {
			factor = 2
			court_grandeur_current_level < court_grandeur_minimum_expected_level
		}
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_diplomatic }
    }

    immediate = {
    	random_courtier_or_guest = {
    		limit = { court_8060_snooty_trigger = yes }
    		alternative_limit = { court_8060_trigger = yes }
    		weight = {
    			modifier = { factor = THIS.prestige }
    		}
    		save_scope_as = snooty_1
    	}
    	random_courtier_or_guest = {
    		limit = {
    			court_8060_snooty_trigger = yes
    			NOT = { THIS = scope:snooty_1 }
    		}
    		alternative_limit = {
    			court_8060_trigger = yes
    			NOT = { THIS = scope:snooty_1 }
    		}
    		weight = {
    			modifier = { factor = THIS.prestige }
    		}
    		save_scope_as = snooty_2
    	}
    }

    option = { # We could make X better...
        name = {
			trigger = {
				amenity_level = { type = court_fashion value < high_amenity_level }
			}
			text = court.8060.a.fashion
		}
		name = {
			trigger = {
				amenity_level = { type = court_servants value < high_amenity_level }
			}
			text = court.8060.a.servants
		}
		name = { text = court.8060.a.food }
        if = {
        	limit = { 
        		amenity_level = { type = court_fashion value < high_amenity_level }
        	}
        	set_amenity_level = { type = court_fashion value = high_amenity_level }
        }
        else_if = {
        	limit = { 
        		amenity_level = { type = court_servants value < high_amenity_level }
        	}
        	set_amenity_level = { type = court_servants value = high_amenity_level }
        }
        else = {
        	set_amenity_level = { type = court_food_quality value = high_amenity_level }
        }
        change_current_court_grandeur = medium_court_grandeur_gain
        scope:snooty_1 = {
        	add_opinion = {
        		target = ROOT
        		modifier = respect_opinion
        		opinion = 10
        	}
        }
        scope:snooty_2 = {
        	add_opinion = {
        		target = ROOT
        		modifier = respect_opinion
        		opinion = 5
        	}
        }
        stress_impact = {
        	greedy = medium_stress_impact_gain # But it costs so much...
        	stubborn = medium_stress_impact_gain # Things are ok as they are
        	humble = medium_stress_impact_gain # What do I need fancy shmancy things for?
        	wrathful = medium_stress_impact_gain # How dare they!
        	vengeful = medium_stress_impact_gain # How dare he!
        }
        ai_chance = {
        	base = 100
            ai_value_modifier = {
            	ai_greed = -2
   				ai_boldness = -1
   			}
            modifier = { # Weight down for stress.
            	add = -15
            	has_trait = greedy
            }
            modifier = { # Weight down for stress.
            	add = -15
            	has_trait = stubborn
            }
            modifier = { # Weight down for stress.
            	add = -15
            	has_trait = humble
            }
            modifier = { # Weight down for stress.
            	add = -15
            	has_trait = wrathful
            }
            modifier = { # Weight down for stress.
            	add = -15
            	has_trait = vengeful
            }
        }
    }

    option = { # Our Y is not great...
        name = {
			trigger = {
				amenity_level = { type = court_lodging_standards value < high_amenity_level }
			}
			text = court.8060.b.lodgings
		}
		name = {
			trigger = {
				amenity_level = { type = court_food_quality value < high_amenity_level }
			}
			text = court.8060.b.food
		}
		name = { text = court.8060.b.servants }
        if = {
        	limit = { 
        		amenity_level = { type = court_lodging_standards value < high_amenity_level }
        	}
        	set_amenity_level = { type = court_lodging_standards value = high_amenity_level }
        }
        else_if = {
        	limit = { 
        		amenity_level = { type = court_food_quality value < high_amenity_level }
        	}
        	set_amenity_level = { type = court_food_quality value = high_amenity_level }
        }
        else = {
        	set_amenity_level = { type = court_servants value = high_amenity_level }
        }
        change_current_court_grandeur = medium_court_grandeur_gain
        scope:snooty_2 = {
        	add_opinion = {
        		target = ROOT
        		modifier = respect_opinion
        		opinion = 10
        	}
        }
        scope:snooty_1 = {
        	add_opinion = {
        		target = ROOT
        		modifier = respect_opinion
        		opinion = 5
        	}
        }
        stress_impact = {
        	greedy = medium_stress_impact_gain # But it costs so much...
        	stubborn = medium_stress_impact_gain # Things are ok as they are
        	humble = medium_stress_impact_gain # What do I need fancy shmancy things for?
        	wrathful = medium_stress_impact_gain # How dare they!
        	vengeful = medium_stress_impact_gain # How dare he!
        }
        ai_chance = {
        	base = 100
            ai_value_modifier = {
            	ai_greed = -2
   				ai_boldness = -1
   			}
            modifier = { # Weight down for stress.
            	add = -15
            	has_trait = greedy
            }
            modifier = { # Weight down for stress.
            	add = -15
            	has_trait = stubborn
            }
            modifier = { # Weight down for stress.
            	add = -15
            	has_trait = humble
            }
            modifier = { # Weight down for stress.
            	add = -15
            	has_trait = wrathful
            }
            modifier = { # Weight down for stress.
            	add = -15
            	has_trait = vengeful
            }
        }
    }

    option = { # Admonish
        name = court.8060.c
        scope:snooty_1 = {
        	add_opinion = {
        		target = ROOT
        		modifier = insulted_opinion
        		opinion = -10
        	}
        }
        scope:snooty_2 = {
        	add_opinion = {
        		target = ROOT
        		modifier = insulted_opinion
        		opinion = -10
        	}
        }
        change_current_court_grandeur = medium_court_grandeur_loss
        stress_impact = {
        	patient = medium_stress_impact_gain # I am chill
        	compassionate = medium_stress_impact_gain # I am a nice guy
        	shy = medium_stress_impact_gain # Shouting at the scary people?!
        	humble = medium_stress_impact_gain # Who am I to judge?
        }
        ai_chance = {
        	base = 100
            ai_value_modifier = {
            	ai_vengefulness = 1
   				ai_boldness = 2
   			}
            modifier = { # Weight down for stress.
            	add = -15
            	has_trait = patient
            }
             modifier = { # Weight down for stress.
            	add = -15
            	has_trait = compassionate
            }
            modifier = { # Weight down for stress.
            	add = -15
            	has_trait = shy
            }
            modifier = { # Weight down for stress.
            	add = -15
            	has_trait = humble
            }
        }
    }

    option = { # Find some other ruler to brown-nose then!
        name = court.8060.d
        add_prestige = minor_prestige_gain
        change_current_court_grandeur = medium_court_grandeur_loss
        scope:snooty_1 = {
        	add_opinion = {
        		target = ROOT
        		modifier = angry_opinion
        		opinion = -20
        	}
        	select_and_move_to_pool_effect = yes
        }
        scope:snooty_2 = {
        	add_opinion = {
        		target = ROOT
        		modifier = angry_opinion
        		opinion = -20
        	}
        	select_and_move_to_pool_effect = yes
        }
        stress_impact = {
        	patient = major_stress_impact_gain # I am chill though
        	compassionate = major_stress_impact_gain # I am a nice guy though
        	shy = major_stress_impact_gain # Shouting at the scary people?!
        	humble = major_stress_impact_gain # I am just like them though
        }
        ai_chance = {
        	base = 100
            ai_value_modifier = {
            	ai_vengefulness = 2
   				ai_boldness = 4
   			}
            modifier = { # Weight down for stress.
            	add = -15
            	has_trait = patient
            }
             modifier = { # Weight down for stress.
            	add = -15
            	has_trait = compassionate
            }
            modifier = { # Weight down for stress.
            	add = -15
            	has_trait = shy
            }
            modifier = { # Weight down for stress.
            	add = -15
            	has_trait = humble
            }
        }
    }

    option = { # Material things are a distraction
        name = court.8060.e
        trigger = {
        	NOT = { has_trait = cynical }
        	faith = {
        		OR = {
        			has_doctrine = tenet_monasticism
					has_doctrine = tenet_vows_of_poverty
					has_doctrine = tenet_mendicant_preachers
					has_doctrine = tenet_gnosticism
					has_doctrine = tenet_inner_journey
					has_doctrine = tenet_asceticism
        		}
        	}
        }
        add_piety = medium_piety_gain
        if = {
			limit = { exists = cp:councillor_court_chaplain }
			cp:councillor_court_chaplain = {
				add_opinion = {
					target = root
					modifier = pious_opinion
					opinion = 10
				}
			}
		}
		every_vassal = {
        	limit = {
        		NOT = { has_trait = cynical }
        		faith = {
        			OR = {
	        			has_doctrine = tenet_monasticism
						has_doctrine = tenet_vows_of_poverty
						has_doctrine = tenet_mendicant_preachers
						has_doctrine = tenet_gnosticism
						has_doctrine = tenet_inner_journey
						has_doctrine = tenet_asceticism
	        		}
        		}
        	}
        	custom = court.8060.e.pious_tt
        	add_opinion = {
        		target = ROOT
        		modifier = pious_opinion
        		opinion = 5
        	}
        }
        hidden_effect = {
	        every_courtier = {
	        	limit = {
	        		NOT = { has_trait = cynical }
	        		faith = {
	        			OR = {
		        			has_doctrine = tenet_monasticism
							has_doctrine = tenet_vows_of_poverty
							has_doctrine = tenet_mendicant_preachers
							has_doctrine = tenet_gnosticism
							has_doctrine = tenet_inner_journey
							has_doctrine = tenet_asceticism
		        		}
	        		}
	        		NOT = { THIS = scope:snooty_1 }
	        		NOT = { THIS = scope:snooty_2 }
	        	}
	        	custom = court.8060.e.pious_tt
	        	add_opinion = {
	        		target = ROOT
	        		modifier = pious_opinion
	        		opinion = 10
	        	}
	        }
	    }
        scope:snooty_1 = {
        	add_opinion = {
        		target = ROOT
        		modifier = humbled_opinion
        		opinion = -5
        	}
        }
        scope:snooty_2 = {
        	add_opinion = {
        		target = ROOT
        		modifier = humbled_opinion
        		opinion = -5
        	}
        }
        stress_impact = {
        	cynical = major_stress_impact_gain # ...from what?
        	greedy = medium_stress_impact_gain # ...but they are also shiny
        	gluttonous = medium_stress_impact_gain # ...but they are also tasty
        }
        ai_chance = {
        	base = 100
            ai_value_modifier = {
            	ai_greed = -2
   				ai_zeal = 2
   			}
            modifier = { # Weight down for stress.
            	add = -15
            	has_trait = cynical
            }
            modifier = { # Weight down for stress.
            	add = -15
            	has_trait = greedy
            }
            modifier = { # Weight down for stress.
            	add = -15
            	has_trait = gluttonous
            }
        }
    }

    option = { # Pretend you didn't hear
        name = court.8060.f
        flavor = court.8060.f.flavor
        add_prestige = minor_prestige_loss
        change_current_court_grandeur = medium_court_grandeur_loss
        stress_impact = {
        	arrogant = medium_stress_impact_gain # Those churls!
        	vengeful = medium_stress_impact_gain # You churls!
        	wrathful = medium_stress_impact_gain # CHURLS!!!!!
        	arbitrary = medium_stress_impact_gain # These churls!
        	honest = medium_stress_impact_gain # I heard you, churls!
        }
        ai_chance = {
        	base = 100
            ai_value_modifier = {
            	ai_vengefulness = -2
   				ai_boldness = -2
   			}
            modifier = { # Weight down for stress.
            	add = -15
            	has_trait = arrogant
            }
            modifier = { # Weight down for stress.
            	add = -15
            	has_trait = vengeful
            }
            modifier = { # Weight down for stress.
            	add = -15
            	has_trait = wrathful
            }
            modifier = { # Weight down for stress.
            	add = -15
            	has_trait = arbitrary
            }
            modifier = { # Weight down for stress.
            	add = -15
            	has_trait = honest
            }
        }
    }
}

#########################
# Feeling Useful		#
# by Joe Parkin 		#
#########################

scripted_trigger court_8070_employed_parent_trigger = {
	is_available_healthy_ai_adult = yes
	is_landed = no
	is_councillor = no
	has_any_court_position = no
	NOT = { has_trait = devoted }
}

court.8070 = {
    type = court_event
    title = court.8070.t
    desc = court.8070.desc
    theme = court
    cooldown = { years = 10 }
    court_scene = {
        button_position_character = scope:parent
        roles = {
            scope:parent = {
                group = event_group
                animation = throne_room_conversation_2
            }
            scope:other_parent = {
            	group = event_group
            	animation = throne_room_conversation_3
            }
        }
    }

    trigger = {
    	has_royal_court = yes
    	any_parent = {
    		employer = ROOT
    		court_8070_employed_parent_trigger = yes
    	}
    }

    weight_multiplier = {
    	base = 1
    }

    immediate = {
    	random_parent = {
    		limit = {
	    		employer = ROOT
	    		court_8070_employed_parent_trigger = yes
	    	}
	    	weight = {
	    		base = 1
	    		modifier = {
	    			factor = 2
	    			trigger_if = {
						limit = { is_female = yes }
						ROOT = { faith_dominant_gender_female_or_equal = yes }
					}
					trigger_else = { faith_dominant_gender_male_or_equal = yes }
	    		}
	    	}
	    	save_scope_as = parent
    	}
    	if = {
    		limit = {
    			any_parent = {
    				employer = ROOT
    				court_8070_employed_parent_trigger = yes
    				NOT = { THIS = scope:parent }
    			}
    		}
    		random_parent = {
	    		limit = {
		    		employer = ROOT
    				court_8070_employed_parent_trigger = yes
    				NOT = { THIS = scope:parent }
		    	}
		    	save_scope_as = other_parent
	    	}
    	}
    	else = {
    		random_courtier_or_guest = {
       			limit = {
            		NOT = { THIS = scope:parent }
					is_human = yes
        		}
        		save_scope_as = other_parent # Fallback for court scene errors
    		}
		}
		scope:parent = {
			court_position_backup_variable_effect = { EMPLOYER = root }
		}
    }

    option = { # Promise a court position
		name = court.8070.a
		custom_tooltip = court.8070.a.tt
		scope:parent = {
			set_variable = {
				name = court_8070_tracker
				value = ROOT
			} 
			add_character_modifier = {
				modifier = promised_court_position_modifier
				months = 3
			}
			trigger_event = {
				id = court.8071
				months = 3
			}
		}
		stress_impact = {
			callous = medium_stress_impact_gain
			lazy = medium_stress_impact_gain
			arrogant = medium_stress_impact_gain
		}
		ai_chance = {
            base = 100
            ai_value_modifier = {
            	ai_compassion = 1
            	ai_energy = 1
            }
            modifier = {	#Weight down for stress.
            	add = -15
            	has_trait = callous       	
            }
            modifier = {	#Weight down for stress.
            	add = -15
            	has_trait = lazy       	
            }
            modifier = {	#Weight down for stress.
            	add = -15
            	has_trait = arrogant       	
            }
        }
	}

	option = { # Convent
		name = court.8070.b
		trigger = {
			scope:parent = { is_married = no }
		}
		add_piety = minor_piety_gain
		scope:parent = {
			add_trait = devoted
			if = {
				limit = { has_trait = zealous }
				add_opinion = {
					target = ROOT
					modifier = insulted_opinion
					opinion = -20
				}
			}
			else = {
				add_opinion = {
					target = ROOT
					modifier = insulted_opinion
					opinion = -40
				}
			}
		}
		stress_impact = {
			cynical = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
		}
		ai_chance = {
            base = 100
            ai_value_modifier = {
            	ai_compassion = -1
            	ai_zeal = 1
            }
            modifier = {	#Weight down for stress.
            	add = -15
            	has_trait = cynical       	
            }
            modifier = {	#Weight down for stress.
            	add = -15
            	has_trait = compassionate       	
            }
        }
	}

	option = { # Grant a random open position
		name = court.8070.c
		trigger = {
			scope:parent = { has_variable = backup_court_position }
		}
		court_position_variable_assignment_effect = { VARIABLE = backup_court_position CANDIDATE = scope:parent  EMPLOYER = root }
		reverse_add_opinion = {
			target = scope:parent
			modifier = grateful_opinion
			opinion = 5
		}
		stress_impact = {
			cynical = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
		}
		ai_chance = {
            base = 100
            ai_value_modifier = {
            	ai_compassion = 1
            	ai_energy = -1
            }
            modifier = {	#Weight down for stress.
            	add = -15
            	has_trait = diligent       	
            }
            modifier = {	#Weight down for stress.
            	add = -15
            	has_trait = callous       	
            }
        }
	}

	option = { # Mother, please
		name = court.8070.d
		reverse_add_opinion = {
			target = scope:parent
			modifier = disappointed_opinion
			opinion = -10
		}
		stress_impact = {
			compassionate = medium_stress_impact_gain
			diligent = medium_stress_impact_gain
		}
		ai_chance = {
            base = 100
            ai_value_modifier = {
            	ai_compassion = -1
            	ai_energy = -1
            }
            modifier = {	#Weight down for stress.
            	add = -15
            	has_trait = compassionate       	
            }
            modifier = {	#Weight down for stress.
            	add = -15
            	has_trait = diligent       	
            }
        }
	}

	after = {
		scope:parent = {
			if = {
				limit = { has_variable = backup_court_position }
				remove_variable = backup_court_position
			}
		}
	}
}

court.8071 = {
    scope = none
    hidden = yes

    trigger = {
    	has_royal_court = yes
    	has_variable = court_8070_tracker
		employer = var:court_8070_tracker
    }

    immediate = {
    	if = {
    		limit = { has_character_modifier = promised_court_position_modifier }
    		remove_character_modifier = promised_court_position_modifier
    	}
    	if = {
    		limit = {
    			OR = {
    				is_landed = yes
					is_councillor = yes
					has_any_court_position = yes
    			}
    		}
    		var:court_8070_tracker = {
    			send_interface_toast = {
					title = court.8071.satisfied
					left_icon = ROOT
					ROOT = {
						add_opinion = {
							target = var:court_8070_tracker
							modifier = pleased_opinion
							opinion = 10
						}
					}
				}
    		}
    	}
    	else = {
    		var:court_8070_tracker = {
    			send_interface_toast = {
					title = court.8071.disappoint
					left_icon = ROOT
					ROOT = {
						add_opinion = {
							target = var:court_8070_tracker
							modifier = disappointed_opinion
							opinion = -15
						}
					}
				}
    		}
    	}
    }

    after = { remove_variable = court_8070_tracker }
}

#########################
# Maternal Reproach		#
# by Joe Parkin 		#
#########################

court.8080 = {
    type = court_event
    title = court.8080.t
    desc = {
    	desc = court.8080.desc.intro
    	first_valid = {
    		triggered_desc = {
    	        trigger = {
					amenity_level = { type = court_fashion value < high_amenity_level }	
    	        }
    	        desc = court.8080.desc.fashion
    	    }
    	    triggered_desc = {
    	        trigger = {
    				amenity_level = { type = court_servants value < high_amenity_level }
    	        }
    	        desc = court.8080.desc.servants
    	    }
    	    triggered_desc = {
    	        trigger = {
    				amenity_level = { type = court_lodging_standards value < high_amenity_level }
    	        }
    	        desc = court.8080.desc.lodgings
    	    }
    	    triggered_desc = {
    	        desc = court.8080.desc.food
    	    }
    	}
    	desc = court.8080.desc.outro
   	}
    theme = court
    cooldown = { years = 10 }
    court_scene = {
        button_position_character = scope:parent
        roles = {
            scope:parent = {
                group = event_group
                animation = throne_room_conversation_2
            }
            scope:other_parent = {
                group = event_group
                animation = throne_room_conversation_3
            }
        }
    }

    trigger = {
    	has_royal_court = yes
    	any_parent = {
    		employer = ROOT
    		is_available_ai_adult = yes
    	}
    	average_amenity_level < high_amenity_level
    	OR = {
    		amenity_level = { type = court_fashion value < high_amenity_level }
    		amenity_level = { type = court_servants value < high_amenity_level }
    		amenity_level = { type = court_lodging_standards value < high_amenity_level }
    		amenity_level = { type = court_food_quality value < high_amenity_level }
    	}
		
		NOT = {
			government_has_flag = government_is_tribal # No changing amenities above what's legal for tribals
		}
    }

    weight_multiplier = {
    	base = 1
    	modifier = {
        	factor = 2
        	average_amenity_level < medium_amenity_level
		}
		modifier = {
			factor = 2
			court_grandeur_current_level < court_grandeur_minimum_expected_level
		}
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_diplomatic }
    }

    immediate = {
    	random_parent = {
    		limit = {
	    		employer = ROOT
	    		is_available_ai_adult = yes
	    	}
	    	weight = {
	    		base = 1
	    		modifier = {
	    			factor = 2
	    			trigger_if = {
						limit = { is_female = yes }
						ROOT = { faith_dominant_gender_female_or_equal = yes }
					}
					trigger_else = { faith_dominant_gender_male_or_equal = yes }
	    		}
	    	}
	    	save_scope_as = parent
    	}
    	if = {
    		limit = {
    			any_parent = {
    				NOT = { THIS = scope:parent }
    				employer = ROOT
	    			is_available_ai_adult = yes
	    			is_married = yes
	    			primary_spouse = scope:parent
    			}
    		}
    		random_parent = {
    			limit = {
    				NOT = { THIS = scope:parent }
    				employer = ROOT
	    			is_available_ai_adult = yes
	    			is_married = yes
	    			primary_spouse = scope:parent
    			}
    			save_scope_as = other_parent
    		}
    	}
    	else = {
    		random_courtier_or_guest = {
       			limit = {
            		NOT = { THIS = scope:parent }
        		}
        		save_scope_as = other_parent # Fallback for court scene errors
    		}
		}	
    	random_list = {
    		2 = {
    			trigger = {
    				amenity_level = { type = court_fashion value < high_amenity_level }
    			}
    			set_variable = {
	        		name = court_8080_amenity
	        		value = 0
	        	}
    		}
    		2 = {
    			trigger = {
    				amenity_level = { type = court_servants value < high_amenity_level }
    			}
    			set_variable = {
	        		name = court_8080_amenity
	        		value = 1
	        	}
    		}
    		2 = {
    			trigger = {
    				amenity_level = { type = court_lodging_standards value < high_amenity_level }
    			}
    			set_variable = {
	        		name = court_8080_amenity
	        		value = 2
	        	}
        	}
    		2 = {
    			trigger = {
    				amenity_level = { type = court_food_quality value < high_amenity_level }
    			}
    			set_variable = {
	        		name = court_8080_amenity
	        		value = 3
	        	}
    		}
        }
    }

    option = { # Increase the amenity
		name = court.8080.a
		change_current_court_grandeur = medium_court_grandeur_gain
		trigger = { exists = var:court_8080_amenity }							   
		switch = {
			trigger = var:court_8080_amenity
			0 = {
				set_amenity_level = { type = court_fashion value = high_amenity_level }
			}
			1 = {
				set_amenity_level = { type = court_fashion value = high_amenity_level }
			}
			2 = {
				set_amenity_level = { type = court_fashion value = high_amenity_level }
			}
			3 = {
				set_amenity_level = { type = court_fashion value = high_amenity_level }
			}
		}
		reverse_add_opinion = {
			target = scope:parent
			modifier = pleased_opinion
			opinion = 10
		}
		stress_impact = {
			greedy = medium_stress_impact_gain # Expensive stuff
			stubborn = medium_stress_impact_gain # Things are fine
			lazy = medium_stress_impact_gain # Sounds like effort
			humble = medium_stress_impact_gain # Good enough for me
		}
		ai_chance = {
            base = 100
            ai_value_modifier = {
            	ai_greed = -1
            	ai_energy = -1
            }
            modifier = {	#Weight down for stress.
            	add = -15
            	has_trait = greedy       	
            }
            modifier = {	#Weight down for stress.
            	add = -15
            	has_trait = stubborn       	
            }
            modifier = {	#Weight down for stress.
            	add = -15
            	has_trait = lazy       	
            }
            modifier = {	#Weight down for stress.
            	add = -15
            	has_trait = humble       	
            }
        }
	}

	option = { # You think you are better than my courtiers?
		name = court.8080.b
		add_prestige = miniscule_prestige_gain
		reverse_add_opinion = {
			target = scope:parent
			modifier = annoyed_opinion
			opinion = -5
		}
		every_courtier = {
			limit = {
				NOT = { THIS = scope:parent }
			}
			custom = court.8080.b.tt
			add_opinion = {
				target = ROOT
				modifier = respect_opinion
				opinion = 5
			}
		}
		stress_impact = {
			arrogant = medium_stress_impact_gain # But they are better
			shy = medium_stress_impact_gain # Bad with people
			fickle = medium_stress_impact_gain # I go with the flow
		}
		ai_chance = {
            base = 100
            ai_value_modifier = {
            	ai_greed = -1
            	ai_boldness = 1
            }
            modifier = {	#Weight down for stress.
            	add = -15
            	has_trait = arrogant       	
            }
            modifier = {	#Weight down for stress.
            	add = -15
            	has_trait = shy       	
            }
        }
	}

	option = { # Convent time
		name = {
			trigger = {
				scope:parent = { is_female = yes }
				amenity_level = { type = court_fashion value < high_amenity_level }
			}
			text = court.8080.c.nun
		}
		name = {
			trigger = {
				scope:parent = { is_female = no }
				amenity_level = { type = court_servants value < high_amenity_level }
			}
			text = court.8080.c.monk
		}
		name = court.8080.c.fallback
		trigger = {
			scope:parent = {
				is_married = no
				NOT = { has_trait = devoted }
			}
		}
		add_piety = miniscule_piety_gain
		scope:parent = {
			add_trait = devoted
			add_opinion = {
				target = ROOT
				modifier = insulted_opinion
				opinion = -40
			}
		}
		stress_impact = {
			cynical = medium_stress_impact_gain # There is no god
			compassionate = medium_stress_impact_gain # A fate worse than death
		}
		ai_chance = {
            base = 100
            ai_value_modifier = {
            	ai_zeal = 2
            	ai_boldness = 1
            }
            modifier = {	#Weight down for stress.
            	add = -15
            	has_trait = cynical       	
            }
            modifier = {	#Weight down for stress.
            	add = -15
            	has_trait = compassionate       	
            }
        }
	}

	option = { # Why not help fix the issue?
		name = {
			trigger = { var:court_8080_amenity = 0 }
			text = court.8080.d.fashion
		}
		name = {
			trigger = { var:court_8080_amenity = 1 }
			text = court.8080.d.servants
		}
		name = {
			trigger = { var:court_8080_amenity = 2 }
			text = court.8080.d.lodgings
		}
		name = {
			trigger = { var:court_8080_amenity = 3 }
			text = court.8080.d.food
		}
		trigger = {
			exists = var:court_8080_amenity
			var:court_8080_amenity <= 2
		}					  
		add_dread = miniscule_dread_gain
		scope:parent = {
			add_character_modifier = {
				modifier = court_8080_degraded_modifier
				years = 2
			}
		}
		reverse_add_opinion = {
			target = scope:parent
			modifier = insulted_opinion
			opinion = -20
		}
		stress_impact = {
			arrogant = medium_stress_impact_gain # My parent deserves better
			compassionate = medium_stress_impact_gain # A fate worse than death
		}
		ai_chance = {
            base = 100
            ai_value_modifier = {
            	ai_vengefulness = 1
            	ai_boldness = 2
            }
            modifier = {	#Weight down for stress.
            	add = -15
            	has_trait = arrogant       	
            }
            modifier = {	#Weight down for stress.
            	add = -15
            	has_trait = compassionate       	
            }
        }
	}

	option = { # Oh my god mom!
		name = court.8080.e
		add_prestige = miniscule_prestige_loss
		reverse_add_opinion = {
			target = scope:parent
			modifier = insulted_opinion
			opinion = -10
		}
		stress_impact = {
			gregarious = medium_stress_impact_gain # I am good with people
			compassionate = major_stress_impact_gain # A fate worse than death
		}
		ai_chance = {
            base = 100
            ai_value_modifier = {
            	ai_vengefulness = 1
            	ai_boldness = 2
            }
            modifier = {	#Weight down for stress.
            	add = -15
            	has_trait = gregarious       	
            }
            modifier = {	#Weight down for stress.
            	add = -30
            	has_trait = compassionate       	
            }
        }
	}

	after = { remove_variable = court_8080_amenity }
}

#########################
# Building Blocks		#
# by Joe Parkin 		#
#########################

scripted_trigger court_8090_barony_trigger = {
	tier = tier_barony
	is_leased_out = no
	title_province.free_building_slots > 0
	NOT = { county = scope:my_county }
}

court.8090 = {
    type = court_event
    title = court.8090.t
    desc = {
    	desc = court.8090.desc.intro
    	first_valid = {
		    triggered_desc = {
		        trigger = {
					exists = scope:chaplain
					scope:chaplain = scope:architect
				}
		        desc = court.8090.desc.religious
		    }
		    desc = court.8090.desc.castle
    	}
    	desc = court.8090.desc.outro
	    first_valid = {
	    	triggered_desc = {
		        trigger = { exists = scope:chaplain }
		        desc = court.8090.desc.chaplain
		    }
		    desc = court.8090.desc.fallback
	    }
    }
    theme = court
    cooldown = { years = 10 }
    court_scene = {
        button_position_character = scope:architect
        roles = {
            scope:architect = {
                group = event_group
                animation = throne_room_chancellor
            }
            scope:steward = {
                group = event_group
                animation = throne_room_conversation_3
            }
        }
    }

    trigger = {
    	has_royal_court = yes
    	exists = cp:councillor_steward
    	cp:councillor_steward = {
    		is_available_ai_adult = yes
    		has_court_event_flag = no
    	}
    	employs_court_position = royal_architect_court_position
    	any_court_position_holder = {
    		type = royal_architect_court_position
    		is_available_ai_adult = yes
    		has_court_event_flag = no
    		NOT = { THIS = ROOT.cp:councillor_steward }
    	}
    	any_held_title = {
    		tier = tier_barony
    		is_leased_out = no
    		title_province.free_building_slots > 0
    	}
    }

    weight_multiplier = {
    	base = 1
    	ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_administrative }
		modifier = {
			factor = 2
			exists = cp:councillor_steward
	    	cp:councillor_steward = {
	    		is_available_ai_adult = yes
	    		has_trait = compassionate
	    	}
		}
    }

    immediate = {
    	random_court_position_holder = {
    		type = royal_architect_court_position
    		limit = { is_available_ai_adult = yes }
    		save_scope_as = architect
    		court_event_character_flag_effect = yes
    	}
		cp:councillor_steward = {
			save_scope_as = steward
			court_event_character_flag_effect = yes
		}
		ordered_held_title = { # Save barony with least buildings
			limit = {
				tier = tier_barony
				is_leased_out = no
    			title_province.free_building_slots > 0
			}
			order_by = {
				value = 0 
				subtract = title_province.combined_building_level
			}
			save_scope_as = my_barony
			county = { save_scope_as = my_county }
			scope:my_barony.title_province = { add_random_building_variable_effect = yes }
		}
		scope:my_county = { # Save church in same county
			ordered_county_province = {
				limit = {
					has_holding_type = church_holding
					free_building_slots > 0
				}
				order_by = free_building_slots
				barony = { save_scope_as = temple_barony }
				scope:temple_barony.title_province = { add_random_building_variable_effect = yes }
			}
		}
		if = { # Pick a second option if available
			limit = {
				any_held_title = { court_8090_barony_trigger = yes }
			}
			ordered_held_title = {
				limit = {
					court_8090_barony_trigger = yes 
					county = {
						any_neighboring_county = { THIS = scope:my_county }
					}
				}
				alternative_limit = { court_8090_barony_trigger = yes }
				order_by = {
					value = 0 
					subtract = title_province.combined_building_level
				}
				save_scope_as = backup_barony
				county = { save_scope_as = backup_county }
				scope:backup_barony.title_province = { add_random_building_variable_effect = yes }
			}
		}
		if = {
			limit = {
				exists = cp:councillor_court_chaplain
				NOT = { cp:councillor_court_chaplain = scope:architect }
				trigger_if = {
					limit = {
						NOT = { exists = scope:temple_barony }
					}
					any_held_title = {
						tier = tier_county
						any_county_province = {
							has_holding_type = church_holding
							free_building_slots > 0
						}
					}
				}
			}
			cp:councillor_court_chaplain = { save_scope_as = chaplain }
			if = {
				limit = {
					NOT = { exists = scope:temple_barony }
				}
				random_held_title = {
					limit = {
						tier = tier_county
						any_county_province = {
							has_holding_type = church_holding
							free_building_slots > 0
						}
					}
					random_county_province = {
						limit = {
							has_holding_type = church_holding
							free_building_slots > 0
						}
						barony = { save_scope_as = temple_barony }
						add_random_building_variable_effect = yes
					}
				}
			}
		}
    }

    option = { # For my barony
		name = court.8090.a
		remove_short_term_gold = court_8090_half_building_cost_value
		reverse_add_opinion = {
			target = scope:architect
			modifier = pleased_opinion
			opinion = 10
		}
		if = {
			limit = {
				exists = scope:chaplain
			}
			reverse_add_opinion = {
				target = scope:chaplain
				modifier = disappointed_opinion
				opinion = -5
			}
		}
		reverse_add_opinion = {
			target = scope:steward
			modifier = disappointed_opinion
			opinion = -5
		}
		scope:my_barony.title_province = { add_random_building_construct_effect = yes }
		stress_impact = {
			architect = medium_stress_impact_loss # A good idea
			lazy = medium_stress_impact_gain # Too much work
			greedy = medium_stress_impact_gain # It will cost _how_ much?
		}
		ai_chance = {
            base = 100
            ai_value_modifier = {
            	ai_greed = -1
            	ai_energy = 1
            }
            modifier = {	#Weight up.
            	add = 15
            	has_trait = architect       	
            }
            modifier = {	#Weight down for stress.
            	add = -15
            	has_trait = lazy       	
            }
            modifier = {	#Weight down for stress.
            	add = -15
            	has_trait = greedy       	
            }
        }
	}

	option = { # For the church
		name = court.8090.b
		trigger = {
			exists = scope:chaplain
			exists = scope:temple_barony
		}
		add_piety = minor_piety_value
		remove_short_term_gold = court_8090_half_building_cost_value
		reverse_add_opinion = {
			target = scope:chaplain
			modifier = pleased_opinion
			opinion = 10
		}
		reverse_add_opinion = {
			target = scope:architect
			modifier = disappointed_opinion
			opinion = -5
		}
		reverse_add_opinion = {
			target = scope:steward
			modifier = disappointed_opinion
			opinion = -5
		}
		scope:temple_barony.title_province = { add_random_building_construct_effect = yes }
		stress_impact = {
			architect = minor_stress_impact_loss # A good idea
			cynical = medium_stress_impact_gain # God needs no house
			greedy = medium_stress_impact_gain # It will cost _how_ much?
		}
		ai_chance = {
            base = 100
            ai_value_modifier = {
            	ai_vengefulness = 1
            	ai_boldness = 2
            }
            modifier = {	#Weight up.
            	add = 5
            	has_trait = architect       	
            }
            modifier = {	#Weight down for stress.
            	add = -15
            	has_trait = cynical       	
            }
            modifier = {	#Weight down for stress.
            	add = -15
            	has_trait = greedy       	
            }
        }
	}

	option = { # Elsweyr
		name = court.8090.c
		trigger = { exists = scope:backup_barony }
		remove_short_term_gold = court_8090_discount_building_cost_value
		reverse_add_opinion = {
			target = scope:architect
			modifier = pleased_opinion
			opinion = 5
		}
		if = {
			limit = {
				exists = scope:chaplain
			}
			reverse_add_opinion = {
				target = scope:chaplain
				modifier = disappointed_opinion
				opinion = -5
			}
		}
		reverse_add_opinion = {
			target = scope:steward
			modifier = disappointed_opinion
			opinion = -5
		}
		scope:backup_barony.title_province = { add_random_building_construct_effect = yes }
		stress_impact = {
			architect = minor_stress_impact_gain # A good idea
			lazy = major_stress_impact_gain # Too much work
			greedy = major_stress_impact_gain # It will cost _how_ much?
		}
		ai_chance = {
            base = 100
            ai_value_modifier = {
            	ai_greed = -2
            	ai_energy = 1
            }
            modifier = {	#Weight up.
            	add = 5
            	has_trait = architect       	
            }
            modifier = {	#Weight down for stress.
            	add = -30
            	has_trait = lazy       	
            }
            modifier = {	#Weight down for stress.
            	add = -30
            	has_trait = greedy       	
            }
        }
	}

	option = { # For the people
		name = court.8090.d
		reverse_add_opinion = {
			target = scope:steward
			modifier = pleased_opinion
			opinion = 10
		}
		reverse_add_opinion = {
			target = scope:architect
			modifier = disappointed_opinion
			opinion = -5
		}
		if = {
			limit = {
				exists = scope:chaplain
			}
			reverse_add_opinion = {
				target = scope:chaplain
				modifier = disappointed_opinion
				opinion = -5
			}
		}
		scope:my_barony.county = {
			add_county_modifier = {
				modifier = court_8090_commoners_modifier
				years = 5
			}
		}
		stress_impact = {
			architect = medium_stress_impact_gain # But my castle!
			callous = major_stress_impact_gain # The people? Pah
			diligent = major_stress_impact_gain # I can do it
		}
		ai_chance = {
            base = 100
            ai_value_modifier = {
            	ai_greed = -2
            	ai_energy = 1
            }
            modifier = {	#Weight down for stress.
            	add = -15
            	has_trait = architect       	
            }
            modifier = {	#Weight down for stress.
            	add = -30
            	has_trait = callous       	
            }
            modifier = {	#Weight down for stress.
            	add = -30
            	has_trait = diligent       	
            }
        }
	}

	after = {
		if = {
			limit = {
				exists = scope:my_barony
				scope:my_barony.title_province = { has_variable = random_building_variable }
			}
			scope:my_barony.title_province = { remove_variable = random_building_variable }
		}
		if = {
			limit = {
				exists = scope:temple_barony
				scope:temple_barony.title_province = { has_variable = random_building_variable }
			}
			scope:temple_barony.title_province = { remove_variable = random_building_variable }
		}
		if = {
			limit = {
				exists = scope:backup_barony
				scope:backup_barony.title_province = { has_variable = random_building_variable }
			} 
			scope:backup_barony.title_province = { remove_variable = random_building_variable }
		}
		scope:steward = {
			clear_court_event_participation = yes
		}
		scope:architect = {
			clear_court_event_participation = yes
		}
	}
}



#########################
# Upon the Block		#
# by Joe Parkin 		#
#########################

scripted_trigger court_8110_prisoner_trigger = {
	NOT = { is_close_or_extended_family_of = ROOT }
	OR = {
		ROOT = { has_execute_reason = PREV }
		has_trait = peasant_leader
		NOT = { faith = ROOT.faith }
	}
	OR = {
		AND = {
			is_lowborn = no
			liege = ROOT
    	}
		is_lowborn = yes
	}
	is_human = yes
}

court.8110 = {
    type = court_event
    title = court.8110.t
    desc = {
    	desc = court.8110.desc.intro
    	first_valid = {
    	    triggered_desc = {
    	        trigger = {
    	        	scope:prisoner_1 = { has_trait = peasant_leader }
    	        }
    	        desc = court.8110.desc.leader_1
    	    }
    	    triggered_desc = {
    	        trigger = {
    	        	scope:prisoner_1 = {
    	        		NOT = { faith = ROOT.faith }
    	        		religion = ROOT.religion
    	        	}
    	        }
    	        desc = court.8110.desc.heretic
    	    }
    	    triggered_desc = {
    	        trigger = {
    	        	#AGOT Disabled
    	        	# NOT = {
    	        	# 	religion = { is_in_family = rf_pagan }
    	        	# }
    	        	scope:prisoner_1 = {
    	        		NOT = { religion = ROOT.religion }
    	        		#AGOT Disabled
    	        		# religion = { is_in_family = rf_pagan }
    	        	}
    	        }
    	        desc = court.8110.desc.heathen
    	    }
    	    #AGOT Disabled
    	    # triggered_desc = {
    	    #     trigger = {
    	    #     	NOT = { scope:prisoner_1.religion = ROOT.religion }
    	    #     }
    	    #     desc = court.8110.desc.infidel
    	    # }
    	    triggered_desc = {
    	        trigger = {
    	        	scope:prisoner_1 = {
    	        		employer = ROOT
    	        		is_lowborn = no
    	        		NOT = { is_close_or_extended_family_of = ROOT }
    	        	}
    	        }
    	        desc = court.8110.desc.noble
    	    }
    	    desc = court.8110.desc.fallback
    	}
    	desc = court.8110.desc.body
    	first_valid = {
    		triggered_desc = {
    	        trigger = {
    	        	scope:prisoner = {
    	        		OR = {
    	        			AND = { # Heretic
    	        				NOT = { faith = ROOT.faith }
    	        				religion = ROOT.religion
    	        			}
    	        			AND = { # Heathen
    	        				#AGOT Disabled
    	        				# NOT = {
			    	        	# 	ROOT.religion = { is_in_family = rf_pagan }
			    	        	# }
			    	        	NOT = { religion = ROOT.religion }
			    	        	#AGOT Disabled
			    	        	# religion = { is_in_family = rf_pagan }
			    	        }
			    	        #AGOT Disabled
			    	        # NOT = { religion = ROOT.religion } # Infidel
    	        		}
    	        	}
    	        }
    	        desc = court.8110.desc.religious
    	    }
    	    triggered_desc = {
    	        trigger = {
    	        	scope:prisoner_1 = { has_trait = peasant_leader }
    	        }
    	        desc = court.8110.desc.leader_2
    	    }
    	    desc = court.8110.desc.criminal
    	}
    }
    theme = court
    cooldown = { years = 10 }
    court_scene = {
        button_position_character = scope:my_executioner
        roles = {
            scope:my_executioner = {
                group = event_group
                animation = throne_room_chancellor
            }
            scope:prisoner_1 = {
                group = event_group
                animation = prisonhouse
            }
        }
    }

    trigger = {
    	employs_court_position = executioner_court_position
    	any_court_position_holder = {
    		type = executioner_court_position
    		is_available_ai_adult = yes
    		has_court_event_flag = no
    		faith = ROOT.faith
    		NOT = { has_trait = compassionate }
    		save_temporary_scope_as = executioner_temp
    	}
    	any_prisoner = {
    		court_8110_prisoner_trigger = yes
    		has_court_event_flag = no
    		NOT = { is_close_or_extended_family_of = scope:executioner_temp }
    	}
    }

    weight_multiplier = {
        base = 1
        modifier = {
        	factor = 2
        	any_prisoner = {
        		count > 3
	    		court_8110_prisoner_trigger = yes
	    	}
        }
    }

    immediate = {
    	random_court_position_holder = {
    		type = executioner_court_position
    		limit = {
	    		is_available_ai_adult = yes
	    		NOT = { has_trait = compassionate }
    		}
    		save_scope_as = my_executioner
    		court_event_character_flag_effect = yes
    		assign_quirk_effect = yes
    	}
    	random_prisoner = {
    		limit = {
    			court_8110_prisoner_trigger = yes
    			NOT = { is_close_or_extended_family_of = scope:my_executioner }
    		}
    		weight = {
    			base = 1
    			modifier = {
    				factor = 2
    				has_trait = peasant_leader
    			}
    		}
    		save_scope_as = prisoner_1
    		court_event_character_flag_effect = yes
    	}
    	if = {
    		limit = {
    			any_prisoner = {
    				court_8110_prisoner_trigger = yes
    				NOT = { is_close_or_extended_family_of = scope:my_executioner }
    				NOT = { THIS = scope:prisoner_1 }
    			}
    		}
    		random_prisoner = {
    			limit = {
    				court_8110_prisoner_trigger = yes
    				NOT = { is_close_or_extended_family_of = scope:my_executioner }
    				NOT = { THIS = scope:prisoner_1 }
    			}
	    		weight = {
	    			base = 1
	    			modifier = {
	    				factor = 2
	    				has_trait = peasant_leader
	    			}
	    		}
	    		save_scope_as = prisoner_2
    		}
    	}
    }

    option = { # Execute prisoner 
        name = court.8110.a
        change_current_court_grandeur = minor_court_grandeur_gain
       	execute_prisoner_effect = {
			VICTIM = scope:prisoner_1
			EXECUTIONER = ROOT
		}
		reverse_add_opinion = {
			target = scope:my_executioner
			modifier = pleased_opinion
			opinion = 10
		}
        ai_chance = {
            base = 100
            ai_value_modifier = {
            	ai_greed = 0.5
            	ai_compassion = 1
            }
        }
    }

    option = { # Execute another prisoner
        name = court.8110.b
        trigger = { exists = scope:prisoner_2 }
        change_current_court_grandeur = minor_court_grandeur_gain
        execute_prisoner_effect = {
			VICTIM = scope:prisoner_2
			EXECUTIONER = ROOT
		}
		reverse_add_opinion = {
			target = scope:my_executioner
			modifier = pleased_opinion
			opinion = 5
		}
        ai_chance = {
            base = 100
            ai_value_modifier = {
            	ai_greed = 0.5
            	ai_compassion = 1
            }
        }
    }

    option = { # You are a criminal yourself
        name = court.8110.c
        flavor = court.8110.c.flavor
        reverse_add_opinion = {
			target = scope:my_executioner
			modifier = humbled_opinion
			opinion = -10
		}
		reverse_add_opinion = {
			target = scope:prisoner_1
			modifier = grateful_opinion
				opinion = 10
		}
		if = {
			limit = { exists = scope:prisoner_2 }
			reverse_add_opinion = {
				target = scope:prisoner_2
				modifier = grateful_opinion
				opinion = 10
			}
		}		
        ai_chance = {
            base = 100
            ai_value_modifier = {
            	ai_greed = 0.5
            	ai_compassion = 1
            }
        }
	}

	option = { # You enjoy this too much
        name = court.8110.d
        revoke_court_position = {
			court_position = executioner_court_position
			recipient = scope:my_executioner
		}
        reverse_add_opinion = {
			target = scope:my_executioner
			modifier = disappointed_opinion
			opinion = -20
		}
		reverse_add_opinion = {
			target = scope:prisoner_1
			modifier = grateful_opinion
			opinion = 10
		}
		if = {
			limit = { exists = scope:prisoner_2 }
			reverse_add_opinion = {
				target = scope:prisoner_2
				modifier = grateful_opinion
				opinion = 10
			}
		}	
        ai_chance = {
            base = 100
            ai_value_modifier = {
            	ai_greed = 0.5
            	ai_compassion = 1
            }
        }
	}

    option = { # Dismiss
        name = court.8110.e
        reverse_add_opinion = {
			target = scope:my_executioner
			modifier = disappointed_opinion
			opinion = -10
		}
		stress_impact = {
			callous = medium_stress_impact_gain
			arbitrary = medium_stress_impact_gain
		}
        ai_chance = {
            base = 100
            ai_value_modifier = {
            	ai_compassion = 1
            	ai_honor = 1
            }
        }
    }
    after = {
    	scope:my_executioner = {
    		clear_court_event_participation = yes
    	}
    	scope:prisoner_1 = {
    		clear_court_event_participation = yes
    	}
    }
}

#########################
# Contrived Conflicts	#
# by Joe Parkin 		#
#########################

scripted_trigger court_8130_champion_trigger = {
	is_available_healthy_ai_adult = yes
	NOR = {
		has_trait = forgiving
		has_trait = honest
		has_trait = calm
	}
}

scripted_trigger court_8130_vassal_trigger = {
	primary_title.tier < tier_kingdom
	is_adult = yes
	opinion = {
		target = ROOT
		value < 50
	}
	NOR = {
		is_close_family_of = ROOT
		has_relation_friend = ROOT
	}
	trigger_if = {
		limit = {
			NOT = {
				ROOT.faith = { has_doctrine = doctrine_gender_equal }
			}
		}
		OR = {
			AND = {
				ROOT.faith = { has_doctrine = doctrine_gender_female_dominated }
				is_female = yes
			}
			AND = {
				ROOT.faith = { has_doctrine = doctrine_gender_male_dominated }
				is_male = yes
			}
		}
	}
}

court.8130 = {
    type = court_event
    title = court.8130.t
    desc = {
    	desc = court.8130.desc.intro
    	first_valid = {
		    triggered_desc = {
		        trigger = {
		        	scope:vassal = {
		        		OR = {
		        			has_trait = craven
		        			has_trait = shy
		        		}
		        	}
		        }
		        desc = court.8130.desc.craven
		    }
		    desc = court.8130.desc.bold
		}
	    desc = court.8130.desc.outro
    }
    theme = court
    cooldown = { years = 10 }
    court_scene = {
        button_position_character = scope:champion
        roles = {
            scope:champion = {
                group = event_group
                animation = rage
            }
            scope:vassal = {
                group = event_group
                animation = throne_room_conversation_4
            }
            scope:mediator = {
                group = event_group
                animation = beg
            }
        }
    }

    trigger = {
    	employs_court_position = champion_court_position
		any_court_position_holder = {
			type = champion_court_position
			court_8130_champion_trigger = yes
			has_court_event_flag = no
			save_temporary_scope_as = champion_temp
		}
		any_vassal = {
			NOR = {
				THIS = scope:champion_temp
				is_close_family_of = scope:champion_temp
				has_relation_friend = scope:champion_temp
				has_relation_rival = scope:champion_temp
			}
			court_8130_vassal_trigger = yes
			has_court_event_flag = no
		}
    }

    weight_multiplier = {
    	base = 1
    	# Court weightings.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_warlike }
    	modifier = {
    		factor = 2
    		any_court_position_holder = {
				type = champion_court_position
				court_8130_champion_trigger = yes
				OR = {
					has_trait = vengeful
					has_trait = wrathful
					faith = { has_doctrine = tenet_warmonger }
				}
			}
		}
    }

    immediate = {
    	set_signature_weapon_effect = yes
    	ordered_court_position_holder = {
    		type = champion_court_position
    		limit = { court_8130_champion_trigger = yes }
	    	order_by = prowess
	    	save_scope_as = champion
	    	court_event_character_flag_effect = yes
    	}
    	random_vassal = {
			limit = {
				NOR = {
					THIS = scope:champion
					is_close_family_of = scope:champion
					has_relation_friend = scope:champion
					has_relation_rival = scope:champion
				}
				court_8130_vassal_trigger = yes
			}
			weight = {
				base = 1
				modifier = {
					factor = 10
					has_trait = craven
				}
				modifier = {
					factor = 10
					has_trait = shy
				}
				modifier = {
					factor = 5
					primary_title.tier = tier_county
				}
				modifier = {
					factor = 10
					primary_title.tier = tier_barony
				}
			}
			save_scope_as = vassal
			court_event_character_flag_effect = yes
			assign_quirk_effect = yes
		}
    	if = {
    		limit = {
    			exists = cp:councillor_chancellor
    			NOR = {
    				cp:councillor_chancellor = scope:champion
    				cp:councillor_chancellor = scope:vassal
    			}
    		}
    		cp:councillor_chancellor = {
    			save_scope_as = mediator
    			court_event_character_flag_effect = yes
    			}
    	}
    	else = {
    		ordered_courtier = {
    			limit = {
    				NOR = {
    					THIS = scope:champion
    					THIS = scope:vassal
    				}
    			}
    			order_by = diplomacy
    			save_scope_as = mediator
    			court_event_character_flag_effect = yes
    		}
    	}
    	scope:champion = {
    		progress_towards_rival_effect = {
				CHARACTER = scope:vassal
				REASON = rival_perceived_slight
				OPINION = 0
			}
    	}
    	hidden_effect = {
    		scope:champion = {
    			add_opinion = {
					target = scope:vassal
					modifier = angry_opinion
					opinion = -20
				}
    			reverse_add_opinion = {
					target = scope:vassal
					modifier = insulted_opinion
					opinion = -20
				}
    		}
    	}
    }

    option = { # Allow duel
        name = court.8130.a
        scope:vassal = {
        	if = {
	        	limit = {
	        		OR = {
	        			has_trait = craven
	        			has_trait = shy
	        		}
	        	}
	        	add_opinion = {
					target = ROOT
					modifier = angry_opinion
					opinion = -15
				}
	        }
	        else_if = {
	        	limit = {
	        		NOR = {
	        			has_trait = brave
	        			has_trait = arrogant
		        	}
		        }
		        add_opinion = {
					target = ROOT
					modifier = disappointed_opinion
					opinion = -10
				}
		    }
		}
        reverse_add_opinion = {
			target = scope:champion
			modifier = pleased_opinion
			opinion = 10
		}
		custom_tooltip = court.8130.a.tt
		show_as_tooltip = {
			scope:vassal = {
				set_relation_rival = {
					target = scope:champion
					reason = rival_insult_and_duel
				}
			}
			random_list = {
				2 = {
					show_chance = no
					desc = court.8130.a.tt_champion
					scope:champion = { add_prestige = medium_prestige_gain }
					scope:vassal = {
						increase_wounds_effect = { REASON = duel }
					}
				}
				2 = {
					show_chance = no
					desc = court.8130.a.tt_vassal
					scope:vassal = { add_prestige = medium_prestige_gain }
					scope:champion = {
						increase_wounds_effect = { REASON = duel }
					}
				}
			}
		}
		configure_start_single_combat_effect = {
			SC_INITIATOR = scope:champion
			SC_ATTACKER = scope:champion
			SC_DEFENDER = scope:vassal
			FATALITY = no
			FIXED = no
			LOCALE = throne_room
			OUTPUT_EVENT = court.8131
			INVALIDATION_EVENT = fp1_tbc.0102 
		}
		if = {
			limit = {
				has_court_type = court_warlike
			}
			change_current_court_grandeur = medium_court_grandeur_gain
		}
		stress_impact = {
			gallant = medium_stress_impact_loss
			just = medium_stress_impact_gain
			patient = medium_stress_impact_gain
			forgiving = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
		}
		ai_chance = {
        	base = 100
        	ai_value_modifier = {
				ai_compassion = -1
				ai_honor = -1
			}
			modifier = { # Weight up.
        		add = 30
        		has_trait = gallant
        	}
        	modifier = { # Weight down for stress.
        		add = -15
        		has_trait = just
        	}
        	modifier = { # Weight down for stress.
        		add = -15
        		has_trait = patient
        	}
        	modifier = { # Weight down for stress.
        		add = -15
        		has_trait = forgiving
        	}
        	modifier = { # Weight down for stress.
        		add = -15
        		has_trait = compassionate
        	}
        }
    }

    option = { # Side with vassal
        name = court.8130.b
        reverse_add_opinion = {
			target = scope:vassal
			modifier = respect_opinion
			opinion = 10
		}
		reverse_add_opinion = {
			target = scope:mediator
			modifier = respect_opinion
			opinion = 5
		}
        reverse_add_opinion = {
			target = scope:champion
			modifier = disappointed_opinion
			opinion = -10
		}
		stress_impact = {
			arbitrary = medium_stress_impact_gain
			wrathful = medium_stress_impact_gain
			vengeful = medium_stress_impact_gain
			callous = medium_stress_impact_gain
		}
		ai_chance = {
        	base = 100
        	ai_value_modifier = {
				ai_compassion = 0.5
				ai_honor = 0.5
			}
        	modifier = { # Weight down for stress.
        		add = -15
        		has_trait = arbitrary
        	}
        	modifier = { # Weight down for stress.
        		add = -15
        		has_trait = wrathful
        	}
        	modifier = { # Weight down for stress.
        		add = -15
        		has_trait = vengeful
        	}
        	modifier = { # Weight down for stress.
        		add = -15
        		has_trait = callous
        	}
        }
    }

    option = { # Remove champion
        name = court.8130.c
        reverse_add_opinion = {
			target = scope:champion
			modifier = angry_opinion
			opinion = -20
		}
		revoke_court_position = {
			court_position = champion_court_position
			recipient = scope:champion
		}
		scope:champion = {
			if = {
				limit = { has_relation_friend = ROOT }
				remove_relation_friend = ROOT
			}
			progress_towards_rival_effect = {
				CHARACTER = ROOT
				REASON = rival_perceived_slight_root
				OPINION = 0
			}
		}
		reverse_add_opinion = {
			target = scope:vassal
			modifier = pleased_opinion
			opinion = 15
		}
		reverse_add_opinion = {
			target = scope:mediator
			modifier = pleased_opinion
			opinion = 5
		}
		stress_impact = {
			arbitrary = massive_stress_impact_gain
			wrathful = massive_stress_impact_gain
			vengeful = massive_stress_impact_gain
			callous = massive_stress_impact_gain
		}
		ai_chance = {
        	base = 100
        	ai_value_modifier = {
				ai_compassion = 1
				ai_honor = 1
			}
        	modifier = { # Weight down for stress.
        		add = -30
        		has_trait = arbitrary
        	}
        	modifier = { # Weight down for stress.
        		add = -30
        		has_trait = wrathful
        	}
        	modifier = { # Weight down for stress.
        		add = -30
        		has_trait = vengeful
        	}
        	modifier = { # Weight down for stress.
        		add = -30
        		has_trait = callous
        	}
        }
    }

    option = { # Duel vassal
        name = court.8130.d
        scope:vassal = {
        	if = {
	        	limit = {
	        		OR = {
	        			has_trait = craven
	        			has_trait = shy
	        		}
	        	}
	        	add_opinion = {
					target = ROOT
					modifier = insulted_opinion
					opinion = -20
				}
	        }
	        else_if = {
	        	limit = {
	        		OR = {
	        			has_trait = brave
	        			has_trait = arrogant
		        	}
		        }
		        add_opinion = {
					target = ROOT
					modifier = insulted_opinion
					opinion = -10
				}
		    }
		    else = {
		    	add_opinion = {
					target = ROOT
					modifier = insulted_opinion
					opinion = -15
				}
		    }
		}
		reverse_add_opinion = {
			target = scope:champion
			modifier = respect_opinion
			opinion = 10
		}
		reverse_add_opinion = {
			target = scope:mediator
			modifier = disappointed_opinion
			opinion = -5
		}
		custom_tooltip = court.8130.d.tt
		show_as_tooltip = {
			random_list = {
				2 = {
					show_chance = no
					desc = court.8130.b.tt_me
					add_prestige = medium_prestige_gain
					scope:vassal = {
						increase_wounds_effect = { REASON = duel }
					}
				}
				2 = {
					show_chance = no
					desc = court.8130.a.tt_vassal
					scope:vassal = { add_prestige = medium_prestige_gain }
					ROOT = {
						increase_wounds_effect = { REASON = duel }
					}
				}
			}
		}
		configure_start_single_combat_effect = {
			SC_INITIATOR = ROOT
			SC_ATTACKER = ROOT
			SC_DEFENDER = scope:vassal
			FATALITY = no
			FIXED = no
			LOCALE = throne_room
			OUTPUT_EVENT = court.8131
			INVALIDATION_EVENT = fp1_tbc.0102 
		}
		stress_impact = {
			lifestyle_blademaster = medium_stress_impact_loss
			just = medium_stress_impact_gain
			calm = medium_stress_impact_gain
			forgiving = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
			patient = medium_stress_impact_gain
		}
		if = {
			limit = {
				has_court_type = court_warlike
			}
			change_current_court_grandeur = medium_court_grandeur_gain
		}
		ai_chance = {
        	base = 100
        	ai_value_modifier = {
				ai_compassion = -1
				ai_honor = -1
				ai_boldness = 1
				ai_energy = 1
				ai_vengefulness = 1
			}
			modifier = { # Weight up.
        		add = 30
        		has_trait = lifestyle_blademaster
        	}
        	modifier = { # Weight down for stress.
        		add = -5
        		has_trait = just
        	}
        	modifier = { # Weight down for stress.
        		add = -5
        		has_trait = calm
        	}
        	modifier = { # Weight down for stress.
        		add = -5
        		has_trait = forgiving
        	}
        	modifier = { # Weight down for stress.
        		add = -5
        		has_trait = compassionate
        	}
        	modifier = { # Weight down for stress.
        		add = -5
        		has_trait = patient
        	}
        }
    }

    option = { # Stop duel
        name = court.8130.e
        reverse_add_opinion = {
			target = scope:champion
			modifier = disappointed_opinion
			opinion = -10
		}
        scope:vassal = {
        	if = {
	        	limit = {
	        		OR = {
	        			has_trait = craven
	        			has_trait = shy
	        		}
	        	}
	        	add_opinion = {
					target = ROOT
					modifier = grateful_opinion
					opinion = 10
				}
	        }
	        else_if = {
	        	limit = {
	        		OR = {
	        			has_trait = brave
	        			has_trait = arrogant
		        	}
		        }
		        add_opinion = {
					target = ROOT
					modifier = disappointed_opinion
					opinion = -5
				}
		    }
		    else = {
		    	add_opinion = {
					target = ROOT
					modifier = grateful_opinion
					opinion = 5
				}
		    }
		}
		if = {
			limit = {
				scope:vassal = {
					NOR = {
	        			has_trait = brave
	        			has_trait = arrogant
		        	}
				}
				can_add_hook = {
					target = scope:vassal
					type = favor_hook
				}
			}
			add_hook = {
				type = favor_hook
				target = scope:vassal
				days = default_favor_duration
			}
		}
		reverse_add_opinion = {
			target = scope:mediator
			modifier = respect_opinion
			opinion = 5
		}
		stress_impact = {
			diplomat = medium_stress_impact_loss
			arbitrary = minor_stress_impact_gain
			wrathful = minor_stress_impact_gain
			vengeful = minor_stress_impact_gain
			callous = minor_stress_impact_gain
		}
		if = {
			limit = {
				has_court_type = court_warlike
			}
			change_current_court_grandeur = medium_court_grandeur_gain
		}
		ai_chance = {
        	base = 100
        	ai_value_modifier = {
				ai_compassion = 1
				ai_rationality = 1
			}
			modifier = { # Weight up.
        		add = 30
        		has_trait = diplomat
        	}
        	modifier = { # Weight down for stress.
        		add = -5
        		has_trait = arbitrary
        	}
        	modifier = { # Weight down for stress.
        		add = -5
        		has_trait = wrathful
        	}
        	modifier = { # Weight down for stress.
        		add = -5
        		has_trait = vengeful
        	}
        	modifier = { # Weight down for stress.
        		add = -5
        		has_trait = callous
        	}
        }
    }
    after = {
    	scope:champion = {
    		clear_court_event_participation = yes
    	}
    	scope:vassal = {
    		clear_court_event_participation = yes
    	}
    	scope:mediator = {
    		clear_court_event_participation = yes
    	}
    }
}

court.8131 = {
	hidden = yes

	immediate = {
		scope:vassal.liege = {
			send_interface_toast = {
				title = hold_court.8031.t
				left_icon = scope:sc_victor
				right_icon = scope:sc_loser
				scope:sc_victor = { add_prestige = medium_prestige_gain }
			}
		}
	}
}

#########################
# Royal Lapse 			#
# by Joe Parkin 		#
#########################

court.8140 = {
    type = court_event
    title = court.8140.t
    desc = court.8140.desc
    theme = court
    cooldown = { years = 10 }
    court_scene = {
        button_position_character = scope:vassal
        roles = {
            scope:vassal = {
                group = event_group
                animation = throne_room_kneel_2
            }
            scope:courtier = {
                group = event_group
                animation = throne_room_conversation_4
            }
        }
    }

    trigger = {
    	has_a_stress_coping_trait_trigger = yes
    	any_vassal = {
    		is_available_ai_adult = yes
    		has_court_event_flag = no
    		save_temporary_scope_as = vassal_temp
    	}
    	any_courtier_or_guest = {
    		is_available_ai_adult = yes
    		has_court_event_flag = no
    		NOT = { THIS = scope:vassal_temp }
    	}
    }

    weight_multiplier = {
    	base = 1
    	modifier = {
    		factor = 2
    		has_two_stress_coping_traits_trigger = yes
    	}
    	modifier = {
    		factor = 2
    		stress_level > 1
    	}
    }

    immediate = {
    	random_vassal = {
	    	limit = { is_available_ai_adult = yes }
	    	weight = {
	    		base = 1
	    		modifier = {
	    			factor = 10
	    			is_councillor = yes
	    		}
	    	}
	    	save_scope_as = vassal
	    	court_event_character_flag_effect = yes
	    }
	    random_courtier_or_guest = {
	    	limit = {
	    		is_available_ai_adult = yes
	    		NOT = { THIS = scope:vassal }
	    	}
	    	save_scope_as = courtier
	    	court_event_character_flag_effect = yes
	    }
    }

    option = { # Make an effort
        name = court.8140.a
        flavor = court.8140.a.flavor_tt
        stress_impact = {
        	base = minor_stress_impact_gain
        	fickle = medium_stress_impact_gain
        	callous = medium_stress_impact_gain
        	arbitrary = medium_stress_impact_gain
        	lazy = medium_stress_impact_gain
        }
        ai_chance = {
        	base = 20
        	ai_value_modifier = {
				ai_compassion = 2
				ai_energy = 1
			}
        	modifier = { # Weight down for stress.
        		add = -15
        		has_trait = fickle
        	}
        	modifier = { # Weight down for stress.
        		add = -15
        		has_trait = callous
        	}
        	modifier = { # Weight down for stress.
        		add = -15
        		has_trait = arbitrary
        	}
        	modifier = { # Weight down for stress.
        		add = -15
        		has_trait = lazy
        	}
        }
    }

    option = { # That is enough for today
        name = court.8140.b
        flavor = court.8140.b.flavor_tt
        change_current_court_grandeur = massive_court_grandeur_loss
        scope:courtier = {
        	add_opinion = {
        		target = ROOT
        		modifier = annoyed_opinion
        		opinion = -15
        	}
        }
        scope:vassal = {
        	add_opinion = {
        		target = ROOT
        		modifier = annoyed_opinion
        		opinion = -15
        	}
        }
        stress_impact = {
        	base = minor_stress_impact_loss
        	just = medium_stress_impact_gain
        	compassionate = medium_stress_impact_gain
        	diligent = medium_stress_impact_gain
        }
        ai_chance = {
        	base = 100
        	ai_value_modifier = {
				ai_compassion = -1
				ai_energy = -1
			}
        	modifier = { # Weight down for stress.
        		add = -15
        		has_trait = just
        	}
        	modifier = { # Weight down for stress.
        		add = -15
        		has_trait = compassionate
        	}
        	modifier = { # Weight down for stress.
        		add = -15
        		has_trait = diligent
        	}
        }
    }

    option = { # Give in
        name = court.8140.c
        flavor = court.8140.c.flavor_tt
        change_current_court_grandeur = medium_court_grandeur_loss
    	reverse_add_opinion = {
    		target = scope:courtier
    		modifier = annoyed_opinion
    		opinion = -5
    	}
    	reverse_add_opinion = {
    		target = scope:vassal
    		modifier = annoyed_opinion
    		opinion = -5
    	}
        stress_impact = {
        	base = miniscule_stress_impact_loss
        	just = minor_stress_impact_gain
        	compassionate = minor_stress_impact_gain
        	diligent = minor_stress_impact_gain
        }
        ai_chance = {
        	base = 100
        	ai_value_modifier = {
				ai_compassion = -0.5
				ai_energy = -0.5
			}
        	modifier = { # Weight down for stress.
        		add = -5
        		has_trait = just
        	}
        	modifier = { # Weight down for stress.
        		add = -5
        		has_trait = compassionate
        	}
        	modifier = { # Weight down for stress.
        		add = -5
        		has_trait = diligent
        	}
        }
    }
    after = {
    	scope:vassal = {
    		clear_court_event_participation = yes
    	}
    	scope:courtier = {
    		clear_court_event_participation = yes
    	}
    }
}

#########################
# Prandial Excess		#
# by Joe Parkin 		#
#########################

scripted_trigger court_8150_foodie_trigger = {
	NOR = {
		has_trait = temperate
		has_trait = inappetetic
	}
	is_human = yes
}

scripted_trigger court_8150_vassal_trigger = {
	is_available_ai_adult = yes
	court_8150_foodie_trigger = yes
	trigger_if = {
		limit = { exists = scope:chaplain }
		NOT = { THIS = scope:chaplain }
	}
	trigger_if = {
		limit = { exists = scope:food_taster }
		NOT = { THIS = scope:food_taster }
	}
	#AGOT Disabled
	# trigger_if = {
	# 	limit = { exists = scope:high_almoner }
	# 	NOT = { THIS = scope:high_almoner }
	# }
	trigger_if = {
		limit = { exists = scope:vassal_1 }
		NOT = { THIS = scope:vassal_1 }
	}
	trigger_if = {
		limit = { exists = scope:vassal_2 }
		NOT = { THIS = scope:vassal_2 }
	}
}

court.8150 = {
    type = court_event
    title = court.8150.t
    desc = {
    	desc = court.8150.desc.intro
    	triggered_desc = {
			trigger = { exists = scope:food_taster }
			desc = court.8150.desc.taster
		}
    	desc = court.8150.desc.body
    	first_valid = {
    		#AGOT Disabled
    		# triggered_desc = {
    		# 	trigger = {
    		# 		exists = scope:high_almoner
    		# 		exists = scope:chaplain
    		# 	}
    		# 	desc = court.8150.desc.almoner_chaplain
    		# }
    		triggered_desc = {
    			trigger = { exists = scope:chaplain }
    			desc = court.8150.desc.chaplain
    		}
    		#AGOT Disabled
    		# triggered_desc = {
    		# 	trigger = { exists = scope:high_almoner }
    		# 	desc = court.8150.desc.almoner
    		# }
    	}
    }
    theme = court
    cooldown = { years = 10 }
    court_scene = {
        button_position_character = scope:vassal_1
        roles = {
            scope:vassal_1 = {
                group = event_group
                animation = throne_room_conversation_1
            }
            scope:vassal_2 = {
                group = event_group
                animation = throne_room_conversation_2
            }
            scope:vassal_3 = {
                group = event_group
                animation = throne_room_conversation_3
            }
        }
    }

    trigger = {
    	amenity_level = { type = court_food_quality value >= high_amenity_level }
    	OR = {
    		AND = {
    			is_married = yes
    			primary_spouse = {
    				court_8150_vassal_trigger = yes
    				has_court_event_flag = no
    			}
    			any_courtier_or_guest = {
    				count >= 2
					court_8150_foodie_trigger = yes
					has_court_event_flag = no
    			}
    		}
    		any_courtier_or_guest = {
				count >= 3
				court_8150_foodie_trigger = yes
				has_court_event_flag = no
			}
    	}
    }

    weight_multiplier = {
        base = 1
        modifier = {
        	factor = 2
        	amenity_level = { type = court_food_quality value > very_high_amenity_level }
        }
    }

    immediate = {
 		if = {
 			limit = { court_8150_foodie_trigger = yes }
 			hidden_effect = { change_current_weight = 10 }
 		}
    	if = {
    		limit = {
    			exists = cp:councillor_court_chaplain
    			cp:councillor_court_chaplain = {
    				is_available_ai_adult = yes
    				NOR = {
    					has_trait = gluttonous
		        		faith = { has_doctrine = tenet_hedonistic }
						faith = { has_doctrine = tenet_carnal_exaltation }
		        	}
    			}
    		}
    		cp:councillor_court_chaplain = { save_scope_as = chaplain }
 		}
 		#AGOT Disabled
 		# if = {
    	# 	limit = {
    	# 		employs_court_position = high_almoner_court_position
		# 		any_court_position_holder = {
		# 			type = high_almoner_court_position
		# 			is_available_ai_adult = yes
		# 			NOR = {
		# 				has_trait = gluttonous
		# 				faith = { has_doctrine = tenet_hedonistic }
		# 				faith = { has_doctrine = tenet_carnal_exaltation }
		# 			}
		# 			trigger_if = {
		# 				limit = { exists = scope:chaplain }
		# 				NOT = { this = scope:chaplain }
		# 			}
		# 		}
    	# 	}
    	# 	random_court_position_holder = {
		# 		type = high_almoner_court_position
		# 		limit = {
		# 			is_available_healthy_ai_adult = yes
		# 			NOR = {
		# 				has_trait = gluttonous
		# 				faith = { has_doctrine = tenet_hedonistic }
		# 				faith = { has_doctrine = tenet_carnal_exaltation }
		# 			}
		# 			trigger_if = {
		# 				limit = { exists = scope:chaplain }
		# 				NOT = { this = scope:chaplain }
		# 			}
		#         }
		# 		save_scope_as = high_almoner
		# 	}
    	# }
    	if = {
    		limit = {
    			employs_court_position = food_taster_court_position
				any_court_position_holder = {
					type = food_taster_court_position
					is_available_healthy_ai_adult = yes
				}
    		}
    		random_court_position_holder = {
				type = food_taster_court_position
				limit = { is_available_ai_adult = yes }
				save_scope_as = food_taster
				hidden_effect = { change_current_weight = 25 }
			}
    	}
    	if = {
    		limit = {
    			is_married = yes
    			primary_spouse = { court_8150_vassal_trigger = yes }
    		}
    		primary_spouse = { save_scope_as = vassal_1 }
    	}
    	else = {
    		random_courtier_or_guest = {
    			limit = { court_8150_vassal_trigger = yes }
    			weight = {
					modifier = {
						factor = 2
						has_any_court_position = yes
					}
					modifier = {
						factor = 10
						has_trait = gluttonous
					}
					modifier = {
						factor = 5
						has_trait = greedy
					}
					modifier = {
						factor = 2
						is_courtier = yes
					}
				}
    			save_scope_as = vassal_1
    			court_event_character_flag_effect = yes
    			hidden_effect = { change_current_weight = 15 }
    		}
    	}
		random_courtier_or_guest = {
			limit = { court_8150_vassal_trigger = yes }
			weight = {
				modifier = {
					factor = 2
					has_any_court_position = yes
				}
				modifier = {
					factor = 10
					has_trait = gluttonous
				}
				modifier = {
					factor = 5
					has_trait = greedy
				}
				modifier = {
					factor = 2
					is_courtier = yes
				}
			}
			save_scope_as = vassal_2
			court_event_character_flag_effect = yes
			hidden_effect = { change_current_weight = 15 }
		}
		random_courtier_or_guest = {
			limit = { court_8150_vassal_trigger = yes }
			weight = {
				modifier = {
					factor = 2
					has_any_court_position = yes
				}
				modifier = {
					factor = 10
					has_trait = gluttonous
				}
				modifier = {
					factor = 5
					has_trait = greedy
				}
				modifier = {
					factor = 2
					is_courtier = yes
				}
			}
			save_scope_as = vassal_3
			court_event_character_flag_effect = yes
			hidden_effect = { change_current_weight = 15 }
		}
		hidden_effect = {
			random_list = {
				2 = {
					trigger = { exists = scope:vassal_1 }
					scope:vassal_1 = { save_scope_as = demander }
				}
				2 = {
					trigger = { exists = scope:vassal_2 }
					scope:vassal_2 = { save_scope_as = demander }
				}
				2 = {
					trigger = { exists = scope:vassal_3 }
					scope:vassal_3 = { save_scope_as = demander }
				}
			}
		}
    }

    option = { # Chow down
        name = court.8150.a
        change_current_court_grandeur = major_court_grandeur_gain
		reverse_add_opinion = {
        	modifier = pleased_opinion
        	target = scope:vassal_1
        	opinion = 10
        }
        if = {
        	limit = { exists = scope:vassal_2 }
        	reverse_add_opinion = {
	        	modifier = pleased_opinion
	        	target = scope:vassal_2
	        	opinion = 10
	        }
        }
        if = {
        	limit = { exists = scope:vassal_3 }
        	reverse_add_opinion = {
	        	modifier = pleased_opinion
	        	target = scope:vassal_3
	        	opinion = 10
	        }
        }
        if = {
        	limit = { exists = scope:chaplain }
    		reverse_add_opinion = {
    			modifier = disgusted_opinion
    			target = scope:chaplain
    			opinion = -10
    		}
        }
        #AGOT Disabled
        # if = {
        # 	limit = { exists = scope:high_almoner }
    	# 	reverse_add_opinion = {
    	# 		modifier = disgusted_opinion
    	# 		target = scope:high_almoner
    	# 		opinion = -10
    	# 	}
        # }
      	hidden_effect = { change_current_weight = 20 }
        stress_impact = {
        	lifestyle_reveler = medium_stress_impact_loss
        	comfort_eater = medium_stress_impact_loss
        	gluttonous = minor_stress_impact_loss
        	temperate = major_stress_impact_gain
        	inappetetic = massive_stress_impact_gain
        }
        ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 1
				ai_energy = 1
			}
			modifier = {	#Weight up for stress.
				add = 50
				has_trait = lifestyle_reveler
			}
			modifier = {	#Weight up for stress.
				add = 30
				has_trait = comfort_eater
			}
			modifier = {	#Weight up for stress.
				add = 15
				has_trait = gluttonous
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = temperate
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = inappetetic
			}
		}
    }

    option = { # Support foodies
        name = court.8150.b
        change_current_court_grandeur = minor_court_grandeur_gain
        reverse_add_opinion = {
        	modifier = pleased_opinion
        	target = scope:vassal_1
        	opinion = 5
        }
        if = {
        	limit = { exists = scope:vassal_2 }
        	reverse_add_opinion = {
	        	modifier = pleased_opinion
	        	target = scope:vassal_2
	        	opinion = 5
	        }
        }
        if = {
        	limit = { exists = scope:vassal_3 }
        	reverse_add_opinion = {
	        	modifier = pleased_opinion
	        	target = scope:vassal_3
	        	opinion = 5
	        }
        }
        if = {
        	limit = { exists = scope:chaplain }
    		reverse_add_opinion = {
    			modifier = disgusted_opinion
    			target = scope:chaplain
    			opinion = -5
    		}
        }
        #AGOT Disabled
        # if = {
        # 	limit = { exists = scope:high_almoner }
    	# 	reverse_add_opinion = {
    	# 		modifier = disgusted_opinion
    	# 		target = scope:high_almoner
    	# 		opinion = -5
    	# 	}
        # }
        stress_impact = {
        	greedy = medium_stress_impact_gain
        	humble = medium_stress_impact_gain
        }
        ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 0.5
				ai_compassion = -1
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = greedy
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = humble
			}
		}
    }

    option = { # Stop foodies
        name = court.8150.c
        if = {
        	limit = {
	        	NOT = {
	        		faith = { has_doctrine = tenet_hedonistic }
	        	}
        	}
        	add_piety = minor_piety_gain
	        if = {
	        	limit = { exists = scope:chaplain }
	    		reverse_add_opinion = {
	    			modifier = pleased_opinion
	    			target = scope:chaplain
	    			opinion = 10
	    		}
	        }
	        #AGOT Disabled
	        # if = {
	        # 	limit = { exists = scope:high_almoner }
	    	# 	reverse_add_opinion = {
	    	# 		modifier = pleased_opinion
	    	# 		target = scope:high_almoner
	    	# 		opinion = 10
	    	# 	}
	        # }
	    }
        reverse_add_opinion = {
        	modifier = disappointed_opinion
        	target = scope:vassal_1
        	opinion = -10
        }
        if = {
        	limit = { exists = scope:vassal_2 }
        	reverse_add_opinion = {
	        	modifier = disappointed_opinion
	        	target = scope:vassal_2
	        	opinion = -10
	        }
        }
        if = {
        	limit = { exists = scope:vassal_3 }
        	reverse_add_opinion = {
	        	modifier = disappointed_opinion
	        	target = scope:vassal_3
	        	opinion = -10
	        }
        }
        stress_impact = {
        	gluttonous = medium_stress_impact_gain
        	arrogant = medium_stress_impact_gain
        	profligate = medium_stress_impact_gain
        	cynical = medium_stress_impact_gain
        }
        set_amenity_level = { type = court_food_quality value = high_amenity_level }
        ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = -1
				ai_compassion = 1
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = gluttonous
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = arrogant
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = profligate
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = cynical
			}
		}
    }

    option = { # Scorn foodies
        name = court.8150.d
        reverse_add_opinion = {
        	modifier = disappointed_opinion
        	target = scope:vassal_1
        	opinion = -5
        }
        if = {
        	limit = { exists = scope:vassal_2 }
        	reverse_add_opinion = {
	        	modifier = disappointed_opinion
	        	target = scope:vassal_2
	        	opinion = -5
	        }
        }
        if = {
        	limit = { exists = scope:vassal_3 }
        	reverse_add_opinion = {
	        	modifier = disappointed_opinion
	        	target = scope:vassal_3
	        	opinion = -5
	        }
        }
        if = {
        	limit = { exists = scope:chaplain }
    		reverse_add_opinion = {
    			modifier = pleased_opinion
    			target = scope:chaplain
    			opinion = 5
    		}
        }
        #AGOT Disabled
        # if = {
        # 	limit = { exists = scope:high_almoner }
    	# 	reverse_add_opinion = {
    	# 		modifier = pleased_opinion
    	# 		target = scope:high_almoner
    	# 		opinion = 5
    	# 	}
        # }
        stress_impact = {
        	gluttonous = medium_stress_impact_gain
        	diplomat = medium_stress_impact_gain
        	humble = medium_stress_impact_gain
        }
        ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = -0.5
				ai_compassion = 0.5
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = gluttonous
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = diplomat
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = humble
			}
		}
    }
    after = {
    	scope:vassal_1 = {
    		clear_court_event_participation = yes
    	}
		if = {
			limit = {
				exists = scope:vassal_2
			}
			scope:vassal_2 = {
				clear_court_event_participation = yes
			}
		}
		if = {
			limit = {
				exists = scope:vassal_3
			}
			scope:vassal_3 = {
				clear_court_event_participation = yes
			}
		}
	}
}

#########################
# Foremost Knight		#
# by Joe Parkin 		#
#########################

scripted_trigger court_8160_knight_trigger = {
	is_landed = no
	is_available_ai_adult = yes
	can_start_single_combat_trigger = yes
	NOR = {
		has_trait = humble
		has_trait = craven
		has_trait = shy
	}
}

court.8160 = {
    type = court_event
    title = court.8160.t
    desc = {
    	desc = court.8160.desc.intro
    }
    theme = court
    cooldown = { years = 10 }
    court_scene = {
        button_position_character = scope:knight_1
        roles = {
            scope:knight_1 = {
                group = event_group
                animation = rage
            }
            scope:knight_2 = {
                group = event_group
                animation = anger
            }
        }
    }

    trigger = {
    	any_knight = {
    		court_8160_knight_trigger = yes
    		has_court_event_flag = no
    		save_temporary_scope_as = temp_knight
    	}
    	any_knight = {
    		court_8160_knight_trigger = yes
    		has_court_event_flag = no
    		NOR = {
    		 	THIS = scope:temp_knight
    			is_close_or_extended_family_of = scope:temp_knight
    			has_relation_friend = scope:temp_knight
    		}
    	}
    }

    weight_multiplier = {
        base = 1
        # Court weightings.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_warlike }
    }

    immediate = {
    	every_knight = {
    		limit = { court_8160_knight_trigger = yes }
    		add_to_list = knight_list
    	}
 		ordered_in_list = {
 			list = knight_list
 			order_by = prowess
 			save_scope_as = knight_1
 			court_event_character_flag_effect = yes
 			assign_quirk_effect = yes
 		}
 		ordered_in_list = {
 			list = knight_list
 			limit = {
 				NOR = {
 					THIS = scope:knight_1
	    			is_close_or_extended_family_of = scope:knight_1
	    			has_relation_friend = scope:knight_1
	    		}
 				court_8160_knight_trigger = yes
 			}
 			order_by = prowess
 			save_scope_as = knight_2
 			court_event_character_flag_effect = yes
 			assign_quirk_effect = yes
 			if = {
	 			limit = {
	 				NOT = { has_relation_rival = scope:knight_1 }
	 			}
	 			set_relation_rival = {
	 				target = scope:knight_1
	 				reason = rival_age_old_rivalry
	 			}
	 		}
 		}
    }

    option = { # Allow duel
        name = court.8160.a
        change_current_court_grandeur = medium_court_grandeur_gain
		show_as_tooltip = {
			random_list = {
				2 = {
					modifier = { factor = scope:knight_1.prowess }
					show_chance = no
					desc = court.8160.a.tt_knight_1
					scope:knight_1 = { add_prestige = medium_prestige_gain }
					scope:knight_2 = {
						death = {
							death_reason = death_duel
							killer = scope:knight_1
						}
					}
				}
				2 = {
					modifier = { factor = scope:knight_2.prowess }
					show_chance = no
					desc = court.8160.a.tt_knight_2
					scope:knight_2 = { add_prestige = medium_prestige_gain }
					scope:knight_1 = {
						death = {
							death_reason = death_duel
							killer = scope:knight_2
						}
					}
				}
			}
		}
		reverse_add_opinion = {
			target = scope:knight_1
			modifier = respect_opinion
			opinion = 10
		}
		reverse_add_opinion = {
			target = scope:knight_2
			modifier = respect_opinion
			opinion = 10
		}
		configure_start_single_combat_effect = {
			SC_INITIATOR = scope:knight_2
			SC_ATTACKER = scope:knight_2
			SC_DEFENDER = scope:knight_1
			FATALITY = yes
			FIXED = no
			LOCALE = throne_room
			OUTPUT_EVENT = court.8161
			INVALIDATION_EVENT = fp1_tbc.0102 
		}
		stress_impact = {
			compassionate = medium_stress_impact_gain
			craven = minor_stress_impact_gain
			just = minor_stress_impact_gain
		}
		ai_chance = {
			#AGOT Modified, KG stop killing each other
			# base = 100
			base = 10
			ai_value_modifier = {
				ai_boldness = -1
				ai_compassion = -1
				ai_honor = -0.5
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = compassionate
			}
			modifier = {	#Weight down for stress.
				add = -5
				has_trait = craven
			}
			modifier = {	#Weight down for stress.
				add = -5
				has_trait = just
			}
		}
    }

    option = { # Make it a safe duel
        name = court.8160.b
        change_current_court_grandeur = minor_court_grandeur_gain
		show_as_tooltip = {
			random_list = {
				2 = {
					modifier = { factor = scope:knight_1.prowess }
					show_chance = no
					desc = court.8160.a.tt_knight_1
					scope:knight_1 = { add_prestige = minor_prestige_gain }
					scope:knight_2 = {
						increase_wounds_effect = { REASON = duel }
					}
				}
				2 = {
					modifier = { factor = scope:knight_2.prowess }
					show_chance = no
					desc = court.8160.a.tt_knight_2
					scope:knight_2 = { add_prestige = minor_prestige_gain }
					scope:knight_1 = {
						increase_wounds_effect = { REASON = duel }
					}
				}
			}
		}
		reverse_add_opinion = {
			target = scope:knight_1
			modifier = respect_opinion
			opinion = 5
		}
		reverse_add_opinion = {
			target = scope:knight_2
			modifier = respect_opinion
			opinion = 5
		}
		configure_start_single_combat_effect = {
			SC_INITIATOR = scope:knight_2
			SC_ATTACKER = scope:knight_2
			SC_DEFENDER = scope:knight_1
			FATALITY = no
			FIXED = no
			LOCALE = throne_room
			OUTPUT_EVENT = court.8162
			INVALIDATION_EVENT = fp1_tbc.0102
		}
		stress_impact = {
			callous = medium_stress_impact_gain
			arbitrary = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 1
				ai_honor = 1
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = callous
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = arbitrary
			}
		}
    }

    option = { # Duel them yourself
        name = court.8160.c
        trigger = { can_start_single_combat_trigger = yes }
        configure_start_single_combat_effect = {
			SC_INITIATOR = ROOT
			SC_ATTACKER = ROOT
			SC_DEFENDER = scope:knight_1
			FATALITY = no
			FIXED = no
			LOCALE = throne_room
			OUTPUT_EVENT = court.8163
			INVALIDATION_EVENT = fp1_tbc.0102
		}
		custom_tooltip = court.8160.c.tt
		show_as_tooltip = {
			random_list = {
				2 = {
					show_chance = no
					desc = court.8160.c.tt_win
					add_prestige = medium_prestige_gain
					scope:knight_1 = {
						remove_relation_rival = scope:knight_2
						add_opinion = {
							target = ROOT
							modifier = humbled_opinion
							opinion = 5
						}
					}
					scope:knight_2 = {
						add_opinion = {
							target = ROOT
							modifier = respect_opinion
							opinion = 15
						}
						progress_towards_friend_effect = {
							REASON = friend_bested_me_in_duel
							CHARACTER = ROOT
							OPINION = 0
						}
					}
				}
				2 = {
					show_chance = no
					desc = court.8160.c.tt_lose
					add_prestige = minor_prestige_loss
					add_character_modifier = {
						modifier = court_humiliation_modifier
						years = 5
					}
					scope:knight_1 = {
						add_opinion = {
							target = ROOT
							modifier = disappointed_opinion
							opinion = -10
						}
					}
					scope:knight_2 = {
						add_opinion = {
							target = ROOT
							modifier = disappointed_opinion
							opinion = -10
						}
					}
				}
			}
		}
        stress_impact = {
			humble = medium_stress_impact_gain
			craven = medium_stress_impact_gain
			shy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 1
				ai_boldness = 2
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = humble
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = craven
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = shy
			}
		}
    }

    option = { # Do not allow duel
        name = court.8160.d
        change_current_court_grandeur = minor_court_grandeur_loss
		reverse_add_opinion = {
			target = scope:knight_1
			modifier = disappointed_opinion
			opinion = -5
		}
		reverse_add_opinion = {
			target = scope:knight_2
			modifier = disappointed_opinion
			opinion = -5
		}
        stress_impact = {
			arbitrary = medium_stress_impact_gain
			brave = medium_stress_impact_gain
			wrathful = medium_stress_impact_gain
			vengeful = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = 1
				ai_boldness = -1
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = arbitrary
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = brave
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = wrathful
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = vengeful
			}
		}
    }
    after = {
    	scope:knight_1 = {
    		if = {
    			limit = { is_alive = yes }
    			clear_court_event_participation = yes
    		}
    	}
    	scope:knight_2 = {
    		if = {
    			limit = { is_alive = yes }
    			clear_court_event_participation = yes
    		}
    	}

    }
}

court.8161 = {
	hidden = yes

	immediate = {
		scope:sc_victor.liege = {
			send_interface_toast = {
				title = hold_court.8031.t
				left_icon = scope:sc_victor
				right_icon = scope:sc_loser
				scope:sc_victor = { add_prestige = medium_prestige_gain }
				scope:sc_loser = {
					death = {
						death_reason = death_duel
						killer = scope:sc_victor
					}
				}
			}
		}
	}
}

court.8162 = {
	hidden = yes

	immediate = {
		scope:sc_victor.liege = {
			send_interface_toast = {
				title = hold_court.8031.t
				left_icon = scope:sc_victor
				right_icon = scope:sc_loser
				scope:sc_victor = { add_prestige = minor_prestige_gain }
			}
		}
	}
}

court.8163 = {
	hidden = yes

	immediate = {
		if = {
			limit = { scope:sc_victor = ROOT }
			send_interface_toast = {
				title = court.8163.t
				left_icon = scope:sc_victor
				right_icon = scope:sc_loser
				scope:sc_victor = { add_prestige = medium_prestige_gain }
				scope:knight_1 = {
					remove_relation_rival = scope:knight_2
					add_opinion = {
						target = ROOT
						modifier = humbled_opinion
						opinion = 5
					}
				}
				scope:knight_2 = {
					add_opinion = {
						target = ROOT
						modifier = humbled_opinion
						opinion = 5
					}
				}
			}
		}
		else = {
			send_interface_toast = {
				title = hold_court.8031.t
				left_icon = scope:sc_loser
				right_icon = scope:sc_victor
				add_prestige = minor_prestige_loss
				add_character_modifier = {
					modifier = court_humiliation_modifier
					years = 5
				}
				scope:knight_1 = {
					add_opinion = {
						target = ROOT
						modifier = disappointed_opinion
						opinion = -10
					}
				}
				scope:knight_2 = {
					add_opinion = {
						target = ROOT
						modifier = disappointed_opinion
						opinion = -10
					}
				}
			}
		}
	}
}

#########################
# Pariah of Court		#
# by Joe Parkin 		#
#########################

scripted_trigger kinslayer_crime_trigger = {
	AND = {
		liege.faith = {
			NOR = {
				has_doctrine = doctrine_kinslaying_accepted
				has_doctrine = doctrine_kinslaying_shunned
			}
		}
		OR = {
			has_trait = kinslayer_1
			has_trait = kinslayer_2
			has_trait = kinslayer_3
		}
	}
	is_human = yes
}

scripted_trigger cannibal_crime_trigger = {
	AND = {
		NOT = {
			liege.faith = { has_doctrine = tenet_ritual_cannibalism }
		}
		has_trait = cannibal
	}
	is_human = yes
}

scripted_trigger witch_crime_trigger = {
	AND = {
		liege.faith = { has_doctrine_parameter = witchcraft_illegal }
		has_trait = witch
	}
	is_human = yes
}

scripted_trigger deviant_crime_trigger = {
	AND = {
		liege.faith = { has_doctrine_parameter = deviancy_illegal }
		has_trait = deviant
	}
	is_human = yes
}

scripted_trigger sodomite_crime_trigger = {
	AND = {
		liege.faith = { has_doctrine = doctrine_homosexuality_crime }
		is_male = yes
		has_trait = sodomite
	}
	is_human = yes
}

scripted_trigger incest_crime_trigger = {
	AND = {	
		liege.faith = {
			NOT = { has_doctrine = doctrine_consanguinity_unrestricted }
		}
		has_trait = incestuous
	}
	is_human = yes
}

scripted_trigger adultery_crime_trigger = {
	AND = {
		OR = {
			AND = {
				liege.faith = { has_doctrine = doctrine_adultery_women_crime }
				is_female = yes
			}
			AND = {
				liege.faith = { has_doctrine = doctrine_adultery_men_crime }
				is_male = yes
			}
		}
		OR = {
			has_trait = adulterer
			has_trait = fornicator
		}
	}
	is_human = yes
}

scripted_trigger excommunicated_crime_trigger = {
	AND = {
		faith = liege.faith
		has_trait = excommunicated
	}
	is_human = yes
}

scripted_trigger faith_crime_trigger = {
	AND = {
		faith = {
			faith_hostility_level = {
				target = ROOT.faith
				value > faith_hostile_level
			}
		}
	}
	is_human = yes
}

scripted_trigger is_illegal_criminal_trigger = {
	exists = liege.faith
	OR = {
		kinslayer_crime_trigger = yes
		cannibal_crime_trigger = yes
		witch_crime_trigger = yes
		deviant_crime_trigger = yes
		sodomite_crime_trigger = yes
		incest_crime_trigger = yes
		adultery_crime_trigger = yes
		excommunicated_crime_trigger = yes
		faith_crime_trigger = yes
		has_trait = denounced
	}
	is_human = yes
}

scripted_trigger court_8170_criminal_trigger = {
	is_imprisoned = no
	is_landed = no
	is_illegal_criminal_trigger = yes
}

court.8170 = {
    type = court_event
    title = court.8170.t
    desc = {
   	 	first_valid = {
			triggered_desc = {
				trigger = {
					scope:criminal = {
						OR = {
							kinslayer_crime_trigger = yes
							cannibal_crime_trigger = yes
							witch_crime_trigger = yes
						}
					}
				}
				desc = court.8170.desc.intro_scary
			}
			triggered_desc = {
				trigger = {
					scope:criminal = {
						OR = {
							deviant_crime_trigger = yes
							sodomite_crime_trigger = yes
							incest_crime_trigger = yes
							adultery_crime_trigger = yes
						}
					}
				}
				desc = court.8170.desc.intro_sordid
			}
			triggered_desc = {
				trigger = {
					scope:criminal = {
						OR = {
							excommunicated_crime_trigger = yes
							faith_crime_trigger = yes
						}
					}
				}
				desc = court.8170.desc.intro_religious
			}
			desc = court.8170.desc.intro_fallback
		}
    	desc = court.8170.desc.body
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:criminal = { is_close_or_extended_family_of = ROOT }
				}
				desc = court.8170.desc.family
			}
			triggered_desc = {
				trigger = {
					scope:criminal = { is_pool_guest = yes }
				}
				desc = court.8170.desc.guest
			}
			desc = court.8170.desc.fallback
		}
    }
    theme = court
    cooldown = { years = 10 }
    court_scene = {
        button_position_character = scope:criminal
        roles = {
            scope:criminal = {
                group = event_group
                animation = shame
            }
        }
    }

    trigger = {
    	NOT = { court_8170_criminal_trigger = yes }
    	any_courtier_or_guest = {
    		court_8170_criminal_trigger = yes
    		has_court_event_flag = no
		}
    }

    weight_multiplier = {
        base = 1
    }

    immediate = {
    	random_courtier_or_guest = {
    		limit = {
    			is_close_or_extended_family_of = ROOT
    			court_8170_criminal_trigger = yes
    		}
    		alternative_limit = {
    			is_courtier = yes
    			court_8170_criminal_trigger = yes
    		}
    		alternative_limit = { court_8170_criminal_trigger = yes }
	    	save_scope_as = criminal
	    	court_event_character_flag_effect = yes
    	}
    }

    option = { # Do nothing
        name = {
        	text = court.8170.a.family
        	trigger = {
        		scope:criminal = { is_close_or_extended_family_of = ROOT }
        	}
        }
        name = {
        	text = court.8170.a.other
        	trigger = {
        		NOT = {
        			scope:criminal = { is_close_or_extended_family_of = ROOT }
        		}
        	}
        }
        change_current_court_grandeur = medium_court_grandeur_loss
        add_character_modifier = {
        	modifier = harbors_criminals_modifier
        	years = 5
        }
        reverse_add_opinion = {
    		target = scope:criminal
    		modifier = grateful_opinion
    		opinion = 10
    	}
        stress_impact = {
        	just = medium_stress_impact_gain
        	arrogant = medium_stress_impact_gain
        	vengeful = medium_stress_impact_gain
        	callous = medium_stress_impact_gain
        }
    }

    option = { # Convent
        name = court.8170.b
        trigger = {
        	scope:criminal = {
        		faith = ROOT.faith
        		NOT = { has_trait = devoted }
        		is_married = no
        	}
        }
        add_piety = minor_piety_gain
        scope:criminal = { add_trait = devoted }
        reverse_add_opinion = {
    		target = scope:criminal
    		modifier = insulted_opinion
    		opinion = -15
    	}
    	if = {
    		limit = { exists = cp:councillor_court_chaplain }
    		reverse_add_opinion = {
    			target = cp:councillor_court_chaplain
	    		modifier = pious_opinion
	    		opinion = 5
	    	}
    	}
    	stress_impact = {
        	cynical = medium_stress_impact_gain
        	arbitrary = medium_stress_impact_gain
        	forgiving = medium_stress_impact_gain
        }
    }

	option = { # Convert
        name = court.8170.b
        trigger = {
        	scope:criminal = {
        		NOT = { faith = ROOT.faith }
        		faith = {
					faith_hostility_level = {
						target = ROOT.faith
						value >= faith_hostile_level
					}
				}
				is_courtier = yes
        	}
        }
        add_piety = medium_piety_gain
		save_scope_as = actor
		scope:criminal = { save_scope_as = recipient }
		custom_tooltip = demand_conversion_tt
		hidden_effect = { demand_conversion_interaction_effect = yes }
    	if = {
    		limit = { exists = cp:councillor_court_chaplain }
    		reverse_add_opinion = {
    			target = cp:councillor_court_chaplain
	    		modifier = pious_opinion
	    		opinion = 10
	    	}
    	}
    	stress_impact = {
        	cynical = medium_stress_impact_gain
        	arbitrary = medium_stress_impact_gain
        	vengeful = medium_stress_impact_gain
        }
    }

    option = { # Imprison
        name = court.8170.c
        change_current_court_grandeur = minor_court_grandeur_gain
        if = {
	    	limit = { has_relation_friend = scope:criminal }
	    	stress_impact = { base = major_stress_impact_gain }
	    }
	    if = {
	    	limit = { is_close_family_of = scope:criminal }
	    	stress_impact = { base = medium_stress_impact_gain }
	    }
	    if = {
	    	limit = { is_extended_family_of = scope:criminal }
	    	stress_impact = { base = minor_stress_impact_gain }
	    }
	  	if = {
	    	limit = { has_relation_rival = scope:criminal }
	    	stress_impact = { base = medium_stress_impact_loss }
	    }
	    stress_impact = {
	    	compassionate = minor_stress_impact_gain
	    }
        rightfully_imprison_character_effect = {
			TARGET = scope:criminal
			IMPRISONER = ROOT
		}
    	if = {
    		limit = { exists = cp:councillor_court_chaplain }
    		reverse_add_opinion = {
    			target = cp:councillor_court_chaplain
	    		modifier = pious_opinion
	    		opinion = 10
	    	}
    	}
    }

    option = { # Kick out
        name = court.8170.d
        change_current_court_grandeur = minor_court_grandeur_gain
        if = {
	    	limit = { has_relation_friend = scope:criminal }
	    	stress_impact = { base = medium_stress_impact_gain }
	    }
	    if = {
	    	limit = { is_close_family_of = scope:criminal }
	    	stress_impact = { base = minor_stress_impact_gain }
	    }
	    if = {
	    	limit = { is_extended_family_of = scope:criminal }
	    	stress_impact = { base = miniscule_stress_impact_gain }
	    }
	  	if = {
	    	limit = { has_relation_rival = scope:criminal }
	    	stress_impact = { base = medium_stress_impact_loss }
	    }
	    stress_impact = {
	    	compassionate = minor_stress_impact_gain
	    }
	    reverse_add_opinion = {
    		target = scope:criminal
    		modifier = insulted_opinion
    		opinion = -30
    	}
        hidden_effect = {
        	scope:criminal = { select_and_move_to_pool_effect = yes }
        }
        show_as_tooltip = { remove_courtier_or_guest = scope:criminal }
        if = {
    		limit = { exists = cp:councillor_court_chaplain }
    		reverse_add_opinion = {
    			target = cp:councillor_court_chaplain
	    		modifier = pious_opinion
	    		opinion = 10
	    	}
    	}
    }
    after = {
    	scope:criminal = {
    		clear_court_event_participation = yes
    	}
    }
}

#########################
# Secrets and Lies		#
# by Joe Parkin 		#
#########################

scripted_trigger court_8180_secret_trigger = {
	exists = secret_owner
	is_criminal_for = secret_owner
	any_secret_knower = { this = root }
	NOT = { secret_target ?= root }
}

scripted_trigger court_8180_relation_trigger = {
	is_available_ai_adult = yes
	any_secret = { court_8180_secret_trigger = yes }
}

court.8180 = {
    type = court_event
    title = court.8180.t
    desc = court.8180.desc.intro
    theme = court
    cooldown = { years = 10 }
    court_scene = {
        button_position_character = scope:criminal
        roles = {
            scope:criminal = {
                group = event_group
                animation = worry
            }
        }
    }

    trigger = {
    	any_courtier_or_guest = {
    		court_8180_relation_trigger = yes
			has_court_event_flag = no
   		}
    }

    weight_multiplier = {
        base = 1
    }

    immediate = {
    	random_courtier_or_guest = {
    		limit = {
    			court_8180_relation_trigger = yes
    			has_court_event_flag = no
    		}
	    	save_scope_as = criminal
	    	court_event_character_flag_effect = yes
	    	random_secret = {
	    		limit = { court_8180_secret_trigger = yes }
	    		save_scope_as = criminal_secret
	    	}
    	}
    	save_scope_as = knower # custom_loc
    	save_scope_as = actor # blackmail interaction
        scope:criminal = { save_scope_as = recipient } # blackmail interaction
        scope:criminal_secret = { save_scope_as = target } # blackmail interaction
    }

    option = { # Expose secret
        name = court.8180.a
        change_current_court_grandeur = medium_court_grandeur_loss
        scope:criminal_secret = { expose_secret = ROOT }
        reverse_add_opinion = {
        	target = scope:criminal
        	modifier = exposed_my_secret_opinion
        }
        stress_impact = {
    		deceitful = minor_stress_impact_gain
    		compassionate = minor_stress_impact_gain
        }
    }

    option = { # Blackmail
        name = court.8180.b
        trigger = {
        	NOT = { has_hook = scope:criminal }
        }
        blackmail_interaction_effect = yes
        stress_impact = {
    		honest = minor_stress_impact_gain
    		compassionate = minor_stress_impact_gain
    		lazy = minor_stress_impact_gain
        }
    }

    option = { # Imprison
        name = court.8180.c
        change_current_court_grandeur = minor_court_grandeur_loss
        scope:criminal_secret = { expose_secret = ROOT }
        hidden_effect = {
	        rightfully_imprison_character_effect = {
				TARGET = scope:criminal
				IMPRISONER = ROOT
			}
		}
		show_as_tooltip = {
			imprison = { target = scope:criminal type = house_arrest }
		}
		stress_impact = {
    		arbitrary = minor_stress_impact_gain
    		compassionate = minor_stress_impact_gain
    		lazy = minor_stress_impact_gain
        }
    }

    option = { # Kick out of court
        name = court.8180.d
        change_current_court_grandeur = miniscule_court_grandeur_loss
        scope:criminal = { select_and_move_to_pool_effect = yes }
        reverse_add_opinion = {
        	target = scope:criminal
        	modifier = insulted_opinion
        	opinion = -10
        }
        stress_impact = {
    		arbitrary = minor_stress_impact_gain
    		honest = minor_stress_impact_gain
    		generous = minor_stress_impact_gain
    		compassionate = minor_stress_impact_gain
        }
    }

    option = { # Do nothing
        name = court.8180.e
        stress_impact = {
    		base = minor_stress_impact_gain
    		just = medium_stress_impact_gain
    		honest = medium_stress_impact_gain
    		trusting = medium_stress_impact_gain
    		vengeful = medium_stress_impact_gain
    		zealous = medium_stress_impact_gain
    		diligent = medium_stress_impact_gain
        }
    }
    after = {
    	scope:criminal = {
    		clear_court_event_participation = yes
    	}
    }
}











##################################################
# Oltner

##################################################
# 9000 - 9009	A Knight's Declaration
# 9100 - 9109	Epicurean Entertainment
# 9200 - 9209	Bacchanalian Bonding
# 9300 - 9309	Overt Overindulgence
# 9400 - 9409	Pie-based Shenanigans
# 9500 - 9509	A Little Language
##################################################

#########################
# A Knight's Declaration
# by Alexander Oltner
#########################

scripted_trigger suitably_flirty_knight = {
	is_available_adult = yes
	is_courtier_of = root
	is_attracted_to_gender_of = root.primary_spouse
	can_start_scheme = {
		type = courting
		target = root.primary_spouse
	}
	NOR = {
		has_trait = chaste
		has_trait = celibate
		has_relation_lover = root.primary_spouse
		#AGOT Added, less incest
		is_close_or_extended_family_of = root.primary_spouse
	}
}

# A Knight's Declaration
court.9000 = {
	type = court_event
	title = court.9000.t
	desc = court.9000.desc
	theme = court

	court_scene = {
		button_position_character = scope:flirty_knight
		roles = {
			scope:flirty_knight = {
				group = event_group
				animation = flirtation_left
			}
			scope:flirty_spouse = {
				group = event_group
				animation = flirtation
			}
		}
	}
	
	cooldown = {
		years = 10
	}
	
	trigger = {
		is_available_adult = yes
		is_married = yes
		any_knight = {
			suitably_flirty_knight = yes
			has_court_event_flag = no
			save_temporary_scope_as = attraction_check
		}
		primary_spouse = {
			is_available_adult = yes
			has_court_event_flag = no
			is_courtier_of = root
			is_attracted_to_gender_of = scope:attraction_check
			NOR = {
				has_trait = chaste
				has_trait = celibate
				has_relation_lover = scope:attraction_check
			}
		}
	}

	weight_multiplier = {
		base = 1

		# Court weightings.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_warlike }
	}

	immediate = {
		primary_spouse = {
			save_scope_as = flirty_spouse
			court_event_character_flag_effect = yes
		}
		random_knight = {
			limit = {
				suitably_flirty_knight = yes
			}
			weight = {
				base = 1
				modifier = {
					add = 10
					OR = {
						has_trait = lustful
						has_trait = seducer
					}
				}
				modifier = {
					add = 10
					has_trait = poet
				}
			}
			hidden_effect = {
				if = {
					limit = {
						NOT = {
							has_trait = poet
						}
					}
					add_trait = poet
				}
			}
			save_scope_as = flirty_knight
			court_event_character_flag_effect = yes
			
			# Set up a subject gender.
			select_poem_subject_gender_effect = {
				SUBJECT = flag:specific
				SUBJECT_TARGET = scope:flirty_spouse
			}
			# Roll for theme.
			select_poem_theme_romance_effect = yes
		}
	}

	option = { # Throw them in prison
		name = court.9000.a
		
		custom_tooltip = court_9000_a_tt
		
		add_prestige = major_prestige_loss
		
		rightfully_imprison_character_effect = {
			TARGET = scope:flirty_knight
			IMPRISONER = root
		}
		
		scope:flirty_spouse = { save_scope_as = relationship_reason_involved_character }
		progress_towards_rival_effect = {
			CHARACTER = scope:flirty_knight
			REASON = rival_wooed_spouse
			OPINION = 0
		}
		clear_saved_scope = relationship_reason_involved_character
		
		stress_impact = {
			trusting = massive_stress_impact_gain
			forgiving = massive_stress_impact_gain
			chaste = medium_stress_impact_gain
			calm = medium_stress_impact_gain
			just = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
		}
		ai_chance = {
			base = 25
			modifier = {
				factor = 0.1
				OR = {
					has_trait = trusting
					has_trait = forgiving
					has_trait = chaste
				}
			}
		}
	}

	option = { # Stop this at once!
		name = court.9000.b
		
		custom_tooltip = court_9000_b_tt
		
		add_prestige = minor_prestige_loss
		
		scope:flirty_knight = {
			add_opinion = {
				target = root
				modifier = rude_opinion
				opinion = -20
			}
			hidden_effect = {
				random = {
					chance = 45
					start_scheme = {
						type = courting
						target = scope:flirty_spouse
					}
				}
			}
		}
		
		scope:flirty_spouse = {
			add_opinion = {
				target = root
				modifier = rude_opinion
				opinion = -20
			}
		}
		
		stress_impact = {
			trusting = massive_stress_impact_gain
			forgiving = medium_stress_impact_gain
			chaste = medium_stress_impact_gain
			calm = medium_stress_impact_gain
			shy = medium_stress_impact_gain
			gregarious = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0.1
				OR = {
					has_trait = trusting
					has_trait = forgiving
					has_trait = chaste
				}
			}
		}
	}
	
	option = { # Let it go on!
		name = court.9000.c
		
		custom_tooltip = court_9000_c_tt
		
		change_current_court_grandeur = major_court_grandeur_gain
		
		add_prestige = minor_prestige_gain
		
		scope:flirty_knight = {
			add_opinion = {
				target = root
				modifier = flattered_opinion
				opinion = 20
			}
			hidden_effect = {
				random = {
					chance = 75
					start_scheme = {
						type = courting
						target = scope:flirty_spouse
					}
				}
			}
		}
		
		stress_impact = {
			paranoid = massive_stress_impact_gain
			arrogant = major_stress_impact_gain
			vengeful = medium_stress_impact_gain
			lustful = medium_stress_impact_gain
			callous = minor_stress_impact_gain
			sadistic = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0.1
				OR = {
					has_trait = paranoid
					has_trait = arrogant
					has_trait = vengeful
					has_trait = lustful
				}
			}
		}
	}
	after = {
		scope:flirty_knight = {
			clear_court_event_participation = yes
		}
		scope:flirty_spouse = {
			clear_court_event_participation = yes
		}
	}
}

# A Knight's Dedication
court.9001 = {
	type = court_event
	title = court.9001.t
	desc = court.9001.desc
	theme = court

	court_scene = {
		button_position_character = scope:flirty_knight
		roles = {
			scope:flirty_knight = {
				group = event_group
				animation = flirtation_left
			}
			scope:flirty_spouse = {
				group = event_group
				animation = flirtation
			}
		}
	}
	
	cooldown = {
		years = 30
	}
	
	trigger = {
		is_available_adult = yes
		is_married = yes
		primary_spouse = {
			is_available_adult = yes
			has_court_event_flag = no
			is_courtier_of = root
			NOT = {
				has_relation_soulmate = root
			}
			
			any_targeting_scheme = {
				scheme_owner = {
					is_available_adult = yes
					is_courtier_of = root
					has_court_event_flag = no
					save_temporary_scope_as = attraction_check
				}
				scheme_type = courting
			}
			
			is_attracted_to_gender_of = scope:attraction_check
		}
	}

	weight_multiplier = {
		base = 1

		# Court weightings.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_warlike }
	}

	immediate = {
		save_scope_as = root_for_loc
		primary_spouse = {
			save_scope_as = flirty_spouse
			court_event_character_flag_effect = yes
			random_targeting_scheme = {
				limit = {
					scheme_owner = {
						is_available_adult = yes
						is_courtier_of = root
						scope:flirty_spouse = {
							is_attracted_to_gender_of = prev
						}
					}
					scheme_type = courting
				}
				scheme_owner = {
					save_scope_as = flirty_knight
					court_event_character_flag_effect = yes
				}
			}
		}
	}

	option = { # Duel them
		name = court.9001.a
		
		trigger = {
			can_start_single_combat_trigger = yes
			scope:flirty_knight = {
				can_be_warrior_trigger = { ARMY_OWNER = root }
				can_start_single_combat_trigger = yes
			}
		}
		custom_tooltip = court.9001.a.tt
		
		configure_start_single_combat_effect = {
			SC_INITIATOR = root
			SC_ATTACKER = root
			SC_DEFENDER = scope:flirty_knight
			FATALITY = no
			FIXED = no
			LOCALE = throne_room
			OUTPUT_EVENT = court.9003
			INVALIDATION_EVENT = court.9002
		}
		
		ai_chance = {
			base = 25
			modifier = {
				factor = 0.1
				OR = {
					has_trait = trusting
					has_trait = forgiving
					has_trait = chaste
				}
			}
		}
	}

	option = { # Banish the knight
		name = court.9001.b
		
		add_gold = 5
		
		scope:flirty_knight = {
			#AGOT Modified
			#banish = yes
			agot_banish_effect = { BANISHER = root }
			hidden_effect = {	
				if = {
					limit = {
						any_scheme = {
							scheme_type = courting
							scheme_target = scope:flirty_spouse
						}
					}
					random_scheme = {
						limit = {
							scheme_type = courting
							scheme_target = scope:flirty_spouse
						}
						end_scheme = yes
					}
				}
			}
		}
		
		scope:flirty_spouse = {
			progress_towards_rival_effect = {
				CHARACTER = root
				REASON = rival_banished_knight
				OPINION = 0
			}
			
			add_opinion = {
				modifier = how_could_you_opinion
				target = root
			}
		}
		
		stress_impact = {
			trusting = massive_stress_impact_gain
			forgiving = medium_stress_impact_gain
			chaste = medium_stress_impact_gain
			calm = medium_stress_impact_gain
			shy = medium_stress_impact_gain
			gregarious = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0.1
				OR = {
					has_trait = trusting
					has_trait = forgiving
					has_trait = chaste
				}
			}
		}
	}
	
	option = { # Let it go on!
		name = court.9001.c
		
		change_current_court_grandeur = major_court_grandeur_gain
		
		add_prestige = minor_prestige_gain
		
		stress_impact = {
			paranoid = massive_stress_impact_gain
			arrogant = major_stress_impact_gain
			vengeful = medium_stress_impact_gain
			lustful = medium_stress_impact_gain
			callous = minor_stress_impact_gain
			sadistic = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0.1
				OR = {
					has_trait = paranoid
					has_trait = arrogant
					has_trait = vengeful
					has_trait = lustful
				}
			}
		}
	}
	after = {
		scope:flirty_knight = {
			clear_court_event_participation = yes
		}
		scope:flirty_spouse = {
			clear_court_event_participation = yes
		}
	}
}

# Invalidated
court.9002 = {
	hidden = yes

	immediate = {
		# Inform both parties that the duel has invalidated.
		scope:root_for_loc = {
			send_interface_toast = {	
				title = court.9002.trigger_failure
				left_icon = scope:flirty_knight
			}
		}
	}
}

# Outcome
court.9003 = {
	hidden = yes

	immediate = {
		if = {
			limit = {
				scope:root_for_loc = scope:sc_victor
			}
			trigger_event = { id = court.9004 }
		}
		else = {
			trigger_event = { id = court.9005 }
		}
	}
}

# Won
court.9004 = {
	type = character_event
	title = court.9004.t
	desc = court.9004.desc
	theme = education
	left_portrait = {
		character = scope:flirty_spouse
		animation = dismissal
	}
	right_portrait = {
		character = scope:flirty_knight
		animation = pain
	}

	trigger = {

	}

	immediate = {
		
	}

	option = { # Leave my spouse alone!
		name = court.9004.a
		
		scope:flirty_knight = {
			if = {
				limit = {
					any_scheme = {
						scheme_type = courting
						scheme_target = scope:flirty_spouse
					}
				}
				random_scheme = {
					limit = {
						scheme_type = courting
						scheme_target = scope:flirty_spouse
					}
					end_scheme = yes
				}
			}
			if = {
				limit = {
					has_relation_lover = scope:flirty_spouse
				}
				#AGOT Modified to use effect accounting for paramours
				# remove_relation_lover = scope:flirty_spouse
				remove_lover_or_soulmate_relation_effect = { CHARACTER = scope:flirty_spouse }
			}
			if = {
				limit = {
					has_relation_potential_lover = scope:flirty_spouse
				}
				remove_relation_potential_lover = scope:flirty_spouse
			}
			if = {
				limit = {
					has_relation_soulmate = scope:flirty_spouse
				}
				remove_relation_soulmate = scope:flirty_spouse
			}
		}
		if = {
			limit = {
				can_add_hook = {
					target = scope:flirty_knight
					type = loyalty_hook
				}
			}
			add_hook = {
				type = loyalty_hook
				target = scope:flirty_knight
			}
		}
		
		scope:flirty_spouse = {
			add_opinion = {
				target = scope:flirty_knight
				modifier = disappointed_opinion
				opinion = -50
			}
			add_opinion = {
				modifier = impressed_opinion
				target = root
				opinion = 50
			}
			if = {
				limit = {
					can_set_relation_soulmate_trigger = { CHARACTER = root }
				}
				set_relation_soulmate = { reason = soulmate_defended_spouse copy_reason = lover target = root involved_character = scope:flirty_knight }
			}
			else_if = {
				limit = {
					can_set_relation_lover_trigger = { CHARACTER = root }
				}
				set_relation_lover = { reason = lover_dueled_for_love target = root involved_character = scope:flirty_knight }
			}
		}
		
		add_prestige = major_prestige_gain
		
		ai_chance = {
			base = 100
		}
	}
}

# Beaten
court.9005 = {
	type = character_event
	title = court.9005.t
	desc = court.9005.desc
	theme = family
	left_portrait = {
		character = scope:flirty_spouse
		animation = flirtation_left
	}
	right_portrait = {
		character = scope:flirty_knight
		animation = flirtation
	}
	override_background = { reference = study }

	trigger = {

	}

	immediate = {
		
	}

	option = { # They leave
		name = court.9005.a
		
		scope:flirty_knight = {
			if = {
				limit = {
					has_relation_lover = scope:flirty_spouse
				}
				#AGOT Modified to use effect accounting for paramours
				# remove_relation_lover = scope:flirty_spouse
				remove_lover_or_soulmate_relation_effect = { CHARACTER = scope:flirty_spouse }
			}
			if = {
				limit = {
					has_relation_potential_lover = scope:flirty_spouse
				}
				remove_relation_potential_lover = scope:flirty_spouse
			}
			if = {
				limit = {
					has_relation_soulmate = scope:flirty_spouse
				}
				remove_relation_soulmate = scope:flirty_spouse
			}
			hidden_effect = {
				#AGOT Modified
				#banish = yes
				agot_banish_effect = { BANISHER = root }
			}
		}
		
		scope:flirty_spouse = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -50
			}
			add_opinion = {
				modifier = impressed_opinion
				target = scope:flirty_knight
				opinion = 50
			}
			if = {
				limit = {
					can_set_relation_soulmate_trigger = { CHARACTER = scope:flirty_knight }
				}
				set_relation_soulmate = { reason = soulmate_won_love_in_duel copy_reason = lover target = scope:flirty_knight }
			}
			else_if = {
				limit = {
					can_set_relation_lover_trigger = { CHARACTER = scope:flirty_knight }
				}
				set_relation_lover = { reason = lover_dueled_for_love target = scope:flirty_knight involved_character = root }
			}
			less_verbose_divorce_effect = {
				DIVORCER = scope:flirty_spouse
				DIVORCEE = root
			}
			hidden_effect = {
				move_to_pool_at = scope:flirty_knight.location
			}
		}
		
		add_prestige = major_prestige_loss
		
		custom_tooltip = court_9005_tt
		
		ai_chance = {
			base = 100
		}
	}
}

#########################
# Epicurean Entertainment
# by Alexander Oltner
#########################

# Your courtiers love your expensive food!
court.9100 = {
	type = court_event
	title = court.9100.t
	desc = court.9100.desc
	theme = court

	court_scene = {
		button_position_character = scope:food_lover_1
		roles = {
			scope:food_lover_1 = {
				group = event_group
				animation = ecstasy
			}
			scope:food_lover_2 = {
				group = event_group
				animation = admiration
			}
			scope:food_lover_3 = {
				group = event_group
				animation = personality_greedy
			}
		}
	}
	
	cooldown = {
		years = 10
	}
	
	trigger = {
		is_available = yes
		age >= 10
		amenity_level = { type = court_food_quality value >= 3 }
		any_courtier_or_guest = {
			is_available_ai_adult = yes
			has_court_event_flag = no
			NOR = {
				has_trait = temperate
				has_trait = inappetetic
				has_relation_rival = root
			}
			count >= 3
		}
	}

	weight_multiplier = {
		base = 1

		# Court weightings.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_diplomatic }
	}

	immediate = {
		hidden_effect = {
			random_courtier_or_guest = {
				limit = {
					is_available_ai_adult = yes
					NOR = {
						has_trait = temperate
						has_trait = inappetetic
						has_relation_rival = root
					}
				}
				weight = {
					base = 1
					modifier = {
						add = 100
						loves_food_trigger = yes
					}
					modifier = {
						add = 50
						has_relation_potential_friend = root
					}
					modifier = {
						add = 10
						is_of_major_interest_to_root_trigger = yes
					}
					modifier = {
						add = 5
						is_of_minor_interest_to_root_trigger = yes
					}
				}
				save_scope_as = food_lover_1
				court_event_character_flag_effect = yes
				change_current_weight = 15
			}
			random_courtier_or_guest = {
				limit = {
					is_available_ai_adult = yes
					NOR = {
						has_trait = temperate
						has_trait = inappetetic
						has_relation_rival = root
					}
					NOT = {
						this = scope:food_lover_1
					}
				}
				weight = {
					base = 1
					modifier = {
						add = 100
						loves_food_trigger = yes
					}
					modifier = {
						add = 50
						has_relation_potential_friend = root
					}
					modifier = {
						add = 10
						is_of_major_interest_to_root_trigger = yes
					}
					modifier = {
						add = 5
						is_of_minor_interest_to_root_trigger = yes
					}
				}
				save_scope_as = food_lover_2
				court_event_character_flag_effect = yes
				change_current_weight = 15
			}
			random_courtier_or_guest = {
				limit = {
					is_available_ai_adult = yes
					NOR = {
						has_trait = temperate
						has_trait = inappetetic
						has_relation_rival = root
					}
					NOR = {
						this = scope:food_lover_1
						this = scope:food_lover_2
					}
				}
				weight = {
					base = 1
					modifier = {
						add = 100
						loves_food_trigger = yes
					}
					modifier = {
						add = 50
						has_relation_potential_friend = root
					}
					modifier = {
						add = 10
						is_of_major_interest_to_root_trigger = yes
					}
					modifier = {
						add = 5
						is_of_minor_interest_to_root_trigger = yes
					}
				}
				save_scope_as = food_lover_3
				court_event_character_flag_effect = yes
				change_current_weight = 15
			}
		}
	}

	option = { # Befriend food lover 1
		name = court.9100.a
		
		progress_towards_friend_effect = {
			REASON = friend_fellow_food_lover
			CHARACTER = scope:food_lover_1
			OPINION = default_friend_opinion
		}
		
		stress_impact = {
			sadistic = massive_stress_impact_gain
			shy = major_stress_impact_gain
			arrogant = medium_stress_impact_gain
			callous = medium_stress_impact_gain
			impatient = medium_stress_impact_gain
			temperate = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0.1
				OR = {
					has_trait = sadistic
					has_trait = shy
					has_trait = arrogant
					has_trait = callous
					has_trait = impatient
					has_trait = temperate
				}
			}
		}
	}

	option = { # Befriend food lover 2
		name = court.9100.b
		
		progress_towards_friend_effect = {
			REASON = friend_fellow_food_lover
			CHARACTER = scope:food_lover_2
			OPINION = default_friend_opinion
		}
		
		stress_impact = {
			sadistic = massive_stress_impact_gain
			shy = major_stress_impact_gain
			arrogant = medium_stress_impact_gain
			callous = medium_stress_impact_gain
			impatient = medium_stress_impact_gain
			temperate = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0.1
				OR = {
					has_trait = sadistic
					has_trait = shy
					has_trait = arrogant
					has_trait = callous
					has_trait = impatient
					has_trait = temperate
				}
			}
		}
	}
	
	option = { # Befriend food lover 3
		name = court.9100.c
		
		progress_towards_friend_effect = {
			REASON = friend_fellow_food_lover
			CHARACTER = scope:food_lover_3
			OPINION = default_friend_opinion
		}
		
		stress_impact = {
			sadistic = massive_stress_impact_gain
			shy = major_stress_impact_gain
			arrogant = medium_stress_impact_gain
			callous = medium_stress_impact_gain
			impatient = medium_stress_impact_gain
			temperate = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0.1
				OR = {
					has_trait = sadistic
					has_trait = shy
					has_trait = arrogant
					has_trait = callous
					has_trait = impatient
					has_trait = temperate
				}
			}
		}
	}
	
	option = { # Let them enjoy themselves in peace!
		name = court.9100.d
		
		change_current_court_grandeur = medium_court_grandeur_gain
		
		add_prestige = minor_prestige_gain
		
		stress_impact = {
			gregarious = major_stress_impact_gain
			gluttonous = medium_stress_impact_gain
			fickle = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0.1
				OR = {
					has_trait = gregarious
					has_trait = gluttonous
					has_trait = fickle
				}
			}
		}
	}
	after = {
		scope:food_lover_1 = {
			clear_court_event_participation = yes
		}
		scope:food_lover_2 = {
			clear_court_event_participation = yes
		}
		scope:food_lover_3 = {
			clear_court_event_participation = yes
		}
	}
}

#########################
# Bacchanalian Bonding
# by Alexander Oltner
#########################

# Two courtiers bond over good food, and praise you!
court.9200 = {
	type = court_event
	title = court.9200.t
	desc = court.9200.desc
	theme = court

	court_scene = {
		button_position_character = scope:food_lover_1
		roles = {
			scope:food_lover_1 = {
				group = event_group
				animation = ecstasy
			}
			scope:food_lover_2 = {
				group = event_group
				animation = admiration
			}
		}
	}
	
	cooldown = {
		years = 10
	}
	
	trigger = {
		is_available = yes
		age >= 10
		amenity_level = { type = court_food_quality value >= 3 }
		any_courtier_or_guest = {
			is_available_ai_adult = yes
			has_court_event_flag = no
			NOR = {
				has_trait = temperate
				has_trait = inappetetic
				has_relation_rival = root
			}
			count >= 2
		}
	}

	weight_multiplier = {
		base = 1

		# Court weightings.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_diplomatic }
	}

	immediate = {
		hidden_effect = {
			random_courtier_or_guest = {
				limit = {
					is_available_ai_adult = yes
					NOR = {
						has_trait = temperate
						has_trait = inappetetic
						has_relation_rival = root
					}
				}
				weight = {
					base = 1
					modifier = {
						add = 100
						loves_food_trigger = yes
					}
					modifier = {
						add = 50
						has_relation_potential_friend = root
					}
					modifier = {
						add = 10
						is_of_major_interest_to_root_trigger = yes
					}
					modifier = {
						add = 5
						is_of_minor_interest_to_root_trigger = yes
					}
				}
				save_scope_as = food_lover_1
				court_event_character_flag_effect = yes
				change_current_weight = 15
			}
			random_courtier_or_guest = {
				limit = {
					is_available_ai_adult = yes
					NOR = {
						has_trait = temperate
						has_trait = inappetetic
						has_relation_rival = root
					}
					NOT = {
						this = scope:food_lover_1
					}
				}
				weight = {
					base = 1
					modifier = {
						add = 100
						loves_food_trigger = yes
					}
					modifier = {
						add = 50
						has_relation_potential_friend = root
					}
					modifier = {
						add = 10
						is_of_major_interest_to_root_trigger = yes
					}
					modifier = {
						add = 5
						is_of_minor_interest_to_root_trigger = yes
					}
				}
				set_favorite_treat_effect = yes
				save_scope_as = food_lover_2
				court_event_character_flag_effect = yes
				change_current_weight = 15
			}
		}
		scope:food_lover_1 = {
			if = {
				limit = {
					can_set_relation_friend_trigger = { CHARACTER = scope:food_lover_2 }
				}
				set_relation_friend = { reason = friend_bonded_over_food target = scope:food_lover_2 }
			}
		}
	}

	option = { # Join in and eat!
		name = court.9200.a
		
		hidden_effect = {
			change_current_weight = 15
		}
		scope:food_lover_1 = {
			add_opinion = {
				modifier = feast_amazing_food_glutton_opinion
				target = root
				opinion = 15
			}
			hidden_effect = {
				random = {
					chance = 50
					if = {
						limit = {
							can_set_relation_potential_friend_trigger = { CHARACTER = root }
						}
						set_relation_potential_friend = root
					}
				}
			}
		}
		scope:food_lover_2 = {
			add_opinion = {
				modifier = feast_amazing_food_glutton_opinion
				target = root
				opinion = 15
			}
			hidden_effect = {
				random = {
					chance = 50
					if = {
						limit = {
							can_set_relation_potential_friend_trigger = { CHARACTER = root }
						}
						set_relation_potential_friend = root
					}
				}
			}
		}
		
		stress_impact = {
			base = major_stress_loss
			temperate = massive_stress_impact_gain
			paranoid = major_stress_impact_gain
			shy = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0.1
				OR = {
					has_trait = temperate
					has_trait = shy
					has_trait = paranoid
				}
			}
		}
	}

	option = { # Shower them in treats
		name = court.9200.b
		
		remove_short_term_gold = minor_gold_value
		
		change_current_court_grandeur = medium_court_grandeur_gain
		dynasty = {
			add_dynasty_prestige = minor_dynasty_prestige_gain
		}
		
		scope:food_lover_1 = {
			add_opinion = {
				modifier = feast_amazing_food_glutton_opinion
				target = root
				opinion = 25
			}
			hidden_effect = {
				random = {
					chance = 50
					if = {
						limit = {
							can_set_relation_potential_friend_trigger = { CHARACTER = root }
						}
						set_relation_potential_lover = root
					}
				}
			}
		}
		scope:food_lover_2 = {
			add_opinion = {
				modifier = feast_amazing_food_glutton_opinion
				target = root
				opinion = 25
			}
			hidden_effect = {
				random = {
					chance = 50
					if = {
						limit = {
							can_set_relation_potential_friend_trigger = { CHARACTER = root }
						}
						set_relation_potential_lover = root
					}
				}
			}
		}
		
		
		
		stress_impact = {
			greedy = massive_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0.1
				OR = {
					has_trait = greedy
				}
			}
		}
	}
	
	option = { # Let them be!
		name = court.9200.c
		
		add_prestige = minor_prestige_gain
		
		stress_impact = {
			gregarious = massive_stress_impact_gain
			gluttonous = medium_stress_impact_gain
			fickle = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0.1
				OR = {
					has_trait = gregarious
					has_trait = gluttonous
					has_trait = fickle
				}
			}
		}
	}
	after = {
		scope:food_lover_1 = {
			clear_court_event_participation = yes
		}
		scope:food_lover_2 = {
			clear_court_event_participation = yes
		}
	}
}

#########################
# Overt Overindulgence
# by Alexander Oltner
#########################

# Someone eats all of the food!
court.9300 = {
	type = court_event
	title = court.9300.t
	desc = court.9300.desc
	theme = court

	court_scene = {
		button_position_character = scope:worried_courtier
		roles = {
			scope:worried_courtier = {
				group = event_group
				animation = fear
			}
			scope:overindulger_target = {
				group = event_group
				animation = admiration
			}
		}
	}
	
	cooldown = {
		years = 30
	}
	
	trigger = {
		is_available = yes
		age >= 10
		amenity_level = { type = court_food_quality value >= 3 }
		any_courtier = {
			is_available_ai_adult = yes
			has_court_event_flag = no
			save_temporary_scope_as = another_courtier_check
		}
		any_courtier_or_guest = {
			is_available_ai_adult = yes
			has_court_event_flag = no
			NOR = {
				has_trait = temperate
				has_trait = inappetetic
				this = scope:another_courtier_check
			}
		}
	}

	weight_multiplier = {
		base = 1

		# Court weightings.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_diplomatic }
	}

	immediate = {
		random_courtier_or_guest = {
			limit = {
				is_available_ai_adult = yes
				NOR = {
					has_trait = temperate
					has_trait = inappetetic
				}
			}
			weight = {
				base = 1
				modifier = {
					add = 100
					loves_food_trigger = yes
				}
				modifier = {
					add = -10
					is_of_major_interest_to_root_trigger = yes
				}
				modifier = {
					add = 5
					is_of_minor_interest_to_root_trigger = yes
				}
			}
			hidden_effect = {
				change_current_weight = 100
				set_favorite_treat_effect = yes
				assign_quirk_effect = yes
				if = {
					limit = {
						NOT = {
							has_trait = comfort_eater
						}
					}
					add_trait = comfort_eater
				}
			}
			save_scope_as = overindulger_target
			court_event_character_flag_effect = yes
		}
		random_courtier = {
			limit = {
				is_available_ai_adult = yes
				NOT = {
					this = scope:overindulger_target
				}
			}
			weight = {
				base = 1
				modifier = {
					add = 100
					is_knight = yes
				}
			}
			save_scope_as = worried_courtier
			court_event_character_flag_effect = yes
		}
	}

	option = { # Stealing the King's treats, are we!?
		name = court.9300.a

		rightfully_imprison_character_effect = {
			TARGET = scope:overindulger_target
			IMPRISONER = root
		}
		
		scope:overindulger_target = {
			progress_towards_rival_effect = {
				CHARACTER = root
				REASON = rival_overindulger_jailed
				OPINION = 0
			}
			pay_short_term_gold = {
				target = root
				gold = root.tiny_gold_value
			}
		}
		
		stress_impact = {
			forgiving = massive_stress_impact_gain
			compassionate = major_stress_gain
			patient = major_stress_impact_gain
			humble = medium_stress_impact_gain
			calm = medium_stress_impact_gain
			trusting = minor_stress_impact_gain
		}
		ai_chance = {
			base = 0
			modifier = {
				add = ai_vengefulness
			}
		}
	}

	option = { # By the gods, man, stop eating!
		name = court.9300.b
		
		duel = {
			skill = diplomacy
			value = 12

			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}

				desc = court.9300.b.success
				send_interface_toast = {
					title = court.9300.b.success
					left_icon = scope:overindulger_target
					
					scope:overindulger_target = {
						add_opinion = {
							target = root
							modifier = grateful_opinion
							opinion = 15
						}
						progress_towards_friend_effect = {
							REASON = friend_saved_me_from_myself
							CHARACTER = root
							OPINION = 0
						}
						pay_short_term_gold = {
							target = root
							gold = root.tiny_gold_value
						}
					}
				}
			}
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}

				desc = court.9300.b.failure
				send_interface_toast = {
					title = court.9300.b.failure
					left_icon = scope:overindulger_target

					scope:overindulger_target = {
						add_opinion = {
							target = root
							modifier = disappointed_opinion
							opinion = -25
						}
						progress_towards_rival_effect = {
							CHARACTER = root
							REASON = rival_overindulger_shamed
							OPINION = 0
						}
					}
				}
			}
		}
		
		stress_impact = {
			vengeful = massive_stress_impact_gain
			paranoid = major_stress_gain
			cynical = major_stress_impact_gain
			fickle = medium_stress_impact_gain
			cynical = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0.1
				ai_compassion <= low_positive_ai_value
			}
		}
	}

	option = { # Have them compensate you
		name = court.9300.c
		
		
		scope:overindulger_target = {
			pay_short_term_gold = {
				target = root
				gold = root.tiny_gold_value
			}
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -15
			}
		}
		
		stress_impact = {
			forgiving = massive_stress_impact_gain
			generous = medium_stress_impact_gain
			vengeful = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
		}
	}

	option = { # You're barred from the pantry...
		name = court.9300.d
		
		scope:overindulger_target = {
			add_opinion = {
				target = root
				opinion = -5
				modifier = disappointed_opinion
			}
			hidden_effect = {
				random = {
					chance = 50
					if = {
						limit = {
							can_set_relation_potential_rival_trigger = { CHARACTER = root }
						}
						set_relation_potential_rival = root
					}
				}
			}
		}
		
		stress_impact = {
			greedy = medium_stress_impact_gain
			ambitious = medium_stress_impact_gain
			wrathful = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0.1
				ai_vengefulness >= low_positive_ai_value
			}
		}
	}
	after = {
		scope:overindulger_target = {
			clear_court_event_participation = yes
		}
		scope:worried_courtier = {
			clear_court_event_participation = yes
		}
	}
}

#########################
# Pie-based Shenanigans
# by Alexander Oltner
#########################

scripted_trigger court_9400_court_jester_trigger = {
	is_available_ai_adult = yes
	has_court_position = court_jester_court_position
	has_trait = dwarf
}

scripted_trigger court_9400_courtier_trigger = {
	is_available_ai_adult = yes
	NOR = {
		has_court_position = court_jester_court_position
		is_cannibal_trigger = yes
	}
}

# Court Jester pie event, loosely based on Jeffrey Hudson
court.9400 = {
	type = court_event
	title = court.9400.t
	desc = court.9400.desc
	theme = court

	court_scene = {
		button_position_character = scope:pie_presenting_courtier
		roles = {
			scope:pie_presenting_courtier = {
				group = event_group
				animation = ecstasy
			}
			scope:court_jester = {
				group = event_group
				animation = happiness
			}
		}
	}
	
	cooldown = {
		years = 15
	}
	
	trigger = {
		is_available = yes
		age >= 10
		amenity_level = { type = court_food_quality value >= 2 }
		amenity_level = { type = court_servants value >= 2 }
		any_courtier = {
			court_9400_court_jester_trigger = yes
			has_court_event_flag = no
		}
		any_courtier = {
			court_9400_courtier_trigger = yes
			has_court_event_flag = no
		}
	}

	weight_multiplier = {
		base = 1

		# Court weightings.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_intrigue }
	}

	immediate = {
		save_scope_as = you_target
		random_courtier = {
			limit = {
				court_9400_court_jester_trigger = yes
			}
			save_scope_as = court_jester
			court_event_character_flag_effect = yes
		}
		random_courtier = {
			limit = {
				court_9400_courtier_trigger = yes
			}
			weight = {
				base = 1
				modifier = {
					add = 10
					is_of_major_interest_to_root_trigger = yes
				}
				modifier = {
					add = 5
					is_of_minor_interest_to_root_trigger = yes
				}
			}
			save_scope_as = pie_presenting_courtier
			court_event_character_flag_effect = yes
		}
		scope:pie_presenting_courtier = {	
			progress_towards_friend_effect = {
				REASON = friend_played_trick_on_liege
				CHARACTER = scope:court_jester
				OPINION = 0
			}
		}
	}

	option = { # My favorite meal!
		name = court.9400.a
		
		trait = cannibal
		
		trigger = {
			is_cannibal_trigger = yes
		}
		
		if = {
			limit = {
				any_secret = {
					secret_type = secret_cannibal
					NOT = {
						is_known_by = scope:pie_presenting_courtier
					}
				}
			}
			random_secret = {
				limit = {
					secret_type = secret_cannibal
					NOT = {
						is_known_by = scope:pie_presenting_courtier
					}
				}
				reveal_to = scope:pie_presenting_courtier
			}
		}
		
		scope:pie_presenting_courtier = {
			add_opinion = {
				target = root
				modifier = absolutely_horrified_opinion
			}
		}
		
		add_character_modifier = {
			modifier = best_meal_of_my_life_modifier
			years = 15
		}
		
		unknown_murder_effect = {
			VICTIM = scope:court_jester
			MURDERER = root
			REASON = death_eaten
		}
		
		stress_impact = {
			base = massive_stress_impact_loss
			compassionate = massive_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				has_trait = compassionate
			}
		}
	}

	option = { # Reward them
		name = court.9400.b
		
		pay_short_term_gold = {
			target = scope:court_jester
			gold = root.tiny_gold_value
		}
		
		progress_towards_friend_effect = {
			REASON = friend_gave_gold
			CHARACTER = scope:court_jester
			OPINION = 0
		}
		
		scope:pie_presenting_courtier = {
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 25
			}
		}
		
		change_current_court_grandeur = medium_court_grandeur_gain
		
		stress_impact = {
			base = medium_stress_impact_loss
			paranoid = massive_stress_impact_gain
			greedy = massive_stress_impact_gain
			arrogant = medium_stress_impact_gain
			arbitrary = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0.1
				ai_compassion <= low_positive_ai_value
			}
			modifier = {
				factor = 0.1
				ai_greed >= low_positive_ai_value
			}
			modifier = {
				factor = 0
				has_trait = paranoid
			}
		}
	}

	option = { # Imprison them!
		name = court.9400.c

		rightfully_imprison_character_effect = {
			TARGET = scope:court_jester
			IMPRISONER = root
		}
		
		If = {
			limit = {
				is_ai = yes
			}
			execute_prisoner_effect = {
				VICTIM = scope:court_jester
				EXECUTIONER = root
			} 
		}
		
		add_character_modifier = {
			modifier = suspicious_against_pies_modifier
			years = 15
		}
		
		scope:court_jester = {	
			progress_towards_rival_effect = {
				CHARACTER = root
				REASON = rival_jester_jailed
				OPINION = 0
			}
		}
		
		scope:pie_presenting_courtier = {	
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -25
			}
		}
		
		stress_impact = {
			base = major_stress_impact_gain
			paranoid = massive_stress_impact_loss
			compassionate = medium_stress_impact_gain
			forgiving = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				NOT = {
					has_trait = paranoid
				}
			}
		}
	}

	option = { # Har har! Fantastic!
		name = court.9400.d
		
		scope:pie_presenting_courtier = {
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 10
			}
		}
		
		stress_impact = {
			base = medium_stress_impact_loss
			paranoid = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				has_trait = paranoid
			}
		}
	}
	after = {
		scope:pie_presenting_courtier = {
			clear_court_event_participation = yes
		}
		scope:court_jester = {
			clear_court_event_participation = yes
		}
	}
}

#########################
# A Little Language
# by Alexander Oltner
#########################

scripted_trigger appropriate_tutor_trigger = {
	is_available_ai_adult = yes
	OR = {
		AND = {
			learning >= 10
			OR = {
				has_court_position = court_tutor_court_position
				has_trait = eunuch
			}
		}
		learning >= 20
	}
}

scripted_trigger appropriate_child_trigger = {
	age <= 20
	is_incapable = no
	is_imprisoned = no
	is_alive = yes
	is_ruler = no
	is_courtier_of = root
	culture = root.culture
	num_of_known_languages < 2
}

scripted_trigger has_a_good_language_trigger = {
	culture = {
		NOT = {
			has_same_culture_language = root.culture
		}
	}
}

# Someone offers to teach your child a language
court.9500 = {
	type = court_event
	title = court.9500.t
	desc = court.9500.desc
	theme = court
	
	cooldown = {
		years = 10
	}
	
	court_scene = {
		button_position_character = scope:child_to_learn_language
		roles = {
			scope:child_to_learn_language = {
				group = event_group
				animation = dismissal
			}
		}
		roles = {
			scope:teacher_target = {
				group = event_group
				animation = personality_rational
			}
		}
	}
	
	trigger = {
		is_landed = yes
		is_available_adult = yes
		any_child = {
			appropriate_child_trigger = yes
			has_court_event_flag = no
			save_temporary_scope_as = temp_child_to_learn_lang
		}
		OR = { # There must be a useful language to learn
			any_sub_realm_county = {
				has_a_good_language_trigger = yes
			}
			any_vassal = {
				has_a_good_language_trigger = yes
			}
			any_liege_or_above = {
				has_a_good_language_trigger = yes
			}
			AND = {
				exists = faith.religious_head
				faith.religious_head = {
					has_a_good_language_trigger = yes
				}
			}
		}
		any_courtier_or_guest = {
			appropriate_tutor_trigger = yes
			has_court_event_flag = no
			NOT = { this = scope:temp_child_to_learn_lang }
		}
	}

	weight_multiplier = {
		base = 1

		# Court weightings.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_scholarly }
	}

	immediate = {
		random_child = { # Pick a good child
			limit = {
				appropriate_child_trigger = yes
			}
			weight = { # Prefer primary heir
				base = 1
				modifier = {
					add = 100
					this = root.player_heir
				}
			}
			save_scope_as = child_to_learn_language
			court_event_character_flag_effect = yes
		}
		
		every_sub_realm_county = { # Pick a culture to take the language from
			limit = {
				has_a_good_language_trigger = yes
			}
			culture = {
				if = {
					limit = {
						NOT = {
							is_in_list = potential_language_cultures
						}
					}
				}
				add_to_list = potential_language_cultures
			}
		}
		every_vassal = {
			limit = {
				has_a_good_language_trigger = yes
			}
			culture = {
				if = {
					limit = {
						NOT = {
							is_in_list = potential_language_cultures
						}
					}
				}
				add_to_list = potential_language_cultures
			}
		}
		every_liege_or_above = {
			limit = {
				has_a_good_language_trigger = yes
			}
			culture = {
				if = {
					limit = {
						NOT = {
							is_in_list = potential_language_cultures
						}
					}
				}
				add_to_list = potential_language_cultures
			}
		}
		if = {
			limit = {
				exists = faith.religious_head
				faith.religious_head = {
					has_a_good_language_trigger = yes
				}
			}
			faith.religious_head.culture = {
				if = {
					limit = {
						NOT = {
							is_in_list = potential_language_cultures
						}
					}
				}
				add_to_list = potential_language_cultures
			}
		}
		
		random_in_list = { # Pick the best culture language
			list = potential_language_cultures
			weight = {
				base = 1
				modifier = { # Vassal languages are objectively best to learn
					add = 10
					save_temporary_scope_as = culture_check
					root = {
						any_vassal = {
							culture = scope:culture_check
						}
					}
				}
			}
			save_scope_as = culture_language_to_learn
		}
		
		random_courtier_or_guest = {
			limit = {
				appropriate_tutor_trigger = yes
				NOT = {
					this = scope:child_to_learn_language
				}
			}
			weight = {
				base = 1
				modifier = {
					add = 100
					has_court_position = court_tutor_court_position
				}
				modifier = {
					add = 50
					has_trait = eunuch
				}
			}
			hidden_effect = {
				assign_quirk_effect = yes
				if = {
					limit = {
						NOT = {
							knows_language_of_culture = scope:culture_language_to_learn
						}
					}
					learn_language_of_culture = scope:culture_language_to_learn
				}
			}
			save_scope_as = teacher_target
			court_event_character_flag_effect = yes
		}
	}

	option = { # Pay more than needed; your child must learn!
		name = court.9500.a
		
		pay_short_term_gold = {
			target = scope:teacher_target
			gold = root.medium_gold_value
		}
		
		scope:teacher_target = {
			add_opinion = {
				target = root
				opinion = 10
				modifier = grateful_opinion
			}
		}
		
		scope:child_to_learn_language = {
			learn_language_of_culture = scope:culture_language_to_learn
		}
		
		stress_impact = {
			greedy = massive_stress_impact_gain
			paranoid = major_stress_gain
			arrogant = major_stress_impact_gain
			fickle = medium_stress_impact_gain
			cynical = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0.1
				ai_greed >= low_positive_ai_value
			}
		}
	}

	option = { # Pay what they ask, and hope your child manages
		name = court.9500.b
		
		pay_short_term_gold = {
			target = scope:teacher_target
			gold = root.tiny_gold_value
		}
		
		scope:child_to_learn_language = {
			duel = {
				skill = learning
				value = 6

				50 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = 3.5
						min = -49
					}
					

					desc = court.9500.b.success
					root = {
						send_interface_toast = {
							title = court.9500.b.success
							left_icon = scope:child_to_learn_language
							right_icon = scope:teacher_target
							
							scope:child_to_learn_language = {
								learn_language_of_culture = scope:culture_language_to_learn
							}
						}
					}
				}
				50 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = -3.5
						min = -49
					}

					desc = court.9500.b.failure
					root = {
						send_interface_toast = {
							title = court.9500.b.failure
							left_icon = scope:child_to_learn_language
							right_icon = scope:teacher_target
							
							scope:child_to_learn_language = {
								add_stress = major_stress_gain
							}
						}
					}
				}
			}
		}
		
		stress_impact = {
			generous = major_stress_impact_gain
			patient = medium_stress_impact_gain
			humble = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0.1
				ai_greed >= low_positive_ai_value
			}
		}
	}

	option = { # Deny
		name = court.9500.c
		
		scope:teacher_target = {
			add_opinion = {
				target = root
				opinion = -5
				modifier = disappointed_opinion
			}
		}
		
		stress_impact = {
			diligent = medium_stress_impact_gain
			gregarious = medium_stress_impact_gain
			ambitious = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
		}
	}
	after = {
		scope:teacher_target = {
			clear_court_event_participation = yes
		}
		scope:child_to_learn_language = {
			clear_court_event_participation = yes
		}
	}
}
