namespace = physician_epidemic_events

############################
## Superstitious physician irritating religious officials
## 1000
## by James Beaumont
############################
physician_epidemic_events.1000 = {
	type = character_event
	title = physician_epidemic_events.1000.t
	desc = physician_epidemic_events.1000.desc
	theme = plague
	override_effect_2d = { reference = flies }
	left_portrait = {
		character = scope:zealous_courtier
		animation = anger
		camera = camera_event_very_left
	}
	right_portrait = {
		character = scope:physician
		animation = physician
	}
	cooldown = { years = 5 } 
	trigger = {
		realm_has_any_nearby_epidemic = { INTENSITY = major SIZE = 1 }
		court_position:court_physician_court_position ?= {
			probably_superstitious = yes
			is_available_ai_adult = yes
		}
		OR = {
			any_vassal = {
				probably_anti_superstitious = yes
				is_available_ai_adult = yes
			}
			any_courtier_or_guest = {
				probably_anti_superstitious = yes
				is_available_ai_adult = yes
			}
		}
	}

	immediate = {
		get_random_nearby_realm_epidemic = { INTENSITY = major }
		court_position:court_physician_court_position = { save_scope_as = physician }
		if = {
			limit = {
				any_vassal = {
					probably_anti_superstitious = yes
					is_available_ai_adult = yes
				}
			}
			random_vassal = {
				limit = {
					probably_anti_superstitious = yes
					is_available_ai_adult = yes
				}
				weight = {
					base = 1
					modifier = {
						add = 10
						is_of_major_interest_to_root_trigger = yes
					}
					modifier = {
						add = 5
						is_of_minor_interest_to_root_trigger = yes
					}
					modifier = {
						add = ai_zeal
					}
				}
				save_scope_as = zealous_courtier
			}
		}
		else = {
			random_courtier_or_guest = {
				limit = {
					probably_anti_superstitious = yes
					is_available_ai_adult = yes
				}
				weight = {
					base = 1
					modifier = {
						add = 10
						is_of_major_interest_to_root_trigger = yes
					}
					modifier = {
						add = 5
						is_of_minor_interest_to_root_trigger = yes
					}
					modifier = {
						add = ai_zeal
					}
				}
				save_scope_as = zealous_courtier
			}
		}
	}

	option = { # How about I suggest a better solution instead
		name = physician_epidemic_events.1000.a
		trigger = {
			has_trait = whole_of_body
		}
		add_character_modifier = {
			modifier = ce1_non_heretical_solution
			years = 5
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = 1
				ai_compassion = 1
				ai_rationality = 1
			}
		}
	}

	option = { # Oh hush you bore, I'm sure this will work
		name = physician_epidemic_events.1000.b
		add_character_modifier = {
			modifier = ce1_unorthodox_epidemic_treatment
			years = 5
		}
		scope:zealous_courtier = {
			progress_towards_rival_effect = {
				REASON = rival_heretical_physician
				CHARACTER = scope:physician
				OPINION = 0
			}
		}
		stress_impact = {
			zealous = medium_stress_impact_gain
			cynical = medium_stress_impact_gain
			eccentric = minor_stress_impact_loss
			witch = minor_stress_impact_loss
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = -1
				ai_rationality = -0.1
				ai_compassion = 1
			}
		}
	}

	option = { # I don't think so
		name = physician_epidemic_events.1000.c
		scope:zealous_courtier = {
			add_opinion = {
				target = root
				modifier = relieved_opinion
				opinion = 20
			}
		}
		add_piety = medium_piety_gain
		stress_impact = {
			witch = medium_stress_impact_gain
			eccentric = medium_stress_impact_gain
			diligent = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = 1
				ai_rationality = 0.1
				ai_compassion = -1
			}
		}
	}
}

############################
## Physician calls for a quarantine of infected counties
## 1010
## by James Beaumont
############################
physician_epidemic_events.1010 = {
	type = character_event
	title = physician_epidemic_events.1010.t
	desc = physician_epidemic_events.1010.desc
	theme = plague
	override_effect_2d = { reference = flies }
	left_portrait = {
		character = root
		animation = worry
		camera = camera_event_crowd
	}
	right_portrait = {
		character = scope:physician
		animation = debating
		camera = camera_event_very_right
	}
	cooldown = { years = 5 } 
	trigger = {
		court_position:court_physician_court_position ?= {
			is_available_ai_adult = yes
		}
		realm_has_any_nearby_epidemic = { SIZE = 5 INTENSITY = major }
	}

	immediate = {
		get_random_nearby_realm_epidemic = { INTENSITY = major }
		court_position:court_physician_court_position = { save_scope_as = physician }
	}

	option = { # Oh well alrighty then
		name = physician_epidemic_events.1010.a
		add_character_modifier = {
			modifier = ce1_major_quarantine
			years = 5
		}
		every_sub_realm_county = {
			custom = every_infected_county
			limit = {
				any_county_province = {
					any_province_epidemic = {
						this = scope:epidemic_scope
					}
				}
			}
			add_county_modifier = {
				modifier = ce1_major_quarantine_county
				years = 5
			}
		}
		stress_impact = {
			greedy = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
			just = medium_stress_impact_gain
			cynical = minor_stress_impact_gain
			impatient = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = -1
				ai_compassion = -1
				ai_rationality = 1
			}
		}
	}

	option = { # This is not at all worth it
		name = physician_epidemic_events.1010.b
		stress_impact = {
			callous = medium_stress_impact_gain
			diligent = medium_stress_impact_gain
			scholar = minor_stress_impact_gain
			patient = minor_stress_impact_gain
			trusting = minor_stress_impact_gain
			generous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 1
				ai_honor = -1
				ai_energy = -1
			}
		}
	}
}

###############################
## PHYSICIAN EPIDEMIC TREATMENT
## 1020
## by James Beaumont
###############################
physician_epidemic_events.1020 = {
	type = character_event
	title = physician_epidemic_events.1020.t
	desc = {
		desc = physician_epidemic_events.1020.start.desc
		first_valid = { #Disease type
			triggered_desc = {
				trigger = { scope:epidemic.epidemic_type.epidemic_trait = trait:typhus }
				desc = disease_desc_short_typhus
			}
			triggered_desc = {
				trigger = { scope:epidemic.epidemic_type.epidemic_trait = trait:consumption }
				desc = disease_desc_short_consumption
			}
			triggered_desc = {
				trigger = { scope:epidemic.epidemic_type.epidemic_trait = trait:great_pox }
				desc = disease_desc_short_smallpox
			}
			triggered_desc = {
				trigger = { scope:epidemic.epidemic_type.epidemic_trait = trait:smallpox }
				desc = disease_desc_short_smallpox
			}
			triggered_desc = {
				trigger = { scope:epidemic.epidemic_type.epidemic_trait = trait:bubonic_plague }
				desc = disease_desc_short_plague
			}
			triggered_desc = {
				trigger = { scope:epidemic.epidemic_type.epidemic_trait = trait:measles }
				desc = disease_desc_short_measles
			}
			triggered_desc = {
				trigger = { scope:epidemic.epidemic_type.epidemic_trait = trait:ergotism }
				desc = disease_desc_short_ergotism
			}
			triggered_desc = {
				trigger = { scope:epidemic.epidemic_type.epidemic_trait = trait:dysentery }
				desc = disease_desc_short_dysentery
			}
			desc = missing_epidemic
		}
		desc = physician_epidemic_events.1020.start.desc2
		random_valid = {
			triggered_desc = {
				trigger = {
					OR = {
						scope:epidemic = { outbreak_intensity <= minor }
						scope:physician = {
							NOR = {
								has_trait = lifestyle_physician
								has_trait = lifestyle_mystic
							}
						}
					}
				}
				desc = physician_epidemic_events.1020.safe_recommendation.desc
			}
			triggered_desc = {
				trigger = {
					OR = {
						scope:epidemic = { outbreak_intensity >= major }
						scope:physician = {
							NOR = {
								has_trait = lifestyle_physician
								has_trait = lifestyle_mystic
							}
						}
					}
					scope:physician = {
						NOT = { has_trait = lifestyle_mystic }
					}
				}
				desc = physician_epidemic_events.1020.risky_recommendation.desc
			}
			triggered_desc = {
				trigger = {
					scope:physician = { has_trait = lifestyle_mystic }
				}
				desc = physician_epidemic_events.1020.mystic_recommendation.desc
			}
		}
		desc = physician_epidemic_events.1020.end.desc
	}
	theme = plague
	override_background = {
		trigger = { scope:physician ?= { is_travelling = yes } exists = scope:background_terrain_scope }
		reference = terrain_scope
	}
	override_background = {
		reference = physicians_study
	}
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = {
				OR = {
					has_trait = cynical
					has_trait = callous
					has_trait = deceitful
					has_trait = sadistic
				}
			}
			animation = eyeroll
		}
		triggered_animation = {
			trigger = {
				OR = {
					has_trait = compassionate
					has_trait = generous
					has_trait = trusting
					has_trait = gregarious
				}
			}
			animation = sadness
		}
		animation = thinking
	}
	right_portrait = {
		character = scope:physician
		triggered_animation = {
			trigger = { scope:epidemic = { outbreak_intensity >= major } }
			animation = worry
		}
		triggered_animation = {
			trigger = { scope:physician = { ai_rationality >= 0 } }
			animation = personality_rational
		}
		triggered_animation = {
			trigger = { scope:physician = { ai_rationality < -50 } }
			animation = eccentric
		}
		animation = idle
	}

	immediate = {
		scope:physician.location ?= { save_scope_as = background_terrain_scope }
	}

	#Minimal epidemic prevention
	option = {
		name = physician_epidemic_events.1020.a
		epidemic_prevention_effect = { PREVENTION_LEVEL = 1 PHYSICIAN = scope:physician }
		ai_chance = { base = 10 }
	}

	#Moderate epidemic prevention
	option = {
		name = physician_epidemic_events.1020.b
		epidemic_prevention_effect = { PREVENTION_LEVEL = 2 PHYSICIAN = scope:physician }
		ai_chance = { base = 1 }
	}
	
	#Superstitious epidemic prevention
	option = {
		trigger = {
			scope:physician = {
				OR = {
					has_trait = lifestyle_mystic
					has_trait = eccentric
				}
			}
		}
		name = physician_epidemic_events.1020.c
		epidemic_prevention_effect = { PREVENTION_LEVEL = 3 PHYSICIAN = scope:physician }
		ai_chance = {
			base = 0.5
			modifier = {
				add = -0.5
				ai_zeal >= 0
			}
		}
	}

	#No treatment
	option = {
		name = physician_epidemic_events.1020.d
		
		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 = 0 }
	}
}

# Minor success
physician_epidemic_events.1021 = {
	type = character_event
	title = physician_epidemic_events.1021.t
	desc = physician_epidemic_events.1021.desc
	theme = plague
	override_background = {
		trigger = { scope:physician ?= { is_travelling = yes } exists = scope:background_terrain_scope }
		reference = terrain_scope
	}
	override_background = {
		reference = physicians_study
	}
	left_portrait = {
		character = scope:physician
		animation = physician
	}

	immediate = {
		add_character_modifier = {
			modifier = minor_epidemic_treatment
			years = 10
		}
	}

	#Neato!
	option = {
		name = physician_epidemic_events.1021.a
		
		if = { # Admin governors gain some XP when successful
			limit = {
				is_governor = yes
				has_trait = governor
			}
			increase_governance_effect = { VALUE = 2 }
		}
		
		ai_chance = { base = 10 }
	}
}

# Minor fail
physician_epidemic_events.1022 = {
	type = character_event
	title = physician_epidemic_events.1022.t
	desc = physician_epidemic_events.1022.desc
	theme = plague
	override_background = {
		trigger = { scope:physician ?= { is_travelling = yes } exists = scope:background_terrain_scope }
		reference = terrain_scope
	}
	override_background = {
		reference = physicians_study
	}
	left_portrait = {
		character = scope:physician
		animation = shock
	}

	immediate = {
		add_character_modifier = {
			modifier = minor_epidemic_treatment_failed
			years = 10
		}
	}

	

	#Chastise
	option = {
		name = health.3107.b

		chastise_physician_effect = yes
		
		ai_chance = {
			factor = 30
			modifier = {
				scope:physician = { has_character_modifier = chastised_physician_modifier }
				add = -20
			}
		}
	}

	#Oh well ¯\_(ツ)_/¯
	option = {
		name = health.3107.c

		forgive_physician_effect = yes
		
		ai_chance = {
			factor = 20
			ai_value_modifier = {
				max = 80
				ai_compassion = 2.5
				ai_vengefulness = -2.5
			}
		}
	}

	#Imprison!
	option = {
		name = health.3107.d

		imprison_physician_effect = yes

		ai_chance = {
			factor = 30
			ai_value_modifier = {
				ai_compassion = -0.5
			}
		}
	}

	#Execute!
	option = {
		name = health.3107.e

		execute_physician_effect = yes

		ai_chance = {
			factor = 15
			ai_value_modifier = {
				ai_compassion = -1
			}
		}
	}
}

# Major success
physician_epidemic_events.1023 = {
	type = character_event
	title = physician_epidemic_events.1023.t
	desc = physician_epidemic_events.1023.desc
	theme = plague
	override_background = {
		trigger = { scope:physician ?= { is_travelling = yes } exists = scope:background_terrain_scope }
		reference = terrain_scope
	}
	override_background = {
		reference = physicians_study
	}
	left_portrait = {
		character = scope:physician
		animation = admiration
	}

	immediate = {
		add_character_modifier = {
			modifier = major_epidemic_treatment
			years = 10
		}
	}

	#Neato!
	option = {
		name = physician_epidemic_events.1023.a
		
		if = { # Admin governors gain some XP when successful
			limit = {
				is_governor = yes
				has_trait = governor
			}
			increase_governance_effect = { VALUE = 4 }
		}
		
		ai_chance = { base = 10 }
	}
}

# Major fail
physician_epidemic_events.1024 = {
	type = character_event
	title = physician_epidemic_events.1024.t
	desc = physician_epidemic_events.1024.desc
	theme = plague
	override_background = {
		trigger = { scope:physician ?= { is_travelling = yes } exists = scope:background_terrain_scope }
		reference = terrain_scope
	}
	override_background = {
		reference = physicians_study
	}
	left_portrait = {
		character = scope:physician
		animation = shock
	}

	immediate = {
		add_character_modifier = {
			modifier = major_epidemic_treatment_failed
			years = 10
		}
		every_sub_realm_county = {
			custom = every_infected_county
			limit = {
				any_county_province = {
					any_province_epidemic = {
						this = scope:epidemic
					}
				}
			}
			change_development_progress_with_overflow = -45
		}
	}

	

	#Chastise
	option = {
		name = health.3107.b

		chastise_physician_effect = yes
		
		ai_chance = {
			factor = 30
			modifier = {
				scope:physician = { has_character_modifier = chastised_physician_modifier }
				add = -20
			}
		}
	}

	#Oh well ¯\_(ツ)_/¯
	option = {
		name = health.3107.c

		forgive_physician_effect = yes
		
		ai_chance = {
			factor = 20
			ai_value_modifier = {
				max = 80
				ai_compassion = 2.5
				ai_vengefulness = -2.5
			}
		}
	}

	#Imprison!
	option = {
		name = health.3107.d

		imprison_physician_effect = yes

		ai_chance = {
			factor = 30
			ai_value_modifier = {
				ai_compassion = -0.5
				ai_vengefulness = 1
			}
		}
	}

	#Execute!
	option = {
		name = health.3107.e

		execute_physician_effect = yes

		ai_chance = {
			factor = 15
			ai_value_modifier = {
				ai_compassion = -1
				ai_vengefulness = 2.5
			}
		}
	}
}

# Critical success
physician_epidemic_events.1025 = {
	type = character_event
	title = physician_epidemic_events.1025.t
	desc = physician_epidemic_events.1025.desc
	theme = plague
	override_background = {
		trigger = { scope:physician ?= { is_travelling = yes } exists = scope:background_terrain_scope }
		reference = terrain_scope
	}
	override_background = {
		reference = physicians_study
	}
	left_portrait = {
		character = scope:physician
		animation = manic
	}

	immediate = {
		add_character_modifier = {
			modifier = critical_epidemic_treatment
			years = 10
		}
	}

	#Neato!
	option = {
		name = physician_epidemic_events.1025.a
		
		if = { # Admin governors gain some XP when successful
			limit = {
				is_governor = yes
				has_trait = governor
			}
			increase_governance_effect = { VALUE = 6 }
		}
		
		ai_chance = { base = 10 }
	}
}

# Critical fail
physician_epidemic_events.1026 = {
	type = character_event
	title = physician_epidemic_events.1026.t
	desc = physician_epidemic_events.1026.desc
	theme = plague
	override_background = {
		trigger = { scope:physician ?= { is_travelling = yes } exists = scope:background_terrain_scope }
		reference = terrain_scope
	}
	override_background = {
		reference = physicians_study
	}
	left_portrait = {
		character = scope:physician
		animation = manic
	}

	immediate = {
		add_character_modifier = {
			modifier = critical_epidemic_treatment_failed
			years = 10
		}
		every_sub_realm_county = {
			custom = every_infected_county
			limit = {
				any_county_province = {
					any_province_epidemic = {
						this = scope:epidemic
					}
				}
			}
			change_development_progress_with_overflow = -150
		}
	}

	

	#Chastise
	option = {
		name = health.3107.b

		chastise_physician_effect = yes
		
		ai_chance = {
			factor = 30
			modifier = {
				scope:physician = { has_character_modifier = chastised_physician_modifier }
				add = -20
			}
		}
	}

	#Oh well ¯\_(ツ)_/¯
	option = {
		name = health.3107.c

		forgive_physician_effect = yes
		
		ai_chance = {
			factor = 20
			ai_value_modifier = {
				max = 80
				ai_compassion = 2.5
				ai_vengefulness = -2.5
			}
		}
	}

	#Imprison!
	option = {
		name = health.3107.d

		imprison_physician_effect = yes

		ai_chance = {
			factor = 30
			ai_value_modifier = {
				ai_compassion = -0.5
				ai_vengefulness = 1
			}
		}
	}

	#Execute!
	option = {
		name = health.3107.e

		execute_physician_effect = yes

		ai_chance = {
			factor = 15
			ai_value_modifier = {
				ai_compassion = -1
				ai_vengefulness = 2.5
			}
		}
	}
}

###############################
## PHYSICIAN BOOK
## 1030
## by James Beaumont
###############################
physician_epidemic_events.1030 = {
	type = character_event
	title = physician_epidemic_events.1030.t
	desc = physician_epidemic_events.1030.desc
	theme = plague
	override_effect_2d = { reference = flies }
	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		character = scope:physician
		animation = writing
	}
	cooldown = { years = 10 }

	trigger = {
		exists = court_position:court_physician_court_position
		court_position:court_physician_court_position = {
			is_available_ai_adult = yes
		}
		realm_has_any_nearby_epidemic = { INTENSITY = major SIZE = 1 }
	}

	immediate = {
		court_position:court_physician_court_position = { save_scope_as = physician }
		get_random_nearby_realm_epidemic = { INTENSITY = major }
	}

	#Go for it king!
	option = {
		name = physician_epidemic_events.1030.a
		remove_short_term_gold = medium_gold_value
		custom_tooltip = may_get_cool_book_tt
		hidden_effect = {
			scope:physician = {
				duel = {
					skill = learning
					value = high_skill_rating
					# Failure
					50 = {
						compare_modifier = {
							value = scope:duel_value
							multiplier = -3.5
							min = -49
						}
						modifier = {
							scope:physician = { has_trait = lifestyle_physician }
							factor = 0.5
						}
						modifier = {
							scope:physician = {
								has_trait = lifestyle_physician
								has_trait_xp = {
									trait = lifestyle_physician
									value >= 50
								}
							}
							factor = 0.5
						}
						modifier = {
							scope:physician = {
								has_trait = lifestyle_physician
								has_trait_xp = {
									trait = lifestyle_physician
									value >= 100
								}
							}
							factor = 0.5
						}
						root = {
							send_interface_toast = {
								title = physician_epidemic_events.1030.a.failure
								left_icon = root
								right_icon = scope:physician
								custom_tooltip = book_is_gibberish
							}
						}
					}
					50 = { # Win
						compare_modifier = {
							value = scope:duel_value
							multiplier = 3.5
							min = -49
						}
						duel = { # How much did I win by?
							skill = learning
							value = high_skill_rating
							50 = { # Not much
								compare_modifier = {
									value = scope:duel_value
									multiplier = -3.5
									min = -49
								}
								root = {
									set_artifact_rarity_masterwork = yes
									send_interface_toast = {
										title = physician_epidemic_events.1030.a.success
										left_icon = root
										right_icon = scope:physician
										create_artifact = {
											name = pharmaceuticals
											description = pharmaceuticals_desc
											type = miscellaneous
											modifier = artifact_epidemic_resistance_1_modifier
											modifier = artifact_negate_health_penalty_add_1_modifier
											visuals = pocket_book
											quality = scope:quality
											wealth = scope:wealth
											creator = scope:physician
										}
									}
								}
							}
							50 = { # Okay
								compare_modifier = {
									value = scope:duel_value
									multiplier = 3.5
									min = -49
								}
								root = {
									set_artifact_rarity_famed = yes
									send_interface_toast = {
										title = physician_epidemic_events.1030.a.success
										left_icon = root
										right_icon = scope:physician
										create_artifact = {
											name = pharmaceuticals
											description = pharmaceuticals_desc
											type = miscellaneous
											modifier = artifact_epidemic_resistance_4_modifier
											modifier = artifact_negate_health_penalty_add_2_modifier
											visuals = pocket_book
											quality = scope:quality
											wealth = scope:wealth
											creator = scope:physician
										}
									}
								}
							}
							15 = { # Bigly
								compare_modifier = {
									value = scope:duel_value
									multiplier = 3.5
									min = -49
								}
								root = {
									set_artifact_rarity_illustrious = yes
									send_interface_toast = {
										title = physician_epidemic_events.1030.a.success
										left_icon = root
										right_icon = scope:physician
										create_artifact = {
											name = pharmaceuticals
											description = pharmaceuticals_desc
											type = miscellaneous
											modifier = artifact_epidemic_resistance_7_modifier
											modifier = artifact_negate_health_penalty_add_2_modifier
											visuals = pocket_book
											quality = scope:quality
											wealth = scope:wealth
											creator = scope:physician
										}
									}
								}
							}
						}
					}
				}
			}
		}
		ai_chance = {
			base = 10
			modifier = {
				factor = 0
				short_term_gold < major_gold_value
			}
			ai_value_modifier = {
				ai_greed = -1
				ai_rationality = 1
			}
		}
	}

	#How much for a bloody book?
	option = {
		name = physician_epidemic_events.1030.b
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = 1
				ai_rationality = -1
			}
		}
	}
}

###############################
## DISTRIBUTE ALMS
## 1040
## by James Beaumont
###############################
physician_epidemic_events.1040 = {
	type = character_event
	title = physician_epidemic_events.1040.t
	desc = physician_epidemic_events.1040.desc
	theme = plague
	override_effect_2d = { reference = flies }
	left_portrait = {
		character = root
		animation = pondering
		camera = camera_event_left_away_3_4
	}
	right_portrait = {
		character = scope:physician
		animation = obsequious_bow
		camera = camera_event_right_away
	}
	
	cooldown = { years = 20 }

	trigger = {
		realm_has_any_nearby_epidemic = { INTENSITY = major SIZE = 1 }
		exists = court_position:court_physician_court_position
		court_position:court_physician_court_position = {
			is_available_ai_adult = yes
		}
	}

	immediate = {
		get_random_nearby_realm_epidemic = { INTENSITY = major }
		court_position:court_physician_court_position = { save_scope_as = physician }
	}

	# Let's go touch some lepers
	option = {
		name = physician_epidemic_events.1040.a
		add_piety = major_piety_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_royal_touch
				years = 10
			}
		}
		if = {
			limit = {
				NOT = {
					has_trait = scope:epidemic_scope.epidemic_type.epidemic_trait
				}
			}
			if = {
				limit = {
					NOT = {
						has_trait = scope:epidemic_scope.epidemic_type.epidemic_trait
					}
				}
				if = {
					limit = {
						scope:epidemic_scope.epidemic_type.epidemic_trait = trait:smallpox
					}
					random = {
						chance = 5
						contract_disease_effect = { DISEASE = smallpox TREATMENT_EVENT = yes }
					}
				}
				else_if = {
					limit = {
						scope:epidemic_scope.epidemic_type.epidemic_trait = trait:measles
					}
					random = {
						chance = 5
						contract_disease_effect = { DISEASE = measles TREATMENT_EVENT = yes }
					}
				}
				else_if = {
					limit = {
						scope:epidemic_scope.epidemic_type.epidemic_trait = trait:dysentery
					}
					random = {
						chance = 5
						contract_disease_effect = { DISEASE = dysentery TREATMENT_EVENT = yes }
					}
				}
				else_if = {
					limit = {
						scope:epidemic_scope.epidemic_type.epidemic_trait = trait:bubonic_plague
					}
					random = {
						chance = 5
						contract_disease_effect = { DISEASE = bubonic_plague TREATMENT_EVENT = yes }
					}
				}
				else_if = {
					limit = {
						scope:epidemic_scope.epidemic_type.epidemic_trait = trait:typhus
					}
					random = {
						chance = 5
						contract_disease_effect = { DISEASE = typhus TREATMENT_EVENT = yes }
					}
				}
				else_if = {
					limit = {
						scope:epidemic_scope.epidemic_type.epidemic_trait = trait:consumption
					}
					random = {
						chance = 5
						contract_disease_effect = { DISEASE = consumption TREATMENT_EVENT = yes }
					}
				}
			}
		}
		stress_impact = {
			sadistic = medium_stress_impact_gain
			callous = medium_stress_impact_gain
			arrogant = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50
			modifier = {
				factor = 0
				gold < minor_gold_value
			}
			ai_value_modifier = {
				ai_compassion = 1
			}
		}
	}

	#I will absolutely not do this are you insane
	option = {
		name = physician_epidemic_events.1040.b
		add_piety = minor_piety_loss
		stress_impact = {
			humble = minor_stress_impact_gain
			compassionate = medium_stress_impact_gain
			zealous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = -1
			}
		}
	}
}

###############################
## Physician is helping soldiers
## 1050
## by James Beaumont
###############################
physician_epidemic_events.1050 = {
	type = character_event
	title = physician_epidemic_events.1050.t
	desc = physician_epidemic_events.1050.desc
	theme = plague
	override_effect_2d = { reference = flies }
	left_portrait = {
		character = root
		animation = anger
	}
	right_portrait = {
		character = scope:physician
		animation = prisonhouse
	}
	lower_right_portrait = {
		character = scope:enemy
	}

	cooldown = { years = 20 }

	trigger = {
		is_at_war = yes
		exists = court_position:court_physician_court_position
		realm_has_any_nearby_epidemic = { INTENSITY = major SIZE = 1 }
		court_position:court_physician_court_position = {
			is_available_ai_adult = yes
			OR = { # Would be willing to heal the enemy
				has_trait = compassionate
				has_trait = forgiving
				has_trait = just
				has_trait = zealous
			}
		}
	}

	immediate = {
		get_random_nearby_realm_epidemic = { INTENSITY = major }
		court_position:court_physician_court_position = { save_scope_as = physician }
		random_primary_war_enemy = {
			limit = {
				is_ai = yes
			}
			save_scope_as = enemy
		}
	}

	# Very good work, please continue
	option = {
		name = physician_epidemic_events.1050.a
		add_piety = major_piety_gain
		add_character_modifier = {
			modifier = war_doctor
			years = 10
		}
		scope:enemy = {
			add_character_modifier = {
				modifier = war_doctor
				years = 10
			}
			add_opinion = {
				modifier = impressed_opinion
				opinion = 50
				target = root
			}
		}
		stress_impact = {
			compassionate = medium_stress_impact_loss
			forgiving = medium_stress_impact_loss
			sadistic = medium_stress_impact_gain
			callous = medium_stress_impact_gain
			arrogant = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = 1
				ai_rationality = -0.1
			}
		}
	}

	#I demand that this stop at once!
	option = {
		name = physician_epidemic_events.1050.b
		add_character_modifier = {
			modifier = war_doctor
			years = 10
		}
		scope:physician = {
			progress_towards_rival_effect = {
				REASON = rival_prevented_from_protecting_sick
				CHARACTER = root
				OPINION = default_rival_opinion
			}
		}
		stress_impact = {
			humble = minor_stress_impact_gain
			compassionate = medium_stress_impact_gain
			zealous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = -1
				ai_rationality = 0.1
			}
		}
	}
}

###############################
## Physician advises you to banish all infected characters from your court
## 1060
## by James Beaumont
###############################
physician_epidemic_events.1060 = {
	type = character_event
	title = physician_epidemic_events.1060.t
	desc = physician_epidemic_events.1060.desc
	theme = plague
	override_background = physicians_study
	override_effect_2d = { reference = flies }
	left_portrait = {
		character = scope:physician
		animation = physician
	}
	right_portrait = {
		character = scope:gross_sick_person
		animation = cough
	}

	trigger = {
		exists = court_position:court_physician_court_position
		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 = {
					count >= 1
					intensity >= major
					save_temporary_scope_as = epidemic_to_check
					root = {
						any_close_or_extended_family_member = {
							is_courtier_of = root
							has_trait = scope:epidemic_to_check.epidemic_type.epidemic_trait
						}
					}
				}
			}
		}
		court_position:court_physician_court_position = {
			is_available_ai_adult = yes
		}
	}

	immediate = {
		get_random_nearby_realm_epidemic = { INTENSITY = major }
		court_position:court_physician_court_position = { save_scope_as = physician }
		random_close_or_extended_family_member = {
			limit = {
				is_courtier_of = root
				has_trait = scope:epidemic_scope.epidemic_type.epidemic_trait
			}
			save_scope_as = gross_sick_person
		}
	}

	# Drastic times call for drastic measures
	option = {
		name = physician_epidemic_events.1060.a
		every_courtier_or_guest = {
			custom = every_infected_courtier_or_guest
			limit = {
				has_trait_with_flag = epidemic_disease
			}
			banish = yes # banish_effect not used for unlanded
		}
		every_courtier_or_guest = {
			custom = every_uninfected_courtier_or_guest
			limit = {
				NOT = { 
					has_trait_with_flag = epidemic_disease
				}
			}
			add_character_modifier = {
				modifier = ce1_banishment_resistance
				years = 10
			}
		}
		add_character_modifier = {
			modifier = ce1_banishment_resistance
			years = 10
		}
		stress_impact = {
			base = medium_stress_impact_gain
			callous = medium_stress_impact_loss
			sadistic = medium_stress_impact_loss
			arbitrary = medium_stress_impact_loss
			arrogant = medium_stress_impact_loss
			forgiving = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = -1
				ai_greed = 0.5
				ai_rationality = 0.5
			}
		}
	}

	#I will not banish my own kin!
	option = {
		name = physician_epidemic_events.1060.b
		add_piety = medium_piety_gain
		every_courtier_or_guest = {
			custom = every_infected_courtier_or_guest
			limit = {
				has_trait_with_flag = epidemic_disease
			}
			add_opinion = {
				modifier = grateful_opinion
				opinion = 25
				target = root
			}
		}
		stress_impact = {
			callous = medium_stress_impact_gain
			sadistic = medium_stress_impact_gain
			arbitrary = medium_stress_impact_gain
			arrogant = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = 1
				ai_greed = -0.5
				ai_rationality = -0.5
				ai_vengefulness = -0.5
			}
		}
	}
}
