namespace = natural_disaster_flavor_events

scripted_trigger is_location_affected_by_disaster_in_recovery_trigger = {
	location.county = {
		any_county_situation = {
			tgp_natural_disaster_situation_is_disaster_trigger = yes
			situation_current_phase = recovery
		}
	}
}

scripted_effect create_random_misc_artifact_effect = {
	create_artifact = {
		name = random_misc_artifact
		description = random_misc_artifact_desc
		type = miscellaneous
		visuals = ring
		rarity = common
		modifier = artifact_prowess_1_modifier
		max_durability = 15
		save_scope_as = random_misc_artifact
	}
	hidden_effect = {
		random_list = {
			50 = {
				scope:random_misc_artifact = {
					add_artifact_modifier = character_travel_speed_1
				}
			}
			50 = {
				scope:random_misc_artifact = {
					add_artifact_modifier = artifact_travel_safety_1
				}
			}
		}
	}
}

# As Scavengers Gather
natural_disaster_flavor_events.0001 = {
	type = character_event
	title = natural_disaster_flavor_events.0001.t
	desc = natural_disaster_flavor_events.0001.desc
	theme = disaster
	left_portrait = {
		character = root
		animation = survey
	}
	cooldown = { years = 20 }

	trigger = {
		has_tgp_dlc_trigger = yes
		is_location_valid_for_travel_event_on_land = yes
		is_location_affected_by_disaster_in_recovery_trigger = yes
		is_available_travelling_adult = yes
		is_landed = no
	}

	widgets = {
		widget = {
			is_shown = {
				scope:random_weather = flag:fog
			}
			gui = event_window_widget_vfx_rainy_fog container = foreground_shader_vfx_container
		}
	}

	immediate = {
		location.county = {
			random_county_situation = {
				limit = {
					tgp_natural_disaster_situation_is_disaster_trigger = yes
				}
				save_scope_as = disaster_situation
			}
		}

		create_character = {
			template = generic_peasant_character
			location = root.location
			culture = root.location.culture
			faith = root.location.faith
			gender_female_chance = root_soldier_female_chance
			save_scope_as = person_in_need
		}

		random_list = {
			20 = {
				save_scope_value_as = {
					name = random_weather
					value = flag:fog
				}
			}
			80 = { }
		}
	}

	option = { # Valuables
		name = natural_disaster_flavor_events.0001.a
		add_piety = minor_piety_loss
		random_list = {
			33 = { # Gold
				send_interface_toast = {
					type = event_toast_effect_good
					title = natural_disaster_flavor_events.0001.a.gold.toast
					left_icon = root
					add_gold = {
						add = miniscule_gold_value
						multiply = 3
					}	
				}
				modifier = {
					add = 15
					has_trait = greedy
				}
			}
			33 = { # Provisions
				send_interface_toast = {
					type = event_toast_effect_good
					title = natural_disaster_flavor_events.0001.a.provisions.toast
					left_icon = root
					domicile = {
	 					change_provisions = miniscule_provisions_gain
  					}
				}
 				modifier = {
					add = 15
					has_trait = gluttonous
				}
			}
			33 = { # Artifact
				send_interface_toast = {
					type = event_toast_effect_good
					title = natural_disaster_flavor_events.0001.a.artifact.toast
					left_icon = root
					create_random_misc_artifact_effect = yes
				}
 				modifier = {
					add = 15
					has_trait = brave
				}
			}
		}
		current_travel_plan = {
			delay_travel_plan = {
				days = 10 
			}
		}
		random = {
			chance = 20
			contract_disease_effect = { DISEASE = ill TREATMENT_EVENT = yes }
		}

		stress_impact = {
			just = minor_stress_impact_gain
			greedy = minor_stress_impact_loss
		}

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

	option = { # Survivors
		name = natural_disaster_flavor_events.0001.b

		duel = {
			skill = prowess
			value = medium_skill_rating
			50 = { # Success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				min = 20
				max = 90
				reverse_add_opinion = {
					target = scope:person_in_need
					modifier = grateful_opinion
					opinion = 25
				}
			}
			50 = { # Failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				min = 20
				max = 90
				send_interface_toast = {
					type = event_toast_effect_bad
					title = natural_disaster_flavor_events.0001.b.failure.toast # fix this
					left_icon = root
					right_icon = scope:person_in_need
					scope:person_in_need = {
						increase_wounds_effect = { REASON = wounds }
					}
				}
			}
		}

		send_interface_toast = {
			type = event_toast_effect_good
			title = natural_disaster_flavor_events.0001.b.success.toast
			left_icon = root
			right_icon = scope:person_in_need
			current_travel_plan = {
				add_companion = scope:person_in_need
			}
		}
		current_travel_plan = {
			delay_travel_plan = {
				days = 10 
			}
		}

		stress_impact = {
			lazy = minor_stress_impact_gain
			compassionate = minor_stress_impact_loss
		}

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

	option = { # Opt out
		name = natural_disaster_flavor_events.0001.c

		custom_tooltip = RESUME_TRAVEL_PLAN_EFFECT

		stress_impact = {
			compassionate = minor_stress_impact_gain
			craven = minor_stress_impact_loss
		}

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

# Waking Nightmare
natural_disaster_flavor_events.0005 = {
	type = character_event
	title = natural_disaster_flavor_events.0005.t
	desc = natural_disaster_flavor_events.0005.desc
	theme = disaster
	left_portrait = {
		character = root
		animation = shock
	}
	cooldown = { years = 20 }

	trigger = {
		has_tgp_dlc_trigger = yes
		is_location_valid_for_travel_event_on_land = yes
		is_landed = no
	}

	widget = { gui = event_window_widget_vfx_earthquake container = foreground_shader_vfx_container }

	immediate = {
		location.county = {
			random_county_situation = {
				limit = {
					tgp_natural_disaster_situation_is_disaster_trigger = yes
				}
				save_scope_as = disaster_situation
			}
		}
	}

	option = { # Run for your life
		name = natural_disaster_flavor_events.0005.a
		duel = {
			skill = prowess
			value = medium_skill_rating
			50 = { # Success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = natural_disaster_flavor_events.0005.a.success.toast
				min = 20
				max = 90
				send_interface_toast = {
					type = event_toast_effect_good
					title = natural_disaster_flavor_events.0005.a.success.toast
					left_icon = root
					add_character_modifier = {
						modifier = tgp_selfish_actions_character_modifier
						years = 10
					}
				}
			}
			50 = { # Failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = natural_disaster_flavor_events.0005.a.failure.toast
				min = 20
				max = 90
				send_interface_toast = {
					type = event_toast_effect_bad
					title = natural_disaster_flavor_events.0005.a.failure.toast
					left_icon = root
					increase_wounds_effect = { REASON = wounds }
				}
			}
		}

		stress_impact = {
			compassionate = minor_stress_impact_gain
			craven = minor_stress_impact_loss
		}

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

	option = { # Find a safe location
		name = natural_disaster_flavor_events.0005.b
		duel = {
			skill = learning
			value = medium_skill_rating
			50 = { # Success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = natural_disaster_flavor_events.0005.b.success.toast
				min = 20
				max = 90
				send_interface_toast = {
					type = event_toast_effect_good
					title = natural_disaster_flavor_events.0005.b.success.toast
					left_icon = root
					add_character_modifier = {
						modifier = tgp_finding_safe_spot_character_modifier
						years = 10
					}
				}
			}
			50 = { # Failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = natural_disaster_flavor_events.0005.b.failure.toast
				min = 20
				max = 90
				send_interface_toast = {
					type = event_toast_effect_bad
					title = natural_disaster_flavor_events.0005.b.failure.toast
					left_icon = root
					increase_wounds_effect = { REASON = wounds }
				}
			}
		}

		stress_impact = {
			fickle = minor_stress_impact_gain
			diligent = minor_stress_impact_loss
		}

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

# Desperate Souls
natural_disaster_flavor_events.0010 = {
	type = character_event
	title = natural_disaster_flavor_events.0010.t
	desc = natural_disaster_flavor_events.0010.desc
	theme = disaster
	left_portrait = {
		character = root
		animation = worry
	}
	cooldown = { years = 20 }

	trigger = {
		has_tgp_dlc_trigger = yes
		is_location_valid_for_travel_event_on_land = yes
		is_location_affected_by_disaster_in_recovery_trigger = yes
		is_available_travelling_adult = yes
	}

	immediate = {
		location.county = {
			random_county_situation = {
				limit = {
					tgp_natural_disaster_situation_is_disaster_trigger = yes
				}
				save_scope_as = disaster_situation
			}
		}
	}

	option = { # Reassure them that help is coming
		name = natural_disaster_flavor_events.0010.a
		duel = {
			skill = diplomacy
			value = medium_skill_rating
			50 = { # Success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = natural_disaster_flavor_events.0010.a.success.toast
				min = 20
				max = 90
				send_interface_toast = {
					type = event_toast_effect_good
					title = natural_disaster_flavor_events.0010.a.success.toast
					left_icon = root
					add_diplomacy_lifestyle_xp = medium_lifestyle_experience
				}
			}
			50 = { # Failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = natural_disaster_flavor_events.0010.a.failure.toast
				min = 20
				max = 90
				send_interface_toast = {
					type = event_toast_effect_bad
					title = natural_disaster_flavor_events.0010.a.failure.toast
					left_icon = root
					add_character_modifier = {
						modifier = tgp_deceitful_overconfidence_character_modifier
						years = 10
					}
				}
			}
		}

		stress_impact = {
			honest = minor_stress_impact_gain
			deceitful = minor_stress_impact_loss
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = -1
				ai_compassion = -1
				ai_sociability = 1
			}
		}
	}
	
	option = { # Lie your way out of the situation
		name = natural_disaster_flavor_events.0010.b
		duel = {
			skill = intrigue
			value = medium_skill_rating
			50 = { # Success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = natural_disaster_flavor_events.0010.b.success.toast
				min = 20
				max = 90
				send_interface_toast = {
					type = event_toast_effect_good
					title = natural_disaster_flavor_events.0010.b.success.toast
					left_icon = root
					add_intrigue_lifestyle_xp = medium_lifestyle_experience
				}
			}
			50 = { # Failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = natural_disaster_flavor_events.0010.b.failure.toast
				min = 20
				max = 90
				send_interface_toast = {
					type = event_toast_effect_bad
					title = natural_disaster_flavor_events.0010.b.failure.toast
					left_icon = root
					add_character_modifier = {
						modifier = tgp_deceitful_overconfidence_character_modifier
						years = 10
					}
				}
			}
		}

		stress_impact = {
			honest = minor_stress_impact_gain
			deceitful = minor_stress_impact_loss
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = -1
				ai_compassion = -2
				ai_rationality = 1
			}
		}
	}

	option = { # Ignore their pleas
		name = natural_disaster_flavor_events.0010.c
		flavor = natural_disaster_flavor_events.0010.c.tt
		current_travel_plan.current_location.county = {
			if = { 
				limit = {
					holder = { save_temporary_scope_as = county_holder }
					OR = {
						scope:county_holder = root
						root = { is_vassal_or_below_of = scope:county_holder }
					}
				}
				add_county_modifier = {
					modifier = tgp_abandoned_population_modifier
					years = 10
				}
			}
			else = {
				root = { add_prestige = minor_prestige_loss }
			}
		}

		stress_impact = {
			compassionate = minor_stress_impact_gain
			callous = minor_stress_impact_loss
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = -2
				ai_rationality = 2
			}
		}
	}
}

# Selfless Acts
natural_disaster_flavor_events.0015 = {
	type = character_event
	title = natural_disaster_flavor_events.0015.t
	desc = natural_disaster_flavor_events.0015.desc
	theme = disaster
	left_portrait = {
		character = root
		animation = shock
	}
	right_portrait = {
		character = scope:spouse
		animation = fear
	}
	lower_center_portrait = {
		trigger = { exists = scope:heir }
		character = scope:heir
	}
	lower_right_portrait = {
		trigger = { exists = scope:courtier }
		character = scope:courtier
	}
	cooldown = { years = 20 }

	trigger = {
		has_tgp_dlc_trigger = yes
		is_location_valid_for_travel_event_on_land = yes
		is_location_affected_by_disaster_in_recovery_trigger = yes
		is_landed = yes
		primary_spouse ?= {
			is_at_same_location = root
		}
	}

	immediate = {
		location.county = {
			random_county_situation = {
				limit = { tgp_natural_disaster_situation_is_disaster_trigger = yes }
				save_scope_as = disaster_situation
			}
		}
		primary_spouse = {
			save_scope_as = spouse
		}
		primary_heir ?= {
			if = {
				limit = { 
					this != scope:spouse
					is_at_same_location = root
				}
				save_scope_as = heir
			}
		}
		random_courtier = {
			limit = {
				this != scope:spouse
				this != scope:heir
				has_any_court_position = yes
				is_at_same_location = root
			}
			save_scope_as = courtier
		}
	}

	option = { # Save your spouse
		name = natural_disaster_flavor_events.0015.a
		random = {
			chance = {
				value = 25
				subtract = prowess
			}
			send_interface_toast = {
				type = event_toast_effect_bad
				title = natural_disaster_flavor_events.0015.a.failure
				left_icon = root
				increase_wounds_effect = { REASON = wounds }
			}
			save_scope_as = damage_done
		}
		if = {
			limit = {
				OR = {
					exists = scope:heir
					exists = scope:courtier
				}
			}
			random = {
				chance = {
					value = 35
					subtract = prowess
				}
				send_interface_toast = {
					type = event_toast_effect_bad
					title = natural_disaster_flavor_events.0015.a.failure
					left_icon = scope:heir
					right_icon = scope:courtier
					primary_heir ?= {
						increase_wounds_effect = { REASON = wounds }
					}
					scope:courtier ?= {
						increase_wounds_effect = { REASON = wounds }
					}
				}
				save_scope_as = damage_done
			}
		}

		if = {
			limit = { NOT = { exists = scope:damage_done } }
			send_interface_toast = {
				type = event_toast_effect_good
				title = natural_disaster_flavor_events.0015.a.success
				left_icon = root
			}
		}

		add_prowess_skill = 1
		reverse_add_opinion = {
			target = primary_spouse
			modifier = grateful_opinion
			opinion = 25
		}

		stress_impact = {
			craven = minor_stress_impact_gain
			brave = minor_stress_impact_loss
		}

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

	option = { # Save your heir
		name = natural_disaster_flavor_events.0015.b
		trigger = { exists = scope:heir }

		random = {
			chance = {
				value = 25
				subtract = prowess
			}
			send_interface_toast = {
				type = event_toast_effect_bad
				title = natural_disaster_flavor_events.0015.b.failure
				left_icon = root
				increase_wounds_effect = { REASON = wounds }
			}
			save_scope_as = damage_done
		}
		random = {
			chance = {
				value = 35
				subtract = prowess
			}
			send_interface_toast = {
				type = event_toast_effect_bad
				title = natural_disaster_flavor_events.0015.b.failure
				left_icon = scope:spouse
				right_icon = scope:courtier
				primary_spouse = {
					increase_wounds_effect = { REASON = wounds }
				}
				scope:courtier ?= {
					increase_wounds_effect = { REASON = wounds }
				}
			}
			save_scope_as = damage_done
		}

		if = {
			limit = { NOT = { exists = scope:damage_done } }
			send_interface_toast = {
				type = event_toast_effect_good
				title = natural_disaster_flavor_events.0015.b.success
				left_icon = root
			}
		}

		add_prowess_skill = 1
		reverse_add_opinion = {
			target = primary_heir
			modifier = grateful_opinion
			opinion = 25
		}

		stress_impact = {
			craven = minor_stress_impact_gain
			brave = minor_stress_impact_loss
		}

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

	option = { # Save your courtier
		name = natural_disaster_flavor_events.0015.c
		trigger = { exists = scope:courtier }

		random = {
			chance = {
				value = 25
				subtract = prowess
			}
			send_interface_toast = {
				type = event_toast_effect_bad
				title = natural_disaster_flavor_events.0015.c.failure
				left_icon = root
				increase_wounds_effect = { REASON = wounds }
			}
			save_scope_as = damage_done
		}
		random = {
			chance = {
				value = 35
				subtract = prowess
			}
			send_interface_toast = {
				type = event_toast_effect_bad
				title = natural_disaster_flavor_events.0015.c.failure
				left_icon = scope:spouse
				right_icon = scope:heir
				primary_spouse = {
					increase_wounds_effect = { REASON = wounds }
				}
				primary_heir ?= {
					increase_wounds_effect = { REASON = wounds }
				}
			}
			save_scope_as = damage_done
		}

		if = {
			limit = { NOT = { exists = scope:damage_done } }
			send_interface_toast = {
				type = event_toast_effect_good
				title = natural_disaster_flavor_events.0015.c.success
				left_icon = root
			}
		}

		add_prowess_skill = 1
		reverse_add_opinion = {
			target = scope:courtier
			modifier = grateful_opinion
			opinion = 25
		}

		stress_impact = {
			craven = minor_stress_impact_gain
			brave = minor_stress_impact_loss
		}

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

	option = { # Save yourself
		name = natural_disaster_flavor_events.0015.d
		random = {
			chance = {
				value = 45
			}
			send_interface_toast = {
				type = event_toast_effect_bad
				title = natural_disaster_flavor_events.0015.a.failure
				left_icon = scope:spouse
				right_icon = scope:heir
				primary_spouse = {
					increase_wounds_effect = { REASON = wounds }
				}
				primary_heir ?= {
					increase_wounds_effect = { REASON = wounds }
				}
				scope:courtier ?= {
					increase_wounds_effect = { REASON = wounds }
				}
			}
			save_scope_as = damage_done
		}

		if = {
			limit = { NOT = { exists = scope:damage_done } }
			send_interface_toast = {
				type = event_toast_effect_good
				title = natural_disaster_flavor_events.0015.a.success
				left_icon = root
			}
		}

		stress_impact = {
			brave = minor_stress_impact_gain
			craven = minor_stress_impact_loss
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = -1
				ai_compassion = -1
				ai_boldness = -1
				ai_rationality = 1
			}
		}
	}
}
