﻿imprison_interaction = {
	interface_priority = 120
	common_interaction = yes
	icon = prison

	category = interaction_category_hostile
	highlighted_reason = HIGHLIGHTED_HAS_IMPRISONMENT_REASON
	ai_maybe = yes
	ai_min_reply_days = 4
	ai_max_reply_days = 9
	can_send_despite_rejection = yes
	popup_on_receive = yes
	pause_on_receive = yes

	desc = imprison_interaction_desc

	greeting = negative
	notification_text = REQUEST_ARREST_NOTIFICATION_TEXT
	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

	on_decline_summary = imprison_decline_summary
	
	ai_potential = {
		NOT = { has_realm_law_flag = cannot_imprison }
		is_imprisoned = no
	}

	is_shown = {
		NOT = { scope:actor = scope:recipient }
		scope:actor = {
			basic_allowed_to_imprison_character_trigger = {
				CHARACTER = scope:recipient
			}
		}
		# Scope:recipient can't be visiting elsewhere.
		trigger_if = {
			limit = {
				scope:recipient = { is_courtier_of = scope:actor }
			}
			NOT = {
				scope:recipient.host = {
					any_foreign_court_guest = { this = scope:recipient }
				}
			}
		}
		
		#AGOT Added, no non-human interactions
		scope:actor = { is_human = yes }
		scope:recipient = { is_human = yes }
	}
	
	is_valid_showing_failures_only = {
		scope:actor = {
			allowed_to_imprison_character_trigger = { CHARACTER = scope:recipient }
		}
		imprison_neutral_is_valid_showing_failures_only_triggers_trigger = yes
		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 }
			}
		}
	}
	
	is_highlighted = {
		scope:recipient = {
			is_imprisoned = no
		}
		scope:actor = {
			has_imprisonment_reason = scope:recipient
		}
	}

	#Use hook
	send_option = {
		is_valid = {
			exists = scope:recipient
			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

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

	on_send = {
		scope:actor = {
			add_character_flag = {
				flag = flag_hostile_actions_disabled_delay
				days = 10
			}
		}
	}

	on_auto_accept = {
		illegal_imprisonment_dread_effect = yes
		imprison_court_chaplain_consequences_effect = yes
		imprison_HoF_consequences_effect = yes
		scope:recipient = {
			if = {
				limit = {
					is_a_faction_member = yes
					liege = scope:actor
				}
				joined_faction = { save_scope_as = retaliating_faction }
			}
		}
		imprison_character_effect = {
			TARGET = scope:recipient
			IMPRISONER = scope:actor
		}
		scope:recipient = {
			trigger_event = char_interaction.0233
		}
		scope:actor = {
			trigger_event = char_interaction.0231
			if = {
				limit = {
					has_imprisonment_reason = scope:recipient
				}
				stress_impact = {
					compassionate = minor_stress_impact_gain
					forgiving = minor_stress_impact_gain
				}
			}
			else = {
				stress_impact = {
					just = medium_stress_impact_gain
					compassionate = medium_stress_impact_gain
				}
				if = {
					limit = { exists = scope:retaliating_faction}
					scope:retaliating_faction = {
						imprisonment_retribution_start_faction_war_if_valid = yes
					}
				}
			}
		}
		if = {
			limit = {
				scope:actor = { has_character_flag = flag_hostile_actions_disabled_delay }
			}
			scope:actor = { remove_character_flag = flag_hostile_actions_disabled_delay }
		}
	}

	on_accept = {
		if = {
			limit = { scope:hook = yes }
			scope:actor = { use_hook = scope:recipient }
		}
		illegal_imprisonment_dread_effect = yes
		imprison_court_chaplain_consequences_effect = yes
		imprison_HoF_consequences_effect = yes
		scope:recipient = {
			if = {
				limit = {
					is_a_faction_member = yes
					liege = scope:actor
				}
				joined_faction = { save_scope_as = retaliating_faction }
			}
		}
		imprison_character_effect = {
			TARGET = scope:recipient
			IMPRISONER = scope:actor
		}
		# If they recently revoked your title, or asked for your excommunication, they become your rival
		imprison_attempt_escalates_rivalry_effect = yes
		scope:actor = {
			trigger_event = char_interaction.0231
			if = {
				limit = {
					has_imprisonment_reason = scope:recipient
				}
				stress_impact = {
					compassionate = minor_stress_impact_gain
					forgiving = minor_stress_impact_gain
				}
			}
			else = {
				stress_impact = {
					just = medium_stress_impact_gain
					compassionate = medium_stress_impact_gain
				}
				if = {
					limit = { exists = scope:retaliating_faction}
					scope:retaliating_faction = {
						imprisonment_retribution_start_faction_war_if_valid = yes
					}
				}
			}
		}
		if = {
			limit = {
				scope:actor = { has_character_flag = flag_hostile_actions_disabled_delay }
			}
			scope:actor = { remove_character_flag = flag_hostile_actions_disabled_delay }
		}

		# If we're a clan this interaction affects unity
		if = { # If you don't have an imprisonment reason, and the target is landed, you lose more unity
			limit = {
				NOT = { scope:actor = { has_imprisonment_reason = scope:recipient } }
				scope:recipient = { is_landed = yes }
			}
			add_clan_unity_interaction_effect = {
				CHARACTER = scope:actor
				TARGET = scope:recipient
				VALUE = major_unity_loss
				DESC = clan_unity_imprison.desc
				REVERSE_NON_HOUSE_TARGET = no
			}
		}
		else_if = { # If you don't have an imprisonment reason, and the target is unlanded, you lose slightly less unity
			limit = {
				NOT = {
					scope:actor = { has_imprisonment_reason = scope:recipient }
					scope:recipient = { is_landed = yes }
				}
			}
			add_clan_unity_interaction_effect = {
				CHARACTER = scope:actor
				TARGET = scope:recipient
				VALUE = medium_unity_loss
				DESC = clan_unity_imprison.desc
				REVERSE_NON_HOUSE_TARGET = no
			}
		}
		else = { # If you have a valid reason, you lose only a tiny bit of unity (criminal or not, they are still family)
			add_clan_unity_interaction_effect = {
				CHARACTER = scope:actor
				TARGET = scope:recipient
				VALUE = minor_unity_loss
				DESC = clan_unity_imprison.desc
				REVERSE_NON_HOUSE_TARGET = no
			}
		}
	}
	
	on_decline = {
		scope:actor = {
			imprison_HoF_consequences_effect = yes 
			imprison_tyranny_effect = yes
		}
		scope:recipient = {
			#If target is count or higher, start war.
			if = {
				limit = {
					is_landed = yes
					primary_title.tier > tier_barony
				}
				if = {
					limit = {
						is_a_faction_member = yes
						liege = scope:actor
						joined_faction = {
							faction_target = scope:actor
							#AGOT Disabled, populist factions
							#NOT = { faction_is_type = populist_faction }
						}
					}
					joined_faction = {
						save_scope_as = retaliating_faction # For loc
						imprisonment_retribution_start_faction_war_if_valid = yes
					}
					hidden_effect = {
						if = {
							limit = { NOT = { exists = joined_faction.faction_war } }
							war_for_imprison_effect = yes
						}
					}
				}
				else = {
					war_for_imprison_effect = yes
				}
			}
			#If target is a baron or unlanded, have them escape.
			else = {
				if = { #To block them from being instantly rehired
					limit = {
						is_councillor_of = scope:actor
						can_be_fired_from_council_trigger = { COURT_OWNER = scope:actor }
					}
					set_variable = {
						name = escaped_imprisonment_from
						value = scope:actor
						years = 20
					}
				}
				imprison_court_chaplain_consequences_effect = yes
				if = {
					limit = {
						is_landed = yes
					}
					custom_tooltip = deposed_and_become_wanderer
					hidden_effect = {
						depose = yes
						move_to_pool = yes
					}
				}
				else_if  = {
					limit = {
						is_hostage = yes
						warden = scope:actor
					}
					save_scope_as = imprison_failure
					save_scope_as = hostage
					warden = { save_scope_as = warden }
					home_court = { save_scope_as = home_court }
					scope:warden = { trigger_event = bp2_hostage_system.0400 }
					scope:home_court = { trigger_event = bp2_hostage_system.0401 }
					return_hostage = yes
				}
				else_if = {
					limit = {
						is_landed = no
						trigger_if = {
							limit = {
								is_councillor = yes
							}
							can_be_fired_from_council_trigger = { COURT_OWNER = scope:recipient.liege }
						}
						trigger_if = {
							limit = {
								exists = scope:actor.faith.religious_head
							}
							NOT = { scope:actor.faith.religious_head = scope:recipient }
						}
					}
					select_and_move_to_pool_effect = yes
				}
				add_opinion = {
					target = scope:actor
					modifier = attempted_imprisonment_opinion
				}
			}
		}

		if = {
			limit = {
				scope:actor = { has_realm_law_flag = vassal_refusal_is_treason }
			}
			scope:actor = {
				add_opinion = {
					target = scope:recipient
					modifier = treasonous_imprison_refusal
				}
			}
		}

		#Remove them as guardian/ward for any courtier (feedback given in char_interaction.0230)
		scope:actor = {
			if = {
				limit = {
					any_courtier = {
						has_relation_guardian = scope:recipient
					}
				}
				every_courtier = {
					limit = {
						has_relation_guardian = scope:recipient
					}
					save_scope_as = ward
					scope:recipient = { remove_relation_ward = scope:ward }

					scope:ward = {
						if = {
							limit = {
								NOT = { host = liege }
							}
							return_to_court = yes
						}
						guardian_remove_opinion_effect = {
							GUARDIAN = scope:recipient
							WARD = this
							WARD_LIEGE = scope:actor
						}
					}

					add_to_list = ward_children
				}
			}
			if = {
				limit = {
					any_courtier = {
						has_relation_ward = scope:recipient
					}
				}
				random_courtier = {
					limit = {
						has_relation_ward = scope:recipient
					}
					save_scope_as = guardian
					scope:guardian = { remove_relation_ward = scope:recipient }

					scope:guardian = {
						if = {
							limit = {
								NOT = { host = liege }
							}
							return_to_court = yes
						}
						guardian_remove_opinion_effect = {
							GUARDIAN = this
							WARD = scope:recipient
							WARD_LIEGE = scope:actor
						}
					}

					add_to_list = guardian_list
				}

				hidden_effect = {
					scope:guardian = {
						send_interface_message = {
							type = event_generic_neutral
							title = remove_guardian_interaction_notification
							left_icon = scope:recipient
							right_icon = scope:guardian
							remove_guardian_effect = {
								GUARDIAN = scope:guardian
								WARD = scope:recipient
								RETURN_WARD = yes
								HIDE_OPINION = no
							}
						}
					}
				}
			}
		}

		scope:actor = {
			if = {
				limit = {
					scope:recipient = {
						OR = {
							is_landed = no
							AND = {
								is_landed = yes
								primary_title.tier = tier_barony
							}
						}
						#AGOT Added
						NOT = {
							has_trait = kingsguard
						}
					}
				}
				trigger_event = char_interaction.0230
			}
			#AGOT Added
			else_if = {
				limit = {
					scope:recipient = {
						has_trait = kingsguard
					}
				}
				trigger_event = agot_kingsguard.2002
			}
		}

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

		# If we're a clan this interaction affects unity
		if = { # If you don't have an imprisonment reason, and the target is landed, you lose more unity
			limit = {
				NOT = {
					scope:actor = { has_imprisonment_reason = scope:recipient }
				}
				scope:recipient = { is_landed = yes }
			}
			add_clan_unity_interaction_effect = {
				CHARACTER = scope:actor
				TARGET = scope:recipient
				VALUE = major_unity_loss
				DESC = clan_unity_imprison.desc
				REVERSE_NON_HOUSE_TARGET = no
			}
		}
		else_if = { # If you don't have an imprisonment reason, and the target is unlanded, you lose slightly less unity
			limit = {
				NOT = {
					scope:actor = { has_imprisonment_reason = scope:recipient }
					scope:recipient = { is_landed = yes }
				}
			}
			add_clan_unity_interaction_effect = {
				CHARACTER = scope:actor
				TARGET = scope:recipient
				VALUE = medium_unity_loss
				DESC = clan_unity_imprison.desc
				REVERSE_NON_HOUSE_TARGET = no
			}
		}
		else = { # If you have a valid reason, you lose only a tiny bit of unity (criminal or not, they are still family)
			add_clan_unity_interaction_effect = {
				CHARACTER = scope:actor
				TARGET = scope:recipient
				VALUE = miniscule_unity_loss
				DESC = clan_unity_imprison.desc
				REVERSE_NON_HOUSE_TARGET = no
			}
		}
	}

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

		modifier = {
			add = {
				value = scope:actor.intrigue
				multiply = 1
			}
			desc = IMPRISON_INTRIGUE_ACTOR
		}
		modifier = {
			add = {
				value = scope:recipient.intrigue
				multiply = -2
			}
			desc = IMPRISON_INTRIGUE_RECIPIENT
		}

		modifier = {
			add = 30
			scope:hook = yes
			desc = SCHEME_HOOK_USED
		}
		opinion_modifier = { # Opinion Factor
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 0.5
			desc = AI_OPINION_REASON
		}
		ai_value_modifier = {
			who = scope:recipient
			ai_boldness = {
				if = {
					limit = {
						scope:recipient = { NOT = { ai_boldness = 0 } }
					}
					value = -0.5
				}
			}
			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_imprisonment_reason = scope:recipient
							has_realm_law_flag = vassal_refusal_is_treason
						}
					}
					value = 0.75
				}
			}
		}
		modifier = {
			add = 20
			scope:actor = {
				any_vassal_or_below = { this = scope:recipient }
				has_realm_law_flag = vassal_refusal_is_treason
			}
			desc = AI_REFUSAL_IS_TREASON
		}
		modifier = {
			add = 50
			scope:actor = {
				has_perk = prison_feudal_complex_perk
			}
			desc = AI_PRISON_FEUDAL_COMPLEX_PERK
		}
		modifier = { #I am a King!
			desc = offer_vassalization_interaction_aibehavior_amkingtier_tt
			scope:recipient = { highest_held_title_tier = tier_kingdom }
			add = -40
		}
		modifier = { #Courtiers.
			desc = AI_REFUSAL_COURTIER
			scope:recipient = { is_ruler = no }
			add = 50
		}
		modifier = { # Your young children can't really stop you
			desc = AI_REFUSAL_YOUNG_CHILD
			scope:recipient = {
				is_child_of = scope:actor
				is_courtier_of = scope:actor
				is_adult = no
			}
			add = 200
		}
		modifier = { #They're a claimant against you
			desc = AI_CLAIMANT_PENALTY
			scope:actor = {
				OR = {
					any_targeting_faction = {
						faction_is_type = claimant_faction
						faction_is_at_war = yes
						exists = special_character
						special_character = scope:recipient
					}
					AND = {
						exists = var:claimant_faction_sent_demand
						var:claimant_faction_sent_demand = scope:recipient
					}
				}
			}
			add = -70
		}
		modifier = { #Rank difference.
			desc = AI_REFUSAL_RANK_DIFFERENCE
			scope:recipient = {
				is_ruler = yes
				highest_held_title_tier < tier_kingdom
			}
			add = {
				value = -15
				if = {
					limit = {
						scope:actor = {
							tier_difference = {
								target = scope:recipient
								value >= 2
							}
						}
					}
					add = 5
				}
				if = {
					limit = {
						scope:actor = {
							tier_difference = {
								target = scope:recipient
								value >= 3
							}
						}
					}
					add = 5
				}
				if = { #King asking Baron, modifier becomes positive.
					limit = {
						scope:actor = {
							tier_difference = {
								target = scope:recipient
								value >= 4
							}
						}
					}
					add = 10
				}
			}
		}
		modifier = {
			add = intimidated_halved_reason_value
			scope:recipient = {
				target_is_liege_or_above = scope:actor
				has_dread_level_towards = {
					target = scope:actor
					level = 1
				}
			}
			desc = INTIMIDATED_REASON
		}
		modifier = {
			add = cowed_halved_reason_value
			scope:recipient = {
				target_is_liege_or_above = scope:actor
				has_dread_level_towards = {
					target = scope:actor
					level = 2
				}
			}
			desc = COWED_REASON
		}
		
		modifier = {
			add = intimidated_external_reason_value
			scope:recipient = {
				NOT = { target_is_liege_or_above = scope:actor }
				has_dread_level_towards = {
					target = scope:actor
					level = 1
				}
			}
			desc = INTIMIDATED_REASON
		}
		modifier = {
			add = cowed_external_reason_value
			scope:recipient = {
				NOT = { target_is_liege_or_above = scope:actor }
				has_dread_level_towards = {
					target = scope:actor
					level = 2
				}
			}
			desc = COWED_REASON
		}
		modifier = { #Comparative military strength.
			desc = offer_vassalization_interaction_aibehavior_power_tt
			trigger = {
				scope:actor = { is_ruler = yes }
				scope:recipient = { is_ruler = yes }
			}
			add = {
				value = 1
				subtract = {
					value = scope:recipient.current_military_strength
					divide = { value = scope:actor.current_military_strength min = 1 }
				}
				multiply = 100
				min = -1000
				# This max needs to match the loc in offer_vassalization_interaction_aibehavior_power_tt
				max = 20
			}
		}
		modifier = { #Rivalry modifier.
			desc = offer_vassalization_interaction_aibehavior_rival_tt
			trigger = {
				scope:recipient = {
					has_relation_rival = scope:actor
					NOT = { has_relation_nemesis = scope:actor }
				}
			}
			add = -50
		}
		modifier = { #Nemesis modifier.
			desc = offer_vassalization_interaction_aibehavior_nemesis_tt
			trigger = {
				scope:recipient = {
					has_relation_nemesis = scope:actor
				}
			}
			add = -100
		}
		modifier = {
			add = 10
			scope:actor = {
				has_royal_court = yes
				is_liege_or_above_of = scope:recipient
				court_grandeur_current_level >= 7
				court_grandeur_current_level < 9
			}
			desc = GRANDEUR_REASON
		}
		modifier = {
			add = 20
			scope:actor = {
				has_royal_court = yes
				is_liege_or_above_of = scope:recipient
				court_grandeur_current_level >= 9
			}
			desc = GRANDEUR_REASON
		}
		modifier = { # Legalistic tradition
			desc = tradition_legalistic_name
			scope:actor = {
				has_imprisonment_reason = scope:recipient
				culture = { has_cultural_parameter = vassals_more_likely_accept_punishments }
			}
			add = legalistic_vassal_punishment_acceptance
		}
		#AGOT Disabled
		# 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
		# }
		# Thug accolade increases imprison chance because they scary
		modifier = {
			scope:actor = {
				any_active_accolade = {
					has_accolade_parameter = accolade_imprisonment_chance
				}
			}
			desc = THUG_REASON
			add = accolade_imprisonment_chance_value
		}
		modifier = {
			scope:actor = {
				any_active_accolade = {
					has_accolade_parameter = accolade_imprisonment_chance_high
				}
			}
			desc = THUG_REASON_HIGH
			add = accolade_imprisonment_chance_value_high
		}
		evaluate_action_decreasing_house_unity = {
			VALUE = 100
		}
	}

	# AI
	ai_targets = {
		ai_recipients = vassals
		chance = 0.5
	}
	ai_targets = {
		ai_recipients = courtiers
		chance = 0.25
	}
	ai_frequency = 10

	ai_will_do = {
		base = -100
		
		modifier = { # Make sure the AI uses hooks for this as it's % based
			scope:hook = yes
			add = 1
		}

		modifier = {
			add = 200
			scope:actor = {
				has_imprisonment_reason = scope:recipient
			}
		}

		modifier = { # Avoid Tyranny wars at inopportune times
			add = -190
			scope:actor = {
				ai_rationality > -100 # Lunatics can do whatever, let the world burn...
				is_at_war = yes
			}
			scope:recipient = {
				is_landed = yes
			}
		}

		modifier = { # Avoid imprisonments in certain circumstances
			add = -190
			scope:actor = {
				ai_rationality > -100 # Lunatics can do whatever, let the world burn...
				NOR = {
					AND = {
						intrigue > scope:recipient.intrigue
						intrigue >= 12
					}
					has_perk = prison_feudal_complex_perk
					scope:recipient = {
						has_dread_level_towards = {
							target = scope:actor
							level >= 1
						}
					}
					culture = { has_cultural_parameter = vassals_more_likely_accept_punishments }
					current_military_strength >= scope:recipient.twice_current_military_strength
					scope:recipient.ai_boldness <= -100
				}
			}
			scope:recipient = {
				is_landed = yes
			}
		}

		modifier = { # If the AI is not very bold, avoid imprisoning people unless you're more powerful
			add = -190
			scope:actor.ai_rationality > -100 # Lunatics can do whatever, let the world burn...
			scope:actor.ai_boldness <= 25
			scope:actor.current_military_strength < scope:recipient.one_and_a_half_times_current_military_strength
		}

		modifier = { # Avoid imprisoning people that would destroy you
			add = -190
			scope:actor.ai_rationality > -100 # Lunatics can do whatever, let the world burn...
			scope:actor.current_military_strength < scope:recipient.current_military_strength
		}
		
		modifier = { # Do not imprison when the chance of success if exceedingly low
			add = -190
			scope:actor.ai_rationality > -100 # Lunatics can do whatever, let the world burn...
			scope:recipient = {
				is_landed = yes
			}
			NOT = {
				scope:recipient = {
					highest_held_title_tier = tier_barony
				}
			}
			scope:actor = {
				gold < minimum_ai_gold_value_for_tyranny_wars
			}
		}

		modifier = { # Don't imprison people you like
			scope:actor = {
				NOT = {
					has_trait = sadistic
				}
				OR = {
					has_secret_relation_lover = scope:recipient
					has_relation_lover = scope:recipient
					has_relation_soulmate = scope:recipient
					has_relation_friend = scope:recipient
					has_relation_best_friend = scope:recipient
					opinion = {
						target = scope:recipient
						value > very_high_positive_opinion
					}
				}
			}
			add = -1000
		}

		modifier = { # Don't imprison your own children... unless they're your rival/nemesis
			scope:recipient = {
				is_child_of = scope:actor
				NOR = {
					has_relation_rival = scope:actor
					has_relation_nemesis = scope:actor
				}
			}
			add = -1000
		}

		modifier = { # Don't imprison your spouse, unless they're your rival/have cheated on you
			scope:recipient = {
				is_spouse_of = scope:actor
				NOR = {
					has_relation_rival = scope:actor
					has_relation_nemesis = scope:actor
					exposed_cheating_on_spouse_trigger = { SPOUSE = scope:actor }
				}
			}
			add = -1000
		}

		modifier = { # Try to avoid pointless imprisonments
			scope:recipient = {
				NOR = {
					scope:actor = { # Sadists want people to torture
						has_trait = sadistic
					}
					AND = { # Imprisoning vassals you have revoke reasons on is relevant
						is_landed = yes
						scope:actor = { has_revoke_title_reason = scope:recipient }
					}
					is_a_faction_member = yes
					has_relation_rival = scope:actor
					has_relation_nemesis = scope:actor
					exposed_cheating_on_spouse_trigger = { SPOUSE = scope:actor }
					scope:actor = { # Scheme Agents should be imprisoned indiscriminately
						any_targeting_scheme = {
							hostile_scheme_trigger = yes
							is_scheme_agent_exposed = scope:recipient
						}
					}
					AND = { # Zealots will imprison characters of other faiths
						scope:actor.ai_zeal >= medium_positive_ai_value
						NOT = { scope:actor.faith = scope:recipient.faith }
					}
					has_opinion_modifier = {
						modifier = murdered_close_family_crime
						target = scope:recipient
					}
					has_opinion_modifier = {
						modifier = attempted_murder_close_family_crime
						target = scope:recipient
					}
					has_opinion_modifier = {
						modifier = executed_close_family
						target = scope:recipient
					}
					has_opinion_modifier = {
						modifier = slept_with_spouse_discovered_opinion
						target = scope:recipient
					}
					has_opinion_modifier = {
						modifier = slept_with_spouse_exposed_opinion
						target = scope:recipient
					}
					has_opinion_modifier = {
						modifier = unfaithful_spouse_discovered_opinion
						target = scope:recipient
					}
					has_opinion_modifier = {
						modifier = unfaithful_spouse_exposed_opinion
						target = scope:recipient
					}
					has_opinion_modifier = {
						modifier = refused_to_renounce_lover_opinion
						target = scope:recipient
					}
					has_opinion_modifier = {
						modifier = betrayed_our_promise
						target = scope:recipient
					}
					has_opinion_modifier = {
						modifier = botched_my_treatment_crime_opinion
						target = scope:recipient
					}
					has_opinion_modifier = {
						modifier = botched_treatment_of_kin_crime_opinion
						target = scope:recipient
					}
					has_opinion_modifier = {
						modifier = smeared_opinion
						target = scope:recipient
					}
					has_opinion_modifier = {
						modifier = insulted_opinion
						target = scope:recipient
					}
					has_opinion_modifier = {
						modifier = mocked_me_in_time_of_need
						target = scope:recipient
					}
					has_opinion_modifier = {
						modifier = loved_one_dungeon_death
						target = scope:recipient
					}
					has_opinion_modifier = {
						modifier = abandoned_me_opinion
						target = scope:recipient
					}
					has_opinion_modifier = {
						modifier = reason_child_died
						target = scope:recipient
					}
					has_opinion_modifier = {
						modifier = falsely_accused
						target = scope:recipient
					}
				}
			}
			add = -1000
		}

		modifier = {
			exists = scope:recipient.primary_title
			add = scope:recipient.primary_title.tier
		}

		# Agenda impact
		modifier = {
			scope:recipient = {
				is_important_or_vip_struggle_character = yes
				any_character_struggle = {
					involvement = involved
				}
			}
			add = {
				value = 0
				if = {
					limit = {
						scope:actor = {
							any_character_struggle = {
								phase_has_catalyst = catalyst_imprison_important
							}
							has_character_flag = agenda_towards_escalation
						}
					}
					add = 200
				}
				else_if = {
					limit = {
						scope:actor = {
							any_character_struggle = {
								phase_has_catalyst = catalyst_imprison_important
							}
						}
					}
					add = -100
				}
			}
		}
		#AGOT Disabled
		# modifier = {
		# 	scope:recipient = {
		# 		has_trait = fp3_struggle_supporter
		# 		any_character_struggle = {
		# 			involvement = involved
		# 		}
		# 	}
		# 	add = {
		# 		value = 0
		# 		if = {
		# 			limit = {
		# 				scope:actor = {
		# 					any_character_struggle = {
		# 						phase_has_catalyst = catalyst_imprison_supporter
		# 					}
		# 					has_trait = fp3_struggle_detractor
		# 				}
		# 			}
		# 			add = 200
		# 		}
		# 		else_if = {
		# 			limit = {
		# 				scope:actor = {
		# 					any_character_struggle = {
		# 						phase_has_catalyst = catalyst_imprison_supporter
		# 					}
		# 				}
		# 			}
		# 			add = -100
		# 		}
		# 	}
		# }
		#AGOT Disabled
		# modifier = {
		# 	scope:recipient = {
		# 		has_trait = fp3_struggle_detractor
		# 		any_character_struggle = {
		# 			involvement = involved
		# 		}
		# 	}
		# 	add = {
		# 		value = 0
		# 		if = {
		# 			limit = {
		# 				scope:actor = {
		# 					any_character_struggle = {
		# 						phase_has_catalyst = catalyst_imprison_detractor
		# 					}
		# 					has_trait = fp3_struggle_supporter
		# 				}
		# 			}
		# 			add = 200
		# 		}
		# 		else_if = {
		# 			limit = {
		# 				scope:actor = {
		# 					any_character_struggle = {
		# 						phase_has_catalyst = catalyst_imprison_detractor
		# 					}
		# 				}
		# 			}
		# 			add = -100
		# 		}
		# 	}
		# }

		modifier = { # Avoid triggering Tyranny wars mid-grand activity
			factor = 0
			scope:actor = {
				has_ongoing_grand_activity_trigger = yes
			}
			scope:recipient = {
				highest_held_title_tier >= tier_county
			}
		}
		
		evaluate_action_decreasing_house_unity = {
			VALUE = 100
		}
	}
}

move_to_dungeon_interaction = {
	interface_priority = 30
	category = interaction_category_prison
	desc = move_to_dungeon_interaction_desc
	icon = prison

	is_shown = {
		scope:recipient = {
			is_imprisoned_by = scope:actor
			is_in_prison_type = house_arrest
		}
	}

	is_valid_showing_failures_only = {
		scope:recipient = { is_busy_in_events_localised = yes }
		scope:recipient = {
			custom_description = {
				text = "currently_being_tortured"
				NOT = { has_character_flag = is_being_tortured }
			}
		}
	}
	
	on_accept = {
		if = {
			limit = { scope:recipient = { has_character_modifier = allowed_to_go_outside } }
			scope:recipient = { remove_character_modifier = allowed_to_go_outside }
		}
		scope:recipient = {
			hidden_effect = {
				change_prison_type = dungeon
			}
			trigger_event = prison_notification.1001
			custom_tooltip = MOVE_PRISONER_TO_DUNGEON
			scope:recipient = {
				#AGOT Modified - ESR
				# every_close_or_extended_family_member = {
				# 	custom = all_family_members
				# 	limit = {
				# 		NOT = { scope:actor = this }
				# 	}
				# 	add_opinion = {
				# 		modifier = family_moved_to_dungeon_opinion
				# 		target = scope:actor
				# 	}
				# }
				every_spouse = {
					limit = { NOT = { this = scope:actor } }
					add_to_temporary_list = recipient_family_opinion_list	
				}
			every_close_or_extended_family_member ={
					limit = { NOT = { this = scope:actor } }
					add_to_temporary_list = recipient_family_opinion_list
					###Note recipient_family_opinion_list stores both close and extened family in esr
				}
		
				if = {
					limit = {
						any_in_list = {
							list = recipient_family_opinion_list
							always = yes
						}
					}
					every_in_list = {
						list = recipient_family_opinion_list
						custom = all_family_members
						add_opinion = {
							target = scope:actor
							modifier = esr_threw_family_in_dungeon
						}
					}
				}
		
				#recipient's friends and lovers
				every_relation = {
					type = friend
					limit = {
						NOR = {
							this = scope:recipient
							this = scope:actor
							has_relation_best_friend = scope:recipient				
						}
					}
					add_to_list = recipient_close_relations_list
				}
				every_relation = {
					type = lover
					limit = {
						NOR = {
							this = scope:recipient
							this = scope:actor
							has_relation_soulmate = scope:recipient
							is_in_list = recipient_close_relations_list
						}
					}
					add_to_list = recipient_close_relations_list
				}
				if = {
					limit = {
						any_in_list = {
							list = recipient_close_relations_list
							always = yes
						}
					}
					every_in_list = {
						list = recipient_close_relations_list
						custom = all_friends_and_lovers
						add_opinion = {
							target = scope:actor
							modifier = esr_threw_close_relation_in_dungeon
						}
					}
				}
		
				#recipient's best friend and soulmate
				every_relation = {
					type = best_friend
					limit = { NOT = {this = scope:actor}}
					add_opinion = {
						target = scope:actor
						modifier = esr_threw_very_close_in_dungeon
					}
				}
		
				every_relation = {
					type = soulmate
					limit = { NOT = {this = scope:actor}}
					add_opinion = {
						target = scope:actor
						modifier = esr_threw_very_close_in_dungeon
					}
				}
		
				#recipient's nemesis
		
				every_relation = {
					type = nemesis
		
					limit = {
						NOR = {
							this = scope:actor
							has_trait = compassionate
						}
					}
					add_opinion = {
						target = scope:actor
						modifier = esr_threw_nemesis_in_dungeon
					}
				}
			}
		}
		scope:actor = {
			stress_impact = {
				compassionate = medium_stress_impact_gain
				forgiving = medium_stress_impact_gain
			}
			
			
			hidden_effect = {
				if = {
					limit = { 
						AND = {
							exists = scope:actor.var:RE_court_intr_2_var
							scope:actor.var:RE_court_intr_2_var <= 98
						}
					}
					scope:actor = {
						change_variable = {
							name = RE_court_intr_2_var
							add = 2
						}
						RE_axis_recount_intr = yes
					}
				}
				else_if = {
					limit = { 
						exists = scope:actor.var:RE_court_intr_2_var
					}
					scope:actor = {
						set_variable = {
							name = RE_court_intr_2_var
							value = 100
						}
					}
				}
				else = {}
			}
			
			hidden_effect = {
				send_interface_message = {
					type = event_generic_neutral
					title = msg_move_prisoner_to_dungeon
					right_icon = scope:recipient
					custom_tooltip = MOVE_PRISONER_TO_DUNGEON
				}
			}
		}

		# 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_move_to_dungeon.desc
			REVERSE_NON_HOUSE_TARGET = no
		}
	}
	
	auto_accept = yes
	
	# AI
	ai_targets = {
		ai_recipients = prisoners
	}
	ai_frequency = 12

	ai_potential = {
		always = yes
	}
	
	ai_will_do = {
		base = 0

		modifier = {
			add = 100
			scope:actor.ai_compassion < medium_positive_ai_value
			scope:actor = {
				opinion = {
					target = scope:recipient
					value <= high_negative_opinion
				}
			}
		}
		modifier = { # Family Feud
			add = 25
			trigger = {
				exists = scope:actor.house
				exists = scope:recipient.house
				scope:actor = {
					house.house_head = {
						any_owned_story = {
							story_type = story_cycle_house_feud
							has_variable = house_feud_house
							var:house_feud_house = scope:recipient.house
						}
					}
					has_opinion_modifier = {
						modifier = house_feud_opinion
						target = scope:recipient.house.house_head
					}
				}
			}
			desc = INTERACTION_FAMILY_FEUD_REASON
		}
	}
}
	
move_to_house_arrest_interaction = {
	interface_priority = 30
	category = interaction_category_prison
	desc = move_to_house_arrest_interaction_desc
	icon = prison

	is_shown = {
		scope:recipient = {
			is_imprisoned_by = scope:actor
			is_in_prison_type = dungeon
		}
	}

	is_valid_showing_failures_only = {
		scope:recipient = { is_busy_in_events_localised = yes }
		scope:recipient = {
			custom_description = {
				text = "currently_being_tortured"
				NOT = { has_character_flag = is_being_tortured }
			}
		}
	}
	
	on_accept = {
		if = {
			limit = { scope:recipient = { has_character_modifier = allowed_to_go_outside } }
			scope:recipient = { remove_character_modifier = allowed_to_go_outside }
		}
		if = {
			limit = { scope:recipient = { has_character_modifier = moldy_gruel_diet } }
			scope:recipient = { remove_character_modifier = moldy_gruel_diet }
		}
		scope:recipient = {
			hidden_effect = {
				change_prison_type = house_arrest
				trigger_event = prison_notification.1002
			}
			custom_tooltip = MOVE_PRISONER_TO_HOUSE_ARREST
			scope:recipient = {
				###AGOT Modified - ESR
			    # every_close_or_extended_family_member = {
				# 	custom = all_family_members
				# 	limit = {
				# 		NOT = { scope:actor = this }
				# 	}
				# 	add_opinion = {
				# 		modifier = moved_to_house_arrest_opinion
				# 		target = scope:actor
				# 	}
				# }
				every_spouse = {
					limit = { NOT = { this = scope:actor } }
					add_to_temporary_list = recipient_family_opinion_list	
				}
		
				every_close_or_extended_family_member ={
					limit = { NOT = { this = scope:actor } }
					add_to_temporary_list = recipient_family_opinion_list
					###Note recipient_family_opinion_list stores both close and extened family in esr
				}
		
				if = {
					limit = {
						any_in_list = {
							list = recipient_family_opinion_list
							always = yes
						}
					}
					every_in_list = {
						list = recipient_family_opinion_list
						custom = all_family_members
						add_opinion = {
							target = scope:actor
							modifier = esr_move_family_to_house_arrest
						}
					}
				}
		
				#recipient's friends and lovers
				every_relation = {
					type = friend
					limit = {
						NOR = {
							this = scope:recipient
							this = scope:actor
							has_relation_best_friend = scope:recipient				
						}
					}
					add_to_list = recipient_close_relations_list
				}
				every_relation = {
					type = lover
					limit = {
						NOR = {
							this = scope:recipient
							this = scope:actor
							has_relation_soulmate = scope:recipient
							is_in_list = recipient_close_relations_list
						}
					}
					add_to_list = recipient_close_relations_list
				}
				if = {
					limit = {
						any_in_list = {
							list = recipient_close_relations_list
							always = yes
						}
					}
					every_in_list = {
						list = recipient_close_relations_list
						custom = all_friends_and_lovers
						add_opinion = {
							target = scope:actor
							modifier = esr_move_close_relation_to_house_arrest
						}
					}
				}
		
				#recipient's best friend and soulmate
				every_relation = {
					type = best_friend
					limit = { NOT = {this = scope:actor}}
					add_opinion = {
						target = scope:actor
						modifier = esr_move_very_close_to_house_arrest
					}
				}
		
				every_relation = {
					type = soulmate
					limit = { NOT = {this = scope:actor}}
					add_opinion = {
						target = scope:actor
						modifier = esr_move_very_close_to_house_arrest
					}
				}
		
				#recipient's nemesis
		
				every_relation = {
					type = nemesis
		
					limit = {
						NOR = {
							this = scope:actor
							has_trait = compassionate
						}
					}
					add_opinion = {
						target = scope:actor
						modifier = esr_move_nemesis_to_house_arrest
					}
				}
			}
		}
		scope:actor = {
			stress_impact = {
				sadistic = medium_stress_impact_gain
				vengeful = medium_stress_impact_gain
			}
			
			hidden_effect = {
				if = {
					limit = { 
						AND = {
							exists = scope:actor.var:RE_court_intr_2_var
							scope:actor.var:RE_court_intr_2_var >= 3
						}
					}
					scope:actor = {
						change_variable = {
							name = RE_court_intr_2_var
							add = -3
						}
						RE_axis_recount_intr = yes
					}
				}
				else_if = {
					limit = { 
						exists = scope:actor.var:RE_court_intr_2_var
					}
					scope:actor = {
						set_variable = {
							name = RE_court_intr_2_var
							value = 0
						}
					}
				}
				else = {}
			}
			
			hidden_effect = {
				send_interface_message = {
					type = event_generic_neutral
					title = msg_move_prisoner_to_house_arrest
					right_icon = scope:recipient
					custom_tooltip = MOVE_PRISONER_TO_HOUSE_ARREST
				}
			}
		}
	}
	
	auto_accept = yes
}

ransom_interaction = {
	interface_priority = 50
	common_interaction = yes
	use_diplomatic_range = no
	category = interaction_category_prison
	special_interaction = ransom_interaction
	icon = icon_gold
	redirect = {
		scope:recipient = {
			save_scope_as = secondary_recipient
			if = {
				limit = {
					is_ruler = no
					exists = liege
				}
				liege = {
					save_scope_as = recipient
				}
			}
		}
	}

	desc = ransom_interaction_desc

	notification_text = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:secondary_recipient = scope:recipient
				}
				desc = OFFER_RANSOM_PROPOSAL_PERSONAL
			}
			desc = OFFER_RANSOM_PROPOSAL
		}
	}
	
	is_shown = {
		scope:secondary_recipient = {
			#exists = liege
			is_imprisoned_by = scope:actor
		}
		NOT = {
			scope:actor = scope:recipient
		}
	}

	is_valid_showing_failures_only = {
		trigger_if = {
			limit = {
				scope:invalid = yes
			}
			always = no
		}

		scope:recipient = { is_busy_in_events_localised = yes } #Payer
		scope:secondary_recipient = { is_busy_in_events_localised = yes } #Prisoner
		scope:secondary_recipient = {
			custom_description = {
				text = "currently_being_tortured"
				NOT = { has_character_flag = is_being_tortured }
			}
		}
		cannot_release_former_regent_whilst_old_regent_holds_power_trigger = {
			PRISONER = scope:recipient
			REGENT = scope:recipient.var:imprisoned_by_diarch
		}
	}
	
	on_accept = {
		if = {
			limit = { scope:recipient = { has_character_modifier = allowed_to_go_outside } }
			scope:recipient = { remove_character_modifier = allowed_to_go_outside }
		}
		if = {
			limit = { scope:recipient = { has_character_modifier = moldy_gruel_diet } }
			scope:recipient = { remove_character_modifier = moldy_gruel_diet }
		}
		# Set up event scopes and trigger the exchange.
		if = {
			limit = { scope:secondary_recipient = { is_imprisoned_by = scope:actor } } # To prevent simultaneous release-shenanigans
			scope:secondary_recipient = {
				save_scope_as = prisoner
			}
			scope:recipient = {
				save_scope_as = payer

				# If the recipient doesn't have enough funds to pay the full amount and we're only requesting their current funds, save how much they've agreed to pay.
				if = {
					limit = {
						OR = {
							exists = scope:current_gold
							exists = scope:extortionate_current_gold
						}
					}
					save_scope_value_as = {
						name = ransom_saved_gold_value
						value = scope:payer.current_gold_value
					}
				}
			}
			scope:actor = {
				save_scope_as = imprisoner

				#Save scopes for portraits
				scope:recipient = { save_scope_as = portrait_first }
				if = {
					limit = {
						NOT = { scope:portrait_first = scope:prisoner }
					}
					scope:prisoner = { save_scope_as = portrait_second}
					# Must come after we save the payment value, or the payer won't know how much they need to pay.
					send_interface_message = {
						type = event_prison_good
						title = msg_ransom_prisoner
						right_icon = scope:portrait_first
						left_icon = scope:portrait_second
						ransom_interaction_effect = yes
					}
				}
				else = {
					# Must come after we save the payment value, or the payer won't know how much they need to pay.
					send_interface_message = {
						type = event_prison_good
						title = msg_ransom_prisoner
						right_icon = scope:portrait_first
						ransom_interaction_effect = yes
					}
				}

				# Struggle Catalyst
				if = {
					limit = {
						any_character_struggle = {
							involvement = involved
							activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
								CATALYST = catalyst_ransom_important
								CHAR = scope:secondary_recipient
							}
						}
					}
					every_character_struggle = {
						involvement = involved
						limit = {
							activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
								CATALYST = catalyst_ransom_important
								CHAR = scope:secondary_recipient
							}
						}
						activate_struggle_catalyst = {
							catalyst = catalyst_ransom_important
							character = scope:actor
						}
					}
				}
			}
		}
	}

	on_decline = {
		# If a player declines this ransom offer, wait 10 years before sending another one (they presumably will ransom that character themselves when they want them back).
		if = {
			limit = { scope:recipient = { is_ai = no } }
			scope:secondary_recipient = {
				add_character_flag = {
					flag = character_ransom_refused_by_player
					years = 10
				}
			}
		}		

		# Trigger notification event
		scope:actor = {
			trigger_event = char_interaction.0131
		}
	}
	
	# Pay me an extortionate amount!
	send_option = {
		is_shown = {
			scope:actor = {
				exists = dynasty
				dynasty = {
					has_dynasty_perk = fp1_pillage_legacy_3
				}
			}
			scope:recipient ?= {
				gold >= scope:secondary_recipient.increased_ransom_cost_value
			}
		}
		flag = extortionate_gold
		localization = "RANSOM_EXTORTIONATE_GOLD_OPTION"
	}

	# If you don't have what they're worth, pay me what you have (extort version)!
	send_option = {
		is_shown = {
			scope:actor = {
				exists = dynasty
				dynasty = {
					has_dynasty_perk = fp1_pillage_legacy_3
				}
			}
			scope:recipient ?= {
				gold < scope:secondary_recipient.increased_ransom_cost_value
				gold >= 1
			}
		}
		flag = extortionate_current_gold
		localization = "RANSOM_EXTORTIONATE_CURRENT_GOLD_OPTION"
	}
	
	# Pay me what they're worth!
	send_option = {
		is_shown = {
			scope:actor = {
				OR = {
					is_lowborn = yes
					NOT = {
						dynasty = {
							has_dynasty_perk = fp1_pillage_legacy_3
						}
					}
				}
			}
			scope:recipient ?= {
				gold >= scope:secondary_recipient.ransom_cost_value
			}
		}
		flag = gold
		localization = "RANSOM_GOLD_OPTION"
	}

	# If you don't have what they're worth, pay me what you have!
	send_option = {
		is_shown = {
			scope:actor = {
				OR = {
					is_lowborn = yes
					NOT = {
						dynasty = {
							has_dynasty_perk = fp1_pillage_legacy_3
						}
					}
				}
			}
			scope:recipient ?= {
				gold < scope:secondary_recipient.ransom_cost_value
				gold >= 1
			}
		}
		flag = current_gold
		localization = "RANSOM_CURRENT_GOLD_OPTION"
	}
	
	send_option = {
		is_shown = {
			trigger_if = { # in the mass action ransom we only want to do it for gold
				limit = { exists = scope:mass_action }
				scope:mass_action = no
			}
		}
		is_valid = {
			scope:actor = {
				can_add_hook = { #To match the hook added through ransom_interaction_effect
					target = scope:recipient
					type = favor_hook
				}
			}
		}
		flag = favor
		localization = "RANSOM_FAVOR_OPTION"
	}
	
	localization_values = {
		EXTORTIONATE_RANSOM_COST = scope:secondary_recipient.increased_ransom_cost_value
		RANSOM_COST = scope:secondary_recipient.ransom_cost_value
		CURRENT_GOLD = scope:recipient.gold
	}
	
	ai_accept = {
		base = 0
		modifier = { # Greedy characters can have their greed get the better of them...
			add = { 
				value = scope:recipient.ai_greed
				multiply = -0.5 
			}
			scope:recipient.ai_greed >= medium_positive_ai_value
			OR = {
				scope:gold = yes
				scope:extortionate_gold = yes
			}
			NOT = {
				scope:recipient = scope:secondary_recipient
			}		
			desc = AI_VALUE_MODIFIER_GREED
		}
		modifier = { # Generous characters are more willing to pay
			add = { 
				value = scope:recipient.ai_greed
				multiply = -0.10 
			}
			OR = {
				scope:gold = yes
				scope:extortionate_gold = yes
			}
			NOT = {
				scope:recipient = scope:secondary_recipient
			}
			scope:recipient.ai_greed <= medium_negative_ai_value 
			desc = AI_VALUE_MODIFIER_GENEROUS
		}
		modifier = {
			add = -10
			NOT = { scope:recipient = scope:secondary_recipient }
			scope:recipient = {
				NOR = {
					is_spouse_of = scope:secondary_recipient
					is_close_or_extended_family_of = scope:secondary_recipient
					has_relation_lover = scope:secondary_recipient
					has_relation_friend = scope:secondary_recipient
					has_secret_relation_lover = scope:secondary_recipient
					has_relation_soulmate = scope:secondary_recipient
					has_relation_best_friend = scope:secondary_recipient
					is_parent_of = scope:secondary_recipient
				}
				#AGOT Added
				scope:secondary_recipient = {
					NOT = { has_trait = kingsguard }
				}
			}
			
			desc = "UNIMPORTANT_CHAR_REASON"
		}
		modifier = {
			add = 100
			scope:recipient = scope:secondary_recipient
			desc = "WANTS_FREEDOM_REASON"
		}
		modifier = { # Acceptance boon for lovers, friends, etc
			add = 25
			NOT = { scope:recipient = scope:secondary_recipient }
			scope:recipient = {
				OR = {
					is_spouse_of = scope:secondary_recipient
					is_close_or_extended_family_of = scope:secondary_recipient
					has_relation_lover = scope:secondary_recipient
					has_relation_friend = scope:secondary_recipient
					has_secret_relation_lover = scope:secondary_recipient
				}
				NOR = {
					has_relation_soulmate = scope:secondary_recipient
					has_relation_best_friend = scope:secondary_recipient
					is_parent_of = scope:secondary_recipient
				}
			}
			desc = "DEAR_TO_ME_REASON"
		}
		modifier = { # Massive acceptance boon for Soulmates and Best Friends
			add = 200
			scope:recipient = {
				OR = {
					has_relation_soulmate = scope:secondary_recipient
					has_relation_best_friend = scope:secondary_recipient
					is_parent_of = scope:secondary_recipient
				}
				NOR = {
					is_spouse_of = scope:secondary_recipient
					AND = {
						NOT = {
							is_parent_of = scope:secondary_recipient
						}
						is_close_or_extended_family_of = scope:secondary_recipient
					}
					has_relation_lover = scope:secondary_recipient
					has_relation_friend = scope:secondary_recipient
					has_secret_relation_lover = scope:secondary_recipient
				}
			}
			desc = "DEAR_TO_ME_REASON"
		}
		modifier = { # Say no to rivals
			add = -200
			scope:recipient = {
				has_relation_rival = scope:secondary_recipient
			}
			desc = "RIVAL_TO_ME_REASON"
		}
		modifier = { # Say no to rivals
			add = -500
			scope:recipient = {
				has_relation_nemesis = scope:secondary_recipient
			}
			desc = "NEMESIS_TO_ME_REASON"
		}
		modifier = {
			add = 10
			scope:recipient = {
				NOR = {
					this = scope:secondary_recipient
					is_spouse_of = scope:secondary_recipient
					is_close_or_extended_family_of = scope:secondary_recipient
					has_relation_lover = scope:secondary_recipient
					has_relation_soulmate = scope:secondary_recipient
					has_secret_relation_lover = scope:secondary_recipient
				}
				NOR = {
					has_relation_rival = scope:secondary_recipient
					has_relation_nemesis = scope:secondary_recipient
				}
			}
			scope:recipient.dynasty = scope:secondary_recipient.dynasty
			desc = "MY_DYNASTY_REASON"
		}
		modifier = { # An Intimidated recipient is significantly more likely to accept an offer from the liege
			add = intimidated_reason_value
			trigger = {
				scope:recipient = {
					target_is_liege_or_above = scope:actor
					has_dread_level_towards = {
						target = scope:actor
						level = 1
					}
				}
			}
			desc = INTIMIDATED_REASON
		}

		modifier = { # An Cowed recipient is significantly more likely to accept an offer from the liege
			add = cowed_reason_value
			trigger = {
				scope:recipient = {
					target_is_liege_or_above = scope:actor
					has_dread_level_towards = {
						target = scope:actor
						level = 2
					}
				}
			}
			desc = COWED_REASON
		}
	}
	
	# AI
	ai_targets = {
		ai_recipients = prisoners
	}
	ai_frequency = 6

	ai_potential = {
		always = yes
	}

	ai_will_do = {
		base = 0
		
		modifier = {
			add = 100
			OR = {
				OR = {
					scope:gold = yes
					scope:extortionate_gold = yes
				}
				AND = {
					scope:recipient = {
						gold >= 25
					}
					scope:secondary_recipient = {
						time_in_prison = { years > 1 }
					}
					scope:current_gold = yes
				}
			}
		}
		
		modifier = {
			add = ai_greed
			ai_greed > 0
			OR = {
				scope:gold = yes
				scope:extortionate_gold = yes
			}
		}
		
		modifier = {
			add = -100
			has_relation_rival = scope:secondary_recipient
		}
		
		modifier = {
			add = -300
			has_relation_nemesis = scope:secondary_recipient
		}
		
		modifier = {
			add = 100
			scope:favor = yes
			scope:recipient = {
				OR = {
					is_vassal_of = scope:actor
					AND = {
						exists = liege
						liege = scope:actor
					}
				}
			}
		}

		# Struggle Agenda
		modifier = {
			scope:secondary_recipient = {
				any_character_struggle = {
					involvement = involved
				}
			}
			scope:actor = {
				any_character_struggle = {
					involvement = involved
				}
			}
			add = {
				value = 0
				if = {
					limit = {
						scope:actor = {
							any_character_struggle = {
								phase_has_catalyst = catalyst_ransom_important
							}
							has_character_flag = agenda_towards_escalation
						}
					}
					add = -100
				}
				else_if = {
					limit = {
						scope:actor = {
							any_character_struggle = {
								phase_has_catalyst = catalyst_ransom_important
							}
						}
					}
					add = 200
				}
			}
		}
		
		modifier = {
			factor = 0
			is_at_war = yes
		}

		modifier = { # Don't annoy players
			factor = 0
			scope:recipient = { is_ai = no }
			OR = {
				scope:recipient = { is_at_war = yes }
				scope:secondary_recipient = { has_character_flag = character_ransom_refused_by_player }
			}
		}		
	}

	# Needs to be after all other send options so we only default to it if everything else is blocked
	send_option = {
		is_shown = { # When doing the mass ransom, its possible for no option to be valid for the gold costs, so instead of defaulting wrong we explitly fail it
			exists = scope:mass_action
			scope:mass_action = yes
		}
		flag = invalid
		localization = "INVALID"
	}
}

#For lieges to ransom their courtiers
pay_ransom_interaction = {
	interface_priority = 50
	common_interaction = yes
	use_diplomatic_range = no
	category = interaction_category_prison
	icon = icon_gold

	redirect = {
		scope:recipient = {
			save_scope_as = secondary_recipient
			if = {
				limit = {
					exists = imprisoner
				}
				imprisoner = { save_scope_as = recipient }
			}
		}
	}

	desc = pay_ransom_interaction_desc

	greeting = positive
	notification_text = PAY_RANSOM_PROPOSAL
	
	is_shown = {
		exists = scope:recipient
		scope:secondary_recipient = {
			NOT = {
				this = scope:actor
			}
			is_imprisoned_by = scope:recipient
			OR = {
				liege ?= scope:actor # You can ransom anyone you have in your court
				is_close_family_of = scope:actor # And anyone who is your close family
				dynasty ?= { # And anyone from your Dynasty
					this ?= scope:actor.dynasty
				}
				any_spouse = { # And anyone married to one of your close kin or dynasty members
					OR = {
						is_close_family_of = scope:actor
						dynasty ?= {
							this ?= scope:actor.dynasty
						}
					}
				}
				has_relation_lover = scope:actor # And Lovers
				has_relation_friend = scope:actor # And Friends
			}
		}
		NOT = {
			scope:actor = scope:recipient
		}
	}

	is_valid_showing_failures_only = {
		scope:recipient = { is_busy_in_events_localised = yes } #Imprisoner
		scope:secondary_recipient = { is_busy_in_events_localised = yes } #Prisoner
		scope:recipient = {
			custom_description = {
				text = "currently_being_tortured"
				NOT = { has_character_flag = is_being_tortured }
			}
		}
		cannot_release_former_regent_whilst_old_regent_holds_power_trigger = {
			PRISONER = scope:recipient
			REGENT = scope:recipient.var:imprisoned_by_diarch
		}
	}
	
	on_accept = {
		# Set up event scopes and trigger the exchange.
		if = {
			limit = { scope:secondary_recipient = { is_imprisoned_by = scope:recipient } }
			scope:secondary_recipient = {
				save_scope_as = prisoner
			}
			scope:recipient = {
				save_scope_as = imprisoner
			}
			scope:actor = {
				save_scope_as = payer
				
				# Stress impacts
				if = {
					limit = {
						scope:prisoner = { # Stress impact for random courtiers
							NOR = {
								is_vassal_of = scope:actor
								is_consort_of = scope:actor
								is_close_family_of = scope:actor
								dynasty ?= {
									this ?= scope:actor.dynasty
								}
								any_spouse = {
									OR = {
										is_close_family_of = scope:actor
										dynasty ?= {
											this ?= scope:actor.dynasty
										}
									}
								}
								has_relation_lover = scope:actor
								has_relation_friend = scope:actor
							}
						}
					}
					stress_impact = {
						compassionate = minor_stress_impact_loss
						generous = medium_stress_impact_loss
					}
				}
				else_if = { # Stress impact for 'relevant' ransoms; in other words, everyone but random courtiers
					limit = {
						scope:prisoner = {
							OR = {
								is_vassal_of = scope:actor
								is_consort_of = scope:actor
								is_close_family_of = scope:actor
								dynasty ?= {
									this ?= scope:actor.dynasty
								}
								any_spouse = {
									OR = {
										is_close_family_of = scope:actor
										dynasty ?= {
											this ?= scope:actor.dynasty
										}
									}
								}
								has_relation_lover = scope:actor
								has_relation_friend = scope:actor
							}
						}
					}
					stress_impact = {
						compassionate = medium_stress_impact_loss
						generous = minor_stress_impact_loss
						just = minor_stress_impact_loss
					}
				}
				
				if = { # Lustful characters want their lovers back
					limit = {
						scope:prisoner = {
							has_relation_lover = scope:actor
						}
					}
					stress_impact = {
						lustful = major_stress_impact_loss
					}
				}
				
				if = { # Loyal characters want to free their friends and lovers
					limit = {
						scope:prisoner = {
							OR = {
								has_relation_friend = scope:actor
								has_relation_lover = scope:actor
							}
						}
					}
					stress_impact = {
						loyal = major_stress_impact_loss
					}
				}
				
				if = { # Family should be free!
					limit = {
						scope:prisoner = {
							is_close_family_of = scope:payer
						}
					}
					stress_impact = {
						family_first = miniscule_stress_impact_loss
					}
				}
				
				# If the payer doesn't have enough funds to pay the full amount and we're only requesting their current funds, save how much they've agreed to pay.
				if = {
					limit = {
						OR = {
							exists = scope:current_gold
							exists = scope:extortionate_current_gold
						}
					}
					save_scope_value_as = {
						name = ransom_saved_gold_value
						value = scope:payer.current_gold_value
					}
				}

				# Must come after we save the payment value, or the payer won't know how much they need to pay.
				trigger_event = char_interaction.0140
			}
			hidden_effect = {
				scope:prisoner = {
					send_interface_toast = {
						type = event_toast_effect_good
						title = ransomed_by_someone
						left_icon = scope:payer
						show_as_tooltip = {
							scope:imprisoner = {
								ransom_interaction_effect = yes
							}
						}
					}
				}
				scope:prisoner = {
					if = {
						limit = {
							liege ?= {
								is_ai = no
								NOR = {
									this = scope:payer
									this = scope:imprisoner
								}
								OR = {
									is_close_or_extended_family_of = scope:prisoner
									is_consort_of = scope:prisoner
									has_relation_lover = scope:prisoner
									has_relation_friend = scope:prisoner
								}
							}
						}
						liege = {
							save_scope_as = prisoner_liege_scope
							send_interface_toast = {
								type = event_toast_effect_good
								title = ransomed_by_someone_third_party
								left_icon = scope:payer
								right_icon = scope:prisoner
								custom_tooltip = ransomed_by_someone_third_party_desc
							}
						}
					}
				}
			}
			scope:imprisoner = {
				send_interface_message = {
					type = event_generic_neutral
					title = recipient_released_from_prison
					right_icon = scope:prisoner
					left_icon = scope:imprisoner
					ransom_interaction_effect = yes
				}

				# Struggle Catalyst
				if = {
					limit = {
						any_character_struggle = {
							involvement = involved
							activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
								CATALYST = catalyst_ransom_important
								CHAR = scope:prisoner
							}
						}
					}
					every_character_struggle = {
						involvement = involved
						limit = {
							activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
								CATALYST = catalyst_ransom_important
								CHAR = scope:prisoner
							}
						}
						activate_struggle_catalyst = {
							catalyst = catalyst_ransom_important
							character = scope:imprisoner
						}
					}
				}
				#AGOT Disabled
				# if = {
				# 	limit = {
				# 		fp3_struggle_involves_one_supporter_and_one_detractor = {
				# 			FIRST = scope:imprisoner
				# 			SECOND = scope:prisoner
				# 		}
				# 		any_character_struggle = {
				# 			involvement = involved
				# 			activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
				# 				CATALYST = catalyst_ransom_supporter_detractor
				# 				CHAR = scope:prisoner
				# 			}
				# 		}
				# 	}
				# 	every_character_struggle = {
				# 		involvement = involved
				# 		limit = {
				# 			activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
				# 				CATALYST = catalyst_ransom_supporter_detractor
				# 				CHAR = scope:prisoner
				# 			}
				# 		}
				# 		activate_struggle_catalyst = {
				# 			catalyst = catalyst_ransom_supporter_detractor
				# 			character = scope:imprisoner
				# 		}
				# 		log_debug_variable_for_persian_struggle_effect = { VAR = concession_catalyst_ransom_supporter_detractor }
				# 	}
				# }
			}
			if = {
				limit = { scope:hook = yes }
				scope:actor = {
					use_hook = scope:recipient
				}
			}
		}
		
		# If we're a clan this interaction affects unity
		add_clan_unity_interaction_effect = {
			CHARACTER = scope:actor
			TARGET = scope:prisoner
			VALUE = medium_unity_gain
			DESC = clan_unity_ransom.desc
			REVERSE_NON_HOUSE_TARGET = no
		}
	}

	on_decline = {
		# If a player declines this ransom offer, wait 10 years before sending another one (they presumably have reasons for keeping that character in prison).
		if = {
			limit = { scope:recipient = { is_ai = no } }
			scope:secondary_recipient = {
				add_character_flag = {
					flag = character_ransom_refused_by_player
					years = 10
				}
			}
		}		

		# Trigger notification event
		scope:actor = {
			trigger_event = char_interaction.0141
		}
	}
	
	send_option = {
		is_shown = {
			exists = scope:recipient
			scope:recipient = {
				exists = dynasty
				dynasty = {
					has_dynasty_perk = fp1_pillage_legacy_3
				}
			}
		}
		is_valid = {
			exists = scope:recipient
			scope:actor = {
				gold >= scope:secondary_recipient.increased_ransom_cost_value
			}
		}
		starts_enabled = {
			exists = scope:recipient
			scope:recipient = {
				exists = dynasty
				dynasty = {
					has_dynasty_perk = fp1_pillage_legacy_3
				}
			}
			scope:actor = {
				gold >= scope:secondary_recipient.increased_ransom_cost_value
			}
		}
		flag = extortionate_gold
		localization = "RANSOM_EXTORTIONATE_GOLD_IMPRISONED_PERSPECTIVE_OPTION"
	}

	# If you don't have what they're worth, pay me what you have (extort version)!
	send_option = {
		is_shown = {
			exists = scope:recipient
			scope:recipient = {
				exists = dynasty
				dynasty = {
					has_dynasty_perk = fp1_pillage_legacy_3
				}
			}
			scope:actor = {
				gold < scope:secondary_recipient.increased_ransom_cost_value
				gold > 0
			}
		}
		starts_enabled = {
			exists = scope:recipient
			scope:recipient = {
				exists = dynasty
				dynasty = {
					has_dynasty_perk = fp1_pillage_legacy_3
				}
			}
			scope:actor = {
				gold < scope:secondary_recipient.increased_ransom_cost_value
				gold > 0
			}
		}
		flag = extortionate_current_gold
		localization = "RANSOM_EXTORTIONATE_CURRENT_GOLD_IMPRISONED_PERSPECTIVE_OPTION"
	}
	
	send_option = {
		is_shown = {
			exists = scope:recipient
			scope:recipient = {
				OR = {
					is_lowborn = yes
					NOT = {
						dynasty = {
							has_dynasty_perk = fp1_pillage_legacy_3
						}
					}
				}
			}
		}
		is_valid = {
			exists = scope:recipient
			scope:actor = {
				gold >= scope:secondary_recipient.ransom_cost_value
			}
		}
		starts_enabled = {
			exists = scope:recipient
			scope:recipient = {
				OR = {
					is_lowborn = yes
					NOT = {
						dynasty = {
							has_dynasty_perk = fp1_pillage_legacy_3
						}
					}
				}
			}
			scope:actor = {
				gold >= scope:secondary_recipient.ransom_cost_value
			}
		}
		flag = gold
		localization = "RANSOM_GOLD_PAY_OPTION"
	}

	# If you don't have what they're worth, pay me what you have!
	send_option = {
		is_shown = {
			exists = scope:recipient
			scope:recipient = {
				OR = {
					is_lowborn = yes
					NOT = {
						dynasty = {
							has_dynasty_perk = fp1_pillage_legacy_3
						}
					}
				}
			}
			scope:actor = {
				gold < scope:secondary_recipient.ransom_cost_value
				gold > 0
			}
		}
		starts_enabled = {
			exists = scope:recipient
			scope:recipient = {
				OR = {
					is_lowborn = yes
					NOT = {
						dynasty = {
							has_dynasty_perk = fp1_pillage_legacy_3
						}
					}
				}
			}
			scope:actor = {
				gold < scope:secondary_recipient.ransom_cost_value
				gold > 0
			}
		}
		flag = current_gold
		localization = "RANSOM_CURRENT_PAY_GOLD_OPTION"
	}
	
	send_option = {
		is_valid = {
			exists = scope:recipient
			scope:recipient = {
				can_add_hook = { #To match the hook added through ransom_interaction_effect
					target = scope:actor
					type = favor_hook
				}
			}
		}
		flag = favor
		localization = "RANSOM_OWE_FAVOR_OPTION"
	}

	#Use hook
	send_option = {
		is_valid = {
			exists = scope:recipient
			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
	
	localization_values = {
		EXTORTIONATE_RANSOM_COST = scope:secondary_recipient.increased_ransom_cost_value
		RANSOM_COST = scope:secondary_recipient.ransom_cost_value
		CURRENT_GOLD = scope:actor.gold
	}
	
	ai_accept = {
		base = 0
		modifier = {
			add = 50
			OR = {
				scope:gold = yes
				scope:extortionate_gold = yes
			}
			desc = "GOLD_POSITIVE_REASON"
		}
		modifier = { # Accept more than half the ransom (unless greedy)
			add = 25
			scope:current_gold = yes
			AND = {
				scope:actor = { gold >= scope:secondary_recipient.half_ransom_cost_value }
				NOT = { scope:recipient.ai_greed >= medium_positive_ai_value }
			}
			desc = "GOLD_POSITIVE_REASON"
		}
		modifier = { # Accept more than half the ransom (unless greedy)
			add = 25
			scope:extortionate_current_gold = yes
			AND = {
				scope:actor = { gold >= scope:secondary_recipient.half_increased_ransom_cost_value }
				NOT = { scope:recipient.ai_greed >= medium_positive_ai_value }
			}
			desc = "GOLD_POSITIVE_REASON"
		}
		modifier = {
			add = 50
			scope:favor = yes
			scope:recipient.top_liege = scope:actor.top_liege
			desc = "FAVOR_POSITIVE_REASON"
		}
		modifier = {
			add = 0
			scope:favor = yes
			NOT = { scope:recipient.top_liege = scope:actor.top_liege }
			desc = "NO_USE_FOR_A_FAVOR_REASON"
		}
		modifier = { # For clarification
			add = 0
			OR = {
				scope:current_gold = yes
				scope:extortionate_current_gold = yes
			}
			OR = {
				scope:actor = { gold < scope:secondary_recipient.half_ransom_cost_value }
				scope:recipient.ai_greed >= medium_positive_ai_value
			}
			desc = "WANTS_MORE_GOLD"
		}
		modifier = { # Say no to rivals
			add = -55
			scope:recipient = {
				has_relation_rival = scope:secondary_recipient
			}
			desc = "RIVAL_TO_ME_REASON"
		}
		modifier = { # Say no to rivals
			add = -300
			scope:recipient = {
				has_relation_nemesis = scope:secondary_recipient
			}
			desc = "NEMESIS_TO_ME_REASON"
		}
		modifier = { # At war
			add = -300
			scope:recipient = {
				is_at_war_with = scope:actor
			}
			desc = "IS_AT_WAR_REASON"
		}
		modifier = { # At war
			add = -300
			scope:recipient = {
				is_at_war = yes
				any_primary_war_enemy = {
					scope:secondary_recipient = {
						liege ?= prev
					}
				}
			}
			desc = "IS_POW_REASON"
		}
		modifier = { # At war
			add = -300
			scope:recipient = {
				is_at_war_with = scope:secondary_recipient
			}
			desc = "IS_AT_WAR_WITH_TARGET_REASON"
		}
		#opinion_modifier = { # A lot more likely if Recipient likes Actor
		#	who = scope:recipient
		#	opinion_target = scope:actor
		#	multiplier = 1.0
		#	desc = AI_OPINION_REASON
		#}
		#opinion_modifier = { # A lot more likely if Recipient likes secondary_recipient/prisoner
		#	who = scope:recipient
		#	opinion_target = scope:secondary_recipient
		#	multiplier = 1.0
		#	desc = AI_OPINION_REASON
		#}
		modifier = {
			scope:hook = yes
			add = 100
			desc = SCHEME_WEAK_HOOK_USED
		}
		modifier = { # An Intimidated recipient is significantly more likely to accept an offer from the liege
			add = 40
			trigger = {
				scope:recipient = {
					target_is_liege_or_above = scope:actor
					has_dread_level_towards = {
						target = scope:actor
						level = 1
					}
				}
			}
			desc = INTIMIDATED_REASON
		}

		modifier = { # An Cowed recipient is significantly more likely to accept an offer from the liege
			add = 100
			trigger = {
				scope:recipient = {
					target_is_liege_or_above = scope:actor
					has_dread_level_towards = {
						target = scope:actor
						level = 2
					}
				}
			}
			desc = COWED_REASON
		}
	}

	auto_accept = {
		custom_description = {
			text = "spending_hook"
			subject = scope:actor
			object = scope:recipient
			scope:hook = yes
			scope:actor = { has_strong_hook = scope:recipient }
		}
	}
	
	
	# AI
	ai_targets = {
		ai_recipients = family
	}
	ai_targets = {
		ai_recipients = spouses
	}
	ai_targets = {
		ai_recipients = scripted_relations
	}
	ai_targets = {
		ai_recipients = liege
	}
	ai_targets = {
		ai_recipients = neighboring_rulers
		ai_recipients = peer_vassals
		max = 5
	}
	ai_frequency = 6

	ai_potential = {
		gold >= 25
	}

	ai_target_quick_trigger = {
		prison = yes
	}

	ai_will_do = {
		base = 0

		modifier = {
			add = 100
			OR = {
				scope:gold = yes
				scope:extortionate_gold = yes
				AND = {
					scope:actor = {
						gold >= 25
					}
					scope:secondary_recipient = {
						time_in_prison = { years > 1 }
					}
					OR = {
						scope:current_gold = yes
						scope:extortionate_current_gold = yes
					}
				}
			}
		}
		
		modifier = {
			add = -100
			has_relation_rival = scope:secondary_recipient
		}
		
		modifier = {
			add = -300
			has_relation_nemesis = scope:secondary_recipient
		}
		
		modifier = {
			add = 100
			scope:favor = yes
			scope:recipient = {
				OR = {
					is_vassal_of = scope:actor
					AND = {
						exists = liege
						liege = scope:actor
					}
				}
			}
		}
		
		modifier = { # Ransom your primary heir first
			add = 10
			OR = {
				scope:gold = yes
				scope:extortionate_gold = yes
				AND = {
					scope:actor = {
						gold >= 25
					}
					scope:secondary_recipient = {
						time_in_prison = { years > 1 }
					}
					OR = {
						scope:current_gold = yes
						scope:extortionate_current_gold = yes
					}
				}
				AND = {
					scope:favor = yes
					scope:recipient = {
						OR = {
							is_vassal_of = scope:actor
							AND = {
								exists = liege
								liege = scope:actor
							}
						}
					}
				}
			}
			scope:secondary_recipient = {
				is_primary_heir_of = scope:actor
			}
		}
		
		modifier = { # Only ransom people you care about... unless you're very compassionate
			factor = 0
			ai_compassion < high_positive_ai_value
			scope:secondary_recipient = {
				NOR = {
					is_heir_of = scope:actor
					is_child_of = scope:actor
					is_grandchild_of = scope:actor
					is_great_grandchild_of = scope:actor
					is_consort_of = scope:actor
					is_parent_of = scope:actor
					is_grandparent_of = scope:actor
					is_great_grandparent_of = scope:actor
					has_relation_friend = scope:actor
					has_relation_lover = scope:actor
					has_secret_relation_lover = scope:actor
					any_spouse = {
						OR = {
							is_heir_of = scope:actor
							is_child_of = scope:actor
							is_grandchild_of = scope:actor
							is_great_grandchild_of = scope:actor
							is_parent_of = scope:actor
							is_grandparent_of = scope:actor
							is_great_grandparent_of = scope:actor
							has_relation_friend = scope:actor
						}
					}
				}
			}
		}
		
		modifier = { # If you're very compassionate, well, then you ransom most people you can!
			factor = 0
			ai_compassion >= high_positive_ai_value
			scope:secondary_recipient = {
				NOR = {
					is_heir_of = scope:actor
					is_close_or_extended_family_of = scope:actor
					is_consort_of = scope:actor
					has_relation_friend = scope:actor
					has_relation_lover = scope:actor
					has_secret_relation_lover = scope:actor
					any_spouse = {
						OR = {
							is_heir_of = scope:actor
							is_close_or_extended_family_of = scope:actor
							has_relation_friend = scope:actor
						}
					}
				}
			}
		}
		
		modifier = { # If you're very greedy... then they're a little bit more restrictive!
			factor = 0
			ai_greed >= high_positive_ai_value
			scope:secondary_recipient = {
				NOR = { # Very Greedy rulers only ransom people in their own realm, or their heir
					is_courtier_of = scope:actor
					is_vassal_or_below_of = scope:actor
					is_heir_of = scope:actor
				}
				NOR = {
					is_heir_of = scope:actor
					is_close_or_extended_family_of = scope:actor
					is_consort_of = scope:actor
					has_relation_friend = scope:actor
					has_relation_lover = scope:actor
					has_secret_relation_lover = scope:actor
					any_spouse = {
						OR = {
							is_heir_of = scope:actor
							is_close_or_extended_family_of = scope:actor
							has_relation_friend = scope:actor
						}
					}
				}
			}
		}
		
		# Some exceptions!
		modifier = { # Lustful characters want to ransom lovers
			add = 100
			has_trait = lustful
			ai_greed <= 50
			scope:secondary_recipient = {
				has_relation_lover = scope:actor
			}
			OR = {
				scope:gold = yes
				scope:extortionate_gold = yes
				AND = {
					scope:actor = {
						gold >= 25
					}
					scope:secondary_recipient = {
						time_in_prison = { years > 1 }
					}
					OR = {
						scope:current_gold = yes
						scope:extortionate_current_gold = yes
					}
				}
			}
		}
		
		modifier = { # Loyal characters want to ransom their relations
			add = 100
			has_trait = loyal
			scope:secondary_recipient = {
				OR = {
					has_relation_lover = scope:actor
					has_relation_friend = scope:actor
				}
			}
			OR = {
				scope:gold = yes
				scope:extortionate_gold = yes
				AND = {
					scope:actor = {
						gold >= 25
					}
					scope:secondary_recipient = {
						time_in_prison = { years > 1 }
					}
					OR = {
						scope:current_gold = yes
						scope:extortionate_current_gold = yes
					}
				}
			}
		}
		
		modifier = { # Certain characters will try to ransom their liege!
			add = 100
			ai_greed <= very_high_negative_ai_value
			ai_compassion >= very_high_negative_ai_value
			NOT = { exists = joined_faction }
			is_at_war = no
			OR = {
				has_trait = loyal
				ai_honor >= high_positive_ai_value
			}
			scope:secondary_recipient = {
				is_liege_or_above_of = scope:actor
			}
			OR = {
				scope:gold = yes
				scope:extortionate_gold = yes
				# They won't offer current gold, only full ransoms
			}
		}
		
		modifier = { # Favors only relevant within the realm
			add = -100
			scope:favor = yes
			scope:recipient = {
				NOR = {
					is_vassal_of = scope:actor
					AND = {
						exists = liege
						liege = scope:actor
					}
				}
			}
		}
		
		modifier = { # Don't spam the player with cheapskate offers
			add = -100
			scope:current_gold = yes
			scope:recipient = {
				is_ai = no
			}
			scope:secondary_recipient = {
				highest_held_title_tier >= tier_duchy
			}
		}

		# Struggle Agenda
		modifier = {
			scope:secondary_recipient = {
				any_character_struggle = {
					involvement = involved
				}
			}
			scope:actor = {
				any_character_struggle = {
					involvement = involved
				}
			}
			add = {
				value = 0
				if = {
					limit = {
						scope:actor = {
							any_character_struggle = {
								phase_has_catalyst = catalyst_ransom_important
							}
							has_character_flag = agenda_towards_escalation
						}
					}
					add = -100
				}
				else_if = {
					limit = {
						scope:actor = {
							any_character_struggle = {
								phase_has_catalyst = catalyst_ransom_important
							}
						}
					}
					add = 200
				}
			}
		}

		evaluate_action_increasing_house_unity = {
			VALUE = 100
		}
		
		modifier = { # Don't give away prisoners for free
			factor = 0
			NOR = {
				scope:favor = yes
				scope:extortionate_gold = yes
				scope:extortionate_current_gold = yes
				scope:gold = yes
				AND = {
					scope:actor = {
						gold >= 25
					}
					scope:current_gold = yes
				}
			}
		}
		
		modifier = { # Don't annoy players
			factor = 0
			scope:recipient = { is_ai = no }
			OR = {
				scope:recipient = { is_at_war = yes }
				scope:secondary_recipient = { has_character_flag = character_ransom_refused_by_player }
			}
		}
	}
}

#To ransom yourself
ransom_me_interaction = {
	interface_priority = 50
	common_interaction = yes
	use_diplomatic_range = no
	category = interaction_category_prison
	icon = icon_gold

	greeting = positive
	notification_text = PAY_RANSOM_PROPOSAL_PERSONAL

	desc = ransom_me_interaction_desc

	redirect = { # So that users can ransom themselves by clicking on their portrait
		if = {
			limit = {
				scope:actor = scope:recipient
				exists = scope:actor.imprisoner
			}
			scope:actor.imprisoner = { save_scope_as = recipient }
		}
	}
	
	is_shown = {
		scope:actor = {
			is_imprisoned_by = scope:recipient
		}
	}

	is_valid_showing_failures_only = {
		scope:recipient = { is_busy_in_events_localised = yes } #Imprisoner
		scope:actor = { is_busy_in_events_localised = yes } #Prisoner
		scope:recipient = {
			custom_description = {
				text = "currently_being_tortured"
				NOT = { has_character_flag = is_being_tortured }
			}
		}
		cannot_release_former_regent_whilst_old_regent_holds_power_trigger = {
			PRISONER = scope:recipient
			REGENT = scope:recipient.var:imprisoned_by_diarch
		}
	}
	
	on_accept = {
		if = {
			limit = { scope:actor = { is_imprisoned_by = scope:recipient } }
			scope:actor = {
				save_scope_as = prisoner
			}
			scope:recipient = {
				save_scope_as = imprisoner
			}
			scope:actor = {
				save_scope_as = payer
				
				# If the payer doesn't have enough funds to pay the full amount and we're only requesting their current funds, save how much they've agreed to pay.
				if = {
					limit = {
						OR = {
							exists = scope:current_gold
							exists = scope:extortionate_current_gold
						}
					}
					save_scope_value_as = {
						name = ransom_saved_gold_value
						value = scope:payer.current_gold_value
					}
				}

				# Must come after we save the payment value, or the payer won't know how much they need to pay.
				trigger_event = char_interaction.0150
			}
			scope:imprisoner = {
				send_interface_message = {
					type = event_generic_neutral
					title = recipient_released_from_prison
					right_icon = scope:prisoner
					left_icon = scope:imprisoner
					ransom_interaction_effect = yes
				}

				# Struggle Catalyst
				if = {
					limit = {
						any_character_struggle = {
							involvement = involved
							activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
								CATALYST = catalyst_ransom_important
								CHAR = scope:prisoner
							}
						}
					}
					every_character_struggle = {
						involvement = involved
						limit = {
							activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
								CATALYST = catalyst_ransom_important
								CHAR = scope:prisoner
							}
						}
						activate_struggle_catalyst = {
							catalyst = catalyst_ransom_important
							character = scope:imprisoner
						}
					}
				}
			}
			if = {
				limit = { always = scope:hook }
				scope:actor = {
					use_hook = scope:recipient
				}
			}
		}
	}

	on_decline = {
		# If a player declines this ransom offer, wait 10 years before sending another one (they presumably have reasons for keeping you in prison).
		if = {
			limit = { scope:recipient = { is_ai = no } }
			scope:actor = {
				add_character_flag = {
					flag = character_ransom_refused_by_player
					years = 10
				}
			}
		}		

		# Trigger notification event
		scope:actor = {
			trigger_event = char_interaction.0151
		}
	}
	
	send_option = {
		is_shown = {
			exists = scope:recipient
			scope:recipient = {
				exists = dynasty
				dynasty = {
					has_dynasty_perk = fp1_pillage_legacy_3
				}
			}
		}
		is_valid = {
			scope:actor = {
				gold >= increased_ransom_cost
			}
		}
		flag = extortionate_gold
		localization = "RANSOM_EXTORTIONATE_GOLD_IMPRISONED_PERSPECTIVE_OPTION"
	}

	# If you don't have what they're worth, pay me what you have (extort version)!
	send_option = {
		is_shown = {
			exists = scope:recipient
			scope:recipient = {
				exists = dynasty
				dynasty = {
					has_dynasty_perk = fp1_pillage_legacy_3
				}
			}
			scope:actor = {
				gold < increased_ransom_cost
				gold > 0
			}
		}
		flag = extortionate_current_gold
		localization = "RANSOM_EXTORTIONATE_CURRENT_GOLD_IMPRISONED_PERSPECTIVE_OPTION"
	}
	
	send_option = {
		is_shown = {
			exists = scope:recipient
			scope:recipient = {
				OR = {
					is_lowborn = yes
					NOT = {
						dynasty = {
							has_dynasty_perk = fp1_pillage_legacy_3
						}
					}
				}
			}
		}
		is_valid = {
			scope:actor = {
				gold >= ransom_cost
			}
		}
		flag = gold
		localization = "RANSOM_GOLD_OPTION"
	}

	# If you don't have what they're worth, pay me what you have!
	send_option = {
		is_shown = {
			exists = scope:recipient
			scope:recipient = {
				OR = {
					is_lowborn = yes
					NOT = {
						dynasty = {
							has_dynasty_perk = fp1_pillage_legacy_3
						}
					}
				}
			}
			scope:actor = {
				gold < ransom_cost
				gold > 0
			}
		}
		flag = current_gold
		localization = "RANSOM_CURRENT_GOLD_OPTION"
	}
	
	send_option = {
		is_valid = {
			scope:recipient = {
				can_add_hook = { #To match the hook added through ransom_interaction_effect
					target = scope:actor
					type = favor_hook
				}
			}
		}
		flag = favor
		localization = "RANSOM_FAVOR_OPTION"
	}

	#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
	
	localization_values = {
		EXTORTIONATE_RANSOM_COST = scope:actor.increased_ransom_cost_value
		RANSOM_COST = scope:actor.ransom_cost_value
		CURRENT_GOLD = scope:actor.gold
	}
	
	ai_accept = {
		base = 0
		modifier = {
			add = 50
			OR = {
				scope:gold = yes
				scope:extortionate_gold = yes
			}
			desc = "GOLD_POSITIVE_REASON"
		}
		
		modifier = { # Accept more than half the ransom (unless greedy)
			add = 25
			scope:current_gold = yes
			AND = {
				scope:actor = { gold >= half_ransom_cost_value }
				NOT = { scope:recipient.ai_greed >= medium_positive_ai_value }
			}
			desc = "GOLD_POSITIVE_REASON"
		}
		
		modifier = { # Accept more than half the ransom (unless greedy)
			add = 25
			scope:extortionate_current_gold = yes
			AND = {
				scope:actor = { gold >= half_increased_ransom_cost_value }
				NOT = { scope:recipient.ai_greed >= medium_positive_ai_value }
			}
			desc = "GOLD_POSITIVE_REASON"
		}
		
		modifier = {
			add = 50
			scope:favor = yes
			scope:recipient.top_liege = scope:actor.top_liege
			desc = "FAVOR_POSITIVE_REASON"
		}
		
		modifier = {
			add = -50
			scope:favor = yes
			NOR = {
				scope:gold = yes
				scope:extortionate_gold = yes
			}
			OR = {
				NOT = { scope:recipient.top_liege = scope:actor.top_liege }
				scope:recipient.ai_greed >= medium_positive_ai_value
			}
			desc = "NO_USE_FOR_A_FAVOR_REASON"
		}
		
		modifier = { # For clarification
			add = 0
			OR = {
				scope:current_gold = yes
				scope:extortionate_current_gold = yes
			}
			OR = {
				scope:actor = { gold < half_ransom_cost_value }
				scope:recipient.ai_greed >= medium_positive_ai_value
			}
			desc = "WANTS_MORE_GOLD"
		}
		
		#opinion_modifier = { # A lot more likely if Recipient likes Actor
		#	who = scope:recipient
		#	opinion_target = scope:actor
		#	multiplier = 1.0
		#	desc = AI_OPINION_REASON
		#}
		
		modifier = { # Say no to rivals
			add = -55
			scope:recipient = {
				has_relation_rival = scope:actor
			}
			desc = "ACTOR_RIVAL_TO_ME_REASON"
		}
		modifier = { # Say no to nemesis
			add = -300
			scope:recipient = {
				has_relation_nemesis = scope:actor
			}
			desc = "ACTOR_NEMESIS_TO_ME_REASON"
		}
		
		
		modifier = { # At war
			add = -300
			scope:recipient = {
				is_at_war_with = scope:actor
			}
			desc = "IS_AT_WAR_REASON"
		}

		modifier = {
			scope:hook = yes
			add = 100
			desc = SCHEME_WEAK_HOOK_USED
		}
		
		modifier = { # An Intimidated recipient is significantly more likely to accept an offer from the liege
			add = intimidated_reason_value
			trigger = {
				scope:recipient = {
					target_is_liege_or_above = scope:actor
					has_dread_level_towards = {
						target = scope:actor
						level = 1
					}
				}
			}
			desc = INTIMIDATED_REASON
		}

		modifier = { # A Cowed recipient is significantly more likely to accept an offer from the liege
			add = cowed_reason_value
			trigger = {
				scope:recipient = {
					target_is_liege_or_above = scope:actor
					has_dread_level_towards = {
						target = scope:actor
						level = 2
					}
				}
			}
			desc = COWED_REASON
		}
		modifier = { # Family Feud
			add = -50
			trigger = {
				exists = scope:actor.house
				exists = scope:recipient.house
				scope:recipient = {
					house.house_head = {
						any_owned_story = {
							story_type = story_cycle_house_feud
							has_variable = house_feud_house
							var:house_feud_house = scope:actor.house
						}
					}
					has_opinion_modifier = {
						modifier = house_feud_opinion
						target = scope:actor.house.house_head
					}
				}
			}
			desc = INTERACTION_FAMILY_FEUD_REVERSE_REASON
		}
	}

	auto_accept = {
		custom_description = {
			text = "spending_hook"
			subject = scope:actor
			object = scope:recipient
			scope:hook = yes
			scope:actor = { has_strong_hook = scope:recipient }
		}
	}
	
	# AI
	ai_frequency = 24
	
	ai_targets = {
		ai_recipients = self
	}

	ai_potential = {
		always = yes
	}

	ai_will_do = {
		base = 0 

		modifier = {
			add = 100
			OR = {
				scope:gold = yes
				scope:extortionate_gold = yes
				AND = {
					scope:actor = {
						gold >= 25
					}
					OR = {
						time_in_prison = { years > 1 }
						has_trait = impatient #LET ME OUT! I want out! NOW!
					}
					OR = {
						scope:current_gold = yes
						scope:extortionate_current_gold = yes
					}
				}
			}
		}

		modifier = {
			add = 100
			scope:favor = yes
			scope:recipient = {
				OR = {
					is_vassal_of = scope:actor
					AND = {
						exists = liege
						liege = scope:actor
					}
				}
			}
		}
		
		modifier = {
			add = -100
			scope:favor = yes
			scope:recipient = {
				NOR = {
					is_vassal_of = scope:actor
					AND = {
						exists = liege
						liege = scope:actor
					}
				}
			}
		}

		# Struggle Agenda
		modifier = {
			scope:recipient = {
				any_character_struggle = {
					involvement = involved
				}
			}
			scope:actor = {
				any_character_struggle = {
					involvement = involved
				}
			}
			add = {
				value = 0
				if = {
					limit = {
						scope:actor = {
							any_character_struggle = {
								phase_has_catalyst = catalyst_ransom_important
							}
							has_character_flag = agenda_towards_escalation
						}
					}
					add = -100
				}
				else_if = {
					limit = {
						scope:actor = {
							any_character_struggle = {
								phase_has_catalyst = catalyst_ransom_important
							}
						}
					}
					add = 200
				}
			}
		}

		modifier = { # Don't give away prisoners for free
			factor = 0
			NOR = {
				scope:favor = yes
				scope:gold = yes
				scope:extortionate_gold = yes
				scope:current_gold = yes
				AND = {
					scope:actor = {
						gold >= 25
					}
					scope:current_gold = yes
				}
			}
		}

		modifier = { # Don't annoy players
			factor = 0
			scope:recipient = { is_ai = no }
			OR = {
				scope:recipient = { is_at_war = yes }
				scope:actor = { has_character_flag = character_ransom_refused_by_player }
			}
		}
	}
}

release_from_prison_interaction = {
	interface_priority = 30
	common_interaction = yes
	category = interaction_category_prison
	special_interaction = release_from_prison_interaction
	icon = prison

	desc = release_from_prison_interaction_desc

	notification_text = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:demand_conversion = no
					scope:renounce_claims = no
					scope:banish = no
					scope:take_vows = no
					scope:recruit = no
				}
				desc = RELEASE_PRISONER_OFFER
			}
			desc = RELEASE_PRISONER_OFFER_CONDITIONAL
		}
	}
	
	is_shown = {
		scope:recipient = {
			is_imprisoned_by = scope:actor
		}
	}

	is_valid_showing_failures_only = {
		scope:recipient = { is_busy_in_events_localised = yes } #Prisoner
		scope:recipient = {
			custom_description = {
				text = "currently_being_tortured"
				NOT = { has_character_flag = is_being_tortured }
			}
		}
		cannot_release_former_regent_whilst_old_regent_holds_power_trigger = {
			PRISONER = scope:recipient
			REGENT = scope:recipient.var:imprisoned_by_diarch
		}
	}
	
	on_accept = {
		scope:actor = {
			hidden_effect = {
				if = {
					limit = { 
						AND = {
							exists = scope:actor.var:RE_court_intr_2_var
							scope:actor.var:RE_court_intr_2_var >= 1
						}
					}
					scope:actor = {
						change_variable = {
							name = RE_court_intr_2_var
							add = -1
						}
						RE_axis_recount_intr = yes
					}
				}
				else_if = {
					limit = { 
						exists = scope:actor.var:RE_court_intr_2_var
					}
					scope:actor = {
						set_variable = {
							name = RE_court_intr_2_var
							value = 0
						}
					}
				}
				else = {}
			}
		}
	
		if = {
			limit = { scope:recipient = { has_character_modifier = allowed_to_go_outside } }
			scope:recipient = { remove_character_modifier = allowed_to_go_outside }
		}
		if = {
			limit = { scope:recipient = { has_character_modifier = moldy_gruel_diet } }
			scope:recipient = { remove_character_modifier = moldy_gruel_diet }
		}
		if = {
			limit = { scope:recipient = { is_imprisoned_by = scope:actor } }

			scope:recipient = {
				# Demand Conversion
				if = {
					limit = {
						scope:demand_conversion = yes
					}
					demand_conversion_interaction_effect = yes
					add_opinion = {
						modifier = demanded_my_conversion_opinion
						target = scope:actor
					}

					# Struggle Catalyst
					if = {
						limit = {
							scope:actor = {
								any_character_struggle = {
									involvement = involved
									activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
										CATALYST = catalyst_demanding_important_conversion
										CHAR = scope:recipient
									}
								}
							}
						}
						scope:actor = {
							every_character_struggle = {
								involvement = involved
								limit = {
									activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
										CATALYST = catalyst_demanding_important_conversion
										CHAR = scope:recipient
									}
								}
								activate_struggle_catalyst = {
									catalyst = catalyst_demanding_important_conversion
									character = scope:actor
								}
							}
						}
					}
				}
				
				# Banish Landed Character
				if = {
					limit = {
						scope:banish = yes
						scope:recipient = { is_landed = yes	}
					}
					#AGOT Modified, add NW banishment
					# banish = yes
					if = {
						limit = {
							agot_nw_can_banish = { BANISHER = scope:actor BANISHEE = scope:recipient }
						}

						if = {
							limit = {
								OR = {
									AND = {
										scope:actor = {
											has_banish_reason = scope:recipient
										}
										has_trait_xp = {
											trait = maester
											value = 100
										}
									}
									has_trait_xp = {
										trait = maester
										value < 100
									}
								}
							}
							agot_expel_appropriate_maester_effect = yes
						}
						agot_send_to_nightswatch_effect = {
							ACTOR = scope:actor
							NIGHTSWATCH_CANDIDATE = scope:recipient
						}
					}
					else = {
						agot_banish_effect = { BANISHER = scope:actor }
					}
					if = {
						limit = {
							NOT = {
								scope:actor = {
									has_banish_reason = scope:recipient
								}
							}
						}
						scope:actor = { add_tyranny = banishment_tyranny_gain }
					}
					add_opinion = {
						modifier = banished_me
						target = scope:actor
					}
				}
				# Banish Unlanded Character
				else_if = {
					limit = {
						AND = {
							scope:banish = yes
							scope:recipient = {
								is_landed = no
								is_pool_character = no # It is possible for them to end up in the pool between the interaction being sent, and it being accepted
							}
						}
					}
					if = {
						limit = {
							this.gold > 0
							NOT = {
								has_character_flag = realm_priest
							}
						}
						pay_short_term_gold = { target = scope:actor gold = this.gold }
					}
					if = {
						limit = {
							has_any_artifact = yes
						}
						every_character_artifact = {
							#AGOT Modified
							limit = { NOT = { has_variable = maesterwork } }
							set_owner = {
								target = scope:actor
								history = {
									location = scope:recipient.location
									actor = scope:recipient
									recipient = scope:actor
									type = stolen
								}
							}
							scope:actor = {
								if = {
									limit = {
										NOT = { has_variable = stolen_artifact }
									}
									set_variable = {
										name = stolen_artifact
										value = 1
									}
								}
								else = {
									change_variable = {
										name = stolen_artifact
										add = 1
									}
								}
							}
						}
					}
					#AGOT Modified, add NW banishment
					# banish = yes
					if = {
						limit = {
							agot_nw_can_banish = { BANISHER = scope:actor BANISHEE = scope:recipient }
						}
						if = {
							limit = {
								OR = {
									AND = {
										scope:actor = {
											has_banish_reason = scope:recipient
										}
										has_trait_xp = {
											trait = maester
											value = 100
										}
									}
									has_trait_xp = {
										trait = maester
										value < 100
									}
								}
							}
							agot_expel_appropriate_maester_effect = yes
						}
						agot_send_to_nightswatch_effect = {
							ACTOR = scope:actor
							NIGHTSWATCH_CANDIDATE = scope:recipient
						}
					}
					else = {
						agot_banish_effect = { BANISHER = scope:actor }
					}
					add_opinion = {
						modifier = banished_me
						target = scope:actor
					}
				}
				# 'Banish' Pool Character
				else_if = {
					limit = {
						AND = {
							scope:banish = yes
							scope:recipient = {
								is_landed = no
								is_pool_character = yes # They'll just leave for the pool
							}
						}
					}
					if = {
						limit = {
							this.gold > 0
						}
						pay_short_term_gold = { target = scope:actor gold = this.gold }
					}		

					#AGOT Added, add NW banishment
					if = {
						limit = {
							agot_nw_can_banish = { BANISHER = scope:actor BANISHEE = scope:recipient }
						}
						if = {
							limit = {
								OR = {
									AND = {
										scope:actor = {
											has_banish_reason = scope:recipient
										}
										has_trait_xp = {
											trait = maester
											value = 100
										}
									}
									has_trait_xp = {
										trait = maester
										value < 100
									}
								}
							}
							agot_expel_appropriate_maester_effect = yes
						}
						agot_send_to_nightswatch_effect = {
							ACTOR = scope:actor
							NIGHTSWATCH_CANDIDATE = scope:recipient
						}
					}

					add_opinion = {
						modifier = banished_me
						target = scope:actor
					}
				}

				# AGOT Added, Banish to Essos - Landed Character
				if = {
					limit = {
						scope:agot_banish_to_essos = yes
						scope:recipient = {
							is_landed = yes
						}
					}
					if = {
						limit = {
							OR = {
								AND = {
									scope:actor = {
										has_banish_reason = scope:recipient
									}
									has_trait_xp = {
										trait = maester
										value = 100
									}
								}
								has_trait_xp = {
									trait = maester
									value < 100
								}
							}
						}
						agot_expel_appropriate_maester_effect = yes
					}
					agot_sent_to_essos_effect = {
						ACTOR = scope:actor
						TARGET = scope:recipient
					}
					if = {
						limit = {
							NOT = {
								scope:actor = {
									has_banish_reason = scope:recipient
								}
							}
						}
						scope:actor = { add_tyranny = banishment_tyranny_gain }
					}
					add_opinion = {
						modifier = banished_me
						target = scope:actor
					}
				}
				# AGOT Added, Banish to Essos - Unlanded Character
				else_if = {
					limit = {
						AND = {
							scope:agot_banish_to_essos = yes
							scope:recipient = {
								is_landed = no
								is_pool_character = no # It is possible for them to end up in the pool between the interaction being sent, and it being accepted
							}
						}
					}
					if = {
						limit = {
							this.gold > 0
							NOT = {
								has_character_flag = realm_priest
							}
						}
						pay_short_term_gold = { target = scope:actor gold = this.gold }
					}
					if = {
						limit = {
							has_any_artifact = yes
						}
						every_character_artifact = {
							limit = { NOT = { has_variable = maesterwork } }
							set_owner = {
								target = scope:actor
								history = {
									location = scope:recipient.location
									actor = scope:recipient
									recipient = scope:actor
									type = stolen
								}
							}
							scope:actor = {
								if = {
									limit = {
										NOT = { has_variable = stolen_artifact }
									}
									set_variable = {
										name = stolen_artifact
										value = 1
									}
								}
								else = {
									change_variable = {
										name = stolen_artifact
										add = 1
									}
								}
							}
						}
					}
					if = {
						limit = {
							OR = {
								AND = {
									scope:actor = {
										has_banish_reason = scope:recipient
									}
									has_trait_xp = {
										trait = maester
										value = 100
									}
								}
								has_trait_xp = {
									trait = maester
									value < 100
								}
							}
						}
						agot_expel_appropriate_maester_effect = yes
					}
					agot_sent_to_essos_effect = {
						ACTOR = scope:actor
						TARGET = scope:recipient
					}
					add_opinion = {
						modifier = banished_me
						target = scope:actor
					}
				}
				# AGOT Added, Banish to Essos - Pool Character
				else_if = {
					limit = {
						AND = {
							scope:agot_banish_to_essos = yes
							scope:recipient = {
								is_landed = no
								is_pool_character = yes # They'll just leave for the pool
							}
						}
					}
					if = {
						limit = {
							this.gold > 0
						}
						pay_short_term_gold = { target = scope:actor gold = this.gold }
					}
					if = {
						limit = {
							OR = {
								AND = {
									scope:actor = {
										has_banish_reason = scope:recipient
									}
									has_trait_xp = {
										trait = maester
										value = 100
									}
								}
								has_trait_xp = {
									trait = maester
									value < 100
								}
							}
						}
						agot_expel_appropriate_maester_effect = yes
					}
					agot_sent_to_essos_effect = {
						ACTOR = scope:actor
						TARGET = scope:recipient
					}
					add_opinion = {
						modifier = banished_me
						target = scope:actor
					}
				}

				# Recruit Character
				if = {
					limit = {
						scope:recruit = yes
					}
					if = {
						limit = {
							scope:actor = {
								culture = {
									has_cultural_parameter = can_recruit_prisoners_easily
								}
							}
						}
						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 = {
							modifier = demanded_recruitment
							target = scope:actor
						}
					}
					scope:actor = {
						if = {
							limit = {
								AND = {
									scope:actor.faith = { 
										has_doctrine = tenet_communal_possessions 
									}
									scope:recipient = {
										has_trait = peasant_leader
									}
								}
							}
							scope:actor = { 
								add_piety = medium_piety_gain
							}
						}
					}
					scope:actor = {
						add_courtier = scope:recipient
					}
				}
				
				# Renounce Claims
				if = {
					limit = {
						scope:renounce_claims = yes
					}
					add_opinion = {
						modifier = demanded_claim_renouncement
						target = scope:actor
					}
					scope:recipient = {
						every_claim = {
							explicit = yes
							limit = {
								save_temporary_scope_as = temp_claim
								OR = {
									holder = scope:actor
									AND = {
										exists = holder
										NOT = { prev = { target_is_liege_or_above = scope:actor } }
										holder = { target_is_liege_or_above = scope:actor }
									}
									scope:actor = {
										any_held_title = {
											is_de_jure_liege_or_above_target = scope:temp_claim
										}
									}
								}
							}
							scope:recipient = { remove_claim = prev }
						}
					}
				}
				
				# Gain Hook
				if = {
					limit = {
						scope:gain_hook = yes
					}
					add_opinion = {
						modifier = demanded_hook
						target = scope:actor
					}
					scope:actor = {
						add_hook = { #Hook effect must match gain_hook option condition
							target = scope:recipient
							type = favor_hook
						}
					}
				}
				
				# Take Vows
				if = {
					limit = {
						scope:take_vows = yes
					}
					send_child_to_clergy_effect = yes
				}
				
				# Take Vows
				if = {
					limit = {
						scope:become_executioner = yes
					}
					release_as_executioner_effect = yes
				}

				#AGOT Added, MW switch sides
				if = {
					limit = {
						scope:mega_war_switch_sides = yes
					}

					agot_mw_fetch_story_scopes_of_chars_effect = { CHARACTER_1 = scope:actor CHARACTER_2 = scope:recipient }

					scope:actor = {
						if = { # switch to rebels?
							limit = {
								any_ruler = {
									any_owned_story = {
										story_type = story_agot_mw_crown
										is_target_in_variable_list = { name = mw_loyalist_list target = scope:recipient }
									}
								}
							}
							agot_mw_join_rebels_effect = { RULER = scope:recipient REBEL_LEADER = scope:mw_rebel_story.story_owner }
						}
						else = {
							agot_mw_join_loyalists_effect = { RULER = scope:recipient CROWN = scope:mw_crown_story.story_owner }
						}
					}
				}
				#AGOT Added, Strip Knighthood
				if = {
					limit = {
						scope:agot_strip_knighthood = yes
					}
					agot_strip_knighthood_as_punishment_effect = { STRIPPER = scope:actor KNIGHT = scope:recipient }
				}
				
				# No Demands Added
				if = {
					limit = {
						scope:demand_conversion = no
						scope:renounce_claims = no
						scope:banish = no
						scope:gain_hook = no
						scope:take_vows = no
						scope:become_executioner = no
						scope:recruit = no
						#AGOT Added
						scope:mega_war_switch_sides = no
						scope:agot_strip_knighthood = no
						scope:agot_banish_to_essos = no
					}
					# Notification to the imprisoner
					scope:actor = {
						send_interface_toast = {
							title = recipient_released_from_prison
							left_icon = scope:recipient
							scope:recipient = {
								add_opinion = {
									modifier = released_from_prison
									target = scope:actor
								}
							}
						}
						scope:actor = {
							add_dread = minor_dread_loss
							stress_impact = {
								sadistic = medium_stress_impact_gain
								callous = minor_stress_impact_gain
							}
						}
						# Struggle impact
						if = {
							limit = {
								any_character_struggle = {
									involvement = involved
									#AGOT Modified
									#is_struggle_type = iberian_struggle
									is_struggle_type = btw_struggle
									OR = {
										has_struggle_phase_parameter = release_prisoner_diff_culture_gives_prestige
										#AGOT Disabled
										#has_struggle_phase_parameter = release_prisoner_diff_faith_gives_prestige
									}
								}
								#AGOT Modified, no faith in struggle
								#is_diff_faith_or_culture_trigger = {
								is_diff_culture_trigger = {
									CHAR = scope:recipient
									STATUS = involved
								}
							}
							add_prestige = medium_prestige_gain
						}

						# Struggle Catalyst
						if = {
							limit = {
								any_character_struggle = {
									involvement = involved
									activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
										CATALYST = catalyst_release_important
										CHAR = scope:recipient
									}
								}
							}
							every_character_struggle = {
								involvement = involved
								limit = {
									activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
										CATALYST = catalyst_release_important
										CHAR = scope:recipient
									}
								}
								activate_struggle_catalyst = {
									catalyst = catalyst_release_important
									character = scope:actor
								}
							}
						}
						#AGOT Disabled
						# if = {
						# 	limit = {
						# 		fp3_struggle_involves_one_supporter_and_one_detractor = {
						# 			FIRST = scope:actor
						# 			SECOND = scope:recipient
						# 		}
						# 		any_character_struggle = {
						# 			involvement = involved
						# 			activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
						# 				CATALYST = catalyst_release_supporter_detractor
						# 				CHAR = scope:recipient
						# 			}
						# 		}
						# 	}
						# 	every_character_struggle = {
						# 		involvement = involved
						# 		limit = {
						# 			activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
						# 				CATALYST = catalyst_release_supporter_detractor
						# 				CHAR = scope:recipient
						# 			}
						# 		}
						# 		activate_struggle_catalyst = {
						# 			catalyst = catalyst_release_supporter_detractor
						# 			character = scope:actor
						# 		}
						# 		log_debug_variable_for_persian_struggle_effect = { VAR = concession_catalyst_release_supporter_detractor }
						# 	}
						# }
					}
					
					# If we're a clan (and not making any demands) this interaction affects unity
					add_clan_unity_interaction_effect = {
						CHARACTER = scope:actor
						TARGET = scope:recipient
						VALUE = minor_unity_gain
						DESC = clan_unity_released_from_own_prison.desc
						REVERSE_NON_HOUSE_TARGET = no
					}

					# LEGITIMACY GAIN FROM RELEASING DUKES AND ABOVE
					if = {
						limit = {
							exists = scope:recipient.primary_title
							scope:recipient.primary_title.tier >= tier_duchy
						}
						# Minus 2, since we want Duchy to be 1, and it's normally 3
						save_scope_value_as = {
							name = title_tier_minus_2
							value = {
								value = scope:recipient.primary_title.tier
								subtract = 2
							}
						}
						scope:actor = {
							send_interface_toast = {
								type = event_toast_effect_good
								title = legitimacy_gain_toast
								left_icon = scope:actor
								right_icon = scope:recipient
								add_legitimacy = {
									value = {
										value = miniscule_legitimacy_gain
										multiply = scope:title_tier_minus_2
									}
								}
							}
						}
					}
				}
				else = {
					scope:actor = {
						trigger_event = char_interaction.0160
					}
				}

				# If a child was imprisoned due to yearly_4021 they'll come back to say hi
				if = {
					limit = {
						exists = var:marked_for_revenge_in_event_yearly_4021
					}
					add_opinion = {
						modifier = abandoned_me_opinion
						target = var:marked_for_revenge_in_event_yearly_4021
					}
					if = {
						limit = {
							var:marked_for_revenge_in_event_yearly_4021 = {
								is_alive = yes
								is_ai = no
							}
						}
						save_scope_as = child
						if = {
							limit = { #Make sure they're sadistic!
								NOT = { has_trait = sadistic }
								number_of_personality_traits < personality_trait_limit
							}
							add_trait = sadistic
						}
						var:marked_for_revenge_in_event_yearly_4021 = {
							add_character_flag = { #TO make sure that they don't get spammed about the release
								flag = block_for_prison_release_notification
								days = 10
							}
							trigger_event = yearly.4022
						}
						remove_variable = marked_for_revenge_in_event_yearly_4021
					}
				}

				if = {
					limit = { is_imprisoned = yes }
					release_from_prison = yes
				}
			}

			# FP3 - If prisoner is important for war
			scope:actor = { # FP3
				if = {
					limit = {
						exists = scope:recipient.house
						any_character_war = {
							using_cb = fp3_free_house_member_cb
							is_defender = scope:actor
							primary_attacker.house = scope:recipient.house
						}
					}
					random_character_war = {
						limit = {
							using_cb = fp3_free_house_member_cb
							is_defender = scope:actor
							primary_attacker.house = scope:recipient.house
						}
						primary_attacker = {
							hidden_effect = {
								send_interface_message = {
									type = event_war_good
									title = lesson_war_final_notes_victory_step_1
									left_icon = scope:recipient
									right_icon = scope:actor
								
									show_as_tooltip = {
										release_from_prison = scope:recipient
										add_prestige = major_prestige_gain
										prev.primary_defender = { add_prestige = major_prestige_loss }
									}
								}
							}
							add_prestige = major_prestige_gain
							prev.primary_defender = { add_prestige = major_prestige_loss }
						}
					}
				}
			}
		}
	}

	on_decline = {
		scope:actor = {
			trigger_event = char_interaction.0161
		}
	}
	
	send_option = {
		flag = demand_conversion
		localization = "RELEASE_DEMAND_CONVERSION"
		is_shown = {
			NOT = { scope:recipient.faith = scope:actor.faith }
			# AGOT Added, NW doesn't care about faith
			scope:actor = {
				NOT = { has_trait = nightswatch }
			}
		}
		is_valid = {
			trigger_if = {
				limit = {
					scope:actor = { is_ai = yes }
				}
				scope:recipient = {
					OR = {
						is_close_or_extended_family_of = scope:actor
						is_vassal_of = scope:actor
					}
				}
			}

			# Cannot ask Landed Rulers to convert if they're not your vassal
			custom_description = {
				text = cannot_demand_unsubordinate_landed_ruler_conversion
				scope:recipient = {
					trigger_if = {
						limit = {
							is_landed = yes
						}
						is_vassal_or_below_of = scope:actor
					}
				}
			}

			# Cannot ask Religious Heads to convert
			custom_description = {
				text = cannot_demand_religious_head_conversion
				NOT = {
					AND = {
						exists = scope:recipient.faith.religious_head
						scope:recipient.faith.religious_head = scope:recipient
					}
				}
			}
			# Cannot ask Holy Order Master to convert
			custom_description = {
				text = cannot_demand_holy_order_master_conversion
				NAND = {
					exists = scope:recipient.faith
					scope:recipient.faith = {
						any_faith_holy_order = { leader = scope:recipient }
					}
				}
			}
		}
	}
	
	send_option = {
		flag = renounce_claims
		localization = RELEASE_RENOUNCE_CLAIMS
		is_shown = {
			custom_description = {
				text = "release_renounce_claims"
				subject = scope:recipient
				scope:recipient = {
					any_claim = {
						explicit = yes
						save_temporary_scope_as = temp_claim
						OR = {
							holder = scope:actor
							AND = {
								NOT = { prev = { target_is_liege_or_above = scope:actor } }
								trigger_if = {
									limit = {
										exists = holder
									}
									holder = { target_is_liege_or_above = scope:actor }
								}
							}
							scope:actor = {
								any_held_title = {
									is_de_jure_liege_or_above_target = scope:temp_claim
								}
							}
						}
					}
				}
			}
		}
		current_description = {
			desc = RELEASE_RENOUNCE_CLAIMS_DESC
		}
	}
	
	send_option = {
		flag = banish
		localization = "RELEASE_BANISH"
		is_shown = {
			trigger_if = {
				limit = {
					scope:actor = { is_ai = yes }
				}
				scope:recipient = {
					OR = {
						AND = {
							is_landed = no
							is_ruler = no
							gold > scope:actor.gold
							gold > scope:actor.medium_gold_value
							scope:actor.ai_greed > low_negative_ai_value
						}
						AND = {
							is_landed = no
							is_ruler = no
							gold > 0
							scope:actor = {
								has_banish_reason = scope:recipient
							}
						}
						AND = {
							is_landed = no
							is_ruler = no
							gold > 100
							scope:actor.ai_greed >= high_positive_ai_value
						}
						AND = {
							scope:actor = {
								has_banish_reason = scope:recipient
							}
							scope:actor = {
								opinion = {
									target = scope:recipient
									value <= medium_negative_opinion
								}
							}
						}
					}
				}
			}
			#AGOT Modified, can attempt to banish anyone
			# if they can be sent to NW, or are in the actor's realm or in the pool
			# trigger_if = {
			# 	limit = {
			# 		scope:recipient = {
			# 			is_landed = yes
			# 		}
			# 	}
			# 	scope:recipient = {
			# 		is_vassal_of = scope:actor
			# 	}
			# }
			# trigger_else = {
			# 	scope:recipient = {
			# 		is_courtier_of = scope:actor
			# 	}
			# }
			OR = {
				agot_nw_can_banish = { BANISHER = scope:actor BANISHEE = scope:recipient }
				scope:recipient = {
					OR = {
						target_is_liege_or_above = scope:actor
						is_pool_character = yes
					}
				}
			}
			custom_description = {
				text = "release_banish_invalid_take_vows"
				object = scope:recipient
				scope:take_vows = no
			}
			scope:recruit = no #Should be impossible to have both but just in case
			NOT = {
				scope:recipient = {
					is_spouse_of = scope:actor	
				}
			}
			#scope:recipient = {
			#	trigger_if = {
			#		limit = { exists = liege }
			#		liege = scope:actor
			#	}
			#	is_pool_character = no
			#}

			# AGOT Added, NW cannot banish
			scope:actor = {
				NOT = { has_trait = nightswatch }
			}
			scope:recipient = {
				NOT = { has_trait = nightswatch }
			}
			scope:agot_banish_to_essos = no
		}
	}
	
	send_option = {
		flag = gain_hook
		localization = "RELEASE_GAIN_HOOK"
		is_valid = {
			trigger_if = {
				limit = {
					scope:actor = { is_ai = yes }
				}
				scope:recipient = {
					OR = {
						is_vassal_of = scope:actor
						AND = {
							exists = liege
							liege = scope:actor
						}
					}
				}
			}
			scope:actor = {
				can_add_hook = {
					type = favor_hook #Matches the hook added in the on_accept
					target = scope:recipient
				}
			}
		}
	}
	
	
	send_option = {
		flag = take_vows
		localization = "RELEASE_TAKE_VOWS"
		is_shown = {
			scope:actor.faith = {
				has_doctrine_parameter = take_vows_active
			}
			# AGOT Added
			scope:actor = {
				NOT = { has_trait = nightswatch }
			}
			scope:recipient = {
				NOT = { has_trait = nightswatch }
			}
		}
		is_valid = {
			trigger_if = {
				limit = {
					scope:actor = { is_ai = yes }
				}
				scope:recipient = {
					is_close_or_extended_family_of = scope:actor
					NOT = {
						is_heir_of = scope:actor
					}
				}
				scope:actor = {
					opinion = {
						target = scope:recipient
						value <= medium_negative_opinion
					}
				}
			}
			scope:recipient = {
				custom_description = {
					text = "release_take_vows_invalid_recruit"
					object = scope:recipient
					OR = {
						is_courtier_of = scope:actor
						scope:recruit = yes
					}
				}

			}
			custom_description = {
				text = "release_vows_invalid_not_your_faith"
				object = scope:recipient
				subject = scope:actor
				trigger_if = {
					limit = {
						NOT = { scope:recipient.faith = scope:actor.faith }
					}
					scope:demand_conversion = yes
				}
			}
			custom_description = {
				text = "release_executioner_invalid_take_vows_condition"
				object = scope:recipient
				scope:become_executioner = no
			}
			custom_description = {
				text = "release_banish_invalid_take_vows"
				object = scope:recipient
				scope:banish = no
			}
			scope:recipient = {
				age >= 10
				NOR = {
					has_trait = excommunicated
					has_trait = devoted
					has_trait = incapable
				}
				#Do they have the "wrong" marriage type?
				NOR = {
					custom_description = {
						text = is_married_matrilineally
						subject = scope:recipient
						any_spouse = {
							is_female = yes
							matrilinear_marriage = yes
						}
					}
					custom_description = {
						text = is_married_patrilineally
						subject = scope:recipient
						any_spouse = {
							is_male = yes
							patrilinear_marriage = yes
						}
					}
					custom_description = {
						text = matrilinear_betrothal
						subject = scope:recipient
						exists = betrothed
						betrothed = {
							is_female = yes
							matrilinear_betrothal = yes
						}
					}
					custom_description = {
						text = patrilinear_betrothal
						subject = scope:recipient
						exists = betrothed
						betrothed = {
							is_male = yes
							patrilinear_betrothal = yes
						}
					}
				}
			}
		}
	}
	
	
	send_option = {
		flag = become_executioner
		localization = "RELEASE_AS_EXECUTIONER"
		is_shown = {
			has_ep1_court_positions_dlc_trigger = yes
			scope:actor = {
				has_royal_court = yes
			}
			scope:recipient = {
				is_adult = yes
			}
			#AGOT Added
			scope:recipient = {
				NOT = { has_trait = nightswatch }
			}
		}
		is_valid = {
			scope:actor = {
				NOT = { employs_court_position = executioner_court_position }
			}
			scope:recipient = {
				trigger_if = {
					limit = { scope:recruit = yes }
					custom_description = {
						text = "release_executioner_invalid_recruit"
						object = scope:recipient
						scope:recruit = yes
					}
				}
				trigger_else = {
					is_courtier_of = scope:actor
				}

				custom_description = {
					text = "release_executioner_invalid_take_vows_condition"
					object = scope:recipient
					scope:take_vows = no
				}
				NOT = { is_spouse_of = scope:actor  }
			}
		}
	}
	
	send_option = {
		flag = recruit
		localization = "RELEASE_RECRUIT"
		is_shown = {
			trigger_if = {
				limit = {
					scope:actor = { is_ai = yes }
				}
				scope:recipient = {
					OR = {
						has_relation_best_friend = scope:actor
						has_relation_friend = scope:actor
						has_relation_lover = scope:actor
						has_relation_soulmate = scope:actor
						has_secret_relation_lover = scope:actor
						is_heir_of = scope:actor
					}
				}
			}
			scope:recipient = {			
				is_ruler = no
				NOT = { is_courtier_of = scope:actor }
				OR = {
					is_adult = yes
					AND = {
						is_adult = no
						OR = {
							trigger_if = {
								limit = { exists = liege }
								NOT = { is_heir_of = liege }
							}
							NOT = { exists = liege } 
						}
					}				
				}					
			}
			#AGOT Added, NW can only forcibly recruit men over a certain age and wildling children
			trigger_if = {
				limit = {
					scope:actor = { has_trait = nightswatch }
				}
				NOR = {
					scope:recipient = { is_female = yes }
					scope:recipient = { age < 7 }
					AND = {
						scope:recipient.culture = { agot_is_wildling_culture = yes }
						scope:recipient = { age > 13 }
					}
				}
			}
			#AGOT Added, can't forcibly recruit a watchman
			scope:recipient = {
				NOT = { has_trait = nightswatch }
			}
		}
	}
	
	#AGOT Added
	send_option = {
		flag = mega_war_switch_sides
		localization = "MEGA_WAR_SWITCH_SIDES"
		is_shown = {
			custom_tooltip = {
				text = "MEGA_WAR_SWITCH_SIDES"
				agot_mw_switch_side_send_trigger = yes
			}
		}
	}

	#AGOT Added - AGOT Strip Knighthood
	send_option = {
		flag = agot_strip_knighthood
		localization = "agot_strip_knighthood"
		is_shown = {
			custom_tooltip = {
				text = "agot_strip_knighthood"
				agot_can_revoke_knighthood_punishment_trigger = yes
			}
		}
	}

	#AGOT Added - Banish to Essos
	send_option = {
		flag = agot_banish_to_essos
		localization = "agot_banish_to_essos"
		is_shown = {		# Mostly same as banish
			trigger_if = {
				limit = {
					scope:actor = { is_ai = yes }
				}
				scope:recipient = {
					OR = {
						AND = {
							is_landed = no
							is_ruler = no
							gold > scope:actor.gold
							gold > scope:actor.medium_gold_value
							scope:actor.ai_greed > low_negative_ai_value
						}
						AND = {
							is_landed = no
							is_ruler = no
							gold > 0
							scope:actor = {
								has_banish_reason = scope:recipient
							}
						}
						AND = {
							is_landed = no
							is_ruler = no
							gold > 100
							scope:actor.ai_greed >= high_positive_ai_value
						}
						AND = {
							scope:actor = {
								has_banish_reason = scope:recipient
							}
							scope:actor = {
								opinion = {
									target = scope:recipient
									value <= medium_negative_opinion
								}
							}
						}
					}
				}
			}
			scope:recipient = {
				OR = {
					target_is_liege_or_above = scope:actor
					is_pool_character = yes
				}
			}
			custom_description = {
				text = "release_banish_invalid_take_vows"
				object = scope:recipient
				scope:take_vows = no
			}
			scope:recruit = no # Should be impossible to have both but just in case	
			scope:banish = no
			NOT = {
				scope:recipient = {
					is_spouse_of = scope:actor
				}
			}

			scope:actor = {
				NOR = {
					capital_province = {
						geographical_region = world_essos
					}
					has_trait = nightswatch
					culture = { agot_is_wildling_culture = yes }
				}
			}
			
			scope:recipient = {
				NOT = { has_trait = nightswatch }
				NOT = { has_trait = kingsguard }
			}
		}
	}

	send_options_exclusive = no

	auto_accept = {
		scope:demand_conversion = no
		scope:renounce_claims = no
		scope:banish = no
		scope:gain_hook = no
		scope:take_vows = no
		scope:recruit = no
		#AGOT Added
		scope:mega_war_switch_sides = no
		scope:agot_strip_knighthood = no
		scope:agot_banish_to_essos = no
	}
	
	ai_accept = {
		base = 0
		modifier = {
			#AGOT Added, only for non-banishment
			trigger = {
				AND = {
					scope:banish = no
					scope:agot_banish_to_essos = no
				}
			}
			add = 100
			desc = "WANTS_FREEDOM_REASON"
		}
		modifier = {
			trigger = {
				scope:recipient = { ai_zeal <= 20 }
				scope:demand_conversion = yes
			}
			#AGOT Modified, less likely to convert
			#add = -20
			add = -50
			desc = "CONVERSION_NEGATIVE_REASON"
		}
		modifier = {
			trigger = {
				scope:recipient = { ai_zeal > 20 }
				scope:demand_conversion = yes
			}
			add = {
				value = ai_zeal
				if = {
					limit = {
						scope:recipient.faith = {
							faith_hostility_level = {
								target = scope:actor.faith
								value = faith_astray_level
							}
						}
					}
					#AGOT Modified, less likely to convert
					#multiply = -1
					multiply = -2
				}
				else = {
					#AGOT Modified, less likely to convert
					#multiply = -2
					multiply = -5
				}
			}
			desc = "CONVERSION_NEGATIVE_REASON"
		}
		modifier = {
			add = -25
			trigger = {
				scope:renounce_claims = yes
				ai_greed < 0
			}
			desc = "RENOUNCE_CLAIMS_REASON"
		}
		modifier = {
			add = -50
			trigger = {
				scope:renounce_claims = yes
				ai_greed >= 0
				ai_greed < 26
			}
			desc = "RENOUNCE_CLAIMS_REASON"
		}
		modifier = {
			add = -50
			trigger = {
				scope:become_executioner = yes
				# Sadists don't care about becoming an executioner
				NOR = {
					has_trait = sadistic
					has_trait = callous
				}
			}
			desc = "BECOME_EXECUTIONER_REASON"
		}
		modifier = {
			add = -75
			trigger = {
				scope:renounce_claims = yes
				ai_greed >= 26
				ai_greed < 51
			}
			desc = "RENOUNCE_CLAIMS_REASON"
		}
		modifier = {
			add = -95
			trigger = {
				scope:renounce_claims = yes
				ai_greed >= 51
			}
			desc = "RENOUNCE_CLAIMS_REASON"
		}
		modifier = {
			add = -50
			trigger = {
				scope:banish = yes
			}
			NOT = {
				scope:actor = {
					has_imprisonment_reason = scope:recipient
					culture = { has_cultural_parameter = vassals_more_likely_accept_punishments }
				}
			}
			desc = "BANISH_NEGATIVE_REASON"
		}
		modifier = { # Legalistic tradition
			add = legalistic_vassal_punishment_acceptance
			trigger = {
				scope:banish = yes
			}
			scope:actor = {
				has_imprisonment_reason = scope:recipient
				culture = { has_cultural_parameter = vassals_more_likely_accept_punishments }
			}
			desc = tradition_legalistic_name
		}
		modifier = {
			add = {
				value = -50
				if = {
					limit = {
						scope:recipient = {
							ai_vengefulness > 0
						}
					}
					subtract = ai_vengefulness
				}
			}
			trigger = {
				scope:gain_hook = yes
			}
			desc = "GAIN_HOOK_NEGATIVE_REASON"
		}
		modifier = {
			add = -30
			trigger = {
				scope:take_vows = yes
			}
			desc = "TAKE_VOWS_NEGATIVE_REASON"
		}
		modifier = {
			add = -10
			trigger = {
				scope:recruit = yes
				NOT = {
					scope:actor = {
						culture = {
							has_cultural_parameter = can_recruit_prisoners_easily
						}
					}
				}
			}
			desc = "RECRUITMET_NEGATIVE_REASON"
		}
		# Struggle
		modifier = {
			trigger = {
				scope:demand_conversion = no
				scope:renounce_claims = no
				scope:banish = no
				scope:gain_hook = no
				scope:take_vows = no
				scope:recruit = no
			}
			scope:recipient = {
				any_character_struggle = {
					involvement = involved
				}
			}
			scope:actor = {
				any_character_struggle = {
					involvement = involved
				}
			}
			add = {
				value = 0
				if = {
					limit = {
						scope:recipient = {
							any_character_struggle = {
								phase_has_catalyst = catalyst_release_important
							}
							has_character_flag = agenda_towards_escalation
						}
					}
					add = -100
				}
				else_if = {
					limit = {
						scope:recipient = {
							any_character_struggle = {
								phase_has_catalyst = catalyst_release_important
							}
						}
					}
					add = 200
				}
			}
		}

		#AGOT Added, Megawars
		agot_mw_switch_sides_modifier = yes

		#AGOT Added, Strip knighthood
		modifier = {
			trigger = {
				OR = {
					scope:recipient = { ai_zeal <= 50 }
					scope:recipient = {
						NOT = {
							faith = {
								has_doctrine = tenet_knighthood
							}
						}
					}
				}
				scope:agot_strip_knighthood = yes
			}
			add = -50
			desc = "NOT_RELIGIOUS_ATTACHED_TO_KNIGHTHOOD_REASON"
		}
		modifier = {
			trigger = {
				scope:recipient = { ai_zeal > 50 }
				scope:recipient = {
					faith = {
						has_doctrine = tenet_knighthood
					}
				}
				scope:agot_strip_knighthood = yes
			}
			add = {
				value = ai_zeal
				multiply = -1
			}
			desc = "RELIGIOUS_ATTACHED_TO_KNIGHTHOOD_REASON"
		}

		#AGOT Added, Banishment
		modifier = { # Base modifier for banishment
			trigger = {
				OR = {
					scope:banish = yes
					scope:agot_banish_to_essos = yes
				}
			}
			add = 75
			desc = "WANTS_FREEDOM_REASON"
		}
		modifier = { # Cannot banish your liege or higher!
			trigger = {
				OR = {
					scope:banish = yes
					scope:agot_banish_to_essos = yes
				}
				scope:recipient = {
					is_liege_or_above_of = scope:actor
				}
			}
			add = -200
			desc = "AGOT_CANNOT_BANISH_LIEGE"
		}
		modifier = { # Cannot banish the family of your liege or higher!
			trigger = {
				OR = {
					scope:banish = yes
					scope:agot_banish_to_essos = yes
				}
				scope:recipient = {
					any_close_family_member = {
						NOT = { this = scope:actor }
						is_liege_or_above_of = scope:actor
					 }
				}
			}
			add = -100
			desc = "AGOT_CANNOT_BANISH_LIEGE_FAMILY"
		}
		modifier = { # Cannot banish your peers or betters!
			trigger = {
				OR = {
					scope:banish = yes
					scope:agot_banish_to_essos = yes
				}
				scope:recipient = {
					is_landed = yes
					scope:actor.primary_title.tier <= scope:recipient.primary_title.tier
				}
			}
			add = -200
			desc = "AGOT_CANNOT_BANISH_PEER"
		}
		modifier = { # Cannot banish the family of your peers or betters!
			trigger = {
				OR = {
					scope:banish = yes
					scope:agot_banish_to_essos = yes
				}
				scope:recipient = {
					any_close_family_member = {
						NOT = { this = scope:actor }
						is_landed = yes
						scope:actor.primary_title.tier <= this.primary_title.tier
					}
				}
			}
			add = -100
			desc = "AGOT_CANNOT_BANISH_PEER_FAMILY"
		}
		modifier = { # Cannot banish outsiders
			trigger = {
				OR = {
					scope:banish = yes
					scope:agot_banish_to_essos = yes
				}
				scope:recipient = {
					culture = { agot_is_wildling_culture = no }
					NAND = {
						is_landed = yes
						scope:actor.primary_title.tier <= scope:recipient.primary_title.tier
					}
					OR = {
						any_close_family_member = {
							NOT = { this = scope:actor }
							is_landed = yes
							NOR = {
								is_vassal_or_below_of = scope:actor
								is_liege_or_above_of = scope:actor
							}
						}
						NOR = {
							is_vassal_or_below_of = scope:actor
							is_liege_or_above_of = scope:actor
						}
					}
					NAND = {
						is_landed = no
						NOT = {
							any_close_family_member = {
								is_landed = yes
							}
						}
					}
				}
			}
			add = -150
			desc = "AGOT_CANNOT_BANISH_OUTSIDER"
		}
	}
	
	# AI
	ai_targets = {
		ai_recipients = prisoners
	}
	ai_frequency = 1

	ai_potential = {
		has_prisoners = yes
	}

	ai_will_do = {
		base = 0

		modifier = {
			add = 20
			scope:demand_conversion = yes
		}
		modifier = {
			add = 100
			scope:demand_conversion = yes
			scope:recipient = {
				is_vassal_of = scope:actor
			}
		}
		modifier = {
			add = 30
			scope:renounce_claims = yes
		}
		modifier = {
			add = 50
			scope:banish = yes
		}
		modifier = {
			add = 30
			scope:agot_banish_to_essos = yes
		}
		modifier = {
			add = 30
			scope:take_vows = yes
		}
		modifier = {
			add = 10
			scope:recruit = yes
		}
		modifier = { # Rivals can rot
			add = -40
			scope:actor = {
				NOT = {
					has_trait = forgiving
				}
			}
			scope:recipient = {
				OR = {
					has_relation_rival = scope:actor
					has_relation_nemesis = scope:actor
					scope:recipient = {
						is_spouse_of = scope:actor
						exposed_cheating_on_spouse_trigger = { SPOUSE = scope:actor }
					}
				}
			}
		}
		modifier = { # Rivals can rot FOREVER if vengeful
			add = -100
			scope:actor = {
				NOT = {
					has_trait = forgiving
				}
			}
			scope:actor.ai_vengefulness >= very_high_positive_ai_value
			scope:recipient = {
				OR = {
					has_relation_rival = scope:actor
					has_relation_nemesis = scope:actor
					scope:recipient = {
						is_spouse_of = scope:actor
						exposed_cheating_on_spouse_trigger = { SPOUSE = scope:actor }
					}
				}
			}
		}
		modifier = { # Compassionate characters don't want to keep children in their dungeon for too long
			add = 10
			scope:actor = {
				is_at_war = no
				ai_compassion >= low_positive_ai_value
			}
			scope:recipient = {
				is_adult = no
				time_in_prison = { years > 1 }
			}
		}
		modifier = { # Very compassionate characters tend to release prisoners
			add = 10
			scope:actor = {
				is_at_war = no
				ai_compassion >= very_high_positive_ai_value
			}
			scope:recipient = {
				time_in_prison = { years > 1 }
			}
		}
		modifier = { # Somewhat compassionate characters tend to keep people in their dungeon for a while
			add = 10
			scope:actor = {
				is_at_war = no
				ai_compassion >= medium_positive_ai_value
			}
			scope:recipient = {
				is_landed = no
				time_in_prison = { years > 3 }
			}
		}
		modifier = { # Only truly discompassionate characters will have their dungeon full of hapless victims after 5 years
			add = 10
			scope:actor = {
				is_at_war = no
				ai_compassion >= low_negative_ai_value
			}
			scope:recipient = {
				is_landed = no
				time_in_prison = { years > 5 }
			}
		}
		modifier = { # Most AI characters will let family out...
			add = 10
			scope:actor = {
				is_at_war = no
				OR = {
					ai_compassion >= very_high_positive_ai_value
					AND = {
						ai_compassion >= high_negative_ai_value
						opinion = {
							target = scope:recipient
							value >= low_negative_opinion
						}
					}
				}
			}
			scope:recipient = {
				time_in_prison = { years > 1 }
				is_landed = no
				is_close_family_of = scope:actor
			}
		}
		modifier = { # Almost all will let their own children out
			add = 40
			scope:actor = {
				is_at_war = no
				ai_compassion >= very_high_negative_ai_value
			}
			scope:recipient = {
				is_landed = no
				is_child_of = scope:actor
			}
		}
		# Struggle
		modifier = {
			trigger = {
				scope:demand_conversion = no
				scope:renounce_claims = no
				scope:banish = no
				scope:gain_hook = no
				scope:take_vows = no
				scope:recruit = no
			}
			scope:recipient = {
				any_character_struggle = {
					involvement = involved
				}
			}
			scope:actor = {
				any_character_struggle = {
					involvement = involved
				}
			}
			add = {
				value = 0
				if = {
					limit = {
						scope:actor = {
							any_character_struggle = {
								phase_has_catalyst = catalyst_release_important
							}
							has_character_flag = agenda_towards_escalation
						}
					}
					add = -100
				}
				else_if = {
					limit = {
						scope:actor = {
							any_character_struggle = {
								phase_has_catalyst = catalyst_release_important
							}
							NOT = {
								ai_greed >= 25
							}
							OR = {
								ai_compassion > 50
								AND  = {
									ai_compassion > 0
									scope:recipient = {
										time_in_prison = { years > 1 }
									}
								}
							}
						}
					}
					add = 200
				}
			}
		}
		modifier = { # Family Feud
			add = -50
			exists = scope:actor.house
			exists = scope:recipient.house
			scope:actor = {
				house.house_head = {
					any_owned_story = {
						story_type = story_cycle_house_feud
						has_variable = house_feud_house
						var:house_feud_house = scope:recipient.house
					}
				}
				has_opinion_modifier = {
					modifier = house_feud_opinion
					target = scope:recipient.house.house_head
				}
			}
		}

		evaluate_action_increasing_house_unity = {
			VALUE = 100
		}
	}
}

execute_prisoner_interaction = {
	interface_priority = 120
	common_interaction = yes
	category = interaction_category_prison
	special_interaction = execute_prisoner_interaction
	icon = icon_dead

	desc = execute_prisoner_interaction_desc
	
	ai_targets = {
		ai_recipients = prisoners
	}
	
	ai_frequency = 12
	
	ai_potential = {
		is_at_war = no
	}
	
	ai_will_do = {
		base = 0
		
		opinion_modifier = {
			trigger = {
				NOT = { scope:actor = scope:recipient }
			}
			opinion_target = scope:recipient
			multiplier = -1
		}
		
		ai_value_modifier = {
			ai_compassion = -1
		}
		modifier = {
			add = -20
			ai_compassion >= low_positive_ai_value
			scope:recipient = { is_adult = no }
		}
		# Try to avoid Kinslaying
		modifier = {
			add = -20
			scope:actor.dynasty = scope:recipient.dynasty
			NOT = { faith = { has_doctrine = doctrine_kinslaying_any_dynasty_member_crime } }
		}
		modifier = {
			add = -20
			is_close_or_extended_family_of = scope:recipient
			NOT = { faith = { has_doctrine = doctrine_kinslaying_extended_family_crime } }
		}
		modifier = {
			add = -20
			is_close_family_of = scope:recipient
			NOT = { faith = { has_doctrine = doctrine_kinslaying_close_kin_crime } }
		}
		modifier = {
			add = 50
			has_execute_reason = scope:recipient
			OR = {
				has_trait = sadistic
				has_trait = lunatic
			}
		}
		modifier = { # Executing your way to new titles is a worthy cause...
			add = 20
			scope:actor = {
				has_execute_reason = scope:recipient
				ai_greed > 0
				any_heir_title = { # Execute rulers you can inherit land from
					exists = holder
					holder = scope:recipient
					place_in_line_of_succession = {
						target = scope:actor
						value > 2
					}
				}
			}
		}
		modifier = { # Vengeful characters enjoy executing their rivals
			add = 20
			scope:actor = {
				has_execute_reason = scope:recipient
				ai_vengefulness >= medium_positive_ai_value
				OR = {
					has_relation_rival = scope:recipient # Execute rivals
					has_relation_nemesis = scope:recipient # Execute rivals
					scope:recipient = {
						is_spouse_of = scope:actor
						exposed_cheating_on_spouse_trigger = { SPOUSE = scope:actor }
					}
				}
			}
		}
		modifier = { # Executing your way to new titles is a worthy cause... and very greedy characters need no execution reason
			add = 35
			scope:actor = {
				ai_greed >= very_high_positive_ai_value
				any_heir_title = { # Execute rulers you can inherit land from
					exists = holder
					holder = scope:recipient
					place_in_line_of_succession = {
						target = scope:actor
						value > 2
					}
				}
			}
		}
		modifier = { # Vengeful characters enjoy executing their rivals, and very vengeful characters need no execution reason
			add = 35
			scope:actor = {
				ai_vengefulness >= very_high_positive_ai_value
				OR = {
					has_relation_rival = scope:recipient # Execute rivals
					has_relation_nemesis = scope:recipient # Execute rivals
					scope:recipient = {
						is_spouse_of = scope:actor
						exposed_cheating_on_spouse_trigger = { SPOUSE = scope:actor }
					}
				}
			}
		}
		#Scope:target has caused internal strife in the realm
		character_hates_scope_due_to_strife_modifier = { TARGET = scope:recipient }
		modifier = {
			factor = 0
			scope:actor = {
				NOR = { # Do not execute unless you have some sort of reason to do it
					has_execute_reason = scope:recipient
					has_relation_rival = scope:recipient # Execute rivals
					has_relation_nemesis = scope:recipient # Execute rivals
					scope:recipient = {
						is_spouse_of = scope:actor
						exposed_cheating_on_spouse_trigger = { SPOUSE = scope:actor }
					}
					any_heir_title = { # Execute rulers you can inherit land from
						exists = holder
						holder = scope:recipient
						place_in_line_of_succession = {
							target = scope:actor
							value > 2
						}
					}
					has_trait = lunatic # Self explanatory
				}
			}
		}

		# Agenda impact
		modifier = {
			scope:recipient = {
				any_character_struggle = {
					involvement = involved
				}
				is_important_or_vip_struggle_character = yes
			}
			add = {
				value = 0
				if = {
					limit = {
						scope:actor = {
							any_character_struggle = {
								phase_has_catalyst = catalyst_execute_important
							}
							has_character_flag = agenda_towards_escalation
						}
					}
					add = 200
				}
				else_if = {
					limit = {
						scope:actor = {
							any_character_struggle = {
								phase_has_catalyst = catalyst_execute_important
							}
						}
					}
					add = -100
				}
			}
		}

		#AGOT Disabled
		# modifier = {
		# 	scope:recipient = {
		# 		any_character_struggle = {
		# 			involvement = involved
		# 		}
		# 		has_trait = fp3_struggle_supporter
		# 	}
		# 	add = {
		# 		value = 0
		# 		if = {
		# 			limit = {
		# 				scope:actor = {
		# 					any_character_struggle = {
		# 						phase_has_catalyst = catalyst_execute_supporter
		# 					}
		# 					has_trait = fp3_struggle_detractor
		# 				}
		# 			}
		# 			add = 200
		# 		}
		# 		else_if = {
		# 			limit = {
		# 				scope:actor = {
		# 					any_character_struggle = {
		# 						phase_has_catalyst = catalyst_execute_supporter
		# 					}
		# 				}
		# 			}
		# 			add = -100
		# 		}
		# 	}
		# }

		#AGOT Disabled
		# modifier = {
		# 	scope:recipient = {
		# 		any_character_struggle = {
		# 			involvement = involved
		# 		}
		# 		has_trait = fp3_struggle_detractor
		# 	}
		# 	add = {
		# 		value = 0
		# 		if = {
		# 			limit = {
		# 				scope:actor = {
		# 					any_character_struggle = {
		# 						phase_has_catalyst = catalyst_execute_detractor
		# 					}
		# 					has_trait = fp3_struggle_supporter
		# 				}
		# 			}
		# 			add = 200
		# 		}
		# 		else_if = {
		# 			limit = {
		# 				scope:actor = {
		# 					any_character_struggle = {
		# 						phase_has_catalyst = catalyst_execute_detractor
		# 					}
		# 				}
		# 			}
		# 			add = -100
		# 		}
		# 	}
		# }
	}
	
	is_shown = {
		scope:recipient = {
			is_imprisoned_by = scope:actor
		}
	}

	is_valid_showing_failures_only = {
		scope:recipient = { is_busy_in_events_localised = yes } #Prisoner
		scope:recipient = { NOT = { has_strong_hook = scope:actor } }
		scope:recipient = {
			custom_description = {
				text = "currently_being_tortured"
				NOT = { has_character_flag = is_being_tortured }
			}
		}

		# Blocked by current struggle phase
		custom_tooltip = {
			text = struggle_parameter_struggle_cannot_execute_involved_prisoners
			NOT = {
				scope:actor = {
					any_character_struggle = {
						involvement = involved
						has_struggle_phase_parameter = struggle_cannot_execute_involved_prisoners
						is_secondary_character_involvement_involved_trigger = {
							CHAR = scope:recipient
						}
					}
				}
			}
		}
	}

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

	on_accept = {
		scope:actor = {
			hidden_effect = {
				if = {
					limit = { 
						AND = {
							exists = scope:actor.var:RE_court_intr_2_var
							scope:actor.var:RE_court_intr_2_var <= 90
						}
					}
					scope:actor = {
						change_variable = {
							name = RE_court_intr_2_var
							add = 10
						}
						RE_axis_recount_intr = yes
					}
				}
				else_if = {
					limit = { 
						exists = scope:actor.var:RE_court_intr_2_var
					}
					scope:actor = {
						set_variable = {
							name = RE_court_intr_2_var
							value = 100
						}
					}
				}
				else = {}
				
				if = {
					limit = { 
						AND = {
							exists = scope:actor.var:RE_court_mart_1_var
							scope:actor.var:RE_court_mart_1_var <= 97
						}
					}
					scope:actor = {
						change_variable = {
							name = RE_court_mart_1_var
							add = 3
						}
						RE_axis_recount_mart = yes
					}
				}
				else_if = {
					limit = { 
						exists = scope:actor.var:RE_court_mart_1_var
					}
					scope:actor = {
						set_variable = {
							name = RE_court_mart_1_var
							value = 100
						}
					}
				}
				else = {}
			}
		}
		if = {
			limit = { scope:recipient = { is_imprisoned_by = scope:actor } }
			# Are you HumSac'ing the HoF of a faith that doesn't practice HumSac?
			hidden_effect = {
				scope:actor = {
					humsacd_a_hof_effect = {
						SACRIFICER = scope:actor
						SACRIFICED_HOF = scope:recipient
					}
				}
			}
			if = {
				limit = { always = scope:execution_public }
				if = {
					limit = {
						scope:actor.capital_county = {
							NOT = { has_county_modifier = held_public_execution_modifier }
						}
					}
					custom_description_no_bullet = {
						text = public_execution_tooltip
					}

					scope:actor = {
						capital_county = {
							add_county_modifier = {
								modifier = held_public_execution_modifier
								days = 1850
							}
						}
						custom_tooltip = public_execution_control_effect
						hidden_effect = {
							every_held_title = {
								limit = {
									tier = tier_county
								}
								change_county_control = executioner_control_value
							}
						}
					}
				}
				else = {
					custom_description_no_bullet = {
						text = public_execution_too_soon_tooltip
					}
				}
			}
			# Other Effects
			if = { # Boil their skull?
				limit = {
					NOT = { always = scope:execution_devour }
					scope:actor = {
						has_relation_rival = scope:recipient
						has_personality_malicious_trigger = yes
						has_royal_court = yes
					}
					scope:recipient = {
						is_adult = yes
					}
				}
				scope:actor = {
					random = {
						chance = {
							value = 25
							if = {
								limit = {
									has_relation_nemesis = scope:recipient
								}
								add = 75
							}
						}
						hidden_effect = {
							scope:recipient = {
								save_scope_as = skull_to_boil
							}
							trigger_event = {
								id = artifact.7000
								days = { 3 10 }
							}
						}
					}
				}
			}
			if = {
				limit = {
					NOT = { always = scope:execution_devour }
					#AGOT Added
					NOT = { always = scope:execution_dragon_fed }
					NOT = { always = scope:execution_dragon_burn }
					NOT = { always = scope:execution_dragon_stomped }
					NOT = { always = scope:execution_dragon_dropped }
					scope:actor = {
						is_adult = no
						age >= 4
						is_ai = no
						NOT = { has_character_flag = witnessed_execution_flag }
					}
					scope:recipient = {
						is_adult = yes
					}
				}
				scope:actor = { trigger_event = bp1_yearly.9045 }
			}
			else_if = {
				limit = {
					NOT = { always = scope:execution_devour }
					#AGOT Added
					NOT = { always = scope:execution_dragon_fed }
					NOT = { always = scope:execution_dragon_burn }
					NOT = { always = scope:execution_dragon_stomped }
					NOT = { always = scope:execution_dragon_dropped }
					scope:actor = {
						OR = {
							has_relation_friend = scope:recipient
							has_relation_lover = scope:recipient
						}
						is_ai = no
					}
					scope:recipient = {
						is_adult = yes
					}
				}
				scope:actor = { trigger_event = bp1_yearly.9044 }
			}

			# FP3
			# Struggle Catalysts
			scope:actor = {
				if = { # Execute important
					limit = {
						scope:recipient = { is_important_or_vip_struggle_character = yes }
						any_character_struggle = {
							involvement = involved
							activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
								CATALYST = catalyst_execute_important
								CHAR = scope:recipient
							}
						}
					}
					every_character_struggle = {
						involvement = involved
						limit = {
							activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
								CATALYST = catalyst_execute_important
								CHAR = scope:recipient
							}
						}
						activate_struggle_catalyst = {
							catalyst = catalyst_execute_important
							character = scope:actor
						}
					}
				}
				#AGOT Disabled
				# if = { # Execute Supporter/Detractor
				# 	limit = {
				# 		fp3_struggle_involves_one_supporter_and_one_detractor = {
				# 			FIRST = scope:actor
				# 			SECOND = scope:recipient
				# 		}
				# 	}
				# 	if = {
				# 		limit = {
				# 			scope:recipient = { has_trait = fp3_struggle_detractor }
				# 			any_character_struggle = {
				# 				involvement = involved
				# 				activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
				# 					CATALYST = catalyst_execute_detractor
				# 					CHAR = scope:recipient
				# 				}
				# 			}
				# 		}
				# 		every_character_struggle = {
				# 			involvement = involved
				# 			limit = {
				# 				activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
				# 					CATALYST = catalyst_execute_detractor
				# 					CHAR = scope:recipient
				# 				}
				# 			}
				# 			activate_struggle_catalyst = {
				# 				catalyst = catalyst_execute_detractor
				# 				character = scope:actor
				# 			}
				# 			log_debug_variable_for_persian_struggle_effect = { VAR = stabil_catalyst_execute_detractor }
				# 		}
				# 	}
				# 	else_if = {
				# 		limit = {
				# 			scope:recipient = { has_trait = fp3_struggle_supporter }
				# 			any_character_struggle = {
				# 				involvement = involved
				# 				activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
				# 					CATALYST = catalyst_execute_supporter
				# 					CHAR = scope:recipient
				# 				}
				# 			}
				# 		}
				# 		every_character_struggle = {
				# 			involvement = involved
				# 			limit = {
				# 				activate_struggle_catalyst_secondary_character_involvement_involved_trigger = {
				# 					CATALYST = catalyst_execute_supporter
				# 					CHAR = scope:recipient
				# 				}
				# 			}
				# 			activate_struggle_catalyst = {
				# 				catalyst = catalyst_execute_supporter
				# 				character = scope:actor
				# 			}
				# 			log_debug_variable_for_persian_struggle_effect = { VAR = unrest_catalyst_execute_supporter }
				# 		}
				# 	}
				# }
				# Free House Member CB target executed during war
				if = {
					limit = {
						exists = scope:recipient.house
						any_character_war = {
							using_cb = fp3_free_house_member_cb
							is_defender = scope:actor
							primary_attacker.house = scope:recipient.house
						}
					}
					random_character_war = {
						limit = {
							using_cb = fp3_free_house_member_cb
							is_defender = scope:actor
							primary_attacker.house = scope:recipient.house
						}
						primary_attacker = {
							add_opinion = {
								target = scope:actor
								modifier = executed_close_relation_opinion
							}
						}
					}
					add_prestige = {
						value = medium_piety_loss
						multiply = {
							value = ai_honor
							add = 1
						}
					}
					every_vassal = {
						limit = {
							OR = {
								has_vassal_stance = courtly
								has_vassal_stance = glory_hound
								ai_honor > 0.48
							}
						}
						add_opinion = {
							target = scope:actor
							modifier = executed_valuable_prisoner_modifier
						}
					}
				}
			}

			# Kill the target
			# AGOT Added - dragon execute
			if = {
				limit = { 
					always = scope:execution_dragon_fed
					scope:recipient = { is_ai = no }
					scope:actor = { is_ai = yes }
				}
				scope:recipient = { trigger_event = agot_dragon.0004 } # Give players a chance to see what's about to happen
				show_as_tooltip = {
					execute_dragon_prisoner_effect = {
						VICTIM = scope:recipient
						EXECUTIONER = scope:actor
						REASON = death_fed_to_dragon
					}
				}
			}
			else_if = {
				limit = { 
					always = scope:execution_dragon_fed
				}
				scope:recipient = { trigger_event = agot_dragon.0005 }
				execute_dragon_prisoner_effect = {
					VICTIM = scope:recipient
					EXECUTIONER = scope:actor
					REASON = death_fed_to_dragon
				}
			}
			# Incineration by Dragon
			else_if = {
				limit = {
					always = scope:execution_dragon_burn
					scope:recipient = { is_ai = no }
					scope:actor = { is_ai = yes }
				}
				scope:recipient = { trigger_event = agot_dragon.0004 } # Give players a chance to see what's about to happen
				show_as_tooltip = {
					execute_dragon_prisoner_effect = {
						VICTIM = scope:recipient
						EXECUTIONER = scope:actor
						REASON = death_dragon_fire
					}
				}
			}
			else_if = {
				limit = { always = scope:execution_dragon_burn }
				scope:recipient = { trigger_event = agot_dragon.0005 }
				execute_dragon_prisoner_effect = {
					VICTIM = scope:recipient
					EXECUTIONER = scope:actor
					REASON = death_dragon_fire
				}
			}
			# Stomped to Death by Dragon
			else_if = {
				limit = { 
					always = scope:execution_dragon_stomped
					scope:recipient = { is_ai = no }
					scope:actor = { is_ai = yes }
				}
				scope:recipient = { trigger_event = agot_dragon.0004 } # Give players a chance to see what's about to happen
				show_as_tooltip = {
					execute_dragon_prisoner_effect = {
						VICTIM = scope:recipient
						EXECUTIONER = scope:actor
						REASON = death_dragon_stomped
					}
				}
			}
			else_if = {
				limit = { always = scope:execution_dragon_stomped }
				scope:recipient = { trigger_event = agot_dragon.0005 }
				execute_dragon_prisoner_effect = {
					VICTIM = scope:recipient
					EXECUTIONER = scope:actor
					REASON = death_dragon_stomped
				}
			}
			# DROPPED from the sky by Dragon
			else_if = {
				limit = { 
					always = scope:execution_dragon_dropped
					scope:recipient = { is_ai = no }
					scope:actor = { is_ai = yes }
				}
				scope:recipient = { trigger_event = agot_dragon.0004 } # Give players a chance to see what's about to happen
				show_as_tooltip = {
					execute_dragon_prisoner_effect = {
						VICTIM = scope:recipient
						EXECUTIONER = scope:actor
						REASON = death_dropped_from_dragon
					}
				}
			}
			else_if = {
				limit = { always = scope:execution_dragon_dropped }
				scope:recipient = { trigger_event = agot_dragon.0005 }
				execute_dragon_prisoner_effect = {
					VICTIM = scope:recipient
					EXECUTIONER = scope:actor
					REASON = death_dropped_from_dragon
				}
			}
			# AGOT Modified
			#if = {
			else_if = {
				limit = {
					scope:recipient = { is_ai = no }
					scope:actor = { is_ai = yes }
				}
				scope:recipient = { trigger_event = char_interaction.0170 } # Give players a chance to see what's about to happen
				show_as_tooltip = {
					execute_prisoner_effect = {
						VICTIM = scope:recipient
						EXECUTIONER = scope:actor
					}
				}
			}
			else = {
				scope:recipient = { trigger_event = char_interaction.0171 }
				execute_prisoner_effect = {
					VICTIM = scope:recipient
					EXECUTIONER = scope:actor
				}
			}

			if = {
				limit = { always = scope:execution_devour }
				scope:actor = {
					custom_tooltip = devour_as_execution_tooltip
					if = {
						limit = {
							faith = { has_doctrine_parameter = cannibalism_legal }
							NOT = { has_trait = cannibal }
						}
						add_trait = cannibal
					}
					stress_impact = {
						base = medium_stress_impact_loss
						compassionate = miniscule_stress_impact_gain
						forgiving = miniscule_stress_impact_gain
					}
					random = {
						chance = 20
						show_as_tooltip = { add_trait = ill }
						hidden_effect = {
							trigger_event = {
								id = health.1001
								days = { 3 10 }
							}
						}
					}
				}
			}

			if = {
				limit = {
					always = scope:execution_burned
					scope:actor.faith = {
						has_doctrine = doctrine_pluralism_fundamentalist
					}
				}
				scope:actor = {
					add_piety = miniscule_piety_value
				}
			}

			scope:actor = {
				hidden_effect = {
					send_interface_message = {
						type = event_generic_neutral
						title = msg_execute_prisoner
						right_icon = scope:recipient
						custom_tooltip = msg_execute_prisoner_desc
					}
				}
			}
		}
	}

	options_heading = execution_options_heading

	send_option = {
		is_shown = {
			scope:actor.faith = scope:recipient.faith
			NOT = {
				scope:actor.faith = { has_doctrine_parameter = human_sacrifice_active }
			}
		}
		flag = execution_beheaded
		localization = "EXECUTION_BEHEADED"
	}

	#Cannibal option. Should be treated as a "normal" execution, but that you eat the body afterwards (in secret if faith does not allow it).
	send_option = {
		is_shown = {
			scope:actor = {
				OR = {
					scope:actor.faith = { has_doctrine_parameter = cannibalism_legal }
					has_trait = cannibal
					any_secret = { secret_type = secret_cannibal }
				}
			}
		}
		flag = execution_devour
		localization = "EXECUTION_DEVOUR"
	}

	send_option = {
		is_shown = {
			NOT = {
				scope:actor.faith = scope:recipient.faith
				scope:actor.faith = { has_doctrine_parameter = human_sacrifice_active }
			}
		}
		flag = execution_burned
		localization = "EXECUTION_BURNED"
	}

	send_option = {
		is_shown = {
			scope:actor.faith = { has_doctrine_parameter = human_sacrifice_active }
		}
		flag = execution_sacrifice
		localization = "EXECUTION_SACRIFICE"
	}

	send_option = {
		is_shown = {
			scope:actor = {
				employs_court_position = executioner_court_position
				any_court_position_holder = {
			        type = executioner_court_position
			        is_physically_able = yes
			    }
				exists = capital_county
			}
		}
		is_valid = {
			scope:actor = {
				NOT = {
					capital_county = {
						has_county_modifier = held_public_execution_modifier
					}
				}
			}
		}
		flag = execution_public
		localization = "EXECUTION_PUBLIC"
	}
	
	#AGOT Added
	send_option = {
		is_shown = {
			scope:actor = {
				is_current_dragonrider = yes
			}
			scope:recipient = {
				is_human = yes
			}
		}
		flag = execution_dragon_fed
		localization = "EXECUTION_DRAGON_FED"
	}
	send_option = {
		is_shown = {
			scope:actor = {
				is_current_dragonrider = yes
			}
			scope:recipient = {
				is_human = yes
			}
		}
		flag = execution_dragon_burn
		localization = "EXECUTION_DRAGON_BURN"
	}
	send_option = {
		is_shown = {
			scope:actor = {
				is_current_dragonrider = yes
			}
			scope:recipient = {
				is_human = yes
			}
		}
		flag = execution_dragon_stomped
		localization = "EXECUTION_DRAGON_STOMPED"
	}
	send_option = {
		is_shown = {
			scope:actor = {
				is_current_dragonrider = yes
			}
			scope:recipient = {
				is_human = yes
			}
		}
		flag = execution_dragon_dropped
		localization = "EXECUTION_DRAGON_DROPPED"
	}
	
	send_options_exclusive = yes
	auto_accept = yes
}

debug_imprison_simple_interaction = {
	use_diplomatic_range = no
	category = interaction_debug_main
	common_interaction = yes
	ignores_pending_interaction_block = yes
	icon = prison
	interface_priority = 1000

	is_shown = {
		debug_only = yes
		scope:recipient = {
			is_imprisoned = no
		}
		NOT = {
			scope:recipient = scope:actor
		}
	}

	on_accept = {
		scope:actor = {
			imprison = {
				target = scope:recipient
				type = house_arrest
			}
		}
	}

	auto_accept = yes
}

torture_interaction = {
	interface_priority = 30
	common_interaction = yes
	icon = torture_interaction

	category = interaction_category_prison

	desc = torture_interaction_desc

	#cooldown = { years = 1 }
	cooldown_against_recipient = { years = 5 }

	is_shown = {
		scope:recipient = { is_imprisoned_by = scope:actor }
		scope:recipient = { is_adult = yes }
		scope:actor = { is_adult = yes }
	}

	is_valid_showing_failures_only = {
		#scope:recipient = {
		#	NOT = {
		#		health <= 1.5 #Because torture would definitely kill them
		#	}
		#}
		scope:recipient = {
			custom_description = {
				text = "currently_being_tortured"
				NOT = { has_character_flag = is_being_tortured }
			}
		}
		cannot_release_former_regent_whilst_old_regent_holds_power_trigger = {
			PRISONER = scope:recipient
			REGENT = scope:recipient.var:imprisoned_by_diarch
		}
	}

	is_highlighted = {
		OR = {
			scope:actor = { has_trait = sadistic }
			scope:actor = { has_relation_rival = scope:recipient }
			scope:actor = { has_relation_nemesis = scope:recipient }
		}
	}

	on_accept = {
		scope:actor = {
			hidden_effect = {
				if = {
					limit = { 
						AND = {
							exists = scope:actor.var:RE_court_intr_2_var
							scope:actor.var:RE_court_intr_2_var <= 90
						}
					}
					scope:actor = {
						change_variable = {
							name = RE_court_intr_2_var
							add = 10
						}
						RE_axis_recount_intr = yes
					}
				}
				else_if = {
					limit = { 
						exists = scope:actor.var:RE_court_intr_2_var
					}
					scope:actor = {
						set_variable = {
							name = RE_court_intr_2_var
							value = 100
						}
					}
				}
				else = {}
			}
		}
	
		scope:recipient = {
			add_character_flag = {
				flag = is_being_tortured
				months = 6 # Players in MP can keep the event window open...
			}
		}

		###EFFECT TOOLTIP###
		torture_interaction_actor_effect = yes
		show_as_tooltip = {
			scope:recipient = {
				add_character_modifier = {
					modifier = recently_tortured
					years = 5
				}
			}
		}

		###EVENTS###
		hidden_effect = {
			#Torture method for descs
			random_list = {
				3 = { save_scope_value_as = { name = torture_method value = flag:rack } }
				3 = { save_scope_value_as = { name = torture_method value = flag:whip } }
				1 = { save_scope_value_as = { name = torture_method value = flag:rats } }
				8 = {
					trigger = {
						scope:actor = { has_trait = poet }
					}
					save_scope_value_as = {
						name = torture_method
						value = flag:poetry
					}
				}
			}

			#They have a secret I want to know about
			if = {
				limit = {
					scope:recipient = {	
						OR = {
							any_secret = {
								torture_secret_trigger = { PARTICIPANT = scope:recipient }
							}
							any_known_secret = {
								secret_owner = { save_temporary_scope_as = torture_secret_owner }
								torture_secret_trigger = { PARTICIPANT = scope:torture_secret_owner }
							}
						}
					}
				}
				scope:recipient = {
					trigger_event = {
						id = prison.1001
						days = 1
					}
				}
			}
			else = {
				scope:actor = {
					trigger_event = {
						id = prison.1010
						days = 1
					}
				}
			}	
		}

		# Dark Insights Perk:
		if = {
			limit = {
				scope:actor = { has_perk = dark_insights_perk }
			}
			scope:actor = {
				dark_insights_skill_gain_roll_effect = yes
			}
		}
	}

	auto_accept = yes

	# AI
	ai_targets = {
		ai_recipients = prisoners
	}
	
	ai_frequency = 24
	
	ai_potential = {
		always = yes
	}

	ai_will_do = {
		base = -25

		modifier = {
			has_trait = sadistic
			add = 30
		}
		ai_value_modifier = {
			ai_compassion = tiny_chance_impact_negative_ai_value #Adds +50 for highly uncompassionate characters, -50 for highly compassionate characters
		}
		opinion_modifier = {
			opinion_target = scope:recipient
			multiplier = -0.25
		}
		#Scope:target has caused internal strife in the realm
		character_hates_scope_due_to_strife_modifier = { TARGET = scope:recipient }
		modifier = { # Family Feud
			exists = scope:actor.house
			exists = scope:recipient.house
			scope:actor = {
				house.house_head = {
					any_owned_story = {
						story_type = story_cycle_house_feud
						has_variable = house_feud_house
						var:house_feud_house = scope:recipient.house
					}
				}
				has_opinion_modifier = {
					modifier = house_feud_opinion
					target = scope:recipient.house.house_head
				}
			}
			add = 30
		}
	}	
}

castrate_interaction = {
	interface_priority = 30
	icon = eunuch

	category = interaction_category_prison
	desc = castrate_interaction_desc

	is_shown = {
		scope:recipient = {
			is_imprisoned_by = scope:actor
			NOT = { has_trait = eunuch }
			is_male = yes
		}
		scope:actor = {
			is_adult = yes
			#AGOT Modified
			# culture = {
			# 	has_cultural_parameter = can_castrate_prisoners
			# }
			OR = {
				culture = { has_cultural_parameter = can_castrate_prisoners }
				AND = {
					has_trait = torturer
					has_trait = sadistic
				}
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:recipient = {
			custom_description = {
				text = "currently_being_tortured"
				NOT = { has_character_flag = is_being_tortured }
			}
		}
		cannot_release_former_regent_whilst_old_regent_holds_power_trigger = {
			PRISONER = scope:recipient
			REGENT = scope:recipient.var:imprisoned_by_diarch
		}
	}

	is_highlighted = {
		OR = {
			scope:actor = { has_trait = sadistic }
			scope:actor = { has_relation_rival = scope:recipient }
			scope:recipient = {
				any_claim = {
					holder = scope:actor
				}
			}
		}
	}

	on_accept = {
		scope:actor = {
			hidden_effect = {
				if = {
					limit = { 
						AND = {
							exists = scope:actor.var:RE_court_intr_2_var
							scope:actor.var:RE_court_intr_2_var <= 93
						}
					}
					scope:actor = {
						change_variable = {
							name = RE_court_intr_2_var
							add = 7
						}
						RE_axis_recount_intr = yes
					}
				}
				else_if = {
					limit = { 
						exists = scope:actor.var:RE_court_intr_2_var
					}
					scope:actor = {
						set_variable = {
							name = RE_court_intr_2_var
							value = 100
						}
					}
				}
				else = {}
			}
		}
	
		scope:recipient = {
			add_character_flag = {
				flag = is_being_tortured
				months = 6 # Players in MP can keep the event window open...
			}
		}

		blind_and_castrate_actor_effect = yes #Stress & dread

		show_as_tooltip = {
			scope:recipient = {
				add_trait = eunuch
				release_from_prison = yes
			}
		}

		torture_blind_castrate_opinion_effect = { VERB = castrated }

		scope:actor = {
			trigger_event = {
				id = prison.1025
				days = 1
			}
		}

		# 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_abelarding.desc
			REVERSE_NON_HOUSE_TARGET = no
		}
	}

	auto_accept = yes

	ai_targets = {
		ai_recipients = prisoners
	}

	ai_potential = {
		always = yes
	}

	ai_will_do = {
		base = -20

		modifier = {
			has_trait = sadistic
			add = 20
		}
		ai_value_modifier = {
			ai_compassion = tiny_chance_impact_negative_ai_value #Adds +50 for highly uncompassionate characters, -50 for highly compassionate characters
		}
		opinion_modifier = {
			opinion_target = scope:recipient
			multiplier = -0.25
		}
		#Scope:target has caused internal strife in the realm
		character_hates_scope_due_to_strife_modifier = { TARGET = scope:recipient }
		modifier = { # Family Feud
			exists = scope:actor.house
			exists = scope:recipient.house
			scope:actor = {
				house.house_head = {
					any_owned_story = {
						story_type = story_cycle_house_feud
						has_variable = house_feud_house
						var:house_feud_house = scope:recipient.house
					}
				}
				has_opinion_modifier = {
					modifier = house_feud_opinion
					target = scope:recipient.house.house_head
				}
			}
			add = 30
		}
	}

	ai_frequency = 36
}

blind_interaction = {
	interface_priority = 30
	icon = blind

	category = interaction_category_prison
	desc = blind_interaction_desc

	is_shown = {
		scope:recipient = {
			is_imprisoned_by = scope:actor
			NOT = { has_trait = blind }
		}
		scope:actor = {
			is_adult = yes
			# AGOT Modified
			# culture = { has_cultural_parameter = can_blind_prisoners }
			OR = {
				culture = { has_cultural_parameter = can_blind_prisoners }
				AND = {
					has_trait = torturer
					has_trait = sadistic
				}
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:recipient = {
			custom_description = {
				text = "currently_being_tortured"
				NOT = { has_character_flag = is_being_tortured }
			}
		}
		cannot_release_former_regent_whilst_old_regent_holds_power_trigger = {
			PRISONER = scope:recipient
			REGENT = scope:recipient.var:imprisoned_by_diarch
		}
	}

	is_highlighted = {
		OR = {
			scope:actor = { has_trait = sadistic }
			scope:actor = { has_relation_rival = scope:recipient }
			scope:recipient = {
				any_claim = {
					holder = scope:actor
				}
			}
			scope:actor = {
				culture = { has_cultural_parameter = merciful_blinding }
				OR = {
					has_execute_reason = scope:recipient
					has_banish_reason = scope:recipient
				}
			}
		}
	}

	on_accept = {
	
		scope:actor = {
			hidden_effect = {
				if = {
					limit = { 
						AND = {
							exists = scope:actor.var:RE_court_intr_2_var
							scope:actor.var:RE_court_intr_2_var <= 93
						}
					}
					scope:actor = {
						change_variable = {
							name = RE_court_intr_2_var
							add = 7
						}
						RE_axis_recount_intr = yes
					}
				}
				else_if = {
					limit = { 
						exists = scope:actor.var:RE_court_intr_2_var
					}
					scope:actor = {
						set_variable = {
							name = RE_court_intr_2_var
							value = 100
						}
					}
				}
				else = {}
			}
		}
		scope:recipient = {
			add_character_flag = {
				flag = is_being_tortured
				months = 6 # Players in MP can keep the event window open...
			}
		}

		blind_and_castrate_actor_effect = yes #Stress & dread

		show_as_tooltip = {
			scope:recipient = {
				add_trait = blind
				release_from_prison = yes
			}
		}

		# Merciful Blindings
		scope:actor = {
			if = {
				limit = {
					culture = { has_cultural_parameter = merciful_blinding }
					OR = {
						has_execute_reason = scope:recipient
						has_banish_reason = scope:recipient
					}
				}
				add_piety = medium_piety_gain
			}
		}
		
		torture_blind_castrate_opinion_effect = { VERB = blinded }

		scope:actor = {
			trigger_event = {
				id = prison.1020
				days = 1
			}
		}

		# If we're a clan this interaction affects unity
		if = {
			limit = { scope:actor.culture = { has_cultural_parameter = merciful_blinding } } # If actor's culture has Merciful Blindings, they lose less unity
			add_clan_unity_interaction_effect = {
				CHARACTER = scope:actor
				TARGET = scope:recipient
				VALUE = minor_unity_loss
				DESC = clan_unity_blinding.desc
				REVERSE_NON_HOUSE_TARGET = no
			}
		}
		else = {
			add_clan_unity_interaction_effect = {
				CHARACTER = scope:actor
				TARGET = scope:recipient
				VALUE = medium_unity_loss
				DESC = clan_unity_blinding.desc
				REVERSE_NON_HOUSE_TARGET = no
			}
		}
	}

	auto_accept = yes

	ai_targets = {
		ai_recipients = prisoners
	}

	ai_potential = {
		always = yes
	}

	ai_will_do = {
		base = -20

		modifier = {
			has_trait = sadistic
			add = 20
		}
		ai_value_modifier = {
			ai_compassion = tiny_chance_impact_negative_ai_value #Adds +50 for highly uncompassionate characters, -50 for highly compassionate characters
		}
		opinion_modifier = {
			opinion_target = scope:recipient
			multiplier = -0.25
		}
		#Scope:target has caused internal strife in the realm
		character_hates_scope_due_to_strife_modifier = { TARGET = scope:recipient }
		modifier = { # Family Feud
			exists = scope:actor.house
			exists = scope:recipient.house
			scope:actor = {
				house.house_head = {
					any_owned_story = {
						story_type = story_cycle_house_feud
						has_variable = house_feud_house
						var:house_feud_house = scope:recipient.house
					}
				}
				has_opinion_modifier = {
					modifier = house_feud_opinion
					target = scope:recipient.house.house_head
				}
			}
			add = 30
		}
	}

	ai_frequency = 36
}
