namespace = ep3_emperor_yearly

##############################
# EP3 Admin (Emperor) Events #
# by Claudia Baldassi        #
# 2000 - 2999	             #
##############################

# Byzantine-only: you have reconquered an important city of the long-lost Empire

ep3_emperor_yearly.2000 = {
	type = character_event
	window = fullscreen_event
	title = ep3_emperor_yearly.2000.t
	desc = {
		desc = ep3_emperor_yearly.2000.desc_intro
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:county = title:c_antiocheia
					OR = { faith.religion = religion:eastern_orthodox_religion faith.religion = religion:catholic_religion faith.religion = religion:protestant_religion }
				}
				desc = ep3_emperor_yearly.2000.desc_antioch
			}
			triggered_desc = {
				trigger = {
					scope:county = title:c_antiocheia
				}
				desc = ep3_emperor_yearly.2000.desc_antioch_not_christ
			}
			triggered_desc = {
				trigger = {
					scope:county = title:c_jerusalem
					OR = { faith.religion = religion:eastern_orthodox_religion faith.religion = religion:catholic_religion faith.religion = religion:protestant_religion }
				}
				desc = ep3_emperor_yearly.2000.desc_jerusalem
			}
			triggered_desc = {
				trigger = {
					scope:county = title:c_jerusalem
				}
				desc = ep3_emperor_yearly.2000.desc_jerusalem_not_christ
			}
			triggered_desc = {
				trigger = {
					scope:county = title:c_alexandria
					OR = { faith.religion = religion:eastern_orthodox_religion faith.religion = religion:catholic_religion faith.religion = religion:protestant_religion }
				}
				desc = ep3_emperor_yearly.2000.desc_alexandria_not_christ
			}
			triggered_desc = {
				trigger = {
					scope:county = title:c_alexandria
				}
				desc = ep3_emperor_yearly.2000.desc_alexandria
			}
			#Maximum estent of the Roman Empire to the East (Trajan) - Abbadan
			triggered_desc = {
				trigger = {
					scope:county = title:c_abbadan
				}
				desc = ep3_emperor_yearly.2000.desc_frontier
			}
			triggered_desc = {
				trigger = {
					scope:county = title:c_edessa
					OR = { faith.religion = religion:eastern_orthodox_religion faith.religion = religion:catholic_religion faith.religion = religion:protestant_religion }
				}
				desc = ep3_emperor_yearly.2000.desc_edessa
			}
			triggered_desc = {
				trigger = {
					scope:county = title:c_edessa
				}
				desc = ep3_emperor_yearly.2000.desc_edessa_not_christ
			}
			triggered_desc = {
				trigger = {
					scope:county = title:c_bari
				}
				desc = ep3_emperor_yearly.2000.desc_bari
			}
			triggered_desc = {
				trigger = {
					scope:county = title:c_siracusa
				}
				desc = ep3_emperor_yearly.2000.desc_syracuse
			}
			triggered_desc = {
				trigger = {
					scope:county = title:c_roma
				}
				desc = ep3_emperor_yearly.2000.desc_rome
			}
			triggered_desc = {
				trigger = {
					scope:county = title:c_ravenna
				}
				desc = ep3_emperor_yearly.2000.desc_ravenna
			}
			triggered_desc = {
				trigger = {
					scope:county = title:c_tunis
				}
				desc = ep3_emperor_yearly.2000.desc_carthago
			}
			triggered_desc = {
				trigger = {
					scope:county = title:c_tangiers
				}
				desc = ep3_emperor_yearly.2000.desc_tingis
			}
			triggered_desc = {
				trigger = {
					scope:county = title:c_murcia
				}
				desc = ep3_emperor_yearly.2000.desc_carthago_spartaria
			}
			triggered_desc = {
				trigger = {
					scope:county = title:c_lombardia
				}
				desc = ep3_emperor_yearly.2000.desc_milan
			}
			triggered_desc = {
				trigger = {
					scope:county = title:c_trier
				}
				desc = ep3_emperor_yearly.2000.desc_trier
			}
			triggered_desc = {
				trigger = {
					OR = {
						scope:county = title:c_cumberland
						scope:county = title:c_northumberland
					}
				}
				desc = ep3_emperor_yearly.2000.desc_hadrians_wall
			}
			triggered_desc = {
				trigger = {
					scope:county = title:c_chandax
				}
				desc = ep3_emperor_yearly.2000.desc_chandax
			}
			triggered_desc = {
				trigger = {
					scope:county = title:c_tourraine
				}
				desc = ep3_emperor_yearly.2000.desc_tours
			}
		}
	}
	theme = war
	override_background = { reference = ep3_triumph }

	trigger = {
		has_ep3_dlc_trigger = yes
		is_roman_emperor_trigger = yes
		trigger_if = {
			limit = {
				scope:county = title:c_tourraine
			}
			NOT = { exists = var:ep3_reconquered_tourraine }
		}
		trigger_else_if = {
			limit = {
				scope:county = title:c_chandax
			}
			NOT = { exists = var:ep3_reconquered_chandax }
		}
		trigger_else_if = {
			limit = {
				OR = {
					scope:county = title:c_cumberland
					scope:county = title:c_northumberland
				}
			}
			NOT = { exists = var:ep3_reconquered_hadrian }
		}
		trigger_else_if = {
			limit = {
				scope:county = title:c_trier
			}
			NOT = { exists = var:ep3_reconquered_trier }
		}
		trigger_else_if = {
			limit = {
				scope:county = title:c_lombardia
			}
			NOT = { exists = var:ep3_reconquered_lombardia }
		}
		trigger_else_if = {
			limit = {
				scope:county = title:c_murcia
			}
			NOT = { exists = var:ep3_reconquered_murcia }
		}
		trigger_else_if = {
			limit = {
				scope:county = title:c_tangiers
			}
			NOT = { exists = var:ep3_reconquered_tangiers }
		}
		trigger_else_if = {
			limit = {
				scope:county = title:c_tunis
			}
			NOT = { exists = var:ep3_reconquered_tunis }
		}
		trigger_else_if = {
			limit = {
				scope:county = title:c_ravenna
			}
			NOT = { exists = var:ep3_reconquered_ravenna }
		}
		trigger_else_if = {
			limit = {
				scope:county = title:c_roma
			}
			NOT = { exists = var:ep3_reconquered_roma }
		}
		trigger_else_if = {
			limit = {
				scope:county = title:c_siracusa
			}
			NOT = { exists = var:ep3_reconquered_siracusa }
		}
		trigger_else_if = {
			limit = {
				scope:county = title:c_bari
			}
			NOT = { exists = var:ep3_reconquered_bari }
		}
		trigger_else_if = {
			limit = {
				scope:county = title:c_edessa
			}
			NOT = { exists = var:ep3_reconquered_edessa }
		}
		trigger_else_if = {
			limit = {
				scope:county = title:c_abbadan
			}
			NOT = { exists = var:ep3_reconquered_abbadan }
		}
		trigger_else_if = {
			limit = {
				scope:county = title:c_alexandria
			}
			NOT = { exists = var:ep3_reconquered_alexandria }
		}
		trigger_else_if = {
			limit = {
				scope:county = title:c_jerusalem
			}
			NOT = { exists = var:ep3_reconquered_jerusalem }
		}
		trigger_else_if = {
			limit = {
				scope:county = title:c_antiocheia
			}
			NOT = { exists = var:ep3_reconquered_antiocheia }
		}
		trigger_else = {
			always = no
		}
	}

	immediate = {
		change_influence = massive_influence_gain
		add_prestige = major_prestige_gain
	}

	#Option A
	option = {
		name = ep3_emperor_yearly.2000.a
		if = {
			limit = {
				OR = {
					scope:county = title:c_antiocheia
					scope:county = title:c_jerusalem
					scope:county = title:c_alexandria
					scope:county = title:c_roma
				}
			}
			scope:county = {
				add_county_modifier = {
					modifier = ep3_restored_pentarchy_seat_county_modifier
					years = 10
				}
			}
			add_character_modifier = {
				modifier = ep3_restored_pentarchy_seat_modifier
				years = 10
			}
		}
		else_if = {
			limit = {
				OR = {
					scope:county = title:c_abbadan
					scope:county = title:c_cumberland
					scope:county = title:c_northumberland
				}
			}
			scope:county = {
				add_county_modifier = {
					modifier = ep3_maximum_border_county_modifier
					years = 10
				}
			}
			add_character_modifier = {
				modifier = ep3_maximum_border_modifier
				years = 10
			}
		}
		else_if = {
			limit = {
				OR = {
					scope:county = title:c_ravenna
					scope:county = title:c_tunis
					scope:county = title:c_murcia
				}
			}
			scope:county = {
				add_county_modifier = {
					modifier = ep3_new_justinian_county_modifier
					years = 10
				}
			}
			add_character_modifier = {
				modifier = ep3_new_justinian_modifier
				years = 10
			}
		}
		else_if = {
			limit = {
				OR = {
					scope:county = title:c_lombardia
					scope:county = title:c_trier
				}
			}
			scope:county = {
				add_county_modifier = {
					modifier = ep3_western_tetrarch_county_modifier
					years = 10
				}
			}
			add_character_modifier = {
				modifier = ep3_western_tetrarch_modifier
				years = 10
			}
		}
		else_if = {
			limit = {
				OR = {
					scope:county = title:c_tangiers
					scope:county = title:c_tourraine
				}
			}
			scope:county = {
				add_county_modifier = {
					modifier = ep3_long_lost_province_county_modifier
					years = 10
				}
			}
			add_character_modifier = {
				modifier = ep3_long_lost_province_modifier
				years = 10
			}
		}
		else_if = {
			limit = {
				OR = {
					scope:county = title:c_edessa
					scope:county = title:c_bari
				}
			}
			scope:county = {
				add_county_modifier = {
					modifier = ep3_long_contested_province_county_modifier
					years = 10
				}
			}
			add_character_modifier = {
				modifier = ep3_long_contested_province_modifier
				years = 10
			}
		}
		else_if = {
			limit = {
				OR = {
					scope:county = title:c_siracusa
					scope:county = title:c_chandax
				}
			}
			scope:county = {
				add_county_modifier = {
					modifier = ep3_medi_gem_county_modifier
					years = 10
				}
			}
			add_character_modifier = {
				modifier = ep3_medi_gem_modifier
				years = 10
			}
		}
	}

	after = {
		if = {
			limit = {
				scope:county = title:c_antiocheia
			}
			set_global_variable = ep3_reconquered_antiocheia
		}
		else_if = {
			limit = {
				scope:county = title:c_jerusalem
			}
			set_global_variable = ep3_reconquered_jerusalem
		}
		else_if = {
			limit = {
				scope:county = title:c_alexandria
			}
			set_global_variable = ep3_reconquered_alexandria
		}
		else_if = {
			limit = {
				scope:county = title:c_abbadan
			}
			set_global_variable = ep3_reconquered_abbadan
		}
		else_if = {
			limit = {
				scope:county = title:c_edessa
			}
			set_global_variable = ep3_reconquered_edessa
		}
		else_if = {
			limit = {
				scope:county = title:c_bari
			}
			set_global_variable = ep3_reconquered_bari
		}
		else_if = {
			limit = {
				scope:county = title:c_siracusa
			}
			set_global_variable = ep3_reconquered_siracusa
		}
		else_if = {
			limit = {
				scope:county = title:c_roma
			}
			set_global_variable = ep3_reconquered_roma
		}
		else_if = {
			limit = {
				scope:county = title:c_ravenna
			}
			set_global_variable = ep3_reconquered_ravenna
		}
		else_if = {
			limit = {
				scope:county = title:c_tunis
			}
			set_global_variable = ep3_reconquered_tunis
		}
		else_if = {
			limit = {
				scope:county = title:c_tangiers
			}
			set_global_variable = ep3_reconquered_tangiers
		}
		else_if = {
			limit = {
				scope:county = title:c_murcia
			}
			set_global_variable = ep3_reconquered_murcia
		}
		else_if = {
			limit = {
				scope:county = title:c_lombardia
			}
			set_global_variable = ep3_reconquered_lombardia
		}
		else_if = {
			limit = {
				scope:county = title:c_trier
			}
			set_global_variable = ep3_reconquered_trier
		}
		else_if = {
			limit = {
				OR = {
					scope:county = title:c_cumberland
					scope:county = title:c_northumberland
				}
			}
			set_global_variable = ep3_reconquered_hadrian
		}
		else_if = {
			limit = {
				scope:county = title:c_chandax
			}
			set_global_variable = ep3_reconquered_chandax
		}
		else_if = {
			limit = {
				scope:county = title:c_tourraine
			}
			set_global_variable = ep3_reconquered_tourraine
		}

		if = {
			limit = {
				NOT = {
					any_owned_story = {
						type = ep3_story_cycle_restoring_rome
					}
				}
			}
			create_story = ep3_story_cycle_restoring_rome
		}
	}
}

# Courtiers grumble about you sending an imperial prince/princess to marry abroad among barbarians

scripted_trigger emperor_2010_valid_child_trigger = {
	is_adult = yes
	is_married = yes
	primary_spouse.culture = {
		NOT = { has_cultural_pillar = heritage_byzantine }
	}
	liege.culture = {
		NOT = { has_cultural_pillar = heritage_byzantine }
	}
	location.culture = {
		NOT = { has_cultural_pillar = heritage_byzantine }
	}
	is_travelling = no
	culture = { has_cultural_pillar = heritage_byzantine }
}

scripted_trigger emperor_2010_valid_courtier_trigger = {
	is_available_healthy_ai_adult = yes
	is_of_major_or_minor_interest_trigger = { CHARACTER = root }
	culture = { has_cultural_pillar = heritage_byzantine }
}

ep3_emperor_yearly.2010 = {
	type = character_event
	title = ep3_emperor_yearly.2010.t
	desc = ep3_emperor_yearly.2010.desc
	theme = emperor
	left_portrait = {
		character = scope:gossip_1
		animation = eyeroll
	}
	right_portrait = {
		character = scope:gossip_2
		animation = throne_room_conversation_1
	}
	lower_center_portrait = scope:sent_off
	cooldown = { years = 50 }

	trigger = {
		is_available_adult = yes
		valid_for_byz_emperor_content_trigger = yes
		any_child = {
			emperor_2010_valid_child_trigger = yes
		}
		any_courtier = {
			count >= 2
			emperor_2010_valid_courtier_trigger = yes
		}
	}

	immediate = {
		random_child = {
			limit = {
				emperor_2010_valid_child_trigger = yes
			}
			save_scope_as = sent_off
		}
		random_courtier = {
			limit = {
				emperor_2010_valid_courtier_trigger = yes
			}
			save_scope_as = gossip_1
		}
		random_courtier = {
			limit = {
				emperor_2010_valid_courtier_trigger = yes
				this != scope:gossip_1
			}
			save_scope_as = gossip_2
		}
		scope:sent_off.primary_spouse = { save_scope_as = spouse }
	}

	#Option A: it was necessary
	option = {
		name = ep3_emperor_yearly.2010.a
		add_character_modifier = {
			modifier = ep3_politics_before_all_modifier
			years = 40
		}
		add_diplomacy_lifestyle_xp = medium_lifestyle_xp
		if = {
			limit = {
				government_allows = administrative
			}
			change_influence = medium_influence_gain
		}
		else = {
			add_prestige = medium_prestige_gain
		}
		stress_impact = {
			arrogant = medium_stress_impact_gain
			deceitful = medium_stress_impact_gain
			zealous = medium_stress_impact_gain
			compassionate = major_stress_impact_gain
			family_first = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				add = -50
				has_trait = arrogant
			}
			modifier = {
				add = -50
				has_trait = deceitful
			}
			modifier = {
				add = 50
				has_trait = diplomat
			}
			modifier = {
				add = 100
				has_trait = ambitious
			}
			modifier = {
				factor = 0
				has_trait = compassionate
			}
			modifier = {
				factor = 0
				has_trait = family_first
			}
		}
	}

	#Option B: a worthy sacrifice
	option = {
		name = {
			trigger = {
				OR = { faith.religion = religion:eastern_orthodox_religion faith.religion = religion:catholic_religion faith.religion = religion:protestant_religion }
			}
			text = ep3_emperor_yearly.2010.b
		}
		name = {
			trigger = {
				NOT = { OR = { faith.religion = religion:eastern_orthodox_religion faith.religion = religion:catholic_religion faith.religion = religion:protestant_religion } }
			}
			text = ep3_emperor_yearly.2010.b2
		}
		add_character_modifier = {
			modifier = ep3_everything_for_byz_modifier
			years = 40
		}
		add_piety = medium_piety_gain
		stress_impact = {
			cynical = medium_stress_impact_gain
			arrogant = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = zealous
				add = 100
			}
			modifier = {
				has_trait = cynical
				add = -50
			}
			modifier = {
				has_trait = humble
				add = 75
			}
		}
	}

	#Option C: shut up
	option = {
		name = ep3_emperor_yearly.2010.c
		add_prestige = minor_prestige_gain
		reverse_add_opinion = {
			target = scope:gossip_1
			modifier = angry_opinion
			opinion = -10
		}
		reverse_add_opinion = {
			target = scope:gossip_2
			modifier = angry_opinion
			opinion = -10
		}
		stress_impact = {
			humble = major_stress_impact_gain
		}
		ai_chance = {
			base = 75
			modifier = {
				has_trait = arrogant
				add = 100
			}
		}
	}
}

# Byzantine-only: The Patriarch refuses to crown you as new emperor because you have a criminal trait (e.g. kinslayer)

ep3_emperor_yearly.2020 = {
	type = character_event
	title = ep3_emperor_yearly.2020.t
	desc = ep3_emperor_yearly.2020.desc
	theme = emperor
	override_background = { reference = ep3_hagia_sophia }
	left_portrait = {
		character = root
		animation = disbelief
	}
	right_portrait = {
		character = scope:patriarch
		animation = anger
	}
	
	trigger = {
		has_ep3_dlc_trigger = yes
		valid_for_byz_emperor_content_trigger = yes
		exists = root.faith.religious_head
		this != faith.religious_head
		faith.religious_head = {
			opinion = {
				target = root
				value <= 0
			}
			location = root.location
		}
		has_any_criminal_trait_in_faith_trigger = {
			CHARACTER = root
			FAITH = root.faith
		}
		NOT = { has_character_flag = has_had_ep3_2020 }
	}

	immediate = {
		faith.religious_head = { save_scope_as = patriarch }
		add_character_flag = has_had_ep3_2020
		random_character_trait = {
			limit = {
				save_temporary_scope_as = temp_trait
				scoped_trait_is_criminal_in_faith_trigger = { TRAIT = scope:temp_trait FAITH = root.faith GENDER_CHARACTER = root }
			}
			save_scope_as = target_criminal_trait
		}
	}

	#Option A: repent
	option = {
		name = ep3_emperor_yearly.2020.a
		flavor = ep3_emperor_yearly.2020.a.tt
		change_influence = major_influence_loss
		add_prestige = major_prestige_loss
		custom_tooltip = ep3_emperor_yearly.2020.a.tt2

		trigger_event = {
			id = ep3_emperor_yearly.2021
			days = 366
		}
		scope:patriarch = {
			add_opinion = {
				target = root
				modifier = forgiven_opinion
			}
		}

		stress_impact = {
			ambitious = medium_stress_impact_gain
			cynical = major_stress_impact_gain
			arrogant = major_stress_impact_gain
			zealous = medium_stress_impact_loss
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = 1
			}
			modifier = {
				has_trait = ambitious
				add = -50
			}
			modifier = {
				has_trait = arrogant
				add = -50
			}
		}
	}

	#Option B: ignore
	option = {
		name = ep3_emperor_yearly.2020.b
		change_influence = major_influence_gain
		add_prestige = major_prestige_gain
		if = {
			limit = { piety_level >= low_piety_level }
			add_piety_level = -1
		}
		else = {
			add_piety = major_piety_loss
		}
		scope:patriarch = {
			add_opinion = {
				target = root
				modifier = impious_opinion
				opinion = -50
			}
		}

		stress_impact = {
			zealous = major_stress_impact_gain
			humble = major_stress_impact_gain
			arrogant = medium_stress_impact_loss
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 1
			}
			modifier = {
				has_trait = zealous
				add = -50
			}
			modifier = {
				has_trait = humble
				add = -50
			}
		}
	}
}

ep3_emperor_yearly.2021 = {
	type = character_event
	title = ep3_emperor_yearly.2021.t
	desc = {
		desc = ep3_emperor_yearly.2021.desc
		first_valid = {
			triggered_desc = {
				trigger = { scope:patriarch = { is_alive = yes } }
				desc = ep3_emperor_yearly.2021.desc_patriarch
			}
			desc = ep3_emperor_yearly.2021.desc_patriarch_new
		}
		desc = ep3_emperor_yearly.2021.desc_end
	}
	theme = crown
	override_background = { reference = ep3_hagia_sophia }
	left_portrait = {
		character = root
		animation = personality_zealous
	}
	right_portrait = {
		character = scope:patriarch_portrait
		animation = wedding_priest
	}
	lower_right_portrait = {
 		trigger = {
 			scope:patriarch = { is_alive = no }
 		}
 		character = scope:patriarch
 	}

 	trigger = {
 		exists = faith.religious_head
 		this != faith.religious_head
 		has_any_criminal_trait_in_faith_trigger = {
			CHARACTER = root
			FAITH = root.faith
		}
 	}

	immediate = {
		if = {
			limit = {
				scope:patriarch = {
					is_alive = yes
					faith = scope:patriarch.faith
				}
			}
			scope:patriarch = { save_scope_as = patriarch_portrait }
		}
		else = {
			faith.religious_head = { save_scope_as = patriarch_portrait }
		}
	}

	option = {
		name = ep3_emperor_yearly.2021.a
		add_legitimacy = minor_legitimacy_gain
		remove_trait = scope:target_criminal_trait
	}
}

# The Patriarch refuses to crown a new emperor after a coup
scripted_trigger valid_clergy_gender_trigger = {
	trigger_if = {
		limit = {
			root.faith = { has_doctrine_parameter = clergy_must_be_male }
		}
		is_male = yes
	}
	trigger_else_if = {
		limit = {
			root.faith = { has_doctrine_parameter = clergy_must_be_female }
		}
		is_male = no
	}
	trigger_else = {
		always = yes
	}
	is_available_ai_adult = yes
	has_education_learning_trigger = yes
}

ep3_emperor_yearly.2030 = {
	type = character_event
	title = ep3_emperor_yearly.2030.t
	desc = ep3_emperor_yearly.2030.desc
	theme = crown
	override_background = { reference = ep3_hagia_sophia }
	left_portrait = {
		character = root
		animation = disbelief
	}
	right_portrait = {
		character = scope:patriarch
		animation = anger
	}
	lower_center_portrait = scope:predecessor
	lower_left_portrait = scope:new_patriarch

	trigger = {
		exists = faith.religious_head
		root != root.faith.religious_head
		title:e_byzantium.previous_holder = { is_alive = yes }
		faith.religious_head = {
			opinion = {
				target = root
				value <= 0
			}
		}
		faith.religious_head = {
			opinion = {
				target = title:e_byzantium.previous_holder
				value > 40
			}
		}
		# You have already had an event about the Patriarch complaining!
		NOT = { has_character_flag = has_had_ep3_2020 }
	}

	immediate = {
		faith.religious_head = { save_scope_as = patriarch }
		title:e_byzantium.previous_holder = { save_scope_as = predecessor }
		hidden_effect = {
			if = {
				limit = {
					any_courtier = {
						valid_clergy_gender_trigger = yes
						is_available_ai_adult = yes
					}
				}
				random_courtier = {
					limit = {
						house = root.house
						valid_clergy_gender_trigger = yes
						is_of_major_or_minor_interest_trigger = { CHARACTER = root }
					}
					alternative_limit = {
						valid_clergy_gender_trigger = yes
						is_of_major_or_minor_interest_trigger = { CHARACTER = root }
					}
					alternative_limit = {
						valid_clergy_gender_trigger = yes
					}
					save_scope_as = new_patriarch
					add_character_flag = {
						flag = need_priest_outfit
					}
				}
			}
			else_if = {
				limit = {
					any_pool_character = {
						province = root.location
						is_available_ai_adult = yes
						valid_clergy_gender_trigger = yes
					}
				}
				random_pool_character = {
					province = root.location
					limit = {
						is_available_ai_adult = yes
						valid_clergy_gender_trigger = yes
					}
					save_scope_as = new_patriarch
					add_character_flag = {
						flag = need_priest_outfit
					}
				}
			}
			else = {
				create_character = {
					template = priest_character_template
					location = root.location
					save_scope_as = new_patriarch
				}
				scope:new_patriarch = {
					add_character_flag = patriarch_created
				}
			}
			scope:new_patriarch = {
				add_trait = loyal
			}
		}
		#needed for loc
		root = { save_scope_as = root_scope }
	}

	# Option A: then it's time for a change!
	option = {
		name = ep3_emperor_yearly.2030.a
		custom_tooltip = ep3_emperor_yearly.2030.a.tt
		create_title_and_vassal_change = {
			type = usurped
			save_scope_as = change
			add_claim_on_loss = no
		}
		faith.religious_head_title = {
			change_title_holder = {
				holder = scope:new_patriarch
				change = scope:change
			}
		}
		resolve_title_and_vassal_change = scope:change

		scope:patriarch = {
			add_opinion = {
				target = root
				modifier = hate_opinion
				opinion = -100
			}
		}
		scope:new_patriarch = {
			add_opinion = {
				target = root
				modifier = pious_opinion
				opinion = 60
			}
		}
		add_hook = {
			target = scope:new_patriarch
			type = favor_hook
		}
		every_vassal = { 
			vassal_stance = zealot
			limit = {
				this != scope:new_patriarch
			}
			custom = every_zealot_vassal
			add_opinion = {
				modifier = impious_opinion
				target = root
				opinion = -25
			}
		}
		every_vassal = { 
			vassal_stance = glory_hound
			custom = every_glory_hound_vassal
			add_opinion = {
				modifier = impressed_opinion
				target = root
				opinion = 20
			}
		}
		stress_impact = {
			zealous = massive_stress_impact_gain
			ambitious = minor_stress_impact_loss
			paranoid = medium_stress_impact_loss
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_zeal = -1
				ai_boldness = 0.5
			}
			modifier = {
				has_trait = ambitious
				add = 100
			}
			modifier = {
				has_trait = zealous
				factor = 0
			}
		}
	}

	#Option B: I'll prove my worth
	option = {
		name = ep3_emperor_yearly.2030.b
		add_character_modifier = {
			modifier = ep3_emperor_proving_themselves_modifier
			years = 15
		}
		custom_tooltip = patriarch_support_2030_desc_tt
		scope:predecessor = {
			add_character_flag = {
				flag = patriarch_support_2030
				years = 15
			}
		}
		stress_impact = {
			humble = medium_stress_impact_gain
			lazy = major_stress_impact_gain
			content = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
		}
	}

	after = {
		if = {
			limit = {
				has_character_flag = has_had_ep3_2020
			}
			remove_character_flag = has_had_ep3_2020
		}
		if = {
			limit = {
				is_ai = yes
				scope:new_patriarch = {
					this != root.faith.religious_head
					has_character_flag = patriarch_created
				}
			}
			scope:new_patriarch = { silent_disappearance_effect = yes }
		}
	}
}

# Patriarch who dislikes you protests you remarrying
ep3_emperor_yearly.2040 = {
	type = character_event
	title = ep3_emperor_yearly.2040.t
	desc = ep3_emperor_yearly.2040.desc
	theme = emperor
	override_background = { reference = ep3_hagia_sophia }
	left_portrait = {
		character = root
		animation = disbelief
	}
	right_portrait = {
		character = scope:patriarch
		animation = anger
	}
	lower_left_portrait = scope:new_wife

	lower_right_portrait = scope:new_patriarch

	trigger = {
		valid_for_byz_emperor_content_trigger = yes
		faith = {
			NOR = {
				has_doctrine = doctrine_polygamy
				has_doctrine = doctrine_concubines
			}
		}
		exists = faith.religious_head
		root != root.faith.religious_head
		faith.religious_head = {
			opinion = {
				target = root
				value <= 20
			}
		}
		#Only dead previous spouses: if divorce is disallowed by your faith, you can't have previous spouses who are alive; if divorce is allowed, there is no reason to nag about your previous spouses; if divorce is approved (by the HoF), it means that the previous wedding has been annuled, so there's nothing to complain about.
		any_former_spouse = {
			even_if_dead = yes
			is_alive = no
			count >= 2
		}
		NOT = { has_character_flag = ep3_has_had_2040 }
	}

	immediate = {
		add_character_flag = ep3_has_had_2040
		faith.religious_head = { save_scope_as = patriarch }
		primary_spouse = { save_scope_as = new_wife }
		random_former_spouse = {
			even_if_dead = yes
			limit = { is_alive = no }
			save_scope_as = old_wife_1
		}
		random_former_spouse = {
			even_if_dead = yes
			limit = {
				is_alive = no
				this != scope:old_wife_1
			}
			save_scope_as = old_wife_2
		}
		hidden_effect = {
			create_character = {
				template = priest_character_template
				location = root.location
				save_scope_as = new_patriarch
			}
			scope:new_patriarch = {
				add_trait = loyal
			}
		}
		#needed for loc
		root = { save_scope_as = root_scope }
	}

	#Option A: replace him!
	option = {
		name = ep3_emperor_yearly.2040.a
		custom_tooltip = ep3_emperor_yearly.2030.a.tt
		create_title_and_vassal_change = {
			type = usurped
			save_scope_as = change
			add_claim_on_loss = no
		}
		faith.religious_head_title = {
			change_title_holder = {
				holder = scope:new_patriarch
				change = scope:change
			}
		}
		resolve_title_and_vassal_change = scope:change

		add_piety = major_piety_loss
		scope:patriarch = {
			add_opinion = {
				target = root
				modifier = hate_opinion
				opinion = -100
			}
		}
		scope:new_patriarch = {
			add_opinion = {
				target = root
				modifier = pious_opinion
				opinion = 60
			}
		}
		add_hook = {
			target = scope:new_patriarch
			type = favor_hook
		}
		every_vassal = { 
			vassal_stance = zealot
			limit = {
				this != scope:new_patriarch
			}
			custom = every_zealot_vassal
			add_opinion = {
				modifier = impious_opinion
				target = root
				opinion = -35
			}
		}
		every_vassal = { 
			vassal_stance = glory_hound
			custom = every_glory_hound_vassal
			add_opinion = {
				modifier = impressed_opinion
				target = root
				opinion = 10
			}
		}
		stress_impact = {
			zealous = massive_stress_impact_gain
			content = major_stress_impact_gain
			ambitious = minor_stress_impact_loss
			lustful = medium_stress_impact_loss
			paranoid = medium_stress_impact_loss
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_zeal = -1
				ai_boldness = 0.5
			}
			modifier = {
				has_trait = ambitious
				add = 100
			}
			modifier = {
				has_trait = lustful
				add = 50
			}
			modifier = {
				has_trait = zealous
				factor = 0
			}
		}
	}

	#Option B: bribe
	option = {
		name = ep3_emperor_yearly.2040.b
		add_piety = medium_piety_loss
		pay_short_term_gold = {
			target = scope:patriarch
			gold = major_gold_value
		}
		scope:patriarch = {
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 20
			}
		}
		add_character_modifier = {
			modifier = ep3_blessed_union_modifier
			years = 25
		}
		stress_impact = {
			honest = major_stress_impact_gain
			greedy = major_stress_impact_gain
			paranoid = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = -0.5
				ai_honor = -0.5
			}
		}
	}

	#Option C: you try to convince him it's fine
	option = {
		name = ep3_emperor_yearly.2040.c
		duel = {
			target = scope:patriarch
			skills = { diplomacy learning }
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = ep3_emperor_yearly.2040.c.success
				send_interface_toast = {
					title = ep3_emperor_yearly.2040.c.success.tt
					left_icon = scope:patriarch
					add_character_modifier = {
						modifier = ep3_blessed_union_modifier
						years = 25
					}
				}
			}
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = ep3_emperor_yearly.2040.c.failure
				send_interface_toast = {
					title = ep3_emperor_yearly.2040.c.failure.tt
					left_icon = scope:patriarch
					add_character_modifier = {
						modifier = ep3_non_blessed_union_modifier
						years = 25
					}
				}
			}
		}
		stress_impact = {
			shy = major_stress_impact_gain
		}
		ai_chance = {
			base = 200
			ai_value_modifier = {
				ai_energy = 1
			}
		}
	}
}

# Flavor event hailing the new emperor, recounting when and if their family last held the throne
ep3_emperor_yearly.2050 = {
	type = character_event
	title = {
		desc = {
			first_valid = {
				triggered_desc = {
					trigger = {
						exists = scope:last_emperor
					}
					desc = ep3_emperor_yearly.2050.t2
				}
				desc = ep3_emperor_yearly.2050.t
			}
		}
	}
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:last_emperor
				}
				desc = ep3_emperor_yearly.2050.desc
			}
			desc = ep3_emperor_yearly.2050.desc_first
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:last_emperor
					scope:last_emperor = { highest_skill = diplomacy }
				}
				desc = ep3_emperor_yearly.2050.desc_diplo
			}
			triggered_desc = {
				trigger = {
					exists = scope:last_emperor
					scope:last_emperor = { highest_skill = martial }
				}
				desc = ep3_emperor_yearly.2050.desc_martial
			}
			triggered_desc = {
				trigger = {
					exists = scope:last_emperor
					scope:last_emperor = { highest_skill = stewardship }
				}
				desc = ep3_emperor_yearly.2050.desc_stewardship
			}
			triggered_desc = {
				trigger = {
					exists = scope:last_emperor
					scope:last_emperor = { highest_skill = intrigue }
				}
				desc = ep3_emperor_yearly.2050.desc_intrigue
			}
			triggered_desc = {
				trigger = {
					exists = scope:last_emperor
					scope:last_emperor = { highest_skill = learning }
				}
				desc = ep3_emperor_yearly.2050.desc_learning
			}
			triggered_desc = {
				trigger = {
					exists = scope:last_emperor
					scope:last_emperor = { highest_skill_including_prowess = prowess }
				}
				desc = ep3_emperor_yearly.2050.desc_prowess
			}
			triggered_desc = {
				trigger = {
					exists = scope:last_emperor
				}
				desc = ep3_emperor_yearly.2050.desc_fallback
			}
			desc = ep3_emperor_yearly.2050.desc_first_accomplish
		}
		triggered_desc = {
			trigger = {
				exists = scope:last_emperor
			}
			desc = ep3_emperor_yearly.2050.desc_body
		}
	}
	theme = crown
	override_background = { reference = throne_room }
	left_portrait = {
		character = root
		animation = personality_bold
	}

	lower_right_portrait = {
		trigger = { exists = scope:last_emperor }
		character = scope:last_emperor
	}

	immediate = {
		#scope:title comes from the on_action that triggers the event
		scope:title = {
			if = {
				limit = {
					any_past_holder = {
						house = root.house
						this != root
					}
				}
				ordered_past_holder_reversed = {
					limit = {
						house = root.house
						this != root
					}
					position = 1
					save_scope_as = last_emperor
				}
			}
		}
	}

	option = {
		name = ep3_emperor_yearly.2050.a
	}
}

# Hold Court event: Councillor/court position asks you to organize a large celebration for the anniversary of the foundation of Constantinople (11 May)
scripted_trigger valid_date_foundation_constantinople_trigger = {
	OR = {
		AND = {
			current_date > 923.5.11
			current_date <= 924.5.11
		}
		AND = {
			current_date > 1023.5.11
			current_date <= 1024.5.11
		}
		AND = {
			current_date > 1123.5.11
			current_date <= 1124.5.11
		}
		AND = {
			current_date > 1223.5.11
			current_date <= 1224.5.11
		}
		AND = {
			current_date > 1323.5.11
			current_date <= 1324.5.11
		}
		AND = {
			current_date > 1423.5.11
			current_date <= 1424.5.11
		}
	}
}

ep3_emperor_yearly.2060 = {
	type = court_event
	title = ep3_emperor_yearly.2060.t
	desc = {
		desc = ep3_emperor_yearly.2060.desc
		triggered_desc = {
			trigger = {
				OR = {
					valid_date_foundation_constantinople_trigger = yes
					AND = {
						current_date > 1323.5.11
						current_date <= 1324.5.11
					}
				}
			}
			desc = ep3_emperor_yearly.2060.desc_century
		}
	}
	theme = court
	court_scene = {
		button_position_character = scope:2060_councillor
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:2060_councillor = {
				group = petitioners_group
				animation = personality_honorable
			}
		}
	}

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

	cooldown = { years = 10 }

	trigger = {
		valid_for_byz_emperor_content_trigger = yes
		# You have Constantinople!
		any_realm_county = {
			this = title:c_byzantion
		}
		OR = {
			cp:councillor_chancellor ?= {
				has_court_event_flag = no
				is_available_ai_adult = yes
			}
			cp:councillor_steward ?= {
				has_court_event_flag = no
				is_available_ai_adult = yes
			}
			any_court_position_holder = {
				has_court_event_flag = no
				is_available_ai_adult = yes
			}
		}
	}

	weight_multiplier = {
		base = 1

		modifier = {
			capital_county = title:c_byzantion
			add = 1
		}
		# The foundation was in 324 - we wanna make it more likely if it's X centuries
		modifier = {
			valid_date_foundation_constantinople_trigger = yes
			add = 4
		}
		# This is the 1000 years from foundation!
		modifier = {
			current_date > 1323.5.11
			current_date <= 1324.5.11
			add = 5
		}

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

	immediate = {
		if = {
			limit = {
				cp:councillor_chancellor ?= {
					has_court_event_flag = no
					is_available_ai_adult = yes
				}
			}
			cp:councillor_chancellor = {
				save_scope_as = 2060_councillor
				court_event_character_flag_effect = yes
			}
		}
		else_if = {
			limit = {
				cp:councillor_steward ?= {
					has_court_event_flag = no
					is_available_ai_adult = yes
				}
			}
			cp:councillor_steward = {
				save_scope_as = 2060_councillor
				court_event_character_flag_effect = yes
			}
		}
		else = {
			random_court_position_holder = {
				limit = {
					has_court_event_flag = no
					is_available_ai_adult = yes
				}
				save_scope_as = 2060_councillor
				court_event_character_flag_effect = yes
			}
		}
		court_event_character_flag_effect = yes
		# for loc
		title:b_constantinople = {
			save_scope_as = queen_city
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	# Option A: greatest celebration for the century or millennia
	option = {
		name = ep3_emperor_yearly.2060.a
		trigger = {
			valid_date_foundation_constantinople_trigger = yes
		}
		title:c_byzantion = {
			add_county_modifier = {
				modifier = ep3_century_celebration_county_modifier
				years = 5
			}
		}
		add_character_flag = {
			flag = constantinople_birthday_flag
			years = 5
		}
		custom_tooltip = constantinople_birthday_flag_tt
		remove_treasury_or_gold = major_treasury_or_gold_value
		stress_impact = {
			greedy = medium_stress_impact_gain
			paranoid = major_stress_impact_gain
			arrogant = minor_stress_impact_loss
			ambitious = medium_stress_impact_loss
			generous = medium_stress_impact_loss
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = -0.5
				ai_sociability = 0.5
			}
		}
	}

	# Option B: celebration
	option = {
		name = ep3_emperor_yearly.2060.b
		trigger = {
			NOT = {
				valid_date_foundation_constantinople_trigger = yes
			}
		}
		title:c_byzantion = {
			add_county_modifier = {
				modifier = ep3_foundation_celebration_county_modifier
				years = 5
			}
		}
		add_character_flag = {
			flag = constantinople_birthday_flag
			years = 5
		}
		custom_tooltip = constantinople_birthday_flag_tt
		remove_treasury_or_gold = major_treasury_or_gold_value
		stress_impact = {
			greedy = medium_stress_impact_gain
			paranoid = major_stress_impact_gain
			arrogant = minor_stress_impact_loss
			ambitious = minor_stress_impact_loss
			generous = minor_stress_impact_loss
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = -0.5
				ai_sociability = 0.5
			}
		}
	}
	# Option C: not the right time
	option = {
		name = ep3_emperor_yearly.2060.c
		stress_impact = {
			arrogant = minor_stress_impact_gain
			ambitious = minor_stress_impact_gain
			generous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_greed = 1
			}
		}
	}
	after = {
		clear_court_event_participation = yes
		scope:2060_councillor = {
			clear_court_event_participation = yes
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

# Hold Court event: Foreigners bring exotic diplomatic gifts: what are you supposed to do with a giraffe??
ep3_emperor_yearly.2070 = {
	type = court_event
	title = ep3_emperor_yearly.2070.t
	desc = ep3_emperor_yearly.2070.desc
	theme = court
	court_scene = {
		button_position_character = scope:ambassador
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:ambassador = {
				group = petitioners_group
				animation = obsequious_bow
			}
		}
	}

	lower_left_portrait = scope:ambassador_liege

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

	cooldown = { years = 25 }

	trigger = {
		is_valid_for_east_asian_events_geo_trigger = no
		has_ep3_dlc_trigger = yes
		NOT = {
			# You don't own any province where giraffes could reasonably be
			any_realm_county = {
				any_county_province = {
					geographical_region = custom_sub_saharan_africa_immediate
				}
			}

		}
		any_county_in_region = {
			region = custom_sub_saharan_africa_immediate
			holder = { is_ai = yes }
			holder.top_liege = { is_ai = yes }
		}
		#Admin only
		government_allows = administrative
		#Admin Emperor
		top_liege = this
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = 0.2
			any_county_in_region = {
				region = custom_sub_saharan_africa_immediate
				faith.religion = root.faith.religion
			}
		}
		modifier = {
			add = 0.3
			any_county_in_region = {
				region = custom_sub_saharan_africa_immediate
				faith = root.faith
			}
		}

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

	immediate = {
		random_county_in_region = {
			region = custom_sub_saharan_africa_immediate
			limit = {
				holder = { is_ai = yes }
				holder.top_liege = { is_ai = yes }
				faith = root.faith
			}
			alternative_limit = {
				holder = { is_ai = yes }
				holder.top_liege = { is_ai = yes }
				faith.religion = root.faith.religion
			}
			alternative_limit = {
				holder = { is_ai = yes }
				holder.top_liege = { is_ai = yes }
			}
			save_scope_as = giraffe_county
		}
		scope:giraffe_county.holder.top_liege = {
			save_scope_as = ambassador_liege
		}
		create_character = {
			template = ambassador_template
			location = root.location
			faith = scope:giraffe_county.faith
			culture = scope:giraffe_county.culture
			gender_female_chance = 50 
			save_scope_as = ambassador
		}
		court_event_character_flag_effect = yes
		scope:ambassador = {
			court_event_character_flag_effect = yes
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	#Option A: accept gifts
	option = {
		name = ep3_emperor_yearly.2070.a
		add_character_modifier = {
			modifier = ep3_exotic_giraffe_modifier
			years = 20
		}
		if = {
			limit = {
				scope:ambassador_liege = {
					in_diplomatic_range = root
				}
			}
			scope:ambassador_liege = {
				add_opinion = {
					target = root
					modifier = accepted_gift_opinion
				}
			}
		}
		stress_impact = {
			humble = medium_stress_impact_gain
			gregarious = medium_stress_impact_gain
			zealous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = humble
				add = -25
			}
			modifier = {
				has_trait = gregarious
				add = -25
			}
			modifier = {
				has_trait = zealous
				add = -25
			}
		}
	}

	#Option B: bribe the ambassador
	option = {
		name = ep3_emperor_yearly.2070.b
		flavor = ep3_emperor_yearly.2070.b.tt
		duel = {
			skills = { diplomacy intrigue }
			target = scope:ambassador
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				modifier = {
					scope:ambassador.faith.religion = root.faith.religion
					add = 10
				}
				modifier = {
					scope:ambassador.faith = root.faith
					add = 10
				}
				modifier = {
					OR = {
						scope:ambassador_liege = { has_royal_court = no }
						scope:ambassador_liege = {
							court_grandeur_current_level < root.court_grandeur_current_level
						}
					}
					add = 15
				}
				modifier = {
					diplomacy >= high_skill_rating
					add = 10
				}
				modifier = {
					legitimacy_level >= scope:ambassador_liege.legitimacy_level
					add = 10
				}
				#Everyone is impressed by your automata etc
				modifier = {
					valid_for_byz_emperor_content_trigger = yes
					add = 10
				}
				desc = ep3_emperor_yearly.2070.b.success
				send_interface_toast = {
					left_icon = scope:ambassador
					title = ep3_emperor_yearly.2070.b.success.tt
					add_courtier = scope:ambassador
				}
			}
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				modifier = {
					faith = {
						faith_hostility_level = {
							target = scope:ambassador.faith
							value > faith_astray_level
						}
					}
					add = 15
				}
				modifier = {
					diplomacy <= mediocre_skill_rating
					add = 10
				}
				modifier = {
					scope:ambassador_liege = {
						court_grandeur_current_level > root.court_grandeur_current_level
					}
					add = 15
				}
				desc = ep3_emperor_yearly.2070.b.failure
				send_interface_toast = {
					left_icon = scope:ambassador
					title = ep3_emperor_yearly.2070.b.failure.tt
					add_courtier = scope:ambassador
					pay_short_term_gold = {
						target = scope:ambassador
						gold = medium_gold_value
					}
				}
			}
		}
		stress_impact = {
			honest = medium_stress_impact_gain
			just = medium_stress_impact_gain
			paranoid = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = honest
				add = -25
			}
			modifier = {
				has_trait = just
				add = -25
			}
			modifier = {
				has_trait = paranoid
				add = -25
			}
		}
	}

	#Option C: opt out
	option = {
		name = ep3_emperor_yearly.2070.c
		flavor = ep3_emperor_yearly.2070.c.tt
		add_treasury_or_gold = minor_treasury_or_gold_value
		stress_impact = {
			base = minor_stress_impact_loss
		}
		ai_chance = {
			base = 50
			modifier = {
				has_trait = lazy
				add = 25
			}
		}
	}

	after = {
		clear_court_event_participation = yes
		if = {
			limit = {
				is_ai = yes
				scope:ambassador = { liege != root }
			}
			scope:ambassador = {
				silent_disappearance_effect = yes
			}
		}
		else_if = {
			limit = {
				is_ai = no
				scope:ambassador = { liege != root }
			}
			hidden_effect = {
				scope:ambassador = {
					move_to_pool_at = scope:ambassador_liege.capital_province
				}
			}
		}
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

# Someone suggests opening a (grammar) school for the poor
ep3_emperor_yearly.2080 = {
	type = court_event
	title = ep3_emperor_yearly.2080.t
	desc = {
		desc = ep3_emperor_yearly.2080.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					valid_for_byz_emperor_content_trigger = yes
				}
				desc = ep3_emperor_yearly.2080.desc_byz
			}
			desc = ep3_emperor_yearly.2080.desc_gen
		}
	}
	theme = court
	court_scene = {
		button_position_character = scope:school_proposer
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:school_proposer = {
				group = petitioners_group
				animation = obsequious_bow
			}
		}
	}

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

	cooldown = { years = 25 }

	trigger = {
		has_ep3_dlc_trigger = yes
		#Only admin systems tolerate education as a mean for social advancement
		government_allows = administrative
		#Emperor
		top_liege = this
		#Not ongoing in the same capital
		capital_county = {
			NOT = {
				has_county_modifier = ep3_grammar_school_county_modifier
			}
		}
		#Ongoing building construction in the capital
		capital_county = {
			any_county_province = {
				has_ongoing_construction = yes
			}
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = 1
			valid_for_byz_emperor_content_trigger = yes
		}
		modifier = {
			add = 1
			employs_court_position = high_almoner_court_position
		}
		# Court weightings.
 		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_scholarly }
	}

	immediate = {
		court_event_character_flag_effect = yes
		capital_county = {
			save_scope_as = school_county
		}
		if = {
			limit = {
				any_court_position_holder = {
					type = high_almoner_court_position
					is_available_ai_adult = yes
				}
			}
			random_court_position_holder = {
				type = high_almoner_court_position
				limit = {
					is_available_ai_adult = yes
				}
				save_scope_as = school_proposer
			}
		}
		else_if = {
			limit = {
				exists = cp:councillor_court_chaplain
				cp:councillor_court_chaplain = { is_available_ai_adult = yes }
			}
			cp:councillor_court_chaplain = { save_scope_as = school_proposer }
		}
		else = {
			random_courtier = {
				limit = {
					is_available_ai_adult = yes
				}
				save_scope_as = school_proposer
			}
		}
		scope:school_proposer = { court_event_character_flag_effect = yes }
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	# Option A: Build the school
	option = {
		name = ep3_emperor_yearly.2080.a
		flavor = ep3_emperor_yearly.2080.a.tt
		capital_county = {
			add_county_modifier = {
				modifier = ep3_school_building_county_modifier
				years = 5
			}
		}
		trigger_event = {
			id = ep3_emperor_yearly.2081
			years = 5
		}
		remove_treasury_or_gold = medium_treasury_or_gold_value
		stress_impact = {
			greedy = major_stress_impact_gain
			arrogant = medium_stress_impact_gain
			lazy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = -0.5
				ai_compassion = 1
			}
		}
	}

	# Option B: opt out
	option = {
		name = ep3_emperor_yearly.2080.b
		stress_impact = {
			compassionate = major_stress_impact_gain
			diligent = medium_stress_impact_gain
			just = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 0.5
				ai_energy = -0.5
			}
		}
	}

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

ep3_emperor_yearly.2081 = {
	hidden = yes

	trigger = {
		scope:school_county.holder = root
	}

	on_trigger_fail = {
		scope:school_county.holder ?= {
			trigger_event = ep3_emperor_yearly.2081
		}
	}

	immediate = {
		scope:school_county = {
			add_county_modifier = {
				modifier = ep3_grammar_school_county_modifier
				years = 50
			}
		}
	}
}

# Very popular mime is making offers and demands
ep3_emperor_yearly.2090 = {
	type = court_event
	title = ep3_emperor_yearly.2090.t
	desc = ep3_emperor_yearly.2090.desc
	theme = court
	lower_right_portrait = scope:marshal
	court_scene = {
		button_position_character = scope:mime
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:mime = {
				group = petitioners_group
				animation = obsequious_bow
			}
		}
	}

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

	cooldown = { years = 15 }

	trigger = {
		# Only Byz has famous mimes
		valid_for_byz_emperor_content_trigger = yes
		# Ongoing increase control task
		cp:councillor_marshal ?= {
			is_performing_council_task = task_increase_control
		}
		NOT = { employs_court_position = court_jester_court_position }
		can_employ_court_position_type = court_jester_court_position
	}

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

	immediate = {
		court_event_character_flag_effect = yes
		cp:councillor_marshal = {
			councillor_task_target ?= {
				save_scope_as = control_target
			}
		}
		if = {
			limit = {
				any_pool_character = {
					province = root.location
					has_character_flag = famous_mime
				}
			}
			random_pool_character = {
				province = root.location
				limit = {
					has_character_flag = famous_mime
				}
				save_scope_as = mime
			}
		}
		else_if = {
			limit = {
				any_pool_character = {
					province = root.location
					culture = root.capital_county.culture
					faith = {
						this = root.capital_county.faith
						has_dominant_ruling_gender = prev
					}
					diplomacy >= 14
				}
			}
			random_pool_character = {
				province = root.location
				limit = {
					culture = root.capital_county.culture
					faith = {
						this = root.capital_county.faith
						has_dominant_ruling_gender = prev
					}
					diplomacy >= 14
				}
				save_scope_as = mime
			}
			hidden_effect = {
				if = {
					limit = {
						scope:mime = {
							NOT = { has_trait = shrewd }
						}
					}
					scope:mime = { add_trait = shrewd }
				}
				if = {
					limit = {
						scope:mime = {
							NOT = { has_trait = athletic }
						}
					}
					scope:mime = { add_trait = athletic }
				}
			}
		}
		else = {
			create_character = {
				location = root.location
				template = mime_template
				save_scope_as = mime
			}
		}
		scope:mime = {
			court_event_character_flag_effect = yes
			add_character_flag = famous_mime
		}
		cp:councillor_marshal = {
			save_scope_as = marshal
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	# Option A: hire to help
	option = {
		name = ep3_emperor_yearly.2090.a
		add_courtier = scope:mime
		court_position_grant_effect = {
			EMPLOYER = root
			POS = court_jester
			CANDIDATE = scope:mime
		}
		scope:mime = {
			add_character_flag = famous_mime_control
		}
		custom_tooltip = ep3_emperor_yearly.2090.a.tt
		stress_impact = {
			arrogant = medium_stress_impact_gain
			callous = medium_stress_impact_gain
			vengeful = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 1
			}
		}
	}

	# Option B: hire for yourself
	option = {
		name = ep3_emperor_yearly.2090.b
		add_courtier = scope:mime
		court_position_grant_effect = {
			EMPLOYER = root
			POS = court_jester
			CANDIDATE = scope:mime
		}
		scope:mime = {
			add_character_flag = famous_mime_court
		}
		custom_tooltip = ep3_emperor_yearly.2090.b.tt
		stress_impact = {
			diligent = medium_stress_impact_gain
			compassionate = minor_stress_impact_gain
			gregarious = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_sociability = 1
			}
		}
	}

	# Option C: opt out
	option = {
		name = ep3_emperor_yearly.2090.c
		stress_impact = {
			base = minor_stress_impact_loss
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_energy = -1
			}
		}
	}

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

# Different copies of a diplomatic treaty with a neighbor don't match.
scripted_trigger 2100_valid_neighboring_county_trigger = {
	any_neighboring_county = {
		holder.top_liege = root
	}
	save_temporary_scope_as = check_county
	NOT = {
		root = {
			has_claim_on = scope:check_county
		}
	}
}

ep3_emperor_yearly.2100 = {
	type = court_event
	title = ep3_emperor_yearly.2100.t
	desc = ep3_emperor_yearly.2100.desc
	theme = court
	court_scene = {
		button_position_character = scope:chancellor
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:chancellor = {
				group = petitioners_group
				animation = obsequious_bow
			}
		}
	}

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

	cooldown = { years = 15 }

	trigger = {
		government_allows = administrative
		top_liege = this
		any_neighboring_top_liege_realm_owner = {
			is_ai = yes
			NOT = { is_at_war_with = root }
			custom_tooltip = {
				text = ep3_emperor_yearly.2100.angry_error_log
				any_top_realm_border_county = {
					2100_valid_neighboring_county_trigger = yes
				}
			}
		}
		cp:councillor_chancellor ?= {
			is_available_ai_adult = yes
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = 0.5
			valid_for_byz_emperor_content_trigger = yes
		}
		modifier = {
			add = 4
			cp:councillor_court_chaplain ?= {
				is_performing_council_task = task_fabricate_claim
			}
		}
		# Court weightings.
 		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_diplomatic }
 		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_intrigue }
	}

	immediate = {
		court_event_character_flag_effect = yes
		cp:councillor_chancellor = {
			save_scope_as = chancellor
			court_event_character_flag_effect = yes
		}
		random_neighboring_top_liege_realm_owner = {
			limit = {
				is_ai = yes
				NOT = { is_at_war_with = root }
				any_top_realm_border_county = {
					2100_valid_neighboring_county_trigger = yes
				}
			}
			random_top_realm_border_county = {
				limit = {
					2100_valid_neighboring_county_trigger = yes
				}
				save_scope_as = contested_county
			}
			save_scope_as = neighbor	
		}
		random_top_realm_border_county = {
			limit = {
				any_neighboring_county = {
					this = scope:contested_county
				}
				NOT = {
					scope:neighbor = { has_claim_on = prev }
				}
			}
			save_scope_as = our_county
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	# Option A: try to gain claim
	option = {
		name = ep3_emperor_yearly.2100.a
		duel = {
			skill = diplomacy
			target = scope:neighbor
			60 = { #Success: get claim
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = ep3_emperor_yearly.2100.a.success
				send_interface_toast = {
					title = ep3_emperor_yearly.2100.a.success.tt
					left_icon = scope:neighbor
					add_pressed_claim = scope:contested_county
				}
			}
			35 = { #Failure: no claim
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = ep3_emperor_yearly.2100.a.failure
				send_interface_toast = {
					title = ep3_emperor_yearly.2100.a.failure.tt
					left_icon = scope:neighbor
					add_diplomacy_lifestyle_xp = medium_lifestyle_xp
				}
			}
			5 = { #Crit failure: get them a claim
				trigger = {
					exists = scope:our_county
				}
				compare_modifier = {
					value = scope:duel_value
					multiplier = -4.5
				}
				desc = ep3_emperor_yearly.2100.a.crit_fail
				send_interface_toast = {
					title = ep3_emperor_yearly.2100.a.crit_fail.tt
					left_icon = scope:neighbor
					scope:neighbor = {
						add_pressed_claim = scope:our_county
					}
				}
			}
		}
		stress_impact = {
			just = medium_stress_impact_gain
			honest = medium_stress_impact_gain
			diligent = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 1
				ai_honor = -0.5
			}
		}
	}

	# Option B: let's collaborate
	option = {
		name = ep3_emperor_yearly.2100.b
		trigger = {
			NOR = {
				has_truce = scope:neighbor
				is_allied_to = scope:neighbor
			}
		}
		add_truce_both_ways = {
			character = scope:neighbor
			years = 5
			name = TRUCE_COLLABORATION
		}
		scope:neighbor = {
			add_opinion = {
				target = root
				modifier = collaborative_opinion
				opinion = 30
			}
		}
		stress_impact = {
			vengeful = medium_stress_impact_gain
			callous = medium_stress_impact_gain
			arrogant = major_stress_impact_gain
			ambitious = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 0.5
				ai_honor = 1
			}
		}
	}

	# Option C: opt out
	option = {
		name = ep3_emperor_yearly.2100.c
		add_intrigue_lifestyle_xp = minor_lifestyle_xp
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_energy = -0.5
			}
		}
	}

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

# Merchants of a foreign culture offer their services as translators and interpreters.
ep3_emperor_yearly.2110 = {
	type = court_event
	title = ep3_emperor_yearly.2110.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					culture = scope:provincial_culture
				}
				desc = ep3_emperor_yearly.2110.desc_same
			}
			desc = ep3_emperor_yearly.2110.desc_other
		}
		desc = ep3_emperor_yearly.2110.desc
	}
	theme = court
	court_scene = {
		button_position_character = scope:merchant
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:merchant = {
				group = petitioners_group
				animation = obsequious_bow
			}
		}
	}

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

	cooldown = { years = 15 }

	trigger = {
		OR = {
			has_ep3_dlc_trigger = yes
			has_tgp_dlc_trigger = yes
		}
		government_allows = administrative
		top_liege = this
		any_realm_county = {
			culture != root.capital_county.culture
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = 0.5
			valid_for_byz_emperor_content_trigger = yes
		}
		# Court weightings.
 		ep1_weight_up_for_court_type_modifier = { COURT_TYPE = court_diplomatic }
	}

	immediate = {
		court_event_character_flag_effect = yes
		root.capital_county.culture = { save_scope_as = capital_culture }
		random_realm_county = {
			limit = {
				culture != scope:capital_culture
			}
			save_scope_as = provincial_county
			culture = { save_scope_as = provincial_culture }
		}
		random_pool_character = {
			province = scope:provincial_county.title_province
			limit = {
				stewardship >= 14
				culture = scope:provincial_culture
			}
			save_scope_as = merchant
		}
		if = {
			limit = {
				exists = scope:merchant
			}
			scope:merchant = {
				hidden_effect = {
					move_to_pool_at = root.location
					learn_language_of_culture = scope:capital_culture
					if = {
						limit = {
							NOT = {
								has_trait = lifestyle_traveler
							}
						}
						add_trait = lifestyle_traveler
						add_random_tiered_trait_track_xp_effect = {
							TRAIT = lifestyle_traveler
							TRACK = travel
							LEVEL_1 = yes
							LEVEL_3 = no
						}
						add_random_tiered_trait_track_xp_effect = {
							TRAIT = lifestyle_traveler
							TRACK = danger
							LEVEL_1 = yes
							LEVEL_3 = no
						}
					}
				}
			}
		}
		else = {
			create_character = {
				location = root.location
				template = good_merchant_template
				culture = scope:provincial_culture
				faith = scope:provincial_county.faith
				save_scope_as = merchant
			}
			hidden_effect = {
				scope:merchant = {
					if = {
						limit = {
							NOT = {
								knows_language_of_culture = scope:capital_culture
							}
						}
						learn_language_of_culture = scope:capital_culture
					}
					add_character_flag = created
				}
			}
		}
		scope:merchant = { court_event_character_flag_effect = yes }
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	# Option A: Send to local administration
	option = {
		name = ep3_emperor_yearly.2110.a
		scope:capital_culture = {
			change_cultural_acceptance = {
				target = scope:provincial_culture
				value = low_positive_culture_acceptance
				desc = cultural_acceptance_gain_hold_court_event_outcome
			}
		}
		scope:merchant = {
			hidden_effect = {
				move_to_pool_at = scope:provincial_county
			}
		}
		#Governor
		scope:provincial_county.duchy.holder = {
			hidden_effect = { add_courtier = scope:merchant }
		}
		stress_impact = {
			ambitious = minor_stress_impact_gain
			arbitrary = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 0.5
			}
			modifier = {
				has_trait = ambitious
				add = -25
			}
		}
	}

	# Option B: Send to central administration
	option = {
		name = ep3_emperor_yearly.2110.b
		scope:capital_culture = {
			change_cultural_acceptance = {
				target = scope:provincial_culture
				value = miniscule_positive_culture_acceptance
				desc = cultural_acceptance_gain_hold_court_event_outcome
			}
		}
		add_courtier = scope:merchant
		change_influence = medium_influence_gain
		pay_treasury_or_gold = {
			target = scope:merchant
			value = minor_treasury_or_gold_value
		}
		stress_impact = {
			lazy = medium_stress_impact_gain
			greedy = medium_stress_impact_gain
			arrogant = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 0.5
			}
			modifier = {
				has_trait = lazy
				add = -25
			}
		}
	}

	# Option C: opt out
	option = {
		name = ep3_emperor_yearly.2110.c
		add_prestige = minor_prestige_gain
		scope:merchant = { add_character_flag = unused }
		stress_impact = {
			gregarious = minor_stress_impact_gain
			compassionate = minor_stress_impact_gain
			diligent = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50
		}
	}

	after = {
		scope:merchant = {
			clear_court_event_participation = yes
			if = {
				limit = {
					root = { is_ai = yes }
					has_character_flag = created
					has_character_flag = unused
				}
				silent_disappearance_effect = yes
			}
		}
		clear_court_event_participation = yes
		# Finish up the chain if relevant.
		hold_court_queue_post_event_effect = yes
	}
}

# Your Byz spouse or child-in-law at court is accused of being arrogant and pretentious
scripted_trigger 2120_valid_byz_spouse_trigger = {
	is_alive = yes
	culture = { has_cultural_pillar = heritage_byzantine }
	location = root.location
	is_available_ai_adult = yes
}
scripted_trigger 2120_valid_non_byz_complainer_trigger = {
	culture = {
		NOT = { has_cultural_pillar = heritage_byzantine }
	}
	is_of_major_or_minor_interest_trigger = { CHARACTER = root }
	is_available_ai_adult = yes
	location = root.location
}

ep3_emperor_yearly.2120 = {
	type = court_event
	title = ep3_emperor_yearly.2120.t
	desc = ep3_emperor_yearly.2120.desc
	theme = court
	court_scene = {
		button_position_character = scope:complainer
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:complainer = {
				group = petitioners_group
				animation = obsequious_bow
			}
		}
	}

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

	cooldown = { years = 15 }

	trigger = {
		has_ep3_dlc_trigger = yes
		# You and your capital are not Byz
		NOR = {
			culture = {
				has_cultural_pillar = heritage_byzantine
			}
			capital_county.culture = {
				has_cultural_pillar = heritage_byzantine
			}
		}
		# You have a spouse or in-law at court who is Byz
		OR = {
			any_spouse = {
				2120_valid_byz_spouse_trigger = yes
				save_temporary_scope_as = byz_char
			}
			any_child = {
				any_spouse = {
					2120_valid_byz_spouse_trigger = yes
					save_temporary_scope_as = byz_char
				}
			}
		}
		# Someone who could complain
		any_courtier = {
			2120_valid_non_byz_complainer_trigger = yes
			NOT = { is_close_family_of = scope:byz_char }
		}
	}

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

	immediate = {
		court_event_character_flag_effect = yes
		random_spouse = {
			limit = {
				2120_valid_byz_spouse_trigger = yes
			}
			save_scope_as = the_byz
		}
		if = {
			limit = {
				NOT = { exists = scope:the_byz }
			}
			random_child = {
				limit = {
					any_spouse = {
						2120_valid_byz_spouse_trigger = yes
					}
				}
				random_spouse = {
					limit = {
						2120_valid_byz_spouse_trigger = yes
					}
					save_scope_as = the_byz
				}
			}
		}
		random_courtier = {
			limit = {
				2120_valid_non_byz_complainer_trigger = yes
				NOT = { is_close_family_of = scope:the_byz }
			}
			save_scope_as = complainer
		}
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	# Option A: side with Byz
	option = {
		name = ep3_emperor_yearly.2120.a
		culture = {
			change_cultural_acceptance = {
				target = scope:the_byz.culture
				value = low_positive_culture_acceptance
				desc = cultural_acceptance_gain_hold_court_event_outcome
			}
		}
		scope:the_byz = {
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = 20
			}
		}
		stress_impact = {
			arrogant = medium_stress_impact_gain
			temperate = medium_stress_impact_gain
			content = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = arrogant
				add = -25
			}
			modifier = {
				has_trait = temperate
				add = -25
			}
			modifier = {
				has_trait = content
				add = -25
			}
		}
	}

	# Option B: side with courtier
	option = {
		name = ep3_emperor_yearly.2120.b
		culture = {
			change_cultural_acceptance = {
				target = scope:the_byz.culture
				value = miniscule_negative_culture_acceptance
				desc = cultural_acceptance_gain_hold_court_event_outcome
			}
		}
		add_character_modifier = {
			modifier = defender_of_values_modifier
			years = 15
		}
		scope:the_byz = {
			add_opinion = {
				target = root
				modifier = insult_opinion
				opinion = -20
			}
		}
		stress_impact = {
			humble = medium_stress_impact_gain
			ambitious = medium_stress_impact_gain
			fickle = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = humble
				add = -25
			}
			modifier = {
				has_trait = ambitious
				add = -25
			}
			modifier = {
				has_trait = fickle
				add = -25
			}
		}
	}

	# Option C: opt out
	option = {
		name = ep3_emperor_yearly.2120.c
		stress_impact = {
			diligent = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
			modifier = {
				has_trait = diligent
				add = -25
			}
		}
	}

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

#A prisoner (house arrest) is allowed into the court to plead for freedom
ep3_emperor_yearly.2130 = {
	type = court_event
	title = ep3_emperor_yearly.2130.t
	desc = ep3_emperor_yearly.2130.desc
	theme = court
	court_scene = {
		button_position_character = scope:prisoner
		court_event_force_open = yes
		show_timeout_info = no
		should_pause_time = yes
		roles = {
			scope:prisoner = {
				group = petitioners_group
				animation = obsequious_bow
			}
		}
	}

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

	cooldown = { years = 10 }

	trigger = {
		government_allows = administrative
		top_liege = this
		any_prisoner = {
			is_in_prison_type = house_arrest
			is_ai = yes
			age >= 14
		}
	}

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

	immediate = {
		court_event_character_flag_effect = yes
		random_prisoner = {
			limit = {
				is_in_prison_type = house_arrest
				is_ai = yes
				age >= 14
			}
			save_scope_as = prisoner
		}
		scope:prisoner = { court_event_character_flag_effect = yes }
		# Trigger next event in chain.
		hold_court_queue_next_event_effect = yes
	}

	# Option A: Pardon
	option = {
		name = ep3_emperor_yearly.2130.a
		scope:prisoner = { release_from_prison = yes }
		consume_all_criminal_reasons_effect = {
			LIEGE = root
			CRIMINAL = scope:prisoner
		}
		if = {
			limit = {
				can_add_hook = {
					target = scope:prisoner
					type = favor_hook
				}
			}
			add_hook = {
				target = scope:prisoner
				type = favor_hook
			}
		}
		change_influence = minor_influence_gain
		stress_impact = {
			forgiving = major_stress_impact_loss
			compassionate = major_stress_impact_loss
			just = medium_stress_impact_loss
			vengeful = massive_stress_impact_gain
			callous = medium_stress_impact_gain
			sadistic = medium_stress_impact_gain
			ambitious = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_vengefulness = -1
			}
		}
	}

	# Option B: Require support
	option = {
		name = ep3_emperor_yearly.2130.b
		trigger = {
			scope:prisoner = { 
				government_allows = administrative
				is_vassal_or_below_of = root
				is_landed_or_landless_administrative = yes
			}
		}
		scope:prisoner = {
			release_from_prison = yes
			change_influence = major_influence_loss
		}
		change_influence = major_influence_gain
		stress_impact = {
			honest = medium_stress_impact_gain
			forgiving = medium_stress_impact_gain
			compassionate = major_stress_impact_gain
			content = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 0.5
				ai_greed = 0.5
			}
		}
	}

	# Option C: work for me
	option = {
		name = ep3_emperor_yearly.2130.c
		trigger = {
			scope:prisoner = { 
				NOR = {
					is_vassal_or_below_of = root
					is_landed_or_landless_administrative = yes
					is_landed = yes
				}
			}
		}
		scope:prisoner = { release_from_prison = yes }
		hidden_effect = { add_courtier = scope:prisoner }
		custom_tooltip = {
			text = ep3_emperor_yearly.2130.c.tt
			add_character_flag = ep3_2130_ex_prisoner
		}
		stress_impact = {
			honest = major_stress_impact_gain
			compassionate = major_stress_impact_gain
			forgiving = medium_stress_impact_gain
			content = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_vengefulness = 1
			}
		}
	}

	# Option D: ask for troops
	option = {
		name = ep3_emperor_yearly.2130.d
		trigger = {
			scope:prisoner = {
				is_landed = yes
				NOT = { is_vassal_or_below_of = root }
			}
		}
		scope:prisoner = {
			release_from_prison = yes
			add_character_modifier = {
				modifier = ep3_mercenaries_abroad_modifier
				years = 10
			}
		}
		add_character_modifier = {
			modifier = ep3_mercenaries_from_abroad_modifier
			years = 10
		}
		stress_impact = {
			craven = medium_stress_impact_gain
			honest = medium_stress_impact_gain
			content = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 0.5
			}
		}
	}

	# Option E: Ignore
	option = {
		name = ep3_emperor_yearly.2130.e
		add_prestige = minor_prestige_gain
		stress_impact = {
			base = minor_stress_impact_gain
		}
		ai_chance = {
			base = 75
			modifier = {
				has_trait = vengeful
				add = 25
			}
			modifier = {
				has_trait = deceitful
				add = -25
			}
			modifier = {
				has_trait = forgiving
				add = -25
			}
		}
	}

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

# Plunder the tombs of previous emperors if in debt

ep3_emperor_yearly.2140 = {
	type = character_event
	title = ep3_emperor_yearly.2140.t
	desc = ep3_emperor_yearly.2140.desc
	theme = emperor
	override_background = { reference = ep3_constantinople }
	left_portrait = {
		character = root
		animation = personality_greedy
	}
	cooldown = { years = 50 }

	trigger = {
		valid_for_byz_emperor_content_trigger = yes
		gold < 0
	}

	weight_multiplier = {
		base = 1
		modifier = {
			gold < -150
			add = 1
		}
		modifier = {
			gold < -300
			add = 2
		}
		modifier = {
			factor = 0.5
			has_trait = zealous
		}
	}

	# Option A: Let's do it
	option = {
		name = ep3_emperor_yearly.2140.a
		add_treasury_or_gold = major_treasury_or_gold_value
		add_character_modifier = {
			modifier = ep3_grave_robber_modifier
			years = 20
		}
		root.capital_province = {
			add_province_modifier = {
				modifier = ep3_imperial_tombs_violated_province_modifier
				years = 10
			}
		}
		stress_impact = {
			zealous = massive_stress_impact_gain
			gregarious = medium_stress_impact_gain
			content = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 1
			}
		}
	}

	# Option B: Not worth it
	option = {
		name = ep3_emperor_yearly.2140.b
		add_piety = minor_piety_gain
		change_influence = minor_influence_gain
		stress_impact = {
			greedy = massive_stress_impact_gain
			diligent = medium_stress_impact_gain
			cynical = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = 1
			}
		}
	}
}

# Governor/Emperor: You are told about a new Stylite "saint" in your area

ep3_emperor_yearly.2150 = {
	type = character_event
	title = ep3_emperor_yearly.2150.t
	desc = {
		desc = ep3_emperor_yearly.2150.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:saint = { has_nickname = nick_the_stylite }
				}
				desc = ep3_emperor_yearly.2150.desc.stylite
			}
			triggered_desc = {
				trigger = {
					scope:saint = { has_nickname = nick_the_grazer }
				}
				desc = ep3_emperor_yearly.2150.desc.grazer
			}
			triggered_desc = {
				trigger = {
					scope:saint = { has_nickname = nick_the_iron_wearer }
				}
				desc = ep3_emperor_yearly.2150.desc.iron
			}	
		}
		desc = ep3_emperor_yearly.2150.desc.end
	}
	theme = administrative
	left_portrait = {
		character = root
		animation = thinking
	}
	lower_right_portrait = scope:saint
	cooldown = { years = 25 }

	trigger = {
		OR = {
			valid_for_byz_governor_content_trigger = yes
			valid_for_byz_emperor_content_trigger = yes
		}
		any_sub_realm_county = {
			faith = faith:orthodox
		}
	}

	weight_multiplier = {
		base = 1
		#More common in early dates
		modifier = {
			add = 1
			current_date < 1000.1.1
		}
		modifier = {
			add = 1
			has_trait = zealous
		}
		modifier = {
			add = 1
			has_trait = cynical
		}
		modifier = {
			is_ai = yes
			factor = 0.1
		}
	}

	immediate = {
		if = {
			limit = {
				capital_province.county.faith = faith:orthodox
			}
			capital_province = {
				save_scope_as = capital
			}
		}
		else = {
			random_sub_realm_county = {
				limit = {
					faith = faith:orthodox
				}
				random_province = {
					save_scope_as = capital
				}
			}
		}
		random_pool_character = {
			province = root.location
			limit = {
				faith = faith:orthodox
				can_be_clergy_due_to_gender_trigger = yes
				is_available_ai_adult = yes
				OR = {
					has_trait = eccentric
					has_trait = zealous
					has_trait = saint
					has_trait = lifestyle_mystic
					has_nickname = nick_the_stylite
					has_nickname = nick_the_grazer
					has_nickname = nick_the_iron_wearer
				}
				learning >= 16
			}
			save_scope_as = saint
		}
		if = {
			limit = {
				NOT = { exists = scope:saint }
			}
			create_character = {
				template = stylite_saint_character
				faith = faith:orthodox
				culture = scope:capital.county.culture
				location = root.location
				save_scope_as = saint
			}
		}
		hidden_effect = {
			if = {
				limit = {
					scope:saint = {
						NOT = {
							has_trait = eccentric
						}
					}
				}
				scope:saint = {
					add_trait = eccentric
				}
			}
			scope:saint = {
				add_trait = inappetetic
				add_trait = wounded_1
				change_current_weight = -50
				random_list = {
					# is a holy man
					50 = {
						add_character_flag = real_holy_man
						modifier = {
							has_trait = zealous
							add = 20
						}
						modifier = {
							has_trait = education_learning_1
							add = 5
						}
						modifier = {
							has_trait = education_learning_2
							add = 10
						}
						modifier = {
							has_trait = education_learning_3
							add = 15
						}
						modifier = {
							has_trait = education_learning_4
							add = 20
						}
						modifier = {
							has_trait = saint
							add = 25
						}
						modifier = {
							has_trait = lifestyle_mystic
							add = 15
						}
						modifier = {
							has_trait = honest
							add = 15
						}
						modifier = {
							has_trait = scholar
							add = 10
						}
						modifier = {
							has_trait = theologian
							add = 10
						}
						modifier = {
							has_trait = chaste
							add = 10
						}
						modifier = {
							has_trait = temperate
							add = 10
						}
						modifier = {
							has_trait = wrathful
							add = 15
						}
						modifier = {
							has_trait = arrogant
							add = 10
						}
						modifier = {
							has_trait = humble
							add = 10
						}
						modifier = {
							has_trait = arbitrary
							add = 15
						}
						modifier = {
							has_trait = callous
							add = 10
						}
						modifier = {
							has_trait = reclusive
							add = 25
						}
					}
					# is a crook
					50 = {
						add_character_flag = is_a_crook
						modifier = {
							has_trait = education_intrigue_1
							add = 5
						}
						modifier = {
							has_trait = education_intrigue_2
							add = 10
						}
						modifier = {
							has_trait = education_intrigue_3
							add = 15
						}
						modifier = {
							has_trait = education_intrigue_4
							add = 20
						}
						modifier = {
							has_trait = whole_of_body
							add = 15
						}
						modifier = {
							has_trait = deceitful
							add = 20
						}
						modifier = {
							has_trait = lifestyle_reveler
							add = 30
						}
						modifier = {
							has_trait = lustful
							add = 10
						}
						modifier = {
							has_trait = greedy
							add = 10
						}
						modifier = {
							has_trait = patient
							add = 15
						}
						modifier = {
							has_trait = brave
							add = 15
						}
						modifier = {
							has_trait = paranoid
							add = 10
						}
						modifier = {
							has_trait = compassionate
							add = 15
						}
					}
				}
				random_list = {
					33 = {
						give_nickname = nick_the_stylite
					}
					33 = {
						give_nickname = nick_the_grazer
					}
					33 = {
						give_nickname = nick_the_iron_wearer
					}
				}
			}
		}
	}

	#Option A: all hail the saint!
	option = {
		name = ep3_emperor_yearly.2150.a
		flavor = ep3_emperor_yearly.2150.a.tt
		pay_treasury_or_gold = {
			target = scope:saint
			value = minor_treasury_or_gold_value
		}
		if = {
			limit = {
				can_employ_court_position_type = cave_hermit_court_position
				scope:saint = { can_be_employed_as = cave_hermit_court_position } 
			}
			court_position_grant_effect = {
				EMPLOYER = root
				POS = cave_hermit
				CANDIDATE = scope:saint
			}
		}
		scope:capital.county = {
			change_county_control = major_county_control_gain
		}
		add_piety = minor_piety_gain
		stress_impact = {
			cynical = major_stress_impact_gain
			comfort_eater = medium_stress_impact_gain
			just = minor_stress_impact_gain
			greedy = minor_stress_impact_gain
			gluttonous = minor_stress_impact_gain
			craven = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = 1
				ai_energy = -0.5
			}
			modifier = {
				treasury_or_gold < tiny_treasury_or_gold_value
				factor = 0
			}
			modifier = {
				has_trait = cynical
				factor = 0
			}
		}
	}

	#Option B: put him to the test
	option = {
		name = ep3_emperor_yearly.2150.b
		duel = {
			skills = { intrigue learning }
			target = scope:saint
			# you find the truth
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = ep3_emperor_yearly.2150.b.tt.success
				show_as_tooltip = {
					if = {
						limit = {
							top_liege = this
						}
						change_influence = major_influence_gain
					}
					else = {
						add_character_flag = {
							flag = ep3_2150_found_truth
							years = 25
						}
						custom_tooltip = ep3_emperor_yearly.2150.b.tt
						change_influence = minor_influence_gain
					}
					random_list = {
						50 = {
							show_chance = no
							desc = ep3_emperor_yearly.2150.b.tt.holy
							scope:capital.county = {
								add_county_modifier = {
									modifier = land_of_holy_county_modifier
									years = 25
								}
							}
						}
						50 = {
							show_chance = no
							desc = ep3_emperor_yearly.2150.b.tt.crook
							scope:capital.county = {
								add_county_modifier = {
									modifier = no_crooks_county_modifier
									years = 25
								}
							}
						}
					}
				}
				hidden_effect = {
					send_interface_toast = {
						title = ep3_emperor_yearly.2150.b.tt.success
						left_icon = scope:saint
						type = event_generic_neutral
						if = {
							limit = {
								top_liege = this
							}
							change_influence = major_influence_gain
						}
						else = {
							add_character_flag = {
								flag = ep3_2150_found_truth
								years = 25
							}
							custom_tooltip = ep3_emperor_yearly.2150.b.tt
							change_influence = minor_influence_gain
						}
						if = {
							limit = {
								scope:saint = { has_character_flag = real_holy_man }
							}
							custom_tooltip = ep3_emperor_yearly.2150.b.tt.holy
							scope:capital.county = {
								add_county_modifier = {
									modifier = land_of_holy_county_modifier
									years = 25
								}
							}
						}
						else = {
							custom_tooltip = ep3_emperor_yearly.2150.b.tt.crook
							scope:capital.county = {
								add_county_modifier = {
									modifier = no_crooks_county_modifier
									years = 25
								}
							}
						}
					}
				}
			}
			# you have no idea
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = ep3_emperor_yearly.2150.b.tt.failure
				send_interface_toast = {
					title = ep3_emperor_yearly.2150.b.tt.failure
					left_icon = scope:saint
					type = event_generic_neutral
					custom_tooltip = ep3_emperor_yearly.2150.b.tt.continue
					change_influence = minor_influence_loss
				}
				scope:saint = { add_character_flag = follow_up_2150 }
				trigger_event = {
					id = ep3_emperor_yearly.2151
					years = 3
				}
			}
		}
		stress_impact = {
			lazy = major_stress_impact_gain
			arbitrary = major_stress_impact_gain
			fickle = medium_stress_impact_gain
			zealous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 1
				ai_energy = 0.5
			}
			modifier = {
				has_trait = lazy
				add = -75
			}
		}
	}

	#Option C: he's clearly a fake!
	option = {
		name = ep3_emperor_yearly.2150.c
		scope:capital.county = {
			change_county_control = minor_county_control_loss
		}
		if = {
			limit = {
				top_liege = this
			}
			change_influence = medium_influence_gain
		}
		else = {
			increase_governance_effect = { VALUE = 2 }
			change_influence = miniscule_influence_gain
		}
		stress_impact = {
			zealous = major_stress_impact_gain
			diligent = medium_stress_impact_gain
			just = minor_stress_impact_gain
			humble = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = -1
				ai_rationality = 0.5
			}
		}
	}

	after = {
		if = {
			limit = {
				scope:saint = {
					NOT = {
						has_character_flag = follow_up_2150
					}
				}
			}
			scope:saint = {
				remove_character_flag = real_holy_man
				remove_character_flag = is_a_crook
			}
			if = {
				limit = {
					is_ai = yes
					scope:saint = { has_any_court_position = no }
				}
				scope:saint = { silent_disappearance_effect = yes }
			}
		}
	}
}

ep3_emperor_yearly.2151 = {
	type = character_event
	title = ep3_emperor_yearly.2150.t
	desc = {
		desc = ep3_emperor_yearly.2151.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:saint = { has_character_flag = real_holy_man }
				}
				desc = ep3_emperor_yearly.2151.desc_saint
			}
			desc = ep3_emperor_yearly.2151.desc_crook
		}
	}
	theme = administrative
	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		character = scope:chaplain
		triggered_animation = {
			trigger = { OR = { religion = religion:eastern_orthodox_religion religion = religion:catholic_religion religion = religion:protestant_religion } }
			animation = scepter # anim uses crucifix scepter
		}
		animation = war_over_tie
	}
	lower_right_portrait = scope:saint

	trigger = {
		scope:saint = { is_alive = yes }
		OR = {
			valid_for_byz_governor_content_trigger = yes
			valid_for_byz_emperor_content_trigger = yes
		}
		any_sub_realm_county = {
			faith = faith:orthodox
			this = scope:capital.county
		}
		exists = cp:councillor_court_chaplain
	}

	on_trigger_fail = {
		if = {
			limit = {
				scope:saint = { is_alive = yes }
			}
			scope:saint = {
				remove_character_flag = real_holy_man
				remove_character_flag = is_a_crook
				remove_character_flag = follow_up_2150
			}
		}
	}

	immediate = {
		if = {
			limit = {
				scope:saint = { has_character_flag = real_holy_man }
			}
			scope:capital.county = {
				add_county_modifier = {
					modifier = ep3_persecuting_saints_county_modifier
					years = 5
				}
			}
		}
		else = {
			scope:capital.county = {
				add_county_modifier = {
					modifier = ep3_conmen_among_us_county_modifier
					years = 5
				}
			}
		}
		cp:councillor_court_chaplain = { save_scope_as = chaplain }
	}

	option = {
		name = ep3_emperor_yearly.2151.a
	}

	after = {
		scope:saint = {
			remove_character_flag = real_holy_man
			remove_character_flag = is_a_crook
			remove_character_flag = follow_up_2150
		}
		if = {
			limit = {
				is_ai = yes
			}
			scope:saint = { silent_disappearance_effect = yes }
		}
	}
}

# Governor: If you border with nomadic people, they keep moving people into your borders

scripted_trigger ep3_2160_valid_neighbor_trigger = {
	liege != root.liege
	OR = {
		government_has_flag = government_is_tribal
		culture = {
			OR = {
				has_cultural_tradition = tradition_horse_lords
				has_cultural_tradition = tradition_saharan_nomads
				has_cultural_tradition = tradition_desert_nomads
			}
		}
	}
	is_ai = yes
}

ep3_emperor_yearly.2160 = {
	type = character_event
	title = ep3_emperor_yearly.2160.t
	desc = ep3_emperor_yearly.2160.desc
	theme = war
	left_portrait = {
		character = root
		animation = eyeroll
	}
	lower_right_portrait = scope:nomad_neighbor
	cooldown = { years = 25 }

	trigger = {
		valid_for_byz_governor_content_trigger = yes
		any_neighboring_realm_same_rank_owner = {
			ep3_2160_valid_neighbor_trigger = yes
			any_sub_realm_county = {
				any_neighboring_county = {
					holder = root
				}
			}
		}
	}

	immediate = {
		random_neighboring_realm_same_rank_owner = {
			limit = {
				ep3_2160_valid_neighbor_trigger = yes
			}
			save_scope_as = nomad_neighbor
		}
		scope:nomad_neighbor = {
			random_sub_realm_county = {
				limit = {
					any_neighboring_county = {
						holder = root
					}
				}
				save_scope_as = nomad_county
			}
		}
		scope:nomad_county = {
			random_neighboring_county = {
				limit = {
					holder = root
				}
				save_scope_as = our_county
			}
		}
	}

	# Option A: welcome them
	option = {
		name = ep3_emperor_yearly.2160.a
		flavor = ep3_emperor_yearly.2160.a.tt
		scope:our_county = {
			add_county_modifier = {
				modifier = ep3_settling_nomads_county_modifier
				years = 25
			}
		}
		culture = {
			change_cultural_acceptance = {
				target = scope:nomad_neighbor.culture
				value = minor_cultural_acceptance_gain
				desc = cultural_acceptance_gain_hold_court_event_outcome
			}
		}
		stress_impact = {
			paranoid = medium_stress_impact_gain
			callous = minor_stress_impact_gain
			arbitrary = minor_stress_impact_gain
			impatient = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = paranoid
				add = -100
			}
			modifier = {
				has_trait = callous
				add = -25
			}
			modifier = {
				has_trait = gregarious
				add = 25
			}
			ai_value_modifier = {
				ai_compassion = 0.5
			}
		}
	}

	# Option B: diplomatic escalation
	option = {
		name = ep3_emperor_yearly.2160.b
		flavor = ep3_emperor_yearly.2160.b.flavor
		duel = {
			skill = diplomacy
			target = scope:nomad_neighbor
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = ep3_emperor_yearly.2160.b.tt.success
				send_interface_toast = {
					title = ep3_emperor_yearly.2160.b.success
					left_icon = scope:nomad_neighbor
					type = event_generic_neutral
					add_pressed_claim = scope:nomad_county
					add_character_flag = {
						flag = ep3_2160_success
						years = 25
					}
					custom_tooltip = ep3_emperor_yearly.2160.b.tt
				}
			}
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = ep3_emperor_yearly.2160.b.tt.failure
				send_interface_toast = {
					title = ep3_emperor_yearly.2160.b.failure
					left_icon = scope:nomad_neighbor
					type = event_generic_neutral
					scope:nomad_neighbor = { add_pressed_claim = scope:our_county }
					add_character_flag = {
						flag = ep3_2160_failure
						years = 25
					}
					custom_tooltip = ep3_emperor_yearly.2160.b.tt2
				}
			}
		}
		stress_impact = {
			compassionate = medium_stress_impact_gain
			gregarious = medium_stress_impact_gain
			shy = medium_stress_impact_gain
			content = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 1
			}
		}
	}
}

# People are hiding from you, in your low-control province, in tunnels, in fairy chimneys, and within mountains

ep3_emperor_yearly.2170 = {
	type = character_event
	title = ep3_emperor_yearly.2170.t
	desc = ep3_emperor_yearly.2170.desc
	theme = stewardship
	left_portrait = {
		character = root
		animation = thinking
	}
	cooldown = { years = 25 }

	trigger = {
		OR ={
			valid_for_byz_governor_content_trigger = yes
			has_tgp_dlc_trigger = yes
		}
		
		any_sub_realm_county = {
			OR = {
				any_county_province = { has_building = fairy_chimneys }
				AND = {
					county_control <= 50
					county_has_province_with_terrain = {
						terrain = mountains
						terrain = hills
						terrain = forest
						terrain = jungle
						terrain = desert_mountains
						terrain = steppe
						terrain = desert
					}
				}
			}
			NOR = {
				has_county_modifier = ep3_tunnels_encouraged_county_modifier
				has_county_modifier = ep3_population_control_county_modifier
			}
		}
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		random_sub_realm_county = {
			limit = {
				NOR = {
					has_county_modifier = ep3_tunnels_encouraged_county_modifier
					has_county_modifier = ep3_population_control_county_modifier
				}
				any_county_province = { has_building = fairy_chimneys }
			}
			save_scope_as = our_county
		}
		if = {
			limit = {
				NOT = { exists = scope:our_county }
			}
			ordered_sub_realm_county = {
				limit = {
					NOR = {
						has_county_modifier = ep3_tunnels_encouraged_county_modifier
						has_county_modifier = ep3_population_control_county_modifier
					}
					county_has_province_with_terrain = {
						terrain = mountains
						terrain = hills
						terrain = forest
						terrain = jungle
						terrain = desert_mountains
						terrain = steppe
						terrain = desert
					}
				}
				order_by = {
					value = county_control
					multiply = -1
				}
				save_scope_as = our_county
			}
		}
	}

	# Option A: encourage it as defense
	option = {
		name = ep3_emperor_yearly.2170.a
		scope:our_county = {
			add_county_modifier = {
				modifier = ep3_tunnels_encouraged_county_modifier
				years = 50
			}
		}
		change_influence = major_influence_gain
		stress_impact = {
			greedy = major_stress_impact_gain
			paranoid = medium_stress_impact_gain
			honest = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 0.5
			}
			modifier = {
				has_trait = paranoid
				add = -75
			}
			modifier = {
				has_trait = greedy
				factor = 0
			}
		}
	}

	# Option B: discourage it for taxation
	option = {
		name = ep3_emperor_yearly.2170.b
		scope:our_county = {
			add_county_modifier = {
				modifier = ep3_population_control_county_modifier
				years = 50
			}
		}
		add_character_flag = {
			flag = ep3_2170_success
			years = 25
		}
		custom_tooltip = ep3_emperor_yearly.2160.b.tt
		stress_impact = {
			generous = medium_stress_impact_gain
			deceitful = medium_stress_impact_gain
			trusting = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 0.5
			}
		}
	}
}

# Traveling pilgrims come to an estate - response from the estate owner

ep3_emperor_yearly.2180 = {
	type = character_event
	title = ep3_emperor_yearly.2180.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					location = top_liege.capital_province
				}
				desc = ep3_emperor_yearly.2180.desc_capital
			}
			desc = ep3_emperor_yearly.2180.desc
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					top_liege = scope:event_host.top_liege
				}
				desc = ep3_emperor_yearly.2180.desc_fellow
			}
			desc = ep3_emperor_yearly.2180.desc_foreigner
		}
	}
	theme = travel
	left_portrait = {
		character = root
		animation = worry
	}
	lower_right_portrait = scope:event_host
	cooldown = { years = 10 }

	trigger = {
		is_available_travelling = yes
		is_location_valid_for_travel_event_on_land = yes
		involved_activity ?= {
			has_activity_type = activity_pilgrimage
		}
		location = {
			any_province_domicile = {
				is_domicile_type = estate
				owner ?= {
					dynasty != root.dynasty
					is_available = yes
				}
			}
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			location = {
				any_province_domicile = {
					is_domicile_type = estate
					owner.religion = root.religion
				}
			}
			add = 0.5
		}
		modifier = {
			location = {
				any_province_domicile = {
					is_domicile_type = estate
					owner.faith = root.faith
				}
			}
			add = 0.5
		}
	}

	immediate = {
		location = {
			random_province_domicile = {
				limit = {
					is_domicile_type = estate
					owner ?= {
						dynasty != root.dynasty
						is_available = yes
						faith = root.faith
					}
				}
				alternative_limit = {
					is_domicile_type = estate
					owner ?= {
						dynasty != root.dynasty
						is_available = yes
						religion = root.religion
					}
				}
				alternative_limit = {
					is_domicile_type = estate
					owner ?= {
						dynasty != root.dynasty
						is_available = yes
					}
				}
				owner ?= {
					save_scope_as = event_host
				}
			}
			save_scope_as = location
		}
		#for the response event
		root = { save_scope_as = pilgrim }
	}

	# Option A: let's approach the estate
	option = {
		name = ep3_emperor_yearly.2180.a
		flavor = ep3_emperor_yearly.2180.a.tt
		current_travel_plan = {
			delay_travel_plan = {
				days = 7
			}
		}
		scope:event_host = {
			trigger_event = {
				id = ep3_emperor_yearly.2181
				days = 1
			}
		}
		stress_impact = {
			shy = medium_stress_impact_gain
			zealous = medium_stress_impact_gain
			reclusive = major_stress_impact_gain
			impatient = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_sociability = 1
			}
		}
	}

	# Option B: better make hurry instead
	option = {
		name = ep3_emperor_yearly.2180.b
		add_piety = minor_piety_gain
		stress_impact = {
			craven = minor_stress_impact_gain
			gregarious = medium_stress_impact_gain
			patient = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = 1
			}
		}
	}
}

ep3_emperor_yearly.2181 = {
	type = character_event
	title = ep3_emperor_yearly.2180.t
	desc = {
		desc = ep3_emperor_yearly.2181.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					top_liege = scope:pilgrim.top_liege
				}
				desc = ep3_emperor_yearly.2181.desc_fellow
			}
			desc = ep3_emperor_yearly.2181.desc_foreigner
		}
	}
	theme = stewardship
	left_portrait = {
		character = root
		animation = chaplain
	}
	right_portrait = {
		character = scope:pilgrim
		animation = beg
	}

	trigger = {
		scope:pilgrim = { is_alive = yes }
	}

	immediate = {
		top_liege = { save_scope_as = liege }
	}

	# Option A: give advice on the area
	option = {
		name = ep3_emperor_yearly.2181.a
		flavor = ep3_emperor_yearly.2181.a_flavor
		scope:pilgrim = {
			send_interface_toast = {
				type = event_generic_good_text
				title = ep3_emperor_yearly.2181.a.tt
				left_icon = root
				current_travel_plan = {
					add_travel_plan_modifier = {
						modifier = ep3_lay_of_the_land_modifier
					}
				}
			}
		}
		add_character_modifier = {
			modifier = ep3_friendly_host_modifier
			years = 10
		}
		stress_impact = {
			shy = minor_stress_impact_gain
			paranoid = minor_stress_impact_gain
			cynical = minor_stress_impact_gain
			reclusive = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_sociability = 1
			}
		}
	}

	# Option B: give guides and guards
	option = {
		name = ep3_emperor_yearly.2181.b
		flavor = ep3_emperor_yearly.2181.b_flavor
		scope:pilgrim = {
			send_interface_toast = {
				type = event_generic_good_text
				title = ep3_emperor_yearly.2181.b.tt
				left_icon = root
				current_travel_plan = {
					add_travel_plan_modifier = {
						modifier = ep3_guides_and_guards_modifier
					}
				}
			}
		}
		change_influence = minor_influence_loss
		if = {
			limit = {
				faith = scope:pilgrim.faith
			}
			add_character_modifier = {
				modifier = ep3_pilgrim_protector_same_modifier
				years = 10
			}
		}
		else = {
			add_character_modifier = {
				modifier = ep3_pilgrim_protector_other_modifier
				years = 10
			}
		}
		stress_impact = {
			cynical = medium_stress_impact_gain
			greedy = minor_stress_impact_gain
			paranoid = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = -0.5
				ai_zeal = 0.5
			}
			modifier = {
				scope:pilgrim.faith = root.faith
				add = 150
			}
		}
	}

	# Option C: this is not a hotel - opt out
	option = {
		name = ep3_emperor_yearly.2181.c
		scope:pilgrim = {
			send_interface_toast = {
				type = event_generic_bad_text
				title = ep3_emperor_yearly.2181.c.tt
				left_icon = root

				pay_short_term_gold = {
					target = root
					gold = tiny_gold_value
				}
			}
		}
		stress_impact = {
			generous = medium_stress_impact_gain
			gregarious = medium_stress_impact_gain
			zealous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_sociability = -1
				ai_zeal = -1
			}
		}
	}
}

# Emperor/Governor: Landowners have been hoarding grain to resell it during food shortages

scripted_trigger ep3_2190_valid_domicile_owner_trigger = {
	NOR = {
		dynasty = root.dynasty
		this = root
	}
	is_available_ai_adult = yes
	opinion = {
		target = root
		value <= 20
	}
}

ep3_emperor_yearly.2190 = {
	type = character_event
	title = ep3_emperor_yearly.2190.t
	desc = ep3_emperor_yearly.2190.desc
	theme = administrative
	override_background = { reference = ep3_relaxing_room }
	left_portrait = {
		character = root
		animation = anger
	}
	right_portrait = {
		character = scope:landowner
		animation = eyeroll
	}
	cooldown = { years = 15 }

	trigger = {
		OR = {
			valid_for_byz_governor_content_trigger = yes
			valid_for_byz_emperor_content_trigger = yes
		}
		capital_province = {
			any_province_domicile = {
				is_domicile_type = estate
				owner ?= {
					ep3_2190_valid_domicile_owner_trigger = yes
				}
			}
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			capital_province = {
				any_province_domicile = {
					is_domicile_type = estate
					owner ?= {
						ep3_2190_valid_domicile_owner_trigger = yes
						OR = {
							has_trait = greedy
							has_trait = deceitful
							has_trait = arbitrary
						}
					}
				}
			}
			add = 2
		}
		modifier = {
			capital_province = {
				any_province_domicile = {
					is_domicile_type = estate
					owner ?= {
						ep3_2190_valid_domicile_owner_trigger = yes
						OR = {
							has_trait = generous
							has_trait = humble
							has_trait = honest
							has_trait = just
						}
					}
				}
			}
			factor = 0
		}
	}

	immediate = {
		capital_province = {
			random_province_domicile = {
				limit = {
					is_domicile_type = estate
					owner ?= {
						ep3_2190_valid_domicile_owner_trigger = yes
					}
				}
				owner = {
					save_scope_as = landowner
				}
			}
			save_scope_as = capital
		}
		liege = { save_scope_as = liege }
		save_scope_as = root_scope
	}

	# Option A: Make an example
	option = {
		name = ep3_emperor_yearly.2190.a
		if = {
			limit = {
				top_liege = this
			}
			every_vassal = {
				limit = {
					OR = {
						has_vassal_stance = courtly
						has_vassal_stance = parochial
					}
					this != scope:landowner
				}
				custom = every_courtly_parochial_vassal
				add_opinion = {
					target = root
					modifier = targeting_nobility_opinion
				}
			}
		}
		else = {
			custom_tooltip = ep3_emperor_yearly.2150.b.tt
			add_character_flag = {
				flag = ep3_2190_honest
				years = 25
			}
			liege = {
				every_vassal = {
					limit = {
						OR = {
							has_vassal_stance = courtly
							has_vassal_stance = parochial
						}
						NOR = {
							this = scope:landowner
							this = root
						}
					}
					custom = every_courtly_parochial_fellow_vassal
					add_opinion = {
						target = root
						modifier = targeting_nobility_opinion
					}
				}
			}
		}
		capital_province.county = {
			add_county_modifier = {
				modifier = ep3_open_granary_county_modifier
				years = 15
			}
		}
		scope:landowner = {
			change_influence = medium_influence_loss
			remove_short_term_gold = medium_gold_value
			add_opinion = {
				target = root
				modifier = ruined_me_opinion
			}
		}
		stress_impact = {
			greedy = medium_stress_impact_gain
			content = medium_stress_impact_gain
			arbitrary = medium_stress_impact_gain
			craven = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = 0.5
				ai_sociability = -0.5
			}
			modifier = {
				has_trait = brave
				add = 25
			}
			modifier = {
				has_trait = just
				add = 25
			}
			modifier = {
				has_trait = craven
				add = -75
			}
			modifier = {
				scope:landowner = {
					gold < medium_gold_value
				}
				factor = 0
			}
		}
	}

	# Option B: get bribed
	option = {
		name = ep3_emperor_yearly.2190.b
		scope:landowner = {
			pay_short_term_gold = {
				target = root
				gold = medium_gold_value
			}
			add_opinion = {
				target = root
				modifier = accepted_bribe_opinion
				opinion = 20
			}
		}
		change_influence = miniscule_influence_loss
		stress_impact = {
			honest = major_stress_impact_gain
			just = major_stress_impact_gain
			diligent = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = -1
				ai_greed = 0.5
			}
			modifier = {
				has_trait = honest
				factor = 0
			}
			modifier = {
				has_trait = just
				factor = 0
			}
			modifier = {
				has_trait = diligent
				add = -50
			}
			modifier = {
				scope:landowner = {
					gold < medium_gold_value
				}
				factor = 0
			}
		}
	}

	# Option C: wrist-slap - opt out
	option = {
		name = ep3_emperor_yearly.2190.c
		scope:landowner = {
			add_opinion = {
				target = root
				modifier = off_the_hook_opinion
				opinion = 5
			}
		}
		stress_impact = {
			just = minor_stress_impact_gain
			honest = minor_stress_impact_gain
			greedy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_energy = -0.5
			}
		}
	}
}

# A governor who doesn't like the emperor can seize the tax gold about to go to the emperor
ep3_emperor_yearly.2200 = {
	type = character_event
	title = ep3_emperor_yearly.2200.t
	
	desc = {
		first_valid = {
			#You have a ceremonial monarch
			triggered_desc = {
				trigger = {
					tgp_realm_has_ceremonial_liege_trigger = yes
				}
				desc = ep3_emperor_yearly.2200.desc.c_monarch
			}
			#Not ceremonial monarch 
			desc = ep3_emperor_yearly.2200.desc
		}
	}
	theme = stewardship
	override_background = relaxing_room
	left_portrait = {
		character = root
		animation = personality_greedy
	}
	lower_right_portrait = scope:liege
	lower_left_portrait = scope:ceremonial_monarch
	cooldown = { years = 10 }

	trigger = {
		is_governor = yes
		NOT = { is_at_war_with = liege }
		OR = {
			opinion = {
				target = liege
				value < 0
			}
			has_relation_potential_rival = liege
			has_relation_rival = liege
			house_has_feud_relation_with_trigger = { TARGET = liege }
			liege = { house_has_feud_relation_with_trigger ={ TARGET = root } }
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			valid_for_byz_governor_content_trigger = yes
			add = 1
		}
	}

	immediate = {
		liege = { save_scope_as = liege }
		primary_title = { save_scope_as = governorship }
		liege.capital_county = { save_scope_as = capital }
		if = {
			limit = {
				tgp_realm_has_ceremonial_liege_trigger = yes
			}
			top_liege.primary_title.var:administrative_ui_special_title.holder = {
				save_scope_as = ceremonial_monarch
			}	 
		}
	}

	# Option A: why not?
	option = {
		name = ep3_emperor_yearly.2200.a
		add_gold = major_gold_value
		add_character_flag = {
			flag = ep3_embezzling_governor
			years = 10
		}
		custom_tooltip = ep3_emperor_yearly.2160.b.tt2
		increase_governance_effect = { VALUE = -4 }
		if = {
			limit = {
				NOT = { has_trait = disloyal }
			}
			random = {
				chance = 35
				send_interface_toast = {
					title = ep3_emperor_yearly.2200.a.tt
					left_icon = root
					add_trait_force_tooltip = disloyal
				}
			}
		}
		if = {
			limit = {
				any_scheme = {
					type = depose
					scheme_target_character = scope:liege
				}
			}
			random_scheme = {
				type = depose 
				limit = {
					scheme_target_character = scope:liege
				}
				add_scheme_modifier = {
					type = scheme_grand_ambitions_embezzling_modifier
				}
			}
		}
		stress_impact = {
			honest = major_stress_impact_gain
			just = major_stress_impact_gain
			loyal = major_stress_impact_gain
			diligent = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 0.5
			}
		}
	}

	# Option B: never!
	option = {
		name = ep3_emperor_yearly.2200.b
		if = {
			limit = {
				NOT = { has_trait = loyal }
			}
			random = {
				chance = 35
				send_interface_toast = {
					title = ep3_emperor_yearly.2200.b.tt
					left_icon = root
					add_trait_force_tooltip = loyal
				}
			}
		}
		stress_impact = {
			deceitful = minor_stress_impact_gain
			greedy = minor_stress_impact_gain
			disloyal = minor_stress_impact_gain
			arbitrary = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 0.5
			}
		}
	}
}

# Make up a prophecy to present to the emperor to support your candidacy to a certain position
ep3_emperor_yearly.2210 = {
	type = character_event
	title = ep3_emperor_yearly.2210.t
	desc = {
		desc = ep3_emperor_yearly.2210.desc
		triggered_desc = {
			trigger = {
				NOR = {
					has_trait = zealous
					has_trait = loyal
				}
				liege = {
					OR = {
						has_trait = eccentric
						has_trait = zealous
						has_trait = trusting
						has_character_modifier = bp1_superstition_modifier
					}
				}
			}
			desc = ep3_emperor_yearly.2210.desc_believe
		}
		triggered_desc = {
			trigger = {
				faith.religion = { is_in_family = rf_abrahamic }
			}
			desc = ep3_emperor_yearly.2210.desc_jacob
		}
	}
	theme = realm
	override_background = { reference = estate }
	left_portrait = {
		character = root
		animation = schadenfreude
	}
	cooldown = { years = 25 }

	trigger = {
		has_ep3_dlc_trigger = yes
		is_available_adult = yes
		liege = { is_available_adult = yes }
		# candidate to a governorship (or the empire)
		any_heir_title = {
			tier > tier_county
			holder ?= {
				government_allows = administrative
				has_realm_law_flag = appointment_type_succession
			}
		}
		is_landed = no
	}

	weight_multiplier = {
		base = 1
		modifier = {
			has_trait = deceitful
			add = 0.5
		}
		modifier = {
			has_trait = eccentric
			add = 0.5
		}
		modifier = {
			has_trait = zealous
			add = 0.5
		}
		modifier = {
			liege = { has_character_modifier = bp1_superstition_modifier }
			add = 0.5
		}
		modifier = {
			liege = {
				OR = {
					has_trait = zealous
					has_trait = eccentric
					has_trait = trusting
				}
			}
			add = 0.5
		}
	}

	immediate = {
		random_heir_title = {
			limit = {
				holder ?= {
					government_allows = administrative
					has_realm_law_flag = appointment_type_succession
				}
				tier > tier_county
			}
			save_scope_as = potential_title
		}
		liege = { save_scope_as = liege }
		# For the responding event
		root = { save_scope_as = vassal }
	}

	#Option A: yes
	option = {
		name = ep3_emperor_yearly.2210.a
		change_influence = minor_influence_loss
		if = {
			limit = {
				scope:liege = { is_ai = no }
			}
			custom_tooltip = ep3_emperor_yearly.2210.a.tt
			scope:liege = {
				trigger_event = {
					id = ep3_emperor_yearly.2211
					days = 1
				}
			}
		}
		else = {
			duel = {
				skills = { intrigue learning }
				target = scope:liege
				40 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = 3.5
						min = -49
					}
					modifier = {
						scope:liege = { has_trait = eccentric }
						add = 20
					}
					modifier = {
						scope:liege = { has_trait = zealous }
						add = 20
					}
					modifier = {
						scope:liege = { has_trait = trusting }
						add = 20
					}
					modifier = {
						scope:liege = { has_character_modifier = bp1_superstition_modifier }
						add = 30
					}
					desc = ep3_emperor_yearly.2210.a.success
					send_interface_toast = {
						title = ep3_emperor_yearly.2210.a.success.tt
						left_icon = scope:liege
						scope:potential_title = {
							change_appointment_investment = {
								target = root
								value = appointment_score_major_value
							}
						}
					}
				}
				60 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = -3.5
						min = -49
					}
					modifier = {
						has_trait = honest
						add = 10
					}
					modifier = {
						scope:liege = { has_trait = cynical }
						add = 20
					}
					modifier = {
						scope:liege.faith = { this != root.faith }
						add = 15
					}
					desc = ep3_emperor_yearly.2210.a.failure
					send_interface_toast = {
						title = ep3_emperor_yearly.2210.a.failure.tt
						left_icon = scope:liege
						change_influence = minor_influence_loss
					}
				}
			}
		}
		stress_impact = {
			honest = medium_stress_impact_gain
			cynical = minor_stress_impact_gain
			loyal = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = deceitful
				add = 50
			}
			modifier = {
				liege = { has_trait = eccentric }
				add = 75
			}
			modifier = {
				liege = { has_trait = zealous }
				add = 75
			}
			modifier = {
				liege = { has_character_modifier = bp1_superstition_modifier }
				add = 100
			}
		}
	}

	#Option B: no
	option = {
		name = ep3_emperor_yearly.2210.b
		change_influence = miniscule_influence_gain
		stress_impact = {
			deceitful = medium_stress_impact_gain
			arbitrary = minor_stress_impact_gain
			eccentric = minor_stress_impact_gain
		}
		ai_chance = {
			base = 75
			ai_value_modifier = {
				ai_honor = 0.5
			}
		}
	}
}

ep3_emperor_yearly.2211 = {
	type = character_event
	title = ep3_emperor_yearly.2210.t
	desc = ep3_emperor_yearly.2211.desc
	theme = vassal
	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		character = scope:vassal
		animation = debating
	}

	immediate = {
	}

	# Option A: super yes
	option = {
		name = ep3_emperor_yearly.2211.a
		trigger = {
			OR = {
				has_trait = eccentric
				has_trait = zealous
				has_trait = trusting
				has_character_modifier = bp1_superstition_modifier
			}
		}
		scope:potential_title = {
			change_appointment_investment = {
				target = scope:vassal
				value = appointment_score_major_value
			}
		}
		add_piety = minor_piety_gain
		stress_impact = {
			base = massive_stress_impact_loss
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = eccentric
				add = 50
			}
			modifier = {
				has_trait = zealous
				add = 50
			}
			modifier = {
				has_trait = trusting
				add = 50
			}
			modifier = {
				has_character_modifier = bp1_superstition_modifier
				add = 50
			}
		}
	}

	# Option B: yes
	option = {
		name = ep3_emperor_yearly.2211.b
		trigger = {
			NOR = {
				has_trait = eccentric
				has_trait = zealous
				has_character_modifier = bp1_superstition_modifier
			}
		}
		scope:potential_title = {
			change_appointment_investment = {
				target = scope:vassal
				value = appointment_score_medium_value
			}
		}
		if = {
			limit = {
				can_add_hook = {
					target = scope:vassal
					type = favor_hook
				}
			}
			add_hook = {
				target = scope:vassal
				type = favor_hook
			}
		}
		else = {
			change_influence = minor_influence_gain
		}
		stress_impact = {
			cynical = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = 0.5
				ai_rationality = -0.5
			}
		}
	}

	# Option D: super no
	option = {
		name = ep3_emperor_yearly.2211.d
		trigger = {
			OR = {
				has_trait = cynical
				has_trait = callous
				has_trait = sadistic
				faith != scope:vassal.faith
			}
		}
		add_character_modifier = {
			modifier = ep3_unbeliever_in_signs_modifier
			years = 25
		}
		scope:vassal = {
			change_influence = major_influence_loss
		}
		stress_impact = {
			zealous = major_stress_impact_gain
		}
		ai_chance = {
			base = 150
			modifier = {
				has_trait = cynical
				add = 50
			}
			modifier = {
				has_trait = callous
				add = 50
			}
			modifier = {
				has_trait = sadistic
				add = 50
			}
			modifier = {
				faith != scope:vassal.faith
				add = 50
			}
		}
	}

	# Option C: no
	option = {
		name = ep3_emperor_yearly.2211.c
		scope:vassal = {
			change_influence = minor_influence_loss
		}
		change_influence = minor_influence_gain
		ai_chance = {
			base = 100
		}
	}
}

# Shepherds moved close to a monastery with wives and children

scripted_trigger ep3_2220_valid_county_trigger = {
	faith = { has_doctrine = tenet_monasticism }
	any_county_province = {
		OR = {
			has_holding_type = church_holding
			ep3_2220_famous_monastery_trigger = yes
		}
	}
	any_county_province = {
		NOR = { 
			has_holding_type = church_holding
			ep3_2220_famous_monastery_trigger = yes
		}
		OR = {
			has_building_or_higher = hill_farms_01
			has_building_or_higher = pastures_01
			has_building_or_higher = farm_estates_01
		}
	}
}

scripted_trigger ep3_2220_famous_monastery_trigger = {
	OR = {
		this = province:678 #Sumela
		this = province:3796 #Meteora
		this = province:3776 #Mt.Athos
		this = province:6032 #St.Catherine
		this = province:5764 #Jvari
		this = province:3729 #Hosios Loukas
	}
}

ep3_emperor_yearly.2220 = {
	type = character_event
	title = ep3_emperor_yearly.2220.t
	desc = ep3_emperor_yearly.2220.desc
	theme = vassal
	override_background = { reference = relaxing_room }
	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		character = scope:chaplain
		animation = throne_room_messenger_3
	}
	cooldown = { years = 20 }

	trigger = {
		valid_for_byz_governor_content_trigger = yes
		any_sub_realm_county = {
			ep3_2220_valid_county_trigger = yes
		}
		cp:councillor_court_chaplain ?= {
			is_available_ai_adult = yes
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			any_sub_realm_county = {
				ep3_2220_valid_county_trigger = yes
				any_county_province = {
					ep3_2220_famous_monastery_trigger = yes
				}
			}
			add = 2
		}
	}

	immediate = {
		random_sub_realm_county = {
			limit = {
				ep3_2220_valid_county_trigger = yes
				any_county_province = {
					ep3_2220_famous_monastery_trigger = yes
				}
			}
			alternative_limit = {
				ep3_2220_valid_county_trigger = yes
			}
			random_county_province = {
				limit = {
					ep3_2220_famous_monastery_trigger = yes
				}
				alternative_limit = {
					has_holding_type = church_holding
					OR = {
						has_building_or_higher = scriptorium_01
						has_building_or_higher = monastic_schools_01
					}
				}
				alternative_limit = {
					has_holding_type = church_holding
				}
				save_scope_as = monastery
			}
			random_county_province = {
				limit = {
					NOR = { 
						has_holding_type = church_holding
						ep3_2220_famous_monastery_trigger = yes
					}
					OR = {
						has_building_or_higher = hill_farms_01
						has_building_or_higher = pastures_01
						has_building_or_higher = farm_estates_01
					}
				}
				save_scope_as = shepherd_province
			}
			save_scope_as = interested_county
		}
		cp:councillor_court_chaplain = { save_scope_as = chaplain }
	}

	# Option A: Shepherds' side
	option = {
		name = ep3_emperor_yearly.2220.a
		scope:interested_county = {
			add_county_modifier = {
				modifier = ep3_roaming_shepherds_county_modifier
				years = 20
			}
		}
		add_prestige = medium_prestige_gain
		stress_impact = {
			zealous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = -0.5
			}
		}
	}

	# Option B: Monks' side
	option = {
		name = ep3_emperor_yearly.2220.b
		scope:interested_county = {
			add_county_modifier = {
				modifier = ep3_monastic_quiet_county_modifier
				years = 20
			}
		}
		change_influence = minor_influence_gain
		stress_impact = {
			cynical = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = 0.5
			}
		}
	}

	# Option C: it's their problem
	option = {
		name = ep3_emperor_yearly.2220.c
		change_influence = miniscule_influence_loss
		stress_impact = {
			base = minor_stress_impact_loss
			diligent = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50
			modifier = {
				has_trait = diligent
				add = -40
			}
		}
	}
}

# Public sentiment turns against foreign merchants and riots break out in their section of the city

ep3_emperor_yearly.2230 = {
	type = character_event
	title = ep3_emperor_yearly.2230.t
	desc = ep3_emperor_yearly.2230.desc
	theme = administrative
	left_portrait = {
		character = root
		animation = worry
	}
	cooldown = { years = 35 }

	trigger = {
		OR = {
			AND = {
				is_governor = yes
				government_has_flag = government_is_administrative
			}
			valid_for_byz_governor_content_trigger = yes
			valid_for_byz_emperor_content_trigger = yes
		}
		capital_county = { county_control <= 75 }
	}

	weight_multiplier = {
		base = 1
		modifier = {
			capital_county = {
				county_control <= 50
			}
			add = 1
		}
		modifier = {
			OR = {
				valid_for_byz_governor_content_trigger = yes
				valid_for_byz_emperor_content_trigger = yes
			}
			add = 1
		}
	}

	immediate = {
		capital_county = { save_scope_as = capital }
		capital_province.barony = { save_scope_as = city }
	}

	# Option A: repress
	option = {
		name = ep3_emperor_yearly.2230.a
		add_character_modifier = {
			modifier = ep3_law_and_order_modifier
			years = 20
		}
		if = {
			limit = {
				top_liege = this
			}
			change_influence = medium_influence_gain
		}
		else = {
			if = {
				limit = {
					has_trait = governor
				}
				add_trait_xp = {
					trait = governor
					value = small_lifestyle_random_xp_high
				}
			}
			else = {
				add_trait = governor
			}
		}
		stress_impact = {
			compassionate = major_stress_impact_gain
			forgiving = major_stress_impact_gain
			patient = medium_stress_impact_gain
			calm = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = 0.5
				ai_vengefulness = 0.5
			}
			modifier = {
				has_trait = compassionate
				add = -50
			}
			modifier = {
				has_trait = forgiving
				add = -50
			}
			modifier = {
				has_trait = patient
				add = -25
			}
		}
	}

	# Option B: exploit
	option = {
		name = ep3_emperor_yearly.2230.b
		add_gold = medium_gold_value
		change_influence = massive_influence_value
		scope:capital = {
			add_county_modifier = {
				modifier = ep3_rampaging_disorders_county_modifier
				years = 15
			}
		}
		stress_impact = {
			generous = major_stress_impact_gain
			just = major_stress_impact_gain
			honest = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain	
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 1
			}
			modifier = {
				has_trait = generous
				add = -50
			}
			modifier = {
				has_trait = just
				add = -50
			}
			modifier = {
				has_trait = honest
				add = -25
			}
			modifier = {
				has_trait = compassionate
				add = -25
			}
		}
	}

	# Option C: find a compromise
	option = {
		name = ep3_emperor_yearly.2230.c
		duel = {
			skill = diplomacy
			value = high_skill_rating
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = ep3_emperor_yearly.2230.c_success
				send_interface_toast = {
					title = ep3_emperor_yearly.2230.c_success.tt
					left_icon = root
					change_influence = medium_influence_gain
					add_character_modifier = {
						modifier = ep3_crowd_bender_modifier
						years = 20
					}
				}
			}
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = ep3_emperor_yearly.2230.c_failure
				send_interface_toast = {
					title = ep3_emperor_yearly.2230.c_failure.tt
					left_icon = root
					scope:capital = {
						add_county_modifier = {
							modifier = ep3_rampaging_disorders_county_modifier
							years = 15
						}
					}
				}
			}
		}
		stress_impact = {
			vengeful = major_stress_impact_gain
			callous = major_stress_impact_gain
			sadistic = major_stress_impact_gain
			patient = medium_stress_impact_gain
			wrathful = medium_stress_impact_gain
			arrogant = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 1
			}
			modifier = {
				has_trait = vengeful
				add = -50
			}
			modifier = {
				has_trait = callous
				add = -50
			}
			modifier = {
				has_trait = sadistic
				add = -50
			}
			modifier = {
				has_trait = patient
				add = -25
			}
			modifier = {
				has_trait = wrathful
				add = -25
			}
		}
	}
}

# An obnoxious "scholar" close to you keeps quoting the Classics out of place

scripted_trigger ep3_valid_greek_culture_trigger = {
	OR = {
		has_cultural_pillar = heritage_byzantine
		has_cultural_pillar = heritage_caucasian
		this = culture:greek
		any_parent_culture_or_above = { this = culture:greek }
	}
}

scripted_trigger ep3_2240_valid_courtier_trigger = {
	culture = { 
		OR = {
			has_graphical_east_asia_culture_group_trigger = yes
			ep3_valid_greek_culture_trigger = yes 
		}
	}

	OR = {
		knows_language = language_greek
		learning >= 10
		has_trait = education_learning_1
		has_trait = education_learning_2
		has_trait = education_learning_3
	}
	
	OR = {
		has_trait = arrogant
		has_trait = eccentric
		has_trait = gregarious
	}
	is_of_major_or_minor_interest_trigger = { CHARACTER = root } 
}

ep3_emperor_yearly.2240 = {
	type = character_event
	title = ep3_emperor_yearly.2240.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:the_scholar = { 
						culture = { has_graphical_east_asia_culture_group_trigger = yes }  
					}
				}
				desc = ep3_emperor_yearly.2240.desc_quote_confucius
			}
			random_valid = {
				desc = ep3_emperor_yearly.2240.desc_quote_a
				desc = ep3_emperor_yearly.2240.desc_quote_b
				desc = ep3_emperor_yearly.2240.desc_quote_c
				triggered_desc = {
					trigger = {
						scope:the_scholar = { knows_language = language_latin }
					}
					desc = ep3_emperor_yearly.2240.desc_quote_latin
				}
			}
		}
		desc = ep3_emperor_yearly.2240.desc_outro
	}
	theme = learning
	override_background = { reference = ep3_medi_market }
	left_portrait = {
		character = root
		animation = rage
	}
	right_portrait = {
		character = scope:the_scholar
		animation = debating
	}
	cooldown = { years = 25 }

	trigger = {
		OR = {
			has_ep3_dlc_trigger = yes
			has_tgp_dlc_trigger = yes
		}
		is_landed_or_landless_administrative = yes
		government_allows = administrative
		culture = {
			OR = {
				has_graphical_east_asia_culture_group_trigger = yes
				ep3_valid_greek_culture_trigger = yes
			}	
		}	
		any_courtier_or_guest = {
			ep3_2240_valid_courtier_trigger = yes
		}		
	}

	weight_multiplier = {
		base = 1
		modifier = {
			culture = culture:greek
			add = 1
		}
		modifier = {
			any_courtier_or_guest = {
				ep3_2240_valid_courtier_trigger = yes
				knows_language = language_latin
			}
			add = 1
		}
		modifier = {
			any_courtier_or_guest = {
				ep3_2240_valid_courtier_trigger = yes
				is_of_major_interest_trigger = { CHARACTER = root }
			}
			add = 1
		}
	}

	immediate = {
		random_courtier_or_guest = {
			limit = {
				ep3_2240_valid_courtier_trigger = yes
			}
			weight = {
				base = 1
				modifier = { 
					add = 3
					knows_language = language_latin
				}
				modifier = { 
					add = 2
					is_of_major_interest_trigger = { CHARACTER = root }
				}
			}
			save_scope_as = the_scholar
		}
	}

	# Option A: outwit
	option = {
		name = ep3_emperor_yearly.2240.a
		flavor = ep3_emperor_yearly.2240.a.flavor
		duel = {
			skill = learning
			target = scope:the_scholar
			60 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = ep3_emperor_yearly.2240.a_success
				send_interface_toast = {
					title = ep3_emperor_yearly.2240.a_success.tt
					left_icon = root
					right_icon = scope:the_scholar
					change_influence = massive_influence_gain
					scope:the_scholar = { change_influence = major_influence_loss }
				}
			}
			40 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = ep3_emperor_yearly.2240.a_failure
				send_interface_toast = {
					title = ep3_emperor_yearly.2240.a_failure.tt
					left_icon = root
					right_icon = scope:the_scholar
					change_influence = major_influence_loss
					scope:the_scholar = { change_influence = massive_influence_gain }
				}
			}
		}
		stress_impact = {
			dull = major_stress_impact_gain
			shy = medium_stress_impact_gain
			humble = medium_stress_impact_gain
			lazy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 1
			}
			modifier = {
				has_trait = dull
				add = -50
			}
			modifier = {
				has_trait = shy
				add = -25
			}
			modifier = {
				has_trait = humble
				add = -25
			}
		}
	}

	# Option B: just shut up!
	option = {
		name = ep3_emperor_yearly.2240.b
		add_dread = minor_dread_gain
		change_influence = minor_influence_gain
		scope:the_scholar = {
			change_influence = medium_influence_loss
			pay_short_term_gold = {
				target = root
				gold = minor_gold_value
			}
			add_opinion = {
				target = root
				modifier = hurt_opinion
				opinion = -25
			}
		}
		stress_impact = {
			base = medium_stress_impact_loss
			humble = major_stress_impact_gain
			calm = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_vengefulness = 1
			}
			modifier = {
				has_trait = humble
				add = -25
			}
			modifier = {
				has_trait = calm
				add = -25
			}
			modifier = {
				scope:the_scholar.dynasty ?= root.dynasty
				add = -75
			}
			modifier = {
				scope:the_scholar = { is_heir_of = root }
				factor = 0
			}
		}
	}

	# Option C: ignore - opt-out
	option = {
		name = ep3_emperor_yearly.2240.c
		stress_impact = {
			base = minor_stress_impact_loss
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_energy = -1
			}
		}
	}
}

### STATE FAITH EVENTS ###

# Your liege changed the state faith (reaction)
ep3_emperor_yearly.2300 = {
	type = character_event
	title = ep3_emperor_yearly.2300.t
	desc = ep3_emperor_yearly.2300.desc
	theme = administrative
	left_portrait = {
		character = root
		animation = reading
	}
	lower_right_portrait = scope:liege_loc

	immediate = {
		liege = { save_scope_as = liege_loc }
		liege.capital_province = { save_scope_as = capital }
	}

	#Option A: Outrageous
	option = {
		name = ep3_emperor_yearly.2300.a
		trigger = {
			faith != liege.primary_title.state_faith
		}
		add_piety = medium_piety_gain
		stress_impact = {
			calm = minor_stress_impact_gain
			cynical = medium_stress_impact_gain
			humble = medium_stress_impact_gain
			loyal = major_stress_impact_gain
		}
	}

	#Option B: The emperor must be right
	option = {
		name = ep3_emperor_yearly.2300.b
		trigger = {
			faith != liege.primary_title.state_faith
		}
		set_character_faith = liege.primary_title.state_faith
		stress_impact = {
			zealous = major_stress_impact_gain
			disloyal = major_stress_impact_gain
			arrogant = major_stress_impact_gain
			loyal = major_stress_impact_loss
		}
	}

	#Option C: Finally
	option = {
		name = ep3_emperor_yearly.2300.c
		trigger = {
			faith = liege.primary_title.state_faith
		}
		add_piety = medium_piety_gain
		stress_impact = {
			zealous = major_stress_impact_loss
			loyal = major_stress_impact_loss
		}
	}
}

# Your liege demands that you make more of an effort to convert your counties, who don't follow the state faith
ep3_emperor_yearly.2310 = {
	type = letter_event
	opening = ep3_emperor_yearly.2310.t
	desc = {
		desc = ep3_emperor_yearly.2310.desc
		triggered_desc = {
			trigger = {
				faith != top_liege.primary_title.state_faith
			}
			desc = ep3_emperor_yearly.2310.desc_you_too
		}
	}
	sender = scope:liege_loc

	trigger = {
		is_governor = yes
		government_allows = state_faith
		exists = top_liege.primary_title.state_faith
		top_liege.faith = top_liege.primary_title.state_faith
		any_sub_realm_county = {
			faith != root.top_liege.primary_title.state_faith
		}
		top_liege = { is_ai = yes }
	}

	immediate = {
		top_liege = { save_scope_as = liege_loc }
		cp:councillor_court_chaplain ?= { save_scope_as = chaplain }
		random_sub_realm_county = {
			limit = {
				faith != root.top_liege.primary_title.state_faith
			}
			weight = {
				base = 1
				modifier = {
					this = root.capital_county
					add = 100
				}
			}
			save_scope_as = target_county
		}
	}

	#Option A: start converting county
	option = {
		name = ep3_emperor_yearly.2310.a
		trigger = {
			exists = scope:chaplain
			scope:chaplain.faith = root.top_liege.primary_title.state_faith
		}
		scope:chaplain = {
			set_council_task = {
				task_type = task_conversion
				target = scope:target_county.title_province
			}
		}
		increase_governance_effect = { VALUE = 10 }
		scope:liege_loc = {
			add_opinion = {
				target = root
				modifier = pious_opinion
				opinion = 20
			}
		}
		stress_impact = {
			cynical = medium_stress_impact_gain
			lazy = medium_stress_impact_gain
			disloyal = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = -0.5
			}
			modifier = {
				has_trait = disloyal
				add = -50
			}
			modifier = {
				has_trait = lazy
				add = -50
			}
			opinion_modifier = {
				who = root
				opinion_target = scope:liege_loc
			}
		}
	}

	#Option B: no thanks
	option = {
		name = ep3_emperor_yearly.2310.b
		trigger = {
			faith != top_liege.primary_title.state_faith
		}
		add_piety = medium_piety_gain
		scope:liege_loc = {
			add_opinion = {
				target = root
				modifier = impious_opinion
				opinion = -20
			}
		}
		stress_impact = {
			loyal = major_stress_impact_gain
			zealous = major_stress_impact_loss
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 1
				ai_zeal = 0.5
			}
			opinion_modifier = {
				opinion_target = scope:liege_loc
				multiplier = -1
			}
		}
	}

	#Option C: I'll convert myself for starters
	option = {
		name = ep3_emperor_yearly.2310.c
		trigger = {
			faith != top_liege.primary_title.state_faith
		}
		set_character_faith = top_liege.primary_title.state_faith
		change_influence = medium_influence_gain
		stress_impact = {
			zealous = major_stress_impact_gain
			disloyal = major_stress_impact_gain
			arrogant = major_stress_impact_gain
			loyal = major_stress_impact_loss
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = -0.5
				ai_zeal = -0.5
			}
			modifier = {
				has_trait = loyal
				add = 100
			}
			modifier = {
				has_trait = disloyal
				add = -50
			}
			opinion_modifier = {
				opinion_target = scope:liege_loc
			}
		}
	}

	#Option D: I'll think about it
	option = {
		name = ep3_emperor_yearly.2310.d
		trigger = {
			faith = top_liege.primary_title.state_faith
		}
		scope:liege_loc = {
			add_opinion = {
				target = root
				modifier = impious_opinion
				opinion = -10
			}
		}
		ai_chance = {
			base = 100
			opinion_modifier = {
				who = root
				opinion_target = scope:liege_loc
				multiplier = -1
			}
		}
	}
}

# HoF helps you change state faith
ep3_emperor_yearly.2320 = {
	type = character_event
	title = ep3_emperor_yearly.2320.t
	desc = ep3_emperor_yearly.2320.desc
	theme = faith
	left_portrait = {
		character = root
		animation = personality_honorable
	}
	right_portrait = {
		character = scope:hof
		animation = wedding_priest
	}

	cooldown = { years = 20 }

	trigger = {
		government_allows = administrative
		government_allows = state_faith
		exists = primary_title.state_faith
		top_liege = this
		highest_held_title_tier >= tier_empire
		faith != primary_title.state_faith
		faith.fervor > primary_title.state_faith.fervor
		exists = faith.religious_head
		faith.religious_head != root
		primary_title.state_faith.religious_head ?= {
			this != root.faith.religious_head
		}
	}

	immediate = {
		faith.religious_head = { save_scope_as = hof }
	}

	weight_multiplier = {
		base = 1
		# More likely if you are close to affording the (discounted) change state faith decision
		modifier = {
			OR = {
				influence >= 7000
				piety >= 3000
			}
			add = 1
		}
		# Less likely if you are far from affording the (discounted) change state faith decision
		modifier = {
			OR = {
				influence <= 3000
				piety <= 2000
			}
			factor = 0.5
		}
	}

	#Option A: thanks
	option = {
		name = ep3_emperor_yearly.2320.a
		custom_tooltip = ep3_emperor_yearly.2320.a.tt
		add_character_flag = {
			flag = ep3_hof_state_faith_discount
			years = 10
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = 1
			}
		}
	}

	#Option B: no thanks
	option = {
		name = ep3_emperor_yearly.2320.b
		every_vassal = {
			limit = {
				faith = root.primary_title.state_faith
			}
			custom = every_vassal_state_faith
			add_opinion = {
				target = root
				modifier = pious_opinion
				opinion = 5
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_energy = -0.5
				ai_boldness = -0.5
			}
		}
	}
}

# Your State faith's fervor is too low (heresy risk)
ep3_emperor_yearly.2330 = {
	type = character_event
	title = ep3_emperor_yearly.2330.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:hof
				}
				desc = ep3_emperor_yearly.2330.desc_hof
			}
			desc = ep3_emperor_yearly.2330.desc
		}
		desc = ep3_emperor_yearly.2330.desc_end
		triggered_desc = {
			trigger = {
				exists = scope:hof
			}
			desc = ep3_emperor_yearly.2330.desc_end_hof
		}
	}
	theme = faith
	left_portrait = {
		character = root
		animation = personality_zealous
	}
	right_portrait = {
		trigger = {
			exists = scope:hof
		}
		character = scope:hof
		animation = debating
	}

	cooldown = { years = 20 }

	trigger = {
		government_allows = administrative
		government_allows = state_faith
		exists = primary_title.state_faith
		top_liege = this
		highest_held_title_tier >= tier_empire
		faith = primary_title.state_faith
		faith.fervor < 40
	}

	immediate = {
		if = {
			limit = {
				exists = faith.religious_head
				faith.religious_head != root
			}
			faith.religious_head = { save_scope_as = hof }
		}
	}

	weight_multiplier = {
		base = 1
		# More likely if fervor is very low
		modifier = {
			faith = {
				fervor < 30
			}
			add = 1
		}
		modifier = {
			faith = {
				fervor < 20
			}
			add = 1
		}
		modifier = {
			faith = {
				fervor < 10
			}
			add = 1
		}
	}

	#Option A: let's do something
	option = {
		name = ep3_emperor_yearly.2330.a
		flavor = ep3_emperor_yearly.2330.a.tt
		faith = {
			change_fervor = {
				value = minor_fervor_gain
				desc = state_faith_fervor_campaign
			}
		}
		add_piety = major_piety_loss
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = 1
			}
		}
	}

	#Option B: it's probably fine
	option = {
		name = ep3_emperor_yearly.2330.b
		stress_impact = {
			zealous = massive_stress_impact_gain
			diligent = major_stress_impact_gain
			loyal = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_energy = -0.5
				ai_zeal = -0.5
			}
			modifier = {
				add = 50
				has_trait = eccentric
			}
			modifier = {
				add = -50
				has_trait = loyal
			}
		}
	}
}

# You (either emperor or governor) do not practice your state faith and someone complains
ep3_emperor_yearly.2340 = {
	type = character_event
	title = ep3_emperor_yearly.2340.t
	desc = ep3_emperor_yearly.2340.desc
	theme = administrative
	left_portrait = {
		character = root
		animation = eyeroll
	}
	right_portrait = {
		character = scope:complainer
		animation = debating
	}

	cooldown = { years = 10 }

	trigger = {
		government_allows = administrative
		OR = {
			#emperor
			AND = {
				top_liege = this
				highest_held_title_tier >= tier_empire
			}
			#governor
			is_governor = yes
		}
		government_allows = state_faith
		exists = top_liege.primary_title.state_faith
		faith != top_liege.primary_title.state_faith
		trigger_if = {
			limit = {
				top_liege = this
			}
			any_vassal = {
				house ?= {
					is_powerful_family = yes
				}
				faith = top_liege.primary_title.state_faith
				is_available_ai_adult = yes
			}
		}
		trigger_else = {
			top_liege = {
				any_vassal = {
					faith = top_liege.primary_title.state_faith
					is_available_ai_adult = yes
				}
			}
		}
	}

	immediate = {
		# If emperor
		if = {
			limit = {
				top_liege = this
			}
			# Find a vassal from a powerful family
			random_vassal = {
				limit = {
					house ?= {
						is_powerful_family = yes
					}
					faith = root.primary_title.state_faith
					is_available_ai_adult = yes
				}
				save_scope_as = complainer
			}
		}
		# If governor
		else = {
			# find a fellow vassal - prio to neighbors, powerful families, zealots
			top_liege = {
				random_vassal = {
					limit = {
						faith = top_liege.primary_title.state_faith
						is_available_ai_adult = yes
					}
					weight = {
						base = 1
						modifier = {
							any_neighboring_realm_same_rank_owner = {
								this = root
							}
							add = 50
						}
						modifier = {
							house ?= {
								is_powerful_family = yes
							}
							add = 25
						}
						modifier = {
							has_trait = zealous
							add = 25
						}
						modifier = {
							has_vassal_stance = zealot
							add = 15
						}
					}
					save_scope_as = complainer
				}
			}
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			top_liege = this
			add = 0.5
		}
	}

	#Option A: Maybe I should fall in line...
	option = {
		name = ep3_emperor_yearly.2340.a
		set_character_faith = top_liege.primary_title.state_faith
		if = {
			limit = {
				top_liege = this
			}
			add_legitimacy = minor_legitimacy_gain
		}
		else = {
			change_influence = medium_influence_gain
		}
		stress_impact = {
			zealous = massive_stress_impact_gain
			stubborn = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = -0.5
				ai_zeal = -0.5
			}
			modifier = {
				has_trait = diligent
				add = 50
			}
			modifier = {
				has_trait = loyal
				add = 50
			}
		}
	}

	#Option B: Blah blah blah...
	option = {
		name = ep3_emperor_yearly.2340.b
		if = {
			limit = {
				top_liege = this
			}
			every_vassal = {
				limit = {
					faith = root.primary_title.state_faith
				}
				custom = every_vassal_state_faith
				add_opinion = {
					target = root
					modifier = impious_opinion
					opinion = -10
				}
			}
		}
		else = {
			top_liege = {
				every_vassal = {
					limit = {
						faith = top_liege.primary_title.state_faith
					}
					custom = every_fellow_vassal_state_faith
					add_opinion = {
						target = root
						modifier = impious_opinion
						opinion = -10
					}
				}
			}
		}
		add_piety = major_piety_gain
		stress_impact = {
			zealous = major_stress_impact_loss
			lazy = medium_stress_impact_loss
			eccentric = medium_stress_impact_loss
			diligent = medium_stress_impact_gain
			loyal = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = 1
				ai_energy = -0.5
			}
			modifier = {
				has_trait = loyal
				add = -50
			}
			modifier = {
				has_trait = eccentric
				add = 50
			}
		}
	}
}

### NOBLE FAMILIES MAINTENANCE ###

# You are not from a Powerful Family - react to a new Powerful Family emerging

ep3_emperor_yearly.2400 = {
	type = character_event
	title = ep3_emperor_yearly.2400.t
	desc = ep3_emperor_yearly.2400.desc
	theme = administrative
	left_portrait = {
		character = root
		animation = disapproval
	}
	right_portrait = {
		character = scope:new_family
		animation = toast_goblet
	}

	trigger = {
		government_allows = administrative
		house ?= {
			is_powerful_family = no
		}
		NOT = {
			#cooldown
			has_character_flag = 8020_powerful_family_cooldown
		}
	}

	immediate = {
		add_character_flag = {
			flag = 8020_powerful_family_cooldown
			years = 10
		}
	}

	option = {
		name = ep3_emperor_yearly.2400.a
		custom_tooltip = 8020_powerful_family_desc
	}
}

# Your family is now a Powerful Family

ep3_emperor_yearly.2401 = {
	type = character_event
	title = ep3_emperor_yearly.2401.t
	desc = ep3_emperor_yearly.2401.desc
	theme = administrative
	left_portrait = {
		character = root
		animation = ecstasy
	}

	trigger = {	
		government_allows = administrative
		house ?= {
			is_powerful_family = yes
		}
	}

	immediate = {
		# For the tooltip
		root = { save_scope_as = new_family }
	}

	option = {
		name = ep3_emperor_yearly.2401.a
		custom_tooltip = 8020_powerful_family_desc
	}
}

# A new noble family is introduced to the empire

ep3_emperor_yearly.2410 = {
	type = character_event
	title = ep3_emperor_yearly.2410.t
	desc = ep3_emperor_yearly.2410.desc
	theme = administrative
	left_portrait = {
		character = root
		animation = boredom
	}
	right_portrait = {
		character = scope:noble_family_head
		animation = happy_teacher
	}

	trigger = {
		government_allows = administrative
		is_available = yes
		exists = scope:noble_family_head
		exists = scope:new_title
		NOR = {
			this.house ?= scope:new_title.holder.house
			has_character_flag = 2410_noble_family_cooldown
		}
	}

	on_trigger_fail = {
		if = {
			limit = {
				exists = scope:noble_family_head
				exists = scope:new_title
				OR = {
					has_character_flag = 2410_noble_family_cooldown
					is_available = no
				}
			}
			send_interface_message = {
				title = 2410_noble_family_tt
				type = msg_new_powerful_family
				left_icon = scope:noble_family_head
				right_icon = scope:new_title
				desc = 2410_noble_family_tt_desc
			}
		}
	}

	immediate = {
		add_character_flag = {
			flag = 2410_noble_family_cooldown
			years = 5
		}
		scope:new_title.holder = {
			save_scope_as = new_family
			save_scope_as = noble_family_head
		}
	}

	option = {
		name = ep3_emperor_yearly.2410.a
		custom_tooltip = 2410_noble_family_tt_desc
	}
}

# A new family (and not the emperor's) has become dominant
ep3_emperor_yearly.2420 = {
	type = character_event
	title = ep3_emperor_yearly.2420.t
	desc = ep3_emperor_yearly.2420.desc
	theme = administrative
	left_portrait = {
		character = scope:noble_family_head
		animation = personality_dishonorable
	}

	trigger = {
		government_allows = administrative
		is_available = yes
		NOT = {
			#cooldown
			has_character_flag = 2420_noble_family_cooldown
		}
	}

	on_trigger_fail = {
		if = {
			limit = {
				OR = {
					has_character_flag = 2420_noble_family_cooldown
					is_available = no
				}
			}
			send_interface_message = {
				title = 2420_noble_family_tt
				type = msg_new_powerful_family
				left_icon = scope:noble_family_head
				desc = 2420_noble_family_tt_desc
			}
		}
	}

	immediate = {
		add_character_flag = {
			flag = 2420_noble_family_cooldown
			years = 5
		}
	}

	option = {
		name = ep3_emperor_yearly.2420.a
		custom_tooltip = 2420_noble_family_tt_desc
	}
}
