﻿namespace = succession_crisis_debug

# Trigger this to start moving
succession_crisis_debug.0001 = {
	type = character_event
	title = succession_crisis_debug.0001.t
	desc = succession_crisis_debug.0001.desc
    theme = intrigue
	
	immediate = {
		# Scope to any random ruler that isn't the player
		random_ruler = {
			limit = {
				NOT = { this = root }
				is_landed = yes
			}
			capital_province = {
				save_scope_as = debug_destination_province
			}
		}
		
		start_travel_plan = {
			destination = scope:debug_destination_province
			players_use_planner = no
			return_trip = yes
			on_travel_planner_cancel_event = succession_crisis_travel.0002
			on_arrival_event = succession_crisis_arrival.0001
			on_arrival_destinations = all_but_last
		}

		# Trigger the test menu in 3 days
		trigger_event = {
			id = succession_crisis_debug.0002
			days = 3
		}
	}

	option = {
		name = succession_crisis_debug.0001.a
	}
}

# The Choice Menu
succession_crisis_debug.0002 = {
	type = character_event
	title = succession_crisis_debug.0002.t
	desc = succession_crisis_debug.0002.desc
	theme = intrigue

	left_portrait = root

	option = {
		name = succession_crisis_debug.0002.opt2
		trigger_event = succession_crisis_travel.0002
	}

}

succession_crisis_debug.0003 = {
	type = character_event
	title = succession_crisis_debug_3.t
	desc = succession_crisis_debug_3.desc
	theme = mental_break
	
	left_portrait = {
		character = root
		animation = disbelief
	}

	option = {
		name = succession_crisis_debug_3.a
	}
}

succession_crisis_debug.0004 = {
	type = character_event
	title = succession_crisis_debug.0004.t
	desc = succession_crisis_debug.0004.desc
	theme = mental_break
	left_portrait = scope:crisis_heir

	immediate = {
		root = { save_scope_as = crisis_heir }
		primary_title = { save_scope_as = crisis_title }
		calculate_succession_instability_points = yes
	}

	option = {
		name = succession_crisis_debug.0004.a
	}
}

succession_crisis_debug.0005 = {
	type = character_event
	title = succession_crisis_debug.0005.t
	desc = succession_crisis_debug.0005.desc
	theme = mental_break
	left_portrait = scope:crisis_heir

	immediate = {
		primary_heir = { save_scope_as = crisis_heir }
		primary_title = { save_scope_as = crisis_title }
		primary_heir = {
			calculate_succession_instability_points = yes
		}
	}

	option = {
		name = succession_crisis_debug.0005.a
	}
}

# ============================================================
# DEBUG EVENT 0006: FORCE SUCCESSION CRISIS SETUP
# ============================================================
succession_crisis_debug.0006 = {
	type = character_event
	theme = realm
	title = succession_crisis_debug.0006.t
	desc = succession_crisis_debug.0006.desc
	
	immediate = {
		# Save ROOT as the current ruler
		save_scope_as = current_ruler
		save_scope_as = crisis_heir

		# Save the primary title of the ruler as the crisis title
		root.primary_title = {
			save_scope_as = crisis_title
		}

		# Find a random independent ruler who specifically has a claim on the crisis title
		random_ruler = {
			limit = {
				is_alive = yes
				is_landed = yes
				is_independent_ruler = yes
				NOT = { this = root }
				is_eligible_for_succession_crisis = yes
				NOT = { this = root.liege }
				NOT = { top_liege = root.top_liege }
				NOT = { is_at_war_with = root }
				has_claim_on = scope:crisis_title
			}
			save_scope_as = warleader
		}

		# Fallback: If no claimant found, find a high-tier independent ruler and give them the claim
		if = {
			limit = {
				NOT = { exists = scope:warleader }
			}
			random_ruler = {
				limit = {
					is_alive = yes
					is_landed = yes
					is_independent_ruler = yes
					highest_held_title_tier >= tier_kingdom
					is_eligible_for_succession_crisis = yes
					NOT = { this = root }
					NOT = { this = root.liege }
					NOT = { top_liege = root.top_liege }
					NOT = { is_at_war_with = root }
				}
				save_scope_as = warleader
				add_pressed_claim = scope:crisis_title
			}
		}

		# Process loyalty logic based on the scopes defined above
		succession_crisis_process_vassal_loyalty_effect = yes

		# Schedule the war declaration
		trigger_event = {
			id = succession_crisis_debug.0007
			days = 30
		}
	}

	option = {
		name = succession_crisis_debug.0006.a
	}
}

# ============================================================
# DEBUG EVENT 0007: FORCE WAR DECLARATION
# ============================================================
succession_crisis_debug.0007 = {
	type = character_event
	theme = realm
	title = succession_crisis_debug.0007.t
	desc = succession_crisis_debug.0007.desc

	immediate = {
		# Trigger the start war effect which relies on the saved scopes
		succession_crisis_start_war_effect = yes
	}

	option = {
		name = succession_crisis_debug.0007.a
	}
}

# ============================================================
# DEBUG EVENT 0008: FORCE SUCCESSION CRISIS SETUP
# ============================================================
succession_crisis_debug.0008 = {
	type = character_event
	theme = realm
	title = succession_crisis_debug.0008.t
	desc = succession_crisis_debug.0008.desc
	
	immediate = {
		# Save ROOT as the current ruler
		save_scope_as = current_ruler
		save_scope_as = crisis_heir

		# Save the primary title of the ruler as the crisis title
		root.primary_title = {
			save_scope_as = crisis_title
		}

		# Find a random independent ruler who specifically has a claim on the crisis title
		random_ruler = {
			limit = {
				is_alive = yes
				is_landless_adventurer = yes
				is_eligible_for_succession_crisis = yes
				is_independent_ruler = yes
				NOT = { this = root }
				NOT = { is_at_war_with = root }
				has_claim_on = scope:crisis_title
			}
			save_scope_as = warleader
		}

		# Fallback: If no claimant found, find a high-tier independent ruler and give them the claim
		if = {
			limit = {
				NOT = { exists = scope:warleader }
			}
			random_ruler = {
				limit = {
					is_alive = yes
					is_landless_adventurer = yes
					is_eligible_for_succession_crisis = yes
					is_independent_ruler = yes
					NOT = { this = root }
					NOT = { is_at_war_with = root }
				}
				save_scope_as = warleader
				add_pressed_claim = scope:crisis_title
			}
		}

		# Process loyalty logic based on the scopes defined above
		succession_crisis_process_vassal_loyalty_effect = yes

		# Schedule the war declaration
		trigger_event = {
			id = succession_crisis_debug.0007
			days = 30
		}
	}

	option = {
		name = succession_crisis_debug.0008.a
	}
}

# ============================================================
# DEBUG EVENT 0009: FORCE SUCCESSION CRISIS SETUP (FELLOW VASSAL)
# ============================================================
succession_crisis_debug.0009 = {
	type = character_event
	theme = realm
	title = succession_crisis_debug.0009.t
	desc = succession_crisis_debug.0009.desc
	
	immediate = {
		# Save ROOT as the current ruler (the one being challenged)
		save_scope_as = current_ruler
		save_scope_as = crisis_heir

		# Save the primary title of the ruler as the crisis title
		root.primary_title = {
			save_scope_as = crisis_title
		}

		# Scope to liege to find fellow vassals
		root.liege = {
			# Find a fellow vassal in the same realm who has a claim
			random_vassal = {
				limit = {
					is_alive = yes
					is_independent_ruler = no
					is_eligible_for_succession_crisis = yes
					NOT = { this = root }
					NOT = { is_at_war_with = root }
					has_claim_on = scope:crisis_title
				}
				save_scope_as = warleader
			}
		}

		# Fallback: Find any fellow vassal and give them the claim
		if = {
			limit = {
				NOT = { exists = scope:warleader }
			}
			root.liege = {
				random_vassal = {
					limit = {
						is_alive = yes
						is_independent_ruler = no
						is_eligible_for_succession_crisis = yes
						NOT = { this = root }
						NOT = { is_at_war_with = root }
					}
					save_scope_as = warleader
					add_pressed_claim = scope:crisis_title
				}
			}
		}

		# Process loyalty logic based on the scopes defined above
		succession_crisis_process_vassal_loyalty_effect = yes

		# Schedule the war declaration
		trigger_event = {
			id = succession_crisis_debug.0007
			days = 30
		}
	}

	option = {
		name = succession_crisis_debug.0009.a
	}
}
# ============================================================
# DEBUG EVENT 0010: Diplomacy 
# ============================================================
succession_crisis_debug.0010 = {
	type = character_event
	theme = realm
	title = succession_crisis_debug.0010.t
	desc = succession_crisis_debug.0010.desc

	immediate = {
		save_scope_as = current_ruler
		save_scope_as = crisis_heir
		root.primary_title = {
			save_scope_as = crisis_title
		}
		root.capital_province = {
			save_scope_as = crisis_destination
		}

		random_ruler = {
			limit = {
				is_alive = yes
				NOT = { this = root }
			}
			save_scope_as = claimant
			save_scope_as = warleader
			add_pressed_claim = scope:crisis_title
		}

		scope:claimant = {
			trigger_event = {
				id = succession_crisis_diplomacy_event.0001
				days = 1
			}
		}
	}

	left_portrait = scope:claimant

	option = {
		name = succession_crisis_debug.0010.a
	}
}
# ============================================================
# DEBUG EVENT 0011: VISIT VASSAL 
# ============================================================
succession_crisis_debug.0011 = {
	type = character_event
	title = succession_crisis_debug.0011.t
	desc = succession_crisis_debug.0011.desc
	theme = diplomacy

	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		character = scope:selected_consolidation_vassal
		animation = dancing
	}

	immediate = {
		liege = {
			save_scope_as = current_ruler
			primary_title = {
				save_scope_as = crisis_title
			}
		}

		scope:current_ruler = {
			random_vassal = {
				limit = {
					NOT = { this = root }
				}
				save_scope_as = selected_consolidation_vassal
				location = {
					save_scope_as = target_destination
				}
			}
		}
	}

	option = {
		name = succession_crisis_debug.0011.a
		
		scope:crisis_title = {
			root = {
				add_pressed_claim = prev
			}
		}

		add_character_flag = crisis_special_character
		add_character_flag = visiting_vassal

		trigger_event = {
			id = succession_crisis_travel.0003
		}
	}
}

succession_crisis_debug.0012 = {
	type = character_event
	title = succession_crisis_debug.0012.t
	desc = succession_crisis_debug.0012.desc
	
	theme = physical_health
	left_portrait = root

	option = {
		name = succession_crisis_debug.0012.a
		if = {
			limit = {
				is_independent_ruler = no
			}
			create_title_and_vassal_change = {
				type = created
				save_scope_as = independence_change
				add_claim_on_loss = no
			}
			becomes_independent = {
				change = scope:independence_change
			}
			resolve_title_and_vassal_change = scope:independence_change
		}
		sc_create_custom_kingdom_effect = yes
	}
}


# ============================================================
# EVENT 0013: HEIR ASSIGNMENT DEBUG
# ============================================================

succession_crisis_debug.0013 = {
	type = character_event
	title = succession_crisis_debug.0013.t
	desc = succession_crisis_debug.0013.desc
	theme = diplomacy

	immediate = {
		random_child = {
			save_scope_as = random_ruler_target
		}
		# Using a fallback in case there are multiple children to distinguish scopes
		random_child = {
			limit = { NOT = { this = scope:random_ruler_target } }
			save_scope_as = random_heir_target
		}
	}

	left_portrait = {
		character = root
		animation = thinking
	}

	right_portrait = {
		character = scope:random_ruler_target
		animation = personality_rational
	}

	lower_left_portrait = {
		character = scope:random_heir_target
		animation = obsequious_bow
	}

	option = {
		name = succession_crisis_debug.0013.a
		
		root = {
			set_designated_heir = scope:random_ruler_target
		}
	}

	option = {
		name = succession_crisis_debug.0013.b
		
		root = {
			set_designated_heir = scope:random_heir_target
		}
	}
}
# ============================================================
# EVENT 0014: RANDOM MARRIAGE
# ============================================================
succession_crisis_debug.0014 = {
	type = character_event
	title = succession_crisis_debug.0014.t
	desc = succession_crisis_debug.0014.desc
	theme = diplomacy

	immediate = {
		random_ruler = {
			limit = {
				is_married = no
				OR = {
					AND = {
						root = { is_male = yes }
						is_male = no
					}
					AND = {
						root = { is_male = no }
						is_male = yes
					}
				}
			}
			save_scope_as = debug_marriage_target
		}
	}

	left_portrait = {
		character = root
	}

	right_portrait = {
		character = scope:debug_marriage_target
	}

	option = {
		name = succession_crisis_debug.0014.a
		trigger = {
			exists = scope:debug_marriage_target
		}
		marry = scope:debug_marriage_target
	}
}
# ============================================================
# EVENT 0015: DPLOMATIC MARRIAGE
# ============================================================
succession_crisis_debug.0015 = {
	type = character_event
	hidden = yes

	immediate = {
		root = {
			save_scope_as = current_ruler
		}
		random_ruler = {
			limit = {
				can_marry_trigger = yes
				any_child = {
					can_marry_trigger = yes
				}
				OR = {
					AND = {
						root = { is_male = yes }
						is_male = no
					}
					AND = {
						root = { is_male = no }
						is_male = yes
					}
				}
			}
			save_scope_as = claimant
			save_scope_as = warleader
		}
		
		if = {
			limit = {
				exists = scope:claimant
			}
			scope:claimant = {
				trigger_event = {
					id = succession_crisis_diplomacy_event.0006
				}
			}
		}
	}
}
# ============================================================
# EVENT 0016: USURPING
# ============================================================
succession_crisis_debug.0016 = {
	type = character_event
	hidden = yes

	immediate = {
		save_scope_as = current_ruler
		primary_title = {
			save_scope_as = crisis_title
		}
		location = {
			save_scope_as = crisis_destination
		}
		random_ruler = {
			limit = {
				is_alive = yes
				NOT = { this = root }
			}
			save_scope_as = claimant
			set_location = scope:crisis_destination
			add_pressed_claim = scope:crisis_title
			trigger_event = succession_crisis_claimant_event.0002
		}
	}
}

succession_crisis_debug.0017 = {
	type = character_event
	hidden = yes
	immediate = {
		top_liege = {
			save_scope_as = crisis_heir
			primary_title = {
				save_scope_as = crisis_title
			}
			location = {
				save_scope_as = crisis_destination
			}
			
			# If the liege is at the intended destination, move them to a vassal's capital
			if = {
				limit = {
					location = scope:crisis_destination
				}
				random_vassal = {
					capital_province = {
						save_scope_as = liege_away_loc
					}
				}
				set_location = scope:liege_away_loc
			}
		}
		
		add_pressed_claim = scope:crisis_title
		
		# Set root to the original destination
		set_location = scope:crisis_destination
		
		trigger_event = {
			id = succession_crisis_claimant_event.0002
		}
	}
}

succession_crisis_debug.0018 = {
	type = character_event
	title = succession_crisis_debug.0018.t
	desc = succession_crisis_debug.0018.desc
	theme = diplomacy

	immediate = {
		save_scope_as = claimant
		top_liege = {
			save_scope_as = current_ruler
			primary_title = {
				save_scope_as = crisis_title
			}
		}
	}

	option = {
		name = succession_crisis_debug.0018.a
		succession_crisis_diplomatic_transfer_effect = yes
	}
}

succession_crisis_debug.0019 = {
	type = character_event
	title = succession_crisis_debug.0019.t
	theme = realm
	desc = succession_crisis_debug.0019.desc

	immediate = {
		save_scope_as = claimant
		top_liege = {
			save_scope_as = current_ruler
			primary_title = {
				save_scope_as = crisis_title
			}
		}
	}

	option = {
		name = succession_crisis_debug.0019.a
		trigger_event = { id = succession_crisis_diplomacy_event.0004 }
	}
}

succession_crisis_debug.0020 = {
	type = character_event
	title = succession_crisis_debug.0020.t
	desc = succession_crisis_debug.0020.desc
	theme = realm

	immediate = {
		save_scope_as = claimant
		top_liege = {
			save_scope_as = current_ruler
			primary_title = {
				save_scope_as = crisis_title
			}
		}
	}

	option = {
		name = succession_crisis_debug.0020.a
		trigger_event = {
			id = succession_crisis_diplomacy_event.0004
			days = 7
		}
		scope:current_ruler = {
			trigger_event = {
				id = succession_crisis_diplomacy_ruler.0004
				days = 7
			}
		}
	}
}

succession_crisis_debug.0021 = {
	type = character_event
	theme = realm
	title = succession_crisis_debug.0021.t
	desc = succession_crisis_debug.0021.desc

	immediate = {
		save_scope_as = claimant
		save_scope_as = warleader
		add_character_flag = debugging

		top_liege = {
			save_scope_as = current_ruler
			save_scope_as = crisis_heir
			primary_title = {
				save_scope_as = crisis_title
			}
			capital_province = {
				save_scope_as = crisis_destination
			}
		}

		add_pressed_claim = scope:crisis_title

		trigger_event = {
			id = succession_crisis_diplomacy_event.0001
			days = 1
		}
	}

	left_portrait = scope:current_ruler

	option = {
		name = succession_crisis_debug.0021.a
	}
}

# ============================================================
# DEBUG EVENT 0022: FORCE SUCCESSION CRISIS SETUP (DIRECT VASSAL)
# ============================================================
succession_crisis_debug.0022 = {
	type = character_event
	theme = realm
	title = succession_crisis_debug.0022.t
	desc = succession_crisis_debug.0022.desc
	
	immediate = {
		# Save ROOT as the current ruler (the one being challenged)
		save_scope_as = current_ruler
		save_scope_as = crisis_heir

		# Save the primary title of the ruler as the crisis title
		root.primary_title = {
			save_scope_as = crisis_title
		}

		# Find a direct vassal who has a claim
		random_vassal = {
			limit = {
				is_alive = yes
				is_independent_ruler = no
				is_eligible_for_succession_crisis = yes
				NOT = { is_at_war_with = root }
				has_claim_on = scope:crisis_title
			}
			save_scope_as = warleader
		}

		# Fallback: Find any direct vassal and give them the claim
		if = {
			limit = {
				NOT = { exists = scope:warleader }
			}
			random_vassal = {
				limit = {
					is_alive = yes
					is_independent_ruler = no
					is_eligible_for_succession_crisis = yes
					NOT = { is_at_war_with = root }
				}
				save_scope_as = warleader
				add_pressed_claim = scope:crisis_title
			}
		}

		# Process loyalty logic based on the scopes defined above
		succession_crisis_process_vassal_loyalty_effect = yes

		# Schedule the war declaration
		trigger_event = {
			id = succession_crisis_debug.0007
			days = 30
		}
	}

	option = {
		name = succession_crisis_debug.0022.a
	}
}

succession_crisis_debug.0023 = {
	type = character_event
	theme = realm
	title = succession_crisis_debug.0023.t
	desc = succession_crisis_debug.0023.desc

	immediate = {
		root = {
			primary_title = { save_scope_as = crisis_title }
			save_scope_as = current_ruler
			save_scope_as = crisis_heir
			add_character_flag = crisis_heir_flag
			location = { save_scope_as = crisis_destination }
			
			# Find claimant
			scope:crisis_title = {
				random_claimant = {
					limit = {
						is_eligible_for_succession_crisis = yes
						is_ruler = yes
						age >= 16
					}
					save_scope_as = claimant
					save_scope_as = warleader
					add_character_flag = active_crisis_rebel
					add_character_flag = in_debate
					
					if = {
						limit = { NOT = { has_claim_on = scope:crisis_title } }
						add_pressed_claim = scope:crisis_title
					}
				}
			}
			
			# Randomly assign allegiance to vassals
			every_vassal = {
				limit = {
					NOT = { this = scope:claimant }
					NOT = { this = scope:crisis_heir }
					NOT = { this = root }
				}
				random_list = {
					50 = { add_character_flag = pledged_to_claimant }
					50 = { add_character_flag = pledged_to_heir }
				}
			}
			
			start_grand_council_councillor_effect = yes

			if = {
				limit = {
					exists = scope:target_vassal
					exists = scope:claimant
				}
				scope:target_vassal = {
					set_variable = {
						name = grand_council_special_guest
						value = scope:claimant
					}
				}
			}
		}

		# Setup locations
		if = {
			limit = { exists = scope:claimant scope:claimant = { NOT = { location = scope:crisis_destination } } }
			scope:claimant = { set_location = scope:crisis_destination }
		}
		if = {
			limit = { exists = scope:target_vassal scope:target_vassal = { NOT = { location = scope:crisis_destination } } }
			scope:target_vassal = { set_location = scope:crisis_destination }
		}
	}

	left_portrait = scope:target_vassal
	right_portrait = scope:claimant

	option = {
		name = succession_crisis_debug.0023.a
		trigger = {
			exists = scope:target_vassal
		}
	}

	option = {
		name = succession_crisis_debug.0023.b
	}
}

succession_crisis_debug.0024 = {
	type = character_event
	hidden = yes

	immediate = {
		add_gold = 10000
		ai_attempt_to_host_activity = activity_grand_council
		debug_log = "AI attempted to host a Supreme Council"
		debug_log_scopes = yes		
	}
}

succession_crisis_debug.0025 = {
	type = character_event
	hidden = yes

	immediate = {
		save_scope_as = test_target_root
		
		primary_title = {
			save_scope_as = crisis_title
			set_variable = {
				name = primary_claimant
				value = root
			}
		}

		add_character_flag = grand_council_host
		
		primary_heir = {
			save_scope_as = test_target_switch
		}
		
		set_player_character = scope:test_target_switch
		
		scope:test_target_root = {
			ai_attempt_to_host_activity = activity_grand_council
		}
		
		trigger_event = {
			id = succession_crisis_debug.0026
		}
	}
}

succession_crisis_debug.0026 = {
	type = character_event
	hidden = yes

	immediate = {
		set_player_character = scope:test_target_root
	}
}

succession_crisis_debug.0027 = {
	type = character_event
	theme = realm
	title = succession_crisis_debug.0023.t
	desc = succession_crisis_debug.0023.desc

	immediate = {
		root = {
			primary_title = {
				save_scope_as = crisis_title
			}
			
			save_scope_as = current_ruler
			save_scope_as = crisis_heir
			
			location = {
				save_scope_as = crisis_destination
			}
			
			# Scope to the primary title to find an eligible claimant
			scope:crisis_title = {
				random_claimant = {
					limit = {
						is_eligible_for_succession_crisis = yes
						is_ruler = yes
						age >= 16
					}
					save_scope_as = claimant
					save_scope_as = warleader
					add_character_flag = active_crisis_rebel
					add_character_flag = debating
					
					# Ensure they have the claim
					if = {
						limit = { NOT = { has_claim_on = scope:crisis_title } }
						add_pressed_claim = scope:crisis_title
					}
				}
			}
			
			# Councillor logic
			if = {
				limit = {
					any_councillor = {
						has_council_position = councillor_chancellor
					}
				}
				random_councillor = {
					limit = {
						has_council_position = councillor_chancellor
					}
					save_scope_as = target_vassal
					add_character_flag = council_host_flag
				}
			}
			else = {
				every_councillor = {
					if = {
						limit = {
							NOR = {
								has_council_position = councillor_court_chaplain
							}
							NOT = { exists = scope:target_vassal }
							location = scope:current_ruler.location
						}
						save_scope_as = target_vassal
						add_character_flag = council_host_flag
					}
				}
			}

			if = {
				limit = {
					exists = scope:target_vassal
					exists = scope:claimant
				}
				scope:target_vassal = {
					set_variable = {
						name = primary_claimant
						value = scope:claimant
					}
					set_variable = {
						name = claimant
						value = scope:claimant
					}
				}
			}
		}

		if = {
			limit = {
				exists = scope:claimant
				scope:claimant = {
					NOT = { location = scope:crisis_destination }
				}
			}
			scope:claimant = {
				set_location = scope:crisis_destination
			}
		}

		if = {
			limit = {
				exists = scope:target_vassal
				scope:target_vassal = {
					NOT = { location = scope:crisis_destination }
				}
			}
			scope:target_vassal = {
				set_location = scope:crisis_destination
			}
		}
	}

	left_portrait = scope:target_vassal
	right_portrait = scope:claimant

	option = {
		name = succession_crisis_debug.0023.a
		trigger = {
			exists = scope:target_vassal
		}
		scope:target_vassal = {
			trigger_event = {
				id = succession_crisis_debug.0024
				days = 1
			}
		}
	}

	option = {
		name = succession_crisis_debug.0023.b
	}
}

# ============================================================
# DEBUG EVENT: CHECK CHILDREN MARRIAGE ELIGIBILITY
# ============================================================
succession_crisis_debug.0028 = {
	type = character_event
	title = succession_crisis_debug.0028.t
	desc = succession_crisis_debug.0028.desc
	
	immediate = {
		random_child = {
			limit = {
				sc_diplomatic_marriage_check = yes
			}
			save_scope_as = child_1
		}
		random_child = {
			limit = {
				sc_diplomatic_marriage_check = yes
				NOT = { this = scope:child_1 }
			}
			save_scope_as = child_2
		}
		random_child = {
			limit = {
				sc_diplomatic_marriage_check = yes
				NOT = { this = scope:child_1 }
				NOT = { this = scope:child_2 }
			}
			save_scope_as = child_3
		}
	}

	left_portrait = scope:child_1
	center_portrait = scope:child_2
	right_portrait = scope:child_3

	option = {
		name = succession_crisis_debug.0028.a
	}
}

succession_crisis_debug.0029 = {
	type = character_event
	title = succession_crisis_debug.0029.t
	desc = succession_crisis_debug.0029.desc

	immediate = {
		save_scope_as = claimant_to_marry
		random_child = {
			limit = {
				sc_diplomatic_marriage_check = yes
			}
			save_scope_as = claimant_child_to_marry
		}
		involved_activity = {
			scope:host = {
				save_scope_as = ruler_to_marry
				random_child = {
					limit = {
						sc_diplomatic_marriage_check = yes
					}
					save_scope_as = ruler_child_to_marry
				}
			}
		}
	}

	left_portrait = scope:claimant_to_marry
	right_portrait = scope:ruler_to_marry
	lower_left_portrait = scope:claimant_child_to_marry
	lower_right_portrait = scope:ruler_child_to_marry

	option = {
		name = succession_crisis_debug.0029.a
		scope:claimant_to_marry = {
			marry = scope:ruler_to_marry
		}
	}

	option = {
		name = succession_crisis_debug.0029.b
		scope:claimant_to_marry = {
			marry = scope:ruler_child_to_marry
		}
	}

	option = {
		name = succession_crisis_debug.0029.c
		scope:claimant_child_to_marry = {
			marry = scope:ruler_to_marry
		}
	}

	option = {
		name = succession_crisis_debug.0029.d
		scope:claimant_child_to_marry = {
			marry = scope:ruler_child_to_marry
		}
	}
}

succession_crisis_debug.0030 = {
	type = character_event
	theme = realm
	title = succession_crisis_debug.0029.t
	desc = succession_crisis_debug.0029.desc

	immediate = {
		# Save root as the winner
		save_scope_as = winner
		
		# Find a random ruler in diplomatic range with at least kingdom tier as the loser, not being root
		random_ruler = {
			limit = {
				this != root
				in_diplomatic_range = root
				primary_title = { tier >= tier_kingdom }
			}
			save_scope_as = loser
			
			# Save their primary title as crisis_title
			primary_title = {
				save_scope_as = crisis_title
			}
			
			capital_province = {
				save_scope_as = crisis_destination
			}
		}
	}

	left_portrait = scope:winner
	right_portrait = scope:loser

	option = {
		name = succession_crisis_debug.0029.a
		
		hidden_effect = {
			# Trigger the transfer effect as requested
			succession_crisis_diplomatic_transfer_effect = yes
		}
	}
}