﻿
bodyguard_court_position = {
	sort_order = {
		value = 131
		if = { # Lower for landless
			limit = {
				is_landed_or_landless_administrative = no
			}
			subtract = 101
		}
	}
	max_available_positions = 7

	skill = prowess

	court_position_asset = {
		animation = menacing
		background = "gfx/interface/illustrations/event_scenes/corridor.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 ?= {
					#AGOT Modified
					#government_has_flag = government_is_landless_adventurer
					OR = {
						government_has_flag = government_is_landless_adventurer
						agot_is_landless_character = yes
					}
					has_perk = soon_forgiven_perk
				}
			}
			add = {
				value = 10
				desc = court_position_soon_forgiven_perk
			}
		}
		if = {
			limit = {
				employer ?= {
					#AGOT Modified
					#government_has_flag = government_is_landless_adventurer
					OR = {
						government_has_flag = government_is_landless_adventurer
						agot_is_landless_character = yes
					}
					has_perk = positions_of_power_perk
				}
				any_relation = { type = friend }
			}
			add = {
				value = 5
				desc = court_position_positions_of_power_perk_friend
			}
		}
		if = {
			limit = {
				employer ?= {
					#AGOT Modified
					#government_has_flag = government_is_landless_adventurer
					OR = {
						government_has_flag = government_is_landless_adventurer
						agot_is_landless_character = yes
					}
					has_perk = positions_of_power_perk
				}
				any_relation = { type = lover }
			}
			add = {
				value = 5
				desc = court_position_positions_of_power_perk_lover
			}
		}
		if = {
			limit = {
				employer ?= {
					#AGOT Modified
					#government_has_flag = government_is_landless_adventurer
					OR = {
						government_has_flag = government_is_landless_adventurer
						agot_is_landless_character = yes
					}
					has_perk = positions_of_power_perk
				}
				is_married = yes
			}
			add = {
				value = 10
				desc = court_position_positions_of_power_perk_marriage
			}
		}
		add = {
			value = prowess
			multiply = 4
			max = 50
			desc = court_position_skill_prowess
		}
		if = {
			limit = {
				has_trait = shieldmaiden
			}
			add = {
				value = 20
				desc = court_position_shieldmaiden_trait
			}
		}
		if = {
			limit = {
				has_trait = lifestyle_blademaster
				has_trait_xp = {
					trait = lifestyle_blademaster
					value >= 100
				}
			}
			add = {
				value = 15
				desc = court_position_blademaster_3_trait
			}
		}
		else_if = {
			limit = {
				has_trait = lifestyle_blademaster
				has_trait_xp = {
					trait = lifestyle_blademaster
					value >= 50
				}
			}
			add = {
				value = 10
				desc = court_position_blademaster_2_trait
			}
		}
		else_if = {
			limit = {
				has_trait = lifestyle_blademaster
			}
			add = {
				value = 5
				desc = court_position_blademaster_1_trait
			}
		}
		if = {
			limit = {
				has_trait = gallant
			}
			add = {
				value = 5
				desc = court_position_gallant_trait
			}
		}
		if = {
			limit = {
				has_trait = brave
			}
			add = {
				value = 20
				desc = court_position_brave_trait
			}
		}
		if = {
			limit = {
				has_trait = paranoid
			}
			add = {
				value = 10
				desc = court_position_paranoid_trait
			}
		}
		if = {
			limit = {
				has_trait = craven
			}
			add = {
				value = -15
				desc = court_position_craven_trait
			}
		}
		add = court_position_aptitude_traveling_friends_value
		#AGOT Disabled
		#if = {
		#	limit = {
		#		has_trait = varangian
		#		employer ?= {
		#			has_title = title:e_byzantium
		#			employs_court_position = akolouthos_court_position
		#		}
		#	}
		#	add = {
		#		value = 5
		#		multiply = employer.court_position:akolouthos_court_position.aptitude:akolouthos_court_position
		#		desc = court_position_akolouthos_bonus
		#	}
		#}
		if = {
			limit = {
				employer ?= {
					culture = {
						has_cultural_parameter = reduced_bodyguard_aptitude
					}
				}
			}
			add = {
				value = -10
				desc = court_position_palace_politics
			}
		}
		#Pick _one_
		if = {
			limit = {
				employer ?= { has_relation_soulmate = prev } #The considered character
			}
			add = {
				value = 40
				desc = court_position_soulmate
			}
		}
		else_if = {
			limit = {
				employer ?= { has_relation_best_friend = prev } #The considered character
			}
			add = {
				value = 30
				desc = court_position_best_friend
			}
		}
		else_if = {
			limit = {
				employer ?= { has_relation_friend = prev } #The considered character
			}
			add = {
				value = 15
				desc = court_position_friend
			}
		}
		if = {
			limit = {
				has_character_flag = best_knight_position
			}
			add = {
				value = 20
				desc = best_knight_position_desc
			}
		}
		if = {
			limit = {
				has_character_flag = competing_knight_position
				OR = {
					any_court_position_holder = {
						type = bodyguard_court_position
						has_character_flag = competing_knight_position
						NOT = { this = prev }
					}
					any_court_position_holder = {
						type = champion_court_position
						has_character_flag = competing_knight_position
					}
					any_court_position_holder = {
						type = akolouthos_court_position
						has_character_flag = competing_knight_position
					}
				}
			}
			add = 30
			desc = competing_knight_position_desc
		}
		# Estate bonus
		if = {
			limit = {
				liege ?= {
					domicile ?= { has_domicile_parameter = estate_increase_bodyguard_aptitude_1 }
				}
			}
			add = {
				value = estate_increase_bodyguard_aptitude_1_value
				desc = estate_increase_bodyguard_aptitude_desc
			}
		}
		if = {
			limit = {
				liege ?= {
					domicile ?= { has_domicile_parameter = estate_increase_bodyguard_aptitude_2 }
				}
			}
			add = {
				value = estate_increase_bodyguard_aptitude_2_value
				desc = estate_increase_bodyguard_aptitude_desc
			}
		}

		if = {
			limit = {
				has_perk = praetorian_guard_perk
			}
			add = {
				value = 15
				desc = court_position_bodyguard_modifier
			}
		}
		if = {
			limit = {
				liege ?= { has_perk = praetorian_guard_perk }
			}
			add = {
				value = 15
				desc = court_position_bodyguard_liege_modifier
			}
		}
		
		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:bodyguard }
			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 = {
		has_ep1_court_positions_dlc_trigger = yes
		trigger_if = {
			limit = {
				is_ai = yes
				highest_held_title_tier <= tier_county
			}
			always = no
		}
		#AGOT Added, KG serve this purpose
		NOT = {
			primary_title = { has_variable = kingsguard }
		}
		#AGOT Added
		NOT = { government_has_flag = government_is_custom_landless }
	}

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

	valid_character = {
		valid_camp_officer_trigger = {
			OFFICER = bodyguard
		}
	}

	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 = bodyguard
						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
			}
			#AGOT Added Inner circle legacy allows revoking without cost
			if = {
				limit = { agot_court_position_inner_circle_revoke_trigger = { LIEGE = root  POS = bodyguard } }
				desc = inner_circle_salary_mod
				multiply = 0
			}
		}
	}

	salary = {
		round = no
		gold = {
			value = sworn_shield_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 = bodyguard } }
				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 = bodyguard
						LIEGE = scope:liege
					}
				}
				multiply = {
					value = 0.5
					desc = obligation_hook_salary
					format = "BASE_VALUE_FORMAT_DECIMALS_MINUS_POSITIVE"
				}
			}
			#Set to 0 with our psycho bodyguard from travel_events.2040
			if = {
				limit = {
					scope:liege = {
						employs_court_position = bodyguard_court_position
						any_court_position_holder = {
					        type = bodyguard_court_position
					        has_variable = insane_bodyguard
						}
					}
				}
				multiply = {
					value = 0
					desc = insane_bodyguard_salary_mod
				}
			}
			# Halved salary
			if = {
				limit = {
					court_position_halved_salary_trigger = { POS = bodyguard }
				}
				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 = bodyguard }
				}
				multiply = {
					value = 1.5
					desc = court_position_increased_salary
					format = "BASE_VALUE_FORMAT_DECIMALS_MINUS_POSITIVE"
				}
			}
			#You're working with LAAMPS now
			if = {
				limit = { 
					#AGOT Modified
					#scope:liege ?= { government_has_flag = government_is_landless_adventurer }
					scope:liege ?= {
						OR = {
							government_has_flag = government_is_landless_adventurer
							agot_is_landless_character = yes
						}
					}
				}
				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
			# Set to 0 with Dynasty Perk Inner Circle
			if = {
				limit = { court_position_inner_circle_salary_trigger = { POS = bodyguard } }
				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 = bodyguard
						LIEGE = scope:liege
					}
				}
				multiply = {
					value = 0.5
					desc = obligation_hook_salary
					format = "BASE_VALUE_FORMAT_DECIMALS_MINUS_POSITIVE"
				}
			}
			#Set to 0 with our psycho bodyguard from travel_events.2040
			if = {
				limit = {
					scope:liege = {
						employs_court_position = bodyguard_court_position
						any_court_position_holder = {
					        type = bodyguard_court_position
					        has_variable = insane_bodyguard
						}
					}
				}
				multiply = {
					value = 0
					desc = insane_bodyguard_salary_mod
				}
			}
			# Halved salary
			if = {
				limit = {
					court_position_halved_salary_trigger = { POS = bodyguard }
				}
				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 = bodyguard }
				}
				multiply = {
					value = 1.5
					desc = court_position_increased_salary
					format = "BASE_VALUE_FORMAT_DECIMALS_MINUS_POSITIVE"
				}
			}
			#You're working with LAAMPS now
			if = {
				limit = { 
					#AGOT Modified
					#scope:liege ?= { government_has_flag = government_is_landless_adventurer }
					scope:liege ?= {
						OR = {
							government_has_flag = government_is_landless_adventurer
							agot_is_landless_character = yes
						}
					}
				}
				multiply = {
					value = 0
					desc = court_position_laamps_free
					format = "BASE_VALUE_FORMAT_DECIMALS_MINUS_POSITIVE"
				}
			}
		}
	}

	is_powerful_agent = yes

	# These modifiers are employed based on what level the aptitude reaches (levels are defined as breakpoints)
	scaling_employer_modifiers = {
		terrible = {
			enemy_hostile_scheme_success_chance_max_add = -1
		}
		poor = {
			enemy_hostile_scheme_success_chance_max_add = -2
		}
		average = {
			enemy_hostile_scheme_success_chance_max_add = -5
		}
		good = {
			enemy_hostile_scheme_success_chance_max_add = -7
		}
		excellent = {
			enemy_hostile_scheme_success_chance_max_add = -10
		}
	}

	custom_employer_modifier_description = bodyguard_employer_custom_effect_description

	modifier = {
		dread_baseline_add = 10
		intrigue = 1
		enemy_hostile_scheme_success_chance_max_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 = bodyguard_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 = 500
		add = scope:base_value
		add = court_position_candidate_score_base_value
		add = court_position_candidate_aptitude_value

		#counter the base_value for landless adventurers, as it assumes you would have a monthly income, don't worry court position don't have salary when hired by landless adventurers
    	if = {
    		limit = {
    			scope:liege = {
    				government_has_flag = government_is_landless_adventurer
    			}
    		}
    		add = {
    			value = scope:base_value
    			multiply = -1
    		}
    	}

		scope:liege = {
			# More likely if you're scared all the time
			if = {
				limit = {
					has_trait = paranoid
				}
				add = 50
			}

			# Less likely to hire an additional one if you're already employing one
			#if = {
			#	limit = {
			#		employs_court_position = bodyguard_court_position
			#	}
			#	add = -50
			#}
		}
		if = { # To stop petitioned positions immediately being fired by the AI
			limit = {
				court_position_petition_ai_weight_trigger = { ROLE = bodyguard }
			}
			add = 1000
		}
		add = court_position_debt_considerations_value
	}
}