﻿namespace = court

##################################################
# # RANGES
# 0001 - 0099		Misc Events
# 0100 - 0999 		James
# 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 = {
#				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 = {
		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
		}
		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
			court_position:court_tutor_court_position = { has_trait = journaller }
		}
		modifier = {
			add = 0.5
			court_position:court_tutor_court_position = {
				OR = {
					has_trait = intellect_good_1
					has_trait = intellect_good_2
					has_trait = intellect_good_3
				}
			}
		}
		modifier = {
			add = -0.5
			court_position:court_tutor_court_position = {
				OR = {
					has_trait = intellect_bad_1
					has_trait = intellect_bad_2
					has_trait = intellect_bad_3
				}
			}
		}
	}

	immediate = {
		random_court_position_holder = {
			type = court_tutor_court_position
			limit = {
				is_available_ai_adult = yes
				has_court_event_flag = no
			}
			save_scope_as = tutor
			court_event_character_flag_effect = yes
		}
		random_child = {
			limit = {
				is_available_child = yes
				age >= 6
				OR = {
					has_trait = bossy
					has_trait = rowdy
				}
			}
			alternative_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
		}
		custom_tooltip = court.0107.a.tt.1
		hidden_effect = {
			scope:unruly_child = {
				education_point_acquisition_effect = yes
			}
		}
		custom_tooltip = court.0107.a.tt.2
		scope:tutor = {
			add_character_flag = {
				flag = court_0107_tutor
				years = 20
			}
		}
		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 - opt out
	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 = {
			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 }
		}
		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
		is_valid_for_east_asian_events_trigger = no
		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
		}
		any_kingdom = {
			holder ?= {
				is_ai = yes
				NOT = {
					in_diplomatic_range = root
				}
			}
		}
		court_grandeur_current_level >= medium_court_grandeur_level
	}

	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
					}
				}
				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
		scope:foreign_prince = {
			pay_short_term_gold = {
				target = root
				gold = 50_percent_of_owned_gold
			}
		}
		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
		scope:foreign_prince = {
			pay_short_term_gold = {
				target = root
				gold = 80_percent_of_owned_gold
			}
		}
		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 = 20 }

	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 }
		}
	}

	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 = {
					this != scope:executioner
				}
			}
			random_court_position_holder = {
				type = court_physician_court_position
				limit = { 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
	 	}

	 	court_position_grant_effect = { POS = court_physician CANDIDATE = scope:executioner EMPLOYER = root }

		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 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
	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 = 3
		modifier = {
			add = 1
			court_position:executioner_court_position = {
				has_trait = sadistic
			}
		}
		modifier = {
			add = 1
			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
			}
		}
		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								#
#####################################

# Someone has been hiding a cadaver in the closet

scripted_trigger valid_lady_in_waiting_like_character_trigger = {
	is_available_ai_adult = yes
	has_court_event_flag = no
	trigger_if = {
		limit = {
			root = { is_female = yes }
		}
		is_female = yes
	}
	trigger_else = {
		is_male = yes
	}
	OR = {
		has_trait = sadistic
		has_trait = callous
		has_trait = wrathful
		has_trait = craven
		has_trait = paranoid
	}
	OR = {
		has_court_position = lady_in_waiting_court_position
		is_of_major_or_minor_interest_trigger = { CHARACTER = root }
	}
	NOT = {
		is_close_family_of = root
	}
}

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 = 20 }

	trigger = {
		any_courtier = {
			valid_lady_in_waiting_like_character_trigger = yes
		}
		any_pool_character = {
            province = root.capital_province
			is_available_ai_adult = yes
			NOT = { exists = scope:inspiration }
		}
		is_available_adult = yes
	}

	weight_multiplier = {
		base = 0.5
		modifier = {
			amenity_level = {
				target = court_fashion
				value > medium_amenity_level
			}
			add = 0.5
		}
		modifier = {
			add = 0.5
			employs_court_position = lady_in_waiting_court_position
		}
	}

	immediate = {
      	random_courtier = {
			limit = {
				valid_lady_in_waiting_like_character_trigger = yes
				has_court_position = lady_in_waiting_court_position
			}
			alternative_limit = {
				valid_lady_in_waiting_like_character_trigger = yes
			}
      		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 = {
				type = secret_murder
				limit = {
					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 = {
				type = secret_murder
				limit = {
					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
	 	}
		 scope:guilty_courtier = {
			random_secret = {
				type = secret_murder
				limit = {
					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
		}
	}
}



##################################################
# 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.
##################################################

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

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

scripted_trigger court_2201_valid_basic_heir_child_trigger = {
	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
	# Is the eldest heir of root.
	save_temporary_scope_as = eldest_heir_temp
	root = {
		player_heir_position = {
			value = 0 #player heir
			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 = {
		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_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
			}
		}
	}

	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 = {
		is_at_war_with = root
	}
	# Has a royal court, and therefore amenities.
	has_royal_court = yes
	# Is more fashionable.
	amenity_level = {
		target = court_fashion
		value > medium_amenity_level
	}
}

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

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

	cooldown = { years = 15 }

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

	trigger = {
		# DLC check.
		has_royal_court = yes
		# Standard checks.
		is_available_adult = yes
		is_landed = yes
		# Low fashion amenity.
		amenity_level = {
			target = 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
			is_available_ai_adult = yes
			has_court_event_flag = no
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			amenity_level = {
				target = court_fashion
				value <= low_amenity_level
			}
			add = 1
		}
		modifier = {
			any_neighboring_and_across_water_realm_same_rank_owner = {
				court_2401_valid_neighbouring_ruler_trigger = yes
				amenity_level = {
					target = court_fashion
					value >= high_amenity_level
				}
			}
			add = 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
				is_available_ai_adult = 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
		}
	}

	# 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
		# Increase your amenities
		add_amenity_level = { type = court_fashion value = 1 }
		# 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
				ai_greed = -0.5
			}
		}
	}

	# 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
		# But upset scope:seller
		reverse_add_opinion = {
			target = scope:seller
			modifier = angry_opinion
			opinion = -30
		}
		#And loss a little CGV.
		change_current_court_grandeur = minor_court_grandeur_loss
		#But gain tiny legitimacy
		add_legitimacy = miniscule_legitimacy_gain

		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:seller = {
			clear_court_event_participation = yes
		}
	}
}



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

##################################################
# 3040 - 3049	Homesick MotherFather
# 3060 - 3069	A Feline Hunter
##################################################

#####################################
# 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_trigger court_3010_inspired_work_courtier_trigger = {
	is_available_ai_adult = yes
	NOR = {
		exists = scope:inspiration
		exists = inspiration
	}
	NOR = {
		has_trait = blind
		has_relation_rival = root
		has_relation_potential_rival = root
		has_relation_nemesis = root
	}
	learning >= 10
	diplomacy >= 12
}

## An inspired courtier
court.3011 = {
	type = character_event
	title = court.3010.t
	desc = {
		desc = court.3011.desc.opening
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:inspired_writer = {
						OR = {
							has_trait = shy
							has_trait = chaste
						}
					}
				}
				desc = court.3011.desc.shy_or_chaste
			}
			triggered_desc = {
				trigger = {
					scope:inspired_writer = {
						OR = {
							has_trait = adventurer
							has_trait = pilgrim
							has_trait = lifestyle_traveler
						}
					}
				}
				desc = court.3011.desc.adventurer_or_pilgrim
			}
			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 = {
		has_ep1_dlc_trigger = yes
		NOT = { has_trait = blind }
		has_royal_court = yes
		any_courtier_or_guest = {
			court_3010_inspired_work_courtier_trigger = yes
		}
	}

	immediate = {
		random_courtier_or_guest = {
			limit = {
				court_3010_inspired_work_courtier_trigger = yes
			}
			save_scope_as = inspired_writer
		}
	}

	# Option A: Encourage them to keep writing
	option = {
		name = court.3011.a
		custom_tooltip = court.3011.c.tt.gain_inspiration
		scope:inspired_writer = { create_inspiration = book_inspiration }
		progress_towards_friend_effect = {
			REASON = friend_believed_in_my_writing
			CHARACTER = scope:inspired_writer
			OPINION = 20
		}
		stress_impact = {
			callous = medium_stress_impact_gain
			arrogant = medium_stress_impact_gain
			sadistic = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_sociability = 1
			}
		}
	}

	# Option C: You tell them to stop
	option = {
		name = court.3011.c
		custom_tooltip = court.3011.c.tt.hurt
		add_prestige = minor_prestige_gain
		reverse_add_opinion = {
			target = scope:inspired_writer
			modifier = cruelty_opinion
			opinion = -20
		}
		stress_impact = {
			gregarious = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
		}
		ai_chance = {
			base = 75
			ai_value_modifier = {
				ai_sociability = -1
			}
		}
	}
}
#
######################################
## Lady-in-Waiting Events			 #
## by Bianca Savazzi				 #
## 3031								 #
######################################
#
## Court position smooths things over with people
court.3031 = {
	type = court_event
	title = court.3031.t
	desc = court.3031.desc
	theme = court
	cooldown = { years = 15 }
	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
		OR = {
			AND = {
				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
				}
			}
			AND = {
				employs_court_position = cultural_emissary_court_position
				any_court_position_holder = {
					type = cultural_emissary_court_position
					is_available_ai_adult = yes
					has_court_event_flag = no
				}
			}
			AND = {
				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
				}
			}
			AND = {
				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_vassal = {
			count > 0
			vassal_stance = minority
		}
		any_vassal = {
			count > 0
			vassal_stance = barons_and_minor_landholders
		}
		any_sub_realm_county = {
			culture = {
				NOR = {
					this = root.culture
					this = root.capital_county.culture
				}
			}
		}
	}

	immediate = {
		court_event_character_flag_effect = yes
		random_court_position_holder = {
			type = lady_in_waiting_court_position
			limit = {
				is_available_ai_adult = yes
				has_court_event_flag = no
			}
			save_scope_as = liw
		}
		if = {
			limit = {
				NOT = { exists = scope:liw }
			}
			random_court_position_holder = {
				type = cultural_emissary_court_position
				limit = {
					is_available_ai_adult = yes
					has_court_event_flag = no
				}
				save_scope_as = liw
			}
		}
		if = {
			limit = {
				NOT = { exists = scope:liw }
			}
			random_court_position_holder = {
				type = chief_eunuch_court_position
				limit = {
					is_available_ai_adult = yes
					has_court_event_flag = no
				}
				save_scope_as = liw
			}
		}
		if = {
			limit = {
				NOT = { exists = scope:liw }
			}
			random_court_position_holder = {
				type = court_poet_court_position
				limit = {
					is_available_ai_adult = yes
					has_court_event_flag = no
				}
				save_scope_as = liw
			}
		}
		scope:liw = {
			court_event_character_flag_effect = yes
			assign_quirk_effect = yes
		}
		random_sub_realm_county = {
			limit = {
				culture = {
					NOR = {
						this = root.culture
						this = root.capital_county.culture
					}
				}
			}
			save_scope_as = reference_county
		}
		root = { save_scope_as = root_scope }
	}

	# Option A: Minority vassals
	option = {
		name = court.3031.a
		every_vassal = {
			vassal_stance = minority
			custom = every_minority_vassal
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 10
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 0.5
			}
		}
	}

	# Option B: Baron vassals
	option = {
		name = court.3031.b
		every_vassal = {
			vassal_stance = barons_and_minor_landholders
			custom = every_baron_vassal
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 10
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_sociability = 0.5
			}
		}
	}

	# Option C: Minority culture
	option = {
		name = court.3031.c
		every_sub_realm_county = {
			limit = {
				culture = scope:reference_county.culture
			}
			change_county_control = 5
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 0.5
			}
		}
	}

	# Option D: Nah
	option = {
		name = court.3031.d
		add_prestige = miniscule_prestige_gain
		stress_impact = {
			ambitious = minor_stress_impact_gain
			gregarious = 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 = 20 }
	court_scene = {
		button_position_character = scope:homesick_parent
		roles = {
			scope:homesick_parent = {
				group = event_group
				animation = sadness
			}
			root = {
				group = event_group
				animation = personality_rational
			}
		}
	}
	lower_left_portrait = scope:jester

	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
			is_courtier_of = root
			culture != root.culture
			save_temporary_scope_as = temp_parent_scope
		}
		capital_province.culture = root.culture
	}

	immediate = {
		court_event_character_flag_effect = yes
		random_parent = {
			limit = {
				has_court_event_flag = no
				is_courtier_of = root
				culture != root.culture
			}
			save_scope_as = homesick_parent
			court_event_character_flag_effect = yes
		}
		if = {
			limit = {
				any_pool_character = {
					province = root.location
					culture = scope:homesick_parent.culture
					diplomacy >= 8
					is_available_ai_adult = yes
				}
			}
			random_pool_character = {
				province = root.location
				limit = {
					culture = scope:homesick_parent.culture
					diplomacy >= 8
					is_available_ai_adult = yes
				}
				save_scope_as = jester
			}
		}
		else = {
			create_character = {
				template = jester_template
				location = root.location
				culture = scope:homesick_parent.culture
				faith = scope:homesick_parent.faith
				save_scope_as = jester
			}
		}

		if = {
			limit = {
				OR = {
					can_appoint_char_to_court_position = {
						CHAR = scope:homesick_parent
						COURT_POS = antiquarian_court_position
					}
					can_appoint_char_to_court_position = {
	 					CHAR = scope:homesick_parent
	 					COURT_POS = wet_nurse_court_position
	 				}
					can_appoint_char_to_court_position = {
	 					CHAR = scope:homesick_parent
	 					COURT_POS = keeper_of_swans_court_position
	 				}
					can_appoint_char_to_court_position = {
	 					CHAR = scope:homesick_parent
	 					COURT_POS = court_gardener_court_position
	 				}
					can_appoint_char_to_court_position = {
	 					CHAR = scope:homesick_parent
	 					COURT_POS = lady_in_waiting_court_position
	 				}
					can_appoint_char_to_court_position = {
 	 					CHAR = scope:homesick_parent
 						COURT_POS = court_tutor_court_position
  					}
				}
			}
			random_list = {
				15 = {
					trigger = {
						can_appoint_char_to_court_position = {
							CHAR = scope:homesick_parent
							COURT_POS = antiquarian_court_position
						}
					}
					scope:homesick_parent = { add_character_flag = antiquarian }
				}
				15 = {
					trigger = {
						can_appoint_char_to_court_position = {
	 						CHAR = scope:homesick_parent
	 						COURT_POS = wet_nurse_court_position
	 					}
					}
					scope:homesick_parent = { add_character_flag = wet_nurse }
				}
				15 = {
					trigger = {
						can_appoint_char_to_court_position = {
	 						CHAR = scope:homesick_parent
	 						COURT_POS = keeper_of_swans_court_position
	 					}
					}
					scope:homesick_parent = { add_character_flag = swans }
				}
				15 = {
					trigger = {
						can_appoint_char_to_court_position = {
	 						CHAR = scope:homesick_parent
	 						COURT_POS = court_gardener_court_position
	 					}
					}
					scope:homesick_parent = { add_character_flag = gardener }
				}
				15 = {
					trigger = {
						can_appoint_char_to_court_position = {
	 						CHAR = scope:homesick_parent
	 						COURT_POS = lady_in_waiting_court_position
	 					}
					}
					scope:homesick_parent = { add_character_flag = liw }
				}
				15 = {
					trigger = {
						can_appoint_char_to_court_position = {
 	 						CHAR = scope:homesick_parent
 							COURT_POS = court_tutor_court_position
  						}
					}
					scope:homesick_parent = { add_character_flag = tutor }
				}
			}
		}
	}

	# Option A: increase amenities
	option = {
		name = court.3040.a
		trigger = {
			# The culture of origin has higher court grandeur's courts
			scope:homesick_parent.culture = {
				any_culture_duchy = {
					holder.top_liege ?= {
						has_royal_court = yes
						court_grandeur_current > root.court_grandeur_current
					}
				}
			}
			#Your amenities are not all top level
			OR = {
				amenity_level = {
					target = court_fashion
					value < max_amenity_level
				}
				amenity_level = {
					target = court_lodging_standards
					value < max_amenity_level
				}
				amenity_level = {
					target = court_food_quality
					value < max_amenity_level
				}
				amenity_level = {
					target = court_servants
					value < max_amenity_level
				}
			}
		}
		custom_tooltip = court.3040.a.tt
		hidden_effect = {
			random_list = {
				25 = {
					trigger = {
						amenity_level = {
							target = court_fashion
							value < max_amenity_level
						}
					}
					send_interface_toast = {
						title = court.3040.a.tt_2
						left_icon = scope:homesick_parent
						add_amenity_level = {
							type = court_fashion
							value = 1
						}
					}
				}
				25 = {
					trigger = {
						amenity_level = {
							target = court_lodging_standards
							value < max_amenity_level
						}
					}
					send_interface_toast = {
						title = court.3040.a.tt_2
						left_icon = scope:homesick_parent
						add_amenity_level = {
							type = court_lodging_standards
							value = 1
						}
					}
				}
				25 = {
					trigger = {
						amenity_level = {
							target = court_food_quality
							value < max_amenity_level
						}
					}
					send_interface_toast = {
						title = court.3040.a.tt_2
						left_icon = scope:homesick_parent
						add_amenity_level = {
							type = court_food_quality
							value = 1
						}
					}
				}
				25 = {
					trigger = {
						amenity_level = {
							target = court_servants
							value < max_amenity_level
						}
					}
					send_interface_toast = {
						title = court.3040.a.tt_2
						left_icon = scope:homesick_parent
						add_amenity_level = {
							type = court_servants
							value = 1
						}
					}
				}
			}
		}
		scope:homesick_parent = {
			add_opinion = {
				target = root
				modifier = listened_opinion
			}
		}
		stress_impact = {
			greedy = major_stress_impact_gain
			humble = medium_stress_impact_gain
			temperate = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100

			ai_value_modifier = {
				ai_greed = -1
			}
		}
	}

	# Option B: available job
	option = {
		name = court.3040.b
		trigger = {
			scope:homesick_parent = {
				OR = {
					has_character_flag = antiquarian
					has_character_flag = wet_nurse
					has_character_flag = swans
					has_character_flag = gardener
					has_character_flag = liw
					has_character_flag = tutor
				}
			}
		}
		if = {
			limit = {
				scope:homesick_parent = { has_character_flag = antiquarian }
			}
			court_position_grant_effect = { POS = antiquarian CANDIDATE = scope:homesick_parent EMPLOYER = root }
		}
		else_if = {
			limit = {
				scope:homesick_parent = { has_character_flag = wet_nurse }
			}
			court_position_grant_effect = { POS = wet_nurse CANDIDATE = scope:homesick_parent EMPLOYER = root }
		}
		else_if = {
			limit = {
				scope:homesick_parent = { has_character_flag = swans }
			}
			court_position_grant_effect = { POS = keeper_of_swans CANDIDATE = scope:homesick_parent EMPLOYER = root }
		}
		else_if = {
			limit = {
				scope:homesick_parent = { has_character_flag = gardener }
			}
			court_position_grant_effect = { POS = court_gardener CANDIDATE = scope:homesick_parent EMPLOYER = root }
		}
		else_if = {
			limit = {
				scope:homesick_parent = { has_character_flag = liw }
			}
			court_position_grant_effect = { POS = lady_in_waiting CANDIDATE = scope:homesick_parent EMPLOYER = root }
		}
		else_if = {
			limit = {
				scope:homesick_parent = { has_character_flag = tutor }
			}
			court_position_grant_effect = { POS = court_tutor CANDIDATE = scope:homesick_parent EMPLOYER = root }
		}
		scope:homesick_parent = {
			add_opinion = {
				target = root
				modifier = listened_opinion
			}
		}
		stress_impact = {
			lazy = medium_stress_impact_gain
			content = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100

			modifier = {
				has_trait = lazy
				add = -25
			}
			modifier = {
				has_trait = content
				add = -25
			}
		}
	}

	# Option C: parent's culture's jester
	option = {
		name = court.3040.c
		flavor = court.3040.c.tt
		trigger = {
			exists = scope:jester
		}
		add_courtier = scope:jester
		court_position_grant_effect = { POS = court_jester CANDIDATE = scope:jester EMPLOYER = root }
		stress_impact = {
			gregarious = minor_stress_impact_loss
			shy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100

			modifier = {
				has_trait = shy
				add = -50
			}
		}
	}

	# 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 = 100
			ai_value_modifier = {
				ai_compassion = -1
			}
		}
	}
	after = {
		clear_court_event_participation = yes
		scope:homesick_parent = {
			clear_court_event_participation = yes
			remove_character_flag = antiquarian
			remove_character_flag = wet_nurse
			remove_character_flag = swans
			remove_character_flag = gardener
			remove_character_flag = liw
			remove_character_flag = tutor
		}
		if = {
			limit = {
				is_ai = yes
				scope:jester = {
					NOT = { has_court_position = court_jester_court_position }
				}
			}
			scope:jester = { silent_disappearance_effect = 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 = { 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_if = {
			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 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
		}
	}
}




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

##################################################
# 4750 - 4751	Your court poet is writing a heroic book
##################################################


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

scripted_trigger pope_joan_trigger = {
	faith = faith:catholic
	is_female = yes
	any_held_title = { is_head_of_faith = no }
}

scripted_trigger lady_godiva_trigger = {
	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 }
		}
	}
}

scripted_trigger sinbad_trigger = {
	capital_province = {
		OR = {
			geographical_region = world_middle_east
			geographical_region = world_africa_east
			geographical_region = world_africa_north
		}
	}
}

scripted_trigger caligula_trigger = {
	OR = {
		has_trait = sadistic
		has_trait = torturer
		has_focus = intrigue_intimidation_focus
		has_trait = deviant
		has_trait = lunatic_1
	}
	OR = {
		has_title = title:k_italy
		has_title = title:k_romagna
		has_title = title:k_sardinia
		has_title = title:e_italy
		is_roman_emperor_excluding_byzantium_trigger = yes
		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 = {
	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
}

scripted_trigger valmiki_trigger = {
	root.culture = {
		has_cultural_pillar = heritage_indo_aryan
	}
}

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

	trigger = {
		has_court_event_flag = no
		can_employ_court_position_type = court_poet_court_position
		trigger_if = {
			limit = {
				is_ai = yes
			}
			any_pool_character = {
				province = root.location
				OR = {
					diplomacy >= 14
					has_trait = lifestyle_poet
				}
				is_available_ai_adult = yes
			}
		}
	}
	cooldown = { years = 25 }
	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
		if = {
			limit = {
				any_pool_character = {
					province = root.location
					OR = {
						diplomacy >= 14
						has_trait = lifestyle_poet
					}
					is_available_ai_adult = yes
				}
			}
			random_pool_character = {
				province = root.location
				limit = {
					OR = {
						diplomacy >= 14
						has_trait = lifestyle_poet
					}
					is_available_ai_adult = yes
				}
				save_scope_as = poet
			}
			if = {
				limit = {
					scope:poet = {
						NOT = { has_trait = lifestyle_poet }
					}
				}
				scope:poet = { add_trait = lifestyle_poet }
			}
		}
		else = {
			create_character = {
				template = poet_template
				location = root.location
				save_scope_as = poet
			}
			scope:poet = { add_character_flag = created }
		}
		scope: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
		add_courtier = scope:poet
		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
		add_courtier = scope:poet
		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
		add_courtier = scope:poet
		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
		add_courtier = scope:poet
		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
		add_courtier = scope:poet
		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
		add_courtier = scope:poet
		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
		add_courtier = scope:poet
		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
		stress_impact = {
			lifestyle_poet = major_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = -0.5
				ai_greed = -0.75
			}
		}
	}

	after = {
		if = {
			limit = { NOT = { has_character_flag = rejected_poet } }
			trigger_event = {
				id = court.4751
				days = 90
			}
		}
		else = {
			scope:poet = {
				if = {
					limit = {
						has_character_flag = created
					}
					silent_disappearance_effect = yes
				}
			}
		}
		clear_court_event_participation = yes
		scope:poet ?= {
			clear_court_event_participation = yes
		}
		remove_character_flag = rejected_poet
	}
}

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

	left_portrait = {
		character = root
		animation = reading
	}
	right_portrait = {
		character = scope:poet
		animation = interested
	}

	trigger = {
		scope:poet = {
			is_alive = yes
			is_available = yes
			liege = root
		}
		is_available = 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
		}
		if = {
			limit = { artifacts_use_indian_books_trigger = yes }
			create_artifact = {
				name = pope_joan_book_name
				description = pope_joan_book_desc
				type = book
				visuals = indian_book
				modifier = artifact_monthly_piety_2_modifier
				save_scope_as = pope_joan_book
				save_scope_as = artifact
			}
		}
		else = {
			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
				save_scope_as = artifact
			}
		}
		if = {
			limit = {
				can_appoint_char_to_court_position = {
					CHAR = scope:poet
					COURT_POS = court_poet_court_position
				}
			}
			court_position_grant_effect = { POS = court_poet CANDIDATE = scope:poet EMPLOYER = root }
		}
		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
			root != scope:current_head_of_faith
		}
		if = {
			limit = { artifacts_use_indian_books_trigger = yes }
			create_artifact = {
				name = pope_joan_book_name
				description = pope_joan_book_desc
				type = book
				visuals = indian_book
				modifier = artifact_monthly_piety_2_modifier
				save_scope_as = pope_joan_book
				save_scope_as = artifact
			}
		}
		else = {
			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
				save_scope_as = artifact
			}
		}
		if = {
			limit = {
				can_appoint_char_to_court_position = {
					CHAR = scope:poet
					COURT_POS = court_poet_court_position
				}
			}
			court_position_grant_effect = { POS = court_poet CANDIDATE = scope:poet EMPLOYER = root }
		}
		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
			}
		}
		if = {
			limit = { artifacts_use_indian_books_trigger = yes }
			create_artifact = {
				name = lady_godiva_book_name
				description = lady_godiva_book_desc
				type = book
				visuals = indian_book
				modifier = artifact_attraction_opinion_3_modifier
				save_scope_as = lady_godiva_book
				save_scope_as = artifact
			}
		}
		else = {
			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
				save_scope_as = artifact
			}
		}
		if = {
			limit = {
				can_appoint_char_to_court_position = {
					CHAR = scope:poet
					COURT_POS = court_poet_court_position
				}
			}
			court_position_grant_effect = { POS = court_poet CANDIDATE = scope:poet EMPLOYER = root }
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_greed = 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
			save_scope_as = artifact
		}
		if = {
			limit = { artifacts_use_indian_books_trigger = yes }
			create_artifact = {
				name = nasreddin_book_name
				description = nasreddin_book_desc
				type = book
				visuals = indian_book
				modifier = artifact_monthly_diplomacy_lifestyle_xp_1_modifier
				save_scope_as = nasreddin_book
				save_scope_as = artifact
			}
		}
		else = {
			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
				save_scope_as = artifact
			}
		}
		if = {
			limit = {
				can_appoint_char_to_court_position = {
					CHAR = scope:poet
					COURT_POS = court_poet_court_position
				}
			}
			court_position_grant_effect = { POS = court_poet CANDIDATE = scope:poet EMPLOYER = root }
		}
		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
			}
			if = {
				limit = { artifacts_use_indian_books_trigger = yes }
				create_artifact = {
					name = valmiki_book_name
					description = valmiki_book_desc
					type = book
					visuals = indian_book
					modifier = artifact_monthly_diplomacy_lifestyle_xp_1_modifier
					save_scope_as = valmiki_book
					save_scope_as = artifact
				}
			}
			else = {
				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
					save_scope_as = artifact
				}
			}
		}
		if = {
			limit = { has_character_flag = caligula }
			add_character_modifier = {
				modifier = compared_to_caligula
				years = 5
			}
			if = {
				limit = { artifacts_use_indian_books_trigger = yes }
				create_artifact = {
					name = caligula_book_name
					description = caligula_book_desc
					type = book
					visuals = indian_book
					modifier = artifact_monthly_diplomacy_lifestyle_xp_1_modifier
					save_scope_as = caligula_book
					save_scope_as = artifact
				}
			}
			else = {
				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
					save_scope_as = artifact
				}
			}
		}
		if = {
			limit = { has_character_flag = ruler_hero }
			if = {
				limit = { artifacts_use_indian_books_trigger = yes }
				create_artifact = {
					name = ruler_hero_book_name
					description = ruler_hero_book_desc
					type = book
					visuals = indian_book
					modifier = artifact_monthly_diplomacy_lifestyle_xp_1_modifier
					save_scope_as = ruler_hero_book
					save_scope_as = artifact
				}
			}
			else = {
				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
					save_scope_as = artifact
				}
			}
		}
		if = {
			limit = {
				has_character_flag = sinbad
			}
			add_character_modifier = {
				modifier = compared_to_sinbad
				years = 5
			}
			if = {
				limit = { artifacts_use_indian_books_trigger = yes }
				create_artifact = {
					name = sinbad_book_name
					description = sinbad_book_desc
					type = book
					visuals = indian_book
					modifier = artifact_monthly_martial_lifestyle_xp_1_modifier
					save_scope_as = sinbad_hero_book
					save_scope_as = artifact
				}
			}
			else = {
				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
					save_scope_as = artifact
				}
			}
		}
		if = {
			limit = {
				can_appoint_char_to_court_position = {
					CHAR = scope:poet
					COURT_POS = court_poet_court_position
				}
			}
			court_position_grant_effect = { POS = court_poet CANDIDATE = scope:poet EMPLOYER = root }
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_sociability = 0.75
			}
		}
	}
	option = {
		name = court.4751.h
		scope:poet = {
			add_opinion = {
				modifier = insulted_opinion
				target = root
			}
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_vengefulness = 0.75
			}
		}
	}

	after = {
		if = {
			limit = {
				scope:poet = {
					NOT = { has_court_position = court_poet_court_position }
				}
				is_ai = yes
			}
			scope:poet = { silent_disappearance_effect = yes }
		}
		court_4751_flag_removal_effect = yes
	}
}


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

##################################################
# 5030 - 5039	Playtime
# 5040 - 5049	Pranking Spree
# 5055 - 5059	Colorful Talent
# 5060 - 5069	The Gallant Knight
# 5070 - 5074	Dedicated Tutor
# 5075 - 5079	Gift From Neigh-bor
##################################################

#####################################
# 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 }
		age >= 4
		age <= 13
		any_courtier = {
			age >= 3
			age <= 13
			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 = {
				age >= 3
				age <= 13
			}
			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
		add_prowess_skill = 1
		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 = court.5030.b
		add_stewardship_skill = 1
		scope:child = {
			add_opinion = {
				target = root
				modifier = refusal_opinion
				opinion = -10
			}
		}

		add_stress = medium_stress_gain
	}
	after = {
		scope:child = {
			clear_court_event_participation = yes
		}
	}
}



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

scripted_trigger court_5055_child_painter_trigger = {
	is_available_ai_child = yes
	age >= 6
	NOT = { is_player_heir_of = root }
	is_of_major_or_minor_interest_trigger = { CHARACTER = 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
			}
		}
	}
	cooldown = { years = 25 }

	trigger = {
		is_available_adult = yes
		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 = {
		random_courtier = {
			limit = {
				court_5055_child_painter_trigger = yes
			}
			save_scope_as = painter
			court_event_character_flag_effect = yes
		}
	}

	option = { #Make them stop
		name = court.5055.a
		scope:painter = {
			add_martial_skill = 1
			add_stewardship_skill = 1
		}
	}

	option = { #Encourage them
		name = court.5055.b
		scope:painter = {
			add_diplomacy_skill = 1
			add_intrigue_skill = 1
		}
	}
	after = {
		scope:painter = {
			clear_court_event_participation = yes
		}
	}
}


#####################################
# 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 = {
			title_tier = county
			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 = {
					is_acclaimed = yes
					add = 2
				}
				modifier = {
					add = {
						add = var:number_of_impressive_knight_things
						multiply = 2
					}
				}
			}
			save_scope_as = knight
			court_event_character_flag_effect = yes
		}
	}

	option = { # Accolade
		name = court.5060.c
		trigger = {
			scope:knight = {
				is_acclaimed = yes
			}
		}
		scope:knight = {
			accolade_major_glory_gain_with_checks_effect = yes
			add_opinion = {
				target = root
				modifier = friendliness_opinion
				opinion = 20
			}
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = gregarious
				add = 25
			}
		}
	}

	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
				}
				can_appoint_char_to_court_position = {
					CHAR = scope:knight
					COURT_POS = akolouthos_court_position
				}
			}
		}
		# employ them as champion or bodyguard
		name = {
			trigger = {
				can_appoint_char_to_court_position = {
					CHAR = scope:knight
					COURT_POS = akolouthos_court_position
				}
			}
			text = court.5060.d.akolouthos
		}
		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 = bodyguard_court_position
					}
				}
			}
			text = court.5060.d.bodyguard
		}
		
		if = {
			limit = {
				can_appoint_char_to_court_position = {
					CHAR = scope:knight
					COURT_POS = akolouthos_court_position
				}
			}
			employ_character_as_position_in_current_scope_court_effect = {
				CHARACTER = scope:knight
				POSITION = akolouthos
			}
		}
		else_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
			}
		}
		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
			}
		}
		scope:knight = {
			accolade_minor_glory_gain_with_checks_effect = yes
		}
		stress_impact = {
			paranoid = medium_stress_impact_loss
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = paranoid
				add = 50
			}
		}
	}

	option = { #Pat on the shoulder - opt out
		name = court.5060.a
		scope:knight = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -20
			}
		}
		ai_chance = {
			base = 50
			modifier = {
				has_trait = arrogant
				add = 25
			}
			modifier = {
				has_trait = vengeful
				add = 25
			}
			modifier = {
				has_trait = greedy
				add = 25
			}
		}
	}
	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 = 15
		}
		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 = { #Pay to improve the education of all your wards
		name = court.5070.b
		custom_tooltip = court.5070.b.tt
		every_courtier = {
			limit = {
				is_adult = no
				any_relation = {
					type = guardian
					this = root
				}
			}
			hidden_effect = {
				education_point_acquisition_additional_points_effect = { LEVEL = mid }
			}
		}

		remove_short_term_gold = medium_gold_value
		scope:court_tutor = {
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = 15
			}
		}
		ai_chance = {
			base = 50
		}
	}

	option = { #nah
		name = court.5070.a
		scope:court_tutor = {
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = -10
			}
		}
		ai_chance = {
			base = 10
			modifier = {
				gold < medium_gold_value
				add = 200
			}
			modifier = {
				has_trait = greedy
				add = 30
			}
		}
	}

	after = {
		scope:court_tutor = {
			clear_court_event_participation = yes
		}
		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
		is_available_ai_adult = yes
	}
	OR = {
		# They are friendly towards you
		has_relation_potential_friend = root
		has_relation_friend = root
		is_close_or_extended_family_of = root
		# They have reason to fear you
		root = {
			has_dread_level_towards = {
  				target = prev
  				level = 1
  			}
		}
		root = {
			has_dread_level_towards = {
  				target = prev
  				level = 2
  			}
		}
		current_military_strength < root.current_strength_ninety_percent_value
		# They feel indebted
		has_opinion_modifier = {
			modifier = gift_opinion
			target = root
		}
		root = {
			has_hook = prev
		}
	}
}

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 = {
		NOT = { has_character_flag = had_event_court_5075 }
		age >= 14
		OR = {
			AND = {
				top_liege = this
				any_neighboring_top_liege_realm_owner = {
					court_5075_neighbor_trigger = yes
					has_court_event_flag = no
				}
			}
			AND = {
				top_liege != this
				any_neighboring_realm_same_rank_owner = {
					court_5075_neighbor_trigger = yes
					has_court_event_flag = no
				}
			}
		}
	}

	weight_multiplier = {
		base = 1
		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 = {
				top_liege = this
			}
			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
			}
		}
		if = {
			limit = {
				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 = { # give them to the court
		name = court.5075.a
		change_current_court_grandeur = medium_court_grandeur_gain
		if = {
			limit = {
				government_allows = administrative
			}
			change_influence = minor_influence_gain
		}
		else = {
			add_prestige = minor_prestige_gain
		}
		scope:neighbor = {
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 15
			}
		}
		stress_impact = {
			brave = minor_stress_impact_gain
			arrogant = medium_stress_impact_gain
			greedy = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
		}
	}

	option = { # Warhorse
		name = court.5075.c
		trigger = {
			NOT = {
				any_owned_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 = {
					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
					}
				}
			}
		}
		scope:neighbor = {
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 30
			}
		}
		stress_impact = {
			craven = major_stress_impact_gain
			paranoid = medium_stress_impact_gain
			generous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 200
		}
	}

	option = { # Opt out - 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
		}
		ai_chance = {
			base = 75
		}
	}

	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
				this != scope:author
			}
			save_scope_as = courtier
			court_event_character_flag_effect = yes
		}
		if = {
			limit = {
				primary_title.previous_holder = {
					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
			ai_value_modifier = {
				ai_energy = 0.5
				ai_rationality = 0.5
				ai_vengefulness = 1
			}
		}
	}

	# 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
			ai_value_modifier = {
				ai_energy = 0.5
				ai_rationality = 0.5
				ai_vengefulness = 1
			}
		}
	}

	# Option D: Opt out - You really don't care
	option = {
		name = court.6000.d
		dynasty = { add_dynasty_prestige = minor_dynasty_prestige_loss }
		stress_impact = {
			base = minor_stress_impact_loss
		}
		ai_chance = {
			base = 75
			ai_value_modifier = {
				ai_energy = -0.5
			}
		}
	}

	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 = { #success
					compare_modifier = {
						value = scope:duel_value
						multiplier = 3.5
					}
					trigger_event = court.6002
				}
				50 = { #failure
					compare_modifier = {
						value = scope:duel_value
						multiplier = -3.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: Force to recant
	option = {
		name = court.6002.a
		flavor = court.6002.a.tt
		dynasty = { add_dynasty_prestige = minor_dynasty_prestige_gain }
		add_dread = medium_dread_gain
		custom_tooltip = court.6002.a.tt2
		add_character_flag = {
			flag = court_of_no_secrets
			years = 15
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_vengefulness = 1
			}
		}
	}

	#Option D: forgive the author
	option = {
		name = court.6002.d
		change_current_court_grandeur = minor_court_grandeur_gain
		scope:author = {
			create_inspiration = book_inspiration
			add_opinion = {
				target = root
				modifier = forgiven_opinion
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_vengefulness = -1
			}
		}
	}
}

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 = {
		trigger = {
			exists = scope:spymaster
		}
		character = scope:spymaster
		animation = shame
	}

	#Option B: disappointed
	option = {
		name = court.6003.b
		add_intrigue_lifestyle_xp = medium_lifestyle_xp
		add_stress = medium_stress_gain
	}
}

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_available_ai_adult = yes
	has_trait = zealous
	faith = scope:target_county.faith
}

# 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
			}
		}
	}

	cooldown = { years = 20 }

	trigger = {
		has_court_event_flag = no
		cp:councillor_court_chaplain ?= {
			is_performing_council_task = task_conversion
			councillor_task_target = {
				NOR = {
					faith = root.faith
					faith = root.capital_county.faith
					faith = { has_doctrine = doctrine_pluralism_pluralistic }
				}
			}
		}
	}

	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 = chaplain }
		scope:chaplain.councillor_task_target.county = { save_scope_as = target_county }

		random_courtier_or_guest = {
			limit = {
				court_6010_valid_preacher_trigger = yes
			}
			save_scope_as = preacher
		}
		if = {
			limit = {
				NOT = { exists = scope:preacher }
			}
			create_character = {
				location = root.location
				template = preacher_template
				faith = scope:target_county.faith
				culture = scope:target_county.culture
				save_scope_as = preacher
			}
		}
		scope:preacher = { court_event_character_flag_effect = yes }
		# Save the preacher's "liege"
		scope:target_county.holder ?= {
			save_scope_as = preacher_liege
		}
		every_realm_county = {
			limit = {
				faith = scope:preacher.faith
			}
			add_to_list = preacher_faith_counties
		}
		save_scope_value_as = {
			name = preacher_faith_counties_size
			value = list_size:preacher_faith_counties
		}
	}

	#OPTION C: Imprison them
	option = {
		name = court.6010.c
		rightfully_imprison_character_effect = {
			TARGET = scope:preacher
			IMPRISONER = root
		}
		if = {
			limit = {
				exists = scope:preacher_liege
				scope:preacher_liege = {
					this != root
					faith = scope:preacher.faith
					is_ai = yes
				}
			}
			custom_tooltip = court.6010.c.tt
			trigger_event = {
				id = court.6011
				days = 5
			}
		}
		custom_tooltip = court.6010.c.tt2
		set_variable = {
			name = 6010_harsh_conversion
			value = scope:preacher.faith
			years = 20
		}
		every_in_list = {
			list = preacher_faith_counties
			custom = court.6010.a_every_county
			change_county_control = -15
		}
		every_courtier_or_guest = {
			limit = {
				faith = scope:preacher.faith
			}
			custom = court_6010_all_courtiers_and_guests_faith
			add_opinion = {
				target = root
				modifier = impious_opinion
				opinion = -20
			}
		}
		stress_impact = {
			cynical = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
			gregarious = medium_stress_impact_gain
			just = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = 1
			}
		}
	}

	#OPTION A: Let them be
	option = {
		name = court.6010.a
		#you are tolerant and open-minded
		change_current_court_grandeur = medium_court_grandeur_gain
		custom_tooltip = court.6010.c.tt3
		set_variable = {
			name = 6010_tolerant_conversion
			value = scope:preacher.faith
			years = 20
		}
		every_in_list = {
			list = preacher_faith_counties
			custom = court.6010.a_every_county
			change_county_control = 15
		}
		every_courtier_or_guest = {
			limit = {
				faith = scope:preacher.faith
			}
			custom = court_6010_all_courtiers_and_guests_faith
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 20
			}
		}
		stress_impact = {
			zealous = major_stress_impact_gain
			patient = medium_stress_impact_gain
			wrathful = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = -1
			}
		}
	}

	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 = court.6011.desc_prisoner
	sender = scope:preacher_liege

	#Option A: sorry for the diplomatic blunder - offer repayment
	option = {
		name = court.6011.a
		trigger = {
			can_make_expensive_purchase_trigger = {
				PRICE = root.minor_gold_value
			}
		}
		if = {
			limit = {
				government_allows = administrative
			}
			change_influence = medium_influence_gain
		}
		else = {
			add_prestige = medium_prestige_gain
		}
		pay_short_term_gold = {
			target = scope:preacher_liege
			gold = minor_gold_value
		}
		scope:preacher_liege = {
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 20
			}
		}
		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
			}
		}
	}

	#Option B: reiterate that their religion is not welcome at your court
	option = {
		name = court.6011.b
		add_piety = medium_piety_gain
		scope:preacher_liege = {
			add_opinion = {
				target = root
				modifier = insult_opinion
				opinion = -20
			}
		}
		stress_impact = {
			humble = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
			cynical = 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 = {
			OR = {
				has_trait = possessed_1
				has_trait = possessed_genetic
			}
			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.
		cp:councillor_court_chaplain ?= {
			NOT = { has_court_position = court_physician_court_position }
		}
		has_court_type = court_scholarly
	}

	weight_multiplier = {
		base = 0.5
		modifier = {
			exists = cp:councillor_court_chaplain
			add = 0.5
		}
		modifier = {
			employs_court_position = court_physician_court_position
			add = 0.5
		}
		modifier = {
			has_trait = lifestyle_physician
			add = 0.5
		}
		modifier = {
			has_trait = theologian
			add = 0.5
		}
		modifier = {
			has_trait = whole_of_body
			add = 0.5
		}
	}

	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
			}
		}
	}

	# Option A: Court chaplain exorcizes them - limited to christians
	option = {
		name = court.6020.a
		trigger = {
			exists = scope:court_chaplain
			OR = { scope:court_chaplain.religion = religion:eastern_orthodox_religion scope:court_chaplain.religion = religion:catholic_religion scope:court_chaplain.religion = religion:protestant_religion }
			OR = { root.religion = religion:eastern_orthodox_religion root.religion = religion:catholic_religion root.religion = religion:protestant_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
						change_current_court_grandeur = major_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
						change_current_court_grandeur = medium_court_grandeur_loss
					}
				}
			}
		}
		ai_chance = {
			base = 150
			ai_value_modifier = {
				ai_zeal = 1
				ai_rationality = -1
			}
		}
	}

	# Option B: it is a sign of the favor of the gods - limited to non-monotheistic
	option = {
		name = court.6020.b
		trigger = {
			NOR = {
				root.religion = { is_in_family = rf_abrahamic }
				scope:court_chaplain ?= {
					religion = {
						is_in_family = rf_abrahamic
					}
				}
				has_trait = cynical
				faith = {
					OR = {
						trait_is_sin = possessed_1
						trait_is_sin = possessed_genetic
					}
				}
			}
		}
		add_piety = medium_piety_gain
		scope:possessed_char = {
			add_character_modifier = possessed_prophetic_visions
		}
		custom_tooltip = court.6020.b.tt
		change_current_court_grandeur = medium_court_grandeur_gain
		ai_chance = {
			base = 150
			ai_value_modifier = {
				ai_zeal = 1
				ai_rationality = -1
			}
		}
	}

	# Option E: it's just a disease - court physician
	option = {
		name = court.6020.e
		trigger = {
			exists = scope:court_physician
		}
		if = {
			limit = {
				OR = {
					root.religion = religion:islam_religion
					root.religion = { is_in_family = rf_eastern }
				}
			}
			add_learning_lifestyle_xp = major_lifestyle_xp
		}
		change_current_court_grandeur = major_court_grandeur_gain
		scope:possessed_char = {
			add_character_modifier = court_possessed_improved_condition_modifier
		}
		scope:possessed_char = {
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 60
			}
		}
		ai_chance = {
			base = 150
			ai_value_modifier = {
				ai_zeal = -1
				ai_rationality = 1
			}
		}
	}

	# Option F: opt out - don't bother me
	option = {
		name = court.6020.f
		add_prestige = minor_prestige_loss
		stress_impact = {
			base = minor_stress_impact_loss
		}
		ai_chance = {
			base = 75
			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 = {
					OR = {
						root.culture = { has_cultural_pillar = language_greek }
						root.culture = { has_cultural_pillar = heritage_byzantine }
					}
				}
				desc = court.6050.desc_byz
			}
			triggered_desc = {
				trigger = {
					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 }
					}
				}
				desc = court.6050.desc_islam
			}
			triggered_desc = {
				trigger = {
					OR = {
						root.culture = { has_cultural_pillar = language_french }
						root.culture = { has_cultural_pillar = language_occitano_romance }
						root.culture = { has_cultural_pillar = heritage_latin }
					}

				}
				desc = court.6050.desc_sonetti
			}
			triggered_desc = {
				trigger = {
					OR = {
						root.culture = { has_cultural_pillar = language_anglic }
						root.culture = { has_cultural_pillar = language_saxon }
					}
				}
				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
		modifier = {
			has_lifestyle = intrigue_lifestyle
			add = 0.5
		}
		modifier = {
			has_lifestyle = learning_lifestyle
			add = 0.5
		}

		# 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 B: purify them all with fire!
	option = {
		name = court.6050.b
		flavor = court.6050.b.tt
		add_dread = major_dread_gain
		add_piety = major_piety_gain
		custom_tooltip = court.6050.b.tt.2
		add_character_flag = {
			flag = burned_indecent_books
			years = 20
		}
		scope:court_chaplain = {
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 30
			}
		}

		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
		add_learning_lifestyle_xp = major_lifestyle_xp
		if = {
			limit = {
				has_court_type = court_scholarly
			}
			change_current_court_grandeur = major_court_grandeur_gain
		}
		else = {
			change_current_court_grandeur = minor_court_grandeur_gain
		}
		custom_tooltip = court.6050.c.tt
		add_character_flag = {
			flag = supported_indecent_books
			years = 20
		}

		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_intrigue_lifestyle_xp = major_lifestyle_xp
		add_character_modifier = {
			modifier = confident_lover
			years = 15
		}
		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 = -100
			}
			modifier = {
				has_trait = celibate
				add = -200
			}
		}
	}

	#Option F: opt out - move on
	option = {
		name = court.6050.f
		add_piety = minor_piety_gain
		stress_impact = {
			zealous = medium_stress_impact_gain
			chaste = medium_stress_impact_gain
			fickle = medium_stress_impact_loss
			lazy = medium_stress_impact_loss
		}
		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 = {
			OR = { religion = religion:eastern_orthodox_religion religion = religion:catholic_religion religion = religion:protestant_religion }
			AND = {
				religion = religion:islam_religion
				culture = { has_cultural_pillar = heritage_iranian }
			}
		}
		employs_court_position = court_physician_court_position
		exists = cp:councillor_court_chaplain
		cp:councillor_court_chaplain = {
			has_court_event_flag = no
			NOT = { 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 = {
		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
		add_character_modifier = {
			modifier = court_no_wine_modifier
			days = 3650
		}
		add_piety = medium_piety_gain
		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
				}
			}
		}
		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
		add_character_modifier = {
			modifier = court_moderate_drinking_modifier
			days = 3650
		}
		add_prestige = medium_prestige_gain
		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
				}
			}
		}
		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
		flavor = court.6060.c.tt
		trigger = {
			exists = scope:courtier_drunkard
		}
		add_character_modifier = {
			modifier = rivers_of_wine_modifier
			years = 10
		}
		custom_tooltip = court.6060.c.tt.2
		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
			}
		}
	}

	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
			}
		}
	}

	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
				}
			}
		}
	}

	#Option B: my tutor deserves compensation
	option = {
		name = court.6071.b
		add_prestige = medium_prestige_gain
		add_learning_skill = 2
		pay_short_term_gold = {
			gold = minor_gold_value
			target = scope:tutor_6070
		}
		scope:tutor_6070 = {
			add_character_flag = court_language_teacher
		}
		custom_tooltip = court.6071.b.tt
		reverse_add_opinion = {
			target = scope:tutor_6070
			modifier = grateful_opinion
			opinion = 20
		}
		stress_impact = {
			base = minor_stress_impact_loss
			greedy = minor_stress_impact_gain
		}
	}
}

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
	}

	artifact = {
		position = lower_left_portrait
		target = scope:newly_created_artifact
		trigger = { exists = scope:newly_created_artifact }
	}

	immediate = {
		hidden_effect = {
			scope:tutor_6070 = {
				create_artifact = {
					name = court_fancy_seal_modifier
					description = court_fancy_seal_modifier_desc
					type = miscellaneous
					visuals = small_box
					modifier = artifact_diplomacy_1_modifier
					save_scope_as = newly_created_artifact
				}
			}
		}
	}

	#Option B: you use a seal instead of signing
	option = {
		name = court.6072.b
		flavor = court.6072.b.tt
		scope:newly_created_artifact = {
			set_owner = {
				target = root
				history = {
					type = given
					actor = scope:tutor_6070
					recipient = root
				}
			}
		}
	}
}

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

# A traveling ruler 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
	is_travelling = yes
	top_liege = this
	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 = {
		first_valid = {
			triggered_desc = {
				trigger = {
					# The visiting ruler is your liege on a Tour
					is_vassal_of = scope:6080_visitor
					scope:6080_visitor = { involved_activity ?= { has_activity_type = activity_tour } }
				}
				desc = court.6080.desc_liege
			}
			desc = court.6080.desc
		}
		desc = court.6080.desc_middle
		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_sub_realm_county = {
			holder = root
			any_county_province = {
				any_character_in_location = {
					court_6080_valid_visitor_trigger = yes
				}
			}
		}
		any_courtier_or_guest = {
			is_available_ai_adult = yes
			has_court_event_flag = no
		}
	}

	immediate = {
		random_sub_realm_county = {
			limit = {
				holder = root
				any_county_province = {
					any_character_in_location = {
						court_6080_valid_visitor_trigger = yes
					}
				}
			}
			random_county_province = {
				limit = {
					any_character_in_location = {
						court_6080_valid_visitor_trigger = yes
					}
				}
				random_character_in_location = {
					limit = {
						court_6080_valid_visitor_trigger = yes
					}
					save_scope_as = 6080_visitor
				}
			}
		}
		random_courtier_or_guest = {
			limit = {
				is_available_ai_adult = yes
				has_court_event_flag = no
			}
			save_scope_as = beneficiary_1
			court_event_character_flag_effect = yes
		}
		if = {
			limit = {
				any_courtier_or_guest = {
					is_available_ai_adult = yes
					has_court_event_flag = no
					this != scope:beneficiary_1
				}
			}
			random_courtier_or_guest = {
				limit = {
					is_available_ai_adult = yes
					has_court_event_flag = no
					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
					has_court_event_flag = no
					age >= 3
				}
			}
			random_courtier_or_guest = {
				limit = {
					is_available_ai_child = yes
					has_court_event_flag = no
				}
				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
		if = {
			limit = {
				government_allows = administrative
			}
			change_influence = medium_influence_gain
		}
		else = {
			add_prestige = medium_prestige_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 = {
				has_trait = ambitious
				add = 25
			}
			modifier = {
				has_trait = humble
				add = -25
			}
			modifier = {
				has_trait = content
				add = -25
			}
			modifier = {
				gold < medium_gold_value
				factor = 0
			}
		}
	}

	#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.5
				}
				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.5
				}
				send_interface_toast = {
					title = court.6080.b.failure.tt
					add_prestige = minor_prestige_loss
				}
			}
		}
		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 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
			generous = medium_stress_impact_gain
			ambitious = medium_stress_impact_gain
		}
		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
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:6090_poet = {
						OR = {
							has_court_position = court_poet_court_position
							has_court_position = court_tutor_court_position
						}
					}
				}
				desc = court.6090.desc.cp
			}
			desc = court.6090.desc.teacher
		}
		desc = court.6090.desc.middle
		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 = {
		any_child = {
			count >= 2
			is_available_ai_child = yes
			has_court_event_flag = no
			age >= 8
			location = root.location
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			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
			}
			add = 1
		}
		modifier = {
			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
			}
			add = 1
		}
	}

	immediate = {
		random_court_position_holder = {
			type = court_poet_court_position
			limit = { is_available_ai_adult = yes }
			save_scope_as = 6090_poet
		}
		if = {
			limit = {
				NOT = { exists = scope:6090_poet }
			}
			random_court_position_holder = {
				type = court_tutor_court_position
				limit = { is_available_ai_adult = yes }
				save_scope_as = 6090_poet
			}
		}
		if = {
			limit = {
				NOT = { exists = scope:6090_poet }
			}
			random_pool_character = {
				province = root.location
				limit = {
					diplomacy >= 14
				}
				save_scope_as = 6090_poet
			}
		}
		if = {
			limit = {
				NOT = { exists = scope:6090_poet }
			}
			create_character = {
				location = root.location
				template = poet_template
				save_scope_as = 6090_poet
			}
			scope:6090_poet = { add_character_flag = created_character }
		}
		scope:6090_poet = { court_event_character_flag_effect = yes }
		every_child = {
			limit = {
				is_available_ai_child = yes
				age >= 8
				location = root.location
			}
			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
				court_event_character_flag_effect = yes
			}
		}
	}

	#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
			}
			if = {
				limit = {
					scope:6090_poet = {
						OR = {
							has_court_position = court_poet_court_position
							has_court_position = court_tutor_court_position
						}
					}
				}
				add_diplomacy_skill = 2
			}
			else = {
				add_diplomacy_skill = 1
			}
		}
		scope:6090_child_b = {
			add_opinion = {
				target = root
				modifier = annoyed_opinion
				opinion = -10
			}
			if = {
				limit = {
					scope:6090_poet = {
						OR = {
							has_court_position = court_poet_court_position
							has_court_position = court_tutor_court_position
						}
					}
				}
				add_diplomacy_skill = 2
			}
			else = {
				add_diplomacy_skill = 1
			}
		}
		if = {
			limit = {
				exists = scope:6090_child_c
			}
			scope:6090_child_c = {
				add_opinion = {
					target = root
					modifier = annoyed_opinion
					opinion = -10
				}
				if = {
					limit = {
						scope:6090_poet = {
							OR = {
								has_court_position = court_poet_court_position
								has_court_position = court_tutor_court_position
							}
						}
					}
					add_diplomacy_skill = 2
				}
				else = {
					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 C: Side with them - court poet is booooring
	option = {
		name = court.6090.c
		flavor = court.6090.c.tt
		scope:6090_child_a = {
			add_prowess_skill = 1
			add_opinion = {
				target = root
				modifier = amused_opinion
				opinion = 10
			}
		}
		scope:6090_child_b = {
			add_prowess_skill = 1
			add_opinion = {
				target = root
				modifier = amused_opinion
				opinion = 10
			}
		}
		if = {
			limit = {
				exists = scope:6090_child_c
			}
			scope:6090_child_c = {
				add_prowess_skill = 1
				add_opinion = {
					target = root
					modifier = amused_opinion
					opinion = 10
				}
			}
		}
		scope:6090_poet = {
			add_opinion = {
				target = root
				modifier = insulted_opinion
				opinion = -30
			}
		}
		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
			if = {
				limit = {
					root = { is_ai = yes }
					has_character_flag = created_character
				}
				silent_disappearance_effect = yes
			}
		}
		scope:6090_child_a = {
			clear_court_event_participation = yes
		}
		scope:6090_child_b = {
			clear_court_event_participation = yes
		}
		scope:6090_child_c ?= {
			clear_court_event_participation = yes
		}
	}
}




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

##################################################
# 7300			Where's the Lamb Sauce?
# 7600			Wild at Heart
# 7610			Child asks for a destrier
# 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.t
	desc = court.7300.desc
	theme = court

	court_scene = {
		button_position_character = scope:taster
		roles = {
			scope:taster = {
				group = event_group
				animation = disgust
			}
			root = {
				group = event_group
				animation = worry
			}
		}
	}

	cooldown = { years = 25 }

	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 = {
			target = 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
		}
	}

	# invest more in food
	option = {
		name = court.7300.a
		add_amenity_level = { type = court_food_quality value = 1 }
		add_character_modifier = {
			modifier = incentivized_food_taster
			years = 15
		}
		scope:taster = {
			add_opinion = {
				modifier = grateful_opinion
				target = root
				opinion = 10
			}
		}
		stress_impact = {
			gluttonous = medium_stress_impact_loss
			greedy = major_stress_impact_gain
			generous = medium_stress_impact_loss
		}
		ai_chance = {
			base = 40
			ai_value_modifier = {
				ai_rationality = 1
				ai_honor = 0.5
				ai_compassion = 1
				ai_greed = -1
			}
		}
	}

	# Let things be
	option = {
		name = court.7300.b
		scope:taster = {
			add_opinion = {
				modifier = disgusted_opinion
				target = root
				opinion = -15
			}
		}
		stress_impact = {
			compassionate = medium_stress_impact_gain
			stubborn = medium_stress_impact_loss
			callous = medium_stress_impact_loss
		}
		ai_chance = {
			base = 20
			ai_value_modifier = {
				ai_honor = -1
				ai_greed = 1
			}
		}
	}

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


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

scripted_trigger active_child_trigger = {
	age >= 7
	age <= 15
	is_landed = no
	location = root.location
	is_available_healthy_ai_child = yes
	NOT = { has_character_flag = child_goes_hunting }
}

court.7600 = {
	type = court_event
	title = court.7600.t
	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 = 15 }

	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_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
			}
			weight ={
				base = 1
				modifier = {
					has_trait = rowdy
					add = 2
				}
				modifier = {
					has_trait = curious
					add = 1
				}
			}
			save_scope_as = child
			court_event_character_flag_effect = yes
			add_character_flag = child_goes_hunting
			select_local_animal_effect = { TYPE = harmless } # 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
		scope:child = {
			add_learning_skill = 2
			add_opinion = {
				modifier = hate_opinion
				target = root
				opinion = -30
			}
		}
		stress_impact = {
			lifestyle_hunter = major_stress_impact_gain
			brave = medium_stress_impact_gain
			ambitious = minor_stress_impact_gain
			craven = medium_stress_impact_loss
		}

		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_boldness = -1
			}
			modifier = {
				has_trait = lifestyle_hunter
				factor = 0
			}
		}
	}

	# Approve the outings
	option = {
		name = court.7600.c
		scope:child = {
			add_prowess_skill = 1
			add_opinion = {
				modifier = love_opinion
				target = root
				opinion = 15
			}
		}
		scope:huntmaster = {
			custom_tooltip = 7600_taking_child_to_hunt.tt
			add_character_flag = 7600_taking_child_to_hunt
			if = {
				limit = {
					has_trait = lifestyle_hunter
				}
				add_trait_xp = {
					trait = lifestyle_hunter
					track = hunter
					value = 5
				}
			}
			else = {
				add_trait = lifestyle_hunter
			}
		}
		stress_impact = {
			lifestyle_hunter = medium_stress_impact_loss
			craven = medium_stress_impact_gain
			scholar = minor_stress_impact_gain
			theologian = minor_stress_impact_gain
			diligent = minor_stress_impact_gain
			paranoid = minor_stress_impact_gain
		}
		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_honor = 0.5
				ai_boldness = 1
			}
			modifier = {
				has_trait = paranoid
				factor = 0
			}
		}
	}
	after = {
		scope:huntmaster = {
			clear_court_event_participation = yes
		}
		scope:child = {
			clear_court_event_participation = yes
		}
	}
}


#########################
# Spymaster 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.t
	desc = court.7700.desc
	theme = court
	court_scene = {
		button_position_character = scope:spymaster
		roles = {
			scope:spymaster = {
				group = event_group
				animation = scheme
			}
		}
	}
	cooldown = { years = 25 }

	weight_multiplier = {
		base = 1

		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_intrigue }
	}

	trigger = {
		cp:councillor_spymaster ?= {
			is_available_ai_adult = yes
			has_court_event_flag = no
		}
		any_scheme = {
			pigeon_assistance_scheme_trigger = yes
		}
	}

	immediate = {
		cp:councillor_spymaster = {
			save_scope_as = spymaster
			court_event_character_flag_effect = yes
		}
		random_scheme = {
			limit = {
				pigeon_assistance_scheme_trigger = yes
			}
			save_scope_as = scheme
		}
		scope:spymaster = {
			add_character_modifier = {
				modifier = pigeon_thief
				years = 10
			}
		}
	}

	# Just this once, ok?
	option = {
		name = court.7700.b
		# You've told them you need help, they are in on it now!
		try_to_force_assign_character_to_random_agent_slot_effect = {
			SCHEME = scope:scheme
			CHAR = scope:spymaster
			YEARS = 10
		}
		add_character_modifier = {
			modifier = profiting_from_pigeon_thievery
			years = 10
		}
		stress_impact = {
			honest = massive_stress_impact_gain
			just = major_stress_impact_gain
			compassionate = medium_stress_impact_gain
			brave = minor_stress_impact_gain
			arrogant = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 1
				ai_honor = -0.5
				ai_compassion = -0.5
			}
		}
	}

	# Turn the spymaster away
	option = {
		name = court.7700.d
		add_prestige = minor_prestige_gain
		stress_impact = {
			deceitful = major_stress_impact_gain
			vengeful = major_stress_impact_gain
			fickle = medium_stress_impact_gain
			arbitrary = medium_stress_impact_gain
			craven = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_vengefulness = -1
				ai_honor = 1
			}
		}
	}
	after = {
		scope:spymaster = {
			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
# 8070 - Feeling Useful
# 8080 - Maternal Reproach
# 8090 - Building Blocks
# 8120 - Novel Perspectives
# 8140 - Royal Lapse
# 8150 - Prandial Excess
# 8160 - Foremost Knight

#########################
# Trampled Underfoot	#
# by Joe Parkin 		#
#########################

scripted_trigger court_8001_child_trigger = {
	is_available = yes
	is_healthy = yes
	age > 3
	age < 12
	has_any_focus = yes
	NOT = { has_variable = court_8001_child_flag }
	location = root.location
}

scripted_effect court_8001_skill_effect = {
	duel = {
		skill = $SKILL$
		value = decent_skill_rating
		5 = {
			compare_modifier = {
				value = scope:duel_value
				multiplier = 1
				min = -49
			}
			min = 1
			desc = court.8001.a.success
			send_interface_toast = {
				left_icon = scope:child_1
				title = court.8001.a.lesson_tt
				scope:child_1 = { add_$SKILL$_skill = 2 }
			}
		}
		10 = {
			compare_modifier = {
				value = scope:duel_value
				multiplier = 3.5
				min = -49
			}
			min = 2
			desc = court.8001.a.success
			send_interface_toast = {
				left_icon = scope:child_1
				title = court.8001.a.lesson_tt
				scope:child_1 = { add_$SKILL$_skill = 1 }
			}
		}
		10 = {
			compare_modifier = {
				value = scope:duel_value
				multiplier = -3.5
				min = -49
			}
			min = 5
			desc = court.8001.a.failure
		}
	}
	stress_impact = {
		base = minor_stress_impact_gain
		wrathful = minor_stress_impact_gain
		callous = minor_stress_impact_gain
	}
}

court.8001 = {
	type = court_event
	title = court.8001.t
	desc = {
		desc = court.8001.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:child_1 = { has_focus = education_diplomacy }
				}
				desc = court.8001.desc.diplomacy
			}
			triggered_desc = {
				trigger = {
					scope:child_1 = { has_focus = education_martial }
				}
				desc = court.8001.desc.martial
			}
			triggered_desc = {
				trigger = {
					scope:child_1 = { has_focus = education_stewardship }
				}
				desc = court.8001.desc.stewardship
			}
			triggered_desc = {
				trigger = {
					scope:child_1 = { has_focus = education_intrigue }
				}
				desc = court.8001.desc.intrigue
			}
			triggered_desc = {
				trigger = {
					scope:child_1 = { has_focus = education_learning }
				}
				desc = court.8001.desc.learning
			}
			desc = court.8001.desc.fallback
		}
		desc = court.8001.desc.closing
	}
	theme = court
	cooldown = { years = 10 }
	court_scene = {
		button_position_character = scope:gardener
		roles = {
			root = {
				group = event_group
				animation = war_over_tie
			}
			scope:gardener = {
				group = event_group
				animation = rage
			}
			scope:child_1 = {
				group = event_group
				animation = shame
			}
		}
	}

	trigger = {
		any_courtier_or_guest = {
			count >= 1
			court_8001_child_trigger = yes
			has_court_event_flag = no
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			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
			}
			add = 2
		}
		modifier = {
			has_trait = lifestyle_gardener
			add = 2
		}
		# 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
		}
		if = {
			limit = {
				NOT = { exists = scope:gardener }
			}
			create_character = {
				location = root.location
				template = gardener_template
				save_scope_as = gardener
			}
			scope:gardener = { add_character_flag = created_character }
		}
		scope:gardener = {
			court_event_character_flag_effect = yes
		}
		random_courtier_or_guest = {
			limit = {
				court_8001_child_trigger = yes
				OR = {
					is_child_of = root
					any_relation = {
						type = guardian
						this = root
					}
				}
			}
			alternative_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 = court.8001.a.diplomacy
		trigger = {
			scope:child_1 = { has_focus = education_diplomacy }
		}
		skill = diplomacy
		court_8001_skill_effect = { SKILL = diplomacy }
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 2
				ai_energy = 1
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = wrathful
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = callous
			}
		}
	}

	option = { # Encourage the child's interests
		name = court.8001.a.martial
		trigger = {
			scope:child_1 = { has_focus = education_martial }
		}
		skill = martial
		court_8001_skill_effect = { SKILL = martial }
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 2
				ai_energy = 1
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = wrathful
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = callous
			}
		}
	}

	option = { # Encourage the child's interests
		name = court.8001.a.stewardship
		trigger = {
			scope:child_1 = { has_focus = education_stewardship }
		}
		skill = stewardship
		court_8001_skill_effect = { SKILL = stewardship }
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 2
				ai_energy = 1
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = wrathful
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = callous
			}
		}
	}

	option = { # Encourage the child's interests
		name = court.8001.a.intrigue
		trigger = {
			scope:child_1 = { has_focus = education_intrigue }
		}
		skill = intrigue
		court_8001_skill_effect = { SKILL = intrigue }
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 2
				ai_energy = 1
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = wrathful
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = callous
			}
		}
	}

	option = { # Encourage the child's interests
		name = court.8001.a.learning
		trigger = {
			scope:child_1 = { has_focus = education_learning }
		}
		skill = learning
		court_8001_skill_effect = { SKILL = learning }
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 2
				ai_energy = 1
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = wrathful
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = callous
			}
		}
	}

	option = { # Replant them
		name = court.8001.c
		scope:child_1 = {
			random = {
				chance = 20
				modifier = {
					scope:gardener = { has_court_position = court_gardener_court_position }
					add = 5
				}
				modifier = {
					scope:gardener = { has_trait = lifestyle_gardener }
					add = 10
				}
				modifier = {
					has_trait = diligent
					add = 10
				}
				modifier = {
					has_trait = lazy
					add = -10
				}
				root = {
					send_interface_toast = {
						left_icon = scope:child_1
						title = court.8001.c.gardener_tt
						scope:child_1 = { add_trait = lifestyle_gardener }
					}
				}
			}
			add_opinion = {
				target = root
				modifier = annoyed_opinion
				opinion = -20
			}
			stress_impact = {
				base = minor_stress_impact_gain
				lazy = minor_stress_impact_gain
				arrogant = minor_stress_impact_gain
			}
		}
		stress_impact = {
			just = minor_stress_impact_loss
			diligent = minor_stress_impact_loss
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = -1
				ai_vengefulness = 1
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = vengeful
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = greedy
			}
		}
	}

	option = { # Dismiss the gardener's protests (opt out)
		name = court.8001.e
		reverse_add_opinion = {
			target = scope:gardener
			modifier = annoyed_opinion
			opinion = -20
		}
		ai_chance = {
			base = 50
			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
			if = {
				limit = {
					root = { is_ai = yes }
					has_character_flag = created_character
				}
				silent_disappearance_effect = 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
    	first_valid = {
    	    triggered_desc = {
    	        trigger = {
    				scope:underequipped = {
    					OR = {
    						has_court_position = bodyguard_court_position
    						has_court_position = akolouthos_court_position
    					}
    				}
    	        }
    	        desc = court.8010.desc.bodyguard
    	    }
    	    triggered_desc = {
    	        trigger = {
    				scope:underequipped = { has_court_position = champion_court_position }
    	        }
    	        desc = court.8010.desc.champion
    	    }
    	    desc = court.8010.desc.knight
    	}
    	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 = {
    					OR = {
    						has_court_position = bodyguard_court_position
    						has_court_position = akolouthos_court_position
    						is_knight_of = root
    					}
    				}
    	        }
    	        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 = {
        	any_court_position_holder = {
				type = bodyguard_court_position
				court_8010_underequipped_trigger = yes
				has_court_event_flag = no
				location = root.location
			}
			any_court_position_holder = {
				type = champion_court_position
				court_8010_underequipped_trigger = yes
				has_court_event_flag = no
				location = root.location
			}
			any_court_position_holder = {
				type = akolouthos_court_position
				court_8010_underequipped_trigger = yes
				has_court_event_flag = no
				location = root.location
			}
			any_knight = {
				court_8010_underequipped_trigger = yes
				has_court_event_flag = no
				is_landed = no
				location = root.location
			}
        }
    }

    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 = {
        		4 = {
        			trigger = {
        				any_court_position_holder = {
							type = bodyguard_court_position
							court_8010_underequipped_trigger = yes
							location = root.location
						}
        			}
		        	random_court_position_holder = {
						type = bodyguard_court_position
						limit = {
							court_8010_underequipped_trigger = yes
							location = root.location
						}
						save_scope_as = underequipped
						court_event_character_flag_effect = yes
					}
				}
				4 = {
					trigger = {
        				any_court_position_holder = {
							type = champion_court_position
							court_8010_underequipped_trigger = yes
							location = root.location
						}
        			}
					random_court_position_holder = {
						type = champion_court_position
						limit = {
							court_8010_underequipped_trigger = yes
							location = root.location
						}
						save_scope_as = underequipped
						court_event_character_flag_effect = yes
					}
		        }
		        8 = {
					trigger = {
        				any_court_position_holder = {
							type = akolouthos_court_position
							court_8010_underequipped_trigger = yes
							location = root.location
						}
        			}
					random_court_position_holder = {
						type = akolouthos_court_position
						limit = {
							court_8010_underequipped_trigger = yes
							location = root.location
						}
						save_scope_as = underequipped
						court_event_character_flag_effect = yes
					}
		        }
		        1 = {
					trigger = {
        				any_knight = {
							court_8010_underequipped_trigger = yes
							location = root.location
							is_landed = no
						}
        			}
					random_knight = {
						limit = {
							court_8010_underequipped_trigger = yes
							location = root.location
							is_landed = no
						}
						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
	        	}
	        	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 = medium_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 = 20
	    	}
	    }
        stress_impact = {
			greedy = major_stress_impact_gain # It's too expensive
			callous = medium_stress_impact_gain # So?
			arrogant = medium_stress_impact_gain
			paranoid = medium_stress_impact_gain
			fickle = minor_stress_impact_gain
		}
        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 = major_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 (opt out)
        name = court.8010.d
        change_current_court_grandeur = minor_court_grandeur_loss
        custom_tooltip = court.8010.d.tt
        scope:underequipped = {
	        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 = {
			base = minor_stress_impact_loss
		}
        ai_chance = {
            base = 50
            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
            }

        }
    }

    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 = { target = 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
    				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 = { # Make an effort
        name = court.8020.b
        set_amenity_level = { type = court_fashion value = high_amenity_level }
        remove_short_term_gold = minor_gold_value
        capital_county = {
        	add_county_modifier = {
        		modifier = fashion_industry_county_modifier
        		years = 25
        	}
        }
    	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
            }
            modifier = {
            	gold < minor_gold_value
            	factor = 0
            }
        }
    }

     option = { # Laugh it off (opt out)
        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 = {
    		base = minor_stress_impact_loss
    		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
            }
        }
    }

    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 = interested
            }
        }
    }

    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
    				this != scope:child_1
    			}
    		}
    		random_child = {
    			limit = {
    				court_8030_child_trigger = yes
    				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
        }
        stress_impact = {
        	lifestyle_hunter = major_stress_impact_loss
        	greedy = minor_stress_impact_gain
        	impatient = minor_stress_impact_gain
        	family_first = minor_stress_impact_gain
		}
        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
        	}
        }
        if = {
        	limit = { exists = scope:child_2 }
        	scope:child_2 = {
	        	add_opinion = {
	        		target = root
	        		modifier = disappointed_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:child_1 = {
        	add_opinion = {
        		target = root
        		modifier = disappointed_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:child_1 = {
        	add_opinion = {
        		target = root
        		modifier = disappointed_opinion
        		opinion = -15
        	}
        }
        if = {
        	limit = { exists = scope:child_2 }
        	scope:child_2 = {
	        	add_opinion = {
	        		target = root
	        		modifier = disappointed_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 }
	NOR = {
		is_close_family_of = root
		has_trait = content
		has_trait = humble
		is_hostage = yes
	}
	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
				}
			}
			scope:new_noble = {
				add_character_flag = {
					flag = joining_faction_block
					years = 20
				}
			}
			custom_tooltip = joining_faction_block_tt
			every_in_list = {
				list = court_8040_list
				limit = {
					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 = {
	        	title_tier = barony
	        	is_capital_barony = no
	        	is_leased_out = no
	        	this != root.capital_barony
	        }
	        any_held_title = {
	        	count >= 4
	        	title_tier = county
				is_landless_type_title = no
	        }
	    }
	    domain_limit_available < 0
    }

    weight_multiplier = {
        base = 1
        modifier = {
        	is_ai = yes
        	factor = 0.5
        }
        ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_warlike }
        ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_diplomatic }
    }

    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 = {
        			title_tier = barony
        			is_capital_barony = no
        			is_leased_out = no
        			this != root.capital_barony
        		}
        	}
        	ordered_held_title = {
				title_tier = barony
	        	limit = {
	        		is_capital_barony = no
        			is_leased_out = no
        			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 = {
				title_tier = county
	        	limit = {
	        		this != root.capital_county
					is_landless_type_title = no
	        	}
	        	order_by = {
	        		value = 0
	        		subtract = development_level
	        	}
	        	save_scope_as = worst_title
	        }
	    }
    }

    option = { # Best courtier wins - fight
        name = court.8040.d
        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_no_death_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
			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
   			}
            modifier = {	#Weight up for stress.
				add = 15
				has_trait = lifestyle_blademaster
			}
			modifier = {	#Weight up for stress.
				add = 15
				has_trait = viking
			}
			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 = {
			lifestyle_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
   			}
            modifier = {	#Weight up for stress.
				add = 15
				has_trait = lifestyle_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
        add_prestige = minor_prestige_gain
        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 }
		}
	}
}

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
    			is_of_major_or_minor_interest_trigger = { CHARACTER = root }
    		}
    	}
		amenity_level = {
			target = court_servants
			value > high_amenity_level
		}
    }

    weight_multiplier = {
        base = 1
        modifier = {
        	factor = 2
        	amenity_level = {
				target = 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
    			is_of_major_or_minor_interest_trigger = { CHARACTER = root }
    		}
    		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 }
    				}
    			}
    			modifier = {
    				factor = 3
    				is_landed = yes
    			}
    		}
    		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
	        		this != scope:vassal
	        	}
	        }
	        random_in_list = {
	        	list = court_8050_secret_list
	        	limit = { this != scope:vassal }
	        	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 = { # What else have you heard?
        name = court.8050.b
        trigger = { exists = scope:secret_2 }
        add_prestige = minor_prestige_loss
        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 = { # Thanks for your service (opt out)
        name = court.8050.a
        stress_impact = {
        	deceitful = medium_stress_impact_gain # I could have learned so much more...
        	arrogant = medium_stress_impact_gain # I don't surround myself with commoners
			paranoid = medium_stress_impact_gain # What do they know about me instead??
        }
        ai_chance = {
        	base = 50
            ai_value_modifier = {
   				ai_rationality = 0.5
   			}
   			 modifier = { # Weight down for stress.
            	add = -15
            	has_trait = deceitful
            }
             modifier = { # Weight down for stress.
            	add = -15
            	has_trait = arrogant
            }
            modifier = { # Weight down for stress.
            	add = -15
            	has_trait = paranoid
            }
        }
    }

    after = {
    	clear_court_event_participation = yes
    	scope:servant ?= {
    		clear_court_event_participation = yes
    	}
    }
}


#########################
# Building Blocks		#
# by Joe Parkin 		#
#########################

scripted_trigger court_8090_barony_trigger = {
	tier = tier_barony
	is_leased_out = no
	title_province.free_building_slots > 0
	county != scope:my_county
}

court.8090 = {
    type = court_event
    title = court.8090.t
    desc = {
    	first_valid = {
    		triggered_desc = {
    			trigger = {
    				scope:architect = { has_court_position = royal_architect_court_position }
    			}
    			desc = court.8090.desc.intro
    		}
    		desc = court.8090.desc.intro_alt
    	}
    	desc = court.8090.desc.intro_end
    	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
    	}
    	any_held_title = {
    		title_tier = barony
    		is_leased_out = no
    		title_province.free_building_slots > 0
			title_province.county = {
    			any_county_province = {
    				has_holding = no
    			}
    		}
    	}
    }

    weight_multiplier = {
    	base = 1
    	ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_administrative }
		modifier = {
			add = 1
			exists = cp:councillor_steward
	    	cp:councillor_steward = {
	    		is_available_ai_adult = yes
	    		has_trait = compassionate
	    	}
		}
		modifier = {
			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 }
    		}
    		add = 2
		}
    }

    immediate = {
		cp:councillor_steward = {
			save_scope_as = steward
			court_event_character_flag_effect = yes
		}
		random_court_position_holder = {
    		type = royal_architect_court_position
    		limit = { is_available_ai_adult = yes }
    		save_scope_as = architect
    	}
    	if = {
    		limit = {
    			NOT = { exists = scope:architect }
    		}
    		random_pool_character = {
    			province = root.location
    			limit = {
    				stewardship > 12
    				is_adult = yes
    			}
    			save_scope_as = architect
    			hidden_effect = { add_trait = architect }
    		}
    	}
    	if = {
    		limit = {
    			NOT = { exists = scope:architect }
    		}
    		create_character = {
    			location = root.location
    			template = foreign_architect_template
    			save_scope_as = architect
    		}
    		scope:architect = {
    			add_character_flag = created_character
    		}
    	}
    	scope:architect = { court_event_character_flag_effect = yes }
		ordered_held_title = { # Save barony with least buildings
			title_tier = barony
			limit = {
				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 = {
			ordered_county_province = { # Save church in same county
				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 }
			}
			random_county_province = { # Save an empty province in the same county
				limit = {
					has_holding = no
				}
				save_scope_as = empty_holding
			}
		}
		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 = {
						title_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 = {
					title_tier = county
					limit = {
						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_treasury_or_gold = court_8090_half_building_cost_value
		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
            }
            modifier = {
            	gold < court_8090_half_building_cost_value
            	factor = 0
            }
        }
	}

	option = { # For the church
		name = court.8090.b
		trigger = {
			exists = scope:chaplain
			exists = scope:temple_barony
		}
		add_piety = minor_piety_value
		remove_treasury_or_gold = court_8090_half_building_cost_value
		reverse_add_opinion = {
			target = scope:chaplain
			modifier = pleased_opinion
			opinion = 10
		}
		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
            }
             modifier = {
            	gold < court_8090_half_building_cost_value
            	factor = 0
            }
        }
	}

	option = { # Architect can do better
		name = court.8090.c
		trigger = {
			scope:architect = { has_court_position = royal_architect_court_position }
			is_ai = no
		}
		flavor = court.8090.c.tt
		remove_treasury_or_gold = hold_court_holding_cost_architect_cheaper_value
		scope:empty_holding = {
			begin_create_holding = {
				type = castle_holding
				refund_cost = {
					gold = hold_court_holding_cost_architect_cheaper_value
				}
			}
		}
		stress_impact = {
			greedy = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
			fickle = medium_stress_impact_gain
		}
		ai_chance = {
            base = 0
        }
	}

	option = { # For the people (opt out)
		name = court.8090.d
		scope:my_barony.county = {
			add_county_modifier = {
				modifier = court_8090_commoners_modifier
				years = 25
			}
		}
		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 = 1
            	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 }
		}
		scope:steward = {
			clear_court_event_participation = yes
		}
		scope:architect = {
			clear_court_event_participation = yes
			if = {
				limit = {
					root = {
						is_ai = yes
					}
					has_character_flag = created_character
				}
				silent_disappearance_effect = yes
			}
		}
	}
}


#########################
# Royal Lapse 			#
# by Joe Parkin 		#
#########################

court.8140 = {
    type = court_event
    title = court.8140.t
    desc = court.8140.desc
    theme = court
    cooldown = { years = 10 }
	orphan = yes
    court_scene = {
        button_position_character = scope:vassal_1
        roles = {
            scope:vassal_1 = {
                group = event_group
                animation = throne_room_kneel_2
            }
            scope:vassal_2 = {
                group = event_group
                animation = throne_room_conversation_4
            }
        }
    }

    trigger = {
    	has_a_stress_coping_trait_trigger = yes
    	stress_level >= 1
    	OR = {
    		exists = cp:councillor_court_chaplain
    		exists = cp:councillor_steward
    		exists = court_position:seneschal_court_position
    		exists = court_position:travel_leader_court_position
    	}
    	OR = {
    		exists = cp:councillor_marshal
    		exists = court_position:master_of_hunt_court_position
    		exists = court_position:master_of_horse_court_position
    		exists = court_position:court_physician_court_position
    	}
    }

    weight_multiplier = {
    	base = 1
    	modifier = {
    		factor = 2
    		has_two_stress_coping_traits_trigger = yes
    	}
    	modifier = {
    		factor = stress_level
    		stress_level >= 1
    	}
    }

    immediate = {
    	random_list = {
    		1 = {
    			cp:councillor_court_chaplain ?= { save_scope_as = vassal_1 } #prayer
    		}
    		1 = {
    			cp:councillor_steward ?= { save_scope_as = vassal_1 } #feast
    		}
    		2 = {
    			court_position:seneschal_court_position ?= { save_scope_as = vassal_1 } #feast
    		}
    		2 = {
    			court_position:travel_leader_court_position ?= { save_scope_as = vassal_1 } #travel
    		}
    	}
    	random_list = {
    		1 = {
    			cp:councillor_marshal ?= { save_scope_as = vassal_2 } #hunt
    		}
    		2 = {
    			court_position:master_of_hunt_court_position ?= { save_scope_as = vassal_2 } #hunt
    		}
    		2 = {
    			trigger = {
    				NOT = {
    					any_owned_story = {
							type = story_cycle_martial_lifestyle_warhorse
						}
					}
    			}
    			court_position:master_of_horse_court_position ?= { save_scope_as = vassal_2 } #horse
    		}
    		2 = {
    			court_position:court_physician_court_position ?= { save_scope_as = vassal_2 } #fresh air
    		}
    	}
    }

    option = { # Engage in stress coping
        name = court.8140.b
        flavor = court.8140.b.flavor_tt
        change_current_court_grandeur = medium_court_grandeur_loss
        scope:vassal_1 = {
        	add_opinion = {
        		target = root
        		modifier = annoyed_opinion
        		opinion = -15
        	}
        }
        scope:vassal_2 = {
        	add_opinion = {
        		target = root
        		modifier = annoyed_opinion
        		opinion = -15
        	}
        }
        stress_impact = {
        	base = massive_stress_impact_loss
        }
        ai_chance = {
        	base = 100
        	ai_value_modifier = {
				ai_compassion = -1
				ai_energy = -1
			}
        	modifier = {
        		add = -30
        		has_trait = diligent
        	}
        }
    }

    option = { # vassal_1 proposal
        name = {
			trigger = { #prayer
				scope:vassal_1 = cp:councillor_court_chaplain
			}
			text = court.8140.c.1
		}
		name = {
			trigger = { #feast
				OR = {
					scope:vassal_1 = cp:councillor_steward
					scope:vassal_1 = court_position:seneschal_court_position
				}
			}
			text = court.8140.c.2
		}
		name = {
			trigger = { #travel
				scope:vassal_1 = court_position:travel_leader_court_position
			}
			text = court.8140.c.3
		}
        flavor = court.8140.c.flavor_tt
        if = { #prayer
        	limit = {
        		scope:vassal_1 = cp:councillor_court_chaplain
        	}
        	add_piety = major_piety_gain
        	custom_tooltip = court.8140.c.tt.2
        	add_character_flag = {
        		flag = court_event_discount_pilgrimage
        		years = 10
        	}
        }
        else_if = { #feats
        	limit = {
        		OR = {
					scope:vassal_1 = cp:councillor_steward
					scope:vassal_1 = court_position:seneschal_court_position
				}
        	}
        	custom_tooltip = court.8140.c.tt
        	add_character_flag = {
        		flag = court_event_discount_feast
        		years = 5
        	}
        }
        else = { #travel
        	add_character_modifier = {
        		modifier = enjoy_the_travel_modifier
        		years = 25
        	}
        }
        ai_chance = {
        	base = 100
        	ai_value_modifier = {
        		ai_energy = 1
			}
        }
    }

    option = { # vassal_2 proposal
        name = {
			trigger = { #hunt
				OR = {
					scope:vassal_2 = cp:councillor_marshal
					scope:vassal_2 = court_position:master_of_hunt_court_position
				}
			}
			text = court.8140.d.1
		}
		name = {
			trigger = { #horse
				scope:vassal_2 = court_position:master_of_horse_court_position
			}
			text = court.8140.d.2
		}
		name = {
			trigger = { #fresh air
				scope:vassal_2 = court_position:court_physician_court_position
			}
			text = court.8140.d.3
		}
        flavor = court.8140.d.flavor_tt
        if = { #hunt
        	limit = {
        		OR = {
					scope:vassal_2 = cp:councillor_marshal
					scope:vassal_2 = court_position:master_of_hunt_court_position
				}
        	}
        	custom_tooltip = court.8140.d.tt
        	add_character_flag = {
        		flag = court_event_discount_hunt
        		years = 5
        	}
        }
        else_if = {
        	limit = {
        		scope:vassal_2 = court_position:master_of_horse_court_position
        	}
        	start_warhorse_story_cycle_effect = yes
        }
        else = {
        	add_character_modifier = {
        		modifier = healthy_strolls_modifier
        		years = 25
        	}
        }
        ai_chance = {
        	base = 100
        	ai_value_modifier = {
        		ai_energy = 1
			}
        }
    }

    option = { # Make an effort (opt out)
        name = court.8140.a
        flavor = court.8140.a.flavor_tt
        change_current_court_grandeur = medium_court_grandeur_gain
        stress_impact = {
        	base = minor_stress_impact_gain
        }
        ai_chance = {
        	base = 0
        	ai_value_modifier = {
				ai_rationality = 0.5
			}
        	modifier = {
        		add = -15
        		has_trait = fickle
        	}
        	modifier = {
        		add = -15
        		has_trait = callous
        	}
        	modifier = {
        		add = -15
        		has_trait = arbitrary
        	}
        	modifier = {
        		add = -15
        		has_trait = lazy
        	}
        }
    }

    after = {
    	scope:vassal_1 = {
    		clear_court_event_participation = yes
    	}
    	scope:vassal_2 = {
    		clear_court_event_participation = yes
    	}
    }
}

#########################
# Prandial Excess		#
# by Joe Parkin 		#
#########################

scripted_trigger court_8150_foodie_trigger = {
	NOR = {
		has_trait = temperate
		has_trait = inappetetic
	}
}

scripted_trigger court_8150_vassal_trigger = {
	is_available_ai_adult = yes
	court_8150_foodie_trigger = yes
	trigger_if = {
		limit = { exists = scope:chaplain }
		this != scope:chaplain
	}
	trigger_if = {
		limit = { exists = scope:food_taster }
		this != scope:food_taster
	}
	trigger_if = {
		limit = { exists = scope:high_almoner }
		this != scope:high_almoner
	}
	trigger_if = {
		limit = { exists = scope:vassal_1 }
		this != scope:vassal_1
	}
	trigger_if = {
		limit = { exists = scope:vassal_2 }
		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 = {
    		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
    		}
    		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 = {
		NOT = {
			faith = { has_doctrine = tenet_ritual_celebrations }
		}
    	amenity_level = { target = 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 = {
        	add = 1
        	amenity_level = { target = court_food_quality value > very_high_amenity_level }
        }
        modifier = {
        	add = 1
        	employs_court_position = high_almoner_court_position
        }
        modifier = {
        	add = 1
        	employs_court_position = food_taster_court_position
        }
    }

    immediate = {
    	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 }
 		}
 		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 }
						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 }
						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
        if = {
        	limit = {
        		exists = scope:food_taster
        	}
        	custom_tooltip = court.8150.a.tt
        	scope:food_taster = {
        		add_character_flag = food_taster_mettle_tested
       		}
       	}
        if = {
        	limit = { exists = scope:chaplain }
    		reverse_add_opinion = {
    			modifier = disgusted_opinion
    			target = scope:chaplain
    			opinion = -10
    		}
        }
        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 = { # Stop foodies
        name = court.8150.c
        add_legitimacy = miniscule_legitimacy_gain
        if = {
        	limit = {
	        	NOT = {
	        		faith = { has_doctrine = tenet_hedonistic }
	        	}
        	}
        	add_piety = medium_piety_gain
        }
	    if = {
	       	limit = { exists = scope:chaplain }
	    	reverse_add_opinion = {
	    		modifier = pleased_opinion
	    		target = scope:chaplain
	    		opinion = 10
	    	}
	    }
	    if = {
        	limit = {
        		exists = scope:high_almoner
        	}
        	custom_tooltip = court.8150.b.tt
        	scope:high_almoner = {
        		add_character_flag = plenty_to_donate_almoner
	    		add_opinion = {
	    			modifier = pleased_opinion
	    			target = root
	    			opinion = 10
	    		}
	    	}
        }
        stress_impact = {
        	gluttonous = medium_stress_impact_gain
        	arrogant = medium_stress_impact_gain
        	profligate = medium_stress_impact_gain
        	cynical = medium_stress_impact_gain
        }
        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
			}
			modifier = {
				add = 50
				has_trait = temperate
			}
		}
    }

    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 = { # employ them both
        name = court.8160.a
        trigger = {
        	OR = {
        		any_court_position_holder = {
        			type = bodyguard_court_position
        			count < 1
        		}
        		AND = {
        			any_court_position_holder = {
        				type = bodyguard_court_position
        				count < 2
        			}
        			NOT = { employs_court_position = champion_court_position }
        		}
        		AND = {
        			any_court_position_holder = {
        				type = bodyguard_court_position
        				count < 2
        			}
        			NOT = { employs_court_position = akolouthos_court_position }
        			can_employ_court_position_type = akolouthos_court_position
        		}
        	}
        }
        court_position_grant_effect = { POS = bodyguard CANDIDATE = scope:knight_1 EMPLOYER = root }
        if = {
        	limit = {
        		any_court_position_holder = {
        			type = bodyguard_court_position
        			count = 1
        		}
        	}
			court_position_grant_effect = { POS = bodyguard CANDIDATE = scope:knight_2 EMPLOYER = root }
        }
        else_if = {
        	limit = {
        		NOT = { employs_court_position = champion_court_position }
        	}
        	court_position_grant_effect = { POS = champion CANDIDATE = scope:knight_2 EMPLOYER = root }
        }
        else = {
       	 	court_position_grant_effect = { POS = akolouthos CANDIDATE = scope:knight_2 EMPLOYER = root }
        }
        custom_tooltip = court.8160.a.tt
        scope:knight_1 = { add_character_flag = competing_knight_position }
        scope:knight_2 = { add_character_flag = competing_knight_position }
        stress_impact = {
        	wrathful = medium_stress_impact_gain
        	fickle = medium_stress_impact_gain
        	arbitrary = medium_stress_impact_gain
        }
        ai_chance = {
        	base = 100
        	ai_value_modifier = {
        		ai_compassion = 0.5
        		ai_sociability = 0.5
        	}
        }
    }


    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 }
					}
				}
			}
		}
		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 = {
			craven = medium_stress_impact_gain
			deceitful = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 1
				ai_honor = 1
			}
		}
    }

    option = { # Do not allow duel
        name = court.8160.d
        add_character_modifier = {
        	modifier = fostering_competitiveness_modifier
        	years = 10
        }
		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
			wrathful = medium_stress_impact_gain
			vengeful = medium_stress_impact_gain
			fickle = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = 0.5
				ai_rationality = 1
			}
			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
			}
		}
    }
    after = {
    	scope:knight_1 = {
    		clear_court_event_participation = yes
    	}
    	scope:knight_2 = {
    		clear_court_event_participation = yes
    	}
    }
}

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
					custom_tooltip = court.8162.tt
					add_character_flag = best_knight_position
				}
			}
		}
	}
}


#########################
# 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
		}
	}
}

scripted_trigger cannibal_crime_trigger = {
	AND = {
		NOT = {
			liege.faith = { has_doctrine = tenet_ritual_cannibalism }
		}
		has_trait = cannibal
	}
}

scripted_trigger witch_crime_trigger = {
	AND = {
		liege.faith = { has_doctrine_parameter = witchcraft_illegal }
		has_trait = witch
	}
}

scripted_trigger deviant_crime_trigger = {
	AND = {
		liege.faith = { has_doctrine_parameter = deviancy_illegal }
		has_trait = deviant
	}
}

scripted_trigger sodomite_crime_trigger = {
	AND = {
		liege.faith = { has_doctrine = doctrine_homosexuality_crime }
		is_male = yes
		has_trait = sodomite
	}
}

scripted_trigger incest_crime_trigger = {
	AND = {
		liege.faith = {
			NOT = { has_doctrine = doctrine_consanguinity_unrestricted }
		}
		has_trait = incestuous
	}
}

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
		}
	}
}

scripted_trigger excommunicated_crime_trigger = {
	AND = {
		faith = liege.faith
		has_trait = excommunicated
	}
}

scripted_trigger faith_crime_trigger = {
	AND = {
		faith = {
			faith_hostility_level = {
				target = ROOT.faith
				value >= faith_hostile_level
			}
		}
	}
}

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
	}
}

scripted_trigger court_8170_criminal_trigger = {
	is_imprisoned = no
	is_landed = no
	is_illegal_criminal_trigger = yes
	NOR = {
		has_relation_lover = root
		has_relation_soulmate = root
	}
}

scripted_effect court_8170_torture_etc_end_effect = {
	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 = major_stress_impact_gain
	}
}

scripted_effect court_8170_torture_etc_setup_effect = {
	change_current_court_grandeur = medium_court_grandeur_gain
    add_legitimacy = miniscule_legitimacy_gain
    add_character_modifier = {
    	modifier = fast_hard_justice_modifier
    	years = 10
    }
    rightfully_imprison_character_effect = {
		TARGET = scope:criminal
		IMPRISONER = root
	}
	#Needed for the scripted effects below
	root = { save_scope_as = actor }
	scope:criminal = { save_scope_as = recipient }
}

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
        modifier = {
        	any_courtier_or_guest = {
        		is_close_or_extended_family_of = root
    			court_8170_criminal_trigger = yes
        	}
        	add = 1
        }
        modifier = {
        	any_courtier_or_guest = {
        		is_of_major_or_minor_interest_trigger = { CHARACTER = root }
    			court_8170_criminal_trigger = yes
        	}
        	add = 0.5
        }
    }

    immediate = {
    	random_courtier_or_guest = {
    		limit = {
    			is_close_or_extended_family_of = root
    			court_8170_criminal_trigger = yes
    		}
    		alternative_limit = {
    			is_of_major_or_minor_interest_trigger = { CHARACTER = 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 = { # Let them stay: dark deals to protect you
        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 = 10
        }
        reverse_add_opinion = {
    		target = scope:criminal
    		modifier = grateful_opinion
    		opinion = 10
    	}
        stress_impact = {
        	just = major_stress_impact_gain
        	vengeful = medium_stress_impact_gain
        	diligent = medium_stress_impact_gain
        	honest = medium_stress_impact_gain
        	zealous = medium_stress_impact_gain
        }
        ai_chance = {
        	base = 100
        	modifier = {
        		has_trait = just
        		add = -75
        	}
        	modifier = {
        		has_trait = diligent
        		add = -50
        	}
        	modifier = {
        		has_trait = honest
        		add = -50
        	}
        	ai_value_modifier = {
        		ai_zeal = -0.5
        		ai_vengefulness = -1
        	}
        }
    }

    option = { # Big deal of punishing them: blind
        name = court.8170.c1
        trigger = {
        	scope:criminal = { NOT = { has_trait = blind } }
			culture = { has_cultural_parameter = can_blind_prisoners }
        }
        court_8170_torture_etc_setup_effect = yes
		blind_recipient_effect = yes
		# House Feud
		add_character_flag = house_feud_blinding_flag
		house_feud_torture_event_effect = yes
		court_8170_torture_etc_end_effect = yes
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = -1
				ai_vengefulness = 1
			}
		}
	}

	option = { #castrate
		name = court.8170.c2
		trigger = {
			scope:criminal = {
				NOT = { has_trait = eunuch }
				is_male = yes
				culture = {
					has_cultural_parameter = can_castrate_prisoners
				}
			}
		}
        court_8170_torture_etc_setup_effect = yes
		castrate_recipient_effect = yes
		# House Feud
		add_character_flag = house_feud_castration_flag
		house_feud_torture_event_effect = yes
		court_8170_torture_etc_end_effect = yes
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = -1
				ai_vengefulness = 1
			}
		}
	}

	option = { #execute
		name = court.8170.c3
		court_8170_torture_etc_setup_effect = yes
		execute_prisoner_effect = {
			VICTIM = scope:recipient
			EXECUTIONER = scope:actor
		}
		if = {
			limit = {
				scope:actor.capital_county = {
					NOT = { has_county_modifier = held_public_execution_modifier }
				}
			}
			scope:actor = {
				capital_county = {
					add_county_modifier = {
						modifier = held_public_execution_modifier
						days = 1850
					}
				}
				custom_tooltip = public_execution_control_effect
				hidden_effect = {
					every_held_title = {
						title_tier = county
						change_county_control = executioner_control_value
					}
				}
			}
		}
		court_8170_torture_etc_end_effect = yes
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = -1
				ai_vengefulness = 1
			}
		}
	}

    option = { # Kick out - opt 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
	    }
        hidden_effect = {
        	scope:criminal = { select_and_move_to_pool_effect = yes }
        }
        show_as_tooltip = { remove_courtier_or_guest = scope:criminal }
        ai_chance = {
        	base = 100
        	ai_value_modifier = {
        		ai_energy = -1
        	}
        }
    }
    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 }
	is_of_major_or_minor_interest_trigger = { CHARACTER = root }
}

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
        modifier = {
        	cp:councillor_spymaster.intrigue >= 15
        	add = 1
        }
        modifier = {
        	cp:councillor_spymaster ?= { is_performing_council_task = task_find_secrets }
        	add = 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 = { # Blackmail
        name = court.8180.b
        trigger = {
        	NOT = { has_hook = scope:criminal }
        }
        blackmail_interaction_effect = yes
        scope:criminal = {
        	add_character_modifier = {
        		modifier = liege_scrutiny_modifier
        		years = 20
        	}
        }
        stress_impact = {
    		forgiving = major_stress_impact_gain
    		honest = medium_stress_impact_gain
    		gregarious = medium_stress_impact_gain
    		lazy = minor_stress_impact_gain
    		compassionate = minor_stress_impact_gain
        }
        ai_chance = {
        	base = 100
        	ai_value_modifier = {
        		ai_vengefulness = 0.5
        		ai_compassion = -0.5
        	}
        }
    }

    option = { # Punish
        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 }
		}
		add_character_modifier = {
			modifier = court_without_secrets_modifier
			years = 15
		}
		custom_tooltip = court.6002.a.tt2
		stress_impact = {
    		arbitrary = minor_stress_impact_gain
    		cynical = minor_stress_impact_gain
    		deceitful = medium_stress_impact_gain
    		compassionate = medium_stress_impact_gain
        }
        ai_chance = {
        	base = 100
        	ai_value_modifier = {
        		ai_rationality = 0.5
        		ai_zeal = 0.5
        	}
        }
    }

    option = { # Do nothing - opt out
        name = court.8180.e
        stress_impact = {
    		base = minor_stress_impact_loss
    		lazy = minor_stress_impact_loss
    		compassionate = minor_stress_impact_loss
    		vengeful = medium_stress_impact_gain
    		zealous = medium_stress_impact_gain
    		diligent = medium_stress_impact_gain
    		deceitful = major_stress_impact_gain
        }
        ai_chance = {
        	base = 75
        }
    }
    after = {
    	scope:criminal = {
    		clear_court_event_participation = yes
    	}
    }
}





##################################################
# Oltner

##################################################
# 9000 - 9009	A Knight's Declaration
# 9100 - 9109	Epicurean Entertainment
# 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_character = root.primary_spouse
	}
	NOR = {
		has_trait = chaste
		has_trait = celibate
		has_relation_lover = root.primary_spouse
	}
	would_attempt_to_seduce_married_trigger = yes
	would_attempt_to_seduce_trigger = { CHARACTER = root.primary_spouse }
	might_cheat_on_every_partner_trigger = yes
}

# 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

		modifier = {
			root.primary_spouse = { might_cheat_on_every_partner_trigger = yes }
			add = 1
		}
		modifier = {
			culture = { has_cultural_tradition = tradition_chivalry }
			add = 2
		}

		# 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 = lifestyle_poet
				}
			}
			hidden_effect = {
				if = {
					limit = {
						NOT = {
							has_trait = lifestyle_poet
						}
					}
					add_trait = lifestyle_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 = { # Stop this at once!
		name = court.9000.b

		custom_tooltip = court_9000_b_tt

		add_prestige = minor_prestige_loss
		add_character_modifier = {
			modifier = detractor_of_courtly_love_modifier
			years = 20
		}
		custom_tooltip = court_9000.b.tt
		scope:flirty_spouse = {
			add_opinion = {
				target = root
				modifier = rude_opinion
				opinion = -20
			}
		}
		scope:flirty_knight = {
			hidden_effect = {
				random = {
					chance = 35
					start_scheme = {
						type = courting
						target_character = scope:flirty_spouse
					}
				}
			}
		}

		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
				}
			}
		}
	}

	option = { # Let it go on!
		name = court.9000.c

		custom_tooltip = court_9000_c_tt

		change_current_court_grandeur = major_court_grandeur_gain
		add_character_modifier = {
			modifier = promoter_of_courtly_love_modifier
			years = 20
		}
		custom_tooltip = court_9000.c.tt
		scope:flirty_knight = {
			create_inspiration = book_inspiration
			hidden_effect = {
				start_scheme = {
					type = courting
					target_character = 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
				}
			}
		}
	}
	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
			}
			might_cheat_on_every_partner_trigger = yes

			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
		modifier = {
			culture = { has_cultural_tradition = tradition_chivalry }
			add = 2
		}
		# 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
		}
		add_prestige = medium_prestige_gain
		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 = {
			banish_effect = { BANISHER = root }
			hidden_effect = {
				if = {
					limit = {
						any_scheme = {
							type = courting
							scheme_target_character = scope:flirty_spouse
						}
					}
					random_scheme = {
						type = courting
						limit = {
							scheme_target_character = scope:flirty_spouse
						}
						end_scheme = yes
					}
				}
			}
		}
		if = {
			limit = {
				NOR = {
					has_character_modifier = detractor_of_courtly_love_modifier
					has_character_modifier = promoter_of_courtly_love_modifier
				}
			}
			add_character_modifier = {
				modifier = detractor_of_courtly_love_modifier
				years = 20
			}
			custom_tooltip = court_9000.b.tt
		}
		else = {
			add_hook = {
				target = scope:flirty_spouse
				type = loyalty_hook
			}
		}

		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
		if = {
			limit = {
				NOR = {
					has_character_modifier = promoter_of_courtly_love_modifier
					has_character_modifier = detractor_of_courtly_love_modifier
				}
			}
			add_character_modifier = {
				modifier = promoter_of_courtly_love_modifier
				years = 20
			}
			custom_tooltip = court_9000.c.tt
		}
		else =  { add_prestige = medium_prestige_gain }

		stress_impact = {
			paranoid = massive_stress_impact_gain
			arrogant = major_stress_impact_gain
			vengeful = 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
				}
			}
		}
	}
	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 = {
						type = courting
						scheme_target_character = scope:flirty_spouse
					}
				}
				random_scheme = {
					type = courting
					limit = {
						scheme_target_character = scope:flirty_spouse
					}
					end_scheme = yes
				}
			}
			if = {
				limit = {
					has_relation_lover = scope:flirty_spouse
				}
				remove_relation_lover = 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
			}
			create_inspiration = book_inspiration
		}
		if = {
			limit = {
				can_add_hook = {
					target = scope:flirty_knight
					type = loyalty_hook
				}
			}
			add_hook = {
				type = loyalty_hook
				target = scope:flirty_knight
			}
		}

		add_character_modifier = {
			modifier = knight_of_love_modifier
			years = 20
		}
		scope:flirty_spouse = {
			add_opinion = {
				target = scope:flirty_knight
				modifier = disappointed_opinion
				opinion = -40
			}
			add_opinion = {
				modifier = impressed_opinion
				target = root
				opinion = 40
			}
			if = {
				limit = {
					can_set_relation_lover_trigger = { CHARACTER = root }
				}
				set_relation_lover = { reason = lover_dueled_for_love target = root involved_character = scope:flirty_knight }
			}
		}

		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 = {
		name = court.9005.a

		scope:flirty_knight = {
			hidden_effect = {
				if = {
					limit = {
						has_relation_lover = scope:flirty_spouse
					}
					remove_relation_lover = 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
				}
			}
		}

		scope:flirty_spouse = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -40
			}
			add_opinion = {
				modifier = impressed_opinion
				target = scope:flirty_knight
				opinion = 40
			}
			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 }
			}
		}
		add_character_modifier = {
			modifier = fought_for_courtly_love_modifier
			years = 20
		}
		add_prestige = major_prestige_loss
		if = {
			limit = {
				scope:flirty_knight = {
					government_allows = administrative
				}
			}
			scope:flirty_knight = {
				change_influence = medium_influence_gain
			}
		}
		else = {
			scope:flirty_knight = { add_prestige = major_prestige_gain }
		}

		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 = { target = 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
			}
			is_of_major_or_minor_interest_trigger = { CHARACTER = 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
					}
					is_of_major_or_minor_interest_trigger = { CHARACTER = root }
				}
				weight = {
					base = 1
					modifier = {
						add = 100
						loves_food_trigger = yes
					}
					modifier = {
						add = 50
						has_relation_potential_friend = root
					}
					modifier = {
						add = 30
						is_of_major_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
					}
					is_of_major_or_minor_interest_trigger = { CHARACTER = root }
					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 = 30
						is_of_major_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
					}
					is_of_major_or_minor_interest_trigger = { CHARACTER = 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 = 30
						is_of_major_interest_to_root_trigger = yes
					}
				}
				save_scope_as = food_lover_3
				court_event_character_flag_effect = yes
				change_current_weight = 15
			}
		}
	}

	option = { # More working, less stuffing faces!
		name = court.9100.a
		trigger = {
			NOT = { government_has_flag = government_is_mandala }
		}
		add_character_modifier = {
			modifier = more_work_less_fun_modifier
			years = 15
			desc = feasts_more_expensive_modifier_tt
		}
		custom_tooltip = feasts_more_expensive_tt
		stress_impact = {
			gregarious = major_stress_impact_gain
			gluttonous = major_stress_impact_gain
			lazy = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0.1
				OR = {
					has_trait = gregarious
					has_trait = gluttonous
					has_trait = lazy
				}
			}
		}
	}

	option = { # You all deserve the best!
		name = court.9100.b
		add_character_modifier = {
			modifier = promise_of_feasts_modifier
			years = 15
		}
		progress_towards_friend_effect = {
			REASON = friend_fellow_food_lover
			CHARACTER = scope:food_lover_1
			OPINION = default_friend_opinion
		}
		progress_towards_friend_effect = {
			REASON = friend_fellow_food_lover
			CHARACTER = scope:food_lover_2
			OPINION = default_friend_opinion
		}
		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
			greedy = medium_stress_impact_gain
			callous = medium_stress_impact_gain
			temperate = medium_stress_impact_gain
			shy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0.1
				OR = {
					has_trait = sadistic
					has_trait = callous
					has_trait = temperate
					has_trait = greedy
					has_trait = shy
				}
			}
		}
	}

	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 = minor_stress_impact_gain
			gluttonous = minor_stress_impact_gain
			fickle = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0.5
				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
		}
	}
}


#########################
# 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 = { target = court_food_quality value >= 4 }
		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
			loves_food_trigger = yes
			NOR = {
				this = scope:another_courtier_check
				is_of_major_interest_to_root_trigger = yes
			}
			is_of_minor_interest_to_root_trigger = yes
		}
	}

	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
				has_court_event_flag = no
				loves_food_trigger = yes
				NOR = {
					this = scope:another_courtier_check
					is_of_major_interest_to_root_trigger = yes
				}
				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
				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
		if = {
			limit = {
				can_add_hook = {
					target = scope:overindulger_target
					type = major_threat_hook
				}
			}
			add_hook = {
				target = scope:overindulger_target
				type = major_threat_hook
			}
		}
		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
					add_prestige = medium_prestige_gain
					if = {
						limit = {
							government_allows = administrative
						}
						change_influence = medium_influence_gain
					}
					if = {
						limit = {
							can_add_hook = {
								target = scope:overindulger_target
								type = favor_hook
							}
						}
						add_hook = {
							target = scope:overindulger_target
							type = favor_hook
						}
					}
					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
						}
					}
				}
			}
			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
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0.1
				ai_compassion <= low_positive_ai_value
			}
		}
	}

	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_trait = dwarf
}

scripted_trigger court_9400_courtier_trigger = {
	is_available_ai_adult = yes
	NOT = {
		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 = { target = court_food_quality value >= 2 }
		amenity_level = { target = court_servants value >= 2 }
		OR = {
			AND = {
				any_courtier = {
					court_9400_court_jester_trigger = yes
					has_court_event_flag = no
					save_temporary_scope_as = jester_check
				}
				any_courtier = {
					court_9400_courtier_trigger = yes
					has_court_event_flag = no
					this != scope:jester_check
				}
			}
			any_vassal = {
				court_9400_courtier_trigger = yes
				has_court_event_flag = no
				any_courtier = {
					court_9400_court_jester_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_vassal = {
			limit = {
				court_9400_courtier_trigger = yes
				has_court_event_flag = no
				any_courtier = {
					court_9400_court_jester_trigger = yes
					has_court_event_flag = no
				}
			}
			save_scope_as = pie_presenting_courtier
			court_event_character_flag_effect = yes
			random_courtier = {
				limit = {
					court_9400_court_jester_trigger = yes
					has_court_event_flag = no
				}
				save_scope_as = court_jester
				court_event_character_flag_effect = yes
			}
		}
		if = {
			limit = {
				NOR = {
					exists = scope:pie_presenting_courtier
					exists = scope:court_jester
				}
			}
			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 = {
					type = secret_cannibal
					NOT = {
						is_known_by = scope:pie_presenting_courtier
					}
				}
			}
			random_secret = {
				type = secret_cannibal
				limit = {
					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 = 200
			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
		}
		if = {
			limit = {
				scope:court_jester.location = {
					this != root.location
				}
			}
			scope:court_jester = {
				set_location = root.location
			}
		}
		if = {
			limit = {
				scope:court_jester = {
					NOT = {
						is_courtier_of = root
					}
				}
			}
			add_courtier = scope:court_jester
		}
		if = {
			limit = {
				can_employ_court_position_type = court_jester_court_position
				scope:court_jester = { can_be_employed_as = court_jester_court_position }
			}
			court_position_grant_effect = { POS = court_jester CANDIDATE = scope:court_jester EMPLOYER = root }
		}
		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
		trigger = {
			has_trait = paranoid
		}

		rightfully_imprison_character_effect = {
			TARGET = scope:court_jester
			IMPRISONER = root
		}

		if = {
			limit = {
				is_ai = yes
			}
			execute_prisoner_effect = {
				VICTIM = scope:court_jester
				EXECUTIONER = root
			} 
		}
		else = {
			scope:court_jester = {	
				progress_towards_rival_effect = {
					CHARACTER = root
					REASON = rival_jester_jailed
					OPINION = 0
				}
			}
		}
		
		add_character_modifier = {
			modifier = suspicious_against_pies_modifier
			years = 15
		}

		scope:pie_presenting_courtier = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -25
			}
		}

		stress_impact = {
			base = massive_stress_impact_loss
			compassionate = medium_stress_impact_gain
			forgiving = medium_stress_impact_gain
		}
		ai_chance = {
			base = 200
		}
	}

	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
				is_eunuch_trigger = yes
			}
		}
		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
			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
				this != scope:child_to_learn_language
			}
			weight = {
				base = 1
				modifier = {
					add = 100
					has_court_position = court_tutor_court_position
				}
				modifier = {
					add = 50
					is_eunuch_trigger = yes
				}
			}
			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:child_to_learn_language = {
			learn_language_of_culture = scope:culture_language_to_learn
		}

		scope:teacher_target = {
			add_opinion = {
				target = root
				opinion = 10
				modifier = grateful_opinion
			}
		}

		if = {
			limit = {
				scope:teacher_target = {
					NOT = { has_court_position = court_tutor_court_position }
				}
				can_appoint_char_to_court_position = {
					CHAR = scope:teacher_target
					COURT_POS = court_tutor_court_position
				}
			}
			court_position_grant_effect = { POS = court_tutor CANDIDATE = scope:teacher_target EMPLOYER = root }
		}

		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
		}
	}
}
