﻿
journey_knowledge_hoarding_skill_effect = {
	scope:activity = {
		if = {
			limit = { has_variable = skill_chance }
			change_variable = {
				name = skill_chance
				add = $VALUE$
			}
		}
		else = {
			set_variable = {
				name = skill_chance
				value = $VALUE$
			}
		}
		if = {
			limit = {
				$VALUE$ == 25
			}
			custom_tooltip = increase_skill_chance_25
		}
		if = {
			limit = {
				$VALUE$ == 20
			}
			custom_tooltip = increase_skill_chance_20
		}
		else_if = {
			limit = {
				$VALUE$ == 15
			}
			custom_tooltip = increase_skill_chance_15
		}
		else_if = {
			limit = {
				$VALUE$ == 10
			}
			custom_tooltip = increase_skill_chance_10
		}
		else_if = {
			limit = {
				$VALUE$ == 5
			}
			custom_tooltip = increase_skill_chance_5
		}
		else_if = {
			limit = {
				$VALUE$ == 30
			}
			custom_tooltip = increase_skill_chance_30
		}
		else_if = {
			limit = {
				$VALUE$ == 35
			}
			custom_tooltip = increase_skill_chance_35
		}
		else_if = {
			limit = {
				$VALUE$ == 50
			}
			custom_tooltip = increase_skill_chance_50
		}
		else_if = {
			limit = {
				$VALUE$ == 2
			}
			custom_tooltip = increase_skill_chance_2
		}
		if = {
			limit = {
				has_variable = skill_chance
				var:skill_chance > 100
			}
			set_variable = {
				name = skill_chance
				value = 100
			}
		}
	}
}

journey_find_or_create_excellent_court_position_effect = {
	#if = {
	#	limit = {
	#		any_pool_character = {
	#			province = $LOCATION$
	#			culture = $LOCATION$.culture
	#			aptitude = {
	#				court_position = $COURT_POSITION$
	#				value >= 4
	#			}
	#			is_available_healthy_ai_adult = yes
	#			$COURT_POSITION$_validity_trigger = { EMPLOYER = root }
	#		}
	#	}
	#	random_pool_character = {
	#		province = $LOCATION$
	#		limit = {
	#			culture = $LOCATION$.culture
	#			aptitude = {
	#				court_position = $COURT_POSITION$
	#				value >= 4
	#			}
	#			is_available_healthy_ai_adult = yes
	#			$COURT_POSITION$_validity_trigger = { EMPLOYER = root }
	#		}
	#		save_scope_as = local_character
	#	}
	#}
	#else = {
		create_character = {
			template = $COURT_POSITION$_template
			location = $LOCATION$
			culture = $LOCATION$.culture
			faith = $LOCATION$.faith
			save_scope_as = local_character
		}
		scope:local_character = {
			add_character_flag = {
				flag = silently_disappear_me
				years = 1
			}
		}
	#}
	if = {
		limit = {
			any_court_position_holder = {
				type = $COURT_POSITION$
			}
		}
		random_court_position_holder = {
			type = $COURT_POSITION$
			save_scope_as = current_holder
		}
	}
	add_character_flag = $COURT_POSITION$
}

journey_employ_in_court_position = {
	show_as_tooltip = {
		if = {
			limit = {
				is_valid_to_hire_court_position_type = $COURT_POSITION$_court_position
			}
			appoint_court_position = {
				recipient = $CHARACTER$
				court_position = $COURT_POSITION$_court_position
			}
		}
	}
	custom_tooltip = will_have_excellent_aptitude
	
	hidden_effect = {
		$CHARACTER$ = {
			add_to_court_and_entourage_effect = yes
		}
	}
	
	if = {
		limit = {
			is_valid_to_hire_court_position_type = $COURT_POSITION$_court_position
			NOT = { exists = scope:current_holder }
		}
		employ_character_as_position_in_current_scope_court_effect = {
			CHARACTER = $CHARACTER$
			POSITION = $COURT_POSITION$
		}
	}
	else_if = {
		limit = {
			exists = scope:current_holder
			scope:local_character.aptitude:$COURT_POSITION$_court_position > scope:current_holder.aptitude:$COURT_POSITION$_court_position
		}
		replace_court_position = {
			recipient = $CHARACTER$
			holder = scope:current_holder
			court_position = $COURT_POSITION$_court_position
		}
	}
}

journey_employ_in_camp_position = {
	show_as_tooltip = {
		if = {
			limit = {
				is_valid_to_hire_court_position_type = $COURT_POSITION$_camp_officer
			}
			appoint_court_position = {
				recipient = $CHARACTER$
				court_position = $COURT_POSITION$_camp_officer
			}
		}
	}
	custom_tooltip = will_have_excellent_aptitude
	
	hidden_effect = {
		$CHARACTER$ = {
			add_to_court_and_entourage_effect = yes
		}
	}
	
	if = {
		limit = {
			is_valid_to_hire_court_position_type = $COURT_POSITION$_camp_officer
			NOT = { exists = scope:current_holder }
		}
		employ_character_as_position_in_current_scope_camp_effect = {
			CHARACTER = $CHARACTER$
			POSITION = $COURT_POSITION$
		}
	}
	else_if = {
		limit = {
			exists = scope:current_holder
			scope:local_character.aptitude:$COURT_POSITION$_camp_officer > scope:current_holder.aptitude:$COURT_POSITION$_camp_officer
		}
		replace_court_position = {
			recipient = $CHARACTER$
			holder = scope:current_holder
			court_position = $COURT_POSITION$_camp_officer
		}
	}
}
