############################################
# 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
	}
	effect = {
		# Check Lord Ruler attention thresholds and fire appropriate events
		if = {
			limit = {
				is_ruler = yes
				has_variable = lord_ruler_attention
			}
			# Tier 3 - The Lord Ruler's Wrath
			if = {
				limit = {
					var:lord_ruler_attention >= 90
				}
				trigger_event = {
					id = mistborn_lord_ruler.0020
					days = { 30 90 }
				}
			}
			# Tier 2 - Inquisition Visit
			else_if = {
				limit = {
					var:lord_ruler_attention >= 60
				}
				trigger_event = {
					id = mistborn_lord_ruler.0010
					days = { 30 120 }
				}
			}
			# Tier 1 - Obligator Warning
			else_if = {
				limit = {
					var:lord_ruler_attention >= 25
				}
				trigger_event = {
					id = mistborn_lord_ruler.0001
					days = { 30 180 }
				}
			}
		}

		# 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
				}
				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 = {
	effect = {
		every_ruler = {
			limit = {
				is_ruler = yes
				highest_held_title_tier >= tier_county
			}
			set_variable = {
				name = lord_ruler_attention
				value = 0
			}
		}
	}
}

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