﻿namespace = ep1_flavor

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

##################################################
# 0001 - 0010	Learn of the secret scion of an existing neighbouring court.
# 0011 - 0020	Diplomats from nearby realms have trashed your favourite hall.
# 0021 - 0030	You compete with another realm that shares your court language for grandeur.
# 0031 - 0040	Several fresh young scholars are newly arrived at court & need guidance.
##################################################

##################################################
# The Secret DaughterSon
# by Ewan Cowhig Croft
# 0001 - 0010
##################################################

scripted_trigger ep1_flavour_0001_relative_appropriate_to_marry_trigger = {
	can_marry_trigger = yes
	is_adult = yes
	liege = root
	# Make sure we don't accidentally nab a player.
	NOT = { is_ai = no }
}

scripted_trigger ep1_flavour_0001_valid_to_have_secret_scion_trigger = {
	# Standards checks: make sure the ruler is of the correct age, decently fertile, etc.
	is_ai = yes
	any_spouse = {
		count = all
		is_ai = yes
	}
	can_have_children = yes
	fertility >= medium_fertility
	## Age needs to be relatively high so that the scion can be created successfully.
	age >= ep1_flavour_0001_scion_parent_minimum_age_value
	## Having a dynasty makes things more fun
	exists = dynasty
	## Soulmates are too complex to really handle hidden bastards for.
	num_of_relation_soulmate = 0
	## And though heterosexual, bisexual, and asexual characters might also conceivably have such a child, homosexual characters generally shouldn't.
	NOT = { has_sexuality = homosexual }
	# Hostility checks: filter out anyone who's at war with root, a bad relation, or just otherwise wouldn't be a good fit.
	NOR = {
		is_at_war_with = root
		has_any_bad_relationship_with_root_trigger = yes
		# Faiths that'd never consider marrying you are bad picks.
		faith = {
			faith_hostility_level = {
				target = root.faith
				value >= faith_evil_level
			}
		}
	}
	# Make sure we have someone who'd be personally concerned about the existence of bastards.
	## I.e, their faith discriminates against bastards. We check this manually both for ease of triggers & to keep things simple.
	faith = {
		OR = {
			has_doctrine_parameter = bastards_legitimize
			has_doctrine_parameter = bastards_always
		}
	}
	# And finally someone who might actually actively empathise enough to try and protect their bastard from a harsh existence.
	NOR = {
		has_trait = lazy
		has_trait = honest
		has_trait = just
		has_trait = trusting
		has_trait = callous
		has_trait = sadistic
	}
}

scripted_effect ep1_flavour_0001_marry_suitor_effect = {
	# Diplo duel to try to pressure for the marriage.
	duel = {
		skill = diplomacy
		target = scope:scion_parent
		# Root wins, obtaining a forceful marriage alliance.
		50 = {
			compare_modifier = {
				value = scope:duel_value
				multiplier = 3.5
				min = -49
			}
			desc = ep1_flavor.0001.a.tt.success
			send_interface_toast = {
				title = ep1_flavor.0001.a.tt.success
				left_icon = scope:scion_parent
				right_icon = scope:scion_actual
				# Calc all the bastard stuff.
				ep1_flavour_0001_reveal_secret_child_effect = yes
				# Scope:prospective_spouse & scope:scion_actual marry immediately or asap through grand wedding
				if = {
					limit = {
						has_ep2_dlc_trigger = yes
					}
					create_grand_wedding_betrothal = {
						SPOUSE_1 = scope:prospective_spouse
						SPOUSE_2 = scope:scion_actual
						HOST = root
						PROMISEE = scope:scion_parent
					}
				}
				else = { scope:prospective_spouse = { marry = scope:scion_actual } }
				# Create an alliance root & scope:scion_parent via the married couple.
				create_alliance = {
					target = scope:scion_parent
					allied_through_owner = scope:prospective_spouse
					allied_through_target = scope:scion_actual
				}
				# Scope:scion_parent steps rivalry with root.
				progress_towards_rival_effect = {
					REASON = rival_succeeded_force_marriage
					CHARACTER = scope:scion_parent
					OPINION = -50
				}
			}
		}
		# Scope:scion_parent obfuscates till they can whisk away their child.
		50 = {
			compare_modifier = {
				value = scope:duel_value
				multiplier = -3.5
				min = -49
			}
			desc = ep1_flavor.0001.a.tt.failure
			send_interface_toast = {
				title = ep1_flavor.0001.a.tt.failure
				left_icon = scope:scion_parent
				right_icon = scope:scion_actual
				# Scope:scion gets away.
				custom_tooltip = ep1_flavor.0001.tt.scion_escapes
				# Root loses prestige.
				add_prestige = major_prestige_loss
				# Scope:scion_parent steps rivalry with root, but a bit less because they still won.
				progress_towards_rival_effect = {
					REASON = rival_attempted_to_force_marriage
					CHARACTER = scope:scion_parent
					OPINION = -25
				}
			}
		}
	}

	# Sort stress.
	## If scope:scion_actual is at least a royal bastard, then arrogant characters are a little happy.
	if = {
		limit = { scope:scion_parent.primary_title.tier >= tier_kingdom }
		stress_impact = {
			arrogant = miniscule_stress_impact_loss
			humble = medium_stress_impact_gain
			honest = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
		}
	}
	## Otherwise, they don't have a feeling.
	else = {
		stress_impact = {
			humble = medium_stress_impact_gain
			honest = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
		}
	}
}

scripted_effect ep1_flavour_0001_reveal_secret_child_effect = {
	# First, set up the sex as "recent" so we can pull the reveal.
	## The affair partner's gender is picked deterministically so that it could result in pregnancy.
	scope:scion_parent = {
		if = {
			limit = { is_female = yes }
			set_variable = {
				name = had_recent_sex
				value = flag:male
			}
		}
		else = {
			set_variable = {
				name = had_recent_sex
				value = flag:female
			}
		}
	}
	# Then, do the actual reveal.
	## First the effects of the extra-marital sex.
	### We regard this as the same as cheating actively for simplicity and the sake of the scale of the lie.
	extramaritial_sex_exposure_consequences_with_had_recent_sex_var_effect = { SPOUSE_EVENT = no }
	# Finally, deal with scope:scion_actual's transformation.
	scope:scion_actual = {
		# Then make scope:scion_actual a bastard.
		add_trait = bastard
		# Obfuscate a few irrelevant bits.
		hidden_effect = {
			# Set up their legal parentage.
			scope:scion_parent = {
				if = {
					limit = { is_female = yes }
					scope:scion_actual = { set_mother = scope:scion_parent }
				}
				else = {
					scope:scion_actual = { set_father = scope:scion_parent }
				}
			}
			# Plus, dynasty.
			set_house = scope:scion_parent.house
		}
	}
	scope:scion_parent = {
		if = {
			limit = {
				OR = {
					AND = {
						is_male = yes
						NOT = {
							faith = { has_doctrine = doctrine_adultery_men_accepted }
						}
					}
					AND = {
						is_female = yes
						NOT = {
							faith = { has_doctrine = doctrine_adultery_women_accepted }
						}
					}
				}

			}
			add_trait = adulterer
		}
	}
}

#	Learn of the secret scion of an existing neighbouring court.
ep1_flavor.0001 = {
	type = character_event
	title = ep1_flavor.0001.t
	desc = ep1_flavor.0001.desc
	theme = diplomacy
	left_portrait = {
		character = scope:scion_parent
		animation = disbelief
		outfit_tags = { beggar_rags }
	}
	right_portrait = {
		character = scope:scion_actual
		animation = worry
		outfit_tags = { beggar_rags }
	}
	lower_center_portrait = scope:prospective_spouse
	override_background = { reference = tavern }

	cooldown = { years = 100 }

	trigger = {
		# Standard checks.
		has_royal_court = yes
		has_dlc_feature = royal_court
		is_available_at_peace_adult = yes
		# Is suitable/has suitable family for the marriage.
		OR = {
			can_marry_trigger = yes
			any_close_family_member = { ep1_flavour_0001_relative_appropriate_to_marry_trigger = yes }
		}
		# Has a valid neighbour or vassal.
		OR = {
			any_neighboring_and_across_water_realm_same_rank_owner = { ep1_flavour_0001_valid_to_have_secret_scion_trigger = yes }
			any_vassal = { ep1_flavour_0001_valid_to_have_secret_scion_trigger = yes }
		}
	}

	weight_multiplier = {
		base = 1

		# Court weightings: plug in a court type that should see this event more often.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_diplomatic }
	}

	immediate = {
		# First up, we decide whether root or a relative of theirs will be the marriable candidate.
		## If root can marry, we use root.
		if = {
			limit = { can_marry_trigger = yes }
			save_scope_as = prospective_spouse
		}
		## Otherwise, pick a family member.
		else = {
			random_close_family_member = {
				limit = { ep1_flavour_0001_relative_appropriate_to_marry_trigger = yes }
				save_scope_as = prospective_spouse
			}
		}
		# Now we need to select a suitable dynasty to add the scion to.
		## Grab every candidate, chuck 'em in a list.
		every_neighboring_and_across_water_realm_same_rank_owner = {
			limit = { ep1_flavour_0001_valid_to_have_secret_scion_trigger = yes }
			add_to_list = valid_scion_candidates_list
		}
		every_vassal = {
			limit = { ep1_flavour_0001_valid_to_have_secret_scion_trigger = yes }
			add_to_list = valid_scion_candidates_list
		}
		## Comb through the list for the most suitable dynasty.
		ordered_in_list = {
			list = valid_scion_candidates_list
			order_by = {
				value = 0
				# We prefer characters outside your sub-realm.
				if = {
					limit = {
						liege != root
					}
					add = 100
				}
				# Ideally ones with at least a bit of the relevant skills.
				if = {
					limit = { diplomacy >= decent_skill_rating }
					add = 15
				}
				if = {
					limit = { intrigue >= decent_skill_rating }
					add = 15
				}
				# Certain traits really weight up the chances of the candidate.
				if = {
					limit = { has_trait = lustful }
					add = 20
				}
				if = {
					limit = { has_trait = diligent }
					add = 20
				}
				if = {
					limit = { has_trait = paranoid }
					add = 20
				}
				if = {
					limit = { has_trait = seducer }
					add = 20
				}
				if = {
					limit = { has_trait = schemer }
					add = 20
				}
				if = {
					limit = { has_trait = compassionate }
					add = 20
				}
			}
			save_scope_as = scion_parent
		}
		## Take off scope:scion_parent's headgear for the event.
		scope:scion_parent = { add_character_flag = no_headgear }
		# Finally, we create the scion themselves.
		## Basic setup.
		create_character = {
			location = scope:scion_parent.capital_county.title_province
			template = hidden_scion_template
			save_scope_as = scion_actual
		}
		## Adjust a few details.
		hidden_effect = {
			scope:scion_actual = {
				# Copy over their genetics.
				copy_inheritable_appearance_from = scope:scion_parent
				# Add the sheltered modifier.
				add_character_modifier = raised_in_secrecy_modifier
			}
		}
	}

	# Preferred candidate: No doubt scope:scion_parent was simply holding HerHis hand for me?
	option = {
		name = ep1_flavor.0001.a
		trigger = { this = scope:prospective_spouse }

		ep1_flavour_0001_marry_suitor_effect = yes

		# Stress impact taken care of in the scripted effect.
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 0.5
				ai_rationality = 0.25
				ai_compassion = -0.5
			}
		}
	}

	# Backup candidate: No doubt scope:scion_parent was simply holding HerHis hand for my [Relative]?
	option = {
		name = ep1_flavor.0001.b
		trigger = {
			this != scope:prospective_spouse
		}

		ep1_flavour_0001_marry_suitor_effect = yes

		# Stress impact taken care of in the scripted effect.
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 0.5
				ai_rationality = 0.25
				ai_compassion = -0.5
			}
		}
	}

	# Grab them both, the world must know!
	option = {
		name = ep1_flavor.0001.c

		# You attempt to reveal scope:scion_actual's existence, giving scope:scion_parent fairly little time to completely erase HerHis existence.
		duel = {
			skill = intrigue
			target = scope:scion_parent
			# Scope:scion_parent leaves a trace, and you become the QueenKing of gossip for a time.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = ep1_flavor.0001.c.tt.success
				send_interface_toast = {
					title = ep1_flavor.0001.c.tt.success
					left_icon = scope:scion_parent
					# Gain some permanent intrigue.
					add_intrigue_skill = 2
					# Scope:scion_actual is revealed. Consequences ensue.
					ep1_flavour_0001_reveal_secret_child_effect = yes
					## Remember to mark this as having happened.
					save_scope_value_as = {
						name = scion_revealed
						value = yes
					}
					# Become rivals with scope:scion_parent immediately (nemeses if they're vengeful).
					if = {
						limit = {
							scope:scion_parent = { has_trait = vengeful }
							can_set_relation_nemesis_trigger = { CHARACTER = scope:scion_parent }
						}
						set_relation_nemesis = {
							target = scope:scion_parent
							reason = rival_exposed_bastard
						}
					}
					else_if = {
						limit = {
							can_set_relation_rival_trigger = { CHARACTER = scope:scion_parent }
						}
						set_relation_rival = {
							target = scope:scion_parent
							reason = rival_exposed_bastard
						}
					}
					else = {
						reverse_add_opinion = {
							target = scope:scion_parent
							modifier = hate_opinion
							opinion = -50
						}
					}
				}
			}
			# You're flummoxed by scope:scion_parent's trickery, leaving your accusations ridiculously baseless.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = ep1_flavor.0001.c.tt.failure
				send_interface_toast = {
					title = ep1_flavor.0001.c.tt.failure
					left_icon = scope:scion_parent
					# Scope:scion gets away.
					custom_tooltip = ep1_flavor.0001.tt.scion_escapes
					# Lose a load of prestige.
					add_prestige = major_prestige_loss
					# Stepped rivalry with scope:scion_parent.
					progress_towards_rival_effect = {
						REASON = rival_attempted_to_reveal_offspring
						CHARACTER = scope:scion_parent
						OPINION = -25
					}
				}
			}
		}

		stress_impact = {
			honest = miniscule_stress_impact_loss
			compassionate = minor_stress_impact_gain
			deceitful = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 0.75
				ai_compassion = -0.75
			}
		}
	}

	# I'll help you, but I expect something in return...
	option = {
		name = ep1_flavor.0001.d
		trigger = {
			can_add_hook = {
				target = scope:scion_parent
				type = manipulation_hook
			}
		}

		# Scope:scion gets away.
		custom_tooltip = ep1_flavor.0001.tt.scion_escapes
		# Gain a hook on scope:scion_parent, who's also grateful for your assistance in their time of need.
		add_hook = {
			type = favor_hook
			target = scope:scion_parent
		}
		reverse_add_opinion = {
			target = scope:scion_parent
			modifier = grateful_opinion
			opinion = 50
		}

		stress_impact = {
			deceitful = miniscule_stress_impact_loss
			callous = minor_stress_impact_gain
			sadistic = minor_stress_impact_gain
			honest = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 0.5
				ai_compassion = 0.25
			}
		}
	}

	# What a pedestrian drama.
	option = {
		# Doesn't believe in bastards.
		name = {
			trigger = {
				faith = { has_doctrine_parameter = bastards_none }
			}
			text = ep1_flavor.0001.e.no_bastards
		}
		# Fallback.
		name = ep1_flavor.0001.e.fallback

		# Scope:scion gets away.
		custom_tooltip = ep1_flavor.0001.tt.scion_escapes
		# You pay the stranger no mind; scope:scion_parent is relieved.
		reverse_add_opinion = {
			target = scope:scion_parent
			modifier = relieved_opinion
			opinion = 25
		}

		stress_impact = {
			base = medium_stress_impact_loss
			shy = miniscule_stress_impact_loss
			gregarious = minor_stress_impact_gain
			paranoid = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = -0.5
				ai_energy = -0.75
			}
		}
	}

	# Do a little clean-up.
	after = {
		# Afterwards, if scope:scion_actual isn't married or revealed, quietly disappear them.
		hidden_effect = {
			scope:scion_actual = {
				if = {
					limit = {
						is_married = no
						NOT = { exists = scope:scion_revealed }
					}
					death = { death_reason = death_vanished }
				}
			}
		}
		# Give scope:scion_parent their hat back.
		scope:scion_parent = { remove_character_flag = no_headgear }
	}
}

##################################################
# An Absolute Shambles
# by Ewan Cowhig Croft
# 0011 - 0020
##################################################

scripted_trigger ep1_flavour_0011_valid_diplomats_trigger = {
	# The title must be created first off.
	is_title_created = yes
	holder = {
		# Make sure we're not looking at root.
		this != root
		# Now discard any that lack royal courts or aren't in diplomatic range.
		has_royal_court = yes
		has_dlc_feature = royal_court
		in_diplomatic_range = root
		# Then any that lack a chancellor.
		exists = cp:councillor_chancellor
		# Finally, their chancellor must be available & at peace.
		cp:councillor_chancellor = { is_available_at_peace_ai_adult = yes }
	}
}

scripted_effect ep1_flavour_0011_friendly_diplomats_effect = {
	reverse_add_opinion = {
		target = scope:diplomat_1
		modifier = relieved_opinion
		opinion = $OPINION$
	}
	reverse_add_opinion = {
		target = scope:diplomat_2
		modifier = relieved_opinion
		opinion = $OPINION$
	}
	## Make them potential friends if appropriate.
	hidden_effect = {
		if = {
			limit = {
				can_set_relation_friend_trigger = { CHARACTER = scope:diplomat_1 }
			}
			set_relation_potential_friend = scope:diplomat_1
		}
		if = {
			limit = {
				can_set_relation_friend_trigger = { CHARACTER = scope:diplomat_2 }
			}
			set_relation_potential_friend = scope:diplomat_2
		}
	}
}

#	Diplomats from nearby realms have trashed your favourite hall.
ep1_flavor.0011 = {
	type = character_event
	title = ep1_flavor.0011.t
	desc = ep1_flavor.0011.desc
	theme = diplomacy
	left_portrait = {
		character = scope:diplomat_1
		animation = shock
	}
	right_portrait = {
		character = scope:diplomat_2
		animation = shame
	}
	override_background = { reference = feast }

	cooldown = { years = 10 }

	trigger = {
		# Standard checks.
		has_royal_court = yes
		has_dlc_feature = royal_court
		is_available_at_peace_adult = yes
		# Any two valid foreign chancellors are available.
		any_kingdom = {
			count >= 2
			ep1_flavour_0011_valid_diplomats_trigger = yes
		}
	}

	weight_multiplier = {
		base = 1

		# Court weightings: plug in a court type that should see this event more often.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_diplomatic }
	}

	immediate = {
		# Grab all applicable chancellors.
		every_kingdom = {
			limit = { ep1_flavour_0011_valid_diplomats_trigger = yes }
			holder.cp:councillor_chancellor = { add_to_list = valid_chancellors_list }
		}
		# Now, pick out the two most relevant chancellors.
		ordered_in_list = {
			list = valid_chancellors_list
			order_by = {
				value = 0
				# Prio up realms you're allied with, since they'd have good cause.
				if = {
					limit = {
						liege = {
							any_ally = { this = root }
						}
					}
					add = 100
				}
				# Plus anyone where there's a degree of mutual religious tolerance.
				if = {
					limit = {
						faith = {
							faith_hostility_level = {
								target = root.faith
								value <= faith_hostile_level
							}
						}
						save_temporary_scope_as = current_char
						root.faith = {
							faith_hostility_level = {
								target = scope:current_char.faith
								value <= faith_hostile_level
							}
						}
					}
					add = 50
				}
				# Various traits make it more likely.
				## Obviously drunkards.
				if = {
					limit = { has_trait = drunkard }
					add = 10
				}
				## Revellers of all stripes.
				if = {
					limit = { has_trait = lifestyle_reveler }
					add = 20
				}
				## Gluttons.
				if = {
					limit = { has_trait = gluttonous }
					add = 10
				}
				## Arbitrary folks.
				if = {
					limit = { has_trait = arbitrary }
					add = 10
				}
				## Gregarious party-throwers.
				if = {
					limit = { has_trait = gregarious }
					add = 10
				}
				# And a few traits make it less likely.
				## Recluses.
				if = {
					limit = { has_trait = reclusive }
					add = -10
				}
				## The temperate.
				if = {
					limit = { has_trait = temperate }
					add = -10
				}
				## Just folks.
				if = {
					limit = { has_trait = just }
					add = -10
				}
				## The shy.
				if = {
					limit = { has_trait = shy }
					add = -10
				}
				# Diplomatic skill decreases it, since better diplomats are less likely to make a scene.
				add = {
					value = diplomacy
					multiply = -1
				}
			}
			max = 2
			if = {
				limit = {
					NOT = { exists = scope:diplomat_1 }
				}
				save_scope_as = diplomat_1
			}
			else_if = {
				limit = {
					NOT = {
						this = scope:diplomat_1
						exists = scope:diplomat_2
					}
				}
				save_scope_as = diplomat_2
			}
		}
		# Set up a cost based on root's lodgings amenity.
		if = {
			limit = {
				amenity_level = {
					target = court_lodging_standards
					value <= low_amenity_level
				}
			}
			set_variable = {
				name = reimbursement_cost
				value = {
					value = minor_gold_value
					multiply = 0.5
					round = yes
				}
			}
		}
		if = {
			limit = {
				amenity_level = {
					target = court_lodging_standards
					value <= medium_amenity_level
				}
			}
			set_variable = {
				name = reimbursement_cost
				value = {
					value = medium_gold_value
					multiply = 0.5
					round = yes
				}
			}
		}
		if = {
			limit = {
				amenity_level = {
					target = court_lodging_standards
					value <= high_amenity_level
				}
			}
			set_variable = {
				name = reimbursement_cost
				value = {
					value = major_gold_value
					multiply = 0.5
					round = yes
				}
			}
		}
		if = {
			limit = {
				amenity_level = {
					target = court_lodging_standards
					value >= very_high_amenity_level
				}
			}
			set_variable = {
				name = reimbursement_cost
				value = {
					value = massive_gold_value
					multiply = 0.5
					round = yes
				}
			}
		}
		## No more gold for max, since we've already reached a pretty expensive bill.
		# Add a negative modifier for the trashed hall.
		add_character_modifier = {
			modifier = legendary_party_aftermath_modifier
			years = 10
		}
		scope:diplomat_2 = {
			add_character_flag = is_naked
		}
	}

	# You will pay for these damages, you lickspittle curs!
	option = {
		name = ep1_flavor.0011.a

		# Deduct half of the damages from each diplomat, pay it towards root.
		## We're not fussed if this cost is unexpected for the diplomats: they shouldn't have messed with the hall.
		scope:diplomat_1 = {
			pay_short_term_gold = {
				target = root
				gold = root.var:reimbursement_cost
			}
		}
		scope:diplomat_2 = {
			pay_short_term_gold = {
				target = root
				gold = root.var:reimbursement_cost
			}
		}
		# Remove the negative modifier.
		remove_character_modifier = legendary_party_aftermath_modifier
		# Gain a replacement modifier.
		add_character_modifier = {
			modifier = lacking_diplomatic_munity_modifier
			years = 10
		}

		stress_impact = {
			greedy = miniscule_stress_impact_loss
			wrathful = miniscule_stress_impact_loss
			calm = medium_stress_impact_gain
			generous = medium_stress_impact_gain
			forgiving = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_vengefulness = 1
				ai_greed = 0.5
			}
		}
	}

	# Alright, you trashed it, you can clean it up. SERVANTS! A mop!
	option = {
		name = ep1_flavor.0011.b

		# The diplomats are fairly upset with this humiliation.
		reverse_add_opinion = {
			target = scope:diplomat_1
			modifier = humiliated_opinion
			opinion = -30
		}
		reverse_add_opinion = {
			target = scope:diplomat_2
			modifier = humiliated_opinion
			opinion = -30
		}
		## Make them potential rivals if appropriate.
		hidden_effect = {
			if = {
				limit = {
					can_set_relation_rival_trigger = { CHARACTER = scope:diplomat_1 }
				}
				set_relation_potential_rival = scope:diplomat_1
			}
			if = {
				limit = {
					can_set_relation_rival_trigger = { CHARACTER = scope:diplomat_2 }
				}
				set_relation_potential_rival = scope:diplomat_2
			}
		}
		# Remove the negative modifier.
		remove_character_modifier = legendary_party_aftermath_modifier
		# Replace it with a positive one.
		add_character_modifier = {
			modifier = humbling_hall_modifier
			years = 10
		}
		# Whack a lil CGV in for your swagger.
		change_current_court_grandeur = miniscule_court_grandeur_gain

		stress_impact = {
			just = miniscule_stress_impact_loss
			calm = miniscule_stress_impact_loss
			wrathful = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = 0.5
				ai_vengefulness = -0.5
			}
		}
	}

	# Oh no, this party's not over yet: someone fill my goblet!
	option = {
		name = ep1_flavor.0011.c
		trigger = {
			NOT = { has_trait = lifestyle_reveler }
		}

		# The diplomats are immensely happy.
		ep1_flavour_0011_friendly_diplomats_effect = { OPINION = 30 }
		# The modifier gets worse in some ways, better in others.
		remove_character_modifier = legendary_party_aftermath_modifier
		add_character_modifier = {
			modifier = mythic_party_aftermath_modifier
			years = 10
		}

		stress_impact = {
			gregarious = miniscule_stress_impact_loss
			shy = medium_stress_impact_gain
			temperate = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_sociability = 0.5
				ai_energy = 0.25
				ai_vengefulness = -0.5
			}
		}
	}

	# [Reveller] One night? Pathetic! Make way for the Party [TitleAsName]!
	option = {
		name = ep1_flavor.0011.d
		trigger = { has_trait = lifestyle_reveler }
		trait = lifestyle_reveler

		# The diplomats are even happier.
		ep1_flavour_0011_friendly_diplomats_effect = { OPINION = 50 }
		# The modifier gets *much* worse in some ways, *much* better in others.
		remove_character_modifier = legendary_party_aftermath_modifier
		add_character_modifier = {
			modifier = world_shattering_party_aftermath_modifier
			years = 10
		}

		stress_impact = {
			base = medium_stress_loss
			gregarious = miniscule_stress_impact_loss
			shy = medium_stress_impact_gain
			temperate = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_sociability = 0.75
				ai_energy = 0.55
				ai_vengefulness = -0.5
			}
		}
	}

	# [wordlessly leave the hall]
	option = {
		name = ep1_flavor.0011.e
		flavor = ep1_flavor.0011.e.tt

		# The diplomats gain stress & fear reprisal.
		scope:diplomat_1 = {
			add_opinion = {
				target = root
				modifier = scared_opinion
				opinion = -30
			}
			add_stress = major_stress_gain
		}
		scope:diplomat_2 = {
			add_opinion = {
				target = root
				modifier = scared_opinion
				opinion = -30
			}
			add_stress = major_stress_gain
		}
		# People think you inscrutable.
		add_character_modifier = {
			modifier = inscrutable_host_modifier
			years = 10
		}

		stress_impact = {
			shy = minor_stress_impact_loss
			reclusive = minor_stress_impact_loss
			wrathful = medium_stress_impact_gain
			vengeful = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_sociability = -0.25
				ai_energy = -0.5
				ai_vengefulness = -0.75
			}
		}
	}

	# Do a little clean-up.
	after = {
		# Get rid of the reimbursement cost.
		remove_variable = reimbursement_cost
		scope:diplomat_2 = {
			remove_character_flag = is_naked
		}
	}
}

##################################################
# Two Realms Separated by a Courtly Language
# by Ewan Cowhig Croft
# 0021 - 0030
##################################################

scripted_trigger ep1_flavour_0021_valid_nitpicking_courtier_trigger = {
	# A simple is available check.
	is_available_ai_adult = yes
	# Plus they speak the court language.
	knows_court_language_of = root
}

scripted_trigger ep1_flavour_0021_valid_wrong_spelling_realm_trigger = {
	# The title must be created first off.
	is_title_created = yes
	holder = {
		# Make sure we're not looking at root.
		this != root
		# For erroring reasons, double check that their court is royal.
		has_royal_court = yes
		has_dlc_feature = royal_court
		# Now ensure they speak the same court language.
		has_same_court_language = root
		# And that they can speak their *own* court language.
		knows_court_language_of = this
		# Finally, discard any that aren't in diplomatic range.
		in_diplomatic_range = root
		# ... or players.
		is_ai = yes
	}
}

scripted_trigger ep1_flavour_0021_valid_characters_to_fuss_trigger = {
	# Must speak the court language.
	knows_court_language_of = $OWN_COURT$
	# And be an AI who's around and about.
	is_available_at_peace_ai_adult = yes
}

scripted_trigger ep1_flavour_0021_different_cultured_realms_trigger = {
	$THIS$ = {
		any_courtier = {
			percent >= 0.5
			culture = $THIS$.culture
		}
		OR = {
			any_sub_realm_county = {
				count >= 10
				culture = $THIS$.culture
			}
			culture = {
				any_culture_county = {
					percent >= 0.25
					OR = {
						holder = $THIS$
						holder = {
							any_liege_or_above = { this = $THIS$ }
						}
					}
				}
			}
			any_sub_realm_county = {
				percent >= 0.5
				culture = $THIS$.culture
			}
		}
	}
}

scripted_effect ep1_flavour_0021_apply_mutual_court_opinions_effect = {
	hidden_effect = {
		every_in_list = {
			list = root_court_list
			save_temporary_scope_as = current_char
			every_in_list = {
				list = scope_rival_monarch_court_list
				add_opinion = {
					target = scope:current_char
					modifier = $OPINION_TYPE$
					opinion = $OPINION_VALUE$
				}
			}
		}
		every_in_list = {
			list = scope_rival_monarch_court_list
			save_temporary_scope_as = current_char
			every_in_list = {
				list = root_court_list
				add_opinion = {
					target = scope:current_char
					modifier = $OPINION_TYPE$
					opinion = $OPINION_VALUE$
				}
			}
		}
	}
}

scripted_effect ep1_flavour_0021_apply_mutual_cultural_dislike_effect = {
	if = {
		limit = {
			# First, check they're not the same culture.
			culture != scope:rival_monarch.culture
			# Then make sure both actually have a decent chunk of courtiers of their culture around, and aren't ruling some total adventurer kingdom..
			ep1_flavour_0021_different_cultured_realms_trigger = { THIS = root }
			ep1_flavour_0021_different_cultured_realms_trigger = { THIS = scope:rival_monarch }
		}
		culture = {
			change_cultural_acceptance = {
				target = scope:rival_monarch.culture
				value = $ACCEPTANCE_CHANGE$
				desc = $ACCEPTANCE_DESC$
			}
		}
	}
}

#	You compete with another realm that shares your court language for grandeur.
ep1_flavor.0021 = {
	type = character_event
	title = ep1_flavor.0021.t
	desc = ep1_flavor.0021.desc
	theme = diplomacy
	left_portrait = {
		character = scope:nitpicker
		animation = scheme
	}
	right_portrait = {
		character = scope:rival_monarch
		animation = personality_vengeful
	}

	cooldown = { years = 5 }

	trigger = {
		# Standard checks.
		has_royal_court = yes
		has_dlc_feature = royal_court
		is_available_at_peace_adult = yes
		# For flavour reasons, root must be able to speak their own court language.
		knows_court_language_of = this
		# You'll also need someone in your court who can be the focal point.
		## This might occasionally make dumb selections, but honestly, that's sorta in the spirit of the quibbling.
		any_courtier = { ep1_flavour_0021_valid_nitpicking_courtier_trigger = yes }
		# Make sure we've got a suitable opposing realm.
		OR = {
			any_kingdom = { ep1_flavour_0021_valid_wrong_spelling_realm_trigger = yes }
			any_empire = { ep1_flavour_0021_valid_wrong_spelling_realm_trigger = yes }
		}
	}

	weight_multiplier = {
		base = 1

		# Court weightings: plug in a court type that should see this event more often.
		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_diplomatic }
	}

	immediate = {
		# Select an opposing realm.
		## Kingdoms look for kingdoms...
		if = {
			limit = { highest_held_title_tier = tier_kingdom }
			random_kingdom = {
				limit = { ep1_flavour_0021_valid_wrong_spelling_realm_trigger = yes }
				save_scope_as = rival_realm
				holder = { save_scope_as = rival_monarch }
			}
			# ... but otherwise will take an empire.
			if = {
				limit = {
					NOT = { exists = scope:rival_realm }
				}
				random_empire = {
					limit = { ep1_flavour_0021_valid_wrong_spelling_realm_trigger = yes }
					save_scope_as = rival_realm
					holder = { save_scope_as = rival_monarch }
				}
			}
		}
		## Empires look for empires...
		else = {
			random_empire = {
				limit = { ep1_flavour_0021_valid_wrong_spelling_realm_trigger = yes }
				save_scope_as = rival_realm
				holder = { save_scope_as = rival_monarch }
			}
			# ... but will otherwise take kingdoms.
			if = {
				limit = {
					NOT = { exists = scope:rival_realm }
				}
				random_kingdom = {
					limit = { ep1_flavour_0021_valid_wrong_spelling_realm_trigger = yes }
					save_scope_as = rival_realm
					holder = { save_scope_as = rival_monarch }
				}
			}
		}
		# Grab a nitpicking courtier.
		## We do this after selecting the realm so that we can weight against poor-choice characters.
		random_courtier = {
			limit = { ep1_flavour_0021_valid_nitpicking_courtier_trigger = yes }
			weight = {
				base = 0
				# Weight up according to learning.
				modifier = { add = learning }
				# Plus a few traits make it more likely.
				modifier = {
					add = 10
					has_trait = arrogant
				}
				modifier = {
					add = 10
					has_trait = scholar
				}
				## Y'know, assuming you're just a stickler for the rules of language too.
				modifier = {
					add = 5
					has_trait = just
				}
				# And a few others less likely.
				modifier = {
					add = -10
					has_trait = humble
				}
				## And, as with just, assuming that you also don't much care for the rules of language.
				modifier = {
					add = -5
					has_trait = arbitrary
				}
				# Weight against characters that might identify with the other realm.
				modifier = {
					add = -20
					any_close_or_extended_family_member = { this = scope:rival_monarch }
				}
				modifier = {
					add = -20
					culture = scope:rival_monarch.culture
				}
			}
			save_scope_as = nitpicker
		}
		# Nab both courts for effects.
		## First root.
		every_courtier = {
			limit = {
				ep1_flavour_0021_valid_characters_to_fuss_trigger = { OWN_COURT = root }
			}
			add_to_list = root_court_list
		}
		every_councillor = {
			limit = {
				ep1_flavour_0021_valid_characters_to_fuss_trigger = { OWN_COURT = root }
				# Ensure that a vassal kingdom isn't added as disapproving of their own spelling.
				this != scope:rival_monarch
			}
			add_to_list = root_court_list
		}
		## Then scope:rival_monarch.
		scope:rival_monarch = {
			every_courtier = {
				limit = {
					ep1_flavour_0021_valid_characters_to_fuss_trigger = { OWN_COURT = scope:rival_monarch }
				}
				add_to_list = scope_rival_monarch_court_list
			}
			every_councillor = {
				limit = {
					ep1_flavour_0021_valid_characters_to_fuss_trigger = { OWN_COURT = scope:rival_monarch }
					# Ensure that a vassal kingdom isn't added as disapproving of their own spelling.
					this != root
				}
				add_to_list = scope_rival_monarch_court_list
			}
		}
	}

	# This missive is missing half the vowels! Disgusting!
	option = {
		name = ep1_flavor.0021.a

		# Both courts gain dislike of each other.
		custom_tooltip = ep1_flavor.0021.a.tt
		ep1_flavour_0021_apply_mutual_court_opinions_effect = {
			OPINION_TYPE = disgusted_opinion
			OPINION_VALUE = ep1_flavour_0021_courts_lose_opinion_actual_value
		}
		# Diplo challenge to gain CGV at their expense.
		duel = {
			skill = diplomacy
			target = scope:rival_monarch
			# PrimaryTitle.GetAdjective spellings are best!
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = ep1_flavor.0021.a.tt.success
				send_interface_toast = {
					title = ep1_flavor.0021.a.tt.success
					left_icon = scope:rival_monarch
					# Some for you...
					change_current_court_grandeur = medium_court_grandeur_gain
					# ... some from them.
					scope:rival_monarch = { change_current_court_grandeur = medium_court_grandeur_loss }
				}
			}
			# Scope:rival_monarch.PrimaryTitle.GetAdjective spellings are best!
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = ep1_flavor.0021.a.tt.failure
				send_interface_toast = {
					title = ep1_flavor.0021.a.tt.failure
					left_icon = scope:rival_monarch
					# Some from you...
					change_current_court_grandeur = medium_court_grandeur_loss
					# ... some for them.
					scope:rival_monarch = { change_current_court_grandeur = medium_court_grandeur_gain }
				}
			}
		}
		# Look at making things a bit more tense.
		ep1_flavour_0021_apply_mutual_cultural_dislike_effect = {
			ACCEPTANCE_CHANGE = minor_cultural_acceptance_loss
			ACCEPTANCE_DESC = cultural_acceptance_courtly_spelling_differences
		}

		stress_impact = {
			humble = minor_stress_impact_gain
			patient = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_energy = 0.75
				ai_rationality = -0.25
			}
		}
	}

	# Are they not our linguistic cousins?
	option = {
		name = ep1_flavor.0021.b

		# Both courts start to like each other a bit more.
		custom_tooltip = ep1_flavor.0021.b.tt
		ep1_flavour_0021_apply_mutual_court_opinions_effect = {
			OPINION_TYPE = respect_opinion
			OPINION_VALUE = ep1_flavour_0021_courts_gain_opinion_value
		}
		# Stepped friendship with the other ruler.
		progress_towards_friend_effect = {
			CHARACTER = scope:rival_monarch
			OPINION = default_friend_opinion
			REASON = friend_common_language
		}
		# And, if appropriate, a little cultural acceptance.
		ep1_flavour_0021_apply_mutual_cultural_dislike_effect = {
			ACCEPTANCE_CHANGE = minor_cultural_acceptance_gain
			ACCEPTANCE_DESC = cultural_acceptance_courtly_cousins
		}

		stress_impact = {
			arrogant = medium_stress_impact_gain
			impatient = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 0.25
				ai_energy = 0.5
			}
		}
	}

	# Two noble courts and not a sodding brain between them...
	option = {
		name = ep1_flavor.0021.c

		# Both courts gain dislike of each other.
		custom_tooltip = ep1_flavor.0021.c.tt
		ep1_flavour_0021_apply_mutual_court_opinions_effect = {
			OPINION_TYPE = disgusted_opinion
			OPINION_VALUE = ep1_flavour_0021_courts_lose_opinion_actual_value
		}
		# Look at making things a bit more tense.
		ep1_flavour_0021_apply_mutual_cultural_dislike_effect = {
			ACCEPTANCE_CHANGE = minor_cultural_acceptance_loss
			ACCEPTANCE_DESC = cultural_acceptance_courtly_spelling_differences
		}
		# Gain a modifier for your troubles.
		add_character_modifier = {
			modifier = above_petty_differences_modifier
			years = 10
		}

		stress_impact = {
			cynical = miniscule_stress_impact_loss
			patient = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 0.25
				ai_sociability = -0.5
				ai_energy = -0.75
			}
		}
	}
}

##################################################
# Fresh at Court
# by Ewan Cowhig Croft
# 0031 - 0040
##################################################

scripted_effect ep1_flavour_0031_give_random_inspiration_effect = {
	# Sort out an appropriate tooltip.
	## One for scope:scholar_1.
	if = {
		limit = { $THIS$ = scope:scholar_1 }
		custom_tooltip = ep1_flavor.0031.inspire.scholar_1.tt
	}
	## And one for scope:scholar_2.
	if = {
		limit = { $THIS$ = scope:scholar_2 }
		custom_tooltip = ep1_flavor.0031.inspire.scholar_2.tt
	}
	# We weight up the more bookish inspirations a bit.
	hidden_effect = {
		random_list = {
			300 = { create_inspiration = book_inspiration }
			200 = { create_inspiration = artisan_inspiration }
			200 = { create_inspiration = alchemy_inspiration }
			100 = { create_inspiration = weapon_inspiration }
			100 = { create_inspiration = armor_inspiration }
			100 = { create_inspiration = weaver_inspiration }
			100 = { create_inspiration = smith_inspiration }
			50 = { create_inspiration = adventure_inspiration }
			50 = { create_inspiration = bow_inspiration }
		}
	}
}

scripted_effect ep1_flavour_0031_add_both_scholars_effect = {
	# Add both scholars first-up.
	add_courtier = scope:scholar_1
	add_courtier = scope:scholar_2
	# Well, this doesn't exactly paint your court in the best light.
	change_current_court_grandeur = miniscule_court_grandeur_loss
	# Buuuut it does make pepole think better of ye.
	add_prestige = minor_prestige_gain
}

scripted_effect ep1_flavour_031_add_scholars_stress_effect = {
	stress_impact = {
		drunkard = miniscule_stress_impact_loss
		gregarious = miniscule_stress_impact_loss
		shy = $STRESS_GAIN$
		temperate = $STRESS_GAIN$
	}
}

#	Several fresh young scholars are newly arrived at court & need guidance.
ep1_flavor.0031 = {
	type = character_event
	title = ep1_flavor.0031.t
	desc = ep1_flavor.0031.desc
	theme = learning
	left_portrait = {
		character = scope:scholar_1
		animation = worry
	}
	right_portrait = {
		character = scope:scholar_2
		animation = personality_bold
	}
	override_background = { reference = tavern }

	cooldown = { years = 5 }

	trigger = {
		# Standard checks.
		has_royal_court = yes
		has_dlc_feature = royal_court
		is_available_at_peace_adult = yes
		# Since this is a fairly scholar-specific thing, we restrict it to scholarly courts.
		has_court_type = court_scholarly
	}

	weight_multiplier = {
		base = 1

		# No court weighting, since we hard-restrict this to scholarly courts.
	}

	immediate = {
		# Create the two scholars.
		## First a scholar's scholar.
		create_character = {
			template = capital_scholar_character
			location = root.capital_province
			save_scope_as = scholar_1
		}
		## Then a writer.
		create_character = {
			template = capital_writer_character
			location = root.capital_province
			save_scope_as = scholar_2
		}
	}

	# Down it, scope:scholar_1!
	option = {
		name = ep1_flavor.0031.a

		# Become friends with scope:scholar_1.
		set_relation_friend = { reason = friend_drinking_together target = scope:scholar_1 }
		# Give scope:scholar_1 an inspiration.
		scope:scholar_1 = {
			ep1_flavour_0031_give_random_inspiration_effect = { THIS = scope:scholar_1 }
		}
		# Gain both scholars.
		ep1_flavour_0031_add_both_scholars_effect = yes

		# Stress impact handled in the effect.
		ep1_flavour_031_add_scholars_stress_effect = { STRESS_GAIN = medium_stress_impact_gain }
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_sociability = 1
				ai_energy = 0.5
			}
		}
	}

	# We like to drink with scope:scholar_2, because scope:scholar_2 is our mate!
	option = {
		name = ep1_flavor.0031.b

		# Become friends with scope:scholar_2.
		set_relation_friend = { reason = friend_drinking_together target = scope:scholar_1 }
		# Give scope:scholar_2 an inspiration.
		scope:scholar_2 = {
			ep1_flavour_0031_give_random_inspiration_effect = { THIS = scope:scholar_2 }
		}
		# Gain both scholars.
		ep1_flavour_0031_add_both_scholars_effect = yes

		# Stress impact handled in the effect.
		ep1_flavour_031_add_scholars_stress_effect = { STRESS_GAIN = medium_stress_impact_gain }
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_sociability = 1
				ai_energy = 0.5
			}
		}
	}

	# There are some techniques that only experience can teach...
	option = {
		name = ep1_flavor.0031.c
		flavor = ep1_flavor.0031.c.tt
		trigger = {
			OR = {
				has_trait = scholar
				has_trait = drunkard
			}
		}
		trait = scholar
		trait = drunkard

		# Become friends with *both* scholars.
		set_relation_friend = { reason = friend_impressive_feat_of_alcoholism target = scope:scholar_1 }
		set_relation_friend = { reason = friend_impressive_feat_of_alcoholism target = scope:scholar_2 }
		# Plus, *both* get inspirations.
		scope:scholar_1 = {
			ep1_flavour_0031_give_random_inspiration_effect = { THIS = scope:scholar_1 }
		}
		scope:scholar_2 = {
			ep1_flavour_0031_give_random_inspiration_effect = { THIS = scope:scholar_2 }
		}
		# Gain a modifier that loses you a little health for the weird concoction.
		add_character_modifier = {
			modifier = what_did_i_just_drink_modifier
			years = 5
		}
		# Gain both scholars.
		ep1_flavour_0031_add_both_scholars_effect = yes

		# Stress impact handled in the effect.
		ep1_flavour_031_add_scholars_stress_effect = { STRESS_GAIN = major_stress_impact_gain }
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_sociability = 1
				ai_energy = 1
			}
		}
	}

	# These rituals are unbecoming of the scholarly.
	option = {
		name = ep1_flavor.0031.d

		# The scholars are booted.
		hidden_effect = {
			scope:scholar_1 = { silent_disappearance_effect = yes }
			scope:scholar_2 = { silent_disappearance_effect = yes }
		}
		# Gain a modifier making you out to be a bit of a miser, but a more learned one.
		add_character_modifier = {
			modifier = known_killjoy_modifier
			years = 10
		}
		# Gain a bunch of learning lifestyle XP.
		add_learning_lifestyle_xp = major_lifestyle_xp

		stress_impact = {
			shy = miniscule_stress_impact_loss
			temperate = miniscule_stress_impact_loss
			lifestyle_reveler = minor_stress_impact_gain
			drunkard = minor_stress_impact_gain
			gregarious = minor_stress_impact_gain
			gluttonous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_vengefulness = -0.25
				ai_sociability = -0.5
			}
		}
	}
}


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

scripted_trigger appropriate_eunuch_trigger = {
	is_available_ai_adult = yes
	is_eunuch_trigger = yes
	NOT = {
		has_relation_rival = root
	}
}

scripted_effect appoint_court_eunuch_effect = {
	if = {
		limit = {
			culture = { has_cultural_parameter = can_appoint_chief_eunuch }
		}
		court_position_grant_effect = {
			EMPLOYER = root
			CANDIDATE = scope:eunuch_target
			POS = chief_eunuch
		}
	}
}

# A visiting Eunuch offers their services
ep1_flavor.1000 = {
	type = character_event
	title = ep1_flavor.1000.t
	desc = ep1_flavor.1000.desc
	theme = learning
	override_background = {
		reference = sitting_room
	}

	cooldown = {
		years = 10
	}

	left_portrait = {
		character = scope:eunuch_target
		animation = flirtation
	}

	trigger = {
		has_ep1_dlc_trigger = yes
		is_landed_or_landless_administrative = yes
		culture = {
			OR = {
				has_cultural_parameter = can_castrate_prisoners
				has_cultural_parameter = eunuch_trait_bonuses
				has_cultural_parameter = court_machinations_eunuch_trait_bonuses
				has_cultural_parameter = can_appoint_chief_eunuch
			}
		}
		is_available_at_peace_adult = yes
		OR = {
			is_ai = no
			primary_title.tier > tier_duchy # So that we don't create too many characters for the AI (performance)
		}
	}

	immediate = {
		if = {
			limit = {
				any_pool_character = {
					province = root.capital_province
					appropriate_eunuch_trigger = yes
				}
			}
			random_pool_character = {
				province = root.capital_province
				limit = {
					appropriate_eunuch_trigger = yes
				}
				save_scope_as = eunuch_target
			}
		}
		else = {
			# Find an appropriate culture for the Eunuch
			if = {
				limit = {
					is_ai = no # This is gonna be expensive, exclude AI's
					any_culture_global = {
						has_cultural_parameter = can_castrate_prisoners
					}
				}
				random_culture_global = {
					limit = {
						has_cultural_parameter = can_castrate_prisoners
					}
					weight = { # Upweight for your own culture if it's valid (more greeks in greece, but the potential for east africans to visit, etc)
						base = 1
						modifier = {
							add = 2
							this = root.culture
						}
						modifier = {
							factor = 0
							this != root.culture
							NOT = {
								any_culture_county = { # This is the expensive part
									title_province = {
										squared_distance = { target = root.capital_province value < squared_distance_massive }
									}
								}
							}
						}
					}
					save_scope_as = eunuch_target_culture
				}
			}
			else = {
				root.culture = {
					save_scope_as = eunuch_target_culture
				}
			}
			create_character = {
				location = root.capital_province
				culture = scope:eunuch_target_culture
				dynasty = none
				template = random_learned_eunuch_character
				save_scope_as = eunuch_target
			}
		}

		if = { # Find somewhere else for the eunuch to move if they do not get employment
			limit = {
				any_neighboring_and_across_water_top_liege_realm = {
					always = yes
				}
			}
			random_neighboring_and_across_water_top_liege_realm = {
				save_scope_as = new_court
			}
		}

		if = { # Save old court eunuch if relevant
			limit = { employs_court_position = chief_eunuch_court_position }
			random_court_position_holder = {
				type = chief_eunuch_court_position
				save_scope_as = old_holder
			}
		}
	}

	option = { # Accept the Eunuch's offer
		name = ep1_flavor.1000.a

		pay_short_term_gold = {
			target = scope:eunuch_target
			gold = root.tiny_gold_value
		}

		add_courtier = scope:eunuch_target

		appoint_court_eunuch_effect = yes

		scope:eunuch_target = {
			add_opinion = {
				target = root
				opinion = 50
				modifier = grateful_opinion
			}
			add_character_flag = {
				flag = blocked_from_leaving
				years = 25
			}
		}

		stress_impact = {
			greedy = massive_stress_impact_gain
			paranoid = major_stress_gain
			arrogant = major_stress_impact_gain
			fickle = medium_stress_impact_gain
			cynical = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0.1
				ai_greed >= low_positive_ai_value
			}
		}
	}

	option = { # Negotiate with the eunuch
		name = ep1_flavor.1000.b

		duel = {
			skill = diplomacy
			value = 12

			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}


				desc = ep1_flavor.1000.c.success
				send_interface_toast = {
					title = ep1_flavor.1000.c.success
					left_icon = scope:eunuch_target

					add_courtier = scope:eunuch_target
					appoint_court_eunuch_effect = yes
					add_prestige = minor_prestige_gain
					scope:eunuch_target = {
						progress_towards_friend_effect = {
							CHARACTER = root
							OPINION = 0
							REASON = friend_court_position_recieved
						}
					}
				}
			}
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}

				desc = ep1_flavor.1000.c.failure
				send_interface_toast = {
					title = ep1_flavor.1000.c.failure
					left_icon = scope:eunuch_target

					add_prestige = minor_prestige_loss
					scope:eunuch_target = {
						hidden_effect = {
							random = {
								chance = 50
								if = {
									limit = {
										can_set_relation_potential_rival_trigger = { CHARACTER = root }
									}
									set_relation_potential_rival = root
								}
							}
						}
					}

					custom_tooltip = eunuch_moves_tt

					hidden_effect = {
						scope:eunuch_target = {
							if = {
								limit = {
									exists = scope:new_court
								}
								move_to_pool_at = scope:new_court.holder.capital_county.title_province
							}
						}
					}
				}
			}
		}

		stress_impact = {
			generous = medium_stress_impact_gain
			patient = medium_stress_impact_gain
			humble = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0.1
				ai_sociability >= low_positive_ai_value
			}
		}
	}

	option = { # Deny the eunuch
		name = ep1_flavor.1000.c

		custom_tooltip = eunuch_moves_tt

		hidden_effect = {
			scope:eunuch_target = {
				if = {
					limit = {
						exists = scope:new_court
					}
					move_to_pool_at = scope:new_court.holder.capital_county.title_province
				}
			}
		}

		stress_impact = {
			diligent = massive_stress_impact_gain
			gregarious = major_stress_impact_gain
			ambitious = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0.1
				ai_greed <= low_positive_ai_value
			}
		}
	}
}

# A learned eunuch wishes to sell various tips & tricks
ep1_flavor.1200 = {
	type = character_event
	title = ep1_flavor.1200.t
	desc = ep1_flavor.1200.desc
	theme = intrigue

	cooldown = {
		years = 30
	}

	left_portrait = {
		character = scope:eunuch_target
		animation = personality_rational
	}

	trigger = {
		has_ep1_dlc_trigger = yes
		is_landed_or_landless_administrative = yes
		culture = {
			OR = {
				has_cultural_parameter = can_castrate_prisoners
				has_cultural_parameter = eunuch_trait_bonuses
				has_cultural_parameter = court_machinations_eunuch_trait_bonuses
				has_cultural_parameter = can_appoint_chief_eunuch
			}
		}
		is_available_at_peace_adult = yes
		OR = {
			is_ai = no
			primary_title.tier > tier_duchy # So that we don't create too many characters for the AI (performance)
		}
		OR = { # Performance
			is_ai = no
			any_courtier_or_guest = {
				appropriate_eunuch_trigger = yes
			}
		}
	}

	immediate = {
		if = {
			limit = {
				any_courtier_or_guest = {
					appropriate_eunuch_trigger = yes
				}
			}
			random_courtier_or_guest = {
				limit = {
					appropriate_eunuch_trigger = yes
				}
				assign_quirk_effect = yes
				save_scope_as = eunuch_target
			}
		}
		else_if = {
			limit = {
				any_pool_character = {
					province = root.capital_province
					appropriate_eunuch_trigger = yes
				}
			}
			random_pool_character = {
				province = root.capital_province
				limit = {
					appropriate_eunuch_trigger = yes
				}
				assign_quirk_effect = yes
				save_scope_as = eunuch_target
			}
		}
		else = {
			# Find an appropriate culture for the Eunuch
			if = {
				limit = {
					is_ai = no # This is gonna be expensive, exclude AI's
					any_culture_global = {
						has_cultural_parameter = can_castrate_prisoners
					}
				}
				random_culture_global = {
					limit = {
						has_cultural_parameter = can_castrate_prisoners
					}
					weight = { # Upweight for your own culture if it's valid (more greeks in greece, but the potential for east africans to visit, etc)
						base = 1
						modifier = {
							add = 2
							this = root.culture
						}
						modifier = {
							factor = 0
							this != root.culture
							NOT = {
								any_culture_county = { # This is the expensive part
									title_province = {
										squared_distance = { target = root.capital_province value < squared_distance_massive }
									}
								}
							}
						}
					}
					save_scope_as = eunuch_target_culture
				}
			}
			else = {
				root.culture = {
					save_scope_as = eunuch_target_culture
				}
			}
			create_character = {
				location = root.capital_province
				culture = scope:eunuch_target_culture
				dynasty = none
				template = random_learned_eunuch_character
				save_scope_as = eunuch_target
			}
		}
	}

	option = { # Boost to learning languages
		name = ep1_flavor.1200.a

		pay_short_term_gold = {
			target = scope:eunuch_target
			gold = root.tiny_gold_value
		}

		add_character_modifier = {
			modifier = secrets_of_language_modifier
			years = 15
		}

		stress_impact = {
			greedy = massive_stress_impact_gain
			paranoid = major_stress_gain
			arrogant = major_stress_impact_gain
			fickle = medium_stress_impact_gain
			cynical = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				add = ai_sociability
			}
		}
	}

	option = { # Hostile Scheme boost
		name = ep1_flavor.1200.b

		pay_short_term_gold = {
			target = scope:eunuch_target
			gold = root.tiny_gold_value
		}

		add_character_modifier = {
			modifier = secrets_of_murder_modifier
			years = 15
		}

		stress_impact = {
			forgiving = massive_stress_impact_gain
			compassionate = major_stress_gain
			content = major_stress_impact_gain
			humble = medium_stress_impact_gain
			calm = medium_stress_impact_gain
			temperate = minor_stress_impact_gain
		}
		ai_chance = {
			base = 0
			modifier = {
				add = ai_vengefulness
			}
		}
	}

	option = { # Stewardship tips
		name = ep1_flavor.1200.c

		pay_short_term_gold = {
			target = scope:eunuch_target
			gold = root.tiny_gold_value
		}

		add_character_modifier = {
			modifier = secrets_of_the_realm_modifier
			years = 15
		}

		stress_impact = {
			lazy = massive_stress_impact_gain
			impatient = medium_stress_impact_gain
			vengeful = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
		}
	}

	option = { # No, thank you
		name = ep1_flavor.1200.d

		scope:eunuch_target = {
			add_opinion = {
				target = root
				opinion = -15
				modifier = disappointed_opinion
			}
			hidden_effect = {
				random = {
					chance = 50
					if = {
						limit = {
							can_set_relation_potential_rival_trigger = { CHARACTER = root }
						}
						set_relation_potential_rival = root
					}
				}
			}
		}

		stress_impact = {
			diligent = massive_stress_impact_gain
			gregarious = medium_stress_impact_gain
			ambitious = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				add = ai_energy
				ai_energy <= 0
			}
		}
	}
}


##################################################
# Joe

##################################################
# 2000 - 2999
##################################################

#########################
# Martial Exercises		#
# by Joe Parkin 		#
#########################

scripted_trigger ep1_flavor_2000_maa_scope_trigger = {
	NAND = {
		exists = scope:maa_type_1
		scope:maa_type_1 = flag:$TYPE$
	}
	NAND = {
		exists = scope:maa_type_2
		scope:maa_type_2 = flag:$TYPE$
	}
}

scripted_effect ep1_flavor_2000_maa_scope_effect = {
	if = {
		limit = {
			NOT = { exists = scope:maa_type_1 }
		}
		save_scope_value_as = {
			name = maa_type_1
			value = flag:$TYPE$
		}
	}
	else_if = {
		limit = {
			NOT = { exists = scope:maa_type_2 }
		}
		save_scope_value_as = {
			name = maa_type_2
			value = flag:$TYPE$
		}
	}
}

# Positive opinion modifiers for all vassal/courtier characters of root culture (they like you respecting their cultural MAA)
scripted_effect ep1_flavor_2000_culture_opinion_effect = {
	every_vassal_or_below = {
		custom = ep1_flavor.2000.culture_tt
		limit = {
			culture = root.culture
			NOR = {
				AND = {
					exists = scope:knight_scope
					this = scope:knight_scope
				}
				AND = {
					exists = scope:marshal_scope
					this = scope:marshal_scope
				}
			}
		}
		add_opinion = {
			target = root
			modifier = respect_opinion
			opinion = 5
		}
	}
	hidden_effect = {
		every_courtier = {
			limit = {
				culture = root.culture
				NOR = {
					AND = {
						exists = scope:knight_scope
						this = scope:knight_scope
					}
					AND = {
						exists = scope:marshal_scope
						this = scope:marshal_scope
					}
				}
			}
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = 5
			}
		}
	}
}

# Apply correct modifier and opinion boosts based on selected MAA type
scripted_effect ep1_flavor_2000_type_effect = {
	switch = {
		trigger = scope:$TYPE$
		flag:archers = {
			add_character_modifier = {
				modifier = ep1_2000_archer_modifier
				years = 10
			}
			if = {
				limit = {
					culture = { culture_has_archer_maa = yes }
				}
				ep1_flavor_2000_culture_opinion_effect = yes # Applies opinion modifiers to all vassal/courtier characters of root culture
			}
		}
		flag:infantry = {
			add_character_modifier = {
				modifier = ep1_2000_infantry_modifier
				years = 10
			}
			if = {
				limit = {
					OR = {
						culture = { culture_has_heavy_infantry_maa = yes }
						culture = { culture_has_pikemen_maa = yes }
					}
				}
				ep1_flavor_2000_culture_opinion_effect = yes # Applies opinion modifiers to all vassal/courtier characters of root culture
			}
		}
		flag:cavalry = {
			add_character_modifier = {
				modifier = ep1_2000_cavalry_modifier
				years = 10
			}
			if = {
				limit = {
					OR = {
						culture = { culture_has_light_cavalry_maa = yes }
						culture = { culture_has_heavy_cavalry_maa = yes }
					}
				}
				ep1_flavor_2000_culture_opinion_effect = yes # Applies opinion modifiers to all vassal/courtier characters of root culture
			}
		}
		flag:archer_cavalry = {
			add_character_modifier = {
				modifier = ep1_2000_acavalry_modifier
				years = 10
			}
			if = {
				limit = {
					OR = {
						culture = { culture_has_archer_cavalry_maa = yes }
						mpo_can_recruit_nomad_maa_trigger = yes
					}
				}
				ep1_flavor_2000_culture_opinion_effect = yes
			}
		}
		flag:skirmishers = {
			add_character_modifier = {
				modifier = ep1_2000_skirmisher_modifier
				years = 10
			}
			if = {
				limit = {
					culture = { culture_has_skirmisher_maa = yes }
				}
				ep1_flavor_2000_culture_opinion_effect = yes # Applies opinion modifiers to all vassal/courtier characters of root culture
			}
		}
		flag:elephant_cavalry = {
			add_character_modifier = {
				modifier = ep1_2000_ecavalry_modifier
				years = 10
			}
		}
		flag:camel_cavalry = {
			add_character_modifier = {
				modifier = ep1_2000_ccavalry_modifier
				years = 10
			}
		}
		flag:levies = {
			add_character_modifier = {
				modifier = ep1_2000_levies_modifier
				years = 10
			}
		}
	}
}

ep1_flavor.2000 = {
	type = character_event
	title = ep1_flavor.2000.t
	desc = {
		desc = ep1_flavor.2000.desc_intro
		first_valid = {
			triggered_desc = {
				trigger = { scope:maa_type_1 = flag:archers }
				desc = ep1_flavor.2000.desc_archers
			}
			triggered_desc = {
				trigger = { scope:maa_type_1 = flag:infantry }
				desc = ep1_flavor.2000.desc_infantry
			}
			triggered_desc = {
				trigger = { scope:maa_type_1 = flag:cavalry }
				desc = ep1_flavor.2000.desc_cavalry
			}
			triggered_desc = {
				trigger = { scope:maa_type_1 = flag:archer_cavalry }
				desc = ep1_flavor.2000.desc_archer_cavalry
			}
			triggered_desc = {
				trigger = { scope:maa_type_1 = flag:elephant_cavalry }
				desc = ep1_flavor.2000.desc_elephant_cavalry
			}
			triggered_desc = {
				trigger = { scope:maa_type_1 = flag:camel_cavalry }
				desc = ep1_flavor.2000.camel_cavalry
			}
			triggered_desc = {
				trigger = { scope:maa_type_1 = flag:levies }
				desc = ep1_flavor.2000.desc_levies
			}
		}
		desc = ep1_flavor.2000.desc_bridge
		first_valid = {
			triggered_desc = {
				trigger = { scope:maa_type_2 = flag:archers }
				desc = ep1_flavor.2000.desc_archers
			}
			triggered_desc = {
				trigger = { scope:maa_type_2 = flag:infantry }
				desc = ep1_flavor.2000.desc_infantry
			}
			triggered_desc = {
				trigger = { scope:maa_type_2 = flag:cavalry }
				desc = ep1_flavor.2000.desc_cavalry
			}
			triggered_desc = {
				trigger = { scope:maa_type_2 = flag:archer_cavalry }
				desc = ep1_flavor.2000.desc_archer_cavalry
			}
			triggered_desc = {
				trigger = { scope:maa_type_2 = flag:elephant_cavalry }
				desc = ep1_flavor.2000.desc_elephant_cavalry
			}
			triggered_desc = {
				trigger = { scope:maa_type_2 = flag:camel_cavalry }
				desc = ep1_flavor.2000.camel_cavalry
			}
			triggered_desc = {
				trigger = { scope:maa_type_2 = flag:levies }
				desc = ep1_flavor.2000.desc_levies
			}
		}
		desc = ep1_flavor.2000.desc_outro
	}
	theme = martial
	override_background = { reference = army_camp }
	cooldown = { years = 10 }
	left_portrait = {
		character = scope:knight_scope
		animation = throne_room_two_handed_passive_1
	}
	right_portrait = {
		character = cp:councillor_marshal
		animation = marshal
	}

	trigger = {
		has_ep1_dlc_trigger = yes
		has_royal_court = yes
		has_dlc_feature = royal_court
		is_landed_or_landless_administrative = yes
		is_available_adult = yes
		exists = cp:councillor_marshal
		any_knight = {
			count >= 1
			is_available_ai_adult = yes
			NOT = { this = root.cp:councillor_marshal }
		}
		OR = {
			OR = {
				culture = { culture_has_archer_maa = yes }
				number_maa_regiments_of_base_type = { type = archers value > 0 }
			}
			OR = {
				culture = { culture_has_light_cavalry_maa = yes }
				culture = { culture_has_heavy_cavalry_maa = yes }
				number_maa_regiments_of_base_type = { type = light_cavalry value > 0 }
				number_maa_regiments_of_base_type = { type = heavy_cavalry value > 0 }
			}
			OR = {
				culture = { culture_has_heavy_infantry_maa = yes }
				culture = { culture_has_pikemen_maa = yes }
				number_maa_regiments_of_base_type = { type = heavy_infantry value > 0 }
				number_maa_regiments_of_base_type = { type = pikemen value > 0 }

			}
			OR = {
				OR = {
					culture = { culture_has_archer_cavalry_maa = yes }
					mpo_can_recruit_nomad_maa_trigger = yes
				}
				number_maa_regiments_of_base_type = { type = archer_cavalry value > 0 }
			}
			OR = {
				culture = { culture_has_skirmisher_maa = yes }
				number_maa_regiments_of_base_type = { type = skirmishers value > 0 }
			}
			number_maa_regiments_of_base_type = { type = elephant_cavalry value > 0 }
			number_maa_regiments_of_base_type = { type = camel_cavalry value > 0 }
		}
	}

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

	immediate = {
		cp:councillor_marshal = { save_scope_as = marshal_scope }
		ordered_knight = {
			limit = {
				is_available_ai_adult = yes
				this != scope:marshal_scope
			}
			order_by = prowess
			save_scope_as = knight_scope
		}
		hidden_effect = {
			while = {
				count = 3
				random_list = {
					10 = { # archers
						trigger = {
							OR = {
								number_maa_regiments_of_base_type = { type = archers value > 0 }
								culture = { culture_has_archer_maa = yes }
							}
							ep1_flavor_2000_maa_scope_trigger = { TYPE = archers }
						}
						modifier = {
							factor = 2
							number_maa_regiments_of_base_type = { type = archers value > 4 }
						}
						ep1_flavor_2000_maa_scope_effect = { TYPE = archers }
					}
					10 = { # infantry
						trigger = {
							OR = {
								number_maa_regiments_of_base_type = { type = heavy_infantry value > 0 }
								number_maa_regiments_of_base_type = { type = pikemen value > 0 }
								culture = { culture_has_heavy_infantry_maa = yes }
								culture = { culture_has_pikemen_maa = yes }
							}
							ep1_flavor_2000_maa_scope_trigger = { TYPE = infantry }
						}
						modifier = {
							factor = 2
							number_maa_regiments_of_base_type = { type = heavy_infantry value > 4 }
						}
						modifier = {
							factor = 2
							number_maa_regiments_of_base_type = { type = pikemen value > 4 }
						}
						ep1_flavor_2000_maa_scope_effect = { TYPE = infantry }
					}
					10 = { # cavalry
						trigger = {
							OR = {
								number_maa_regiments_of_base_type = { type = light_cavalry value > 0 }
								number_maa_regiments_of_base_type = { type = heavy_cavalry value > 0 }
								culture = { culture_has_light_cavalry_maa = yes }
								culture = { culture_has_heavy_cavalry_maa = yes }
							}
							ep1_flavor_2000_maa_scope_trigger = { TYPE = cavalry }
						}
						modifier = {
							factor = 2
							number_maa_regiments_of_base_type = { type = light_cavalry value > 4 }
						}
						modifier = {
							factor = 2
							number_maa_regiments_of_base_type = { type = heavy_cavalry value > 4 }
						}
						ep1_flavor_2000_maa_scope_effect = { TYPE = cavalry }
					}
					10 = { # archer_cavalry
						trigger = {
							OR = {
								number_maa_regiments_of_base_type = { type = archer_cavalry value > 0 }
								OR = {
									culture = { culture_has_archer_cavalry_maa = yes }
									mpo_can_recruit_nomad_maa_trigger = yes
								}
							}
							ep1_flavor_2000_maa_scope_trigger = { TYPE = archer_cavalry }
						}
						modifier = {
							factor = 2
							number_maa_regiments_of_base_type = { type = archer_cavalry value > 4 }
						}
						ep1_flavor_2000_maa_scope_effect = { TYPE = archer_cavalry }
					}
					10 = { # skirmishers
						trigger = {
							OR = {
								number_maa_regiments_of_base_type = { type = skirmishers value > 0 }
								culture = { culture_has_skirmisher_maa = yes }
							}
							ep1_flavor_2000_maa_scope_trigger = { TYPE = skirmishers }
						}
						modifier = {
							factor = 2
							number_maa_regiments_of_base_type = { type = skirmishers value > 4 }
						}
						ep1_flavor_2000_maa_scope_effect = { TYPE = skirmishers }
					}
					10 = { # elephant_cavalry
						trigger = {
							number_maa_regiments_of_base_type = { type = elephant_cavalry value > 0 }
							ep1_flavor_2000_maa_scope_trigger = { TYPE = elephant_cavalry }
						}
						modifier = {
							factor = 2
							number_maa_regiments_of_base_type = { type = elephant_cavalry value > 4 }
						}
						ep1_flavor_2000_maa_scope_effect = { TYPE = elephant_cavalry }
					}
					10 = { # camel_cavalry
						trigger = {
							number_maa_regiments_of_base_type = { type = camel_cavalry value > 0 }
							ep1_flavor_2000_maa_scope_trigger = { TYPE = camel_cavalry }
						}
						modifier = {
							factor = 2
							number_maa_regiments_of_base_type = { type = camel_cavalry value > 4 }
						}
						ep1_flavor_2000_maa_scope_effect = { TYPE = camel_cavalry }
					}
					1 = { # levies
						trigger = {
							ep1_flavor_2000_maa_scope_trigger = { TYPE = levies }
						}
						ep1_flavor_2000_maa_scope_effect = { TYPE = levies }
					}
				}
			}
		}
	}

	option = { # First type
		name = {
			trigger = { scope:maa_type_1 = flag:archers }
			text = ep1_flavor.2000.archers
		}
		name = {
			trigger = {
				scope:maa_type_1 = flag:archers
				culture = { has_cultural_tradition = tradition_longbow_competitions }
			}
			text = ep1_flavor.2000.archers_longbow
		}
		name = {
			trigger = { scope:maa_type_1 = flag:infantry }
			text = ep1_flavor.2000.infantry
		}
		name = {
			trigger = { scope:maa_type_1 = flag:cavalry }
			text = ep1_flavor.2000.cavalry
		}
		name = {
			trigger = {
				scope:maa_type_1 = flag:cavalry
				OR = {
					culture = culture:french
					culture = { has_cultural_tradition = tradition_chivalry }
				}
			}
			text = ep1_flavor.2000.cavalry_joust
		}
		name = {
			trigger = {
				scope:maa_type_1 = flag:cavalry
				OR = {
					culture = { has_cultural_pillar = heritage_byzantine }
					is_roman_emperor_trigger = yes
				}
			}
			text = ep1_flavor.2000.cavalry_tzykanion
		}
		name = {
			trigger = {
				scope:maa_type_1 = flag:cavalry
				OR = {
					culture = { has_cultural_pillar = heritage_iranian }
					has_title = title:e_persia	#Must be the current emperor.
				}
			}
			text = ep1_flavor.2000.cavalry_chovgan
		}
		name = {
			trigger = { scope:maa_type_1 = flag:archer_cavalry }
			text = ep1_flavor.2000.archer_cavalry
		}
		name = {
			trigger = { scope:maa_type_1 = flag:skirmishers }
			text = ep1_flavor.2000.skirmishers
		}
		name = {
			trigger = { scope:maa_type_1 = flag:elephant_cavalry }
			text = ep1_flavor.2000.elephant_cavalry
		}
		name = {
			trigger = { scope:maa_type_1 = flag:camel_cavalry }
			text = ep1_flavor.2000.camel_cavalry
		}
		name = {
			trigger = { scope:maa_type_1 = flag:levies }
			text = ep1_flavor.2000.levies
		}
		name = {
			trigger = {
				scope:maa_type_1 = flag:levies
				culture = { has_cultural_pillar = heritage_goidelic }
			}
			text = ep1_flavor.2000.levies_caid
		}
		# Costs
		stress_impact = {
			arrogant = medium_stress_impact_gain
			greedy = medium_stress_impact_gain
		}
		remove_treasury_or_gold = medium_treasury_or_gold_value
		# Effects
		ep1_flavor_2000_type_effect = { TYPE = maa_type_1 } # Add relevant modifier and cultural opinion if relevant
		scope:marshal_scope = {
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = 10
			}
		}
		scope:knight_scope = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -10
			}
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_greed = -1
				ai_boldness = 0.5
				ai_rationality = 0.5
			}
			modifier = {
				factor = 2
				OR = {
					has_relation_friend = scope:marshal_scope
					has_relation_rival = scope:knight_scope
				}
			}
		}
	}

	option = { # Second type
		name = { # Archers
			trigger = { scope:maa_type_2 = flag:archers }
			text = ep1_flavor.2000.archers
		}
		name = { # Longbowmen - welsh
			trigger = {
				scope:maa_type_2 = flag:archers
				culture = { has_cultural_tradition = tradition_longbow_competitions }
			}
			text = ep1_flavor.2000.archers_longbow
		}
		name = { # Infantry
			trigger = { scope:maa_type_2 = flag:infantry }
			text = ep1_flavor.2000.infantry
		}
		name = { # Cavalry
			trigger = { scope:maa_type_2 = flag:cavalry }
			text = ep1_flavor.2000.cavalry
		}
		name = { # Joust - chivalry
			trigger = {
				scope:maa_type_2 = flag:cavalry
				OR = {
					culture = culture:french
					culture = { has_cultural_tradition = tradition_chivalry }
				}
			}
			text = ep1_flavor.2000.cavalry_joust
		}
		name = { # Tyzkanion - byzaboo
			trigger = {
				scope:maa_type_2 = flag:cavalry
				OR = {
					culture = { has_cultural_pillar = heritage_byzantine }
					is_roman_emperor_trigger = yes
				}
			}
			text = ep1_flavor.2000.cavalry_tzykanion
		}
		name = { # Chovgan - parsi
			trigger = {
				scope:maa_type_2 = flag:cavalry
				OR = {
					culture = { has_cultural_pillar = heritage_iranian }
					has_title = title:e_persia	#Must be the current emperor.
				}
			}
			text = ep1_flavor.2000.cavalry_chovgan
		}
		name = { # Horse archers
			trigger = { scope:maa_type_2 = flag:archer_cavalry }
			text = ep1_flavor.2000.archer_cavalry
		}
		name = { # Skirmishers
			trigger = { scope:maa_type_2 = flag:skirmishers }
			text = ep1_flavor.2000.skirmishers
		}
		name = { # Elephantry
			trigger = { scope:maa_type_2 = flag:elephant_cavalry }
			text = ep1_flavor.2000.elephant_cavalry
		}
		name = { # Camelry
			trigger = { scope:maa_type_2 = flag:camel_cavalry }
			text = ep1_flavor.2000.camel_cavalry
		}
		name = { # Peasants
			trigger = { scope:maa_type_2 = flag:levies }
			text = ep1_flavor.2000.levies
		}
		name = { # Caid - gaelic
			trigger = {
				scope:maa_type_2 = flag:levies
				culture = { has_cultural_pillar = heritage_goidelic }
			}
			text = ep1_flavor.2000.levies_caid
		}
		# Costs
		stress_impact = {
			arrogant = medium_stress_impact_gain
			greedy = medium_stress_impact_gain
		}
		remove_treasury_or_gold = medium_treasury_or_gold_value
		# Effects
		ep1_flavor_2000_type_effect = { TYPE = maa_type_2 } # Add relevant modifier and cultural opinion if relevant
		scope:marshal_scope = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -10
			}
		}
		scope:knight_scope = {
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = 10
			}
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_greed = -1
				ai_boldness = 0.5
				ai_rationality = 0.5
			}
			modifier = {
				factor = 2
				OR = {
					has_relation_friend = scope:knight_scope
					has_relation_rival = scope:marshal_scope
				}
			}
		}
	}

	option = { # Hunting is the best sport
		name = ep1_flavor.2000.c
		# Costs
		remove_treasury_or_gold = medium_treasury_or_gold_value
		stress_impact = {
			humble = medium_stress_impact_gain
			lazy = medium_stress_impact_gain
			greedy = major_stress_impact_gain
			lifestyle_hunter = medium_stress_impact_loss
			athletic = minor_stress_impact_loss
		}
		# Effects
		add_character_modifier = {
			modifier = ep1_2000_knights_modifier
			years = 5
		}
		if = {
			limit = {
				culture = {
					OR = {
						has_cultural_tradition = tradition_hunters
						has_cultural_tradition = tradition_sacred_hunts
					}
				}
			}
			custom_tooltip = ep1_flavor.2000.tradition_tt
			ep1_flavor_2000_culture_opinion_effect = yes
		}
		else = {
			every_knight = {
				custom = ep1_flavor.2000.knight_tt
				limit = {
					NOR = {
						this = scope:knight_scope
						this = scope:marshal_scope
					}
				}
				add_opinion = {
					target = root
					modifier = grateful_opinion
					opinion = 5
				}
			}
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = -2
				ai_boldness = 1
				ai_energy = 1
			}
			modifier = {
				factor = 2
				OR = {
					has_trait = lifestyle_hunter
					has_trait = athletic
				}
			}
		}
	}

	option = { # Too expensive
		name = ep1_flavor.2000.d
		# Costs
		change_current_court_grandeur = minor_court_grandeur_loss
		scope:marshal_scope = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -10
			}
		}
		scope:knight_scope = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -10
			}
		}
		stress_impact = {
			generous = medium_stress_impact_gain
			athletic = medium_stress_impact_gain
			lifestyle_hunter = medium_stress_impact_gain
			improvident = medium_stress_impact_gain
			profligate = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = 1
				ai_boldness = -1
			}
			modifier = {
				factor = 0.5
				OR = {
					has_trait = lifestyle_hunter
					has_trait = athletic
				}
			}
			modifier = {
				factor = 0.5
				OR = {
					has_trait = improvident
					has_trait = profligate
				}
			}
		}
	}
}

#########################
# Court of Vipers		#
# by Joe Parkin 		#
#########################

# Councillor exists and is not already saved
scripted_trigger ep1_flavor_councillor_scope_trigger = {
	exists = cp:councillor_$ROLE$
	NAND = {
		exists = scope:councillor_1
		scope:councillor_1 = cp:councillor_$ROLE$
	}
}

# Scheme is secret and hostile
scripted_trigger ep1_flavor_2010_base_scheme_trigger = {
	scheme_owner.liege = root
	is_hostile = yes
	is_scheme_exposed = no
}

# Scheme is above and contains a single councillor from event
scripted_trigger ep1_flavor_2010_councillor_scheme_trigger = {
	ep1_flavor_2010_base_scheme_trigger = yes # Scheme is secret and hostile
	OR = { # Only 1 councillor in a plot against you
		AND = {
			scheme_owner = { is_in_list = ep1_2010_list }
			any_scheme_agent_character = {
				count = 0
				is_in_list = ep1_2010_list
			}
		}
		any_scheme_agent_character = {
			count = 1
			is_in_list = ep1_2010_list
		}
	}
}

# Character is not involved in plot already
scripted_trigger ep1_flavor_2010_real_plot_involvement_trigger = {
	AND = {
		exists = scope:real_plot
		OR = {
			this = scope:real_plot.scheme_owner
			scope:real_plot = { scheme_is_character_agent = prev }
		}
	}
}

# Character is not involved in event already
scripted_trigger ep1_flavor_2010_scapegoat_trigger = {
	is_adult = yes
	NOR = {
		ep1_flavor_2010_real_plot_involvement_trigger = yes
		AND = {
			exists = scope:real_plot_revealer
			this = scope:real_plot_revealer
		}
		AND = {
			exists = scope:fake_plot_revealer_1
			this = scope:fake_plot_revealer_1
		}
		AND = {
			exists = scope:fake_plot_revealer_2
			this = scope:fake_plot_revealer_2
		}
		AND = {
			exists = scope:scapegoat_1
			this = scope:scapegoat_1
		}
	}
}

# Save scopes and add to list dynamically
scripted_effect ep1_flavor_2010_councillor_scope_effect = {
	if = {
		limit = {
			NOT = { exists = scope:councillor_1 }
		}
		save_scope_as = councillor_1
	}
	else = { save_scope_as = councillor_2 }
	add_to_list = ep1_2010_list
}

# Imprison selected character, and notify if it was the right one
scripted_effect ep1_flavor_2010_imprison_effect = {
	if = {
		limit = { $COUNCILLOR$ = scope:real_plot_revealer }
		scope:real_plotter = { save_scope_as = accused }
	}
	else_if = {
		limit = { $COUNCILLOR$ = scope:fake_plot_revealer_1 }
		scope:scapegoat_1 = { save_scope_as = accused }
	}
	else_if = {
		limit = { $COUNCILLOR$ = scope:fake_plot_revealer_2 }
		scope:scapegoat_2 = { save_scope_as = accused }
	}
	rightfully_imprison_character_effect = {
		TARGET = scope:accused
		IMPRISONER = root
	}
	random_list = {
		2 = {
			desc = ep1_flavor.2010.guilty
			show_chance = no
			modifier = {
				trigger = {
					scope:real_plotter != scope:accused
				}
				factor = 0
			}
			send_interface_toast = {
				title = ep1_flavor.2010.guilty
				left_icon = scope:accused
				hidden_effect = {
					scope:real_plot = {
						expose_scheme = yes
						expose_scheme_agent = scope:real_plotter
					}
				}
				add_prestige = minor_prestige_gain
				change_current_court_grandeur = miniscule_court_grandeur_gain
			}
		}
		2 = {
			desc = ep1_flavor.2010.innocent
			show_chance = no
			modifier = {
				trigger = { scope:real_plotter = scope:accused }
				factor = 0
			}
			send_interface_toast = {
				title = ep1_flavor.2010.innocent
				left_icon = scope:accused
				add_tyranny = minor_tyranny_gain
				change_current_court_grandeur = miniscule_court_grandeur_loss
			}
		}
	}
}

ep1_flavor.2010 = {
	type = character_event
	title = ep1_flavor.2010.t
	desc = {
		desc = ep1_flavor.2010.desc
		# Spymaster
		first_valid = {
			triggered_desc = { #Real
				trigger = { scope:spymaster = scope:real_plot_revealer }
				desc = ep1_flavor.2010.desc_spy_real
			}
			triggered_desc = { #Fake 1
				trigger = { scope:spymaster = scope:fake_plot_revealer_1 }
				desc = ep1_flavor.2010.desc_spy_1
			}
			triggered_desc = { #Fake 2
				trigger = { scope:spymaster = scope:fake_plot_revealer_2 }
				desc = ep1_flavor.2010.desc_spy_2
			}
		}
		# Councillor 1
		first_valid = {
			triggered_desc = { #Real
				trigger = { scope:councillor_1 = scope:real_plot_revealer }
				desc = ep1_flavor.2010.desc_1_real
			}
			triggered_desc = { #Fake 1
				trigger = { scope:councillor_1 = scope:fake_plot_revealer_1 }
				desc = ep1_flavor.2010.desc_1_1
			}
			triggered_desc = { #Fake 2
				trigger = { scope:councillor_1 = scope:fake_plot_revealer_2 }
				desc = ep1_flavor.2010.desc_1_2
			}
		}
		# Councillor 2
		first_valid = {
			triggered_desc = { #Real
				trigger = { scope:councillor_2 = scope:real_plot_revealer }
				desc = ep1_flavor.2010.desc_2_real
			}
			triggered_desc = { #Fake 1
				trigger = { scope:councillor_2 = scope:fake_plot_revealer_1 }
				desc = ep1_flavor.2010.desc_2_1
			}
			triggered_desc = { #Fake 2
				trigger = { scope:councillor_2 = scope:fake_plot_revealer_2 }
				desc = ep1_flavor.2010.desc_2_2
			}
		}
		# Context
		first_valid = {
			triggered_desc = {
				trigger = {
					OR = {
						scope:real_plotter = { is_close_family_of = root }
						scope:scapegoat_1 = { is_close_family_of = root }
						scope:scapegoat_2 = { is_close_family_of = root }
					}
				}
				desc = ep1_flavor.2010.desc_family
			}
			triggered_desc = {
				trigger = {
					OR = {
						scope:real_plotter = { is_consort_of = root }
						scope:scapegoat_1 = { is_consort_of = root }
						scope:scapegoat_2 = { is_consort_of = root }
					}
				}
				desc = ep1_flavor.2010.desc_consort
			}
			triggered_desc = {
				trigger = {
					OR = {
						scope:real_plotter = { is_councillor_of = root }
						scope:scapegoat_1 = { is_councillor_of = root }
						scope:scapegoat_2 = { is_councillor_of = root }
					}
				}
				desc = ep1_flavor.2010.desc_councillor
			}
			desc = ep1_flavor.2010.desc_fallback
		}
		desc = ep1_flavor.2010.desc_outro
	}
	theme = intrigue
	cooldown = { years = 10 }
	left_portrait = {
		character = scope:spymaster
		animation = spymaster
	}
	lower_left_portrait = {
		character = scope:councillor_1
	}
	lower_center_portrait = {
		character = scope:councillor_2
	}

	trigger = {
		is_ai = no # Murder schemes are heavy for performance
		has_ep1_dlc_trigger = yes
		is_landed_or_landless_administrative = yes
		has_royal_court = yes
		has_dlc_feature = royal_court
		is_available_adult = yes
		exists = cp:councillor_spymaster
		cp:councillor_spymaster = { is_available_ai_adult = yes }
		calc_true_if = {
			amount >= 2
			AND = {
				exists = cp:councillor_chancellor
				cp:councillor_chancellor = { is_available_ai_adult = yes }
			}
			AND = {
				exists = cp:councillor_marshal
				cp:councillor_marshal = { is_available_ai_adult = yes }
			}
			AND = {
				exists = cp:councillor_steward
				cp:councillor_steward = { is_available_ai_adult = yes }
			}
			AND = {
				exists = cp:councillor_court_chaplain
				cp:councillor_court_chaplain = { is_available_ai_adult = yes }
			}
		}
		any_courtier = {
			is_available_ai_adult = yes
			can_start_scheme = {
				type = murder
				target_character = root
			}
		}
	}

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

	immediate = {
		# save 3 councillors
		cp:councillor_spymaster = {
			save_scope_as = spymaster
			add_to_list = ep1_2010_list
		}
		hidden_effect = {
			while = {
				count = 2
				random_list = {
					2 = {
						trigger = { # Councillor exists and is not already saved
							ep1_flavor_councillor_scope_trigger = { ROLE = chancellor }
						}
						modifier = {
							factor = 4
							cp:councillor_chancellor = {
								is_scheming_against = { target = root }
							}
						}
						cp:councillor_chancellor = { ep1_flavor_2010_councillor_scope_effect = yes }
					}
					2 = {
						trigger = { # Councillor exists and is not already saved
							ep1_flavor_councillor_scope_trigger = { ROLE = marshal }
						}
						modifier = {
							factor = 4
							cp:councillor_marshal = {
								is_scheming_against = { target = root }
							}
						}
						cp:councillor_marshal = { ep1_flavor_2010_councillor_scope_effect = yes }
					}
					2 = {
						trigger = { # Councillor exists and is not already saved
							ep1_flavor_councillor_scope_trigger = { ROLE = steward }
						}
						modifier = {
							factor = 4
							cp:councillor_steward = {
								is_scheming_against = { target = root }
							}
						}
						cp:councillor_steward = { ep1_flavor_2010_councillor_scope_effect = yes }
					}
					1 = {
						trigger = { # Councillor exists and is not already saved
							ep1_flavor_councillor_scope_trigger = { ROLE = court_chaplain }
						}
						modifier = {
							factor = 4
							cp:councillor_court_chaplain = {
								is_scheming_against = { target = root }
							}
						}
						cp:councillor_court_chaplain = { ep1_flavor_2010_councillor_scope_effect = yes }
					}
				}
			}
		}
		# find hostile scheme that does involve councillor as an agent
		if = {
			limit = {
				any_targeting_scheme = { ep1_flavor_2010_councillor_scheme_trigger = yes }
			}
			ordered_targeting_scheme = {
				limit = { ep1_flavor_2010_councillor_scheme_trigger = yes }
				order_by = scheme_phase_duration
				save_scope_as = real_plot
			}
			random_in_list = {
				list = ep1_2010_list
				limit = { ep1_flavor_2010_real_plot_involvement_trigger = yes }
				save_scope_as = real_plotter
			}
		}
		# find hostile scheme that does not involve councillor as an agent
		else_if = {
			limit = { # Scheme is secret and hostile
				any_targeting_scheme = { ep1_flavor_2010_base_scheme_trigger = yes }
			}
			ordered_targeting_scheme = {
				limit = { ep1_flavor_2010_base_scheme_trigger = yes }
				order_by = scheme_phase_duration
				save_scope_as = real_plot
				scheme_owner = { save_scope_as = real_plotter }
			}
		}
		# create hostile scheme via a random courtier
		else = {
			random_courtier = {
				limit = {
					is_available_ai_adult = yes
					can_start_scheme = {
						type = murder
						target_character = root
					}
				}
				weight = {
					modifier = {
						factor = 10
						has_relation_rival = root
					}
					modifier = {
						factor = 4
						opinion = {
							target = root
							value < 0
						}
					}
					modifier = {
						factor = 2
						opinion = {
							target = root
							value < 50
						}
					}
				}
				save_scope_as = plotter
				hidden_effect = {
					start_scheme = {
						target_character = root
						type = murder
					}
				}
				random_scheme = {
					type = murder
					limit = {
						scheme_target_character = root
					}
					save_scope_as = real_plot
					scheme_owner = { save_scope_as = real_plotter }
				}
			}
		}
		# Save councillor roles in event
		random_in_list = {
			list = ep1_2010_list
			limit = { ep1_flavor_2010_real_plot_involvement_trigger = no }
			save_scope_as = real_plot_revealer
		}
		random_in_list = {
			list = ep1_2010_list
			limit = {
				NOT = { scope:real_plot_revealer ?= this }
			}
			save_scope_as = fake_plot_revealer_1
		}
		random_in_list = {
			list = ep1_2010_list
			limit = {
				NOR = {
					scope:real_plot_revealer ?= this
					scope:fake_plot_revealer_1 ?= this
				}
			}
			save_scope_as = fake_plot_revealer_2
		}
		random_courtier = {
			limit = { ep1_flavor_2010_scapegoat_trigger = yes }
			weight = {
				modifier = {
					factor = 4
					trigger = {
						any_in_list = {
							list = ep1_2010_list
							ep1_flavor_2010_real_plot_involvement_trigger = yes
						}
					}
					is_councillor = yes
				}
			}
			save_scope_as = scapegoat_1
		}
		random_vassal_or_below = {
			limit = { ep1_flavor_2010_scapegoat_trigger = yes }
			weight = {
				modifier = {
					factor = 4
					trigger = {
						any_in_list = {
							list = ep1_2010_list
							ep1_flavor_2010_real_plot_involvement_trigger = yes
						}
					}
					is_councillor = yes
				}
			}
			save_scope_as = scapegoat_2
		}
	}

	option = { # Spymaster
		name = {
			trigger = { scope:spymaster = scope:real_plot_revealer }
			text = ep1_flavor.2010.a.real
		}
		name = {
			trigger = { scope:spymaster = scope:fake_plot_revealer_1 }
			text = ep1_flavor.2010.a.fake_1
		}
		name = {
			trigger = { scope:spymaster = scope:fake_plot_revealer_2 }
			text = ep1_flavor.2010.a.fake_2
		}
		ep1_flavor_2010_imprison_effect = { COUNCILLOR = scope:spymaster }
		stress_impact = {
			just = medium_stress_impact_gain
			paranoid = medium_stress_impact_gain
			diligent = medium_stress_impact_gain
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_energy = 1
				ai_boldness = 1
			}
		}
	}

	option = { # Councillor 1
		name = {
			trigger = { scope:councillor_1 = scope:real_plot_revealer }
			text = ep1_flavor.2010.b.real
		}
		name = {
			trigger = { scope:councillor_1 = scope:fake_plot_revealer_1 }
			text = ep1_flavor.2010.b.fake_1
		}
		name = {
			trigger = { scope:councillor_1 = scope:fake_plot_revealer_2 }
			text = ep1_flavor.2010.b.fake_2
		}
		ep1_flavor_2010_imprison_effect = { COUNCILLOR = scope:councillor_1 }
		stress_impact = {
			just = medium_stress_impact_gain
			paranoid = medium_stress_impact_gain
			diligent = medium_stress_impact_gain
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_energy = 1
				ai_boldness = 1
			}
		}
	}

	option = { # Councillor 2
		name = {
			trigger = { scope:councillor_2 = scope:real_plot_revealer }
			text = ep1_flavor.2010.c.real
		}
		name = {
			trigger = { scope:councillor_2 = scope:fake_plot_revealer_1 }
			text = ep1_flavor.2010.c.fake_1
		}
		name = {
			trigger = { scope:councillor_2 = scope:fake_plot_revealer_2 }
			text = ep1_flavor.2010.c.fake_2
		}
		ep1_flavor_2010_imprison_effect = { COUNCILLOR = scope:councillor_2 }
		stress_impact = {
			just = medium_stress_impact_gain
			paranoid = medium_stress_impact_gain
			diligent = medium_stress_impact_gain
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_energy = 1
				ai_boldness = 1
			}
		}
	}

	option = { # Untangle the truth
		name = ep1_flavor.2010.d
		duel = {
			skill = intrigue
			value = high_skill_rating
			60 = {
				desc = ep1_flavor.2010.d.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 5
				}
				min = 10
				custom_tooltip = ep1_flavor.2010.d.success_tt
				hidden_effect = {
					send_interface_toast = {
						title = ep1_flavor.2010.d.success
						left_icon = root
						scope:real_plot = {
							expose_scheme = yes
							expose_scheme_agent = scope:real_plotter
						}
						rightfully_imprison_character_effect = {
							TARGET = scope:real_plotter
							IMPRISONER = root
						}
						show_as_tooltip = {
							add_prestige = medium_prestige_gain
							change_current_court_grandeur = minor_court_grandeur_gain
						}
					}
				}
				add_prestige = medium_prestige_gain
				change_current_court_grandeur = minor_court_grandeur_gain
			}
			40 = {
				desc = ep1_flavor.2010.d.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -5
				}
				min = 10
				send_interface_toast = {
					title = ep1_flavor.2010.d.failure
					left_icon = root
					add_prestige = medium_prestige_loss
					change_current_court_grandeur = minor_court_grandeur_loss
					add_character_modifier = {
						modifier = ep1_2010_failure_modifier
						years = 5
					}
				}
			}
		}
		stress_impact = {
			arbitrary = medium_stress_impact_gain
			lazy = medium_stress_impact_gain
			trusting = medium_stress_impact_gain
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_honor = 1
				ai_rationality = 1
				ai_compassion = 1
			}
		}
	}
}

#########################
# Interservice Rivalry	#
# by Joe Parkin 		#
#########################

# Save scopes and add to list dynamically
scripted_effect ep1_flavor_2020_maa_type_scope_effect = {
	if = {
		limit = {
			NOT = { exists = scope:maa_type_1 }
		}
		save_scope_value_as = { name = maa_type_1 value = flag:$TYPE$ }
	}
	else = {
		save_scope_value_as = { name = maa_type_2 value = flag:$TYPE$ }
	}
}

# Applies correct modifier based on relevant MAA (saved in event)
scripted_effect ep1_flavor_2020_modifier_effect = {
	if = {
		limit = { scope:$TYPE$ = flag:archers }
		add_character_modifier = {
			modifier = ep1_flavor_2020_archers_modifier
			years = 5
		}
	}
	else_if = {
		limit = { scope:$TYPE$ = flag:light_cavalry }
		add_character_modifier = {
			modifier = ep1_flavor_2020_light_cavalry_modifier
			years = 5
		}
	}
	else_if = {
		limit = { scope:$TYPE$ = flag:heavy_infantry }
		add_character_modifier = {
			modifier = ep1_flavor_2020_heavy_infantry_modifier
			years = 5
		}
	}
	else_if = {
		limit = { scope:$TYPE$ = flag:pikemen }
		add_character_modifier = {
			modifier = ep1_flavor_2020_pikemen_modifier
			years = 5
		}
	}
	else_if = {
		limit = { scope:$TYPE$ = flag:heavy_cavalry }
		add_character_modifier = {
			modifier = ep1_flavor_2020_heavy_cavalry_modifier
			years = 5
		}
	}
	else_if = {
		limit = { scope:$TYPE$ = flag:archer_cavalry }
		add_character_modifier = {
			modifier = ep1_flavor_2020_archer_cavalry_modifier
			years = 5
		}
	}
	else_if = {
		limit = { scope:$TYPE$ = flag:skirmishers }
		add_character_modifier = {
			modifier = ep1_flavor_2020_skirmishers_modifier
			years = 5
		}
	}
	else_if = {
		limit = { scope:$TYPE$ = flag:elephant_cavalry }
		add_character_modifier = {
			modifier = ep1_flavor_2020_elephant_cavalry_modifier
			years = 5
		}
	}
	else_if = {
		limit = { scope:$TYPE$ = flag:camel_cavalry }
		add_character_modifier = {
			modifier = ep1_flavor_2020_camel_cavalry_modifier
			years = 5
		}
	}
}

ep1_flavor.2020 = {
	type = character_event
	title = ep1_flavor.2020.t
	desc = {
		desc = ep1_flavor.2020.desc
		first_valid = {
			triggered_desc = {
				trigger = { scope:maa_type_1 = flag:archers }
				desc = ep1_flavor.2020.desc_knight_1_archers
			}
			triggered_desc = {
				trigger = { scope:maa_type_1 = flag:light_cavalry }
				desc = ep1_flavor.2020.desc_knight_1_light_cavalry
			}
			triggered_desc = {
				trigger = { scope:maa_type_1 = flag:heavy_infantry }
				desc = ep1_flavor.2020.desc_knight_1_heavy_infantry
			}
			triggered_desc = {
				trigger = { scope:maa_type_1 = flag:pikemen }
				desc = ep1_flavor.2020.desc_knight_1_pikemen
			}
			triggered_desc = {
				trigger = { scope:maa_type_1 = flag:heavy_cavalry }
				desc = ep1_flavor.2020.desc_knight_1_heavy_cavalry
			}
			triggered_desc = {
				trigger = { scope:maa_type_1 = flag:archer_cavalry }
				desc = ep1_flavor.2020.desc_knight_1_archer_cavalry
			}
			triggered_desc = {
				trigger = { scope:maa_type_1 = flag:skirmishers }
				desc = ep1_flavor.2020.desc_knight_1_skirmishers
			}
			triggered_desc = {
				trigger = { scope:maa_type_1 = flag:elephant_cavalry }
				desc = ep1_flavor.2020.desc_knight_1_elephant_cavalry
			}
			triggered_desc = {
				trigger = { scope:maa_type_1 = flag:camel_cavalry }
				desc = ep1_flavor.2020.desc_knight_1_camel_cavalry
			}
		}
		desc = ep1_flavor.2020.desc_bridge
		first_valid = {
			triggered_desc = {
				trigger = { scope:maa_type_2 = flag:archers }
				desc = ep1_flavor.2020.desc_knight_2_archers
			}
			triggered_desc = {
				trigger = { scope:maa_type_2 = flag:light_cavalry }
				desc = ep1_flavor.2020.desc_knight_2_light_cavalry
			}
			triggered_desc = {
				trigger = { scope:maa_type_2 = flag:heavy_infantry }
				desc = ep1_flavor.2020.desc_knight_2_heavy_infantry
			}
			triggered_desc = {
				trigger = { scope:maa_type_2 = flag:pikemen }
				desc = ep1_flavor.2020.desc_knight_2_pikemen
			}
			triggered_desc = {
				trigger = { scope:maa_type_2 = flag:heavy_cavalry }
				desc = ep1_flavor.2020.desc_knight_2_heavy_cavalry
			}
			triggered_desc = {
				trigger = { scope:maa_type_2 = flag:archer_cavalry }
				desc = ep1_flavor.2020.desc_knight_2_archer_cavalry
			}
			triggered_desc = {
				trigger = { scope:maa_type_2 = flag:skirmishers }
				desc = ep1_flavor.2020.desc_knight_2_skirmishers
			}
			triggered_desc = {
				trigger = { scope:maa_type_2 = flag:elephant_cavalry }
				desc = ep1_flavor.2020.desc_knight_2_elephant_cavalry
			}
			triggered_desc = {
				trigger = { scope:maa_type_2 = flag:camel_cavalry }
				desc = ep1_flavor.2020.desc_knight_2_camel_cavalry
			}
		}
	}
	theme = martial
	override_background = { reference = army_camp }
	cooldown = { years = 10 }
	left_portrait = {
		character = scope:knight_1
		animation = disapproval
	}
	right_portrait = {
		character = scope:knight_2
		animation = marshal
	}

	trigger = {
		has_ep1_dlc_trigger = yes
		has_royal_court = yes
		has_dlc_feature = royal_court
		is_landed_or_landless_administrative = yes
		is_available_adult = yes
		number_of_maa_regiments > 0
		calc_true_if = {
			amount >= 2
			number_maa_regiments_of_base_type = { type = archers value > 0 }
			number_maa_regiments_of_base_type = { type = light_cavalry value > 0 }
			number_maa_regiments_of_base_type = { type = heavy_infantry value > 0 }
			number_maa_regiments_of_base_type = { type = pikemen value > 0 }
			number_maa_regiments_of_base_type = { type = heavy_cavalry value > 0 }
			number_maa_regiments_of_base_type = { type = archer_cavalry value > 0 }
			number_maa_regiments_of_base_type = { type = skirmishers value > 0 }
			number_maa_regiments_of_base_type = { type = elephant_cavalry value > 0 }
			number_maa_regiments_of_base_type = { type = camel_cavalry value > 0 }
		}
		any_knight = {
			count >= 2
			is_available_ai_adult = yes
		}
	}

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

	immediate = {
		hidden_effect = {
			while = {
				count = 2
				ordered_knight = {
					limit = {
						is_available_ai_adult = yes
						NAND = {
							exists = scope:knight_1
							THIS = scope:knight_1
						}
					}
					order_by = prowess
					if = {
						limit = {
							NOT = { exists = scope:knight_1 }
						}
						save_scope_as = knight_1
					}
					else = { save_scope_as = knight_2 }
				}
			}
			while = {
				count = 2
				random_list = {
					2 = { # archers
						trigger = {
							number_maa_regiments_of_base_type = { type = archers value > 0 }
							NAND = {
								exists = scope:maa_type_1
								scope:maa_type_1 = flag:archers
							}
						}
						modifier = {
							factor = 10
							culture = { culture_has_archer_maa = yes }
						}
						ep1_2020_maa_regiment_modifier = { TYPE = archers }
						ep1_flavor_2020_maa_type_scope_effect = { TYPE = archers }
					}
					2 = { # light_cavalry
						trigger = {
							number_maa_regiments_of_base_type = { type = light_cavalry value > 0 }
							NAND = {
								exists = scope:maa_type_1
								scope:maa_type_1 = flag:light_cavalry
							}
						}
						modifier = {
							factor = 10
							culture = { culture_has_light_cavalry_maa = yes }
						}
						ep1_2020_maa_regiment_modifier = { TYPE = light_cavalry }
						ep1_flavor_2020_maa_type_scope_effect = { TYPE = light_cavalry }
					}
					2 = { # heavy_infantry
						trigger = {
							number_maa_regiments_of_base_type = { type = heavy_infantry value > 0 }
							NAND = {
								exists = scope:maa_type_1
								scope:maa_type_1 = flag:heavy_infantry
							}
						}
						modifier = {
							factor = 10
							culture = { culture_has_heavy_infantry_maa = yes }
						}
						ep1_2020_maa_regiment_modifier = { TYPE = heavy_infantry }
						ep1_flavor_2020_maa_type_scope_effect = { TYPE = heavy_infantry }
					}
					2 = { # pikemen
						trigger = {
							number_maa_regiments_of_base_type = { type = pikemen value > 0 }
							NAND = {
								exists = scope:maa_type_1
								scope:maa_type_1 = flag:pikemen
							}
						}
						ep1_2020_maa_regiment_modifier = { TYPE = pikemen }
						ep1_flavor_2020_maa_type_scope_effect = { TYPE = pikemen }

					}
					2 = { # heavy_cavalry
						trigger = {
							number_maa_regiments_of_base_type = { type = heavy_cavalry value > 0 }
							NAND = {
								exists = scope:maa_type_1
								scope:maa_type_1 = flag:heavy_cavalry
							}
						}
						modifier = {
							factor = 10
							culture = { culture_has_heavy_cavalry_maa = yes }
						}
						ep1_2020_maa_regiment_modifier = { TYPE = heavy_cavalry }
						ep1_flavor_2020_maa_type_scope_effect = { TYPE = heavy_cavalry }
					}
					2 = { # archer_cavalry
						trigger = {
							number_maa_regiments_of_base_type = { type = archer_cavalry value > 0 }
							NAND = {
								exists = scope:maa_type_1
								scope:maa_type_1 = flag:archer_cavalry
							}
						}
						modifier = {
							factor = 10
							OR = {
								culture = { culture_has_archer_cavalry_maa = yes }
								mpo_can_recruit_nomad_maa_trigger = yes
							}
						}
						ep1_2020_maa_regiment_modifier = { TYPE = archer_cavalry }
						ep1_flavor_2020_maa_type_scope_effect = { TYPE = archer_cavalry }
					}
					2 = { # skirmishers
						trigger = {
							number_maa_regiments_of_base_type = { type = skirmishers value > 0 }
							NAND = {
								exists = scope:maa_type_1
								scope:maa_type_1 = flag:skirmishers
							}
						}
						modifier = {
							factor = 10
							culture = { culture_has_skirmisher_maa = yes }
						}
						ep1_2020_maa_regiment_modifier = { TYPE = skirmishers }
						ep1_flavor_2020_maa_type_scope_effect = { TYPE = skirmishers }
					}
					2 = { # elephant_cavalry
						trigger = {
							number_maa_regiments_of_base_type = { type = elephant_cavalry value > 0 }
							NAND = {
								exists = scope:maa_type_1
								scope:maa_type_1 = flag:elephant_cavalry
							}
						}
						ep1_2020_maa_regiment_modifier = { TYPE = elephant_cavalry }
						ep1_flavor_2020_maa_type_scope_effect = { TYPE = elephant_cavalry }
					}
					2 = { # camel_cavalry
						trigger = {
							number_maa_regiments_of_base_type = { type = camel_cavalry value > 0 }
							NAND = {
								exists = scope:maa_type_1
								scope:maa_type_1 = flag:camel_cavalry
							}
						}
						ep1_2020_maa_regiment_modifier = { TYPE = camel_cavalry }
						ep1_flavor_2020_maa_type_scope_effect = { TYPE = camel_cavalry }
					}
				}
			}

		}
	}

	option = { # Side with 1st
		name = ep1_flavor.2020.a
		ep1_flavor_2020_modifier_effect = { TYPE = maa_type_1 } # Applies modifier based on relevant MAA type
		scope:knight_1 = {
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = 10
			}
			progress_towards_rival_effect = {
				REASON = rival_snubbed_maa
				CHARACTER = scope:knight_2
				OPINION = 0
			}
		}
		scope:knight_2 = {
			add_opinion = {
				target = root
				modifier = insulted_opinion
				opinion = -10
			}
		}
		if = {
			limit = { has_relation_rival = scope:knight_1 }
			stress_impact = {
				base = medium_stress_impact_gain
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_honor = 1
				ai_vengefulness = 0.5
			}
			modifier = {
				factor = 1.5
				opinion = { target = scope:knight_1 value > 25 }
			}
			modifier = {
				factor = 0
				has_relation_rival = scope:knight_1
			}
		}
		stress_impact = {
			just = minor_stress_impact_gain
			calm = minor_stress_impact_gain
			humble = minor_stress_impact_gain
		}
	}

	option = { # Side with 2nd
		name = ep1_flavor.2020.b
		ep1_flavor_2020_modifier_effect = { TYPE = maa_type_2 } # Applies modifier based on relevant MAA type
		scope:knight_2 = {
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = 10
			}
			progress_towards_rival_effect = {
				REASON = rival_snubbed_maa
				CHARACTER = scope:knight_1
				OPINION = 0
			}
		}
		scope:knight_1 = {
			add_opinion = {
				target = root
				modifier = insulted_opinion
				opinion = -10
			}
		}
		if = {
			limit = { has_relation_rival = scope:knight_2 }
			stress_impact = {
				base = medium_stress_impact_gain
			}
		}
		stress_impact = {
			just = minor_stress_impact_gain
			calm = minor_stress_impact_gain
			humble = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_honor = 1
				ai_vengefulness = 0.5
			}
			modifier = {
				factor = 1.5
				opinion = { target = scope:knight_2 value > 25 }
			}
			modifier = {
				factor = 0
				has_relation_rival = scope:knight_2
			}
		}
	}

	option = { # Side with neither
		name = ep1_flavor.2020.c
		duel = {
			skill = martial
			target = scope:knight_1
			2 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 0.5
				}
				desc = ep1_flavor.2020.c.success
				send_interface_toast = {
					title = ep1_flavor.2020.c.success
					left_icon = scope:knight_1
					right_icon = scope:knight_2
					add_character_modifier = {
						modifier = ep1_flavor_2020_both_modifier
						years = 5
					}
					scope:knight_1 = {
						add_opinion = {
							target = root
							modifier = pleased_opinion
							opinion = 5
						}
					}
					scope:knight_2 = {
						add_opinion = {
							target = root
							modifier = pleased_opinion
							opinion = 5
						}
					}
				}
			}
			3 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -0.5
				}
				desc = ep1_flavor.2020.c.failure
				send_interface_toast = {
					title = ep1_flavor.2020.c.failure
					left_icon = scope:knight_1
					right_icon = scope:knight_2
					add_prestige = minor_prestige_loss
					scope:knight_1 = {
						add_opinion = {
							target = root
							modifier = annoyed_opinion
							opinion = -5
						}
					}
					scope:knight_2 = {
						add_opinion = {
							target = root
							modifier = annoyed_opinion
							opinion = -5
						}
					}
				}
			}
		}
		stress_impact = {
			arrogant = minor_stress_impact_gain
			wrathful = minor_stress_impact_gain
			arbitrary = minor_stress_impact_gain
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_honor = 1
				ai_vengefulness = -1
			}
			modifier = {
				factor = 0.5
				martial < average_skill_rating
			}
			modifier = {
				factor = 2
				martial > average_skill_rating
			}
		}
	}

	option = { # Chastise
		name = ep1_flavor.2020.d
		add_prestige = minor_prestige_loss
		scope:knight_1 = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -10
			}
		}
		scope:knight_2 = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -10
			}
		}
		stress_impact = {
			brave = minor_stress_impact_gain
			arbitrary = minor_stress_impact_gain
			compassionate = minor_stress_impact_gain
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_energy = -1
				ai_boldness = -1
			}
		}
	}
}

#########################
# Exotic Arms			#
# by Joe Parkin 		#
#########################

scripted_trigger ep1_flavor_2040_foreign_holder_trigger = {
	NOR = {
		has_variable = exotic_arms_cooldown
		this = prev
		in_diplomatic_range = prev
	}
	has_royal_court = yes
	has_dlc_feature = royal_court
	is_landed_or_landless_administrative = yes
	is_available_adult = yes
	gold >= major_gold_value
}

scripted_trigger ep1_flavor_2040_artifact_trigger = {
	is_equipped = no
	artifact_durability >= 25
	AND = {
		has_variable = quality
		var:quality >= 33
	}
	AND = {
		has_variable = wealth
		var:wealth >= 33
	}
	OR = {
		artifact_slot_type = primary_armament
		artifact_slot_type = armor
	}
}

scripted_effect ep1_flavor_2040_artifact_effect = {
	dummy_female = { save_scope_as = dummy_gender }
	## Chance for artifact to be bad
	random = {
		chance = 40
		save_scope_value_as = {
			name = exotic_blade_quality
			value = no
		}
	}
	random_list = {
		2 = {
			create_artifact_weapon_effect = {
				OWNER = scope:exotic_blade_holder
				CREATOR = scope:dummy_gender
				SET_WEAPON_TYPE = flag:no
			}
		}
		2 = {
			create_artifact_armor_effect = {
				OWNER = scope:exotic_blade_holder
				CREATOR = scope:dummy_gender
				SET_ARMOR_TYPE = flag:no
			}
		}
	}
	## Create Merchant
	scope:exotic_arms_target = {
		if = {
			limit = {
				any_character_to_title_neighboring_and_across_water_county = {
					NOT = {
						culture = { this = scope:exotic_arms_target.culture }
					}
				}
			}
			random_character_to_title_neighboring_and_across_water_county = {
				limit = {
					NOT = {
						culture = { this = scope:exotic_arms_target.culture }
					}
				}
				save_scope_as = merchant_county
			}
		}
		else = {
			random_independent_ruler = {
				limit = {
					in_diplomatic_range = root
					any_realm_county = {
						NOT = {
							culture = { this = scope:exotic_arms_target.culture }
						}
					}
				}
				random_realm_county = {
					limit = {
						NOT = {
							culture = { this = scope:exotic_arms_target.culture }
						}
					}
					save_scope_as = merchant_county
				}
			}
		}
	}
	create_character = {
		template = foreign_merchant_template
		location = scope:exotic_arms_target.capital_province
		save_scope_as = foreign_merchant
	}
	if = {
		limit = { exists = scope:newly_created_artifact }
		scope:newly_created_artifact = { save_scope_as = exotic_blade }
	}
}

scripted_effect ep1_flavor_2040_transfer_effect = {
	if = {
		limit = { exists = scope:exotic_blade_quality }
		send_interface_toast = {
			title = ep1_flavor.2040.toast_poor
			left_icon = scope:exotic_blade
			scope:exotic_blade = {
				set_owner = {
					target = scope:exotic_arms_target
					history = {
						location = scope:exotic_arms_target.capital_province
						actor = scope:foreign_merchant
						recipient = scope:exotic_arms_target
						type = given
					}
				}
			}
		}
	}
	else = {
		send_interface_toast = {
			title = ep1_flavor.2040.toast
			left_icon = scope:exotic_blade
			scope:exotic_blade = {
				set_owner = {
					target = scope:exotic_arms_target
					history = {
						location = scope:exotic_arms_target.capital_province
						actor = scope:foreign_merchant
						recipient = scope:exotic_arms_target
						type = given
					}
				}
			}
		}
	}
}

ep1_flavor.2040 = {
	type = character_event
	title = ep1_flavor.2040.t
	desc = {
		desc = ep1_flavor.2040.desc
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:my_artifact }
				desc = ep1_flavor.2040.desc.artifact
			}
			desc = ep1_flavor.2040.desc.gold
		}
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:antiquarian }
				desc = {
					desc = ep1_flavor.2040.desc.outro_antiquarian
					first_valid = {
						triggered_desc = {
							trigger = {
								exists = scope:antiquarian
								scope:antiquarian.aptitude:court_tutor_court_position >= 4
							}
							desc = ep1_flavor.2040.desc.outro_good_praise
						}
						triggered_desc = {
							trigger = {
								exists = scope:antiquarian
								scope:antiquarian.aptitude:court_tutor_court_position = 3
							}
							desc = ep1_flavor.2040.desc.outro_good_unsure
						}
						triggered_desc = {
							trigger = {
								exists = scope:antiquarian
								scope:antiquarian.aptitude:court_tutor_court_position <= 2
							}
							desc = ep1_flavor.2040.desc.outro_good_warning
						}
						triggered_desc = {
							trigger = {
								exists = scope:antiquarian
								scope:antiquarian.aptitude:court_tutor_court_position >= 4
								exists = scope:exotic_blade_quality
							}
							desc = ep1_flavor.2040.desc.outro_bad_warning
						}
						triggered_desc = {
							trigger = {
								exists = scope:antiquarian
								scope:antiquarian.aptitude:court_tutor_court_position = 3
								exists = scope:exotic_blade_quality
							}
							desc = ep1_flavor.2040.desc.outro_bad_unsure
						}
						triggered_desc = {
							trigger = {
								exists = scope:antiquarian
								scope:antiquarian.aptitude:court_tutor_court_position <= 2
								exists = scope:exotic_blade_quality
							}
							desc = ep1_flavor.2040.desc.outro_bad_praise
						}
					}
				}
			}
			desc = ep1_flavor.2040.desc.outro
		}
	}
	theme = martial
	left_portrait = {
		character = scope:antiquarian
		animation = worry
	}
	right_portrait = {
		character = scope:foreign_merchant
		animation = admiration
	}

	immediate = {
		if = {
			limit = {
				employs_court_position = antiquarian_court_position
				any_court_position_holder = {
					is_available_ai_adult = yes
					type = antiquarian_court_position
				}
			}
			random_court_position_holder = {
				type = antiquarian_court_position
				limit = { is_available_ai_adult = yes }
				save_scope_as = antiquarian
			}
		}
		## Save own artifact if exists
		if = {
			limit = {
				any_character_artifact = { ep1_flavor_2040_artifact_trigger = yes }
			}
			random_character_artifact = {
				limit = { ep1_flavor_2040_artifact_trigger = yes }
				save_scope_as = my_artifact
			}
		}
	}

	option = {
		name = ep1_flavor.2040.a
		trigger = { exists = scope:my_artifact }
		custom_tooltip = ep1_flavor.2040.tt_my
		custom_tooltip = ep1_flavor.2040.tt_exotic
		hidden_effect = {
			ep1_flavor_2040_transfer_effect = yes
			scope:my_artifact = {
				set_owner = {
					target = scope:foreign_merchant
					history = {
						location = scope:exotic_arms_target.capital_province
						actor = scope:exotic_arms_target
						recipient = scope:foreign_merchant
						type = purchased
					}
				}
				set_owner = {
					target = scope:exotic_blade_holder
					history = {
						location = scope:exotic_blade_holder.capital_province
						actor = scope:foreign_merchant
						recipient = scope:exotic_blade_holder
						type = purchased
					}
				}
			}
		}
		stress_impact = {
			greedy = major_stress_impact_gain
			arrogant = major_stress_impact_gain
			paranoid = major_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = 2
			}
		}
	}

	option = {
		name = ep1_flavor.2040.b
		trigger = {
			NOT = { exists = scope:my_artifact }
		}
		remove_short_term_gold = major_gold_value
		custom_tooltip = ep1_flavor.2040.tt_exotic
		hidden_effect = { ep1_flavor_2040_transfer_effect = yes }
		stress_impact = {
			greedy = medium_stress_impact_gain
			arrogant = medium_stress_impact_gain
			paranoid = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = 2
			}
			modifier = {
				factor = 0
				gold <= major_gold_value
			}
		}
	}

	option = {
		name = ep1_flavor.2040.c
		stress_impact = {
			profligate = medium_stress_impact_gain
			trusting = medium_stress_impact_gain
			improvident = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_greed = 4
			}
		}
	}

	after = {
		scope:foreign_merchant = { silent_disappearance_effect = yes }
	}
}

ep1_flavor.2041 = {
	type = character_event
	hidden = yes
	cooldown = { years = 10 }

	trigger = {
		has_ep1_dlc_trigger = yes
		has_royal_court = yes
		has_dlc_feature = royal_court
		is_ai = yes
		is_landed_or_landless_administrative = yes
		any_character_with_royal_court = { ep1_flavor_2040_foreign_holder_trigger = yes }
	}

	weight_multiplier = {
		base = 1
		modifier = {
			factor = 2
			primary_title.tier = tier_empire
		}
	}

	immediate = {
		save_scope_as = exotic_blade_holder
		random_character_with_royal_court = {
			limit = { ep1_flavor_2040_foreign_holder_trigger = yes }
			weight = {
				base = 1
				modifier = {
					add = 10
					is_ai = no
				}
				modifier = {
					add = 1
					has_court_type = court_warlike
				}
				modifier = {
					add = 2
					any_character_artifact = { ep1_flavor_2040_artifact_trigger = yes }
				}
			}
			save_scope_as = exotic_arms_target
			set_variable = {
				name = exotic_arms_cooldown
				years = 50
			}
		}
		ep1_flavor_2040_artifact_effect = yes
		scope:exotic_arms_target = {
			trigger_event = {
				id = ep1_flavor.2040
				days = 1
			}
		}
	}
}

#########################
# Academic Disagreement	#
# by Joe Parkin 		#
#########################

scripted_trigger ep1_flavor_2070_foreign_court_trigger = {
	this != root
	in_diplomatic_range = root
	faith = {
		faith_hostility_level = {
			target = root.faith
			value < faith_hostile_level
		}
	}
	save_temporary_scope_as = symposium_ruler_temp
	root = {
		faith = {
			faith_hostility_level = {
				target = scope:symposium_ruler_temp.faith
				value < faith_hostile_level
			}
		}
	}
}

ep1_flavor.2070 = {
	type = character_event
	title = ep1_flavor.2070.t
	desc = {
		desc = ep1_flavor.2070.desc.intro
		first_valid = {
			triggered_desc = { # Theological
				trigger = {
					OR = {
						scope:symposium_scholar = { is_theological_character_trigger = yes }
						scope:symposium_courtier = { is_theological_character_trigger = yes }
					}
				}
				desc = {
					first_valid = {
						triggered_desc = { # Same faith same culture
							trigger = {
								scope:symposium_scholar.faith = scope:symposium_courtier.faith
								scope:symposium_scholar.culture = scope:symposium_courtier.culture

							}
							desc = ep1_flavor.2070.desc.theo_same_faith
						}
						triggered_desc = { # Same faith diff culture
							trigger = { scope:symposium_scholar.faith = scope:symposium_courtier.faith }
							desc = ep1_flavor.2070.desc.theo_same_faith_diff_cult
						}
						triggered_desc = { # Same religion
							trigger = {
								scope:symposium_scholar.religion = scope:symposium_courtier.religion
								scope:symposium_scholar.faith != scope:symposium_courtier.faith
							}
							desc = ep1_flavor.2070.desc.theo_same_relig
						}
						triggered_desc = { # Different religion
							trigger = {
								scope:symposium_scholar.religion != scope:symposium_courtier.religion
							}
							desc = ep1_flavor.2070.desc.theo_diff_relig
						}
					}
				}
			}
			triggered_desc = { # Mystic
				trigger = {
					scope:symposium_scholar = { has_trait = lifestyle_mystic }
					NOT = {
						scope:symposium_courtier = { has_trait = lifestyle_mystic }
					}
				}
				desc = ep1_flavor.2070.desc.mystic
			}
			triggered_desc = { # Medicine
				trigger = {
					OR = {
						scope:symposium_scholar = { has_trait = lifestyle_physician }
						scope:symposium_courtier = { has_trait = lifestyle_physician }
					}
				}
				desc = ep1_flavor.2070.desc.medicine
			}
			triggered_desc = { # Culture
				trigger = { scope:symposium_scholar.culture = scope:symposium_courtier.culture }
				desc = ep1_flavor.2070.desc.ling_same_cult
			}
			triggered_desc = { # Language
				trigger = {
					scope:symposium_scholar.culture != scope:symposium_courtier.culture
					scope:symposium_scholar.culture = { has_same_culture_language = scope:symposium_courtier.culture }
				}
				desc = ep1_flavor.2070.desc.ling_diff_cult
			}
			triggered_desc = { # Diff language
				trigger = {
					NOT = {
						scope:symposium_scholar.culture = { has_same_culture_language = scope:symposium_courtier.culture }
					}
				}
				desc = ep1_flavor.2070.desc.ling_diff_lang
			}
			random_valid = { # Fallback
				desc = ep1_flavor.2070.desc.fall_alchemy
				desc = ep1_flavor.2070.desc.fall_stars
				desc = ep1_flavor.2070.desc.fall_books
			}
		}
	}
	theme = learning
	cooldown = { years = 10 }
	left_portrait = {
		character = scope:symposium_courtier
		animation = personality_rational
	}
	right_portrait = {
		character = scope:symposium_scholar
		animation = schadenfreude
	}

	trigger = {
		has_ep1_dlc_trigger = yes
		has_royal_court = yes
		has_dlc_feature = royal_court
		is_landed_or_landless_administrative = yes
		is_available_adult = yes
		any_character_with_royal_court = { ep1_flavor_2070_foreign_court_trigger = yes }
		any_vassal_or_below = { learning >= 6 }
	}

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

	immediate = {
		culture = { save_scope_as = ling_cul_1 }
		every_vassal_or_below = {
			limit = { learning >= 15 }
			alternative_limit = { learning >= 10 }
			alternative_limit = { learning >= 6 }
			add_to_list = symposium_list
		}
		random_in_list = {
			list = symposium_list
			limit = { learning >= 15 }
			alternative_limit = { learning >= 10 }
			alternative_limit = { learning >= 6 }
			weight = {
				modifier = {
					factor = 2
					is_powerful_vassal = yes
				}
			}
			save_scope_as = symposium_courtier
		}
		random_character_with_royal_court = {
			limit = { ep1_flavor_2070_foreign_court_trigger = yes }
			weight = {
				modifier = {
					factor = 2
					primary_title.tier = tier_empire
				}
			}
			save_scope_as = symposium_ruler
		}
		scope:symposium_ruler.culture = { save_scope_as = ling_cul_2 }
		linguist_bonus_culture_effect = { CULTURE = ling_cul_1 }
		linguist_bonus_culture_effect = { CULTURE = ling_cul_2 }
		create_character = {
			dynasty = none
			location = root.capital_province
			template = symposium_template
			save_scope_as = symposium_scholar
		}
	}

	option = {
		name = ep1_flavor.2070.a
		stress_impact = {
			greedy = medium_stress_impact_gain
			arrogant = medium_stress_impact_gain
			paranoid = medium_stress_impact_gain
		}
		pay_short_term_gold = {
			target = scope:symposium_scholar
			gold = medium_gold_value
		}
		add_courtier = scope:symposium_scholar
		hidden_effect = {
			scope:symposium_scholar = { return_to_court = yes }
		}
		reverse_add_opinion = {
			target = scope:symposium_courtier
			modifier = angry_opinion
			opinion = -15
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_greed = -0.5
				ai_compassion = 0.5
				ai_rationality = 1
			}
		}
	}

	option = {
		name = {
			trigger = {
				NOT = {
					scope:symposium_scholar.culture = { has_same_culture_language = scope:symposium_courtier.culture }
				}
				root = { knows_language_of_culture = scope:symposium_scholar.culture }
			}
			text = ep1_flavor.2070.c.lang
		}
		name = {
			trigger = { always = yes }
			text = ep1_flavor.2070.c
		}
		stress_impact = {
			humble = medium_stress_impact_gain
			shy = medium_stress_impact_gain
		}
		duel = {
			skill = learning
			target = scope:symposium_scholar
			4 = {
				desc = ep1_flavor.2070.c.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 5
				}
				modifier = {
					add = 1
					has_trait = scholar
				}
				modifier = {
					add = 4
					NOT = {
						scope:symposium_scholar.culture = { has_same_culture_language = scope:symposium_courtier.culture }
					}
					root = { knows_language_of_culture = scope:symposium_scholar.culture }
				}
				min = 5
				send_interface_toast = {
					title = ep1_flavor.2070.c.success
					left_icon = scope:symposium_scholar
					right_icon = scope:symposium_courtier
					add_learning_lifestyle_xp = medium_lifestyle_xp
					add_prestige = medium_prestige_gain
					reverse_add_opinion = {
						target = scope:symposium_courtier
						modifier = impressed_opinion
						opinion = 10
					}
					custom_tooltip = ep1_flavor.2070.c.tt
					hidden_effect = {
						random_list = {
							2 = {
								send_interface_toast = {
									title = ep1_flavor.2070.c.success
									left_icon = scope:symposium_scholar
									add_courtier = scope:symposium_scholar
								}
							}
							2 = {
								send_interface_toast = {
									title = ep1_flavor.2070.c.failure
									left_icon = scope:symposium_scholar
									show_as_tooltip = {
										scope:symposium_ruler = { add_courtier = scope:symposium_scholar }
									}
								}
							}
						}
					}
				}
			}
			6 = {
				desc = ep1_flavor.2070.c.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -2
				}
				min = 10
				send_interface_toast = {
					title = ep1_flavor.2070.c.failure
					left_icon = scope:symposium_scholar
					right_icon = scope:symposium_courtier
					add_prestige = medium_prestige_loss
					reverse_add_opinion = {
						target = scope:symposium_courtier
						modifier = disappointed_opinion
						opinion = -10
					}
					show_as_tooltip = {
						scope:symposium_ruler = { add_courtier = scope:symposium_scholar }
					}
				}
			}
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_boldness = 1
				ai_compassion = -0.5
				ai_rationality = 1
			}
		}
	}

	option = {
		name = ep1_flavor.2070.d
		stress_impact = {
			humble = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
			generous = medium_stress_impact_gain
			shy = medium_stress_impact_gain
			forgiving = medium_stress_impact_gain
		}
		add_prestige = minor_prestige_loss
		reverse_add_opinion = {
			target = scope:symposium_courtier
			modifier = grateful_opinion
			opinion = 5
		}
		show_as_tooltip = {
			scope:symposium_ruler = { add_courtier = scope:symposium_scholar }
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_boldness = 0.5
				ai_compassion = -1
				ai_rationality = -0.5
			}
		}
	}

	option = {
		name = ep1_flavor.2070.e
		trigger = {
			OR = {
				OR = {
					scope:symposium_scholar = { is_theological_character_trigger = yes }
					scope:symposium_courtier = { is_theological_character_trigger = yes }
				}
				AND = {
					scope:symposium_scholar = { has_trait = lifestyle_mystic }
					NOT = { has_trait = lifestyle_mystic }
				}
			}
			has_trait = zealous
		}
		add_learning_skill = -1
		add_piety = medium_piety_gain
		stress_impact = {
			zealous = medium_stress_impact_loss
		}
		show_as_tooltip = {
			scope:symposium_ruler = { add_courtier = scope:symposium_scholar }
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_zeal = 1
				ai_compassion = -1
				ai_rationality = -1
			}
		}
	}

	after = {
		hidden_effect = {
			scope:symposium_ruler = {
				if = {
					limit = {
						scope:symposium_scholar.employer != root
					}
					add_courtier = scope:symposium_scholar
				}
			}
			scope:symposium_scholar = { return_to_court = yes }
		}
	}
}

#########################
# The Greater Good		#
# by Joe Parkin 		#
#########################

ep1_flavor.2060 = {
	type = character_event
	title = ep1_flavor.2060.t
	desc = ep1_flavor.2060.desc
	theme = intrigue
	cooldown = { years = 10 }
	left_portrait = {
		character = scope:detective_scope
		animation = worry
	}
	right_portrait = {
		character = scope:grocer_scope
		animation = scheme
	}
	lower_right_portrait = {
		character = scope:victim_scope
		outfit_tags = { beggar_rags }
	}

	trigger = {
		has_ep1_dlc_trigger = yes
		has_royal_court = yes
		has_dlc_feature = royal_court
		is_landed_or_landless_administrative = yes
		is_available_adult = yes
		# Victim
		any_pool_guest = {
			is_lowborn = yes
			is_married = no
		}
	}

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

	immediate = {
		# Detective
		create_character = {
			age = { 30 35 }
			dynasty = none
			faith = root.capital_county.faith
			culture = root.capital_county.culture
			location = root.capital_province
			# Education
			random_traits_list = {
				count = 1
				education_martial_2 = {}
				education_martial_3 = {}
			}
			# Personality
			trait = brave
			trait = diligent
			trait = compassionate
			trait = intellect_good_1
			# Misc
			random_traits = no
			gender_female_chance = root_faith_dominant_gender_female_chance
			# Skills
			diplomacy = { min_template_low_skill max_template_decent_skill }
			martial = { min_template_low_skill max_template_decent_skill }
			stewardship = { min_template_low_skill max_template_decent_skill }
			intrigue = { min_template_low_skill max_template_decent_skill }
			learning = { min_template_low_skill max_template_decent_skill }
			prowess = { min_template_low_skill max_template_decent_skill }
			save_scope_as = detective_scope
		}
		# Grocer
		create_character = {
			age = { 50 55 }
			dynasty = none
			faith = root.capital_county.faith
			culture = root.capital_county.culture
			location = root.capital_province
			# Education
			random_traits_list = {
				count = 1
				education_intrigue_2 = {}
				education_intrigue_3 = {}
			}
			# Personality
			trait = deceitful
			trait = callous
			trait = arrogant
			# Misc
			random_traits = no
			gender_female_chance = root_faith_dominant_gender_female_chance
			# Skills
			diplomacy = { min_template_low_skill max_template_decent_skill }
			martial = { min_template_low_skill max_template_decent_skill }
			stewardship = { min_template_low_skill max_template_decent_skill }
			intrigue = { min_template_low_skill max_template_low_skill }
			learning = { min_template_low_skill max_template_decent_skill }
			prowess = { min_template_low_skill max_template_decent_skill }
			save_scope_as = grocer_scope
		}
		scope:grocer_scope = {
			add_character_flag = {
				flag = use_stealth_clothes
  				days = 1
			}
		}
		# Victim
		random_pool_guest = {
			limit = {
				is_lowborn = yes
				is_married = no
			}
			save_scope_as = victim_scope
		}
		hidden_effect = {
			scope:victim_scope = {
				death = {
					death_reason = death_disappearance
					killer = scope:grocer_scope
				}
			}
			scope:grocer_scope = {
				add_secret = {
					type = secret_murder
					target = scope:victim_scope
				}
			}
		}
		custom_tooltip = ep1_flavor.2060.death_tt
		random_realm_province = {
			limit = {
				county != root.capital_county
				has_holding_type = city_holding
			}
			alternative_limit = { has_holding_type = city_holding }
			alternative_limit = { always = yes }
			save_scope_as = sandford_scope
		}
	}

	option = {
		name = ep1_flavor.2060.a
		add_prestige = medium_prestige_loss
		scope:detective_scope = { silent_disappearance_effect = yes }
		custom_tooltip = ep1_flavor.2060.a.tt
		change_current_court_grandeur = minor_court_grandeur_loss
		every_pool_guest = {
			custom = custom.every_guest
			move_to_pool = yes
		}
		stress_impact = {
			paranoid = medium_stress_impact_gain
			diligent = medium_stress_impact_gain
			wrathful = medium_stress_impact_gain
			impatient = medium_stress_impact_gain
			craven = medium_stress_impact_gain
		}
		ai_chance = {
			ai_value_modifier = {
				ai_compassion = 1
				ai_boldness = -1
				ai_energy = -1
			}
		}
	}

	option = {
		name = ep1_flavor.2060.b
		hidden_effect = {
			scope:victim_scope = { set_killer_public = yes }
		}
		send_interface_toast = {
			title = ep1_flavor.2060.b.title
			left_icon = scope:detective_scope
			right_icon = scope:grocer_scope
			show_as_tooltip = {
				imprison = {
  					target = scope:grocer_scope
 					type = dungeon
				}
			}
			add_courtier = scope:detective_scope
		}
		hidden_effect = {
			scope:grocer_scope = {
				random_secret = {
					type = secret_murder
					limit = {
						secret_target = scope:victim_scope
					}
					expose_secret = scope:detective_scope
				}
			}
			rightfully_imprison_character_effect = {
				TARGET = scope:grocer_scope
				IMPRISONER = root
			}
		}
		scope:detective_scope = {
			hidden_effect = { return_to_court = yes }
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = 20
			}
		}
		stress_impact = {
			callous = medium_stress_impact_gain
			arbitrary = medium_stress_impact_gain
			deceitful = medium_stress_impact_gain
			arrogant = medium_stress_impact_gain
			trusting = medium_stress_impact_gain
		}
		ai_chance = {
			ai_value_modifier = {
				ai_compassion = 1
				ai_honor = 1
				ai_boldness = 1
			}
		}
	}

	option = {
		name = ep1_flavor.2060.c
		send_interface_toast = {
			title = ep1_flavor.2060.c.title
			left_icon = scope:grocer_scope
			right_icon = scope:detective_scope
			scope:detective_scope = {
				death = {
					death_reason = death_disappearance
					killer = root
				}
			}
			add_courtier = scope:grocer_scope
		}
		add_secret = {
			type = secret_murder
			target = scope:detective_scope
		}
		random_secret = {
			type = secret_murder
			limit = {
				secret_target = scope:detective_scope
			}
			reveal_to = scope:grocer_scope
		}
		scope:grocer_scope = {
			hidden_effect = { return_to_court = yes }
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = 20
			}
			hidden_effect = {
				scope:grocer_scope = {
					random_secret = {
						type = secret_murder
						limit = {
							secret_target = scope:victim_scope
						}
						reveal_to = root
					}
				}
			}
		}
		change_current_court_grandeur = minor_court_grandeur_gain
		stress_impact = {
			compassionate = medium_stress_impact_gain
			just = medium_stress_impact_gain
			honest = medium_stress_impact_gain
			humble = medium_stress_impact_gain
			trusting = medium_stress_impact_gain
		}
		ai_chance = {
			ai_value_modifier = {
				ai_compassion = -1
				ai_honor = -1
				ai_boldness = 1
			}
		}
	}
}

#########################
# Taking Sides			#
# by Joe Parkin 		#
#########################

# Save scopes and add to list dynamically
scripted_effect ep1_flavor_2030_local_dispute_scope_effect = {
	if = {
		limit = {
			NOT = { exists = scope:local_dispute_1 }
		}
		save_scope_as = local_dispute_1
		if = {
			limit = { is_landed_or_landless_administrative = yes }
			capital_province.county = { save_scope_as = local_county_1 }
		}
		else = {
			root = {
				random_sub_realm_county = {
					weight = {
						modifier = {
							factor = 5
							culture = scope:local_dispute_1.culture
						}
						modifier = {
							factor = 5
							faith = scope:local_dispute_1.faith
						}
						modifier = {
							factor = 0.1
							this = root.capital_province.county
						}
					}
					save_scope_as = local_county_1
				}
			}
		}
	}
	else_if = {
		limit = {
			exists = scope:local_dispute_1
			this != scope:local_dispute_1
		}
		save_scope_as = local_dispute_2
		if = {
			limit = { is_landed_or_landless_administrative = yes }
			capital_province.county = { save_scope_as = local_county_2 }
		}
		else = {
			root = {
				random_sub_realm_county = {
					weight = {
						modifier = {
							factor = 5
							culture = scope:local_dispute_2.culture
						}
						modifier = {
							factor = 5
							faith = scope:local_dispute_2.faith
						}
						modifier = {
							factor = 0.1
							this = root.capital_province.county
						}
						modifier = {
							factor = 0.1
							exists = scope:local_county_1
							this = scope:local_county_1
						}
					}
					save_scope_as = local_county_2
				}
			}
		}
	}
}

scripted_effect ep1_flavor_2030_option_effect = {
	scope:local_county_$WIN$ = {
		add_county_modifier = {
			modifier = ep1_flavor_2030_positive_modifier
			years = 5
		}
	}
	scope:local_county_$LOSE$ = {
		add_county_modifier = {
			modifier = ep1_flavor_2030_negative_modifier
			years = 5
		}
	}
	scope:local_dispute_$WIN$ = {
		if = {
			limit = {
				NOT = { is_in_list = generated_dispute_characters }
			}
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 10
			}
		}
	}
	scope:local_dispute_$LOSE$ = {
		if = {
			limit = {
				NOT = { is_in_list = generated_dispute_characters }
			}
			add_opinion = {
				target = root
				modifier = annoyed_opinion
				opinion = -10
			}
		}
	}
}

scripted_effect ep1_flavor_2030_boon_effect = {
	switch = {
		trigger = scope:taking_sides_boon_$NUM$
		0 = {
			add_character_modifier = {
				modifier = ep1_flavor_2030_boon_1_modifier
				years = 5
			}
		}
		1 = {
			add_character_modifier = {
				modifier = ep1_flavor_2030_boon_2_modifier
				years = 5
			}
		}
		2 = {
			add_character_modifier = {
				modifier = ep1_flavor_2030_boon_3_modifier
				years = 5
			}
		}
		3 = {
			add_character_modifier = {
				modifier = ep1_flavor_2030_boon_4_modifier
				years = 5
			}
		}
		4 = {
			add_character_modifier = {
				modifier = ep1_flavor_2030_boon_5_modifier
				years = 5
			}
		}
		5 = {
			add_character_modifier = {
				modifier = ep1_flavor_2030_boon_6_modifier
				years = 5
			}
		}
		6 = {
			add_character_modifier = {
				modifier = ep1_flavor_2030_boon_7_modifier
				years = 5
			}
		}
		7 = {
			add_character_modifier = {
				modifier = ep1_flavor_2030_boon_8_modifier
				years = 5
			}
		}
		8 = {
			add_character_modifier = {
				modifier = ep1_flavor_2030_boon_9_modifier
				years = 5
			}
		}
		9 = {
			add_character_modifier = {
				modifier = ep1_flavor_2030_boon_10_modifier
				years = 5
			}
		}
	}
}

ep1_flavor.2030 = {
	type = character_event
	title = ep1_flavor.2030.t
	desc = {
		desc = ep1_flavor.2030.desc_intro
		first_valid = {
			triggered_desc = { # Monk
				trigger = {
					exists = scope:local_dispute_1
					scope:local_dispute_1 = { has_trait = devoted }
				}
				desc = ep1_flavor.2030.desc_1_monk
			}
			triggered_desc = { # Bishop
				trigger = {
					exists = scope:local_dispute_1
					scope:local_dispute_1 = {
						is_landed_or_landless_administrative = yes
						government_has_flag = government_is_theocracy
					}
				}
				desc = ep1_flavor.2030.desc_1_bishop
			}
			triggered_desc = { # Baron
				trigger = {
					exists = scope:local_dispute_1
					scope:local_dispute_1 = { is_landed_or_landless_administrative = yes }
				}
				desc = ep1_flavor.2030.desc_1_baron
			}
			triggered_desc = { # Scholar
				trigger = {
					exists = scope:local_dispute_1
					scope:local_dispute_1 = { has_trait = scholar }
				}
				desc = ep1_flavor.2030.desc_1_scholar
			}
			triggered_desc = { # Cultural minority
				trigger = {
					exists = scope:local_dispute_1
					culture != root.culture
				}
				desc = ep1_flavor.2030.desc_1_culture
			}
			triggered_desc = { # Religious minority
				trigger = {
					exists = scope:local_dispute_1
					faith != root.faith
				}
				desc = ep1_flavor.2030.desc_1_faith
			}
			triggered_desc = { # Judge
				trigger = {
					exists = scope:local_dispute_1
					scope:local_dispute_1 = { has_trait = education_learning }
				}
				desc = ep1_flavor.2030.desc_1_judge
			}
			triggered_desc = { # Captain
				trigger = {
					exists = scope:local_dispute_1
					scope:local_dispute_1 = { has_trait = education_martial }
				}
				desc = ep1_flavor.2030.desc_1_captain
			}
			triggered_desc = { # Merchant
				trigger = {
					exists = scope:local_dispute_1
					scope:local_dispute_1 = { always = yes }
				}
				desc = ep1_flavor.2030.desc_1_merchant
			}
		}
		desc = ep1_flavor.2030.desc_bridge
		first_valid = {
			triggered_desc = { # Monk
				trigger = {
					exists = scope:local_dispute_2
					scope:local_dispute_2 = { has_trait = devoted }
				}
				desc = ep1_flavor.2030.desc_2_monk
			}
			triggered_desc = { # Bishop
				trigger = {
					exists = scope:local_dispute_2
					scope:local_dispute_2 = {
						is_landed_or_landless_administrative = yes
						government_has_flag = government_is_theocracy
					}
				}
				desc = ep1_flavor.2030.desc_2_bishop
			}
			triggered_desc = { # Baron
				trigger = {
					exists = scope:local_dispute_2
					scope:local_dispute_2 = { is_landed_or_landless_administrative = yes }
				}
				desc = ep1_flavor.2030.desc_2_baron
			}
			triggered_desc = { # Scholar
				trigger = {
					exists = scope:local_dispute_2
					scope:local_dispute_2 = { has_trait = scholar }
				}
				desc = ep1_flavor.2030.desc_2_scholar
			}
			triggered_desc = { # Cultural minority
				trigger = {
					exists = scope:local_dispute_2
					culture != root.culture
				}
				desc = ep1_flavor.2030.desc_2_culture
			}
			triggered_desc = { # Religious minority
				trigger = {
					exists = scope:local_dispute_2
					faith != root.faith
				}
				desc = ep1_flavor.2030.desc_2_faith
			}
			triggered_desc = { # Judge
				trigger = {
					exists = scope:local_dispute_2
					scope:local_dispute_2 = { has_trait = education_learning }
				}
				desc = ep1_flavor.2030.desc_2_judge
			}
			triggered_desc = { # Captain
				trigger = {
					exists = scope:local_dispute_2
					scope:local_dispute_2 = { has_trait = education_martial }
				}
				desc = ep1_flavor.2030.desc_2_captain
			}
			triggered_desc = { # Merchant
				trigger = {
					exists = scope:local_dispute_2
					scope:local_dispute_2 = { always = yes }
				}
				desc = ep1_flavor.2030.desc_2_merchant
			}
		}
		desc = ep1_flavor.2030.desc_outro
	}
	theme = stewardship
	override_background = { reference = market }
	cooldown = { years = 100 }
	left_portrait = {
		character = scope:local_dispute_1
		animation = dismissal
	}
	right_portrait = {
		character = scope:local_dispute_2
		animation = disapproval
	}

	trigger = {
		has_ep1_dlc_trigger = yes
		is_landed_or_landless_administrative = yes
		has_royal_court = yes
		has_dlc_feature = royal_court
		is_available_adult = yes
		any_sub_realm_county = { count >= 3 }
	}

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

	immediate = {
		save_scope_value_as = {
			name = taking_sides_boon_1
			value = {
				integer_range = {
					min = 0
					max = 9
				}
			}
		}
		save_scope_value_as = {
			name = taking_sides_boon_2
			value = {
				integer_range = {
					min = 0
					max = 9
				}
			}
		}
		if = {
			limit = { scope:taking_sides_boon_2 = scope:taking_sides_boon_1 }
			while = {
				limit = { scope:taking_sides_boon_2 = scope:taking_sides_boon_1 }
				clear_saved_scope = taking_sides_boon_2
				save_scope_value_as = {
					name = taking_sides_boon_2
					value = {
						integer_range = {
							min = 0
							max = 9
						}
					}
				}
			}
		}
		hidden_effect = {
			while = {
				count = 2
				random_list = {
					10 = {
						trigger = {
							any_vassal_or_below = {
								primary_title.tier = tier_barony
								primary_title.county = { save_temporary_scope_as = local_dispute_temp_county }
								NOR = {
									is_in_list = dispute_characters
									any_in_list = {
										list = dispute_characters
										AND = {
											exists = scope:local_dispute_temp_county
											is_landed_or_landless_administrative = yes
											primary_title.county = scope:local_dispute_temp_county
										}
									}
								}
							}
						}
						modifier = {
							add = -5
							any_in_list = {
								list = dispute_characters
								is_landed_or_landless_administrative = yes
								has_same_government = prev
							}
						}
						modifier = {
							add = -4
							any_in_list = {
								list = dispute_characters
								count = all
								faith = prev.faith
							}
						}
						random_vassal_or_below = {
							limit = {
								primary_title.tier = tier_barony
								NOT = { is_in_list = dispute_characters }
							}
							add_to_list = dispute_characters
						}
					}
					10 = {
						modifier = {
							add = -9
							any_in_list = {
								list = dispute_characters
								is_landed_or_landless_administrative = no
							}
						}
						every_sub_realm_county = { add_to_list = local_dispute_county_list }
						every_in_list = {
							list = local_dispute_county_list
							culture = { add_to_temporary_list = local_dispute_culture_list }
							faith = { add_to_temporary_list = local_dispute_faith_list }
						}
						random_in_list = {
							list = local_dispute_culture_list
							weight = {
								modifier = {
									add = 10
									this = root.culture
								}
								modifier = {
									add = -10
									any_in_list = {
										list = dispute_characters
										culture = prev
									}
								}
							}
							save_temporary_scope_as = local_dispute_culture
						}
						random_in_list = {
							list = local_dispute_faith_list
							weight = {
								modifier = {
									add = 10
									this = root.faith
								}
								modifier = {
									add = -10
									any_in_list = {
										list = dispute_characters
										faith = prev
									}
								}
								modifier = {
									factor = 50
									any_in_list = {
										list = local_dispute_county_list
										faith = prev
										culture = scope:local_dispute_culture
									}
								}
							}
							save_temporary_scope_as = local_dispute_faith
						}
						create_character = {
							dynasty = none
							culture = scope:local_dispute_culture
							faith = scope:local_dispute_faith
							location = root.capital_province
							template = local_dispute_template
						}
					}
				}
			}
			every_in_list = {
				list = dispute_characters
				ep1_flavor_2030_local_dispute_scope_effect = yes
			}
		}
	}

	option = { # Side with 1st
		name = ep1_flavor.2030.a
		ep1_flavor_2030_option_effect = { WIN = 1 LOSE = 2 }
		ep1_flavor_2030_boon_effect = { NUM = 1 }
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = 1
				ai_honor = 1
			}
			modifier = {
				add = -50
				has_relation_rival = scope:local_dispute_1
			}
			modifier = {
				add = 25
				has_relation_friend = scope:local_dispute_1
			}
		}
	}

	option = { # Side with 2nd
		name = ep1_flavor.2030.b
		ep1_flavor_2030_option_effect = { WIN = 2 LOSE = 1 }
		ep1_flavor_2030_boon_effect = { NUM = 2 }
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = 1
				ai_honor = 1
			}
			modifier = {
				add = -50
				has_relation_rival = scope:local_dispute_2
			}
			modifier = {
				add = 25
				has_relation_friend = scope:local_dispute_2
			}
		}
	}

	option = { # Recruit 1st
		name = ep1_flavor.2030.c
		trigger = {
			exists = scope:local_dispute_1
			scope:local_dispute_1 = { is_in_list = generated_dispute_characters }
		}
		add_prestige = medium_prestige_loss
		send_interface_toast = {
			title = ep1_flavor.2030.c.tt
			left_icon = scope:local_dispute_1
			add_courtier = scope:local_dispute_1
		}
		scope:local_dispute_1 = {
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 15
			}
			hidden_effect = { return_to_court = yes }
		}
		scope:local_county_2 = {
			add_county_modifier = {
				modifier = ep1_flavor_2030_negative_modifier
				years = 5
			}
		}
		stress_impact = {
			arrogant = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_compassion = -1
			}
		}
	}

	option = { # Recruit 2nd
		name = ep1_flavor.2030.d
		trigger = {
			exists = scope:local_dispute_2
			scope:local_dispute_2 = { is_in_list = generated_dispute_characters }
		}
		add_prestige = medium_prestige_loss
		send_interface_toast = {
			title = ep1_flavor.2030.d.tt
			left_icon = scope:local_dispute_2
			add_courtier = scope:local_dispute_2
		}
		scope:local_dispute_2 = {
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 15
			}
			hidden_effect = { return_to_court = yes }
		}
		scope:local_county_1 = {
			add_county_modifier = {
				modifier = ep1_flavor_2030_negative_modifier
				years = 5
			}
		}
		stress_impact = {
			arrogant = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_compassion = -1
			}
		}
	}

	after = {
		stress_impact = {
			just = minor_stress_impact_gain
		}
		if = {
			limit = {
				any_in_list = {
					list = generated_dispute_characters
					employer != root
				}
			}
			every_in_list = {
				list = generated_dispute_characters
				limit = {
					employer != root
				}
				silent_disappearance_effect = yes
			}
		}
	}
}
