﻿master_of_raids_court_position = {
	sort_order = 251
	max_available_positions = 1
	minimum_rank = county
	skill = intrigue

	court_position_asset = {
		animation = throne_room_two_handed_passive_1
		background = "gfx/interface/illustrations/event_scenes/courtyard.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 = intrigue
			multiply = 1.5
			max = 50
			desc = court_position_skill_martial
		}
		add = {
			value = martial
			multiply = 1.5
			max = 50
			desc = court_position_skill_martial
		}
		add = {
			value = prowess
			multiply = 1.5
			max = 50
			desc = court_position_skill_prowess
		}
		if = {
			limit = {
				has_trait = reaver
			}
			add = {
				value = 30
				desc = court_position_reaver_trait
			}
		}
		if = {
			limit = {
				has_trait = greedy
			}
			add = {
				value = 10
				desc = court_position_greedy_trait
			}
		}
		if = {
			limit = {
				has_trait = brave
			}
			add = {
				value = 10
				desc = court_position_brave_trait
			}
		}
		if = {
			limit = {
				has_trait = sadistic
			}
			add = {
				value = 15
				desc = court_position_sadistic_trait
			}
		}
		if = {
			limit = {
				has_trait = torturer
			}
			add = {
				value = 15
				desc = court_position_torturer_trait
			}
		}
		if = {
			limit = {
				has_trait = callous
			}
			add = {
				value = 15
				desc = court_position_callous_trait
			}
		}
		if = {
			limit = {
				has_trait = lifestyle_reveler
			}
			add = {
				value = 10
				desc = court_position_reveler_1_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:master_of_horse }
			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
		highest_held_title_tier >= 2
	}

	# Is this an available position for this court? (root is court owner)
	valid_position = {
		is_landed_or_landless_administrative = yes
		OR = {
			government_has_flag = government_is_feudal
			government_has_flag = government_is_clan
			government_has_flag = government_is_administrative
			government_has_flag = government_is_japan_feudal
		}
		highest_held_title_tier >= 2
	}

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

	valid_character = {
		scope:employee = {
			master_of_horse_validity_trigger = { EMPLOYER = scope:liege }
			is_ruler = no
			age >= 21
			is_clergy = no
			NOT = { has_trait = compassionate }
			NOT = { has_trait = craven }
		}
	}

	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 = master_of_horse
						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 = minor_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 = master_of_horse } }
				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 = master_of_horse
						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 = master_of_horse }
				}
				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 = master_of_horse }
				}
				multiply = {
					value = 1.5
					desc = court_position_increased_salary
					format = "BASE_VALUE_FORMAT_DECIMALS_MINUS_POSITIVE"
				}
			}
			if = {
				limit = {
					scope:liege = {
						employs_court_position = master_of_horse_court_position
						any_court_position_holder = {
					        type = master_of_horse_court_position
					        has_character_flag = free_master_of_horse
						}
					}
				}
				multiply = {
					value = 0
					desc = free_court_position
				}
			}
			#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"
				}
			}
		}
		prestige = {
			value = medium_court_position_prestige_salary # Update X_salary_tooltip if script_value is changed
			multiply = 2
			# Set to 0 with Dynasty Perk Inner Circle
			if = {
				limit = { court_position_inner_circle_salary_trigger = { POS = master_of_horse } }
				multiply = {
					value = 0
					desc = inner_circle_salary_mod
					format = "BASE_VALUE_FORMAT_DECIMALS_MINUS_POSITIVE"
				}
			}
			# Halved via obligation hook
			else_if = {
				limit = {
					court_position_obligation_hook_salary_trigger = {
						POS = master_of_horse
						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 = master_of_horse }
				}
				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 = master_of_horse }
				}
				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"
				}
			}
		}
	}

	custom_employer_modifier_description = gpt_master_of_raids_employer_custom_effect_description

	# These modifiers are employed based on what level the aptitude reaches (levels are defined as breakpoints)
	scaling_employer_modifiers = {
		terrible = {
			monthly_war_income_mult = 0.02
			independent_ruler_opinion = -5
			fellow_vassal_opinion = -5
		}
		poor = {
			monthly_war_income_mult = 0.04
			independent_ruler_opinion = -5
			fellow_vassal_opinion = -5
		}
		average = {
			monthly_war_income_mult = 0.06
			independent_ruler_opinion = -5
			fellow_vassal_opinion = -5
		}
		good = {
			monthly_war_income_mult = 0.08
			independent_ruler_opinion = -5
			fellow_vassal_opinion = -5
		}
		excellent = {
			monthly_war_income_mult = 0.10
			independent_ruler_opinion = -5
			fellow_vassal_opinion = -5
		}
	}

	modifier = {
		dread_baseline_add = 10
	}

	on_court_position_received = {
		bodyguard_title_accepted_effect = yes
	}
	on_court_position_revoked = {
		bodyguard_title_revoked_effect = yes
	}
	on_court_position_invalidated = {
		bodyguard_title_invalidated_effect = yes
	}
	on_court_position_vacated = {
		court_position_vacated_event_effect = {
			COURT_POSITION_TYPE = master_of_raids_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_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 = {
					ai_has_warlike_personality = yes
				}
			}
			add = 200
		}
		add = court_position_debt_considerations_value
	}
}