namespace = hold_court

# Differences in namespace range down to the ongoing CD civil war between whether a range starts at 0 or 1.
## It starts at 001 and goes to 000, damn it, and anyone who says otherwise is a knave and a cur.

##################################################
# # RANGES
# 0001 - 0100		Setup, Example, & Misc
# 1001 - 2000		Shoes
# 2001 - 2999		Ewan
# 3000 - 4000		Bianca
# 4001 - 5000		Isabella
# 5001 - 5999		Linnea
# 6000 - 6999		Claudia
# 7000 - 8000		George
# 8001 - 8999		Joe
# 9000 - 9999		Oltner
# 
##################################################











##################################################
# Setup, Example, & Misc

##################################################
# 0001 - 0010	Example Event
# 0011 - 0010	Activity Start
# 0021 - 0020	Activity End
##################################################

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

# Example hold court event for studying.
hold_court.0001 = {
	# Court-type events only appear in the Royal Court view, and, for the Hold Court activity, are mandatory.
	type = court_event
	# Desc and theming rules are as normal, but since there's no background, there's no need for background overrides.
	title = hold_court.0001.t
	desc = hold_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

	# Hold Court events should be fired from their specific on_action (hold_court_event_selection), 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
		# Forcibly open the event next.
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		# 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.
				group = petitioners_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).
				animation = anger
			}
			scope:character_b = {
				group = petitioners_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.
		}
	}

	# Add the widget to show which court event we're currently at in the chain.
	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

	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 = hold_court.0001.a
	}
}

##################################################
# Activity Start
# by Sean Hughes & Ewan Cowhig Croft
# 0011 - 0010
##################################################

# Played at the start of the activity as an intro.
hold_court.0011 = {
	type = court_event
	title = hold_court.0001.t
	desc = hold_court.0001.desc
	theme = realm
	override_sound = { reference = "event:/SFX/Events/Themes/sfx_event_theme_type_duty" }
	court_scene = {
		button_position_character = root
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		# roles = {
		# 	root = {
		# 		role = ruler
		# 		animation = throne_room_ruler
		# 	}
		# }
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

	immediate = {
		# Play the appropriate music cue.
		if = {
			limit = {
				culture = { has_graphical_mena_culture_group_trigger = yes }
			}
			play_music_cue = "middleeasterncourt_cue"
		}
		else_if = {
			limit = {
				culture = { has_graphical_mediterranean_culture_group_trigger = yes }
			}
			play_music_cue = "mediterraneancourt_cue"
		}
		else_if = {
			limit = {
				culture = { has_graphical_india_culture_group_trigger = yes }
			}
			play_music_cue = "indiancourt_cue"
		}
		else_if = {
			limit = {
				culture = { has_graphical_east_asia_culture_group_trigger = yes }
			}
			play_music_cue = "mx_cue_tgp_asian_tournament"
		}
		## If we can't find a more specific cue track, default to something more neutral.
		else = { play_music_cue = "europeancourt_cue" }
		# Set variable so we know if a player is holding court 
		if = {
			limit = {
				has_multiple_players = no
			}
			add_character_flag = {
				flag = holding_court_character_flag
				days = 5
			}
		}
		else = {
			add_character_flag = {
				flag = holding_court_character_flag
				years = 1
			}
		}
		
		# Tracking for how many petitioners have come through.
		set_variable = {
			name = num_petitioners
			value = initial_petitioners_value
		}
		# Start a counting variable for widget progress.
		set_variable = {
			name = petitioner_current_progress
			value = 0
		}
		# Widget setup.
		## Set the total length of the chain.
		save_scope_value_as = {
			name = event_chain_length
			value = petitioner_total_chain_length_value
		}
		## Manually set the current widget length.
		### Due to code-side shenanigans, we do this a bit awkwardly.
		save_scope_value_as = {
			name = event_chain_progress
			value = 1
		}
	}

	option = { 
		name = hold_court.0001.a
		custom_tooltip = hold_court_start_activity
		# Set up the general flow.
		hold_court_queue_next_event_effect = yes
	}

	option = {
		name = hold_court.0001.b
		remove_variable = num_petitioners
		remove_variable = petitioner_current_progress
		remove_character_flag = holding_court_character_flag
		ai_chance = {
			base = 0
		}
	}
}

##################################################
# Activity End
# by Sean Hughes & Ewan Cowhig Croft
# 0021 - 0030
##################################################

# Played at the end of the activity to clean it up.
hold_court.0021 = {
	type = court_event
	title =	hold_court.0021.t
	desc = hold_court.0021.desc
	theme = realm
	override_sound = { reference = event:/SFX/Events/Themes/sfx_event_theme_type_generic }
	court_scene = {
		button_position_character = root
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		# roles = {
		# 	root = {
		# 		role = ruler
		# 		animation = throne_room_ruler
		# 	}
		# }
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}


	immediate = {
		# Clean up the ol' variable.
		remove_variable = petitioner_current_progress
		remove_character_flag = holding_court_character_flag
		# Update the widget one last time.
		save_scope_value_as = {
			name = event_chain_progress
			value = petitioner_total_chain_length_value
		}
		root = { apply_hold_court_grace_effect = yes }
	}

	option = { 
		name = hold_court.0021.a
		# Guaranteed small grandeur reward, in addition to any from events
		change_current_court_grandeur = minor_court_grandeur_gain
		# LEGITIMACY GAIN FROM HOLDING COURT
		if = {
			limit = {
				has_legitimacy = yes
			}
			add_legitimacy = minor_legitimacy_gain
		}
	}
}










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

##################################################
# 1001 - 1010	Indirect Espionage
# 1011 - 1020	A Call to War
# 1021 - 1030	Dust to Dust
# 1031 - 1040	A Traitor Uncovered
# 1041 - 1050	God's Own Lands
##################################################

##################################################
# Indirect Espionage
# by Sean Hughes
# 1001 - 1010
##################################################

# Guest arrives in your court, offers to spill rumors in exchange for money.
hold_court.1001 = {
	type = court_event
	title = hold_court.1001.t
	desc = hold_court.1001.desc
	theme = realm
	override_sound = { reference = event:/SFX/Events/Themes/sfx_event_theme_type_generic }
	lower_right_portrait = scope:neighboring_ruler
	court_scene = {
		button_position_character = scope:rumormonger
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:rumormonger = {
				group = petitioners_group
				animation = personality_greedy
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}
	
	trigger = {
		NOT = { has_character_flag = had_event_hold_court_1001 }
		any_pool_guest = {
			save_temporary_scope_as = rumor_person
			is_available_adult = yes
			any_known_secret = {
				NOR = {
					is_known_by = root
					secret_target ?= scope:rumor_person
				}
				secret_target ?= {
					top_liege ?= { is_landed = yes }
					top_liege != root.top_liege
				}
			}
			has_court_event_flag = no
		}
	}

	weight_multiplier = {
		base = 1

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

	immediate = {
		add_character_flag = {
			flag = had_event_hold_court_1001
			years = 10
		}
		random_pool_guest = {
			limit = {
				save_temporary_scope_as = rumor_person
				is_available_adult = yes
				any_known_secret = {
					NOR = {
						is_known_by = root
						secret_target ?= scope:rumor_person
					}
					secret_target ?= {
						top_liege ?= { is_landed = yes }
						top_liege != root.top_liege
					}
				}
				has_court_event_flag = no
			}
			save_scope_as = rumormonger
			court_event_character_flag_effect = yes
			random_known_secret = {
				limit = {
					NOR = {
						is_known_by = root
						secret_target ?= scope:rumor_person
					}
					secret_target ?= {
						top_liege ?= { is_landed = yes }
						top_liege != root.top_liege
					}
				}
				secret_target.top_liege = {
					save_scope_as = neighboring_ruler
					court_event_character_flag_effect = yes
					primary_title = {
						save_scope_as = neighboring_realm
					}
				}
			}
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = { 
		name = hold_court.1001.a
		trigger = {
			trigger_if = {
				limit = {
					is_ai = yes
				}
				short_term_gold >= major_gold_value
			}
		}
		pay_short_term_gold = {
			target = scope:rumormonger
			gold = tiny_gold_value
		}
		custom_tooltip = hold_court.1001.a.success.tt
		hidden_effect = {
			scope:rumormonger = {
				every_known_secret = {
					limit = {
						NOR = {
							is_known_by = root
							secret_target ?= scope:rumor_person
						}
						secret_target = {
							top_liege ?= { is_landed = yes }
							top_liege != root.top_liege
						}
					}
					reveal_to = root
				}
			}
		}
	}

	option = { 
		name = hold_court.1001.a.seducer
		trigger = {
			has_trait = seducer
			might_cheat_on_every_partner_trigger = yes
			scope:rumormonger = {
				is_attracted_to_gender_of = root
				might_cheat_on_every_partner_trigger = yes
			}
		}
		trait = seducer


		had_sex_with_effect = {
  			CHARACTER = scope:rumormonger
 			PREGNANCY_CHANCE = pregnancy_chance
		}
		custom_tooltip = hold_court.1001.a.success.tt
		hidden_effect = {
			scope:rumormonger = {
				every_known_secret = {
					limit = {
						NOR = {
							is_known_by = root
							secret_target ?= scope:rumor_person
						}
						secret_target = {
							top_liege ?= { is_landed = yes }
							top_liege != root.top_liege
						}
					}
					reveal_to = root
				}
			}
		}
	}

	option = {
		name = hold_court.1001.b
		add_dread = minor_dread_gain
		imprison_character_effect = {
			TARGET = scope:rumormonger
			IMPRISONER = root
		}
	}
	
	option = {
		name = hold_court.1001.c
		change_current_court_grandeur = medium_court_grandeur_gain
		custom_tooltip = hold_court_1001_pool_tt
		hidden_effect = {
			scope:rumormonger = {
				move_to_pool = yes
			}
		}
		
	}

	after = {
		scope:rumormonger = {
			clear_court_event_participation = yes
		}
		scope:neighboring_ruler = {
			clear_court_event_participation = yes
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

##################################################
# A Call to War
# by Sean Hughes
# 1011 - 1020
##################################################

scripted_trigger hold_court_1011_valid_neighbour_trigger = {
	tier < root.primary_title.tier
	any_claimant = { hold_court_1011_valid_neighbour_claimant_trigger = yes }
}

scripted_trigger hold_court_1011_valid_neighbour_claimant_trigger = {
	is_ruler = no
	is_adult = yes
	basic_is_available_ai = yes
	has_court_event_flag = no
	NOT = { is_courtier_of = root }
}

# Claimant asks for your help in pushing their claim RIGHT NOW!!!
hold_court.1011 = {
	type = court_event
	title = hold_court.1011.t
	desc = hold_court.1011.desc
	theme = realm
	override_sound = { reference = event:/SFX/Events/Themes/sfx_event_theme_type_generic }
	lower_right_portrait = scope:target_character
	court_scene = {
		button_position_character = scope:claimant_guest
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:claimant_guest = {
				group = petitioners_group
				animation = personality_bold
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}
	cooldown = { years = 10 }
	
	trigger = {
		any_neighboring_and_across_water_top_liege_realm = { hold_court_1011_valid_neighbour_trigger = yes }
	}

	weight_multiplier = {
		base = 1

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

	immediate = {
		random_neighboring_and_across_water_top_liege_realm = {
			limit = { hold_court_1011_valid_neighbour_trigger = yes }
			random_claimant = {
				limit = { hold_court_1011_valid_neighbour_claimant_trigger = yes }
				save_scope_as = claimant_guest
				court_event_character_flag_effect = yes
			}
			save_scope_as = target_title
			holder = {
				save_scope_as = target_character
			}
		}
		hidden_effect = {
			add_visiting_courtier = scope:claimant_guest
			scope:claimant_guest = { save_scope_as = courtier }
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}


	option = { 
		name = hold_court.1011.a
		add_courtier = scope:claimant_guest
		add_hook = {
			type = loyalty_hook
			target = scope:claimant_guest
		}
		reverse_add_opinion = {
			target = scope:target_character
			modifier = insult_opinion
			opinion = -25
		}
		show_as_tooltip = {
			random_list = {
				desc = courtier_guest_management.0102.a.rl.desc
				1 = {
					show_chance = no
					desc = courtier_guest_management.0102.a.stay
					custom_tooltip = courtier_guest_management.0102.a.stay.tt
				}
				1 = {
					show_chance = no
					desc = courtier_guest_management.0102.a.leave
					scope:claimant_guest = { select_and_move_to_pool_effect = yes }
				}
			}
		}

		hidden_effect = {
			scope:claimant_guest = {
				add_character_flag = {
					flag = courtier_staying_for_claim
					years = 1
				}
				trigger_event = {
					id = courtier_guest_management.0103
					years = 1
				}
			}
		}
	}

	option = {
		name = hold_court.1011.b
		remove_courtier_or_guest = scope:claimant_guest
		scope:claimant_guest = {
			add_opinion = {
				modifier = refusal_opinion
				target = root
				opinion = -20
			}
		}
		scope:target_character = {
			add_opinion = {
				modifier = pleased_opinion
				target = root
				opinion = 20
			}
		}
	}

	option = {
		name = hold_court.1011.c
		show_as_tooltip = {
			add_visiting_courtier = scope:claimant_guest
		}
		scope:claimant_guest = {
			add_opinion = {
				modifier = kindness_opinion
				target = root
				opinion = 10
			}
		}
	}

	after = {
		scope:claimant_guest = {
			clear_court_event_participation = yes
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

##################################################
# Dust to Dust
# by Sean Hughes
# 1021 - 1030
##################################################

# Dust to Dust: A peasant asks for financial relief
hold_court.1021 = {
	type = court_event
	title = hold_court.1021.t
	desc = hold_court.1021.desc
	theme = realm
	override_sound = { reference = event:/SFX/Events/Themes/sfx_event_theme_type_generic }
	court_scene = {
		button_position_character = scope:peasant
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:peasant = {
				group = petitioners_group
				animation = beg
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}
	# Portrait left in in order to apply outfit tags.	
	left_portrait = {
		character = scope:peasant
		outfit_tags = { beggar_rags }
		hide_info = yes
	}

	trigger = {
		NOT = { has_character_flag = had_event_hold_court_2001 }
	}

	weight_multiplier = {
		base = 1

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

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

		random_sub_realm_barony = {
			limit = { county = { holder = root } }
			save_scope_as = village
			county = { save_scope_as = county }
		}
		hidden_effect = {
			create_character = {
				template = servant_character
				dynasty = none
				location = root.capital_province
				gender_female_chance = root_soldier_female_chance
				save_scope_as = peasant
			}
			scope:peasant = {
				add_trait = peasant_leader
				change_current_weight = -60
			}
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = {
		trigger = { stewardship >= high_skill_rating }
		name = hold_court.1021.a.stewardship
		skill = stewardship
		every_sub_realm_county = {
			custom = county_or_15_dev
			limit = { 
				OR = {
					this = scope:county
					development_level <= 15
				}
			}
			add_county_modifier = {
				modifier = hold_court_cropsharing
				years = 20
			}
		}
	}

	option = { 
		name = hold_court.1021.a
		trigger = {
			trigger_if = {
				limit = {
					is_ai = yes
				}
				short_term_treasury_or_gold >= medium_treasury_or_gold_value
			}
		}

		remove_treasury_or_gold = medium_treasury_or_gold_value
		every_sub_realm_county = {
			custom = county_or_15_dev
			limit = { 
				OR = {
					this = scope:county
					development_level <= 15
				}
			}
			add_county_modifier = {
				modifier = hold_court_grateful_peasants_modifier
				years = 10
			}
		}
		change_current_court_grandeur = medium_court_grandeur_gain
	}
	
	option = {
		name = hold_court.1021.b
		trigger = {
			trigger_if = {
				limit = {
					is_ai = yes
				}
				short_term_treasury_or_gold >= medium_gold_value
			}
		}

		remove_treasury_or_gold = minor_treasury_or_gold_value
		every_sub_realm_county = {
			custom = county_or_15_dev
			limit = { 
				OR = {
					this = scope:county
					development_level <= 15
				}
			}
			add_county_modifier = {
				modifier = hold_court_free_labor
				years = 10
			}
		}
	}	

	option = {
		name = hold_court.1021.c

		every_sub_realm_county = {
			custom = county_or_15_dev
			limit = { 
				OR = {
					this = scope:county
					development_level <= 15
				}
			}
			add_county_modifier = {
				modifier = hold_court_ploughs_to_swords
				years = 10
			}
		}
	}	

	after = {
		scope:peasant = { silent_disappearance_effect = yes }
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}










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

# [slightly anachronistic tumbleweed imagery]










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

##################################################
# 3000 - 3001	A Feast in your Name
# 3010			An Unconventional Preacher
# 3020			Culture Clash: Offensive Monument
# 3030			War Restorations
# 3040			Laughs Requested
# 3050			A Noble Responsibility
# 3060			Addressing the Corruption
# 3070			The Child with Two Mothers
# 3080			Exhibiting your collection
# 3090 - 3091	Celebrating another culture
##################################################

#####################################
# A Feast in your Name				#
# by Bianca Savazzi					#
# 3000 - 3001						#
#####################################

scripted_trigger hold_court_3000_vassal_trigger = {
	basic_is_available_ai = yes
	is_adult = yes
	short_term_gold >= standard_activity_cost 
	has_court_event_flag = no
	NOT = {
		has_hook_of_type = {
			target = root
			type = favor_hook
		}
	}
	trigger_if = {
		limit = { exists = root.var:was_promised_a_feast } 
		root.var:was_promised_a_feast = { this != prev }
	}
}

# You're approached by a vassal that offers to pay for your next feast
hold_court.3000 = {
	type = court_event
	title = hold_court.3000.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { has_trait = blind } 
				desc = hold_court.3000.desc.opening.blind
			}
			triggered_desc = { 
				desc = hold_court.3000.desc.opening
			}
		}
		first_valid = {
			triggered_desc = {
				trigger = { 
					scope:feast_vassal = {
						opinion = {
							target = root
							value >= 10
						}
					}
				} 
				desc = hold_court.3000.desc.dislikes
			}
			triggered_desc = {
				desc = hold_court.3000.desc.likes
			}
		}
	}
	theme = court
	cooldown = { years = 5 }
	court_scene = {
		button_position_character = scope:feast_vassal
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:feast_vassal = {
				group = petitioners_group
				animation = happiness
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}
		
	weight_multiplier = {
		base = 1
		modifier = { 
			add = 1
			has_character_flag = had_event_vassal_2101 # Event where vassal requests a feast
		}

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

	trigger = {
		NOT = { government_has_flag = government_is_mandala }
		is_landed_or_landless_administrative = yes
		is_in_civil_war = no
		is_adult = yes
		any_vassal = {
			hold_court_3000_vassal_trigger = yes 
		}
	}

	immediate = {
		random_vassal = {
			limit = {
				hold_court_3000_vassal_trigger = yes 
			}
			save_scope_as = feast_vassal
			court_event_character_flag_effect = yes
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	# Option A: Accept, grant a favour
	option = { 
		name = hold_court.3000.a
		scope:feast_vassal = {
			add_opinion = {
				modifier = ep1_accepted_sponsoring_a_feast_opinion
				target = root
			}
			add_hook = {
				target = root
				type = favor_hook
			}
			pay_short_term_gold = {
				target = root
				gold = standard_activity_cost
			}
		}
		custom_tooltip = hold_court.3000.a.tt

		hidden_effect = {
			set_variable = {
				name = hold_court_sponsored_a_feast
				value = scope:feast_vassal
				years = 5
			}
		}
		ai_chance = {
			base = 15
			ai_value_modifier = {
				ai_honor = tiny_chance_impact_positive_ai_value # Honorable characters tend to agree to fair deals
				ai_greed = medium_chance_impact_negative_ai_value # Greedy characters don't necessarily want a "fair" deal
			}
		}
	}
	
	# Option B: Accept greedily
	option = {
		name = hold_court.3000.b
		trigger = {
			OR = {
				has_trait = greedy
				has_trait = arbitrary 
				has_trait = arrogant
			}
		}
		stress_impact = { 
			greedy = medium_stress_loss 
		}
		scope:feast_vassal = {
			if = {
				limit = {
					OR = {
						has_trait = generous
						has_trait = humble
					}
				}
				add_opinion = {
					modifier = ep1_took_advantage_of_kindness_opinion
					target = root
					opinion = -10
				}
			}
			else = {
				add_opinion = {
					modifier = ep1_took_advantage_of_kindness_opinion
					target = root
				}
			}
			pay_short_term_gold = {
				target = root
				gold = standard_activity_cost
			}
		}
		custom_tooltip = hold_court.3000.a.tt
		hidden_effect = {
			set_variable = {
				name = hold_court_sponsored_a_feast
				value = scope:feast_vassal
				years = 5
			}
		}
		ai_chance = {
			base = 15
			ai_value_modifier = {
				ai_honor = medium_chance_impact_negative_ai_value # Honorable characters tend to agree to fair deals
				ai_greed = medium_chance_impact_positive_ai_value # Greedy characters don't necessarily want a "fair" deal
			}
		}
	}

	# Option C: Persuade them to change the deal
	option = {
		name = hold_court.3000.c
		trigger = {
			OR = {
				has_lifestyle = diplomacy_lifestyle
				diplomacy >= high_skill_rating
				has_education_diplomacy_trigger = yes
			}
		}
		duel = {
			skill = diplomacy
			value = 10
			30 = {
				desc = hold_court.3000.c.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 0.5
				}
				hidden_effect = {
					set_variable = {
						name = hold_court_sponsored_a_feast
						value = scope:feast_vassal
						years = 5
					}
				}
				send_interface_toast = {
					title = hold_court.3000.t
					left_icon = scope:feast_vassal
					custom_tooltip = hold_court.3000.c.success
				}
			}
			10 = {
				desc = hold_court.3000.c.failure
				scope:feast_vassal = {
					add_opinion = {
						modifier = ep1_rejected_sponsoring_a_feast_opinion
						target = root
					}
				}
				send_interface_toast = {
					title = hold_court.3000.t
					left_icon = scope:feast_vassal
					custom_tooltip = hold_court.3000.c.failure
				}
			}
		}
		ai_chance = {
			base = 15
			modifier = {
				OR = {
					has_lifestyle = diplomacy_lifestyle
					diplomacy >= high_skill_rating
					has_education_diplomacy_trigger = yes
				}
				add = 40
			}
			ai_value_modifier = {
				ai_honor = medium_chance_impact_positive_ai_value # Honorable characters tend to agree to fair deals
				ai_greed = medium_chance_impact_positive_ai_value # Greedy characters don't necessarily want a "fair" deal
			}
		}
	}

	# Option D: Reject
	option = {
		name = hold_court.3000.d
		scope:feast_vassal = {
			add_opinion = {
				modifier = ep1_rejected_sponsoring_a_feast_opinion
				target = root
			}
		}

		ai_chance = {
			base = 15
			modifier = {
				OR = {
					has_trait = reclusive
					has_trait = shy
				}
				add = 40
			}
			modifier = {
				gold < -100 #AI should want to take the loan if out of money 
				add = -100
			}
		}
	}

	after = {
		add_character_flag = {
			flag = hold_court_3000_a_feast_in_your_name
			years = 5
		}
		scope:feast_vassal = {
			clear_court_event_participation = yes
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

# Follow-up event Gain some GSV
hold_court.3001 = {
	type = character_event
	title = hold_court.3000.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { 
					scope:feast_vassal = { is_alive = yes } 
				} 
				desc = hold_court.3001.desc
			}
			triggered_desc = { 
				desc = hold_court.3001.desc.dead
			}
		}
	}
	theme = court
	left_portrait = {
		character = root
		animation = happiness
	}
	right_portrait = {
		character = scope:feast_vassal
		animation = happiness
	}
		
	trigger = {
		has_character_flag = hold_court_3000_a_feast_in_your_name
		has_variable = hold_court_sponsored_a_feast
	}

	immediate = {
		var:hold_court_sponsored_a_feast = {
			save_scope_as = feast_vassal
		}
		remove_variable = hold_court_sponsored_a_feast
	}

	# Option A: Celebrate your success! 
	option = { 
		name = hold_court.3001.a
		trigger = {
			scope:feast_vassal = { is_alive = yes } 
		}
		ai_chance = {
			base = 1 
		}
	}

	# Option B: Celebrate your success, even if the vassal is dead! 
	option = { 
		name = hold_court.3001.b
		trigger = {
			scope:feast_vassal = { is_alive = no } 
		}
		ai_chance = {
			base = 1 
		}
	}

	after = {
		change_current_court_grandeur = medium_court_grandeur_gain
	}
}

#####################################
# An Unconventional Preacher		#
# by Bianca Savazzi					#
# 3010								#
#####################################

scripted_trigger court_3010_an_unconventional_preacher_vassal_trigger = {
	faith = root.faith
	is_available_healthy_ai_adult = yes
	has_court_event_flag = no
	save_temporary_scope_as = unconventional_preacher_temp
}

# Vassal requests investigation of an unorthodox preacher. Another pleas for more tolerance or even a change in doctrines.
hold_court.3010 = {
	type = court_event
	title = hold_court.3010.t
	desc = {
		desc = hold_court.3010.desc.opening
		first_valid = {
			triggered_desc = {
				trigger = { 
					faith = { 
						OR = { 
							has_doctrine = doctrine_clerical_gender_male_only
							has_doctrine = doctrine_clerical_gender_female_only
						}
					}
				} 
				desc = hold_court.3010.desc.preacher_gender
			}
		}
		desc = hold_court.3010.desc.closing
	}
	theme = court
	lower_center_portrait = scope:unconventional_preacher
	cooldown = { years = 5 }
	court_scene = {
		button_position_character = scope:religious_vassal
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:religious_vassal = {
				group = petitioners_group
				animation = personality_zealous
			}
			scope:tolerant_vassal = {
				group = petitioners_group
				animation = personality_forgiving
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}
	
	trigger = {
		any_vassal = {
			court_3010_an_unconventional_preacher_vassal_trigger = yes
			count >= 2
		}
		faith = {
			# Faith requires some restriction on who can practise it for the event to make sense	
			NOT = {
				has_doctrine = doctrine_clerical_gender_either
			}
		}
		OR = {
			can_appoint_char_to_court_position = {
				CHAR = scope:unconventional_preacher_temp
				COURT_POS = high_almoner_court_position
			}
			can_appoint_char_to_court_position = {
				CHAR = scope:unconventional_preacher_temp
				COURT_POS = court_artificer_court_position
			}
			can_appoint_char_to_court_position = {
				CHAR = scope:unconventional_preacher_temp
				COURT_POS = court_physician_court_position
			}
			can_appoint_char_to_court_position = {
				CHAR = scope:unconventional_preacher_temp
				COURT_POS = chief_qadi_court_position
			} 
			can_appoint_char_to_court_position = {
				CHAR = scope:unconventional_preacher_temp
				COURT_POS = court_tutor_court_position
			}
		}
	}

	weight_multiplier = {
		base = 1

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

	immediate = {
		if = {
			limit = {
				faith = { has_doctrine_parameter = clergy_must_be_male }
			}
			create_character = {
				template = virtuous_priest_character_template
				location = root.capital_province
				gender = female
				dynasty = none
				save_scope_as = unconventional_preacher	
			}
		}
		else_if = {
			limit = {
				faith = { has_doctrine_parameter = clergy_must_be_female }
			}
			create_character = {
				template = virtuous_priest_character_template
				location = root.capital_province
				gender = male
				dynasty = none
				save_scope_as = unconventional_preacher	
			}
		}
		else = {
			create_character = {
				template = virtuous_priest_character_template
				location = root.capital_province
				gender_female_chance = 50
				dynasty = none
				save_scope_as = unconventional_preacher	
			}
		}
		hidden_effect = {
			# We add them to court so that they can become high almoner, but hide that from the tooltip
			add_courtier = scope:unconventional_preacher
		}

		random_vassal = {
			limit = { court_3010_an_unconventional_preacher_vassal_trigger = yes }
			weight = {
				base = 1
				modifier = {
					add = 10
					has_trait = zealous
				}
				modifier = {
					add = 5
					OR = {
						has_trait = stubborn
						has_trait = diligent
						has_trait = impatient
					}
				}
				modifier = {
					add = -3
					OR = {
						has_trait = forgiving
						has_trait = compassionate
					}
				}
				modifier = {
					add = -5
					OR = {
						has_trait = cynical
						any_secret = {
							type = secret_non_believer
						}
					}
				}
				modifier = {
					add = 2
					has_council_position = councillor_court_chaplain #Slight pivot towards picking 
				}
			}
			save_scope_as = religious_vassal
			court_event_character_flag_effect = yes
		}

		random_vassal = {
			limit = { 
				this != scope:religious_vassal
				court_3010_an_unconventional_preacher_vassal_trigger = yes 
			}
			weight = {
				base = 1
				modifier = {
					add = -10
					has_trait = zealous
				}
				modifier = {
					add = 5
					OR = {
						has_trait = forgiving
						has_trait = compassionate
					}
				}
				modifier = {
					add = 5
					OR = {
						has_trait = cynical
						any_secret = {
							type = secret_non_believer
						}
					}
				}
				modifier = {
					add = 2
					has_council_position = councillor_court_chaplain
				}
			}
			save_scope_as = tolerant_vassal
			court_event_character_flag_effect = yes
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	# Option A: Leave the preacher alone
	option = {
		trigger = {
			OR = {
				can_appoint_char_to_court_position = {
					CHAR = scope:unconventional_preacher
					COURT_POS = court_artificer_court_position
				}
				can_appoint_char_to_court_position = {
					CHAR = scope:unconventional_preacher
					COURT_POS = court_physician_court_position
				}
				can_appoint_char_to_court_position = {
					CHAR = scope:unconventional_preacher
					COURT_POS = chief_qadi_court_position
				}
			}
		}
		name = hold_court.3010.a
		reverse_add_opinion = {
			target = scope:religious_vassal
			modifier = impious_opinion
			opinion = -10
		}
		if = {
			limit = {
				can_appoint_char_to_court_position = {
					CHAR = scope:unconventional_preacher
					COURT_POS = chief_qadi_court_position
				}
			}
			employ_character_as_position_in_current_scope_court_effect = {
				CHARACTER = scope:unconventional_preacher
				POSITION = chief_qadi
			}
		}
		else_if = {
			limit = {
				can_appoint_char_to_court_position = {
					CHAR = scope:unconventional_preacher
					COURT_POS = court_artificer_court_position
				}
			}
			employ_character_as_position_in_current_scope_court_effect = {
				CHARACTER = scope:unconventional_preacher
				POSITION = court_artificer
			}
		}
		else_if = {
			limit = {
				can_appoint_char_to_court_position = {
					CHAR = scope:unconventional_preacher
					COURT_POS = court_physician_court_position
				}
			}
			employ_character_as_position_in_current_scope_court_effect = {
				CHARACTER = scope:unconventional_preacher
				POSITION = court_physician
			}
		}
		ai_chance = {
			base = 15
			modifier = {
				gold < tiny_gold_value # AI won't hire positions if they don't have money
				add = -15
			}
			ai_value_modifier = {
				ai_zeal = medium_chance_impact_negative_ai_value # Zealous characters don't like unconventional preachers
			}
		}
	}
	
	# Option C: Appoint them as your almoner
	option = {
		trigger = {
			can_appoint_char_to_court_position = {
				CHAR = scope:unconventional_preacher
				COURT_POS = high_almoner_court_position
			}
		}
		name = hold_court.3010.c
		reverse_add_opinion = {
			target = scope:religious_vassal
			modifier = impious_opinion
			opinion = -10
		}
		employ_character_as_position_in_current_scope_court_effect = {
			CHARACTER = scope:unconventional_preacher
			POSITION = high_almoner
		}
		ai_chance = {
			base = 15
			modifier = {
				gold < tiny_gold_value # AI won't hire positions if they don't have money
				add = -15
			}
			ai_value_modifier = {
				ai_zeal = medium_chance_impact_negative_ai_value # Zealous characters don't like unconventional preachers
			}
		}
	}

	# Option D: Invite the preacher to serve as court tutor
	option = {
		trigger = {
			can_appoint_char_to_court_position = {
				CHAR = scope:unconventional_preacher
				COURT_POS = court_tutor_court_position
			}
		}
		name = hold_court.3010.d
		reverse_add_opinion = {
			target = scope:religious_vassal
			modifier = impious_opinion
			opinion = -10
		}
		employ_character_as_position_in_current_scope_court_effect = {
			CHARACTER = scope:unconventional_preacher
			POSITION = court_tutor
		}
		ai_chance = {
			base = 15
			modifier = {
				gold < tiny_gold_value # AI won't hire positions if they don't have money
				add = -15
			}
			ai_value_modifier = {
				ai_zeal = medium_chance_impact_negative_ai_value # Zealous characters don't like unconventional preachers
			}
		}
	}

	# Option B: Punish the preacher
	option = {
		name = hold_court.3010.b
		scope:unconventional_preacher = {
			silent_disappearance_effect = yes
		}

		ai_chance = {
			base = 15
			ai_value_modifier = {
				ai_zeal = medium_chance_impact_positive_ai_value # Zealous characters don't like unconventional preachers
				ai_compassion = medium_chance_impact_negative_ai_value # Compassionate characters rather not punish those who do good
			}
		}
	}

	after = {
		scope:tolerant_vassal = {
			clear_court_event_participation = yes
		}
		scope:religious_vassal = {
			clear_court_event_participation = yes
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

#####################################
# Culture Clash: Offensive Monument	#
# by Bianca Savazzi					#
# 3020								#
#####################################

scripted_trigger hold_court_3020_peasant_trigger = { 
	basic_is_available_ai = yes
	is_adult = yes
	is_lowborn = yes
	has_court_event_flag = no
	#culture is left out for reusability
}

scripted_trigger hold_court_3020_valid_barony = {
	tier = tier_barony
	holder ?= {
		this != root
		culture = root.culture
		has_court_event_flag = no
	}
}

# Peasants of another culture want to restore a controversial monument that mocks yours
hold_court.3020 = {
	type = court_event
	title = hold_court.3020.t
	desc = hold_court.3020.desc
	theme = court
	cooldown = { years = 5 }
	court_scene = {
		button_position_character = scope:holder_of_area
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:holder_of_area = {
				group = petitioners_group
				animation = shock
			}
			scope:different_culture_peasant = {
				group = petitioners_group
				animation = anger
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

	trigger = {
		any_held_title = {
			title_tier = county
			any_in_de_jure_hierarchy = {
				hold_court_3020_valid_barony = yes
			}
			culture != root.culture
		}
	}

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

	immediate = {
		random_held_title = {
			title_tier = county
			limit = {
				any_in_de_jure_hierarchy = {
					hold_court_3020_valid_barony = yes
				}
				culture != root.culture
			}
			random_in_de_jure_hierarchy = {
				limit = {
					hold_court_3020_valid_barony = yes
				}
				save_scope_as = village
				holder = {
					save_scope_as = holder_of_area
					court_event_character_flag_effect = yes
					}
				county = { save_scope_as = village_county }
			}
		}
		# Try to fetch an existing character
		if = {
			limit = {
				any_pool_guest = {
					hold_court_3020_peasant_trigger = yes
					culture = scope:village.culture
				}
			}

			random_pool_guest = {
				limit = {
					hold_court_3020_peasant_trigger = yes
					culture = scope:village.culture
				}
				add_trait = peasant_leader
				save_scope_as = different_culture_peasant
				court_event_character_flag_effect = yes
			}
		}
		else = { # else, make one for the event
			create_character = {
				template = servant_character
				location = scope:village.title_province
				culture = scope:village.title_province.culture
				dynasty = none
				trait = peasant_leader 
				save_scope_as = different_culture_peasant	
			}
			add_character_flag = created_character_hold_court_3020
			court_event_character_flag_effect = yes
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	# Option C: Build something marrying the two cultures
	option = {
		name = hold_court.3020.c
		trigger = {
			has_trait = eccentric
		}
		remove_treasury_or_gold = medium_treasury_or_gold_value
		every_held_title = {
			title_tier = county
			limit = {
				culture = scope:village.culture 
			}
			custom = every_county_of_culture
			add_county_modifier = {
				modifier = 3020_multicultural_monument
				years = 15
			}
		}
		scope:village.culture = {
			change_cultural_acceptance = {
				target = root.culture
				value = medium_positive_culture_acceptance
				desc = cultural_acceptance_gain_hold_court_event_outcome
			}
		}
		ai_chance = {
			base = 15
			ai_value_modifier = {
				ai_greed = medium_chance_impact_negative_ai_value # SPeNd rEsouRcEs!?
				ai_compassion = high_chance_impact_positive_ai_value # Compassionate characters don't like punishing others
			}
			modifier = {
				factor = 0
				short_term_treasury_or_gold < medium_treasury_or_gold_value
			}
		}
	}

	# Option A: Destroy the statue and build one for YOUR culture!
	option = { 
		name = hold_court.3020.a
		add_dread = minor_dread_gain
		every_held_title = {
			title_tier = county
			limit = { 
				culture = scope:village.culture 
			}
			custom = every_county_of_culture
			add_county_modifier = {
				modifier = 3020_own_culture_monument
				years = 15
			}
		}
		ai_chance = {
			base = 15
			ai_value_modifier = {
				ai_vengefulness = medium_chance_impact_positive_ai_value # Vengeful characters don't like being mocked
				ai_compassion = medium_chance_impact_negative_ai_value # Compassionate characters don't like punishing others
			}
		}
	}
	
	# Option B: Accept
	option = {
		name = hold_court.3020.b
		remove_treasury_or_gold = minor_treasury_or_gold_value
		every_held_title = {
			title_tier = county
			limit = { 
				culture = scope:village.culture 
			}
			custom = every_county_of_culture
			add_county_modifier = {
				modifier = hold_court_grateful_peasants_modifier
				years = 15
			}
		}
		scope:village.culture = {
			change_cultural_acceptance = {
				target = root.culture
				value = low_positive_culture_acceptance
				desc = cultural_acceptance_gain_hold_court_event_outcome 
			}
		}
		ai_chance = {
			base = 15
			ai_value_modifier = {
				ai_greed = medium_chance_impact_negative_ai_value # SPend resources!?
				ai_compassion = medium_chance_impact_positive_ai_value # Compassionate characters don't like punishing others
			}
			modifier = {
				factor = 0
				short_term_treasury_or_gold < minor_treasury_or_gold_value
			}
		}
	}

	after = {
		if = {
			limit = { has_character_flag = created_character_hold_court_3020 }
			hidden_effect = {
				scope:different_culture_peasant = {
					clear_court_event_participation = yes
					death = {
						death_reason = death_vanished
					}
				}
				remove_character_flag = created_character_hold_court_3020
			}
		}
		scope:holder_of_area = {
			clear_court_event_participation = yes
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

#####################################
# War Restorations 					#
# by Bianca Savazzi					#
# 3030								#
#####################################

# Peasants of another culture want to restore a monument that was looted during war
hold_court.3030 = {
	type = court_event
	title = hold_court.3030.t
	desc = hold_court.3030.desc
	theme = court
	cooldown = { years = 5 }
	court_scene = {
		button_position_character = scope:different_culture_peasant
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:different_culture_peasant = {
				group = petitioners_group
				animation = beg
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

	trigger = {
		is_at_war = no  
		days_of_continuous_peace < 600
		any_directly_owned_province = {
			culture != root.culture
		}
	}

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

	immediate = {
		random_directly_owned_province = {
			limit = {
				culture != root.culture
			}
			weight = {
				base = 1
				modifier = {
					add = 10
					has_free_building_slot = yes
				}
			}
			save_scope_as = province
		}

		# Try to fetch an existing character
		if = {
			limit = {
				any_pool_guest = {
					hold_court_3020_peasant_trigger = yes
					culture = scope:province.culture
				}
			}

			random_pool_guest = {
				limit = {
					hold_court_3020_peasant_trigger = yes
					culture = scope:province.culture
				}
				add_trait = peasant_leader
				save_scope_as = different_culture_peasant
				court_event_character_flag_effect = yes
			}
		}
		else = { # else, make one for the event
			create_character = {
				template = servant_character
				location = scope:province
				culture = scope:province.culture
				dynasty = none
				trait = peasant_leader 
				save_scope_as = different_culture_peasant	
			}
			scope:different_culture_peasant = {
				court_event_character_flag_effect = yes
			}
			add_character_flag = created_character_hold_court_3030
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	# Option A: Pay to restore the building
	option = { 
		name = hold_court.3030.a
		trigger = {
			trigger_if = {
				limit = {
					is_ai = yes
				}
				short_term_treasury_or_gold >= major_treasury_or_gold_value
			}
		}
		remove_treasury_or_gold = medium_treasury_or_gold_value

		stress_impact = { 
			greedy = medium_stress_gain
			generous = medium_stress_loss
			improvident = medium_stress_loss
		}

		scope:province.culture = {
			change_cultural_acceptance = {
				target = root.culture
				value = low_positive_culture_acceptance
				desc = cultural_acceptance_gain_hold_court_event_outcome
			}
		}
	}
	
	# Option B: Raze monument to use the materials elsewhere
	option = {
		name = hold_court.3030.b
		trigger = {
			scope:province = { has_free_building_slot = yes }
		}

		stress_impact = { 
			greedy = medium_stress_loss
		}

		scope:province = {
			add_province_modifier = {
				modifier = hold_court_less_building_cost_modifier
				days = 3650
			}
		}
		
		scope:province.culture = {
			change_cultural_acceptance = {
				target = root.culture
				value = medium_negative_culture_acceptance
				desc = cultural_acceptance_gain_hold_court_event_outcome
			}
		}
	}

	# Option C: Refuse
	option = {
		name = hold_court.3030.c

		stress_impact = { 
			generous = medium_stress_gain
			improvident = medium_stress_gain
		}
		
		scope:province = {
			county = {
				add_county_modifier = {
					modifier = hold_court_displeased_peasants_modifier
					years = 5
				}
			}
		}
	}

	after = {
		if = {
			limit = { has_character_flag = created_character_hold_court_3030 }
			hidden_effect = {
				scope:different_culture_peasant = {
					clear_court_event_participation = yes
					death = {
						death_reason = death_vanished
					}
				}
				remove_character_flag = created_character_hold_court_3030
			}
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

#####################################
# Laughs Requested					#
# by Bianca Savazzi					#
# 3040								#
#####################################

# Vassal/Courtier petitions for the recruitment of a jester
hold_court.3040 = {
	type = court_event
	title = hold_court.3040.t
	desc = hold_court.3040.desc
	theme = court 
	lower_center_portrait = scope:potential_jester
	cooldown = { years = 10 }
	court_scene = {
		button_position_character = scope:jester_requester
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:jester_requester = {
				group = petitioners_group
				animation = happiness
			}
			scope:kill_joy = {
				group = petitioners_group
				animation = dismissal
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}
		
	trigger = {
		NOT = {
			employs_court_position = court_jester_court_position
		}
		can_employ_court_position_type = court_jester_court_position
		any_vassal = {
			is_available_ai_adult = yes
			has_court_event_flag = no
			save_temporary_scope_as = extroverted_vassal_check
		}
		any_vassal = {
			is_available_ai_adult = yes
			has_court_event_flag = no
			this != scope:extroverted_vassal_check
		}
	}

	weight_multiplier = {
		base = 1

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

	immediate = {
		random_vassal = {
			limit = {
				is_available_ai_adult = yes
				has_court_event_flag = no
			}
			weight = {
				base = 1
				modifier = {
					has_personality_extroverted_trigger = yes
					add = 10
				}
				modifier = {
					is_of_major_or_minor_interest_trigger = { CHARACTER = root }
					add = 5
				}
			}
			save_scope_as = jester_requester
			court_event_character_flag_effect = yes
			assign_quirk_effect = yes # So that they have a quirk in loc

			create_character = {
				template = pool_repopulate_diplomacy
				location = scope:jester_requester.location
				dynasty = none #It has to be a lowborn
				save_scope_as = potential_jester	
			}
		}

		hidden_effect = { add_courtier = scope:potential_jester } # So they're considered valid for the position

		random_vassal = {
			limit = {
				is_available_ai_adult = yes
				has_court_event_flag = no
				this != scope:jester_requester
			}
			weight = {
				base = 1
				modifier = {
					has_trait_introverted_trigger = yes
					add = 10
				}
				modifier = {
					is_of_major_or_minor_interest_trigger = { CHARACTER = root }
					add = 5
				}
			}
			save_scope_as = kill_joy
			court_event_character_flag_effect = yes
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	# Option A: Employ peasant 
	option = { 
		name = hold_court.3040.a

		trigger = {
			can_appoint_char_to_court_position = {
				CHAR = scope:potential_jester
				COURT_POS = court_jester_court_position
			}
		}

		hidden_effect = {
			reverse_add_opinion = {
				target = scope:potential_jester
				modifier = loyal_servant
			}
		}
		court_position_grant_effect = {
			EMPLOYER = root
			POS = court_jester
			CANDIDATE = scope:potential_jester
		}
		custom_tooltip = {
			text = generic_cp_discount_tt
			scope:potential_jester = {
				add_character_flag = cp_discount
			}
		}
		reverse_add_opinion = {
			target = scope:jester_requester
			modifier = pleased_opinion
			opinion = 20
		}
		ai_chance = {
			base = 5

			modifier = {
				has_trait_extroverted_trigger = yes
				add = 2
			}
			modifier = {
				short_term_gold >= medium_gold_value
				add = 5
			}

			ai_value_modifier = {
				ai_greed = tiny_chance_impact_negative_ai_value #Recruiting this person means less cost to find a jester
			}
		}
	}

	# Option B: Employ jester requester as jester 
	option = { 
		trigger = {
			can_appoint_char_to_court_position = {
				CHAR = scope:jester_requester
				COURT_POS = court_jester_court_position
			}
		}
		name = hold_court.3040.b

		court_position_grant_effect = {
			EMPLOYER = root
			POS = court_jester
			CANDIDATE = scope:jester_requester
		}
		hidden_effect = {
			scope:potential_jester = {
				death = {
					death_reason = death_vanished #Ripperoni
				}
			}
		}

		ai_chance = {
			base = 5

			modifier = {
				opinion = {
					target = scope:jester_requester
					value <= low_positive_opinion
				}
				add = 5
			}
			modifier = {
				has_trait = arbitrary
				add = 5
			}
			modifier = {
				short_term_gold >= medium_gold_value
				add = 5
			}
		}
	}

	# Option C: Employ killjoy as jester
	option = { 
		name = hold_court.3040.c

		trigger = {
			can_appoint_char_to_court_position = {
				CHAR = scope:kill_joy
				COURT_POS = court_jester_court_position
			}
		}

		court_position_grant_effect = {
			EMPLOYER = root
			POS = court_jester
			CANDIDATE = scope:kill_joy
		}
		scope:kill_joy = {
			progress_towards_rival_effect = {
				CHARACTER = root
				REASON = rival_killjoy_jester
				OPINION = -20
			}
		}
		reverse_add_opinion = {
			target = scope:jester_requester
			modifier = pleased_opinion
			opinion = 35
		}
		hidden_effect = {
			scope:potential_jester = {
				death = {
					death_reason = death_vanished 
				}
			}
		}

		ai_chance = {
			base = 5

			modifier = {
				opinion = {
					target = scope:kill_joy
					value <= low_positive_opinion
				}
				add = 5
			}
			modifier = {
				has_trait = arbitrary
				add = 5
			}
			modifier = {
				short_term_gold >= medium_gold_value
				add = 5
			}
		}
	}

	# Option E: Do nothing
	option = { 
		name = hold_court.3040.e

		hidden_effect = {
			scope:potential_jester = {
				death = {
					death_reason = death_vanished 
				}
			}
		}

		ai_chance = {
			base = 2

			modifier = {
				has_trait_introverted_trigger = yes
				add = 2
			}

			modifier = {
				short_term_gold < medium_gold_value
				add = 5
			}
		}
	}

	after = {
		scope:jester_requester = {
			clear_court_event_participation = yes
		}
		scope:kill_joy = {
			clear_court_event_participation = yes
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

#####################################
# Addressing the Corruption			#
# by Bianca Savazzi					#
# 3060								#
#####################################
 
scripted_trigger hold_court_3060_county_and_holder_trigger = {
	county_control <= low_county_control
	holder = { 
		this != root 
		is_vassal_of = root
		basic_is_available_ai = yes
		is_adult = yes
		has_court_event_flag = no
	}
}

scripted_trigger hold_court_3060_replacement_candidate_trigger = {
	basic_is_available_ai = yes
	has_court_event_flag = no
	is_adult = yes
	stewardship >= mediocre_skill_rating
	NOT = { is_of_major_or_minor_interest_trigger = { CHARACTER = root } }
	can_be_steward_trigger = { COURT_OWNER = scope:county_petitioner }
}

scripted_effect hold_court_3060_remove_corruption = {
	if = {
		limit = {
			scope:corrupt_county = {
				has_county_modifier = county_corruption_inefficient_tax_collection_modifier
			}
		}
		scope:corrupt_county = {
			remove_county_modifier = county_corruption_inefficient_tax_collection_modifier
		}
	}
	if = {
		limit = {
			scope:corrupt_county = {
				has_county_modifier = county_corruption_deserting_levies_modifier
			}
		}
		scope:corrupt_county = {
			remove_county_modifier = county_corruption_deserting_levies_modifier
		}
	}
	if = {
		limit = {
			scope:corrupt_county = {
				has_county_modifier = county_corruption_lackluster_administration_modifier
			}
		}
		scope:corrupt_county = {
			remove_county_modifier = county_corruption_lackluster_administration_modifier
		}
	}
	if = {
		limit = {
			scope:corrupt_county = {
				has_county_modifier = county_corruption_uncooperative_guilds_modifier
			}
		}
		scope:corrupt_county = {
			remove_county_modifier = county_corruption_uncooperative_guilds_modifier
		}
	}
	if = {
		limit = {
			scope:corrupt_county = {
				has_county_modifier = county_corruption_lack_of_sheriffs_modifier
			}
		}
		scope:corrupt_county = {
			remove_county_modifier = county_corruption_lack_of_sheriffs_modifier
		}
	}
	if = {
		limit = {
			scope:corrupt_county = {
				has_county_modifier = county_corruption_lack_of_courts_modifier
			}
		}
		scope:corrupt_county = {
			remove_county_modifier = county_corruption_lack_of_courts_modifier
		}
	}
	if = {
		limit = {
			scope:corrupt_county = {
				has_county_modifier = county_corruption_bandits_rampant_modifier
			}
		}
		scope:corrupt_county = {
			remove_county_modifier = county_corruption_bandits_rampant_modifier
		}
	}
	if = {
		limit = {
			scope:corrupt_county = {
				has_county_modifier = county_corruption_unsafe_highways_modifier
			}
		}
		scope:corrupt_county = {
			remove_county_modifier = county_corruption_unsafe_highways_modifier
		}
	}
	if = {
		limit = {
			scope:corrupt_county = {
				has_county_modifier = county_corruption_smuggling_ring_modifier
			}
		}
		scope:corrupt_county = {
			remove_county_modifier = county_corruption_smuggling_ring_modifier
		}
	}
	if = {
		limit = {
			scope:corrupt_county = {
				has_county_modifier = county_corruption_thieves_guild_modifier
			}
		}
		scope:corrupt_county = {
			remove_county_modifier = county_corruption_thieves_guild_modifier
		}
	}
}

# Banditry is rife in a county and now a vassal is coming to you asking for help.
hold_court.3060 = {
	type = court_event
	title = hold_court.3060.t
	desc = {
		desc = hold_court.3060.desc.opening
		first_valid = {
			random_valid = {
				triggered_desc = {
					trigger = { 
						scope:corrupt_county = {
							OR = {
								has_county_modifier = county_corruption_smuggling_ring_modifier
								has_county_modifier = county_corruption_thieves_guild_modifier
							}
						}
					}
					desc = hold_court.3060.desc.thieves
				}
				triggered_desc = {
					trigger = {
						scope:corrupt_county = {
							OR = {
								county_control <= low_county_control
								has_county_modifier = county_corruption_bandits_rampant_modifier
								has_county_modifier = county_corruption_unsafe_highways_modifier
							}
						}
					}
					desc = hold_court.3060.desc.bandits
				}
				triggered_desc = {
					trigger = {
						scope:corrupt_county = { has_county_modifier = county_corruption_inefficient_tax_collection_modifier }
					}
					desc = hold_court.3060.desc.tax
				}
				triggered_desc = {
					trigger = {
						scope:corrupt_county = { has_county_modifier = county_corruption_lack_of_sheriffs_modifier }
					}
					desc = hold_court.3060.desc.sheriffs
				}
				triggered_desc = {
					trigger = {
						scope:corrupt_county = { has_county_modifier = county_corruption_uncooperative_guilds_modifier }
					}
					desc = hold_court.3060.desc.guilds
				}
				triggered_desc = {
					trigger = {
						scope:corrupt_county = { has_county_modifier = county_corruption_deserting_levies_modifier }
					}
					desc = hold_court.3060.desc.levies
				}
				triggered_desc = {
					trigger = {
						scope:corrupt_county = { has_county_modifier = county_corruption_lack_of_courts_modifier }
					}
					desc = hold_court.3060.desc.courts
				}
				triggered_desc = {
					trigger = {
						scope:corrupt_county = {
							has_county_modifier = county_corruption_inefficient_census_modifier 
							has_county_modifier = county_corruption_lackluster_administration_modifier
						}
					}
					desc = hold_court.3060.desc.rulers
				}
			}
		}
		desc = hold_court.3060.desc.closing
	}
	theme = court
	lower_left_portrait = {
		trigger = {
			exists = scope:cp_steward
			exists = scope:cp_steward_replacement
		}
		character = scope:cp_steward
	}
	lower_right_portrait = {
		trigger = {
			exists = scope:cp_steward_replacement
		}
		character = scope:cp_steward_replacement
	}
	court_scene = {
		button_position_character = scope:county_petitioner
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:county_petitioner = {
				group = petitioners_group
				animation = personality_rational
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}
	
	trigger = {
		any_sub_realm_county = {
			hold_court_3060_county_and_holder_trigger = yes 
		}
		NOT = { has_character_flag = hold_court_3060_corrupt_county }
	}

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

	immediate = {
		#Cooldown flag
		add_character_flag = {	
			flag = hold_court_3060_corrupt_county
			years = 10
		}
		random_sub_realm_county = {
			limit = { hold_court_3060_county_and_holder_trigger = yes }
			holder = {
				save_scope_as = county_petitioner
				assign_quirk_effect = yes
				court_event_character_flag_effect = yes
			}
			save_scope_as = corrupt_county
		}

		# Getting random better courtier for Option D
		if = {
			limit = { 
				scope:county_petitioner = { 
					exists = cp:councillor_steward 
					is_ai = yes
				} 
			}
			scope:county_petitioner.cp:councillor_steward = { save_scope_as = cp_steward }
			random_courtier = {
				limit = {  
					hold_court_3060_replacement_candidate_trigger = yes
					stewardship > scope:cp_steward.stewardship #should be better than the current one to be considered a better replacement
				}
				save_scope_as = cp_steward_replacement
				court_event_character_flag_effect = yes
			}
		}
		else = {
			random_courtier = { 
				limit = {  
					hold_court_3060_replacement_candidate_trigger = yes
				}
				save_scope_as = cp_steward_replacement
				court_event_character_flag_effect = yes
			}
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	# Option A: Gold
	option = {
		name = hold_court.3060.a
		pay_treasury_or_gold = {
			target = scope:county_petitioner
			value = medium_treasury_or_gold_value
		}
		every_sub_realm_county = {
			custom = every_low_county_control
			limit = { county_control <= low_county_control }
			change_county_control = 20 
		}
		hold_court_3060_remove_corruption = yes
		scope:county_petitioner = {
			add_opinion = {
				modifier = grateful_opinion
				target = root
				opinion = 20
			}
			hidden_effect = {
				stress_impact = {
					greedy = medium_stress_loss
				}
			}
		}

		ai_chance = {
			base = 15

			modifier = {
				has_trait = generous
				add = 5
			}
			modifier = {
				has_trait = greedy
				add = -15
			}
			modifier = {
				short_term_treasury_or_gold <= medium_treasury_or_gold_value
				factor = 0
			}
		}
	}

	# Option B: Offer a courtier
	option = { 
		name = hold_court.3060.d
		trigger = {
			exists = scope:cp_steward_replacement
		}

		scope:county_petitioner = {
			add_opinion = {
				modifier = grateful_opinion
				target = root
				opinion = 20
			} 
			fire_councillor = scope:cp_steward 
			assign_councillor_type = {
				type = councillor_steward
				target = scope:cp_steward_replacement
			}
		}
		every_sub_realm_county = {
			custom = every_low_county_control
			limit = { county_control <= low_county_control }
			change_county_control = 20 
		}
		hold_court_3060_remove_corruption = yes

		ai_chance = {
			base = 0
		}
	}
	
	# Option C: Do nothing 
	option = {  
		name = hold_court.3060.c

		ai_chance = {
			base = 100
		}
	}

	after = {
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
		scope:county_petitioner = {
			clear_court_event_participation = yes
		}
	}
}

#####################################
# Exhibiting your collection		#
# by Bianca Savazzi					#
# 3080								#
#####################################

# Antiquarian suggests letting people pay to see your artifacts
hold_court.3080 = {
	type = court_event
	title = hold_court.3080.t
	desc = hold_court.3080.desc
	theme = court 
	cooldown = { years = 5 }

	court_scene = {
		button_position_character = scope:antiquarian
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:antiquarian = {
				group = petitioners_group
				animation = happiness
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}
		
	trigger = {
		employs_court_position = antiquarian_court_position
		any_court_position_holder = {
			type = antiquarian_court_position
			is_physically_able_ai_adult = yes
			has_court_event_flag = no
		}
		any_character_artifact = {
			count >= 2
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = -0.5
			NOR = {
				gold < minor_gold_value
				prestige < minor_prestige_value
			}
		}
		# Court weightings.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_scholarly }
	}

	immediate = {
		random_court_position_holder = {
			type = antiquarian_court_position
			limit = {
				is_physically_able_ai_adult = yes
				has_court_event_flag = no
			}
			save_scope_as = antiquarian
			court_event_character_flag_effect = yes
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	# Option A: Charge money
	option = { 
		name = hold_court.3080.a
		custom_tooltip = hold_court.3080.a.tt
		add_gold = medium_gold_value
		add_character_modifier = {
			modifier = petition_event_artifact_exhibition_for_gold
			years = 10
		}
		stress_impact = {
			greedy = medium_stress_loss
			arrogant = medium_stress_loss
			generous = medium_stress_gain
			humble = medium_stress_gain
		}
		ai_chance = {
			base = 15
			ai_value_modifier = {
				ai_greed = 1
			}
			modifier = {
				gold < minor_gold_value
				add = 5
			}
		}
	}

	# Option B: Gain Prestige 
	option = { 
		name = hold_court.3080.b
		custom_tooltip = hold_court.3080.a.tt
		add_prestige = medium_prestige_gain
		add_character_modifier = {
			modifier = petition_event_artifact_exhibition_for_prestige
			years = 10
		}
		stress_impact = {
			greedy = minor_stress_gain
			arrogant = medium_stress_loss
			generous = medium_stress_gain
			humble = medium_stress_gain
		}

		ai_chance = {
			base = 15

			ai_value_modifier = {
				ai_greed = -0.5
				ai_boldness = 1
			}
			modifier = {
				has_trait = ambitious
				add = 5
			}
			modifier = {
				has_trait = arrogant
				add = 5
			}
		}
	}

	# Option C: Not worth the risk
	option = { 
		name = hold_court.3080.c

		ai_chance = {
			base = 15
			modifier = {
				has_trait = lazy
				add = 5
			}
			modifier = {
				has_trait = paranoid #They're already after me! Why would I invite an increased risk!?
				add = 50
			}
		}
	}

	after = {
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
		scope:antiquarian = {
			clear_court_event_participation = yes
		}
	}
}

#####################################
# Celebrating another culture		#
# by Bianca Savazzi					#
# 3090 - 3091						#
#####################################

#A vassal of a minority culture suggest holding a festival/exhibit/faire of their minority Culture

scripted_trigger hold_court_3090_different_culture_vassal_trigger = {
	culture != root.culture
	culture = {
		cultural_acceptance = { target = root.culture value < hybridization_threshold_value } 
	}
	is_physically_able_ai_adult = yes
	has_court_event_flag = no
}

hold_court.3090 = {
	type = court_event
	title = hold_court.3090.t
	desc = hold_court.3090.desc
	theme = court 
	cooldown = { years = 10 }

	court_scene = {
		button_position_character = scope:different_culture_vassal
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:different_culture_vassal = {
				group = petitioners_group
				animation = happiness
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}
		
	trigger = {
		any_vassal = {
			hold_court_3090_different_culture_vassal_trigger = yes
		}
	}

	immediate = {
		random_vassal = {
			limit = {
				hold_court_3090_different_culture_vassal_trigger = yes
			}
			save_scope_as = different_culture_vassal
			court_event_character_flag_effect = yes
			assign_quirk_effect = yes # So that they have a quirk in loc
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	#More common if you're currently Promoting Acceptance
	weight_multiplier = {
		base = 0.5
		modifier = { 
			add = 10
			exists = cp:councillor_steward
			cp:councillor_steward = {
				is_performing_council_task = task_accept_culture
			}
		}
		modifier = {
			add = 0.5 
			short_term_gold < minor_gold_value
		}

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

	# Option A: Celebrate both cultures!
	option = { 
		name = hold_court.3090.a
		remove_treasury_or_gold = major_treasury_or_gold_value
		culture = {
			change_cultural_acceptance = {
				target = scope:different_culture_vassal.culture
				value = medium_positive_culture_acceptance
				desc = cultural_acceptance_gain_hold_court_event_outcome
			}
		}
		reverse_add_opinion = {
			modifier = impressed_opinion
			target = scope:different_culture_vassal
			opinion = 40
		}
		if = {
			limit = {
				any_vassal = {
					is_ai = no
					has_court_event_flag = no
					scope:different_culture_vassal != this
					culture = scope:different_culture_vassal.culture
				}
			}
			every_vassal = {
				custom = custom.every_vassal_of_target_culture
				limit = {
					culture = scope:different_culture_vassal.culture
					has_court_event_flag = no
					is_ai = no
				}
				add_opinion = {
					target = root
					opinion = 10
					modifier = respect_opinion
				}
			}
		}

		stress_impact = {
			greedy = major_stress_gain #SO. MUCH. SPENT. MONEY.
			arrogant = medium_stress_gain #Presenting oursselves as equals!? BAH!
			compassionate = major_stress_loss #Promoting understanding between the two, yaaaaaay!
		}

		ai_chance = {
			base = 15
			ai_value_modifier = {
				ai_greed = -1
				ai_boldness = 1
				ai_compassion = 0.5
			}
			modifier = {
				has_trait = compassionate
				add = 50
			}
			modifier = {
				short_term_treasury_or_gold < major_treasury_or_gold_value #AI don't do it if they can't afford it 
				factor = 0
			}
		}
	}

	# Option B: Their culture in the capital!
	option = { 
		name = hold_court.3090.b
		remove_treasury_or_gold = medium_treasury_or_gold_value
		culture = {
			change_cultural_acceptance = {
				target = scope:different_culture_vassal.culture
				value = low_positive_culture_acceptance
				desc = cultural_acceptance_gain_hold_court_event_outcome
			}
		}
		reverse_add_opinion = {
			modifier = pleased_opinion
			target = scope:different_culture_vassal
			opinion = 20
		}
		if = {
			limit = {
				any_vassal = {
					scope:different_culture_vassal != this
					culture = scope:different_culture_vassal.culture
				}
			}
			every_vassal = {
				custom = custom.every_vassal_of_target_culture
				limit = {
					culture = scope:different_culture_vassal.culture
				}
				add_opinion = {
					target = root
					opinion = 5
					modifier = respect_opinion
				}
			}
		}
		stress_impact = {
			greedy = medium_stress_loss
			arrogant = medium_stress_loss
			generous = medium_stress_gain
			humble = medium_stress_gain
		}

		ai_chance = {
			base = 15
			ai_value_modifier = {
				ai_greed = -0.5
			}
			modifier = {
				short_term_treasury_or_gold < medium_treasury_or_gold_value #AI don't do it if they can't afford it 
				factor = 0
			}
		}
	}

	# Option C: OUR culture, in their area 
	option = { 
		name = hold_court.3090.c
		remove_treasury_or_gold = minor_treasury_or_gold_value
		culture = {
			change_cultural_acceptance = {
				target = scope:different_culture_vassal.culture
				value = miniscule_positive_culture_acceptance
				desc = cultural_acceptance_gain_hold_court_event_outcome
			}
		}
		reverse_add_opinion = {
			modifier = disappointed_opinion
			target = scope:different_culture_vassal
			opinion = -10
		}
		stress_impact = {
			arrogant = medium_stress_loss
			humble = medium_stress_gain
		}

		ai_chance = {
			base = 15

			ai_value_modifier = {
				ai_greed = 1
				ai_boldness = 1
			}
			modifier = {
				short_term_treasury_or_gold < minor_treasury_or_gold_value #AI don't do it if they can't afford it 
				factor = 0
			}
			modifier = {
				has_trait = arrogant
				add = 5
			}
		}
	}

	# Option D: Nah
	option = { 
		name = hold_court.3090.d
		reverse_add_opinion = {
			modifier = disappointed_opinion
			target = scope:different_culture_vassal
			opinion = -30
		}
		ai_chance = {
			base = 15
			modifier = {
				has_trait = lazy
				add = 5
			}
			modifier = {
				short_term_treasury_or_gold < minor_treasury_or_gold_value #AI won't do anything if they can't afford it 
				factor = 2
			}
		}
	}

	after = {
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
		scope:different_culture_vassal = {
			clear_court_event_participation = yes
		}
	}
}

#Vassal wants to peacock a culture that's close to hybridizing with your culture

scripted_trigger hold_court_3091_different_culture_vassal_trigger = {
	culture != root.culture
	culture = {
		cultural_acceptance = { target = root.culture value >= hybridization_threshold_value } 
	}
	is_physically_able_ai_adult = yes
	has_court_event_flag = no
}

hold_court.3091 = {
	type = court_event
	title = hold_court.3091.t
	desc = hold_court.3091.desc
	theme = court 
	cooldown = { years = 10 }

	court_scene = {
		button_position_character = scope:same_culture_vassal
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:same_culture_vassal = {
				group = petitioners_group
				animation = happiness
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}
		
	trigger = {
		any_vassal = {
			hold_court_3091_different_culture_vassal_trigger = yes
		}
		any_vassal = {
			culture = root.culture 
			is_physically_able_ai_adult = yes
			has_court_event_flag = no
		}
	}

	immediate = {
		random_vassal = {
			limit = {
				hold_court_3091_different_culture_vassal_trigger = yes
			}
			save_scope_as = different_culture_vassal #Used to track the culture that's close to hybridization
		}

		random_vassal = {
			limit = {
				culture = root.culture 
				is_physically_able_ai_adult = yes
				has_court_event_flag = no
			}
			weight = {
				base = 1
				ai_value_modifier = {
					ai_compassion = -1 #More likely to pick a vassal with less compassion and understanding
				}
				modifier = {
					add = 10
					has_trait = arrogant #believes they are better
				}
				modifier = {
					add = 10
					has_trait = zealous #zealous and not tolerant
					faith = { NOT = { has_doctrine = doctrine_pluralism_pluralistic } }
				}
			}
			save_scope_as = same_culture_vassal
			court_event_character_flag_effect = yes
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	#More common if you're currently Promoting Culture
	weight_multiplier = {
		base = 0.5
		modifier = { 
			add = 10
			exists = cp:councillor_steward
			cp:councillor_steward = {
				is_performing_council_task = task_promote_culture
			}
		}
		modifier = {
			add = 0.5 
			short_term_gold < minor_gold_value
		}

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

	# Option A: Peacocking to the max, strut your culture struff
	option = { 
		name = hold_court.3091.a
		add_prestige = major_prestige_gain
		culture = {
			change_cultural_acceptance = {
				target = scope:different_culture_vassal.culture
				value = low_negative_culture_acceptance
				desc = cultural_acceptance_gain_hold_court_event_outcome
			}
		}
		reverse_add_opinion = {
			modifier = impressed_opinion
			target = scope:same_culture_vassal
			opinion = 40
		}
		every_vassal = {
			custom = custom.every_vassal_of_target_culture
			limit = {
				culture = scope:different_culture_vassal.culture
			}
			add_opinion = {
				target = root
				opinion = -10
				modifier = annoyed_opinion
			}
		}

		stress_impact = {
			arrogant = major_stress_loss #Yeah, we awesome
			humble = major_stress_gain #I don't think we should claim to be better
			compassionate = major_stress_gain #but... why not understanding between us?
		}

		ai_chance = {
			base = 15
			ai_value_modifier = {
				ai_greed = 1
				ai_boldness = 1
				ai_compassion = -0.5
			}
		}
	}

	# Option B: Humblebrag
	option = { 
		name = hold_court.3091.b
		add_prestige = medium_prestige_gain
		culture = {
			change_cultural_acceptance = {
				target = scope:different_culture_vassal.culture
				value = miniscule_negative_culture_acceptance
				desc = cultural_acceptance_gain_hold_court_event_outcome
			}
		}
		reverse_add_opinion = {
			modifier = pleased_opinion
			target = scope:same_culture_vassal
			opinion = 20
		}
		every_vassal = {
			custom = custom.every_vassal_of_target_culture
			limit = {
				culture = scope:different_culture_vassal.culture
			}
			add_opinion = {
				target = root
				opinion = -5
				modifier = annoyed_opinion
			}
		}
		stress_impact = {
			arrogant = medium_stress_loss
			generous = medium_stress_gain
			humble = medium_stress_gain
		}

		ai_chance = {
			base = 15
			ai_value_modifier = {
				ai_greed = -0.5
			}
		}
	}

	# Option C: Nah 
	option = { 
		name = hold_court.3091.c

		reverse_add_opinion = {
			modifier = disappointed_opinion
			target = scope:same_culture_vassal
			opinion = -30
		}
		ai_chance = {
			base = 15
			modifier = {
				has_trait = lazy
				add = 5
			}
		}
	}

	after = {
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
		scope:same_culture_vassal = {
			clear_court_event_participation = yes
		}
	}
}










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

##################################################
# 4001			Scourge - Your heir is a terrible person, vassals request new heir
# 4500			Endless Poetry - Great Poet appears at court
# 4600			SheHe who makes a Beast out of HerHimself... - Peasants are convinced tyrannical ruler is an actual monster
# 4700			An End to Agony - Vassals discuss the state of your prisons
# 4800			I Should Like a Veal Cutlet - House arrest prisoner demands fancy dinner
# 4900			In Ancient Times... - Dodgy genealogist offers to trace your lineage back to mythic heroes
##################################################

##################################################
# Scourge
# by Isabella Welch
# 4001
##################################################

# Your heir is a terrible person, vassals request new heir
hold_court.4001 = {
	type = court_event
	title = hold_court.4001.t 
	desc = {
		desc = hold_court.4001.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = {
					has_character_flag = heir_gets_in_street_fights
				}
				desc = hold_court.4001.heir_street_fight
			}
			triggered_desc = {
				trigger = {
					has_character_flag = heir_robbed_me
				}
				desc = hold_court.4001.heir_robbery
			}
			triggered_desc = {
				trigger = {
					has_character_flag = heir_lives_in_tavern
				}
				desc = hold_court.4001.heir_tavern
			}
			triggered_desc = {
				trigger = {
					has_character_flag = heir_poor_diplomat
				}
				desc = hold_court.4001.heir_diplomacy_failure
			}
			triggered_desc = {
				trigger = {
					has_character_flag = heir_personally_hated
				}
				desc = hold_court.4001.heir_hated
			}

		}
		first_valid = {
			triggered_desc = {
				trigger = {
					has_character_flag = has_protective_spouse
				}
				desc = hold_court.4001.protective_parent
			}
			desc = hold_court.4001.accusation_default
		}
		desc = hold_court.4001.heir_admission
	}
	theme = diplomacy_family_focus
	lower_left_portrait = scope:protective_parent
	lower_right_portrait = scope:preferred_heir
	court_scene = {
		button_position_character = scope:annoyed_vassal
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:annoyed_vassal = {
				group = petitioners_group
				animation = rage
			}
			scope:annoying_heir = {
				group = petitioners_group
				animation = scheme
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

	trigger = {
		NOT = { has_character_flag = has_had_disliked_heir_event }
		any_vassal = {
			count >= 1
			has_court_event_flag = no
			is_ai = yes
		}
		root.primary_heir = {
			has_court_event_flag = no
			is_ai = yes
			age >= 13
			is_player_heir_of = root
			is_child_of = root
			OR = {
				has_trait = arrogant
				has_trait = arbitrary
				has_trait = wrathful
				has_trait = sadistic
				has_trait = lunatic
				has_trait = callous
				has_trait = drunkard
				has_trait = deceitful
				has_trait = greedy
				has_trait = lazy
				has_trait = lustful
				has_trait = stubborn
				has_trait = rakish
				has_trait = fornicator
				has_trait = adulterer
				has_trait = deviant
				has_trait = rowdy
				has_trait = murderer
				has_trait = vengeful
				has_trait = torturer
				any_vassal = {
					opinion = {
						target = root.primary_heir
						value <= medium_negative_opinion
					}
				}
				diplomacy <= low_skill_rating
			}
		}
		any_child = {
			NOT = { is_player_heir_of = root }
			NOT = { has_trait = bastard }
			has_court_event_flag = no
			is_ai = yes
			character_gender_can_inherit_from_trigger = { CHARACTER = root }
			is_child_of = root
		}
	}

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

	immediate = {
		save_scope_as = actor # for loc
		add_character_flag = {
			flag = has_had_disliked_heir_event
			days = 1825
		}
		primary_heir = {
			save_scope_as = annoying_heir
			court_event_character_flag_effect = yes
		}
		random_child = {
			limit = {
				NOT = { is_player_heir_of = root }
				NOT = { has_trait = bastard }
				has_court_event_flag = no
				character_gender_can_inherit_from_trigger = { CHARACTER = root }
				is_child_of = root
				is_ai = yes
			}
			court_event_character_flag_effect = yes
			save_scope_as = preferred_heir
		}
		random_vassal = {
			weight = {
				base = 1
				modifier = {
					has_relation_rival = scope:annoying_heir
					factor = 20
				}
				modifier = {
					factor = 20
					opinion = {
						target = scope:annoying_heir
						value <= medium_negative_opinion
					}
				}
				modifier = {
					factor = 5
					is_powerful_vassal = yes
				}
			}
			limit = {
				is_ai = yes
				has_court_event_flag = no
				NOT = {
					scope:annoying_heir = {
						is_child_of = prev
					}
				}
			}
			save_scope_as = annoyed_vassal
			court_event_character_flag_effect = yes
		}
		if = {
			limit = {
				any_spouse = { 
					is_parent_of = scope:annoying_heir
					has_court_event_flag = no
					is_ai = no
				}
			}
			random_spouse = { 
				limit = {
					is_parent_of = scope:annoying_heir
					has_court_event_flag = no
					is_ai = no
				}
				save_scope_as = protective_parent
			}	
			add_character_flag = has_protective_spouse		
		}
		if = {
			limit = {
				scope:annoying_heir = {
					OR = {
						has_trait = wrathful
						has_trait = sadistic
						has_trait = vengeful
						has_trait = torturer
						has_trait = murderer
						has_trait = callous
						has_trait = stubborn
					}
				}
			}
			add_character_flag = heir_gets_in_street_fights

		}
		else_if = {
			limit = {
				scope:annoying_heir = {
					OR = {
						has_trait = greedy
						has_trait = arrogant
						has_trait = deceitful
						has_trait = arbitrary
						has_trait = lunatic
					}
				}
			}
			add_character_flag = heir_robbed_me
		}
		else_if = {
			limit = {
				scope:annoying_heir = {
					OR = {
						has_trait = drunkard
						has_trait = lazy
						has_trait = fornicator
						has_trait = lustful
						has_trait = adulterer
						has_trait = rakish
						has_trait = rowdy
					}
				}
			}
			add_character_flag = heir_lives_in_tavern
		}

		else_if = {
			limit = {
				scope:annoying_heir = {
					diplomacy <= low_skill_rating
				}
			}
			add_character_flag = heir_poor_diplomat
		}
		else = {
			add_character_flag = heir_personally_hated
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = {
		name = hold_court.4001.b
		set_designated_heir = scope:preferred_heir
		scope:annoying_heir = {
			disinherit_effect = { DISINHERITOR = root }
		}
		stress_impact = {
			family_first = medium_stress_gain
		}
		every_courtier_or_guest = {
			custom = all_courtiers_and_guests
			add_opinion = {
				opinion = 15
				target = root
				modifier = grateful_opinion
			}
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_vengefulness = 0.75
				ai_rationality = -0.5
				ai_sociability = 0.5
			}
		}
	}
	option = {
		name = hold_court.4001.d
		trigger = {
			scope:preferred_heir = { 
				NOR = {
					has_trait = arrogant
					has_trait = arbitrary
					has_trait = wrathful
					has_trait = sadistic
					has_trait = lunatic
					has_trait = callous
					has_trait = drunkard
					has_trait = deceitful
					has_trait = greedy
					has_trait = lazy
					has_trait = lustful
					has_trait = stubborn
					has_trait = rakish
					has_trait = fornicator
					has_trait = adulterer
					has_trait = deviant
					has_trait = rowdy
					has_trait = murderer
					has_trait = vengeful
					has_trait = torturer
				}
			}
			scope:annoying_heir = {
				number_of_commander_traits > 0

			}
		}
		scope:annoying_heir = {
			if = {
				limit = {
					NOT = { has_trait = reckless }
				}
				add_trait = reckless
			}
			add_prowess_skill = 4
		}
		ai_chance = {
			base =50
			ai_value_modifier = {
				ai_boldness = 0.5
			}
		}
	}

	option = { 
		name = hold_court.4001.a
		add_legitimacy = miniscule_legitimacy_gain
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_vengefulness = -0.75
				ai_rationality = -0.5
				ai_sociability = -0.5
			}
		}
	}

	after = {
		remove_character_flag = heir_personally_hated
		remove_character_flag = heir_poor_diplomat
		remove_character_flag = heir_lives_in_tavern
		remove_character_flag = heir_robbed_me
		remove_character_flag = heir_gets_in_street_fights
		remove_character_flag = has_protective_spouse
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
		scope:annoyed_vassal = {
			clear_court_event_participation = yes
		}
		scope:annoying_heir = {
			clear_court_event_participation = yes
		}
	}
}

##################################################
# Endless Poetry
# by Isabella Welch
# 4500
##################################################

# Demanding poet!
scripted_trigger demanding_poet_scripted_gender_trigger = {
	primary_title = {
		OR = {
			has_title_law = female_only_law
			has_title_law = female_preference_law
		}
	}
	NOT = { root.faith = { has_doctrine_parameter = clergy_must_be_male } }
}

hold_court.4500 = {
	type = court_event
	title = hold_court.4500.t
	desc = hold_court.4500.desc
	theme = learning_scholarship_focus
	court_scene = {
		button_position_character = scope:demanding_poet
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:demanding_poet = {
				group = petitioners_group
				animation = beg
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

	trigger = {
		is_ai = no
		NOT = {
			has_character_flag = has_had_demanding_poet_event
			NOT = { has_free_council_slot = yes }
		}
		can_employ_court_position_type = court_poet_court_position
		NOT = { employs_court_position = court_poet_court_position }
	}

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

	immediate = {
		add_character_flag = {
			flag = has_had_demanding_poet_event
			days = 7300
		}
		save_scope_as = realm_holder

		if = {
			limit = { demanding_poet_scripted_gender_trigger = yes }
			create_character = {
				location = root.capital_province
				template = demanding_poet_character
				gender = female
				save_scope_as = demanding_poet
			}
		}
		else = {
			create_character = {
				location = root.capital_province
				template = demanding_poet_character
				gender = male
				save_scope_as = demanding_poet
			}
		}
		hidden_effect = {
			add_courtier = scope:demanding_poet
			scope:demanding_poet = {
				give_nickname = nick_the_poet
				court_event_character_flag_effect = yes
			} 
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = {
		name = hold_court.4500.b
		change_current_court_grandeur = minor_court_grandeur_gain
		replace_existing_position_with_character_in_current_scope_court_effect = {
			CHARACTER = scope:demanding_poet
			POSITION = court_poet_court_position
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = -0.25
				ai_rationality = 0.75
			}
		}
	}
	option = { 
		name = hold_court.4500.a
		scope:demanding_poet = { silent_disappearance_effect = yes }
		stress_impact = {
			lifestyle_poet = minor_stress_gain
			journaller = medium_stress_gain
			arbitrary = minor_stress_gain
		}
		ai_chance = {
			base = 75
			ai_value_modifier = {
				ai_boldness = -0.25
				ai_rationality = 0.75
			}
		}
	}
	after = {
		scope:demanding_poet = {
			clear_court_event_participation = yes
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

##################################################
# SheHe who makes a Beast out of HerHimself...
# by Isabella Welch
# 4600
##################################################

scripted_trigger cannibal_follow_up_trigger = {
	scope:possible_cannibal_ruler = { 
		is_alive = yes
		is_cannibal_trigger = no
	}
	scope:cannibal_vassal = {
		is_alive = yes
		is_cannibal_trigger = yes
		is_ai = yes
		has_court_event_flag = no
	}
}

# Peasants are convinced you're a literal monster
hold_court.4600 = {
	type = court_event
	title = hold_court.4600.t 
	desc = hold_court.4600.desc
	theme = intrigue_intimidation_focus
	override_background = {
		reference = throne_room
	}
	lower_left_portrait = scope:chancellor
	court_scene = {
		button_position_character = scope:challenger_peasant
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:challenger_peasant = {
				group = petitioners_group
				animation = rage
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}
	
	trigger = {
		NOT = { has_character_flag = has_had_monstrous_ruler_event }
		OR = {
			tyranny >= medium_tyranny
			has_trait = torturer
			has_trait = schemer
			has_trait = sadistic
			AND = {
				is_witch_trigger = yes
				trait_is_shunned_or_criminal_in_my_or_lieges_faith_trigger = { TRAIT = witch GENDER_CHARACTER = root }
			}
			AND = {
				is_cannibal_trigger = yes
				trait_is_shunned_or_criminal_in_my_or_lieges_faith_trigger = { TRAIT = cannibal GENDER_CHARACTER = root }
			}
		}
		OR = { # I care about dread
			has_focus = intrigue_skulduggery_focus
			has_focus = intrigue_intimidation_focus
			has_focus = diplomacy_majesty_focus
			has_focus = martial_authority_focus
			dread <= low_dread
		}
		exists = cp:councillor_chancellor
		cp:councillor_chancellor = {
			has_court_event_flag = no
			is_ai = yes
		}
	}

	weight_multiplier = {
		base = 1

		# Court weightings.
		## The beast...
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_warlike }
		## & his library...
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_scholarly }
	}

	immediate = {
		add_character_flag = {
			flag = has_had_monstrous_ruler_event
			years = 5
		}
		save_scope_as = possible_cannibal_ruler
		create_character = {
			location = root.capital_province
			template = challenger_peasant_character
			save_scope_as = challenger_peasant

		}
		scope:challenger_peasant = {
			court_event_character_flag_effect = yes
		}
		cp:councillor_chancellor = {
			save_scope_as = chancellor
			court_event_character_flag_effect = yes
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = {
		name = hold_court.4600.a
		trigger = {
			has_trait = eccentric
		}
		add_prestige = medium_prestige_gain
		change_current_court_grandeur = minor_court_grandeur_gain
		add_intrigue_lifestyle_perk_points = 1
		every_held_county = {
			custom = custom.every_held_county
			add_county_modifier = {
				modifier = county_confident_in_humanity_modifier
				years = 25
			}
		}
		add_dread = medium_dread_gain
		ai_chance = {
			base = 200
			ai_value_modifier = {
				ai_boldness = 0.25
				ai_rationality = 0.25
			}
		}
	}

	option = {
		name = hold_court.4600.b
		add_dread = medium_dread_gain
		if = {
			limit = {
				any_vassal_or_below = {
					is_ai = yes
					OR = {
						has_trait = cannibal
						any_secret = { type = secret_cannibal }
					}
				}
			}
			random_vassal_or_below = {
				limit = {
					is_ai = yes
					has_court_event_flag = no
					OR = {
						has_trait = cannibal
						any_secret = { type = secret_cannibal }
					}
					NOR = {
						has_relation_lover = root
						has_relation_friend = root
						has_relation_rival = root
						has_relation_soulmate = root
						is_close_family_of = root
					}
				}
				save_scope_as = cannibal_vassal
			}
			trigger_event = {
				id = hold_court.4601
				days = { 30 40 }
			}
		}
		give_nickname = nick_the_child_of_devilgod
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_boldness = 0.25
				ai_honor = -0.75
			}
		}
	}
	
	option = {
		name = hold_court.4600.c
		flavor = hold_court.4600.c.tt
		add_dread = major_dread_loss
		if = {
			limit = { has_trait = sadistic }
			remove_trait = sadistic
			add_trait_force_tooltip = compassionate
		}
		else_if = {
			limit = { has_trait = callous }
			remove_trait = callous
			add_trait_force_tooltip = compassionate
		}
		if = {
			limit = {
				is_cannibal_trigger = yes
			}
			remove_cannibal_secret_or_trait_effect = yes
		}
		if = {
			limit = {
				is_witch_trigger = yes
			}
			remove_witch_secret_or_trait_effect = yes
		}
		every_held_county = {
			custom = custom.every_held_county
			add_county_modifier = {
				modifier = county_confident_in_humanity_modifier
				years = 25
			}
		}
		stress_impact = {
			sadistic = massive_stress_impact_gain
			callous = massive_stress_impact_gain
			confider = medium_stress_loss
			just = medium_stress_loss
		}
		ai_chance = {
			base = 0 # We don't want the AI changing their traits
		}
	}

	option = {
		name = hold_court.4600.d
		ai_chance = {
			base = 15
			ai_value_modifier = {
				ai_boldness = -0.25
				ai_rationality = 1
			}
		}
	}

	after = {
		hidden_effect = {
			scope:challenger_peasant = {
				clear_court_event_participation = yes
				death = {
					death_reason = death_vanished
				}
			}
		}
		scope:chancellor = {
			clear_court_event_participation = yes
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

hold_court.4601 = {
	type = letter_event
	opening = { desc = hold_court.4601.t }
	desc = hold_court.4601.d
	sender = scope:cannibal_vassal
	
	trigger = {
		cannibal_follow_up_trigger = yes
	}

	option = {
		name = hold_court.4601.a
		add_prestige = minor_prestige_gain
		trigger_event = {
			id = hold_court.4602
			days = { 7 9 }
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_sociability = 0.25
			}
		}
	}
	option = {
		name = hold_court.4601.b
		add_prestige = minor_prestige_loss
		scope:cannibal_vassal = {	
			add_opinion = {
				modifier = rejected_invitation_opinion
				opinion = -10
				target = root
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_sociability = -0.25
			}
		}
	}
}

hold_court.4602 = {
	type = character_event
	title = hold_court.4602.t
	desc = hold_court.4602.desc
	theme = murder_scheme
	left_portrait = {
		character = scope:cannibal_vassal
		animation = flirtation
	}
	
	trigger = {
		cannibal_follow_up_trigger = yes
	}

	immediate = {
		scope:cannibal_vassal = {
			if = {
				limit = {
					any_secret = {
						type = secret_cannibal
						NOT = { any_secret_knower = { this = root } }
					}
				}
				random_secret = {
					type = secret_cannibal
					reveal_to = root
				}
			}
		}
	}

	option = { 
		name = hold_court.4602.a
		give_cannibal_secret_or_trait_effect = yes
		scope:cannibal_vassal = {
			add_opinion = {
				target = root
				modifier = also_cannibal
			}
		}
		ai_chance = {
			base = 5
			ai_value_modifier = {
				ai_rationality = -0.75
			}
			modifier = {
				has_trait = gluttonous
				add = 20
			}
		}
	}

	option = {
		name = hold_court.4602.b
		if = {
			limit = {
				scope:cannibal_vassal = { is_attracted_to_gender_of = root }
				is_attracted_to_gender_of = scope:cannibal_vassal
			}
			set_relation_lover = { reason = lover_cannibal_seduction target = scope:cannibal_vassal }
		}
		else = {
			set_relation_friend = { reason = friend_private_feast target = scope:cannibal_vassal }
		}
		increase_wounds_effect = { REASON = eaten }
		scope:cannibal_vassal = {
			add_opinion = {
				target = root
				opinion = 40
				modifier = delicious_morsel_opinion
			}
		}
		ai_chance = {
			base = 5
			ai_value_modifier = {
				ai_rationality = -0.75
			}
			modifier = {
				has_trait = lustful
				add = 20
			}
		}
	}
	
	option = {
		name = hold_court.4602.c
		trigger = {
			is_cannibal_trigger = no
		}
		add_opinion = {
			target = scope:cannibal_vassal
			opinion = -50
			modifier = tried_to_eat_me_opinion
		}
		scope:cannibal_vassal = {
			add_opinion = {
				target = root
				opinion = -20
				modifier = rejected_opinion
			}
		}
		ai_chance = {
			base = 75
			ai_value_modifier = {
				ai_rationality = 0.75
			}
			modifier = {
				has_trait = gluttonous
				add = -20
			}
		}
	}
}

##################################################
# In Ancient Times...
# by Isabella Welch
# 4900
##################################################

# Shady genealogist offers to write up your legendary family history
hold_court.4900 = {
	type = court_event
	title = hold_court.4900.t 
	desc = hold_court.4900.desc
	theme = diplomacy_family_focus
	court_scene = {
		button_position_character = scope:suspicious_genealogist
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:suspicious_genealogist = {
				group = petitioners_group
				animation = scheme
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}
	
	trigger = {
		NOT = { has_character_flag = has_had_suspicious_genealogist_event }
		exists = cp:councillor_court_chaplain
		cp:councillor_court_chaplain = {
			has_court_event_flag = no
			is_ai = yes
		}
		OR = {
			AND = {
				is_female = yes
				mother ?= {
					mother ?= {
						mother ?= {
							mother ?= {
								exists = mother
							}
						}
					}
				}
			}
			AND = {
				is_male = yes
				father ?= {
					father ?= {
						father ?= {
							father ?= {
								exists = father
							}
						}
					}
				}
			}
		}
	}

	weight_multiplier = {
		base = 1

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

	immediate = {
		add_character_flag = {
			flag = has_had_suspicious_genealogist_event
			years = 5
		}
		save_scope_as = ruler_history_target
		create_character = {
			location = root.capital_province
			template = suspicious_genealogist_character
			save_scope_as = suspicious_genealogist
		}
		scope:suspicious_genealogist = {
			court_event_character_flag_effect = yes
		}
		primary_title = { save_scope_as = target_title }
		grab_mythical_founder_effect = yes
		cp:councillor_court_chaplain = {
			save_scope_as = chaplain
			court_event_character_flag_effect = yes
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = {
		name = hold_court.4900.e
		trigger = {
			NOT = { exists = promoted_legend }
			has_dlc_feature = legends
			NOT = { has_game_rule = historical_legends_only }
		}
		create_legend_seed = {
			type = legitimizing
			quality = famed
			chronicle = ancestral_glory_not_in_history
			properties = {
				ancestor_flag = root.var:mythical_ancestor_var
				title = root.primary_title
			}
		}
		stress_impact = {
			arrogant = major_stress_impact_loss
			honest = minor_stress_impact_gain
			humble = major_stress_impact_gain
		}
		ai_chance = {
			base = 75
			ai_value_modifier = {
				ai_boldness = 0.75
				ai_honor = 0.75
			}
		}
	}

	option = {
		name = hold_court.4900.a
		trigger = {
			root.dynasty = { 
				dynasty_prestige_level >= low_dynasty_prestige_level
				dynasty_prestige_level < high_dynasty_prestige_level 
			}
		}
		root.dynasty = { add_dynasty_prestige = medium_dynasty_prestige_gain }
		hidden_effect = {
			scope:suspicious_genealogist = {
				death = {
					death_reason = death_vanished
				}
			}
		}
		ai_chance = {
			base = 75
			ai_value_modifier = {
				ai_boldness = 0.75
				ai_honor = 0.75
			}
		}
	}

	option = {
		name = hold_court.4900.b
		trigger = {
			trigger_if = {
				limit = {
					is_ai = yes
				}
				short_term_gold >= medium_gold_value
			}
		}
		change_current_court_grandeur = major_court_grandeur_gain
		trigger_event = {
			id = hold_court.4901
			days = { 1 2 }
		}
		remove_short_term_gold = minor_gold_value
		ai_chance = {
			base = 25
		}
	}
	
	option = {
		name = hold_court.4900.c
		trigger = { 
			root.dynasty = {
				dynasty_prestige_level >= high_dynasty_prestige_level
			}
		}
		root.dynasty = { add_dynasty_prestige = medium_dynasty_prestige_gain }
		hidden_effect = {
			scope:suspicious_genealogist = {
				death = {
					death_reason = death_vanished
				}
			}
		}
		ai_chance = {
			base = 25
		}
	}

	option = {
		name = hold_court.4900.d
		trigger = { 
			root.dynasty = { 
				dynasty_prestige_level < low_dynasty_prestige_level 
			}
		}
		root.dynasty = { add_dynasty_prestige = medium_dynasty_prestige_gain }
		hidden_effect = {
			scope:suspicious_genealogist = {
				death = {
					death_reason = death_vanished
				}
			}
		}
		ai_chance = {
			base = 25
		}
	}

	after = {
		scope:chaplain = {
			clear_court_event_participation = yes
		}
		scope:suspicious_genealogist = {
			clear_court_event_participation = yes
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

# the reading of the family lineage...
hold_court.4901 = {
	type = character_event
	title = hold_court.4900.t
	theme = diplomacy_family_focus
	desc = {
		desc = hold_court.4901.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = {
					is_female = yes
				}
				desc = hold_court.4901.mothers
			}
			triggered_desc = {
				trigger = {
					is_male = yes
				}
				desc = hold_court.4901.fathers
			}
		}
		desc = hold_court.4901.desc.outro
	}
	left_portrait = {
		character = root
		animation = personality_bold
	}
	right_portrait = {
		character = scope:suspicious_genealogist
		animation = scheme
	}

	trigger = {
		scope:suspicious_genealogist = { is_alive = yes }
		scope:ruler_history_target = { is_alive = yes }
	}

	immediate = {
		if = {
			limit = { is_female = yes }
			root.mother = {
				save_scope_as = mother_1
				this.mother = {
					save_scope_as = mother_2
					this.mother = {
						save_scope_as = mother_3
						this.mother = {
							save_scope_as = mother_4
							this.mother = {
								save_scope_as = mother_5
							}
						}
					}
				}
			}
		}
		if = {
			limit = { is_male = yes }
			root.father = {
				save_scope_as = father_1
				this.father = {
					save_scope_as = father_2
					this.father = {
						save_scope_as = father_3
						this.father = {
							save_scope_as = father_4
							this.father = {
								save_scope_as = father_5
							}
						}
					}
				}
			}
		}
		cp:councillor_court_chaplain = { save_scope_as = chaplain }
	}

	option = {
		name = hold_court.4901.a
		flavor = hold_court.4901.a.tt
		every_courtier_or_guest = {
			custom = all_courtiers_and_guests
			add_opinion = {
				target = root
				modifier = bored_opinion
				opinion = -5
			}
		}
		stress_impact = {
			diligent = medium_stress_gain
			patient = medium_stress_gain
			family_first = medium_stress_gain

		}
		every_child = {
			limit = { 
				age < 15
				has_education_diplomacy_trigger = yes
			}
			add_diplomacy_skill = 2 
		}
		every_child = {
			limit = {
				has_trait = bastard
			}
			add_opinion = {
				target = root
				opinion = -15
				modifier = flaunted_lineage_opinion
			}
		}
		ai_chance = {
			base = 25
			modifier = {
				has_trait = family_first
				add = 50
			}
		}
	}
	option = {
		name = hold_court.4901.b
		every_courtier_or_guest = {
			limit = { NOT = { is_close_or_extended_family_of = root } }
			custom = all_courtiers_and_guests
			add_opinion = {
				target = root
				modifier = bored_opinion
				opinion = -5
			}
		}
		stress_impact = {
			humble = major_stress_gain
			family_first = minor_stress_loss	
		}
		every_close_or_extended_family_member = {
			limit = {
				NOR = {
					is_courtier_of = root
				}
			}
			custom = all_family_members
			add_opinion = {
				target = root
				modifier = flaunted_lineage_opinion
				opinion = 15
			}
		}
		ai_chance = {
			base = 25
			modifier = {
				has_trait = patient
				add = 50
			}
		}
	}
	option = {
		name = hold_court.4901.c
		every_courtier_or_guest = {
			custom = all_courtiers_and_guests
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 5
			}
		}
		stress_impact = {
			impatient = major_stress_loss
		}
		ai_chance = {
			base = 25
			modifier = {
				has_trait = impatient
				add = 50
			}
		}
	}

	after = {
		hidden_effect = {
			scope:suspicious_genealogist = {
				death = {
					death_reason = death_vanished
				}
			}
		}
	}
}










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

##################################################
# 5010 - 5019	Out of Control
# 5020 - 5029	Dancing Plague
# 5030 - 5039	New Written Language
##################################################

##################################################
# Out of Control
# by Linnéa Thimrén
# 5010 - 5019
##################################################

# Low control - give control to low control counties
hold_court.5010 = {
	type = court_event
	title = hold_court.5010.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:marshal
				}
				desc = hold_court.5010.desc_marshal
			}
			desc = hold_court.5010.desc
		}
		desc = hold_court.5010.desc.outro
	}
	theme = realm
	override_sound = { reference = event:/SFX/Events/Themes/sfx_event_theme_type_generic }
	left_portrait = {
		character = scope:peasant
		animation = beg
	}
	lower_right_portrait = scope:portrait
	court_scene = {
		button_position_character = scope:peasant
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:peasant = {
				group = petitioners_group
				animation = beg
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}
	
	trigger = {
		NOT = { has_character_flag = had_event_hold_court_5010 }
		any_sub_realm_county = {
			county_control < medium_county_control
			NOT = { has_county_modifier = county_increased_presence_modifier }
		}
	}

	weight_multiplier = {
		base = 0.5
		modifier = {
			add = 0.5
			exists = cp:councillor_marshal
			cp:councillor_marshal = {
				is_performing_council_task = task_increase_control
				is_available = yes #Not currently travelling or attending activity
				location.county ?= {
					county_control < medium_county_control
					NOT = { has_county_modifier = county_increased_presence_modifier }
				}
			}
		}
		modifier = {
			add = 0.25
			any_sub_realm_county = {
				county_control <= low_county_control
				NOT = { has_county_modifier = county_increased_presence_modifier }
			}
		}

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

	immediate = {
		add_character_flag = {
			flag = had_event_hold_court_5010
			years = 10
		}
		every_sub_realm_county = {
			limit = {
				county_control < medium_county_control
				NOT = { has_county_modifier = county_increased_presence_modifier }
			}
			add_to_list = potential_county
		}
		random_in_list = {
			list = potential_county
			limit = {
				exists = root.cp:councillor_marshal
				root.cp:councillor_marshal = {
					is_performing_council_task = task_increase_control
					is_available = yes #Not currently travelling or attending activity
					councillor_task_target = prev.title_province
				}
			}
			alternative_limit = {
				county_control <= low_county_control
			}
			alternative_limit = {
				always = yes
			}
			save_scope_as = county
		}
		create_character = {
			template = servant_character
			dynasty = none
			location = root.capital_province
			trait = compassionate
			save_scope_as = peasant
		}
		scope:peasant = {
			court_event_character_flag_effect = yes	
		}
		#To save the most relevant character for loc and portrait
		if = {
			limit = {
				exists = cp:councillor_marshal
				cp:councillor_marshal = {
					has_court_event_flag = no
					is_ai = yes
					is_performing_council_task = task_increase_control
					councillor_task_target = scope:county.title_province
				}
			}
			cp:councillor_marshal = {
				save_scope_as = marshal
				save_scope_as = portrait
				court_event_character_flag_effect = yes
			}
		}
		else_if = {
			limit = {
				scope:county.holder != root
				scope:county.holder = { has_court_event_flag = no }
			}
			scope:county.holder = {
				save_scope_as = vassal
				save_scope_as = portrait
				court_event_character_flag_effect = yes
			}
		}
		else = {
			save_scope_as = portrait
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}


	option = { # Let's go for it
		name = hold_court.5010.a

		remove_treasury_or_gold = medium_treasury_or_gold_value
		scope:county = {
			change_county_control = medium_county_control_gain
		}
		every_sub_realm_county = {
			custom = every_low_county_control
			limit = {
				county_control <= low_county_control
				NOT = { this = scope:county }
			}
			change_county_control = minor_county_control_gain 
		}
		stress_impact = {
			compassionate = medium_stress_impact_loss
			callous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_rationality = 1
				ai_greed = -1
				ai_compassion = 1
			}
			modifier = {
				factor = 0
				gold <= medium_treasury_or_gold_value
			}
		}
	}

	option = { # We need more violence!
		name = hold_court.5010.b
		scope:county = {
			add_county_modifier = {
				modifier = county_increased_presence_modifier
				days = 3650
			}
			change_county_control = major_county_control_gain
		}
		every_sub_realm_county = {
			custom = every_low_county_control
			limit = {
				county_control <= low_county_control
				NOT = { this = scope:county }
			}
			add_county_modifier = {
				modifier = county_increased_presence_modifier
				days = 3650
			}
			change_county_control = major_county_control_gain
		}
		stress_impact = {
			sadistic = medium_stress_impact_loss
			compassionate = medium_stress_impact_gain
		}
	}

	option = { # Idc lol
		name = hold_court.5010.c
		stress_impact = {
			compassionate = minor_stress_impact_gain
		}
	}
	
	after = {
		if = {
			limit = {
				exists = scope:marshal
			}
			clear_court_event_participation = yes
		}
		else_if = {
			limit = {
				exists = scope:vassal
			}
			clear_court_event_participation = yes
		}
		hidden_effect = {
			scope:peasant = {
				clear_court_event_participation = yes
			}
			if = {
				limit = {
					scope:county = {
						has_county_modifier = county_increased_presence_modifier
					}
				}
				scope:peasant = {
					death = {
						death_reason = death_hanged
					}
				}
			}
			else_if = {
				limit = {
					scope:county.holder != root
					scope:county.holder.capital_province = {
						local_pool_is_full_trigger = no
					}
				}
				scope:peasant = {
					move_to_pool_at = scope:county.holder.capital_province
				}
			}
			else = {
				scope:peasant = {
					death = {
						death_reason = death_vanished
					}
				}
			}
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

##################################################
# New Written Language
# by Linnéa Thimrén
# 5030 - 5039
##################################################

# Minority gender in your court develops their own written language (think Nüshu)
scripted_trigger hold_court_5030_courtier_basic_trigger = {
	has_court_event_flag = no
	is_ai = yes
	faith = root.faith
	is_imprisoned = no
	NOT = { has_trait = incapable }
	OR = {
		AND = {
			OR = {
				root = { has_realm_law = male_only_law }
				root = { has_realm_law = male_preference_law }
			}
			is_female = yes
		}
		AND = {
			OR = {
				root = { has_realm_law = female_only_law }
				root = { has_realm_law = female_preference_law }
			}
			is_male = yes
		}
	}
}
scripted_trigger hold_court_5030_courtier_adult_trigger = {
	hold_court_5030_courtier_basic_trigger = yes
	is_adult = yes
	NOT = { has_court_position = court_tutor_court_position }
}
hold_court.5030 = {
	type = court_event
	title = hold_court.5030.t
	desc = hold_court.5030.desc
	theme = realm
	override_sound = { reference = event:/SFX/Events/Themes/sfx_event_theme_type_generic }
	lower_right_portrait = scope:court_tutor
	court_scene = {
		button_position_character = scope:courtier
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:courtier = {
				group = petitioners_group
				animation = happiness
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

	trigger = {
		any_courtier = {
			hold_court_5030_courtier_adult_trigger = yes
		}
		OR = {
			AND = {
				OR = {
					root = { has_realm_law = male_only_law }
					root = { has_realm_law = male_preference_law }
				}
				is_female = yes
			}
			AND = {
				OR = {
					root = { has_realm_law = female_only_law }
					root = { has_realm_law = female_preference_law }
				}
				is_male = yes
			}
		}
		OR = { # Make sure you care about schemes and such
			has_lifestyle = intrigue_lifestyle
			any_scheme = { is_hostile = yes }
		}
	}

	weight_multiplier = {
		base = 1

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

	cooldown = { years = 40 }

	immediate = {
		random_courtier = {
			limit = {
				hold_court_5030_courtier_adult_trigger = yes
			}
			weight = {
				base = 1
				compare_modifier = {
					value = learning
					multiplier = 2
				}
			}
			save_scope_as = courtier
			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_physically_able_adult = yes
					has_court_event_flag = no
					is_ai = yes
				}
			}
			random_court_position_holder = {
				type = court_tutor_court_position
				limit = {
					is_physically_able_adult = yes
					has_court_event_flag = no
					is_ai = yes
				}
				save_scope_as = court_tutor
				court_event_character_flag_effect = yes
			}
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = { # Allow it
		name = hold_court.5030.a
		#If you're part of the gender minority you get a boost as well
		if = {
			limit = {
				OR = {
					AND = {
						OR = {
							has_realm_law = male_only_law
							has_realm_law = male_preference_law
						}
						is_female = yes
					}
					AND = {
						OR = {
							has_realm_law = female_only_law
							has_realm_law = female_preference_law
						}
						is_male = yes
					}
				}
			}
			if = {
				limit = {
					is_male = yes
				}
				add_character_modifier = {
					modifier = hold_court_written_language_men_advanced_modifier
					years = 20
				}
			}
			else = {
				add_character_modifier = {
					modifier = hold_court_written_language_women_advanced_modifier
					years = 20
				}
			}
		}
		#Boost all courtiers of the relevant gender
		every_courtier = {
			limit = {
				hold_court_5030_courtier_basic_trigger = yes
			}
			custom = hold_court.5030.courtiers
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 10
			}
			if = {
				limit = {
					is_male = yes
				}
				add_character_modifier = {
					modifier = hold_court_written_language_men_modifier
					years = 20
				}
			}
			else = {
				add_character_modifier = {
					modifier = hold_court_written_language_women_modifier
					years = 20
				}
			}
		}
	}

	option = { # Embrace it and task your Court Tutor with teaching it
		name = hold_court.5030.b
		trigger = {
			exists = scope:court_tutor
		}
		#If you're part of the gender minority you get a boost as well
		if = {
			limit = {
				OR = {
					AND = {
						OR = {
							has_realm_law = male_only_law
							has_realm_law = male_preference_law
						}
						is_female = yes
					}
					AND = {
						OR = {
							has_realm_law = female_only_law
							has_realm_law = female_preference_law
						}
						is_male = yes
					}
				}
			}
			if = {
				limit = {
					is_male = yes
				}
				add_character_modifier = {
					modifier = hold_court_written_language_men_advanced_modifier
					years = 20
				}
			}
			else = {
				add_character_modifier = {
					modifier = hold_court_written_language_women_advanced_modifier
					years = 20
				}
			}
		}
		#Boost all courtiers of the relevant gender
		every_courtier = {
			limit = {
				hold_court_5030_courtier_basic_trigger = yes
			}
			custom = hold_court.5030.courtiers
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 10
			}
			if = {
				limit = {
					is_male = yes
				}
				add_character_modifier = {
					modifier = hold_court_written_language_men_advanced_modifier
					years = 20
				}
			}
			else = {
				add_character_modifier = {
					modifier = hold_court_written_language_women_advanced_modifier
					years = 20
				}
			}
		}
	}

	option = { # Use their expertise for other things
		name = hold_court.5030.c
		scope:courtier = {
			add_opinion = {
				target = root
				modifier = refusal_opinion
				opinion = -15
			}
		}
		add_character_modifier = {
			modifier = invented_code_resistance_modifier
			years = 5
		}
		stress_impact = {
			paranoid = medium_stress_impact_loss
		}
	}

	after = {
		scope:courtier = {
			clear_court_event_participation = yes
		}
		if = {
			limit = { exists = scope:court_tutor }
			scope:court_tutor = {
				clear_court_event_participation = yes
			}
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}










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

##################################################
# 6000			Empty Granaries
# 6010			Land Grants
# 6020			Hawks and Doves
# 6030			From Beyond the Border
# 6040			A Lost Treasure
# 6050 - 6051	A Holy Tomb
# 6060			A Convenient Offer
# 6070			Budding Ally
# 6080			Settling the [people]
# 6090			Heretics at Large
# 6100 - 6101	A Land at War
# 6110			A Ravaged Land
# 6120 - 6121	The Day of Truth
# 6130			The Cadastre
# 6140			A Cumbersome Gift
# 6150			The End Is Nigh!
# 6160			Empty Coffers
# 6170			Ignoble Imprisonment
# 6180			The Shadow Behind the Throne
# 6190			A Shadow in the Night
# 6200 - 6201	The Monster of X
# 6210 			A Land of Barbarians
# 6220			Studying the Dead
# 6230			A Massive Problem
##################################################

##################################################
# Empty Granaries
# by Claudia Baldassi
# 6000
##################################################

# A province has been hit by a famine and is asking for your help. What do you do? #

scripted_trigger hold_court_6000_valid_province_trigger = {
	OR = {
		has_province_modifier = recently_looted_modifier
		has_province_modifier = disease_spreading_modifier
		has_province_modifier = winter_harsh_modifier
		barony = {
			holder ?= {
				has_character_flag = recently_occupied_flag
			}
		}
	}
	barony = {
		holder ?= {
			this != root
			is_available_ai_adult = yes
			has_court_event_flag = no
		}
	}
}

scripted_trigger hold_court_6000_valid_inspector_trigger = {
	has_court_event_flag = no
	OR = {
		stewardship >= 14
		has_trait = education_stewardship_2
		has_trait = education_stewardship_3
		has_trait = education_stewardship_4
		has_trait = education_stewardship_5
		has_trait = administrator
	}
	NOR = {
		has_trait = lazy
		is_spouse_of = root
		is_concubine_of = root
	}
	is_councillor = no
	is_available_ai_adult = yes
}

hold_court.6000 = {
	type = court_event
	title = hold_court.6000.t
	desc = {
		desc = hold_court.6000.desc_intro
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:6000_poor = {
						has_character_flag = recently_occupied_flag
					}
				}
				desc = hold_court.6000.desc_occupation
			}
			triggered_desc = {
				trigger = {
					scope:6000_province = {
						has_province_modifier = recently_looted_modifier
					}
				}
				desc = hold_court.6000.desc_raiding
			}
			triggered_desc = {
				trigger = {
					scope:6000_province = {
						has_province_modifier = disease_spreading_modifier
					}
				}
				desc = hold_court.6000.desc_epidemics
			}
			triggered_desc = {
				trigger = {
					scope:6000_province = {
						has_province_modifier = winter_harsh_modifier
					}
				}
				desc = hold_court.6000.desc_winter
			}
		}
		desc = hold_court.6000.desc_middle
		triggered_desc = {
			trigger = {
				exists = scope:6000_count
			}
			desc = hold_court.6000.desc_count
		}
		desc = hold_court.6000.desc_ending
	}
	theme = court
	lower_left_portrait = scope:6000_count
	lower_right_portrait = scope:inspector
	court_scene = {
		button_position_character = scope:6000_poor
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:6000_poor = {
				group = petitioners_group
				animation = beg
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

	cooldown = { years = 10 }

	trigger = {
		any_realm_province = {
			hold_court_6000_valid_province_trigger = yes
		}
	}

	weight_multiplier = {
		base = 1

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

	immediate = {
		random_realm_province = {
			limit = {
				hold_court_6000_valid_province_trigger = yes
			}
			save_scope_as = 6000_province
		}
		scope:6000_province = {
			barony = {
				holder = {
					save_scope_as = 6000_poor
				}
			}
		}
		if = {
			limit = {
				employs_court_position = seneschal_court_position
				any_court_position_holder = {
					type = seneschal_court_position
					is_available_ai_adult = yes
					has_court_event_flag = no
				}
			}
			random_court_position_holder = {
				type = seneschal_court_position
				limit = {
					is_available_ai_adult = yes
					has_court_event_flag = no
				}
				save_scope_as = inspector
				court_event_character_flag_effect = yes
			}
		}
		else_if = {
			limit = {
				any_courtier_or_guest = {
					hold_court_6000_valid_inspector_trigger = yes
				}
			}
			random_courtier_or_guest = {
				limit = {
					hold_court_6000_valid_inspector_trigger = yes
				}
				save_scope_as = inspector
				court_event_character_flag_effect = yes
			}
		}
		if = {
			limit = {
				scope:6000_province.county.holder = {
					NOR = {
						this = root
						this = scope:6000_poor
					}
				}
			}
			scope:6000_province.county.holder = {
				save_scope_as = 6000_count
				court_event_character_flag_effect = yes
			}
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	#Option A: send money
	option = {
		name = hold_court.6000.a
		trigger = {
			trigger_if = {
				limit = {
					is_ai = yes
				}
				short_term_gold >= medium_gold_value
			}
		}
		pay_treasury_or_gold = {
			target = scope:6000_poor
			value = medium_treasury_or_gold_value
		}
		add_hook = {
			type = favor_hook
			target = scope:6000_poor
		}
		every_sub_realm_county = {
			limit = {
				title_province = { hold_court_6000_valid_province_trigger = yes }
			}
			add_county_modifier = {
				modifier = invested_in_province_modifier
				years = 10
			}
		}
		if = {
			limit = { exists = scope:6000_count }
			scope:6000_count = {
				add_opinion = {
					target = root
					modifier = grateful_opinion
					opinion = 20
				}
			}
		}
		stress_impact = {
			greedy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 5

			modifier = {
				gold < 0
				add = -10
			}
			modifier = {
				short_term_gold >= medium_gold_value
				add = 5
			}
			modifier = {
				OR = {
					has_trait = generous
					has_trait = improvident
					has_trait = profligate
				}
				add = 15
			}
		}
	}

	#Option B: less taxes
	option = {
		name = hold_court.6000.b
		every_sub_realm_county = {
			limit = {
				title_province = { hold_court_6000_valid_province_trigger = yes }
			}
			add_county_modifier = {
				modifier = court_tax_relief_county_modifier
				years = 10
			}
		}
		if = {
			limit = { exists = scope:6000_count }
			scope:6000_count = {
				add_opinion = {
					target = root
					modifier = grateful_opinion
					opinion = 30
				}
			}
		}
		add_hook = {
			type = indebted_hook
			target = scope:6000_poor
		}
		stress_impact = {
			greedy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 5

			modifier = {
				gold < 0
				add = -5
			}
			modifier = {
				OR = {
					has_trait = greedy
					ai_greed >= medium_positive_ai_value
				}
				add = -10
			}
		}
	}

	#Option C: send inspector - limited to adequate character
	option = {
		name = hold_court.6000.c
		trigger = {
			exists = scope:inspector
		}
		custom_tooltip = hold_court.6000.c.tt
		scope:inspector = {
			add_character_modifier = {
				modifier = hold_court_inspector_modifier
				years = 10
			}
		}
		remove_courtier_or_guest = {
			character = scope:inspector
			new_location = scope:6000_province
		}
		ai_chance = {
			base = 10
		}
	}

	#Option D: they can manage it on their own
	option = {
		name = hold_court.6000.d
		stress_impact = {
			generous = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
			gregarious = medium_stress_impact_gain
			just = medium_stress_impact_gain
		}
		ai_chance = {
			base = 2

			modifier = {
				has_trait = lazy
				add = 10
			}
			modifier = {
				OR = {
					has_trait = just
					has_trait = generous
					has_trait = compassionate
					has_trait = gregarious
				}
				add = -5
			}
		}
	}

	after = {
		if = {
			limit = {
				exists = scope:inspector
			}
			scope:inspector = {
				clear_court_event_participation = yes
			}
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

##################################################
# From Beyond the Border
# by Claudia Baldassi
# 6030
##################################################

# A bilingual monk from a (recently conquered) county of a different culture is offering their translation of the great works of their culture into your language #

scripted_trigger hold_court_6030_valid_county_trigger = {
	culture = {
		this != root.culture
		save_temporary_scope_as = 6030_border_culture
	}
	any_neighboring_county = {
		holder = {
			this != root
			culture = scope:6030_border_culture
		}
	}
	any_county_province = {
		has_holding_type = church_holding
	}
	religion = {
		any_faith = {
			has_doctrine = tenet_monasticism
		}
	}
}

hold_court.6030 = {
	type = court_event
	title = hold_court.6030.t
	desc = hold_court.6030.desc
	theme = court
	court_scene = {
		button_position_character = scope:6030_monk
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:6030_monk = {
				group = petitioners_group
				animation = personality_rational
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

	cooldown = { years = 25 }

	trigger = {
		any_held_county = {
			hold_court_6030_valid_county_trigger = yes
		}
	}

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

	immediate = {
		random_held_county = {
			limit = {
				hold_court_6030_valid_county_trigger = yes
			}
			save_scope_as = 6030_border
		}
		scope:6030_border = {
			random_county_province = {
				limit = {
					has_holding_type = church_holding
				}
				save_scope_as = 6030_church
			}
		}
		create_character = {
			location = root.capital_province
			template = priest_character_template
			faith = scope:6030_border.faith
			culture = scope:6030_border.culture
			gender_female_chance = root_faith_clergy_gender_female_chance
			trait = devoted
			save_scope_as = 6030_monk
		}
		hidden_effect = {
			add_courtier = scope:6030_monk
		}
		scope:6030_monk = {
			court_event_character_flag_effect = yes
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	#Option A: accept the translation
	option = {
		name = hold_court.6030.a
		add_prestige = minor_prestige_gain
		change_current_court_grandeur = minor_court_grandeur_gain
		scope:6030_monk = { select_and_move_to_pool_effect = yes }
		culture = {
			change_cultural_acceptance = {
				target = scope:6030_monk.culture
				value = minor_cultural_acceptance_value
				desc = cultural_acceptance_gain_hold_court_event_outcome
			}
		}
		scope:6030_monk = {
			add_character_flag = 6030_remove_char_flag
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 0.5
			}
		}
	}

	#Option B: you ask them to stay and teach you
	option = {
		name = hold_court.6030.b
		trigger = {
			learning >= 12
		}
		skill = learning
		add_prestige = medium_prestige_gain
		change_current_court_grandeur = minor_court_grandeur_gain
		if = {
			limit = {
				can_appoint_char_to_court_position = {
					CHAR = scope:6030_monk
					COURT_POS = court_tutor_court_position
				}
			}
			court_position_grant_effect = {
				EMPLOYER = root
				POS = court_tutor
				CANDIDATE = scope:6030_monk
			}
		}
		add_character_modifier = {
			modifier = hold_court_bilingual_readings_modifier
			years = 10
		}
		culture = {
			change_cultural_acceptance = {
				target = scope:6030_monk.culture
				value = minor_cultural_acceptance_gain
				desc = cultural_acceptance_gain_hold_court_event_outcome
			}
		}
		stress_impact = {
			content = minor_stress_impact_gain
			impatient = minor_stress_impact_gain
			irritable = medium_stress_impact_gain
			arrogant = medium_stress_impact_gain
			lazy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 0.5
			}
			modifier = {
				has_trait = content
				add = -25
			}
			modifier = {
				has_trait = impatient
				add = -25
			}
			modifier = {
				has_trait = irritable
				add = -50
			}
			modifier = {
				has_trait = arrogant
				add = -50
			}
			modifier = {
				has_trait = lazy
				add = -50
			}
			modifier = {
				has_trait = ambitious
				add = 50
			}
		}
	}

	#Option C: I don't care
	option = {
		name = hold_court.6030.c
		scope:6030_monk = { select_and_move_to_pool_effect = yes }
		scope:6030_monk = {
			add_character_flag = 6030_remove_char_flag
		}
		stress_impact = {
			lazy = medium_stress_impact_loss
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = -0.5
			}
			modifier = {
				has_trait = lazy
				add = 50
			}
		}
	}

	after = {
		scope:6030_monk = {
			clear_court_event_participation = yes
			if = {
				limit = { has_character_flag = 6030_remove_char_flag }
				silent_disappearance_effect = yes
			}
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

##################################################
# A Lost Treasure
# by Claudia Baldassi
# 6040
##################################################

# Scribes from a remote monastery think they've found a rare/long-lost manuscript. It might be a fake, something worthless, or an artifact #

hold_court.6040 = {
	type = court_event
	title = hold_court.6040.t
	desc = hold_court.6040.desc
	theme = court
	lower_left_portrait = scope:antiquarian
	court_scene = {
		button_position_character = scope:6040_monk
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:6040_monk = {
				group = petitioners_group
				animation = ecstasy
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

	cooldown = { years = 20 }

	trigger = {
		any_realm_province = {
			has_holding_type = church_holding
			religion = {
				any_faith = {
					has_doctrine = tenet_monasticism
				}
			}
		}
	}

	weight_multiplier = {
		base = 1

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

	immediate = {
		random_realm_province = {
			limit = {
				has_holding_type = church_holding
				religion = {
					any_faith = {
						has_doctrine = tenet_monasticism
					}
				}
			}
			save_scope_as = 6040_church
		}
		create_character = {
			location = root.capital_province
			template = priest_character_template
			faith = scope:6040_church.faith
			gender_female_chance = root_faith_clergy_gender_female_chance
			trait = devoted
			save_scope_as = 6040_monk
		}
		scope:6040_monk = {
			court_event_character_flag_effect = yes
		}
		if = {
			limit = {
				employs_court_position = antiquarian_court_position
			}
			court_position:antiquarian_court_position = { save_scope_as = antiquarian }
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	#Option B: send for the antiquarian - if you have one
	option = {
		name = hold_court.6040.b
		trigger = {
			exists = scope:antiquarian
		}
		random_list = {
			10 = { #it's an artifact!
				desc = hold_court.6040.c.tt.4
				send_interface_toast = {
					title = hold_court_6040_b_artifact
					random_dummy_gender_effect = yes
					create_artifact_book_effect = {
						OWNER = root
						CREATOR = scope:dummy_gender
						SET_SUBJECT = flag:lunatic
						SET_TOPIC = flag:artifact_book_voynich
					}
				}
				scope:antiquarian = { add_learning_skill = 2 }
				add_prestige = medium_prestige_gain
			}
			35 = {	#it's an old book
				desc = hold_court.6040.c.tt.3
				send_interface_toast = {
					title = hold_court_6040_b_generic
					scope:antiquarian = { add_learning_skill = 1 }
					add_prestige = minor_prestige_gain
				}
			}
			30 = {	#they have no clue
				modifier = {
					factor = 0
					scope:antiquarian = {
						OR = {
							has_trait = education_learning_4
							has_trait = education_learning_5
							has_trait = intellect_good_3
							has_trait = scholar
							learning > 20
						}
					}
				}
				modifier = {
					add = -20
					scope:antiquarian = {
						OR = {
							has_trait = education_learning_3
							has_trait = intellect_good_2
							learning >= 15
							learning <= 20
						}
					}
				}
				desc = hold_court.6040.b.tt
				send_interface_toast = {
					title = hold_court_6040_b_clueless
					add_character_modifier = hold_court_mysterious_book_modifier
					add_prestige = medium_prestige_loss
				}
			}
			20 = {	#it's a fake!
				desc = hold_court.6040.c.tt
				send_interface_toast = {
					title = hold_court_6040_b_fake
					add_prestige = medium_prestige_gain
					scope:antiquarian = { add_learning_skill = 2 }
				}
			}
		}
		ai_chance = {
			base = 150
			ai_value_modifier = {
				ai_rationality = 0.5
			}
		}
	}

	#Option C: study it yourself - if you can
	option = {
		name = hold_court.6040.c
		trigger = {
			learning >= 12
		}
		skill = learning
		random_list = {
			30 = {	#it's an old book
				desc = hold_court.6040.c.tt.3
				send_interface_toast = {
					title = hold_court_6040_b_generic
					add_learning_skill = 1
					add_prestige = minor_prestige_gain
					create_artifact_book_effect = {
						OWNER = root
						CREATOR = scope:dummy_gender
						SET_SUBJECT = flag:lunatic
						SET_TOPIC = flag:artifact_book_voynich
					}
				}
			}
			50 = {	#you have no clue
				modifier = {
					factor = 0
					OR = {
						has_trait = education_learning_4
						has_trait = education_learning_5
						has_trait = intellect_good_3
						has_trait = scholar
						learning > 20
					}
				}
				modifier = {
					add = -20
					OR = {
						has_trait = education_learning_3
						has_trait = intellect_good_2
						AND = {
							learning <= 20
							learning >= 15
						}
					}
				}
				desc = hold_court.6040.c.tt.2
				send_interface_toast = {
					title = hold_court_6040_c_clueless
					add_prestige = medium_prestige_loss
					add_character_modifier = hold_court_mysterious_book_modifier
				}
			}
			15 = {	#it's a fake!
				desc = hold_court.6040.c.tt
				send_interface_toast = {
					title = hold_court_6040_b_fake
					add_prestige = medium_prestige_gain
					add_learning_skill = 2
				}
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 0.5
				ai_energy = 0.25
			}
		}
	}

	#Option D: it's clearly demonic!
	option = {
		name = hold_court.6040.d
		trigger = {
			OR = {
				has_trait = zealous
				has_trait = theologian
			}
		}
		add_piety = major_piety_gain
		add_prestige = minor_prestige_loss
		add_dread = minor_dread_gain
		add_stress = major_stress_impact_loss
		ai_chance = {
			base = 200
		}
	}

	#Option E: who cares about books?
	option = {
		name = hold_court.6040.e
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = -0.5
			}
			modifier = {
				has_trait = lazy
				add = 50
			}
		}
	}

	after = {
		scope:6040_monk = {
			clear_court_event_participation = yes
			silent_disappearance_effect = yes
		}
		if = {
			limit = { exists = scope:antiquarian }
			scope:antiquarian = { clear_court_event_participation = yes }
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

##################################################
# A Holy Tomb
# by Claudia Baldassi
# 6050 - 6051
##################################################

# The tomb of a local saint has been growing in popularity. The devotees of the saint are now asking for a land grant to support the growing religious establishment there. #

scripted_trigger hold_court_6050_religion_trigger = {
	OR = {
		OR = { religion = religion:eastern_orthodox_religion religion = religion:catholic_religion religion = religion:protestant_religion }
		religion = religion:islam_religion
		religion = religion:buddhism_religion
		religion = religion:hinduism_religion
	}
}

hold_court.6050 = {
	type = court_event
	title = hold_court.6050.t
	desc = {
		desc = hold_court.6050.desc
		triggered_desc = {
			trigger = {
				exists = scope:6050_pop.faith.religious_head
				scope:6050_pop.faith.religious_head = root
			}
			desc = hold_court.6050.desc_hof
		}
	}
	theme = court
	lower_left_portrait = scope:6050_holy
	court_scene = {
		button_position_character = scope:6050_pop
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:6050_pop = {
				group = petitioners_group
				animation = ecstasy
			}
			scope:chaplain = {
				group = petitioners_group
				animation = ecstasy
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

	#Note: This event is triggered by hold_court.6051 and cannot have any triggers of its own. All triggers must be in hold_court.6051 or the queue can get stuck here forever.

	weight_multiplier = {
		base = 1

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

	immediate = {
		create_character = {
			location = root.capital_province
			template = servant_character
			faith = scope:6050_tomb.faith
			culture = scope:6050_tomb.culture
			save_scope_as = 6050_pop
		}
		scope:6050_pop = {
			court_event_character_flag_effect = yes
		}
		cp:councillor_court_chaplain = {
			save_scope_as = chaplain
			court_event_character_flag_effect = yes
		}
		if = {
			limit = {
				exists = scope:6050_pop.faith.religious_head
				scope:6050_pop.faith.religious_head != root
			}
			random = {
				chance = 20
				add_character_flag = {
					flag = 6050_church_approves
					days = 10
				}
			}
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	#Option A: create a temple on the tomb
	option = {
		name = hold_court.6050.a
		trigger = {
			NOT = { has_trait = lifestyle_mystic }
		}
		scope:6050_tomb = {
			set_holding_type = church_holding
		}
		if = {
			limit = {
				OR = {
					has_character_flag = 6050_church_approves
					AND = {
						exists = scope:6050_pop.faith.religious_head
						scope:6050_pop.faith.religious_head = root
					}
				}
			}
			add_piety = major_piety_gain
		}
		else = {
			add_piety = major_piety_loss
		}
		scope:6050_tomb.county = {
			add_county_modifier = {
				modifier = tougher_to_convert
				years = 10
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = 1
			}
		}
	}

	#Option B: limited to mystic: relic
	option = {
		name = hold_court.6050.b
		trigger = { has_trait = lifestyle_mystic }
		religion = { save_scope_as = statue_religion }
		create_artifact = {	
			name = artifact_pedestal_reliquary_6050_saint_name
			description = artifact_pedestal_reliquary_6050_saint_desc
			type = pedestal
			template = 6050_relic_template
			visuals = reliquary
			modifier = artifact_monthly_piety_3_modifier
			save_scope_as = 6050_relic
		}
		scope:6050_relic = {
			set_variable = { # required to track equipability in template
				name = statue_religion
				value = root.religion
			}
		}
		scope:6050_tomb = {
			set_holding_type = church_holding
		}
		if = {
			limit = {
				OR = {
					has_character_flag = 6050_church_approves
					AND = {
						exists = scope:6050_pop.faith.religious_head
						scope:6050_pop.faith.religious_head = root
					}
				}
			}
			add_piety = major_piety_gain
		}
		else = {
			add_piety = major_piety_loss
		}
		scope:6050_tomb.county = {
			add_county_modifier = {
				modifier = tougher_to_convert
				years = 10
			}
		}
		ai_chance = {
			base = 200
		}
	}

	#Option C: persecute the local cult
	option = {
		name = hold_court.6050.c
		add_dread = medium_dread_gain
		if = {
			limit = {
				OR = {
					NOT = {
						has_character_flag = 6050_church_approves
					}
					AND = {
						exists = scope:6050_pop.faith.religious_head
						scope:6050_pop.faith.religious_head = root
					}
				}
			}
			add_piety = major_piety_gain
		}
		if = {
			limit = {
				scope:6050_tomb.county.faith != root.faith
			}
			scope:6050_tomb.county = {
				set_county_faith = root.faith
			}
		}
		scope:6050_tomb.county = {
			change_county_control = 50
		}
		stress_impact = {
			lifestyle_mystic = medium_stress_impact_gain
			trusting = minor_stress_impact_gain
			compassionate = major_stress_impact_gain
			forgiving = major_stress_impact_gain
		}
		if = {
			limit = {
				has_character_flag = 6050_church_approves
			}
			stress_impact = {
				zealous = major_stress_impact_gain
			}
		}
		else = {
			stress_impact = {
				zealous = major_stress_impact_loss
			}
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = trusting
				add = -25
			}
			modifier = {
				has_trait = lifestyle_mystic
				add = -50
			}
			modifier = {
				has_trait = compassionate
				add = -75
			}
			modifier = {
				has_trait = forgiving
				add = -75
			}
		}
	}
	#Option D: ignore them
	option = {
		name = hold_court.6050.d
		ai_chance = {
			base = 100
			modifier = {
				has_trait = lazy
				add = 50
			}
		}
	}

	after = {
		scope:6050_pop = {
			clear_court_event_participation = yes
			silent_disappearance_effect = yes
		}
		scope:chaplain = {
			clear_court_event_participation = yes
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

hold_court.6051 = {		#Hidden event to create the saint
	type = character_event
	hidden = yes
	cooldown = { years = 30 }

	trigger = {
		any_realm_province = {
			has_holding = no
			hold_court_6050_religion_trigger = yes
			county.faith != root.faith
		}
		exists = cp:councillor_court_chaplain
		cp:councillor_court_chaplain = {
			has_court_event_flag = no
			is_available_ai_adult = yes
		}
	}

	immediate = {
		random_realm_province = {
			limit = {
				has_holding = no
				hold_court_6050_religion_trigger = yes
			}
			save_scope_as = 6050_tomb
		}
		create_character = {
			location = scope:6050_tomb
			template = local_saint_template
			faith = scope:6050_tomb.faith
			culture = scope:6050_tomb.culture 
			save_scope_as = 6050_holy
		}
		scope:6050_holy = {
			death = {
				death_reason = death_mysterious
			}
		}
		trigger_event = hold_court.6050
	}
}

##################################################
# A Convenient Offer
# by Claudia Baldassi
# 6060
##################################################

# A wealthy knight or merchant offers to purchase a piece of land from you - in exchange for money, which you really need #

scripted_trigger hold_court_6060_valid_county_trigger = {
	OR = {
		has_holding = no
		AND = {
			is_county_capital = no
			barony = {
				holder = root
				is_leased_out = no
			}
			NOT = {
				has_holding_type = church_holding
			}
		}
	}
}

scripted_trigger hold_court_6060_valid_knight_trigger = {
	has_court_event_flag = no
	is_landed = no
	stewardship >= 6
	NOT = { has_trait = celibate }
	is_available_ai_adult = yes
}

hold_court.6060 = {
	type = court_event
	title = hold_court.6060.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:6060_rich = { is_knight = yes }
				}
				desc = hold_court.6060.desc
			}
			desc = hold_court.6060.desc_merchant
		}
		desc = hold_court.6060.desc_ending
	}
	theme = court
	court_scene = {
		button_position_character = scope:6060_rich
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:6060_rich = {
				group = petitioners_group
				animation = personality_bold
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

	cooldown = { years = 20 }
	
	trigger = {
		faith = {
			trait_is_sin = drunkard		
		}
		any_held_county = {
			any_county_province = {
				hold_court_6060_valid_county_trigger = yes
			}
		}
		trigger_if = {
			limit = {
				highest_held_title_tier = tier_empire
			}
			gold < 500
		}
		trigger_if = {
			limit = {
				highest_held_title_tier = tier_kingdom
			}
			gold < 250
		}
		NOR = {
			government_has_flag = government_is_tribal
			government_has_flag = government_is_nomadic
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = 2
			gold <= 0
		}

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

	immediate = {
		random_held_county = {
			limit = {
				any_county_province = {
					hold_court_6060_valid_county_trigger = yes
				}
			}
			random_county_province = {
				limit = {
					hold_court_6060_valid_county_trigger = yes
				}
				save_scope_as = 6060_offer
			}
		}
		if = {
			limit = {
				any_knight = {
					hold_court_6060_valid_knight_trigger = yes
				}
			}
			random_knight = {
				limit = {
					hold_court_6060_valid_knight_trigger = yes
				}
				save_scope_as = 6060_rich
				court_event_character_flag_effect = yes
			}
		}
		else = {
			create_character = {
				location = root.capital_province
				template = stewardship_wealth_focus_friend_template
				trait = ambitious
				save_scope_as = 6060_rich
			}
		}
		hidden_effect = {
			scope:6060_rich = {
				court_event_character_flag_effect = yes
				add_treasury_or_gold = major_treasury_or_gold_value
			}
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	#Option A: sell the province
	option = {
		name = hold_court.6060.a
		scope:6060_rich = {
			pay_treasury_or_gold = {
				target = root
				value = major_treasury_or_gold_value
			}
		}
		if = {
			limit = {
				scope:6060_offer = {
					has_holding = no
				}
			}
			scope:6060_offer = {
				set_holding_type = castle_holding
			}
		}
		create_title_and_vassal_change = {
			type = granted
			save_scope_as = change
			add_claim_on_loss = no
		}
		scope:6060_offer = {
			barony = {
				change_title_holder = {
					holder = scope:6060_rich
					change = scope:change
				}
			}
		}
		custom_tooltip = {
			text = character_title_cannot_be_revoked_tt
			scope:6060_rich = {
				add_character_flag = {
					flag = titles_protected
					years = 25
				}
			}
		}
		resolve_title_and_vassal_change = scope:change
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = -0.25
				ai_honor = 0.25
			}
		}
	}

	#Option B: Allow it as a city
	option = {
		name = hold_court.6060.b
		scope:6060_rich = {
			pay_treasury_or_gold = {
				target = root
				value = 250
			}
		}
		if = {
			limit = {
				scope:6060_offer = {
					has_holding = no
				}
			}
			scope:6060_offer = {
				set_holding_type = city_holding
			}
		}
		create_title_and_vassal_change = {
			type = granted
			save_scope_as = change
			add_claim_on_loss = no
		}
		scope:6060_offer = {
			barony = {
				change_title_holder = {
					holder = scope:6060_rich
					change = scope:change
				}
			}
		}
		custom_tooltip = {
			text = character_title_cannot_be_revoked_tt
			scope:6060_rich = {
				add_character_flag = {
					flag = titles_protected
					years = 25
				}
			}
		}
		resolve_title_and_vassal_change = scope:change
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 0.5
				ai_boldness = 0.5
			}
			modifier = {
				has_trait = greedy
				add = 50
			}
		}
	}

	#Option C: refuse
	option = {
		name = hold_court.6060.c
		ai_chance = {
			base = 100
		}
	}

	after = {
		scope:6060_rich = {
			clear_court_event_participation = yes
			if = {
				limit = {
					is_knight = no
					is_landed = no
				}
				silent_disappearance_effect = yes
			}
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

##################################################
# Budding Ally
# by Claudia Baldassi
# 6070
##################################################

# An ally is asking you to raise their child as their guardian #

scripted_trigger hold_court_6070_valid_child_trigger = {
	has_court_event_flag = no
	is_available_ai_child = yes
	age >= 6
	age <= 12
	is_incapable = no
	is_courtier_of = prev
	is_alive = yes
	is_landed = no
}

scripted_trigger hold_court_6070_valid_friend_trigger = {
	has_court_event_flag = no
	is_available_ai_child = yes
	age >= 4
	age <= 14
	is_incapable = no
	is_alive = yes
	is_landed = no
	is_courtier_of = root
}

scripted_trigger hold_court_6070_valid_betrothed_trigger = {
	has_court_event_flag = no
	is_betrothed = no
	is_married = no
	could_marry_character_trigger = { CHARACTER = scope:6070_child }
	is_alive = yes
	is_landed = no
	is_incapable = no
	is_courtier_of = root
	basic_is_available_ai = yes
}

hold_court.6070 = {
	type = court_event
	title = hold_court.6070.t
	desc = hold_court.6070.desc
	theme = court
	court_scene = {
		button_position_character = scope:6070_embassy
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:6070_embassy = {
				group = petitioners_group
				animation = admiration
			}
			scope:6070_child = {
				group = petitioners_group
				animation = worry
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

	cooldown = { years = 15 }

	trigger = {
		is_adult = yes
		num_of_relation_ward < 2
		any_ally = {
			is_ruler = yes
			is_available_ai_adult = yes
			has_court_event_flag = no
			any_child = {
				hold_court_6070_valid_child_trigger = yes
				save_temporary_scope_as = temp_ward
			}
		}
		trigger_if = {
			limit = {
				scope:temp_ward = {
					any_relation = { type = guardian }
				}
			}
			any_ally = {
				is_ruler = yes
				is_available_ai_adult = yes
				has_court_event_flag = no
				any_child = {
					this = scope:temp_ward
				}
				any_courtier_or_guest = {
					has_relation_guardian = scope:temp_ward
					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_diplomatic }
	}

	immediate = {
		random_ally = {
			limit = {
				any_child = {
					hold_court_6070_valid_child_trigger = yes
				}
			}
			save_scope_as = 6070_sender
			court_event_character_flag_effect = yes
		}
		scope:6070_sender = {
			random_child = {
				limit = {
					hold_court_6070_valid_child_trigger = yes
				}
				save_scope_as = 6070_child
				court_event_character_flag_effect = yes
			}
		}
		if = {
			limit = {
				scope:6070_sender = {
					any_courtier = {
						has_court_event_flag = no
						is_available_healthy_ai_adult = yes
					}
				}
			}
			scope:6070_sender = {
				random_courtier = {
					limit = {
						has_court_event_flag = no
						is_available_healthy_ai_adult = yes
					}
					save_scope_as = 6070_embassy
					court_event_character_flag_effect = yes
				}
			}
		}
		else = {
			create_character = {
				location = scope:6070_sender.capital_province
				template = pool_repopulate_diplomacy
				culture = scope:6070_sender.culture
				faith = scope:6070_sender.faith
				save_scope_as = 6070_embassy
			}
			scope:6070_embassy = {
				court_event_character_flag_effect = yes
				add_character_flag = 6070_remove_char_flag
			}
		}
		if = {
			limit = {
				any_child = {
					is_heir_of = root
					hold_court_6070_valid_friend_trigger = yes
				}
			}
			random_child = {
				limit = {
					is_heir_of = root
					hold_court_6070_valid_friend_trigger = yes
				}
				save_scope_as = 6070_friend
				court_event_character_flag_effect = yes
			}
		}
		else_if = {
			limit = {
				any_child = {
					hold_court_6070_valid_friend_trigger = yes
				}
			}
			random_child = {
				limit = {
					hold_court_6070_valid_friend_trigger = yes
				}
				save_scope_as = 6070_friend
				court_event_character_flag_effect = yes
			}
		}
		if = {
			limit = {
				any_child = {
					hold_court_6070_valid_betrothed_trigger = yes
				}
			}
			random_child = {
				limit = {
					hold_court_6070_valid_betrothed_trigger = yes
				}
				save_scope_as = 6070_betrothed_temp
			}
		}
		if = {
			limit = {
				exists = scope:6070_betrothed_temp
				scope:6070_child = {
					is_betrothed = no
					could_marry_character_trigger = { CHARACTER = scope:6070_betrothed_temp }
				}
			}
			scope:6070_betrothed_temp = {
				save_scope_as = 6070_betrothed
				court_event_character_flag_effect = yes
			}
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	#Option A: Accept
	option = {
		name = hold_court.6070.a
		scope:6070_sender = {
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 30
			}
		}
		if = {
			limit = {
				scope:6070_child = {
					any_relation = { type = guardian }
				}
			}
			scope:6070_child = {
				every_relation = {
					type = guardian
					remove_guardian_effect = {
						GUARDIAN = this
						WARD = scope:6070_child
						RETURN_WARD = no
						HIDE_OPINION = no
					}
				}
			}
		}
		scope:6070_child = {
			set_relation_guardian = root
		}
		set_variable = {
			name = character_requested_as_educator
			value = root
			years = 10
		}
		set_variable = {
			name = character_making_education_request
			value = scope:6070_sender
			years = 10
		}
		if = {
			limit = {
				root != scope:6070_child.host				
			}
			root = {
				add_visiting_courtier = scope:6070_child
			}				
		}
		stress_impact = {
			shy = medium_stress_impact_gain
			reclusive = medium_stress_impact_gain
			paranoid = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_sociability = 0.25
				ai_honor = 0.25
			}
			modifier = {
				has_trait = shy
				add = -50
			}
			modifier = {
				has_trait = reclusive
				add = -50
			}
			modifier = {
				has_trait = paranoid
				add = -75
			}
		}
	}

	#Option B: Accept + encourage friendship with your child (limited if child available)
	option = {
		name = hold_court.6070.b
		trigger = {
			exists = scope:6070_friend
		}
		scope:6070_sender = {
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 35
			}
		}
		if = {
			limit = {
				scope:6070_child = {
					any_relation = { type = guardian }
				}
			}
			scope:6070_child = {
				every_relation = {
					type = guardian
					remove_guardian_effect = {
						GUARDIAN = this
						WARD = scope:6070_child
						RETURN_WARD = no
						HIDE_OPINION = no
					}
				}
			}
		}
		scope:6070_child = {
			set_relation_guardian = root
			progress_towards_friend_effect = {
				REASON = friend_childhood_new_home
 				CHARACTER = scope:6070_friend
				OPINION = 10
			}
		}
		if = {
			limit = {
				root != scope:6070_child.host				
			}
			root = {
				add_visiting_courtier = scope:6070_child
			}				
		}
		stress_impact = {
			shy = medium_stress_impact_gain
			reclusive = medium_stress_impact_gain
			paranoid = major_stress_impact_gain
		}
		ai_chance = {
			base = 150
			ai_value_modifier = {
				ai_sociability = 0.25
			}
			modifier = {
				has_trait = shy
				add = -50
			}
			modifier = {
				has_trait = reclusive
				add = -50
			}
			modifier = {
				has_trait = paranoid
				add = -75
			}
		}
	}

	#Option C: Accept + require betrothal (limited if child available)
	option = {
		name = hold_court.6070.c
		trigger = {
			exists = scope:6070_betrothed
		}
		scope:6070_sender = {
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 40
			}
		}
		if = {
			limit = {
				scope:6070_child = {
					any_relation = { type = guardian }
				}
			}
			scope:6070_child = {
				every_relation = {
					type = guardian
					remove_guardian_effect = {
						GUARDIAN = this
						WARD = scope:6070_child
						RETURN_WARD = no
						HIDE_OPINION = no
					}
				}
			}
		}
		scope:6070_child = {
			set_relation_guardian = root
			create_betrothal = scope:6070_betrothed
		}
		if = {
			limit = {
				root != scope:6070_child.host				
			}
			root = {
				add_visiting_courtier = scope:6070_child
			}				
		}
		stress_impact = {
			shy = medium_stress_impact_gain
			reclusive = medium_stress_impact_gain
			paranoid = major_stress_impact_gain
			diplomat = major_stress_impact_loss
			family_first = major_stress_impact_loss
		}
		ai_chance = {
			base = 150
			ai_value_modifier = {
				ai_sociability = 0.25
			}
			modifier = {
				has_trait = shy
				add = -50
			}
			modifier = {
				has_trait = reclusive
				add = -50
			}
			modifier = {
				has_trait = paranoid
				add = -75
			}
			modifier = {
				has_trait = diplomat
				add = 75
			}
			modifier = {
				has_trait = family_first
				add = 75
			}
		}
	}

	#Option D: Refuse
	option = {
		name = hold_court.6070.d
		scope:6070_sender = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -30
			}
		}
		stress_impact = {
			shy = medium_stress_impact_loss
			paranoid = medium_stress_impact_loss
			reclusive = medium_stress_impact_loss
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_sociability = -0.25
				ai_honor = -0.25
			}
			modifier = {
				has_trait = shy
				add = 50
			}
			modifier = {
				has_trait = reclusive
				add = 50
			}
			modifier = {
				has_trait = paranoid
				add = 75
			}
		}
	}

	#Option E: Refuse because child is a menace!
	option = {
		name = hold_court.6070.e
		trigger = {
			scope:6070_child = {
				OR = {
					has_trait = rowdy
					has_trait = bossy
					has_trait = callous
					has_trait = wrathful
					has_trait = sadistic
				}
			}
		}
		scope:6070_sender = {
			add_opinion = {
				target = root
				modifier = insult_opinion
				opinion = -50
			}
		}
		stress_impact = {
			base = medium_stress_impact_loss
		}
		ai_chance = {
			base = 150
		}
	}

	after = {
		scope:6070_sender = {
			clear_court_event_participation = yes
		}
		scope:6070_child = {
			clear_court_event_participation = yes
		}
		scope:6070_embassy = {
			clear_court_event_participation = yes
			if = {
				limit = { has_character_flag = 6070_remove_char_flag }
				silent_disappearance_effect = yes
			}
		}
		if = {
			limit = { exists = scope:6070_friend }
			scope:6070_friend = {
				clear_court_event_participation = yes
			}
		}
		if = {
			limit = { exists = scope:6070_betrothed }
			scope:6070_betrothed = {
				clear_court_event_participation = yes
			}
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

##################################################
# Settling the [people]
# by Claudia Baldassi
# 6080
##################################################

# A representative of another culture in a county you own offers to settle an unused holding. You can grant them the county, which cannot be revoked for a long while. #

scripted_trigger hold_court_6080_valid_county_trigger = {
	is_landless_type_title = no
	any_county_province = {
		has_holding = no
	}
	culture = {
		this != root.culture
	}
}

hold_court.6080 = {
	type = court_event
	title = hold_court.6080.t
	desc = hold_court.6080.desc
	theme = court
	court_scene = {
		button_position_character = scope:6080_count
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:6080_count = {
				group = petitioners_group
				animation = happiness
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

	cooldown = { years = 20 }

	trigger = {
		any_held_county = {
			hold_court_6080_valid_county_trigger = yes
		}
		government_has_flag = government_is_feudal
	}

	weight_multiplier = {
		base = 1

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

	immediate = {
		random_held_county = {
			limit = {
				hold_court_6080_valid_county_trigger = yes
			}
			save_scope_as = 6080_county
		}
		scope:6080_county.culture = {
			save_scope_as = 6080_culture
		}
		if = {
			limit = {
				any_courtier_or_guest = {
					has_court_event_flag = no
					is_available_healthy_ai_adult = yes
					culture = {
						this = scope:6080_culture
					}
				}
			}
			random_courtier_or_guest = {
				limit = {
					has_court_event_flag = no
					is_available_healthy_ai_adult = yes
					culture = {
						this = scope:6080_culture
					}
				}
				save_scope_as = 6080_count
				court_event_character_flag_effect = yes
			}
		}
		else = {
			create_character = {
				location = root.capital_province
				template = merchant_template
				culture = scope:6080_culture
				save_scope_as = 6080_count
			}
			scope:6080_count = {
				add_character_flag = 6080_remove_char_flag
				court_event_character_flag_effect = yes
			}
		}
		scope:6080_county = {
			random_county_province = {
				limit = {
					has_holding = no
				}
				save_scope_as = 6080_province
			}
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	#Option C: Grant the barony
	option = {
		name = hold_court.6080.c
		trigger = {
			has_trait = administrator
		}
		scope:6080_province = {
			set_holding_type = church_holding
		}
		create_title_and_vassal_change = {
			type = granted
			save_scope_as = change
			add_claim_on_loss = no
		}
		scope:6080_province = {
			barony = {
				change_title_holder = {
					holder = scope:6080_count
					change = scope:change
				}
			}
		}
		custom_tooltip = {
			text = character_title_cannot_be_revoked_tt
			scope:6080_count = {
				add_character_flag = {
					flag = titles_protected
					years = 25
				}
			}
		}
		resolve_title_and_vassal_change = scope:change
		scope:6080_county = {
			culture = {
				change_cultural_acceptance = {
					target = root.culture
					value = minor_cultural_acceptance_gain
					desc = cultural_acceptance_gain_hold_court_event_outcome
				}
			}
		}
		stress_impact = {
			greedy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = greedy
				add = -50
			}
		}
	}

	#Option A: Grant the county
	option = {
		name = hold_court.6080.a
		create_title_and_vassal_change = {
			type = granted
			save_scope_as = change
			add_claim_on_loss = no
		}
		scope:6080_county = {
			change_title_holder = {
				holder = scope:6080_count
				change = scope:change
			}
		}
		resolve_title_and_vassal_change = scope:change
		scope:6080_count = {
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 30
			}
			if = {
				limit = {
					government_has_flag = government_is_feudal
				}
				vassal_contract_set_obligation_level = {
					type = title_revocation_rights
					level = 1
				}
				set_subject_contract_modification_blocked = yes
			}
		}
		custom_tooltip = hold_court.6080.a.tt
		scope:6080_county = {
			culture = {
				change_cultural_acceptance = {
					target = root.culture
					value = medium_cultural_acceptance_gain
					desc = cultural_acceptance_gain_hold_court_event_outcome
				}
			}
			add_county_modifier = {
				modifier = hold_court_grateful_peasants_modifier
				years = 50
			}
			scope:6080_province = {
				random_list = {
					40 = {
						set_holding_type = city_holding
					}
					25 = {
						set_holding_type = castle_holding
					}
					15 = {
						set_holding_type = church_holding
					}
				}
			}
		}
		stress_impact = {
			greedy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = greedy
				add = -75
			}
		}
	}

	#Option B: Say no
	option = {
		name = hold_court.6080.b
		scope:6080_county = {
			change_county_control = 10
		}
		stress_impact = {
			generous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = generous
				add = -50
			}
		}
	}

	after = {
		scope:6080_count = {
			clear_court_event_participation = yes
			if = {
				limit = {
					has_character_flag = 6080_remove_char_flag
					is_landed = no
				}
				silent_disappearance_effect = yes
			}
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

##################################################
# Heretics at Large
# by Claudia Baldassi
# 6090
##################################################

# A vassal comes to you begging for help because their land is overrun by heretics/infidels. #

scripted_trigger hold_court_6090_valid_vassal_trigger = {
	has_court_event_flag = no
	is_available_ai_adult = yes
	faith = root.faith
	is_landed_or_landless_administrative = yes
	capital_county ?= {
		hold_court_6090_valid_county_trigger = yes
	}
}

scripted_trigger hold_court_6090_valid_county_trigger = {
	is_landless_type_title = no
	faith = {
		this != root.faith
		faith_hostility_level = {
			target = root.faith
			value >= faith_hostile_level
		}
	}
}

hold_court.6090 = {
	type = court_event
	title = hold_court.6090.t
	desc = {
		desc = hold_court.6090.desc
		triggered_desc = {
			trigger = {
				exists = scope:high_almoner
			}
			desc = hold_court.6090.desc.almoner
		}
		triggered_desc = {
			trigger = {
				exists = scope:executioner
			}
			desc = hold_court.6090.desc.executioner
		}
	}
	theme = court
	lower_right_portrait = scope:high_almoner
	lower_center_portrait = scope:executioner
	lower_left_portrait = scope:court_chaplain
	court_scene = {
		button_position_character = scope:6090_vassal
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:6090_vassal = {
				group = petitioners_group
				animation = beg
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

	cooldown = { years = 20 }

	trigger = {
		any_vassal = {
			hold_court_6090_valid_vassal_trigger = yes
		}
	}

	weight_multiplier = {
		base = 1

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

	immediate = {
		random_vassal = {
			limit = {
				hold_court_6090_valid_vassal_trigger = yes
			}
			save_scope_as = 6090_vassal
			court_event_character_flag_effect = yes
		}
		if = {
			limit = {
				employs_court_position = high_almoner_court_position
				any_court_position_holder = {
					type = high_almoner_court_position
					is_available_ai_adult = yes
					has_court_event_flag = no
				}
			}
			random_court_position_holder = {
				type = high_almoner_court_position
				limit = {
					is_available_ai_adult = yes
					has_court_event_flag = no
				}
				save_scope_as = high_almoner
				court_event_character_flag_effect = yes
			}
		}
		if = {
			limit = {
				employs_court_position = executioner_court_position
				any_court_position_holder = {
					type = executioner_court_position
					is_available_ai_adult = yes
					has_court_event_flag = no
				}
			}
			random_court_position_holder = {
				type = executioner_court_position
				limit = {
					is_available_ai_adult = yes
					has_court_event_flag = no
				}
				save_scope_as = executioner
				court_event_character_flag_effect = yes
			}
		}
		if = {
			limit = {
				exists = cp:councillor_court_chaplain
				cp:councillor_court_chaplain = {
					is_available_ai_adult = yes
					has_court_event_flag = no
				}
			}
			cp:councillor_court_chaplain = {
				save_scope_as = court_chaplain
				court_event_character_flag_effect = yes
			}
		}
		scope:6090_vassal = {
			capital_county = {
				save_scope_as = 6090_main_county
			}
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	#Option A: send court chaplain
	option = {
		name = hold_court.6090.a
		trigger = {
			exists = scope:court_chaplain
		}
		scope:6090_vassal = {
			every_sub_realm_county = {
				limit = {
					hold_court_6090_valid_county_trigger = yes
				}
				add_county_modifier = {
					modifier = easier_to_convert
					years = 15
				}
			}
		}
		scope:court_chaplain = {
			set_council_task = {
				task_type = task_conversion
				target = scope:6090_main_county.title_province
			}
		}
		scope:6090_vassal = {
			add_opinion = {
				target = root
				modifier = pious_opinion
				opinion = 20
			}
		}
		stress_impact = {
			cynical = medium_stress_impact_gain		
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = 1
			}
			modifier = {
				has_trait = cynical
				add = -75
			}
		}
	}

	#Option B: send the almoners
	option = {
		name = hold_court.6090.b
		trigger = {
			exists = scope:high_almoner
			trigger_if = {
				limit = {
					is_ai = yes
				}
				short_term_treasury_or_gold >= major_treasury_or_gold_value
			}
		}
		scope:6090_vassal = {
			every_sub_realm_county = {
				limit = {
					hold_court_6090_valid_county_trigger = yes
				}
				add_county_modifier = {
					modifier = easier_to_convert
					years = 15
				}
			}
		}
		remove_treasury_or_gold = medium_gold_value
		scope:6090_vassal = {
			every_sub_realm_county = {
				limit = {
					hold_court_6090_valid_county_trigger = yes
				}
				add_county_modifier = {
					modifier = court_6090_almoners_county_modifier
					years = 15
				}
			}
			add_opinion = {
				target = root
				modifier = pious_opinion
				opinion = 30
			}
		}
		scope:high_almoner = {
			add_opinion = {
				target = root
				modifier = pious_opinion
				opinion = 30
			}
		}
		stress_impact = {
			greedy = major_stress_impact_gain
		}
		change_current_court_grandeur = medium_court_grandeur_gain
		add_piety = medium_piety_gain
		ai_chance = {
			base = 200
			modifier = {
				gold < medium_gold_value
				add = -200
			}
			ai_value_modifier = {
				ai_zeal = 1
			}
			modifier = {
				has_trait = cynical
				add = -75
			}
		}
	}

	#Option C: tolerance
	option = {
		name = hold_court.6090.c
		trigger = {
			NOT = { has_trait = zealous }
		}
		scope:6090_vassal = {
			every_sub_realm_county = {
				limit = {
					hold_court_6090_valid_county_trigger = yes
				}
				add_county_modifier = {
					modifier = governance_1074_local_faith_respected_modifier
					years = 10
				}
			}
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -20
			}
		}
		custom_tooltip = {
			text = title_granted_to_local_leader_tt
			create_character = {
				template = servant_character
				location = root.location
				faith = scope:6090_main_county.faith
				culture = scope:6090_main_county.culture
				save_scope_as = new_ruler
			}
			create_title_and_vassal_change = {
				type = granted
				save_scope_as = change
				add_claim_on_loss = no
			}
			scope:6090_main_county = {
				change_title_holder = {
					holder = scope:new_ruler
					change = scope:change
				}
			}
			resolve_title_and_vassal_change = scope:change
			scope:new_ruler ?= {
				if = {
					limit = {
						government_has_flag = government_is_feudal
					}
					vassal_contract_set_obligation_level = {
						type = religious_rights
						level = 1
					}
					set_subject_contract_modification_blocked = yes
				}
			}
			add_hook = {
				target = scope:new_ruler
				type = loyalty_hook
			}
		}
		change_current_court_grandeur = minor_court_grandeur_gain
		add_prestige = medium_prestige_gain
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = -1
			}
			modifier = {
				has_trait = cynical
				add = 75
			}
		}
	}

	#Option D: send the executioners
	option = {
		name = hold_court.6090.d
		trigger = {
			exists = scope:executioner
		}
		scope:6090_vassal = {
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = 25
			}
			every_sub_realm_county = {
				limit = {
					hold_court_6090_valid_county_trigger = yes
				}
				add_county_modifier = {
					modifier = court_6090_executioners_county_modifier
					years = 5
				}
				add_county_modifier = {
					modifier = easier_to_convert
					years = 15
				}
			}
		}
		scope:executioner = {
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = 25
			}
		}
		stress_impact = {
			just = major_stress_impact_gain
			compassionate = massive_stress_impact_gain
		}
		ai_chance = {
			base = 150
			ai_value_modifier = {
				ai_zeal = 1
				ai_vengefulness = 0.5
			}
			modifier = {
				has_trait = just
				add = -75
			}
			modifier = {
				has_trait = compassionate
				add = -100
			}
			modifier = {
				has_trait = zealous
				add = 50
			}
			modifier = {
				has_trait = callous
				add = 75
			}
		}
	}

	#Option E: It's your problem
	option = {
		name = hold_court.6090.e
		scope:6090_vassal = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -30
			}
			if = {
				limit = {
					has_trait = zealous
					can_set_relation_rival_trigger = { CHARACTER = root }
				}
				progress_towards_rival_effect = {
					CHARACTER = root
					REASON = rival_province_help
					OPINION = 0
				}
			}
		}
		stress_impact = {
			lazy = medium_stress_impact_loss
			diligent = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = lazy
				add = 50
			}
			modifier = {
				has_trait = diligent
				add = -75
			}
		}
	}

	after = {
		scope:6090_vassal = {
			clear_court_event_participation = yes
		}
		if = {
			limit = { exists = scope:high_almoner }
			scope:high_almoner = {
				clear_court_event_participation = yes
			}
		}
		if = {
			limit = { exists = scope:executioner }
			scope:executioner = {
				clear_court_event_participation = yes
			}
		}
		if = {
			limit = { exists = scope:court_chaplain }
			scope:court_chaplain = {
				clear_court_event_participation = yes
			}
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

##################################################
# A Land at War
# by Claudia Baldassi
# 6100 - 6101
##################################################

# Two vassals have been waging a long inconclusive war and come to you to settle the dispute #

scripted_trigger vassal_war_char_trigger = {
	has_court_event_flag = no	
	is_at_war = yes
	is_at_war_with_liege = no
	is_available_ai_adult = yes
}

scripted_trigger vassal_war_conflict_trigger = {
	any_war_participant = {
		count = 0
		OR = {
			top_liege = this
			NOT = { is_vassal_or_below_of = root }
		}   
	}
	war_days >= 365
	attacker_war_score >= -50
	attacker_war_score <= 50
	casus_belli = {
		primary_attacker = {
			vassal_war_char_trigger = yes
			is_vassal_of = root
		}
		primary_defender = {
			vassal_war_char_trigger = yes
			is_vassal_of = root
		}
	}
}

hold_court.6100 = {
	type = court_event
	title = hold_court.6100.t
	desc = {
		desc = hold_court.6100.desc
		triggered_desc = {
			trigger = {
				exists = scope:jester
				NOR = {
					scope:6100_vassal_1 = { has_trait = lifestyle_poet }
					scope:6100_vassal_2 = { has_trait = lifestyle_poet }
				}
			}
			desc = hold_court.6100.desc.jester
		}
	}
	theme = court
	lower_center_portrait = scope:jester
	court_scene = {
		button_position_character = scope:6100_vassal_1
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:6100_vassal_1 = {
				group = petitioners_group
				animation = personality_bold
			}
			scope:6100_vassal_2 = {
				group = petitioners_group
				animation = personality_bold
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

	cooldown = { years = 10 }
	
	trigger = {
		 any_vassal = {
			vassal_war_char_trigger = yes
			any_character_war = { vassal_war_conflict_trigger = yes }
		}
	}

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

	immediate = {
		random_vassal = {
			limit = { vassal_war_char_trigger = yes }
			random_character_war = {
				limit = { vassal_war_conflict_trigger = yes }
				save_scope_as = vassal_war
			}
		}
		scope:vassal_war = {
			primary_attacker = {
				save_scope_as = 6100_vassal_1
				court_event_character_flag_effect = yes
			}
			primary_defender = {
				save_scope_as = 6100_vassal_2
				court_event_character_flag_effect = yes
		   }
		}
		if = {
			limit = {
				employs_court_position = court_jester_court_position
				any_court_position_holder = {
					type = court_jester_court_position
					has_court_event_flag = no		
					is_landed = no
					is_available_ai_adult = yes
				}
			}
			random_court_position_holder = {
				type = court_jester_court_position
				limit = {
					has_court_event_flag = no
					is_landed = no	
					is_available_ai_adult = yes
				}
				save_scope_as = jester
				court_event_character_flag_effect = yes
			}
		}
		root = {
			save_scope_as = 6100_lord
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	#Option A: Attacker is right
	option = {
		name = hold_court.6100.a
		scope:vassal_war = {
			end_war = attacker
		}
		scope:6100_vassal_1 = {
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 50
			}
		}
		scope:6100_vassal_2 = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -50
			}
		}
		ai_chance = {
			base = 100
			modifier = {
				opinion = {
					target = scope:6100_vassal_1
					value >= low_positive_opinion
				}
				opinion = {
					target = scope:6100_vassal_2
					value <= low_positive_opinion
				}
				add = 50
			}
			modifier = {
				opinion = {
					target = scope:6100_vassal_1
					value >= high_positive_opinion
				}
				opinion = {
					target = scope:6100_vassal_2
					value <= low_negative_opinion
				}
				add = 100
			}
		}
	}

	#Option B: Defender is right
	option = {
		name = hold_court.6100.b
		scope:vassal_war = {
			end_war = defender
		}
		scope:6100_vassal_2 = {
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 50
			}
		}
		scope:6100_vassal_1 = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -50
			}
		}
		ai_chance = {
			base = 100
			modifier = {
				opinion = {
					target = scope:6100_vassal_2
					value >= low_positive_opinion
				}
				opinion = {
					target = scope:6100_vassal_1
					value <= low_positive_opinion
				}
				add = 50
			}
			modifier = {
				opinion = {
					target = scope:6100_vassal_2
					value >= high_positive_opinion
				}
				opinion = {
					target = scope:6100_vassal_1
					value <= low_negative_opinion
				}
				add = 100
			}
		}
	}

	#Option C: ask for a white peace
	option = {
		name = hold_court.6100.c
		trigger = {
			NOT = { exists = scope:jester }
		}
		scope:vassal_war = {
			end_war = white_peace
		}
		scope:6100_vassal_1 = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -20
			}
		}
		scope:6100_vassal_2 = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -20
			}
		}
		add_prestige = medium_prestige_gain
		add_piety = medium_piety_gain
		stress_impact = {
			wrathful = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 0.5
			}
			modifier = {
				has_trait = wrathful
				add = -50
			}
		}
	}

	#Option D: cruel/arbitrary - throw them both in prison
	option = {
		name = hold_court.6100.d
		trigger = {
			OR = {
				has_trait = arbitrary
				has_trait = sadistic
				has_trait = paranoid
				has_trait = deceitful
				has_trait = torturer
			}
			NOT = { exists = scope:jester }
		}
		imprison_character_effect = {
			IMPRISONER = root
			TARGET = scope:6100_vassal_1
		}
		imprison_character_effect = {
			IMPRISONER = root
			TARGET = scope:6100_vassal_2
		}
		add_dread = major_dread_gain
		ai_chance = {
			base = 200
		}
	}

	#Option E: propose a duel - if possible
	option = {
		name = hold_court.6100.e
		custom_tooltip = hold_court.6100.e.tt
		trigger = {
			scope:6100_vassal_1 = {
				can_start_single_combat_trigger = yes
			}
			scope:6100_vassal_2 = {
				can_start_single_combat_trigger = yes
			}
			NOR = {
				has_trait = arbitrary
				has_trait = sadistic
				has_trait = paranoid
				has_trait = deceitful
				has_trait = torturer
			}
			NOT = { exists = scope:jester }
		}
		configure_start_single_combat_effect = {
			SC_INITIATOR = scope:6100_vassal_1
			SC_ATTACKER = scope:6100_vassal_1
			SC_DEFENDER = scope:6100_vassal_2
			FATALITY = no
			FIXED = no
			LOCALE = terrain_scope
			OUTPUT_EVENT = hold_court.6101
			INVALIDATION_EVENT = fp1_tbc.0102
		}
		add_prestige = medium_prestige_gain
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = 1
			}
		}
	}

	#Option F: jester proposes a funny solution/competition
	option = {
		name = hold_court.6100.f
		trigger = {
			exists = scope:jester
			NOR = {
				scope:6100_vassal_1 = { has_trait = lifestyle_poet }
				scope:6100_vassal_2 = { has_trait = lifestyle_poet }
			}
		}
		scope:6100_vassal_1 = {
			add_opinion = {
				target = root
				modifier = humiliated_opinion
				opinion = -75
			}
		}
		scope:6100_vassal_2 = {
			add_opinion = {
				target = root
				modifier = humiliated_opinion
				opinion = -75
			}
		}
		scope:6100_vassal_1 = {
			duel = {
				skill = diplomacy
				target = scope:6100_vassal_2
				10 = {
					desc = hold_court.6100.f.1
					compare_modifier = {
						value = scope:duel_value
						multiplier = 3
					}
					root = {
						send_interface_toast = {
							title = hold_court.6100.f.1.t
							scope:vassal_war = {
								end_war = attacker
							}
						}
					}
				}
				10 = {
					desc = hold_court.6100.f.2
					compare_modifier = {
						value = scope:duel_value
						multiplier = -3
					}
					root = {
						send_interface_toast = {
							title = hold_court.6100.f.2.t
							scope:vassal_war = {
								end_war = defender
							}
						}
					}
				}
			}
		}
		every_courtier_or_guest = {
			custom = custom.every_courtier_and_guest
			add_opinion = {
				target = root
				modifier = amused_opinion
				opinion = 10
			}
		}
		stress_impact = {
			base = medium_stress_impact_loss
		}
		ai_chance = {
			base = 150
			ai_value_modifier = {
				ai_sociability = 0.25
			}
		}
	}

	#Option G: solve your own problems
	option = {
		name = hold_court.6100.g
		custom_tooltip = hold_court.6100.g.tt
		scope:6100_vassal_1 = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -20
			}
		}
		scope:6100_vassal_2 = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -20
			}
		}
		stress_impact = {
			lazy = medium_stress_impact_loss
			content = medium_stress_impact_loss
			diligent = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = lazy
				add = 50
			}
			modifier = {
				has_trait = content
				add = 50
			}
			modifier = {
				has_trait = diligent
				add = -50
			}
			modifier = {
				has_trait = compassionate
				add = -50
			}
		}
	}

	after = {
		scope:6100_vassal_1 = {
			clear_court_event_participation = yes
		}
		scope:6100_vassal_2 = {
			clear_court_event_participation = yes
		}
		if = {
			limit = { exists = scope:jester }
			scope:jester = {
				clear_court_event_participation = yes
			}
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

hold_court.6101 = {
	hidden = yes

	immediate = {
		scope:6100_lord = {
			send_interface_toast = {
				title = hold_court.6101.t
				left_icon = scope:sc_victor
				right_icon = scope:sc_loser
				custom_tooltip = hold_court.6101.tt
			}
		}

		if = {
			limit = {
				scope:sc_victor = {
					this = scope:6100_vassal_1
				}
			}
			scope:vassal_war = {
				end_war = attacker
			}
			scope:6100_vassal_1 = {
				add_prestige = medium_prestige_gain
			}
		}
		else = {
			scope:vassal_war = {
				end_war = defender
			}
			scope:6100_vassal_2 = {
				add_prestige = medium_prestige_gain
			}
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}
}

##################################################
# A Ravaged Land
# by Claudia Baldassi
# 6110
##################################################

# Two vassals are fighting a bitter & bloody war, with the land/peasants suffering as it rages onwards. The peasants come to complain and ask for a peaceful solution #

scripted_trigger hold_court_6110_valid_pool_character_trigger = {
	has_court_event_flag = no
	is_available_ai_adult = yes
	is_lowborn = yes
	OR = {
		faith = scope:6110_vassal_1.capital_county.faith
		faith = scope:6110_vassal_2.capital_county.faith
	}
	OR = {
		culture = scope:6110_vassal_1.capital_county.culture
		culture = scope:6110_vassal_2.capital_county.culture
	}
}

hold_court.6110 = {
	type = court_event
	title = hold_court.6110.t
	desc = {
		desc = hold_court.6110.desc
		triggered_desc = {
			trigger = {
				exists = scope:almoner
			}
			desc = hold_court.6110.desc.almoner
		}
	}
	theme = court
	lower_left_portrait = scope:6110_vassal_1
	lower_center_portrait = scope:6110_vassal_2
	court_scene = {
		button_position_character = scope:6110_rep
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:6110_rep = {
				group = petitioners_group
				animation = beg
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

	cooldown = { years = 10 }

	trigger = {
		 any_vassal = {
			vassal_war_char_trigger = yes
			any_character_war = { vassal_war_conflict_trigger = yes }
		}
	}

	weight_multiplier = {
		base = 1

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

	immediate = {
		random_vassal = {
			limit = { vassal_war_char_trigger = yes }
			random_character_war = {
				limit = { vassal_war_conflict_trigger = yes }
				save_scope_as = vassal_war
			}
		}
		scope:vassal_war = {
			primary_attacker = {
		   		save_scope_as = 6110_vassal_1
		   		court_event_character_flag_effect = yes
		   	}
			primary_defender = {
				save_scope_as = 6110_vassal_2
				court_event_character_flag_effect = yes
			}
		}
		if = {
			limit = {
				any_pool_character = {
					province = root.capital_province
					hold_court_6110_valid_pool_character_trigger = yes
				}
			}
			random_pool_character = {
				province = root.capital_province
				limit = {
					hold_court_6110_valid_pool_character_trigger = yes
				}
				save_scope_as = 6110_rep
			}
		}
		else = {
			create_character = {
				location = root.capital_province
				template = servant_character
				faith = scope:6110_vassal_2.capital_county.faith
				culture = scope:6110_vassal_2.capital_county.culture
				save_scope_as = 6110_rep
			}
			scope:6110_rep = {
				add_character_flag = 6110_remove_char_flag
			}
		}
		scope:6110_rep = {
			court_event_character_flag_effect = yes
		}
		hidden_effect = { add_courtier = scope:6110_rep }
		if = {
			limit = {
				employs_court_position = high_almoner_court_position
				any_court_position_holder = {
					type = high_almoner_court_position
					has_court_event_flag = no
					is_available_ai_adult = yes
				}
			}
			random_court_position_holder = {
				type = high_almoner_court_position
				limit = {
					has_court_event_flag = no
					is_available_ai_adult = yes
				}
				save_scope_as = almoner
				court_event_character_flag_effect = yes
			}
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	#Option A: decree ceasefire (enforce demands)
	option = {
		name = hold_court.6110.a
		scope:vassal_war = {
			end_war = attacker
		}
		scope:6110_vassal_1 = {
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 30
			}
			every_sub_realm_county = {
				custom = 6110_custom_every_realm_1
				change_county_control = 15
			}
		}
		scope:6110_vassal_2 = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -30
			}
			every_sub_realm_county = {
				custom = 6110_custom_every_realm_2
				change_county_control = 15
			}
		}
		ai_chance = {
			base = 100
			modifier = {
				gold < medium_gold_value
				add = -100
			}
			modifier = {
				has_trait = profligate
				add = 75
			}
			modifier = {
				has_trait = improvident
				add = 75
			}
			modifier = {
				has_trait = greedy
				add = -75
			}
			ai_value_modifier = {
				ai_greed = 0.5
			}
		}
	}

	#Option B: decree ceasefire (white peace)
	option = {
		name = hold_court.6110.b
		scope:vassal_war = {
			end_war = white_peace
		}
		scope:6110_vassal_1 = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -15
			}
			every_sub_realm_county = {
				custom = 6110_custom_every_realm_1
				change_county_control = 15
			}
		}
		scope:6110_vassal_2 = {
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 15
			}
			every_sub_realm_county = {
				custom = 6110_custom_every_realm_2
				change_county_control = 15
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 0.5
			}
			modifier = {
				has_trait = wrathful
				add = -50
			}
		}
	}

	#Option C: decree ceasefire (surrender)
	option = {
		name = hold_court.6110.c
		scope:vassal_war = {
			end_war = defender
		}
		scope:6110_vassal_1 = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -30
			}
			every_sub_realm_county = {
				custom = 6110_custom_every_realm_1
				change_county_control = 15
			}
		}
		scope:6110_vassal_2 = {
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 30
			}
			every_sub_realm_county = {
				custom = 6110_custom_every_realm_2
				change_county_control = 15
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 0.5
			}
			modifier = {
				has_trait = wrathful
				add = -50
			}
		}
	}

	#Option E: don't meddle
	option = {
		name = hold_court.6110.e
		scope:6110_vassal_1 = {
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 5
			}
			every_sub_realm_county = {
				custom = 6110_custom_every_realm_1
				change_county_control = -5
			}
		}
		scope:6110_vassal_2 = {
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 5
			}
			every_sub_realm_county = {
				custom = 6110_custom_every_realm_2
				change_county_control = 5
			}
		}
		ai_chance = {
			base = 100
		}
	}

	after = {
		scope:6100_vassal_1 = {
			clear_court_event_participation = yes
		}
		scope:6100_vassal_2 = {
			clear_court_event_participation = yes
		}
		scope:6110_rep = {
			clear_court_event_participation = yes
			if = {
				limit = {
					has_character_flag = 6110_remove_char_flag
					is_imprisoned = no
				}
				silent_disappearance_effect = yes
			}
		}
		if = {
			limit = { exists = scope:almoner }
			scope:almoner = {
				clear_court_event_participation = yes
			}
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

##################################################
# The Day of Truth
# by Claudia Baldassi
# 6120 - 6121
##################################################

# Your steward requires you to invest in a large-scale survey of your kingdom and people to make taxation more efficient (think Domesday Book) #

scripted_effect hold_court_6120_rewards = {
	every_sub_realm_county = {
		custom = all_realm_county
		change_county_control = 20
	}
	if = {
		limit = {
			any_court_position_holder = {
				type = seneschal_court_position
			}
		}
		add_character_modifier = {
			modifier = 6121_seneschal_domesday_modifier
			years = 30
		}
	}
	else = {
		add_character_modifier = {
			modifier = 6121_steward_domesday_modifier
			years = 30
		}
	}
}

hold_court.6120 = {
	type = court_event
	title = hold_court.6120.t
	desc = {
		desc = hold_court.6120.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:keeper_swans
				}
				desc = hold_court.6120.desc.swans
			}
			triggered_desc = {
				trigger = {
					exists = scope:seneschal
				}
				desc = hold_court.6120.desc.seneschal
			}
		}
		triggered_desc = {
			trigger = {
				exists = scope:jester
			}
			desc = hold_court.6120.desc.jester
		}
	}
	theme = court
	lower_left_portrait = scope:seneschal
	lower_center_portrait = scope:keeper_swans
	lower_right_portrait = scope:jester
	cooldown = { years = 10 }
	court_scene = {
		button_position_character = scope:steward
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:steward = {
				group = petitioners_group
				animation = personality_rational
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

	trigger = {
		exists = cp:councillor_steward
		cp:councillor_steward = {
			has_court_event_flag = no
			is_available_ai_adult = yes
		}
		NOT = { #not using cooldown because the cooldown is only valid if you do the survey
			has_character_flag = 6120_has_domesday_book_flag
		}
	}

	weight_multiplier = {
		base = 1

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

	immediate = {
		cp:councillor_steward = {
			save_scope_as = steward
			court_event_character_flag_effect = yes
		}
		if = {
			limit = {
				employs_court_position = keeper_of_swans_court_position
				any_court_position_holder = {
					type = keeper_of_swans_court_position
					has_court_event_flag = no
					is_available_ai_adult = yes
				}
			}
			random_court_position_holder = {
				type = keeper_of_swans_court_position
				limit = {
					has_court_event_flag = no
					is_available_ai_adult = yes
				}
				save_scope_as = keeper_swans
				court_event_character_flag_effect = yes
			}
		}
		else_if = {
			limit = {
				employs_court_position = seneschal_court_position
				any_court_position_holder = {
					type = seneschal_court_position
					has_court_event_flag = no
					is_available_ai_adult = yes
				}
			}
			random_court_position_holder = {
				type = seneschal_court_position
				limit = {
					has_court_event_flag = no
					is_available_ai_adult = yes
				}
				save_scope_as = seneschal
				court_event_character_flag_effect = yes
			}
		}
		if = {
			limit = {
				employs_court_position = court_jester_court_position
				any_court_position_holder = {
					type = court_jester_court_position
					has_court_event_flag = no
					is_available_ai_adult = yes
					is_landed = no
				}
			}
			random_court_position_holder = {
				type = court_jester_court_position
				limit = {
					has_court_event_flag = no
					is_available_ai_adult = yes
					is_landed = no
				}
				save_scope_as = jester
				court_event_character_flag_effect = yes
			}
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	#Option A: yes
	option = {
		name = hold_court.6120.a
		trigger = {
			NOT = { exists = scope:seneschal }
			trigger_if = {
				limit = {
					is_ai = yes
				}
				short_term_treasury_or_gold >= major_treasury_or_gold_value
			}
		}
		remove_treasury_or_gold = major_treasury_or_gold_value
		add_character_flag = {
			flag = 6120_has_domesday_book_flag
			years = 50
		}
		show_as_tooltip = {
			random_list = {
				100 = {
					show_chance = no
					desc = hold_court.6120.a.tt
					hold_court_6120_rewards = yes
				}
			}
		}
		hidden_effect = {
			scope:steward = {
				add_opinion = {
					target = root
					modifier = pleased_opinion
					opinion = 20
				}
			}
			trigger_event = {
				id = hold_court.6121
				days = 185
			}
		}
		stress_impact = {
			lazy = major_stress_impact_gain
			content = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				gold < major_gold_value
				add = -100
			}
			ai_value_modifier = {
				ai_energy = 0.25
				ai_rationality = 0.5
				ai_greed = -0.25
			}
			modifier = {
				has_trait = lazy
				add = -75
			}
			modifier = {
				has_trait = content
				add = -75
			}
		}
	}

	#Option C: did you say TAXES??
	option = {
		name = hold_court.6120.c
		every_vassal = {
			limit = {
				is_ai = yes
			}
			custom = 6120_every_vassal
			pay_treasury_or_gold = {
 				target = root
 				value = tiny_treasury_or_gold_value
 			}
		}
		add_character_modifier = {
			modifier = 6120_extra_taxes_modifier
			years = 10
		}
		stress_impact = {
			generous = major_stress_impact_gain
			compassionate = major_stress_impact_gain
			just = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = generous
				add = -75
			}
			modifier = {
				has_trait = compassionate
				add = -75
			}
			modifier = {
				has_trait = just
				add = -75
			}
			ai_value_modifier = {
				ai_greed = -0.5
			}
		}
	}

	#Option D: no
	option = {
		name = hold_court.6120.d
		trigger = {
			NOT = { exists = scope:jester }
		}
		stress_impact = {
			ambitious = medium_stress_impact_gain
			diligent = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = ambitious
				add = -50
			}
			modifier = {
				has_trait = diligent
				add = -75
			}
		}
	}

	#Option E: no but with jester
	option = {
		name = hold_court.6120.e
		trigger = {
			exists = scope:jester
		}
		scope:jester = {
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 30
			}
		}
		stress_impact = {
			ambitious = major_stress_impact_gain
			diligent = massive_stress_impact_gain
		}
		ai_chance = {
			base = 150
			modifier = {
				has_trait = ambitious
				add = -50
			}
			modifier = {
				has_trait = diligent
				add = -75
			}
		}
	}

	after = {
		scope:steward = {
			clear_court_event_participation = yes
		}
		if = {
			limit = { exists = scope:keeper_swans }
			scope:keeper_swans = {
				clear_court_event_participation = yes
			}
		}
		if = {
			limit = { exists = scope:seneschal }
			scope:seneschal = {
				clear_court_event_participation = yes
			}
		}
		if = {
			limit = { exists = scope:jester }
			scope:jester = {
				clear_court_event_participation = yes
			}
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

hold_court.6121 = {
	type = character_event
	title = hold_court.6121.t
	desc = hold_court.6121.desc
	theme = court
	left_portrait = {
		character = root
		animation = happiness
	}
	right_portrait = {
		character = scope:6121_responsible
		animation = personality_rational
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

	trigger = {
		OR = {
			AND = {
				exists = cp:councillor_steward
				cp:councillor_steward = {
					is_available_ai_adult = yes
				}
			}
			AND = {
				employs_court_position = seneschal_court_position
				any_court_position_holder = {
					type = seneschal_court_position
					is_available_ai_adult = yes
				}
			}
		}
	}

	immediate = {
		if = {
			limit = {
				employs_court_position = seneschal_court_position
				any_court_position_holder = {
					type = seneschal_court_position
					is_available_ai_adult = yes
				}
			}
			random_court_position_holder = {
				type = seneschal_court_position
				limit = { is_available_ai_adult = yes }
				save_scope_as = 6121_responsible
			}
		}
		else = {
			cp:councillor_steward = {
				save_scope_as = 6121_responsible
			}
		}
	}

	option = {
		name = hold_court.6121.a
		hold_court_6120_rewards = yes
	}
}

##################################################
# The Cadastre
# by Claudia Baldassi
# 6130
##################################################

# Someone suggests a "cadastral survey" - high cost for an increase of development in all counties you hold #

scripted_trigger hold_court_6130_valid_child_trigger = {
	has_court_event_flag = no
	is_courtier_of = root
	age >= 11
	is_available_ai_child = yes
}

scripted_effect hold_court_6130_a_rewards = {
	if = {
		limit = {
			OR = {
				has_character_flag = 6130_seneschal_assigned
				has_character_flag = 6131_seneschal_assigned
			}
		}
		every_held_county = {
			custom = custom.every_held_county
			change_development_progress_with_overflow = 50
		}
	}
	else_if = {
		limit = {
			OR = {
				has_character_flag = 6130_steward_assigned
				has_character_flag = 6131_steward_assigned
			}
		}
		every_held_county = {
			custom = custom.every_held_county
			change_development_progress_with_overflow = 35
		}
	}
	scope:6130_proposer = {
		add_prestige = minor_prestige_gain
	}
	every_held_county = {
		custom = custom.every_held_county
		add_county_modifier = {
			modifier = 6131_mapped_wilderness_county_modifier
			years = 10
		}
	}
	add_prestige = medium_prestige_gain
}

hold_court.6130 = {
	type = court_event
	title = hold_court.6130.t
	desc = hold_court.6130.desc
	theme = court
	lower_left_portrait = scope:tutor
	lower_center_portrait = scope:m_hunt
	cooldown = { years = 10 }
	court_scene = {
		button_position_character = scope:6130_proposer
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:6130_proposer = {
				group = petitioners_group
				animation = personality_rational
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

	trigger = {
		exists = cp:councillor_steward
		cp:councillor_steward = {
			has_court_event_flag = no
			is_available_ai_adult = yes
		}
		NOT = {	# not cooldown because it's only valid if you do the cadastre
			has_character_flag = 6130_has_done_cadastre
		}
	}

	weight_multiplier = {
		base = 1

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

	immediate = {
		if = {
			limit = {
				employs_court_position = seneschal_court_position
				any_court_position_holder = {
					type = seneschal_court_position
					has_court_event_flag = no
					is_available_ai_adult = yes
				}
			}
			random_court_position_holder = {
				type = seneschal_court_position
				limit = {
					has_court_event_flag = no
					is_available_ai_adult = yes
				}
				save_scope_as = 6130_proposer
				save_scope_as = seneschal
				court_event_character_flag_effect = yes
			}
			add_character_flag = {
				flag = 6130_seneschal_assigned
				months = 6
			}
		}
		else = {
			cp:councillor_steward = {
				save_scope_as = 6130_proposer
				court_event_character_flag_effect = yes
			}
			add_character_flag = {
				flag = 6130_steward_assigned
				days = 180
			}
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	#Option A: yes
	option = {
		name = hold_court.6130.a
		remove_treasury_or_gold = major_treasury_or_gold_value
		show_as_tooltip = {
			random_list = {
				100 = {
					show_chance = no
					desc = hold_court.6130.a.tt
					hold_court_6130_a_rewards = yes
				}
			}
		}
		hidden_effect = {
			trigger_event = {
				id = hold_court.6131
				days = { 93 171 }
			}
			add_character_flag = {
				flag = 6130_has_done_cadastre
				years = 20
			}
		}
		stress_impact = {
			lazy = minor_stress_gain
			greedy = medium_stress_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = lazy
				add = -50
			}
			modifier = {
				has_trait = greedy
				add = -75
			}
			modifier = {
				gold < major_treasury_or_gold_value
				factor = 0
			}
			ai_value_modifier = {
				ai_greed = -0.25
				ai_rationality = 0.25
			}
		}
	}

	#Option D: no
	option = {
		name = hold_court.6130.d
		scope:6130_proposer = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -20
			}
		}
		if = {
			limit = {
				has_character_flag = 6130_seneschal_assigned
			}
			remove_character_flag = 6130_seneschal_assigned
		}
		if = {
			limit = {
				has_character_flag = 6130_steward_assigned
			}
			remove_character_flag = 6130_steward_assigned
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_energy = -0.25
			}
			modifier = {
				gold < major_gold_value
				add = 100
			}
		}
	}

	after = {
		scope:6130_proposer = {
			clear_court_event_participation = yes
		}
		if = {
			limit = { exists = scope:m_hunt }
			scope:m_hunt = {
				clear_court_event_participation = yes
			}
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

hold_court.6131 = {
	type = character_event
	title = hold_court.6131.t
	desc = hold_court.6131.desc
	theme = court
	right_portrait = {
		character = scope:6131_proposer
		animation = personality_rational
	}

	trigger = {
		trigger_if = {
			limit = {
				scope:6130_proposer = { is_alive = no }
			}
			OR = {
				exists = cp:councillor_steward
				any_court_position_holder = {
					type = seneschal_court_position
				}
			}
		}
	}

	immediate = {
		if = {
			limit = {
				scope:6130_proposer = { is_alive = yes }
			}
			scope:6130_proposer = {
				save_scope_as = 6131_proposer
			}
		}
		else_if = {
			limit = {
				any_court_position_holder = {
					type = seneschal_court_position
				}
			}
			random_court_position_holder = {
				type = seneschal_court_position
				save_scope_as = 6131_proposer
			}
			add_character_flag = {
				flag = 6131_seneschal_assigned
				days = 3
			}
		}
		else = {
			cp:councillor_steward = {
				save_scope_as = 6131_proposer
			}
			add_character_flag = {
				flag = 6131_steward_assigned
				days = 3
			}
		}
		if = {
			limit = {
				scope:6130_proposer = {
					is_alive = no
				}
			}
			if = {
				limit = {
					has_character_flag = 6130_seneschal_assigned
				}
				remove_character_flag = 6130_seneschal_assigned
			}
			if = {
				limit = {
					has_character_flag = 6130_steward_assigned
				}
				remove_character_flag = 6130_steward_assigned
			}
		}
	}

	option = {
		name = hold_court.6131.a
		hold_court_6130_a_rewards = yes
	}
}

##################################################
# A Cumbersome Gift
# by Claudia Baldassi
# 6140
##################################################

# A vassal offers you a bear/tiger/lion. Do you keep it for entertainment, kill it for a soft carpet, or...? If you keep it to show off during banquets, something might happen, good or bad! #

scripted_trigger hold_court_6140_valid_vassal_trigger = {
	has_court_event_flag = no
	opinion = {
		target = root
		value >= 50
	}
	is_available_healthy_ai_adult = yes
	any_held_county = {
		title_province = {
			OR = {
				hold_court_6140_europe_trigger = yes
				hold_court_6140_india_trigger = yes
				hold_court_6140_africa_trigger = yes
			}
		}
	}
}

scripted_trigger hold_court_6140_europe_trigger = {
	terrain = forest
	geographical_region = world_europe
}

scripted_trigger hold_court_6140_india_trigger = {
	terrain = jungle
	geographical_region = world_india
}

scripted_trigger hold_court_6140_africa_trigger = {
	OR = {
		terrain = jungle
		terrain = desert_mountains
		terrain = oasis
		terrain = drylands
	}
	geographical_region = world_africa
}

hold_court.6140 = {
	type = court_event
	title = hold_court.6140.t
	desc = hold_court.6140.desc
	theme = court
	lower_right_portrait = scope:jester
	court_scene = {
		button_position_character = scope:6140_gifter
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:6140_gifter = {
				group = petitioners_group
				animation = happiness
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

	cooldown = { years = 20 }
	
	trigger = {
		any_vassal = {
			hold_court_6140_valid_vassal_trigger = yes
		}
	}

	weight_multiplier = {
		base = 1

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

	immediate = {
		random_vassal = {
			limit = {
				hold_court_6140_valid_vassal_trigger = yes
			}
			save_scope_as = 6140_gifter
			court_event_character_flag_effect = yes
			random_held_county = {
				limit = {
					title_province = {
						OR = {
							hold_court_6140_europe_trigger = yes
							hold_court_6140_india_trigger = yes
							hold_court_6140_africa_trigger = yes
						}
					}
				}
				save_scope_as = location
				title_province = {
					save_scope_as = 6140_province
				}
			}
		}
		if = {
			limit = {
				employs_court_position = court_jester_court_position
				any_court_position_holder = {
					type = court_jester_court_position
					has_court_event_flag = no
					is_available_healthy_ai_adult = yes
				}
			}
			random_court_position_holder = {
				type = court_jester_court_position
				limit = {
					has_court_event_flag = no
					is_available_healthy_ai_adult = yes
				}
				save_scope_as = jester
			}
		}
		hunt_activity_dangerous_game_effect = { PROVINCE = scope:6140_province }
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	#Option A: Kill it for pelt (chance to get an artifact)
	option = {
		name = hold_court.6140.a
		custom_tooltip = hold_court.6140.a.tt
		random_list = {
			80 = {
				add_character_modifier = {
					modifier = 6140_new_carpet_modifier
					years = 50
				}
			}
			20 = {
				create_artifact_animal_hide_effect = {
					OWNER = root
					HUNTER = root
					LEGENDARY = no
					ANIMAL = root.var:animal_type
				}
				if = {
					limit = { exists = scope:newly_created_artifact }
					scope:newly_created_artifact = { save_scope_as = pelt }
					send_interface_toast = {
						title = hold_court.6140.artifact_toast
						left_icon = scope:pelt
						show_as_tooltip = {
							scope:pelt = { set_owner = root }
						}
					}
				}
				custom_tooltip = hold_court.6140.artifact_tt
			}
		}
		change_current_court_grandeur = minor_court_grandeur_gain
		ai_chance = {
			base = 100
		}
	}

	#Option B: Keep it as pet 
	option = {
		name = hold_court.6140.b
		change_current_court_grandeur = monumental_court_grandeur_gain
		add_character_modifier = {
			modifier = 6140_pet_modifier
			years = 10
		}
		ai_chance = {
			base = 100
		}
	}

	#Option C: if you have a jester
	option = {
		name = hold_court.6140.c
		trigger = {
			exists = scope:jester
		}
		change_current_court_grandeur = medium_court_grandeur_gain
		reverse_add_opinion = {
			target = scope:jester
			modifier = scared_opinion
			opinion = -30
		}
		add_character_modifier = {
			modifier = 6140_pet_modifier
			years = 10
		}
		every_courtier_or_guest = {
			custom = 6140_every_courtier_or_guest
			add_opinion = {
				target = root
				modifier = amused_opinion
				opinion = 10
			}
		}
		scope:jester = {
			duel = {
				skill = prowess
				value = average_skill_rating
				50 = {		#Success!
					compare_modifier = {
						value = scope:duel_value
						multiplier = 4
						min = -50
					}
					desc = hold_court.6140.c.success
					root = {
						send_interface_toast = {
							title = hold_court.6140.c.success.tt
							left_icon = scope:jester
							every_courtier_or_guest = {
								custom = 6140_every_courtier_or_guest
								add_opinion = {
									target = scope:jester
									modifier = impressed_opinion
									opinion = 20
								}
							}
						}
					}
				}
				30 = {		#Soft failure
					compare_modifier = {
						value = scope:duel_value
						multiplier = 1
						min = -20
					}
					desc = hold_court.6140.c.soft_failure
					root = {
						send_interface_toast = {
							title = hold_court.6140.c.soft_failure.tt
							left_icon = scope:jester
							every_courtier_or_guest = {
								custom = 6140_every_courtier_or_guest
								add_opinion = {
									target = scope:jester
									modifier = amused_opinion
									opinion = 10
								}
							}
						}
					}
				}
				15 = {		#Middle failure
					compare_modifier = {
						value = scope:duel_value
						multiplier = -2
						min = -20
					}
					desc = hold_court.6140.c.middle_failure
					root = {
						send_interface_toast = {
							title = hold_court.6140.c.middle_failure.tt
							left_icon = scope:jester
							scope:jester = {
								random_list = {
									30 = {
										apply_maimed_trait_and_modifier_effect = yes
									}
									30 = {
										add_trait = one_legged
									}
									30 = {
										add_trait = disfigured
									}
								}
							}
						}
					}
				}
				5 = {		#Hard failure
					compare_modifier = {
						value = scope:duel_value
						multiplier = -1
						min = -1
					}
					desc = hold_court.6140.c.hard_failure
					root = {
						send_interface_toast = {
							title = hold_court.6140.c.hard_failure.tt
							left_icon = scope:jester
							scope:jester = {
								death = {
									death_reason = death_riding_animal
								}
							}
						}
					}
				}
			}
		}
		ai_chance = {
			base = 120
			ai_value_modifier = {
				ai_compassion = -0.25
				ai_sociability = 0.25
			}
		}
	}

	#Option D: if you are a torturer
	option = {
		name = hold_court.6140.d
		trigger = {
			OR = {
				has_trait = torturer
				has_trait = callous
				has_trait = sadistic
			}
		}
		trait = torturer
		trait = callous
		trait = sadistic
		add_character_modifier = {
			modifier = 6140_pet_modifier
			years = 10
		}
		every_prisoner = {
			custom = 6140_every_prisoner
			add_opinion = {
				target = root
				modifier = scared_opinion
				opinion = -50
			}
			add_character_modifier = 6140_animal_guardian_modifier
		}
		ai_chance = {
			base = 150
		}
	}

	#Option E: Turn it away
	option = {
		name = hold_court.6140.e
		reverse_add_opinion = {
			target = scope:6140_gifter
			modifier = insult_opinion
			opinion = -40
		}		
		ai_chance = {
			base = 75
		}
	}

	after = {
		remove_variable = animal_type
		scope:6140_gifter = {
			clear_court_event_participation = yes
		}
		if = {
			limit = { exists = scope:jester }
			scope:jester = {
				clear_court_event_participation = yes
			}
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

#feast events: 
# -host-only - you bring in the beast: you/someone gets hurt or killed, your master of the hunt intervenes, jester rides it, you intimidate your enemies, all guests are impressed (if no one dies)
# -host-triggered - the host brings in the beast: you are scared/impressed, you/someone gets hurt or killed, master of the hunt of host intervenes, jester rides it

##################################################
# Empty Coffers
# by Claudia Baldassi
# 6160
##################################################

# A vassal is bankrupt and is asking for money to be bailed out. #

scripted_trigger hold_court_6160_valid_bankrupt_vassal_trigger = {
	has_court_event_flag = no
	is_available_ai_adult = yes
	gold < 0
}

scripted_trigger hold_court_6160_valid_hook_trigger = {
	OR = {
		has_hook_of_type = {
			type = indebted_hook
			target = root
		}
		has_hook_of_type = {
			type = favor_hook
			target = root
		}
	}
}

scripted_trigger hold_court_6160_valid_friend_trigger = {
	has_court_event_flag = no
	is_available_ai_adult = yes
	OR = {
		has_any_good_relationship_with_root_trigger = yes
		is_child_of = root
		has_relation_best_friend = root
		has_relation_soulmate = root
		is_close_family_of = root
	}
}

hold_court.6160 = {
	type = court_event
	title = hold_court.6160.t
	desc = {
		desc = hold_court.6160.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:6160_vassal = { hold_court_6160_valid_friend_trigger = yes }
				}
				desc = hold_court.6160.desc_friend
			}
			triggered_desc = {
				trigger = {
					scope:6160_vassal = { hold_court_6160_valid_hook_trigger = yes }
				}
				desc = hold_court.6160.desc_hook
			}
			desc = hold_court.6160.desc_fallback
		}
	}
	theme = court
	lower_left_portrait = scope:almoner
	lower_center_portrait = scope:seneschal
	court_scene = {
		button_position_character = scope:6160_vassal
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:6160_vassal = {
				group = petitioners_group
				animation = beg
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

	cooldown = { years = 15 }
	
	trigger = {
		any_vassal = { hold_court_6160_valid_bankrupt_vassal_trigger = yes }
	}

	weight_multiplier = {
		base = 1
		modifier = {
			factor = 3
			any_vassal = {
				hold_court_6160_valid_bankrupt_vassal_trigger = yes
				hold_court_6160_valid_hook_trigger = yes
			}
		}
		modifier = {
			factor = 2
			any_vassal = {
				hold_court_6160_valid_bankrupt_vassal_trigger = yes
				hold_court_6160_valid_friend_trigger = yes
			}
		}
		modifier = {
			factor = 0.1
			gold < 0
		}

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

	immediate = {
		if = {
			limit = {
				any_vassal = {
					hold_court_6160_valid_bankrupt_vassal_trigger = yes
					hold_court_6160_valid_hook_trigger = yes
				}
			}
			random_vassal = {
				limit = {
					hold_court_6160_valid_bankrupt_vassal_trigger = yes
					hold_court_6160_valid_hook_trigger = yes
				}
				save_scope_as = 6160_vassal
			}
		}
		else_if = {
			limit = {
				any_vassal = {
					hold_court_6160_valid_bankrupt_vassal_trigger = yes
					hold_court_6160_valid_friend_trigger = yes
				}
			}
			random_vassal = {
				limit = {
					hold_court_6160_valid_bankrupt_vassal_trigger = yes
					hold_court_6160_valid_friend_trigger = yes
				}
				save_scope_as = 6160_vassal
			}
		}
		else = {
			random_vassal = {
				limit = { hold_court_6160_valid_bankrupt_vassal_trigger = yes }
				save_scope_as = 6160_vassal
			}
		}
		scope:6160_vassal = {
			court_event_character_flag_effect = yes
		}
		if = {
			limit = {
				employs_court_position = high_almoner_court_position
				any_court_position_holder = {
					type = high_almoner_court_position
					has_court_event_flag = no
					is_available_ai_adult = yes
 				}
 			}
 			random_court_position_holder = {
 				type = high_almoner_court_position
 				limit = {
 					has_court_event_flag = no
 					is_available_ai_adult = yes
 				}
 				save_scope_as = almoner
 				court_event_character_flag_effect = yes
 			}
		}
		if = {
			limit = {
				employs_court_position = seneschal_court_position
				any_court_position_holder = {
					type = seneschal_court_position
					has_court_event_flag = no
					is_available_ai_adult = yes
 				}
 			}
 			random_court_position_holder = {
 				type = seneschal_court_position
 				limit = {
 					has_court_event_flag = no
 					is_available_ai_adult = yes
 				}
 				save_scope_as = seneschal
 				court_event_character_flag_effect = yes
 			}
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	#Option A: money for new hook
	option = {
		name = hold_court.6160.a
		trigger = {
			NOT = {
				scope:6160_vassal = {
					hold_court_6160_valid_hook_trigger = yes
				}
			}
			trigger_if = {
				limit = {
					is_ai = yes
				}
				short_term_gold >= major_gold_value
			}
		}
		pay_short_term_gold = {
			target = scope:6160_vassal
			gold = medium_gold_value
		}
		add_hook = {
			type = indebted_hook
			target = scope:6160_vassal
		}
		reverse_add_opinion = {
			target = scope:6160_vassal
			modifier = grateful_opinion
			opinion = 20
		}
		stress_impact = {
			greedy = medium_stress_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				gold < medium_gold_value
				add = -95
			}
			modifier = {
				has_trait = greedy
				add = -50
			}
			ai_value_modifier = {
				ai_greed = -0.25
			}
		}
	}

	#Option B: gold for old hook
	option = {
		name = hold_court.6160.b
		trigger = {
			scope:6160_vassal = {
				hold_court_6160_valid_hook_trigger = yes
			}
			trigger_if = {
				limit = {
					is_ai = yes
				}
				short_term_gold >= major_gold_value
			}
		}
		scope:6160_vassal = {
			remove_hook = { target = root }
		}
		pay_short_term_gold = {
			target = scope:6160_vassal
			gold = medium_gold_value
		}
		reverse_add_opinion = {
			target = scope:6160_vassal
			modifier = grateful_opinion
			opinion = 30
		}
		stress_impact = {
			greedy = medium_stress_gain
		}
		ai_chance = {
			base = 120
			modifier = {
				gold < medium_gold_value
				add = -95
			}
			modifier = {
				has_trait = greedy
				add = -50
			}
			ai_value_modifier = {
				ai_greed = -0.25
				ai_honor = 0.25
			}
		}
	}

	#Option C: gold for friend
	option = {
		name = hold_court.6160.c
		trigger = {
			scope:6160_vassal = {
				hold_court_6160_valid_friend_trigger = yes
				NOT = {
					hold_court_6160_valid_hook_trigger = yes
				}
			}
			trigger_if = {
				limit = {
					is_ai = yes
				}
				short_term_gold >= major_gold_value
			}
		}
		pay_short_term_gold = {
			target = scope:6160_vassal
			gold = medium_gold_value
		}
		add_prestige = major_prestige_gain
		change_current_court_grandeur = medium_court_grandeur_gain
		reverse_add_opinion = {
			target = scope:6160_vassal
			modifier = grateful_opinion
			opinion = 40
		}
		stress_impact = {
			gregarious = medium_stress_loss
			improvident = major_stress_loss
			greedy = major_stress_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				gold < medium_gold_value
				add = -95
			}
			modifier = {
				has_trait = greedy
				add = -75
			}
			modifier = {
				has_trait = gregarious
				add = 50
			}
			modifier = {
				has_trait = improvident
				add = 75
			}
			ai_value_modifier = {
				ai_greed = -0.5
			}
		}
	}

	#Option D: almoner
	option = {
		name = hold_court.6160.d
		trigger = {
			exists = scope:almoner
			NOT = { exists = scope:seneschal } # Prevent option bloat
			trigger_if = {
				limit = {
					is_ai = yes
				}
				short_term_gold >= major_gold_value
			}
		}
		pay_short_term_gold = {
			target = scope:6160_vassal
			gold = major_gold_value
		}
		add_piety = major_piety_gain
		change_current_court_grandeur = major_court_grandeur_gain
		reverse_add_opinion = {
			target = scope:6160_vassal
			modifier = grateful_opinion
			opinion = 30
		}
		add_hook = {
			type = indebted_hook
			target = scope:6160_vassal
		}
		stress_impact = {
			improvident = major_stress_loss
			greedy = major_stress_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				gold < major_gold_value
				add = -95
			}
			modifier = {
				has_trait = greedy
				add = -75
			}
			modifier = {
				has_trait = improvident
				add = 75
			}
			modifier = {
				has_trait = zealous
				add = 25
			}
			ai_value_modifier = {
				ai_greed = -0.5
				ai_zeal = 0.5
			}
		}
	}

	#Option E: seneschal
	option = {
		name = hold_court.6160.e
		trigger = {
			exists = scope:seneschal
			trigger_if = {
				limit = {
					is_ai = yes
				}
				short_term_gold >= major_gold_value
			}
		}
		if = {
			limit = {
				scope:6160_vassal = {
					hold_court_6160_valid_hook_trigger = yes
				}
			}
			scope:6160_vassal = {
				remove_hook = { target = root }
			}
		}
		pay_treasury_or_gold = {
			target = scope:6160_vassal
			value = medium_treasury_or_gold_value
		}
		scope:6160_vassal = {
			add_character_modifier = {
				modifier = 6160_seneschal_help_modifier
				years = 5
			}
		}
		add_hook = {
			type = indebted_hook
			target = scope:6160_vassal
		}
		add_prestige = medium_prestige_gain
		change_current_court_grandeur = medium_court_grandeur_gain
		reverse_add_opinion = {
			target = scope:6160_vassal
			modifier = grateful_opinion
			opinion = 30
		}
		stress_impact = {
			greedy = medium_stress_gain
		}
		ai_chance = {
			base = 120
			modifier = {
				gold < medium_treasury_or_gold_value
				add = -95
			}
			modifier = {
				has_trait = greedy
				add = -50
			}
			ai_value_modifier = {
				ai_greed = -0.25
			}
		}
	}

	#Option F: no money to spare
	option = {
		name = hold_court.6160.f
		reverse_add_opinion = {
			target = scope:6160_vassal
			modifier = disappointed_opinion
			opinion = -10
		}
		stress_impact = {
			generous = major_stress_gain
			improvident = massive_stress_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				gold < medium_gold_value
				add = 95
			}
			modifier = {
				has_trait = greedy
				add = 50
			}
			modifier = {
				has_trait = generous
				add = -75
			}
			modifier = {
				has_trait = improvident
				add = -100
			}
			ai_value_modifier = {
				ai_greed = 0.25
			}
		}
	}

	after = {
		scope:6160_vassal = {
			clear_court_event_participation = yes
		}
		if = {
			limit = { exists = scope:almoner }
			scope:almoner = {
				clear_court_event_participation = yes
			}
		}
		if = {
			limit = { exists = scope:seneschal }
			scope:seneschal = {
				clear_court_event_participation = yes
			}
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

##################################################
# Ignoble Imprisonment
# by Claudia Baldassi
# 6170
##################################################

# A vassal has a family member imprisoned by another vassal in your realm. They petition you to have them released #

scripted_trigger hold_court_6170_valid_vassal_trigger = {
	is_available_ai_adult = yes
	has_court_event_flag = no
	save_temporary_scope_as = vassal_scope
	OR = {
		any_close_or_extended_family_member = {
			hold_court_6170_valid_prisoner_trigger = yes
		}
		any_consort = {
			hold_court_6170_valid_prisoner_trigger = yes
		}
		betrothed ?= {
			hold_court_6170_valid_prisoner_trigger = yes
		}
	}
}

scripted_trigger hold_court_6170_valid_prisoner_trigger = {
	has_court_event_flag = no
	is_imprisoned = yes
	is_ai = yes
	imprisoner = {
		is_vassal_of = root
		NOR = {
			AND = {
				exists = scope:vassal_scope
				this = scope:vassal_scope
			}
			AND = {
				exists = scope:6170_vassal
				this = scope:6170_vassal
			}
		}
	}
}

hold_court.6170 = {
	type = court_event
	title = hold_court.6170.t
	desc = hold_court.6170.desc
	theme = court
	lower_right_portrait = scope:6170_relative
	lower_left_portrait = scope:6170_rival
	court_scene = {
		button_position_character = scope:6170_vassal
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:6170_vassal = {
				group = petitioners_group
				animation = beg
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

	cooldown = { years = 10 }

	trigger = {
		any_vassal = {
			hold_court_6170_valid_vassal_trigger = yes
		}
	}

	weight_multiplier = {
		base = 1

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

	immediate = {
		random_vassal = {
			limit = {
				hold_court_6170_valid_vassal_trigger = yes
			}
			save_scope_as = 6170_vassal
			court_event_character_flag_effect = yes
		}
		if = {
			limit = {
				scope:6170_vassal = {
					any_close_or_extended_family_member = {
						hold_court_6170_valid_prisoner_trigger = yes
					}
				}
			}
			scope:6170_vassal = {
				random_close_or_extended_family_member = {
					limit = {
						hold_court_6170_valid_prisoner_trigger = yes
					}
					save_scope_as = 6170_relative
				}
			}
		}
		else_if = {
			limit = {
				scope:6170_vassal = {
					any_consort = {
						hold_court_6170_valid_prisoner_trigger = yes
					}
				}
			}
			scope:6170_vassal = {
				random_consort = {
					limit = {
						hold_court_6170_valid_prisoner_trigger = yes
					}
					save_scope_as = 6170_relative
				}
			}
		}
		else = {
			scope:6170_vassal = {
				betrothed = {
					save_scope_as = 6170_relative
				}
			}
		}
		scope:6170_relative = {
			court_event_character_flag_effect = yes
			imprisoner = {
				save_scope_as = 6170_rival
			}
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	#Option A: release them
	option = {
		name = hold_court.6170.a
		if = {
			limit = {
				can_add_hook = {
					type = favor_hook
					target = scope:6170_vassal
				}
			}
			add_hook = {
				type = favor_hook
				target = scope:6170_vassal
			}
		}
		if = {
			limit = {
				can_add_hook = {
					type = favor_hook
					target = scope:6170_relative
				}
			}
			add_hook = {
				type = favor_hook
				target = scope:6170_relative
			}
		}
		scope:6170_relative = { release_from_prison = yes }
		reverse_add_opinion = {
			target = scope:6170_vassal
			modifier = grateful_opinion
			opinion = 30
		}
		if = {
			limit = {
				scope:6170_vassal = {
					can_set_relation_potential_friend_trigger = { CHARACTER = root }
				}
			}
			scope:6170_vassal = {
				set_relation_potential_friend = root
			}
		}
		reverse_add_opinion = {
			target = scope:6170_relative
			modifier = grateful_opinion
			opinion = 30
		}
		stress_impact = {
			callous = medium_stress_gain
			torturer = medium_stress_gain
			arbitrary = medium_stress_gain
			sadistic = medium_stress_gain
			vengeful = medium_stress_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 1
			}
			modifier = {
				has_trait = callous
				add = -50
			}
			modifier = {
				has_trait = torturer
				add = -50
			}
			modifier = {
				has_trait = arbitrary
				add = -50
			}
			modifier = {
				has_trait = sadistic
				add = -50
			}
			modifier = {
				has_trait = vengeful
				add = -50
			}
		}
	}

	#Option E: I don't care
	option = {
		name = hold_court.6170.e
		stress_impact = {
			lazy = medium_stress_loss
			compassionate = medium_stress_gain
			diligent = medium_stress_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = lazy
				add = 50
			}
			modifier = {
				has_trait = compassionate
				add = -50
			}
			modifier = {
				has_trait = diligent
				add = -50
			}
		}
	}

	after = {
		scope:6170_vassal = {
			clear_court_event_participation = yes		
		}
		scope:6170_relative = {
			clear_court_event_participation = yes
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

#############################
# A Shadow in the Night		#
# by Claudia Baldassi		#
# 6190						#
#############################

# Court physician has been spotted in the cemetery excavating the graves of the recently deceased. He is using them to practice dissecting/documentation but the locals are (understandably) not happy and want you to disown him. #

hold_court.6190 = {
	type = court_event
	title = hold_court.6190.t
	desc = hold_court.6190.desc
	theme = court

	court_scene = {
		button_position_character = scope:6190_local
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:6190_local = {
				group = petitioners_group
				animation = anger
			}
			scope:physician = {
				group = petitioners_group
				animation = schadenfreude
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

	cooldown = { years = 20 }
	
	trigger = {
		employs_court_position = court_physician_court_position
		any_court_position_holder = {
			type = court_physician_court_position
			has_court_event_flag = no
			is_available_ai_adult = yes
			OR = {
				has_trait = ambitious
				has_trait = cynical
				has_trait = callous
				has_trait = sadistic
			}
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = 20
			employs_court_position = court_physician_court_position
			any_court_position_holder = {
				type = court_physician_court_position
				has_focus_or_focus_trait_trigger = { FOCUS = intrigue_intimidation_focus }
			}
		}
		modifier = {
			add = 10
			employs_court_position = court_physician_court_position
			any_court_position_holder = {
				type = court_physician_court_position
				has_focus_or_focus_trait_trigger = { FOCUS = learning_medicine_focus }
			}
		}
		modifier = {
			add = 5
			employs_court_position = court_physician_court_position
			any_court_position_holder = {
				type = court_physician_court_position
				has_trait = lifestyle_physician
				has_trait_xp = {
					trait = lifestyle_physician
					value >= 100
				}
			}
		}
		modifier = {
			add = 10
			employs_court_position = court_physician_court_position
			any_court_position_holder = {
				type = court_physician_court_position
				has_trait = ambitious
			}
		}
		modifier = {
			add = 10
			employs_court_position = court_physician_court_position
			any_court_position_holder = {
				type = court_physician_court_position
				has_trait = cynical
			}
		}
		modifier = {
			add = 10
			employs_court_position = court_physician_court_position
			any_court_position_holder = {
				type = court_physician_court_position
				has_trait = callous
			}
		}
		modifier = {
			add = 10
			employs_court_position = court_physician_court_position
			any_court_position_holder = {
				type = court_physician_court_position
				has_trait = sadistic
			}
		}

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

	immediate = {
		random_court_position_holder = {
			type = court_physician_court_position
			limit = {
				has_court_event_flag = no
				is_available_ai_adult = yes
			}
			save_scope_as = physician
			court_event_character_flag_effect = yes
		}
		create_character = {
			location = root.capital_province
			template = generic_peasant_character
			save_scope_as = 6190_local
		}
		scope:6190_local = {
			court_event_character_flag_effect = yes
		}
		capital_province = {
			save_scope_as = capital
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	#Option A: these studies are necessary
	option = {
		name = hold_court.6190.a
		capital_county = {
 			add_county_modifier = {
 				modifier = 6190_grave_robbing_county_modifier
 				years = 10
 			}
 		}
 		every_courtier_or_guest = {
			custom = custom.every_non_callous_or_sadistic_courtier_and_guest
			limit = {
				NOR = {
					has_trait = callous
					has_trait = sadistic
					this = scope:physician
				}
			}
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -10
			}
		}
 		scope:physician = {
 			if = {
 				limit = {
 					NAND = {
						has_trait = lifestyle_physician
						has_trait_xp = {
							trait = lifestyle_physician
							value >= 100
						}
					}
 				}
				random = {
					chance = 15
					physician_lifestyle_rank_up_effect = yes
				}
			}
			else_if = {
				limit = {
					NOT = {
						has_trait = lifestyle_physician
					}
				}
				add_trait = lifestyle_physician
			}
			else = {
				add_learning_skill = 1
			}
 		}
 		stress_impact = {
 			zealous = major_stress_impact_gain
 			compassionate = major_stress_impact_gain
 		}
 		ai_chance = {
 			base = 100
 			ai_value_modifier = {
 				ai_zeal = -0.25
 			}
 		}
	}

	#Option B: I wanna take part! FOR SCIENCE!
	option = {
		name = hold_court.6190.b
		trigger = {
			OR = {
				has_trait = lifestyle_physician
				has_trait = cynical
				has_trait = callous
				has_trait = sadistic
				AND = {
					has_focus_or_focus_trait_trigger = { FOCUS = learning_medicine_focus }
					has_trait = ambitious
				}
				has_focus_or_focus_trait_trigger = { FOCUS = intrigue_intimidation_focus }
			}
		}
		add_dread = medium_dread_gain
 		change_current_court_grandeur = minor_court_grandeur_loss
 		add_learning_lifestyle_perk_points = 1
 		every_courtier_or_guest = {
			custom = custom.every_non_callous_or_sadistic_courtier_and_guest
			limit = {
				NOR = {
					has_trait = callous
					has_trait = sadistic
					this = scope:physician
				}
			}
			add_opinion = {
				target = root
				modifier = impious_opinion
				opinion = -20
			}
		}
 		scope:physician = {
 			if = {
 				limit = {
 					NAND = {
						has_trait = lifestyle_physician
						has_trait_xp = {
							trait = lifestyle_physician
							value >= 100
						}
					}
 				}
				random = {
					chance = 20
					physician_lifestyle_rank_up_effect = yes
				}
			}
			else_if = {
				limit = {
					NOT = {
						has_trait = lifestyle_physician
					}
				}
				add_trait = lifestyle_physician
			}
			else = {
				add_learning_skill = 1
			}
 		}
 		capital_county = {
 			add_county_modifier = {
 				modifier = 6190_grave_robbing_county_modifier
 				years = 10
 			}
 		}
 		stress_impact = {
 			compassionate = major_stress_impact_gain
 			zealous = major_stress_impact_gain
 			just = major_stress_impact_gain
 		}
 		ai_chance = {
 			base = 100
 			ai_value_modifier = {
 				ai_zeal = -0.5
 				ai_compassion = -0.5
 			}
 		}
	}

	#Option D: Blasphemy! Punish the physician
	option = {
		name = hold_court.6190.d
		revoke_court_position = {
			recipient = scope:physician
			court_position = court_physician_court_position
		}
		rightfully_imprison_character_effect = {
 			TARGET = scope:physician
			IMPRISONER = root
 		}
 		capital_county = {
 			add_county_modifier = {
 				modifier = 6190_safe_graves_county_modifier
 				years = 10
 			}
 		}
 		every_courtier_or_guest = {
			custom = custom.every_zealous_courtier_and_guest
			limit = {
				has_trait = zealous
				this != scope:physician
			}
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 25
			}
		}
 		stress_impact = {
 			zealous = medium_stress_impact_loss
 			sadistic = medium_stress_impact_gain
			callous = medium_stress_impact_gain
			torturer = medium_stress_impact_gain
			vengeful = medium_stress_impact_gain
 		}
 		ai_chance = {
 			base = 100
 			ai_value_modifier = {
 				ai_zeal = 1
 				ai_compassion = -1
 			}
 		}
	}

	#Option E: Just stop
	option = {
		name = hold_court.6190.e
		scope:physician = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -5
			}
		}
		capital_county = {
 			add_county_modifier = {
 				modifier = 6190_safe_graves_county_modifier
 				years = 10
 			}
 		}
 		ai_chance = {
 			base = 100
 		}
	}

	after = {
		scope:physician = {
			clear_court_event_participation = yes
		}
		scope:6190_local = {
			clear_court_event_participation = yes
			if = {
				limit = {
					is_alive = yes
					is_imprisoned = no
				}
				silent_disappearance_effect = yes
			}
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

#########################
# A Land of Foreigners	#
# by Claudia Baldassi	#
# 6210					#
#########################

# A vassal comes to you begging for help because their land is overrun by unhappy barbarians (= other culture). #

scripted_trigger hold_court_6210_valid_vassal_trigger = {
	has_court_event_flag = no
	culture = {
		this = root.culture
		any_parent_culture_or_above = {
			save_temporary_scope_as = parent
		}
	}
	is_landed_or_landless_administrative = yes
	is_available_ai_adult = yes
	exists = capital_county
	OR = {
		capital_county = {
			hold_court_6210_valid_county_trigger = yes
		}
		AND = {
			realm_size >= 4
			any_sub_realm_county = {
				count >= 3
				hold_court_6210_valid_county_trigger = yes
			}
		}
	}
}

scripted_trigger hold_court_6210_valid_county_trigger = {
	culture = {
		NOR = {
			this = root.culture
			any_parent_culture_or_above = {
				this = root.culture
				this = scope:parent
			}
		}
	}
}

hold_court.6210 = {
	type = court_event
	title = hold_court.6210.t
	desc = hold_court.6210.desc
	theme = court
	lower_left_portrait = {
		trigger = { exists = scope:steward }
		character = scope:steward
	}
	lower_center_portrait = {
		trigger = { exists = scope:r_architect }
		character = scope:r_architect
	}
	cooldown = { years = 10 }

	court_scene = {
		button_position_character = scope:6210_vassal
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:6210_vassal = {
				group = petitioners_group
				animation = beg
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

	trigger = {
		any_vassal = {
			hold_court_6210_valid_vassal_trigger = yes
		}
	}

	weight_multiplier = {
		base = 1

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

	immediate = {
		random_vassal = {
			limit = {
				hold_court_6210_valid_vassal_trigger = yes
			}
			save_scope_as = 6210_vassal
			court_event_character_flag_effect = yes
		}
		if = {
			limit = {
				any_court_position_holder = {
					type = royal_architect_court_position
					has_court_event_flag = no
					is_available_ai_adult = yes
				}
			}
			random_court_position_holder = {
				type = royal_architect_court_position
				limit = {
					has_court_event_flag = no
					is_available_ai_adult = yes
				}
				save_scope_as = r_architect
				court_event_character_flag_effect = yes
			}
		}
		if = {
			limit = {
				exists = cp:councillor_steward
				cp:councillor_steward = {
					has_court_event_flag = no
					is_available_ai_adult = yes
				}
			}
			cp:councillor_steward = {
				save_scope_as = steward
				court_event_character_flag_effect = yes
			}
		}
		if = {
			limit = {
				scope:6210_vassal.capital_county = {
					hold_court_6210_valid_county_trigger = yes
				}
			}
			scope:6210_vassal.capital_county = {
				save_scope_as = 6210_main_county
			}
		}
		else = {
			scope:6210_vassal = {
				random_sub_realm_county = {
					limit = {
						hold_court_6210_valid_county_trigger = yes
					}
					save_scope_as = 6210_main_county
				}
			}
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	#Option A: send steward
	option = {
		name = hold_court.6210.a
		trigger = {
			exists = scope:steward
		}
		scope:steward = {
			set_council_task = {
				task_type = task_promote_culture
				target = scope:6210_main_county.title_province
			}
		}
		scope:6210_main_county = {
			add_county_modifier = {
				modifier = easier_to_culture_convert
				years = 25
			}
		}
		scope:6210_vassal = {
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 20
			}
		}
		stress_impact = {
			humble = medium_stress_impact_gain	
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = humble
				add = -25
			}
		}
	}

	#Option B: send the architect
	option = {
		name = hold_court.6210.b
		trigger = {
			exists = scope:r_architect
			trigger_if = {
				limit = {
					is_ai = yes
				}
				short_term_gold >= major_gold_value
			}
		}
		custom_tooltip = hold_court.6210.b.tt
		remove_treasury_or_gold = medium_treasury_or_gold_value
		scope:6210_vassal = {
			every_sub_realm_county = {
				limit = {
					hold_court_6210_valid_county_trigger = yes
				}
				add_county_modifier = {
					modifier = 6210_architect_county_modifier
					years = 5
				}
			}
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 30
			}
		}
		scope:r_architect = {
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 30
			}
		}
		change_current_court_grandeur = major_court_grandeur_gain
		add_prestige = medium_prestige_gain
		scope:6210_main_county = {
			add_county_modifier = {
				modifier = easier_to_culture_convert
				years = 25
			}
		}
		stress_impact = {
			greedy = major_stress_impact_gain
		}
		ai_chance = {
			base = 200
			modifier = {
				gold < medium_treasury_or_gold_value
				add = -200
			}
		}
	}

	#Option C: tolerance
	option = {
		name = hold_court.6210.c
		scope:6210_vassal = {
			every_sub_realm_county = {
				limit = {
					hold_court_6210_valid_county_trigger = yes
				}
				add_county_modifier = {
					modifier = governance_1073_conversion_resistance_modifier
					years = 10
				}
			}
		}
		scope:6210_main_county.culture = {
			change_cultural_acceptance = {
				target = root.culture
				value = minor_cultural_acceptance_gain
				desc = cultural_acceptance_gain_hold_court_event_outcome
			}
		}
		change_current_court_grandeur = minor_court_grandeur_gain
		add_prestige = medium_prestige_gain
		ai_chance = {
			base = 100
			modifier = {
				has_trait = trusting
				add = 20
			}
			modifier = {
				has_trait = compassionate
				add = 30
			}
			modifier = {
				culture = { has_cultural_pillar = ethos_egalitarian }
				add = 100
			}
			modifier = {
				has_trait = paranoid
				add = -100
			}
		}
	}

	after = {
		scope:6210_vassal = {
			clear_court_event_participation = yes
		}
		if = {
			limit = { exists = scope:r_architect }
			scope:r_architect = {
				clear_court_event_participation = yes
			}
		}
		if = {
			limit = { exists = scope:steward }
			scope:steward = {
				clear_court_event_participation = yes
			}
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

#############################
# A Massive Problem			#
# by Claudia Baldassi		#
# 6230						#
#############################

# A vassal in India has problem with a horde of elephants that have gone berserk and brought ruin and destruction in one (several?) of his counties. He pleads for help to manage the elephants and rebuild! #

hold_court.6230 = {
	type = court_event
	title = hold_court.6230.t
	desc = hold_court.6230.desc
	theme = court
	lower_left_portrait = scope:m_horse

	court_scene = {
		button_position_character = scope:6230_vassal
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:6230_vassal = {
				group = petitioners_group
				animation = beg
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

	cooldown = { years = 20 }

	trigger = {
		any_vassal_or_below = {
			has_court_event_flag = no
			is_available_ai_adult = yes
			is_landed_or_landless_administrative = yes
			capital_province = {
				geographical_region = world_innovation_elephants
			}
		}
	}

	weight_multiplier = {
		base = 1

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

	immediate = {
		random_vassal_or_below = {
			limit = {
				has_court_event_flag = no
				is_available_ai_adult = yes
				is_landed_or_landless_administrative = yes
				capital_province = {
					geographical_region = world_innovation_elephants
				}
				
			}
			save_scope_as = 6230_vassal
			court_event_character_flag_effect = yes
		}
		scope:6230_vassal.capital_province = {
			save_scope_as = 6230_province
		}
		if = {
			limit = {
				employs_court_position = master_of_horse_court_position
				any_court_position_holder = {
					type = master_of_horse_court_position
					has_court_event_flag = no
					is_available_ai_adult = yes
				}
			}
			random_court_position_holder = {
				type = master_of_horse_court_position
				limit = {
					has_court_event_flag = no
					is_available_ai_adult = yes
				}
				save_scope_as = m_horse
				court_event_character_flag_effect = yes
			}
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	#Option A: send gold to rebuild
	option = {
		name = hold_court.6230.a
		trigger = {
			trigger_if = {
				limit = {
					is_ai = yes
				}
				short_term_gold >= major_gold_value
			}
		}
		pay_treasury_or_gold = {
			target = scope:6230_vassal
			value = medium_gold_value
		}
		reverse_add_opinion = {
			target = scope:6230_vassal
			modifier = grateful_opinion
			opinion = 20
		}
		scope:6230_province.county = {
			add_county_modifier = {
				modifier = 6230_rebuilding
				years = 25
			}
		}
		add_prestige = medium_prestige_gain
		stress_impact = {
			greedy = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 1
			}
			modifier = {
				add = -200
				gold < medium_gold_value
			} 
		}
	}

	#Option B: send aid in capturing the elephants
	option = {
		name = hold_court.6230.b
		trigger = {
			NOT = { exists = scope:m_horse }
		}
		duel = {
			skill = martial
			value = average_skill_rating
			40 = {
				desc = hold_court.6230.b.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3
				}
				send_interface_toast = {
					title = hold_court.6230.b.success.tt
					add_character_modifier = {
						modifier = 6230_new_elephants_modifier
						years = 10
					}
					change_current_court_grandeur = medium_court_grandeur_gain
				}
			}
			60 = {
				desc = hold_court.6230.b.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3
				}
				send_interface_toast = {
					title = hold_court.6230.b.failure.tt
					change_current_court_grandeur = medium_court_grandeur_loss
					scope:6230_province.county = { change_county_control = -5 }
				}
			}
		}
		stress_impact = {
			lazy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_energy = -0.5
			}
			modifier = {
				add = -75
				martial < 10
			}
		}
	}

	#Option C: send master of horse to help
	option = {
		name = hold_court.6230.c
		trigger = {
			exists = scope:m_horse
		}
		scope:m_horse = {
			duel = {
				skill = martial
				value = average_skill_rating
				40 = {
					desc = hold_court.6230.c.success
					compare_modifier = {
						value = scope:duel_value
						multiplier = 3
					}
					root = {
						send_interface_toast = {
							title = hold_court.6230.b.success.tt
							add_character_modifier = {
								modifier = 6230_new_elephants_modifier
								years = 10
							}
							change_current_court_grandeur = medium_court_grandeur_gain
						}
					}
				}
				60 = {
					desc = hold_court.6230.b.failure
					compare_modifier = {
						value = scope:duel_value
						multiplier = -3
					}
					root = {
						send_interface_toast = {
							title = hold_court.6230.b.failure.tt
							change_current_court_grandeur = medium_court_grandeur_loss
							scope:6230_province.county = { change_county_control = -5 }
						}
					}
				}
			}
		}
		ai_chance = {
			base = 100
		}
	}

	#Option D: Ganesh leads them
	option = {
		name = hold_court.6230.d
		trigger = {
			faith.religion = religion:hinduism_religion
		}
		add_piety = major_piety_gain
		stress_impact = {
			cynical = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = 1
			}
		}
	}

	#Option E: nope
	option = {
		name = hold_court.6230.e
		reverse_add_opinion = {
			target = scope:6230_vassal
			modifier = disappointed_opinion
			opinion = -20
		}
		scope:6230_province.county = { change_county_control = -5 }
		ai_chance = {
			base = 75
		}
	}

	after = {
		scope:6230_vassal = {
			clear_court_event_participation = yes
		}
		if = {
			limit = { exists = scope:m_horse }
			scope:m_horse = {
				clear_court_event_participation = yes
			}
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}





##################################################
# Joe Parkin

##################################################
# 8001			Stifled Commerce
# 8010			The X Frontier
# 8020			Sacred Claims
# 8030			Civic Rivalry
# 8040			Special Treatment
# 8050 - 8053	Royal Service
# 8060 - 8061	A Temple for X
# 8070 - 8071	The Growth of X
# 8080			The Republic of X
# 8090			A Place at Court
# 8100			A Child of the Court
# 8110			Serious Business
# 8120			Evangelical Backlash
# 8130			Cultural Pride
# 8140 - 8142	Puppy Patronage
# 8150			Contractual Compromise
# 8160			Public Accusation
# 8161			Personal Matter
# 8170 - 8171	Services Rendered
# 8180			Noble Privileges
# 8190			Enemy Within
# 8200			Servant of God
# 8210			Rightful Lands
# 8220 - 8222	Opportunity Knocks
# 8240			Thy Neighbor's Wife
# 8241			Spoiled for Choice
# 8250			Hankering for X
# 8251			The Dancer
# 8260			The King's Peace
# 8270			Oath of Fealty
# 8280			Nomadic Neighbors
##################################################

##################################################
# Stifled Commerce
# by Joe Parkin
# 8001
##################################################

scripted_trigger hold_court_available_mayor_trigger = {
	has_court_event_flag = no
	is_available_ai_adult = yes
	primary_title = {
		tier = tier_barony
		NOT = { has_variable = hold_court_city_cooldown_var }
	}
	government_has_flag = government_is_republic
	NOT = { is_close_or_extended_family_of = root }
}

scripted_effect hold_court_8001_revoke_title_effect = {
	if = {
		limit = {  has_relation_friend = root  }
		remove_relation_friend = root
	}
	if = { # If they recently imprisoned you, or asked for your excommunication, they become your rival
		limit = {
			OR = {
				has_opinion_modifier = {
					target = root
					modifier = released_from_prison
				}
				AND = {
					exists = var:requested_my_excommunication
					var:requested_my_excommunication = root
				}
			}
			NOT = { has_relation_rival = root }
		}
		if = {
			limit = { has_relation_potential_rival = root }
			remove_relation_potential_rival = root
		}
		root = {
			set_relation_rival = {
				target = prev
				reason = rival_revoked_title
			}
		}
	}
	else = {
		progress_towards_rival_effect = {
			CHARACTER = root
			REASON = rival_removed_mayor
			OPINION = 0
		}
	}
}

# A merchant complains about the mayor of their town
hold_court.8001 = {
	type = court_event
	title = hold_court.8001.t
	desc = hold_court.8001.desc
	theme = court
	lower_right_portrait = scope:portrait
	court_scene = {
		button_position_character = scope:merchant
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:merchant = {
				group = petitioners_group
				animation = beg
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

	cooldown = { years = 10 }

	trigger = {
		any_vassal = { hold_court_available_mayor_trigger = yes }
	}

	weight_multiplier = {
		base = 1

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

	immediate = {
		every_vassal = {
			limit = { hold_court_available_mayor_trigger = yes }
			add_to_list = potential_mayor
		}
		random_in_list = {
			list = potential_mayor
			limit = {
				OR = {
					has_trait = lazy
					has_trait = greedy
					has_trait = deceitful
					has_trait = arbitrary
					stewardship <= mediocre_skill_rating
				}
			}
			alternative_limit = {
				NOR = {
					has_trait = diligent
					has_trait = generous
					has_trait = honest
					has_trait = just
					stewardship >= decent_skill_rating
				}
			}
			alternative_limit = {
				always = yes
			}
			save_scope_as = mayor
			save_scope_as = portrait
			court_event_character_flag_effect = yes
			primary_title = {
				save_scope_as = town
				set_variable = {
					name = hold_court_city_cooldown_var
					years = 25
				}
			}
		}
		create_character = {
			template = merchant_template
			location = root.capital_province
			trait = honest
			save_scope_as = merchant
			after_creation = {
				add_character_flag = created
			}
		}
		scope:merchant = {
			court_event_character_flag_effect = yes
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = { # Replace the Mayor
		name = hold_court.8001.a
		scope:mayor = {
			depose = yes # depose_effect unnecessary for AI mayor
			add_opinion = {
				modifier = angry_opinion
				target = root
				opinion = -40
			}
			hold_court_8001_revoke_title_effect = yes
		}
		scope:town.county = { change_development_progress = 50 }
		add_character_modifier = {
			modifier = hold_court_8001_deposed_modifier
			years = 10
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = 0.25
   				ai_compassion = 0.25
   				ai_rationality = 0.25
   				ai_greed = -0.5
   				ai_boldness = -0.5
			}
		}
	}

	option = { # Make Merchant the Mayor
		name = hold_court.8001.b
		create_title_and_vassal_change = {
			type = revoked
			save_scope_as = change
			add_claim_on_loss = no
		}
		scope:town = {
			change_title_holder = {
				holder = scope:merchant
				change = scope:change
			}
		}
		resolve_title_and_vassal_change = scope:change
		scope:mayor = {
			add_opinion = {
				modifier = angry_opinion
				target = root
				opinion = -60
			}
			hold_court_8001_revoke_title_effect = yes
		}
		random_list = {
			30 = {
				modifier = {
					add = 5
					scope:merchant = { has_trait = diligent }
				}
				modifier = {
					add = 5
					scope:merchant = { has_trait = generous }
				}
				modifier = {
					add = 5
					scope:merchant = { has_trait = honest }
				}
				modifier = {
					add = 5
					scope:merchant = { has_trait = just }
				}
				modifier = {
					add = 5
					scope:merchant = { stewardship >= decent_skill_rating }
				}
				send_interface_toast = {
					title = hold_court.8001.b.tt_success
					scope:town.county = {
						add_county_modifier = {
							modifier = hold_court_8001_merchant_boon_modifier
							years = 15
						}
						change_development_level = 1
					}
				}
			}
			70 = {
				modifier = {
					add = 5
					scope:merchant = { has_trait = lazy }
				}
				modifier = {
					add = 5
					scope:merchant = { has_trait = greedy }
				}
				modifier = {
					add = 5
					scope:merchant = { has_trait = arbitrary }
				}
				modifier = {
					add = 5
					scope:merchant = { has_trait = deceitful }
				}
				modifier = {
					add = 5
					scope:merchant = { stewardship <= 6 }
				}
				modifier = {
					add = 5
					scope:merchant = { age < 25 }
				}
				modifier = {
					add = 5
					scope:merchant = { has_trait = infirm }
				}
				modifier = {
					add = 5
					scope:merchant = { has_trait = incapable }
				}
				modifier = {
					add = 5
					scope:merchant = { age > 60 }
				}
				send_interface_toast = {
					title = hold_court.8001.b.tt_failure
					scope:town.county = {
						add_county_modifier = {
							modifier = hold_court_8001_merchant_bust_modifier
							years = 15
						}
					}
					stress_impact = {
						just = medium_stress_impact_gain
						compassionate = medium_stress_impact_gain
					}
				}
			}
		}
		add_character_modifier = {
			modifier = hold_court_8001_deposed_modifier
			years = 10
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = -0.25
   				ai_compassion = -0.25
   				ai_rationality = -0.25
   				ai_greed = -0.5
   				ai_boldness = 0.5
			}
		}
	}

	option = { # Fine the Mayor
		name = hold_court.8001.c
		duel = {
			skill = stewardship
			value = average_skill_rating
			8 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 2
				}
				desc = hold_court.8001.c.tt_success
				send_interface_toast = {
					title = hold_court.8001.c.tt_success
					scope:mayor = {
						pay_short_term_gold = {
							target = root
							gold = root.medium_gold_value
						}
						add_opinion = {
							modifier = annoyed_opinion
							target = root
							opinion = -15
						}
					}
				}
			}
			12 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -2
					min = -9
				}
				desc = hold_court.8001.c.tt_failure
				send_interface_toast = {
					title = hold_court.8001.c.tt_failure
					scope:town.county = {
						scope:town.county = { change_development_progress = -50 }
						add_county_modifier = {
							modifier = hold_court_8001_ignored_modifier
							years = 10
						}
					}
					stress_impact = {
						just = medium_stress_impact_gain
						greedy = medium_stress_impact_gain
					}
				}
			}
		}	
		ai_chance = {
			base = 100
			ai_value_modifier = {
   				ai_rationality = 0.25
   				ai_greed = 0.5
			}
			modifier = {	#Weight up for duel.
				add = 15
				stewardship > scope:mayor.stewardship
			}
		}
	}

	option = { # Compensate the Merchants
		name = hold_court.8001.d
		trigger = {
			trigger_if = {
				limit = {
					is_ai = yes
				}
				short_term_treasury_or_gold >= major_treasury_or_gold_value
			}
		}
		remove_treasury_or_gold = medium_treasury_or_gold_value
		scope:mayor = {
			add_opinion = {
				modifier = grateful_opinion
				target = root
				opinion = 10
			}
		}
		scope:town.county = {
			add_county_modifier = {
				modifier = hold_court_8001_compensated_modifier
				years = 15
			}
		}
		stress_impact = {
			greedy = massive_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = 0.25
				ai_compassion = 0.5
				ai_greed = -0.5
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = greedy
			}
		}
	}

	option = { # Imprison the Merchant
		name = hold_court.8001.e
		imprison_character_effect = {
			TARGET = scope:merchant
			IMPRISONER = root
		}
		scope:mayor = {
			add_opinion = {
				modifier = grateful_opinion
				target = root
				opinion = 20
			}
		}
		add_dread = minor_dread_gain
		scope:town.county = {
			add_county_modifier = {
				modifier = hold_court_8001_imprisoned_modifier
				years = 10
			}
		}
		stress_impact = {
			just = medium_stress_impact_gain
			calm = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = -0.5
				ai_greed = -0.5
				ai_rationality = -0.25
				ai_compassion = -0.25
				ai_boldness = 0.5
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = just
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = calm
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = compassionate
			}
		}
	}

	after = {
		scope:mayor = {
			clear_court_event_participation = yes
		}
		scope:merchant = {
			clear_court_event_participation = yes
			if = {
				limit = {
					is_landed = no
					is_imprisoned = no
				}
				silent_disappearance_effect = yes
			}
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
		scope:merchant = {
			if = {
				limit = {
					is_ruler = no
				}
				silent_disappearance_ai_if_created_effect = yes
			}
		}
	}
}

##################################################
# The X Frontier
# by Joe Parkin
# 8010
##################################################

scripted_trigger hold_court_8010_lord_trigger = {
	has_court_event_flag = no
	is_available_ai_adult = yes
	primary_title.tier >= tier_county
	government_has_flag = government_is_feudal
	subject_contract_is_blocked_from_modification = no
	OR = {
		vassal_contract_obligation_level_can_be_increased = fortification_rights
		NOT = { vassal_contract_has_flag = has_march_contract }
	}
}

scripted_trigger hold_court_8010_contract_trigger = {
	scope:frontier_lord = {
		government_has_flag = government_is_feudal
		vassal_contract_has_modifiable_obligations = yes
		OR = {
			AND = {
				root.culture = { has_innovation = innovation_battlements }
				vassal_contract_obligation_level_can_be_increased = fortification_rights
			}
			AND = {
				root.culture = { has_innovation = innovation_burhs }
				NOT = { vassal_contract_has_flag = has_march_contract }
			}
		}
	}
}

# A vassal bordering a powerful neighbor is worried
hold_court.8010 = {
	type = court_event
	title = hold_court.8010.t
	desc = hold_court.8010.desc
	theme = court
	lower_right_portrait = scope:neighboring_enemy
	court_scene = {
		button_position_character = scope:frontier_lord
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:frontier_lord = {
				group = petitioners_group
				animation = worry
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

	cooldown = { years = 20 }

	trigger = {
		top_liege = this
		NOT = {
			any_vassal = { has_character_modifier = hold_court_8010_fortifications_modifier }
		}
		any_vassal = {
			hold_court_8010_lord_trigger = yes
			any_sub_realm_county = { hold_court_8010_county_trigger = yes }
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = 1
			any_vassal = {
				hold_court_8010_lord_trigger = yes
				any_sub_realm_county = { hold_court_8010_county_trigger = yes }
				primary_title.tier >= 2
				OR = {
					has_trait = paranoid
					has_trait = lazy
					has_trait = craven
					is_powerful_vassal = yes
				}
			}
		}

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

	immediate = {
		capital_barony = { save_scope_as = capital }
		ordered_vassal = {
			limit = {
				hold_court_8010_lord_trigger = yes
				any_sub_realm_county = { hold_court_8010_county_trigger = yes } # Prefer Dukes...
				primary_title.tier = tier_duchy
			}
			alternative_limit = {
				hold_court_8010_lord_trigger = yes
				any_sub_realm_county = { hold_court_8010_county_trigger = yes } # ...then Counts...
				primary_title.tier = tier_county
			}
			alternative_limit = {
				hold_court_8010_lord_trigger = yes
				any_sub_realm_county = { hold_court_8010_county_trigger = yes } # ...then Kings
				primary_title.tier = tier_kingdom
			}
			order_by = hold_court_8010_border_length_value
			save_scope_as = frontier_lord
			court_event_character_flag_effect = yes
			random_sub_realm_county = {
				limit = { hold_court_8010_county_trigger = yes }
				title_province.barony = { save_scope_as = frontier_barony }
				ordered_title_to_title_neighboring_county = {
					limit = {
						holder.top_liege = {
							NOR = {
								this = root
								is_allied_to = root
								max_military_strength < hold_court_8010_75_strength_value # 75% of root's soldiers
							}
						}
					}
					order_by = holder.top_liege.max_military_strength
					de_jure_liege = { save_scope_as = neighboring_duchy }
					holder.top_liege = { save_scope_as = neighboring_enemy }
				}
			}
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = { # Give vassal defensive contract (March/Fortification Rights)
		name = hold_court.8010.a
		trigger = {
			hold_court_8010_contract_trigger = yes
			OR = {
				AND = {
					culture = { has_innovation = innovation_burhs }
					scope:frontier_lord.primary_title.tier >= tier_duchy
				}
				AND = {
					culture = { has_innovation = innovation_battlements }
					scope:frontier_lord = { vassal_contract_obligation_level_can_be_increased = fortification_rights }
				}
			}
		}
		scope:frontier_lord = {
			if = {
				limit = {
					AND = {
						root.culture = { has_innovation = innovation_battlements }
						vassal_contract_obligation_level_can_be_increased = fortification_rights
					}
				}
				vassal_contract_set_obligation_level = {
					type = fortification_rights
					level = 1
				}
			}
			else = {
				vassal_contract_set_obligation_level = {
					type = special_contract
					level = 2
				}
			}
			add_opinion = {
				modifier = grateful_opinion
				target = root
				opinion = 20
			}
		}
		if = {
			limit = {
				can_add_hook = {
					target = scope:frontier_lord
					type = indebted_hook
				}
			}
			add_hook = {
				target = scope:frontier_lord
				type = indebted_hook
			}
		}
		stress_impact = {
			greedy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = -0.5
				ai_compassion = 0.5
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = greedy
			}
		}
	}

	option = { # Pay for vassals fortications (if A is unavailable)
		name = hold_court.8010.b
		trigger = {
			trigger_if = {
				limit = {
					is_ai = yes
				}
				short_term_treasury_or_gold >= major_treasury_or_gold_value
			}
		}
		remove_treasury_or_gold = medium_treasury_or_gold_value
		scope:frontier_barony.county = {
			add_county_modifier = {
				modifier = hold_court_8010_fortifications_modifier
				years = 15
			}
		}
		scope:frontier_lord = {
			add_opinion = {
				modifier = grateful_opinion
				target = root
				opinion = 20
			}
		}
		if = {
			limit = {
				can_add_hook = {
					target = scope:frontier_lord
					type = indebted_hook
				}
			}
			add_hook = {
				target = scope:frontier_lord
				type = indebted_hook
			}
		}
		stress_impact = {
			greedy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = -0.5
				ai_compassion = 0.5
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = greedy
			}
		}
	}

	option = { # Fortify your own capital instead 
		name = hold_court.8010.c
		trigger = {
			trigger_if = {
				limit = {
					is_ai = yes
				}
				short_term_treasury_or_gold >= major_treasury_or_gold_value
			}
		}
		remove_treasury_or_gold = medium_treasury_or_gold_value
		capital_county = {
			add_county_modifier = {
				modifier = hold_court_8010_fortifications_modifier
				years = 15
			}
		}
		scope:frontier_lord = {
			add_opinion = {
				modifier = annoyed_opinion
				target = root
				opinion = -15
			}
		}
		stress_impact = {
			brave = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = -0.5
				ai_honor = -0.5
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = brave
			}
		}
	}

	option = { # Argue that it is unwarranted
		name = hold_court.8010.d
		duel = {
			skill = diplomacy
			value = average_skill_rating
			8 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 2
				}
				desc = hold_court.8010.d.tt_success
				send_interface_toast = {
					title = hold_court.8010.d.tt_success
					left_icon = scope:frontier_lord
					change_current_court_grandeur = medium_court_grandeur_gain
				}
			}
			12 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -1
				}
				desc = hold_court.8010.d.tt_failure
				send_interface_toast = {
					title = hold_court.8010.d.tt_failure
					left_icon = scope:frontier_lord
					add_prestige = minor_prestige_loss
					scope:frontier_lord = {
						add_opinion = {
							modifier = dismissive_opinion
							target = root
							opinion = -20
						}
					}
				}
			}
		}
		stress_impact = {
			honest = medium_stress_impact_gain
			paranoid = medium_stress_impact_gain
		}	
		ai_chance = {
			base = 100
			ai_value_modifier = {
   				ai_rationality = 0.25
   				ai_greed = 0.5
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = honest
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = paranoid
			}
			modifier = {	#Weight up for duel.
				add = 15
				diplomacy > scope:frontier_lord.diplomacy
			}
		}
	}

	option = { # Dismiss vassal
		name = hold_court.8010.e
		add_character_modifier = {
			modifier = hold_court_8010_vassal_modifier
			years = 10
		}
		scope:frontier_lord = {
			add_opinion = {
				modifier = dismissive_opinion
				target = root
				opinion = -10
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
   				ai_boldness = 0.5
   				ai_greed = 0.5
   			}
		}
	}

	after = {
		scope:frontier_lord = {
			clear_court_event_participation = yes
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

##################################################
# Sacred Claims
# by Joe Parkin
# 8020
##################################################

scripted_trigger hold_court_8020_county_trigger = {
	this != root.capital_county
	any_county_province = {
		barony = { is_holy_site_of = root.faith }
	}
	faith = root.faith
	holder = {
		has_court_event_flag = no
		NOR = {
			government_has_flag = government_is_theocracy
			this = root.cp:councillor_court_chaplain
			trigger_if = {
				limit = {
					exists = root.faith.religious_head
					root != root.faith.religious_head
				}
				this = root.faith.religious_head
			}
		}
		any_held_title = {
			count >= 2
			title_tier = county
		}
		OR = {
			this = root
			AND = {
				is_available_ai_adult = yes
				NOT = { has_any_bad_relationship_with_root_trigger = yes }
			}
		}
	}
}

scripted_trigger hold_court_8020_cathedral_barony_trigger = {
	is_holy_site_of = root.faith
	title_province = {
		OR = {
			has_building = holy_site_cathedral_01
			has_building = holy_site_mosque_01
			has_building = holy_site_pagan_grand_temple_01
			has_building = holy_site_indian_grand_temple_01
			has_building = holy_site_other_grand_temple_01
			# TGP
			has_building = holy_site_buddhist_grand_temple_01
			has_building = holy_site_japanese_temple_01
			has_building = holy_site_chinese_temple_01
			has_building = holy_site_se_asia_pagan_temple_01
		}
	}
}

scripted_effect hold_court_8020_grant_effect = {
	create_title_and_vassal_change = {
		type = granted
		save_scope_as = change
		add_claim_on_loss = no
	}
	if = {
		limit = { exists = scope:vassal }
		scope:vassal = {
			add_opinion = {
				modifier = angry_opinion
				target = root
				opinion = -20
			}
		}
	}
	scope:target_county = {
		change_title_holder = {
			holder = scope:candidate
			change = scope:change
		}
	}
	resolve_title_and_vassal_change = scope:change
	hidden_effect = {
		scope:candidate = { change_government = theocracy_government }
	}
}

# Chaplain asks for a holy site
hold_court.8020 = {
	type = court_event
	title = hold_court.8020.t
	desc = {
		desc = hold_court.8020.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:pope }
				desc = hold_court.8020.desc.body_pope
			}
			desc = hold_court.8020.desc.body_fallback
		}
		desc = hold_court.8020.desc.body_1
		first_valid = {
			triggered_desc = {
				trigger = { scope:target_county.holder = root } # Owns target personally
				desc = hold_court.8020.desc.body_personal
			}
			desc = hold_court.8020.desc.body_vassal # Vassal owns target
		}
		desc = hold_court.8020.desc.body_2
	}
	theme = realm
	lower_left_portrait = scope:candidate
	lower_right_portrait = scope:pope
	artifact = {
		target = scope:bishop_relic
		position = lower_center_portrait
	}
	court_scene = {
		button_position_character = scope:bishop
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:bishop = {
				group = petitioners_group
				animation = chaplain
			}
			scope:vassal_or_candidate = {
				group = petitioners_group
				animation = disapproval
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

	cooldown = { years = 30 }

	trigger = {
		NOT = { has_character_flag = has_had_county_request_event }
		top_liege = this
		exists = cp:councillor_court_chaplain
		cp:councillor_court_chaplain = {
			has_court_event_flag = no
			is_available_ai_adult = yes
		}
		faith = {
			has_doctrine = doctrine_theocracy_temporal
			NOT = { has_doctrine_parameter = unreformed }
		}
		any_realm_county = { # Less than 10% theocratic counties in realm
			percent <= 0.1
			holder = { government_has_flag = government_is_theocracy }
		}
		any_realm_county = { hold_court_8020_county_trigger = yes } # there is a holy_site in the realm
	}

	weight_multiplier = {
		base = 1
		modifier = { # County has a cathedral
			add = 1
			any_realm_county = {
				hold_court_8020_county_trigger = yes
				any_county_province = {
					barony = { hold_court_8020_cathedral_barony_trigger = yes }
				}
				OR = {
					holder = root
					holder = { is_vassal_of = root }
				}
			}
		}
		modifier = { # No prince bishops in realm
			add = 0.5
			NOT = {
				any_vassal_or_below = {
					primary_title = { tier >= tier_county }
					government_has_flag = government_is_theocracy
				}
			}
		}
		modifier = { # Favor emperors
			add = 1 
			highest_held_title_tier = tier_empire
		}

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

	immediate = {
		add_character_flag = {
			flag = has_had_county_request_event
			years = 15
		}
		cp:councillor_court_chaplain = {
			save_scope_as = bishop
			court_event_character_flag_effect = yes
		}
		hidden_effect = {
			if = {
				limit = { OR = { religion = religion:eastern_orthodox_religion religion = religion:catholic_religion religion = religion:protestant_religion } }
				create_artifact_pedestal_reliquary_christian_effect = { OWNER = scope:bishop }
			}
			else_if = {
				limit = { religion = religion:islam_religion }
				create_artifact_pedestal_reliquary_islam_effect = { OWNER = scope:bishop }
			}
			else_if = {
				limit = { religion = religion:buddhism_religion }
				create_artifact_pedestal_reliquary_buddhism_effect = { OWNER = scope:bishop }
			}
			else_if = {
				limit = { religion = religion:judaism_religion }
				create_artifact_pedestal_reliquary_judaism_effect = { OWNER = scope:bishop }
			}
			else = {
				create_artifact_sculpture_religious_effect = { OWNER = scope:bishop }
			}
			scope:newly_created_artifact = { save_scope_as = bishop_relic }
		}
		if = {
			limit = {
				exists = faith.religious_head
				NOR = {
					faith.religious_head = root
					faith.religious_head = scope:bishop
				}
			}
			faith.religious_head = { save_scope_as = pope }
		}
		every_realm_county = {
			limit = { hold_court_8020_county_trigger = yes }
			add_to_list = potential_princebishoprics
		}
		random_in_list = {
			list = potential_princebishoprics
			limit = {
				holder = root
				any_county_province = {
					barony = { hold_court_8020_cathedral_barony_trigger = yes }
				}
			}
			alternative_limit = {
				any_county_province = {
					barony = { hold_court_8020_cathedral_barony_trigger = yes }
				}
			}
			alternative_limit = { holder = root }
			alternative_limit = { always = yes }
			save_scope_as = target_county
			root = {
				set_variable = { # Save var for custom loc
					name = holy_site_var
					value = scope:target_county
				}
			}
		}
		if = {
			limit = {
				scope:target_county.holder != root
			}
			scope:target_county.holder = {
				save_scope_as = vassal
				court_event_character_flag_effect = yes
			}
		}
		create_character = {
			age = { 30 50 }
			template = priest_character_template
			location = root.capital_province
			trait = devoted
			save_scope_as = candidate
		}
		scope:candidate = {
			court_event_character_flag_effect = yes
		}
		
		if = {
			limit = { exists = scope:vassal }
			scope:vassal = { save_scope_as = vassal_or_candidate }
		}
		else = {
			scope:candidate = { save_scope_as = vassal_or_candidate }
		}

		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = { # Gift the county
		name = hold_court.8020.a
		scope:bishop_relic = {
			set_owner = {
				target = root
				history = {
					location = root.capital_province
					actor = scope:bishop
					recipient = root
					type = given
				}
			}
		}
		hold_court_8020_grant_effect = yes
		scope:target_county = {
			if = {
				limit = {
					any_county_province = {
						barony = { hold_court_8020_cathedral_barony_trigger = yes }
					}
				}
				root = { add_piety = massive_piety_gain }
			}	
			else = {
				root = { add_piety = major_piety_gain }
			}
		}	
		scope:bishop = {
			add_opinion = {
				modifier = pleased_opinion
				target = root
				opinion = 30
			}
		}
		if = {
			limit = { exists = scope:pope }
			scope:pope = {
				add_opinion = {
					modifier = pleased_opinion
					target = root
					opinion = 15
				}
			}
		}
		if = {
			limit = { scope:target_county.holder = root }
			stress_impact = { greedy = medium_stress_impact_gain }
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
   				ai_boldness = -0.5
   				ai_greed = -0.5
   			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = greedy
			}
		}
	}

	option = { # Theocratic debate
		name = hold_court.8020.b
		duel = {
			skill = learning
			target = scope:bishop
			8 = {
				desc = hold_court.8020.b.tt_success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 2
				}
				send_interface_toast = {
					title = hold_court.8020.b.tt_success
					left_icon = scope:bishop
					change_current_court_grandeur = medium_court_grandeur_gain
					add_prestige = medium_prestige_gain
				}
			}
			12 = {
				desc = hold_court.8020.b.tt_failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -1
				}
				send_interface_toast = {
					title = hold_court.8020.b.tt_failure
					left_icon = scope:bishop
					hold_court_8020_grant_effect = yes
					scope:target_county = {
						if = {
							limit = {
								any_county_province = {
									barony = { hold_court_8020_cathedral_barony_trigger = yes }
								}
							}
							root = { add_piety = major_piety_gain }
						}	
						else = {
							root = { add_piety = minor_piety_gain }
						}
					}
					scope:bishop = {
						add_opinion = {
							target = root
							modifier = pleased_opinion
							opinion = 10
						}
					}
					if = {
						limit = { exists = scope:pope }
						scope:pope = {
							add_opinion = {
								target = root
								modifier = pleased_opinion
								opinion = 5
							}
						}
					}
				}
			}
		}
		stress_impact = {
			cynical = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
   				ai_boldness = 0.5
   				ai_greed = 0.5
   			}
   			modifier = {	#Weight down for stress.
				add = -30
				has_trait = cynical
			}
			modifier = {	#Weight up for duel.
				add = 15
				learning > scope:bishop.learning
			}
		}
	}

	option = { # Refuse no pope + no candidate
		name = hold_court.8020.c
		trigger = {
			NOT = { exists = scope:pope }
			scope:target_county.holder = root
		}
		add_piety = minor_piety_loss
		scope:bishop = {
			add_opinion = {
				modifier = refusal_opinion
				target = root			
				opinion = -20
			}
		}
		stress_impact = {
			zealous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
   				ai_boldness = 0.5
   				ai_greed = 0.5
   			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = zealous
			}
		}
	}

	option = { # Refuse no pope + candidate
		name = hold_court.8020.d
		trigger = {
			NOT = { exists = scope:pope }
			scope:target_county.holder != root
		}
		add_piety = minor_piety_loss
		scope:target_county.holder = {
			if = {
				limit = {
					this != root
				}
				add_opinion = {
					modifier = grateful_opinion
					target = root
					opinion = 15
				}
			}
		}
		scope:bishop = {
			add_opinion = {
				modifier = refusal_opinion
				target = root				
				opinion = -10
			}
		}
		stress_impact = {
			zealous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
   				ai_boldness = 0.5
   				ai_greed = 0.5
   			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = zealous
			}
		}
	}

	option = { # Refuse pope + no candidate
		name = hold_court.8020.e
		trigger = {
			exists = scope:pope
			scope:target_county.holder = root
		}
		add_piety = minor_piety_loss
		scope:bishop = {
			add_opinion = {
				modifier = refusal_opinion
				target = root				
				opinion = -20
			}
		}
		scope:pope = {
			add_opinion = {
				modifier = refusal_opinion
				target = root				
				opinion = -10
			}
		}
		stress_impact = {
			zealous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
   				ai_boldness = 0.5
   				ai_greed = 0.5
   			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = zealous
			}
		}
	}

	option = { # Refuse pope + candidate
		name = hold_court.8020.e
		trigger = {
			exists = scope:pope
			scope:target_county.holder != root
		}
		add_piety = minor_piety_loss
		scope:target_county.holder = {
			add_opinion = {
				modifier = grateful_opinion
				target = root
				opinion = 15
			}
		}
		scope:bishop = {
			add_opinion = {
				modifier = refusal_opinion
				target = root				
				opinion = -10
			}
		}
		
		scope:pope = {
			add_opinion = {
				modifier = refusal_opinion
				target = root				
				opinion = -5
			}
		}
		stress_impact = {
			zealous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
   				ai_boldness = 0.5
   				ai_greed = 0.5
   			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = zealous
			}
		}
	}

	after = {
		scope:bishop = {
			clear_court_event_participation = yes
		}
		if = {
			limit = { exists = scope:vassal }
			scope:vassal = {
				clear_court_event_participation = yes
			}
		}
		if = {
			limit = { exists = scope:candidate }
			scope:candidate = {
				clear_court_event_participation = yes
				if = {
					limit = {
						is_alive = yes
						is_landed = no
					}
					silent_disappearance_effect = yes
				}
			}
		}
		remove_variable = holy_site_var
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

##################################################
# Special Treatment
# by Joe Parkin
# 8040
##################################################

scripted_trigger hold_court_8040_vassal_trigger = {
	has_court_event_flag = no
	faith != root.faith
	faith = {
		NOT = { has_doctrine_parameter = unreformed }
	}
	government_has_flag = government_is_feudal
	vassal_contract_obligation_level_can_be_increased = religious_rights
	liege.faith = {
		faith_hostility_level = {
			target = prev.faith
			value < faith_evil_level
		}
	}
}

# A vassal of another faith asks for religious freedom
hold_court.8040 = {
	type = court_event
	title = hold_court.8040.t
	desc = {
		desc = hold_court.8040.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:infidel_vassal.religion = root.religion
				}
				desc = hold_court.8040.desc.intro_same_religion
			}
			triggered_desc = {
				trigger = {
					always = yes
				}
				desc = hold_court.8040.desc.intro_fallback
			}
		}
	}
	theme = court
	lower_right_portrait = scope:bishop
	court_scene = {
		button_position_character = scope:infidel_vassal
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:infidel_vassal = {
				group = petitioners_group
				animation = worry
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

	cooldown = { years = 10 }

	trigger = {
		faith = {
			NOT = { has_doctrine_parameter = unreformed }
		}
		any_vassal = { hold_court_8040_vassal_trigger = yes }
		exists = cp:councillor_court_chaplain
		cp:councillor_court_chaplain = {
			has_court_event_flag = no
			is_available_ai_adult = yes
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = 1
			any_vassal = { 
				hold_court_8040_vassal_trigger = yes
				is_powerful_vassal = yes
			}
		}

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

	immediate = {
		cp:councillor_court_chaplain = {
			save_scope_as = bishop
			court_event_character_flag_effect = yes
		}
		ordered_vassal = {
			limit = { hold_court_8040_vassal_trigger = yes }
			order_by = max_military_strength
			save_scope_as = infidel_vassal
			court_event_character_flag_effect = yes
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = { # Grant religious rights
		name = hold_court.8040.a
		if = {
			limit = {
				can_add_hook = {
					target = scope:infidel_vassal
					type = indebted_hook
				}
			}
			add_hook = {
				target = scope:infidel_vassal
				type = indebted_hook
			}
		}
		scope:infidel_vassal = {
			vassal_contract_set_obligation_level = {
				type = religious_rights
				level = 1
			}
			add_opinion = {
				modifier = grateful_opinion
				target = root
				opinion = 20
			}
		}
		scope:bishop = {
			if = {
				limit = { scope:infidel_vassal.religion = root.religion }
				add_opinion = {
					modifier = disappointed_opinion
					target = root
					opinion = -10
				}
			}
			else = {
				add_opinion = {
					modifier = disappointed_opinion
					target = root
					opinion = -20
				}
			}
		}
		stress_impact = {
			zealous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
  				ai_compassion = 0.5
  				ai_rationality = 0.25
   			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = zealous
			}
		}
	}

	option = { # Learning debate with same religion
		name = hold_court.8040.b
		trigger = { scope:infidel_vassal.religion = root.religion }
		duel = {
			skill = learning
			target = scope:infidel_vassal
			10 = {
				desc = hold_court.8040.c.tt_accept
				compare_modifier = {
					value = scope:duel_value
					multiplier = 1
				}
				send_interface_toast = {
					title = hold_court.8040.c.tt_accept
					left_icon = scope:infidel_vassal
					right_icon = scope:bishop
					add_prestige = medium_prestige_gain
					save_scope_as = actor
					scope:infidel_vassal = { save_scope_as = recipient }
					custom_tooltip = demand_conversion_tt
					hidden_effect = { demand_conversion_interaction_effect = yes }
				}
			}
			10 = {
				desc = hold_court.8040.c.tt_refuse
				compare_modifier = {
					value = scope:duel_value
					multiplier = -1
				}
				send_interface_toast = {
					title = hold_court.8040.c.tt_refuse
					left_icon = scope:infidel_vassal
					right_icon = scope:bishop
					scope:bishop = {
						add_opinion = {
							modifier = disappointed_opinion
							target = root
							opinion = -10
						}
					}
				}
			}
		}
	}

	option = { # Different faith demand
		name = {
			trigger = {
				scope:infidel_vassal.religion != root.religion
			}
			text = hold_court.8040.c.religion
		}
		name = {
			trigger = {
				scope:infidel_vassal.faith != root.faith
			}
			text = hold_court.8040.c.faith
		}
		scope:infidel_vassal = {
			add_opinion = {
				modifier = demanded_my_conversion_opinion
				target = root
				opinion = -10
			}
		}
		random_list = {
			40 = {
				modifier = {
					add = -20
					scope:infidel_vassal.religion != root.religion
				}
				show_chance = no
				desc = hold_court.8040.c.tt_accept
				send_interface_toast = {
					title = hold_court.8040.c.tt_accept
					left_icon = scope:infidel_vassal
					add_piety = medium_piety_gain
					save_scope_as = actor
					scope:infidel_vassal = { save_scope_as = recipient }
					custom_tooltip = demand_conversion_tt
					hidden_effect = { demand_conversion_interaction_effect = yes }
					scope:bishop = {
						add_opinion = {
							modifier = pious_opinion
							target = root
							opinion = 10
						}
					}
				}
			}
			60 = {
				show_chance = no
				desc = hold_court.8040.c.tt_refuse
				send_interface_toast = {
					title = hold_court.8040.c.tt_refuse
					left_icon = scope:infidel_vassal
					stress_impact = { zealous = medium_stress_impact_gain }
				}
			}
		}
		stress_impact = {
			cynical = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
			humble = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 0.5
  				ai_compassion = -0.5
  				ai_rationality = -0.25
   			}
   			modifier = {	#Weight down for stress.
				add = -30
				has_trait = compassionate
			}
   			modifier = {	#Weight down for stress.
				add = -30
				has_trait = cynical
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = humble
			}
		}
	}

	option = { # Refuse
		name = hold_court.8040.d
		add_piety = minor_piety_gain
		scope:infidel_vassal = {
			add_opinion = {
				modifier = disappointed_opinion
				target = root
				opinion = -5
			}
		}
		scope:bishop = {
			add_opinion = {
				modifier = disappointed_opinion
				target = root
				opinion = -5
			}
		}
	}

	after = {
		scope:bishop = {
			clear_court_event_participation = yes
		}
		scope:infidel_vassal = {
			clear_court_event_participation = yes
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

##################################################
# Royal Service
# by Joe Parkin
# 8050 - 054
##################################################

scripted_trigger hold_court_8050_knight_trigger = {
	has_court_event_flag = no
	is_available_ai_adult = yes
	is_landed = no
	faith = root.faith
	top_liege = root
	NOT = { is_primary_heir_of = prev } # prev = scope:vassal
	NOT = { is_knight_of = root }
	NOT = { has_relation_rival = root }
	NOT = { is_close_family_of = root }
	court_position_martial_trigger = { EMPLOYER = root }
}

scripted_trigger hold_court_8050_vassal_trigger = {
	has_court_event_flag = no
	is_available_ai_adult = yes
	NOT = { is_close_family_of = root }
	NOT = { has_relation_rival = root }
	NOT = { has_court_position = bodyguard_court_position }
	OR = {
		any_close_or_extended_family_member = { hold_court_8050_knight_trigger = yes }
		any_courtier = {
			has_relation_friend = prev
			hold_court_8050_knight_trigger = yes
		}
		is_ai = no
	}
}

scripted_effect hold_court_8050_accepted_knight_effect = {
	scope:knight = {
		hidden_effect = {
			if = {
				limit = {
					is_foreign_court_or_pool_guest = yes
				}
				return_to_court = yes
			}
			set_employer = root
			set_knight_status = force
		}
		set_variable = {
			name = hold_court_8050_knight
			value = scope:vassal
			years = 10
		}
		add_prestige = minor_prestige_gain
		add_opinion = {
			modifier = grateful_opinion
			target = root
			opinion = 20
		}
	}
	trigger_event = {
		id = hold_court.8054
		days = 365
	}
	send_interface_message = {
		title = hold_court.8050.a.tt_toast
		left_icon = scope:knight
		right_icon = scope:vassal
		scope:knight = { custom_tooltip = hold_court.8050.a.tt_knight }
	}
}

# Vassal presents their relative as a potential knight
hold_court.8050 = {
	type = court_event
	title = hold_court.8050.t
	desc = {
		desc = hold_court.8050.desc
		first_valid = {
			triggered_desc = {
				trigger = { scope:knight.prowess >= extremely_high_skill_rating }
				desc = hold_court.8050.desc_talented
			}
			triggered_desc = {
				trigger = { scope:knight.prowess >= decent_skill_rating }
				desc = hold_court.8050.desc_suitable
			}
			triggered_desc = {
				trigger = { scope:knight.prowess >= mediocre_skill_rating }
				desc = hold_court.8050.desc_passing
			}
			desc = hold_court.8050.desc_unsuitable
		}
	}
	theme = court
	lower_right_portrait = scope:grandmaster
	lower_center_portrait = {
		character = scope:bodyguard
		trigger = {
			scope:knight.prowess > medium_skill_rating
			NOT = {
				scope:vassal = { has_hook = root }
			}
		}
	}
	court_scene = {
		button_position_character = scope:vassal
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:vassal = {
				group = petitioners_group
				animation = admiration
			}
			scope:knight = {
				group = petitioners_group
				animation = marshal
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

	cooldown = { years = 15 }
	
	trigger = {
		any_vassal = { hold_court_8050_vassal_trigger = yes }
		NOT = { has_character_flag = hold_court_8051_flag }
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = 1
			number_of_knights < max_number_of_knights
		}

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

	immediate = {
		random_vassal = { # Find a vassal with someone to present
			limit = { hold_court_8050_vassal_trigger = yes }
			save_scope_as = vassal
			court_event_character_flag_effect = yes
			if = {
				limit = {
					any_close_or_extended_family_member = { hold_court_8050_knight_trigger = yes }
				}
				random_close_or_extended_family_member = {
					limit = { hold_court_8050_knight_trigger = yes }
					save_scope_as = knight
					set_signature_weapon_effect = yes
				}
			}
			else_if = {
				limit = {
					any_courtier = {
						has_relation_friend = scope:vassal
						hold_court_8050_knight_trigger = yes
					}
				}
				random_courtier = {
					limit = {
						has_relation_friend = scope:vassal
						hold_court_8050_knight_trigger = yes
					}
					save_scope_as = knight
					set_signature_weapon_effect = yes
				}
			}
			else = {
				create_character = {
					gender_female_chance = root_soldier_female_chance
					location = scope:vassal.capital_province
					template = soldier_friend_character
					dynasty = generate
					save_scope_as = knight
				}
				scope:knight = { set_signature_weapon_effect = yes }
			}
		}
		scope:knight = {
			court_event_character_flag_effect = yes
		}
		faith = { # Find a holy order
			if = {
				limit = {
					any_faith_holy_order = { always = yes }
				}
				random_faith_holy_order = {
					limit = {
						leader = { NOT = { has_relation_rival = scope:knight } }
					}
					alternative_limit = { always = yes }
					leader = { save_scope_as = grandmaster }
				}
			}
		}
		if = {
			limit = {
				any_court_position_holder = {
					type = bodyguard_court_position
					count >= 2
					this != scope:vassal
				}
			}
			ordered_court_position_holder = {
				type = bodyguard_court_position
				limit = {
					this != scope:vassal
				}
				order_by = {
					value = 0
					subtract = prowess
				}
				save_scope_as = bodyguard
			}
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = { # Accept
		name = hold_court.8050.a
		highlight_portrait = scope:knight
		set_variable = {
			name = hold_court_8050_promise
			value = scope:knight
			years = 10
		}
		scope:vassal = {
			add_opinion = {
				modifier = grateful_opinion
				target = root
				opinion = 10
			}
			if = {
				limit = { has_hook = root }
				custom_tooltip = hold_court.8050.a.tt_hook
				remove_hook = { target = root }
			}
		}
		hold_court_8050_accepted_knight_effect = yes
		stress_impact = {
			gallant = medium_stress_impact_loss
			paranoid = medium_stress_impact_gain
			shy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = 0.5
				ai_compassion = 0.25
			}
			modifier = {
				add = 30
				number_of_knights < max_number_of_knights
			}
			modifier = {	#Weight up for stress.
				add = 30
				has_trait = gallant
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = paranoid
			}
		}
	}

	option = { # Take a hook if they suck
		name = hold_court.8050.b
		trigger = {
			scope:knight.prowess < medium_skill_rating
			NOR = {
				scope:vassal = { has_hook = root }
				root = { has_hook = scope:vassal }
			}
		}
		highlight_portrait = scope:vassal
		set_variable = {
			name = hold_court_8050_promise
			value = scope:knight
			years = 10
		}
		scope:vassal = {
			add_opinion = {
				modifier = annoyed_opinion
				target = root
				opinion = -10
			}
		}
		if = {
			limit = {
				can_add_hook = {
					target = scope:vassal
					type = indebted_hook
				}
			}
			add_hook = {
				target = scope:vassal
				type = indebted_hook
			}
		}
		hold_court_8050_accepted_knight_effect = yes
		stress_impact = {
			generous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 0.5
				ai_rationality = 0.25
				ai_compassion = -0.25
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = generous
			}
		}
	}

	option = { # Send to Holy Order instead
		name = hold_court.8050.c
		trigger = {
			has_trait = zealous
			exists = scope:grandmaster
			NOT = {
				scope:vassal = { has_hook = root }
			}
			NOT = { # unlikely to be the case, but since they are more complicated to break, let's just avoid breaking grand wedding
				scope:knight = { has_been_promised_grand_wedding = yes }
			}
		}
		trait = zealous
		highlight_portrait = scope:grandmaster
		add_piety = medium_piety_gain
		scope:vassal = {
			add_opinion = {
				modifier = disappointed_opinion
				target = root
				opinion = -5
			}
		}
		scope:knight = {
			add_trait = order_member
			if = {
				limit = { is_married = yes }
				every_spouse = { divorce = scope:knight }
			}
			if = {
				limit = { exists = betrothed }
				break_betrothal = betrothed
			}
		}
		scope:grandmaster = {
			add_courtier = scope:knight
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 10
			}
		}
		stress_impact = {
			cynical = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = 2
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = cynical
			}
		}
	}

	option = { # Make them your new bodyguard
		name = hold_court.8050.d
		trigger = {
			scope:knight.prowess > medium_skill_rating
			scope:vassal = {
				NOR = {
					has_hook = root
					has_court_position = bodyguard_court_position
				}
			}
		}
		scope:vassal = {
			add_opinion = {
				modifier = grateful_opinion
				target = root
				opinion = 15
			}
		}
		set_variable = {
			name = hold_court_8050_promise
			value = scope:knight
			years = 10
		}
		add_courtier = scope:knight
		scope:knight = {
			hidden_effect = { return_to_court = yes }			
			add_opinion = {
				modifier = grateful_opinion
				target = root
				opinion = 30
			}
			hidden_effect = {
				add_prestige = medium_prestige_gain
				progress_towards_friend_effect = {
					REASON = friend_hired_body_guard
					CHARACTER = root
					OPINION = 0
				}
			}
			set_variable = {
				name = hold_court_8050_knight
				value = scope:vassal
				years = 10
			}
		}
		if = {
			limit = { exists = scope:bodyguard }
			revoke_court_position = {
				recipient = scope:bodyguard
				court_position = bodyguard_court_position
			}
			scope:bodyguard = {
				add_opinion = {
					target = root
					modifier = disappointed_opinion
					opinion = -10
				}
			}
		}
		if = {
			limit = {
				can_appoint_char_to_court_position = {
					CHAR = scope:knight
					COURT_POS = bodyguard_court_position
				}
			}
			court_position_grant_effect = {
				EMPLOYER = root
				POS = bodyguard
				CANDIDATE = scope:knight
			}
		}
		hidden_effect = {
			send_interface_message = {
				title = hold_court.8050.a.tt_toast
				left_icon = scope:knight
				right_icon = scope:vassal
				scope:knight = { custom_tooltip = hold_court.8050.d.tt_bodyguard }
			}
		}
		trigger_event = {
			id = hold_court.8054
			days = 365
		}
		stress_impact = {
			paranoid = medium_stress_impact_gain
			shy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 0.5
				ai_rationality = 0.5
				ai_compassion = 0.25
			}
			modifier = {	#Weight up.
				add = 30
				scope:knight.prowess > decent_skill_rating
			}
			modifier = {	#Weight up.
				add = 30
				scope:knight.prowess > very_high_skill_rating
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = paranoid
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = shy
			}
		}
	}

	option = { # Refuse
		name = {
			trigger = {
				scope:knight.prowess >= 20
			}
			text = hold_court.8050.e.talented
		}
		name = {
			trigger = {
				scope:knight.prowess < 20
				scope:knight.prowess >= 14
			}
			text = hold_court.8050.e.suitable
		}
		name = {
			trigger = {
				scope:knight.prowess < 14
				scope:knight.prowess >= 8
			}
			text = hold_court.8050.e.passing
		}
		name = {
			trigger = {
				scope:knight.prowess < 8
			}
			text = hold_court.8050.e.unsuitable
		}
		trigger = {
			NOT = {
				scope:vassal = { has_hook = root }
			}
		}
		scope:vassal = {
			add_opinion = {
				modifier = refusal_opinion
				target = root
				opinion = -10
			}
		}
		scope:knight = {
			add_prestige = minor_prestige_loss
			add_opinion = {
				modifier = refusal_opinion
				target = root
				opinion = -20
			}
			progress_towards_rival_effect = {
				CHARACTER = root
				REASON = rival_refused_service
				OPINION = 0
			}
		}
		stress_impact = {
			compassionate = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = -0.5
			}
			modifier = {
				add = 15
				scope:knight.prowess < 10
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = compassionate
			}
		}
	}

	after = {
		scope:vassal = {
			clear_court_event_participation = yes
		}
		scope:knight = {
			clear_court_event_participation = yes
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

scripted_trigger hold_court_8050_angry_trigger = {
	OR = {
		prowess >= high_skill_rating
		has_trait = vengeful
		has_trait = wrathful
		has_trait = just
		has_trait = honest
		has_trait = ambitious
		has_trait = arrogant
		has_trait = brave
		AND = {
			has_variable = hold_court_8050_knight
			var:hold_court_8050_knight = {
				is_alive = yes
				is_vassal_of = root
				has_relation_friend = prev # prev = scope:vassal
			}
		}
	}
}

scripted_effect hold_court_8051_promise_opinion_effect = {
	if = {
		limit = {
			has_opinion_modifier = {
				modifier = grateful_opinion
				target = root
			}
		}
		remove_opinion = {
			modifier = grateful_opinion
			target = root
		}
	}
	add_opinion = {
		modifier = broke_promise
		target = root
	}
}

# Vassal is angry you fired the knight
hold_court.8051 = {
	type = court_event
	title = hold_court.8051.t
	desc = hold_court.8051.desc
	theme = court
	court_scene = {
		button_position_character = scope:vassal
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:vassal = {
				group = petitioners_group
				animation = anger
			}
			scope:knight = {
				group = petitioners_group
				animation = shame
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

	weight_multiplier = {
		base = 1
		modifier = {
		 	add = 3
			var:hold_court_8050_promise = { hold_court_8050_angry_trigger = yes }
		}

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

	immediate = {
		var:hold_court_8050_promise = {
			save_scope_as = knight
			var:hold_court_8050_knight = { save_scope_as = vassal }
		}
		add_character_flag = {
			flag = hold_court_8051_flag
			years = 15
		}
	}

	option = { # Reinstate
		name = hold_court.8051.a
		scope:knight = {
			if = {
				limit = { scope:knight.employer = root }
				custom_tooltip = hold_court.8051.a.tt_knight
			}
			else = {
				hidden_effect = { set_employer = root }
				custom_tooltip = hold_court.8050.a.tt_knight
			}
			hidden_effect = { set_knight_status = force }
		}
		stress_impact = {
			arbitrary = medium_stress_impact_gain
		}
		trigger_event = {
			id = hold_court.8054
			days = 365
		}	
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = -0.25
				ai_honor = -0.25
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = arbitrary
			}
		}
	}

	option = { # Refuse
		name = hold_court.8051.b
		scope:vassal = { hold_court_8051_promise_opinion_effect = yes }
		scope:knight = { 
			hold_court_8051_promise_opinion_effect = yes
			hidden_effect = {
				return_to_court = yes
				set_employer = scope:vassal
			}
			custom_tooltip = hold_court.8051.b.tt_return
		}
		remove_variable = hold_court_8050_promise
		stress_impact = {
			just = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = -0.25
				ai_honor = -0.25
			}
			modifier = {
				add = 15
				scope:knight.prowess < 10
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = just
			}
		}
	}
}

# Vassal is apoplectic! You the fired knight again!
hold_court.8052 = {
	type = court_event
	title = hold_court.8052.t
	desc = {
		desc = hold_court.8052.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:vassal = { has_trait = wrathful }
				}
				desc = hold_court.8052.desc.wrath
			}
			desc = hold_court.8052.desc.fallback
		}
	}
	theme = court
	court_scene = {
		button_position_character = scope:vassal
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:vassal = {
				group = petitioners_group
				animation = rage
			}
			scope:knight = {
				group = petitioners_group
				animation = marshal
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

	weight_multiplier = {
		base = 1
		modifier = {
		 	add = 3
			var:hold_court_8050_promise = { hold_court_8050_angry_trigger = yes }
		}

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

	immediate = {
		var:hold_court_8050_promise = {
			save_scope_as = knight
			var:hold_court_8050_knight = { save_scope_as = vassal }
			remove_variable = hold_court_8050_knight
		}
		scope:vassal = { hold_court_8051_promise_opinion_effect = yes }
		scope:knight = { hold_court_8051_promise_opinion_effect = yes }
	}

	option = { # Oh get over it
		name = hold_court.8052.a
		scope:knight = {
			hidden_effect = {
				return_to_court = yes
				set_employer = scope:vassal
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_vengefulness = -0.5
				ai_boldness = -0.5
			}
		}
	}

	option = { # Arrest them
		name = hold_court.8052.b
		trigger = {
			scope:vassal = { has_trait = wrathful }
			OR = {
				has_trait = vengeful
				has_trait = wrathful
				has_trait = arrogant
			}
		}
		trait = vengeful
		trait = wrathful
		trait = arrogant
		imprison_character_effect = {
			TARGET = scope:vassal
			IMPRISONER = root
		}
		scope:vassal = { hold_court_8051_promise_opinion_effect = yes }
		scope:knight = {
			hold_court_8051_promise_opinion_effect = yes
			hidden_effect = {
				return_to_court = yes
				set_employer = scope:vassal
			}
		}
		stress_impact = {
			just = medium_stress_impact_gain
			forgiving = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_vengefulness = 2
				ai_boldness = 0.5
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = just
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = forgiving
			}
		}
	}

	after = { remove_variable = hold_court_8050_promise }
}

# Knight dies in your service
hold_court.8053 = {
	type = character_event
	title = hold_court.8053.t
	desc = {
		desc = hold_court.8053.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:knight.killer }
				desc = hold_court.8053.killer
			}
			desc = hold_court.8053.battle
		}
		random_valid = {
			triggered_desc = {
				trigger = { scope:knight.prowess >= 20 }
				desc = hold_court.8053.desc_talented
			}
			triggered_desc = {
				trigger = { scope:knight.prowess >= 14 }
				desc = hold_court.8053.desc_suitable
			}
			triggered_desc = {
				trigger = { scope:knight.prowess >= 8 }
				desc = hold_court.8053.desc_passing
			}
			triggered_desc = {
				trigger = { has_trait = craven }
				desc = hold_court.8053.desc_coward
			}
			triggered_desc = {
				trigger = {
					NOT = { has_trait = craven }
					scope:knight.prowess < 8
				}
				desc = hold_court.8053.desc_unsuitable
			}
		}
		desc = hold_court.8053.desc.body
	}
	theme = court
	override_background = { reference = battlefield }
	left_portrait = {
		character = scope:vassal
		animation = sadness
	}
	right_portrait = {
		character = scope:knight
	}

	trigger = { primary_title.tier >= tier_kingdom }

	immediate = {
		scope:knight = {
			show_as_tooltip = {
				if = {
					limit = { exists = killer }
					death = {
						death_reason = death_battle
						killer = scope:knight.killer
					}
				}
				else = {
					death = { death_reason = death_battle }
				}
			}
		}
	}

	option = { # Oh
		name = hold_court.8053.a
	}
}

scripted_trigger hold_court_8050_fired_trigger = {
	has_variable = hold_court_8050_knight
	this = root.var:hold_court_8050_promise
	is_knight = no
	var:hold_court_8050_knight = {
		is_landed_or_landless_administrative = yes
		is_vassal_or_below_of = root
		NOT = { has_relation_rival = root }
	}
	NOR = {
		has_trait = disfigured
		has_trait = maimed
		has_relation_friend = root
		has_relation_rival = root
		has_court_position = bodyguard_court_position
	}
}

# Trigger for follow up events
hold_court.8054 = {
	hidden = yes

	trigger = {
		has_variable = hold_court_8050_promise
		primary_title.tier >= tier_kingdom }

	immediate = {
		if = {
			limit = { hold_court_8050_fired_trigger = yes }
			if = {
				limit = { has_variable = hold_court_8051_flag }
				trigger_event = hold_court.8052
			}
			else = { trigger_event = hold_court.8051 }
		}
		else = {
			trigger_event = {
				id = hold_court.8054
				days = 365
			}
		}
	}
}

##################################################
# A Temple for X
# by Joe Parkin
# 8060 - 061
##################################################

scripted_trigger hold_court_8060_vassal_trigger = {
	faith = root.faith
	NOR = {
		this = scope:bishop
		is_vassal_of = scope:bishop
	}
}

scripted_effect hold_court_8060_completion_effect = {
	show_as_tooltip = {
		scope:target_county = {
			custom_tooltip = hold_court.8060.a.tt
			add_county_modifier = {
				modifier = hold_court_8060_built_modifier
				years = 20
			}
		}
		scope:bishop = {
			custom_tooltip = hold_court.8060.a.tt
			add_opinion = {
				modifier = pleased_opinion
				target = root
				opinion = 20
			}
		}
	}
}

# Chaplain wants a new Temple built
hold_court.8060 = {
	type = court_event
	title = hold_court.8060.t
	desc = {
		desc = hold_court.8060.desc
		first_valid = {
			triggered_desc = {
				trigger = { scope:target_county.holder = root }
				desc = hold_court.8060.desc.owned
			}
			triggered_desc = {
				trigger = {
					exists = scope:vassal
					scope:vassal = { is_vassal_of = root }
				}
				desc = hold_court.8060.desc.vassal
			}
			desc = hold_court.8060.desc.subvassal
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:target_county = {
						any_county_province = { has_holding_type = church_holding }
					}
				}
				desc = hold_court.8060.desc.existing
			}
			desc = hold_court.8060.desc.first
		}
		desc = hold_court.8060.desc.end
	}
	theme = realm
	lower_left_portrait = scope:vassal
	lower_center_portrait = scope:subvassal
	court_scene = {
		button_position_character = scope:bishop
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:bishop = {
				group = petitioners_group
				animation = chaplain
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

	cooldown = { years = 15 }

	trigger = {
		exists = cp:councillor_court_chaplain
		cp:councillor_court_chaplain = {
			has_court_event_flag = no
			is_available_ai_adult = yes
		}
		NOT = { has_character_flag = has_had_holding_request_event }
		NOT = { has_variable = hold_court_8060_church_var }
		gold > hold_court_holding_cost_double_value
		faith = {
			has_doctrine = doctrine_theocracy_temporal
			NOT = { has_doctrine_parameter = unreformed }
		}
		OR = {
			any_held_title = {
				county_has_empty_province_trigger = yes
				faith = ROOT.faith
			}
			any_sub_realm_county = {
				faith = root.faith
				holder = {
					NOR = {
						this = root.cp:councillor_court_chaplain
						is_vassal_of = root.cp:councillor_court_chaplain
					}
				}
				any_county_province = { province_has_no_holding_trigger = yes }
			}
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = 2
			any_held_title = {
				title_tier = county
				county_has_empty_province_trigger = yes
				faith = ROOT.faith
				county_has_no_church_trigger = yes
			}
		}
		modifier = {
			add = 1
			any_held_title = {
				title_tier = county
				county_has_empty_province_trigger = yes
				faith = ROOT.faith
				county_has_all_holding_types = yes
			}
		}
		modifier = {
			add = -2
			cp:councillor_court_chaplain.learning < 10
		}

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

	immediate = {
		add_character_flag = {
			flag = has_had_holding_request_event
			years = 15
		}
		cp:councillor_court_chaplain = {
			save_scope_as = bishop
			court_event_character_flag_effect = yes
		}
		if = { # root's counties...
			limit = {
				any_held_title = {
					county_has_empty_province_trigger = yes
					faith = ROOT.faith
				}
			}
			ordered_held_title = {
				limit = {
					county_has_empty_province_trigger = yes
					faith = ROOT.faith
					county_has_no_church_trigger = yes
				}
				alternative_limit = {
					county_has_empty_province_trigger = yes
					faith = ROOT.faith
					county_has_all_holding_types = yes
				}
				alternative_limit = { county_has_empty_province_trigger = yes }
				order_by = development_level
				save_scope_as = target_county
			}
		}
		else = { # ... vassal counties
			ordered_sub_realm_county = {
				limit = {
					holder = {
						is_vassal_of = ROOT
						hold_court_8060_vassal_trigger = yes
					}
					faith = ROOT.faith
					any_county_province = { province_has_no_holding_trigger = yes }
					county_has_no_church_trigger = yes
				}
				alternative_limit = {
					holder = {
						is_vassal_of = ROOT
						hold_court_8060_vassal_trigger = yes
					}
					faith = ROOT.faith
					any_county_province = {	province_has_no_holding_trigger = yes }
					county_has_all_holding_types = yes
				}
				alternative_limit = {
					holder = {
						is_vassal_of = ROOT
						hold_court_8060_vassal_trigger = yes
					}
					faith = ROOT.faith
					any_county_province = { province_has_no_holding_trigger = yes }
				}
				alternative_limit = {
					holder = { hold_court_8060_vassal_trigger = yes }
					faith = ROOT.faith
					any_county_province = { province_has_no_holding_trigger = yes }
					county_has_no_church_trigger = yes
				}
				alternative_limit = {
					holder = { hold_court_8060_vassal_trigger = yes }
					faith = ROOT.faith
					any_county_province = { province_has_no_holding_trigger = yes }
					county_has_all_holding_types = yes
				}
				alternative_limit = {
					holder = { hold_court_8060_vassal_trigger = yes }
					faith = ROOT.faith
					any_county_province = { province_has_no_holding_trigger = yes }
				}
				order_by = development_level
				save_scope_as = target_county
				holder = {
					if = {
						limit = {
							NOT = { is_vassal_of = root }
						}
						liege = { save_scope_as = vassal }
						save_scope_as = subvassal
					}
					else = { save_scope_as = vassal }
				}
			}
		}
		scope:target_county = {
			random_county_province = {
				limit = { province_has_no_holding_trigger = yes }
				save_scope_as = target_province
			}
		}
		if = {
			limit = {
				any_court_position_holder = { type = royal_architect_court_position }
			}
			random_court_position_holder = {
				type = royal_architect_court_position
				save_scope_as = royal_architect
			}
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = { # Pay for the Temple
		name = hold_court.8060.a
		trigger = {
			trigger_if = {
				limit = {
					is_ai = yes
				}
				short_term_treasury_or_gold >= major_treasury_or_gold_value
			}
		}
		remove_treasury_or_gold = hold_court_holding_cost_cheaper_value
		scope:target_province = {
			begin_create_holding = {
				type = church_holding
				refund_cost = { gold = hold_court_holding_cost_cheaper_value }
			}
		}
		hold_court_8060_completion_effect = yes
		if = {
			limit = { exists = scope:vassal }
			scope:vassal = {
				add_opinion = {
					modifier = grateful_opinion
					target = root
					opinion = 10
				}
			}
		}
		if = {
			limit = { exists = scope:subvassal }
			scope:subvassal = {
				add_opinion = {
					modifier = grateful_opinion
					target = root
					opinion = 10
				}
			}
		}
		set_variable = {
			name = hold_court_8060_church_var
			value = scope:target_province
			years = 6
		}
		stress_impact = {
			greedy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = -0.5
				ai_zeal = 0.5
				ai_rationality = 0.25
				ai_compassion = 0.25
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = greedy
			}
		}
	}

	option = { # Get the Vassal to pay half
		name = hold_court.8060.b
		trigger = {
			exists = scope:vassal
			scope:vassal = { is_vassal_of = root }
			scope:vassal.short_term_gold >= hold_court_holding_cost_half_value
		}
		show_as_unavailable = { scope:vassal.short_term_gold < hold_court_holding_cost_half_value }
		highlight_portrait = scope:vassal
		remove_treasury_or_gold = hold_court_holding_cost_half_value
		scope:vassal = {
			remove_treasury_or_gold = hold_court_holding_cost_half_value
			add_opinion = {
				modifier = annoyed_opinion
				target = root
				opinion = -15
			}
		}
		scope:target_province = {
			begin_create_holding = {
				type = church_holding
				refund_cost = { gold = hold_court_holding_cost_half_value }
			}
		}
		hold_court_8060_completion_effect = yes
		set_variable = {
			name = hold_court_8060_church_var
			value = scope:target_province
			years = 6
		}
		stress_impact = {
			greedy = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = -0.25
				ai_compassion = 0.5
				ai_zeal = 0.25
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = greedy
			}
		}
	}

	option = { # Get the Subvassal to pay half
		name = hold_court.8060.c
		trigger = {
			exists = scope:subvassal
			OR = {
				scope:subvassal.short_term_gold >= hold_court_holding_cost_half_value
				scope:vassal.short_term_gold >= hold_court_holding_cost_half_value
			}
		}
		show_as_unavailable = {
			scope:subvassal.short_term_gold < hold_court_holding_cost_half_value
			scope:vassal.short_term_gold < hold_court_holding_cost_half_value
		}
		highlight_portrait = scope:subvassal
		remove_treasury_or_gold = hold_court_holding_cost_half_value
		scope:subvassal = { # Vassals not happy about paying
			if = {
				limit = { long_term_gold >= hold_court_holding_cost_half_value }
				remove_treasury_or_gold = hold_court_holding_cost_half_value
				add_opinion = {
					target = root
					modifier = annoyed_opinion
					opinion = -15
				}
			}
			else = {
				scope:vassal = {
					remove_treasury_or_gold = hold_court_holding_cost_half_value
					add_opinion = {
						target = root
						modifier = annoyed_opinion
						opinion = -15
					}
				}
			}
		}
		scope:target_province = {
			begin_create_holding = {
				type = church_holding
				refund_cost = { gold = hold_court_holding_cost_half_value }
			}
		}
		hold_court_8060_completion_effect = yes
		set_variable = {
			name = hold_court_8060_church_var
			value = scope:target_province
			years = 6
		}
		stress_impact = {
			greedy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = -0.25
				ai_compassion = 0.5
				ai_zeal = 0.25
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = greedy
			}
		}
	}

	option = { # Architect involved
		name = hold_court.8060.d
		trigger = { exists = scope:royal_architect }
		scope:royal_architect = {
			add_opinion = {
				modifier = grateful_opinion
				target = root
				opinion = 10
			}
			duel = {
				skill = stewardship
				value = average_skill_rating
				6 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = 2
					}
					desc = hold_court.8060.d.tt_success
					send_interface_toast = {
						title = hold_court.8060.d.tt_success
						left_icon = scope:frontier_lord
						root = {
							remove_treasury_or_gold = hold_court_holding_cost_architect_cheaper_value
							scope:target_province = {
								begin_create_holding = {
									type = church_holding
									refund_cost = { gold = hold_court_holding_cost_architect_cheaper_value }
								}
							}
						}
					}
				}
				10 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = -1
					}
					desc = hold_court.8060.d.tt_normal
					send_interface_toast = {
						title = hold_court.8060.d.tt_normal
						left_icon = scope:frontier_lord
						root = {
							remove_treasury_or_gold = hold_court_holding_cost_cheaper_value
							scope:target_province = {
								begin_create_holding = {
									type = church_holding
									refund_cost = { gold = hold_court_holding_cost_cheaper_value }
								}
							}
						}
					}
				}
				4 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = -0.5
					}
					desc = hold_court.8060.d.tt_failure
					send_interface_toast = {
						title = hold_court.8060.d.tt_failure
						left_icon = scope:frontier_lord
						root = {
							remove_treasury_or_gold = hold_court_holding_cost_architect_expensive_value
							scope:target_province = {
								begin_create_holding = {
									type = church_holding
									refund_cost = { gold = hold_court_holding_cost_architect_expensive_value }
								}
							}
						}
					}
				}
			}
		}
		hold_court_8060_completion_effect = yes
		stress_impact = {
			diligent = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_energy = -0.5
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = diligent
			}
		}
	}

	option = { # Refuse
		name = {
			trigger = {
				NOT = { exists = scope:vassal }
			}
			text = hold_court.8060.e.own
		}
		name = {
			trigger = { exists = scope:vassal }
			text = hold_court.8060.e.vassal
		}
		if = {
			limit = { exists = scope:vassal }
			add_piety = miniscule_piety_loss
		}
		else = { add_piety = minor_piety_loss }
		scope:bishop = {
			add_opinion = {
				modifier = disappointed_opinion
				target = root
				opinion = -10
			}
		}
		if = {
			limit = { exists = scope:vassal }
			scope:vassal = {
				add_opinion = {
					modifier = disappointed_opinion
					target = root
					opinion = -5
				}
			}
		}
		if = {
			limit = { exists = scope:subvassal }
			scope:subvassal = {
				add_opinion = {
					modifier = disappointed_opinion
					target = root
					opinion = -5
				}
			}
		}
		stress_impact = {
			zealous = medium_stress_impact_gain
			generous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 0.5
				ai_zeal = -0.5
				ai_compassion = -0.25
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = zealous
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = generous
			}
		}
	}

	after = {
		if = {
			limit = { has_variable = hold_court_8060_church_var }
			trigger_event = {
				id = hold_court.8061
				days = 1830 # 5 years + 5 days
			}
		}
		scope:bishop = {
			clear_court_event_participation = yes
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

# The Temple is complete
hold_court.8061 = {
	type = character_event
	title = hold_court.8061.t
	desc = {
		first_valid = {
			triggered_desc = { # In case you have no bishop on completion
				trigger = {
					exists = scope:bishop
					scope:bishop = { is_alive = yes }
				}
				desc = hold_court.8061.desc.bishop
			}
			desc = hold_court.8061.desc.fallback
		}
		first_valid = {
			triggered_desc = {
				trigger = { scope:target_county.holder = root }
				desc = hold_court.8061.desc.owned
			}
			triggered_desc = {
				trigger = {
					exists = scope:vassal
					scope:vassal = { is_vassal_of = root }
				}
				desc = hold_court.8061.desc.vassal
			}
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:target_county = {
						any_county_province = {
							count >= 2
							has_holding_type = church_holding
						}
					}
				}
				desc = hold_court.8061.desc.existing
			}
			desc = hold_court.8061.desc.first
		}
	}
	theme = realm
	override_background = {
		trigger = {
			NOR = {
				faith = { religion = religion:hinduism_religion }
				faith = { religion = religion:buddhism_religion }
				faith = { religion = religion:jainism_religion }
			}
		}
		reference = temple
	}
	override_background = {
		trigger = {
			OR = {
				faith = { religion = religion:hinduism_religion }
				faith = { religion = religion:buddhism_religion }
				faith = { religion = religion:jainism_religion }
			}
		}
		reference = ep2_holy_site_indian
	}
	left_portrait = {
		character = scope:bishop
		animation = happiness
		trigger = {
			scope:bishop = { is_alive = yes }
		}
	}
	lower_right_portrait = scope:vassal

	trigger = {
		has_variable = hold_court_8060_church_var
		var:hold_court_8060_church_var = {
			OR = {
				county.holder = root
				county.holder.top_liege = root
			}
		}
	}

	immediate = {
		if = {
			limit = { exists = cp:councillor_court_chaplain }
			cp:councillor_court_chaplain = { save_scope_as = bishop }
		}
		var:hold_court_8060_church_var = {
			save_scope_as = target_province
			county = {
				save_scope_as = target_county
				holder = {
					if = {
						limit = {
							this != root
						}
						if = {
							limit = {
								liege != root
							}
							save_scope_as = subvassal
							liege = { save_scope_as = vassal }
						}
						else = { save_scope_as = vassal }
					}
				}
			}
		}
		if = {
			limit = { exists = scope:vassal }
			scope:vassal = {
				add_opinion = {
					modifier = grateful_opinion
					target = root
					opinion = 10
				}
			}
		}
		if = {
			limit = { exists = scope:subvassal }
			scope:subvassal = {
				add_opinion = {
					modifier = grateful_opinion
					target = root
					opinion = 10
				}
			}
		}
		show_as_tooltip = {
			scope:target_county.holder = {
				add_piety = massive_piety_gain
			}
			faith = {
				change_fervor = {
					value = 1
					desc = fervor_gain_built_temple_holding
				}
			}
		}
	}

	option = { # Great
		name = hold_court.8061.a
		if = {
			limit = { exists = scope:vassal }
			add_piety = major_piety_gain
		}
		scope:target_county = {
			add_county_modifier = {
				modifier = hold_court_8060_built_modifier
				years = 25
			}
		}
		scope:bishop = {
			add_opinion = {
				modifier = pleased_opinion
				target = root
				opinion = 20
			}
		}
	}

	after = { remove_variable = hold_court_8060_church_var }
}

##################################################
# The Growth of X
# by Joe Parkin
# 8070 - 071
##################################################

scripted_trigger hold_court_8070_vassal_trigger = { # Vassal who is not the steward
	NOR = {
		this = scope:steward
		is_vassal_of = scope:steward
	}
}

scripted_effect hold_court_8070_completion_effect = { # Show effects once holding is built
	show_as_tooltip = {
		scope:target_county = {
			custom_tooltip = hold_court.8070.a.tt
			add_county_modifier = {
				modifier = hold_court_8070_built_modifier
				years = 25
			}
		}
		scope:steward = {
			custom_tooltip = hold_court.8070.a.tt
			add_opinion = {
				modifier = pleased_opinion
				target = root
				opinion = 20
			}
		}
	}
}

# Steward wants investment in City
hold_court.8070 = {
	type = court_event
	title = hold_court.8070.t
	desc = {
		desc = hold_court.8070.desc.intro
		first_valid = { # County owner descriptions
			triggered_desc = {
				trigger = { scope:target_county.holder = root }
				desc = hold_court.8060.desc.owned
			}
			triggered_desc = {
				trigger = {
					exists = scope:vassal
					scope:vassal = { is_vassal_of = root }
				}
				desc = hold_court.8060.desc.vassal
			}
			desc = hold_court.8060.desc.subvassal
		}
		desc = hold_court.8070.desc.body
		first_valid = { # City number descriptions
			triggered_desc = {
				trigger = {
					scope:target_county = {
						any_county_province = { has_holding_type = city_holding }
					}
				}
				desc = hold_court.8070.desc.existing
			}
			desc = hold_court.8070.desc.first
		}
		desc = hold_court.8070.desc.end
	}
	theme = realm
	lower_right_portrait = scope:vassal
	court_scene = {
		button_position_character = scope:steward
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:steward = {
				group = petitioners_group
				animation = steward
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

	cooldown = { years = 30 }

	trigger = {
		exists = cp:councillor_steward
		cp:councillor_steward = {
			has_court_event_flag = no
			is_available_ai_adult = yes
		}
		NOT = { has_character_flag = has_had_holding_request_event }
		NOT = { has_variable = hold_court_8070_city_var }
		gold > hold_court_holding_cost_double_value
		OR = {
			any_held_title = { county_has_empty_province_trigger = yes }
			any_sub_realm_county = {
				holder = {
					NOR = {
						this = root.cp:councillor_steward
						is_vassal_of = root.cp:councillor_steward
					}
				}
				any_county_province = { province_has_no_holding_trigger = yes }
			}
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = 2
			any_held_title = {
				title_tier = county
				county_has_empty_province_trigger = yes
				county_has_no_city_trigger = yes
			}
		}
		modifier = {
			add = 1
			any_held_title = {
				title_tier = county
				county_has_empty_province_trigger = yes
				county_has_all_holding_types = yes
			}
		}
		modifier = {
			add = -2
			cp:councillor_steward.stewardship < 10
		}

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

	immediate = {
		add_character_flag = {
			flag = has_had_holding_request_event
			years = 15
		}
		cp:councillor_steward = {
			save_scope_as = steward
			court_event_character_flag_effect = yes
		}
		if = { # root's counties...
			limit = {
				any_held_title = { county_has_empty_province_trigger = yes }
			}
			ordered_held_title = {
				limit = {
					county_has_empty_province_trigger = yes
					county_has_no_city_trigger = yes
				}
				alternative_limit = {
					county_has_empty_province_trigger = yes
					county_has_all_holding_types = yes
				}
				alternative_limit = { county_has_empty_province_trigger = yes }
				order_by = development_level
				save_scope_as = target_county
			}
		}
		else = { # ... vassal counties
			ordered_sub_realm_county = {
				limit = {
					holder = {
						is_vassal_of = root
						hold_court_8070_vassal_trigger = yes
					}
					any_county_province = { province_has_no_holding_trigger = yes }
					county_has_no_city_trigger = yes
				}
				alternative_limit = {
					holder = {
						is_vassal_of = root
						hold_court_8070_vassal_trigger = yes
					}
					any_county_province = {	province_has_no_holding_trigger = yes }
					county_has_all_holding_types = yes
				}
				alternative_limit = {
					holder = {
						is_vassal_of = root
						hold_court_8070_vassal_trigger = yes
					}
					any_county_province = { province_has_no_holding_trigger = yes }
				}
				alternative_limit = {
					holder = { hold_court_8070_vassal_trigger = yes }
					any_county_province = { province_has_no_holding_trigger = yes }
					county_has_no_city_trigger = yes
				}
				alternative_limit = {
					holder = { hold_court_8070_vassal_trigger = yes }
					any_county_province = { province_has_no_holding_trigger = yes }
					county_has_all_holding_types = yes
				}
				alternative_limit = {
					holder = { hold_court_8070_vassal_trigger = yes }
					any_county_province = { province_has_no_holding_trigger = yes }
				}
				order_by = development_level
				save_scope_as = target_county
				holder = { save_scope_as = vassal }
			}
		}
		scope:target_county = {
			random_county_province = {
				limit = { province_has_no_holding_trigger = yes }
				save_scope_as = target_province
			}
		}
		if = {
			limit = {
				any_court_position_holder = { type = royal_architect_court_position }
			}
			random_court_position_holder = {
				type = royal_architect_court_position
				save_scope_as = royal_architect
			}
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = { # Pay for the City
		name = hold_court.8070.a
		trigger = {
			trigger_if = {
				limit = {
					is_ai = yes
				}
				short_term_gold >= major_gold_value
			}
		}
		remove_treasury_or_gold = hold_court_holding_cost_cheaper_value
		scope:target_province = {
			begin_create_holding = {
				type = city_holding
				refund_cost = { gold = hold_court_holding_cost_cheaper_value }
			}
		}
		hold_court_8070_completion_effect = yes
		show_as_tooltip = {
			if = {
				limit = { exists = scope:vassal }
				scope:vassal = {
					add_opinion = {
						modifier = grateful_opinion
						target = root
						opinion = 10
					}
				}
			}
			if = {
				limit = { exists = scope:subvassal }
				scope:subvassal = {
					add_opinion = {
						modifier = grateful_opinion
						target = root
						opinion = 10
					}
				}
			}
		}
		set_variable = {
			name = hold_court_8070_city_var
			value = scope:target_province
			years = 6
		}
		stress_impact = {
			greedy = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = -0.5
				ai_rationality = 0.25
				ai_compassion = 0.25
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = greedy
			}
		}
	}

	option = { # Get the Vassal to pay half
		name = hold_court.8070.b
		trigger = {
			exists = scope:vassal
			scope:vassal = { is_vassal_of = root }
			scope:vassal.short_term_gold >= hold_court_holding_cost_half_value
		}
		show_as_unavailable = { scope:vassal.short_term_gold < hold_court_holding_cost_half_value }
		highlight_portrait = scope:vassal
		remove_treasury_or_gold = hold_court_holding_cost_half_value
		scope:vassal = {
			remove_treasury_or_gold = hold_court_holding_cost_half_value
			add_opinion = {
				modifier = annoyed_opinion
				target = root
				opinion = -15
			}
		}
		scope:target_province = {
			begin_create_holding = {
				type = city_holding
				refund_cost = { gold = hold_court_holding_cost_half_value }
			}
		}
		hold_court_8070_completion_effect = yes
		set_variable = {
			name = hold_court_8070_city_var
			value = scope:target_province
			years = 6
		}
		stress_impact = {
			greedy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = -0.25
				ai_rationality = 0.25
				ai_compassion = 0.5
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = greedy
			}
		}
	}

	option = { # Get the Subvassal to pay half
		name = hold_court.8070.c
		trigger = {
			exists = scope:vassal
			exists = scope:subvassal
			OR = {
				scope:subvassal.short_term_gold >= hold_court_holding_cost_half_value
				scope:vassal.short_term_gold >= hold_court_holding_cost_half_value
			}
		}
		show_as_unavailable = {
			scope:subvassal.short_term_gold < hold_court_holding_cost_half_value
			scope:vassal.short_term_gold < hold_court_holding_cost_half_value
		}
		remove_treasury_or_gold = hold_court_holding_cost_half_value
		scope:subvassal = { # Vassals not happy about paying
			if = {
				limit = { long_term_gold >= hold_court_holding_cost_half_value }
				remove_treasury_or_gold = hold_court_holding_cost_half_value
				add_opinion = {
					target = root
					modifier = annoyed_opinion
					opinion = -15
				}
			}
			else = {
				scope:vassal = {
					remove_treasury_or_gold = hold_court_holding_cost_half_value
					add_opinion = {
						target = root
						modifier = annoyed_opinion
						opinion = -15
					}
				}
			}
		}
		scope:target_province = {
			begin_create_holding = {
				type = city_holding
				refund_cost = { gold = hold_court_holding_cost_half_value }
			}
		}
		hold_court_8070_completion_effect = yes
		set_variable = {
			name = hold_court_8070_city_var
			value = scope:target_province
			years = 6
		}
		stress_impact = {
			greedy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = -0.25
				ai_rationality = 0.25
				ai_compassion = 0.5
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = greedy
			}
		}
	}

	option = { # Architect involved
		name = hold_court.8070.d
		trigger = { exists = scope:royal_architect }
		scope:royal_architect = {
			add_opinion = {
				modifier = grateful_opinion
				target = root
				opinion = 10
			}
			duel = {
				skill = stewardship
				value = average_skill_rating
				6 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = 2
					}
					desc = hold_court.8060.d.tt_success
					send_interface_toast = {
						title = hold_court.8060.d.tt_success
						left_icon = scope:royal_architect
						root = {
							remove_treasury_or_gold = hold_court_holding_cost_architect_cheaper_value
							scope:target_province = {
								begin_create_holding = {
									type = city_holding
									refund_cost = { gold = hold_court_holding_cost_architect_cheaper_value }
								}
							}
						}
					}
				}
				10 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = -1
					}
					desc = hold_court.8060.d.tt_normal
					send_interface_toast = {
						title = hold_court.8060.d.tt_normal
						left_icon = scope:royal_architect
						root = {
							remove_treasury_or_gold = hold_court_holding_cost_cheaper_value
							scope:target_province = {
								begin_create_holding = {
									type = city_holding
									refund_cost = { gold = hold_court_holding_cost_cheaper_value }
								}
							}
						}
					}
				}
				4 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = -0.5
					}
					desc = hold_court.8060.d.tt_failure
					send_interface_toast = {
						title = hold_court.8060.d.tt_failure
						left_icon = scope:royal_architect
						root = {
							remove_treasury_or_gold = hold_court_holding_cost_architect_expensive_value
							scope:target_province = {
								begin_create_holding = {
									type = city_holding
									refund_cost = { gold = hold_court_holding_cost_architect_expensive_value }
								}
							}
						}
					}
				}
			}
		}
		hold_court_8070_completion_effect = yes
		stress_impact = {
			diligent = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_energy = -0.5
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = diligent
			}
		}
	}

	option = { # Refuse
		name = hold_court.8070.e
		add_prestige = minor_prestige_loss
		scope:steward = {
			add_opinion = {
				modifier = disappointed_opinion
				target = root
				opinion = -5
			}
		}
		if = {
			limit = { exists = scope:vassal }
			scope:vassal = {
				add_opinion = {
					modifier = disappointed_opinion
					target = root
					opinion = -5
				}
			}
		}
		if = {
			limit = { exists = scope:subvassal }
			scope:subvassal = {
				add_opinion = {
					modifier = disappointed_opinion
					target = root
					opinion = -5
				}
			}
		}
		stress_impact = {
			generous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 0.5
				ai_compassion = -0.25
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = generous
			}
		}
	}

	after = {
		scope:steward = {
			clear_court_event_participation = yes
		}
		if = {
			limit = { has_variable = hold_court_8070_city_var }
			trigger_event = {
				id = hold_court.8071
				days = 1830 # 5 years + 10 days
			}
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

# The City is complete
hold_court.8071 = {
	type = character_event
	title = hold_court.8071.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:steward
					scope:steward = { is_alive = yes }
				}
				desc = hold_court.8071.desc.steward
			}
			desc = hold_court.8071.desc.fallback
		}
		first_valid = {
			triggered_desc = {
				trigger = { scope:target_county.holder = root }
				desc = hold_court.8071.desc.owned
			}
			triggered_desc = {
				trigger = {
					exists = scope:vassal
					scope:vassal = { is_vassal_of = root }
				}
				desc = hold_court.8071.desc.vassal
			}
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:target_county = {
						any_county_province = {
							count >= 2
							has_holding_type = city_holding
						}
					}
				}
				desc = hold_court.8071.desc.existing
			}
			desc = hold_court.8071.desc.first
		}
	}
	theme = realm
	override_background = { reference = market }
	left_portrait = {
		character = scope:steward
		animation = happiness
		trigger = {
			scope:steward = { is_alive = yes }
		}
	}
	lower_right_portrait = scope:vassal

	trigger = {
		has_variable = hold_court_8070_city_var
		var:hold_court_8070_city_var = {
			OR = {
				county.holder = root
				county.holder.top_liege = root
			}
		}
	}

	immediate = {
		if = {
			limit = { exists = cp:councillor_steward }
			cp:councillor_steward = { save_scope_as = steward }
		}
		var:hold_court_8070_city_var = {
			save_scope_as = target_province
			county = {
				save_scope_as = target_county
				holder = {
					if = {
						limit = {
							this != root
						}
						if = {
							limit = {
								liege != root
							}
							save_scope_as = subvassal
							liege = { save_scope_as = vassal }
						}
						else = { save_scope_as = vassal }
					}
				}
			}
		}
		if = {
			limit = { exists = scope:vassal }
			scope:vassal = {
				add_opinion = {
					modifier = grateful_opinion
					target = root
					opinion = 10
				}
			}
		}
		if = {
			limit = { exists = scope:subvassal }
			scope:subvassal = {
				add_opinion = {
					modifier = grateful_opinion
					target = root
					opinion = 10
				}
			}
		}
	}

	option = { # Great
		name = hold_court.8071.a
		scope:target_county = {
			add_county_modifier = {
				modifier = hold_court_8070_built_modifier
				years = 25
			}
		}
		scope:steward = {
			add_opinion = {
				modifier = pleased_opinion
				target = root
				opinion = 20
			}
		}
	}

	after = { remove_variable = hold_court_8070_city_var }
}

##################################################
# The Republic of X
# by Joe Parkin
# 8080
##################################################

scripted_trigger hold_court_8080_mayor_trigger = { # Check mayor's culture, and city wealth
	hold_court_available_mayor_trigger = yes
	culture = { has_innovation = innovation_development_02 }
	primary_title = {
		de_jure_liege = {
			this != root.capital_county
		}
		title_province.combined_building_level >= 5
	}
}

scripted_effect hold_court_8080_grant_effect = { # Grant county to mayor
	create_title_and_vassal_change = {
		type = granted
		save_scope_as = change
		add_claim_on_loss = no
	}
	scope:mayor.primary_title.de_jure_liege = {
		change_title_holder = {
			holder = scope:mayor
			change = scope:change
		}
	}
	resolve_title_and_vassal_change = scope:change
	scope:target_county = {
		add_county_modifier = {
			modifier = hold_court_8080_granted_modifier
			years = 20
		}
	}
}

# Mayor wants rights over a county
hold_court.8080 = {
	type = court_event
	title = hold_court.8080.t
	desc = {
		desc = hold_court.8080.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:target_county = {
						has_coastal_province = yes
					}
				}
				desc = hold_court.8080.desc.body_sea
			}
			desc = hold_court.8080.desc.body_fallback
		}
		desc = hold_court.8080.desc.body
	}
	theme = realm
	court_scene = {
		button_position_character = scope:mayor
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:mayor = {
				group = petitioners_group
				animation = admiration
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

	cooldown = { years = 40 }

	trigger = {
		NOR = {
			has_character_flag = has_had_county_request_event
			has_character_flag = has_had_government_request_event
		}
		top_liege = this
		culture = { has_innovation = innovation_development_02 }
		any_vassal = { hold_court_8080_mayor_trigger = yes }
		NOT = {
			any_sub_realm_county = {
				percent > 0.1
				holder = { government_has_flag = government_is_republic }
			}
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = 1
			any_vassal = {	
				hold_court_8080_mayor_trigger = yes
				primary_title.title_province = { has_building_or_higher = common_tradeport_01 }
			}
		}
		modifier = {
			add = 1
			any_vassal = {	
				hold_court_8080_mayor_trigger = yes
				primary_title = {
					de_jure_liege = {
						has_coastal_province = yes
					}
				}
			}
		}

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

	immediate = {
		add_character_flag = {
			flag = has_had_county_request_event
			years = 15
		}
		add_character_flag = {
			flag = has_had_government_request_event
			years = 15
		}
		ordered_vassal = {
			limit = {
				hold_court_8080_mayor_trigger = yes
				primary_title.title_province = { has_building_or_higher = common_tradeport_01 }
			}
			alternative_limit = {
				hold_court_8080_mayor_trigger = yes
				primary_title = {
					de_jure_liege = {
						has_coastal_province = yes
					}
				}
			}
			alternative_limit = { hold_court_8080_mayor_trigger = yes }
			order_by = primary_title.title_province.combined_building_level
			save_scope_as = mayor
			court_event_character_flag_effect = yes
			primary_title = {
				save_scope_as = target_city
				set_variable = {
					name = hold_court_city_cooldown_var
					years = 10
				}
				de_jure_liege = { save_scope_as = target_county }
			}
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = { # Grant Republican County
		name = hold_court.8080.a
		hold_court_8080_grant_effect = yes
		scope:mayor = {
			add_opinion = {
				modifier = grateful_opinion
				target = root
				opinion = 20
			}
		}
		stress_impact = {
			greedy = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = -2
				ai_compassion = 0.25
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = greedy
			}
		}
	}

	option = { # For a gift
		name = hold_court.8080.b
		if = {
			limit = { scope:mayor.short_term_treasury_or_gold >= root.medium_treasury_or_gold_value }
			scope:mayor = {
				pay_treasury_or_gold = {
					target = root
					value = root.medium_treasury_or_gold_value
				}
			}
		}
		else = { add_treasury_or_gold = major_treasury_or_gold_value }
		hold_court_8080_grant_effect = yes
		stress_impact = {
			generous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = -1
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = generous
			}
		}
	}

	option = { # Offer smaller privileges
		name = hold_court.8080.c
		duel = {
			skill = stewardship
			target = scope:mayor
			8 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 2
				}
				desc = hold_court.8080.c.tt_success
				send_interface_toast = {
					title = hold_court.8080.c.tt_success
					left_icon = scope:mayor
					scope:mayor = {
						add_opinion = {
							modifier = pleased_opinion
							target = root
							opinion = 10
						}
					}
					scope:target_county = {
						add_county_modifier = {
							modifier = hold_court_8080_compromise_modifier
							years = 20
						}
					}
				}
			}
			8 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -1
				}
				desc = hold_court.8080.c.tt_failure
				send_interface_toast = {
					title = hold_court.8080.c.tt_failure
					left_icon = scope:mayor
					add_prestige = minor_prestige_loss
					scope:mayor = {
						add_opinion = {
							modifier = disappointed_opinion
							target = root
							opinion = -10
						}
					}
				}
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 1
				ai_rationality = 0.5
			}
		}
	}

	option = { # Refuse
		name = hold_court.8080.d
		scope:mayor = {
			add_opinion = {
				modifier = disappointed_opinion
				target = root
				opinion = -5
			}
		}
		scope:target_county = {
			add_county_modifier = {
				modifier = hold_court_8080_upset_modifier
				years = 15
			}
		}
		stress_impact = {
			generous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 1
				ai_rationality = 0.5
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = generous
			}
		}
	}

	option = { # Imprison the Mayor
		name = hold_court.8080.e
		imprison_character_effect = {
			TARGET = scope:mayor
			IMPRISONER = root
		}
		add_dread = minor_dread_gain
		add_character_modifier = {
			modifier = hold_court_8080_prison_modifier
			years = 10
		}
		stress_impact = {
			humble = medium_stress_impact_gain
			just = medium_stress_impact_gain
			calm = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = -0.5
				ai_greed = -0.5
				ai_rationality = -0.25
				ai_compassion = -0.25
				ai_boldness = 0.5
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = humble
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = just
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = calm
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = compassionate
			}
		}
	}

	after = {
		scope:mayor = {
			clear_court_event_participation = yes
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

##################################################
# A Place at Court
# by Joe Parkin
# 8090
##################################################

scripted_trigger hold_court_8090_can_move_trigger = {
	has_court_event_flag = no
	AND = {
		has_any_court_position = no
		can_be_employed_as_any_court_position_trigger = yes
	}
	is_available_ai_adult = yes
	is_landed = no
	faith = root.faith
	top_liege = root
	NOT = { is_primary_heir_of = prev } # prev = scope:vassal
	NOT = { has_relation_rival = root }
	NOT = { is_close_family_of = root }
}

scripted_trigger hold_court_8090_candidate_trigger = { # Courtier is not already in a position
	has_court_event_flag = no
	is_available_ai_adult = yes
	OR = {
		AND = {
			has_any_court_position = no
			can_be_employed_as_any_court_position_trigger = yes
		}
		any_close_family_member = { hold_court_8090_can_move_trigger = yes }
	}
}

scripted_effect hold_court_8090_hook_effect = {
	if = {
		limit = {
			NOR = {
				has_relation_lover = $CHAR$
				has_relation_friend = $CHAR$
			}
		}
		if = {
			limit = {
				can_add_hook = {
					target = $CHAR$
					type = indebted_hook
				}
			}
			add_hook = {
				target = $CHAR$
				type = indebted_hook
			}
		}
	}
	else = {
		if = {
			limit = { has_character_modifier = hold_court_8090_favorites_modifier }
			hidden_effect = { remove_character_modifier = hold_court_8090_favorites_modifier }
		}
		add_character_modifier = {
			modifier = hold_court_8090_favorites_modifier
			years = 5
		}
	}
}

# Vassal/courtier wants a Court Position
hold_court.8090 = {
	type = court_event
	title = hold_court.8090.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					NOT = { exists = scope:vassal_advocate }
				}
				desc = hold_court.8090.desc.intro
			}
			desc = hold_court.8090.desc.intro_advocate
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:old_holder
					scope:vassal = { has_relation_rival = scope:old_holder }
				}
				desc = hold_court.8090.desc.rival # RIVAL HOLDS POS
			}
			triggered_desc = {
				trigger = {
					exists = scope:old_holder
					exists = scope:vassal_advocate
				}
				desc = hold_court.8090.desc.other_advocate
			}
			triggered_desc = {
				trigger = { exists = scope:old_holder }
				desc = hold_court.8090.desc.other
			}
			triggered_desc = {
				trigger = {
					NOT = { exists = scope:vassal_advocate }
					scope:vassal = { has_trait = arrogant }
				}
				desc = hold_court.8090.desc.arrogant # FILLED BUT ARROGANT	
			}
			triggered_desc = {
				trigger = {
					NOT = { exists = scope:vassal_advocate }
					scope:vassal = { has_trait = ambitious }
				}
				desc = hold_court.8090.desc.ambitious # FILLED BUT AMBITIOUS
			}
			triggered_desc = {
				trigger = {
					exists = scope:old_holder
					OR = {
						AND = { # Stewardship roles
							scope:vassal.var:target_court_position = flag:royal_architect
							scope:vassal.var:target_court_position = flag:seneschal
							scope:vassal.var:target_court_position = flag:court_gardener
							scope:vassal.var:target_court_position = flag:keeper_of_swans
							scope:vassal.stewardship > scope:old_holder.stewardship
						}
						AND = { # Learning roles
							scope:vassal.var:target_court_position = flag:court_tutor
							scope:vassal.var:target_court_position = flag:high_almoner
							scope:vassal.var:target_court_position = flag:court_physician
							scope:vassal.var:target_court_position = flag:antiquarian
							scope:vassal.var:target_court_position = flag:court_artificer
							scope:vassal.var:target_court_position = flag:chief_qadi
							scope:vassal.var:target_court_position = flag:court_astrologer
							scope:vassal.learning > scope:old_holder.learning
						}
						AND = { # Martial roles
							scope:vassal.var:target_court_position = flag:master_of_horse
							scope:vassal.var:target_court_position = flag:bodyguard
							scope:vassal.var:target_court_position = flag:champion
							scope:vassal.var:target_court_position = flag:master_of_hunt
							scope:vassal.var:target_court_position = flag:garuda
							scope:vassal.martial > scope:old_holder.martial
							scope:vassal.var:target_court_position = flag:akolouthos
						}
						AND = { # Diplomacy roles
							scope:vassal.var:target_court_position = flag:court_poet
							scope:vassal.var:target_court_position = flag:court_musician
							scope:vassal.var:target_court_position = flag:cupbearer
							scope:vassal.var:target_court_position = flag:lady_in_waiting
							scope:vassal.var:target_court_position = flag:cultural_emissary
							scope:vassal.diplomacy > scope:old_holder.diplomacy
						}
						AND = { # Intrigue roles
							scope:vassal.var:target_court_position = flag:chief_eunuch
							scope:vassal.intrigue > scope:old_holder.intrigue
						}
					}
				}
				desc = hold_court.8090.desc.superior # Position is occupied but by someone worse at it
			}
		}
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:vassal_advocate }
				desc = hold_court.8090.desc.empty_advocate
			}
			desc = hold_court.8090.desc.empty
		}
		random_valid = {
			triggered_desc = {
				trigger = {
					scope:vassal.var:target_court_position = flag:royal_architect
					scope:vassal = { has_trait = architect }
				}
				desc = hold_court_8090_interest_architect
			}
			triggered_desc = {
				trigger = {
					scope:vassal.var:target_court_position = flag:seneschal
					scope:vassal = { has_trait = administrator }
				}
				desc = hold_court_8090_interest_seneschal_administrator
			}
			triggered_desc = {
				trigger = {
					scope:vassal.var:target_court_position = flag:seneschal
					scope:vassal = { is_eunuch_trigger = yes }
				}
				desc = hold_court_8090_interest_seneschal_eunuch
			}
			triggered_desc = {
				trigger = {
					scope:vassal.var:target_court_position = flag:high_almoner
					scope:vassal = { has_trait = improvident }
				}
				desc = hold_court_8090_interest_almoner
			}
			triggered_desc = {
				trigger = {
					scope:vassal.var:target_court_position = flag:court_physician
					scope:vassal = { has_trait = lifestyle_physician }
				}
				desc = hold_court_8090_interest_physician_experience
			}
			triggered_desc = {
				trigger = {
					scope:vassal.var:target_court_position = flag:court_physician
					scope:vassal = { has_trait = lifestyle_mystic }
				}
				desc = hold_court_8090_interest_physician_mystic
			}
			triggered_desc = {
				trigger = {
					scope:vassal.var:target_court_position = flag:court_physician
					scope:vassal = { has_trait = lifestyle_herbalist }
				}
				desc = hold_court_8090_interest_physician_herbalist
			}
			triggered_desc = {
				trigger = {
					scope:vassal.var:target_court_position = flag:antiquarian
					scope:vassal = { has_trait = scholar }
				}
				desc = hold_court_8090_interest_antiquarian
			}
			triggered_desc = {
				trigger = {
					scope:vassal.var:target_court_position = flag:master_of_horse
					scope:vassal = { has_trait = overseer }
				}
				desc = hold_court_8090_interest_horse
			}
			triggered_desc = {
				trigger = {
					OR = {
						scope:vassal.var:target_court_position = flag:bodyguard
						scope:vassal.var:target_court_position = flag:akolouthos
					}
					has_relation_soulmate = scope:vassal
				}
				desc = hold_court_8090_interest_bodyguard_soulmate
			}
			triggered_desc = {
				trigger = {
					OR = {
						scope:vassal.var:target_court_position = flag:bodyguard
						scope:vassal.var:target_court_position = flag:akolouthos
					}
					has_relation_lover = scope:vassal
				}
				desc = hold_court_8090_interest_bodyguard_lover
			}
			triggered_desc = {
				trigger = {
					OR = {
						scope:vassal.var:target_court_position = flag:bodyguard
						scope:vassal.var:target_court_position = flag:akolouthos
					}
					has_relation_best_friend = scope:vassal
				}
				desc = hold_court_8090_interest_bodyguard_bestie
			}
			triggered_desc = {
				trigger = {
					OR = {
						scope:vassal.var:target_court_position = flag:bodyguard
						scope:vassal.var:target_court_position = flag:akolouthos
					}
					has_relation_friend = scope:vassal
				}
				desc = hold_court_8090_interest_bodyguard_friend
			}
			triggered_desc = {
				trigger = {
					OR = {
						scope:vassal.var:target_court_position = flag:champion
						scope:vassal.var:target_court_position = flag:garuda
					}
					scope:vassal = { has_trait = lifestyle_blademaster }
				}
				desc = hold_court_8090_interest_champion
			}
			triggered_desc = {
				trigger = {
					scope:vassal.var:target_court_position = flag:master_of_hunt
					scope:vassal = { has_trait = lifestyle_hunter }
				}
				desc = hold_court_8090_interest_hunt
			}
			triggered_desc = {
				trigger = {
					scope:vassal.var:target_court_position = flag:court_poet
					scope:vassal = { has_trait = lifestyle_poet }
				}
				desc = hold_court_8090_interest_poet
			}
			triggered_desc = {
				trigger = {
					scope:vassal.var:target_court_position = flag:court_musician
					scope:vassal = { has_trait = gregarious }
				}
				desc = hold_court_8090_interest_musician_gregarious
			}
			triggered_desc = {
				trigger = {
					scope:vassal.var:target_court_position = flag:court_musician
					scope:vassal = {
						culture = {
							this != scope:second.culture
							has_cultural_tradition = tradition_music_theory
						}
					}
				}
				desc = hold_court_8090_interest_musician_culture
			}
			triggered_desc = {
				trigger = {
					scope:vassal.var:target_court_position = flag:cupbearer
					scope:vassal = { has_trait = lifestyle_reveler }
				}
				desc = hold_court_8090_interest_cupbearer
			}
			triggered_desc = {
				trigger = {
					scope:vassal.var:target_court_position = flag:lady_in_waiting
					has_relation_soulmate = scope:vassal
				}
				desc = hold_court_8090_interest_lady_soulmate
			}
			triggered_desc = {
				trigger = {
					scope:vassal.var:target_court_position = flag:lady_in_waiting
					has_relation_lover = scope:vassal
				}
				desc = hold_court_8090_interest_lady_lover
			}
			triggered_desc = {
				trigger = {
					scope:vassal.var:target_court_position = flag:lady_in_waiting
					has_relation_best_friend = scope:vassal
				}
				desc = hold_court_8090_interest_lady_bestie
			}
			triggered_desc = {
				trigger = {
					scope:vassal.var:target_court_position = flag:lady_in_waiting
					has_relation_friend = scope:vassal
				}
				desc = hold_court_8090_interest_lady_friend
			}
			triggered_desc = {
				trigger = { scope:vassal.var:target_court_position = flag:chief_eunuch }
				desc = hold_court_8090_interest_eunuch
			}
			triggered_desc = {
				trigger = {
					scope:vassal.var:target_court_position = flag:court_gardener
					scope:vassal = {
						OR = {
							has_trait = lifestyle_gardener
							has_trait = lifestyle_herbalist
						}
					}
				}
				desc = hold_court_8090_interest_gardener
			}
			triggered_desc = {
				trigger = {
					scope:vassal.var:target_court_position = flag:court_artificer
					scope:vassal = { has_completed_inspiration = yes }
				}
				desc = hold_court_8090_interest_artificer
			}
			triggered_desc = {
				trigger = {
					scope:vassal.var:target_court_position = flag:cultural_emissary
					scope:vassal = { has_trait = diplomat }
				}
				desc = hold_court_8090_interest_emissary
			}
			triggered_desc = {
				trigger = {
					scope:vassal.var:target_court_position = flag:chief_qadi
					scope:vassal = { has_trait = scholar }
				}
				desc = hold_court_8090_interest_qadi
			}
			triggered_desc = {
				trigger = {
					scope:vassal.var:target_court_position = flag:garuda
					scope:vassal = { has_trait = lifestyle_blademaster }
				}
				desc = hold_court_8090_interest_garuda
			}
			triggered_desc = {
				trigger = {
					scope:vassal.var:target_court_position = flag:keeper_of_swans
					scope:vassal = { has_trait = lifestyle_hunter }
				}
				desc = hold_court_8090_interest_keeper_of_swans
			}
			triggered_desc = {
				trigger = { has_relation_soulmate = scope:vassal }
				desc = hold_court_8090_interest_soulmate
			}
			triggered_desc = {
				trigger = { has_relation_lover = scope:vassal }
				desc = hold_court_8090_interest_lover
			}
			triggered_desc = {
				trigger = { has_relation_best_friend = scope:vassal }
				desc = hold_court_8090_interest_bestie
			}
			triggered_desc = {
				trigger = { has_relation_friend = scope:vassal }
				desc = hold_court_8090_interest_friend
			}
			triggered_desc = {
				trigger = { exists = scope:old_holder }
				desc = hold_court_8090_interest_other
			}
			triggered_desc = {
				trigger = {
					NOT = { exists = scope:old_holder }
				}
				desc = hold_court_8090_interest_fallback
			}
		}
	}
	theme = realm
	lower_right_portrait = scope:old_holder
	court_scene = {
		button_position_character = scope:vassal
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:vassal = {
				group = petitioners_group
				animation = admiration
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

	cooldown = { years = 10 }

	trigger = {
		OR = {
			any_vassal = { hold_court_8090_candidate_trigger = yes }
			any_courtier = { hold_court_8090_candidate_trigger = yes }
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = 2
			has_employed_any_court_position = no
		}

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

	immediate = {
		save_scope_as = liege
		every_vassal = {
			limit = { hold_court_8090_candidate_trigger = yes }
			add_to_list = hold_court_8090_candidate_list
		}
		every_courtier = {
			limit = { hold_court_8090_candidate_trigger = yes }
			add_to_list = hold_court_8090_candidate_list
		}
		random_in_list = {
			list = hold_court_8090_candidate_list
			weight = {
				base = 1
				modifier = {
					add = 2
					is_landed_or_landless_administrative = yes
				}
				modifier = {
					add = -1
					highest_held_title_tier = tier_barony
				}
				modifier = {
					add = 2
					highest_held_title_tier = tier_duchy
				}
				modifier = {
					add = 4
					highest_held_title_tier = tier_kingdom
				}
				modifier = {
					add = -20
					is_councillor_of = root
				}
				modifier = {
					add = 2
					has_trait = arrogant
				}
				modifier = {
					add = 2
					has_trait = ambitious
				}
				modifier = {
					add = 10
					has_relation_friend = root
				}
				modifier = {
					add = 20
					has_relation_best_friend = root
				}
				modifier = {
					add = 30
					has_relation_lover = root
				}
				modifier = {
					add = 40
					has_relation_soulmate = root
				}
			}
			hidden_effect = {
				random_list = {
					2 = {
						trigger = { has_any_court_position = no }
						save_scope_as = vassal
						court_event_character_flag_effect = yes
					}
					2 = {
						trigger = {
							any_close_family_member = { hold_court_8090_can_move_trigger = yes }
						}
						save_scope_as = vassal_advocate
						court_event_character_flag_effect = yes
						ordered_close_family_member = {
							limit = { hold_court_8090_can_move_trigger = yes }
							save_scope_as = vassal
							court_event_character_flag_effect = yes
						}
					}
				}
			}
		}
		scope:vassal = {
			court_position_generator_effect = { VAR = target EMPLOYER = root }
			court_position_generator_effect = { VAR = backup EMPLOYER = root }
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = { # Grant desired position
		name = {
			trigger = { exists = scope:old_holder } # Replace
			text = hold_court.8090.b
		}
		name = { # Lady-in-Waiting Soulmate
			trigger = {
				scope:vassal.var:target_court_position = flag:lady_in_waiting
				has_relation_soulmate = scope:vassal
			}
			text = hold_court.8090.a.lady_in_waiting_soulmate
		}
		name = { # Lady-in-Waiting Lover
			trigger = {
				scope:vassal.var:target_court_position = flag:lady_in_waiting
				has_relation_lover = scope:vassal
			}
			text = hold_court.8090.a.lady_in_waiting_lover
		}
		name = { # Bodyguard Soulmate
			trigger = {
				OR = {
					scope:vassal.var:target_court_position = flag:bodyguard
					scope:vassal.var:target_court_position = flag:akolouthos
				}
				has_relation_soulmate = scope:vassal
			}
			text = hold_court.8090.a.bodyguard_soulmate
		}
		name = { # Bodyguard Lover
			trigger = {
				OR = {
					scope:vassal.var:target_court_position = flag:bodyguard
					scope:vassal.var:target_court_position = flag:akolouthos
				}
				has_relation_lover = scope:vassal
			}
			text = hold_court.8090.a.bodyguard_lover
		}
		name = { # Default
			trigger = { always = yes }
			text = hold_court.8090.a
		}
		trigger = { exists = scope:vassal.var:target_court_position }
		court_position_generator_assignment_effect = { VAR = target CANDIDATE = scope:vassal  EMPLOYER = root }
		if = {
			limit = {
				NOT = { exists = scope:vassal_advocate }
			}
			if = {
				limit = { exists = scope:vassal_advocate }
				hold_court_8090_hook_effect = { CHAR = scope:vassal_advocate }
				scope:vassal_advocate = {
					add_opinion = {
						modifier = grateful_opinion
						target = root
						opinion = 15
					}
				}
			}
		}
		else = {
			hold_court_8090_hook_effect = { CHAR = scope:vassal }
		}
		scope:vassal = {
			add_opinion = {
				modifier = grateful_opinion
				target = root
				opinion = 10
			}
		}
		if = {
			limit = {
				OR = {
					has_relation_lover = scope:vassal
					has_relation_soulmate = scope:vassal
				}
				OR = {
					scope:vassal.var:target_court_position = flag:bodyguard
					scope:vassal.var:target_court_position = flag:akolouthos
					scope:vassal.var:target_court_position = flag:lady_in_waiting
				}
			}
			had_sex_with_effect = {
	  			CHARACTER = scope:vassal
	 			PREGNANCY_CHANCE = pregnancy_chance
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 0.5
			}
			modifier = {	#Weight up.
				add = 15
				has_relation_friend = scope:vassal 
			}
			modifier = {	#Weight up.
				add = 30
				has_relation_best_friend = scope:vassal 
			}
			modifier = {	#Weight up.
				add = 45
				has_relation_lover = scope:vassal 
			}
			modifier = {	#Weight up.
				add = 60
				has_relation_soulmate = scope:vassal 
			}
		}
	}

	option = { # Grant some other unclaimed position
		name = hold_court.8090.c
		trigger = { exists = scope:vassal.var:backup_court_position }
		show_unlock_reason = no
		court_position_generator_assignment_effect = { VAR = backup CANDIDATE = scope:vassal EMPLOYER = root }
		if = {
			limit = { exists = scope:vassal_advocate }
			scope:vassal_advocate = {
				add_opinion = {
					modifier = grateful_opinion
					target = root
					opinion = 5
				}
			}
		}
		scope:vassal = {
			add_opinion = {
				modifier = grateful_opinion
				target = root
				opinion = 10
			}
		}
		stress_impact = {
			lazy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 2
				ai_energy = 1
				ai_compassion = 1
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = lazy
			}
		}
	}

	option = { # Offer bad role
		name = {
			text = hold_court.8090.d.advocate
			trigger = { exists = scope:vassal_advocate }
		}
		name = {
			text = hold_court.8090.d
			trigger = {
				NOT = { exists = scope:vassal_advocate }
			}
		}
		trigger = {
			OR = {
				AND = {
					has_imprisonment_reason = scope:vassal
					can_appoint_char_to_court_position = {
						CHAR = scope:vassal
						COURT_POS = executioner_court_position
					}
					NOR = {
						scope:vassal.var:target_court_position ?= flag:executioner
						scope:vassal.var:backup_court_position ?= flag:executioner
					}
				}
				AND = {
					can_appoint_char_to_court_position = {
						CHAR = scope:vassal
						COURT_POS = court_jester_court_position
					}
					NOR = {
						scope:vassal.var:target_court_position ?= flag:court_jester
						scope:vassal.var:backup_court_position ?= flag:court_jester
					}
				}
				AND = {
					can_appoint_char_to_court_position = {
						CHAR = scope:vassal
						COURT_POS = food_taster_court_position
					}
					NOR = {
						scope:vassal.var:target_court_position ?= flag:food_taster
						scope:vassal.var:backup_court_position ?= flag:food_taster
					}
				}
			}
		}
		scope:vassal = {
			if = {
				limit = {
					NOR = { 
						is_vassal_of = root
						is_courtier_of = root
						employer = root
					}
				}
				hidden_effect = { set_employer = root }
			}
		}
		if = {
			limit = { # Executioner
				can_appoint_char_to_court_position = {
					CHAR = scope:vassal
					COURT_POS = executioner_court_position
				}
				NOR = {
					scope:vassal.var:target_court_position = flag:executioner
					scope:vassal.var:backup_court_position = flag:executioner
				}
			}
			court_position_grant_effect = {
				EMPLOYER = root
				POS = executioner
				CANDIDATE = scope:vassal
			}
			if = {
				limit = {
					NOT = { has_imprisonment_reason = scope:vassal }
				}
				stress_impact = {
					just = medium_stress_impact_gain
				}
			}
		}
		else_if = { # Jester
			limit = {
				can_appoint_char_to_court_position = {
					CHAR = scope:vassal
					COURT_POS = court_jester_court_position
				}
				NOR = {
					scope:vassal.var:target_court_position = flag:court_jester
					scope:vassal.var:backup_court_position = flag:court_jester
				}
			}
			court_position_grant_effect = {
				EMPLOYER = root
				POS = court_jester
				CANDIDATE = scope:vassal
			}
			stress_impact = {
				just = minor_stress_impact_gain
				compassionate = minor_stress_impact_gain
			}
		}
		else_if = { # Taster
			limit = {
				can_appoint_char_to_court_position = {
					CHAR = scope:vassal
					COURT_POS = food_taster_court_position
				}
				NOR = {
					scope:vassal.var:target_court_position = flag:food_taster
					scope:vassal.var:backup_court_position = flag:food_taster
				}
			}
			court_position_grant_effect = {
				EMPLOYER = root
				POS = food_taster
				CANDIDATE = scope:vassal
			}
			stress_impact = {
				just = minor_stress_impact_gain
				compassionate = minor_stress_impact_gain
			}
		}
		if = {
			limit = { exists = scope:vassal_advocate }
			scope:vassal_advocate = {
				add_opinion = {
					modifier = insulted_opinion
					target = root
					opinion = -10
				}
			}
		}
		scope:vassal = {
			if = {
				limit = { has_court_position = executioner_court_position }
				root = { consume_imprisonment_reasons = scope:vassal }
			}
			if = {
				limit = { has_relation_friend = root }
				remove_relation_friend = root
			}
			add_opinion = {
				modifier = insulted_opinion
				target = root
				opinion = -15
			}
		}
		ai_chance = {
			base = 100
			modifier = {	#Weight up.
				add = 15
				has_imprisonment_reason = scope:vassal
				has_trait = just
			}
			modifier = {	#Weight up.
				add = 15
				NOT = { has_imprisonment_reason = scope:vassal }
				has_trait = arbitrary
			}
		}
	}

	option = { # Refuse
		name = {
			text = hold_court.8090.e.advocate
			trigger = { exists = scope:vassal_advocate }
		}
		name = {
			text = hold_court.8090.e
			trigger = {
				NOT = { exists = scope:vassal_advocate }
			}
		}
		if = {
			limit = { exists = scope:vassal_advocate }
			scope:vassal_advocate = {
				add_opinion = {
					modifier = disappointed_opinion
					target = root
					opinion = -10
				}
			}
		}
		scope:vassal = {
			add_opinion = {
				modifier = disappointed_opinion
				target = root
				opinion = -10
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = -0.5
			}
		}
	}

	after = {
		scope:vassal = {
			clear_court_event_participation = yes
			remove_variable = target_court_position
			remove_variable = backup_court_position
		}
		if = {
			limit = { exists = scope:vassal_advocate }
			scope:vassal_advocate = {
				clear_court_event_participation = yes
			}
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

##################################################
# A Child of the Court
# by Joe Parkin
# 8100
##################################################

scripted_trigger hold_court_8100_child_trigger = {
	has_court_event_flag = no
	is_available_ai_child = yes # Children only
	age < 14 # Not already almost done with education, sets time which must be invested to get rewards
	NOT = { is_child_of = root } # Is not your child
	NOT = { has_relation_ward = root } # Is not already a ward of the player
	NOT = {
		root = { has_strong_hook = prev } # prev = scope:ward
	}
	trigger_if = {
		limit = { is_close_or_extended_family_of = root } # If related to the player, must be a nibling or great nibling
		OR = {
			AND = {
				exists = root.father
				OR = {
					is_grandchild_of = root.father	
					is_great_grandchild_of = root.father
				}
			}
			AND = {
				exists = root.mother
				OR = {
					is_grandchild_of = root.mother	
					is_great_grandchild_of = root.mother
				}
			}
		}
	}
	faith = root.faith # Has the same faith as the player
	trigger_if = {
		limit = {
			faith = { has_doctrine = doctrine_gender_male_dominated } # If male dominated, must be no father
		}
		OR = {
			NOT = { exists = father }
			father = {
				OR = {
					is_alive = no
					is_imprisoned = yes
				}
			}
		}
		NOR = {
			AND = {
				is_courtier_of = root
				mother ?= { is_courtier_of = root }
			}
			AND = {
				is_courtier_of = root
				father ?= { is_courtier_of = root }
			}
		}
	}
	trigger_if = {
		limit = {
			faith = { has_doctrine = doctrine_gender_female_dominated } # If female dominated, must be no mother
		}
		OR = {
			NOT = { exists = mother }
			mother = {
				OR = {
					is_alive = no
					is_imprisoned = yes
				}
			}
		}
	}
}

scripted_trigger hold_court_8100_parent_trigger = { # is a parent eligible to advocate?
	this != root
	OR = {
		is_alive = yes
		is_imprisoned = no
	}
	has_court_event_flag = no
	is_available_ai_adult = yes
	OR = {
		employer = root
		AND = {
			exists = scope:ward_employer
			employer = scope:ward_employer
		}	
	}
}

scripted_trigger hold_court_8100_adopt_trigger = { # is someone disadvantaged by adoption?
	OR = {
		is_child_of = root
		AND = {
			is_spouse_of = root	
			root = {
				any_child = {
					any_parent = { this = scope:advocate }
				}
			}
		}
	}
}

scripted_effect hold_court_8100_root_effect = { # make root the guardian
	hidden_effect = {
		if = {
			limit = {
				employer != root
			}
			set_employer = root
		}
	}
	set_relation_guardian = root
	set_variable = {
		name = hold_court_8100_fosterer
		value = root
		years = 17
	}
	root = {
		if = {
			limit = {
				NOT = {
					scope:ward = { is_close_family_of = root }
				}
			}
			change_current_court_grandeur = medium_court_grandeur_gain
		}
	}
}

scripted_effect hold_court_8100_guardian_effect = { # make scope:guardian the guardian
	hidden_effect = {
		if = {
			limit = {
				employer != scope:guardian.employer
			}
			set_employer = scope:guardian.employer
		}
	}
	set_relation_guardian = scope:guardian
	root = {
		if = {
			limit = {
				NOT = {
					scope:ward = { is_close_family_of = root }
				}
			}
			change_current_court_grandeur = minor_court_grandeur_gain
		}
	}
}

scripted_effect hold_court_8100_root_or_guardian_effect = { # make root guardian, or scope:guardian if not
	if = {
		limit = {
			root = { num_of_relation_ward < 2 }
		}
		hold_court_8100_root_effect = yes
	}
	else = { hold_court_8100_guardian_effect = yes }	
}

# A parent wants you to be their child's ward
hold_court.8100 = {
	type = court_event
	title = hold_court.8100.t
	desc = {
		desc = hold_court.8100.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:ward_employer
					scope:ward_employer != root
				}
				desc = hold_court.8100.desc.vassal
			}
			desc = hold_court.8100.desc.court
		}
		desc = hold_court.8100.desc.body
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:ward = { is_close_or_extended_family_of = root }
				}
				desc = hold_court.8100.desc.interest_family
			}
			triggered_desc = {
				trigger = {
					scope:ward = {
						is_landed_or_landless_administrative = yes
						OR = {
							AND = {
								is_female = yes
								faith = { has_doctrine = doctrine_gender_male_dominated }
							}
							AND = {
								is_female = no
								faith = { has_doctrine = doctrine_gender_female_dominated }
							}
						}
					}
				}
				desc = hold_court.8100.desc.interest_marriage
			}
			triggered_desc = {
				trigger = {
					scope:ward = { is_landed_or_landless_administrative = yes }
				}
				desc = hold_court.8100.desc.interest_alliance
			}
			desc = hold_court.8100.desc.interest_fallback
		}
	}
	theme = realm
	override_background = { reference = throne_room }
	lower_left_portrait = scope:ward_employer
	lower_right_portrait = scope:guardian
	court_scene = {
		button_position_character = scope:advocate
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:advocate = {
				group = petitioners_group
				animation = beg
			}
			scope:ward = {
				group = petitioners_group
				animation = sadness
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

	cooldown = { years = 10 }

	trigger = {
		NOT = {
			any_courtier = {
				has_variable = hold_court_8100_fosterer
				var:hold_court_8100_fosterer = root
			}
		}
		trigger_if = { # There is a parentless child at court
			limit = {
				any_courtier = { hold_court_8100_child_trigger = yes }
			}
			any_courtier = {
				hold_court_8100_child_trigger = yes
				save_temporary_scope_as = ward_temp
			}
		}
		trigger_else = {
			any_vassal = {
				any_courtier = {
					hold_court_8100_child_trigger = yes
					save_temporary_scope_as = ward_temp
				}
			}
		}
		OR = {
			num_of_relation_ward < 2
			any_courtier = { # Guardian
				has_court_event_flag = no
				is_available_ai_adult = yes
				num_of_relation_ward < 2
				NOT = { is_parent_of = scope:ward_temp }
				save_temporary_scope_as = compare_character
				scope:ward_temp = { has_ward_guardian_education_match_compare_character_trigger = yes } # same education
			}
		}
		any_courtier = { # Advocate backup
			has_court_event_flag = no
			is_available_ai_adult = yes
			NOT = { is_parent_of = scope:ward_temp }
			trigger_if = {
				limit = { exists = scope:compare_character }
				this != scope:compare_character
			}
		}
	}

	weight_multiplier = {
		base = 1
		# Shares education focus of player
		modifier = {
			add = 1
			any_courtier = {
				hold_court_8100_child_trigger = yes
				root = { save_temporary_scope_as = compare_character }
				has_ward_guardian_education_match_compare_character_trigger = yes # same education interest
			}
		}
		modifier = {
			add = 1
			any_vassal = {
				any_courtier = {
					hold_court_8100_child_trigger = yes
					root = { save_temporary_scope_as = compare_character }
					has_ward_guardian_education_match_compare_character_trigger = yes # same education interest
				}
			}
		}
		# Has no guardian
		modifier = {
			add = 2
			any_courtier = {
				hold_court_8100_child_trigger = yes
				num_of_relation_guardian = 0
			}
		}
		modifier = {
			add = 2
			any_vassal = {
				any_courtier = {
					hold_court_8100_child_trigger = yes
					num_of_relation_guardian = 0
				}
			}
		}

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

	immediate = {
		every_courtier = {
			limit = { hold_court_8100_child_trigger = yes }
			add_to_list = hold_court_8100_list
		}
		every_vassal = {
			every_courtier = {
				limit = { hold_court_8100_child_trigger = yes }
				add_to_list = hold_court_8100_list
			}
		}
		random_in_list = {
			list = hold_court_8100_list
			weight = {
				base = 1
				# Shares education focus of root
				modifier = {
					add = 10
					root = { save_temporary_scope_as = compare_character }
					has_ward_guardian_education_match_compare_character_trigger = yes # same education interest
				}
				# Has no guardian
				modifier = {
					add = 2
					num_of_relation_guardian = 0
				}
				# Not a more suitable ward
				modifier = {
					add = 20
					any_sibling = {
						count = all
						hold_court_8100_child_trigger = yes
						OR = {
							AND = {
								root = { save_temporary_scope_as = compare_character }
								has_ward_guardian_education_match_compare_character_trigger = yes # same education interest
							}
							age < prev.age # prev = scope:ward
						}
					}
				}
				# Related to root
				modifier = {
					add = 100
					is_close_or_extended_family_of = root
				}
				# In root court
				modifier = {
					add = 25
					employer = root
				}
			}
			save_scope_as = ward
			court_event_character_flag_effect = yes
			if = {
				limit = {
					employer ?= {
						this != root
					}
				}
				employer = { save_scope_as = ward_employer }
			}
		}
		random_courtier = { # Guardian
			limit = {
				has_court_event_flag = no
				is_available_ai_adult = yes
				num_of_relation_ward < 2
				NOT = { is_parent_of = scope:ward }
				save_temporary_scope_as = compare_character
				scope:ward = { has_ward_guardian_education_match_compare_character_trigger = yes } # same education
			}
			alternative_limit = {
				has_court_event_flag = no
				is_available_ai_adult = yes
				num_of_relation_ward < 2
				NOT = { is_parent_of = scope:ward }
			}
			save_scope_as = guardian
			court_event_character_flag_effect = yes
		}
		scope:ward = {
			if = {
				limit = {
					mother ?= { hold_court_8100_parent_trigger = yes }
				}
				mother = { save_scope_as = advocate }
			}
			else_if = {
				limit = {
					father ?= { hold_court_8100_parent_trigger = yes }
				}
				father = { save_scope_as = advocate }
			}
			else = {
				root = {
					random_courtier = { # Advocate backup
						limit = {
							is_available_ai_adult = yes
							has_court_event_flag = no
							NOT = { is_parent_of = scope:ward }
							trigger_if = {
								limit = { exists = scope:guardian }
								this != scope:guardian
							}
						}
						weight = {
							base = 1
							modifier = {
								factor = 10
								OR = {
									has_trait = compassionate
									has_trait = generous
									has_trait = just
									has_trait = paranoid
									has_trait = family_first
									has_trait = gallant
									has_trait = diligent
									has_trait = lazy
								}
							}
							modifier = {
								factor = 50
								is_close_family_of = scope:ward
							}
						}
						save_scope_as = advocate
						court_event_character_flag_effect = yes
					}
				}
			}
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = { # Become the child's guardian
		name = hold_court.8100.a
		trigger = { num_of_relation_ward < 2 }
		highlight_portrait = root
		scope:ward = {
			hold_court_8100_root_effect = yes
			custom_tooltip = hold_court.8100.hook.tt
			add_opinion = {
				modifier = grateful_opinion
				target = root
				opinion = 20
			}
		}
		scope:advocate = {
			add_opinion = {
				modifier = respect_opinion
				target = root
				opinion = 10
			}
		}
		if = {
			limit = { exists = scope:ward_employer }
			scope:ward_employer = {
				add_opinion = {
					modifier = respect_opinion
					target = root
					opinion = 5
				}
			}
		}
		stress_impact = {
			greedy = medium_stress_impact_gain
			callous = medium_stress_impact_gain
			lazy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 0.5
				ai_energy = 0.25
				ai_greed = -0.25
			}
			modifier = {	#Weight up.
				add = 30
				scope:ward = {
					root = { save_temporary_scope_as = compare_character }
					has_ward_guardian_education_match_compare_character_trigger = yes # same education interest
				}
			}
			modifier = {	#Weight up.
				add = 30
				scope:ward = { is_close_or_extended_family_of = root }
			}
			modifier = {	#Weight down for stress.
				add = -45
				has_trait = greedy
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = callous
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = lazy
			}
		}
	}

	option = { # Find another guardian
		name = hold_court.8100.b
		trigger = { exists = scope:guardian }
		highlight_portrait = scope:guardian
		scope:ward = {
			hold_court_8100_guardian_effect = yes
			add_opinion = {
				modifier = grateful_opinion
				target = root
				opinion = 10
			}
		}
		scope:advocate = {
			if = {
				limit = { is_close_family_of = root }
				add_opinion = {
					target = root
					modifier = respect_opinion
					opinion = 5
				}
			}
			else = {
				add_opinion = {
					target = root
					modifier = respect_opinion
					opinion = 10
				}
			}
		}
		if = {
			limit = { exists = scope:ward_employer }
			scope:ward_employer = {
				add_opinion = {
					modifier = respect_opinion
					target = root
					opinion = 5
				}
			}
		}
		stress_impact = {
			greedy = medium_stress_impact_gain
			callous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 0.25
				ai_greed = -0.25
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = greedy
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = callous
			}
		}
	}

	option = { # Adopt them
		name = hold_court.8100.c
		trigger = {
			scope:ward = { is_lowborn = yes }
		}
		scope:ward = {
			if = {
				limit = {
					can_add_hook = {
						target = scope:ward
						type = loyalty_hook
					}
				}
				add_hook = {
					target = scope:ward
					type = loyalty_hook
				}
			}
			hidden_effect = {
				if = {
					limit = {
						employer != root
					}
					set_employer = root
				}
			}
			set_relation_guardian = root
			if = {
				limit = {
					root = { is_male = yes }
				}
				set_father = root
			}
			else = { set_mother = root }
			set_house = root.house
			add_opinion = {
				modifier = grateful_child
				target = root
				opinion = 40
			}
			add_character_modifier = { modifier = hold_court_8100_adopted_modifier }
		}
		scope:advocate = {
			if = {
				limit = { hold_court_8100_adopt_trigger = yes }
				add_opinion = {
					target = root
					modifier = envy_opinion
					opinion = -20
				}
			}
			else = {
				add_opinion = {
					modifier = respect_opinion
					target = root
					opinion = 20
				}
			}
		}
		if = {
			limit = {
				exists = scope:ward_employer
				scope:ward_employer = {
					NOT = { hold_court_8100_adopt_trigger = yes }
				}
			}
			scope:ward_employer = {
				add_opinion = {
					modifier = respect_opinion
					target = root
					opinion = 10
				}
			}
		}
		every_child = {
			custom = hold_court.8100.c.tt_child
			limit = {
				this != scope:ward
			}
			add_opinion = {
				target = root
				modifier = envy_opinion
				opinion = -20
			}
			add_opinion = {
				target = scope:ward
				modifier = envy_opinion
				opinion = -40
			}
		}
		stress_impact = {
			arrogant = medium_stress_impact_gain
			callous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 0.5
				ai_greed = -0.5
			}
			modifier = {	#Weight up.
				add = 50
				AND = {
					any_child = { count = 0 }
					OR = {
						can_have_children = no
						AND = {
							is_married = yes
							primary_spouse = { can_have_children = no }
							allowed_more_spouses = no
							max_number_of_concubines = 0
						}
					}
				}
			}
			modifier = {	#Weight down.
				add = -50
				any_child = {
					count > 0
					this = root.primary_heir
				}
			}
			modifier = {	#Weight down.
				add = -50
				any_child = {
					count > 2
				}
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = arrogant
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = callous
			}
			modifier = {
				factor = 0
				is_adult = no
			}
		}
	}

	option = { # Pay their way
		name = hold_court.8100.d
		trigger = {
			OR = {
				scope:advocate.gold >= root.minor_gold_value
				scope:ward.gold >= root.minor_gold_value
			}
		}
		if = {
			limit = { scope:ward.gold >= root.minor_gold_value }
			scope:ward = {
				pay_short_term_gold = {
					target = root
					gold = root.minor_gold_value
				}
				add_opinion = {
					target = root
					modifier = cruelty_opinion
					opinion = -15
				}
			}
			scope:advocate = {
				add_opinion = {
					target = root
					modifier = cruelty_opinion
					opinion = -10
				}
			}
		}
		else = {
			scope:advocate = {
				pay_short_term_gold = {
					target = root
					gold = root.minor_gold_value
				}
				add_opinion = {
					target = root
					modifier = angry_opinion
					opinion = -15
				}
			}
			scope:ward = {
				add_opinion = {
					target = root
					modifier = cruelty_opinion
					opinion = -10
				}
			}
		}
		if = {
			limit = { exists = scope:ward_employer }
			scope:ward_employer = {
				add_opinion = {
					modifier = pleased_opinion
					target = root
					opinion = 5
				}
			}
		}
		if = {
			limit = { num_of_relation_ward < 2 }
			scope:ward = {
				hidden_effect = {
					if = {
						limit = {
							employer != root
						}
						set_employer = root
					}
				}
				set_relation_guardian = root
				set_variable = {
					name = hold_court_8100_fosterer
					value = root
					years = 17
				}
				custom_tooltip = hold_court.8100.hook.tt
			}
		}
		else = {
			scope:ward = {
				hidden_effect = {
					if = {
						limit = {
							employer != scope:guardian.employer
						}
						set_employer = scope:guardian.employer
					}
				}
				set_relation_guardian = scope:guardian
			}
		}
		stress_impact = {
			generous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = -0.25
				ai_greed = 0.5
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = generous
			}
		}
	}

	option = { # Refuse
		name = hold_court.8100.e
		if = {
			limit = {
				NOT = {
					scope:ward = { is_close_family_of = root }
				}
			}
			change_current_court_grandeur = medium_court_grandeur_loss
		}
		scope:ward = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -20
			}
		}
		scope:advocate = {
			if = {
				limit = { is_close_family_of = root }
				add_opinion = {
					target = root
					modifier = disappointed_opinion
					opinion = -20
				}
			}
			else = {
				add_opinion = {
					target = root
					modifier = disappointed_opinion
					opinion = -10
				}
			}
		}
		if = {
			limit = { exists = scope:ward_employer }
			scope:ward_employer = {
				add_opinion = {
					modifier = disappointed_opinion
					target = root
					opinion = -5
				}
			}
		}
		stress_impact = {
			compassionate = medium_stress_impact_gain
			generous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = -1
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = compassionate
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = generous
			}
		}
	}

	after = {
		scope:ward = {
			clear_court_event_participation = yes
		}
		scope:guardian = {
			clear_court_event_participation = yes
		}
		scope:advocate = {
			clear_court_event_participation = yes
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

##################################################
# Serious Business
# by Joe Parkin
# 8110
##################################################

# A peasant comes to you with a very provincial problem
hold_court.8110 = {
	type = court_event
	title = hold_court.8110.t
	desc = {
		desc = hold_court.8110.desc
		random_valid = {
			desc = hold_court.8110.desc.affair
			desc = hold_court.8110.desc.fence
			desc = hold_court.8110.desc.goat
			desc = hold_court.8110.desc.veg
			desc = hold_court.8110.desc.drink
		}
	}
	theme = realm
	lower_center_portrait = cp:councillor_steward
	lower_right_portrait = scope:executioner
	court_scene = {
		button_position_character = scope:peasant
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:peasant = {
				group = petitioners_group
				animation = happiness
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

	cooldown = { years = 20 }

	trigger = {
		any_held_title = {
			title_tier = county
			county = {
				county_control > 80
				any_county_province = { has_holding = yes }
			}
		}
	}

	weight_multiplier = {
		base = 1

		# Court weightings.
		## Since you take peasant administrative concerns seriously...
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_administrative }
	}

	immediate = {
		random_held_title = { # Find a place for loc
			title_tier = county
			limit = {
				county = {
					county_control > 80
					any_county_province = { has_holding = yes }
				}
			}
			random_county_province = {
				limit = { has_holding = yes }
				save_scope_as = peasant_holding
			}
		}
		hidden_effect = { # Create peasants
			create_character = {
				template = servant_character
				dynasty = none
				location = root.capital_province
				gender_female_chance = root_soldier_female_chance
				trait = beauty_bad_2
				save_scope_as = peasant
			}
			dummy_female = { save_scope_as = dummy_female }
			dummy_male = { save_scope_as = dummy_male }
		}
		scope:peasant = {
			court_event_character_flag_effect = yes
		}
		if = { # Save Steward if relevant
			limit = {
				exists = cp:councillor_steward
				cp:councillor_steward = {
					has_court_event_flag = no
					is_available_ai_adult = yes
				}
			}
			cp:councillor_steward = {
				save_scope_as = steward
				court_event_character_flag_effect = yes
			}
		}
		if = { # Save Executioner if relevant
			limit = {
				employs_court_position = executioner_court_position
				any_court_position_holder = {
					type = executioner_court_position
					has_court_event_flag = no
					is_available_ai_adult = yes
				}
			}
			random_court_position_holder = {
				type = executioner_court_position
				limit = {
					has_court_event_flag = no
					is_available_ai_adult = yes
				}
				save_scope_as = executioner
				court_event_character_flag_effect = yes
			}
		}
		court_position_old_holder_effect = { POS = court_jester EMPLOYER = root } # Save Jester if relevant
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = { # Hear them out
		name = hold_court.8110.a
		add_character_modifier = {
			modifier = hold_court_8110_common_modifier
			years = 10
		}
		stress_impact = {
 			base = medium_stress_impact_gain
 			lazy = medium_stress_impact_gain
 			arrogant = medium_stress_impact_gain
 			impatient = medium_stress_impact_gain
 		}
 		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = 0.25
				ai_energy = 0.25
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = lazy
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = arrogant
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = impatient
			}
		}
	}

	option = { # Steward handle it 
		name = hold_court.8110.b
		trigger = { exists = scope:steward }
		highlight_portrait = scope:steward
		scope:steward = {
		 	add_opinion = {
		 		target = root
				modifier = annoyed_opinion
				opinion = -15
		 	}
		}
		scope:peasant_holding.county = {
			add_county_modifier = {
				modifier = hold_court_8110_steward_modifier
				years = 10
			}
		}
		stress_impact = {
			patient = medium_stress_impact_gain
			diligent = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_energy = -0.5
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = patient
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = diligent
			}
		}
	}

	option = { # Execute them
		name = hold_court.8110.c
		trigger = { exists = scope:executioner }
		highlight_portrait = scope:executioner
		add_tyranny = minor_tyranny_gain
		add_dread = miniscule_dread_gain
		scope:peasant = {
			death = {
				killer = scope:executioner
				death_reason = death_execution
			}
		}
		scope:peasant_holding.county = {
			add_county_modifier = {
				modifier = hold_court_8110_execute_modifier
				years = 10
			}
		}
		stress_impact = {
			compassionate = medium_stress_impact_gain
			just = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = -0.5
				ai_compassion = -0.5
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = compassionate
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = just
			}
		}
	}

	option = { # Make them a jester
		name = hold_court.8110.d
		scope:peasant = {
			hidden_effect = { set_employer = root }
			add_opinion = {
				modifier = insult_opinion
				target = root
				opinion = -10
			}
		}
		if = {
			limit = { exists = scope:old_holder }
			show_as_tooltip = {
				appoint_court_position = {
					recipient = scope:peasant
					court_position = court_jester_court_position
				}
			}
			hidden_effect = {
				add_character_flag = temporary_court_position_cost_removal
				replace_court_position = {
					recipient = scope:peasant
					holder = scope:old_holder
					court_position = court_jester_court_position
				}
				remove_character_flag = temporary_court_position_cost_removal
			}
		}
		else = {
			if = {
				limit = {
					can_employ_court_position_type = court_jester_court_position
				}
				court_position_grant_effect = {
					EMPLOYER = root
					POS = court_jester
					CANDIDATE = scope:peasant
				}
			}
		}
		scope:peasant_holding.county = {
			add_county_modifier = {
				modifier = hold_court_8110_jester_modifier
				years = 10
			}
		}
		stress_impact = {
 			compassionate = medium_stress_impact_gain
 			humble = medium_stress_impact_gain
 		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 0.5
				ai_compassion = 0.25
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = compassionate
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = humble
			}
		}
	}

	option = { # Be done with it
		name = hold_court.8110.e
		add_character_modifier = {
			modifier = hold_court_8110_haughty_modifier
			years = 10
		}
		stress_impact = {
 			just = medium_stress_impact_gain
 			patient = medium_stress_impact_gain
 			humble = medium_stress_impact_gain
 		}
 		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = 0.5
				ai_boldness = -0.5
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = just
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = patient
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = humble
			}
		}
	}

	after = {
		scope:peasant = {
			clear_court_event_participation = yes
			if = {
				limit = {
					is_alive = yes
					NOT = { has_court_position = court_jester_court_position }
				}
				silent_disappearance_effect = yes
			}
		}
		scope:steward ?= {
			clear_court_event_participation = yes 
		}
		scope:executioner ?= {
			clear_court_event_participation = yes 
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

##################################################
# Evangelical Backlash
# by Joe Parkin
# 8120
##################################################

scripted_trigger hold_court_8120_syncretic_faith_trigger = {
	scope:peasant.religion != root.religion
	OR = {
		AND = { # Eastern
			scope:peasant.faith.religion = { is_in_family = rf_eastern }
			faith = { has_doctrine = tenet_eastern_syncretism }
		}
		AND = { # Pagan
			scope:peasant.faith = { has_doctrine_parameter = unreformed }
			faith = { has_doctrine = tenet_unreformed_syncretism }
		}
		AND = { # Christian
			OR = {
			scope:peasant.religion = religion:eastern_orthodox_religion 
			scope:peasant.religion = religion:catholic_religion 
			scope:peasant.religion = religion:protestant_religion 
			}
			faith = { has_doctrine = tenet_christian_syncretism }
		}
		AND = { # Islam
			scope:peasant.religion = religion:islam_religion
			faith = { has_doctrine = tenet_islamic_syncretism }
		}
		AND = { # Judaism
			scope:peasant.religion = religion:judaism_religion
			faith = { has_doctrine = tenet_jewish_syncretism }
		}
	}
}

scripted_effect hold_court_8120_stop_effect = {
	set_variable = {
		name = hold_court_8120_religion_block
		value = scope:conversion_target.faith
		years = 15
	}
	add_character_modifier = {
		modifier = hold_court_8120_tolerance_modifier
		years = 10
	}
	scope:bishop = {
		add_opinion = {
			modifier = impious_opinion
			target = root
			opinion = -15
		}
		set_council_task = { task_type = task_religious_relations }
	}
	scope:conversion_target = {
		add_county_modifier = {
			modifier = hold_court_8120_stopped_modifier
			years = 15
		}
	}
	custom_tooltip = hold_court.8120.a.tt_conversion
	stress_impact = {
		zealous = medium_stress_impact_gain
		callous = medium_stress_impact_gain
	}
}

# Locals ask you to stop trying to convert them
hold_court.8120 = {
	type = court_event
	title = hold_court.8120.t
	desc = {
		desc = hold_court.8120.desc
		first_valid = {
			triggered_desc = {
				trigger = { scope:peasant.religion = root.religion }
				desc = hold_court.8120.desc.same_religion
			}
			triggered_desc = {
				trigger = { scope:peasant.culture = root.culture }
				desc = hold_court.8120.desc.same_culture
			}
			desc = hold_court.8120.desc.other
		}
	}
	theme = realm
	lower_right_portrait = scope:bishop
	court_scene = {
		button_position_character = scope:peasant
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:peasant = {
				group = petitioners_group
				animation = beg
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

	cooldown = { years = 20 }

	trigger = {
		NOT = { has_character_flag = has_had_conversion_event }
		top_liege = this
		exists = cp:councillor_court_chaplain
		cp:councillor_court_chaplain = {
			has_court_event_flag = no
			is_available_ai_adult = yes
		}
		any_held_county = { is_target_of_council_task = task_conversion }
	}

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

	immediate = {
		add_character_flag = {
			flag = has_had_conversion_event
			years = 15
		}
		cp:councillor_court_chaplain = {
			save_scope_as = bishop
			court_event_character_flag_effect = yes
		}
		random_held_county = {
			limit = { is_target_of_council_task = task_conversion }
			save_scope_as = conversion_target
		}
		create_character = {
			template = servant_character
			dynasty = none
			location = root.capital_province
			gender_female_chance = root_soldier_female_chance
			culture = scope:conversion_target.culture
			faith = scope:conversion_target.faith
			save_scope_as = peasant
		}
		scope:peasant = {
			court_event_character_flag_effect = yes
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = { # Stop the priests - unsyncretic
		name = hold_court.8120.a
		trigger = { hold_court_8120_syncretic_faith_trigger = no }
		if = {
			limit = {
				faith = {
					faith_hostility_level = {
						target = scope:peasant.faith
						value >= faith_evil_level
					}
				}
			}
			add_piety = medium_piety_loss
		}
		else_if = {
			limit = {
				faith = {
					faith_hostility_level = {
						target = scope:peasant.faith
						value >= faith_hostile_level
					}
				}
			}
			add_piety = minor_piety_loss
		}
		else_if = {
			limit = {
				faith = {
					faith_hostility_level = {
						target = scope:peasant.faith
						value >= faith_astray_level
					}
				}
			}
			add_piety = miniscule_piety_loss
		}
		hold_court_8120_stop_effect = yes
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 0.5
				ai_zeal = -1
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = callous
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = zealous
			}
		}
	}

	option = { # Stop the priests - syncretic
		name = hold_court.8120.b
		trigger = { hold_court_8120_syncretic_faith_trigger = yes }
		if = {
			limit = {
				AND = { 
					scope:peasant.faith.religion = { is_in_family = rf_eastern }
					faith = { has_doctrine = tenet_eastern_syncretism }
				}
			}
			custom_tooltip = hold_court.8120.b.tt_eastern # Eastern
		}
		else_if = {
			limit = {
				AND = { 
					scope:peasant.faith = { has_doctrine_parameter = unreformed }
					faith = { has_doctrine = tenet_unreformed_syncretism }
				}
			}
			custom_tooltip = hold_court.8120.b.tt_pagan # Pagan
		}
		else_if = {
			limit = {
				AND = { 
					OR = {
					scope:peasant.religion = religion:eastern_orthodox_religion 
					scope:peasant.religion = religion:catholic_religion 
					scope:peasant.religion = religion:protestant_religion 
					}
					faith = { has_doctrine = tenet_christian_syncretism }
				}
			}
			custom_tooltip = hold_court.8120.b.tt_christianity # Christian
		}
		else_if = {
			limit = {
				AND = { 
					scope:peasant.religion = religion:islam_religion
					faith = { has_doctrine = tenet_islamic_syncretism }
				}
			}
			custom_tooltip = hold_court.8120.b.tt_islam # Islam
		}
		else = { custom_tooltip = hold_court.8120.b.tt_judaism } # Judaism
		add_piety = medium_piety_gain
		hold_court_8120_stop_effect = yes
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 0.5
				ai_zeal = -1
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = callous
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = zealous
			}
		}
	}

	option = { # Demand religious taxes
		name = hold_court.8120.c
		add_treasury_or_gold = minor_treasury_or_gold_value
		if = {
			limit = {
				NOT = {
					faith = {
						OR = {
							has_doctrine = tenet_tax_nonbelievers
							has_doctrine = special_doctrine_jizya
						}
					}
				}
			}
			custom_tooltip = hold_court.8120.c.tt_tenet
			stress_impact = {
				honest = medium_stress_impact_gain
				zealous = medium_stress_impact_gain
			}
		}
		else = {
			add_piety = minor_piety_gain
			stress_impact = {
				cynical = medium_stress_impact_gain
			}
		}
		stress_impact = {
			generous = medium_stress_impact_gain
		}
		set_variable = {
			name = hold_court_8120_religion_block
			value = scope:conversion_target.faith
			years = 15
		}
		scope:bishop = {
			if = {
				limit = {
					faith = {
						OR = {
							has_doctrine = tenet_tax_nonbelievers
							has_doctrine = special_doctrine_jizya
						}
					}
				}
				add_opinion = {
					modifier = pious_opinion
					target = root
					opinion = 5
				}
			}
			else = {
				add_opinion = {
					modifier = impious_opinion
					target = root
					opinion = -10
				}
			}
			set_council_task = { task_type = task_religious_relations }
		}
		scope:conversion_target = {
			add_county_modifier = {
				modifier = hold_court_8120_tax_modifier
				years = 15
			}
			custom_tooltip = hold_court.8120.a.tt_conversion
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 2
				ai_zeal = 1
			}
			modifier = {	#Weight up for stress.
				add = 30
				NOT = {
					faith = {
						OR = {
							has_doctrine = tenet_tax_nonbelievers
							has_doctrine = special_doctrine_jizya
						}
					}
				}
				OR = {
					has_trait = cynical
					has_trait = deceitful
				}
			}
			modifier = {	#Weight down for stress.
				add = -30
				NOT = {
					faith = {
						OR = {
							has_doctrine = tenet_tax_nonbelievers
							has_doctrine = special_doctrine_jizya
						}
					}
				}
				OR = {
					has_trait = honest
					has_trait = zealous
				}
			}
			modifier = {	#Weight down for stress.
				add = -15
				faith = {
					OR = {
						has_doctrine = tenet_tax_nonbelievers
						has_doctrine = special_doctrine_jizya
					}
				}
				has_trait = cynical
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = generous
			}
		}
	}

	option = { # Execute
		name = hold_court.8120.d
		if = {
			limit = {
				faith = {
					faith_hostility_level = {
						target = scope:peasant.faith
						value >= faith_evil_level
					}
				}
			}
			add_piety = major_piety_gain
		}
		else_if = {
			limit = {
				faith = {
					faith_hostility_level = {
						target = scope:peasant.faith
						value >= faith_hostile_level
					}
				}
			}
			add_piety = medium_piety_gain
		}
		else_if = {
			limit = {
				faith = {
					faith_hostility_level = {
						target = scope:peasant.faith
						value >= faith_astray_level
					}
				}
			}
			add_piety = minor_piety_gain
		}
		add_dread = minor_dread_gain
		add_character_modifier = {
			modifier = hold_court_8120_terror_modifier
			years = 10
		}
		scope:peasant = {
			death = {
				killer = root
				death_reason = death_execution
			}
		}
		scope:bishop = {
			add_opinion = {
				modifier = pious_opinion
				target = root
				opinion = 20
			}
		}
		stress_impact = {
			cynical = medium_stress_impact_gain
			compassionate = massive_stress_impact_gain
			torturer = medium_stress_impact_loss
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = 2
   				ai_compassion = -1
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = cynical
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = compassionate
			}
			modifier = {	#Weight up for stress.
				add = 15
				has_trait = torturer
			}
		}
	}

	option = { # Refuse
		name = hold_court.8120.e
		scope:bishop = {
			add_opinion = {
				modifier = pious_opinion
				target = root
				opinion = 10
			}
		}
		scope:conversion_target = {
			add_county_modifier = {
				modifier = hold_court_8120_refused_modifier
				years = 20
			}
		}
		stress_impact = {
			callous = medium_stress_impact_gain
			cynical = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = 1
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = callous
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = cynical
			}
		}
	}

	after = {
		scope:bishop = {
			clear_court_event_participation = yes
		}
		scope:peasant = {
			clear_court_event_participation = yes
			if = {
				limit = { is_alive = yes }
				silent_disappearance_effect = yes
			}
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

##################################################
# Cultural Pride
# by Joe Parkin
# 8130
##################################################

scripted_trigger hold_court_8130_county_trigger = {
	NOR  = {
		has_county_modifier = hold_court_8120_tax_modifier
		has_county_modifier = hold_court_8120_stopped_modifier
		has_county_modifier = hold_court_8120_refused_modifier
		has_county_modifier = hold_court_8130_service_modifier
	}
}

scripted_effect hold_court_8130_stop_effect = {
	set_variable = {
		name = hold_court_8130_culture_block
		value = scope:conversion_target.culture
		years = 15
	}
	add_character_modifier = {
		modifier = hold_court_8130_tolerance_modifier
		years = 10
	}
	scope:steward = {
		if = {
			limit = {
				culture != scope:conversion_target.culture
			}
			add_opinion = {
				modifier = disappointed_opinion
				target = root
				opinion = -5
			}
		}
		else = {
			add_opinion = {
				modifier = respect_opinion
				target = root
				opinion = 10
			}
		}
		set_council_task = { task_type = task_collect_taxes }
	}
	scope:conversion_target = {
		add_county_modifier = {
			modifier = hold_court_8120_stopped_modifier
			years = 15
		}
		custom_tooltip = hold_court.8120.a.tt_conversion
	}
	stress_impact = {
		arrogant = medium_stress_impact_gain
	}
}

# Locals ask you to stop trying to integrate them
hold_court.8130 = {
	type = court_event
	title = hold_court.8130.t
	desc = {
		desc = hold_court.8130.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:peasant.culture = { has_same_culture_language = root.culture }
				}
				desc = hold_court.8130.desc.same_language
			}
			triggered_desc = {
				trigger = {
					scope:peasant.culture = { has_same_culture_heritage = root.culture }
				}
				desc = hold_court.8130.desc.same_heritage
			}
			triggered_desc = {
				trigger = {
					scope:peasant.culture = { has_same_culture_ethos = root.culture }
				}
				desc = hold_court.8130.desc.same_ethos
			}
			desc = hold_court.8130.desc.other
		}
	}
	theme = realm
	lower_right_portrait = scope:steward
	court_scene = {
		button_position_character = scope:peasant
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:peasant = {
				group = petitioners_group
				animation = beg
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

	cooldown = { years = 10 }

	trigger = {
		NOT = { has_character_flag = has_had_conversion_event }
		top_liege = this
		exists = cp:councillor_steward
		cp:councillor_steward = {
			has_court_event_flag = no
			is_available_ai_adult = yes
		}
		any_held_county = {
			is_target_of_council_task = task_promote_culture
			hold_court_8130_county_trigger = yes
		}
	}

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

	immediate = {
		add_character_flag = {
			flag = has_had_conversion_event
			years = 5
		}
		cp:councillor_steward = {
			save_scope_as = steward
			court_event_character_flag_effect = yes
		}
		random_held_county = {
			limit = {
				is_target_of_council_task = task_promote_culture
				hold_court_8130_county_trigger = yes
			}
			save_scope_as = conversion_target
		}
		create_character = {
			template = servant_character
			dynasty = none
			location = root.capital_province
			gender_female_chance = root_soldier_female_chance
			culture = scope:conversion_target.culture
			faith = scope:conversion_target.faith
			save_scope_as = peasant
		}
		scope:peasant = {
			court_event_character_flag_effect = yes
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = { # Stop
		name = hold_court.8130.a
		trigger = {
			NOT = { 
				root.culture = { has_cultural_pillar = ethos_egalitarian }
			}
		}
		add_prestige = minor_prestige_loss
		hold_court_8130_stop_effect = yes
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 1
			}
			modifier = {	#Weight down for stress.
				add = -60
				has_trait = arrogant
			}
		}
	}

	option = { # Stop - but egalitarian!
		name = hold_court.8130.b
		trigger = {
			root.culture = { has_cultural_pillar = ethos_egalitarian }
		}
		hold_court_8130_stop_effect = yes
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 1
				ai_zeal = -2
			}
			modifier = {	#Weight down for stress.
				add = -60
				has_trait = arrogant
			}
		}
	}

	option = { # Demand
		name = hold_court.8130.c
		custom_tooltip = hold_court.8130.c.tt_service
		hidden_effect = {
			create_character = {
				gender_female_chance = root_soldier_female_chance
				location = root.capital_province
				template = new_warrior_character
				faith = scope:conversion_target.faith
				culture = scope:conversion_target.culture
				save_scope_as = soldier
			}
			send_interface_message = {
				type = event_guest_neutral
				title = hold_court.8130.c.tt_service_title
				right_icon = scope:soldier
				hidden_effect = {
					scope:soldier = { set_employer = root }
				}
				scope:soldier = {
					add_opinion = {
						modifier = kindness_opinion
						target = root
						opinion = 15
					}
				}
			}
		}
		set_variable = {
			name = hold_court_8130_culture_block
			value = scope:conversion_target.culture
			years = 15
		}
		scope:steward = {
			if = {
				limit = {
					culture != scope:conversion_target.culture
				}
				add_opinion = {
					modifier = disappointed_opinion
					target = root
					opinion = -5
				}
			}
			else = {
				add_opinion = {
					modifier = respect_opinion
					target = root
					opinion = 10
				}
			}
			set_council_task = { task_type = task_collect_taxes }
		}
		scope:conversion_target = {
			add_county_modifier = {
				modifier = hold_court_8130_service_modifier
				years = 15
			}
			custom_tooltip = hold_court.8120.a.tt_conversion
		}
		stress_impact = {
			generous = medium_stress_impact_gain
			arrogant = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = generous
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = arrogant
			}
		}
	}

	option = { # Execute
		name = hold_court.8130.d
		trigger = { 
			OR = {
				has_trait = arrogant
				has_trait = torturer
				has_trait = sadistic
				has_trait = callous
			}
		}
		trait = arrogant
		trait = torturer
		trait = sadistic
		trait = callous
		add_dread = minor_dread_gain
		add_character_modifier = {
			modifier = hold_court_8130_terror_modifier
			years = 10
		}
		scope:peasant = {
			death = {
				killer = root
				death_reason = death_execution
			}
		}
		scope:steward = {
			if = {
				limit = {
					culture != scope:conversion_target.culture
				}
				add_opinion = {
					modifier = pleased_opinion
					target = root
					opinion = 20
				}
			}
			else = {
				add_opinion = {
					modifier = cruelty_opinion
					target = root
					opinion = -10
				}
			}
		}
		stress_impact = {
			torturer = medium_stress_impact_loss
			compassionate = massive_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 2
   				ai_compassion = -1
			}
			modifier = {	#Weight up for stress.
				add = 15
				has_trait = torturer
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = compassionate
			}
		}
	}

	option = { # Refuse
		name = hold_court.8130.e
		scope:steward = {
			if = {
				limit = {
					culture != scope:conversion_target.culture
				}
				add_opinion = {
					modifier = pleased_opinion
					target = root
					opinion = 10
				}
			}
			else = {
				add_opinion = {
					modifier = hurt_opinion
					target = root
					opinion = -5
				}
			}
		}
		scope:conversion_target = {
			add_county_modifier = {
				modifier = hold_court_8120_refused_modifier
				years = 20
			}
		}
		stress_impact = {
			callous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = 1
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = callous
			}
		}
	}

	after = {
		scope:steward = {
			clear_court_event_participation = yes
		}
		scope:peasant = {
			clear_court_event_participation = yes
			if = {
				limit = { is_alive = yes }
				silent_disappearance_effect = yes
			}
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

##################################################
# Puppy Patronage
# by Joe Parkin
# 8140 - 142
##################################################

# Master of the hunt brings a pup
hold_court.8140 = {
	type = court_event
	title = hold_court.8140.t
	desc = hold_court.8140.desc
	theme = realm
	court_scene = {
		button_position_character = scope:huntmaster
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:huntmaster = {
				group = petitioners_group
				animation = admiration
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

	cooldown = { years = 10 }

	trigger = {
		any_court_position_holder = {
			type = master_of_hunt_court_position
			has_court_event_flag = no
			is_available_ai_adult = yes
			NOR = { 
				has_any_bad_relationship_with_root_trigger = yes
				any_owned_story = { type = story_cycle_pet_cat }
				has_character_modifier = cat_story_modifier
			}
		}
		NOR = {
			house = { has_house_modifier = hold_court_8140_house_modifier }
			any_owned_story = { type = story_cycle_pet_dog }
			any_owned_story = { type = story_cycle_pet_cat }
			has_character_modifier = dog_story_modifier
			has_character_modifier = cat_story_modifier
		}
	}

	weight_multiplier = {
		base = 1

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

	immediate = {
		random_court_position_holder = {
			type = master_of_hunt_court_position
			limit = {
				has_court_event_flag = no
				is_available_ai_adult = yes
				NOR = {
					has_any_bad_relationship_with_root_trigger = yes
					any_owned_story = { type = story_cycle_pet_cat }
					has_character_modifier = cat_story_modifier
				}
			}
			save_scope_as = huntmaster
			court_event_character_flag_effect = yes
		}
		save_scope_as = pup_house_ruler
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = { # Invest in the kennel
		name = hold_court.8140.a
		trigger = {
			trigger_if = {
				limit = {
					is_ai = yes
				}
				short_term_treasury_or_gold >= massive_treasury_or_gold_value
			}
		}
		remove_treasury_or_gold = major_treasury_or_gold_value
		house = {
			add_house_modifier = {
				modifier = hold_court_8140_house_modifier
				years = 30
			}
			custom_tooltip = hold_court.8140.a.tt
			every_house_member = {
				limit = {
					is_ai = no
					is_landed_or_landless_administrative = yes
					this != root
				}
				trigger_event = hold_court.8141
			}
			set_variable = {
				name = hold_court_8140_pup_founder
				value = root
			}
		}
		scope:huntmaster = {
			add_opinion = {
				modifier = pleased_opinion
				target = root
				opinion = 15
			}
			progress_towards_friend_effect = {
				REASON = friend_invested_in_kennel
				CHARACTER = root
				OPINION = 0
			}
		}
		start_dog_story_cycle_effect = yes
		change_current_court_grandeur = medium_court_grandeur_gain
		stress_impact = {
			lifestyle_hunter = minor_stress_impact_loss
			lazy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
   				ai_compassion = 0.25
   				ai_greed = -0.5
   				ai_boldness = 1
   				ai_energy = 2
			}
			modifier = {	#Weight up.
				add = 30
				has_trait = lifestyle_hunter
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = lazy
			}
		}
	}

	option = { # Just take the pup
		name = hold_court.8140.b
		trigger = {
			trigger_if = {
				limit = {
					is_ai = yes
				}
				short_term_gold >= medium_gold_value
			}
		}
		remove_short_term_gold = minor_gold_value
		start_dog_story_cycle_effect = yes
		scope:huntmaster = {
			add_opinion = {
				modifier = disappointed_opinion
				target = root
				opinion = -5
			}
		}
		stress_impact = {
			callous = medium_stress_impact_gain
			lazy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
   				ai_compassion = 1
   				ai_greed = -0.25
   				ai_energy = 1
			}
			modifier = {	#Weight up.
				add = 15
				has_trait = lifestyle_hunter
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = callous
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = lazy
			}
		}
	}

	option = { # Cat's are better tho
		name = hold_court.8140.c
		trigger = {
			trigger_if = {
				limit = {
					is_ai = yes
				}
				short_term_gold >= medium_gold_value
			}
		}
		remove_short_term_gold = minor_gold_value
		start_cat_story_cycle_effect = yes
		scope:huntmaster = {
			add_opinion = {
				modifier = disappointed_opinion
				target = root
				opinion = -15
			}
			progress_towards_rival_effect = {
  				CHARACTER = root
  				REASON = rival_dogs_suck
 				OPINION = 0
 			}
		}
		if = {
			limit = {
				any_vassal_or_below = {
					any_owned_story = { type = story_cycle_pet_cat }
				}
			}
			every_vassal_or_below = {
				limit = {
					any_owned_story = { type = story_cycle_pet_cat }
				}
				add_opinion = {
					modifier = respect_opinion
					target = root
					opinion = 10
				}
			}
		}
		stress_impact = {
			diligent = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
   				ai_compassion = -1
   				ai_greed = -0.25
   				ai_energy = -1
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = diligent
			}
		}
	}

	option = { # Refuse
		name = hold_court.8140.d
		scope:huntmaster = {
			add_opinion = {
				modifier = disappointed_opinion
				target = root
				opinion = -10
			}
		}
		change_current_court_grandeur = minor_court_grandeur_loss
		stress_impact = {
			compassionate = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
   				ai_greed = 1
   				ai_compassion = -2
   				ai_energy = -2
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = compassionate
			}
		}
	}

	after = {
		scope:huntmaster = {
			clear_court_event_participation = yes
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

hold_court.8141 = { # Ping for non-AI house members
	type = character_event
	title = hold_court.8140.t
	desc = hold_court.8141.desc
	theme = realm
	override_background = { reference = throne_room }
	left_portrait = {
		character = scope:pup_house_ruler
	}
	right_portrait = {
		character = scope:huntmaster
		animation = admiration
	}

	option = { # Yay puppos
		name = hold_court.8141.a
		show_as_tooltip = {
			house = {
				add_house_modifier = {
					modifier = hold_court_8140_house_modifier
					years = 30
				}
				custom_tooltip = hold_court.8140.a.tt
			}
		}
	}
}

hold_court.8142 = { # Event on puppy adoption
	type = character_event
	title = hold_court.8142.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					house ?= { has_variable = hold_court_8140_pup_founder }
				}
				desc = hold_court.8142.desc
			}
			desc = hold_court.8142.desc_alternative
		}
	}
	theme = realm
	override_background = { reference = throne_room }
	left_portrait = {
		character = scope:pup_house_ruler
		animation = happiness
	}

	immediate = {
		if = {
			limit = {
				house ?= { has_variable = hold_court_8140_pup_founder }
			}
			house.var:hold_court_8140_pup_founder = { save_scope_as = pup_house_ruler }
		}
		else = {
			save_scope_as = pup_house_ruler
		}
	}

	option = { # Accept
		name = hold_court.8142.a
		start_dog_story_cycle_effect = yes
	}

	option = { # Change mind
		name = hold_court.8142.b
		add_gold = minor_gold_value
	}
}

##################################################
# Contractual Compromise
# by Joe Parkin
# 8150
##################################################

scripted_trigger hold_court_8150_faction_trigger = {
	exists = yes
	NOT = { exists = faction_war }
	faction_leader ?= {
		has_court_event_flag = no
		is_available_ai_adult = yes
		is_vassal_of = root
		government_has_flag = government_is_feudal
		OR = {
			vassal_contract_obligation_level_can_be_decreased = feudal_government_taxes
			vassal_contract_obligation_level_can_be_decreased = feudal_government_levies
		}
	}
	OR = {
		faction_is_type = independence_faction
		faction_is_type = liberty_faction
		faction_is_type = claimant_faction
	}
}

scripted_effect hold_court_8150_obligation_effect = {
	hidden_effect = {
		random_list = {
			50 = {
				trigger = { vassal_contract_obligation_level_can_be_decreased = feudal_government_taxes }
				vassal_contract_decrease_obligation_level = feudal_government_taxes
			}
			50 = {
				trigger = { vassal_contract_obligation_level_can_be_decreased = feudal_government_levies }
				vassal_contract_decrease_obligation_level = feudal_government_levies
			}
		}
	}
	add_character_flag = {
		flag = joining_faction_block
		years = 5
	}
}

# Leader of a faction offers you an out
hold_court.8150 = {
	type = court_event
	title = hold_court.8150.t
	desc = {
		desc = hold_court.8150.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:target_faction = {
						any_faction_member = { count = 1 }
					}
				}
				desc = hold_court.8150.desc.alone
			}
			triggered_desc = {
				trigger = {
					scope:target_faction = {
						any_faction_member = { count <= 3 }
					}
				}
				desc = hold_court.8150.desc.few
			}
			desc = hold_court.8150.desc.group
		}
		desc = hold_court.8150.desc.body
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:target_faction = { faction_is_type = independence_faction }
				}
				desc = hold_court.8150.desc.independence
			}
			triggered_desc = {
				trigger = {
					scope:target_faction = { faction_is_type = liberty_faction }
				}
				desc = hold_court.8150.desc.liberty
			}
			triggered_desc = {
				trigger = {
					scope:target_faction = { faction_is_type = claimant_faction }
					exists = scope:target_faction.special_character
					scope:target_faction.faction_leader = scope:target_faction.special_character
				}
				desc = hold_court.8150.desc.claimant_self
			}
			triggered_desc = {
				trigger = {
					scope:target_faction = { faction_is_type = claimant_faction }
				}
				desc = hold_court.8150.desc.claimant
			}
		}
		desc = hold_court.8150.desc.outro
	}
	theme = realm
	court_scene = {
		button_position_character = scope:target_faction.faction_leader
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:target_faction.faction_leader = {
				group = petitioners_group
				animation = disapproval
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

	cooldown = { years = 10 }

	trigger = {
		any_targeting_faction = { hold_court_8150_faction_trigger = yes }
	}

	weight_multiplier = {
		base = 1
		modifier = {
			factor = 2
			any_targeting_faction = {
				hold_court_8150_faction_trigger = yes
				any_faction_member = { count >= 5 }
			}
		}
		modifier = {
			factor = 2
			any_targeting_faction = {
				hold_court_8150_faction_trigger = yes
				faction_power >= faction_power_threshold
			}
		}

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

	immediate = {
		ordered_targeting_faction = {
			limit = { hold_court_8150_faction_trigger = yes }
			order_by = faction_power
			save_scope_as = target_faction
			faction_leader = {
				court_event_character_flag_effect = yes
				save_scope_as = targeted_factions_leader #Saving in order to be able to clear the flag.
			}
		}
		if = {
			limit = {
				any_held_title = {
					count > 1
					title_tier = county
					is_landless_type_title = no
				}
			}
			ordered_held_title = {
				title_tier = county
				limit = {
					this != root.capital_county
					is_landless_type_title = no
				}
				order_by = {
					value = 0
					subtract = title_province.combined_building_level
				}
				save_scope_as = bribe_county
			}
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = { # Accept
		name = hold_court.8150.a
		change_current_court_grandeur = medium_court_grandeur_loss
		scope:target_faction = {
			if = { # Split effects for nicer tooltips
				limit = {
					any_faction_member = { count = 1 }
				}
				faction_leader = {
					custom_tooltip = hold_court.8150.a.tt_single_all
					hold_court_8150_obligation_effect = yes
				}
			}
			else = {
				every_faction_member = {
					custom = hold_court.8150.a.tt_multiple_feudal_intro
					limit = { government_has_flag = government_is_feudal }
					custom_tooltip = hold_court.8150.a.tt_shared
					hold_court_8150_obligation_effect = yes
				}
			}
			destroy_faction = yes
		}
		stress_impact = {
			arrogant = medium_stress_impact_gain
			greedy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
   				ai_greed = -1
   				ai_boldness = -2
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = arrogant
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = greedy
			}
		}
	}

	option = { # Arrest
		name = hold_court.8150.b
		imprison_character_effect = {
			TARGET = scope:target_faction.faction_leader
			IMPRISONER = root
		}
		scope:target_faction = {
			every_faction_member = {
				custom = hold_court.8150.a.tt_multiple_intro
				limit = {
					this != scope:target_faction.faction_leader
				}
				add_opinion = {
					modifier = angry_opinion
					target = root
					opinion = -20
				}
			}
			if = {
				limit = {
					any_faction_member = { count = 1 }
				}
				show_as_tooltip = { destroy_faction = yes }
			}
		}
		add_dread = minor_dread_gain
		stress_impact = {
			just = medium_stress_impact_gain
			patient = medium_stress_impact_gain
			shy = medium_stress_impact_gain
			forgiving = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
   				ai_honor = -1
   				ai_boldness = 2
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = just
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = patient
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = shy
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = forgiving
			}
		}
	}

	option = { # Bribe
		name = hold_court.8150.c
		trigger = {
			NOT = {
				scope:target_faction.faction_leader = { has_relation_rival = root }
			}
		}
		random_list = {
			40 = {
				desc = hold_court.8150.d.tt_accept
				send_interface_toast = {
					title = hold_court.8150.c.tt_success
					left_icon = scope:target_faction.faction_leader
					if = {
						limit = { exists = scope:bribe_county }
						create_title_and_vassal_change = {
							type = granted
							save_scope_as = change
							add_claim_on_loss = no
						}
						scope:bribe_county = {
							change_title_holder = {
								holder = scope:target_faction.faction_leader
								change = scope:change
							}
						}
						resolve_title_and_vassal_change = scope:change
					}
					else = {
						pay_short_term_gold = {
							target = scope:target_faction.faction_leader
							gold = root.major_gold_value
						}
					}
					scope:target_faction = {
						faction_leader = {
							custom_tooltip = hold_court.8150.a.tt_single_cooldown
							add_character_flag = {
								flag = joining_faction_block
								years = 5
							}
						}
						every_faction_member = {
							custom = hold_court.8150.a.tt_multiple_intro
							limit = {
								this != scope:target_faction.faction_leader
							}
							add_opinion = {
								target = scope:target_faction.faction_leader
								modifier = angry_opinion
								opinion = -20
							}
						}
						destroy_faction = yes
					}
				}
				modifier = {
					factor = 10
					has_trait = deceitful
				}
				modifier = {
					factor = 10
					has_trait = greedy
				}
				modifier = {
					factor = 10
					has_trait = fickle
				}
			}
			60 = {
				desc = hold_court.8150.d.tt_reject
				send_interface_toast = {
					title = hold_court.8150.c.tt_failure
					left_icon = scope:target_faction.faction_leader
					scope:target_faction = {
						add_faction_discontent = 15
						every_faction_member = {
							custom = hold_court.8150.a.tt_multiple_intro
							add_opinion = {
								target = root
								modifier = disgusted_opinion
								opinion = -15
							}
						}
					}
				}
				modifier = {
					factor = 10
					has_trait = honest
				}
				modifier = {
					factor = 10
					has_trait = stubborn
				}
				modifier = {
					factor = 20
					scope:target_faction.faction_leader = scope:target_faction.special_character
				}
			}
		}
		stress_impact = {
			generous = medium_stress_impact_gain
			honest = medium_stress_impact_gain
			just = medium_stress_impact_gain
			vengeful = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
   				ai_honor = -0.5
   				ai_greed = -0.5
   				ai_rationality = 1
   				ai_boldness = 1
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = generous
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = honest
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = just
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = vengeful
			}
		}
	}

	option = { # Convince
		name = hold_court.8150.d
		duel = {
			skill = diplomacy
			target = scope:target_faction.faction_leader
			8 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 1
				}
				desc = hold_court.8150.d.tt_accept
				send_interface_toast = {
					title = hold_court.8150.d.tt_accept
					left_icon = scope:target_faction.faction_leader
					add_prestige = medium_prestige_gain
					scope:target_faction = {
						faction_leader = {
							custom_tooltip = hold_court.8150.a.tt_single_cooldown
							add_character_flag = {
								flag = joining_faction_block
								years = 5
							}
						}
						every_faction_member = {
							custom = hold_court.8150.a.tt_multiple_intro
							limit = {
								this != scope:target_faction.faction_leader
							}
							add_opinion = {
								target = scope:target_faction.faction_leader
								modifier = disappointed_opinion
								opinion = -10
							}
						}
						destroy_faction = yes
					}
				}
			}
			12 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 2
				}
				desc = hold_court.8150.d.tt_reject
				send_interface_toast = {
					title = hold_court.8150.d.tt_reject
					left_icon = scope:target_faction.faction_leader
					scope:target_faction = { add_faction_discontent = 10 }
				}
			}
		}
		stress_impact = {
			humble = medium_stress_impact_gain
			vengeful = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
   				ai_honor = 1
   				ai_rationality = 1
   				ai_boldness = 1
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = humble
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = vengeful
			}
		}
	}

	option = { # Refuse
		name = hold_court.8150.e
		add_prestige = medium_prestige_loss
		scope:target_faction = { add_faction_discontent = 5 }
		stress_impact = {
			paranoid = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
   				ai_honor = 2
   				ai_boldness = 2
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = paranoid
			}
		}
	}

	after = {
		scope:targeted_factions_leader = { clear_court_event_participation = yes }
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

##################################################
# Public Accusation
# by Joe Parkin
# 8160
##################################################

# Is the scheme a valid court scheme?
scripted_trigger hold_court_8160_valid_court_scheme_trigger = {
	exists = scheme_target_character.liege
	OR = { # Victim and plotter share same court
		scheme_owner = scheme_target_character.liege
		scheme_owner = { is_vassal_or_below_of = prev.scheme_target_character.liege }
		scheme_owner = { is_courtier_of = prev.scheme_target_character.liege }
	}
	NOR = {
		scheme_owner = root
		scheme_target_character = root
	}
}

scripted_trigger hold_court_8160_valid_plotter_trigger = {
	this != root
	is_available_ai_adult = yes
	exists = scope:scheme_target_scope
	trigger_if = {
		limit = { exists = scope:scheme_target_scope }
		NOR = {
			this = scope:scheme_target_scope # victim
			has_friendly_relationship_trigger = { CHARACTER = scope:scheme_target_scope } # victim
		}
		can_start_scheme = {
			type = murder
			target_character = scope:scheme_target_scope # victim
		}
	}
}

# Is the scheme a valid murder/abduct scheme?
scripted_trigger hold_court_8160_valid_hostile_scheme_trigger = {
	AND = {
		hold_court_8160_valid_court_scheme_trigger = yes
		OR = {
			scheme_type = murder
			scheme_type = abduct
		}
	}
	scheme_target_character = {
		save_temporary_scope_as = scheme_target_scope
		liege = {
			OR = {
				any_vassal_or_below = { hold_court_8160_valid_plotter_trigger = yes }
				any_courtier = { hold_court_8160_valid_plotter_trigger = yes }
			}
		}
	}
}

# Is the character a valid advocate of the victim?
scripted_trigger hold_court_8160_valid_concerned_trigger = {
	this != root
	is_available_ai_adult = yes
	top_liege = prev.top_liege # victim
	NOT = {
		is_scheming_against = { target = prev } # victim
	}
}

# Is the character already targeted by a valid scheme?
scripted_trigger hold_court_8160_current_hostile_target_trigger = {
	this != root
	has_court_event_flag = no
	is_available_ai = yes
	any_targeting_scheme = { hold_court_8160_valid_hostile_scheme_trigger = yes }
	trigger_if = { # if target is a child, they have a parent or family member to advocate
		limit = { is_adult = no }
		OR = {
			any_parent = { hold_court_8160_valid_concerned_trigger = yes }
			any_close_family_member = { hold_court_8160_valid_concerned_trigger = yes }
		}
	}
}

# Is the character, their spouse, or a family member, targeted?
scripted_trigger hold_court_8160_valid_existing_hostile_trigger = {
	this != root
	OR = {
		hold_court_8160_current_hostile_target_trigger = yes
		AND = {
			is_married = yes
			primary_spouse = {
				top_liege = prev.top_liege
				hold_court_8160_current_hostile_target_trigger = yes
			}
		}
		any_close_family_member = {
			exists = yes
			OR = {
				is_vassal_or_below_of = prev.liege # victim.root
				is_courtier_of = prev.liege # victim.root
			}
			hold_court_8160_current_hostile_target_trigger = yes
		}
	}
}

scripted_effect hold_court_8160_save_create_scheme_effect = {
	if = {
		limit = {
			any_targeting_scheme = { hold_court_8160_valid_hostile_scheme_trigger = yes }
		}
		random_targeting_scheme = {
			limit = { hold_court_8160_valid_hostile_scheme_trigger = yes }
			save_scope_as = victim_scheme
			scheme_target_character = { save_scope_as = victim }
			scheme_owner = { save_scope_as = debug_scheme_owner }
		}
	}
	else = {
		save_temporary_scope_as = scheme_target_scope
		save_scope_as = victim
		liege = {
			if = {
				limit = {
					any_vassal_or_below = { hold_court_8160_valid_plotter_trigger = yes }
				}
				random_vassal_or_below = {
					limit = { hold_court_8160_valid_plotter_trigger = yes }
					save_scope_as = debug_scheme_owner
					start_scheme = {
						type = murder
						target_character = scope:victim
					}
				}
			}
			else = {
				random_courtier = {
					limit = { hold_court_8160_valid_plotter_trigger = yes }
					save_scope_as = debug_scheme_owner
					start_scheme = {
						type = murder
						target_character = scope:victim
					}
				}
			}
		}
		random_targeting_scheme = {
			limit = { scheme_owner = scope:debug_scheme_owner }
			save_scope_as = victim_scheme
		}
	}
	scope:victim = {
		court_event_character_flag_effect = yes
	}
}

# Choose who is the target of the scheme
scripted_effect hold_court_8160_vassal_picker_scheme_effect = {
	hidden_effect = {
		random_list = {
			100 = {
				modifier = {
					factor = 100
					hold_court_8160_current_hostile_target_trigger = yes
				}
				hold_court_8160_save_create_scheme_effect = yes
			}
			50 = {
				trigger = { is_married = yes }
				modifier = {
					factor = 100
					primary_spouse = { hold_court_8160_current_hostile_target_trigger = yes }
				}
				primary_spouse = { hold_court_8160_save_create_scheme_effect = yes }
			}
			50 = {
				trigger = {
					any_close_family_member = { count = 1 }
				}
				modifier = {
					factor = 100
					any_close_family_member = { hold_court_8160_current_hostile_target_trigger = yes }
				}
				random_close_family_member = {
					limit = { hold_court_8160_current_hostile_target_trigger = yes }
					alternative_limit = { always = yes }
					hold_court_8160_save_create_scheme_effect = yes
				}
			}
		}
	}
}

scripted_effect hold_court_8160_imprison_effect = {
	rightfully_imprison_character_effect = {
		TARGET = scope:accused
		IMPRISONER = root
	}
	hidden_effect = {
		scope:accused = {
			if = {
				limit = {
					exists = scope:victim.primary_spouse
					scope:victim_scheme = { scheme_type = seduce }
					this != scope:victim.primary_spouse
				}
				add_opinion = {
					modifier = angry_opinion
					target = scope:victim.primary_spouse
					opinion = -20
				}
			}
			else = {
				add_opinion = {
					modifier = angry_opinion
					target = scope:victim
					opinion = -20
				}
			}
			if = {
				limit = { exists = scope:concerned }
				add_opinion = {
					modifier = angry_opinion
					target = scope:concerned
					opinion = -20
				}
			}
		}
	}
	scope:victim = {
		if = {
			limit = {
				exists = primary_spouse
				scope:victim_scheme = { scheme_type = seduce }
				scope:accused != scope:victim.primary_spouse
			}
			primary_spouse = {
				add_opinion = {
					modifier = grateful_opinion
					target = root
					opinion = 10
				}
			}
		}
		else = {
			add_opinion = {
				modifier = grateful_opinion
				target = root
				opinion = 10
			}
		}
	}
	if = {
		limit = { exists = scope:concerned }
		scope:concerned = {
			add_opinion = {
				modifier = grateful_opinion
				target = root
				opinion = 10
			}
		}
	}
}

scripted_trigger hold_court_8160_accused_trigger = {
	this != root
	is_available_ai_adult = yes
	NOR = {
		this = scope:victim
		has_friendly_relationship_trigger = { CHARACTER = scope:victim }
	}
	can_start_scheme = {
		type = murder
		target_character = scope:victim
	}
}

# Target of a scheme wants you to punish the schemer - murder/abduct version
hold_court.8160 = {
	type = court_event
	title = hold_court.8160.t
	desc = {
		# Who is coming to the throne?
		first_valid = { 
			triggered_desc = { # Child with family
				trigger = {
					scope:victim = { is_adult = no }
				}
				desc = hold_court.8160.desc.intro_child
			}
			triggered_desc = { # Spouse
				trigger = { exists = scope:concerned }
				desc = hold_court.8160.desc.intro_spouse
			}
			desc = hold_court.8160.desc.intro_alone # fallback/default
		}
		first_valid = { 
			triggered_desc = { # Spouse
				trigger = { exists = scope:concerned }
				desc = hold_court.8160.desc.intro_other
			}
			desc = hold_court.8160.desc.intro_me
		}
		# Who is accused?
		first_valid = {
			triggered_desc = { # Actually revealed to be involved in scheme
				trigger = {
					scope:accused = { is_agent_exposed_in_scheme = scope:victim_scheme }
				}
				desc = hold_court.8160.desc.exposed
			}
			desc = hold_court.8160.desc.suspicion # Speculation
		}
		# What is the reason for suspicion?
		first_valid = {
			triggered_desc = { # Nemeses
				trigger = {
					scope:accused = { has_relation_nemesis = scope:victim }
				}
				desc = hold_court.8160.desc.nemesis
			}
			triggered_desc = { # Rivals
				trigger = {
					scope:accused = { has_relation_rival = scope:victim }
				}
				desc = hold_court.8160.desc.rival
			}
			triggered_desc = { # Accused has claim on Target
				trigger = {
					scope:accused = {
						any_claim = { holder = scope:victim }
					}
				}
				desc = hold_court.8160.desc.my_claimant
			}
			triggered_desc = { # Target has claim on Accused
				trigger = {
					scope:accused = {
						any_held_title = {
							any_claimant = { this = scope:victim }
						}
					}
				}
				desc = hold_court.8160.desc.their_claimant
			}
			triggered_desc = { # Accused and Target covet same title
				trigger = {
					scope:victim = {
						any_claim = {
							any_claimant = { this = scope:accused }
						}
					}
				}
				desc = hold_court.8160.desc.joint_claimant
			}
			triggered_desc = { # Accused is a villain
				trigger = {
					scope:accused = {
						OR = {
							has_education_intrigue_trigger = yes
							has_trait = deceitful
						}
					}
				}
				desc = hold_court.8160.desc.intrigue
			}
			triggered_desc = { # Accused dislikes Target
				trigger = {
					scope:accused = {
						opinion = {
							target = scope:victim
							value < 0
						}
					}
				}
				desc = hold_court.8160.desc.their_dislike
			}
			triggered_desc = { # Target dislikes Accused
				trigger = {
					scope:accused = {
						reverse_opinion = {
							target = scope:victim
							value < 0
						}
					}
				}
				desc = hold_court.8160.desc.my_dislike
			}
			desc = hold_court.8160.desc.fallback # No good reason
		}
		# How many agents revealed?
		desc = hold_court.8160.desc.outro
	}
	theme = realm
	lower_right_portrait = scope:accused
	court_scene = {
		button_position_character = scope:concerned
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:concerned = {
				group = petitioners_group
				animation = worry
			}
			scope:victim = {
				group = petitioners_group
				animation = paranoia
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

	cooldown = { years = 5 }

	trigger = {
		is_ai = no # Murder schemes are heavy for performance
		OR = {
			any_vassal_or_below = {
				save_temporary_scope_as = scheme_target_scope
				OR = {
					hold_court_8160_valid_existing_hostile_trigger = yes
					liege = {
						OR = {
							any_vassal_or_below = { hold_court_8160_valid_plotter_trigger = yes }
							any_courtier = { hold_court_8160_valid_plotter_trigger = yes }
						}
					}
				}
			}
			any_courtier = {
				save_temporary_scope_as = scheme_target_scope
				OR = {
					hold_court_8160_valid_existing_hostile_trigger = yes
					liege = {
						OR = {
							any_vassal_or_below = { hold_court_8160_valid_plotter_trigger = yes }
							any_courtier = { hold_court_8160_valid_plotter_trigger = yes }
						}
					}
				}
			}
		}
	}

	weight_multiplier = {
		base = 1

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

	immediate = {
		every_vassal_or_below = {
			limit = { hold_court_8160_valid_existing_hostile_trigger = yes }
			alternative_limit = {
				save_temporary_scope_as = scheme_target_scope
				liege = {
					OR = {
						any_vassal_or_below = { hold_court_8160_valid_plotter_trigger = yes }
						any_courtier = { hold_court_8160_valid_plotter_trigger = yes }
					}
				}
			}
			add_to_list = victim_list
		}
		every_courtier = {
			limit = { hold_court_8160_valid_existing_hostile_trigger = yes }
			alternative_limit = {
				save_temporary_scope_as = scheme_target_scope
				liege = {
					OR = {
						any_vassal_or_below = { hold_court_8160_valid_plotter_trigger = yes }
						any_courtier = { hold_court_8160_valid_plotter_trigger = yes }
					}
				}
			}
			add_to_list = victim_list
		}
		random_in_list = {
			list = victim_list
			limit = { hold_court_8160_current_hostile_target_trigger = yes }
			alternative_limit = {
				is_married = yes
				primary_spouse = {
					top_liege = prev.top_liege
					hold_court_8160_current_hostile_target_trigger = yes
				}
			}
			alternative_limit = {
				any_close_family_member = {
					exists = yes
					OR = {
						is_vassal_or_below_of = prev.liege # victim.root
						is_courtier_of = prev.liege # victim.root
					}
					hold_court_8160_current_hostile_target_trigger = yes
				}
			}
			alternative_limit = { is_vassal_of = root }
			alternative_limit = { is_courtier_of = root }
			alternative_limit = { always = yes }
			weight = {
				modifier = {
					factor = 50
					has_trait = paranoid
				}
				modifier = {
					factor = 25
					has_trait = arrogant
				}
			}
			hold_court_8160_vassal_picker_scheme_effect = yes
		}
		if = { # Find actual scheme owner if revealed
			limit = {
				exists = scope:victim_scheme
				scope:victim_scheme.scheme_owner = { is_agent_exposed_in_scheme = scope:victim_scheme } # scheme owner is known by target
			}
			scope:victim_scheme.scheme_owner = {
				save_scope_as = accused
				court_event_character_flag_effect = yes
			}
		}
		else = { # Else find a suspect
			every_vassal_or_below = {
				limit = { hold_court_8160_accused_trigger = yes }
				add_to_list = accused_list
			}
			every_courtier = {
				limit = { hold_court_8160_accused_trigger = yes }
				add_to_list = accused_list
			}	
			random_in_list = {
				list = accused_list
				limit = { is_vassal_of = root }
				alternative_limit = { is_courtier_of = root }
				alternative_limit = { always = yes }
				weight = {
					base = 1
					modifier = { # Nemeses
						add = 100
						has_relation_nemesis = scope:victim
					}
					modifier = { # Rivals
						add = 50
						has_relation_rival = scope:victim
					} 
					modifier = { # Accused has claim on Target
						add = 100
						any_claim = { holder = scope:victim }
					}
					modifier = { # Target has claim on Accused
						add = 100
						any_held_title = {
							any_claimant = { this = scope:victim }
						}
					}
					modifier = { # Accused and Target covet same title
						add = 100
						any_claim = {
							any_claimant = { this = scope:victim }
						}
					}
					modifier = { # Accused is a villain
						add = 100
						OR = {
							has_education_intrigue_trigger = yes
							has_trait = deceitful
						}
					}
					modifier = { # Accused dislikes Target
						add = 25
						opinion = {
							target = scope:victim
							value < 0
						}
					}
					modifier = { # Target dislikes Accused
						add = 25
						reverse_opinion = {
							target = scope:victim
							value < 0
						}
					}
				}
				save_scope_as = accused
			}
		}
		# Save an advocate if necessary/relevant
		scope:victim = { 
			if = {
				limit = { is_adult = no }
				if = {
					limit = {
						OR = {
							faith_dominant_gender_female_or_equal = yes
							father = { hold_court_8160_valid_concerned_trigger = no }
						}
						mother ?= { hold_court_8160_valid_concerned_trigger = yes }
					}
					mother = { save_scope_as = concerned }
				}
				else_if = {
					limit = {
						OR = {
							faith_dominant_gender_male_or_equal = yes
							mother = { hold_court_8160_valid_concerned_trigger = no }
						}
						father ?= { hold_court_8160_valid_concerned_trigger = yes }
					}
					father = { save_scope_as = concerned }
				}
				else = {
					ordered_close_family_member = {
						limit = { hold_court_8160_valid_concerned_trigger = yes }
						order_by = age
						save_scope_as = concerned
					}
				}
			}
			else_if = {
				limit = {
					is_married = yes
					primary_spouse = { hold_court_8160_valid_concerned_trigger = yes }
				}
				primary_spouse = { save_scope_as = concerned }
			}
			else_if = {
				limit = {
					NOT = { is_vassal_of = root }
					any_close_family_member = { hold_court_8160_valid_concerned_trigger = yes }
				}
				random_close_family_member = { 
					limit = { hold_court_8160_valid_concerned_trigger = yes }
					save_scope_as = concerned
				}
			}
			if = {
				limit = { exists = scope:concerned }
				scope:concerned = {
					court_event_character_flag_effect = yes
				}
			}
		}
		if = {
			limit = { exists = scope:concerned }
			add_character_flag = {
				flag = concerned_exists
				years = 1
			}
		}
		# Save titles for motives localization
		scope:accused = {
			if = {
				limit = {
					any_claim = { holder = scope:victim }
				}
				ordered_claim = {
					limit = { holder = scope:victim }
					order_by = tier
					save_scope_as = relevant_title
				}
			}
			else_if = {
				limit = {
					any_held_title = {
						any_claimant = { this = scope:victim }
					}
				}
				ordered_held_title = {
					limit = {
						any_claimant = { this = scope:victim }
					}
					order_by = tier
					save_scope_as = relevant_title
				}
			}
			else_if = {
				limit = {
					any_claim = {
						any_claimant = { this = scope:victim }
					}
				}
				ordered_claim = {
					limit = {
						any_claimant = { this = scope:victim }
					}
					order_by = tier
					save_scope_as = relevant_title
				}
			}
		}
		if = {
			limit = {
				any_court_position_holder = {
					type = executioner_court_position
					has_court_event_flag = no
					is_available_ai_adult = yes
					NOR = {
						this = scope:victim
						this = scope:accused
						AND = {
							exists = scope:concerned
							this = scope:concerned
						}
					}
				}
			}
			random_court_position_holder = {
				type = executioner_court_position
				limit = {
					has_court_event_flag = no
					is_available_ai_adult = yes
					NOR = {
						this = scope:victim
						this = scope:accused
						AND = {
							exists = scope:concerned
							this = scope:concerned
						}
					}
				}
				save_scope_as = executioner
			}
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = { # Arrest
		name = hold_court.8160.a
		if = {
			limit = {
				scope:victim_scheme = { scheme_type = murder }
			}
			add_opinion = {
				modifier = attempted_murder_opinion
				target = scope:accused
			}
		}
		else = {
			add_opinion = {
				modifier = attempted_abduction_opinion
				target = scope:accused
			}
		}
		scope:accused = {
			add_opinion = {
				modifier = angry_opinion
				target = root
				opinion = -20
			}
			hidden_effect = {
				add_opinion = {
					modifier = angry_opinion
					target = scope:victim
					opinion = -20
				}
				if = {
					limit = { exists = scope:concerned }
					add_opinion = {
						modifier = angry_opinion
						target = scope:concerned
						opinion = -20
					}
				}
			}
		}
		scope:victim = {
			add_opinion = {
				modifier = grateful_opinion
				target = root
				opinion = 10
			}
		}
		if = {
			limit = { exists = scope:concerned }
			scope:concerned = {
				add_opinion = {
					modifier = grateful_opinion
					target = root
					opinion = 10
				}
			}
		}
		if = {
			limit = { scope:accused = scope:debug_scheme_owner }
			add_tyranny = minor_tyranny_gain
		}
		else = {
			stress_impact = {
				just = medium_stress_impact_gain
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = -1
   				ai_compassion = -2
   				ai_boldness = 1
			}
			modifier = {	#Weight down for stress.
				add = -30
				scope:accused = scope:debug_scheme_owner
				has_trait = just
			}
		}
	}

	option = { # Torture
		name = {
			trigger = { has_trait = torturer }
			text = hold_court.8160.b.torturer
		}
		name = {
			trigger = {
				exists = scope:executioner
			}
			text = hold_court.8160.b.executioner
		}
		trigger = {
			OR = {
				exists = scope:executioner
				has_trait = torturer
			}
		}
		scope:accused = {
			random_list = {
				75 = {
					modifier = {
						factor = 2
						has_trait = craven
					}
					modifier = {
						factor = 2
						has_trait = fickle
					}
					modifier = {
						factor = 2
						has_trait = arbitrary
					}
					modifier = {
						factor = 2
						is_agent_exposed_in_scheme = scope:victim_scheme
					}
					desc = hold_court.8160.b.tt_confession
					root = {
						send_interface_toast = {
							title = hold_court.8160.b.tt_confession
							left_icon = scope:accused
							right_icon = scope:victim
							hold_court_8160_imprison_effect = yes
						}
					}
				}
				25 = {
					modifier = {
						factor = 2
						has_trait = stubborn
					}
					modifier = {
						factor = 2
						has_trait = brave
					}
					modifier = {
						factor = 2
						has_trait = just
					}
					modifier = {
						factor = 2
						AND = {
							NOT = { is_agent_exposed_in_scheme = scope:victim_scheme }
							has_trait = honest
						}
					}
					modifier = {
						factor = 2
						AND = {
							is_agent_exposed_in_scheme = scope:victim_scheme
							has_trait = deceitful
						}
					}
					desc = hold_court.8160.b.tt_silence
					root = {
						send_interface_toast = {
							title = hold_court.8160.b.tt_silence
							left_icon = scope:accused
							right_icon = scope:victim
						}
					}
				}
			}
			add_opinion = {
				modifier = tortured_me
				target = root
			}
			if = {
				limit = { exists = scope:executioner }
				hidden_effect = {
					add_opinion = {
						modifier = tortured_me
						target = scope:executioner
					}
				}
			}
			if = {
				limit = {
					is_married = yes
					NOR = {
						primary_spouse = {
							this = root
							this = scope:victim
							AND = {
								exists = scope:concerned
								this = scope:concerned
							}
						}
					}
				}
				primary_spouse = {
					add_opinion = {
						modifier = tortured_family_member
						target = root
					}
					if = {
						limit = { exists = scope:executioner }
						hidden_effect = {
							add_opinion = {
								modifier = tortured_family_member
								target = scope:executioner
							}
						}
					}
				}
			}
			every_close_family_member = {
				limit = {
					NOR = {
						this = root
						this = scope:victim
						AND = {
							exists = scope:concerned
							this = scope:concerned
						}
					}
				}
				add_opinion = {
					modifier = tortured_family_member
					target = root
				}
				if = {
					limit = { exists = scope:executioner }
					hidden_effect = {
						add_opinion = {
							modifier = tortured_family_member
							target = scope:executioner
						}
					}
				}
			}
		}
		scope:victim = {
			add_opinion = {
				modifier = grateful_opinion
				target = root
				opinion = 15
			}
			if = {
				limit = { exists = scope:executioner }
				hidden_effect = {
					add_opinion = {
						modifier = grateful_opinion
						target = scope:executioner
						opinion = 15
					}
				}
			}
		}
		if = {
			limit = { exists = scope:concerned }
			scope:concerned = {
				add_opinion = {
					modifier = grateful_opinion
					target = root
					opinion = 15
				}
				if = {
					limit = { exists = scope:executioner }
					hidden_effect = {
						add_opinion = {
							modifier = grateful_opinion
							target = scope:executioner
							opinion = 15
						}
					}
				}
			}
		}

		if = {
			limit = {
				scope:victim_scheme.scheme_owner = { is_agent_exposed_in_scheme = scope:victim_scheme }
			}
			add_tyranny = medium_tyranny_gain
			stress_impact = {
				just = medium_stress_impact_gain
				compassionate = medium_stress_impact_gain
			}
		}
		else = {
			add_tyranny = major_tyranny_gain
			stress_impact = {
				just = major_stress_impact_gain
				compassionate = major_stress_impact_gain
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = -1
   				ai_compassion = -2
   				ai_boldness = 2
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = just
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = compassionate
			}
		}
	}

	option = { # Attempt to find the truth
		name = hold_court.8160.c
		show_as_tooltip = {
			duel = {
				skill = intrigue
				target = scope:accused
				1 = {
					show_chance = no
					desc = hold_court.8160.c.tt_success
					hold_court_8160_imprison_effect = yes
				}
				1 = {
					show_chance = no
					desc = hold_court.8160.c.tt_failure
					scope:victim = {
						add_opinion = {
							modifier = disappointed_opinion
							target = root
							opinion = -10
						}
					}
				}
			}
		}
		hidden_effect = {
			duel = {
				skill = intrigue
				target = scope:accused
				8 = {
					trigger = {
						scope:victim_scheme = {
							any_scheme_agent_character = { this = scope:accused }
						}
					}
					compare_modifier = {
						value = scope:duel_value
						multiplier = 2
					}
					send_interface_toast = {
						title = hold_court.8160.c.tt_success
						left_icon = scope:accused
						right_icon = scope:victim
						hold_court_8160_imprison_effect = yes
					}
				}
				12 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = -2
						min = -9
					}
					send_interface_toast = {
						title = hold_court.8160.c.tt_failure
						left_icon = scope:accused
						right_icon = scope:victim
						add_prestige = medium_prestige_loss
						scope:victim = {
							add_opinion = {
								modifier = disappointed_opinion
								target = root
								opinion = -5
							}
						}
						if = {
							limit = { exists = scope:concerned }
							scope:concerned = {
								add_opinion = {
									modifier = disappointed_opinion
									target = root
									opinion = -5
								}
							}
						}
					}
				}
			}
		}
		stress_impact = {
			arbitrary = medium_stress_impact_gain
			lazy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = 1
   				ai_compassion = 1
   				ai_zeal = -1
   				ai_energy = -1
   				ai_rationality = 1
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = arbitrary
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = lazy
			}
		}
	}

	option = { # Dismiss
		name = {
			trigger = {
				scope:victim_scheme = {
					any_scheme_agent_character = { this = root }
				}
			}
			text = hold_court.8160.d.involved
		}
		name = {
			trigger = {
				scope:victim_scheme.scheme_owner = { is_agent_exposed_in_scheme = scope:victim_scheme }
			}
			text = hold_court.8160.d.proof
		}
		name = {
			trigger = { always = yes }
			text = hold_court.8160.d.fallback
		}
		scope:victim_scheme = {
			if = {
				limit = {
					any_scheme_agent_character = { this = root }
				}
				add_scheme_progress = scheme_progress_gain
			}
		}
		scope:accused = {
			add_opinion = {
				modifier = grateful_opinion
				target = root
				opinion = 10
			}
		}
		if = {
			limit = { exists = scope:concerned }
			scope:concerned = {
				add_opinion = {
					modifier = disappointed_opinion
					target = root
					opinion = -10
				}
			}
		}
		scope:victim = {
			add_opinion = {
				modifier = disappointed_opinion
				target = root
				opinion = -10
			}
		}
		if = {
			limit = {
				scope:victim_scheme.scheme_owner = { is_agent_exposed_in_scheme = scope:victim_scheme }
			}
			stress_impact = {
				just = major_stress_impact_gain
				compassionate = major_stress_impact_gain
			}
		}
		else = {
			stress_impact = {
				just = medium_stress_impact_gain
				compassionate = medium_stress_impact_gain
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = 0.5
   				ai_compassion = 0.5
   				ai_energy = -2
			}
		}
	}

	after = {
		if = {
			limit = { has_character_flag = concerned_exists }
			remove_character_flag = concerned_exists
		}
		scope:victim = {
			clear_court_event_participation = yes
		}
		scope:accused = {
			clear_court_event_participation = yes
		}
		if = {
			limit = { exists = scope:concerned }
			scope:concerned = {
				clear_court_event_participation = yes
			}
		}
		if = {
			limit = { exists = scope:executioner }
			scope:executioner = {
				clear_court_event_participation = yes
			}
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

##################################################
# Personal Matter
# by Joe Parkin
# 8161
##################################################

# Is the character able to be targeted by a valid scheme?
scripted_trigger hold_court_8161_valid_seduce_target_trigger = {
	this != root
	age < 50
	has_court_event_flag = no
	is_available_ai_adult = yes
	exists = liege
	save_temporary_scope_as = hold_court_8161_victim
	liege = {
		any_vassal_or_below = { hold_court_8161_valid_seduce_plotter_trigger = yes }
	}
}

# Is the character able to start a valid scheme?
scripted_trigger hold_court_8161_valid_seduce_plotter_trigger = {
	NOR = {
		this = root
		is_spouse_of = root
	}
	age < 50
	is_available_ai_adult = yes
	possibly_interested_in_character_trigger = { CHARACTER = scope:hold_court_8161_victim } # victim
	might_cheat_on_every_partner_trigger = yes
	can_start_scheme = {
		type = seduce
		target_character = scope:hold_court_8161_victim # victim
	}
	exists = scope:hold_court_8161_victim.primary_spouse # to avoid errors
	NOR = {
		has_trait = chaste
		has_trait = shy
		has_trait = craven
		has_trait = content
		has_trait = celibate
	}
	NOR = {
		this = scope:hold_court_8161_victim # victim
		this = scope:hold_court_8161_victim.primary_spouse # victim's spouse
		has_friendly_relationship_trigger = { CHARACTER = scope:hold_court_8161_victim.primary_spouse } # victim's spouse
	}
}

# Is the scheme a valid seduction scheme?
scripted_trigger hold_court_8161_valid_seduce_scheme_trigger = {
	hold_court_8160_valid_court_scheme_trigger = yes
	scheme_type = seduce
	scheme_success_chance >= 30
}

# Is the character a valid event target?
scripted_trigger hold_court_8161_valid_target_vassal_trigger = {
	NOR = {
		this = root
		is_spouse_of = root
	}
	has_court_event_flag = no
	is_available_ai_adult = yes
	is_married = yes
	top_liege = primary_spouse.top_liege
	trigger_if = {
		limit = {
			primary_spouse = { is_male = yes }
		}
		NOT = {
			faith = { has_doctrine = doctrine_adultery_men_accepted }
		}
	}
	trigger_else = {
		NOT = {
			faith = { has_doctrine = doctrine_adultery_women_accepted }
		}
	}
	OR = {
		hold_court_8161_valid_seduce_target_trigger = yes
		primary_spouse = { hold_court_8161_valid_seduce_target_trigger = yes }
	}
}

scripted_trigger hold_court_8161_existing_seduction_target_trigger = {
	this != root
	OR = {
		any_targeting_scheme = { hold_court_8161_valid_seduce_scheme_trigger = yes }
		primary_spouse = {
			any_targeting_scheme = { hold_court_8161_valid_seduce_scheme_trigger = yes }
		}
	}
}

scripted_trigger hold_court_8161_religious_crime_trigger = {
	OR = {
		AND = {
			scope:victim.primary_spouse = { is_female = yes }
			NOT = {
				faith = { has_doctrine = doctrine_adultery_women_accepted }
			}
		}
		AND = {
			scope:victim.primary_spouse = { is_male = yes }
			NOT = {
				faith = { has_doctrine = doctrine_adultery_men_accepted }
			}
		}
		AND = {
			OR = {
				AND = {
					scope:victim = { is_male = yes }
					scope:accused = { is_male = yes }
				}
				AND = {
					scope:victim = { is_female = yes }
					scope:accused = { is_female = yes }
				}
			}
			NOT = {
				faith = { has_doctrine = doctrine_homosexuality_accepted }
			}	
		}
	}	
}

# Save or create a seduction scheme in the court
scripted_effect hold_court_8161_save_create_scheme_effect = {
	if = {
		limit = {
			any_targeting_scheme = { hold_court_8161_valid_seduce_scheme_trigger = yes }
		}
		random_targeting_scheme = {
			limit = { hold_court_8161_valid_seduce_scheme_trigger = yes }
			save_scope_as = victim_scheme
			scheme_target_character = { save_scope_as = victim }
			scheme_owner = { save_scope_as = debug_scheme_owner }
		}
	}
	else = {
		save_scope_as = victim
		liege = {
			random_vassal_or_below = {
				limit = { hold_court_8161_valid_seduce_plotter_trigger = yes }
				weight = {
					base = 1
					modifier = {
						factor = 2
						has_trait = lustful
					}
					modifier = {
						factor = 4
						has_trait = honest
					}
					modifier = {
						factor = 2
						intrigue < average_skill_rating
					}
					modifier = {
						factor = 4
						has_trait = contrite
					}
					modifier = {
						factor = 4
						has_trait = confider
					}
					modifier = {
						factor = 2
						has_trait = trusting
					}
				}
				save_scope_as = debug_scheme_owner
				start_scheme = {
					type = seduce
					target_character = scope:victim
				}
			}
		}
		random_targeting_scheme = {
			limit = { scheme_owner = scope:debug_scheme_owner }
			save_scope_as = victim_scheme
		}
	}
	scope:victim = {
		court_event_character_flag_effect = yes
		primary_spouse = {
			court_event_character_flag_effect = yes
		}
	}
}

# Choose who is the target of the scheme
scripted_effect hold_court_8161_vassal_spouse_scheme_effect = {
	hidden_effect = {
		random_list = {
			50 = {
				trigger = { hold_court_8161_valid_seduce_target_trigger = yes }
				hold_court_8161_save_create_scheme_effect = yes
			}
			100 = {
				trigger = {
					primary_spouse = { hold_court_8161_valid_seduce_target_trigger = yes }
				}
				primary_spouse = { hold_court_8161_save_create_scheme_effect = yes }
			}
		}
	}
}

# Spouse of the target of a scheme wants you to punish the schemer - seduction version
hold_court.8161 = {
	type = court_event
	title = hold_court.8161.t
	desc = {
		desc = hold_court.8161.desc.intro
		first_valid = {
			triggered_desc = { # Nemeses
				trigger = {
					scope:accused = { has_relation_nemesis = scope:victim.primary_spouse }
				}
				desc = hold_court.8161.desc.nemesis
			}
			triggered_desc = { # Rivals
				trigger = {
					scope:accused = { has_relation_rival = scope:victim.primary_spouse }
				}
				desc = hold_court.8161.desc.rival
			}
			triggered_desc = { # Quarry
				trigger = {
					scope:victim = {
						OR = {
							has_trait = beauty_good_1
							has_trait = beauty_good_2
							has_trait = beauty_good_3
							has_trait = lustful
						}
					}
				}
				desc = hold_court.8161.desc.quarry
			}
			triggered_desc = { # Accused dislikes Target
				trigger = {
					scope:accused = {
						opinion = {
							target = scope:victim.primary_spouse
							value < 0
						}
					}
				}
				desc = hold_court.8161.desc.their_dislike
			}
			triggered_desc = { # Target dislikes Accused
				trigger = {
					scope:accused = {
						reverse_opinion = {
							target = scope:victim.primary_spouse
							value < 0
						}
					}
				}
				desc = hold_court.8161.desc.my_dislike
			}
			triggered_desc = { # Accused is a villain
				trigger = {
					scope:accused = {
						OR = {
							has_education_intrigue_trigger = yes
							has_trait = deceitful
							has_trait = lustful
							has_trait = seducer
						}
					}
				}
				desc = hold_court.8161.desc.intrigue
			}
			desc = hold_court.8161.desc.fallback # No good reason
		}
		desc = hold_court.8161.desc.body
	}
	theme = realm
	lower_right_portrait = scope:accused
	court_scene = {
		button_position_character = scope:victim.primary_spouse
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:victim.primary_spouse = {
				group = petitioners_group
				animation = anger
			}
			scope:victim = {
				group = petitioners_group
				animation = disapproval
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

	cooldown = { years = 5 }

	trigger = {
		OR = {
			any_courtier_or_guest = {
				hold_court_8161_valid_target_vassal_trigger = yes
				trigger_if = {
					limit = { NOT = { exists = scope:victim } }
					save_temporary_scope_as = victim
				}
				exists = scope:victim.primary_spouse
			}
			any_vassal = {
				hold_court_8161_valid_target_vassal_trigger = yes
				trigger_if = {
					limit = { NOT = { exists = scope:victim } }
					save_temporary_scope_as = victim
				}
				exists = scope:victim.primary_spouse
			}
		}
		OR = {
			any_vassal_or_below = {
				age < 50
				is_available_ai_adult = yes
				possibly_interested_in_character_trigger = { CHARACTER = scope:victim }
				can_start_scheme = {
					type = seduce
					target_character = scope:victim
				}
				exists = scope:victim.primary_spouse
				NOR = {
					this = scope:victim
					this = scope:victim.primary_spouse
					has_friendly_relationship_trigger = { CHARACTER = scope:victim.primary_spouse }
				}
			}
			any_courtier_or_guest = {
				age < 50
				is_available_ai_adult = yes
				possibly_interested_in_character_trigger = { CHARACTER = scope:victim }
				can_start_scheme = {
					type = seduce
					target_character = scope:victim
				}
				exists = scope:victim.primary_spouse
				NOR = {
					this = scope:victim
					this = scope:victim.primary_spouse
					has_friendly_relationship_trigger = { CHARACTER = scope:victim.primary_spouse }
				}
			}
		}
	}

	weight_multiplier = {
		base = 1

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

	immediate = {
		random_list = {
			2 = {
				trigger = {
					any_courtier_or_guest = { hold_court_8161_valid_target_vassal_trigger = yes }
				}
				random_courtier_or_guest = {
					limit = {
						hold_court_8161_valid_target_vassal_trigger = yes
						hold_court_8161_existing_seduction_target_trigger = yes
					}
					alternative_limit = {
						hold_court_8161_valid_target_vassal_trigger = yes
					}
					weight = {
						modifier = {
							factor = 50
							has_trait = paranoid
						}
						modifier = {
							factor = 25
							has_trait = arrogant
						}
					}
					hold_court_8161_vassal_spouse_scheme_effect = yes
				}
			}
			2 = {
				trigger = {
					any_vassal_or_below = { hold_court_8161_valid_target_vassal_trigger = yes }
				}
				random_vassal_or_below = {
					limit = {
						hold_court_8161_valid_target_vassal_trigger = yes
						hold_court_8161_existing_seduction_target_trigger = yes
					}
					alternative_limit = {
						hold_court_8161_valid_target_vassal_trigger = yes
					}
					weight = {
						modifier = {
							factor = 50
							has_trait = paranoid
						}
						modifier = {
							factor = 25
							has_trait = arrogant
						}
					}
					hold_court_8161_vassal_spouse_scheme_effect = yes
				}
			}
		}
		hidden_effect = {
			random_list = {
				50 = {
					trigger = { exists = scope:debug_scheme_owner }
					scope:debug_scheme_owner = { save_scope_as = accused }
				}
				25 = {
					trigger = {
						any_vassal_or_below = {
							age < 50
							is_available_ai_adult = yes
							possibly_interested_in_character_trigger = { CHARACTER = scope:victim }
							can_start_scheme = {
								type = seduce
								target_character = scope:victim
							}
							exists = scope:victim.primary_spouse
							NOR = {
								this = scope:victim
								this = scope:victim.primary_spouse
								has_friendly_relationship_trigger = { CHARACTER = scope:victim.primary_spouse }
							}
						}
					}
					random_vassal_or_below = {
						limit = {
							age < 50
							is_available_ai_adult = yes
							possibly_interested_in_character_trigger = { CHARACTER = scope:victim }
							can_start_scheme = {
								type = seduce
								target_character = scope:victim
							}
							exists = scope:victim.primary_spouse
							NOR = {
								this = scope:victim
								this = scope:victim.primary_spouse
								has_friendly_relationship_trigger = { CHARACTER = scope:victim.primary_spouse }
							}
						}
						weight = {
							base = 1
							modifier = {
								factor = 100
								has_relation_nemesis = scope:victim.primary_spouse # Nemeses
							}
							modifier = {
								factor = 50
								has_relation_rival = scope:victim.primary_spouse # Rivals
							}
							modifier = {
								factor = 25
								opinion = {
									target = scope:victim.primary_spouse # Accused dislikes Target
									value < 0
								}
							}
							modifier = {
								factor = 25
								reverse_opinion = {
									target = scope:victim.primary_spouse # Target dislikes Accused
									value < 0
								}
							}
							modifier = { # Accused is a villain
								factor = 50
								OR = {
									has_education_intrigue_trigger = yes
									has_trait = deceitful
									has_trait = lustful
									has_trait = seducer
								}
							}
						}
						save_scope_as = accused
					}
				}
				25 = {
					trigger = {
						any_courtier_or_guest = {
							age < 50
							is_available_ai_adult = yes
							possibly_interested_in_character_trigger = { CHARACTER = scope:victim }
							can_start_scheme = {
								type = seduce
								target_character = scope:victim
							}
							exists = scope:victim.primary_spouse
							NOR = {
								THIS = scope:victim
								THIS = scope:victim.primary_spouse
								has_friendly_relationship_trigger = { CHARACTER = scope:victim.primary_spouse }
							}
						}
					}
					random_courtier_or_guest = {
						limit = {
							age < 50
							is_available_ai_adult = yes
							possibly_interested_in_character_trigger = { CHARACTER = scope:victim }
							can_start_scheme = {
								type = seduce
								target_character = scope:victim
							}
							exists = scope:victim.primary_spouse
							NOR = {
								THIS = scope:victim
								THIS = scope:victim.primary_spouse
								has_friendly_relationship_trigger = { CHARACTER = scope:victim.primary_spouse }
							}
						}
						weight = {
							base = 1
							modifier = {
								factor = 100
								has_relation_nemesis = scope:victim.primary_spouse # Nemeses
							}
							modifier = {
								factor = 50
								has_relation_rival = scope:victim.primary_spouse # Rivals
							}
							modifier = {
								factor = 25
								opinion = {
									target = scope:victim.primary_spouse # Accused dislikes Target
									value < 0
								}
							}
							modifier = {
								factor = 25
								reverse_opinion = {
									target = scope:victim.primary_spouse # Target dislikes Accused
									value < 0
								}
							}
							modifier = { # Accused is a villain
								factor = 50
								OR = {
									has_education_intrigue_trigger = yes
									has_trait = deceitful
									has_trait = lustful
									has_trait = seducer
								}
							}
						}
						save_scope_as = accused
					}
				}
			}
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = { # Arrest
		name = {
			trigger = {
				OR = {
					AND = {
						scope:victim = { is_male = yes }
						scope:accused = { is_male = yes }
					}
					AND = {
						scope:victim = { is_female = yes }
						scope:accused = { is_female = yes }
					}
				}
				NOT = {
					faith = { has_doctrine = doctrine_homosexuality_accepted }
				}
			}
			text = hold_court.8161.a.homosexual
		}
		name = {
			trigger = {
				OR = {
					AND = {
						scope:victim.primary_spouse = { is_female = yes }
						NOT = {
							faith = { has_doctrine = doctrine_adultery_women_accepted }
						}
					}
					AND = {
						scope:victim.primary_spouse = { is_male = yes }
						NOT = {
							faith = { has_doctrine = doctrine_adultery_men_accepted }
						}
					}
				}	
			}
			text = hold_court.8161.a.adultery
		}
		trigger = { hold_court_8161_religious_crime_trigger = yes }
		if = {
			limit = {
				OR = {
					AND = {
						scope:victim.primary_spouse = { is_female = yes }
						NOT = {
							faith = { has_doctrine = doctrine_adultery_women_accepted }
						}
					}
					AND = {
						scope:victim.primary_spouse = { is_male = yes }
						NOT = {
							faith = { has_doctrine = doctrine_adultery_men_accepted }
						}
					}
				}
			}
			add_opinion = {
				modifier = fornicator_crime
				target = scope:accused
			}
		}
		else = {
			add_opinion = {
				modifier = deviant_crime
				target = scope:accused
			}
		}
		scope:victim.primary_spouse = {
			add_opinion = {
				modifier = grateful_opinion
				target = root
				opinion = 10
			}
		}
		scope:accused = {
			add_opinion = {
				modifier = angry_opinion
				target = root
				opinion = -10
			}
			add_opinion = {
				modifier = angry_opinion
				target = scope:victim.primary_spouse
				opinion = -10
			}
		}
		if = {
			limit = {
				exists = cp:councillor_court_chaplain
				NOR = {
					cp:councillor_court_chaplain = scope:accused
					cp:councillor_court_chaplain = scope:victim
					cp:councillor_court_chaplain = scope:victim.primary_spouse
				}
				NOR = {
					AND = {
						scope:victim.primary_spouse = { is_female = yes }
						faith = { has_doctrine = doctrine_adultery_women_accepted }
					}
					AND = {
						scope:victim.primary_spouse = { is_male = yes }
						faith = { has_doctrine = doctrine_adultery_men_accepted }
					}
				}
			}
			cp:councillor_court_chaplain = {
				add_opinion = {
					modifier = pious_opinion
					target = root
					opinion = 10
				}
			}
		}
		stress_impact = {
			just = medium_stress_impact_gain
			cynical = medium_stress_impact_gain
			deviant = medium_stress_impact_gain
			lustful = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = -0.25
   				ai_compassion = -1
   				ai_zeal = 1
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = just
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = cynical
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = deviant
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = lustful
			}
		}
	}

	option = { # Attempt to find truth
		name = hold_court.8161.c
		show_as_tooltip = {
			duel = {
				skill = intrigue
				target = scope:accused
				1 = {
					show_chance = no
					desc = hold_court.8160.c.tt_success
					hold_court_8160_imprison_effect = yes
				}
				1 = {
					show_chance = no
					desc = hold_court.8160.c.tt_failure
					scope:accused = {
						add_opinion = {
							modifier = angry_opinion
							target = root
							opinion = -10
						}
					}
				}
			}
		}
		hidden_effect = {
			duel = {
				skill = intrigue
				target = scope:accused
				8 = {
					trigger = {
						scope:victim_scheme ?= {
							any_scheme_agent_character = { this = scope:accused }
						}
					}
					compare_modifier = {
						value = scope:duel_value
						multiplier = 2
					}
					send_interface_toast = {
						title = hold_court.8160.c.tt_success
						left_icon = scope:accused
						right_icon = scope:victim
						hold_court_8160_imprison_effect = yes
					}
				}
				12 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = -1
					}
					send_interface_toast = {
						title = hold_court.8160.c.tt_failure
						left_icon = scope:accused
						right_icon = scope:victim
						scope:accused = {
							add_opinion = {
								modifier = angry_opinion
								target = root
								opinion = -10
							}
						}
					}
				}
			}
		}
		stress_impact = {
			arbitrary = medium_stress_impact_gain
			lazy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = 1
   				ai_compassion = 1
   				ai_zeal = -1
   				ai_energy = -1
   				ai_rationality = 1
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = arbitrary
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = lazy
			}
		}
	}

	option = { # Dismiss
		name = {
			trigger = {
				scope:victim_scheme ?= {
					any_scheme_agent_character = { this = root }
				}
			}
			text = hold_court.8161.d.involved
		}
		name = {
			trigger = {
				OR = {
					AND = {
						scope:victim.primary_spouse = { is_female = yes }
						faith = { has_doctrine = doctrine_adultery_women_accepted }
					}
					AND = {
						scope:victim.primary_spouse = { is_male = yes }
						faith = { has_doctrine = doctrine_adultery_men_accepted }
					}
				}	
			}
			text = hold_court.8161.d.permitted
		}
		name = {
			trigger = { always = yes }
			text = hold_court.8161.d.fallback
		}
		scope:victim_scheme ?= {
			if = {
				limit = {
					any_scheme_agent_character = { this = root }
				}
				add_scheme_progress = scheme_progress_gain
			}
		}
		scope:victim.primary_spouse = {
			add_opinion = {
				modifier = disappointed_opinion
				target = root
				opinion = -10
			}
		}
		stress_impact = {
			chaste = medium_stress_impact_gain
		}
		if = {
			limit = { hold_court_8161_religious_crime_trigger = yes }
			stress_impact = {
				zealous = medium_stress_impact_gain
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = 0.5
   				ai_compassion = 0.5
   				ai_energy = -2
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = chaste
			}
			modifier = {	#Weight down for stress.
				add = -30
				hold_court_8161_religious_crime_trigger = yes
				has_trait = zealous
			}
		}
	}

	after = {
		scope:victim = {
			clear_court_event_participation = yes
			primary_spouse = {
				clear_court_event_participation = yes
			}
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

##################################################
# Noble Privileges
# by Joe Parkin
# 8180
##################################################

# Is there a duke or higher vassal has room for a positive contract change?
scripted_trigger hold_court_8180_lord_trigger = {
	has_court_event_flag = no
	is_available_ai_adult = yes
	primary_title.tier >= tier_duchy
	government_has_flag = government_is_feudal
	subject_contract_is_blocked_from_modification = no
	NOT = { has_variable = hc_8180_contract_var }
	NOT = { has_hook = root }
	OR = {
		AND = {
			faith != liege.faith
			vassal_contract_obligation_level_can_be_increased = religious_rights # Religious
		}
		AND = {
			liege.culture = { has_innovation = innovation_battlements }
			vassal_contract_obligation_level_can_be_increased = fortification_rights # Fortification
		}
		AND = {
			liege.culture = { has_innovation = innovation_currency_02 }
			vassal_contract_obligation_level_can_be_increased = coinage_rights # Coinage
		}
		AND = {
			liege = { 
				OR = { # Only relevant if war declaration is limited
					has_realm_law = crown_authority_2
					has_realm_law = crown_authority_3
				}
			}
			vassal_contract_obligation_level_can_be_increased = war_declaration_rights # War Declaration
		}
		vassal_contract_obligation_level_can_be_increased = council_rights # Council
		AND = {
			NOT = {
				liege = { has_realm_law = crown_authority_0 } # Only relevant if revocation is possible
			}
			vassal_contract_obligation_level_can_be_increased = title_revocation_rights # Title Revocation
		}
		AND = { # Scutage
			liege.culture = {
				has_innovation = innovation_scutage
			}
			NOT = { vassal_contract_has_flag = has_scutage_contract }
		}
		AND = { # March
			liege.culture = {
				has_innovation = innovation_burhs
			}
			NOT = { vassal_contract_has_flag = has_march_contract }
		}
		AND = { # Palatinate
			liege.culture = {
				has_innovation = innovation_divine_right
			}
			NOT = { vassal_contract_has_flag = has_palatinate_contract }
		}
	}
}

# Increase the relevant contract
scripted_effect hold_court_8180_grant_contract_effect = {
	switch = {
		trigger = var:hc_8180_contract_var
		1 = { # Religious
			vassal_contract_set_obligation_level = {
				type = religious_rights
				level = 1
			}
		}
		2 = { # Fortification
			vassal_contract_set_obligation_level = {
				type = fortification_rights
				level = 1
			}
		}
		3 = { # Coinage
			vassal_contract_set_obligation_level = {
				type = coinage_rights
				level = 1
			}
		}
		4 = { # War Declaration
			vassal_contract_set_obligation_level = {
				type = war_declaration_rights
				level = 1
			}
		}
		5 = { # Council Rights
			vassal_contract_set_obligation_level = {
				type = council_rights
				level = 1
			}
		}
		6 = { # Title Revocation
			vassal_contract_set_obligation_level = {
				type = title_revocation_rights
				level = 1
			}
		}
		7 = { # Scutage
			vassal_contract_set_obligation_level = {
				type = special_contract
				level = 1
			}
		}
		8 = { # March
			vassal_contract_set_obligation_level = {
				type = special_contract
				level = 2
			}
		}
		9 = { # Palatinate
			vassal_contract_set_obligation_level = {
				type = special_contract
				level = 3
			}
		}
	}
	hidden_effect = { set_subject_contract_modification_blocked = yes }
}

# A vassal wants a contract buff
hold_court.8180 = {
	type = court_event
	title = hold_court.8180.t
	desc = {
		desc = hold_court.8180.desc.intro
		first_valid = { # Contract Type
			triggered_desc = {
				trigger = { scope:contract_lord.var:hc_8180_contract_var = 1 }
				desc = hold_court.8180.desc.religious # Religious
			}
			triggered_desc = {
				trigger = { scope:contract_lord.var:hc_8180_contract_var = 2 }
				desc = hold_court.8180.desc.fortification # Fortification
			}
			triggered_desc = {
				trigger = { scope:contract_lord.var:hc_8180_contract_var = 3 }
				desc = hold_court.8180.desc.coinage # Coinage
			}
			triggered_desc = {
				trigger = { scope:contract_lord.var:hc_8180_contract_var = 4 }
				desc = hold_court.8180.desc.war_declaration # War Declaration
			}
			triggered_desc = {
				trigger = { scope:contract_lord.var:hc_8180_contract_var = 5 }
				desc = hold_court.8180.desc.council # Council
			}
			triggered_desc = {
				trigger = { scope:contract_lord.var:hc_8180_contract_var = 6 }
				desc = hold_court.8180.desc.title_revocation # Title Revocation
			}
			triggered_desc = {
				trigger = { scope:contract_lord.var:hc_8180_contract_var = 7 }
				desc = hold_court.8180.desc.scutage # Scutage
			}
			triggered_desc = {
				trigger = { scope:contract_lord.var:hc_8180_contract_var = 8 }
				desc = hold_court.8180.desc.march # March
			}
			triggered_desc = {
				trigger = { scope:contract_lord.var:hc_8180_contract_var = 9 }
				desc = hold_court.8180.desc.palatinate # Palatinate
			}
			triggered_desc = {
				trigger = { scope:contract_lord.var:hc_8180_contract_var = 10 }
				desc = hold_court.8180.desc.family_entrepeneurship # Family Entrepeneurship
			}
			triggered_desc = {
				trigger = { scope:contract_lord.var:hc_8180_contract_var = 11 }
				desc = hold_court.8180.desc.centralized_power # Centralized Power
			}
		}
		first_valid = { # Context
			# Religious
			triggered_desc = {
				trigger = {
					scope:contract_lord.var:hc_8180_contract_var = 1 # Religious
					scope:contract_lord.religion = root.religion
				}
				desc = hold_court.8180.desc.religious_heretic # Heretic
			}
			triggered_desc = {
				trigger = { scope:contract_lord.var:hc_8180_contract_var = 1 } # Religious
				desc = hold_court.8180.desc.religious_heathen # Heathen
			}
			# Martial
			triggered_desc = {
				trigger = {
					OR = {
						scope:contract_lord.var:hc_8180_contract_var = 2 #Fortification
						scope:contract_lord.var:hc_8180_contract_var = 8 # March
					}
				}
				desc = hold_court.8180.desc.martial_defensive # Defensive
			}
			triggered_desc = {
				trigger = {
					scope:contract_lord.var:hc_8180_contract_var = 4 # War Declaration
					scope:contract_lord.var:hc_8180_contract_var = 7 # Scutage
				}
				desc = hold_court.8180.desc.martial_offensive # Offensive
			}
			# Stewardship
			triggered_desc = {
				trigger = {
					OR = {
						scope:contract_lord.var:hc_8180_contract_var = 3 # Coinage
						scope:contract_lord.var:hc_8180_contract_var = 11 # Centralized Power
					}
				}
				desc = hold_court.8180.desc.stewardship
			}
			# Status
			triggered_desc = {
				trigger = {
					OR = {
						scope:contract_lord.var:hc_8180_contract_var = 5 # Council
						scope:contract_lord.var:hc_8180_contract_var = 9 # Palatinate
					}
				}
				desc = hold_court.8180.desc.status
			}
			# Family
			triggered_desc = {
				trigger = { scope:contract_lord.var:hc_8180_contract_var = 10 } #Family Entrepeneurship
				desc = hold_court.8180.desc.family
			}
			# Other
			desc = hold_court.8180.desc.fallback # General
		}
	}
	theme = court
	artifact = {
		target = scope:vassal_artifact
		position = lower_right_portrait
	}
	court_scene = {
		button_position_character = scope:contract_lord
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:contract_lord = {
				group = petitioners_group
				animation = admiration
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

	cooldown = { years = 10 }

	trigger = {
		is_adult = yes
		any_vassal = { hold_court_8180_lord_trigger = yes }
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = 1
			any_vassal = {
				hold_court_8180_lord_trigger = yes
				OR = {
					has_trait = greedy
					has_trait = ambitious
					has_trait = shrewd
					has_trait = intellect_good_1
					has_trait = intellect_good_2
					has_trait = intellect_good_3
				}
			}
		}

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

	immediate = {
		capital_barony = { save_scope_as = capital }
		random_vassal = {
			limit = {
				hold_court_8180_lord_trigger = yes
				primary_title.tier = tier_kingdom # Prefer Kings...
			}
			alternative_limit = {
				hold_court_8180_lord_trigger = yes 
				primary_title.tier = tier_duchy # ...then Dukes.
			}
			weight = {
				base = 1
				modifier = {
					factor = 2
					NOT = { vassal_contract_obligation_level_can_be_decreased = special_contract } # No existing special contract
				}
				modifier = {
					factor = 2
					is_powerful_vassal = yes
				}
				modifier = {
					factor = 2
					OR = {
						vassal_contract_obligation_level_can_be_increased = feudal_government_taxes
						vassal_contract_obligation_level_can_be_increased = feudal_government_levies
					}
				}
				modifier = {
					factor = 2
					does_ai_vassal_in_vassal_contract_desire_obligation_change = yes
				}
				modifier = {
					factor = 2
					has_trait = greedy
					has_trait = ambitious
					has_trait = shrewd
					has_trait = intellect_good_1
					has_trait = intellect_good_2
					has_trait = intellect_good_3
				}
			}
			save_scope_as = contract_lord
			court_event_character_flag_effect = yes
			if = {
				limit = {
					any_held_title = {
						count > 1
						title_tier = county
						is_landless_type_title = no
					}
				}
				ordered_held_title = {
					title_tier = county
					limit = {
						this != holder.capital_county
						de_jure_liege.holder = root
						is_landless_type_title = no
					}
					alternative_limit = {
						tier = tier_county
						this != holder.capital_county
						any_neighboring_county = { holder = root }
						is_landless_type_title = no
					}
					alternative_limit = {
						tier = tier_county
						this != holder.capital_county
						is_landless_type_title = no
					}
					order_by = {
						value = 0
						subtract = development_level
					}
					save_scope_as = vassal_title
				}
			}
			if = {
				limit = {
					any_character_artifact = { exists = yes }
				}
				ordered_character_artifact = {
					order_by = artifact_rarity
					save_scope_as = vassal_artifact
				}
			}
			hidden_effect = {
				random_list = {
					1 = { # Religious Rights / 1
						trigger = {
							faith != liege.faith
							vassal_contract_obligation_level_can_be_increased = religious_rights
						}
						modifier = {
							factor = 2
							faith != liege.faith
						}
						modifier = {
							factor = 2
							religion != liege.religion
						}
						modifier = {
							factor = 2
							has_trait = zealous
						}
						modifier = { factor = 4 } # contract relative value
						set_variable = {
							name = hc_8180_contract_var
							value = 1
							years = 20 # cooldown for this character
						}
					}
					1 = { # Fortification Rights / 2
						trigger = {
							liege.culture = { has_innovation = innovation_battlements }
							vassal_contract_obligation_level_can_be_increased = fortification_rights
						}
						modifier = {
							factor = 2
							any_sub_realm_county = { hold_court_8010_county_trigger = yes }
						}
						modifier = {
							factor = 2
							has_education_martial_trigger = yes
						}
						modifier = {
							factor = 2
							has_martial_lifestyle_trait_trigger = yes
						}
						modifier = { factor = 2 } # contract relative value
						set_variable = {
							name = hc_8180_contract_var
							value = 2
							years = 20 # cooldown for this character
						}
					}
					1 = { # Coinage Rights / 3
						trigger = {
							liege.culture = { has_innovation = innovation_currency_02 }
							vassal_contract_obligation_level_can_be_increased = coinage_rights
						}
						modifier = {
							factor = 2
							has_education_stewardship_trigger = yes
						}
						modifier = {
							factor = 2
							has_stewardship_lifestyle_trait_trigger = yes
						}
						modifier = {
							factor = 2
							has_trait = arrogant
						}
						modifier = { factor = 2 } # contract relative value
						set_variable = {
							name = hc_8180_contract_var
							value = 3
							years = 20 # cooldown for this character
						}
					}
					1 = { # War Declaration / 4
						trigger = {
							liege = { 
								OR = { # Only relevant if war declaration is limited
									has_realm_law = crown_authority_2
									has_realm_law = crown_authority_3
								}
							}
							vassal_contract_obligation_level_can_be_increased = war_declaration_rights
						}
						modifier = {
							factor = 2
							has_education_martial_trigger = yes
						}
						modifier = {
							factor = 2
							has_martial_lifestyle_trait_trigger = yes
						}
						modifier = {
							factor = 2
							has_trait = ambitious
						}
						modifier = {
							factor = 2
							has_trait = wrathful
						}
						modifier = { factor = 3 } # contract relative value
						set_variable = {
							name = hc_8180_contract_var
							value = 4
							years = 20 # cooldown for this character
						}
					}
					1 = { # Council Rights / 5
						trigger = { vassal_contract_obligation_level_can_be_increased = council_rights }
						modifier = {
							factor = 2
							has_trait = ambitious
						}
						modifier = {
							factor = 2
							has_trait = arrogant
						}
						modifier = {
							factor = 2
							dynasty.dynasty_prestige_level >= liege.dynasty.dynasty_prestige_level
						}
						modifier = { factor = 4 } # contract relative value
						set_variable = {
							name = hc_8180_contract_var
							value = 5
							years = 20 # cooldown for this character
						}
					}
					1 = { # Title Revocation / 6
						trigger = {
							NOT = {
								liege = { has_realm_law = crown_authority_0 }
							}
							vassal_contract_obligation_level_can_be_increased = title_revocation_rights
						}
						modifier = {
							factor = 2
							has_trait = paranoid
						}
						modifier = {
							factor = 2
							has_trait = craven
						}
						modifier = { factor = 4 } # contract relative value
						set_variable = {
							name = hc_8180_contract_var
							value = 6
							years = 20 # cooldown for this character
						}
					}
					1 = { # Scutage / 7
						trigger = {
							liege.culture = {
								has_innovation = innovation_scutage
							}
							NOT = { vassal_contract_obligation_level_can_be_decreased = special_contract } # No existing special contract
						}
						modifier = {
							factor = 2
							OR = {
								has_education_martial_trigger = yes
								has_martial_lifestyle_trait_trigger = yes
							}
						}
						modifier = { factor = 3 } # contract relative value
						set_variable = {
							name = hc_8180_contract_var
							value = 7
							years = 20 # cooldown for this character
						}
					}
					1 = { # March / 8
						trigger = {
							liege.culture = {
								has_innovation = innovation_burhs
							}
							NOT = { vassal_contract_obligation_level_can_be_decreased = special_contract } # No existing special contract
						}
						modifier = {
							factor = 2
							has_education_martial_trigger = yes
						}
						modifier = {
							factor = 2
							has_martial_lifestyle_trait_trigger = yes
						}
						modifier = { factor = 3 } # contract relative value
						set_variable = {
							name = hc_8180_contract_var
							value = 8
							years = 20 # cooldown for this character
						}
					}
					1 = { # Palatinate / 9
						trigger = {
							liege.culture = {
								has_innovation = innovation_divine_right
							}
							is_powerful_vassal = yes
							NOT = { vassal_contract_obligation_level_can_be_decreased = special_contract } # No existing special contract
						}
						modifier = {
							factor = 2
							has_education_diplomacy_trigger = yes
						}
						modifier = {
							factor = 2
							has_diplomacy_lifestyle_trait_trigger = yes
						}
						modifier = {
							factor = 2
							has_trait = arrogant
						}
						modifier = {
							factor = 2
							dynasty.dynasty_prestige_level >= liege.dynasty.dynasty_prestige_level
						}
						modifier = { factor = 5 } # contract relative value
						set_variable = {
							name = hc_8180_contract_var
							value = 9
							years = 20 # cooldown for this character
						}
					}
				}
				if = { # Determine whether tax or levies can be increased, and is relevant
					limit = {
						has_variable = hc_8180_contract_var
						var:hc_8180_contract_var != 9 # Palatinate
						OR = {
							vassal_contract_obligation_level_can_be_increased = feudal_government_taxes
							vassal_contract_obligation_level_can_be_increased = feudal_government_levies
						}
					}
					random_list = {
						1 = {
							trigger = {
								var:hc_8180_contract_var != 8 # March
								var:hc_8180_contract_var != 11 # Centralized Power / Support
								vassal_contract_obligation_level_can_be_increased = feudal_government_taxes
							}
							modifier = {
								factor = 10
								vassal_contract_obligation_level:feudal_government_taxes < vassal_contract_obligation_level:feudal_government_levies
							}
							set_variable = {
								name = hc_8180_increase_var
								value = 1
							}
						}
						1 = {
							trigger = {
								var:hc_8180_contract_var != 7 # Scutage
								var:hc_8180_contract_var != 10 # Family Entrepeneurship
								vassal_contract_obligation_level_can_be_increased = feudal_government_levies
							}
							modifier = {
								factor = 10
								vassal_contract_obligation_level:feudal_government_levies < vassal_contract_obligation_level:feudal_government_taxes
							}
							set_variable = {
								name = hc_8180_increase_var
								value = 2
							}
						}
					}
				}
			}
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = { # Accept
		name = {
			trigger = { scope:contract_lord.var:hc_8180_contract_var = 1 }
			text = hold_court.8180.a.religious
		}
		name = {
			trigger = { scope:contract_lord.var:hc_8180_contract_var = 2 }
			text = hold_court.8180.a.fortification
		}
		name = {
			trigger = { scope:contract_lord.var:hc_8180_contract_var = 3 }
			text = hold_court.8180.a.coinage
		}
		name = {
			trigger = { scope:contract_lord.var:hc_8180_contract_var = 4 }
			text = hold_court.8180.a.war_declaration
		}
		name = {
			trigger = { scope:contract_lord.var:hc_8180_contract_var = 5 }
			text = hold_court.8180.a.council
		}
		name = {
			trigger = { scope:contract_lord.var:hc_8180_contract_var = 6 }
			text = hold_court.8180.a.title_revocation
		}
		name = {
			trigger = { scope:contract_lord.var:hc_8180_contract_var = 7 }
			text = hold_court.8180.a.scutage
		}
		name = {
			trigger = { scope:contract_lord.var:hc_8180_contract_var = 8 }
			text = hold_court.8180.a.march
		}
		name = {
			trigger = { scope:contract_lord.var:hc_8180_contract_var = 9 }
			text = hold_court.8180.a.palatinate
		}
		name = {
			trigger = { scope:contract_lord.var:hc_8180_contract_var = 10 }
			text = hold_court.8180.a.family_entrepeneurship
		}
		name = {
			trigger = { scope:contract_lord.var:hc_8180_contract_var = 11 }
			text = hold_court.8180.a.centralized_power
		}
		if = {
			limit = {
				can_add_hook = {
					target = scope:contract_lord
					type = indebted_hook
				}
			}
			add_hook = {
				target = scope:contract_lord
				type = indebted_hook
			}
		}
		scope:contract_lord = {
			hold_court_8180_grant_contract_effect = yes
			add_opinion = {
				modifier = grateful_opinion
				target = root
				opinion = 20
			}
		}
		stress_impact = {
			greedy = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = -2
   				ai_compassion = 1
   				ai_boldness = 1
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = greedy
			}
		}
	}

	option = { # Demand payment
		name = hold_court.8180.b
		trigger = {
			scope:contract_lord = { short_term_gold >= root.medium_gold_value }
		}
		random_list = {
			2 = {
				desc = hold_court.8180.b.tt.success
				modifier = {
					factor = 2
					scope:contract_lord = { has_trait = content }
				}
				modifier = {
					factor = 2
					scope:contract_lord = { has_trait = generous }
				}
				modifier = { factor = hold_court_8180_contract_value } # based on relative worth of contract
				send_interface_toast = {
					title = hold_court.8180.b.tt.success
					scope:contract_lord = {
						pay_short_term_gold = {
							target = root
							gold = root.medium_gold_value
						}
						hold_court_8180_grant_contract_effect = yes
						add_opinion = {
							modifier = annoyed_opinion
							target = root
							opinion = -5
						}
					}
				}				
			}
			7 = {
				desc = hold_court.8180.b.tt.failure
				modifier = {
					factor = 2
					scope:contract_lord = { has_trait = greedy }
				}
				modifier = {
					factor = 2
					scope:contract_lord = { has_trait = ambitious }
				}
				send_interface_toast = {
					title = hold_court.8180.b.tt.failure
					scope:contract_lord = {
						add_opinion = {
							modifier = angry_opinion
							target = root
							opinion = -15
						}
					}
				}
			}
		}
		stress_impact = {
			generous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 2
   				ai_compassion = -0.25
   				ai_rationality = 1
   				ai_boldness = 2
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = generous
			}
		}
	}

	option = { # Demand artifact
		name = hold_court.8180.c
		trigger = { exists = scope:vassal_artifact }
		random_list = {
			2 = {
				desc = hold_court.8180.c.tt.success
				modifier = {
					factor = 2
					scope:contract_lord = { has_trait = content }
				}
				modifier = {
					factor = 2
					scope:contract_lord = { has_trait = generous }
				}
				modifier = { factor = hold_court_8180_contract_value } # based on relative worth of contract
				send_interface_toast = {
					title = hold_court.8180.c.tt.success
					scope:contract_lord = {
						scope:vassal_artifact = {
							set_owner = { target = root }
						}
						hold_court_8180_grant_contract_effect = yes
						add_opinion = {
							modifier = annoyed_opinion
							target = root
							opinion = -5
						}
					}
				}				
			}
			7 = {
				desc = hold_court.8180.b.tt.failure
				modifier = {
					factor = 2
					scope:contract_lord = { has_trait = greedy }
				}
				modifier = {
					factor = 2
					scope:contract_lord = { has_trait = ambitious }
				}
				modifier = {
					factor = scope:vassal_artifact.var:quality # half of artifact quality
					trigger = {
						scope:vassal_artifact = { has_variable = quality }
					}
				}
				send_interface_toast = {
					title = hold_court.8180.b.tt.failure
					scope:contract_lord = {
						add_opinion = {
							modifier = angry_opinion
							target = root
							opinion = -15
						}
					}
				}
			}
		}
		stress_impact = {
			generous = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 2
   				ai_compassion = -0.25
   				ai_rationality = 1
   				ai_boldness = 2
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = generous
			}
		}
	}

	option = { # Demand title
		name = hold_court.8180.d
		trigger = { exists = scope:vassal_title }
		random_list = {
			2 = {
				desc = hold_court.8180.d.tt.success
				modifier = {
					factor = 2
					scope:contract_lord = { has_trait = content }
				}
				modifier = {
					factor = 2
					scope:contract_lord = { has_trait = generous }
				}
				modifier = { factor = hold_court_8180_contract_value } # based on relative worth of contract
				send_interface_toast = {
					title = hold_court.8180.d.tt.success
					create_title_and_vassal_change = {
						type = granted
						save_scope_as = change
						add_claim_on_loss = no
					}
					scope:vassal_title = {
						change_title_holder = {
							holder = root
							change = scope:change
						}
					}
					resolve_title_and_vassal_change = scope:change
					scope:contract_lord = { hold_court_8180_grant_contract_effect = yes }
				}
			}
			7 = {
				desc = hold_court.8180.b.tt.failure
				modifier = {
					factor = 2
					scope:contract_lord = { has_trait = greedy }
				}
				modifier = {
					factor = 2
					scope:contract_lord = { has_trait = ambitious }
				}
				modifier = {
					factor = 2
					OR = {
						scope:vassal_title.de_jure_liege.holder = root
						scope:contract_lord.primary_title = { is_de_jure_liege_or_above_target = scope:vassal_title }
					}
				}
				send_interface_toast = {
					title = hold_court.8180.b.tt.failure
					scope:contract_lord = {
						add_opinion = {
							modifier = angry_opinion
							target = root
							opinion = -15
						}
					}
				}
			}
		}
		stress_impact = {
			generous = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 2
   				ai_compassion = -0.25
   				ai_rationality = 1
   				ai_boldness = 2
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = generous
			}
		}
	}

	option = { # Demand forced partition
		name = hold_court.8180.e
		trigger = {
			scope:contract_lord = { vassal_contract_obligation_level_can_be_increased = succession_rights }
		}
		random_list = {
			3 = {
				desc = hold_court.8180.e.tt.success
				modifier = {
					factor = 2
					scope:contract_lord = { has_trait = content }
				}
				modifier = {
					factor = 2
					scope:contract_lord = { has_trait = generous }
				}
				modifier = { factor = hold_court_8180_contract_value } # based on relative worth of contract
				send_interface_toast = {
					title = hold_court.8180.e.tt.success
					scope:contract_lord = {
						hold_court_8180_grant_contract_effect = yes
						vassal_contract_set_obligation_level = {
							type = succession_rights
							level = 1
						}
						add_opinion = {
							modifier = annoyed_opinion
							target = root
							opinion = -5
						}
					}
				}
			}
			6 = {
				desc = hold_court.8180.b.tt.failure
				modifier = {
					factor = 2
					scope:contract_lord = { has_trait = greedy }
				}
				modifier = {
					factor = 2
					scope:contract_lord = { has_trait = ambitious }
				}
				modifier = {
					factor = 2
					any_heir = { count > 1 }
				}
				send_interface_toast = {
					title = hold_court.8180.b.tt.failure
					scope:contract_lord = {
						add_opinion = {
							modifier = angry_opinion
							target = root
							opinion = -15
						}
					}
				}
			}
		}
		stress_impact = {
			trusting = medium_stress_impact_gain
			generous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = -0.5
				ai_greed = 1
   				ai_compassion = -0.25
   				ai_rationality = 1
   				ai_boldness = 1
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = trusting
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = generous
			}
		}
	}

	option = { # Demand contract change
		name = hold_court.8180.f
		trigger = {
			scope:contract_lord = { has_variable = hc_8180_increase_var }
		}
		scope:contract_lord = {
			hold_court_8180_grant_contract_effect = yes
			if = {
				limit = { var:hc_8180_increase_var = 1 }
				vassal_contract_increase_obligation_level = feudal_government_taxes
			}
			else = { vassal_contract_increase_obligation_level = feudal_government_levies }
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 0.5
   				ai_compassion = 0.5
   				ai_rationality = 0.5
   				ai_boldness = -1
			}
		}
	}

	option = { # Dismiss vassal
		name = hold_court.8180.g
		scope:contract_lord = {
			add_opinion = {
				modifier = disappointed_opinion
				target = root
				opinion = -10
			}
		}
		stress_impact = {
			greedy = medium_stress_impact_gain
			generous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 1
   				ai_compassion = -0.5
   				ai_rationality = -0.25
   				ai_boldness = 0.5
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = greedy
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = generous
			}
		}
	}

	after = {
		scope:contract_lord = {
			clear_court_event_participation = yes
			if = {
				limit = { has_variable = hc_8180_increase_var }
				remove_variable = hc_8180_increase_var
			}
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

##################################################
# Enemy Within
# by Joe Parkin
# 8190
##################################################

# A vassal wants a foreigner vassal to convert
hold_court.8190 = {
	type = court_event
	title = hold_court.8190.t
	desc = {
		desc = hold_court.8190.desc.intro
		random_valid = {
			triggered_desc = {
				trigger = {
					NOT = {
						scope:other_vassal.culture = { has_same_culture_ethos = root.culture }
					}
				}
				desc = hold_court.8190.desc.ethos
			}
			triggered_desc = {
				trigger = {
					NOT = {
						scope:other_vassal.culture = { has_same_culture_heritage = root.culture }
					}
				}
				desc = hold_court.8190.desc.heritage
			}
			triggered_desc = {
				trigger = {
					NOT = {
						scope:other_vassal.culture = { has_same_culture_language = root.culture }
					}
				}
				desc = hold_court.8190.desc.language
			}
			desc = hold_court.8190.desc.fallback
		}
		desc = hold_court.8190.desc.body
	}
	theme = court
	lower_right_portrait = scope:other_vassal
	court_scene = {
		button_position_character = scope:aggressor_vassal
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:aggressor_vassal = {
				group = petitioners_group
				animation = rage
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

	cooldown = { years = 10 }

	trigger = {
		any_vassal = { # Is there a vassal who is not root culture?
			is_available_ai_adult = yes
			culture != root.culture
			save_temporary_scope_as = other_temp
		}
		any_vassal = { # Is there another vassal of root culture who is not humble and doesn't like the other one?
			has_court_event_flag = no
			is_available_ai_adult = yes
			culture = root.culture
			NOT = { has_trait = humble }
			NOR = {
				has_relation_friend = scope:other_temp
				scope:other_temp = {
					has_friendly_relationship_trigger = { CHARACTER = prev }
				}
			}
		}
	}

	weight_multiplier = {
		base = 1

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

	immediate = {
		random_vassal = {
			limit = {
				is_available_ai_adult = yes
				culture != root.culture
			}
			weight = {
				base = 1
				modifier = { # Victim is at least a count
					factor = 2
					primary_title.tier > tier_barony
				}
			}
			save_scope_as = other_vassal
		}
		random_vassal = {
			limit = {
				is_available_ai_adult = yes
				culture = root.culture
				NOT = { has_trait = humble }
				NOR = {
					has_relation_friend = scope:other_vassal
					scope:other_vassal = {
						has_friendly_relationship_trigger = { CHARACTER = prev }
					}
				}
			}
			weight = {
				modifier = { # Aggressor is arrogant
					factor = 4
					has_trait = arrogant
				}
				modifier = { # Aggressor is a meanie
					factor = 2
					OR = {
						has_trait = vengeful
						has_trait = wrathful
						has_trait = arbitrary
					}
				}
				modifier = { # Aggressor is not a baron/mayor
					factor = 2
					primary_title.tier > tier_barony
				}
				modifier = { # Aggressor borders the victim
					factor = 2
					any_held_title = {
						title_tier = county
						any_neighboring_county = { holder = scope:other_vassal }
					}
				}
				modifier = { # Aggressor has claim beef with victim
					factor = 2
					any_claim = {
						OR = {
							holder = scope:other_vassal
							de_jure_liege.holder = scope:other_vassal
							de_facto_liege.holder = scope:other_vassal
						}
					}
				}
				modifier = { # Aggressor is a rival of the victim
					factor = 4
					has_relation_rival = scope:other_vassal
				}
				modifier = { # Aggressor doesn't like the victim
					factor = 2
					opinion = {
						target = scope:other_vassal
						value <= 0
					}
				}
				modifier = { # Aggressor is the same rank as the victim
					factor = 2
					primary_title.tier = scope:other_vassal.primary_title.tier
				}
				modifier = { # Aggressor is a powerful vassal
					factor = 2
					is_powerful_vassal = yes
				}
			}
			save_scope_as = aggressor_vassal
			court_event_character_flag_effect = yes
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = { # Demand culture adoption
		name = hold_court.8190.a
		add_dread = miniscule_dread_gain
		scope:aggressor_vassal = {
			culture = {
				change_cultural_acceptance = {
					target = scope:other_vassal.culture
					value = -10
					desc = cultural_intolerance_tt
				}
			}
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 10
			}
		}
		every_vassal = {
			limit = {
				culture != root.culture
			}
			custom = hold_court.8190.a.tt.vassals
			add_opinion = {
				target = root
				modifier = hurt_opinion
				opinion = -10
			}
		}
		if = {
			limit = {
				any_realm_county = { culture = scope:other_vassal.culture }
			}
			every_realm_county = {
				limit = { culture = scope:other_vassal.culture }
				custom = hold_court.8190.a.tt.promote
				add_county_modifier = {
					modifier = hold_court_8190_vassal_modifier
					years = 15
				}
			}
		}
		random_list = {
			40 = {
				modifier = {
					add = -20
					NOT = {
						scope:other_vassal.culture = { has_same_culture_heritage = root.culture }
					}
				}
				modifier = {
					add = -20
					scope:other_vassal = { has_trait = stubborn }
				}
				show_chance = no
				desc = hold_court.8190.a.tt_accept
				send_interface_toast = {
					title = hold_court.8190.a.tt_accept
					left_icon = scope:other_vassal
					save_scope_as = actor
					scope:other_vassal = { save_scope_as = recipient }
					add_prestige = minor_prestige_gain
					new_culture_created_vassal_conversion_effect = {
						CONVERTEE = scope:recipient
						CONVERTER = scope:actor
						CULTURE = scope:actor.culture
					}
				}
			}
			60 = {
				show_chance = no
				desc = hold_court.8190.a.tt_refuse
				send_interface_toast = {
					title = hold_court.8190.a.tt_refuse
					left_icon = scope:other_vassal
					scope:other_vassal = {
						add_opinion = {
							modifier = angry_opinion
							target = root
							opinion = -15
						}
					}
					stress_impact = { zealous = medium_stress_impact_gain }
				}
			}
		}
		stress_impact = {
			just = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
			humble = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
   				ai_compassion = -1
   				ai_boldness = 1
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = just
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = compassionate
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = humble
			}
		}
	}

	option = { # Cultural acceptance
		name = hold_court.8190.b
		duel = {
			skill = diplomacy
			target = scope:aggressor_vassal
			8 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = hold_court.8190.b.tt_success
				send_interface_toast = {
					title = hold_court.8190.b.tt_success
					left_icon = scope:aggressor_vassal
					right_icon = scope:other_vassal
					scope:aggressor_vassal.culture = {
						change_cultural_acceptance = {
							target = scope:other_vassal.culture
							value = 10
							desc = cultural_benevolence_tt
						}
					}
				}
			}
			12 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = hold_court.8190.b.tt_failure
				send_interface_toast = {
					title = hold_court.8190.b.tt_failure
					add_prestige = medium_prestige_loss
				}
			}
		}
		scope:aggressor_vassal = {
			add_opinion = {
				target = root
				modifier = angry_opinion
				opinion = -10
			}
		}
		scope:other_vassal = {
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = 10
			}
		}
		if = {
			limit = {
				any_vassal = {
					culture = scope:other_vassal.culture
					this != scope:other_vassal
				}
			}
			every_vassal = {
				limit = {
					culture = scope:other_vassal.culture
					this != scope:other_vassal
				}
				custom = hold_court.8190.b.tt.vassals
				add_opinion = {
					target = root
					modifier = respect_opinion
					opinion = 5
				}
			}
		}
		stress_impact = {
			arrogant = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
   				ai_compassion = 2
   				ai_boldness = 1
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = arrogant
			}
		}
	}

	option = { # Side with other vassal
		name = hold_court.8190.c
		trigger = {
			NOT = { has_relation_rival = scope:other_vassal }
		}
		scope:aggressor_vassal = {
			add_opinion = {
				target = root
				modifier = angry_opinion
				opinion = -20
			}
		}
		scope:other_vassal = {
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 20
			}
			progress_towards_friend_effect = {
				REASON = friend_respected_foreign_culture
				CHARACTER = root
				OPINION = 0
			}
		}
		stress_impact = {
			arrogant = medium_stress_impact_gain
			shy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
   				ai_compassion = 1
   				ai_boldness = 0.5
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = arrogant
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = shy
			}
		}
	}

	option = { # All cultures are equal
		name = hold_court.8190.d
		change_current_court_grandeur = minor_court_grandeur_gain
		every_vassal = {
			limit = {
				culture != root.culture
			}
			custom = hold_court.8190.a.tt.vassals
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = 10
			}
		}
		scope:aggressor_vassal = {
			add_opinion = {
				target = root
				modifier = angry_opinion
				opinion = -15
			}
		}
		if = {
			limit = {
				any_vassal = {
					culture = root.culture
					has_trait = arrogant
					this != scope:aggressor_vassal
				}
			}
			every_vassal = {
				limit = {
					culture = root.culture
					has_trait = arrogant
					this != scope:aggressor_vassal
				}
				add_opinion = {
					target = root
					modifier = disappointed_opinion
					opinion = -5
				}
			}
		}
		stress_impact = {
			arrogant = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
   				ai_compassion = 2
   				ai_boldness = 0.5
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = arrogant
			}
		}
	}

	after = {
		scope:aggressor_vassal = {
			clear_court_event_participation = yes
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

##################################################
# Servant of God
# by Joe Parkin
# 8200
##################################################

scripted_trigger hold_court_8200_infidel_trigger = {
	is_available_ai_adult = yes
	faith != root.faith
	NOR = {
		AND = { # Eastern
			religion = { is_in_family = rf_eastern }
			root.faith = { has_doctrine = tenet_eastern_syncretism }
		}
		AND = { # Pagan
			faith = { has_doctrine_parameter = unreformed }
			root.faith = { has_doctrine = tenet_unreformed_syncretism }
		}
		AND = { # Christian
			OR = { religion = religion:eastern_orthodox_religion religion = religion:catholic_religion religion = religion:protestant_religion }
			root.faith = { has_doctrine = tenet_christian_syncretism }
		}
		AND = { # Islam
			religion = religion:islam_religion
			root.faith = { has_doctrine = tenet_islamic_syncretism }
		}
		AND = { # Judaism
			religion = religion:judaism_religion
			root.faith = { has_doctrine = tenet_jewish_syncretism }
		}
	}
	NAND = {
		government_has_flag = government_is_theocracy
		primary_title = { is_head_of_faith = yes }
		any_held_title = {
			count = 0
			title_tier < duchy
		}
	}
}

# A vassal wants an infidel vassal to convert
hold_court.8200 = {
	type = court_event
	title = hold_court.8200.t
	desc = {
		desc = hold_court.8200.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:infidel_vassal = { # Victim is a religious head with no other titles
						government_has_flag = government_is_theocracy
						primary_title = { is_head_of_faith = yes }
					}
				}
				desc = hold_court.8200.desc.pope
			}
			desc = hold_court.8200.desc.vassal
		}
		desc = hold_court.8200.desc.body
	}
	theme = court
	lower_right_portrait = scope:infidel_vassal
	court_scene = {
		button_position_character = scope:aggressor_vassal
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:aggressor_vassal = {
				group = petitioners_group
				animation = rage
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

	cooldown = { years = 10 }

	trigger = {
		NOT = {
			faith = { has_doctrine = doctrine_pluralism_pluralistic }
		}
		any_vassal = { # Is there a vassal who is not root faith?
			hold_court_8200_infidel_trigger = yes
			save_temporary_scope_as = other_temp
		}
		any_vassal = { # Is there another vassal of root faith who is not cynical and doesn't like the other one?
			has_court_event_flag = no
			is_available_ai_adult = yes
			faith = root.faith
			NOT = { has_trait = cynical }
			NOR = {
				has_relation_friend = scope:other_temp
				scope:other_temp = {
					has_friendly_relationship_trigger = { CHARACTER = prev }
				}
			}
		}
	}

	weight_multiplier = {
		base = 1

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

	immediate = {
		random_vassal = {
			limit = { hold_court_8200_infidel_trigger = yes }
			weight = {
				modifier = {
					factor = 2
					primary_title.tier > tier_barony
				}
			}
			save_scope_as = infidel_vassal
		}
		random_vassal = {
			limit = {
				is_available_ai_adult = yes
				faith = root.faith
				NOR = {
					has_relation_friend = scope:infidel_vassal
					scope:infidel_vassal = {
						has_friendly_relationship_trigger = { CHARACTER = prev }
					}
				}
			}
			weight = {
				modifier = { # Aggressor is zealous
					factor = 4
					has_trait = zealous
				}
				modifier = { # Aggressor is a meanie
					factor = 2
					OR = {
						has_trait = vengeful
						has_trait = wrathful
						has_trait = arbitrary
					}
				}
				modifier = { # Aggressor is not a baron/mayor
					factor = 2
					primary_title.tier > tier_barony
				}
				modifier = { # Aggressor borders the victim
					factor = 2
					any_held_title = {
						title_tier = county
						any_neighboring_county = { holder = scope:infidel_vassal }
					}
				}
				modifier = { # Aggressor has claim beef with victim
					factor = 2
					any_claim = {
						OR = {
							holder = scope:infidel_vassal
							de_jure_liege.holder = scope:infidel_vassal
							de_facto_liege.holder = scope:infidel_vassal
						}
					}
				}
				modifier = { # Aggressor is a rival of the victim
					factor = 4
					has_relation_rival = scope:infidel_vassal
				}
				modifier = { # Aggressor doesn't like the victim
					factor = 2
					opinion = {
						target = scope:infidel_vassal
						value <= 0
					}
				}
				modifier = { # Aggressor is the same rank as the victim
					factor = 2
					primary_title.tier = scope:infidel_vassal.primary_title.tier
				}
				modifier = { # Aggressor is a powerful vassal
					factor = 2
					is_powerful_vassal = yes
				}
			}
			save_scope_as = aggressor_vassal
			court_event_character_flag_effect = yes
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = { # Demand the vassal's conversion
		name = hold_court.8200.a
		add_dread = miniscule_dread_gain
		scope:aggressor_vassal = {
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 10
			}
		}
		every_vassal = {
			limit = {
				NOR = {
					faith = root.faith
					this = scope:infidel_vassal
				}
			}
			custom = hold_court.8200.a.tt.vassals
			add_opinion = {
				target = root
				modifier = hurt_opinion
				opinion = -10
			}
		}
		if = {
			limit = {
				any_realm_county = { faith = scope:infidel_vassal.faith }
			}
			every_realm_county = {
				limit = { faith = scope:infidel_vassal.faith }
				custom = hold_court.8200.a.tt.convert
				add_county_modifier = {
					modifier = hold_court_8200_vassal_modifier
					years = 15
				}
			}
		}
		random_list = {
			40 = {
				modifier = {
					add = -20
					scope:infidel_vassal.religion != root.religion
				}
				modifier = {
					add = -20
					scope:infidel_vassal = { has_trait = zealous }
				}
				show_chance = no
				desc = hold_court.8200.a.tt_accept
				send_interface_toast = {
					title = hold_court.8200.a.tt_accept
					left_icon = scope:infidel_vassal
					add_piety = medium_piety_gain
					save_scope_as = actor
					scope:infidel_vassal = { save_scope_as = recipient }
					demand_conversion_interaction_effect = yes
				}
			}
			60 = {
				show_chance = no
				desc = hold_court.8200.a.tt_refuse
				send_interface_toast = {
					title = hold_court.8200.a.tt_refuse
					left_icon = scope:infidel_vassal
					if = {
						limit = {
							refusing_conversion_is_crime_trigger = {
								CHARACTER = scope:infidel_vassal
							}
						}
						add_opinion = {
							modifier = illegal_resisted_conversion_opinion
							target = scope:infidel_vassal
						}	
					}
					scope:infidel_vassal = {
						add_opinion = {
							modifier = angry_opinion
							target = root
							opinion = -15
						}
					}
					stress_impact = { zealous = medium_stress_impact_gain }
				}
			}
		}
		stress_impact = {
			cynical = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
			just = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
   				ai_compassion = -2
   				ai_zeal = 2
   				ai_boldness = 2
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = cynical
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = compassionate
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = just
			}
		}
	}

	option = { # Adopt heretic's faith
		name = hold_court.8200.c
		trigger = {
			NOT = { has_trait = zealous }
		}
		if = {
			limit = { religion = scope:infidel_vassal.religion }
			add_piety = medium_piety_loss
		}
		else = { add_piety = major_piety_loss }
		scope:aggressor_vassal = {
			add_opinion = {
				target = root
				modifier = angry_opinion
				opinion = -40
			}
		}
		scope:infidel_vassal = {
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = 10
			}
		}
		every_vassal = {
			limit = {
				faith = scope:infidel_vassal.faith
				this != scope:infidel_vassal
			}
			custom = hold_court.8200.c.tt.vassals
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 5
			}
		}
		set_character_faith_with_conversion = scope:infidel_vassal.faith
		stress_impact = {
			zealous = massive_stress_impact_gain
			cynical = medium_stress_impact_gain
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
   				ai_compassion = 2
   				ai_zeal = -4
   				ai_boldness = 2
			}
			modifier = {	#Weight down for stress.
				add = -60
				has_trait = zealous
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = cynical
			}
		}
	}

	option = { # Side with the heretic
		name = hold_court.8200.d
		trigger = {
			NOT = { has_relation_rival = scope:infidel_vassal }
		}
		scope:aggressor_vassal = {
			add_opinion = {
				target = root
				modifier = angry_opinion
				opinion = -20
			}
		}
		scope:infidel_vassal = {
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 20
			}
			progress_towards_friend_effect = {
				REASON = friend_respected_other_religion
				CHARACTER = root
				OPINION = 0
			}
		}
		stress_impact = {
			zealous = medium_stress_impact_gain
			shy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
   				ai_compassion = 2
   				ai_zeal = -2
   				ai_boldness = 2
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = zealous
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = shy
			}
		}
	}

	option = { # Dismiss zealotry
		name = hold_court.8200.e
		trigger = {
			NOT = { has_trait = zealous }
		}
		change_current_court_grandeur = minor_court_grandeur_gain
		every_vassal = {
			limit = {
				faith != root.faith
			}
			custom = hold_court.8200.a.tt.vassals
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = 10
			}
		}
		scope:aggressor_vassal = {
			add_opinion = {
				target = root
				modifier = angry_opinion
				opinion = -15
			}
		}
		if = {
			limit = {
				any_vassal = {
					faith = root.faith
					has_trait = zealous
					this != scope:aggressor_vassal
				}
			}
			every_vassal = {
				limit = {
					faith = root.faith
					has_trait = zealous
					this != scope:aggressor_vassal
				}
				add_opinion = {
					target = root
					modifier = disappointed_opinion
					opinion = -5
				}
			}
		}
		stress_impact = {
			zealous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
   				ai_compassion = 1
   				ai_zeal = -2
   				ai_boldness = 2
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = zealous
			}
		}
	}

	after = {
		scope:aggressor_vassal = {
			clear_court_event_participation = yes
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

##################################################
# Rightful Lands
# by Joe Parkin
# 8210 - 211
##################################################

scripted_trigger hold_court_8210_claim_trigger = {
	tier = tier_county
	is_landless_type_title = no
	NOT = { this = root.capital_county }
	holder = {
		NOT = { this = $VASSAL$ }
		OR = {
			AND = {
				this = root
				root = {
					any_held_title = {
						count > 1
						tier = tier_county
						is_landless_type_title = no
					}
				}
			}
			is_vassal_of = root
		}
		NOR = {
			has_friendly_relationship_trigger = { CHARACTER = $VASSAL$ }
			is_parent_of = $VASSAL$
			is_spouse_of = $VASSAL$
		}
	}
}

scripted_trigger hold_court_8210_vassal_trigger = {
	has_court_event_flag = no
	is_available_ai_adult = yes
	NOT = { has_trait = content }
	is_at_war = no
	NOT = { is_close_family_of = root }
	save_temporary_scope_as = vassal_temp
	OR = {
		any_de_jure_claim = {
			hold_court_8210_claim_trigger = { VASSAL = scope:vassal_temp }
		}
		any_claim = {
			hold_court_8210_claim_trigger = { VASSAL = scope:vassal_temp }
		}
		any_held_title = {
			title_tier = county
			any_neighboring_county = {
				holder = {
					this = root
					NOR = {
						has_friendly_relationship_trigger = { CHARACTER = scope:vassal_temp }
						is_parent_of = scope:vassal_temp
						is_spouse_of = scope:vassal_temp
					}
				}
			}
		}
	}
}

scripted_effect hold_court_8211_duel_win_effect = {
	if = {
		limit = {
			NOR = {
				this = root
				scope:defender_vassal = root
			}
		}
		add_opinion = {
			target = root
			modifier = respect_opinion
			opinion = 10
		}
	}
}

scripted_effect hold_court_8211_duel_lose_effect = {
	if = {
		limit = {
			this != root
		}
		add_opinion = {
			target = root
			modifier = annoyed_opinion
			opinion = -10
		}
	}
}

# A vassal wants a dejure or claimed county from another vassal
hold_court.8210 = {
	type = court_event
	title = hold_court.8210.t
	desc = {
		desc = hold_court.8210.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:aggressor_vassal = {
						any_de_jure_claim = { this = scope:vassal_claim }
					}
				}
				desc = hold_court.8210.desc.de_jure
			}
			triggered_desc = {
				trigger = {
					scope:aggressor_vassal = { has_strong_claim_on = scope:vassal_claim }
				}
				desc = hold_court.8210.desc.strong
			}
			desc = hold_court.8210.desc.weak
		}
		first_valid = {
			triggered_desc = {
				trigger = { scope:defender_vassal = root }
				desc = hold_court.8210.desc.self
			}
			desc = hold_court.8210.desc.other
		}
	}
	theme = court
	lower_right_portrait = scope:defender_vassal
	court_scene = {
		button_position_character = scope:aggressor_vassal
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:aggressor_vassal = {
				group = petitioners_group
				animation = disapproval
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

	cooldown = { years = 10 }

	trigger = {
		any_vassal = { hold_court_8210_vassal_trigger = yes } # Is there a vassal with a de jure claim on a title held by another vassal?
	}

	weight_multiplier = {
		base = 1

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

	immediate = {
		random_vassal = {
			limit = { hold_court_8210_vassal_trigger = yes }
			weight = {
				modifier = {
					factor = 4
					primary_title.tier > tier_barony
				}
				modifier = { # Aggressor is a meanie
					factor = 2
					OR = {
						has_trait = vengeful
						has_trait = wrathful
					}
				}
				modifier = { # Aggressor is a coward
					factor = 2
					has_trait = craven
				}
				modifier = { # Aggressor is a powerful vassal
					factor = 2
					is_powerful_vassal = yes
				}
				modifier = {
					factor = 10
					any_de_jure_claim = {
						hold_court_8210_claim_trigger = { VASSAL = scope:vassal_temp }
					}
				}
				modifier = {
					factor = 5
					any_claim = {
						hold_court_8210_claim_trigger = { VASSAL = scope:vassal_temp }
					}
				}
			}
			save_scope_as = aggressor_vassal
			court_event_character_flag_effect = yes
			if = {
				limit = {
					any_de_jure_claim = {
						hold_court_8210_claim_trigger = { VASSAL = scope:aggressor_vassal }
					}
				}
				random_de_jure_claim = {
					limit = {
						hold_court_8210_claim_trigger = { VASSAL = scope:aggressor_vassal }
					}
					weight = {
						modifier = {
							factor = 4
							any_neighboring_county = { holder = scope:aggressor_vassal }
						}
						modifier = {
							factor = 2
							de_jure_liege.tier = tier_duchy
						}
						modifier = {
							factor = 2
							holder.max_military_strength > scope:aggressor_vassal.max_military_strength
						}
						modifier = { # More relevant if war declaration is limited
							factor = 2
							root = {
								OR = { 
									has_realm_law = crown_authority_2
									has_realm_law = crown_authority_3
								}
							}
						}
						modifier = {
							factor = 2
							scope:aggressor_vassal = { has_strong_claim_on = prev }
						}
						modifier = {
							factor = 4
							holder = { has_relation_rival = scope:aggressor_vassal }
						}
						modifier = {
							factor = 4
							holder = {
								reverse_opinion = {
									target = scope:aggressor_vassal
									value <= 0
								}
							}
						}
					}
					save_scope_as = vassal_claim
					holder = { save_scope_as = defender_vassal }
				}
			}
			else_if = {
				limit = {
					any_claim = {
						hold_court_8210_claim_trigger = { VASSAL = scope:aggressor_vassal }
					}
				}
				random_claim = {
					limit = {
						hold_court_8210_claim_trigger = { VASSAL = scope:aggressor_vassal }
					}
					weight = {
						modifier = {
							factor = 4
							any_neighboring_county = { holder = scope:aggressor_vassal }
						}
						modifier = {
							factor = 2
							de_jure_liege.tier = tier_duchy
						}
						modifier = {
							factor = 2
							holder.max_military_strength > scope:aggressor_vassal.max_military_strength
						}
						modifier = { # More relevant if war declaration is limited
							factor = 2
							root = {
								OR = { 
									has_realm_law = crown_authority_2
									has_realm_law = crown_authority_3
								}
							}
						}
						modifier = {
							factor = 2
							scope:aggressor_vassal = { has_strong_claim_on = prev }
						}
					}
					save_scope_as = vassal_claim
					holder = { save_scope_as = defender_vassal }
				}
			}
			else = {
				random_held_title = {
					title_tier = county
					limit = {
						any_neighboring_county = {
							NOT = { this = root.capital_county }
							holder = {
								this = root
								NOR = {
									has_friendly_relationship_trigger = { CHARACTER = scope:aggressor_vassal }
									is_parent_of = scope:aggressor_vassal
									is_spouse_of = scope:aggressor_vassal
								}
							}
						}
					}
					random_neighboring_county = {
						limit = {
							NOT = { this = root.capital_county }
							holder = {
								this = root
								NOR = {
									has_friendly_relationship_trigger = { CHARACTER = scope:aggressor_vassal }
									is_parent_of = scope:aggressor_vassal
									is_spouse_of = scope:aggressor_vassal
								}
							}
						}
						save_scope_as = vassal_claim
						holder = { save_scope_as = defender_vassal }
					}
				}
			}
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = { # Support claimant
		name = hold_court.8210.a
		trigger = {
			trigger_if = {
				limit = {
					scope:aggressor_vassal = {
						NOR = {
							any_de_jure_claim = { this = scope:vassal_claim }
							has_claim_on = scope:vassal_claim
						}
					}
				}
				scope:defender_vassal != root
			}
		}
		if = {
			limit = { scope:defender_vassal = root }
		}
		else_if = {
			limit = {
				scope:aggressor_vassal = {
					NOR = {
						any_de_jure_claim = { this = scope:vassal_claim }
						has_strong_claim_on = scope:vassal_claim
					}
				}
			}
			add_tyranny = major_tyranny_gain
		}
		else = { add_tyranny = minor_tyranny_gain }
		create_title_and_vassal_change = {
			type = granted
			save_scope_as = change
			add_claim_on_loss = no
		}
		scope:vassal_claim = {
			change_title_holder = {
				holder = scope:aggressor_vassal
				change = scope:change
			}
		}
		resolve_title_and_vassal_change = scope:change
		scope:aggressor_vassal = {
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 20
			}
		}
		if = {
			limit = { scope:defender_vassal = root }
			stress_impact = {
				greedy = medium_stress_impact_gain
			}
		}
		else = {
			scope:defender_vassal = {
				progress_towards_rival_effect = {
					CHARACTER = scope:aggressor_vassal
					REASON = rival_claimant_fight
					OPINION = 0
				}
				add_opinion = {
					target = root
					modifier = angry_opinion
					opinion = -30
				}
			}
			stress_impact = {
				just = medium_stress_impact_gain
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
   				ai_honor = -2
   				ai_boldness = 2
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = just
			}
			modifier = {	#Weight up for relatives.
				add = 2
				scope:aggressor_vassal = { is_close_family_of = root }
				NOT = {
					scope:defender_vassal = { is_close_family_of = root }
				}
			}
		}
	}

	option = { # Start vassal war	
		name = hold_court.8210.b
		trigger = {
			is_valid_for_east_asian_events_trigger = no
			NOT = {
				faith = { has_doctrine = tenet_pacifism }
			}
			NOR = { 
				has_realm_law = crown_authority_2
				has_realm_law = crown_authority_3
			}
			scope:defender_vassal != root
		}
		scope:aggressor_vassal = {
			add_opinion = {
				target = root
				modifier = angry_opinion
				opinion = -10
			}
			add_character_flag = temp_no_claim_war_cost
			start_war = {
				cb = claim_cb
				target = scope:vassal_claim.holder
				claimant = scope:aggressor_vassal
				target_title = scope:vassal_claim
			}
			remove_character_flag = temp_no_claim_war_cost
		}
		scope:defender_vassal = {
			add_opinion = {
				target = root
				modifier = annoyed_opinion
				opinion = -10
			}
		}
		stress_impact = {
			compassionate = medium_stress_impact_gain
			craven = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
   				ai_honor = 1
   				ai_boldness = 2
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = compassionate
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = craven
			}
			modifier = {
				add = 30
				culture = { has_cultural_pillar = ethos_bellicose }
			}
		}
	}

	option = { # Start vassal duel	
		name = {
			trigger = {
				scope:defender_vassal != root
			}
			text = hold_court.8210.f.other
		}
		name = {
			trigger = { always = yes }
			text = hold_court.8210.f.self
		}
		trigger = {
			is_valid_for_east_asian_events_trigger = no
			scope:defender_vassal = { is_adult = yes }
		}
		custom_tooltip = hold_court.8210.duel_tt
		show_as_tooltip = {
			random_list = {
				10 = {
					show_chance = no
					desc = hold_court.8210.b.tt_aggressor
					create_title_and_vassal_change = {
						type = granted
						save_scope_as = change
						add_claim_on_loss = no
					}
					scope:vassal_claim = {
						change_title_holder = {
							holder = scope:aggressor_vassal
							change = scope:change
						}
					}
					resolve_title_and_vassal_change = scope:change
					scope:aggressor_vassal = { hold_court_8211_duel_win_effect = yes }
					scope:defender_vassal = { hold_court_8211_duel_lose_effect = yes }
				}
				10 = {
					show_chance = no
					desc = hold_court.8210.b.tt_defender
					scope:defender_vassal = { hold_court_8211_duel_win_effect = yes }
					scope:aggressor_vassal = { hold_court_8211_duel_lose_effect = yes }
				}
			}
		}
		configure_start_single_combat_effect = {
			SC_INITIATOR = scope:aggressor_vassal
			SC_ATTACKER = scope:aggressor_vassal
			SC_DEFENDER = scope:defender_vassal
			FATALITY = no
			FIXED = no
			LOCALE = terrain_scope
			OUTPUT_EVENT = hold_court.8211
			INVALIDATION_EVENT = fp1_tbc.0102
		}
		stress_impact = {
			lifestyle_blademaster = medium_stress_impact_loss
			viking = medium_stress_impact_loss
			varangian = medium_stress_impact_loss
			berserker = medium_stress_impact_loss
			brave = medium_stress_impact_loss
		}
		stress_impact = {
			compassionate = medium_stress_impact_gain
			craven = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
   				ai_honor = 1
   				ai_boldness = 2
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = compassionate
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = craven
			}
			modifier = {
				add = 30
				OR = {
					culture = { has_cultural_tradition = tradition_martial_admiration }
					culture = { has_cultural_tradition = tradition_chivalry }
					culture = { has_cultural_tradition = tradition_futuwaa }
					has_trait = gallant
					has_perk = stalwart_leader_perk
				}
			}
		}
	}

	option = { # Support defender
		name = {
			trigger = {
				NOR = {
					scope:aggressor_vassal = {
						any_de_jure_claim = { this = scope:vassal_claim }
					}
					scope:aggressor_vassal = { has_claim_on = scope:vassal_claim }
				}
			}
			text = hold_court.8210.c.none
		}
		name = {
			trigger = { scope:defender_vassal = root }
			text = hold_court.8210.c.self
		}
		name = {
			trigger = {
				scope:defender_vassal != root
			}
			text = hold_court.8210.c.other
		}
		scope:aggressor_vassal = {
			if = {
				limit = {
					NOT = {
						any_de_jure_claim = { this = scope:vassal_claim }
					}
				}
				add_opinion = {
					target = root
					modifier = angry_opinion
					opinion = -30
				}
				if = {
					limit = { has_strong_claim_on = scope:vassal_claim }
					make_claim_weak = scope:vassal_claim
				}
				else = { remove_claim = scope:vassal_claim }
			}
			else = {
				add_opinion = {
					target = root
					modifier = angry_opinion
					opinion = -15
				}
			}
		}
		if = {
			limit = {
				scope:defender_vassal != root
			}
			scope:defender_vassal = {
				add_opinion = {
					target = root
					modifier = respect_opinion
					opinion = 15
				}
				progress_towards_friend_effect = {
					REASON = friend_took_side_in_dispute
					CHARACTER = root
					OPINION = 0
				}
			}
		}
		stress_impact = {
			arbitrary = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
   				ai_boldness = 1
   				ai_honor = 2
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = arbitrary
			}
		}
	}

	option = { # Change liege
		name = hold_court.8210.e
		trigger = {
			scope:defender_vassal != root
			scope:aggressor_vassal = {
				any_de_jure_claim = { this = scope:vassal_claim }
			}
			scope:defender_vassal.primary_title.tier < scope:aggressor_vassal.primary_title.tier
		}
		create_title_and_vassal_change = {
			type = created
			save_scope_as = change
			add_claim_on_loss = no
		}
		scope:defender_vassal = {
			change_liege = {
				liege = scope:aggressor_vassal
				change = scope:change
			}
		}
		resolve_title_and_vassal_change = scope:change
		scope:aggressor_vassal = {
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 10
			}
		}
		scope:defender_vassal = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -5
			}
		}
		stress_impact = {
			arbitrary = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
   				ai_boldness = -1
   				ai_honor = 2
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = arbitrary
			}
		}
	}

	option = { # Not my problem
		name = hold_court.8210.d
		trigger = {
			scope:defender_vassal != root
		}
		add_prestige = minor_prestige_gain
		scope:aggressor_vassal = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -10
			}
		}
		scope:defender_vassal = {
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = 5
			}
		}
		stress_impact = {
			arrogant = medium_stress_impact_gain
			diligent = medium_stress_impact_gain
			just = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
   				ai_boldness = -2
   				ai_honor = 1
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = arrogant
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = diligent
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = just
			}
		}
	}

	after = {
		scope:aggressor_vassal = {
			clear_court_event_participation = yes
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

hold_court.8211 = {
	hidden = yes

	immediate = {
		scope:aggressor_vassal.liege = {
			send_interface_toast = {
				title = hold_court.8031.t
				left_icon = scope:sc_victor
				right_icon = scope:sc_loser
				scope:sc_victor = {
					if = {
						limit = {
							this != scope:vassal_claim.holder
						}
						create_title_and_vassal_change = {
							type = granted
							save_scope_as = change
							add_claim_on_loss = no
						}
						scope:vassal_claim = {
							change_title_holder = {
								holder = scope:sc_victor
								change = scope:change
							}
						}
						resolve_title_and_vassal_change = scope:change
					}
					if = {
						limit = {
							liege != root
						}
						hold_court_8211_duel_win_effect = yes
					}
				}
				scope:sc_loser = {
					if = {
						limit = {
							NOR = {						
								liege = root
								this = root
							}
						}
						hold_court_8211_duel_lose_effect = yes
					}
				}
			}
		}
	}
}

##################################################
# The King's Peace
# by Joe Parkin
# 8260
##################################################

scripted_trigger hold_court_8260_faction_trigger = {
	exists = yes
	OR = {
		faction_is_type = liberty_faction
		faction_is_type = claimant_faction
	}
	OR = {
		faction_power >= faction_power_threshold
		faction_is_at_war = yes
	}
	trigger_if = {
		limit = { exists = special_character }
		special_character != root
	}
}

hold_court.8260 = {
	type = court_event
	title = hold_court.8260.t
	desc = {
		desc = hold_court.8260.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:vassal_faction.special_character
					scope:vassal_faction.faction_leader = scope:vassal_faction.special_character
					scope:vassal_faction = { faction_is_type = claimant_faction }
				}
				desc = hold_court.8220.desc.claimant_self
			}
			triggered_desc = {
				trigger = {
					scope:vassal_faction = { faction_is_type = claimant_faction }
				}
				desc = hold_court.8220.desc.claimant
			}
			triggered_desc = {
				trigger = { always = yes }
				desc = hold_court.8220.desc.liberty
			}
		}
		desc = hold_court.8260.desc.body
	}
	theme = court
	override_background = { reference = throne_room }
	cooldown = { years = 10 }
	lower_center_portrait = {
		character = scope:vassal_faction.special_character
		trigger = {
			scope:vassal_faction = {
				exists = special_character
				special_character != faction_leader
			}
		}
	}
	lower_right_portrait = scope:vassal_faction.faction_leader

	court_scene = {
		button_position_character = scope:vassal_faction.faction_target
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:vassal_faction_target = {
				group = petitioners_group
				animation = anger
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

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

	trigger = {
		any_vassal = {
			has_court_event_flag = no
			is_available_ai_adult = yes
			any_targeting_faction = { target_of_powerful_faction_trigger = yes }
		}
	}

	immediate = {
		random_vassal = {
			limit = {
				has_court_event_flag = no
				is_available_ai_adult = yes
				any_targeting_faction = { target_of_powerful_faction_trigger = yes }
			}
			weight = {
				base = 1
				modifier = {
					factor = 4
					any_targeting_faction = { faction_can_press_demands = yes }
				}
				modifier = {
					factor = 4
					any_targeting_faction = {
						faction_type = claimant_faction
						special_title ?= prev.primary_title
					}
				}
				modifier = {
					factor = 8
					is_close_family_of = root
				}
				modifier = {
					factor = 2
					this = root.primary_heir
				}
				modifier = {
					factor = 0.5
					primary_title.tier < tier_duchy
				}
			}
			save_scope_as = vassal_faction_target
			court_event_character_flag_effect = yes
			ordered_targeting_faction = {
				limit = {
					target_of_powerful_faction_trigger = yes
					faction_can_press_demands = yes
				}
				alternative_limit = {
					target_of_powerful_faction_trigger = yes
					faction_is_at_war = yes
				}
				alternative_limit = { target_of_powerful_faction_trigger = yes }
				order_by = faction_discontent
				save_scope_as = vassal_faction
				faction_leader = { save_scope_as = vassal_faction_leader } # For loc
				if = {
					limit = { exists = special_character }
					special_character = { save_scope_as = vassal_claimant }
				}
			}
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = { # Break up the faction/force surrender
		name = {
			trigger = {
				scope:vassal_faction = { faction_is_at_war = yes }
			}
			text = hold_court.8260.a.war
		}
		name = {
			trigger = { always = yes }
			text = hold_court.8260.a.peace
		}
		scope:vassal_faction = {
			faction_target = {
				add_opinion = {
					target = root
					modifier = grateful_opinion
					opinion = 10
				}
			}
			if = {
				limit = {
				 	exists = special_character
				 	NOT = {
				 		any_faction_member = { this = scope:vassal_faction.special_character }
				 	}
				}
				special_character = {
					add_opinion = {
						target = root
						modifier = angry_opinion
						opinion = -10
					}
				}
			}
			if = {
				limit = { faction_is_at_war = no }
				every_faction_member = {
					custom = hold_court_8260_faction_member_tt
					add_faction_cooldown_effect = { YEARS = faction_war_white_peace_cooldown }
					add_opinion = {
						target = root
						modifier = angry_opinion
						opinion = -10
					}
				}
				destroy_faction = yes
			}
			else = {
				every_faction_member = {
					custom = hold_court_8260_faction_member_tt
					add_faction_cooldown_effect = { YEARS = faction_war_defeat_cooldown }
					add_opinion = {
						target = root
						modifier = angry_opinion
						opinion = -25
					}
				}
				faction_war = { end_war = defender }
			}
		}
		stress_impact = {
			arbitrary = medium_stress_impact_gain
			lazy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
   				ai_boldness = 2
   				ai_energy = 2
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = arbitrary
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = lazy
			}
			modifier = {	#Weight up for family
				add = 25
				scope:vassal_faction.faction_target = { is_close_family_of = root }
			}
			modifier = {	#Weight up for relatives
				add = 25
				scope:vassal_faction.faction_target = { is_close_or_extended_family_of = root }
			}
		}
	}

	option = { # Imprison faction leader
		name = hold_court.8260.b
		add_dread = minor_dread_gain
		scope:vassal_faction.faction_target = {
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 20
			}
		}
		imprison_character_effect = {
			TARGET = scope:vassal_faction.faction_leader
			IMPRISONER = root
		}
		scope:vassal_faction = {
			if = {
				limit = {
				 	exists = special_character
				 	faction_leader != special_character
				}
				special_character = {
					add_opinion = {
						target = root
						modifier = angry_opinion
						opinion = -20
					}
				}
			}
			every_faction_member = {
				limit = { is_a_faction_leader = no }
				custom = hold_court_8260_faction_member_tt
				add_faction_cooldown_effect = { YEARS = faction_war_defeat_cooldown }
				add_opinion = {
					target = root
					modifier = angry_opinion
					opinion = -20
				}
			}
			scope:vassal_faction = {
				if = {
					limit = { faction_is_at_war = no }
					destroy_faction = yes
				}
				else = {
					faction_war = { end_war = defender }
				}
			}
		}
		stress_impact = {
			just = medium_stress_impact_gain
			forgiving = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
   				ai_honor = -1
   				ai_compassion = -2
   				ai_boldness = 1
   				ai_vengefulness = 2
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = just
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = forgiving
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = compassionate
			}
		}
	}

	option = { # End war white peace
		name = hold_court.8260.c
		trigger = {
			scope:vassal_faction = { faction_is_at_war = yes }
		}
		scope:vassal_faction = {
			scope:vassal_faction.faction_target = {
				add_opinion = {
					target = root
					modifier = grateful_opinion
					opinion = 5
				}
			}
			if = {
				limit = {
				 	exists = special_character
				 	faction_leader != special_character
				}
				special_character = {
					add_opinion = {
						target = root
						modifier = annoyed_opinion
						opinion = -5
					}
				}
			}
			every_faction_member = {
				limit = { is_a_faction_leader = no }
				custom = hold_court_8260_faction_member_tt
				add_opinion = {
					target = root
					modifier = annoyed_opinion
					opinion = -5
				}
			}
			faction_war = { end_war = white_peace }
		}
		stress_impact = {
			arbitrary = medium_stress_impact_gain
			wrathful = medium_stress_impact_gain
			vengeful = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
   				ai_honor = 2
   				ai_compassion = 1
   				ai_boldness = 1
   				ai_vengefulness = -1
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = arbitrary
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = wrathful
			}
		}
	}

	option = { # Make vassal surrender
		name = hold_court.8260.d
		add_tyranny = minor_tyranny_gain
		scope:vassal_faction = {
			faction_target = {
				add_opinion = {
					target = root
					modifier = angry_opinion
					opinion = -30
				}
			}
			faction_leader = {
				add_opinion = {
					target = root
					modifier = grateful_opinion
					opinion = 20
				}
			}
			if = {
				limit = {
				 	exists = special_character
				 	faction_leader != special_character
				}
				special_character = {
					add_opinion = {
						target = root
						modifier = grateful_opinion
						opinion = 20
					}
				}
			}
			every_faction_member = {
				limit = { is_a_faction_leader = no }
				custom = hold_court_8260_faction_member_tt
				add_opinion = {
					target = root
					modifier = grateful_opinion
					opinion = 10
				}
			}
			if = {
				limit = { faction_is_at_war = no }
				if = {
					limit = { faction_is_type = claimant_faction }
					create_title_and_vassal_change = {
						type = granted
						save_scope_as = change
						add_claim_on_loss = yes
					}
					special_title = {
						change_title_holder_include_vassals = {
							holder = scope:vassal_faction.special_character
							change = scope:change
						}
					}
					resolve_title_and_vassal_change = scope:change
				}
				else = {
					faction_target = { decrease_crown_authority_effect = yes }
				}
			}
			else = {
				faction_war = { end_war = attacker }
			}
			hidden_effect = {
				if = {
					limit = {exists = scope:vassal_faction }
					destroy_faction = yes
				}
			}
		}
		stress_impact = {
			paranoid = medium_stress_impact_gain
			trusting = medium_stress_impact_gain
			vengeful = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
   				ai_honor = -2
   				ai_compassion = -1
   				ai_boldness = 1
   				ai_vengefulness = 1
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = just
			}
			modifier = {	#Weight down for family
				add = -25
				scope:vassal_faction.faction_target = { is_close_family_of = root }
			}
			modifier = {	#Weight down for relatives
				add = -25
				scope:vassal_faction.faction_target = { is_close_or_extended_family_of = root }
			}
		}
	}

	option = { # Refuse
		name = hold_court.8260.e
		scope:vassal_faction = {
			faction_target = {
				add_opinion = {
					target = root
					modifier = disappointed_opinion
					opinion = -10
				}
			}
			every_faction_member = {
				custom = hold_court_8260_faction_member_tt
				add_opinion = {
					target = root
					modifier = disappointed_opinion
					opinion = -5
				}
			}
		}
		stress_impact = {
			humble = medium_stress_impact_gain
			diligent = medium_stress_impact_gain
			just = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
   				ai_honor = 1
   				ai_compassion = 1
   				ai_boldness = -1
   				ai_vengefulness = -1
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = humble
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = diligent
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = just
			}
		}
	}

	after = {
		scope:vassal_faction_target = {
			clear_court_event_participation = yes
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

##################################################
# Oath of Fealty
# by Joe Parkin
# 8270
##################################################

scripted_trigger hold_court_8270_neighbor_trigger = {
	has_court_event_flag = no
	is_available_ai_adult = yes
	top_liege = this
	primary_title.tier < root.primary_title.tier
	primary_title.tier <= tier_duchy
	NOT = { has_relation_rival = root }
	opinion = {
		target = root
		value >= -25
	}
	NOT = {
		faith = {
			faith_hostility_level = {
				target = root.faith
				value >= faith_hostile_level
			}
		}
	}
	any_neighboring_top_liege_realm_owner = {
		count >= 2
		primary_title.tier >= prev.primary_title.tier
		NOT = { is_allied_to = prev }
		max_military_strength > prev.max_military_strength
	}
	calc_true_if = {
		amount >= 2
		primary_title = { # is a de jure vassal
			any_this_title_or_de_jure_above = {
				this != prev
				holder = root
			}
		}
		OR = { # cultural acceptance is good
			culture = root.culture
			culture = {
				cultural_acceptance = { target = root.culture value >= 50 }
			}
		}
		primary_title.tier = tier_county
	}
}

hold_court.8270 = {
	type = court_event
	title = hold_court.8270.t
	desc = hold_court.8270.desc
	theme = court
	override_background = { reference = throne_room }
	cooldown = { years = 15 }

	court_scene = {
		button_position_character = scope:neighbor
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:neighbor = {
				group = petitioners_group
				animation = admiration
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

	trigger = {
		any_neighboring_top_liege_realm_owner = { hold_court_8270_neighbor_trigger = yes }
	}

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

	immediate = {
		random_neighboring_top_liege_realm_owner = {
			limit = { hold_court_8270_neighbor_trigger = yes }
			weight = {
				base = 1
				modifier = {
					factor = 4
					is_close_or_extended_family_of = root
				}
				modifier = {
					factor = 10
					primary_title.tier = tier_county
				}
				modifier = {
					factor = 4
					faith = root.faith
				}
				modifier = {
					factor = 2
					religion = root.religion
				}
				modifier = {
					factor = 2
					culture = root.culture
				}
				modifier = {
					factor = 4
					opinion = {
						target = root
						value >= 50
					}
				}
				modifier = {
					factor = 4
					any_neighboring_top_liege_realm_owner = {
						this != root
						primary_title.tier >= tier_kingdom
						OR = {
							AND = {
								prev.faith = root.faith
								faith != prev.faith
							}
							AND = {
								prev.religion = root.religion
								religion != prev.religion
							}
							AND = {
								prev.culture = root.culture
								culture != prev.culture
							}
						}						
					}
				}
			}
			save_scope_as = neighbor
			court_event_character_flag_effect = yes
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = { # Accept
		name =  hold_court.8270.a
		create_title_and_vassal_change = {
			type = swear_fealty
			save_scope_as = change
			add_claim_on_loss = no
		}
		scope:neighbor = {
			change_liege = {
				liege = root
				change = scope:change
			}
		}
		resolve_title_and_vassal_change = scope:change
		scope:neighbor = {
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 10
			}
			# Feudal vassals get contracts.
			if = {
				limit = { government_has_flag = government_is_feudal }
				hidden_effect = {
					if = {
						limit = { top_liege != this } # To avoid errors during tooltip generation (prior to the contract being generated)
						vassal_contract_set_obligation_level = { type = feudal_government_taxes level = 1 }
						vassal_contract_set_obligation_level = { type = feudal_government_levies level = 1 }
					}			
				}
				custom_tooltip = low_obligations_taxes
				custom_tooltip = low_obligations_levies
			}
		}
		stress_impact = {
			greedy = medium_stress_impact_gain
			paranoid = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 2
   				ai_greed = -2
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = greedy
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = paranoid
			}
		}
	}

	option = { # Demand better deal
		name = hold_court.8270.b
		random_list = {
			2 = {
				show_chance = no
				desc = hold_court.8270.b.accept
				modifier = {
					factor = 2
					scope:neighbor = { has_trait = craven }
				}
				modifier = {
					factor = 2
					scope:neighbor = { has_trait = fickle }
				}
				modifier = {
					factor = 2
					scope:neighbor = { has_trait = content }
				}
				modifier = {
					factor = 2
					scope:neighbor = { has_trait = humble }
				}
				modifier = {
					factor = 2
					scope:neighbor = { has_trait = wrathful }
				}
				modifier = {
					factor = 2
					scope:neighbor = { has_trait = vengeful }
				}
				send_interface_toast = {
					title = hold_court.8270.b.accept
					left_icon = scope:neighbor
					create_title_and_vassal_change = {
						type = swear_fealty
						save_scope_as = change
						add_claim_on_loss = no
					}
					scope:neighbor = {
						change_liege = {
							liege = root
							change = scope:change
						}
					}
					resolve_title_and_vassal_change = scope:change
					custom_tooltip = normal_obligations_taxes
					custom_tooltip = normal_obligations_levies
				}
			}
			4 = {
				show_chance = no
				desc = hold_court.8270.b.refuse
				modifier = {
					factor = 2
					scope:neighbor = { has_trait = brave }
				}
				modifier = {
					factor = 2
					scope:neighbor = { has_trait = stubborn }
				}
				modifier = {
					factor = 2
					scope:neighbor = { has_trait = ambitious }
				}
				modifier = {
					factor = 2
					scope:neighbor = { has_trait = arrogant }
				}
				modifier = {
					factor = 2
					scope:neighbor = { has_trait = patient }
				}
				modifier = {
					factor = 2
					scope:neighbor = { has_trait = forgiving }
				}
				change_current_court_grandeur = medium_court_grandeur_loss
				send_interface_toast = {
					title = hold_court.8270.b.refuse
					left_icon = scope:neighbor
					scope:neighbor = {
						add_opinion = {
							target = root
							modifier = insulted_opinion
							opinion = -20
						}
					}
				}
			}
		}
		stress_impact = {
			generous = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
   				ai_boldness = 2
   				ai_greed = 2
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = generous
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = compassionate
			}
		}
	}

	option = { # Refuse
		name = hold_court.8270.d
		change_current_court_grandeur = minor_court_grandeur_gain
		scope:neighbor = {
			add_opinion = {
				target = root
				modifier = annoyed_opinion
				opinion = -10
			}
		}
		stress_impact = {
			honest = medium_stress_impact_gain
			trusting = medium_stress_impact_gain
			fickle = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
   				ai_boldness = 2
   				ai_rationality = -2
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = honest
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = trusting
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = fickle
			}
		}
	}

	after = {
		scope:neighbor = {
			clear_court_event_participation = yes
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

##################################################
# Nomadic Neighbors
# by Joe Parkin
# 8280
##################################################

scripted_trigger nomadic_cultural_traditions_trigger = {
	culture = {
		OR = {
			has_cultural_tradition = tradition_horse_lords
			has_cultural_tradition = tradition_pastoralists
		}
	}
}

scripted_trigger hold_court_8280_nomad_county_trigger = {
	nomadic_cultural_traditions_trigger = yes
	holder = {
		government_has_flag = government_is_tribal
		this != root
		nomadic_cultural_traditions_trigger = yes
		trigger_if = {
			limit = { top_liege = root }
			is_available_ai_adult = yes
		}
	}
}

scripted_trigger hold_court_8280_feudal_county_trigger = {
	nomadic_cultural_traditions_trigger = no
	holder = {
		has_court_event_flag = no
		is_available_ai_adult = yes
		nomadic_cultural_traditions_trigger = no
		this != root
		OR = {
			government_has_flag = government_is_feudal
			government_has_flag = government_is_clan
		}
	}
	any_neighboring_county = { hold_court_8280_nomad_county_trigger = yes }
}

hold_court.8280 = {
	type = court_event
	title = hold_court.8280.t
	desc = {
		first_valid = { #
			triggered_desc = {
				trigger = {
					scope:nomad.top_liege != root
				}
				desc = hold_court.8280.desc.foreign
			}
			triggered_desc = {
				trigger = { always = yes }
				desc = hold_court.8280.desc.local
			}
		}
	}
	theme = court
	override_background = { reference = throne_room }
	cooldown = { years = 15 }
	lower_right_portrait = {
		character = scope:nomad.top_liege
		trigger = {
			scope:nomad.top_liege != root
		}
	}

	court_scene = {
		button_position_character = scope:feudal_vassal
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:feudal_vassal = {
				group = petitioners_group
				animation = worry
			}
			scope:nomad_same_liege = {
				group = petitioners_group
				animation = dismissal
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}

	trigger = {
		nomadic_cultural_traditions_trigger = no
		any_realm_county = { hold_court_8280_feudal_county_trigger = yes }
	}

	weight_multiplier = {
		base = 1

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

	immediate = {
		random_realm_county = {
			limit = {
				holder = { is_vassal_of = root }
				hold_court_8280_feudal_county_trigger = yes
			}
			alternative_limit = { hold_court_8280_feudal_county_trigger = yes }
			holder = {
				save_scope_as = feudal_vassal
				court_event_character_flag_effect = yes
			}
			save_scope_as = feudal_county
			ordered_neighboring_county = {
				limit = {
					holder.top_liege = {
						this != root
						government_has_flag = government_is_tribal
						culture = { has_cultural_tradition = tradition_horse_lords }
					}
					hold_court_8280_nomad_county_trigger = yes
				}
				alternative_limit = {
					holder.top_liege != root
					hold_court_8280_nomad_county_trigger = yes
				}
				alternative_limit = { hold_court_8280_nomad_county_trigger = yes }
				order_by = {
					value = 0
					subtract = development_level
				}
				save_scope_as = nomad_county
				culture = { save_scope_as = nomad_culture }
				holder = { save_scope_as = nomad }
				# Set up portrait groups.
				scope:nomad = {
					if = {
						limit = { top_liege = root }
						save_scope_as = nomad_same_liege
						court_event_character_flag_effect = yes
					}
				}
			}
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = { # Kick nomads out
		trigger = {
			trigger_if = {
				limit = {
					is_ai = yes
				}
				short_term_treasury_or_gold >= minor_treasury_or_gold_value
			}
		}
		name = {
			trigger = { scope:nomad.top_liege = root }
			text = hold_court.8280.a.local
		}
		name = {
			trigger = { always = yes }
			text = hold_court.8280.a.foreign
		}
		add_prestige = medium_prestige_gain
		remove_treasury_or_gold = tiny_treasury_or_gold_value
		scope:feudal_vassal = {
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 10
			}
		}
		scope:nomad = {
			if = {
				limit = {
					top_liege != root
				}
				top_liege = {
					add_opinion = {
						target = root
						modifier = angry_opinion
						opinion = -10
					}
				}
			}
			else = {
				add_opinion = {
					target = root
					modifier = angry_opinion
					opinion = -10
				}
			}
			culture = {
				if = {
					limit = {
						this != root.culture
					}
					change_cultural_acceptance = {
						target = root.culture
						value = -10
						desc = cultural_intolerance_tt
					}
				}
			}
		}
		if = {
			limit = {
				scope:feudal_vassal.culture != root.culture
			}

			scope:feudal_vassal.culture = {
				if = {
					limit = {
						this != scope:nomad_culture
					}
					change_cultural_acceptance = {
						target = scope:nomad_culture
						value = -10
						desc = cultural_intolerance_tt
					}
				}
			}
		}
		stress_impact = {
			compassionate = medium_stress_impact_gain
			generous = 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 = compassionate
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = generous
			}
		}
	}

	option = { # Recruit them
		name = hold_court.8280.b
		trigger = {
			trigger_if = {
				limit = {
					is_ai = yes
				}
				short_term_treasury_or_gold >= massive_treasury_or_gold_value
			}
		}
		remove_treasury_or_gold = major_treasury_or_gold_value
		culture = {
			if = {
				limit = {
					this != scope:nomad_culture
				}
				change_cultural_acceptance = {
					target = scope:nomad.culture
					value = 10
					desc = cultural_intolerance_tt
				}
			}
		}
		scope:feudal_vassal = {
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 10
			}
		}
		scope:nomad = {
			if = {
				limit = {
					top_liege != root
				}
				top_liege = {
					add_opinion = {
						target = root
						modifier = respect_opinion
						opinion = 10
					}
				}
			}
			else = {
				add_opinion = {
					target = root
					modifier = respect_opinion
					opinion = 10
				}
			}
		}
		add_character_modifier = {
			modifier = hold_court_8280_nomadic_guard
			years = 5
		}
		if = {
			limit = {
				culture != scope:nomad_culture
			}
			stress_impact = {
				paranoid = medium_stress_impact_gain
				arrogant = medium_stress_impact_gain
			}
		}
		stress_impact = {
			greedy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
   				ai_greed = -2
   				ai_energy = 2
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = greedy
			}
			modifier = {	#Weight down for stress.
				add = -15
				culture != scope:nomad_culture
				has_trait = paranoid
			}
			modifier = {	#Weight down for stress.
				add = -15
				culture != scope:nomad_culture
				has_trait = arrogant
			}
		}
	}

	option = { # Dismiss
		name = hold_court.8280.c
		scope:feudal_vassal = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -10
			}
		}
		scope:nomad = {
			if = {
				limit = { top_liege = root }
				add_opinion = {
					target = root
					modifier = respect_opinion
					opinion = 10
				}
			}
		}
		scope:feudal_county = { set_county_culture = scope:nomad_culture }
		culture = {
			if = {
				limit = {
					this != scope:nomad_culture
				}
				change_cultural_acceptance = {
					target = scope:nomad_culture
					value = 5
					desc = cultural_intolerance_tt
				}
			}
		}
		if = {
			limit = {
				culture != scope:nomad_culture
			}
			stress_impact = {
				diligent = medium_stress_impact_gain
				paranoid = medium_stress_impact_gain
			}
		}
		stress_impact = {
			just = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
   				ai_boldness = 2
   				ai_energy = 1
   				ai_honor = -1
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = just
			}
			modifier = {	#Weight down for stress.
				add = -15
				culture != scope:nomad_culture
				has_trait = diligent
			}
			modifier = {	#Weight down for stress.
				add = -15
				culture != scope:nomad_culture
				has_trait = paranoid
			}
		}
	}

	after = {
		scope:feudal_vassal = {
			clear_court_event_participation = yes
		}
		if = {
			limit = { exists = scope:nomad_same_liege }
			scope:nomad_same_liege = {
				clear_court_event_participation = yes
			}
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}
