﻿############################################
# Allomantic Training Event Chain
# A mentor trains a pupil to strengthen their Allomancy
# Completion can grant trait_allomantic_strong
############################################

namespace = mistborn_training

# ============================================================
# TRAINING BEGINS - Choose a training focus
# ============================================================
mistborn_training.0001 = {
	type = character_event
	title = mistborn_training.0001.t
	desc = mistborn_training.0001.desc
	theme = education

	left_portrait = {
		character = root
		animation = personality_rational
	}

	right_portrait = {
		character = scope:training_pupil
		animation = personality_bold
	}

	trigger = {
		exists = scope:training_pupil
	}

	immediate = {
		# Find a mentor — prefer self if Allomancer, else a courtier
		if = {
			limit = {
				is_allomancer_trigger = yes
			}
			save_scope_as = training_mentor
		}
		else = {
			random_courtier = {
				limit = {
					is_allomancer_trigger = yes
				}
				save_scope_as = training_mentor
			}
		}
	}

	# Option A: Combat training - martial focus
	option = {
		name = mistborn_training.0001.a
		scope:training_pupil = {
			add_character_flag = {
				flag = training_focus_combat
				years = 5
			}
		}
		trigger_event = {
			id = mistborn_training.0010
			days = { 365 730 }
		}
		ai_chance = {
			base = 40
			modifier = {
				add = 20
				scope:training_pupil = {
					is_physical_allomancer_trigger = yes
				}
			}
		}
	}

	# Option B: Subtlety training - intrigue focus
	option = {
		name = mistborn_training.0001.b
		scope:training_pupil = {
			add_character_flag = {
				flag = training_focus_subtlety
				years = 5
			}
		}
		trigger_event = {
			id = mistborn_training.0010
			days = { 365 730 }
		}
		ai_chance = {
			base = 40
			modifier = {
				add = 20
				scope:training_pupil = {
					is_mental_allomancer_trigger = yes
				}
			}
		}
	}

	# Option C: Endurance training - health/stamina focus
	option = {
		name = mistborn_training.0001.c
		scope:training_pupil = {
			add_character_flag = {
				flag = training_focus_endurance
				years = 5
			}
		}
		trigger_event = {
			id = mistborn_training.0010
			days = { 365 730 }
		}
		ai_chance = {
			base = 20
		}
	}
}

# ============================================================
# MID-TRAINING CHALLENGE - A test arises
# ============================================================
mistborn_training.0010 = {
	type = character_event
	title = mistborn_training.0010.t
	desc = mistborn_training.0010.desc
	theme = education

	left_portrait = {
		character = root
		animation = worry
	}

	right_portrait = {
		character = scope:training_pupil
		animation = personality_bold
	}

	trigger = {
		exists = scope:training_pupil
		scope:training_pupil = {
			is_alive = yes
			has_character_flag = undergoing_allomantic_training
		}
	}

	immediate = {
		# Nothing to do — challenge is presented in options
	}

	# Option A: Push them harder — risk injury for greater reward
	option = {
		name = mistborn_training.0010.a
		scope:training_pupil = {
			random_list = {
				60 = {
					# They rise to the challenge
					modifier = {
						add = 15
						has_trait = brave
					}
					modifier = {
						add = 10
						root = { has_trait = trait_mistborn }
					}
					add_character_flag = {
						flag = training_challenge_passed
						years = 5
					}
					custom_tooltip = mistborn_training.0010.a.success
				}
				30 = {
					# They struggle but persevere
					add_stress = 20
					custom_tooltip = mistborn_training.0010.a.partial
				}
				10 = {
					# Injury during training
					add_trait = wounded_1
					add_stress = 30
					trigger_event = {
						id = mistborn_training.0030
						days = 7
					}
					custom_tooltip = mistborn_training.0010.a.injury
				}
			}
		}
		# Schedule completion if no interruption
		trigger_event = {
			id = mistborn_training.0020
			days = { 365 730 }
		}
		ai_chance = {
			base = 50
		}
	}

	# Option B: Take a measured approach — safer, lower chance
	option = {
		name = mistborn_training.0010.b
		scope:training_pupil = {
			random_list = {
				40 = {
					# Steady progress
					add_character_flag = {
						flag = training_challenge_passed
						years = 5
					}
					custom_tooltip = mistborn_training.0010.b.success
				}
				60 = {
					# No breakthrough — adequate but unremarkable
					custom_tooltip = mistborn_training.0010.b.adequate
				}
			}
		}
		trigger_event = {
			id = mistborn_training.0020
			days = { 365 730 }
		}
		ai_chance = {
			base = 50
		}
	}
}

# ============================================================
# TRAINING COMPLETE - Assess the results
# ============================================================
mistborn_training.0020 = {
	type = character_event
	title = mistborn_training.0020.t
	desc = mistborn_training.0020.desc
	theme = education

	left_portrait = {
		character = root
		animation = happiness
	}

	right_portrait = {
		character = scope:training_pupil
		animation = personality_bold
	}

	trigger = {
		exists = scope:training_pupil
		scope:training_pupil = {
			is_alive = yes
			has_character_flag = undergoing_allomantic_training
		}
	}

	immediate = {
		scope:training_pupil = {
			# Remove training flag
			remove_character_flag = undergoing_allomantic_training
			remove_character_flag = training_focus_combat
			remove_character_flag = training_focus_subtlety
			remove_character_flag = training_focus_endurance
		}
	}

	# Option A: Training succeeds — the pupil grows stronger
	option = {
		name = mistborn_training.0020.a
		trigger = {
			scope:training_pupil = {
				is_allomancer_trigger = yes
				NOT = { has_trait = trait_allomantic_strong }
				NOT = { has_trait = trait_allomantic_savant }
			}
		}
		scope:training_pupil = {
			# Success chance based on mentor quality and challenge performance
			random_list = {
				55 = {
					modifier = {
						add = 20
						has_character_flag = training_challenge_passed
					}
					modifier = {
						add = 10
						exists = scope:training_mentor
						scope:training_mentor = { has_trait = trait_allomantic_strong }
					}
					modifier = {
						add = 15
						exists = scope:training_mentor
						scope:training_mentor = { has_trait = trait_mistborn }
					}
					# Success — grant strong Allomancy
					if = {
						limit = { has_trait = trait_allomantic_weak }
						remove_trait = trait_allomantic_weak
					}
					add_trait = trait_allomantic_strong
					custom_tooltip = mistborn_training.0020.a.strong
				}
				45 = {
					modifier = {
						add = -20
						has_character_flag = training_challenge_passed
					}
					# Partial success — improvement but not strong
					add_prestige = 50
					custom_tooltip = mistborn_training.0020.a.improved
				}
			}
			remove_character_flag = training_challenge_passed
		}
		add_prestige = 100
		ai_chance = {
			base = 100
		}
	}

	# Option B: Training fails — the pupil did not improve
	option = {
		name = mistborn_training.0020.b
		trigger = {
			scope:training_pupil = {
				OR = {
					NOT = { is_allomancer_trigger = yes }
					has_trait = trait_allomantic_strong
					has_trait = trait_allomantic_savant
				}
			}
		}
		scope:training_pupil = {
			add_stress = 15
			remove_character_flag = training_challenge_passed
		}
		add_stress = 10
		ai_chance = {
			base = 100
		}
	}
}

# ============================================================
# TRAINING INTERRUPTED - Something disrupts the training
# ============================================================
mistborn_training.0030 = {
	type = character_event
	title = mistborn_training.0030.t
	desc = mistborn_training.0030.desc
	theme = secret

	left_portrait = {
		character = root
		animation = worry
	}

	right_portrait = {
		character = scope:training_pupil
		animation = fear
	}

	trigger = {
		exists = scope:training_pupil
	}

	immediate = {
		scope:training_pupil = {
			# Training ends prematurely
			remove_character_flag = undergoing_allomantic_training
			remove_character_flag = training_focus_combat
			remove_character_flag = training_focus_subtlety
			remove_character_flag = training_focus_endurance
			remove_character_flag = training_challenge_passed
		}
	}

	# The training is over
	option = {
		name = mistborn_training.0030.a
		add_stress = 20
		scope:training_pupil = {
			add_stress = 30
		}
		ai_chance = {
			base = 100
		}
	}
}
