namespace = ep3_emperor_yearly

############################
# EP3 Admin Emperor Events #
# by Joe Parkin   	   	   #
# 8000 - 8500              #
############################

# Capital depopulated: move from somewhere else?

scripted_trigger ep3_emperor_yearly_8000_county_holder_trigger = {
	NOT = { has_county_modifier = ep3_development_sacrifice_modifier }
	holder = {
		NOR = {
			this = root
			scope:suggestor ?= this
		}
		OR = {
			is_governor = yes
			liege = { is_governor = yes }
		}
	}
}

scripted_effect ep3_emperor_yearly_8000_save_governor_county_pair_effect = {
	save_scope_as = governor_$COUNT$
	random_in_list = {
		list = developed_counties
		limit = {
			OR = {
				holder = scope:governor_$COUNT$
				holder = { is_vassal_of = scope:governor_$COUNT$ }
			}
		}
		save_scope_as = county_$COUNT$
	}
}

scripted_effect ep3_emperor_yearly_8000_county_effect = {
	scope:governor_$COUNT$ = {
		add_opinion = {
			target = root
			modifier = annoyed_opinion
			opinion = -20
		}
	}
	save_scope_value_as = {
		name = development_loss
		value = {
			value = scope:county_$COUNT$.development_level
			multiply = 0.1
			ceiling = yes
			multiply = -1
		}
	}
	scope:county_$COUNT$ = {
		change_development_level = scope:development_loss
		add_county_modifier = {
			modifier = ep3_development_sacrifice_modifier
			years = 10
		}
	}
}

ep3_emperor_yearly.8000 = {
	type = character_event
	title = ep3_emperor_yearly.8000.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { capital_province = province:496 } # Constantinopolis
				desc = ep3_emperor_yearly.8000.intro_byz
			}
			desc = ep3_emperor_yearly.8000.intro
		}
		desc = ep3_emperor_yearly.8000.desc
	}
	theme = emperor
	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		character = scope:suggestor
		triggered_animation = {
			trigger = { has_trait = blind }
			animation = admiration
		}
		animation = chancellor
	}
	lower_left_portrait = scope:governor_1
	lower_center_portrait = scope:governor_2
	lower_right_portrait = scope:governor_3
	cooldown = { years = 10 }

	trigger = {
		has_ep3_dlc_trigger = yes
		# Ensure you are l'empereur
		highest_held_title_tier >= tier_empire
		is_independent_ruler = yes
		government_allows = administrative
		# Ensure there are people to annoy
		any_vassal = {
			count >= 3
			is_governor = yes
		}
		# Ensure this has not happened already
		NOT = {
			capital_county = { has_county_modifier = ep3_development_waning_modifier }
		}
		# Recent conflict
		OR = {
			any_truce_holder = { }
			any_truce_target = { }
			is_at_war = yes
		}
		# Be nice
		NOR = {
			any_character_epidemic = { }
			capital_province = {
				any_province_epidemic = { }
			}
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			any_truce_holder = { highest_held_title_tier >= tier_kingdom }
			add = 1
		}
		modifier = {
			any_truce_target = { highest_held_title_tier >= tier_kingdom }
			add = 1
		}
		modifier = {
			is_at_war = yes
			add = 1
		}
	}

	immediate = {
		if = { # Steward
			limit = {
				cp:councillor_steward ?= { is_available_adult = yes }
			}
			cp:councillor_steward = { save_scope_as = suggestor }
		}
		else = { # Fallback
			random_courtier = {
				limit = { is_available_adult = yes }
				weight = {
					base = 1
					modifier = {
						has_trait = education_stewardship
						factor = 10
					}
					modifier = { add = stewardship }
					modifier = {
						has_trait = blind
						factor = 0
					}
				}
				save_scope_as = suggestor
			}	
		}
		# Find development target
		ordered_sub_realm_county = {
			limit = { ep3_emperor_yearly_8000_county_holder_trigger = yes }
			order_by = development_level
			position = 2
			save_scope_value_as = {
				name = minimum_development
				value = development_level
			}
		}
		# Find matching counties
		every_sub_realm_county = {
			limit = {
				development_level >= scope:minimum_development
				ep3_emperor_yearly_8000_county_holder_trigger = yes
			}
			add_to_list = developed_counties
			holder = {
				if = {
					limit = { is_governor = yes }
					add_to_list = developed_governors
				}
				else_if = {
					limit = {
						liege = { is_governor = yes }
					}
					liege = { add_to_list = developed_governors }
				}
			}
		}
		hidden_effect = {
			while = {
				count = 3
				random_in_list = {
					list = developed_governors
					limit = {
						trigger_if = {
							limit = { exists = scope:governor_1 }
							this != scope:governor_1
						}
						trigger_if = {
							limit = { exists = scope:governor_2 }
							this != scope:governor_2
						}
					}
					weight = {
						base = 1
						modifier = {
							OR = {
								is_of_major_interest_trigger = { CHARACTER = root }
								liege = { is_of_major_interest_trigger = { CHARACTER = root } }
							}
							add = 5
						}
						modifier = {
							OR = {
								is_of_major_interest_trigger = { CHARACTER = scope:suggestor }
								liege = { is_of_major_interest_trigger = { CHARACTER = scope:suggestor } }
							}
							add = 3
						}
						modifier = {
							OR = {
								is_of_minor_interest_trigger = { CHARACTER = root }
								liege = { is_of_minor_interest_trigger = { CHARACTER = root } }
							}
							add = 5
						}
						modifier = {
							OR = {
								is_of_minor_interest_trigger = { CHARACTER = scope:suggestor }
								liege = { is_of_minor_interest_trigger = { CHARACTER = scope:suggestor } }
							}
							add = 3
						}
					}
					if = {
						limit = { exists = scope:governor_2 }
						ep3_emperor_yearly_8000_save_governor_county_pair_effect = { COUNT = 3 }
					}
					else_if = {
						limit = { exists = scope:governor_1 }
						ep3_emperor_yearly_8000_save_governor_county_pair_effect = { COUNT = 2 }
					}
					else = {
						ep3_emperor_yearly_8000_save_governor_county_pair_effect = { COUNT = 1 }
					}
				}
			}
		}
	}

	option = {
		name = ep3_emperor_yearly.8000.a
		highlight_portrait = scope:governor_1
		ep3_emperor_yearly_8000_county_effect = { COUNT = 1 }
		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_greed = 0.5
			}
			opinion_modifier = {
				who = root
				opinion_target = scope:governor_1
				multiplier = -0.5
			}
		}
	}

	option = {
		name = ep3_emperor_yearly.8000.b
		trigger = { exists = scope:governor_2 }
		highlight_portrait = scope:governor_2
		ep3_emperor_yearly_8000_county_effect = { COUNT = 2 }
		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_greed = 0.5
			}
			opinion_modifier = {
				who = root
				opinion_target = scope:governor_2
				multiplier = -0.5
			}
		}
	}

	option = {
		name = ep3_emperor_yearly.8000.c
		trigger = { exists = scope:governor_3 }
		highlight_portrait = scope:governor_3
		ep3_emperor_yearly_8000_county_effect = { COUNT = 3 }
		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_greed = 0.5
			}
			opinion_modifier = {
				who = root
				opinion_target = scope:governor_3
				multiplier = -0.5
			}
		}
	}

	option = {
		name = ep3_emperor_yearly.8000.d
		capital_county = {
			change_development_level = -2
			add_county_modifier = {
				modifier = ep3_development_waning_modifier
				years = 10
			}
		}
		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_greed = -1
				ai_compassion = 0.25
			}
		}
	}
}

# The fake letter of introduction

scripted_trigger emperor_yearly_8010_valid_governor_trigger = {
	is_governor = yes
	is_available_adult = yes
	NOR = {
		is_close_family_of = root
		is_spouse_of = root
		has_any_scripted_relation = root
	}
}

ep3_emperor_yearly.8010 = {
	type = letter_event
	opening = {
		first_valid = {
			triggered_desc = {
				trigger = { has_title = title:e_byzantium }
				desc = ep3_emperor_yearly.8010.opening_byz
			}
			desc = ep3_emperor_yearly.8010.opening
		}
	}
	desc = ep3_emperor_yearly.8010.desc
	sender = {
		character = scope:governor
		animation = sadness
	}
	cooldown = { years = 10 }

	trigger = {
		has_ep3_dlc_trigger = yes
		# Ensure you are l'empereur
		highest_held_title_tier >= tier_empire
		is_independent_ruler = yes
		government_allows = administrative
		# Ensure there is a governor to be duped
		any_vassal = { emperor_yearly_8010_valid_governor_trigger = yes }
	}

	immediate = {
		random_vassal = {
			limit = { emperor_yearly_8010_valid_governor_trigger = yes }
			weight = {
				base = 1
				modifier = {
					highest_held_title_tier = tier_duchy
					add = 1
				}
				modifier = {
					is_powerful_vassal = yes
					add = -1
				}
				is_of_major_interest_to_weight_up_modifier = { CHARACTER = root }
				is_of_minor_interest_to_weight_up_modifier = { CHARACTER = root }
			}
			save_scope_as = governor
		}
		create_character = {
			template = pool_repopulate_intrigue
			location = scope:governor.capital_province
			dynasty = none
			save_scope_as = liar
		}
		hidden_effect = {
			rightfully_imprison_character_effect = {
				TARGET = scope:liar
				IMPRISONER = scope:governor
			}
		}
		show_as_tooltip = {
			scope:governor = {
				imprison = {
					target = scope:liar
					type = house_arrest
				}
			}
		}
	}

	option = { # Reward
		name = ep3_emperor_yearly.8010.a
		pay_short_term_gold = {
			gold = tiny_gold_value
			target = scope:governor
		}
		reverse_add_opinion = {
			target = scope:governor
			modifier = grateful_opinion
			opinion = 15
		}
		stress_impact = {
			greedy = minor_stress_impact_gain
			callous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_greed = -0.5
			}
			opinion_modifier = {
				who = root
				opinion_target = scope:governor
				multiplier = 0.25
			}
		}
	}

	option = { # Corroborate
		name = ep3_emperor_yearly.8010.b
		change_influence = medium_influence_loss
		add_prestige = minor_prestige_gain
		scope:liar = { release_from_prison = yes }
		scope:governor = { add_courtier = scope:liar }
		reverse_add_opinion = {
			target = scope:liar
			modifier = grateful_opinion
			opinion = 30
		}
		add_hook = {
			target = scope:liar
			type = loyalty_hook
		}
		stress_impact = {
			just = minor_stress_impact_gain
			honest = minor_stress_impact_gain
		}
		ai_chance = {
			base = 0.5
			ai_value_modifier = {
				ai_honor = -0.5
			}
		}
	}

	option = { # Imprison
		name = ep3_emperor_yearly.8010.c
		scope:governor = { change_influence = minor_influence_gain }
		hidden_effect = {
			scope:liar = { release_from_prison = yes }
		}
		send_interface_toast = {
			title = ep3_emperor_yearly.8010.c.tt
			left_icon = scope:liar
			imprison = {
				target = scope:liar
				type = house_arrest
			}
		}
		hidden_effect = {
			scope:liar = { change_prison_type = dungeon }
		}
		stress_impact = {
			lazy = minor_stress_impact_gain
			arbitrary = minor_stress_impact_gain
		}
		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_vengefulness = 0.5
			}
		}
	}

	option = { # Dismiss
		name = ep3_emperor_yearly.8010.d
		scope:governor = { change_influence = medium_influence_gain }
		add_dread = miniscule_dread_gain
		scope:liar = {
			death = {
				death_reason = death_execution
				killer = scope:governor
			}
		}
		stress_impact = {
			forgiving = minor_stress_impact_gain
			compassionate = minor_stress_impact_gain
		}
		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_boldness = -0.25
				ai_energy = -0.25
			}
		}
	}
}

# Selling the purple

scripted_trigger emperor_yearly_8020_valid_purpler_trigger = {
	is_available_ai_adult = yes
	top_liege = root
	is_clergy = no
	NOR = {
		has_character_modifier = ep3_bought_the_purple_modifier
		root.cp:councillor_steward ?= this
		is_spouse_of = root
		has_trait = humble
		has_trait = content
	}
}

scripted_effect emperor_yearly_8020_valid_purpler_effect = {
	save_scope_as = purplest
	pay_short_term_gold = {
		target = root
		gold = scope:purplest.major_gold_value
	}
	if = {
		limit = { is_close_family_of = root }
		change_influence = minor_influence_gain
	}
	else_if = {
		limit = { has_claim_on = root.primary_title }
		change_influence = minor_influence_gain
	}
	else = { change_influence = medium_influence_gain }
	add_character_modifier = ep3_bought_the_purple_modifier
	root.primary_title = {
		change_appointment_investment = {
			target = scope:purplest
			value = 25
		}
	}
}

ep3_emperor_yearly.8020 = {
	type = character_event
	title = ep3_emperor_yearly.8020.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { gold < -150 }
				desc = ep3_emperor_yearly.8020.intro.really_bankrupt
			}
			triggered_desc = {
				trigger = { gold < 0 }
				desc = ep3_emperor_yearly.8020.intro.bankrupt
			}
			desc = ep3_emperor_yearly.8020.intro
		}
		desc = ep3_emperor_yearly.8020.desc
	}
	theme = emperor
	left_portrait = {
		character = root
		animation = worry
	}
	right_portrait = {
		character = scope:suggestor
		animation = admiration
	}
	lower_left_portrait = scope:purpler_1
	lower_center_portrait = scope:purpler_2
	lower_right_portrait = scope:purpler_3
	cooldown = { years = 10 }

	trigger = {
		has_ep3_dlc_trigger = yes
		# Ensure you are l'empereur
		is_roman_emperor_trigger = yes
		# Ensure you are struggling financially
		gold < medium_gold_value
		# Ensure there is someone governor who wants the purple
		OR = {
			any_relation = {
				type = friend
				emperor_yearly_8020_valid_purpler_trigger = yes
			}
			primary_title = {
				any_claimant = { emperor_yearly_8020_valid_purpler_trigger = yes }
			}
			any_vassal = {
				is_governor = yes
				emperor_yearly_8020_valid_purpler_trigger = yes
			}
		}
	}

	weight_multiplier = {
		base = 1
		# Weight up as you get poorer
		modifier = {
			gold < minor_gold_value
			add = 1
		}
		modifier = {
			gold < tiny_gold_value
			add = 1
		}
		modifier = {
			gold < 0
			add = 1
		}
		modifier = {
			gold < 50
			add = 1
		}
		modifier = {
			gold < 100
			add = 1
		}
		modifier = {
			gold < 150
			add = 1
		}
	}

	immediate = {
		# Find suitable candidates
		every_relation = {
			type = friend
			limit = { emperor_yearly_8020_valid_purpler_trigger = yes }
			add_to_list = potential_purplers
		}
		primary_title = {
			every_claimant = {
				limit = { emperor_yearly_8020_valid_purpler_trigger = yes }
				add_to_list = potential_purplers
			}
		}
		every_vassal = {
			limit = {
				is_governor = yes
				emperor_yearly_8020_valid_purpler_trigger = yes
			}
			add_to_list = potential_purplers
		}
		# Select up to 3
		while = {
			limit = {
				# Have not already found 3
				NAND = {
					exists = scope:purpler_1
					exists = scope:purpler_2
					exists = scope:purpler_3
				}
				# Anyone left to pick from
				any_in_list = {
					list = potential_purplers
					NOR = {
						scope:purpler_1 ?= this
						scope:purpler_2 ?= this
						scope:purpler_3 ?= this
					}
				}
			}
			random_in_list = {
				list = potential_purplers
				# Ability to pay
				limit = { gold >= monumental_gold_value }
				alternative_limit = { gold >= massive_gold_value }
				alternative_limit = { gold >= major_gold_value }
				alternative_limit = { always = yes }
				weight = {
					base = 1
					ai_value_modifier = {
						ai_boldness = 0.1
						ai_greed = 0.1
					}
					modifier = { # Prefer arrogant
						has_trait = arrogant
						add = 10
					}
					modifier = { # Prefer ambitious
						has_trait = ambitious
						add = 5
					}
					modifier = { # Prefer born purplers
						has_trait = born_in_the_purple
						factor = 2
					}
					modifier = { # Prefer higher tiers
						highest_held_title_tier > 0
						add = {
							value = highest_held_title_tier
							multiply = 3
						}
					}
					modifier = { # Don't like barons
						highest_held_title_tier = tier_barony
						add = -50
					}
					modifier = { # Don't like counts
						highest_held_title_tier = tier_county
						add = -25
					}
					modifier = { # Prefer best friends
						has_relation_best_friend = root
						add = 10
					}
					modifier = { # Prefer friends
						has_relation_friend = root
						add = 10
					}
					modifier = { # Prefer strong claimants
						has_strong_claim_on = root.primary_title
						add = 10
					}
					modifier = { # Prefer claimants
						has_claim_on = root.primary_title
						add = 10
					}
					# For more diversity
					modifier = {
						has_relation_friend = root
						any_in_list = {
							list = purplers
							has_relation_friend = root
						}
						factor = 0
					}
					modifier = {
						has_claim_on = root.primary_title
						any_in_list = {
							list = purplers
							has_claim_on = root.primary_title
						}
						factor = 0
					}
					modifier = {
						is_vassal_of = root
						is_governor = yes
						any_in_list = {
							list = purplers
							is_vassal_of = root
							is_governor = yes
						}
						factor = 0
					}
					# Interest
					is_of_minor_interest_to_weight_up_modifier = { CHARACTER = root }
					is_of_major_interest_to_weight_up_modifier = { CHARACTER = root }
					modifier = {
						gold <= medium_gold_value
						add = -25
					}
					modifier = {
						gold <= minor_gold_value
						add = -50
					}
					modifier = {
						gold <= 0
						factor = 0
					}
				}
				if = {
					limit = { exists = scope:purpler_2 }
					save_scope_as = purpler_3
				}
				else_if = {
					limit = { exists = scope:purpler_1 }
					save_scope_as = purpler_2
				}
				else = { save_scope_as = purpler_1 }
				remove_from_list = potential_purplers
				add_to_list = purplers
			}
		}
		# Save Suggestor
		if = { # Steward
			limit = {
				cp:councillor_steward ?= { is_available_adult = yes }
			}
			cp:councillor_steward = { save_scope_as = suggestor }
		}
		else = { # Fallback
			random_courtier = {
				limit = {
					is_available_adult = yes
					NOT = { is_in_list = purplers }
				}
				weight = {
					base = 1
					modifier = {
						has_trait = education_stewardship
						factor = 10
					}
					modifier = { add = stewardship }
					modifier = {
						has_trait = blind
						factor = 0
					}
				}
				save_scope_as = suggestor
			}	
		}
	}

	option = { # 1
		name = {
			trigger = {
				scope:purpler_1 = { has_relation_friend = root }
			}
			text = ep3_emperor_yearly.8020.a.friend
		}
		name = {
			trigger = {
				scope:purpler_1 = { has_claim_on = root.primary_title }
			}
			text = ep3_emperor_yearly.8020.a.claimant
		}
		name = {
			trigger = {
				scope:purpler_1 = {
					NOR = {
						has_relation_friend = root
						has_claim_on = root.primary_title
					}
				}
			}
			text = ep3_emperor_yearly.8020.a.vassal
		}
		highlight_portrait = scope:purpler_1
		scope:purpler_1 = { emperor_yearly_8020_valid_purpler_effect = yes }
		stress_impact = {
			arrogant = medium_stress_impact_gain
		}
		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_greed = -0.5
			}
			opinion_modifier = {
				who = root
				opinion_target = scope:purpler_1
				multiplier = 0.25
			}
		}
	}

	option = { # 2
		name = {
			trigger = {
				scope:purpler_2 = { has_relation_friend = root }
			}
			text = ep3_emperor_yearly.8020.b.friend
		}
		name = {
			trigger = {
				scope:purpler_2 = { has_claim_on = root.primary_title }
			}
			text = ep3_emperor_yearly.8020.b.claimant
		}
		name = {
			trigger = {
				scope:purpler_2 = {
					NOR = {
						has_relation_friend = root
						has_claim_on = root.primary_title
					}
				}
			}
			text = ep3_emperor_yearly.8020.b.vassal
		}
		highlight_portrait = scope:purpler_2
		scope:purpler_2 = { emperor_yearly_8020_valid_purpler_effect = yes }
		stress_impact = {
			arrogant = medium_stress_impact_gain
		}
		ai_chance = {
			base = 0.5
			ai_value_modifier = {
				ai_honor = -0.5
			}
			opinion_modifier = {
				who = root
				opinion_target = scope:purpler_2
				multiplier = 0.25
			}
		}
	}

	option = { # 3
		name = {
			trigger = {
				scope:purpler_3 = { has_relation_friend = root }
			}
			text = ep3_emperor_yearly.8020.c.friend
		}
		name = {
			trigger = {
				scope:purpler_3 = { has_claim_on = root.primary_title }
			}
			text = ep3_emperor_yearly.8020.c.claimant
		}
		name = {
			trigger = {
				scope:purpler_3 = {
					NOR = {
						has_relation_friend = root
						has_claim_on = root.primary_title
					}
				}
			}
			text = ep3_emperor_yearly.8020.c.vassal
		}
		highlight_portrait = scope:purpler_3
		scope:purpler_3 = { emperor_yearly_8020_valid_purpler_effect = yes }
		stress_impact = {
			arrogant = medium_stress_impact_gain
		}
		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_rationality = -0.5
			}
			opinion_modifier = {
				who = root
				opinion_target = scope:purpler_3
				multiplier = 0.25
			}
		}
	}

	option = { # PURPLE MINE
		name = ep3_emperor_yearly.8020.d
		add_prestige = medium_prestige_value
		stress_impact = {
			greedy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_boldness = -0.25
				ai_energy = -0.25
			}
		}
	}
}

# Porphyrios returns

scripted_trigger ep3_emperor_yearly_8030_bosporos_trigger = {
	any_sub_realm_county = {
		is_coastal_county = yes
		OR = {
			duchy = title:d_thrace
			duchy = title:d_optimatoi
			duchy = title:d_opsikion
			this = title:c_abydos
		}
	}
}

scripted_effect ep3_emperor_yearly_8030_coast_modifier_effect = {
	every_in_list = {
		list = coast_counties
		custom = every_bosporos_coast_county_tt
		add_county_modifier = {
			modifier = ep3_leviathan_$MODIFIER$_county_modifier
			years = 15
		}
	}
}

scripted_effect ep3_emperor_yearly_8030_sea_modifier_effect = {
	every_in_list = {
		list = sea_provinces
		custom = every_bosporos_sea_province_tt
		add_province_modifier = {
			modifier = ep3_leviathan_$MODIFIER$_province_modifier
			years = 15
		}
	}
}

ep3_emperor_yearly.8030 = {
	type = character_event
	title = ep3_emperor_yearly.8030.t
	desc = ep3_emperor_yearly.8030.desc
	theme = emperor
	override_background = { reference = docks }
	left_portrait = {
		character = root
		animation = worry
	}
	right_portrait = {
		character = scope:complainer
		animation = survey
	}
	cooldown = { years = 50 }

	trigger = {
		has_ep3_dlc_trigger = yes
		# Ensure you are l'empereur
		is_roman_emperor_trigger = yes
		# Have a marshal
		cp:councillor_marshal ?= { is_ai = yes }
		# Ensure you control the Bosporos strait
		completely_controls = title:c_byzantion # Dytika
		completely_controls = title:c_bithynia # Anatoli
		# Never twice
		NOT = { has_character_flag = ep3_porphyrios_cooldown }
	}

	immediate = {
		add_character_flag = ep3_porphyrios_cooldown
		# Sea provinces scopes
		province:8668 = { add_to_list = sea_provinces }
		province:947 = { add_to_list = sea_provinces }
		province:8665 = { add_to_list = sea_provinces }
		# Coastal counties scopes
		title:c_byzantion = { add_to_list = coast_counties }
		title:d_thrace = {
			every_de_jure_county = {
				limit = { is_coastal_county = yes }
				add_to_list = coast_counties
			}
		}
		title:d_optimatoi = {
			every_de_jure_county = {
				limit = { is_coastal_county = yes }
				add_to_list = coast_counties
			}
		}
		title:d_opsikion = {
			every_de_jure_county = {
				limit = { is_coastal_county = yes }
				add_to_list = coast_counties
			}
		}
		title:c_abydos = { add_to_list = coast_counties }
		# Save marshal
		cp:councillor_marshal = { save_scope_as = marshal }
		# Complaining character scope
		cp:councillor_steward ?= { add_to_list = complainants }
		every_vassal = {
			limit = { ep3_emperor_yearly_8030_bosporos_trigger = yes }
			add_to_list = complainants
		}
		every_courtier = { add_to_list = complainants }
		ordered_in_list = {
			list = complainants
			limit = {
				is_available_ai_adult = yes
				is_clergy = no
			}
			order_by = highest_held_title_tier
			save_scope_as = complainer
		}
		# Justinian I for flavor
		character:70512 = { save_scope_as = justinian }
		random = {
			chance = 25
			save_scope_as = artifact_reward
		}
	}

	option = { # Bold
		name = ep3_emperor_yearly.8030.a
		flavor = ep3_emperor_yearly.8030.a.flavor
		scope:marshal = {
			duel = {
				skill = martial
				value = decent_skill_rating
				5 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = 3.5
						min = 1
					}
					desc = ep3_emperor_yearly.8030.a.success
					root = {
						show_as_tooltip = {
							send_interface_toast = {
								title = ep3_emperor_yearly.8030.a.success
								left_icon = root
								add_prestige = medium_prestige_gain
								add_short_term_gold = medium_gold_value
								add_character_modifier = {
									modifier = ep3_leviathan_success_character_modifier
									years = 15
								}
								scope:marshal = { change_influence = medium_influence_gain }
							}
							random = {
								chance = 25
								create_artifact = {
									name = whale_fat_candles_name
									description = whale_fat_candles_description
									rarity = masterwork
									type = miscellaneous
									visuals = small_box
									modifier = artifact_monthly_prestige_5_modifier
									creator = root
									save_scope_as = whale_fat_candles
								}
							}
						}
						hidden_effect = {
							send_interface_toast = {
								type = event_toast_effect_good
								title = ep3_emperor_yearly.8030.a.success
								left_icon = root
								add_prestige = medium_prestige_gain
								add_short_term_gold = medium_gold_value
								add_character_modifier = {
									modifier = ep3_leviathan_success_character_modifier
									years = 15
								}
								scope:marshal = { change_influence = medium_influence_gain }
								if = {
									limit = { exists = scope:artifact_reward }
									create_artifact = {
										name = whale_fat_candles_name
										description = whale_fat_candles_description
										rarity = masterwork
										type = miscellaneous
										visuals = small_box
										modifier = artifact_monthly_prestige_5_modifier
										creator = root
										save_scope_as = whale_fat_candles
									}
								}
							}
						}
					}
				}
				10 = {
					desc = ep3_emperor_yearly.8030.a.failure
					compare_modifier = {
						value = scope:duel_value
						multiplier = -3.5
						min = 1
					}
					root = {
						send_interface_toast = {
							type = event_toast_effect_bad
							title = ep3_emperor_yearly.8030.a.failure
							left_icon = root
							add_prestige = minor_prestige_loss
							remove_short_term_gold = tiny_gold_value
							add_character_modifier = {
								modifier = ep3_leviathan_failure_character_modifier
								years = 15
							}
							ep3_emperor_yearly_8030_coast_modifier_effect = { MODIFIER = loose }
							ep3_emperor_yearly_8030_sea_modifier_effect = { MODIFIER = loose }
						}
					}
				}
			}
		}
		stress_impact = {
			craven = medium_stress_impact_gain
			calm = minor_stress_impact_gain
			forgiving = minor_stress_impact_gain
		}
		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_greed = -0.25
				ai_boldness = 0.5
			}
		}
	}

	option = { # Rational
		name = ep3_emperor_yearly.8030.c
		remove_treasury_or_gold = minor_treasury_or_gold_value
		ep3_emperor_yearly_8030_coast_modifier_effect = { MODIFIER = mandate }
		ep3_emperor_yearly_8030_sea_modifier_effect = { MODIFIER = mandate }
		stress_impact = {
			greedy = medium_stress_impact_gain
			lazy = minor_stress_impact_gain
			callous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_greed = -0.5
				ai_boldness = 0.5
			}
		}
	}

	option = { # Do nothing
		name = ep3_emperor_yearly.8030.d
		flavor = ep3_emperor_yearly.8030.d.flavor
		add_piety = major_piety_gain
		ep3_emperor_yearly_8030_coast_modifier_effect = { MODIFIER = loose }
		ep3_emperor_yearly_8030_sea_modifier_effect = { MODIFIER = loose }
		stress_impact = {
			zealous = medium_stress_impact_loss
			diligent = minor_stress_impact_gain
			compassionate = minor_stress_impact_gain
		}
		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_boldness = -0.25
				ai_energy = -0.25
			}
		}
	}
}

# Iconoclasm
#
#ep3_emperor_yearly.8040 = {
#	type = character_event
#	title = ep3_emperor_yearly.8040.t
#	desc = {
#		desc = ep3_emperor_yearly.8040.intro
#		first_valid = {
#			triggered_desc = {
#				trigger = { exists = scope:truce_target }
#				desc = ep3_emperor_yearly.8040.truce_target
#			}
#			triggered_desc = {
#				trigger = { exists = scope:truce_holder }
#				desc = ep3_emperor_yearly.8040.truce_holder
#			}
#			triggered_desc = {
#				trigger = { exists = scope:epidemic }
#				desc = ep3_emperor_yearly.8040.plague
#			}
#			triggered_desc = {
#				trigger = {
#					any_in_list = {
#						variable = formerly_infected_counties
#						this = title:c_byzantion
#					}
#				}
#				desc = ep3_emperor_yearly.8040.past_plague
#			}
#			desc = ep3_emperor_yearly.8040.debt
#		}
#		desc = ep3_emperor_yearly.8040.desc
#		first_valid = {
#			triggered_desc = {
#				trigger = { exists = scope:family }
#				desc = ep3_emperor_yearly.8040.family
#			}
#			triggered_desc = {
#				trigger = { exists = scope:predecessor }
#				desc = ep3_emperor_yearly.8040.predecessor
#			}
#			desc = ep3_emperor_yearly.8040.leo
#		}
#	}
#	theme = emperor
#	override_background = { reference = ep3_hagia_sophia }
#	left_portrait = {
#		character = root
#		animation = worry
#	}
#	right_portrait = {
#		character = scope:priest
#		triggered_animation = {
#			trigger = { faith = faith:iconoclast }
#			animation = admiration
#		}
#		animation = disapproval
#	}
#	lower_right_portrait = scope:leo
#	cooldown = { years = 50 }
#
#	trigger = {
#		OR = {
#			static_group_filter = {
#				group = ep3_emperor_yearly.8040
#				match = 0.2
#			}
#			has_trait = cynical
#		}
#		has_ep3_dlc_trigger = yes
#		# Ensure you are l'empereur
#		has_title = title:e_byzantium
#		# You are not an Iconoclast
#		faith = faith:orthodox
#		# Something bad has happened
#		OR = {
#			# Won war recently to powerful enemy
#			any_truce_holder = { highest_held_title_tier >= tier_kingdom }
#			# Lost war recently to powerful enemy
#			any_truce_target = { highest_held_title_tier >= tier_kingdom }
#			# In debt
#			gold < -100
#			# Epidemic
#			capital_province = {
#				any_province_epidemic = { }
#			}
#			any_in_list = {
#				variable = formerly_infected_counties
#				title_province = root.capital_province
#			}
#		}
#		# Never twice
#		NOT = { has_character_flag = ep3_iconoclast_cooldown }
#	}
#
#	weight_multiplier = {
#		base = 1
#		modifier = {
#			factor = 2
#			# Constantinopolis is Iconoclast
#			capital_province.faith = faith:iconoclast
#		}
#		modifier = {
#			factor = 2
#			# Iconoclasm is about
#			any_sub_realm_county = { faith = faith:iconoclast }
#		}
#		modifier = {
#			factor = 2
#			# Won war recently to powerful enemy
#			any_truce_holder = { highest_held_title_tier >= tier_kingdom }
#		}
#		modifier = {
#			factor = 2
#			# Lost war recently to powerful enemy
#			any_truce_target = { highest_held_title_tier >= tier_kingdom }
#		}
#		modifier = {
#			factor = 2
#			# In debt
#			gold < -100
#		}
#		modifier = {
#			factor = 2
#			capital_province = {
#				any_province_epidemic = { }
#			}
#		}
#		modifier = {
#			factor = 2
#			any_in_list = {
#				variable = formerly_infected_counties
#				title_province = root.capital_province
#			}
#		}
#	}
#
#	immediate = {
#		add_character_flag = ep3_iconoclast_cooldown
#		capital_province = { save_scope_as = constantinople }
#		character:70502 = { save_scope_as = leo }
#		title:e_byzantium.previous_holder ?= {
#			if = {
#				limit = { faith = faith:iconoclast }
#				save_scope_as = predecessor
#			}
#		}
#		if = {
#			limit = {
#				any_close_family_member = {
#					faith = faith:iconoclast
#					OR = {
#						is_parent_of = root
#						is_grandparent_of = root
#					}
#				}
#			}
#			random_close_family_member = {
#				limit = {
#					sex_same_as = root
#					is_parent_of = root
#					faith = faith:iconoclast
#				}
#				alternative_limit = {
#					is_parent_of = root
#					faith = faith:iconoclast
#				}
#				alternative_limit = {
#					sex_same_as = root
#					is_grandparent_of = root
#					faith = faith:iconoclast
#				}
#				alternative_limit = {
#					is_grandparent_of = root
#					faith = faith:iconoclast
#				}
#				save_scope_as = family
#			}
#		}
#		if = {
#			limit = {
#				title:k_orthodox.holder = { is_vassal_of = root }
#			}
#			title:k_orthodox.holder = { save_scope_as = priest }
#		}
#		else = {
#			ordered_vassal = {
#				limit = {
#					OR = {
#						is_clergy = yes
#						is_theocratic_lessee = yes
#						government_has_flag = government_is_theocracy
#					}
#				}
#				order_by = highest_held_title_tier
#				save_scope_as = priest
#			}
#		}
#		# Fallback
#		if = {
#			limit = { NOT = { exists = scope:priest } }
#			cp:councillor_court_chaplain ?= { save_scope_as = priest }
#		}
#		if = {
#			limit = {
#				# Lost war recently to powerful enemy
#				any_truce_target = { highest_held_title_tier >= tier_kingdom }
#			}
#			ordered_truce_target = {
#				order_by = max_military_strength
#				save_scope_as = truce_target
#			}
#		}
#		if = {
#			limit = {
#				# Won war recently to powerful enemy
#				any_truce_holder = { highest_held_title_tier >= tier_kingdom }
#			}
#			ordered_truce_holder = {
#				order_by = max_military_strength
#				save_scope_as = truce_holder
#			}
#		}
#		scope:constantinople = {
#			if = {
#				limit = {
#					any_province_epidemic = { }
#				}
#				random_province_epidemic = {
#					limit = { outbreak_intensity = apocalyptic }
#					alternative_limit = { outbreak_intensity = major }
#					alternative_limit = { outbreak_intensity = minor }
#					save_scope_as = epidemic
#				}
#			}
#		}
#	}
#
#	option = { # Convert
#		name = ep3_emperor_yearly.8040.a
#		add_piety = major_piety_gain
#		set_character_faith_with_conversion = faith:iconoclast
#		if = {
#			limit = { 
#				faith:iconoclast = { has_doctrine = doctrine_monotheist }
#			}
#			custom_description_no_bullet = { text = mandala_monotheist_warning_tt }
#		}
#		add_character_modifier = {
#			modifier = ep3_iconoclast_modifier
#			years = 15
#		}
#		if = {
#			limit = { ep3_iconoclast_vassal_count > 0 }
#			change_influence = {
#				value = 25
#				multiply = ep3_iconoclast_vassal_count
#			}
#		}
#		scope:priest = {
#			if = {
#				limit = { faith != faith:iconoclast }
#				add_opinion = {
#					target = root
#					modifier = angry_opinion
#					opinion = -30
#				}
#			}
#			else = {
#				add_opinion = {
#					target = root
#					modifier = pleased_opinion
#					opinion = 15
#				}
#			}
#		}
#		stress_impact = {
#			stubborn = medium_stress_impact_gain
#			lazy = medium_stress_impact_gain
#			arrogant = medium_stress_impact_gain
#			brave = medium_stress_impact_gain
#		}
#		ai_chance = {
#			base = 1
#			ai_value_modifier = {
#				ai_boldness = 0.5
#				ai_zeal = 0.5
#			}
#		}
#	}
#
#	option = { # Stay the course
#		name = ep3_emperor_yearly.8040.b
#		change_influence = medium_influence_gain
#		stress_impact = {
#			fickle = medium_stress_impact_gain
#			zealous = medium_stress_impact_gain
#			humble = medium_stress_impact_gain
#			craven = medium_stress_impact_gain
#		}
#		ai_chance = {
#			base = 2
#			ai_value_modifier = {
#				ai_energy = -0.5
#				ai_rationality = 0.5
#			}
#		}
#	}
#}

# Norse raiders

scripted_trigger ep3_emperor_yearly_8050_culture_trigger = {
	OR = {
		this = culture:norse
		any_parent_culture_or_above = { this = culture:norse }
	}
	culture_number_of_counties > 0
}

scripted_effect ep3_emperor_yearly_8050_unchecked_county_effect = {
	change_county_control = -10
	change_development_level = -1
	add_county_modifier = {
		modifier = ep3_raider_unchecked_modifier
		years = 10
	}
}

ep3_emperor_yearly.8050 = {
	type = character_event
	title = ep3_emperor_yearly.8050.t
	desc = ep3_emperor_yearly.8050.desc
	theme = emperor
	override_background = { reference = ep3_constantinople }
	left_portrait = {
		character = root
		animation = war_over_tie
	}
	right_portrait = {
		character = cp:councillor_marshal
		animation = worry
	}
	lower_right_portrait = {
		character = scope:raider
		outfit_tags = { military }
	}
	cooldown = { years = 50 }

	trigger = {
		has_ep3_dlc_trigger = yes
		# Ensure you are l'empereur
		government_allows = administrative
		highest_held_title_tier >= tier_empire
		is_independent_ruler = yes
		# Have a marshal
		cp:councillor_marshal ?= { is_ai = yes }
		# Sea capital
		any_held_county = {
			development_level >= terrible_development_level
			title_province = {
				OR = {
					is_coastal = yes
					is_riverside_province = yes
				}
				# Only oceans that make sense
				OR = {
					geographical_region = world_europe
					geographical_region = world_middle_east_jerusalem
					geographical_region = world_africa_north
					geographical_region = world_asia_minor
					geographical_region = world_steppe_west
				}
			}
		}
		# Never twice
		NOT = { has_character_flag = ep3_sea_raiders_cooldown }
		# Culture
		OR = {
			culture:norse = { culture_number_of_counties >= 1 }
			any_culture_global = {
				culture_number_of_counties >= 1
				any_parent_culture_or_above = { this = culture:norse }
			}
		}
		# Faith
		religion:folkgerman_religion = {
			any_faith = { num_county_followers >= 1 }
		}
	}

	immediate = {
		# Never twice
		add_character_flag = ep3_sea_raiders_cooldown
		# Save marshal
		cp:councillor_marshal = { save_scope_as = marshal }
		# Pick a port county
		if = {
			limit = {
				capital_province = { is_coastal = yes }
			}
			capital_province.county = { save_scope_as = raid_target }
		}
		else = {
			random_held_county = {
				limit = {
					development_level >= terrible_development_level
					title_province = { is_coastal = yes }
				}
				weight = {
					base = 1
					modifier = { add = development_level }
					modifier = {
						title_province = { has_building_or_higher = common_tradeport_01 }
						factor = 2
					}
				}
				save_scope_as = raid_target
			}
		}
		# Save sea for raider location
		scope:raid_target.title_province = {
			random_neighboring_province = {
				limit = { is_sea_province = yes }
				save_scope_as = sea_province
			}
		}
		# Culture
		random_culture_global = {
			limit = {
				has_cultural_pillar = heritage_north_germanic
				has_cultural_tradition = tradition_fp1_coastal_warriors
				ep3_emperor_yearly_8050_culture_trigger = yes
			}
			alternative_limit = {
				has_cultural_tradition = tradition_fp1_coastal_warriors
				ep3_emperor_yearly_8050_culture_trigger = yes
			}
			alternative_limit = {
				has_cultural_pillar = heritage_north_germanic
				ep3_emperor_yearly_8050_culture_trigger = yes
			}
			alternative_limit = { ep3_emperor_yearly_8050_culture_trigger = yes }
			weight = {
				base = 1
				modifier = { add = culture_number_of_counties }
			}
			save_scope_as = raider_culture
		}
		# Faith
		religion:folkgerman_religion = {
			random_faith = {
				limit = { num_county_followers >= 1 }
				weight = {
					base = 1
					modifier = { add = num_county_followers }
				}
				save_scope_as = raider_faith
			}
		}
		# Create raider
		create_character = {
			template = ep3_sea_raider_template
			dynasty = none
			location = scope:sea_province
			culture = scope:raider_culture
			faith = scope:raider_faith
			save_scope_as = raider
		}
		scope:raider = { add_character_flag = wear_armor }
	}

	option = { # Recruit
		name = {
			text = ep3_emperor_yearly.8050.b.byz
			trigger = { primary_title = title:e_byzantium }
		}
		name = {
			text = ep3_emperor_yearly.8050.b
			trigger = { primary_title != title:e_byzantium }
		}
		pay_short_term_gold = {
			gold = minor_gold_value
			target = scope:raider
		}
		if = {
			limit = { has_title = title:e_byzantium }
			scope:raider = { add_trait = varangian }
		}
		add_courtier = scope:raider
		reverse_add_opinion = {
			target = scope:raider
			modifier = loyalty_opinion
			opinion = 20
		}
		stress_impact = {
			paranoid = medium_stress_impact_gain
			vengeful = minor_stress_impact_gain
		}
		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_sociability = 0.5
				ai_greed = -0.5
			}
		}
	}

	option = { # Attack
		name = ep3_emperor_yearly.8050.c
		scope:marshal = {
			duel = {
				skill = martial
				target = scope:raider
				8 = {
					desc = ep3_emperor_yearly.8050.c.success
					compare_modifier = {
						value = scope:duel_value
						multiplier = 3.5
						min = 1
					}
					root = {
						send_interface_toast = {
							type = event_toast_effect_good
							title = ep3_emperor_yearly.8050.c.success
							right_icon = scope:raider
							add_prestige = medium_prestige_gain
							scope:marshal = {
								change_influence = medium_influence_gain
								add_short_term_gold = root.tiny_gold_value
							}
							rightfully_imprison_character_less_verbose_effect = {
								TARGET = scope:raider 
								IMPRISONER = root
							}
						}
					}
				}
				12 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = -3.5
						min = 1
					}
					desc = ep3_emperor_yearly.8050.c.failure
					root = {
						send_interface_toast = {
							type = event_toast_effect_bad
							title = ep3_emperor_yearly.8050.c.failure
							right_icon = scope:raider
							add_prestige = medium_prestige_loss
							scope:raid_target.county = { ep3_emperor_yearly_8050_unchecked_county_effect = yes }
						}
					}
				}
			}
		}
		stress_impact = {
			craven = medium_stress_impact_gain
			lazy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_vengefulness = 0.5
				ai_boldness = 0.5
			}
		}
	}

	option = { # Pay-off
		name = ep3_emperor_yearly.8050.a
		pay_short_term_gold = {
			gold = tiny_gold_value
			target = scope:raider
		}
		stress_impact = {
			greedy = medium_stress_impact_gain
			wrathful = minor_stress_impact_gain
		}
		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_rationality = 0.5
				ai_greed = -0.25
			}
		}
	}

	after = {
		scope:raider = {
			if = {
				limit = {
					OR = {
						employer ?= root
						imprisoner ?= root
					}
				}
				remove_character_flag = wear_armor
			}
			else = { silent_disappearance_effect = yes }
		}
	}
}

# Defecting governor

scripted_trigger ep3_emperor_yearly_8060_defector_trigger = {
	is_ai = yes
	is_governor = yes
	is_at_war = no
	# Something is rotten
	OR = {
		root.legitimacy_level <= 2
		governor_efficiency <= 0.75
	}
	NOR = {
		has_character_flag = ep3_defector_cooldown
		has_trait = loyal
		has_relation_friend = root
		has_relation_lover = root
		is_close_family_of = root
		is_spouse_of = root
		house = root.house
	}
	opinion = {
		target = root
		value < -25
	}
	save_temporary_scope_as = defector_temp
	NOT = {
		root = { has_hook = scope:defector_temp }
	}
	root = {
		# Valid defection sponsor
		any_neighboring_and_across_water_top_liege_realm_owner = {
			ep3_emperor_yearly_8060_neighbour_trigger = { DEFECTOR = scope:defector_temp }
		}
		# Avoid any factions which are ongoing
		NOT = {
			any_targeting_faction = {
				any_faction_member = { this = scope:defector_temp }
				OR = {
					faction_can_press_demands = yes
					faction_is_at_war = yes
				}
			}
		}
	}
}

scripted_trigger ep3_emperor_yearly_8060_neighbour_trigger = {
	highest_held_title_tier > $DEFECTOR$.highest_held_title_tier
	opinion = {
		target = $DEFECTOR$
		value >= 25
	}
	reverse_opinion = {
		target = $DEFECTOR$
		value >= 25
	}
	OR = {
		AND = {
			culture = $DEFECTOR$.culture
			culture != root.culture
		}
		AND = {
			faith = $DEFECTOR$.faith
			faith != root.faith
		}
		AND = {
			dynasty = $DEFECTOR$.dynasty
			dynasty != root.dynasty
		}
		is_spouse_of = $DEFECTOR$
		is_close_family_of = $DEFECTOR$
		has_relation_friend = $DEFECTOR$
		has_relation_lover = $DEFECTOR$
	}
}

scripted_effect ep3_emperor_yearly_8060_defect_effect = {
	add_legitimacy = medium_legitimacy_loss
	create_title_and_vassal_change = {
		type = conquest
		save_scope_as = title_change
		add_claim_on_loss = no
	}
	scope:defector = {
		change_liege = {
			liege = scope:sponsor
			change = scope:title_change
		}
	}
	resolve_title_and_vassal_change = scope:title_change
	custom_tooltip = {
		text = ep3_emperor_yearly.8060.every_title
		scope:defector = {
			every_held_title = {
				title_tier >= county
				save_scope_as = title
				root = { add_pressed_claim = scope:title }
			}
		}
	}
	add_opinion = {
		target = scope:defector
		modifier = treachery_opinion
	}
	scope:defector = {
		if = {
			limit = {
				scope:sponsor = {
					NOT = { government_allows = administrative }
				}
			}
			if = {
				limit = {
					faith = { religion_tag = islam_religion }
				}
				change_government = clan_government
			}
			else = { change_government = feudal_government }
		}
		hidden_effect = {
			every_vassal = {
				limit = { government_allows = administrative }
				if = {
					limit = {
						scope:sponsor = {
							NOT = { government_allows = administrative }
						}
					}
					if = {
						limit = {
							faith = { religion_tag = islam_religion }
						}
						change_government = clan_government
					}
					else = { change_government = feudal_government }
				}
			}
		}
	}
}

ep3_emperor_yearly.8060 = {
	type = character_event
	title = ep3_emperor_yearly.8060.t
	desc = {
		desc = ep3_emperor_yearly.8060.intro
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:defector = { is_spouse_of = scope:sponsor }
					NOT = { is_spouse_of = scope:defector }
				}
				desc = ep3_emperor_yearly.8060.spouse
			}
			triggered_desc = {
				trigger = {
					scope:defector = { is_close_family_of = scope:sponsor }
					NOT = { is_close_family_of = scope:defector }
				}
				desc = ep3_emperor_yearly.8060.family
			}
			triggered_desc = {
				trigger = {
					scope:defector.house = scope:sponsor.house
					house != scope:defector.house
				}
				desc = ep3_emperor_yearly.8060.house
			}
			triggered_desc = {
				trigger = {
					scope:defector.dynasty = scope:sponsor.dynasty
					dynasty != scope:defector.dynasty
				}
				desc = ep3_emperor_yearly.8060.dynasty
			}
			triggered_desc = {
				trigger = {
					scope:defector.culture = scope:sponsor.culture
					culture != scope:defector.culture
					scope:defector.faith = scope:sponsor.faith
					faith != scope:defector.faith
				}
				desc = ep3_emperor_yearly.8060.faith_and_culture
			}
			triggered_desc = {
				trigger = {
					scope:defector.culture = scope:sponsor.culture
					culture != scope:defector.culture
				}
				desc = ep3_emperor_yearly.8060.culture
			}
			triggered_desc = {
				trigger = {
					scope:defector.faith = scope:sponsor.faith
					faith != scope:defector.faith
				}
				desc = ep3_emperor_yearly.8060.faith
			}
			desc = ep3_emperor_yearly.8060.fallback
		}
	}
	theme = emperor
	override_background = { reference = throne_room }
	left_portrait = {
		character = root
		animation = worry
	}
	lower_center_portrait = scope:defector
	lower_right_portrait = scope:sponsor
	cooldown = { years = 50 }

	trigger = {
		has_ep3_dlc_trigger = yes
		# Ensure you are l'empereur
		highest_held_title_tier >= tier_empire
		is_independent_ruler = yes
		government_allows = administrative
		# To avoid edge cases
		is_at_war = no
		# Valid defector exists
		any_vassal = { ep3_emperor_yearly_8060_defector_trigger = yes }
	}

	immediate = {
		ordered_vassal = {
			limit = { ep3_emperor_yearly_8060_defector_trigger = yes }
			order_by = {
				value = 0
				add = {
					value = "opinion(root)"
					abs = yes
				}
			}
			save_scope_as = defector
			add_character_flag = ep3_defector_cooldown
			root = {
				ordered_neighboring_and_across_water_top_liege_realm_owner = {
					limit = {
						any_sub_realm_county = {
							any_neighboring_county = {
								OR = {
									holder = scope:defector
									holder.liege ?= scope:defector
									holder.liege.liege ?= scope:defector
								}
							}
						}
						ep3_emperor_yearly_8060_neighbour_trigger = { DEFECTOR = scope:defector }
					}
					alternative_limit = {
						ep3_emperor_yearly_8060_neighbour_trigger = { DEFECTOR = scope:defector }
					}
					order_by = max_military_strength
					save_scope_as = sponsor
				}
			}
		}
	}

	option = { # Arrest
		name = ep3_emperor_yearly.8060.a
		duel = {
			skill = intrigue
			target = scope:defector
			8 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = 1
				}
				desc = ep3_emperor_yearly.8060.success
				send_interface_toast = {
					title = ep3_emperor_yearly.8060.success
					left_icon = scope:defector
					right_icon = scope:sponsor
					change_influence = medium_influence_gain
					add_dread = medium_dread_gain
					rightfully_imprison_character_less_verbose_effect = {
						TARGET = scope:defector
						IMPRISONER = root
					}
					reverse_add_opinion = {
						target = scope:sponsor
						modifier = annoyed_opinion
						opinion = -20
					}
				}
			}
			12 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = 1
				}
				desc = ep3_emperor_yearly.8060.failure
				send_interface_toast = {
					title = ep3_emperor_yearly.8060.failure
					left_icon = scope:defector
					right_icon = scope:sponsor
					ep3_emperor_yearly_8060_defect_effect = yes
				}
			}
		}
		add_tyranny = medium_tyranny_gain
		stress_impact = {
			just = medium_stress_impact_gain
			forgiving = medium_stress_impact_gain
		}
		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_honor = -0.5
				ai_energy = 0.5
			}
		}
	}

	option = { # Pay off
		name = ep3_emperor_yearly.8060.b
		pay_short_term_gold = {
			gold = medium_gold_value
			target = scope:defector
		}
		reverse_add_opinion = {
			modifier = grateful_opinion
			opinion = 25
			target = scope:defector
		}
		stress_impact = {
			greedy = medium_stress_impact_gain
			vengeful = medium_stress_impact_gain
		}
		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_vengefulness = -0.5
				ai_greed = -0.5
			}
		}
	}

	option = { # May defect
		name = ep3_emperor_yearly.8060.c
		random = {
			chance = 33
			save_scope_as = failure
			send_interface_toast = {
				type = event_toast_effect_bad
				title = ep3_emperor_yearly.8060.defect
				left_icon = scope:defector
				right_icon = scope:sponsor
				ep3_emperor_yearly_8060_defect_effect = yes
			}
		}
		hidden_effect = {
			if = {
				limit = { NOT = { exists = scope:failure } }
				send_interface_toast = {
					type = event_toast_effect_neutral
					title = ep3_emperor_yearly.8060.no_defect
					left_icon = scope:defector
					right_icon = scope:sponsor
				}
			}
		}
		stress_impact = {
			just = medium_stress_impact_gain
			diligent = medium_stress_impact_gain
		}
		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_vengefulness = 0.5
				ai_boldness = 0.5
			}
		}
	}
}
