﻿eparch_court_position = {
	sort_order = 371
	max_available_positions = 1
	#AGOT Modified
	#minimum_rank = empire
	minimum_rank = kingdom
	skill = stewardship

	court_position_asset = {
		animation = reading
		background = "gfx/interface/illustrations/event_scenes/ep3_constantinople.dds"
	}

	opinion = {
		value = 20
	}

	aptitude_level_breakpoints = { 20 40 60 80 }

	aptitude = {
		value = 1
		# Skills
		add = {
			value = stewardship
			multiply = 1
			max = 50
			desc = court_position_skill_stewardship
		}
		add = {
			value = diplomacy
			multiply = 1
			max = 50
			desc = court_position_skill_diplomacy
		}
		
		# Lifestyle traits - 1 trait from each lifestyle
		if = {
			limit = { has_trait = diplomat }
			add = {
				value = 10
				desc = court_position_diplomat_trait
			}
		}
		if = {
			limit = { has_trait = overseer }
			add = {
				value = 10
				desc = court_position_overseer_trait
			}
		}
		if = {
			limit = { has_trait = administrator }
			add = {
				value = 10
				desc = court_position_administrator_trait
			}
		}
		if = {
			limit = { has_trait = schemer }
			add = {
				value = 10
				desc = court_position_schemer_trait
			}
		}
		if = {
			limit = { has_trait = scholar }
			add = {
				value = 10
				desc = court_position_scholar_trait
			}
		}
		
		# Personality traits
		if = {
			limit = { has_trait = diligent }
			add = {
				value = 5
				desc = court_position_diligent_trait
			}
		}
		if = {
			limit = { has_trait = just }
			add = {
				value = 5
				desc = court_position_just_trait
			}
		}
		if = {
			limit = { has_trait = stubborn }
			add = {
				value = 5
				desc = court_position_stubborn_trait
			}
		}
		if = {
			limit = { has_trait = fickle }
			add = {
				value = -5
				desc = court_position_fickle
			}
		}
		if = {
			limit = { has_trait = impatient }
			add = {
				value = -5
				desc = court_position_impatient_trait
			}
		}
		
		# Other traits
		if = {
			limit = {
				has_trait = education_republican_knowledge
			}
			add = {
				if = {
					limit = {
						has_trait = education_republican_knowledge_4
					}
					add = {
						value = 8
						desc = republican_knowledge_4_desc
					}
				}
				else_if = {
					limit = {
						has_trait = education_republican_knowledge_3
					}
					add = {
						value = 6
						desc = republican_knowledge_3_desc
					}
				}
				else_if = {
					limit = {
						has_trait = education_republican_knowledge_2
					}
					add = {
						value = 4
						desc = republican_knowledge_2_desc
					}
				}
				else = {
					add = {
						value = 2
						desc = republican_knowledge_1_desc
					}
				}
			}
		}
		
		# Admin specific bonuses
		# Influence level
		if = {
			limit = { influence_level >= 1 }
			add = {
				value = influence_level
				subtract = 1
				multiply = 5
				desc = "[influence_level|E]"
			}
		}
		
		# Powerful and dominant family
		if = {
			limit = {
				house ?= {
					is_powerful_family = yes
					NOT = { this = root.liege.house }
				}
			}
			add = {
				value = 8
				desc = is_powerful_family_desc
			}
		}
		if = {
			limit = {
				house ?= {
					is_dominant_family = yes
				}
			}
			add = {
				value = 12
				desc = is_dominant_family_desc
			}
		}
		
		# Governor trait
		if = {
			limit = {
				has_trait = governor
			}
			add = {
				value = 4
				if = {
					limit = {
						has_trait_xp = {
							trait = governor
							value >= 100
						}
					}
					add = 16
				}
				else_if = {
					limit = {
						has_trait_xp = {
							trait = governor
							value >= 75
						}
					}
					add = 12
				}
				else_if = {
					limit = {
						has_trait_xp = {
							trait = governor
							value >= 50
						}
					}
					add = 8
				}
				else_if = {
					limit = {
						has_trait_xp = {
							trait = governor
							value >= 25
						}
					}
					add = 4
				}
				desc = governor_trait_short_desc
			}
		}
		
		# Capital Bureau
		if = {
			limit = {
				liege ?= {
					capital_province ?= { has_building_or_higher = capital_bureau_01 }
				}
			}
			add = {
				value = 0
				liege ?= {
					capital_province = {
						if = {
							limit = {
								has_building_or_higher = capital_bureau_08
							}
							add = 16
						}
						else_if = {
							limit = {
								has_building_or_higher = capital_bureau_07
							}
							add = 14
						}
						else_if = {
							limit = {
								has_building_or_higher = capital_bureau_06
							}
							add = 12
						}
						else_if = {
							limit = {
								has_building_or_higher = capital_bureau_05
							}
							add = 10
						}
						else_if = {
							limit = {
								has_building_or_higher = capital_bureau_04
							}
							add = 8
						}
						else_if = {
							limit = {
								has_building_or_higher = capital_bureau_03
							}
							add = 6
						}
						else_if = {
							limit = {
								has_building_or_higher = capital_bureau_02
							}
							add = 4
						}
						else = {
							add = 2
						}
					}
				}
				desc = eparch_capital_bureau
			}
		}
		
		# Grain dole has been reinstituted and is active
		#AGOT Disabled
		#if = {
		#	limit = {
		#		liege ?= {
		#			capital_county ?= { has_county_modifier = panem_et_circenses_county_modifier }
		#		}
		#	}
		#	add = {
		#		value = 5
		#		desc = eparch_capital_has_grain_dole_desc
		#	}
		#}
		
		# Other
		add = court_position_aptitude_traveling_friends_value
		add = court_position_aptitude_eunuch_tradition_value
		add = court_position_aptitude_family_business_value
	}

	# Is this an available position for this court? (root is court owner)
	is_shown = {
		government_has_flag = government_is_administrative
		is_independent_ruler = yes
	}

	is_shown_character = {
		scope:employee = {
			court_position_employee_shown_trigger = yes
		}
	}

	valid_position = {
	}

	valid_character = {
		scope:employee = {
			liege = scope:liege # To ensure invalidation if they leave court
			
			OR = { # Is either unlanded (a courtier or landless family head) or a governor of a nearby theme
				is_landed = no
				custom_tooltip = {
					text = eparch_distance_trigger_desc
					capital_province ?= {
						squared_distance = {
							target = scope:liege.capital_province
							value < 50000
						}
					}
					government_allows = administrative
				}
			}
			# Eunuchs were historically not allowed to have this position
			NOT = { has_trait = eunuch }
		}
	}

	revoke_cost = {
		prestige = {
			value = major_court_position_prestige_revoke_cost
			# Set to 0 via obligation hook
			if = {
				limit = {
					court_position_obligation_hook_salary_trigger = {
						POS = eparch
						LIEGE = scope:liege
					}
				}
				multiply = 0
			}
			if = {
				limit = {
					exists = this
					is_ai = yes
				}
				multiply = 0
			}
		}
		influence = {
			value = major_influence_value
			if = {
				limit = {
					exists = this
					is_ai = yes
				}
				multiply = 0
			}
		}
	}

	salary = {
		gold = {
			value = 0
			if = {
				limit = {
					scope:liege = {
						has_treasury = no
				}
			}
				add = eparch_total_salary_value
			}
				}
		treasury = {
			value = 0
			if = {
				limit = {
					scope:liege = {
						has_treasury = yes
					}
				}
				add = eparch_total_salary_value
			}
		}
		round = no
	}

	received_salary = {
		gold = {
			value = eparch_total_salary_value
		}
		round = no
	}

	# Employeer bonuses
	base_employer_modifier = {
	}

	scaling_employer_modifiers = {
	}
	
	custom_scaling_employer_modifier_description = {
		terrible = eparch_terrible_desc
		poor = eparch_poor_desc
		average = eparch_average_desc
		good = eparch_good_desc
		excellent = eparch_excellent_desc
		range = eparch_range_desc
	}
	
	custom_employer_modifier_description = eparch_custom_effect_desc

	# Employee bonuses
	modifier = {
		monthly_prestige = 1
		monthly_influence_mult = 0.25
	}

	# Effects on received/revoked/invalidated
	on_court_position_received = {
		basic_gained_court_position_effect = yes
	}
	on_court_position_revoked = {
		basic_revoked_court_position_effect = yes
	}
	on_court_position_invalidated = {
		basic_invalidated_court_position_effect = yes
	}

	on_court_position_vacated = {
		court_position_vacated_event_epa_effect = {
			COURT_POSITION_TYPE = eparch_court_position
		}
	}

	# Scripted value to determine whether an AI will hire/fire a position or not. Hires over 0, fires under -50. Look in _court_positions.info for more extensive documentation!
	ai_position_score = {
		value = 100
		scope:liege = {
			# More likely if you have a lot of gold and can afford it
			if = {
				limit = {
					monthly_character_income > monthly_character_expenses_plus_fourty_percent
				}
				add = 50
			}
			
			# More likely if you are a builder
			if = {
				limit = {
					ai_has_economical_boom_personality = yes
				}
				add = 50
			}
		}
		add = court_position_debt_considerations_value
	}
	ai_candidate_score = {
		value = 100
		add = scope:base_value
		add = court_position_candidate_score_base_value
		add = court_position_candidate_aptitude_value
	}
}
