﻿namespace = hold_court

# Differences in namespace range down to the on-going 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 = {
				NOT = { this = scope:character_a }
			}
			save_scope_as = character_b
		}
	}

	# Court events, as with all events, require at least one option to display.
	option = {
		name = 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"
		}
		## 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 
		add_character_flag = holding_court_character_flag
		# 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
		}
	}
	
	option = {
		name = hold_court.0001.c
		trigger = {
			AND = {
				is_ai = no
				has_character_flag = RE_diplo_first_flag
			}
		}
		remove_short_term_gold = major_gold_value
		hold_court_queue_next_event_effect_cut = yes
		hidden_effect = {
			trigger_event = RE_hold_court.1001
		}
	}
	
	option = {
		name = hold_court.0001.c
		trigger = {
			AND = {
				is_ai = no
				has_character_flag = RE_diplo_sec_flag
			}
		}
		remove_short_term_gold = major_gold_value
		hold_court_queue_next_event_effect_cut = yes
		hidden_effect = {
			trigger_event = RE_hold_court.1002
		}
	}
	
	option = {
		name = hold_court.0001.c
		trigger = {
			AND = {
				is_ai = no
				has_character_flag = RE_diplo_tri_flag
			}
		}
		remove_short_term_gold = major_gold_value
		hold_court_queue_next_event_effect_cut = yes
		hidden_effect = {
			trigger_event = RE_hold_court.1003
		}
	}
	
	option = {
		name = hold_court.0001.c
		trigger = {
			AND = {
				is_ai = no
				has_character_flag = RE_mart_first_flag
			}
		}
		remove_short_term_gold = major_gold_value
		hold_court_queue_next_event_effect_cut = yes
		hidden_effect = {
			trigger_event = RE_hold_court.1011
		}
	}
	
	option = {
		name = hold_court.0001.c
		trigger = {
			AND = {
				is_ai = no
				has_character_flag = RE_mart_sec_flag
			}
		}
		remove_short_term_gold = major_gold_value
		hold_court_queue_next_event_effect_cut = yes
		hidden_effect = {
			trigger_event = RE_hold_court.1012
		}
	}
	
	option = {
		name = hold_court.0001.c
		trigger = {
			AND = {
				is_ai = no
				has_character_flag = RE_mart_tri_flag
			}
		}
		remove_short_term_gold = major_gold_value
		hold_court_queue_next_event_effect_cut = yes
		hidden_effect = {
			trigger_event = RE_hold_court.1013
		}
	}
	
	option = {
		name = hold_court.0001.c
		trigger = {
			AND = {
				is_ai = no
				has_character_flag = RE_stew_first_flag
			}
		}
		remove_short_term_gold = major_gold_value
		hold_court_queue_next_event_effect_cut = yes
		hidden_effect = {
			trigger_event = RE_hold_court.1021
		}
	}
	
	option = {
		name = hold_court.0001.c
		trigger = {
			AND = {
				is_ai = no
				has_character_flag = RE_stew_sec_flag
			}
		}
		remove_short_term_gold = major_gold_value
		hold_court_queue_next_event_effect_cut = yes
		hidden_effect = {
			trigger_event = RE_hold_court.1022
		}
	}
	
	option = {
		name = hold_court.0001.c
		trigger = {
			AND = {
				is_ai = no
				has_character_flag = RE_stew_tri_flag
			}
		}
		remove_short_term_gold = major_gold_value
		hold_court_queue_next_event_effect_cut = yes
		hidden_effect = {
			trigger_event = RE_hold_court.1023
		}
	}
	
	option = {
		name = hold_court.0001.c
		trigger = {
			AND = {
				is_ai = no
				has_character_flag = RE_intr_first_flag
			}
		}
		remove_short_term_gold = major_gold_value
		hold_court_queue_next_event_effect_cut = yes
		hidden_effect = {
			trigger_event = RE_hold_court.1031
		}
	}
	
	option = {
		name = hold_court.0001.c
		trigger = {
			AND = {
				is_ai = no
				has_character_flag = RE_intr_sec_flag
			}
		}
		remove_short_term_gold = major_gold_value
		hold_court_queue_next_event_effect_cut = yes
		hidden_effect = {
			trigger_event = RE_hold_court.1032
		}
	}
	
	option = {
		name = hold_court.0001.c
		trigger = {
			AND = {
				is_ai = no
				has_character_flag = RE_intr_tri_flag
			}
		}
		remove_short_term_gold = major_gold_value
		hold_court_queue_next_event_effect_cut = yes
		hidden_effect = {
			trigger_event = RE_hold_court.1033
		}
	}
	
	option = {
		name = hold_court.0001.c
		trigger = {
			AND = {
				is_ai = no
				has_character_flag = RE_lear_first_flag
			}
		}
		remove_short_term_gold = major_gold_value
		hold_court_queue_next_event_effect_cut = yes
		hidden_effect = {
			trigger_event = RE_hold_court.1041
		}
	}
	
	option = {
		name = hold_court.0001.c
		trigger = {
			AND = {
				is_ai = no
				has_character_flag = RE_lear_sec_flag
			}
		}
		remove_short_term_gold = major_gold_value
		hold_court_queue_next_event_effect_cut = yes
		hidden_effect = {
			trigger_event = RE_hold_court.1042
		}
	}
	
	option = {
		name = hold_court.0001.c
		trigger = {
			AND = {
				is_ai = no
				has_character_flag = RE_lear_tri_flag
			}
		}
		remove_short_term_gold = major_gold_value
		hold_court_queue_next_event_effect_cut = yes
		hidden_effect = {
			trigger_event = RE_hold_court.1043
		}
	}
}

##################################################
# 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
		}
		# Finish the activity.
		#scope:activity = {
		#	activity_host = { apply_hold_court_grace_effect = yes }
		#	complete_activity = yes
		#}
		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
		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 = {
			count >= 1
			is_available_adult = yes
			has_court_event_flag = no
		}
		any_neighboring_and_across_water_top_liege_realm = {
			count > 0
		}
	}

	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 = {
				is_available_adult = yes
				has_court_event_flag = no
			}
			save_scope_as = rumormonger
			court_event_character_flag_effect = yes
		}
		random_neighboring_and_across_water_top_liege_realm = {
			save_scope_as = neighboring_realm
			holder = {
				save_scope_as = neighboring_ruler
				court_event_character_flag_effect = yes
			}
		}
		# 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 = medium_gold_value
		}
		random_list = {
			50 = {
				show_chance = no
				desc = hold_court.1001.a.success
				custom_tooltip = hold_court.1001.a.success.tt
			}
			50 = {
				show_chance = no
				desc = hold_court.1001.a.failure
				custom_tooltip = hold_court.1001.a.failure.tt
			}
		}
	}

	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
		}
		random_list = {
			50 = {
				show_chance = no
				desc = hold_court.1001.a.success
				custom_tooltip = hold_court.1001.a.success.tt
			}
			50 = {
				show_chance = no
				desc = hold_court.1001.a.failure
				custom_tooltip = hold_court.1001.a.failure.tt
			}
		}
	}

	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
		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_landed = no
	basic_is_available_ai = yes
	has_court_event_flag = no
	NOT = { is_courtier_of = root }
	#AGOT Added, invalid claimants
	is_human = yes
	NOT = { has_trait = nightswatch }
	NOT = { has_trait = kingsguard }
	NOT = { has_trait = maester }
	NOT = { has_trait = septon }
	OR = {
		AND = {
			culture = { agot_is_wildling_culture = yes }
			root.culture = { agot_is_wildling_culture = yes }
		}
		AND = {
			culture = { agot_is_wildling_culture = no }
			root.culture = { agot_is_wildling_culture = no }
		}
	}
}

# 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
	}
	
	trigger = {
		NOT = { has_character_flag = had_event_hold_court_1011 }
		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 = {
		add_character_flag = {
			flag = had_event_hold_court_1011
			years = 10
		}
		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
		}
		# 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
		}
		add_character_flag = temp_no_claim_war_cost
		start_war = {
			cb = claim_cb
			target = scope:target_title.holder.top_liege
			claimant = scope:claimant_guest
			target_title = scope:target_title
		}
		remove_character_flag = temp_no_claim_war_cost
	}

	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

		scope:county = {
			add_county_modifier = {
				modifier = hold_court_cropsharing
				years = 10
			}
		}
	}

	option = { 
		name = hold_court.1021.a
		trigger = {
			trigger_if = {
				limit = {
					is_ai = yes
				}
				short_term_gold >= medium_gold_value
			}
		}

		remove_short_term_gold = minor_gold_value
		scope:county = {
			add_county_modifier = {
				modifier = hold_court_grateful_peasants_modifier
				years = 5
			}
		}
		change_current_court_grandeur = medium_court_grandeur_gain
	}
	
	option = {
		name = hold_court.1021.b
		trigger = {
			trigger_if = {
				limit = {
					is_ai = yes
				}
				short_term_gold >= medium_gold_value
			}
		}

		remove_short_term_gold = minor_gold_value
		scope:county = {
			add_county_modifier = {
				modifier = hold_court_free_labor
				years = 5
			}
		}
	}	

	option = {
		name = hold_court.1021.c

		scope:county = {
			add_county_modifier = {
				modifier = hold_court_ploughs_to_swords
				years = 5
			}
		}
	}	

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

##################################################
# A Traitor Uncovered
# by Sean Hughes
# 1031 - 1040
##################################################

# A Traitor Uncovered: A courtier or guest has been spying on you!
scripted_trigger hold_court_2011_valid_traitor = {
	is_available_ai_adult = yes
	has_court_event_flag = no
	NOT = { root = { has_hook = prev } }
	opinion = {
		target = root
		value <= 20
	}
}

hold_court.1031 = {
	type = court_event
	title = hold_court.1031.t
	desc = hold_court.1031.desc
	theme = realm
	override_sound = { reference = event:/SFX/Events/Themes/sfx_event_theme_type_generic }	
	court_scene = {
		button_position_character = scope:guard
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:guard = {
				group = petitioners_group
				animation = disapproval
			}
			scope:traitor = {
				group = petitioners_group
				animation = worry
			}
		}
	}

	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.
	right_portrait = {
		character = scope:guard
		hide_info = yes
	}

	trigger = {
		NOT = { has_character_flag = had_event_hold_court_2011 }
		any_courtier_or_guest = { 
			hold_court_2011_valid_traitor = yes
		}
		#AGOT Modified
		#any_neighboring_and_across_water_top_liege_realm = { count > 0 }
		any_neighboring_and_across_water_top_liege_realm = {
			NOT = { holder = { has_government = nights_watch_government } }
			NOT = { holder = { has_government = ruins_government } }
			count > 0
		}
	}

	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_2011
			years = 10
		}

		#AGOT Modified

		#random_neighboring_and_across_water_top_liege_realm = { save_scope_as = foreign_realm }
		random_neighboring_and_across_water_top_liege_realm = {
			limit = {
				NOT = { holder = { has_government = nights_watch_government } }
				NOT = { holder = { has_government = ruins_government } }
			}
			save_scope_as = foreign_realm
		}
		random_courtier_or_guest = {
			limit = { hold_court_2011_valid_traitor = yes }

			weight = {
				base = 0.5
				compare_modifier = {
					value = ai_greed
					multiplier = 0.01 # At 100 greed, x3 as likely to be picked. At -50 greed, 0% chance of being picked.
				}
				compare_modifier = {
					value = ai_honor
					multiplier = -0.01 # At 50 honor, 0% chance to be picked. At -100 honor, x3 as likely to be picked.
				}
				modifier = {
					scope:foreign_realm.holder.top_liege.religion = religion # More likely if same faith as the ones they spy for
					add = 0.2
				}
				modifier = {
					scope:foreign_realm.holder.top_liege.faith = faith
					add = 0.3 # Total sum = 0.5
				}
			}
			save_scope_as = traitor
			court_event_character_flag_effect = yes
		}

		hidden_effect = {
			create_character = {
				template = new_warrior_character
				dynasty = none
				location = root.capital_province
				culture = root.capital_county.culture
				faith = root.capital_county.faith
				gender_female_chance = root_soldier_female_chance
				save_scope_as = guard
			}
		}
		scope:guard = {
			add_character_flag = wear_armor
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = { 
		name = hold_court.1031.a

		add_dread = medium_dread_gain
		execute_prisoner_effect = {
			VICTIM = scope:traitor
			EXECUTIONER = root
		}
	}

	option = {
		name = hold_court.1031.b
		add_hook = { 
			type = loyalty_hook
			target = scope:traitor
		}
	}
	
	option = {
		name = hold_court.1031.c

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

	after = {
		scope:guard = {
			clear_court_event_participation = yes
		}
		scope:guard = {
			remove_character_flag = wear_armor
		}
		scope:guard = { silent_disappearance_effect = yes }
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

##################################################
# God's Own Lands
# by Sean Hughes
# 1041 - 1050
##################################################

# God's Own Lands: Your bishop comes to you with a request to establish a new Bishopric, with a suitable candidate in tow.
scripted_trigger hold_court_2021_bishop_candidate_trigger = {
	faith = root.faith
	has_trait = education_learning
	is_ai = yes
	has_court_event_flag = no
}

hold_court.1041 = {
	type = court_event
	title = hold_court.1041.t
	desc = hold_court.1041.desc
	theme = realm
	override_sound = { reference = event:/SFX/Events/Themes/sfx_event_theme_type_generic }
	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 = admiration
			}
			scope:chosen_candidate = {
				group = petitioners_group
				animation = personality_zealous
			}
		}
	}

	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_2021 }
		has_council_position = councillor_court_chaplain
		cp:councillor_court_chaplain = {
			is_ai = yes
			has_court_event_flag = no
		}
		faith = { has_doctrine = doctrine_theocracy_temporal }
		any_held_title = {
			tier = tier_county
			NOT = { this = root.capital_county}
		}
	}

	weight_multiplier = {
		base = 1

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

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

		# Get the scopes for use in the event.
		cp:councillor_court_chaplain = { 
			save_scope_as = bishop
			court_event_character_flag_effect = yes
		}
		random_held_title = {
			limit = {
				tier = tier_county
				NOT = { this = root.capital_county}
			}
			save_scope_as = selected_title
		}

		# Pick a courtier or pool character to be our candidate
		every_courtier = {
			limit = { hold_court_2021_bishop_candidate_trigger = yes }
			add_to_list = potential_candidates
		}
		every_pool_guest = {
			limit = { hold_court_2021_bishop_candidate_trigger = yes }
			add_to_list = potential_candidates
		}
		every_pool_character = {
			province = root.capital_province
			limit = { hold_court_2021_bishop_candidate_trigger = yes }
			add_to_list = potential_candidates
		}
		random_in_list = {
			list = potential_candidates
			limit = { has_court_event_flag = no }
			save_scope_as = chosen_candidate
			court_event_character_flag_effect = yes
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = { 
		name = hold_court.1041.a
		add_piety = massive_piety_value
		scope:bishop = {
			add_opinion = {
				modifier = pleased_opinion
				target = root
				opinion = 25
			}
		}
		create_title_and_vassal_change = {
  			type = granted
  			save_scope_as = change
  		}
  		scope:selected_title = {
	  		change_title_holder = {
				holder = scope:chosen_candidate
				change = scope:change
				take_baronies = no
			}
  		}
		resolve_title_and_vassal_change = scope:change
		scope:chosen_candidate = {
			change_government = theocracy_government
			add_opinion = {
				modifier = received_title_county
				target = root
			}
		}	
	}

	option = {
		name = hold_court.1041.b
		remove_short_term_gold = tiny_gold_value
		add_piety = minor_piety_gain
		scope:bishop = {
			add_opinion = {
				modifier = pleased_opinion
				target = root
				opinion = 10
			}
		}
	}
	
	option = {
		name = hold_court.1041.c
		add_prestige = minor_prestige_gain
		scope:bishop = {
			add_opinion = {
				modifier = disappointed_opinion
				target = root
				opinion = -10
			}
		}
	}

	after = {
		# Finish up the chain if relevant.
		scope:chosen_candidate = {
			clear_court_event_participation = yes
		}
		scope:bishop = {
			clear_court_event_participation = yes
		}
		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 = { NOT = { 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 = {
		is_landed = 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
}

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

	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 = doctrine_clerical_gender_male_only }
			}
			create_character = {
				template = virtuous_priest_character_template
				location = root.capital_province
				gender = female
				dynasty = none
				save_scope_as = unconventional_preacher	
			}
		}
		else = {
			create_character = {
				template = virtuous_priest_character_template
				location = root.capital_province
				gender = male
				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 = {
							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 = { 
				NOT = { 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 = {
							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 = { 
		name = hold_court.3010.a
		capital_county = {
			add_county_modifier = {
				modifier = hold_court_preacher_loved_by_peasants_modifier
				years = 15
			}
		} 
		reverse_add_opinion = {
			target = scope:tolerant_vassal
			modifier = pleased_opinion
			opinion = 10
		}
		reverse_add_opinion = {
			target = scope:religious_vassal
			modifier = impious_opinion
			opinion = -10
		}
		hidden_effect = {
			scope:unconventional_preacher = {
				death = {
					death_reason = death_vanished
				}
			}
		}
		ai_chance = {
			base = 15
			ai_value_modifier = {
				ai_zeal = medium_chance_impact_negative_ai_value # Zealous characters don't like unconventional preachers
				ai_compassion = medium_chance_impact_positive_ai_value # Compassionate characters rather not punish those who do good
			}
		}
	}

	# Option B: Punish the preacher
	option = {
		name = hold_court.3010.b
		rightfully_imprison_character_effect = {
			TARGET = scope:unconventional_preacher
			IMPRISONER = root
		}
		capital_county = {
			add_county_modifier = {
				modifier = hold_court_beloved_preacher_imprisoned_modifier
				years = 15
			}
		}
		reverse_add_opinion = {
			target = scope:religious_vassal
			modifier = pious_opinion
			opinion = 10
		}
		reverse_add_opinion = {
			target = scope:tolerant_vassal
			modifier = cruelty_opinion
			opinion = -10
		}

		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
			}
		}
	}
	
	#AGOT Disabled, position disabled
	# Option C: Invite the preacher to serve as high almoner
	# option = {
	# 	trigger = {
	# 		can_appoint_char_to_court_position = {
	# 			CHAR = scope:unconventional_preacher
	# 			COURT_POS = high_almoner_court_position
	# 		}
	# 	}
	# 	name = hold_court.3010.c
	# 	add_piety = medium_piety_loss
	# 	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_court_position
	# 	}
	# 	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
		add_piety = medium_piety_loss
		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_court_position
		}
		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
			}
		}
	}

	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
}

# 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_sub_realm_barony = {
			county = { holder = root } 
			holder = { 
				NOT = { this = root } 
				culture = root.culture
				has_court_event_flag = no
			}
			NOT = { 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_sub_realm_barony = {
			limit = { 
				county = { holder = root } 
				holder = { 
					NOT = { this = root } 
					culture = root.culture
				}
				NOT = { culture = root.culture }
			}
			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 A: Get angry and punish them
	option = { 
		name = hold_court.3020.a
		trigger = {
			OR = {
				has_trait = arrogant
				has_trait = wrathful
				has_trait = vengeful
			}
		}
		add_dread = medium_dread_gain

		if = {
			every_held_title = {
				limit = { 
					tier = tier_county 
					culture = scope:village.culture 
				}
				custom = custom.every_county_of_culture
				add_county_modifier = {
					modifier = hold_court_displeased_peasants_modifier
					years = 5
				}
			}
		}
		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
		trigger = {
			trigger_if = {
				limit = {
					is_ai = yes
				}
				short_term_gold >= major_gold_value
			}
		}
		remove_short_term_gold = medium_gold_value
		if = {
			every_held_title = {
				limit = { 
					tier = tier_county 
					culture = scope:village.culture 
				}
				custom = custom.every_county_of_culture
				add_county_modifier = {
					modifier = hold_court_grateful_peasants_modifier
					years = 5
				}
			}
		}
		scope:village.culture = {
			change_cultural_acceptance = {
				target = root.culture
				value = low_negative_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
			}
		}
	}

	# Option C: Build something nicer instead
	option = {
		name = hold_court.3020.c
		trigger = {
			OR = {
				has_trait = compassionate
				has_trait = diplomat
				has_trait = overseer
				has_trait = architect
			}
			trigger_if = {
				limit = {
					is_ai = yes
				}
				short_term_gold >= major_gold_value
			}
		}
		remove_short_term_gold = medium_gold_value
		scope:village_county = {
			add_county_modifier = {
				modifier = hold_court_displeased_peasants_modifier
				years = 5
			}
		}
		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 = high_chance_impact_positive_ai_value # Compassionate characters don't like punishing others
			}
		}
	}

	# Option D: Refuse
	option = {
		name = hold_court.3020.d
		scope:village_county = {
			add_county_modifier = {
				modifier = hold_court_displeased_peasants_modifier
				years = 5
			}
		}
		ai_chance = {
			base = 15
			modifier = {
				gold < tiny_gold_value # AI can't pay if they don't have the money
				add = 50
			}
		}
	}

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

	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 = {
			NOT = { 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 = {
				NOT = { 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_gold >= major_gold_value
			}
		}
		remove_short_term_gold = medium_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 = {
		can_employ_court_position_type = court_jester_court_position
		any_vassal = {
			has_personality_extroverted_trigger = yes
			is_available_ai_adult = yes
			has_court_event_flag = no
			save_temporary_scope_as = extroverted_vassal_check
		}
		any_vassal = {
			has_trait_introverted_trigger = yes
			is_available_ai_adult = yes
			has_court_event_flag = no
			NOT = { 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 = {
				has_personality_extroverted_trigger = yes
				is_available_ai_adult = yes
				has_court_event_flag = no
			}
			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	
			}
		}

		random_vassal = {
			limit = {
				has_trait_introverted_trigger = yes
				is_available_ai_adult = yes
				has_court_event_flag = no
				NOT = { this = scope:jester_requester }
			}
			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 = { add_courtier = scope:potential_jester }
		appoint_court_position = {
			recipient = scope:potential_jester
			court_position = court_jester_court_position
		}
		reverse_add_opinion = {
			target = scope:potential_jester
			modifier = pleased_opinion
			opinion = 20
		}
		reverse_add_opinion = {
			target = scope:jester_requester
			modifier = pleased_opinion
			opinion = 20
		}
		reverse_add_opinion = {
			target = scope:kill_joy
			modifier = disappointed_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

		appoint_court_position = {
			recipient = scope:jester_requester
			court_position = court_jester_court_position
		}
		reverse_add_opinion = {
			target = scope:jester_requester
			modifier = rude_opinion
			opinion = -30
		}
		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
			}
		}

		appoint_court_position = {
			recipient = scope:kill_joy
			court_position = court_jester_court_position
		}
		scope:kill_joy = {
			progress_towards_rival_effect = {
				CHARACTER = root
				REASON = rival_killjoy_jester
				OPINION = -40
			}
		}
		reverse_add_opinion = {
			target = scope:jester_requester
			modifier = pleased_opinion
			opinion = 15
		}
		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 D: Refuse
	option = { 
		name = hold_court.3040.d
		add_character_modifier = {
			modifier = hold_court_austere_court_modifier
			years = 5
		}
		reverse_add_opinion = {
			target = scope:kill_joy
			modifier = respect_opinion
			opinion = 20
		}
		reverse_add_opinion = {
			target = scope:jester_requester
			modifier = disappointed_opinion
			opinion = -20
		}
		scope:jester_requester = {
			progress_towards_rival_effect = {
				CHARACTER = root
				REASON = rival_jester_refused
				OPINION = -30
			}
		}
		hidden_effect = {
			scope:potential_jester = {
				death = {
					death_reason = death_vanished 
				}
			}
		}

		ai_chance = {
			base = 5

			modifier = {
				has_trait_introverted_trigger = yes
				add = 5
			}
			modifier = {
				short_term_gold < medium_gold_value
				add = 2
			}
		}
	}

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

		reverse_add_opinion = {
			target = scope:jester_requester
			modifier = disappointed_opinion
			opinion = -20
		}
		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
	}
}

#####################################
# A Noble Responsibility			#
# by Bianca Savazzi					#
# 3050								#
#####################################

# Councillor reminds you that you haven't held court (in a while)
hold_court.3050 = {
	type = character_event
	title = hold_court.3050.t
	desc = hold_court.3050.desc
	theme = court
	left_portrait = {
		character = scope:reminder_person
		animation = personality_rational
	}
	
	trigger = {
		is_ai = no
		is_available = yes
		exists = var:last_hold_court_date
		var:last_hold_court_date < hold_court_grace_period_comparison
		has_royal_court = yes
		NOT = { has_variable = hold_court_cooldown }
		any_councillor = {
			count >= 1
			has_court_event_flag = no
		}
		NOT = {
			government_has_flag = government_is_tribal
		}
		has_multiple_players = no
	}

	immediate = {
		#AGOT Modified, Castellan first choice to remind you
		if = {
			limit = {
				exists = cp:councillor_castellan
			}
			cp:councillor_castellan = { save_scope_as = reminder_person }
		}
		else_if = {
			limit = {
				exists = cp:councillor_chancellor
			}
			cp:councillor_chancellor = { save_scope_as = reminder_person }
		}
		else_if = {
			limit = {
				exists = cp:councillor_spymaster
			}
			cp:councillor_spymaster = { save_scope_as = reminder_person }
		}
		else_if = {
			limit = {
				exists = cp:councillor_court_chaplain
			}
			cp:councillor_court_chaplain = { save_scope_as = reminder_person }
		}
		else_if = {
			limit = {
				exists = cp:councillor_steward
			}
			cp:councillor_steward = { save_scope_as = reminder_person }
		}
		else_if = {
			limit = {
				exists = cp:councillor_marshal
			}
			cp:councillor_marshal = { save_scope_as = reminder_person }
		}
		scope:reminder_person = {
			court_event_character_flag_effect = yes
		}
	}

	# Option A: Threaten the person reminding you
	option = { 
		trigger = {
			OR = {
				dread >= medium_dread
				has_trait = sadistic
				has_trait = arrogant
			}
		}
		name = hold_court.3050.a
		scope:reminder_person = {
			progress_towards_rival_effect = {
				CHARACTER = root
				REASON = rival_threatened_hold_court
				OPINION = -40
			}
			add_stress = major_stress_gain
		}
		add_dread = medium_dread_gain
		stress_impact = {
			irritable = miniscule_stress_impact_loss
			wrathful = miniscule_stress_impact_loss
			calm = major_stress_impact_gain
		}
		change_current_court_grandeur = minor_court_grandeur_loss 

		ai_chance = {
			base = 15

			modifier = {
				dread < high_dread
				add = 5
			}
		}
	}

	# Option B: Acknowledge 
	option = { 
		name = hold_court.3050.b

		change_current_court_grandeur = medium_court_grandeur_loss

		ai_chance = {
			base = 15

			modifier = {
				has_trait = just
				add = 5
			}
			modifier = {
				has_trait = diligent
				add = 5
			}
		}
	}

	# Option C: Stall them pls
	option = { 
		name = hold_court.3050.c
		if = {
			limit = {
				scope:reminder_person = {
					can_add_hook = {
						target = root
						type = favor_hook
					}
				}
			}
			scope:reminder_person = {
				add_hook = {
					target = root
					type = favor_hook
				}
				add_stress = medium_stress_gain
			}
		}
		else = {
			scope:reminder_person = {
				progress_towards_rival_effect = {
					CHARACTER = root
					REASON = rival_hold_court_reminder
					OPINION = -30
				}
				add_stress = medium_stress_gain
			}
		}
		change_current_court_grandeur = minor_court_grandeur_loss

		ai_chance = {
			base = 15

			modifier = {
				has_trait = lazy
				add = 5
			}
			modifier = {
				has_trait = diligent
				add = -5
			}
		}
	}

	after = {
		set_variable = {
			name = last_hold_court_date
			value = current_date
		}
		scope:reminder_person = {
			clear_court_event_participation = yes
		}
	}
}

#####################################
# Addressing the Corruption			#
# by Bianca Savazzi					#
# 3060								#
#####################################
 
scripted_trigger hold_court_3060_county_and_holder_trigger = {
	OR = {
		has_county_modifier = county_corruption_inefficient_tax_collection_modifier
		has_county_modifier = county_corruption_deserting_levies_modifier
		has_county_modifier = county_corruption_lackluster_administration_modifier
		has_county_modifier = county_corruption_uncooperative_guilds_modifier
		has_county_modifier = county_corruption_lack_of_sheriffs_modifier
		has_county_modifier = county_corruption_lack_of_courts_modifier
		has_county_modifier = county_corruption_inefficient_tax_collection_modifier
		has_county_modifier = county_corruption_bandits_rampant_modifier
		has_county_modifier = county_corruption_unsafe_highways_modifier
		has_county_modifier = county_corruption_smuggling_ring_modifier
		has_county_modifier = county_corruption_thieves_guild_modifier
	}
	holder = { 
		NOT = { 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 }
}

# 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 = {
								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 = {
						OR = { 
							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_if = {
			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
		trigger = {
			trigger_if = {
				limit = {
					is_ai = yes
				}
				short_term_gold >= scope:county_petitioner.major_gold_value
			}
		}
		pay_short_term_gold = {
			target = scope:county_petitioner
			gold = scope:county_petitioner.medium_gold_value
		}
		scope:county_petitioner = {
			add_opinion = {
				modifier = grateful_opinion
				target = root
				opinion = 20
			}
			stress_impact = {
				greedy = medium_stress_loss
			}
		}

		ai_chance = {
			base = 15

			modifier = {
				has_trait = generous
				add = 5
			}
			modifier = {
				has_trait = greedy
				add = -15
			}
		}
	}

	# Option B: Steward Advice 
	option = { 
		name = hold_court.3060.b
		trigger = {
			exists = cp:councillor_steward
			scope:county_petitioner = {
				liege = root
			}
		}
		scope:county_petitioner = {
			add_opinion = {
				modifier = grateful_opinion
				opinion = 10
				target = root
			}
			add_character_modifier = {
				modifier = hold_court_receiving_liege_steward_advise_modifier
				years = 2
			}
		}
		cp:councillor_steward = {
			add_character_modifier = {
				modifier = hold_court_steward_advising_vassal_modifier
				years = 2
			}
		}

		ai_chance = {
			base = 0
		}
	}
	
	# Option C: Tell them off and do nothing 
	option = {  
		name = hold_court.3060.c
		scope:county_petitioner = {
			add_opinion = {
				modifier = insult_opinion
				opinion = -30
				target = root
			}
		}

		ai_chance = {
			base = 100
		}
	}

	# Option D: 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
			}
		}

		scope:cp_steward = {
			progress_towards_rival_effect = {
				CHARACTER = root
				REASON = rival_replaced_steward
				OPINION = -30
			}
		}

		ai_chance = {
			base = 0
		}
	}

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

#####################################
# The Child with Two Mothers		#
# by Bianca Savazzi					#
# 3070								#
#####################################

# CK version of the "Judgement of Solomon" - two women are quarreling over who is the mother of a baby.
hold_court.3070 = {
	type = court_event
	title = hold_court.3070.t
	desc = hold_court.3070.desc
	theme = court 
	cooldown = { years = 10 }
	lower_center_portrait = scope:mystery_baby
	lower_right_portrait = scope:invested_viewer_favoring_youngest
	lower_left_portrait = scope:invested_viewer_favoring_eldest
	court_scene = {
		button_position_character = scope:possible_mother_oldest
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:possible_mother_oldest = {
				group = petitioners_group
				animation = anger
			}
			scope:possible_mother_youngest = {
				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
		# More likely if a scholarly court because of the unique option 
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_scholarly }
	}

	trigger = {
		is_physically_able_adult = yes
	}
	
	immediate = {
		#get potential peeps who are invested in this case
		if = {
			limit = {
				any_relation = {
					type = friend
					is_available_healthy_ai_adult = yes
					liege = root
					has_court_event_flag = no
				}
			}
			every_relation = {
				type = friend 
				limit = { 
					is_available_healthy_ai_adult = yes
					liege = root
					has_court_event_flag = no
				}
				add_to_list = invested_viewers
			}
		}
		if = {
			limit = {
				any_relation = {
					type = best_friend
					is_available_healthy_ai_adult = yes
					liege = root
					has_court_event_flag = no
				}
			}
			every_relation = {
				type = best_friend 
				limit = { 
					is_available_healthy_ai_adult = yes
					liege = root
					has_court_event_flag = no
				}
				add_to_list = invested_viewers
			}
		}
		if = {
			limit = {
				any_close_or_extended_family_member = {
					is_available_healthy_ai_adult = yes
					liege = root
					has_court_event_flag = no
				}
			}
			every_close_or_extended_family_member = {
				limit = { 
					is_available_healthy_ai_adult = yes
					liege = root
					has_court_event_flag = no
				}
				add_to_list = invested_viewers
			}
		}
		if = {
			limit = {
				any_vassal = {
					is_available_healthy_ai_adult = yes
					has_court_event_flag = no
				}
			}
			every_vassal = {
				limit = { 
					is_available_healthy_ai_adult = yes
					has_court_event_flag = no
				}
				add_to_list = invested_viewers
			}
		}
		#Now pick two that are attending the petition
		if = {
			limit = {
				any_in_list = {
					list = invested_viewers
					count > 2
				}
			}
			random_in_list = {
				list = invested_viewers
				save_scope_as = invested_viewer_favoring_youngest
				court_event_character_flag_effect = yes
			}
			random_in_list = {
				list = invested_viewers
				limit = { 
					NOT = { this = scope:invested_viewer_favoring_youngest } 
				}
				save_scope_as = invested_viewer_favoring_eldest
				court_event_character_flag_effect = yes
			}
		}

		#create the characters introduced in the event
		create_character = {
			template = servant_character
			location = root.capital_province
			gender = female
			age = { 25 40 }
			dynasty = none
			save_scope_as = possible_mother_oldest	
		}
		create_character = {
			template = servant_character
			location = root.capital_province
			gender = female
			age = { 18 24 } #So that she's always the younger woman
			dynasty = none
			save_scope_as = possible_mother_youngest	
		}
		create_character = {
			template = miracle_baby_template
			location = root.capital_province
			dynasty = none
			save_scope_as = mystery_baby	
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	# Option A: Test the parents
	option = { 
		trigger = {
			learning > high_skill_rating
		}
		name = hold_court.3070.a
		custom_tooltip = hold_court.3070.a.tt
		change_current_court_grandeur = medium_court_grandeur_gain 
		stress_impact = {
			compassionate = massive_stress_impact_loss #the child will now go to a loving home
			diligent = medium_stress_impact_loss #due diligence 
			callous = medium_stress_impact_gain #ugh, parental attachment is fake
		}
		ai_chance = {
			base = 15
			modifier = {
				dread < high_dread
				add = 5
			}
			ai_value_modifier = {
				ai_honor = 1 # Honorable characters want to do the honarable thing
				ai_compassion = 1 # compassionate wants the child to be with their true family
			}
		}
		scope:mystery_baby = { silent_disappearance_effect = yes }
	}

	# Option B: Cleave the bby 
	option = { 
		trigger = {
			OR = {
				has_trait = sadistic
				has_trait = callous
			}
		}
		name = hold_court.3070.b
		give_nickname = nick_the_child_killer
		add_dread = massive_dread_gain
		every_vassal = {
			custom = custom.every_non_callous_or_sadistic_vassal
			limit = {
				NOR = {
					has_trait = sadistic 
					has_trait = callous
				}
			}
			add_opinion = {
				modifier = cruelty_opinion
				target = root
				opinion = -40
			}
		}
		scope:mystery_baby = {
			death = {
				death_reason = death_cloven_in_half
				killer = root
			}
		}
		stress_impact = {
			trusting = medium_stress_impact_gain #You don't trust the mothers' words and kill a child
			compassionate = massive_stress_impact_gain #WAT
			callous = medium_stress_impact_loss #meh, it's the rational choice, both gets half
			sadistic = major_stress_impact_loss #lmao, your faces made it all worth this
		}
		ai_chance = {
			base = 55
			modifier = {
				dread < high_dread
				add = 15
			}
			modifier = {	#We favour the other trait specific options for callous & sadistic
				add = 100
				has_trait = callous
			}
			#AGOT Added
			modifier = {
				factor = 0
				can_have_children = yes
			}
			modifier = {	
				add = 100
				has_trait = sadistic
			}
			ai_value_modifier = {
				ai_honor = -0.5 # Honorable characters want to do the honarable thing
				ai_compassion = -0.5 # compassionate don't want to slice kid
			}
		}
	}

	# Option C: Favour the younger woman
	option = { 
		name = hold_court.3070.c
		scope:mystery_baby = { set_mother = scope:possible_mother_youngest } 
		scope:mystery_baby = { silent_disappearance_effect = yes }
		#Opinion change if you have invested peeps watching
		if = {
			limit = {
				exists = scope:invested_viewer_favoring_youngest
				exists = scope:invested_viewer_favoring_eldest
			}
			scope:invested_viewer_favoring_youngest = {
				add_opinion = {
					modifier = ep1_agreed_with_decision_opinion
					target = root
					opinion = 10
				}
			}
			scope:invested_viewer_favoring_eldest = {
				add_opinion = {
					modifier = ep1_disagreed_with_decision_opinion
					target = root
					opinion = -20
				}
			}
		}

		ai_chance = {
			base = 15
			modifier = {
				has_trait = lazy
				add = 5
			}
			modifier = {
				has_trait = diligent
				add = -5
			}
		}
	}

	# Option D: Favour the older woman
	option = { 
		name = hold_court.3070.d
		scope:mystery_baby = { set_mother = scope:possible_mother_oldest } 
		scope:mystery_baby = { silent_disappearance_effect = yes }
		#Opinion change if you have invested peeps watching
		if = {
			limit = {
				exists = scope:invested_viewer_favoring_youngest
				exists = scope:invested_viewer_favoring_eldest
			}
			scope:invested_viewer_favoring_eldest = {
				add_opinion = {
					modifier = ep1_agreed_with_decision_opinion
					target = root
					opinion = 10
				}
			}
			scope:invested_viewer_favoring_youngest = {
				add_opinion = {
					modifier = ep1_disagreed_with_decision_opinion
					target = root
					opinion = -20
				}
			}
		}
		ai_chance = {
			base = 15
			modifier = {
				has_trait = lazy
				add = 5
			}
			modifier = {
				has_trait = diligent
				add = -5
			}
		}
	}

	# Option E: Adopt!
	option = { 
		name = hold_court.3070.e
		#Only possible if you don't have any live kids
		trigger = {
			any_child = { is_alive = yes count = 0 }
		}

		#One shiny new child for you!
		if = {
			limit = { is_female = yes }
			scope:mystery_baby = { set_mother = root }
		}
		else = {
			scope:mystery_baby = { set_father = root }
		}
		hidden_effect = {
			#We take care of the sundries in a hidden effect so as not to put too much into the tooltip.
			scope:mystery_baby = { 
				set_house = root.house 
				add_trait = disputed_heritage
			}
			add_courtier = scope:mystery_baby
			#And they're pretty happy about being stepping up in life.
			reverse_add_opinion = {
				target = scope:mystery_baby
				modifier = love_opinion
				opinion = 70
			}
			add_hook = {
				target = scope:mystery_baby
				type = loyalty_hook
			}
		}
		every_vassal = {
			custom = custom.every_feudal_vassal
			limit = {
				government_has_flag = government_is_feudal
			}
			add_opinion = {
				modifier = ep1_disagreed_with_lowborn_adoption_opinion
				target = root
				opinion = -40
			}
		}
		every_consort = {
			custom = custom.every_opposite_sex_consort
			limit = {
				sex_opposite_of = root
			}
			add_opinion = {
				modifier = ep1_disagreed_with_lowborn_adoption_opinion
				target = root
				opinion = -80
			}
		} 
		stress_impact = {
			ambitious = medium_stress_impact_loss #Finally, I got a kid! My lineage is secure!
			compassionate = massive_stress_impact_loss #Yay, a kid!
			arrogant = medium_stress_impact_loss #Ye, I can do these controversial things because I'm so cool
			paranoid = medium_stress_impact_gain #WHO IS THIS CHILD???
			callous = major_stress_impact_gain #ew, no
			sadistic = major_stress_impact_gain #wat, no
		}
		ai_chance = {
			base = 100 #High because it makes sense to secure your lineage
			modifier = {	#Weight up for stress.
				add = 20
				has_trait = ambitious
			}
			modifier = {	
				add = 50
				has_trait = compassionate
			}
			modifier = {	#Weight down for stress.
				add = -20
				has_trait = paranoid
			}
			modifier = {	#We favour the other trait specific options for callous & sadistic
				add = -100
				has_trait = callous
			}
			modifier = {	
				add = -100
				has_trait = sadistic
			}
		}
	}

	after = {
		scope:possible_mother_oldest = { silent_disappearance_effect = yes }
		scope:possible_mother_youngest = { silent_disappearance_effect = yes }
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = 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

		# 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
		stress_impact = {
			greedy = medium_stress_loss
			arrogant = medium_stress_loss
			generous = medium_stress_gain
			humble = medium_stress_gain
		}
		add_character_modifier = {
			modifier = petition_event_artifact_exhibition_for_gold
			years = 3
		}
		ai_chance = {
			base = 15
			ai_value_modifier = {
				ai_greed = 1
			}
			modifier = {
				gold < minor_gold_value
				add = 5
			}
		}
		stress_impact = {
			greedy = medium_stress_loss
			arrogant = medium_stress_loss
			generous = medium_stress_gain
			humble = medium_stress_gain
		}
	}

	# Option B: Gain Prestige 
	option = { 
		name = hold_court.3080.b
		custom_tooltip = hold_court.3080.a.tt
		add_character_modifier = {
			modifier = petition_event_artifact_exhibition_for_prestige
			years = 3
		}
		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 = {
	NOT = { 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_short_term_gold = major_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
					NOT = { 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_gold < major_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_short_term_gold = medium_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 = {
					NOT = { 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_gold < medium_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_short_term_gold = minor_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_gold < minor_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_gold < minor_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 = {
	NOT = { 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
# 4100			Cheated by Nature - Vassals express prejudice towards ruler's disability
# 4200*			Sanctuary - Foreign noble seeks shelter
# 4300			Dress Me! Dress Me! - Should there be a dress code at court?
# 4400			Open Carry - Vassals argue about open carry of weapons in the realm
# 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
			#AGOT Added, these people shouldn't inherit
			NOR = {
				has_trait = nightswatch
				has_trait = kingsguard
				has_trait = maester
				has_trait = septon
			}
		}
	}

	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 = {
		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
				#AGOT Added, these people shouldn't inherit
				NOR = {
					has_trait = nightswatch
					has_trait = kingsguard
					has_trait = maester
					has_trait = septon
				}
			}
			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 = {
				#AGOT Modified
				#is_ai = yes
				is_available_ai_adult = 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
			scope:annoying_heir = {
				if = {
					limit = {
						NOT = { has_trait = murderer }
					}
					add_trait = murderer
				}
				if = {
					limit = {
						NOT = { has_trait = sadistic}
					}
					add_trait = sadistic
				}
			}

		}
		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
			scope:annoying_heir = {
				if = {
					limit = {
						NOT = { has_trait = deceitful }
					}
					add_trait = deceitful
				}
			}
		}
		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
			scope:annoying_heir = {
				if = {
					limit = {
						NOT = { has_trait = drunkard }
					}
					add_trait = drunkard
				}
			}
		}

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

	option = { 
		name = hold_court.4001.a
		add_dread = major_dread_gain
		every_courtier_or_guest = {
			custom = all_courtiers_and_guests
			add_opinion = {
				opinion = -10
				target = root
				modifier = cruelty_opinion
			}
		}
		stress_impact = {
			craven = medium_stress_gain
			sadistic = medium_stress_loss
			family_first = medium_stress_loss
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_vengefulness = -0.75
				ai_rationality = -0.5
				ai_sociability = -0.5
			}
		}
	}

	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.c
		trigger = {
			scope:preferred_heir = { 
				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
				}
			}
		}
		scope:preferred_heir = {
			add_opinion = {
				target = root
				opinion = -50
				modifier = insulted_opinion
			}
			if = {
				limit = {
					NOT = { has_relation_rival = root }
				}
				set_relation_rival = {
					target = root
					reason = rival_favoritism
				}
			}
		}
		scope:annoyed_vassal = {
			add_opinion = {
				target = root
				opinion = -50
				modifier = annoyed_opinion
			}

		}
		add_prestige = medium_prestige_loss
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_vengefulness = 0.75
				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 = {
				OR = {
					number_of_commander_traits > 0
				}
			}
		}
		scope:annoying_heir = {
			if = {
				limit = {
					NOT = { has_trait = reckless }
				}
				add_trait = reckless
			}
			add_prowess_skill = 4
		}
		every_courtier_or_guest = {
			custom = all_courtiers_and_guests
			add_opinion = {
				opinion = -10
				target = root
				modifier = cruelty_opinion
			}
		}
		ai_chance = {
			base =50
			ai_value_modifier = {
				ai_boldness = 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
		}
	}
}

##################################################
# Cheated by Nature
# by Isabella Welch
# 4100
##################################################

scripted_effect health_challenge_duel_effect = {
	duel = {
		skill = diplomacy
		target = scope:prejudiced_vassal
		4 = {
			custom_tooltip = hold_court.4100.duel_win
			compare_modifier = {
				value = scope:duel_value
				multiplier = 1.5
			}
			every_vassal = {
				custom = all_vassals
				add_opinion = {
					target = root
					modifier = admires_resolve_opinion
				}
			}
			if = {
				limit = {
					NOT = { has_trait = brave }
					OR = {
						has_character_flag = mental_health_prejudice
					}
				}
				add_trait = brave
			}
			if = {
				limit = {
					OR = {
						has_character_flag = chronic_pain_prejudice
					}
				}
				add_martial_skill = 1
			}
			hidden_effect = {
				send_interface_toast = {
					left_icon = scope:prejudiced_vassal
					title = hold_court.4100.impressed
					show_as_tooltip = { add_diplomacy_lifestyle_xp = medium_lifestyle_xp }
				}
			}
		}
		6 = {
			custom_tooltip = hold_court.4100.duel_loss
			compare_modifier = {
				value = scope:duel_value
				multiplier = 0.5
			}
			add_dread = major_dread_loss
			every_vassal = {
				limit = {
					NOT = { has_trait = compassionate }
				}
				custom = all_vassals
				add_opinion = {
					target = root
					modifier = thinks_liege_incapable_opinion
				}
			}
			change_current_court_grandeur = medium_court_grandeur_loss
			send_interface_toast = {
				left_icon = scope:prejudiced_vassal
				title = hold_court.4100.unimpressed
				show_as_tooltip = { add_stress = major_stress_gain }
			}		
		}
	}
} 

# Vassals suggest you are unfit to rule because of your disability
hold_court.4100 = {
	type = court_event
	title = hold_court.4100.t 
	desc = {
		desc = hold_court.4100.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					has_character_flag = deformity_prejudice
				}
				desc = hold_court.4100.deformity_prejudice
			}
			triggered_desc = {
				trigger = {
					has_character_flag = speech_prejudice
				}
				desc = hold_court.4100.speech_prejudice
			}
			triggered_desc = {
				trigger = {
					has_character_flag = mental_health_prejudice
				}
				desc = hold_court.4100.mental_health_prejudice
			}
			triggered_desc = {
				trigger = {
					has_character_flag = chronic_pain_prejudice
				}
				desc = hold_court.4100.chronic_pain_prejudice
			}
			triggered_desc = {
				trigger = {
					has_character_flag = disability_prejudice_fallback
				}
				desc = hold_court.4100.disability_prejudice_fallback
			}
		}
		triggered_desc = {
			trigger = {
				OR = {
					has_character_flag = deformity_prejudice
					has_character_flag = speech_prejudice
					has_character_flag = mental_health_prejudice
					has_character_flag = disability_prejudice_fallback
				}
			}
			desc = hold_court.4100.disability_insult
		}
		desc = hold_court.4100.disability_prejudice_ending
	}
	theme = learning_medicine_focus
	court_scene = {
		button_position_character = scope:prejudiced_vassal
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:prejudiced_vassal = {
				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_disability_prejudice_event }
		any_vassal = {
			has_court_event_flag = no
			is_ai = yes
			NOR = {
				has_trait = scarred
				has_trait = one_eyed
				has_trait = one_legged
				has_trait = disfigured
				has_trait = weak
				has_trait = dull
				has_trait = depressed
				has_trait = possessed
				has_trait = albino
				has_trait = lisping
				has_trait = stuttering
				has_trait = giant
				has_trait = scaly
				has_trait = clubfooted
				has_trait = dwarf
				has_trait = hunchbacked
				has_trait = impotent
				has_trait = wheezing
				has_trait = spindly
				has_trait = bleeder
				has_trait = wounded
				has_trait = maimed
				has_trait = infirm
				has_trait = blind
				has_trait = compassionate
				#AGOT Added
				has_trait = mute
			}
			age > 10
		}
		OR = {
			has_trait = scarred
			has_trait = one_eyed
			has_trait = one_legged
			has_trait = disfigured
			has_trait = maimed
			has_trait = infirm
			has_trait = blind
			has_trait = weak
			has_trait = dull
			has_trait = depressed
			has_trait = possessed
			has_trait = albino
			has_trait = lisping
			has_trait = stuttering
			has_trait = giant
			has_trait = scaly
			has_trait = clubfooted
			has_trait = dwarf
			has_trait = hunchbacked
			has_trait = impotent
			has_trait = wheezing
			has_trait = spindly
			has_trait = bleeder
			has_trait = maimed
			has_trait = infirm
			has_trait = blind
			#AGOT Added
			has_trait = mute
		}
	}

	weight_multiplier = {
		base = 1

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

	immediate = {
		add_character_flag = {
			flag = has_had_disability_prejudice_event
			days = 1825
		}

		random_vassal = {
			weight = {
				base = 1
				modifier = {
					factor = 5
					is_powerful_vassal = yes
				}
				modifier = {
					factor = 40
					opinion = {
						target = root
						value <= medium_negative_opinion
					}
				}
				modifier = {
					number_of_commander_traits > 0
					factor = 10
				}
				modifier = {
					is_knight_of = root
					factor = 10
				}
			}
			limit = {
				is_ai = yes
				has_court_event_flag = no
				NOT = {
					has_trait = scarred
					has_trait = one_eyed
					has_trait = one_legged
					has_trait = disfigured
					has_trait = weak
					has_trait = dull
					has_trait = depressed
					has_trait = possessed
					has_trait = albino
					has_trait = lisping
					has_trait = stuttering
					has_trait = giant
					has_trait = scaly
					has_trait = clubfooted
					has_trait = dwarf
					has_trait = hunchbacked
					has_trait = impotent
					has_trait = wheezing
					has_trait = spindly
					has_trait = bleeder
					has_trait = wounded
					has_trait = maimed
					has_trait = infirm
					has_trait = blind
					#AGOT Added
					has_trait = mute
				}
			}
			save_scope_as = prejudiced_vassal
			court_event_character_flag_effect = yes
		}
		if = {
			limit = {
				OR = {
					has_trait = scarred
					has_trait = one_eyed
					has_trait = one_legged
					has_trait = disfigured
					has_trait = scaly
					has_trait = albino
					has_trait = dwarf
					has_trait = hunchbacked
					has_trait = clubfooted
					has_trait = giant
					has_trait = maimed
					has_trait = infirm
					has_trait = blind
					#AGOT Added
					has_trait = mute
				}
			}
			add_character_flag = deformity_prejudice
		}
		else_if = {
			limit = {
				OR = {
					has_trait = lisping
					has_trait = stuttering
				}
			}
			add_character_flag = speech_prejudice
		}
		else_if = {
			limit = {
				OR = {
					has_trait = depressed_1
					has_trait = depressed_genetic
				}
			}
			add_character_flag = mental_health_prejudice
		}


		else_if = {
			limit = {
				OR = {
					has_trait = spindly
					has_trait = weak
					has_trait = infirm
				}
			}
			add_character_flag = chronic_pain_prejudice
		}
		else = {
			add_character_flag = disability_prejudice_fallback
		}
		if = {
			limit = { 
				scope:prejudiced_vassal = { 
					NOT = { has_relation_rival = root }
				}
			}
			set_relation_rival = {
				target = scope:prejudiced_vassal
				reason = rival_prejudice
			}
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = { 
		name = hold_court.4100.a
		if = {
			limit = {
				NOT = { has_trait = cynical }
			}
			add_trait = cynical
		}
		stress_impact = {
			zealous = major_stress_gain
		}
		every_courtier = {
			limit = { 
				has_trait = zealous 
			}
			custom = all_zealous_in_the_court
			add_opinion = {
				target = root
				modifier = disgusted_opinion
				opinion = -10
			}
		}
		if = {
			limit = {
				cp:councillor_court_chaplain = { exists = yes }
			}
			cp:councillor_court_chaplain = {
				add_opinion = {
					target = root
					modifier = impious_opinion
					opinion = -20
				}
			}
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_zeal = -0.75
			}
		}
	}

	option = {
		name = hold_court.4100.b
		trigger = { has_character_flag = disability_prejudice_fallback }
		health_challenge_duel_effect = yes
		stress_impact = {
			craven = major_stress_gain
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_boldness = 0.75
			}
		}
	}

	option = {
		name = hold_court.4100.c
		trigger = { has_trait = disfigured }
		add_dread = minor_dread_loss
		add_character_modifier = {
			modifier = dashing_mask
		}
		remove_short_term_gold = minor_gold_value
		scope:prejudiced_vassal = {
			add_opinion = {
				target = root
				modifier = thinks_liege_incapable_opinion
			}
		}
		change_current_court_grandeur = medium_court_grandeur_gain
	}
	option = {
		name = hold_court.4100.d
		trigger = { has_character_flag = speech_prejudice }
		health_challenge_duel_effect = yes
		stress_impact = {
			craven = major_stress_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = 0.5
				ai_rationality = 0.5
			}
		}
	}
	option = {
		name = hold_court.4100.e
		trigger = { has_character_flag = mental_health_prejudice }
		health_challenge_duel_effect = yes
		stress_impact = {
			craven = major_stress_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = 0.5
				ai_rationality = 0.5
			}
		}
	}
	option = {
		name = hold_court.4100.f
		trigger = { has_character_flag = chronic_pain_prejudice }
		health_challenge_duel_effect = yes
		add_martial_lifestyle_xp = minor_lifestyle_xp
		stress_impact = {
			craven = major_stress_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = 0.5
				ai_rationality = 0.5
			}
		}
	}
	option = {
		name = hold_court.4100.g
		add_dread = medium_dread_gain
		scope:prejudiced_vassal = {
			add_trait = maimed
			add_opinion = {
				modifier = hate_opinion
				opinion = -40
				target = root
			}
			hidden_effect = {
				if = {
					limit = {
						can_start_scheme = {
						type = murder
						target = root
						}
					}
					start_scheme = {
						type = murder
						target = root
					}
				}
			}
		}
		stress_impact = {
			compassionate = major_stress_gain
			craven = major_stress_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_vengefulness = 0.75
			}
		}
	}
	option = {
		name = hold_court.4100.h
		trigger = { 
			OR = {
				stress_level >= 2 
				has_character_flag = deformity_prejudice
			}
			NOT = { has_trait = disfigured } #disfigured already has the chance to have 3 options
		}
		stress_impact = {
			confider = major_stress_loss
		}
		if = {
			limit = {
				NOT = { has_trait = depressed_1 }
			}
			add_trait = depressed_1
		}
		else_if = {
			limit = {
				NOT = {
					has_trait = confider
				}
			}
			add_trait = confider
		}
		every_courtier = {
			limit = { 
				has_trait = compassionate 
			}
			custom = all_compassionate_in_the_court
			add_opinion = {
				target = root
				modifier = pity_opinion
				opinion = 15
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = -0.5
				ai_rationality = 0.5
			}
		}
	}

	after = {
		remove_character_flag = deformity_prejudice
		remove_character_flag = speech_prejudice
		remove_character_flag = mental_health_prejudice
		remove_character_flag = chronic_pain_prejudice
		remove_character_flag = disability_prejudice_fallback
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
		scope:prejudiced_vassal = {
			clear_court_event_participation = yes
		}
	}
}

##################################################
# Sanctuary
# based on event by Isabella Welch
# 4200*
##################################################

# Foreign Noble is Usurped and Seeks Sanctuary
hold_court.4200 = {
	type = court_event
	title = hold_court.4200.t 
	desc = hold_court.4200.desc
	theme = diplomacy_foreign_affairs_focus
	# Portrait left in in order to apply outfit tags.
	right_portrait = {
		character = scope:fleeing_noble
		outfit_tags = { beggar_rags }
	}
	court_scene = {
		button_position_character = scope:fleeing_noble
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:fleeing_noble = {
				group = petitioners_group
				animation = shame
			}
		}
	}

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

	weight_multiplier = {
		base = 1

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

	immediate = {
		add_character_flag = {
			flag = had_event_hold_court_4200
		}
		random_neighboring_and_across_water_top_liege_realm = {
			save_scope_as = neighboring_realm
			holder = {
				save_scope_as = neighboring_ruler
				capital_province = {
					save_scope_as = neighboring_province
				}
			}
		}
			
		create_character = {
			location = root.capital_province
			template = generic_noble_character_diplo
			culture = scope:neighboring_province.culture
			faith = scope:neighboring_province.faith
			trait = vengeful
			gender = male
			save_scope_as = fleeing_noble
		}

		if = {
			limit = {
				employs_court_position = cupbearer_court_position
				any_court_position_holder = {
					type = cupbearer_court_position
				}
			}
			random_court_position_holder = {
				type = cupbearer_court_position
				save_scope_as = current_cupbearer
			}
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}
	
#Make them cupbearer
	option = { 
		name = hold_court.4200.a
		trigger = {
			can_appoint_char_to_court_position = {
				CHAR = scope:fleeing_noble
				COURT_POS = cupbearer_court_position
			}
		}
		add_courtier = scope:fleeing_noble
		add_hook = {
			target = scope:fleeing_noble
			type = loyalty_hook
		}
		scope:fleeing_noble = {
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 50
			}
		}
		if = {
			limit = {
				exists = scope:current_cupbearer
			}
			revoke_court_position = {
				recipient = scope:current_cupbearer
				court_position = cupbearer_court_position
			}
		}
		appoint_court_position = {
			recipient = scope:fleeing_noble
			court_position = cupbearer_court_position
		}
		add_diplomacy_lifestyle_xp = medium_lifestyle_xp
		stress_impact = {
			compassionate = major_stress_loss
			generous = medium_stress_loss
			sadistic = medium_stress_gain
			paranoid = major_stress_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = 0.5
			}
		}
	}
	
#Just acccept them into court
	option = {
		name = hold_court.4200.b
		add_courtier = scope:fleeing_noble
		add_hook = {
			target = scope:fleeing_noble
			type = favor_hook
		}
		scope:fleeing_noble = {
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 20
			}
		}
		change_current_court_grandeur = medium_court_grandeur_gain
		stress_impact = {
			just = minor_stress_loss
			compassionate = minor_stress_loss
			generous = minor_stress_loss
			sadistic = minor_stress_gain
			paranoid = medium_stress_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = 0.5
				ai_rationality = 0.5
			}
		}
	}

#Humiliate them, but still accept them
	option = {
		name = hold_court.4200.c
		add_courtier = scope:fleeing_noble
		scope:fleeing_noble = {
			give_nickname = nick_the_footstool
		}
		add_dread = minor_dread_gain
		 scope:fleeing_noble = {
			add_opinion = {
				target = root
				modifier = humiliated_opinion
				opinion = -20
			}
		}
		change_current_court_grandeur = minor_court_grandeur_gain
		stress_impact = {
			sadistic = major_stress_loss
			just = minor_stress_gain
			arbitrary = minor_stress_loss
			compassionate = medium_stress_gain
			generous = medium_stress_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_greed = 0.5
				ai_compassion = -0.5
			}
		}
	}

#Send them away
	option = {
		name = hold_court.4200.d
		scope:fleeing_noble = {
			silent_disappearance_effect = yes
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_honor = -0.5
			}
		}
		stress_impact = {
			compassionate = medium_stress_gain
			wrathful = minor_stress_loss
			generous = medium_stress_gain
		}
	}

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

##################################################
# Dress Me! Dress Me!
# by Isabella Welch
# 4300
##################################################

# Enforcing a dress code at court
hold_court.4300 = {
	type = court_event
	title = hold_court.4300.t 
	desc = hold_court.4300.desc
	theme = diplomacy_majesty_focus
	court_scene = {
		button_position_character = scope:proposing_chancellor
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:proposing_chancellor = {
				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_local_dress_event }
		highest_held_title_tier >= tier_kingdom
		any_vassal = { count >= 12 }
		exists = cp:councillor_chancellor
		cp:councillor_chancellor = {
			is_ai = yes
			has_court_event_flag = no
		}
		NOT = { has_variable = petitioners_dealt_with_count } # must be first event of 3
	}

	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 = {
		add_character_flag = has_had_local_dress_event
		cp:councillor_chancellor = {
			save_scope_as = proposing_chancellor
			court_event_character_flag_effect = yes
		}
		random_vassal = {
			limit = {
				is_ai = yes
				has_court_event_flag = no
				NOT = { is_in_list = vassal_memory_check }
			}
			add_to_list = vassal_memory_check
		}
		random_vassal = {
			limit = {
				is_ai = yes
				has_court_event_flag = no
				NOT = { is_in_list = vassal_memory_check }
			}
			add_to_list = vassal_memory_check
		}
		random_vassal = {
			limit = {
				is_ai = yes
				has_court_event_flag = no
				NOT = { is_in_list = vassal_memory_check }
			}
			add_to_list = vassal_memory_check
		}
		random_vassal = {
			limit = {
				is_ai = yes
				has_court_event_flag = no
				NOT = { is_in_list = vassal_memory_check }
			}
			add_to_list = vassal_memory_check
		}
		random_vassal = {
			limit = {
				is_ai = yes
				has_court_event_flag = no
				NOT = { is_in_list = vassal_memory_check }
			}
			add_to_list = vassal_memory_check
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = {
		name = hold_court.4300.a
		duel = {
			skill = diplomacy
			value = 10
			60 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = hold_court.4300.a.success
				change_current_court_grandeur = minor_court_grandeur_gain
				send_interface_toast = {
					left_icon = root
					title = hold_court.4300.a.success
					add_diplomacy_lifestyle_xp = major_lifestyle_experience
				}
			}
			40 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = hold_court.4300.a.failure
				every_in_list = {
					list = vassal_memory_check
					add_opinion = {
						modifier = forgot_name_opinion
						opinion = -15
						target = root
					}
				}
				send_interface_toast = {
					left_icon = root
					custom_tooltip = hold_court.4300.a.failure
					title = hold_court.4300.b.failure.toast
				}
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_honor = 0.25
				ai_sociability = 0.25
			}
		}
	}

	option = {
		name = hold_court.4300.b
		duel = {
			skill = diplomacy
			value = 10
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = hold_court.4300.b.success
				send_interface_toast = {
					left_icon = root
					title = hold_count.4300.b.success.toast
					every_vassal = {
						custom = all_vassals
						add_character_modifier = {
							modifier = striking_traditional_garb
							years = 10
						}
					}
				}
			}
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = hold_court.4300.b.failure
				if = {
					limit = {
						any_targeting_faction = {
							exists = yes
							NOT = { exists = faction_war }
							NOT = { faction_is_type = peasant_faction }
						}
					}
					add_targeting_factions_discontent = 10
				}
				send_interface_toast = {
					left_icon = root
					title = hold_court.4300.b.failure.toast
					show_as_tooltip = {
						every_vassal = {
							custom = all_vassals
							add_character_modifier = {
								modifier = striking_false_traditional_garb
								years = 10
							}
						}
					}
				}
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_honor = -0.25
				ai_sociability = -0.25
			}
		}
	}

	option = {
		name = hold_court.4300.c
		trigger = {
			trigger_if = {
				limit = {
					is_ai = yes
				}
				short_term_gold >= major_gold_value
			}
		}
		change_current_court_grandeur = medium_court_grandeur_gain
		remove_short_term_gold = medium_gold_value
		stress_impact = {
			arrogant = minor_stress_loss
			humble = medium_stress_gain
		}
		random_list = {
			10 = {
		        create_artifact = {
		            name = honey_colored_gusset
		            description = dress_me_artifact_desc
		            type = miscellaneous
		            visuals = fabric_roll
		            modifier = artifact_placeholder_modifier
		            save_scope_as = dress
		        }
			}
			10 = {
				create_artifact = {
		            name = diamond_studs
		            description = dress_me_artifact_desc
		            type = miscellaneous
		            visuals = fabric_roll
		            modifier = artifact_attraction_opinion_3_modifier
		            save_scope_as = dress
		        }
			}
			10 = {
				create_artifact = {
		            name = purple_girdle
		            description = dress_me_artifact_desc
		            type = miscellaneous
		            visuals = fabric_roll
		            modifier = artifact_prowess_2_modifier
		            save_scope_as = dress
		        }
			}
			10 = {
				create_artifact = {
		            name = mouse_fur_blouse
		            description = dress_me_artifact_desc
		            type = miscellaneous
		            visuals = pelt
		            modifier = artifact_health_gain_1_modifier
		            save_scope_as = dress
		        }
			}
			10 = {
				create_artifact = {
		            name = lavender_placket
		            description = dress_me_artifact_desc
		            type = miscellaneous
		            visuals = fabric_roll
		            modifier = artifact_diplomacy_1_modifier
		            save_scope_as = dress
		        }
			}
			10 = {
				trigger = { is_female = yes }
				create_artifact = {
		            name = pink_brocaded_bodice
		            description = dress_me_artifact_desc
		            type = miscellaneous
		            visuals = fabric_roll
		            modifier = artifact_fertility_gain_1_modifier
		            save_scope_as = dress
		        }
			}
		}
		send_interface_toast = {
			title = hold_court.4300.c.tt
			left_icon = scope:dress
			show_as_tooltip = {
				scope:dress = { set_owner = root }
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_greed = 0.25
				ai_boldness = 0.25
			}
		}
	}

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

##################################################
# Open Carry
# by Isabella Welch
# 4400
##################################################

# Vassals debate on open carry of weapons in towns
hold_court.4400 = {
	type = court_event
	title = hold_court.4400.t 
	desc = hold_court.4400.desc
	theme = martial_authority_focus
	court_scene = {
		button_position_character = scope:wants_safety_vassal
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:wants_safety_vassal = {
				group = petitioners_group
				animation = worry
			}
			scope:wants_weapons_vassal = {
				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_open_carry_event }
		any_vassal = {
			is_ai = yes
			has_court_event_flag = no
			OR = {
				has_trait = reckless
				number_of_commander_traits > 0
				has_trait = wrathful
				has_trait = lifestyle_blademaster
				has_trait = paranoid
				has_trait = sadistic 
			}
			save_temporary_scope_as = same_vassal_check
		}
		any_vassal = {
			is_ai = yes
			has_court_event_flag = no
			OR = {	
				has_trait = craven
				has_trait = just
				has_trait = calm
				has_trait = trusting 
				has_trait = compassionate
			}
			NOT = { this = scope:same_vassal_check }
		}
	}

	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 = {
		add_character_flag = {
			flag = has_had_open_carry_event
			days = 1825
		}
		random_vassal = {
			weight = {
				base = 1
				modifier = {
					factor = 5
					is_powerful_vassal = yes
				}
				modifier = {
					factor = 20
					has_trait = lifestyle_blademaster
				}
				modifier = {
					number_of_commander_traits > 0
					factor = 10
				}
				modifier = {
					is_knight_of = root
					factor = 10
				}
				modifier = {
					has_trait = reckless
					factor = 10
				}
				modifier = {
					has_trait = wrathful
					factor = 10
				}
				modifier = {
					has_trait = paranoid
					factor = 10
				}
				modifier = {
					has_trait = sadistic
					factor = 10
				}
			}
			limit = {
				is_ai = yes
				has_court_event_flag = no
				OR = {
					has_trait = reckless
					number_of_commander_traits > 0
					has_trait = wrathful
					has_trait = lifestyle_blademaster
					has_trait = paranoid
					has_trait = sadistic 
				}
			}
			save_scope_as = wants_weapons_vassal
			court_event_character_flag_effect = yes
		}
		random_vassal = {
			weight = {
				base = 1
				modifier = {
					factor = 5
					is_powerful_vassal = yes
				}
				modifier = {
					factor = -20
					has_trait = lifestyle_blademaster
				}
				modifier = {
					number_of_commander_traits > 0
					factor = -10
				}
				modifier = {
					is_knight_of = root
					factor = -10
				}
				modifier = {
					has_trait = compassionate
					factor = 10
				}
				modifier = {
					has_trait = trusting
					factor = 10
				}
				modifier = {
					has_trait = calm
					factor = 10
				}
				modifier = {
					has_trait = just
					factor = 10
				}
				modifier = {
					has_trait = craven
					factor = 10
				}
			}
			limit = {
				is_ai = yes
				has_court_event_flag = no
				OR = {	
					has_trait = craven
					has_trait = just
					has_trait = calm
					has_trait = trusting 
					has_trait = compassionate
				}
				NOT = { this = scope:wants_weapons_vassal }
			}
			save_scope_as = wants_safety_vassal
			court_event_character_flag_effect = yes
		}
		random_dummy_gender_soldier_effect = { SCOPE_NAME = dummy_gender }
		scope:wants_weapons_vassal = {
			if = {
				limit = {
					NOT = { has_relation_rival = scope:wants_safety_vassal }
				}
				set_relation_rival = {
					target = scope:wants_safety_vassal
					reason = rival_weapon_disagreement
				}
			}
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = { 
		name = hold_court.4400.a
		every_held_county = {
			custom = custom.every_held_county
			add_county_modifier = {
				modifier = county_weapons_ban_in_city_modifier
				years = 50
			}
		}
		scope:wants_safety_vassal = {
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = 20
			}
		}
		stress_impact = {
			reckless = minor_stress_gain
			wrathful = minor_stress_gain
			paranoid = minor_stress_gain
			sadistic = minor_stress_gain
			lifestyle_blademaster = major_stress_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = -0.25
				ai_compassion = 0.25
			}
		}
	}

	option = {
		name = hold_court.4400.b
		every_held_county = {
			custom = custom.every_held_county
			add_county_modifier = {
				modifier = county_weapons_carried_in_city_modifier
				years = 50
			}
		}
		scope:wants_weapons_vassal = {
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = 20
			}
		}
		stress_impact = {
			craven = minor_stress_gain
			just = minor_stress_gain
			calm = minor_stress_gain
			trusting = minor_stress_gain
			compassionate = minor_stress_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = 0.25
				ai_compassion = -0.25
			}
		}
	}
	
	option = {
		name = hold_court.4400.c
		scope:wants_weapons_vassal = {
			duel = {
				skill = prowess
				target = scope:wants_safety_vassal
				10 = {	
					compare_modifier = {
						value = scope:duel_value
						multiplier = 2
					}
					scope:wants_safety_vassal = {
						increase_wounds_effect = { REASON = fight }
					}
					root = {
						every_held_county = {
							custom = custom.every_held_county
							add_county_modifier = {
								modifier = county_weapons_carried_in_city_modifier
								years = 50
							}
						}
						hidden_effect = {
							send_interface_toast =  {
							left_icon = scope:wants_weapons_vassal
							title = hold_court.4400.c1
							custom_tooltip = hold_court.4400.c1.tt
							}
						}
					}
				}
				10 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = -2
					}
					increase_wounds_effect = { REASON = fight }
					root = {
						every_held_county = {
							custom = custom.every_held_county
							add_county_modifier = {
								modifier = county_weapons_ban_in_city_modifier
								years = 50
							}
						}
						hidden_effect = {
							send_interface_toast =  {
							left_icon = scope:wants_safety_vassal
							title = hold_court.4400.c2
							custom_tooltip = hold_court.4400.c2.tt
							}
						}
					}
					
				}
			}
		}
		stress_impact = {
			arbitrary = major_stress_loss
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_vengefulness = 0.75
			}
		}
	}

	after = {
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
		scope:wants_weapons_vassal = {
			clear_court_event_participation = yes
		}
		scope:wants_safety_vassal = {
			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 } }
}
scripted_trigger demanding_poet_attraction_trigger = {
	is_attracted_to_women = yes
}
scripted_trigger demanding_poet_vassal_trigger = {
	age > 8
	is_ai = yes
	has_court_event_flag = no
	NOT = { has_trait = incapable }
	NOT = { government_has_flag = government_is_theocracy }
}

hold_court.4500 = {
	type = court_event
	title = hold_court.4500.t 
	desc = {
		desc = hold_court.4500.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = { 
					OR = {
						has_character_flag = poet_challenges_steward
						has_character_flag = poet_challenges_chancellor
						has_character_flag = poet_challenges_marshal
						has_character_flag = poet_challenges_spymaster
						has_character_flag = poet_challenges_chaplain
					}
				}
				desc = hold_court.4500.council
			}
			triggered_desc = {
				trigger = { has_character_flag = poet_offers_romance }
				desc = hold_court.4500.romance
			}
			triggered_desc = {
				trigger = { has_character_flag = poet_wants_titles }
				desc = hold_court.4500.titles
			}
			triggered_desc = {
				trigger = { has_character_flag = poet_wants_realm }
				desc = hold_court.4500.realm
			}
		}
		desc = hold_court.4500.desc.middle
		first_valid = {
			triggered_desc = {
				trigger = { has_character_flag = poet_challenges_chancellor }
				desc = hold_court.4500.chancellor_2
			}
			triggered_desc = {
				trigger = { has_character_flag = poet_challenges_steward }
				desc = hold_court.4500.steward_2
			}
			triggered_desc = {
				trigger = { has_character_flag = poet_challenges_marshal }
				desc = hold_court.4500.marshal_2
			}
			triggered_desc = {
				trigger = { has_character_flag = poet_challenges_spymaster }
				desc = hold_court.4500.spymaster_2
			}
			triggered_desc = {
				trigger = { has_character_flag = poet_challenges_chaplain }
				desc = hold_court.4500.chaplain_2
			}
			triggered_desc = {
				trigger = { has_character_flag = poet_offers_romance }
				desc = hold_court.4500.romance_2
			}
			triggered_desc = {
				trigger = { has_character_flag = poet_wants_titles }
				desc = hold_court.4500.titles_2
			}
			triggered_desc = {
				trigger = { has_character_flag = poet_wants_realm }
				desc = hold_court.4500.realm_2
			}
		}
		desc = hold_court.4500.desc.end
	}
	theme = learning_scholarship_focus
	lower_left_portrait = scope:secondary_character
	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 = {
		NOT = {
			has_character_flag = has_had_demanding_poet_event
			NOT = { has_free_council_slot = yes }
		}
		OR = {
			AND = {
				exists = cp:councillor_chancellor
				cp:councillor_chancellor = {
					diplomacy <= average_skill_level
					can_be_fired_from_council_trigger = { COURT_OWNER = root }
					has_court_event_flag = no
					is_ai = yes
				}
			}
			AND = {
				exists = cp:councillor_steward
				cp:councillor_steward = {
					stewardship <= average_skill_level
					can_be_fired_from_council_trigger = { COURT_OWNER = root }
					has_court_event_flag = no
					is_ai = yes
				}
			}
			AND = {
				exists = cp:councillor_marshal
				cp:councillor_marshal = {
					martial <= average_skill_level
					can_be_fired_from_council_trigger = { COURT_OWNER = root }
					has_court_event_flag = no
					is_ai = yes
				}
			}
			AND = {
				exists = cp:councillor_spymaster
				cp:councillor_spymaster = {
					intrigue <= average_skill_level
					can_be_fired_from_council_trigger = { COURT_OWNER = root }
					has_court_event_flag = no
					is_ai = yes
				}
			}
			AND = {
				exists = cp:councillor_court_chaplain
				cp:councillor_court_chaplain = {
					learning <= average_skill_level
					can_be_fired_from_council_trigger = { COURT_OWNER = root }
					has_court_event_flag = no
					is_ai = yes
				}
			}
			any_vassal = {
				demanding_poet_vassal_trigger = yes
				has_court_event_flag = no
			}
		}
	}

	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

		random_list = {
			20 = {
				trigger = {
					exists = cp:councillor_chancellor
					cp:councillor_chancellor = { 
						diplomacy <= average_skill_level
						can_be_fired_from_council_trigger = { COURT_OWNER = root }
						has_court_event_flag = no
						is_ai = yes
					}
				}
				modifier  = {
					factor = 20
					cp:councillor_chancellor = {
						diplomacy <= low_skill_rating
					}
				}
				if = {
					limit = { demanding_poet_scripted_gender_trigger = yes }
					create_character = {
						location = root.capital_province
						template = demanding_poet_diplomacy_character
						gender = female
						save_scope_as = demanding_poet
					}
				}
				else = {
					create_character = {
						location = root.capital_province
						template = demanding_poet_diplomacy_character
						gender = male
						save_scope_as = demanding_poet
					}
				}
				add_character_flag = poet_challenges_chancellor
				cp:councillor_chancellor = {
					save_scope_as = secondary_character
					court_event_character_flag_effect = yes
				}
			}
			20 = {
				trigger = {
					exists = cp:councillor_steward
					cp:councillor_steward = {
						stewardship <= average_skill_level
						can_be_fired_from_council_trigger = { COURT_OWNER = root }
						has_court_event_flag = no
						is_ai = yes
					}
				}
				modifier  = {
					factor = 20
					cp:councillor_steward = {
						stewardship <= low_skill_rating
					}
				}
				if = {
					limit = { demanding_poet_scripted_gender_trigger = yes }
					create_character = {
						location = root.capital_province
						template = demanding_poet_stewardship_character
						gender = female
						save_scope_as = demanding_poet
					}
				}
				else = {
					create_character = {
						location = root.capital_province
						template = demanding_poet_stewardship_character
						gender = male
						save_scope_as = demanding_poet
					}
				}
				add_character_flag = poet_challenges_steward
				cp:councillor_steward = {
					save_scope_as = secondary_character
					court_event_character_flag_effect = yes
				}
			}
			20 = {
				trigger = {
					exists = cp:councillor_marshal
					cp:councillor_marshal = {
						martial <= average_skill_level
						can_be_fired_from_council_trigger = { COURT_OWNER = root }
						has_court_event_flag = no
						is_ai = yes
					}
				}
				modifier  = {
					factor = 20
					cp:councillor_marshal = {
						martial <= low_skill_rating
					}
				}
				if = {
					limit = { demanding_poet_scripted_gender_trigger = yes }
					create_character = {
						location = root.capital_province
						template = demanding_poet_martial_character
						gender = female
						save_scope_as = demanding_poet
					}
				}
				else = {
					create_character = {
						location = root.capital_province
						template = demanding_poet_martial_character
						gender = male
						save_scope_as = demanding_poet
					}
				}
				add_character_flag = poet_challenges_marshal
				cp:councillor_marshal = {
					save_scope_as = secondary_character
					court_event_character_flag_effect = yes
				}
			}
			20 = {
				trigger = {
					exists = cp:councillor_spymaster
					cp:councillor_spymaster = {
						intrigue <= average_skill_level
						can_be_fired_from_council_trigger = { COURT_OWNER = root }
						has_court_event_flag = no
						is_ai = yes
					}
				}
				modifier  = {
					factor = 20
					cp:councillor_spymaster = {
						intrigue <= low_skill_rating
					}
				}
				if = {
					limit = { demanding_poet_scripted_gender_trigger = yes }
					create_character = {
						location = root.capital_province
						template = demanding_poet_intrigue_character
						gender = female
						save_scope_as = demanding_poet
					}
				}
				else = {
					create_character = {
						location = root.capital_province
						template = demanding_poet_intrigue_character
						gender = male
						save_scope_as = demanding_poet
					}
				}
				add_character_flag = poet_challenges_spymaster
				cp:councillor_spymaster = {
					save_scope_as = secondary_character
					court_event_character_flag_effect = yes
				}
			}
			20 = {
				trigger = {
					exists = cp:councillor_court_chaplain
					cp:councillor_court_chaplain = {
						learning <= average_skill_level
						can_be_fired_from_council_trigger = { COURT_OWNER = root }
						has_court_event_flag = no
						is_ai = yes
					}
				}
				modifier  = {
					factor = 20
					cp:councillor_court_chaplain = {
						learning <= low_skill_rating
					}
				}
				if = {
					limit = { demanding_poet_scripted_gender_trigger = yes }
					create_character = {
						location = root.capital_province
						template = demanding_poet_learning_character
						gender = female
						save_scope_as = demanding_poet
					}
				}
				else = {
					create_character = {
						location = root.capital_province
						template = demanding_poet_learning_character
						gender = male
						save_scope_as = demanding_poet
					}
				}
				add_character_flag = poet_challenges_chaplain
				cp:councillor_court_chaplain = {
					save_scope_as = secondary_character
					court_event_character_flag_effect = yes
				}
			}
			10 = {
				trigger = {
					exists = root.primary_spouse
					root.primary_spouse = {
						NOT = { has_trait = beauty_good_3 }
						has_court_event_flag = no
					}
					is_ai = yes
				}
				if = {
					limit = { is_attracted_to_women = yes }
					create_character = {
						location = root.capital_province
						template = demanding_poet_lover_character
						gender = female
						save_scope_as = demanding_poet
					}
				}
				else = {
					create_character = {
						location = root.capital_province
						template = demanding_poet_lover_character
						gender = male
						save_scope_as = demanding_poet
					}
				}
				add_character_flag = poet_offers_romance
				primary_spouse = {
					save_scope_as = secondary_character
					court_event_character_flag_effect = yes
				}
			}
			20 = {
				trigger = {
					OR = {
						any_vassal = {
							count >= 1
							is_ai = yes
							has_court_event_flag = no
						}
						has_realm_law = crown_authority_1 
						has_realm_law = crown_authority_2
						has_realm_law = crown_authority_3
					}
					any_vassal = {
						is_ai = yes
						demanding_poet_vassal_trigger = yes
						has_court_event_flag = no
					}
				}
				random_vassal = {
					weight = {
						base = 1
						modifier = {
							has_relation_rival = root
							factor = 5
						}
						modifier = {
							factor = 5
							opinion = {
								target = root
								value <= medium_negative_opinion
							}
						}
						modifier = {
							factor = 20
							is_powerful_vassal = yes
						}
						modifier = {
							factor = 20
							highest_held_title_tier >= tier_kingdom
						}
						modifier = {
							factor = 20
							terrible_sum_of_all_skills_trigger = yes
						}
						modifier = {
							factor = 10
							poor_sum_of_all_skills_trigger = yes
						}
					}
					limit = {
						is_ai = yes
						demanding_poet_vassal_trigger = yes
						has_court_event_flag = no
					}
					save_scope_as = vassal_with_titles
					save_scope_as = secondary_character
					court_event_character_flag_effect = yes
				}
				add_character_flag = poet_wants_titles
				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
					}
				}
			}
			1 = {
				random_councillor = {
					limit = {
						is_ai = yes
						has_court_event_flag = no
					}
					save_scope_as = secondary_character
					court_event_character_flag_effect = yes
				}	
				add_character_flag = poet_wants_realm
				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 = {
			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.a
		change_current_court_grandeur = minor_court_grandeur_loss
		hidden_effect = {
			scope:demanding_poet = {
				death = {
					death_reason = death_vanished
				}
			}
		}
		stress_impact = {
			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
			}
		}
	}

	option = {
		trigger = {
			can_employ_court_position_type = court_poet_court_position
		}
		name = hold_court.4500.b
		change_current_court_grandeur = minor_court_grandeur_gain
		add_courtier = scope:demanding_poet
		replace_existing_position_with_character_in_current_scope_court_effect = {
			CHARACTER = scope:demanding_poet
			POSITION = court_poet_court_position
		}
		if = {
			limit = { has_character_flag = poet_offers_romance }
			set_relation_potential_lover = scope:demanding_poet
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = -0.25
				ai_rationality = 0.75
			}
		}
	}
	
	option = {
		name = hold_court.4500.c
		stress_impact = {
			arbitrary = major_stress_loss
		}
		scope:secondary_character = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -40
			}
		}
		if = {
			limit = {
				has_character_flag = poet_challenges_chancellor
			}
			fire_councillor = cp:councillor_chancellor
			if = {
				limit = { scope:demanding_poet = { NOT = { is_courtier_of = root } } }
				add_courtier = scope:demanding_poet
			}
			root = {
				assign_councillor_type = {
					type = councillor_chancellor
					target = scope:demanding_poet
				}
			}
		}
		else_if = {
			limit = {
				has_character_flag = poet_challenges_spymaster
			}
			root = { fire_councillor = cp:councillor_spymaster }
			if = {
				limit = { scope:demanding_poet = { NOT = { is_courtier_of = root } } }
				add_courtier = scope:demanding_poet
			}
			root = {
				assign_councillor_type = {
					type = councillor_spymaster
					target = scope:demanding_poet
				}
			}	
		}
		else_if = {
			limit = {
				has_character_flag = poet_challenges_chaplain
			}
			root = { fire_councillor = cp:councillor_court_chaplain }
			if = {
				limit = { scope:demanding_poet = { NOT = { is_courtier_of = root } } }
				add_courtier = scope:demanding_poet
			}
			scope:demanding_poet = {
				assign_councillor_type = {
					type = councillor_court_chaplain
					target = root
				}
			}
		}
		else_if = {
			limit = {
				has_character_flag = poet_challenges_marshal
			}
			root = { fire_councillor = cp:councillor_marshal }
			if = {
				limit = { scope:demanding_poet = { NOT = { is_courtier_of = root } } }
				add_courtier = scope:demanding_poet
			}
			root = {
				assign_councillor_type = {
					type = councillor_marshal
					target = scope:demanding_poet
				}
			}
		}
		else_if = {
			limit = {
				has_character_flag = poet_challenges_steward
			}
			root = { fire_councillor = cp:councillor_steward }
			if = {
				limit = { scope:demanding_poet = { NOT = { is_courtier_of = root } } }
				add_courtier = scope:demanding_poet
			}
			root = {
				assign_councillor_type = {
					type = councillor_steward
					target = scope:demanding_poet
				}
			}		
		}
		else_if = {
			limit = {
				has_character_flag = poet_wants_titles
			}
			custom_tooltip = hold_court.4500.c.titles.tt
			hidden_effect = {
				scope:secondary_character = {
					every_held_title = {
						limit = {
							tier >= tier_county
						}
						add_to_list = stolen_vassal_titles
					}
					every_vassal = {
						add_to_list = stolen_vassals_for_poet
					}
					add_opinion = {
						target = scope:demanding_poet
						modifier = usurped_title
					}
				}
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = title_change_vassal
					add_claim_on_loss = yes
				}
				every_in_list = {
					list = stolen_vassal_titles
					change_title_holder = {
						holder = scope:demanding_poet
						change = scope:title_change_vassal
						take_baronies = no
					}
				}
				every_in_list = {
					list = stolen_vassals_for_poet
					change_liege = {
						liege = scope:demanding_poet
						change = scope:title_change_vassal
					}
				}
				resolve_title_and_vassal_change = scope:title_change_vassal
			}
		}
		else_if = {
			limit = {
				has_character_flag = poet_offers_romance
			}
			set_relation_lover = { reason = lover_poet_demand target = scope:demanding_poet }
			expose_lover_secret_or_run_consequence_effect = {
				TARGET = scope:demanding_poet
				EXPOSER = root
			}
			if = {
				limit = { scope:demanding_poet = { NOT = { is_courtier_of = root } } }
				add_courtier = scope:demanding_poet
			}
		}
		else_if = {
			limit = {
				has_character_flag = poet_wants_realm
			}
			custom_tooltip = hold_court.4500.c.realm.tt
			hidden_effect = {
				primary_title = {
					add_to_list = titles_to_give
					every_in_de_facto_hierarchy = {
						this.holder = {
							add_to_list = vassals_to_reassign
						}
					}
				}
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = title_change_realm
					add_claim_on_loss = yes
				}
				every_in_list = {
					list = titles_to_give
					change_title_holder = {
						holder = scope:demanding_poet
						change = scope:title_change_realm
						take_baronies = no
					}
				}
				every_in_list = {
					list = vassals_to_reassign
					change_liege = {
						liege = scope:demanding_poet
						change = scope:title_change_realm
					}
				}
				root = {
					change_liege = {
						liege = scope:demanding_poet
						change = scope:title_change_realm
					}
				} 
				resolve_title_and_vassal_change = scope:title_change_realm
			}
		}
		ai_chance = {
			base = 5
			ai_value_modifier = {
				ai_boldness = 0.25
				ai_rationality = -0.75
			}
			#AGOT Added
			modifier = {
				OR = {
					has_character_flag = poet_wants_titles
					has_character_flag = poet_wants_realm
				}
				factor = 0
			}
		}
	}
	after = {
		scope:demanding_poet = {
            clear_court_event_participation = yes
        }
        scope:secondary_character = {
            clear_court_event_participation = yes
        }
		remove_character_flag = poet_challenges_chancellor
		remove_character_flag = poet_challenges_spymaster
		remove_character_flag = poet_challenges_chaplain
		remove_character_flag = poet_challenges_marshal
		remove_character_flag = poet_challenges_steward
		remove_character_flag = poet_wants_titles 
		remove_character_flag = poet_offers_romance
		remove_character_flag = poet_wants_realm
		# 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
			dread >= high_dread
			has_trait = sadistic
			any_secret = {
				secret_type = secret_witch
			}
		}
		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
		add_prestige = medium_prestige_gain
		duel = {
			skill = intrigue
			target = scope:challenger_peasant
			60 = {		
				compare_modifier = {
					value = scope:duel_value
					multiplier = 2
					min = -49
				}
				desc = hold_court.4600.a.success
				change_current_court_grandeur = minor_court_grandeur_gain
				send_interface_toast = {
					left_icon = root
					title = hold_court.4600.a.success
					show_as_tooltip = {
						add_intrigue_lifestyle_xp = medium_lifestyle_experience
					}
				}
				every_held_county = {
					custom = custom.every_held_county
					add_county_modifier = {
						modifier = county_confident_in_humanity_modifier
						years = 25
					}
				}
			}
			40 = {		
				compare_modifier = {
					value = scope:duel_value
					multiplier = -2
					min = -49
				}
				desc = hold_court.4600.a.failure
				hidden_effect = {
					send_interface_toast = {
						left_icon = root
						title = hold_court.4600.a.failure
						show_as_tooltip = {
							every_held_county = {
								custom = custom.every_held_county
								add_county_modifier = {
									modifier = county_superstitious_of_ruler_modifier
									years = 25
								}
							}
						}
					}
				}
				every_held_county = {
					custom = custom.every_held_county
					add_county_modifier = {
						modifier = county_superstitious_of_ruler_modifier
						years = 25
					}
				}
			}
		}
		ai_chance = {
			base = 75
			ai_value_modifier = {
				ai_boldness = 0.25
				ai_rationality = 0.75
			}
		}
	}

	option = {
		name = hold_court.4600.b
		trigger = {
			NOT = { 
				is_cannibal_trigger = yes
				has_trait = witch 
			}
		}
		add_dread = massive_dread_gain
		if = {
			limit = {
				any_vassal_or_below = {
					is_ai = yes
					OR = {
						has_trait = cannibal
						any_secret = { secret_type = secret_cannibal }
					}
				}
			}
			random_vassal_or_below = {
				limit = {
					is_ai = yes
					has_court_event_flag = no
					OR = {
						has_trait = cannibal
						any_secret = { 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
		add_piety = medium_piety_loss
		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
		stress_impact = {
				confider = medium_stress_loss
			}
		if = {
			limit = { has_trait = sadistic }
			remove_trait = sadistic
		}
		else_if = {
			limit = { has_trait = callous }
			remove_trait = callous
		}
		if = {
			limit = {
				number_of_traits <= 3
			}
			add_trait = compassionate
		}
		every_held_county = {
			custom = custom.every_held_county
			add_county_modifier = {
				modifier = county_confident_in_humanity_modifier
				years = 25
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = -0.25
				ai_rationality = 0.75
				ai_honor = 0.5
			}
		}
	}

	option = {
		name = hold_court.4600.d
		trigger = {
			any_secret = {
				secret_type = secret_witch
			}
		}
		trait = witch
		add_dread = major_dread_gain
		if = {
			limit = { trait_is_criminal_in_faith_trigger = { TRAIT = witch FAITH = root.faith GENDER_CHARACTER = root } }
			add_piety = medium_piety_loss
		}
		duel = {
			skill = intrigue
			value = 10
			55 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 2.5
					min = -49
				}
				desc = hold_court.4600.d.success
				hidden_effect = {
					send_interface_toast = {
						left_icon = root
						title = hold_court.4600.d.success
						show_as_tooltip = {
							add_intrigue_lifestyle_xp = medium_lifestyle_experience
							every_courtier_or_guest = {
								custom = all_courtiers_and_guests
								add_opinion = {
									target = root
									modifier = humorous_opinion
								}
							}
						}
					}
				}
				add_intrigue_lifestyle_xp = medium_lifestyle_experience
				every_courtier_or_guest = {
					custom = all_courtiers_and_guests
					add_opinion = {
						target = root
						modifier = humorous_opinion
					}
				}
			}
			45 = {		
				compare_modifier = {
					value = scope:duel_value
					multiplier = -2.5
					min = -49
				}
				desc = hold_court.4600.a.failure
				hidden_effect = {
					send_interface_toast = {
						left_icon = root
						title = hold_court.4600.d.failure
						show_as_tooltip = {
							every_courtier_or_guest = {
								custom = all_courtiers_and_guests
								add_opinion = {
									target = root
									modifier = scared_opinion
									opinion = -5
								}
							}
						}
					}	
				}
				
				every_courtier_or_guest = {
					custom = all_courtiers_and_guests
					add_opinion = {
						target = root
						modifier = scared_opinion
						opinion = -5
					}
				}
			}
		}
		ai_chance = {
			base = 15
			ai_value_modifier = {
				ai_boldness = 0.25
				ai_rationality = -0.75
			}
		}
	}

	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 = {
						secret_type = secret_cannibal
						NOT = { any_secret_knower = { this = root } }
					}
				}
				random_secret = {
					limit = { 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
		add_opinion = {
			target = scope:cannibal_vassal
			opinion = -20
			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
			}
		}
	}
}

##################################################
# An End to Agony
# by Isabella Welch
# 4700
##################################################

scripted_trigger imprisoned_family_vassal_trigger = {
	has_court_event_flag = no
	NOR = {
		has_trait = sadistic
		has_trait = torturer
	}
	age > 8
	OR = {
		has_opinion_modifier = {
			target = root
			modifier = imprisoned_family_member
		}
		has_opinion_modifier = {
			target = root
			modifier = tortured_family_member
		}
		has_opinion_modifier = {
			target = root
			modifier = family_moved_to_dungeon_opinion
		}
	}
	any_close_family_member = {
		has_court_event_flag = no
		is_ai = yes
		is_imprisoned_by = root
		is_in_prison_type = dungeon
	}
}

# Vassals discuss the state of prisons in the realm
hold_court.4700 = {
	type = court_event
	title = hold_court.4700.t 
	desc = {
		desc = hold_court.4700.desc
		first_valid = {
			triggered_desc = {
				trigger = { has_character_flag = has_moldy_gruel }
				desc = hold_court.4700.desc.gruel
			}
			triggered_desc = {
				trigger = { has_character_flag = default_prison_loc }
				desc = hold_court.4700.desc.default
			}
		}
		desc = hold_court.4700.desc.2
	}
	theme = intrigue_intimidation_focus
	lower_right_portrait = scope:imprisoned_family_character
	court_scene = {
		button_position_character = scope:prison_challenger_vassal
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:prison_challenger_vassal = {
				group = petitioners_group
				animation = shame
			}
		}
	}

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

	trigger = {
		NOT = { has_character_flag = has_had_prison_condition_event }
		any_vassal = {
			imprisoned_family_vassal_trigger = yes
		}
	}

	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 = {
		add_character_flag = has_had_prison_condition_event
		random_vassal = {
			limit = {
				imprisoned_family_vassal_trigger = yes
			}
			save_scope_as = prison_challenger_vassal
			court_event_character_flag_effect = yes
		}
		scope:prison_challenger_vassal = {
			random_close_family_member = {
				limit = {
					is_ai = yes
					is_in_prison_type = dungeon
					is_imprisoned_by = root
					has_court_event_flag = no
				}
				save_scope_as = imprisoned_family_character
				court_event_character_flag_effect = yes
			}
		}
		random_list = {
			1 = {
				add_character_flag = has_moldy_gruel
				modifier = {
					factor = 10
					has_trait = arbitrary
				}
			}
			10 = {
				add_character_flag = default_prison_loc
			}
		}
		add_gold = medium_gold_value
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = { 
		name = hold_court.4700.a
		trigger =  { 
			NOR = { 
				has_character_flag = has_moldy_gruel 
				has_trait = torturer
				has_trait = sadistic
			}
		}
		add_dread = medium_dread_gain
		scope:prison_challenger_vassal = {
			add_opinion = {
				opinion = -15
				modifier = cruelty_opinion
				target = root
			}
		}
		stress_impact = {
			compassionate = major_stress_gain
			trusting = major_stress_gain
		}
		ai_chance = {
			base = 75
			ai_value_modifier = {
				ai_rationality = 0.75
				ai_vengefulness = 0.75
				ai_compassion = -0.75
			}
		}
	}

	option = {
		name = hold_court.4700.b
		trigger = {
			trigger_if = {
				limit = {
					is_ai = yes
				}
				short_term_gold >= major_gold_value
			}
			OR = {
				age < 25
				primary_title = { title_held_years <= 5 } 
			}
		}
		custom_tooltip = hold_court.4700.d.tt
		add_character_modifier = {
			modifier = overturned_old_barbarity
			years = 5		
		}
		set_variable = {
			name = reformed_dungeon
			value = 1
		}
		remove_short_term_gold = medium_gold_value
		ai_chance = {
			base = 75
			ai_value_modifier = {
				ai_sociability = 0.75
				ai_vengefulness = -0.75
				ai_compassion = 0.75
			}
		}
	}
	
	option = {
		name = hold_court.4700.c
		trigger = {
			trigger_if = {
				limit = {
					is_ai = yes
				}
				short_term_gold >= major_gold_value
			}
			OR = {
				has_trait = torturer
				has_trait = sadistic
			}
		}
		custom_tooltip = hold_court.4700.c.tt
		trait = torturer
		trait = sadistic
		add_dread = medium_dread_gain
		set_variable = {
			name = neglected_dungeon
			value = 1
		}
		remove_short_term_gold = medium_gold_value
	}

	option = {
		name = hold_court.4700.d
		trigger = {
			NOR = {
				age < 25
				primary_title = { title_held_years <= 5 } 
			}
		}
		custom_tooltip = hold_court.4700.d.tt
		set_relation_friend = { reason = friend_renovate_dungeons target = scope:prison_challenger_vassal }
		stress_impact = {
			vengeful = major_stress_gain
			sadistic = major_stress_gain
			wrathful = major_stress_gain
			paranoid = major_stress_gain
		}
		set_variable = {
			name = reformed_dungeon
			value = 1
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_vengefulness = 0.75
				ai_compassion = -0.75
			}
		}
	}

	option = {
		name = hold_court.4700.e
		trigger =  { has_character_flag = has_moldy_gruel }
		add_character_flag = {
			flag = enjoys_moldy_gruel
			years = 5
		} 
		stress_impact = {
			arbitrary = minor_stress_loss
		}
		scope:prison_challenger_vassal = {
			add_opinion = {
				target = root
				opinion = -15
				modifier = disgusted_opinion
			}
		}
		every_prisoner = {
			custom = all_in_dungeon
			limit = {
				is_in_prison_type = dungeon
				NOT = { has_trait = inappetetic }
			}
			add_trait = inappetetic
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_rationality = -0.75
			}
		}
	}

	after = {
		remove_character_flag = has_moldy_gruel
		remove_character_flag = default_prison_loc
		scope:prison_challenger_vassal = {
            clear_court_event_participation = yes
		}
		scope:imprisoned_family_character = {
            clear_court_event_participation = yes
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

##################################################
# I Should Like a Veal Cutlet
# by Isabella Welch
# 4800
##################################################

# Prisoner escapes house arrest, demands fancy dinner
hold_court.4800 = {
	type = court_event
	title = hold_court.4800.t 
	desc = hold_court.4800.desc
	theme = prison
	lower_left_portrait = scope:incompetent_guard
	court_scene = {
		button_position_character = scope:escaped_prisoner
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:escaped_prisoner = {
				group = petitioners_group
				animation = personality_greedy
			}
		}
	}

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

	cooldown = { years = 5 }
	
	trigger = {
		any_prisoner = {
			has_court_event_flag = no
			is_ai = yes
			is_in_prison_type = house_arrest
			NOT = {
				has_trait = craven
				has_trait = incapable
			}
			age > 3
		}
		any_knight = {
			is_ai = yes
            has_court_event_flag = no		
			prowess <= medium_skill_rating
			is_physically_able_adult = yes
			is_landed = no
		}
	}

	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 = {
		random_prisoner = {
			limit = {
				is_ai = yes
	            has_court_event_flag = no		
				is_in_prison_type = house_arrest
				NOT = { 
					has_trait = craven
					has_trait = incapable
				}
				age > 3
			}
			weight = {
				base = 1
				modifier = {
					has_trait = lazy
					factor = 20
				}
				modifier = {
					has_trait = brave
					factor = 20
				}
				modifier = {
					has_trait = greedy
					factor = 20
				}
				modifier = {
					has_trait = gregarious
					factor = 10
				}
				modifier = {
					has_education_diplomacy_trigger = yes
					factor = 20
				}
				compare_modifier = {
					value = diplomacy
					multiplier = 0.2
				}
				compare_modifier = {
					value = health
					multiplier = 0.1
				}
				compare_modifier = {
					value = age
					multiplier = -0.1
				}
			}
			save_scope_as = escaped_prisoner
			court_event_character_flag_effect = yes
		}
		random_knight = {
			limit = {
				is_ai = yes
	            has_court_event_flag = no		
				prowess <= medium_skill_rating
				is_physically_able_adult = yes
				is_landed = no
			}
			weight = {
				base = 1
				compare_modifier = {
					value = prowess
					multiplier = -0.5
				}
			}
			save_scope_as = incompetent_guard
			court_event_character_flag_effect = yes
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = { 
		name = hold_court.4800.a
		change_current_court_grandeur = minor_court_grandeur_gain
		scope:escaped_prisoner = {	
			add_opinion = {
				target = root
				modifier = kindness_opinion
				opinion = 20
			}
		}
		if = {
			limit = {
				NOT = { has_relation_friend = scope:escaped_prisoner }
			}
			set_relation_friend = { reason = friend_sheer_audacity target = scope:escaped_prisoner }
		}
		stress_impact = {
			greedy = medium_stress_gain
			patient = minor_stress_gain
			paranoid = minor_stress_gain
			callous = minor_stress_gain
		}
		ai_chance = {
			base = 75
			ai_value_modifier = {
				ai_rationality = -0.25
				ai_vengefulness = -0.75
				ai_compassion = 0.75
			}
		}
	}

	option = {
		name = hold_court.4800.b
		trigger = { has_character_flag = enjoys_moldy_gruel }
		add_dread = minor_dread_gain
		every_prisoner = {
			custom = all_in_house_arrest
			limit = {
				is_in_prison_type = house_arrest
			}
			add_character_modifier = {
				modifier = moldy_gruel_diet
			}
		}
		scope:escaped_prisoner = {	
			add_opinion = {
				target = root
				modifier = disgusted_opinion
				opinion = -20
			}
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_boldness = 0.75
				ai_vengefulness = 0.75
				ai_compassion = -0.75
			}
		}
	}
	
	option = {
		name = hold_court.4800.c
		custom_tooltip = hold_court.4800.c.tt
		every_prisoner = {
			custom = all_in_house_arrest
			limit = {
				is_in_prison_type = house_arrest
			}
			add_character_modifier = {
				modifier = allowed_to_go_outside
			}
		}
		every_courtier = {
			custom = all_compassionate_in_the_court
			limit = { has_trait = compassionate }
			add_opinion = {
				target = root
				modifier = kindness_opinion
				opinion = 5
			}
		}
		add_dread = minor_dread_loss
		ai_chance = {
			base = 15
			ai_value_modifier = {
				ai_compassion = 0.75
			}
		}
	}

	option = {
		name = hold_court.4800.d
		custom_tooltip = hold_court.4800.d.tt
		trigger = { NOT = { has_character_flag = enjoys_moldy_gruel } }
		scope:incompetent_guard = {
			add_opinion = {
				target = root
				modifier = banned_from_knight_force
				opinion = -15
			}
			hidden_effect = { set_knight_status = forbid }
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_rationality = 0.75
				ai_vengefulness = 0.75
			}
		}
	}

	option = {
		name = hold_court.4800.e
		trigger = {
			OR = {
				has_trait = wrathful
				has_trait = sadistic
				has_trait = vengeful
				has_trait = torturer
			}
		}
		scope:escaped_prisoner = {
			change_prison_type = dungeon	
			add_opinion = {
				target = root
				modifier = disgusted_opinion
				opinion = -20
			}
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_zeal = 0.75
				ai_vengefulness = 0.75
				ai_compassion = -0.25
			}
		}
	}

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

##################################################
# 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
				exists = mother
				mother = {
					exists = mother
					mother = {
						exists = mother
						mother = {
							exists = mother
							mother = {
								exists = mother
							}
						}
					}
				}
			}
			AND = {
				is_male = yes
				exists = father
				father = {
					exists = father
					father = {
						exists = father
						father = {
							exists = 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 }
		claim_throne_set_mythical_founder_variable_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.a
		trigger = {
			root.dynasty = { 
				dynasty_prestige_level >= low_dynasty_prestige_level
				dynasty_prestige_level < high_dynasty_prestige_level 
			}
		}
		stress_impact = {
			humble = major_stress_gain
		}
		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 }
		stress_impact = {
			humble = major_stress_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

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

##################################################
# Unhappy Match
# by Linnéa Thimrén
# 5001 - 5009
##################################################

# Someone dissatisfied with their betrothal asks you to break it off
scripted_trigger hold_court_5001_unhappy_betrothed_trigger = {
	is_imprisoned = no
	is_ai = yes
	has_court_event_flag = no
	is_commanding_army = no
	NOT = { has_trait = incapable }
	age >= 12
	opinion = {
		target = betrothed
		value <= -20
	}
}

scripted_trigger hold_court_5001_betrothed_trigger = {
	has_court_event_flag = no
	is_betrothed = yes
	is_ai = yes
	number_of_personality_traits_in_common = {
		target = betrothed
		value <= 2
	}
	#To not ruin things for other players
	betrothed = { is_ai = yes }
	matchmaker = {
		NOT = { this = prev }
		OR = {
			this = root
			is_ai = yes
		}
	}
	#At least one of them is unhappy with the match
	OR = {
		hold_court_5001_unhappy_betrothed_trigger = yes
		betrothed = {
			hold_court_5001_unhappy_betrothed_trigger = yes
		}
	}
}

scripted_trigger hold_court_5001_horrible_betrothed_trigger = {
	OR = {
		has_trait = murderer
		has_trait = incestuous
		has_trait = sodomite
		has_trait = cannibal
		has_trait = deviant
		has_trait = kinslayer
		has_trait = adulterer
		has_trait = fornicator
		has_trait = maimed
		has_trait = drunkard
		has_trait = hashishiyah
		has_trait = flagellant
		num_of_bad_genetic_traits >= 1
		num_sinful_traits >= 2
	}
	betrothed = { age >= 12 }
	is_ai = yes
	has_court_event_flag = no
}

hold_court.5001 = {
	type = court_event
	title = hold_court.5001.t
	desc = {
		desc = hold_court.5001.desc_opening
		first_valid = {
			triggered_desc = {
			    trigger = {
					scope:complainer_betrothed = {
						OR = {
							has_trait = murderer
							has_trait = incestuous
							has_trait = sodomite
							has_trait = cannibal
							has_trait = deviant
							has_trait = kinslayer
							has_trait = adulterer
							has_trait = fornicator
						}
					}
			    }
			    desc = hold_court.5001.desc_bad_fame
			}
			triggered_desc = {
			    trigger = {
					scope:complainer_betrothed = {
						OR = {
							has_trait = drunkard
							has_trait = hashishiyah
							has_trait = flagellant
						}
					}
			    }
			    desc = hold_court.5001.desc_bad_habits
			}
			triggered_desc = {
			    trigger = {
					scope:complainer_betrothed = {
						has_contagious_disease_trigger = yes
					}
			    }
			    desc = hold_court.5001.desc_bad_health
			}
			triggered_desc = {
			    trigger = {
					scope:complainer_betrothed = {
						num_of_bad_genetic_traits >= 1
					}
			    }
			    desc = hold_court.5001.desc_bad_genes
			}
			triggered_desc = {
			    trigger = {
					scope:complainer_betrothed = {
						num_sinful_traits >= 2
					}
			    }
			    desc = hold_court.5001.desc_bad_traits
			}
			desc = hold_court.5001.desc_fallback_1
		}
		desc = hold_court.5001.desc_quirk
		first_valid = {
			triggered_desc = {
			    trigger = {
					scope:complainer_betrothed = {
						OR = {
							has_trait = maimed
							has_trait = blind
							has_trait = beauty_bad
							has_trait = hunchbacked
							has_trait = dwarf
							has_trait = spindly
							has_trait = scaly
							has_trait = albino
							has_trait = one_eyed
						}
					}
			    }
			    desc = hold_court.5001.desc_ugly
			}
			triggered_desc = {
			    trigger = {
					scope:complainer = {
						age < scope:complainer_betrothed.age_minus_25
					}
			    }
			    desc = hold_court.5001.desc_old
			}
			triggered_desc = {
			    trigger = {
					scope:complainer = {
						age > scope:complainer_betrothed.age_plus_25
					}
			    }
			    desc = hold_court.5001.desc_young
			}
			desc = hold_court.5001.desc_fallback_2
		}
		desc = hold_court.5001.desc_ending
	}
	theme = realm
	override_sound = { reference = event:/SFX/Events/Themes/sfx_event_theme_type_generic }
	lower_left_portrait = scope:complainer_betrothed
	court_scene = {
		button_position_character = scope:complainer
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:complainer = {
				group = petitioners_group
				animation = sadness
			}
		}
	}
	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_5001 }
		OR = {
			any_vassal = {
				hold_court_5001_betrothed_trigger = yes
			}
			any_courtier = {
				hold_court_5001_betrothed_trigger = yes
			}
		}
	}

	weight_multiplier = {
		base = 1
		modifier = { #More likely if they're a very bad match 
			add = 1
			OR = {
				any_vassal = {
					hold_court_5001_betrothed_trigger = yes
					betrothed = { save_temporary_scope_as = compare_character }
					has_any_bad_relationship_with_character_trigger = { CHARACTER = scope:compare_character }
					has_a_personality_trait_opposite_to_compare_character_trigger = yes
				}
				any_courtier = {
					hold_court_5001_betrothed_trigger = yes
					betrothed = { save_temporary_scope_as = compare_character }
					has_any_bad_relationship_with_character_trigger = { CHARACTER = scope:compare_character }
					has_a_personality_trait_opposite_to_compare_character_trigger = yes
				}
			}
		}
		modifier = { #More likely if someone horrible is involved in the match
			add = 2
			OR = {
				any_vassal = {
					hold_court_5001_betrothed_trigger = yes
					OR = {
						hold_court_5001_horrible_betrothed_trigger = yes
						betrothed = {
							hold_court_5001_horrible_betrothed_trigger = yes
						}
					}
				}
				any_courtier = {
					hold_court_5001_betrothed_trigger = yes
					OR = {
						hold_court_5001_horrible_betrothed_trigger = yes
						betrothed = {
							hold_court_5001_horrible_betrothed_trigger = yes
						}
					}
				}
			}
		}
		modifier = { #Much less likely if the characters involved were supposed to get a grand wedding: you can't break that off with no consequences!
			OR = {
				any_vassal = {
					hold_court_5001_betrothed_trigger = yes
					has_been_promised_grand_wedding = yes
				}
				any_courtier = {
					hold_court_5001_betrothed_trigger = yes
					has_been_promised_grand_wedding = yes
				}
			}
			factor = 0.2
		}

		# 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 = {
		add_character_flag = {
			flag = had_event_hold_court_5001
			years = 10
		}
		
		if = {
			limit = {
				any_vassal = {
					hold_court_5001_betrothed_trigger = yes
				}
			}
			every_vassal = {
				limit = {
					hold_court_5001_betrothed_trigger = yes
				}
				add_to_list = possible_complainers
			}
		}
		if = {
			limit = {
				any_courtier = {
					hold_court_5001_betrothed_trigger = yes
				}
			}
			every_courtier = {
				limit = {
					hold_court_5001_betrothed_trigger = yes
				}
				add_to_list = possible_complainers
			}
		}

		random_in_list = {
			list = possible_complainers
			limit = {
				hold_court_5001_betrothed_trigger = yes
				OR = {
					betrothed = { hold_court_5001_horrible_betrothed_trigger = yes }
					hold_court_5001_horrible_betrothed_trigger = yes
				}
			}
			alternative_limit = {
				hold_court_5001_betrothed_trigger = yes
				betrothed = { save_temporary_scope_as = compare_character }
				has_any_bad_relationship_with_character_trigger = { CHARACTER = scope:compare_character }
				has_a_personality_trait_opposite_to_compare_character_trigger = yes
			}
			alternative_limit = {
				hold_court_5001_betrothed_trigger = yes
			}
			weight = {
				base = 1
				modifier = {
					NOT = { is_attracted_to_gender_of = betrothed }
					add = 2
				}
				modifier = {
					OR = {
						age > betrothed.age_plus_25
						age < betrothed.age_minus_25
					}
					add = 2
				}
			}
			#Who is the (most) unhappy one in the match?
			if = {
				limit = {
					hold_court_5001_unhappy_betrothed_trigger = yes
				}
				save_scope_as = complainer
				betrothed = {
					save_scope_as = complainer_betrothed
				}
			}
			else = {
				betrothed = {
					save_scope_as = complainer
		        }
				save_scope_as = complainer_betrothed
			}
		}
		scope:complainer_betrothed = {
			assign_quirk_effect = yes
	 		court_event_character_flag_effect = yes		
		}

		#To save down scopes so the take vows triggers and effects works properly
		scope:complainer = {
			save_scope_as = recipient
			court_event_character_flag_effect = yes
		}
		save_scope_as = actor
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}


	option = { #Ok, you are free of them
		trigger = {
			NOR = {
				scope:complainer = {
					has_been_promised_grand_wedding = yes
				}
				scope:complainer_betrothed = {
					has_been_promised_grand_wedding = yes
				}
			}
		}
		name = hold_court.5001.a
		scope:complainer = {
			break_betrothal = scope:complainer_betrothed
		}
		if = {
			limit = {
				can_add_hook = {
					target = scope:complainer
					type = favor_hook
				}
			}
			add_hook = {
				type = favor_hook
				target = scope:complainer
				days = default_favor_duration
			}
		}
		scope:complainer_betrothed = {
			add_opinion = {
				target = root
				modifier = broke_betrothal_opinion
			}
			hidden_effect = { #TO block that you just re-form the betrothal straight after this
				add_opinion = {
					modifier = divorced_me_opinion
					target = scope:complainer
				}
			}
		}
	}

	option = { #Nah, you're stuck
		name = {
			trigger = { always = yes }
			text = hold_court.5001.b
		}
		name = {
			trigger = {
				any_close_family_member = { this = scope:complainer_betrothed }
			}
			text = hold_court.5001.b_close_family
		}
		
		scope:complainer = {
			add_opinion = {
				modifier = refusal_opinion
				target = root
				opinion = -40
			}
			hidden_effect = {
				if = {
					limit = {
						can_set_relation_potential_rival_trigger = { CHARACTER = root }
					}
					set_relation_potential_rival = root
				}
			}
		}
		stress_impact = {
			compassionate = medium_stress_impact_gain
		}
	}

	option = { #Well, now you'll never marry!!
		name = hold_court.5001.c
		trigger = {
			scope:complainer = {
				can_take_religious_vows_disregard_marriage_trigger = yes
			}
		}
		send_child_to_clergy_effect = yes
		
		scope:complainer = {
			if = {
				limit = {
					root.top_liege = {
						any_vassal_or_below = {
							government_has_flag = government_is_theocracy
							primary_title.tier > tier_barony
							faith = root.faith
						}
					}
				}
				root.top_liege = {
					random_vassal_or_below = {
						limit = {
							government_has_flag = government_is_theocracy
							primary_title.tier > tier_barony
							faith = root.faith
						}
						save_scope_as = theocratic_travel_target
					}
				}
				visit_court_of = scope:theocratic_travel_target
			}
			else_if = {
				limit = {
					exists = root.capital_province
				}
				move_to_pool_at = root.capital_province
			}
			kick_from_court_interaction_warning_tooltip_effect = yes
			add_opinion = {
				modifier = refusal_opinion
				target = root
				opinion = -40
			}
			hidden_effect = {
				if = {
					limit = {
						can_set_relation_potential_rival_trigger = { CHARACTER = root }
					}
					set_relation_potential_rival = root
				}
			}
		}
		if = {
			limit = {
				exists = cp:councillor_court_chaplain
				scope:complainer = {
					is_close_family_of = root
				}
			}
			cp:councillor_court_chaplain = {
				add_opinion = {
					target = root
					modifier = pious_opinion
					opinion = 25
				}
			}
		}
		if = {
			limit = {
				exists = faith.religious_head
				scope:recipient = {
					is_close_family_of = root
				}
			}
			faith.religious_head = {
				add_opinion = {
					target = root
					modifier = pious_opinion
					opinion = 10
				}
			}
		}
		stress_impact = {
			zealous = medium_stress_impact_loss
			sadistic = medium_stress_impact_loss
			compassionate = minor_stress_impact_gain
		}
	}

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

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

# Low control - peasants petition you to please make your marshal stop hanging people
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
		}
		first_valid = {
			triggered_desc = {
			    trigger = {
					exists = scope:vassal
			    }
			    desc = hold_court.5010.desc_vassal_holder
			}
			desc = hold_court.5010.desc_holder
		}
	}
	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 = cp:councillor_marshal
				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 = {
				NOT = { 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 calm down with the violence
		name = hold_court.5010.a
		if = {
			limit = {
				exists = scope:marshal
			}
			custom_tooltip = hold_court.5010.a_tt_marshal
			scope:marshal = {
				add_opinion = {
					target = root
					modifier = insult_opinion
					opinion = -20
				}
			}
		}
		else_if = {
			limit = {
				exists = scope:vassal
			}
			custom_tooltip = hold_court.5010.a_tt_vassal
			scope:vassal = {
				add_opinion = {
					target = root
					modifier = insult_opinion
					opinion = -20
				}
			}
		}

		scope:county = {
			change_county_control = medium_county_control_gain
		}

		stress_impact = {
			compassionate = medium_stress_impact_loss
			callous = minor_stress_impact_gain
		}
	}

	option = { # We need more violence!
		name = hold_court.5010.b
		scope:county = {
			add_county_modifier = {
				modifier = county_increased_presence_modifier
				days = 3650
			}
		}
		stress_impact = {
			sadistic = medium_stress_impact_loss
			compassionate = medium_stress_impact_gain
		}
	}

	option = { # Throw some money at the problem
		name = hold_court.5010.c
		remove_short_term_gold = tiny_gold_value
		scope:county = {
			change_county_control = miniscule_county_control_gain
		}
		stress_impact = {
			greedy = 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 = {
					NOT = { 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
	}
}

##################################################
# Dancing Plague
# by Linnéa Thimrén
# 5020 - 5029
##################################################

# Dancing mania has gripped one of your provinces
scripted_trigger hold_court_5020_province_trigger = {
	any_province_epidemic = {
		epidemic_type = epidemic_type:ergotism
		outbreak_intensity < apocalyptic
	}
}
hold_court.5020 = {
	type = court_event
	title = hold_court.5020.t
	desc = {
		desc = hold_court.5020.desc_opening
		triggered_desc = {
		    trigger = {
				exists = scope:court_physician
		    }
		    desc = hold_court.5020.desc_physician
		}
		triggered_desc = {
    	    trigger = {
    			exists = scope:court_chaplain
    	    }
    	    desc = {
    	    	first_valid = {
    	    		triggered_desc = {
    	    		    trigger = {
    	    				exists = scope:court_physician
    	    		    }
    	    		    desc = hold_court.5020.desc_chaplain_intro_1
    	    		}
    	    		desc = hold_court.5020.desc_chaplain_intro_2
    	    	}
    	    	random_valid = {
		    		triggered_desc = {
		    		    trigger = {
		    				exists = scope:john
		    		    }
		    		    desc = hold_court.5020.desc_christian_john
		    		}
		    		triggered_desc = {
		    		    trigger = {
		    				exists = scope:vitus
		    		    }
		    		    desc = hold_court.5020.desc_christian_vitus
		    		}
		    		triggered_desc = {
		    		    trigger = {
		    				NOR = {
		    					exists = scope:john
		    					exists = scope:vitus
		    				}
		    		    }
		    		    desc = hold_court.5020.desc_god
		    		}
		    	}
    	    }
    	}
		triggered_desc = {
		    trigger = {
				NOR = {
					exists = scope:court_physician
					exists = scope:court_chaplain
				}
		    }
		    desc = hold_court.5020.desc_no_physician
		}
	}
	theme = realm
	override_sound = { reference = event:/SFX/Events/Themes/sfx_event_theme_type_generic }
	lower_right_portrait = scope:portrait_3
	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 = dancing_plague
			}
			scope:portrait_2 = {
				group = petitioners_group
				animation = personality_rational
			}
		}
	}

	widget = {
		gui = "event_window_widget_event_chain_progress"
		container = "custom_widgets_container"
		controller = event_chain_progress
	}
	
	trigger = {
		NOT = { has_character_flag = had_event_dancing_plague }
		any_realm_province = {
			hold_court_5020_province_trigger = yes
		}
	}

	immediate = {
		add_character_flag = had_event_dancing_plague
		random_realm_province = {
			limit = {
				hold_court_5020_province_trigger = yes
			}
			save_scope_as = province
		}
		create_character = {
			template = servant_character
			dynasty = none
			location = root.capital_province
			save_scope_as = peasant
		}
		scope:peasant = {
			court_event_character_flag_effect = yes
		}

		#Let's save the court physician if you have one
		if = {
			limit = {
				court_physician_available_trigger = yes
				#AGOT Modified to account for maesters
				# any_court_position_holder = {
				# 	type = court_physician_court_position
	           	# 	has_court_event_flag = no
	           	# 	is_ai = yes
				# }
				OR = {
					any_court_position_holder = {
						type = court_physician_court_position
						has_court_event_flag = no
						is_ai = yes
					}
					any_court_position_holder = {
						type = maester_court_position
						has_court_event_flag = no
						is_ai = yes
					}
			}
			}
			save_court_physician_as_effect = { SCOPE_NAME = court_physician }
			scope:court_physician = {
				save_scope_as = portrait_2
				court_event_character_flag_effect = yes
			}
		}
		if = {
			limit = {
				exists = cp:councillor_court_chaplain
				cp:councillor_court_chaplain = {
					is_ai = yes
					has_court_event_flag = no
				}
			}
			cp:councillor_court_chaplain = {
				save_scope_as = court_chaplain
				court_event_character_flag_effect = yes
				if = {
					limit = {
						NOT = {
							exists = scope:court_physician
						}
					}
					save_scope_as = portrait_2
				}
				else = {
					save_scope_as = portrait_3
				}
			}
			#AGOT Disabled
			# hidden_effect = { #What do they think caused the mania?
			# 	random_list = {
			# 		10 = {
			# 			trigger = {
			# 				faith = { religion_tag = christianity_religion }
			# 	    		scope:court_chaplain = { faith = { religion_tag = christianity_religion } }
			# 			}
			# 			save_scope_value_as = {
			# 				name = john
			# 				value = yes
			# 			}
			# 		}
			# 		10 = {
			# 			trigger = {
			# 				faith = { religion_tag = christianity_religion }
			# 	    		scope:court_chaplain = { faith = { religion_tag = christianity_religion } }
			# 			}
			# 			save_scope_value_as = {
			# 				name = vitus
			# 				value = yes
			# 			}
			# 		}
			# 		10 = {
			# 			trigger = {
			# 				NOT = {
			# 					faith = { religion_tag = christianity_religion }
			# 	    			scope:court_chaplain = { faith = { religion_tag = christianity_religion } }
			# 				}
			# 			}
			# 			#If you're not Christian they will just mention HighGod
			# 		}
			# 	}
			# }
	}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}


	option = { # It looks like you're having a grand time, what are you complaining about?
		name = hold_court.5020.a
		stress_impact = {
			base = medium_stress_impact_loss
			compassionate = major_stress_impact_gain
			sadistic = medium_stress_impact_loss
			callous = minor_stress_impact_loss
		}
	}

	option = { # Go to a shrine and pray it away
		name = {
			trigger = { always = yes }
			text = hold_court.5020.b
		}
		#AGOT Disabled
		# name = {
		# 	trigger = {
		# 		OR = {
		# 			exists = scope:john
		# 			exists = scope:vitus
		# 		}
		# 	}
		# 	text = hold_court.5020.b_saint
		# }
		scope:province = {	
			county ={
				add_county_modifier = {
					modifier = contained_dance_plague_modifier
					days = 3650
				}
			}
		}
		add_piety = medium_piety_gain
		if = {
			limit = {
				exists = scope:court_chaplain
			}
			scope:court_chaplain = {
				add_opinion = {
					target = root
					modifier = pleased_opinion
					opinion = 20
				}
			}
		}

		scope:province = {
			random = {
				chance = 25
				create_epidemic_outbreak = {
					type = ergotism
					intensity = minor
				}
			}
		}

		stress_impact = {
			zealous = medium_stress_impact_loss
			cynical = medium_stress_impact_gain
		}
	}

	option = { # Bloodletting is the way
		name = hold_court.5020.c
		trigger = {
			OR = {
				exists = scope:court_physician
				has_trait = lifestyle_physician
				has_focus = learning_medicine_focus
			}
		}
		trait = lifestyle_physician
		scope:province = {	
			county = {
				add_county_modifier = {
					modifier = physician_dance_plague_modifier
					days = 3650
				}
			}
		}
		if = {
			limit = {
				exists = scope:court_physician
			}
			scope:court_physician = {
				add_opinion = {
					target = root
					modifier = pleased_opinion
					opinion = 20
				}
			}
		}
		
		scope:province = {
			random = {
				chance = 25
				create_epidemic_outbreak = {
					type = ergotism
					intensity = minor
				}
			}
		}
		add_learning_lifestyle_xp = medium_lifestyle_xp
	}

	option = { # You know what you need? More dancing and music!
		name = hold_court.5020.d
		trigger = {
			employs_court_position = court_musician_court_position
			has_trait = eccentric
			any_court_position_holder = {
		        type = court_musician_court_position
		        is_physically_able_adult = yes
		    }
		}
		custom_tooltip = hold_court.5020.d_tt
		random_court_position_holder = {
			type = court_musician_court_position
			limit = {
				is_physically_able_adult = yes
			}
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 20
			}
		}
		scope:province = {	
			county = {
				add_county_modifier = {
					modifier = fanning_the_dancing_flames_modifier
					days = 3650
				}
			}
		}
		scope:province = {
			random = {
				chance = 90
				create_epidemic_outbreak = {
					type = ergotism
					intensity = minor
				}
			}
		}
		stress_impact = {
			lifestyle_reveler = major_stress_impact_loss
			eccentric = major_stress_impact_loss
		}
	}
	
	after = {
		if = {
			limit = {
				exists = scope:court_physician
			}
			scope:court_physician = {
            	clear_court_event_participation = yes
			}
		}
		if = {
			limit = {
				exists = scope:court_chaplain
			}
			scope:court_chaplain = {
            	clear_court_event_participation = yes
			}
		}
		hidden_effect = {
			scope:peasant = {
            	clear_court_event_participation = yes
				death = {
					death_reason = death_danced_to_death
				}
			}
		}
		# 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 = {
			faith = { has_doctrine = doctrine_gender_male_dominated }
			is_female = yes
		}
		AND = {
			faith = { has_doctrine = doctrine_gender_female_dominated }
			is_male = yes
		}
	}
	#AGOT ADDED
	is_human = yes
}
scripted_trigger hold_court_5030_courtier_adult_trigger = {
	hold_court_5030_courtier_basic_trigger = yes
	is_adult = yes
}
hold_court.5030 = {
	type = court_event
	title = hold_court.5030.t
	desc = {
		desc = hold_court.5030.desc
		triggered_desc = {
		    trigger = {
				OR = {
					AND = {
						faith = { has_doctrine = doctrine_gender_male_dominated }
						is_female = yes
					}
					AND = {
						faith = { has_doctrine = doctrine_gender_female_dominated }
						is_male = yes
					}
				}
		    }
		    desc = hold_court.5030.desc_you
		}
	}
	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 = {
		NOT = { has_character_flag = had_event_hold_court_5030 }
		any_courtier = {
			hold_court_5030_courtier_adult_trigger = yes
		}
	}

	weight_multiplier = {
		base = 0.5
		modifier = { #More likely to trigger if you're part of the gender minority
			add = 0.75
			OR = {
				AND = {
					faith = { has_doctrine = doctrine_gender_male_dominated }
					is_female = yes
				}
				AND = {
					faith = { has_doctrine = doctrine_gender_female_dominated }
					is_male = yes
				}
			}
		}

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

	immediate = {
		add_character_flag = {
			flag = had_event_hold_court_5030
			years = 40
		}
		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 = {
						faith = { has_doctrine = doctrine_gender_male_dominated }
						is_female = yes
					}
					AND = {
						faith = { has_doctrine = doctrine_gender_female_dominated }
						is_male = yes
					}
				}
			}
			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
				}
			}
		}
		#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 = {
						faith = { has_doctrine = doctrine_gender_male_dominated }
						is_female = yes
					}
					AND = {
						faith = { has_doctrine = doctrine_gender_female_dominated }
						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
				}
			}
		}
		scope:court_tutor = {
			add_character_modifier = {
				modifier = hold_court_distracted_tutor_modifier
				years = 5
			}
		}
	}

	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 = {
			exists = holder
			holder = {
				has_character_flag = recently_occupied_flag
			}
		}
	}
	barony = {
		exists = holder
		holder = {
			NOT = {
				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_short_term_gold = {
			target = scope:6000_poor
			gold = minor_gold_value
		}
		add_hook = {
			type = favor_hook
			target = scope:6000_poor
		}
		scope:6000_province.county = {
			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
		scope:6000_province.county = {
			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
		}
		if = {
			limit = {
				scope:6000_poor = {
					can_set_relation_rival_trigger = { CHARACTER = root }
				}
			}
			scope:6000_poor = {
				progress_towards_rival_effect = {
					CHARACTER = root
					REASON = rival_no_grain
					OPINION = -30
				}
			}
		}
		else = {
			scope:6000_poor = {
				add_opinion = {
					target = root
					modifier = disappointed_opinion
					opinion = -30
				}
			}
		}
		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
			}
		}
	}

	#Option E: they'd better pay their taxes or there will be consequences...
	option = {
		name = hold_court.6000.e
		trigger = {
			OR = {
				has_trait = callous
				has_trait = greedy
				has_trait = torturer
				has_trait = wrathful
				has_trait = arbitrary
				has_trait = sadistic
			}
		}
		add_dread = medium_dread_gain
		if = {
			limit = {
				scope:6000_poor = {
					can_set_relation_rival_trigger = { CHARACTER = root }
				}
			}
			scope:6000_poor = {
				progress_towards_rival_effect = {
					CHARACTER = root
					REASON = rival_no_grain
					OPINION = -50
				}
			}
		}
		else = {
			scope:6000_poor = {
				add_opinion = {
					target = root
					modifier = scared_opinion
					opinion = -50
				}
			}
		}
		ai_chance = {
			base = 15
		}
	}

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

##################################################
# Land Grants
# by Claudia Baldassi
# 6010
##################################################

# A count is supporting a grabby church, who has been bullying a city into selling their arable land. An embassy from the city is asking for protection and justice. #

scripted_trigger hold_court_6010_valid_county_trigger = {
	any_county_province = {
		has_holding_type = city_holding
		barony = {
			exists = holder
			holder = {
				has_court_event_flag = no
				is_available_ai_adult = yes
				save_temporary_scope_as = city
			}
		}
	}
	any_county_province = {
		has_holding_type = church_holding
		barony = {
			exists = lessee
			lessee = {
				has_court_event_flag = no
				is_available_ai_adult = yes
				save_temporary_scope_as = church
			}
		}
	}
	exists = holder
	holder = {
		NOR = {
			this = root
			this = scope:church
			this = scope:city
		}
		has_court_event_flag = no
		target_is_liege_or_above = root
		is_available_ai_adult = yes
	}
}

hold_court.6010 = {
	type = court_event
	title = hold_court.6010.t
	desc = hold_court.6010.desc
	theme = court
	lower_left_portrait = scope:6010_count
	lower_right_portrait = cp:councillor_court_chaplain
	court_scene = {
		button_position_character = scope:6010_embassy
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:6010_embassy = {
				group = petitioners_group
				animation = beg
			}
			scope:6010_church = {
				group = petitioners_group
				animation = personality_zealous
			}
		}
	}

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

	cooldown = { years = 20 }

	trigger = {
		any_realm_county = {
			hold_court_6010_valid_county_trigger = yes
		}
	}

	weight_multiplier = {
		base = 1

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

	immediate = {
		random_realm_county = {
			limit = {
				hold_court_6010_valid_county_trigger = yes
			}
			save_scope_as = 6010_county
		}
		scope:6010_county = {
			holder = {
				save_scope_as = 6010_count
		        court_event_character_flag_effect = yes
			}
			random_county_province = {
				limit = {
					has_holding_type = city_holding
				}
				save_scope_as = 6010_city
				barony = {
					holder = {
						save_scope_as = 6010_embassy
						court_event_character_flag_effect = yes
					}
				}
			}
			random_county_province = {
				limit = {
					has_holding_type = church_holding
				}
				save_scope_as = 6010_ch_holding
				barony = {
					lessee = {
						save_scope_as = 6010_church
						court_event_character_flag_effect = yes
					}
				}
			}
		}
		if = {
			limit = {
				exists = cp:councillor_court_chaplain
				cp:councillor_court_chaplain = {
					is_available_ai_adult = yes
					NOT = { this = scope:6010_church }
					has_court_event_flag = no
				}
			}
			cp:councillor_court_chaplain = {
				save_scope_as = court_chaplain
				court_event_character_flag_effect = yes
			}
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	#Option A: side with the church (and the count) - the church will be pleased
	option = {
		name = hold_court.6010.a
		stress_impact = {
			cynical = major_stress_impact_gain
			zealous = major_stress_impact_loss
		}
		reverse_add_opinion = {
			target = scope:6010_church
			modifier = grateful_opinion
			opinion = 40
		}
		hidden_effect = {
			if = {
				limit = { 
					can_set_relation_potential_friend_trigger = { CHARACTER = scope:6010_church }
				}
				set_relation_potential_friend = scope:6010_church
			}
		}
		reverse_add_opinion = {
			target = scope:6010_count
			modifier = pleased_opinion
			opinion = 25
		}
		hidden_effect = {
			if = {
				limit = { 
					can_set_relation_potential_friend_trigger = { CHARACTER = scope:6010_count }
				}
				set_relation_potential_friend = scope:6010_count
			}
		}
		if = {
			limit = {
				exists = scope:court_chaplain
			}
			scope:court_chaplain = {
				add_opinion = {
					target = root
					modifier = pious_opinion
					opinion = 15
				}
				hidden_effect = {
					if = {
						limit = { 
							can_set_relation_potential_friend_trigger = { CHARACTER = root }
						}
						set_relation_potential_friend = root
					}
				}
			}
		}
		reverse_add_opinion = {
			target = scope:6010_embassy
			modifier = disappointed_opinion
			opinion = -40
		}
		hidden_effect = {
			if = {
				limit = { 
					can_set_relation_potential_rival_trigger = { CHARACTER = scope:6010_embassy }
				}
				set_relation_potential_rival = scope:6010_embassy
			}
		}
		add_piety = medium_piety_gain
		ai_chance = {
			base = 5

			modifier = {
				has_trait = zealous
				add = 15
			}
			modifier = {
				has_trait = cynical
				add = -10
			}
		}
	}

	#Option B: side with the citizens - the church (and the count) won't be pleased
	option = {
		name = hold_court.6010.b
		stress_impact = {
			cynical = major_stress_impact_loss
			zealous = major_stress_impact_gain
		}
		reverse_add_opinion = {
			target = scope:6010_church
			modifier = insult_opinion
			opinion = -40
		}
		hidden_effect = {
			if = {
				limit = { 
					can_set_relation_potential_rival_trigger = { CHARACTER = scope:6010_church }
				}
				set_relation_potential_rival = scope:6010_church
			}
		}
		reverse_add_opinion = {
			target = scope:6010_count
			modifier = disappointed_opinion
			opinion = -25
		}
		if = {
			limit = {
				has_realm_law_flag = title_revocation_allowed
				scope:6010_count = {
					NOT = { vassal_contract_has_flag = vassal_contract_cannot_revoke_titles }
				}
			}
			custom_tooltip = 6010_revoke_title_reason
			hidden_effect = {
				add_opinion = {
					target = scope:6010_count
					modifier = 6010_mismanagement_opinion
				}
			}
		}
		hidden_effect = {
			if = {
				limit = { 
					can_set_relation_potential_rival_trigger = { CHARACTER = scope:6010_count }
				}
				set_relation_potential_rival = scope:6010_count
			}
		}
		if = {
			limit = {
				exists = scope:court_chaplain
			}
			scope:court_chaplain = {
				add_opinion = {
					target = root
					modifier = impious_opinion
					opinion = -15
				}
				hidden_effect = {
					if = {
						limit = { 
							can_set_relation_potential_rival_trigger = { CHARACTER = root }
						}
						set_relation_potential_rival = root
					}
				}
			}
		}
		reverse_add_opinion = {
			target = scope:6010_embassy
			modifier = grateful_opinion
			opinion = 40
		}
		hidden_effect = {
			if = {
				limit = { 
					can_set_relation_potential_friend_trigger = { CHARACTER = scope:6010_embassy }
				}
				set_relation_potential_friend = scope:6010_embassy
			}
		}
		add_prestige = minor_prestige_gain
		scope:6010_county = {
			change_development_progress = medium_development_progress_gain
		}
		scope:6010_embassy = {
			pay_short_term_gold = {
				target = root
				gold = minor_gold_value
			}
		}
		ai_chance = {
			base = 5

			modifier = {
				has_trait = cynical
				add = 15
			}
			modifier = {
				has_trait = zealous
				add = -10
			}
		}
	}

	#Option D: make it a republic vassal
	option = {
		name = hold_court.6010.d
		trigger = {
			NOT = {
				any_vassal = {
					government_has_flag = government_is_republic
				}
			}
		}
		stress_impact = {
			zealous = major_stress_impact_gain
		}
		create_title_and_vassal_change = {
			type = granted
			save_scope_as = change
			add_claim_on_loss = yes
		}
		scope:6010_county = {
			change_title_holder = {
				holder = scope:6010_embassy
				change = scope:change
			}
		}
		resolve_title_and_vassal_change = scope:change
		custom_tooltip = hold_court.6010.d.tt
		reverse_add_opinion = {
			target = scope:6010_church
			modifier = insult_opinion
			opinion = -40
		}
		hidden_effect = {
			if = {
				limit = { 
					can_set_relation_potential_rival_trigger = { CHARACTER = scope:6010_church }
				}
				set_relation_potential_rival = scope:6010_church
			}
		}
		reverse_add_opinion = {
			target = scope:6010_count
			modifier = insult_opinion
			opinion = -50
		}
		scope:6010_count = {
			if = {
				limit = { 
					can_set_relation_rival_trigger = { CHARACTER = root }
				}
				set_relation_rival = {
					target = root
					reason = rival_took_title
				}
			}
		}
		if = {
			limit = {
				exists = scope:court_chaplain
			}
			scope:court_chaplain = {
				add_opinion = {
					target = root
					modifier = impious_opinion
					opinion = -15
				}
				hidden_effect = {
					if = {
						limit = { 
							can_set_relation_potential_rival_trigger = { CHARACTER = root }
						}
						set_relation_potential_rival = root
					}
				}
			}
		}
		reverse_add_opinion = {
			target = scope:6010_embassy
			modifier = received_title_county
		}
		reverse_add_opinion = {
			target = scope:6010_embassy
			modifier = loyal_servant
		}
		hidden_effect = {
			if = {
				limit = { 
					can_set_relation_potential_friend_trigger = { CHARACTER = scope:6010_embassy }
				}
				set_relation_potential_friend = scope:6010_embassy
			}
		}
		ai_chance = {
			base = 5

			modifier = {
				has_trait = zealous
				add = -10
			}
		}
	}

	#Option C: don't bother me with these small squabbles
	option = {
		name = hold_court.6010.c
		stress_impact = {
			lazy = medium_stress_impact_loss
			just = medium_stress_impact_gain
			diligent = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
		}
		reverse_add_opinion = {
			target = scope:6010_embassy
			modifier = disappointed_opinion
			opinion = -20
		}
		hidden_effect = {
			if = {
				limit = { 
					can_set_relation_potential_rival_trigger = { CHARACTER = scope:6010_embassy }
				}
				set_relation_potential_rival = scope:6010_embassy
			}
		}
		ai_chance = {
			base = 5

			modifier = {
				has_trait = lazy
				add = 10
			}
			modifier = {
				has_trait = just
				add = -5
			}
			modifier = {
				has_trait = diligent
				add = -5
			}
			modifier = {
				has_trait = compassionate
				add = -5
			}
		}
	}

	after = {
		scope:6010_count = {
        	clear_court_event_participation = yes
		}
		scope:6010_embassy = {
        	clear_court_event_participation = yes
		}
		scope:6010_church = {
        	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
	}
}

##################################################
# Hawks and Doves
# by Claudia Baldassi
# 6020
##################################################

# Two important vassals come to you, representing your country's "hawks" and "doves". Which politics do you support? #

scripted_trigger hold_court_6020_hawk_trigger = {
    has_court_event_flag = no
	is_available_ai_adult = yes
	is_of_major_interest_trigger = {
		CHARACTER = root
	}
	has_education_martial_trigger = yes
	NOR = {
		has_trait = lazy
		has_trait = craven
		has_trait = shy
	}
	NOR = {
		has_trait = calm
		has_trait = patient
		has_trait = forgiving
	}
	OR = {
		prowess >= 12
		martial >= 12
	}
}

scripted_trigger hold_court_6020_dove_trigger = {
	has_court_event_flag = no
	is_available_ai_adult = yes
	is_of_major_interest_trigger = {
		CHARACTER = root
	}
	OR = {
		has_education_diplomacy_trigger = yes
		has_education_stewardship_trigger = yes
	}
	NOR = {
		has_trait = vengeful
		has_trait = wrathful
		has_trait = zealous
	}
	OR = {
		diplomacy >= 12
		stewardship >= 12
	}
}

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

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

	cooldown = { years = 20 }

	trigger = {
		any_vassal = {
			hold_court_6020_hawk_trigger = yes
			save_temporary_scope_as = first_vassal 
		}
		any_vassal = {
			hold_court_6020_dove_trigger = yes
			NOT = { this = scope:first_vassal }
		}
	}

	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 = {
				hold_court_6020_hawk_trigger = yes
			}
			save_scope_as = hawk
            court_event_character_flag_effect = yes
		}
		random_vassal = {
			limit = {
				hold_court_6020_dove_trigger = yes
				NOT = { this = scope:hawk }
			}
			save_scope_as = dove
			court_event_character_flag_effect = yes
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	#Option A: support the hawks
	option = {
		name = hold_court.6020.a
		reverse_add_opinion = {
			target = scope:hawk
			modifier = pleased_opinion
			opinion = 30
		}
		reverse_add_opinion = {
			target = scope:dove
			modifier = disappointed_opinion
			opinion = -30
		}
		add_character_modifier = {
			modifier = hold_court_hawks_modifier
			years = 5
		}
		add_prestige = medium_prestige_gain
		stress_impact = {
			shy = medium_stress_impact_gain
			content = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
			craven = major_stress_impact_gain
		}
		ai_chance = {
			base = 100

			ai_value_modifier ={
				ai_boldness = 0.5
				ai_greed = 0.25
				ai_honor = -0.25
			}

			modifier = {
				has_trait = craven
				add = -50
			}
			modifier = {
				has_trait = shy
				add = -25
			}
			modifier = {
				has_trait = content
				add = -25
			}
			modifier = {
				has_trait = compassionate
				add = -25
			}
		}
	}

	#Option B: support the doves
	option = {
		name = hold_court.6020.b
		reverse_add_opinion = {
			target = scope:dove
			modifier = pleased_opinion
			opinion = 30
		}
		reverse_add_opinion = {
			target = scope:hawk
			modifier = disappointed_opinion
			opinion = -30
		}
		add_character_modifier = {
			modifier = hold_court_doves_modifier
			years = 5
		}
		stress_impact = {
			impatient = medium_stress_impact_gain
			arrogant = medium_stress_impact_gain
			ambitious = medium_stress_impact_gain
			vengeful = medium_stress_impact_gain
		}
		change_current_court_grandeur = minor_court_grandeur_gain
		ai_chance = {
			base = 100
			ai_value_modifier ={
				ai_compassion = 0.5
				ai_greed = -0.25
			}
			modifier = {
				has_trait = impatient
				add = -25
			}
			modifier = {
				has_trait = arrogant
				add = -25
			}
			modifier = {
				has_trait = ambitious
				add = -25
			}
			modifier = {
				has_trait = vengeful
				add = -25
			}
		}
	}

	#Option C: you do what YOU decide
	option = {
		name = hold_court.6020.c
		reverse_add_opinion = {
			target = scope:hawk
			modifier = disappointed_opinion
			opinion = -10
		}
		reverse_add_opinion = {
			target = scope:dove
			modifier = disappointed_opinion
			opinion = -10
		}
		ai_chance = {
			base = 50
			modifier = {
				has_trait = arrogant
				add = 50
			}
			modifier = {
				has_trait = lazy
				add = 25
			}
		}
	}

	after = {
		scope:hawk = {
            clear_court_event_participation = yes
		}
		scope:dove = {
            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 = {
		NOT = { this = root.culture }
		save_temporary_scope_as = 6030_border_culture
	}
	any_neighboring_county = {
		holder = {
			NOT = { 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
		}
		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 }
		if = {
			limit = {
				any_vassal = {
					culture = scope:6030_monk.culture
				}
			}
			every_vassal = {
				limit = {
					culture = scope:6030_monk.culture
				}
				custom = hold_court.6030.d.tt
				add_opinion = {
					target = root
					modifier = pleased_opinion
					opinion = 10
				}
			}
		}
		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
				}
			}
			appoint_court_position = {
				recipient = scope:6030_monk
				court_position = court_tutor_court_position
			}
		}
		add_character_modifier = {
			modifier = hold_court_bilingual_readings_modifier
			years = 10
		}
		if = {
			limit = {
				any_ruler = {
					culture = scope:6030_monk.culture
				}
			}
			every_ruler = {
				limit = {
					culture = scope:6030_monk.culture
				}
				custom = hold_court.6030.b.tt.2
				add_opinion = {
					target = root
					modifier = pleased_opinion
					opinion = 10
				}
			}
		}
		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
		reverse_add_opinion = {
			target = scope:6030_monk
			modifier = disappointed_opinion
			opinion = -20
		}
		scope:6030_monk = { select_and_move_to_pool_effect = yes }
		stress_impact = {
			lazy = medium_stress_impact_loss
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = -0.5
			}
			modifier = {
				has_trait = lazy
				add = 50
			}
		}
		scope:6030_monk = {
			add_character_flag = 6030_remove_char_flag
		}
	}

	#Option D: cultural oppression
	option = {
		name = hold_court.6030.d
		trigger = {
			OR = {
				has_trait = zealous
				has_trait = vengeful
				has_trait = sadistic
				has_trait = paranoid
				has_trait = callous
			}
		}
		add_dread = major_dread_gain
		rightfully_imprison_character_effect = {
			TARGET = scope:6030_monk
			IMPRISONER = root
		}
		if = {
			limit = {
				any_vassal = {
					culture = scope:6030_monk.culture
				}
			}
			every_vassal = {
				limit = {
					culture = scope:6030_monk.culture
				}
				custom = hold_court.6030.d.tt
				add_opinion = {
					target = root
					modifier = scared_opinion
					opinion = -25
				}
			}
		}
		ai_chance = {
			base = 200
		}
	}

	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
				any_court_position_holder = {
					type = antiquarian_court_position
					is_available_ai_adult = yes
					has_court_event_flag = no
				}
			}
			random_court_position_holder = {
				type = antiquarian_court_position
				limit = {
					is_available_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: Just add it to the collection
	option = {
		name = hold_court.6040.a
		add_character_modifier = hold_court_mysterious_book_modifier
		ai_chance = {
			base = 100
		}
	}

	#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
			NOT = {
				exists = scope:antiquarian
			}
		}
		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
				}
			}
			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
		add_prestige = medium_prestige_loss
		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. #

#Disable
# scripted_trigger hold_court_6050_religion_trigger = {
# 	OR = {
# 		religion = religion:christianity_religion
# 		religion = religion:islam_religion
# 		religion = religion:buddhism_religion
# 		religion = religion:hinduism_religion
# 	}
# }

#Disable
# 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
# 				NOT = {
# 					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 = {
# 			change_county_control = 50
# 		}
# 		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
# 		}
# 		add_stress = medium_stress_impact_loss
# 		scope:6050_tomb.county = {
# 			change_county_control = 60
# 		}
# 		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
# 		}
# 		else = {
# 			add_piety = major_piety_loss
# 		}
# 		scope:6050_tomb.county = {
# 			change_county_control = -20
# 		}
# 		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
# 		scope:6050_tomb.county = {
# 			change_county_control = -10
# 		}
# 		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
# 	}
# }

#Disable
# 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
# 		}
# 		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
	#AGOT Added
	NOT = { has_trait = kingsguard }
	NOT = { has_trait = nightswatch }
}

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 = {
		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
		}
		NOT = {
			government_has_flag = government_is_tribal
		}
	}

	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_gold = 350
			}
		}
		# 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_short_term_gold = {
				target = root
				gold = 250
			}
		}
		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
				}
			}
		}
		resolve_title_and_vassal_change = scope:change
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = -0.25
				ai_honor = 0.25
			}
		}
	}

	#Option B: haggle on the price
	option = {
		name = hold_court.6060.b
		duel = {
			skill = stewardship
			target = scope:6060_rich
			25 = {
				compare_modifier = {
					value = {
						value = scope:duel_value
						if = {
							limit = { has_trait = greedy }
							add = 2
						}
						if = {
							limit = { has_trait = generous }
							add = -2
						}
						if = {
							limit = { has_trait = education_stewardship_2 }
							add = 0.5
						}
						if = {
							limit = { has_trait = education_stewardship_3 }
							add = 0.75
						}
						if = {
							limit = { has_trait = education_stewardship_4 }
							add = 1
						}
						if = {
							limit = { has_trait = education_stewardship_5 }
							add = 1.5
						}
						if = {
							limit = { has_trait = avaricious }
							add = 1
						}
						if = {
							limit = { has_trait = administrator }
							add = 0.5
						}
						if = {
							limit = { has_trait = patient }
							add = 0.5
						}
						if = {
							limit = { has_trait = impatient }
							add = -0.5
						}
						if = {
							limit = { has_trait = humble }
							add = -1
						}
						if = {
							limit = { has_trait = arrogant }
							add = 0.5
						}
						if = {
							limit = { has_trait = shy }
							add = -2
						}
						if = {
							limit = { has_trait = compassionate }
							add = -1
						}
						if = {
							limit = { has_trait = honest }
							add = -1
						}
						if = {
							limit = { has_trait = deceitful }
							add = 2
						}
						if = {
							limit = { has_trait = stubborn }
							add = 3
						}
					}
					multiplier = 2
					min = -30
					max = 30
				}
				desc = hold_court.6060.b.tt.success
				send_interface_toast = {
					title = hold_court.6060.b.tt.success
					scope:6060_rich = {
						pay_short_term_gold = {
							target = root
							gold = 350
						}
					}
				}
			}
			30 = {
				compare_modifier = {
					value = {
						value = scope:duel_value
						if = {
							limit = { 
								scope:6060_rich = { has_trait = greedy }
							}
							add = -2
						}
						if = {
							limit = {
								scope:6060_rich = { has_trait = generous }
							}
							add = 2
						}
						if = {
							limit = {
								scope:6060_rich = { has_trait = education_stewardship_2 }
							}
							add = -0.5
						}
						if = {
							limit = {
								scope:6060_rich = { has_trait = education_stewardship_3 }
							}
							add = -0.75
						}
						if = {
							limit = {
								scope:6060_rich = { has_trait = education_stewardship_4 }
							}
							add = -1
						}
						if = {
							limit = {
								scope:6060_rich = { has_trait = education_stewardship_5 }
							}
							add = -1.5
						}
						if = {
							limit = {
								scope:6060_rich = { has_trait = avaricious }
							}
							add = -1
						}
						if = {
							limit = {
								scope:6060_rich = { has_trait = ambitious }
							}
							add = 1
						}
						
						if = {
							limit = {
								scope:6060_rich = { has_trait = patient }
							}
							add = -0.5
						}
						if = {
							limit = {
								scope:6060_rich = { has_trait = impatient }
							}
							add = 0.5
						}
						if = {
							limit = {
								scope:6060_rich = { has_trait = humble }
							}
							add = 1
						}
						if = {
							limit = {
								scope:6060_rich = { has_trait = arrogant }
							}
							add = -0.5
						}
						if = {
							limit = {
								scope:6060_rich = { has_trait = shy }
							}
							add = 2
						}
						if = {
							limit = {
								scope:6060_rich = { has_trait = paranoid }
							}
							add = -4
						}
						if = {
							limit = {
								scope:6060_rich = { has_trait = trusting }
							}
							add = 2
						}
						if = {
							limit = {
								scope:6060_rich = { has_trait = compassionate }
							}
							add = 1
						}
						if = {
							limit = {
								scope:6060_rich = { has_trait = deceitful }
							}
							add = -2
						}
						if = {
							limit = {
								scope:6060_rich = { has_trait = stubborn }
							}
							add = -3
						}
						if = {
							limit = {
								scope:6060_rich = { has_trait = fickle }
							}
							add = 2
						}
					}
					multiplier = -2
					min = -30
					max = 30
				}
				desc = hold_court.6060.b.tt.failure
				send_interface_toast = {
					title = hold_court.6060.b.tt.failure
					add_prestige = medium_prestige_loss
					scope:6060_rich = {
						pay_short_term_gold = {
							target = root
							gold = 250
						}
					}
				}
			}
		}
		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
				}
			}
		}
		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
		reverse_add_opinion = {
			target = scope:6060_rich
			modifier = disappointed_opinion
			opinion = -20
		}
		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 = {
					num_of_relation_guardian > 0
				}
			}
			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
						exists = this
					}
				}
			}
			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 = {
				NOT = {
					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
						exists = this
					}
				}
			}
			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 = {
				NOT = {
					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
						exists = this
					}
				}
			}
			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 = {
				NOT = {
					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 = {
	any_county_province = {
		has_holding = no
	}
	culture = {
		NOT = {
			this = root.culture
		}
	}
	NOT = { this = root.capital_county }
}

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
					}
					#AGOT Added
					NOT = { has_trait = nightswatch }
					NOT = { has_trait = kingsguard }
					NOT = { has_trait = maester }
					NOT = { has_trait = septon }
				}
			}
			random_courtier_or_guest = {
				limit = {
		            has_court_event_flag = no
					is_available_healthy_ai_adult = yes
					culture = {
						this = scope:6080_culture
					}
					#AGOT Added
					NOT = { has_trait = nightswatch }
					NOT = { has_trait = kingsguard }
					NOT = { has_trait = maester }
					NOT = { has_trait = septon }
				}
				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
			}
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	#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_vassal_contract_modification_blocked = yes
			}
		}
		custom_tooltip = hold_court.6080.a.tt
		scope:6080_county = {
			change_county_control = -40
			add_county_modifier = {
				modifier = hold_court_grateful_peasants_modifier
				years = 50
			}
			random_county_province = {
				limit = {
					has_holding = no
				}
				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_count = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -30
			}
		}
		scope:6080_county = {
			change_county_control = -10
		}
		stress_impact = {
			generous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = generous
				add = -50
			}
		}
	}

	#Option C: eradicate that culture!
	option = {
		name = hold_court.6080.c
		scope:6080_count = {
			add_opinion = {
				target = root
				modifier = scared_opinion
				opinion = -50
			}
		}
		scope:6080_county = {
			change_county_control = 25
			change_development_level = -2
		}
		add_character_modifier = {
			modifier = court_6080_cultural_hostility_modifier
			years = 10
		}
		stress_impact = {
			generous = medium_stress_impact_gain
			just = medium_stress_impact_gain
			compassionate = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_vengefulness = 0.5
				ai_compassion = -0.5
			}
			modifier = {
				has_trait = generous
				add = -50
			}
			modifier = {
				has_trait = just
				add = -50
			}
			modifier = {
				has_trait = compassionate
				add = -75
			}
			modifier = {
				has_trait = callous
				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 = yes
	exists = capital_county
	capital_county = {
		hold_court_6090_valid_county_trigger = yes
	}
}

scripted_trigger hold_court_6090_valid_county_trigger = {
	faith = {
		NOT = {
			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
		#AGOT Disabled
		# 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
	#AGOT Disabled
	# 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
		}
		#AGOT Disabled
		# if = {
		# 	limit = {
		# 		employs_court_position = high_almoner_court_position
		# 		any_court_position_holder = {
		# 			type = high_almoner_court_position
		# 			is_available_ai_adult = yes
		# 			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:court_chaplain = {
			set_council_task = {
				task_type = task_conversion
				target = scope:6090_main_county
			}
		}
		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
			}
		}
	}

	#AGOT Disabled
	#Option B: send the almoners
	# option = {
	# 	name = hold_court.6090.b
	# 	trigger = {
	# 		exists = scope:high_almoner
	# 		trigger_if = {
	# 			limit = {
	# 				is_ai = yes
	# 			}
	# 			short_term_gold >= major_gold_value
	# 		}
	# 	}
	# 	remove_short_term_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 = 5
	# 			}
	# 		}
	# 		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
			}
		}
		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
				}
			}
		}
		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
		}
		#AGOT Disabled
		# 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 = {
            is_independent_ruler = yes
            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 = poet }
					scope:6100_vassal_2 = { has_trait = 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 = poet }
				scope:6100_vassal_2 = { has_trait = 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
		#AGOT Disabled
		# 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 }
		#AGOT Disabled
		# 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: give money
	option = {
		name = hold_court.6110.a
		trigger = {
			#AGOT Disabled
			# NOT = { exists = scope:almoner }
			trigger_if = {
				limit = {
					is_ai = yes
				}
				short_term_gold >= major_gold_value
			}
		}
		remove_short_term_gold = medium_gold_value
		scope:6110_vassal_1 = {
			random_sub_realm_county = {
				add_county_modifier = {
					modifier = 6110_war_compensations_county_modifier
					years = 2
				}
			}
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 10
			}
		}
		scope:6110_vassal_2 = {
			random_sub_realm_county = {
				add_county_modifier = {
					modifier = 6110_war_compensations_county_modifier
					years = 2
				}
			}
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 10
			}
		}
		stress_impact = {
			profligate = major_stress_impact_loss
			improvident = major_stress_impact_loss
			greedy = major_stress_impact_gain
		}
		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
			}
		}
	}

	#AGOT Disabled
	#Option F: send almoner
	# option = {
	# 	name = hold_court.6110.f
	# 	trigger = {
	# 		exists = scope:almoner
	# 		trigger_if = {
	# 			limit = {
	# 				is_ai = yes
	# 			}
	# 			short_term_gold >= major_gold_value
	# 		}
	# 	}
	# 	remove_short_term_gold = major_gold_value
	# 	scope:6110_vassal_1 = {
	# 		every_sub_realm_county = {
	# 			custom = 6110_custom_every_realm_1
	# 			add_county_modifier = {
	# 				modifier = 6110_sent_alms_county_modifier
	# 				years = 2
	# 			}
	# 		}
	# 		add_opinion = {
	# 			target = root
	# 			modifier = grateful_opinion
	# 			opinion = 25
	# 		}
	# 	}
	# 	scope:6110_vassal_2 = {
	# 		every_sub_realm_county = {
	# 			custom = 6110_custom_every_realm_2
	# 			add_county_modifier = {
	# 				modifier = 6110_sent_alms_county_modifier
	# 				years = 2
	# 			}
	# 		}
	# 		add_opinion = {
	# 			target = root
	# 			modifier = grateful_opinion
	# 			opinion = 25
	# 		}
	# 	}
	# 	scope:almoner = {
	# 		add_opinion = {
	# 			target = root
	# 			modifier = pious_opinion
	# 			opinion = 40
	# 		}
	# 	}
	# 	stress_impact = {
	# 		profligate = major_stress_impact_loss
	# 		improvident = massive_stress_impact_loss
	# 		cynical = medium_stress_impact_gain
	# 		greedy = major_stress_impact_gain
	# 	}
	# 	add_piety = major_piety_gain
	# 	ai_chance = {
	# 		base = 150
	# 		ai_value_modifier = {
	# 			ai_zeal = 0.5
	# 			ai_greed = -0.5
	# 		}
	# 		modifier = {
	# 			gold < major_gold_value
	# 			add = -150
	# 		}
	# 		modifier = {
	# 			has_trait = profligate
	# 			add = 75
	# 		}
	# 		modifier = {
	# 			has_trait = improvident
	# 			add = 100
	# 		}
	# 		modifier = {
	# 			has_trait = cynical
	# 			add = -50
	# 		}
	# 		modifier = {
	# 			has_trait = greedy
	# 			add = -75
	# 		}
	# 	}
	# }

	#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 = -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
			ai_value_modifier = {
				ai_compassion = 0.5
			}
			modifier = {
				has_trait = wrathful
				add = -50
			}
		}
	}

	#Option C: reprimand and fine the vassals
	option = {
		name = hold_court.6110.c
		scope:6110_vassal_1 = {
			add_opinion = {
				target = root
				modifier = annoyed_opinion
				opinion = -10
			}
			pay_short_term_gold = {
				target = root
				gold = minor_gold_value
			}
			every_sub_realm_county = {
				custom = 6110_custom_every_realm_1
				change_county_control = -10
			}
		}
		scope:6110_vassal_2 = {
			add_opinion = {
				target = root
				modifier = annoyed_opinion
				opinion = -10
			}
			pay_short_term_gold = {
				target = root
				gold = minor_gold_value
			}
			every_sub_realm_county = {
				custom = 6110_custom_every_realm_2
				change_county_control = -10
			}
		}
		stress_impact = {
			diligent = medium_stress_impact_gain
			compassionate = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = diligent
				add = -50
			}
			modifier = {
				has_trait = compassionate
				add = -75
			}
			ai_value_modifier = {
				ai_greed = 0.5
				ai_energy = -0.25
			}
		}
	}

	#Option D: how dare you?? Imprison
	option = {
		name = hold_court.6110.d
		imprison = {
			target = scope:6110_rep
			type = house_arrest
		}
		scope:6110_vassal_1 = {
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 20
			}
			every_sub_realm_county = {
				custom = 6110_custom_every_realm_1
				change_county_control = -25
			}
		}
		scope:6110_vassal_2 = {
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 20
			}
			every_sub_realm_county = {
				custom = 6110_custom_every_realm_2
				change_county_control = -25
			}
		}
		stress_impact = {
			compassionate = major_stress_impact_gain
			just = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = compassionate
				add = -75
			}
			modifier = {
				has_trait = just
				add = -75
			}
			modifier = {
				has_trait = callous
				add = 75
			}
			modifier = {
				has_trait = arrogant
				add = 50
			}
			ai_value_modifier = {
				ai_vengefulness = 0.5
			}
		}
		add_dread = medium_dread_gain
	}

	#Option E: don't meddle
	option = {
		name = hold_court.6110.e
		stress_impact = {
			diligent = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
			humble = major_stress_impact_gain
		}
		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
			}
		}
		#AGOT Disabled
		# 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) #

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_gold >= major_gold_value
			}
		}
		stress_impact = {
			lazy = major_stress_impact_gain
			content = major_stress_impact_gain
		}
		remove_short_term_gold = major_gold_value
		scope:steward = {
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 20
			}
		}
		add_character_flag = {
			flag = 6120_has_domesday_book_flag
			years = 50
		}
		custom_tooltip = hold_court.6120.a.tt
		trigger_event = {
			id = hold_court.6121
			days = 185
		}
		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 B: yes but with seneschal
	option = {
		name = hold_court.6120.b
		trigger = {
			exists = scope:seneschal
			trigger_if = {
				limit = {
					is_ai = yes
				}
				short_term_gold >= major_gold_value
			}
		}
		stress_impact = {
			lazy = major_stress_impact_gain
			content = major_stress_impact_gain
		}
		remove_short_term_gold = major_gold_value
		scope:steward = {
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 30
			}
		}
		scope:seneschal = {
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 30
			}
		}
		add_character_flag = {
			flag = 6120_has_domesday_book_flag
			years = 50
		}
		custom_tooltip = hold_court.6120.a.tt
		trigger_event = {
			id = hold_court.6121
			days = 185
		}
		ai_chance = {
			base = 150
			ai_value_modifier = {
				ai_energy = 0.25
				ai_rationality = 0.5
				ai_greed = -0.25
			}
			modifier = {
				gold < major_gold_value
				add = -150
			}
			modifier = {
				has_trait = lazy
				add = -75
			}
			modifier = {
				has_trait = content
				add = -75
			}
		}
	}

	#Option C: did you say TAXES??
	option = {
		name = hold_court.6120.c
		stress_impact = {
			generous = major_stress_impact_gain
			compassionate = major_stress_impact_gain
			just = major_stress_impact_gain
		}
		every_vassal = {
			limit = {
				is_ai = yes
			}
			custom = 6120_every_vassal
			pay_short_term_gold = {
 				target = root
 				gold = tiny_gold_value
 			}
		}
		add_character_modifier = {
			modifier = 6120_extra_taxes_modifier
			years = 2
		}
		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
		}
		scope:steward = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -20
			}
		}
		if = {
			limit = {
				exists = scope:seneschal
			}
			scope:seneschal = {
				add_opinion = {
					target = root
					modifier = disappointed_opinion
					opinion = -20
				}
			}
		}
		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
		}
		stress_impact = {
			ambitious = major_stress_impact_gain
			diligent = massive_stress_impact_gain
		}
		scope:steward = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -30
			}
		}
		scope:jester = {
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 30
			}
		}
		if = {
			limit = {
				exists = scope:seneschal
			}
			scope:seneschal = {
				add_opinion = {
					target = root
					modifier = disappointed_opinion
					opinion = -30
				}
			}
		}
		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
		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
			}
		}
	}
}

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

hold_court.6130 = {
	type = court_event
	title = hold_court.6130.t
	desc = {
		desc = hold_court.6130.desc
		triggered_desc = {
			trigger = {
				exists = scope:tutor
			}
			desc = hold_court.6130.desc_tutor
		}
		triggered_desc = {
			trigger = {
				exists = scope:m_hunt
			}
			desc = hold_court.6130.desc_hunt
		}
	}
	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
			}
		}
		if = {
			limit = {
				employs_court_position = court_tutor_court_position
				any_court_position_holder = {
					type = court_tutor_court_position
					has_court_event_flag = no
					is_available_ai_adult = yes
				}
				any_child = {
					hold_court_6130_valid_child_trigger = yes
				}
			}
			random_court_position_holder = {
				type = court_tutor_court_position
				limit = {
					has_court_event_flag = no
					is_available_ai_adult = yes
				}
				save_scope_as = tutor
				court_event_character_flag_effect = yes
			}
			random_child = {
				limit = {
					hold_court_6130_valid_child_trigger = yes
					is_heir_of = root
				}
				alternative_limit = { hold_court_6130_valid_child_trigger = yes }
				save_scope_as = 6130_tutored
			}
		}
		if = {
			limit = {
				employs_court_position = master_of_hunt_court_position
				any_court_position_holder = {
					type = master_of_hunt_court_position
					has_court_event_flag = no
					is_available_ai_adult = yes
				}
			}
			random_court_position_holder = {
				type = master_of_hunt_court_position
				limit = {
					has_court_event_flag = no
					is_available_ai_adult = yes
				}
				save_scope_as = m_hunt
			}
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	#Option A: yes
	option = {
		name = hold_court.6130.a
		trigger = {
			NOR = {
				exists = scope:tutor
				exists = scope:m_hunt
			}
			trigger_if = {
				limit = {
					is_ai = yes
				}
				short_term_gold >= major_gold_value
			}
		}
		remove_short_term_gold = major_gold_value
		custom_tooltip = hold_court.6130.a.tt
		trigger_event = {
			id = hold_court.6131
			days = { 93 171 }
		}
		add_character_flag = {
			flag = 6130_has_done_cadastre
			years = 20
		}
		stress_impact = {
			lazy = medium_stress_gain
			greedy = major_stress_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				gold < major_gold_value
				add = -100
			}
			modifier = {
				has_trait = lazy
				add = -50
			}
			modifier = {
				has_trait = greedy
				add = -75
			}
			ai_value_modifier = {
				ai_greed = -0.25
				ai_rationality = 0.25
			}
		}
	}

	#Option B: yes with tutor-tutoree
	option = {
		name = hold_court.6130.b
		trigger = {
			exists = scope:tutor
			trigger_if = {
				limit = {
					is_ai = yes
				}
				short_term_gold >= major_gold_value
			}
		}
		remove_short_term_gold = major_gold_value
		custom_tooltip = hold_court.6130.b.tt
		trigger_event = {
			id = hold_court.6131
			days = { 93 171 }
		}
		add_character_flag = {
			flag = 6130_has_done_cadastre
			years = 20
		}
		stress_impact = {
			lazy = medium_stress_gain
			greedy = major_stress_gain
		}
		scope:tutor = {
			save_scope_as = 6130_helper
		}
		ai_chance = {
			base = 150
			modifier = {
				gold < major_gold_value
				add = -150
			}
			modifier = {
				has_trait = lazy
				add = -50
			}
			modifier = {
				has_trait = greedy
				add = -75
			}
			ai_value_modifier = {
				ai_greed = -0.25
				ai_rationality = 0.25
			}
		}
	}

	#Option C: yes with master of hunt
	option = {
		name = hold_court.6130.c
		trigger = {
			exists = scope:m_hunt
			trigger_if = {
				limit = {
					is_ai = yes
				}
				short_term_gold >= major_gold_value
			}
		}
		remove_short_term_gold = major_gold_value
		custom_tooltip = hold_court.6130.b.tt
		trigger_event = {
			id = hold_court.6131
			days = { 93 171 }
		}
		add_character_flag = {
			flag = 6130_has_done_cadastre
			years = 20
		}
		stress_impact = {
			lazy = medium_stress_gain
			greedy = major_stress_gain
		}
		scope:m_hunt = {
			save_scope_as = 6130_helper
		}
		ai_chance = {
			base = 150
			modifier = {
				gold < major_gold_value
				add = -150
			}
			modifier = {
				has_trait = lazy
				add = -50
			}
			modifier = {
				has_trait = greedy
				add = -75
			}
			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 = {
				exists = scope:tutor
			}
			scope:tutor = {
				add_opinion = {
					target = root
					modifier = disappointed_opinion
					opinion = -10
				}
			}
			if = {
				limit = {
					scope:6130_tutored = {
						OR = {
							has_trait = diligent
							has_trait = just
							has_trait = intellect_good
							has_focus = education_stewardship
						}
					}
				}
				scope:6130_tutored = {
					add_opinion = {
						target = root
						modifier = disappointed_opinion
						opinion = -10
					}
				}
			}
		}
		if = {
			limit = {
				exists = scope:m_hunt
			}
			scope:m_hunt = {
				add_opinion = {
					target = root
					modifier = disappointed_opinion
					opinion = -10
				}
			}
		}
		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:tutor }
			scope:tutor = {
				clear_court_event_participation = yes
			}
			scope:6130_tutored = {
				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 = {
		desc = hold_court.6131.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:6130_helper
					scope:6130_helper = {
						is_alive = yes
						this = scope:tutor
					}
					scope:6130_tutored = {
						is_alive = yes
					}
				}
				desc = hold_court.6131.desc_tutor
			}
			triggered_desc = {
				trigger = {
					exists = scope:6130_helper
					scope:6130_helper = {
						is_alive = yes
						this = scope:m_hunt
					}
				}
				desc = hold_court.6131.desc_hunt
			}
			triggered_desc = {
				trigger = {
					exists = scope:6130_helper
					scope:6130_helper = {
						is_alive = no
					}
				}
				desc = hold_court.6131.desc_dead
			}
		}
	}
	theme = court
	right_portrait = {
		character = scope:6131_proposer
		animation = personality_rational
	}
	lower_left_portrait = scope:6130_helper

	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
		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:6131_proposer = {
			add_prestige = minor_prestige_gain
		}
		if = {
			limit = {
				exists = scope:6130_helper
				scope:6130_helper = {
					is_alive = yes
					this = scope:tutor
				}
				scope:6130_tutored = {
					is_alive = yes
				}
			}
			scope:6130_helper = {
				add_prestige = minor_prestige_gain
			}
			scope:6130_tutored = {
				add_stewardship_skill = 3
			}
		}
		if = {
			limit = {
				exists = scope:6130_helper
				scope:6130_helper = {
					is_alive = yes
					this = scope:m_hunt
				}
			}
			every_held_county = {
				custom = custom.every_held_county
				add_county_modifier = {
					modifier = 6131_mapped_wilderness_county_modifier
					years = 10
				}
			}
		}
		add_prestige = medium_prestige_gain
	}
}

##################################################
# 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 = {
	#AGOT Modified
	# terrain = forest
	# geographical_region = world_europe
	hunt_animal_bear_trigger = yes
}

scripted_trigger hold_court_6140_india_trigger = {
	#AGOT Modified
	# terrain = jungle
	# geographical_region = world_india
	hunt_animal_tiger_trigger = yes
}

scripted_trigger hold_court_6140_africa_trigger = {
	#AGOT Modified
	# OR = {
	# 	terrain = jungle
	# 	terrain = desert_mountains
	# 	terrain = oasis
	# 	terrain = drylands
	# }
	# geographical_region = world_africa
	hunt_animal_lion_trigger = yes
}

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 = {
										add_trait = maimed
									}
									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

##################################################
# The End Is Nigh!
# by Claudia Baldassi
# 6150
##################################################

# Millenarian preacher seeks audience to proclaim that the end is nigh and that you must now act before it is too late to save yourself and your kingdom. #

scripted_trigger hold_court_6150_valid_county_trigger = {
	OR = {
		county_control < medium_county_control
		any_county_province = {
			OR = {
				has_province_modifier = recently_looted_modifier
				has_province_modifier = disease_spreading_modifier
				has_province_modifier = winter_harsh_modifier
			}
		}
		has_county_modifier = county_corruption_bandits_rampant_modifier
		has_county_modifier = county_corruption_unsafe_highways_modifier
		has_county_modifier = county_corruption_lack_of_sheriffs_modifier
		has_county_modifier = county_corruption_thieves_guild_modifier
		has_county_modifier = held_human_sacrifice_fp1_modifier
	}
}

scripted_trigger hold_court_6150_valid_politics_trigger = {
	OR = {
		any_neighboring_top_liege_realm_owner = {
			hold_court_6090_valid_county_trigger = yes
		}
		#AGOT Disabled, no holy wars
		# faith = {
		# 	has_variable = 6150_lost_ghw_recently
		# }
		any_realm_county = {
			percent >= 0.7
			hold_court_6090_valid_county_trigger = yes
		}
	}
}

hold_court.6150 = {
	type = court_event
	title = hold_court.6150.t
	desc = {
		desc = hold_court.6150.desc
		triggered_desc = {
			trigger = {
				exists = scope:6150_county
			}
			desc = hold_court.6150.desc_county
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:6150_county
					scope:6150_county = {
						OR = {
							county_control <= medium_county_control
							has_county_modifier = county_corruption_bandits_rampant_modifier
							has_county_modifier = county_corruption_unsafe_highways_modifier
							has_county_modifier = county_corruption_lack_of_sheriffs_modifier
							has_county_modifier = county_corruption_thieves_guild_modifier
						}
					}
				}
				desc = hold_court.6150.desc_unsafety
			}
			triggered_desc = {
				trigger = {
					exists = scope:6150_county
					scope:6150_county = {
						any_county_province = {
							OR = {
								has_province_modifier = disease_spreading_modifier
								has_province_modifier = winter_harsh_modifier
							}
						}
					}
				}
				desc = hold_court.6150.desc_nature
			}
			triggered_desc = {
				trigger = {
					exists = scope:6150_county
					scope:6150_county = {
						any_county_province = {
							has_province_modifier = recently_looted_modifier
						}
					}
				}
				desc = hold_court.6150.desc_looting
			}
			triggered_desc = {
				trigger = {
					OR = {
						any_realm_county = {
							percent >= 0.7
							hold_court_6090_valid_county_trigger = yes
						}
						any_neighboring_top_liege_realm_owner = {
							hold_court_6090_valid_county_trigger = yes
						}
					}
				}
				desc = hold_court.6150.desc_infidels
			}
			#AGOT Disabled, no holy wars
			# triggered_desc = {
			# 	trigger = {
			# 		faith = {
			# 			has_variable = 6150_lost_ghw_recently
			# 		}
			# 	}
			# 	desc = hold_court.6150.desc_lost_hgw
			# }
			triggered_desc = {
				trigger = {
					scope:6150_preacher = {
						OR = {
							has_trait = lunatic_1
							has_trait = lunatic_genetic
							has_trait = possessed_1
							has_trait = possessed_genetic
							has_trait = lifestyle_mystic
						}
					}
				}
				desc = hold_court.6150.desc_visions
			}
			triggered_desc = {
				trigger = {
					scope:6150_preacher = {
						has_trait = devoted
					}
				}
				desc = hold_court.6150.desc_monk
			}
			desc = hold_court.6150.desc_fallback
		}
		first_valid = {
			#AGOT Disabled
			# triggered_desc = {
			# 	trigger = {
			# 		faith.religion = religion:christianity_religion
			# 	}
			# 	desc = hold_court.6150.desc_christianism
			# }
			# triggered_desc = {
			# 	trigger = {
			# 		faith.religion = religion:buddhism_religion
			# 	}
			# 	desc = hold_court.6150.desc_buddhism
			# }
			# triggered_desc = {
			# 	trigger = {
			# 		faith.religion = religion:islam_religion
			# 	}
			# 	desc = hold_court.6150.desc_islam
			# }
			# triggered_desc = {
			# 	trigger = {
			# 		faith.religion = religion:judaism_religion
			# 	}
			# 	desc = hold_court.6150.desc_judaism
			# }
			# triggered_desc = {
			# 	trigger = {
			# 		faith.religion = religion:germanic_religion
			# 	}
			# 	desc = hold_court.6150.desc_germanic
			# }
			# triggered_desc = {
			# 	trigger = {
			# 		faith.religion = religion:hinduism_religion
			# 	}
			# 	desc = hold_court.6150.desc_hinduism
			# }
			# triggered_desc = {
			# 	trigger = {
			# 		faith.religion = religion:zoroastrianism_religion
			# 	}
			# 	desc = hold_court.6150.desc_zoroastrianism
			# }
			desc = hold_court.6150.desc_religion_fallback
		}
		desc = hold_court.6150.desc_solution
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:6150_preacher = {
						has_trait = celibate
					}
				}
				desc = hold_court.6150.desc_celibacy
			}
			triggered_desc = {
				trigger = {
					scope:6150_preacher = {
						has_trait = wrathful
					}
				}
				desc = hold_court.6150.desc_burn
			}
			triggered_desc = {
				trigger = {
					scope:6150_preacher = {
						has_trait = temperate
					}
				}
				desc = hold_court.6150.desc_alcohol
			}
			triggered_desc = {
				trigger = {
					scope:6150_preacher = {
						has_trait = reclusive
					}
				}
				desc = hold_court.6150.desc_reclusive
			}
			triggered_desc = {
				trigger = {
					scope:6150_preacher = {
						has_trait = flagellant
					}
				}
				desc = hold_court.6150.desc_flagellant
			}
			triggered_desc = {
				trigger = {
					scope:6150_preacher = {
						has_trait = inappetetic
					}
				}
				desc = hold_court.6150.desc_eating
			}
		}
		desc = hold_court.6150.desc_end
	}
	theme = court
	court_scene = {
		button_position_character = scope:6150_preacher
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:6150_preacher = {
				group = petitioners_group
				animation = personality_zealous
			}
		}
	}

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

	cooldown = { years = 20 }

	weight_multiplier = {
		base = 1
		modifier = {
			factor = 0.5
		}
		modifier = {
			factor = 1.5
			any_realm_county = {
				hold_court_6150_valid_county_trigger = yes
			}
		}
		modifier = {
			factor = 2
			hold_court_6150_valid_politics_trigger = yes
		}
		modifier = {
			factor = 1.5
			culture = { has_cultural_tradition = tradition_mendicant_mystics}
		}
		#AGOT Modified
		# modifier = {
		# 	factor = 2
		# 	faith.religion = religion:christianity_religion
		# 	current_year < 1001
		# 	current_year >= 990
		# }

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

	immediate = {
		create_character = {
			location = root.capital_province
			template = millenarian_template
			save_scope_as = 6150_preacher
		}
		scope:6150_preacher = {
			court_event_character_flag_effect = yes
		}
		if = {
			limit = {
				any_realm_county = {
					hold_court_6150_valid_county_trigger = yes
				}
			}
			random_realm_county = {
				limit = {
					hold_court_6150_valid_county_trigger = yes
				}
				save_scope_as = 6150_county
			}
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	#Option A: follow advice
	option = {
		name = hold_court.6150.a
		add_piety = major_piety_gain
		if = {
			limit = {
				scope:6150_preacher = {
					has_trait = celibate
				}
			}
			if = {
				limit = { NOT = { has_trait = celibate } }
				add_trait = celibate
			}
			else = {
				custom_tooltip = hold_court.6150.a.tt
			}
			stress_impact = {
				chaste = medium_stress_loss
				lustful = major_stress_gain
				rakish = massive_stress_gain
			}
		}
		if = {
			limit = {
				scope:6150_preacher = {
					has_trait = wrathful
				}
			}
			if = {
				limit = {
					exists = scope:6150_county 
				}
				scope:6150_county = {
					save_scope_as = 6150_heretics_p
				}
			}
			else = {
				random_sub_realm_county = {
					save_scope_as = 6150_heretics_p
				}
			}
			custom_tooltip = hold_court.6150.a.wrath
			scope:6150_heretics_p = {
				change_development_level = -5
			}
			stress_impact = {
				compassionate = major_stress_gain
			}
		}
		if = {
			limit = {
				scope:6150_preacher = {
					has_trait = temperate
				}
			}
			add_character_modifier = {
				modifier = court_no_wine_modifier
				days = 3650
			}

			stress_impact = {
				gluttonous = major_stress_gain
			}
		}
		if = {
			limit = {
				scope:6150_preacher = {
					has_trait = reclusive
				}
			}
			if = {
				limit = { NOT = { has_trait = reclusive } }
				add_trait = reclusive
			}
			else = {
				custom_tooltip = hold_court.6150.a.tt
			}
			stress_impact = {
				shy = medium_stress_loss
				diligent = major_stress_gain
				gregarious = massive_stress_gain
			}
		}
		if = {
			limit = {
				scope:6150_preacher = {
					has_trait = flagellant
				}
			}
			if = {
				limit = { NOT = { has_trait = flagellant } }
				add_trait = flagellant
			}
			else = {
				custom_tooltip = hold_court.6150.a.tt
			}
		}
		if = {
			limit = {
				scope:6150_preacher = {
					has_trait = inappetetic
				}
			}
			if = {
				limit = { NOT = { has_trait = inappetetic } }
				add_trait = inappetetic
			}
			else = {
				custom_tooltip = hold_court.6150.a.tt
			}
			stress_impact = {
				gluttonous = massive_stress_gain
			}
		}
		stress_impact = {
			cynical = major_stress_gain
			zealous = major_stress_loss
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = 1
				ai_energy = 0.5
			}
			modifier = {
				has_trait = cynical
				add = -75
			}
			modifier = {
				has_trait = zealous
				add = 75
			}
			#AGOT Added, don't become celibate if you have no heir
			modifier = {
				factor = 0
				scope:6150_preacher = {
					has_trait = celibate
				}
				any_child = { is_alive = yes count < 1 }
			}
		}
	}

	#Option B: make chaplain
	option = {
		name = hold_court.6150.b
		trigger = {
			scope:6150_preacher = {
				can_be_court_chaplain_trigger = { COURT_OWNER = root }
			}
			trigger_if = {
				limit = {
					exists = cp:councillor_court_chaplain
				}
				cp:councillor_court_chaplain = {
					can_be_fired_from_council_trigger = { COURT_OWNER = root }
				}
			}
		}
		if = {
			limit = {
				exists = cp:councillor_court_chaplain
			}
			cp:councillor_court_chaplain = {
				save_scope_as = old_chaplain
			}
			fire_councillor = scope:old_chaplain
		}
		if = {
			limit = {
				scope:6150_preacher = {
					NOT = {
						is_courtier_of = root
					}
				}
			}
			add_courtier = scope:6150_preacher
		}
		assign_councillor_type = {
			type = councillor_court_chaplain
			target = scope:6150_preacher
		}
		add_piety = medium_piety_gain
		stress_impact = {
			cynical = major_stress_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = 1
			}
			modifier = {
				has_trait = cynical
				add = -75
			}
		}
	}

	#Option C: heretic!!
	option = {
		name = hold_court.6150.c
		scope:6150_preacher = {
			# AGOT Added - Burned
			add_trait = burned
			add_trait_xp = {
				trait = burned
				value = 100
			}
			death = {
				death_reason = death_burned
				killer = root
			}
		}
		add_piety = medium_piety_gain
		stress_impact = {
			compassionate = major_stress_gain
		}
		add_dread = medium_dread_gain
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = 1
			}
			modifier = {
				has_trait = compassionate
				add = -75
			}
			modifier = {
				has_trait = zealous
				add = 75
			}
		}
	}

	#Option D: kick them out
	option = {
		name = hold_court.6150.d
		add_piety = medium_piety_loss
		stress_impact = {
			cynical = major_stress_loss
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = -1
			}
			modifier = {
				has_trait = cynical
				add = 75
			}
			modifier = {
				has_trait = zealous
				add = -75
			}
		}
	}

	after = {
		scope:6150_preacher = {
			clear_court_event_participation = yes
			if = {
				limit = {
					is_alive = yes
					NOT = { has_council_position = councillor_court_chaplain }
				}
				hidden_effect = {
					death = {
						death_reason = death_vanished
					}
				}
			}
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

##################################################
# 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
	#AGOT Disabled
	#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
		}
		#AGOT Disabled
		# 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
	#AGOT Disabled
	# option = {
	# 	name = hold_court.6160.d
	# 	trigger = {
	# 		exists = scope:almoner
	# 		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
	# 	}
	# 	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_short_term_gold = {
			target = scope:6160_vassal
			gold = medium_gold_value
		}
		scope:6160_vassal = {
			add_character_modifier = {
				modifier = 6160_seneschal_help_modifier
				years = 5
			}
		}
		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_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 = -20
		}
		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
		}
		#AGOT Disabled
		# 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
		}
		AND = {
			exists = betrothed
			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
		NOT = {
			this = scope:vassal_scope
		}
	}
}

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
		}
		if = {
			limit = {
				scope:6170_relative = {
					can_set_relation_friend_trigger = { CHARACTER = scope:6170_vassal }
				}
			}
			scope:6170_relative = {
				progress_towards_friend_effect = {
					REASON = friend_helped_free_from_prison
					CHARACTER = scope:6170_vassal
 					OPINION = default_friend_opinion
 				}
			}
		}
		reverse_add_opinion = {
			target = scope:6170_rival
			modifier = angry_opinion
			opinion = -30
		}
		if = {
			limit = {
				scope:6170_rival = {
					can_set_relation_rival_trigger = { CHARACTER = scope:6170_vassal }
				}
			}
			scope:6170_rival = {
				set_relation_rival = {
					target = scope:6170_vassal
					reason = rival_had_relative_freed
				}
			}
		}
		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 B: they have their reasons
	option = {
		name = hold_court.6170.b
		reverse_add_opinion = {
			target = scope:6170_vassal
			modifier = disappointed_opinion
			opinion = -20
		}
		reverse_add_opinion = {
			target = scope:6170_relative
			modifier = disappointed_opinion
			opinion = -20
		}
		reverse_add_opinion = {
			target = scope:6170_rival
			modifier = grateful_opinion
			opinion = 50
		}
		if = {
			limit = {
				scope:6170_rival = {
					can_set_relation_potential_friend_trigger = { CHARACTER = root }
				}
			}
			scope:6170_rival = {
				set_relation_potential_friend = root
			}
		}
		stress_impact = {
			fickle = medium_stress_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = fickle
				add = -50
			}
		}
	}

	#Option C: if possible, dungeon to house arrest
	option = {
		name = hold_court.6170.c
		trigger = {
			scope:6170_relative = {
				is_in_prison_type = dungeon
			}
		}
		scope:6170_relative = {
			change_prison_type = house_arrest
		}
		reverse_add_opinion = {
			target = scope:6170_vassal
			modifier = grateful_opinion
			opinion = 10
		}
		reverse_add_opinion = {
			target = scope:6170_relative
			modifier = grateful_opinion
			opinion = 20
		}
		stress_impact = {
			callous = medium_stress_gain
			torturer = medium_stress_gain
			arbitrary = medium_stress_gain
			sadistic = medium_stress_gain
			vengeful = medium_stress_gain
			fickle = medium_stress_gain
		}
		ai_chance = {
			base = 120
			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
			}
			modifier = {
				has_trait = fickle
				add = -50
			}
		}
	}

	#Option D: cut the head off the snake (literally)
	option = {
		name = hold_court.6170.d
		trigger = {
			OR = {
				has_trait = callous
				has_trait = torturer
				has_trait = wrathful
				has_trait = arbitrary
				has_trait = sadistic
				has_trait = fickle
				has_trait = vengeful
			}
		}
		scope:6170_relative = {
			death = {
				death_reason = death_execution
				killer = scope:6170_vassal
			}
		}
		reverse_add_opinion = {
			target = scope:6170_vassal
			modifier = cruelty_opinion
			opinion = -50
		}
		add_dread = major_dread_gain
		if = {
			limit = {
				scope:6170_vassal = {
					can_set_relation_rival_trigger = { CHARACTER = root }
				}
			}
			scope:6170_vassal = {
				set_relation_rival = {
					target = root
					reason = rival_executed_relative
				}
			}
		}
		ai_chance = {
			base = 150
			ai_value_modifier = {
				ai_compassion = -0.5
			}
		}
	}

	#Option E: I don't care
	option = {
		name = hold_court.6170.e
		reverse_add_opinion = {
			target = scope:6170_vassal
			modifier = disappointed_opinion
			opinion = -20
		}
		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
	}
}

#################################
# The Shadow Behind the Throne	#
# by Claudia Baldassi			#
# 6180							#
#################################

# Someone is concerned/jealous of the growing power and influence of the chief eunuch #

scripted_trigger hold_court_6180_valid_enemy_trigger = {
	has_court_event_flag = no
	is_available_ai_adult = yes
	NOR = {
		has_friendly_relationship_trigger = { CHARACTER = scope:c_eunuch }
		is_close_or_extended_family_of = scope:c_eunuch
		has_trait = eunuch
	}
}

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

	court_scene = {
		button_position_character = scope:6180_enemy
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:c_eunuch = {
				group = petitioners_group
				animation = anger
			}
			scope:6180_enemy = {
				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 = chief_eunuch_court_position
		any_court_position_holder = {
			type = chief_eunuch_court_position
			has_court_event_flag = no
			is_available_ai_adult = yes
		}
	}

	weight_multiplier = {
		base = 1

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

	immediate = {
		random_court_position_holder = {
			type = chief_eunuch_court_position
			limit = {
				has_court_event_flag = no
				is_available_ai_adult = yes
			}
			save_scope_as = c_eunuch
			court_event_character_flag_effect = yes
		}
		scope:c_eunuch = {
			every_relation = {
				type = rival
				limit = { is_available_ai_adult = yes }
				add_to_list = 6180_eunuch_enemies
			}
			every_relation = {
				type = potential_rival
				limit = { is_available_ai_adult = yes }
				add_to_list = 6180_eunuch_enemies
			}
		}
		every_court_position_holder = {
			limit = {
				hold_court_6180_valid_enemy_trigger = yes
			}
			add_to_list = 6180_eunuch_enemies
		}
		every_councillor = {
			limit = {
				hold_court_6180_valid_enemy_trigger = yes
			}
			add_to_list = 6180_eunuch_enemies
		}
		every_close_family_member = {
			limit = {
				hold_court_6180_valid_enemy_trigger = yes
			}
			add_to_list = 6180_eunuch_enemies
		}
		every_powerful_vassal = {
			limit = {
				hold_court_6180_valid_enemy_trigger = yes
			}
			add_to_list = 6180_eunuch_enemies
		}
		random_in_list = {
			list = 6180_eunuch_enemies
			limit = {
				has_court_event_flag = no
			}
			weight = {
				base = 1
				modifier = {
					opinion = {
						target = scope:c_eunuch
						value < 0
					}
					add = 2
				}
				modifier = {
					opinion = {
						target = scope:c_eunuch
						value < -50
					}
					add = 4
				}
				modifier = {
					has_relation_potential_rival = scope:c_eunuch
					add = 3
				}
				modifier = {
					has_relation_rival = scope:c_eunuch
					add = 5
				}
				modifier = {
					has_relation_nemesis = scope:c_eunuch
					add = 10
				}
				modifier = {
					is_male = yes
					add = 10
				}
			}
			save_scope_as = 6180_enemy
			save_scope_as = recipient		#needed for the castrate effect below
			court_event_character_flag_effect = yes
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	#Option A: accept concerns - you will rely less on the eunuch
	option = {
		name = hold_court.6180.a
		scope:c_eunuch = {
			add_opinion = {
				target = root
				modifier = insult_opinion
				opinion = -15
			}
		}
		scope:6180_enemy = {
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 15
			}
		}
		add_prestige = medium_prestige_gain
		change_current_court_grandeur = minor_court_grandeur_loss
		add_character_modifier = {
			modifier = 6180_scorned_eunuchs_modifier
			years = 5
		}
		stress_impact = {
			trusting = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = trusting
				add = -75
			}
			modifier = {
				has_friendly_relationship_trigger = { CHARACTER = scope:c_eunuch }
				add = -25
			}
			modifier = {
				has_trait = paranoid
				add = 50
			}
		}
	}

	#Option B: no more manipulations! Remove the eunuch
	option = {
		name = hold_court.6180.b
		scope:c_eunuch = {
			add_opinion = {
				target = root
				modifier = insult_opinion
				opinion = -30
			}
		}
		scope:6180_enemy = {
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 30
			}
		}
		every_courtier_or_guest = {
			custom = 6140_every_courtier_or_guest
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 5
			}
		}
		revoke_court_position = {
			recipient = scope:c_eunuch
			court_position = chief_eunuch_court_position
		}
		change_current_court_grandeur = medium_court_grandeur_loss
		stress_impact = {
			trusting = major_stress_impact_gain
			paranoid = major_stress_impact_loss
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = trusting
				add = -100
			}
			modifier = {
				has_friendly_relationship_trigger = { CHARACTER = scope:c_eunuch }
				add = -50
			}
			modifier = {
				has_trait = paranoid
				add = 100
			}
		}
	}

	#Option C: I trust the eunuch more than you!
	option = {
		name = hold_court.6180.c
		scope:c_eunuch = {
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 20
			}
		}
		scope:6180_enemy = {
			add_opinion = {
				target = root
				modifier = insult_opinion
				opinion = -20
			}
		}
		add_character_modifier = {
			modifier = 6180_trusting_eunuchs_modifier
			years = 5
		}
		change_current_court_grandeur = minor_court_grandeur_gain
		stress_impact = {
			paranoid = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				has_friendly_relationship_trigger = { CHARACTER = scope:c_eunuch }
				add = 50
			}
			modifier = {
				has_friendly_relationship_trigger = { CHARACTER = scope:c_eunuch }
				NOT = { has_friendly_relationship_trigger = { CHARACTER = scope:6180_enemy } }
				add = 100
			}
			modifier = {
				has_trait = paranoid
				add = -75
			}
			modifier = {
				has_trait = eunuch
				add = 100
			}
		}
	}

	#Option D: blasphemy! Eunuch is an angel sent by God!
	#AGOT Disabled
	# option = {
	# 	name = hold_court.6180.d
	# 	trigger = {
	# 		religion_has_angels_trigger = yes
	# 	}
	# 	scope:c_eunuch = {
	# 		add_opinion = {
	# 			target = root
	# 			modifier = pleased_opinion
	# 			opinion = 50
	# 		}
	# 	}
	# 	scope:6180_enemy = {
	# 		add_opinion = {
	# 			target = root
	# 			modifier = impious_opinion
	# 			opinion = -50
	# 		}
	# 	}
	# 	add_character_modifier = {
	# 		modifier = 6180_angel_eunuchs_modifier
	# 		years = 5
	# 	}
	# 	add_piety = major_piety_gain
	# 	stress_impact = {
	# 		cynical = major_stress_impact_gain
	# 	}
	# 	ai_chance = {
	# 		base = 100
	# 		modifier = {
	# 			has_friendly_relationship_trigger = { CHARACTER = scope:c_eunuch }
	# 			add = 20
	# 		}
	# 		ai_value_modifier = {
	# 			ai_zeal = 1
	# 		}
	# 	}
	# }

	#Option E: why don't you replace him then??
	option = {
		name = hold_court.6180.e
		trigger = {
			culture = {
				has_cultural_parameter = can_castrate_prisoners
			}
			OR = {
				has_trait = sadistic
				has_trait = callous
				has_trait = torturer
				has_trait = wrathful
				has_trait = vengeful
			}
			scope:6180_enemy = {
				is_male = yes
				NOT = { has_trait = eunuch }
			}
		}
		scope:6180_enemy = {
			add_trait = eunuch
			add_character_modifier = {
				modifier = recently_castrated
				years = 1
			}
		}
		add_dread = major_dread_gain
		torture_blind_castrate_opinion_effect = { VERB = castrated }
		stress_impact = {
			forgiving = major_stress_impact_gain
			calm = major_stress_impact_gain
			compassionate = massive_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = -1
			}
			modifier = {
				has_trait = sadistic
				add = 50
			}
			modifier = {
				has_trait = torturer
				add = 50
			}
		}
	}

	#Option F: unfounded concerns - dismissed
	option = {
		name = hold_court.6180.f
		scope:6180_enemy = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -5
			}
		}
		scope:c_eunuch = {
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 5
			}
		}
		ai_chance = {
			base = 80
			modifier = {
				has_trait = lazy
				add = 50
			}
			modifier = {
				has_trait = trusting
				add = 50
			}
		}
	}

	after = {
		scope:c_eunuch = {
			clear_court_event_participation = yes
		}
		scope:6180_enemy = {
			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_focus_or_focus_trait_trigger = { FOCUS = intrigue_intimidation_focus }
				has_focus_or_focus_trait_trigger = { FOCUS = learning_medicine_focus }
				has_trait = ambitious
				has_trait = cynical
				has_trait = callous
				has_trait = sadistic
				AND = {
					has_trait = lifestyle_physician
					has_trait_xp = {
						trait = lifestyle_physician
						value >= 100
					}
				}
			}
		}
	}

	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 = {
 					has_lifestyle = intrigue_lifestyle
 				}
 				add_intrigue_lifestyle_xp = medium_lifestyle_experience
 			}
 			else_if = {
 				limit = {
 					has_lifestyle = learning_lifestyle
 				}
 				add_learning_lifestyle_xp = medium_lifestyle_experience
 			}
 			else = {
 				add_intrigue_lifestyle_xp = minor_lifestyle_experience
 				add_learning_lifestyle_xp = minor_lifestyle_experience
 			}
 			if = {
 				limit = {
 					NAND = {
						has_trait = lifestyle_physician
						has_trait_xp = {
							trait = lifestyle_physician
							value >= 100
						}
					}
 				}
				random = {
					chance = 15
					physician_lifestyle_rank_up_effect = yes
				}
			}
 		}
 		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
 		if = {
 			limit = {
 				has_lifestyle = intrigue_lifestyle
 			}
 			add_intrigue_lifestyle_xp = medium_lifestyle_experience
 		}
 		else_if = {
 			limit = {
 				has_lifestyle = learning_lifestyle
 			}
 			add_learning_lifestyle_xp = medium_lifestyle_experience
 		}
 		else = {
 			add_intrigue_lifestyle_xp = minor_lifestyle_experience
 			add_learning_lifestyle_xp = minor_lifestyle_experience
 		}
 		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 = {
 					has_lifestyle = intrigue_lifestyle
 				}
 				add_intrigue_lifestyle_xp = medium_lifestyle_experience
 			}
 			else_if = {
 				limit = {
 					has_lifestyle = learning_lifestyle
 				}
 				add_learning_lifestyle_xp = medium_lifestyle_experience
 			}
 			else = {
 				add_intrigue_lifestyle_xp = minor_lifestyle_experience
 				add_learning_lifestyle_xp = minor_lifestyle_experience
 			}
 			if = {
 				limit = {
 					NAND = {
						has_trait = lifestyle_physician
						has_trait_xp = {
							trait = lifestyle_physician
							value >= 100
						}
					}
 				}
				random = {
					chance = 20
					physician_lifestyle_rank_up_effect = yes
				}
			}
 		}
 		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 C: fresh alive bodies are better...
	option = {
		name = hold_court.6190.c
		trigger = {
			OR = {
				has_trait = sadistic
				has_trait = callous
				has_trait = vengeful
				has_focus_or_focus_trait_trigger = { FOCUS = intrigue_intimidation_focus }
			}
		}
		hard_imprison_character_effect = {
 			TARGET = scope:6190_local
			IMPRISONER = root
 		}
 		add_dread = major_dread_gain
 		change_current_court_grandeur = medium_court_grandeur_loss
 		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 = scared_opinion
				opinion = -25
			}
		}
 		if = {
 			limit = {
 				has_lifestyle = intrigue_lifestyle
 			}
 			add_intrigue_lifestyle_xp = major_lifestyle_experience
 		}
 		else_if = {
 			limit = {
 				has_lifestyle = learning_lifestyle
 			}
 			add_learning_lifestyle_xp = major_lifestyle_experience
 		}
 		else = {
 			add_intrigue_lifestyle_xp = minor_lifestyle_experience
 			add_learning_lifestyle_xp = minor_lifestyle_experience
 		}
 		scope:physician = {
 			if = {
 				limit = {
 					has_lifestyle = intrigue_lifestyle
 				}
 				add_intrigue_lifestyle_xp = major_lifestyle_experience
 			}
 			else_if = {
 				limit = {
 					has_lifestyle = learning_lifestyle
 				}
 				add_learning_lifestyle_xp = major_lifestyle_experience
 			}
 			else = {
 				add_intrigue_lifestyle_xp = minor_lifestyle_experience
 				add_learning_lifestyle_xp = minor_lifestyle_experience
 			}
 			if = {
 				limit = {
 					NAND = {
						has_trait = lifestyle_physician
						has_trait_xp = {
							trait = lifestyle_physician
							value >= 100
						}
					} 					
 				}
				random = {
					chance = 25
					physician_lifestyle_rank_up_effect = yes
				}
			}
 		}
 		stress_impact = {
 			compassionate = major_stress_impact_gain
 			forgiving = major_stress_impact_gain
 			just = major_stress_impact_gain
 		}
 		ai_chance = {
 			base = 100
 			ai_value_modifier = {
 				ai_compassion = -1
 			}
 		}
	}

	#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
				NOT = {
					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 = -10
			}
		}
		capital_county = {
 			add_county_modifier = {
 				modifier = 6190_safe_graves_county_modifier
 				years = 10
 			}
 		}
 		every_courtier_or_guest = {
			custom = custom.every_courtier_and_guest
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -5
			}
		}
 		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
	}
}

#############################
# The Monster of X			#
# by Claudia Baldassi		#
# 6200						#
#############################

scripted_trigger hold_court_6200_valid_province_trigger = {
	#AGOT Modified
	# OR = {
	# 	AND = {
	# 		geographical_region = world_india
	# 		terrain = jungle
	# 	}
	# 	AND = {
	# 		geographical_region = world_africa
	# 		OR = {
	# 			terrain = jungle
	# 			terrain = forest
	# 			terrain = oasis
	# 			terrain = desert_mountains
	# 			terrain = drylands
	# 		}
	# 	}
	# 	AND = {
	# 		OR = {
	# 			geographical_region = world_europe
	# 			geographical_region = world_steppe
	# 			geographical_region = world_middle_east_persia
	# 		}
	# 		OR = {
	# 			terrain = forest
	# 			terrain = mountains
	# 			terrain = steppe
	# 			terrain = desert_mountains
	# 			terrain = taiga
	# 		}
	# 	}
	# }
	NOT = { agot_is_urban_terrain = yes }
}

# Petitioners have arrived from a local village. They are being hounded by a local beast #

hold_court.6200 = {
	type = court_event
	title = hold_court.6200.t
	desc = hold_court.6200.desc
	theme = court
	lower_left_portrait = scope:m_hunt
	lower_center_portrait = scope:champion
	cooldown = { years = 20 }

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

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

	trigger = {
		any_sub_realm_county = {
			title_province = {
				hold_court_6200_valid_province_trigger = yes
			}
		}
	}

	weight_multiplier = {
		base = 1

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

	immediate = {
		random_sub_realm_county = {
			limit = {
				title_province = {
					hold_court_6200_valid_province_trigger = yes
				}
			}
			title_province = { save_scope_as = 6200_province }
		}
		create_character = {
			location = scope:6200_province
			template = generic_peasant_character
			save_scope_as = 6200_peasant
		}
		scope:6200_peasant = {
			court_event_character_flag_effect = yes
			# Save scope to limit possible animals: big/small/dangerous/harmless/prowling
			select_local_animal_effect = { TYPE = dangerous } # Save scope to limit possible animals: any/big/small/dangerous/harmless/prowling
		}
		set_variable = {
			name = animal_type
			value = scope:6200_peasant.var:animal_type
		}
		random = {			#for funsies, have the Murderous Hare!
			chance = 0.1
			modifier = {
				add = 20
				scope:6200_peasant = { has_trait = lunatic }
			}
			set_variable = {
				name = animal_type
				value = flag:hare
			}
		}
		hidden_effect = { add_visiting_courtier = scope:6200_peasant }
		if = {
			limit = {
				employs_court_position = master_of_hunt_court_position
				any_court_position_holder = {
					type = master_of_hunt_court_position
					has_court_event_flag = no
					is_available_healthy_ai_adult = yes
				}
			}
			random_court_position_holder = {
				type = master_of_hunt_court_position
				limit = {
					has_court_event_flag = no
					is_available_healthy_ai_adult = yes
				}
				save_scope_as = m_hunt
				court_event_character_flag_effect = yes
			}
		}
		if = {
			limit = {
				employs_court_position = champion_court_position
				any_court_position_holder = {
					type = champion_court_position
					has_court_event_flag = no
					is_available_healthy_ai_adult = yes
				}
			}
			random_court_position_holder = {
				type = champion_court_position
				limit = {
					has_court_event_flag = no
					is_available_healthy_ai_adult = yes
				}
				save_scope_as = champion
				court_event_character_flag_effect = yes
			}
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	#Option A: Hire some hunters
	option = {
		name = hold_court.6200.a
		trigger = {
			trigger_if = {
				limit = {
					has_variable = animal_type
					OR = {
						var:animal_type = flag:dragon
						var:animal_type = flag:hare
					}
				}
				OR = {
					has_trait = lunatic
					has_trait = intellect_bad
				}
			}
			trigger_if = {
				limit = {
					is_ai = yes
				}
				short_term_gold >= major_gold_value
			}
		}
		remove_short_term_gold = medium_gold_value
		add_prestige = minor_prestige_gain
		stress_impact = {
			greedy = medium_stress_impact_gain
		}
		ai_chance = {
			ai_value_modifier = {
				ai_greed = -0.5
			}
		}
	}

	#Option B: Send Master of Hunt
	option = {
		name = hold_court.6200.b
		trigger = {
			exists = scope:m_hunt
			trigger_if = {
				limit = {
					has_variable = animal_type
					OR = {
						var:animal_type = flag:dragon
						var:animal_type = flag:hare
					}
				}
				OR = {
					has_trait = lunatic
					has_trait = intellect_bad
				}
			}
		}
		if = {
			limit = {
				NOR = {
					var:animal_type = flag:dragon
					var:animal_type = flag:hare
				}
			}
			scope:m_hunt = {
				duel = {
					skill = prowess
					value = average_skill_rating
					45 = {
						desc = hold_court.6200.b.success
						compare_modifier = {
							value = scope:duel_value
							multiplier = 2
						}
						root = {
							send_interface_toast = {
								title = hold_court.6200.b.success.tt
								left_icon = scope:m_hunt
								scope:6200_province.county = {
									add_county_modifier = {
										modifier = 6200_freed_by_beasts_county_modifier
										years = 5
									}
								}
								add_prestige = medium_prestige_gain
								change_current_court_grandeur = minor_court_grandeur_gain
							}
						}
					}
					45 = {
						desc = hold_court.6200.b.failure
						compare_modifier = {
							value = scope:duel_value
							multiplier = -2
						}
						root = {
							send_interface_toast = {
								title = hold_court.6200.b.failure.tt
								left_icon = scope:m_hunt
								scope:6200_province.county = {
									add_county_modifier = {
										modifier = 6200_plagued_by_beasts_county_modifier
										years = 5
									}
								}
								scope:m_hunt = {
									increase_wounds_effect = { REASON = hunting_accident }
								}
								add_prestige = minor_prestige_loss
								change_current_court_grandeur = minor_court_grandeur_gain
							}
						}
					}
					10 = {
						desc = hold_court.6200.b.crit_failure
						compare_modifier = {
							value = scope:duel_value
							multiplier = -4
						}
						root = {
							send_interface_toast = {
								title = hold_court.6200.b.crit_failure.tt
								left_icon = scope:m_hunt
								scope:m_hunt = {
									death = { death_reason = death_hunting_accident }
								}
								scope:6200_province.county = {
									add_county_modifier = {
										modifier = 6200_mhunt_killed_by_beasts_county_modifier
										years = 5
									}
								}
								add_prestige = medium_prestige_loss
								change_current_court_grandeur = minor_court_grandeur_loss
							}
						}
					}
				}
			}
		}
		else = {
			scope:m_hunt = {
				add_character_modifier = {
					modifier = 6200_wildgoose_modifier
					years = 5
				}
				add_opinion = {
					target = root
					modifier = annoyed_opinion
					opinion = -20
				}
			}
		}
		ai_chance = {
			base = 100
		}
	}

	#Option C: Send Champion
	option = {
		name = hold_court.6200.c
		trigger = {
			exists = scope:champion
			trigger_if = {
				limit = {
					has_variable = animal_type
					OR = {
						var:animal_type = flag:dragon
						var:animal_type = flag:hare
					}
				}
				OR = {
					has_trait = lunatic
					has_trait = intellect_bad
				}
			}
		}
		if = {
			limit = {
				NOR = {
					var:animal_type = flag:dragon
					var:animal_type = flag:hare
				}
			}
			scope:champion = {
				duel = {
					skill = prowess
					value = average_skill_rating
					45 = {
						desc = hold_court.6200.c.success
						compare_modifier = {
							value = scope:duel_value
							multiplier = 2
						}
						root = {
							send_interface_toast = {
								title = hold_court.6200.b.success.tt
								left_icon = scope:champion
								scope:6200_province.county = {
									add_county_modifier = {
										modifier = 6200_freed_by_beasts_county_modifier
										years = 5
									}
								}
								add_prestige = medium_prestige_gain
								change_current_court_grandeur = minor_court_grandeur_gain
							}
						}
					}
					45 = {
						desc = hold_court.6200.c.failure
						compare_modifier = {
							value = scope:duel_value
							multiplier = -2
						}
						root = {
							send_interface_toast = {
								title = hold_court.6200.b.failure.tt
								left_icon = scope:champion
								scope:6200_province.county = {
									add_county_modifier = {
										modifier = 6200_plagued_by_beasts_county_modifier
										years = 5
									}
								}
								scope:champion = {
									increase_wounds_effect = { REASON = hunting_accident }
								}
								add_prestige = minor_prestige_loss
								change_current_court_grandeur = minor_court_grandeur_gain
							}
						}
					}
					10 = {
						desc = hold_court.6200.c.crit_failure
						compare_modifier = {
							value = scope:duel_value
							multiplier = -4
						}
						root = {
							send_interface_toast = {
								title = hold_court.6200.b.crit_failure.tt
								left_icon = scope:champion
								scope:champion = {
									death = { death_reason = death_hunting_accident }
								}
								scope:6200_province.county = {
									add_county_modifier = {
										modifier = 6200_champion_killed_by_beasts_county_modifier
										years = 5
									}
								}
								add_prestige = medium_prestige_loss
								change_current_court_grandeur = minor_court_grandeur_loss
							}
						}
					}
				}
			}
		}
		else = {
			scope:champion = {
				add_character_modifier = {
					modifier = 6200_wildgoose_modifier
					years = 5
				}
				add_opinion = {
					target = root
					modifier = annoyed_opinion
					opinion = -20
				}
			}
		}
		ai_chance = {
			base = 100
		}
	}

	#Option D: A worthy challenge for me!
	option = {
		name = hold_court.6200.d
		trigger = {
			trigger_if = {
				limit = {
					has_variable = animal_type
					OR = {
						var:animal_type = flag:dragon
						var:animal_type = flag:hare
					}
				}
				OR = {
					has_trait = lunatic
					has_trait = intellect_bad
				}
			}
		}
		custom_tooltip = hold_court.6200.d.tt
		add_character_flag = {
			flag = had_6200_beasts_flag
			days = 35
		}
		trigger_event = {
			id = hold_court.6201
			days = 30
		}
		ai_chance = {
			base = 100
			modifier = {
				prowess >= 15
				add = 50
			}
			ai_value_modifier = {
				ai_boldness = 1
			}
		}
	}

	#Option E: Your problem
	option = {
		name = hold_court.6200.e
		if = {
			limit = {
				has_variable = animal_type
				NOR = {
					var:animal_type = flag:dragon
					var:animal_type = flag:hare
				}
			}
			scope:6200_province.county = {
				add_county_modifier = {
					modifier = 6200_menacing_wilderness_county_modifier
					years = 10
				}
			}
		}
		ai_chance = {
			base = 80
			ai_value_modifier = {
				ai_energy = -1
			}		
		}
	}

	after = {
		scope:6200_peasant = {
			clear_court_event_participation = yes
			silent_disappearance_effect = yes
		}
		if = {
			limit = { exists = scope:m_hunt }
			scope:m_hunt = {
				clear_court_event_participation = yes
			}
		}
		if = {
			limit = { exists = scope:champion }
			scope:champion = {
				clear_court_event_participation = yes
			}
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

hold_court.6201 = {
	type = character_event
	title = hold_court.6200.t
	desc = {
		desc = hold_court.6201.desc_start
		first_valid = {
			triggered_desc = {
				trigger = {
					OR = {
						var:animal_type = flag:dragon
						var:animal_type = flag:hare
					}
				}
				desc = hold_court.6201.desc_hare
			}
			desc = hold_court.6201.desc
		}
	}
	theme = court
	left_portrait = {
		character = root
		animation = personality_bold
	}
	lower_left_portrait = {
		trigger = { exists = scope:m_hunt }
		character = scope:m_hunt
	}

	trigger = {
		has_character_flag = had_6200_beasts_flag
	}

	# Challenge the beast!
	option = {
		name = hold_court.6201.a
		trigger = {
			NOR = {
				var:animal_type = flag:dragon
				var:animal_type = flag:hare
			}
		}
		duel = {
			skill = prowess
			value = average_skill_rating
			45 = {
				desc = hold_court.6201.a.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 2
				}
				send_interface_toast = {
					title = hold_court.6200.b.success.tt
					left_icon = root
					scope:6200_province.county = {
						add_county_modifier = {
							modifier = 6200_freed_by_beasts_county_modifier
							years = 5
						}
					}
					add_prestige = major_prestige_gain
					if = {
						limit = { has_trait = lifestyle_hunter }
						add_trait_xp = {
							trait = lifestyle_hunter
							track = hunter
							value = medium_trait_xp
						}
					}
					else = {
						add_trait = lifestyle_hunter
					}
					random = {
						chance = 5
						give_nickname = nick_the_hunter
					}
				}
			}
			50 = {
				desc = hold_court.6201.a.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -2
				}
				send_interface_toast = {
					title = hold_court.6200.b.failure.tt
					left_icon = root
					scope:6200_province.county = {
						add_county_modifier = {
							modifier = 6200_plagued_by_beasts_county_modifier
							years = 5
						}
					}
					increase_wounds_effect = { REASON = hunting_accident }
					add_prestige = medium_prestige_loss
				}
			}
			5 = {
				trigger = {
					NOT = { exists = scope:m_hunt }
				}
				desc = hold_court.6201.a.crit_failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -4
				}
				send_interface_toast = {
					title = hold_court.6200.b.crit_failure.tt
					left_icon = root
					death = { death_reason = death_hunting_accident }
					scope:6200_province.county = {
						add_county_modifier = {
							modifier = 6200_plagued_by_beasts_county_modifier
							years = 5
						}
					}
				}
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 0.5
			}
			modifier = {
				prowess >= 15
				add = 50
			}
		}
	}

	# You don't find the beast...
	option = {
		name = hold_court.6201.b
		trigger = {
			OR = {
				var:animal_type = flag:dragon
				var:animal_type = flag:hare
			}
		}
		add_prestige = medium_prestige_loss
		stress_impact = {
			base = medium_stress_impact_loss
		}
		ai_chance = {
			base = 100
		}
	}

	# Actually, nevermind...
	option = {
		name = hold_court.6201.c
		trigger = {
			NOR = {
				var:animal_type = flag:dragon
				var:animal_type = flag:hare
			}
		}
		custom_tooltip = hold_court.6201.c.tt
		scope:6200_province.county = {
			add_county_modifier = {
				modifier = 6200_menacing_wilderness_county_modifier
				years = 10
			}
		}
		add_prestige = major_prestige_loss
		stress_impact = {
			brave = massive_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = -0.5
			}
			modifier = {
				prowess < 15
				add = 50
			}
		}
	}

	after = {
		if = {
			limit = {
				is_alive = yes
				has_variable = animal_type
			}
			remove_variable = animal_type
		}
	}
}

#########################
# A Land of Barbarians	#
# 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 = 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 = {
	#AGOT MODIFIED
	#culture = {
	#	NOR = {
	#		this = root.culture
	#		any_parent_culture_or_above = {
	#			this = root.culture
	#			this = scope:parent
	#		}
	#	}
	#}
	trigger_if = {
		limit = {
			exists = scope:parent
		}
		culture = {
			NOR = {
				this = root.culture
				any_parent_culture_or_above = {
					this = root.culture
					this = scope:parent
				}
			}
		}
	}
	trigger_else = {
		culture = {
			NOR = {
				this = root.culture
				any_parent_culture_or_above = {
					this = root.culture
				}
			}
		}
	}
}

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
			}
		}
		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_short_term_gold = medium_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
		stress_impact = {
			greedy = major_stress_impact_gain
		}
		ai_chance = {
			base = 200
			modifier = {
				gold < medium_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
				}
			}
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -20
			}
		}
		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
			}
		}
	}

	#Option D: It's your problem
	option = {
		name = hold_court.6210.d
		scope:6210_vassal = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -30
			}
			if = {
				limit = {
					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: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
	}
}

#########################
# Studying the Dead		#
# by Claudia Baldassi	#
# 6220					#
#########################

# A vassal is furious as your Court Physician has been experimenting/practicing surgery on their newly-dead relative! Is this slander, or real? #

hold_court.6220 = {
	type = court_event
	title = hold_court.6220.t
	desc = hold_court.6220.desc
	theme = court
	lower_right_portrait = scope:6220_relative
	cooldown = { years = 10 }

	court_scene = {
		button_position_character = scope:6220_vassal
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:6220_vassal = {
				group = petitioners_group
				animation = anger
			}
			scope:physician = {
				group = petitioners_group
				animation = anger
			}
		}
	}

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

	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
		}
		any_vassal_or_below = {
			has_court_event_flag = no
			any_close_or_extended_family_member = {
				only_if_dead = yes
				days_since_death <= 90
			}
		}
	}

	weight_multiplier = {
		base = 1

		# 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
		}
		random_vassal_or_below = {
			limit = {
				has_court_event_flag = no
				any_close_or_extended_family_member = {
					only_if_dead = yes
					days_since_death <= 90
				}
			}
			save_scope_as = 6220_vassal
			court_event_character_flag_effect = yes
		}
		scope:6220_vassal = {
			random_close_or_extended_family_member = {
				only_if_dead = yes
				limit = {
					days_since_death <= 90
				}
				save_scope_as = 6220_relative
			}
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	#Option A: Slander! I trust the court physician
	option = {
		name = hold_court.6220.a
		scope:6220_vassal = {
			pay_short_term_gold = {
				target = scope:physician
				gold = medium_gold_value
			}
			if = {
				limit = {
					NOT = { has_relation_rival = root }
					can_set_relation_rival_trigger = { CHARACTER = root }
				}
				progress_towards_rival_effect = {
					CHARACTER = root
					REASON = rival_physician_slander
					OPINION = -40
				}
			}
			else = {
				add_opinion = {
					target = root
					modifier = insult_opinion
					opinion = -40
				}
			}
			if = {
				limit = {
					NOT = { has_relation_rival = scope:physician }
					can_set_relation_rival_trigger = { CHARACTER = scope:physician }
				}
				set_relation_rival = {
					target = scope:physician
					reason = rival_exhumed_relative
				}
			}
			else = {
				add_opinion = {
					target = scope:physician
					modifier = hate_opinion
					opinion = -40
				}
			}
		}
		scope:physician = {
			if = {
				limit = {
					NOT = { has_relation_friend = root }
					can_set_relation_friend_trigger = { CHARACTER = root }
				}
				set_relation_friend = { reason = friend_defended_honor_target_character_scope target = root }
			}
			else = {
				add_opinion = {
					target = root
					modifier = friendliness_opinion
					opinion = 40
				}
			}
		}
		stress_impact = {
			zealous = medium_stress_impact_gain
			just = medium_stress_impact_gain
			paranoid = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				add = -50
				has_trait = zealous
			}
			modifier = {
				add = -50
				has_trait = just
			}
			modifier = {
				add = -75
				has_trait = paranoid
			}
		}
	}

	#Option B: Horrible! Imprison
	option = {
		name = hold_court.6220.b
		revoke_court_position = {
			recipient = scope:physician
			court_position = court_physician_court_position
		}
		rightfully_imprison_character_effect = {
			TARGET = scope:physician
			IMPRISONER = root
		}
		add_piety = medium_piety_gain
		scope:6220_vassal = {
			if = {
				limit = {
					NOT = { has_relation_friend = root }
					can_set_relation_friend_trigger = { CHARACTER = root }
				}
				progress_towards_friend_effect = {
					REASON = friend_protected_dead_relatives_body
					CHARACTER = root
					OPINION = 40
				}
			}
			else = {
				add_opinion = {
					target = root
					modifier = grateful_opinion
					opinion = 40
				}
			}
		}
		scope:physician = {
			if = {
				limit = {
					NOT = { has_relation_rival = root }
					can_set_relation_rival_trigger = { CHARACTER = root }
				}
				progress_towards_rival_effect = {
					CHARACTER = root
					OPINION = -40
					REASON = rival_unjustified_imprisonment
				}
			}
			else = {
				add_opinion = {
					target = root
					modifier = insult_opinion
					opinion = -40
				}
			}
		}
		stress_impact = {
			cynical = medium_stress_impact_gain
			just = medium_stress_impact_gain
			trusting = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				add = -50
				has_trait = cynical
			}
			modifier = {
				add = -50
				has_trait = just
			}
			modifier = {
				add = -75
				has_trait = trusting
			}
		}
	}

	#Option C: Find the truth - intrigue challenge
	option = {
		name = hold_court.6220.c
		duel = {
			skill = intrigue
			target = scope:physician
			33 = {	#vassal is lying
				desc = hold_court.6220.c.vassal
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3
				}
				modifier = {
					factor = 1.2
					scope:6220_vassal.intrigue < scope:physician.intrigue
				}
				modifier = {
					factor = 1.5
					scope:6220_vassal = {
						OR = {
							has_trait = deceitful
							has_trait = paranoid
							has_relation_rival = scope:physician
						}
					}
				}
				send_interface_toast = {
					title = hold_court.6220.c.vassal
					left_icon = scope:6220_vassal
					scope:6220_vassal = {
						pay_short_term_gold = {
							target = scope:physician
							gold = medium_gold_value
						}
					}
					add_prestige = medium_prestige_gain
					change_current_court_grandeur = medium_court_grandeur_gain
				}
			}
			33 = {	#physician is lying
				desc = hold_court.6220.c.physician
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3
				}
				modifier = {
					factor = 1.2
					scope:6220_vassal.intrigue > scope:physician.intrigue
				}
				modifier = {
					factor = 1.5
					scope:physician = {
						OR = {
							has_trait = deceitful
							has_trait = cynical
							has_trait = callous
						}
					}
				}
				send_interface_toast = {
					title = hold_court.6220.c.physician
					left_icon = scope:physician
					revoke_court_position = {
						recipient = scope:physician
						court_position = court_physician_court_position
					}
					add_prestige = medium_prestige_gain
					change_current_court_grandeur = medium_court_grandeur_gain
				}
			}
			33 = {	#you have no clue
				desc = hold_court.6220.c.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3
				}
				send_interface_toast = {
					title = hold_court.6220.c.failure
					left_icon = scope:6220_vassal
					right_icon = scope:physician
					add_prestige = medium_prestige_loss
					change_current_court_grandeur = medium_court_grandeur_loss
				}
			}
		}
		stress_impact = {
			shy = medium_stress_impact_gain
			honest = medium_stress_impact_gain
			arbitrary = major_stress_impact_gain
			impatient = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 1
			}
			modifier = {
				add = -75
				has_trait = arbitrary
			}
			modifier = {
				add = -75
				has_trait = impatient
			}
			modifier = {
				add = -50
				has_trait = shy
			}
			modifier = {
				add = -50
				has_trait = honest
			}
		}
	}

	#Option D: So what?
	option = {
		name = hold_court.6220.d
		scope:6220_vassal = {
			if = {
				limit = {
					NOT = { has_relation_rival = root }
					can_set_relation_rival_trigger = { CHARACTER = root }
				}
				progress_towards_rival_effect = {
					CHARACTER = root
					REASON = rival_physician_whocares
					OPINION = -25
				}
			}
			else = {
				add_opinion = {
					target = root
					modifier = insult_opinion
					opinion = -25
				}
			}
			if = {
				limit = {
					NOT = { has_relation_rival = scope:physician }
					can_set_relation_rival_trigger = { CHARACTER = scope:physician }
				}
				progress_towards_rival_effect = {
					CHARACTER = scope:physician
					REASON = rival_physician_insulted
					OPINION = -25
				}
			}
			else = {
				add_opinion = {
					target = scope:physician
					modifier = hate_opinion
					opinion = -25
				}
			}
		}
		stress_impact = {
			compassionate = medium_stress_impact_gain
			zealous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				add = -50
				has_trait = compassionate
			}
			modifier = {
				add = -50
				has_trait = zealous
			}
			modifier = {
				add = 50
				has_trait = callous
			}
		}
	}

	after = {
		scope:physician = {
			clear_court_event_participation = yes
		}
		scope:6220_vassal = {
			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 = 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 = 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_short_term_gold = {
			target = scope:6230_vassal
			gold = medium_gold_value
		}
		reverse_add_opinion = {
			target = scope:6230_vassal
			modifier = grateful_opinion
			opinion = 20
		}
		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_development_level = -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_development_level = -5 }
						}
					}
				}
			}
		}
		ai_chance = {
			base = 100
		}
	}

	#Option F: kill the elephants
	option = {
		name = hold_court.6230.f
		#AGOT Disabled
		# trigger = {
		# 	NOT = { faith.religion = religion:hinduism_religion }
		# }
		#AGOT Disabled
		# if = {
		# 	limit = {
		# 		scope:6230_vassal = {
		# 			faith.religion = religion:hinduism_religion
		# 		}
		# 	}
		# 	reverse_add_opinion = {
		# 		target = scope:6230_vassal
		# 		modifier = impious_opinion
		# 		opinion = -20
		# 	}
		# }
		#AGOT Disabled
		# if = {
		# 	limit = {
		# 		scope:6230_province.county = {
		# 			faith.religion = religion:hinduism_religion
		# 		}
		# 	}
		# 	scope:6230_province.county = {
		# 		add_county_modifier = {
		# 			modifier = 6230_elephant_slayer_county_modifier
		# 			years = 5
		# 		}
		# 	}
		# }
		change_current_court_grandeur = medium_court_grandeur_gain
		stress_impact = {
			compassionate = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = -1
			}
			modifier = {
				has_trait = callous
				add = 25
			}
			modifier = {
				has_trait = sadistic
				add = 50
			}
		}
	}

	#AGOT Disabled
	#Option D: Ganesh leads them
	# option = {
	# 	name = hold_court.6230.d
	# 	trigger = {
	# 		faith.religion = religion:hinduism_religion
	# 	}
	# 	add_piety = major_piety_gain
	# 	reverse_add_opinion = {
	# 		target = scope:6230_vassal
	# 		modifier = disappointed_opinion
	# 		opinion = -10
	# 	}
	# 	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
		change_current_court_grandeur = minor_court_grandeur_loss
		reverse_add_opinion = {
			target = scope:6230_vassal
			modifier = disappointed_opinion
			opinion = -20
		}
		scope:6230_province.county = { change_development_level = -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
	}
}










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

##################################################
# 7000 - 7009	Rivals in Agreement
# 7010 - 7019	A Hero of the Frontier
# 7020 - 7029	Harbouring Exile
# 7030 - 7039	The Ravages of Peace
# 7040 - 7049	Frontier Fracas
# 7050 - 7059	Consequences of War
# 7060 - 7069	Who is That?
# 7070 - 7079	In Tithes of Trouble
##################################################

##################################################
# Rivals in Agreement
# by George Luff
# 7000 - 7009
##################################################

scripted_effect hold_court_7000_controversial_spouse = {
	if = { # faith
		limit = { 
			NOT = { scope:controversial_spouse.faith = scope:rival_1.faith }
			scope:rival_1.faith = scope:rival_2.faith
		}
		add_character_flag = {
			flag = hold_court_7000_heretic_spouse
			days = 30
		}
	}
	else_if = { # culture
		limit = {
			culture = scope:rival_1.culture
			NOT = { scope:controversial_spouse.culture = scope:rival_1.culture }
			scope:rival_1.culture = scope:rival_2.culture
		}
		add_character_flag = {
			flag = hold_court_7000_barbarian_spouse
			days = 30
		}
	}
	else_if = { # Lustful
		limit = { 
			scope:controversial_spouse = {
				OR = {
					has_trait = lustful
					has_trait = adulterer
					has_trait = fornicator
					has_trait = incestuous
				}
			}
		}
		add_character_flag = {
			flag = hold_court_7000_lustful_spouse
			days = 30
		}
	}
	else_if = { # Murderer/Kinslayer/Criminal
		limit = {
			scope:controversial_spouse = {
				OR = {
					has_trait = murderer
					has_trait = kinslayer
					has_trait = cannibal
					has_trait = deviant
				}
			}
		}
		add_character_flag = {
			flag = hold_court_7000_criminal_spouse
			days = 30
		}
	}
	else_if = { # Background
		limit = { scope:controversial_spouse = { has_dynasty = no } }
		add_character_flag = {
			flag = hold_court_7000_lowborn_spouse
			days = 30
		}
	}
	else = {
		add_character_flag = {
			flag = hold_court_7000_spouse_not_specific
			days = 30
		}
	}
}

scripted_effect hold_court_7000_penance_effect = {
	# add modifier that reduces their stats and health
	add_character_modifier = {
		modifier = hold_court_7000_doing_penance
		days = 365
	}

	# remove 1 sinful trait
	hidden_effect = { 
		if = {
			limit = { has_trait = lustful }
			remove_trait = lustful
		}
		else_if = {
			limit = { has_trait = adulterer }
			remove_trait = adulterer
		}
		else_if = {
			limit = { has_trait = fornicator }
			remove_trait = fornicator
		}
		else_if = { 
			limit = { has_trait = incestuous }
			remove_trait = incestuous
		}
		else_if = {
			limit = { has_trait = murderer }
			remove_trait = murderer
		}
		else_if = { 
			limit = { has_trait = kinslayer_1 }
			remove_trait = kinslayer_1
		}
		else_if = { 
			limit = { has_trait = kinslayer_2 }
			remove_trait = kinslayer_2
		}
		else_if = { 
			limit = { has_trait = kinslayer_3 }
			remove_trait = kinslayer_3
		}
		else_if = {
			limit = { has_trait = cannibal }
			remove_trait = cannibal
		}
		else_if = {
			limit = { has_trait = deviant }
			remove_trait = deviant
		}
	}
	add_piety = medium_piety_gain
}

scripted_trigger court_7000_rival_trigger = {
	has_court_event_flag = no
	any_relation = {
		type = rival
		has_court_event_flag = no
		top_liege = root
		NOT = { this = root }
	}
}

# You are accosted by two courtiers, who are normally antagonistic come to see you
hold_court.7000 = {
	type = court_event
	title = hold_court.7000.title
	desc = {
		triggered_desc = { # Tax Dispute
			trigger = {
				has_character_flag = hold_court_7000_tax_dispute
			}
			desc = hold_court.7000.taxes.desc
		}
		triggered_desc = { # Religious dispute
			trigger = {
				has_character_flag = hold_court_7000_religious_dispute
			}
			desc = hold_court.7000.religion.desc
		}
		triggered_desc = { # Culture dispute
			trigger = {
				has_character_flag = hold_court_7000_cultural_dispute
			}
			desc = hold_court.7000.culture.desc
		}
		triggered_desc = { # Faith of spouse
			trigger = {
				has_character_flag = hold_court_7000_heretic_spouse
			}
			desc = hold_court.7000.spouse_religion.desc
		}
		triggered_desc = { # Culture of spouse
			trigger = {
				has_character_flag = hold_court_7000_barbarian_spouse
			}
			desc = hold_court.7000.spouse_culture.desc
		}
		triggered_desc = { # Lustful spouse
			trigger = {
				has_character_flag = hold_court_7000_lustful_spouse
			}
			desc = hold_court.7000.spouse_lustful.desc
		}
		triggered_desc = { # Criminal spouse
			trigger = {
				has_character_flag = hold_court_7000_criminal_spouse
			}
			desc = hold_court.7000.spouse_criminal.desc
		}
		triggered_desc = { # Dynasty of spouse
			trigger = {
				has_character_flag = hold_court_7000_lowborn_spouse
			}
			desc = hold_court.7000.spouse_lowborn.desc
		}
		triggered_desc = { # Other spouse issue
			trigger = {
				has_character_flag = hold_court_7000_spouse_not_specific
			}
			desc = hold_court.7000.spouse_other.desc
		}
	}
	theme = court
	court_scene = {
		button_position_character = scope:rival_1
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:rival_1 = {
				group = petitioners_group
				animation = anger
			}
			scope:rival_2 = {
				group = petitioners_group
				animation = rage
			}
		}
	}

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

	trigger = {
		NOT = { has_character_flag = had_7000_hold_court_event }
		# Search vassals, then search courtiers
		OR = {
			any_vassal = { court_7000_rival_trigger = yes }
			any_courtier = { court_7000_rival_trigger = yes }
		}
	}

	immediate = {
		add_character_flag = {
			flag = had_7000_hold_court_event
			days = 1800
		}

		## Select people
		if = {
			limit = {
				any_vassal = { court_7000_rival_trigger = yes }
			}
			random_vassal = {
				limit = { court_7000_rival_trigger = yes }
				save_scope_as = rival_1
				court_event_character_flag_effect = yes
				random_relation = {
					type = rival
					limit = {
						has_court_event_flag = no
						top_liege = root
						NOT = { this = root }
					}
					save_scope_as = rival_2
					court_event_character_flag_effect = yes
				}
			}
		}
		else = {
			random_courtier = {
				limit = { court_7000_rival_trigger = yes }
				save_scope_as = rival_1
				court_event_character_flag_effect = yes
				random_relation = {
					type = rival
					limit = {
						has_court_event_flag = no
						top_liege = root
						NOT = { this = root }
					}
					save_scope_as = rival_2
					court_event_character_flag_effect = yes
				}
			}
		}

		## Select dispute
		random_list = { 
			20 = { # Taxes, default option
				add_character_flag = {
					flag = hold_court_7000_tax_dispute
					days = 30
				}
			}
			
			20 = { # Religion
				trigger = {
					NOT = { root.faith = scope:rival_1.faith }
					scope:rival_1.faith = scope:rival_2.faith
				}
				add_character_flag = {
					flag = hold_court_7000_religious_dispute
					days = 30
				}
			}

			20 = { # Culture
				trigger = {
					scope:rival_1.culture = scope:rival_2.culture
					NOT = { 
						culture = scope:rival_1.culture 
						has_character_flag = converted_culture_this_lifetime # Don't want this to get ridiculous
					}
				}
				add_character_flag = {
					flag = hold_court_7000_cultural_dispute
					days = 30
				}
			}

			40 = { # Choice of spouse
				trigger = { # Can't fire if no spouse
					exists = primary_spouse
				}
				primary_spouse = { save_scope_as = controversial_spouse }
				hold_court_7000_controversial_spouse = yes
			}
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = { # Diplomatically persuade the courtiers
		name = hold_court.7000.a
		duel = {
			skill = diplomacy
			value = hold_court_7000_diplomacy_value
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = hold_court.7000.a.success
				scope:rival_1 = {
					add_opinion = {
						modifier = hold_court_7000_convinced
						target = root
						opinion = 20
					}
				}
				scope:rival_2 = {
					add_opinion = {
						modifier = hold_court_7000_convinced
						target = root
						opinion = 20
					}
				}
				send_interface_toast = {
					title = hold_court.7000.a.success.toast
					left_icon = scope:rival_1
					right_icon = scope:rival_2
					add_diplomacy_lifestyle_xp = major_lifestyle_xp
				}
			}
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = hold_court.7000.a.failure
				scope:rival_1 = {
					add_opinion = {
						modifier = hold_court_7000_unconvinced
						target = root
						opinion = -20
					}
				}
				scope:rival_2 = {
					add_opinion = {
						modifier = hold_court_7000_unconvinced
						target = root
						opinion = -20
					}
				}
				send_interface_toast = {
					title = hold_court.7000.a.failure.toast
					left_icon = scope:rival_1
					right_icon = scope:rival_2
					add_character_modifier = {
						modifier = hold_court_7000_unworthy_ruler
						years = 5
					}
				}
			}
		}
	}

	option = { # Turn them against each other!
		name = hold_court.7000.b
		duel = {
			skill = intrigue
			value = hold_court_7000_intrigue_value
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
				}
				desc = hold_court.7000.b.success
				scope:rival_1 = {
					add_opinion = {
						modifier = hate_opinion
						target = scope:rival_2
						opinion = -30
					}
				}
				scope:rival_2 = {
					add_opinion = {
						modifier = hate_opinion
						target = scope:rival_1
						opinion = -30
					}
				}
				send_interface_toast = {
					title = hold_court.7000.b.success.toast
					left_icon = scope:rival_1
					right_icon = scope:rival_2
					add_intrigue_lifestyle_xp = major_lifestyle_xp
					add_character_modifier = {
						modifier = hold_court_7000_manipulated_enemies
						years = 5
					}
				}
			}
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
				}
				desc = hold_court.7000.b.failure
				## Hating you
				scope:rival_1 = {
					if = {
						limit = {
							can_set_relation_potential_rival_trigger = { CHARACTER = root }
						}
						set_relation_potential_rival = root
					}
					remove_relation_rival = scope:rival_2
					add_opinion = {
						modifier = hate_opinion
						target = root
						opinion = -20
					}
				}
				scope:rival_2 = {
					if = {
						limit = {
							can_set_relation_potential_rival_trigger = { CHARACTER = root }
						}
						set_relation_potential_rival = root
					}
					remove_relation_rival = scope:rival_1
					add_opinion = {
						modifier = hate_opinion
						target = root
						opinion = -20
					}
				}
				send_interface_toast = {
					title = hold_court.7000.b.failure.toast
					left_icon = scope:rival_1
					right_icon = scope:rival_2
					add_character_modifier = {
						modifier = hold_court_7000_unworthy_ruler
						years = 5
					}
				}
			}
		}
	}

	option = { # Threaten the courtiers
		name = hold_court.7000.c
		duel = {
			skill = prowess
			value = hold_court_7000_prowess_value
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
				}
				desc = hold_court.7000.c.success
				scope:rival_1 = {
					add_opinion = {
						modifier = scared_opinion
						target = root
						opinion = 20
					}
				}
				scope:rival_2 = {
					add_opinion = {
						modifier = scared_opinion
						target = root
						opinion = 20
					}
				}
				send_interface_toast = {
					title = hold_court.7000.c.success.toast
					left_icon = scope:rival_1
					right_icon = scope:rival_2
					add_dread = medium_dread_gain
				}
			}
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
				}
				desc = hold_court.7000.c.failure
				## Hating you
				scope:rival_1 = {
					add_opinion = {
						modifier = dismissive_opinion
						target = root
						opinion = -20
					}
				}
				scope:rival_2 = {
					add_opinion = {
						modifier = dismissive_opinion
						target = root
						opinion = -20
					}
				}
				send_interface_toast = {
					title = hold_court.7000.c.failure.toast
					left_icon = scope:rival_1
					right_icon = scope:rival_2
					add_dread = medium_dread_loss
				}
			}
		}
	}

	option = { # Concede to their demands
		trigger = {
			NOR = {
				has_character_flag = hold_court_7000_cultural_dispute
				has_character_flag = hold_court_7000_barbarian_spouse
			}
		}
		name = {
			trigger = { # Tax Dispute
				has_character_flag = hold_court_7000_tax_dispute
			}
			text = hold_court.7000.opt.tax
		}
		name = {
			trigger = { # Religious Dispute
				has_character_flag = hold_court_7000_religious_dispute
			}
			text = hold_court.7000.opt.religion
		}
		name = {
			trigger = { # Spouse Religion
				has_character_flag = hold_court_7000_heretic_spouse
			}
			text = hold_court.7000.opt.spouse_religion
		}
		name = {
			trigger = { # Spouse Criminality
				OR = {
					has_character_flag = hold_court_7000_lustful_spouse
					has_character_flag = hold_court_7000_criminal_spouse
				}
			}
			text = hold_court.7000.opt.spouse_criminal
		}
		name = {
			trigger = { # Spouse lowborn
				has_character_flag = hold_court_7000_lowborn_spouse
			}
			text = hold_court.7000.opt.spouse_lowborn
		}
		name = {
			trigger = { # Other Spouse issue
				has_character_flag = hold_court_7000_spouse_not_specific
			}
			text = hold_court.7000.opt.spouse_other
		}
		custom_tooltip = hold_court.7000.d.tt
		add_prestige = medium_prestige_loss

		if = { # Lower Taxes
			limit = { 
				has_character_flag = hold_court_7000_tax_dispute
			}
			add_character_modifier = {
				modifier = hold_court_7000_reduced_taxes
				years = 5
			}
		}

		if = { # Convert to Rival faith
			limit = { 
				has_character_flag = hold_court_7000_religious_dispute
			}
			set_character_faith = scope:rival_1.faith
		}

		if = { # Involving spouse
			limit = { 
				OR = {
					has_character_flag = hold_court_7000_heretic_spouse
					has_character_flag = hold_court_7000_barbarian_spouse
					has_character_flag = hold_court_7000_lustful_spouse
					has_character_flag = hold_court_7000_criminal_spouse
					has_character_flag = hold_court_7000_lowborn_spouse
					has_character_flag = hold_court_7000_spouse_not_specific
				}
			}
			# Attempt to fix things I can fix
			if = { # Forcibly convert my spouse
				limit = { has_character_flag = hold_court_7000_heretic_spouse }
				scope:controversial_spouse = { 
					set_character_faith = scope:rival_1.faith
					add_opinion = {
					 	modifier = hold_court_7000_forcibly_converted_faith
					 	target = root
					 	opinion = -30
					}
				}
			}
			else_if = { # Force my spouse to undergo penance
				limit = { 
					#AGOT Modified
					# faith = { religion_tag = christianity_religion } # Only Christians can do penance
					faith = { religion_tag = faith_of_the_seven_religion }
					OR = {
						has_character_flag = hold_court_7000_criminal_spouse
						has_character_flag = hold_court_7000_lustful_spouse
					}
				}
				add_piety = medium_piety_value
				scope:controversial_spouse = {
					hold_court_7000_penance_effect = yes
					add_opinion = {
						modifier = hold_court_7000_forced_penance
						target = root
						opinion = -30
					}
				}

			}
			else_if = { # I can't do anything about this!
				limit = { has_character_flag = hold_court_7000_lowborn_spouse }
				dynasty = { add_dynasty_prestige = minor_dynasty_prestige_loss }
			}
			else = { # Give spouse a general telling-off
				scope:controversial_spouse = {
					add_opinion = {
						modifier = hold_court_7000_rebuked_by_spouse
						target = root
						opinion = -30
					}
				}
			}
		}
	}

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

##################################################
# A Hero of the Frontier
# by George Luff
# 7010 - 7019
##################################################

# A frontier hero comes to your court to be recognised for their achievements
hold_court.7010 = {
	type = court_event
	title = hold_court.7010.title
	desc = {
		first_valid = {
			#AGOT Disabled
			# triggered_desc = { # Desc.a, Arab-Byzantine wars flavour
			# 	trigger = {
			# 		scope:frontier_hero = { has_character_flag = frontier_hero_byzantine }
			# 	}
			# 	desc = hold_court.7010.byzantine_desc
			# }
			# triggered_desc = { # Desc.b, Reconquista flavour
			# 	trigger = {
			# 		scope:frontier_hero = { has_character_flag = frontier_hero_reconquista }
			# 	}
			# 	desc = hold_court.7010.reconquista_desc
			# }
			# triggered_desc = { # Desc.c, England-France flavour
			# 	trigger = {
			# 		scope:frontier_hero = { has_character_flag = frontier_hero_anglofranco }
			# 	}
			# 	desc = hold_court.7010.anglofranco_desc
			# }
			triggered_desc = { # Desc.d, non-specific flavour
				trigger = {
					scope:frontier_hero = { has_character_flag = frontier_hero }
				}
				desc = hold_court.7010.default_desc
			}
		}
	}
	theme = court
	court_scene = {
		button_position_character = scope:frontier_hero
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:frontier_hero = {
				group = petitioners_group
				animation = personality_bold
			}
		}
	}

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

	trigger = {
		# Borders a state towards which they are antagonistic
		NOT = { has_character_flag = had_7010_hold_court_event }
		any_neighboring_top_liege_realm_owner = {
			NOR = { 
				#AGOT Disabled
				# AND = {
				# 	has_title = title:k_papal_state # Not the Pope if catholic
				# 	faith = faith:catholic
				# }
				has_truce = root
				is_allied_to = root
			}
			save_temporary_scope_as = frontier_ruler_temp
		}
	}

	immediate = {
		add_character_flag = {
			flag = had_7010_hold_court_event
			days = 3600
		}
		random_neighboring_top_liege_realm_owner = { #Select realm
			limit = {
				NOR = {
					#AGOT Disabled
					# AND = {
					# 	has_title = title:k_papal_state # Not the Pope if catholic
					# 	faith = faith:catholic
					# }
					has_truce = root
					is_allied_to = root
				}
			}
			save_scope_as = frontier_ruler
		}

		# Identify county for second option
		random_sub_realm_county = {
			limit = {
				any_neighboring_county = {
					holder = {
						OR = {
							this = scope:frontier_ruler
							top_liege = scope:frontier_ruler
						}
					}
				}
				NOT = { this = root.capital_county }
			}
			save_scope_as = frontier_hero_county
			holder = {
				if = {
					limit = {
						NOT = { this = root }
					}
					save_scope_as = lost_county_vassal
				}
			}
		}

		#AGOT Disabled
		# Flavour for the various conflicts
		# if = {
		# 	limit = { # Arab-Byzantine Wars
		# 		root = title:e_byzantium.holder
		# 		scope:frontier_ruler = {
		# 			capital_province = {
		# 				OR = {
		# 					geographical_region = world_middle_east
		# 					geographical_region = world_asia_minor
		# 				}
		# 			}
		# 			OR = {
		# 				culture = { has_cultural_pillar = heritage_arabic }
		# 				faith = { religion_tag = islam_religion }
		# 			}
		# 		}
		# 	}
		# 	create_character = {
		# 		template = frontier_hero_template
		# 		name = digenis
		# 		gender_female_chance = 0 # Digenis Akritis is a male name
		# 		location = root.capital_province
		# 		trait = rough_terrain_expert

		# 		after_creation = {
		# 			give_random_commander_trait_effect = yes
		# 		}

		# 		save_scope_as = frontier_hero
		# 	}
		# 	scope:frontier_hero = {
		# 		add_character_flag = frontier_hero_byzantine
		# 	}
		# }
		# else_if = {
		# 	limit = { # Reconquista, either side
		# 		AND = {
		# 			root = { capital_province = { geographical_region = world_europe_west_iberia }}
		# 			scope:frontier_ruler = { capital_province = { geographical_region = world_europe_west_iberia }}
		# 			NOT = { root.faith = scope:frontier_ruler.faith }
		# 		}
		# 	}
		# 	create_character = {
		# 		template = frontier_hero_template
		# 		gender_female_chance = root_soldier_female_chance
		# 		location = root.capital_province
		# 		trait = holy_warrior

		# 		after_creation = {
		# 			give_random_commander_trait_effect = yes
		# 		}

		# 		save_scope_as = frontier_hero
		# 	}
		# 	scope:frontier_hero = {
		# 		add_character_flag = frontier_hero_reconquista
		# 	}
		# }
		# else_if = {
		# 	limit = { # England-France
		# 		AND = {
		# 			root = title:k_england.holder
		# 			scope:frontier_ruler = title:k_france.holder
		# 		}
		# 	}
		# 	create_character = {
		# 		template = frontier_hero_template
		# 		gender_female_chance = root_soldier_female_chance
		# 		location = root.capital_province
		# 		trait = aggressive_attacker #It should be raider, but since non-tribal governments can't raid, what's the point?
		# 		save_scope_as = frontier_hero

		# 		after_creation = {
		# 			give_random_commander_trait_effect = yes
		# 		}

		# 	}
		# 	scope:frontier_hero = {
		# 		add_character_flag = frontier_hero_anglofranco
		# 	}
		# }
		# else = { # Generic flavour
			create_character = {
				template = frontier_hero_template
				gender_female_chance = root_soldier_female_chance
				location = root.capital_province

				after_creation = {
					give_random_commander_trait_effect = yes
				}

				save_scope_as = frontier_hero
			}
			scope:frontier_hero = {
				add_character_flag = frontier_hero
				random_list = {
					20 = {
						set_variable = {
							name = nickname
							value = flag:nick_the_bold
							days = 30
						}
					}
					20 = {
						set_variable = {
							name = nickname
							value = flag:nick_the_valiant
							days = 30
						}
					}
					20 = {
						set_variable = {
							name = nickname
							value = flag:nick_the_chivalrous
							days = 30
						}
					}
					20 = {
						set_variable = {
							name = nickname
							value = flag:nick_the_fearless
							days = 30
						}
					}
					20 = {
						set_variable = {
							name = nickname
							value = flag:nick_the_brave
							days = 30
						}
					}
				}
			}
		#AGOT Disabled
		# }
		scope:frontier_hero = {
			court_event_character_flag_effect = yes
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = { 	# Opt. a, the hero is offered a place in your household, which irks your existing knights
		name = hold_court.7010.a
		trigger = {
			trigger_if = {
				limit = {
					is_ai = yes
				}
				short_term_gold >= major_gold_value
			}
		}

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

		every_knight = {
			custom = custom.every_knight
			add_opinion = {
				modifier = insult_opinion
				target = root
				opinion = -15
			}

		}

		add_courtier = scope:frontier_hero

		hidden_effect = { # So it doesn't show up in tooltip and make the TT too chungus
			send_interface_toast = {
				title = hold_court_7010_new_courtier
				left_icon = scope:frontier_hero
				scope:frontier_hero = {
					add_opinion = {
						target = root
						modifier = loyal_servant
					}
				}
			}
		}
	}

	option = { # Opt. b, the hero is given your land
		name = hold_court.7010.b
		custom_tooltip = hold_court.7010.b1.tt
		trigger = {
			exists = scope:frontier_hero_county
			NOT = { exists = scope:lost_county_vassal }
		}

		create_title_and_vassal_change = {
			type = granted
			save_scope_as = change
			add_claim_on_loss = yes
		}

		scope:frontier_hero_county = {
			change_title_holder_include_vassals = {
				holder = scope:frontier_hero
				change = scope:change
			}
		}

		scope:frontier_hero = {
			change_liege = {
				liege = root
				change = scope:change
			}
		}

		resolve_title_and_vassal_change = scope:change

		scope:frontier_hero = {
			add_opinion = {
				target = root
				modifier = loyal_servant
			}
		}

		every_vassal = {
			custom = all_vassals
			limit = {
				government_has_flag = government_is_feudal
			}
			add_opinion = {
				modifier = disgusted_opinion
				target = root
				opinion = -10
			}
		}
		ai_chance = {
			base = 0
		}
	}

	option = { # Opt. b, the hero is given a vassal's land
		name = hold_court.7010.b
		trigger = { exists = scope:lost_county_vassal }

		scope:frontier_hero_county = {
			holder = {
				save_scope_as = lost_county_vassal
			}
		}
		custom_tooltip = hold_court.7010.b2.tt

		create_title_and_vassal_change = {
			type = granted
			save_scope_as = change
			add_claim_on_loss = yes
		}

		scope:frontier_hero_county = {
			change_title_holder_include_vassals = {
				holder = scope:frontier_hero
				change = scope:change
			}
		}

		scope:frontier_hero = {
			change_liege = {
				liege = root
				change = scope:change
			}
		}

		resolve_title_and_vassal_change = scope:change

		add_hook = {
			type = loyalty_hook
			target = scope:frontier_hero
		}
		scope:frontier_hero = {
			add_opinion = {
				target = root
				modifier = loyal_servant
			}
		}

		scope:lost_county_vassal = {
			add_opinion = {
				target = root
				modifier = hate_opinion
				opinion = -40
			}
			set_relation_rival = {
				target = scope:frontier_hero
				reason = rival_frontier_confiscation
			}
		}

		every_vassal = {
			custom = all_vassals
			limit = {
				government_has_flag = government_is_feudal
			}
			add_opinion = {
				modifier = disgusted_opinion
				target = root
				opinion = -10
			}
		}
	}

	option = { # Opt. c, the hero is congratulated and honoured with gold and gifts. Nickname awarded. Increases general opinion.
		name = hold_court.7010.c
		trigger = {
			trigger_if = {
				limit = {
					is_ai = yes
				}
				short_term_gold >= massive_gold_value
			}
		}

		pay_short_term_gold = {
			gold = major_gold_value
			target = scope:frontier_hero
		}

		add_character_modifier = {
			modifier = honored_frontier_hero_modifier
			years = 10
		}
		add_prestige = minor_prestige_gain

		stress_impact = {
			just = medium_stress_impact_loss
			greedy = medium_stress_impact_gain
			arrogant = medium_stress_impact_gain
		}

		scope:frontier_hero = {
			add_prestige = medium_prestige_gain
			#AGOT Disabled
			# if = {
			# 	limit = { has_character_flag = frontier_hero_byzantine }
			# 	give_nickname = nick_akritis
			# }
			# else_if = {
			# 	limit = {
			# 		has_character_flag = frontier_hero_reconquista
			# 	}
			# 	if = {
			# 		limit = {
			# 			culture = { has_cultural_pillar = heritage_iberian }
			# 		}
			# 		give_nickname = nick_the_conquistador
			# 	}
			# 	else_if = {
			# 		limit = { has_culture = culture:andalusian }
			# 		give_nickname = nick_al_mansur
			# 	}
			# }
			# else_if = {
			# 	limit = { has_character_flag = frontier_hero_anglofranco }
			# 	if = {
			# 		limit = { has_cultural_pillar = heritage_west_germanic }
			# 		give_nickname = nick_the_chevalier
			# 	}
			# 	else_if = {
			# 		limit = { has_cultural_pillar = heritage_frankish }
			# 		give_nickname = nick_the_irreproachable
			# 	}
			# }
			# else = {
				if = {
					limit = {
						var:nickname = flag:nick_the_bold
					}
					give_nickname = nick_the_bold 
				}
				else_if = {
					limit = {
						var:nickname = flag:nick_the_valiant
					}
					give_nickname = nick_the_valiant
				}
				else_if = {
					limit = {
						var:nickname = flag:nick_the_chivalrous 
					}
					give_nickname = nick_the_chivalrous
				}
				else_if = {
					limit = {
						var:nickname = flag:nick_the_fearless
					}
					give_nickname = nick_the_fearless
				}
				else_if = {
					limit = {
						var:nickname = flag:nick_the_brave
					}
					give_nickname = nick_the_brave 
				}
			#AGOT Disabled
			# }
		}
	}
	
	option = { # Opt. d, the hero is insulted and imprisoned, as punishment for outdoing you!
		name = hold_court.7010.d

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

		stress_impact = {
			just = major_stress_impact_gain
			humble = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
			arbitrary = major_stress_impact_loss
			callous = medium_stress_impact_loss
			sadistic = medium_stress_impact_loss
			arrogant = major_stress_impact_loss
		}

		add_character_modifier = {
			modifier = imprisoned_frontier_hero_modifier
			years = 10
		}
		scope:frontier_hero = {
			add_opinion = {
				modifier = hate_opinion
				target = root
				opinion = -50
			}
		}

		every_vassal = {
			custom = all_vassals
			limit = {
				government_has_flag = government_is_feudal
			}
			add_opinion = {
				modifier = pleased_opinion
				target = root
				opinion = 15
			}
		}
	}

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

##################################################
# Harbouring Exile
# by George Luff
# 7020 - 7029
##################################################

scripted_trigger hold_court_7020_valid_claim_trigger = {
	exists = holder
	holder = {
		NOR = {
			this = root
			any_liege_or_above = {
				this = root
			}
		}
	}
}

# Bars people that don't make sense from being disguised and killed off
scripted_trigger hold_court_7020_disguised_exile_trigger = {
	sex_same_as = scope:exile
	NOT = { 
		this = scope:ambassador 
		this = scope:exile
		has_relation_soulmate = root
	}
}

# sends a letter to the liege of the visiting ambassador informing them of who is rejoining the court.
scripted_effect hold_court_7020_send_ambassador_back = {
	scope:ambassador_liege = {
		send_interface_toast = {
			title = hold_court_7020_ambassador_returns
			if = {
				limit = {
					has_character_flag = hold_court_7020_exile_returned
				}
				show_as_tooltip = {
					add_courtier = scope:exile
				}
			}
			if = {
				limit = {
					has_character_flag = hold_court_7020_fake_exile_returned
				}
				show_as_tooltip = {
					add_courtier = scope:disguised_exile
				}
			}
		}
	}
}

hold_court.7020 = {
	type = court_event
	title = hold_court.7020.title
	desc = hold_court.7020.desc
	theme = court
	lower_left_portrait = {
		character = scope:exile
		animation = worry
	}
	cooldown = { years = 10 }

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

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

	trigger = {
		# does the ruler have a claimant with a foreign claim
		#AGOT Modified, must be actually independent
		#is_independent_ruler = yes
		agot_is_independent_ruler = yes
		any_courtier_or_guest = {
			has_court_event_flag = no
			NOR = {
				is_close_or_extended_family_of = root
				is_consort_of = root
			}
			any_claim = {
				hold_court_7020_valid_claim_trigger = yes
			}
			#AGOT Added
			NOT = { has_trait = nightswatch }
			NOT = { has_trait = kingsguard }
		}
	}

	weight_multiplier = {
		base = 1

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

	immediate = {
		# This finds the claimant
		random_courtier_or_guest = {
			limit = {
				has_court_event_flag = no
				NOR = {
					is_close_or_extended_family_of = root
					is_consort_of = root
				}
				any_claim = {
					hold_court_7020_valid_claim_trigger = yes
				}
				#AGOT Added
				NOT = { has_trait = nightswatch }
				NOT = { has_trait = kingsguard }
			}
			save_scope_as = exile
			court_event_character_flag_effect = yes
		}
		
		scope:exile = {
			random_claim = {
				limit = {
					hold_court_7020_valid_claim_trigger = yes
				}
				save_scope_as = exile_claim
				# this finds us the top liege of the claim
				holder = {
					top_liege = {
						save_scope_as = ambassador_liege
						random_courtier = {
							if = {
								limit = {
									has_court_event_flag = no
									is_available_healthy_ai_adult = yes
									is_councillor = no
									NOR = {
										is_close_or_extended_family_of = prev
										is_spouse_of = prev
									}
								}
								save_scope_as = ambassador
							}
							# if the liege didn't have an appropriate courtier, we create one.
							else = {
								create_character = {
									template = pool_repopulate_diplomacy
									location = scope:ambassador_liege.location
									faith = scope:ambassador_liege.faith
									culture = scope:ambassador_liege.culture
									save_scope_as = ambassador
								}
								# this is required so that the ambassador can visit/return properly
								hidden_effect = {
									scope:ambassador_liege = {
										add_courtier = scope:ambassador
									}
								}
							}
						}
					}
				}
			}
		}
		scope:ambassador = {
			court_event_character_flag_effect = yes
		}
		hidden_effect = {
			add_visiting_courtier = scope:ambassador
		}

		# Checks if you have a random courtier from your court to disguise as the exile. Prefers rivals.
		random_courtier = {
        	limit = {
        		has_court_event_flag = no
            	hold_court_7020_disguised_exile_trigger = yes
            	OR = {
					has_relation_rival = root
					has_relation_potential_rival = root
				}
			}
			alternative_limit = {
				has_court_event_flag = no
				ep1_spare_courtier_trigger = yes
				hold_court_7020_disguised_exile_trigger = yes
			}
			save_scope_as = disguised_exile
			court_event_character_flag_effect = yes
        }
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = { # Agree to the ambassador's demand. The claimant joins the court of the ambassador's liege.
		name = hold_court.7020.a
		# Opinion bonus with the ambassador and liege, sets up a rivalry with the exile and a potential friendship with the liege
		scope:ambassador = {
			add_opinion = {
				modifier = pleased_opinion
				target = root
				opinion = 15
			}
		}

		scope:ambassador_liege = {
			add_character_flag = hold_court_7020_exile_returned
		}

		scope:exile = {
			add_opinion = {
				modifier = betrayed_me_opinion
				target = root
				opinion = -30
			}
		}

		progress_towards_rival_effect = {
			CHARACTER = scope:exile
			REASON = rival_betrayal_exile
			OPINION = 0
		}

		remove_courtier_or_guest = {
			character = scope:exile
			new_location = scope:ambassador_liege.location
		}

		hold_court_7020_send_ambassador_back = yes

		ai_chance = {
			base = 3
			ai_value_modifier = {
				ai_honor = 0.5
				ai_compassion = -0.5
				ai_vengefulness = -0.5
			}
		}
	}

	option = { # Reject ambassador's demand outright.
		name = hold_court.7020.b
		# Opinion malus with the ambassador and their liege, sets up a potential friendship with the exile
		scope:ambassador = {
			add_opinion = {
				modifier = disappointed_opinion
				target = root
				opinion = -15
			}
		}
		scope:ambassador_liege = {
			add_character_flag = hold_court_7020_exile_not_returned
		} 
		scope:exile = {
			add_opinion = {
				modifier = protected_me_opinion
				target = root
				opinion = 30
			}
		}

		progress_towards_friend_effect = {
			REASON = friend_refused_extradition
			CHARACTER = scope:exile
			OPINION = 0
		}

		hold_court_7020_send_ambassador_back = yes

		ai_chance = {
			base = 5
			ai_value_modifier = {
				ai_honor = -0.5
				ai_compassion = 0.5
			}
		}

	}

	option = { # Attempt to deceive the ambassador by picking another courtier and sending them instead
		name = hold_court.7020.c
		trigger = {
			exists = scope:disguised_exile
		}
		custom_tooltip = hold_court.7020.c.tt
		# intrigue duel where success gets you intrigue XP and you keep the claimant.
		duel = {
			skill = intrigue
			target = scope:ambassador
			50 = {
				desc = hold_court.7020.c.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
				}
				send_interface_toast = {
					left_icon = scope:ambassador_liege
					right_icon = scope:disguised_exile
					title = hold_court_7020_successful_deception
					add_intrigue_lifestyle_xp = major_lifestyle_xp
					add_prestige = minor_prestige_gain
				}
				add_character_flag = hold_court_7020_successful_deception
				scope:ambassador = {
					add_opinion = {
						modifier = pleased_opinion
						target = root
						opinion = 15
					}
				}
				scope:ambassador_liege = {
					add_character_flag = hold_court_7020_fake_exile_returned
				}
			}
			50 = {
				desc = hold_court.7020.c.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
				}
				send_interface_toast = {
					left_icon = scope:ambassador
					right_icon = scope:disguised_exile
					title = hold_court_7020_failed_deception
					add_prestige = medium_prestige_loss
				}
				add_character_flag = hold_court_7020_failed_deception
				scope:ambassador = {
					add_opinion = {
						modifier = angry_opinion
						target = root
						opinion = -25
					}
				}
			}
		}
		# the one taking the exile's place dislikes you. Won't matter if you succeed and they die, of course.
		scope:disguised_exile = {
			add_opinion = {
				modifier = betrayed_me_opinion
				target = root
				opinion = -30
			}
		}

		hold_court_7020_send_ambassador_back = yes

		ai_chance = {
			base = 3
			ai_value_modifier = {
				ai_honor = -0.5
				ai_compassion = -0.5
				ai_vengefulness = 1
				ai_boldness = 1
			}
		}
	}

	after = {
		scope:ambassador = {
			clear_court_event_participation = yes
			hidden_effect = {	
				return_to_court = yes
			}
		}
		scope:exile = {
			clear_court_event_participation = yes
		}
		if = {
			limit = { exists = scope:disguised_exile }
			scope:disguised_exile = {
				clear_court_event_participation = yes
			}
		}
		trigger_event = {
			id = hold_court.7021
			days = { 5 10 }
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

hold_court.7021 = { # Ambassador liege responds...
	type = letter_event
	sender = scope:ambassador_liege
	opening = {
		desc = hold_court.7021.opening
	}
	desc = {
		# varies based on previous option and the pass/fail of the duel
		triggered_desc = {
			trigger = {
				has_character_flag = hold_court_7020_successful_deception
			}
			desc = hold_court.7021.success
		}
		triggered_desc = {
			trigger = {
				has_character_flag = hold_court_7020_failed_deception
			}
			desc = hold_court.7021.failure
		}
		triggered_desc = {
			trigger = {
				scope:ambassador_liege = {
					has_character_flag = hold_court_7020_exile_returned
				}
			}
			desc = hold_court.7021.returned
		}
		triggered_desc = {
			trigger = {
				scope:ambassador_liege = {
					has_character_flag = hold_court_7020_exile_not_returned
				}
			}
			desc = hold_court.7021.not_returned
		}
	}

	option = { # Successfully deceived ambassador
		name = hold_court.7021.a
		trigger = {
			has_character_flag = hold_court_7020_successful_deception
		}
		# the exile likes you, the ambassador's liege hates you, and the disguised person is killed
		scope:exile = {
			add_opinion = {
				modifier = protected_me_opinion
				target = root
				opinion = 30
			}
		}

		progress_towards_friend_effect = {
			REASON = friend_refused_extradition
			CHARACTER = scope:exile
			OPINION = 0
		}

		scope:ambassador_liege = {
			add_opinion = {
				modifier = tricked_opinion
				target = root
				opinion = -50
			}
		}

		progress_towards_rival_effect = {
			CHARACTER = scope:ambassador_liege
			REASON = rival_exile_harboured
			OPINION = 0
		}

		scope:disguised_exile = {
			death = {
				death_reason = death_execution
				killer = scope:ambassador_liege
			}
		}
	}

	option = { # Failed to deceive ambassador
		name = hold_court.7021.b
		trigger = {
			has_character_flag = hold_court_7020_failed_deception
		}
		# the exile likes you, and the ambassador's liege hates you
		scope:exile = {
			add_opinion = {
				modifier = attempted_protection_opinion
				target = root
				opinion = 10
			}
		}

		scope:ambassador_liege = {
			add_opinion = {
				modifier = attempted_trickery_opinion
				target = root
				opinion = -30
			}
		}

		progress_towards_rival_effect = {
			CHARACTER = scope:ambassador_liege
			REASON = rival_exile_trickery
			OPINION = 0
		}

		add_character_modifier = {
			modifier = failed_deception_modifier
			years = 5
		}
	}

	option = { # Returned exile
		name = hold_court.7021.c
		trigger = {
			scope:ambassador_liege = {
				has_character_flag = hold_court_7020_exile_returned
			}
		}
		# the ambassador's liege likes you and becomes more friendly. You've lost your claimant.
		scope:ambassador_liege = {
			add_opinion = {
				modifier = grateful_opinion
				target = root
				opinion = 20
			}
		}

		progress_towards_friend_effect = {
			REASON = friend_returned_exile
			CHARACTER = scope:ambassador_liege
			OPINION = 0
		}
	}

	option = { # Failed to return exile
		name = hold_court.7021.d
		trigger = {
			scope:ambassador_liege = {
				has_character_flag = hold_court_7020_exile_not_returned
			}
		}
		# Refusal just brings more anger from the liege
		scope:ambassador_liege = {
			add_opinion = {
				modifier = angry_opinion
				target = root
				opinion = -20
			}
		}
	}
}

##################################################
# The Ravages of Peace
# by George Luff
# 7030 - 7039
##################################################

# Personal guard on a vassal's land have left a mess
hold_court.7030 = {
	type = court_event
	title = hold_court.7030.title
	desc = {
		first_valid = {
			#AGOT Disabled
			# Byzantine flavour - Varangian Guard
			# triggered_desc = {
			# 	trigger = {
			# 		any_held_title = { this = title:e_byzantium }
			# 	}
			# 	desc = hold_court.7030.byzantine_desc
			# }
			desc = hold_court.7030.desc
		}
	}
	theme = court
	court_scene = {
		button_position_character = scope:angry_vassal
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:angry_vassal = {
				group = petitioners_group
				animation = anger
			}
			scope:troublesome_warrior = {
				group = petitioners_group
				#AGOT MODIFIED
				#animation = worried
				animation = worry
			}
		}
	}

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

	trigger = {
		#AGOT Modified, must be actually independent
		#is_independent_ruler = yes
		agot_is_independent_ruler = yes
		NOR = { 
			has_character_flag = had_hold_court_event_7030
			has_character_modifier = hold_court_7030_knight_boost
		}

		#AGOT Disabled
		# trigger_if = {
		# 	limit = {
		# 		any_held_title = { this = title:e_byzantium }
		# 	}
		# 	any_courtier_or_guest = {
		# 		has_court_event_flag = no
		# 		has_trait = varangian
		# 		is_available_healthy_ai_adult = yes
		# 	}
		# }
		# trigger_else = {
			any_knight = {
				has_court_event_flag = no
				is_available_healthy_ai_adult = yes
				save_temporary_scope_as = hold_court_7030_knight_trigger
			}
		#AGOT Disabled
		# }
		any_vassal = {
			has_court_event_flag = no
			is_available_healthy_ai_adult = yes
			primary_title.tier >= tier_county
			trigger_if = {
				limit = {
					exists = scope:hold_court_7030_knight_trigger
				}
				NOT = { this = scope:hold_court_7030_knight_trigger }
			}
		}
	}

	weight_multiplier = {
		base = 1

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

	immediate = {
		add_character_flag = {
			flag = had_hold_court_event_7030
			days = 1800
		}
		# Consistent amount of gold
		set_variable = {
			name = plundered_gold
			value = medium_gold_value
			years = 1
		}
		if = {
			limit = {
				OR = {
					NOT = { exists = root.var:plundered_gold }
					AND = {
						exists = root.var:plundered_gold
						root.var:plundered_gold < 1
					}
				}
			}
			set_variable = {
				name = plundered_gold
				value = 10
				years = 1
			}
		}
		#AGOT Disabled
		# Select a knight or Varangian
		# if = {
		# 	limit = {
		# 		any_held_title = { this = title:e_byzantium }
		# 	}
		# 	random_courtier_or_guest = {
		# 		limit = {
		# 			has_court_event_flag = no
		# 			has_trait = varangian
		# 			is_available_healthy_ai_adult = yes
		# 		}
		# 		save_scope_as = troublesome_warrior
		# 	}
		# }
		# else = {
			random_knight = {
				limit = {
					has_court_event_flag = no
					is_available_healthy_ai_adult = yes
				}
				save_scope_as = troublesome_warrior
			}
		#AGOT Disabled
		# }
		scope:troublesome_warrior = {
			court_event_character_flag_effect = yes
			hidden_effect = {
				add_gold = root.var:plundered_gold
			}
		}
		# Select a vassal
		random_vassal = {
			limit = {
				has_court_event_flag = no
				is_available_healthy_ai_adult = yes
				primary_title.tier >= tier_county
				NOT = {
					this = scope:troublesome_warrior
				}
			}
			save_scope_as = angry_vassal
			court_event_character_flag_effect = yes
			random_held_county = {
				save_scope_as = hold_court_7030_county
				change_county_control = major_county_control_loss
				add_county_modifier = {
					modifier = hold_court_7030_land_trashed
					years = 5
				}
			}
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = { # My armies march in defense of the realm, stop whinging
		# Knight effectiveness boost, anger the vassal and irritate others
		name = hold_court.7030.a

		stress_impact = {
			callous = minor_stress_impact_loss
			arrogant = medium_stress_impact_loss
			wrathful = minor_stress_impact_loss
			shy = medium_stress_impact_gain
			humble = minor_stress_impact_gain
			compassionate = minor_stress_impact_gain
		}

		add_character_modifier = {
			modifier = hold_court_7030_knight_boost
			years = 15
		}

		scope:angry_vassal = {
			add_opinion = {
				modifier = angry_opinion
				target = root
				opinion = -20
			}
			progress_towards_rival_effect = {
				CHARACTER = scope:troublesome_warrior
				REASON = rival_troublesome_warrior
				OPINION = default_rival_opinion
			}
		}
		scope:troublesome_warrior = {
			add_opinion = {
				modifier = loyal_servant
				target = root
			}
		}
		every_knight = {
			limit = {
				NOT = { this = scope:troublesome_warrior }
			}
			custom = custom.every_knight
			add_opinion = {
				modifier = pleased_opinion
				target = root
				opinion = 5
			}
		}

		ai_chance = {
			base = 30
			ai_value_modifier = {
				ai_honor = -0.5
				ai_vengefulness = 2
				ai_compassion = -0.5
			}
		}
	}

	option = { # You must give it back!
		# Decrease knight effectiveness
		name = hold_court.7030.b

		stress_impact = {
			vengeful = minor_stress_impact_loss
			callous = minor_stress_impact_loss
			just = major_stress_impact_loss
			generous = minor_stress_impact_loss
			diligent = minor_stress_impact_loss
			honest = minor_stress_impact_loss
			lazy = minor_stress_impact_gain
			craven = medium_stress_impact_gain
		}

		add_character_modifier = {
			modifier = hold_court_7030_knight_punished
			years = 5
		}

		scope:troublesome_warrior = {
			pay_short_term_gold = {
				gold = root.var:plundered_gold
				target = scope:angry_vassal
			}
			add_opinion = {
				modifier = annoyed_opinion
				target = root
				opinion = -20
			}
			progress_towards_rival_effect = {
				CHARACTER = scope:angry_vassal
				REASON = rival_troublesome_warrior_payback
				OPINION = default_rival_opinion
			}
		}

		scope:angry_vassal = {
			add_opinion = {
				modifier = pleased_opinion
				target = root
				opinion = 20
			}
		}

		hidden_effect = {
			if = {
				limit = {
					scope:angry_vassal = {
						OR = {
							has_trait = greedy
							has_trait = arbitrary
							has_trait = callous
						}
					}
				}
				send_interface_toast = {
					title = hold_court_7030b_land_not_restored
					left_icon = scope:angry_vassal
					right_icon = scope:troublesome_warrior
					custom_tooltip = hold_court_7030b_land_not_restored_tt
				}
			}
			else = {
				scope:hold_court_7030_county = {
					remove_county_modifier = hold_court_7030_land_trashed
				}
				scope:angry_vassal = {
					remove_short_term_gold = root.var:plundered_gold
				}
				send_interface_toast = {
					title = hold_court_7030b_land_restored
					left_icon = scope:angry_vassal
					right_icon = scope:troublesome_warrior
					custom_tooltip = hold_court_7030b_land_restored_tt
				}
			}
		}
		ai_chance = {
			base = 30
			ai_value_modifier = {
				ai_honor = 10
				ai_compassion = 10
				ai_energy = 10
				ai_rationality = 10
			}
		}
	}

	option = { # I will compensate you for the trashed land
		# Give money to the vassal for a big opinion boost
		name = hold_court.7030.c
		trigger = {
			trigger_if = {
				limit = {
					is_ai = yes
				}
				short_term_gold >= major_gold_value
			}
		}

		stress_impact = {
			greedy = major_stress_impact_gain
			generous = minor_stress_impact_loss
			just = medium_stress_impact_loss
		}

		pay_short_term_gold = {
			gold = root.var:plundered_gold
			target = scope:angry_vassal
		}


		

		scope:angry_vassal = {
			add_opinion = {
				modifier = pleased_opinion
				target = root
				opinion = 35
			}
			set_relation_potential_friend = root
		}

		hidden_effect = {
			if = { #Pockets the gold
				limit = {
					scope:angry_vassal = {
						OR = {
							has_trait = greedy
							has_trait = arbitrary
							has_trait = callous
						}
					}
				}
				send_interface_toast = {
					title = hold_court_7030c_land_not_restored
					left_icon = scope:angry_vassal
					right_icon = scope:troublesome_warrior
					custom_tooltip = hold_court_7030c_land_not_restored_tt
				}
			}
			else = {
				scope:hold_court_7030_county = {
					remove_county_modifier = hold_court_7030_land_trashed
				}
				scope:angry_vassal = {
					remove_short_term_gold = root.var:plundered_gold
				} #Uses the gold to fix the land
				send_interface_toast = {
					title = hold_court_7030c_land_restored
					left_icon = scope:angry_vassal
					right_icon = scope:troublesome_warrior
					custom_tooltip = hold_court_7030c_land_restored_tt
				}
			}
		}
		ai_chance = {
			base = 30
			ai_value_modifier = {
				ai_honor = 10
				ai_compassion = 10
				ai_energy = 10
				ai_rationality = 10
				ai_greed = -20
			}
		}
	}

	option = { # Your land? I don't see your flag on it!
		name = hold_court.7030.d

		stress_impact = {
			just = massive_stress_impact_gain
			compassionate = major_stress_impact_gain
			temperate = massive_stress_impact_gain
			humble = major_stress_impact_gain
			generous = major_stress_impact_gain
			content = major_stress_impact_gain
			arbitrary = major_stress_impact_loss
			ambitious = medium_stress_impact_loss
			wrathful = medium_stress_impact_loss
			greedy = medium_stress_impact_loss
			arrogant = minor_stress_impact_loss
		}

		create_title_and_vassal_change = {
			type = revoked
			save_scope_as = change
			add_claim_on_loss = yes
		}

		scope:hold_court_7030_county = {
			change_title_holder = {
				holder = root
				change = scope:change
				take_baronies = yes
			}
		}
		resolve_title_and_vassal_change = scope:change

		add_tyranny = minor_tyranny_gain
		scope:angry_vassal = {
			add_opinion = {
				modifier = hate_opinion
				target = root
				opinion = -60
			}
			if = {
				limit = {
					NOT = {
						has_relation_rival = root
					}
				}
				set_relation_rival = {
					target = root
					reason = rival_protected_looters
				}
			}
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_honor = -100
				ai_rationality = -50
				ai_greed = 10
			}
		}
	}

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

##################################################
# Frontier Fracas
# by George Luff
# 7040 - 7049
##################################################

scripted_trigger already_has_event_bonus_trigger = {
	OR = {
		has_character_modifier = event_bonus_to_agent_invite
		has_character_modifier = event_bonus_to_vassal_accept
		has_character_modifier = hold_court_7040_tax_boost
		AND = {
			exists = cp:councillor_marshal
			cp:councillor_marshal = {
				has_court_event_flag = no
				is_available_ai_adult = yes
				has_character_modifier = event_bonus_to_county_control
			}
		}
	}
}

scripted_trigger hold_court_7040_valid_county_check = {
	any_neighboring_county = {
		NOR = {
			holder = root 
			holder = {
				any_liege_or_above = { this = root }
			}
		}
	}
	save_temporary_scope_as = current_county
}

scripted_trigger hold_court_7040_suitable_leader = {
	has_court_event_flag = no
	is_available_healthy_ai_adult = yes
	NOT = {
		any_heir_title = {} # Not heir to anything
	}
}

scripted_effect hold_court_7040_lose_effects = {
	change_county_control = massive_county_control_loss
	add_county_modifier = {
		modifier = hold_court_7040_county_opinion_loss
		years = 5
	}
}

# Tax revolt in frontier provinces
hold_court.7040 = {
	type = court_event
	title = hold_court.7040.title
	desc = hold_court.7040.desc
	theme = court
	right_portrait = {
		character = scope:frontier_leader
		animation = worry
	}
	cooldown = { years = 10 }
	court_scene = {
		button_position_character = scope:frontier_leader
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:frontier_leader = {
				group = petitioners_group
				animation = worry
			}
		}
	}

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

	trigger = {
		# Must have a marshal
		exists = cp:councillor_marshal
		cp:councillor_marshal = {
			has_court_event_flag = no
			is_available_ai_adult = yes
		}
		# Must not have any of these extant rewards
		already_has_event_bonus_trigger = no
		# Must have a valid province
		any_sub_realm_county = {
			hold_court_7040_valid_county_check = yes
		}
	}

	immediate = {
		# Identify the actual county for this
		random_sub_realm_county = {
			limit = {
				hold_court_7040_valid_county_check = yes
			}
			save_scope_as = frontier_county
		}
		cp:councillor_marshal = {
			save_scope_as = marshal
			court_event_character_flag_effect = yes
		}

		# Create peasant leader character
		if = {
			limit = {
				any_pool_character = {
					province = scope:frontier_county.title_province
					hold_court_7040_suitable_leader = yes
				}
			}
			random_pool_character = {
				province = scope:frontier_county.title_province
				limit = {
					hold_court_7040_suitable_leader = yes
				}
				save_scope_as = frontier_leader
			}
		}
		else = {
			create_character = {
				template = frontier_hero_template
				dynasty = none
				gender_female_chance = root_soldier_female_chance
				location = scope:frontier_county.title_province
				save_scope_as = frontier_leader
			}
		}
		scope:frontier_leader = {
			court_event_character_flag_effect = yes
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = { # Resolve with military force!
		name = hold_court.7040.a

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

		scope:marshal = {
			duel = {
				skill = martial
				value = 10

				# Win
				50 = {
					desc = hold_court.7040.a.win
					compare_modifier = {
						value = scope:duel_value
						multiplier = 3.5
					}

					root = {
						send_interface_toast = {
							title = hold_court.7040.a.win.title
							left_icon = root
							right_icon = scope:marshal
							add_martial_lifestyle_xp = medium_lifestyle_xp
							# Your marshal gets better at controlling counties
							scope:marshal = {
								add_character_modifier = {
									modifier = event_bonus_to_county_control
								}
							}
						}
					}
				}
				# Lose
				50 = {
					desc = hold_court.7040.a.lose
					compare_modifier = {
						value = scope:duel_value
						multiplier = -3.5
					}
					root = {
						send_interface_toast = {
							title = hold_court.7040.a.lose.title
							left_icon = root
							right_icon = scope:marshal
							scope:frontier_county = {
								hold_court_7040_lose_effects = yes
							}
						}
					}
				}
			}
		}
		ai_chance = {
			base = 20
			ai_value_modifier = {
				ai_compassion = -10
				ai_zeal = 10
				ai_vengefulness = 100
			}
		}
	}

	option = { # Negotiate with them, and then trick them!
		name = hold_court.7040.b

		duel = {
			skill = intrigue
			value = 10

			# Win
			50 = {
				desc = hold_court.7040.b.win
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
				}
				send_interface_toast = {
					title = hold_court.7040.b.win.title
					left_icon = root
					scope:frontier_county = {
						change_county_control = medium_county_control_gain
					}
					add_intrigue_lifestyle_xp = medium_lifestyle_xp
					imprison = {
						target = scope:frontier_leader
						type = dungeon
					}
					# Easier to convince agents to join your schemes
					add_character_modifier = {
						modifier = event_bonus_to_agent_invite
					}
				}
			}
			# Lose
			50 = {
				desc = hold_court.7040.b.lose
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
				}
				send_interface_toast = {
					title = hold_court.7040.b.lose.title
					left_icon = root
					scope:frontier_county = {
						hold_court_7040_lose_effects = yes
					}
				}
			}
		}
		ai_chance = {
			base = 20
			ai_value_modifier = {
				ai_compassion = -10
				ai_vengefulness = 100
			}
		}
	}

	option = { # Negotiate with them
		name = hold_court.7040.c

		duel = {
			skill = diplomacy
			value = 10

			# Win
			50 = {
				desc = hold_court.7040.c.win
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
				}
				send_interface_toast = {
					title = hold_court.7040.c.win.title
					left_icon = root
					scope:frontier_county = {
						change_county_control = medium_county_control_gain
					}
					add_diplomacy_lifestyle_xp = medium_lifestyle_xp
					# Easier to get vassalization offers accepted
					add_character_modifier = {
						modifier = event_bonus_to_vassal_accept
						years = 15 # Removed after first use for balance purposes, expires if not used.
					}
				}
			}
			# Lose
			50 = {
				desc = hold_court.7040.c.lose
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
				}
				send_interface_toast = {
					title = hold_court.7040.c.lose.title
					left_icon = root
					scope:frontier_county = {
						hold_court_7040_lose_effects = yes
					}
				}
			}
		}
		ai_chance = {
			base = 20
			ai_value_modifier = {
				ai_honor = 20
				ai_compassion = 20
				ai_energy = 30
				ai_rationality = 20
			}
		}
	}

	option = { # Prove that the taxes are actually lower than what they should be
		name = hold_court.7040.d

		duel = {
			skill = stewardship
			value = 10

			# Win
			50 = {
				desc = hold_court.7040.d.win
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
				}
				send_interface_toast = {
					title = hold_court.7040.d.win.title
					left_icon = root
					scope:frontier_county = {
						change_county_control = medium_county_control_gain
					}
					add_stewardship_lifestyle_xp = medium_lifestyle_xp
					add_gold = medium_gold_value
					add_character_modifier = {
						modifier = hold_court_7040_tax_boost
						years = 20
					}
				}
			}
			# Lose
			50 = {
				desc = hold_court.7040.d.lose
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
				}
				send_interface_toast = {
					title = hold_court.7040.d.lose.title
					left_icon = root
					scope:frontier_county = {
						hold_court_7040_lose_effects = yes
					}
				}
			}
		}
		ai_chance = {
			base = 20
			ai_value_modifier = {
				ai_compassion = 20
				ai_energy = 50
				ai_rationality = 20
			}
		}
	}

	option = { # "opt out option"
		name = hold_court.7040.e

		stress_impact = {
			lazy = major_stress_impact_loss
			diligent = major_stress_impact_gain
		}

		scope:frontier_county = {
			add_county_modifier = {
				modifier = hold_court_7040_tax_cut
				years = 5
			}
		}
		ai_chance = {
			base = 20
			ai_value_modifier = {
				ai_energy = -300
				ai_greed = -10
			}
		}
	}

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

##################################################
# Consequences of War
# by George Luff
# 7050 - 7059
##################################################

scripted_effect hold_court_7050_duel_effects = {
	scope:sc_victor = {
		send_interface_toast = {
			title = hold_court_7050_victory

			left_icon = root
			right_icon = scope:lunatic_soldier

			add_prestige = major_prestige_gain
			add_stress = major_stress_loss
			if = {
				limit = {
					NOT = { has_trait = lifestyle_blademaster }
				}
				add_trait = lifestyle_blademaster
			}
			else = {
				add_trait_xp = {
					trait = lifestyle_blademaster
					value = 10
				}
			}
		}
	}
}

# Former soldier has lost their marbles and seeks death.
hold_court.7050 = {
	type = court_event
	title = hold_court.7050.title
	desc = hold_court.7050.desc
	theme = court
	court_scene = {
		button_position_character = scope:lunatic_soldier
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:lunatic_soldier = {
				group = petitioners_group
				animation = lunatic
			}
		}
	}

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

	trigger = {
		any_court_position_holder = {
			type = court_physician_court_position
			has_court_event_flag = no
			is_available_ai_adult = yes
		}
		is_available_healthy_adult = yes
		days_of_continuous_peace < 1800
		NOT = { has_character_flag = had_hold_court_event_7050 }
	}

	immediate = {
		add_character_flag = had_hold_court_event_7050
		if = {
			limit = {
				any_court_position_holder = {
					type = court_physician_court_position
					has_court_event_flag = no
					is_available_ai_adult = yes
				}
			}
			random_court_position_holder = {
				type = court_physician_court_position
				limit = {
					has_court_event_flag = no
					is_available_ai_adult = yes
				}
				save_scope_as = court_physician
				court_event_character_flag_effect = yes
			}
		}
		# Generate a lunatic soldier with ok stats
		create_character = {
			location = root.capital_province
			template = errant_soldier_character
			trait = lunatic_1
			save_scope_as = lunatic_soldier
		}
		scope:lunatic_soldier = {
			court_event_character_flag_effect = yes
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = { # Compassionate choice - ask the physician to examine them
		name = hold_court.7050.a
		trigger = {
			exists = scope:court_physician
		}

		stress_impact = {
			sadistic = medium_stress_gain
			callous = medium_stress_gain
		}

		add_piety = major_piety_value

		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = sadistic
					has_trait = callous
				}
			}
		}
	}

	option = { # Prowess choice - fight the soldier
		name = hold_court.7050.b
		custom_tooltip = hold_court.7050.b.tt

		stress_impact = {
			craven = medium_stress_gain
			ambitious = minor_stress_gain
		}

		hidden_effect = {
			root = { save_scope_as = killed_pc } # In case of death
			root.player_heir = { save_scope_as = killed_pc_heir } # In case of death
		}

		## Use the new Duel system!
		configure_start_single_combat_effect = {
			SC_INITIATOR = root
			SC_ATTACKER = root
			SC_DEFENDER = scope:lunatic_soldier
			FATALITY = always
			FIXED = no
			LOCALE = throne_room
			OUTPUT_EVENT = hold_court.7051
			INVALIDATION_EVENT = hold_court.7054
		}
		# Show possible results
		show_as_tooltip = {
			random_list = {
				# Root wins
				50 = {
					show_chance = no
					desc = hold_court.7050.b.victory
					scope:lunatic_soldier = {
						death = {
							killer = root
							death_reason = death_duel
						}
					}
					add_prestige = major_prestige_gain
					add_stress = major_stress_loss
					if = {
						limit = {
							NOT = { has_trait = lifestyle_blademaster }
						}
						add_trait = lifestyle_blademaster
					}
					else = {
						add_trait_xp = {
							trait = lifestyle_blademaster
							value = 10
						}
					}
				}
				# Lunatic Soldier wins
				50 = {
					show_chance = no
					desc = hold_court.7050.b.defeat
					death = {
						killer = scope:lunatic_soldier
						death_reason = death_duel
					}
				}
			}
		}
		ai_chance = {
			base = 10
			modifier = {
				factor = 0
				NOT = {
					ai_rationality < -50
				}
			}
		}
	}

	option = { # Have them executed
		name = hold_court.7050.c

		stress_impact = {
			vengeful = medium_stress_loss
			wrathful = medium_stress_loss
			arbitrary = minor_stress_loss
			callous = medium_stress_loss
			sadistic = medium_stress_loss
			compassionate = medium_stress_gain
			forgiving = medium_stress_gain
		}

		execute_prisoner_effect = {
			VICTIM = scope:lunatic_soldier
			EXECUTIONER = root
		} 

		ai_chance = {
			base = 10
			modifier = {
				factor = 0
				OR = {
					has_trait = compassionate
					has_trait = forgiving
				}
			}
		}
	}

	option = { # Neutral choice - let them go
		name = hold_court.7050.d
		add_prestige = miniscule_prestige_gain

		if = {
			limit = {
				scope:lunatic_soldier = {
					OR = {
						is_courtier_of = root
						is_foreign_court_or_pool_guest_of = root
					}
				}
			}
			remove_courtier_or_guest = scope:lunatic_soldier
		}
		hidden_effect = {
			scope:lunatic_soldier = {
				death = {
					death_reason = death_vanished
				}
			}
		}
		ai_chance = {
			base = 100
		}
	}

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

hold_court.7051 = {
	# Hidden event that fires the follow-up stuff
	# trigger event with a one day delay
	hidden = yes

	immediate = {
		if = {
			limit = { scope:sc_victor = { this = scope:lunatic_soldier } }
			scope:lunatic_soldier = {
				death = { 
					death_reason = death_suicide
				}
			}
			scope:killed_pc_heir = {
				trigger_event = {
					id = hold_court.7052
					days = 1
				}
			}
		}
		else_if = {
			limit = { scope:sc_victor = { this = root } }
			trigger_event = {
				id = hold_court.7053
				days = 1
			}
		}
	}
}

hold_court.7052 = {
	type = character_event
	title = hold_court.7052.title
	desc = hold_court.7052.desc
	theme = death
	left_portrait = {
		character = root
		animation = grief
	}
	right_portrait = {
		character = scope:lunatic_soldier
		animation = grief
	}

	option = {
		name = hold_court.7052.a
	}
}

hold_court.7053 = {
	hidden = yes

	immediate = {
		# Execute effects
		hold_court_7050_duel_effects = yes
	}
}

hold_court.7054 = {
	hidden = yes

	immediate = {
		# Inform root that the duel has invalidated.
		send_interface_toast = {	
			title = hold_court.7054.sc_invalid
			left_icon = root
			right_icon = scope:lunatic_soldier
		}
	}
}

##################################################
# Who is That?
# by George Luff
# 7060 - 7069
##################################################

scripted_effect hold_court_7060_rival_effects = {
	hidden_effect = {
		progress_towards_rival_effect = {
			CHARACTER = scope:cinderella
			REASON = rival_cinderella_dislike
			OPINION = default_rival_opinion
		}
	}
	progress_towards_rival_effect = {
		CHARACTER = root
		REASON = rival_cinderella
		OPINION = 0
	}
}

# Unmarried Ruler is propositioned by a vassal's daughter but is distracted by Cinderella/Cinderedward
hold_court.7060 = {
	type = court_event
	title = hold_court.7060.title
	desc = hold_court.7060.desc
	theme = court
	lower_left_portrait = scope:cinderella
	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 = personality_bold
			}
			scope:vassal_spouse = {
				group = petitioners_group
				animation = personality_content
			}
		}
	}

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

	trigger = {
		is_ai = no
		NOT = { has_character_flag = had_hold_court_event_7060 }
		is_married = no
		# Eligible vassal spouse exists
		any_vassal = {
			has_court_event_flag = no
			any_child = {
				has_court_event_flag = no
				location = prev.capital_province
				is_married = no
				NOT = { sex_same_as = root }
				is_adult = yes
			}
		}	
	}

	weight_multiplier = {
		base = 0.5

		# Better chance of firing if the player is a good boi.
		modifier = {
			add = 0.1
			has_trait = compassionate
		}

		modifier = {
			add = 0.1
			has_trait = humble
		}

		modifier = {
			add = 0.1
			has_trait = temperate
		}

		modifier = {
			add = 0.1
			has_trait = forgiving
		}

		modifier = {
			add = 0.1
			has_trait = generous
		}

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

	immediate = {
		add_character_flag = had_hold_court_event_7060
		# Identify the vassal and potential bride
		random_vassal = {
			limit = {
				has_court_event_flag = no
				any_child = {
					has_court_event_flag = no
					location = prev.capital_province
					is_married = no
					NOT = { sex_same_as = root }
					is_adult = yes
				} 	
			}
			save_scope_as = vassal
			court_event_character_flag_effect = yes
			random_child = {
				limit = {
					has_court_event_flag = no
					location = prev.capital_province
					is_married = no
					NOT = { sex_same_as = root }
					is_adult = yes
				}
				save_scope_as = vassal_spouse
				court_event_character_flag_effect = yes
			}
		}
		# Creation of Cinderella character dependent on sexuality
		if = {
			limit = { is_attracted_to_men = yes }
			create_character = {
				location = root.capital_province
				template = cinderella_character
				gender = male
				save_scope_as = cinderella
			}
		}
		else_if = {
			limit = { is_attracted_to_men = no }
			create_character = {
				location = root.capital_province
				template = cinderella_character
				gender = female
				save_scope_as = cinderella
			}
		}
		scope:cinderella = {
			court_event_character_flag_effect = yes
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = { # I will ask eligible_vassal_spouse to stay at court a while
		name = hold_court.7060.a
		custom_tooltip = hold_court.7060.a.tt
		trigger = {
			exists = scope:vassal
			exists = scope:vassal_spouse
			exists = scope:cinderella
		}
		hidden_effect = {
			every_scheme = {
				limit = {
					OR = {
						scheme_type = befriend
						scheme_type = sway
						scheme_type = seduce
						scheme_type = courting
						scheme_type = elope
					}
				}
				end_scheme = yes
			}
		}

		# Vassal is happy
		scope:vassal = {
			add_opinion = {
				modifier = pleased_opinion
				target = root
				opinion = 25
			}
		}
		# Vassal_spouse wants you
		scope:vassal_spouse = {
			add_opinion = {
				modifier = developing_attraction_opinion
				target = root
				opinion = 20
			}
		}
		add_character_modifier = {
			modifier = pursuing_a_desirable_match
			years = 5
		}
		add_courtier = scope:vassal_spouse
		start_scheme = {
			type = courting
			target = scope:vassal_spouse
		}

		hidden_effect = { # Cleanup murder, Cinderpeople are desirable and we don't want them wandering about
			scope:cinderella = {
				death = {
					death_reason = death_vanished
				}
			}
		}
		ai_chance = {
			base = 30
			ai_value_modifier = {
				ai_honor = 20
				ai_rationality = 50
				ai_energy = 5
				ai_greed = -100
				ai_compassion = -5
				ai_zeal = -50
			}
		}
	}

	option = { # I must know who that is!
		name = hold_court.7060.b
		custom_tooltip = hold_court.7060.b.tt
		trigger = {
			exists = scope:vassal
			exists = scope:vassal_spouse
			exists = scope:cinderella
		}
		# Drawback that any other personal scheme you have will be dropped
		hidden_effect = {
			every_scheme = {
				limit = {
					OR = {
						scheme_type = befriend
						scheme_type = sway
						scheme_type = seduce
						scheme_type = courting
						scheme_type = elope
						# Hostile schemes "should" get dropped by the negative modifier in hold_court_7060_infatuated, but just to be sure, let's clean up properly
						scheme_type = murder
						scheme_type = abduct
						scheme_type = claim_throne
						scheme_type = fabricate_hook
						scheme_type = convert_to_witchcraft
					}
				}
				end_scheme = yes
			}
		}
		hidden_effect = { add_courtier = scope:cinderella } # They were always here
		add_prestige = medium_prestige_loss
		# Initiates a Romance scheme with the Cinderella/Cinderedward
		start_scheme = {
			type = courting
			target = scope:cinderella
		}
		scope:cinderella = {
			add_opinion = {
				modifier = developing_attraction_opinion
				target = root
				opinion = 20
			}
		}
		add_character_modifier = {
			modifier = hold_court_7060_infatuated
			years = 1
		}
		scope:vassal = {
			add_opinion = {
				modifier = insult_opinion
				target = root
				opinion = -35
			}
			hold_court_7060_rival_effects = yes
		}
		scope:vassal_spouse = {
			add_opinion = {
				modifier = rejected_opinion
				target = root
			}
			hold_court_7060_rival_effects = yes
		}
		ai_chance = {
			base = 30
			ai_value_modifier = {
				ai_zeal = 100
				ai_compassion = 50
				ai_energy = 50
				ai_rationality = -10
				ai_honor = -50
			}
		}
	}

	option = { # I shall accept the hand of eligible_vassal_spouse
		name = hold_court.7060.c
		custom_tooltip = hold_court.7060.c.tt
		trigger = {
			exists = scope:vassal
			exists = scope:vassal_spouse
			exists = scope:cinderella
		}
		marry = scope:vassal_spouse
		add_prestige = medium_prestige_gain
		
		scope:vassal = {
			add_opinion = {
				modifier = pleased_opinion
				target = root
				opinion = 35
			}
		}

		scope:vassal_spouse = {
			add_opinion = {
				modifier = love_opinion
				target = root
				opinion = 20
			}
		}

		hidden_effect = { # Cleanup murder, Cinderpeople are desirable and we don't want them wandering about
			scope:cinderella = {
				death = {
					death_reason = death_vanished
				}
			}
		}
		ai_chance = {
			base = 20
			ai_value_modifier = {
				ai_honor = 100
				ai_compassion = 10
				ai_energy = -30
				ai_rationality = 100
			}
		}
	}

	option = { # Gondor has no wife, Gondor needs no wife.
		name = hold_court.7060.d
		trigger = {
			exists = scope:vassal
			exists = scope:vassal_spouse
			exists = scope:cinderella
		}
		if = {
			limit = { 
				NOR = {
					 has_trait = shy 
					 has_trait = gregarious
					 number_of_personality_traits >= personality_trait_limit
				}
			}
			add_trait = shy
		}
		else_if = {
			limit = { has_trait = shy }
			add_character_modifier = {
				modifier = hold_court_7060_alone
				years = 1
			}
		}

		stress_impact = {
			base = massive_stress_impact_loss
			gregarious = medium_stress_impact_gain
		}

		scope:vassal = {
			add_opinion = {
				modifier = insult_opinion
				target = root
				opinion = -25
			}
		}
		scope:vassal_spouse = {
			add_opinion = {
				modifier = rejected_opinion
				target = root
			}
		}

		hidden_effect = { # Cleanup murder, Cinderpeople are desirable and we don't want them wandering about
			scope:cinderella = {
				death = {
					death_reason = death_vanished
				}
			}
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_honor = -10
				ai_compassion = -10
				ai_energy = -100
				ai_zeal = -50
			}
		}
	}

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

##################################################
# In Tithes of Trouble
# by George Luff
# 7070 - 7079
##################################################

scripted_trigger hold_court_7070_modifiers_trigger = {
	OR = {
		has_character_modifier = hold_court_7070_defended_peasantry
		has_character_modifier = hold_court_7070_defended_church
		has_character_modifier = hold_court_7070_undermined_church
	}
}

# Tithe Barn suffers theft
hold_court.7070 = {
	type = court_event
	title = hold_court.7070.title
	desc = hold_court.7070.desc
	theme = court
	court_scene = {
		button_position_character = scope:irritated_bishop
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:irritated_bishop = {
				group = petitioners_group
				animation = anger
			}
			scope:hapless_thief = {
				group = petitioners_group
				animation = fear
			}
		}
	}

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

	trigger = {
		NOT = { has_character_flag = had_hold_court_7070 }
		hold_court_7070_modifiers_trigger = no
		# Must be have clerical taxation doctrine
		#AGOT Modified
		# faith = { religion_tag = christianity_religion }
		faith = { religion_tag = faith_of_the_seven_religion }
		faith = { has_doctrine = doctrine_clerical_function_taxation }
		# A valid bishop exists
		any_theocratic_vassal = {
			has_court_event_flag = no
			faith = root.faith
			is_landed = yes
			is_available_healthy_ai_adult = yes
		}
	}

	immediate = {
		add_character_flag = had_hold_court_7070
		# Generate thief - scope:hapless_thief
		create_character = {
			location = root.capital_province
			template = generic_peasant_character
			save_scope_as = hapless_thief
		}
		scope:hapless_thief = {
			court_event_character_flag_effect = yes
		}
		# Select bishop - scope:irritated_bishop
		random_theocratic_vassal = {
			limit = {
				has_court_event_flag = no
				is_available_healthy_ai_adult = yes
				faith = root.faith
				is_landed = yes
			}
			save_scope_as = irritated_bishop
			court_event_character_flag_effect = yes
		}
		scope:irritated_bishop = {
			capital_province = {
				save_scope_as = tithe_province
			}
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = { # Just option - thievery is wrong but extortionate tithes are too
		name = hold_court.7070.a
		flavor = hold_court.7070.a.tt

		stress_impact = {
			just = major_stress_impact_loss
			greedy = major_stress_impact_gain
		}
		add_character_modifier = {
			modifier = hold_court_7070_defended_peasantry
			years = 10
		}

		scope:irritated_bishop = {
			add_opinion = {
				modifier = angry_opinion
				target = root
				opinion = -20
			}
		}

		# Cleanup
		scope:hapless_thief = {
			silent_disappearance_effect = yes
		}
		ai_chance = {
			base = 30
			ai_value_modifier = {
				ai_honor = 50
				ai_compassion = 50
				ai_rationality = 20
				ai_zeal = -100
			}
		}
	}

	option = { # Zealous option - I will not abide the Church being maltreated
		name = hold_court.7070.b
		flavor = hold_court.7070.b.tt

		trigger = {
			has_trait = zealous
		}

		stress_impact = {
			zealous = medium_stress_impact_loss
			sadistic = minor_stress_impact_loss
			callous =  minor_stress_impact_loss
			compassionate = major_stress_impact_gain
		}

		scope:hapless_thief = {
			death = {
				death_reason = death_execution
				killer = root
			}
		}

		add_character_modifier = {
			modifier = hold_court_7070_defended_church
			years = 10
		}

		scope:irritated_bishop = {
			add_opinion = {
				modifier = pious_opinion
				target = root
				opinion = 20
			}
		}
		ai_chance = {
			base = 30
			ai_value_modifier = {
				ai_honor = -20
				ai_compassion = -50
				ai_zeal = 100
			}
		}
	}

	option = { # Compassionate option - the peasants are starving, let them eat food!
		name = hold_court.7070.c
		flavor = hold_court.7070.c.tt

		trigger = {
			scope:irritated_bishop = {
				scope:tithe_province = {
					OR = {
						free_building_slots > 1
						has_existing_farming_building_trigger = yes
					}
				}
			}
		}

		stress_impact = {
			compassionate = medium_stress_impact_loss
			sadistic = major_stress_impact_loss
			callous =  major_stress_impact_loss
		}

		scope:irritated_bishop = {
			scope:tithe_province = {
				upgrade_farm_building = yes
			}
			add_opinion = {
				modifier = angry_opinion
				target = root
				opinion = -35
			}
		}
		scope:hapless_thief = {
			silent_disappearance_effect = yes
		}
		add_character_modifier = {
			modifier = hold_court_7070_undermined_church
			years = 5
		}
		ai_chance = {
			base = 20
			ai_value_modifier = {
				ai_honor = 10
				ai_compassion = 100
				ai_rationality = 10
				ai_zeal = -50
			}
		}
	}

	option = { # A thief is a thief
		name = hold_court.7070.d

		stress_impact = {
			forgiving = major_stress_impact_gain
			arbitrary = minor_stress_impact_loss
			vengeful = medium_stress_impact_loss
		}

		rightfully_imprison_character_effect = { 
			TARGET = scope:hapless_thief
			IMPRISONER = root
		}
		ai_chance = {
			base = 20
			ai_value_modifier = {
				ai_honor = 10
				ai_compassion = -50
				ai_rationality = 20
				ai_zeal = 20
				ai_energy = -10
			}
		}
	}

	option = { # Greedy option - Taxes are mine to collect, not the Church's!
		name = hold_court.7070.e
		flavor = hold_court.7070.e.tt

		trigger = {
			has_trait = greedy
		}

		stress_impact = {
			zealous = massive_stress_impact_gain
			just = major_stress_impact_gain
			generous = major_stress_impact_gain
			greedy = minor_stress_impact_loss
			cynical = minor_stress_impact_loss
		}

		add_gold = medium_gold_value

		scope:irritated_bishop = {
			progress_towards_rival_effect = {
				CHARACTER = root
				REASON = rival_irritated_bishop
				OPINION = default_rival_opinion
			}

			rightfully_imprison_character_effect = { 
				TARGET = scope:hapless_thief
				IMPRISONER = scope:irritated_bishop
			}
		}
		ai_chance = {
			base = 20
			ai_value_modifier = {
				ai_greed = 500
				ai_zeal = -100
			}
		}
	}

	after = {
		scope:hapless_thief = {
			clear_court_event_participation = yes
		}
		scope:irritated_bishop = {
			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
		}
		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
			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_gold >= major_gold_value
			}
		}
		remove_short_term_gold = medium_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
	}
}

##################################################
# 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
	vassal_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 = {
		#AGOT Modified, must be actually independent
		#is_independent_ruler = yes
		agot_is_independent_ruler = yes
		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_gold >= major_gold_value
			}
		}
		remove_short_term_gold = medium_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_gold >= major_gold_value
			}
		}
		remove_short_term_gold = medium_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 = {
	NOT = { 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
					NOT = { root = root.faith.religious_head }
				}
				this = root.faith.religious_head
			}
		}
		any_held_title = {
			count >= 2
			tier = 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
		}
	}
}

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 }
		is_independent_ruler = yes
		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 = {
			#AGOT Disabled
			# if = {
			# 	limit = { religion = religion:christianity_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 }
			#AGOT Disabled
			#}
			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 = {
				NOT = { 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 }
			NOT = { scope:target_county.holder = root }
		}
		add_piety = minor_piety_loss
		scope:target_county.holder = {
			if = {
				limit = {
					NOT = { 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
			NOT = { 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
	}
}

##################################################
# Civic Rivalry
# by Joe Parkin
# 8030 - 031
##################################################

scripted_trigger hold_court_8030_same_county_trigger = {
	primary_title.county.holder = {
		any_sub_realm_barony = {
			NOT = { has_variable = hold_court_city_cooldown_var }
			holder = {
				NOT = { this = prev.holder } # prev = primary_title.county.holder
				hold_court_available_mayor_trigger = yes
				is_vassal_of = root
			}
		}
	}
}	

scripted_trigger hold_court_8030_neighbor_county_trigger = {
	primary_title.county = {
		any_title_to_title_neighboring_county = {
			holder = {
				this = root
				any_sub_realm_barony = {
					holder = { hold_court_available_mayor_trigger = yes }
				}
			}
		}
	}
}	

scripted_effect hold_court_8030_favored_effect = {
	add_opinion = {
		modifier = pleased_opinion
		target = root
		opinion = 10
	}
	progress_towards_friend_effect = {
		REASON = friend_took_side_in_dispute
		CHARACTER = root
		OPINION = 0
	}
	if = {
		limit = { this = scope:mayor_1 }
		scope:mayor_2 = {
			add_opinion = {
				modifier = insult_opinion
				target = root
				opinion = -15
			}
			progress_towards_rival_effect = {
				CHARACTER = root
				REASON = rival_took_other_side_in_dispute
				OPINION = 0
			}
		}
	}
	else = {
		scope:mayor_1 = {
			add_opinion = {
				modifier = insult_opinion
				target = root
				opinion = -15
			}
			progress_towards_rival_effect = {
				CHARACTER = root
				REASON = rival_took_other_side_in_dispute
				OPINION = 0
			}
		}
	}
	primary_title.county = {
		if = {
			limit = {
				NAND = {
					this = scope:mayor_1.primary_title.county
					this = scope:mayor_2.primary_title.county
				}
			}
			add_county_modifier = {
				modifier = hold_court_8030_favored_modifier
				years = 10
			}
		}
		else = {
			add_county_modifier = {
				modifier = hold_court_8030_spurred_modifier
				years = 10
			}
		}
	}
}

scripted_effect hold_court_8030_duel_win_effect = {
	primary_title.county = {
		if = {
			limit = {
				NAND = {
					this = scope:mayor_1.primary_title.county
					this = scope:mayor_2.primary_title.county
				}
			}
			add_county_modifier = {
				modifier = hold_court_8030_duel_modifier
				years = 15
			}
		}
	}
}

scripted_effect hold_court_8030_duel_lose_effect = {
	add_opinion = {
		modifier = angry_opinion
		target = scope:mayor_1.liege
		opinion = -15
	}
}

# Solve a dispute between two rival towns in your realm
hold_court.8030 = {
	type = court_event
	title = hold_court.8030.t
	desc = {
		desc = hold_court.8030.desc.intro_1
		first_valid = { # Flavorful insults
			triggered_desc = {
				trigger = {
					NOT = { scope:mayor_1.primary_title.religion = scope:mayor_2.primary_title.religion }
				}
				desc = hold_court.8030.desc.intro_heretical
			}
			triggered_desc = {
				trigger = {
					NOT = { scope:mayor_1.primary_title.faith = scope:mayor_2.primary_title.faith }
				}
				desc = hold_court.8030.desc.intro_heathen
			}
			triggered_desc = {
				trigger = {
					NOT = { scope:mayor_1.primary_title.culture = scope:mayor_2.primary_title.culture }
				}
				desc = hold_court.8030.desc.intro_foreign
			}
			triggered_desc = {
				trigger = {	always = yes }
				desc = hold_court.8030.desc.intro_fallback
			}
		}
		desc = hold_court.8030.desc.intro_2
		first_valid = { # Relation of Mayors
			triggered_desc = {
				trigger = { scope:mayor_1.primary_title.county = scope:mayor_2.primary_title.county } # Same county
				desc = hold_court.8030.desc.body_same_county
			}
			triggered_desc = {
				trigger = { scope:mayor_1.primary_title.duchy = scope:mayor_2.primary_title.duchy } # Same duchy
				desc = hold_court.8030.desc.body_same_duchy
			}
			triggered_desc = {
				trigger = {
					scope:mayor_1.primary_title.county = {
						any_title_to_title_neighboring_county = { this = scope:mayor_2.primary_title.county } # Neighbor county
					}
				}
				desc = hold_court.8030.desc.body_neighbor_county
			}
			desc = hold_court.8030.desc.body_fallback
		}
	}
	theme = court
	court_scene = {
		button_position_character = scope:mayor_2
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:mayor_2 = {
				group = petitioners_group
				animation = anger
			}
		}
	}

	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
			save_temporary_scope_as = mayor_1_temp
		}
		any_vassal = {
			NOT = { this = scope:mayor_1_temp }
			hold_court_available_mayor_trigger = yes
			OR = {
				has_relation_rival = scope:mayor_1_temp
				can_set_relation_rival_trigger = { CHARACTER = scope:mayor_1_temp }
			}
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = 2
			any_vassal = { # Another city in the same county
				hold_court_available_mayor_trigger = yes
				hold_court_8030_same_county_trigger = yes
			}
		}
		modifier = {
			add = 1
			any_vassal = { # A city in a neighboring county
				hold_court_available_mayor_trigger = yes
				hold_court_8030_neighbor_county_trigger = yes
			}
		}

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

	immediate = {
		ordered_vassal = {
			limit = { # An existing rival mayor exists
				hold_court_available_mayor_trigger = yes
				save_temporary_scope_as = mayor_1_temp
				liege = {
					any_vassal = {
						NOT = { this = scope:mayor_1_temp }
						hold_court_available_mayor_trigger = yes
						OR = {
							has_relation_rival = scope:mayor_1_temp
							can_set_relation_rival_trigger = { CHARACTER = scope:mayor_1_temp }
						}
					}
				}
			}
			alternative_limit = { # Another city in the same county exists
				hold_court_available_mayor_trigger = yes
				hold_court_8030_same_county_trigger = yes
			}
			alternative_limit = { # A city in a neighboring county exists
				hold_court_available_mayor_trigger = yes
				hold_court_8030_neighbor_county_trigger = yes
			}
			alternative_limit = { hold_court_available_mayor_trigger = yes }
			order_by = monthly_character_income
			save_scope_as = mayor_1
			court_event_character_flag_effect = yes
		}
		ordered_vassal = {
			limit = { # An existing rival mayor
				NOT = { this = scope:mayor_1 }
				hold_court_available_mayor_trigger = yes
				has_relation_rival = scope:mayor_1
			}
			alternative_limit = { # Another city in the same county
				NOT = { this = scope:mayor_1 }
				hold_court_available_mayor_trigger = yes
				OR = {
					has_relation_rival = scope:mayor_1
					can_set_relation_rival_trigger = { CHARACTER = scope:mayor_1 }
				}
				primary_title.county = scope:mayor_1.primary_title.county
			}
			alternative_limit = { # A city in a neighboring county
				NOT = { this = scope:mayor_1 }
				hold_court_available_mayor_trigger = yes
				OR = {
					has_relation_rival = scope:mayor_1
					can_set_relation_rival_trigger = { CHARACTER = scope:mayor_1 }
				}
				primary_title.county = {
					any_title_to_title_neighboring_county = { this = scope:mayor_1.primary_title.county }
				}
			}
			alternative_limit = {
				NOT = { this = scope:mayor_1 }
				hold_court_available_mayor_trigger = yes
				OR = {
					has_relation_rival = scope:mayor_1
					can_set_relation_rival_trigger = { CHARACTER = scope:mayor_1 }
				}
			}
			order_by = monthly_character_income
			save_scope_as = mayor_2
			court_event_character_flag_effect = yes
			primary_title = {
				set_variable = {
					name = hold_court_city_cooldown_var
					years = 10
				}
			}
		}
		hidden_effect = {
			scope:mayor_1 = {
				if = {
					limit = {
						NOT = { has_relation_rival = scope:mayor_2 }
					}
					set_relation_rival = {
						target = scope:mayor_2
						reason = rival_inter_city_rivalry
					}
				}
			}
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = { # Favor City 1
		name = hold_court.8030.a
		highlight_portrait = scope:mayor_2
		scope:mayor_1 = { hold_court_8030_favored_effect = yes }
		stress_impact = {
			deceitful = medium_stress_impact_gain
			just = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
   				ai_rationality = -0.25
   			}
   			modifier = {	#Weight down for stress.
				add = -15
				has_trait = deceitful
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = just
			}
		}
	}

	option = { # Favor City 2
		name = hold_court.8030.b
		highlight_portrait = scope:mayor_2
		scope:mayor_2 = { hold_court_8030_favored_effect = yes }
		stress_impact = {
			honest = medium_stress_impact_gain
			arbitrary = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
   				ai_rationality = 0.25
   			}
   			modifier = {	#Weight down for stress.
				add = -15
				has_trait = honest
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = arbitrary
			}
		}
	}

	option = { # Settle their problems
		name = hold_court.8030.c
		duel = {
			skill = diplomacy
			value = hold_court_8030_average_mayor_diplomacy_value
			8 = {
				desc = hold_court.8030.c.tt_success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 2
				}
				send_interface_toast = {
					title = hold_court.8030.c.tt_success
					left_icon = scope:mayor_2
					right_icon = scope:mayor_1
					scope:mayor_2 = {
						remove_relation_rival = scope:mayor_1
						if = { # If in the same county, development
							limit = { primary_title.county = scope:mayor_1.primary_title.county }
							primary_title.county = {
								add_county_modifier = {
									modifier = hold_court_8030_settled_county_modifier
									years = 15
								}
							}
						}
						else = { # If not in the same county, republic opinion
							root = {
								add_character_modifier = {
									modifier = hold_court_8030_settled_character_modifier
									years = 15
								}
							}
						}
					}
				}
			}
			12 = {
				desc = hold_court.8030.c.tt_failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -1
				}
				send_interface_toast = {
					title = hold_court.8030.c.tt_failure
					left_icon = scope:mayor_2
					right_icon = scope:mayor_1
					add_prestige = medium_prestige_loss
					change_current_court_grandeur = minor_court_grandeur_loss
					scope:mayor_1 = {
						set_relation_nemesis = {
							reason = nemesis_mayoral_dispute
							copy_reason = rival
							target = scope:mayor_2
						}
					}
				}
			}
		}
		stress_impact = {
			lazy = medium_stress_impact_gain
			impatient = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
   				ai_rationality = 0.5
   			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = lazy
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = impatient
			}
		}
	}

	option = { # Force a duel
		name = hold_court.8030.d
		trigger = {
			NOT = {
				faith = { has_doctrine = tenet_pacifism }
			}
		}
		custom_tooltip = hold_court.8030.d.tt
		show_as_tooltip = {
			scope:mayor_2 = {
				set_relation_nemesis = {
					reason = nemesis_mayoral_dispute
					copy_reason = rival
					target = scope:mayor_1
				}
			}
			random_list = {
				10 = {
					show_chance = no
					desc = hold_court.8030.d.tt_mayor_1
					scope:mayor_1 = { hold_court_8030_duel_win_effect = yes }
					scope:mayor_2 = { hold_court_8030_duel_lose_effect = yes }
				}
				10 = {
					show_chance = no
					desc = hold_court.8030.d.tt_mayor_2
					scope:mayor_2 = { hold_court_8030_duel_win_effect = yes }
					scope:mayor_1 = { hold_court_8030_duel_lose_effect = yes }
				}
			}
		}
		configure_start_single_combat_effect = {
			SC_INITIATOR = scope:mayor_2
			SC_ATTACKER = scope:mayor_2
			SC_DEFENDER = scope:mayor_1
			FATALITY = no
			FIXED = no
			LOCALE = terrain_scope
			OUTPUT_EVENT = hold_court.8031
			INVALIDATION_EVENT = fp1_tbc.0102
		}
		stress_impact = {
			lifestyle_blademaster = medium_stress_impact_loss
			viking = medium_stress_impact_loss
			#AGOT Disabled
			# varangian = medium_stress_impact_loss
			berserker = medium_stress_impact_loss
			brave = medium_stress_impact_loss
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
   				ai_boldness = 0.5
   				ai_rationality = -0.25
   			}
   			modifier = {	#Weight up for stress.
				add = 15
				has_trait = lifestyle_blademaster
			}
			modifier = {	#Weight up for stress.
				add = 15
				has_trait = viking
			}
			#AGOT Disabled
			# modifier = {	#Weight up for stress.
			# 	add = 15
			# 	has_trait = varangian
			# }
			modifier = {	#Weight up for stress.
				add = 15
				has_trait = berserker
			}
			modifier = {	#Weight up for stress.
				add = 15
				has_trait = berserker
			}
			modifier = {	#Weight up for stress.
				add = 15
				has_trait = brave
			}
		}
	}

	option = { # Dismiss the issue
		name = hold_court.8030.e
		add_prestige = minor_prestige_gain
		scope:mayor_2 = {
			add_opinion = {
				modifier = dismissive_opinion
				target = root
				opinion = -15
			}
		}
		scope:mayor_1 = {
			add_opinion = {
				modifier = dismissive_opinion
				target = root
				opinion = -15
			}
		}
		stress_impact = {
			humble = medium_stress_impact_gain
			diligent = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
   				ai_boldness = 0.5
   			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = humble
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = diligent
			}
		}
	}

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

hold_court.8031 = {
	hidden = yes

	immediate = {
		scope:mayor_1.liege = {
			send_interface_toast = {
				title = hold_court.8031.t
				left_icon = scope:sc_victor
				right_icon = scope:sc_loser
				scope:sc_victor = { hold_court_8030_duel_win_effect = yes }
				scope:sc_loser = { hold_court_8030_duel_lose_effect = yes }
			}
		}
	}
}

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

scripted_trigger hold_court_8040_vassal_trigger = {
	has_court_event_flag = no
	NOT = { 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 = {
				NOT = { scope:infidel_vassal.religion = root.religion }
			}
			text = hold_court.8040.c.religion
		}
		name = {
			trigger = {
				NOT = { 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
					NOT = { 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_below_ai_friend_soft_cap_trigger = yes
	}
}

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
					NOT = { this = scope:vassal }
				}
			}
			ordered_court_position_holder = {
				type = bodyguard_court_position
				limit = {
					NOT = { 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
				}
			}
		}
		highlight_portrait = scope:bodyguard
		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
				}
			}
			appoint_court_position = {
				recipient = scope:knight
				court_position = bodyguard_court_position
			}
		}
		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 = 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 = {
				tier = tier_county
				county_has_empty_province_trigger = yes
				faith = ROOT.faith
				county_has_no_church_trigger = yes
			}
		}
		modifier = {
			add = 1
			any_held_title = {
				tier = 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_gold >= major_gold_value
			}
		}
		remove_short_term_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_short_term_gold = hold_court_holding_cost_half_value
		scope:vassal = {
			remove_short_term_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_short_term_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_short_term_gold = hold_court_holding_cost_half_value
				add_opinion = {
					target = root
					modifier = annoyed_opinion
					opinion = -15
				}
			}
			else = {
				scope:vassal = {
					remove_short_term_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_short_term_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_short_term_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_short_term_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
	}
	#AGOT DISABLED, Lets just use the above temple reference
	#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 = {
							NOT = { this = root }
						}
						if = {
							limit = {
								NOT = { 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 = {
				tier = tier_county
				county_has_empty_province_trigger = yes
				county_has_no_city_trigger = yes
			}
		}
		modifier = {
			add = 1
			any_held_title = {
				tier = 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_short_term_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_short_term_gold = hold_court_holding_cost_half_value
		scope:vassal = {
			remove_short_term_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_short_term_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_short_term_gold = hold_court_holding_cost_half_value
				add_opinion = {
					target = root
					modifier = annoyed_opinion
					opinion = -15
				}
			}
			else = {
				scope:vassal = {
					remove_short_term_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_short_term_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_short_term_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_short_term_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 = {
							NOT = { this = root }
						}
						if = {
							limit = {
								NOT = { 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 = {
			NOT = { 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 = {
						any_county_province = { is_coastal = 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 = {
		NOT = { has_character_flag = has_had_county_request_event }
		#AGOT Modified, must be actually independent
		#is_independent_ruler = yes
		agot_is_independent_ruler = yes
		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 = {
						any_county_province = { is_coastal = 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
		}
		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 = {
						any_county_province = { is_coastal = 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_gold >= root.medium_gold_value }
			scope:mayor = {
				pay_short_term_gold = {
					target = root
					gold = root.medium_gold_value
				}
			}
		}
		else = { add_gold = major_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
	has_any_court_position = 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 = { 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 = {
		has_any_court_position = no
		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
							#AGOT Disabled
							# 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
							#AGOT Disabled
							# scope:vassal.var:target_court_position = flag:chief_qadi
							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
							#AGOT Disabled
							# scope:vassal.var:target_court_position = flag:garuda
							scope:vassal.martial > scope:old_holder.martial
						}
						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 = { has_trait = eunuch }
				}
				desc = hold_court_8090_interest_seneschal_eunuch
			}
			#AGOT Disabled
			# 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 = {
					scope:vassal.var:target_court_position = flag:bodyguard
					has_relation_soulmate = scope:vassal
				}
				desc = hold_court_8090_interest_bodyguard_soulmate
			}
			triggered_desc = {
				trigger = {
					scope:vassal.var:target_court_position = flag:bodyguard
					has_relation_lover = scope:vassal
				}
				desc = hold_court_8090_interest_bodyguard_lover
			}
			triggered_desc = {
				trigger = {
					scope:vassal.var:target_court_position = flag:bodyguard
					has_relation_best_friend = scope:vassal
				}
				desc = hold_court_8090_interest_bodyguard_bestie
			}
			triggered_desc = {
				trigger = {
					scope:vassal.var:target_court_position = flag:bodyguard
					has_relation_friend = scope:vassal
				}
				desc = hold_court_8090_interest_bodyguard_friend
			}
			triggered_desc = {
				trigger = {
					OR = {
						scope:vassal.var:target_court_position = flag:champion
						#AGOT Disabled
						#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 = 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 = {
							NOT = { 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
			}
			#AGOT Disabled
			# triggered_desc = {
			# 	trigger = {
			# 		scope:vassal.var:target_court_position = flag:chief_qadi
			# 		scope:vassal = { has_trait = scholar }
			# 	}
			# 	desc = hold_court_8090_interest_qadi
			# }
			#AGOT Disabled
			# 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 = {
		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 = 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_target_variable_effect = { EMPLOYER = root }
			court_position_backup_variable_effect = { 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 = {
				scope:vassal.var:target_court_position = flag:bodyguard
				has_relation_soulmate = scope:vassal
			}
			text = hold_court.8090.a.bodyguard_soulmate
		}
		name = { # Bodyguard Lover
			trigger = {
				scope:vassal.var:target_court_position = flag:bodyguard
				has_relation_lover = scope:vassal
			}
			text = hold_court.8090.a.bodyguard_lover
		}
		name = { # Default
			trigger = { always = yes }
			text = hold_court.8090.a
		}
		court_position_variable_assignment_effect = { VARIABLE = target_court_position 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: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 = {
			scope:vassal = { has_variable = backup_court_position }
		}
		show_unlock_reason = no
		court_position_variable_assignment_effect = { VARIABLE = backup_court_position 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
			}
		}
		if = {
			limit = { exists = scope:old_holder }
			scope:old_holder = {
				add_opinion = {
					modifier = grateful_opinion
					target = root
					opinion = 5
				}
			}
		}
		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 = { # No Executioner, and scope:vassal is a criminal
					has_imprisonment_reason = scope:vassal
					NOT = { employs_court_position = executioner_court_position }
				}
				NOT = { employs_court_position = court_jester_court_position } # No Jester
				NOT = { employs_court_position = food_taster_court_position } # No 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
				}
			}
			appoint_court_position = {
				recipient = scope:vassal
				court_position = executioner_court_position
			}
			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
				}
			}
			appoint_court_position = {
				recipient = scope:vassal
				court_position = court_jester_court_position
			}
			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
				}
			}
			appoint_court_position = {
				recipient = scope:vassal
				court_position = food_taster_court_position
			}
			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
			if = {
				limit = { has_variable = backup_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
				}
			}
		}
		NOT = {
			AND = {
				exists = mother
				mother = { 
					is_landed = yes
				}
			}
		}
	}
	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
				}
			}
		}
		NOT = {
			AND = {
				exists = father
				father = {  
					is_landed = yes
				}
			}
		}
	}
	trigger_if = {
		limit = {
			faith = { has_doctrine = doctrine_gender_equal } # If equal, had no triggers before
		}
		OR = {
			AND = {
				OR = {
					NOT = { exists = father }
					father = {
						OR = {
							is_alive = no
							is_imprisoned = yes
						}
					}
				}
				NOT = {
					AND = {
						exists = mother
						mother = { 
							OR = { 
								is_landed = yes
							}
						}
					}
				}
			}
			AND = {
				OR = {
					NOT = { exists = mother }
					mother = {
						OR = {
							is_alive = no
							is_imprisoned = yes
						}
					}
				}
				NOT = {
					AND = {
						exists = father
						father = { 
							OR = { 
								is_landed = yes
							}
						}
					}
				}
			}
		}
	}
}

scripted_trigger hold_court_8100_parent_trigger = { # is a parent eligible to advocate?
	NOT = { 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 = {
				NOT = { 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 = {
				NOT = { 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
					NOT = { 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 = 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 = 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 = {
		is_adult = yes
		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 }
				NOT = { 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 ?= {
						NOT = { 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 = {
					exists = mother
					mother = { hold_court_8100_parent_trigger = yes }
				}
				mother = { save_scope_as = advocate }
			}
			else_if = {
				limit = {
					exists = father
					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 }
								NOT = { 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 = {
						NOT = { 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 = {
				NOT = { 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 = {
			#AGOT Modified, Westeros doesn't really do noble adoptions
			# 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
			# }
			base = 0
		}
	}

	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 = {
							NOT = { 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 = {
							NOT = { 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 = {
			tier = 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
			limit = {
				tier = tier_county
				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_court_position 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 }
			replace_court_position = {
				recipient = scope:peasant
				holder = scope:old_holder
				court_position = court_jester_court_position
			}
		}
		else = {
			if = {
				limit = {
					NOT = { employs_court_position = court_jester_court_position }
				}
				appoint_court_position = {
					recipient = scope:peasant
					court_position = court_jester_court_position
				}
			}
		}
		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
			}
		}
		# 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 = {
	NOT = { scope:peasant.religion = root.religion }
	OR = {
		#AGOT Modified, aithnea to do syncretism
		# 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
		# 	scope:peasant.religion = religion:christianity_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 }
		#AGOT Modified, must be actually independent
		#is_independent_ruler = yes
		agot_is_independent_ruler = yes
		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 }
		#AGOT Modified, aithnea to do syncretic
		# 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 = {
		# 			scope:peasant.religion = religion:christianity_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_gold = minor_gold_value
		if = {
			limit = {
				NOT = {
					faith = { has_doctrine = tenet_tax_nonbelievers }
				}
			}
			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 = { has_doctrine = tenet_tax_nonbelievers }
				}
				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 = { has_doctrine = tenet_tax_nonbelievers }
				}
				OR = {
					has_trait = cynical
					has_trait = deceitful
				}
			}
			modifier = {	#Weight down for stress.
				add = -30
				NOT = {
					faith = { has_doctrine = tenet_tax_nonbelievers }
				}
				OR = {
					has_trait = honest
					has_trait = zealous
				}
			}
			modifier = {	#Weight down for stress.
				add = -15
				faith = { has_doctrine = tenet_tax_nonbelievers }
				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 = {
				NOT = { 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 }
		#AGOT Modified, must be actually independent
		#is_independent_ruler = yes
		agot_is_independent_ruler = yes
		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 = {
				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 = {
					NOT = { 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 = {
					NOT = { 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 = {
					NOT = { 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 = { 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 = { story_type = story_cycle_pet_dog }
			any_owned_story = { 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 = { 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_gold >= massive_gold_value
			}
		}
		remove_short_term_gold = major_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 = yes
					NOT = { 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 = { story_type = story_cycle_pet_cat }
				}
			}
			every_vassal_or_below = {
				limit = {
					any_owned_story = { 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 = hold_court.8142.desc
	theme = realm
	override_background = { reference = throne_room }
	left_portrait = {
		character = scope:pup_house_ruler
		#AGOT MODIFIED
		#animation = happy
		animation = happiness 
	}

	immediate = {
		house.var:hold_court_8140_pup_founder = { 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 }
	exists = faction_leader
	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
					tier = tier_county
				}
			}
			ordered_held_title = {
				limit = {
					tier = tier_county
					NOT = { this = root.capital_county }
				}
				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 = {
					NOT = { 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 = {
								NOT = { 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 = {
								NOT = { 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.liege
	OR = { # Victim and plotter share same court
		scheme_owner = scheme_target.liege
		scheme_owner = { is_vassal_or_below_of = prev.scheme_target.liege }
		scheme_owner = { is_courtier_of = prev.scheme_target.liege }
	}
	NOR = {
		scheme_owner = root
		scheme_target = root
	}
}

scripted_trigger hold_court_8160_valid_plotter_trigger = {
	NOT = { 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 = 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 = {
		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 = {
	NOT = { 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 = {
	NOT = { 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 = {
	NOT = { 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 = { 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 = scope:victim
					}
				}
			}
			else = {
				random_courtier = {
					limit = { hold_court_8160_valid_plotter_trigger = yes }
					save_scope_as = debug_scheme_owner
					start_scheme = {
						type = murder
						target = 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 }
					NOT = { 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 }
				NOT = { 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 = {
	NOT = { this = root }
	is_available_ai_adult = yes
	NOR = {
		this = scope:victim
		has_friendly_relationship_trigger = { CHARACTER = scope:victim }
	}
	can_start_scheme = {
		type = murder
		target = 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 = {
		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 }
						}
						exists = mother
						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 }
						}
						exists = father
						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 = { 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 = { 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 = { 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 = {
	NOT = { 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 = 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 = {
	NOT = { 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 = { 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 = 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 = 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 = 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 = 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 = 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 = 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 = 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 = { 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 = { 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 = { 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
	}
}

##################################################
# Services Rendered
# by Joe Parkin
# 8170 - 171
##################################################

scripted_trigger hold_court_8170_knight_trigger = {
	has_court_event_flag = no
	is_available_ai_adult = yes
	age >= 35
	is_landed = no
	NOT = { is_close_or_extended_family_of = root }
	has_variable = hc_8170_fought_battle_for
	var:hc_8170_fought_battle_for = employer
	has_variable = hc_8170_fought_battle_where
	has_variable = hc_8170_fought_battle_against
	#AGOT Added
	NOT = { has_trait = kingsguard }
	NOT = { has_trait = nightswatch }
}

scripted_trigger hold_court_8170_barony_type_trigger = {
	exists = title_province
	OR = {
		title_province = { has_holding_type = castle_holding }
		AND = {
			title_province = { has_holding_type = church_holding }
			root.faith = { has_doctrine = doctrine_theocracy_lay_clergy }
		}
	}
}

scripted_trigger hold_court_8170_barony_trigger = {
	tier = tier_barony
	is_capital_barony = no
	NOT = { this = holder.capital_barony }
	hold_court_8170_barony_type_trigger = yes
}

scripted_trigger hold_court_8170_county_trigger = {
	tier = tier_county
	NOT = { this = root.capital_county }
}

scripted_trigger hold_court_8170_vassal_barony_trigger = {
	highest_held_title_tier = tier_barony
	any_held_title = {
		tier = tier_barony
		hold_court_8170_barony_type_trigger = yes
	}
}

hold_court.8170 = {
	type = court_event
	title = hold_court.8170.t
	desc = hold_court.8170.desc.intro
	theme = realm
	artifact = {
		target = scope:knight_weapon
		position = lower_center_portrait
	}
	lower_right_portrait = scope:vassal_title.holder
	court_scene = {
		button_position_character = scope:knight
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			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 = 10 }

	trigger = {
		is_at_war = no
		age >= 20
		any_knight = { hold_court_8170_knight_trigger = yes }
		OR = {
			any_held_title = { hold_court_8170_barony_trigger = yes } # Barony spare
			any_held_title = { hold_court_8170_county_trigger = yes } # County spare
			any_vassal = { hold_court_8170_vassal_barony_trigger = yes } # Vassal barony
			any_vassal = { 
				any_held_title = { hold_court_8170_county_trigger = yes } # Vassal county
			}
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			factor = 2
			domain_limit_available < 0
		}

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

	immediate = {
		ordered_knight = {
			limit = { hold_court_8170_knight_trigger = yes }
			order_by = prowess
			save_scope_as = knight
			court_event_character_flag_effect = yes
			if = {
				limit = {
					NOT = {
						any_character_artifact = { artifact_slot_type = primary_armament }
					}
				}
				set_signature_weapon_effect = yes
				random_dummy_gender_effect = yes #To feed to the weapon effect since we don't have a creator
				#To create an artifact of the "signature weapon" type
				if = {
					limit = { var:signature_weapon = flag:axe }
					create_artifact_weapon_effect = {
						OWNER = this
						CREATOR = scope:dummy_gender
						SET_WEAPON_TYPE = flag:artifact_weapon_type_axe
					}
				}
				else_if = {
					limit = { var:signature_weapon = flag:hammer }
					create_artifact_weapon_effect = {
						OWNER = this
						CREATOR = scope:dummy_gender
						SET_WEAPON_TYPE = flag:artifact_weapon_type_hammer
					}
				}
				else_if = {
					limit = { var:signature_weapon = flag:spear }
					create_artifact_weapon_effect = {
						OWNER = this
						CREATOR = scope:dummy_gender
						SET_WEAPON_TYPE = flag:artifact_weapon_type_spear
					}
				}
				else_if = {
					limit = { var:signature_weapon = flag:mace }
					create_artifact_weapon_effect = {
						OWNER = this
						CREATOR = scope:dummy_gender
						SET_WEAPON_TYPE = flag:artifact_weapon_type_mace
					}
				}
				else_if = {
					limit = { var:signature_weapon = flag:dagger }
					create_artifact_weapon_effect = {
						OWNER = this
						CREATOR = scope:dummy_gender
						SET_WEAPON_TYPE = flag:artifact_weapon_type_dagger
					}
				}
				else = { #For swords, but also as fallback
					create_artifact_weapon_effect = {
						OWNER = this
						CREATOR = scope:dummy_gender
						SET_WEAPON_TYPE = flag:artifact_weapon_type_sword
					}
				}
				scope:newly_created_artifact = { save_scope_as = knight_weapon }
			}
			else = {
				ordered_character_artifact = {
					limit = { artifact_slot_type = primary_armament }
					order_by = artifact_rarity
					save_scope_as = knight_weapon
				}
			}
		}
		if = { # My barony
			limit = {
				any_held_title = { hold_court_8170_barony_trigger = yes }
			}
			ordered_held_title = {
				limit = { hold_court_8170_barony_trigger = yes }
				order_by = {
					value = 0
					subtract = title_province.combined_building_level
				}
				save_scope_as = my_title
			}
		}
		else_if = { # My county
			limit = {
				any_held_title = { hold_court_8170_county_trigger = yes }
			}
			ordered_held_title = {
				limit = { hold_court_8170_county_trigger = yes }
				order_by = {
					value = 0
					subtract = development_level
				}
				save_scope_as = my_title
			}
		}
		if = { # Vassal barony
			limit = {
				any_vassal = { hold_court_8170_vassal_barony_trigger = yes }
			}
			random_vassal = {
				limit = { hold_court_8170_vassal_barony_trigger = yes }
				ordered_held_title = {
					limit = { hold_court_8170_barony_type_trigger = yes }
					order_by = {
						value = 0
						subtract = title_province.combined_building_level
					}
					save_scope_as = vassal_title
				}
			}
		}
		else_if = { # Vassal county
			limit = {
				any_vassal = {
					any_held_title = { hold_court_8170_county_trigger = yes }
				}
			}
			random_vassal = {
				limit = {
					any_held_title = { hold_court_8170_county_trigger = yes }
				}
				ordered_held_title = {
					limit = { hold_court_8170_county_trigger = yes }
					order_by = {
						value = 0
						subtract = development_level
					}
					save_scope_as = vassal_title
				}
			}
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = { # Give land
		name = hold_court.8170.a
		trigger = { exists = scope:my_title }
		create_title_and_vassal_change = {
			type = granted
			save_scope_as = change
			add_claim_on_loss = no
		}
		scope:my_title = {
			change_title_holder = {
				holder = scope:knight
				change = scope:change
			}
		}
		resolve_title_and_vassal_change = scope:change
		scope:knight = {
			add_opinion = {
				modifier = grateful_opinion
				target = root
				opinion = 40
			}
		}
		if = {
			limit = { domain_limit_available >= 0 }
			stress_impact = {
				greedy = major_stress_impact_gain
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = -0.5
   				ai_compassion = 0.5
   				ai_greed = -0.25
			}
			modifier = {	#Weight down for stress.
				add = -60
				domain_limit_available >= 0
				has_trait = greedy
			}
		}
	}

	option = { # Give vassal's land
		name = hold_court.8170.b
		trigger = { exists = scope:vassal_title }
		scope:vassal_title.holder = {
			add_opinion = {
				modifier = angry_opinion
				target = root
				opinion = -60
			}
			add_opinion = {
				modifier = angry_opinion
				target = scope:knight
				opinion = -30
			}
			hold_court_8001_revoke_title_effect = yes
		}
		create_title_and_vassal_change = {
			type = revoked
			save_scope_as = change
			add_claim_on_loss = yes
		}
		scope:vassal_title = {
			change_title_holder = {
				holder = scope:knight
				change = scope:change
			}
		}
		resolve_title_and_vassal_change = scope:change
		scope:knight = {
			add_opinion = {
				modifier = grateful_opinion
				target = root
				opinion = 40
			}
		}
		if = {
			limit = { scope:vassal_title.tier = tier_county }
			add_tyranny = major_tyranny_gain
		}
		else = { add_tyranny = minor_tyranny_gain }
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = -1
   				ai_compassion = 0.5
   				ai_boldness = 1
			}
		}
	}

	option = { # Give land for sword
		name = hold_court.8170.c
		trigger = {
			exists = scope:my_title
			exists = scope:knight_weapon
		}
		scope:knight = {
			get_title = scope:my_title
			add_opinion = {
				modifier = grateful_opinion
				target = root
				opinion = 10
			}
		}
		scope:knight_weapon = {
			set_owner = {
				target = root
				history = {
					location = root.capital_province
					actor = scope:knight
					recipient = root
					type = given
				}
			}
		}
		hidden_effect = {
			scope:knight = { add_personal_artifact_claim = scope:knight_weapon }
		}
		if = {
			limit = { domain_limit_available >= 0 }
			stress_impact = {
				greedy = major_stress_impact_gain
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = -1
   				ai_compassion = 0.5
   				ai_boldness = 1
			}
			modifier = {	#Weight down for stress.
				add = -60
				domain_limit_available >= 0
				has_trait = greedy
			}
		}
	}

	option = { # Give land if they can beat vassal
		name = hold_court.8170.d
		trigger = { exists = scope:vassal_title }
		custom_tooltip = hold_court.8170.d.tt
		show_as_tooltip = {
			random_list = {
				10 = {
					show_chance = no
					desc = hold_court.8170.d.tt_knight
					scope:vassal_title.holder = {
						add_opinion = {
							modifier = angry_opinion
							target = root
							opinion = -20
						}
					}
					create_title_and_vassal_change = {
						type = revoked
						save_scope_as = change
						add_claim_on_loss = yes
					}
					scope:vassal_title = {
						change_title_holder = {
							holder = scope:knight
							change = scope:change
						}
					}
					resolve_title_and_vassal_change = scope:change
				}
				10 = {
					show_chance = no
					desc = hold_court.8170.d.tt_vassal
				}
			}
		}
		configure_start_single_combat_effect = {
			SC_INITIATOR = scope:knight
			SC_ATTACKER = scope:knight
			SC_DEFENDER = scope:vassal_title.holder
			FATALITY = no
			FIXED = no
			LOCALE = terrain_scope
			OUTPUT_EVENT = hold_court.8171
			INVALIDATION_EVENT = fp1_tbc.0102
		}
		add_tyranny = minor_tyranny_gain
		stress_impact = {
			lifestyle_blademaster = medium_stress_impact_loss
			viking = medium_stress_impact_loss
			#AGOT Disabled
			# varangian = medium_stress_impact_loss
			berserker = medium_stress_impact_loss
			brave = medium_stress_impact_loss
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
   				ai_boldness = 1
   				ai_rationality = -0.25
   			}
   			modifier = {	#Weight up for stress.
				add = 15
				has_trait = lifestyle_blademaster
			}
			modifier = {	#Weight up for stress.
				add = 15
				has_trait = viking
			}
			#AGOT Disabled
			# modifier = {	#Weight up for stress.
			# 	add = 15
			# 	has_trait = varangian
			# }
			modifier = {	#Weight up for stress.
				add = 15
				has_trait = berserker
			}
			modifier = {	#Weight up for stress.
				add = 15
				has_trait = berserker
			}
			modifier = {	#Weight up for stress.
				add = 15
				has_trait = brave
			}
		}
	}

	option = { # Give gold
		name = hold_court.8170.e
		trigger = { 
			NOT = { exists = scope:vassal_title }
			trigger_if = {
				limit = {
					is_ai = yes
				}
				short_term_gold >= medium_gold_value
			}
		}
		pay_short_term_gold = {
			target = scope:knight
			gold = minor_gold_value
		}
		scope:knight = {
			add_opinion = {
				modifier = disappointed_opinion
				target = root
				opinion = -10
			}
		}
		stress_impact = {
			greedy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = -0.5
   				ai_compassion = 0.5
   				ai_greed = -0.25
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = greedy
			}
		}
	}

	option = { # Refuse
		name = hold_court.8170.f
		scope:knight = {
			add_opinion = {
				modifier = disappointed_opinion
				target = root
				opinion = -20
			}
			move_to_pool = yes
		}
		stress_impact = {
			compassionate = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = -1
   				ai_compassion = -2
   				ai_greed = 1
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = compassionate
			}
		}
	}

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

hold_court.8171 = {
	hidden = yes

	immediate = {
		scope:sc_victor.liege = {
			send_interface_toast = {
				title = hold_court.8031.t
				left_icon = scope:sc_victor
				right_icon = scope:sc_loser
				if = {
					limit = { scope:sc_victor = scope:knight }
					create_title_and_vassal_change = {
						type = revoked
						save_scope_as = change
						add_claim_on_loss = yes
					}
					scope:vassal_title = {
						change_title_holder = {
							holder = scope:knight
							change = scope:change
						}
					}
					resolve_title_and_vassal_change = scope:change
					scope:sc_loser = {
						add_opinion = {
							modifier = angry_opinion
							target = root
							opinion = -20
						}
					}
				}
			}
		}
	}
}

##################################################
# 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
	vassal_contract_is_blocked_from_modification = no
	NOT = { has_variable = hc_8180_contract_var }
	NOT = { has_hook = root }
	OR = {
		AND = {
			NOT = { 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_vassal_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
						tier = tier_county
					}
				}
				ordered_held_title = {
					limit = {
						tier = tier_county
						NOT = { this = holder.capital_county }
						de_jure_liege.holder = root
					}
					alternative_limit = {
						tier = tier_county
						NOT = { this = holder.capital_county }
						any_neighboring_county = { holder = root }
					}
					alternative_limit = {
						tier = tier_county
						NOT = { this = holder.capital_county }
					}
					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 = {
							NOT = { faith = liege.faith }
							vassal_contract_obligation_level_can_be_increased = religious_rights
						}
						modifier = {
							factor = 2
							NOT = { faith = liege.faith }
						}
						modifier = {
							factor = 2
							NOT = { 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
			NOT = { 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
				NOT = { 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 = {
						tier = 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 = {
				NOT = { 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
			40 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -39
				}
				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
						}
					}
				}
			}
			60 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -59
				}
				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
					NOT = { this = scope:other_vassal }
				}
			}
			every_vassal = {
				limit = {
					culture = scope:other_vassal.culture
					NOT = { 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 = {
				NOT = { 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
					NOT = { this = scope:aggressor_vassal }
				}
			}
			every_vassal = {
				limit = {
					culture = root.culture
					has_trait = arrogant
					NOT = { 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
##################################################

#AGOT Disabled
# scripted_trigger hold_court_8200_infidel_trigger = {
# 	is_available_ai_adult = yes
# 	NOT = { 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
# 			religion = religion:christianity_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
# 			tier < tier_duchy
# 		}
# 	}
# }

#AGOT Disabled
# 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 = {
# 						tier = 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
# 					NOT = { 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
# 				NOT = { 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 = {
# 				NOT = { 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
# 					NOT = { this = scope:aggressor_vassal }
# 				}
# 			}
# 			every_vassal = {
# 				limit = {
# 					faith = root.faith
# 					has_trait = zealous
# 					NOT = { 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
	holder = {
		NOT = { this = $VASSAL$ }
		OR = {
			this = root
			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 = {
			tier = 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 = {
			NOR = { 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 = {
					limit = {
						tier = tier_county
						any_neighboring_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 = {
							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
						}
					}
				}
				NOT = { 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 = {
			NOT = {
				faith = { has_doctrine = tenet_pacifism }
			}
			NOR = { 
				has_realm_law = crown_authority_2
				has_realm_law = crown_authority_3
			}
			NOT = { 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 = {
				NOT = { scope:defender_vassal = root }
			}
			text = hold_court.8210.f.other
		}
		name = {
			trigger = { always = yes }
			text = hold_court.8210.f.self
		}
		trigger = {
			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
			#AGOT Disabled
			# 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 }
					#AGOT Disabled
					# 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 = {
				NOT = { 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 = {
				NOT = { 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 = {
			NOT = { 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 = {
			NOT = { 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 = {
							NOT = { 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 = {
							NOT = { 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
					}
				}
			}
		}
	}
}

##################################################
# Opportunity Knocks
# by Joe Parkin
# 8220 - 8222
##################################################

# Is assassin a courtier and the type to give life away?
scripted_trigger hold_court_8220_attacker_trigger = {
	has_court_event_flag = no
	is_available_ai_adult = yes
	NOT = { this = root.primary_heir }
	OR = {
		is_vassal_of = root
		is_courtier_of = root
	}
	NOR = {
		is_agent_exposed_in_scheme = prev
		has_trait = calm
		has_trait = shrewd
		has_trait = patient
		has_trait = craven
		has_trait = content
	}
}

# Is assassin more likely to be reckless?
scripted_trigger hold_court_8220_weight_trigger = {
	OR = {
		has_relation_rival = root
		has_trait = wrathful
		has_trait = impatient
		has_trait = reckless
		health <= death_chance_dying_health
	}
}

# Is the entire scheme exposed by assassin?
scripted_trigger hold_court_8220_reveal_trigger = {
	OR = {
		has_trait = intellect_bad_1
		has_trait = intellect_bad_2
		has_trait = intellect_bad_3
		has_trait = trusting
		has_trait = honest
		intrigue <= 3
	}
}

# Can courtier be potentially killed/wounded?
scripted_trigger hold_court_8220_other_victim_trigger = {
	NOR = {
		has_relation_rival = root
		is_scheming_against = {
			target = root
			type = murder
		}
		has_trait = craven
	}
}

# Is courtier more likely to be killed/wounded?
scripted_trigger hold_court_8220_other_helpful_trigger = {
	OR = {
		has_relation_lover = root
		has_relation_friend = root
		has_trait = brave
	}
}

# A courtier tries to assassinate you while you hold court
hold_court.8220 = {
	type = court_event
	title = hold_court.8220.t
	desc = {
		desc = hold_court.8220.desc.intro
		random_valid = { # flavor reasons for wanting to kill you
			triggered_desc = {
				trigger = {
					scope:assassin = {
						NOT = { this = scope:murder_scheme.scheme_owner }	
						OR = {
							has_relation_friend = scope:murder_scheme.scheme_owner
							has_relation_lover = scope:murder_scheme.scheme_owner
							is_vassal_or_below_of = scope:murder_scheme.scheme_owner
						}
						hold_court_8220_reveal_trigger = yes
					}
				}
				desc = hold_court.8220.desc.follower
			}
			triggered_desc = {
				trigger = {
					NOT = { scope:assassin = scope:murder_scheme.scheme_owner }
					hold_court_8220_reveal_trigger = yes
				}
				desc = hold_court.8220.desc.stupid
			}
			triggered_desc = {
				trigger = {
					scope:assassin = {
						has_trait = arrogant
						NOT = { culture = root.culture }
					}
				}
				desc = hold_court.8220.desc.cultural
			}
			triggered_desc = {
				trigger = {
					scope:assassin = {
						has_trait = zealous
						NOT = { faith = root.faith }
					}
				}
				desc = hold_court.8220.desc.religious
			}
			triggered_desc = {
				trigger = {
					scope:assassin = {
						has_dread_level_towards = {
							target = root
							level >= 1
						}
					}
				}
				desc = hold_court.8220.desc.dread
			}
			triggered_desc = {
				trigger = { has_relation_rival = scope:assassin }
				desc = hold_court.8220.desc.vengeance
			}
			desc = hold_court.8220.desc.time
			desc = hold_court.8220.desc.insult
			desc = hold_court.8220.desc.die
		}
	}
	theme = court
	override_background = { reference = throne_room }
	cooldown = { years = 10 }

	court_scene = {
		button_position_character = scope:assassin
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:assassin = {
				group = petitioners_group
				animation = rage
			}
			scope:bodyguard = {
				group = petitioners_group
				animation = throne_room_one_handed_passive_1
			}
		}
	}

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

	trigger = {
		any_targeting_scheme = {
			scheme_type = murder
			OR = {
				scheme_owner = { hold_court_8220_attacker_trigger = yes }
				any_scheme_agent = { hold_court_8220_attacker_trigger = yes }
			}
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = 1
			any_targeting_scheme = {
				scheme_type = murder
				any_scheme_agent = {
					hold_court_8220_attacker_trigger = yes
					hold_court_8220_weight_trigger = yes
				}
			}
		}
		modifier = {
			add = 1
			court_grandeur_current_level < court_grandeur_minimum_expected_level
		}
		# Court weightings.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_intrigue }
	}

	immediate = {
		save_scope_as = victim
		random_targeting_scheme = { # Select murder scheme
			limit = {
				scheme_type = murder
				any_scheme_agent = { hold_court_8220_attacker_trigger = yes }
			}
			alternative_limit = {
				scheme_type = murder
				scheme_owner = { hold_court_8220_attacker_trigger = yes }
			}
			weight = {
				base = 2
				modifier = {
					factor = 2
					OR = {
						scheme_owner = { hold_court_8220_weight_trigger = yes }
						any_scheme_agent = { hold_court_8220_weight_trigger = yes }
					}
				}
				modifier = {
					factor = 10
					scheme_power <= 50
					scheme_duration_days >= 100
				}
			}			
			save_scope_as = murder_scheme
			if = {
				limit = {
					any_scheme_agent = { hold_court_8220_attacker_trigger = yes }
				}
				every_scheme_agent = {
					limit = { hold_court_8220_attacker_trigger = yes }
					add_to_list = attacker_list
				}
			}
			scheme_owner = {
				if = {
					limit = { hold_court_8220_attacker_trigger = yes }
					add_to_list = attacker_list
				}
			}
		}
		random_in_list = {
			list = attacker_list
			limit = { 
				is_landed = no
				hold_court_8220_weight_trigger = yes
			}
			alternative_limit = { hold_court_8220_weight_trigger = yes }
			alternative_limit = { is_landed = no }
			alternative_limit = { always = yes }
			weight = {
				base = 2
				modifier = {
					factor = 6
					is_landed = no
				}
				modifier = {
					factor = 2
					has_relation_rival = root
				}
				modifier = {
					factor = 2
					has_trait = wrathful
				}
				modifier = {
					factor = 2
					has_trait = impatient
				}
				modifier = {
					factor = 2
					has_trait = brave
				}
				modifier = {
					factor = 4
					OR = {
						has_education_intrigue_trigger = yes
						has_trait = deceitful
					}
				}
			}
			save_scope_as = assassin
			court_event_character_flag_effect = yes
		}
		if = { # Save bodyguard if they exist
			limit = {
				any_court_position_holder = {
					type = bodyguard_court_position
					NOT = { this = scope:assassin }
					is_available_healthy_ai_adult = yes
					has_court_event_flag = no
				}
			}
			random_court_position_holder = {
				type = bodyguard_court_position
				limit = {
					NOT = { this = scope:assassin }
					is_available_healthy_ai_adult = yes
					has_court_event_flag = no
				}
				save_scope_as = bodyguard
				court_event_character_flag_effect = yes
			}
		}
		if = { # Potential accidental victims
			limit = {
				is_married = yes
				primary_spouse = {
					is_available_ai = yes
					location = root.location
					hold_court_8220_other_victim_trigger = yes
				}
			}
			primary_spouse = { add_to_list = other_victim_list }
		}
		if = { # Potential accidental victims
			limit = {
				any_child = {
					count > 0
					is_adult = no
					age >= 6
					is_available_ai = yes
					location = root.location
					hold_court_8220_other_victim_trigger = yes
				}
			}
			every_child = {
				limit = {
					is_adult = no
					age >= 6
					is_available_ai = yes
					location = root.location
					hold_court_8220_other_victim_trigger = yes
				}
				add_to_list = other_victim_list
			}
		}
		every_courtier = { # Potential accidental victims
			limit = {
				is_available_ai = yes
				location = root.location
				hold_court_8220_other_victim_trigger = yes
			}
			add_to_list = other_victim_list
		}
		scope:murder_scheme = { # Reveal scheme and owner/agents
			if = {
				limit = { is_scheme_exposed = no }
				expose_scheme = yes
			}
			if = {
				limit = {
					NOT = { is_scheme_agent_exposed = scope:assassin }
				}
				expose_scheme_agent = scope:assassin
			}
		}
		if = { # Reveal scheme and owner/agents
			limit = {
				scope:assassin = {
					NOT = { this = scope:murder_scheme.scheme_owner }
					hold_court_8220_reveal_trigger = yes
				}
			}
			scope:murder_scheme = {
				if = {
					limit = {
						NOT = { is_scheme_agent_exposed = scope:murder_scheme.scheme_owner }
					}
					expose_scheme_agent = scope:murder_scheme.scheme_owner
				}
			}

		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = { # Flee
		name = {
			trigger = { has_trait = craven }
			text = hold_court.8220.a.craven
		}
		name = {
			trigger = { has_trait = paranoid }
			text = hold_court.8220.a.paranoid
		}
		name = {
			trigger = { always = yes }
			text = hold_court.8220.a.fallback
		}
		if = {
			limit = {
				NOR = {
					primary_heir = scope:assassin
					any_targeting_scheme = {
						scheme_type = murder
						OR = {
							scheme_owner = root.primary_heir
							scheme_is_character_agent = root.primary_heir
						}
					}
				}
			}
			scope:assassin = { set_variable = assassin_caught }
		}
		flavor = hold_court.8220.a.flavor_flee
		add_prestige = major_prestige_loss
		random_list = {
			12 = { # Bodyguard stops attacker
				trigger = { exists = scope:bodyguard }
				desc = hold_court_8220_bodyguard
				modifier = {
					factor = 0
					var:hold_court_8220_outcome != 1
					any_targeting_scheme = {
						scheme_type = murder
						OR = {
							scheme_owner = scope:bodyguard
							scheme_is_character_agent = scope:bodyguard
						}
					}
				}
				modifier = {
					factor = 2
					scope:bodyguard.prowess > mediocre_skill_rating
				}
				modifier = {
					factor = 2
					scope:bodyguard.prowess >= high_skill_rating
				}
				modifier = {
					factor = 2
					scope:bodyguard.prowess >= extremely_high_skill_rating
				}
				set_variable = {
					name = hold_court_8220_outcome
					value = 1
				}
				show_as_tooltip = {
					scope:bodyguard = {
						add_prestige = medium_prestige_gain
						add_hook = {
							target = root
							type = indebted_hook
						}
					}
				}
			}
			8 = { # Guard kills attacker
				desc = hold_court_8220_fumbled
				modifier = {
					factor = 2
					has_trait = shy
				}
				modifier = {
					factor = 2
					scope:assassin.prowess <= mediocre_skill_rating
				}
				modifier = {
					factor = 2
					scope:assassin.prowess < low_skill_rating
				}
				hidden_effect = {
					random_list = {
						1 = {
							trigger = {
								NOT = { exists = scope:bodyguard }
							}
							set_variable = {
								name = hold_court_8220_outcome
								value = 2
							}
						}
						1 = {
							set_variable = {
								name = hold_court_8220_outcome
								value = 3
							}
						}
					}
				}
				custom_tooltip = hold_court_8220_accosted_tt
			}
			7 = { # Another victim takes the heat
				trigger = {
					any_in_list = {
						list = other_victim_list
						count > 0
					}
				}
				desc = hold_court_8220_other_victim
				modifier = {
					factor = 2
					any_in_list = {
						list = other_victim_list
						OR = {
							has_relation_lover = root
							has_relation_friend = root
						}
					}
				}
				custom_tooltip = hold_court.8220.tt.other_victim
				set_variable = {
					name = hold_court_8220_outcome
					value = 7
				}
			}
			4 = { # You are wounded
				trigger = {
					NOT = {
						has_trait_rank = {
							trait = wounded
							rank = 3
						}
					}
				}
				desc = hold_court_8220_wounded
				modifier = {
					factor = 2
					scope:assassin.prowess > mediocre_skill_rating
				}
				modifier = {
					factor = 2
					scope:assassin.prowess >= high_skill_rating
				}
				modifier = {
					factor = 2
					scope:assassin.prowess >= extremely_high_skill_rating
				}
				set_variable = {
					name = hold_court_8220_outcome
					value = 4
				}
				show_as_tooltip = {
					increase_wounds_effect = { REASON = assassination }
				}
			}
			1 = { # You die
				desc = hold_court_8220_killed
				modifier = {
					factor = 3
					has_trait_rank = {
						trait = wounded
						rank = 3
					}
				}
				modifier = {
					factor = 3
					has_trait_rank = {
						trait = wounded
						rank = 3
					}
				}
				modifier = {
					factor = 2
					scope:assassin.prowess > mediocre_skill_rating
				}
				modifier = {
					factor = 2
					scope:assassin.prowess >= high_skill_rating
				}
				modifier = {
					factor = 2
					scope:assassin.prowess >= extremely_high_skill_rating
				}
				set_variable = {
					name = hold_court_8220_outcome
					value = 6
				}
				show_as_tooltip = {
					death = {
						killer = scope:assassin
						death_reason = death_assassination
					}
				}
			}
		}
		stress_impact = {
			trusting = medium_stress_impact_gain
			brave = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
   				ai_boldness = -2
   				ai_energy = 1
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = trusting
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = brave
			}
		}
	}

	option = { # Trust
		name = { # Trusts bodyguard
			trigger = { exists = scope:bodyguard }
			text = hold_court.8220.b.bodyguard
		}
		name = { # Trusts in something
			trigger = { has_trait = trusting }
			text = hold_court.8220.b.trusting
		}
		name = { # 
			trigger = { always = yes }
			text = hold_court.8220.b.fallback
		}
		if = {
			limit = {
				NOR = {
					primary_heir = scope:assassin
					any_targeting_scheme = {
						scheme_type = murder
						OR = {
							scheme_owner = root.primary_heir
							scheme_is_character_agent = root.primary_heir
						}
					}
				}
			}
			scope:assassin = { set_variable = assassin_caught }
		}
		flavor = hold_court.8220.b.flavor_trust
		random_list = {
			9 = { # Bodyguard stops attacker
				trigger = { exists = scope:bodyguard }
				desc = hold_court_8220_bodyguard
				modifier = {
					factor = 0
					var:hold_court_8220_outcome != 1
					any_targeting_scheme = {
						scheme_type = murder
						OR = {
							scheme_owner = scope:bodyguard
							scheme_is_character_agent = scope:bodyguard
						}
					}
				}
				modifier = {
					factor = 2
					scope:bodyguard.prowess > mediocre_skill_rating
				}
				modifier = {
					factor = 2
					scope:bodyguard.prowess >= high_skill_rating
				}
				modifier = {
					factor = 2
					scope:bodyguard.prowess >= extremely_high_skill_rating
				}
				set_variable = {
					name = hold_court_8220_outcome
					value = 1
				}
				show_as_tooltip = {
					scope:bodyguard = {
						add_prestige = medium_prestige_gain
						add_hook = {
							target = root
							type = indebted_hook
						}
					}
				}
			}
			6 = { # Guard kills attacker
				desc = hold_court_8220_fumbled
				modifier = {
					factor = 2
					has_trait = shy
				}
				modifier = {
					factor = 2
					scope:assassin.prowess <= mediocre_skill_rating
				}
				modifier = {
					factor = 2
					scope:assassin.prowess < low_skill_rating
				}
				hidden_effect = {
					random_list = {
						1 = {
							set_variable = {
								name = hold_court_8220_outcome
								value = 2
							}
						}
						1 = {
							set_variable = {
								name = hold_court_8220_outcome
								value = 3
							}
						}
					}
				}
				custom_tooltip = hold_court_8220_accosted_tt
			}
			5 = { # Another victim takes the heat
				trigger = {
					any_in_list = {
						list = other_victim_list
						count > 0
					}
				}
				desc = hold_court_8220_other_victim
				modifier = {
					factor = 2
					any_in_list = {
						list = other_victim_list
						OR = {
							has_relation_lover = root
							has_relation_friend = root
						}
					}
				}
				custom_tooltip = hold_court.8220.tt.other_victim
				set_variable = {
					name = hold_court_8220_outcome
					value = 7
				}
			}
			9 = { # You are wounded
				trigger = {
					NOT = {
						has_trait_rank = {
							trait = wounded
							rank = 3
						}
					}
				}
				desc = hold_court_8220_wounded
				modifier = {
					factor = 2
					scope:assassin.prowess > mediocre_skill_rating
				}
				modifier = {
					factor = 2
					scope:assassin.prowess >= high_skill_rating
				}
				modifier = {
					factor = 2
					scope:assassin.prowess >= extremely_high_skill_rating
				}
				set_variable = {
					name = hold_court_8220_outcome
					value = 4
				}
				show_as_tooltip = {
					increase_wounds_effect = { REASON = assassination }
				}
			}
			3 = { # You die
				desc = hold_court_8220_killed
				modifier = {
					factor = 3
					has_trait_rank = {
						trait = wounded
						rank = 3
					}
				}
				modifier = {
					factor = 3
					has_trait_rank = {
						trait = wounded
						rank = 3
					}
				}
				modifier = {
					factor = 2
					scope:assassin.prowess > mediocre_skill_rating
				}
				modifier = {
					factor = 2
					scope:assassin.prowess >= high_skill_rating
				}
				modifier = {
					factor = 2
					scope:assassin.prowess >= extremely_high_skill_rating
				}
				set_variable = {
					name = hold_court_8220_outcome
					value = 6
				}
				show_as_tooltip = {
					death = {
						killer = scope:assassin
						death_reason = death_assassination
					}
				}
			}
		}
		stress_impact = {
			craven = medium_stress_impact_gain
			brave = major_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 = craven
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = brave
			}
		}
	}

	option = { # Duel
		name = { # Blademaster
			trigger = { has_trait = lifestyle_blademaster }
			text = hold_court.8220.c.blademaster
		}
		name = { # Brave
			trigger = { has_trait = brave }
			text = hold_court.8220.c.brave
		}
		name = { # Fallback
			trigger = { always = yes }
			text = hold_court.8220.c.fallback
		}
		trigger = {
			prowess >= average_skill_rating
			NOR = {
				has_trait = incapable
				has_trait = infirm
			}
		}
		skill = prowess
		flavor = hold_court.8220.c.flavor_brave
		duel = {
			skill = prowess
			target = scope:assassin
			10 = {
				desc = hold_court_8220_duel_victory_tt
				compare_modifier = {
					value = scope:duel_value
					multiplier = 2
				}
				modifier = {
					factor = 2
					OR = {
						has_trait = viking
						#AGOT Disabled
						# has_trait = varangian
						has_trait = berserker
						has_trait = shieldmaiden
						has_trait = lifestyle_blademaster
					}
				}
				set_variable = {
					name = duel_outcome
					value = 1
				}
			}
			5 = {
				trigger = {
					NOT = {
						has_trait_rank = {
							trait = wounded
							rank = 3
						}
					}
				}
				desc = hold_court_8220_wounded
				compare_modifier = {
					value = scope:duel_value
					multiplier = 0.5
				}
				modifier = {
					factor = 2
					scope:assassin = {
						OR = {
							has_trait = viking
							#AGOT Disabled
							# has_trait = varangian
							has_trait = berserker
							has_trait = shieldmaiden
							has_trait = lifestyle_blademaster
						}
					}
				}
				show_as_tooltip = {
					increase_wounds_effect = { REASON = assassination }
				}
				set_variable = {
					name = duel_outcome
					value = 2
				}
			}
			5 = {
				desc = hold_court_8220_killed
				compare_modifier = {
					value = scope:duel_value
					multiplier = 0.5
				}
				modifier = {
					factor = 2
					has_trait = wounded
				}
				modifier = {
					factor = 2
					scope:assassin = {
						OR = {
							has_trait = viking
							#AGOT Disabled
							# has_trait = varangian
							has_trait = berserker
							has_trait = shieldmaiden
							has_trait = lifestyle_blademaster
						}
					}
				}
				show_as_tooltip = {
					death = {
						killer = scope:assassin
						death_reason = death_assassination
					}
				}
				set_variable = {
					name = duel_outcome
					value = 3
				}
			}
		}
		set_variable = {
			name = hold_court_8220_outcome
			value = 5
		}
		stress_impact = {
			craven = massive_stress_impact_gain
			trusting = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
   				ai_honor = 2
   				ai_energy = 2
   				ai_boldness = 2
			}
			modifier = {	#Weight down for stress.
				add = -60
				has_trait = craven
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = trusting
			}
		}
	}

	after = {
		scope:assassin = {
			clear_court_event_participation = yes
		}
		if = {
			limit = { exists = scope:bodyguard }
			scope:bodyguard = {
				clear_court_event_participation = yes
			}
		}
		trigger_event = hold_court.8221
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

scripted_trigger hold_court_8220_bodyguard_complicit_trigger = {
	var:hold_court_8220_outcome != 1
	any_targeting_scheme = {
		scheme_type = murder
		OR = {
			scheme_owner = scope:bodyguard
			scheme_is_character_agent = scope:bodyguard
		}
	}
}

scripted_effect add_murderer_trait_effect = {
	if = {
		limit = {
			is_close_or_extended_family_of = $SCOPE$
			NOT = { has_trait = kinslayer_1 }
		}
		add_trait = kinslayer_1
	}
	else_if = {
		limit = {
			NOT = { has_trait = murderer }
		}
		add_trait = murderer
	}
}

scripted_effect hold_court_8220_torture_effect = {
	add_opinion = {
		modifier = tortured_me
		target = root
	}
	add_character_flag = {
		flag = is_being_tortured
		months = 6 # Players in MP can keep the event window open...
	}
	if = {
		limit = { exists = scope:executioner }
		hidden_effect = {
			add_opinion = {
				modifier = tortured_me
				target = scope:executioner
			}
		}
	}
}

hold_court.8221 = {
	type = character_event
	title = hold_court.8220.t
	desc = {
		first_valid = { # Intro
			triggered_desc = { # Bodyguard gets assassin
				trigger = { var:hold_court_8220_outcome = 1 }
				desc = hold_court.8221.desc.bodyguard
			}
			triggered_desc = { # Guard gets assassin
				trigger = { var:hold_court_8220_outcome = 2 }
				desc = hold_court.8221.desc.guard
			}
			triggered_desc = { # Assassin fumbles
				trigger = { var:hold_court_8220_outcome = 3 }
				desc = hold_court.8221.desc.fumbled
			}
			triggered_desc = { # Wounded
				trigger = { var:hold_court_8220_outcome = 4 }
				desc = hold_court.8221.desc.wounded
			}
			triggered_desc = { # Duel
				trigger = { var:hold_court_8220_outcome = 5 }
				desc = hold_court.8221.desc.duel
			}
			triggered_desc = { # Died
				trigger = { var:hold_court_8220_outcome = 6 }
				desc = hold_court.8221.desc.died
			}
			desc = hold_court.8221.desc.other
		}
		first_valid = { # Assassin
			# Bodyguard
			triggered_desc = { # Assassin killed by bodyguard with them
				trigger = {
					var:hold_court_8220_outcome = 1
					scope:assassin = { is_alive = no }
					scope:bodyguard = { is_alive = no }
				}
				desc = hold_court.8221.desc.assassin_died_with_bodyguard
			}
			triggered_desc = { # Assassin killed by bodyguard
				trigger = {
					var:hold_court_8220_outcome = 1
					scope:assassin = { is_alive = no }
				}
				desc = hold_court.8221.desc.assassin_died_bodyguard
			}
			triggered_desc = { # Assassin kills bodyguard
				trigger = {
					var:hold_court_8220_outcome = 1
				}
				desc = hold_court.8221.desc.assassin_kills_bodyguard
			}
			# Guard
			triggered_desc = { # Assassin killed by guards
				trigger = {
					scope:assassin = { is_alive = no }
					var:hold_court_8220_outcome = 2
				}
				desc = hold_court.8221.desc.assassin_died_guards
			}
			# Fumble
			triggered_desc = { # Assassin fumbled and killed by guards
				trigger = {
					scope:assassin = { is_alive = no }
					var:hold_court_8220_outcome = 3
				}
				desc = hold_court.8221.desc.assassin_died_fumbled
			}
			# Duel outcomes
			triggered_desc = { # Assassin dies
				trigger = {
					var:hold_court_8220_outcome = 5
					var:duel_outcome = 1
					scope:assassin = { is_alive = no }
				}
				desc = hold_court.8221.desc.assassin_duel_killed
			}
			triggered_desc = { # Assassin disarmed by me
				trigger = {
					var:hold_court_8220_outcome = 5
					var:duel_outcome = 1
				}
				desc = hold_court.8221.desc.assassin_duel_disarmed
			}
			triggered_desc = { # Assassin dies and wounds me
				trigger = {
					var:hold_court_8220_outcome = 5
					var:duel_outcome = 2
					scope:assassin = { is_alive = no }
				}
				desc = hold_court.8221.desc.assassin_duel_killed_wounded
			}
			triggered_desc = { # Assassin wounded by me and wounds me
				trigger = {
					var:hold_court_8220_outcome = 5
					var:duel_outcome = 2
					scope:assassin = { has_trait = wounded }
				}
				desc = hold_court.8221.desc.assassin_duel_wounded_wounded
			}
			triggered_desc = { # Assassin disarmed by me and wounds me
				trigger = {
					var:hold_court_8220_outcome = 5
					var:duel_outcome = 2
				}
				desc = hold_court.8221.desc.assassin_duel_disarmed_wounded
			}
			triggered_desc = { # Assassin kills me and dies
				trigger = {
					var:hold_court_8220_outcome = 5
					var:duel_outcome = 3
					scope:assassin = { is_alive = no }
				}
				desc = hold_court.8221.desc.assassin_duel_killed_killed
			}
			triggered_desc = { # Assassin wounded and kills me
				trigger = {
					var:hold_court_8220_outcome = 5
					var:duel_outcome = 3
					scope:assassin = { has_trait = wounded }
				}
				desc = hold_court.8221.desc.assassin_duel_wounded_killed
			}
			# Die
			triggered_desc = { # Assassin killed by guard with me
				trigger = {
					scope:assassin = { is_alive = no }
					var:hold_court_8220_outcome = 6
				}
				desc = hold_court.8221.desc.assassin_killed_killed
			}
			triggered_desc = { # Assassin is pardoned
				trigger = {
					var:hold_court_8220_outcome = 6
					any_targeting_scheme = {
						scheme_type = murder
						OR = {
							scheme_owner = root.primary_heir
							scheme_is_character_agent = root.primary_heir
						}
					}
				}
				desc = hold_court.8221.desc.assassin_pardoned_accomplice
			}
			triggered_desc = { # Assassin is pardoned
				trigger = {
					var:hold_court_8220_outcome = 6
					primary_heir = scope:assassin
				}
				desc = hold_court.8221.desc.assassin_pardoned_heir
			}
			triggered_desc = { # Assassin is accosted after killing me
				trigger = { var:hold_court_8220_outcome = 6 }
				desc = hold_court.8221.desc.assassin_accosted_killed
			}
			# Other victim
			triggered_desc = { # Other victim wound child
				trigger = {
					var:hold_court_8220_outcome = 7
					scope:other_victim = {
						is_alive = yes
						is_adult = no
					}
				}
				desc = hold_court.8221.desc.assassin_other_wounded_child
			}
			triggered_desc = { # Other victim wound
				trigger = {
					var:hold_court_8220_outcome = 7
					scope:other_victim = { is_alive = yes }
				}
				desc = hold_court.8221.desc.assassin_other_wounded
			}
			triggered_desc = { # Other victim dies child
				trigger = {
					var:hold_court_8220_outcome = 7
					scope:other_victim = {
						is_alive = no
						is_adult = no
					}
				}
				desc = hold_court.8221.desc.assassin_other_killed_child
			}
			triggered_desc = { # Other victim dies
				trigger = { var:hold_court_8220_outcome = 7 }
				desc = hold_court.8221.desc.assassin_other_killed
			}
			# Fallback
			triggered_desc = { # Assassin killed by guard
				trigger = {
					scope:assassin = { is_alive = no }
				}
				desc = hold_court.8221.desc.assassin_fumbled
			}
			desc = hold_court.8221.desc.assassin_accosted
		}
		first_valid = { # Bodyguard
			triggered_desc = { # Bodyguard didn't help but you survived
				trigger = {
					exists = scope:bodyguard
					var:hold_court_8220_outcome != 6
					hold_court_8220_bodyguard_complicit_trigger = yes
				}
				desc = hold_court.8221.desc.bodyguard_complicit_survived
			}
			triggered_desc = { # Bodyguard didn't help and you died
				trigger = {
					exists = scope:bodyguard
					var:hold_court_8220_outcome = 6
					hold_court_8220_bodyguard_complicit_trigger = yes
				}
				desc = hold_court.8221.desc.bodyguard_complicit_death
			}
			triggered_desc = { # Bodyguard helps but you still die
				trigger = {
					exists = scope:bodyguard
					var:hold_court_8220_outcome = 6
					hold_court_8220_bodyguard_complicit_trigger = no
				}
				desc = hold_court.8221.desc.bodyguard_fails
			}
			triggered_desc = { # Bodyguard saves you but dies
				trigger = {
					var:hold_court_8220_outcome = 1
					scope:bodyguard = { is_alive = no }
				}
				desc = hold_court.8221.desc.bodyguard_saves_died
			}
			triggered_desc = { # Bodyguard saves you but is wounded
				trigger = {
					var:hold_court_8220_outcome = 1
					scope:bodyguard = { has_trait = wounded }
				}
				desc = hold_court.8221.desc.bodyguard_saves_wound
			}
			triggered_desc = { # Bodyguard saves you
				trigger = {	var:hold_court_8220_outcome = 1 }
				desc = hold_court.8221.desc.bodyguard_saves
			}
			triggered_desc = { # No bodyguard but died
				trigger = {
					NOT = { exists = scope:bodyguard }
					OR = {
						var:hold_court_8220_outcome = 6
						trigger_if = {
							limit = { has_variable = duel_outcome }
						 	var:duel_outcome = 3
						}
					}
				}
				desc = hold_court.8221.desc.no_bodyguard_died
			}
			triggered_desc = { # No bodyguard but wounded
				trigger = {
					NOT = { exists = scope:bodyguard }
					var:hold_court_8220_outcome = 4
				}
				desc = hold_court.8221.desc.no_bodyguard_wounded
			}
			triggered_desc = { # Bodyguard saves you
				trigger = {	exists = scope:bodyguard }
				desc = hold_court.8221.desc.bodyguard_useless
			}
			triggered_desc = { # No bodyguard and other exists
				trigger = { var:hold_court_8220_outcome = 7 }
				desc = hold_court.8221.desc.no_bodyguard_other
			}
			triggered_desc = { # No bodyguard but survived
				trigger = {
					NOT = { exists = scope:bodyguard }
					var:hold_court_8220_outcome != 6
					trigger_if = {
						limit = { has_variable = duel_outcome }
						NOT = { var:duel_outcome = 3 }
					}
				}
				desc = hold_court.8221.desc.no_bodyguard_survived
			}
		}
	}
	theme = court
	override_background = { reference = throne_room }
	left_portrait = {
		character = scope:left_portrait
		# Other Vassal
		triggered_animation = {
			trigger = {
				has_variable = hold_court_8220_outcome
				var:hold_court_8220_outcome = 7
			}
			animation = anger
		}
		# Bodyguard
		triggered_animation = {
			trigger = {
				has_variable = hold_court_8220_outcome
				var:hold_court_8220_outcome = 1
			}
			animation = aggressive_dagger
		}
		triggered_animation = {
			trigger = {
				has_variable = hold_court_8220_outcome
				var:hold_court_8220_outcome != 6
				exists = scope:bodyguard
				hold_court_8220_bodyguard_complicit_trigger = yes
			}
			animation = fear
		}
		triggered_animation = {
			trigger = {
				has_variable = hold_court_8220_outcome
				var:hold_court_8220_outcome != 6
			}
			animation = throne_room_one_handed_passive_1
		}
		triggered_animation = {
			trigger = {
				has_variable = hold_court_8220_outcome
				var:hold_court_8220_outcome = 6
				exists = scope:bodyguard
				hold_court_8220_bodyguard_complicit_trigger = yes
			}
			animation = throne_room_one_handed_passive_1
		}
		triggered_animation = {
			trigger = {
				has_variable = hold_court_8220_outcome
				var:hold_court_8220_outcome = 6
			}
			animation = sadness
		}
	}
	right_portrait = {
		character = scope:assassin
		animation = rage
	}
	lower_center_portrait = {
		character = scope:guard
		trigger = { exists = scope:guard }
	}
	lower_right_portrait = {
		character = scope:bodyguard
		animation = disbelief
		trigger = { exists = scope:other_victim }
	}

	immediate = {
		primary_heir = { save_scope_as = successor }
		scope:assassin = { # Does the assassin die?
			random_list = {
				2 = {
					trigger = { root.var:hold_court_8220_outcome = 1 }
					death = {
						death_reason = death_beaten
						killer = scope:bodyguard
					}
				}
				2 = {
					trigger = {
						NOR = {
							root.var:hold_court_8220_outcome = 1
							root.var:hold_court_8220_outcome = 5
						}
					}
					death = { death_reason = death_while_assassinating }
				}
				2 = {
					modifier = {
						factor = 0.5
						has_trait = craven
					}
					modifier = {
						factor = 0.75
						prowess > mediocre_skill_rating
					}
					modifier = {
						factor = 0.75
						prowess >= high_skill_rating
					}
					modifier = {
						factor = 0.75
						prowess >= extremely_high_skill_rating
					}
				}
			}
		}
		if = { # Does the bodyguard die?
			limit = { var:hold_court_8220_outcome = 1 }
			scope:bodyguard = {
				random_list = {
					2 = {
						modifier = {
							factor = 2
							prowess < scope:assassin.prowess
						}
						modifier = {
							factor = 2
							prowess < low_skill_rating
						}
						death = {
							death_reason = death_assassination
							killer = scope:assassin
						}
						scope:assassin = {
							add_murderer_trait_effect = { SCOPE = scope:bodyguard }
						}
					}
					2 = {
						modifier = {
							factor = 2
							prowess >= low_skill_rating
						}
						modifier = {
							factor = 2
							prowess <= high_skill_rating
						}
						increase_wounds_effect = { REASON = assassination }
					}
					2 = {
						modifier = {
							factor = 2
							prowess > scope:assassin.prowess
						}
						modifier = {
							factor = 2
							prowess >= high_skill_rating
						}
					}
				}
			}
		}
		if = { # Duel outcome
			limit = { has_variable = duel_outcome }
			random_list = {
				1 = {
					scope:assassin = {
						death = {
							death_reason = death_duel
							killer = root
						}
					}
					modifier = {
						factor = 2
						OR = {
							has_trait = callous
							has_trait = vengeful
							has_trait = brave
						}
					}
				}
				1 = {
					scope:assassin = {
						increase_wounds_effect = { REASON = duel }
					}
					modifier = {
						factor = 5
						scope:assassin = { is_close_family_of = root }
					}
				}
				1 = {
					modifier = {
						factor = 2
						OR = {
							has_trait = compassionate
							has_trait = forgiving
						}
					}
					modifier = {
						factor = 10
						scope:assassin = { is_close_family_of = root }
					}
				}
			}
		}	
		if = { # Select other victim 
			limit = { var:hold_court_8220_outcome = 7 }
			random_in_list = {
				list = other_victim_list
				weight = {
					base = 1
					modifier = {
						factor = 2
						OR = {
							has_relation_lover = root
							has_relation_friend = root
							has_trait = brave
						}
					}
				}
				save_scope_as = other_victim
				save_scope_as = left_portrait
			}
			scope:other_victim = {
				random_list = {
					2 = {
						death = {
							death_reason = death_assassination
							killer = scope:assassin
						}
						scope:assassin = {
							if = {
								limit = { is_close_or_extended_family_of = scope:other_victim }
								add_trait = kinslayer_1
							}
							else = { add_trait = murderer }
						}
					}
					2 = {
						increase_wounds_effect = { REASON = assassination }
					}
				}
			}
		}
		else = {
			if = {
				limit = { exists = scope:bodyguard }
				scope:bodyguard = { save_scope_as = left_portrait }
			}
		}
		if = {
			limit = {
				var:hold_court_8220_outcome = 1
				scope:bodyguard = { is_alive = yes }
			}
			scope:bodyguard = {
				add_prestige = medium_prestige_gain
				if = {
					limit = {
						can_add_hook = {
							target = root
							type = indebted_hook
						}
					}
					add_hook = {
						target = root
						type = indebted_hook
					}
				}
			}
		}
		if = {
			limit = {
				OR = {
					var:hold_court_8220_outcome = 2
					var:hold_court_8220_outcome = 4
					AND = {
						var:hold_court_8220_outcome = 3
						scope:assassin = { is_alive = no }
					}
				}
			}
			hidden_effect = {
				create_character = {
					template = new_warrior_character
					faith = root.faith
					culture = root.culture
					dynasty = none
					location = root.capital_province
					gender_female_chance = root_soldier_female_chance
					save_scope_as = guard
				}
			}
		}
		if = {
			limit = { var:hold_court_8220_outcome = 4 }
			increase_wounds_effect = { REASON = assassination }
		}
	}

	option = { # Kill them
		name = {
			trigger = {
				exists = scope:bodyguard
				hold_court_8220_bodyguard_complicit_trigger = yes
			}
			text = hold_court.8221.a.bodyguard
		}
		name = {
			trigger = { always = yes }
			text = hold_court.8221.a.alone
		}
		trigger = {
			AND = {
				has_variable = hold_court_8220_outcome
				var:hold_court_8220_outcome != 6
			}
			scope:assassin = { is_alive = yes }
			trigger_if = {
				limit = { has_variable = duel_outcome }
				NOT = { var:duel_outcome = 3 }
			}
		}
		if = {
			limit = {
				exists = scope:bodyguard
				hold_court_8220_bodyguard_complicit_trigger = yes
			}
			send_interface_toast = {
				title = hold_court.8221.execute_bodyguard
				left_icon = scope:assassin
				right_icon = scope:bodyguard
				scope:assassin = {
					death = {
						death_reason = death_execution
						killer = root
					}
				}
				scope:bodyguard = {
					death = {
						death_reason = death_execution
						killer = root
					}
				}
			}
			
		}
		else = {
			send_interface_toast = {
				title = hold_court.8221.execute_alone
				left_icon = scope:assassin
				scope:assassin = {
					death = {
						death_reason = death_execution
						killer = root
					}
				}
			}
		}
	 	custom_tooltip = hold_court.8221.end_hold_court
	 	stress_impact = {
			forgiving = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = -2
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = forgiving
			}
		}
	}

	option = { # Imprison them
		name = {
			trigger = {
				exists = scope:bodyguard
				hold_court_8220_bodyguard_complicit_trigger = yes
			}
			text = hold_court.8221.b.bodyguard
		}
		name = {
			trigger = { always = yes }
			text = hold_court.8221.b.alone
		}
		trigger = {
			var:hold_court_8220_outcome != 6
			scope:assassin = { is_alive = yes }
			trigger_if = {
				limit = { has_variable = duel_outcome }
				NOT = { var:duel_outcome = 3 }
			}
		}
		if = {
			limit = {
				exists = scope:bodyguard
				scope:bodyguard = { is_alive = yes }
				hold_court_8220_bodyguard_complicit_trigger = yes
			}
			send_interface_toast = {
				title = hold_court.8221.imprison_bodyguard
				left_icon = scope:assassin
				right_icon = scope:bodyguard
				imprison = {
					target = scope:assassin
					type = dungeon
				}
				imprison = {
					target = scope:bodyguard
					type = dungeon
				}
			}
		}
		else = {
			send_interface_toast = {
				title = hold_court.8221.imprison_alone
				left_icon = scope:assassin
				imprison = {
					target = scope:assassin
					type = dungeon
				}
			}
		}
		custom_tooltip = hold_court.8221.end_hold_court
		stress_impact = {
			vengeful = medium_stress_impact_gain
			wrathful = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = -1
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = vengeful
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = wrathful
			}
		}
	}

	option = { # Torture them
		name = hold_court.8221.c
		trigger = {
			AND = {
				has_variable = hold_court_8220_outcome
				var:hold_court_8220_outcome != 6
			}
			scope:assassin = { is_alive = yes }
			OR = {
				has_trait = torturer
				any_court_position_holder = {
					type = executioner_court_position
					NOT = { this = scope:assassin }
				}
			}
			trigger_if = {
				limit = { has_variable = duel_outcome }
				NOT = { var:duel_outcome = 3 }
			}
		}
		trait = torturer
		add_dread = minor_dread_gain
		if = {
			limit = {
				any_court_position_holder = {
					type = executioner_court_position
					NOT = { this = scope:assassin }
				}
			}
			random_court_position_holder = {
				type = executioner_court_position
				limit = {
					NOT = { this = scope:assassin }
				}
				save_scope_as = executioner
			}
		}
		imprison = {
			target = scope:assassin
			type = dungeon
		}
		if = {
			limit = {
				exists = scope:bodyguard
				scope:bodyguard = { is_alive = yes }
				hold_court_8220_bodyguard_complicit_trigger = yes
			}
			imprison = {
				target = scope:assassin
				type = dungeon
			}
		}
		if = {
			limit = {
				NOT = { has_trait = torturer }
			}
			custom_tooltip = hold_court.8221.tt.executioner
		}
		else = { custom_tooltip = hold_court.8221.tt.torturer }
		hidden_effect = {
			scope:murder_scheme = {
				random_list = {
				 	2 =  {
				 		trigger = {
				 			any_scheme_agent = {
								NOT = { is_agent_exposed_in_scheme = prev }
							}
						}
						random_scheme_agent = {
							limit = {
								NOT = { is_agent_exposed_in_scheme = prev }
							}
							save_scope_as = exposed_agent
						}
						root = {
							send_interface_toast = {
								title = hold_court.8221.torture_success
								left_icon = scope:assassin
								right_icon = scope:exposed_agent
								scope:murder_scheme = { expose_scheme_agent = scope:exposed_agent }
								scope:assassin = { hold_court_8220_torture_effect = yes }
							}
						}	 	
					}
					2 = {
						root = {
							send_interface_toast = {
								title = hold_court.8221.torture_failure
								left_icon = scope:assassin
								scope:assassin = { hold_court_8220_torture_effect = yes }
							}
						}
					}
				}
			}
		}
		custom_tooltip = hold_court.8221.end_hold_court
		stress_impact = {
			compassionate = major_stress_impact_gain
			just = medium_stress_impact_gain
			forgiving = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = -3
			}
			modifier = {	#Weight down for stress.
				add = -30
				has_trait = compassionate
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = just
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = forgiving
			}
		}
	}

	option = { # RIP them
		name = hold_court.8221.d
		trigger = {
			AND = {
				has_variable = hold_court_8220_outcome
				var:hold_court_8220_outcome != 6
			}
			scope:assassin = { is_alive = no }
		}
		custom_tooltip = hold_court.8221.end_hold_court
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = -1
			}
		}
	}

	option = { # RIP me
		name = hold_court.8221.e
		trigger = {
			OR = {
				AND = {
					has_variable = hold_court_8220_outcome
					var:hold_court_8220_outcome = 6
				}
				trigger_if = {
					limit = { has_variable = duel_outcome }
					var:duel_outcome = 3
				}
			}
		}
		scope:assassin = {
			if = {
				limit = { is_close_or_extended_family_of = root }
				add_trait = kinslayer_1
			}
			else = { add_trait = murderer }
		}
		death = {
			death_reason = death_assassination
			killer = scope:assassin
		}
		scope:assassin = {
			trigger_event = {
				id = hold_court.8222
				days = 5
			}
		}
	}

	option = { # Promote guard
		name = hold_court.8221.f
		trigger = { exists = scope:guard }
		add_prestige = minor_prestige_loss
		hidden_effect = {
			scope:guard = { set_employer = root }
		}
		send_interface_toast = {
			title = hold_court.8221.guard
			left_icon = scope:guard
			if = {
				limit = { exists = scope:bodyguard }
				replace_court_position = {
					recipient = scope:guard
					holder = scope:bodyguard
					court_position = bodyguard_court_position
				}
			}
			else = {
				if = { 
					limit = {
						can_appoint_char_to_court_position = {
							CHAR = scope:guard 
							COURT_POS = bodyguard_court_position
						}
					}
					appoint_court_position = {
						recipient = scope:guard
						court_position = bodyguard_court_position
					}
				}
			}
		}
		if = {
			limit = {
				scope:assassin = { is_alive = yes }
			}
			imprison = {
				target = scope:assassin
				type = dungeon
			}
		}
		if = {
			limit = { exists = scope:bodyguard }
			scope:bodyguard = {
				if = {
					limit = {
						is_alive = yes
						root = { hold_court_8220_bodyguard_complicit_trigger = yes }
					}
					root = {
						imprison = {
							target = scope:bodyguard
							type = dungeon
						}
					}
				}
				else = {
					add_opinion = {
						target = root
						modifier = disappointed_opinion
						opinion = -10
					}
				}
			}	
		}
		custom_tooltip = hold_court.8221.end_hold_court
		stress_impact = {
			arrogant = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 1
			}
			modifier = {	#Weight down for stress.
				add = -15
				has_trait = arrogant
			}
		}
	}

	after = {
		change_current_court_grandeur = medium_court_grandeur_loss
		if = {
			limit = {
				exists = scope:bodyguard
				NOT = { var:hold_court_8220_outcome = 6 }
				hold_court_8220_bodyguard_complicit_trigger = yes
			}
			scope:bodyguard = { add_prestige = medium_prestige_loss }
		}
		if = {
			limit = { is_alive = yes }
			remove_variable = hold_court_8220_outcome
			if = {
				limit = { has_variable = duel_outcome }
				remove_variable = duel_outcome
			}
		}
		if = {
			limit = {
				exists = scope:guard
				scope:guard = {
					NOT = { has_court_position = bodyguard_court_position }
				}
			}
			scope:guard = { silent_disappearance_effect = yes }
		}
		remove_variable = num_petitioners
	}
}

hold_court.8222 = {
	type = character_event
	hidden = yes

	immediate = {
		if = {
			limit = { has_variable = assassin_caught }
			remove_variable = assassin_caught
			scope:successor = {
				random_list = {
					10 = {
						send_interface_toast = {
							title = hold_court.8222.killed
							scope:assassin = {
								death = {
									death_reason = death_while_assassinating
									killer = scope:victim
								}
							}
						}
					}
					10 = {						
						send_interface_toast = {
							title = hold_court.8222.imprison
							rightfully_imprison_character_effect = {
								TARGET = scope:accused
								IMPRISONER = scope:accused.employer
							}
						}
					}
				}
			}
		}
		else = {
			send_interface_toast = {
				title = hold_court.8222.success
				custom_tooltip = hold_court.8222.success
			}
		}
	}
}

##################################################
# Thy Neighbor's Wife
# by Joe Parkin
# 8240
##################################################

scripted_trigger accepted_female_attraction_trigger = { # Legitimate female attraction?
	OR = {
		AND = {
			hold_court_8240_homosexuality_accepted_trigger = yes
			is_female = yes
			attracted_to_same_gender_trigger = yes
		}
		AND = {
			is_male = yes
			attracted_to_opposite_gender_trigger = yes
		}
	}
}

scripted_trigger accepted_male_attraction_trigger = { # Legitimate male attraction?
	OR = {
		AND = {
			hold_court_8240_homosexuality_accepted_trigger = yes
			is_male = yes
			attracted_to_same_gender_trigger = yes
		}
		AND = {
			is_female = yes
			attracted_to_opposite_gender_trigger = yes
		}
	}
}

scripted_trigger hold_court_8240_homosexuality_accepted_trigger = { # Is homosexuality accepted?
	faith = { has_doctrine = doctrine_homosexuality_accepted }
	root.faith = { has_doctrine = doctrine_homosexuality_accepted }
}

scripted_trigger hold_court_8240_polygamous_trigger = { # Is character able to have more spouses?
	has_court_event_flag = no
	is_available_ai_adult = yes
	OR = {
		is_married = no
		polygamy_accepted_trigger = yes
	}
	allowed_more_spouses = yes
}

scripted_trigger seeking_love_trigger = { # Is character looking for love?
	NOR = {
		has_trait = chaste
		has_trait = shy
		has_trait = craven
		has_trait = content
	}
}

scripted_trigger hold_court_8240_attraction_list_trigger = { # is not chaste, accepts polygamy, and is legally attracted to relevant gender? 
	has_court_event_flag = no
	is_available_ai_adult = yes
	seeking_love_trigger = yes
	accepted_$LIST$_attraction_trigger = yes
	hold_court_8240_polygamous_trigger = yes
}

scripted_effect hold_court_attraction_list_effect = { # Find characters who like women/men
	if = { 
		limit = {
			any_vassal_or_below = {
				count > 1
				hold_court_$ID$_attraction_list_trigger = { LIST = $LIST$ }
			}
		}
		every_vassal_or_below = {
			limit = {
				hold_court_$ID$_attraction_list_trigger = { LIST = $LIST$ }
			}
			add_to_list = $LIST$_attraction_list
		}
	}
}

scripted_effect hold_court_attraction_dummy_effect = { # Save random character and attracted vassals
	random_in_list = {
		list = $LIST$_attraction_list
		save_scope_as = vassal_1
		court_event_character_flag_effect = yes
	}
	random_in_list = {
		list = $LIST$_attraction_list
		limit = { NOT = { this = scope:vassal_1 } }
		weight = {
			base = 1
			modifier = {
				factor = 0.5
				is_close_family_of = scope:vassal_1
			} 
		}
		save_scope_as = vassal_2
		court_event_character_flag_effect = yes
	}
	dummy_$LIST$ = { save_scope_as = dummy_yearn_gender }
}

scripted_effect hold_court_attraction_dummy_gender_effect = { # Determine random character's gender
	random_list = { # Pick gender
		2 = { # Female
			trigger = { 
				any_in_list = {
					list = female_attraction_list
					count > 1
				}
			}
			hold_court_attraction_dummy_effect = { LIST = female }
		}
		2 = { # Male
			trigger = { 
				any_in_list = {
					list = male_attraction_list
					count > 1
				}
			}
			hold_court_attraction_dummy_effect = { LIST = male }
		}
	}
}

scripted_trigger polygamy_accepted_trigger = { # Is polygamy accepted?
	OR = {
		culture = { has_cultural_tradition = tradition_polygamous }
		faith = { has_doctrine = doctrine_polygamy }
	}
}

scripted_trigger hold_court_8240_covetable_spouse_trigger = { # Is polygamous and has an adult non-primary spouse?
	has_court_event_flag = no
	is_available_ai_adult = yes
	polygamy_accepted_trigger = yes
	save_temporary_scope_as = vassal_victim_temp
	any_spouse = {
		is_available_ai_adult = yes
		NOT = { this = scope:vassal_victim_temp.primary_spouse }
	}
}

scripted_trigger hold_court_8240_spouse_coveter_trigger = { # is polygamous + not already married to yearn_target + and legally attracted to them
	hold_court_8240_polygamous_trigger = yes
	is_attracted_to_gender_of = $SPOUSE$
	NOR = {
		is_spouse_of = $SPOUSE$
		has_relation_rival = $SPOUSE$
	}
	trigger_if = {
		limit = {
			$SPOUSE$ = { is_female = yes }
		}
		accepted_female_attraction_trigger = yes
	}
	trigger_else = { accepted_male_attraction_trigger = yes }
}

scripted_trigger hold_court_8240_possible_yearn_target_trigger = {
	is_available_ai_adult = yes
	NOT = { this = primary_spouse.primary_spouse }
	save_temporary_scope_as = yearn_target_temp
	root = {
		OR = {
			any_vassal_or_below = {
				hold_court_8240_spouse_coveter_trigger = { SPOUSE = scope:yearn_target_temp }
			}
			any_courtier = {
				hold_court_8240_spouse_coveter_trigger = { SPOUSE = scope:yearn_target_temp }
			}
		}
	}
}

# Vassal covets another's non-primary spouse
hold_court.8240 = {
	type = court_event
	title = hold_court.8240.t
	desc = hold_court.8240.desc
	theme = court
	override_background = { reference = throne_room }
	cooldown = { years = 10 }
	lower_right_portrait = scope:yearn_target

	court_scene = {
		button_position_character = scope:vassal_jealous
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:vassal_jealous = {
				group = petitioners_group
				animation = beg
			}
			scope:vassal_victim = {
				group = petitioners_group
				animation = anger
			}
		}
	}

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

	trigger = {
		has_royal_court = yes
		polygamy_accepted_trigger = yes # culture or religion allows polygamy
		NOT = {
			faith = { has_doctrine = doctrine_divorce_disallowed } # divorce accepted
		}
		trigger_if = {
			limit = {
				faith = { has_doctrine = doctrine_divorce_approval }
			}
			faith.religious_head = root # if divorce needs HoF approval, you are the HoF (e.g. Caliph)
		}
		OR = { # a vassal or courtier who accepts polygamy has an adult non-primary_spouse
			any_vassal_or_below = {
				hold_court_8240_covetable_spouse_trigger = yes
				any_spouse = { hold_court_8240_possible_yearn_target_trigger = yes }
			}
			any_courtier = {
				hold_court_8240_covetable_spouse_trigger = yes
				any_spouse = { hold_court_8240_possible_yearn_target_trigger = yes }
			}
		}
	}

	weight_multiplier = {
		base = 1

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

	immediate = {
		if = {
			limit = {
				any_vassal_or_below = {
					hold_court_8240_covetable_spouse_trigger = yes
					any_spouse = { hold_court_8240_possible_yearn_target_trigger = yes }
				}
			}
			random_vassal_or_below = { 
				limit = {
					hold_court_8240_covetable_spouse_trigger = yes
					any_spouse = { hold_court_8240_possible_yearn_target_trigger = yes }
				}
				court_event_character_flag_effect = yes
				save_scope_as = vassal_victim
				ordered_spouse = {
					limit = { hold_court_8240_possible_yearn_target_trigger = yes }
					order_by = attraction
					court_event_character_flag_effect = yes
					save_scope_as = yearn_target
				}
			}
		}
		else = {
			random_courtier = { 
				limit = {
					hold_court_8240_covetable_spouse_trigger = yes
					any_spouse = { hold_court_8240_possible_yearn_target_trigger = yes }
				}
				court_event_character_flag_effect = yes
				save_scope_as = vassal_victim
				ordered_spouse = {
					limit = { hold_court_8240_possible_yearn_target_trigger = yes }
					order_by = attraction
					court_event_character_flag_effect = yes
					save_scope_as = yearn_target
				}
			}
		}
		every_vassal_or_below = { 
			limit = {
				hold_court_8240_spouse_coveter_trigger = { SPOUSE = scope:yearn_target }
			}
			add_to_list = jealous_list
		}
		every_courtier = { 
			limit = {
				hold_court_8240_spouse_coveter_trigger = { SPOUSE = scope:yearn_target }
			}
			add_to_list = jealous_list
		}
		# save a vassal/courtier as the coveter, favoring existing lovers
		random_in_list = {
			list = jealous_list
			limit = { has_relation_soulmate = scope:yearn_target }
			alternative_limit = { has_relation_lover = scope:yearn_target }
			alternative_limit = { always = yes }
			weight = {
				base = 1
				modifier = {
					factor = 4
					has_trait = lustful
				}
				modifier = {
					factor = 4
					has_trait = greedy
				}
			}
			save_scope_as = vassal_jealous
			court_event_character_flag_effect = yes
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = { # Side with victim vassal
		name = hold_court.8240.a
		scope:vassal_victim = {
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 10
			}
		}
		scope:vassal_jealous = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -10
			}
			scope:yearn_target = { save_scope_as = relationship_reason_involved_character }
			progress_towards_rival_effect = {
				CHARACTER = scope:vassal_victim
				REASON = rival_love_triangle
				OPINION = 0
			}
			clear_saved_scope = relationship_reason_involved_character
			hidden_effect = {
				if = {
					limit = {
						can_start_scheme = {
							type = seduce
							target = scope:yearn_target
						}
					}
					random = {
						chance = 50
						start_scheme = {
							type = seduce
							target = scope:yearn_target
						}
					}
				}
			}
		}
	}

	option = { # Side with jealous vassal
		name = hold_court.8240.b
		scope:vassal_victim = { divorce = scope:yearn_target }
		hidden_effect = {
			scope:yearn_target = {
				if = {
					limit = { 
						scope:vassal_jealous = { 
							is_landed = yes 
						} 
					}
					set_employer = scope:vassal_jealous
				}
				else = {
					if = {
						limit = { exists = scope:vassal_jealous.liege }
						save_scope_as = vassal_jealous_liege
					}
					set_employer = scope:vassal_jealous_liege
				}
			}
		}
		scope:vassal_jealous = {
			if = {
				limit = { is_female = yes }
				marry_matrilineal = scope:yearn_target
			}
			else = { marry = scope:yearn_target }
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 20
			}
		}
		scope:yearn_target = {
			if = {
				limit = {
					NOR = {
						has_relation_rival = scope:vassal_victim
						has_relation_lover = scope:vassal_jealous
						has_relation_soulmate = scope:vassal_jealous
					}
				}
				add_opinion = {
					target = root
					modifier = angry_opinion
					opinion = -20
				}
			}
			else = {
				add_opinion = {
					target = root
					modifier = pleased_opinion
					opinion = 10
				}
			}
		}
		scope:vassal_victim = {
			add_opinion = {
				target = root
				modifier = angry_opinion
				opinion = -20
			}
			scope:yearn_target = { save_scope_as = relationship_reason_involved_character }
			progress_towards_rival_effect = {
				CHARACTER = scope:vassal_jealous
				REASON = rival_love_triangle_allowed
				OPINION = 0
			}
			clear_saved_scope = relationship_reason_involved_character
		}
	}

	option = { # Take spouse
		name = hold_court.8240.c
		trigger = {
			allowed_more_spouses = yes
			trigger_if = {
				limit = {
					scope:yearn_target = { is_male = yes }
				}
				accepted_male_attraction_trigger = yes
			}
			trigger_else = { accepted_female_attraction_trigger = yes }
		}
		scope:vassal_victim = { divorce = scope:yearn_target }
		hidden_effect = {
			scope:yearn_target = { set_employer = root }
		}
		if = {
			limit = { is_female = yes }
			marry_matrilineal = scope:yearn_target
		}
		else = { marry = scope:yearn_target }
		scope:yearn_target = {
			if = {
				limit = {
					NOR = {
						has_relation_rival = scope:vassal_victim
						has_relation_lover = root
					}
				}
				add_opinion = {
					target = root
					modifier = angry_opinion
					opinion = -20
				}
			}
		}
		scope:vassal_victim = { 
			add_opinion = {
				target = root
				modifier = angry_opinion
				opinion = -20
			}
			scope:yearn_target = { save_scope_as = relationship_reason_involved_character }
			progress_towards_rival_effect = {
				CHARACTER = root
				REASON = rival_love_triangle_root
				OPINION = 0
			}
			clear_saved_scope = relationship_reason_involved_character
		}
		scope:vassal_jealous = { 
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -10
			}
		}
		stress_impact = {
			chaste = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
		}
	}

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

##################################################
# Spoiled for Choice
# by Joe Parkin
# 8241
##################################################

scripted_trigger hold_court_8241_existing_suitor_trigger = { # is there a courtier or guest who would make a good low noble suitor?
	is_lowborn = no
	is_married = no
	fertility >= low_fertility
	age >= 18
	age <= 35
	polygamy_accepted_trigger = yes
	NOT = { is_close_or_extended_family_of = root }
	trigger_if = {
		limit = {
			scope:dummy_yearn_gender = { is_female = yes }
		}
		is_female = yes
	}
	trigger_else = { is_male = yes }
}

# Vassals both seek the same suitor
hold_court.8241 = {
	type = court_event
	title = hold_court.8241.t
	desc = hold_court.8241.desc
	theme = court
	override_background = { reference = throne_room }
	cooldown = { years = 10 }
	lower_right_portrait = scope:yearn_target

	court_scene = {
		button_position_character = scope:vassal_1
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:vassal_1 = {
				group = petitioners_group
				animation = anger
			}
			scope:vassal_2 = {
				group = petitioners_group
				animation = disapproval
			}
		}
	}

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

	trigger = {
		polygamy_accepted_trigger = yes # is polygamy cool?
		OR = { # at least 2 vassals attracted to the same gender?
			any_vassal_or_below = {
				count > 1
				hold_court_8240_attraction_list_trigger = { LIST = female }
			}
			any_vassal_or_below = {
				count > 1
				hold_court_8240_attraction_list_trigger = { LIST = male }
			}
		}
	}

	weight_multiplier = {
		base = 1

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

	immediate = {
		hold_court_attraction_list_effect = { ID = 8240 LIST = female } # populate list of vassals attracted to women
		hold_court_attraction_list_effect = { ID = 8240 LIST = male } # populate list of vassals attracted to me
		hold_court_attraction_dummy_gender_effect = yes # decide whether female or male is picked, based on lists being populated (50/50)
		if = {
			limit = {
				any_courtier_or_guest = { hold_court_8241_existing_suitor_trigger = yes } # is there a courtier or guest who would make a good low noble suitor?
			}
			ordered_courtier_or_guest = {
				limit = { hold_court_8241_existing_suitor_trigger = yes }
				order_by = attraction
				save_scope_as = yearn_target
			}
		}
		else = {
			create_character = { # Generate yearned for suitor
				location = root.location
				template = alluring_suitor_character
				gender = scope:dummy_yearn_gender
				dynasty = generate
				save_scope_as = yearn_target
			}
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = { # Side with 1st vassal
		name = hold_court.8241.a
		hidden_effect = {
			scope:yearn_target = { set_employer = scope:vassal_2 }
		}
		scope:vassal_1 = {
			if = {
				limit = { is_female = yes }
				marry_matrilineal = scope:yearn_target
			}
			else = { marry = scope:yearn_target }
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 10
			}
		}
		scope:vassal_2 = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -10
			}
			progress_towards_rival_effect = {
				CHARACTER = scope:vassal_1
				REASON = rival_love_triangle_generic
				OPINION = 0
			}
		}
	}

	option = { # Side with 2nd vassal
		name = hold_court.8241.b
		hidden_effect = {
			scope:yearn_target = { set_employer = scope:vassal_2 }
		} 
		scope:vassal_2 = {
			if = {
				limit = { is_female = yes }
				marry_matrilineal = scope:yearn_target
			}
			else = { marry = scope:yearn_target }
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 10
			}
		}
		scope:vassal_1 = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -10
			}
			progress_towards_rival_effect = {
				CHARACTER = scope:vassal_2
				REASON = rival_love_triangle_generic
				OPINION = 0
			}
		}
	}

	option = { # Take spouse
		name = hold_court.8241.c
		trigger = {
			trigger_if = {
				limit = {
					is_ai = yes
				}
				short_term_gold >= medium_gold_value
			}
			allowed_more_spouses = yes
			is_attracted_to_gender_of = scope:yearn_target
			trigger_if = {
				limit = {
					scope:yearn_target = { is_male = yes }
				}
				accepted_male_attraction_trigger = yes
			}
			trigger_else = { accepted_female_attraction_trigger = yes }
		}
		add_prestige = minor_prestige_loss
		hidden_effect = {
			scope:yearn_target = { set_employer = root }
		}
		remove_short_term_gold = minor_gold_value
		if = {
			limit = { is_female = yes }
			marry_matrilineal = scope:yearn_target
		}
		else = { marry = scope:yearn_target }
		scope:vassal_1 = { 
			add_opinion = {
				target = root
				modifier = angry_opinion
				opinion = -20
			}
		}
		scope:vassal_2 = { 
			add_opinion = {
				target = root
				modifier = angry_opinion
				opinion = -20
			}
		}
	}

	option = { # Dismiss
		name = hold_court.8241.d
		change_current_court_grandeur = medium_court_grandeur_gain
		scope:vassal_1 = {
			if = {
				limit = {
					can_set_relation_nemesis_trigger = { CHARACTER = scope:vassal_2 }
				}
				set_relation_nemesis = {
					reason = nemesis_vassal_dispute_marriage
					involved_character = scope:yearn_target
					copy_reason = rival
					target = scope:vassal_2
				}
			}
			duel = {
				skill = diplomacy
				target = scope:vassal_2
				2 = {
					desc = hold_court_8241_duel_vassal_1
					compare_modifier = {
						value = scope:vassal_1.diplomacy
						multiplier = 5
					}
					modifier = {
						factor = 2
						scope:vassal_1 = {
							OR = {
								has_trait = poet
								has_trait = seducer
							}
						}
					}
					modifier = {
						factor = 2
						scope:vassal_1 = { is_married = no }
					}
					hidden_effect = {
						scope:yearn_target = { set_employer = scope:vassal_2 }
					} 
					root = {
						send_interface_toast = {
							title = hold_court_8241_duel_vassal_1
							left_icon = scope:vassal_1
							right_icon = scope:yearn_target
							scope:vassal_1 = {
								if = {
									limit = { is_female = yes }
									marry_matrilineal = scope:yearn_target
								}
								else = { marry = scope:yearn_target }
							}
						}
					}
				}
				2 = {
					desc = hold_court_8241_duel_vassal_2
					compare_modifier = {
						value = scope:vassal_2.diplomacy
						multiplier = 5
					}
					modifier = {
						factor = 2
						scope:vassal_2 = {
							OR = {
								has_trait = poet
								has_trait = seducer
							}
						}
					}
					modifier = {
						factor = 2
						scope:vassal_2 = { is_married = no }
					}
					hidden_effect = {
						scope:yearn_target = { set_employer = scope:vassal_1 }
					}
					root = {
						send_interface_toast = {
							title = hold_court_8241_duel_vassal_2
							left_icon = scope:vassal_2
							right_icon = scope:yearn_target
							scope:vassal_2 = {
								if = {
									limit = { is_female = yes }
									marry_matrilineal = scope:yearn_target
								}
								else = { marry = scope:yearn_target }
							}
						}
					}
				}
			}
			scope:vassal_1 = { 
				add_opinion = {
					target = root
					modifier = disappointed_opinion
					opinion = -5
				}
			}
			scope:vassal_2 = { 
				add_opinion = {
					target = root
					modifier = disappointed_opinion
					opinion = -5
				}
			}
		}
	}

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

##################################################
# Hankering for X
# by Joe Parkin
# 8250
##################################################

scripted_trigger concubinage_accepted_trigger = {
	OR = {
		culture = { has_cultural_tradition = tradition_concubines }
		faith = { has_doctrine = doctrine_concubines }
	}
}

scripted_trigger hold_court_8250_concubinage_trigger = { # Is character able to have more concubines?
	has_court_event_flag = no
	is_available_ai_adult = yes
	concubinage_accepted_trigger = yes
	allowed_more_concubines = yes
}

scripted_trigger hold_court_8250_attraction_list_trigger = {
	has_court_event_flag = no
	is_available_ai_adult = yes
	seeking_love_trigger = yes
	accepted_$LIST$_attraction_trigger = yes
	hold_court_8250_concubinage_trigger = yes
}

scripted_trigger hold_court_8250_victim_trigger = {
	has_court_event_flag = no
	is_available_ai_adult = yes
	concubinage_accepted_trigger = yes
	OR = {
		is_courtier_of = root
		is_vassal_of = root
	}
}

scripted_trigger hold_court_8250_attracted_to_concubine_trigger = {
	hold_court_8250_concubinage_trigger = yes
	is_attracted_to_gender_of = $CONCUBINE$
	NOR = {
		this = $CONCUBINE$.primary_partner
		has_relation_rival = $CONCUBINE$
	}
	trigger_if = {
		limit = {
			$CONCUBINE$ = { is_male = yes }
		}
		accepted_male_attraction_trigger = yes
	}
	trigger_else = { accepted_female_attraction_trigger = yes }
}

scripted_trigger hold_court_8250_possible_yearn_target_trigger = {
	has_court_event_flag = no
	is_available_ai_adult = yes
	save_temporary_scope_as = yearn_target_temp
	root = {
		OR = {
			any_vassal_or_below = {
				hold_court_8250_attracted_to_concubine_trigger = { CONCUBINE = scope:yearn_target_temp }
			}
			any_courtier = {
				hold_court_8250_attracted_to_concubine_trigger = { CONCUBINE = scope:yearn_target_temp }
			}
		}
	}
}

# Vassal covets another's concubine
hold_court.8250 = {
	type = court_event
	title = hold_court.8250.t
	desc = hold_court.8250.desc
	theme = court
	override_background = { reference = throne_room }
	cooldown = { years = 10 }
	lower_right_portrait = scope:yearn_target

	court_scene = {
		button_position_character = scope:vassal_jealous
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:vassal_jealous = {
				group = petitioners_group
				animation = beg
			}
			scope:vassal_victim = {
				group = petitioners_group
				animation = anger
			}
		}
	}

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

	trigger = {
		concubinage_accepted_trigger = yes
		any_vassal_or_below = {
			hold_court_8250_victim_trigger = yes
			any_concubine = { hold_court_8250_possible_yearn_target_trigger = yes }
		}
	}
 
	weight_multiplier = {
		base = 1

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

	immediate = {
		random_vassal_or_below = {
			limit = {
				hold_court_8250_victim_trigger = yes
				any_concubine = { hold_court_8250_possible_yearn_target_trigger = yes }
			}
			court_event_character_flag_effect = yes
			save_scope_as = vassal_victim
			ordered_concubine = {
				limit = { hold_court_8250_possible_yearn_target_trigger = yes }
				order_by = attraction
				court_event_character_flag_effect = yes
				save_scope_as = yearn_target
			}
		}
		every_vassal_or_below = {
			limit = {
				hold_court_8250_attracted_to_concubine_trigger = { CONCUBINE = scope:yearn_target }
			}
			add_to_list = jealous_list
		}
		every_courtier = {
			limit = {
				hold_court_8250_attracted_to_concubine_trigger = { CONCUBINE = scope:yearn_target }
			}
			add_to_list = jealous_list
		}
		random_in_list = {
			list = jealous_list
			limit = { has_relation_soulmate = scope:yearn_target }
			alternative_limit = { has_relation_lover = scope:yearn_target }
			alternative_limit = { always = yes }
			weight = {
				base = 1
				modifier = {
					factor = 4
					has_trait = lustful
				}
				modifier = {
					factor = 4
					has_trait = greedy
				}
			}
			save_scope_as = vassal_jealous
			court_event_character_flag_effect = yes
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = { # Side with victim vassal
		name = hold_court.8250.a
		scope:vassal_victim = {
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 10
			}
		}
		scope:vassal_jealous = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -15
			}
			progress_towards_rival_effect = {
				CHARACTER = scope:vassal_victim
				REASON = rival_love_triangle_generic
				OPINION = 0
			}
			hidden_effect = {
				if = {
					limit = {
						can_start_scheme = {
							type = seduce
							target = scope:yearn_target
						}
					}
					random = {
						chance = 50
						start_scheme = {
							type = seduce
							target = scope:yearn_target
						}
					}
				}
			}
		}
	}

	option = { # Side with jealous vassal
		name = hold_court.8250.b
		hidden_effect = {
			scope:vassal_victim = { remove_concubine = scope:yearn_target }
			scope:yearn_target = { set_employer = scope:vassal_jealous }
		}
		scope:vassal_jealous = {
			make_concubine = scope:yearn_target
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 15
			}
		}
		scope:vassal_victim = {
			add_opinion = {
				target = root
				modifier = angry_opinion
				opinion = -20
			}
			progress_towards_rival_effect = {
				CHARACTER = scope:vassal_jealous
				REASON = rival_love_triangle_generic
				OPINION = 0
			}
		}
	}

	option = { # Take concubine
		name = hold_court.8250.c
		trigger = {
			allowed_more_concubines = yes
			trigger_if = {
				limit = {
					scope:yearn_target = { is_male = yes }
				}
				accepted_male_attraction_trigger = yes
			}
			trigger_else = { accepted_female_attraction_trigger = yes }
		}
		hidden_effect = {
			scope:vassal_victim = { remove_concubine = scope:yearn_target }
			scope:yearn_target = { set_employer = root }
		}
		make_concubine = scope:yearn_target
		scope:vassal_victim = { 
			add_opinion = {
				target = root
				modifier = angry_opinion
				opinion = -20
			}
		}
		scope:vassal_jealous = { 
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -10
			}
		}
		stress_impact = {
			compassionate = medium_stress_impact_gain
			chaste = medium_stress_impact_gain
		}
	}

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

##################################################
# The Dancer
# by Joe Parkin
# 8251
##################################################

# Vassals both seek the same concubine
hold_court.8251 = {
	type = court_event
	title = hold_court.8251.t
	desc = hold_court.8251.desc
	theme = court
	override_background = { reference = throne_room }
	cooldown = { years = 10 }
	lower_right_portrait = scope:yearn_target

	court_scene = {
		button_position_character = scope:vassal_1
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:vassal_1 = {
				group = petitioners_group
				animation = anger
			}
			scope:vassal_2 = {
				group = petitioners_group
				animation = disapproval
			}
		}
	}

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

	trigger = {
		concubinage_accepted_trigger = yes
		OR = {
			any_vassal_or_below = {
				count > 1
				hold_court_8250_attraction_list_trigger = { LIST = female }
			}
			any_vassal_or_below = {
				count > 1
				hold_court_8250_attraction_list_trigger = { LIST = male }
			}
		}
	}

	weight_multiplier = {
		base = 1

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

	immediate = {
		hold_court_attraction_list_effect = { ID = 8250 LIST = female }
		hold_court_attraction_list_effect = { ID = 8250 LIST = male }
		hold_court_attraction_dummy_gender_effect = yes
		create_character = { # Generate yearned for concubine
			location = root.location
			template = beautiful_peasant_character
			gender = scope:dummy_yearn_gender
			dynasty = none
			save_scope_as = yearn_target
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	option = { # Side with 1st vassal
		name = hold_court.8251.a
		hidden_effect = {
			scope:yearn_target = { set_employer = scope:vassal_2 }
		}
		scope:vassal_1 = {
			make_concubine = scope:yearn_target
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 10
			}
		}
		scope:vassal_2 = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -10
			}
			progress_towards_rival_effect = {
				CHARACTER = scope:vassal_1
				REASON = rival_love_triangle_generic
				OPINION = 0
			}
		}
	}

	option = { # Side with 2nd vassal
		name = hold_court.8251.b
		hidden_effect = {
			scope:yearn_target = { set_employer = scope:vassal_2 }
		} 
		scope:vassal_2 = {
			make_concubine = scope:yearn_target
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 10
			}
		}
		scope:vassal_1 = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -10
			}
			progress_towards_rival_effect = {
				CHARACTER = scope:vassal_2
				REASON = rival_love_triangle_generic
				OPINION = 0
			}
		}
	}

	option = { # Take concubine
		name = hold_court.8251.c
		trigger = {
			allowed_more_concubines = yes
			trigger_if = {
				limit = {
					scope:yearn_target = { is_male = yes }
				}
				accepted_male_attraction_trigger = yes
			}
			trigger_else = { accepted_female_attraction_trigger = yes }
		}
		hidden_effect = {
			scope:yearn_target = { set_employer = root }
		}
		make_concubine = scope:yearn_target
		scope:vassal_1 = { 
			add_opinion = {
				target = root
				modifier = angry_opinion
				opinion = -20
			}
		}
		scope:vassal_2 = { 
			add_opinion = {
				target = root
				modifier = angry_opinion
				opinion = -20
			}
		}
		stress_impact = {
			chaste = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
		}
	}

	option = { # Marry
		name = hold_court.8251.d
		trigger = {

			trigger_if = {
				limit = { allowed_to_marry_same_sex_trigger = no }
				OR = {
					AND = {
						is_female = yes
						scope:yearn_target = { is_male = yes }
					}
					AND = {
						is_male = yes
						scope:yearn_target = { is_female = yes }
					}
				}
			}

			allowed_more_spouses = yes
			is_attracted_to_gender_of = scope:yearn_target
			trigger_if = {
				limit = {
					scope:yearn_target = { is_male = yes }
				}
				accepted_male_attraction_trigger = yes
			}
			trigger_else = { accepted_female_attraction_trigger = yes }
		}
		add_prestige = medium_prestige_loss
		hidden_effect = {
			scope:yearn_target = { set_employer = root }
		}
		if = {
			limit = { is_female = yes }
			marry_matrilineal = scope:yearn_target
		}
		else = { marry = scope:yearn_target }
		scope:vassal_1 = { 
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -5
			}
		}
		scope:vassal_2 = { 
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -5
			}
		}
		stress_impact = {
			honest = medium_stress_impact_gain
			arrogant = medium_stress_impact_gain
		}
	}

	option = { # Dismiss
		name = hold_court.8251.e
		change_current_court_grandeur = minor_court_grandeur_gain
		scope:vassal_1 = {
			duel = {
				skill = diplomacy
				target = scope:vassal_2
				2 = {
					desc = hold_court_8251_duel_vassal_1
					compare_modifier = {
						value = scope:vassal_1.diplomacy
						multiplier = 5
					}
					modifier = {
						factor = 2
						scope:vassal_1 = {
							OR = {
								has_trait = poet
								has_trait = seducer
							}
						}
					}
					modifier = {
						factor = 2
						scope:vassal_1 = { is_married = no }
					}
					hidden_effect = {
						scope:yearn_target = { set_employer = scope:vassal_2 }
					} 
					root = {
						send_interface_toast = {
							title = hold_court_8241_duel_vassal_1
							left_icon = scope:vassal_1
							right_icon = scope:yearn_target
							scope:vassal_1 = { make_concubine = scope:yearn_target }
						}
					}
				}
				2 = {
					desc = hold_court_8251_duel_vassal_2
					compare_modifier = {
						value = scope:vassal_2.diplomacy
						multiplier = 5
					}
					modifier = {
						factor = 2
						scope:vassal_2 = {
							OR = {
								has_trait = poet
								has_trait = seducer
							}
						}
					}
					modifier = {
						factor = 2
						scope:vassal_2 = { is_married = no }
					}
					hidden_effect = {
						scope:yearn_target = { set_employer = scope:vassal_1 }
					}
					root = {
						send_interface_toast = {
							title = hold_court_8251_duel_vassal_2
							left_icon = scope:vassal_2
							right_icon = scope:yearn_target
							scope:vassal_2 = { make_concubine = scope:yearn_target }
						}
					}
				}
			}
			scope:vassal_1 = { 
				add_opinion = {
					target = root
					modifier = disappointed_opinion
					opinion = -5
				}
			}
			scope:vassal_2 = { 
				add_opinion = {
					target = root
					modifier = disappointed_opinion
					opinion = -5
				}
			}
		}
	}

	after = {
		scope:vassal_1 = { 
			clear_court_event_participation = yes
		}
		scope:vassal_2 = { 
			clear_court_event_participation = yes
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_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 }
		NOT = { 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
				NOT = { 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_is_type = claimant_faction
						exists = special_title
						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
				 	NOT = { 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
				 	NOT = { 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
				 	NOT = { 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
	#AGOT Modified, must be actually independent
	#is_independent_ruler = yes
	agot_is_independent_ruler = yes
	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 = {
				NOT = { 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
	}

	## AGOT Added, either both have to be wildlings, or neither can be
	OR = {
		AND = {
			culture = { agot_is_wildling_culture = yes }
			root.culture = { agot_is_wildling_culture = yes }
		}
		AND = {
			culture = { agot_is_wildling_culture = no }
			root.culture = { agot_is_wildling_culture = no }
		}
	}
}

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 = {
						NOT = { this = root }
						primary_title.tier >= tier_kingdom
						OR = {
							AND = {
								prev.faith = root.faith
								NOT = { faith = prev.faith }
							}
							AND = {
								prev.religion = root.religion
								NOT = { religion = prev.religion }
							}
							AND = {
								prev.culture = root.culture
								NOT = { 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 = { is_independent_ruler = no } # 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
		NOT = { 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
		NOT = { 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 = {
					NOT = { 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 = {
			NOT = { 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 = {
						NOT = { this = root }
						government_has_flag = government_is_tribal
						culture = { has_cultural_tradition = tradition_horse_lords }
					}
					hold_court_8280_nomad_county_trigger = yes
				}
				alternative_limit = {
					NOT = { 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_gold >= minor_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_short_term_gold = tiny_gold_value
		scope:feudal_vassal = {
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 10
			}
		}
		scope:nomad = {
			if = {
				limit = {
					NOT = { 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 = {
						NOT = { this = root.culture }
					}
					change_cultural_acceptance = {
						target = root.culture
						value = -10
						desc = cultural_intolerance_tt
					}
				}
			}
		}
		if = {
			limit = {
				NOT = { scope:feudal_vassal.culture = root.culture }
			}

			scope:feudal_vassal.culture = {
				if = {
					limit = {
						NOT = { 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_gold >= massive_gold_value
			}
		}
		remove_short_term_gold = major_gold_value
		culture = {
			if = {
				limit = {
					NOT = { 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 = {
					NOT = { 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 = {
				NOT = { 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
				NOT = { culture = scope:nomad_culture }
				has_trait = paranoid
			}
			modifier = {	#Weight down for stress.
				add = -15
				NOT = { 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 = {
					NOT = { this = scope:nomad_culture }
				}
				change_cultural_acceptance = {
					target = scope:nomad_culture
					value = 5
					desc = cultural_intolerance_tt
				}
			}
		}
		if = {
			limit = {
				NOT = { 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
				NOT = { culture = scope:nomad_culture }
				has_trait = diligent
			}
			modifier = {	#Weight down for stress.
				add = -15
				NOT = { 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
	}
}
