#Interactions relating to vassals

grant_vassal_interaction = {
	category = interaction_category_vassal
	common_interaction = no
	interface = transfer_vassal
	icon = icon_vassal

	special_interaction = grant_vassal_interaction

	populate_actor_list = {
		scope:actor = {
			every_vassal = {
				add_to_list = characters
			}
		}
	}

	desc = grant_vassal_interaction_desc

	prompt = GRANT_VASSAL_SELECT_VASSAL_TO_TRANSFER

	greeting = positive
	notification_text = GRANT_VASSAL_PROPOSAL

	pre_answer_yes_key = ACCEPT
	pre_answer_no_key = DECLINE

	is_shown = {
		scope:recipient != scope:actor
		OR = {
			AND = {
				exists = scope:recipient.liege
				scope:recipient.liege = scope:actor
			}
			AND = {
				exists = scope:actor.liege
				scope:actor.liege = scope:recipient
			}
			AND = {
				scope:actor.faith.religious_head = scope:recipient
				scope:recipient = { is_independent_ruler = yes }
#				scope:actor.faith = { NOT = { has_doctrine = doctrine_holy_order_head } }
			}
		}
		scope:recipient.highest_held_title_tier > tier_barony
	}

	is_valid_showing_failures_only = {
		scope:recipient = {
			is_landed = yes # Landless rulers should not have Vassals
			# Gallivanters won't accept additional responsibilities.
			NOT = { has_trait = gallivanter }
		}
		NOT = { scope:actor = { is_at_war_with = scope:recipient } }
		trigger_if = {
			limit = { exists = scope:secondary_actor }
			NOT = { scope:secondary_actor = { is_at_war_with = scope:recipient } }
			scope:recipient.primary_title.tier > scope:secondary_actor.primary_title.tier
		}
		trigger_if = {
			limit = {
				scope:actor = { is_ai = yes }
				exists = scope:secondary_actor
			}
			trigger_if = {
				limit = {
					NOT = {
						scope:recipient.primary_title = {
							any_in_de_jure_hierarchy = {
								holder = scope:secondary_actor
							}
						}
					}
				}
				scope:recipient.vassal_count < scope:recipient.vassal_limit # Avoid creating vassals with unsustainable situations
			}
			scope:secondary_actor = {
				NOT = { has_character_flag = ai_should_not_transfer }
			}
		}
		trigger_if = {
			limit = { scope:recipient.highest_held_title_tier <= tier_county }
			scope:recipient = { highest_held_title_tier > tier_county }
		}
		trigger_else = {
			scope:actor = {
				custom_description = {
					text = "basic_valid_vassal_to_tranfer"
					object = scope:recipient
					any_vassal = {
						NOT = { highest_held_title_tier = tier_barony }
						scope:recipient.highest_held_title_tier > highest_held_title_tier
					}
				}
			}
		}
		# Prevent Admin AI transferring admin vassals under non-admin vassals
		NAND = {
			scope:actor ?= {
				is_ai = yes
				government_allows = administrative
			}
			scope:recipient ?= {
				NOT = { government_allows = administrative }
			}
			scope:secondary_actor ?= { government_allows = administrative }
		}
		# Ritsuryo cannot transfer Soryo to Ritsuryo
		custom_tooltip = {
			text = ritsuryo_to_soryo_invalid_to_transfer
			NAND = {
				scope:actor ?= { has_government = japan_administrative_government }
				scope:recipient ?= { has_government = japan_administrative_government }
				scope:secondary_actor ?= { has_government = japan_feudal_government }
			}
		}
		custom_tooltip = {
			text = cannot_transfer_bloc_leader_as_vassal_tt
			NOT = {
				scope:secondary_actor ?= {
					exists = house.house_confederation.leading_house
					house.house_confederation.leading_house ?= house
					is_house_head = yes
				}
			}
		}
	}

	can_be_picked = {
		scope:recipient != root
		highest_held_title_tier > tier_barony
		highest_held_title_tier < scope:recipient.highest_held_title_tier

		trigger_if = {
			limit = { scope:actor.liege = scope:recipient }
			custom_tooltip = {
				text = is_de_jure_liege_of_target
				NOT = {
					primary_title = {
						any_this_title_or_de_jure_above = {
							holder = scope:actor
						}
					}
				}
			}
		}

		# You can't give your diarch away as a vassal.
		custom_description = {
			text = cannot_grant_own_diarch_as_vassal
			subject = scope:actor.diarch
			NOT = { root ?= scope:actor.diarch }
		}

		# Not at war with the vassal being transferred (blocks explicit transfer of war enemies, which invalidates the war).
		custom_description = {
			text = "basic_is_at_war_with_vassal"
			subject = root
			object = scope:actor
			NOT = {
				root = {
					is_at_war_with = scope:actor
				}
			}
		}

		# Not at war with a vassal under the vassal being transferred (blocks implicit transfers of war enemies).
		custom_description = {
			text = "basic_is_at_war_with_sub_vassal"
			subject = root
			object = scope:actor
			NOT = {
				any_vassal_or_below = {
					is_at_war_with = root
				}
			}
		}

		# EP3 Admin - You cannot give away noble families
		custom_description = {
			text = admin_cannot_grant_vassal_noble_family
			subject = root
			trigger_if = {
				limit = {
					government_allows = administrative
				}
				any_held_title = {
					is_noble_family_title = no
				}
			}
		}
	}

	auto_accept = {
		scope:recipient = {
			custom_description = {
				text = wants_more_vassals
				is_ai = yes
			}
		}
	}

	on_accept = {
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_good
				title = grant_vassal_interaction_notification
				right_icon = scope:recipient
				left_icon = scope:secondary_actor

				# If we're granting a vassal to our liege, gain a truce with our former vassal (we can't immediately reconquer them, and they can't attack us either).
				if = {
					limit = {
						scope:actor = {
							is_vassal_of = scope:recipient
						}
					}
					add_truce_both_ways = {
						character = scope:secondary_actor
						days = 3650
						name = TRUCE_GRANT_INDEPENDENCE
					}
				}

				# Transfer the vassal over to their new liege.
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change
					add_claim_on_loss = no
				}
				scope:secondary_actor = {
					change_liege = {
						liege = scope:recipient
						change = scope:change
					}
				}
				resolve_title_and_vassal_change = scope:change

				# Gain an opinion bonus with the person we gave a vassal to.
				scope:recipient = {
					add_opinion = {
						target = scope:actor
						modifier = granted_vassal
					}
				}
			}
		}

		# If we're a clan this interaction affects unity
		add_clan_unity_interaction_effect = {
			CHARACTER = scope:actor
			TARGET = scope:recipient
			VALUE = miniscule_unity_gain
			DESC = clan_unity_grant_vassal.desc
			REVERSE_NON_HOUSE_TARGET = yes
		}

		hidden_effect = {
			# Struggle catalyst
#			if = {
#				limit = {
#					fp3_struggle_involves_one_supporter_and_one_detractor = {
#						FIRST = scope:actor
#						SECOND = scope:recipient
#					}
#					scope:actor = {
#						any_character_struggle	 = {
#							involvement = involved
#							phase_has_catalyst = catalyst_grants_vassal_to_de_jure_liege_supporter_detractor
#							is_secondary_character_involvement_involved_trigger = {
#								CHAR = scope:recipient
#							}
#						}
#					}
#					scope:recipient.primary_title = {
#						any_this_title_or_de_jure_above = {
#							holder = scope:secondary_actor
#						}
#					}
#				}
#				scope:actor = {
#					every_character_struggle = {
#						involvement = involved
#						activate_struggle_catalyst = {
#							catalyst = catalyst_grants_vassal_to_de_jure_liege_supporter_detractor
#							character = scope:actor
#						}
#						log_debug_variable_for_persian_struggle_effect = { VAR = concession_catalyst_grants_vassal_to_de_jure_liege_supporter_detractor }
#					}
#				}
#			}
			if = {
				limit = {
					scope:recipient = {
						government_has_flag = government_is_nomadic
					}
				}
				while = {
					limit = {
						scope:secondary_actor ?= {
							any_held_title = {
								vassal_grant_de_jure_shift_trigger = yes
							}
						}
					}
					scope:secondary_actor ?= {
						random_held_title = {
							limit = {
								vassal_grant_de_jure_shift_trigger = yes
							}
							set_de_jure_liege_title = scope:recipient.primary_title
						}
					}
				}
			}
		}
	}

	on_decline = {
		scope:actor = {
			trigger_event = char_interaction.0211
		}

		# If we're a clan this interaction affects unity
		add_clan_unity_interaction_effect = {
			CHARACTER = scope:recipient
			TARGET = scope:actor
			VALUE = miniscule_unity_loss
			DESC = clan_unity_grant_vassal_decline.desc
			REVERSE_NON_HOUSE_TARGET = no
		}
	}

	# AI handled entirely though code
}

retract_vassal_interaction = {
	category = interaction_category_vassal
	special_interaction = retract_vassal_interaction
	interface = transfer_vassal
	ai_maybe = yes
	ai_min_reply_days = 4
	ai_max_reply_days = 9
	popup_on_receive = yes
	pause_on_receive = yes
	icon = icon_liege

	interface_priority = 109 #after revoke title

	desc = retract_vassal_interaction_desc

	on_decline_summary = general_rebellion_decline_summary

	prompt = RETRACT_VASSAL_SELECT_VASSAL_TO_RETRACT

	notification_text = RETRACT_VASSAL_PROPOSAL

	populate_recipient_list = {
		scope:recipient = {
			every_vassal = {
				add_to_list = characters
			}
		}
	}

	is_shown = {
		scope:recipient != scope:actor
		scope:recipient = {
			highest_held_title_tier > tier_barony
			liege = scope:actor
		}
	}

	is_valid_showing_failures_only = {
		vassal_retraction_standard_valid_showing_failures_only_trigger = yes
		# Make sure this exactly matches "can_be_picked" section below
		scope:recipient = {
			custom_description = {
				text = "basic_vassal_to_retract"
				any_vassal = {
					highest_held_title_tier > tier_barony
				}
			}
		}
		# Plus make sure there's a legal right to retract.
		scope:actor = {
			trigger_if = {
				limit = {
					government_has_flag = government_is_tribal
				}
				custom_description = {
					text = "has_law_allowing_vassal_retraction_tribal"
					has_realm_law_flag = vassal_retraction_allowed
				}
			}
			trigger_else_if = {
				limit = {
					government_has_flag = government_is_administrative
				}
				custom_description = {
					text = "has_law_allowing_vassal_retraction_admin"
					has_realm_law_flag = vassal_retraction_allowed
				}
			}
			trigger_else = {
				custom_description = {
					text = "has_law_allowing_vassal_retraction_crown"
					has_realm_law_flag = vassal_retraction_allowed
				}
			}
		}
		scope:recipient = {
			NOT = { has_strong_hook = scope:actor }
		}
		custom_tooltip = {
			text = cannot_take_overt_hostile_actions_against_diarch.tt
			NOT = { scope:recipient ?= scope:actor.diarch }
		}
	}

	can_send = {
		scope:actor = {
			custom_description = {
				text = "character_interactions_hostile_actions_disabled_delay"
				NOT = { has_character_flag = flag_hostile_actions_disabled_delay }
			}
		}
	}

	can_be_picked = {
		highest_held_title_tier > tier_barony
	}

	cost = {
		# Usually, this action is free, but during certain diarchies, we want it to cost.
		prestige = liege_diarchy_surcharge_interaction_retract_vassal_interaction_value
	}

	on_send = {
		scope:actor = {
			add_character_flag = {
				flag = flag_hostile_actions_disabled_delay
				days = 10
			}
		}
		hidden_effect = {
			scope:secondary_recipient = {
				add_character_flag = {
					flag = ai_should_not_transfer
					years = 3
				}
			}
		}
	}

	on_accept = {
		retract_vassal_interaction_effect = yes

		if = {
			limit = {
				scope:actor = { has_character_flag = flag_hostile_actions_disabled_delay }
			}
			scope:actor = { remove_character_flag = flag_hostile_actions_disabled_delay }
		}

		scope:actor = {
			trigger_event = char_interaction.0220
		}
	}

	on_decline = {
		scope:actor = { vassal_revocation_tyranny_effect = yes }
		war_for_retraction_effect = yes
		scope:recipient = {
			add_opinion = {
				target = scope:actor
				modifier = retracted_vassal
			}
		}
		if = {
			limit = {
				scope:actor = { has_realm_law_flag = vassal_refusal_is_treason }
			}
			scope:actor = {
				add_opinion = {
					target = scope:recipient
					modifier = treasonous_retract_refusal
				}
			}
		}
		if = {
			limit = {
				scope:actor = { has_character_flag = flag_hostile_actions_disabled_delay }
			}
			scope:actor = { remove_character_flag = flag_hostile_actions_disabled_delay }
		}
	}

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

	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_accept = {
		base = 0 # Try to make it 0 for most interactions

		modifier = {
			has_game_rule = hard_difficulty
			scope:actor = { is_ai = no }
			add = -50
			desc = FACTION_REASON_DIFFICULTY_HARD
		}

		modifier = {
			has_game_rule = very_hard_difficulty
			scope:actor = { is_ai = no }
			add = -100
			desc = FACTION_REASON_DIFFICULTY_VERY_HARD
		}

		modifier = {
			has_game_rule = hard_difficulty
			scope:actor = { is_ai = yes }
			add = 50
		}

		modifier = {
			has_game_rule = very_hard_difficulty
			scope:actor = { is_ai = yes }
			add = 100
		}

		modifier = {
			scope:hook = yes
			add = 40
			desc = SCHEME_WEAK_HOOK_USED
		}

		opinion_modifier = { # Opinion Factor
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 1.0
			desc = AI_OPINION_REASON
		}

		modifier = {
			add = 25
			scope:actor = {
				has_realm_law_flag = vassal_refusal_is_treason
			}
			desc = AI_REFUSAL_IS_TREASON
		}

		modifier = {
			add = 20
			scope:recipient = {
				has_trait = trusting
			}
			desc = TAKE_THE_VOWS_TRUSTING
		}

		modifier = {
			add = 20
			scope:recipient = {
				has_trait = content
			}
			desc = INTERACTION_CONTENT
		}

		modifier = {
			add = 20
			scope:actor.current_military_strength > scope:recipient.current_military_strength
			scope:recipient = {
				has_trait = craven
			}
			desc = INTERACTION_CRAVEN
		}

		ai_value_modifier = {
			who = scope:recipient
			ai_greed = {
				if = {
					limit = {
						scope:recipient = { NOT = { ai_greed = 0 } }
					}
					value = -0.25
				}
			}
			ai_honor  = {
				if = {
					limit = {
						scope:recipient = { #If AI is honorable and the law compels to obey the liege, AI will be more likely to obey.
							ai_honor > 0
						}
						scope:actor = {
							has_realm_law_flag = vassal_refusal_is_treason
						}
					}
					value = 0.75
				}
			}
		}
		modifier = {
			exists = scope:actor.primary_title.title_capital_county
			scope:secondary_recipient = {
				OR = {
					any_sub_realm_county = {
						this = scope:actor.primary_title.title_capital_county
					}
					any_sub_realm_duchy = {
						this = scope:actor.primary_title.title_capital_county.de_jure_liege
					}
				}
			}
			add = 50
			desc = AI_VASSAL_HOLDS_REALM_CAPITAL
		}

		modifier = {
			exists = scope:actor.primary_title.title_capital_county
			scope:secondary_recipient = {
				NOR = {
					any_sub_realm_county = {
						this = scope:actor.primary_title.title_capital_county
					}
					any_sub_realm_duchy = {
						this = scope:actor.primary_title.title_capital_county.de_jure_liege
					}
				}
				primary_title.tier = tier_county
				any_sub_realm_county = {
					de_jure_liege = scope:actor.primary_title.title_capital_county.de_jure_liege
				}
			}
			add = 30
			desc = AI_VASSAL_IS_IN_CAPITAL_DUCHY
		}

		modifier = { #Sub-Vassal is NOT De jure of current Vassal.
			add = 25
			NOT = {
				scope:recipient = {
					any_held_title = {
						is_de_jure_liege_or_above_target = scope:secondary_recipient.primary_title
					}
				}
			}
			desc = AI_REFUSAL_IS_NOT_DE_JURE_LIEGE
		}
		modifier = { #Sub-Vassal is De jure of liege title.
			add = 15
			scope:actor = {
				any_held_title = {
					this = scope:secondary_recipient.primary_title.de_jure_liege
				}
			}
			desc = AI_REFUSAL_IS_DE_JURE_LIEGE
		}
		modifier = {
			add = intimidated_halved_reason_value
			scope:recipient = {
				has_dread_level_towards = {
					target = scope:actor
					level = 1
				}
			}
			desc = INTIMIDATED_REASON
		}
		modifier = {
			add = cowed_halved_reason_value
			scope:recipient = {
				has_dread_level_towards = {
					target = scope:actor
					level = 2
				}
			}
			desc = COWED_REASON
		}
		modifier = { #Comparative military strength.
			desc = offer_vassalization_interaction_aibehavior_power_tt
			add = {
				value = 1
				subtract = {
					value = scope:recipient.current_military_strength
					divide = { value = scope:actor.current_military_strength min = 1 }
				}
				multiply = 100
			}
		}
		modifier = { #Different faith, no pluralism.
			desc = AI_REFUSAL_SPLITTING_SAME_FAITH_VASSALS
			trigger = {
				scope:actor.faith = scope:secondary_recipient.faith #Will not care as much if the vassal being retracted is of a different faith.
				scope:actor = {
					NOR = { #Of two different faiths AND the potential vassal's faith is not pluralistic.
						faith = scope:recipient.faith
						faith = { has_doctrine = doctrine_pluralism_pluralistic }
					}
				}
			}
			add = {
				value = -25
				if = {
					limit = {
						scope:actor.faith = {
							faith_hostility_level = {
								target = scope:recipient.faith
								value >= faith_hostile_level
							}
						}
					}
					add = -10
				}
				if = {
					limit = {
						scope:actor.faith = {
							faith_hostility_level = {
								target = scope:recipient.faith
								value >= faith_evil_level
							}
						}
					}
					add = -25
				}
			}
		}
		modifier = { # AI Mongols, tyranny wars just delay the inevitable fun!
			scope:actor = {
				is_ai = yes
				OR = {
					has_trait = greatest_of_khans
					has_character_modifier = the_great_khan_modifier
				}
			}
			scope:recipient = {
				is_ai = yes
			}
			add = 500
		}
		modifier = {
			add = -25
			scope:recipient = {
				culture = { has_cultural_parameter = vassals_more_likely_to_refuse_demands }
			}
			desc = VASSALS_REFUSAL_indomitable_azatani
		}
	}

	#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

	can_send_despite_rejection = yes

	# AI
	ai_targets = {
		ai_recipients = vassals
	}
	ai_frequency_by_tier = {
		barony = 0
		county = 0
		duchy = 12
		kingdom = 12
		empire = 12
		hegemony = 12
	}

	ai_potential = {
		has_realm_law_flag = title_revocation_allowed
		primary_title.tier > tier_county
	}

	ai_will_do = {
		base = -1000

		# We want to avoid tyranny unless we've got a good reason
		# And even if we can avoid tyranny we don't want to retract just because we can, so this only gets us to -10
		# Certain characters will retract despite tyranny, if their rationality is sufficiently low
		modifier = {
			scope:actor = {
				OR = {
					has_revoke_title_reason = scope:recipient
					AND = {
						ai_rationality <= very_high_negative_ai_value
						OR = {
							has_trait = lunatic
							has_trait = possessed
							has_trait = arbitrary
						}
					}
				}
			}

			add = 990
		}
		# Always retract preferred capital if you hold the duchy, or the duchy is uncreated
		modifier = {
			years_from_game_start >= 3
			OR = {
				scope:actor = {
					is_at_war = no
					gold > 0
				}
				scope:recipient = {
					is_imprisoned_by = scope:actor
				}
			}
#			scope:actor = { # The HRE doesn't need endless civil wars
#				NOT = {
#					primary_title = title:e_hre
#				}
#			}
			exists = scope:actor.primary_title.title_capital_county
			OR = {
				scope:actor = {
					any_held_title = {
						this = scope:actor.primary_title.title_capital_county.de_jure_liege
					}
				}
				scope:actor.primary_title.title_capital_county.de_jure_liege = {
					is_title_created = no
				}
			}
			scope:secondary_recipient = {
				any_sub_realm_county = {
					this = scope:actor.primary_title.title_capital_county
				}
			}
			NAND = { # Don't retract player vassals tyrannically
				scope:recipient = {
					is_ai = no
				}
				scope:actor = {
					NOT = { has_revoke_title_reason = scope:recipient }
				}
			}
			add = 1100
		}
		# If below domain limit, try to revoke counties in your capital duchy despite tyranny, sometimes
		modifier = {
			years_from_game_start >= 3
			scope:actor = { is_at_war = no }
			scope:actor = { # The HRE doesn't need endless civil wars
				NOT = {
					primary_title = title:e_hre
				}
			}
			scope:actor.domain_size < scope:actor.domain_limit
			scope:actor.primary_title.tier >= tier_kingdom
			trigger_if = {
				limit = {
					scope:actor = {
						domain_size > 3
					}
				}
				scope:actor = {
					NOR = {
						has_trait = generous
						has_trait = just
					}
				}
			}
			exists = scope:actor.primary_title.title_capital_county
			OR = {
				scope:actor.primary_title.title_capital_county.holder = scope:actor # You have your de jure capital already
				NOT = {
					scope:actor.primary_title.title_capital_county.holder.top_liege = scope:actor.top_liege # Or your De Jure capital isn't in your realm
				}
			}
			scope:secondary_recipient = {
				primary_title.tier = tier_county
				any_sub_realm_county = {
					de_jure_liege = scope:actor.primary_title.title_capital_county.de_jure_liege # Under the same Duchy as your capital
				}
			}
			OR = { # And the capital duchy, if it exists at all
				AND = {
					exists = scope:actor.primary_title.title_capital_county.de_jure_liege.holder
					scope:actor.primary_title.title_capital_county.de_jure_liege.holder = scope:actor
				}
				AND = {
					exists = scope:actor.primary_title.title_capital_county.de_jure_liege.holder
					scope:actor.primary_title.title_capital_county.de_jure_liege.holder.top_liege != scope:actor.top_liege
				}
				scope:actor.primary_title.title_capital_county.de_jure_liege = {
					is_title_created = no
				}
			}

			scope:recipient = { # Not from players
				is_ai = yes
			}

			OR = { # Tyranny tolernance is based on rationality
				AND = {
					scope:actor.ai_rationality < 0
					scope:actor.tyranny <= 15 # Don't go crazy with tyranny, just a bit is fine
				}
				AND = {
					scope:actor.ai_rationality >= 0
					scope:actor.ai_rationality < 50
					scope:actor.tyranny <= 5 # Don't go crazy with tyranny, just a bit is fine
				}
				AND = {
					scope:actor.ai_rationality >= 50
					scope:actor.tyranny <= 0 # Don't go crazy with tyranny, just a bit is fine
				}
				AND = {
					scope:actor.ai_rationality >= 0
					scope:recipient = {
						is_imprisoned_by = scope:actor
					}
					scope:actor = { has_revoke_title_reason = scope:recipient }
				}
				AND = {
					scope:actor.ai_rationality < 0
					scope:recipient = {
						is_imprisoned_by = scope:actor
					}
				}
			}
			# To do this, the target must be weak or willing in some way
			OR = {
				scope:actor.current_military_strength > scope:recipient.current_military_strength # Must be stronger
				scope:recipient = {
					is_imprisoned_by = scope:actor
				}
			}
			scope:recipient = {
				OR = {
					has_trait = craven
					has_trait = content
					has_trait = trusting
					has_dread_level_towards = {
						target = scope:actor
						level >= 1
					}
					opinion = { target = scope:actor value >= 40 }
					is_imprisoned_by = scope:actor
					scope:actor = { has_revoke_title_reason = scope:recipient }
				}
			}

			add = 1100
		}
		# Always retract preferred capital duchy
		modifier = {
			exists = scope:actor.primary_title.title_capital_county
			scope:secondary_recipient = {
				any_sub_realm_duchy = {
					this = scope:actor.primary_title.title_capital_county.de_jure_liege
				}
			}
			NAND = { # Don't retract player vassals tyranically
				scope:recipient = {
					is_ai = no
				}
				scope:actor = {
					NOT = { has_revoke_title_reason = scope:recipient }
				}
			}
			add = 1000
		}
		# Retract vassal we're dejure liege of if below domain limit
		modifier = {
			scope:actor = {
				vassal_limit_available > 0
			}
			scope:secondary_recipient.primary_title.de_jure_liege.holder = scope:actor
			add = 500
		}
		# Retract non-De Jure vassals from Megadukes (only if a revoke reason is present, so we don't end up in massive tyranny war spirals)
		modifier = {
			scope:actor = {
				has_revoke_title_reason = scope:recipient
			}
			scope:recipient = {
				primary_title.tier = tier_duchy
				any_sub_realm_county = {
					count > 30
				}
			}
			scope:secondary_recipient.primary_title.de_jure_liege.holder != scope:recipient
			add = 500
		}
		# Do not revoke titles from certain characters
		modifier = {
			scope:actor = {
				OR = {
					has_relation_friend = scope:recipient
					has_relation_best_friend = scope:recipient
					has_relation_lover = scope:recipient
					has_relation_soulmate = scope:recipient
					is_heir_of = scope:recipient
				}
			}
			add = -2000
		}
		# Do not revoke titles when the chance of success if exceedingly low
		modifier = {
			NOT = {
				scope:recipient = {
					is_imprisoned_by = scope:actor
				}
			}
			scope:actor = {
				OR = {
					gold < minimum_ai_gold_value_for_tyranny_wars
					AND = {
						scope:actor.current_military_strength < scope:recipient.current_military_strength
						gold < comfortable_ai_gold_value_for_tyranny_wars
					}
				}
			}
			add = -2000
		}

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

		modifier = { # The AI shouldn't ruin the player's fun
			add = -2000
			scope:recipient = { has_character_flag = is_party_baron }
		}

		modifier = { # Avoid triggering Tyranny wars mid-war
			factor = 0
			scope:actor = {
				is_at_war = yes
			}
			scope:recipient = {
				NOT = {
					is_imprisoned_by = scope:actor
				}
			}
		}

		modifier = { # Avoid triggering Tyranny wars mid-grand activity
			factor = 0
			scope:actor = {
				has_ongoing_grand_activity_trigger = yes
			}
			NOR = {
				scope:recipient = {
					is_imprisoned_by = scope:actor
				}
				scope:recipient = {
					highest_held_title_tier = tier_barony
				}
			}
		}
	}
}

start_independence_faction_interaction = {
	icon = independence
	category = interaction_category_vassal
	desc = start_independence_faction_interaction_desc

	is_shown = {
		scope:actor != scope:recipient
		scope:actor = {
			highest_held_title_tier > tier_barony
			liege = scope:recipient
			is_a_faction_member = no
		}
		scope:recipient = {
			is_landed_or_landless_administrative = no
			NOT = {
				any_targeting_faction = {
					faction_type = independence_faction
				}
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			can_create_faction = {
				target = scope:recipient
				type = independence_faction
			}
		}
	}

	on_accept = {
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = start_independence_faction_interaction_notification

				left_icon = scope:actor
				right_icon = scope:recipient

				create_faction = {
					type = independence_faction
					target = scope:recipient
				}
				if = {
					limit = {
						is_de_jure_vassal_of_liege_trigger = yes
					}
					stress_impact = {
						just = medium_stress_impact_gain
					}
				}
			}
		}
	}

	auto_accept = yes
}

join_independence_faction_interaction = {
	icon = independence
	category = interaction_category_vassal
	desc = join_independence_faction_interaction_desc

	is_shown = {
		scope:actor != scope:recipient
		scope:actor.liege = scope:recipient
		scope:actor = {
			is_landed_or_landless_administrative = no
			is_a_faction_member = no
			highest_held_title_tier > tier_barony
		}
		scope:recipient = {
			highest_held_title_tier > tier_barony
			any_targeting_faction = {
				faction_type = independence_faction
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:recipient = {
			custom_description = {
				text = "basic_independence_faction_at_war"
				object = scope:recipient
				any_targeting_faction = {
					faction_type = independence_faction
					faction_is_at_war = no
				}
			}
		}
		scope:actor = {
			can_join_or_create_faction_against = {
				who = scope:recipient
				faction = independence_faction
			}
		}
	}

	on_accept = {
		scope:recipient = {
			random_targeting_faction = {
				faction_type = independence_faction
				save_scope_as = faction_target
			}
		}

		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = join_independence_faction_interaction_notification

				left_icon = scope:actor
				right_icon = scope:recipient

				join_faction = scope:faction_target
				if = {
					limit = {
						is_de_jure_vassal_of_liege_trigger = yes
					}
					stress_impact = {
						just = minor_stress_impact_gain
					}
				}
			}
		}
	}

	auto_accept = yes
}

create_claimant_faction_against_interaction = {
	icon = vassal_claim_liege_title_interaction
	category = interaction_category_vassal
	interface_priority = 270
	use_diplomatic_range = no
	needs_recipient_to_open = no

	desc = create_claimant_faction_against_interaction_desc

	special_interaction = create_claimant_faction_against_interaction
	interface = create_claimant_faction_against

	is_shown = {
		scope:actor = {
			NOT = { scope:secondary_actor ?= this }
			scope:secondary_actor ?= liege
			custom_description = {
				text = "faction_can_join_create_in_another_faction"
				is_a_faction_member = no
			}
			highest_held_title_tier > tier_barony
		}
	}

	is_valid_showing_failures_only = {
		NOT = {
			scope:actor = { has_truce = scope:secondary_actor }
		}
		scope:secondary_actor = {
			trigger_if = {
				limit = {
					NOT = {
						any_held_title = {
							any_claimant = {}
						}
					}
				}
				custom_description = {
					text = "basic_claimant_found"
					always = no
				}
			}
			trigger_else = {
				custom_description = {
					text = "basic_capable_claimant_found"
					any_held_title = {
						any_claimant = {
							NOT = { has_trait = incapable }
						}
					}
				}
			}
			trigger_if = {
				limit = {
					exists = scope:landed_title
				}
				custom_description = {
					text = "claimant_faction_already_exists"
					subject = scope:landed_title
					object = scope:recipient
					NOT = {
						any_targeting_faction = {
							faction_type = claimant_faction
							special_character = scope:recipient
							special_title = scope:landed_title
						}
					}
				}
			}
		}
		scope:actor = {
			can_join_or_create_faction_against = {
				who = scope:secondary_actor
				faction = claimant_faction
				check_in_a_faction = no # already checked in is_shown. Via the faction interface we'd see this twice if it fails (TIT-11380)
			}
		}
		trigger_if = {
			limit = {
				exists = scope:recipient
			}
			scope:recipient = {
				NOT = { is_at_war_with = scope:actor }
				NOT = { has_trait = incapable }
			}
		}
		scope:secondary_actor = { NOT = { has_strong_hook = scope:actor } }

		# Admin vassals can only start and join a claimant faction if the target is independent
		trigger_if = {
			limit = {
				scope:actor = { government_allows = administrative }
			}
			trigger_if = {
				limit = {
					scope:secondary_actor = { government_allows = administrative }
				}
				scope:secondary_actor = { is_independent_ruler = yes }
			}
		}

		# Under Byzantine law, a ruler must be unblemished
		trigger_if = {
			limit = {
				scope:landed_title.holder.culture ?= { has_cultural_parameter = physical_disfigurement_blocks_inheritance }
			}
			scope:recipient ?= {
				custom_description = {
					text = "byzantine_claimant_is_disfigured"
					object = scope:recipient
					valid_for_byz_succession_trigger = yes
				}
			}
		}
		# Ceremonial Liege
		trigger_if = {
			limit = {
				exists = scope:landed_title
				scope:actor.top_liege.primary_title.var:administrative_ui_special_title ?= scope:landed_title
			}
			scope:recipient = {
				tgp_is_in_ceremonial_house_trigger = yes
				trigger_if = {
					limit = {
						scope:landed_title = {
							holder.faith = { has_doctrine = doctrine_gender_male_dominated }
							any_claimant = { is_male = yes }
						}
					}
					is_male = yes
				}
				trigger_else_if = {
					limit = {
						scope:landed_title = {
							holder.faith = { has_doctrine = doctrine_gender_female_dominated }
							any_claimant = { is_female = yes }
						}
					}
					is_female = yes
				}
				trigger_else = { always = yes }
			}
		}
		# TGP - Use Coup against Kampaku instead
		trigger_if = {
			limit = {
				scope:recipient ?= { tgp_realm_has_ceremonial_liege_trigger = yes }
			}
			custom_tooltip = {
				text = cannot_create_claimant_faction_against_kampaku_tooltip
				scope:recipient ?= {
					# TGP - Use Coup against Kampaku instead
					tgp_is_ceremonial_regent_trigger = no
				}
			}
		}
		# Ministers cannot be claimants unless we are targeting h_china
		trigger_if = {
			limit = {
				exists = scope:recipient
				exists = scope:landed_title
				scope:recipient = {
					tgp_is_any_minister = yes
				}
			}
			scope:recipient = {
				custom_description = {
					text = target_is_a_minister_desc
					subject = this
					any_held_title = {
						tgp_is_minister_title = yes
						de_jure_liege ?= scope:landed_title
					}
				}
			}
		}
	}

	can_send = {
		NOT = {
			scope:recipient ?= { has_title = title:e_japan }
		}
	}

	on_send = {
		scope:actor = {
			set_variable = {
				name = claiming_title
				value = scope:landed_title
			}

			if = {
				limit = {
					can_create_faction = {
						type = claimant_faction
						target = scope:secondary_actor
					}
				}

				create_faction = {
					type = claimant_faction
					target = scope:secondary_actor
				}
				joined_faction = {
					set_special_character = scope:recipient
					set_special_title = scope:landed_title
				}
				scope:recipient = {
					add_to_variable_list = {
						name = claimant_factions
						target = scope:actor.joined_faction
					}
				}

				if = {
					limit = { this != scope:recipient }
					save_scope_as = faction_invite_from
					joined_faction = { save_scope_as = faction }
					scope:secondary_actor = { save_scope_as = faction_target }
					scope:recipient = {
						trigger_event = faction_invitation.0001
					}
				}
			}

			remove_variable = claiming_title
		}
	}

	auto_accept = yes
}

invite_to_council_position_interaction = {
	category = interaction_category_vassal
	popup_on_receive = yes
	pause_on_receive = yes

	hidden = yes

	special_interaction = invite_to_council_interaction
	notification_text = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:recipient = {
						is_councillor_of = scope:actor
					}
				}
				desc = liege_offer_council_position_exchange
			}
			triggered_desc = {
				trigger = {
					scope:actor = {
						opinion = {
							value >= 30
							target = scope:recipient
						}
					}
				}
				desc = liege_offer_council_position_liked
			}
			triggered_desc = {
				trigger = {
					scope:actor = {
						opinion = {
							value <= -30
							target = scope:recipient
						}
					}
				}
				desc = liege_offer_council_position_disliked
			}
			triggered_desc = {
				trigger = {
					scope:recipient = {
						is_powerful_vassal_of = scope:actor
					}
				}
				desc = liege_offer_council_position_powerful
			}
			triggered_desc = {
				trigger = {
					scope:recipient = {
						OR = {
							diplomacy > high_skill_rating
							martial > high_skill_rating
							stewardship > high_skill_rating
							intrigue > high_skill_rating
							learning > high_skill_rating
						}
					}
				}
				desc = liege_offer_council_position_skilled
			}
			desc = liege_offer_council_position_fallback
		}
	}

	is_valid_showing_failures_only = {
		ALL_FALSE = {
			scope:recipient.council_task = scope:target
			scope:actor = { is_at_war_with = scope:recipient }
		}
		trigger_if = {
			limit = {
				exists = scope:target.councillor
			}
			scope:target = { can_fire_position = yes }
			NOT = {
				scope:target.councillor = {
					is_blocked_from_being_fired_from_council_trigger = { COURT_OWNER = scope:actor }
				}
			}
		}
	}

	on_accept = {
		# Assign the councillor to their new responsibilities.
		scope:actor = {
			assign_council_task = {
				target = scope:recipient
				council_task = scope:target
			}
		}

		# If the new councillor is a player, inform their liege that they have accepted the offer.
		if = {
			limit = {
				scope:recipient = {
					is_ai = no
				}
			}
			scope:actor = {
				trigger_event = {
					id = council_interaction.0001
					days = 1
				}
			}
		}
		# If we're a clan this interaction affects unity
		#if = {
		#	limit = { scope:actor = { NOT = { has_character_flag = fp3_consulted_house } } }
		#	add_clan_unity_interaction_effect = {
		#		CHARACTER = scope:actor
		#		TARGET = scope:recipient
		#		VALUE = miniscule_unity_gain
		#		DESC = clan_unity_council_position.desc
		#		REVERSE_NON_HOUSE_TARGET = yes
		#	}
		#}
	}

	on_decline = {
		# If the requested councillor is a player, inform their liege that they have declined the offer.
		if = {
			limit = {
				scope:recipient = {
					is_ai = no
				}
			}
			scope:actor = {
				trigger_event = {
					id = council_interaction.0002
					days = 1
				}
			}
		}
	}

	auto_accept = {
		custom_description = {
			text = auto_accept_interaction_ai
			object = scope:recipient
			scope:recipient = {
				is_ai = yes
			}
		}
	}
}

force_onto_council = {
	category = interaction_category_vassal
	interface_priority = 120
	icon = council

	desc = force_onto_council_desc
	notification_text = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:actor = { has_strong_hook = scope:recipient }
				}
				desc = force_onto_council.notification.strong_hook
			}
			desc = force_onto_council.notification.fallback
		}
	}

	special_interaction = force_onto_council_interaction
	interface = council_task_interaction

	should_use_extra_icon = {
		scope:actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	is_shown = {
		scope:recipient != scope:actor
		scope:actor = {
			liege = scope:recipient
			NOT = {
				is_councillor = yes
			}
			# Merit based realms cannot force themselves onto the council - they should compete with merit and score instead
			NOT = { government_allows = merit }
		}

		trigger_if = {
			limit = {
				exists = scope:target.councillor
			}
			scope:target = { can_fire_position = yes }
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			custom_description = {
				text = "has_usable_hook_or_council_rights_through_vassal_contract"
				subject = scope:actor
				OR = {
					has_usable_hook = scope:recipient
					vassal_contract_has_flag = can_demand_council_seat
					vassal_contract_has_flag = can_demand_kurultai_seat
				}
			}
			is_adult = yes
			NOT = {
				is_at_war_with = scope:recipient
			}
			NAND = {
				has_council_position = councillor_court_chaplain
				faith = {
					has_doctrine_parameter = clerical_appointment_fixed
				}
			}
		}
	}

	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 = {
			if = {
				limit = {
					NOR = {
						vassal_contract_has_flag = can_demand_council_seat
						vassal_contract_has_flag = can_demand_kurultai_seat
					}
				}
				save_scope_value_as = {
					name = used_hook
					value = yes
				}
			}
			block_firing_councillor_effect = { COURT_OWNER = scope:recipient }
			#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
				}
			}
			stress_impact = { content = minor_stress_impact_gain }
		}
		scope:recipient = {
			assign_council_task = {
				target = scope:actor
				council_task = scope:council_task
			}
			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
					if = {
						limit = { exists = scope:used_hook }
						show_as_tooltip = { scope:actor = { use_hook = scope:recipient } }
					}
					custom_tooltip = force_onto_council.recipient.tt.duration
				}
			}
		}
		#Done in the end so that all tooltips will show correct information
		scope:actor = {
			if = {
				limit = {
					exists = scope:used_hook
				}
				use_hook = scope:recipient
			}
		}

		# If we're a clan this interaction affects unity
		add_clan_unity_interaction_effect = {
			CHARACTER = scope:actor
			TARGET = scope:recipient
			VALUE = medium_unity_loss
			DESC = clan_unity_forced_unto_council.desc
			REVERSE_NON_HOUSE_TARGET = no
		}
	}

	ai_set_target = {
		scope:actor = {
			random_list = {
				10 = {
					trigger = {
						exists = scope:recipient.council_task:councillor_chancellor
						can_be_chancellor_trigger = { COURT_OWNER = scope:recipient }
						scope:recipient = {
							NOT = { vassal_contract_has_flag = can_demand_kurultai_seat }
						}
					}
					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 }
						scope:recipient = {
							NOT = { vassal_contract_has_flag = can_demand_kurultai_seat }
						}
					}
					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 }
						scope:recipient = {
							NOT = { vassal_contract_has_flag = can_demand_kurultai_seat }
						}
					}
					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 }
						scope:recipient = {
							NOT = { vassal_contract_has_flag = can_demand_kurultai_seat }
						}
					}
					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 }
						scope:recipient = {
							NOT = { vassal_contract_has_flag = can_demand_kurultai_seat }
						}
					}
					modifier = {
						factor = learning
					}
					modifier = {
						trigger = { highest_skill = learning }
						factor = 10
					}
					scope:recipient.council_task:councillor_court_chaplain = {
						save_scope_as = target
					}
				}
				# Kurultai Demanded
				10 = {
					trigger = {
						exists = scope:recipient.council_task:councillor_kurultai_1
						can_be_kurultai_trigger = {
							COURT_OWNER = scope:actor.liege_or_court_owner
							CP1 = councillor_kurultai_2
							CP2 = councillor_kurultai_3
							CP3 = councillor_kurultai_4
						}
						scope:recipient = {
							NOT = { vassal_contract_has_flag = can_demand_council_seat }
						}
					}
					modifier = {
						factor = martial
					}
					modifier = {
						trigger = { highest_skill = martial }
						factor = 10
					}
					scope:recipient.council_task:councillor_kurultai_1 = {
						save_scope_as = target
					}
				}
				# Repeated so they don't always demand the same position
				10 = {
					trigger = {
						exists = scope:recipient.council_task:councillor_kurultai_2
						can_be_kurultai_trigger = {
							COURT_OWNER = scope:actor.liege_or_court_owner
							CP1 = councillor_kurultai_1
							CP2 = councillor_kurultai_3
							CP3 = councillor_kurultai_4
						}
						scope:recipient = {
							NOT = { vassal_contract_has_flag = can_demand_council_seat }
						}
					}
					modifier = {
						factor = martial
					}
					modifier = {
						trigger = { highest_skill = martial }
						factor = 10
					}
					scope:recipient.council_task:councillor_kurultai_2 = {
						save_scope_as = target
					}
				}
				10 = {
					trigger = {
						exists = scope:recipient.council_task:councillor_kurultai_3
						can_be_kurultai_trigger = {
							COURT_OWNER = scope:actor.liege_or_court_owner
							CP1 = councillor_kurultai_1
							CP2 = councillor_kurultai_2
							CP3 = councillor_kurultai_4
						}
						scope:recipient = {
							NOT = { vassal_contract_has_flag = can_demand_council_seat }
						}
					}
					modifier = {
						factor = martial
					}
					modifier = {
						trigger = { highest_skill = martial }
						factor = 10
					}
					scope:recipient.council_task:councillor_kurultai_3 = {
						save_scope_as = target
					}
				}
				10 = {
					trigger = {
						exists = scope:recipient.council_task:councillor_kurultai_4
						can_be_kurultai_trigger = {
							COURT_OWNER = scope:actor.liege_or_court_owner
							CP1 = councillor_kurultai_1
							CP2 = councillor_kurultai_2
							CP3 = councillor_kurultai_3
						}
						scope:recipient = {
							NOT = { vassal_contract_has_flag = can_demand_council_seat }
						}
					}
					modifier = {
						factor = martial
					}
					modifier = {
						trigger = { highest_skill = martial }
						factor = 10
					}
					scope:recipient.council_task:councillor_kurultai_4 = {
						save_scope_as = target
					}
				}
			}
		}
	}

	ai_potential = {
		top_liege != this
		is_councillor = no
	}

	ai_targets = {
		ai_recipients = liege
	}
	ai_frequency_by_tier = {
		barony = 0
		county = 48
		duchy = 36
		kingdom = 24
		empire = 24
		hegemony = 0
	}

	auto_accept = yes
	force_notification = yes

	ai_will_do = {
		base = 100

		modifier = {
			factor = 0
			scope:actor = {
				ai_greed <= medium_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
				}
			}
		}

		modifier = {
			factor = 0
			is_councillor = yes
		}
	}
}

stop_attacker_vassal_war_interaction = {
	category = interaction_category_vassal
	interface = interfere_in_war
	special_interaction = interfere_in_war_interaction
	ai_accept_negotiation = yes
	popup_on_receive = yes
	pause_on_receive = yes
	icon = icon_retreat

	send_name = "stop_attacker_vassal_war_interaction"

	ai_maybe = yes

	prompt = STOP_VASSAL_WAR_ATTACKER

	desc = {
		desc = stop_vassal_war_negotiation
		triggered_desc = {
			trigger = { scope:actor = { has_usable_hook = scope:recipient } }
			desc = stop_vassal_war_use_hook
		}
		desc = might_ask_for_something_in_return_warning_double_line_break
	}

	on_decline_summary = stop_attacker_vassal_war_decline_summary

	is_shown = {
		scope:recipient != scope:actor
		scope:recipient = {
			liege ?= scope:actor
			highest_held_title_tier > tier_barony
			any_character_war = {
				primary_attacker = scope:recipient
				save_temporary_scope_as = target_war
			}
		}
		scope:actor = {
			NOT = { is_participant_in_war = scope:target_war }
		}
	}

	is_valid_showing_failures_only = {
		custom_description = {
			text = cannot_stop_war_when_already_fighting
			object = scope:recipient
			scope:recipient = {
				NOT = {
					any_war_enemy = {
						this = scope:actor
					}
				}
			}
		}
		custom_description = {
			text = cannot_stop_war_timer
			object = scope:recipient
			NOT = {
				scope:recipient = {
					has_opinion_modifier = {
						target = scope:actor
						modifier = attempt_to_force_end_war_opinion
					}
				}
			}
		}
		NOT = {
			scope:recipient = {
				has_strong_hook = scope:actor
			}
		}
	}

	can_be_picked = {
		scope:target.primary_attacker = scope:recipient
	}

	on_accept = {
		scope:recipient = {
			add_opinion = {
				modifier = attempt_to_force_end_war_opinion
				target = scope:actor
			}
		}
		hidden_effect = {
			scope:recipient = {
				trigger_event = vassal_interaction.0001 #Starts "negotiations"
			}
		}
		show_as_tooltip = {
			scope:target ?= { end_war = white_peace }
		}

		# If we're a clan this interaction affects unity - But we only show it in the tooltip, actual effect is applied in the respective follow-up events
		show_as_tooltip = {
			if = {
				limit = { # If we are asking a non-house member to stop attacking a house member, gain unity
					exists = scope:recipient.house
					exists = scope:actor.house
					scope:recipient.house != scope:actor.house
				}
				add_clan_unity_interaction_effect = {
					CHARACTER = scope:actor
					TARGET = scope:target.primary_defender
					VALUE = medium_unity_gain
					DESC = clan_unity_aided_in_war.desc
					REVERSE_NON_HOUSE_TARGET = no
				}
			}
			else_if = {
				limit = { # If we are asking a house member to stop attacking a non-house member, lose unity
					exists = scope:actor.house
					exists = scope:target.primary_defender.house
					scope:target.primary_defender.house != scope:actor.house
				}
				add_clan_unity_interaction_effect = {
					CHARACTER = scope:actor
					TARGET = scope:recipient
					VALUE = medium_unity_loss
					DESC = clan_unity_stopped_vassal_war.desc
					REVERSE_NON_HOUSE_TARGET = no
				}
			}
		}
	}

	on_decline = {
		show_as_tooltip = {
			scope:recipient = {
				add_opinion = {
					modifier = attempt_to_force_end_war_opinion
					target = scope:actor
				}
			}
			scope:actor = { add_prestige = minor_prestige_loss }
		}
	}

	auto_accept = yes
}

stop_defender_vassal_war_interaction = {
	category = interaction_category_vassal
	interface = interfere_in_war
	special_interaction = interfere_in_war_interaction
	ai_accept_negotiation = yes
	popup_on_receive = yes
	pause_on_receive = yes
	send_name = "SEND_DEMAND"
	icon = icon_retreat

	ai_maybe = yes

	prompt = STOP_VASSAL_WAR_DEFENDER

	desc = {
		desc = stop_vassal_war_negotiation
		triggered_desc = {
			trigger = { scope:actor = { has_usable_hook = scope:recipient } }
			desc = stop_vassal_war_use_hook
		}
		desc = might_ask_for_something_in_return_warning_double_line_break
	}

	on_decline_summary = stop_attacker_vassal_war_decline_summary

	is_shown = {
		scope:recipient != scope:actor
		scope:recipient = {
			liege ?= scope:actor
			highest_held_title_tier > tier_barony
			any_character_war = {
				primary_defender = scope:recipient
				save_temporary_scope_as = target_war
			}
		}
		scope:actor = {
			NOT = { is_participant_in_war = scope:target_war }
		}
	}

	is_valid_showing_failures_only = {
		custom_description = {
			text = cannot_stop_war_when_already_fighting
			object = scope:recipient
			NOT = {
				scope:recipient = {
					any_war_enemy = {
						this = scope:actor
					}
				}
			}
		}
		custom_description = {
			text = cannot_stop_war_timer
			object = scope:recipient
			NOT = {
				scope:recipient = {
					has_opinion_modifier = {
						target = scope:actor
						modifier = attempt_to_force_surrender_opinion
					}
				}
			}
		}
		NOT = {
			scope:recipient = {
				has_strong_hook = scope:actor
			}
		}
	}

	can_be_picked = {
		scope:target.primary_defender = scope:recipient
	}

	on_accept = {
		scope:recipient = {
			add_opinion = {
				modifier = attempt_to_force_surrender_opinion
				target = scope:actor
			}
		}
		hidden_effect = {
			scope:recipient = {
				trigger_event = vassal_interaction.0011 #Starts "negotiations"
			}
		}

		# If we're a clan this interaction affects unity - But we only show it in the tooltip, actual effect is applied in the respective follow-up events
		show_as_tooltip = {
			if = {
				limit = { # If recipient is a house member and the attacker is not, lose unity
					exists = scope:actor.house
					exists = scope:target.primary_attacker.house
					scope:target.primary_attacker.house != scope:actor.house
				}
				add_clan_unity_interaction_effect = {
					CHARACTER = scope:actor
					TARGET = scope:recipient
					VALUE = medium_unity_loss
					DESC = clan_unity_stop_defender_vassal_war.desc
					REVERSE_NON_HOUSE_TARGET = no
				}
			}
			else_if = {
				limit = { # If recipient is a non-house member and the attacker is, gain unity
					exists = scope:actor.house
					exists = scope:recipient.house
					scope:recipient.house != scope:actor.house
				}
				add_clan_unity_interaction_effect = {
					CHARACTER = scope:actor
					TARGET = scope:target.primary_attacker
					VALUE = medium_unity_gain
					DESC = clan_unity_aided_in_war.desc
					REVERSE_NON_HOUSE_TARGET = no
				}
			}
		}
	}

	auto_accept = yes
}

ask_for_pardon_interaction = {
	category = interaction_category_vassal
	icon = scroll_scales

	filter_tags = { celestial_ministry }

	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:actor.top_liege != scope:recipient
				}
				desc = ask_for_pardon_interaction_minister_desc
			}
			desc = ask_for_pardon_interaction_desc
		}
	}
	notification_text = ASK_FOR_PARDON_NOTIFICATION

	is_shown = {
		ask_for_pardon_available_trigger = { ACTOR = scope:actor }
		OR = {
			scope:actor.top_liege = scope:recipient
			scope:recipient = {
				top_liege = scope:actor.top_liege
				has_title = title:e_minister_of_justice
			}
		}
	}


	is_valid_showing_failures_only = {
		scope:actor = {
			NOT = { is_at_war_with = scope:recipient }
			NOT = { is_imprisoned_by = scope:recipient }#Then you use the regular ransom interactions
		}
	}

	highlighted_reason = {
		triggered_desc = {
			trigger = {
				scope:recipient = {
					has_title = title:e_minister_of_justice
				}
			}
			desc = HIGHLIGHTED_MINISTER_WILLING_TO_PARDON
		}
	}

	is_highlighted = {
		OR = {
			scope:actor = {
				has_usable_hook = scope:recipient
			}
			AND = {
				scope:recipient = {
					has_title = title:e_minister_of_justice
				}
				scope:recipient = {
					is_character_interaction_potentially_accepted = {
						recipient = scope:recipient
						interaction = ask_for_pardon_interaction
					}
				}
			}
		}
	}

	ai_accept = {
		base = -50

		#How bad is it, really?
		modifier = {
			scope:recipient = {
				has_banish_reason = scope:actor
				NOR = { #These are worse
					has_execute_reason = scope:actor
					has_revoke_title_reason = scope:actor
				}
			}
			desc = AI_BANISHMENT_REASON_MODIFIER
			add = -20
		}
		modifier = {
			scope:recipient = {
				has_revoke_title_reason = scope:actor
				NOT = { #This is worse are worse
					has_execute_reason = scope:actor
				}
			}
			desc = AI_REVOKE_TITLE_REASON_MODIFIER
			add = -30
		}
		modifier = {
			scope:recipient = {
				has_execute_reason = scope:actor
			}
			desc = AI_EXECUTE_REASON_MODIFIER
			add = -40
		}

		#Willing to forgive
		opinion_modifier = {
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 1
			desc = AI_OPINION_REASON
		}
	}

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

	ai_min_reply_days = 1
	ai_max_reply_days = 5

	on_accept = {
		ask_for_pardon_interaction_effect = yes
		scope:actor = {
			trigger_event = vassal_interaction.0030
		}

		scope:recipient = {
			if = {
				limit = {
					culture = {
						has_cultural_parameter = pardoning_gives_prestige
					}
				}
				add_prestige = minor_prestige_gain
			}
 			add_merit_if_relevant_effect = {
 				MERIT = minor_merit_value
 			}
		}

		# If we're a clan this interaction affects unity
		add_clan_unity_interaction_effect = {
			CHARACTER = scope:actor
			TARGET = scope:recipient
			VALUE = minor_unity_gain
			DESC = clan_unity_pardon_granted.desc
			REVERSE_NON_HOUSE_TARGET = no
		}

		hidden_effect = {
			# Struggle catalysts
#			if = {
#				limit = {
#					fp3_struggle_involves_one_supporter_and_one_detractor = {
#						FIRST = scope:actor
#						SECOND = scope:recipient
#					}
#					scope:recipient = {
#						any_character_struggle	 = {
#							involvement = involved
#							phase_has_catalyst = catalyst_grants_pardon_supporter_detractor
#							is_secondary_character_involvement_involved_trigger = {
#								CHAR = scope:actor
#							}
#						}
#					}
#				}
#				scope:recipient = {
#					every_character_struggle = {
#						involvement = involved
#						activate_struggle_catalyst = {
#							catalyst = catalyst_grants_pardon_supporter_detractor
#							character = scope:recipient
#						}
#						log_debug_variable_for_persian_struggle_effect = { VAR = concession_catalyst_grants_pardon_supporter_detractor }
#					}
#				}
#			}
		}
	}

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

	on_decline = {
		scope:recipient = {
			send_interface_toast = {
				type = event_toast_effect_bad
				title = ask_for_pardon_interaction_decline_toast
				left_icon = scope:actor

				custom_tooltip = ask_for_pardon_interaction_accept_decline
			}
		}

		# If we're a clan this interaction affects unity
		add_clan_unity_interaction_effect = {
			CHARACTER = scope:recipient
			TARGET = scope:actor
			VALUE = minor_unity_loss
			DESC = clan_unity_refused_pardon.desc
			REVERSE_NON_HOUSE_TARGET = no
		}
	}

	#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_targets = {
		ai_recipients = liege
	}
	ai_frequency_by_tier = {
		barony = 0
		county = 24
		duchy = 12
		kingdom = 12
		empire = 12
		hegemony = 0
	}

	ai_will_do = {
		base = 0

		modifier = {
			add = 100
			scope:actor = {
				has_usable_hook = scope:recipient
			}
		}

		modifier = {
			add = 100
			scope:hook = yes
		}
	}
}

pardon_interaction = {
	category = interaction_category_friendly
	icon = scroll_scales

	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:actor != scope:recipient.liege
				}
				desc = pardon_interaction_minister_desc
			}
			desc = pardon_interaction_desc
		}
		triggered_desc = {
			trigger = {
				scope:actor = {
					culture = {
						has_cultural_parameter = pardoning_gives_prestige
					}
				}
			}
			desc = pardon_interaction_has_jirga_desc
		}
	}
	is_shown = {
		scope:actor = {
			OR = {
				has_imprisonment_reason = scope:recipient
				AND = {
					has_title = title:e_minister_of_justice
					scope:recipient = {
						any_liege_or_above = {
							has_imprisonment_reason = scope:recipient
						}
					}
				}
			}
		}
		scope:recipient = {
			OR = {
				scope:actor = {
					has_title = title:e_minister_of_justice
					top_liege = scope:recipient.top_liege
				}
				target_is_liege_or_above = scope:actor
			}
		}
	}
	cost = {
		influence = {
			value = 0
			if = {
				limit = {
					scope:actor = {
						has_title = title:e_minister_of_justice
						NOT = { has_imprisonment_reason = scope:recipient }
					}
				}
				add = {
					value = 25
					if = {
						limit = {
							scope:actor.top_liege = {
								has_realm_law = celestial_bureaucracy_0
							}
						}
						add = 75
					}
					else_if = {
						limit = {
							scope:actor.top_liege = {
								has_realm_law = celestial_bureaucracy_1
							}
						}
						add = 50
					}
					else_if = {
						limit = {
							scope:actor.top_liege = {
								has_realm_law = celestial_bureaucracy_2
							}
						}
						add = 25
					}
				}
			}
		}
		treasury = {
			value = 0
			if = {
				limit = {
					scope:actor = {
						has_title = title:e_minister_of_justice
						has_treasury = yes
						NOT = { has_imprisonment_reason = scope:recipient }
					}
				}
				add = scope:actor.minor_treasury_value
			}
		}
	}

	auto_accept = yes

	is_highlighted = {
		scope:recipient = {
			is_imprisoned = no
		}
		scope:actor = {
			has_title = title:e_minister_of_justice
		}
	}

	on_accept = {
		if = {
			limit = {
				scope:actor = {
					has_title = title:e_minister_of_justice
				}
			}
			scope:actor = {
	 			add_merit_if_relevant_effect = {
	 				MERIT = minor_merit_value
	 			}
				if = {
					limit = {
						government_has_flag = government_has_influence
					}
					change_influence = {
						value = minor_influence_gain
						multiply = scope:recipient.highest_held_title_tier
					}
				}
			}
			scope:recipient = {
				send_interface_toast = {
					type = event_toast_effect_neutral
					title = pardon_interaction_toast_title
					desc = pardon_interaction_toast_minister
					right_icon = scope:actor
					if = {
						limit = {
							OR = {
								scope:recipient.liege = {
									has_extra_criminal_reason_against_trigger = {
										CRIMINAL = scope:recipient
									}
								}
								is_close_or_extended_family_of = scope:actor
							}
						}
						scope:actor = {
							change_strife_opinion = massive_strife_gain
							situation:dynastic_cycle = {
								trigger_situation_catalyst = {
									catalyst = catalyst_minister_pardoned_dangerous_criminal
									character = scope:actor
								}
							}
						}
					}
					consume_all_criminal_reasons_effect = {
						LIEGE = scope:recipient.liege
						CRIMINAL = scope:recipient
					}
	            }
            }
            hidden_effect = {
				scope:recipient.liege = {
					send_interface_toast = {
						type = event_toast_effect_neutral
						title = pardon_interaction_toast_title
						desc = pardon_interaction_toast_minister_liege
						right_icon = scope:actor
						left_icon = scope:recipient
						show_as_tooltip = {
							if = {
								limit = {
									OR = {
										has_extra_criminal_reason_against_trigger = {
											CRIMINAL = scope:recipient
										}
										scope:recipient = {
											is_close_or_extended_family_of = scope:actor
										}
									}
								}
								scope:actor = {
									change_strife_opinion = massive_strife_gain
									situation:dynastic_cycle = {
										trigger_situation_catalyst = {
											catalyst = catalyst_minister_pardoned_dangerous_criminal
											character = scope:actor
										}
									}
								}
							}
							consume_all_criminal_reasons_effect = {
								LIEGE = scope:recipient.liege
								CRIMINAL = scope:recipient
							}
		            	}
		            }
		        }
	        }
		}
		else = {
			scope:recipient = {
				send_interface_toast = {
					type = event_toast_effect_neutral
					title = pardon_interaction_toast_title
					desc = pardon_interaction_toast
					right_icon = scope:actor
					consume_all_criminal_reasons_effect = {
						LIEGE = scope:actor
						CRIMINAL = scope:recipient
					}
	            }
            }
		}

		scope:actor = {
			stress_impact = {
				forgiving =  medium_stress_loss
			}
		}

		scope:actor = {
			if = {
				limit = {
					culture = {
						has_cultural_parameter = pardoning_gives_prestige
					}
				}
				add_prestige = minor_prestige_gain
			}

			hidden_effect = {
			# Struggle catalysts
#				if = {
#					limit = {
#						fp3_struggle_involves_one_supporter_and_one_detractor = {
#							FIRST = scope:actor
#							SECOND = scope:recipient
#						}
#						scope:recipient = {
#							any_character_struggle	 = {
#								involvement = involved
#								phase_has_catalyst = catalyst_grants_pardon_supporter_detractor
#								is_secondary_character_involvement_involved_trigger = {
#									CHAR = scope:actor
#								}
#							}
#						}
#					}
#					every_character_struggle = {
#						involvement = involved
#						activate_struggle_catalyst = {
#							catalyst = catalyst_grants_pardon_supporter_detractor
#							character = scope:recipient
#						}
#						log_debug_variable_for_persian_struggle_effect = { VAR = concession_catalyst_grants_pardon_supporter_detractor }
#					}
#				}
			}
		}

		scope:recipient = {
			if = {
				limit = {
					scope:actor = {
						culture = {
							has_cultural_parameter = pardoning_gives_loyalty
						}
					}
				}
				add_opinion = {
					modifier = loyal_servant
					target = scope:actor
				}
				scope:actor = {
					if = {
						limit = {
							can_add_hook = {
								target = scope:recipient
								type = loyalty_hook
							}
						}
						add_hook = {
							type = loyalty_hook
							target = scope:recipient
						}
					}
				}
			}
			else = {
				add_opinion = {
					target = scope:actor
					modifier = grateful_opinion
					opinion = 15
				}
			}
		}

		# If we're a clan this interaction affects unity
		add_clan_unity_interaction_effect = {
			CHARACTER = scope:actor
			TARGET = scope:recipient
			VALUE = minor_unity_gain
			DESC = clan_unity_forgiveness.desc
			REVERSE_NON_HOUSE_TARGET = no
		}
	}

	ai_potential = {
		OR = {
			ai_vengefulness <= 0
			culture = {
				has_cultural_parameter = pardoning_gives_loyalty
			}
		}
	}
	ai_targets = {
		ai_recipients = vassals
	}
	ai_targets = {
		ai_recipients = courtiers
		chance = 0.25
	}
	ai_frequency_by_tier = {
		barony = 0
		county = 144
		duchy = 72
		kingdom = 36
		empire = 36
		hegemony = 36
	}
	ai_will_do = {
		base = 0

		modifier = {
			add = 100
			scope:recipient = {
				OR = {
					has_relation_friend = scope:actor
					has_relation_best_friend = scope:actor
					has_relation_lover = scope:actor
					has_relation_soulmate = scope:actor
					is_primary_heir_of = scope:actor
				}
			}
		}

		modifier = {
			add = 25
			scope:actor = {
				scope:actor.ai_vengefulness <= 0
				culture = {
					has_cultural_parameter = pardoning_gives_loyalty
				}
			}
		}

		modifier = {
			add = {
				value = ai_vengefulness
				multiply = -1
			}
			scope:actor.ai_vengefulness <= -25
		}
	}
}

vassal_claim_liege_title_interaction = {
	category = interaction_category_vassal
	interface_priority = 269 # after Start Claimant Faction
	desc = vassal_claim_liege_title_interaction_desc
	target_type = title
	target_filter = recipient_domain_titles
	ignores_pending_interaction_block = yes
	icon = vassal_claim_liege_title_interaction

	cost = {
		prestige = {
			value = {
				add = monumental_prestige_value
				if = {
					limit = {
						scope:actor.prestige_level > scope:recipient.prestige_level
					}
					subtract = {
						value = major_prestige_value
						multiply = {
							value = scope:actor.prestige_level
							subtract = scope:recipient.prestige_level
						}
						desc = higher_prestige_level_than_liege
					}
				}
				else_if = {
					limit = {
						scope:actor.prestige_level < scope:recipient.prestige_level
					}
					add = {
						value = major_prestige_value
						multiply = {
							value = scope:recipient.prestige_level
							subtract = scope:actor.prestige_level
						}
						desc = lower_prestige_level_than_liege
					}
				}
				min = 0
			}
		}
	}

	is_shown = {
		scope:recipient != scope:actor

		scope:actor = {
			is_physically_able_adult = yes
		}

		scope:recipient = scope:actor.liege

		scope:recipient = {
			is_playable_character = yes
			any_held_title = {
				title_tier >= duchy
				NOR = {
					has_title_law = noble_family_succession_law
					has_title_law = landless_adventurer_succession_law
					has_title_law = mandala_succession_law
				}
				scope:actor = {
					NOT = {
						has_claim_on = prev
					}
				}
			}
		}
	}

	is_highlighted = {
		scope:actor.prestige >= vassal_claim_liege_title_interaction_highlight_value
	}

	can_be_picked = {
#		trigger_if = {
#			limit = {
#				scope:actor = {
#					any_character_struggle = {
#						involvement = involved
#						has_struggle_phase_parameter = powerful_vassal_can_claim_liege_titles
#					}
#				}
#			}
#			scope:actor = { is_powerful_vassal_of = scope:recipient }
#		}
		trigger_if = {
			limit = {
				scope:actor = { legitimacy_level = 5 }
			}
			scope:target = {
				tier >= tier_duchy
				custom_description = {
					text = has_15_percent_of_a_dejure_title
					any_in_de_jure_hierarchy = {
						filter = {
							tier = tier_county
						}
						continue = {
							tier > tier_county
						}
						OR = {
							holder = scope:actor
							holder = {
								target_is_liege_or_above = scope:actor
							}
						}
						percent >= 0.15
					}
				}
			}
		}
		trigger_if = {
			limit = {
				scope:actor = { legitimacy_level = 4 }
			}
			scope:target = {
				tier >= tier_duchy
				custom_description = {
					text = has_21_percent_of_a_dejure_title
					any_in_de_jure_hierarchy = {
						filter = {
							tier = tier_county
						}
						continue = {
							tier > tier_county
						}
						OR = {
							holder = scope:actor
							holder = {
								target_is_liege_or_above = scope:actor
							}
						}
						percent >= 0.21
					}
				}
			}
		}
		trigger_if = {
			limit = {
				scope:actor = { legitimacy_level = 3 }
			}
			scope:target = {
				tier >= tier_duchy
				custom_description = {
					text = has_31_percent_of_a_dejure_title
					any_in_de_jure_hierarchy = {
						filter = {
							tier = tier_county
						}
						continue = {
							tier > tier_county
						}
						OR = {
							holder = scope:actor
							holder = {
								target_is_liege_or_above = scope:actor
							}
						}
						percent >= 0.31
					}
				}
			}
		}
		trigger_if = {
			limit = {
				scope:actor = { legitimacy_level = 2 }
			}
			scope:target = {
				tier >= tier_duchy
				custom_description = {
					text = has_41_percent_of_a_dejure_title
					any_in_de_jure_hierarchy = {
						filter = {
							tier = tier_county
						}
						continue = {
							tier > tier_county
						}
						OR = {
							holder = scope:actor
							holder = {
								target_is_liege_or_above = scope:actor
							}
						}
						percent >= 0.41
					}
				}
			}
		}
		trigger_if = {
			limit = {
				scope:actor = {
					OR = {
						legitimacy_level = 1
						legitimacy_level = 0
						has_legitimacy = no #if you don't have legitimacy at all we fall back to the default
					}
				}
			}
			scope:target = {
				tier >= tier_duchy
				custom_description = {
					text = has_51_percent_of_a_dejure_title
					any_in_de_jure_hierarchy = {
						filter = {
							tier = tier_county
						}
						continue = {
							tier > tier_county
						}
						OR = {
							holder = scope:actor
							holder = {
								target_is_liege_or_above = scope:actor
							}
						}
						percent >= 0.51
					}
				}
			}
		}

		custom_description = {
			NOT = {
				scope:actor = {
					has_claim_on = scope:target
				}
			}
			text = "already_have_a_claim_on_this_title"
		}
		trigger_if = {
			limit = {
				scope:target = {
					tier = tier_duchy
				}
			}
			custom_description = {
				text = not_family_or_adventurer_title
				scope:target = {
					NOR = {
						has_title_law = noble_family_succession_law
						has_title_law = landless_adventurer_succession_law
						has_title_law = mandala_succession_law
					}
				}
			}
		}
	}

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

	is_valid_showing_failures_only = {
		custom_description = {
			scope:recipient = {
				any_held_title = {
					title_tier >= county
					NOT = { any_claimant = { this = scope:actor } }
				}
			}

			object = scope:recipient
			text = "already_have_claims_on_all_titles"
		}
		scope:recipient = { NOT = { has_strong_hook = scope:actor } }
		NOT = {
			scope:actor = {
				is_allied_to = scope:recipient
			}
		}
	}

	on_auto_accept = {
		scope:target = {
			random_in_de_jure_hierarchy = {
				limit = {
					tier = tier_county
					OR = {
						holder = scope:actor
						holder = {
							target_is_liege_or_above = scope:actor
						}
					}
				}
				title_province = {
					save_scope_as = county_in_title
				}
			}
		}
		scope:recipient = {
			trigger_event = vassal_interaction.0040
		}
	}

	on_accept = {
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_good
				title = buy_claim_interaction.message
				left_icon = scope:actor
				right_icon = scope:recipient
				vassal_claim_liege_title_interaction_effect = yes
			}
			claim_title_achievement_effect = yes
		}

		# If we're a clan this interaction affects unity
		add_clan_unity_interaction_effect = {
			CHARACTER = scope:actor
			TARGET = scope:recipient
			VALUE = major_unity_loss
			DESC = clan_unity_title_claim.desc
			REVERSE_NON_HOUSE_TARGET = no
		}
	}

	auto_accept = yes

	ai_targets = {
		ai_recipients = liege
	}
	ai_frequency_by_tier = {
		barony = 0
		county = 48
		duchy = 24
		kingdom = 24
		empire = 24
		hegemony = 0
	}

	ai_potential = {
		domain_size > 1
		NOR = {
			has_trait = content
			has_trait = craven
		}
	}

	ai_will_do = {
		base = 25

		ai_value_modifier = {
			who = scope:actor
			ai_greed = 1
			ai_boldness = 0.5
			ai_honor = -0.5
		}

		modifier = {
			add = scope:actor.ai_zeal
			scope:actor = {
				ai_zeal > 0
			}
			scope:actor.faith != scope:recipient.faith
		}

		modifier = {
			add = 25
			scope:actor = {
				is_powerful_vassal_of = scope:recipient
			}
		}

		modifier = {
			add = 50
			scope:actor = {
				opinion = {
					target = scope:recipient
					value <= 0
				}
			}
		}

		modifier = {
			add = 25
			scope:recipient = {
				OR = {
					has_relation_rival = scope:actor
					has_relation_nemesis = scope:actor
				}
			}
		}

		modifier = {
			add = -15
			scope:recipient = {
				has_relation_lover = scope:actor
			}
		}

		# Agenda impact
#		modifier = {
#			scope:actor = {
#				any_character_struggle = {
#					involvement = involved
#					is_struggle_type = iberian_struggle
#				}
#			}
#			add = {
#				value = 0
#				if = {
#					limit = {
#						scope:actor = {
#							any_character_struggle = {
#								phase_has_catalyst = catalyst_gain_claim_on_title_fp2
#							}
#							has_character_flag = agenda_towards_escalation
#						}
#					}
#					add = 200
#				}
#				else_if = {
#					limit = {
#						scope:actor = {
#							any_character_struggle = {
#								phase_has_catalyst = catalyst_gain_claim_on_title_fp2
#							}
#						}
#					}
#					add = -100
#				}
#			}
#		}
#
#		modifier = {
#			scope:actor = {
#				any_character_struggle = {
#					involvement = involved
#					is_struggle_type = persian_struggle
#				}
#			}
#			add = {
#				value = 0
#				if = {
#					limit = {
#						scope:actor = {
#							any_character_struggle = {
#								phase_has_catalyst = catalyst_gain_claim_on_title_fp3
#							}
#							has_trait = fp3_struggle_detractor
#						}
#					}
#					add = 200
#				}
#				else_if = {
#					limit = {
#						scope:actor = {
#							any_character_struggle = {
#								phase_has_catalyst = catalyst_gain_claim_on_title_fp3
#							}
#						}
#					}
#					add = -100
#				}
#			}
#		}

		modifier = {
			factor = 0.25
			scope:actor = {
				ai_greed < 100
				opinion = {
					target = scope:recipient
					value >= 50
				}
			}
		}

		modifier = {
			factor = 0
			scope:actor = {
				ai_greed < 100
				opinion = {
					target = scope:recipient
					value >= 75
				}
			}
		}

		modifier = {
			add = -25
			scope:actor = {
				has_dread_level_towards = {
					target = scope:recipient
					level = 1
				}
			}
		}

		modifier = {
			factor = 0
			scope:actor = {
				has_dread_level_towards = {
					target = scope:recipient
					level = 2
				}
			}
		}

		modifier = {
			factor = 0
			scope:recipient = {
				OR = {
					has_relation_friend = scope:actor
					has_relation_best_friend = scope:actor
					has_relation_soulmate = scope:actor
				}
			}
		}
	}
}

give_vassal_directive_interaction = {
	category = interaction_category_vassal
	icon = icon_scheme_challenge_status
	interface_priority = 60
	desc = give_vassal_directive_interaction_desc

	auto_accept = yes

	is_shown = {
		scope:recipient = {
			trigger_if = {
				limit = {
					scope:actor = { government_allows = administrative }
				}
				is_vassal_or_below_of = scope:actor
			}
			trigger_else = {
				is_vassal_of = scope:actor
			}
			is_landed = yes
			NOT = { government_has_flag = government_is_true_herder }
			highest_held_title_tier >= tier_county
			is_ai = yes
		}
	}

	is_valid = {
		vassal_follows_directive_trigger = { VASSAL = scope:recipient LIEGE = scope:actor }
	}

	is_valid_showing_failures_only = {
		vassal_follows_directive_valid_trigger = { VASSAL = scope:recipient LIEGE = scope:actor }
		scope:recipient = { is_physically_able = yes }
	}

	send_option = {
		flag = improve_development
		is_shown = {
			scope:recipient = {
				government_allows = administrative
			}
		}
		is_valid = {
			scope:recipient = {
				highest_held_title_tier >= tier_duchy
			}
		}
	}

	send_option = {
		flag = train_commanders
		is_shown = {
			scope:recipient = {
				government_allows = administrative
			}
		}
		is_valid = {
		}
	}

	send_option = {
		flag = build_maa
		is_shown = {
			scope:recipient = {
				government_allows = administrative
			}
		}
		is_valid = {
		}
	}

	send_option = {
		flag = convert_faith
		is_shown = {
			scope:recipient = {
				NOT = { government_has_flag = government_is_nomadic }
			}
		}
		is_valid = {
			scope:recipient = {
				custom_tooltip = {
					text = subrealm_has_county_of_other_faith
					any_sub_realm_county = {
						faith != scope:recipient.faith
					}
				}
			}
		}
	}

	send_option = {
		flag = convert_culture
		is_shown = {
			scope:recipient = {
				NOT = { government_has_flag = government_is_nomadic }
			}
		}
		is_valid = {
			scope:recipient = {
				custom_tooltip = {
					text = subrealm_has_county_of_other_culture
					any_sub_realm_county = {
						culture != scope:recipient.culture
					}
				}
			}
		}
	}

	send_option = {
		flag = improve_cultural_acceptance
		is_shown = {
			scope:recipient = {
				NOT = { government_has_flag = government_is_nomadic }
			}
		}
		is_valid = {
			scope:recipient = {
				highest_held_title_tier >= tier_duchy
				custom_tooltip = {
					text = subrealm_has_county_of_other_culture
					any_sub_realm_county = {
						culture != scope:recipient.culture
					}
				}
			}
		}
	}

	send_option = {
		flag = building_focus_fortification
		is_shown = {
			scope:recipient = {
				NOT = { government_has_flag = government_is_nomadic }
			}
		}
		is_valid = {
		}
	}

	send_option = {
		flag = building_focus_military
		is_shown = {
			scope:recipient = {
				NOT = { government_has_flag = government_is_nomadic }
			}
		}
		is_valid = {
		}
	}

	send_option = {
		flag = building_focus_economy
		is_shown = {
			scope:recipient = {
				NOT = { government_has_flag = government_is_nomadic }
			}
		}
		is_valid = {
		}
	}

	send_option = {
		flag = manage_fertility
		is_shown = {
			scope:recipient = {
				government_has_flag = government_is_nomadic
			}
		}
		is_valid = {
		}
	}
	send_option = {
		flag = explore_cultures
		is_shown = {
			scope:recipient = {
				government_has_flag = government_is_nomadic
			}
		}
		is_valid = {
			scope:recipient = {
				custom_tooltip = {
					text = subrealm_has_county_of_other_culture
					any_sub_realm_county = {
						NOT = { culture = scope:recipient.culture }
					}
				}
			}
		}
	}
	send_option = {
		flag = raid_innovation_intent
		is_shown = {
			scope:recipient = {
				government_has_flag = government_is_nomadic
			}
		}
		is_valid = {
			custom_tooltip = {
				text = has_any_directive
				scope:recipient = {
					NOT = {
						has_character_flag = vassal_directive_raid_innovation_intent
					}
				}
			}
		}
	}
	send_option = {
		flag = raid_herd_intent
		is_shown = {
			scope:recipient = {
				government_has_flag = government_is_nomadic
			}
		}
		is_valid = {
		}
	}

	send_option = {
		flag = remove_directive
		is_shown = {
		}
		is_valid = {
			custom_tooltip = {
				text = has_any_directive
				scope:recipient = {
					OR = {
						has_character_flag = vassal_directive_improve_development
						has_character_flag = vassal_directive_train_commanders
						has_character_flag = vassal_directive_build_maa
						has_character_flag = vassal_directive_convert_faith
						has_character_flag = vassal_directive_convert_culture
						has_character_flag = vassal_directive_improve_cultural_acceptance
						has_character_flag = vassal_directive_building_focus_fortification
						has_character_flag = vassal_directive_building_focus_military
						has_character_flag = vassal_directive_building_focus_economy
						has_character_flag = vassal_directive_manage_fertility
						has_character_flag = vassal_directive_explore_cultures
						has_character_flag = vassal_directive_raid_innovation_intent
						has_character_flag = vassal_directive_raid_herd_intent
					}
				}
			}
		}
	}

	on_accept = {
		scope:recipient = {
			if = {
				limit = {
					OR = {
						has_character_flag = vassal_directive_improve_development
						has_character_flag = vassal_directive_train_commanders
						has_character_flag = vassal_directive_build_maa
						has_character_flag = vassal_directive_convert_faith
						has_character_flag = vassal_directive_convert_culture
						has_character_flag = vassal_directive_improve_cultural_acceptance
						has_character_flag = vassal_directive_building_focus_fortification
						has_character_flag = vassal_directive_building_focus_military
						has_character_flag = vassal_directive_building_focus_economy
						has_character_flag = vassal_directive_manage_fertility
						has_character_flag = vassal_directive_explore_cultures
						has_character_flag = vassal_directive_raid_innovation_intent
						has_character_flag = vassal_directive_raid_herd_intent
					}
				}
				custom_tooltip = {
					text = vassal_directive_remove_directive
					remove_vassal_directives = yes
				}
			}
			switch = {
				trigger = yes

				scope:improve_development ?= {
					custom_tooltip = {
						text = vassal_directive_improve_development
						remove_vassal_directives = yes
						add_character_flag = vassal_directive_improve_development
					}
				}

				scope:train_commanders ?= {
					custom_tooltip = {
						text = vassal_directive_train_commanders
						remove_vassal_directives = yes
						add_character_flag = vassal_directive_train_commanders
					}
				}

				scope:build_maa ?= {
					custom_tooltip = {
						text = vassal_directive_build_maa
						remove_vassal_directives = yes
						add_character_flag = vassal_directive_build_maa
					}
				}

				scope:convert_faith ?= {
					custom_tooltip = {
						text = vassal_directive_convert_faith
						remove_vassal_directives = yes
						add_character_flag = vassal_directive_convert_faith
					}
				}

				scope:convert_culture ?= {
					custom_tooltip = {
						text = vassal_directive_convert_culture
						remove_vassal_directives = yes
						add_character_flag = vassal_directive_convert_culture
					}
				}

				scope:improve_cultural_acceptance ?= {
					custom_tooltip = {
						text = vassal_directive_improve_cultural_acceptance
						remove_vassal_directives = yes
						add_character_flag = vassal_directive_improve_cultural_acceptance
					}
				}

				scope:building_focus_fortification ?= {
					custom_tooltip = {
						text = vassal_directive_building_focus_fortification
						remove_vassal_directives = yes
						add_character_flag = vassal_directive_building_focus_fortification
					}
				}

				scope:building_focus_military ?= {
					custom_tooltip = {
						text = vassal_directive_building_focus_military
						remove_vassal_directives = yes
						add_character_flag = vassal_directive_building_focus_military
					}
				}

				scope:building_focus_economy ?= {
					custom_tooltip = {
						text = vassal_directive_building_focus_economy
						remove_vassal_directives = yes
						add_character_flag = vassal_directive_building_focus_economy
					}
				}

				scope:manage_fertility ?= {
					custom_tooltip = {
						text = vassal_directive_manage_fertility
						remove_vassal_directives = yes
						add_character_flag = vassal_directive_manage_fertility
					}
				}
				scope:explore_cultures ?= {
					custom_tooltip = {
						text = vassal_directive_explore_cultures
						remove_vassal_directives = yes
						add_character_flag = vassal_directive_explore_cultures
					}
				}
				scope:raid_innovation_intent ?= {
					custom_tooltip = {
						text = vassal_directive_raid_innovation_intent
						remove_vassal_directives = yes
						add_character_flag = vassal_directive_raid_innovation_intent
					}
				}
				scope:raid_herd_intent ?= {
					custom_tooltip = {
						text = vassal_directive_raid_herd_intent
						remove_vassal_directives = yes
						add_character_flag = vassal_directive_raid_herd_intent
					}
				}

				scope:remove_directive ?= {
					custom_tooltip = {
						text = vassal_directive_remove_directive
						remove_vassal_directives = yes
					}
				}
			}
		}
	}

	ai_potential = {
		government_allows = administrative
	}
	ai_targets = {
		ai_recipients = vassals
	}
	ai_frequency_by_tier = {
		barony = 0
		county = 0
		duchy = 0
		kingdom = 12
		empire = 1
		hegemony = 1
	}
	ai_will_do = {
		base = 0

		modifier = {
			add = 100
			scope:improve_development ?= yes
			scope:recipient = {
				NOR = {
					has_character_flag = vassal_directive_building_focus_economy
					has_character_flag = vassal_directive_improve_development
				}
				OR = {
					vassal_contract_has_flag = admin_theme_civilian
					vassal_contract_has_flag = admin_theme_balanced
				}
			}
		}

		modifier = {
			add = 100
			scope:building_focus_economy ?= yes
			scope:recipient = {
				NOR = {
					has_character_flag = vassal_directive_building_focus_economy
					has_character_flag = vassal_directive_improve_development
				}
				OR = {
					vassal_contract_has_flag = admin_theme_civilian
					vassal_contract_has_flag = admin_theme_balanced
				}
			}
		}

		modifier = {
			add = 100
			scope:building_focus_fortification ?= yes
			scope:recipient = {
				NOR = {
					has_character_flag = vassal_directive_building_focus_fortification
					has_character_flag = vassal_directive_build_maa
				}
				vassal_contract_has_flag = admin_theme_frontier
			}
		}

		modifier = {
			add = 100
			scope:build_maa ?= yes
			scope:recipient = {
				NOR = {
					has_character_flag = vassal_directive_building_focus_fortification
					has_character_flag = vassal_directive_building_focus_military
					has_character_flag = vassal_directive_build_maa
				}
				OR = {
					vassal_contract_has_flag = admin_theme_military
					vassal_contract_has_flag = admin_theme_frontier
				}
			}
		}

		modifier = {
			add = 100
			scope:building_focus_military ?= yes
			scope:recipient = {
				NOR = {
					has_character_flag = vassal_directive_building_focus_military
					has_character_flag = vassal_directive_build_maa
				}
				OR = {
					vassal_contract_has_flag = admin_theme_military
					vassal_contract_has_flag = admin_theme_naval
				}
			}
		}
	}
}



request_court_position = {
	category = interaction_category_vassal
	interface_priority = 120
	icon = seneschal_court_position

	desc = request_court_position_desc

	special_interaction = request_court_position
	interface = court_task_interaction
	target_type = court_position_type

	should_use_extra_icon = {
		scope:actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	is_shown = {
		NOT = { scope:recipient = scope:actor }
		scope:actor.liege ?= scope:recipient
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			tgp_is_ceremonial_liege_trigger = no
		}
	}

	on_accept = {
		scope:recipient = {
			appoint_court_position = {
				recipient = scope:actor
				court_position = scope:target
			}
		}
		scope:actor = {
			if = {
				limit = { always = scope:claim_hook }
				use_hook = scope:recipient
			}
		}
	}

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

	send_option = {
		is_shown = {
			NOT = { scope:actor = scope:recipient }
		}
		is_valid = {
			scope:actor = {
				has_usable_hook = scope:recipient
			}
		}
		flag = claim_hook
		localization = GENERIC_SPEND_A_HOOK
	}

	send_options_exclusive = no

	ai_accept = {
		base = -75

		modifier = {
			scope:claim_hook ?= yes
			add = 100
			desc = SCHEME_WEAK_HOOK_USED
		}

		opinion_modifier = { # More likely if Recipient likes Actor
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 0.5
			desc = AI_OPINION_REASON
		}
	}

	force_notification = yes
}

grant_court_position = {
	category = interaction_category_vassal
	interface_priority = 120
	icon = seneschal_court_position

	desc = grant_court_position_desc

	special_interaction = grant_court_position
	interface = court_task_interaction
	target_type = court_position_type

	is_shown = {
		NOT = { scope:recipient = scope:actor }
		scope:recipient = {
			liege ?= scope:actor
			tgp_is_ceremonial_liege_trigger = no
			NOT = { has_character_flag = travel_option_added_character }
		}
	}

	is_valid_showing_failures_only = {
		scope:recipient = {
			NOT = {
				is_imprisoned_by = scope:actor
			}
			is_adult = yes
		}
	}

	on_accept = {
		scope:actor = {
			appoint_court_position = {
				recipient = scope:recipient
				court_position = scope:target
			}
		}
	}

	auto_accept = yes
}
