﻿# PLAYER ONLY - AI uses the two separate interactions below this ( Promote/Harm Candidacy)
influence_candidacy_interaction = {
	icon = support_candidacy
	category = interaction_category_admin
	common_interaction = yes
	interface_priority = 100
	desc = influence_candidacy_interaction_desc

	target_type = title
	target_filter = recipient_de_jure_titles

	custom_character_sort = { governor_efficiency candidate_score }

	populate_recipient_list = {
		scope:actor = {
			house ?= {
				every_house_member = {
					limit = {
						is_independent_ruler = no
						has_government = administrative_government
						top_liege = scope:actor.top_liege
						any_valid_title_to_grant_trigger = {
							CANDIDATE = this
							TOP_LIEGE = scope:actor.top_liege
						}
					}
					add_to_list = characters
				}
			}
			if = {
				limit = { primary_title.tier >= tier_kingdom }
				every_courtier_or_guest = {
					limit = {
						is_independent_ruler = no
						has_government = administrative_government
						top_liege = scope:actor.top_liege
						any_valid_title_to_grant_trigger = {
							CANDIDATE = this
							TOP_LIEGE = scope:actor.top_liege
						}
					}
					add_to_list = characters
				}
			}
		}
	}

	can_be_picked_title = {
		trigger_if = {
			limit = { exists = scope:secondary_recipient }
			is_appointment_valid_trigger = {
				TITLE = scope:target
				CANDIDATE = scope:secondary_recipient
				TOP_LIEGE = scope:recipient
			}
		}
	}

	has_valid_target_showing_failures_only = {
		scope:target = {
			tier >= tier_duchy
			exists = holder
			holder = {
				top_liege = scope:recipient
				OR = {
					has_realm_law = acclamation_succession_law
					has_realm_law = appointment_succession_law
				}
			}
		}
	}

	is_shown = {
		scope:actor = {
			is_ai = no
			has_government = administrative_government
		}
		trigger_if = {
			limit = { exists = scope:secondary_recipient }
			scope:secondary_recipient = {
				is_independent_ruler = no
				has_government = administrative_government
				top_liege = scope:actor.top_liege
			}
		}
	}

	is_valid_showing_failures_only = {
	}

	can_send = {
		trigger_if = {
			limit = {
				OR = {
					scope:as_much_as_needed_influence_option = yes
					scope:major_influence_option = yes
					scope:medium_influence_option = yes
				}
			}
			scope:actor = {
				custom_tooltip = {
					text = support_candidacy_cap_reached_tt
					succession_appointment_score_invested = {
						title = scope:target
						candidate = scope:secondary_recipient
						value < scope:actor.appointment_investment_cap
					}
				}
			}

			# Check if the target is available or if they have decided to not compete for the throne
			trigger_if = {
				limit = {
					exists = scope:target
					scope:target.tier = scope:recipient.highest_held_title_tier
				}
				scope:secondary_recipient = {
					custom_tooltip = {
						text = admin_renounce_throne_desc
						NOR = {
							has_character_modifier = ep3_admin_renounce_throne_personal
							house ?= { has_house_modifier = ep3_admin_renounce_throne_house }
						}
					}
				}
			}
		}
	}

	redirect = {
		scope:recipient = {
			if = {
				limit = {
					NOT = { this = scope:actor.top_liege }
				}
				save_scope_as = secondary_recipient
				scope:actor.top_liege = {
					save_scope_as = recipient
				}
			}
		}
	}

	auto_accept = yes

	send_option = {
		flag = as_much_as_needed_influence_option
		localization = "as_much_as_needed_influence_option_desc"
	}
	send_option = {
		flag = major_influence_option
		localization = "major_influence_option_desc"
	}
	send_option = {
		flag = medium_influence_option
		localization = "medium_influence_option_desc"
		starts_enabled = { always = yes }
	}
	send_option = {
		flag = medium_influence_loss_option
		localization = "medium_influence_loss_option_desc"
	}
	send_option = {
		flag = major_influence_loss_option
		localization = "major_influence_loss_option_desc"
	}

	cost = {
		influence = {
			# Base cost
			switch = {
				trigger = yes
				scope:as_much_as_needed_influence_option = {
					add = {
						if = {
							limit = { exists = scope:secondary_recipient }
							value = {
								add = {
									value = "scope:target.current_heir.appointment_candidate_score(scope:target)"
									multiply = 1.1
								}
								subtract = "scope:secondary_recipient.appointment_candidate_score(scope:target)"
								multiply = 5
								min = 20 # We do this to prevent cases when the default score of the candidate is already much higher than that the heir
							}
						}
						else = { value = 20 } # Show the default cost if there is no candidate selected yet
						desc = BASE
					}
				}
				scope:major_influence_option = {
					add = {
						value = appointment_major_influence_cost
						desc = BASE
					}
				}
				scope:medium_influence_option = {
					add = {
						value = appointment_medium_influence_cost
						desc = BASE
					}
				}
				scope:medium_influence_loss_option = {
					add = {
						value = appointment_medium_influence_cost
						desc = BASE
					}
				}
				scope:major_influence_loss_option = {
					add = {
						value = appointment_major_influence_cost
						desc = BASE
					}
				}
			}

			save_temporary_value_as = calculated_base_cost

			# Gender modifiers
			if = {
				limit = {
					scope:secondary_recipient ?= {
						top_liege = { has_realm_law = male_preference_law }
						is_female = yes
					}
				}
				if = {
					limit = {
						OR = {
							scope:medium_influence_loss_option = yes
							scope:major_influence_loss_option = yes
						}
					}
					add = {
						value = scope:calculated_base_cost
						multiply = -0.5
						desc = male_preference_law
					}
				}
				else = {
					add = { # Double the (base) cost
						value = scope:calculated_base_cost
						desc = male_preference_law
					}
				}
			}
			else_if = {
				limit = {
					scope:secondary_recipient ?= {
						top_liege = { has_realm_law = female_preference_law }
						is_female = no
					}
				}
				if = {
					limit = {
						OR = {
							scope:medium_influence_loss_option = yes
							scope:major_influence_loss_option = yes
						}
					}
					add = {
						value = scope:calculated_base_cost
						multiply = -0.5
						desc = female_preference_law
					}
				}
				else = {
					add = { # Double the (base) cost
						value = scope:calculated_base_cost
						desc = female_preference_law
					}
				}
			}


			# Local bonuses
			if = {
				limit = {
					scope:actor = {
						domicile ?= {
							domicile_location.county = {
								scope:target ?= { is_de_jure_liege_or_above_target = prev }
							}
						}
					}
					scope:target ?= { tier < tier_empire }
				}
				add = {
					value = scope:calculated_base_cost
					multiply = {
						value = -0.25
						if = {
							limit = { # Increase the bonus if you have the "office" estate upgrade
								scope:actor = {
									domicile ?= { has_domicile_parameter = estate_local_theme_cost_reduction }
								}
							}
							add = estate_local_theme_cost_reduction_value
						}
					}
					desc = estate_location_in_area
				}
			}

			# Bureaucracy Legacy Perk Discount
			if = {
				limit = {
					scope:actor.dynasty ?= { has_dynasty_perk = ep3_administrative_legacy_2 }
				}
				add = {
					value = scope:calculated_base_cost
					multiply = -0.1
					desc = "[GetDynastyPerk('ep3_administrative_legacy_2').GetName]"
				}
			}

			# A dominant family gets to spend less influence
			if = {
				limit = {
					scope:actor.house ?= { is_dominant_family = yes }
				}
				add = {
					value = scope:calculated_base_cost
					multiply = -0.5
					desc = "[dominant_family|E]"
				}
			}
		}
	}

	localization_values = {
		AS_MUCH_AS_NEEDED_INFLUENCE_OPTION = scope:actor.appointment_score_max_tt_value
		MAJOR_INFLUENCE_OPTION = scope:actor.appointment_score_major_tt_value
		MEDIUM_INFLUENCE_OPTION = scope:actor.appointment_score_medium_tt_value
		MEDIUM_INFLUENCE_LOSS_OPTION = scope:actor.appointment_score_medium_loss_tt_value
		MAJOR_INFLUENCE_LOSS_OPTION = scope:actor.appointment_score_major_loss_tt_value
	}

	on_accept = {
		switch = {
			trigger = yes
			scope:as_much_as_needed_influence_option = {
				# Save the score value
				save_scope_value_as = {
					name = support_candidate_score
					value = {
						value = 0
						if = {
							limit = { exists = scope:target }
							add = {
								value = "scope:target.current_heir.appointment_candidate_score(scope:target)"
								multiply = 1.1
							}
							subtract = "scope:secondary_recipient.appointment_candidate_score(scope:target)"
						}
						min = 4 # We do this to prevent cases when the default score of the candidate is already much higher than that the heir
						multiply = scope:actor.appointment_score_interaction_multiplier_modifiers_value
					}
				}
				if = {
					limit = {
						scope:support_candidate_score >= 100
					}
					save_scope_value_as = {
						name = opinion_change_value
						value = 25
					}
				}
				else_if = {
					limit = {
						scope:support_candidate_score >= 80
					}
					save_scope_value_as = {
						name = opinion_change_value
						value = 20
					}
				}
				else_if = {
					limit = {
						scope:support_candidate_score >= 60
					}
					save_scope_value_as = {
						name = opinion_change_value
						value = 15
					}
				}
				else_if = {
					limit = {
						scope:support_candidate_score >= 40
					}
					save_scope_value_as = {
						name = opinion_change_value
						value = 10
					}
				}
				else_if = {
					limit = {
						scope:support_candidate_score >= 20
					}
					save_scope_value_as = {
						name = opinion_change_value
						value = 5
					}
				}
				else_if = {
					limit = {
						scope:support_candidate_score >= 10
					}
					save_scope_value_as = {
						name = opinion_change_value
						value = 3
					}
				}
				else = {
					save_scope_value_as = {
						name = opinion_change_value
						value = 1
					}
				}
			}
			scope:major_influence_option = {
				save_scope_value_as = {
					name = support_candidate_score
					value = {
						value = appointment_score_major_value
						multiply = scope:actor.appointment_score_interaction_multiplier_modifiers_value
					}
				}
				save_scope_value_as = {
					name = opinion_change_value
					value = 10
				}
			}
			scope:medium_influence_option = {
				# Save the score value
				save_scope_value_as = {
					name = support_candidate_score
					value = {
						value = appointment_score_medium_value
						multiply = scope:actor.appointment_score_interaction_multiplier_modifiers_value
					}
				}
				save_scope_value_as = {
					name = opinion_change_value
					value = 5
				}
			}
			scope:medium_influence_loss_option = {
				# Save the score value
				save_scope_value_as = {
					name = support_candidate_score
					value = {
						value = appointment_score_medium_loss_value
						multiply = scope:actor.appointment_score_interaction_multiplier_modifiers_value
					}
				}
				save_scope_value_as = {
					name = opinion_change_value
					value = -10
				}
			}
			scope:major_influence_loss_option = {
				# Save the score value
				save_scope_value_as = {
					name = support_candidate_score
					value = {
						value = appointment_score_major_loss_value
						multiply = scope:actor.appointment_score_interaction_multiplier_modifiers_value
					}
				}
				save_scope_value_as = {
					name = opinion_change_value
					value = -20
				}
			}
		}

		# Update the score for the corresponding title
		scope:target = {
			change_appointment_investment = {
				target = scope:secondary_recipient
				investor = scope:actor
				value = scope:support_candidate_score
			}
			if = {
				limit = { appointment_interactions_recipient_is_suitable_co_emperor_trigger = yes }
				diarch_promoted_as_administrative_candidate_get_best_tooltip_effect = yes
			}
		}

		if = {
			limit = {
				OR = {
					scope:as_much_as_needed_influence_option = yes
					scope:major_influence_option = yes
					scope:medium_influence_option = yes
				}
			}
			# Notify the supported character (unless they are the actor)
			scope:secondary_recipient ?= {
				if = {
					limit = {
						NOT = { this = scope:actor }
					}
					hidden_effect = {
						send_interface_message = {
							type = msg_candidacy_improved
							title = supported_candidacy_toast
							left_icon = scope:actor
							right_icon = scope:target
							show_as_tooltip = {
								scope:target = {
									change_appointment_investment = {
										target = scope:secondary_recipient
										investor = scope:actor
										value = scope:support_candidate_score
									}
								}
							}
						}
					}
				}
				if = {
					limit = {
						NOT = { house ?= scope:actor.house }
					}
					add_opinion = {
						modifier = supported_candidacy_opinion
						target = scope:actor
						opinion = scope:opinion_change_value
					}
					custom_tooltip = support_candidacy_success_reward_tt
				}
			}
		}
		else = {
			# Notify the harmed character (unless they are the actor)
			scope:secondary_recipient ?= {
				if = {
					limit = { this != scope:actor }
					hidden_effect = {
						send_interface_message = {
							type = msg_candidacy_harmed
							title = harmed_candidacy_toast
							left_icon = scope:actor
							right_icon = scope:target
							show_as_tooltip = {
								scope:target = {
									change_appointment_investment = {
										target = scope:secondary_recipient
										investor = scope:actor
										value = scope:support_candidate_score
									}
								}
							}
						}
					}
					add_opinion = {
						modifier = harmed_candidacy_opinion
						target = scope:actor
						opinion = scope:opinion_change_value
					}
				}
			}
		}
	}
}

# AI ONLY - Interaction is referenced in code, please don't rename it used by AI from code
support_candidacy_interaction = {
	icon = support_candidacy
	category = interaction_category_admin
	common_interaction = yes
	hidden = yes

	desc = support_candidacy_interaction_desc

	target_type = title
	target_filter = recipient_de_jure_titles

	can_be_picked_title = {
		is_appointment_valid_trigger = {
			TITLE = scope:target
			CANDIDATE = scope:secondary_recipient
			TOP_LIEGE = scope:recipient
		}
	}

	has_valid_target_showing_failures_only = {
		scope:target = {
			tier >= tier_duchy
			exists = holder
			
			holder.top_liege = scope:recipient
		}
	}

	is_shown = {
		scope:actor = {
			is_ai = yes
			has_government = administrative_government
		}
		scope:secondary_recipient = {
			is_independent_ruler = no
			has_government = administrative_government
			top_liege = scope:actor.top_liege
		}
	}

	is_valid_showing_failures_only = {
		any_valid_title_to_grant_trigger = {
			CANDIDATE = scope:secondary_recipient
			TOP_LIEGE = scope:recipient
		}
		scope:actor = {
			NOT = { is_at_war_with = scope:recipient }
		}
	}

	can_send = {
		is_appointment_valid_trigger = {
			TITLE = scope:target
			CANDIDATE = scope:secondary_recipient
			TOP_LIEGE = scope:recipient
		}
	}

	redirect = {
		scope:recipient = {
			save_scope_as = secondary_recipient
		}
		scope:actor.top_liege = {
			save_scope_as = recipient
		}
	}

	auto_accept = yes

	send_option = {
		flag = as_much_as_needed_influence_option
		localization = as_much_as_needed_influence_option_desc
	}
	send_option = {
		flag = major_influence_option
		localization = major_influence_option_desc
	}
	send_option = {
		flag = medium_influence_option
		localization = medium_influence_option_desc
		starts_enabled = { always = yes }
	}

	cost = {
		influence = {
			# Base cost
			switch = {
				trigger = yes
				scope:as_much_as_needed_influence_option = {
					add = {
						value = {
							add = {
								value = "scope:target.current_heir.appointment_candidate_score(scope:target)"
								multiply = 1.1
							}
							subtract = "scope:secondary_recipient.appointment_candidate_score(scope:target)"
							multiply = 5
							min = 20 # We do this to prevent cases when the default score of the candidate is already much higher than that the heir
						}
						desc = BASE
					}
				}
				scope:major_influence_option = {
					add = {
						value = appointment_major_influence_cost
						desc = BASE
					}
				}
				scope:medium_influence_option = {
					add = {
						value = appointment_medium_influence_cost
						desc = BASE
					}
				}
			}

			save_temporary_value_as = calculated_base_cost

			# Gender modifiers
			if = {
				limit = {
					scope:secondary_recipient ?= {
						top_liege = { has_realm_law = male_preference_law }
						is_female = yes
					}
				}
				add = { # Double the (base) cost
					value = scope:calculated_base_cost
					desc = male_preference_law
				}
			}
			else_if = {
				limit = {
					scope:secondary_recipient ?= {
						top_liege = { has_realm_law = female_preference_law }
						is_female = no
					}
				}
				add = { # Double the (base) cost
					value = scope:calculated_base_cost
					desc = female_preference_law
				}
			}


			# Local bonuses
			if = {
				limit = {
					scope:actor = {
						domicile ?= {
							domicile_location.county = {
								scope:target ?= { is_de_jure_liege_or_above_target = prev }
							}
						}
					}
					scope:target ?= { tier < tier_empire }
				}
				add = {
					value = scope:calculated_base_cost
					multiply = {
						value = -0.25
						if = {
							limit = { # Increase the bonus if you have the "office" estate upgrade
								scope:actor = {
									domicile ?= { has_domicile_parameter = estate_local_theme_cost_reduction }
								}
							}
							add = estate_local_theme_cost_reduction_value
						}
					}
					desc = estate_location_in_area
				}
			}

			# Bureaucracy Legacy Perk Discount
			if = {
				limit = {
					scope:actor.dynasty ?= { has_dynasty_perk = ep3_administrative_legacy_2 }
				}
				add = {
					value = scope:calculated_base_cost
					multiply = -0.1
					desc = "[GetDynastyPerk('ep3_administrative_legacy_2').GetName]"
				}
			}
		}
	}

	on_accept = {
		switch = {
			trigger = yes
			scope:as_much_as_needed_influence_option = {
				# Save the score value
				save_scope_value_as = {
					name = support_candidate_score
					value = {
						value = 0
						if = {
							limit = { exists = scope:target }
							add = {
								value = "scope:target.current_heir.appointment_candidate_score(scope:target)"
								multiply = 1.1
							}
							subtract = "scope:secondary_recipient.appointment_candidate_score(scope:target)"
						}
						min = 4 # We do this to prevent cases when the default score of the candidate is already much higher than that the heir
						multiply = scope:actor.appointment_score_interaction_multiplier_modifiers_value
					}
				}
				save_scope_value_as = {
					name = opinion_change_value
					value = 20
				}
			}
			scope:major_influence_option = {
				save_scope_value_as = {
					name = support_candidate_score
					value = {
						value = appointment_score_major_value
						multiply = scope:actor.appointment_score_interaction_multiplier_modifiers_value
					}
				}
				save_scope_value_as = {
					name = opinion_change_value
					value = 10
				}
			}
			scope:medium_influence_option = {
				# Save the score value
				save_scope_value_as = {
					name = support_candidate_score
					value = {
						value = appointment_score_medium_value
						multiply = scope:actor.appointment_score_interaction_multiplier_modifiers_value
					}
				}
				save_scope_value_as = {
					name = opinion_change_value
					value = 5
				}
			}
		}

		# Update the score for the corresponding title
		scope:target = {
			change_appointment_investment = {
				target = scope:secondary_recipient
				investor = scope:actor
				value = scope:support_candidate_score
			}
			if = {
				limit = { appointment_interactions_recipient_is_suitable_co_emperor_trigger = yes }
				diarch_promoted_as_administrative_candidate_get_best_tooltip_effect = yes
			}
		}


		# Notify the supported character (unless they are the actor)
		scope:secondary_recipient = {
			if = {
				limit = {
					NOT = { this = scope:actor }
				}
				hidden_effect = {
					send_interface_message = {
						type = msg_candidacy_improved
						title = supported_candidacy_toast
						left_icon = scope:actor
						right_icon = scope:target
						show_as_tooltip = {
							scope:target = {
								change_appointment_investment = {
									target = scope:secondary_recipient
									investor = scope:actor
									value = scope:support_candidate_score
								}
							}
						}
					}
				}
			}
		}
		if = {
			limit = {
				scope:secondary_recipient = {
					NOT = {
						house ?= scope:actor.house
					}
				}
			}
			scope:secondary_recipient = {
				add_opinion = {
					modifier = supported_candidacy_opinion
					target = scope:actor
					opinion = scope:opinion_change_value
				}
			}
		}

		scope:secondary_recipient = {
			custom_tooltip = support_candidacy_success_reward_tt
		}
	}

	# AI
	# Interaction is used by AI in code, don't change the frequency
	ai_frequency = 0

	ai_will_do = {
		base = 5

		# No one promoting... ripe for the taking
		modifier = {
			scope:target = {
				NOT = {
					any_title_heir = {
						"appointment_candidate_accumulated_score(scope:target)" > 0
					}
				}
				NOT = {
					current_heir = {
						exists = house
						exists = scope:actor.house
						house = scope:actor.house
					}
				}
			}
			add = 150
		}

		# Spending more influence in one go is better
		modifier = {
			scope:major_influence_option = yes
			factor = 1.1
		}

		# Promote characters we like
		modifier = {
			scope:actor = {
				opinion = {
					target = scope:secondary_recipient
					value >= medium_positive_opinion
				}
			}
			factor = 1.5
		}
		modifier = {
			scope:secondary_recipient = {
				is_close_family_of = scope:actor
			}
			factor = 3
		}
		modifier = {
			scope:secondary_recipient = {
				is_extended_family_of = scope:actor
			}
			factor = 1.5
		}
		modifier = {
			scope:actor = {
				has_relation_friend = scope:secondary_recipient
			}
			factor = 2
		}
		modifier = {
			scope:actor = {
				has_relation_best_friend = scope:secondary_recipient
			}
			factor = 10
		}

		# For the imperial title, we want to promote ourselves
		modifier = {
			scope:target.tier >= tier_empire
			scope:actor = scope:secondary_recipient
			factor = 5
		}

		# Prefer unlanded relatives
		modifier = {
			scope:target.tier < tier_empire
			scope:secondary_recipient = {
				is_ruler = no
			}
			factor = 2
		}

		# Prefer titles that are somewhat close to the capital
		modifier = {
			exists = scope:recipient.capital_province # Make sure the top liege has a capital
			scope:target = {
				title_capital_county = {
					squared_distance = {
						target = scope:recipient.capital_province
						value <= 130000
					}
				}
			}
			factor = 1.1
		}

		# Try to avoid promoting the same candidate for multiple titles if they are winning a title already
		modifier = {
			scope:secondary_recipient = {
				any_heir_title = {
					
					holder = {
						has_government = administrative_government
					}
				}
			}
			factor = 0
		}

		# Promote only one house member for each title
		modifier = {
			scope:target = {
				any_title_heir = {
					exists = house
					exists = scope:actor.house
					house = scope:actor.house
					"appointment_candidate_accumulated_score(scope:target)" > 0
				}
			}
			scope:secondary_recipient = {
				exists = house
				exists = scope:actor.house
				house = scope:actor.house
				"appointment_candidate_accumulated_score(scope:target)" <= 0
			}
			factor = 0
		}

		# Don't promote rivals
		modifier = {
			scope:actor = {
				has_relation_rival = scope:secondary_recipient
			}
			factor = 0
		}

		# Don't promote a candidate if your house is first in line
		modifier = {
			scope:target = {
				any_title_heir = {
					exists = house
					exists = scope:actor.house
					house = scope:actor.house
					scope:target = {
						place_in_line_of_succession = {
							target = prev
							value = 1
						}
					}
				}
			}
			factor = 0
		}

		# Don't promote your candidate if they are first in line
		modifier = {
			scope:target = {
				any_title_heir = {
					this = scope:secondary_recipient
					scope:target = {
						place_in_line_of_succession = {
							target = prev
							value = 1
						}
					}
				}
			}
			factor = 0
		}

		# Don't promote lowborn or characters of a different house
		modifier = {
			NOT = { exists = scope:secondary_recipient.house }
			factor = 0
		}
		modifier = {
			exists = scope:secondary_recipient.house
			exists = scope:actor.house
			NOT = { scope:actor.house = scope:secondary_recipient.house }
			factor = 0
		}

		modifier = { # For now
			scope:actor.top_liege = { has_realm_law = male_preference_law }
			scope:secondary_recipient = { is_female = yes }
			factor = 0
		}
		modifier = { # For now
			scope:actor.top_liege = { has_realm_law = female_preference_law }
			scope:secondary_recipient = { is_male = yes }
			factor = 0
		}

		# Don't outcompete someone you like
		modifier = {
			scope:target = {
				any_title_heir = {
					scope:target  = {
						place_in_line_of_succession = {
							target = prev
							value <= 3
						}
					}
					scope:actor = { has_any_good_relationship_with_character_trigger = { CHARACTER = prev } }
				}
			}
			factor = 0
		}

		# Don't support someone who has renounced their aspirations for the throne
		modifier = {
			scope:secondary_recipient = {
				OR = {
					has_character_modifier = ep3_admin_renounce_throne_personal
					house ?= { has_house_modifier = ep3_admin_renounce_throne_house }
				}
			}
			scope:target.tier = scope:recipient.highest_held_title_tier
			factor = 0
		}
	}
}

# AI ONLY - Smear campaign against a character to reduce score
harm_candidacy_interaction = {
	icon = harm_candidacy
	category = interaction_category_admin
	common_interaction = yes
	hidden = yes

	desc = harm_candidacy_interaction_desc

	target_type = title
	target_filter = secondary_recipient_de_jure_titles

	can_be_picked_title = {
		is_candidate_for_title_trigger = {
			TITLE = scope:target
			CANDIDATE = scope:secondary_recipient
		}
	}

	has_valid_target_showing_failures_only = {
		scope:target = {
			tier >= tier_duchy
			exists = holder
			holder = {
				top_liege = scope:recipient
			}
		}
	}

	is_shown = {
		scope:actor = {
			has_government = administrative_government
		}
		scope:secondary_recipient = {
			is_independent_ruler = no
			has_government = administrative_government
			top_liege = scope:actor.top_liege
		}
	}

	is_valid_showing_failures_only = {
		any_valid_title_to_grant_trigger = {
			CANDIDATE = scope:secondary_recipient
			TOP_LIEGE = scope:recipient
		}
	}

	can_send = {
		is_candidate_for_title_trigger = {
			TITLE = scope:target
			CANDIDATE = scope:secondary_recipient
		}
	}

	redirect = {
		scope:recipient = { save_scope_as = secondary_recipient }
		scope:actor.top_liege = { save_scope_as = recipient }
	}

	auto_accept = yes

	send_option = {
		flag = minor_influence_option
		localization = minor_influence_option_desc
		starts_enabled = { always = yes }
	}
	send_option = {
		flag = medium_influence_option
		localization = medium_influence_option_desc
	}
	send_option = {
		flag = major_influence_option
		localization = major_influence_option_desc
	}

	cost = {
		influence = {
			# Base cost
			switch = {
				trigger = yes
				scope:minor_influence_option = {
					add = {
						value = appointment_minor_influence_cost
						desc = BASE
					}
				}
				scope:medium_influence_option = {
					add = {
						value = appointment_medium_influence_cost
						desc = BASE
					}
				}
				scope:major_influence_option = {
					add = {
						value = appointment_major_influence_cost
						desc = BASE
					}
				}
			}

			save_temporary_value_as = calculated_base_cost

			# Gender modifiers
			if = {
				limit = {
					scope:secondary_recipient ?= {
						top_liege = { has_realm_law = male_preference_law }
						is_female = yes
					}
				}
				add = {
					value = scope:calculated_base_cost
					multiply = -0.5
					desc = male_preference_law
				}
			}
			else_if = {
				limit = {
					scope:secondary_recipient ?= {
						top_liege = { has_realm_law = female_preference_law }
						is_female = no
					}
				}
				add = {
					value = scope:calculated_base_cost
					multiply = -0.5
					desc = female_preference_law
				}
			}


			# Local bonuses
			if = {
				limit = {
					scope:actor = {
						domicile ?= {
							domicile_location.county = {
								scope:target ?= { is_de_jure_liege_or_above_target = prev }
							}
						}
					}
					scope:target ?= { tier < tier_empire }
				}
				add = {
					value = scope:calculated_base_cost
					multiply = {
						value = -0.25
						if = {
							limit = { # Increase the bonus if you have the "office" estate upgrade
								scope:actor = {
									domicile ?= { has_domicile_parameter = estate_local_theme_cost_reduction }
								}
							}
							add = estate_local_theme_cost_reduction_value
						}
					}
					desc = estate_location_in_area
				}
			}

			# Bureaucracy Legacy Perk Discount
			if = {
				limit = {
					scope:actor.dynasty ?= { has_dynasty_perk = ep3_administrative_legacy_2 }
				}
				add = {
					value = scope:calculated_base_cost
					multiply = -0.1
					desc = "[GetDynastyPerk('ep3_administrative_legacy_2').GetName]"
				}
			}
		}
	}

	on_accept = {
		switch = {
			trigger = yes
			scope:minor_influence_option = {
				# Save the score value
				save_scope_value_as = {
					name = harm_candidate_score
					value = {
						value = appointment_score_minor_loss_value
						multiply = scope:actor.appointment_score_interaction_multiplier_modifiers_value
					}
				}
				save_scope_value_as = {
					name = opinion_change_value
					value = -5
				}
			}
			scope:medium_influence_option = {
				# Save the score value
				save_scope_value_as = {
					name = harm_candidate_score
					value = {
						value = appointment_score_medium_loss_value
						multiply = scope:actor.appointment_score_interaction_multiplier_modifiers_value
					}
				}
				save_scope_value_as = {
					name = opinion_change_value
					value = -15
				}
			}
			scope:major_influence_option = {
				save_scope_value_as = {
					name = harm_candidate_score
					value = {
						value = appointment_score_major_loss_value
						multiply = scope:actor.appointment_score_interaction_multiplier_modifiers_value
					}
				}
				save_scope_value_as = {
					name = opinion_change_value
					value = -30
				}
			}
		}

		# Update the score for the corresponding title
		scope:target = {
			change_appointment_investment = {
				target = scope:secondary_recipient
				investor = scope:actor
				value = scope:harm_candidate_score
			}
		}

		# Handle opinion change and chance for a rivalry
		if = {
			limit = {
				scope:secondary_recipient = { this != scope:actor }
			}
			scope:secondary_recipient = {
				add_opinion = {
					modifier = harmed_candidacy_opinion
					target = scope:actor
					opinion = scope:opinion_change_value
				}
				hidden_effect = {
					send_interface_message = {
						type = msg_candidacy_harmed
						title = harmed_candidacy_toast
						left_icon = scope:actor
						right_icon = scope:target
						show_as_tooltip = {
							scope:target = {
								change_appointment_investment = {
									target = scope:secondary_recipient
									investor = scope:actor
									value = scope:harm_candidate_score
								}
							}
						}
					}
				}
			}
			scope:actor = {
				send_interface_toast = {
					type = event_toast_effect_bad
					title = harm_candidate_rival_progress_toast
					left_icon = scope:secondary_recipient
					scope:secondary_recipient = {
						progress_towards_rival_effect = {
							REASON = rival_harmed_candidacy
							CHARACTER = scope:actor
							OPINION = 0
						}
					}
				}
			}
		}
	}

	ai_targets = {
		ai_recipients = scripted_relations
		max = 10
	}

	ai_frequency = 24

	ai_potential = {
		influence > major_influence_value
		has_government = administrative_government
		ai_honor <= 25
	}

	ai_will_do = {
		base = 0
		modifier = {
			scope:actor = {
				has_relation_rival = scope:secondary_recipient
			}
			add = 100
		}
		modifier = {
			scope:actor = {
				has_relation_nemesis = scope:secondary_recipient
			}
			add = 150
		}
		modifier = {
			scope:actor = {
				opinion = {
					target = scope:secondary_recipient
					value < medium_positive_opinion
				}
			}
			add = 20
		}
		modifier = {
			scope:secondary_recipient = {
				is_close_family_of = scope:actor
			}
			add = -50
		}
		modifier = {
			scope:secondary_recipient = {
				is_extended_family_of = scope:actor
			}
			add = -25
		}
		modifier = {
			scope:actor = {
				OR = {
					has_trait = ambitious
					has_trait = callous
					has_trait = fickle
				}
			}
			add = 40
		}
		modifier = {
			scope:actor = {
				has_usable_hook = scope:secondary_recipient
			}
			add = -10
		}
		modifier = {
			scope:actor = {
				OR = {
					has_relation_friend = scope:secondary_recipient
					has_relation_lover = scope:secondary_recipient
				}
			}
			factor = 0
		}
	}
}

# Request support from another character
request_appointment_support = {
	category = interaction_category_admin
	common_interaction = yes
	interface_priority = 70
	custom_character_sort = { governor_efficiency candidate_score }

	desc = request_appointment_support_desc

	target_type = title
	target_filter = actor_top_liege_de_jure_titles

	populate_recipient_list = {
		scope:actor = {
			every_succession_appointment_invested_candidate = {
				limit = {
					this != scope:recipient
					is_alive = yes
					has_government = administrative_government
					# Check that they are still valid to be appointed
					any_valid_title_to_grant_trigger = {
						CANDIDATE = this
						TOP_LIEGE = scope:actor.top_liege
					}
				}
				add_to_list = characters
			}
			# We limit how many recipients to check for the AI for performance, player gets the unabridged list
			if = {
				limit = {
					is_ai = no
				}
				house = {
					every_house_member = {
						limit = {
							this != scope:recipient
							has_government = administrative_government
							any_valid_title_to_grant_trigger = {
								CANDIDATE = this
								TOP_LIEGE = scope:actor.top_liege
							}
						}
						add_to_list = characters
					}
				}
			}
		}
	}

	can_be_picked_title = {
		trigger_if = {
			limit = { exists = scope:secondary_recipient }
			is_appointment_valid_trigger = {
				TITLE = scope:target
				CANDIDATE = scope:secondary_recipient
				TOP_LIEGE = scope:actor.top_liege
			}
			trigger_if = {
				limit = {
					scope:actor = { is_ai = yes }
					scope:secondary_recipient = { has_succession_appointment_investors = scope:target }
				}
				scope:target = {
					any_succession_appointment_investors = {
						candidate = scope:secondary_recipient
						this = scope:actor
					}
				}
			}
		}
	}

	has_valid_target_showing_failures_only = {
		scope:target = {
			tier >= tier_duchy
			exists = holder
			holder = {
				top_liege = scope:actor.top_liege
			}
		}
		scope:actor = {
			trigger_if = {
				limit = { is_ai = yes }
				any_succession_appointment_invested_title = {
					this = scope:target
				}
			}
		}
	}

	is_shown = {
		scope:actor = { has_government = administrative_government }
		scope:recipient = {
			this != scope:actor
			has_government = administrative_government
			top_liege = scope:actor.top_liege
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			house = {
				any_house_member = {
					has_government = administrative_government
					any_valid_title_to_grant_trigger = {
						CANDIDATE = this
						TOP_LIEGE = scope:actor.top_liege
					}
					count >= 1
				}
			}
			is_in_civil_war = no
		}
		scope:recipient = {
			influence >= appointment_minor_influence_cost
			is_in_civil_war = no
		}
	}

	can_send = {
		trigger_if = {
			limit = { scope:hook = no }
			scope:actor = {
				gold >= medium_gold_value
			}
		}
		custom_tooltip = {
			text = appointment_cannot_support_themself
			NOT = { scope:recipient = scope:secondary_recipient }
		}
	}

	send_option = {
		is_valid = {
			scope:actor = {
				has_usable_hook = scope:recipient
			}
		}
		flag = hook
		localization = GENERIC_SPEND_A_HOOK
	}
	should_use_extra_icon = {
		scope:actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	send_options_exclusive = no

	on_accept = {
		scope:actor = {
			if = {
				limit = {
					scope:hook = yes
					has_hook = scope:recipient
				}
				use_hook = scope:recipient
			}
		}
		if = {
			limit = {
				scope:hook = no
			}
			scope:actor = {
				pay_short_term_gold = {
					target = scope:recipient
					gold = medium_gold_value
				}
			}
		}
		if = {
			limit = { # Players gets to accept/decline a specific suggestion
				scope:recipient = { is_ai = no }
			}
			scope:recipient ={
				change_influence = {
					value = appointment_medium_influence_cost
					multiply = -1
				}
			}
			scope:target = {
				change_appointment_investment = {
					target = scope:secondary_recipient
					investor = scope:recipient
					value = appointment_score_medium_value
				}
			}
			scope:actor = {
				add_opinion = {
					target = scope:recipient
					modifier = thankful_opinion
					opinion = 30
				}
				trigger_event = ep3_interactions_events.0201
			}
		}
		else = { # The AI randomizes the amount of support
			scope:recipient = { custom_tooltip = request_appointment_support_tt }
			hidden_effect = {
				random_list = {
					60 = {
						scope:actor = {
							save_scope_value_as = {
								name = request_support_score
								value = appointment_score_minor_value
							}
							send_interface_message = {
								type = msg_candidacy_improved
								title = supported_candidacy_toast
								left_icon = scope:secondary_recipient
								right_icon = scope:target
								custom_tooltip = request_appointment_support_toast_tt
								scope:target = {
									change_appointment_investment = {
										target = scope:secondary_recipient
										investor = scope:recipient
										value = scope:request_support_score
									}
								}
							}
						}
						scope:recipient = {
							change_influence = {
								value = appointment_minor_influence_cost
								multiply = -1
							}
						}
					}
					30 = {
						scope:actor = {
							save_scope_value_as = {
								name = request_support_score
								value = appointment_score_medium_value
							}
							send_interface_message = {
								type = msg_candidacy_improved
								title = supported_candidacy_toast
								left_icon = scope:secondary_recipient
								right_icon = scope:target
								custom_tooltip = request_appointment_support_toast_tt
								scope:target = {
									change_appointment_investment = {
										target = scope:secondary_recipient
										investor = scope:recipient
										value = scope:request_support_score
									}
								}
							}
						}
						scope:recipient = {
							change_influence = {
								value = appointment_medium_influence_cost
								multiply = -1
							}
						}
						opinion_modifier = {
							who = scope:recipient
							opinion_target = scope:actor
							multiplier = 0.2
							min = 0
						}
						modifier = {
							factor = 1.5
							scope:recipient = { has_any_good_relationship_with_character_trigger = { CHARACTER = scope:actor } }
						}
						modifier = {
							factor = 2
							scope:recipient = { has_any_best_good_relationship_with_character_trigger = { CHARACTER = scope:actor } }
						}
						modifier = {
							factor = 0
							scope:recipient = { influence < appointment_medium_influence_cost }
						}
					}
					10 = {
						scope:actor = {
							save_scope_value_as = {
								name = request_support_score
								value = appointment_score_major_value
							}
							send_interface_message = {
								type = msg_candidacy_improved
								title = supported_candidacy_toast
								left_icon = scope:secondary_recipient
								right_icon = scope:target
								custom_tooltip = request_appointment_support_toast_tt
								scope:target = {
									change_appointment_investment = {
										target = scope:secondary_recipient
										investor = scope:recipient
										value = scope:request_support_score
									}
								}
							}
						}
						scope:recipient = {
							change_influence = {
								value = appointment_major_influence_cost
								multiply = -1
							}
						}
						opinion_modifier = {
							who = scope:recipient
							opinion_target = scope:actor
							multiplier = 0.3
							min = 0
						}
						modifier = {
							factor = 1.5
							scope:recipient = { has_any_good_relationship_with_character_trigger = { CHARACTER = scope:actor } }
						}
						modifier = {
							factor = 2
							scope:recipient = { has_any_best_good_relationship_with_character_trigger = { CHARACTER = scope:actor } }
						}
						modifier = {
							factor = 0
							scope:recipient = { influence < appointment_major_influence_cost }
						}
					}
				}
			}
			scope:actor = { trigger_event = ep3_interactions_events.0201 }
		}
	}

	on_decline = {
		scope:actor = {
			add_opinion = {
				target = scope:recipient
				modifier = disappointed_opinion
				opinion = -10
			}
			trigger_event = ep3_interactions_events.0202
		}
	}

	auto_accept = {
		custom_description = {
			text = "spending_hook"
			subject = scope:actor
			object = scope:recipient
			scope:hook = yes
			scope:recipient = { is_ai = yes }
		}
	}

	ai_accept = {
		base = -40

		# Opinion Factor
		opinion_modifier = {
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 0.5
			desc = AI_SIMPLE_OPINION_REASON
		}

		# Admin
		modifier = {
			influence >= {
				value = monumental_influence_value
				multiply = 3
			}
			add = 20
			desc = plenty_of_influence_reason
		}
		modifier = {
			influence >= massive_influence_value
			influence < {
				value = monumental_influence_value
				multiply = 3
			}
			add = 10
			desc = has_influence_reason
		}
		modifier = {
			influence < major_influence_value
			add = -100
			desc = not_enough_influence_reason
		}
		modifier = { # Don't support actor if recipient holds the title (they should want to secure it for their own family first)
			exists = scope:target
			scope:target.holder = scope:recipient
			exists = scope:recipient.house
			exists = scope:secondary_recipient
			NOT = { scope:secondary_recipient.house ?= scope:recipient.house }
			add = -25
			desc = requesting_my_title_reason
		}
		modifier = { # Don't support actor if there is a close family member within the top 3 candidates
			scope:target ?= {
				any_title_heir = {
					scope:target ?= {
						place_in_line_of_succession = {
							target = prev
							value <= 3
						}
					}
					is_close_family_of = scope:recipient
				}
			}
			exists = scope:secondary_recipient
			NOT = { # Unless secondary_recipient is, in fact, one of these
				scope:secondary_recipient = {
					scope:target ?= {
						place_in_line_of_succession = {
							target = prev
							value <= 3
						}
					}
					is_close_family_of = scope:recipient
				}
			}
			add = -100
			desc = close_family_in_line_of_succession
		}
		modifier = { # More reluctant to lend support towards titles held by top liege
			exists = scope:target
			scope:target.holder = {
				is_independent_ruler = yes
				NOT = { this = scope:actor } # Assuming the top liege isn't the one doing the requesting
			}
			add = -25
			desc = targeting_top_liege_title
		}
		modifier = { # If you are from a powerful family, and they are not, they are more likely to accept
			scope:actor.house ?= {
				is_powerful_family = yes
			}
			scope:recipient.house ?= {
				is_powerful_family = no
				is_dominant_family = no
			}
			add = 15
			desc = your_house_is_powerful_reason
		}
		modifier = { # If you are from a dominant family, and they are not, they are more likely to accept
			scope:actor.house ?= {
				is_dominant_family = yes
			}
			scope:recipient.house ?= {
				is_dominant_family = no
			}
			add = 25
			desc = your_house_is_dominant_reason
		}
		modifier = { # If they are from a powerful family, and you are not, they are more likely to refuse
			scope:recipient.house ?= {
				is_powerful_family = yes
			}
			scope:actor.house ?= {
				is_powerful_family = no
				is_dominant_family = no
			}
			add = -15
			desc = their_house_is_powerful_reason
		}
		modifier = { # If they are from a dominant family, and you are not, they are more likely to refuse
			scope:recipient.house ?= {
				is_dominant_family = yes
			}
			scope:actor.house ?= {
				is_dominant_family = no
			}
			add = -25
			desc = their_house_is_dominant_reason
		}
		modifier = { # Difference in influence level
			NOT = { scope:actor.influence_level = scope:recipient.influence_level }
			add = {
				add = {
					add = 10
					multiply = scope:actor.influence_level
				}
				subtract = {
					add = 10
					multiply = scope:recipient.influence_level
				}
			}
			desc = difference_in_influence_level_reason
		}

		# Relations to actor
		modifier = {
			scope:actor = {
				has_relation_rival = scope:recipient
			}
			add = -100
			desc = AI_YOUR_RIVAL
		}
		modifier = {
			scope:actor = {
				has_relation_nemesis = scope:recipient
			}
			add = -150
			desc = offer_vassalization_interaction_aibehavior_nemesis_tt # Reused loc
		}
		modifier = {
			scope:recipient = {
				is_close_family_of = scope:actor
			}
			add = 50
			desc = CLOSE_FAMILY_REASON
		}
		modifier = {
			scope:recipient = {
				is_extended_family_of = scope:actor
			}
			add = 25
			desc = EXTENDED_FAMILY_REASON
		}
		modifier = {
			exists = scope:actor.house
			scope:recipient = {
				NOR = {
					is_close_family_of = scope:actor
					is_extended_family_of = scope:actor
				}
				exists = house
				house = scope:actor.house
			}
			add = 5
			desc = YOU_ARE_MY_HOUSE_MEMBER
		}
		modifier = {
			scope:actor = {
				has_relation_friend = scope:recipient
				NOT = { has_relation_best_friend = scope:recipient }
			}
			add = 15
			desc = WE_ARE_FRIENDS
		}
		modifier = {
			scope:actor = {
				has_relation_best_friend = scope:recipient
			}
			add = 30
			desc = WE_ARE_BEST_FRIENDS
		}

		# Relations to secondary_recipient (the character you want them to support)
		modifier = {
			scope:recipient = {
				has_relation_rival = scope:secondary_recipient
				NOT = { has_relation_nemesis = scope:secondary_recipient }
			}
			add = -50
			desc = RIVAL_TO_ME_REASON
		}
		modifier = {
			scope:recipient = {
				has_relation_nemesis = scope:secondary_recipient
			}
			add = -100
			desc = NEMESIS_TO_ME_REASON
		}

		# Relations to current title holder
		modifier = {
			exists = scope:target
			scope:recipient = {
				has_relation_rival = scope:target.holder
				NOT = { has_relation_nemesis = scope:target.holder }
				liege = scope:target.holder
				liege != scope:actor # Don't worry about liege relation when the liege is the one requesting support
			}
			add = 25
			desc = AI_THEIR_RIVAL
		}
		modifier = {
			exists = scope:target
			scope:recipient = {
				has_relation_nemesis = scope:target.holder
				liege = scope:target.holder
				liege != scope:actor # Don't worry about liege relation when the liege is the one requesting support
			}
			add = 50
			desc = AI_THEIR_RIVAL
		}
		modifier = {
			exists = scope:target
			scope:recipient = {
				has_relation_friend = scope:target.holder
				NOT = { has_relation_best_friend = scope:target.holder }
				liege = scope:target.holder
				liege != scope:actor # Don't worry about liege relation when the liege is the one requesting support
			}
			add = -50
			desc = AI_THEIR_FRIEND
		}
		modifier = {
			exists = scope:target
			scope:recipient = {
				has_relation_best_friend = scope:target.holder
				liege = scope:target.holder
				liege != scope:actor # Don't worry about liege relation when the liege is the one requesting support
			}
			add = -100
			desc = AI_THEIR_FRIEND
		}
		modifier = {
			exists = scope:target
			scope:recipient = {
				has_relation_lover = scope:target.holder
				liege = scope:target.holder
				liege != scope:actor # Don't worry about liege relation when the liege is the one requesting support
			}
			add = -30
			desc = AI_THEIR_LOVER
		}
		modifier = {
			exists = scope:target
			scope:recipient = {
				OR = {
					is_close_family_of = scope:target.holder
					is_extended_family_of = scope:target.holder
				}
				opinion = { target = scope:target.holder value > -25 }
				liege = scope:target.holder
				liege != scope:actor # Don't worry about liege relation when the liege is the one requesting support
			}
			add = -20
			desc = AI_THEIR_RELATIVE
		}

		# Traits
		modifier = {
			scope:recipient = { # Ambitious characters doesn't want to spend their influence on anyone not from their house
				has_trait = ambitious
				exists = house
			}
			scope:secondary_recipient ?= {
				exists = house
				NOT = { house = scope:recipient.house }
			}
			add = -50
			desc = INTERACTION_AMBITIOUS
		}
		modifier = {
			scope:recipient = {
				has_trait = callous
			}
			add = -20
			desc = INTERACTION_CALLOUS
		}
		modifier = {
			scope:recipient = {
				has_trait = fickle
			}
			add = -30
			desc = INTERACTION_FICKLE
		}
		modifier = {
			scope:recipient = {
				has_trait = paranoid
			}
			add = -25
			desc = INTERACTION_PARANOID
		}
		modifier = {
			scope:recipient = {
				has_trait = trusting
			}
			add = 10
			desc = INTERACTION_TRUSTING
		}
		modifier = {
			scope:recipient = {
				has_trait = arbitrary
			}
			add = -15
			desc = INTERACTION_ARBITRARY
		}
		modifier = { # Cravens dare not help you
			scope:recipient = {
				has_trait = craven
			}
			scope:actor.house ?= {
				is_dominant_family = no
			}
			add = -20
			desc = INTERACTION_CRAVEN
		}
		modifier = { # Cravens dare not refuse a dominant family
			scope:recipient = {
				has_trait = craven
			}
			scope:actor.house ?= {
				is_dominant_family = yes
			}
			add = 20
			desc = INTERACTION_CRAVEN
		}
	}

	ai_potential = {
		has_government = administrative_government
		house ?= {
			OR = {
				is_powerful_family = yes
				is_dominant_family = yes
			}
		}
	}

	ai_frequency = 48

	ai_targets = {
		ai_recipients = peer_vassals
		max = 8
	}

	ai_targets = {
		ai_recipients = hooked_characters
		max = 2
	}
}

# Demand that a vassal switches to admin
# Note: Do not rename or delete this interaction as its directly referred to in code
demand_admin_interaction = {
	category = interaction_category_admin
	icon = demand_admin_interaction

	ai_maybe = yes
	ai_min_reply_days = 4
	ai_max_reply_days = 9
	can_send_despite_rejection = yes
	ai_accept_negotiation = yes
	popup_on_receive = yes
	common_interaction = yes

	ai_targets = {
		ai_recipients = vassals
	}
	ai_target_quick_trigger = {
		adult = yes
	}
	ai_frequency = 12

	desc = demand_admin_interaction_desc

	is_shown = {
		scope:actor = { has_government = administrative_government }
		scope:recipient = {
			target_is_liege_or_above = scope:actor
			is_ai = yes
			is_ruler = yes
			NOT = { has_government = administrative_government }
		}
		trigger_if = {
			limit = {
				scope:actor = {
					is_ai = yes
				}
			}
			scope:recipient = {
				highest_held_title_tier >= tier_county
			}
		}
	}

	cooldown_against_recipient = { years = 10 }

	is_valid_showing_failures_only = {
		scope:recipient = { is_busy_in_events_localised = yes }
		scope:recipient = { NOT = { has_strong_hook = scope:actor } }
		scope:recipient = { is_at_war = no }
		scope:actor = { is_at_war = no }
		custom_tooltip = {
			text = cannot_take_overt_hostile_actions_against_diarch.tt
			NOT = { scope:recipient ?= scope:actor.diarch }
		}
		custom_tooltip = {
			text = demand_admin_tribal
			NOT = {
				scope:recipient = { government_has_flag = government_is_tribal }
			}
		}
		custom_tooltip = {
			text = head_of_faith_unable_to_change_government_desc
			NOT = {
				scope:recipient = { faith.religious_head ?= this }
			}
		}
	}

	# Offer hereditary boost
	send_option = {
		is_valid = {
			custom_tooltip = {
				text = demand_admin_hereditary_tt
				scope:recipient.house ?= {
					any_house_member = { count > 1 }
				}
			}
			custom_tooltip = {
				text = demand_admin_hereditary_exists_tt
				NOT = { exists = scope:recipient.primary_title.var:petition_house_rights }
			}
		}
		flag = hereditary
		localization = demand_admin_hereditary
	}
	#Spend influence
	send_option = {
		flag = influence
		is_valid = {
			scope:actor.influence >= massive_influence_value
		}
		localization = SPEND_INFLUENCE
	}
	#Use hook
	send_option = {
		is_valid = {
			scope:actor = { has_usable_hook = scope:recipient }
		}
		flag = hook
		localization = SCHEME_HOOK
	}
	should_use_extra_icon = {
		scope:actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	send_options_exclusive = no

	auto_accept = {
		custom_description = {
			text = "spending_hook"
			subject = scope:actor
			object = scope:recipient
			scope:hook = yes
		}
	}

	on_send = {
		scope:recipient = {
			primary_title = { save_scope_as = demanded_administration }
			trigger_event = {
				id = ep3_interactions_events.0005
				days = 5
			}
		}
	}

	on_accept = {
		show_as_tooltip = {
			change_to_administrative_interaction_effect = yes
		}
	}

	on_decline = {
		scope:recipient = { custom_tooltip = demand_admin_interaction_vassal_refuses }
	}

	ai_potential = {
		has_government = administrative_government
		is_adult = yes
	}

	ai_will_do = {
		base = 100
		modifier = {
			factor = 0
			scope:recipient = { highest_held_title_tier >= tier_county }
			gold >= 300
		}
		modifier = {
			factor = 0
			scope:recipient = { highest_held_title_tier >= tier_duchy }
			gold >= 600
		}
		modifier = {
			factor = 0
			scope:recipient = { highest_held_title_tier >= tier_kingdom }
			gold >= 2000
		}
	}

	ai_accept = {
		base = 0
		demand_admin_acceptance_modifier = yes
	}
}

#Contest the appointment of another character to a title you have a claim on
contest_appointment_interaction = {
	category = interaction_category_admin
	common_interaction = yes
	highlighted_reason = HIGHLIGHTED_CAN_CONTEST_APPOINTMENT
	notification_text = contest_appointment_interaction_desc_tt
	intermediary_notification_text = contest_appointment_interaction_liege_desc
	intermediary_breakdown_yes = ANSWER_TRILATERAL_CONTEST_LIEGE_YES
	intermediary_breakdown_no = ANSWER_TRILATERAL_CONTEST_LIEGE_NO
	intermediary_breakdown_maybe = ANSWER_TRILATERAL_INTERMEDIARY_LIEGE_MAYBE
	intermediary_answer_accept_key = REPLY_ANSWER_ACCEPT
	intermediary_answer_reject_key = REPLY_ANSWER_REJECT
	pre_answer_yes_breakdown_key = ANSWER_TRILATERAL_RECIPIENT_YES
	pre_answer_no_breakdown_key = ANSWER_TRILATERAL_RECIPIENT_NO
	pre_answer_maybe_breakdown_key = ANSWER_TRILATERAL_RECIPIENT_MAYBE
	#icon = TODO_CD_EP3: TIT-55514

	redirect = {
		scope:actor.top_liege = { save_scope_as = intermediary }
	}

	desc = contest_appointment_interaction_desc

	target_type = title
	target_filter = recipient_domain_titles
	ai_maybe = yes
	ai_intermediary_maybe = yes
	can_send_despite_rejection = yes
	popup_on_receive = yes
	pause_on_receive = yes

	interface_priority = 60
	ai_min_reply_days = 4
	ai_max_reply_days = 9

	prompt = CONTEST_TITLE_SELECT_TITLE

	is_shown = {
		# The obvious.
		NOR = {
			scope:actor = scope:recipient
			scope:actor = scope:intermediary
			scope:recipient = scope:intermediary
		}
		# Admin Govt
		#You don't have another appointment
		scope:actor = { is_landless_administrative = yes }
		scope:recipient = { has_government = administrative_government }
		scope:intermediary ?= { has_government = administrative_government }
		# Make sure scope:recipient is suitable.
		scope:recipient = {
			# We only target vassals of the liege
			top_liege = scope:actor.top_liege
			# who have a contestable title
			highest_held_title_tier > tier_county
			any_held_title = {
				tier >= tier_duchy
				scope:actor = {
					has_claim_on = prev
				}
				title_revocation_standard_can_pick_title_trigger = yes
			}
		}
	}

	is_valid_showing_failures_only = {
		trigger_if = { # Stop AI sending this too often
			limit = {
				scope:actor = { is_ai = yes }
			}
			NOT = {
				scope:intermediary ?= { has_character_flag = contest_appointment_liege_cooldown }
			}
		}
		trigger_if = {
			limit = {
				scope:recipient = { vassal_contract_has_flag = vassal_contract_cannot_revoke_titles }
			}
			custom_description = {
				text = liege_vassal_contract_forbids_revocation
				object = scope:recipient
				scope:recipient = {
					NOT = { vassal_contract_has_flag = vassal_contract_cannot_revoke_titles }
				}
			}
		}
		scope:intermediary = {
			influence >= medium_influence_value
		}
	}

	cooldown_against_recipient = { years = 10 }

	can_send = {
		scope:actor = {
			custom_description = {
				text = "character_interactions_hostile_actions_disabled_delay"
				NOT = { has_character_flag = flag_hostile_actions_disabled_delay }
			}
		}
		trigger_if = {
			limit = {
				exists = scope:target
			}
			is_appointment_valid_trigger = {
				TITLE = scope:target
				CANDIDATE = scope:actor
				TOP_LIEGE = scope:intermediary
			}
		}
	}

	is_highlighted = {
		scope:recipient = {
			any_held_title = {
				scope:actor = {
					has_claim_on = prev
				}
				title_revocation_standard_can_pick_title_trigger = yes
			}
		}
	}

	can_be_picked_title = {
		scope:target = {
			title_revocation_standard_can_pick_title_trigger = yes
			# Plus, must have scope:actor as a claimant.
			custom_description = {
				text = "you_must_have_a_claim_on_the_title"
				tier >= tier_duchy
				scope:actor = { has_claim_on = scope:target }
			}
		}
	}

	cost = {
		influence = {
			value = major_influence_value
			if = {
				limit = { scope:influence_bribe = yes }
				add = 100
			}
		}
	}

	# Hooks can be used to force this through.
	send_options_exclusive = no
	send_option = {
		is_valid = {
			scope:actor = { has_usable_hook = scope:intermediary }
		}
		flag = hook_liege
		localization = SCHEME_HOOK
	}
	should_use_extra_icon = {
		scope:actor = {
			OR = {
				has_usable_hook = scope:intermediary
				has_usable_hook = scope:recipient
			}
		}
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	on_send = {
		scope:actor = {
			add_character_flag = {
				flag = flag_hostile_actions_disabled_delay
				days = 10
			}
		}
		scope:intermediary ?= { # Stop AI sending this too often
			add_character_flag = {
				flag = contest_appointment_liege_cooldown
				years = 1
			}
		}
	}
	send_option = {
		is_valid = {
			scope:actor = { has_usable_hook = scope:recipient }
		}
		flag = hook
		localization = SCHEME_HOOK
	}
	# Spend influence to convince your liege
	send_option = {
		flag = influence_bribe
		localization = influence_value_bribe_desc
		is_valid = {
			scope:actor = { influence >= major_influence_value }
		}
	}

	on_auto_accept = {
		scope:recipient = { trigger_event = ep3_interactions_events.0010 }
		scope:actor = {
			# Tell them that the revocation went through fine.
			trigger_event = ep3_interactions_events.0011
		}
		scope:actor = {
			# Scope:actor can be hostile again.
			clear_hostile_actions_lock_flag_effect = yes
		}
		create_title_and_vassal_change = {
			type = revoked
			save_scope_as = change
			add_claim_on_loss = yes
		}
		scope:target = {
			change_title_holder_include_vassals = {
				holder = scope:actor
				change = scope:change
			}
		}
		resolve_title_and_vassal_change = scope:change
	}

	on_accept = {
		scope:recipient = { trigger_event = ep3_interactions_events.0010 }
		scope:actor = {
			# Tell them that the revocation went through fine.
			trigger_event = ep3_interactions_events.0011
		}
		scope:intermediary = {
			change_influence = medium_influence_loss
			if = {
				limit = {
					scope:influence_bribe = yes
				}
				change_influence = major_influence_gain
			}
		}
		scope:actor = {
			# Scope:actor can be hostile again.
			clear_hostile_actions_lock_flag_effect = yes
		}
		scope:recipient = {
			every_held_title = {
				limit = {
					
					tier >= tier_county
					any_this_title_or_de_jure_above = {
						this = scope:target
					}
				}
				add_to_list = transfer_titles
			}
		}
		create_title_and_vassal_change = {
			type = revoked
			save_scope_as = change
			add_claim_on_loss = yes
		}
		every_in_list = {
			list = transfer_titles
			change_title_holder_include_vassals = {
				holder = scope:actor
				change = scope:change
			}
		}
		resolve_title_and_vassal_change = scope:change
	}

	on_intermediary_decline = {
		scope:actor = {
			# Inform scope:actor that their liege has vetoed them.
			trigger_event = ep3_interactions_events.0012
			# Scope:actor can be hostile again.
			clear_hostile_actions_lock_flag_effect = yes
		}
		# Inform scope:recipient that scope:intermediary has their back.
		scope:recipient = {
			send_interface_toast = {
				type = event_toast_effect_bad
				title = liege_blocked_contest_title
				left_icon = scope:actor
				right_icon = scope:intermediary
				custom_tooltip = liege_blocked_contest_title.inform_recipient
			}
		}
		scope:intermediary = {
			if = {
				limit = {
					scope:influence_bribe = yes
				}
				change_influence = major_influence_gain
			}
		}
		# Flick out some opinions.
		diarch_revoke_title_interaction_intermediary_fail_opinions_effect = yes
	}

	on_decline = {
		scope:intermediary = {
			# Tell them that the revocation was refused
			trigger_event = ep3_interactions_events.0013
			# And give a crime reason
			if = {
				limit = { is_ai = no }
				custom_tooltip = ADD_OPINION_EFFECT_I_HAVE_IMPRISONMENT_REASON_UNUSABLE
				hidden_effect = {
					add_opinion = {
						target = scope:recipient
						modifier = treasonous_revoke_refusal
					}
				}
			}
			## AI use the standard opinion flow.
			else = {
				add_opinion = {
					target = scope:recipient
					modifier = treasonous_revoke_refusal
				}
			}
		}
		scope:actor = {
			# Notify
			trigger_event = ep3_interactions_events.0014
			# Scope:actor can be hostile again.
			clear_hostile_actions_lock_flag_effect = yes
		}
		## Scope:recipient is annoyed with scope:actor and the other way around.
		scope:recipient = {
			add_opinion = {
				target = scope:actor
				modifier = revoked_title
			}
		}
		scope:actor = {
			add_opinion = {
				target = scope:recipient
				modifier = treasonous_revoke_refusal
			}
		}
	}

	auto_accept = {
		scope:recipient = {
			calc_true_if = {
				amount >= 2
				custom_description = {
					text = "prisoner_revocation"
					is_imprisoned_by = scope:actor
				}
				custom_description = {
					text = "spending_hook"
					subject = scope:actor
					object = scope:recipient
					scope:hook = yes
					OR = {
						# Strong hooks generally.
						scope:actor = { has_strong_hook = scope:recipient }
						# Weak hooks in inter-AI interactions count as strong hooks.
						AND = {
							scope:actor = { is_ai = yes }
							scope:recipient = { is_ai = yes }
						}
					}
				}
				custom_description = {
					text = "foreign_prison_revocation"
					subject = scope:actor
					object = scope:recipient
					scope:recipient = {
						is_imprisoned = yes
						NOT = { is_imprisoned_by = scope:actor }
					}
				}
			}
		}
	}

	ai_intermediary_accept = {
		base = 0
		modifier = {
			add = -50
			desc = BASE_RELUCTANCE
		}
		# Hook
		modifier = {
			add = 40
			desc = SCHEME_WEAK_HOOK_USED
			scope:hook_liege = yes
		}
		# Bribe
		modifier = {
			desc = INFLUENCE_REASON
			scope:influence_bribe = yes
			add = {
				value = 20
				multiply = scope:actor.influence_level
				min = 5
			}
		}
		# Opinion Factor
		opinion_modifier = {
			who = scope:intermediary
			opinion_target = scope:actor
			multiplier = 1
			desc = AI_OPINION_REASON
		}
		opinion_modifier = {
			who = scope:intermediary
			opinion_target = scope:recipient
			multiplier = -1
			desc = AI_OPINION_REASON
		}
		# You would be a better public official (or not)!
		modifier = {
			desc = AI_STEWARDSHIP_REASON
			add = {
				value = scope:actor.stewardship
				subtract = scope:recipient.stewardship
				multiply = 2
			}
		}
		# How good is the respective character's Governor Efficiency?
		modifier = {
			scope:actor = { is_ai = no }
			desc = AI_GOVERNOR_EFFICIENCY
			add = {
				value = 0
				add = {
					value = scope:actor.governor_efficiency
					subtract = 1
					multiply = 100
				}
			}
		}
		modifier = {
			scope:actor = { is_ai = no }
			desc = RECIPIENT_GOVERNOR_EFFICIENCY
			add = {
				value = 0
				add = {
					value = scope:recipient.governor_efficiency
					subtract = 1
					multiply = -100
				}
			}
		}
		# Dread
		## Intimidation
		modifier = {
			add = {
				value = 0
				subtract = intimidated_halved_reason_value
			}
			desc = YOU_INTIMIDATED_REASON
			scope:actor = {
				has_dread_level_towards = {
					target = scope:intermediary
					level = 1
				}
			}
		}
		## Cowing
		modifier = {
			add = {
				value = 0
				subtract = cowed_halved_reason_value
			}
			desc = YOU_COWED_REASON
			scope:actor = {
				has_dread_level_towards = {
					target = scope:intermediary
					level = 2
				}
			}
		}
		# Legalistic tradition
		modifier = {
			add = legalistic_vassal_punishment_acceptance
			desc = tradition_legalistic_name
			scope:actor = {
				has_revoke_title_reason = scope:recipient
				culture = { has_cultural_parameter = vassals_more_likely_accept_punishments }
			}
		}
	}

	ai_accept = {
		# Try to make it 0 for most interactions
		base = 0

		# Weak Hook
		modifier = {
			add = 40
			desc = SCHEME_WEAK_HOOK_USED
			scope:hook = yes
		}
		# Opinion Factor
		opinion_modifier = {
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 0.5
			desc = AI_OPINION_REASON
		}
		# Refusal is Treason
		## It's always treason, but worth pointing it out.
		modifier = {
			add = 20
			desc = AI_REFUSAL_IS_TREASON
		}
		# I am a King!
		modifier = {
			add = -20
			desc = offer_vassalization_interaction_aibehavior_amkingtier_tt
			scope:recipient = { highest_held_title_tier = tier_kingdom }
		}
		# Dread
		## Intimidation
		modifier = {
			add = intimidated_halved_reason_value
			desc = INTIMIDATED_REASON
			scope:recipient = {
				has_dread_level_towards = {
					target = scope:actor
					level = 1
				}
			}
		}
		## Cowing
		modifier = {
			add = cowed_halved_reason_value
			desc = COWED_REASON
			scope:recipient = {
				has_dread_level_towards = {
					target = scope:actor
					level = 2
				}
			}
		}
		## Intimidation
		modifier = {
			add = intimidated_halved_reason_value
			desc = INTIMIDATED_REASON
			scope:recipient = {
				has_dread_level_towards = {
					target = scope:intermediary
					level = 1
				}
			}
		}
		## Cowing
		modifier = {
			add = cowed_halved_reason_value
			desc = COWED_REASON
			scope:recipient = {
				has_dread_level_towards = {
					target = scope:intermediary
					level = 2
				}
			}
		}
		# Difference in influence level
		modifier = {
			scope:actor.influence_level != scope:recipient.influence_level
			add = {
				value = scope:actor.influence_level
				subtract = scope:recipient.influence_level
				multiply = 20
			}
			desc = difference_in_influence_level_reason
		}
		# Legalistic tradition
		modifier = {
			add = legalistic_vassal_punishment_acceptance
			desc = tradition_legalistic_name
			scope:actor = {
				has_revoke_title_reason = scope:recipient
				culture = { has_cultural_parameter = vassals_more_likely_accept_punishments }
			}
		}
		# Factor for personality.
		ai_value_modifier = {
			who = scope:recipient
			# Greed is always a factor.
			ai_greed = {
				if = {
					limit = {
						scope:recipient = {
							NOT = { ai_greed = 0 }
						}
					}
					value = -0.75
				}
			}
			# If AI is honourable and the law compels them to obey the liege, AI will be more likely to obey.
			ai_honor = {
				if = {
					limit = {
						scope:recipient = { ai_honor > 0 }
					}
					value = 0.5
				}
			}
		}
	}

	# AI
	ai_targets = {
		ai_recipients = peer_vassals
		max = 10
	}

	ai_frequency = 12

	ai_potential = {
		is_landless_administrative = yes
		liege = { has_realm_law_flag = title_revocation_allowed }
	}

	ai_will_do = {
		base = 100
		ai_value_modifier = {
			ai_greed = 0.5
			ai_boldness = 1
		}
		## Opinion.
		opinion_modifier = {
			opinion_target = scope:recipient
			multiplier = 0.25
		}
		## Traits.
		### +++ Ambitious.
		modifier = {
			add = 100
			has_trait = ambitious
		}
		### +++ Greedy.
		modifier = {
			add = 50
			has_trait = greedy
		}
		### +++ Vengeful (under certain criteria).
		modifier = {
			add = 100
			has_trait = vengeful
			has_opinion_modifier = {
				modifier = revoked_title
				target = scope:recipient
			}
		}
		### --- Content.
		modifier = {
			add = -50
			has_trait = content
		}
		# hooked AI.
		modifier = {
			add = 50
			is_landed = no
			has_hook = scope:recipient
			scope:recipient = { is_ai = yes }
		}
		### + Do pick on people we hate.
		modifier = {
			factor = 1.5
			should_prioritise_hostile_action_against_due_to_personal_relations_trigger = {
				ACTOR = scope:actor
				RECIPIENT = scope:recipient
			}
		}
		### - Try not to pick on allies of our liege.
		modifier = {
			factor = 0.25
			should_avoid_hostile_action_against_due_to_liege_relations_trigger = {
				ACTOR = scope:actor
				RECIPIENT = scope:recipient
			}
		}
		### x0 Don't pick on our friends or allies.
		modifier = {
			factor = 0
			should_avoid_hostile_action_against_due_to_personal_relations_trigger = {
				ACTOR = scope:actor
				RECIPIENT = scope:recipient
			}
		}
		### x0 Don't go into influence debt!
		modifier = {
			factor = 0
			influence <= 0
		}
	}
}

# Request a council position from your liege in exchange for influence
request_council_interaction = {
	category = interaction_category_admin
	interface_priority = 90
	icon = council

	desc = request_council_interaction_desc

	special_interaction = request_council_position
	interface = council_task_interaction
	ai_maybe = yes
	ai_min_reply_days = 4
	ai_max_reply_days = 9
	can_send_despite_rejection = yes
	popup_on_receive = yes
	send_name = "SEND_REQUEST_COUNCIL"

	greeting = positive
	notification_text = REQUEST_COUNCIL_PROPOSAL

	pre_answer_yes_key = ACCEPT
	pre_answer_no_key = DECLINE

	on_decline_summary = request_council_decline_summary

	ai_targets = {
		ai_recipients = liege
	}
	ai_target_quick_trigger = {
		adult = yes
	}
	ai_frequency = 36

	cooldown_against_recipient = { years = 25 }

	cost = {
		influence = admin_council_cost_value
	}

	is_shown = {
		NOT = { scope:recipient = scope:actor }
		scope:actor = {
			liege ?= scope:recipient
		}
		#Admin only
		scope:actor = { has_government = administrative_government }
		scope:recipient = { has_government = administrative_government }
		trigger_if = {
			limit = {
				exists = scope:target.councillor
			}
			scope:target = { can_fire_position = yes }
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			is_adult = yes
			NOT = {
				is_at_war_with = scope:recipient
			}
			NOT = {
				is_councillor = yes
			}
			NAND = {
				has_council_position = councillor_court_chaplain
				faith = {
					OR = {
						has_doctrine = doctrine_clerical_succession_temporal_fixed_appointment
						has_doctrine = doctrine_clerical_succession_spiritual_fixed_appointment
					}
				}
			}
		}
	}

	has_valid_target_showing_failures_only = {
		trigger_if = {
			limit = {
				exists = scope:target.councillor
			}
			scope:target.councillor = {
				NOT = {
					is_blocked_from_being_fired_from_council_trigger = {
						COURT_OWNER = scope:recipient
					}
				}
			}
		}
	}

	on_accept = {
		scope:target = {
			save_scope_as = council_task
		}
		scope:actor = {
			block_firing_councillor_effect = { COURT_OWNER = scope:recipient }
			custom_tooltip = force_onto_council.recipient.tt.duration
			#And notify exactly which councillor type they've become.
			hidden_effect = {
				send_interface_toast = {
					type = event_toast_effect_good
					title = force_onto_council.actor.tt
					left_icon = scope:recipient
					custom_tooltip = force_onto_council.actor.tt.duration
					show_as_tooltip = {
						change_influence = admin_council_loss_value
					}
				}
			}
			stress_impact = { content = minor_stress_impact_gain }
		}
		scope:recipient = {
			assign_council_task = {
				target = scope:actor
				council_task = scope:council_task
			}
			change_influence = massive_influence_gain
			custom_tooltip = force_onto_council.desc.tt
			#And notify exactly which councillor type they've become.
			hidden_effect = {
				send_interface_toast = {
					type = event_toast_effect_neutral
					title = force_onto_council.recipient.tt
					left_icon = scope:actor
					custom_tooltip = force_onto_council.recipient.tt.duration
					show_as_tooltip = { change_influence = massive_influence_gain }
				}
			}
		}
	}

	on_decline = {
		scope:actor = {
			add_opinion = {
				target = scope:recipient
				modifier = disappointed_opinion
				opinion = -25
			}
			trigger_event = ep3_interactions_events.0020
		}
		scope:recipient = {
			if = { # If the liege is a player, put on a longer global cooldown to reduce potential spam
				limit = { is_ai = no }
				add_character_flag = {
					flag = refused_council_request
					years = 15
				}
			}
		}
	}

	ai_set_target = {
		scope:actor = {
			random_list = {
				10 = {
					trigger = {
						exists = scope:recipient.council_task:councillor_chancellor
						can_be_chancellor_trigger = { COURT_OWNER = scope:recipient }
					}
					modifier = {
						factor = diplomacy
					}
					modifier = {
						trigger = { highest_skill = diplomacy }
						factor = 10
					}
					scope:recipient.council_task:councillor_chancellor = {
						save_scope_as = target
					}
				}
				10 = {
					trigger = {
						exists = scope:recipient.council_task:councillor_steward
						can_be_steward_trigger = { COURT_OWNER = scope:recipient }
					}
					modifier = {
						factor = stewardship
					}
					modifier = {
						trigger = { highest_skill = stewardship }
						factor = 10
					}
					scope:recipient.council_task:councillor_steward = {
						save_scope_as = target
					}
				}
				10 = {
					trigger = {
						exists = scope:recipient.council_task:councillor_marshal
						can_be_marshal_trigger = { COURT_OWNER = scope:recipient }
					}
					modifier = {
						factor = martial
					}
					modifier = {
						trigger = { highest_skill = martial }
						factor = 10
					}
					scope:recipient.council_task:councillor_marshal = {
						save_scope_as = target
					}
				}
				10 = {
					trigger = {
						exists = scope:recipient.council_task:councillor_spymaster
						can_be_spymaster_trigger = { COURT_OWNER = scope:recipient }
					}
					modifier = {
						factor = intrigue
					}
					modifier = {
						trigger = { highest_skill = intrigue }
						factor = 10
					}
					scope:recipient.council_task:councillor_spymaster = {
						save_scope_as = target
					}
				}
				10 = {
					trigger = {
						exists = scope:recipient.council_task:councillor_court_chaplain
						can_be_court_chaplain_trigger = { COURT_OWNER = scope:recipient }
					}
					modifier = {
						factor = learning
					}
					modifier = {
						trigger = { highest_skill = learning }
						factor = 10
					}
					scope:recipient.council_task:councillor_court_chaplain = {
						save_scope_as = target
					}
				}
			}
		}
	}

	ai_potential = {
		is_independent_ruler = no
		is_councillor = no
		liege ?= {
			NOT = { has_character_flag = refused_council_request }
			is_at_war = no
		}
	}

	ai_will_do = {
		base = 0

		# Increase chance if greed and/or boldness is high enough
		modifier = {
			add = 20
			ai_greed >= medium_positive_ai_value
			ai_boldness >= medium_positive_ai_value
		}
		modifier = {
			factor = 1.5
			ai_greed >= very_high_positive_ai_value
		}
		modifier = {
			factor = 1.5
			ai_boldness >= very_high_positive_ai_value
		}

		# Don't do it towards a good relation, unless very greedy
		modifier = {
			factor = 0
			scope:actor = {
				ai_greed <= very_high_positive_ai_value
				OR = {
					has_relation_friend = scope:recipient
					has_relation_lover = scope:recipient
					has_relation_best_friend = scope:recipient
					has_relation_soulmate = scope:recipient
				}
			}
		}

		# No need if they are a councillor already
		modifier = {
			factor = 0
			is_councillor = yes
		}
	}

	ai_accept = {
		base = 0
		modifier = {
			add = -50
			desc = BASE_RELUCTANCE
		}
		opinion_modifier = { # Opinion of you
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 0.8
			desc = AI_OPINION_REASON
		}
		opinion_modifier = { # Opinion of the current councillor
			who = scope:recipient
			opinion_target = scope:target.councillor
			multiplier = -0.8
			desc = AI_OPINION_REASON
		}
		ai_value_modifier = {
			ai_energy = 0.25 		#It's a change
			ai_greed = 0.4 			#Free influence is free influence
			ai_honor = -0.4 		#Some might see it as a bribe
		}
		#Relations
		modifier = {
			scope:actor = {
				has_relation_rival = scope:recipient
			}
			add = -50
			desc = AI_YOUR_RIVAL
		}
		modifier = {
			scope:actor = {
				has_relation_friend = scope:recipient
			}
			add = 25
			desc = AI_YOUR_FRIEND
		}
		#You are better at the job
		modifier = {
			scope:target = council_task:councillor_chancellor
			scope:actor.diplomacy > scope:target.councillor.diplomacy
			desc = AI_BETTER_AT_THE_JOB
			add = {
				value = scope:actor.diplomacy
				subtract = scope:target.councillor.diplomacy
				multiply = 10
			}
		}
		modifier = {
			scope:target = council_task:councillor_marshal
			scope:actor.martial > scope:target.councillor.martial
			desc = AI_BETTER_AT_THE_JOB
			add = {
				value = scope:actor.martial
				subtract = scope:target.councillor.martial
				multiply = 10
			}
		}
		modifier = {
			scope:target = council_task:councillor_steward
			scope:actor.stewardship > scope:target.councillor.stewardship
			desc = AI_BETTER_AT_THE_JOB
			add = {
				value = scope:actor.stewardship
				subtract = scope:target.councillor.stewardship
				multiply = 10
			}
		}
		modifier = {
			scope:target = council_task:councillor_spymaster
			scope:actor.intrigue > scope:target.councillor.intrigue
			desc = AI_BETTER_AT_THE_JOB
			add = {
				value = scope:actor.intrigue
				subtract = scope:target.councillor.intrigue
				multiply = 10
			}
		}
		modifier = {
			scope:target = council_task:councillor_court_chaplain
			scope:actor.learning > scope:target.councillor.learning
			desc = AI_BETTER_AT_THE_JOB
			add = {
				value = scope:actor.learning
				subtract = scope:target.councillor.learning
				multiply = 10
			}
		}
		#You are significantly WORSE at the job (we start reducing AI acceptance when it is more than 10 below current councillor's skill)
		modifier = {
			scope:target = council_task:councillor_chancellor
			scope:actor.diplomacy < { value = scope:target.councillor.diplomacy subtract = 10 }
			desc = AI_WORSE_AT_THE_JOB
			add = {
				value = scope:actor.diplomacy
				subtract = scope:target.councillor.diplomacy
				add = 10
				multiply = 2
			}
		}
		modifier = {
			scope:target = council_task:councillor_marshal
			scope:actor.martial < { value = scope:target.councillor.martial subtract = 10 }
			desc = AI_WORSE_AT_THE_JOB
			add = {
				value = scope:actor.martial
				subtract = scope:target.councillor.martial
				add = 10
				multiply = 2
			}
		}
		modifier = {
			scope:target = council_task:councillor_steward
			scope:actor.stewardship < { value = scope:target.councillor.stewardship subtract = 10 }
			desc = AI_WORSE_AT_THE_JOB
			add = {
				value = scope:actor.stewardship
				subtract = scope:target.councillor.stewardship
				add = 10
				multiply = 2
			}
		}
		modifier = {
			scope:target = council_task:councillor_spymaster
			scope:actor.intrigue < scope:target.councillor.intrigue
			desc = AI_WORSE_AT_THE_JOB
			add = {
				value = scope:actor.intrigue
				subtract = scope:target.councillor.intrigue
				add = 10
				multiply = 2
			}
		}
		modifier = {
			scope:target = council_task:councillor_court_chaplain
			scope:actor.learning < scope:target.councillor.learning
			desc = AI_WORSE_AT_THE_JOB
			add = {
				value = scope:actor.learning
				subtract = scope:target.councillor.learning
				add = 10
				multiply = 2
			}
		}
		#You are more powerful
		modifier = {
			scope:actor = { is_powerful_vassal = yes }
			scope:target.councillor = { is_powerful_vassal = no }
			desc = AI_POWERFUL_VASSAL
			add = 75
		}
		modifier = {
			scope:actor.house ?= { is_powerful_family = yes }
			scope:target.councillor.house ?= { is_powerful_family = no }
			desc = AI_POWERFUL_FAMILY
			add = 100
		}
		#You are more influential
		modifier = {
			NOT = { scope:actor.influence_level = scope:target.councillor.influence_level }
			add = {
				value = scope:actor.influence_level
				subtract = scope:target.councillor.influence_level
				multiply = 10
			}
			desc = AI_DIFFERENCE_INFLUENCE
		}
	}
}

# Transfer a single county (not belonging to a theme) to an already existing governor
transfer_county_interaction = {
	icon = icon_transfer_county
	category = interaction_category_admin
	common_interaction = no

	desc = transfer_county_interaction_desc

	target_type = title
	target_filter = actor_domain_titles
	interface_priority = 60

	# actor character giving the title
	# recipient character receiving the title

	is_shown = {
		NOT = { scope:actor = scope:recipient }
		scope:recipient = {
			target_is_liege_or_above = scope:actor
			highest_held_title_tier >= tier_duchy
			has_government = administrative_government
		}
		scope:actor = {
			has_government = administrative_government
			is_independent_ruler = yes
			highest_held_title_tier >= tier_empire
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = { is_at_war = no }
		scope:recipient = {
			is_adult = yes
			is_at_war = no
			bp2_valid_for_standard_interactions_trigger = yes
			is_busy_in_events_localised = yes
		}
		custom_tooltip = {
			text = have_no_valid_county_to_assign_trigger
			scope:actor = {
				any_held_title = {
					count >= 1
					tier = tier_county
					NOT = {
						this = scope:actor.primary_title.title_capital_county
					}
					duchy ?= {
						NOT = { this = scope:actor.primary_title.title_capital_county.duchy }
					}
				}
			}
		}
	}

	can_be_picked_title = {
		scope:target = {
			is_leased_out = no
			tier = tier_county
			custom_tooltip = {
				NOT = { this = scope:actor.primary_title.title_capital_county }
				text = not_can_be_picked_capital
			}
			custom_tooltip = {
				duchy ?= {
					NOT = { this = scope:actor.primary_title.title_capital_county.duchy }
				}
				text = not_can_be_picked_capital_duchy
			}
		}

		custom_description = {
			text = grant_titles_interaction_can_only_give_diarch_de_jure_liege_to_diarch
			subject = scope:actor.diarch
			NAND = {
				# Only applies if we have an active diarchy.
				scope:actor = { has_active_diarchy = yes }
				# Now, prevent us from giving away our diarch's land to invalidate them...
				scope:target = {
					any_dejure_vassal_title_holder = { this = scope:actor.diarch }
					# ... _unless_ we're giving it _to_ the diarch.
					NOT = { scope:recipient = scope:actor.diarch }
					# Plus we only care if the title is below our tier.
					tier < scope:actor.highest_held_title_tier
				}
			}
		}

		custom_description = {
			text = grant_titles_interaction_title_being_wagered
			NOT = {
				scope:target = { has_variable = wagered_county }
			}
		}
	}

	auto_accept = yes

	on_auto_accept = {
		scope:recipient = {
			trigger_event = char_interaction.0111
		}
	}

	on_accept = {
		hidden_effect = {
			scope:recipient = {
				add_opinion = {
					target = scope:actor
					modifier = received_title_county
				}
			}
			scope:target = { add_to_temporary_list = titles_to_grant }
		}
		#Promised a vassal this title they had a claim on (vassal.2901)
		if = {
			limit = {
				scope:actor = {
					exists = var:was_promised_title
					var:was_promised_title = scope:recipient
				}
			}
			if = {
				limit = {
					scope:recipient = {
						exists = var:promised_title
					}
					scope:landed_title = scope:recipient.var:promised_title
				}
				scope:actor = {
					trigger_event = {
						id = vassal.2910
						days = { 7 14 }
					}
				}
			}
		}

		# The accumulated discontent reduction of the recipient
		scope:recipient = {
			if = {
				limit = {
					is_a_faction_member = yes
				}
				add_joined_faction_discontent = grant_title_opinion_sum_discontent_calc
				custom_tooltip = grant_title_modifier_stack_discontent
			}
		}

		custom_tooltip = grant_title_modifier_stack_counties

		# Jealousy check
		if = {
			limit = {
				any_in_list = {
					list = titles_to_grant
					any_claimant = { grant_title_rivalry_trigger = yes }
				}
			}
			hidden_effect = {
				random = {
					chance = 25
					ordered_in_list = {
						list = titles_to_grant
						limit = {
							any_claimant = { grant_title_rivalry_trigger = yes }
						}
						order_by = tier
						save_scope_as = claim_title
						ordered_claimant = {
							limit = { grant_title_rivalry_trigger = yes }
							order_by = primary_title.tier
							save_scope_as = claim_vassal
							if = {
								limit = {
									scope:recipient = { is_lowborn = yes }
								}
								scope:recipient = { save_scope_as = lowborn_scope }
							}
							else_if = {
								limit = {
									scope:recipient = { has_claim_on = scope:claim_title }
								}
								scope:recipient = { save_scope_as = claimant_scope }
							}
							scope:actor = {
								trigger_event = {
									id = bp1_yearly.8070
									days = 5
								}
							}
						}
					}
				}
			}
		}

		scope:actor = {
			# Maintenance for runestones
			if = {
				limit = {
					# Use expanded version if we have FP1.
					has_fp1_dlc_trigger = yes
					fp1_remove_stele_new_holder_trigger = {
						TITLE = scope:target
						PREVIOUS_HOLDER = scope:actor
						NEW_HOLDER = scope:recipient
					}
				}
				# Actually removed in fp1_other_decisions.0113
				custom_tooltip = runestone_grant_title_warning
			}
			else_if = {
				limit = {
					scope:target = {
						exists = var:ancestor_to_bury
						has_county_modifier = county_raised_runestone_modifier
					}
					NOT = { scope:recipient.dynasty = var:ancestor_to_bury.dynasty } #We only have to change something if the new holder is of a different dynasty
				}
				# Actually removed in religious_decision.0312
				custom_tooltip = runestone_grant_title_warning
			}

			if = {
				limit = {
					exists = scope:actor.dynasty
					scope:actor.dynasty = {
						has_dynasty_perk = ep1_culture_legacy_3
					}
					scope:recipient = {
						is_playable_character = no
						NOT = {
							culture = scope:actor.culture
						}
						any_in_list = {
							list = target_titles
							OR = {
								tier = tier_county
								tier = tier_barony
							}
							culture = scope:recipient.culture
						}
					}
				}
				scope:actor = {
					if = {
						limit = {
							can_add_hook = {
								target = scope:recipient
								type = favor_hook
							}
						}
						add_hook = {
							type = favor_hook
							target = scope:recipient
						}
					}
				}
			}

			#Feedback for actor
			hidden_effect = {
				scope:target = {
					save_scope_as = loc_title
				}
				scope:actor = {
					send_interface_toast = {
						type = event_toast_effect_good
						title = transfer_county_interaction_notification

						left_icon = scope:actor
						right_icon = scope:recipient

						custom_tooltip = grant_titles_interaction_notification_effect_2
						if = {
							limit = {
								exists = dynasty
								is_diff_faith_or_culture_trigger = {
									CHAR = scope:recipient
									STATUS = involved
								}
								any_character_struggle = {
									involvement = involved
									has_struggle_phase_parameter = struggle_grant_titles_diff_faith_culture_gives_prestige
								}
							}
							dynasty = {
								add_dynasty_prestige = minor_dynasty_prestige_gain
							}
						}
					}
				}
			}
		}

		hidden_effect = {
			# Struggle Catalyst
			if = {
				limit = {
					scope:actor = {
						is_diff_faith_or_culture_trigger = {
							CHAR = scope:recipient
							STATUS = involved
						}
						any_character_struggle = {
							involvement = involved
							activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
								CATALYST = catalyst_grant_privilege_to_diff_faith_culture_vassal
								CHAR = scope:recipient
							}
						}
					}
				}
				scope:actor = {
					every_character_struggle = {
						involvement = involved
						limit = {
							activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
								CATALYST = catalyst_grant_privilege_to_diff_faith_culture_vassal
								CHAR = scope:recipient
							}
						}
						activate_struggle_catalyst = {
							catalyst = catalyst_grant_privilege_to_diff_faith_culture_vassal
							character = scope:actor
						}
					}
				}
			}
		}
		# The actual transfer
		create_title_and_vassal_change = {
			type = granted
			save_scope_as = title_change_vassal
		}
		every_in_list = {
			list = titles_to_grant
			change_title_holder = {
				holder = scope:recipient
				change = scope:title_change_vassal
				take_baronies = no
			}
		}
		resolve_title_and_vassal_change = scope:title_change_vassal
	}
	# AI
	ai_targets = {
		ai_recipients = vassals
	}
	ai_frequency = 24
	ai_will_do = {
		base = 100

		modifier = {
			scope:recipient.house ?= scope:actor.house
			add = 10
		}
		modifier = {
			scope:recipient = {
				is_close_family_of = scope:actor
			}
			add = 10
		}
		modifier = {
			scope:target = {
				any_neighboring_county = {
					holder = {
						this = scope:recipient
					}
				}
			}
			add = 200
		}
	}
}

# Demand that a family member be made a eunuch
castrate_child_interaction = {
	category = interaction_category_friendly
	icon = eunuch
	common_interaction = yes
	interface_priority = 60
	ai_maybe = yes
	ai_min_reply_days = 1
	ai_max_reply_days = 1
	can_send_despite_rejection = yes
	ai_accept_negotiation = yes
	popup_on_receive = yes

	pre_answer_maybe_key = ANSWER_MIGHT_SUCCEED
	pre_answer_no_key = ANSWER_CANT_SUCCEED
	pre_answer_yes_key = ANSWER_WILL_SUCCEED
	pre_answer_maybe_breakdown_key = ANSWER_SUM_CHANCE

	ai_targets = {
		ai_recipients = family
		max = 5
	}
	ai_frequency = 12

	desc = castrate_child_interaction_desc

	is_shown = {
		has_ep3_dlc_trigger = yes
		scope:actor = {
			culture = {
				has_cultural_parameter = family_castration
			}
			NAND = {
				is_ai = yes
				any_close_family_member = {
					is_ai = no
				}
			}
		}
		scope:recipient = {
			is_ai = yes
			is_female = no
			is_adult = no
			is_close_family_of = scope:actor
			is_eunuch_trigger = no
		}
	}

	cooldown_against_recipient = { years = 1 }

	is_valid_showing_failures_only = {
		scope:actor = {
			employs_court_position = court_physician_court_position
		}
		scope:recipient = {
			custom_tooltip = {
				text = COURTIER_OR_GUEST
				OR = {
					is_courtier_of = scope:actor
					is_pool_guest_of = scope:actor
					is_foreign_court_guest_of = scope:actor
				}
			}
			is_ruler = no
			is_available = yes
			is_betrothed = no
			NOT = { is_primary_heir_of = scope:actor }
		}
	}

	auto_accept = {
		custom_description = {
			text = "spending_hook"
			subject = scope:actor
			object = scope:recipient
			exists = scope:hook
			scope:hook = yes
			scope:actor = { has_strong_hook = scope:recipient }
		}
	}

	is_highlighted = {
		#This interaction should only be suggested on potential rivals for the imperial throne, bastards, and for landless house heads

		OR = {
			#bastards
			AND = {
				scope:actor = {
					any_close_family_member = {
						is_male = yes
						house ?= scope:actor.house
						is_eunuch_trigger = no
						NOR = {
							has_trait = celibate
							has_trait = devoted
							has_trait = order_member
							has_trait = bastard
						}
						OR = {
							#Is an old adult with a kid
							AND = {
								age >= 40
								any_child = {
									is_male = yes
								}
							}
							#Is a young adult or child
							age < 40
						}
					}
				}
				scope:recipient = {
					has_trait = bastard
				}
			}
			#You are poor and uninfluential OR Emperor
			AND = {
				scope:actor = {
					ep3_castration_interest_trigger = yes
					ep3_castration_male_family_trigger = yes
				}
				#Target is a good one
				scope:recipient = {
					NOT = { is_heir_of = scope:actor }
					ep3_ideal_castration_candidate_trigger = yes
					OR = {
						#target is 3rd child or lower
						any_sibling = {
							count >= 2
							AND = {
								is_male = yes
								age > scope:recipient.age
							}
						}
						#target is sibling
						NOT = { is_child_of = scope:actor }
					}
				}
			}
		}
	}

	on_accept = {
		scope:recipient = {
			if = {
				limit = {
					age < 12
				}
				add_character_flag = accepted_castration_child
			}
			else = {
				add_character_flag = accepted_castration_youth
			}
		}
		show_as_tooltip = {
			scope:actor = { change_influence = minor_influence_gain }
			#Effects on child target
			if = {
				limit = {
					scope:recipient = {
						age < 12
					}
				}
				scope:recipient = {
					ep3_child_castration_effect = yes
					add_stress = medium_stress_gain
					custom_tooltip = castration_better_before_maturity
				}
				#Notification that it is better than doing it after 12 years of age
			}
			#effects on teenaged target
			else = {
				scope:recipient = {
					ep3_youth_castration_effect = yes
					add_stress = major_stress_gain
				}
			}
		}
		#Immediate interaction effects
		if = {
			limit = {
				exists = scope:hook
				scope:hook = yes
				scope:actor = { has_usable_hook = scope:recipient }
			}
			scope:actor = {
				use_hook = scope:recipient
			}
		}
		scope:actor = {
			if = {
				limit = {
					scope:recipient = {
						age > 6
					}
				}
				stress_impact = {
					compassionate = medium_stress_impact_gain
					content = minor_stress_impact_gain
					generous = medium_stress_impact_gain
				}
			}
			trigger_event = ep3_interactions_events.0030
		}
	}

	on_decline = {
		show_as_tooltip = {
			#For child targets
			if = {
				limit = {
					scope:recipient = {
						age < 12
					}
				}
				scope:actor = { change_influence = minor_influence_gain }
				scope:recipient = {
					ep3_child_castration_effect = yes
					add_opinion = {
						modifier = castration_opinion
						target = scope:actor
						opinion = -50
					}
					add_stress = major_stress_gain
					custom_tooltip = castration_better_before_maturity
				}
			}
			#For teenaged victims
			else = {
				scope:actor = {
					remove_courtier_or_guest = scope:recipient
					if = {
						limit = {
							has_hook = scope:recipient
						}
						remove_hook  =  { target = scope:recipient }
					}
					scope:recipient = {
						set_relation_rival = {
							target = scope:actor
							reason = rival_attempted_castration
						}
						add_stress = medium_stress_gain

					}
				}
			}
		}
		if = {
			limit = {
				scope:hook = yes
				scope:actor = { has_usable_hook = scope:recipient }
			}
			scope:actor = {
				use_hook = scope:recipient
			}
		}
		scope:actor = {
			if = {
				limit = {
					scope:recipient = {
						age > 6
					}
				}
				stress_impact = {
					compassionate = medium_stress_impact_gain
					content = minor_stress_impact_gain
					generous = medium_stress_impact_gain
				}
			}
		}
		if = {
			limit = {
				scope:recipient = {
					age < 12
				}
			}
			scope:recipient = {
				add_character_flag = resents_castration
			}
			scope:actor = {
				trigger_event = ep3_interactions_events.0030
			}
		}
		else = {
			scope:actor = {
				trigger_event = ep3_interactions_events.0031
			}
		}
	}

	ai_potential = {
		is_adult = yes
	}

	# Use hook
	send_option = {
		is_valid = {
			scope:actor = {
				has_usable_hook = scope:recipient
			}
			NOT = {
				scope:recipient = { is_imprisoned_by = scope:actor }
			}
		}
		flag = hook
		localization = SCHEME_HOOK
	}
	should_use_extra_icon = {
		scope:actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	send_options_exclusive = no

	ai_will_do = {
		base = 0
		modifier = {
			scope:actor = {
				has_trait = compassionate
			}
			add = -50
		}
		modifier = {
			scope:actor = {
				has_trait = generous
			}
			add = -25
		}
		modifier = {
			scope:actor = {
				has_trait = content
			}
			add = -25
		}
		modifier = {
			scope:recipient = {
				has_trait = bastard
			}
			add = 100
		}
		modifier = {
			scope:actor = {
				ep3_castration_interest_trigger = yes
			}
			scope:recipient = {
				#target is 3rd child or lower
				AND = {
					ep3_ideal_castration_candidate_trigger = yes
					NOT = { is_heir_of = scope:actor }
					#Not oldest child
					any_sibling = {
						count >= 2
						is_male = yes
						age > scope:recipient.age
					}
				}
			}

			add = 100
		}
		modifier = {
			scope:actor = {
				ep3_castration_interest_trigger = yes
			}
			scope:recipient = {
				#target is sibling
				AND = {
					ep3_ideal_castration_candidate_trigger = yes
					NOT = { is_heir_of = scope:actor }
					#Not oldest child
					NOT = { is_child_of = scope:actor }
				}
			}
			add = 100
		}
		modifier = {
			scope:actor = {
				has_trait = greedy
			}
			factor = 2
		}
		modifier = {
			scope:actor = {
				has_trait = paranoid
			}
			factor = 2
		}
		modifier = {
			scope:actor = {
				has_trait = ambitious
			}
			factor = 2
		}
		modifier = {
			scope:actor = {
				has_trait = sadistic
			}
			factor = 2
		}
		modifier = {
			scope:actor = {
				opinion = {
					target = scope:recipient
					value <= -50
				}
			}
			factor = 2
		}
		modifier = {
			scope:recipient = {
				age > 6
			}
			factor = 0.5
		}
		modifier = {
			scope:recipient = {
				age >= 12
			}
			factor = 0.5
		}
		modifier = {
			scope:actor = {
				age <= 4
			}
			factor = 3
		}
		modifier = {
			OR = {
				scope:actor = {
					ep3_castration_male_family_trigger = no
				}
				scope:recipient = {
					is_primary_heir_of = scope:actor
				}
				scope:recipient = {
					AND = {
						is_child_of = scope:actor
						any_sibling = {
							count = 0
							is_male = yes
							age >= scope:recipient.age
							house ?= scope:recipient.house
						}
					}
				}
			}
			factor = 0
		}
	}

	ai_accept = {
		base = 0
		opinion_modifier = { # Opinion Factor
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 0.5
			desc = AI_OPINION_REASON
		}
		ai_value_modifier = {
			ai_rationality = 0.25	#It's just the way things are
			ai_energy = -0.25 		#I have big dreams!
			ai_boldness = -0.25		#I don't want to be reduced
			ai_honor = 0.12 	#It is wrong to defy you
			ai_sociability = 0.12 #I see the advantages
		}
		# Weak Hook
		modifier = {
			trigger = {
				always = scope:hook
			}
			add = 50
			desc = SCHEME_WEAK_HOOK_USED
		}
		modifier = {
			scope:recipient = {
				age <= 2
			}
			desc = SCHEME_AGE_2_OR_LESS
			add = 50
		}
		modifier = {
			scope:recipient = {
				age <= 6
			}
			desc = SCHEME_AGE_6_OR_LESS
			add = 20
		}
		modifier = {
			scope:recipient = {
				age >= 10
			}
			desc = SCHEME_AGE_10_OR_MORE
			add = -20
		}
		modifier = {
			scope:recipient = {
				age >= 14
			}
			desc = SCHEME_AGE_14_OR_MORE
			add = -40
		}
		# They are afraid of you
		modifier = {
			scope:recipient = {
				age >= 12
				has_dread_level_towards = {
					target = scope:actor
					level = 1
				}
			}
			desc = SCHEME_TOO_SCARED_TO_RUN
			add = 30
		}
		modifier = {
			scope:recipient = {
				age >= 12
				has_dread_level_towards = {
					target = scope:actor
					level = 2
				}
			}
			desc = SCHEME_TOO_TERRIFIED_TO_RUN
			add = 60
		}
		modifier = {
			scope:actor = {
				highest_held_title_tier >= tier_empire
			}
			desc = SCHEME_EMPIRE_TIER
			add = 30
		}
		#You are too good a governor for them to slip away
		modifier = {
			scope:recipient = {
				age >= 12
			}
			scope:actor = {
				is_governor = yes
				governor_efficiency >= 1.25
			}
			desc = SCHEME_GOVERNOR_EFFICIENCY_DISSUADES_FLEEING
			add = 20
		}
	}
}

### Offer eunuch
# actor = offerer
# recipient = receiver
# secondary_actor = eunuch
offer_eunuch_interaction = {
	category = interaction_category_diplomacy
	ai_min_reply_days = 4
	ai_max_reply_days = 9
	popup_on_receive = yes
	pause_on_receive = yes
	icon = eunuch

	populate_recipient_list= {
		scope:actor = {
			every_courtier = {
				limit = {
					is_eunuch_trigger = yes
				}
				add_to_list = characters
			}
		}
	}

	desc = offer_eunuch_interaction_desc

	prompt = OFFER_EUNUCH_SELECT_EUNUCH_TO_TRANSFER

	notification_text = OFFER_EUNUCH_PROPOSAL

	cooldown_against_recipient = { years = 1 }

	is_shown = {
		# Only admin gov care about this
		scope:actor = { has_government = administrative_government }
		scope:recipient = { has_government = administrative_government }
		# Only if you actually have any eunuchs in your court
		scope:actor = {
			any_courtier = {
				is_eunuch_trigger = yes
			}
		}
		# Cannot exchange eunuchs with self
		NOT = { scope:recipient = scope:actor }
		# Only significant rulers
		scope:actor.highest_held_title_tier > tier_barony
		# Target has to be a ruler and have a court
		scope:recipient = { is_ruler = yes }
		# Target has to be a direct vassal of the Emperor
		scope:recipient.top_liege = scope:recipient.liege
	}

	is_valid_showing_failures_only = {
		# Must be available
		scope:recipient = { is_busy_in_events_localised = yes }
		trigger_if = {
			limit = { exists = scope:secondary_recipient }
			scope:secondary_recipient = { is_busy_in_events_localised = yes }
		}
		NOT = {
			# Must be at peace
			scope:recipient = { is_at_war_with = scope:actor }
		}
		# Stop AI spamming eunuch offers
		trigger_if = {
			limit = {
				scope:actor = { is_ai = yes }
				exists = scope:secondary_recipient
			}
			NOT = {
				scope:secondary_recipient = { has_character_flag = ai_should_not_offer_eunuch }
			}
		}
	}

	can_be_picked = {
		# We don't want baby eunuchs, we want eunuchs who can actually do something
		is_adult = yes
	}

	can_send = {
		scope:recipient = {
			trigger_if = {
				limit = { is_ai = no }
				NOT = {
					scope:secondary_recipient = { has_character_flag = ai_should_not_offer_eunuch }
				}
			}
		}
	}

	is_highlighted = { # We highlight this interaction so it's easier to notice, since we don't show it in the main list
		scope:actor = {
			any_courtier = {
				is_eunuch_trigger = yes
			}
		}
	}

	cost = {}

	on_send = {
		scope:secondary_recipient = {
			add_character_flag = {
				flag = under_offer_as_eunuch_flag
				months = 1
			}
			court_position_generator_effect = {
				VAR = target
				EMPLOYER = scope:recipient
			}
		}
		if = {
			limit = {
				scope:recipient = { is_ai = no }
			}
			hidden_effect = {
				scope:secondary_recipient = {
					add_character_flag = {
						flag = ai_should_not_offer_eunuch
						years = 3
					}
				}
			}
		}
	}

	on_accept = {
		# Save scopes for clarity
		scope:actor = { save_scope_as = eunuch_sender }
		scope:secondary_recipient = { save_scope_as = eunuch }
		scope:recipient = { save_scope_as = eunuch_taker }
		scope:actor = { trigger_event = char_interaction.0350 }
		show_as_tooltip = {
			ep3_give_eunuch_effect = {
				EUNUCH = scope:secondary_recipient
				TAKER = scope:recipient
				GIVER = scope:actor
			}
			custom_tooltip = eunuch_will_be_given_a_position_tt
		}
	}

	on_decline = {
		scope:actor = {
			trigger_event = char_interaction.0351
		}
		scope:secondary_recipient = { remove_character_flag = under_offer_as_eunuch_flag }
	}

	auto_accept = {
		trigger_if = {
			limit = {
				scope:hook ?= yes
				scope:actor = { has_strong_hook = scope:recipient }
			}
			custom_description = {
				text = "spending_hook"
				subject = scope:actor
				object = scope:recipient
				scope:hook ?= yes
				scope:actor = { has_strong_hook = scope:recipient }
			}
		}
		trigger_else = { always = no }
	}

	can_be_blocked = {
		custom_description = { #Hook from Recipient can counteract, but only if Actor is not forcing the action via Strong Hook.
			text = "spending_hook"
			subject = scope:recipient
			object = scope:actor
			scope:recipient = { has_hook = scope:actor }
			NAND = {
				scope:hook = yes
				scope:actor = { has_strong_hook = scope:recipient }
			}
		}
	}

	on_blocked_effect = {
		scope:recipient = {
			remove_hook = { target = scope:actor }
		}
	}

	#Use hook
	send_option = {
		is_valid = {
			scope:actor = { has_usable_hook = scope:recipient }
		}
		flag = hook
		localization = SCHEME_HOOK
	}
	should_use_extra_icon = {
		scope:actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	send_options_exclusive = no

	# AI
	ai_accept = {
		base = -50
		######### OPINION OF LIEGE
		opinion_modifier = {
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 0.5
			desc = AI_OPINION_REASON
		}
		######### OPINION OF EUNUCH
		opinion_modifier = {
			who = scope:recipient
			opinion_target = scope:secondary_recipient
			multiplier = 0.5
			desc = AI_OPINION_REASON
		}
		######## EUNUCH AGE
		modifier = {
			add = {
				value = 50
				subtract = scope:secondary_recipient.age
			}
			desc = AI_REASON_EUNUCH_AGE
		}
		######## EUNUCH SKILLS
		modifier = {
			add = {
				add = scope:secondary_recipient.diplomacy
				add = scope:secondary_recipient.intrigue
				add = scope:secondary_recipient.stewardship
				add = scope:secondary_recipient.martial
				add = scope:secondary_recipient.learning
			}
			desc = AI_REASON_EUNUCH_SKILLS
		}
		######## EUNUCH SKILLS
		modifier = {
			scope:secondary_recipient = {
				has_trait = beardless_eunuch
			}
			add = 25
			desc = AI_REASON_BEARDLESS_EUNUCH
		}
	}

	ai_targets = {
		ai_recipients = liege
	}

	ai_frequency = 36

	ai_potential = { highest_held_title_tier >= tier_county }

	ai_will_do = {
		base = 0
		modifier = {
			add = scope:actor.ai_boldness
			add = {
				subtract = scope:actor.ai_compassion
			}
		}
		opinion_modifier = { # Opinion Factor
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 0.5
			desc = AI_OPINION_REASON
		}
		opinion_modifier = { # Opinion Factor
			who = scope:actor
			opinion_target = scope:secondary_recipient
			multiplier = -0.5
			desc = AI_OPINION_REASON
		}
		modifier = { # The AI will only use a Hook if they couldn't otherwise do this
			scope:hook = yes
			add = -1
		}
		# Cultural traditions
		modifier = {
			scope:actor.culture = { has_cultural_tradition = tradition_equitable }
			add = 25
		}
		modifier = {
			scope:actor.culture = { has_cultural_tradition = tradition_esteemed_hospitality }
			add = 25
		}
		modifier = {
			scope:actor = {
				culture = { has_cultural_tradition = tradition_loyal_soldiers }
			}
			add = 25
			desc = HOSTAGE_CULTURAL_TRADITION_REASON
		}
	}
}

# Add artifact to Cabinet of Curiosities
cabinet_of_curiosities_interaction = {
	category = interaction_category_admin
	common_interaction = yes
	interface_priority = 60
	desc = cabinet_of_curiosities_interaction_desc
	icon = artisan_inspiration

	target_type = artifact
	target_filter = actor_artifacts

	can_be_picked_artifact = {
		scope:actor = {
			any_artifact = {
				this = scope:target
			}
			#block the artifact from the laamp escort contract
			NOT = {
				any_scheme = {
					var:escorted_artifact ?= scope:target
				}
			}
		}
	}

	is_shown = {
		scope:recipient = scope:actor
		scope:actor = {
			domicile ?= {
				has_domicile_building_or_higher = cabinet_of_curiosities_01
			}
		}
	}

	is_valid_showing_failures_only = {
		# needs to have an artifact to give away
		scope:actor = {
			has_any_artifact = yes
			is_imprisoned = no
		}
	}

	on_accept = {
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = cabinet_of_curiosities_interaction_notification
				left_icon = scope:actor
				right_icon = scope:target

				custom_tooltip = artifact_added_to_domicile_tt

				# Determine Bonus
				if = {
					limit = {
						scope:target = { is_unique = yes }
					}
					house = {
						if = {
							limit = {
								has_variable = ep3_legacy_domicile_artifact_counter_unique
							}
							change_variable = {
								name = ep3_legacy_domicile_artifact_counter_unique
								add = 1
							}
						}
						else = {
							set_variable = {
								name = ep3_legacy_domicile_artifact_counter_unique
								value = 1
							}
						}
					}
				}
				scope:target = {
					if = {
						limit = { rarity = common }
						scope:actor.house = {
							if = {
								limit = {
									has_variable = ep3_legacy_domicile_artifact_counter_common
								}
								change_variable = {
									name = ep3_legacy_domicile_artifact_counter_common
									add = 1
								}
							}
							else = {
								set_variable = {
									name = ep3_legacy_domicile_artifact_counter_common
									value = 1
								}
							}
						}
					}
					else_if = {
						limit = { rarity = masterwork }
						scope:actor.house = {
							if = {
								limit = {
									has_variable = ep3_legacy_domicile_artifact_counter_masterwork
								}
								change_variable = {
									name = ep3_legacy_domicile_artifact_counter_masterwork
									add = 1
								}
							}
							else = {
								set_variable = {
									name = ep3_legacy_domicile_artifact_counter_masterwork
									value = 1
								}
							}
						}
					}
					else_if = {
						limit = { rarity = famed }
						scope:actor.house = {
							if = {
								limit = {
									has_variable = ep3_legacy_domicile_artifact_counter_famed
								}
								change_variable = {
									name = ep3_legacy_domicile_artifact_counter_famed
									add = 1
								}
							}
							else = {
								set_variable = {
									name = ep3_legacy_domicile_artifact_counter_famed
									value = 1
								}
							}
						}
					}
					else_if = {
						limit = { rarity = illustrious }
						scope:actor.house = {
							if = {
								limit = {
									has_variable = ep3_legacy_domicile_artifact_counter_illustrious
								}
								change_variable = {
									name = ep3_legacy_domicile_artifact_counter_illustrious
									add = 1
								}
							}
							else = {
								set_variable = {
									name = ep3_legacy_domicile_artifact_counter_illustrious
									value = 1
								}
							}
						}
					}
				}
			}

			custom_tooltip = add_artifact_to_domicile_warning
			hidden_effect = {
				destroy_artifact = scope:target
				house = {
					if = {
						limit = {
							has_variable = ep3_legacy_domicile_artifact_counter
						}
						change_variable = {
							name = ep3_legacy_domicile_artifact_counter
							add = 1
						}
					}
					else = {
						set_variable = {
							name = ep3_legacy_domicile_artifact_counter
							value = 1
						}
					}
				}
			}
		}
	}

	auto_accept = yes

	# AI
	ai_targets = {
		ai_recipients = self
	}

	ai_frequency = 84

	ai_potential = {
		has_any_unequipped_artifact = yes
		any_character_artifact = {
			count >= 5
			is_equipped = no
		}
	}

	ai_will_do = {
		base = 30
	}
}

# Send an acknowledgment and reward for a governor's good performance
acknowledge_governor_interaction = {
	category = interaction_category_admin
	icon = icon_acknowledge_governor
	common_interaction = yes
	interface_priority = 60
	popup_on_receive = yes

	ai_targets = {
		ai_recipients = vassals
		max = 10
	}
	ai_frequency = 36

	desc = acknowledge_governor_interaction_desc

	is_shown = {
		NOT = { scope:actor = scope:recipient }
		scope:recipient = {
			target_is_liege_or_above = scope:actor
			highest_held_title_tier >= tier_duchy
			has_government = administrative_government
		}
		scope:actor = {
			has_government = administrative_government
			is_independent_ruler = yes
			highest_held_title_tier >= tier_empire
		}
	}

	cooldown_against_recipient = { years = 10 }

	is_valid_showing_failures_only = {
		scope:actor = {
			is_adult = yes
			NOT = {
				is_at_war_with = scope:recipient
			}
		}
		scope:recipient = {
			has_trait = governor
			has_trait_xp = {
				trait = governor
				value >= 80
			}
		}
	}

	auto_accept = yes

	cost = {
		influence = major_influence_value
	}

	on_accept = {
		scope:actor = { save_scope_as = emperor }
		scope:recipient = {
			trigger_event = {
				id = ep3_interactions_events.0040
				days = 1
			}
		}
		custom_tooltip = acknowledge_governor_interaction_tt
		show_as_tooltip = {
			scope:actor = {
				add_hook = {
					target = scope:recipient
					type = loyalty_hook
					years = 5
				}
			}
			if = {
				limit = {
					scope:recipient = { is_ai = yes }
				}
				scope:recipient = {
					add_opinion = {
						target = scope:actor
						modifier = feeling_appreciated_opinion
						opinion = 30
					}
				}
			}
		}
	}

	ai_potential = {
		has_government = administrative_government
		highest_held_title_tier >= tier_empire
	}

	ai_will_do = {
		base = 10
		modifier = {
			scope:recipient.house ?= scope:actor.house
			add = 10
		}
		modifier = {
			scope:recipient = {
				is_close_family_of = scope:actor
			}
			add = 20
		}
		modifier = {
			scope:recipient = {
				is_extended_family_of = scope:actor
			}
			add = 10
		}
		modifier = {
			scope:actor = {
				has_relation_friend = scope:recipient
			}
			add = 10
		}
		modifier = {
			scope:actor = {
				has_relation_best_friend = scope:recipient
			}
			add = 20
		}
		modifier = {
			scope:actor = {
				has_relation_rival = scope:recipient
			}
			add = -30
		}
		opinion_modifier = { # Opinion Factor
			who = scope:actor
			opinion_target = scope:recipient
			multiplier = 0.5
		}
		modifier = {
			scope:recipient = {
				has_trait_xp = {
					trait = governor
					value >= 90
				}
			}
			factor = 1.5
		}
		modifier = {
			scope:recipient = {
				has_trait_xp = {
					trait = governor
					value >= 100
				}
			}
			factor = 2
		}
		modifier = {
			scope:actor = {
				has_strong_hook = scope:recipient
			}
			factor = 0.1
		}
	}
}

# Affect Governor's performance
boost_efficiency_interaction = {
	category = interaction_category_admin
	icon = icon_boost_efficiency
	interface_priority = 1
	popup_on_receive = yes

	ai_targets = {
		ai_recipients = peer_vassals
		max = 15
	}
	ai_targets = {
		ai_recipients = vassals
		max = 15
	}
	ai_frequency = 36

	desc = boost_efficiency_interaction_desc

	is_shown = {
		scope:actor = { has_government = administrative_government }
		scope:recipient = {
			has_government = administrative_government
			NOT = { this = scope:actor }
			is_governor = yes
			top_liege = scope:actor.top_liege
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			is_adult = yes
			NOT = { is_at_war_with = scope:recipient }
		}
		custom_tooltip = {
			text = boost_efficiency_interaction_too_high_tt
			scope:recipient.governor_efficiency_presented <= boost_efficiency_maximum_value
		}
		custom_tooltip = {
			text = efficiency_interaction_cooldown_tt
			scope:recipient = {
				NOR = {
					is_target_in_variable_list = {
						name = efficiency_boosters
						target = scope:actor
					}
					is_target_in_variable_list = {
						name = efficiency_damagers
						target = scope:actor
					}
				}
			}
		}
	}

	can_send = {
		custom_tooltip = {
			text = boost_efficiency_interaction_too_high_tt
			scope:recipient.governor_efficiency_presented <= boost_efficiency_maximum_value
		}
		custom_tooltip = {
			text = efficiency_interaction_cooldown_tt
			scope:recipient = {
				NOR = {
					is_target_in_variable_list = {
						name = efficiency_boosters
						target = scope:actor
					}
					is_target_in_variable_list = {
						name = efficiency_damagers
						target = scope:actor
					}
				}
			}
		}
	}

	cost = {
		influence = {
			value = minor_influence_value
			if = {
				limit = { scope:influence_boost = yes }
				add = scope:recipient.medium_influence_value
			}
		}
		gold = {
			value = 0
			if = {
				limit = { scope:gold_boost = yes }
				add = scope:recipient.medium_gold_value
			}
		}
	}

	send_option = {
		is_valid = { scope:actor.influence >= scope:recipient.medium_influence_gain }
		localization = influence_boost_desc
		flag = influence_boost
	}
	send_option = {
		is_valid = { scope:actor.gold >= scope:recipient.medium_gold_value }
		localization = gold_boost_desc
		flag = gold_boost
	}
	send_option = {
		localization = diplomacy_boost_desc
		flag = diplomacy_boost
	}
	send_option = {
		localization = stewardship_boost_desc
		flag = stewardship_boost
	}
	send_option = {
		localization = intrigue_boost_desc
		flag = intrigue_boost
	}
	send_options_exclusive = yes

	on_send = {
		scope:recipient = {
			add_to_variable_list = {
				name = efficiency_boosters
				target = scope:actor
				years = 2
			}
		}
	}

	auto_accept = yes

	on_accept = {
		switch = {
			trigger = yes
			scope:diplomacy_boost = {
				boost_governor_efficiency_duel_effect = { SKILL = diplomacy }
			}
			scope:stewardship_boost = {
				boost_governor_efficiency_duel_effect = { SKILL = stewardship }
			}
			scope:intrigue_boost = {
				boost_governor_efficiency_duel_effect = { SKILL = intrigue }
			}
			fallback = { boost_governor_efficiency_success_effect = yes } # Non-duel options always succeed
		}
	}

	ai_potential = {
		has_government = administrative_government
		top_liege = {
			any_vassal = {
				is_governor = yes
				NOT = { this = root }
			}
		}
	}

	ai_will_do = {
		base = -10
		modifier = { # Boost house members
			scope:recipient.house ?= scope:actor.house
			add = 10
		}
		modifier = { # Boost family
			scope:recipient = { is_close_family_of = scope:actor }
			add = 10
		}
		modifier = { # Boost friends
			scope:actor = { has_relation_friend = scope:recipient }
			add = 10
		}
		modifier = { # Avoid boosting rivals
			scope:actor = { has_relation_rival = scope:recipient }
			add = -25
		}
		modifier = { # Avoid making potential house gains harder
			scope:recipient = {
				any_held_title = {
					tier >= tier_duchy
					current_heir.house = scope:actor.house
					scope:actor.house != scope:recipient.house
				}
			}
			add = -10
		}
		modifier = { # AI copy players they like
			scope:recipient = {
				any_in_list = {
					variable = efficiency_boosters
					is_ai = no
					NOT = { has_relation_rival = scope:actor }
					OR = {
						has_relation_friend = scope:actor
						AND = {
							exists = house
							scope:actor.house ?= house
						}
						is_close_family_of = scope:actor
					}
				}
			}
			add = 15
		}
		opinion_modifier = { # Opinion Factor - boost for characters they like
			who = scope:actor
			opinion_target = scope:recipient
			multiplier = 0.25
		}
	}
}

# Affect Governor's performance
damage_efficiency_interaction = {
	category = interaction_category_admin
	icon = icon_damage_efficiency
	interface_priority = 0
	popup_on_receive = yes

	ai_targets = {
		ai_recipients = peer_vassals
		max = 15
	}
	ai_targets = {
		ai_recipients = vassals
		max = 15
	}
	ai_frequency = 36

	desc = damage_efficiency_interaction_desc

	is_shown = {
		scope:actor = { has_government = administrative_government }
		scope:recipient = {
			is_governor = yes
			NOT = { this = scope:actor }
			top_liege = scope:actor.top_liege
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			is_adult = yes
			NOT = { is_at_war_with = scope:recipient }
		}
		custom_tooltip = {
			text = damage_efficiency_interaction_too_low_tt
			scope:recipient.governor_efficiency_presented >= damage_efficiency_minimum_value
		}
		custom_tooltip = {
			text = efficiency_interaction_cooldown_tt
			scope:recipient = {
				NOR = {
					is_target_in_variable_list = {
						name = efficiency_boosters
						target = scope:actor
					}
					is_target_in_variable_list = {
						name = efficiency_damagers
						target = scope:actor
					}
				}
			}
		}
	}

	can_send = {
		custom_tooltip = {
			text = damage_efficiency_interaction_too_low_tt
			scope:recipient.governor_efficiency_presented >= damage_efficiency_minimum_value
		}
		custom_tooltip = {
			text = efficiency_interaction_cooldown_tt
			scope:recipient = {
				NOR = {
					is_target_in_variable_list = {
						name = efficiency_boosters
						target = scope:actor
					}
					is_target_in_variable_list = {
						name = efficiency_damagers
						target = scope:actor
					}
				}
			}
		}
	}

	cost = {
		influence = {
			value = minor_influence_gain
			if = {
				limit = { scope:influence_damage = yes }
				add = scope:recipient.medium_influence_gain
			}
		}
		gold = {
			value = 0
			if = {
				limit = { scope:gold_damage = yes }
				add = scope:recipient.medium_gold_value
			}
		}
	}

	send_option = {
		is_valid = { scope:actor.influence >= scope:recipient.medium_influence_gain }
		localization = influence_damage_desc
		flag = influence_damage
	}
	send_option = {
		is_valid = { scope:actor.gold >= scope:recipient.medium_gold_value }
		localization = gold_damage_desc
		flag = gold_damage
	}
	send_option = {
		localization = diplomacy_damage_desc
		flag = diplomacy_damage
	}
	send_option = {
		localization = stewardship_damage_desc
		flag = stewardship_damage
	}
	send_option = {
		localization = intrigue_damage_desc
		flag = intrigue_damage
	}
	send_options_exclusive = yes

	on_send = {
		scope:recipient = {
			add_to_variable_list = {
				name = efficiency_damagers
				target = scope:actor
				years = 2
			}
		}
	}

	auto_accept = yes

	on_accept = {
		switch = {
			trigger = yes
			scope:diplomacy_damage = {
				damage_governor_efficiency_duel_effect = { SKILL = diplomacy }
			}
			scope:stewardship_damage = {
				damage_governor_efficiency_duel_effect = { SKILL = stewardship }
			}
			scope:intrigue_damage = {
				damage_governor_efficiency_duel_effect = { SKILL = intrigue }
			}
			fallback = { damage_governor_efficiency_success_effect = yes } # Non-duel options always succeed
		}
	}

	ai_potential = {
		has_government = administrative_government
		top_liege = {
			any_vassal = {
				is_governor = yes
				NOT = { this = root }
			}
		}
	}

	ai_will_do = {
		base = -10
		modifier = { # Don't damage house members
			scope:recipient.house ?= scope:actor.house
			add = -10
		}
		modifier = { # Don't damage close family
			scope:recipient = { is_close_family_of = scope:actor }
			add = -10
		}
		modifier = { # Don't damage friends
			scope:actor = { has_relation_friend = scope:recipient }
			add = -10
		}
		modifier = { # Damage rivals
			scope:actor = { has_relation_rival = scope:recipient }
			add = 15
		}
		modifier = { # Damage when house stands to gain
			scope:recipient = {
				any_held_title = {
					tier >= tier_duchy
					current_heir.house = scope:actor.house
					scope:actor.house != scope:recipient.house
				}
			}
			add = 10
		}
		modifier = { # AI copy players they like
			scope:recipient = {
				any_in_list = {
					variable = efficiency_damagers
					is_ai = no
					NOT = { has_relation_rival = scope:actor }
					OR = {
						has_relation_friend = scope:actor
						AND = {
							exists = house
							scope:actor.house ?= house
						}
						is_close_family_of = scope:actor
					}
				}
			}
			add = 15
		}
		opinion_modifier = { # Opinion Factor - boost for characters they dislike
			who = scope:actor
			opinion_target = scope:recipient
			multiplier = -0.25
		}
	}
}

# Emperor fires Governor - AKA Depose Governor/depose_governor
governor_removal_interaction = {
	category = interaction_category_admin
	icon = icon_governor_removal
	common_interaction = yes
	desc = governor_removal_interaction_desc
	greeting = negative
	notification_text = GOVERNOR_REMOVAL_NOTIFICATION_TEXT
	popup_on_receive = yes
	pause_on_receive = yes
	cooldown_against_recipient = { years = 5 }

	auto_accept = yes

	is_shown = {
		scope:actor = {
			is_independent_ruler = yes
			has_government = administrative_government
		}
		scope:recipient = {
			NOT = { this = scope:actor }
			is_governor = yes
			is_vassal_of = scope:actor
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			NOT = { is_at_war_with = scope:recipient }
			any_vassal = {
				is_governor = yes
				NOT = { this = scope:actor }
			}
		}
	}

	is_highlighted = {
		scope:recipient ?= {
			any_held_title = {
				current_heir ?= {
					OR = {
						scope:actor ?= this
						is_close_family_of = scope:actor
					}
				}
			}
		}
	}

	highlighted_reason = HIGHLIGHTED_GOVERNOR_REMOVAL_HEIR

	can_send = {
		scope:recipient != scope:actor
		custom_tooltip = {
			text = demand_governor_removal_dominant_family_tt
			scope:recipient.house ?= { is_dominant_family = no }
		}
	}

	cost = {
		influence = {
			value = 0
			if = {
				limit = { exists = scope:recipient }
				scope:recipient ?= {
					if = {
						limit = {
							any_held_title = {
								tier = tier_kingdom
								is_landless_type_title = no
								
							}
						}
						add = {
							every_held_title = {
								limit = {
									tier = tier_kingdom
									is_landless_type_title = no
									
								}
								add = {
									value = scope:recipient.massive_influence_value
									multiply = 3
								}
							}
							desc = GOVERNOR_RESIGNATION_KINGDOM_COST
						}
					}
					else_if = {
						limit = {
							any_held_title = {
								tier = tier_duchy
								is_landless_type_title = no
								
							}
						}
						add = {
							every_held_title = {
								limit = {
									tier = tier_duchy
									is_landless_type_title = no
									
								}
								add = scope:recipient.massive_influence_value
							}
							desc = GOVERNOR_RESIGNATION_DUCHY_COST
						}
					}
					if = {
						limit = { house ?= { is_powerful_family = yes } }
						add = {
							value = scope:recipient.massive_influence_value
							desc = GOVERNOR_RESIGNATION_POWERFUL_COST
						}
					}
					else_if = {
						limit = { house ?= { is_dominant_family = yes } }
						add = {
							value = scope:recipient.monumental_influence_value
							desc = GOVERNOR_RESIGNATION_DOMINANT_COST
						}
					}
					if = {
						limit = {
							scope:actor = { is_ai = no } # This cost is only for players due to performance reasons
						}
						if = {
							limit = {
								scope:recipient.governor_efficiency != 1
							}
							add = {
								value = -100
								add = {
									value = scope:recipient.governor_efficiency
									multiply = 100
								}
								desc = GOVERNOR_RESIGNATION_EFFICIENCY_COST
							}
						}
					}
					if = {
						limit = {
							influence_level != 1
						}
						add = {
							value = {
								value = influence_level
								subtract = 1
							}
							multiply = 50
							desc = GOVERNOR_RESIGNATION_INFLUENCE_LEVEL_COST
						}
					}
				}
				scope:actor = {
					if = {
						limit = { has_revoke_title_reason = scope:recipient }
						multiply = {
							value = 0.5
							desc = temporal_condemnation_got_revoke_reason # Reused loc
						}
					}
				}
			}
		}
	}

	on_accept = {
		scope:recipient = {
			if = {
				limit = {
					exists = house
					house = {
						OR = {
							is_powerful_family = yes
							is_dominant_family = yes
						}
					}
					can_set_relation_rival_trigger = { CHARACTER = scope:actor }
				}
				progress_towards_rival_effect = {
					REASON = rival_deposed_governor
					CHARACTER = scope:actor
					OPINION = 0
				}
			}
			add_opinion = {
				target = scope:actor
				modifier = demanded_my_resignation_opinion
			}
			custom_tooltip = demanded_my_resignation_house_tt
			hidden_effect = {
				house ?= {
					if = {
						limit = {
							NOT = { this = scope:actor.house }
						}
						every_house_member = {
							custom = custom.every_house_member_secondary_recipient
							limit = {
								is_ai = yes
								NOT = { this = scope:recipient }
							}
							if = {
								limit = {
									house = {
										OR = {
											is_powerful_family = yes
											is_dominant_family = yes
										}
									}
								}
								add_opinion = {
									target = scope:actor
									modifier = demanded_my_house_members_resignation_opinion
									opinion = -20
								}
							}
							else = {
								add_opinion = {
									target = scope:actor
									modifier = demanded_my_house_members_resignation_opinion
									opinion = -15
								}
							}
						}
					}
				}
			}
			if = {
				limit = {
					any_held_title = {
						
						exists = current_heir
						current_heir = {
							NOR = {
								this = scope:actor
								AND = {
									exists = scope:recipient.house
									house ?= scope:recipient.house
								}
								has_relation_friend = scope:recipient
								has_relation_best_friend = scope:recipient
								is_allied_to = scope:recipient
								has_relation_soulmate = scope:recipient
								is_spouse_of = scope:recipient
								is_close_family_of = scope:recipient
							}
							opinion = {
								target = scope:recipient
								value <= 40
							}
						}
					}
				}
				every_held_title = {
					limit = {
						
						exists = current_heir
						current_heir = {
							NOR = {
								this = scope:actor
								AND = {
									exists = scope:recipient.house
									house ?= scope:recipient.house
								}
								has_relation_friend = scope:recipient
								has_relation_best_friend = scope:recipient
								is_allied_to = scope:recipient
								has_relation_soulmate = scope:recipient
								is_spouse_of = scope:recipient
								is_close_family_of = scope:recipient
							}
							opinion = {
								target = scope:recipient
								value <= 40
							}
						}
					}
					current_heir = {
						add_to_list = deposed_title_heirs
					}
				}
				every_in_list = {
					list = deposed_title_heirs
					add_opinion = {
						target = scope:actor
						modifier = deposed_predecessor_opinion
					}
				}
			}
			trigger_event = ep3_interactions_events.0630
			show_as_tooltip = {
				governor_resignation_title_transfer_effect = yes
			}
		}
	}

	on_decline = {
		scope:recipient = {
			add_opinion = {
				target = scope:actor
				modifier = demanded_my_resignation_opinion
			}
		}
		scope:actor = {
			send_interface_toast = {
				title = demand_governor_resignation_declined_toast
				type = event_toast_effect_bad
				left_icon = scope:recipient
				revocation_tyranny_effect = { VASSAL = scope:recipient }
				title_revocation_stress_effect = { VASSAL = scope:recipient }
			}
		}
		war_for_revoke_effect = {
			LIEGE = scope:actor
			REBEL = scope:recipient
		}
		scope:actor = {
			if = {
				limit = { has_realm_law_flag = vassal_refusal_is_treason }
				add_opinion = {
					target = scope:recipient
					modifier = treasonous_revoke_refusal
				}
			}
		}
	}

	send_option = {
		is_valid = {
			scope:actor = { has_usable_hook = scope:recipient }
		}
		flag = hook
		localization = GENERIC_SPEND_A_HOOK
	}
	should_use_extra_icon = {
		scope:actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	send_options_exclusive = no

	can_be_blocked = {
		custom_description = { #Hook from Recipient can counteract, but only if Actor is not forcing the action via Strong Hook.
			text = "spending_hook"
			subject = scope:recipient
			object = scope:actor
			scope:recipient = { has_hook = scope:actor }
			NAND = {
				scope:hook = yes
				scope:actor = { has_strong_hook = scope:recipient }
			}
		}
	}

	on_blocked_effect = {
		scope:recipient = {
			remove_hook = { target = scope:actor }
		}
	}

	# AI
	ai_targets = {
		ai_recipients = vassals
	}

	ai_frequency = 6
	ai_potential = {
		influence > massive_influence_value
		is_at_war = no # Don't spend influence when at war in case troops are needed
	}

	ai_will_do = {
		base = -10
		modifier = {
			scope:actor.house = scope:recipient.house
			add = -50
		}
		modifier = {
			scope:actor = { has_relation_rival = scope:recipient }
			add = 30
		}
		modifier = { # Get rid of bad governors, but there is no point if the heir is worse
			scope:recipient = {
				governor_efficiency <= 0.7
				governor_efficiency < scope:recipient.primary_heir.governor_efficiency
			}
			add = 10
		}
		modifier = {
			scope:recipient = {
				is_a_faction_member = yes
			}
			add = 20
		}
		modifier = {
			scope:recipient = {
				governor_efficiency >= 1.25
			}
			add = -10
		}
		modifier = {
			scope:recipient = {
				has_trait = loyal
			}
			add = -10
		}
		modifier = {
			scope:recipient = {
				has_trait = disloyal
			}
			add = 5
		}
		modifier = {
			scope:recipient = {
				is_allied_to = scope:actor
			}
			add = -100
		}
		modifier = {
			scope:recipient = {
				any_held_title = {
					current_heir ?= {
						house = scope:actor.house
						NOT = { this = scope:actor }
					}
				}
			}
			add = 10
		}
		opinion_modifier = { # Opinion Factor
			who = scope:actor
			opinion_target = scope:recipient
			multiplier = -0.25
		}
	}
}

# Demand Emperor fires Governor - AKA Compel Resignation/compel_resignation
force_governor_removal_interaction = {
	category = interaction_category_admin
	icon = icon_force_governor_removal
	desc = force_governor_removal_interaction_desc
	interface_priority = 95

	greeting = positive
	notification_text = DEMAND_GOVERNOR_REMOVAL_NOTIFICATION_TEXT
	can_send_despite_rejection = yes
	popup_on_receive = yes
	pause_on_receive = yes

	cooldown = { years = 5 }

	ai_maybe = yes
	ai_min_reply_days = 4
	ai_max_reply_days = 9

	is_shown = {
		scope:actor = {
			is_independent_ruler = no
			exists = top_liege
			top_liege = { has_government = administrative_government }
		}
		scope:secondary_recipient ?= { is_governor = yes }
		OR = {
			scope:secondary_recipient ?= { is_vassal_of = scope:recipient }
			scope:secondary_recipient ?= scope:recipient
		}
		scope:secondary_recipient != scope:actor
		scope:secondary_recipient != scope:recipient
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			NOR = {
				is_at_war_with = scope:recipient
				is_at_war_with = scope:secondary_recipient
			}
			top_liege = {
				any_vassal = {
					is_governor = yes
					NOT = { this = scope:actor }
				}
			}
		}
		scope:secondary_recipient = {
			NOT = { is_at_war_with = scope:recipient }
		}
	}

	is_highlighted = {
		scope:secondary_recipient ?= {
			any_held_title = {
				current_heir ?= {
					OR = {
						scope:actor ?= this
						house ?= scope:actor.house
					}
				}
			}
		}
	}

	highlighted_reason = HIGHLIGHTED_DEMAND_GOVERNOR_REMOVAL_HEIR

	can_send = {
		scope:secondary_recipient != scope:actor
		custom_tooltip = {
			text = demand_governor_removal_dominant_family_tt
			scope:secondary_recipient.house ?= { is_dominant_family = no }
		}
		scope:actor = {
			NAND = {
				is_ai = yes
				scope:recipient = { has_character_flag = force_governor_resignation_ai_cooldown }
			}
		}
	}

	can_be_picked = {
		house ?= { is_dominant_family = no }
		any_held_title = {
			is_landless_type_title = no
			
		}
		exists = house
		is_governor = yes
		NOR = {
			this = scope:actor
			this = scope:recipient
		}
	}

	redirect = {
		if = {
			limit = { scope:recipient != scope:actor.top_liege }
			scope:recipient = { save_scope_as = secondary_recipient }
		}
		scope:actor.top_liege ?= {
			save_scope_as = recipient
		}
	}

	populate_recipient_list = {
		scope:actor.top_liege = {
			every_vassal = {
				limit = {
					exists = house
					is_governor = yes
					NOR = {
						this = scope:actor
						this = scope:recipient
					}
				}
				add_to_list = characters
			}
		}
	}

	cost = {
		influence = {
			value = 0
			if = {
				limit = { exists = scope:secondary_recipient }
				scope:secondary_recipient ?= {
					if = {
						limit = {
							any_held_title = {
								tier = tier_duchy
								is_landless_type_title = no
								
							}
						}
						add = {
							value = 0
							every_held_title = {
								limit = {
									tier = tier_duchy
									is_landless_type_title = no
									
								}
								add = scope:secondary_recipient.massive_influence_value
							}
							desc = DEMAND_GOVERNOR_RESIGNATION_DUCHY_COST
						}
					}
					if = {
						limit = {
							any_held_title = {
								tier = tier_kingdom
								is_landless_type_title = no
								
							}
						}
						add = {
							value = 0
							every_held_title = {
								limit = {
									tier = tier_kingdom
									is_landless_type_title = no
									
								}
								add = {
									value = scope:secondary_recipient.massive_influence_value
									multiply = 2
								}
							}
							desc = DEMAND_GOVERNOR_RESIGNATION_KINGDOM_COST
						}
					}
					if = {
						limit = { house ?= { is_powerful_family = yes } }
						add = {
							value = scope:secondary_recipient.massive_influence_value
							desc = DEMAND_GOVERNOR_RESIGNATION_POWERFUL_COST
						}
					}
					else_if = {
						limit = { house ?= { is_dominant_family = yes } }
						add = {
							value = scope:secondary_recipient.monumental_influence_value
							desc = DEMAND_GOVERNOR_RESIGNATION_DOMINANT_COST
						}
					}
					else_if = {
						limit = { scope:secondary_recipient.governor_efficiency > 1 }
						add = {
							value = -100
							add = {
								value = scope:secondary_recipient.governor_efficiency
								multiply = 100
							}
							desc = DEMAND_GOVERNOR_RESIGNATION_EFFICIENCY_COST
						}
					}
					if = {
						limit = {
							influence_level != 1
						}
						add = {
							value = {
								value = influence_level
								subtract = 1
							}
							multiply = 50
							desc = DEMAND_GOVERNOR_RESIGNATION_INFLUENCE_LEVEL_COST
						}
					}
				}
			}
		}
	}

	on_accept = {
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_good
				title = force_governor_resignation_accepted_toast
				left_icon = scope:secondary_recipient
				right_icon = scope:recipient
				if = {
					limit = { scope:criminal_secret_recipient = yes}
					scope:actor = {
						random_known_secret = {
							limit = {
								secret_owner = scope:recipient
								is_criminal_for = scope:recipient
								can_be_exposed_by = scope:actor
							}
							disable_exposure_by = scope:actor
						}
					}
				}
				if = {
					limit = { scope:criminal_secret_secondary_recipient = yes }
					scope:actor = {
						random_known_secret = {
							limit = {
								secret_owner = scope:secondary_recipient
								is_criminal_for = scope:secondary_recipient
								can_be_exposed_by = scope:actor
								NOT = { is_known_by = scope:recipient }
							}
							reveal_to = scope:recipient
							disable_exposure_by = scope:actor
						}
					}
				}
				scope:secondary_recipient ?= {
					if = {
						limit = { is_ai = yes }
						add_opinion = {
							target = scope:actor
							modifier = forced_my_resignation_opinion
						}
					}
					progress_towards_rival_effect = {
						REASON = rival_forced_my_resignation_reason
						CHARACTER = scope:actor
						OPINION = default_rival_opinion
					}
					house ?= {
						if = {
							limit = {
								this != scope:actor.house
							}
							every_house_member = {
								custom = custom.every_house_member_secondary_recipient
								limit = {
									is_ai = yes
									this != scope:secondary_recipient
								}
								add_opinion = {
									target = scope:actor
									modifier = forced_my_house_members_resignation_opinion
								}
							}
						}
					}
					governor_resignation_title_transfer_effect = yes
				}
			}
			if = {
				limit = { scope:influence = yes }
				change_influence = massive_influence_loss
			}
		}
	}

	on_decline = {
		scope:secondary_recipient ?= {
			if = {
				limit = { is_ai = yes }
				add_opinion = {
					target = scope:actor
					modifier = attempted_force_my_resignation_opinion
				}
				add_opinion = {
					target = scope:recipient
					modifier = blocked_my_resignation_opinion
				}
			}
			custom_tooltip = demanded_my_resignation_blocked_house_tt
			hidden_effect = {
				scope:actor = {
					send_interface_toast = {
						type = event_toast_effect_bad
						title = force_governor_resignation_vetoed_toast
						left_icon = scope:secondary_recipient
						right_icon = scope:recipient
						scope:secondary_recipient = {
							send_interface_toast = {
								type = event_toast_effect_good
								title = force_governor_resignation_vetoed_toast
								left_icon = scope:actor
								right_icon = scope:recipient
								scope:recipient = { change_influence = medium_influence_loss }
								house ?= {
									every_house_member = {
										custom = custom.every_house_member_secondary_recipient
										limit = {
											is_ai = yes
											NOR = {
												this = scope:secondary_recipient
												this = scope:actor
												this = scope:recipient
											}
										}
										if = {
											limit = {
												NOT = { scope:actor.house ?= scope:secondary_recipient.house }
											}
											add_opinion = {
												target = scope:actor
												modifier = attempted_force_my_house_members_resignation_opinion
											}
										}
										if = {
											limit = {
												NOT = { scope:recipient.house ?= scope:secondary_recipient.house }
											}
											add_opinion = {
												target = scope:recipient
												modifier = blocked_my_house_members_resignation_opinion
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_bad
				title = force_governor_resignation_declined_toast
				left_icon = scope:secondary_recipient
				right_icon = scope:recipient
				scope:recipient = {
					title_revocation_stress_effect = { VASSAL = scope:secondary_recipient }

					if = {
						limit = { has_realm_law_flag = vassal_refusal_is_treason }
						add_opinion = {
							target = scope:secondary_recipient
							modifier = treasonous_revoke_refusal
						}
					}
					if = {
						limit = { scope:criminal_secret_recipient = yes}
						scope:actor = {
							random_known_secret = {
								limit = {
									secret_owner = scope:recipient
									is_criminal_for = scope:recipient
									can_be_exposed_by = scope:actor
								}
								expose_secret = scope:actor
							}
						}
					}
				}
			}
		}
	}

	on_send = {
		scope:actor.top_liege = {
			add_character_flag = {
				flag = force_governor_resignation_ai_cooldown
				months = 6
			}
		}
	}

	send_option = {
		is_valid = {
			scope:actor = { has_usable_hook = scope:recipient }
		}
		flag = hook
		localization = GENERIC_SPEND_A_HOOK
	}
	should_use_extra_icon = {
		scope:actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"
	send_option = {
		flag = influence
		is_valid = {
			scope:actor.influence >= massive_influence_value
		}
		localization = SPEND_INFLUENCE
	}
	send_option = {
		flag = criminal_secret_recipient
		is_shown = {
			scope:recipient = {
				any_secret = {
					is_criminal_for = scope:recipient
					is_known_by = scope:actor
					can_be_exposed_by = scope:actor
				}
			}
		}
		localization = LEVERAGE_CRIMINAL_SECRET_RECIPIENT
	}
	send_option = {
		flag = criminal_secret_secondary_recipient
		is_shown = {
			scope:secondary_recipient = {
				any_secret = {
					is_criminal_for = scope:secondary_recipient
					is_known_by = scope:actor
					can_be_exposed_by = scope:actor
					NOT = { is_known_by = scope:recipient }
				}
			}
		}
		localization = LEVERAGE_CRIMINAL_SECRET_SECONDARY_RECIPIENT
	}

	send_options_exclusive = no

	can_be_blocked = {
		custom_description = { #Hook from Recipient can counteract, but only if Actor is not forcing the action via Strong Hook.
			text = "spending_hook"
			subject = scope:recipient
			object = scope:actor
			scope:recipient = { has_hook = scope:actor }
			NAND = {
				scope:hook = yes
				scope:actor = { has_strong_hook = scope:recipient }
			}
		}
	}

	on_blocked_effect = {
		scope:recipient = {
			remove_hook = { target = scope:actor }
		}
	}

	# AI
	ai_targets = {
		ai_recipients = peer_vassals
		max = 10
	}
	ai_targets = {
		ai_recipients = liege
	}

	ai_frequency = 60
	ai_potential = {
		influence > massive_influence_value
		is_independent_ruler = no
		has_government = administrative_government
	}
	ai_accept = {
		base = -50
		# SEND OPTIONS
		modifier = {
			scope:hook = yes
			add = 30
			desc = SCHEME_WEAK_HOOK_USED
		}
		modifier = {
			desc = INFLUENCE_REASON
			scope:influence = yes
			add = {
				value = 20
				multiply = scope:actor.influence_level
				min = 5
			}
		}
		modifier = {
			desc = RECIPIENT_SECRET
			scope:criminal_secret_recipient = yes
			add = 50
		}
		modifier = {
			desc = SECONDARY_RECIPIENT_SECRET
			scope:criminal_secret_secondary_recipient = yes
			add = 50
		}

		modifier = {
			add = {
				value = -100
				add = {
					value = scope:secondary_recipient.governor_efficiency
					multiply = 100
				}
				multiply = -1
				round = yes
			}
			desc = SECONDARY_RECIPIENT_GOVERNOR_EFFICIENCY
		}
		modifier = {
			scope:secondary_recipient.dynasty = scope:recipient.dynasty
			scope:secondary_recipient.house != scope:recipient.house
			NOT = {
				scope:secondary_recipient = { is_close_family_of = scope:recipient }
			}
			add = -30
			desc = THEY_ARE_MY_HOUSE_MEMBER
		}
		modifier = {
			scope:secondary_recipient.house = scope:recipient.house
			NOT = {
				scope:secondary_recipient = { is_close_family_of = scope:recipient }
			}
			add = -50
			desc = THEY_ARE_MY_HOUSE_MEMBER
		}
		modifier = {
			scope:secondary_recipient = { is_close_family_of = scope:recipient }
			add = -70
			desc = THEY_ARE_MY_CLOSE_FAMILY
		}
		modifier = {
			scope:secondary_recipient = { is_councillor = yes }
			add = -15
			desc = THEY_ARE_MY_COUNCILLOR
		}
		modifier = {
			scope:recipient = { is_spouse_of = scope:secondary_recipient }
			add = -25
			desc = THEY_ARE_MY_SPOUSE
		}
		modifier = {
			scope:recipient = { has_relation_friend = scope:secondary_recipient }
			add = -30
			desc = THEY_ARE_MY_FRIEND
		}
		modifier = {
			scope:recipient = { has_relation_rival = scope:secondary_recipient }
			add = 25
			desc = THEY_ARE_MY_RIVAL
		}
		modifier = {
			scope:secondary_recipient.house = {
				is_powerful_family = yes
				NOR = {
					this = scope:actor.house
					this = scope:intermediary.house
				}
			}
			add = -20
			desc = TARGET_FAMILY_IS_POWERFUL
		}
		modifier = {
			scope:actor.house = {
				is_powerful_family = yes
				NOR = {
					this = scope:actor.house
					this = scope:intermediary.house
				}
			}
			add = 20
			desc = YOUR_FAMILY_IS_POWERFUL
		}
		modifier = {
			scope:actor.house = {
				is_dominant_family = yes
				NOT = { this = scope:recipient.house }
			}
			add = 30
			desc = YOUR_FAMILY_IS_DOMINANT
		}
		modifier = {
			scope:secondary_recipient.house = {
				is_dominant_family = yes
				this != scope:recipient.house
			}
			add = -30
			desc = TARGET_FAMILY_IS_DOMINANT
		}
		modifier = {
			scope:secondary_recipient = {
				house != scope:recipient.house
				any_held_title = {
					current_heir ?= {
						is_close_family_of = scope:recipient
						NOT = { this = scope:recipient }
					}
				}
			}
			add = 30
			desc = THEIR_HOUSE_MEMBER_STANDS_TO_INHERIT
		}
		opinion_modifier = {
			who = scope:recipient
			opinion_target = scope:secondary_recipient
			multiplier = -0.5
		}
		opinion_modifier = {
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 0.5
		}
	}
	auto_accept = {
		trigger_if = {
			limit = {
				scope:hook ?= yes
				scope:actor = { has_strong_hook = scope:recipient }
			}
			custom_description = {
				text = "spending_hook"
				subject = scope:actor
				object = scope:recipient
				scope:hook ?= yes
				scope:actor = { has_strong_hook = scope:recipient }
			}
		}
		trigger_else = { always = no }
	}

	ai_will_do = {
		base = -10
		modifier = {
			scope:actor.house = scope:recipient.house
			add = -50
		}
		modifier = {
			scope:actor = { has_relation_rival = scope:secondary_recipient }
			add = 10
		}
		modifier = {
			scope:secondary_recipient = {
				any_held_title = { current_heir.house ?= scope:actor.house }
			}
			add = 10
		}
		modifier = {
			scope:actor = {
				OR = {
					has_relation_friend = scope:secondary_recipient
					has_relation_lover = scope:secondary_recipient
					is_spouse_of = scope:secondary_recipient
					is_close_family_of = scope:secondary_recipient
				}
			}
			add = -50
		}
	}
}

# Force Step Down
force_step_down_interaction = {
	icon = icon_force_to_step_down
	common_interaction = yes
	interface_priority = 65
	category = interaction_category_admin

	cooldown_against_recipient = { years = 5 }

	target_type = title
	target_filter = recipient_domain_titles
	can_be_picked_title = {
		scope:target = {
			tier = tier_duchy
			
		}
	}
	has_valid_target_showing_failures_only = {
		scope:target = {
			tier = tier_duchy
			
		}
	}

	ai_target_quick_trigger = { adult = yes }
	ai_targets = {
		ai_recipients = vassals
		ai_recipients = peer_vassals
		max = 10
	}

	ai_maybe = yes
	ai_min_reply_days = 4
	ai_max_reply_days = 9
	can_send_despite_rejection = yes
	popup_on_receive = yes

	greeting = negative
	notification_text = FORCE_STEP_DOWN_PROPOSAL

	pre_answer_yes_key = ACCEPT
	pre_answer_no_key = DECLINE

	ai_frequency = 180

	is_shown = {
		scope:actor = {
			has_government = administrative_government
			is_independent_ruler = no
			this != scope:recipient
		}
		scope:recipient = {
			has_government = administrative_government
			is_governor = yes
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			is_adult = yes
			is_imprisoned = no
			is_in_civil_war = no
		}
		scope:recipient = {
			is_in_civil_war = no
		}
	}

	desc = scheme_interaction_tt_force_step_down_approved

	send_options_exclusive = no
	send_option = {
		flag = hook
		is_valid = {
			scope:actor = { has_usable_hook = scope:recipient }
			NOT = {
				scope:recipient = { has_hook = scope:actor }
			}
		}
		localization = GENERIC_SPEND_A_HOOK
	}
	should_use_extra_icon = {
		scope:actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"
	send_option = {
		flag = influence
		is_valid = {
			scope:actor.influence >= massive_influence_value
		}
		localization = SPEND_INFLUENCE
	}
	send_option = {
		flag = gold
		is_valid = {
			scope:actor.gold >= scope:actor.massive_gold_value
		}
		localization = GENERIC_SPEND_GOLD
	}
	send_option = {
		flag = criminal_secret_recipient
		is_shown = {
			scope:recipient = {
				any_secret = {
					is_criminal_for = scope:recipient
					is_known_by = scope:actor
					can_be_exposed_by = scope:actor
				}
			}
		}
		localization = LEVERAGE_CRIMINAL_SECRET_RECIPIENT
	}

	on_accept = {
		scope:actor = {
			# Save the number of held governorships
			scope:recipient = {
				save_scope_value_as = {
					name = recipient_number_of_governorships
					value = {
						value = 0
						every_held_title = {
							limit = {
								tier >= tier_duchy
								
							}
							add = 1
						}
					}
				}
			}

			if = {
				limit = { scope:hook = yes }
				use_hook = scope:recipient
			}
			if = {
				limit = { scope:influence = yes }
				change_influence = {
					value = massive_influence_loss
					multiply = 2
					multiply = scope:recipient_number_of_governorships
				}
			}
			if = {
				limit = { scope:gold = yes }
				pay_short_term_gold = {
					target = scope:recipient
					gold = {
						value = massive_gold_value
						multiply = scope:recipient_number_of_governorships
					}
				}
			}
			if = {
				limit = { scope:criminal_secret_recipient = yes}
				scope:actor = {
					random_known_secret = {
						limit = {
							secret_owner = scope:recipient
							is_criminal_for = scope:recipient
							can_be_exposed_by = scope:actor
						}
						disable_exposure_by = scope:actor
					}
				}
			}
			send_interface_toast = {
				type = event_toast_effect_good
				title = force_governor_resignation_accepted_toast
				left_icon = scope:target
				right_icon = scope:recipient
				scope:recipient = {
					custom_tooltip = loses_target_title_tt
					if = {
						limit = { is_ai = yes }
						add_opinion = {
							target = scope:actor
							modifier = forced_my_resignation_opinion
						}
					}
					if = {
						limit = { can_set_relation_rival_trigger = { CHARACTER = scope:actor } }
						set_relation_rival = {
							target = scope:actor
							reason = rival_forced_my_resignation_reason
						}
					}
					house ?= {
						if = {
							limit = {
								this != scope:actor.house
							}
							every_house_member = {
								custom = custom.every_house_member_recipient
								limit = {
									is_ai = yes
									this != scope:secondary_recipient
								}
								add_opinion = {
									target = scope:actor
									modifier = forced_my_house_members_resignation_opinion
								}
							}
						}
					}
					
					force_step_down_landed_titles = yes
				}
			}
		}
	}

	on_decline = {
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_bad
				title = force_governor_resignation_declined_toast
				left_icon = scope:target
				right_icon = scope:recipient

				change_influence = major_influence_loss
				add_prestige = medium_prestige_loss
				scope:recipient = {
					add_opinion = {
						target = scope:actor
						modifier = attempted_force_step_down_opinion
					}
					if = {
						limit = { can_set_relation_rival_trigger = { CHARACTER = scope:actor } }
						set_relation_rival = {
							target = scope:actor
							reason = rival_attempted_to_force_my_resignation_reason
						}
					}
				}
				if = {
					limit = { scope:criminal_secret_recipient = yes}
					scope:actor = {
						random_known_secret = {
							limit = {
								secret_owner = scope:recipient
								is_criminal_for = scope:recipient
								can_be_exposed_by = scope:actor
							}
							expose_secret = scope:actor
						}
					}
				}
			}
		}
	}

	auto_accept = {
		trigger_if = {
			limit = {
				scope:hook ?= yes
				scope:actor = { has_strong_hook = scope:recipient }
			}
			custom_description = {
				text = "spending_hook"
				subject = scope:actor
				object = scope:recipient
				scope:hook ?= yes
				scope:actor = { has_strong_hook = scope:recipient }
			}
		}
		trigger_else = { always = no }
	}

	ai_accept = {
		base = 0

		# SEND OPTIONS
		modifier = {
			scope:hook = yes
			add = 30
			desc = SCHEME_WEAK_HOOK_USED
		}
		modifier = {
			desc = INFLUENCE_REASON
			scope:influence = yes
			add = {
				value = 20
				multiply = scope:actor.influence_level
				min = 5
			}
		}
		modifier = {
			desc = GOLD_REASON
			scope:gold = yes
			add = 30
		}
		modifier = {
			desc = RECIPIENT_SECRET
			scope:criminal_secret_recipient = yes
			add = 50
		}

		# TRAITS
		modifier = {
			scope:recipient = { has_trait = craven }
			add = 10
			desc = INTERACTION_CRAVEN
		}
		modifier = {
			scope:recipient = { has_trait = trusting }
			add = 5
			desc = INTERACTION_TRUSTING
		}
		modifier = {
			scope:recipient = { has_trait = generous }
			add = 5
			desc = INTERACTION_GENEROUS
		}
		modifier = {
			scope:recipient = { has_trait = lazy }
			add = 10
			desc = INTERACTION_LAZY
		}
		modifier = {
			scope:recipient = { has_trait = paranoid }
			add = -20
			desc = INTERACTION_PARANOID
		}
		modifier = {
			scope:recipient = { has_trait = patient }
			add = -5
			desc = INTERACTION_PATIENT
		}
		modifier = {
			scope:recipient = { has_trait = brave }
			add = -10
			desc = INTERACTION_BRAVE
		}
		modifier = {
			scope:recipient = { has_trait = greedy }
			add = -10
			desc = INTERACTION_GREEDY
		}
		modifier = {
			scope:recipient = { has_trait = ambitious }
			add = -20
			desc = INTERACTION_AMBITIOUS
		}

		# INTRIGUE COMPARISON
		modifier = {
			add = {
				value = scope:actor.intrigue
				multiply = 2
			}
			desc = INTERACTION_ACTOR_INTRIGUE
		}
		modifier = {
			add = {
				value = scope:recipient.intrigue
				multiply = -2
			}
			desc = INTERACTION_RECIPIENT_INTRIGUE
		}
	}

	ai_potential = {
		NOT = {
			any_scheme = {
				is_scheme_category = political
			}
		}
		has_government = administrative_government
		is_independent_ruler = no
		highest_held_title_tier >= tier_duchy
	}

	ai_will_do = {
		base = -200

		opinion_modifier = {
			who = scope:actor
			opinion_target = scope:recipient
			multiplier = -1
		}

		modifier = { # AI should really only use this if they have a house member in line for the title
			house = {
				any_house_member = {
					scope:recipient.primary_title = {
						place_in_line_of_succession = {
							target = prev
							value <= 3
						}
					}
				}
			}
			add = 100
		}

		#Personality
		modifier = {
			has_trait = vengeful
			add = 10
		}

		modifier = {
			has_trait = deceitful
			add = 10
		}

		modifier = {
			has_trait = honest
			add = -10
		}

		# House & Family
		modifier = {
			is_close_family_of = scope:recipient
			add = -500
		}
		modifier = {
			house = scope:recipient.house
			add = -500
		}

		#Feuds
		modifier = {
			house.house_head ?= {
				any_owned_story = {
					story_type = story_cycle_house_feud
					has_variable = house_feud_house
					var:house_feud_house = scope:recipient.house
				}
			}
			add = 75
		}

		# Relationships
		modifier = {
			add = 25
			has_any_mild_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}

		modifier = {
			add = 50
			has_any_moderate_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}

		modifier = {
			add = 100
			has_any_worst_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}

		modifier = {
			add = -50
			has_any_mild_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}

		modifier = {
			add = -100
			has_any_moderate_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}

		modifier = {
			factor = 0
			has_any_best_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}
	}
}

# Request a governorship from your liege
request_governorship_interaction = {
	category = interaction_category_admin
	icon = icon_request_governorship
	desc = request_governorship_interaction_desc
	common_interaction = yes
	interface_priority = 95
	is_highlighted = {
		always = yes
	}

	ai_maybe = yes
	ai_min_reply_days = 4
	ai_max_reply_days = 9
	can_send_despite_rejection = yes
	popup_on_receive = yes

	greeting = positive
	notification_text = REQUEST_GOVERNORSHIP_PROPOSAL

	pre_answer_yes_key = ACCEPT
	pre_answer_no_key = DECLINE

	ai_targets = { ai_recipients = liege }
	ai_target_quick_trigger = { adult = yes }
	ai_frequency = 36

	cooldown_against_recipient = { years = 10 }

	redirect = {
		scope:recipient = { save_scope_as = secondary_recipient }
	}

	cost = {
		influence = {
			add = {
				add = {
					value = scope:actor.monumental_influence_value
					multiply = 2
				}
				desc = BASE
			}
			# Province Size
			add = {
				value = 0
				if = {
					limit = { exists = scope:target }
					scope:target = {
						every_de_jure_county = { add = 10 }
					}
				}
				multiply = 2
				desc = province_size_desc
			}
			# Being a Powerful or Dominant Family reduces the cost significantly
			scope:actor.house = {
				if = {
					limit = { is_dominant_family = yes }
					multiply = {
						value = 0.25
						desc = is_dominant_family_desc
					}
				}
				else_if = {
					limit = { is_powerful_family = yes }
					multiply = {
						value = 0.5
						desc = is_powerful_family_desc
					}
				}
			}
			# Only asking for candidate score
			scope:target = {
				if = {
					limit = {
						exists = holder
						NOT = { holder = scope:recipient }
					}
					multiply = {
						value = 0.5
						desc = candidacy_request_desc
					}
				}
			}
		}
	}

	is_shown = {
		scope:recipient != scope:actor
		scope:recipient = scope:actor.top_liege
		scope:actor = {
			has_government = administrative_government
			is_governor = no
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			is_adult = yes
			is_landed = no
			NOT = { is_at_war_with = scope:recipient }
		}
	}

	target_type = title
	target_filter = secondary_recipient_de_jure_titles

	can_be_picked_title = {
		scope:target = {
			custom_tooltip = {
				text = request_governorship_interaction_tier_tt
				OR = {
					tier = tier_duchy
					tier = tier_kingdom
				}
			}
			trigger_if = {
				limit = { is_title_created = no }
				custom_tooltip = {
					text = request_governorship_interaction_created_tt
					any_de_jure_county = { holder = scope:recipient }
				}
			}
			trigger_else = {
				custom_tooltip = {
					text = request_governorship_interaction_holder_tt
					holder.top_liege = scope:actor.top_liege
				}
			}
			custom_tooltip = {
				text = request_governorship_interaction_liege_duchy_tt
				NOT = {
					any_de_jure_county = { this = scope:recipient.capital_county }
				}
			}
			trigger_if = {
				limit = { scope:target.holder ?= scope:recipient }
				custom_tooltip = {
					text = request_governorship_interaction_county_tt
					any_de_jure_county = { holder = scope:recipient }
				}
			}
		}
	}

	has_valid_target_showing_failures_only = {
		scope:target.tier = tier_duchy
		trigger_if = {
			limit = { exists = scope:target.holder }
			scope:target.holder ?= { has_government = administrative_government }
		}
	}

	can_send = {
		scope:actor = {
			is_landed = no
		}
	}

	on_send = {
		save_scope_value_as = {
			name = influence_cost
			value = {
				add = {
					add = {
						value = scope:actor.monumental_influence_value
						multiply = 2
					}
					desc = BASE
				}
				# Province Size
				add = {
					value = 0
					if = {
						limit = { exists = scope:target }
						scope:target = {
							every_de_jure_county = { add = 10 }
						}
					}
					multiply = 2
					desc = province_size_desc
				}
				# Being a Powerful or Dominant Family reduces the cost significantly
				scope:actor.house = {
					if = {
						limit = { is_dominant_family = yes }
						multiply = {
							value = 0.25
							desc = is_dominant_family_desc
						}
					}
					else_if = {
						limit = { is_powerful_family = yes }
						multiply = {
							value = 0.5
							desc = is_powerful_family_desc
						}
					}
				}
				# Only asking for candidate score
				scope:target = {
					if = {
						limit = {
							exists = holder
							NOT = { holder = scope:recipient }
						}
						multiply = {
							value = 0.5
							desc = candidacy_request_desc
						}
					}
				}
			}
		}
	}

	on_accept = {
		scope:recipient = {
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = request_governorship_interaction_toast_liege
				left_icon = scope:actor
				right_icon = scope:target
				change_influence = massive_influence_gain
				scope:actor = {
					# Grant title if held by Liege or uncreated but de jure land is held
					if = {
						limit = {
							scope:target = {
								OR = {
									is_title_created = no
									holder ?= scope:recipient
								}
							}
						}
						send_interface_toast = {
							type = event_toast_effect_good
							title = request_governorship_interaction_toast_granted
							left_icon = scope:target
							right_icon = scope:recipient
							# Create Title if necessary
							hidden_effect = {
								scope:target ?= {
									if = {
										limit = { is_title_created = no }
										create_title_and_vassal_change = {
											type = created
											save_scope_as = creation_change
										}
										change_title_holder = {
											holder = scope:recipient
											change = scope:creation_change
										}
										resolve_title_and_vassal_change = scope:creation_change
									}
								}
							}
							# Move Titles
							create_title_and_vassal_change = {
								type = appointment
								save_scope_as = grant_change
							}
							scope:target = {
								# Transfer counties
								hidden_effect = {
									every_de_jure_county = {
										limit = { holder = scope:recipient }
										change_title_holder = {
											holder = scope:actor
											change = scope:grant_change
										}
									}
								}
								# Transfer governorship
								change_title_holder_include_vassals = {
									holder = scope:actor
									change = scope:grant_change
								}
							}
							resolve_title_and_vassal_change = scope:grant_change
						}
					}
					# Grant Appointment score if already has a Governor
					else = {
						send_interface_toast = {
							type = event_toast_effect_good
							title = request_governorship_interaction_toast_candidacy
							left_icon = scope:target
							right_icon = scope:recipient
							scope:target ?= {
								change_appointment_investment = {
									target = scope:actor
									investor = scope:recipient
									value = appointment_major_influence_cost
								}
							}
						}
						scope:target = {
							ordered_title_heir = {
								limit = {
									NOR = {
										house ?= scope:actor.house
										house ?= scope:recipient.house
									}
								}
								order_by = "appointment_candidate_score(scope:target)"
								check_range_bounds = no
								max = 3
								if = {
									limit = {
										is_house_head = no
										exists = house.house_head
										NOR = {
											house.house_head = scope:actor
											house.house_head = scope:recipient
										}
									}
									house.house_head = {
										if = {
											limit = {
												NOT = { is_in_list = governorship_house_head_opinion }
											}
											add_to_list = governorship_house_head_opinion
										}
									}
								}
								else = { add_to_list = governorship_direct_opinion }
							}
						}
						every_in_list = {
							list = governorship_house_head_opinion
							add_opinion = {
								target = scope:actor
								modifier = requested_house_heired_governorship
							}
						}
						every_in_list = {
							list = governorship_direct_opinion
							add_opinion = {
								target = scope:actor
								modifier = requested_heired_governorship
							}
						}
					}
				}
			}
		}
	}

	on_decline = {
		scope:actor = {
			if = {
				limit = { is_ai = yes }
				add_opinion = {
					target = scope:recipient
					modifier = disappointed_opinion
					opinion = -15
				}
			}
			trigger_event = ep3_interactions_events.0021
		}
	}

	ai_potential = {
		is_governor = no
	}

	ai_will_do = {
		base = 0
		# Increase chance if greed and/or boldness is high enough
		modifier = {
			add = 20
			ai_greed >= medium_positive_ai_value
			ai_boldness >= medium_positive_ai_value
		}
		modifier = {
			add = 15
			ai_greed >= high_positive_ai_value
		}
		modifier = {
			add = 15
			ai_boldness >= high_positive_ai_value
		}
	}

	ai_accept = {
		base = -15
		opinion_modifier = { # Opinion of you
			who = scope:recipient
			opinion_target = scope:actor
			desc = AI_LIEGE_OPINION_REASON
		}
		modifier = {
			exists = scope:target.current_heir
			NOR = {
				scope:target.current_heir = scope:recipient
				scope:target.current_heir = scope:actor
				trigger_if = {
					limit = { exists = scope:target.current_heir.house.house_head }
					scope:target.current_heir != scope:target.current_heir.house.house_head
				}
			}
			add = {
				value = "scope:recipient.opinion(scope:target.current_heir)"
				divide = 2
				round = yes
			}
			desc = AI_LIEGE_OPINION_HEIR_REASON
		}
		modifier = {
			exists = scope:target.current_heir
			scope:target.current_heir.house.house_head ?= scope:target.current_heir
			NOR = {
				scope:target.current_heir = scope:recipient
				scope:target.current_heir = scope:actor
			}
			add = {
				value = "scope:recipient.opinion(scope:target.current_heir)"
				divide = 2
				round = yes
			}
			desc = AI_LIEGE_OPINION_HEIR_REASON
		}
		modifier = {
			exists = scope:target.current_heir.house.house_head
			NOR = {
				scope:target.current_heir.house.house_head = scope:target.current_heir
				scope:target.current_heir.house.house_head = scope:recipient
				scope:target.current_heir.house.house_head = scope:actor
			}
			add = {
				value = "scope:recipient.opinion(scope:target.current_heir.house.house_head)"
				round = yes
			}
			desc = AI_LIEGE_OPINION_HEIR_HOUSE_HEAD_REASON
		}
		ai_value_modifier = {
			ai_energy = 0.1 		#It's a change
			ai_greed = 0.2 			#Free influence is free influence
			ai_honor = -0.2 		#Some might see it as a bribe
		}
		# Your Efficiency
		modifier = {
			add = {
				value = {
					value = scope:actor.governor_efficiency
					multiply = 25
				}
				round = yes
			}
			desc = AI_GOVERNOR_EFFICIENCY
		}
		# Heir Governor Efficiency
		modifier = {
			exists = scope:target.current_heir
			NOR = {
				scope:target.current_heir = scope:recipient
				scope:target.current_heir = scope:actor
			}
			add = {
				value = {
					value = scope:target.current_heir.governor_efficiency
					multiply = -50
				}
				round = yes
			}
			desc = AI_GOVERNOR_EFFICIENCY_HEIR
		}
		# Your family is dominant
		modifier = {
			scope:actor.house = { is_dominant_family = yes }
			desc = AI_DOMINANT_FAMILY
			add = 50
		}
		# Your family is powerful
		modifier = {
			scope:actor.house = { is_powerful_family = yes }
			desc = AI_POWERFUL_FAMILY
			add = 25
		}
		# Heir family is dominant
		modifier = {
			scope:target.current_heir.house ?= { is_dominant_family = yes }
			desc = AI_HEIR_DOMINANT_FAMILY
			add = -50
		}
		# Heir family is powerful
		modifier = {
			scope:target.current_heir.house ?= { is_powerful_family = yes }
			desc = AI_HEIR_POWERFUL_FAMILY
			add = -25
		}
		# House of Emperor
		modifier = {
			scope:actor.house != scope:recipient.house
			scope:target.current_heir.house ?= scope:recipient.house
			desc = AI_HEIR_IS_MY_HOUSE
			add = -50
		}
		# You are more influential than heir
		modifier = {
			exists = scope:target.current_heir
			scope:actor.influence_level != scope:target.current_heir.influence_level
			add = {
				value = scope:actor.influence_level
				subtract = scope:target.current_heir.influence_level
				multiply = 2
			}
			desc = AI_DIFFERENCE_INFLUENCE
		}
		# Size of Province
		modifier = {
			exists = scope:target
			add = {
				value = 0
				scope:target = {
					every_de_jure_county = { add = -1 }
				}
				multiply = 2
			}
			desc = AI_THEME_SIZE
		}
		# Kingdoms are harder to request
		modifier = {
			scope:target ?= { tier = tier_kingdom }
			add = -50
			desc = AI_THEME_IS_KINGDOM
		}
		# Province is close to the capital duchy
		modifier = {
			add = -10
			scope:target.tier <= tier_duchy
			trigger_if = {
				limit = { scope:target.tier = tier_duchy }
				scope:target = { save_temporary_scope_as = duchy }
			}
			trigger_else = {
				scope:target.duchy = { save_temporary_scope_as = duchy }
			}
			scope:duchy = {
				OR = {
					this = scope:recipient.capital_county.duchy
					any_title_to_title_neighboring_and_across_water_duchy = { this = scope:recipient.capital_county.duchy }
				}
			}
			desc = AI_THEME_CLOSE_TO_CAPITAL
		}
		# Province is far from the capital
		modifier = {
			add = 10
			trigger_if = {
				limit = { scope:target.tier = tier_kingdom }
				scope:target = { save_temporary_scope_as = kingdom }
			}
			trigger_else = {
				scope:target.kingdom = { save_temporary_scope_as = kingdom }
			}
			scope:kingdom = {
				NOR = {
					this = scope:recipient.capital_county.kingdom
					any_title_to_title_neighboring_and_across_water_kingdom = { this = scope:recipient.capital_county.kingdom }
				}
			}
			desc = AI_THEME_FAR_FROM_CAPITAL
		}
	}
}

# Adopt character to Noble Family
noble_family_adoption_interaction = {
	icon = icon_dynasty
	category = interaction_category_friendly
	interface_priority = 60

	desc = noble_family_adoption_interaction_desc
	use_diplomatic_range = yes

	ai_min_reply_days = 4
	ai_max_reply_days = 9
	ai_maybe = yes

	cooldown_against_recipient = { years = 5 }

	is_shown = {
		NOT = { scope:actor = scope:recipient }
		scope:actor = {
			culture = { has_cultural_parameter = allows_noble_family_adoption }
			house.house_head ?= {
				any_held_title = { is_noble_family_title = yes }
			}
		}
		scope:recipient = {
			# Don't get imprisoned and so on
			is_available = yes
			NOR = {
				# They don't already belong to your house
				house ?= scope:actor.house
				# Don't adopt your own grandkids
				any_ancestor = { this = scope:actor }
			}
		}
	}

	is_valid = {}

	is_valid_showing_failures_only = {
		scope:actor = {
			is_adult = yes
		}
		can_recruit_character_to_court_trigger = {
			RECRUITER = scope:actor
			RECRUITEE = scope:recipient
		}
		scope:recipient = {
			age >= 10
			trigger_if = {
				limit = { exists = house.house_head }
				custom_tooltip = {
					text = adopt_interaction_noble_family_is_not_house_head_tt
					NOT = { scope:recipient.house.house_head = scope:recipient }
				}
			}
			is_ruler = no
		}
		scope:actor = {
			custom_tooltip = {
				text = adopt_interaction_noble_family_house_head_tt
				is_house_head = yes
			}
		}
	}

	send_option = {
		is_valid = { scope:actor.gold >= scope:actor.minor_gold_value }
		flag = gold
		localization = GENERIC_SPEND_GOLD
	}
	send_option = {
		is_valid = {
			scope:actor = { has_usable_hook = scope:recipient }
			NOT = {
				scope:recipient = { has_hook = scope:actor }
			}
		}
		flag = hook
		localization = GENERIC_SPEND_A_HOOK
	}
	should_use_extra_icon = {
		scope:actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	send_options_exclusive = no

	on_accept = {
		show_as_tooltip = {
			noble_family_adoption_effect = {
				ADOPTEE = scope:recipient
				ADOPTER = scope:actor
			}
		}
		hidden_effect = {
			scope:actor = { trigger_event = ep3_interactions_events.0400 }
		}
	}

	on_decline = {
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_bad
				title = noble_family_adoption_effect_toast
				left_icon = scope:recipient
				right_icon = scope:actor.house
				scope:recipient = {
					send_interface_toast = {
						type = event_toast_effect_bad
						title = noble_family_adoption_effect_toast
						left_icon = scope:recipient
						right_icon = scope:actor.house
						if = {
							limit = { scope:actor = { is_ai = yes } }
							reverse_add_opinion = {
								modifier = angry_opinion
								opinion = -20
								target = scope:actor
							}
						}
						if = {
							limit = { is_ai = yes }
							add_opinion = {
								modifier = respect_opinion
								opinion = -10
								target = scope:actor
							}
						}
					}
				}
			}
		}
	}

	cost = {
		prestige = {
			value = {
				add = medium_prestige_value
				if = {
					limit = {
						scope:actor = {
							OR = {
								culture = { has_cultural_parameter = free_adoption }
								has_game_rule = adoption_always_allowed
								# Replace with Influence for Admin noble families
								house.house_head ?= {
									any_held_title = { is_noble_family_title = yes }
								}
							}
						}
					}
					multiply = 0
				}
			}
		}
		piety = {
			value = {
				add = medium_piety_value
				if = {
					limit = {
						scope:actor = {
							OR = {
								culture = { has_cultural_parameter = free_adoption }
								has_game_rule = adoption_always_allowed
							}
						}
					}
					multiply = 0
				}
				# No piety cost for adopting a righteous-faith child
				if = {
					limit = {
						scope:actor.faith = {
							faith_hostility_level = {
								target = scope:recipient.faith
								value < faith_astray_level
							}
						}
					}
					multiply = 0
				}
				else_if = {
					limit = {
						scope:actor.faith = {
							faith_hostility_level = {
								target = scope:recipient.faith
								value > faith_astray_level
							}
						}
					}
					add = minor_piety_value
				}
				else_if = {
					limit = {
						scope:actor.faith = {
							faith_hostility_level = {
								target = scope:recipient.faith
								value > faith_hostile_level
							}
						}
					}
					add = medium_piety_value
				}
			}
		}
		influence = {
			value = {
				value = 0
				# Influence cost for Admin noble families
				if = {
					limit = {
						scope:actor.house.house_head ?= {
							any_held_title = { is_noble_family_title = yes }
						}
					}
					add = massive_influence_gain
				}
				if = {
					limit = {
						scope:actor = {
							OR = {
								culture = { has_cultural_parameter = free_adoption }
								has_game_rule = adoption_always_allowed
							}
						}
					}
					multiply = 0
				}
			}
		}
	}

	ai_potential = {
		is_house_head = yes
		house ?= {
			any_house_member = {
				count <= 5
				is_alive = yes
			}
		}
	}

	ai_targets = {
		ai_recipients = courtiers
		ai_recipients = guests
		# Friends, wards, etc.
		ai_recipients = scripted_relations
		max = 20
	}

	ai_accept = {
		base = 0
		modifier = {
			exists = house
			any_parent = {
				is_alive = yes
				house = scope:recipient.house
			}
			add = -15
			desc = MY_PARENT_HOUSE
		}
		modifier = {
			exists = house.house_head
			is_close_family_of = house.house_head
			add = -15
			desc = CLOSE_FAMILY_OF_HOUSE_HEAD
		}
		modifier = {
			scope:hook = yes
			add = 40
			desc = SCHEME_WEAK_HOOK_USED
		}
		modifier = {
			scope:gold = yes
			add = 25
			desc = SCHEME_WITH_GIFT_SIGNIFICANT
		}
		modifier = { # I have a house
			add = -15
			desc = I_ALREADY_HAVE_A_HOUSE
			exists = house.house_head
		}
		modifier = { # My house is powerful
			add = -10
			desc = MY_HOUSE_IS_POWERFUL
			house ?= { is_powerful_family = yes }
		}
		modifier = { # My house is dominant
			add = -25
			desc = MY_HOUSE_IS_DOMINANT
			house ?= { is_dominant_family = yes }
		}
		modifier = {
			scope:actor.house = { is_powerful_family = yes }
			add = 10
			desc = YOUR_FAMILY_IS_POWERFUL
		}
		modifier = {
			scope:actor.house = { is_dominant_family = yes }
			add = 25
			desc = YOUR_FAMILY_IS_DOMINANT
		}
		opinion_modifier = {
			opinion_target = scope:actor
			multiplier = 0.5
		}
		modifier = { # I hate my house head
			add = 15
			desc = I_HATE_MY_HOUSE_HEAD
			exists = house.house_head
			is_house_head = no
			opinion = {
				value <= medium_negative_opinion
				target = house.house_head
			}
		}
		modifier = { # I like my house head
			add = -15
			desc = I_LIKE_MY_HOUSE_HEAD
			exists = house.house_head
			is_house_head = no
			opinion = {
				value >= medium_positive_opinion
				target = house.house_head
			}
		}
		modifier = { # You're my friend :)
			add = 10
			desc = youre_my_friend_tt
			has_relation_friend = scope:actor
		}
		modifier = { # You're my guardian
			add = 10
			desc = youre_my_guardian_tt
			has_relation_guardian = scope:actor
		}
		modifier = { # I have no house
			add = 10
			desc = I_WANT_A_HOUSE
			NOT = { exists = house }
		}
		modifier = { # I am a noble!
			add = -15
			desc = i_am_noble_tt
			has_no_particular_noble_roots_trigger = no
		}
		modifier = { # Yo, you're offering me a place in a landed house? Sick.
			add = 10
			desc = ambition_tt
			has_trait = ambitious
			has_no_particular_noble_roots_trigger = yes
		}
		modifier = {
			scope:actor = {
				exists = house
			}
			scope:recipient = {
				exists = house
			}
			exists = scope:actor.house.house_head.top_liege
			house.house_head.top_liege ?= scope:actor.house.house_head.top_liege
			add = {
				value = scope:actor.house.house_power_score
				subtract = scope:recipient.house.house_power_score
			}
			desc = RELATIVE_FAMILY_RATING
		}
		modifier = {
			exists = scope:actor.house
			exists = house
			scope:recipient.dynasty.dynasty_prestige_level != scope:actor.dynasty.dynasty_prestige_level
			add = {
				value = scope:actor.dynasty.dynasty_prestige_level
				subtract = scope:recipient.dynasty.dynasty_prestige_level
				multiply = 10
			}
			desc = RELATIVE_FAMILY_RENOWN
		}
		modifier = {
			exists = house
			house = {
				any_house_member = {
					count < 5
					is_alive = yes
				}
			}
			scope:actor.house ?= {
				any_house_member = {
					count >= 5
					is_alive = yes
				}
			}
			add = 10
			desc = MY_HOUSE_IS_SMALL
		}
		modifier = {
			faith = {
				faith_hostility_level = {
					target = scope:actor.faith
					value >= faith_astray_level
				}
			}
			add = {
				value = "faith.faith_hostility_level(scope:actor.faith)"
				multiply = -10
			}
			desc = FAITH_HOSTILITY_LEVEL
		}
		modifier = {
			exists = scope:actor.top_liege.primary_title.state_faith
			faith = {
				faith_hostility_level = {
					target = scope:actor.top_liege.primary_title.state_faith
					value >= faith_astray_level
				}
			}
			add = {
				value = "faith.faith_hostility_level(scope:actor.top_liege.primary_title.state_faith)"
				multiply = -5
			}
			desc = FAITH_HOSTILITY_LEVEL_STATE_FAITH
		}
		modifier = {
			culture != scope:actor.culture
			"scope:recipient.culture.cultural_acceptance(scope:actor.culture)" < 50
			add = {
				value = 50
				subtract = "scope:recipient.culture.cultural_acceptance(scope:actor.culture)"
				multiply = -0.25
				round = yes
			}
			desc = CULTURAL_ACCEPTANCE
		}
		modifier = {
			culture != scope:actor.culture
			"scope:recipient.culture.cultural_acceptance(scope:actor.culture)" >= 50
			add = {
				value = "scope:recipient.culture.cultural_acceptance(scope:actor.culture)"
				subtract = 50
				multiply = 0.25
				round = yes
			}
			desc = CULTURAL_ACCEPTANCE
		}
		modifier = {
			NOT = {
				culture  = { has_cultural_parameter = allows_noble_family_adoption }
			}
			add = -10
			desc = NOBLE_FAMILY_ADOPTION_NOT_CULTURAL
		}
		modifier = {
			exists = house
			age >= 31
			add = {
				value = age
				subtract = 30
				multiply = -1
			}
			desc = THEIR_AGE_REASON
		}
	}

	ai_frequency = 120

	ai_will_do = {
		base = 50
		modifier = { # My house needs more members
			add = 100
			scope:actor.house = {
				any_house_member = {
					count < 3
					save_temporary_scope_as = house_member_temp
					NOT = {
						scope:actor.top_liege.faith = { has_dominant_ruling_gender = scope:house_member_temp }
					}
				}
			}
		}
		opinion_modifier = { # Opinion
			opinion_target = scope:recipient
			multiplier = 0.5
		}
		modifier = { # My rival
			add = -25
			scope:actor = { has_relation_rival = scope:recipient }
		}
		modifier = { # My friend
			add = 25
			scope:actor = { has_relation_friend = scope:recipient }
		}
		modifier = { # My ward
			add = 25
			scope:actor = { has_relation_guardian = scope:recipient }
		}
		modifier = { # I care about bloodlines and dynasties and whatnot
			add = -25
			scope:actor = {
				OR = {
					has_trait = arrogant
					has_trait = callous
				}
			}
		}
		modifier = { # I will not adopt filthy filthy heretics
			factor = 0
			ai_zeal >= medium_positive_ai_value
			faith = {
				faith_hostility_level = {
					target = scope:recipient.faith
					value >= faith_astray_level
				}
			}
		}
	}
}

# Request title troops from an allied fellow vassal
#
# Referenced in code
request_ally_title_troops_interaction = {
	category = interaction_category_admin
	desc = request_ally_title_troops_interaction_desc
	hidden = yes

	ai_maybe = yes
	ai_min_reply_days = 1
	ai_max_reply_days = 3
	popup_on_receive = yes

	greeting = positive
	notification_text = REQUEST_TITLE_TROOPS_PROPOSAL

	pre_answer_yes_key = ACCEPT
	pre_answer_no_key = DECLINE

	ai_targets = { ai_recipients = peer_vassals }
	ai_target_quick_trigger = { adult = yes }
	ai_frequency = 36

	cooldown_against_recipient = { years = 1 }

	target_type = title
	target_filter = recipient_domain_titles

	redirect = {
	}

	cost = {
		influence = {
			value = 0
			if = {
				limit = { exists = scope:target }
				add = scope:target.admin_title_troop_command_cost_value
			}
		}
	}

	is_shown = {
		scope:actor = {
			has_government = administrative_government
			is_independent_ruler = no
			is_governor = yes
		}
		scope:recipient = {
			has_government = administrative_government
			NOT = {
				this = scope:actor
				this = scope:actor.top_liege
			}
			top_liege = scope:actor.top_liege
		}
	}

	is_valid_showing_failures_only = {
		custom_tooltip = {
			text = admin_troops_have_no_troops_desc
			scope:recipient = {
				any_maa_regiment = {
					is_title_maa_regiment = yes
					regiment_owning_title = { holder = scope:recipient }
				}
			}
		}
		custom_tooltip = {
			text = admin_troops_can_request_from_governor_desc
			scope:actor = {
				OR = {
					is_allied_to = scope:recipient
					has_hook = scope:recipient
					is_liege_or_above_of = scope:recipient
					AND = {
						culture ?= { has_cultural_parameter = frontier_themes_borrow_neighbor_troops }
						vassal_contract_has_flag = admin_theme_frontier
						any_character_to_title_neighboring_duchy = {
							holder ?= {
								this = scope:recipient
								NOT = { vassal_contract_has_flag = admin_theme_frontier }
							}
						}
					}
					AND = {
						has_perk = friendly_counsel_perk
						has_relation_friend = scope:recipient
					}
					AND = {
						has_perk = mortal_adoration_perk
						has_relation_lover = scope:recipient
					}
				}
			}
		}

		scope:actor = {
			NOT = { is_at_war_with = scope:recipient }
		}
	}

	has_valid_target_showing_failures_only = {
		scope:target = {
			tier >= tier_duchy
			
		}
	}

	can_send = {
		custom_tooltip = {
			text = admin_troops_target_title_has_maa_desc
			scope:target = {
				any_owned_title_maa_regiment = { exists = this }
			}
		}
		trigger_if = {
			limit = {
				scope:target = {
					any_owned_title_maa_regiment = { exists = this }
				}
			}
			custom_tooltip = {
				text = admin_troops_target_title_controls_maa_desc #admin_troops_target_title_has_maa_desc
				scope:target = {
					any_owned_title_maa_regiment = { regiment_controlling_title = scope:target }
				}
			}
		}
	}

	on_send = {
	}

	on_accept = {
		scope:recipient = {
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = request_governorship_interaction_toast_liege
				left_icon = scope:actor
				right_icon = scope:target
				scope:target = {
					transfer_owned_maa_control = scope:actor.primary_title

					# Set up a timer to allow the owner to take back the troops when duration runs out
					set_variable = {
						name = title_troops_lent_out
						years = admin_troops_reclaim_cost_cooldown_value
					}
				}
			}
		}
		scope:actor = {
			hidden_effect = {
				send_interface_message = {
					type = msg_admin_provincial_army_request_accepted
					title = msg_admin_provincial_army_request_accepted.title
					left_icon = scope:recipient
					right_icon = scope:target
					show_as_tooltip = {
						scope:target = {
							transfer_owned_maa_control = scope:actor.primary_title
						}
					}
				}
			}
		}
	}

	on_decline = {
		scope:actor = {
			if = {
				limit = { is_ai = yes }
				add_opinion = {
					target = scope:recipient
					modifier = disappointed_opinion
					opinion = -15
				}
			}
			hidden_effect = {
				send_interface_message = {
					type = msg_admin_provincial_army_request_denied
					title = msg_admin_provincial_army_request_denied.title
					desc = msg_admin_provincial_army_request_denied.desc
					left_icon = scope:recipient
					right_icon = scope:target
				}
			}
		}
	}

	ai_potential = {
		is_governor = yes
	}

	ai_will_do = {
		base = 0 # AI uses this interaction from code
	}

	ai_accept = {
		base = 100

		opinion_modifier = {
			who = scope:recipient
			opinion_target = scope:actor
			desc = AI_SIMPLE_OPINION_REASON
		}
		modifier = { # Target is less likely to accept if at war
			scope:recipient = {
				is_at_war = yes
			}
			scope:target = {
				holder = scope:recipient
			}
			add = -200
			desc = TARGET_IS_AT_WAR_REASON
		}
	}
}

request_emperor_title_troops_interaction = {
	category = interaction_category_admin
	interface_priority = 60
	common_interaction = yes
	desc = request_emperor_title_troops_interaction_desc
	hidden = yes

	ai_maybe = yes
	ai_min_reply_days = 4
	ai_max_reply_days = 9
	popup_on_receive = yes

	greeting = positive
	notification_text = REQUEST_TITLE_TROOPS_PROPOSAL

	pre_answer_yes_key = ACCEPT
	pre_answer_no_key = DECLINE

	ai_targets = { ai_recipients = liege }
	ai_target_quick_trigger = { adult = yes }
	ai_frequency = 24

	cooldown_against_recipient = { years = 1 }

	target_type = title
	target_filter = recipient_de_jure_titles

	redirect = {
		scope:actor.top_liege = { save_scope_as = recipient }
	}

	cost = {
		influence = {
			value = 0
			if = {
				limit = { exists = scope:target }
				add = scope:target.admin_title_troop_command_cost_value
			}
		}
	}

	is_shown = {
		scope:actor = {
			has_government = administrative_government
			is_independent_ruler = no
			is_governor = yes
		}
		scope:recipient = {
			has_government = administrative_government
			this = scope:actor.liege
		}
	}

	is_valid_showing_failures_only = {
		custom_tooltip = {
			text = admin_troops_not_available_desc
			scope:recipient = {
				OR = {
					any_vassal = {
						any_maa_regiment = {
							is_title_maa_regiment = yes
						}
						any_held_title = {
							any_owned_title_maa_regiment = { regiment_owning_title = prev }
						}
					}
					any_maa_regiment = {
						is_title_maa_regiment = yes
						regiment_owning_title = { holder = scope:recipient }
					}
				}
			}
		}

		scope:actor = {
			is_at_war_with_liege = no
		}

		trigger_if = {
			limit = {
				scope:actor = { is_ai = yes }
			}
			NOT = {
				scope:recipient = { has_variable = admin_request_troop_cooldown }
			}
		}
	}

	has_valid_target_showing_failures_only = {
		scope:target = {
			tier >= tier_duchy
			
			exists = holder
			holder.top_liege = scope:recipient
			NOT = { holder = scope:actor }
			any_title_maa_regiment = {
				exists = this
			}
		}
		scope:recipient = {
			primary_title ?= {
				NOT = { this = scope:target }
			}
		}
	}

	can_send = {
		custom_tooltip = {
			text = admin_troops_target_title_controls_maa_desc
			scope:target = {
				any_owned_title_maa_regiment = { regiment_controlling_title = scope:target }
			}
		}
	}

	on_send = {
	}

	# Hook
	send_option = {
		is_valid = {
			scope:actor = { has_usable_hook = scope:recipient }
			NOT = {
				scope:recipient = { has_hook = scope:actor }
			}
		}
		flag = hook
		localization = GENERIC_SPEND_A_HOOK
	}
	# Dominant Family
	send_option = {
		is_shown = {
			scope:actor = {
				house ?= { is_dominant_family = yes }
			}
		}
		flag = dominant_family
		localization = OPTION_DOMINANT_FAMILY
	}
	should_use_extra_icon = {
		scope:actor = { has_usable_hook = scope:recipient }
	}
	send_options_exclusive = no

	on_accept = {
		if = {
			limit = {
				scope:hook = yes
				scope:actor = { has_usable_hook = scope:recipient }
			}
			scope:actor = {
				use_hook = scope:recipient
			}
		}
		if = {
			limit = { scope:dominant_family = yes }
			scope:actor = {
				change_influence = medium_influence_loss
			}
		}
		scope:actor = {
			if = {
				limit = {
					is_ai = yes
				}
				add_opinion = {
					target = scope:recipient
					modifier = grateful_opinion
					opinion = 10
				}
			}
			hidden_effect = {
				send_interface_message = {
					type = msg_admin_provincial_army_request_accepted
					title = msg_admin_provincial_army_request_accepted.title
					left_icon = scope:recipient
					right_icon = scope:target
					show_as_tooltip = {
						scope:target = {
							transfer_owned_maa_control = scope:actor.primary_title
						}
					}
				}
			}
		}
		scope:recipient = {
			if = {
				limit = {
					is_ai = yes
				}
				custom_tooltip = request_emperor_title_troops_approve_desc
			}

			# Set up AI cooldown to prevent spam
			if = {
				limit = {
					NOT = { has_variable = admin_request_troop_cooldown }
				}
				set_variable = {
					name = admin_request_troop_cooldown
					years = 2
				}
			}
		}
		scope:target = {
			transfer_owned_maa_control = scope:actor.primary_title

			# Set up a timer to allow the owner to take back the troops when duration runs out
			set_variable = {
				name = title_troops_lent_out
				years = admin_troops_reclaim_cost_cooldown_value
			}
		}
	}

	on_decline = {
		scope:actor = {
			if = {
				limit = { is_ai = yes }
				add_opinion = {
					target = scope:recipient
					modifier = disappointed_opinion
					opinion = -20
				}
			}
			hidden_effect = {
				send_interface_message = {
					type = msg_admin_provincial_army_request_denied
					title = msg_admin_provincial_army_request_denied.title
					desc = msg_admin_provincial_army_request_denied.desc
					left_icon = scope:recipient
					right_icon = scope:target
				}
			}
		}
		scope:recipient = {
			if = {
				limit = {
					is_ai = yes
				}
				custom_tooltip = request_emperor_title_troops_deny_desc
			}
			if = {
				limit = { scope:dominant_family = yes }
				change_influence = medium_influence_loss
			}

			# Set up AI cooldown to prevent spam
			if = {
				limit = {
					NOT = { has_variable = admin_request_troop_cooldown }
				}
				set_variable = { # If declined, we make the cooldown a bit longer to prevent the AI from asking again too soon
					name = admin_request_troop_cooldown
					years = 5
				}
			}
			else = { # Just in case - If we have a cooldown already, refresh it
				remove_variable = admin_request_troop_cooldown
				set_variable = {
					name = admin_request_troop_cooldown
					years = 5
				}
			}
		}
	}

	ai_potential = {
		is_governor = yes # Only governors may ask for troops
		NOT = { # Don't ask for more troops if you have borrowed some already
			any_maa_regiment = {
				is_title_maa_regiment = yes
				regiment_owning_title = { holder = root }
			}
		}
	}

	ai_will_do = {
		base = 0

		# Some governors are more likely to ask than others
		modifier = {
			add = 50
			scope:actor = {
				vassal_contract_has_flag = admin_theme_frontier
			}
		}
		modifier = {
			add = 25
			scope:actor = {
				vassal_contract_has_flag = admin_theme_naval
			}
		}
		ai_value_modifier = {
			who = scope:actor
			ai_greed = 0.25
			ai_boldness = 0.5
		}
		modifier = {
			add = 20
			is_at_war = yes
		}

		# Don't ask for the liege's troops if you can help it
		modifier = {
			add = -10
			scope:target ?= {
				holder = scope:recipient
			}
		}
		modifier = {
			add = -30
			scope:recipient = { primary_title = scope:target }
		}

		# Don't bother the liege if they are at war
		modifier = {
			add = -100
			scope:recipient = { is_at_war = yes }
		}

		# Consider which title we would like to request troops from
		modifier = { # Don't ask for troops owned by your own house if we can help it
			add = -20
			scope:target = { holder.house ?= root.house }
		}
		modifier = { # Larger armies are more enticing, so ask for troops from a military theme
			add = 10
			scope:target.holder = { vassal_contract_has_flag = admin_theme_military }
		}
		modifier = { # Smaller armies are not as exciting, so don't ask for troops from a civilian theme
			add = -5
			scope:target.holder = { vassal_contract_has_flag = admin_theme_civilian }
		}
		modifier = { # Don't request troops that may join your wars
			add = 10
			scope:target.holder = {
				NOT = { is_allied_to = root }
			}
		}

		# Some governors never asks for troops
		modifier = {
			factor = 0
			scope:actor = {
				OR = {
					vassal_contract_has_flag = admin_theme_balanced
					vassal_contract_has_flag = admin_theme_civilian
				}
			}
		}
	}

	ai_accept = {
		base = -20

		opinion_modifier = {
			who = scope:recipient
			opinion_target = scope:actor
			desc = AI_SIMPLE_OPINION_REASON
		}
		modifier = {
			add = -20
			scope:recipient = {
				has_trait = paranoid
			}
			desc = INTERACTION_PARANOID
		}
		modifier = {
			add = 10
			scope:recipient = {
				has_trait = trusting
			}
			desc = INTERACTION_TRUSTING
		}
		modifier = {
			scope:hook = yes
			add = 50
			desc = SCHEME_WEAK_HOOK_USED
		}
		modifier = {
			scope:dominant_family = yes
			add = 100
			desc = your_house_is_dominant_reason
		}
		modifier = {
			scope:actor = {
				is_at_war = no
			}
			add = -20
			desc = IS_NOT_AT_WAR_REASON
		}
		modifier = {
			scope:actor = {
				vassal_contract_has_flag = admin_theme_military
			}
			add = 20
			desc = IS_A_MILITARY_THEME
		}
		modifier = {
			scope:actor = {
				vassal_contract_has_flag = admin_theme_frontier
			}
			add = 30
			desc = IS_A_FRONTIER_THEME
		}
		modifier = {
			scope:actor = {
				vassal_contract_has_flag = admin_theme_naval
			}
			add = 25
			desc = IS_A_NAVAL_THEME
		}
		modifier = {
			scope:recipient = {
				is_at_war = no
			}
			scope:target = {
				holder = scope:recipient
			}
			add = -50
			desc = TARGETS_OWN_TROOPS_REASON
		}
		modifier = { # Asking for the liege's troops when he is at war
			scope:recipient = {
				is_at_war = yes
			}
			scope:target = {
				holder = scope:recipient
			}
			add = -200
			desc = TARGET_IS_AT_WAR_REASON
		}
		modifier = { # Asking for a governor's troops when they are at war
			scope:target = {
				holder = { is_at_war = yes }
				NOT = { holder = scope:recipient }
			}
			add = -50
			desc = TARGET_IS_AT_WAR_REASON
		}
		modifier = {
			scope:actor = {
				any_held_title = {
					any_controlled_title_maa_regiment = {
						regiment_owning_title = {
							NOT = { holder = scope:actor }
						}
					}
				}
			}
			add = {
				value = 0
				scope:actor = {
					every_held_title = {
						every_controlled_title_maa_regiment = {
							limit = {
								regiment_owning_title = {
									NOT = { holder = scope:actor }
								}
							}
							add = {
								value = maa_size
								multiply = -10
							}
						}
					}
				}
			}
			desc = CONTROLS_EXTRA_TROOPS_REASON
		}
	}
}

request_title_troops_back_interaction = {
	category = interaction_category_admin
	desc = request_title_troops_back_interaction_desc

	hidden = yes
	popup_on_receive = yes

	greeting = positive
	notification_text = REQUEST_TITLE_TROOPS_PROPOSAL

	pre_answer_yes_key = ACCEPT
	pre_answer_no_key = DECLINE

	ai_targets = { ai_recipients = liege }
	ai_target_quick_trigger = { adult = yes }
	ai_frequency = 24

	cooldown_against_recipient = { years = 1 }

	target_type = title
	target_filter = actor_de_jure_titles

	redirect = {
	}

	cost = {
		influence = {
			value = {
				add = {
					value = define:NAdministrative|BASE_REASSIGN_COST
				}
				desc = BASE
			}
			if = {
				limit = {
					exists = scope:target
					scope:target = {
						NOT = { has_variable = title_troops_lent_out }
						any_owned_title_maa_regiment = {
							regiment_controlling_title = {
								NOT  = { holder = scope:actor.top_liege }
							}
						}
					}
				}
				subtract = {
					value = {
						value = define:NAdministrative|BASE_REASSIGN_COST
						multiply = 0.8
					}
					desc = admin_troops_borrowed_years_desc
				}
			}
		}
	}

	is_shown = {
		scope:actor = {
			has_government = administrative_government
			is_independent_ruler = no
			is_ai = no # The AI should not request their troops back ahead of time
		}
		scope:recipient = {
			has_government = administrative_government
			this = scope:actor
		}
	}

	is_valid_showing_failures_only = {
		scope:recipient = {
			custom_tooltip = {
				text = admin_troops_already_at_home_desc
				any_held_title = {
					any_owned_title_maa_regiment = {
						regiment_controlling_title = {
							NOT = { holder = scope:actor }
						}
					}
				}
			}
		}
	}

	has_valid_target_showing_failures_only = {
		scope:target = {
			any_owned_title_maa_regiment = {
				regiment_controlling_title = {
					NOT = { this = scope:target }
				}
			}
		}
	}

	can_send = {
		custom_tooltip = {
			text = admin_troops_controlled_by_liege_desc
			scope:target = {
				any_owned_title_maa_regiment = {
					regiment_controlling_title = {
						NOT = { holder = scope:actor.top_liege }
					}
				}
			}
		}
	}

	on_send = {
	}

	auto_accept = yes

	on_accept = {
		scope:target = {
			custom_tooltip = {
				text = admin_troops_transfer_troops_back_desc
				every_owned_title_maa_regiment = {
					limit = {
						regiment_controlling_title = {
							NOT = { this = scope:target }
						}
					}
					transfer_title_maa = regiment_owning_title
				}
			}

			# Clear cost timer if present
			if = {
				limit = {
					has_variable = title_troops_lent_out
				}
				remove_variable = title_troops_lent_out
			}
		}
	}

	on_decline = {
	}

	ai_potential = {
		always = no
	}

	ai_will_do = {
		base = 0
	}

	ai_accept = {
		base = 100
	}
}

# Request Raid Estate Remit
request_raid_remit_interaction = {
	icon = icon_request_raid_remit
	category = interaction_category_admin
	interface_priority = 90

	desc = request_raid_remit_interaction_desc
	use_diplomatic_range = yes

	ai_min_reply_days = 4
	ai_max_reply_days = 9

	cooldown_against_recipient = { years = 5 }

	is_shown = {
		scope:actor = {
			is_independent_ruler = no
			has_government = administrative_government
		}
		scope:secondary_recipient ?= {
			NOT = { house = scope:recipient.house }
			top_liege = scope:actor.top_liege
			NOT = { house = scope:actor.house }
			has_government = administrative_government
			any_held_title = { is_noble_family_title = yes }
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			is_adult = yes
			custom_tooltip = {
				text = raid_estate_noble_family_tt
				any_held_title = { is_noble_family_title = yes }
				house.house_head ?= this
			}
			custom_tooltip = {
				text = raid_estate_already_remit_tt
				NOT = { exists = var:raid_estate_permission }
			}
		}
		scope:recipient.house.house_head ?= {
			custom_tooltip = {
				text = raid_estate_noble_family_target_tt
				any_held_title = { is_noble_family_title = yes }
			}
			custom_tooltip = {
				text = raid_estate_estate_tt
				domicile ?= { is_domicile_type = estate }
			}
		}
		scope:actor = {
			NOT = { is_at_war_with = scope:recipient }
		}
	}

	populate_recipient_list = {
		scope:actor.top_liege = {
			every_noble_family = {
				limit = {
					NOR = {
						holder = scope:actor
						holder = scope:actor.top_liege
					}
				}
				holder = { add_to_list = characters }
			}
		}
	}

	redirect = {
		scope:recipient.house.house_head ?= { save_scope_as = secondary_recipient }
		scope:actor.top_liege = { save_scope_as = recipient }
	}

	send_option = {
		is_valid = { scope:actor.gold >= scope:actor.minor_gold_value }
		flag = gold
		localization = GENERIC_SPEND_GOLD
	}
	send_option = {
		is_valid = {
			scope:actor = { has_usable_hook = scope:recipient }
			NOT = {
				scope:recipient = { has_hook = scope:actor }
			}
		}
		flag = hook
		localization = GENERIC_SPEND_A_HOOK
	}
	should_use_extra_icon = {
		scope:actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	send_options_exclusive = no

	on_accept = {
		if = {
			limit = { scope:gold = yes }
			scope:actor = {
				pay_short_term_gold = {
					target = scope:recipient
					gold = scope:actor.minor_gold_value
				}
			}
		}
		scope:recipient = { custom_tooltip = request_raid_remit_interaction_effect_tt }
		custom_tooltip = request_raid_remit_interaction_duration_tt
		hidden_effect = {
			scope:actor = { trigger_event = ep3_interactions_events.0421 }
		}
	}

	on_decline = {
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_bad
				title = request_raid_remit_effect_toast
				left_icon = scope:recipient
				right_icon = scope:actor
				scope:recipient = {
					send_interface_toast = {
						type = event_toast_effect_bad
						title = request_raid_remit_effect_toast
						left_icon = scope:recipient
						right_icon = scope:actor
						if = {
							limit = { scope:actor = { is_ai = yes } }
							reverse_add_opinion = {
								modifier = angry_opinion
								opinion = -20
								target = scope:actor
							}
						}
						if = {
							limit = { is_ai = yes }
							add_opinion = {
								modifier = respect_opinion
								opinion = -10
								target = scope:actor
							}
						}
					}
				}
			}
		}
	}

	cost = {
		influence = {
			add = scope:actor.massive_influence_value
			# Being a Powerful or Dominant Family reduces the cost significantly
			scope:actor.house = {
				if = {
					limit = { is_dominant_family = yes }
					add = {
						value = massive_influence_value
						multiply = -0.75
						desc = is_dominant_family_desc
					}
				}
				else_if = {
					limit = { is_powerful_family = yes }
					add = {
						value = massive_influence_value
						multiply = -0.5
						desc = is_powerful_family_desc
					}
				}
			}
		}
	}

	ai_potential = {
		is_house_head = yes
		house ?= {
			any_house_member = {
				count <= 5
				is_alive = yes
			}
		}
	}

	ai_targets = {
		ai_recipients = peer_vassals
		ai_recipients = scripted_relations
		max = 10
	}

	ai_accept = {
		base = -30
		modifier = {
			scope:hook = yes
			add = 40
			desc = SCHEME_WEAK_HOOK_USED
		}
		modifier = {
			scope:gold = yes
			add = 25
			desc = SCHEME_WITH_GIFT_SIGNIFICANT
		}
		modifier = { # Target house is powerful
			add = -10
			desc = MY_HOUSE_IS_POWERFUL
			scope:secondary_recipient.house ?= { is_powerful_family = yes }
		}
		modifier = { # Target house is dominant
			add = -25
			desc = MY_HOUSE_IS_DOMINANT
			scope:secondary_recipient.house ?= { is_dominant_family = yes }
		}
		modifier = {
			scope:actor.house = { is_powerful_family = yes }
			add = 10
			desc = YOUR_FAMILY_IS_POWERFUL
		}
		modifier = {
			scope:actor.house = { is_dominant_family = yes }
			add = 25
			desc = YOUR_FAMILY_IS_DOMINANT
		}
		modifier = {
			scope:recipient.primary_spouse ?= { house ?= scope:secondary_recipient.house }
			add = -10
			desc = MY_SPOUSES_HOUSE
		}
		modifier = {
			any_child = { house = scope:secondary_recipient.house }
			add = -10
			desc = MY_CHILDS_HOUSE
		}
		modifier = {
			is_close_family_of = scope:secondary_recipient
			add = -10
			desc = TARGET_IS_MY_CLOSE_FAMILY
		}
		opinion_modifier = {
			opinion_target = scope:actor
			multiplier = 0.5
		}
		opinion_modifier = {
			opinion_target = scope:secondary_recipient
			multiplier = -0.5
		}
		modifier = {
			has_relation_rival = scope:secondary_recipient
			add = 10
			desc = THEY_ARE_MY_RIVAL
		}
		modifier = {
			add = -10
			desc = THEY_ARE_MY_FRIEND
			scope:secondary_recipient = { has_relation_friend = scope:recipient }
		}
		modifier = { # You're my friend :)
			add = 10
			desc = youre_my_friend_tt
			has_relation_friend = scope:actor
		}
		modifier = { # You're my rival >:(
			add = -10
			desc = ai_opinion.reason.relation.rival
			has_relation_rival = scope:actor
		}
		modifier = { # You're my guardian
			add = 10
			desc = youre_my_guardian_tt
			has_relation_guardian = scope:actor
		}
		ai_value_modifier = {
			ai_boldness = -0.2
			ai_honor = -0.2
		}
	}

	ai_frequency = 120

	ai_will_do = {
		base = -25
		opinion_modifier = { # Opinion
			opinion_target = scope:recipient
			multiplier = -0.5
		}
		modifier = { # My rival
			add = 25
			scope:actor = { has_relation_rival = scope:recipient }
		}
		modifier = { # My friend
			add = -25
			scope:actor = { has_relation_friend = scope:recipient }
		}
		modifier = {
			existing_feud_against_target_trigger = { TARGET = scope:recipient }
			add = 15
		}
	}
}

# Request to become co-emperor
request_co_emperor_interaction = {
	category = interaction_category_diarch
	icon = icon_declare_me_co_emperor

	desc = request_co_emperor_interaction_desc
	notification_text = DECLARE_ME_CO_EMPEROR_PROPOSAL

	interface_priority = 20
	ai_min_reply_days = 4
	ai_max_reply_days = 9

	pre_answer_yes_key = ACCEPT
	pre_answer_no_key = DECLINE

	# AI
	ai_targets = { ai_recipients = liege }
	ai_frequency = 60
	ai_target_quick_trigger = { adult = yes }

	cooldown_against_recipient = { years = 10 }

	redirect = {
		scope:recipient = { save_scope_as = secondary_recipient }
	}

	cost = {
		influence = {
			add = {
				add = {
					value = scope:actor.monumental_influence_value
					multiply = 2
				}
				desc = BASE
			}
			# Being a Powerful or Dominant Family reduces the cost significantly
			scope:actor.house = {
				if = {
					limit = { is_dominant_family = yes }
					multiply = {
						value = 0.25
						desc = is_dominant_family_desc
					}
				}
				else_if = {
					limit = { is_powerful_family = yes }
					multiply = {
						value = 0.5
						desc = is_powerful_family_desc
					}
				}
			}
			if = {
				limit = { scope:influence = yes }
				add = {
					add = scope:actor.request_co_emperor_interaction_influence_cost_value
					desc = SPEND_INFLUENCE
				}
			}
		}

		gold = {
			if = {
				limit = { scope:gold = yes }
				add = {
					add = scope:recipient.request_co_emperor_interaction_gold_cost_value
					desc = SCHEME_AGENT_GOLD
				}
			}
		}
	}

	is_shown = {
		scope:actor = {
			has_government = administrative_government
			is_independent_ruler = no
		}
		scope:recipient = {
			this = scope:actor.top_liege
			may_appoint_co_emperors_trigger = yes
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			valid_co_emperor_candidate_trigger = { LIEGE = scope:recipient }
			NOT = { is_at_war_with = scope:recipient }
		}
		scope:recipient = {
			is_at_war = no
			has_active_diarchy = no
			trigger_if = {
				limit = { exists = designated_diarch }
				time_after_diarch_designated = { years >= 10 }
			}
		}
	}

	send_options_exclusive = no
	#Spend influence
	send_option = {
		flag = influence
		is_valid = { scope:actor.influence >= request_co_emperor_interaction_influence_cost_value }
		localization = SPEND_INFLUENCE
	}
	#Promise gold.
	send_option = {
		flag = gold
		is_valid = { scope:actor.gold >= scope:recipient.request_co_emperor_interaction_gold_cost_value }
		localization = SCHEME_AGENT_GOLD
	}
	#Use hook
	send_option = {
		is_valid = {
			scope:actor = { has_usable_hook = scope:recipient }
		}
		flag = hook
		localization = GENERIC_SPEND_A_HOOK
	}
	should_use_extra_icon = {
		scope:actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	on_accept = {
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_good
				title = declare_me_co_emperor_interaction.tt.success
				left_icon = scope:recipient
				scope:recipient = {
					custom_tooltip = {
						text = declare_me_co_emperor_interaction.tt.effect
						start_diarchy = co_emperorship
						set_diarch = scope:actor
					}
					if = {
						limit = {
							scope:actor = {
								is_child_of = scope:recipient
							}
						}

						designated_heir ?= {
							if = {
								limit = { this != scope:actor }
								custom_tooltip = appoint_co_emperor_interaction.tt.overwrite_designated_heir
								# Nab them for use further on.
								save_scope_as = old_heir
							}
						}
						hidden_effect = { set_designated_heir = scope:actor }
					}
				}
			}
			if = {
				limit = {
					scope:hook = yes
					has_usable_hook = scope:recipient
				}
				# Use the hook up.
				use_hook = scope:recipient
				reverse_add_opinion = {
					target = scope:recipient
					modifier = suspicion_opinion
					opinion = -20
				}
			}
			if = {
				limit = { scope:gold = yes }
				show_as_tooltip = {
					pay_short_term_gold = {
						target = scope:recipient
						gold = scope:recipient.request_co_emperor_interaction_gold_cost_value
					}
				}
				hidden_effect = {
					scope:recipient = { add_gold = request_co_emperor_interaction_gold_cost_value }
				}
			}
		}
		if = {
			limit = { scope:influence = yes }
			scope:recipient = { change_influence = scope:actor.request_co_emperor_interaction_influence_cost_value }
		}
		# And remember who appointed them on scope:recipient.
		scope:actor = {
			set_variable = {
				name = co_emp_appointer
				value = scope:recipient
			}
		}

		# Your designated heir is _very_ pissed.
		if = {
			limit = {
				exists = scope:old_heir
			}
			diarch_overwrites_old_designated_heir_apply_opinions_effect = {
				LIEGE = scope:recipient
				CO_RULER = scope:actor
			}
		}
	}

	on_decline = {
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_bad
				title = declare_me_co_emperor_interaction.tt.failure
				left_icon = scope:recipient
				if = {
					limit = { is_ai = yes }
					add_opinion = {
						target = scope:recipient
						modifier = insult_opinion
						opinion = -40
					}
				}
				change_strife_opinion = medium_strife_gain
			}
		}
	}

	ai_potential = {
		NOR = {
			has_trait = humble
			has_trait = content
		}
	}

	ai_will_do = {
		# Most AI think this is audacious.
		base = 0

		# Weight for personality.
		## Both modifier.
		ai_value_modifier = {
			# Bold, energetic characters fancy the gig.
			ai_boldness = 0.5
			ai_energy = 0.5
		}
		## And traits!
		### These are balanced differently to the other interactions, so it's deliberate that they're not using the @values here.
		### +++ Ambitious.
		modifier = {
			add = 15
			has_trait = ambitious
		}
		### ++ Arrogant.
		modifier = {
			add = 10
			has_trait = arrogant
		}
		### + Diligent.
		modifier = {
			add = 5
			has_trait = diligent
		}
		### + Loyal.
		modifier = {
			add = 5
			has_trait = loyal
		}
		### - Humble.
		modifier = {
			add = -5
			has_trait = humble
		}
		### --- Content.
		modifier = {
			add = -15
			has_trait = content
		}
		### --- Lazy.
		modifier = {
			add = -15
			has_trait = lazy
		}
		# Weight by proximity to the ruler: close family, spouses, etc.
		modifier = {
			add = 25
			OR = {
				any_close_or_extended_family_member = { this = scope:recipient }
				any_spouse = { this = scope:recipient }
			}
		}
		# Councillors have ambitions.
		modifier = {
			add = 25
			is_councillor = yes
		}
		# Weight for opinion of current regent.
		modifier = {
			add = {
				scope:recipient = {
					# Designated diarchs.
					if = {
						limit = {
							designated_diarch ?= {
								save_temporary_scope_as = diarch_successor_temp
								scope:actor = {
									save_temporary_opinion_value_as = {
										name = actor_opinion_temp
										target = scope:diarch_successor_temp
									}
								}
							}
						}
						add = scope:actor_opinion_temp
						# Invert to get the true total.
						multiply = -1
					}
					# Expected diarchs.
					else_if = {
						limit = {
							diarchy_successor ?= {
								save_temporary_scope_as = diarch_successor_temp
								scope:actor = {
									save_temporary_opinion_value_as = {
										name = actor_opinion_temp
										target = scope:diarch_successor_temp
									}
								}
							}
						}
						add = scope:actor_opinion_temp
						# Invert to get the true total.
						multiply = -1
					}
				}
			}
			always = yes
		}
		# The AI will only use a Hook if they couldn't otherwise do this
		modifier = {
			scope:hook = yes
			add = -1
		}
		# Dominant family have ambitions.
		modifier = {
			add = 25
			is_house_head = yes
			house ?= { is_dominant_family = yes }
		}
		# Pretenders.
		modifier = {
			add = 25
			NOT = { is_close_family_of = scope:recipient }
			has_claim_on = scope:recipient.primary_title
		}
		# Designated Heir
		modifier = {
			add = 25
			scope:recipient.designated_heir ?= this
		}
		# Flag management.
		## Hook used
		modifier = {
			add = 1
			scope:hook = yes
		}
		## Influence traded.
		modifier = {
			add = 3
			scope:influence = yes
		}
		## Gold traded.
		modifier = {
			add = 2
			scope:gold = yes
		}
	}

	auto_accept = {
		custom_description = {
			text = "spending_hook"
			subject = scope:actor
			object = scope:recipient
			scope:hook = yes
			scope:actor = { has_strong_hook = scope:recipient }
			scope:recipient = { is_ai = yes }
		}
	}

	ai_accept = {
		# Try to make it 0 for most interactions
		base = -150
		# Opinion of scope:actor.
		opinion_modifier = {
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 0.5
		}
		# Personality.
		ai_value_modifier = {
			# Meek characters are more likely to accept this.
			ai_boldness = -0.5
			# Characters with low energy just want to avoid all this planning.
			ai_energy = -0.25
		}
		# Familial closeness.
		## Close family get a decent boost.
		modifier = {
			add = 30
			desc = declare_me_regent_interaction.tt.actor_is.close_family
			is_close_family_of = scope:actor
			# Make sure this isn't cancelled out by the incumbent sharing the relation.
			diarchy_successor = {
				NOT = { is_close_family_of = scope:recipient }
			}
		}
		## Extended family get a minor boost.
		modifier = {
			add = 20
			desc = declare_me_regent_interaction.tt.actor_is.extended_family
			is_extended_family_of = scope:actor
			# Make sure this isn't cancelled out by the incumbent sharing the relation.
			diarchy_successor = {
				NOT = { is_extended_family_of = scope:recipient }
			}
		}
		## House members get a slight boost.
		modifier = {
			add = 10
			desc = declare_me_regent_interaction.tt.actor_is.house_member
			house = scope:actor.house
			NOT = { is_close_or_extended_family_of = scope:actor }
			# Make sure this isn't cancelled out by the incumbent sharing the relation.
			diarchy_successor = {
				NOT = {
					house = scope:recipient.house
				}
			}
		}
		## Dominant family
		modifier = {
			scope:actor.house = {
				is_dominant_family = yes
				NOT = { this = scope:recipient.house }
			}
			add = 10
			desc = YOUR_FAMILY_IS_DOMINANT
		}
		## Powerful family
		modifier = {
			scope:actor.house = {
				is_powerful_family = yes
				is_dominant_family = no
				NOT = { this = scope:recipient.house }
			}
			add = 5
			desc = YOUR_FAMILY_IS_POWERFUL
		}
		## Powerful family
		modifier = {
			scope:recipient.designated_heir ?= scope:actor
			add = 25
			desc = YOU_ARE_MY_DESIGNATED_HEIR
		}
		# Relationships.
		## Positive.
		modifier = {
			add = 25
			desc = declare_me_regent_interaction.tt.actor_is.positive_relationship
			has_any_good_relationship_with_character_trigger = { CHARACTER = scope:actor }
			# We don't factor for this in the designated/expected diarch 'cause the matrix of overlap'd be hellish.
		}
		## Negative.
		modifier = {
			add = -25
			desc = declare_me_regent_interaction.tt.actor_is.negative_relationship
			has_any_bad_relationship_with_character_trigger = { CHARACTER = scope:actor }
			# We don't factor for this in the designated/expected diarch 'cause the matrix of overlap'd be hellish.
		}
		# Succession score is a direct factor.
		modifier = {
			add = {
				value = "scope:actor.appointment_candidate_score(scope:recipient.primary_title)"
				divide = 4
				min = 0
				max = 100
			}
			desc = declare_me_regent_interaction.tt.actor_is.succession_score
		}
		# Send options.
		## Hook used
		modifier = {
			add = 50
			desc = SCHEME_WEAK_HOOK_USED
			scope:hook = yes
		}
		## Influence traded.
		modifier = {
			add = 50
			desc = INFLUENCE_REASON
			scope:influence = yes
		}
		## Gold traded.
		modifier = {
			add = 50
			desc = GOLD_REASON
			scope:gold = yes
		}
	}
}

# Request a character to fight a war on your behalf - AKA Summon to War/summon_to_war
frontier_influence_war_interaction = {
	category = interaction_category_admin
	interface_priority = 80
	icon = icon_coax_to_war
	desc = frontier_influence_war_interaction_desc

	is_highlighted = {
		scope:recipient = {
			is_at_war = no
			is_adult = yes
			custom_tooltip = {
				text = admin_theme_type_trigger
				OR = {
					vassal_contract_has_flag = admin_theme_frontier
					vassal_contract_has_flag = admin_theme_naval
				}
			}
		}
	}

	target_type = title
	target_filter = secondary_recipient_de_jure_titles
	can_be_picked_title = {
		scope:target = {
			is_title_created = yes
			tier = tier_duchy
		}
	}

	populate_recipient_list = {
		scope:recipient = {
			if = {
				limit = { vassal_contract_has_flag = admin_theme_frontier }
				every_character_to_title_neighboring_duchy = {
					limit = {
						holder ?= { top_liege != scope:actor.top_liege }
					}
					holder ?= { add_to_list = characters }
				}
			}
			else_if = {
				limit = { vassal_contract_has_flag = admin_theme_naval }
				every_character_to_title_neighboring_and_across_water_duchy = {
					limit = {
						holder ?= { top_liege != scope:actor.top_liege }
					}
					holder ?= { add_to_list = characters }
				}
			}
		}
	}

	redirect = {
		scope:recipient = {
			if = {
				limit = { vassal_contract_has_flag = admin_theme_frontier }
				random_character_to_title_neighboring_duchy = {
					limit = {
						exists = holder
						holder = { top_liege != scope:actor.top_liege }
					}
					holder = { save_scope_as = secondary_recipient }
				}
			}
			else_if = {
				limit = { vassal_contract_has_flag = admin_theme_naval }
				random_character_to_title_neighboring_and_across_water_duchy = {
					limit = {
						exists = holder
						holder = { top_liege != scope:actor.top_liege }
					}
					holder = { save_scope_as = secondary_recipient }
				}
			}
		}
	}

	has_valid_target = {
		scope:target = {
			is_title_created = yes
			tier = tier_duchy
			holder.top_liege != scope:actor
		}
	}

	ai_min_reply_days = 3
	ai_max_reply_days = 9
	popup_on_receive = yes
	ai_maybe = yes
	can_send_despite_rejection = yes

	greeting = positive
	notification_text = REQUEST_DUCHY_INFLUENCE_WAR_PROPOSAL

	pre_answer_yes_key = ACCEPT
	pre_answer_no_key = DECLINE

	cooldown_against_recipient = { years = 10 }

	is_shown = {
		scope:actor = {
			is_independent_ruler = yes
			has_government = administrative_government
			NOT = { government_has_flag = government_is_landless_adventurer }
		}
		scope:recipient = {
			has_government = administrative_government
			NOT = { government_has_flag = government_is_landless_adventurer }
			custom_tooltip = {
				text = admin_theme_type_trigger
				OR = {
					vassal_contract_has_flag = admin_theme_frontier
					vassal_contract_has_flag = admin_theme_naval
				}
			}
			top_liege = scope:actor.top_liege
		}
	}

	is_valid_showing_failures_only = {
		scope:actor != scope:recipient
		scope:recipient = {
			is_at_war = no
			is_adult = yes
			custom_tooltip = {
				text = admin_theme_type_trigger
				OR = {
					vassal_contract_has_flag = admin_theme_frontier
					vassal_contract_has_flag = admin_theme_naval
				}
			}

			custom_tooltip = {
				text = admin_vassal_war_no_target_desc
				trigger_if = {
					limit = { vassal_contract_has_flag = admin_theme_frontier }
					any_character_to_title_neighboring_duchy = {
						exists = holder
						holder = { top_liege != scope:actor.top_liege }
					}
				}
				trigger_if= {
					limit = { vassal_contract_has_flag = admin_theme_naval }
					any_character_to_title_neighboring_and_across_water_duchy = {
						exists = holder
						holder = { top_liege != scope:actor.top_liege }
					}
				}
			}
		}
	}

	send_options_exclusive = no
	send_option = {
		flag = title_maa
		localization = send_option_title_troops
		is_valid = {
			scope:actor = {
				is_at_war = no
				custom_tooltip = {
					text = all_title_maa_must_not_be_raised_tt
					primary_title = {
						NOT = {
							any_controlled_title_maa_regiment = {
								is_raised = yes
							}
						}
					}
				}
			}
		}
	}
	send_option = {
		is_valid = {
			scope:actor = {
				has_usable_hook = scope:recipient
			}
		}
		flag = hook
		localization = GENERIC_SPEND_A_HOOK
	}
	should_use_extra_icon = {
		scope:actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	on_accept = {
		if = {
			limit = { scope:title_maa = yes }
			scope:actor.primary_title = {
				transfer_owned_maa_control = scope:recipient.primary_title
			}
		}
		scope:recipient = {
			start_war = {
				cb = influence_war_cb
				target = scope:secondary_recipient
				claimant = scope:recipient.top_liege
				target_title = scope:target
			}
			custom_tooltip = frontier_influence_war_interaction_target_title_tt
		}
		scope:actor = {
			trigger_event = ep3_interactions_events.0210
		}
	}

	on_decline = {
		scope:recipient = {
			change_influence = major_influence_loss
		}
		scope:actor = {
			if = {
				limit = { is_ai = yes }
				add_opinion = {
					modifier = refused_summons_to_war_opinion
					target = scope:recipient
				}
			}
			trigger_event = ep3_interactions_events.0211
		}
	}

	cost = {
		prestige = {
			# BASE COSTS
			add = {
				value = massive_prestige_value
				desc = BASE
			}
			# DOMINANT FAMILY DISCOUNTS
			if = {
				limit = { scope:actor.house ?= { is_dominant_family = yes } }
				multiply = {
					value = 0.75
					desc = DOMINANT_FAMILY_DISCOUNT
				}
			}
			# DOMICILE BUILDING DISCOUNTS
		}
	}

	ai_potential = {
		has_government = administrative_government
		is_independent_ruler = yes
	}

	ai_targets = {
		ai_recipients = vassals
	}

	auto_accept = {
		custom_description = {
			text = "spending_hook"
			subject = scope:actor
			object = scope:recipient
			scope:hook = yes
		}
	}

	ai_accept = {
		base = 0
		modifier = { # My house is powerful
			add = -10
			desc = MY_HOUSE_IS_POWERFUL
			house ?= { is_powerful_family = yes }
		}
		modifier = { # My house is dominant
			add = -25
			desc = MY_HOUSE_IS_DOMINANT
			house ?= { is_dominant_family = yes }
		}
		modifier = {
			scope:actor.house = { is_powerful_family = yes }
			add = 10
			desc = YOUR_FAMILY_IS_POWERFUL
		}
		modifier = {
			scope:actor.house = { is_dominant_family = yes }
			add = 25
			desc = YOUR_FAMILY_IS_DOMINANT
		}
		opinion_modifier = {
			opinion_target = scope:actor
			multiplier = 0.5
		}
		modifier = { # You're my friend :)
			add = 10
			desc = youre_my_friend_tt
			has_relation_friend = scope:actor
		}
		modifier = { # You're my guardian
			add = 10
			desc = youre_my_guardian_tt
			has_relation_guardian = scope:actor
		}
		modifier = {
			scope:actor = {
				exists = house
			}
			scope:recipient = {
				exists = house
			}
			exists = scope:actor.house.house_head.top_liege
			house.house_head.top_liege ?= scope:actor.house.house_head.top_liege
			add = {
				value = scope:actor.house.house_power_score
				subtract = scope:recipient.house.house_power_score
			}
			desc = RELATIVE_FAMILY_RATING
		}
		modifier = {
			exists = scope:actor.house
			exists = house
			scope:recipient.dynasty.dynasty_prestige_level != scope:actor.dynasty.dynasty_prestige_level
			add = {
				value = scope:actor.dynasty.dynasty_prestige_level
				subtract = scope:recipient.dynasty.dynasty_prestige_level
				multiply = 10
			}
			desc = RELATIVE_FAMILY_RENOWN
		}
		modifier = {
			faith = {
				faith_hostility_level = {
					target = scope:actor.faith
					value >= faith_astray_level
				}
			}
			add = {
				value = "faith.faith_hostility_level(scope:actor.faith)"
				multiply = -10
			}
			desc = FAITH_HOSTILITY_LEVEL
		}
		modifier = {
			exists = scope:actor.top_liege.primary_title.state_faith
			faith = {
				faith_hostility_level = {
					target = scope:actor.top_liege.primary_title.state_faith
					value >= faith_astray_level
				}
			}
			add = {
				value = "faith.faith_hostility_level(scope:actor.top_liege.primary_title.state_faith)"
				multiply = -5
			}
			desc = FAITH_HOSTILITY_LEVEL_STATE_FAITH
		}
		modifier = {
			culture != scope:actor.culture
			"scope:recipient.culture.cultural_acceptance(scope:actor.culture)" < 50
			add = {
				value = 50
				subtract = "scope:recipient.culture.cultural_acceptance(scope:actor.culture)"
				multiply = -0.25
				round = yes
			}
			desc = CULTURAL_ACCEPTANCE
		}
		modifier = {
			culture != scope:actor.culture
			"scope:recipient.culture.cultural_acceptance(scope:actor.culture)" >= 50
			add = {
				value = "scope:recipient.culture.cultural_acceptance(scope:actor.culture)"
				subtract = 50
				multiply = 0.25
				round = yes
			}
			desc = CULTURAL_ACCEPTANCE
		}
		modifier = {
			add = scope:recipient.current_military_strength
			desc = RECIPIENT_MILITARY_STRENGTH
		}
		modifier = {
			add = scope:actor.current_military_strength
			scope:title_maa = yes
			desc = PROMISED_TITLE_MAA
		}
		modifier = {
			add = {
				value = scope:secondary_recipient.top_liege.current_military_strength
				multiply = -1
			}
			desc = SECONDARY_RECIPIENT_MILITARY_STRENGTH
		}
		modifier = { # Must not be at war already
			is_at_war = yes
			add = -1000
			desc = ALREADY_AT_WAR
		}
	}

	ai_frequency = 120

	ai_will_do = {
		base = 50
		modifier = { # The AI will only use a Hook if they couldn't otherwise do this
			scope:hook = yes
			add = -1
		}
		modifier = { # My house needs more members
			add = 100
			scope:actor.house = {
				any_house_member = {
					count < 3
					save_temporary_scope_as = house_member_temp
					NOT = {
						scope:actor.top_liege.faith = { has_dominant_ruling_gender = scope:house_member_temp }
					}
				}
			}
		}
		opinion_modifier = { # Opinion
			opinion_target = scope:recipient
			multiplier = 0.5
		}
		modifier = { # My rival
			add = -25
			scope:actor = { has_relation_rival = scope:recipient }
		}
		modifier = { # My friend
			add = 25
			scope:actor = { has_relation_friend = scope:recipient }
		}
		modifier = { # My ward
			add = 25
			scope:actor = { has_relation_guardian = scope:recipient }
		}
		modifier = { # I care about bloodlines and dynasties and whatnot
			add = -25
			scope:actor = {
				OR = {
					has_trait = arrogant
					has_trait = callous
				}
			}
		}
		modifier = { # I will not adopt filthy filthy heretics
			factor = 0
			ai_zeal >= medium_positive_ai_value
			faith = {
				faith_hostility_level = {
					target = scope:recipient.faith
					value >= faith_astray_level
				}
			}
		}
		modifier = { # I'll not make them start a war they'll surely lose
			factor = 0
			scope:recipient.current_military_strength < {
				value = scope:secondary_recipient.current_military_strength
				multiply = 0.75
			}
		}
	}
}

#House Head requests to landed family member - AKA Request as House Head
house_head_request_interaction = {
	icon = house_head_request_interaction
	category = interaction_category_admin
	common_interaction = yes
	desc = house_head_request_interaction_desc

	ai_maybe = yes
	ai_min_reply_days = 4
	ai_max_reply_days = 9
	can_send_despite_rejection = yes
	popup_on_receive = yes

	greeting = positive
	notification_text = HOUSE_HEAD_REQUEST_PROPOSAL

	pre_answer_yes_key = ACCEPT
	pre_answer_no_key = DECLINE

	ai_targets = {
		ai_recipients = family
		ai_recipients = peer_vassals
		ai_recipients = vassals
		ai_recipients = liege
	}
	ai_target_quick_trigger = { adult = yes }
	ai_frequency = 36

	cooldown_against_recipient = { years = 10 }
	cooldown = { years = 2 }

	redirect = {
	}

	cost = { # If the cost changes, remember to update the on_send to give correct refund in the event
	}

	is_shown = {
		NOT = { scope:recipient = scope:actor }
		scope:actor = {
			has_government = administrative_government
			this = house.house_head
		}
		scope:recipient = {
			has_government = administrative_government
			house = scope:actor.house
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			NOT = { is_at_war_with = scope:recipient }
		}
		scope:recipient = {
			is_landed = yes
			is_adult = yes
		}
	}

	send_options_exclusive = yes
	send_option = {
		flag = gold
		localization = HH_ASK_FOR_GOLD
	}
	send_option = {
		flag = hostile_schemes
		localization = ASK_FOR_HOSTILE_SCHEMES_HELP
	}
	send_option = {
		flag = personal_schemes
		localization = ASK_FOR_PERSONAL_SCHEMES_HELP
	}
	send_option = {
		flag = political_schemes
		localization = ASK_FOR_POLITICAL_SCHEMES_HELP
	}
	send_option = {
		is_valid = {
			custom_tooltip = {
				text = hh_recipient_has_valid_artifact
				scope:recipient = {
					any_character_artifact = {
						save_temporary_scope_as = target_artifact
						OR = {
							scope:actor.house = { has_house_artifact_claim = scope:target_artifact }
							scope:actor = { has_personal_artifact_claim = scope:target_artifact }
						}
					}
				}
			}
		}
		is_shown = {
			scope:actor.domicile ?= { has_domicile_building_or_higher = cabinet_of_curiosities_01 }

		}
		flag = artifact
		localization = ASK_FOR_ARTIFACT
	}
	send_option = {
		is_valid = {
			custom_tooltip = {
				text = hh_recipient_has_valid_knight
				scope:recipient = {
					number_of_knights > 0
					any_knight = {
						is_acclaimed = no
						is_landed = no
					}
				}
			}
		}
		is_shown = {
			OR = {
				scope:actor.domicile ?= { has_domicile_building_or_higher = guardhouse_01 }
				scope:actor.domicile ?= { has_domicile_building_or_higher = barracks_01 }
			}
		}
		flag = knight
		localization = ASK_FOR_KNIGHT
	}
	send_option = {
		is_valid = {
			trigger_if = {
				limit = {
					scope:actor = {
						NOT = {
							any_maa_regiment = { is_personal_maa_regiment = yes }
						}
					}
				}
				custom_tooltip = {
					text = hh_has_personal_maa
					scope:actor = {
						any_maa_regiment = { is_personal_maa_regiment = yes }
					}
				}
			}
			trigger_else = {
				custom_tooltip = {
					text = hh_has_personal_maa_size
					scope:actor = {
						any_maa_regiment = {
							is_personal_maa_regiment = yes
							can_upgrade_maa = yes
						}
					}
				}
			}
			custom_tooltip = {
				text = hh_recipient_has_personal_maa
				scope:recipient = {
					any_maa_regiment = {
						is_personal_maa_regiment = yes
					}
				}
			}
		}
		is_shown = {
			OR = {
				scope:actor.domicile ?= { has_domicile_building_or_higher = guardhouse_03 }
				scope:actor.domicile ?= { has_domicile_building_or_higher = barracks_01 }
				scope:actor.domicile ?= { has_domicile_building_or_higher = watchtower_04 }
			}
		}
		flag = maa
		localization = ASK_FOR_MAA
	}
	send_option = {
		is_shown = {
			OR = {
				scope:actor.domicile ?= { has_domicile_building_or_higher = storage_01 }
				scope:actor.domicile ?= { has_domicile_building_or_higher = storage_warehouse_03 }
			}
		}
		flag = building
		localization = ASK_FOR_BUILDING
	}
	send_option = {
		is_valid = {
			custom_tooltip = {
				text = hh_recipient_has_valid_courtier
				scope:recipient = {
					any_courtier_or_guest = {
						ep3_interesting_courtier_to_ask_trigger = yes
					}
				}
			}
		}
		flag = courtier
		localization = ASK_FOR_COURTIER
	}

	on_send = {
	}

	on_accept = {
		if = {
			limit = {
				scope:gold = yes
			}
			scope:actor = {
				send_interface_message = {
					type = event_toast_effect_good
					title = house_head_request_accepted
					left_icon = scope:recipient

					scope:recipient = {
						pay_short_term_gold = {
							target = scope:actor
							gold = medium_gold_value
						}
					}
				}
			}
		}
		else_if = {
			limit = {
				scope:hostile_schemes = yes
			}
			scope:actor = {
				send_interface_message = {
					type = event_toast_effect_good
					title = house_head_request_accepted
					left_icon = scope:recipient

					custom_tooltip = {
						text = hostile_schemes_help_request_tt
						scope:actor = {
							add_to_variable_list = {
								name = supporting_hostile_schemes
								target = scope:recipient
								years = 10
							}
						}
					}
					scope:recipient = {
						add_character_modifier = {
							modifier = hostile_schemes_distracted_modifier
							years = 5
						}
					}
				}
			}
		}
		else_if = {
			limit = {
				scope:personal_schemes = yes
			}
			scope:actor = {
				send_interface_message = {
					type = event_toast_effect_good
					title = house_head_request_accepted
					left_icon = scope:recipient

					custom_tooltip = {
						text = personal_schemes_help_request_tt
						scope:actor = {
							add_to_variable_list = {
								name = supporting_personal_schemes
								target = scope:recipient
								years = 10
							}
						}
					}
					scope:recipient = {
						add_character_modifier = {
							modifier = personal_schemes_distracted_modifier
							years = 5
						}
					}
				}
			}
		}
		else_if = {
			limit = {
				scope:political_schemes = yes
			}
			scope:actor = {
				send_interface_message = {
					type = event_toast_effect_good
					title = house_head_request_accepted
					left_icon = scope:recipient

					custom_tooltip = {
						text = political_schemes_help_request_tt
						scope:actor = {
							add_to_variable_list = {
								name = supporting_political_schemes
								target = scope:recipient
								years = 10
							}
						}
					}
					scope:recipient = {
						add_character_modifier = {
							modifier = political_schemes_distracted_modifier
							years = 5
						}
					}
				}
			}
		}
		else_if = {
			limit = {
				scope:artifact = yes
			}
			scope:actor = {
				send_interface_message = {
					type = event_toast_effect_good
					title = house_head_request_accepted
					left_icon = scope:recipient
					right_icon = scope:target_artifact

					scope:recipient = {
						random_character_artifact = {
							limit = {
								save_temporary_scope_as = target_artifact
								OR = {
									scope:actor.house = { has_house_artifact_claim = scope:target_artifact }
									scope:actor = { has_personal_artifact_claim = scope:target_artifact }
								}
							}
							save_scope_as = target_artifact
							set_owner = scope:actor
						}
					}
				}
			}
		}
		else_if = {
			limit = {
				scope:knight = yes
			}
			scope:recipient = {
				ordered_knight = {
					limit = {
						is_acclaimed = no
						is_landed = no
					}
					order_by = prowess
					save_scope_as = knight
				}
			}
			scope:actor = {
				send_interface_message = {
					type = event_toast_effect_good
					title = house_head_request_accepted
					left_icon = scope:recipient
					right_icon = scope:knight

					scope:actor = { add_courtier = scope:knight }
				}
			}
		}
		else_if = {
			limit = {
				scope:maa = yes
			}
			scope:actor = {
				send_interface_message = {
					type = event_toast_effect_good
					title = house_head_request_accepted
					left_icon = scope:recipient

					scope:recipient = {
						ordered_maa_regiment = {
							limit = {
								is_personal_maa_regiment = yes
							}
							save_scope_as = maa_regiment_decrease
						}
						scope:maa_regiment_decrease = {
							change_maa_regiment_size = -1
						}
					}
					scope:actor = {
						ordered_maa_regiment = {
							limit = {
								is_personal_maa_regiment = yes
								can_upgrade_maa = yes
							}
							save_scope_as = maa_regiment_increase
						}
						scope:maa_regiment_increase = {
							change_maa_regiment_size = {
								size = 1
								reinforce = yes
							}
						}
					}
				}
			}
		}
		else_if = {
			limit = {
				scope:building = yes
			}
			scope:actor = {
				send_interface_message = {
					type = event_toast_effect_good
					title = house_head_request_accepted
					left_icon = scope:recipient

					scope:actor = {
						add_to_variable_list = {
							name = supporting_building
							target = scope:recipient
							years = 10
						}
						add_character_modifier = {
							modifier = estate_supporting_buildings_modifier
							years = 10
						}
					}
					scope:recipient = {
						add_prestige = medium_prestige_loss
					}
				}
			}
		}
		else_if = {
			limit = {
				scope:courtier = yes
			}
			scope:recipient = {
				random_courtier_or_guest = {
					limit = {
						ep3_interesting_courtier_to_ask_trigger = yes
					}
					save_scope_as = courtier
				}
			}
			scope:actor = {
				send_interface_message = {
					type = event_toast_effect_good
					title = house_head_request_accepted
					left_icon = scope:recipient
					right_icon = scope:courtier

					add_courtier = scope:courtier
				}
			}
		}
	}

	on_decline = {
		scope:actor = {
			send_interface_message = {
				type = event_toast_effect_bad
				title = house_head_request_denied
				left_icon = scope:recipient

				scope:recipient = {
					change_influence = major_influence_loss
				}
			}
		}

		scope:actor = {
			if = {
				limit = {
					is_ai = yes
				}
				add_opinion = {
					target = scope:recipient
					modifier = disrespect_opinion
					opinion = -30
				}
			}
		}
	}

	ai_potential = {
		is_house_head = yes
	}

	ai_will_do = {
		base = 50
	}

	ai_accept = {
		base = 100
		modifier = {
			add = 25
			desc = CLOSE_FAMILY_REASON
			scope:recipient = {
				is_close_family_of = scope:actor
			}
		}

		modifier = {
			add = 25
			desc = WE_ARE_FRIENDS
			scope:recipient = {
				has_relation_friend = scope:actor
			}
		}

		modifier = {
			add = 50
			desc = WE_ARE_BEST_FRIENDS
			scope:recipient = {
				has_relation_best_friend = scope:actor
			}
		}

		modifier = {
			add = 10
			desc = WE_ARE_LOVERS
			scope:recipient = {
				has_relation_lover = scope:actor
			}
		}

		modifier = {
			add = -100
			desc = WE_ARE_RIVALS
			scope:recipient = {
				has_relation_rival = scope:actor
			}
		}

		modifier = {
			add = -500
			desc = WE_ARE_NEMESES
			scope:recipient = {
				has_relation_nemesis = scope:actor
			}
		}
		opinion_modifier = {
			opinion_target = scope:actor
			multiplier = 0.5
		}
		modifier = {
			# can't afford to be difficult
			scope:recipient = {
				influence <= major_influence_value
			}
			add = 30
			desc = INFLUENCE_USED
		}
		# Don't bankrupt the AI
		modifier = {
			scope:gold = yes
			scope:recipient.gold <= medium_gold_value
			add = -75
			desc = GOLD_NEGATIVE_REASON
		}
		# Personality
		modifier = {
			scope:recipient = {
				has_trait = loyal
			}
			desc = INTERACTION_LOYAL
			add = 20
		}
		modifier = {
			scope:recipient = {
				has_trait = disloyal
			}
			desc = INTERACTION_DISLOYAL
			add = -20
		}
	}
}

# Request Clergy Support / request_clergy_support
ep3_hof_ask_for_influence_interaction = {
	icon = icon_influence_01
	category = interaction_category_religion

	desc = ep3_hof_ask_for_influence_interaction_desc

	ai_targets = {
		ai_recipients = head_of_faith
	}
	ai_target_quick_trigger = {
		adult = yes
	}
	ai_frequency = 24

	cooldown_against_recipient = { years = 10 }

	is_shown = {
		NOT = {
			scope:recipient = scope:actor
		}
		scope:actor.faith = {
			religious_head = scope:recipient
			has_doctrine = doctrine_spiritual_head
		}
		scope:actor = {
			is_playable_character = yes
			has_government = administrative_government
			is_lowborn = no
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			piety >= massive_piety_value
			custom_description = {
				text = "hof_ask_for_gold_excommunicated"
				NOT = { has_trait = excommunicated }
			}
			NOT = { is_at_war_with = scope:recipient }
			custom_description = {
				text = "hof_interaction_unreformed_faith"
				NOT = {
					faith = { has_doctrine_parameter = unreformed }
				}
			}
			custom_description = {
				text = "hof_interaction_state_faith"
				top_liege = {
					government_allows = state_faith
					exists = primary_title.state_faith
				}
				faith = {
					this = scope:actor.top_liege.primary_title.state_faith
				}
			}
			custom_description = {
				text = "hof_interaction_has_house_modifier"
				exists = house
				house = {
					NOT = {
						has_house_modifier = ep3_requested_faith_support_modifier
					}
				}
			}
			custom_description = {
				text = "hof_interaction_is_house_head"
				exists = house
				house = {
					house_head = scope:actor
				}
			}
		}
		scope:recipient = { is_busy_in_events_localised = yes }
	}

	auto_accept = {
		custom_description = {
			text = "spending_hook"
			subject = scope:actor
			object = scope:recipient
			scope:hook = yes
		}
	}

	send_option = {
		is_shown = {
			NOT = { scope:actor = scope:recipient }
		}
		is_valid = {
			scope:actor = {
				has_usable_hook = scope:recipient
			}
		}
		flag = hook
		localization = GENERIC_SPEND_A_HOOK
	}
	should_use_extra_icon = {
		scope:actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	send_options_exclusive = no

	ai_min_reply_days = 1
	ai_max_reply_days = 5

	on_accept = {
		ep3_hof_ask_for_influence_interaction_effect = yes

		scope:actor = {
			trigger_event = ep3_interactions_events.0620
		}
	}

	on_decline = {
		scope:actor = {
			trigger_event = ep3_interactions_events.0621
		}
	}

	ai_potential = {
		is_playable_character = yes
		piety >= massive_piety_value
		NOT = { has_trait = excommunicated }
		highest_held_title_tier > tier_barony
		exists = faith.religious_head
		exists = house
	}

	ai_accept = {
		base = -50

		opinion_modifier = {
			opinion_target = scope:actor
			who = scope:recipient
			multiplier = 0.5
		}

		#Doesn't like the emperor... if you're not the emperor
		modifier = {
			add = 5
			scope:actor.top_liege = {
				NOR = {
					this = scope:actor
					this = scope:recipient
				}
				reverse_opinion = {
					target = scope:recipient
					value < 0
				}
				reverse_opinion = {
					target = scope:recipient
					value > -40
				}
			}
			desc = HOF_OPINION_OF_EMPEROR
		}
		modifier = {
			add = 10
			scope:actor.top_liege = {
				NOR = {
					this = scope:actor
					this = scope:recipient
				}
				reverse_opinion = {
					target = scope:recipient
					value <= -40
				}
				reverse_opinion = {
					target = scope:recipient
					value > -80
				}
			}
			desc = HOF_OPINION_OF_EMPEROR
		}
		modifier = {
			add = 20
			scope:actor.top_liege = {
				NOR = {
					this = scope:actor
					this = scope:recipient
				}
				reverse_opinion = {
					target = scope:recipient
					value <= -80
				}
			}
			desc = HOF_OPINION_OF_EMPEROR
		}
		#Likes emperor... and you're not emperor
		modifier = {
			add = -5
			scope:actor.top_liege = {
				NOR = {
					this = scope:actor
					this = scope:recipient
				}
				reverse_opinion = {
					target = scope:recipient
					value >= 40
				}
				reverse_opinion = {
					target = scope:recipient
					value < 80
				}
			}
			desc = HOF_OPINION_OF_EMPEROR
		}
		modifier = {
			add = -10
			scope:actor.top_liege = {
				NOR = {
					this = scope:actor
					this = scope:recipient
				}
				reverse_opinion = {
					target = scope:recipient
					value >= 80
				}
			}
			desc = HOF_OPINION_OF_EMPEROR
		}

		modifier = { # Same language
			add = 5
			desc = speaks_same_language_interaction_reason
			trigger = {
				scope:actor = {
					knows_language_of_culture = scope:recipient.culture
				}
			}
		}

		modifier = { # Attacking a co-religionist
			add = -50
			desc = I_AM_ATTACKING_A_CORELIGIONIST
			scope:actor = {
				is_at_war = yes
				any_character_war = {
					primary_attacker = scope:actor
					primary_defender.faith = scope:actor.faith
					primary_defender = {
						NOT = {
							has_trait = excommunicated
						}
					}
				}
			}
		}

		modifier = { # Offensive holy war/excommunication war
			add = 30
			desc = I_AM_WAGING_AN_OFFENSIVE_HOLY_OR_EXCOMMUNICATION_WAR
			scope:actor = {
				is_at_war = yes
				any_character_war = {
					is_attacker = scope:actor
					OR = {
						using_non_ghw_holy_war_cb_trigger = yes
						using_cb = excommunication_war
					}
				}
			}
		}

		modifier = { # Defensive Holy War
			add = 50
			desc = I_AM_DEFENDING_AGAINST_A_HOLY_WAR
			scope:actor = {
				is_at_war = yes
				any_character_war = {
					is_defender = scope:actor
					using_non_ghw_holy_war_cb_trigger = yes
				}
			}
		}

		modifier = { # HoF wants the influence for themselves!
			add = -10
			desc = THEY_ARE_GREEDY
			scope:recipient = {
				ai_greed >= high_positive_greed
			}
		}

		modifier = { # I am influential already
			add = -10
			desc = I_AM_INFLUENTIAL
			scope:actor = {
				influence_level >= 4
				NOT = {
					influence_level >= 6
				}
			}
		}

		modifier = { # I am very influential already
			add = -20
			desc = I_AM_INFLUENTIAL
			scope:actor = {
				influence_level >= 6
			}
		}

		modifier = { # I am Adulterer/Fornicator
			add = -25
			desc = I_AM_ADULTERER
			scope:actor = {
				OR = {
					AND = {
						has_trait = fornicator
						trait_is_shunned_or_criminal_in_faith_trigger = { FAITH = faith TRAIT = fornicator GENDER_CHARACTER = scope:actor }
					}
					AND = {
						has_trait = adulterer
						trait_is_shunned_or_criminal_in_faith_trigger = { FAITH = faith TRAIT = adulterer GENDER_CHARACTER = scope:actor }
					}
				}
			}
		}

		modifier = { # I am a Murderer
			add = -50
			desc = I_AM_MURDERER
			scope:actor = {
				has_trait = murderer
			}
		}

		modifier = { # I am Incestous
			add = -50
			desc = I_AM_INCESTOUS
			scope:actor = {
				NOT = { scope:recipient = { faith = { has_doctrine = doctrine_consanguinity_unrestricted } } }
				has_trait = incestuous
			}
		}

		modifier = { # I am a Kinslayer
			add = -50
			desc = I_AM_A_KINSLAYER
			scope:actor = {
				OR = {
					AND = {
						has_trait = kinslayer_1
						trait_is_shunned_or_criminal_in_faith_trigger = { FAITH = faith TRAIT = kinslayer_1 GENDER_CHARACTER = scope:actor }
					}
					AND = {
						has_trait = kinslayer_2
						trait_is_shunned_or_criminal_in_faith_trigger = { FAITH = faith TRAIT = kinslayer_2 GENDER_CHARACTER = scope:actor }
					}
					AND = {
						has_trait = kinslayer_3
						trait_is_shunned_or_criminal_in_faith_trigger = { FAITH = faith TRAIT = kinslayer_3 GENDER_CHARACTER = scope:actor }
					}
				}
			}
		}
		modifier = {
			desc = RELIGIOUS_HEAD_INTERACTION_SAVIOR
			add = 15
			scope:actor = {
				has_trait = savior
			}
		}
		modifier = {
			desc = RELIGIOUS_HEAD_INTERACTION_DIVINE_BLOOD
			add = 5
			scope:actor = {
				has_trait = divine_blood
			}
		}
		modifier = {
			desc = RELIGIOUS_HEAD_INTERACTION_PARAGON
			add = 15
			scope:actor = {
				has_trait = paragon
			}
		}
		modifier = {
			desc = RELIGIOUS_HEAD_INTERACTION_CONSECRATED_BLOOD
			add = 5
			scope:actor = {
				has_trait = consecrated_blood
			}
		}

		modifier = { # You are of the same dynasty as the Head of Faith
			add = 5
			desc = YOU_ARE_MY_DYNASTY_MEMBER
			scope:recipient = {
				is_lowborn = no
				dynasty = scope:actor.dynasty
				NOR = {
					is_close_or_extended_family_of = scope:actor
					is_cousin_of = scope:actor
					is_child_of = scope:actor
					scope:recipient.dynasty = scope:secondary_recipient.dynasty
				}
			}
		}

		modifier = { # You are of the same house as the Head of Faith
			add = 10
			desc = YOU_ARE_MY_HOUSE_MEMBER
			scope:recipient = {
				is_lowborn = no
				house = scope:actor.house
				NOR = {
					is_close_or_extended_family_of = scope:actor
					is_cousin_of = scope:actor
					is_child_of = scope:actor
					scope:recipient.house = scope:secondary_recipient.house
				}
			}
		}

		modifier = { # Related to the Head of Faith
			add = 10
			desc = YOU_ARE_MY_RELATIVE
			scope:recipient = {
				OR = {
					is_close_or_extended_family_of = scope:actor
					is_cousin_of = scope:actor
				}
				NOT = { is_child_of = scope:actor }
			}
		}

		modifier = { # Parent of the Head of Faith
			add = 25
			desc = YOU_ARE_MY_PARENT
			scope:recipient = {
				is_child_of = scope:actor
			}
		}

		modifier = { # Friend of the Head of Faith
			add = 25
			desc = WE_ARE_FRIENDS
			scope:recipient = {
				has_relation_friend = scope:actor
			}
		}

		modifier = { # Best Friend of the Head of Faith
			add = 50
			desc = WE_ARE_BEST_FRIENDS
			scope:recipient = {
				has_relation_best_friend = scope:actor
			}
		}

		modifier = { # Lover of the Head of Faith
			add = 10
			desc = WE_ARE_LOVERS
			scope:recipient = {
				has_relation_lover = scope:actor
			}
		}

		modifier = { # Rival of the Head of Faith
			add = -100
			desc = WE_ARE_RIVALS
			scope:recipient = {
				has_relation_rival = scope:actor
			}
		}

		modifier = { # Nemesis of the Head of Faith
			add = -500
			desc = WE_ARE_NEMESES
			scope:recipient = {
				has_relation_nemesis = scope:actor
			}
		}

		modifier = {
			add = {
				add = 10
				multiply = scope:actor.num_virtuous_traits
			}
			scope:actor.num_virtuous_traits > 0
			desc = I_AM_VIRTUOUS
		}

		modifier = {
			add = {
				add = 5
				multiply = scope:actor.piety_level
			}
			scope:actor.piety_level > 1
			desc = I_AM_PIOUS
		}

		modifier = {
			add = {
				add = -10
				multiply = scope:actor.num_sinful_traits
			}
			scope:actor.num_sinful_traits > 0
			desc = I_AM_SINFUL
		}
	}

	ai_will_do = {
		base = 0

		modifier = { # The AI will only use a Hook if they couldn't otherwise do this
			scope:hook = yes
			add = -1
		}

		modifier = { # I am low on influence
			add = 300
			scope:actor = {
				influence <= minor_influence_value
			}
		}

		modifier = { # Piety to burn, and no reason to keep it.
			add = 100
			scope:actor = {
				piety > massive_piety_value
				NOR = {
					has_character_modifier = vow_of_poverty_modifier
					has_trait = content
					has_trait = humble
				}
			}
		}
		modifier = { # Or when greedy
			add = {
				value = scope:actor.ai_greed
				multiply = 0.5
			}
			scope:actor = {
				ai_greed > 0
			}
		}
		modifier = { # Or when energy
			add = {
				value = scope:actor.ai_energy
				multiply = 0.5
			}
			scope:actor = {
				ai_energy > 0
			}
		}

		modifier = { # I am an up and comer who really needs help
			add = 100
			scope:actor = {
				influence_level <= 1
			}
		}

		modifier = {
			add = 100
			scope:actor = {
				ai_has_warlike_personality = yes
			}
		}

		modifier = {
			add = 50
			scope:actor = {
				ai_has_cautious_personality = no
			}
		}
	}
}

# Ask non-participating governor to join ongoing Faction War
ep3_join_faction_war_interaction = {
	icon = join_faction_war_interaction
	category = interaction_category_diplomacy
	common_interaction = yes

	desc = ep3_join_faction_war_interaction_desc

	cooldown_against_recipient = { years = 10 }

	greeting = positive
	notification_text = JOIN_FACTION_WAR_NOTIFICATION_TEXT

	ai_min_reply_days = 4
	ai_max_reply_days = 9

	is_shown = {
		scope:actor = {
			has_ep3_dlc_trigger = yes
			is_at_war = yes
			NOR = {
				this = scope:recipient
				is_at_war_with = scope:recipient
			}
			has_government = administrative_government
		}
		scope:recipient = {
			has_government = administrative_government
			scope:actor.liege ?= liege
		}
		scope:actor.joined_faction ?= {
			faction_is_at_war = yes
			faction_war ?= { is_attacker = scope:actor }
			faction_target != scope:recipient
		}
	}

	redirect = {
		# Save secondary_recipient for UI and ai chance
		scope:actor.joined_faction.faction_target ?= { save_scope_as = secondary_recipient }
	}

	cost = { influence = 150 }

	is_valid_showing_failures_only = {
		scope:recipient = {
			is_imprisoned = no
			NOT = { is_at_war_with = liege }
		}
		scope:actor.joined_faction ?= {
			faction_war = {
				custom_tooltip = {
					text = ep3_join_faction_war_interaction_ally_tt
					NOT = {
						primary_defender = { is_allied_to = scope:recipient }
					}
				}
			}
		}
	}

	# Offer gold
	send_option = {
		is_valid = { scope:actor.gold > scope:actor.medium_gold_value }
		flag = gold
		localization = GENERIC_SPEND_GOLD
	}
	# Use hook
	send_option = {
		is_valid = {
			scope:actor = { has_usable_hook = scope:recipient }
			NOT = {
				scope:recipient = { is_imprisoned_by = scope:actor }
			}
		}
		flag = hook
		localization = SCHEME_HOOK
	}
	should_use_extra_icon = {
		scope:actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	send_options_exclusive = no

	can_send = {
		scope:actor = { is_ai = no } # player only
		custom_tooltip = {
			text = ep3_join_faction_war_interaction_ongoing_tt
			scope:actor.joined_faction ?= {
				faction_is_at_war = yes
				faction_war ?= { is_attacker = scope:actor }
			}
		}
		custom_tooltip = {
			text = ep3_join_faction_war_interaction_faction_tt
			scope:recipient = {
				trigger_if = {
					limit = { exists = joined_faction }
					NOR = {
						joined_faction.faction_leader = this
						joined_faction.special_character ?= this
					}
				}
			}
		}
		scope:recipient = {
			custom_tooltip = {
				text = ep3_join_faction_war_interaction_offer_tt
				NOT = { has_character_flag = under_offer_join_faction_war_flag }
			}
		}
	}

	on_send = {
		scope:recipient = {
			add_character_flag = {
				flag = under_offer_join_faction_war_flag
				months = 1
			}
		}
	}

	on_accept = {
		scope:actor = { trigger_event = ep3_interactions_events.0800 }
		show_as_tooltip = { ep3_join_faction_war_effect = yes }
		scope:recipient = { remove_character_flag = under_offer_join_faction_war_flag }
	}

	on_decline = {
		scope:actor = { trigger_event = ep3_interactions_events.0801 }
		scope:recipient = { remove_character_flag = under_offer_join_faction_war_flag }
	}

	auto_accept = {
		custom_description = {
			text = "spending_hook"
			subject = scope:actor
			object = scope:recipient
			scope:hook = yes
			scope:actor = { has_strong_hook = scope:recipient }
		}
	}

	ai_accept = {
		base = -25
		modifier = {
			scope:hook = yes
			add = 40
			desc = SCHEME_WEAK_HOOK_USED
		}
		modifier = {
			scope:gold = yes
			add = {
				value = 10
				add = {
					value = scope:recipient.ai_greed
					multiply = 0.25
					min = 0
				}
			}
			desc = SCHEME_WITH_GIFT_SIGNIFICANT
		}
		modifier = { # Target is less likely to accept if at war
			scope:recipient = { is_at_war = yes }
			add = -200
			desc = RECIPIENT_IS_AT_WAR_REASON
		}
		common_faction_modifiers = {
			FACTION_TARGET = scope:secondary_recipient
			OPINION_MULTIPLIER = -1.5
			MAX_OPINION = 150
			POWER = 0
			THRESHOLD = 80
		}
		admin_faction_modifiers = {
			FACTION_TARGET = scope:secondary_recipient
			FACTION_TYPE = claimant_faction
		}
		modifier = {
			exists = scope:actor.joined_faction.special_character
			add = "scope:recipient.opinion(scope:actor.joined_faction.special_character)"
			desc = CLAIMANT_OPINION_REASON
		}
		modifier = {  # Refuse call against Heir
			add = -1000
			scope:recipient.player_heir ?= scope:secondary_recipient
			desc = WONT_FIGHT_HEIR_REASON
		}
		modifier = {  # Refuse call against Spouse
			add = -1000
			is_spouse_of = scope:secondary_recipient
			desc = WONT_FIGHT_SPOUSE_REASON
		}
		modifier = { # Reluctant to join against Friends
			add = -50
			has_relation_friend = scope:secondary_recipient
			desc = WONT_FIGHT_FRIEND
		}
		modifier = { # Reluctant to join against Best Friends
			add = -100
			has_relation_best_friend = scope:secondary_recipient
			desc = WONT_FIGHT_BEST_FRIEND
		}
		modifier = { # Reluctant to join against Lovers
			add = -100
			has_relation_lover = scope:secondary_recipient
			desc = WONT_FIGHT_LOVER
		}
		modifier = { # Reluctant to join against Soulmate
			add = -200
			has_relation_soulmate = scope:secondary_recipient
			desc = WONT_FIGHT_SOULMATE
		}
		modifier = {  # Refuse call for hostages' safety
			any_home_court_hostage = {
				warden = {
					OR = {
						is_at_war_with = scope:actor
						any_ally = { is_at_war_with = scope:actor }
					}
				}
			}
			add = {
				value = 0
				every_home_court_hostage = {
					limit = {
						warden = {
							OR = {
								is_at_war_with = scope:actor
								any_ally = { is_at_war_with = scope:actor }
							}
						}
					}
					subtract = call_to_arms_hostage_value
				}
				multiply = 0.25
			}
			desc = HOSTAGE_ENEMY_CALL_TO_ARMS_REASON
		}
		opinion_modifier = { # Opinion Factor
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 1.0
			desc = AI_OPINION_REASON
		}
	}

	ai_will_do = { base = 0 }
}

# Ask governor to switch sides in ongoing Faction War
ep3_switch_faction_war_sides_interaction = {
	icon = switch_faction_war_sides_interaction
	category = interaction_category_diplomacy
	common_interaction = yes

	desc = {
		triggered_desc = {
			trigger = {
				NOT = { scope:recipient = scope:secondary_recipient }
			}
			desc = ep3_switch_faction_war_sides_interaction_desc
		}
	}

	cooldown_against_recipient = { years = 10 }

	greeting = positive
	notification_text = SWITCH_FACTION_WAR_SIDES_NOTIFICATION_TEXT

	ai_min_reply_days = 4
	ai_max_reply_days = 9

	is_shown = {
		scope:actor = {
			has_ep3_dlc_trigger = yes
			is_at_war_with = scope:recipient
			has_government = administrative_government
			NOT = { this = scope:recipient }
		}
		scope:recipient = {
			has_government = administrative_government
			OR = {
				is_vassal_of = scope:actor
				scope:actor.liege ?= liege
			}
		}
		scope:actor = {
			any_character_war = {
				# Recipient involved in war
				is_participant = scope:recipient
				# Is a Faction war
				save_temporary_scope_as = faction_war_temp
				primary_attacker.joined_faction.faction_war ?= scope:faction_war_temp
				# Actor and recipient on opposing sides
				trigger_if = {
					limit = { is_defender = scope:recipient }
					is_attacker = scope:actor
				}
				trigger_else = { is_defender = scope:actor }
			}
		}
	}

	redirect = {
		scope:actor = {
			# Actor is involved in a faction war with recipient on the other side
			random_character_war = {
				limit = { ep3_switch_faction_war_sides_war_trigger = yes }
				# Save secondary_recipient for UI and ai chance
				if = {
					limit = { is_defender = scope:actor }
					primary_attacker = { save_scope_as = secondary_recipient }
				}
				else = {
					primary_defender = { save_scope_as = secondary_recipient }
				}
			}
		}
	}

	cost = { influence = 300 }

	is_valid_showing_failures_only = {
		scope:recipient = {
			is_imprisoned = no
			is_at_war = yes
		}
		custom_tooltip = {
			text = ep3_switch_faction_war_sides_interaction_primary_or_ally_or_claimant_tt
			scope:actor = {
				any_character_war = { ep3_switch_faction_war_sides_war_trigger = yes }
			}
		}
	}

	# Offer gold
	send_option = {
		is_valid = { scope:actor.gold > scope:actor.medium_gold_value }
		flag = gold
		localization = GENERIC_SPEND_GOLD
	}
	# Use hook
	send_option = {
		is_valid = {
			scope:actor = { has_usable_hook = scope:recipient }
			NOT = {
				scope:recipient = { is_imprisoned_by = scope:actor }
			}
		}
		flag = hook
		localization = SCHEME_HOOK
	}
	should_use_extra_icon = {
		scope:actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	send_options_exclusive = no

	can_send = {
		scope:actor = { is_ai = no } # player only
		custom_tooltip = {
			text = ep3_switch_faction_war_sides_interaction_tt
			scope:actor = {
				any_character_war = { ep3_switch_faction_war_sides_war_trigger = yes }
			}
		}
		scope:recipient = {
			custom_tooltip = {
				text = ep3_switch_faction_war_sides_interaction_offer_tt
				NOT = { has_character_flag = under_offer_switch_faction_war_sides_flag }
			}
		}
		custom_tooltip = {
			text = ep3_switch_faction_war_sides_cooldown_tt
			NOT = { exists = scope:recipient.var:switched_faction_war_sides }
		}
	}

	on_send = {
		scope:recipient = {
			add_character_flag = {
				flag = under_offer_switch_faction_war_sides_flag
				months = 1
			}
		}
	}

	on_accept = {
		scope:actor = { trigger_event = ep3_interactions_events.0810 }
		show_as_tooltip = { ep3_switch_faction_war_sides_effect = yes }
		scope:recipient = {
			set_variable = {
				name = switched_faction_war_sides
				value = scope:secondary_recipient
				years = 10
			}
			remove_character_flag = under_offer_join_faction_war_flag
		}
	}

	on_decline = {
		scope:actor = { trigger_event = ep3_interactions_events.0811 }
		scope:recipient = { remove_character_flag = under_offer_join_faction_war_flag }
	}

	auto_accept = {
		custom_description = {
			text = "spending_hook"
			subject = scope:actor
			object = scope:recipient
			scope:hook = yes
			scope:actor = { has_strong_hook = scope:recipient }
		}
	}

	ai_accept = {
		base = -50
		modifier = {
			scope:hook = yes
			add = 40
			desc = SCHEME_WEAK_HOOK_USED
		}
		modifier = {
			scope:gold = yes
			add = {
				value = 10
				add = {
					value = scope:recipient.ai_greed
					multiply = 0.25
					min = 0
				}
			}
			desc = SCHEME_WITH_GIFT_SIGNIFICANT
		}
		modifier = {
			add = {
				value = 0
				scope:actor = {
					every_character_war = {
						limit = {
							# Recipient involved in war
							is_participant = scope:recipient
							# Is a Faction war
							save_temporary_scope_as = faction_war_temp
							primary_attacker.joined_faction.faction_war ?= scope:faction_war_temp
							# Actor and recipient on opposing sides
							trigger_if = {
								limit = { is_defender = scope:recipient }
								is_attacker = scope:actor
								# Recipient must not be an ally of the opposing war leader
								NOT = {
									primary_defender = { is_allied_to = scope:recipient }
								}
							}
							trigger_else = {
								is_defender = scope:actor
								# Recipient must not be an ally of the opposing war leader
								NOT = {
									primary_attacker = { is_allied_to = scope:recipient }
								}
							}
							# Recipient must not be a war leader
							NOT = { is_war_leader = scope:recipient }
						}
						if = {
							limit = { is_defender = scope:actor }
							add = {
								value = ep3_invite_to_faction_war_strength_compare_defender_value
								divide = ep3_invite_to_faction_war_strength_compare_attacker_value
								if = {
									limit = { ep3_invite_to_faction_war_strength_compare_defender_value > ep3_invite_to_faction_war_strength_compare_attacker_value }
									multiply = 10
								}
								else = { multiply = -200 }
								max = 50
								min = -50
							}
						}
						else = {
							add = {
								value = ep3_invite_to_faction_war_strength_compare_attacker_value
								divide = ep3_invite_to_faction_war_strength_compare_defender_value
								if = {
									limit = { ep3_invite_to_faction_war_strength_compare_attacker_value > ep3_invite_to_faction_war_strength_compare_defender_value }
									multiply = 10
								}
								else = { multiply = -200 }
								max = 50
								min = -50
							}
						}
					}
				}
			}
			desc = WAR_STRENGTH_BALANCE_REASON
		}
		modifier = {
			add = {
				value = 0
				scope:actor = {
					every_character_war = {
						limit = {
							# Recipient involved in war
							is_participant = scope:recipient
							# Is a Faction war
							save_temporary_scope_as = faction_war_temp
							primary_attacker.joined_faction.faction_war ?= scope:faction_war_temp
							# Actor and recipient on opposing sides
							trigger_if = {
								limit = { is_defender = scope:recipient }
								is_attacker = scope:actor
								# Recipient must not be an ally of the opposing war leader
								NOT = {
									primary_defender = { is_allied_to = scope:recipient }
								}
							}
							trigger_else = {
								is_defender = scope:actor
								# Recipient must not be an ally of the opposing war leader
								NOT = {
									primary_attacker = { is_allied_to = scope:recipient }
								}
							}
							# Recipient must not be a war leader
							NOT = { is_war_leader = scope:recipient }
						}
						if = {
							limit = { is_defender = scope:actor }
							add = {
								value = 0
								if = {
									limit = { defender_war_score > attacker_war_score }
									add = defender_war_score
									divide = 2
								}
								else = {
									add = attacker_war_score
									multiply = -0.5
								}
								max = 50
								min = -50
							}
						}
						else = {
							add = {
								value = 0
								if = {
									limit = { attacker_war_score > defender_war_score }
									add = attacker_war_score
									divide = 2
								}
								else = {
									add = defender_war_score
									multiply = -0.5
								}
								max = 50
								min = -50
							}
						}
					}
				}
			}
			desc = WAR_SCORE_REASON
		}
		opinion_modifier = {
			opinion_target = scope:actor
			multiplier = 0.5
		}
		opinion_modifier = {
			trigger = {
				exists = scope:secondary_recipient
			}
			opinion_target = scope:secondary_recipient
			multiplier = -0.5
		}
		modifier = {  # Refuse call against Heir
			add = -1000
			exists = scope:secondary_recipient
			scope:recipient.player_heir ?= scope:secondary_recipient
			desc = WONT_FIGHT_HEIR_REASON
		}
		modifier = {  # Refuse call against Spouse
			add = -1000
			exists = scope:secondary_recipient
			is_spouse_of = scope:secondary_recipient
			desc = WONT_FIGHT_SPOUSE_REASON
		}
		modifier = { # Reluctant to join against Friends
			add = -50
			exists = scope:secondary_recipient
			has_relation_friend = scope:secondary_recipient
			desc = WONT_FIGHT_FRIEND
		}
		modifier = { # Reluctant to join against Best Friends
			add = -100
			exists = scope:secondary_recipient
			has_relation_best_friend = scope:secondary_recipient
			desc = WONT_FIGHT_BEST_FRIEND
		}
		modifier = { # Reluctant to join against Lovers
			add = -100
			exists = scope:secondary_recipient
			has_relation_lover = scope:secondary_recipient
			desc = WONT_FIGHT_LOVER
		}
		modifier = { # Reluctant to join against Soulmate
			add = -200
			exists = scope:secondary_recipient
			has_relation_soulmate = scope:secondary_recipient
			desc = WONT_FIGHT_SOULMATE
		}
	}

	ai_will_do = { base = 0 }
}

# Request Permission to Wage War
ep3_governor_request_war_permission_interaction = {
	icon = invasion
	category = interaction_category_admin

	desc = ep3_governor_request_war_permission_interaction_desc

	cooldown_against_recipient = { years = 10 }

	greeting = positive
	notification_text = request_war_permission_notification_text

	ai_targets = {
		ai_recipients = liege
	}
	ai_target_quick_trigger = {
		adult = yes
	}
	ai_frequency = 60
	ai_min_reply_days = 2
	ai_max_reply_days = 5

	is_shown = {
		scope:actor = {
			has_government = administrative_government
			liege = scope:recipient
			OR = {
				vassal_contract_has_flag = admin_theme_frontier
				vassal_contract_has_flag = admin_theme_naval
			}
		}
		scope:recipient = {
			has_government = administrative_government
			is_independent_ruler = yes
			has_realm_law_flag = admin_vassal_wars_permission_only
		}
	}

	is_valid_showing_failures_only = {
		scope:recipient = { is_busy_in_events_localised = yes }
		scope:recipient = { NOT = { has_strong_hook = scope:actor } }
		scope:actor = {
			is_at_war = no
			custom_tooltip = {
				text = admin_has_war_permission_already_desc
				NOT = { has_variable = admin_permission_to_declare_war }
			}
			top_liege = {
				custom_tooltip = {
					text = admin_all_vassal_wars_banned
					NOT = { has_realm_law_flag = admin_vassal_wars_banned }
				}
			}
		}
	}

	#Spend influence
	send_option = {
		flag = influence
		is_valid = {
			scope:actor.influence >= { value = massive_influence_value multiply = 2 }
			scope:actor = { is_ai = no } # The AI shouldn't spend influence for this
		}
		localization = SPEND_INFLUENCE
	}
	#Use hook
	send_option = {
		is_valid = {
			scope:actor = { has_usable_hook = scope:recipient }
		}
		flag = hook
		localization = SCHEME_HOOK
	}
	should_use_extra_icon = {
		scope:actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	send_options_exclusive = no

	on_accept = {
		scope:actor = {
			# Add permission
			custom_tooltip = {
				text = admin_gain_war_permission_desc
				set_variable = admin_permission_to_declare_war
			}

			# And send a toast as confirmation
			hidden_effect = {
				send_interface_toast = {
					type = event_toast_effect_good
					title = admin_gained_war_permission_title
					left_icon = scope:recipient
					custom_tooltip = admin_gained_war_permission_desc
				}
			}

			# If options are used, spend the corresponding cost
			if = {
				limit = { scope:influence = yes }
				change_influence = {
					value = massive_influence_loss
					multiply = 2
				}
				scope:recipient = { # Liege gets the spent influence
					change_influence = {
						value = massive_influence_gain
						multiply = 2
					}
				}
			}
			if = {
				limit = {
					scope:hook = yes
					has_hook = scope:recipient
				}
				use_hook = scope:recipient
			}
		}
	}

	on_decline = {
		scope:actor = {
			# Add penalties
			change_influence = minor_influence_loss
			add_opinion = {
				target = scope:recipient
				modifier = disappointed_opinion
				opinion = -20
			}

			# And send a toast to inform
			hidden_effect = {
				send_interface_toast = {
					type = event_toast_effect_bad
					title = admin_declined_war_permission_title
					left_icon = scope:recipient
					custom_tooltip = admin_declined_war_permission_desc

					show_as_tooltip = { change_influence = minor_influence_loss }
				}
			}
		}
	}

	ai_accept = {
		base = -50

		# Opinion Factor
		opinion_modifier = {
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 1
			desc = AI_SIMPLE_OPINION_REASON
		}

		# Send options
		modifier = {
			scope:hook = yes
			add = 100
			desc = SCHEME_WEAK_HOOK_USED
		}
		modifier = {
			scope:influence = yes
			add = {
				value = 20
				multiply = scope:actor.influence_level
				min = 5
			}
			desc = INFLUENCE_REASON
		}

		# Relations
		modifier = {
			scope:actor = {
				has_relation_rival = scope:recipient
			}
			add = -100
			desc = AI_YOUR_RIVAL
		}
		modifier = {
			scope:recipient = {
				is_close_family_of = scope:actor
			}
			add = 20
			desc = CLOSE_FAMILY_REASON
		}
		modifier = {
			scope:recipient = {
				is_extended_family_of = scope:actor
			}
			add = 10
			desc = EXTENDED_FAMILY_REASON
		}
		modifier = {
			scope:actor = {
				has_relation_friend = scope:recipient
			}
			add = 20
			desc = WE_ARE_FRIENDS
		}

		# Family status
		modifier = { # You are a powerful family
			scope:actor.house ?= {
				is_powerful_family = yes
			}
			add = 15
			desc = YOUR_FAMILY_IS_POWERFUL
		}
		modifier = { # You are a dominant family
			scope:actor.house ?= {
				is_dominant_family = yes
			}
			add = 30
			desc = YOUR_FAMILY_IS_DOMINANT
		}
	}

	ai_potential = {
		has_government = administrative_government
		is_adult = yes
		liege = { is_at_war = no } # Don't ask if your liege is at war
	}

	ai_will_do = {
		base = 10
		modifier = {
			scope:actor = {
				OR = {
					has_trait = ambitious
					has_trait = brave
					has_trait = greedy
					has_trait = wrathful
				}
			}
			add = 20
		}
		modifier = {
			scope:actor = {
				has_vassal_stance = glory_hound
			}
			add = 10
		}
		modifier = { # Attempt to be opportunistic if you border weak realms
			scope:actor = {
				any_top_realm_border_county = {
					any_neighboring_county = {
						holder.top_liege = {
							NOT = { this = scope:actor.top_liege }
							current_military_strength < { value = scope:actor.current_military_strength multiply = 0.4 }
						}
					}
				}
			}
			add = 25
		}
	}
}
