namespace = mpo_chaotic_kurultai_succession

scripted_trigger disobedient_kurultai_member_trigger = {
	is_physically_able_ai_adult = yes
	NOR = {
		is_obedient_to = root
		has_relation_friend = root
		has_relation_lover = root
		has_trait = loyal
	}
}

mpo_chaotic_kurultai_succession.0001 = { # Siblings become your rivals
	type = character_event
	title = mpo_chaotic_kurultai_succession.0001.t
	theme = raid
	override_background = { reference = mpo_steppe_evening }
	override_effect_2d = {
		reference = rain	
	}
	
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:dead_parent
				}
				desc = chaotic_kurultai_intro_1
			}
			desc = chaotic_kurultai_intro_2
		}
		desc = mpo_chaotic_kurultai_succession.0001.desc
		triggered_desc = {
			trigger = {
				exists = scope:sibling_rival_2
			}
			desc = mpo_chaotic_kurultai_succession.0001.desc_addition
		}
	}
	
	left_portrait = {
		character = scope:sibling_rival_1
		animation = hunting_knife_start
	}
	right_portrait = {
		character = scope:sibling_rival_2
		animation = spymaster
		camera = camera_event_left
	}
	
	trigger = {
		any_sibling = {
			is_physically_able_ai = yes
			age >= 12
			can_set_relation_rival_trigger = { CHARACTER = root }
			NOR = {
				has_relation_friend = root
				has_relation_potential_friend = root
				has_relation_rival = root
				has_trait = craven
				has_trait = content
			}
			OR = {
				AND = {
					is_male = yes
					faith_dominant_gender_male_or_equal = yes
				}
				AND = {
					is_female = yes
					faith_dominant_gender_female_or_equal = yes
				}
			}
		}
	}
	
	immediate = {
		primary_title.previous_holder = {
			if = {
				limit = {
					is_alive = no
				}
				save_scope_as = dead_parent
			}
		}
		random_sibling = {
			limit = {
				is_physically_able_ai = yes
				age >= 12
				can_set_relation_rival_trigger = { CHARACTER = root }
				NOR = {
					has_relation_friend = root
					has_relation_potential_friend = root
					has_relation_rival = root
					has_trait = craven
					has_trait = content
				}
				OR = {
					AND = {
						is_male = yes
						faith_dominant_gender_male_or_equal = yes
					}
					AND = {
						is_female = yes
						faith_dominant_gender_female_or_equal = yes
					}
				}
			}
			save_scope_as = sibling_rival_1
		}
		random_sibling = {
			limit = {
				is_physically_able_ai = yes
				age >= 12
				NOR = {
					has_relation_friend = root
					has_relation_rival = root
					has_trait = craven
					has_trait = content
					this = scope:sibling_rival_1
				}
				OR = {
					AND = {
						is_male = yes
						faith_dominant_gender_male_or_equal = yes
					}
					AND = {
						is_female = yes
						faith_dominant_gender_female_or_equal = yes
					}
				}
			}
			save_scope_as = sibling_rival_2
		}
		scope:sibling_rival_1 = {
			set_relation_rival = {
				target = root
				reason = rival_kurultai_succession
			}
		}
		scope:sibling_rival_2 ?= {
			set_relation_rival = {
				target = root
				reason = rival_kurultai_succession
			}
		}
	}
	
	option = {
		name = mpo_chaotic_kurultai_succession.0001.a
		ai_chance = {
			base = 100
		}
	}
}

mpo_chaotic_kurultai_succession.0002 = { # Sibling seizes tributary lands and leaves
	type = character_event
	title = mpo_chaotic_kurultai_succession.0002.t
	theme = raid
	override_background = { reference = mpo_steppe_evening }
	override_effect_2d = {
		reference = smoke
	}
	
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:dead_parent
				}
				desc = chaotic_kurultai_intro_1
			}
			desc = chaotic_kurultai_intro_2
		}
		desc = mpo_chaotic_kurultai_succession.0002.desc
		triggered_desc = {
			trigger = {
				exists = scope:backing_kurultai
			}
			desc = mpo_chaotic_kurultai_succession.0002.desc_addition
		}
		desc = mpo_chaotic_kurultai_succession.0002.desc_end
	}
	
	left_portrait = {
		character = scope:sibling_rival_1
		triggered_animation = {
			trigger = {
				NOT = { exists = scope:backing_kurultai }
			}
			animation = horse_surveying
		}
		animation = horse_conversing_right
		camera = camera_event_horse_left
	}
	right_portrait = {
		character = scope:backing_kurultai
		animation = horse_conversing_left
		camera = camera_event_horse_right
	}
	
	lower_right_portrait = scope:tributary_usurped
	
	trigger = {
		any_tributary = {
			is_ai = yes
			exists = dynasty
			dynasty != root.dynasty
			government_has_flag = government_is_nomadic
			domicile.herd < root.domicile.herd
			is_landed = yes
			save_temporary_scope_as = tributary_test
		}
		any_sibling = {
			is_physically_able_ai_adult = yes
			is_ruler = no
			is_courtier_of = root
			NOR = {
				has_relation_friend = root
				has_relation_potential_friend = root
				has_trait = craven
				has_trait = content
			}
			OR = {
				AND = {
					is_male = yes
					faith_dominant_gender_male_or_equal = yes
				}
				AND = {
					is_female = yes
					faith_dominant_gender_female_or_equal = yes
				}
			}
			save_temporary_scope_as = sibling_test
		}
	}
	
	immediate = {
		primary_title.previous_holder = {
			if = {
				limit = {
					is_alive = no
				}
				save_scope_as = dead_parent
			}
		}
		random_tributary = {
			limit = {
				is_ai = yes
				exists = dynasty
				dynasty != root.dynasty
				government_has_flag = government_is_nomadic
				domicile.herd < root.domicile.herd
				is_landed = yes
			}
			save_scope_as = tributary_usurped
		}
		random_sibling = {
			limit = {
				is_physically_able_ai_adult = yes
				is_ruler = no
				is_courtier_of = root
				NOR = {
					has_relation_friend = root
					has_relation_potential_friend = root
					has_trait = craven
					has_trait = content
				}
				OR = {
					AND = {
						is_male = yes
						faith_dominant_gender_male_or_equal = yes
					}
					AND = {
						is_female = yes
						faith_dominant_gender_female_or_equal = yes
					}
				}
			}
			save_scope_as = sibling_rival_1
			add_character_flag = {
				flag = domicile_culture_and_faith_check
				days = 1
			}
		}
		random_in_list = {
			list = disobedient_kurultai
			limit = {
				is_physically_able_ai_adult = yes
				NOR = {
					is_obedient_to = root
					has_relation_friend = root
					has_relation_lover = root
					has_trait = loyal
					this = scope:sibling_rival_1
					this = scope:tributary_usurped
				}
			}
			save_scope_as = backing_kurultai
		}
		hidden_effect = {
			create_title_and_vassal_change = {
				type = usurped
				save_scope_as = change
				add_claim_on_loss = yes
			}
			scope:tributary_usurped = {
				every_held_title = {
					limit = {
						tier >= tier_county
						is_landless_type_title = no
					}
					change_title_holder = {
						holder = scope:sibling_rival_1
						change = scope:change
					}
				}
				every_vassal = {
					change_liege = {
						LIEGE = scope:sibling_rival_1
						CHANGE = scope:change
					}
				}
			}
			resolve_title_and_vassal_change = scope:change
			scope:tributary_usurped = {
				every_tributary = {
					save_scope_as = current_tributary
					start_tributary_interaction_effect = {
						TRIBUTARY = scope:current_tributary
						SUZERAIN = scope:sibling_rival_1
					}
				}
			}
			scope:sibling_rival_1 = {
				domicile ?= {
					add_domicile_building = yurt_main_02
					add_random_yurt_external_building_effect = yes
					add_random_yurt_external_building_effect = yes
					upgrade_random_yurt_external_building_effect = yes
					upgrade_random_yurt_external_building_effect = yes
				}
			}
		}
		custom_tooltip = sibling_usurped_tributary_lands_tt
		scope:sibling_rival_1 = {
			if = {
				limit = {
					can_set_relation_potential_rival_trigger = { CHARACTER = root }
				}
				set_relation_potential_rival = root
			}
			add_opinion = {
				target = root
				modifier = weak_opinion
				opinion = -35
			}
		}
		scope:tributary_usurped = {
			end_tributary = yes
			pay_herd = { target = scope:sibling_rival_1 value = scope:tributary_usurped.domicile.herd }
			hidden_effect = {
				if = {
					limit = {
						can_set_relation_potential_rival_trigger = { CHARACTER = scope:sibling_rival_1 }
					}
					set_relation_potential_rival = root
				}
				add_opinion = {
					target = scope:sibling_rival_1
					modifier = usurped_title
					opinion = -50
				}
			}
		}
		scope:backing_kurultai ?= {
			add_opinion = {
				target = root
				modifier = weak_opinion
				opinion = -25
			}
		}
	}
	
	option = {
		name = mpo_chaotic_kurultai_succession.0002.a
		ai_chance = {
			base = 100
		}
	}
}

mpo_chaotic_kurultai_succession.0003 = { # Tributary leaves
	type = character_event
	title = mpo_chaotic_kurultai_succession.0003.t
	theme = raid
	override_background = { reference = mpo_steppe_evening }
	
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:dead_parent
				}
				desc = chaotic_kurultai_intro_1
			}
			desc = chaotic_kurultai_intro_2
		}
		desc = mpo_chaotic_kurultai_succession.0003.desc
		triggered_desc = {
			trigger = {
				exists = scope:backing_kurultai
			}
			desc = mpo_chaotic_kurultai_succession.0003.desc_addition
		}
		desc = mpo_chaotic_kurultai_succession.0003.desc_end
	}
	
	left_portrait = {
		character = scope:tributary_leaving
		animation = dismissal
	}
	right_portrait = {
		character = scope:backing_kurultai
		animation = standing_horse
		camera = camera_event_standing_with_horse_right
	}
	
	trigger = {
		any_tributary = {
			is_physically_able_ai_adult = yes
			NOT = {
				government_has_flag = government_is_herder
			}
			is_landed = yes
			NOR = {
				is_obedient_to = root
				has_relation_friend = root
				has_relation_potential_friend = root
				has_relation_lover = root
				has_trait = craven
				has_trait = content
				has_trait = loyal
			}
		}
	}
	
	immediate = {
		primary_title.previous_holder = {
			if = {
				limit = {
					is_alive = no
				}
				save_scope_as = dead_parent
			}
		}
		random_tributary = {
			limit = {
				is_physically_able_ai_adult = yes
				NOT = {
					government_has_flag = government_is_herder
				}
				is_landed = yes
				NOR = {
					is_obedient_to = root
					has_relation_friend = root
					has_relation_potential_friend = root
					has_relation_lover = root
					has_trait = craven
					has_trait = content
					has_trait = loyal
				}
			}
			save_scope_as = tributary_leaving
		}
		random_in_list = {
			list = disobedient_kurultai
			limit = {
				disobedient_kurultai_member_trigger = yes
			}
			save_scope_as = backing_kurultai
		}
		scope:tributary_leaving = {
			end_tributary = yes
			if = {
				limit = {
					can_set_relation_potential_rival_trigger = { CHARACTER = root }
				}
				set_relation_potential_rival = root
			}
			add_opinion = {
				target = root
				modifier = weak_opinion
				opinion = -100
			}
		}
		scope:backing_kurultai ?= {
			add_opinion = {
				target = root
				modifier = weak_opinion
				opinion = -25
			}
		}
	}
	
	option = {
		name = mpo_chaotic_kurultai_succession.0003.a
		ai_chance = {
			base = 100
		}
	}
}

mpo_chaotic_kurultai_succession.0004 = { # County Control loss
	type = character_event
	title = mpo_chaotic_kurultai_succession.0004.t
	theme = raid
	override_background = { reference = mpo_raid_burning_asian }
	override_effect_2d = {
		reference = smoke	
	}
	
	left_portrait = {
		character = scope:raider
		animation = sword_coup_degrace
		hide_info = yes
	}
	right_portrait = {
		character = scope:backing_kurultai
		animation = menacing
		camera = camera_event_left
	}
	
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:dead_parent
				}
				desc = chaotic_kurultai_intro_1
			}
			desc = chaotic_kurultai_intro_2
		}
		desc = mpo_chaotic_kurultai_succession.0004.desc
		triggered_desc = {
			trigger = {
				exists = scope:backing_kurultai
			}
			desc = mpo_chaotic_kurultai_succession.0004.desc_addition
		}
		desc = mpo_chaotic_kurultai_succession.0004.desc_end
	}
	
	trigger = {
		any_held_title = {
			tier = tier_county
			is_landless_type_title = no
			county_control > 0
		}
	}
	
	immediate = {
		primary_title.previous_holder = {
			if = {
				limit = {
					is_alive = no
				}
				save_scope_as = dead_parent
			}
		}
		random_pool_character = {
			province = root.location
			limit = { is_physically_able_ai = yes }
			save_scope_as = raider
		}
		every_held_title = {
			limit = {
				tier = tier_county
				is_landless_type_title = no
				county_control > 0
			}
			change_county_control = {
				value = {
					integer_range = {
						min = -50
						max = -5
					}
				}
			}
		}
		random_in_list = {
			list = disobedient_kurultai
			limit = {
				disobedient_kurultai_member_trigger = yes
			}
			save_scope_as = backing_kurultai
		}
		scope:backing_kurultai ?= {
			add_gold = {
				value = {
					integer_range = {
						min = 10
						max = 100
					}
				}
			}
			add_opinion = {
				target = root
				modifier = weak_opinion
				opinion = -25
			}
		}
	}
	
	option = {
		name = mpo_chaotic_kurultai_succession.0004.a
		ai_chance = {
			base = 100
		}
	}
}

mpo_chaotic_kurultai_succession.0005 = { # Loss of Prestige Level
	type = character_event
	title = mpo_chaotic_kurultai_succession.0005.t
	theme = raid
	override_effect_2d = {
		reference = rain
	}
	
	left_portrait = {
		character = root
		animation = stress
	}
	right_portrait = {
		character = scope:backing_kurultai
		animation = laugh
	}
	
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:dead_parent
				}
				desc = chaotic_kurultai_intro_1
			}
			desc = chaotic_kurultai_intro_2
		}
		desc = mpo_chaotic_kurultai_succession.0005.desc
		triggered_desc = {
			trigger = {
				exists = scope:backing_kurultai
			}
			desc = mpo_chaotic_kurultai_succession.0005.desc_addition
		}
	}
	
	trigger = {
		prestige_level > 0
	}
	
	immediate = {
		primary_title.previous_holder = {
			if = {
				limit = {
					is_alive = no
				}
				save_scope_as = dead_parent
			}
		}
		random_in_list = {
			list = disobedient_kurultai
			limit = {
				disobedient_kurultai_member_trigger = yes
			}
			save_scope_as = backing_kurultai
		}
		add_prestige_level = -1
		scope:backing_kurultai ?= {
			add_opinion = {
				target = root
				modifier = weak_opinion
				opinion = -25
			}
		}
	}
	
	option = {
		name = mpo_chaotic_kurultai_succession.0005.a
		ai_chance = {
			base = 100
		}
	}
}

mpo_chaotic_kurultai_succession.0006 = { # 10% of Herd defects to Neighboring realm
	type = character_event
	title = mpo_chaotic_kurultai_succession.0006.t
	theme = raid
	override_background = { reference = mpo_campfire_steppe }
	override_effect_2d = {
		reference = rain
	}
	
	left_portrait = {
		character = scope:rustler
		animation = betting
	}
	right_portrait = {
		character = scope:backing_kurultai
		animation = standing_horse
		camera = camera_event_standing_with_horse_right
	}
	
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:dead_parent
				}
				desc = chaotic_kurultai_intro_1
			}
			desc = chaotic_kurultai_intro_2
		}
		desc = mpo_chaotic_kurultai_succession.0006.desc
		triggered_desc = {
			trigger = {
				exists = scope:backing_kurultai
			}
			desc = mpo_chaotic_kurultai_succession.0006.desc_addition
		}
		desc = mpo_chaotic_kurultai_succession.0006.desc_end
	}
	
	trigger = {
		domicile.herd >= 1000
		any_land_neighboring_realm_with_tributaries_owner = {
			is_physically_able_ai_adult = yes
			government_has_flag = government_is_nomadic
			is_landed = yes
			NOR = {
				is_obedient_to = root
				has_relation_friend = root
				has_relation_lover = root
			}
		}
	}
	
	immediate = {
		save_scope_as = ruler_rustled
		primary_title.previous_holder = {
			if = {
				limit = {
					is_alive = no
				}
				save_scope_as = dead_parent
			}
		}
		random_land_neighboring_realm_with_tributaries_owner = {
			limit = {
				is_physically_able_ai_adult = yes
				government_has_flag = government_is_nomadic
				is_landed = yes
				NOR = {
					is_obedient_to = root
					has_relation_friend = root
					has_relation_lover = root
				}
			}
			save_scope_as = rustler
		}
		random_in_list = {
			list = disobedient_kurultai
			limit = {
				disobedient_kurultai_member_trigger = yes
			}
			save_scope_as = backing_kurultai
		}
		scope:backing_kurultai ?= {
			add_opinion = {
				target = root
				modifier = weak_opinion
				opinion = -25
			}
		}
		save_scope_value_as = {
			name = herd_transfer_value
			value = {
				add = root.domicile.herd
				divide = 10
			}
		}
		show_as_tooltip = {
			pay_herd = {
				target = scope:rustler
				value = scope:herd_transfer_value
			}
		}
	}
	
	option = {
		name = mpo_chaotic_kurultai_succession.0006.a
		ai_chance = {
			base = 100
		}
	}
	
	after = {
		scope:rustler = {
			trigger_event = mpo_chaotic_kurultai_succession.1006
		}
	}
}

mpo_chaotic_kurultai_succession.1006 = { # Response event
	type = character_event
	title = mpo_chaotic_kurultai_succession.1006.t
	theme = raid
	override_background = { reference = mpo_steppe_evening }
	
	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		character = scope:backing_kurultai
		animation = standing_horse
		camera = camera_event_standing_with_horse_right
	}
	lower_right_portrait = scope:ruler_rustled
	
	desc = {
		desc = mpo_chaotic_kurultai_succession.1006.desc
		triggered_desc = {
			trigger = {
				exists = scope:backing_kurultai
			}
			desc = mpo_chaotic_kurultai_succession.1006.desc_addition
		}
	}
	
	trigger = {
	}
	
	immediate = {
	}
	
	option = {
		name = mpo_chaotic_kurultai_succession.1006.a
		scope:ruler_rustled = {
			pay_herd = {
				target = scope:rustler
				value = scope:herd_transfer_value
			}
		}
		ai_chance = {
			base = 100
		}
	}
	
	option = {
		name = mpo_chaotic_kurultai_succession.1006.b
		scope:ruler_rustled = {
			send_interface_toast = {
				type = event_toast_effect_good
				title = mpo_chaotic_kurultai_succession.1006.b.title
				left_icon = scope:rustler
				custom_tooltip = mpo_chaotic_kurultai_succession.1006.b.tt
				add_opinion = {
					target = scope:rustler
					modifier = grateful_opinion
					opinion = 50
				}
				if = {
					limit = {
						NOT = { this = scope:rustler }
						can_set_relation_potential_friend_trigger = { CHARACTER = scope:rustler }
					}
					set_relation_potential_friend = scope:rustler
				}
			}
		}
		ai_chance = {
			base = 0
		}
	}
}

scripted_trigger is_great_courtier_trigger = {
	is_physically_able_ai_adult = yes
	NOR = {
		is_in_list = obedient_kurultai
		is_obedient_to = root
		has_relation_friend = root
		has_relation_lover = root
		has_trait = loyal
		has_trait = content
		is_child_of = root
		is_grandchild_of = root
		is_great_grandchild_of = root
		is_consort_of = root
		is_heir_of = root
		AND = {
			is_female = yes
			patrilinear_marriage = yes
		}
		AND = {
			is_male = yes
			matrilinear_marriage = yes
		}
		is_diarch = yes
		is_designated_diarch = yes
	}
	OR = {
		AND = {
			is_knight = yes
			prowess >= 16
		}
		has_any_court_position = yes
		martial >= monumentally_high_skill_rating
		sum_of_all_skills_value >= sum_of_all_skills_threshold_good
		martial >= monumentally_high_skill_rating
		aptitude:master_of_hunt_court_position >= 4
		aptitude:keeper_of_the_horses_court_position >= 4
		aptitude:boyan_court_position >= 4
		aptitude:siege_engineer_court_position >= 4
		aptitude:yurtchi_court_position >= 4
		aptitude:cherbi_court_position >= 4
		aptitude:yeke_jarquchi_court_position >= 4
		aptitude:foreign_emissary_court_position >= 4
		aptitude:court_physician_court_position >= 4
	}
}

mpo_chaotic_kurultai_succession.0007 = { # Good Courtiers defect to Neighbor
	type = character_event
	title = mpo_chaotic_kurultai_succession.0007.t
	theme = raid
	override_background = { reference = mpo_steppe_evening }
	
	left_portrait = {
		character = scope:courtier_stealer
		animation = schadenfreude
	}
	right_portrait = {
		character = scope:backing_kurultai
		animation = go_to_your_room
		camera = camera_event_left
	}
	lower_right_portrait = scope:courtier_1
	lower_center_portrait = scope:courtier_2
	lower_left_portrait = scope:courtier_3
	
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:dead_parent
				}
				desc = chaotic_kurultai_intro_1
			}
			desc = chaotic_kurultai_intro_2
		}
		desc = mpo_chaotic_kurultai_succession.0007.desc
		triggered_desc = {
			trigger = {
				exists = scope:backing_kurultai
			}
			desc = mpo_chaotic_kurultai_succession.0007.desc_addition
		}
		desc = mpo_chaotic_kurultai_succession.0007.desc_end
	}
	
	trigger = {
		any_land_neighboring_realm_with_tributaries_owner = {
			is_physically_able_ai_adult = yes
			is_landed = yes
			NOR = {
				is_obedient_to = root
				has_relation_friend = root
				has_relation_lover = root
			}
		}
		any_courtier = {
			count >= 3
			is_great_courtier_trigger = yes
		}
	}
	
	immediate = {
		save_scope_as = ruler_rustled
		primary_title.previous_holder = {
			if = {
				limit = {
					is_alive = no
				}
				save_scope_as = dead_parent
			}
		}
		random_land_neighboring_realm_with_tributaries_owner = {
			limit = {
				is_physically_able_ai_adult = yes
				is_landed = yes
				NOR = {
					is_obedient_to = root
					has_relation_friend = root
					has_relation_lover = root
				}
			}
			save_scope_as = courtier_stealer
		}
		random_courtier = {
			limit = {
				is_great_courtier_trigger = yes
			}
			save_scope_as = courtier_1
		}
		random_courtier = {
			limit = {
				is_great_courtier_trigger = yes
				NOT = {
					this = scope:courtier_1
				}
			}
			save_scope_as = courtier_2
		}
		random_courtier = {
			limit = {
				is_great_courtier_trigger = yes
				NOR = {
					this = scope:courtier_1
					this = scope:courtier_2
				}
			}
			save_scope_as = courtier_3
		}
		random_in_list = {
			list = disobedient_kurultai
			limit = {
				disobedient_kurultai_member_trigger = yes
			}
			save_scope_as = backing_kurultai
		}
		scope:backing_kurultai ?= {
			add_opinion = {
				target = root
				modifier = weak_opinion
				opinion = -25
			}
		}
		scope:courtier_stealer = {
			add_courtier = scope:courtier_1
			add_courtier = scope:courtier_2
			add_courtier = scope:courtier_3
		}
	}
	
	option = {
		name = mpo_chaotic_kurultai_succession.0007.a
		ai_chance = {
			base = 100
		}
	}
	
	after = {
		scope:courtier_stealer = {
			trigger_event = mpo_chaotic_kurultai_succession.1007
		}
	}
}

mpo_chaotic_kurultai_succession.1007 = { # Response event
	type = character_event
	title = mpo_chaotic_kurultai_succession.1007.t
	theme = raid
	override_background = { reference = mpo_steppe_evening }
	
	left_portrait = {
		character = root
		animation = interested
	}
	right_portrait = {
		character = scope:backing_kurultai
		animation = debating
	}
	lower_right_portrait = scope:courtier_1
	lower_center_portrait = scope:courtier_2
	lower_left_portrait = scope:courtier_3
	
	desc = {
		desc = mpo_chaotic_kurultai_succession.1007.desc
		triggered_desc = {
			trigger = {
				exists = scope:backing_kurultai
			}
			desc = mpo_chaotic_kurultai_succession.1007.desc_addition
		}
	}
	
	trigger = {
	}
	
	immediate = {
		show_as_tooltip = {
			add_courtier = scope:courtier_1
			add_courtier = scope:courtier_2
			add_courtier = scope:courtier_3
		}
	}
	
	option = {
		name = mpo_chaotic_kurultai_succession.1007.a
		ai_chance = {
			base = 100
		}
	}
	
	option = {
		name = mpo_chaotic_kurultai_succession.1007.b
		scope:ruler_rustled = {
			send_interface_toast = {
				type = event_toast_effect_good
				title = mpo_chaotic_kurultai_succession.1007.b.title
				left_icon = scope:courtier_stealer
				scope:ruler_rustled = {
					add_courtier = scope:courtier_1
					add_courtier = scope:courtier_2
					add_courtier = scope:courtier_3
				}
				add_opinion = {
					target = scope:courtier_stealer
					modifier = grateful_opinion
					opinion = 50
				}
				if = {
					limit = {
						NOT = { this = scope:courtier_stealer }
						can_set_relation_potential_friend_trigger = { CHARACTER = scope:courtier_stealer }
					}
					set_relation_potential_friend = scope:courtier_stealer
				}
			}
		}
		ai_chance = {
			base = 0
		}
	}
}

mpo_chaotic_kurultai_succession.0008 = { # MaA Regiment defects to neighbor
	type = character_event
	title = mpo_chaotic_kurultai_succession.0008.t
	theme = raid
	override_background = { reference = mpo_hunt_steppe }
	
	left_portrait = {
		character = scope:maa_stealer
		animation = horse_archer_idle
		camera = camera_event_horse_left
	}
	right_portrait = {
		character = scope:backing_kurultai
		animation = horse_archer_aggressive
		camera = camera_event_horse_left
	}
	
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:dead_parent
				}
				desc = chaotic_kurultai_intro_1
			}
			desc = chaotic_kurultai_intro_2
		}
		desc = mpo_chaotic_kurultai_succession.0008.desc
		triggered_desc = {
			trigger = {
				exists = scope:backing_kurultai
			}
			desc = mpo_chaotic_kurultai_succession.0008.desc_addition
		}
		desc = mpo_chaotic_kurultai_succession.0008.desc_end
	}
	
	trigger = {
		any_land_neighboring_realm_with_tributaries_owner = {
			is_physically_able_ai_adult = yes
			is_landed = yes
			maa_regiments_count < maa_regiments_max_count
			NOR = {
				is_obedient_to = root
				has_relation_friend = root
				has_relation_lover = root
			}
			NOT = {
				government_has_flag = government_is_herder
			}
		}
		any_maa_regiment = {
			maa_current_troops_count >= maa_max_troops_count
			is_raised = no
			NOT = {
				is_unit_type = siege_weapon
			}
		}
	}
	
	immediate = {
		save_scope_as = ruler_rustled
		primary_title.previous_holder = {
			if = {
				limit = {
					is_alive = no
				}
				save_scope_as = dead_parent
			}
		}
		random_land_neighboring_realm_with_tributaries_owner = {
			limit = {
				is_physically_able_ai_adult = yes
				is_landed = yes
				NOR = {
					is_obedient_to = root
					has_relation_friend = root
					has_relation_lover = root
				}
				NOT = {
					government_has_flag = government_is_herder
				}
			}
			save_scope_as = maa_stealer
		}
		random_maa_regiment = {
			limit = {
				maa_current_troops_count >= maa_max_troops_count
				is_raised = no
				NOT = {
					is_unit_type = siege_weapon
				}
			}
			save_scope_as = defecting_maa
		}
		save_scope_value_as = {
			name = maa_size_scope
			value = scope:defecting_maa.maa_size
		}
		random_in_list = {
			list = disobedient_kurultai
			limit = {
				disobedient_kurultai_member_trigger = yes
			}
			save_scope_as = backing_kurultai
		}
		scope:backing_kurultai ?= {
			add_opinion = {
				target = root
				modifier = weak_opinion
				opinion = -25
			}
		}
		custom_tooltip = regiment_destroyed_tt
	}
	
	option = {
		name = mpo_chaotic_kurultai_succession.0008.a
		ai_chance = {
			base = 100
		}
	}
	
	after = {
		scope:maa_stealer = {
			trigger_event = mpo_chaotic_kurultai_succession.1008
		}
	}
}

mpo_chaotic_kurultai_succession.1008 = { # Response event
	type = character_event
	title = mpo_chaotic_kurultai_succession.1008.t
	theme = raid
	override_background = { reference = mpo_steppe_evening }
	
	left_portrait = {
		character = root
		animation = marshal_random_weapon
	}
	right_portrait = {
		character = scope:backing_kurultai
		animation = bow_idle
	}
	lower_right_portrait = scope:ruler_rustled
	
	desc = {
		desc = mpo_chaotic_kurultai_succession.1008.desc
		triggered_desc = {
			trigger = {
				exists = scope:backing_kurultai
			}
			desc = mpo_chaotic_kurultai_succession.1008.desc_addition
		}
	}
	
	trigger = {
	}
	
	immediate = {
	}
	
	option = {
		name = mpo_chaotic_kurultai_succession.1008.a
		create_maa_regiment = {
			type_of = scope:defecting_maa
			check_can_recruit = no
			size = 1
		}
		custom_tooltip = chaos_upgrade_maa_tt
		hidden_effect = {
			while = {
				random_maa_regiment = {
					limit = {
						can_upgrade_maa = yes
					}
					change_maa_regiment_size = 1
				}
				count = scope:maa_size_scope
			}
			scope:ruler_rustled = {
				scope:defecting_maa = {
					destroy_maa_regiment = yes
				}
			}
		}
		ai_chance = {
			base = 100
		}
	}
	
	option = {
		name = mpo_chaotic_kurultai_succession.1008.b
		scope:ruler_rustled = {
			send_interface_toast = {
				type = event_toast_effect_good
				title = mpo_chaotic_kurultai_succession.1008.b.title
				left_icon = scope:maa_stealer
				add_opinion = {
					target = scope:maa_stealer
					modifier = grateful_opinion
					opinion = 50
				}
				if = {
					limit = {
						NOT = { this = scope:maa_stealer }
						can_set_relation_potential_friend_trigger = { CHARACTER = scope:maa_stealer }
					}
					set_relation_potential_friend = scope:maa_stealer
				}
			}
		}
		ai_chance = {
			base = 0
		}
	}
}

mpo_chaotic_kurultai_succession.0009 = { # Some Gold divided by Siblings
	type = character_event
	title = mpo_chaotic_kurultai_succession.0009.t
	theme = raid
	override_background = { reference = mpo_steppe_evening }
	
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:dead_parent
				}
				desc = chaotic_kurultai_intro_1
			}
			desc = chaotic_kurultai_intro_2
		}
		triggered_desc = {
			trigger = {
				exists = scope:sibling_rival_2
			}
			desc = mpo_chaotic_kurultai_succession.0009.desc
		}
		triggered_desc = {
			trigger = {
				NOT = { exists = scope:sibling_rival_2 }
			}
			desc = mpo_chaotic_kurultai_succession.0009.desc_addition
		}
		triggered_desc = {
			trigger = {
				exists = scope:sibling_rival_2
			}
			desc = mpo_chaotic_kurultai_succession.0009.desc_addition2
		}
		triggered_desc = {
			trigger = {
				exists = scope:sibling_rival_3
			}
			desc = mpo_chaotic_kurultai_succession.0009.desc_addition3
		}
		triggered_desc = {
			trigger = {
				exists = scope:sibling_rival_4
			}
			desc = mpo_chaotic_kurultai_succession.0009.desc_addition4
		}
		triggered_desc = {
			trigger = {
				exists = scope:sibling_rival_5
			}
			desc = mpo_chaotic_kurultai_succession.0009.desc_addition5
		}
		triggered_desc = {
			trigger = {
				exists = scope:sibling_rival_2
			}
			desc = mpo_chaotic_kurultai_succession.0009.desc_end
		}
	}
	
	left_portrait = {
		character = scope:sibling_rival_1
		animation = bribing
	}
	right_portrait = {
		character = scope:sibling_rival_2
		animation = steward
	}
	lower_left_portrait = scope:sibling_rival_3
	lower_center_portrait = scope:sibling_rival_4
	lower_right_portrait = scope:sibling_rival_5
	
	trigger = {
		gold >= 100
		gold >= medium_gold_value
		any_sibling = {
			is_physically_able_ai = yes
			age >= 12
			NOR = {
				has_relation_friend = root
				has_relation_potential_friend = root
				has_trait = generous
				has_trait = content
			}
			OR = {
				AND = {
					is_male = yes
					faith_dominant_gender_male_or_equal = yes
				}
				AND = {
					is_female = yes
					faith_dominant_gender_female_or_equal = yes
				}
			}
		}
	}
	
	immediate = {
		primary_title.previous_holder = {
			if = {
				limit = {
					is_alive = no
				}
				save_scope_as = dead_parent
			}
		}
		random_sibling = {
			limit = {
				is_physically_able_ai = yes
				age >= 12
				NOR = {
					has_relation_friend = root
					has_relation_potential_friend = root
					has_trait = generous
					has_trait = content
				}
				OR = {
					AND = {
						is_male = yes
						faith_dominant_gender_male_or_equal = yes
					}
					AND = {
						is_female = yes
						faith_dominant_gender_female_or_equal = yes
					}
				}
			}
			save_scope_as = sibling_rival_1
			add_to_list = sibling_gold
		}
		random_sibling = {
			limit = {
				is_physically_able_ai = yes
				age >= 12
				NOR = {
					has_relation_friend = root
					has_relation_rival = root
					has_trait = craven
					has_trait = content
					this = scope:sibling_rival_1
				}
				OR = {
					AND = {
						is_male = yes
						faith_dominant_gender_male_or_equal = yes
					}
					AND = {
						is_female = yes
						faith_dominant_gender_female_or_equal = yes
					}
				}
			}
			save_scope_as = sibling_rival_2
			add_to_list = sibling_gold
		}
		random_sibling = {
			limit = {
				is_physically_able_ai = yes
				age >= 12
				NOR = {
					has_relation_friend = root
					has_relation_rival = root
					has_trait = craven
					has_trait = content
					this = scope:sibling_rival_1
					this = scope:sibling_rival_2
				}
				OR = {
					AND = {
						is_male = yes
						faith_dominant_gender_male_or_equal = yes
					}
					AND = {
						is_female = yes
						faith_dominant_gender_female_or_equal = yes
					}
				}
			}
			save_scope_as = sibling_rival_3
			add_to_list = sibling_gold
		}
		random_sibling = {
			limit = {
				is_physically_able_ai = yes
				age >= 12
				NOR = {
					has_relation_friend = root
					has_relation_rival = root
					has_trait = craven
					has_trait = content
					this = scope:sibling_rival_1
					this = scope:sibling_rival_2
					this = scope:sibling_rival_3
				}
				OR = {
					AND = {
						is_male = yes
						faith_dominant_gender_male_or_equal = yes
					}
					AND = {
						is_female = yes
						faith_dominant_gender_female_or_equal = yes
					}
				}
			}
			save_scope_as = sibling_rival_4
			add_to_list = sibling_gold
		}
		random_sibling = {
			limit = {
				is_physically_able_ai = yes
				age >= 12
				NOR = {
					has_relation_friend = root
					has_relation_rival = root
					has_trait = craven
					has_trait = content
					this = scope:sibling_rival_1
					this = scope:sibling_rival_2
					this = scope:sibling_rival_3
					this = scope:sibling_rival_4
				}
				OR = {
					AND = {
						is_male = yes
						faith_dominant_gender_male_or_equal = yes
					}
					AND = {
						is_female = yes
						faith_dominant_gender_female_or_equal = yes
					}
				}
			}
			save_scope_as = sibling_rival_5
			add_to_list = sibling_gold
		}
		save_scope_value_as = {
			name = sibling_gold_sum
			value = {
				add = root.gold
				subtract = {
					value = root.minor_gold_value
					divide = 2
					min = 50
				}
				divide = list_size:sibling_gold
			}
		}
		every_in_list = {
			list = sibling_gold
			root = {
				pay_treasury_or_gold = {
					target = prev
					value = scope:sibling_gold_sum
				}
			}
		}
	}
	
	option = {
		name = mpo_chaotic_kurultai_succession.0009.a
		ai_chance = {
			base = 100
		}
	}
}

mpo_chaotic_kurultai_succession.0010 = { # Legitimacy -500
	type = character_event
	title = mpo_chaotic_kurultai_succession.0010.t
	theme = raid
	override_background = { reference = mpo_campfire_steppe }
	override_effect_2d = {
		reference = rain
	}
	
	left_portrait = {
		character = root
		animation = rage
	}
	right_portrait = {
		character = scope:backing_kurultai
		animation = laugh
	}
	
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:dead_parent
				}
				desc = chaotic_kurultai_intro_1
			}
			desc = chaotic_kurultai_intro_2
		}
		desc = mpo_chaotic_kurultai_succession.0010.desc
		triggered_desc = {
			trigger = {
				exists = scope:backing_kurultai
			}
			desc = mpo_chaotic_kurultai_succession.0010.desc_addition
		}
		desc = mpo_chaotic_kurultai_succession.0010.desc_end
	}
	
	trigger = {
		has_legitimacy = yes
		legitimacy > 0
	}
	
	immediate = {
		primary_title.previous_holder = {
			if = {
				limit = {
					is_alive = no
				}
				save_scope_as = dead_parent
			}
		}
		random_in_list = {
			list = disobedient_kurultai
			limit = {
				disobedient_kurultai_member_trigger = yes
			}
			save_scope_as = backing_kurultai
		}
		add_legitimacy = -500
		scope:backing_kurultai ?= {
			add_opinion = {
				target = root
				modifier = weak_opinion
				opinion = -50
			}
		}
	}
	
	option = {
		name = mpo_chaotic_kurultai_succession.0010.a
		ai_chance = {
			base = 100
		}
	}
}

mpo_chaotic_kurultai_succession.0011 = { # 20% of Herd defects to Neighboring realm
	type = character_event
	title = mpo_chaotic_kurultai_succession.0011.t
	theme = raid
	override_background = { reference = mpo_campfire_steppe }
	override_effect_2d = {
		reference = rain
	}
	
	left_portrait = {
		character = scope:rustler
		animation = manic
	}
	right_portrait = {
		character = scope:backing_kurultai
		animation = standing_horse
		camera = camera_event_standing_with_horse_right
	}
	
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:dead_parent
				}
				desc = chaotic_kurultai_intro_1
			}
			desc = chaotic_kurultai_intro_2
		}
		desc = mpo_chaotic_kurultai_succession.0011.desc
		triggered_desc = {
			trigger = {
				exists = scope:backing_kurultai
			}
			desc = mpo_chaotic_kurultai_succession.0011.desc_addition
		}
		desc = mpo_chaotic_kurultai_succession.0011.desc_end
	}
	
	trigger = {
		domicile.herd >= 1000
		any_land_neighboring_realm_with_tributaries_owner = {
			is_physically_able_ai_adult = yes
			government_has_flag = government_is_nomadic
			is_landed = yes
			NOR = {
				is_obedient_to = root
				has_relation_friend = root
				has_relation_lover = root
			}
		}
	}
	
	immediate = {
		save_scope_as = ruler_rustled
		primary_title.previous_holder = {
			if = {
				limit = {
					is_alive = no
				}
				save_scope_as = dead_parent
			}
		}
		random_land_neighboring_realm_with_tributaries_owner = {
			limit = {
				is_physically_able_ai_adult = yes
				government_has_flag = government_is_nomadic
				is_landed = yes
				NOR = {
					is_obedient_to = root
					has_relation_friend = root
					has_relation_lover = root
				}
			}
			save_scope_as = rustler
		}
		random_in_list = {
			list = disobedient_kurultai
			limit = {
				disobedient_kurultai_member_trigger = yes
			}
			save_scope_as = backing_kurultai
		}
		scope:backing_kurultai ?= {
			add_opinion = {
				target = root
				modifier = weak_opinion
				opinion = -25
			}
		}
		save_scope_value_as = {
			name = herd_transfer_value
			value = {
				add = root.domicile.herd
				divide = 5
			}
		}
		show_as_tooltip = {
			pay_herd = {
				target = scope:rustler
				value = scope:herd_transfer_value
			}
		}
	}
	
	option = {
		name = mpo_chaotic_kurultai_succession.0011.a
		ai_chance = {
			base = 100
		}
	}
	
	after = {
		scope:rustler = {
			trigger_event = mpo_chaotic_kurultai_succession.1006
		}
	}
}

mpo_chaotic_kurultai_succession.0012 = { # 50% Realm Split
	type = character_event
	title = mpo_chaotic_kurultai_succession.0012.t
	theme = raid
	override_background = { reference = mpo_steppe_evening }
	
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:dead_parent
				}
				desc = chaotic_kurultai_intro_1
			}
			desc = chaotic_kurultai_intro_2
		}
		desc = mpo_chaotic_kurultai_succession.0012.desc
	}
	
	left_portrait = {
		character = scope:sibling_rival_1
		animation = jockey_victory
		camera = camera_event_horse_left
	}
	
	trigger = {
		OR = {
			any_in_list = {
				list = disobedient_kurultai
				is_physically_able_ai_adult = yes
				highest_held_title_tier <= tier_duchy
				NOR = {
					has_relation_friend = root
					has_relation_potential_friend = root
					has_trait = generous
					has_trait = content
				}
				OR = {
					AND = {
						is_male = yes
						faith_dominant_gender_male_or_equal = yes
					}
					AND = {
						is_female = yes
						faith_dominant_gender_female_or_equal = yes
					}
				}
			}
			any_sibling = {
				is_physically_able_ai_adult = yes
				highest_held_title_tier <= tier_duchy
				NOR = {
					has_relation_friend = root
					has_relation_potential_friend = root
					has_trait = generous
					has_trait = content
				}
				OR = {
					AND = {
						is_male = yes
						faith_dominant_gender_male_or_equal = yes
					}
					AND = {
						is_female = yes
						faith_dominant_gender_female_or_equal = yes
					}
				}
			}
		}
		highest_held_title_tier >= tier_kingdom
		top_liege = root
		primary_title = {
			any_in_de_jure_hierarchy = {
				count >= 20
				tier = tier_county
				holder.top_liege ?= root
			}
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			any_held_title = {
				has_variable = guaranteed_disastrous_succession
			}
			factor = 0.1
		}	
	}

	immediate = {
		hidden_effect = {
			primary_title.previous_holder = {
				if = {
					limit = {
						is_alive = no
					}
					save_scope_as = dead_parent
				}
			}
			every_sibling = {
				limit = {
					is_physically_able_ai_adult = yes
					highest_held_title_tier <= tier_duchy
					NOR = {
						has_relation_friend = root
						has_relation_potential_friend = root
						has_trait = generous
						has_trait = content
					}
					OR = {
						AND = {
							is_male = yes
							faith_dominant_gender_male_or_equal = yes
						}
						AND = {
							is_female = yes
							faith_dominant_gender_female_or_equal = yes
						}
					}
				}
				add_to_list = potential_khans
			}
			every_in_list = {
				list = disobedient_kurultai
				limit = {
					is_physically_able_ai_adult = yes
					highest_held_title_tier <= tier_duchy
					NOR = {
						has_relation_friend = root
						has_relation_potential_friend = root
						has_trait = generous
						has_trait = content
					}
					OR = {
						AND = {
							is_male = yes
							faith_dominant_gender_male_or_equal = yes
						}
						AND = {
							is_female = yes
							faith_dominant_gender_female_or_equal = yes
						}
					}
				}
				add_to_list = potential_khans
			}
			random_in_list = {
				list = potential_khans
				weight = {
					base = 1
					modifier = {
						add = 100
						is_landed = no
					}
				}
				save_scope_as = sibling_rival_1
				add_character_flag = {
					flag = domicile_culture_and_faith_check
					days = 1
				}
				# The thing below ensures that they are landless if they had land, without breaking realms
				nomadic_heir_cleanup_realm_effect = { CLEANUP_SCOPE_CHAR = scope:sibling_rival_1 }
			}
			nomadic_realm_split_effect = {
				ORIGINAL_REALM_HOLDER = root
				NEW_RULER = scope:sibling_rival_1
				SPLIT_VALUE = 0.5
			}
			scope:sibling_rival_1 = {
				if = {
					limit = {
						has_realm_law = nomadic_authority_1
					}
					remove_realm_law = nomadic_authority_1
				}
				else_if = {
					limit = {
						has_realm_law = nomadic_authority_2
					}
					remove_realm_law = nomadic_authority_2
				}
				if = {
					limit = {
						NOR = {
							has_realm_law = nomadic_authority_4
							has_realm_law = nomadic_authority_5
						}
					}
					add_realm_law_skip_effects = nomadic_authority_3
				}
			}
		}
		custom_tooltip = sibling_tool_50_percent_tt
		pay_treasury_or_gold = {
			target = scope:sibling_rival_1
			value = {
				add = root.gold
				multiply = 0.5
			}
		}
		pay_herd = {
			target = scope:sibling_rival_1
			value = {
				add = root.domicile.herd
				multiply = 0.5
			}
		}
	}
	
	option = {
		name = mpo_chaotic_kurultai_succession.0012.a
		ai_chance = {
			base = 100
		}
	}
}

mpo_chaotic_kurultai_succession.0013 = { # 20% Realm Split
	type = character_event
	title = mpo_chaotic_kurultai_succession.0013.t
	theme = raid
	override_background = { reference = mpo_steppe_evening }
	
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:dead_parent
				}
				desc = chaotic_kurultai_intro_1
			}
			desc = chaotic_kurultai_intro_2
		}
		desc = mpo_chaotic_kurultai_succession.0013.desc
	}
	
	left_portrait = {
		character = scope:sibling_rival_1
		animation = horse_archer_idle
		camera = camera_event_horse_right
	}
	
	trigger = {
		NOT = {
			has_character_flag = mongol_successor_flag
		}
		OR = {
			any_in_list = {
				list = disobedient_kurultai
				is_physically_able_ai_adult = yes
				highest_held_title_tier <= tier_duchy
				NOR = {
					has_relation_friend = root
					has_relation_potential_friend = root
					has_trait = generous
					has_trait = content
				}
				OR = {
					AND = {
						is_male = yes
						faith_dominant_gender_male_or_equal = yes
					}
					AND = {
						is_female = yes
						faith_dominant_gender_female_or_equal = yes
					}
				}
			}
			any_sibling = {
				is_physically_able_ai_adult = yes
				highest_held_title_tier <= tier_duchy
				NOR = {
					has_relation_friend = root
					has_relation_potential_friend = root
					has_trait = generous
					has_trait = content
				}
				OR = {
					AND = {
						is_male = yes
						faith_dominant_gender_male_or_equal = yes
					}
					AND = {
						is_female = yes
						faith_dominant_gender_female_or_equal = yes
					}
				}
			}
		}
		highest_held_title_tier >= tier_kingdom
		top_liege = root
		primary_title = {
			any_in_de_jure_hierarchy = {
				count >= 20
				tier = tier_county
				holder.top_liege ?= root
			}
		}
	}
	
	immediate = {
		hidden_effect = {
			primary_title.previous_holder = {
				if = {
					limit = {
						is_alive = no
					}
					save_scope_as = dead_parent
				}
			}
			every_sibling = {
				limit = {
					is_physically_able_ai_adult = yes
					highest_held_title_tier <= tier_duchy
					NOR = {
						has_relation_friend = root
						has_relation_potential_friend = root
						has_trait = generous
						has_trait = content
					}
					OR = {
						AND = {
							is_male = yes
							faith_dominant_gender_male_or_equal = yes
						}
						AND = {
							is_female = yes
							faith_dominant_gender_female_or_equal = yes
						}
					}
				}
				add_to_list = potential_khans
			}
			every_in_list = {
				list = disobedient_kurultai
				limit = {
					is_physically_able_ai_adult = yes
					highest_held_title_tier <= tier_duchy
					NOR = {
						has_relation_friend = root
						has_relation_potential_friend = root
						has_trait = generous
						has_trait = content
					}
					OR = {
						AND = {
							is_male = yes
							faith_dominant_gender_male_or_equal = yes
						}
						AND = {
							is_female = yes
							faith_dominant_gender_female_or_equal = yes
						}
					}
				}
				add_to_list = potential_khans
			}
			random_in_list = {
				list = potential_khans
				weight = {
					base = 1
					modifier = {
						add = 100
						is_landed = no
					}
				}
				save_scope_as = sibling_rival_1
				add_character_flag = {
					flag = domicile_culture_and_faith_check
					days = 1
				}
				# The thing below ensures that they are landless if they had land, without breaking realms
				nomadic_heir_cleanup_realm_effect = { CLEANUP_SCOPE_CHAR = scope:sibling_rival_1 }
			}
			nomadic_realm_split_effect = {
				ORIGINAL_REALM_HOLDER = root
				NEW_RULER = scope:sibling_rival_1
				SPLIT_VALUE = 0.2
			}
			scope:sibling_rival_1 = {
				if = {
					limit = {
						has_realm_law = nomadic_authority_1
					}
					remove_realm_law = nomadic_authority_1
				}
				else_if = {
					limit = {
						has_realm_law = nomadic_authority_2
					}
					remove_realm_law = nomadic_authority_2
				}
				if = {
					limit = {
						NOR = {
							has_realm_law = nomadic_authority_4
							has_realm_law = nomadic_authority_5
						}
					}
					add_realm_law_skip_effects = nomadic_authority_3
				}
			}
		}
		custom_tooltip = sibling_tool_20_percent_tt
		pay_treasury_or_gold = {
			target = scope:sibling_rival_1
			value = {
				add = root.gold
				multiply = 0.2
			}
		}
		pay_herd = {
			target = scope:sibling_rival_1
			value = {
				add = root.domicile.herd
				multiply = 0.2
			}
		}
	}
	
	option = {
		name = mpo_chaotic_kurultai_succession.0013.a
		ai_chance = {
			base = 100
		}
	}
}

mpo_chaotic_kurultai_succession.0014 = { # Extreme kurultai disapproval: shatter realm
	type = character_event
	title = mpo_chaotic_kurultai_succession.0014.t
	theme = raid
	override_background = { reference = mpo_raid_burning_asian }
	override_effect_2d = {
		reference = smoke	
	}
	
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:dead_parent
				}
				desc = chaotic_kurultai_intro_1
			}
			desc = chaotic_kurultai_intro_2
		}
		triggered_desc = {
			trigger = {
				exists = scope:kurultai_1
			}
			desc = mpo_chaotic_kurultai_succession.0014.desc
		}
		triggered_desc = {
			trigger = {
				NOT = { exists = scope:kurultai_1 }
			}
			desc = mpo_chaotic_kurultai_succession.0014.desc_alt
		}
	}
	
	left_portrait = {
		character = scope:kurultai_1
		animation = manic
	}
	
	right_portrait = {
		character = scope:kurultai_2
		animation = rage
	}
	
	lower_left_portrait = scope:kurultai_3
	lower_center_portrait = scope:kurultai_4
	lower_right_portrait = scope:kurultai_5
	
	trigger = {
		#Stop breakup during Mongol breakup
		NOT = {
			has_character_flag = mongol_successor_flag
		}
		#This is happening to newly made titles
		exists = primary_title.previous_holder
		OR = {
			any_in_list = {
				list = disobedient_kurultai
				count >= 4
				is_physically_able_ai_adult = yes
				NOR = {
					has_relation_friend = root
					has_relation_potential_friend = root
					has_trait = calm
				}
			}
			"list_size(obedient_kurultai)" <= 0
		}
		highest_held_title_tier >= tier_kingdom
		top_liege = root
	}
	#This is the worst one, right? Well... there ya go
	weight_multiplier = {
		base = 1
		modifier = {
			any_held_title = {
				has_variable = guaranteed_disastrous_succession
			}
			factor = 100
		}	
	}
	
	immediate = {
		every_held_title = {
			limit = {
				has_variable = guaranteed_disastrous_succession
			}
			remove_variable = guaranteed_disastrous_succession
		}
		custom_tooltip = title_chaos_dissolved_tt
		primary_title.previous_holder = {
			if = {
				limit = {
					is_alive = no
				}
				save_scope_as = dead_parent
			}
		}
		random_in_list = {
			list = disobedient_kurultai
			limit = {
				is_physically_able_ai_adult = yes
				NOR = {
					has_relation_friend = root
					has_relation_potential_friend = root
					has_trait = calm
				}
			}
			save_scope_as = kurultai_1
			add_opinion = {
				target = root
				modifier = weak_opinion
				opinion = -50
			}
		}
		random_in_list = {
			list = disobedient_kurultai
			limit = {
				is_physically_able_ai_adult = yes
				NOR = {
					has_relation_friend = root
					has_relation_potential_friend = root
					has_trait = calm
					this = scope:kurultai_1
				}
			}
			save_scope_as = kurultai_2
			add_opinion = {
				target = root
				modifier = weak_opinion
				opinion = -50
			}
		}
		random_in_list = {
			list = disobedient_kurultai
			limit = {
				is_physically_able_ai_adult = yes
				NOR = {
					has_relation_friend = root
					has_relation_potential_friend = root
					has_trait = calm
					this = scope:kurultai_1
					this = scope:kurultai_2
				}
			}
			save_scope_as = kurultai_3
			add_opinion = {
				target = root
				modifier = weak_opinion
				opinion = -50
			}
		}
		random_in_list = {
			list = disobedient_kurultai
			limit = {
				is_physically_able_ai_adult = yes
				NOR = {
					has_relation_friend = root
					has_relation_potential_friend = root
					has_trait = calm
					this = scope:kurultai_1
					this = scope:kurultai_2
					this = scope:kurultai_3
				}
			}
			save_scope_as = kurultai_4
			add_opinion = {
				target = root
				modifier = weak_opinion
				opinion = -50
			}
		}
		random_in_list = {
			list = disobedient_kurultai
			limit = {
				is_physically_able_ai_adult = yes
				NOR = {
					has_relation_friend = root
					has_relation_potential_friend = root
					has_trait = calm
					this = scope:kurultai_1
					this = scope:kurultai_2
					this = scope:kurultai_3
					this = scope:kurultai_4
				}
			}
			save_scope_as = kurultai_5
			add_opinion = {
				target = root
				modifier = weak_opinion
				opinion = -50
			}
		}
		hidden_effect = {
			create_title_and_vassal_change = {
				type = independency
				save_scope_as = change
				add_claim_on_loss = no
			}

			every_vassal = {
				change_liege_or_become_independent = {
					CHANGE = scope:change
					VASSAL = this
				}
			}

			every_vassal = {
				limit = { is_ai = no }
				send_interface_toast = {
					type = event_faction_neutral_text
					title = liege_primary_title_dissolution
					desc = liege_primary_title_chaos_desc
					left_icon = root
				}
			}

			resolve_title_and_vassal_change = scope:change

			every_held_title = {
				limit = {
					tier >= tier_kingdom
				}
				add_to_temporary_list = titles_to_destroy
			}

			every_in_list = {
				list = titles_to_destroy
				holder = {
					destroy_title = prev
				}
			}
		}
	}
	
	option = {
		name = mpo_chaotic_kurultai_succession.0014.a
		ai_chance = {
			base = 100
		}
	}
}

mpo_chaotic_kurultai_succession.0015 = { # 40% of Herd defects to Neighboring realm
	type = character_event
	title = mpo_chaotic_kurultai_succession.0015.t
	theme = raid
	override_background = { reference = mpo_campfire_steppe }
	override_effect_2d = {
		reference = rain
	}
	
	left_portrait = {
		character = scope:rustler
		animation = eccentric
	}
	right_portrait = {
		character = scope:backing_kurultai
		animation = standing_horse
		camera = camera_event_standing_with_horse_right
	}
	
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:dead_parent
				}
				desc = chaotic_kurultai_intro_1
			}
			desc = chaotic_kurultai_intro_2
		}
		desc = mpo_chaotic_kurultai_succession.0015.desc
		triggered_desc = {
			trigger = {
				exists = scope:backing_kurultai
			}
			desc = mpo_chaotic_kurultai_succession.0015.desc_addition
		}
		desc = mpo_chaotic_kurultai_succession.0015.desc_end
	}
	
	trigger = {
		domicile.herd >= 1000
		any_land_neighboring_realm_with_tributaries_owner = {
			is_physically_able_ai_adult = yes
			government_has_flag = government_is_nomadic
			is_landed = yes
			NOR = {
				is_obedient_to = root
				has_relation_friend = root
				has_relation_lover = root
			}
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			any_held_title = {
				has_variable = guaranteed_disastrous_succession
			}
			factor = 0.1
		}	
	}
	
	immediate = {
		save_scope_as = ruler_rustled
		primary_title.previous_holder = {
			if = {
				limit = {
					is_alive = no
				}
				save_scope_as = dead_parent
			}
		}
		random_land_neighboring_realm_with_tributaries_owner = {
			limit = {
				is_physically_able_ai_adult = yes
				government_has_flag = government_is_nomadic
				is_landed = yes
				NOR = {
					is_obedient_to = root
					has_relation_friend = root
					has_relation_lover = root
				}
			}
			save_scope_as = rustler
		}
		random_in_list = {
			list = disobedient_kurultai
			limit = {
				disobedient_kurultai_member_trigger = yes
			}
			save_scope_as = backing_kurultai
		}
		scope:backing_kurultai ?= {
			add_opinion = {
				target = root
				modifier = weak_opinion
				opinion = -50
			}
		}
		save_scope_value_as = {
			name = herd_transfer_value
			value = {
				add = root.domicile.herd
				multiply = 0.4
			}
		}
		show_as_tooltip = {
			pay_herd = {
				target = scope:rustler
				value = scope:herd_transfer_value
			}
		}
	}
	
	option = {
		name = mpo_chaotic_kurultai_succession.0015.a
		ai_chance = {
			base = 100
		}
	}
	
	after = {
		scope:rustler = {
			trigger_event = mpo_chaotic_kurultai_succession.1006
		}
	}
}

mpo_chaotic_kurultai_succession.0016 = { # 3 Tributaries leave
	type = character_event
	title = mpo_chaotic_kurultai_succession.0016.t
	theme = raid
	override_background = { reference = mpo_steppe_evening }
	
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:dead_parent
				}
				desc = chaotic_kurultai_intro_1
			}
			desc = chaotic_kurultai_intro_2
		}
		desc = mpo_chaotic_kurultai_succession.0016.desc
		triggered_desc = {
			trigger = {
				exists = scope:backing_kurultai
			}
			desc = mpo_chaotic_kurultai_succession.0016.desc_addition
		}
		desc = mpo_chaotic_kurultai_succession.0016.desc_end
	}
	
	left_portrait = {
		character = scope:tributary_leaving
		animation = eyeroll
	}
	right_portrait = {
		character = scope:backing_kurultai
		animation = standing_horse
		camera = camera_event_standing_with_horse_right
	}
	lower_left_portrait = scope:tributary_leaving2
	lower_right_portrait = scope:tributary_leaving3
	
	trigger = {
		any_tributary = {
			count >= 3
			is_physically_able_ai_adult = yes
			NOT = {
				government_has_flag = government_is_herder
			}
			is_landed = yes
			NOR = {
				is_obedient_to = root
				has_relation_friend = root
				has_relation_potential_friend = root
				has_relation_lover = root
				has_trait = craven
				has_trait = content
				has_trait = loyal
			}
		}
	}
	
	immediate = {
		primary_title.previous_holder = {
			if = {
				limit = {
					is_alive = no
				}
				save_scope_as = dead_parent
			}
		}
		random_tributary = {
			limit = {
				is_physically_able_ai_adult = yes
				NOT = {
					government_has_flag = government_is_herder
				}
				is_landed = yes
				NOR = {
					is_obedient_to = root
					has_relation_friend = root
					has_relation_potential_friend = root
					has_relation_lover = root
					has_trait = craven
					has_trait = content
					has_trait = loyal
				}
			}
			save_scope_as = tributary_leaving
		}
		random_tributary = {
			limit = {
				is_physically_able_ai_adult = yes
				NOT = {
					government_has_flag = government_is_herder
				}
				is_landed = yes
				NOR = {
					is_obedient_to = root
					has_relation_friend = root
					has_relation_potential_friend = root
					has_relation_lover = root
					has_trait = craven
					has_trait = content
					has_trait = loyal
					this = scope:tributary_leaving
				}
			}
			save_scope_as = tributary_leaving2
		}
		random_tributary = {
			limit = {
				is_physically_able_ai_adult = yes
				NOT = {
					government_has_flag = government_is_herder
				}
				is_landed = yes
				NOR = {
					is_obedient_to = root
					has_relation_friend = root
					has_relation_potential_friend = root
					has_relation_lover = root
					has_trait = craven
					has_trait = content
					has_trait = loyal
					this = scope:tributary_leaving
					this = scope:tributary_leaving2
				}
			}
			save_scope_as = tributary_leaving3
		}
		random_in_list = {
			list = disobedient_kurultai
			limit = {
				disobedient_kurultai_member_trigger = yes
			}
			save_scope_as = backing_kurultai
		}
		scope:tributary_leaving = {
			end_tributary = yes
			if = {
				limit = {
					can_set_relation_potential_rival_trigger = { CHARACTER = root }
				}
				set_relation_potential_rival = root
			}
			add_opinion = {
				target = root
				modifier = weak_opinion
				opinion = -100
			}
		}
		scope:tributary_leaving2 = {
			end_tributary = yes
			if = {
				limit = {
					can_set_relation_potential_rival_trigger = { CHARACTER = root }
				}
				set_relation_potential_rival = root
			}
			add_opinion = {
				target = root
				modifier = weak_opinion
				opinion = -100
			}
		}
		scope:tributary_leaving3 = {
			end_tributary = yes
			if = {
				limit = {
					can_set_relation_potential_rival_trigger = { CHARACTER = root }
				}
				set_relation_potential_rival = root
			}
			add_opinion = {
				target = root
				modifier = weak_opinion
				opinion = -100
			}
		}
		scope:backing_kurultai ?= {
			add_opinion = {
				target = root
				modifier = weak_opinion
				opinion = -35
			}
		}
	}
	
	option = {
		name = mpo_chaotic_kurultai_succession.0016.a
		ai_chance = {
			base = 100
		}
	}
}

mpo_chaotic_kurultai_succession.0017 = { # All Tributaries leave
	type = character_event
	title = mpo_chaotic_kurultai_succession.0017.t
	theme = raid
	override_background = { reference = mpo_steppe_evening }
	override_effect_2d = {
		reference = rain	
	}
	
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:dead_parent
				}
				desc = chaotic_kurultai_intro_1
			}
			desc = chaotic_kurultai_intro_2
		}
		desc = mpo_chaotic_kurultai_succession.0017.desc
		triggered_desc = {
			trigger = {
				exists = scope:backing_kurultai
			}
			desc = mpo_chaotic_kurultai_succession.0017.desc_addition
		}
		desc = mpo_chaotic_kurultai_succession.0017.desc_end
	}
	
	left_portrait = {
		character = scope:tributary_leaving
		animation = threatening
	}
	right_portrait = {
		character = scope:backing_kurultai
		animation = standing_horse
		camera = camera_event_standing_with_horse_right
	}
	
	trigger = {
		any_tributary = {
			count >= 5
			is_physically_able_ai_adult = yes
			NOT = {
				government_has_flag = government_is_herder
			}
			is_landed = yes
			NOR = {
				is_obedient_to = root
				has_relation_friend = root
				has_relation_potential_friend = root
				has_relation_lover = root
				has_trait = craven
				has_trait = content
				has_trait = loyal
			}
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			primary_title = {
				has_variable = guaranteed_disastrous_succession
			}
			factor = 0.1
		}	
	}
	
	immediate = {
		primary_title.previous_holder = {
			if = {
				limit = {
					is_alive = no
				}
				save_scope_as = dead_parent
			}
		}
		random_tributary = {
			limit = {
				is_physically_able_ai_adult = yes
				NOT = {
					government_has_flag = government_is_herder
				}
				is_landed = yes
				NOR = {
					is_obedient_to = root
					has_relation_friend = root
					has_relation_potential_friend = root
					has_relation_lover = root
					has_trait = craven
					has_trait = content
					has_trait = loyal
				}
			}
			save_scope_as = tributary_leaving
		}
		every_tributary = {
			limit = {
				is_physically_able_ai_adult = yes
				NOT = {
					government_has_flag = government_is_herder
				}
				is_landed = yes
				NOR = {
					is_obedient_to = root
					has_relation_friend = root
					has_relation_potential_friend = root
					has_relation_lover = root
					has_trait = craven
					has_trait = content
					has_trait = loyal
					this = scope:tributary_leaving
				}
			}
			end_tributary = yes
			if = {
				limit = {
					can_set_relation_potential_rival_trigger = { CHARACTER = root }
				}
				set_relation_potential_rival = root
			}
			add_opinion = {
				target = root
				modifier = weak_opinion
				opinion = -100
			}
		}
		random_in_list = {
			list = disobedient_kurultai
			limit = {
				disobedient_kurultai_member_trigger = yes
			}
			save_scope_as = backing_kurultai
		}
		scope:tributary_leaving = {
			end_tributary = yes
			if = {
				limit = {
					can_set_relation_potential_rival_trigger = { CHARACTER = root }
				}
				set_relation_potential_rival = root
			}
			add_opinion = {
				target = root
				modifier = weak_opinion
				opinion = -100
			}
		}
		scope:backing_kurultai ?= {
			add_opinion = {
				target = root
				modifier = weak_opinion
				opinion = -50
			}
		}
	}
	
	option = {
		name = mpo_chaotic_kurultai_succession.0017.a
		ai_chance = {
			base = 100
		}
	}
}

mpo_chaotic_kurultai_succession.1000 = { # Choose successor Khanate
	type = character_event
	title = mpo_chaotic_kurultai_succession.1000.t
	theme = raid
	override_background = { reference = mpo_steppe_evening }
	override_effect_2d = {
		reference = rain	
	}
	
	desc = mpo_chaotic_kurultai_succession.1000.desc
	
	left_portrait = {
		character = root
		animation = standing_horse
		camera = camera_event_standing_with_horse_right
	}
	
	option = {
		name = mpo_chaotic_kurultai_succession.1000.a
		ai_chance = {
			base = 100
		}
	}
	
	option = {
		name = mpo_chaotic_kurultai_succession.1000.b
		trigger = {
			exists = scope:ilkhanate_ruler
			scope:ilkhanate_ruler != root
		}
		set_player_character = scope:ilkhanate_ruler
		ai_chance = {
			base = 100
		}
	}
	
	option = {
		name = mpo_chaotic_kurultai_succession.1000.c
		trigger = {
			exists = scope:red_horde_ruler
			scope:red_horde_ruler != root
		}
		set_player_character = scope:red_horde_ruler
		ai_chance = {
			base = 100
		}
	}
	
	option = {
		name = mpo_chaotic_kurultai_succession.1000.d
		trigger = {
			exists = scope:white_horde_ruler
			scope:white_horde_ruler != root
		}
		set_player_character = scope:white_horde_ruler
		ai_chance = {
			base = 100
		}
	}
	
	option = {
		name = mpo_chaotic_kurultai_succession.1000.e
		trigger = {
			exists = scope:aarlud_khanate_ruler
			scope:aarlud_khanate_ruler != root
		}
		set_player_character = scope:aarlud_khanate_ruler
		ai_chance = {
			base = 100
		}
	}
	
	option = {
		name = mpo_chaotic_kurultai_succession.1000.f
		trigger = {
			exists = scope:togskol_khanate_ruler
			scope:togskol_khanate_ruler != root
		}
		set_player_character = scope:togskol_khanate_ruler
		ai_chance = {
			base = 100
		}
	}
	
	option = {
		name = mpo_chaotic_kurultai_succession.1000.g
		trigger = {
			exists = scope:baruun_khanate_ruler
			scope:baruun_khanate_ruler != root
		}
		set_player_character = scope:baruun_khanate_ruler
		ai_chance = {
			base = 100
		}
	}
	
	option = {
		name = mpo_chaotic_kurultai_succession.1000.h
		trigger = {
			exists = scope:golden_horde_ruler
			scope:golden_horde_ruler != root
		}
		set_player_character = scope:golden_horde_ruler
		ai_chance = {
			base = 100
		}
	}
	
	option = {
		name = mpo_chaotic_kurultai_succession.1000.i
		trigger = {
			exists = scope:chagatai_ruler
			scope:chagatai_ruler != root
		}
		set_player_character = scope:chagatai_ruler
		ai_chance = {
			base = 100
		}
	}

	option = {
		name = mpo_chaotic_kurultai_succession.1000.j
		trigger = {
			exists = scope:great_yuan_ruler
			scope:great_yuan_ruler != root
		}
		set_player_character = scope:great_yuan_ruler
		ai_chance = {
			base = 100
		}
	}

	option = {
		name = mpo_chaotic_kurultai_succession.1000.k
		trigger = {
			exists = scope:blue_horde_ruler
			scope:blue_horde_ruler != root
		}
		set_player_character = scope:blue_horde_ruler
		ai_chance = {
			base = 100
		}
	}

	option = {
		name = mpo_chaotic_kurultai_succession.1000.l
		trigger = {
			exists = scope:omnod_dalai_khanate_ruler
			scope:omnod_dalai_khanate_ruler != root
		}
		set_player_character = scope:omnod_dalai_khanate_ruler
		ai_chance = {
			base = 100
		}
	}
}
