############################################
# Snapping Event Chain
# Allomantic potential must be activated through
# a traumatic event known as "Snapping"
############################################

namespace = mistborn_snapping

# ============================================================
# NATURAL SNAPPING - Childhood Trauma
# Fires on birthday for characters age 10-16 with potential
# ============================================================
mistborn_snapping.0001 = {
	type = character_event
	title = mistborn_snapping.0001.t
	desc = mistborn_snapping.0001.desc
	theme = education

	left_portrait = {
		character = root
		animation = pain
	}

	trigger = {
		OR = {
			has_trait = trait_allomantic_potential
			has_trait = trait_mistborn_potential
		}
		age >= 10
		age <= 16
		NOT = { has_trait = trait_mistborn }
		NOT = { has_character_flag = snapping_attempted_this_year }
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = 0.5
			age >= 14
		}
		modifier = {
			add = 0.3
			has_trait = brave
		}
	}

	immediate = {
		add_character_flag = {
			flag = snapping_attempted_this_year
			years = 1
		}
	}

	# The Snapping attempt
	option = {
		name = mistborn_snapping.0001.a
		# Natural snapping has moderate success chance
		random_list = {
			35 = {
				# Success - Snapping occurs
				trigger_event = {
					id = mistborn_snapping.0020
					days = 1
				}
			}
			65 = {
				# Failure - nothing happens yet
				custom_tooltip = mistborn_snapping.0001.a.fail
			}
		}
		ai_chance = {
			base = 100
		}
	}
}

# ============================================================
# FORCED SNAPPING - Deliberate Trauma by Parent
# Triggered by the "Subject Heir to Snapping" decision
# ============================================================
mistborn_snapping.0010 = {
	type = character_event
	title = mistborn_snapping.0010.t
	desc = mistborn_snapping.0010.desc
	theme = secret

	left_portrait = {
		character = root
		animation = personality_callous
	}

	right_portrait = {
		character = scope:snapping_target
		animation = fear
	}

	trigger = {
		exists = scope:snapping_target
	}

	immediate = {
		# Parent steels themselves for what must be done
	}

	# Option A: Beat the child - the common noble method
	option = {
		name = mistborn_snapping.0010.a
		add_stress = 20
		stress_impact = {
			compassionate = 30
			callous = -10
		}
		scope:snapping_target = {
			random_list = {
				45 = {
					# Success
					modifier = {
						add = 10
						root = {
							OR = {
								has_trait = trait_mistborn
								has_trait = trait_misting_thug
								has_trait = trait_misting_coinshot
								has_trait = trait_misting_lurcher
							}
						}
					}
					trigger_event = {
						id = mistborn_snapping.0020
						days = 3
					}
				}
				40 = {
					# Failure - no Snapping
					trigger_event = {
						id = mistborn_snapping.0030
						days = 3
					}
				}
				10 = {
					# Injury during the attempt
					add_trait = wounded_1
					trigger_event = {
						id = mistborn_snapping.0030
						days = 3
					}
				}
				5 = {
					# Death - the trauma was too much
					death = {
						death_reason = death_murder
						killer = root
					}
				}
			}
		}
		ai_chance = {
			base = 50
		}
	}

	# Option B: Lock them in a cold room for days
	option = {
		name = mistborn_snapping.0010.b
		add_stress = 30
		stress_impact = {
			compassionate = 40
			callous = -10
		}
		scope:snapping_target = {
			random_list = {
				55 = {
					# Success - higher chance
					trigger_event = {
						id = mistborn_snapping.0020
						days = 5
					}
				}
				25 = {
					# Failure
					trigger_event = {
						id = mistborn_snapping.0030
						days = 5
					}
				}
				12 = {
					# Injury - frostbite, illness
					add_trait = wounded_2
					trigger_event = {
						id = mistborn_snapping.0030
						days = 5
					}
				}
				8 = {
					# Death from exposure
					death = {
						death_reason = death_murder
						killer = root
					}
				}
			}
		}
		ai_chance = {
			base = 30
		}
	}

	# Option C: Hire professionals - expensive but safest
	option = {
		name = mistborn_snapping.0010.c
		remove_short_term_gold = 150
		add_stress = 10
		scope:snapping_target = {
			random_list = {
				60 = {
					# Success - highest chance
					modifier = {
						add = 10
						root = { gold >= 300 }
					}
					trigger_event = {
						id = mistborn_snapping.0020
						days = 7
					}
				}
				35 = {
					# Failure - but safe
					trigger_event = {
						id = mistborn_snapping.0030
						days = 7
					}
				}
				5 = {
					# Injury - rare with professionals
					add_trait = wounded_1
					trigger_event = {
						id = mistborn_snapping.0030
						days = 7
					}
				}
			}
		}
		ai_chance = {
			base = 20
			modifier = {
				add = 30
				gold >= 200
			}
		}
	}
}

# ============================================================
# SNAPPING SUCCESS - The child discovers their power
# ============================================================
mistborn_snapping.0020 = {
	type = character_event
	title = mistborn_snapping.0020.t
	desc = mistborn_snapping.0020.desc
	theme = education

	left_portrait = {
		character = root
		animation = happiness
	}

	trigger = {
		OR = {
			has_trait = trait_allomantic_potential
			has_trait = trait_mistborn_potential
		}
	}

	immediate = {
		# Determine what type of Allomancer they become
		if = {
			limit = {
				has_trait = trait_mistborn_potential
			}
			remove_trait = trait_mistborn_potential
			add_trait = trait_mistborn
			save_scope_as = became_mistborn
		}
		else_if = {
			limit = {
				has_trait = trait_allomantic_potential
			}
			remove_trait = trait_allomantic_potential
			# Random Misting type, weighted by parent traits
			random_list = {
				12 = {
					# Coinshot
					modifier = {
						add = 5
						any_parent = { has_trait = trait_misting_coinshot }
					}
					add_trait = trait_misting_coinshot
				}
				12 = {
					# Lurcher
					modifier = {
						add = 5
						any_parent = { has_trait = trait_misting_lurcher }
					}
					add_trait = trait_misting_lurcher
				}
				10 = {
					# Thug
					modifier = {
						add = 5
						any_parent = { has_trait = trait_misting_thug }
					}
					add_trait = trait_misting_thug
				}
				12 = {
					# Tineye
					modifier = {
						add = 5
						any_parent = { has_trait = trait_misting_tineye }
					}
					add_trait = trait_misting_tineye
				}
				12 = {
					# Soother
					modifier = {
						add = 5
						any_parent = { has_trait = trait_misting_soother }
					}
					add_trait = trait_misting_soother
				}
				12 = {
					# Rioter
					modifier = {
						add = 5
						any_parent = { has_trait = trait_misting_rioter }
					}
					add_trait = trait_misting_rioter
				}
				12 = {
					# Smoker
					modifier = {
						add = 5
						any_parent = { has_trait = trait_misting_smoker }
					}
					add_trait = trait_misting_smoker
				}
				12 = {
					# Seeker
					modifier = {
						add = 5
						any_parent = { has_trait = trait_misting_seeker }
					}
					add_trait = trait_misting_seeker
				}
				3 = {
					# Augur (rare)
					add_trait = trait_misting_augur
				}
				1 = {
					# Oracle (extremely rare)
					add_trait = trait_misting_oracle
				}
				1 = {
					# Duralumin (rare)
					add_trait = trait_misting_duralumin
				}
				1 = {
					# Nicroburst (rare)
					add_trait = trait_misting_nicroburst
				}
			}
		}
	}

	# Mistborn discovery - whole house celebrates
	option = {
		name = mistborn_snapping.0020.a
		trigger = {
			exists = scope:became_mistborn
		}
		add_prestige = 500
		dynasty = {
			add_dynasty_prestige = 200
		}
		if = {
			limit = {
				exists = root.court_owner
			}
			root.court_owner = {
				add_prestige = 100
			}
		}
		# But also draws Lord Ruler attention
		if = {
			limit = {
				exists = root.court_owner
				root.court_owner = {
					has_variable = lord_ruler_attention
				}
			}
			root.court_owner = {
				change_variable = {
					name = lord_ruler_attention
					add = 10
				}
			}
		}
		ai_chance = {
			base = 100
		}
	}

	# Misting discovery
	option = {
		name = mistborn_snapping.0020.b
		trigger = {
			NOT = { exists = scope:became_mistborn }
		}
		add_prestige = 100
		dynasty = {
			add_dynasty_prestige = 50
		}
		ai_chance = {
			base = 100
		}
	}
}

# ============================================================
# SNAPPING FAILURE - The child didn't Snap
# ============================================================
mistborn_snapping.0030 = {
	type = character_event
	title = mistborn_snapping.0030.t
	desc = mistborn_snapping.0030.desc
	theme = education

	left_portrait = {
		character = root
		animation = sadness
	}

	trigger = {
		OR = {
			has_trait = trait_allomantic_potential
			has_trait = trait_mistborn_potential
		}
	}

	# The child is fine but not an Allomancer
	option = {
		name = mistborn_snapping.0030.a
		add_stress = 10
		if = {
			limit = {
				exists = root.father
			}
			root.father = {
				add_opinion = {
					target = root
					modifier = disappointed_opinion
					opinion = -15
				}
				# If the child was injured during snapping, father feels guilt
				if = {
					limit = {
						root = {
							OR = {
								has_trait = wounded_1
								has_trait = wounded_2
								has_trait = wounded_3
							}
						}
					}
					add_opinion = {
						target = root
						modifier = guilty_about_snapping_opinion
						opinion = -10
					}
				}
			}
		}
		ai_chance = {
			base = 100
		}
	}
}

# ============================================================
# LATE SNAPPING - Traumatic life events for older characters
# Fires for characters age 17-30 with dormant potential
# Triggered by imprisonment, combat, near-death experiences
# ============================================================
mistborn_snapping.0040 = {
	type = character_event
	title = mistborn_snapping.0040.t
	desc = mistborn_snapping.0040.desc
	theme = secret

	left_portrait = {
		character = root
		animation = pain
	}

	trigger = {
		OR = {
			has_trait = trait_allomantic_potential
			has_trait = trait_mistborn_potential
		}
		age >= 17
		age <= 30
		NOT = { has_trait = trait_mistborn }
		NOT = { is_allomancer_trigger = yes }
		NOT = { has_character_flag = late_snapping_attempted }
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = 0.5
			is_imprisoned = yes
		}
		modifier = {
			add = 0.3
			has_trait = brave
		}
		modifier = {
			add = 0.3
			has_trait = wrathful
		}
	}

	immediate = {
		add_character_flag = {
			flag = late_snapping_attempted
			years = 3
		}
	}

	# The trauma triggers a late Snapping
	option = {
		name = mistborn_snapping.0040.a
		# Late snapping has lower success chance (15%)
		random_list = {
			15 = {
				# Success - late Snapping occurs
				trigger_event = {
					id = mistborn_snapping.0020
					days = 1
				}
			}
			75 = {
				# Failure - the moment passes
				add_stress = 20
				custom_tooltip = mistborn_snapping.0040.a.fail
			}
			10 = {
				# Injury from the trauma
				add_trait = wounded_1
				add_stress = 30
				custom_tooltip = mistborn_snapping.0040.a.injured
			}
		}
		ai_chance = {
			base = 100
		}
	}

	# Resist the trauma - refuse to break
	option = {
		name = mistborn_snapping.0040.b
		add_stress = 10
		stress_impact = {
			brave = -10
			craven = 10
		}
		ai_chance = {
			base = 20
		}
	}
}
