﻿namespace = court

##################################################
# # RANGES
# 0001 - 0099		Misc Events
# 0100 - 0999 		James
# 1000 - 2000		Shoes
# 2001 - 2999		Ewan
# 3000 - 4000		Bianca
# 4001 - 5000		Isabella
# 5001 - 5999		Linnea
# 6000 - 6999		Claudia
# 7000 - 8000		George
# 8001 - 8999		Joe
# 9000 - 9999		Oltner
#
##################################################

#########################
# Court Position Boons	#
# by Joe Parkin 		#
#########################

scripted_trigger employed_booner_pos_trigger = {
	is_available_healthy_ai_adult = yes
	aptitude = {
		court_position = $POS$_court_position
		value >= 3
	}
	trigger_if = {
		limit = { exists = employer }
		opinion = {
			target = employer
			value >= -50
		}
	}
	trigger_else_if = {
		limit = { exists = liege }
		opinion = {
			target = liege
			value >= -50
		}
	}
	trigger_else = { always = yes }
	NOT = { exists = var:booner_target }
}

scripted_trigger employed_booner_trigger = {
	has_royal_court = yes
	employs_court_position = $POS$_court_position
	any_court_position_holder = {
		type = $POS$_court_position
		employed_booner_pos_trigger = { POS = $POS$ }
	}
	NOT = { has_character_flag = court_employer_booner_cooldown }
}

scripted_trigger employer_triple_modifier_trigger = {
	NOT = {
		any_courtier = {
			OR = {
				has_character_modifier = employer_booner_$POS$_1_modifier
				has_character_modifier = employer_booner_$POS$_2_modifier
				has_character_modifier = employer_booner_$POS$_3_modifier
			}
		}
	}
}

scripted_effect employed_booner_reward_effect = {
	save_scope_as = booner_target
	add_character_modifier = {
		modifier = employer_booner_$POS$_modifier
		years = 10
	}
	custom_tooltip = employer_booner_invalidated_tt
	scope:position_holder = {
		set_variable = {
			name = booner_target
			value = scope:booner_target
			years = 10
		}
	}
}

# Physician

scripted_trigger court_8190_employed_booner_patient_trigger = {
	is_available = yes
	is_courtier_of = root
	NOR = {
		has_relation_rival = root
		scope:position_holder ?= this
		scope:heir ?= this
		scope:child ?= this
		scope:spouse ?= this
		scope:relation ?= this
		scope:family ?= this
	}
}

court.8190 = {
	type = court_event
	title = court.8190.t
	desc = court.8190.desc
	theme = court
	cooldown = { years = 25 }
	court_scene = {
		button_position_character = scope:position_holder
		roles = {
			scope:position_holder = {
				group = event_group
				animation = physician
			}
			root = {
				group = event_group
				triggered_animation = {
					trigger = { is_healthy = no }
					animation = sick
				}
				animation = idle
			}
		}
	}

	trigger = {
		employed_booner_trigger = { POS = court_physician }
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = {
				value = "court_position:court_physician_court_position.aptitude(court_physician_court_position)"
				subtract = 3
			}
		}
	}

	immediate = {
		add_character_flag = {
			flag = court_employer_booner_cooldown
			years = 5
		}
		ordered_court_position_holder = {
			type = court_physician_court_position
			limit = {
				employed_booner_pos_trigger = { POS = court_physician }
			}
			order_by = "aptitude(court_physician_court_position)"
			save_scope_as = position_holder
		}
		player_heir ?= {
			if = {
				limit = {
					house = root.house
					court_8190_employed_booner_patient_trigger = yes
				}
				save_scope_as = heir
			}
		}
		ordered_child = {
			limit = {
				NOT = { scope:heir ?= this }
				court_8190_employed_booner_patient_trigger = yes
			}
			order_by = {
				value = 0
				subtract = health
			}
			save_scope_as = child
		}
		ordered_spouse = {
			limit = {
				NOR = {
					scope:heir ?= this
					scope:child ?= this
				}
				court_8190_employed_booner_patient_trigger = yes
			}
			order_by = {
				value = 0
				subtract = health
			}
			save_scope_as = spouse
		}
		ordered_relation = {
			type = friend
			type = lover
			limit = {
				NOR = {
					scope:heir ?= this
					scope:child ?= this
					scope:spouse ?= this
				}
				court_8190_employed_booner_patient_trigger = yes
			}
			order_by = {
				value = 0
				subtract = health
			}
			save_scope_as = relation
		}
		ordered_close_family_member = {
			limit = {
				NOR = {
					this = root
					scope:heir ?= this
					scope:child ?= this
					scope:spouse ?= this
					scope:relation ?= this
				}
				court_8190_employed_booner_patient_trigger = yes
			}
			order_by = {
				value = 0
				subtract = health
			}
			save_scope_as = family
		}
		house ?= {
			ordered_house_member = {
				limit = {
					NOR = {
						this = root
						scope:heir ?= this
						scope:child ?= this
						scope:spouse ?= this
						scope:relation ?= this
						scope:family ?= this
					}
					court_8190_employed_booner_patient_trigger = yes
				}
				order_by = {
					value = 0
					subtract = health
				}
				save_scope_as = house
			}
		}
	}

	option = { # Take your medicine
		name = court.8190.a
		employed_booner_reward_effect = { POS = court_physician }
		ai_chance = {
			base = 50
			employer_boon_treatment_ai_chance_modifier = { TARGET = scope:position_holder }
		}
	}

	option = { # Heir
		name = court.8190.b
		trigger = { exists = scope:heir }
		scope:heir = {
			employed_booner_reward_effect = { POS = court_physician }
		}
		ai_chance = {
			base = 25
			employer_boon_treatment_ai_chance_modifier = { TARGET = scope:heir }
		}
	}

	option = { # Child
		name = court.8190.c
		trigger = { exists = scope:child }
		scope:child = {
			employed_booner_reward_effect = { POS = court_physician }
		}
		ai_chance = {
			base = 10
			employer_boon_treatment_ai_chance_modifier = { TARGET = scope:child }
		}
	}

	option = { # Spouse
		name = court.8190.d
		trigger = { exists = scope:spouse }
		scope:spouse = {
			employed_booner_reward_effect = { POS = court_physician }
		}
		ai_chance = {
			base = 10
			employer_boon_treatment_ai_chance_modifier = { TARGET = scope:spouse }
		}
	}

	option = { # Relation
		name = court.8190.e
		trigger = {
			exists = scope:relation
			calc_true_if = {
				amount < 3
				exists = scope:heir
				exists = scope:child
				exists = scope:spouse
			}
		}
		scope:relation = {
			employed_booner_reward_effect = { POS = court_physician }
		}
		ai_chance = {
			base = 10
			employer_boon_treatment_ai_chance_modifier = { TARGET = scope:relation }
		}
	}

	option = { # Family
		name = court.8190.f
		trigger = {
			exists = scope:family
			calc_true_if = {
				amount < 3
				exists = scope:heir
				exists = scope:child
				exists = scope:spouse
				exists = scope:relation
			}
		}
		scope:family = {
			employed_booner_reward_effect = { POS = court_physician }
		}
		ai_chance = {
			base = 10
			employer_boon_treatment_ai_chance_modifier = { TARGET = scope:family }
		}
	}

	option = { # House
		name = court.8190.g
		trigger = {
			exists = scope:house
			calc_true_if = {
				amount < 3
				exists = scope:heir
				exists = scope:child
				exists = scope:spouse
				exists = scope:relation
				exists = scope:family
			}
		}
		scope:house = {
			employed_booner_reward_effect = { POS = court_physician }
		}
		ai_chance = {
			base = 10
			employer_boon_treatment_ai_chance_modifier = { TARGET = scope:house }
		}
	}
}

# Tutor

scripted_trigger court_8191_employed_booner_student_trigger = {
	is_available = yes
	is_adult = no
	age >= 6 # to ensure coming of age education effects are fully utilized
	is_courtier_of = root
	OR = {
		is_heir_of = root
		is_close_family_of = root
		is_hostage_of = root
	}
	NOR = {
		has_relation_rival = root
		root = this
		scope:position_holder ?= this
	}
}

scripted_effect court_8191_employed_booner_reward_effect = {
	save_scope_as = child
	scope:position_holder = {
		switch = {
			trigger = has_trait
			education_diplomacy = {
				scope:child = { add_diplomacy_skill = 1 }
			}
			education_martial = {
				scope:child = { add_martial_skill = 1 }
			}
			education_stewardship = {
				scope:child = { add_stewardship_skill = 1 }
			}
			education_intrigue = {
				scope:child = { add_intrigue_skill = 1 }
			}
			education_learning = {
				scope:child = { add_learning_skill = 1 }
			}
		}
	}
	employed_booner_reward_effect = { POS = court_tutor }
	education_point_acquisition_additional_points_effect = { LEVEL = mid }
	root = {
		if = {
			limit = { this = scope:child }
			stress_impact = { lazy = minor_stress_impact_gain }
		}
		else_if = {
			limit = { is_adult = no }
			stress_impact = { diligent = minor_stress_impact_gain }
		}
	}
}

scripted_effect court_8191_portrait_effect = {
	if = {
		limit = {
			NOT = { exists = scope:portrait }
		}
		save_scope_as = portrait
	}
}

court.8191 = {
	type = court_event
	title = court.8191.t
	desc = court.8191.desc
	theme = court
	cooldown = { years = 25 }
	court_scene = {
		button_position_character = scope:position_holder
		roles = {
			scope:position_holder = {
				group = event_group
				triggered_animation = {
					trigger = { exists = scope:baby }
					animation = newborn
				}
				animation = happy_teacher
			}
			scope:portrait = {
				group = event_group
				animation = reading
			}
			root = {
				group = event_group
				animation = idle
			}
		}
	}

	trigger = {
		employed_booner_trigger = { POS = court_tutor }
		any_courtier = {
			count >= 2
			court_8191_employed_booner_student_trigger = yes
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = {
				value = "court_position:court_tutor_court_position.aptitude(court_tutor_court_position)"
				subtract = 3
			}
		}
	}

	immediate = {
		add_character_flag = {
			flag = court_employer_booner_cooldown
			years = 5
		}
		ordered_court_position_holder = {
			type = court_tutor_court_position
			limit = {
				employed_booner_pos_trigger = { POS = court_tutor }
			}
			order_by = "aptitude(court_tutor_court_position)"
			save_scope_as = position_holder
		}
		every_close_family_member = {
			limit = { court_8191_employed_booner_student_trigger = yes }
			add_to_list = students
		}
		every_warden_hostage = {
			limit = { court_8191_employed_booner_student_trigger = yes }
			add_to_list = students
		}
		every_in_list = {
			list = students
			limit = {
				save_temporary_scope_as = struggling_temp
				any_in_list = {
					list = students
					this != scope:struggling_temp
					age < scope:struggling_temp.age
					sum_of_all_skills_value > scope:struggling_temp.sum_of_all_skills_value
				}
			}
			add_to_list = struggling
			remove_from_list = students
		}
		player_heir ?= { # Heir
			if = {
				limit = { is_in_list = students }
				save_scope_as = heir
				court_8191_portrait_effect = yes
				remove_from_list = students
			}
		}
		if = {
			limit = {
				NOT = { exists = scope:heir }
			}
			ordered_in_list = {
				list = students
				limit = {
					is_heir_of = root
					save_temporary_scope_as = heir_temp
				}
				order_by = {
					value = 0
					subtract = "root.primary_title.place_in_line_of_succession(scope:heir_temp)"
				}
				save_scope_as = heir
				court_8191_portrait_effect = yes
				remove_from_list = students
			}
		}
		ordered_in_list = { # Struggling
			list = struggling
			limit = { is_heir_of = root }
			alternative_limit = { is_child_of = root }
			alternative_limit = { always = yes }
			order_by = age
			save_scope_as = struggling
				court_8191_portrait_effect = yes
			remove_from_list = struggling
		}
		ordered_in_list = { # Oldest
			list = students
			limit = { is_heir_of = root }
			alternative_limit = { always = yes }
			order_by = age
			save_scope_as = oldest
			court_8191_portrait_effect = yes
			remove_from_list = students
		}
		ordered_in_list = { # Youngest
			list = students
			limit = { is_heir_of = root }
			alternative_limit = { always = yes }
			order_by = {
				value = 0
				subtract = age
			}
			save_scope_as = youngest
			court_8191_portrait_effect = yes
			remove_from_list = students
		}
		random_in_list = { # Hostage
			list = students
			limit = {
				is_hostage_of = root
				save_temporary_scope_as = hostage_temp
			}
			weight = {
				base = 1
				is_of_minor_interest_to_weight_up_modifier = { CHARACTER = root }
				is_of_major_interest_to_weight_up_modifier = { CHARACTER = root }
				modifier = {
					add = 1000
					root = {
						any_owned_story = {
							type = bp2_hostage_loyalty
							var:hostage_target ?= scope:hostage_temp
						}
					}
				}
			}
			save_scope_as = hostage
			court_8191_portrait_effect = yes
			remove_from_list = students
		}
		random_in_list = { # Interesting
			list = students
			limit = { is_heir_of = root }
			alternative_limit = { is_child_of = root }
			alternative_limit = { always = yes }
			weight = {
				base = 1
				is_of_minor_interest_to_weight_up_modifier = { CHARACTER = root }
				is_of_major_interest_to_weight_up_modifier = { CHARACTER = root }
			}
			save_scope_as = interesting
			court_8191_portrait_effect = yes
			remove_from_list = students
		}
		random_in_list = { # Extra
			list = students
			limit = { is_heir_of = root }
			alternative_limit = { is_child_of = root }
			alternative_limit = { always = yes }
			weight = {
				base = 1
				is_of_minor_interest_to_weight_up_modifier = { CHARACTER = root }
				is_of_major_interest_to_weight_up_modifier = { CHARACTER = root }
			}
			save_scope_as = extra
			court_8191_portrait_effect = yes
			remove_from_list = students
		}
		ordered_in_list = { # Bonus
			list = struggling
			limit = { is_heir_of = root }
			alternative_limit = { is_child_of = root }
			alternative_limit = { always = yes }
			order_by = {
				value = 0
				subtract = sum_of_all_skills_value
			}
			save_scope_as = bonus
			court_8191_portrait_effect = yes
			remove_from_list = struggling
		}
	}

	option = { # Teach me!
		name = court.8191.a
		trigger = { is_adult = no }
		court_8191_employed_booner_reward_effect = yes
		ai_chance = {
			base = 50
		}
	}

	option = { # Heir
		name = court.8191.b
		trigger = { exists = scope:heir }
		scope:heir = { court_8191_employed_booner_reward_effect = yes }
		ai_chance = {
			base = 10
			employer_boon_child_ai_chance_modifier = { TARGET = scope:heir }
		}
	}

	option = { # Struggling
		name = court.8191.c
		trigger = { exists = scope:struggling }
		scope:struggling = { court_8191_employed_booner_reward_effect = yes }
		ai_chance = {
			base = 10
			employer_boon_child_ai_chance_modifier = { TARGET = scope:struggling }
		}
	}

	option = { # Hostage
		name = court.8191.d
		trigger = { exists = scope:hostage }
		scope:hostage = { court_8191_employed_booner_reward_effect = yes }
		ai_chance = {
			base = 10
			employer_boon_child_ai_chance_modifier = { TARGET = scope:hostage }
		}
	}

	option = { # Interesting
		name = court.8191.e
		trigger = { exists = scope:interesting }
		scope:interesting = { court_8191_employed_booner_reward_effect = yes }
		ai_chance = {
			base = 10
			employer_boon_child_ai_chance_modifier = { TARGET = scope:interesting }
		}
	}

	option = { # Eldest
		name = court.8191.f
		trigger = {
			exists = scope:oldest
			calc_true_if = {
				amount < 4
				exists = scope:heir
				exists = scope:struggling
				exists = scope:hostage
				exists = scope:interesting
			}
		}
		scope:oldest = { court_8191_employed_booner_reward_effect = yes }
		ai_chance = {
			base = 10
			employer_boon_child_ai_chance_modifier = { TARGET = scope:oldest }
		}
	}

	option = { # Youngest
		name = court.8191.g
		trigger = {
			exists = scope:youngest
			calc_true_if = {
				amount < 4
				exists = scope:heir
				exists = scope:struggling
				exists = scope:hostage
				exists = scope:interesting
				exists = scope:oldest
			}
		}
		scope:youngest = { court_8191_employed_booner_reward_effect = yes }
		ai_chance = {
			base = 10
			employer_boon_child_ai_chance_modifier = { TARGET = scope:youngest }
		}
	}

	option = { # Extra
		name = court.8191.h
		trigger = {
			exists = scope:extra
			calc_true_if = {
				amount < 4
				exists = scope:heir
				exists = scope:struggling
				exists = scope:hostage
				exists = scope:interesting
				exists = scope:oldest
				exists = scope:youngest
			}
		}
		scope:extra = { court_8191_employed_booner_reward_effect = yes }
		ai_chance = {
			base = 10
			employer_boon_child_ai_chance_modifier = { TARGET = scope:extra }
		}
	}

	option = { # Bonus
		name = court.8191.i
		trigger = {
			exists = scope:bonus
			calc_true_if = {
				amount < 4
				exists = scope:heir
				exists = scope:struggling
				exists = scope:hostage
				exists = scope:interesting
				exists = scope:oldest
				exists = scope:youngest
				exists = scope:extra
			}
		}
		scope:bonus = { court_8191_employed_booner_reward_effect = yes }
		ai_chance = {
			base = 10
			employer_boon_child_ai_chance_modifier = { TARGET = scope:bonus }
		}
	}
}

# Seneschal

court.8192 = {
	type = court_event
	title = court.8192.t
	desc = court.8192.desc
	theme = court
	cooldown = { years = 25 }
	court_scene = {
		button_position_character = scope:position_holder
		roles = {
			scope:position_holder = {
				group = event_group
				animation = writing
			}
			root = {
				group = event_group
				animation = idle
			}
		}
	}

	trigger = {
		employed_booner_trigger = { POS = seneschal }
		employer_triple_modifier_trigger = { POS = seneschal }
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = {
				value = "court_position:seneschal_court_position.aptitude(seneschal_court_position)"
				subtract = 3
			}
		}
	}

	immediate = {
		add_character_flag = {
			flag = court_employer_booner_cooldown
			years = 5
		}
		ordered_court_position_holder = {
			type = seneschal_court_position
			limit = {
				employed_booner_pos_trigger = { POS = seneschal }
			}
			order_by = "aptitude(seneschal_court_position)"
			save_scope_as = position_holder
		}
	}

	option = { # Lodgings Cost
		name = court.8192.a
		employed_booner_reward_effect = { POS = seneschal_1 }
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_greed = 0.5
			}
		}
	}

	option = { # Servants Cost
		name = court.8192.b
		employed_booner_reward_effect = { POS = seneschal_2 }
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_energy = 0.5
			}
		}
	}

	option = { # Both!
		name = court.8192.c
		duel = {
			skill = stewardship
			value = decent_skill_rating
			10 = {
				min = 2
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
				}
				desc = court.8192.c.success
				send_interface_toast = {
					type = event_toast_effect_good
					title = court.8192.c.success
					right_icon = scope:position_holder
					employed_booner_reward_effect = { POS = seneschal_3 }
				}
			}
			10 = {
				min = 2
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
				}
				desc = court.8192.c.failure
				send_interface_toast = {
					type = event_toast_effect_bad
					title = court.8192.c.failure
					right_icon = scope:position_holder
					stress_impact = {
						base = minor_stress_impact_gain
					}
				}
			}
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_boldness = 0.5
				ai_rationality = -0.5
			}
		}
	}
}

# Wet Nurse

scripted_trigger court_8193_employed_booner_child_trigger = {
	is_available = yes
	is_adult = no
	is_courtier_of = root
	OR = {
		is_heir_of = root
		is_close_family_of = root
		is_hostage_of = root
	}
	NOR = {
		has_relation_rival = root
		scope:position_holder ?= this
		scope:heir ?= this
		scope:baby ?= this
		scope:interesting ?= this
		scope:hostage ?= this
		scope:sickest ?= this
		scope:second_sickest ?= this
		scope:extra ?= this
	}
}

scripted_effect court_8193_employed_booner_reward_effect = {
	save_scope_as = child
	scope:position_holder = {
		switch = {
			trigger = has_trait
			education_diplomacy = {
				scope:child = { add_diplomacy_skill = 1 }
			}
			education_martial = {
				scope:child = { add_martial_skill = 1 }
			}
			education_stewardship = {
				scope:child = { add_stewardship_skill = 1 }
			}
			education_intrigue = {
				scope:child = { add_intrigue_skill = 1 }
			}
			education_learning = {
				scope:child = { add_learning_skill = 1 }
			}
		}
	}
	employed_booner_reward_effect = { POS = wet_nurse }
	education_point_acquisition_additional_points_effect = { LEVEL = low }
}

court.8193 = {
	type = court_event
	title = court.8193.t
	desc = court.8193.desc
	theme = court
	cooldown = { years = 25 }
	court_scene = {
		button_position_character = scope:position_holder
		roles = {
			scope:position_holder = {
				group = event_group
				triggered_animation = {
					trigger = { exists = scope:baby }
					animation = newborn
				}
				animation = personality_compassionate
			}
			root = {
				group = event_group
				animation = idle
			}
		}
	}

	trigger = {
		employed_booner_trigger = { POS = wet_nurse }
		any_courtier = {
			count >= 2
			court_8193_employed_booner_child_trigger = yes
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = {
				value = "court_position:wet_nurse_court_position.aptitude(wet_nurse_court_position)"
				subtract = 3
			}
		}
	}

	immediate = {
		add_character_flag = {
			flag = court_employer_booner_cooldown
			years = 5
		}
		ordered_court_position_holder = {
			type = wet_nurse_court_position
			limit = {
				employed_booner_pos_trigger = { POS = wet_nurse }
			}
			order_by = "aptitude(wet_nurse_court_position)"
			save_scope_as = position_holder
		}
		every_close_family_member = {
			limit = { court_8193_employed_booner_child_trigger = yes }
			add_to_list = children
		}
		every_warden_hostage = {
			limit = { court_8193_employed_booner_child_trigger = yes }
			add_to_list = children
		}
		every_in_list = {
			list = children
			if = {
				limit = { is_healthy = no }
				add_to_list = sickly
			}
		}
		player_heir ?= { # Heir
			if = {
				limit = { is_in_list = children }
				save_scope_as = heir
			}
		}
		if = {
			limit = {
				NOT = { exists = scope:heir }
			}
			ordered_in_list = {
				list = children
				limit = {
					is_heir_of = root
					save_temporary_scope_as = heir_temp
				}
				order_by = {
					value = 0
					subtract = "root.primary_title.place_in_line_of_succession(scope:heir_temp)"
				}
				save_scope_as = heir
			}
		}
		ordered_in_list = { # Baby
			list = children
			limit = {
				is_heir_of = root
				age < 1
				court_8193_employed_booner_child_trigger = yes
			}
			alternative_limit = {
				is_child_of = root
				age < 1
				court_8193_employed_booner_child_trigger = yes
			}
			alternative_limit = {
				age < 1
				court_8193_employed_booner_child_trigger = yes
			}
			order_by = {
				value = 0
				subtract = age
			}
			save_scope_as = baby
		}
		ordered_in_list = { # Sickest
			list = sickly
			limit = {
				is_heir_of = root
				court_8193_employed_booner_child_trigger = yes
			}
			alternative_limit = {
				is_child_of = root
				court_8193_employed_booner_child_trigger = yes
			}
			alternative_limit = { court_8193_employed_booner_child_trigger = yes }
			order_by = {
				value = 0
				subtract = health
			}
			save_scope_as = sickest
		}
		ordered_in_list = { # Second Sickest
			list = sickly
			limit = {
				is_heir_of = root
				court_8193_employed_booner_child_trigger = yes
			}
			alternative_limit = {
				is_child_of = root
				court_8193_employed_booner_child_trigger = yes
			}
			alternative_limit = { court_8193_employed_booner_child_trigger = yes }
			order_by = {
				value = 0
				subtract = health
			}
			save_scope_as = second_sickest
		}
		random_in_list = { # Hostage
			list = children
			limit = {
				is_hostage_of = root
				court_8193_employed_booner_child_trigger = yes
				save_temporary_scope_as = hostage_temp
			}
			weight = {
				base = 1
				is_of_minor_interest_to_weight_up_modifier = { CHARACTER = root }
				is_of_major_interest_to_weight_up_modifier = { CHARACTER = root }
				modifier = {
					add = 1000
					root = {
						any_owned_story = {
							type = bp2_hostage_loyalty
							var:hostage_target ?= scope:hostage_temp
						}
					}
				}
			}
			save_scope_as = hostage
		}
		random_in_list = { # Interesting
			list = children
			limit = {
				is_heir_of = root
				court_8193_employed_booner_child_trigger = yes
			}
			alternative_limit = {
				is_child_of = root
				court_8193_employed_booner_child_trigger = yes
			}
			alternative_limit = { court_8193_employed_booner_child_trigger = yes }
			weight = {
				base = 1
				modifier = {
					add = 25
					has_trait = sickly
				}
				is_of_minor_interest_to_weight_up_modifier = { CHARACTER = root }
				is_of_major_interest_to_weight_up_modifier = { CHARACTER = root }
			}
			save_scope_as = interesting
		}
		random_in_list = { # Extra
			list = children
			limit = {
				is_heir_of = root
				court_8193_employed_booner_child_trigger = yes
			}
			alternative_limit = {
				is_child_of = root
				court_8193_employed_booner_child_trigger = yes
			}
			alternative_limit = { court_8193_employed_booner_child_trigger = yes }
			weight = {
				base = 1
				modifier = {
					add = 25
					has_trait = sickly
				}
				is_of_minor_interest_to_weight_up_modifier = { CHARACTER = root }
				is_of_major_interest_to_weight_up_modifier = { CHARACTER = root }
			}
			save_scope_as = extra
		}
		ordered_in_list = { # Bonus
			list = children
			limit = {
				is_heir_of = root
				court_8193_employed_booner_child_trigger = yes
			}
			alternative_limit = {
				is_child_of = root
				court_8193_employed_booner_child_trigger = yes
			}
			alternative_limit = { court_8193_employed_booner_child_trigger = yes }
			order_by = {
				value = 0
				subtract = health
			}
			save_scope_as = bonus
		}
	}

	option = { # Look after me!
		name = court.8193.a
		trigger = { is_adult = no }
		court_8193_employed_booner_reward_effect = yes
		ai_chance = {
			base = 50
		}
	}

	option = { # Heir
		name = court.8193.b
		trigger = { exists = scope:heir }
		scope:heir = { court_8193_employed_booner_reward_effect = yes }
		ai_chance = {
			base = 10
			employer_boon_child_ai_chance_modifier = { TARGET = scope:heir }
		}
	}

	option = { # Baby
		name = court.8193.c
		trigger = { exists = scope:baby }
		scope:baby = { court_8193_employed_booner_reward_effect = yes }
		ai_chance = {
			base = 10
			employer_boon_child_ai_chance_modifier = { TARGET = scope:baby }
		}
	}

	option = { # Sickest
		name = court.8193.f
		trigger = { exists = scope:sickest }
		scope:sickest = { court_8193_employed_booner_reward_effect = yes }
		ai_chance = {
			base = 10
			employer_boon_child_ai_chance_modifier = { TARGET = scope:sickest }
		}
	}

	option = { # Second Sickest
		name = court.8193.g
		trigger = { exists = scope:second_sickest }
		scope:second_sickest = { court_8193_employed_booner_reward_effect = yes }
		ai_chance = {
			base = 10
			employer_boon_child_ai_chance_modifier = { TARGET = scope:second_sickest }
		}
	}

	option = { # Hostage
		name = court.8193.d
		trigger = {
			exists = scope:hostage
			calc_true_if = {
				amount < 4
				exists = scope:heir
				exists = scope:baby
				exists = scope:sickest
				exists = scope:second_sickest
			}
		}
		scope:hostage = { court_8193_employed_booner_reward_effect = yes }
		ai_chance = {
			base = 10
			employer_boon_child_ai_chance_modifier = { TARGET = scope:hostage }
		}
	}

	option = { # Interesting
		name = court.8193.e
		trigger = {
			exists = scope:interesting
			calc_true_if = {
				amount < 4
				exists = scope:heir
				exists = scope:baby
				exists = scope:sickest
				exists = scope:second_sickest
				exists = scope:hostage
			}
		}
		scope:interesting = { court_8193_employed_booner_reward_effect = yes }
		ai_chance = {
			base = 10
			employer_boon_child_ai_chance_modifier = { TARGET = scope:interesting }
		}
	}

	option = { # Extra
		name = court.8193.h
		trigger = {
			exists = scope:extra
			calc_true_if = {
				amount < 4
				exists = scope:heir
				exists = scope:baby
				exists = scope:sickest
				exists = scope:second_sickest
				exists = scope:hostage
				exists = scope:interesting
			}
		}
		scope:extra = { court_8193_employed_booner_reward_effect = yes }
		ai_chance = {
			base = 10
			employer_boon_child_ai_chance_modifier = { TARGET = scope:extra }
		}
	}

	option = { # Bonus
		name = court.8193.i
		trigger = {
			exists = scope:bonus
			calc_true_if = {
				amount < 4
				exists = scope:heir
				exists = scope:baby
				exists = scope:sickest
				exists = scope:second_sickest
				exists = scope:hostage
				exists = scope:interesting
				exists = scope:extra
			}
		}
		scope:bonus = { court_8193_employed_booner_reward_effect = yes }
		ai_chance = {
			base = 10
			employer_boon_child_ai_chance_modifier = { TARGET = scope:bonus }
		}
	}
}

# High Almoner

court.8194 = {
	type = court_event
	title = court.8194.t
	desc = court.8194.desc
	theme = court
	cooldown = { years = 25 }
	court_scene = {
		button_position_character = scope:position_holder
		roles = {
			scope:position_holder = {
				group = event_group
				animation = steward
			}
			root = {
				group = event_group
				animation = idle
			}
		}
	}

	trigger = {
		employed_booner_trigger = { POS = high_almoner }
		employer_triple_modifier_trigger = { POS = high_almoner }
		any_vassal = { vassal_stance = zealot }
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = {
				value = "court_position:high_almoner_court_position.aptitude(high_almoner_court_position)"
				subtract = 3
			}
		}
	}

	immediate = {
		add_character_flag = {
			flag = court_employer_booner_cooldown
			years = 5
		}
		ordered_court_position_holder = {
			type = high_almoner_court_position
			limit = {
				employed_booner_pos_trigger = { POS = high_almoner }
			}
			order_by = "aptitude(high_almoner_court_position)"
			save_scope_as = position_holder
		}
	}

	option = { # County Opinion
		name = court.8194.a
		employed_booner_reward_effect = { POS = high_almoner_1 }
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_greed = 0.5
			}
		}
	}

	option = { # Realm Priest Opinion
		name = court.8194.b
		employed_booner_reward_effect = { POS = high_almoner_2 }
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_sociability = 0.5
			}
		}
	}

	option = { # Both!
		name = court.8194.c
		duel = {
			skill = learning
			value = decent_skill_rating
			10 = {
				min = 2
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
				}
				desc = court.8194.c.success
				send_interface_toast = {
					type = event_toast_effect_good
					title = court.8194.c.success
					right_icon = scope:position_holder
					employed_booner_reward_effect = { POS = high_almoner_3 }
				}
			}
			10 = {
				min = 2
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
				}
				desc = court.8194.c.failure
				send_interface_toast = {
					type = event_toast_effect_bad
					title = court.8194.c.failure
					right_icon = scope:position_holder
					stress_impact = {
						base = minor_stress_impact_gain
					}
				}
			}
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_boldness = 0.5
				ai_rationality = -0.5
			}
		}
	}
}

# Bodyguard

scripted_trigger court_8195_employed_booner_sparist_trigger = {
	is_available = yes
	age >= 8
	is_courtier_of = root
	is_healthy = yes
	OR = {
		is_heir_of = root
		is_close_family_of = root
		is_hostage_of = root
	}
	can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root }
	NOR = {
		has_relation_rival = root
		root = this
		scope:position_holder ?= this
	}
}

scripted_effect court_8195_employed_booner_reward_effect = {
	save_scope_as = sparist
	if = {
		limit = {
			has_trait = lifestyle_blademaster
			has_trait_xp = { trait = lifestyle_blademaster value < 100 }
		}
		add_trait_xp = {
			trait = lifestyle_blademaster
			value = lifestyle_blademaster_xp_gain_minor_value
		}
	}
	else = { add_trait = lifestyle_blademaster }
	employed_booner_reward_effect = { POS = bodyguard }
	root = {
		stress_impact = { craven = minor_stress_impact_gain }
	}
	stress_impact = { craven = minor_stress_impact_gain }
}

court.8195 = {
	type = court_event
	title = court.8195.t
	desc = court.8195.desc
	theme = court
	cooldown = { years = 25 }
	court_scene = {
		button_position_character = scope:position_holder
		roles = {
			scope:position_holder = {
				group = event_group
				animation = marshal_wooden_sword
			}
			scope:portrait = {
				group = event_group
				animation = throne_room_wooden_sword
			}
			root = {
				group = event_group
				animation = idle
			}
		}
	}

	trigger = {
		employed_booner_trigger = { POS = bodyguard }
		any_courtier = {
			count >= 2
			court_8195_employed_booner_sparist_trigger = yes
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			any_court_position_holder = {
				has_court_position = bodyguard_court_position
				save_temporary_scope_as = position_temp
			}
			add = {
				value = "scope:position_temp.aptitude(bodyguard_court_position)"
				subtract = 3
			}
		}
	}

	immediate = {
		add_character_flag = {
			flag = court_employer_booner_cooldown
			years = 5
		}
		ordered_court_position_holder = {
			type = bodyguard_court_position
			limit = {
				employed_booner_pos_trigger = { POS = bodyguard }
			}
			order_by = "aptitude(bodyguard_court_position)"
			save_scope_as = position_holder
		}
		every_close_family_member = {
			limit = { court_8195_employed_booner_sparist_trigger = yes }
			add_to_list = sparists
		}
		every_warden_hostage = {
			limit = { court_8195_employed_booner_sparist_trigger = yes }
			add_to_list = sparists
		}
		every_in_list = {
			list = sparists
			limit = {
				save_temporary_scope_as = struggling_temp
				any_in_list = {
					list = sparists
					this != scope:struggling_temp
					prowess < scope:struggling_temp.prowess
				}
			}
			add_to_list = struggling
			remove_from_list = sparists
		}
		player_heir ?= { # Heir
			if = {
				limit = { is_in_list = sparists }
				save_scope_as = heir
				court_8191_portrait_effect = yes
				remove_from_list = sparists
			}
		}
		if = {
			limit = {
				NOT = { exists = scope:heir }
			}
			ordered_in_list = {
				list = sparists
				limit = {
					is_heir_of = root
					save_temporary_scope_as = heir_temp
				}
				order_by = {
					value = 0
					subtract = "root.primary_title.place_in_line_of_succession(scope:heir_temp)"
				}
				save_scope_as = heir
				court_8191_portrait_effect = yes
				remove_from_list = sparists
			}
		}
		ordered_in_list = { # Struggling
			list = struggling
			limit = { is_heir_of = root }
			alternative_limit = { is_child_of = root }
			alternative_limit = { always = yes }
			order_by = age
			save_scope_as = struggling
			court_8191_portrait_effect = yes
			remove_from_list = struggling
		}
		ordered_in_list = { # Oldest
			list = sparists
			limit = { is_heir_of = root }
			alternative_limit = { always = yes }
			order_by = age
			save_scope_as = oldest
			court_8191_portrait_effect = yes
			remove_from_list = sparists
		}
		ordered_in_list = { # Youngest
			list = sparists
			limit = { is_heir_of = root }
			alternative_limit = { always = yes }
			order_by = {
				value = 0
				subtract = age
			}
			save_scope_as = youngest
			court_8191_portrait_effect = yes
			remove_from_list = sparists
		}
		random_in_list = { # Hostage
			list = sparists
			limit = {
				is_hostage_of = root
				save_temporary_scope_as = hostage_temp
			}
			weight = {
				base = 1
				is_of_minor_interest_to_weight_up_modifier = { CHARACTER = root }
				is_of_major_interest_to_weight_up_modifier = { CHARACTER = root }
				modifier = {
					add = 1000
					root = {
						any_owned_story = {
							type = bp2_hostage_loyalty
							var:hostage_target ?= scope:hostage_temp
						}
					}
				}
			}
			save_scope_as = hostage
			court_8191_portrait_effect = yes
			remove_from_list = sparists
		}
		random_in_list = { # Interesting
			list = sparists
			limit = { is_heir_of = root }
			alternative_limit = { is_child_of = root }
			alternative_limit = { always = yes }
			weight = {
				base = 1
				is_of_minor_interest_to_weight_up_modifier = { CHARACTER = root }
				is_of_major_interest_to_weight_up_modifier = { CHARACTER = root }
			}
			save_scope_as = interesting
			court_8191_portrait_effect = yes
			remove_from_list = sparists
		}
		random_in_list = { # Extra
			list = sparists
			limit = { is_heir_of = root }
			alternative_limit = { is_child_of = root }
			alternative_limit = { always = yes }
			weight = {
				base = 1
				is_of_minor_interest_to_weight_up_modifier = { CHARACTER = root }
				is_of_major_interest_to_weight_up_modifier = { CHARACTER = root }
			}
			save_scope_as = extra
			court_8191_portrait_effect = yes
			remove_from_list = sparists
		}
		ordered_in_list = { # Bonus
			list = struggling
			limit = { is_heir_of = root }
			alternative_limit = { is_child_of = root }
			alternative_limit = { always = yes }
			order_by = {
				value = 0
				subtract = sum_of_all_skills_value
			}
			save_scope_as = bonus
			court_8191_portrait_effect = yes
			remove_from_list = struggling
		}
	}

	option = { # Teach me!
		name = court.8195.a
		trigger = {
			is_healthy = yes
			can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root }
		}
		court_8195_employed_booner_reward_effect = yes
		ai_chance = {
			base = 50
		}
	}

	option = { # Heir
		name = court.8195.b
		trigger = { exists = scope:heir }
		scope:heir = { court_8195_employed_booner_reward_effect = yes }
		ai_chance = {
			base = 10
			employer_boon_child_ai_chance_modifier = { TARGET = scope:heir }
		}
	}

	option = { # Struggling
		name = court.8195.c
		trigger = { exists = scope:struggling }
		scope:struggling = { court_8195_employed_booner_reward_effect = yes }
		ai_chance = {
			base = 10
			employer_boon_child_ai_chance_modifier = { TARGET = scope:struggling }
		}
	}

	option = { # Hostage
		name = court.8195.d
		trigger = { exists = scope:hostage }
		scope:hostage = { court_8195_employed_booner_reward_effect = yes }
		ai_chance = {
			base = 10
			employer_boon_child_ai_chance_modifier = { TARGET = scope:hostage }
		}
	}

	option = { # Interesting
		name = court.8195.e
		trigger = {
			exists = scope:interesting
			calc_true_if = {
				amount < 4
				AND = {
					is_healthy = yes
					can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root }
				}
				exists = scope:heir
				exists = scope:struggling
				exists = scope:hostage
			}
		}
		scope:interesting = { court_8195_employed_booner_reward_effect = yes }
		ai_chance = {
			base = 10
			employer_boon_child_ai_chance_modifier = { TARGET = scope:interesting }
		}
	}

	option = { # Eldest
		name = court.8195.f
		trigger = {
			exists = scope:oldest
			calc_true_if = {
				amount < 4
				AND = {
					is_healthy = yes
					can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root }
				}
				exists = scope:heir
				exists = scope:struggling
				exists = scope:hostage
				exists = scope:interesting
			}
		}
		scope:oldest = { court_8195_employed_booner_reward_effect = yes }
		ai_chance = {
			base = 10
			employer_boon_child_ai_chance_modifier = { TARGET = scope:oldest }
		}
	}

	option = { # Youngest
		name = court.8195.g
		trigger = {
			exists = scope:youngest
			calc_true_if = {
				amount < 4
				AND = {
					is_healthy = yes
					can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root }
				}
				exists = scope:heir
				exists = scope:struggling
				exists = scope:hostage
				exists = scope:interesting
				exists = scope:oldest
			}
		}
		scope:youngest = { court_8195_employed_booner_reward_effect = yes }
		ai_chance = {
			base = 10
			employer_boon_child_ai_chance_modifier = { TARGET = scope:youngest }
		}
	}

	option = { # Extra
		name = court.8195.h
		trigger = {
			exists = scope:extra
			calc_true_if = {
				amount < 4
				AND = {
					is_healthy = yes
					can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root }
				}
				exists = scope:heir
				exists = scope:struggling
				exists = scope:hostage
				exists = scope:interesting
				exists = scope:oldest
				exists = scope:youngest
			}
		}
		scope:extra = { court_8195_employed_booner_reward_effect = yes }
		ai_chance = {
			base = 10
			employer_boon_child_ai_chance_modifier = { TARGET = scope:extra }
		}
	}

	option = { # Bonus
		name = court.8195.i
		trigger = {
			exists = scope:bonus
			calc_true_if = {
				amount < 4
				AND = {
					is_healthy = yes
					can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root }
				}
				exists = scope:heir
				exists = scope:struggling
				exists = scope:hostage
				exists = scope:interesting
				exists = scope:oldest
				exists = scope:youngest
				exists = scope:extra
			}
		}
		scope:bonus = { court_8195_employed_booner_reward_effect = yes }
		ai_chance = {
			base = 10
			employer_boon_child_ai_chance_modifier = { TARGET = scope:bonus }
		}
	}
}

# Horse Master

court.8196 = {
	type = court_event
	title = court.8196.t
	desc = court.8196.desc
	theme = court
	cooldown = { years = 25 }
	court_scene = {
		button_position_character = scope:position_holder
		roles = {
			scope:position_holder = {
				group = event_group
				animation = inspect_weapon
			}
			root = {
				group = event_group
				animation = idle
			}
		}
	}

	trigger = {
		employed_booner_trigger = { POS = master_of_horse }
		employer_triple_modifier_trigger = { POS = master_of_horse }
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = {
				value = "court_position:master_of_horse_court_position.aptitude(master_of_horse_court_position)"
				subtract = 3
			}
		}
	}

	immediate = {
		add_character_flag = {
			flag = court_employer_booner_cooldown
			years = 5
		}
		ordered_court_position_holder = {
			type = master_of_horse_court_position
			limit = {
				employed_booner_pos_trigger = { POS = master_of_horse }
			}
			order_by = "aptitude(master_of_horse_court_position)"
			save_scope_as = position_holder
		}
	}

	option = { # MaA
		name = court.8196.a
		employed_booner_reward_effect = { POS = master_of_horse_1 }
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_boldness = -0.5
			}
		}
	}

	option = { # Advantage
		name = court.8196.b
		employed_booner_reward_effect = { POS = master_of_horse_2 }
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_energy = 0.5
			}
		}
	}

	option = { # Both!
		name = court.8196.c
		duel = {
			skill = martial
			value = decent_skill_rating
			10 = {
				min = 2
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
				}
				desc = court.8196.c.success
				send_interface_toast = {
					type = event_toast_effect_good
					title = court.8196.c.success
					right_icon = scope:position_holder
					employed_booner_reward_effect = { POS = master_of_horse_3 }
				}
			}
			10 = {
				min = 2
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
				}
				desc = court.8196.c.failure
				send_interface_toast = {
					type = event_toast_effect_bad
					title = court.8196.c.failure
					right_icon = scope:position_holder
					stress_impact = {
						base = minor_stress_impact_gain
					}
				}
			}
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_boldness = 0.5
				ai_rationality = -0.5
			}
		}
	}
}

# Caravan Master

court.8197 = {
	type = court_event
	title = court.8197.t
	desc = court.8197.desc
	theme = court
	cooldown = { years = 25 }
	court_scene = {
		button_position_character = scope:position_holder
		roles = {
			scope:position_holder = {
				group = event_group
				animation = writing
			}
			root = {
				group = event_group
				animation = idle
			}
		}
	}

	trigger = {
		employed_booner_trigger = { POS = travel_leader }
		employer_triple_modifier_trigger = { POS = travel_leader }
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = {
				value = "court_position:travel_leader_court_position.aptitude(travel_leader_court_position)"
				subtract = 3
			}
		}
	}

	immediate = {
		add_character_flag = {
			flag = court_employer_booner_cooldown
			years = 5
		}
		ordered_court_position_holder = {
			type = travel_leader_court_position
			limit = {
				employed_booner_pos_trigger = { POS = travel_leader }
			}
			order_by = "aptitude(travel_leader_court_position)"
			save_scope_as = position_holder
		}
	}

	option = { # Safety
		name = court.8197.a
		employed_booner_reward_effect = { POS = travel_leader_1 }
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_boldness = -0.5
			}
		}
	}

	option = { # Speed
		name = court.8197.b
		employed_booner_reward_effect = { POS = travel_leader_2 }
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_energy = 0.5
			}
		}
	}

	option = { # Both!
		name = court.8197.c
		duel = {
			skill = stewardship
			value = decent_skill_rating
			10 = {
				min = 2
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
				}
				desc = court.8197.c.success
				send_interface_toast = {
					type = event_toast_effect_good
					title = court.8197.c.success
					right_icon = scope:position_holder
					employed_booner_reward_effect = { POS = travel_leader_3 }
				}
			}
			10 = {
				min = 2
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
				}
				desc = court.8197.c.failure
				send_interface_toast = {
					type = event_toast_effect_bad
					title = court.8197.c.failure
					right_icon = scope:position_holder
					stress_impact = {
						base = minor_stress_impact_gain
					}
				}
			}
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_boldness = 0.5
				ai_rationality = -0.5
			}
		}
	}
}

# Antiquarian

scripted_trigger court_8198_employed_booner_artifact_trigger = {
	save_temporary_scope_as = artifact_temp
	root = {
		can_equip_artifact = scope:artifact_temp
		can_benefit_from_artifact = scope:artifact_temp
	}
	OR = {
		artifact_durability_percent < 0.75
		rarity = common
		rarity = masterwork
	}
	NOR = {
		has_variable = employed_boon_artifact
		has_variable = banner_house
		has_variable = banner_dynasty
		scope:broken_1 ?= this
		scope:broken_2 ?= this
		scope:broken_3 ?= this
		scope:broken_4 ?= this
		scope:weak_1 ?= this
		scope:weak_2 ?= this
		scope:weak_3 ?= this
		scope:weak_4 ?= this
	}
}

scripted_trigger court_8198_dynasty_opinion_trigger = {
	OR = {
		has_artifact_modifier = artifact_dynasty_opinion_1_modifier
		has_artifact_modifier = artifact_dynasty_opinion_2_modifier
		has_artifact_modifier = artifact_dynasty_opinion_3_modifier
		has_artifact_modifier = artifact_dynasty_opinion_4_modifier
		has_artifact_modifier = artifact_dynasty_opinion_5_modifier
		has_artifact_modifier = artifact_dynasty_opinion_6_modifier
		has_artifact_modifier = artifact_dynasty_opinion_7_modifier
		has_artifact_modifier = artifact_dynasty_opinion_8_modifier
	}
}

scripted_trigger court_8198_dynasty_prestige_trigger = {
	OR = {
		has_artifact_modifier = artifact_monthly_dynasty_prestige_1_modifier
		has_artifact_modifier = artifact_monthly_dynasty_prestige_2_modifier
		has_artifact_modifier = artifact_monthly_dynasty_prestige_3_modifier
		has_artifact_modifier = artifact_monthly_dynasty_prestige_4_modifier
	}
}

scripted_trigger court_8198_prestige_trigger = {
	OR = {
		has_artifact_modifier = artifact_monthly_prestige_add_1_modifier
		has_artifact_modifier = artifact_monthly_prestige_add_2_modifier
		has_artifact_modifier = artifact_monthly_prestige_add_3_modifier
		has_artifact_modifier = artifact_monthly_prestige_add_4_modifier
		has_artifact_modifier = artifact_monthly_prestige_add_5_modifier
		has_artifact_modifier = artifact_monthly_prestige_add_6_modifier
		has_artifact_modifier = artifact_monthly_prestige_add_7_modifier
		has_artifact_modifier = artifact_monthly_prestige_add_8_modifier
	}
}

scripted_trigger court_8198_court_grandeur_trigger = {
	OR = {
		has_artifact_modifier = artifact_court_grandeur_baseline_add_1_modifier
		has_artifact_modifier = artifact_court_grandeur_baseline_add_2_modifier
		has_artifact_modifier = artifact_court_grandeur_baseline_add_3_modifier
		has_artifact_modifier = artifact_court_grandeur_baseline_add_4_modifier
		has_artifact_modifier = artifact_court_grandeur_baseline_add_5_modifier
		has_artifact_modifier = artifact_court_grandeur_baseline_add_6_modifier
	}
}

scripted_trigger court_8198_prowess_trigger = {
	OR = {
		has_artifact_modifier = artifact_prowess_1_modifier
		has_artifact_modifier = artifact_prowess_2_modifier
		has_artifact_modifier = artifact_prowess_3_modifier
		has_artifact_modifier = artifact_prowess_4_modifier
		has_artifact_modifier = artifact_prowess_5_modifier
		has_artifact_modifier = artifact_prowess_6_modifier
		has_artifact_modifier = artifact_prowess_7_modifier
		has_artifact_modifier = artifact_prowess_8_modifier
		has_artifact_modifier = artifact_prowess_9_modifier
		has_artifact_modifier = artifact_prowess_10_modifier
		has_artifact_modifier = artifact_prowess_11_modifier
	}
}

scripted_effect court_8198_add_modifier_effect = {
	custom_tooltip = court_8198_$MODIFIER$_tooltip
	hidden_effect = {  add_artifact_modifier = $MODIFIER$_$NUM$_modifier }
}

scripted_effect court_8198_select_modifier_effect = {
	random_list = {
		10 = {
			trigger = {
				artifact_slot_type = primary_armament
				OR = {
					court_8198_prowess_trigger = no
					AND = {
						court_8198_prowess_trigger = yes
						NOT = { has_artifact_modifier = artifact_prowess_11_modifier }
					}
				}
			}
			modifier = {
				court_8198_prowess_trigger = no
				add = 10
			}
			set_variable = { name = boon_modifier value = flag:prowess }
		}
		10 = {
			trigger = {
				ep1_artifact_is_court_artifact_trigger = yes
				OR = {
					court_8198_court_grandeur_trigger = no
					AND = {
						court_8198_court_grandeur_trigger = yes
						NOT = { has_artifact_modifier = artifact_court_grandeur_baseline_add_6_modifier }
					}
				}
			}
			modifier = {
				court_8198_court_grandeur_trigger = no
				add = 10
			}
			set_variable = { name = boon_modifier value = flag:grandeur }
		}
		10 = {
			trigger = {
				OR = {
					court_8198_prestige_trigger = no
					AND = {
						court_8198_prestige_trigger = yes
						NOT = { has_artifact_modifier = artifact_monthly_prestige_add_8_modifier }
					}
				}
			}
			modifier = {
				court_8198_prestige_trigger = no
				add = 10
			}
			set_variable = { name = boon_modifier value = flag:prestige }
		}
		10 = {
			trigger = {
				OR = {
					court_8198_dynasty_prestige_trigger = no
					AND = {
						court_8198_dynasty_prestige_trigger = yes
						NOT = { has_artifact_modifier = artifact_monthly_dynasty_prestige_4_modifier }
					}
				}
			}
			modifier = {
				court_8198_dynasty_prestige_trigger = no
				add = 10
			}
			set_variable = { name = boon_modifier value = flag:dynasty_prestige }
		}
		10 = {
			trigger = {
				OR = {
					court_8198_dynasty_opinion_trigger = no
					AND = {
						court_8198_dynasty_opinion_trigger = yes
						NOT = { has_artifact_modifier = artifact_dynasty_opinion_8_modifier }
					}
				}
			}
			modifier = {
				court_8198_dynasty_opinion_trigger = no
				add = 10
			}
			set_variable = { name = boon_modifier value = flag:dynasty_opinion }
		}
	}
}

scripted_effect court_8198_employed_booner_broken_effect = {
	add_durability = {
		value = {
			value = artifact_max_durability
			multiply = 0.25
		}
	}
}

scripted_effect court_8198_employed_booner_weak_effect = {
	switch = {
		trigger = var:boon_modifier
		flag:prowess = {
			court_8198_add_modifier_effect = { MODIFIER = artifact_prowess NUM = 2 }
		}
		flag:grandeur = {
			court_8198_add_modifier_effect = { MODIFIER = artifact_court_grandeur_baseline_add NUM = 2 }
		}
		flag:prestige = {
			court_8198_add_modifier_effect = { MODIFIER = artifact_monthly_prestige_add NUM = 2 }
		}
		flag:dynasty_prestige = {
			court_8198_add_modifier_effect = { MODIFIER = artifact_monthly_dynasty_prestige NUM = 1 }
		}
		flag:dynasty_opinion = {
			court_8198_add_modifier_effect = { MODIFIER = artifact_dynasty_opinion NUM = 3 }
		}
	}
	set_variable = {
		name = employed_boon_artifact
		years = 50
	}
}

court.8198 = {
	type = court_event
	title = court.8198.t
	desc = court.8198.desc
	theme = court
	cooldown = { years = 25 }
	court_scene = {
		button_position_character = scope:position_holder
		roles = {
			scope:position_holder = {
				group = event_group
				animation = thinking
			}
			root = {
				group = event_group
				animation = idle
			}
		}
	}

	trigger = {
		employed_booner_trigger = { POS = antiquarian }
		any_character_artifact = {
			count >= 2
			court_8198_employed_booner_artifact_trigger = yes
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = {
				value = "court_position:antiquarian_court_position.aptitude(antiquarian_court_position)"
				subtract = 3
			}
		}
	}

	immediate = {
		add_character_flag = {
			flag = court_employer_booner_cooldown
			years = 5
		}
		ordered_court_position_holder = {
			type = antiquarian_court_position
			limit = {
				employed_booner_pos_trigger = { POS = antiquarian }
			}
			order_by = "aptitude(antiquarian_court_position)"
			save_scope_as = position_holder
		}
		every_character_artifact = {
			limit = {
				artifact_durability_percent < 0.75
				court_8198_employed_booner_artifact_trigger = yes
			}
			add_to_list = broken
		}
		every_character_artifact = {
			limit = {
				OR = {
					rarity = common
					rarity = masterwork
				}
				court_8198_employed_booner_artifact_trigger = yes
			}
			add_to_list = weak
		}
		ordered_in_list = {
			list = broken
			limit = {
				is_unique = yes
				court_8198_employed_booner_artifact_trigger = yes
			}
			alternative_limit = {
				is_equipped = yes
				court_8198_employed_booner_artifact_trigger = yes
			}
			alternative_limit = { court_8198_employed_booner_artifact_trigger = yes }
			max = 4
			check_range_bounds = no
			order_by = {
				value = 0
				subtract = artifact_durability_percent
			}
			if = {
				limit = { exists = scope:broken_3 }
				save_scope_as = broken_4
			}
			else_if = {
				limit = { exists = scope:broken_2 }
				save_scope_as = broken_3
			}
			else_if = {
				limit = { exists = scope:broken_1 }
				save_scope_as = broken_2
			}
			else = { save_scope_as = broken_1 }
		}
		ordered_in_list = {
			list = broken
			limit = {
				is_unique = yes
				court_8198_employed_booner_artifact_trigger = yes
			}
			alternative_limit = {
				is_equipped = yes
				court_8198_employed_booner_artifact_trigger = yes
			}
			alternative_limit = { court_8198_employed_booner_artifact_trigger = yes }
			max = 4
			check_range_bounds = no
			order_by = artifact_wealth_quality_average_value
			if = {
				limit = { exists = scope:weak_3 }
				save_scope_as = weak_4
				court_8198_select_modifier_effect = yes
			}
			else_if = {
				limit = { exists = scope:weak_2 }
				save_scope_as = weak_3
				court_8198_select_modifier_effect = yes
			}
			else_if = {
				limit = { exists = scope:weak_1 }
				save_scope_as = weak_2
				court_8198_select_modifier_effect = yes
			}
			else = {
				save_scope_as = weak_1
				court_8198_select_modifier_effect = yes
			}
		}
	}

	option = { # Weak 1
		name = court.8198.a
		trigger = { exists = scope:weak_1 }
		scope:weak_1 = { court_8198_employed_booner_weak_effect = yes }
		ai_chance = {
			base = 10
			employer_boon_artifact_ai_chance_modifier = { TARGET = scope:weak_1 }
		}
	}

	option = { # Weak 2
		name = court.8198.b
		trigger = { exists = scope:weak_2 }
		scope:weak_2 = { court_8198_employed_booner_weak_effect = yes }
		ai_chance = {
			base = 10
			employer_boon_artifact_ai_chance_modifier = { TARGET = scope:weak_2 }
		}
	}

	option = { # Weak 3
		name = court.8198.c
		trigger = { exists = scope:weak_3 }
		scope:weak_3 = { court_8198_employed_booner_weak_effect = yes }
		ai_chance = {
			base = 10
			employer_boon_artifact_ai_chance_modifier = { TARGET = scope:weak_3 }
		}
	}

	option = { # Broken 1
		name = court.8198.d
		trigger = { exists = scope:broken_1 }
		scope:broken_1 = { court_8198_employed_booner_broken_effect = yes }
		ai_chance = {
			base = 10
			employer_boon_artifact_ai_chance_modifier = { TARGET = scope:broken_1 }
		}
	}

	option = { # Broken 2
		name = court.8198.e
		trigger = {
			exists = scope:broken_2
			calc_true_if = {
				amount < 4
				exists = scope:weak_1
				exists = scope:weak_2
				exists = scope:weak_3
				exists = scope:broken_1
			}
		}
		scope:broken_2 = { court_8198_employed_booner_broken_effect = yes }
		ai_chance = {
			base = 10
			employer_boon_artifact_ai_chance_modifier = { TARGET = scope:broken_2 }
		}
	}

	option = { # Broken 3
		name = court.8198.f
		trigger = {
			exists = scope:broken_3
			calc_true_if = {
				amount < 4
				exists = scope:weak_1
				exists = scope:weak_2
				exists = scope:weak_3
				exists = scope:broken_1
				exists = scope:broken_2
			}
		}
		scope:broken_3 = { court_8198_employed_booner_broken_effect = yes }
		ai_chance = {
			base = 10
			employer_boon_artifact_ai_chance_modifier = { TARGET = scope:broken_3 }
		}
	}

	option = { # Weak 4
		name = court.8198.g
		trigger = {
			exists = scope:weak_4
			calc_true_if = {
				amount < 4
				exists = scope:weak_1
				exists = scope:broken_1
				exists = scope:weak_2
				exists = scope:broken_2
				exists = scope:weak_3
				exists = scope:broken_3
			}
		}
		scope:weak_4 = { court_8198_employed_booner_weak_effect = yes }
		ai_chance = {
			base = 10
			employer_boon_artifact_ai_chance_modifier = { TARGET = scope:weak_4 }
		}
	}

	option = { # Broken 4
		name = court.8198.h
		trigger = {
			exists = scope:broken_4
			calc_true_if = {
				amount < 4
				exists = scope:weak_1
				exists = scope:broken_1
				exists = scope:weak_2
				exists = scope:broken_2
				exists = scope:weak_3
				exists = scope:broken_3
				exists = scope:weak_4
			}
		}
		scope:broken_4 = { court_8198_employed_booner_broken_effect = yes }
		ai_chance = {
			base = 10
			employer_boon_artifact_ai_chance_modifier = { TARGET = scope:broken_4 }
		}
	}

	option = { # Everything
		name = court.8198.i
		employed_booner_reward_effect = { POS = antiquarian }
		ai_chance = {
			base = 25
		}
	}
}

# Hunt Master

court.8199 = {
	type = court_event
	title = court.8199.t
	desc = court.8199.desc
	theme = court
	cooldown = { years = 25 }
	court_scene = {
		button_position_character = scope:position_holder
		roles = {
			scope:position_holder = {
				group = event_group
				animation = hunting_knife_start
			}
			root = {
				group = event_group
				animation = idle
			}
		}
	}

	trigger = {
		employed_booner_trigger = { POS = master_of_hunt }
		employer_triple_modifier_trigger = { POS = master_of_hunt }
		any_vassal = { vassal_stance = glory_hound }
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = {
				value = "court_position:master_of_hunt_court_position.aptitude(master_of_hunt_court_position)"
				subtract = 3
			}
		}
	}

	immediate = {
		add_character_flag = {
			flag = court_employer_booner_cooldown
			years = 5
		}
		ordered_court_position_holder = {
			type = master_of_hunt_court_position
			limit = {
				employed_booner_pos_trigger = { POS = master_of_hunt }
			}
			order_by = "aptitude(master_of_hunt_court_position)"
			save_scope_as = position_holder
		}
	}

	option = { # Success
		name = court.8199.a
		employed_booner_reward_effect = { POS = master_of_hunt_1 }
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_boldness = -0.5
			}
		}
	}

	option = { # Cost
		name = court.8199.b
		employed_booner_reward_effect = { POS = master_of_hunt_2 }
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_energy = 0.5
			}
		}
	}

	option = { # Both!
		name = court.8199.c
		duel = {
			skill = prowess
			value = decent_skill_rating
			10 = {
				min = 2
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
				}
				desc = court.8199.c.success
				send_interface_toast = {
					type = event_toast_effect_good
					title = court.8199.c.success
					right_icon = scope:position_holder
					employed_booner_reward_effect = { POS = master_of_hunt_3 }
				}
			}
			10 = {
				min = 2
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
				}
				desc = court.8199.c.failure
				send_interface_toast = {
					type = event_toast_effect_bad
					title = court.8199.c.failure
					right_icon = scope:position_holder
					stress_impact = {
						base = minor_stress_impact_gain
					}
				}
			}
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_boldness = 0.5
				ai_rationality = -0.5
			}
		}
	}
}

# Royal Architect

court.8200 = {
	type = court_event
	title = court.8200.t
	desc = court.8200.desc
	theme = court
	cooldown = { years = 25 }
	court_scene = {
		button_position_character = scope:position_holder
		roles = {
			scope:position_holder = {
				group = event_group
				animation = writing
			}
			root = {
				group = event_group
				animation = idle
			}
		}
	}

	trigger = {
		employed_booner_trigger = { POS = royal_architect }
		employer_triple_modifier_trigger = { POS = royal_architect }
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = {
				value = "court_position:royal_architect_court_position.aptitude(royal_architect_court_position)"
				subtract = 3
			}
		}
	}

	immediate = {
		add_character_flag = {
			flag = court_employer_booner_cooldown
			years = 5
		}
		ordered_court_position_holder = {
			type = royal_architect_court_position
			limit = {
				employed_booner_pos_trigger = { POS = royal_architect }
			}
			order_by = "aptitude(royal_architect_court_position)"
			save_scope_as = position_holder
		}
	}

	option = { # Success
		name = court.8200.a
		employed_booner_reward_effect = { POS = royal_architect_1 }
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_boldness = -0.5
			}
		}
	}

	option = { # Cost
		name = court.8200.b
		employed_booner_reward_effect = { POS = royal_architect_2 }
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_energy = 0.5
			}
		}
	}

	option = { # Both!
		name = court.8200.c
		duel = {
			skill = stewardship
			value = decent_skill_rating
			10 = {
				min = 2
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
				}
				desc = court.8200.c.success
				send_interface_toast = {
					type = event_toast_effect_good
					title = court.8200.c.success
					right_icon = scope:position_holder
					employed_booner_reward_effect = { POS = royal_architect_3 }
				}
			}
			10 = {
				min = 2
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
				}
				desc = court.8200.c.failure
				send_interface_toast = {
					type = event_toast_effect_bad
					title = court.8200.c.failure
					right_icon = scope:position_holder
					stress_impact = {
						base = minor_stress_impact_gain
					}
				}
			}
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_boldness = 0.5
				ai_rationality = -0.5
			}
		}
	}
}

# Cupbearer

court.8201 = {
	type = court_event
	title = court.8201.t
	desc = court.8201.desc
	theme = court
	cooldown = { years = 25 }
	court_scene = {
		button_position_character = scope:position_holder
		roles = {
			scope:position_holder = {
				group = event_group
				animation = thinking
			}
			root = {
				group = event_group
				animation = idle
			}
		}
	}

	trigger = {
		employed_booner_trigger = { POS = cupbearer }
		employer_triple_modifier_trigger = { POS = cupbearer }
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = {
				value = "court_position:cupbearer_court_position.aptitude(cupbearer_court_position)"
				subtract = 3
			}
		}
	}

	immediate = {
		add_character_flag = {
			flag = court_employer_booner_cooldown
			years = 5
		}
		ordered_court_position_holder = {
			type = cupbearer_court_position
			limit = {
				employed_booner_pos_trigger = { POS = cupbearer }
			}
			order_by = "aptitude(cupbearer_court_position)"
			save_scope_as = position_holder
		}
	}

	option = { # Courtly Vassals
		name = court.8201.a
		employed_booner_reward_effect = { POS = cupbearer_1 }
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_boldness = -0.5
			}
		}
	}

	option = { # Servants Cost
		name = court.8201.b
		employed_booner_reward_effect = { POS = cupbearer_2 }
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_energy = 0.5
			}
		}
	}

	option = { # Both!
		name = court.8201.c
		duel = {
			skill = prowess
			value = decent_skill_rating
			10 = {
				min = 2
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
				}
				desc = court.8201.c.success
				send_interface_toast = {
					type = event_toast_effect_good
					title = court.8201.c.success
					right_icon = scope:position_holder
					employed_booner_reward_effect = { POS = cupbearer_3 }
				}
			}
			10 = {
				min = 2
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
				}
				desc = court.8201.c.failure
				send_interface_toast = {
					type = event_toast_effect_bad
					title = court.8201.c.failure
					right_icon = scope:position_holder
					stress_impact = {
						base = minor_stress_impact_gain
					}
				}
			}
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_boldness = 0.5
				ai_rationality = -0.5
			}
		}
	}
}

# Lady-in-Waiting

court.8203 = {
	type = court_event
	title = court.8203.t
	desc = court.8203.desc
	theme = court
	cooldown = { years = 25 }
	court_scene = {
		button_position_character = scope:position_holder
		roles = {
			scope:position_holder = {
				group = event_group
				animation = admiration
			}
			root = {
				group = event_group
				animation = scheme
			}
		}
	}

	trigger = {
		employed_booner_trigger = { POS = lady_in_waiting }
		employer_triple_modifier_trigger = { POS = lady_in_waiting }
	}

	weight_multiplier = {
		base = 1
		modifier = {
			any_court_position_holder = {
				has_court_position = lady_in_waiting_court_position
				save_temporary_scope_as = position_temp
			}
			add = {
				value = "scope:position_temp.aptitude(lady_in_waiting_court_position)"
				subtract = 3
			}
		}
	}

	immediate = {
		add_character_flag = {
			flag = court_employer_booner_cooldown
			years = 5
		}
		ordered_court_position_holder = {
			type = lady_in_waiting_court_position
			limit = {
				employed_booner_pos_trigger = { POS = lady_in_waiting }
			}
			order_by = "aptitude(lady_in_waiting_court_position)"
			save_scope_as = position_holder
		}
	}

	option = { # Success
		name = court.8203.a
		employed_booner_reward_effect = { POS = lady_in_waiting_1 }
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_boldness = -0.5
			}
		}
	}

	option = { # Cost
		name = court.8203.b
		employed_booner_reward_effect = { POS = lady_in_waiting_2 }
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_energy = 0.5
			}
		}
	}

	option = { # Both!
		name = court.8203.c
		duel = {
			skill = diplomacy
			value = decent_skill_rating
			10 = {
				min = 2
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
				}
				desc = court.8203.c.success
				send_interface_toast = {
					type = event_toast_effect_good
					title = court.8203.c.success
					right_icon = scope:position_holder
					employed_booner_reward_effect = { POS = lady_in_waiting_3 }
				}
			}
			10 = {
				min = 2
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
				}
				desc = court.8203.c.failure
				send_interface_toast = {
					type = event_toast_effect_bad
					title = court.8203.c.failure
					right_icon = scope:position_holder
					stress_impact = {
						base = minor_stress_impact_gain
					}
				}
			}
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_boldness = 0.5
				ai_rationality = -0.5
			}
		}
	}
}

# Food Taster

court.8204 = {
	type = court_event
	title = court.8204.t
	desc = court.8204.desc
	theme = court
	cooldown = { years = 25 }
	court_scene = {
		button_position_character = scope:position_holder
		roles = {
			scope:position_holder = {
				group = event_group
				animation = thinking
			}
			root = {
				group = event_group
				animation = idle
			}
		}
	}

	trigger = {
		employed_booner_trigger = { POS = food_taster }
		employer_triple_modifier_trigger = { POS = food_taster }
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = {
				value = "court_position:food_taster_court_position.aptitude(food_taster_court_position)"
				subtract = 3
			}
		}
	}

	immediate = {
		add_character_flag = {
			flag = court_employer_booner_cooldown
			years = 5
		}
		ordered_court_position_holder = {
			type = food_taster_court_position
			limit = {
				employed_booner_pos_trigger = { POS = food_taster }
			}
			order_by = "aptitude(food_taster_court_position)"
			save_scope_as = position_holder
		}
	}

	option = { # Food Cost
		name = court.8204.a
		employed_booner_reward_effect = { POS = food_taster_1 }
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_greed = 0.5
			}
		}
	}

	option = { # Scheme Resistance
		name = court.8204.b
		employed_booner_reward_effect = { POS = food_taster_2 }
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_boldness = -0.5
			}
		}
	}

	option = { # Both!
		name = court.8204.c
		duel = {
			skill = intrigue
			value = decent_skill_rating
			10 = {
				min = 2
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
				}
				desc = court.8204.c.success
				send_interface_toast = {
					type = event_toast_effect_good
					title = court.8204.c.success
					right_icon = scope:position_holder
					employed_booner_reward_effect = { POS = food_taster_3 }
				}
			}
			10 = {
				min = 2
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
				}
				desc = court.8204.c.failure
				send_interface_toast = {
					type = event_toast_effect_bad
					title = court.8204.c.failure
					right_icon = scope:position_holder
					stress_impact = {
						base = minor_stress_impact_gain
					}
				}
			}
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_boldness = 0.5
				ai_rationality = -0.5
			}
		}
	}
}

# Poor Court Position Holder - Salary Review Edition

scripted_trigger court_8301_aptitude_trigger = { aptitude:$POS$_court_position < $VALUE$ }

scripted_trigger court_8301_position_trigger = {
	switch = {
		trigger = has_court_position
		court_physician_court_position = {
			court_8301_aptitude_trigger = { POS = court_physician VALUE = $VALUE$ }
		}
		cultural_emissary_court_position = {
			court_8301_aptitude_trigger = { POS = cultural_emissary VALUE = $VALUE$ }
		}
		keeper_of_swans_court_position = {
			court_8301_aptitude_trigger = { POS = keeper_of_swans VALUE = $VALUE$ }
		}
		chief_qadi_court_position = {
			court_8301_aptitude_trigger = { POS = chief_qadi VALUE = $VALUE$ }
		}
		garuda_court_position = {
			court_8301_aptitude_trigger = { POS = garuda VALUE = $VALUE$ }
		}
		court_gardener_court_position = {
			court_8301_aptitude_trigger = { POS = court_gardener VALUE = $VALUE$ }
		}
		lady_in_waiting_court_position = {
			court_8301_aptitude_trigger = { POS = lady_in_waiting VALUE = $VALUE$ }
		}
		antiquarian_court_position = {
			court_8301_aptitude_trigger = { POS = antiquarian VALUE = $VALUE$ }
		}
		travel_leader_court_position = {
			court_8301_aptitude_trigger = { POS = travel_leader VALUE = $VALUE$ }
		}
		wet_nurse_court_position = {
			court_8301_aptitude_trigger = { POS = wet_nurse VALUE = $VALUE$ }
		}
		court_tutor_court_position = {
			court_8301_aptitude_trigger = { POS = court_tutor VALUE = $VALUE$ }
		}
		food_taster_court_position = {
			court_8301_aptitude_trigger = { POS = food_taster VALUE = $VALUE$ }
		}
		master_of_horse_court_position = {
			court_8301_aptitude_trigger = { POS = master_of_horse VALUE = $VALUE$ }
		}
		master_of_hunt_court_position = {
			court_8301_aptitude_trigger = { POS = master_of_hunt VALUE = $VALUE$ }
		}
		royal_architect_court_position = {
			court_8301_aptitude_trigger = { POS = royal_architect VALUE = $VALUE$ }
		}
		high_almoner_court_position = {
			court_8301_aptitude_trigger = { POS = high_almoner VALUE = $VALUE$ }
		}
		seneschal_court_position = {
			court_8301_aptitude_trigger = { POS = seneschal VALUE = $VALUE$ }
		}
		cupbearer_court_position = {
			court_8301_aptitude_trigger = { POS = cupbearer VALUE = $VALUE$ }
		}
		chief_eunuch_court_position = {
			court_8301_aptitude_trigger = { POS = chief_eunuch VALUE = $VALUE$ }
		}
		court_jester_court_position = {
			court_8301_aptitude_trigger = { POS = court_jester VALUE = $VALUE$ }
		}
		court_poet_court_position = {
			court_8301_aptitude_trigger = { POS = court_poet VALUE = $VALUE$ }
		}
		court_musician_court_position = {
			court_8301_aptitude_trigger = { POS = court_musician VALUE = $VALUE$ }
		}
		bodyguard_court_position = {
			court_8301_aptitude_trigger = { POS = bodyguard VALUE = $VALUE$ }
		}
		champion_court_position = {
			court_8301_aptitude_trigger = { POS = champion VALUE = $VALUE$ }
		}
		executioner_court_position = {
			court_8301_aptitude_trigger = { POS = executioner VALUE = $VALUE$ }
		}
		court_artificer_court_position = {
			court_8301_aptitude_trigger = { POS = court_artificer VALUE = $VALUE$ }
		}
		master_assassin_court_position = {
			court_8301_aptitude_trigger = { POS = master_assassin VALUE = $VALUE$ }
		}
		cave_hermit_court_position = {
			court_8301_aptitude_trigger = { POS = cave_hermit VALUE = $VALUE$ }
		}
		chronicler_court_position = {
			court_8301_aptitude_trigger = { POS = chronicler VALUE = $VALUE$ }
		}
		court_scholar_court_position = {
			court_8301_aptitude_trigger = { POS = court_scholar VALUE = $VALUE$ }
		}
		charioteer_court_position = {
			court_8301_aptitude_trigger = { POS = charioteer VALUE = $VALUE$ }
		}
		bookmaker_court_position = {
			court_8301_aptitude_trigger = { POS = bookmaker VALUE = $VALUE$ }
		}
		akolouthos_court_position = {
			court_8301_aptitude_trigger = { POS = akolouthos VALUE = $VALUE$ }
		}
		court_brewmaster_court_position = {
			court_8301_aptitude_trigger = { POS = court_brewmaster VALUE = $VALUE$ }
		}
		court_astrologer_court_position = {
			court_8301_aptitude_trigger = { POS = court_astrologer VALUE = $VALUE$ }
		}
		fallback = { always = no }
	}
}

scripted_effect court_8301_aptitude_effect = {
	if = {
		limit = {
			NOT = { exists = var:penalized_position }
			has_court_position = $POS$_court_position
			aptitude:$POS$_court_position < $VALUE$
		}
		set_variable = {
			name = penalized_position
			value = flag:$POS$
			years = 5
		}
	}
}

scripted_effect court_8301_position_effect = {
	court_8301_aptitude_effect = { POS = court_physician VALUE = $VALUE$ }
	court_8301_aptitude_effect = { POS = cultural_emissary VALUE = $VALUE$ }
	court_8301_aptitude_effect = { POS = keeper_of_swans VALUE = $VALUE$ }
	court_8301_aptitude_effect = { POS = chief_qadi VALUE = $VALUE$ }
	court_8301_aptitude_effect = { POS = garuda VALUE = $VALUE$ }
	court_8301_aptitude_effect = { POS = court_gardener VALUE = $VALUE$ }
	court_8301_aptitude_effect = { POS = lady_in_waiting VALUE = $VALUE$ }
	court_8301_aptitude_effect = { POS = antiquarian VALUE = $VALUE$ }
	court_8301_aptitude_effect = { POS = travel_leader VALUE = $VALUE$ }
	court_8301_aptitude_effect = { POS = wet_nurse VALUE = $VALUE$ }
	court_8301_aptitude_effect = { POS = court_tutor VALUE = $VALUE$ }
	court_8301_aptitude_effect = { POS = food_taster VALUE = $VALUE$ }
	court_8301_aptitude_effect = { POS = master_of_horse VALUE = $VALUE$ }
	court_8301_aptitude_effect = { POS = master_of_hunt VALUE = $VALUE$ }
	court_8301_aptitude_effect = { POS = royal_architect VALUE = $VALUE$ }
	court_8301_aptitude_effect = { POS = high_almoner VALUE = $VALUE$ }
	court_8301_aptitude_effect = { POS = seneschal VALUE = $VALUE$ }
	court_8301_aptitude_effect = { POS = cupbearer VALUE = $VALUE$ }
	court_8301_aptitude_effect = { POS = chief_eunuch VALUE = $VALUE$ }
	court_8301_aptitude_effect = { POS = court_jester VALUE = $VALUE$  }
	court_8301_aptitude_effect = { POS = court_poet VALUE = $VALUE$  }
	court_8301_aptitude_effect = { POS = court_musician VALUE = $VALUE$ }
	court_8301_aptitude_effect = { POS = bodyguard VALUE = $VALUE$ }
	court_8301_aptitude_effect = { POS = champion VALUE = $VALUE$ }
	court_8301_aptitude_effect = { POS = executioner VALUE = $VALUE$ }
	court_8301_aptitude_effect = { POS = court_artificer VALUE = $VALUE$ }
	court_8301_aptitude_effect = { POS = master_assassin VALUE = $VALUE$ }
	court_8301_aptitude_effect = { POS = cave_hermit VALUE = $VALUE$ }
	court_8301_aptitude_effect = { POS = chronicler VALUE = $VALUE$ }
	court_8301_aptitude_effect = { POS = court_scholar VALUE = $VALUE$ }
	court_8301_aptitude_effect = { POS = charioteer VALUE = $VALUE$ }
	court_8301_aptitude_effect = { POS = bookmaker VALUE = $VALUE$ }
	court_8301_aptitude_effect = { POS = akolouthos VALUE = $VALUE$ }
	court_8301_aptitude_effect = { POS = court_brewmaster VALUE = $VALUE$ }
	court_8301_aptitude_effect = { POS = court_astrologer VALUE = $VALUE$ }
}

scripted_effect court_8301_revoke_effect = {
	scope:liege = {
		revoke_court_position = {
			recipient = scope:position_holder
			court_position = $POS$_court_position
		}
		remove_character_flag = free_revoke_cost
	}
}

scripted_effect court_8301_fire_effect = {
	switch = {
		trigger = var:penalized_position
		flag:court_physician = { court_8301_revoke_effect = { POS = court_physician } }
		flag:cultural_emissary = { court_8301_revoke_effect = { POS = cultural_emissary } }
		flag:keeper_of_swans = { court_8301_revoke_effect = { POS = keeper_of_swans } }
		flag:chief_qadi = { court_8301_revoke_effect = { POS = chief_qadi } }
		flag:garuda = { court_8301_revoke_effect = { POS = garuda } }
		flag:court_gardener  = { court_8301_revoke_effect = { POS = court_gardener } }
		flag:lady_in_waiting = { court_8301_revoke_effect = { POS = lady_in_waiting } }
		flag:antiquarian = { court_8301_revoke_effect = { POS = antiquarian } }
		flag:travel_leader = { court_8301_revoke_effect = { POS = travel_leader } }
		flag:wet_nurse = { court_8301_revoke_effect = { POS = wet_nurse } }
		flag:court_tutor = { court_8301_revoke_effect = { POS = court_tutor } }
		flag:food_taster = { court_8301_revoke_effect = { POS = food_taster } }
		flag:master_of_horse = { court_8301_revoke_effect = { POS = master_of_horse } }
		flag:master_of_hunt = { court_8301_revoke_effect = { POS = master_of_hunt } }
		flag:royal_architect = { court_8301_revoke_effect = { POS = royal_architect } }
		flag:high_almoner = { court_8301_revoke_effect = { POS = high_almoner } }
		flag:seneschal = { court_8301_revoke_effect = { POS = seneschal } }
		flag:cupbearer = { court_8301_revoke_effect = { POS = cupbearer } }
		flag:chief_eunuch = { court_8301_revoke_effect = { POS = chief_eunuch } }
		flag:court_jester = { court_8301_revoke_effect = { POS = court_jester } }
		flag:court_poet  = { court_8301_revoke_effect = { POS = court_poet } }
		flag:court_musician  = { court_8301_revoke_effect = { POS = court_musician } }
		flag:bodyguard = { court_8301_revoke_effect = { POS = bodyguard } }
		flag:champion = { court_8301_revoke_effect = { POS = champion } }
		flag:executioner = { court_8301_revoke_effect = { POS = executioner } }
		flag:court_artificer = { court_8301_revoke_effect = { POS = court_artificer } }
		flag:master_assassin = { court_8301_revoke_effect = { POS = master_assassin } }
		flag:cave_hermit = { court_8301_revoke_effect = { POS = cave_hermit } }
		flag:chronicler = { court_8301_revoke_effect = { POS = chronicler } }
		flag:court_scholar = { court_8301_revoke_effect = { POS = court_scholar } }
		flag:charioteer = { court_8301_revoke_effect = { POS = charioteer } }
		flag:bookmaker = { court_8301_revoke_effect = { POS = bookmaker } }
		flag:akolouthos = { court_8301_revoke_effect = { POS = akolouthos } }
		flag:court_brewmaster = { court_8301_revoke_effect = { POS = court_brewmaster } }
		flag:court_astrologer = { court_8301_revoke_effect = { POS = court_astrologer } }
	}
	remove_variable = penalized_position
}

court.8301 = {
	type = court_event
	title = court.8301.t
	desc = {
		desc = court.8301.intro
		desc = court.8301.detractor
		desc = court.8301.desc
	}
	theme = court
	cooldown = { years = 10 }
	court_scene = {
		button_position_character = scope:position_holder
		roles = {
			scope:position_holder = {
				group = event_group
				animation = anger
			}
			scope:detractor = {
				group = event_group
				animation = dismissal
			}
			root = {
				group = event_group
				animation = happiness
			}
		}
	}

	trigger = {
		any_court_position_holder = { } # Easy out
		any_court_position_holder = {
			NOR = {
				root = {
					is_target_in_variable_list = {
						name = halved_position_salary_employees
						target = prev
					}
				}
				root = {
					is_target_in_variable_list = {
						name = increased_position_salary_employees
						target = prev
					}
				}
			}
			court_8301_position_trigger = { VALUE = 3 }
		}
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		save_scope_as = liege
		add_character_flag = free_revoke_cost
		random_court_position_holder = {
			limit = {
				court_8301_position_trigger = { VALUE = 3 }
			}
			save_scope_as = position_holder
			court_8301_position_effect = { VALUE = 3 }
		}
		ordered_courtier = {
			limit = {	
				this != scope:position_holder
				is_of_major_interest_to_root_trigger = yes
				is_available_adult = yes
			}
			order_by = {
				value = 0
				subtract = "opinion(scope:position_holder)"
			}
			save_scope_as = detractor
		}
		if = {
			limit = { NOT = { exists = scope:detractor } }
			ordered_courtier = {
				limit = {	
					this != scope:position_holder
					is_of_minor_interest_to_root_trigger = yes
					is_available_adult = yes
				}
				order_by = {
					value = 0
					subtract = "opinion(scope:position_holder)"
				}
				save_scope_as = detractor
			}
		}
		if = {
			limit = { NOT = { exists = scope:detractor } }
			ordered_courtier = {
				limit = {
					this != scope:position_holder
					is_available_adult = yes
				}
				order_by = {
					value = 0
					subtract = "opinion(scope:position_holder)"
				}
				save_scope_as = detractor
			}
		}
		scope:detractor ?= {
			progress_towards_rival_effect = {
				REASON = rival_poor_court_position_holder
				CHARACTER = scope:position_holder
				OPINION = default_rival_opinion
			}
		}
	}

	option = {
		name = court.8301.a
		scope:position_holder = {
			custom_tooltip = {
				text = halved_position_salary_tt
				scope:liege = {
					add_to_variable_list = {
						name = halved_position_salary_employees
						target = scope:position_holder
						years = 10
					}
				}
			}
		}
		custom_tooltip = employer_booner_invalidated_tt
		reverse_add_opinion = {
			target = scope:position_holder
			modifier = angry_opinion
			opinion = -15
		}
		stress_impact = {
			generous = minor_stress_impact_gain
			diligent = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = 0.5
				ai_vengefulness = -0.5
			}
		}
	}

	option = {
		name = court.8301.b
		scope:position_holder = { court_8301_fire_effect = yes } # TIT-53703 awaiting code support to actually be free
		stress_impact = {
			arbitrary = minor_stress_impact_gain
			compassionate = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = 1
				ai_boldness = 1
			}
		}
	}

	option = {
		name = court.8301.c
		reverse_add_opinion = {
			target = scope:position_holder
			modifier = grateful_opinion
			opinion = 15
		}
		if = {
			limit = { exists = scope:detractor }
			reverse_add_opinion = {
				target = scope:detractor
				modifier = annoyed_opinion
				opinion = -10
			}
		}
		stress_impact = {
			honest = minor_stress_impact_gain
			just = minor_stress_impact_gain
		}
		ai_chance = {
			ai_value_modifier = {
				ai_greed = -1
				ai_boldness = -1
			}
		}
	}

	after = { remove_character_flag = free_revoke_cost }
}

# Bad Holder Improves

court.8311 = {
	type = court_event
	title = court.8311.t
	desc = court.8311.desc
	theme = court
	cooldown = { years = 10 }
	court_scene = {
		button_position_character = scope:position_holder
		roles = {
			scope:position_holder = {
				group = event_group
				animation = thinking
			}
			root = {
				group = event_group
				animation = happiness
			}
		}
	}

	trigger = {
		is_ai = no # Performance
		has_royal_court = yes
		amenity_level = {
			target = court_lodging_standards
			value >= 3
		}
		any_court_position_holder = { } # Easy out
		any_court_position_holder = {
			court_8301_position_trigger = { VALUE = 3 }
			NOT = { exists = var:bonus_aptitude_role }
			NOT = { exists = var:court_8311_cooldown }
		}
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		save_scope_as = liege
		random_court_position_holder = {
			limit = {
				court_8301_position_trigger = { VALUE = 3 }
				NOT = { exists = var:bonus_aptitude_role }
				NOT = { exists = var:court_8311_cooldown }
			}
			weight = {
				base = 1
				modifier = { add = ai_energy }
			}
			save_scope_as = position_holder
			court_8301_position_effect = { VALUE = 3 }
			set_variable = {
				name = target_court_position
				value = var:penalized_position
			}
		}
	}

	option = {
		name = court.8311.a
		scope:position_holder = {
			if = { # Diplomacy
				limit = {
					OR = {
						var:target_court_position ?= flag:cultural_emissary
						var:target_court_position ?= flag:chronicler
						var:target_court_position ?= flag:cupbearer
						var:target_court_position ?= flag:lady_in_waiting
						var:target_court_position ?= flag:court_jester
						var:target_court_position ?= flag:court_poet
						var:target_court_position ?= flag:court_musician
					}
				}
				add_diplomacy_skill = 1
			}
			else_if = { # Martial
				limit = {
					OR = {
						var:target_court_position ?= flag:akolouthos
						var:target_court_position ?= flag:master_of_horse
					}
				}
				add_martial_skill = 1
			}
			else_if = { # Stewardship
				limit = {
					OR = {
						var:target_court_position ?= flag:keeper_of_swans
						var:target_court_position ?= flag:royal_architect
						var:target_court_position ?= flag:court_gardener
						var:target_court_position ?= flag:travel_leader
						var:target_court_position ?= flag:seneschal
						var:target_court_position ?= flag:bookmaker

					}
				}
				add_stewardship_skill = 1
			}
			else_if = { # Intrigue
				limit = {
					OR = {
						var:target_court_position ?= flag:food_taster
						var:target_court_position ?= flag:chief_eunuch
						var:target_court_position ?= flag:executioner
						var:target_court_position ?= flag:master_assassin
						# SAS Change
						var:target_court_position ?= flag:rabble_rouser
						var:target_court_position ?= flag:femme_fatale
						var:target_court_position ?= flag:smuggler
						# SAS Change End

					}
				}
				add_intrigue_skill = 1
			}
			else_if = { # Learning
				limit = {
					OR = {
						var:target_court_position ?= flag:court_physician
						var:target_court_position ?= flag:chief_qadi
						var:target_court_position ?= flag:court_scholar
						var:target_court_position ?= flag:antiquarian
						var:target_court_position ?= flag:court_artificer
						var:target_court_position ?= flag:cave_hermit
						var:target_court_position ?= flag:wet_nurse
						var:target_court_position ?= flag:court_tutor
						var:target_court_position ?= flag:high_almoner
						var:target_court_position ?= flag:court_brewmaster
						var:target_court_position ?= flag:court_astrologer
					}
				}
				add_learning_skill = 1
			}
			else = { add_prowess_skill = 1 } # Prowess
			custom_tooltip = {
				text = bonus_aptitude_role_tt
				set_variable = {
					name = bonus_aptitude_role
					value = var:penalized_position
				}
			}
		}
	}

	after = {
		scope:position_holder = {
			remove_variable = target_court_position
			remove_variable = penalized_position
		}
	}
}

# Holder Wants Raise

court.8321 = {
	type = court_event
	title = court.8321.t
	desc = court.8321.desc
	theme = court
	cooldown = { years = 10 }
	court_scene = {
		button_position_character = scope:position_holder
		roles = {
			scope:position_holder = {
				group = event_group
				animation = debating
			}
			root = {
				group = event_group
				animation = thinking
			}
		}
	}

	trigger = {
		is_ai = no # Performance
		has_royal_court = yes
		any_court_position_holder = { } # Easy out
		any_court_position_holder = {
			NOR = {
				exists = var:court_8311_cooldown
				exists = var:bonus_aptitude_role
				root = {
					is_target_in_variable_list = {
						name = halved_position_salary_employees
						target = prev
					}
				}
				root = {
					is_target_in_variable_list = {
						name = increased_position_salary_employees
						target = prev
					}
				}
			}
			court_8301_position_trigger = { VALUE = 5 }
		}
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		save_scope_as = liege
		random_court_position_holder = {
			limit = {
				court_8301_position_trigger = { VALUE = 5 }
			}
			weight = {
				base = 1
				modifier = { add = ai_energy }
				modifier = { add = ai_greed }
			}
			save_scope_as = position_holder
			court_8301_position_effect = { VALUE = 5 }
			set_variable = {
				name = target_court_position
				value = var:penalized_position
			}
			remove_variable = penalized_position
		}
	}

	option = {
		name = court.8321.a
		scope:position_holder = {
			custom_tooltip = {
				text = increased_position_salary_tt
				scope:liege = {
					add_to_variable_list = {
						name = increased_position_salary_employees
						target = scope:position_holder
						years = 10
					}
				}
			}
			custom_tooltip = {
				text = bonus_aptitude_role_tt
				set_variable = {
					name = bonus_aptitude_role
					value = var:penalized_position
				}
			}
		}
		stress_impact = {
			greedy = minor_stress_impact_gain
		}
	}

	option = {
		name = court.8321.b
		duel = {
			skill = diplomacy
			value = decent_skill_rating
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
				}
				modifier = {
					add = 1
					scope:position_holder = { has_trait = content }
				}
				modifier = {
					add = 1
					scope:position_holder = { has_trait = generous }
				}
				modifier = {
					add = 1
					scope:position_holder = { has_trait = humble }
				}
				desc = court.8321.b.success
				send_interface_toast = {
					type = event_toast_effect_good
					title = court.8321.b.success
					right_icon = scope:position_holder
					pay_short_term_gold = {
						gold = scope:position_holder.minor_gold_value
						target = scope:position_holder
					}
					scope:position_holder = {
						custom_tooltip = {
							text = bonus_aptitude_role_tt
							set_variable = {
								name = bonus_aptitude_role
								value = var:penalized_position
							}
						}
					}
				}
			}
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
				}
				modifier = {
					add = 1
					scope:position_holder = { has_trait = ambitious }
				}
				modifier = {
					add = 1
					scope:position_holder = { has_trait = greedy }
				}
				modifier = {
					add = 1
					scope:position_holder = { has_trait = arrogant }
				}
				desc = court.8321.b.failure
				send_interface_toast = {
					type = event_toast_effect_bad
					title = court.8321.b.failure
					right_icon = scope:position_holder
					reverse_add_opinion = {
						target = scope:position_holder
						modifier = insulted_opinion
						opinion = -10
					}
				}
			}
		}
	}

	option = {
		name = court.8321.c
		reverse_add_opinion = {
			target = scope:position_holder
			modifier = disappointed_opinion
			opinion = -15
		}
		stress_impact = {
			generous = minor_stress_impact_gain
			profligate = minor_stress_impact_gain
		}
	}

	after = {
		scope:position_holder = { remove_variable = target_court_position }
	}
}
