﻿
# Have a look at _court_positions.info for documentation

# COURT POSITIONS
# antiquarian_court_position
# court_artificer_court_position

antiquarian_court_position = {
	sort_order = 350
	max_available_positions = 1
	skill = learning

	court_position_asset = {
		animation = throne_room_one_handed_passive_3
		background = "gfx/interface/illustrations/event_scenes/armory.dds"
	}

	opinion = {
		value = regular_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 = 1
		add = court_position_aptitude_boon_voyager_trait
		if = {
			limit = {
				employer ?= {
					government_has_flag = government_is_landless_adventurer
					has_perk = soon_forgiven_perk
				}
			}
			add = {
				value = 10
				desc = court_position_soon_forgiven_perk
			}
		}
		if = {
			limit = {
				employer ?= {
					government_has_flag = government_is_landless_adventurer
					has_perk = positions_of_power_perk
				}
				any_relation = { type = friend }
			}
			add = {
				value = 5
				desc = court_position_positions_of_power_perk_friend
			}
		}
		if = {
			limit = {
				employer ?= {
					government_has_flag = government_is_landless_adventurer
					has_perk = positions_of_power_perk
				}
				any_relation = { type = lover }
			}
			add = {
				value = 5
				desc = court_position_positions_of_power_perk_lover
			}
		}
		if = {
			limit = {
				employer ?= {
					government_has_flag = government_is_landless_adventurer
					has_perk = positions_of_power_perk
				}
				is_married = yes
			}
			add = {
				value = 10
				desc = court_position_positions_of_power_perk_marriage
			}
		}
		if = {
			limit = {
				employer ?= {
					government_has_flag = government_is_landless_adventurer
					has_perk = likable_perk
					has_relation_best_friend = prev
				}
			}
			add = {
				value = 30
				desc = court_position_best_friend
			}
		}
		else_if = {
			limit = {
				employer ?= {
					government_has_flag = government_is_landless_adventurer
					has_perk = likable_perk
					has_relation_friend = prev
				}
			}
			add = {
				value = 15
				desc = court_position_friend
			}
		}
		add = {
			value = learning
			multiply = 2.5
			max = 60
			desc = court_position_skill_learning
		}
		if = { # Characters with a completed inspiration are very good Antiquarians
			limit = {
				has_completed_inspiration = yes
			}
			add = {
				value = 30
				desc = court_position_completed_inspiration
			}
		}
		if = {
			limit = {
				has_inspirational_lifestyle_trait_trigger = yes
			}
			add = {
				value = 10
				desc = court_position_inspirational_trait
			}
		}
		if = { # Shy characters are likely to spend more time with the artifacts than other people
			limit = {
				has_trait = shy
			}
			add = {
				value = 15
				desc = court_position_shy_trait
			}
		}
		if = {
			limit = {
				has_trait = diligent
			}
			add = {
				value = 15
				desc = court_position_diligent_trait
			}
		}
		if = {
			limit = {
				has_trait = administrator
			}
			add = {
				value = 15
				desc = court_position_administrator_trait
			}
		}
		if = {
			limit = { has_trait = overseer }
			add = {
				value = 15
				desc = court_position_overseer_trait
			}
		}
		if = {
			limit = {
				is_alive = yes
				has_variable = fund_inspiration_6508_architect_improvement
			}
			add = {
				value = 5
				desc = court_position_architect_study_experience
			}
		}
		if = {
			limit = {
				liege ?= {
					domicile ?= { has_domicile_parameter = estate_increase_antiquarian_aptitude }
				}
			}
			add = {
				value = estate_increase_antiquarian_aptitude_value
				desc = estate_increase_antiquarian_aptitude_desc
			}
		}
		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:antiquarian }
			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
			}
		}
	}

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

	# Is this an available position for this court? (root is court owner)
	valid_position = {
		is_landed_or_landless_administrative = yes
		trigger_if = {
			limit = {
				is_ai = yes
			}
			has_any_artifact = yes
		}
	}

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

	valid_character = {
		scope:employee = {
			antiquarian_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 = antiquarian
						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
					government_has_flag = government_is_landless_adventurer
				}
				value = minor_court_position_prestige_revoke_cost
			}
		}
	}

	salary = {
		round = no
		gold = {
			value = court_position_antiquarian_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 = antiquarian } }
				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 = antiquarian
						LIEGE = scope:liege
					}
				}
				multiply = {
					value = 0.5
					desc = obligation_hook_salary
					format = "BASE_VALUE_FORMAT_DECIMALS_MINUS_POSITIVE"
				}
			}
			# Halved salary
			if = {
				limit = {
					court_position_halved_salary_trigger = { POS = antiquarian }
				}
				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 = antiquarian }
				}
				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"
				}
			}
		}
	}

	# These modifiers are employed based on what level the aptitude reaches (levels are defined as breakpoints)
	scaling_employer_modifiers = {
		terrible = {
			artifact_decay_reduction_mult = -0.07
		}
		poor = {
			artifact_decay_reduction_mult = -0.11
		}
		average = {
			artifact_decay_reduction_mult = -0.17
		}
		good = {
			artifact_decay_reduction_mult = -0.25
		}
		excellent = {
			artifact_decay_reduction_mult = -0.35
		}
	}

	custom_employer_modifier_description = antiquarian_employer_custom_effect_description

	modifier = {
		stewardship = 2
		artifact_decay_reduction_mult = -0.2
	}

	on_court_position_received = {
		antiquarian_title_accepted_effect = yes
	}
	on_court_position_revoked = {
		antiquarian_title_revoked_effect = yes
	}
	on_court_position_invalidated = {
		antiquarian_title_invalidated_effect = yes
	}
	on_court_position_vacated = {
		court_position_vacated_event_effect = {
			COURT_POSITION_TYPE = antiquarian_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!
	candidate_score = {
		value = 50
		add = scope:base_value
		add = court_position_candidate_score_base_value
		add = court_position_candidate_aptitude_value
		if = {
			limit = {
				scope:liege = {
					government_allows = administrative
				}
			}
			add = 150
		}
		if = {
			limit = {
				scope:liege = {
					highest_held_title_tier >= tier_duchy
				}
			}
			add = 50
		}
		if = {
			limit = {
				scope:liege = {
					highest_held_title_tier >= tier_kingdom
				}
			}
			add = 50
		}
        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 = antiquarian }
			}
			add = 1000
		}
		add = court_position_debt_considerations_value
	}
}

court_artificer_court_position = { # EP1
	sort_order = 130
	max_available_positions = 3
	minimum_rank = kingdom
	skill = learning

	court_position_asset = {
		trigger = {
			is_independent_ruler = yes
			highest_held_title_tier >= tier_empire
			government_has_flag = government_is_celestial
		}
		animation = page_flipping
		background = "gfx/interface/illustrations/event_scenes/tgp_study_asia.dds"
		localization_key = court_artificer_celestial_imperial
	}

	court_position_asset = {
		trigger = {
			is_independent_ruler = no
			highest_held_title_tier <= tier_empire
			government_has_flag = government_is_celestial
		}
		animation = page_flipping
		background = "gfx/interface/illustrations/event_scenes/tgp_study_asia.dds"
		localization_key = court_artificer_celestial
	}

	court_position_asset = {
		trigger = {
			culture = { has_cultural_pillar = heritage_japonic }
		}
		animation = page_flipping
		background = "gfx/interface/illustrations/event_scenes/tgp_study_japan.dds"
	}

	court_position_asset = {
		trigger = { culture_has_east_asian_heritage_pillar_trigger = yes }
		animation = page_flipping
		background = "gfx/interface/illustrations/event_scenes/tgp_study_asia.dds"
	}

	court_position_asset = {
		trigger = {
			OR = {
				culture_has_south_asian_heritage_pillar_trigger = yes
				culture_has_mena_heritage_pillar_trigger = yes
			}
		}
		animation = page_flipping
		background = "gfx/interface/illustrations/event_scenes/bp2_study_indian.dds"
	}

	court_position_asset = {
		trigger = { culture_has_south_european_heritage_pillar_trigger = yes }
		animation = page_flipping
		background = "gfx/interface/illustrations/event_scenes/ep3_medi_study.dds"
	}

	court_position_asset = {
		animation = page_flipping
		background = "gfx/interface/illustrations/event_scenes/study.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 = 1
		add = court_position_aptitude_boon_voyager_trait
		add = {
			value = prowess
			desc = court_position_skill_intrigue
		}
		add = {
			value = diplomacy
			desc = court_position_skill_diplomacy
		}
		add = {
			value = intrigue
			desc = court_position_skill_intrigue
		}
		add = {
			value = learning
			desc = court_position_skill_learning
		}
		add = {
			value = martial
			desc = court_position_skill_martial
		}
		add = {
			value = stewardship
			desc = court_position_skill_stewardship
		}
		if = {
			limit = {
				has_character_modifier = local_artisan_modifier
			}
			add = {
				value = -20
				desc = local_artisan_modifier
			}
		}
		if = {
			limit = {
				has_inspirational_lifestyle_trait_trigger = yes
			}
			add = {
				value = 10
				desc = court_position_inspirational_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_high_penalty_value
		# Bonus from court.8311
		if = {
			limit = { var:bonus_aptitude_role ?= flag:court_artificer }
			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_ep1_court_positions_dlc_trigger = yes
		NOT = { government_has_flag = government_is_nomadic }
		trigger_if = {
			limit = {
				is_ai = yes
				highest_held_title_tier <= tier_county
			}
			always = no
		}
	}

	valid_position = {
		is_landed_or_landless_administrative = yes
		has_royal_court = yes
	}

	is_shown_character = {
		scope:employee = {
			OR = {
				has_completed_inspiration = yes
				custom_tooltip = {
					text = has_an_inspiration
					exists = inspiration
				}
				has_inspirational_lifestyle_trait_trigger = yes
			}
			court_position_employee_shown_trigger = yes
		}
	}

	valid_character = {
		valid_camp_officer_trigger = {
			OFFICER = court_artificer
		}
	}

	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_artificer
						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
					government_has_flag = government_is_landless_adventurer
				}
				value = minor_court_position_prestige_revoke_cost
			}
		}
	}

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

	received_salary = {
		gold = {
			value = court_artificer_total_salary_value
		}
		prestige = {
			value = court_artificer_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 = {
			court_grandeur_baseline_add = 0
		}
		poor = {
			court_grandeur_baseline_add = 1
		}
		average = {
			court_grandeur_baseline_add = 1
		}
		good = {
			court_grandeur_baseline_add = 2
		}
		excellent = {
			court_grandeur_baseline_add = 2
		}
	}

	custom_employer_modifier_description = court_artificer_employer_custom_effect_description

	modifier = {
		monthly_learning_lifestyle_xp_gain_mult = 0.1
		artifact_decay_reduction_mult = -0.2
	}

	on_court_position_received = {
		basic_gained_court_position_effect = yes
	}
	on_court_position_revoked = {
		basic_revoked_court_position_effect = yes
		scope:employee = {
			# Moves to pool after 1 day
			# Moving them directly here would invalidate the court position too early
			trigger_event = {
				id = courtier_guest_management.0999
				days = 1
			}
		}
	}
	on_court_position_invalidated = {
		basic_invalidated_court_position_effect = yes
	}
	on_court_position_vacated = {
		court_position_vacated_event_effect = {
			COURT_POSITION_TYPE = court_artificer_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 = {
			# Unless you have lots of gold to spend, there's no point
			if = {
				limit = {
					short_term_gold < 500
					monthly_character_income < monthly_character_expenses_plus_fourty_percent
				}
				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 = { # To stop petitioned positions immediately being fired by the AI
			limit = {
				court_position_petition_ai_weight_trigger = { ROLE = court_artificer }
			}
			add = 1000
		}
	}
}