﻿dinn_connection_court_position = {
	sort_order = 21
	max_available_positions = 1
	minimum_rank = county
	skill = intrigue

	court_position_asset = {
		animation = scheme
		background = "gfx/interface/illustrations/event_scenes/deviantorgyroombackground.dds"
	}

	opinion = {
		value = 20
	}

	aptitude_level_breakpoints = { 20 40 60 80 }

	aptitude = {
		value = 1
		# Skills
		add = {
			value = intrigue
			multiply = 1
			max = 50
			desc = court_position_skill_intrigue
		}
		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 = lustful }
			add = {
				value = 5
				desc = court_position_lustful_trait
			}
		}
		if = {
			limit = { has_trait = sadistic }
			add = {
				value = 5
				desc = court_position_sadistic_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
			}
		}
		if = {
			limit = { has_trait = chaste }
			add = {
				value = -5
				desc = court_position_chaste_trait
			}
		}
		if = {
			limit = { has_trait = shy }
			add = {
				value = -5
				desc = court_position_shy_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
			}
		}
		
		# Other
		add = court_position_aptitude_traveling_friends_value
		add = court_position_aptitude_family_business_value
	}

	# Is this an available position for this court? (root is court owner)
	is_shown = {
		has_trait = lustful_inn_slut
	}

	is_shown_character = {
		scope:employee = {
			is_imprisoned = no
		}
	}

	valid_position = {
	}

	valid_character = {
		scope:employee = {
			has_trait = deviant_patron_of_inns
			liege = scope:liege # To ensure invalidation if they leave court
			# 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 = {
					exists = this
					is_ai = yes
				}
				multiply = 0
			}
		}
	}

	salary = {
		round = no
		gold = {
			value = medium_court_position_salary # Update X_salary_tooltip if script_value is changed
			# Set to 0 with Dynasty Perk Inner Circle
			if = {
				limit = { court_position_inner_circle_salary_trigger = { POS = dinn_connection } }
				multiply = {
					value = 0
					desc = inner_circle_salary_mod
					format = "BASE_VALUE_FORMAT_DECIMALS_MINUS_POSITIVE"
				}
			}
			# Halved with obligation hook
			else_if = {
				limit = {
					court_position_obligation_hook_salary_trigger = {
						POS = dinn_connection
						LIEGE = scope:liege
					}
				}
				multiply = {
					value = 0.5
					desc = obligation_hook_salary
				}
			}
			# Halved salary
			if = {
				limit = {
					court_position_halved_salary_trigger = { POS = dinn_connection }
				}
				multiply = {
					value = 0.5
					desc = court_position_halved_salary
					format = "BASE_VALUE_FORMAT_DECIMALS_MINUS_POSITIVE"
				}
			}
			# Increased salary
			if = {
				limit = {
					court_position_increased_salary_trigger = { POS = dinn_connection }
				}
				multiply = {
					value = 1.5
					desc = court_position_increased_salary
					format = "BASE_VALUE_FORMAT_DECIMALS_MINUS_POSITIVE"
				}
			}
			#You're working with LAAMPS now
			if = {
				limit = { 
					scope:liege ?= { government_has_flag = government_is_landless_adventurer }
				}
				multiply = {
					value = 0
					desc = court_position_laamps_free
					format = "BASE_VALUE_FORMAT_DECIMALS_MINUS_POSITIVE"
				}
			}
		}
	}

	# Employeer bonuses
	base_employer_modifier = {
	}

	scaling_employer_modifiers = {
	}
	
	custom_employer_modifier_description = dinn_connection_effect_desc

	# Employee bonuses
	modifier = {
		monthly_prestige = 0.1
		intrigue = 1
		diplomacy = 1
	}

	# 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
	}

	# 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
		add = scope:base_value
		add = court_position_candidate_score_base_value
		add = court_position_candidate_aptitude_value
		add = court_position_debt_considerations_value
		
		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
			}
		}
	}
}