﻿# Mistborn: The Final Empire - Scripted Effects
# Reusable effects for Allomantic activation, Lord Ruler attention, and other game mechanics

# ===== ALLOMANCY ACTIVATION =====

activate_allomancy_effect = {
	# Converts hidden allomantic_potential trait to an active Allomantic power
	# Should be triggered by a "snapping" event (near-death trauma)

	if = {
		limit = { has_trait = trait_allomantic_potential }
		remove_trait = trait_allomantic_potential

		# Determine which metal the character can burn
		# Weight heavily influenced by heritage and genetics
		random_list = {
			10 = {
				# Mistborn - extremely rare, can burn all metals
				trigger = {
					any_parent = { has_trait = trait_mistborn }
				}
				add_trait = trait_mistborn
			}
			20 = { add_trait = trait_misting_lurcher }      # Iron
			20 = { add_trait = trait_misting_coinshot }     # Steel
			15 = { add_trait = trait_misting_tineye }       # Tin
			20 = { add_trait = trait_misting_thug }         # Pewter
			15 = { add_trait = trait_misting_rioter }       # Zinc
			15 = { add_trait = trait_misting_soother }      # Brass
			15 = { add_trait = trait_misting_smoker }       # Copper
			15 = { add_trait = trait_misting_seeker }       # Bronze
			5 = { add_trait = trait_misting_augur }         # Gold - rare
			1 = { add_trait = trait_misting_oracle }        # Atium - extremely rare
			3 = { add_trait = trait_misting_duralumin }     # Duralumin - very rare
			3 = { add_trait = trait_misting_nicroburst }    # Nicrosil - very rare
		}
	}
}

# ===== LORD RULER ATTENTION =====

increase_lord_ruler_attention_effect = {
	# The Lord Ruler and Steel Ministry take notice of the character
	# Uses the variable-based system tracked in on_actions

	if = {
		limit = {
			NOT = { has_variable = lord_ruler_attention }
		}
		set_variable = {
			name = lord_ruler_attention
			value = 0
		}
	}

	change_variable = {
		name = lord_ruler_attention
		add = 15
	}

	# Cap at 100
	if = {
		limit = {
			var:lord_ruler_attention > 100
		}
		set_variable = {
			name = lord_ruler_attention
			value = 100
		}
	}
}

decrease_lord_ruler_attention_effect = {
	# The character manages to reduce the Lord Ruler's scrutiny

	if = {
		limit = {
			has_variable = lord_ruler_attention
			var:lord_ruler_attention > 0
		}
		change_variable = {
			name = lord_ruler_attention
			add = -15
		}

		# Ensure attention doesn't go below 0
		if = {
			limit = {
				var:lord_ruler_attention < 0
			}
			set_variable = {
				name = lord_ruler_attention
				value = 0
			}
		}
	}
}

# ===== SNAPPING EFFECT =====

trigger_snapping_effect = {
	# Utility effect: triggers the snapping event chain for a character with potential.
	# The actual Misting type assignment happens in mistborn_snapping.0020's immediate block,
	# which is the single source of truth for weighted random Misting type selection.
	if = {
		limit = {
			can_snap_trigger = yes
		}
		trigger_event = {
			id = mistborn_snapping.0020
			days = 1
		}
	}
}

# ===== HEMALURGY EFFECTS =====

apply_hemalurgic_spike_effect = {
	# Apply a hemalurgic spike to grant stolen powers (at the cost of sanity)
	add_trait = trait_hemalurgist

	# Hemalurgy comes with costs
	stress_impact = {
		base = massive_stress_impact_gain
	}
}

create_steel_inquisitor_effect = {
	# Transform a character into a Steel Inquisitor via multiple hemalurgic spikes
	# Grants all hemalurgic traits and massive power
	add_trait = trait_hemalurgist
	add_trait = trait_hemalurgic_steel
	add_trait = trait_hemalurgic_pewter
	add_trait = trait_hemalurgic_bronze
	add_trait = trait_hemalurgic_atium

	# Physical transformation
	add_trait = disfigured # Spikes through the eyes
}

# ===== KANDRA CONTRACT EFFECTS =====

assign_kandra_contract_effect = {
	# Assigns a kandra to serve this character
	# The kandra becomes a courtier and gains a flag for the contract
	scope:kandra_target = {
		set_relation_guardian = root  # Represents the Contract bond
		add_character_flag = kandra_contract_active
	}
}

# ===== HOUSE AND DYNASTY EFFECTS =====

establish_great_house_effect = {
	# Elevate a noble house to Great House status
	dynasty = {
		add_dynasty_prestige = 500
	}

	add_prestige = 250
}

strip_great_house_effect = {
	# Remove Great House status (usually by Lord Ruler decree)
	dynasty = {
		add_dynasty_prestige = -500
	}

	add_prestige = -500
}

# ===== ATIUM EFFECTS =====

grant_atium_supply_effect = {
	# Character receives a supply of atium (extremely valuable)
	add_gold = 200
}

deplete_atium_supply_effect = {
	# Character's atium supply runs out
	# No-op if not holding atium
}

# ===== ARTIFACT CREATION EFFECTS =====

create_mistcloak_effect = {
	# Creates and equips a mistcloak artifact for the scoped character
	# $QUALITY$ parameter: 1=poor, 2=common, 3=fine, 4=excellent, 5=masterwork
	create_artifact = {
		name = mistcloak_artifact_name
		description = mistcloak_artifact_desc
		type = mistcloak
		template = standard_mistcloak
		visuals = mistcloak
		quality = $QUALITY$
		modifier = {
			prowess = 2
			intrigue = 2
			dread_baseline_add = 5
		}
	}
}

create_metal_vial_set_effect = {
	# Creates and equips a metal vial set artifact
	create_artifact = {
		name = metal_vial_set_artifact_name
		description = metal_vial_set_artifact_desc
		type = metal_vial_set
		template = metal_vial_set_template
		visuals = metal_vial_set
		quality = $QUALITY$
		modifier = {
			prowess = 1
		}
	}
}

create_glass_daggers_effect = {
	# Creates and equips glass daggers artifact
	create_artifact = {
		name = glass_daggers_artifact_name
		description = glass_daggers_artifact_desc
		type = glass_daggers
		template = glass_daggers_template
		visuals = glass_daggers
		quality = $QUALITY$
		modifier = {
			prowess = 3
		}
	}
}

create_dueling_canes_effect = {
	# Creates and equips dueling canes artifact
	create_artifact = {
		name = dueling_canes_artifact_name
		description = dueling_canes_artifact_desc
		type = dueling_canes
		template = dueling_canes_template
		visuals = dueling_canes
		quality = $QUALITY$
		modifier = {
			diplomacy = 1
			prowess = 1
		}
	}
}

create_koloss_sword_effect = {
	# Creates and equips a koloss sword artifact
	create_artifact = {
		name = koloss_sword_artifact_name
		description = koloss_sword_artifact_desc
		type = koloss_sword
		template = koloss_sword_template
		visuals = koloss_sword
		quality = $QUALITY$
		modifier = {
			prowess = 6
			martial = 2
			diplomacy = -2
		}
	}
}

create_coppermind_effect = {
	# Creates and equips a coppermind artifact
	create_artifact = {
		name = coppermind_artifact_name
		description = coppermind_artifact_desc
		type = coppermind
		template = coppermind_template
		visuals = coppermind
		quality = $QUALITY$
		modifier = {
			learning = 4
			intrigue = 1
		}
	}
}

create_metalmind_set_effect = {
	# Creates and equips a metalmind set artifact
	create_artifact = {
		name = metalmind_set_artifact_name
		description = metalmind_set_artifact_desc
		type = metalmind_set
		template = metalmind_set_template
		visuals = metalmind_set
		quality = $QUALITY$
		modifier = {
			health = 0.5
			prowess = 2
		}
	}
}

create_atium_bracers_effect = {
	# Creates the Lord Ruler's unique atium bracers — only one exists
	create_artifact = {
		name = atium_bracers_artifact_name
		description = atium_bracers_artifact_desc
		type = atium_bracers
		template = lord_ruler_atium_bracers
		visuals = atium_bracers
		quality = 6
		modifier = {
			health = 5
			prowess = 10
			monthly_prestige = 1.0
		}
	}
}

create_inquisitor_spike_set_effect = {
	# Creates inquisitor spike set artifact
	create_artifact = {
		name = inquisitor_spike_set_artifact_name
		description = inquisitor_spike_set_artifact_desc
		type = inquisitor_spike_set
		template = steel_inquisitor_spikes
		visuals = inquisitor_spike_set
		quality = 5
		modifier = {
			prowess = 8
			martial = 4
			intrigue = 3
			dread_baseline_add = 20
			diplomacy = -5
			attraction_opinion = -30
		}
	}
}

# ===== GAME START ARTIFACT ASSIGNMENT =====

assign_starting_artifacts_effect = {
	# Called from on_game_start to give canonical characters their artifacts

	# Lord Ruler (900100) — atium bracers (legendary)
	character:900100 = {
		create_atium_bracers_effect = yes
	}

	# Kelsier (900200) — mistcloak (excellent), glass daggers (good)
	character:900200 = {
		create_mistcloak_effect = { QUALITY = 4 }
		create_glass_daggers_effect = { QUALITY = 3 }
	}

	# Vin (900201) — no starting artifacts (receives mistcloak via events in M6)

	# Sazed (900202) — coppermind (masterwork)
	character:900202 = {
		create_coppermind_effect = { QUALITY = 5 }
	}

	# Breeze (900203) — metal vial set (common)
	character:900203 = {
		create_metal_vial_set_effect = { QUALITY = 2 }
	}

	# Ham (900204) — metal vial set (common)
	character:900204 = {
		create_metal_vial_set_effect = { QUALITY = 2 }
	}

	# Clubs (900205) — metal vial set (common)
	character:900205 = {
		create_metal_vial_set_effect = { QUALITY = 2 }
	}

	# Great House heads — dueling canes (quality varies by house power)
	# Straff Venture (900001) — excellent canes (most powerful house) + excellent vials (Tineye)
	character:900001 = {
		create_dueling_canes_effect = { QUALITY = 4 }
		create_metal_vial_set_effect = { QUALITY = 4 }
	}
	# Jordren Hasting (900010) — fine (military house)
	character:900010 = {
		create_dueling_canes_effect = { QUALITY = 3 }
	}
	# Trentohn Elariel (900020) — fine (intrigue house)
	character:900020 = {
		create_dueling_canes_effect = { QUALITY = 3 }
	}
	# Dagren Tekiel (900030) — excellent (wealthy trade house)
	character:900030 = {
		create_dueling_canes_effect = { QUALITY = 4 }
	}
	# Brodren Lekal (900040) — fine (diplomacy house)
	character:900040 = {
		create_dueling_canes_effect = { QUALITY = 3 }
	}

	# Shan Elariel (900021) — dueling canes only (NO mistcloak — she is a secret Mistborn)
	character:900021 = {
		create_dueling_canes_effect = { QUALITY = 4 }
	}

	# Steel Inquisitors (900300-900302) — inquisitor spike sets
	character:900300 = {
		create_inquisitor_spike_set_effect = yes
	}
	character:900301 = {
		create_inquisitor_spike_set_effect = yes
	}
	character:900302 = {
		create_inquisitor_spike_set_effect = yes
	}
}
