﻿namespace = stress_threshold_prison

################################
# Tier 1 Dungeon Stress Events #
################################

#############################
# Prison Problems			#
# by Sean Hughes			#
# 1001						#
#############################

stress_threshold_prison.1001 = {
	type = character_event
	title = stress_threshold_prison.1001.t
	desc = {
		desc = stress_threshold_prison.1001.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					has_trait = depressed
				}
				desc = stress_threshold_prison.1001.desc.depressed
			}
			triggered_desc = {
				trigger = {
					has_trait = cynical
				}
				desc = stress_threshold_prison.1001.desc.cynical
			}
			desc = stress_threshold_prison.1001.desc.normal
		}
	}
	
	theme = mental_break
	override_background = { reference = dungeon }
	left_portrait = {
		character = root
		animation = prisondungeon
		outfit_tags = { beggar_rags }
		override_imprisonment_visuals = yes
	}
	
	trigger = {
		is_in_prison_type = dungeon
	}

	on_trigger_fail = {
		trigger_event = {
			id = stress_threshold.0001
			days = 0
		}
	}

	immediate = {
		save_scope_as = prisoner
		imprisoner = { save_scope_as = bg_override_char }
		if = {
			limit = {
				has_two_stress_threshold_options = no
				OR = {
					has_trait = inappetetic
					can_be_inappetetic = yes
				}
			}
			add_character_flag = stress_threshold_option_inappetetic
		}
		if = {
			limit = {
				has_two_stress_threshold_options = no
			}
			add_character_flag = stress_threshold_option_conversion
		}
		if = {
			limit = {
				has_two_stress_threshold_options = no
			}
			add_character_flag = stress_threshold_option_depression
		}
		stress_threshold_event_post_immediate = yes
	}

	# Option A-1: Hunger Strike, reduce stress but gain Inappetetic.
	option = {
		trigger = {
			NOT = { has_trait = inappetetic }
			NOT = { has_trait = depressed }
			has_character_flag = stress_threshold_option_inappetetic
		}
		name = stress_threshold_prison.1001.inappetetic.gain

		add_trait = inappetetic
		add_stress = medium_stress_impact_loss
	}

	# Option A-2: Hunger Strike, reduce stress but slowly starve to death.
	option = {
		trigger = {
			NOT = { has_trait = depressed }
			has_trait = inappetetic
			has_character_flag = stress_threshold_option_inappetetic
		}
		name = stress_threshold_prison.1001.inappetetic.effect

		trait = inappetetic
		inappetetic_advance_starvation_effect = yes
		add_stress = medium_stress_impact_loss
	}
	
	# Option B-1: Lose faith in God, reduce stress but gain Cynical.
	option = {
		trigger = {
			NOT = { has_trait = depressed }
			NOT = { has_trait = cynical }
			has_character_flag = stress_threshold_option_conversion
		}
		name = stress_threshold_prison.1001.cynical.gain

		stress_replace_personality_trait_with_opposite_effect = {TRAIT = cynical}

		add_piety = medium_piety_loss	
		add_stress = medium_stress_impact_loss
	}

	# Option B-2: Lost faith in God, reduce stress but lose Piety Levels.
	option = {
		trigger = {
			NOT = { has_trait = depressed }
			has_trait = cynical
			has_character_flag = stress_threshold_option_conversion
		}
		name = stress_threshold_prison.1001.cynical.effect

		trait = cynical

		add_piety = medium_piety_loss
		add_piety_level = -1
		add_stress = medium_stress_impact_loss

	}

	# Option C-1: Give into despair, reduce stress but become Depressed.
	option = {
		trigger = {
			NOT = { has_trait = depressed }
			OR = {
				has_character_flag = stress_threshold_option_depression
				AND = {
					has_trait = cynical
					has_trait = inappetetic
				}
			}
		}
		name = stress_threshold_prison.1001.depressed.gain

		add_trait = depressed_1
		add_stress = major_stress_impact_loss
	}

	# Option C-2: Only option if Depressed. Reduce stress, no negative side effects (can't feel pain when you can't feel anything).
	option = {
		trigger = {
			has_trait = depressed
			OR = {
				has_character_flag = stress_threshold_option_depression
				AND = {
					has_trait = cynical
					has_trait = inappetetic
				}
			}
		}
		name = stress_threshold_prison.1001.depressed.effect

		trait = depressed_1
		trait = depressed_genetic
		add_stress = major_stress_impact_loss
	}

	# Option D: Always 3rd option (unless Depressed), gain Stress but avoid other negative consequences.
	option = {
		trigger = {
			NOT = { has_trait = depressed }
		}
		name = stress_threshold_prison.1001.endure
		add_stress = mental_break_opt_out_stress_gain
	}

	after = {
		stress_threshold_event_aftereffects = yes # Perform stress threshold event clean-up and preparation for future stress threshold events.
	}	
}

#########################################
# Hunger Pangs							#
# by Linnéa Thimrén and Sean Hughes		#
# 1011									#
#########################################
stress_threshold_prison.1011 = {
	type = character_event
	title = stress_threshold_prison.1011.t
	desc = stress_threshold_prison.1011.desc
	
	theme = mental_break
	override_background = {
		reference = dungeon
	}
	left_portrait = {
		character = root
		animation = pain
		outfit_tags = { beggar_rags }
		override_imprisonment_visuals = yes
	}
	right_portrait = {
		character = scope:target
		animation = shame
		outfit_tags = { beggar_rags }
		override_imprisonment_visuals = yes
	}
	
	trigger = {
		is_adult = yes
		is_in_prison_type = dungeon
		is_cannibal_trigger = no
		NOT = {
			has_character_flag = had_dungeon_starvation_event
		}
	}

	weight_multiplier = {
		base = 0.5

		modifier = {
			add = 1
			imprisoner = {
				any_prisoner = {
					is_adult = yes
					is_in_prison_type = dungeon
					this != root
				}
			}
		}
	}

	immediate = {
		add_character_flag = {
			flag = had_dungeon_starvation_event
			days = 3650 # 10 years
		}

		imprisoner = {
			save_scope_as = bg_override_char
			random_prisoner = {
				limit = {
					is_adult = yes
					is_in_prison_type = dungeon
					this != root
				}
				weight = {
					base = 25
					modifier = {
						add = this.current_weight
					}
				}
				save_scope_as = target
			}
		}
		stress_threshold_event_post_immediate = yes
	}

	option = {
		name = stress_threshold_prison.1011.a
		trigger = {
			can_be_inappetetic = yes
			NOT = { has_trait = comfort_eater }
		}
		trait = inappetetic

		if = {
			limit = {
				has_trait = inappetetic
			}
			add_character_modifier = {
				modifier = stress_starvation
				days = 1825 # 5 years
			}
		}
		else = {
			add_trait = inappetetic
		}
		stress_impact = {
			base = medium_stress_impact_loss
		}
	}

	option = {
		name = stress_threshold_prison.1011.b
		if = {
			limit = {
				exists = scope:target
			}
			unknown_cannibal_murder_effect = {
				VICTIM = scope:target
				MURDERER = root
			}
		}
		add_secret = {
			type = secret_cannibal
		}
		stress_impact = {
			base = massive_stress_impact_loss
			gluttonous = medium_stress_impact_loss
			comfort_eater = medium_stress_impact_loss
			temperate = medium_stress_impact_gain
			inappetetic = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
		}
		add_internal_flag = special # Putting this at the end because of tooltip ordering.
	}

	option = {
		name = stress_threshold_prison.1011.c
		add_character_modifier = {
			modifier = stress_starvation_minor
			days = 1825
		}
		stress_impact = {
			base = medium_stress_impact_gain
			gluttonous = minor_stress_impact_loss
			diligent = minor_stress_impact_loss
		}
	}

	after = {
		stress_threshold_event_aftereffects = yes # Perform stress threshold event clean-up and preparation for future stress threshold events.
	}
}

#########################################
# Feeding Time							#
# by Petter Vilberg and Sean Hughes		#
# 1012									#
#########################################
stress_threshold_prison.1012 = {
	type = character_event
	title = stress_threshold_prison.1012.t
	desc = stress_threshold_prison.1012.desc
	
	theme = mental_break
	override_background = {
		reference = dungeon
	}
	override_background = {
		trigger = {
			is_in_prison_type = house_arrest
		}
		reference = sitting_room
	}
	left_portrait = {
		character = root
		animation = admiration
		override_imprisonment_visuals = yes
		outfit_tags = { beggar_rags }
	}
	right_portrait = {
		character = scope:target
		animation = fear
		override_imprisonment_visuals = yes
		outfit_tags = { beggar_rags }
	}
	
	trigger = {
		is_adult = yes
		is_in_prison_type = dungeon
		is_cannibal_trigger = yes
		NOT = {
			has_character_flag = had_dungeon_starvation_event
		}
	}

	weight_multiplier = {
		base = 0.5

		modifier = {
			add = 1
			imprisoner = {
				any_prisoner = {
					is_adult = yes
					is_in_prison_type = dungeon
					this != root
				}
			}
		}
	}

	immediate = {
		add_character_flag = {
			flag = had_dungeon_starvation_event
			days = 3650 # 10 years
		}

		imprisoner = {
			save_scope_as = bg_override_char
			random_prisoner = {
				limit = {
					is_adult = yes
					is_in_prison_type = dungeon
					this != root
				}
				weight = {
					base = 25
					modifier = {
						add = this.current_weight
					}
				}
				save_scope_as = target
			}
		}
		stress_threshold_event_post_immediate = yes
	}

	option = {
		name = stress_threshold_prison.1012.a
		trait = cannibal
		if = {
			limit = {
				exists = scope:target
			}
			unknown_cannibal_murder_effect = {
				VICTIM = scope:target
				MURDERER = root
			}
		}
		stress_impact = {
			base = massive_stress_impact_loss
			gluttonous = medium_stress_impact_loss
			comfort_eater = medium_stress_impact_loss
			temperate = medium_stress_impact_gain
			inappetetic = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
		}
	}

	after = {
		stress_threshold_event_aftereffects = yes # Perform stress threshold event clean-up and preparation for future stress threshold events.
	}
}

#########################################
# Cruel Games							#
# by Linnéa Thimrén and Sean Hughes		#
# 1021									#
#########################################
stress_threshold_prison.1021 = {
	type = character_event
	title = stress_threshold_prison.1021.t
	desc = stress_threshold_prison.1021.desc
	
	theme = mental_break
	left_portrait = {
		character = root
		animation = interested
		override_imprisonment_visuals = yes
		outfit_tags = { beggar_rags }
	}
	right_portrait = {
		character = scope:fellow_prisoner
		animation = boredom
		override_imprisonment_visuals = yes
		outfit_tags = { beggar_rags }
	}
	override_background = {
  		reference = dungeon
	}
	
	trigger = {
		is_in_prison_type = dungeon
		NOR = {
			has_trait = sadistic
			has_trait = callous
			has_trait = depressed
			has_character_flag = had_dungeon_event_1021
		}
		imprisoner = {
			any_prisoner = {
				is_adult = yes
				is_in_prison_type = dungeon
				this != root
			}
		}
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		add_character_flag = {
			flag = had_dungeon_event_1021
			days = 3650
		}

		imprisoner = {
			save_scope_as = bg_override_char
			random_prisoner = {
				limit = {
					is_adult = yes
					is_in_prison_type = dungeon
					this != root
				}
				save_scope_as = fellow_prisoner
			}
		}
		stress_threshold_event_post_immediate = yes
	}

	option = {
		name = stress_threshold_prison.1021.a
		scope:fellow_prisoner = {
			increase_wounds_effect = { REASON = dungeon }
			add_opinion = {
				modifier = cruelty_opinion
				target = root
				opinion = -20
			}
		}
		stress_replace_personality_trait_with_opposite_effect = { TRAIT = sadistic }
		stress_impact = {
			base = major_stress_impact_loss
		}
	}

	option = {
		name = stress_threshold_prison.1021.b
		add_trait = flagellant
		increase_wounds_effect = { REASON = dungeon }
		stress_impact = {
			base = major_stress_impact_loss
		}
	}
	
	option = {
		name = stress_threshold_prison.1021.c
		stress_impact = {
			base = medium_stress_impact_gain
			compassionate = minor_stress_impact_gain
			forgiving = minor_stress_impact_gain
			honest = minor_stress_impact_gain
		}
	}

	after = {
		stress_threshold_event_aftereffects = yes # Perform stress threshold event clean-up and preparation for future stress threshold events.
	}
}



#########################################
# A Grasp on Power						#
# by Petter Vilberg and Sean Hughes		#
# 1031									#
#########################################
stress_threshold_prison.1031 = {
	type = character_event
	title = stress_threshold_prison.1031.t
	desc = stress_threshold_prison.1031.desc
	
	theme = mental_break
	left_portrait = {
		character = root
		animation = manic
		override_imprisonment_visuals = yes
		outfit_tags = { beggar_rags }
	}
	lower_right_portrait = scope:jailer
	override_background = {
		reference = dungeon
	}
	
	trigger = {
		is_in_prison_type = dungeon
		NOR = {
			has_trait = vengeful
			has_trait = lunatic_1
			has_trait = depressed
			has_character_flag = had_dungeon_event_1031
		}
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		add_character_flag = {
			flag = had_dungeon_event_1031
			days = 3650
		}

		imprisoner = {
			save_scope_as = jailer
			save_scope_as = bg_override_char
		}
		stress_threshold_event_post_immediate = yes
	}

	option = {
		name = stress_threshold_prison.1031.a
		stress_replace_personality_trait_with_opposite_effect = { TRAIT = vengeful }
		if = {
			limit = {
				NOR = {
					has_relation_rival = scope:jailer
					has_relation_nemesis = scope:jailer
				}
			}
			if = {
				limit = {
					has_relation_lover = scope:jailer
				}
				remove_relation_lover = scope:jailer
			}
			else_if = {
				limit = {
					has_relation_friend = scope:jailer
				}
				remove_relation_friend = scope:jailer
			}
			if = {
				limit = {
					is_ai = no
				}
				set_relation_rival = {
					target = scope:jailer
					reason = rival_was_kept_in_jail
				}
			}
			else = {
				add_character_flag = rival_on_exit_prison
			}
		}
		stress_impact = {
			base = medium_stress_impact_loss
		}
	}

	option = {
		name = stress_threshold_prison.1031.b
		add_trait = lunatic_1
		stress_impact = {
			base = massive_stress_impact_loss
		}
	}
	
	option = {
		name = stress_threshold_prison.1031.c
		stress_impact = {
			base = medium_stress_impact_gain
			compassionate = minor_stress_impact_gain
			forgiving = minor_stress_impact_gain
			honest = minor_stress_impact_gain
		}
	}

	after = {
		stress_threshold_event_aftereffects = yes # Perform stress threshold event clean-up and preparation for future stress threshold events.
	}
}

#########################################
# Forgotten Needs						#
# by Petter Vilberg and Sean Hughes		#
# 1041									#
#########################################
stress_threshold_prison.1041 = {
	type = character_event
	title = stress_threshold_prison.1041.t
	desc = stress_threshold_prison.1041.desc
	
	theme = mental_break
	left_portrait = {
		character = root
		animation = boredom
		override_imprisonment_visuals = yes
		outfit_tags = { beggar_rags }
	}
	override_background = {
  		reference = sitting_room
	}
	
	trigger = {
		is_in_prison_type = house_arrest
		NOT = { has_character_flag = had_dungeon_event_1041	}
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		add_character_flag = {
			flag = had_dungeon_event_1041
			days = 3650
		}
		imprisoner = { save_scope_as = bg_override_char }
		if = {
			limit = {
				has_two_stress_threshold_options = no
				NOT = { has_trait = depressed }
				OR = {
					has_trait = inappetetic
					can_be_inappetetic = yes
				}
			}
			add_character_flag = stress_threshold_option_inappetetic
		}
		if = {
			limit = {
				has_two_stress_threshold_options = no
				NOT = { has_trait = depressed }
				OR = {
					has_trait = flagellant
					can_be_flagellant = yes
				}
			}
			add_character_flag = stress_threshold_option_flagellant
		}
		if = {
			limit = {
				has_two_stress_threshold_options = no
				NOT = { has_trait = depressed }
				OR = {
					has_trait = journaller
					can_be_journaller = yes
				}
			}
			add_character_flag = stress_threshold_option_journaller
		}
		if = {
			limit = {
				has_two_stress_threshold_options = no
				NOT = { has_trait = depressed }
				OR = {
					has_trait = athletic
					can_be_athletic = yes
				}
			}
			add_character_flag = stress_threshold_option_athletic
		}		
		if = {
			limit = {
				has_two_stress_threshold_options = no
			}
			add_character_flag = stress_threshold_option_depression
		}

		stress_threshold_event_post_immediate = yes
	}

	option = {
		name = stress_threshold_prison.1041.depressed
		trigger = { has_character_flag = stress_threshold_option_depression }

		trait = depressed_1
		trait = depressed_genetic
		add_trait = depressed_1

		stress_impact = {
			base = major_stress_impact_loss
		}
		
	}

	option = {
		name = stress_threshold_prison.1041.inappetetic
		trigger = { has_character_flag = stress_threshold_option_inappetetic }
		
		trait = inappetetic
		add_trait = inappetetic
		inappetetic_advance_starvation_effect = yes

		stress_impact = {
			base = medium_stress_impact_loss
		}
	}

	option = {
		name = stress_threshold_prison.1041.flagellant
		trigger = { has_character_flag = stress_threshold_option_flagellant }
		
		trait = flagellant
		add_trait = flagellant
		increase_wounds_effect = { REASON = whipping }

		if = {
			limit = {
				is_alive = yes
			}
			stress_impact = {
				base = medium_stress_impact_loss
			}
		}
	}

	option = {
		name = {
			trigger = { has_trait = journaller }
			text = stress_threshold_prison.1041.journaller.effect
		}
		name = {
			trigger = { NOT = { has_trait = journaller } }
			text = stress_threshold_prison.1041.journaller.gain
		}
		trigger = { has_character_flag = stress_threshold_option_journaller }

		trait = journaller
		add_trait = journaller

		stress_impact = {
			base = minor_stress_impact_loss
		}
		
	}
	
	option = {
		name = stress_threshold_prison.1041.athletic
		trigger = { has_character_flag = stress_threshold_option_athletic }

		trait = athletic
		add_trait = athletic

		stress_impact = {
			base = minor_stress_impact_loss
		}
		
	}

	option = {
		name = stress_threshold_prison.1041.optout
		trigger = { NOT = { has_trait = depressed } }

		stress_impact = {
			base = mental_break_opt_out_stress_gain
		}
		add_character_modifier = {
			modifier = failing_health
			years = 5
		}
	}

	after = {
		stress_threshold_event_aftereffects = yes # Perform stress threshold event clean-up and preparation for future stress threshold events.
	}
}

################################
# Tier 2 Dungeon Stress Events #
################################

#########################################
# Clawing at the Walls					#
# by Linnéa Thimrén and Sean Hughes		#
# 2001									#
#########################################
stress_threshold_prison.2001 = {
	type = character_event
	title = stress_threshold_prison.2001.t
	desc = stress_threshold_prison.2001.desc
	
	theme = mental_break
	left_portrait = {
		character = root
		animation = prisonhouse
		override_imprisonment_visuals = yes
		outfit_tags = { beggar_rags }
	}
	override_background = {
  		reference = dungeon
	}
	
	trigger = {
		is_in_prison_type = dungeon
		NOR = {
			has_trait = depressed
			has_character_flag = scratching_at_walls_event
		}
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		add_character_flag = {
			flag = scratching_at_walls_event
			days = 3650 # 10 years
		}
		imprisoner = { save_scope_as = bg_override_char }
		stress_threshold_event_post_immediate = yes
	}

	option = {
		name = stress_threshold_prison.2001.a
		increase_wounds_effect = { REASON = dungeon }
		stress_impact = {
			base = medium_stress_impact_loss
		}
	}

	option = {
		name = stress_threshold_prison.2001.b
		add_trait = depressed_1
		stress_impact = {
			base = medium_stress_impact_loss
		}
	}

	after = {
		stress_threshold_event_aftereffects = yes # Perform stress threshold event clean-up and preparation for future stress threshold events.
	}
}


#########################################
# Dungeon Pet							#
# by Linnéa Thimrén and Sean Hughes		#
# 2011									#
#########################################
stress_threshold_prison.2011 = {
	type = character_event
	title = stress_threshold_prison.2011.t
	desc = {
		random_valid = {
			triggered_desc = {
				trigger = {
					var:prison_pet_variable = flag:rat
				}
				desc = stress_threshold_prison.2011.desc_rat
			}
			triggered_desc = {
				trigger = {
					var:prison_pet_variable = flag:stone
				}
				desc = stress_threshold_prison.2011.desc_stone
			}
			triggered_desc = {
				trigger = {
					var:prison_pet_variable = flag:spoon
				}
				desc = stress_threshold_prison.2011.desc_spoon
			}
			triggered_desc = {
				trigger = {
					var:prison_pet_variable = flag:cockroach
				}
				desc = stress_threshold_prison.2011.desc_cockroach
			}
		}
		desc = stress_threshold_prison.2011.desc_end
	}
	
	theme = mental_break
	left_portrait = {
		character = root
		animation = happiness
		override_imprisonment_visuals = yes
		outfit_tags = { beggar_rags }
	}
	override_background = {
  		reference = dungeon
	}
	
	trigger = {
		is_in_prison_type = dungeon
		NOR = {
			has_trait = depressed
			has_character_flag = prison_pet_event
		}
	}

	weight_multiplier = {
		base = 0.5
		modifier = {
			add = 1
			has_trait = lunatic
		}
	}

	immediate = {
		add_character_flag = {
			flag = prison_pet_event
			days = 3650
		}
		imprisoner = { save_scope_as = bg_override_char }
		set_prison_pet_effect = yes
		stress_threshold_event_post_immediate = yes
	}

	option = {
		name = stress_threshold_prison.2011.a
		if = {
			limit = {
				var:prison_pet_variable = flag:rat
			}
			add_character_modifier = {
				modifier = prison_pet_rat_modifier
				days = 1825
			}
		}
		else_if = {
			limit = {
				var:prison_pet_variable = flag:stone
			}
			add_character_modifier = {
				modifier = prison_pet_stone_modifier
				days = 1825
			}
		}
		else_if = {
			limit = {
				var:prison_pet_variable = flag:spoon
			}
			add_character_modifier = {
				modifier = prison_pet_spoon_modifier
				days = 1825
			}
		}
		else_if = {
			limit = {
				var:prison_pet_variable = flag:cockroach
			}
			add_character_modifier = {
				modifier = prison_pet_cockroach_modifier
				days = 1825
			}
		}
		stress_impact = {
			base = major_stress_impact_loss
		}
	}

	after = {
		stress_threshold_event_aftereffects = yes # Perform stress threshold event clean-up and preparation for future stress threshold events.
	}
}

#########################################
# The Darkest Corners					#
# by Linnéa Thimrén and Sean Hughes		#
# 2021									#
#########################################
stress_threshold_prison.2021 = {
	type = character_event
	title = stress_threshold_prison.2021.t
	desc = stress_threshold_prison.2021.desc
	
	theme = mental_break
	left_portrait = {
		character = root
		animation = paranoia
		override_imprisonment_visuals = yes
		outfit_tags = { beggar_rags }
	}
	override_background = {
		reference = dungeon
	}
	override_background = {
		trigger = {
			is_in_prison_type = house_arrest
		}
		reference = sitting_room
	}
	
	trigger = {
		NOR = {
			has_trait = depressed
			has_character_flag = darkest_corners_event
		}
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		add_character_flag = {
			flag = darkest_corners_event
			days = 3650 # 10 years
		}
		imprisoner = { save_scope_as = bg_override_char }
		stress_threshold_event_post_immediate = yes
	}

	option = {
		name = stress_threshold_prison.2021.a
		stress_replace_personality_trait_with_opposite_effect = {TRAIT = paranoid}
		stress_impact = {
			base = major_stress_impact_loss
		}
	}

	option = {
		name = stress_threshold_prison.2021.b
		stress_replace_personality_trait_with_opposite_effect = {TRAIT = craven}
		stress_impact = {
			base = major_stress_impact_loss
		}
	}

	option = {
		name = stress_threshold_prison.2021.c
		add_trait = possessed_1
		stress_impact = {
			base = major_stress_impact_loss
		}
	}

	after = {
		stress_threshold_event_aftereffects = yes # Perform stress threshold event clean-up and preparation for future stress threshold events.
	}
}


################################
# Tier 3 Dungeon Stress Events #
################################

#########################################
# A Friend In Need						#
# by Petter Vilberg						#
# 3001									#
#########################################
stress_threshold_prison.3001 = {
	type = character_event
	title = stress_threshold_prison.3001.t
	desc = stress_threshold_prison.3001.desc
	
	theme = mental_break
	left_portrait = {
		character = root
		animation = happiness
		outfit_tags = { beggar_rags }
		override_imprisonment_visuals = yes
	}
	right_portrait = {
		character = scope:fictional_friend
		animation = war_over_tie
		hide_info = yes
	}
	override_background = {
		reference = dungeon
	}
	
	trigger = {
		is_in_prison_type = dungeon
		NOR = {
			has_trait = lunatic
			has_trait = depressed
			has_character_flag = had_event_stress_threshold_prison_3001
		}
		is_ai = no # Don't bother creating disposable characters for the AI.
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		add_character_flag = {
			flag = had_event_stress_threshold_prison_3001
			days = 3650 # 10 years
		}
		imprisoner = { save_scope_as = bg_override_char }
		create_character = {
			location = root.location
			gender_female_chance = 0.5
			culture = root.culture
			faith = root.faith
			save_scope_as = fictional_friend
		}
		scope:fictional_friend = { add_character_flag = high_noble_clothing }
		stress_threshold_event_post_immediate = yes
	}

	option = {
		name = stress_threshold_prison.3001.a
		add_trait = lunatic_1
		stress_impact = {
			base = major_stress_impact_loss
		}
	}

	after = {
		hidden_effect = {	
			scope:fictional_friend = {
				death = {
					death_reason = death_vanished
				}
			}
		}
		stress_threshold_event_aftereffects = yes # Perform stress threshold event clean-up and preparation for future stress threshold events.
	}
}

#########################################
# True Family							#
# by Petter Vilberg						#
# 3011									#
#########################################
stress_threshold_prison.3011 = {
	type = character_event
	title = stress_threshold_prison.3011.t
	desc = {
		desc = stress_threshold_prison.3011.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					any_sibling = {
						even_if_dead = yes
						count > 1
					}
				}
				desc = stress_threshold_prison.3011.sibling_multiple
			}
			triggered_desc = {
				trigger = { exists = scope:sibling }
				desc = stress_threshold_prison.3011.sibling
			}
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					any_child = {
						even_if_dead = yes
						count > 1
					}
				}
				desc = stress_threshold_prison.3011.child_multiple
			}
			triggered_desc = {
				trigger = { exists = scope:child }
				desc = stress_threshold_prison.3011.child
			}
			desc = stress_threshold_prison.3011.fallback
		}
	}
	theme = mental_break
	left_portrait = {
		character = root
		animation = happiness
		override_imprisonment_visuals = yes
		outfit_tags = { beggar_rags }
	}
	right_portrait = {
		character = scope:family_1
		animation = war_over_tie
	}
	lower_left_portrait = scope:family_2
	lower_center_portrait = scope:family_3
	lower_right_portrait = scope:family_4
	override_background = {
  		reference = dungeon
	}
	
	trigger = {
		is_in_prison_type = dungeon
		NOR = {
			has_trait = depressed
			has_character_flag = had_event_stress_threshold_prison_3011
		}
		any_close_family_member = {
			OR = {
				is_sibling_of = root
				is_parent_of = root
				is_child_of = root
			}
		}
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		add_character_flag = {
			flag = had_event_stress_threshold_prison_3011
			days = 3650 # 10 years
		}
		imprisoner = { save_scope_as = bg_override_char }
		hidden_effect = {
			while = {
				count = 4
				random_close_family_member = {
					even_if_dead = yes
					limit = {
						NOR = {
							scope:family_3 ?= this
							scope:family_2 ?= this
							scope:family_1 ?= this
						}
					}
					weight = {
						base = 1
						modifier = {
							is_parent_of = root
							add = 50
						}
						modifier = {
							is_child_of = root
							add = 25
						}
						modifier = {
							is_sibling_of = root
							add = 10
						}
					}
					add_to_list = family
					if = {
						limit = { exists = scope:family_3 }
						save_scope_as = family_4
					}
					else_if = {
						limit = { exists = scope:family_2 }
						save_scope_as = family_3
					}
					else_if = {
						limit = { exists = scope:family_1 }
						save_scope_as = family_2
					}
					else = { save_scope_as = family_1 }
				}
			}
		}
		random_sibling = {
			even_if_dead = yes
			limit = { is_in_list = family }
			alternative_limit = { always = yes }
			save_scope_as = sibling
		}
		random_child = {
			even_if_dead = yes
			limit = { is_in_list = family }
			alternative_limit = { always = yes }
			save_scope_as = child
		}
		stress_threshold_event_post_immediate = yes
	}

	option = {
		name = stress_threshold_prison.3011.a
		trait = lunatic_1
		trait = lunatic_genetic
		
		if = {
			limit = {
				NOT = {	has_trait = lunatic }
			}
			add_trait = lunatic_1
		}

		stress_impact = {
			base = major_stress_impact_loss
		}
	}

	after = {
		stress_threshold_event_aftereffects = yes # Perform stress threshold event clean-up and preparation for future stress threshold events.
	}
}

#########################################
# Freedom								#
# by Petter Vilberg						#
# 3999									#
#########################################
stress_threshold_prison.3999 = {
	type = character_event
	title = stress_threshold_prison.3999.t
	desc = stress_threshold_prison.3999.desc
	
	theme = mental_break
	left_portrait = {
		character = root
		animation = grief
		override_imprisonment_visuals = yes
	}
	override_background = {
  		reference = dungeon
	}

	trigger = {
		is_in_prison_type = dungeon
	}

	weight_multiplier = {
		base = 0.1

		# Physical Modifiers - Additive
		modifier = {
			has_trait_rank = {
				trait = wounded
				rank = 1
			}
			add = 0.05
		}
		modifier = {
			has_trait_rank = {
				trait = wounded
				rank = 2
			}
			add = 0.10
		}
		modifier = {
			has_trait_rank = {
				trait = wounded
				rank = 3
			}
			add = 0.20
		}

		modifier = {
			OR = {		
				has_character_modifier = stress_inappetetic_hunger_1
				has_character_modifier = stress_starvation_minor
			}
			add = 0.05
		}
		modifier = {
			has_character_modifier = stress_inappetetic_hunger_2
			add = 0.10
		}
		modifier = {
			OR = {		
				has_character_modifier = stress_inappetetic_hunger_3
				has_character_modifier = stress_starvation
			}
			add = 0.20
		}

		# Mental Modifiers - Multiplicative
		modifier = {
			has_trait = lunatic
			factor = 2.0
		}
		modifier = {
			has_trait = possessed
			factor = 2.0
		}
		modifier = {
			has_trait = depressed
			factor = 4.0
		}
	}

	immediate = {
		imprisoner = { save_scope_as = bg_override_char }
	}

	option = {
		name = stress_threshold_prison.3999.a

		death = {
			death_reason = death_dungeon
		}
	}
}
