namespace = RIP

# Dancing Plague Starts
province_event = {
	id = RIP.4000

	is_triggered_only = yes # on_outbreak
	hide_window = yes

	trigger = {
		disease = dancing_plague
	}

	immediate = {
		save_event_target_as = dancing_plague_outbreak_location

		owner = {
			narrative_event = { id = RIP.4001 }

			if = {
				limit = { independent = no }

				any_liege = {
					narrative_event = { id = RIP.4001 }
				}
			}
		}
	}
}

narrative_event = { # Dancing Plague Notification
	id = RIP.4001
	title = EVTNAME_RIP_4001
	desc = EVTDESC_RIP_4001
	picture = GFX_evt_dancing
	border = GFX_event_narrative_frame_religion

	is_triggered_only = yes

	ai = no

	option = {
		name = EVTOPTA_RIP_4001
	}
}

character_event = { # Dancing looks inviting, join in?
	id = RIP.4002
	desc = EVTDESC_RIP_4002
	picture = GFX_evt_dancing
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTA_RIP_4002

		custom_tooltip = { text = join_in_dance }

		if = {
			limit = { has_assigned_minor_title = title_court_physician }

			character_event = {
				id = RIP.4003 # Court Physician recommends you rest.
				days = 5
				random = 10
			}
		}
		else_if = {
			limit = { has_character_flag = got_dancing_plague }

			character_event = {
				id = RIP.4005 # Go out into the streets and get the Dancing Plague!
				days = 5
				random = 10
			}
		}
		else_if = {
			limit = { is_landed = yes }

			character_event = {
				id = RIP.4004 # Go out into the streets and become Dancing Queen!
				days = 5
				random = 10
			}
		}
	}

	option = {
		name = EVTOPTB_RIP_4002

		custom_tooltip = {
			text = refuse_to_join_in_dance

			if = {
				limit = { has_character_flag = got_dancing_plague }

				random_list = {
					50 = { # Nothing happens.
						clr_character_flag = got_dancing_plague
						set_character_flag = immune_dancing_plague
					}

					50 = { # Can't resist dancing!
						mult_modifier = {
							factor = 2
							trait = gluttonous
						}

						mult_modifier = {
							factor = 2
							trait = hedonist
						}

						mult_modifier = {
							factor = 0.5
							trait = temperate
						}

						mult_modifier = {
							factor = 0.5
							trait = gardener
						}

						set_character_flag = forced_to_dance

						character_event = {
							id = RIP.4005
							days = 10
							random = 10
						}
					}
				}
			}
		}

		ai_chance = { factor = 0 }
	}
}

character_event = { # Court Physician recommends rest.
	id = RIP.4003
	desc = EVTDESC_RIP_4003
	picture = GFX_evt_poke_king_in_chest
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	immediate = {
		random_courtier_or_vassal = {
			limit = { has_minor_title = title_court_physician }
			save_event_target_as = target_physician
		}
	}

	option = { # Agree
		name = EVTOPTA_RIP_4003

		custom_tooltip = { text = refuse_to_join_in_dance }

		reverse_opinion = {
			name = opinion_glad
			who = event_target:target_physician
			years = 5
		}

		hidden_effect = {
			if = {
				limit = { has_character_flag = got_dancing_plague }

				random_list = {
					50 = { # Nothing happens.
						clr_character_flag = got_dancing_plague
						set_character_flag = immune_dancing_plague
					}

					50 = { # No, I must dance!
						mult_modifier = {
							factor = 2
							trait = gluttonous
						}

						mult_modifier = {
							factor = 2
							trait = hedonist
						}

						mult_modifier = {
							factor = 0.5
							trait = temperate
						}

						mult_modifier = {
							factor = 0.5
							trait = gardener
						}

						set_character_flag = forced_to_dance

						character_event = {
							id = RIP.4005
							days = 5
							random = 10
						}
					}
				}
			}
		}
	}

	option = { # No! I want to dance.
		name = EVTOPTB_RIP_4003

		custom_tooltip = { text = join_in_dance }

		reverse_opinion = {
			name = opinion_irritated
			who = event_target:target_physician
			years = 5
		}

		if = {
			limit = { has_character_flag = got_dancing_plague }

			character_event = {
				id = RIP.4005 # Go out into the streets and get the Dancing Plague!
				days = 5
				random = 10
			}
		}
		else_if = {
			limit = { is_landed = yes }

			character_event = {
				id = RIP.4004 # Go out into the streets and become Dancing Queen!
				days = 5
				random = 10
			}
		}
	}
}

# Become Dancing Queen!
character_event = {
	id = RIP.4004
	desc = EVTDESC_RIP_4004
	picture = GFX_evt_dancing
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTA_RIP_4004

		prestige = 50

		remove_trait_silently_stressed_effect = yes
		remove_trait_silently_depressed_effect = yes

		if = {
			limit = { is_female = yes }

			add_character_modifier = {
				name = dancing_queen
				years = 5
			}
		}
		else = {
			add_character_modifier = {
				name = dancing_king
				years = 5
			}
		}
	}
}

# Get Dancing Plague!
character_event = {
	id = RIP.4005
	picture = GFX_evt_dancing
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	desc = {
		text = EVTDESCA_RIP_4005
		trigger = {
			NOT = { has_character_flag = forced_to_dance }
		}
	}
	desc = {
		text = EVTDESCB_RIP_4005
		trigger = { has_character_flag = forced_to_dance }
	}

	option = {
		name = EVTOPTA_RIP_4005

		add_trait = dancing_plague

		hidden_effect = {
			random_list = {
				45 = { # Recover
					mult_modifier = {
						factor = 1.5
						is_strong_trigger = yes
					}

					mult_modifier = {
						factor = 0.5
						trait = infirm
					}

					character_event = {
						id = RIP.4006
						months = 3
						random = 20
					}
				}

				40 = { # It gets worse...
					mult_modifier = {
						factor = 1.5
						trait = diligent
					}

					mult_modifier = {
						factor = 50
						is_unimportant_trigger = yes
					}

					character_event = {
						id = RIP.4007
						days = 10
						random = 10
					}
				}

				15 = { # Your leg breaks!
					trigger = {
						NOT = { trait = one_legged }
					}

					mult_modifier = {
						factor = 3
						is_weak_trigger = yes
					}

					character_event = {
						id = RIP.4008
						months = 1
						random = 10
					}
				}
			}
		}
	}
}

# Recover From the Dancing Plague
character_event = {
	id = RIP.4006
	desc = EVTDESC_RIP_4006
	picture = GFX_evt_dancing
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTA_RIP_4006

		remove_trait = dancing_plague

		if = {
			limit = { has_character_modifier = cant_stop_dancing }
			remove_character_modifier = cant_stop_dancing
		}

		clr_character_flag = got_dancing_plague
		set_character_flag = immune_dancing_plague
	}
}

# Dancing Plague gets worse...
character_event = {
	id = RIP.4007
	desc = EVTDESC_RIP_4007
	picture = GFX_evt_dancing
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTA_RIP_4007

		add_character_modifier = {
			name = cant_stop_dancing
			duration = -1
		}

		character_event = {
			id = RIP.4006
			months = 3
			random = 20
		}
	}
}

# Dance until your leg breaks.
character_event = {
	id = RIP.4008
	desc = EVTDESC_RIP_4008
	picture = GFX_evt_dancing
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	option = {
		name = EVTOPTA_RIP_4008

		remove_trait = dancing_plague

		if = {
			limit = { has_character_modifier = cant_stop_dancing }
			remove_character_modifier = cant_stop_dancing
		}

		clr_character_flag = got_dancing_plague
		set_character_flag = immune_dancing_plague

		add_trait = one_legged
		add_trait = severely_injured

		character_event = { id = RIP.11503 } # Notify one-legged
		resolve_severely_injured_effect = yes
	}
}