﻿# court_scholar_court_position

court_scholar_court_position = { # FP3
	sort_order = 231
	max_available_positions = 1
	minimum_rank = kingdom

	court_position_asset = {
		animation = page_flipping
		background = "gfx/interface/illustrations/event_scenes/tgp_relaxing_room_asia.dds"
	}

	opinion = {
		value = ceremonial_court_position_opinion
	}

	# How high the aptitude has to be to reach the 5 different modifier levels
	aptitude_level_breakpoints = { 20 40 60 80 }

	# How good is this character in this position? root scope is the holder of the court position
	aptitude = {
		value = 0
		add = court_position_aptitude_boon_voyager_trait
		add = {
			value = learning
			multiply = 4
			desc = court_position_skill_learning
			max = 65
		}
		if = {
			limit = {
				#AGOT Modified Check employer instead of scope:liege (Unop)
				# scope:liege.dynasty ?= { has_dynasty_perk = fp3_khvarenah_legacy_1 }
				employer ?= {
					dynasty ?= { has_dynasty_perk = fp3_khvarenah_legacy_1 }
				}
			}
			add = {
				value = 10
				desc =  court_position_khvarenah_legacy_1
			}
		}
		if = {
			limit = { has_trait = theologian }
			add = {
				value = 15
				desc = court_position_theologian_trait
			}
		}
		if = {
			limit = { has_trait = scholar }
			add = {
				value = 15
				desc = court_position_scholar_trait
			}
		}
		if = {
			limit = {
				has_trait = lifestyle_physician
				has_trait_xp = {
					trait = lifestyle_physician
					value >= 100
				}
			}
			add = {
				value = 15
				desc = court_position_physician_3_trait
			}
		}
		else_if = {
			limit = {
				has_trait = lifestyle_physician
				has_trait_xp = {
					trait = lifestyle_physician
					value >= 50
				}
			}
			add = {
				value = 10
				desc = court_position_physician_2_trait
			}
		}
		else_if = {
			limit = { has_trait = lifestyle_physician }
			add = {
				value = 5
				desc = court_position_physician_1_trait
			}
		}
		if = {
			limit = {
				has_trait = intellect_good_3
			}
			add = {
				value = 20
				desc = court_position_intellect_good_3_trait
			}
		}
		else_if = {
			limit = {
				has_trait = intellect_good_2
			}
			add = {
				value = 15
				desc = court_position_intellect_good_2_trait
			}
		}
		else_if = {
			limit = {
				has_trait = intellect_good_1
			}
			add = {
				value = 10
				desc = court_position_intellect_good_1_trait
			}
		}
		else_if = {
			limit = {
				has_trait = shrewd
			}
			add = {
				value = 10
				desc = court_position_shrewd_trait
			}
		}
		if = {
			limit = {
				# [ptxxx vb]
				# scope:liege doesn't exist here, check employer instead
				employer ?= {
					has_innovation = fp3_innovation_mural_sextant
				}
				# [/ptxxx vb]
			}
			add = {
				value = 10
				desc = court_position_innovation_mural_sextant
			}
		}
		#AGOT Added
		if = {
			limit = {
				has_trait = inquisitive
			}
			add = {
				value = 10
				desc = court_position_inquistive_trait
			}
		}
		add = court_position_aptitude_traveling_friends_value
		add = court_position_aptitude_eunuch_tradition_value
		add = court_position_aptitude_family_business_value
		add = court_position_aptitude_low_penalty_value
		# Bonus from court.8311
		if = {
			limit = { var:bonus_aptitude_role ?= flag:court_scholar }
			add = {
				value = cp_bonus_aptitude_value
				desc = cp_bonus_aptitude
			}
		}
		# Seneschal
		if = {
			limit = {
				liege.court_position:seneschal_court_position ?= {
					has_variable = performing_improve_court
				}
			}
			add = {
				value = liege.court_position:seneschal_court_position.seneschal_improve_court_value
				desc = seneschal_improve_court_aptitude_desc
			}
		}
		# Yeke Jarquchi
		if = {
			limit = {
				liege.court_position:yeke_jarquchi_court_position ?= {
					has_variable = performing_improve_court
				}
			}
			add = {
				value = liege.court_position:yeke_jarquchi_court_position.yeke_jarquchi_improve_court_value
				desc = yeke_jarquchi_improve_court_aptitude_desc
			}
		}
	}

	is_shown = {
		is_landed_or_landless_administrative = yes
		has_fp3_dlc_trigger = yes
		trigger_if = {
			limit = {
				is_ai = yes
				highest_held_title_tier <= tier_county
			}
			always = no
		}
	}

	# Only Kingdoms+ can attract prominent enough scholars
	valid_position = {
		is_landed_or_landless_administrative = yes
		highest_held_title_tier >= tier_kingdom
		# [mtxxx]
		culture = {
			or = {
				has_cultural_tradition = tradition_fp3_beacon_of_learning
				has_cultural_tradition = tradition_ptolemy_patronage
			}
		}
		# [/mtxxx]
	}

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

	valid_character = {
		scope:employee = {
			court_scholar_validity_trigger = { EMPLOYER = scope:liege }
		}
	}

	revoke_cost = { # root is the liege, no other scopes are passed here!
		prestige =  {
			value = major_court_position_prestige_revoke_cost
			# Set to 0 via obligation hook
			if = {
				limit = {
					court_position_obligation_hook_salary_trigger = {
						POS = court_scholar
						LIEGE = root
					}
				}
				multiply = 0
			}
			# Avoid AI prestige issues
			if = {
				limit = {
					exists = this
					is_ai = yes
				}
				multiply = 0
			}
			# Special case for events
			if = {
				limit = {
					exists = this
					has_character_flag = free_revoke_cost
				}
				multiply = 0
			}
			#Lowering for LAAMPS, to match Camp Officer revoke cost
			if = {
				limit = {
					exists = this
					#AGOT Modified
					#government_has_flag = government_is_landless_adventurer
					OR = {
						government_has_flag = government_is_landless_adventurer
						agot_is_landless_character = yes
					}
				}
				value = minor_court_position_prestige_revoke_cost
			}
		}
	}

	salary = {
		gold = {
					value = 0
			if = {
				limit = {
					scope:liege = {
						has_treasury = no
				}
				}
				add = court_scholar_total_salary_value
			}
				}
		treasury = {
			value = 0
			if = {
				limit = { 
					scope:liege = {
						has_treasury = yes
				}
				}
				add = court_scholar_total_salary_value
			}
		}
		prestige = {
			value = court_scholar_prestige_salary_value
				}
		round = no
			}
	received_salary = {
		gold = {
			value = court_scholar_total_salary_value
					}
		prestige = {
			value = court_scholar_prestige_salary_value
				}
		round = no
	}

	# These modifiers are employed based on what level the aptitude reaches (levels are defined as breakpoints)
	scaling_employer_modifiers = {
		terrible = {
			cultural_head_fascination_mult = 0.02
		}
		poor = {
			cultural_head_fascination_mult = 0.04
		}
		average = {
			learning = 1
			cultural_head_fascination_mult = 0.06
		}
		good = {
			learning = 2
			cultural_head_fascination_mult = 0.08
		}
		excellent = {
			learning = 3
			cultural_head_fascination_mult = 0.10
		}
	}

	# custom_employer_modifier_description = court_scholar_employer_custom_effect_description

	base_employer_modifier = {
	}

	modifier = {
		general_opinion = 5
		monthly_learning_lifestyle_xp_gain_mult = 0.2
	}

	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_effect = {
			COURT_POSITION_TYPE = court_scholar_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 = 50
		scope:liege = {
			if = {
				limit = { has_trait = scholar }
				add = 25
			}
			if = {
				limit = { has_education_learning_trigger = yes }
				add = 50
			}
			if = {
				limit = {
					has_lifestyle = learning_lifestyle
				}
				add = 100
			}
		}
		add = court_position_debt_considerations_value
	}
	ai_candidate_score = {
		value = 50
		add = scope:base_value
		add = court_position_candidate_score_base_value
		add = court_position_candidate_aptitude_value
		if = {
			limit = {
				exists = scope:firing_court_position
			}
			add = 100
			scope:employee = {
				# Does the liege have a better candidate that they should be hiring instead?
				if = {
					limit = {
						scope:highest_available_aptitude > scope:employee_aptitude
					}
					add = -75
 				}
			}
		}
		if = { # To stop petitioned positions immediately being fired by the AI
			limit = {
				court_position_petition_ai_weight_trigger = { ROLE = court_scholar }
			}
			add = 1000
		}
	}
}
