namespace = epidemic_events

############################
## Epidemic Maintenance Events
## 0001-1000
## by Veronica Pazos
############################

# epidemic_events.0001 - Army commander gets infected - may spread to army
# epidemic_events.0010 - The plague has reached your court, set your stance (event to avoid event spamming)

# Army commander gets infected - may spread to army
epidemic_events.0001 = {
	type = character_event
	title = epidemic_events.0001.t
	desc = epidemic_events.0001.desc
	theme = plague
	left_portrait = {
		character = root
		animation = sick
	}
	override_background = { reference = army_camp }
	override_effect_2d = {
		reference = flies	
	}
	cooldown = { years = 2 } 
	
	immediate = {
		grab_epidemic_disease_effect = yes
		random_dummy_gender_soldier_effect = { SCOPE_NAME = dummy_gender }
	}
	
	option = { #You get sick lol
		name = {
			trigger = { OR = { faith.religion = religion:eastern_orthodox_religion faith.religion = religion:catholic_religion faith.religion = religion:protestant_religion } }
			text = epidemic_events.0001.a.christian
		}
		name = {
			trigger = { NOT = { OR = { faith.religion = religion:eastern_orthodox_religion faith.religion = religion:catholic_religion faith.religion = religion:protestant_religion } } }
			text = epidemic_events.0001.a
		}
		if = { #are you infecting your knights or your entire army; kinda arbitrary for flavour
			limit = {
				OR = { #infect army, these are highly contagious
					has_trait = typhus
					has_trait = bubonic_plague
					has_trait = dysentery
				}
			}
			random = {
				chance = 90
				#you infect your knights
				send_interface_toast = {
					title = epidemic_events.0001.a.toast
					left_icon = root
					add_character_modifier = {
						modifier = epidemic_infected_knights_modifier #knights effectiveness
						years = 2
					}
				}
			}
		}
		else = { #infect your knigths only, the rest of diseases are kinda less infectious
			random = {
				chance = 20
				#you infect your army
				send_interface_toast = {
					title = epidemic_events.0001.a.toast
					left_icon = root
					add_character_modifier = {
						modifier = epidemic_infected_army_modifier #damage mult
						years = 2
					}
				}
			}
		}
		stress_impact = {
			paranoid = medium_stress_impact_gain
			gregarious = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
		}
	}
}

# Notification for going into isolation due to epidemic
epidemic_events.0100 = {
	type = character_event
	title = epidemic_events.0100.t
	desc = epidemic_events.0100.desc
	theme = plague
	left_portrait = {
		character = root
		animation = fear
	}

	option = { #Into isolation we go
		name = epidemic_events.0100.a
		add_legitimacy_effect = { LEGITIMACY = minor_legitimacy_loss }
		add_prestige = major_prestige_loss
		isolate_family_decision_effect = yes
		ai_chance = {
			base = 100
		}
	}
}
epidemic_events.0101 = {
	type = character_event
	title = epidemic_events.0101.t
	desc = epidemic_events.0101.desc
	theme = plague
	left_portrait = {
		character = root
		animation = personality_content
	}
	trigger = {
		has_character_modifier = isolating_modifier
	}

	option = { #Out of isolation we come
		name = epidemic_events.0101.a
		unisolate_family_decision_effect = yes
		ai_chance = {
			base = 100
		}
	}
}

# Prosperity event / Plague recovery event
epidemic_events.0110 = {
	type = character_event
	title = epidemic_events.0110.t
	desc = {
		desc = epidemic_events.0110.desc
		triggered_desc = {
			trigger = {
				exists = scope:new_preferred_capital
			}
			desc = epidemic_events.0110.desc.new_capital
		}
	}
	theme = plague
	left_portrait = {
		character = root
		animation = personality_rational
	}

	trigger = {
		exists = scope:epidemic
		# Make sure no new plagues showed up since then, or a new preferred capital county has not been chosen already
		NOT = {
			any_sub_realm_county = {
				OR = {
					has_province_with_epidemic = { intensity = any }
					has_variable = preferred_capital_chosen
				}
			}
		}
		OR = { #You're either not on cooldown OR the Black Death
			NOT = { has_variable = had_recent_prosperity_event_var }
			scope:epidemic = {
				epidemic_type.epidemic_trait = trait:bubonic_plague
				outbreak_intensity = apocalyptic
			}
		}
		has_variable_list = formerly_infected_counties
	}

	immediate = {
		set_variable = {
			name = had_recent_prosperity_event_var
			years = 2
		}
		if = {
			limit = { # A new capital potential?
				highest_held_title_tier >= tier_kingdom
				any_sub_realm_duchy = {
					title_capital_county = {
						NOT = { exists = var:epidemic_cooldown_general }
						holder = {
							OR = {
								this = root
								is_ai = yes
							}
						}
						save_temporary_scope_as = county_to_check
						root = {
							primary_title = {
								is_de_jure_liege_or_above_target = scope:county_to_check
							}
							capital_county != scope:county_to_check
							any_in_list = {
								variable = formerly_infected_counties
								this = scope:county_to_check
							}
						}
					}
				}
			}
			random_sub_realm_duchy = {
				weight = {
					base = 1
					modifier = {
						add = title_capital_county.development_level
					}
				}
				limit = {
					title_capital_county = {
						NOT = { exists = var:epidemic_cooldown_general }
						holder = {
							OR = {
								this = root
								is_ai = yes
							}
						}
						save_temporary_scope_as = county_to_check
						root = {
							primary_title = {
								is_de_jure_liege_or_above_target = scope:county_to_check
							}
							capital_county != scope:county_to_check
							any_in_list = {
								variable = formerly_infected_counties
								this = scope:county_to_check
							}
						}
					}
				}
				title_capital_county = { save_scope_as = new_preferred_capital }
				scope:new_preferred_capital = {
					set_variable = {
						name = preferred_capital_chosen
						years = 2
					}
				}
			}
		}
	}

	option = { # Ah, a cool new capital!
		name = epidemic_events.0110.a
		trigger = {
			exists = scope:new_preferred_capital
			scope:epidemic = { outbreak_intensity >= major } #don't switch capitals for a minor plague
			is_ai = no
		}
		remove_treasury_or_gold = {
			value = epidemic_fromdust_value
			add = minor_treasury_or_gold_value
		}
		create_title_and_vassal_change = {
			type = revoked
			save_scope_as = change
			add_claim_on_loss = no
		}
		scope:new_preferred_capital = {
			change_title_holder = {
				holder = root
				change = scope:change
			}
		}
		resolve_title_and_vassal_change = scope:change
		primary_title = {
			set_capital_county = scope:new_preferred_capital
		}
		set_realm_capital = scope:new_preferred_capital
		scope:new_preferred_capital = {
			add_county_modifier = {
				modifier = plague_new_capital
				years = 10
			}
		}
		every_in_list = {
			variable = formerly_infected_counties
			custom = every_county_infected_10_years
			limit = {
				this != scope:new_preferred_capital
			}
			add_county_modifier = {
				modifier = county_epidemic_recovered_medium_modifier
				years = 5
			}
		}
	}

	option = { # Spend cash to help recover from the plague
		name = epidemic_events.0110.b
		if = {
			limit = {
				scope:epidemic = {
					epidemic_type.epidemic_trait = trait:bubonic_plague
					outbreak_intensity = apocalyptic
				}
			}
			remove_treasury_or_gold = epidemic_fromdust_value
			every_in_list = {
				variable = formerly_infected_counties
				custom = every_county_infected_10_years
				add_county_modifier = {
					modifier = county_epidemic_recovered_strong_modifier
					years = 5
				}
			}
		}
		else_if = {
			limit = {
				scope:epidemic = {
					outbreak_intensity >= major
				}
			}
			remove_treasury_or_gold = epidemic_fromdust_value
			every_in_list = {
				variable = formerly_infected_counties
				custom = every_county_infected_10_years
				add_county_modifier = {
					modifier = county_epidemic_recovered_medium_modifier
					years = 5
				}
			}
		}
		else = {
			remove_treasury_or_gold = {
				value = epidemic_fromdust_value
				multiply = 0.5
			}
			every_in_list = {
				variable = formerly_infected_counties
				custom = every_county_infected_10_years
				add_county_modifier = {
					modifier = county_epidemic_recovered_minor_modifier
					years = 5
				}
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = -1
			}
			modifier = {
				factor = 0
				short_term_gold < epidemic_fromdust_value
			}
		}
	}

	option = { # Nah don't care
		name = epidemic_events.0110.c
		if = {
			limit = {
				scope:epidemic = {
					outbreak_intensity >= major
				}
			}
			every_in_list = {
				variable = formerly_infected_counties
				custom = every_county_infected_10_years
				add_county_modifier = {
					modifier = county_epidemic_recovered_minor_modifier
					years = 5
				}
			}
		}
		else = {
			every_in_list = {
				variable = formerly_infected_counties
				custom = every_county_infected_10_years
				add_county_modifier = {
					modifier = county_epidemic_recovered_tiny_modifier
					years = 5
				}
			}
		}
		if = {
			limit = {
				has_legitimacy = yes
			}
			add_legitimacy = miniscule_legitimacy_loss
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_greed = 2.5
				ai_rationality = -1
			}
		}
	}

	after = {
		clear_variable_list = formerly_infected_counties
	}
}

############################
## Epidemic Flavor Events
## 1000-2000
## by James Beaumont
############################

############################
## A charismatic priest is convincing the sick that the plague is a result of their heathen ways
## 1000
## by James Beaumont
############################
epidemic_events.1000 = {
	type = character_event
	title = epidemic_events.1000.t
	desc = epidemic_events.1000.desc
	theme = plague
	override_background = { reference = ce1_funeral_pyre }
	override_effect_2d = {
		reference = smoke	
	}
	
	left_portrait = {
		character = scope:charismatic_priest
		animation = debating
	}
	cooldown = { years = 5 } 
	trigger = {
		is_available = yes
		# Only tribes
		government_has_flag = government_is_tribal
		# Only if the plague is quite dramatic
		any_sub_realm_county = {
			any_county_province = {
				OR = {
					county.holder = root
					squared_distance = {
						target = root.capital_province
						value <= squared_distance_medium #250 map-pixels. Roughly one Ireland away (top to bottom).
					}
				}
				any_province_epidemic = {
					intensity >= major
				}
			}
		}
		# Make sure there's a valid faith to convert to
		OR = {
			AND = {
				faith = { has_doctrine_parameter = unreformed }
				faith.religion = {
					any_faith = { NOT = { has_doctrine_parameter = unreformed } }
				}
			}
			AND = {
				faith.religion = {
					is_in_family = rf_pagan
				}
				faith = { NOT = { has_doctrine_parameter = unreformed } }
				faith.religion = {
					any_faith = { has_doctrine_parameter = unreformed }
				}
			}
			AND = {
				faith = { has_doctrine_parameter = unreformed }
				top_liege = {
					any_character_to_title_neighboring_and_across_water_county = {
						holder.top_liege = {
							any_sub_realm_county = {
								faith = { NOT = { has_doctrine_parameter = unreformed } }
							}
						}
					}
				}
			}
			AND = {
				faith = { NOT = { has_doctrine_parameter = unreformed } }
				top_liege = {
					any_sub_realm_county = {
						faith = {
							has_doctrine_parameter = unreformed
						}
					}
				}
			}
		}
	}

	immediate = {
		# Grab a county to convert
		random_sub_realm_county = {
			limit = {
				any_county_province = {
					OR = {
						county.holder = root
						squared_distance = {
							target = root.capital_province
							value <= squared_distance_medium #250 map-pixels. Roughly one Ireland away (top to bottom).
						}
					}
					any_province_epidemic = {
						intensity >= major
					}
				}
			}
			weight = {
				base = 1
				modifier = {
					add = 250
					has_province_with_epidemic = { intensity >= apocalyptic }
				}
			}
			random_county_province = {
				limit = {
					any_province_epidemic = {
						intensity >= major
					}
				}
				weight = {
					base = 1
					modifier = {
						add = 250
						any_province_epidemic = {
							intensity >= apocalyptic
						}
					}
				}
				random_province_epidemic = {
					intensity >= major
					weight = {
						base = 1
						modifier = {
							add = 250
							outbreak_intensity >= apocalyptic
						}
					}
					save_scope_as = cult_epidemic
				}
			}
			save_scope_as = infected_county
		}
		# Grab the reformed version of the unreformed faith if possible (Bon for example)
		if = {
			limit = {
				faith = { has_doctrine_parameter = unreformed }
				faith.religion = {
					any_faith = { NOT = { has_doctrine_parameter = unreformed } }
				}
			}
			faith.religion = {
				random_faith = {
					limit = {
						NOT = { has_doctrine_parameter = unreformed }
					}
					save_scope_as = heretical_faith
				}
			}
		}
		# Otherwise grab a reformed faith from within your realm
		else_if = {
			limit = {
				faith = { has_doctrine_parameter = unreformed }
				top_liege = {
					any_sub_realm_county = {
						faith = { NOT = { has_doctrine_parameter = unreformed } }
					}
				}
			}
			top_liege = {
				random_sub_realm_county = {
					limit = {
						faith = { NOT = { has_doctrine_parameter = unreformed } }
					}
					faith = { save_scope_as = heretical_faith }
				}
			}
		}
		# Otherwise grab a nearby reformed faith
		else_if = {
			limit = {
				faith = { has_doctrine_parameter = unreformed }
				top_liege = {
					any_character_to_title_neighboring_and_across_water_county = {
						holder.top_liege = {
							any_sub_realm_county = {
								faith = { NOT = { has_doctrine_parameter = unreformed } }
							}
						}
					}
				}
			}
			top_liege = {
				random_character_to_title_neighboring_and_across_water_county = {
					limit = {
						holder.top_liege = {
							any_sub_realm_county = {
								faith = { NOT = { has_doctrine_parameter = unreformed } }
							}
						}
					}
					holder.top_liege = {
						random_sub_realm_county = {
							limit = {
								faith = { NOT = { has_doctrine_parameter = unreformed } }
							}
							faith = { save_scope_as = heretical_faith }
						}
					}
				}
			}
		}
		# You're a reformed faith and your people wanna revert to the old ways
		else_if = {
			limit = {
				# Don't get Kuzarism for Jewish realms
				faith.religion = { is_in_family = rf_pagan }
				faith = { NOT = { has_doctrine_parameter = unreformed } }
				faith.religion = {
					any_faith = { has_doctrine_parameter = unreformed }
				}
			}
			faith.religion = {
				random_faith = {
					limit = {
						has_doctrine_parameter = unreformed
					}
					save_scope_as = heretical_faith
				}
			}
		}
		# You're a reformed faith and you rule over pagans
		else_if = {
			limit = {
				faith = { NOT = { has_doctrine_parameter = unreformed } }
				top_liege = {
					any_sub_realm_county = {
						faith = {
							has_doctrine_parameter = unreformed
						}
					}
				}
			}
			top_liege = {
				random_sub_realm_county = {
					limit = {
						faith = {
							has_doctrine_parameter = unreformed
						}
					}
					faith = { save_scope_as = heretical_faith }
				}
			}
		}
		# Now create the priest
		# See if there's a nearby person of the culture
		if = {
			limit = {
				top_liege = {
					any_character_to_title_neighboring_and_across_water_county = {
						faith = scope:heretical_faith
					}
				}
			}
			top_liege = {
				random_character_to_title_neighboring_and_across_water_county = {
					limit = { faith = scope:heretical_faith }
					culture = { save_scope_as = heretical_culture }
				}
			}
		}
		else = {
			root.culture = { save_scope_as = heretical_culture }
		}
		# Create a priest
		create_character = {
			template = priest_character_template
			location = root.location
			culture = scope:heretical_culture
			faith = scope:heretical_faith
			trait = eccentric
			#Set up the scope
			save_scope_as = charismatic_priest
		}
	}
	
	option = { # They have a point :thinking_emoji:
		name = epidemic_events.1000.c
		trigger = {
			has_trait = cynical
		}
		set_character_faith = scope:heretical_faith
		every_sub_realm_county = {
			custom = every_infected_county
			limit = {
				any_county_province = {
					any_province_epidemic = {
						this = scope:cult_epidemic
					}
				}
			}
			set_county_faith = scope:heretical_faith
			add_county_modifier = {
				modifier = plague_cult_embraced
				years = 10
			}
		}
		stress_impact = {
			cynical = major_stress_impact_loss
			arrogant = medium_stress_impact_gain
			stubborn = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_zeal = -1
				ai_rationality = -1
			}
			modifier = {
				factor = 0
				faith = { NOT = { has_doctrine_parameter = unreformed } }
			}
		}
	}

	option = { # Burn this raving lunatic!
		name = epidemic_events.1000.a
		scope:charismatic_priest = {
			death = {
				killer = root
				death_reason = death_execution
			}
		}
		every_sub_realm_county = {
			custom = every_infected_county
			limit = {
				any_county_province = {
					any_province_epidemic = {
						this = scope:cult_epidemic
					}
				}
			}
			add_county_modifier = {
				modifier = plague_cult_persecuted
				years = 10
			}
		}
		stress_impact = {
			sadistic = minor_stress_impact_loss
			compassionate = medium_stress_impact_gain
			cynical = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = 1
				ai_compassion = -1
			}
		}
	}

	option = { # I'm sure they can't do any harm
		name = epidemic_events.1000.b
		if = { # Don't go converting all of the world into unreformed faiths
			limit = {
				OR = {
					faith = { has_doctrine_parameter = unreformed }
					is_ai = no
				}
			}
			scope:infected_county = {
				set_county_faith = scope:heretical_faith
			}
		}
		scope:infected_county = {
			add_county_modifier = {
				modifier = plague_cult_embraced
				years = 10
			}
		}
		stress_impact = {
			zealous = medium_stress_impact_gain
			arrogant = medium_stress_impact_gain
			stubborn = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_zeal = -1
				ai_rationality = -0.5
			}
		}
	}
}

############################
## Superstitious courtiers want you to nail the coffin of your deceased lover shut to prevent them from rising as a revanent
## 1010
## by James Beaumont
############################
epidemic_events.1010 = {
	type = character_event
	title = epidemic_events.1010.t
	desc = epidemic_events.1010.desc
	theme = plague
	override_background = ce1_catacombs
	left_portrait = {
		character = scope:superstitious_courtier
		animation = throne_room_one_handed_passive_3
		camera = camera_event_group_talking_left_left
	}
	right_portrait = {
		character = scope:dead_lover
		animation = dead
		camera = camera_event_right_forward
	}
	cooldown = { years = 5 } 
	trigger = {
		is_available_adult = yes
		# Only if there's a big plague
		any_sub_realm_county = {
			any_county_province = {
				OR = {
					county.holder = root
					squared_distance = {
						target = root.capital_province
						value <= squared_distance_medium #250 map-pixels. Roughly one Ireland away (top to bottom).
					}
				}
				any_province_epidemic = {
					intensity >= major
				}
			}
		}
		# Recently deceased
		any_memory = {
			OR = {
				has_memory_type = spouse_died
				has_memory_type = soulmate_died
				has_memory_type = lover_died
			}
			memory_participant:dead_relation = {
				time_since_death = {
					years <= 3
				}
			}
		}
		# You have a courtier who is plausibly superstitious
		any_courtier_or_guest = {
			is_available_adult = yes
			probably_superstitious = yes
		}
	}

	immediate = {
		get_random_nearby_realm_epidemic = { INTENSITY = major }
		random_memory = {
			limit = {
				OR = {
					has_memory_type = spouse_died
					has_memory_type = soulmate_died
					has_memory_type = lover_died
				}
				any_memory_participant = {
					time_since_death = {
						years <= 3
					}
				}
			}
			memory_participant:dead_relation = { save_scope_as = dead_lover }
			save_scope_as = dead_memory
		}
		random_courtier_or_guest = {
			limit = {
				is_available_adult = yes
				probably_superstitious = yes
			}
			save_scope_as = superstitious_courtier
		}
	}

	option = { # Nail every coffin in the kingdom!
		name = epidemic_events.1010.c
		trigger = {
			has_trait = paranoid
		}
		scope:dead_lover = {
			every_close_family_member = {
				custom = every_family_member_of_lover
				add_opinion = {
					modifier = hate_opinion
					opinion = -30
					target = root
				}
			}
		}
		progress_towards_friend_effect = {
			REASON = friend_revenants_nailed
			CHARACTER = scope:superstitious_courtier
			OPINION = default_friend_opinion
		}
		every_sub_realm_county = {
			custom = every_infected_county
			limit = {
				any_county_province = {
					any_province_epidemic = {
						this = scope:epidemic_scope
					}
				}
			}
			add_county_modifier = {
				modifier = revenants_expelled
				years = 15
			}
		}
		stress_impact = {
			paranoid = major_stress_impact_loss
			callous = minor_stress_impact_loss
			base = minor_stress_impact_gain
			zealous = minor_stress_impact_gain
			gregarious = minor_stress_impact_gain
			lustful = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = -1
				ai_rationality = -1
				ai_honor = -1
			}
		}
	}

	option = { # How bloody well dare you
		name = epidemic_events.1010.a
		add_piety = minor_piety_gain
		capital_county = {
			add_county_modifier = {
				modifier = beset_by_revenants
				years = 5
			}
		}
		stress_impact = {
			callous = minor_stress_impact_loss
			cynical = minor_stress_impact_gain
			paranoid = minor_stress_impact_gain
			eccentric = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = 1
				ai_compassion = 1
				ai_rationality = 1
			}
		}
	}

	option = { # Nail it shut!
		name = epidemic_events.1010.b
		scope:dead_lover = {
			every_close_family_member = {
				custom = every_family_member_of_lover
				add_opinion = {
					modifier = hate_opinion
					opinion = -30
					target = root
				}
			}
		}
		capital_county = {
			add_county_modifier = {
				modifier = revenant_expelled
				years = 5
			}
		}
		stress_impact = {
			paranoid = minor_stress_impact_loss
			callous = minor_stress_impact_loss
			base = minor_stress_impact_gain
			zealous = minor_stress_impact_gain
			gregarious = minor_stress_impact_gain
			lustful = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = -1
				ai_rationality = -1
				ai_honor = -1
			}
		}
	}
}

############################
## Guys wanna plant flowers to combat the plague
## 1020
## by James Beaumont
############################
epidemic_events.1020 = {	
	type = character_event
	title = epidemic_events.1020.t
	desc = epidemic_events.1020.desc
	theme = plague
	override_background = ce1_funeral_pyre
	override_effect_2d = { reference = flies }
	left_portrait = {
		character = root
		animation = survey
		camera = camera_event_left_away
	}
	right_portrait = {
		character = scope:miasma_courtier
		animation = storyteller
		camera = camera_event_center_away
	}
	cooldown = { years = 5 } 
	trigger = {
		is_available = yes
		any_sub_realm_county = {
			any_county_province = {
				OR = {
					county.holder = root
					squared_distance = {
						target = root.capital_province
						value <= squared_distance_medium #250 map-pixels. Roughly one Ireland away (top to bottom).
					}
				}
				any_province_epidemic = { }
			}
		}
		any_courtier_or_guest = {
			count >= 1
			is_available_adult = yes
		}
	}

	immediate = {
		random_sub_realm_county = {
			limit = {
				any_county_province = {
					OR = {
						county.holder = root
						squared_distance = {
							target = root.capital_province
							value <= squared_distance_medium #250 map-pixels. Roughly one Ireland away (top to bottom).
						}
					}
					any_province_epidemic = { }
					save_temporary_scope_as = province_temp
				}
			}
			scope:province_temp = {
				save_scope_as = epidemic_province
				random_province_epidemic = {
					save_scope_as = epidemic_scope
				}
			}
			save_scope_as = epidemic_county
		}
		if = {
			limit = {
				exists = court_position:court_physician_court_position
				court_position:court_physician_court_position = {
					is_available_adult = yes
				}
			}
			court_position:court_physician_court_position = {
				save_scope_as = miasma_courtier
			}
		}
		else = {
			random_courtier_or_guest = {
				limit = {
					is_available_adult = yes
				}
				save_scope_as = miasma_courtier
			}
		}
	}

	option = { # Okay, I'll do it :eyeroll:
		name = epidemic_events.1020.a
		add_legitimacy_effect = { LEGITIMACY = miniscule_legitimacy_gain }
		remove_treasury_or_gold = minor_treasury_or_gold_value
		scope:epidemic_county = {
			add_county_modifier = {
				modifier = flowers_planted
				years = 15
			}
		}
		stress_impact = {
			callous = minor_stress_impact_gain
			greedy = minor_stress_impact_gain
			cynical = minor_stress_impact_gain
			zealous = minor_stress_impact_loss
			generous = minor_stress_impact_loss
			improvident = minor_stress_impact_loss
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				treasury_or_gold < medium_treasury_or_gold_value
			}
			ai_value_modifier = {
				ai_zeal = 1
				ai_compassion = 1
				ai_rationality = 0.5 # Miasma theory may be wrong, but a rational person in the middle ages would probably believe in it
			}
		}
	}

	option = { # What a waste of money
		name = epidemic_events.1020.b
		add_legitimacy_effect = { LEGITIMACY = miniscule_legitimacy_loss }
		stress_impact = {
			compassionate = minor_stress_impact_gain
			diligent = minor_stress_impact_gain
			zealous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 75
			ai_value_modifier = {
				ai_compassion = -1
				ai_rationality = -0.5
			}
		}
	}
}

############################
## Courtiers are self-medicating with leeches
## 1030
## by James Beaumont
############################
epidemic_events.1030 = {
	type = character_event
	title = epidemic_events.1030.t
	desc = epidemic_events.1030.desc
	theme = plague
	override_background = physicians_study
	override_effect_2d = { reference = flies }
	left_portrait = {
		character = root
		animation = shock
		camera = camera_event_very_left
	}
	right_portrait = {
		character = scope:leeched_courtier
		animation = personality_irrational
	}
	cooldown = { years = 15 } 
	trigger = {
		# Only if there's a big plague
		capital_county = {
			any_county_province_epidemic = {
				intensity >= major
				save_temporary_scope_as = plague_to_check
				root = {
					# We don't use is_available, because that blocks diseased characters
					any_courtier_or_guest = {
						is_adult = yes
						is_alive = yes
						is_in_army = no
						is_imprisoned = no
						is_incapable = no
						has_trait = scope:plague_to_check.epidemic_type.epidemic_trait
						save_temporary_scope_as = courtier_temp
					}
				}
			}
		}
		
	}

	immediate = {
		capital_county = {
			random_county_province = {
				limit = {
					any_province_epidemic = {
						intensity >= major
						save_temporary_scope_as = plague_to_check
						root = {
							# We don't use is_available, because that blocks diseased characters
							any_courtier_or_guest = {
								is_adult = yes
								is_alive = yes
								is_in_army = no
								is_imprisoned = no
								is_incapable = no
								has_trait = scope:plague_to_check.epidemic_type.epidemic_trait
							}
						}
					}
				}
				random_province_epidemic = {
					intensity >= major
					save_scope_as = epidemic_scope
				}
			}
		}
		# We don't use is_available, because that blocks diseased characters
		random_courtier_or_guest = {
			limit = {
				is_adult = yes
				is_alive = yes
				is_in_army = no
				is_imprisoned = no
				is_incapable = no
				has_trait = scope:epidemic_scope.epidemic_type.epidemic_trait
			}
			save_scope_as = leeched_courtier
		}
	}

	option = { # Leeches! Leeches for everyone!
		name = epidemic_events.1030.a
		if = {
			limit = {
				has_government = landless_adventurer_government
				is_ai = no
			}
			remove_short_term_gold = { 10 20 }
		}
		random_list = {
			50 = {
				desc = epidemic_events.1030.a.success
				show_chance = no
				send_interface_toast = {
					title = epidemic_events.1030.a.success
					left_icon = root
					right_icon = scope:leeched_courtier
					every_courtier_or_guest = {
						custom = every_infected_courtier_and_guest
						limit = {
							has_trait = scope:epidemic_scope.epidemic_type.epidemic_trait
						}
						add_character_modifier = {
							modifier = medicating_with_leeches_good
							years = 5
						}
						add_opinion = {
							modifier = grateful_opinion
							opinion = 25
							target = root
						}
					}
					if = {
						limit = {
							root = {
								has_trait = scope:epidemic_scope.epidemic_type.epidemic_trait
							}
						}
						add_character_modifier = {
							modifier = medicating_with_leeches_good
							years = 5
						}
					}
					if = {
						limit = { is_landed = yes }
						capital_county = {
							add_county_modifier = {
								modifier = healthy_court
								years = 15
							}
						}
					}
				}
			}
			50 = {
				desc = epidemic_events.1030.a.failure
				show_chance = no
				send_interface_toast = {
					title = epidemic_events.1030.a.failure
					left_icon = root
					right_icon = scope:leeched_courtier
					every_courtier_or_guest = {
						custom = every_infected_courtier_and_guest
						limit = {
							has_trait = scope:epidemic_scope.epidemic_type.epidemic_trait
						}
						add_opinion = {
							modifier = annoyed_opinion
							opinion = -30
							target = root
						}
					}
				}
			}
		}
		stress_impact = {
			paranoid = medium_stress_impact_loss
			impatient = minor_stress_impact_loss
			generous = minor_stress_impact_loss
			patient = minor_stress_impact_gain
			calm = minor_stress_impact_gain
			cynical = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = -0.5
			}
		}
	}

	option = { # Maybe we should trust in the medical experts
		name = epidemic_events.1030.b
		every_courtier_or_guest = {
			custom = every_infected_courtier_and_guest
			limit = { has_trait = scope:epidemic_scope.epidemic_type.epidemic_trait }
			add_opinion = {
				modifier = angry_opinion
				opinion = -15
				target = root
			}
		}
		random = {
			chance = 35
			add_learning_skill = 1
		}
		stress_impact = {
			paranoid = minor_stress_impact_gain
			impatient = minor_stress_impact_gain
			generous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 0.5
			}
		}
	}
}

############################
## Courtiers are becoming flagellants to thwart the plague
## 1040
## by James Beaumont
############################
epidemic_events.1040 = {
	type = character_event
	title = epidemic_events.1040.t
	desc = {
		desc = epidemic_events.1040.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:chaplain = {
						has_trait = flagellant
					}
				}
				desc = epidemic_events.1040.desc.mid.approves
			}
			desc = epidemic_events.1040.desc.mid
		}
	}
	theme = plague
	override_background = { reference = ce1_funeral_pyre }
	override_effect_2d = { reference = smoke }
	left_portrait = {
		character = root
		animation = shock
	}
	right_portrait = {
		character = scope:chaplain
		triggered_animation = {
			trigger = {
				has_trait = flagellant
			}
			animation = happiness
		}
		animation = anger
		camera = camera_event_right_forward
	}
	cooldown = { years = 15 } 
	trigger = {
		is_available_adult = yes
		# Only if there's a big plague
		any_sub_realm_county = {
			any_county_province = {
				OR = {
					county.holder = root
					squared_distance = {
						target = root.capital_province
						value <= squared_distance_medium #250 map-pixels. Roughly one Ireland away (top to bottom).
					}
				}
				any_province_epidemic = {
					intensity >= major
				}
			}
		}
		exists = cp:councillor_court_chaplain
	}

	immediate = {
		get_random_nearby_realm_epidemic = { INTENSITY = major }
		cp:councillor_court_chaplain = { save_scope_as = chaplain }
	}

	option = { # They're clearly just perverts
		name = epidemic_events.1040.a
		if = {
			limit = {
				scope:chaplain = { has_trait = flagellant }
			}
			progress_towards_rival_effect = {
				CHARACTER = scope:chaplain
				REASON = rival_kinkshamed_my_flagellating
				OPINION = default_rival_opinion
			}
		}
		every_sub_realm_county = {
			custom = every_infected_county
			limit = {
				any_county_province = {
					any_province_epidemic = {
						this = scope:epidemic_scope
					}
				}
			}
			add_county_modifier = {
				modifier = persecuted_flagellants
				years = 10
			}
		}
		stress_impact = {
			zealous = minor_stress_impact_gain
			# Nice self-report bro
			flagellant = medium_stress_impact_gain
			deviant = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				add = -50
				has_trait = flagellant
			}
			ai_value_modifier = {
				ai_rationality = 0.5
			}
		}
	}

	option = { # I'm sure this is fine. This is totally fine. No consequences can arise as a result of this.
		name = epidemic_events.1040.b
		every_sub_realm_county = {
			custom = every_infected_county
			limit = {
				any_county_province = {
					any_province_epidemic = {
						this = scope:epidemic_scope
					}
				}
			}
			add_county_modifier = {
				modifier = rampant_flagellants
				years = 10
			}
		}
		stress_impact = {
			flagellant = minor_stress_impact_loss # They're just like me fr!
			sadistic = minor_stress_impact_loss # I love seeing people in pain
			compassionate = minor_stress_impact_gain # I hate seeing people in pain
			cynical = minor_stress_impact_gain # I don't believe flagellating makes god love u
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = -1
			}
		}
	}

	option = { # Maybe they're right!
		name = epidemic_events.1040.c
		every_sub_realm_county = {
			custom = every_infected_county
			limit = {
				any_county_province = {
					any_province_epidemic = {
						this = scope:epidemic_scope
					}
				}
			}
			add_county_modifier = {
				modifier = rampant_flagellants
				years = 10
			}
		}
		if = {
			limit = {
				scope:chaplain = { has_trait = flagellant }
			}
			progress_towards_friend_effect = {
				CHARACTER = scope:chaplain
				REASON = friend_flagellating_together
				OPINION = default_friend_opinion
			}
		}
		if = {
			limit = {
				NOT = { has_trait = flagellant }
			}
			add_trait = flagellant
		}
		stress_impact = {
			base = major_stress_impact_loss
			craven = minor_stress_impact_gain # pain hurts
			arrogant = minor_stress_impact_gain # I don't deserve this
			cynical = minor_stress_impact_gain # I don't believe flagellating makes god love me
		}
		ai_chance = {
			base = 0 # Don't do this unless you're already flagellant
			modifier = {
				add = 50
				has_trait = flagellant
			}
		}
	}
}

############################
## Heretics are claiming it's the end of the world
## 1050
## by James Beaumont
############################
epidemic_events.1050 = {
	type = character_event
	title = epidemic_events.1050.t
	desc = epidemic_events.1050.desc
	theme = plague
	override_background = ce1_funeral_pyre
	override_effect_2d = { reference = smoke }
	left_portrait = {
		character = root
		animation = pondering
		camera = camera_event_center_pointing_right
	}
	right_portrait = {
		character = scope:chaplain
		animation = worry
		camera = camera_event_right_pointing_right
	}
	cooldown = { years = 6 } 
	trigger = {
		is_available = yes
		# Only if there's a big plague
		any_sub_realm_county = {
			any_county_province = {
				OR = {
					county.holder = root
					squared_distance = {
						target = root.capital_province
						value <= squared_distance_medium #250 map-pixels. Roughly one Ireland away (top to bottom).
					}
				}
				any_province_epidemic = {
					intensity >= major
				}
			}
		}
		# You have someone to tell you that this is heresy
		exists = cp:councillor_court_chaplain
	}

	immediate = {
		get_random_nearby_realm_epidemic = { INTENSITY = major }
		cp:councillor_court_chaplain = { save_scope_as = chaplain }
	}

	option = { # Root them out!
		name = epidemic_events.1050.a
		every_sub_realm_county = {
			custom = every_infected_county
			limit = {
				any_county_province = {
					any_province_epidemic = {
						this = scope:epidemic_scope
					}
				}
			}
			add_county_modifier = {
				modifier = apocalyptic_inquisition
				years = 10
			}
		}
		stress_impact = {
			# What if they're right? D:
			zealous = minor_stress_impact_gain
			paranoid = medium_stress_impact_gain
			trusting = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = -1
				ai_zeal = 0.2
			}
		}
	}

	option = { # Go and debate them
		name = epidemic_events.1050.b
		duel = {
			skill = learning
			value = high_skill_rating
			# Success: the plague cult is silenced
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = epidemic_events.1050.b.tt.success
				root = {
					send_interface_toast = {
						title = epidemic_events.1050.b.tt.success
						left_icon = scope:chaplain
						add_legitimacy_effect = { LEGITIMACY = minor_legitimacy_gain }
					}
				}
			}
			# Failure: the plague cult still happens
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = epidemic_events.1050.b.tt.failure
				root = {
					send_interface_toast = {
						title = epidemic_events.1050.b.tt.failure
						left_icon = scope:chaplain
						add_legitimacy_effect = { LEGITIMACY = miniscule_legitimacy_loss }
						every_sub_realm_county = {
							custom = every_infected_county
							limit = {
								any_county_province = {
									any_province_epidemic = {
										this = scope:epidemic_scope
									}
								}
							}
							add_county_modifier = {
								modifier = plague_cult
								years = 10
							}
						}
					}
				}
			}
		}
		stress_impact = {
			cynical = minor_stress_impact_gain
			lazy = minor_stress_impact_gain
			greedy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 0.5
				ai_energy = 0.5
				ai_greed = -1
			}
		}
	}

	option = { # Just ignore it
		name = epidemic_events.1050.c
		add_legitimacy_effect = { LEGITIMACY = miniscule_legitimacy_gain }
		every_sub_realm_county = {
			custom = every_infected_county
			limit = {
				any_county_province = {
					any_province_epidemic = {
						this = scope:epidemic_scope
					}
				}
			}
			add_county_modifier = {
				modifier = plague_cult
				years = 10
			}
		}
		stress_impact = {
			diligent = minor_stress_impact_gain
			just = minor_stress_impact_gain
			arbitrary = minor_stress_impact_gain
			stubborn = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = -1
			}
		}
	}
}

############################
## People blaming the plague on witches/animals event chain
## 1060
## by James Beaumont
############################
epidemic_events.1060 = {
	type = character_event
	title = epidemic_events.1060.t
	window = big_event_window
	override_effect_2d = { reference = rain }
	desc = {
		desc = epidemic_events.1060.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:story_scope = {
						var:blamed_plague_on = flag:cats
					}
				}
				desc = epidemic_events.1060.desc.mid.cats
			}
			triggered_desc = {
				trigger = {
					scope:story_scope = {
						var:blamed_plague_on = flag:dogs
					}
				}
				desc = epidemic_events.1060.desc.mid.dogs
			}
			triggered_desc = {
				trigger = {
					scope:story_scope = {
						var:blamed_plague_on = flag:faith
					}
				}
				desc = epidemic_events.1060.desc.mid.faith
			}
			triggered_desc = {
				trigger = {
					scope:story_scope = {
						var:blamed_plague_on = flag:trait
						NOT = { var:trait_blamed = trait:witch }
					}
				}
				desc = epidemic_events.1060.desc.mid.trait
			}
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:story_scope = {
						var:blamed_plague_on = flag:trait
						var:trait_blamed = trait:witch
					}
				}
				desc = epidemic_events.1060.desc.mid2.witches
			}
			triggered_desc = {
				trigger = {
					scope:story_scope = {
						var:blamed_plague_on = flag:trait
					}
				}
				desc = epidemic_events.1060.desc.mid2.sin
			}
		}
		desc = epidemic_events.1060.desc.outro
	}
	theme = plague
	left_portrait = {
		character = root
		animation = stress
	}
	cooldown = { years = 15 } 
	trigger = {
		is_available_adult = yes
		# Only if there's a big plague
		any_sub_realm_county = {
			any_county_province = {
				OR = {
					county.holder = root
					squared_distance = {
						target = root.capital_province
						value <= squared_distance_medium #250 map-pixels. Roughly one Ireland away (top to bottom).
					}
				}
				any_province_epidemic = {
					intensity >= major
				}
			}
		}
	}

	immediate = {
		get_random_nearby_realm_epidemic = { INTENSITY = major }
		create_story = plague_witch_hunt
		random_owned_story = {
			type = plague_witch_hunt
			save_scope_as = story_scope
			# This is used to keep track of which epidemic is the source of people blaming the plague on some group
			set_variable = {
				name = plague
				value = scope:epidemic_scope
			}
			random_list = {
				30 = {
					# blamed_pague_on determines what or who has been blamed for the plague
					set_variable = {
						name = blamed_plague_on
						value = flag:cats
					}
				}
				20 = {
					trigger = {
						NOT = {
							# No attacking the puppos for Zoroastrians and Canary Islanders
							root.faith.religion = religion:zoroastrianism_religion
							root.faith.religion = religion:north_african_religion
						}
					}
					set_variable = {
						name = blamed_plague_on
						value = flag:dogs
					}
				}
				20 = { # Religious minorities
					root = { select_scapegoat_faith_effect = yes }
					set_variable = {
						name = blamed_plague_on
						value = flag:faith
					}
					set_variable = {
						name = faith_blamed
						value = scope:faith_to_blame
					}
				}
				20 = {
					trigger = {
						trait_is_shunned_or_criminal_in_faith_trigger = {
								TRAIT = witch
								FAITH = root.faith
								GENDER_CHARACTER = root
							}
					}
					set_variable = {
						name = blamed_plague_on
						value = flag:trait
					}
					set_variable = {
						name = trait_blamed
						value = trait:witch
					}
				}
				20 = {
					random_trait_in_category = {
						category = personality
						limit = {
							save_temporary_scope_as = sin_trait_to_check
							root.faith = {
								trait_is_sin = scope:sin_trait_to_check
							}
						}
						save_scope_as = sinful_trait
					}
					set_variable = {
						name = blamed_plague_on
						value = flag:trait
					}
					set_variable = {
						name = trait_blamed
						value = scope:sinful_trait
					}
				}
			}
		}
	}
	
	option = { # Am I not an authority on religious matters? This is heresy!
		name = epidemic_events.1060.c
		reason = piety_level
		trigger = {
			piety_level >= very_high_piety_level
		}
		custom_tooltip = witch_trial_story_tt
		if = {
			limit = {
				scope:story_scope = {
					exists = var:faith_blamed
					var:faith_blamed.religion = religion:judaism_religion
				}
			}
			add_character_modifier = {
				modifier = protected_jews
				years = 10
			}
		}
		every_sub_realm_county = {
			custom = every_infected_county
			limit = {
				any_county_province = {
					any_province_epidemic = {
						this = scope:epidemic_scope
					}
				}
			}
			add_county_modifier = {
				modifier = divine_guidance
				years = 10
			}
		}
		add_piety = medium_piety_gain
		ai_chance = { # This is the objectively best option, the AI should generally pick it if they're not insane
			base = 1000
			ai_value_modifier = {
				ai_rationality = 1
				ai_honor = 1
				ai_zeal = 1
			}
		}
	}

	option = { # How awful!
		name = epidemic_events.1060.a
		custom_tooltip = witch_trial_story_tt
		every_sub_realm_county = {
			custom = every_infected_county
			limit = {
				any_county_province = {
					any_province_epidemic = {
						this = scope:epidemic_scope
					}
				}
			}
			add_county_modifier = {
				modifier = rampant_witch_trials
				years = 10
			}
		}
		stress_impact = {
			diligent = minor_stress_impact_gain
			compassionate = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = -1
				ai_zeal = 0.2
			}
		}
	}

	option = { # Stop this madness in the name of your king!
		name = epidemic_events.1060.b
		custom_tooltip = witch_trial_story_tt
		every_sub_realm_county = {
			custom = every_infected_county
			limit = {
				any_county_province = {
					any_province_epidemic = {
						this = scope:epidemic_scope
					}
				}
			}
			add_county_modifier = {
				modifier = witch_trials_slowed
				years = 10
			}
		}
		stress_impact = {
			zealous = minor_stress_impact_gain
			paranoid = medium_stress_impact_gain
			trusting = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 1
				ai_honor = 0.5
			}
		}
	}
}

############################
## People are burning cats/dogs
## 1061
## by James Beaumont
############################
epidemic_events.1061 = {
	type = character_event
	window = big_event_window
	title = epidemic_events.1061.t
	desc = {
		desc = epidemic_events.1061.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:story_scope = {
						var:blamed_plague_on = flag:cats
					}
				}
				desc = epidemic_events.1061.desc.mid.cats
			}
			triggered_desc = {
				trigger = {
					scope:story_scope = {
						var:blamed_plague_on = flag:dogs
					}
				}
				desc = epidemic_events.1061.desc.mid.dogs
			}
		}
		desc = epidemic_events.1061.desc.outro
	}
	theme = plague
	override_background = { reference = ce1_funeral_pyre }
	override_effect_2d = {
		reference = smoke	
	}
	left_portrait = {
		character = root
		animation = stress
	}
	right_portrait = {
		character = scope:chaplain
		animation = shock
	}
	cooldown = { years = 5 }
	trigger = {
		scope:story_scope = {
			OR = {
				var:blamed_plague_on = flag:cats
				var:blamed_plague_on = flag:dogs
			}
		}
		exists = cp:councillor_court_chaplain
	}

	immediate = {
		cp:councillor_court_chaplain = { save_scope_as = chaplain }
	}

	option = { # I declare cats/dogs to be the royal animal of the realm!
		name = epidemic_events.1061.c
		reason = prestige_level
		trigger = {
			prestige_level >= very_high_prestige_level
		}
		add_legitimacy_effect = { LEGITIMACY = minor_legitimacy_gain }
		if = {
			limit = {
				scope:story_scope = {
					var:blamed_plague_on = flag:cats
				}
			}
			add_character_modifier = {
				modifier = royal_cats
				years = 25
			}
		}
		else_if = {
			limit = {
				var:blamed_plague_on = flag:dogs
			}
			add_character_modifier = {
				modifier = royal_dogs
				years = 25
			}
		}
		every_sub_realm_county = {
			custom = every_infected_county
			limit = {
				any_county_province = {
					any_province_epidemic = {
						this = scope:epidemic_scope
					}
				}
			}
			add_county_modifier = {
				modifier = plague_animals_loose
				years = 5
			}
		}
		custom_tooltip = cats_and_dogs_trial_will_end_tt
		hidden_effect = {
			scope:story_scope = { end_story = yes }
		}
		ai_chance = { # This is the objectively best option, the AI should generally pick it if they're not insane
			base = 1000
			ai_value_modifier = {
				ai_rationality = 1
				ai_honor = 1
				ai_zeal = 1
			}
		}
	}

	option = { # Well, nothing I can do unfortunately
		name = epidemic_events.1061.a
		custom_tooltip = unforseen_consequences_tt
		hidden_effect = {
			random_list = {
				50 = {
					send_interface_toast = {
						title = epidemic_events.1061.a.success
						left_icon = root
						custom_tooltip = burning_animals_does_nothing_tt
					}
				}
				50 = {
					send_interface_toast = {
						title = epidemic_events.1061.a.failure
						left_icon = root
						every_sub_realm_county = {
							custom = every_infected_county
							limit = {
								any_county_province = {
									any_province_epidemic = {
										this = scope:epidemic_scope
									}
								}
							}
							add_county_modifier = {
								modifier = lacking_cats_and_dogs
								years = 10
							}
						}
					}
				}
			}
		}
		stress_impact = {
			diligent = minor_stress_impact_gain
			compassionate = medium_stress_impact_gain
			just = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 1
				ai_energy = -0.5
			}
		}
	}

	option = { # Try to stop them!
		name = epidemic_events.1061.b
		every_sub_realm_county = {
			custom = every_infected_county
			limit = {
				any_county_province = {
					any_province_epidemic = {
						this = scope:epidemic_scope
					}
				}
			}
			add_county_modifier = {
				modifier = plague_animals_loose
				years = 10
			}
		}
		add_legitimacy = miniscule_legitimacy_loss
		stress_impact = {
			lazy = minor_stress_impact_gain
			paranoid = medium_stress_impact_gain
			trusting = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 1
				ai_honor = 1
				ai_energy = 0.5
			}
		}
	}
}

############################
## A skilled cat/dog-catcher offers to round them all up
## 1062
## by James Beaumont
############################
epidemic_events.1062 = {
	type = character_event
	window = big_event_window
	override_background = throne_room
	title = epidemic_events.1062.t
	desc = {
		desc = epidemic_events.1062.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:story_scope = {
						var:blamed_plague_on = flag:cats
					}
				}
				desc = epidemic_events.1062.desc.mid.cats
			}
			triggered_desc = {
				trigger = {
					scope:story_scope = {
						var:blamed_plague_on = flag:dogs
					}
				}
				desc = epidemic_events.1062.desc.mid.dogs
			}
		}
		desc = epidemic_events.1062.desc.outro
	}
	theme = plague
	left_portrait = {
		character = root
		animation = pondering
		camera = camera_event_scheme_center
	}
	center_portrait = {
		character = scope:poacher_1
		animation = hunting_knife_start
		camera = camera_event_scheme_far_right
	}
	right_portrait = {
		character = scope:poacher_2
		animation = bow_idle
	}
	cooldown = { years = 5 }
	trigger = {
		scope:story_scope = {
			OR = {
				var:blamed_plague_on = flag:cats
				var:blamed_plague_on = flag:dogs
			}
		}
	}
	
	immediate = {
		create_character = {
			template = generic_peasant_character
			location = root.location
			culture = root.culture
			faith = root.faith
			gender_female_chance = root_soldier_female_chance
			save_scope_as = poacher_1
			after_creation = {
				add_character_flag = created
			}
		}
		create_character = {
			template = generic_peasant_character
			location = root.location
			culture = root.culture
			faith = root.faith
			gender_female_chance = root_soldier_female_chance
			save_scope_as = poacher_2
			after_creation = {
				add_character_flag = created
			}
		}
	}

	option = { # I declare cats/dogs to be the royal animal of the realm!
		name = epidemic_events.1061.c
		reason = prestige_level
		trigger = {
			prestige_level >= very_high_prestige_level
		}
		add_legitimacy_effect = { LEGITIMACY = minor_legitimacy_gain }
		if = {
			limit = {
				scope:story_scope = {
					var:blamed_plague_on = flag:cats
				}
			}
			add_character_modifier = {
				modifier = royal_cats
				years = 25
			}
		}
		else_if = {
			limit = {
				var:blamed_plague_on = flag:dogs
			}
			add_character_modifier = {
				modifier = royal_dogs
				years = 25
			}
		}
		every_sub_realm_county = {
			custom = every_infected_county
			limit = {
				any_county_province = {
					any_province_epidemic = {
						this = scope:epidemic_scope
					}
				}
			}
			add_county_modifier = {
				modifier = plague_animals_loose
				years = 5
			}
		}
		custom_tooltip = cats_and_dogs_trial_will_end_tt
		hidden_effect = {
			scope:story_scope = { end_story = yes }
		}
		ai_chance = { # This is the objectively best option, the AI should generally pick it if they're not insane
			base = 1000
			ai_value_modifier = {
				ai_rationality = 1
				ai_honor = 1
				ai_zeal = 1
			}
		}
	}

	option = { # Catch them and kill them!
		name = epidemic_events.1062.a
		custom_tooltip = unforseen_consequences_tt
		hidden_effect = {
			random_list = {
				33 = {
					send_interface_toast = {
						title = epidemic_events.1062.a.no_effect
						left_icon = root
					}
				}
				33 = {
					send_interface_toast = {
						title = epidemic_events.1062.a.success
						left_icon = root
						every_sub_realm_county = {
							custom = every_infected_county
							limit = {
								any_county_province = {
									any_province_epidemic = {
										this = scope:epidemic_scope
									}
								}
							}
							add_county_modifier = {
								modifier = lacking_cats_and_dogs_good
								years = 10
							}
						}
					}
				}
				33 = {
					send_interface_toast = {
						title = epidemic_events.1062.a.failure
						left_icon = root
						every_sub_realm_county = {
							custom = every_infected_county
							limit = {
								any_county_province = {
									any_province_epidemic = {
										this = scope:epidemic_scope
									}
								}
							}
							add_county_modifier = {
								modifier = lacking_cats_and_dogs
								years = 10
							}
						}
					}
				}
			}
		}
		stress_impact = {
			diligent = minor_stress_impact_gain
			compassionate = medium_stress_impact_gain
			just = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 1
				ai_energy = -0.5
			}
		}
	}

	option = { # Catch them and bring them to the capital
		name = epidemic_events.1062.b
		custom_tooltip = unforseen_consequences_tt
		hidden_effect = {
			random_list = {
				77 = {
					send_interface_toast = {
						title = epidemic_events.1062.b.no_effect
						left_icon = root
					}
				}
				33 = {
					send_interface_toast = {
						title = epidemic_events.1062.b.failure
						left_icon = root
						capital_county = {
							add_county_modifier = {
								modifier = full_of_rabid_animals
								years = 10
							}
						}
					}
				}
			}
		}
		stress_impact = {
			lazy = minor_stress_impact_gain
			paranoid = medium_stress_impact_gain
			trusting = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 1
				ai_honor = 1
				ai_energy = 0.5
			}
		}
	}
	after = {
		scope:poacher_1 = {
			silent_disappearance_ai_effect = yes
		}
		scope:poacher_2 = {
			silent_disappearance_ai_effect = yes
		}
	}
}

############################
## Repent! Repent! Adopt a virtuous trait like right now!
## 1063
## by James Beaumont
############################
epidemic_events.1063 = {
	type = character_event
	window = big_event_window
	title = epidemic_events.1063.t
	desc = {
		desc = epidemic_events.1063.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:story_scope = {
						var:blamed_plague_on = flag:faith
					}
				}
				desc = epidemic_events.1063.desc.mid.faith
			}
			triggered_desc = {
				trigger = {
					scope:story_scope = {
						var:blamed_plague_on = flag:trait
						exists = var:trait_blamed
						NOT = { var:trait_blamed = trait:witch }
					}
				}
				desc = epidemic_events.1063.desc.mid.sin
			}
			triggered_desc = {
				trigger = {
					scope:story_scope = {
						var:blamed_plague_on = flag:trait
						exists = var:trait_blamed
						var:trait_blamed = trait:witch
					}
				}
				desc = epidemic_events.1063.desc.mid.witch
			}
			triggered_desc = {
				trigger = {
					scope:story_scope = {
						var:blamed_plague_on = flag:cats
					}
				}
				desc = epidemic_events.1063.desc.mid.cats
			}
			triggered_desc = {
				trigger = {
					scope:story_scope = {
						var:blamed_plague_on = flag:dogs
					}
				}
				desc = epidemic_events.1063.desc.mid.dogs
			}
		}
		desc = epidemic_events.1063.desc.outro
	}
	theme = plague
	override_effect_2d = {
		reference = rain	
	}
	left_portrait = {
		character = root
		animation = stress
	}
	right_portrait = {
		character = scope:priest
		animation = debating
	}
	cooldown = { years = 5 }
	trigger = {
		is_available_adult = yes
		# Make sure that ROOT doesn't have literally every virtuous trait in their faith
		any_trait_in_category = {
			category = personality
			save_temporary_scope_as = random_virtue_trait_trigger
			root = {
				NOT = { has_trait = prev }
			}
			root.faith = { trait_is_virtue = scope:random_virtue_trait_trigger }
		}
		# Root has something to repent for
		OR = {
			num_sinful_traits >= 1
			AND = {
				is_witch_trigger = yes
				trait_is_shunned_or_criminal_in_faith_trigger = {
					TRAIT = witch
					FAITH = root.faith
					GENDER_CHARACTER = root
				}
			}
			AND = {
				is_incestuous_trigger = yes
				trait_is_shunned_or_criminal_in_faith_trigger = {
					TRAIT = incestuous
					FAITH = root.faith
					GENDER_CHARACTER = root
				}
			}
			AND = {
				scope:story_scope = {
					var:blamed_plague_on = flag:cats
				}
				has_cat_trigger = yes
			}
			AND = {
				scope:story_scope = {
					var:blamed_plague_on = flag:dogs
				}
				has_dog_trigger = yes
			}
		}
	}

	immediate = {
		# Determine the trait to be super into
		random_trait_in_category = {
			category = personality
			limit = {
				save_temporary_scope_as = random_virtue_trait
				root = {
					NOT = { has_trait = prev }
				}
				root.faith = { trait_is_virtue = scope:random_virtue_trait }
			}
			save_scope_as = virtuous_trait
		}
		
		# Create a priest
		create_character = {
			template = priest_character_template
			location = root.location
			culture = root.culture
			faith = root.faith
			save_scope_as = priest
		}
	}

	option = { # Uhhh actually, he speaks the bullshit!
		name = epidemic_events.1063.c
		reason = piety_level
		trigger = {
			piety_level >= very_high_piety_level
		}
		duel = {
			skill = learning
			value = high_skill_rating
			# Success: you are able to argue you're good actually
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = epidemic_events.1063.c.success
				send_interface_toast = {
					title = epidemic_events.1063.c.success
					left_icon = root
					add_piety = major_piety_gain
					add_legitimacy_effect = { LEGITIMACY = minor_legitimacy_gain }
				}
			}
			# Failure: people are still into it
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = epidemic_events.1063.c.failure
				send_interface_toast = {
					title = epidemic_events.1063.c.failure
					left_icon = root
					add_legitimacy = miniscule_legitimacy_loss
					every_sub_realm_county = {
						custom = every_infected_county
						limit = {
							any_county_province = {
								any_province_epidemic = {
									this = scope:epidemic_scope
								}
							}
						}
						add_county_modifier = {
							modifier = refused_to_repent
							years = 10
						}
					}
				}
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 2
				ai_zeal = 1
			}
		}
	}

	option = { # I repent! I repent!
		name = epidemic_events.1063.a
		if = {
			limit = {
				scope:virtuous_trait = {
					any_opposite_trait = {
						root = { has_trait = prev }
					}
				}
			}
			scope:virtuous_trait = {
				random_opposite_trait = {
					limit = {
						root = { has_trait = prev }
					}
					root = {
						remove_trait = prev
					}
				}
			}
		}
		if = {
			limit = {
				scope:story_scope = {
					var:blamed_plague_on = flag:trait
					exists = var:trait_blamed
					var:trait_blamed = trait:witch
				}
				is_witch_trigger = yes
			}
			remove_witch_secret_or_trait_effect = yes
		}
		add_trait_force_tooltip = scope:virtuous_trait
		stress_impact = {
			base = massive_stress_impact_gain
			lazy = minor_stress_impact_gain
			cynical = minor_stress_impact_gain
			arrogant = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = -1 # This is a very rash decision
				ai_energy = -0.5 # This is a very hard decision
				ai_zeal = 0.5 # This is a very religious decision
			}
		}
	}

	option = { # What a load of bollocks
		name = epidemic_events.1063.b
		every_sub_realm_county = {
			custom = every_infected_county
			limit = {
				any_county_province = {
					any_province_epidemic = {
						this = scope:epidemic_scope
					}
				}
			}
			add_county_modifier = {
				modifier = refused_to_repent
				years = 10
			}
		}
		add_legitimacy = miniscule_legitimacy_loss
		stress_impact = {
			base = minor_stress_impact_gain
			cynical = medium_stress_impact_loss # Am I *really* a sinner tho?
			zealous = medium_stress_impact_gain
			trusting = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 1
				ai_zeal = -0.5
			}
		}
	}
}

############################
## Witch trials
## 1064
## by James Beaumont
############################
epidemic_events.1064 = {
	type = character_event
	window = big_event_window
	title = epidemic_events.1064.t
	desc = {
		desc = epidemic_events.1064.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:story_scope = {
						var:blamed_plague_on = flag:trait
						exists = var:trait_blamed
						NOT = { var:trait_blamed = trait:witch }
					}
				}
				desc = epidemic_events.1064.desc.mid.sin
			}
			triggered_desc = {
				trigger = {
					scope:story_scope = {
						var:blamed_plague_on = flag:trait
						exists = var:trait_blamed
						var:trait_blamed = trait:witch
					}
				}
				desc = epidemic_events.1064.desc.mid.witch
			}
		}
		desc = epidemic_events.1064.desc.outro
	}
	theme = plague
	override_background = { reference = ce1_funeral_pyre }
	override_effect_2d = {
		reference = rain	
	}
	left_portrait = {
		character = root
		animation = worry
	}
	cooldown = { years = 5 }
	trigger = {
		scope:story_scope = {
			var:blamed_plague_on = flag:trait
		}
		any_sub_realm_county = {
			development_level >= 3
			any_county_province = {
				any_province_epidemic = {
					this = scope:epidemic_scope
				}
			}
		}
	}

	immediate = {
		random_sub_realm_county = {
			limit = {
				development_level >= 3
				any_county_province = {
					any_province_epidemic = {
						this = scope:epidemic_scope
					}
				}
			}
			save_scope_as = witch_trial_county
		}
	}

	option = { # Let me make a well-formulated argument that sinning is fine actually
		name = epidemic_events.1064.c
		reason = piety_level
		trigger = {
			piety_level >= high_piety_level
		}
		duel = {
			skill = learning
			value = high_skill_rating
			# Success: you are able to argue you're good actually
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = epidemic_events.1064.c.success
				send_interface_toast = {
					title = epidemic_events.1064.c.success
					left_icon = root
					add_piety = medium_piety_gain
					add_legitimacy_effect = { LEGITIMACY = minor_legitimacy_gain }
				}
			}
			# Failure: people are still into it
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = epidemic_events.1064.c.failure
				send_interface_toast = {
					title = epidemic_events.1064.c.failure
					left_icon = root
					add_legitimacy_effect = { LEGITIMACY = miniscule_legitimacy_loss }
					every_sub_realm_county = {
						custom = every_infected_county
						limit = {
							any_county_province = {
								any_province_epidemic = {
									this = scope:epidemic_scope
								}
							}
						}
						add_county_modifier = {
							modifier = witch_trials_obstructed
							years = 10
						}
					}
				}
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 2
				ai_zeal = 1
			}
		}
	}

	option = { # The witch trials are fine maybe probably
		name = epidemic_events.1064.a
		scope:witch_trial_county = {
			change_development_level = -2
			change_county_control = -100
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = -0.2
				ai_honor = -0.5
				ai_zeal = 0.5
			}
		}
	}

	option = { # Stop it! Stop it right now!
		name = epidemic_events.1064.b
		every_sub_realm_county = {
			custom = every_infected_county
			limit = {
				any_county_province = {
					any_province_epidemic = {
						this = scope:epidemic_scope
					}
				}
			}
			add_county_modifier = {
				modifier = witch_trials_obstructed
				years = 15
			}
		}
		add_legitimacy = miniscule_legitimacy_loss
		stress_impact = {
			trusting = minor_stress_impact_gain
			lazy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 0.2
				ai_honor = 0.5
				ai_zeal = -0.5
			}
		}
	}
}

############################
## Walk of shame
## 1065
## by James Beaumont
############################
scripted_trigger epidemic_events_1065_has_blamed_trait = {
	is_ruler = no
	location = root.location
	OR = {
		has_trait = scope:story_scope.var:trait_blamed
		AND = {
			scope:story_scope = {
				var:blamed_plague_on = flag:trait
				exists = var:trait_blamed
				NOT = { var:trait_blamed = trait:witch }
			}
			is_witch_trigger = yes
		}
	}
}

epidemic_events.1065 = {
	type = character_event
	window = big_event_window
	title = epidemic_events.1065.t
	desc = {
		desc = epidemic_events.1065.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:story_scope = {
						var:blamed_plague_on = flag:trait
						exists = var:trait_blamed
						NOT = { var:trait_blamed = trait:witch }
					}
				}
				desc = epidemic_events.1065.desc.mid.sin
			}
			triggered_desc = {
				trigger = {
					scope:story_scope = {
						var:blamed_plague_on = flag:trait
						exists = var:trait_blamed
						var:trait_blamed = trait:witch
					}
				}
				desc = epidemic_events.1065.desc.mid.witch
			}
		}
		desc = epidemic_events.1065.desc.outro
	}
	theme = plague
	override_background = corridor_night
	left_portrait = {
		character = root
		animation = stress
		camera = camera_torso_scheme_player
	}
	right_portrait = {
		character = scope:shamed_buddy
		animation = shock
		camera = camera_torso_scheme_target
	}
	cooldown = { years = 5 }
	trigger = {
		scope:story_scope = {
			var:blamed_plague_on = flag:trait
		}
		OR = {
			# Prioritise spouses
			any_spouse = {
				epidemic_events_1065_has_blamed_trait = yes
			}
			# Family members
			any_close_or_extended_family_member = {
				epidemic_events_1065_has_blamed_trait = yes
			}
			# Lovers
			any_relation = {
				type = lover
				epidemic_events_1065_has_blamed_trait = yes
			}
			# Friends
			any_relation = {
				type = friend
				epidemic_events_1065_has_blamed_trait = yes
			}
			# Concubines
			any_consort = {
				epidemic_events_1065_has_blamed_trait = yes
			}
		}
	}

	immediate = {
		if = {
			limit = {
				any_spouse = {
					epidemic_events_1065_has_blamed_trait = yes
				}
			}
			random_spouse = {
				limit = {
					epidemic_events_1065_has_blamed_trait = yes
				}
				save_scope_as = shamed_buddy
			}
		}
		else_if = {
			limit = {
				any_close_or_extended_family_member = {
					epidemic_events_1065_has_blamed_trait = yes
				}
			}
			random_close_or_extended_family_member = {
				limit = {
					epidemic_events_1065_has_blamed_trait = yes
				}
				save_scope_as = shamed_buddy
			}
		}
		else_if = {
			limit = {
				any_relation = {
					type = lover
					epidemic_events_1065_has_blamed_trait = yes
				}
			}
			random_relation = {
				type = lover
				limit = {
					epidemic_events_1065_has_blamed_trait = yes
				}
				save_scope_as = shamed_buddy
			}
		}
		else_if = {
			limit = {
				any_relation = {
					type = friend
					epidemic_events_1065_has_blamed_trait = yes
				}
			}
			random_relation = {
				type = friend
				limit = {
					epidemic_events_1065_has_blamed_trait = yes
				}
				save_scope_as = shamed_buddy
			}
		}
		else_if = {
			limit = {
				any_consort = {
					epidemic_events_1065_has_blamed_trait = yes
				}
			}
			random_consort = {
				limit = {
					epidemic_events_1065_has_blamed_trait = yes
				}
				save_scope_as = shamed_buddy
			}
		}
	}

	option = { # I will take your place, buddy
		name = epidemic_events.1065.c
		trigger = {
			has_trait = august
		}
		add_legitimacy_effect = { LEGITIMACY = miniscule_legitimacy_loss }
		increase_wounds_no_death_effect = { REASON = beaten }
		upgrade_to_friend_effect = {
			CHARACTER = scope:shamed_buddy
			REASON = friend_walk_of_shame
		}
		stress_impact = {
			base = medium_stress_impact_gain
			arrogant = minor_stress_impact_gain
			humble = medium_stress_impact_loss
			compassionate = medium_stress_impact_loss
			gregarious = minor_stress_impact_loss
			eccentric = minor_stress_impact_loss
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = -2
				ai_sociability = 1
				ai_zeal = 1
			}
		}
	}

	option = { # Just do it, buddy
		name = epidemic_events.1065.a
		add_legitimacy_effect = { LEGITIMACY = miniscule_legitimacy_loss }
		scope:shamed_buddy = {
			add_prestige = massive_prestige_loss
			hidden_effect = {
				increase_wounds_no_death_effect = { REASON = beaten }
				increase_wounds_no_death_effect = { REASON = beaten }
			}
			show_as_tooltip = {
				add_trait = wounded_2
			}
		}
		stress_impact = {
			just = minor_stress_impact_gain
			gregarious = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = -0.2
				ai_honor = -0.5
				ai_sociability = -1
				ai_zeal = 0.5
			}
		}
	}

	option = { # Absolutely not!
		name = epidemic_events.1065.b
		every_sub_realm_county = {
			custom = every_infected_county
			limit = {
				any_county_province = {
					any_province_epidemic = {
						this = scope:epidemic_scope
					}
				}
			}
			add_county_modifier = {
				modifier = witch_trials_obstructed
				years = 10
			}
		}
		stress_impact = {
			trusting = minor_stress_impact_gain
			lazy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 0.2
				ai_honor = 0.5
				ai_sociability = 0.5
				ai_zeal = -0.5
			}
		}
	}
}

############################
## Peasants are forcing minorities out
## 1066-1067
## by James Beaumont
############################
epidemic_events.1066 = {
	type = character_event
	window = big_event_window
	title = epidemic_events.1066.t
	desc = epidemic_events.1066.desc
	theme = plague
	override_background = burning_building
	override_effect_2d = { reference = smoke }
	left_portrait = {
		character = root
		animation = grief
	}
	trigger = {
		scope:story_scope = {
			var:blamed_plague_on = flag:faith
		}
	}
	cooldown = { years = 5 }

	immediate = {
		add_legitimacy = miniscule_legitimacy_loss
	}

	option = { # Offer minorities asylum in the capital
		name = epidemic_events.1066.c
		trigger = {
			has_trait = administrator
		}
		every_sub_realm_county = {
			custom = every_infected_county
			limit = {
				any_county_province = {
					any_province_epidemic = {
						this = scope:epidemic_scope
					}
				}
				this != root.capital_county
			}
			change_development_progress = -50
		}
		capital_county = {
			change_development_progress_with_overflow = 50
			add_county_modifier = {
				modifier = persecuted_minorities_protected
				years = 15
			}
		}
		stress_impact = {
			zealous = minor_stress_impact_gain # I'm a fundementalist
			callous = minor_stress_impact_gain
			arbitrary = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 1
				ai_compassion = 1
				ai_zeal = -0.5
			}
		}
	}

	option = { # Forbid the expulsion
		name = epidemic_events.1066.a
		every_sub_realm_county = {
			custom = every_infected_county
			limit = {
				any_county_province = {
					any_province_epidemic = {
						this = scope:epidemic_scope
					}
				}
				this != root.capital_county
			}
			change_county_control = major_county_control_loss
			add_county_modifier = {
				modifier = minority_persecution_forbidden
				years = 10
			}
			if = {
				limit = {
					faith = scope:faith_blamed
				}
				random = {
					chance = 35
					set_county_faith = root.faith 
				}
			}
		}
		stress_impact = {
			zealous = minor_stress_impact_gain # I'm a fundementalist
			callous = minor_stress_impact_gain
			arbitrary = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 0.5
				ai_compassion = 1
				ai_zeal = -1
			}
		}
	}

	option = { # Oof, sure fine, let them be expelled
		name = epidemic_events.1066.b
		every_sub_realm_county = {
			custom = every_infected_county
			limit = {
				any_county_province = {
					any_province_epidemic = {
						this = scope:epidemic_scope
					}
				}
			}
			change_development_progress = -50
			add_county_modifier = {
				modifier = persecuted_minorities_expelled
				years = 10
			}
		}
		hidden_effect = {
			save_scope_as = bigoted_ruler_that_everyone_hates
			if = {
				limit = {
					any_neighboring_and_across_water_top_liege_realm_owner = {
						is_alive = yes
						any_character_to_title_neighboring_and_across_water_county = {
							holder.top_liege = scope:bigoted_ruler_that_everyone_hates
						}
					}
				}
				random_neighboring_and_across_water_top_liege_realm_owner = {
					limit = {
						is_alive = yes
						any_character_to_title_neighboring_and_across_water_county = {
							holder.top_liege = scope:bigoted_ruler_that_everyone_hates
						}
					}
					trigger_event = {
						id = epidemic_events.1067
						days = { 3 10 }
					}
				}
			}
		}
		stress_impact = {
			just = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
			diligent = minor_stress_impact_gain
			gallant = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = -1
				ai_compassion = -1
				ai_honor = -0.5
				ai_zeal = 0.5
			}
		}
	}
}

# Response event for a neighbouring ruler
epidemic_events.1067 = {
	type = character_event
	title = epidemic_events.1067.t
	desc = epidemic_events.1067.desc
	theme = plague
	left_portrait = {
		character = root
		animation = thinking
	}

	option = { # Funnel them all into the capital
		name = epidemic_events.1067.c
		trigger = {
			has_trait = administrator
		}
		capital_county = {
			change_development_progress_with_overflow = 150
			add_county_modifier = {
				modifier = plague_minorities_sanctuary_boosted
				years = 10
			}
		}
		stress_impact = {
			paranoid = minor_stress_impact_gain
			zealous = minor_stress_impact_gain
			callous = minor_stress_impact_gain
			arbitrary = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 1
				ai_compassion = 1
				ai_zeal = -0.5
			}
		}
	}

	option = { # Oh cool, welcome!
		name = epidemic_events.1067.a
		scope:bigoted_ruler_that_everyone_hates = {
			every_character_to_title_neighboring_and_across_water_county = {
				custom = every_bordering_county
				change_development_progress = 50
				add_county_modifier = {
					modifier = plague_minorities_sanctuary
					years = 10
				}
			}
		}
		stress_impact = {
			paranoid = minor_stress_impact_gain # Foreigners? They could be spies!
			zealous = minor_stress_impact_gain # I'm a fundementalist
			callous = minor_stress_impact_gain
			arbitrary = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 0.5
				ai_compassion = 1
				ai_zeal = -1
			}
		}
	}

	option = { # Well, they can't come 'ere
		name = epidemic_events.1067.b
		stress_impact = {
			just = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
			diligent = minor_stress_impact_gain
			greedy = minor_stress_impact_gain
			gallant = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = -1
				ai_compassion = -1
				ai_honor = -0.5
				ai_zeal = 0.5
			}
		}
	}
}

############################
## Nobles are struggling to get loans
## 1068
## by James Beaumont
############################
epidemic_events.1068 = {
	type = character_event
	window = big_event_window
	title = epidemic_events.1068.t
	desc = epidemic_events.1068.desc
	theme = plague
	override_background = throne_room
	left_portrait = {
		character = root
		animation = stunned
	}
	right_portrait = {
		character = scope:loneless_vassal
		animation = obsequious_bow
		triggered_outfit = {
			remove_default_outfit = no
			outfit_tags = { beggar_rags }
		}
	}
	cooldown = { years = 5 }
	trigger = {
		scope:story_scope = {
			var:blamed_plague_on = flag:faith
		}
		any_vassal = {
			is_landed_or_landless_administrative = yes # No unlanded HoFs
			exists = capital_county # No barons
			highest_held_title_tier >= tier_county
			any_sub_realm_county = {
				any_county_province_epidemic = {
					this = scope:epidemic_scope
				}
			}
		}
	}

	immediate = {
		random_vassal = {
			limit = {
				is_landed_or_landless_administrative = yes
				exists = capital_county
				highest_held_title_tier >= tier_county
				any_sub_realm_county = {
					any_county_province_epidemic = {
						this = scope:epidemic_scope
					}
				}
			}
			weight = {
				base = 1
				# Get guys who would likely wanna take loans
				modifier = {
					add = 10
					gold <= 0
				}
				modifier = {
					add = 10
					gold <= minor_gold_value
				}
				modifier = {
					add = 5
					OR = {
						has_trait = greedy
						has_trait = profligate
					}
				}
			}
			save_scope_as = loneless_vassal
		}
	}

	option = { # Try to make your vassal's realm a safe place for them
		name = epidemic_events.1068.a
		progress_towards_friend_effect = {
			CHARACTER = scope:loneless_vassal
			OPINION = default_friend_opinion
			REASON = friend_plague_financial_help
		}
		scope:loneless_vassal = {
			every_sub_realm_county = {
				custom = all_of_vassals_holding
				change_development_progress = 15
				add_county_modifier = {
					modifier = persecuted_minorities_financial_sanctuary
					years = 10
				}
			}
		}
		stress_impact = {
			zealous = minor_stress_impact_gain # I'm a fundementalist
			callous = minor_stress_impact_gain
			arbitrary = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 0.5
				ai_compassion = 1
				ai_zeal = -1
			}
		}
	}

	option = { # I'll offer you a loan!
		name = epidemic_events.1068.b
		progress_towards_friend_effect = {
			CHARACTER = scope:loneless_vassal
			OPINION = default_friend_opinion
			REASON = friend_plague_financial_help
		}
		if = {
			limit = {
				scope:loneless_vassal = {
					vassal_contract_obligation_level_can_be_increased = feudal_government_taxes
				}
			}
			scope:loneless_vassal = {
				vassal_contract_increase_obligation_level = feudal_government_taxes
			}
		}
		else = {
			add_hook = {
				target = scope:loneless_vassal
				type = indebted_hook
			}
		}
		pay_short_term_gold = {
			target = scope:loneless_vassal
			gold = {
				if = {
					limit = {
						scope:loneless_vassal.gold < 0
					}
					add = scope:loneless_vassal.gold
					multiply = -1
				}
				min = tiny_gold_value
			}
		}
		stress_impact = {
			just = minor_stress_impact_gain
			compassionate = minor_stress_impact_gain
			generous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				gold < major_gold_value
			}
			ai_value_modifier = {
				ai_rationality = 1
				ai_greed = 1
				ai_honor = -0.5
				ai_zeal = 0.5
			}
		}
	}

	option = { # Not my fuckin problem
		name = epidemic_events.1068.c
		add_legitimacy_effect = { LEGITIMACY = minor_legitimacy_gain }
		progress_towards_rival_effect = {
			CHARACTER = scope:loneless_vassal
			OPINION = 0
			REASON = rival_refused_to_help_my_loans
		}
		stress_impact = {
			lazy = minor_stress_impact_loss
			just = minor_stress_impact_gain
			compassionate = minor_stress_impact_gain
			generous = minor_stress_impact_gain
			greedy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_energy = -1
				ai_greed = 1
				ai_honor = -0.5
				ai_zeal = 0.5
			}
		}
	}
}

############################
## Informed of plague showing up // Plague notification event
## 1100
## by James Beaumont
############################
epidemic_events.1100 = {
	type = character_event
	title = epidemic_events.1100.t
	desc = {
		first_valid = { # How bad is the disease?
			triggered_desc = {
				trigger = {
					scope:epidemic = {
						outbreak_intensity = major
					}
				}
				desc = epidemic_events.1100.desc.intro.major
			}
			desc = epidemic_events.1100.desc.intro.fallback
		}
		first_valid = { # How important is the county it appeared in?
			triggered_desc = {
				trigger = {
					scope:infected_county = {
						any_county_province = {
							barony = { is_holy_site_of = root.faith }
						}
					}
				}
				desc = epidemic_events.1100.desc.intro2.holy_site
			}
			triggered_desc = {
				trigger = {
					scope:infected_county = {
						OR = {
							this = root.capital_county
							development_level >= 20
						}
					}
				}
				desc = epidemic_events.1100.desc.intro2.cool_place
			}
			desc = epidemic_events.1100.desc.intro2.backwater
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:epidemic = {
						epidemic_type.epidemic_trait = trait:typhus
					}
				}
				desc = epidemic_events.1100.desc.mid.typhus
			}
			triggered_desc = {
				trigger = {
					scope:epidemic = {
						epidemic_type.epidemic_trait = trait:bubonic_plague
					}
				}
				desc = epidemic_events.1100.desc.mid.bubonic_plague
			}
			triggered_desc = {
				trigger = {
					scope:epidemic = {
						epidemic_type.epidemic_trait = trait:smallpox
					}
				}
				desc = epidemic_events.1100.desc.mid.smallpox
			}
			triggered_desc = {
				trigger = {
					scope:epidemic = {
						epidemic_type.epidemic_trait = trait:measles
					}
				}
				desc = epidemic_events.1100.desc.mid.measles
			}
			triggered_desc = {
				trigger = {
					scope:epidemic = {
						epidemic_type.epidemic_trait = trait:dysentery
					}
				}
				desc = epidemic_events.1100.desc.mid.dysentery
			}
			triggered_desc = {
				trigger = {
					scope:epidemic = {
						epidemic_type.epidemic_trait = trait:ergotism
					}
				}
				desc = epidemic_events.1100.desc.mid.ergotism
			}
			triggered_desc = {
				trigger = {
					scope:epidemic = {
						epidemic_type.epidemic_trait = trait:consumption
					}
				}
				desc = epidemic_events.1100.desc.mid.consumption
			}
			desc = epidemic_events.1100.desc.mid.fallback
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:infected_county = root.capital_county
				}
				desc = epidemic_events.1100.desc.outro.capital
			}
			desc = epidemic_events.1100.desc.outro
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:epidemic = {
						outbreak_intensity = major
					}
				}
				desc = epidemic_events.1100.desc.mid2.major
			}
			desc = epidemic_events.1100.desc.mid2.fallback
		}
	}
	theme = plague
	override_effect_2d = {
		reference = smoke
	}
	left_portrait = {
		character = root
		animation = stress
	}

	trigger = {
		is_available = yes
		NOR = { # Don't repeatedly inform the player of the same plague over and over
			is_target_in_variable_list = {
				name = plagues_notified
				target = scope:epidemic
			}
			scope:epidemic = {
				epidemic_type.epidemic_trait = trait:bubonic_plague
			}
		}
	}

	immediate = {
		scope:province.county = {
			save_scope_as = infected_county
		}
		add_to_variable_list = {
			name = plagues_notified
			target = scope:epidemic
		}
		# LEGITIMACY LOSS FROM OUTBREAK
		if = {
			limit = { scope:infected_county.holder ?= this }
			show_as_tooltip = {
				scope:epidemic = {
					epidemic_outbreak_legitimacy_effect = { PROVINCE = scope:province }
				}
			}
		}
		add_plague_county_modifiers = yes
	}

	option = { # Damn :pensive:
		name = {
			text = {
				first_valid = {
					random_valid = {
						triggered_desc = {
							trigger = {
								has_trait = scope:epidemic.epidemic_type.epidemic_trait
							}
							desc = epidemic_events.1100.a.already_has_it
						}
						triggered_desc = {
							trigger = {
								has_trait = compassionate
							}
							desc = epidemic_events.1100.a.compassionate
						}
						triggered_desc = {
							trigger = {
								has_trait = eccentric
							}
							desc = epidemic_events.1100.a.eccentric
						}
						triggered_desc = {
							trigger = {
								is_cannibal_trigger = yes
							}
							desc = epidemic_events.1100.a.cannibal
						}
						triggered_desc = {
							trigger = {
								OR = {
									has_trait = callous
									has_trait = sadistic
								}
							}
							desc = epidemic_events.1100.a.callous
						}
						triggered_desc = {
							trigger = {
								OR = {
									has_trait = diligent
									has_trait = just
								}
							}
							desc = epidemic_events.1100.a.diligent
						}
						triggered_desc = {
							trigger = {
								OR = {
									has_trait = paranoid
									has_trait = craven
								}
							}
							desc = epidemic_events.1100.a.paranoid
						}
						triggered_desc = {
							trigger = {
								OR = {
									has_trait = brave
									has_trait = arrogant
								}
							}
							desc = epidemic_events.1100.a.brave
						}
						triggered_desc = {
							trigger = {
								has_trait = zealous
							}
							desc = epidemic_events.1100.a.zealous
						}
					}
					desc = epidemic_events.1100.a
				}
			}
		}
		
		if = { # Admin governors lose a bit of trait XP if they don't try to do something
			limit = {
				is_governor = yes
				has_trait = governor
			}
			increase_governance_effect = { VALUE = -2 }
		}
		
		ai_chance = {
			base = 100
		}
	}

	option = { # Call the physician!
		name = epidemic_events.1100.b
		trigger = {
			exists = court_position:court_physician_court_position
		}
		reason = physician
		custom_tooltip = {
			text = physician_will_help_epidemic_tt
			court_position:court_physician_court_position = { save_scope_as = physician }
			trigger_event = {
				id = physician_epidemic_events.1020
				days = 3
			}
		}
		ai_chance = {
			base = 100
		}
	}

	option = { # Call a physician!
		name = epidemic_events.1100.c
		trigger = {
			NOT = { exists = court_position:court_physician_court_position }
			OR = { # prevent stacking treatment
				top_liege = this
				is_ai = no
			}
		}
		custom_tooltip = {
			text = look_for_physician_epidemic_tt
			add_character_flag = { flag = seeking_epidemic_treatment days = 30 }
			trigger_event = {
				id = health.3001 days = { court_physician_search_min court_physician_search_max }
			}
		}
		ai_chance = {
			base = 100
		}
	}
}

#Informed of an apocalyptic plague
epidemic_events.1101 = {
	type = character_event
	window = fullscreen_event
	title = epidemic_events.1100.t
	desc = {
		desc = epidemic_events.1100.desc.intro.apocalyptic
		first_valid = { # How important is the county it appeared in?
			triggered_desc = {
				trigger = {
					scope:infected_county = {
						any_county_province = {
							barony = { is_holy_site_of = root.faith }
						}
					}
				}
				desc = epidemic_events.1100.desc.intro2.holy_site
			}
			triggered_desc = {
				trigger = {
					scope:infected_county = {
						OR = {
							this = root.capital_county
							development_level >= 20
						}
					}
				}
				desc = epidemic_events.1100.desc.intro2.cool_place
			}
			desc = epidemic_events.1100.desc.intro2.backwater
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:epidemic = {
						epidemic_type.epidemic_trait = trait:typhus
					}
				}
				desc = epidemic_events.1100.desc.mid.typhus
			}
			triggered_desc = {
				trigger = {
					scope:epidemic = {
						epidemic_type.epidemic_trait = trait:bubonic_plague
					}
				}
				desc = epidemic_events.1100.desc.mid.bubonic_plague
			}
			triggered_desc = {
				trigger = {
					scope:epidemic = {
						epidemic_type.epidemic_trait = trait:smallpox
					}
				}
				desc = epidemic_events.1100.desc.mid.smallpox
			}
			triggered_desc = {
				trigger = {
					scope:epidemic = {
						epidemic_type.epidemic_trait = trait:measles
					}
				}
				desc = epidemic_events.1100.desc.mid.measles
			}
			triggered_desc = {
				trigger = {
					scope:epidemic = {
						epidemic_type.epidemic_trait = trait:dysentery
					}
				}
				desc = epidemic_events.1100.desc.mid.dysentery
			}
			triggered_desc = {
				trigger = {
					scope:epidemic = {
						epidemic_type.epidemic_trait = trait:ergotism
					}
				}
				desc = epidemic_events.1100.desc.mid.ergotism
			}
			triggered_desc = {
				trigger = {
					scope:epidemic = {
						epidemic_type.epidemic_trait = trait:consumption
					}
				}
				desc = epidemic_events.1100.desc.mid.consumption
			}
			desc = epidemic_events.1100.desc.mid.fallback
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:infected_county = root.capital_county
				}
				desc = epidemic_events.1100.desc.outro.capital
			}
			desc = epidemic_events.1100.desc.outro
		}
		desc = epidemic_events.1100.desc.mid2.apocalyptic
	}
	theme = plague
	override_background = { reference = ce1_fullscreen_apocalyptic }

	trigger = {
		is_available = yes
		OR = {
			AND = {
				has_dlc_feature = legends_of_the_dead
				NOR = { # Don't repeatedly inform the player of the same plague over and over
					is_target_in_variable_list = {
						name = plagues_notified
						target = scope:epidemic
					}
					# There's a special event for the Black Plague
					scope:epidemic = {
						epidemic_type.epidemic_trait = trait:bubonic_plague
					}
				}
			}
			AND = {
				NOT = { # Don't repeatedly inform the player of the same plague over and over
					is_target_in_variable_list = {
						name = plagues_notified
						target = scope:epidemic
					}
				}
				NOT = { has_dlc_feature = legends_of_the_dead }
			}
		}
	}

	immediate = {
		play_music_cue = apocalyptic_plague
		scope:province.county = {
			save_scope_as = infected_county
		}
		add_to_variable_list = {
			name = plagues_notified
			target = scope:epidemic
		}
		# LEGITIMACY LOSS FROM OUTBREAK
		if = {
			limit = { scope:infected_county.holder ?= this }
			show_as_tooltip = {
				scope:epidemic = {
					epidemic_outbreak_legitimacy_effect = { PROVINCE = scope:province }
				}
			}
		}
		add_plague_county_modifiers = yes
	}

	option = { # Damn :pensive:
		name = {
			text = {
				first_valid = {
					random_valid = {
						triggered_desc = {
							trigger = {
								has_trait = scope:epidemic.epidemic_type.epidemic_trait
							}
							desc = epidemic_events.1100.a.already_has_it
						}
						triggered_desc = {
							trigger = {
								has_trait = compassionate
							}
							desc = epidemic_events.1100.a.compassionate
						}
						triggered_desc = {
							trigger = {
								has_trait = eccentric
							}
							desc = epidemic_events.1100.a.eccentric
						}
						triggered_desc = {
							trigger = {
								is_cannibal_trigger = yes
							}
							desc = epidemic_events.1100.a.cannibal
						}
						triggered_desc = {
							trigger = {
								OR = {
									has_trait = callous
									has_trait = sadistic
								}
							}
							desc = epidemic_events.1100.a.callous
						}
						triggered_desc = {
							trigger = {
								OR = {
									has_trait = diligent
									has_trait = just
								}
							}
							desc = epidemic_events.1100.a.diligent
						}
						triggered_desc = {
							trigger = {
								OR = {
									has_trait = paranoid
									has_trait = craven
								}
							}
							desc = epidemic_events.1100.a.paranoid
						}
						triggered_desc = {
							trigger = {
								OR = {
									has_trait = brave
									has_trait = arrogant
								}
							}
							desc = epidemic_events.1100.a.brave
						}
						triggered_desc = {
							trigger = {
								has_trait = zealous
							}
							desc = epidemic_events.1100.a.zealous
						}
					}
					desc = epidemic_events.1100.a
				}
			}
		}

		ai_chance = {
			base = 100
		}
	}

	option = { # Call the physician!
		name = epidemic_events.1100.b
		trigger = {
			OR = { # prevent stacking treatment
				top_liege = this
				is_ai = no
			}
		}
		if = {
			limit = {
				NOT = { exists = court_position:court_physician_court_position }
			}
			custom_tooltip = {
				text = look_for_physician_epidemic_tt
				add_character_flag = { flag = seeking_epidemic_treatment days = 30 }
				trigger_event = {
					id = health.3001 days = { court_physician_search_min court_physician_search_max }
				}
			}
		}
		else = {
			custom_tooltip = {
				text = physician_will_help_epidemic_tt
				court_position:court_physician_court_position = { save_scope_as = physician }
				trigger_event = {
					id = physician_epidemic_events.1020
					days = 3
				}
			}
		}
		ai_chance = {
			base = 100
		}
	}
}

############################
## Common graves for your graveyard?
## 1110
## by James Beaumont
############################
epidemic_events.1110 = {
	type = character_event
	title = epidemic_events.1110.t
	desc = epidemic_events.1110.desc
	theme = plague
	left_portrait = {
		character = root
		animation = pondering
		camera = camera_event_left_away_3_4
	}
	right_portrait = {
		character = scope:chaplain
		animation = beg
		camera = camera_event_right_away
	}
	override_effect_2d = { reference = flies }

	cooldown = { years = 10 }

	trigger = {
		is_available = yes
		any_held_title = {
			title_tier = county
			any_county_province = {
				has_building_or_higher = burial_site_01
			}
		}
		# Only if there's a big plague
		any_sub_realm_county = {
			any_county_province = {
				OR = {
					county.holder = root
					squared_distance = {
						target = root.capital_province
						value <= squared_distance_medium #250 map-pixels. Roughly one Ireland away (top to bottom).
					}
				}
				any_province_epidemic = {
					intensity >= major
				}
			}
		}
		any_courtier_or_guest = {
			is_available_ai_adult = yes
		}
	}

	immediate = {
		random_held_title = {
			title_tier = county
			limit = {
				any_county_province = {
					has_building_or_higher = burial_site_01
				}
			}
			save_scope_as = graveyard_county
		}
		get_random_nearby_realm_epidemic = { INTENSITY = major }
		if = {
			limit = {
				exists = cp:councillor_court_chaplain
				cp:councillor_court_chaplain = {
					is_available_ai_adult = yes
				}
			}
			cp:councillor_court_chaplain = { save_scope_as = chaplain }
		}
		else = {
			random_courtier_or_guest = {
				limit = {
					is_available_ai_adult = yes
				}
				save_scope_as = chaplain
			}
		}
	}

	option = { # Okay, let's make room for common graves :eyeroll:
		name = epidemic_events.1110.a
		scope:graveyard_county = {
			add_county_modifier = {
				modifier = ce1_common_graves
				years = 15
			}
		}
		stress_impact = {
			arrogant = minor_stress_impact_gain
			callous = minor_stress_impact_gain
			sadistic = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = 1
				ai_rationality = 1
				ai_vengefulness = -0.5
			}
		}
	}

	option = { # Lol, no shot I'm ruining my graveyard with commoners
		name = epidemic_events.1110.b
		add_legitimacy_effect = { LEGITIMACY = minor_legitimacy_gain }
		add_prestige = medium_prestige_gain
		every_sub_realm_county = {
			custom = every_infected_county
			limit = {
				any_county_province = {
					any_province_epidemic = {
						this = scope:epidemic_scope
					}
				}
			}
			add_county_modifier = {
				modifier = ce1_bodies_in_the_street
				years = 15
			}
		}
		stress_impact = {
			compassionate = minor_stress_impact_gain
			diligent = minor_stress_impact_gain
			just = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = -1
				ai_rationality = -1
				ai_vengefulness = 0.5
			}
		}
	}
}

############################
## Catapult the plague corpses
## 1120
## by James Beaumont
############################
epidemic_events.1120 = {
	type = character_event
	title = epidemic_events.1120.t
	desc = epidemic_events.1120.desc
	theme = plague
	override_background = { reference = ce1_funeral_pyre }
	left_portrait = {
		character = root
		animation = thinking
	}

	trigger = {
		is_available_adult_or_is_commanding = yes
		# Catapults only
		culture = { has_innovation = innovation_catapult }
		# Only if you're leading the army yourself
		scope:army = {
			army_commander = root
		}
		#No sea provinces
		location = { is_sea_province = no }
		# Only do it to people you're at war with
		OR = {
			location.county.holder ?= { is_at_war_with = root }
			location.county.holder ?= {
				any_liege_or_above = {
					is_at_war_with = root
				}
			}
		}
		# Only do it if you have a plague in your realm that is not present at the location
		any_realm_county = {
			title_province = {
				any_province_epidemic = {
					save_temporary_scope_as = epidemic_temp_scope
					root.location.county.title_province = {
						NOT = {
							any_province_epidemic = { this = scope:epidemic_temp_scope }
						}
					}
				}
			}
		}
		# Check if you have a reason to hate this person
		OR = {
			has_relation_rival = location.county.holder
			has_trait = sadistic
			has_trait = torturer
		}
	}

	cooldown = { years = 100 } # This shouldn't be too common

	immediate = {
		root = { save_scope_as = corpse_flinger }
		location.county.holder = { save_scope_as = corpse_flingee }
		location.county = { save_scope_as = flung_corpse_location }
		# Get the epidemic
		random_realm_county = {
			limit = {
				title_province = {
					any_province_epidemic = {
						save_temporary_scope_as = epidemic_temp_scope
						root.location.county.title_province = {
							NOT = {
								any_province_epidemic = { this = scope:epidemic_temp_scope }
							}
						}
					}
				}
			}
			title_province = {
				random_province_epidemic = {
					limit = {
						save_temporary_scope_as = epidemic_temp_scope
						root.location.county.title_province = {
							NOT = {
								any_province_epidemic = { this = scope:epidemic_temp_scope }
							}
						}
					}
					save_scope_as = epidemic_scope
				}
			}
		}
	}

	option = { # Fuckinnnnnnnn do it
		name = epidemic_events.1120.a
		hidden_effect = {
			if = {
				limit = {
					scope:corpse_flingee = { location.county = scope:flung_corpse_location }
				}
				scope:corpse_flingee = {
					trigger_event = epidemic_events.1121
				}
			}
			else = {
				scope:flung_corpse_location = {
					add_county_modifier = {
						modifier = ce1_siege_corpse
						years = 15
					}
				}
			}
		}
		create_character_memory = {
			type = ce1_flung_corpse
			participants = {
				flingee = scope:corpse_flingee
			}
		}
		show_as_tooltip = {
			scope:flung_corpse_location = {
				add_county_modifier = {
					modifier = ce1_siege_corpse
					years = 15
				}
			}
		}
		stress_impact = {
			compassionate = major_stress_impact_gain
			just = medium_stress_impact_gain
			forgiving = medium_stress_impact_gain
			calm = minor_stress_impact_gain
			humble = minor_stress_impact_gain
			honest = minor_stress_impact_gain
			zealous = minor_stress_impact_gain
			trusting = minor_stress_impact_gain
			vengeful = minor_stress_impact_loss
			callous = minor_stress_impact_loss
			sadistic = medium_stress_impact_loss
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = -1
				ai_zeal = -1
				ai_compassion = -1
				ai_vengefulness = 2
			}
		}
	}

	option = { # Fuckinnnnnnnn don't
		name = epidemic_events.1120.b
		stress_impact = {
			torturer = minor_stress_impact_gain
			vengeful = minor_stress_impact_gain
			sadistic = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = 1
				ai_zeal = 1
				ai_compassion = 1
				ai_vengefulness = -2
			}
		}
	}
}

# The enemy recieves the "gift"
epidemic_events.1121 = {
	type = character_event
	title = epidemic_events.1121.t
	desc = epidemic_events.1121.desc
	theme = plague
	left_portrait = {
		character = root
		animation = shock
	}
	right_portrait = {
		character = scope:corpse_flinger
		animation = schadenfreude
	}

	immediate = {
		create_character_memory = {
			type = ce1_corpse_flung_at_me
			participants = {
				flinger = scope:corpse_flinger
			}
		}
	}

	option = { # Fling it back!
		name = epidemic_events.1121.a
		trigger = {
			culture = { has_innovation = innovation_catapult }
		}
		show_as_unavailable = { always = yes }
		random_list = {
			50 = {
				show_chance = no
				desc = plague_averted_tt
				send_interface_toast = {
					title = plague_averted_tt
					left_icon = root
					right_icon = scope:corpse_flinger
					hidden_effect = {
						scope:corpse_flinger = {
							trigger_event = epidemic_events.1122
						}
					}
				}
				create_character_memory = {
					type = ce1_flung_corpse
					participants = {
						flingee = scope:corpse_flinger
					}
				}
			}
			50 = {
				show_chance = no
				desc = plague_still_infects_tt
				send_interface_toast = {
					title = plague_still_infects_tt
					left_icon = root
					right_icon = scope:corpse_flinger
					scope:flung_corpse_location = {
						add_county_modifier = {
							modifier = ce1_siege_corpse
							years = 15
						}
					}
					infect_with_epidemic = scope:epidemic_scope
				}
			}
		}
		stress_impact = {
			forgiving = medium_stress_impact_gain
			compassionate = minor_stress_impact_gain
			just = minor_stress_impact_gain
			calm = minor_stress_impact_gain
			humble = minor_stress_impact_gain
			honest = minor_stress_impact_gain
			callous = minor_stress_impact_loss
			sadistic = medium_stress_impact_loss
			vengeful = major_stress_impact_loss
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = -1
				ai_vengefulness = 2
			}
		}
	}

	option = { # Do something about the corpse
		name = epidemic_events.1121.b
		duel = {
			skill = learning
			value = high_skill_rating
			# You quarantine the corpse succesfully
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				send_interface_toast = {
					title = epidemic_events.1121.b.success
					left_icon = root
					right_icon = scope:peasant_1

					scope:location = {
						add_province_modifier = {
							modifier = ce1_quarantined_corpse
							years = 10
						}
					}
				}
			}
			# The quarantine fails
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				send_interface_toast = {
					title = epidemic_events.1121.b.failure
					left_icon = root
					right_icon = scope:corpse_flinger
					scope:flung_corpse_location = {
						add_county_modifier = {
							modifier = ce1_siege_corpse
							years = 15
						}
					}
					infect_with_epidemic = scope:epidemic_scope
				}
			}
		}
		stress_impact = {
			arrogant = minor_stress_impact_gain
			torturer = minor_stress_impact_gain
			vengeful = minor_stress_impact_gain
			sadistic = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = 1
				ai_zeal = 1
				ai_compassion = 1
				ai_vengefulness = -1
			}
		}
	}

	option = { # Just keep that thing away from me
		name = epidemic_events.1121.c
		scope:flung_corpse_location = {
			add_county_modifier = {
				modifier = ce1_siege_corpse
				years = 15
			}
		}
		stress_impact = {
			arrogant = minor_stress_impact_loss
			humble = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = -1
				ai_zeal = -1
				ai_compassion = -1
			}
		}
	}
}

# Return to sender
epidemic_events.1122 = {
	type = character_event
	title = epidemic_events.1122.t
	desc = epidemic_events.1122.desc
	theme = plague
	left_portrait = {
		character = root
		animation = shock
	}
	right_portrait = {
		character = scope:corpse_flingee
		animation = schadenfreude
	}

	immediate = {
		create_character_memory = {
			type = ce1_corpse_flung_at_me
			participants = {
				flinger = scope:corpse_flinger
			}
		}
	}

	option = { # God damn it
		name = epidemic_events.1122.a
		infect_with_epidemic = scope:epidemic_scope
		add_stress = major_stress_gain
		ai_chance = {
			base = 100
		}
	}

	option = { # Throw it back again!
		name = epidemic_events.1122.b
		trigger = {
			has_trait = torturer
		}
		random_list = {
			25 = {
				show_chance = no
				desc = epidemic_events.1122.b.success
				send_interface_toast = {
					title = epidemic_events.1122.b.success
					left_icon = root
					right_icon = scope:corpse_flinger
					hidden_effect = {
						scope:corpse_flingee = {
							trigger_event = epidemic_events.1123
						}
					}
				}
			}
			75 = {
				show_chance = no
				desc = epidemic_events.1122.b.failure
				send_interface_toast = {
					title = epidemic_events.1122.b.failure
					left_icon = root
					right_icon = scope:corpse_flingee
					add_character_modifier = {
						modifier = ce1_heavily_ill
						years = 5
					}
					infect_with_epidemic = scope:epidemic_scope
				}
			}
		}
		stress_impact = {
			arrogant = minor_stress_impact_gain
			torturer = minor_stress_impact_gain
			vengeful = minor_stress_impact_gain
			sadistic = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = 1
				ai_zeal = 1
				ai_compassion = 1
				ai_vengefulness = -1
			}
		}
	}
}

# The meat shower
epidemic_events.1123 = {
	type = character_event
	title = epidemic_events.1123.t
	desc = epidemic_events.1123.desc
	theme = plague
	left_portrait = {
		character = root
		animation = shock
	}
	right_portrait = {
		character = scope:corpse_flinger
		animation = schadenfreude
	}

	option = { # God damn it
		name = epidemic_events.1123.a
		scope:flung_corpse_location = {
			add_county_modifier = {
				modifier = ce1_siege_corpse
				years = 15
			}
		}
		create_character_memory = {
			type = ce1_meat_shower
			participants = {
				flinger = scope:corpse_flinger
			}
		}
		
		ai_chance = {
			base = 100
		}
	}
}

############################
## Epidemic Flavor Events
## 3000-3999
## by Veronica Pazos
############################

############################
## You travel through an infected province
## 3000
## by Veronica Pazos
############################

epidemic_events.3000 = {	
	type = character_event
	title = epidemic_events.3000.t
	desc = epidemic_events.3000.desc
	theme = plague
	override_background = { reference = ce1_condemned_village }
	override_effect_2d = {
		reference = flies	
	}
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = {
				NOR = {
					has_trait = callous
					has_trait = sadistic
				}
			}
			animation = fear
		}
		animation = thinking
	}
	right_portrait = {
		character = scope:sick_peasant
		triggered_animation = {
			trigger = {
				scope:epidemic_scope.epidemic_type.epidemic_trait = trait:ergotism
			}
			animation = dancing_plague
		}
		animation = sick_stomach
	}
	lower_center_portrait = scope:companion
	cooldown = { years = 5 }

	trigger = {
		is_travelling = yes
		location = {
			any_province_epidemic = { }
		}
		current_travel_plan ?= {
			any_entourage_character = {
				this != root
				is_physically_able_ai_adult = yes
			}
		}
	}

	immediate = {
		location = {
			save_scope_as = epidemic_location
		}
		location = {
			random_province_epidemic = {
				save_scope_as = epidemic_scope
			}
		}
		current_travel_plan ?= {
			random_entourage_character = {
				limit = {
					this != root
					is_physically_able_ai_adult = yes
					NOT = { has_trait = scope:epidemic_scope.epidemic_type.epidemic_trait }
				}
				weight = {
					base = 1
					modifier = {
						has_trait = compassionate
						add = 10
					}
					modifier = {
						has_trait = lifestyle_herbalist
						add = 5
					}
					modifier = {
						has_trait = lifestyle_physician
						add = 5
					}
					modifier = {
						OR = {
							has_trait = callous
							has_trait = sadistic
						}
						factor = 0
					}
				}
				save_scope_as = companion
			}
		}
		if = {
			limit = {
				any_pool_character = {
					province = root.location
					is_adult = yes
					has_no_particular_noble_roots_trigger = yes
					has_trait = scope:epidemic_scope.epidemic_type.epidemic_trait
				}
			}
			random_pool_character = {
				province = root.location
				limit = {
					is_adult = yes
					has_no_particular_noble_roots_trigger = yes
					has_trait = scope:epidemic_scope.epidemic_type.epidemic_trait
				}
				save_scope_as = sick_peasant
			}
		}
		else = {
			create_character = {
				template = peasant_character
				dynasty = none
				location = root.location
				culture = root.location.culture
				faith = root.location.faith
				gender_female_chance = 50
				save_scope_as = sick_peasant
			}
			scope:sick_peasant = {
				add_trait = scope:epidemic_scope.epidemic_type.epidemic_trait
			}
		}
	}

	option = { # Stop by to help
		name = epidemic_events.3000.a
		add_piety = minor_piety_gain
		pay_short_term_gold = {
			target = scope:sick_peasant
			gold = medium_gold_value
		}
		current_travel_plan ?= {
			delay_travel_plan = { days = 10 }
		}
		
		stress_impact = {
			greedy = major_stress_impact_gain
			avaricious = major_stress_impact_gain
			callous = major_stress_impact_gain
			sadistic = major_stress_impact_gain
		}

		ai_chance = {
			base = 100
			modifier = {
				OR = {
					has_trait = compassionate
					has_trait = profligate
				}
				add = 50
			}
			modifier = {
				OR = {
					has_trait = greedy
					has_trait = avaricious
					has_trait = callous
					has_trait = sadistic
					NAND = {
						can_make_expensive_purchase_trigger = { PRICE = medium_gold_value }
						has_trait = profligate
					}
				}
				factor = 0
			}
		}
	}
	
	option = { # Ask a courtier to help them
		name = epidemic_events.3000.b
		trigger = { exists = scope:companion }
		add_piety = miniscule_piety_gain
		scope:companion = {
			random = {
				chance = 50
				modifier = {
					add = {
						value = 0
						subtract = health #if you're healthy you kinda get away with it
					}
				}
				modifier = {
					add = { value = -10 }
					OR = {
						has_trait = whole_of_body
						has_perk = wash_your_hands_perk
					}
				}
				root = {
					send_interface_toast = {
						title = epidemic_events.3000.b.sick
						left_icon = scope:companion
						scope:companion = {
							add_trait = scope:epidemic_scope.epidemic_type.epidemic_trait
						}
					}
				}
			}
		}

		stress_impact = {
			callous = medium_stress_impact_gain
			sadistic = medium_stress_impact_gain
		}

		ai_chance = {
			base = 100
			modifier = {
				OR = {
					has_trait = callous
					has_trait = sadistic
				}
				factor = 0
			}
		}
	}

	option = { # Wow that sucks
		name = epidemic_events.3000.c
		add_piety = minor_piety_loss
		
		stress_impact = {
			compassionate = major_stress_impact_gain
			just = medium_stress_impact_gain
			callous = medium_stress_impact_loss
			sadistic = medium_stress_impact_loss
		}

		ai_chance = {
			base = 100
			modifier = {
				OR = {
					has_trait = compassionate
					has_trait = just
				}
				factor = 0
			}
		}
	}
	
	after = {
		hidden_effect = {
			if = {
				limit = { is_ai = yes }
				scope:sick_peasant = { silent_disappearance_effect = yes }
			}
			else = {
				scope:sick_peasant = { move_to_pool = yes }
			}
		}
	}
}

############################
## You travel through an infected province AND may get infected
## 3010
## by Veronica Pazos
############################

epidemic_events.3010 = {	
	type = character_event
	title = epidemic_events.3010.t
	desc = epidemic_events.3010.desc
	theme = plague
	override_background = { reference = ce1_condemned_village }
	override_effect_2d = {
		reference = flies	
	}
	left_portrait = {
		character = root
		animation = jockey_walk
		camera = camera_event_horse_left
	}
	cooldown = { years = 5 }

	trigger = {
		is_travelling = yes
		location = {
			any_province_epidemic = { }
		}
	}

	immediate = {
		location = {
			save_scope_as = epidemic_location
		}
		location = {
			random_province_epidemic = {
				save_scope_as = epidemic_scope
			}
		}
		hidden_effect = {
			create_character = {
				template = peasant_character
				dynasty = none
				location = root.location
				culture = root.location.culture
				faith = root.location.faith
				gender_female_chance = 50
				save_scope_as = sick_peasant
			}
			scope:sick_peasant = {
				add_trait = scope:epidemic_scope.epidemic_type.epidemic_trait
			}
		}
	}
	
	option = { # You are very clever
		name = epidemic_events.3010.a
		trigger = {
			OR = {
				has_trait = lifestyle_physician
				has_trait = lifestyle_herbalist
				learning >= high_skill_rating
			}
		}
		add_character_modifier = {
			modifier = humour_knowledge_modifier
			years = 10
		}
		stress_impact = {
			brave = medium_stress_impact_gain
			impatient = medium_stress_impact_gain
		}

		ai_chance = {
			base = 100
			modifier = {
				OR = {
					has_trait = brave
					has_trait = impatient
				}
				factor = 0
			}
		}
	}

	option = { # Drink water
		name = epidemic_events.3010.b
		random = {
			chance = 50
			send_interface_toast = {
				title = epidemic_events.3010.b.sick
				left_icon = root
				add_trait = scope:epidemic_scope.epidemic_type.epidemic_trait
			}
			modifier = {
				add = {
					value = 0
					subtract = health #if you're healthy you kinda get away with it
				}
			}
			modifier = {
				add = { value = -10 }
				OR = {
					has_trait = whole_of_body
					has_perk = wash_your_hands_perk
				}
			}
		}
		
		stress_impact = {
			craven = medium_stress_impact_gain
			cynical = medium_stress_impact_gain
			paranoid = major_stress_impact_gain
		}

		ai_chance = {
			base = 100
			modifier = {
				OR = {
					has_trait = paranoid
					has_trait = craven
					has_trait = cynical
				}
				factor = 0
			}
		}
	}
	
	option = { # Don't drink
		name = epidemic_events.3010.c
		current_travel_plan = {
			add_travel_plan_modifier = no_water_modifier
		}
		stress_impact = {
			impatient = medium_stress_impact_gain
			diligent = medium_stress_impact_gain
		}

		ai_chance = {
			base = 100
			modifier = {
				OR = {
					has_trait = impatient
					has_trait = diligent
				}
				factor = 0
			}
		}
	}
	
	after = {
		hidden_effect = {
			if = {
				limit = { is_ai = yes }
				scope:sick_peasant = { silent_disappearance_effect = yes }
			}
			else = {
				scope:sick_peasant = { move_to_pool = yes }
			}
		}
	}
}

############################
## Epidemic Flavor Events
## 5000-5899
## by Nick Meredith
############################

# Church officials want to cull an animal
# by Nick Meredith
epidemic_events.5000 = {	
	type = character_event
	title = epidemic_events.5000.t
	desc = epidemic_events.5000.desc
	theme = plague
	override_background = { reference = ce1_funeral_pyre }
	override_effect_2d = {
		reference = flies	
	}
	left_portrait = {
		character = root
		animation = chancellor
	}
	right_portrait = {
		character = scope:church_person
		animation = debating
	}
	cooldown = { years = 10 }

	trigger = {
		is_available_adult = yes
		# There be a plague
		any_sub_realm_county = {
			any_county_province = {
				OR = {
					county.holder = root
					squared_distance = {
						target = root.capital_province
						value <= squared_distance_medium #250 map-pixels. Roughly one Ireland away (top to bottom).
					}
				}
				any_province_epidemic = { }
			}
		}

		exists = cp:councillor_court_chaplain
		cp:councillor_court_chaplain = {
			is_available_ai_adult = yes
			location = root.location #Ensure it makes sense they talk to you
		}
	}

	immediate = {
		select_local_farm_animal_effect = yes
		random_sub_realm_county = {
			limit = {
				any_county_province = {
					OR = {
						county.holder = root
						squared_distance = {
							target = root.capital_province
							value <= squared_distance_medium #250 map-pixels. Roughly one Ireland away (top to bottom).
						}
					}
					any_province_epidemic = { }
				}
			}
			save_scope_as = infected_county
		}
		scope:infected_county = {
			random_county_province = {
				limit = {
					any_province_epidemic = { }
				}
				random_province_epidemic = {
					save_scope_as = epidemic
				}
				save_scope_as = infected_province
			}
		}
		cp:councillor_court_chaplain = {
			save_scope_as = church_person
		}
		save_scope_value_as = {
			name = infection_range
			value = {
				integer_range = {
					min = 1
					max = 15
				}
			}
		}
	}

	option = { # How about... rats?
		name = epidemic_events.5000.a

		trigger = {
			has_trait = eccentric
		}

		scope:infected_county = {
			add_county_modifier = {
				modifier = rats_eradicated
				years = 10
			}
		}

		reverse_add_opinion = {
			modifier = confused_opinion
			opinion = -5
			target = scope:church_person
		}

		stress_impact = {
			diligent = miniscule_stress_impact_loss
			calm = miniscule_stress_impact_loss
			humble = miniscule_stress_impact_loss
			lazy = minor_stress_impact_gain
			wrathful = minor_stress_impact_loss
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = 0.5
				ai_rationality = 1
			}
		}
	}

	option = { # Kill all the cats!
		name = epidemic_events.5000.b

		trigger = {
			NOT = {
				any_owned_story = {
					type = story_cycle_pet_cat
				}
			}
			any_owned_story = {
				type = story_cycle_pet_dog
			}
		}
		
		add_piety = major_piety_gain

		if = { #Kill all your courtiers' cats if they're there!
			limit = {
				any_courtier_or_guest = {
					location = scope:infected_province
					any_owned_story = {
						type = story_cycle_pet_cat
					}
				}
			}
			every_courtier_or_guest = {
				limit = {
					location = scope:infected_province
					any_owned_story = {
						type = story_cycle_pet_cat
					}
				}
				random_owned_story = {
					type = story_cycle_pet_cat
					save_scope_as = story
				}
				show_as_tooltip = {
					remove_cat_story_modifiers_effect = yes
				}
				scope:story = {
					hidden_effect = { end_story = yes }
				}
				add_opinion = {
					modifier = hate_opinion
					opinion = -30
					target = root
				}
			}
		}

		scope:infected_county = {
			add_county_modifier = {
				modifier = pets_eradicated
				years = 5
			}
		}

		reverse_add_opinion = {
			modifier = impressed_opinion
			opinion = 40
			target = scope:church_person
		}

		stress_impact = {
			diligent = miniscule_stress_impact_loss
			humble = miniscule_stress_impact_loss
			wrathful = miniscule_stress_impact_loss
			calm = minor_stress_impact_gain
			lazy = minor_stress_impact_gain
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = -1
				ai_rationality = 0.5
			}
		}
	}

	option = { # Kill all the dogs!
		name = epidemic_events.5000.c

		trigger = {
			NOT = {
				any_owned_story = {
					type = story_cycle_pet_dog
				}
			}
			any_owned_story = {
				type = story_cycle_pet_cat
			}
		}
		
		add_piety = major_piety_gain

		if = { #Kill all your courtiers' dogs if they're there!
			limit = {
				any_courtier_or_guest = {
					location = scope:infected_province
					any_owned_story = {
						type = story_cycle_pet_dog
					}
				}
			}
			every_courtier_or_guest = {
				limit = {
					location = scope:infected_province
					any_owned_story = {
						type = story_cycle_pet_dog
					}
				}
				random_owned_story = {
					type = story_cycle_pet_dog
					save_scope_as = story
				}
				show_as_tooltip = {
					remove_dog_story_modifiers_effect = yes
				}
				scope:story = {
					hidden_effect = { end_story = yes }
				}
				add_opinion = {
					modifier = hate_opinion
					opinion = -30
					target = root
				}
			}
		}

		reverse_add_opinion = {
			modifier = impressed_opinion
			opinion = 40
			target = scope:church_person
		}

		stress_impact = {
			diligent = miniscule_stress_impact_loss
			humble = miniscule_stress_impact_loss
			wrathful = miniscule_stress_impact_loss
			calm = minor_stress_impact_gain
			lazy = minor_stress_impact_gain
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = -1
				ai_rationality = 0.5
			}
		}
	}

	option = { # Kill all the sheep!
		name = epidemic_events.5000.d

		trigger = {
			NOT = {
				has_trait = eccentric
			}
		}

		scope:infected_county = {
			add_county_modifier = {
				modifier = vectors_reduced
				years = 10
			}
		}

		reverse_add_opinion = {
			modifier = impressed_opinion
			opinion = 30
			target = scope:church_person
		}

		stress_impact = {
			diligent = miniscule_stress_impact_loss
			humble = miniscule_stress_impact_loss
			stubborn = miniscule_stress_impact_loss
			calm = minor_stress_impact_gain
			lazy = minor_stress_impact_gain
			fickle = minor_stress_impact_gain
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = -0.5
				ai_rationality = 1
			}
		}
	}

	option = { # Don't be ridiculous, realm priest!
		name = epidemic_events.5000.e

		reverse_add_opinion = {
			modifier = angry_opinion
			opinion = -25
			target = scope:church_person
		}

		stress_impact = {
			diligent = minor_stress_impact_gain
			humble = minor_stress_impact_gain
			stubborn = minor_stress_impact_gain
			calm = miniscule_stress_impact_loss
			lazy = miniscule_stress_impact_loss
			fickle = miniscule_stress_impact_loss
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 1
				ai_rationality = -0.5
			}
		}
	}
}

# A minor epidemic is causing massive panic
# by Nick Meredith
epidemic_events.5001 = {
	type = character_event
	title = epidemic_events.5001.t
	desc = epidemic_events.5001.desc
	theme = plague
	override_background = study
	left_portrait = {
		character = root
		animation = chancellor
		camera = camera_event_very_left
	}
	right_portrait = {
		character = scope:courtier
		animation = holding_scrolls
	}
	cooldown = { years = 10 }

	trigger = {
		NOT = {
			government_has_flag = government_is_nomadic
		}
		is_available = yes
		# There be a plague, but it's kinda smol
		any_sub_realm_county = {
			any_county_province = {
				exists = province_owner
				OR = {
					county.holder = root
					squared_distance = {
						target = root.capital_province
						value <= squared_distance_medium #250 map-pixels. Roughly one Ireland away (top to bottom).
					}
				}
				any_province_epidemic = {
					intensity <= minor
				}
			}
		}

		any_courtier = {
			location = root.location
			is_available_ai_adult = yes
		}
	}

	immediate = {
		random_sub_realm_county = {
			limit = {
				any_county_province = {
					exists = province_owner
					OR = {
						county.holder = root
						squared_distance = {
							target = root.capital_province
							value <= squared_distance_medium #250 map-pixels. Roughly one Ireland away (top to bottom).
						}
					}
					any_province_epidemic = {
						intensity <= minor
					}
					province_owner = { save_temporary_scope_as = province_owner_temp }
				}
			}
			random_county_province = {
				limit = {
					exists = province_owner
					OR = {
						county.holder = root
						squared_distance = {
							target = root.capital_province
							value <= squared_distance_medium #250 map-pixels. Roughly one Ireland away (top to bottom).
						}
					}
					any_province_epidemic = {
						intensity <= minor
					}
				}
				random_province_epidemic = {
					save_scope_as = epidemic_scope
				}
			}
			save_scope_as = epidemic_county
			scope:province_owner_temp = { save_scope_as = province_owner }
		}

		random_courtier = {
			limit = {
				location = root.location
				is_available_ai_adult = yes
			}
			save_scope_as = courtier
		}
	}

	option = { # Send them some supplies
		name = epidemic_events.5001.d
		
		add_legitimacy_effect = { LEGITIMACY = minor_legitimacy_gain }

		remove_treasury_or_gold = minor_treasury_or_gold_value

		scope:epidemic_county = {
			add_county_modifier = {
				modifier = supplies_sent
				years = 10
			}
		}

		reverse_add_opinion = {
			modifier = pleased_opinion
			opinion = 15
			target = scope:courtier
		}

		stress_impact = {
			generous = miniscule_stress_impact_loss
			diligent = miniscule_stress_impact_loss
			humble = miniscule_stress_impact_loss
			greedy = minor_stress_impact_gain
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 1
				ai_rationality = 1
			}
		}
	}

	option = { # I'm sure they'll be fine
		name = epidemic_events.5001.e
		
		scope:epidemic_county = {
			add_county_modifier = {
				modifier = plight_ignored
				years = 10
			}
		}

		stress_impact = {
			diligent = minor_stress_impact_gain
			generous = minor_stress_impact_gain
			calm = miniscule_stress_impact_loss
			lazy = miniscule_stress_impact_loss
			fickle = miniscule_stress_impact_loss
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 1
				ai_rationality = -0.5
			}
		}
	}
}

# A peasant asks for your healing touch
# by Nick Meredith
epidemic_events.5003 = {
	type = character_event
	title = epidemic_events.5003.t
	desc = epidemic_events.5003.desc
	theme = plague
	override_background = { reference = market }
	override_effect_2d = {
		reference = rain	
	}
	left_portrait = {
		character = root
		animation = horse_conversing_right
		camera = camera_event_horse_left
	}
	right_portrait = {
		character = scope:peasant
		animation = beg
		camera = camera_event_standing_with_horse_right
	}
	lower_center_portrait = {
		character = scope:child
	}
	cooldown = { years = 10 }
	
	trigger = {
		is_available = yes
		# You're at your capital
		location = root.capital_province

		# There be a plague in your capital
		any_sub_realm_county = {
			any_county_province = {
				OR = {
					county.holder = root
					squared_distance = {
						target = root.capital_province
						value <= squared_distance_medium #250 map-pixels. Roughly one Ireland away (top to bottom).
					}
				}
				any_province_epidemic = { }
				this = root.capital_province
			}
		}
	}

	immediate = {
		random_sub_realm_county = {
			limit = {
				any_county_province = {
					OR = {
						county.holder = root
						squared_distance = {
							target = root.capital_province
							value <= squared_distance_medium #250 map-pixels. Roughly one Ireland away (top to bottom).
						}
					}
					any_province_epidemic = { }
					this = root.capital_province
				}
			}
			random_county_province = {
				limit = {
					any_province_epidemic = { }
					this = root.capital_province
				}
				save_scope_as = location
			}
		}
		hidden_effect = {
			if = {
				limit = {
					any_pool_character = {
						province = root.location
						NOT = { is_courtier_of = root }
						is_available_ai_adult = yes
						has_no_particular_noble_roots_trigger = yes
						any_child = {
							is_healthy = no
							is_adult = no
						}
					}
				}
				random_pool_character = {
					province = root.location
					limit = {
						is_available_ai_adult = yes
						NOT = { is_courtier_of = root }
						has_no_particular_noble_roots_trigger = yes
						any_child = {
							is_healthy = no
							is_adult = no
						}
					}
					save_scope_as = peasant
				}
			}
			else = {
				create_character = {
					template = generic_peasant_character
					culture = root.culture
					faith = root.faith
					location = root.location
					save_scope_as = peasant
					after_creation = {
						add_character_flag = created
					}
				}
				hidden_effect = {
					scope:peasant = {
						move_to_pool = yes
					}
				}
			}
			create_character = {
				template = peasant_toddler_character
				culture = root.culture
				faith = root.faith
				location = root.location
				save_scope_as = child
				after_creation = {
					add_character_flag = created
				}
			}

			if = { #Set the previous character as their parent
				limit = {
					scope:peasant ?= {
						is_female = no
					}
				}
				hidden_effect = {
					scope:child = {
						set_father = scope:peasant
					}
				}
			}
			else = {
				hidden_effect = {
					scope:child = {
						set_mother = scope:peasant
					}
				}
			}
			hidden_effect = {
				scope:child = {
					contract_disease_effect = { DISEASE = ill TREATMENT_EVENT = no }
					move_to_pool = yes
				}
			}
		}

		save_scope_value_as = {
			name = infection_range
			value = {
				integer_range = {
					min = 1
					max = 15
				}
			}
		}
	}

	option = { # Get away from me!
		name = epidemic_events.5003.a

		trigger = {
			OR = {
				has_trait = callous
				has_trait = sadistic
				has_trait = paranoid
			}
		}
		trait = callous
		trait = sadistic
		trait = paranoid

		add_character_modifier = {
			modifier = health_first
			years = 15
		}
		
		scope:child = {
			death = {
				death_reason = death_ill
			}
		}

		stress_impact = {
			base = minor_stress_impact_loss
			wrathful = miniscule_stress_impact_loss
			vengeful = miniscule_stress_impact_loss
			arbitrary = miniscule_stress_impact_loss
			compassionate = medium_stress_impact_gain
			callous = medium_stress_impact_loss
			paranoid = medium_stress_impact_loss
			sadistic = medium_stress_impact_loss
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = -1
				ai_rationality = 0.5
				ai_vengefulness = 1
			}
		}
	}

	option = { # Give it a go
		name = epidemic_events.5003.b
		
		add_legitimacy_effect = { LEGITIMACY = medium_legitimacy_gain }
		
		add_character_modifier = {
			modifier = man_of_the_people
			years = 10
		}
		
		random = {
			chance = 50
			contract_disease_effect = { DISEASE = ill TREATMENT_EVENT = yes }
		}

		stress_impact = {
			compassionate = miniscule_stress_impact_loss
			trusting = miniscule_stress_impact_loss
			paranoid = minor_stress_impact_gain
			craven = minor_stress_impact_gain
			shy = minor_stress_impact_gain
			arrogant = minor_stress_impact_gain
			sadistic = minor_stress_impact_gain
			callous = minor_stress_impact_gain
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 1
				ai_zeal = 0.5
			}
		}
	}

	option = { # Just... try to ignore them
		name = epidemic_events.5003.c

		stress_impact = {
			shy = medium_stress_impact_loss
			compassionate = minor_stress_impact_gain
			trusting = minor_stress_impact_gain
			callous = medium_stress_impact_loss
			paranoid = medium_stress_impact_loss
			sadistic = medium_stress_impact_loss
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = -0.5
			}
		}
	}
	after = {
		scope:peasant = {
			silent_disappearance_ai_effect = yes
		}
		scope:child = {
			silent_disappearance_ai_effect = yes
		}
	}
}

# People are trying to get into your castle!
# by Nick Meredith
epidemic_events.5004 = {
	type = character_event
	title = epidemic_events.5004.t
	desc = epidemic_events.5004.desc
	theme = plague
	override_background = { reference = throne_room }
	override_effect_2d = { reference = flies }
	left_portrait = {
		character = root
		animation = shock
		camera = camera_event_very_left
	}
	right_portrait = {
		character = scope:peasant_1
		animation = beg
	}
	lower_left_portrait = {
		character = scope:peasant_2
	}
	lower_center_portrait = {
		character = scope:peasant_3
	}
	lower_right_portrait = {
		character = scope:peasant_4
	}
	cooldown = { years = 100 }
	
	trigger = {
		is_available = yes
		# Make sure you're royal!
		highest_held_title_tier >= tier_kingdom

		# And you're at your capital
		location = root.capital_province

		# There be a plague in your capital
		capital_province = {
			any_province_epidemic = { }
		}

		any_pool_character = {
			province = root.location
			count >= 4
			is_available_ai_adult = yes
			has_no_particular_noble_roots_trigger = yes
		}
		
		NOR = {
			government_has_flag = government_is_nomadic
			government_has_flag = government_is_tribal
		}
	}

	immediate = {
		random_sub_realm_county = {
			limit = {
				any_county_province = {
					OR = {
						county.holder = root
						squared_distance = {
							target = root.capital_province
							value <= squared_distance_medium #250 map-pixels. Roughly one Ireland away (top to bottom).
						}
					}
					any_province_epidemic = { }
					this = root.capital_province
				}
			}
			random_county_province = {
				limit = {
					any_province_epidemic = { }
					this = root.capital_province
				}
				random_province_epidemic = {
					save_scope_as = epidemic_scope
				}
				save_scope_as = location
			}
		}

		random_pool_character = {
			province = root.location
			limit = {
				is_available_ai_adult = yes
				has_no_particular_noble_roots_trigger = yes
			}
			save_scope_as = peasant_1
		}

		random_pool_character = {
			province = root.location
			limit = {
				is_available_ai_adult = yes
				has_no_particular_noble_roots_trigger = yes
				this != scope:peasant_1
			}
			save_scope_as = peasant_2
		}

		random_pool_character = {
			province = root.location
			limit = {
				is_available_ai_adult = yes
				has_no_particular_noble_roots_trigger = yes
				NOR = {
					this = scope:peasant_1
					this = scope:peasant_2
				}
			}
			save_scope_as = peasant_3
		}

		random_pool_character = {
			province = root.location
			limit = {
				is_available_ai_adult = yes
				has_no_particular_noble_roots_trigger = yes
				NOR = {
					this = scope:peasant_1
					this = scope:peasant_2
					this = scope:peasant_3
				}
			}
			save_scope_as = peasant_4
		}

		every_pool_character = {
			province = root.location
			limit = {
				has_no_particular_noble_roots_trigger = yes
			}
			add_to_list = peasant_rabble
		}
	}

	option = { # Welcome in!
		name = epidemic_events.5004.a

		every_in_list = {
			list = peasant_rabble
			root = {
				add_courtier = prev
			}
		}

		hidden_effect = {
			every_in_list = {
				list = peasant_rabble
				add_opinion = {
					modifier = grateful_opinion
					opinion = 40
					target = root			
				}
			}
		}

		custom_tooltip = epidemic_events.5004.a.new_courtiers

		scope:location = {
			add_province_modifier = {
				modifier = commoners_welcomed_in
				years = 15
			}
		}

		stress_impact = {
			gregarious = medium_stress_impact_loss
			compassionate = medium_stress_impact_loss
			generous = miniscule_stress_impact_loss
			trusting = miniscule_stress_impact_loss
			greedy = minor_stress_impact_gain
			paranoid = minor_stress_impact_gain
			callous = medium_stress_impact_gain
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 1
				ai_rationality = -0.5
			}
		}
	}

	option = { # Get out of here, miscreants!
		name = epidemic_events.5004.c
		
		add_dread = massive_dread_gain

		scope:location = {
			add_province_modifier = {
				modifier = commoners_turned_away
				years = 15
			}
		}
		
		every_in_list = {
			list = peasant_rabble
			if = {
				limit = {
					age <= 20
				}
				add_stress = major_stress_impact_gain
			}
			if = {
				limit = {
					age <= 40
				}
				increase_wounds_effect = { REASON = fight }
			}
			if = {
				limit = {
					age > 40
				}
				death = { death_reason = death_fight }
			}
		}

		stress_impact = {
			wrathful = minor_stress_impact_loss
			shy = minor_stress_impact_loss
			callous = minor_stress_impact_loss
			paranoid = medium_stress_impact_loss
			compassionate = minor_stress_impact_gain
			trusting = minor_stress_impact_gain
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = -1
				ai_sociability = -1
			}
		}
	}

	option = { # Come on, now, you know I can't do that...
		name = epidemic_events.5004.b

		scope:location = {
			add_province_modifier = {
				modifier = commoners_turned_away
				years = 15
			}
		}

		stress_impact = {
			paranoid = miniscule_stress_impact_loss
			trusting = minor_stress_impact_gain
			forgiving = minor_stress_impact_gain
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = -0.5
				ai_vengefulness = 0.5
			}
		}
	}
}

# The plague is spreading in from the coast
# by Nick Meredith
epidemic_events.5005 = {
	type = character_event
	title = epidemic_events.5005.t
	desc = epidemic_events.5005.desc
	theme = plague
	override_background = docks
	override_effect_2d = { reference = flies }
	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		character = scope:steward
		animation = stress
	}
	cooldown = { years = 10 }

	trigger = {
		is_available = yes
		#There be a plague in your subrealm, and it's in a coastal province
		any_sub_realm_county = {
			any_county_province = {
				is_coastal = yes
				OR = {
					county.holder = root
					squared_distance = {
						target = root.capital_province
						value <= squared_distance_medium #250 map-pixels. Roughly one Ireland away (top to bottom).
					}
				}
				any_province_epidemic = { }
			}
		}

		exists = cp:councillor_steward
		cp:councillor_steward = {
			is_available_healthy_ai_adult = yes
		}
	}

	immediate = {
		random_sub_realm_county = {
			limit = {
				any_county_province = {
					is_coastal = yes
					OR = {
						county.holder = root
						squared_distance = {
							target = root.capital_province
							value <= squared_distance_medium #250 map-pixels. Roughly one Ireland away (top to bottom).
						}
					}
					any_province_epidemic = { }
				}
			}
			random_county_province = {
				limit = {
					is_coastal = yes
					any_province_epidemic = { }
				}
				save_scope_as = coastal_province
			}
		}

		every_sub_realm_county = {
			limit = {
				has_coastal_province = yes
			}
			every_county_province = {
				limit = {
					is_coastal = yes
				}
				add_to_list = coastal_list
			}
		}

		random_sub_realm_county = {
			limit = {
				any_county_province = {
					any_province_epidemic = { }
				}
			}
			random_county_province = {
				limit = {
					any_province_epidemic = { }
				}
				random_province_epidemic = {
					save_scope_as = epidemic_scope
				}
			}
		}

		cp:councillor_steward = {
			save_scope_as = steward
		}
	}

	option = { # Make it 40 days, and threaten them
		name = epidemic_events.5005.a

		trigger = {
			OR = {
				has_trait = paranoid
				has_trait = sadistic
				has_trait = callous
				has_trait = arbitrary
				has_trait = stubborn
			}
		}
		trait = paranoid
		trait = sadistic
		trait = callous
		trait = arbitrary
		trait = stubborn

		if = { #Tooltip ensmallener for if you have more than 5 sea provinces
			limit = {
				any_in_list = {
					list = coastal_list
					count > 5
				}
			}
			every_in_list = {
				list = coastal_list
				custom = epidemic_events.5005.a.coastal_quarantine
				add_province_modifier = {
					modifier = strict_coastal_quarantine
					years = 15
				}
			}
		}
		else = {
			every_in_list = {
				list = coastal_list
				add_province_modifier = {
					modifier = strict_coastal_quarantine
					years = 15
				}
			}
		}

		reverse_add_opinion = {
			modifier = relieved_opinion
			opinion = 15
			target = scope:steward
		}

		stress_impact = {
			paranoid = minor_stress_impact_loss
			trusting = medium_stress_impact_gain
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = -1
				ai_greed = -1
			}
		}
	}

	option = { # Institute a quarantine
		name = epidemic_events.5005.b

		if = { #Tooltip ensmallener for if you have more than 5 sea provinces
			limit = {
				any_in_list = {
					list = coastal_list
					count > 5
				}
			}
			every_in_list = {
				list = coastal_list
				custom = epidemic_events.5005.a.coastal_quarantine
				add_province_modifier = {
					modifier = coastal_quarantine
					years = 10
				}
			}
		}
		else = {
			every_in_list = {
				list = coastal_list
				add_province_modifier = {
					modifier = coastal_quarantine
					years = 10
				}
			}
		}

		reverse_add_opinion = {
			modifier = relieved_opinion
			opinion = 15
			target = scope:steward
		}

		stress_impact = {
			paranoid = minor_stress_impact_loss
			trusting = medium_stress_impact_gain
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = -0.5
				ai_vengefulness = 0.5
			}
		}
	}

	option = { # We can't afford this. We'll just have to hope.
		name = epidemic_events.5005.c

		stress_impact = {
			paranoid = medium_stress_impact_gain
			trusting = minor_stress_impact_loss
			compassionate = miniscule_stress_impact_loss
			greedy = minor_stress_impact_loss
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 0.5
				ai_greed = 1
			}
		}
	}
}

# People are attempting to save themselves via... laughter?
# by Nick Meredith
epidemic_events.5006 = {
	type = character_event
	title = epidemic_events.5006.t
	desc = epidemic_events.5006.desc
	theme = plague
	override_background = corridor_day
	left_portrait = {
		character = root
		animation = eyeroll
	}
	right_portrait = {
		character = scope:councillor
		animation = laugh
	}
	cooldown = { years = 10 }

	trigger = {
		is_available = yes
		#There be a plague in your subrealm
		any_sub_realm_county = {
			any_county_province = {
				OR = {
					county.holder = root
					squared_distance = {
						target = root.capital_province
						value <= squared_distance_medium #250 map-pixels. Roughly one Ireland away (top to bottom).
					}
				}
				any_province_epidemic = { }
			}
		}

		any_councillor = {
			is_available_healthy_ai_adult = yes
			NOR = {
				has_trait = callous
				has_trait = irritable
			}
		}
	}

	immediate = {
		random_sub_realm_county = {
			limit = {
				any_county_province = {
					OR = {
						county.holder = root
						squared_distance = {
							target = root.capital_province
							value <= squared_distance_medium #250 map-pixels. Roughly one Ireland away (top to bottom).
						}
					}
					any_province_epidemic = { }
				}
			}
			random_county_province = {
				limit = {
					any_province_epidemic = { }
				}
				save_scope_as = province
			}
		}

		random_sub_realm_county = {
			limit = {
				any_county_province = {
					any_province_epidemic = { }
				}
			}
			random_county_province = {
				limit = {
					any_province_epidemic = { }
				}
				random_province_epidemic = {
					save_scope_as = epidemic_scope
				}
			}
		}

		random_councillor = {
			limit = {
				is_available_healthy_ai_adult = yes
				NOR = {
					has_trait = callous
					has_trait = irritable
				}
			}
			save_scope_as = councillor
		}
	}

	option = { # You're so right! Hee hee hee!
		name = epidemic_events.5006.a

		trigger = {
			has_trait = eccentric
		}

		add_character_modifier = {
			modifier = cackling_loon
			years = 15
		}

		stress_impact = {
			base = medium_stress_impact_loss
			calm = miniscule_stress_impact_loss
			fickle = miniscule_stress_impact_loss
			stubborn = minor_stress_impact_gain
			wrathful = minor_stress_impact_gain
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 0.5
				ai_energy = 0.5
			}
		}
	}

	option = { # Faith is our only shield!
		name = epidemic_events.5006.b

		trigger = {
			has_trait = zealous
		}

		add_piety = medium_piety_gain

		if = {
			limit = {
				exists = cp:councillor_court_chaplain
			}
			reverse_add_opinion = {
				modifier = pleased_opinion
				opinion = 25
				target = cp:councillor_court_chaplain
			}
		}

		stress_impact = {
			base = minor_stress_impact_loss
			calm = miniscule_stress_impact_loss
			content = miniscule_stress_impact_loss
			gregarious = miniscule_stress_impact_loss
			ambitious = minor_stress_impact_gain
			wrathful = minor_stress_impact_gain
			shy = minor_stress_impact_gain
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = 1
			}
		}
	}

	option = { # Let's give it a go eh?
		name = epidemic_events.5006.c
		
		reverse_add_opinion = {
			modifier = pleased_opinion
			opinion = 20
			target = scope:councillor
		}

		stress_impact = {
			base = minor_stress_impact_loss
			impatient = minor_stress_impact_gain
			callous = minor_stress_impact_gain
			stubborn = minor_stress_impact_gain
			patient = miniscule_stress_impact_loss
			fickle = miniscule_stress_impact_loss
			compassionate = miniscule_stress_impact_loss
			eccentric = minor_stress_impact_loss
		}
		
		random = {
			chance = 10
			send_interface_toast = {
				title = epidemic_events.5006.t
				left_icon = root

				add_character_modifier = {
					modifier = strange_levity
					years = 15
				}
			}
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 0.5
				ai_energy = 1
			}
		}
	}

	option = { # This is ridiculous
		name = epidemic_events.5006.d

		add_prestige = miniscule_prestige_gain

		stress_impact = {
			impatient = miniscule_stress_impact_loss
			callous = miniscule_stress_impact_loss
			stubborn = miniscule_stress_impact_loss
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = -1
				ai_energy = -1
			}
		}
	}
}

# You have a herbalist at your court and people are accusing them of witchcraft
# by Nick Meredith
epidemic_events.5007 = {
	type = character_event
	title = epidemic_events.5007.t
	desc = epidemic_events.5007.desc
	theme = plague
	override_background = { reference = corridor_day }
	left_portrait = {
		character = scope:accuser
		animation = rage
		camera = camera_event_very_left
	}
	right_portrait = {
		character = scope:herbalist
		animation = dismissal
	}
	cooldown = { years = 10 }

	trigger = {
		is_available = yes
		trait_is_shunned_or_criminal_in_faith_trigger = {
			TRAIT = witch
			FAITH = root.faith
			GENDER_CHARACTER = root
		}
		faith = {
			NOT = {
				trait_is_virtue = witch
			}
		}
		#There be a plague in your subrealm
		any_sub_realm_county = {
			any_county_province = {
				OR = {
					county.holder = root
					squared_distance = {
						target = root.capital_province
						value <= squared_distance_medium #250 map-pixels. Roughly one Ireland away (top to bottom).
					}
				}
				any_province_epidemic = { }
			}
		}

		any_courtier_or_guest = {
			is_available_healthy_ai_adult = yes
			OR = {
				has_trait = lifestyle_herbalist
				has_trait = lifestyle_mystic
				has_trait = lifestyle_physician
				has_trait = lifestyle_gardener
			}
			NOT = {
				has_trait = witch
			}
			save_temporary_scope_as = temp_herbalist
		}

		any_courtier_or_guest = {
			is_available_healthy_ai_adult = yes
			is_ai = yes
			trait_is_shunned_or_criminal_in_faith_trigger = {
				TRAIT = witch
				FAITH = this.faith
				GENDER_CHARACTER = this
			}
			faith = {
				NOT = {
					trait_is_virtue = witch
				}
			}
			this != scope:temp_herbalist
		}
	}

	immediate = {
		random_sub_realm_county = {
			limit = {
				any_county_province = {
					OR = {
						county.holder = root
						squared_distance = {
							target = root.capital_province
							value <= squared_distance_medium #250 map-pixels. Roughly one Ireland away (top to bottom).
						}
					}
					any_province_epidemic = { }
				}
			}
			random_county_province = {
				limit = {
					any_province_epidemic = { }
				}
				random_province_epidemic = {
					save_scope_as = epidemic_scope
				}
			}
		}

		random_courtier_or_guest = {
			limit = {
				is_available_healthy_ai_adult = yes
				OR = {
					has_trait = lifestyle_herbalist
					has_trait = lifestyle_mystic
					has_trait = lifestyle_physician
					has_trait = lifestyle_gardener
				}
				NOT = {
					has_trait = witch
				}
			}
			save_scope_as = herbalist
		}

		random_courtier_or_guest = {
			limit = {
				is_available_healthy_ai_adult = yes
				is_ai = yes
				this != scope:herbalist
			}
			save_scope_as = accuser
		}
	}

	option = { # Herbalism is a noble art!
		name = epidemic_events.5007.a

		trigger = {
			OR = {
				has_trait = lifestyle_herbalist
				has_trait = lifestyle_mystic
				has_trait = lifestyle_physician
				has_trait = lifestyle_gardener
			}
		}
		trait = lifestyle_herbalist
		trait = lifestyle_mystic
		trait = lifestyle_physician
		trait = lifestyle_gardener

		reverse_add_opinion = {
			modifier = grateful_opinion
			opinion = 40
			target = scope:herbalist
		}
		
		add_legitimacy_effect = { LEGITIMACY = miniscule_legitimacy_gain }

		stress_impact = {
			base = minor_stress_impact_loss
			calm = miniscule_stress_impact_loss
			compassionate = miniscule_stress_impact_loss
			wrathful = minor_stress_impact_gain
			sadistic = medium_stress_impact_gain
			callous = minor_stress_impact_gain
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 1
				ai_energy = 0.5
			}
		}
	}

	option = { # You're right! Imprison them!
		name = epidemic_events.5007.b
		
		add_piety = medium_piety_gain

		scope:herbalist = {
			add_trait = witch
		}

		rightfully_imprison_character_effect = {
			TARGET = scope:herbalist
			IMPRISONER = root
		}

		reverse_add_opinion = {
			modifier = pleased_opinion
			opinion = 40
			target = scope:accuser
		}

		stress_impact = {
			wrathful = miniscule_stress_impact_loss
			callous = miniscule_stress_impact_loss
			sadistic = miniscule_stress_impact_loss
			paranoid = miniscule_stress_impact_loss
			calm = minor_stress_impact_gain
			trusting = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = 0.5
				ai_compassion = -1
			}
		}
	}

	option = { # Nonsense
		name = epidemic_events.5007.c

		reverse_add_opinion = {
			modifier = annoyed_opinion
			opinion = -20
			target = scope:accuser
		}
		
		if = {
			limit = {
				can_set_relation_potential_friend_trigger = { CHARACTER = scope:herbalist }
			}
			set_relation_potential_friend = scope:herbalist
		}

		stress_impact = {
			impatient = minor_stress_impact_gain
			callous = minor_stress_impact_gain
			sadistic = minor_stress_impact_gain
			patient = miniscule_stress_impact_loss
			compassionate = miniscule_stress_impact_loss
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 0.5
				ai_energy = 1
			}
		}
	}
}

# You begin sequestering yourself more often
# by Nick Meredith
epidemic_events.5008 = {
	type = character_event
	title = epidemic_events.5008.t
	desc = epidemic_events.5008.desc
	theme = plague
	override_background = relaxing_room
	left_portrait = {
		character = root
		animation = drink_goblet
	}
	cooldown = { years = 10 }

	trigger = {
		is_available = yes
		#There be a plague in your subrealm
		any_sub_realm_county = {
			any_county_province = {
				OR = {
					county.holder = root
					squared_distance = {
						target = root.capital_province
						value <= squared_distance_medium #250 map-pixels. Roughly one Ireland away (top to bottom).
					}
				}
				any_province_epidemic = { }
			}
		}

		#And you're a recluse
		OR = {
			has_trait_introverted_trigger = yes
			has_character_modifier = isolating_modifier
		}
		has_personality_introverted_trigger = no
	}

	immediate = {
		random_sub_realm_county = {
			limit = {
				any_county_province = {
					OR = {
						county.holder = root
						squared_distance = {
							target = root.capital_province
							value <= squared_distance_medium #250 map-pixels. Roughly one Ireland away (top to bottom).
						}
					}
					any_province_epidemic = { }
				}
			}
			random_county_province = {
				limit = {
					any_province_epidemic = { }
				}
				random_province_epidemic = {
					save_scope_as = epidemic_scope
				}
			}
		}
	}

	option = { # And nobody is allowed to see me without my permission!
		name = epidemic_events.5008.a

		trigger = {
			has_trait = paranoid
		}

		add_character_modifier = {
			modifier = absent_ruler
			years = 10
		}

		stress_impact = {
			base = major_stress_impact_loss
			craven = major_stress_impact_loss
			diligent = medium_stress_impact_gain
			ambitious = minor_stress_impact_gain
			stubborn = miniscule_stress_impact_loss
			content = miniscule_stress_impact_loss
			lazy = miniscule_stress_impact_loss
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_energy = -1
			}
		}
	}

	option = { # I must be seen by my subjects.
		name = epidemic_events.5008.b

		add_legitimacy_effect = { LEGITIMACY = medium_legitimacy_gain }

		add_character_modifier = {
			modifier = present_ruler
			years = 10
		}

		stress_impact = {
			base = medium_stress_impact_gain
			lazy = minor_stress_impact_gain
			stubborn = minor_stress_impact_gain
			content = minor_stress_impact_gain
			shy = medium_stress_impact_gain
			reclusive = medium_stress_impact_gain
			craven = medium_stress_impact_gain
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_energy = 1
			}
		}
	}

	option = { # What a great excuse!
		name = epidemic_events.5008.c

		add_character_modifier = {
			modifier = hiding_from_epidemic
			years = 10
		}

		stress_impact = {
			patient = miniscule_stress_impact_loss
			fickle = miniscule_stress_impact_loss
			compassionate = miniscule_stress_impact_loss
			shy = minor_stress_impact_loss
			reclusive = minor_stress_impact_loss
			craven = minor_stress_impact_loss
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 0.5
				ai_energy = 1
			}
		}
	}
}

# A merchant tries selling you a herbal sachet
# Customary 'Nick makes an event about good smells' event
# by Nick Meredith
epidemic_events.5009 = {
	type = character_event
	title = epidemic_events.5009.t
	desc = epidemic_events.5009.desc
	theme = plague
	override_background = { reference = market }
	override_effect_2d = { reference = flies }
	left_portrait = {
		character = root
		animation = steward
		camera = camera_event_left_crowning_observation
	}
	right_portrait = {
		character = scope:merchant
		animation = debating
		camera = camera_event_very_right
	}
	cooldown = { years = 10 }

	trigger = {
		is_available = yes
		#There be a plague in your subrealm
		any_sub_realm_county = {
			any_county_province = {
				OR = {
					county.holder = root
					squared_distance = {
						target = root.capital_province
						value <= squared_distance_medium #250 map-pixels. Roughly one Ireland away (top to bottom).
					}
				}
				any_province_epidemic = { }
			}
		}
	}

	immediate = {
		random_sub_realm_county = {
			limit = {
				any_county_province = {
					OR = {
						county.holder = root
						squared_distance = {
							target = root.capital_province
							value <= squared_distance_medium #250 map-pixels. Roughly one Ireland away (top to bottom).
						}
					}
					any_province_epidemic = { }
				}
			}
			random_county_province = {
				limit = {
					any_province_epidemic = { }
				}
				random_province_epidemic = {
					save_scope_as = epidemic_scope
				}
			}
		}

		random_pool_character = {
			province = root.location
			limit = {
				is_available_ai_adult = yes
				has_no_particular_noble_roots_trigger = yes
			}
			save_scope_as = merchant
		}
		if = { #As a backup create the character
			limit = {
				NOT = { exists = scope:merchant }
			}
			create_character = {
				template = generic_peasant_character
				location = root.location
				culture = root.capital_province.culture
				faith = root.capital_province.faith
				save_scope_as = merchant
				after_creation = {
					add_character_flag = created
				}
			}
		}
		hidden_effect_new_object = {
			scope:merchant = {
				move_to_pool = yes
				get_pressed_flower_species_effect = { LOCATION = root.location }
				create_artifact_pressed_flower_effect = { OWNER = scope:merchant }
				scope:newly_created_artifact = {
					add_artifact_modifier = artifact_stress_gain_1_modifier
					flag_as_trash_artifact = yes
				}
			}
		}
	}

	option = { # I'LL TAKE YOUR WHOLE STOCK
		name = epidemic_events.5009.a

		trigger = {
			OR = {
				has_trait = paranoid
				has_trait = generous
				has_trait = profligate
			}
		}
		trait = paranoid
		trait = generous
		trait = profligate
		
		scope:newly_created_artifact = { set_owner = root }
		
		pay_short_term_gold = {
			target = scope:merchant
			gold = tiny_gold_value
		}

		add_character_modifier = {
			modifier = overly_fragrant
			years = 15
		}

		stress_impact = {
			base = medium_stress_impact_loss
			greedy = major_stress_impact_gain
			trusting = miniscule_stress_impact_loss
			craven = miniscule_stress_impact_loss
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = -1
				ai_greed = -1
			}
		}
	}

	option = { # Buy a fine sachet
		name = epidemic_events.5009.b
		
		scope:newly_created_artifact = { set_owner = root }

		add_character_modifier = {
			modifier = sachet_protection
			years = 10
		}
		
		pay_short_term_gold = {
			target = scope:merchant
			gold = tiny_gold_value
		}

		stress_impact = {
			greedy = medium_stress_impact_gain
			generous = miniscule_stress_impact_loss
			profligate = miniscule_stress_impact_loss
			diligent = miniscule_stress_impact_loss
			stubborn = miniscule_stress_impact_loss
			fickle = minor_stress_impact_gain
			lazy = minor_stress_impact_gain
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_energy = 1
				ai_greed = -0.5
			}
		}
	}

	option = { # One please!
		name = epidemic_events.5009.c

		add_character_modifier = {
			modifier = sachet_protection
			years = 10
		}

		stress_impact = {
			cynical = minor_stress_impact_gain
			paranoid = minor_stress_impact_gain
			generous = miniscule_stress_impact_loss
			profligate = medium_stress_impact_gain
			trusting = miniscule_stress_impact_loss
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_energy = 1
			}
		}
	}

	option = { # Don't buy anything
		name = epidemic_events.5009.d

		stress_impact = {
			generous = medium_stress_impact_gain
			profligate = medium_stress_impact_gain
			trusting = minor_stress_impact_gain
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 1
			}
		}
	}
	after = {
		scope:merchant = {
			silent_disappearance_ai_effect = yes
		}
	}
}

# An apocalyptic plague enters your capital
# Only for cool capitals
# by Nick Meredith
epidemic_events.5010 = {
	type = character_event
	title = epidemic_events.5010.t
	desc = {
		desc = epidemic_events.5010.opening
		#What great capital do you have?
		first_valid = {
			triggered_desc = {
				trigger = {
					capital_barony = title:b_santiago
				}
				desc = epidemic_events.5010.santiago
			}
			triggered_desc = {
				trigger = {
					capital_barony = title:b_london
				}
				desc = epidemic_events.5010.london
			}
			triggered_desc = {
				trigger = {
					capital_barony = title:b_roma
				}
				desc = epidemic_events.5010.rome
			}
			triggered_desc = {
				trigger = {
					capital_barony = title:b_paris
				}
				desc = epidemic_events.5010.paris
			}
			triggered_desc = {
				trigger = {
					capital_barony = title:b_constantinople
				}
				desc = epidemic_events.5010.constantinople
			}
			triggered_desc = {
				trigger = {
					capital_barony = title:b_praha
				}
				desc = epidemic_events.5010.prague
			}
			triggered_desc = {
				trigger = {
					capital_barony = title:b_toledo
				}
				desc = epidemic_events.5010.toledo
			}
			triggered_desc = {
				trigger = {
					capital_barony = title:b_cairo
				}
				desc = epidemic_events.5010.cairo
			}
			triggered_desc = {
				trigger = {
					capital_barony = title:b_kanyakubja
				}
				desc = epidemic_events.5010.kanyakubja
			}
			triggered_desc = {
				trigger = {
					capital_barony = title:b_varanasi
				}
				desc = epidemic_events.5010.varanasi
			}
			triggered_desc = {
				trigger = {
					NOR = {
						capital_barony = title:b_cairo
						capital_barony = title:b_toledo
						capital_barony = title:b_praha
						capital_barony = title:b_constantinople
						capital_barony = title:b_paris
						capital_barony = title:b_roma
						capital_barony = title:b_london
						capital_barony = title:b_santiago
						capital_barony = title:b_kanyakubja
						capital_barony = title:b_varanasi
					}
				}
				desc = epidemic_events.5010.fallback
			}
		}
	}
	theme = plague
	override_background = { reference = ce1_condemned_village }
	left_portrait = {
		character = root
		animation = stress
	}
	cooldown = { years = 50 }

	trigger = {
		OR = {
			capital_barony = title:b_cairo
			capital_barony = title:b_toledo
			capital_barony = title:b_praha
			capital_barony = title:b_constantinople
			capital_barony = title:b_paris
			capital_barony = title:b_roma
			capital_barony = title:b_london
			capital_barony = title:b_santiago
			capital_barony = title:b_kanyakubja
			capital_barony = title:b_varanasi
		}

		# There be a plague in your capital
		location = {
			any_province_epidemic = {
				intensity = apocalyptic
			}
		}

		is_travelling = no
	}

	immediate = {
		capital_barony = {
			save_scope_as = capital
		}
		capital_barony.county = {
			save_scope_as = capital_region
		}
	}

	option = { # Donate some money
		name = epidemic_events.5010.a

		remove_short_term_gold = medium_gold_value

		scope:capital_region = {
			add_county_modifier = {
				modifier = plague_alms_donations
				years = 10
			}
		}

		stress_impact = {
			greedy = major_stress_impact_gain
			generous = medium_stress_impact_loss
			profligate = medium_stress_impact_loss
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 1
				ai_greed = -1
			}
		}
	}

	option = { # Be sad
		name = epidemic_events.5010.b
		add_legitimacy = miniscule_legitimacy_loss
		random_list = {
			1 = {
				send_interface_toast = {
					title = epidemic_events.5010.b.win
					left_icon = root

					add_character_modifier = {
						modifier = plague_determined_recover
						years = 15
					}
				}
			}
			1 = {
				send_interface_toast = {
					title = epidemic_events.5010.b.neutral
					left_icon = root

					add_character_modifier = {
						modifier = plague_the_long_road
						years = 15
					}
				}			
			}
			1 = {
				send_interface_toast = {
					title = epidemic_events.5010.b.lose
					left_icon = root

					add_character_modifier = {
						modifier = plague_crippling_sorrow
						years = 15
					}
				}			
			}
		}

		stress_impact = {
			greedy = medium_stress_impact_gain
			generous = miniscule_stress_impact_loss
			profligate = miniscule_stress_impact_loss
			diligent = miniscule_stress_impact_loss
			stubborn = miniscule_stress_impact_loss
			fickle = minor_stress_impact_gain
			lazy = minor_stress_impact_gain
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_energy = 1
				ai_greed = -0.5
			}
		}
	}
}

# BLACK DEATH EVENTS
# 5900-5999
#⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣀⣤⣴⣶⣾⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
#⠀⠀⠀⢀⣀⣤⣶⣿⣿⣿⣿⡿⠿⠛⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
#⠀⢰⣾⣿⣿⣿⡿⠟⠛⢉⣠⣤⣶⠿⠛⠀⣀⣀⣤⡤⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
#⠀⠀⠙⠛⢉⣁⣤⣶⠿⠟⢋⣁⣤⣴⣾⣿⠿⠛⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
#⠀⠀⠀⠀⠛⢋⣉⣤⣴⣾⣿⠿⠟⠛⢉⡀⢰⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
#⠀⠀⣠⣴⣿⠿⠿⠛⠋⣁⣤⣴⡾⠀⣾⣿⠀⣿⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
#⠀⠈⠉⠁⢠⣤⣶⣾⣄⠙⢿⣿⣿⠀⠿⠋⣠⣿⣿⣿⣷⣦⣄⡀⠀⠀⠀⠀⠀⠀
#⠀⠀⠀⠀⠘⣿⣿⣿⣿⣷⣄⠉⣿⣷⣶⣾⣿⣿⣿⣿⣿⣿⣿⣿⣦⣄⠀⠀⠀⠀
#⠀⠀⠀⠀⢀⠘⠿⣿⣿⣿⣿⠸⣿⣿⣿⣿⣿⣿⠿⠿⠿⠿⠿⠿⣿⣿⣧⡀⠀⠀
#⠀⠀⠰⣾⣿⣷⣦⡈⠛⠿⣿⣆⡉⠛⠋⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⠿⡄⠀
#⠀⠀⠀⡈⠻⢿⣿⣿⣷⣦⣌⡙⠛⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
#⠀⠀⣼⣿⣷⣤⡉⠛⠿⣿⣿⣿⣷⣶⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
#⠀⢠⣿⣿⣿⣿⣿⣷⣶⣤⣈⡙⠛⠿⢿⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
#⠀⠈⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠁⠀⠀⠈⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀

# The Black Death enters your lands
# by Nick Meredith
epidemic_events.5900 = {
	type = character_event
	window = fullscreen_event
	title = epidemic_events.5900.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					culture_has_asian_heritage_pillar_trigger = yes
				}
				desc = epidemic_events.5900.desc_asia
			}
			desc = epidemic_events.5900.desc
		}
	}
	theme = plague
	override_background = { reference = ce1_fullscreen_black_death }
	cooldown = { years = 100 }

	immediate = {
		add_character_flag = black_death_splash
		play_music_cue = black_death
		add_plague_county_modifiers = yes
		if = { #just to be sure the story about preparing for black death ends
			limit = {
				any_owned_story = {
					type = story_cycle_black_death
				}
			}
			random_owned_story = {
				type = story_cycle_black_death
				end_story = yes
			}
		}
	}

	option = {
		name = {
			text = epidemic_events.5900.christian
			trigger = {
				faith = {
					religion_tag = christianity_religion
				}
			}
		}
		name = {
			text = epidemic_events.5900.fallback
			trigger = {
				NOT = {
					faith = {
						religion_tag = christianity_religion
					}
				}
			}
		}
		
		add_stress = medium_stress_gain
	}

	after = {
		trigger_event = {
			id = health.3001 days = { court_physician_search_min court_physician_search_max }
		}
	}
}

# Demand your physician does an autopsy
# by Nick Meredith
epidemic_events.5901 = {
	type = character_event
	title = epidemic_events.5901.t
	desc = epidemic_events.5901.desc
	theme = plague
	override_background = { reference = physicians_study }
	left_portrait = {
		character = root
		animation = dismissal
	}
	right_portrait = {
		character = scope:physician
		animation = worry
	}
	cooldown = { years = 10 }

	trigger = {
		is_available_healthy_adult = yes
		#You have a court physician
		court_physician_available_trigger = yes
	}

	immediate = {
		save_court_physician_as_effect = { SCOPE_NAME = physician }
	}

	option = { # How about we do it together?
		name = epidemic_events.5901.a

		trigger = {
			OR = {
				has_trait = lifestyle_physician
				has_trait = lifestyle_herbalist
				has_trait = whole_of_body
			}
		}

		random = {
			chance = 75
			add_character_modifier = {
				modifier = plague_insights_gained
				years = 15
			}
			hidden_effect = {
				send_interface_toast = {
					title = epidemic_events.5901.a.tt
					left_icon = root
					right_icon = scope:physician
				}
			}
		}

		random = {
			chance = 10
			send_interface_toast = {
				title = epidemic_events.5901.a.tt.plague
				left_icon = root
				
				add_trait = bubonic_plague
			}
		}

		scope:physician = {
			random = {
				chance = 10

				add_trait = bubonic_plague
			}

			add_opinion = {
				modifier = respect_opinion
				opinion = 25
				target = root
			}
		}

		stress_impact = {
			brave = minor_stress_impact_loss
			craven = medium_stress_impact_gain
			diligent = miniscule_stress_impact_loss
			lazy = medium_stress_impact_gain
			trusting = miniscule_stress_impact_loss
			paranoid = minor_stress_impact_gain
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = 1
				ai_energy = 1
			}
		}
	}

	option = { # I demand it
		name = epidemic_events.5901.b

		random = {
			chance = 50
			add_character_modifier = {
				modifier = plague_insights_gained
				years = 15
			}
			hidden_effect = {
				send_interface_toast = {
					title = epidemic_events.5901.a.tt
					left_icon = root
				}
			}
		}

		scope:physician = {
			random = {
				chance = 10
				add_trait = bubonic_plague
			}

			add_opinion = {
				modifier = scared_opinion
				opinion = -15
				target = root
			}
		}

		stress_impact = {
			impatient = miniscule_stress_impact_loss
			patient = minor_stress_impact_gain
			callous = miniscule_stress_impact_loss
			compassionate = medium_stress_impact_gain
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = -1
			}
		}
	}

	option = { # All right, all right
		name = epidemic_events.5901.c

		reverse_add_opinion = {
			modifier = grateful_opinion
			opinion = 15
			target = scope:physician
		}

		stress_impact = {
			craven = minor_stress_impact_gain
			paranoid = minor_stress_impact_gain
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_energy = -0.5
			}
		}
	}
}

# Calm hordes of refugees
# by Nick Meredith
epidemic_events.5902 = {
	type = character_event
	title = epidemic_events.5902.t
	desc = epidemic_events.5902.desc
	theme = plague
	override_background = { reference = ep2_travel_bridge }
	left_portrait = {
		character = root
		animation = worry
	}
	right_portrait = {
		character = scope:marshal
		animation = marshal
	}
	cooldown = { years = 10 }

	trigger = {
		is_available_healthy_adult = yes

		any_realm_border_county = {
			any_county_province = {
				is_coastal = no #To ensure you don't get landlocked by yourself
			}
		}

		#You have a marshal in your locatiom
		cp:councillor_marshal ?= { location = root.location }
	}

	immediate = {
		location = {
			save_scope_as = province
		}

		cp:councillor_marshal = {
			save_scope_as = marshal
		}

		random_realm_border_county = {
			limit = {
				any_county_province = {
					is_coastal = no #To ensure you don't get landlocked by yourself
				}
			}
			save_scope_as = border_county
			random_county_province = {
				save_scope_as = border_province
			}
		}
	}

	option = { # Kill them! Kill them all!
		name = epidemic_events.5902.a

		trigger = {
			OR = {
				has_trait = callous
				has_trait = sadistic
				has_trait = paranoid
				dread > 50
			}
		}

		scope:border_province = {
			add_province_modifier = {
				modifier = brutal_crackdown
				years = 10
			}
		}

		if = {
			limit = {
				scope:marshal = {
					OR = {
						has_trait = callous
						has_trait = sadistic
					}
				}
			}
			scope:marshal = {
				add_opinion = {
					modifier = pleased_opinion
					opinion = 15
					target = root
				}
			}
		}
		else = {
			scope:marshal = {
				add_opinion = {
					modifier = cruelty_opinion
					opinion = -15
					target = root
				}
			}
		}

		stress_impact = {
			brave = minor_stress_impact_loss
			craven = medium_stress_impact_gain
			callous = miniscule_stress_impact_loss
			sadistic = miniscule_stress_impact_loss
			compassionate = medium_stress_impact_gain
			just = miniscule_stress_impact_loss
			arbitrary = medium_stress_impact_gain
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = -1
			}
		}
	}

	option = { # Set up shanty towns
		name = epidemic_events.5902.b

		remove_treasury_or_gold = medium_treasury_or_gold_value

		scope:border_province = {
			add_province_modifier = {
				modifier = shanty_towns
				years = 10
			}
		}

		stress_impact = {
			just = miniscule_stress_impact_loss
			arbitrary = minor_stress_impact_gain
			compassionate = miniscule_stress_impact_loss
			callous = medium_stress_impact_gain
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = 1
			}
		}
	}

	option = { # Turn them all away
		name = epidemic_events.5902.c

		scope:border_province = {
			add_province_modifier = {
				modifier = border_defended
				years = 10
			}
		}

		stress_impact = {
			craven = minor_stress_impact_gain
			paranoid = minor_stress_impact_loss
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_energy = -1
			}
		}
	}

	option = { # Let them in
		name = epidemic_events.5902.d

		scope:border_province = {
			add_province_modifier = {
				modifier = refugees_coddled
				years = 10
			}
		}

		stress_impact = {
			compassionate = minor_stress_impact_loss
			callous = medium_stress_impact_gain
			sadistic = medium_stress_impact_gain			
			paranoid = minor_stress_impact_gain
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 1
			}
		}
	}
}

# A family member warns you not to take a ride in the countryside
# by Nick Meredith
epidemic_events.5903 = {
	type = character_event
	title = epidemic_events.5903.t
	desc = epidemic_events.5903.desc
	theme = plague
	override_background = { reference = garden }
	left_portrait = {
		character = root
		animation = jockey_idle
		camera = camera_event_horse_left
	}
	right_portrait = {
		character = scope:family
		animation = worry
	}
	cooldown = { years = 10 }

	trigger = {
		is_available_healthy_adult = yes

		#You have a family member in your location
		any_close_family_member = {
			is_available = yes
			location = root.location
			age > 10
		}

		NOR = {
			age < 15
			has_trait = incapable
		}
	}

	immediate = {
		random_close_family_member = {
			limit = {
				is_available = yes
				location = root.location
				age > 10
			}
			save_scope_as = family
		}
	}

	option = { # You're probably right
		name = epidemic_events.5903.a

		add_character_modifier = {
			modifier = cautious_rider
			years = 10
		}

		reverse_add_opinion = {
			modifier = pleased_opinion
			opinion = 20
			target = scope:family
		}

		stress_impact = {
			brave = medium_stress_impact_gain
			craven = minor_stress_impact_loss
			trusting = minor_stress_impact_gain
			paranoid = minor_stress_impact_loss
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = -1
			}
		}
	}

	option = { # Bah, it'll be fine!
		name = epidemic_events.5903.b

		add_character_modifier = {
			modifier = dangerous_rides
			years = 10
		}

		stress_impact = {
			stubborn = miniscule_stress_impact_loss
			fickle = minor_stress_impact_gain
			compassionate = miniscule_stress_impact_loss
			callous = medium_stress_impact_gain
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = 1
			}
		}
	}
}

# A wandering preacher is spreading fear
# by Nick Meredith
epidemic_events.5904 = {
	type = character_event
	title = epidemic_events.5904.t
	desc = epidemic_events.5904.desc
	theme = plague
	override_background = { reference = market }
	left_portrait = {
		character = root
		animation = dismissal
	}
	right_portrait = {
		character = scope:doomsday_preacher
		animation = personality_zealous
	}
	cooldown = { years = 10 }

	trigger = {
		is_available_healthy_adult = yes
		is_landed = yes
		NOT = {
			has_trait = incapable
		}
	}

	immediate = {
		location.county = {
			random_county_province = {
				save_scope_as = doomsday_province
			}
		}

		if = {
			limit = {
				any_pool_character = {
					province = root.location
					is_adult = yes
					has_no_particular_noble_roots_trigger = yes
				}
			}
			random_pool_character = {
				province = root.location
				limit = {
					is_adult = yes
					has_no_particular_noble_roots_trigger = yes
				}
				weight = {
					base = 1
					modifier = {
						factor = 2
						OR = {
							has_trait = zealous
							has_trait = eccentric
						}
					}
				}
				save_scope_as = doomsday_preacher
			}
		}
		else = {
			create_character = {
				template = peasant_character
				dynasty = none
				location = root.location
				culture = root.location.culture
				faith = root.location.faith
				gender_female_chance = 50
				save_scope_as = doomsday_preacher
			}
		}
	}

	option = { # OH GOD YOU'RE RIGHT
		name = epidemic_events.5904.a

		trigger = {
			has_trait = paranoid
		}

		add_character_modifier = {
			modifier = overly_protective
			years = 10
		}

		stress_impact = {
			base = miniscule_stress_impact_loss
			diligent = miniscule_stress_impact_loss
			lazy = medium_stress_impact_gain
			brave = minor_stress_impact_gain
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_energy = 1
			}
		}
	}

	option = { # Lock them up for fearmongering
		name = epidemic_events.5904.b

		hard_imprison_character_effect = {
			TARGET = scope:doomsday_preacher
			IMPRISONER = root
		}

		scope:doomsday_province = {
			add_province_modifier = {
				modifier = angry_crowds
				years = 10
			}
		}

		stress_impact = {
			base = miniscule_stress_impact_loss
			just = medium_stress_impact_gain
			arbitrary = minor_stress_impact_loss
			compassionate = medium_stress_impact_gain
			callous = minor_stress_impact_loss
			sadistic = minor_stress_impact_loss
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = -1
			}
		}
	}

	option = { # Who are you to say that?
		name = epidemic_events.5904.c

		duel = {
			skill = learning
			target = scope:doomsday_preacher
			# You win the theological debate
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = epidemic_events.5904.c.tt.success
				root = {
					send_interface_toast = {
						title = epidemic_events.5904.c.tt.success
						left_icon = root
						right_icon = scope:doomsday_preacher

						scope:doomsday_province = {
							add_province_modifier = {
								modifier = allayed_fears
								years = 10
							}
						}
					}
				}
			}
			# You lose the debate
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = epidemic_events.5904.c.tt.failure
				root = {
					send_interface_toast = {
						title = epidemic_events.5904.c.tt.failure
						left_icon = root
						right_icon = scope:doomsday_preacher
						add_legitimacy = miniscule_legitimacy_loss
						scope:doomsday_province = {
							add_province_modifier = {
								modifier = mass_panic
								years = 10
							}
						}
					}
				}
			}
		}

		stress_impact = {
			just = miniscule_stress_impact_loss
			arbitrary = minor_stress_impact_gain
			zealous = miniscule_stress_impact_loss
			cynical = minor_stress_impact_gain
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_rationality = 1
				ai_zeal = 1
			}
		}
	}

	option = { # Bah, nobody will take them seriously
		name = epidemic_events.5904.d
		add_legitimacy = miniscule_legitimacy_loss
		scope:doomsday_province = {
			random = {
				chance = 15
				add_province_modifier = {
					modifier = mass_panic
					years = 10
				}
			}
			hidden_effect = {
				every_neighboring_province = {
					random = {
						chance = 15
						add_province_modifier = {
							modifier = mass_panic
							years = 10
						}
					}
				}
			}
		}

		custom_tooltip = epidemic_events.5904.d.tt

		stress_impact = {
			fickle = miniscule_stress_impact_loss
			stubborn = minor_stress_impact_gain
			lazy = miniscule_stress_impact_loss
			diligent = medium_stress_impact_gain
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_energy = 0.5
			}
		}
	}
}

# Rumours about the plague's nature begins to spread
# by Nick Meredith
epidemic_events.5905 = {
	type = character_event
	title = epidemic_events.5905.t
	desc = epidemic_events.5905.desc
	theme = plague
	override_background = { reference = tavern }
	left_portrait = {
		character = root
		animation = stress
	}
	right_portrait = {
		character = scope:peasant
		animation = fear
	}
	cooldown = { years = 10 }

	trigger = {
		is_available_healthy_adult = yes
		is_landed = yes
		drinks_alcohol_trigger = yes
	}

	immediate = {
		location.county = {
			random_county_province = {
				save_scope_as = province
			}
		}

		if = {
			limit = {
				any_pool_character = {
					province = root.location
					is_adult = yes
					has_no_particular_noble_roots_trigger = yes
				}
			}
			random_pool_character = {
				province = root.location
				limit = {
					is_adult = yes
					has_no_particular_noble_roots_trigger = yes
				}
				save_scope_as = peasant
			}
		}
		else = {
			create_character = {
				template = peasant_character
				dynasty = none
				location = root.location
				culture = root.location.culture
				faith = root.location.faith
				gender_female_chance = 50
				save_scope_as = peasant
			}
		}
	}

	option = { # Trust me, I'm a doctor
		name = epidemic_events.5905.a

		trigger = {
			OR = {
				has_trait = lifestyle_physician
				has_trait = lifestyle_herbalist
			}
		}

		scope:province = {
			hidden_effect = {
				every_neighboring_province = {
					random = {
						chance = 50
						add_province_modifier = {
							modifier = rumours_stifled
							years = 10
						}
					}
				}
			}
			add_province_modifier = {
				modifier = rumours_stifled
				years = 10
			}
		}

		custom_tooltip = epidemic_events.5905.a.tt

		stress_impact = {
			trusting = minor_stress_impact_loss
			paranoid = medium_stress_impact_gain
			arrogant = miniscule_stress_impact_loss
			humble = minor_stress_impact_gain
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = -1
			}
		}
	}

	option = { # Look, does that sound likely to you?
		name = epidemic_events.5905.b

		duel = {
			skills = { learning diplomacy }
			target = scope:peasant
			# You convince them
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = epidemic_events.5905.b.tt.success
				root = {
					send_interface_toast = {
						title = epidemic_events.5905.b.tt.success
						left_icon = root
						right_icon = scope:peasant

						scope:province = {
							hidden_effect = {
								every_neighboring_province = {
									random = {
										chance = 50
										add_province_modifier = {
											modifier = rumours_stifled
											years = 10
										}
									}
								}
							}
							add_province_modifier = {
								modifier = rumours_stifled
								years = 10
							}
						}

						custom_tooltip = epidemic_events.5905.a.tt
					}
				}
			}
			# They are unconvinced
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = epidemic_events.5905.b.tt.failure
				root = {
					send_interface_toast = {
						title = epidemic_events.5905.b.tt.failure
						left_icon = root
						right_icon = scope:peasant
						add_legitimacy = miniscule_legitimacy_loss
						scope:province = {
							hidden_effect = {
								every_neighboring_province = {
									random = {
										chance = 50
										add_province_modifier = {
											modifier = rumours_proliferated
											years = 10
										}
									}
								}
							}
							add_province_modifier = {
								modifier = rumours_proliferated
								years = 10
							}
						}

						custom_tooltip = epidemic_events.5905.a.tt
					}
				}
			}
		}

		stress_impact = {
			calm = miniscule_stress_impact_loss
			wrathful = minor_stress_impact_gain
			gregarious = miniscule_stress_impact_loss
			shy = medium_stress_impact_gain
			diligent = miniscule_stress_impact_loss
			lazy = minor_stress_impact_gain
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_energy = 0.5
			}
		}
	}

	option = { # Confronting them will only lead to more panic
		name = epidemic_events.5905.c

		random = {
			chance = 50
			add_legitimacy = miniscule_legitimacy_loss
			scope:province = {
				add_province_modifier = {
					modifier = uncaring_ruler
					years = 15
				}
			}
		}

		stress_impact = {
			fickle = miniscule_stress_impact_loss
			stubborn = minor_stress_impact_gain
			lazy = miniscule_stress_impact_loss
			diligent = medium_stress_impact_gain
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_energy = -1
			}
		}
	}
}

# A roving band of flagellants turn up
# by Nick Meredith
epidemic_events.5906 = {
	type = character_event
	title = epidemic_events.5906.t
	desc = epidemic_events.5906.desc
	theme = plague
	override_background = { reference = council_chamber }
	left_portrait = {
		character = root
		animation = stress
	}
	right_portrait = {
		character = scope:flagellant
		animation = paranoia
	}
	lower_center_portrait = scope:marshal
	cooldown = { years = 10 }

	trigger = {
		is_available_adult = yes
		is_landed = yes
		faith = {
			religion_tag = christianity_religion
		}
		exists = cp:councillor_marshal
	}

	immediate = {
		location.county = {
			random_county_province = {
				save_scope_as = doomsday_province
			}
		}

		cp:councillor_marshal = {
			save_scope_as = marshal
		}

		if = {
			limit = {
				any_pool_character = {
					province = root.location
					is_adult = yes
					has_no_particular_noble_roots_trigger = yes
					has_trait = flagellant
					is_imprisoned = no
				}
			}
			random_pool_character = {
				province = root.location
				limit = {
					is_adult = yes
					has_no_particular_noble_roots_trigger = yes
					has_trait = flagellant
					is_imprisoned = no
				}
				save_scope_as = flagellant
			}
		}
		else = {
			create_character = {
				template = peasant_character
				dynasty = none
				location = root.location
				culture = root.location.culture
				faith = root.location.faith
				gender_female_chance = 50
				trait = flagellant
				save_scope_as = flagellant
			}
		}

		save_scope_as = root_scope
	}

	option = { # You're tearing the faith apart, you maniacs!
		name = epidemic_events.5906.a

		trigger = {
			has_trait = zealous
		}

		duel = {
			skill = learning
			target = scope:flagellant
			# You convince them
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = epidemic_events.5906.a.tt.success
				send_interface_toast = {
					title = epidemic_events.5906.a.tt.success
					left_icon = root
					right_icon = scope:flagellant

					add_character_modifier = {
						modifier = flagellants_acquiesce
						years = 10
					}
				}
			}
			# They are unconvinced
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = epidemic_events.5906.a.tt.failure
				send_interface_toast = {
					title = epidemic_events.5906.a.tt.failure
					left_icon = root
					right_icon = scope:flagellant
					add_legitimacy = miniscule_legitimacy_loss
					scope:doomsday_province = {
						add_province_modifier = {
							modifier = unrestrained_flagellants
							years = 10
						}
					}
				}
			}
		}

		stress_impact = {
			base = miniscule_stress_impact_loss
			ambitious = minor_stress_impact_loss
			content = medium_stress_impact_gain
			diligent = miniscule_stress_impact_loss
			lazy = minor_stress_impact_gain
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_zeal = 1
			}
		}
	}

	option = { # You're right, honestly.
		name = epidemic_events.5906.b

		trigger = {
			OR = {
				has_trait = paranoid
				has_trait = fickle
			}
		}

		add_trait = flagellant

		stress_impact = {
			base = major_stress_impact_loss
			craven = miniscule_stress_impact_loss
			brave = minor_stress_impact_gain
			cynical = miniscule_stress_impact_loss
			zealous = medium_stress_impact_gain
		}

		ai_chance = {
			base = 0 # Don't do this unless you're already flagellant
			modifier = {
				add = 50
				has_trait = flagellant
			}
		}
	}


	option = { # Lock 'em up!
		name = epidemic_events.5906.c

		hard_imprison_character_effect = {
			TARGET = scope:flagellant
			IMPRISONER = root
		}

		random = {
			chance = 50
			scope:doomsday_province = {
				add_province_modifier = {
					modifier = pacified_flagellants
					years = 10
				}
				hidden_effect = {
					every_neighboring_province = {
						random = {
							chance = 25
							add_province_modifier = {
								modifier = pacified_flagellants
								years = 10
							}
						}
					}
				}
			}
		}

		custom_tooltip = epidemic_events.5906.d.tt

		stress_impact = {
			calm = minor_stress_impact_gain
			wrathful = miniscule_stress_impact_loss
			diligent = miniscule_stress_impact_loss
			lazy = minor_stress_impact_gain
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_energy = 0.5
			}
		}
	}

	option = { # Let them flagellate
		name = epidemic_events.5906.d

		random = {
			chance = 50
			faith = {
				change_fervor = {
					value = -5
					desc = fervor_loss_flagellants
				}
			}
			scope:doomsday_province = {
				add_province_modifier = {
					modifier = eager_populace
					years = 10
				}
			}
		}

		every_vassal_or_below = {
			vassal_stance = zealot
			custom = every_zealot_vassal
			add_opinion = {
				modifier = disrespect_opinion
				target = root
				opinion = -20
			}
		}

		stress_impact = {
			fickle = minor_stress_impact_loss
			stubborn = minor_stress_impact_gain
			lazy = medium_stress_impact_loss
			diligent = medium_stress_impact_gain
			zealous = medium_stress_impact_gain
			cynical = medium_stress_impact_loss
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_energy = -1
			}
		}
	}
}

# You develop a slight cough
# by Nick Meredith
epidemic_events.5907 = {
	type = character_event
	title = epidemic_events.5907.t
	desc = epidemic_events.5907.desc
	theme = plague
	override_background = { reference = bedchamber }
	left_portrait = {
		character = root
		animation = paranoia
	}
	lower_center_portrait = scope:physician
	cooldown = { years = 10 }

	trigger = {
		is_available_healthy_adult = yes
		court_physician_available_trigger = yes
	}

	immediate = {
		save_court_physician_as_effect = { SCOPE_NAME = physician }
	}

	option = { # I'll consult with my physician for some special treatments, just in case
		name = epidemic_events.5907.a

		remove_short_term_gold = minor_gold_value

		add_character_modifier = {
			modifier = regular_checkups
			years = 5
		}

		stress_impact = {
			base = miniscule_stress_impact_loss
			paranoid = major_stress_impact_loss #Throw 'em a bone!
			diligent = miniscule_stress_impact_loss
			lazy = minor_stress_impact_gain
			greedy = medium_stress_impact_gain
			profligate = minor_stress_impact_loss
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_rationality = 1
				ai_greed = -1
			}
		}
	}

	option = { # I'm sure it's nothing
		name = epidemic_events.5907.b

		random_list = {
			69 = { #You feel a little better
				desc = epidemic_events.5907.b.success
				send_interface_toast = {
					title = epidemic_events.5907.b.success
					left_icon = root
					
					add_stress = minor_stress_loss
				}
			}
			29 = { #You have a small sniffle
				desc = epidemic_events.5907.b.failure
				send_interface_toast = {
					title = epidemic_events.5907.b.failure
					left_icon = root

					add_character_modifier = {
						modifier = under_the_weather
						years = 5
					}
				}
			}
			2 = { #You have something nastier...
				desc = epidemic_events.5907.b.criticalfailure
				send_interface_toast = {
					title = epidemic_events.5907.b.criticalfailure
					left_icon = root

					add_stress = medium_stress_gain

					contract_disease_effect = { DISEASE = ill TREATMENT_EVENT = yes }
				}
			}
		}

		stress_impact = {
			brave = miniscule_stress_impact_loss
			craven = minor_stress_impact_gain
			trusting = miniscule_stress_impact_loss
			paranoid = minor_stress_impact_gain
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_energy = -0.5
			}
		}
	}
}

# Gravediggers demand more pay
# by Nick Meredith
epidemic_events.5908 = {
	type = character_event
	title = epidemic_events.5908.t
	desc = epidemic_events.5908.desc
	theme = plague
	override_background = { reference = throne_room }
	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		character = scope:gravedigger
		animation = beg
	}
	cooldown = { years = 10 }

	trigger = {
		is_available_adult = yes
		is_landed = yes
	}

	immediate = {
		location.county = {
			random_county_province = {
				save_scope_as = province
			}
		}

		if = {
			limit = {
				any_pool_character = {
					province = root.location
					is_adult = yes
					has_no_particular_noble_roots_trigger = yes
				}
			}
			random_pool_character = {
				province = root.location
				limit = {
					is_adult = yes
					has_no_particular_noble_roots_trigger = yes
				}
				save_scope_as = gravedigger
			}
		}
		else = {
			create_character = {
				template = peasant_character
				dynasty = none
				location = root.location
				culture = root.location.culture
				faith = root.location.faith
				gender_female_chance = 50
				save_scope_as = gravedigger
			}
		}
	}

	option = { # You'll be the next in the grave if you cross me laddie
		name = epidemic_events.5908.a

		trigger = {
			OR = {
				has_trait = callous
				has_trait = sadistic
				dread > 50
			}
		}

		scope:province = {
			add_province_modifier = {
				modifier = gravediggers_threatened
				years = 10
			}
		}

		reverse_add_opinion = {
			modifier = cruelty_opinion
			opinion = -25
			target = scope:gravedigger
		}

		stress_impact = {
			base = miniscule_stress_impact_loss
			paranoid = minor_stress_impact_gain
			compassionate = minor_stress_impact_gain
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_greed = 1
			}
		}
	}

	option = { # You'll be compensated fairly
		name = epidemic_events.5908.b

		remove_treasury_or_gold = medium_treasury_or_gold_value

		scope:province = {
			add_province_modifier = {
				modifier = gravediggers_compensated
				years = 15
			}
		}

		stress_impact = {
			generous = miniscule_stress_impact_loss
			greedy = medium_stress_impact_gain
			paranoid = miniscule_stress_impact_loss
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_energy = 0.5
				ai_greed = -1
			}
		}
	}

	option = { # Get out of my throneroom
		name = epidemic_events.5908.c

		scope:province = {
			add_province_modifier = {
				modifier = gravediggers_replaced
				years = 10
			}
		}

		stress_impact = {
			generous = medium_stress_impact_gain
			greedy = miniscule_stress_impact_loss
			paranoid = minor_stress_impact_gain
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_energy = -1
			}
		}
	}
}

epidemic_events.5998 = { #Black death story cycle pacing control
	hidden = yes

	immediate = {
		if = {
			limit = {
				any_neighboring_top_liege_realm_owner = {
					has_character_flag = black_death_splash
				}
			}
			if = {
				limit = {
					has_character_flag = black_death_closer
				}
				remove_character_flag = black_death_closer
			}
			add_character_flag = black_death_nearby
		}
		else_if = {
			limit = {
				any_neighboring_top_liege_realm_owner = {
					any_neighboring_top_liege_realm_owner = {
						has_character_flag = black_death_splash
					}
				}
			}	
			add_character_flag = black_death_closer
		}
		if = {
			limit = {
				OR = {
					has_character_flag = black_death_closer
					has_character_flag = black_death_nearby
				}
				NOT = {
					has_character_flag = black_death_info_event
				}
			}
			trigger_event = {
				id = epidemic_events.5999
				days = { 2 4 }
			}
		}
	}
}

# The Black Death is closing in
# Used to trigger Black Death Story cycle
# by Nick Meredith
epidemic_events.5999 = {
	type = character_event
	title = epidemic_events.5999.t
	desc = epidemic_events.5999.desc
	theme = plague
	override_background = { reference = study }
	left_portrait = {
		character = root
		animation = worry
	}
	cooldown = { years = 100 }

	trigger = {
		is_ai = no
		has_dlc_feature = legends_of_the_dead
		is_available_adult = yes
		is_travelling = no
		NOT = {
			any_sub_realm_county = { #Black Plague is already here, no need to talk about it closing in
				any_county_province = {
					any_province_epidemic = {
						this = global_var:black_death
					}
				}
			}
		}
	}

	on_trigger_fail = {
		trigger_event = {
			id = epidemic_events.5999
			days = { 7 14 }
		}
	}

	immediate = {		
		play_music_cue = mx_cue_death
		add_character_flag = black_death_info_event
		if = {
			limit = {
				NOR = {
					has_character_flag = black_death_closer
					has_character_flag = black_death_nearby
				}
			}
			add_character_flag = black_death_closer
		}
	}

	option = { # Ha, let them die!
		name = epidemic_events.5999.a

		trigger = {
			has_trait = callous
		}

		flavor = epidemic_events.5999.a.tt

		stress_impact = {
			base = medium_stress_impact_loss
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = -1
			}
		}
	}

	option = { # The end times are upon us!
		name = epidemic_events.5999.b

		trigger = {
			has_trait = paranoid
		}

		flavor = epidemic_events.5999.b.tt

		add_character_modifier = {
			modifier = plague_tales
			years = 15
		}

		stress_impact = {
			base = minor_stress_impact_gain
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_rationality = 0.5
				ai_greed = -1
			}
		}
	}

	option = { # Oh no
		name = {
			trigger = {
				faith = {
					religion_tag = christianity_religion
				}
			}

			text = epidemic_events.5999.c.christian
		}
		name = {
			trigger = {
				NOT = {
					faith = {
						religion_tag = christianity_religion
					}
				}
			}
			text = epidemic_events.5999.c.notchristian
		}

		stress_impact = {
			base = miniscule_stress_impact_gain
			craven = minor_stress_impact_gain
			paranoid = minor_stress_impact_gain
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_energy = -0.5
			}
		}
	}
}

# The Black Death enters the lands near your camp
# by Nick Meredith
epidemic_events.6000 = {
	type = character_event
	window = fullscreen_event
	title = epidemic_events.5900.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					culture_has_asian_heritage_pillar_trigger = yes
				}
				desc = epidemic_events.5900.desc_asia
			}
			desc = epidemic_events.5900.desc
		}
	}
	theme = plague
	override_background = { reference = ce1_fullscreen_black_death }
	cooldown = { years = 100 }

	trigger = {
		OR = {
			has_government = landless_adventurer_government
			is_landless_administrative = yes
		}
		location = {
			any_province_epidemic = {
				intensity = apocalyptic
				epidemic_type.epidemic_trait = trait:bubonic_plague
			}
		}
	}

	immediate = {
		add_character_flag = black_death_splash
		play_music_cue = black_death
	}

	option = {
		name = {
			text = epidemic_events.5900.christian
			trigger = {
				faith = {
					religion_tag = christianity_religion
				}
			}
		}
		name = {
			text = epidemic_events.5900.fallback
			trigger = {
				NOT = {
					faith = {
						religion_tag = christianity_religion
					}
				}
			}
		}
		
		add_stress = medium_stress_gain
	}

	after = {
		trigger_event = {
			id = health.3001 days = { court_physician_search_min court_physician_search_max }
		}
	}
}
