﻿
#####################################################################
# EFFECT LIST
#####################################################################
# !!! Remember to add all new effects with a short description here !!!

#got_council_position_effect: 			gives the corresponding opinion to the liege
#fired_from_council_position_effect: 	gives the corresponding opinion to the liege

#####################################################################
# COUNCIL EFFECTS
#####################################################################

got_council_position_effect = {
	save_scope_as = new_councillor
	# Travel Leaders can't be councillors, but should appear in the councillor list
	if = {
		limit = { has_court_position = travel_leader_court_position }
		liege = {
			revoke_court_position = {
				recipient = scope:new_councillor
				court_position = travel_leader_court_position
			}
		}
	}
	#If there is a fired opinion remove it
	if = {
		limit = {
			has_opinion_modifier = {
				modifier = fired_from_council_opinion
				target = liege
			}			
		}
		remove_opinion = {
			modifier = fired_from_council_opinion
			target = liege
		}
	}
	# No longer angry for losing court position - this is *better*!
	if = {
		limit = {
			has_opinion_modifier = {
				modifier = revoked_court_position_opinion
				target = liege
			}			
		}
		remove_opinion = {
			modifier = revoked_court_position_opinion
			target = liege
		}
	}

	add_character_flag = is_in_the_council
}

fired_from_council_position_effect = {

	add_opinion = {
		modifier = fired_from_council_opinion
		target = liege
	}

	# If we're a clan this affects unity
	#add_clan_unity_interaction_effect = {
	#	CHARACTER = root.liege
	#	TARGET = this
	#	VALUE = miniscule_unity_loss
	#	DESC = clan_unity_fired_from_council.desc
	#	REVERSE_NON_HOUSE_TARGET = no
	#}

	remove_character_flag = is_in_the_council
}

#####################################################################
# SPOUSE COUNCILLOR EFFECTS
#####################################################################

councillor_spouse_learning_2601_tutoring_effect = {
	$STUDENT$ = { save_scope_as = tutoring_student }
	scope:tutoring_student = {
		random_list = {
			20 = { #Critical success
				modifier = {
					has_education_rank_trigger = { RANK = 3 OPERATOR = equals }
					factor = 0.6
				}
				modifier = {
					has_education_rank_trigger = { RANK = 4 OPERATOR = equals }
					factor = 0.6
				}
				modifier = {
					root = { spouse_learning_tier_3_trigger = yes }
					factor = 1.5
				}
				desc = councillor_spouse_learning_2601_tutoring_effect.critical_success
				root = {
					send_interface_toast = {
						type = event_toast_effect_good
						title = councillor_spouse_learning_2601_tutoring_effect.critical_success
						left_icon = scope:tutoring_student
						right_icon = scope:councillor
						scope:tutoring_student = {
							rank_up_education_effect = yes
						}
					}	
					add_character_flag = {
						flag = had_councillor_spouse_learning_2601_event
						days = 7300
					}
				}

				hidden_effect = {
					if = {
						limit = { scope:councillor != scope:tutoring_student } #Since the effect can be used on yourself.
						scope:tutoring_student = {
							add_opinion = {
								target = scope:councillor
								modifier = grateful_opinion
								opinion = 15
							}
						}
					}
					scope:councillor = {
						if = {
							limit = { scope:tutoring_student = { has_trait = education_diplomacy } }
							add_character_modifier = {
								modifier = studying_diplomacy
								years = 10
							}
						}
						else_if = {
							limit = { scope:tutoring_student = { has_trait = education_martial } }
							add_character_modifier = {
								modifier = studying_martial
								years = 10
							}
						}
						else_if = {
							limit = { scope:tutoring_student = { has_trait = education_stewardship } }
							add_character_modifier = {
								modifier = studying_stewardship
								years = 10
							}
						}
						else_if = {
							limit = { scope:tutoring_student = { has_trait = education_intrigue } }
							add_character_modifier = {
								modifier = studying_intrigue
								years = 10
							}
						}
						else_if = {
							limit = { scope:tutoring_student = { has_trait = education_learning } }
							add_character_modifier = {
								modifier = studying_learning
								years = 10
							}
						}
						random_list = {
							1 = { set_nickname_effect = { NICKNAME = nick_the_scholar } }
							1 = { set_nickname_effect = { NICKNAME = nick_the_wise } }
							10 = { }
						}
					}
				}
			}
			55 = { #Success
				desc = councillor_spouse_learning_2601_tutoring_effect.success
				root = {
					send_interface_toast = {
						type = event_toast_effect_good
						title = councillor_spouse_learning_2601_tutoring_effect.success
						left_icon = scope:tutoring_student
						right_icon = scope:councillor
						scope:tutoring_student = {
							if = {
								limit = { has_trait = education_diplomacy }
								add_character_modifier = {
									modifier = studying_diplomacy
									years = 10
								}
							}
							else_if = {
								limit = { has_trait = education_martial }
								add_character_modifier = {
									modifier = studying_martial
									years = 10
								}
							}
							else_if = {
								limit = { has_trait = education_stewardship }
								add_character_modifier = {
									modifier = studying_stewardship
									years = 10
								}
							}
							else_if = {
								limit = { has_trait = education_intrigue }
								add_character_modifier = {
									modifier = studying_intrigue
									years = 10
								}
							}
							else_if = {
								limit = { has_trait = education_learning }
								add_character_modifier = {
									modifier = studying_learning
									years = 10
								}
							}
							add_character_flag = {
								flag = had_councillor_spouse_learning_2601_event
								days = 3650
							}
						}
					}
				}
				hidden_effect = {
					if = {
						limit = {
							scope:tutoring_student != scope:councillor #Since the effect can be used on yourself.
						}
						scope:tutoring_student = {
							add_opinion = {
								target = scope:councillor
								modifier = grateful_opinion
								opinion = 10
							}
						}
					}
				}
			}
		}
	}
}

councillor_spouse_learning_2603_scopes_for_portraits_support_effect = {
	if = {
		limit = { exists = scope:councillor_2 }
		save_scope_as = councillor_3
	}
	else_if = {
		limit = { exists = scope:councillor_1 }
		save_scope_as = councillor_2
	}
	else = {
		save_scope_as = councillor_1
	}
}

councillor_spouse_learning_2603_scopes_for_portraits_effect = {
	if = {
		limit = { is_ai = no }

		#Saves the (up to) 3 chosen chancellors for portraits. Set up like this to make sure the options and portraits are in the same order.
		if = {
			limit = { exists = scope:chancellor }
			scope:chancellor = { councillor_spouse_learning_2603_scopes_for_portraits_support_effect = yes }
		}
		if = {
			limit = { exists = scope:marshal }
			scope:marshal = { councillor_spouse_learning_2603_scopes_for_portraits_support_effect = yes }
		}
		if = {
			limit = { exists = scope:steward }
			scope:steward = { councillor_spouse_learning_2603_scopes_for_portraits_support_effect = yes }
		}
		if = {
			limit = { exists = scope:spymaster }
			scope:spymaster = { councillor_spouse_learning_2603_scopes_for_portraits_support_effect = yes }
		}
		if = {
			limit = { exists = scope:court_chaplain }
			scope:court_chaplain = { councillor_spouse_learning_2603_scopes_for_portraits_support_effect = yes }
		}
	}
}

councillor_spouse_learning_2603_scope_save_effect = {
	if = {
		limit = {
			any_normal_councillor = {
				councillor_spouse_learning_2603_valid_councillor_trigger = yes
				NOR = {
					AND = {
						exists = scope:chancellor
						this = scope:chancellor
					}
					AND = {
						exists = scope:marshal
						this = scope:marshal
					}
					AND = {
						exists = scope:steward
						this = scope:steward
					}
					AND = {
						exists = scope:spymaster
						this = scope:spymaster
					}
					AND = {
						exists = scope:court_chaplain
						this = scope:court_chaplain
					}
				}
			}
		}
		random_list = {
			1 = {
				trigger = {
					exists = cp:councillor_chancellor
					cp:councillor_chancellor = { councillor_spouse_learning_2603_valid_councillor_trigger = yes }
					NOT = { exists = scope:chancellor }
				}
				modifier = {
					cp:councillor_chancellor = { diplomacy <= mediocre_skill_rating }
					factor = 3
				}
				cp:councillor_chancellor = { save_scope_as = chancellor }
			}
			1 = {
				trigger = {
					exists = cp:councillor_marshal
					cp:councillor_marshal = { councillor_spouse_learning_2603_valid_councillor_trigger = yes }
					NOT = { exists = scope:marshal }
				}
				modifier = {
					cp:councillor_marshal = { martial <= mediocre_skill_rating }
					factor = 3
				}
				cp:councillor_marshal = { save_scope_as = marshal }
			}
			1 = {
				trigger = {
					exists = cp:councillor_steward
					cp:councillor_steward = { councillor_spouse_learning_2603_valid_councillor_trigger = yes }
					NOT = { exists = scope:steward }
				}
				modifier = {
					cp:councillor_steward = { stewardship <= mediocre_skill_rating }
					factor = 3
				}
				cp:councillor_steward = { save_scope_as = steward }
			}
			1 = {
				trigger = {
					exists = cp:councillor_spymaster
					cp:councillor_spymaster = { councillor_spouse_learning_2603_valid_councillor_trigger = yes }
					NOT = { exists = scope:spymaster }
				}
				modifier = {
					cp:councillor_spymaster = { intrigue <= mediocre_skill_rating }
					factor = 3
				}
				cp:councillor_spymaster = { save_scope_as = spymaster }
			}
			1 = {
				trigger = {
					exists = cp:councillor_court_chaplain
					cp:councillor_court_chaplain = { councillor_spouse_learning_2603_valid_councillor_trigger = yes }
					NOT = { exists = scope:court_chaplain }
				}
				modifier = {
					cp:councillor_court_chaplain = { learning <= mediocre_skill_rating }
					factor = 3
				}
				cp:councillor_court_chaplain = { save_scope_as = court_chaplain }
			}
		}
	}
}

councillor_spouse_learning_2603_chosen_councillor_effect = {
	if = {
		limit = {
			OR = {
				has_trait = humble
				has_trait = calm
				has_trait = diligent
				has_trait = trusting
				has_trait = compassionate
				has_trait = forgiving
				has_trait = content
			}
			NOT = {
				has_trait = arrogant
			}
		}
		add_opinion = {
			target = root
			modifier = grateful_opinion
			opinion = 15
		}
		hidden_effect = {
			add_opinion = {
				target = scope:councillor
				modifier = grateful_opinion
				opinion = 15
			}
		}
	}
	else = {
		add_opinion = {
			target = root
			modifier = insult_opinion
			opinion = -15
		}
	}
}

add_patronage_spouse_education_points_effect = {
	if = {
		limit = {
			exists = host.cp:councillor_spouse
		}
		host.cp:councillor_spouse = { save_scope_as = councillor }
		if = {
			limit ={
				spouse_learning_tier_1_trigger = yes
				has_education_focus_trigger = yes
				trigger_if = {
					limit = {
						has_variable = patronage_spouse_tutor
					}
					var:patronage_spouse_tutor = scope:councillor
				}
			}
			save_scope_as = patronage_student
			random = {
				chance = 7
				modifier = {
					add = 7 #14%
					host = { spouse_learning_tier_2_trigger = yes }
				}
				modifier = {
					add = 7 #21%
					host = { spouse_learning_tier_3_trigger = yes }
				}
				modifier = {
					NOR = {
						is_child_of = scope:councillor
						reverse_opinion = {
							target = scope:councillor
							value >= 25
						}
					}
					add = -5
				}
				modifier = {
					reverse_opinion = {
						target = scope:councillor
						value >= 50
					}
					add = 5
				}
				modifier = {
					NOT = { is_child_of = scope:councillor }
					any_parent = { is_spouse_of = scope:councillor }
					OR = {
						has_trait = bastard
						has_trait = legitimized_bastard
					}
					scope:councillor = {
						NOR = {
							ai_compassion >= high_positive_ai_value
							opinion = { target = scope:patronage_student value >= 50 }
						}
					}
					add = -20
				}

				if = {
					limit = {
						has_variable = patronage_spouse_tutor
						has_variable = patronage_spouse_tutor_points
					}
					change_variable = {
						name = patronage_spouse_tutor_points
						add = 1
					}
				}
				else = {
					set_variable = {
						name = patronage_spouse_tutor
						value = scope:councillor
						days = 5475
					}
					set_variable = {
						name = patronage_spouse_tutor_points
						value = 1
						days = 5475
					}
				}
				host = {
					save_scope_as = host
					if = {
						limit = {
							any_child = { this = scope:patronage_student }
						}			
						send_interface_message = {
							type = msg_spouse_patronage
							title = add_patronage_spouse_education_points_effect.t
							desc = add_patronage_spouse_education_points_child_effect.desc
							left_icon = scope:patronage_student
							right_icon = scope:councillor
						}
					}
					else_if = {
						limit = {
							player_heir ?= { this = scope:patronage_student }
						}
						send_interface_message = {
							type = msg_spouse_patronage
							title = add_patronage_spouse_education_points_effect.t
							desc = add_patronage_spouse_education_points_effect.desc
							left_icon = scope:patronage_student
							right_icon = scope:councillor
						}
					}
				}
			}
		}
	}
}

results_of_patronage_spouse_education_points_effect = {
	if = {
		limit = { has_variable = patronage_spouse_tutor }

		var:patronage_spouse_tutor = {
			save_scope_as = patronage_spouse_tutor
		}

		#Checks their current level
		if = {
			limit = { education_points_equals_education_rank = { RANK = 1 } }
			save_scope_value_as = {
				name = education_rank_before_patronage
				value = 1
			}
		}
		else_if = {
			limit = { education_points_equals_education_rank = { RANK = 2 } }
			save_scope_value_as = {
				name = education_rank_before_patronage
				value = 2
			}
		}
		else_if = {
			limit = { education_points_equals_education_rank = { RANK = 3 } }
			save_scope_value_as = {
				name = education_rank_before_patronage
				value = 3
			}
		}
		else_if = {
			limit = { education_points_equals_education_rank = { RANK = 4 } }
			save_scope_value_as = {
				name = education_rank_before_patronage
				value = 4
			}
		}
		#Adding the points to the current education
		if = {
			limit = { has_focus = education_diplomacy }
			change_variable = {
				name = education_diplomacy_variable
				add = var:patronage_spouse_tutor_points
			}
		}
		else_if = {
			limit = { has_focus = education_martial }
			change_variable = {
				name = education_martial_variable
				add = var:patronage_spouse_tutor_points
			}
		}
		else_if = {
			limit = { has_focus = education_stewardship }
			change_variable = {
				name = education_stewardship_variable
				add = var:patronage_spouse_tutor_points
			}
		}
		else_if = {
			limit = { has_focus = education_intrigue }
			change_variable = {
				name = education_intrigue_variable
				add = var:patronage_spouse_tutor_points
			}
		}
		else_if = {
			limit = { has_focus = education_learning }
			change_variable = {
				name = education_learning_variable
				add = var:patronage_spouse_tutor_points
			}
		}

		#Checks their new level
		if = {
			limit = { education_points_equals_education_rank = { RANK = 1 } }
			save_scope_value_as = {
				name = education_rank_after_patronage
				value = 1
			}
		}
		else_if = {
			limit = { education_points_equals_education_rank = { RANK = 2 } }
			save_scope_value_as = {
				name = education_rank_after_patronage
				value = 2
			}
		}
		else_if = {
			limit = { education_points_equals_education_rank = { RANK = 3 } }
			save_scope_value_as = {
				name = education_rank_after_patronage
				value = 3
			}
		}
		else_if = {
			limit = { education_points_equals_education_rank = { RANK = 4 } }
			save_scope_value_as = {
				name = education_rank_after_patronage
				value = 4
			}
		}

		#Sets flag for result
		if = {
			limit = {
				exists = scope:education_rank_before_patronage
				exists = scope:education_rank_after_patronage
			}
			if = {
				limit = { #+1
					OR = {
						AND = {
							scope:education_rank_before_patronage = 1
							scope:education_rank_after_patronage = 2
						}
						AND = {
							scope:education_rank_before_patronage = 2
							scope:education_rank_after_patronage = 3
						}
						AND = {
							scope:education_rank_before_patronage = 3
							scope:education_rank_after_patronage = 4
						}
					}
				}
				save_scope_value_as = {
					name = education_rank_patronage_bonus
					value = flag:1
				}
			}
			else_if = { #+2 or more
				limit = { scope:education_rank_after_patronage != scope:education_rank_before_patronage }
				save_scope_value_as = {
					name = education_rank_patronage_bonus
					value = flag:2_or_more
				}
			}
		}

		if = {
			limit = {
				exists = scope:education_rank_patronage_bonus
				scope:education_rank_patronage_bonus = flag:1
				scope:education_rank_patronage_bonus = flag:2_or_more
			}
		}

		if = {
			limit = {
				has_variable = patronage_spouse_tutor_points
			}
			remove_variable = patronage_spouse_tutor_points
		}
		#Got to keep the tutor var for now, but it is automatically cleared with time
	}
}

block_firing_councillor_effect = {
	set_variable = {
		name = block_fire_councillor
		value = $COURT_OWNER$
		years = council_position_locked_value
	}
}

block_hiring_councillor_effect = {
	set_variable = {
		name = block_hire_councillor
		value = $COURT_OWNER$
		years = council_position_locked_value
	}
}

unblock_firing_councillor_effect = {
	remove_variable = block_fire_councillor
}

councillor_leaving_effect = {
	if = {
		limit = {
			NOT = { is_councillor_of = scope:old_employer } 
			scope:old_employer = { government_allows = council }
		}
		scope:councillor = {
			# Councillor leaving because of marriage
			if = {
				limit = {
					is_playable_character = no
					is_married = yes
					primary_spouse = { is_playable_character = yes }
				}
				scope:old_employer = {
					send_interface_message = {
						type = msg_left_council_position
						title = councillor_leaving_court_message_title
						desc = councillor_leaving_court_marriage_notification
						left_icon = scope:councillor
						right_icon = scope:councillor.primary_spouse
					}
				}
			}
			# Councillor leaving because of title inheritance
			else_if = {
				limit = {
					is_playable_character = yes
					NOT = { is_vassal_of = scope:old_employer }
				}
				scope:old_employer = {
					send_interface_message = {
						type = msg_left_council_position
						title = councillor_leaving_court_message_title
						desc = councillor_leaving_court_landed_notification
						left_icon = scope:councillor
						right_icon = scope:councillor.primary_title
					}
				}
			}
			# Generic fallback
			else = {
				scope:old_employer = {
					send_interface_message = {
						type = msg_left_council_position
						title = councillor_leaving_court_message_title
						desc = councillor_leaving_court_generic_fallback_notification
						left_icon = scope:councillor
					}
				}
			}
		}
	}
}

councillor_increase_relevant_skill_effect = {
	switch = {
		trigger = has_council_position
		councillor_chancellor = { add_diplomacy_skill = 1 }
		councillor_court_chaplain = { add_learning_skill = 1 }
		councillor_marshal = { add_martial_skill = 1 }
		councillor_steward = { add_stewardship_skill = 1 }
		councillor_spymaster = { add_intrigue_skill = 1 }
		councillor_kurultai_1 = { add_martial_skill = 1 }
		councillor_kurultai_2 = { add_martial_skill = 1 }
		councillor_kurultai_3 = { add_martial_skill = 1 }
		councillor_kurultai_4 = { add_martial_skill = 1 }
	}
}

councillor_increase_relevant_skill_five_points_effect = {
	switch = {
		trigger = has_council_position
		councillor_chancellor = { add_diplomacy_skill = 5 }
		councillor_court_chaplain = { add_learning_skill = 5 }
		councillor_marshal = { add_martial_skill = 5 }
		councillor_steward = { add_stewardship_skill = 5 }
		councillor_spymaster = { add_intrigue_skill = 5 }
		councillor_kurultai_1 = { add_martial_skill = 5 }
		councillor_kurultai_2 = { add_martial_skill = 5 }
		councillor_kurultai_3 = { add_martial_skill = 5 }
		councillor_kurultai_4 = { add_martial_skill = 5 }
	}
}

councillor_increase_relevant_skill_two_points_effect = {
	switch = {
		trigger = has_council_position
		councillor_chancellor = { add_diplomacy_skill = 2 }
		councillor_court_chaplain = { add_learning_skill = 2 }
		councillor_marshal = { add_martial_skill = 2 }
		councillor_steward = { add_stewardship_skill = 2 }
		councillor_spymaster = { add_intrigue_skill = 2 }
		councillor_kurultai_1 = { add_martial_skill = 2 }
		councillor_kurultai_2 = { add_martial_skill = 2 }
		councillor_kurultai_3 = { add_martial_skill = 2 }
		councillor_kurultai_4 = { add_martial_skill = 2 }
	}
}

assign_appropriate_councillor_position_effect = {
	if = {
		limit = {
			$CHARACTER$ = { highest_skill = diplomacy }
		}
		if = {
			limit = { exists = cp:councillor_chancellor }
			fire_councillor = cp:councillor_chancellor
		}
		assign_councillor_type = {
			type = councillor_chancellor
			target = $CHARACTER$
		}
	}
	else_if = {
		limit = {
			$CHARACTER$ = { highest_skill = intrigue }
		}
		if = {
			limit = { exists = cp:councillor_spymaster }
			fire_councillor = cp:councillor_spymaster
		}
		assign_councillor_type = {
			type = councillor_spymaster
			target = $CHARACTER$
		}
	}
	else_if = {
		limit = {
			$CHARACTER$ = { highest_skill = stewardship }
		}
		if = {
			limit = { exists = cp:councillor_steward }
			fire_councillor = cp:councillor_steward
		}
		assign_councillor_type = {
			type = councillor_steward
			target = $CHARACTER$
		}
	}
	else_if = {
		limit = {
			$CHARACTER$ = { highest_skill = martial }
		}
		if = {
			limit = { exists = cp:councillor_marshal }
			fire_councillor = cp:councillor_marshal
		}
		assign_councillor_type = {
			type = councillor_marshal
			target = $CHARACTER$
		}
	}
	else_if = {
		limit = {
			$CHARACTER$ = { highest_skill = learning }
			faith = {
				has_doctrine = doctrine_theocracy_temporal
			}
		}
		if = {
			limit = { exists = cp:councillor_court_chaplain }
			fire_councillor = cp:councillor_court_chaplain
		}
		assign_councillor_type = {
			type = councillor_court_chaplain
			target = $CHARACTER$
		}
	}
	else = {
		if = {
			limit = { exists = cp:councillor_chancellor }
			fire_councillor = cp:councillor_chancellor
		}
		assign_councillor_type = { # Fallback, mostly for faiths that don't allow Chaplain appointment
			type = councillor_chancellor
			target = $CHARACTER$
		}
	}
}

make_councillor_kurultai_effect = {
	if = {
		limit = { # bruh
			is_kurultai_trigger = no
		}

		if = {
			limit = {
				can_be_kurultai_trigger = { 
					COURT_OWNER = root.liege_or_court_owner 
					CP1 = councillor_kurultai_2
					CP2 = councillor_kurultai_3
					CP3 = councillor_kurultai_4
				}
			}
			assign_councillor_type = {
				type = councillor_kurultai_1
				remove_existing_councillor = yes
				target = root
			}
		}
		else_if = {
			limit = {
				can_be_kurultai_trigger = { 
					COURT_OWNER = root.liege_or_court_owner 
					CP1 = councillor_kurultai_1
					CP2 = councillor_kurultai_3
					CP3 = councillor_kurultai_4
				}
			}
			assign_councillor_type = {
				type = councillor_kurultai_2
				remove_existing_councillor = yes
				target = root
			}
		}
		else_if = {
			limit = {
				can_be_kurultai_trigger = { 
					COURT_OWNER = root.liege_or_court_owner 
					CP1 = councillor_kurultai_1
					CP2 = councillor_kurultai_2
					CP3 = councillor_kurultai_4
				}
			}
			assign_councillor_type = {
				type = councillor_kurultai_3
				remove_existing_councillor = yes
				target = root
			}
		}
		else_if = {
			limit = {
				can_be_kurultai_trigger = { 
					COURT_OWNER = root.liege_or_court_owner 
					CP1 = councillor_kurultai_1
					CP2 = councillor_kurultai_2
					CP3 = councillor_kurultai_3
				}
			}
			assign_councillor_type = {
				type = councillor_kurultai_4
				remove_existing_councillor = yes
				target = root
			}
		}
	}
}

make_councillor_start_up_effect = {
	save_scope_as = new_councillor
	liege_or_court_owner = {
		if = {
			limit = {
				NOT = { exists = cp:councillor_kurultai_1 }
				scope:new_councillor = {
					can_be_kurultai_trigger = {
						COURT_OWNER = scope:new_councillor.liege_or_court_owner 
						CP1 = councillor_kurultai_2
						CP2 = councillor_kurultai_3
						CP3 = councillor_kurultai_4
					}
				}
			}
			assign_councillor_type = {
				type = councillor_kurultai_1
				remove_existing_councillor = yes
				target = scope:new_councillor
			}
		}
		else_if = {
			limit = {
				NOT = { exists = cp:councillor_kurultai_2 }
				scope:new_councillor = {
					can_be_kurultai_trigger = {
						COURT_OWNER = scope:new_councillor.liege_or_court_owner 
						CP1 = councillor_kurultai_1
						CP2 = councillor_kurultai_3
						CP3 = councillor_kurultai_4
					}
				}
			}
			assign_councillor_type = {
				type = councillor_kurultai_2
				remove_existing_councillor = yes
				target = scope:new_councillor
			}
		}
		else_if = {
			limit = {
				NOT = { exists = cp:councillor_kurultai_3 }
				scope:new_councillor = {
					can_be_kurultai_trigger = {
						COURT_OWNER = scope:new_councillor.liege_or_court_owner  
						CP1 = councillor_kurultai_1
						CP2 = councillor_kurultai_2
						CP3 = councillor_kurultai_4
					}
				}
			}
			assign_councillor_type = {
				type = councillor_kurultai_3
				remove_existing_councillor = yes
				target = scope:new_councillor
			}
		}
		else_if = {
			limit = {
				NOT = { exists = cp:councillor_kurultai_4 }
				scope:new_councillor = {
					can_be_kurultai_trigger = {
						COURT_OWNER = scope:new_councillor.liege_or_court_owner 
						CP1 = councillor_kurultai_1
						CP2 = councillor_kurultai_2
						CP3 = councillor_kurultai_3
					}
				}
			}
			assign_councillor_type = {
				type = councillor_kurultai_4
				remove_existing_councillor = yes
				target = scope:new_councillor
			}
		}
	}
}
