namespace = court_yearly

#####################################
# Growing Debauchery 				#
# by Sean Hughes					#
# 1000-1001							#
#####################################

scripted_trigger court_1000_valid_child = {
	is_courtier_of = root
	age >= 16
	OR = {
		can_be_drunkard = yes
		can_be_hashishiyah = yes
		can_be_rakish = yes
	}
	NOR = {
		has_trait = drunkard
		has_trait = hashishiyah
		has_trait = rakish
	}
}

scripted_effect court_1000_gain_debauchery_trait = {
	if = {
		limit = { scope:debauchery_type = flag:hashishiyah }
		add_trait = hashishiyah
	}
	else_if = {
		limit = { scope:debauchery_type = flag:drunkard }
		add_trait = drunkard
	}
	else_if = {
		limit = { scope:debauchery_type = flag:rakish }
		add_trait = rakish
	}
}

scripted_trigger court_1001_valid_debaucher = {
	is_courtier_of = root
	age >= 16
	exists = scope:debauchery_type
	OR = {
		AND = {
			scope:debauchery_type = flag:hashishiyah
			can_be_hashishiyah = yes
		}
		AND = {
			scope:debauchery_type = flag:drunkard
			can_be_drunkard = yes
		}
		AND = {
			scope:debauchery_type = flag:rakish
			can_be_rakish = yes
		}
	}
}

court_yearly.1000 = {
	type = character_event
	title = court.1000.t
	desc = {
		desc = court.1000.desc.opening
		first_valid = {
			triggered_desc = {
				trigger = { scope:debauchery_type = flag:drunkard } 
				desc = court.1000.desc.drunkard
			}
			triggered_desc = {
				trigger = { scope:debauchery_type = flag:hashishiyah } 
				desc = court.1000.desc.hashishiyah
			}
			triggered_desc = {
				trigger = { scope:debauchery_type = flag:rakish } 
				desc = court.1000.desc.rakish
			}
		}
 		desc = court.1000.desc.ending
	}
	theme = court
	left_portrait = {
		character = root
		animation = stress
	}
	right_portrait = {
		character = scope:child
		triggered_animation = {
			trigger = {
				scope:debauchery_type = flag:drunkard
			}
  			animation = drink
  		}
		triggered_animation = {
			trigger = {
				scope:debauchery_type = flag:hashishiyah
			}
  			animation = personality_irrational
  		}
		triggered_animation = {
			trigger = {
				scope:debauchery_type = flag:rakish
			}
  			animation = flirtation
  		}
	}
	override_background = {
		trigger = {
			OR = {
				scope:debauchery_type = flag:drunkard
				scope:debauchery_type = flag:rakish
			}
		}
		reference = tavern
	}
	override_background = {
		trigger = {
			scope:debauchery_type = flag:hashishiyah
		}
		reference = bp1_wine_cellar
	}
	
	trigger = {
		has_royal_court = yes
		has_dlc_feature = royal_court
		any_child = {
			court_1000_valid_child = yes
		}
		NOT = { has_character_flag = court_1000_discouraged_debauchery }
	}

	weight_multiplier = {
		base = 1

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

	immediate = {
		random_child = {
			limit = {
				court_1000_valid_child = yes
			}
			save_scope_as = child
			random_list = {
				50 = {
					trigger = { can_be_drunkard = yes }
					modifier = {
						factor = 0.1
						OR = {
							faith = { trait_is_sin = drunkard }
							religion = religion:islam_religion
						}
					}
					save_scope_value_as = {
						name = debauchery_type
						value = flag:drunkard
					}
				}
				40 = {
					trigger = { can_be_hashishiyah = yes }
					modifier = {
						factor = 0.1
						faith = { trait_is_sin = hashishiyah }
					}
					save_scope_value_as = {
						name = debauchery_type
						value = flag:hashishiyah
					}
				}
				10 = {
					trigger = { can_be_rakish = yes }
					modifier = {
						factor = 0.1
						faith = { trait_is_virtue = lustful }
					}
					save_scope_value_as = {
						name = debauchery_type
						value = flag:rakish
					}
				}
			}
		}
	}

	# Option A: Publicly reprimand/humilite your child to make them stop
	option = { 
		name = court.1000.a
		scope:child = {
			add_prestige_level = -1
			add_opinion = {
				modifier = angry_opinion
				target = root
				opinion = -50
			}
		}
		custom_tooltip = court.1000.a.tt
		hidden_effect = {
			add_character_flag = {
				flag = court_1000_discouraged_debauchery
				years = 30
			}
		}
	}

	# Option B: Give your child a title or court position to try and keep them occupied
	option = {
		name = court.1000.b
		trigger = {
			any_held_title = {
				title_tier = county
				is_landless_type_title = no
				count >= 2
			}
		}

		random_held_title = {
			title_tier = county
			limit = {
				is_landless_type_title = no
			}
			save_scope_as = granted_title
		}

		create_title_and_vassal_change = {
			type = granted
			save_scope_as = change
		}
		scope:granted_title = {
			change_title_holder = {
				holder = scope:child
				change = scope:change
			}
		}
		resolve_title_and_vassal_change = scope:change
		scope:child = {		
			random_list = {
				50 = {
					desc = court.1000.b.success
					ai_value_modifier = {
						ai_energy = 0.5
						ai_greed = 0.2
						ai_honor = 0.2
					}
					add_stewardship_skill = 2
				}
				50 = {
					desc = court.1000.b.failure
					ai_value_modifier = {
						ai_energy = -0.5
						ai_greed = -0.2
						ai_honor = -0.2
					}
					court_1000_gain_debauchery_trait = yes
				}
			}
		}
	}
	
	# Option C: Let the behavior continue unpunished, maybe joning in from time to time
	option = {
		name = court.1000.c
		scope:child = {
			court_1000_gain_debauchery_trait = yes
			add_stress = medium_stress_loss
		}
		add_stress = medium_stress_loss
		custom_tooltip = court.1000.c.tt

		# Other courtiers might be tempted by the unmoderated indulgence of vices
		hidden_effect = {	
			every_courtier = {
				limit = {
					this != scope:child
					court_1001_valid_debaucher = yes
				}
				random_list = {
					80 = { 
						# Nothing happens

					}
					20 = {
						ai_value_modifier = {
							ai_energy = -0.1
							ai_honor = -0.1
						}
						modifier = {
							add = 140
							OR = {
								AND = { 
									scope:debauchery_type = flag:drunkard
									OR = {
										has_trait = gluttonous
										has_trait = lifestyle_reveler 
									}
								}
								AND = { 
									scope:debauchery_type = flag:hashishiyah
									OR = {
										has_trait = gluttonous
										has_trait = lazy
									}
								}
								AND = { 
									scope:debauchery_type = flag:rakish
									has_trait = lustful

								}
							}
						}
						modifier = {
							factor = 0
							OR = {
								has_trait = temperate
								has_trait = zealous
								has_trait = chaste
							}
						}

						trigger_event = {
							id = court_yearly.1001
							days =  { 14 60 }
						}
					}
				}
			}
		}
	}
}

court_yearly.1001 = {
	hidden = yes
	
	trigger = {
		# We are still in the same court as the initial debaucher.
		has_royal_court = yes
		has_dlc_feature = royal_court
		scope:child = {
			is_courtier_of = root.court_owner
		}
		# We are not opposed to debauchery
		court_1001_valid_debaucher = yes
	}

	immediate = {
		court_owner = {
			if = {
				# If we're important to our liege in some way, gain debauchery trait with a notification send to them.
				limit = { 
					is_of_major_interest_trigger = { CHARACTER = root }
				}
				root = { save_scope_as = courtier }
				send_interface_message = {
					type = event_generic_neutral
					title = court.1001.title

					root = {
						court_1000_gain_debauchery_trait = yes
					}
				}
			}
			else = {
				# Otherwise we silently gain the trait, in order to avoid notification spam.
				root = {
					court_1000_gain_debauchery_trait = yes
				}
			}
		}
	}
}

#####################################
# Long Arm of the Law 				#
# by Sean Hughes					#
# 1020								#
#####################################

scripted_trigger court_1020_suitable_guest_trigger = {
	# Of suitable age.
	age >= 16
	# Lacks the principle award.
	save_temporary_scope_as = fugitive_check
	NOT = {
		root = { has_strong_hook = scope:fugitive_check }
	}
}

scripted_effect court_1020_remove_opinion_from_root_modifier = {
	if = {
		limit = {
			has_opinion_modifier = {
				modifier = $OPINION_MODIFIER$
				target = root 
			}
		}
		remove_opinion = {
			modifier = $OPINION_MODIFIER$
			target = root
		}
	}
}

court_yearly.1020 = {
	type = letter_event
	opening = court.1020.opening
	desc = {
		desc = court.1020.desc
		first_valid = {
			triggered_desc = {
				trigger = {scope:compensation = flag:forgive_this}
				desc = court.1020.desc.forgive_this
			}
			triggered_desc = {
				trigger = {scope:compensation = flag:forgive_all}
				desc = court.1020.desc.forgive_all
			}
			triggered_desc = {
				trigger = {scope:compensation = flag:gold}
				desc = court.1020.desc.gold
			}
			triggered_desc = {
				trigger = {scope:compensation = flag:opinion}
				desc = court.1020.desc.opinion
			}
		}
	}
	sender = scope:foreign_ruler
	
	trigger = {
		has_royal_court = yes
		has_dlc_feature = royal_court
		any_pool_guest = { court_1020_suitable_guest_trigger = yes }
		any_neighboring_and_across_water_top_liege_realm = {
			exists = holder
		}
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		random_pool_guest = {
			limit = { court_1020_suitable_guest_trigger = yes }
			save_scope_as = fugitive
		}
		random_neighboring_and_across_water_top_liege_realm = {
			holder = { save_scope_as = foreign_ruler }
		}
		scope:foreign_ruler = {
			random_list = {
				33 = {
					ai_value_modifier = {
						ai_vengefulness = 0.15
						ai_greed = 0.1
					}
					if = {
						limit = {
							root = { is_ai = no }
							scope:foreign_ruler = {
								OR = {
									has_opinion_modifier = {
										modifier = hate_opinion
										target = root 
									}
									has_opinion_modifier = {
										modifier = refusal_opinion
										target = root 
									}
									has_opinion_modifier = {
										modifier = suspicion_opinion
										target = root 
									}
									has_opinion_modifier = {
										modifier = disappointed_opinion
										target = root 
									}
									has_opinion_modifier = {
										modifier = insult_opinion
										target = root 
									}
									has_opinion_modifier = {
										modifier = angry_opinion
										target = root 
									}
									has_opinion_modifier = {
										modifier = declared_war
										target = root 
									}
									has_opinion_modifier = {
										modifier = declared_war_on_son_daughter
										target = root 
									}
								}
							}
						}
						save_scope_value_as = {
							name = compensation
							value = flag:forgive_all
						}
					}
					else = {
						save_scope_value_as = {
							name = compensation
							value = flag:forgive_this
						}
					}
				}
				33 = {
					ai_value_modifier = {
						ai_greed = -0.3
					}
					save_scope_value_as = {
						name = compensation
						value = flag:gold
					}
				}
				33 = {
					ai_value_modifier = {
						ai_compassion = 0.2
						ai_honor = 0.1
					}
					if = {
						limit = {
							root = { is_ai = no }
							scope:foreign_ruler = {
								OR = {
									has_opinion_modifier = {
										modifier = hate_opinion
										target = root 
									}
									has_opinion_modifier = {
										modifier = refusal_opinion
										target = root 
									}
									has_opinion_modifier = {
										modifier = suspicion_opinion
										target = root 
									}
									has_opinion_modifier = {
										modifier = disappointed_opinion
										target = root 
									}
									has_opinion_modifier = {
										modifier = insult_opinion
										target = root 
									}
									has_opinion_modifier = {
										modifier = angry_opinion
										target = root 
									}
									has_opinion_modifier = {
										modifier = declared_war
										target = root 
									}
									has_opinion_modifier = {
										modifier = declared_war_on_son_daughter
										target = root 
									}
								}
							}
						}
						save_scope_value_as = {
							name = compensation
							value = flag:forgive_all
						}
					}
					else = {
						save_scope_value_as = {
							name = compensation
							value = flag:opinion
						}
					}
				}
			}
		}
	}

	# Option A: Agree to the foreign ruler's demand and hand over the fugitive
	option = { 
		name = court.1020.a

		if = {
			limit = {
				scope:compensation = flag:forgive_all
			}
			scope:foreign_ruler = {		
				court_1020_remove_opinion_from_root_modifier = { OPINION_MODIFIER = hate_opinion }
				court_1020_remove_opinion_from_root_modifier = { OPINION_MODIFIER = refusal_opinion }
				court_1020_remove_opinion_from_root_modifier = { OPINION_MODIFIER = suspicion_opinion }
				court_1020_remove_opinion_from_root_modifier = { OPINION_MODIFIER = disappointed_opinion }
				court_1020_remove_opinion_from_root_modifier = { OPINION_MODIFIER = insult_opinion }
				court_1020_remove_opinion_from_root_modifier = { OPINION_MODIFIER = angry_opinion }
				court_1020_remove_opinion_from_root_modifier = { OPINION_MODIFIER = declared_war }
				court_1020_remove_opinion_from_root_modifier = { OPINION_MODIFIER = declared_war_on_son_daughter }
			}
		}
		else_if = {
			limit = {
				scope:compensation = flag:gold
			}
			scope:foreign_ruler = {		
				pay_treasury_or_gold = {
					target = root
					value = minor_treasury_or_gold_value
				}
			}
		}
		else_if = {
			limit = {
				scope:compensation = flag:opinion
			}
			scope:foreign_ruler = {
				add_opinion = {
					modifier = pleased_opinion
					target = root
					opinion = 20
				}
			}
		}

		rightfully_imprison_character_effect = {
			TARGET = scope:fugitive
			IMPRISONER = scope:foreign_ruler
		}
	}

	# Option B: Offer the fugitive your protection, pissing off the foreign ruler
	option = {
		name = court.1020.b
		if = {
			limit = {
				can_add_hook = {
					target = scope:fugitive
					type = loyalty_hook
				}
			}
			add_hook = {
				type = loyalty_hook
				target = scope:fugitive
			}
		}
		scope:foreign_ruler = {
			add_opinion = {
				modifier = refusal_opinion
				target = root
				opinion = -30
			}
		}
	}
	
	# Option C: Warn the fugitive and let them escape
	option = {
		name = court.1020.c
		scope:fugitive = {
			add_opinion = {
				modifier = grateful_opinion
				target = root
				opinion = 10
			}
			select_and_move_to_pool_effect = yes
		}
		scope:foreign_ruler = {
			add_opinion = {
				modifier = disappointed_opinion
				target = root
				opinion = -5
			}
		}
	}
}


##################################################
# Competitive Cronying
# by Ewan Cowhig Croft
# 2001 - 2010
##################################################

scripted_trigger court_2001_valid_toadies_available_trigger = {
	# Standard checks.
	is_available_ai_adult = yes
	# Lacks a personality that would actively stop them from toadying:
	NOR = {
		has_trait = honest
		has_trait = arrogant
		has_trait = shy
		has_trait = content
	}
	# Isn't immediately related to you.
	NOR = {
		any_close_or_extended_family_member = { this = root }
		any_spouse = { this = root }
	}
	# And likes you enough to want to suck up to you.
	opinion = {
		target = root
		value >= low_negative_opinion
	}
}

court_yearly.2001 = {
	type = character_event
	title = court.2001.t
	desc = court.2001.desc
	theme = court
	left_portrait = {
		character = scope:crony_a
		animation = disapproval
	}
	right_portrait = {
		character = scope:crony_b
		animation = dismissal
	}

	cooldown = { years = 10 }

	trigger = {
		# DLC check.
		has_royal_court = yes
		has_dlc_feature = royal_court
		# Standard checks.
		is_available_at_peace_adult = yes
		is_landed = yes
		# At least two courtiers or guests are suitable toadies.
		any_courtier_or_guest = {
			count >= 2
			court_2001_valid_toadies_available_trigger = yes
		}
	}

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

	immediate = {
		# Grab two random toadies.
		random_courtier_or_guest = {
			limit = { court_2001_valid_toadies_available_trigger = yes }
			weight = {
				base = 1
				is_of_minor_interest_to_weight_up_modifier = { CHARACTER = root }
				is_of_major_interest_to_weight_up_modifier = { CHARACTER = root }
				opinion_modifier = {
					opinion_target = root
					# Cap it a bit so we don't always have opinion gain with characters that already love you.
					max = 50
				}
			}
			save_scope_as = crony_a
		}
		random_courtier_or_guest = {
			limit = {
				court_2001_valid_toadies_available_trigger = yes
				this != scope:crony_a
			}
			weight = {
				base = 1
				is_of_minor_interest_to_weight_up_modifier = { CHARACTER = root }
				is_of_major_interest_to_weight_up_modifier = { CHARACTER = root }
			}
			save_scope_as = crony_b
		}
	}

	# Honestly, you could both try harder.
	option = {
		name = court.2001.a
		trigger = {
			NOT = { has_trait = sadistic }
		}

		# Gain opinion with the lackeys as they hard-core focus on sucking up to ye.
		reverse_add_opinion = {
			target = scope:crony_a
			modifier = shamed_me_opinion
			opinion = 40
		}
		reverse_add_opinion = {
			target = scope:crony_b
			modifier = shamed_me_opinion
			opinion = 40
		}
		# Add a little CGV for all these obsequious toadies constantly making a big deal about you.
		change_current_court_grandeur = miniscule_court_grandeur_gain

		stress_impact = {
			arrogant = miniscule_stress_impact_loss
			humble = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_sociability = 0.5
				ai_greed = 0.25
				ai_compassion = -0.5
			}
		}
	}

	# Whoever bows lowest gets a shiny coin.
	option = {
		name = court.2001.a.sadistic
		trigger = { has_trait = sadistic }

		# Gain opinion with the lackeys as they hard-core focus on sucking up to ye.
		reverse_add_opinion = {
			target = scope:crony_a
			modifier = shamed_me_opinion
			opinion = 60
		}
		reverse_add_opinion = {
			target = scope:crony_b
			modifier = shamed_me_opinion
			opinion = 60
		}
		# And toss the coin at random.
		random_list = {
			50 = {
				desc = court.2001.a.sadistic.crony_a_wins
				send_interface_toast = {	
					type = event_toast_effect_neutral
					title = court.2001.a.sadistic.crony_a_wins
					left_icon = scope:crony_a
					pay_short_term_gold = {
						target = scope:crony_a
						gold = 1
					}
				}
			}
			50 = {
				desc = court.2001.a.sadistic.crony_b_wins
				send_interface_toast = {
					type = event_toast_effect_neutral
					title = court.2001.a.sadistic.crony_b_wins
					left_icon = scope:crony_b
					pay_short_term_gold = {
						target = scope:crony_b
						gold = 1
					}
				}
			}
		}
		# Add a little CGV for all these obsequious toadies constantly making a big deal about you.
		change_current_court_grandeur = minor_court_grandeur_gain

		stress_impact = {
			arrogant = miniscule_stress_impact_loss
			humble = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_sociability = 0.5
				ai_greed = 0.25
				ai_compassion = -0.5
			}
		}
	}
	
	# These empty platitudes are disgusting!
	option = {
		name = court.2001.b

		# Gain prestige for renouncing their lackeying.
		add_prestige = minor_prestige_gain
		# Lose opinion with both.
		reverse_add_opinion = {
			target = scope:crony_a
			modifier = hurt_opinion
			opinion = -25
		}
		reverse_add_opinion = {
			target = scope:crony_b
			modifier = hurt_opinion
			opinion = -25
		}

		stress_impact = {
			humble = miniscule_stress_impact_loss
			arrogant = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = -0.25
				ai_sociability = -0.25
				ai_compassion = -0.25
			}
		}
	}
	
	# There's one obvious way you haven't tried...
	option = {
		name = court.2001.c

		# Both pay you cash-monies.
		scope:crony_a = {
			pay_short_term_gold = {
				target = root
				gold = minor_gold_value
			}
		}
		scope:crony_b = {
			pay_short_term_gold = {
				target = root
				gold = minor_gold_value
			}
		}
		# Both dislike you for the direct demand.
		reverse_add_opinion = {
			target = scope:crony_a
			modifier = respect_opinion
			opinion = -35
		}
		reverse_add_opinion = {
			target = scope:crony_b
			modifier = respect_opinion
			opinion = -35
		}

		stress_impact = {
			greedy = miniscule_stress_impact_loss
			generous = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 0.75
				ai_compassion = -0.25
			}
		}
	}

	# This is beneath me.
	option = {
		name = court.2001.d

		# Gain some fame for your straight-talking.
		add_prestige_experience = medium_prestige_gain

		stress_impact = {
			shy = miniscule_stress_impact_loss
			gregarious = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = 0.5
				ai_sociability = -0.5
			}
		}
	}
}

#########################
# Scrounger Life		#
# by Claudia Baldassi	#
# 6040-6041				#
#########################

scripted_trigger court_6040_has_valid_scrounger_trigger = {
	is_adult = yes
	NOR = { 
		is_close_family_of = root
		is_councillor_of = root
	}
	OR = {
		has_trait = lazy
		has_trait = greedy
		has_trait = gluttonous
		has_trait = drunkard
		has_trait = comfort_eater
		has_trait = profligate
		has_trait = rakish
		has_trait = hashishiyah
	}
	OR = {
		learning >= 8
		diplomacy >= 8
	}
}

# You have a useless scrounger at court, but if supported long enough, he turns out to be a great poet (might become a Great Person?) #


court_yearly.6040 = {
	type = character_event
	title = court.6040.t
	desc = court.6040.desc
	theme = court
	left_portrait = {
		character = scope:scrounger
		animation = happiness
	}
	right_portrait = {
		character = root
		animation = disapproval
	}

	trigger = {
		has_royal_court = yes
		has_dlc_feature = royal_court
		any_courtier_or_guest = {
			court_6040_has_valid_scrounger_trigger = yes
		}
		NOT = {
			has_character_flag = court_6040_cooldown
		}
	}

	weight_multiplier = {
		base = 1

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

	immediate = {
		add_character_flag = {
			flag = court_6040_cooldown
			years = 20
		}
		random_courtier_or_guest = {
			limit = {
				court_6040_has_valid_scrounger_trigger = yes
			}
			save_scope_as = scrounger
		}
		personality_check_shared_good_ruler_traits_effect = {
			CHAR1 = root
			CHAR2 = scope:scrounger
			STRICT = no
		}
		set_variable = court_6040_best_looking_var
		if = {
			limit = {
				employs_court_position = court_jester_court_position
				any_court_position_holder = {
					type = court_jester_court_position
					is_available_ai_adult = yes
				}
			}
			random_court_position_holder = {
				type = court_jester_court_position
				limit = { is_available_ai_adult = yes }
				save_scope_as = jester
			}
		}
	}

	after = {
		remove_variable = court_6040_best_looking_var
	}

	# Option A: make them earn their living by making them court jester
	option = {
		name = court.6040.a
		trigger = {
			scope:scrounger = { can_be_employed_as = court_jester_court_position }
			OR = {
				can_employ_court_position_type = court_jester_court_position
				exists = scope:jester
			}
		}
		court_position_grant_effect = { POS = court_jester CANDIDATE = scope:scrounger EMPLOYER = root }
		change_current_court_grandeur = minor_court_grandeur_gain
		every_courtier_or_guest = {
			custom = court_6000_all_courtiers_and_guests
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 5
			}
		}
		ai_chance = {
			base = 100
		}
	}

	# Option B: tolerate them
	option = {
		name = court.6040.b
		remove_treasury_or_gold = tiny_treasury_or_gold_value
		add_prestige = minor_prestige_gain
		if = {
			limit = {
				NOR = {
					has_relation_potential_friend = scope:scrounger
					has_relation_friend = scope:scrounger
				}
				can_set_relation_potential_friend_trigger = { CHARACTER = scope:scrounger }
			}
			set_relation_potential_friend = scope:scrounger
		}
		else_if = {
			limit = {
				has_relation_potential_friend = scope:scrounger
				can_set_relation_friend_trigger = { CHARACTER = scope:scrounger }
			}
			set_relation_friend = { reason = friend_amusing_antics target = scope:scrounger }
		}
		scope:scrounger = {
			target_weight_modifier_effect = {
				VALUE = 2
			}
 		}
		trigger_event = {
			id = court_yearly.6041
			days = 180
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 0.5
				ai_sociability = 0.5
			}
			modifier = {
				treasury_or_gold <= tiny_treasury_or_gold_value
				add = -200
			}
		}
	}

	# Option C: kick them out of court
	option = {
		name = court.6040.c
		remove_courtier_or_guest = {
			character = scope:scrounger
		}
		if = {
			limit = {
				NOR = {
					has_relation_potential_rival = scope:scrounger
					has_relation_rival = scope:scrounger
				}
				can_set_relation_potential_rival_trigger = { CHARACTER = scope:scrounger }
			}
			set_relation_potential_rival = scope:scrounger
		}
		else_if = {
			limit = {
				has_relation_potential_rival = scope:scrounger
				can_set_relation_rival_trigger = { CHARACTER = scope:scrounger }
			}
			set_relation_rival = {
				target = scope:scrounger
				reason = rival_scrounger_kicked_out_of_court
			}
		}
		add_stress = medium_stress_loss
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = -0.5
				ai_greed = 0.25
			}
		}
	}
}

court_yearly.6041 = {
	type = character_event
	title = court.6040.t
	desc = court.6041.desc
	theme = court
	left_portrait = {
		character = root
		animation = admiration
	}
	right_portrait = {
		character = scope:scrounger
		animation = happiness
	}

	trigger = {
		has_royal_court = yes
		has_dlc_feature = royal_court
		exists = scope:scrounger #checking that they are still alive
		scope:scrounger = { is_alive = yes }
	}

	immediate = {
		#poet trait is required for court poet position
		hidden_effect = {
			scope:scrounger = { 
				if = {
					limit = {
						NOT = { has_trait = lifestyle_poet }  
					}
					add_trait = lifestyle_poet
				}
			}
		}
		if = {
			limit = {
				employs_court_position = court_poet_court_position
				any_court_position_holder = {
					type = court_poet_court_position
				}
			}
			random_court_position_holder = {
				type = court_poet_court_position
				save_scope_as = c_poet
			}
		}
	}

	# Option A:
	option = {
		name = court.6041.a
		if = {
			limit = {
				exists = scope:c_poet
			}
			revoke_court_position = {
				recipient = scope:c_poet
				court_position = court_poet_court_position
			}
		}
		employ_character_as_position_in_current_scope_court_effect = { 
	        CHARACTER = scope:scrounger 
	        POSITION = court_poet
	    }
	    ai_chance = {
			base = 40
			modifier = {
				add = 15
				can_employ_court_position_type = court_poet_court_position
			}
			modifier = {
				add = -25
				short_term_gold < minor_gold_value
			}
		} 
	}

	# Option B:
	option = {
		name = court.6041.b
		remove_short_term_gold = medium_gold_value
		scope:scrounger = {
			duel = {
				skill = diplomacy
				value = average_skill_rating
				50 = {
					desc = court.6041.b.failure
					compare_modifier = {
						value = scope:duel_value
						multiplier = -2
					}
					root = {
						send_interface_toast = {
							type = event_toast_effect_bad
							title = court.6041.b.failure.tt
							left_icon = scope:scrounger
							stress_impact = {
								ambitious = medium_stress_impact_gain
							}
						}
					}
				}
				10 = {
					desc = court.6041.b.success
					compare_modifier = {
						value = scope:duel_value
						multiplier = 2
					}
					create_inspiration = book_inspiration
					custom_tooltip = inspire_interaction_book
					root = {
						send_interface_toast = {
							type = event_toast_effect_good
							title = court.6041.b.success.tt
							left_icon = scope:scrounger
						}
					}
				}
			}
		}

		ai_chance = {
			base = 40
			modifier = {
				add = 15
				OR = {
					has_trait = ambitious
					has_trait = diligent
				}
			}
			modifier = {
				add = -25
				short_term_gold < medium_gold_value
			}
		}
	}

	# Option C: No further investment
	option = {
		name = court.6041.c
		scope:scrounger = {
			add_opinion = {
				modifier = disappointed_opinion
				target = root
				opinion = -20
			}
		}

		ai_chance = {
			base = 50
			modifier = {
				add = 15
				has_trait = greedy
			}
			modifier = {
				add = 25
				short_term_gold < medium_gold_value
			}
		}
	}
}

#####################################
# Lonely Days		 				#
# by Linnéa Thimrén					#
#####################################

#Your Friend is struggling with feeling isolated/lonely due to your official duties, make time for them or find other ways to make them feel better
scripted_trigger court_5001_basic_friend_trigger = {
	is_courtier_of = root
	is_available_ai = yes
}

scripted_trigger court_5001_basic_marriage_trigger = {
	is_married = no
	is_adult = yes
	is_betrothed = no
	can_marry_trigger = yes
	is_concubine = no
}

court_yearly.5001 = {
	type = character_event
	title = court.5001.t
	desc = court.5001.desc
	theme = court
	left_portrait = {
		character = scope:friend
		animation = sadness
	}
	right_portrait = {
		character = scope:match_for_friend
		animation = flirtation_left
	}
	
	trigger = {
		has_royal_court = yes
		has_dlc_feature = royal_court
		NOT = { has_character_flag = had_event_court_5001 }
		any_relation = {
			type = friend
			court_5001_basic_friend_trigger = yes
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = 0.25
			any_relation = { #More likely if they have no cool minor titles
				type = friend
				court_5001_basic_friend_trigger = yes
				has_any_court_position = no
			}
		}
		modifier = {
			add = 0.25
			any_relation = { #Slightly more likely if you have a pet companion and they don't
				type = friend
				court_5001_basic_friend_trigger = yes
				root = {
					has_cat_or_dog_trigger = yes
				}
				has_cat_or_dog_trigger = no
			}
		}

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

	immediate = {
		add_character_flag = {
			flag = had_event_court_5001
			years = 10
		}
		random_relation = {
			type = friend
			limit = {
				court_5001_basic_friend_trigger = yes
			}
			weight = {
				base = 1
				modifier = {
					add = -1
					has_any_court_position = yes
				}
				modifier = { #More likely to pick an unmarried friend
					add = 1
					court_5001_basic_marriage_trigger = yes
					save_temporary_scope_as = friend_check
					root = {
						any_courtier = {
							this != scope:friend_check
							court_5001_basic_marriage_trigger = yes
							can_marry_character_trigger = { CHARACTER = scope:friend_check }
							scope:friend_check = { is_attracted_to_gender_of = prev }
						}
					}
				}
			}
			save_scope_as = friend
		}

		#Is there anyone for them to marry?
		if = {
			limit = {
				scope:friend = {
					court_5001_basic_marriage_trigger = yes
				}
				any_courtier = {
					this != scope:friend
					court_5001_basic_marriage_trigger = yes
					can_marry_character_trigger = { CHARACTER = scope:friend }
					scope:friend = { is_attracted_to_gender_of = prev }
				}
			}
			random_courtier = {
				limit = {
					this != scope:friend
					court_5001_basic_marriage_trigger = yes
					can_marry_character_trigger = { CHARACTER = scope:friend }
					scope:friend = { is_attracted_to_gender_of = prev }
				}
				weight = {
					base = 1
					opinion_modifier = {
						opinion_target = scope:friend
						multiplier = 1
					}
					modifier = { #More likely if they're openly lovers
						add = 10
						has_relation_lover = scope:friend
						NOT = { has_secret_relation_lover = scope:friend }
					}
					modifier = { #Always a plus if your partner is into you
						is_attracted_to_gender_of = scope:friend
						add = 5
					}
					modifier = { #Let's aim for a similar age
						OR = {
							age < scope:friend.age_plus_10
							age > scope:friend.age_minus_10
						}
						add = 2
					}
				}
				save_scope_as = match_for_friend
			}
		}


		#Can you gift them a cat/dog? We check this here so we keep the story used in script consistent even if they have both a cat and a dog
		if = {
			limit = {
				has_cat_or_dog_trigger = yes
				scope:friend = {
					has_cat_or_dog_trigger = no
				}
			}
			random_owned_story = {
				limit = {
					OR = {
						story_type = story_cycle_pet_dog
						story_type = story_cycle_pet_cat
					}
				}
				save_scope_as = story
			}
		}

		if = {
			limit = {
				scope:friend = { has_any_court_position = no }
				character_can_be_employed_in_a_court_position_trigger = {
					CHARACTER = scope:friend
				}
			}
			mark_court_position_for_employment_effect = {
				CHARACTER = scope:friend
			}
		}
	}

	option = { #Make time for them
		name = court.5001.a

		#Lose some court grandeur.
		change_current_court_grandeur = minor_court_grandeur_loss

		scope:friend = {
			add_opinion = {
				target = root
				modifier = friendliness_opinion
				opinion = 20
			}
		}
		if = {
			limit = {
				can_set_relation_best_friend_trigger = { CHARACTER = scope:friend }
			}
			set_relation_best_friend = { reason = best_friend_make_time copy_reason = friend target = scope:friend }
		}
	}

	option = { #Marry them off
		name = court.5001.b
		trigger = {
			exists = scope:match_for_friend
		}
		scope:friend = {
			marry = scope:match_for_friend
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 20
			}
		}
	}
	
	option = { #Gift them your dog/cat
		name = {
			trigger = {
				scope:story = { story_type = story_cycle_pet_dog }
			}
			text = court.5001.c_dog
		}
		name = {
			trigger = {
				scope:story = { story_type = story_cycle_pet_cat }
			}
			text = court.5001.c_cat
		}
		trigger = {
			exists = scope:story
		}

		if = {
			limit = {
				scope:story = { story_type = story_cycle_pet_dog }
			}
			transfer_dog_story_cycle_to_effect = {
				CHARACTER = scope:friend
				STORY = scope:story
			}
		}
		else = {
			transfer_cat_story_cycle_to_effect = {
				CHARACTER = scope:friend
				STORY = scope:story
			}
		}

		scope:friend = {
			if = {
				limit = { #"What am I supposed to do with this??"
					OR = {
						has_personality_malicious_trigger = yes
						AND = {
							scope:story = { story_type = story_cycle_pet_cat }
							has_character_modifier = cat_story_allergy_modifier
						}
						AND = {
							scope:story = { story_type = story_cycle_pet_dog }
							faith = { religion_tag = islam_religion }
						}
					}
				}
				add_opinion = {
					target = root
					modifier = dumped_animal_on_me_opinion
				}
			}
			else = {
				add_opinion = {
					target = root
					modifier = grateful_opinion
					opinion = 15
				}
			}
		}
	}

	option = { #Give them a minor title
		name = court.5001.d
		trigger = {
			exists = scope:court_position_to_fill
		}
		employ_character_as_marked_court_position_effect = { 
			CHARACTER = scope:friend
			POSITION = scope:court_position_to_fill
	    }
		scope:friend = {
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 20
			}
		}
	}
}

#####################################
# The Haunting		 				#
# by Linnéa Thimrén					#
#####################################

# Family member died some time ago and is now rumored to haunt the place
court_yearly.5010 = {
	type = character_event
	title = court.5010.t
	desc = court.5010.desc
	theme = court
	override_background = {
		reference = corridor_night
	}
	left_portrait = {
		character = scope:family_member
		animation = sadness
	}
	
	trigger = {
		has_royal_court = yes
		has_dlc_feature = royal_court
		is_ai = no
		location = {
			exists = var:possible_haunting
			var:possible_haunting = { #The place belongs to the family of the deceased
				OR = {
					any_close_family_member = {
						this = root
					}
					any_spouse = {
						this = root
					}
					is_grandparent_of = root
					is_great_grandparent_of = root
				}
			}
		}
	}

	weight_multiplier = {
		base = 0.5
		modifier = { #More likely if the death was gruesome
			add = 0.75
			location = {
				var:possible_haunting = {
					had_gruesome_death_trigger = yes
				}
			}
		}

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

	immediate = {
		location = {
			var:possible_haunting = {
				save_scope_as = family_member
			}
			remove_variable = possible_haunting
		}
	}

	option = { #Dismiss their fears and denounce their superstition
		name = court.5010.a
		trigger = {
			faith = {
				NOR = {
					has_doctrine = tenet_ancestor_worship
					has_doctrine = tenet_adorcism
				}
			}
		}
		if = {
			limit = {
				capital_county = {
					NOT = { has_county_modifier = county_dismissed_servants_fear_modifier }
				}
			}
			capital_county = {
				add_county_modifier = {
					modifier = county_dismissed_servants_fear_modifier
					days = 3650
				}
			}
		}
		add_piety = minor_piety_gain
	}

	option = { #Encourage them to be respectful and leave the ghost be
		name = court.5010.b
		trigger = {
			faith = {
				OR = {
					has_doctrine = tenet_ancestor_worship
					has_doctrine = tenet_adorcism
				}
			}
		}
		if = {
			limit = {
				capital_county = {
					NOT = { has_county_modifier = county_dismissed_servants_fear_modifier }
				}
			}
			capital_county = {
				add_county_modifier = {
					modifier = county_dismissed_servants_fear_modifier
					days = 3650
				}
			}
		}
		add_piety = minor_piety_gain
	}

	option = { #Hire someone to investigate and banish the ghost
		name = court.5010.c
		if = {
			limit = {
				capital_county = {
					NOT = { has_county_modifier = county_acknowledged_servants_fear_modifier }
				}
			}
			capital_county = {
				add_county_modifier = {
					modifier = county_acknowledged_servants_fear_modifier
					days = 3650
				}
			}
		}
		remove_short_term_gold = minor_gold_value
		if = {
			limit = {
				exists = cp:councillor_court_chaplain
			}
			cp:councillor_court_chaplain = {
				add_opinion = {
					target = root
					modifier = impious_opinion
					opinion = -20
				}
			}
		}
	}
}

#####################################
# Pillow Talk                       #
# by Linnéa Thimrén					#
#####################################

# Your cat has claimed a courtier's bed
court_yearly.5020 = {
	type = character_event
	title = court.5020.t
	desc = court.5020.desc
	theme = court
	left_portrait = {
		character = scope:courtier
		animation = anger
	}
	
	trigger = {
		has_royal_court = yes
		has_dlc_feature = royal_court
		NOT = { has_character_flag = had_event_court_5020 }
		any_owned_story = {
			type = story_cycle_pet_cat
		}
		any_courtier = {
			is_available_ai_adult = yes
		}
	}

	weight_multiplier = {
		base = 0.5
		modifier = { #More likely if you have a (potential)rival to irritate
			add = 0.75
			any_courtier = {
				OR = {
					has_relation_rival = root
					has_relation_potential_rival = root
				}
			}
		}

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

	immediate = {
		add_character_flag = {
			flag = had_event_court_5020
			years = 10
		}
		random_courtier = {
			weight = { #More likely if you dislike each other
				opinion_modifier = {
					opinion_target = root
					multiplier = -0.5
				}
				modifier = {
					add = 5
					OR = {
						has_relation_rival = root
						has_relation_potential_rival = root
					}
				}
				ai_value_modifier = {
					ai_boldness = 0.75
				}
			}
			save_scope_as = courtier
		}
		random_owned_story = {
			type = story_cycle_pet_cat
			save_scope_as = story
		}
	}

	option = { #It's the cat's pillow now
		name = court.5020.a
		if = {
			limit = {
				NOT = { has_relation_rival = scope:courtier }
			}
			progress_towards_rival_effect = {
				REASON = rival_deposed_for_cat
				CHARACTER = scope:courtier
				OPINION = default_rival_opinion
			}
		}
		else = {
			scope:courtier = {
				add_opinion = {
					target = root
					modifier = angry_opinion
					opinion = -20
				}
			}
		}
		#Might backfire...
		hidden_effect = {
			scope:courtier = {
				if = {
					limit = {
						ai_vengefulness >= medium_positive_ai_value
					}
					random = {
						chance = 20
						ai_value_modifier = {
							ai_vengefulness = 1
							ai_compassion = -0.5
						}
						root = {
							trigger_event = {
								id = court_yearly.5021
								days = { 50 100 }
							}
						}
					}
				}
			}
		}
	}

	option = { #I'll handle it
		name = court.5020.b
		scope:courtier = {
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 20
			}
		}
		#Might backfire... Cat runs away
		hidden_effect = {
			random = {
				chance = 20
				add_character_flag = cat_is_dying #Just so no other cat-events trigger in the meantime
				trigger_event = {
					id = pet_animal.0197
					days = { 50 100 }
				}
			}
		}
	}
}

#The courtier killed the cat
court_yearly.5021 = {
	type = character_event
	title = court.5020.t
	desc = {
		desc = court.5021.desc
		triggered_desc = { #The things we do for bad jokes...
			trigger = {
				var:story_cycle_cat_name = flag:cat_name_mittens
			}
			desc = court.5021.desc_mittens
		}
	}
	theme = court
	left_portrait = {
		character = scope:courtier
		animation = happiness
	}
	
	trigger = {
		has_royal_court = yes
		has_dlc_feature = royal_court
		exists = scope:story
		scope:courtier = {
			is_alive = yes
			is_courtier_of = root
		}
	}

	immediate = {
		show_as_tooltip = {
			remove_cat_story_modifiers_effect = yes
		}
		scope:courtier = {
			hidden_effect = {
				add_character_modifier = {
					modifier = cat_story_fur_mittens_modifier
					years = 10
				}
			}
		}
	}

	option = {
		name = {
			trigger = {
				var:story_cycle_cat_name = flag:cat_name_mittens
			}
			text = court.5021.a_mittens
		}
		name = {
			trigger = {
				NOT = { var:story_cycle_cat_name = flag:cat_name_mittens }
			}
			text = court.5021.a
		}
	}

	option = { #Throw them in jail!
		name = court.5021.b
		imprison_character_effect = {
			TARGET = scope:courtier
			IMPRISONER = root
		}
	}

	option = { #Give them a similar fate
		name = court.5021.c
		execute_prisoner_effect = {
			VICTIM = scope:courtier
			EXECUTIONER = root
		}
	}

	after = {
		scope:story = {
			hidden_effect = { end_story = yes }
		}
	}
}

#####################################
# The Ballad of the Garlic King		#
# by Claudia Baldassi				#
# 6030								#
#####################################

# The adventures of a foolish ruler have become really popular among wandering minstrels. The king of the story looks too much like you for comfort. #

scripted_trigger court_6030_valid_courtier_trigger = {
	is_available_ai_adult = yes
	OR = {
		has_relation_rival = root
		opinion = {
			target = root
			value < 0
		}
		has_trait = intellect_bad
		has_trait = dull
	}
}

court_yearly.6030 = {
	type = character_event
	title = court.6030.t
	desc = court.6030.desc
	theme = court
	left_portrait = {
		character = root
		animation = anger
	}
	right_portrait = {
		character = scope:6030_courtier
		animation = happiness
	}

	trigger = {
		has_royal_court = yes
		has_dlc_feature = royal_court
		highest_held_title_tier >= tier_kingdom
		is_adult = yes
		NOT = {
			has_character_flag = court_6030_cooldown
		}
		any_courtier_or_guest = {
			court_6030_valid_courtier_trigger = yes
		}
	}

	weight_multiplier = {
		base = 0.8

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

	immediate = {
		add_character_flag = court_6030_cooldown
		random_courtier_or_guest = {
			limit = {
				court_6030_valid_courtier_trigger = yes
			}
			save_scope_as = 6030_courtier
		}
	}

	# Option F: I don't care
	option = {
		name = court.6030.f
		if = {
			limit = {
				NOT = {
					has_trait = reclusive
				}
			}
			add_stress = medium_stress_gain
		}
		random = {
			chance = 15
			if = {
				limit = {
					is_female = yes
				}
				give_nickname = nick_garlic_queen
			}
			else = {
				give_nickname = nick_the_garlic
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_energy = -0.5
				ai_sociability = -0.5
			}
			modifier = {
				has_trait = reclusive
				add = 25
			}
		}
	}

	# Option D: prohibit and arrest
	option = {
		name = court.6030.d
		custom_tooltip = court.6030.d.tt
		trigger = {
			OR = {
				has_trait = wrathful
				has_trait = vengeful
				has_trait = callous
				has_trait = irritable
				has_trait = arrogant
			}
		}
		imprison = {
			target = scope:6030_courtier
			type = dungeon
		}
		add_prestige = minor_prestige_gain
		add_dread = major_dread_gain
		every_courtier_or_guest = {
			custom = court_6000_all_courtiers_and_guests
			add_opinion = {
				target = root
				modifier = scared_opinion
				opinion = -20
			}
		}
		stress_impact = {
			just = medium_stress_impact_gain
			gregarious = medium_stress_impact_gain
			shy = medium_stress_impact_gain
			craven = medium_stress_impact_gain
			humble = medium_stress_impact_gain
			compassionate = major_stress_impact_gain
			forgiving = major_stress_impact_gain		
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_vengefulness = 0.5
				ai_energy = 0.25
			}
			modifier = {
				has_trait = just
				add = -25
			}
			modifier = {
				has_trait = gregarious
				add = -25
			}
			modifier = {
				has_trait = shy
				add = -25
			}
			modifier = {
				has_trait = craven
				add = -25
			}
			modifier = {
				has_trait = humble
				add = -25
			}
			modifier = {
				has_trait = compassionate
				add = -50
			}
		}
	}

	# Option A: laugh it off
	option = {
		name = court.6030.a
		trigger = {
			OR = {
				has_trait = gregarious
				has_trait = forgiving
				has_trait = humble
			}
			NOR = {
				has_trait = shy
				has_trait = depressed_1
				has_trait = depressed_genetic
				has_trait = craven
				has_trait = reclusive
			}
		}
		every_courtier_or_guest = {
			custom = court_6000_all_courtiers_and_guests
			add_opinion = {
				target = root
				modifier = amused_opinion
				opinion = 10
			}
		}
		add_stress = medium_stress_loss
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_sociability = 1
			}
		}
	}

	# Option B: this is so humiliating...
	option = {
		name = court.6030.b
		trigger = {
			OR = {
				has_trait = shy
				has_trait = depressed_1
				has_trait = depressed_genetic
				has_trait = craven
				has_trait = reclusive
			}
			NOR = {
				has_trait = gregarious
				has_trait = forgiving
				has_trait = humble
			}
		}
		add_prestige = medium_prestige_loss
		random = {
			chance = 15
			if = {
				limit = {
					is_female = yes
				}
				give_nickname = nick_garlic_queen
			}
			else = {
				give_nickname = nick_the_garlic
			}
		}
		every_courtier_or_guest = {
			custom = court_6000_all_courtiers_and_guests
			add_opinion = {
				target = root
				modifier = amused_opinion
				opinion = 15
			}
		}
		add_stress = medium_stress_gain
		ai_chance = {
			base = 80
			ai_value_modifier = {
				ai_sociability = -1
			}
		}
	}

	# Option C: lash out at your court
	option = {
		name = court.6030.c
		trigger = {
			OR = {
				has_trait = wrathful 
				has_trait = irritable
				has_trait = arbitrary
				has_trait = vengeful
				has_trait = callous
			}
		}
		add_dread = medium_dread_gain	
		every_courtier_or_guest = {
			custom = court_6000_all_courtiers_and_guests
			add_opinion = {
				target = root
				modifier = scared_opinion
				opinion = -10
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_energy = 0.25
				ai_vengefulness = 0.5
			}
		}
	}

	# Option E: heads will roll...
	option = {
		name = court.6030.e
		trigger = {
			OR = {
				has_trait = wrathful
				has_trait = sadistic
				has_trait = torturer
				has_trait = vengeful
				has_trait = giant
				has_trait = physique_good
				has_trait = berserker
			}
		}
		custom_tooltip = court.6030.e.tt
		random_list = {
			20 = {
				scope:6030_courtier = {
					death = {
						death_reason = death_beaten
						killer = root
					}
				}
			}
			50 = {
				scope:6030_courtier = {
					increase_wounds_effect = { REASON = beaten }
				}
			}
			30 = {
				progress_towards_rival_effect = {
					REASON = rival_punched_for_song
					CHARACTER = scope:6030_courtier
					OPINION = -30
				}
				reverse_add_opinion = {
					target = scope:6030_courtier
					modifier = scared_opinion
					opinion = -50
				}
			}
		}
		every_courtier_or_guest = {
			custom = court_6000_all_courtiers_and_guests
			add_opinion = {
				target = root
				modifier = scared_opinion
				opinion = -25
			}
		}
		stress_impact = {
			eccentric = medium_stress_impact_loss
			shy = major_stress_impact_gain
			compassionate = major_stress_impact_gain
			patient = major_stress_impact_gain
		}
		add_dread = major_dread_gain
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_vengefulness = 1
				ai_rationality = -0.5
			}
		}
	}	
}

#########################
# Captured Beast
# by George Luff
#########################

scripted_trigger court_7100_huntsmaster_trigger = {
	has_court_position = master_of_hunt_court_position
	is_available_healthy_ai_adult = yes
}

scripted_effect court_7100_animal_bonus_effect = {
	# Gains modifier based on animal
	if = {
		limit = {
			scope:captured_animal = flag:wolf
		}
		add_character_modifier = {
			modifier = exotic_pet_wolf
			years = 10
		}
	}
	else_if = {
		limit = {
			scope:captured_animal = flag:bear
		}
		add_character_modifier = {
			modifier = exotic_pet_bear
			years = 10
		}
	}
	else_if = {
		limit = {
			scope:captured_animal = flag:lion
		}
		add_character_modifier = {
			modifier = exotic_pet_lion
			years = 10
		}
	}
	else_if = {
		limit = {
			scope:captured_animal = flag:tiger
		}
		add_character_modifier = {
			modifier = exotic_pet_tiger
			years = 10
		}
	}
}

### Exotic Animal event
court_yearly.7100 = {
	type = character_event
	title = court.7100.title
	desc = court.7100.desc
	theme = court
	left_portrait = {
		character = root
		animation = fear
	}
	right_portrait = {
		character = scope:huntmaster
		animation = personality_bold
	}

	cooldown = { years = 10 }

	weight_multiplier = {
		base = 1

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

	trigger = {
		has_royal_court = yes
		has_dlc_feature = royal_court
		# Has Master of the Hunt employed
		any_court_position_holder = {
			court_7100_huntsmaster_trigger = yes
		}

		# Does not already have an exotic pet
		NOR = {
			has_character_modifier = exotic_pet_wolf
			has_character_modifier = exotic_pet_bear
			has_character_modifier = exotic_pet_lion
			has_character_modifier = exotic_pet_tiger
		}
	}

	immediate = {
		# Decide on which animal it is
		random_list = {
			25 = { # Wolf
				save_scope_value_as = {
					name = captured_animal
					value = flag:wolf
				}
			}

			25 = { # Bear
				# Not outside of Europe or Asian black bear territory
				modifier = {
					factor = 0
					location = { 
						NOR = {
							geographical_region = world_europe
							geographical_region = world_tibet
							geographical_region = world_himalaya
							geographical_region = world_burma
							geographical_region = world_middle_east_persia
							geographical_region = world_asia_china
							geographical_region = world_asia_japan
							geographical_region = world_asia_korea
							geographical_region = world_asia_southeast
						}
					}
				}
				save_scope_value_as = {
					name = captured_animal
					value = flag:bear
				}
			}

			25 = { # Lion
				# Not outside of Africa
				modifier = {
					factor = 0
					location = { 
						NOT = { geographical_region = world_africa }
					}
				}
				save_scope_value_as = {
					name = captured_animal
					value = flag:lion
				}
			}

			25 = { # Tiger
				# Not outside of India or Asia
				modifier = {
					factor = 0
					location = {
						NOR = {
							geographical_region = world_india
							geographical_region = world_tibet
							geographical_region = world_himalaya
							geographical_region = world_burma
							geographical_region = world_asia_china
							geographical_region = world_asia_korea
							geographical_region = world_asia_southeast
						}
					}
				}
				save_scope_value_as = {
					name = captured_animal
					value = flag:tiger
				}
			}
		}

		# Save the Master of the Hunt in scope
		random_court_position_holder = {
			limit = {
				court_7100_huntsmaster_trigger = yes
			}
			save_scope_as = huntmaster
		}
	}

	# Dispose of it immediately!
	option = { 
		name = court.7100.a
		custom_tooltip = court.7100.a.tt

		scope:huntmaster = {
			add_opinion = {
				modifier = rejected_gift_opinion
				target = root
				opinion = -20
			}
		}

		stress_impact = {
			brave = medium_stress_impact_gain
		}
	}

	# I shall keep it as a pet!
	option = { 
		name = court.7100.b
		stress_impact = {
			craven = medium_stress_impact_gain
		}
		random = {
			chance = 75
			modifier = {
				add = {
					value = prowess
					multiply = -1
					multiply = 2.5
					min = -50
				}
			}
			increase_wounds_no_death_effect = { REASON = wild_animal }
		}
		court_7100_animal_bonus_effect = yes
	}

	# You can keep it!
	option = {
		name = court.7100.c

		scope:huntmaster = {
			add_opinion = {
				modifier = disappointed_opinion
				target = root
				opinion = -10
			}
			random = {
				chance = 75
				modifier = {
					add = {
						value = scope:huntmaster.prowess
						multiply = -1
						multiply = 2.5
						min = -50
					}
				}
				increase_wounds_no_death_effect = { REASON = wild_animal }
			}	
			court_7100_animal_bonus_effect = yes
		}
	}
}

#########################
# Loud and Proud
# by George Luff
#########################

scripted_trigger court_7200_court_musician_trigger = {
	has_court_position = court_musician_court_position
	is_available_healthy_ai_adult = yes
}

## Musician won't stop making noise
court_yearly.7200 = {
	type = character_event
	title = court.7200.title
	desc = {
		desc = court.7200.intro.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					has_character_flag = court_7200_drum
				}
				desc = court.7200.drum.desc
			}
			triggered_desc = {
				trigger = {
					has_character_flag = court_7200_trombone
				}
				desc = court.7200.trombone.desc
			}
			triggered_desc = {
				trigger = {
					has_character_flag = court_7200_pipes
				}
				desc = court.7200.pipes.desc
			}
			triggered_desc = {
				trigger = {
					has_character_flag = court_7200_guitar
				}
				desc = court.7200.guitar.desc
			}
		}
		desc = court.7200.outro.desc
	}
	theme = court
	left_portrait = {
		character = root
		animation = worry
	}
	right_portrait = {
		character = scope:loud_musician
		animation = happiness
	}

	cooldown = { years = 5 }

	weight_multiplier = {
		base = 1

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

	trigger = {
		has_royal_court = yes
		has_dlc_feature = royal_court
		# Employs a Court Musician
		any_court_position_holder = {
			court_7200_court_musician_trigger = yes
		}
	}

	immediate = {
		# Select court musician
		random_court_position_holder = {
			limit = {
				court_7200_court_musician_trigger = yes
			}
			save_scope_as = loud_musician
		}
		random_list = {
			25 = {
				add_character_flag = court_7200_drum
			}
			25 = {
				add_character_flag = court_7200_trombone
			}
			25 = {
				add_character_flag = court_7200_pipes
			}
			25 = {
				add_character_flag = court_7200_guitar
			}
		}
	}

	# Persuade the musician to keep to a curfew on the racket
	option = {
		name = court.7200.a

		stress_impact = {
			sadistic = medium_stress_impact_gain
		}

		every_courtier_or_guest = {
			custom = all_courtiers_and_guests
			limit = {
				this != scope:loud_musician
			}
			add_opinion = {
				modifier = angry_opinion
				target = root
				opinion = -10
			}
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_rationality = 10
				ai_vengefulness = -10
			}
		}
	}

	# Strip them of their position
	option = {
		name = court.7200.b

		stress_impact = {
			arbitrary = medium_stress_impact_loss
		}

		revoke_court_position = {
			court_position = court_musician_court_position
			recipient = scope:loud_musician
		}

		scope:loud_musician = {
			add_opinion = {
				modifier = angry_opinion
				target = root
				opinion = -15
			}
		}

		add_character_modifier = {
			modifier = fired_court_position
			years = 5
		}

		every_courtier_or_guest = {
			limit = {
				this != scope:loud_musician
			}
			custom = all_courtiers_and_guests
			add_opinion = {
				modifier = grateful_opinion
				target = root
				opinion = 25
			}
		}
	}

	# Just knock it off, okay?
	option = {
		name = court.7200.c
		stress_impact = {
			calm = medium_stress_impact_gain
			wrathful = medium_stress_impact_loss
		}

		scope:loud_musician = {
			add_opinion = {
				target = root
				modifier = cruelty_opinion
				opinion = -20
			}
		}
		every_courtier_or_guest = {
			limit = {
				this != scope:loud_musician
			}
			custom = all_courtiers_and_guests
			add_opinion = {
				modifier = grateful_opinion
				target = root
				opinion = 15
			}
		}
	}
}

# Court event 7030 - Foreign Merchants wish to establish a merchant quarter
court_yearly.7030 = {
	type = character_event
	title = court.7030.title
	desc = court.7030.desc
	theme = court

	cooldown = { years = 20 }
	left_portrait = {
		character = scope:foreign_merchant
		animation = personality_rational
	}
	right_portrait = {
		character = scope:steward
		animation = disapproval
	}

	trigger = {
		has_royal_court = yes
		has_dlc_feature = royal_court
		exists = cp:councillor_steward
		cp:councillor_steward = {
			is_available_ai_adult = yes
		}
		any_character_to_title_neighboring_and_across_water_county = {
			NOT = {
				culture = { this = root.culture }
			}
		}
	}

	immediate = {
		# Save foreign county as scope
		random_character_to_title_neighboring_and_across_water_county = {
			limit = {
				NOT = {
					culture = { this = root.culture }
				}
			}
			save_scope_as = merchant_county
		}

		cp:councillor_steward = {
			save_scope_as = steward
		}

		## Create Merchant
		create_character = {
			template = foreign_merchant_template
			location = root.capital_province
			save_scope_as = foreign_merchant
		}
	}

	option = { # Establish merchant quarter, cultural acceptance
		name = court.7030.a
		root.culture = {
			change_cultural_acceptance = {
				target = scope:foreign_merchant.culture
				value = major_cultural_acceptance_gain
				desc = cultural_acceptance_foreign_merchants
			}
		}

		root.capital_county = {
			add_county_modifier = {
				modifier = foreign_merchant_community
				years = 20
			}
		}

		stress_impact = {
			arrogant = minor_stress_gain
		} 

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_sociability = 0.2
				ai_greed = 0.5
			}

		}
	}

	option = { # Expand the mercantile district for everyone
		name = court.7030.c
		trigger = {
			capital_county = {
				title_province = {
					OR = {
						AND = {
							building_common_tradeport_requirement_terrain = yes
							NOT = { has_building = common_tradeport_08 }
						}
						AND = {
							has_building_or_higher = city_01
							NOT = { has_building = guild_halls_08 }
						}
					}
				}
			}
		}

		remove_treasury_or_gold = medium_treasury_or_gold_value

		if = {
			limit = {
				root.capital_county = {
					title_province = {
						building_common_tradeport_requirement_terrain = yes
					}
				}
			}
			root.capital_county = {
				title_province = {
					upgrade_tradeport = yes
				}
			}
		}
		else_if = {
			limit = {
				root.capital_county = {
					title_province = {
						has_building_or_higher = city_01
					}
				}
			}
			root.capital_county = {
				title_province = {
					upgrade_guildhall = yes
				}
			}
		}

		ai_chance = {
			base = 20
			ai_value_modifier = {
				ai_greed = -0.5
				ai_rationality = 0.2
			}
		}

		stress_impact = {
			greedy = medium_stress_gain
		}
	}

	option = { # Ban the foreigners!
		name = court.7030.d
		custom_tooltip = court.7030.d.tt
		add_treasury_or_gold = medium_treasury_or_gold_value
		scope:foreign_merchant = {
			show_as_tooltip = {
				banish = yes
			}
			silent_disappearance_effect = yes
		}
		
		root.culture = {
			change_cultural_acceptance = {
				target = scope:foreign_merchant.culture
				value = major_cultural_acceptance_loss
				desc = cultural_acceptance_foreigners_expelled
			}
		}

		ai_chance = {
			base = 20
			ai_value_modifier = {
				ai_zeal = 1
				ai_rationality = -1
				ai_greed = 1
				ai_compassion = -0.5
			}
		}

		stress_impact = {
			eccentric = minor_stress_impact_loss
			generous = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
			cynical = minor_stress_impact_gain
		}
	}
}

### One of your courtiers has started sitting on a pillar during the day

scripted_trigger court_7040_ascetic_religion_trigger = {
	faith = {
		OR = {
			religion_tag = christianity_religion
			religion_tag = buddhism_religion
			religion_tag = jainism_religion
			religion_tag = taoism_religion
			religion_tag = dualism_religion
			has_doctrine = tenet_asceticism
		}
	}
}

court_yearly.7040 = {
	type = character_event
	title = court.7040.title
	desc = court.7040.desc
	theme = court

	cooldown = { years = 10 }
	left_portrait = {
		character = root
		animation = throne_room_conversation_1
	}
	right_portrait = {
		character = scope:chaplain
		animation = disapproval
	}

	trigger = {
		has_royal_court = yes
		has_dlc_feature = royal_court
		NOT = { has_character_modifier = court_7040_ascetic_practices }
		# Must follow a faith that historically practised asceticism, or possess the asceticism tenet

		root = { court_7040_ascetic_religion_trigger = yes }
		# Courtier must be of the same faith as root

		any_courtier = {
			ep1_spare_courtier_trigger = yes
			faith = root.faith
		}

		# We need the court chaplain for narrative purposes
		exists = cp:councillor_court_chaplain
		cp:councillor_court_chaplain = {
			is_available_healthy_ai_adult = yes
		}
	}

	immediate = {
		# Select courtier
		random_courtier = {
			limit = {
				ep1_spare_courtier_trigger = yes
				faith = root.faith
			}
			add_trait = reclusive
			save_scope_as = ascetic
		}

		# Select the court chaplain
		cp:councillor_court_chaplain = {
			save_scope_as = chaplain
		}

		# Select religious head for option b
		if = {
			limit = {
				faith = {
					religious_head ?= {
						this != root
					}
				}
			}
			faith.religious_head = {
				save_scope_as = head_of_faith
			}
		}
	}

	option = { # Send them to the religious head, if they exist
		name = court.7040.b

		trigger = {
			exists = scope:head_of_faith
			exists = scope:head_of_faith.capital_province
		}

		remove_courtier_or_guest = { character = scope:ascetic new_location = scope:head_of_faith.capital_province }

		scope:head_of_faith = {
			add_opinion = {
				modifier = grateful_opinion
				target = root
				opinion = 25
			}
		}

		faith = {
			change_fervor = {
				value = 5
				desc = fervor_gain_ascetic_example
			}
		}

		ai_chance = {
			base = 40
			ai_value_modifier = {
				ai_zeal = 0.4
				ai_compassion = -0.2
			}
		}
	}

	option = { # Truly a pious individual, their example inspires me!
		name = court.7040.c

		add_character_modifier = {
			modifier = court_7040_ascetic_practices
			years = 10
		}

		stress_impact = {
			lazy = minor_stress_gain
			cynical = minor_stress_gain
		}
		ai_chance = {
			base = 40
			ai_value_modifier = {
				ai_zeal = 1
				ai_boldness = 0.5
				ai_honor = 0.5
			}
		}
	}

	option = { # If you want to live in isolation, do so somewhere else!
		name = court.7040.d

		add_piety = minor_piety_loss

		stress_impact = {
			zealous = medium_stress_gain
		}

		scope:ascetic = {
			show_as_tooltip = {
				banish = yes
			}
			silent_disappearance_effect = yes
		}
		
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_zeal = -1
				ai_compassion = -1
				ai_honor = -0.5
				ai_vengefulness = 1
			}
		}
	}

	option = { # Just ignore them, they'll get over it eventually.
		name = court.7040.a

		scope:chaplain = {
			add_opinion = {
				target = root
				modifier = ignored_concerns 
			}
		}

		add_piety = minor_piety_loss 

		stress_impact = {
			zealous = minor_stress_gain
			impatient = minor_stress_gain
		}

		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_zeal = -1
				ai_rationality = 1
				ai_compassion = 0.5
			}
		}
	}
}

########## Your caravans are attacked by rampaging Christian nobles!

court_yearly.4350 = {
	type = character_event
	title = court.4350.t
	desc = court.4350.desc
	theme = diplomacy_foreign_affairs_focus
	lower_left_portrait = {
		character = scope:caravan_attacker_liege
	}
	left_portrait = {
		character = root
		animation = personality_honorable
	}
	right_portrait = {
		character = scope:concerned_marshal
		animation = worry
	}
	
	trigger = {
		has_royal_court = yes
		has_dlc_feature = royal_court
		NOT = { has_character_flag = has_had_caravan_islamic_event }
		is_at_war = no
		religion = religion:islam_religion
		any_neighboring_realm_same_rank_owner = {
			is_landed = yes 
			OR = { religion = religion:eastern_orthodox_religion religion = religion:catholic_religion religion = religion:protestant_religion }
			in_diplomatic_range = root 
			liege != root
		}
		exists = root.cp:councillor_marshal
	}

	immediate = {
		add_character_flag = {
			flag = has_had_caravan_islamic_event
			days = 1825
		}
		cp:councillor_marshal = { save_scope_as = concerned_marshal }
		random_neighboring_realm_same_rank_owner = {
			limit = {
				is_landed = yes 
				OR = { religion = religion:eastern_orthodox_religion religion = religion:catholic_religion religion = religion:protestant_religion }
				in_diplomatic_range = root 
				liege != root
			}
			save_scope_as = caravan_attacker_liege
		}
		remove_treasury_or_gold = medium_treasury_or_gold_value
	}

	option = { 
		name = court.4350.a
		every_courtier_or_guest = {
			limit = {
				NOT = { has_trait = temperate }
			}
			custom = all_courtiers_and_guests
			add_opinion = {
				target = root
				modifier = given_luxuries_opinion
				opinion = 10
			}
		}
		scope:caravan_attacker_liege = {
			add_opinion = {
				target = root
				opinion = 40
				modifier = pleased_opinion
			}
			if = {
				limit = {
					NOR = {
						is_allied_to = root
						has_truce = root
					}	
				}
				add_truce_both_ways = {
					character = root
 					days = 1825
 					name = TRUCE_TRADE_DEAL
				}
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = 0.25
				ai_greed = 0.25
			}
		}
	}

	option = {
		name = court.4350.b
		add_dread = medium_dread_gain
		add_character_modifier = {
			modifier = leading_looting_modifier
			days = 1000
		}
		add_gold = minor_gold_value 
		scope:caravan_attacker_liege = {
			add_opinion = {
				target = root
				opinion = -40
				modifier = disappointed_opinion
			}
			every_vassal = {
				custom = all_vassals
				add_opinion = {
					target = root
					opinion = -40
					modifier = disappointed_opinion
				}
			}
		}
		scope:caravan_attacker_liege = {
			if = {
				limit = {
					OR = {
						is_allied_to = root
						has_truce = root
					}	
				}
				cancel_truce_both_ways = root
				break_alliance = root
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = 0.25
				ai_greed = 0.25
				ai_vengefulness = 0.5
			}
		}
	}
	option = {
		name = court.4350.c
		flavor = court.4350.c.tt
		add_dread = minor_dread_gain
		add_piety = minor_piety_gain
		scope:caravan_attacker_liege = {
			add_opinion = {
				target = root
				opinion = -20
				modifier = disappointed_opinion
			}
			this.capital_province = {
				add_province_modifier = {
					modifier = spurned_by_traders
					years = 10
				}
			}
			every_vassal = {
				custom = all_vassals
				add_opinion = {
					target = root
					opinion = -20
					modifier = disappointed_opinion
				}
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_vengefulness = 0.25
			}
		}
	}
}
### Reversed POV - one of our nobles attacked a trading caravan!
court_yearly.4355 = {
	type = character_event
	title = court.4355.t
	desc = court.4355.desc
	theme = diplomacy_foreign_affairs_focus
	left_portrait = {
		character = scope:reporting_marshal
		animation = personality_honorable
	}
	right_portrait = {
		character = scope:caravan_attacker
		animation = rage
	}
	lower_left_portrait = {
		character = scope:attacked_liege
	}
	
	trigger = {
		has_royal_court = yes
		has_dlc_feature = royal_court
		NOT = { has_character_flag = has_had_caravan_christian_event }
		is_at_war = no
		OR = { has_religion = religion:eastern_orthodox_religion has_religion = religion:catholic_religion has_religion = religion:protestant_religion } 
		any_neighboring_realm_same_rank_owner = {
			is_landed = yes
			religion = religion:islam_religion
			in_diplomatic_range = root 
			liege != root
		}
		any_powerful_vassal = {
			opinion = {
				target = root
				value <= medium_negative_opinion
			}
			age > 15
		}
		exists = root.cp:councillor_marshal
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		add_character_flag = {
			flag = has_had_caravan_christian_event
			days = 1825
		}
		cp:councillor_marshal = { save_scope_as = reporting_marshal }
		random_vassal = {
			limit = {
				opinion = {
				target = root
				value < 20
				}
				is_imprisoned = no
				age > 15
				is_ai = yes
			}
			weight = {
				base = 1
				modifier = {
					has_relation_rival = root
					factor = 20
				}
				modifier = {
					factor = 20
					is_powerful_vassal = yes
				}
			}
			save_scope_as = caravan_attacker
		}	
			 
		random_neighboring_realm_same_rank_owner = { 
			limit = { 
				is_landed = yes
				religion = religion:islam_religion
				in_diplomatic_range = root 
			}
			save_scope_as = attacked_liege
		}
	}

	option = { 
		name = court.4355.a
		flavor = court.4355.a.tt
		every_courtier_or_guest = {
			custom = all_courtiers_and_guests
			add_opinion = {
				target = root
				opinion = 10
				modifier = given_luxuries_opinion
			}
		}
		faith.religious_head = {
			add_opinion = {
				target = root
				opinion = 10
				modifier = pious_opinion
			}
		}
		scope:attacked_liege = {
			add_opinion = {
				target = root
				opinion = -40
				modifier = disappointed_opinion
			}
		}
		add_character_modifier = {
			modifier = leading_looting_modifier
			days = 1000
		}
		scope:attacked_liege = {
			if = {
				limit = {
					OR = {
						is_allied_to = root
						has_truce = root
					}	
				}
				cancel_truce_both_ways = root
			}
		}
		capital_province = {
			add_province_modifier = {
				modifier = spurned_by_traders
				years = 10
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_zeal = 0.5
			}
		}
	}

	option = {
		name = court.4355.b
		scope:caravan_attacker = {
			add_opinion = {
				target = root
				opinion = -40
				modifier = disappointed_opinion
			}
		}
		scope:attacked_liege = {
			add_opinion = {
				target = root
				opinion = 20
				modifier = respect_opinion
			}
			if = {
				limit = {
					NOR = {
						is_allied_to = root
						has_truce = root
					}	
				}
				add_truce_both_ways = {
					character = root
 					days = 1825
 					name = TRUCE_TRADE_DEAL
				}
			}
		}
		add_diplomacy_lifestyle_xp = major_lifestyle_xp
		add_dread = medium_dread_gain
		stress_impact = {
			sadistic = medium_stress_loss
			wrathful = medium_stress_loss
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_zeal = -0.5
			}
		}
	}
	
	option = {
		name = court.4355.c
		flavor = court.4355.c.tt
		stress_impact = {
			arbitrary = medium_stress_loss
			craven = medium_stress_loss
		}
		if = {
			limit = {
				scope:caravan_attacker = { has_relation_rival = root }
			}
			scope:caravan_attacker = { remove_relation_rival = root }
		}
		scope:caravan_attacker = {
			add_opinion = {
				target = root
				opinion = 20
				modifier = pleased_opinion
			}
		}
		capital_province = {
			add_province_modifier = {
				modifier = spurned_by_traders
				years = 10
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_zeal = 0.5
			}
		}
	}
}

court_yearly.4800 = {
	type = character_event
	title = court.4800.t
	desc = court.4800.desc
	cooldown = { years = 10 }
	theme = court
	trigger = {
		has_royal_court = yes
		has_dlc_feature = royal_court
		OR = {
			any_court_position_holder = {
				type = bodyguard_court_position
				is_available_ai_adult = yes
			}
			any_court_position_holder = {
				type = akolouthos_court_position
				is_available_ai_adult = yes
			}
		}
		
		OR = {
			AND = {
				employs_court_position = court_jester_court_position
				any_court_position_holder = {
					type = court_jester_court_position
					is_available_ai_adult = yes
				}
			}
			AND = {
				employs_court_position = keeper_of_swans_court_position
				any_court_position_holder = {
					type = keeper_of_swans_court_position
					is_available_ai_adult = yes
				}
			}
		}
	}
	left_portrait = {
		character = scope:defenestrated_character
		animation = flirtation
	}
	right_portrait = {
		character = scope:defenestrating_bodyguard
		animation = rage
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		if = {
			limit = {
				employs_court_position = bodyguard_court_position
			}
			random_court_position_holder = {
				type = akolouthos_court_position
				limit = {
					is_available_ai_adult = yes
				}
				save_scope_as = defenestrating_bodyguard
			}
		}
		else = {
			random_court_position_holder = {
				type = bodyguard_court_position
				limit = {
					is_available_ai_adult = yes
				}
				save_scope_as = defenestrating_bodyguard
			}
		}
		
		if = {
			limit ={
				employs_court_position = court_jester_court_position
				any_court_position_holder = {
					type = court_jester_court_position
					is_available_ai_adult = yes
				}
			}
			random_court_position_holder = {
				type = court_jester_court_position
				save_scope_as = defenestrated_character
			}
		}
		else = {
			random_court_position_holder = {
				type = keeper_of_swans_court_position
				save_scope_as = defenestrated_character
			}
		}
	}

	option = { 
		name = court.4800.a
		stress_impact = {
			compassionate = medium_stress_impact_gain
			just = medium_stress_impact_gain
			arbitrary = minor_stress_loss
			sadistic = minor_stress_loss
		}
		random_list = {
			10 = {
				scope:defenestrated_character = {
					increase_wounds_effect = { REASON = defenestration }
					apply_maimed_trait_and_modifier_effect = yes
					add_opinion = {
						target = root
						opinion = -20
						modifier = hate_opinion
					}
					add_opinion = {
						target = scope:defenestrating_bodyguard
						opinion = -40
						modifier = hate_opinion
					}
				}
				hidden_effect = {
					send_interface_toast = {
						type = event_toast_effect_neutral
						left_icon = scope:defenestrated_character
						title = court.4800.maimed_toast
						show_as_tooltip = {
							scope:defenestrated_character = {
								increase_wounds_effect = { REASON = defenestration }
								apply_maimed_trait_and_modifier_effect = yes
							}
						}
					}
				}
			}
			5 = {
				scope:defenestrated_character = {
					death = {
						death_reason = death_defenestration
						killer = scope:defenestrating_bodyguard
					}
				}
				hidden_effect = {
					send_interface_toast = {
						type = event_toast_effect_neutral
						left_icon = scope:defenestrated_character
						title = court.4800.death_toast
						show_as_tooltip = {
							scope:defenestrated_character = {
								death = {
									death_reason = death_defenestration
									killer = scope:defenestrating_bodyguard
								}
							}
						}
					}
				}
			}
		}
		add_dread = minor_dread_gain
		scope:defenestrating_bodyguard = {
			add_opinion = {
				target = root
				opinion = 10
				modifier = respect_opinion
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = -0.5
				ai_vengefulness = 0.5
				ai_boldness = 0.25
				ai_rationality = -0.5
			}
		}
	}

	option = {
		name = court.4800.b
		stress_impact = {
			compassionate = minor_stress_gain
			just = minor_stress_gain
			sadistic = miniscule_stress_impact_loss
		}
		scope:defenestrated_character = {
			increase_wounds_effect = { REASON = fight }
			add_opinion = {
				target = root
				opinion = -5
				modifier = scared_opinion
			}
			add_opinion = {
				target = scope:defenestrating_bodyguard
				opinion = -25
				modifier = scared_opinion
			}
		}
		scope:defenestrating_bodyguard = {
			add_opinion = {
				target = root
				opinion = 10
				modifier = respect_opinion
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = -0.25
				ai_vengefulness = 0.25
				ai_boldness = 0.25
				ai_rationality = -0.25
			}
		}
	}
	
	option = {
		name = court.4800.c
		if = {
			limit = {
				scope:defenestrating_bodyguard = {
					has_court_position = bodyguard_court_position
					
				}
			}
			revoke_court_position = {
				recipient = scope:defenestrating_bodyguard
				court_position = bodyguard_court_position
			}
		}
		else = {
			revoke_court_position = {
				recipient = scope:defenestrating_bodyguard
				court_position = akolouthos_court_position
			}
		}
		reverse_add_opinion = {
			target = scope:defenestrated_character
			opinion = 30
			modifier = grateful_opinion
		}
		reverse_add_opinion = {
			target = scope:defenestrating_bodyguard
			opinion = -30
			modifier = insulted_opinion
		}
		add_martial_lifestyle_xp = medium_lifestyle_xp
		add_prestige = minor_prestige_gain
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_rationality = 0.5
			}
		}
	}
}

#Rando criminal is spawned based on what your culture considers criminal/shunned
scripted_effect event_0101_spawn_criminal_effect = {
	create_character = {
		location = root.capital_province
		template = generic_peasant_character
		faith = root.capital_province.faith #Character is meant to be a random lowborn, should be the local faith/culture rather than ruling class
		culture = root.capital_province.culture
		save_scope_as = lowborn_criminal
	}
	scope:lowborn_criminal = {
		random_list = {
			10 = {
				modifier = {
					factor = 0
					root.faith = { has_doctrine_parameter = deviancy_accepted }
				}
				modifier = {
					factor = 0.5
					root.faith = { has_doctrine_parameter = deviancy_shunned }
				}
				add_trait = deviant
				save_scope_value_as = {
					name = criminal_trait
					value = flag:deviant_trait_flag
				}
			}
			10 = {
				add_trait = murderer
			}
			10 = {
				modifier = {
					factor = 0
					root.faith = { has_doctrine_parameter = witchcraft_accepted }
				}
				modifier = {
					factor = 0.5
					root.faith = { has_doctrine_parameter = witchcraft_shunned }
				}
				add_trait = witch
				save_scope_value_as = {
					name = criminal_trait
					value = flag:witch_trait_flag
				}
			}
			10 = {
				add_trait = lazy
			}
			10 = { #Dumb crimes that aren't trait-specific
				
			}
		}
	}
	if = {
		limit = {
			scope:lowborn_criminal = {
				has_trait = murderer
			}
		}
		scope:lowborn_criminal = {
			random_list = {
				10 = {
					add_trait = cannibal
					game_rule_create_spouse_and_children = { CHARACTER = scope:lowborn_criminal LOCATION = scope:lowborn_criminal }
					every_child  = {
						add_trait = cannibal
					}
					every_spouse  = {
						add_trait = cannibal
					}
					save_scope_value_as = {
						name = criminal_trait
						value = flag:cannibal_trait_flag
					}
				}
				10 = {
					add_trait = sadistic
					save_scope_value_as = {
						name = criminal_trait
						value = flag:sadistic_trait_flag
					}
				}
				10 = { #Holy man murderer
					modifier = {
						factor = 0
						NOT = { has_allowed_gender_for_clergy = scope:lowborn_criminal }
					}
					replace_with_learning_trait_effect = yes
					add_character_flag = {
						flag = need_priest_outfit
					}
				}
			}
		}
	}
	if = {
		limit = {
			scope:lowborn_criminal = {
				has_trait = deviant
			}
		}
		scope:lowborn_criminal = {
			random_list = {
				10 = { #Stableboy
					add_character_flag = {
						flag = stableboy_crime
					}
					pick_servant_romance_target_effect = yes
				}
				10 = { #Kinky
					add_character_flag = {
						flag = kinky_crime
					}
				}
				10 = { #Animal lover
					add_character_flag = {
						flag = beastiality_crime
					}
				}
			}
		}
	}
	if = {
		limit = {
			scope:lowborn_criminal = {
				has_trait = witch
			}
		}
		scope:lowborn_criminal = {
			random_list = {
				10 = { #Baby soup
					add_character_flag = {
						flag = baby_soup_crime
					}
				}
				10 = { #Evil healer
					add_character_flag = {
						flag = healer_crime
					}
					replace_with_learning_trait_effect = yes
					add_trait = lifestyle_herbalist
					give_nickname = nick_the_angel_of_death 
				}
				10 = { #Devil worshiper
					add_character_flag = {
						flag = devil_worship_crime
					}
				}
			}
		}
	}
	scope:lowborn_criminal = {
		add_to_list = lowborn_criminal_list
		every_child = {
			add_to_list = lowborn_criminal_list
		}
		every_spouse = {
			add_to_list = lowborn_criminal_list
		}
	}
}

# Rando criminal shows up
court_yearly.0101 = {
	type = character_event
	title = court.0101.t
	desc = {
		desc = court.0101.desc.opening
		first_valid = { #What the crime was
			triggered_desc = {
				trigger = { 
					scope:lowborn_criminal = {
						has_trait = murderer
					}
				}
				desc = court.0101.desc.murderer
			}
			triggered_desc = {
				trigger = { 
					scope:lowborn_criminal = {
						has_trait = deviant
					}
				}
				desc = court.0101.desc.deviant
			}
			triggered_desc = {
				trigger = { 
					scope:lowborn_criminal = {
						has_trait = witch
					}
				}
				desc = court.0101.desc.witch
			}
			triggered_desc = {
				trigger = { 
					scope:lowborn_criminal = {
						has_trait = lazy
					}
				}
				desc = court.0101.desc.lazy
			}
		}
		random_valid = { #Traitless crimes
			triggered_desc = {
				trigger = { 
					scope:lowborn_criminal = {
						NOR = {
							has_trait = murderer
							has_trait = witch
							has_trait = deviant
							has_trait = lazy
						}
					}
				}
				desc = court.0101.desc.thief
			}
			triggered_desc = {
				trigger = { 
					scope:lowborn_criminal = {
						NOR = {
							has_trait = murderer
							has_trait = witch
							has_trait = deviant
							has_trait = lazy
						}
					}
				}
				desc = court.0101.desc.sumptuary
			}
		}
		first_valid = { #Details about the crime
			#Murderer
			triggered_desc = {
				trigger = { 
					scope:lowborn_criminal = {
						has_trait = murderer
						has_trait = cannibal
					}
				}
				desc = court.0101.desc.cannibal
			}
			triggered_desc = {
				trigger = { 
					scope:lowborn_criminal = {
						has_trait = murderer
						has_trait = sadistic
					}
				}
				desc = court.0101.desc.sadistic
			}
			triggered_desc = {
				trigger = { 
					scope:lowborn_criminal = {
						has_trait = murderer
						has_character_flag = need_priest_outfit
					}
				}
				desc = court.0101.desc.priest
			}
			#Deviant
			triggered_desc = {
				trigger = { 
					scope:lowborn_criminal = {
						has_trait = deviant
						has_character_flag = stableboy_crime
					}
				}
				desc = court.0101.desc.stableboy
			}
			triggered_desc = {
				trigger = { 
					scope:lowborn_criminal = {
						has_trait = deviant
						has_character_flag = kinky_crime
					}
				}
				desc = court.0101.desc.kinky
			}
			triggered_desc = {
				trigger = { 
					scope:lowborn_criminal = {
						has_trait = deviant
						has_character_flag = beastiality_crime
					}
				}
				desc = court.0101.desc.animals
			}
			#Witch
			triggered_desc = {
				trigger = { 
					scope:lowborn_criminal = {
						has_trait = witch
						has_character_flag = baby_soup_crime
					}
				}
				desc = court.0101.desc.baby_soup
			}
			triggered_desc = {
				trigger = { 
					scope:lowborn_criminal = {
						has_trait = witch
						has_character_flag = healer_crime
					}
				}
				desc = court.0101.desc.suspicious_healer
			}
			triggered_desc = {
				trigger = { 
					scope:lowborn_criminal = {
						has_trait = witch
						has_character_flag = devil_worship_crime
					}
				}
				desc = court.0101.desc.devil_worshiper
			}
		}
 		desc = court.0101.desc.outro
	}

	theme = court
	left_portrait = {
		character = scope:executioner
		animation = schadenfreude
	}
	right_portrait = {
		character  = scope:lowborn_criminal
		animation = fear
	}
	
	
	# More likely to trigger if you are a sadistic person 
	weight_multiplier = {
		base = 1
		modifier = { 
			add = 0.5
			has_trait = sadistic
		}
	}

	trigger = {
		has_royal_court = yes
		has_dlc_feature = royal_court
		is_available_at_peace_adult = yes
		employs_court_position = executioner_court_position
	}

	immediate = {
		event_0101_spawn_criminal_effect = yes
		if = {
			limit = {
				any_court_position_holder = {
					type = executioner_court_position
				}
			}
			random_court_position_holder = {
				type = executioner_court_position
				save_scope_as = executioner
			}
		}
	}

	# Option A: Ironic punishment
	option = { 
		name = {
			trigger = { 
				scope:lowborn_criminal = {
					has_trait = murderer
					has_trait = cannibal
				}
			}
			text = court.0101.a.cannibal
		}
		name = {
			trigger = { 
				scope:lowborn_criminal = {
					has_trait = murderer
					has_trait = sadistic
				}
			}
			text = court.0101.a.sadistic
		}
		name = {
			trigger = { 
				scope:lowborn_criminal = {
					has_trait = murderer
					has_character_flag = need_priest_outfit
					faith = { has_doctrine_parameter = sky_burials_active }
				}
			}
			text = court.0101.a.priest.sky
		}
		name = {
			trigger = { 
				scope:lowborn_criminal = {
					has_trait = murderer
					has_character_flag = need_priest_outfit
				}
			}
			text = court.0101.a.priest
		}
		name = {
			trigger = { 
				scope:lowborn_criminal = {
					has_trait = deviant
					has_character_flag = stableboy_crime
				}
			}
			text = court.0101.a.stableboy
		}
		name = {
			trigger = { 
				scope:lowborn_criminal = {
					has_trait = deviant
					has_character_flag = kinky_crime
				}
			}
			text = court.0101.a.kinky
		}
		name = {
			trigger = { 
				scope:lowborn_criminal = {
					has_trait = deviant
					has_character_flag = beastiality_crime
				}
			}
			text = court.0101.a.animals
		}
		#Witch
		name = {
			trigger = { 
				scope:lowborn_criminal = {
					has_trait = witch
					has_character_flag = baby_soup_crime
				}
			}
			text = court.0101.a.baby_soup
		}
		name = {
			trigger = { 
				scope:lowborn_criminal = {
					has_trait = witch
					has_character_flag = healer_crime
				}
			}
			text = court.0101.a.suspicious_healer
		}
		name = {
			trigger = { 
				scope:lowborn_criminal = {
					has_trait = witch
				}
				has_character_flag = devil_worship_crime
			}
			text = court.0101.a.devil_worshiper
		}
		name = {
			trigger = {
			}
			text = court.0101.a
		}
		stress_impact = {
			zealous = minor_stress_impact_loss #They are a criminal afterall
			vengeful = minor_stress_impact_loss
			wrathful = minor_stress_impact_loss
			sadistic = major_stress_impact_loss
			compassionate = major_stress_impact_gain
			forgiving = major_stress_impact_gain
		}
		scope:lowborn_criminal = {
			every_child = {
				limit = {
					has_trait = cannibal
				}
				death = {
					killer = root
					death_reason = death_torture
				}
			}
			every_spouse = {
				limit = {
					has_trait = cannibal
				}
				death = {
					killer = root
					death_reason = death_torture
				}
			}
			death = {
				killer = root
				death_reason = death_torture
			}
		}
		progress_towards_friend_effect = {
			CHARACTER = scope:executioner
			OPINION = default_friend_opinion
			REASON = friend_art_of_torture_punishment
		}
	}

	#Option C: I like this person, bring them to court!
	option = {
		trigger = {
			OR = {
				AND = {
					OR = {
						has_trait = sadistic
						any_secret = { type = secret_murder }
					}
					scope:criminal_trait ?= flag:sadistic_trait_flag
				}
				AND = {
					OR = {
						has_trait = cannibal
						any_secret = { type = secret_cannibal }
					}
					scope:criminal_trait ?= flag:cannibal_trait_flag
				}
				AND = {
					OR = {
						has_trait = deviant
						any_secret = { type = secret_deviant }
					}
					scope:criminal_trait ?= flag:deviant_trait_flag
				}
				AND = {
					OR = {
						has_trait = witch
						any_secret = { type = secret_witch }
					}
					scope:criminal_trait ?= flag:witch_trait_flag
				}
			}
		}
		name = {
			trigger = {
				scope:lowborn_criminal = {
					has_trait = deviant
					has_character_flag = beastiality_crime
				}
			}
			text = court.0101.c.beastiality
		}
		name = {
			trigger = {
				scope:lowborn_criminal = {
					has_trait = deviant
					NOT = { has_character_flag = beastiality_crime }
				}
			}
			text = court.0101.c.deviant
		}
		name = {
			trigger = {
				scope:lowborn_criminal = {
					NOT = { has_trait = deviant }
				}
			}
			text = court.0101.c
		}
		stress_impact = {
			zealous = minor_stress_impact_gain
			vengeful = minor_stress_impact_gain
			sadistic = minor_stress_impact_gain #You wanna see them hurt, even if you are both sadists
			witch = minor_stress_impact_loss
			deviant = minor_stress_impact_loss #Another pervert for me to have fun with
			compassionate = major_stress_impact_loss
			forgiving = major_stress_impact_loss
		}
		every_in_list = {
			list = lowborn_criminal_list
			root = {
				add_courtier = prev
			}
		}
		if = {
			limit = {
				has_trait = deviant
				can_set_relation_lover_trigger = { CHARACTER = scope:lowborn_criminal }
			}
			set_relation_lover = { reason = lover_deviant target = scope:lowborn_criminal }
		}
	}

	#Option D: Keep them in the castle prison
	option = {
		name = court.0101.d
		every_in_list = {
			list = lowborn_criminal_list
			root = {
				add_courtier = prev
			}
			rightfully_imprison_character_effect = {
				TARGET = this
				IMPRISONER = root
			}
		}

	}

	#Option B: I don't care
	option = { 
		name = court.0101.b
		scope:lowborn_criminal = {
			silent_disappearance_effect = yes
			every_child = {
				silent_disappearance_effect = yes
			}
			every_spouse = {
				silent_disappearance_effect = yes
			}
		}
	}
}

# Executioner feeling lonely
court_yearly.0102 = {
	type = character_event
	title = court.0102.t
	desc = court.0102.desc
	theme = court
	left_portrait = {
		character = scope:executioner
		animation = sadness
	}

	trigger = {
		has_royal_court = yes
		has_dlc_feature = royal_court
		employs_court_position = executioner_court_position
		is_available_adult = yes
		any_court_position_holder = {
			type = executioner_court_position
			is_available_ai_adult = yes
		}
	}
	
	# More likely to trigger if the executioner actually likes other humans 
	weight_multiplier = {
		base = 1
		modifier = { 
			add = 0.5
			any_court_position_holder = {
				type = executioner_court_position
				has_trait = gregarious
			}
		}
		modifier = { 
			add = 0.5
			any_court_position_holder = {
				type = executioner_court_position
				has_trait = compassionate
			}
		}
		modifier = { 
			add = -0.5
			any_court_position_holder = {
				type = executioner_court_position
				has_trait = shy
			}
		}
	}

	immediate = {
		if = {
			limit = {
				any_court_position_holder = {
					type = executioner_court_position
				}
			}
			random_court_position_holder = {
				type = executioner_court_position
				save_scope_as = executioner
			}
		}
	}

	# Option A: Pity the executioner
	option = { 
		name = court.0102.a
		progress_towards_friend_effect = {
			CHARACTER = scope:executioner
			OPINION = default_friend_opinion
			REASON = friend_took_pity
		}
		reverse_add_opinion = {
	 		target = scope:executioner
	 		modifier = grateful_opinion
	 		opinion = 15
	 	}
		stress_impact = {
			vengeful = minor_stress_impact_gain
			sadistic = minor_stress_impact_gain
			shy = minor_stress_impact_gain
			compassionate = minor_stress_impact_loss
			gregarious = minor_stress_impact_loss
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = -0.5
				ai_vengefulness = 0.5
			}
		}
	}

	#Option C: Repremand the executioner for moaning about being lonely
	option = { 
		name = court.0102.c
		progress_towards_rival_effect = {
			REASON = rival_reprimanded_lonely
			CHARACTER = scope:executioner
			OPINION = -25
		}
		scope:executioner = {
			add_stress = minor_stress_gain
		}
		stress_impact = {
			vengeful = minor_stress_impact_loss
			sadistic = minor_stress_impact_loss
			shy = minor_stress_impact_gain
			compassionate = minor_stress_impact_gain
			gregarious = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = -0.5
				ai_vengefulness = 0.5
			}
		}
	}

	#Option B: I don't care
	option = { 
		name = court.0102.b
		scope:executioner = {
			add_stress = minor_stress_gain
		}
		stress_impact = {
			vengeful = minor_stress_impact_loss
			compassionate = minor_stress_impact_gain
			gregarious = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = -0.5
			}
		}
	}
}

# Executioner selling... items from the prisoners
court_yearly.0103 = {
	type = character_event
	title = court.0103.t
	desc = {
		desc = court.0103.desc.opening
		random_valid = { #What did the executioner do
			desc = court.0103.desc.hair_and_teeth
			desc = court.0103.desc.jewelry
			triggered_desc = {
				trigger = {
					scope:executioner = {
						NOR = {
							has_trait = compassionate
							has_trait = content
							has_trait = just
							AND = {
								has_trait = zealous
								faith = {
									NOT = {
										has_doctrine = tenet_ritual_cannibalism
									}
								}
							}
						}
					}
				}
				desc = court.0103.desc.meat
			}
			triggered_desc = {
				trigger = {
					scope:executioner = {
						is_christian_trigger = yes
						NOT = {
							has_trait = zealous
						}
					}
				}
				desc = court.0103.desc.saint_bones
			}
		}
		desc = court.0103.desc.outro
	}
	theme = court
	left_portrait = {
		character = scope:executioner
		animation = personality_greedy
	}

	trigger = {
		has_royal_court = yes
		has_dlc_feature = royal_court
		employs_court_position = executioner_court_position
		is_available_adult = yes
		any_court_position_holder = {
			type = executioner_court_position
			is_available_ai_adult = yes
			NOT = {
				has_trait = improvident
			}
		}
	}
	
	weight_multiplier = {
		base = 0.5
		modifier = { 
			add = 0.5
			any_court_position_holder = {
				type = executioner_court_position
				has_trait = greedy
			}
		}
		modifier = {
			add = 0.5
			any_court_position_holder = {
				type = executioner_court_position
				has_trait = sadistic
			}
		}
		modifier = {
			add = 0.5
			any_court_position_holder = {
				type = executioner_court_position
				has_trait = callous
			}
		}
		modifier = {
			add = 0.5
			any_court_position_holder = {
				type = executioner_court_position
				has_trait = ambitious
			}
		}
		modifier = {
			add = 0.5
			any_court_position_holder = {
				type = executioner_court_position
				has_trait = deceitful
			}
		}
		modifier = {
			add = -0.5
			any_court_position_holder = {
				type = executioner_court_position
				has_trait = honest
			}
		}
		modifier = {
			add = -0.5
			any_court_position_holder = {
				type = executioner_court_position
				has_trait = just
			}
		}
	}

	immediate = {
		if = {
			limit = {
				any_court_position_holder = {
					type = executioner_court_position
				}
			}
			random_court_position_holder = {
				type = executioner_court_position
				save_scope_as = executioner
			}
		}
	}

	# Option A: Get in on this
	option = { 
		name = court.0103.a
		reverse_add_opinion = {
	 		target = scope:executioner
	 		modifier = grateful_opinion
	 		opinion = 15
	 	}
	 	add_gold = medium_gold_value
	 	add_piety = major_piety_loss
		stress_impact = {
			vengeful = minor_stress_impact_loss
			sadistic = minor_stress_impact_loss
			greedy = major_stress_impact_loss
			compassionate = major_stress_impact_gain
			zealous = major_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = -1
				ai_vengefulness = 1.5
			}
		}
	}

	#Option B: Repremand the executioner
	option = { 
		name = court.0103.b
		rightfully_imprison_character_effect = {
			TARGET = scope:executioner
			IMPRISONER = root
		}
		stress_impact = {
			greedy = major_stress_impact_gain
			just = minor_stress_impact_loss
			zealous = minor_stress_impact_loss
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_honor = 0.5
				ai_vengefulness = -0.5
			}
		}
	}

	#Option C: Don't care
	option = { 
		name = court.0103.c
		reverse_add_opinion = {
	 		target = scope:executioner
	 		modifier = grateful_opinion
	 		opinion = 15
	 	}
		stress_impact = {
			greedy = major_stress_impact_gain
			just = minor_stress_impact_gain
			zealous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_honor = -0.5
				ai_vengefulness = -0.5
			}
		}
	}
}

#################################################
# The executioner events						#
# by James Beaumont								#
# 0104 - Child into exectution					#
# 0106 - Executioner asks how far they can go	#
#################################################

# Executioner talking to a ward about their trade
court_yearly.0104 = {
	type = character_event
	title = court.0104.t
	desc = court.0104.desc

	theme = court
	left_portrait = {
		character = scope:executioner
		animation = happiness
	}
	right_portrait = {
		character = scope:morbid_child
		animation = admiration
	}

	trigger = {
		has_royal_court = yes
		has_dlc_feature = royal_court
		employs_court_position = executioner_court_position
		any_relation = {
			type = ward
			NOT = { has_trait = compassionate }
			is_available = yes
			age >= 5
		}
		is_available_adult = yes
		any_court_position_holder = {
			type = executioner_court_position
			is_available_ai_adult = yes
		}
	}
	
	# More likely to trigger if the executioner likes talking to children
	weight_multiplier = {
		base = 1
		modifier = {
			add = 0.5
			any_court_position_holder = {
				type = executioner_court_position
				has_trait = gregarious
			}
		}
		modifier = {
			add = 0.5
			any_court_position_holder = {
				type = executioner_court_position
				has_trait = trusting
			}
		}
		modifier = {
			add = 0.5
			any_court_position_holder = {
				type = executioner_court_position
				has_trait = patient  #You gotta have some real patience to answer some children's questions
			}
		}
		modifier = {
			add = 0.5
			any_court_position_holder = {
				type = executioner_court_position
				has_trait = family_first
			}
		}
		modifier = {
			add = -0.5
			any_court_position_holder = {
				type = executioner_court_position
				has_trait = shy
			}
		}
		modifier = {
			add = -0.5
			any_court_position_holder = {
				type = executioner_court_position
				has_trait = impatient
			}
		}
	}

	immediate = {
		if = {
			limit = {
				any_court_position_holder = {
					type = executioner_court_position
				}
			}
			random_court_position_holder = {
				type = executioner_court_position
				save_scope_as = executioner
			}
		}
		random_relation = {
			type = ward
			limit = {
				NOT = { has_trait = compassionate }
				is_available = yes
				age >= 5
			}
			save_scope_as = morbid_child
		}
	}

	# Option A: Join in the conversation
	option = { 
		name = court.0104.a
		scope:morbid_child = {
			add_trait = sadistic
		}
		progress_towards_friend_effect = {
			CHARACTER = scope:morbid_child
			OPINION = default_friend_opinion
			REASON = friend_torture_stories
		}
		reverse_add_opinion = {
	 		target = scope:morbid_child
	 		modifier = grateful_opinion
	 		opinion = 15
	 	}
		progress_towards_friend_effect = {
			CHARACTER = scope:executioner
			OPINION = default_friend_opinion
			REASON = friend_torture_stories
		}
		reverse_add_opinion = {
	 		target = scope:executioner
	 		modifier = grateful_opinion
	 		opinion = 15
	 	}
	 	scope:morbid_child = {
			progress_towards_friend_effect = {
				CHARACTER = scope:executioner
				OPINION = default_friend_opinion
				REASON = friend_torture_stories
			}
		}
		stress_impact = {
			sadistic = minor_stress_impact_loss
			shy = minor_stress_impact_gain
			compassionate = major_stress_impact_gain
			gregarious = minor_stress_impact_loss
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = -0.5
				ai_vengefulness = 0.5
			}
			modifier = {
				factor = 0.5
				scope:morbid_child = { has_trait = sadistic }
			}
		}
	}

	#Option B: Repremand the executioner for talking to your ward
	option = { 
		name = court.0104.b
		progress_towards_rival_effect = {
			REASON = rival_morbid_child
			CHARACTER = scope:morbid_child
			OPINION = -25
		}
		scope:morbid_child = {
			add_stress = minor_stress_gain
		}
		progress_towards_rival_effect = {
			REASON = rival_reprimanded_child
			CHARACTER = scope:executioner
			OPINION = -25
		}
		scope:executioner = {
			add_stress = minor_stress_gain
		}
		stress_impact = {
			vengeful = minor_stress_impact_loss
			sadistic = minor_stress_impact_loss
			shy = minor_stress_impact_gain
			compassionate = minor_stress_impact_gain
			gregarious = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = 0.5
			}
			modifier = { #The kid is already a sadist
				factor = 2
				scope:morbid_child = { has_trait = sadistic }
			}
		}
	}

	#Option C: Pretend you didn't hear
	option = { 
		name = court.0104.c
		random_list = {
			50 = {}
			50 = {
				scope:morbid_child = {
					add_trait = sadistic
				}
			}
		}
	 	scope:morbid_child = {
			progress_towards_friend_effect = {
				CHARACTER = scope:executioner
				OPINION = default_friend_opinion
				REASON = friend_torture_stories
			}
		}
		stress_impact = {
			compassionate = minor_stress_impact_gain
			gregarious = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = -0.5
			}
		}
	}
}


# Executioner asks how far they can go
court_yearly.0106 = {
	type = character_event
	title = court.0106.t
	desc = court.0106.desc
	theme = court
	left_portrait = {
		character = scope:executioner
		animation = scheme
	}

	trigger = {
		has_royal_court = yes
		has_dlc_feature = royal_court
		employs_court_position = executioner_court_position
		is_available_adult = yes
		any_court_position_holder = {
			type = executioner_court_position
			is_available_ai_adult = yes
		}
	}
	
	weight_multiplier = {
		base = 0.5
		modifier = {
			add = 0.5
			any_court_position_holder = {
				type = executioner_court_position
				has_trait = sadistic
			}
		}
		modifier = {
			add = 0.5
			any_court_position_holder = {
				type = executioner_court_position
				has_trait = callous
			}
		}
		modifier = {
			add = 1.0
			any_prisoner = { has_any_secrets = yes }
		}
		modifier = {
			add = -0.5
			any_court_position_holder = {
				type = executioner_court_position
				has_trait = just
			}
		}
		modifier = {
			add = -0.5
			any_court_position_holder = {
				type = executioner_court_position
				has_trait = compassionate
			}
		}
	}

	immediate = {
		if = {
			limit = {
				any_court_position_holder = {
					type = executioner_court_position
				}
			}
			random_court_position_holder = {
				type = executioner_court_position
				save_scope_as = executioner
			}
		}
	}

	# Option A: Go hard on the prisoners
	option = {
		name = court.0106.a
		if = {
			limit = {
				any_prisoner = { has_any_secrets = yes }
			}
			random_prisoner = {
				random_secret = {
					limit = {
						NOT = {
							any_secret_knower = {
								this = root
							}
						}
					}
					reveal_to = root
				}
			}
		}
		if = {
			limit = {
				scope:executioner = {
					has_trait = sadistic
				}
			}
			scope:executioner = { add_stress = major_stress_impact_loss }
			progress_towards_friend_effect = {
				CHARACTER = scope:executioner
				OPINION = default_friend_opinion
				REASON = friend_shared_opinions_on_punishment
			}
		}
		else_if = {
			limit = {
				scope:executioner = {
					has_trait = compassionate
				}
			}
			scope:executioner = { add_stress = major_stress_impact_gain }
			progress_towards_rival_effect = {
				REASON = rival_go_hard_on_prisoners
				CHARACTER = scope:executioner
				OPINION = default_rival_opinion
			}
		}
		stress_impact = {
			vengeful = minor_stress_impact_loss
			sadistic = minor_stress_impact_loss
			callous = minor_stress_impact_loss
			compassionate = major_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = -1
				ai_vengefulness = 1.5
			}
		}
	}

	#Option B: Be a little gentle
	option = { 
		name = court.0106.b
		if = {
			limit = {
				scope:executioner = {
					has_trait = compassionate
				}
			}
			scope:executioner = { add_stress = major_stress_impact_loss }
			progress_towards_friend_effect = {
				CHARACTER = scope:executioner
				OPINION = default_friend_opinion
				REASON = friend_shared_opinions_on_punishment
			}
		}
		else_if = {
			limit = {
				scope:executioner = {
					has_trait = sadistic
				}
			}
			scope:executioner = { add_stress = major_stress_impact_gain }
			progress_towards_rival_effect = {
				REASON = rival_go_easy_on_prisoners
				CHARACTER = scope:executioner
				OPINION = default_rival_opinion
			}
		}
		stress_impact = {
			vengeful = minor_stress_impact_gain
			sadistic = minor_stress_impact_gain
			compassionate = major_stress_impact_loss
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_honor = 0.5
				ai_vengefulness = -0.5
			}
		}
	}

	#Option C: Don't care
	option = { 
		name = court.0106.c
		if = {
			limit = {
				any_prisoner = { has_any_secrets = yes }
			}
			random_list = {
				50 = {

				}
				50 = {
					random_prisoner = {
						random_secret = {
							limit = {
								NOT = {
									any_secret_knower = {
										this = root
									}
								}
							}
							reveal_to = root
						}
					}
				}
			}
		}
		stress_impact = {
			vengeful = minor_stress_impact_gain
			sadistic = minor_stress_impact_gain
			compassionate = minor_stress_impact_gain
			just = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_honor = -0.5
				ai_vengefulness = -0.5
			}
		}
	}
}

# Parent sends you to horny jail
court_yearly.0110 = {
	type = character_event
	title = court.0110.t
	desc = {
		desc = court.0110.desc.intro
		first_valid = {
			triggered_desc = {
					trigger = { 
						has_trait = deviant
					}
				desc = court.0110.desc.deviant
			}
			triggered_desc = {
					trigger = { 
						has_trait = lovers_pox
					}
				desc = court.0110.desc.pox
			}
			desc = court.0110.desc.notspecial
		}
		desc = court.0110.desc.outro
	}

	theme = court
	left_portrait = {
		character = scope:parent
		animation = worry
	}
	right_portrait = {
		character = cp:councillor_court_chaplain
		animation = anger
	}

	trigger = {
		has_royal_court = yes
		has_dlc_feature = royal_court
		any_parent = {
			exists = yes
			is_available_adult = yes
			liege = root
			is_landed = no
		}
		cp:councillor_court_chaplain ?= { is_available_adult = yes }
		is_available_adult = yes
		OR = {
			trait_is_shunned_in_faith_trigger = { TRAIT = adulterer FAITH = root.faith GENDER_CHARACTER = root } #Fornicator is handled by same rules
			trait_is_criminal_in_faith_trigger = { TRAIT = adulterer FAITH = root.faith GENDER_CHARACTER = root } #Fornicator is handled by same rules
		}
		OR = {
			has_trait = deviant
			has_trait = lovers_pox
			any_relation = {
				type = lover
				NOT = { is_consort_of = root }
			}
			any_relation = {
				type = soulmate
				NOT = { is_consort_of = root }
			}
		}
		is_eunuch_trigger = no
		NOR = {
			has_trait = celibate
			has_trait = chaste
		}
	}
	
	# More likely to trigger if your character is lustful and your parent is chaste
	weight_multiplier = {
		base = 1
		modifier = { 
			add = 0.5
			any_parent = {
				exists = yes
				is_available_adult = yes
				liege = root
				is_landed = no
				has_trait = chaste
			}
		}
		modifier = { 
			add = 0.5
			cp:councillor_court_chaplain = {
				has_trait = chaste
			}
		}
		modifier = {
			add = -0.5
			cp:councillor_court_chaplain = {
				has_trait = lustful
			}
		}
		modifier = { 
			add = 0.5
			has_trait = lustful
		}
	}

	immediate = {
		random_parent = {
			limit = {
				is_alive = yes
				is_available_adult = yes
				liege = root
				is_landed = no
			}
			save_scope_as = parent
		}
		cp:councillor_court_chaplain = {
			save_scope_as = chaplain
		}
	}

	# Option A: Imprison your parent and chaplain
	option = { 
		name = court.0110.a
		progress_towards_rival_effect = {
			REASON = rival_parent_imprisoned
			CHARACTER = scope:parent
			OPINION = default_rival_opinion
		}
		progress_towards_rival_effect = {
			REASON = rival_parent_imprisoned
			CHARACTER = cp:councillor_court_chaplain
			OPINION = default_rival_opinion
		}
		imprison_character_effect = {
			TARGET = scope:parent
			IMPRISONER = root
		}
		imprison_character_effect = {
			TARGET = cp:councillor_court_chaplain
			IMPRISONER = root
		}
		stress_impact = {
			just = major_stress_impact_gain
			compassionate = major_stress_impact_gain
			forgiving = major_stress_impact_gain
			calm = major_stress_impact_gain
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_vengefulness = 0.5
				ai_honor = -1
			}
		}
	}

	#Option B: Agree, become celibate
	option = { 
		name = court.0110.b
		add_trait = celibate
		add_piety = medium_piety_gain
		reverse_add_opinion = {
	 		target = cp:councillor_court_chaplain
	 		modifier = impressed_opinion
	 		opinion = 15
	 	}
		reverse_add_opinion = {
	 		target = scope:parent
	 		modifier = relieved_opinion
	 		opinion = 15
	 	}
		stress_impact = {
			vengeful = minor_stress_impact_gain
			lustful = major_stress_impact_gain
			rakish = massive_stress_impact_gain
			stubborn = major_stress_impact_gain
			wrathful = major_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_vengefulness = -0.5
				ai_zeal = 0.5
			}
			modifier = { #Character shouldn't give up sex if they haven't got any children
				factor = 0
				any_child = { is_alive = yes count < 1 }
			}
			modifier = { #More likely to do it if they have a lot of kids
				add = 5
				any_child = { is_alive = yes count > 4 }
			}
		}
	}

	#Option C: Refuse and move on
	option = { 
		name = court.0110.c
		reverse_add_opinion = {
	 		target = cp:councillor_court_chaplain
	 		modifier = disappointed_opinion
	 		opinion = -15
	 	}
		reverse_add_opinion = {
	 		target = scope:parent
	 		modifier = disappointed_opinion
	 		opinion = -15
	 	}
		stress_impact = {
		}
		ai_chance = {
			base = 50
		}
	}
}

###########################
# Questionable Concoction #
# by Joe Parkin 		  #
###########################

scripted_trigger court_8100_physician_trigger = {
	is_available_ai_adult = yes
	NOT = { government_has_flag = government_is_theocracy }
	NOT = { has_trait = devoted }
	NAND = {
		exists = ROOT.cp:councillor_court_chaplain
		THIS = ROOT.cp:councillor_court_chaplain
	}
}

scripted_trigger court_8100_witch_trigger = {
	OR = {
	    has_trait = lifestyle_mystic
	    has_trait = lifestyle_herbalist
	    has_trait = witch
	    any_secret = { type = secret_witch }
	}
}

court_yearly.8100 = {
    type = character_event
    title = court.8100.t
    desc = court.8100.desc
    theme = court
    cooldown = { years = 10 }
    left_portrait = {
		character = scope:physician
		animation = throne_room_conversation_4
	}
	right_portrait = {
		character = scope:food_taster
		animation = throne_room_conversation_1
	}

    trigger = {
    	has_royal_court = yes
		has_dlc_feature = royal_court
    	employs_court_position = court_physician_court_position
    	any_court_position_holder = {
    		type = court_physician_court_position
    		court_8100_physician_trigger = yes
    	}
    }

    weight_multiplier = {
        base = 1
        modifier = {
            factor = 2
            any_court_position_holder = {
                type = court_physician_court_position
              	court_8100_physician_trigger = yes
                court_8100_witch_trigger = yes
            }
        }
    }

    immediate = {
    	random_court_position_holder = {
    		type = court_physician_court_position
    		limit = { court_8100_physician_trigger = yes }
            weight = {
                modifier = {
                	factor = 100
	                court_8100_witch_trigger = yes
	            }
            }
    		save_scope_as = physician
    	}
        if = {
            limit = {
                employs_court_position = food_taster_court_position
                any_court_position_holder = {
                    type = food_taster_court_position
                    is_available_ai_adult = yes
                    THIS != scope:physician
                }
            }
            random_court_position_holder = {
                type = food_taster_court_position
                limit = {
                	is_available_ai_adult = yes
                	THIS != scope:physician
                }
                save_scope_as = food_taster
            }
        }
        else = {
        	random_courtier_or_guest = { save_scope_as = food_taster }
        }
    }

    option = { # Your strongest potion, you say?
        name = court.8100.a
        stress_impact = {
        	craven = major_stress_impact_gain # What if I am not strong enough?
        	humble = medium_stress_impact_gain # I am fine with my strength
        	content = medium_stress_impact_gain # ""
        }
        add_prestige = minor_prestige_gain
        random_list = {
            1 = {
            	desc = court.8100.tt.handle_potion
                modifier = { factor = scope:physician.learning }
                modifier = {
                    factor = 2
                    scope:physician = { has_trait = lifestyle_mystic }
                }
                modifier = {
                    factor = 2
                    scope:physician = { has_trait = lifestyle_herbalist }
                }
                modifier = {
                    factor = 2
                    scope:physician = {
	                    OR = {
	                        has_trait = witch
	                        any_secret = { type = secret_witch }
	                    }
	                }
                }
                add_character_modifier = {
                    modifier = strong_potion_modifier
                    years = 5
                }
            }
            45 = {
            	desc = court.8100.tt.need_weaker
            	add_character_modifier = {
                    modifier = feeling_unwell_modifier
                    years = 5
                }
                stress_impact = {
                	base = medium_stress_impact_gain
                }
            }
            1 = {
            	desc = court.8100.tt.too_strong
                modifier = {
                    factor = 2
                    scope:physician = { has_relation_rival = ROOT }
                }
                modifier = {
                    factor = 2
                    scope:physician = { learning < average_skill_rating }
                }
                death = {
                    death_reason = death_strongest_potion
                    killer = scope:physician
                }
                add_internal_flag = dangerous
            }
        }
		ai_chance = {
            base = 100
            ai_value_modifier = {
            	ai_greed = -2
            	ai_energy = 1
            }
            modifier = {	#Weight down for stress.
            	add = -30
            	has_trait = craven       	
            }
            modifier = {	#Weight down for stress.
            	add = -15
            	has_trait = humble       	
            }
            modifier = {	#Weight down for stress.
            	add = -15
            	has_trait = content       	
            }
        }
    }

    option = { # Try it on my taster first
        name = court.8100.b
        trigger = {
        	exists = scope:food_taster
        	scope:food_taster = { has_court_position = food_taster_court_position } # To check against fallback
        }
        add_tyranny = minor_tyranny_gain
        random_list = {
            1 = {
            	desc = court.8100.tt.handle_potion
            	modifier = { factor = scope:physician.learning }
                modifier = {
                    factor = 2
                    scope:physician = { has_trait = lifestyle_mystic }
                }
                modifier = {
                    factor = 2
                    scope:physician = { has_trait = lifestyle_herbalist }
                }
                modifier = {
                    factor = 2
                    scope:physician = {
	                    OR = {
	                        has_trait = witch
	                        any_secret = { type = secret_witch }
	                    }
	                }
                }
                scope:food_taster = {
                    add_character_modifier = {
                        modifier = strong_potion_modifier
                        years = 5
                    }
                    if = {
	                	limit = {
	                		NOT = { has_trait = forgiving }
	                	}
	                	custom_tooltip = court.8100.b.tt_forgiving
	                	add_opinion = {
				            target = ROOT
				            modifier = angry_opinion
				            opinion = -15
				        }
	                }
                }
                add_character_modifier = {
                    modifier = strong_potion_modifier
                    years = 5
                }
            }
            45 = {
            	desc = court.8100.tt.need_weaker
            	scope:food_taster = {
            		add_character_modifier = {
	                    modifier = feeling_unwell_modifier
	                    years = 5
	                }
	                add_opinion = {
			            target = ROOT
			            modifier = angry_opinion
			            opinion = -15
			        }
	            }
            }
            1 = {
            	desc = court.8100.tt.too_strong
                modifier = {
                    factor = 2
                    scope:physician = { has_relation_rival = ROOT }
                }
                modifier = {
                    factor = 2
                    scope:physician = { learning < average_skill_rating }
                }
                scope:food_taster = {
                    death = {
                        death_reason = death_strongest_potion
                        killer = scope:physician
                    }
                }
                add_opinion = {
                    target = scope:physician
                    modifier = attempted_murder_opinion
                }
            }
        }
        stress_impact = {
        	brave = medium_stress_impact_gain # What if I am not strong enough?
        	humble = medium_stress_impact_gain # I am fine with my strength
        	content = medium_stress_impact_gain # ""
        	compassionate = major_stress_impact_gain # Food tasters are people too
        	greedy = medium_stress_impact_gain # It's mine, it came to me!
        }
		ai_chance = {
            base = 100
            ai_value_modifier = {
            	ai_greed = -2
            	ai_energy = 1
            }
            modifier = {	#Weight down for stress.
            	add = -15
            	has_trait = brave       	
            }
            modifier = {	#Weight down for stress.
            	add = -15
            	has_trait = humble       	
            }
            modifier = {	#Weight down for stress.
            	add = -15
            	has_trait = content       	
            }
            modifier = {	#Weight down for stress.
            	add = -30
            	has_trait = compassionate       	
            }
             modifier = {	#Weight down for stress.
            	add = -15
            	has_trait = greedy       	
            }
        }
    }

    option = { # Sacrilege
        name = court.8100.c
        add_piety = minor_piety_gain
        revoke_court_position = {
        	court_position = court_physician_court_position
        	recipient = scope:physician
        }
        reverse_add_opinion = {
            target = scope:physician
            modifier = angry_opinion
            opinion = -15
        }
        stress_impact = {
        	cynical = medium_stress_impact_gain # There is no god
        	arrogant = medium_stress_impact_gain # I want to be swole
        	ambitious = medium_stress_impact_gain # ""
        }
        ai_chance = {
            base = 100
            ai_value_modifier = {
            	ai_zeal = 1
            	ai_boldness = -1
            }
            modifier = {	#Weight down for stress.
            	add = -30
            	has_trait = cynical       	
            }
            modifier = {	#Weight down for stress.
            	add = -15
            	has_trait = arrogant       	
            }
            modifier = {	#Weight down for stress.
            	add = -15
            	has_trait = ambitious       	
            }
        }
    }

    option = { # I have no need of your potions
        name = court.8100.d
        add_prestige = miniscule_prestige_loss
        reverse_add_opinion = {
            target = scope:physician
            modifier = insulted_opinion
            opinion = -5
        }
        stress_impact = {
        	brave = minor_stress_impact_gain
        	arrogant = medium_stress_impact_gain # I want to be swole
        	ambitious = medium_stress_impact_gain # ""
        }
        ai_chance = {
            base = 100
            ai_value_modifier = {
            	ai_boldness = -2
            	ai_greed = -1
            }
            modifier = {	#Weight down for stress.
            	add = -5
            	has_trait = brave       	
            }
            modifier = {	#Weight down for stress.
            	add = -15
            	has_trait = arrogant       	
            }
            modifier = {	#Weight down for stress.
            	add = -15
            	has_trait = ambitious       	
            }
        }
    }
}

#########################
# Novel Perspectives	#
# by Joe Parkin 		#
#########################

scripted_trigger root_faith_compare_doctrine_trigger = {
	OR = {
		AND = {
			faith = { has_doctrine = $DOCTRINE$ }
			NOT = {
				ROOT.faith = { has_doctrine = $DOCTRINE$ }
			}
		}
		AND = {
			ROOT.faith = { has_doctrine = $DOCTRINE$ }
			NOT = {
				faith = { has_doctrine = $DOCTRINE$ }
			}
		}
	}
}

scripted_trigger court_8120_zealous_vassal_trigger = {
	faith = ROOT.faith
	has_trait = zealous
	NOR = {
		THIS = scope:accuser
		THIS = scope:refuter
	}
}

scripted_effect court_8120_convert_vassal_effect = {
	if = {
    	limit = {
			any_vassal = {
				court_8120_zealous_vassal_trigger = yes
				faith = $FAITH$
				NOT = { THIS = $CONVERTOR$ }
			}
		}
    	every_vassal = {
			limit = {
				court_8120_zealous_vassal_trigger = yes
				faith = $FAITH$
				NOT = { THIS = $CONVERTOR$ }
			}
    		add_opinion = {
    			target = ROOT
	        	modifier = pious_opinion
	        	opinion = 10
    		}
    	}
    	hidden_effect = {
	    	every_courtier_or_guest = {
    			limit = {
    				court_8120_zealous_vassal_trigger = yes
    				faith = $FAITH$
    				NOT = { THIS = $CONVERTOR$ }
    			}
	    		add_opinion = {
	    			target = ROOT
		        	modifier = pious_opinion
		        	opinion = 10
	    		}
	    	}
	    }
	}
	else_if = {
		limit = {
			any_courtier_or_guest = {
				court_8120_zealous_vassal_trigger = yes
				faith = $FAITH$
				NOT = { THIS = $CONVERTOR$ }
			}
		}
		every_courtier_or_guest = {
			limit = {
				court_8120_zealous_vassal_trigger = yes
				faith = $FAITH$
				NOT = { THIS = $CONVERTOR$ }
			}
    		add_opinion = {
    			target = ROOT
	        	modifier = pious_opinion
	        	opinion = 10
    		}
    	}
	}
}

scripted_trigger court_8120_debater_trigger = {
	is_available_ai_adult = yes
	faith != ROOT.faith
	faith = {
		faith_hostility_level = {
			target = ROOT.faith
			value <= faith_hostile_level
		}
	}
	ROOT.faith = {
		faith_hostility_level = {
			target = PREV.faith
			value <= faith_hostile_level
		}
	}
	OR = {
		root_faith_compare_doctrine_trigger = { DOCTRINE = doctrine_monogamy } # Marriage
		root_faith_compare_doctrine_trigger = { DOCTRINE = doctrine_divorce_disallowed } # Divorce 
		root_faith_compare_doctrine_trigger = { DOCTRINE = doctrine_adultery_women_accepted } # Adultery Female
		root_faith_compare_doctrine_trigger = { DOCTRINE = doctrine_adultery_men_accepted } # Adultery Male
		root_faith_compare_doctrine_trigger = { DOCTRINE = doctrine_witchcraft_accepted } # Witchcraft 
		root_faith_compare_doctrine_trigger = { DOCTRINE = doctrine_gender_equal } # Equality 
		root_faith_compare_doctrine_trigger = { DOCTRINE = doctrine_consanguinity_unrestricted } # Cosanguity
	}
}

court_yearly.8120 = {
    type = character_event
    title = court.8120.t
    desc = {
    	desc = court.8120.desc.intro
    	first_valid = {
    		triggered_desc = {
    			trigger = { scope:accuser.religion = ROOT.religion }
    			desc = court.8120.desc.same_religion
    		}
    		desc = court.8120.desc.other_religion
    	}
    	first_valid = {
    		# Variables used to find randomly chosen doctrine difference
    		triggered_desc = { # Marriage
    			trigger = { var:court_8120_issue = 0 }
    			desc = court.8120.desc.marriage
    		}
    		triggered_desc = { # Divorce
    			trigger = { var:court_8120_issue = 1 }
    			desc = court.8120.desc.divorce
    		}
    		triggered_desc = { # Adultery
    			trigger = { var:court_8120_issue = 2 }
    			desc = court.8120.desc.adultery
    		}
    		triggered_desc = { # Witchcraft
    			trigger = { var:court_8120_issue = 3 }
    			desc = court.8120.desc.witchcraft
    		}
    		triggered_desc = { # Equality
    			trigger = { var:court_8120_issue = 4 }
    			desc = court.8120.desc.equality
    		}
    		triggered_desc = { # Cosanguity
    			trigger = { var:court_8120_issue = 5 }
    			desc = court.8120.desc.cosanguity
    		}
    	}
    	desc = court.8120.desc.outro
    }
    theme = court
    cooldown = { years = 10 }
    left_portrait = {
    	character = scope:accuser
    	animation = throne_room_conversation_2
    }
    right_portrait = {
    	character = scope:refuter
    	animation = throne_room_conversation_4
    }
   
    trigger = {
    	has_royal_court = yes
		has_dlc_feature = royal_court
    	any_courtier_or_guest = { court_8120_debater_trigger = yes }
    	trigger_if = {
    		limit = {
    			NOT = { exists = cp:councillor_court_chaplain }
  			}
    		any_courtier_or_guest = {
	    		is_available_ai_adult = yes
	    		faith = ROOT.faith
	    	}
    	}
    }

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

    immediate = {
    	# Save 1st debater
    	ordered_courtier_or_guest = {
    		limit = { court_8120_debater_trigger = yes }
    		order_by = learning
    		random_list = {
    			4 = { # Marriage
    				trigger = {
    					root_faith_compare_doctrine_trigger = { DOCTRINE = doctrine_monogamy } # 1/2 faiths have this
    				}
    				ROOT = {
	    				set_variable = { # To track which issue was raised
	    					name = court_8120_issue
	    					value = 0
	    				}
	    			}
    				if = { # Accuser attacks polygamy
    					limit = {
    						faith = { has_doctrine = doctrine_monogamy }
    					}
    					save_scope_as = accuser
    				}
    				else = { save_scope_as = refuter }
    			}
    			4 = { # Divorce
    				trigger = {
    					root_faith_compare_doctrine_trigger = { DOCTRINE = doctrine_divorce_disallowed } # 1/2 faiths have this
    				}
    				ROOT = {
	    				set_variable = { # To track which issue was raised
	    					name = court_8120_issue
	    					value = 1
	    				}
	    			}
    				if = { # Accuser attacks divorce
    					limit = {
    						faith = { has_doctrine = doctrine_divorce_disallowed }
    					}
    					save_scope_as = accuser
    				}
    				else = { save_scope_as = refuter }
    			}
    			2 = { # Adultery
    				trigger = {
    					OR = {
    						root_faith_compare_doctrine_trigger = { DOCTRINE = doctrine_adultery_women_accepted } # 1/2 faiths have this
    						root_faith_compare_doctrine_trigger = { DOCTRINE = doctrine_adultery_men_accepted } # 1/2 faiths have this
    					}
    				}
    				ROOT = {
	    				set_variable = { # To track which issue was raised
	    					name = court_8120_issue
	    					value = 2
	    				}
	    			}
    				if = { # Accuser attacks adultery
    					limit = {
    						NOT = {
    							faith = { has_doctrine = doctrine_adultery_women_accepted }
    						}
    					}
    					save_scope_as = accuser
    				}
    				else = { save_scope_as = refuter }
    			}
    			4 = { # Witchcraft
    				trigger = {
    					root_faith_compare_doctrine_trigger = { DOCTRINE = doctrine_witchcraft_accepted } # 1/2 faiths have this
    				}
    				ROOT = {
	    				set_variable = { # To track which issue was raised
	    					name = court_8120_issue
	    					value = 3
	    				}
	    			}
    				if = { # Accuser attacks magic
    					limit = {
    						NOT = {
    							faith = { has_doctrine_parameter = witchcraft_accepted }
    						}
    					}
    					save_scope_as = accuser
    				}
    				else = { save_scope_as = refuter }
    			}
    			2 = { # Equality
    				trigger = {
    					root_faith_compare_doctrine_trigger = { DOCTRINE = doctrine_gender_equal } # 1/2 faiths have this
    				}
    				ROOT = {
	    				set_variable = { # To track which issue was raised
	    					name = court_8120_issue
	    					value = 4
	    				}
	    			}
    				if = { # Accuser attacks inequality
    					limit = {
    						faith = { has_doctrine = doctrine_gender_equal }
    					}
    					save_scope_as = accuser
    				}
    				else = { save_scope_as = refuter }
    			}
    			4 = { # Cosanguity
    				trigger = {
    					root_faith_compare_doctrine_trigger = { DOCTRINE = doctrine_consanguinity_unrestricted } # 1/2 faiths have this
    				}
    				ROOT = {
	    				set_variable = { # To track which issue was raised
	    					name = court_8120_issue
	    					value = 5
	    				}
	    			}
    				if = { # Accuser attacks intermarriage
    					limit = {
    						NOT = {
    							faith = { has_doctrine = doctrine_consanguinity_unrestricted }
    						}
    					}
    					save_scope_as = accuser
    				}
    				else = { save_scope_as = refuter }
    			}
    		}
    	}
    	# Save 2nd debater
    	if = {
    		limit = { exists = cp:councillor_court_chaplain }
    		cp:councillor_court_chaplain = {
    			if = {
					limit = {
						NOT = { exists = scope:accuser }
					}
					save_scope_as = accuser
				}
				else = { save_scope_as = refuter }
			}
		}
    	else = {
	    	ordered_courtier_or_guest = {
	    		limit = {
	    			is_available_ai_adult = yes
		    		faith = ROOT.faith
	    		}
	    		order_by = learning
	    		if = {
					limit = {
						NOT = { exists = scope:accuser }
					}
					save_scope_as = accuser
				}
				else = { save_scope_as = refuter }
	    	}
	    }
	    # Scopes for conversion effects
	    save_scope_as = character
        if = {
        	limit = { scope:refuter.faith = ROOT.faith }
			scope:accuser.faith = { save_scope_as = new_faith }
		}
		else = {
			scope:refuter.faith = { save_scope_as = new_faith }
		}
		scope:accuser = { assign_quirk_effect = yes }
		scope:refuter = { assign_quirk_effect = yes }
    }

    option = { # Convert
        name = {
        	text = court.8120.a.accuser
        	trigger = { scope:refuter.faith = ROOT.faith }
        }
        name = {
        	text = court.8120.a.refuter
        	trigger = { scope:accuser.faith = ROOT.faith }
        }
        add_piety = massive_piety_loss
        if = {
        	limit = { faith = scope:refuter.faith }
        	reverse_add_opinion = {
	        	target = scope:refuter
	        	modifier = disappointed_opinion
	        	opinion = -40
	        }
	        reverse_add_opinion = {
	        	target = scope:accuser
	        	modifier = respect_opinion
	        	opinion = 40
	        }
	        court_8120_convert_vassal_effect = {
	        	FAITH = scope:accuser.faith
	        	CONVERTOR = scope:accuser
	        }
	        set_character_faith_with_conversion = scope:accuser.faith
        }
        else = {
        	reverse_add_opinion = {
	        	target = scope:accuser
	        	modifier = disappointed_opinion
	        	opinion = -40
	        }
	        reverse_add_opinion = {
	        	target = scope:refuter
	        	modifier = respect_opinion
	        	opinion = 40
	        }
	        court_8120_convert_vassal_effect = {
	        	FAITH = scope:refuter.faith
	        	CONVERTOR = scope:refuter
	        }
	        set_character_faith_with_conversion = scope:refuter.faith
        }
    	stress_impact = {
        	zealous = massive_stress_impact_gain
        	stubborn = medium_stress_impact_gain
        	lazy = medium_stress_impact_gain
        	callous = medium_stress_impact_gain
        }
        ai_chance = {
        	base = 20
        	ai_value_modifier = {
				ai_zeal = -1
				ai_energy = 0.5
				ai_rationality = 0.5
			}
        	modifier = { # Weight down.
        		add = -100
        		THIS = ROOT.faith.religious_head
        	}
        	modifier = { # Weight down for stress.
        		add = -30
        		has_trait = zealous
        	}
        	modifier = { # Weight down for stress.
        		add = -15
        		has_trait = stubborn
        	}
        	modifier = { # Weight down for stress.
        		add = -15
        		has_trait = lazy
        	}
        	modifier = { # Weight down for stress.
        		add = -15
        		has_trait = callous
        	}
        }
    }

    option = { # Theological kumbaya
        name = court.8120.c
        trigger = { has_trait = theologian }
        reverse_add_opinion = {
        	target = scope:accuser
        	modifier = respect_opinion
        	opinion = 15
        }
        reverse_add_opinion = {
        	target = scope:refuter
        	modifier = respect_opinion
        	opinion = 15
        }
        stress_impact = {
        	base = minor_stress_impact_loss
        	diplomat = minor_stress_impact_loss
        	cynical = medium_stress_impact_gain
        	eccentric = minor_stress_impact_gain
        }
        ai_chance = {
        	base = 100
        	ai_value_modifier = {
				ai_zeal = 0.5
				ai_rationality = 1
			}
        	modifier = { # Weight up.
        		add = 15
        		has_trait = diplomat
        	}
        	modifier = { # Weight down for stress.
        		add = -15
        		has_trait = cynical
        	}
        }
    }

    option = { # Defender of the faith
        name = court.8120.d
        trigger = { has_trait = zealous }
        create_artifact = {	
			name = my_holy_book
			description = my_holy_book_description
			type = journal
			visuals = book
			modifier = artifact_monthly_piety_2_modifier
		}
        if = {
        	limit = { faith = scope:refuter.faith }
        	scope:accuser = { select_and_move_to_pool_effect = yes }
        	reverse_add_opinion = {
	        	target = scope:accuser
	        	modifier = insulted_opinion
	        	opinion = -15
	        }
	        reverse_add_opinion = {
	        	target = scope:refuter
	        	modifier = pious_opinion
	        	opinion = 15
	        }
        }
        else = {
    		scope:refuter = { select_and_move_to_pool_effect = yes }
        	reverse_add_opinion = {
	        	target = scope:refuter
	        	modifier = insulted_opinion
	        	opinion = -15
	        }
        	reverse_add_opinion = {
	        	target = scope:accuser
	        	modifier = pious_opinion
	        	opinion = 15
        	}
        }
    	every_vassal = {
    		limit = { court_8120_zealous_vassal_trigger = yes } # root faith, zealous, not accuser/refuter
    		custom = court.8120.d.tt
    		add_opinion = {
    			target = root
	        	modifier = pious_opinion
	        	opinion = 10
    		}
    	}
        hidden_effect = {
        	every_courtier_or_guest = {
        		limit = { court_8120_zealous_vassal_trigger = yes } # root faith, zealous, not accuser/refuter
        		add_opinion = {
        			target = root
		        	modifier = pious_opinion
		        	opinion = 10
        		}
        	}
        }
        stress_impact = {
        	base = minor_stress_impact_loss
        	lazy = major_stress_impact_gain
        }
        ai_chance = {
        	base = 100
        	ai_value_modifier = {
				ai_zeal = 1
				ai_energy = -1
			}
        	modifier = { # Weight up.
        		add = 15
        		has_trait = diplomat
        	}
        	modifier = { # Weight down for stress.
        		add = -30
        		has_trait = lazy
        	}
        }
    }

    option = { # Admonish
        name = court.8120.e
        if = {
        	limit = { faith = scope:refuter.faith }
        	reverse_add_opinion = {
	        	target = scope:accuser
	        	modifier = insulted_opinion
	        	opinion = -10
	        }
	        reverse_add_opinion = {
	        	target = scope:refuter
	        	modifier = pious_opinion
	        	opinion = 10
	        }
	        progress_towards_rival_effect = {
	        	REASON = rival_refuted_faith
				CHARACTER = scope:accuser
				OPINION = 0
			}
        }
        else = {
 			scope:refuter = { select_and_move_to_pool_effect = yes }
        	reverse_add_opinion = {
	        	target = scope:refuter
	        	modifier = insulted_opinion
	        	opinion = -10
	        }
        	reverse_add_opinion = {
	        	target = scope:accuser
	        	modifier = pious_opinion
	        	opinion = 10
		    }
        }
        stress_impact = {
        	cynical = medium_stress_impact_gain
        }
        ai_chance = {
        	base = 100
        	ai_value_modifier = {
				ai_zeal = 0.5
				ai_compassion = -0.5
			}
        	modifier = { # Weight down for stress.
        		add = -15
        		has_trait = cynical
        	}
        }
    }

    option = { # Dismiss
        name = court.8120.f
        add_piety = miniscule_piety_gain
        reverse_add_opinion = {
        	target = scope:accuser
        	modifier = humbled_opinion
        	opinion = -5
        }
  		reverse_add_opinion = {
        	target = scope:refuter
        	modifier = humbled_opinion
        	opinion = -5
        }
        ai_chance = {
        	base = 100
        }
    }

    after = { remove_variable = court_8120_issue }
}
