########################
# EP3 Eparch Events
########################
namespace = ep3_eparch_event

### Fortify the Capital
ep3_eparch_event.0001 = {
	type = character_event
	title = ep3_eparch_event.0001.t
	desc = {
		desc = ep3_eparch_event.0001.desc_intro
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:defensive_war = { defender_war_score > 10 }
				}
				desc = ep3_eparch_event.0001.desc_winning_war
			}
			triggered_desc = {
				trigger = {
					scope:defensive_war = { defender_war_score < -10 }
				}
				desc = ep3_eparch_event.0001.desc_losing_war
			}
			desc = ep3_eparch_event.0001.desc_undecided_war
		}
		desc = ep3_eparch_event.0001.desc_outro
	}
	theme = administrative
	override_background = { reference = ep3_city_gate }
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = {
				OR = {
					has_trait = craven
					has_trait = paranoid
				}
			}
			animation = paranoia
		}
		triggered_animation = {
			trigger = {
				OR = {
					has_trait = brave
					has_trait = diligent
					has_trait = ambitious
				}
			}
			animation = inspect_weapon
		}
		animation = worry
	}
	
	cooldown = { years = 10 }
	
	trigger = {
		has_court_position = eparch_court_position
		liege = {
			any_character_war = {
				is_war_leader = prev
				is_defender = prev
			}
			capital_province ?= {
				NOT = { has_province_modifier = ep3_eparch_fortified_capital_modifier }
				is_occupied = no
				any_army_in_location = {
					NOR = {
						is_army_in_siege = yes
						is_army_in_raid = yes
					}
				}
			}
		}
	}
	
	immediate = {
		save_scope_as = eparch
		liege = {
			save_scope_as = emperor
			random_character_war = {
				limit = {
					is_war_leader = prev
					is_defender = prev
				}
				primary_attacker = { save_scope_as = attacker }
				save_scope_as = defensive_war
			}
			capital_province = { save_scope_as = capital }
		}
	}
	
	option = { # The capital MUST be protected!
		name = ep3_eparch_event.0001.a
		
		remove_treasury_or_gold = major_treasury_or_gold_value
		if = {
			limit = { has_trait = governor }
			increase_governance_effect = { VALUE = 4 }
		}
		scope:capital = {
			add_province_modifier = {
				modifier = ep3_eparch_fortified_capital_modifier
				years = 20
			}
		}
		
		# Follow up event for the liege
		scope:emperor = { trigger_event = ep3_eparch_event.0002 }
		
		stress_impact = {
			greedy = medium_stress_impact_loss
		}
		
		ai_chance = {
			base = 10
			
			modifier = {
				factor = 3
				has_trait = diligent
			}
			modifier = { # Wants to protect themself, the enemey MIGHT actually get here
				factor = 2
				has_trait = paranoid
			}
			modifier = { # Wants to make sure the citizens are safe
				factor = 2
				has_trait = compassionate
			}
			modifier = {
				factor = 0
				has_trait = greedy
			}
			modifier = { # The AI shouldn't spend gold it doesn't have
				factor = 0
				short_term_treasury_or_gold < major_treasury_or_gold_value
			}
		}
	}
	
	option = { # A moderate improvement should suffice.
		name = ep3_eparch_event.0001.b
		
		remove_treasury_or_gold = minor_treasury_or_gold_value
		scope:capital = {
			add_province_modifier = {
				modifier = ep3_eparch_somewhat_fortified_capital_modifier
				years = 10
			}
		}
		
		stress_impact = {
			# None
		}
		
		ai_chance = {
			base = 20
			
			modifier = {
				factor = 4
				has_trait = temperate
			}
			modifier = {
				factor = 2
				has_trait = content
			}
			modifier = { # The AI shouldn't spend gold it doesn't have
				factor = 0
				short_term_treasury_or_gold < minor_treasury_or_gold_value
			}
		}
	}
	
	option = { # Surely the capital is not in any danger?
		name = ep3_eparch_event.0001.c
		
		stress_impact = {
			craven = medium_stress_impact_loss
		}
		
		ai_chance = {
			base = 10
			
			modifier = {
				factor = 5
				has_trait = lazy
			}
			modifier = {
				factor = 2
				has_trait = arbitrary
			}
			modifier = {
				factor = 2
				has_trait = brave
			}
			modifier = {
				factor = 0
				has_trait = craven
			}
		}
	}
}

# Liege follow up
ep3_eparch_event.0002 = {
	type = character_event
	title = ep3_eparch_event.0001.t
	desc = {
		desc = ep3_eparch_event.0002.desc
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:emperor_is_home }
				desc = ep3_eparch_event.0002.desc_at_home
			}
			desc = ep3_eparch_event.0002.desc_away
		}
	}
	theme = emperor
	override_background = {
		trigger = { exists = scope:emperor_is_home }
		reference = ep3_city_gate
	}
	override_background = {
		trigger = { is_commanding_army = yes }
		reference = army_camp
	}
	override_background = {
		reference = terrain
	}
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = { exists = scope:emperor_is_home }
			animation = war_defender
		}
		animation = reading
	}
	right_portrait = {
		character = scope:emperor_is_home
		triggered_animation = {
			trigger = {
				OR = {
					has_trait = brave
					has_trait = diligent
					has_trait = ambitious
				}
			}
			animation = inspect_weapon
		}
		animation = steward
	}
	lower_right_portrait = {
		character = scope:emperor_is_away
	}
	
	trigger = {
	}
	
	immediate = {
		show_as_tooltip = {
			scope:capital = {
				add_province_modifier = {
					modifier = ep3_eparch_fortified_capital_modifier
					years = 20
				}
			}
		}
		
		# Scopes for portraits, descs, etc.
		if = {
			limit = {
				location = scope:capital
			}
			scope:eparch = { save_scope_as = emperor_is_home }
		}
		else = {
			scope:eparch = { save_scope_as = emperor_is_away }
		}
	}
	
	option = { # Such diligence ought to be rewarded!
		name = ep3_eparch_event.0002.a
		
		scope:eparch = {
			send_interface_message = {
				type = event_generic_good
				title = eparch_reward_msg_title
				left_icon = root
				
				root = {
					pay_short_term_gold = {
						target = scope:eparch
						gold = medium_gold_value
					}
				}
			}
		}
		progress_towards_friend_effect = {
			REASON = friend_rewarding_duties
			CHARACTER = scope:eparch
			OPINION = default_friend_opinion
		}
		
		stress_impact = {
			greedy = medium_stress_impact_loss
		}
		
		ai_chance = {
			base = 10
			
			modifier = {
				factor = 4
				has_trait = just
			}
			modifier = {
				factor = 3
				has_trait = generous
			}
			modifier = {
				factor = 2
				has_trait = compassionate
			}
			modifier = {
				factor = 0
				has_trait = greedy
			}
			modifier = { # The AI shouldn't spend gold it doesn't have
				factor = 0
				short_term_gold < medium_gold_value
			}
		}
	}
	
	option = { # They are only doing their job.
		name = ep3_eparch_event.0002.b
		
		stress_impact = {
			# None
		}
		
		ai_chance = {
			base = 10
			
			modifier = {
				factor = 4
				has_trait = greedy
			}
			modifier = {
				factor = 2
				has_trait = callous
			}
			modifier = {
				factor = 2
				has_trait = arrogant
			}
			modifier = {
				factor = 2
				has_trait = content
			}
		}
	}
}

### Losing Control
ep3_eparch_event.0005 = {
	type = character_event
	title = ep3_eparch_event.0005.t
	desc = ep3_eparch_event.0005.desc
	theme = administrative
	override_background = {
		trigger = { scope:capital = province:496 }
		reference = ep3_constantinople
	}
	override_background = { reference = market }
	left_portrait = {
		character = root
		animation = worry
	}
	
	cooldown = { years = 10 }
	
	trigger = {
		has_court_position = eparch_court_position
		liege = {
			capital_province.county ?= {
				county_control < 90
			}
		}
	}
	
	weight_multiplier = {
		base = 1
		modifier = {
			capital_province.county ?= {
				county_control < 60
			}
			factor = 1.1
		}
		modifier = {
			capital_province.county ?= {
				county_control < 30
			}
			factor = 1.2
		}
	}
	
	immediate = {
		save_scope_as = eparch
		liege = {
			save_scope_as = emperor
			capital_province = { save_scope_as = capital }
			
			if = {
				limit = {
					exists = cp:councillor_marshal
					NOT = { cp:councillor_marshal = root }
				}
				cp:councillor_marshal = { save_scope_as = marshal }
			}
		}
	}
	
	option = { # Let's pay for some extra hands to patrol the streets
		name = ep3_eparch_event.0005.a
		
		remove_treasury_or_gold = medium_treasury_or_gold_value
		if = {
			limit = { has_trait = governor }
			increase_governance_effect = { VALUE = 4 }
		}
		scope:emperor = {
			send_interface_message = {
				type = send_interface_message_good
				title = ep3_eparch_event.0005.success_liege
				left_icon = scope:capital.county
				right_icon = scope:eparch
				
				scope:capital.county = {
					change_county_control = 5
				}
			}
		}
		
		stress_impact = {
			greedy = minor_stress_impact_gain
		}
		
		ai_chance = {
			base = 10
			
			modifier = {
				factor = 3
				has_trait = education_martial
			}
			modifier = {
				factor = 2
				has_trait = paranoid
			}
			modifier = {
				factor = 2
				has_trait = compassionate
			}
			modifier = {
				factor = 0
				has_trait = greedy
			}
			modifier = { # The AI shouldn't spend gold it doesn't have
				factor = 0
				short_term_treasury_or_gold < medium_treasury_or_gold_value
			}
		}
	}
	
	option = { # Perhaps we can turn the criminals against each other?
		name = ep3_eparch_event.0005.b
		
		duel = {
			skill = intrigue
			value = decent_skill_rating
			50 = { # Success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 2
					min = -49
				}
				desc = ep3_eparch_event.0005.b_success_tt
				send_interface_toast = {
					title = ep3_eparch_event.0005.b_success
					left_icon = scope:capital.county
					
					add_intrigue_lifestyle_xp = medium_lifestyle_xp
					
					scope:emperor = {
						send_interface_message = {
							type = send_interface_message_good
							title = ep3_eparch_event.0005.success_liege
							left_icon = scope:capital.county
							right_icon = scope:eparch
							
							scope:capital.county = {
								change_county_control = 10
							}
						}
					}
				}
			}
			50 = { # Failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -2
					min = -49
				}
				desc = ep3_eparch_event.0005.b_failure_tt
				send_interface_toast = {
					title = ep3_eparch_event.0005.b_failure
					left_icon = scope:capital.county
					
					scope:emperor = {
						send_interface_message = {
							type = send_interface_message_bad
							title = ep3_eparch_event.0005.failure_liege
							left_icon = scope:capital.county
							right_icon = scope:eparch
							
							scope:capital.county = {
								change_county_control = -5
							}
						}
					}
				}
			}
		}
		
		stress_impact = {
			compassionate = minor_stress_impact_gain
		}
		
		ai_chance = {
			base = 10
			
			modifier = {
				factor = 4
				has_trait = deceitful
			}
			modifier = {
				factor = 2
				has_trait = vengeful
			}
			modifier = {
				factor = 2
				has_trait = arbitrary
			}
			modifier = {
				factor = 0
				has_trait = compassionate
			}
		}
	}
	
	option = { # Marshal might be able to help?
		name = ep3_eparch_event.0005.c
		
		trigger = {
			exists = scope:marshal
		}
		
		change_influence = medium_influence_loss
		scope:marshal = {
			random = {
				chance = {
					value = 10
					add = {
						value = scope:marshal.intrigue
						multiply = 2
					}
					max = 90
				}
				
				send_interface_toast = {
					left_icon = scope:eparch
					
					if = {
						limit = {
							can_add_hook = {
								type = favor_hook
								target = scope:eparch
							}
						}
						add_hook = {
							type = favor_hook
							target = scope:eparch
						}
					}
				}
			}
		}
		scope:emperor = {
			send_interface_message = {
				type = send_interface_message_good
				title = ep3_eparch_event.0005.success_liege
				left_icon = scope:capital.county
				right_icon = scope:eparch
				
				scope:capital.county = {
					change_county_control = 5
				}
			}
		}
		
		stress_impact = {
			paranoid = minor_stress_impact_gain
		}
		
		ai_chance = {
			base = 10
			
			modifier = {
				factor = 4
				has_trait = trusting
			}
			modifier = {
				factor = 2
				has_trait = gregarious
			}
			modifier = {
				factor = 2
				has_trait = humble
			}
			modifier = {
				factor = 0
				has_trait = paranoid
			}
		}
	}
	
	option = { # No need to overreact. The situation is not THAT desperate.
		name = ep3_eparch_event.0005.d
		
		eparch_neglecting_duty_effect = yes
		
		stress_impact = {
			diligent = medium_stress_impact_gain
		}
		
		ai_chance = {
			base = 10
			
			modifier = {
				factor = 5
				has_trait = lazy
			}
			modifier = {
				factor = 2
				has_trait = content
			}
			modifier = {
				factor = 0
				has_trait = diligent
			}
		}
	}
}

### Sickness Strikes
ep3_eparch_event.0010 = {
	type = character_event
	title = ep3_eparch_event.0010.t
	desc = ep3_eparch_event.0010.desc
	theme = administrative
	override_background = {
		trigger = { scope:capital = province:496 }
		reference = ep3_constantinople
	}
	override_background = { reference = market }
	left_portrait = {
		character = root
		animation = disbelief
	}
	
	cooldown = { years = 10 }
	
	trigger = {
		has_court_position = eparch_court_position
		liege = {
			capital_province ?= {
				any_province_epidemic = { count > 0 }
			}
		}
	}
	
	immediate = {
		save_scope_as = eparch
		liege = {
			save_scope_as = emperor
			capital_province = { save_scope_as = capital }
		}
		if = {
			limit = {
				employs_court_position = court_physician_court_position
			}
			random_court_position_holder = {
				type = court_physician_court_position
				save_scope_as = physician
			}
		}
		liege = {
			capital_province ?= {
				random_province_epidemic = {
					weight = {
						base = 1
						modifier = {
							add = 30
							outbreak_intensity >= apocalyptic
						}
						modifier = {
							add = 20
							outbreak_intensity >= major
						}
					}
					
					save_scope_as = capital_plague
				}
			}
		}
	}
	
	option = { # Drastic measures are required. Quarantine the city!
		name = ep3_eparch_event.0010.a
		
		trigger = {
			scope:capital = {
				any_province_epidemic = {
					OR = {
						outbreak_intensity = major
						outbreak_intensity = apocalyptic
					}
				}
			}
		}
		
		remove_treasury_or_gold = major_treasury_or_gold_value
		scope:capital = {
			every_province_epidemic = {
				if = {
					limit = {
						outbreak_intensity = major
					}
					set_epidemic_outbreak_intensity = minor
				}
				else_if = {
					limit = {
						outbreak_intensity = apocalyptic
					}
					set_epidemic_outbreak_intensity = major
				}
			}
		}
		
		stress_impact = {
			fickle = medium_stress_impact_gain
		}
		
		ai_chance = {
			base = 10
			
			modifier = {
				factor = 3
				has_trait = eccentric
			}
			modifier = {
				factor = 2
				has_trait = wrathful
			}
			modifier = {
				factor = 0
				has_trait = greedy
			}
			modifier = { # The AI shouldn't spend gold it doesn't have
				factor = 0
				short_term_treasury_or_gold < major_treasury_or_gold_value
			}
		}
	}
	
	option = { # Scour the city for physicians and put them to work.
		name = ep3_eparch_event.0010.b
		
		change_influence = medium_influence_loss
		scope:capital = {
			add_province_modifier = {
				modifier = ep3_eparch_plague_protection_modifier
				years = 20
			}
		}
		
		stress_impact = {
		}
		
		ai_chance = {
			base = 10
			
			modifier = {
				factor = 4
				has_trait = deceitful
			}
			modifier = {
				factor = 2
				has_trait = diligent
			}
			modifier = {
				factor = 2
				has_trait = arbitrary
			}
			modifier = {
				factor = 0.5
				has_trait = greedy
			}
		}
	}
	
	option = { # My physician can help!
		name = ep3_eparch_event.0010.c
		
		trigger = {
			exists = scope:physician
		}
		
		scope:physician = {
			duel = {
				value = decent_skill_rating
				localization = duel_aptitude_challenge
				10 = { # Success
					compare_modifier = {
						value = scope:physician.aptitude:court_physician_court_position
						multiplier = 20
						min = -9
					}
					desc = ep3_eparch_event.0010.c_success_tt
					send_interface_toast = {
						title = ep3_eparch_event.0010.c_success
						left_icon = scope:capital.county
						
						scope:capital = {
							add_province_modifier = {
								modifier = ep3_eparch_physician_at_work_modifier
								years = 25
							}
						}
					}
				}
				90 = { # Failure
					compare_modifier = {
						value = scope:physician.aptitude:court_physician_court_position
						multiplier = -20
						min = -89
					}
					desc = ep3_eparch_event.0010.c_failure_tt
					send_interface_toast = {
						title = ep3_eparch_event.0010.c_failure
						left_icon = scope:capital.county
						
						root = { change_influence = major_influence_loss }
					}
				}
			}
		}
		
		stress_impact = {
			compassionate = minor_stress_impact_loss
		}
		
		ai_chance = {
			base = 10
			
			modifier = {
				factor = 4
				has_trait = generous
			}
			modifier = {
				factor = 1.5
				has_trait = diligent
			}
			modifier = {
				factor = 0.5
				has_trait = greedy
			}
		}
	}
	
	option = { # A slight cough isn't going to kill anyone...
		name = ep3_eparch_event.0010.d
		
		eparch_neglecting_duty_effect = yes
		
		stress_impact = {
			diligent = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
		}
		
		ai_chance = {
			base = 10
			
			modifier = {
				factor = 4
				has_trait = arbitrary
			}
			modifier = {
				factor = 2
				has_trait = cynical
			}
			modifier = {
				factor = 2
				has_trait = sadistic
			}
			modifier = {
				factor = 2
				has_trait = callous
			}
			modifier = {
				factor = 0
				OR = {
					has_trait = diligent
					has_trait = compassionate
				}
			}
		}
	}
}

### University Needs Teachers
ep3_eparch_event.0015 = {
	type = character_event
	title = ep3_eparch_event.0015.t
	desc = ep3_eparch_event.0015.desc
	theme = administrative
	override_background = {
		trigger = { scope:capital = province:496 }
		reference = ep3_constantinople
	}
	override_background = { reference = bp2_university }
	left_portrait = {
		character = root
		animation = reading
	}
	lower_left_portrait = scope:teacher_my_house
	lower_center_portrait = scope:teacher_powerful_family
	lower_right_portrait = scope:teacher_local_scholar
	
	cooldown = { years = 10 }
	
	trigger = {
		has_court_position = eparch_court_position
		liege = {
			capital_province ?= {
				is_higher_studies_location = yes
			}
		}
	}
	
	immediate = {
		save_scope_as = eparch
		liege = {
			save_scope_as = emperor
			capital_province = {
				save_scope_as = capital
				save_scope_as = location # For the teacher trigger used below
			}
		}
		
		# Look for and save suitable candidates
		# Find a candidate within root's own house
		house = {
			random_house_member = {
				limit = {
					is_courtier = yes
					liege = { # It's your direct courtier or the courtier of an AI character
						OR = {
							this = scope:eparch
							is_ai = yes
						}
					}
					any_heir_title = { count < 1 } # Is not an heir to any titles
					is_available_adult_education_teacher = yes # Is a suitable teacher
				}
				save_scope_as = teacher_my_house
			}
		}
		# Find a candidate from a powerful family
		liege = {
			random_powerful_family = {
				limit = {
					NOR = {
						this = scope:eparch.house
						this = scope:emperor.house
					}
					any_house_member = {
						is_courtier = yes
						liege = { is_ai = yes } # Is a courtier of an AI character
						any_heir_title = { count < 1 } # Is not an heir to any titles
						is_available_adult_education_teacher = yes # Is a suitable teacher
					}
				}
				random_house_member = {
					limit = {
						is_courtier = yes
						liege = { is_ai = yes } # Is a courtier of an AI character
						any_heir_title = { count < 1 } # Is not an heir to any titles
						is_available_adult_education_teacher = yes # Is a suitable teacher
					}
					save_scope_as = teacher_powerful_family
					house.house_head = { save_scope_as = powerful_house_head }
				}
			}
		}
		# Find/create a local scholar
		if = {
			limit = {
				any_pool_character = {
					province = scope:capital
					is_available_adult_education_teacher = yes
					NOR = {
						has_character_flag = teacher_1
						has_character_flag = teacher_2
					}
				}
			}
			random_pool_character = {
				province = scope:capital
				limit = {
					is_available_adult_education_teacher = yes
					NOR = {
						has_character_flag = teacher_1
						has_character_flag = teacher_2
					}
				}
				save_scope_as = teacher_local_scholar						
			}
		}
		else = {
			create_character = {
				# Below is based on the adult_education_teacher template
				age = { 35 75 }
				random_traits_list = {
					count = 1
					education_diplomacy_4 = {}
					education_martial_4 = {}
					education_stewardship_4 = {}
					education_intrigue_4 = {}
					education_learning_4 = {}
					education_diplomacy_5 = {}
					education_martial_5 = {}
					education_stewardship_5 = {}
					education_intrigue_5 = {}
					education_learning_5 = {}
				}
				diplomacy = {
					min_template_average_skill
					max_template_decent_skill
				}
				martial = {
					min_template_average_skill
					max_template_decent_skill
				}
				stewardship = {
					min_template_average_skill
					max_template_decent_skill
				}
				intrigue = {
					min_template_average_skill
					max_template_decent_skill
				}
				learning = {
					min_template_average_skill
					max_template_decent_skill
				}
				random_traits = yes
				dynasty = none
				faith = scope:capital.faith
				culture = scope:capital.culture
				gender_female_chance = {
					if = {
						limit = { scope:capital.faith = { has_doctrine = doctrine_gender_male_dominated } }
						add = 0
					}
					else_if = {
						limit = { scope:capital.faith = { has_doctrine = doctrine_gender_female_dominated } }
						add = 100
					}
					else = {
						add = 50
					}
				}
				location = scope:capital
				save_scope_as = teacher_local_scholar
			}
		}
	}
	
	option = { # As it happens, I know the perfect candidate!
		name = ep3_eparch_event.0015.a
		
		trigger = {
			exists = scope:teacher_my_house
		}
		
		remove_treasury_or_gold = major_treasury_or_gold_value
		house = {
			add_house_modifier = {
				modifier = ep3_eparch_university_influence_modifier
				years = 25
			}
		}
		scope:teacher_my_house = {
			save_scope_as = teacher_tt
			custom_tooltip = {
				text = teacher_moves_to_capital_tt
				move_to_pool_at = scope:capital
				add_character_flag = teacher_1
			}
		}
		
		stress_impact = {
			greedy = minor_stress_impact_loss
		}
		
		ai_chance = {
			base = 10
			
			modifier = {
				factor = 5
				has_trait = family_first
			}
			modifier = {
				factor = 3
				has_trait = ambitious
			}
			modifier = {
				factor = 2
				has_trait = arrogant
			}
			modifier = {
				factor = 2
				has_trait = just
				scope:teacher_my_house.sum_of_all_skills_value > scope:teacher_powerful_family.sum_of_all_skills_value
				scope:teacher_my_house.sum_of_all_skills_value > scope:teacher_local_scholar.sum_of_all_skills_value
			}
			modifier = {
				factor = 0.5
				has_trait = honest
			}
			modifier = { # The AI shouldn't spend gold it doesn't have
				factor = 0
				short_term_treasury_or_gold < major_treasury_or_gold_value
			}
		}
	}
	
	option = { # The X family has a worthy candidate.
		name = ep3_eparch_event.0015.b
		
		trigger = {
			exists = scope:teacher_powerful_family
		}
		
		if = {
			limit = {
				can_add_hook = {
					target = scope:powerful_house_head
					type = favor_hook
				}
			}
			add_hook = {
				target = scope:powerful_house_head
				type = favor_hook
			}
		}
		scope:powerful_house_head = {
			add_opinion = {
				modifier = respect_opinion
				opinion = 20
				target = scope:eparch
			}
			send_interface_message = {
				type = msg_admin_eparch_with_text_good
				title = ep3_eparch_event.0015.b.msg.t
				desc = ep3_eparch_event.0015.b.msg.desc
				left_icon = scope:eparch
				right_icon = scope:teacher_powerful_family
				
				change_influence = medium_influence_gain
				house = {
					add_house_modifier = {
						modifier = ep3_eparch_university_influence_modifier
						years = 25
					}
				}
			}
		}
		scope:teacher_powerful_family = {
			save_scope_as = teacher_tt
			custom_tooltip = {
				text = teacher_moves_to_capital_tt
				move_to_pool_at = scope:capital
				add_character_flag = teacher_1
			}
		}
		
		stress_impact = {
			paranoid = medium_stress_impact_gain
		}
		
		ai_chance = {
			base = 10
			
			modifier = {
				factor = 4
				has_trait = trusting
			}
			modifier = {
				factor = 2
				has_trait = just
				scope:teacher_powerful_family.sum_of_all_skills_value > scope:teacher_my_house.sum_of_all_skills_value
				scope:teacher_powerful_family.sum_of_all_skills_value > scope:teacher_local_scholar.sum_of_all_skills_value
			}
			modifier = {
				factor = 0
				has_trait = paranoid
			}
		}
	}
	
	option = { # There is bound to be a scholar I can hire within the city
		name = ep3_eparch_event.0015.c
		
		remove_treasury_or_gold = medium_treasury_or_gold_value
		scope:teacher_local_scholar = {
			save_scope_as = teacher_tt
			custom_tooltip = {
				text = teacher_moves_to_capital_tt
				add_character_flag = teacher_1
			}
		}
		
		ai_chance = {
			base = 10
			
			modifier = {
				factor = 4
				has_trait = just
				scope:teacher_local_scholar.sum_of_all_skills_value > scope:teacher_my_house.sum_of_all_skills_value
				scope:teacher_local_scholar.sum_of_all_skills_value > scope:teacher_powerful_family.sum_of_all_skills_value
			}
			modifier = {
				factor = 2
				has_trait = humble
			}
			modifier = { # The AI shouldn't spend gold it doesn't have
				factor = 0
				short_term_treasury_or_gold < medium_treasury_or_gold_value
			}
		}
	}
	
	option = { # Actually. How about you come work for me?
		name = ep3_eparch_event.0015.d
		
		trigger = {
			NOT = { exists = scope:teacher_my_house }
		}
		
		change_influence = medium_influence_loss
		add_courtier = scope:teacher_local_scholar
		eparch_neglecting_duty_effect = yes
		
		ai_chance = {
			base = 10
			
			modifier = {
				factor = 2
				has_trait = greedy
			}
			modifier = {
				factor = 2
				has_trait = arbitrary
			}
			modifier = {
				factor = 2
				has_trait = deceitful
			}
			modifier = {
				factor = 0
				has_trait = content
			}
			modifier = { # The AI shouldn't spend influence it doesn't have
				factor = 0
				influence < medium_influence_value
			}
		}
	}
	
	option = { # They will have to make do for now.
		name = ep3_eparch_event.0015.e
		
		eparch_neglecting_duty_effect = yes
		
		ai_chance = {
			base = 10
			
			modifier = {
				factor = 3
				has_trait = lazy
			}
			modifier = {
				factor = 0
				has_trait = diligent
			}
		}
	}
}

### For Services Rendered
ep3_eparch_event.0020 = {
	type = character_event
	title = ep3_eparch_event.0020.t
	desc = {
		desc = ep3_eparch_event.0020.desc_intro
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:reward_gold
				}
				desc = ep3_eparch_event.0020.desc_gold
			}
			triggered_desc = {
				trigger = {
					exists = scope:reward_artifact
				}
				desc = ep3_eparch_event.0020.desc_artifact
			}
			triggered_desc = {
				trigger = {
					exists = scope:reward_hook_removal
				}
				desc = ep3_eparch_event.0020.desc_hook_removal
			}
			triggered_desc = {
				trigger = {
					exists = scope:reward_emperor_hook
				}
				desc = ep3_eparch_event.0020.desc_emperor_hook
			}
		}
	}
	theme = administrative
	override_background = { reference = corridor_night }
	left_portrait = {
		character = root
		animation = happiness
	}
	right_portrait = {
		character = scope:emperor
		triggered_animation = {
			trigger = {
				exists = scope:reward_gold
			}
			animation = betting
		}
		triggered_animation = {
			trigger = {
				exists = scope:reward_artifact
			}
			animation = inspect_weapon
		}
		triggered_animation = {
			trigger = {
				exists = scope:reward_hook_removal
			}
			animation = toast
		}
		triggered_animation = {
			trigger = { OR = { religion = religion:eastern_orthodox_religion religion = religion:catholic_religion religion = religion:protestant_religion } }
			animation = acknowledging # anim uses crucifix scepter
		}
		animation = war_over_tie
	}
	lower_right_portrait = scope:peer_with_hook
	artifact = {
	    target = scope:newly_created_artifact
	    position = lower_left_portrait
	}
	
	cooldown = { years = 20 }
	
	trigger = {
		has_court_position = eparch_court_position
	}
	
	weight_multiplier = {
		base = 1
		
		modifier = { # Neglecting your duty reduces the chance to receive rewards
			add = {
				value = var:eparch_neglecting_duty
				multiply = -1 # To make this a negative value
				divide = 100 # To make the value fit the scale
				min = -0.8
			}
			exists = var:eparch_neglecting_duty
		}
	}
	
	immediate = {
		save_scope_as = eparch
		liege = {
			save_scope_as = emperor
			capital_province = {
				save_scope_as = capital
			}
		}
		
		# Generate a reward
		hidden_effect = {
			random_list = {
				10 = { # Gold
					save_scope_as = reward_gold
				}
				10 = { # Artifact
					save_scope_as = reward_artifact
					random_list = { # Randomize the artifact type
						10 = {
							create_artifact_weapon_effect = { OWNER = root CREATOR = scope:emperor SET_WEAPON_TYPE = flag:artifact_weapon_type_axe }
						}
						10 = {
							create_artifact_weapon_effect = { OWNER = root CREATOR = scope:emperor SET_WEAPON_TYPE = flag:artifact_weapon_type_mace }
						}
						10 = {
							create_artifact_weapon_effect = { OWNER = root CREATOR = scope:emperor SET_WEAPON_TYPE = flag:artifact_weapon_type_sword }
						}
						10 = {
							create_artifact_armor_effect = { OWNER = root CREATOR = scope:emperor SET_ARMOR_TYPE = flag:no }
						}
						10 = {
							create_artifact_regalia_effect = { OWNER = root SMITH = scope:emperor }
						}
						10 = {
							create_artifact_crown_effect = { OWNER = root SMITH = scope:emperor }
						}
						10 = {
							create_artifact_brooch_effect = { OWNER = root SMITH = scope:emperor }
						}
					}
				}
				10 = { # Hook Removal
					trigger = {
						liege = {
							any_vassal = {
								has_usable_hook = root
								is_ai = yes
							}
						}
					}
					save_scope_as = reward_hook_removal
					liege = {
						random_vassal = {
							limit = {
								has_usable_hook = root
								is_ai = yes
							}
							save_scope_as = peer_with_hook
						}
					}
				}
				10 = { # Gain hook on emperor
					trigger = {
						can_add_hook = {
							target = scope:emperor
							type = favor_hook
						}
					}
					save_scope_as = reward_emperor_hook
				}
			}
		}
	}
	
	option = {
		name = ep3_eparch_event.0020.a
		
		# We apply the actual effects here, instead of in the immediate, because it looks better in-game
		if = { # Add the gold
			limit = {
				exists = scope:reward_gold
			}
			add_gold = major_gold_value
		}
		if = { # We create the artifact above, but let's make sure we show it
			limit = {
				exists = scope:newly_created_artifact
			}
			scope:newly_created_artifact = {
				show_as_tooltip = {
					set_owner = root
				}
			}
		}
		if = { # Spend the hook on the peer-vassal
			limit = {
				exists = scope:reward_hook_removal
			}
			scope:peer_with_hook ?= {
				use_hook = root
			}
		}
		if = { # Add hook on emperor
			limit = {
				exists = scope:reward_emperor_hook
			}
			add_hook = {
				target = scope:emperor
				type = favor_hook
			}
		}
		
		ai_chance = {
			base = 10
		}
	}
}

### Eparch: Neglect of Duty
ep3_eparch_event.9000 = {
	type = character_event
	title = ep3_eparch_event.9000.t
	desc = ep3_eparch_event.9000.desc
	theme = emperor
	override_background = { reference = throne_room }
	left_portrait = {
		character = root
		animation = anger
	}
	right_portrait = {
		character = scope:eparch
		animation = shame
	}
	
	trigger = {
		employs_court_position = eparch_court_position
		OR = {
			NOT = { exists = var:eparch_neglecting_duty }
			AND = {
				exists = var:eparch_neglecting_duty
				var:eparch_neglecting_duty <= 10
			}
		}
	}
	
	immediate = {
		# Let's make sure we have all of our scopes
		if = {
			limit = {
				NOT = { exists = scope:eparch }
			}
			random_court_position_holder = {
				type = eparch_court_position
				save_scope_as = eparch
			}
		}
		if = {
			limit = {
				NOT = { exists = scope:emperor }
			}
			save_scope_as = emperor
		}
		if = {
			limit = {
				NOT = { exists = scope:capital }
			}
			capital_province = { save_scope_as = capital }
		}
	}
	
	option = { # Unacceptable! Have them fired at once!
		name = ep3_eparch_event.9000.a
		
		show_as_tooltip = {
			revoke_court_position = {
				recipient = scope:eparch
				court_position = eparch_court_position
			}
			scope:eparch = {
				change_influence = massive_influence_loss
			}
		}
		add_dread = 10
		if = {
			limit = {
				scope:eparch = { has_hook = root }
			}
			custom_tooltip = eparch_hook_warning
			change_influence = major_influence_loss
		}
		scope:eparch = {
			save_scope_as = eparch_is_fired
			trigger_event = ep3_eparch_event.9001
		}
		
		stress_impact = {
			compassionate = medium_stress_impact_gain
			forgiving = minor_stress_impact_gain
			wrathful = minor_stress_impact_loss
		}
		
		ai_chance = {
			base = 10
			
			modifier = {
				factor = 3
				has_trait = wrathful
			}
			modifier = {
				factor = 3
				has_trait = vengeful
			}
			modifier = {
				factor = 2
				has_trait = callous
			}
			modifier = {
				factor = 2
				has_trait = impatient
			}
			modifier = {
				factor = 0
				has_trait = compassionate
			}
			modifier = {
				factor = 0
				scope:eparch = { has_hook = root }
			}
		}
	}
	
	option = { # Consider this a warning. But you will owe me!
		name = ep3_eparch_event.9000.b
		
		change_influence = medium_influence_gain
		
		show_as_tooltip = {
			if = { # If the eparch has a hook on us, spend that hook
				limit = {
					scope:eparch = { has_hook = root }
				}
				scope:eparch = { use_hook = root }
			}
			else_if = { # Otherwise, let's add a hook on the eparch if we can
				limit = {
					can_add_hook = {
						type = favor_hook
						target = scope:eparch
					}
				}
				add_hook = {
					type = favor_hook
					target = scope:eparch
				}
			}
		}
		scope:eparch = {
			save_scope_as = eparch_is_warned
			trigger_event = ep3_eparch_event.9001
		}
		
		stress_impact = {
			honest = minor_stress_impact_gain
		}
		
		ai_chance = {
			base = 20
			
			modifier = {
				factor = 4
				has_trait = deceitful
			}
			modifier = {
				factor = 2
				has_trait = patient
			}
			modifier = {
				factor = 2
				has_trait = arbitrary
			}
			modifier = {
				factor = 0
				has_trait = honest
			}
		}
	}
	
	option = { # I will turn a blind eye to this. For now.
		name = ep3_eparch_event.9000.c
		
		scope:eparch = {
			save_scope_as = eparch_gets_away_with_it
			trigger_event = ep3_eparch_event.9001
		}
		
		stress_impact = {
			vengeful = medium_stress_impact_gain
			just = minor_stress_impact_gain
		}
		
		ai_chance = {
			base = 20
			
			modifier = {
				factor = 4
				has_trait = trusting
			}
			modifier = {
				factor = 2
				has_trait = gregarious
			}
			modifier = {
				factor = 2
				has_trait = humble
			}
			modifier = {
				factor = 1.5
				has_trait = craven
			}
			modifier = {
				factor = 1.5
				has_trait = shy
			}
			modifier = {
				factor = 0
				OR = {
					has_trait = vengeful
					has_trait = just
				}
			}
		}
	}
}

# Notify Eparch of liege's action
ep3_eparch_event.9001 = {
	type = character_event
	title = ep3_eparch_event.9000.t
	desc = {
		triggered_desc = {
			trigger = {
				OR = {
					exists = scope:eparch_is_fired
					exists = scope:eparch_is_warned
				}
			}
			desc = ep3_eparch_event.9001.intro
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:eparch_is_fired
				}
				desc = ep3_eparch_event.9001.desc_fired
			}
			triggered_desc = {
				trigger = {
					exists = scope:eparch_is_warned
				}
				desc = ep3_eparch_event.9001.desc_warned
			}
			desc = ep3_eparch_event.9001.desc_nothing
		}
	}
	theme = administrative
	override_background = { reference = throne_room_scope }
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = {
				exists = scope:eparch_is_fired
			}
			animation = stress
		}
		triggered_animation = {
			trigger = {
				exists = scope:eparch_is_warned
			}
			animation = worry
		}
		animation = shame
	}
	right_portrait = {
		character = scope:emperor
		triggered_animation = {
			trigger = {
				exists = scope:eparch_is_fired
			}
			animation = dismissal
		}
		triggered_animation = {
			trigger = {
				exists = scope:eparch_is_warned
			}
			animation = scheme
		}
		animation = disapproval
	}
	
	trigger = {
		scope:emperor = { is_alive = yes }
		scope:eparch = { is_alive = yes }
	}
	
	immediate = {
		scope:emperor = { save_scope_as = background_throne_room_scope }
	}
	
	option = { # What? FIRED!?
		name = ep3_eparch_event.9001.a
		
		trigger = {
			exists = scope:eparch_is_fired
		}
		
		change_influence = massive_influence_loss
		scope:emperor = {
			revoke_court_position = {
				recipient = scope:eparch
				court_position = eparch_court_position
			}
		}
	}
	
	option = { # Well, that could have ended much worse I suppose.
		name = ep3_eparch_event.9001.b
		
		trigger = {
			exists = scope:eparch_is_warned
		}
		
		if = { # If the eparch has a hook on the emperor, spend that hook
			limit = {
				has_hook = scope:emperor
			}
			use_hook = scope:emperor
		}
		else_if = { # Otherwise, let's add a hook on the eparch if we can
			limit = {
				scope:emperor = {
					can_add_hook = {
						type = favor_hook
						target = scope:eparch
					}
				}
			}
			scope:emperor = {
				add_hook = {
					type = favor_hook
					target = scope:eparch
				}
			}
		}
	}
	
	option = { # I can consider myself lucky.
		name = ep3_eparch_event.9001.c
		
		trigger = {
			NOR = {
				exists = scope:eparch_is_fired
				exists = scope:eparch_is_warned
			}
		}
		
		change_influence = minor_influence_gain
	}
}
