namespace = epidemic_events

epidemic_events.2001 = { #defender trying to status quo the vassal war cuz he's sick
	type = character_event
	title = epidemic_events.2001.t
	desc = epidemic_events.2001.desc
	theme = plague
	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		character = scope:pleading_vassal
		animation = beg
	}
	lower_right_portrait = {
		character = scope:attacking_vassal
	}
	override_background = {
		reference = army_camp
	}
	override_effect_2d = {
		reference = fog
	}	
	cooldown = { years = 30 }

	trigger = {
		is_available_adult = yes
		any_vassal = {
			is_ai = yes
			is_at_war = yes
			any_character_war = {
				primary_attacker = {
					is_vassal_of = root
					is_ai = yes
				}
				is_defender = prev
				attacker_war_score > 30
			}
			realm_has_any_epidemic = { SIZE = 3 INTENSITY = minor }
			current_gold_value > minor_gold_value
		}
	}

	immediate = {
		random_vassal = {
			limit = {
				is_ai = yes
				is_at_war = yes
				any_character_war = {
					primary_attacker = {
						is_vassal_of = root
						is_ai = yes
					}
					is_defender = prev
					attacker_war_score > 30
				}
				realm_has_any_epidemic = { SIZE = 2 INTENSITY = minor }
				current_gold_value > minor_gold_value				
			}
			save_scope_as = pleading_vassal
			get_random_realm_epidemic = { INTENSITY = minor }
			random_character_war = {
				limit = {
					primary_attacker = {
						is_vassal_of = root
						is_ai = yes
					}
					is_defender = prev
					attacker_war_score > 30
				}
				save_scope_as = vassal_war
			}
		}
		scope:vassal_war = {
			primary_attacker = {
				save_scope_as = attacking_vassal
			}
		}
		set_variable = {
			name = gold_transfer_value
			value = scope:pleading_vassal.current_gold_value
		}
		scope:pleading_vassal = {
			pay_short_term_gold = {
				target = root
				gold = current_gold_value
			}
			hidden_effect = {
				if = {
					limit = {
						NOT = { has_trait = scope:epidemic_scope.epidemic_type.epidemic_trait }
					}
					random = {
						chance = 25
						infect_with_epidemic = scope:epidemic_scope
					}
				}
			}
		}
	}

	option = { #send a royal order for white peace
		name = epidemic_events.2001.c

		duel = {
			skill = diplomacy
			target = scope:attacking_vassal

			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 1
				}
				send_interface_toast = {
					title = epidemic_events.2001.c.success
					left_icon = scope:pleading_vassal
					right_icon = scope:attacking_vassal
					scope:vassal_war = {
						end_war = white_peace
					}
					add_legitimacy_effect = { LEGITIMACY = minor_legitimacy_gain }
					scope:pleading_vassal = {
						add_opinion = {
							modifier = thankful_opinion
							opinion = 30
							target = root
						}
					}						
				}
			}

			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -1
				}
				send_interface_toast = {
					title = epidemic_events.2001.c.failure
					left_icon = scope:pleading_vassal
					right_icon = scope:attacking_vassal		
					scope:pleading_vassal = {
						add_opinion = {
							modifier = disappointed_opinion
							opinion = -25
							target = root
						}
					}
					custom_tooltip = epidemic_events.2001.danger
				}
				hidden_effect = {
					random = {
						chance = 10
						trigger_event = {
							months = 4
							id = epidemic_events.2002
						}
					}
				}
			}
		}

		stress_impact = {
			greedy = medium_stress_gain
			compassionate = medium_stress_loss
			just = medium_stress_loss
		}

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

	option = { #imprison the other guy from traveling to you during a pandemic and wash whatever he touched
		name = epidemic_events.2001.b
		flavor = epidemic_events.2001.b.desc

		imprison = {
			target = scope:pleading_vassal
			type = dungeon
		}

		scope:pleading_vassal = {
			add_opinion = {
				modifier = angry_opinion
				opinion = -40
				target = root
			}
		}
		custom_tooltip = epidemic_events.2001.danger
		hidden_effect = {
			random = {
				chance = 10
				trigger_event = {
					months = 4
					id = epidemic_events.2002
				}
			}
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = low_chance_impact_positive_ai_value
				ai_rationality = low_chance_impact_positive_ai_value
			}
		}

		stress_impact = {
			compassionate = medium_stress_gain
			just = medium_stress_gain
			paranoid = major_stress_loss
		}
	}

	option = { #pay money to end war
		name = epidemic_events.2001.a

		scope:vassal_war = {
			end_war = white_peace
		}
		pay_treasury_or_gold = {
			target = scope:attacking_vassal
			value = {
				value = root.var:gold_transfer_value
				multiply = 0.5
			}
		}

		scope:pleading_vassal = {
			add_opinion = {
				modifier = thankful_opinion
				opinion = 30
				target = root
			}
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = low_chance_impact_negative_ai_value
				ai_compassion = low_chance_impact_positive_ai_value
			}
		}

		stress_impact = {
			greedy = medium_stress_gain
			compassionate = medium_stress_loss
		}


	}

	after = {
		hidden_effect = {
			if = {
				limit = {
					scope:pleading_vassal = {
						has_trait = scope:epidemic_scope.epidemic_type.epidemic_trait
						is_imprisoned = no
					}
				}
				random_list = {
					60 = {
						random_courtier = {
							limit = {
								NOT = { has_trait = scope:epidemic_scope.epidemic_type.epidemic_trait }
							}
							save_scope_as = infected_courtier
						}
						send_interface_toast = {
							title = epidemic_events.2001.epidemic_spread.t
							left_icon = scope:pleading_vassal
							right_icon = scope:infected_courtier
							scope:infected_courtier = {
								infect_with_epidemic = scope:epidemic_scope
							}
						}
					}
					20 = {
						if = {
							limit = {
								NOT = { has_trait = scope:epidemic_scope.epidemic_type.epidemic_trait }
							}
						}
						random_courtier = {
							limit = {
								NOT = { has_trait = scope:epidemic_scope.epidemic_type.epidemic_trait }
							}
							save_scope_as = first_infected_courtier
						}
						random_courtier = {
							limit = {
								NOT = {
									has_trait = scope:epidemic_scope.epidemic_type.epidemic_trait
									scope:first_infected_courtier = this
								}
							}
							save_scope_as = second_infected_courtier
						}
						send_interface_toast = {
							title = epidemic_events.2001.epidemic_spread.t
							left_icon = scope:second_infected_courtier
							right_icon = scope:first_infected_courtier
							scope:first_infected_courtier = {
								infect_with_epidemic = scope:epidemic_scope
							}
							scope:second_infected_courtier = {
								infect_with_epidemic = scope:epidemic_scope
							}
						}
					}
				}
			}
		}
	}
}

epidemic_events.2002 = {
	type = character_event
	title = epidemic_events.2002.t
	desc = epidemic_events.2002.desc
	theme = plague

	left_portrait = {
		character = root
		animation = stress
	}
	lower_left_portrait = scope:attacking_vassal
	lower_right_portrait = scope:pleading_vassal

	trigger = {
		exists = scope:epidemic_scope
		exists = scope:vassal_war
		is_ai = no
	}

	override_background = {
		reference = battlefield
	}
	override_effect_2d = {
		reference = fog
	}

	immediate = {
		if = {
			limit = {
				scope:epidemic_scope = {
					outbreak_intensity = minor
				}
			}
			scope:epidemic_scope = {
				set_epidemic_outbreak_intensity = major
			}
		}
		else = {
			scope:epidemic_scope = {
				set_epidemic_outbreak_intensity = apocalyptic
			}
		}
		add_legitimacy = miniscule_legitimacy_loss
	}

	option = {
		name = epidemic_events.2002.a
		stress_impact = {
			base = minor_stress_gain
		}
	}

}

epidemic_events.2003 = { #maa are dying from war
	type = character_event
	title = epidemic_events.2003.t
	desc = epidemic_events.2003.desc
	theme = plague

	left_portrait = {
		character = root
		animation = stress 
	}

	right_portrait = {
		character = scope:marshal
		animation = marshal_shield
	}

	override_background = {
		reference = army_camp
	}

	override_effect_2d = {
		reference = flies
	}

	cooldown = { years = 8 } 

	trigger = {
		is_available_adult = yes
		any_held_county = {
			any_county_province = {
				has_stationed_regiment = yes
				any_province_epidemic = {
					intensity >= minor
				}
			}
			save_temporary_scope_as = first_county
		}
		any_held_county = {
			this != scope:first_county
			any_county_province = {
				has_stationed_regiment = yes
				any_province_epidemic = {
					intensity >= minor
				}
			}
		}

		exists = cp:councillor_marshal
	}
	immediate = {
		random_held_county = {
			limit = {
				any_county_province = {
					has_stationed_regiment = yes
					any_province_epidemic = {
						intensity >= minor
					}
				}
			}
			random_county_province = {
				limit = {
					has_stationed_regiment = yes
					any_province_epidemic = {
						intensity >= minor
					}
				}
				save_scope_as = first_epidemic_province
				random_province_epidemic = {
					save_scope_as = epidemic_scope
				}
			}
			save_scope_as = first_epidemic_county
		}
		random_held_county = {
			limit = {
				this != scope:first_epidemic_county
				any_county_province = {
					has_stationed_regiment = yes
					any_province_epidemic = {
						intensity >= minor
					}
				}
			}
			random_county_province = {
				limit = {
					has_stationed_regiment = yes
					any_province_epidemic = {
						intensity >= minor
					}
				}
				save_scope_as = second_epidemic_province
			}
		}
		cp:councillor_marshal = { save_scope_as = marshal }
	}

	option = { #pay more to get more recruits
		name = epidemic_events.2003.a
		
		every_maa_regiment = { 
			change_maa_troops_count = {
				value = {
					value = this.maa_current_troops_count
					multiply = -0.25
				}
			}
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = low_chance_impact_negative_ai_value
				ai_rationality = low_chance_impact_positive_ai_value
			}
		}

		stress_impact = {
			greedy = medium_stress_gain
			ambitious = medium_stress_loss
		}
	}

	option = { #dont care, press peasants as maa
		name = epidemic_events.2003.b
		
		scope:first_epidemic_province = {
			add_province_modifier = {
				modifier = epidemic_pressed_levies
				years = 5
			}
		}
		
		scope:second_epidemic_province = {
			add_province_modifier = {
				modifier = epidemic_pressed_levies
				years = 5
			}
		}
		
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = low_chance_impact_positive_ai_value
				ai_compassion = low_chance_impact_negative_ai_value
				ai_rationality = low_chance_impact_positive_ai_value
			}
		}

		stress_impact = {
			just = medium_stress_gain
		}
	}

	option = { #close the barracks!
		name = epidemic_events.2003.c
		
		scope:first_epidemic_province = {
			add_province_modifier = {
				modifier = epidemic_closed_barracks
				years = 5
			}
		}
		
		scope:second_epidemic_province = {
			add_province_modifier = {
				modifier = epidemic_closed_barracks
				years = 5
			}
		}

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

		stress_impact = {
			paranoid = medium_stress_loss
		}
	}
}

epidemic_events.2004 = { #Medicinal Jar creation event
	hidden = yes

	trigger = {
		is_available_adult = yes
		court_position:court_physician_court_position ?= {
			is_available_ai_adult = yes
			culture != root.culture
			NOT = {
				has_character_flag = physician_medicinal_jar
			}
		}
		realm_has_any_nearby_epidemic = { SIZE = 4 INTENSITY = minor }
	}

	cooldown = { years = 160 }

	immediate = {
		court_position:court_physician_court_position = {
			save_scope_as = physician
		} 
		scope:physician = {
			create_artifact = {
				name = medicine_jar
				description = medicine_jar_desc
				type = miscellaneous
				visuals = glazed_jar
				modifier = artifact_epidemic_resistance_1_modifier
				modifier = artifact_learning_lifestyle_xp_2_modifier
				save_scope_as = medicine_jar
				quality = 50
			}
			add_character_flag = physician_medicinal_jar
		}
		
		if = {
			limit = {
				scope:physician = {
					can_equip_artifact = scope:medicine_jar
				}
			}
			scope:medicine_jar = {
				equip_artifact_to_owner = yes
			}
			get_random_nearby_realm_epidemic = { INTENSITY = minor }
			trigger_event = {
				days = { 3 7 }
				id = epidemic_events.2005
			}
		}
	}
	
}

epidemic_events.2005 = { #Glass jar artifact
	type = character_event
	title = epidemic_events.2005.t
	desc = epidemic_events.2005.desc
	theme = plague

	left_portrait = {
		character = root
		animation = personality_rational
	}

	right_portrait = {
		character = scope:physician
		animation = physician
	}

	artifact = {
		target = scope:medicine_jar
		position = lower_center_portrait
	}

	override_background = {
		reference = physicians_study
	}
	
	trigger = {
		scope:physician = { is_alive = yes }
	}

	option = { #politely ask the physisican to part with the jar
		name = epidemic_events.2005.a
		duel = {
			skill = diplomacy
			target = scope:physician

			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 1
				}
				send_interface_toast = {
					title = epidemic_events.2005.a.success
					left_icon = scope:physician
					scope:medicine_jar = {
						set_owner = root
					}
				}
			}
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -1
				}
				send_interface_toast = {
					title = epidemic_events.2005.a.failure
					left_icon = scope:physician
					scope:medicine_jar = {
						add_artifact_modifier = artifact_physician_aptitude_1_modifier
					}						
				}
			}
		}

		stress_impact = {
			craven = minor_stress_loss
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = low_chance_impact_negative_ai_value
			}
		}


	}

	option = { #violently grab the jar from physician
		name = epidemic_events.2005.b

		scope:physician = {
			add_opinion = {
				modifier = fp3_stole_from_me
				opinion = -25
				target = root
			}
			progress_towards_rival_effect = {
				REASON = rival_stole_artifact
				CHARACTER = root
				OPINION = 0
			}
		}

		scope:medicine_jar = {
			set_owner = root
		}
		
		stress_impact = {
			temperate = medium_stress_gain
			just = medium_stress_gain
			paranoid = medium_stress_loss
			wrathful = medium_stress_loss
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = low_chance_impact_positive_ai_value
				ai_energy = low_chance_impact_positive_ai_value
				ai_rationality = low_chance_impact_negative_ai_value
			}
		}
	}

	option = { #let phycisian keep his precious jar
		name = epidemic_events.2005.c
		scope:medicine_jar = {
			add_artifact_modifier = artifact_physician_aptitude_1_modifier
		}

		stress_impact = {
			temperate = medium_stress_loss
			just = medium_stress_loss
			trusting = medium_stress_loss
		}

		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_compassion = low_chance_impact_positive_ai_value
				ai_rationality = low_chance_impact_positive_ai_value
				ai_greed = low_chance_impact_negative_ai_value
			}
		}
	}

}

epidemic_events.2006 = { #Dancing plague
	type = character_event
	title = epidemic_events.2006.t
	desc = epidemic_events.2006.desc
	theme = plague
	override_background = courtyard
	override_effect_2d = { reference = flies }

	left_portrait = {
		character = root
		animation = stress
	}

	right_portrait = {
		character = scope:dance_victim
		animation = dancing_plague
	}

	trigger = {
		is_available_adult = yes
		OR = {
			is_ai = no
			this = top_liege
		}
		capital_province = {
			any_province_epidemic = {
				#epidemic_type = epidemic_type:ergotism
				intensity < apocalyptic
			}
		}
		NOT = {
			has_character_flag = had_event_dancing_plague
		}
	}

	weight_multiplier = {
		base = 1
		modifier = { #Since a big outbreak occurred in Aachen 1374
			add = 9
			capital_province = {
				county = title:c_aachen
			}
			current_date >= 1370.1.1
			current_date <= 1380.1.1
		}
		modifier = { #Since an outbreak occurred in Erfurt 1247
			add = 9
			capital_province = {
				duchy = title:d_thuringia
			}
			current_date >= 1240.1.1
			current_date <= 1250.1.1
		}
		modifier = { #Since an outbreak occurred in Kolbigk 1021
			add = 9
			capital_province = {
				geographical_region = ghw_region_saxony
			}
			current_date >= 1020.1.1
			current_date <= 1030.1.1
			
		}
		modifier = {  #Since it historically occurred in Europe
			add = 1
			capital_province = {
				geographical_region = world_europe
			}			
		}
		
	}
 
	immediate = {
		capital_province = {
			random_province_epidemic = {
				limit = {
					epidemic_type = epidemic_type:ergotism
					outbreak_intensity < apocalyptic
				}
				save_scope_as = dancing_plague
			}
		}
		create_character = {
			template = servant_character
			dynasty = none
			location = root.capital_province
			save_scope_as = dance_victim
		}
		hidden_effect = {
			scope:dance_victim = {
				add_trait = ergotism
			}
		}

		scope:dancing_plague = {
			set_epidemic_outbreak_intensity = apocalyptic
		}

		add_character_flag = had_event_dancing_plague
	}

	option = { #let's join the paaartey
		trigger = {
			has_trait = eccentric
		}
		name = epidemic_events.2006.a
		add_character_modifier = {
			modifier = ce1_gone_dancing
			years = 2
		}
		
		hidden_effect = {
			random = {
				chance = 10
				trigger_event = { id = health.1017 days = { 5 15 } } #You contract ergotism
			}
		}
		
		stress_impact = {
			eccentric = medium_stress_loss
		}

		ai_chance = {
			base = 100
		}

	}

	option = { #slay the demon!
		trigger = {
			has_trait = zealous
		}
		name = epidemic_events.2006.d
		add_piety = minor_piety_gain

		scope:dance_victim = {
			death = {
				death_reason = death_murder
				killer = root
			}
		}

		stress_impact = {
			zealous = medium_stress_loss
		}

		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_compassion = low_chance_impact_negative_ai_value
				ai_zeal = low_chance_impact_positive_ai_value
			}
		}
	}

	option = { #eh, every dance stops eventually, right?
		name = epidemic_events.2006.b
		
		capital_county = {
			add_county_modifier = {
				modifier = dance_plague_modifier
				years = 4
			}
		}

		stress_impact = {
			compassionate = minor_stress_gain
		}
		
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_compassion = low_chance_impact_negative_ai_value
			}
		}
	}

	option = { #tie them down! allieviate their pains somehow
		name = epidemic_events.2006.c
		
		hidden_effect = {
			random = {
				chance = 10
				trigger_event = { id = health.1017 days = { 5 15 } } #You contract ergotism
			}
		}

		stress_impact = {
			lustful = medium_stress_loss
			compassionate = medium_stress_loss
		}
		
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_compassion = low_chance_impact_positive_ai_value
			}
		}
	}
}
