﻿namespace = succession_crisis_diplomacy_ruler


# ============================================================
# EVENT 0001: DIPLOMACY RULER (RULER PERSPECTIVE)
# ============================================================
succession_crisis_diplomacy_ruler.0001 = {
	type = character_event
	title = succession_crisis_diplomacy_ruler.0001.t
	desc = succession_crisis_diplomacy_ruler.0001.desc
	theme = diplomacy
	window = big_event_window
	override_background = council_chamber

	trigger = {
		NOT = { has_character_flag = in_debate }
		NOT = { has_character_flag = active_succession_crisis }
	}

	immediate = {

		if = {
			limit = {
				NOT = { exists = scope:claimant }
			}
			root.primary_title = {
				random_claimant = {
					limit = {
						has_character_flag = debating
					}
					save_scope_as = claimant
				}
			}
		}

		set_variable = {
			name = crisis_diplomacy_score
			value = 0
		}
		if = {
			limit = {
				is_adult = no
				has_active_diarchy = no
			}
			designate_diarch_or_secretariat_effect = { ACTOR = root }
		}

		root = {
			add_character_flag = council_host_flag
			set_variable = {
				name = grand_council_special_guest
				value = scope:claimant
			}
		}
	}

	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		character = scope:claimant
		animation = throne_room_conversation_1
	}

	# OPTION A: COUNCIL (DIPLOMATIC PATH)
	option = {
		name = succession_crisis_diplomacy_ruler.0001.a
		ai_chance = {
			base = 50
			modifier = {
				factor = 0
				is_at_war = yes
			}
			modifier = {
				add = 0
				scope:claimant = { is_adult = no }
			}
			modifier = {
				add = 30
				has_trait = patient
			}
			modifier = {
				add = 30
				has_trait = content
			}
			modifier = {
				add = 20
				has_trait = compassionate
			}
			modifier = {
				add = 20
				has_trait = just
			}
			modifier = {
				add = 20
				has_trait = calm
			}
			modifier = {
				add = -30
				has_trait = wrathful
			}
			modifier = {
				add = -30
				has_trait = arrogant
			}
			modifier = {
				add = -20
				has_trait = ambitious
			}
			modifier = {
				add = -20
				has_trait = brave
			}
		}

		if = {
			limit = { has_character_flag = debating }
			remove_character_flag = debating
		}
		add_character_flag = in_debate

		# Remove from current activity after 5 days
		trigger_event = {
			id = succession_crisis_misc.0022
			days = 20
		}

		# Fire the council after 7 days
		trigger_event = {
			id = succession_crisis_misc.0016
			days = 30
		}
		
		# Notify claimant
		scope:claimant = { 
			trigger_event = {
				id = succession_crisis_misc.0020
				days = 7
			}
		}
	}

	# OPTION B: WAR (REJECTION PATH)
	option = {
		name = succession_crisis_diplomacy_ruler.0001.b
		ai_chance = {
			base = 50
			modifier = {
				factor = 0
				scope:claimant = { is_adult = no }
			}
			modifier = {
				add = 30
				has_trait = wrathful
			}
			modifier = {
				add = 30
				has_trait = arrogant
			}
			modifier = {
				add = 20
				has_trait = ambitious
			}
			modifier = {
				add = 20
				has_trait = brave
			}
			modifier = {
				add = -30
				has_trait = patient
			}
			modifier = {
				add = -20
				has_trait = content
			}
			modifier = {
				add = -20
				has_trait = compassionate
			}
			modifier = {
				add = -20
				has_trait = just
			}
			modifier = {
				add = -20
				has_trait = calm
			}
			modifier = {
				add = -50
				has_trait = craven
			}
		}

		if = {
			limit = { has_character_flag = debating }
			remove_character_flag = debating
		}

		scope:claimant = {
			remove_character_flag = debating
			trigger_event = {
				id = succession_crisis_diplomacy_event.0002
				days = { 3 10 }
			}
		}
	}
}
# ============================================================
# EVENT 0002:  DIPLOMACY ROUND 1
# ============================================================
succession_crisis_diplomacy_ruler.0002 = {
	type = activity_event
	title = succession_crisis_diplomacy_ruler.0002.t
	desc = succession_crisis_diplomacy_ruler.0002.desc
	theme = diplomacy
	window = big_event_window
	override_background = ep3_hagia_sophia
	
	immediate = {
		# Scope Saving
		root = { save_scope_as = current_ruler }
		scope:activity.special_guest:the_pretender = {
			save_scope_as = claimant
		}
		if = {
			limit = { scope:current_ruler = { has_character_flag = crisis_heir_flag } }
			scope:current_ruler = { save_scope_as = crisis_heir }
		}
		scope:current_ruler = {
			primary_title = { save_scope_as = crisis_title }
		}

		# Existing Portrait and Witness Logic
		if = {
			limit = {
				scope:claimant = { is_adult = no }
				scope:claimant = { has_active_diarchy = yes }
			}
			scope:claimant = {
				diarch = {
					save_scope_as = right_portrait_char
				}
			}
		}
		else = {
			scope:claimant = {
				save_scope_as = right_portrait_char
			}
		}

		if = {
			limit = {
				root = { is_adult = no }
				root = { has_active_diarchy = yes }
			}
			root = {
				diarch = {
					save_scope_as = left_portrait_char
				}
			}
		}
		else = {
			root = {
				save_scope_as = left_portrait_char
			}
		}

		# Check for vassals who have arrived via flag instead of variable list
		scope:activity = {
			every_attending_character = {
				limit = {
					NOT = { this = scope:left_portrait_char }
					NOT = { this = scope:right_portrait_char }
				}
				add_to_list = potential_witnesses
			}
		}
		
		random_in_list = {
			list = potential_witnesses
			save_scope_as = witness_left
		}
		
		random_in_list = {
			list = potential_witnesses
			limit = { NOT = { this = scope:witness_left } }
			save_scope_as = witness_right
		}

		random_in_list = {
			list = potential_witnesses
			limit = { 
				NOT = { this = scope:witness_left }
				NOT = { this = scope:witness_right }
			}
			save_scope_as = witness_center
		}

		random_in_list = {
			list = potential_witnesses
			limit = { 
				NOT = { this = scope:witness_left }
				NOT = { this = scope:witness_right }
				NOT = { this = scope:witness_center }
			}
			save_scope_as = witness_lower_left
		}
	}

	left_portrait = {
		character = scope:witness_left
		camera = camera_event_left_pointing_back_fov20
		animation = chaplain

	}

	center_portrait = {
		character = scope:left_portrait_char
		animation = debating
		camera = camera_activity_horse
	}

	right_portrait = {
		character = scope:witness_right
		camera = camera_event_center_away_pointing_left_fov25
		animation = chancellor
	}

	lower_left_portrait = {
		character = scope:witness_lower_left
		animation = frontend_right_idle
	}

	lower_center_portrait = {
		character = scope:witness_center
		animation = eavesdrop
	}

	lower_right_portrait = {
		character = scope:right_portrait_char
		animation = throne_room_conversation_1
	}

	option = {
		name = succession_crisis_diplomacy_ruler.0002.a
		custom_tooltip = succession_crisis_diplomacy_ruler.0002.a.tt
		ai_chance = {
			base = 10
			modifier = { add = 20 has_trait = calm }
			modifier = { add = 20 has_trait = patient }
			modifier = { add = 20 has_trait = diligent }
			modifier = { add = 20 has_trait = honest }
			modifier = { add = 50 diplomacy >= 15 }
		}
		hidden_effect = {
			random_list = {
				50 = {
					modifier = {
						add = 25
						scope:left_portrait_char.diplomacy > scope:right_portrait_char.diplomacy
					}
					change_variable = {
						name = crisis_diplomacy_score
						add = 1
					}
					trigger_event = {
						id = succession_crisis_misc.0009
						days = { 30 60 }
					}
				}
				50 = {
					trigger_event = {
						id = succession_crisis_misc.0010
						days = { 30 60 }
					}
				}
			}
		}
	}
	option = {
		name = succession_crisis_diplomacy_ruler.0002.b
		custom_tooltip = succession_crisis_diplomacy_ruler.0002.b.tt
		ai_chance = {
			base = 10
			modifier = { add = 20 has_trait = arrogant }
			modifier = { add = 20 has_trait = ambitious }
			modifier = { add = 20 has_trait = brave }
			modifier = { add = 50 prestige_level >= 4 }
		}
		hidden_effect = {
			random_list = {
				50 = {
					modifier = {
						add = 25
						scope:left_portrait_char.prestige_level >= 3
					}
					change_variable = {
						name = crisis_diplomacy_score
						add = 1
					}
					trigger_event = {
						id = succession_crisis_misc.0009
						days = { 30 60 }
					}
				}
				50 = {
					trigger_event = {
						id = succession_crisis_misc.0010
						days = { 30 60 }
					}
				}
			}
		}
	}
	option = {
		name = succession_crisis_diplomacy_ruler.0002.c
		custom_tooltip = succession_crisis_diplomacy_ruler.0002.c.tt
		trigger = {
			short_term_gold >= 1000
		}
		ai_chance = {
			base = 5
			modifier = { add = 30 has_trait = greedy }
			modifier = { add = 20 has_trait = cynical }
			modifier = { add = 10 has_trait = callous }
			modifier = { add = 50 gold >= 2000 }
		}
		hidden_effect = {
			remove_short_term_gold = medium_gold_value
			random_list = {
				50 = {
					modifier = {
						add = 40
					}
					change_variable = {
						name = crisis_diplomacy_score
						add = 1
					}
					trigger_event = {
						id = succession_crisis_misc.0009
						days = { 30 60 }
					}
				}
				50 = {
					trigger_event = {
						id = succession_crisis_misc.0010
						days = { 30 60 }
					}
				}
			}
		}
	}
	option = {
		name = succession_crisis_diplomacy_ruler.0002.d
		custom_tooltip = succession_crisis_diplomacy_ruler.0002.d.tt
		ai_chance = {
			base = 10
			modifier = { add = 20 has_trait = cynical }
			modifier = { add = 20 has_trait = stubborn }
			modifier = { add = 20 has_trait = diligent }
			modifier = { add = 20 has_trait = patient }
			modifier = { add = 50 learning >= 15 }
		}
		hidden_effect = {
			random_list = {
				50 = {
					modifier = {
						add = 25
						scope:left_portrait_char.learning > scope:right_portrait_char.learning
					}
					change_variable = {
						name = crisis_diplomacy_score
						add = 1
					}
					trigger_event = {
						id = succession_crisis_misc.0009
						days = { 30 60 }
					}
				}
				50 = {
					trigger_event = {
						id = succession_crisis_misc.0010
						days = { 30 60 }
					}
				}
			}
		}
	}
}
# ============================================================
# EVENT 0003:  DIPLOMACY ROUND 2
# ============================================================
succession_crisis_diplomacy_ruler.0003 = {
	type = activity_event
	title = succession_crisis_diplomacy_ruler.0003.t
	desc = succession_crisis_diplomacy_ruler.0003.desc
	theme = diplomacy
	window = big_event_window
	override_background = ep3_hagia_sophia

	immediate = {
		# Scope Saving
		root = { save_scope_as = current_ruler }
		scope:activity.special_guest:the_pretender = {
			save_scope_as = claimant
		}
		if = {
			limit = { scope:current_ruler = { has_character_flag = crisis_heir_flag } }
			scope:current_ruler = { save_scope_as = crisis_heir }
		}
		scope:current_ruler = {
			primary_title = { save_scope_as = crisis_title }
		}

		# Existing Portrait and Witness Logic
		if = {
			limit = {
				scope:claimant = { is_adult = no }
				scope:claimant = { has_active_diarchy = yes }
			}
			scope:claimant = {
				diarch = {
					save_scope_as = right_portrait_char
				}
			}
		}
		else = {
			scope:claimant = {
				save_scope_as = right_portrait_char
			}
		}

		if = {
			limit = {
				root = { is_adult = no }
				root = { has_active_diarchy = yes }
			}
			root = {
				diarch = {
					save_scope_as = left_portrait_char
				}
			}
		}
		else = {
			root = {
				save_scope_as = left_portrait_char
			}
		}

		# Check for vassals who have arrived via flag instead of variable list
		scope:activity = {
			every_attending_character = {
				limit = {
					NOT = { this = scope:left_portrait_char }
					NOT = { this = scope:right_portrait_char }
				}
				add_to_list = potential_witnesses
			}
		}
		
		random_in_list = {
			list = potential_witnesses
			save_scope_as = witness_left
		}
		
		random_in_list = {
			list = potential_witnesses
			limit = { NOT = { this = scope:witness_left } }
			save_scope_as = witness_right
		}

		random_in_list = {
			list = potential_witnesses
			limit = { 
				NOT = { this = scope:witness_left }
				NOT = { this = scope:witness_right }
			}
			save_scope_as = witness_center
		}

		random_in_list = {
			list = potential_witnesses
			limit = { 
				NOT = { this = scope:witness_left }
				NOT = { this = scope:witness_right }
				NOT = { this = scope:witness_center }
			}
			save_scope_as = witness_lower_left
		}
	}

	left_portrait = {
		character = scope:witness_left
		camera = camera_event_left_pointing_back_fov20
		animation = writing

	}

	center_portrait = {
		character = scope:left_portrait_char
		animation = debating
		camera = camera_activity_horse
	}

	right_portrait = {
		character = scope:witness_right
		camera = camera_event_center_away_pointing_left_fov25
		animation = reading
	}

	lower_left_portrait = {
		character = scope:witness_lower_left
		animation = frontend_right_idle
	}

	lower_center_portrait = {
		character = scope:witness_center
		animation = eavesdrop
	}

	lower_right_portrait = {
		character = scope:right_portrait_char
		animation = throne_room_conversation_1
	}

	option = {
		name = succession_crisis_diplomacy_ruler.0003.a
		custom_tooltip = succession_crisis_diplomacy_ruler.0003.a.tt
		ai_chance = {
			base = 10
			modifier = { add = 50 martial >= 15 }
			modifier = { add = 20 has_trait = brave }
			modifier = { add = 20 has_trait = wrathful }
		}
		hidden_effect = {
			random_list = {
				50 = {
					modifier = {
						add = 35
						scope:left_portrait_char.max_military_strength >= scope:right_portrait_char.max_military_strength
					}
					change_variable = {
						name = crisis_diplomacy_score
						add = 1
					}
					trigger_event = {
						id = succession_crisis_misc.0009
						days = { 30 60 }
					}
				}
				50 = {
					trigger_event = {
						id = succession_crisis_misc.0010
						days = { 30 60 }
					}
				}
			}
		}
	}
	option = {
		name = succession_crisis_diplomacy_ruler.0003.b
		custom_tooltip = succession_crisis_diplomacy_ruler.0003.b.tt
		ai_chance = {
			base = 10
			modifier = { add = 30 has_trait = zealous }
		}
		hidden_effect = {
			random_list = {
				50 = {
					modifier = {
						add = 25
						cp:councillor_court_chaplain = {
							opinion = {
								target = root
								value > 0
							}
						}
					}
					change_variable = {
						name = crisis_diplomacy_score
						add = 1
					}
					trigger_event = {
						id = succession_crisis_misc.0009
						days = { 30 60 }
					}
				}
				50 = {
					trigger_event = {
						id = succession_crisis_misc.0010
						days = { 30 60 }
					}
				}
			}
		}
	}
	option = {
		name = succession_crisis_diplomacy_ruler.0003.c
		custom_tooltip = succession_crisis_diplomacy_ruler.0003.c.tt
		ai_chance = {
			base = 10
			modifier = { add = 50 stewardship >= 15 }
			modifier = { add = 20 has_trait = diligent }
			modifier = { add = 20 has_trait = ambitious }
		}
		hidden_effect = {
			random_list = {
				50 = {
					modifier = {
						add = 35
						stewardship > scope:right_portrait_char.stewardship
					}
					change_variable = {
						name = crisis_diplomacy_score
						add = 1
					}
					trigger_event = {
						id = succession_crisis_misc.0009
						days = { 30 60 }
					}
				}
				50 = {
					trigger_event = {
						id = succession_crisis_misc.0010
						days = { 30 60 }
					}
				}
			}
		}
	}
}
# ============================================================
# EVENT 0004: RULER DIPLOMATIC WIN
# ============================================================
succession_crisis_diplomacy_ruler.0004 = {
	type = activity_event
	title = succession_crisis_diplomacy_ruler.0004.t
	desc = succession_crisis_diplomacy_ruler.0004.desc
	theme = diplomacy
	override_background = ep3_hagia_sophia
	override_effect_2d = { reference = legend_glow }
	window = big_event_window

	immediate = {
		involved_activity = {
			activity_host = {
				save_scope_as = current_ruler
			}
			special_guest:the_pretender = {
				save_scope_as = claimant
			}
		}

		if = {
			limit = {
				involved_activity = {
					any_attending_character = {
						is_vassal_of = scope:current_ruler
						this != scope:current_ruler
						this != scope:claimant
					}
				}
			}
			involved_activity = {
				random_attending_character = {
					limit = {
						is_vassal_of = scope:current_ruler
						this != scope:current_ruler
						this != scope:claimant
					}
					save_scope_as = witness_left
				}
				random_attending_character = {
					limit = { 
						is_vassal_of = scope:current_ruler 
						NOT = { this = scope:witness_left } 
						this != scope:current_ruler
						this != scope:claimant
					}
					save_scope_as = witness_right
				}
			}
		}
		else = {
			scope:current_ruler = {
				random_courtier = {
					limit = {
						this != scope:claimant
					}
					save_scope_as = witness_left
				}
				random_courtier = {
					limit = { 
						NOT = { this = scope:witness_left }
						this != scope:claimant
					}
					save_scope_as = witness_right
				}
			}
		}
	}

	left_portrait = {
		character = scope:witness_left
		camera = camera_event_left_pointing_back_fov20
		animation = throne_room_applaud_1

	}

	center_portrait = {
		character = root
		animation = prayer
	}

	right_portrait = {
		character = scope:witness_right
		camera = camera_event_center_away_pointing_left_fov25
		animation = throne_room_cheer_1
	}

	lower_right_portrait = {
		character = scope:claimant
		animation = anger
	}

	option = {
		name = succession_crisis_diplomacy_ruler.0004.a
	}
}
# ============================================================
# EVENT 0005: RULER DIPLOMATIC LOSE
# ============================================================
succession_crisis_diplomacy_ruler.0005 = {
	type = activity_event
	title = succession_crisis_diplomacy_ruler.0005.t
	desc = succession_crisis_diplomacy_ruler.0005.desc
	theme = diplomacy
	override_background = ep3_hagia_sophia
	override_effect_2d = { reference = legend_glow }
	window = big_event_window

	immediate = {
		# Ensure current_ruler and claimant are defined for the transfer effect
		involved_activity = {
			activity_host = {
				save_scope_as = current_ruler
			}
			special_guest:the_pretender = {
				save_scope_as = claimant
			}
		}

		# Handle witness list selection
		if = {
			limit = {
				involved_activity = {
					any_attending_character = {
						is_vassal_of = scope:current_ruler
						this != scope:current_ruler
						this != scope:claimant
					}
				}
			}
			involved_activity = {
				random_attending_character = {
					limit = {
						is_vassal_of = scope:current_ruler
						this != scope:current_ruler
						this != scope:claimant
					}
					save_scope_as = witness_left
				}
				random_attending_character = {
					limit = { 
						is_vassal_of = scope:current_ruler 
						NOT = { this = scope:witness_left } 
						this != scope:current_ruler
						this != scope:claimant
					}
					save_scope_as = witness_right
				}
			}
		}
		else = {
			scope:current_ruler = {
				random_courtier = {
					limit = {
						this != scope:claimant
					}
					save_scope_as = witness_left
				}
				random_courtier = {
					limit = { 
						NOT = { this = scope:witness_left }
						this != scope:claimant
					}
					save_scope_as = witness_right
				}
			}
		}
	}

	left_portrait = {
		character = scope:witness_left
		camera = camera_event_left_pointing_back_fov20
		animation = throne_room_applaud_1
	}

	center_portrait = {
		character = scope:claimant
		animation = prayer
	}

	right_portrait = {
		character = scope:witness_right
		camera = camera_event_center_away_pointing_left_fov25
		animation = throne_room_cheer_1
	}

	lower_right_portrait = {
		character = root
		animation = anger
	}

	# Accept the loss
	option = {
		name = succession_crisis_diplomacy_ruler.0005.a
		ai_chance = {
			base = 50
			modifier = { add = 20 has_trait = craven }
			modifier = { add = 20 has_trait = content }
			modifier = { add = -30 has_trait = arrogant }
			modifier = { add = -30 has_trait = ambitious }
		}

		# Trigger sc_council_events.0011 for all attending guests
		involved_activity = {
			every_attending_character = {
				limit = {
					NOT = { this = scope:current_ruler }
					NOT = { this = scope:claimant }
				}
				trigger_event = sc_council_events.0011
			}
		}

		remove_character_flag = debating

		involved_activity = {
			special_guest:the_pretender = {
				remove_character_flag = debating
			}
		}
	}

	# Refuse to concede, set war flag
	option = {
		name = succession_crisis_diplomacy_ruler.0005.b
		ai_chance = {
			base = 50
			modifier = { add = 30 has_trait = wrathful }
			modifier = { add = 30 has_trait = arrogant }
			modifier = { add = 30 has_trait = ambitious }
			modifier = { add = 20 has_trait = brave }
		}

		# Set war flags
		root = { add_character_flag = imminent_war }

		remove_character_flag = debating

		involved_activity = {
			special_guest:the_pretender = {
				remove_character_flag = debating
			}
		}
	}
}
# ============================================================
# EVENT 0006: RULER DIPLOMACY CLAIMANT's CHILD DESIGNATED HEIR (DEFUNCT)
# ============================================================
succession_crisis_diplomacy_ruler.0006 = {
	type = activity_event
	title = succession_crisis_diplomacy_ruler.0006.t
	desc = succession_crisis_diplomacy_ruler.0006.desc
	theme = diplomacy
	window = big_event_window
	override_background = ep3_hagia_sophia

	immediate = {
		scope:claimant = {
			save_scope_as = claimant
		}
	}

	left_portrait = {
		character = root
		animation = acknowledging
	}

	right_portrait = {
		character = scope:claimant
		animation = obsequious_bow
	}

	# OPTION A: ACCEPT COMPROMISE
	option = {
		name = succession_crisis_diplomacy_ruler.0006.a
		
		ai_chance = {
			base = 50
			modifier = {
				add = 30
				has_trait = calm
			}
			modifier = {
				add = 30
				has_trait = patient
			}
			modifier = {
				add = 20
				has_trait = content
			}
			modifier = {
				add = 20
				has_trait = compassionate
			}
			modifier = {
				add = -50
				has_trait = ambitious
			}
			modifier = {
				add = -50
				has_trait = wrathful
			}
			modifier = {
				add = -20
				has_trait = arrogant
			}
		}

		scope:claimant = {
			primary_heir = {
				save_scope_as = target_heir
			}
			trigger_event = {
				id = succession_crisis_diplomacy_event.0008
				days = { 3 10 }
			}
		}

		root = {
			set_designated_heir = scope:target_heir
		}
	}

	# OPTION B: REJECT COMPROMISE
	option = {
		name = succession_crisis_diplomacy_ruler.0006.b
		
		ai_chance = {
			base = 50
			modifier = {
				add = 40
				has_trait = ambitious
			}
			modifier = {
				add = 40
				has_trait = wrathful
			}
			modifier = {
				add = 30
				has_trait = arrogant
			}
			modifier = {
				add = 20
				has_trait = stubborn
			}
			modifier = {
				add = -50
				has_trait = calm
			}
			modifier = {
				add = -50
				has_trait = patient
			}
		}

		scope:claimant = {
			trigger_event = {
				id = succession_crisis_diplomacy_event.0007
				days = { 3 10 }
			}
		}
	}
}
# ============================================================
# EVENT 0007: RULER DIPLOMACY CLAIMANT DESIGNATED HEIR
# ============================================================
succession_crisis_diplomacy_ruler.0007 = {
	type = activity_event
	title = succession_crisis_diplomacy_ruler.0007.t
	desc = succession_crisis_diplomacy_ruler.0007.desc
	theme = diplomacy
	window = big_event_window
	override_background = ep3_hagia_sophia

	immediate = {
		scope:claimant = {
			save_scope_as = claimant
		}
	}

	left_portrait = {
		character = root
		animation = reading
	}

	right_portrait = {
		character = scope:claimant
		animation = obsequious_bow
	}

	# OPTION A: ACCEPT CLAIMANT AS HEIR
	option = {
		name = succession_crisis_diplomacy_ruler.0007.a
		
		ai_chance = {
			base = 50
			modifier = {
				add = 30
				has_trait = calm
			}
			modifier = {
				add = 30
				has_trait = patient
			}
			modifier = {
				add = 20
				has_trait = content
			}
			modifier = {
				add = 20
				has_trait = humble
			}
			modifier = {
				add = -50
				has_trait = ambitious
			}
			modifier = {
				add = -50
				has_trait = wrathful
			}
			modifier = {
				add = -20
				has_trait = arrogant
			}
		}

		root = {
			set_designated_heir = scope:claimant
		}
		
		scope:claimant = {
			trigger_event = {
				id = succession_crisis_diplomacy_event.0009
				days = { 3 10 }
			}
		}
	}

	# OPTION B: REJECT CLAIMANT AS HEIR
	option = {
		name = succession_crisis_diplomacy_ruler.0007.b
		
		ai_chance = {
			base = 50
			modifier = {
				add = 40
				has_trait = ambitious
			}
			modifier = {
				add = 40
				has_trait = wrathful
			}
			modifier = {
				add = 30
				has_trait = arrogant
			}
			modifier = {
				add = 20
				has_trait = stubborn
			}
			modifier = {
				add = -50
				has_trait = calm
			}
			modifier = {
				add = -50
				has_trait = patient
			}
		}

		scope:claimant = {
			trigger_event = {
				id = succession_crisis_diplomacy_event.0007
				days = { 3 10 }
			}
		}
	}
}
# ============================================================
# EVENT 0008: COUNCIL DEADLOCK
# ============================================================
succession_crisis_diplomacy_ruler.0008 = {
	type = activity_event
	title = succession_crisis_diplomacy_ruler.0008.t
	desc = succession_crisis_diplomacy_ruler.0008.desc
	theme = war
	override_background = ep3_hagia_sophia
	window = big_event_window
	left_portrait = {
		character = root
		animation = worry
	}
	right_portrait = {
		character = scope:activity.special_guest:the_pretender
		animation = stunned
	}
	option = {
		name = succession_crisis_diplomacy_ruler.0008.a
	}
}
# ============================================================
# EVENT 0009: CLAIMANT AND RULER MARRY
# ============================================================
succession_crisis_diplomacy_ruler.0009 = {
	type = activity_event
	title = succession_crisis_diplomacy_ruler.0009.t
	desc = succession_crisis_diplomacy_ruler.0009.desc
	theme = diplomacy

	immediate = {
		involved_activity = {
			special_guest:the_pretender = {
				save_scope_as = claimant
				save_scope_as = claimant_to_marry
			}
		}
	}

	left_portrait = {
		character = root
	}

	right_portrait = {
		character = scope:claimant_to_marry
	}

	option = {
		name = succession_crisis_diplomacy_ruler.0009.a
		trigger = {
			exists = scope:claimant_to_marry
		}
		ai_chance = {
			base = 50
			modifier = {
				add = 20
				opinion = {
					target = scope:claimant_to_marry
					value >= 20
				}
			}
			modifier = {
				add = -20
				opinion = {
					target = scope:claimant_to_marry
					value <= -20
				}
			}
			modifier = {
				add = 10
				has_trait = trusting
			}
			modifier = {
				add = -10
				has_trait = stubborn
			}
		}
		add_opinion = {
			target = scope:claimant_to_marry
			modifier = avoided_crisis_opinion
		}
		reverse_add_opinion = {
			target = scope:claimant_to_marry
			modifier = avoided_crisis_opinion
		}
		marry = scope:claimant_to_marry
		scope:claimant_to_marry = {
			save_scope_as = new_spouse
		}
		trigger_event = {
			id = succession_crisis_misc.0018
			days = 1
		}
		scope:claimant_to_marry = {
			root = {
				save_scope_as = new_spouse
			}
			trigger_event = {
				id = succession_crisis_misc.0018
				days = 1
			}
		}
	}

	option = {
		name = succession_crisis_diplomacy_ruler.0009.b
		ai_chance = {
			base = 50
			modifier = {
				add = 20
				opinion = {
					target = scope:claimant_to_marry
					value <= -20
				}
			}
			modifier = {
				add = -20
				opinion = {
					target = scope:claimant_to_marry
					value >= 20
				}
			}
			modifier = {
				add = 10
				has_trait = stubborn
			}
			modifier = {
				add = -10
				has_trait = trusting
			}
		}
		scope:claimant_to_marry = {
			trigger_event = {
				id = succession_crisis_diplomacy_event.0007
				days = { 3 10 }
			}
		}
	}
}

# ============================================================
# EVENT 0010: CLAIMANT MARRY RULER'S CHILD
# ============================================================
succession_crisis_diplomacy_ruler.0010 = {
	type = activity_event
	title = succession_crisis_diplomacy_ruler.0010.t
	desc = succession_crisis_diplomacy_ruler.0010.desc
	theme = diplomacy

	immediate = {
		involved_activity = {
			special_guest:the_pretender = {
				save_scope_as = claimant
				save_scope_as = claimant_to_marry
			}
		}
	}

	left_portrait = {
		character = root
	}

	right_portrait = {
		character = scope:ruler_child_to_marry
	}

	option = {
		name = succession_crisis_diplomacy_ruler.0010.a
		trigger = {
			exists = scope:ruler_child_to_marry
			exists = scope:claimant_to_marry
		}
		ai_chance = {
			base = 50
			modifier = {
				add = 20
				opinion = {
					target = scope:claimant_to_marry
					value >= 20
				}
			}
			modifier = {
				add = -20
				opinion = {
					target = scope:claimant_to_marry
					value <= -20
				}
			}
			modifier = {
				add = 10
				has_trait = trusting
			}
			modifier = {
				add = -10
				has_trait = stubborn
			}
		}
		add_opinion = {
			target = scope:claimant_to_marry
			modifier = avoided_crisis_opinion
		}
		reverse_add_opinion = {
			target = scope:claimant_to_marry
			modifier = avoided_crisis_opinion
		}
		scope:claimant_to_marry = {
			marry = scope:ruler_child_to_marry
			scope:ruler_child_to_marry = {
				save_scope_as = new_spouse
			}
			trigger_event = {
				id = succession_crisis_misc.0018
				days = 1
			}
			trigger_event = {
				id = succession_crisis_diplomacy_event.0010
				days = 1
			}
		}
		scope:ruler_child_to_marry = {
			scope:claimant_to_marry = {
				save_scope_as = new_spouse
			}
			trigger_event = {
				id = succession_crisis_misc.0018
				days = 1
			}
		}
	}

	option = {
		name = succession_crisis_diplomacy_ruler.0010.b
		ai_chance = {
			base = 50
			modifier = {
				add = 20
				opinion = {
					target = scope:claimant_to_marry
					value <= -20
				}
			}
			modifier = {
				add = -20
				opinion = {
					target = scope:claimant_to_marry
					value >= 20
				}
			}
			modifier = {
				add = 10
				has_trait = stubborn
			}
			modifier = {
				add = -10
				has_trait = trusting
			}
		}
		scope:claimant_to_marry = {
			trigger_event = {
				id = succession_crisis_diplomacy_event.0007
				days = { 3 10 }
			}
		}
	}
}

# ============================================================
# EVENT 0011: CLAIMANT CHILD MARRY RULER
# ============================================================
succession_crisis_diplomacy_ruler.0011 = {
	type = activity_event
	title = succession_crisis_diplomacy_ruler.0011.t
	desc = succession_crisis_diplomacy_ruler.0011.desc
	theme = diplomacy

	immediate = {
		involved_activity = {
			special_guest:the_pretender = {
				save_scope_as = claimant
				save_scope_as = claimant_to_marry
			}
		}
	}

	left_portrait = {
		character = root
	}

	right_portrait = {
		character = scope:claimant_child_to_marry
	}

	option = {
		name = succession_crisis_diplomacy_ruler.0011.a
		trigger = {
			exists = scope:claimant_child_to_marry
		}
		ai_chance = {
			base = 50
			modifier = {
				add = 20
				opinion = {
					target = scope:claimant_to_marry
					value >= 20
				}
			}
			modifier = {
				add = -20
				opinion = {
					target = scope:claimant_to_marry
					value <= -20
				}
			}
			modifier = {
				add = 10
				has_trait = trusting
			}
			modifier = {
				add = -10
				has_trait = stubborn
			}
		}
		add_opinion = {
			target = scope:claimant_to_marry
			modifier = avoided_crisis_opinion
		}
		reverse_add_opinion = {
			target = scope:claimant_to_marry
			modifier = avoided_crisis_opinion
		}
		scope:claimant_to_marry = {
			trigger_event = {
				id = succession_crisis_diplomacy_event.0011
				days = 1
			}
		}
		marry = scope:claimant_child_to_marry
		scope:claimant_child_to_marry = {
			save_scope_as = new_spouse
		}
		trigger_event = {
			id = succession_crisis_misc.0018
			days = 1
		}
		scope:claimant_child_to_marry = {
			root = {
				save_scope_as = new_spouse
			}
			trigger_event = {
				id = succession_crisis_misc.0018
				days = 1
			}
		}
	}

	option = {
		name = succession_crisis_diplomacy_ruler.0011.b
		ai_chance = {
			base = 50
			modifier = {
				add = 20
				opinion = {
					target = scope:claimant_to_marry
					value <= -20
				}
			}
			modifier = {
				add = -20
				opinion = {
					target = scope:claimant_to_marry
					value >= 20
				}
			}
			modifier = {
				add = 10
				has_trait = stubborn
			}
			modifier = {
				add = -10
				has_trait = trusting
			}
		}
		scope:claimant_to_marry = {
			trigger_event = {
				id = succession_crisis_diplomacy_event.0007
				days = { 3 10 }
			}
		}
	}
}

# ============================================================
# EVENT 0012: CHILDREN MARRY
# ============================================================
succession_crisis_diplomacy_ruler.0012 = {
	type = activity_event
	title = succession_crisis_diplomacy_ruler.0012.t
	desc = succession_crisis_diplomacy_ruler.0012.desc
	theme = diplomacy

	immediate = {
		involved_activity = {
			special_guest:the_pretender = {
				save_scope_as = claimant
				save_scope_as = claimant_to_marry
			}
		}
	}

	left_portrait = {
		character = scope:ruler_child_to_marry
	}

	right_portrait = {
		character = scope:claimant_child_to_marry
	}

	option = {
		name = succession_crisis_diplomacy_ruler.0012.a
		trigger = {
			exists = scope:claimant_child_to_marry
			exists = scope:ruler_child_to_marry
		}
		ai_chance = {
			base = 50
			modifier = {
				add = 20
				opinion = {
					target = scope:claimant_to_marry
					value >= 20
				}
			}
			modifier = {
				add = -20
				opinion = {
					target = scope:claimant_to_marry
					value <= -20
				}
			}
			modifier = {
				add = 10
				has_trait = trusting
			}
			modifier = {
				add = -10
				has_trait = stubborn
			}
		}
		add_opinion = {
			target = scope:claimant_to_marry
			modifier = avoided_crisis_opinion
		}
		reverse_add_opinion = {
			target = scope:claimant_to_marry
			modifier = avoided_crisis_opinion
		}
		scope:claimant_to_marry = {
			trigger_event = {
				id = succession_crisis_diplomacy_event.0012
				days = 1
			}
		}
		scope:ruler_child_to_marry = {
			marry = scope:claimant_child_to_marry
			scope:claimant_child_to_marry = {
				save_scope_as = new_spouse
			}
			trigger_event = {
				id = succession_crisis_misc.0018
				days = 1
			}
		}
		scope:claimant_child_to_marry = {
			scope:ruler_child_to_marry = {
				save_scope_as = new_spouse
			}
			trigger_event = {
				id = succession_crisis_misc.0018
				days = 1
			}
		}
	}

	option = {
		name = succession_crisis_diplomacy_ruler.0012.b
		ai_chance = {
			base = 50
			modifier = {
				add = 20
				opinion = {
					target = scope:claimant_to_marry
					value <= -20
				}
			}
			modifier = {
				add = -20
				opinion = {
					target = scope:claimant_to_marry
					value >= 20
				}
			}
			modifier = {
				add = 10
				has_trait = stubborn
			}
			modifier = {
				add = -10
				has_trait = trusting
			}
		}
		scope:claimant_to_marry = {
			trigger_event = {
				id = succession_crisis_diplomacy_event.0007
				days = { 3 10 }
			}
		}
	}
}

# ============================================================
# EVENT 0013: CLAIMANT IS LATE (RULER PERSPECTIVE)
# ============================================================
succession_crisis_diplomacy_ruler.0013 = {
	type = character_event
	title = succession_crisis_diplomacy_ruler.0013.t
	desc = succession_crisis_diplomacy_ruler.0013.desc
	theme = diplomacy

	immediate = {
		# Resolve the crisis_title scope
		if = {
			limit = { NOT = { exists = scope:crisis_title } }
			root.primary_title = { save_scope_as = crisis_title }
		}

		# Find the claimant within the crisis title with the specific flags
		scope:crisis_title = {
			random_claimant = {
				limit = {
					has_character_flag = active_crisis_rebel
				}
				save_scope_as = claimant
			}
		}
	}

	left_portrait = {
		character = root
		animation = disapproval
	}

	right_portrait = {
		character = scope:claimant
		animation = worry
	}

	option = {
		name = succession_crisis_diplomacy_ruler.0013.a

		# Ruler gets prestige and legitimacy
		add_prestige = 150
		if = {
			limit = { is_valid_for_legitimacy_change = yes }
			add_legitimacy = 100
		}

		# Claimant loses prestige and legitimacy
		scope:claimant = {
			add_prestige = -150
			if = {
				limit = { is_valid_for_legitimacy_change = yes }
				add_legitimacy = -100
			}
		}
	}
}