﻿smuggler_court_position = { 
	sort_order = 255
	max_available_positions = 1
	skill = intrigue
	minimum_rank = county

	court_position_asset = {
		animation = drink
		background = "gfx/interface/illustrations/event_scenes/tavern.dds"
	}

	opinion = {
		value = regular_court_position_opinion
	}

	aptitude_level_breakpoints = { 20 40 60 80 }

	aptitude = {
		value = 10
		add = {
			value = intrigue
			multiply = 1.5
			max = 50
			desc = court_position_skill_intrigue
		}
		add = {
			value = stewardship
			multiply = 1.5
			max = 50
			desc = court_position_skill_stewardship
		}
		# Negative
		if = {
			limit = { has_trait = craven }
			add = { value = -15 desc = court_position_craven_trait }
		}
		if = {
			limit = { has_trait = lazy }
			add = { value = -15 desc = court_position_lazy_trait }
		}
		if = {
			limit = { has_trait = shy }
			add = { value = -30 desc = court_position_shy_trait }
		}		
		if = {
			limit = { has_trait = generous }
			add = { value = -15 desc = court_position_generous_trait }
		}
		if = {
			limit = { has_trait = reclusive }
			add = { value = -15 desc = court_position_reclusive_trait }
		}
		if = {
			limit = { has_trait = infirm }
			add = { value = -75 desc = court_position_infirm_trait }
		}
		if = {
			limit = { has_trait = disloyal }
			add = { value = -15 desc = court_position_disloyal_trait }
		}
		# Positive
		if = {
			limit = { has_trait = deceitful }
			add = { value = 20 desc = court_position_deceitful_trait }
		}
		if = {
			limit = { has_trait = diligent }
			add = { value = 15 desc = court_position_diligent_trait }
		}
		if = {
			limit = { has_trait = paranoid }
			add = { value = 20 desc = court_position_paranoid_trait }
		}
		if = {
			limit = { has_trait = patient }
			add = { value = 25 desc = court_position_patient_trait }
		}
		if = {
			limit = { has_trait = greedy }
			add = { value = 25 desc = court_position_greedy_trait }
		}
		if = {
			limit = { has_trait = avaricious }
			add = { value = 20 desc = court_position_avaricious_trait }
		}
		if = {
			limit = { has_trait = schemer }
			add = { value = 20 desc = court_position_schemer_trait }
		}
		if = {
			limit = { has_trait = logistician }
			add = { value = 35 desc = court_position_logistician_trait}
		}
		if = {
			limit = { has_trait = loyal }
			add = { value = 15 desc = court_position_loyal_trait }
		}
		# Pilgrim
		if = {
			limit = { has_trait = pilgrim }
			add = {
				if = {
					limit = {
						has_trait_xp = { trait = pilgrim value <= 49 }
					}
					value = 10
				}
				else_if = {
					limit = {
						has_trait_xp = { trait = pilgrim value <= 99 }
					}
					value = 20
				}
				else_if = {
					limit = {
						has_trait_xp = { trait = pilgrim value > 99 }
					}
					value = 35
				}
				desc = court_position_pilgrim_trait
			}
		}
		# Traveler
		if = {
			limit = { has_trait = lifestyle_traveler }
			add = {
				if = {
					limit = {
						OR = {
							has_trait_xp = { trait = lifestyle_traveler track = travel value <= 49 }
							has_trait_xp = { trait = lifestyle_traveler track = danger value <= 49 }
						}

					}
					value = 10
				}
				else_if = {
					limit = {
						OR = {
							has_trait_xp = { trait = lifestyle_traveler track = travel value <= 99 }
							has_trait_xp = { trait = lifestyle_traveler track = danger value <= 99 }
						}
					}
					value = 20
				}
				else_if = {
					limit = {
						OR = {
							has_trait_xp = { trait = lifestyle_traveler track = travel value > 99 }
							has_trait_xp = { trait = lifestyle_traveler track = danger value > 99 }
						}
					}
					value = 35
				}
				desc = court_position_traveler_trait
			}
		}
		# Education
		if = {
			limit = {
				OR = {
					has_trait = education_stewardship_1
					has_trait = education_stewardship_2
					has_trait = education_stewardship_3
					has_trait = education_stewardship_4
					has_trait = education_stewardship_5
				}
			}
			add = {
				value = 5
				if = {
					limit = { has_trait = education_stewardship_2 }
					add = 5
				}
				else_if = {
					limit = { has_trait = education_stewardship_3 }
					add = 10
				}
				else_if = {
					limit = { has_trait = education_stewardship_4 }
					add = 15
				}
				else_if = {
					limit = { has_trait = education_stewardship_5 }
					add = 20
				}
				desc = trait_education_stewardship
			}
		}
		if = {
			limit = {
				OR = {
					has_trait = education_intrigue_1
					has_trait = education_intrigue_2
					has_trait = education_intrigue_3
					has_trait = education_intrigue_4
					has_trait = education_intrigue_5
				}
			}
			add = {
				value = 5
				if = {
					limit = { has_trait = education_intrigue_2 }
					add = 5
				}
				else_if = {
					limit = { has_trait = education_intrigue_3 }
					add = 10
				}
				else_if = {
					limit = { has_trait = education_intrigue_4 }
					add = 15
				}
				else_if = {
					limit = { has_trait = education_intrigue_5 }
					add = 20
				}
				desc = trait_education_intrigue
			}
		}
		# Bonus from court.8311
		if = {
			limit = { var:bonus_aptitude_role ?= flag:smuggler }
			add = {
				value = cp_bonus_aptitude_value
				desc = cp_bonus_aptitude
			}
		}
		add = court_position_aptitude_high_penalty_value
		add = general_aptitude_bonus
	}

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

	valid_position = {
		highest_held_title_tier >= tier_county
		OR = {
			capital_province = {
				OR = {
					is_coastal = yes
					has_holding_type = city_holding
				}
			}
			custom_description = {
				text = already_established_criminal_underground
				house ?= { has_house_modifier = sas_establish_criminal_underground_house_modifier }
			}
		}
	}

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

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

	revoke_cost = {
		prestige =  {
			value = major_court_position_prestige_revoke_cost
			# Set to 0 via obligation hook
			if = {
				limit = {
					court_position_obligation_hook_salary_trigger = {
						POS = smuggler
						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 = smuggler_total_salary_value
			}
		}
		treasury = {
			value = 0
			if = {
				limit = {
					scope:liege = {
						has_treasury = yes
					}
				}
				add = smuggler_total_salary_value
			}
		}
		prestige = {
			value = smuggler_prestige_salary_value
		}
		round = no
	}

	received_salary = {
		gold = {
			value = smuggler_total_salary_value
		}
		prestige = {
			value = smuggler_prestige_salary_value
		}
		round = no
	}

	scaling_employer_modifiers = {
		terrible = {
			diplomatic_range_mult = 0.05
		}
		poor = {
			diplomatic_range_mult = 0.15
		}
		average = {
			diplomatic_range_mult = 0.25
		}
		good = {
			diplomatic_range_mult = 0.35
		}
		excellent = {
			diplomatic_range_mult = 0.45
		}
	}

	custom_employer_modifier_description = smuggler_custom_effect_description_scheme
	custom_employer_modifier_description = smuggler_custom_effect_description_demand_payment
	# custom_employer_modifier_description = smuggler_custom_effect_description_raiding_spoils

	modifier = {
		intrigue = 1
		stewardship = 1
		monthly_income = 0.2
		monthly_stewardship_lifestyle_xp_gain_mult = 0.1
		monthly_intrigue_lifestyle_xp_gain_mult =  0.1
	}

	on_court_position_received = {
		basic_gained_court_position_effect = yes
		scope:liege = {
			set_variable = {
				name = smuggler_is_planning_heist
				value = no
			}
			set_variable = {
				name = smuggler_is_planning_prison_break
				value = no
			}
		}
	}
	on_court_position_revoked = {
		basic_revoked_court_position_effect = yes
		scope:liege = { 
			remove_variable = smuggler_is_planning_heist
			remove_variable = smuggler_is_planning_prison_break
		}
	}
	on_court_position_invalidated = {
		basic_invalidated_court_position_effect = yes
		scope:liege = { 
			remove_variable = smuggler_is_planning_heist
			remove_variable = smuggler_is_planning_prison_break
		}
	}
	on_court_position_vacated = {
		court_position_vacated_event_effect = {
			COURT_POSITION_TYPE = smuggler_court_position
		}
		scope:liege = { 
			remove_variable = smuggler_is_planning_heist
			remove_variable = smuggler_is_planning_prison_break
		}
	}

	# 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 = {
			# More likely to hire if a Schemer
			if = {
				limit = {
					has_trait = schemer
				}
				add = 25
			}
		}
		scope:liege = {
			if = {
				limit = {
					OR = {
						has_trait = greedy
						has_trait = avaricious
					}
				}
				add = 25
			}
		}
		scope:liege = {
			if = {
				limit = {
					stewardship >= 10
					intrigue >= 10
				}
				add = 50
			}
		}
		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 = smuggler }
			}
			add = 1000
		}
	}
}