############################################
# Miscellaneous Mistborn Events
# Kandra, Compounding, Skaa Uprisings
############################################

namespace = mistborn_misc

# ============================================================
# KANDRA EVENT - A shapeshifter enters your service
# Triggered by hire_kandra_decision
# ============================================================
mistborn_misc.0001 = {
	type = character_event
	title = mistborn_misc.0001.t
	desc = mistborn_misc.0001.desc
	theme = intrigue

	left_portrait = {
		character = root
		animation = scheme
	}

	trigger = {
		has_character_flag = hired_kandra
	}

	immediate = {
		remove_character_flag = hired_kandra
	}

	# Option A: Infiltrate a rival court
	option = {
		name = mistborn_misc.0001.a
		remove_short_term_gold = 200
		# Find a rival to infiltrate
		random_neighboring_top_liege_realm_owner = {
			limit = {
				is_ruler = yes
				NOT = { this = root }
			}
			save_scope_as = kandra_target
		}
		if = {
			limit = {
				exists = scope:kandra_target
			}
			add_intrigue_lifestyle_xp = 100
			# The kandra will report back
			add_character_flag = {
				flag = kandra_infiltrating
				years = 3
			}
		}
		ai_chance = {
			base = 40
		}
	}

	# Option B: Gather secrets from within your own court
	option = {
		name = mistborn_misc.0001.b
		remove_short_term_gold = 150
		add_intrigue_lifestyle_xp = 75
		# Discover hidden plots
		random_list = {
			60 = {
				custom_tooltip = mistborn_misc.0001.b.success
				add_prestige = 50
			}
			40 = {
				custom_tooltip = mistborn_misc.0001.b.fail
			}
		}
		ai_chance = {
			base = 30
		}
	}

	# Option C: Use the kandra for assassination
	option = {
		name = mistborn_misc.0001.c
		remove_short_term_gold = 300
		add_tyranny = 10
		add_stress = 20
		stress_impact = {
			compassionate = 30
			just = 20
		}
		# Select a target
		random_neighboring_top_liege_realm_owner = {
			limit = {
				is_ruler = yes
				NOT = { this = root }
			}
			save_scope_as = assassination_target
		}
		if = {
			limit = {
				exists = scope:assassination_target
			}
			random_list = {
				50 = {
					# Success
					scope:assassination_target = {
						death = {
							death_reason = death_murder
							killer = root
						}
					}
					custom_tooltip = mistborn_misc.0001.c.success
				}
				30 = {
					# Failure - kandra is discovered
					custom_tooltip = mistborn_misc.0001.c.fail
					add_prestige = -100
				}
				20 = {
					# Kandra refuses - they have their own Contract
					custom_tooltip = mistborn_misc.0001.c.refuse
					add_gold = 100
				}
			}
		}
		ai_chance = {
			base = 15
			modifier = {
				add = 15
				has_trait = callous
			}
		}
	}
}

# ============================================================
# COMPOUNDING DISCOVERY
# A character with both Allomancy and Feruchemy discovers Compounding
# ============================================================
mistborn_misc.0010 = {
	type = character_event
	title = mistborn_misc.0010.t
	desc = mistborn_misc.0010.desc
	theme = learning

	left_portrait = {
		character = root
		animation = ecstasy
	}

	trigger = {
		# Must have both an Allomantic trait and Feruchemy
		OR = {
			has_trait = trait_mistborn
			has_trait = trait_misting_coinshot
			has_trait = trait_misting_lurcher
			has_trait = trait_misting_thug
			has_trait = trait_misting_tineye
			has_trait = trait_misting_soother
			has_trait = trait_misting_rioter
			has_trait = trait_misting_smoker
			has_trait = trait_misting_seeker
			has_trait = trait_misting_augur
			has_trait = trait_misting_oracle
			has_trait = trait_misting_duralumin
			has_trait = trait_misting_nicroburst
		}
		has_trait = trait_feruchemist
		NOT = { has_character_modifier = compounder_modifier }
		NOT = { has_character_flag = compounding_check_done }
	}

	immediate = {
		add_character_flag = {
			flag = compounding_check_done
			years = 100
		}
	}

	# Option A: Embrace the power
	option = {
		name = mistborn_misc.0010.a
		add_character_modifier = {
			modifier = compounder_modifier
		}
		add_prestige = 200
		# The Lord Ruler takes EXTREME notice of Compounders
		if = {
			limit = {
				has_variable = lord_ruler_attention
			}
			change_variable = {
				name = lord_ruler_attention
				add = 30
			}
		}
		else = {
			set_variable = {
				name = lord_ruler_attention
				value = 30
			}
		}
		ai_chance = {
			base = 70
		}
	}

	# Option B: Suppress the knowledge - too dangerous
	option = {
		name = mistborn_misc.0010.b
		add_stress = 30
		add_learning_lifestyle_xp = 100
		# Do not become a Compounder - safer
		ai_chance = {
			base = 30
			modifier = {
				add = 30
				has_trait = craven
			}
		}
	}
}

# ============================================================
# SKAA UPRISING
# Skaa in your lands rebel against noble oppression
# ============================================================
mistborn_misc.0020 = {
	type = character_event
	title = mistborn_misc.0020.t
	desc = mistborn_misc.0020.desc
	theme = war

	left_portrait = {
		character = root
		animation = anger
	}

	trigger = {
		is_ruler = yes
		highest_held_title_tier >= tier_county
		NOT = { has_character_flag = recent_skaa_uprising }
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = 0.5
			any_held_county = {
				county_opinion < -20
			}
		}
		modifier = {
			add = 0.3
			has_trait = callous
		}
		modifier = {
			add = 0.3
			has_trait = greedy
		}
	}

	immediate = {
		add_character_flag = {
			flag = recent_skaa_uprising
			years = 5
		}
	}

	# Option A: Crush brutally - the noble way
	option = {
		name = mistborn_misc.0020.a
		add_dread = 30
		add_tyranny = 5
		add_prestige = 25
		# Reduce rebellion but increase long-term resentment
		capital_county = {
			add_county_modifier = {
				modifier = brutal_repression
				years = 2
			}
		}
		stress_impact = {
			compassionate = 20
			callous = -10
			just = 15
		}
		ai_chance = {
			base = 50
			modifier = {
				add = 20
				has_trait = callous
			}
			modifier = {
				add = 20
				has_trait = wrathful
			}
		}
	}

	# Option B: Negotiate and offer concessions
	option = {
		name = mistborn_misc.0020.b
		remove_short_term_gold = 100
		add_prestige = -25
		# Reduces tension more effectively
		stress_impact = {
			callous = 10
			compassionate = -10
		}
		ai_chance = {
			base = 30
			modifier = {
				add = 20
				has_trait = compassionate
			}
			modifier = {
				add = 15
				has_trait = just
			}
		}
	}

	# Option C: Recruit the rebels - absorb their strength
	option = {
		name = mistborn_misc.0020.c
		trigger = {
			intrigue >= 12
		}
		add_prestige = -50
		# May find hidden skaa Allomancers
		random_list = {
			30 = {
				# Found a skaa Misting
				custom_tooltip = mistborn_misc.0020.c.found_misting
				add_intrigue_lifestyle_xp = 50
			}
			70 = {
				# Just regular rebels
				custom_tooltip = mistborn_misc.0020.c.normal
			}
		}
		# Draws Steel Ministry attention
		if = {
			limit = {
				has_variable = lord_ruler_attention
			}
			change_variable = {
				name = lord_ruler_attention
				add = 5
			}
		}
		ai_chance = {
			base = 15
			modifier = {
				add = 20
				has_trait = deceitful
			}
		}
	}
}

# ============================================================
# MIST SPIRIT ENCOUNTER
# A mysterious spirit appears in the mists
# ============================================================
mistborn_misc.0030 = {
	type = character_event
	title = mistborn_misc.0030.t
	desc = mistborn_misc.0030.desc
	theme = secret

	left_portrait = {
		character = root
		animation = fear
	}

	trigger = {
		is_ruler = yes
		NOT = { has_character_flag = recent_mist_spirit }
		OR = {
			has_trait = trait_mistborn
			has_trait = trait_feruchemist
			has_trait = trait_allomantic_potential
			has_trait = trait_mistborn_potential
		}
	}

	weight_multiplier = {
		base = 0.1
	}

	immediate = {
		add_character_flag = {
			flag = recent_mist_spirit
			years = 10
		}
	}

	# Option A: Follow the spirit into the mists
	option = {
		name = mistborn_misc.0030.a
		random_list = {
			40 = {
				# Gain insight
				add_learning_lifestyle_xp = 100
				add_piety = 50
				custom_tooltip = mistborn_misc.0030.a.insight
			}
			40 = {
				# Nothing happens - just fog
				add_stress = 10
				custom_tooltip = mistborn_misc.0030.a.nothing
			}
			20 = {
				# Wounded by something in the mists
				add_trait = wounded_1
				custom_tooltip = mistborn_misc.0030.a.danger
			}
		}
		ai_chance = {
			base = 30
			modifier = {
				add = 20
				has_trait = brave
			}
		}
	}

	# Option B: Retreat to safety
	option = {
		name = mistborn_misc.0030.b
		add_stress = 5
		stress_impact = {
			brave = 10
			craven = -5
		}
		ai_chance = {
			base = 70
		}
	}
}

# ============================================================
# ATIUM DISCOVERY
# A cache of atium is found - incredibly valuable
# ============================================================
mistborn_misc.0040 = {
	type = character_event
	title = mistborn_misc.0040.t
	desc = mistborn_misc.0040.desc
	theme = stewardship

	left_portrait = {
		character = root
		animation = happiness
	}

	trigger = {
		is_ruler = yes
		NOT = { has_character_flag = recent_atium_find }
	}

	weight_multiplier = {
		base = 0.05
		modifier = {
			add = 0.5
			any_held_county = {
				this = title:c_pits_of_hathsin
			}
		}
	}

	immediate = {
		add_character_flag = {
			flag = recent_atium_find
			years = 10
		}
	}

	# Option A: Sell it for gold
	option = {
		name = mistborn_misc.0040.a
		add_gold = 500
		ai_chance = {
			base = 40
		}
	}

	# Option B: Keep it for your Mistborn
	option = {
		name = mistborn_misc.0040.b
		trigger = {
			OR = {
				has_trait = trait_mistborn
				any_courtier = {
					has_trait = trait_mistborn
				}
			}
		}
		add_prestige = 100
		# Temporary combat bonus
		add_character_flag = {
			flag = has_atium_reserve
			years = 5
		}
		ai_chance = {
			base = 40
		}
	}

	# Option C: Tribute it to the Lord Ruler
	option = {
		name = mistborn_misc.0040.c
		add_piety = 100
		add_prestige = 50
		if = {
			limit = {
				has_variable = lord_ruler_attention
			}
			change_variable = {
				name = lord_ruler_attention
				add = -10
			}
		}
		ai_chance = {
			base = 20
			modifier = {
				add = 20
				has_trait = zealous
			}
		}
	}
}

# ============================================================
# SAVANT ACQUISITION
# Long-term Allomancers with trait_allomantic_strong may develop
# savantism through constant metal-burning
# ============================================================
mistborn_misc.0050 = {
	type = character_event
	title = mistborn_misc.0050.t
	desc = mistborn_misc.0050.desc
	theme = education

	left_portrait = {
		character = root
		animation = worry
	}

	trigger = {
		is_allomancer_trigger = yes
		has_trait = trait_allomantic_strong
		NOT = { has_trait = trait_allomantic_savant }
		NOT = { has_character_flag = savant_check_done }
		# Must have been an Allomancer for a long time (proxy: age 30+, since snapping happens 10-16)
		age >= 30
	}

	weight_multiplier = {
		base = 0.05
		modifier = {
			add = 0.05
			has_trait = trait_mistborn
		}
		modifier = {
			add = 0.03
			age >= 40
		}
	}

	immediate = {
		add_character_flag = {
			flag = savant_check_done
			years = 5
		}
	}

	# Option A: Embrace the intensity - become a savant
	option = {
		name = mistborn_misc.0050.a
		if = {
			limit = { has_trait = trait_allomantic_strong }
			remove_trait = trait_allomantic_strong
		}
		add_trait = trait_allomantic_savant
		add_prestige = 50
		custom_tooltip = mistborn_misc.0050.a.tt
		ai_chance = {
			base = 40
			modifier = {
				add = 20
				has_trait = ambitious
			}
			modifier = {
				add = 20
				has_trait = brave
			}
		}
	}

	# Option B: Pull back - maintain control
	option = {
		name = mistborn_misc.0050.b
		add_stress = 20
		custom_tooltip = mistborn_misc.0050.b.tt
		ai_chance = {
			base = 60
			modifier = {
				add = 20
				has_trait = temperate
			}
		}
	}
}

# ============================================================
# SAVANT CONSEQUENCES
# Yearly random events for characters with trait_allomantic_savant
# ============================================================
mistborn_misc.0060 = {
	type = character_event
	title = mistborn_misc.0060.t
	desc = mistborn_misc.0060.desc
	theme = education

	left_portrait = {
		character = root
		animation = stress
	}

	trigger = {
		has_trait = trait_allomantic_savant
		NOT = { has_character_flag = recent_savant_episode }
	}

	weight_multiplier = {
		base = 0.3
	}

	immediate = {
		add_character_flag = {
			flag = recent_savant_episode
			years = 2
		}
	}

	# Option A: Heightened senses cause paranoia
	option = {
		name = mistborn_misc.0060.a
		add_stress = 30
		random_list = {
			50 = {
				# The paranoia was justified — you detect a real threat
				add_intrigue_lifestyle_xp = 50
				custom_tooltip = mistborn_misc.0060.a.justified
			}
			50 = {
				# False alarm — the paranoia is just the savantism talking
				add_stress = 10
				custom_tooltip = mistborn_misc.0060.a.false
			}
		}
		ai_chance = {
			base = 30
		}
	}

	# Option B: Channel the power surge — enhanced abilities
	option = {
		name = mistborn_misc.0060.b
		# Temporary prowess boost at the cost of health
		add_character_modifier = {
			modifier = savant_power_surge
			years = 1
		}
		ai_chance = {
			base = 40
		}
	}

	# Option C: Resist the compulsion — try to regain control
	option = {
		name = mistborn_misc.0060.c
		add_stress = 15
		stress_impact = {
			temperate = -10
			brave = -5
		}
		add_learning_lifestyle_xp = 50
		ai_chance = {
			base = 30
		}
	}
}
