﻿############################################
# Hemalurgy Event Chain
# The dark art of stealing powers through metal spikes
############################################

namespace = mistborn_hemalurgy

# ============================================================
# HEMALURGIC SPIKE CREATION
# Triggered by commission_hemalurgic_spike_decision
# The schemer targets a courtier with Allomantic abilities
# ============================================================
mistborn_hemalurgy.0001 = {
	type = character_event
	title = mistborn_hemalurgy.0001.t
	desc = mistborn_hemalurgy.0001.desc
	theme = secret

	left_portrait = {
		character = root
		animation = scheme
	}

	trigger = {
		has_trait = trait_knows_hemalurgy
	}

	immediate = {
		# Find an Allomancer target in court
		random_courtier = {
			limit = {
				OR = {
					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
				}
			}
			save_scope_as = hemalurgy_victim
		}
	}

	# Option A: Proceed with the spike - kill the victim, steal their power
	option = {
		name = mistborn_hemalurgy.0001.a
		trigger = {
			exists = scope:hemalurgy_victim
		}
		add_stress = 50
		add_tyranny = 20
		stress_impact = {
			compassionate = 60
			just = 40
			callous = -20
			sadistic = -30
		}

		# Determine which hemalurgic trait to gain based on victim's power
		scope:hemalurgy_victim = {
			if = {
				limit = { has_trait = trait_misting_coinshot }
				root = { add_trait = trait_hemalurgic_steel }
			}
			else_if = {
				limit = {
					OR = {
						has_trait = trait_misting_thug
						has_trait = trait_misting_lurcher
					}
				}
				root = { add_trait = trait_hemalurgic_pewter }
			}
			else_if = {
				limit = {
					OR = {
						has_trait = trait_misting_seeker
						has_trait = trait_misting_smoker
					}
				}
				root = { add_trait = trait_hemalurgic_bronze }
			}
			else_if = {
				limit = { has_trait = trait_misting_oracle }
				root = { add_trait = trait_hemalurgic_atium }
			}
			else = {
				# Generic hemalurgic benefit for other metals
				root = { add_trait = trait_hemalurgic_steel }
			}

			# The victim dies
			death = {
				death_reason = death_murder
				killer = root
			}
		}

		# Add the hemalurgist trait if not already present
		if = {
			limit = { NOT = { has_trait = trait_hemalurgist } }
			add_trait = trait_hemalurgist
		}

		# Lord Ruler attention for practicing the forbidden art
		if = {
			limit = { has_variable = lord_ruler_attention }
			change_variable = {
				name = lord_ruler_attention
				add = 15
			}
		}
		else = {
			set_variable = {
				name = lord_ruler_attention
				value = 15
			}
		}

		ai_chance = {
			base = 60
			modifier = {
				add = 20
				has_trait = ambitious
			}
		}
	}

	# Option B: Abandon the plan - too dangerous
	option = {
		name = mistborn_hemalurgy.0001.b
		add_stress = 15
		add_piety = 20
		ai_chance = {
			base = 40
			modifier = {
				add = 30
				has_trait = craven
			}
		}
	}
}

# ============================================================
# THE INQUISITOR RISES
# Fires when a character has accumulated 3+ hemalurgic spike traits
# Offers full Inquisitor transformation
# ============================================================
mistborn_hemalurgy.0010 = {
	type = character_event
	title = mistborn_hemalurgy.0010.t
	desc = mistborn_hemalurgy.0010.desc
	theme = secret

	left_portrait = {
		character = root
		animation = rage
	}

	trigger = {
		has_trait = trait_hemalurgist
		has_multiple_spikes_trigger = yes
		NOT = { has_character_modifier = steel_inquisitor_power }
		NOT = { has_character_flag = inquisitor_transformation_offered }
	}

	weight_multiplier = {
		base = 1
		modifier = {
			factor = 0.3
		}
	}

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

	# Option A: Undergo the full transformation
	option = {
		name = mistborn_hemalurgy.0010.a
		create_steel_inquisitor_effect = yes
		add_character_modifier = steel_inquisitor_power

		# Massive dread and opinion consequences
		add_dread = 50

		# Lord Ruler attention — Inquisitors serve the Lord Ruler
		# Unauthorized Inquisitors draw enormous attention
		increase_lord_ruler_attention_effect = yes
		increase_lord_ruler_attention_effect = yes

		stress_impact = {
			compassionate = 80
			content = 40
			craven = -30
			ambitious = -20
		}

		ai_chance = {
			base = 40
			modifier = {
				add = 30
				has_trait = ambitious
			}
			modifier = {
				add = -20
				has_trait = craven
			}
		}
	}

	# Option B: Refuse — the price is too high
	option = {
		name = mistborn_hemalurgy.0010.b
		add_stress = 30
		add_piety = 10
		ai_chance = {
			base = 60
			modifier = {
				add = 20
				has_trait = content
			}
		}
	}
}

# ============================================================
# RUIN'S WHISPERS
# Fires periodically for characters with hemalurgic spikes
# Each spike creates a crack in the soul for Ruin to exploit
# ============================================================
mistborn_hemalurgy.0020 = {
	type = character_event
	title = mistborn_hemalurgy.0020.t
	desc = mistborn_hemalurgy.0020.desc
	theme = secret

	left_portrait = {
		character = root
		animation = stress
	}

	trigger = {
		has_trait = trait_hemalurgist
		has_hemalurgic_spike_trigger = yes
	}

	weight_multiplier = {
		base = 1

		# More spikes = more whispers
		modifier = {
			add = 0.5
			has_trait = trait_hemalurgic_steel
		}
		modifier = {
			add = 0.5
			has_trait = trait_hemalurgic_pewter
		}
		modifier = {
			add = 0.5
			has_trait = trait_hemalurgic_bronze
		}
		modifier = {
			add = 1.0
			has_trait = trait_hemalurgic_atium
		}

		# Already under Ruin's influence — whispers are stronger
		modifier = {
			add = 1.0
			has_character_modifier = ruin_influence
		}

		# Low base chance per year
		modifier = {
			factor = 0.15
		}
	}

	immediate = {
		# Nothing additional needed
	}

	# Option A: Resist the whispers
	option = {
		name = mistborn_hemalurgy.0020.a
		add_stress = 30
		add_learning_lifestyle_xp = 100
		stress_impact = {
			brave = -10
			zealous = -10
		}
		ai_chance = {
			base = 50
			modifier = {
				add = 20
				has_trait = brave
			}
			modifier = {
				add = 20
				has_trait = zealous
			}
		}
	}

	# Option B: Listen to Ruin — gain power at a cost
	option = {
		name = mistborn_hemalurgy.0020.b
		add_intrigue_lifestyle_xp = 150
		if = {
			limit = { NOT = { has_character_modifier = ruin_influence } }
			add_character_modifier = ruin_influence
		}
		add_stress = -20
		stress_impact = {
			cynical = -10
			ambitious = -10
			compassionate = 20
		}
		ai_chance = {
			base = 30
			modifier = {
				add = 20
				has_trait = cynical
			}
			modifier = {
				add = 20
				has_trait = ambitious
			}
		}
	}

	# Option C: Give in completely — embrace Ruin
	option = {
		name = mistborn_hemalurgy.0020.c
		set_character_faith = faith:cult_of_ruin
		if = {
			limit = { NOT = { has_trait = trait_knows_hemalurgy } }
			add_trait = trait_knows_hemalurgy
		}
		if = {
			limit = { NOT = { has_character_modifier = ruin_influence } }
			add_character_modifier = ruin_influence
		}
		add_stress = -40
		add_piety = -50
		stress_impact = {
			zealous = 60
			compassionate = 40
		}
		ai_chance = {
			base = 10
			modifier = {
				add = 15
				has_character_modifier = ruin_influence
			}
			modifier = {
				add = -10
				has_trait = zealous
			}
		}
	}
}

# ============================================================
# DISCOVERY BY THE STEEL MINISTRY
# The Ministry discovers a character practicing Hemalurgy
# ============================================================
mistborn_hemalurgy.0030 = {
	type = character_event
	title = mistborn_hemalurgy.0030.t
	desc = mistborn_hemalurgy.0030.desc
	theme = secret

	left_portrait = {
		character = root
		animation = fear
	}

	trigger = {
		has_trait = trait_hemalurgist
		NOT = { has_character_flag = hemalurgy_discovery_cooldown }
		# Must not already be an authorized Inquisitor (those serving the Ministry)
		NOT = { has_character_modifier = steel_ministry_favor }
	}

	weight_multiplier = {
		base = 1

		# More spikes = easier to detect
		modifier = {
			add = 0.3
			has_trait = trait_hemalurgic_steel
		}
		modifier = {
			add = 0.3
			has_trait = trait_hemalurgic_pewter
		}
		modifier = {
			add = 0.3
			has_trait = trait_hemalurgic_bronze
		}
		modifier = {
			add = 0.5
			has_trait = trait_hemalurgic_atium
		}

		# Inquisitors are very conspicuous
		modifier = {
			add = 2.0
			has_character_modifier = steel_inquisitor_power
		}

		# Smokers can hide Allomantic pulses
		modifier = {
			factor = 0.5
			any_courtier = {
				has_trait = trait_misting_smoker
			}
		}

		# Low base chance
		modifier = {
			factor = 0.1
		}
	}

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

	# Option A: Bribe the Obligator to look away
	option = {
		name = mistborn_hemalurgy.0030.a
		remove_short_term_gold = 100
		add_stress = 20
		ai_chance = {
			base = 40
			modifier = {
				add = 20
				gold >= 200
			}
		}
	}

	# Option B: Deny everything — bluff your way out
	option = {
		name = mistborn_hemalurgy.0030.b
		# Success depends on intrigue
		random_list = {
			50 = {
				modifier = {
					add = 20
					intrigue >= 15
				}
				modifier = {
					add = 10
					intrigue >= 20
				}
				custom_tooltip = mistborn_hemalurgy.0030.b.success
				add_stress = 10
			}
			50 = {
				modifier = {
					add = 20
					intrigue < 10
				}
				custom_tooltip = mistborn_hemalurgy.0030.b.fail
				increase_lord_ruler_attention_effect = yes
				increase_lord_ruler_attention_effect = yes
				add_stress = 40
			}
		}
		ai_chance = {
			base = 30
			modifier = {
				add = 30
				intrigue >= 15
			}
		}
	}

	# Option C: Flee before they come for you
	option = {
		name = mistborn_hemalurgy.0030.c
		add_prestige = -200
		increase_lord_ruler_attention_effect = yes
		add_stress = 30
		ai_chance = {
			base = 20
			modifier = {
				add = 20
				has_trait = craven
			}
		}
	}
}
