﻿namespace = 0s_kings_men_crisis

0s_kings_men_crisis.0001 = {
	type = character_event
	title = 0s_kings_men_crisis.0001.t
	desc = 0s_kings_men_crisis.0001.desc
	theme = murder_scheme
	override_background = { reference = throne_room }

	left_portrait = {
		character = root
		animation = fear
	}

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

	trigger = {
		has_title = title:k_england
		NOT = { has_character_flag = flag_kings_men_crisis_triggered }
	}

	immediate = {
		create_story = 0s_kings_men_story
		
		# The new, weighted logic replacing the temporary lists
		random_close_or_extended_family_member = {
			limit = {
				is_alive = yes
				is_adult = yes
				has_claim_on = title:k_england
				opinion = { target = root value < 40 }
			}
			weight = {
				base = 1
				modifier = {
					add = 100 # Massive priority for your specific House
					house = root.house
				}
				modifier = {
					add = 30 # Secondary priority for your wider Dynasty
					dynasty = root.dynasty
					NOT = { house = root.house }
				}
			}
			save_scope_as = traitorous_kin
		}

		play_music_cue = "mx_cue_stress"
		set_character_flag = flag_kings_men_crisis_triggered
	}

	option = {
		name = 0s_kings_men_crisis.0001.a
		add_stress = 100
		add_character_flag = flag_dynastic_strife_active
		scope:traitorous_kin = {
			add_opinion = {
				target = root
				modifier = rival_opinion
				opinion = -30
			}
		}
	}
}

0s_kings_men_crisis.0002 = {
	type = character_event
	title = 0s_kings_men_crisis.0002.t
	desc = 0s_kings_men_crisis.0002.desc
	theme = murder_scheme
	override_background = { reference = throne_room }

	left_portrait = {
		character = root
		animation = personality_bold
	}

immediate = {
	every_owned_story = {
		type = 0s_kings_men_story
		end_story = yes
	}
	remove_character_flag = flag_dynastic_strife_active
	add_character_modifier = {
		modifier = kings_men_vigilance_modifier
		years = 10
	}
}

	option = {
		name = 0s_kings_men_crisis.0002.a 

		add_prestige = major_prestige_gain

		dynasty = {
			add_dynasty_modifier = {
				modifier = kings_men_dynastic_distrust
				years = 5
			}
		}
		custom_tooltip = 0s_kings_men_crisis_peace_tooltip
	}
}

0s_kings_men_crisis.0003 = {
	type = character_event
	title = 0s_kings_men_crisis.0003.t
	desc = 0s_kings_men_crisis.0003.desc
	theme = realm
	override_background = { reference = throne_room }

	left_portrait = {
		character = root
		animation = fear
	}
	
	right_portrait = {
		trigger = { exists = scope:opportunist }
		character = scope:opportunist
		animation = scheme
	}

	immediate = {
		# 1. Apply the 5-year Legitimacy drain modifier
		add_character_modifier = {
			modifier = kings_men_succession_legitimacy_penalty # You will need to define this in common/modifiers
			years = 5
		}
		
		# 2. Add Discontent to any existing factions
		every_targeting_faction = {
			add_faction_discontent = 25
		}

		# 3. Create a Claimant Faction
		# Find someone who wants the throne
		title:k_england = {
			random_claimant = {
				limit = { 
					is_alive = yes
					NOT = { this = root }
				}
				save_scope_as = faction_claimant
			}
		}
		# Find a vassal to lead the faction
		random_vassal = {
			limit = {
				is_adult = yes
				is_imprisoned = no
				NOT = { is_allied_to = root }
			}
			save_scope_as = opportunist
		}
		
		# If both exist, instantly form the faction
		if = {
			limit = { 
				exists = scope:faction_claimant 
				exists = scope:opportunist 
			}
			scope:opportunist = {
				create_faction = {
					type = claimant_faction
					target = root
					claimant = scope:faction_claimant
				}
			}
		}
		
		play_music_cue = "mx_cue_stress"
	}

	option = { # "Uneasy lies the head..."
		name = 0s_kings_men_crisis.0003.a
		add_stress = minor_stress_gain
	}
}

0s_kings_men_crisis.1001 = {
	type = character_event
	title = 0s_kings_men_crisis.1001.t
	desc = 0s_kings_men_crisis.1001.desc
	theme = intrigue
	
	left_portrait = { character = root }

	option = {
		name = 0s_kings_men_crisis.1001.a
		add_character_modifier = {
			modifier = kings_men_paranoia_modifier
			years = 3
		}
		add_stress = minor_stress_value
	}

}

0s_kings_men_crisis.1002 = {
	type = character_event
	title = 0s_kings_men_crisis.1002.t
	desc = 0s_kings_men_crisis.1002.desc
	theme = mental_break

	left_portrait = { character = root }

	option = { # "Burn the papers!"
		name = 0s_kings_men_crisis.1002.a
		every_close_family_member = {
			limit = { opinion = { target = root value < 0 } }
			add_opinion = {
				target = root
				modifier = rival_opinion
				opinion = -10
			}
		}
	}
}

0s_kings_men_crisis.1003 = {
	type = character_event
	title = 0s_kings_men_crisis.1003.t
	desc = 0s_kings_men_crisis.1003.desc
	theme = family
	
	left_portrait = { character = root }

	right_portrait = {
		character = scope:traitorous_kin
	}

	immediate = {
		random_vassal = {
			limit = { is_family_member = yes }
			save_scope_as = traitorous_kin
		}
	}

	option = { # "They are circling like vultures."
		name = 0s_kings_men_crisis.1003.a
		# Global dynasty hit
		dynasty = {
			add_dynasty_modifier = {
				modifier = kings_men_dynastic_distrust
				years = 5
			}
		}
	}
}

0s_kings_men_crisis.1004 = {
	type = character_event
	title = 0s_kings_men_crisis.1004.t
	desc = 0s_kings_men_crisis.1004.desc
	theme = vassal
	override_background = { reference = feast }

	left_portrait = { character = root }
	right_portrait = { character = scope:random_guest }
	
	immediate = {
		random_vassal = {
			save_scope_as = random_guest
		}
	}

	option = {
		name = 0s_kings_men_crisis.1004.a
		add_character_modifier = {
			modifier = kings_men_vassal_distrust_modifier
			years = 5
		}
		add_prestige = minor_prestige_gain
	}
}

0s_kings_men_crisis.1005 = {
	type = character_event
	title = 0s_kings_men_crisis.1005.t
	desc = 0s_kings_men_crisis.1005.desc
	theme = intrigue

	left_portrait = { character = root }

	right_portrait = { 
		character = cp:councillor_spymaster 
		animation = intrigue
	}

	option = { # "Pay for the silence."
		name = 0s_kings_men_crisis.1005.a
		add_gold = -50
		add_character_modifier = {
			modifier = kings_men_spy_network_modifier
			years = 3
		}
	}
}

0s_kings_men_crisis.1006 = {
	type = character_event
	title = 0s_kings_men_crisis.1006.t
	desc = 0s_kings_men_crisis.1006.desc
	theme = realm
	override_background = { reference = council_chamber }

	trigger = {
		any_targeting_faction = {
			faction_discontent < 100
		}
	}

	immediate = {
		random_targeting_faction = {
			limit = { faction_discontent < 100 }
			save_scope_as = angry_faction
			faction_leader = { save_scope_as = faction_head }
		}
	}

	left_portrait = { character = root }
	right_portrait = { 
		character = scope:faction_head 
		animation = anger 
	}

	option = { # "Send gold to quiet their tongues."
		name = 0s_kings_men_crisis.1006.a
		pay_short_term_gold = {
			target = scope:faction_head
			gold = medium_gold_value
		}
		scope:angry_faction = {
			add_faction_discontent = -20
		}
		add_stress = minor_stress_gain
	}

	option = {
		name = 0s_kings_men_crisis.1006.b
		scope:angry_faction = {
			add_faction_discontent = 30
		}
		add_prestige = minor_prestige_gain
	}

	option = {
		name = 0s_kings_men_crisis.1006.c
		trigger = {
			dread >= 50
		}
		scope:faction_head = {
			add_opinion = {
				target = root
				modifier = fearful_opinion
				opinion = 20
			}
		}
		scope:angry_faction = {
			add_faction_discontent = -40
		}
		add_dread = minor_dread_gain
	}
}