############################################
# Ball Event Chain
# Noble social gatherings where politics,
# intrigue, and Allomantic displays intertwine
############################################

namespace = mistborn_ball

# ============================================================
# HOST A BALL - Main Event
# Grand social gathering of the noble houses
# ============================================================
mistborn_ball.0001 = {
	type = character_event
	title = mistborn_ball.0001.t
	desc = mistborn_ball.0001.desc
	theme = feast_activity

	left_portrait = {
		character = root
		animation = personality_bold
	}

	trigger = {
		is_ruler = yes
		highest_held_title_tier >= tier_county
		gold >= 100
		NOT = { has_character_flag = recently_hosted_ball }
	}

	immediate = {
		add_character_flag = {
			flag = recently_hosted_ball
			years = 2
		}
		add_gold = -100
	}

	# The ball begins - select what to focus on
	# Option A: Focus on political maneuvering
	option = {
		name = mistborn_ball.0001.a
		trigger_event = {
			id = mistborn_ball.0010
			days = 1
		}
		ai_chance = {
			base = 40
			modifier = {
				add = 20
				has_trait = gregarious
			}
		}
	}

	# Option B: Focus on intelligence gathering
	option = {
		name = mistborn_ball.0001.b
		trigger_event = {
			id = mistborn_ball.0020
			days = 1
		}
		ai_chance = {
			base = 30
			modifier = {
				add = 20
				has_trait = deceitful
			}
		}
	}

	# Option C: Show off your Allomancers
	option = {
		name = mistborn_ball.0001.c
		trigger = {
			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
				any_courtier = {
					OR = {
						has_trait = trait_mistborn
						has_trait = trait_misting_coinshot
						has_trait = trait_misting_lurcher
						has_trait = trait_misting_thug
					}
				}
			}
		}
		trigger_event = {
			id = mistborn_ball.0030
			days = 1
		}
		ai_chance = {
			base = 30
			modifier = {
				add = 20
				has_trait = ambitious
			}
		}
	}
}

# ============================================================
# BALL - POLITICAL MANEUVERING
# Meet a rival noble and negotiate
# ============================================================
mistborn_ball.0010 = {
	type = character_event
	title = mistborn_ball.0010.t
	desc = mistborn_ball.0010.desc
	theme = diplomacy

	left_portrait = {
		character = root
		animation = personality_rational
	}

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

	immediate = {
		# Find a nearby rival or potential ally
		random_neighboring_top_liege_realm_owner = {
			limit = {
				is_ruler = yes
				NOT = { this = root }
				highest_held_title_tier >= tier_county
			}
			save_scope_as = ball_rival
		}
		if = {
			limit = {
				NOT = { exists = scope:ball_rival }
			}
			random_vassal = {
				limit = {
					is_ruler = yes
					NOT = { this = root }
				}
				save_scope_as = ball_rival
			}
		}
	}

	# Option A: Propose an alliance
	option = {
		name = mistborn_ball.0010.a
		trigger = {
			exists = scope:ball_rival
		}
		add_prestige = 50
		if = {
			limit = {
				exists = scope:ball_rival
			}
			scope:ball_rival = {
				add_opinion = {
					target = root
					modifier = pleased_opinion
					opinion = 20
				}
			}
		}
		ai_chance = {
			base = 40
		}
	}

	# Option B: Propose a marriage arrangement
	option = {
		name = mistborn_ball.0010.b
		trigger = {
			exists = scope:ball_rival
		}
		add_prestige = 30
		add_diplomacy_lifestyle_xp = 50
		if = {
			limit = {
				exists = scope:ball_rival
			}
			scope:ball_rival = {
				add_opinion = {
					target = root
					modifier = pleased_opinion
					opinion = 15
				}
			}
		}
		ai_chance = {
			base = 30
		}
	}

	# Option C: Propose a trade deal
	option = {
		name = mistborn_ball.0010.c
		add_gold = 75
		add_prestige = 20
		ai_chance = {
			base = 30
		}
	}
}

# ============================================================
# BALL - INTRIGUE DISCOVERY
# Your spymaster or Seeker uncovers something
# ============================================================
mistborn_ball.0020 = {
	type = character_event
	title = mistborn_ball.0020.t
	desc = mistborn_ball.0020.desc
	theme = intrigue

	left_portrait = {
		character = root
		animation = scheme
	}

	immediate = {
		# Bonus for having a Seeker
		if = {
			limit = {
				OR = {
					has_trait = trait_misting_seeker
					any_courtier = {
						has_trait = trait_misting_seeker
					}
				}
			}
			save_scope_as = has_seeker
		}
	}

	# Option A: Learn about rival's Allomantic abilities
	option = {
		name = mistborn_ball.0020.a
		add_intrigue_lifestyle_xp = 50
		# Better results with a Seeker
		if = {
			limit = {
				exists = scope:has_seeker
			}
			add_intrigue_lifestyle_xp = 25
			custom_tooltip = mistborn_ball.0020.seeker_bonus
		}
		random_list = {
			60 = {
				modifier = {
					add = 20
					exists = scope:has_seeker
				}
				# Discovery - learn a secret
				custom_tooltip = mistborn_ball.0020.a.success
				add_prestige = 50
			}
			40 = {
				modifier = {
					add = -20
					exists = scope:has_seeker
				}
				# Nothing found
				custom_tooltip = mistborn_ball.0020.a.fail
			}
		}
		ai_chance = {
			base = 40
		}
	}

	# Option B: Discover a political plot
	option = {
		name = mistborn_ball.0020.b
		add_intrigue_lifestyle_xp = 30
		random_list = {
			50 = {
				modifier = {
					add = 15
					has_trait = trait_misting_tineye
				}
				# Overhear a plot
				custom_tooltip = mistborn_ball.0020.b.success
				add_prestige = 75
			}
			50 = {
				modifier = {
					add = -15
					has_trait = trait_misting_tineye
				}
				# Nothing useful
				custom_tooltip = mistborn_ball.0020.b.fail
			}
		}
		ai_chance = {
			base = 30
		}
	}

	# Option C: Discover a hidden religion
	option = {
		name = mistborn_ball.0020.c
		add_intrigue_lifestyle_xp = 40
		random_list = {
			30 = {
				# Discover a secret Survivorist
				custom_tooltip = mistborn_ball.0020.c.success
				add_piety = 50
				add_prestige = 30
			}
			70 = {
				# Nothing found
				custom_tooltip = mistborn_ball.0020.c.fail
			}
		}
		ai_chance = {
			base = 30
		}
	}
}

# ============================================================
# BALL - ALLOMANTIC DISPLAY
# Show off your house's Allomantic power
# ============================================================
mistborn_ball.0030 = {
	type = character_event
	title = mistborn_ball.0030.t
	desc = mistborn_ball.0030.desc
	theme = diplomacy

	left_portrait = {
		character = root
		animation = personality_bold
	}

	immediate = {
		# Check if player has impressive Allomancers
		if = {
			limit = {
				OR = {
					any_child = {
						has_trait = trait_mistborn
					}
					any_courtier = {
						has_trait = trait_mistborn
					}
				}
			}
			save_scope_as = has_mistborn_display
		}
	}

	# Option A: Dramatic Coinshot/Lurcher display
	option = {
		name = mistborn_ball.0030.a
		add_prestige = 100
		dynasty = {
			add_dynasty_prestige = 50
		}
		# Draws attention
		if = {
			limit = {
				has_variable = lord_ruler_attention
			}
			change_variable = {
				name = lord_ruler_attention
				add = 3
			}
		}
		ai_chance = {
			base = 50
		}
	}

	# Option B: Subtle Soother/Rioter manipulation of the crowd
	option = {
		name = mistborn_ball.0030.b
		trigger = {
			OR = {
				has_trait = trait_misting_soother
				has_trait = trait_misting_rioter
				has_trait = trait_mistborn
				any_courtier = {
					OR = {
						has_trait = trait_misting_soother
						has_trait = trait_misting_rioter
					}
				}
			}
		}
		add_prestige = 50
		add_diplomacy_lifestyle_xp = 75
		# Less attention - subtle
		if = {
			limit = {
				has_variable = lord_ruler_attention
			}
			change_variable = {
				name = lord_ruler_attention
				add = 1
			}
		}
		ai_chance = {
			base = 40
		}
	}

	# Option C: Reveal your Mistborn (if you have one) - massive impact
	option = {
		name = mistborn_ball.0030.c
		trigger = {
			exists = scope:has_mistborn_display
		}
		add_prestige = 300
		dynasty = {
			add_dynasty_prestige = 150
		}
		# Major attention draw
		if = {
			limit = {
				has_variable = lord_ruler_attention
			}
			change_variable = {
				name = lord_ruler_attention
				add = 10
			}
		}
		# Marriage proposals may follow
		add_character_flag = {
			flag = mistborn_revealed_at_ball
			years = 5
		}
		ai_chance = {
			base = 20
			modifier = {
				add = 20
				has_trait = ambitious
			}
		}
	}
}
