﻿############################################
# Mistborn: The Final Empire - On Actions
# Hooks into CK3's event system for Mistborn mechanics
############################################

# ============================================================
# ON BIRTHDAY - Check for natural Snapping
# ============================================================
on_birthday = {
	events = {
		mistborn_snapping.0001
	}
}

# ============================================================
# YEARLY PULSE - Lord Ruler attention and misc events
# ============================================================
on_yearly_pulse = {
	events = {
		mistborn_lord_ruler.0030		# Attention decay
		mistborn_lord_ruler.0040		# Attention gain tracking
		mistborn_misc.0020				# Skaa uprising chance
		mistborn_misc.0030				# Mist spirit encounter
		mistborn_misc.0040				# Atium discovery
		mistborn_metal.0001				# Metal reserves running low
		mistborn_metal.0010				# Metal reserves depleted
		mistborn_metal.0020				# Metal supply windfall
		mistborn_metal.0030				# Wartime metal scarcity
		mistborn_feruchemy.0001			# Feruchemy discovery for Terris characters
		mistborn_hemalurgy.0010			# Inquisitor transformation check
		mistborn_hemalurgy.0020			# Ruin's whispers
		mistborn_hemalurgy.0030			# Hemalurgy discovery risk
		mistborn_misc.0050				# Savant acquisition check
		mistborn_misc.0060				# Savant consequences
	}
	effect = {
		# Check Lord Ruler attention thresholds and apply tiered modifiers
		if = {
			limit = {
				is_ruler = yes
				has_variable = lord_ruler_attention
			}
			# Tier 3 - The Lord Ruler's Wrath (attention >= 90)
			if = {
				limit = {
					var:lord_ruler_attention >= 90
				}
				if = {
					limit = { NOT = { has_character_modifier = lord_ruler_attention_3 } }
					add_character_modifier = lord_ruler_attention_3
				}
				remove_character_modifier = lord_ruler_attention_1
				remove_character_modifier = lord_ruler_attention_2
				trigger_event = {
					id = mistborn_lord_ruler.0020
					days = { 30 90 }
				}
			}
			# Tier 2 - Inquisition Visit (attention >= 60)
			else_if = {
				limit = {
					var:lord_ruler_attention >= 60
				}
				if = {
					limit = { NOT = { has_character_modifier = lord_ruler_attention_2 } }
					add_character_modifier = lord_ruler_attention_2
				}
				remove_character_modifier = lord_ruler_attention_1
				remove_character_modifier = lord_ruler_attention_3
				trigger_event = {
					id = mistborn_lord_ruler.0010
					days = { 30 120 }
				}
			}
			# Tier 1 - Obligator Warning (attention >= 25)
			else_if = {
				limit = {
					var:lord_ruler_attention >= 25
				}
				if = {
					limit = { NOT = { has_character_modifier = lord_ruler_attention_1 } }
					add_character_modifier = lord_ruler_attention_1
				}
				remove_character_modifier = lord_ruler_attention_2
				remove_character_modifier = lord_ruler_attention_3
				trigger_event = {
					id = mistborn_lord_ruler.0001
					days = { 30 180 }
				}
			}
			# Below threshold - remove all tiered modifiers
			else = {
				remove_character_modifier = lord_ruler_attention_1
				remove_character_modifier = lord_ruler_attention_2
				remove_character_modifier = lord_ruler_attention_3
			}
		}

		# Compounding check - if character has both Allomancy and Feruchemy
		if = {
			limit = {
				is_ruler = yes
				has_trait = trait_feruchemist
				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
				}
				NOT = { has_character_modifier = compounder_modifier }
				NOT = { has_character_flag = compounding_check_done }
			}
			trigger_event = {
				id = mistborn_misc.0010
				days = { 1 30 }
			}
		}
	}
}

# ============================================================
# ON GAME START - Initialize variables for starting rulers
# ============================================================
on_game_start = {
	events = {
		mistborn_init.0001
	}
}

# ============================================================
# ON CHARACTER CREATED - Set up new characters
# ============================================================
on_birth = {
	events = {
		# Future: Add events for checking Allomantic potential at birth
	}
}

# ============================================================
# ON IMPRISON - Late Snapping from imprisonment trauma
# ============================================================
on_imprison = {
	events = {
		mistborn_snapping.0040		# Late snapping for characters 17-30 with potential
	}
}
