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 = {
		triggered_desc = {
			trigger = {
				scope:recipient = {
					NAND = {
						has_government = landless_adventurer_government
						reverse_has_opinion_modifier = {
							target = scope:actor
							modifier = eviction_ignored_opinion
						}
					}
				}
			}
			desc = imprison_decline_summary
		}
	}

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

	is_shown = {
		scope:actor != scope:recipient
		scope:actor = {
			OR = {
				AND = {
					has_title = title:e_minister_of_justice
					top_liege = {
						basic_allowed_to_imprison_character_trigger = {
							CHARACTER = scope:recipient
						}
					}
					scope:recipient = {
						tgp_is_any_minister = no
					}
				}
				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 }
				}
			}
		}
		POD_hostile_interaction_is_shown = yes
		POD_imprison_interaction_is_shown = yes
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			OR = {
				AND = {
					has_title = title:e_minister_of_justice
					top_liege = {
						allowed_to_imprison_character_trigger = { CHARACTER = scope:recipient }
					}
				}
				allowed_to_imprison_character_trigger = { CHARACTER = scope:recipient }
			}
			trigger_if = {
				limit = {
					government_has_flag = government_is_nomadic
				}
				NOT = { has_realm_law = nomadic_authority_1 }
			}
			trigger_if = {
				limit = {
					has_title = title:e_minister_of_justice
				}
				scope:recipient = {
					NOT = {
						is_close_or_extended_family_of = scope:actor.top_liege
					}
				}
			}
		}
		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 }
		}
		POD_imprison_interaction_is_valid_showing_failures_only = yes
	}

	can_send = {
		scope:actor = {
			custom_description = {
				text = "character_interactions_hostile_actions_disabled_delay"
				NOT = { has_character_flag = flag_hostile_actions_disabled_delay }
			}
			trigger_if = {
				limit = {
					is_ai = no
				}
				scope:recipient = {
					trigger_if = {
						limit = {
							has_government = landless_adventurer_government
							reverse_has_opinion_modifier = {
								target = scope:actor
								modifier = eviction_ignored_opinion
							}
						}
						is_travelling = no
					}
				}
			}
			trigger_else = {
				OR = {
					has_imprisonment_reason = scope:recipient
					any_character_struggle = {
						involvement = involved
					}
				}
			}
		}
	}

	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 = {
		if = {
			limit = {	
				scope:actor = {
					has_title = title:e_minister_of_justice
				}
			}
			save_scope_value_as = {
				name = use_strife_not_tyranny
				value = yes
			}
		}
		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 = {
					POD_incompatible_splats_trigger = yes
				}
				stress_impact = {
					vengeful = minor_stress_impact_loss
					zealous = minor_stress_impact_loss
					just = minor_stress_impact_loss
				}
			}
			else_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 = {
		scope:actor = {
			if = {
				limit = {	
					has_title = title:e_minister_of_justice
				}
				save_scope_value_as = {
					name = use_strife_not_tyranny
					value = yes
				}
				if = {
					limit = {
						NOT = {
							has_imprisonment_reason = scope:recipient
						}
						any_character_situation = {
							situation_type = dynastic_cycle
							situation_top_has_catalyst = catalyst_minister_imprison
						}
					}
					situation:dynastic_cycle = {
						trigger_situation_catalyst = {
							catalyst = catalyst_minister_imprison
							character = scope:recipient
						}
					}
				}
			}
		}
		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 = {
					POD_incompatible_splats_trigger = yes
				}
				stress_impact = {
					vengeful = minor_stress_impact_loss
					zealous = minor_stress_impact_loss
					just = minor_stress_impact_loss
				}
			}
			else_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_or_landless_administrative = 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_or_landless_administrative = no }
			}
			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
			}
		}

		# Harrying logic.
		scope:actor = {
			if = {
				limit = {
					character_is_valid_for_harrying_of_the_north_trigger = yes
					scope:recipient = {
						character_is_valid_for_harrying_of_the_north_trigger = yes
						is_important_or_vip_struggle_character = yes
					}
					culture != scope:recipient.culture
				}
				global_var:harrying_of_the_north = { save_scope_as = story }
				if = {
					limit = {
						character_is_valid_norman_for_harrying_of_the_north_trigger = yes
						scope:recipient = { character_is_valid_anglo_saxon_for_harrying_of_the_north_trigger = yes }
					}
					ep3_increase_pacification_effect = { AMOUNT = harrying_minor_increase_value }
				}
				else_if = {
					limit = {
						character_is_valid_anglo_saxon_for_harrying_of_the_north_trigger = yes
						scope:recipient = { character_is_valid_norman_for_harrying_of_the_north_trigger = yes }
					}
					ep3_increase_resistance_effect = { AMOUNT = harrying_minor_increase_value }
				}
			}
		}
	}

	on_decline = {
		if = {
			limit = {
				scope:recipient = {
					has_government = landless_adventurer_government
					reverse_has_opinion_modifier = {
						target = scope:actor
						modifier = eviction_ignored_opinion
					}
				}
			}
			scope:recipient = {
				if = {
					limit = { current_military_strength >= ep3_interactions_events_0500_troops_count_value }
					start_war = {
						cb = ep3_laamp_apprehend_adventurer_cb
						target = scope:actor
					}
				}
				else = {
					# Remove them immediately.
					remove_laamp_from_exiled_county_automatically_effect = {
						PROVINCE = scope:recipient.location
						LAAMP = scope:recipient
					}
				}
			}
		}
		else = {
			scope:actor = {
				imprison_HoF_consequences_effect = yes
				imprison_tyranny_effect = yes
			}
			scope:recipient = {
				#If target is count or higher, start war.
				if = {
					limit = {
						is_playable_character = yes
						primary_title.tier > tier_barony
					}
					if = {
						limit = {
							is_a_faction_member = yes
							liege = scope:actor
							joined_faction = {
								faction_target = scope:actor
								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_or_landless_administrative = yes
						}
						depose_effect = { DEPOSER = scope:actor }
					}
					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_or_landless_administrative = 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
								}
								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 = {
								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 = {
								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_childhood_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_playable_character = no
							AND = {
								is_playable_character = yes
								primary_title.tier = tier_barony
							}
						}
					}
				}
				trigger_event = char_interaction.0230
			}
		}

		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_or_landless_administrative  = 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_or_landless_administrative  = no }
			}
			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 = {
		scope:actor = {
			has_title = title:e_minister_of_justice
		}
	}

	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_hightier_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_type = claimant_faction
						faction_is_at_war = yes
						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
				is_landed = 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
				has_dlc_feature = royal_court
				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
				has_dlc_feature = royal_court
				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
		}
		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 = {
					accolade_parameter = accolade_imprisonment_chance
				}
			}
			desc = THUG_REASON
			add = accolade_imprisonment_chance_value
		}
		modifier = {
			scope:actor = {
				any_active_accolade = {
					accolade_parameter = accolade_imprisonment_chance_high
				}
			}
			desc = THUG_REASON_HIGH
			add = accolade_imprisonment_chance_value_high
		}
		evaluate_action_decreasing_house_unity = {
			VALUE = 100
		}
		modifier = {
			add = -25
			scope:recipient = {
				culture = { has_cultural_parameter = vassals_more_likely_to_refuse_demands }
			}
			desc = VASSALS_REFUSAL_indomitable_azatani
		}
		modifier = {
			add = 10
			scope:recipient = { has_character_modifier = ach_intent_imprisonment_modifier }
			desc = ach_host_intent_imprison_reason
		}
	}

	# AI
	ai_targets = {
		ai_recipients = vassals
		chance = 0.5
	}
	ai_targets = {
		ai_recipients = courtiers
		chance = 0.25
	}
	
	ai_frequency_by_tier = {
		barony = 0
		county = 36
		duchy = 10
		kingdom = 10
		empire = 10
		hegemony = 10
	}

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

		modifier = { # Default imprisonment reason weight
			add = 200
			scope:actor = {
				has_imprisonment_reason = scope:recipient
			}
		}
		
		modifier = { # More likely to imprison criminal Soryo's if Ritsuryo
			add = 200
			scope:actor = {
				has_imprisonment_reason = scope:recipient
				government_has_flag = government_is_japan_administrative
			}
			scope:recipient = {
				government_has_flag = government_is_japan_feudal
			}
		}
		
		modifier = { # Even more imprisonment reason if you are a danger to the Kampaku
			add = 400
			scope:actor = {
				primary_title = title:e_japan
				has_imprisonment_reason = scope:recipient
			}
			scope:recipient = {
				exists = house.house_confederation
				house.house_confederation.combined_military_strength > scope:actor.current_military_strength
			}
		}

		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_playable_character = 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_playable_character = 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_playable_character = 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_playable_character = 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
						scope:actor.faith != scope:recipient.faith
					}
					scope:actor = {
						has_opinion_modifier = {
							modifier = murdered_close_family_crime
							target = scope:recipient
						}
					}
					scope:actor = {
						has_opinion_modifier = {
							modifier = attempted_murder_close_family_crime
							target = scope:recipient
						}
					}
					scope:actor = {
						has_opinion_modifier = {
							modifier = executed_close_family
							target = scope:recipient
						}
					}
					scope:actor = {
						has_opinion_modifier = {
							modifier = slept_with_spouse_discovered_opinion
							target = scope:recipient
						}
					}
					scope:actor = {
						has_opinion_modifier = {
							modifier = slept_with_spouse_exposed_opinion
							target = scope:recipient
						}
					}
					scope:actor = {
						has_opinion_modifier = {
							modifier = unfaithful_spouse_discovered_opinion
							target = scope:recipient
						}
					}
					scope:actor = {
						has_opinion_modifier = {
							modifier = unfaithful_spouse_exposed_opinion
							target = scope:recipient
						}
					}
					scope:actor = {
						has_opinion_modifier = {
							modifier = refused_to_renounce_lover_opinion
							target = scope:recipient
						}
					}
					scope:actor = {
						has_opinion_modifier = {
							modifier = betrayed_our_promise
							target = scope:recipient
						}
					}
					scope:actor = {
						has_opinion_modifier = {
							modifier = botched_my_treatment_crime_opinion
							target = scope:recipient
						}
					}
					scope:actor = {
						has_opinion_modifier = {
							modifier = botched_treatment_of_kin_crime_opinion
							target = scope:recipient
						}
					}
					scope:actor = {
						has_opinion_modifier = {
							modifier = smeared_opinion
							target = scope:recipient
						}
					}
					scope:actor = {
						has_opinion_modifier = {
							modifier = insulted_opinion
							target = scope:recipient
						}
					}
					scope:actor = {
						has_opinion_modifier = {
							modifier = mocked_me_in_time_of_need
							target = scope:recipient
						}
					}
					scope:actor = {
						has_opinion_modifier = {
							modifier = loved_one_dungeon_death
							target = scope:recipient
						}
					}
					scope:actor = {
						has_opinion_modifier = {
							modifier = abandoned_me_opinion
							target = scope:recipient
						}
					}
					scope:actor = {
						has_opinion_modifier = {
							modifier = reason_child_died
							target = scope:recipient
						}
					}
					scope:actor = {
						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
				}
			}
		}
		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
				}
			}
		}
		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
				}
			}
		}

		# TGP Be more careful with blocs generally
		house_bloc_tyranny_war_modifiers = yes

		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:actor = {
			is_landless_ruler = no
		}
		scope:recipient = {
			is_imprisoned_by = scope:actor
			is_in_prison_type = house_arrest
		}
	}

	is_valid_showing_failures_only = {
		scope:recipient = {
			custom_description = {
				text = "currently_being_tortured"
				NOT = { has_character_flag = is_being_tortured }
			}
		}
		tgp_blocked_action_against_tenno_trigger = {
			ACTOR = scope:actor
			TARGET = scope:recipient
		}
		POD_move_to_dungeon_interaction_is_valid_showing_failures_only = yes
	}

	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 = {
				every_close_or_extended_family_member = {
					custom = all_family_members
					limit = {
						scope:actor != this
					}
					add_opinion = {
						modifier = family_moved_to_dungeon_opinion
						target = scope:actor
					}
				}
			}
		}
		scope:actor = {
			stress_impact = {
				compassionate = medium_stress_impact_gain
				forgiving = medium_stress_impact_gain
			}
			hidden_effect = {
				send_interface_message = {
					type = event_prison_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_by_tier = {
		barony = 0
		county = 48
		duchy = 12
		kingdom = 12
		empire = 12
		hegemony = 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 = {
				scope:actor = {
					house_has_feud_relation_with_trigger = { TARGET = scope:recipient }

				}
			}
			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:actor = {
			is_landless_ruler = no
		}
		scope:recipient = {
			is_imprisoned_by = scope:actor
			is_in_prison_type = dungeon
		}
	}

	is_valid_showing_failures_only = {
		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 = {
				every_close_or_extended_family_member = {
					custom = all_family_members
					limit = {
						scope:actor != this
					}
					add_opinion = {
						modifier = moved_to_house_arrest_opinion
						target = scope:actor
					}
				}
			}
		}
		scope:actor = {
			stress_impact = {
				sadistic = medium_stress_impact_gain
				vengeful = medium_stress_impact_gain
			}
			hidden_effect = {
				send_interface_message = {
					type = event_prison_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 = no
	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
		}
		scope:actor != scope:recipient
		POD_ransom_interaction_is_shown = yes
	}

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

		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
		}
	}

	cost = {
		influence = {
			value = 0
			if = {
				limit = { scope:influence_send_option = yes }
				add = scope:actor.medium_influence_value
				desc = INFLUENCE_INTERACTION_ACCEPTANCE_SEND_OPTION
			}
		}
	}

	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 = {
					limit = {
						employs_court_position = person_haggler_camp_officer
						is_asking_for_gold_in_ransom_trigger = yes
					}
					random_court_position_holder = {
						type = person_haggler_camp_officer
						save_scope_as = haggler
					}
					scope:prisoner = {
						save_scope_value_as = {
							name = new_ransom_value
							value = haggler_ransom_cost_modifier
						}
					}
					custom_tooltip = has_person_haggler_decrease_ransom_cost
				}
				# 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
				if = {
					limit = {
						employs_court_position = person_haggler_camp_officer
						is_asking_for_gold_in_ransom_trigger = yes
					}
					random_court_position_holder = {
						type = person_haggler_camp_officer
						save_scope_as = haggler
					}
					scope:recipient = {
						scope:prisoner = {
							save_scope_value_as = {
								name = new_ransom_value
								value = haggler_ransom_cost_modifier
							}
						}
						custom_tooltip = has_person_haggler_increase_ransom_cost
					}
				}

				#Save scopes for portraits
				scope:recipient = { save_scope_as = portrait_first }
				if = {
					limit = {
						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 = {
				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 = {
				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"
	}

	send_option = { # EP3 Influence
		is_shown = { # Actor must have a government that uses influence 
			trigger_if = { # in the mass action ransom we only want to do it for gold
				limit = { exists = scope:mass_action }
				scope:mass_action = no
			}
			scope:actor = {
				government_has_flag = government_has_influence
			}
		}
		is_valid = {
			# Actor has enough influence
			scope:actor = { influence >= medium_influence_value }
			# Both characters are within the same top realm
			custom_tooltip = {
				text = not_same_realm_tt
				scope:recipient.top_liege = scope:actor.top_liege
			}
		}
		flag = influence_send_option
		localization = TRADE_INFLUENCE_FOR_BETTER_AI_ACCEPTANCE
	}
	
	# MPO Herd
	send_option = {
		is_shown = { # Actor must have a government that uses Herd 
			scope:actor = {
				government_has_flag = government_is_nomadic
				exists = domicile
				is_ai = no
			}
			# Recipient must care about Herd
			scope:recipient ?= {
				government_has_flag = government_is_nomadic
				exists = domicile
			}
		}
		is_valid = {
			# Recipient has enough Herd
			scope:recipient = { domicile.herd >= domicile.medium_herd_value }
		}
		flag = herd_send_option
		localization = RANSOM_HERD_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
		RANSOM_HERD_COST = ransom_herd_value_recipient
	}

	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
			}
			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
			}
			scope:recipient != scope:secondary_recipient
			scope:recipient.ai_greed <= medium_negative_ai_value
			desc = AI_VALUE_MODIFIER_GENEROUS
		}
		modifier = {
			add = -10
			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
				}
			}
			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
			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_by_tier = {
		barony = 36
		county = 6
		duchy = 6
		kingdom = 6
		empire = 6
		hegemony = 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
					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 = { # Do not ransom at war
			factor = 0
			scope:actor = { 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 }
			}
		}

		#don't ransom if they are tied with a prison break contract, we don't want it invalidating all the time
		modifier = {
			factor = 0
			scope:secondary_recipient = {
				has_character_flag = being_prisonbroken_by_laamp
			}
		}
	}

	# 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 = no
	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

	cost = {
		influence = {
			value = 0
			if = {
				limit = { scope:influence_send_option = yes }
				add = scope:actor.medium_influence_value
				desc = INFLUENCE_INTERACTION_ACCEPTANCE_SEND_OPTION
			}
		}
	}

	greeting = positive
	notification_text = PAY_RANSOM_PROPOSAL

	is_shown = {
		exists = scope:recipient
		scope:secondary_recipient = {
			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
			}
		}
		scope:actor != scope:recipient

		POD_interaction_is_shown = yes
	}

	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
		}
	}

	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
				if = {
					limit = {
						employs_court_position = person_haggler_camp_officer
						is_asking_for_gold_in_ransom_trigger = yes
					}
					random_court_position_holder = {
						type = person_haggler_camp_officer
						save_scope_as = haggler
					}
					custom_tooltip = has_person_haggler_increase_ransom_cost
				}
			}
			scope:actor = {
				save_scope_as = payer
				if = {
					limit = {
						employs_court_position = person_haggler_camp_officer
						is_asking_for_gold_in_ransom_trigger = yes
					}
					random_court_position_holder = {
						type = person_haggler_camp_officer
						save_scope_as = haggler

					}
					scope:prisoner = {
						save_scope_value_as = {
							name = new_ransom_value
							value = haggler_ransom_cost_modifier
						}
					}
					custom_tooltip = has_person_haggler_decrease_ransom_cost
				}
				# 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_prison_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 = {
						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 = {
				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 = {
				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 = {
				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 = {
				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"
	}

	send_option = { # EP3 Influence
		is_shown = { # Actor must have a government that uses influence 
			scope:actor = {
				government_has_flag = government_has_influence
			}
		}
		is_valid = {
			# Actor has enough influence
			scope:actor = { influence >= medium_influence_value }
			# Both characters are within the same top realm
			custom_tooltip = {
				text = not_same_realm_tt
				scope:recipient.top_liege = scope:actor.top_liege
			}
		}
		flag = influence_send_option
		localization = TRADE_INFLUENCE_FOR_BETTER_AI_ACCEPTANCE
	}
	
	send_option = { # MPO Herd
		is_shown = { # Actor must have a government that uses Herd 
			scope:actor = {
				government_has_flag = government_is_nomadic
				exists = domicile
				is_ai = no
			}
			# Recipient must care about Herd
			scope:recipient = {
				government_has_flag = government_is_nomadic
				exists = domicile
			}
		}
		is_valid = {
			# Actor has enough Herd
			scope:actor = { domicile.herd >= domicile.medium_herd_value }
		}
		flag = herd_send_option
		localization = PAY_FOR_BETTER_AI_ACCEPTANCE
	}

	#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
		RANSOM_HERD_COST = ransom_herd_value_actor
	}

	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
			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
		}

		modifier = {
			add = 25
			scope:influence_send_option = yes
			desc = INFLUENCE_INTERACTION_ACCEPTANCE_SEND_OPTION
		}
		
		modifier = {
			add = 25
			scope:herd_send_option = yes
			desc = HERD_INTERACTION_ACCEPTANCE_SEND_OPTION
		}
	}

	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_recipients = spouses
		ai_recipients = scripted_relations
		ai_recipients = liege
	}
	ai_targets = {
		ai_recipients = neighboring_rulers
		ai_recipients = peer_vassals
		ai_recipients = top_realm_domicile_owners
		max = 5
	}
	ai_frequency_by_tier = {
		barony = 0
		county = 6
		duchy = 6
		kingdom = 6
		empire = 6
		hegemony = 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
					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
							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
					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 }
			}
		}

		#don't ransom prisoners that are tied with a prison break contract, we don't want it invalidating all the time
		modifier = {
			factor = 0
			scope:secondary_recipient = {
				has_character_flag = being_prisonbroken_by_laamp
			}
		}
	}
}

#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
		}

		POD_interaction_is_shown = yes
	}

	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
		}
	}

	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 = {
					limit = {
						employs_court_position = person_haggler_camp_officer
						is_asking_for_gold_in_ransom_trigger = yes
					}
					random_court_position_holder = {
						type = person_haggler_camp_officer
						save_scope_as = haggler
					}
					save_scope_value_as = {
						name = new_ransom_value
						value = haggler_ransom_cost_modifier
					}
					custom_tooltip = has_person_haggler_decrease_ransom_cost
				}

				# 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 = {
				if = {
					limit = {
						employs_court_position = person_haggler_camp_officer
						is_asking_for_gold_in_ransom_trigger = yes
					}
					random_court_position_holder = {
						type = person_haggler_camp_officer
						save_scope_as = haggler
					}
					scope:actor = {
						custom_tooltip = has_person_haggler_increase_ransom_cost
					}
				}
				send_interface_message = {
					type = event_prison_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
		}
	}

	cost = {
		influence = {
			value = 0
			if = {
				limit = { scope:influence_send_option = yes }
				add = scope:actor.medium_influence_value
				desc = INFLUENCE_INTERACTION_ACCEPTANCE_SEND_OPTION
			}
		}
	}

	send_option = {
		is_shown = {
			exists = scope:recipient
			scope:recipient = {
				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 = {
				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"
	}

	send_option = { # EP3 Influence
		is_shown = { # Actor must have a government that uses influence 
			scope:actor = {
				government_has_flag = government_has_influence
			}
		}
		is_valid = {
			# Actor has enough influence
			scope:actor = { influence >= medium_influence_value }
			# Both characters are within the same top realm
			custom_tooltip = {
				text = not_same_realm_tt
				scope:recipient.top_liege = scope:actor.top_liege
			}
		}
		flag = influence_send_option
		localization = TRADE_INFLUENCE_FOR_BETTER_AI_ACCEPTANCE
	}
	
	send_option = { # MPO Herd
		is_shown = { # Actor must have a government that uses Herd 
			scope:actor = {
				government_has_flag = government_is_nomadic
				exists = domicile
			}
			# Recipient must care about Herd
			scope:recipient = {
				government_has_flag = government_is_nomadic
				exists = domicile
			}
		}
		is_valid = {
			# Actor has enough Herd
			scope:actor = { domicile.herd >= domicile.medium_herd_value }
		}
		flag = herd_send_option
		localization = PAY_FOR_BETTER_AI_ACCEPTANCE
	}

	#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
		RANSOM_HERD_COST = ransom_herd_value_actor
	}

	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 = {
				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 = {
				scope:recipient = {
					house_has_feud_relation_with_trigger = { TARGET = scope:actor }

				}
			}
			desc = INTERACTION_FAMILY_FEUD_REVERSE_REASON
		}

		modifier = {
			add = 25
			scope:influence_send_option = yes
			desc = INFLUENCE_INTERACTION_ACCEPTANCE_SEND_OPTION
		}
		
		modifier = {
			add = 25
			scope:herd_send_option = yes
			desc = HERD_INTERACTION_ACCEPTANCE_SEND_OPTION
		}
	}

	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_by_tier = {
		barony = 72
		county = 24
		duchy = 24
		kingdom = 12
		empire = 12
		hegemony = 12
	}

	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
					}
				}
				scope:herd_send_option = yes
			}
		}

		modifier = {
			add = 100
			scope:favor = yes
			scope:recipient = {
				OR = {
					is_vassal_of = scope:actor
					liege ?= scope:actor
				}
			}
		}

		modifier = {
			add = -100
			scope:favor = yes
			scope:recipient = {
				NOR = {
					is_vassal_of = scope:actor
					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
				scope:herd_send_option = 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 }
			}
		}

		#don't do it if you are tied with a prison break contract, we don't want it invalidating all the time
		modifier = {
			factor = 0
			scope:actor = {
				has_character_flag = being_prisonbroken_by_laamp
			}
		}
	}
}

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
					scope:disfigure = no
					scope:blind = no
					scope:castrate = no
				}
				desc = RELEASE_PRISONER_OFFER
			}
			desc = RELEASE_PRISONER_OFFER_CONDITIONAL
		}
	}

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

	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
		}
	}

	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 }
		}
		if = {
			limit = { scope:recipient = { is_imprisoned_by = scope:actor } }

			scope:recipient = {
				# POD CfV:
				# Effects from custom send options go in this scripted_effect
				# so that the vanilla file stays clean
				POD_release_from_prison_send_option_effects = yes
				
				# 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_or_landless_administrative = yes }
					}
					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_landless_adventurer = 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
							NOR = {
								has_character_flag = realm_priest
								has_character_flag = was_bookmaker
							}
						}
						pay_short_term_gold = { target = scope:actor gold = this.gold }
					}
					if = {
						limit = {
							has_any_artifact = yes
							scope:actor = { has_perk = weaver_ward_perk } # CfV
						}
						every_character_artifact = {
							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
									}
								}
							}
						}
					}
					banish = yes
					add_opinion = {
						modifier = banished_me
						target = scope:actor
					}
				}
				# 'Banish' Pool Character
				else_if = {
					limit = {
						AND = {
							scope:banish = yes
							scope:recipient = {
								is_playable_character = 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 }
					}
					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
					#Does Byzan go hay-wire with deposing vassals?
					if = {
						limit = {
							scope:actor = {
								is_ai = yes
								culture = { has_cultural_pillar = heritage_byzantine }
							}
						}
						debug_log = debug_ai_byzan_forced_vows_on_prison_release
						debug_log_scopes = yes
					}
					#Does the AI in general go haywire with deposing prisoners?
					else_if = {
						limit = {
							scope:actor = { is_ai = yes }
						}
						debug_log = debug_ai_forced_vows_on_prison_release
						debug_log_scopes = yes
					}
				}

				# Become Executioner
				if = {
					limit = { scope:become_executioner = yes }
					release_as_executioner_effect = yes
				}

				# Disfigure
				if = {
					limit = { scope:disfigure = yes }

					scope:recipient = {
						add_character_flag = {
							flag = is_being_tortured
							months = 6 # Players in MP can keep the event window open...
						}
					}

					blind_castrate_and_disfigure_effect = yes #Stress & dread

					show_as_tooltip = {
						scope:recipient = {
							add_trait = disfigured
						}
					}

					torture_blind_castrate_disfigure_opinion_effect = { VERB = disfigured }

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

				# Blind
				if = {
					limit = { scope:blind = yes }
					scope:recipient = {
						add_character_flag = {
							flag = is_being_tortured
							months = 6 # Players in MP can keep the event window open...
						}
					}

					blind_castrate_and_disfigure_effect = yes #Stress & dread

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

					# 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_disfigure_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
						}
					}
				}

				# Castrate
				if = {
					limit = { scope:castrate = yes }
					scope:recipient = {
						add_character_flag = {
							flag = is_being_tortured
							months = 6 # Players in MP can keep the event window open...
						}
					}

					blind_castrate_and_disfigure_effect = yes #Stress & dread

					show_as_tooltip = {
						scope:recipient = {
							if = {
								limit = {
									age < 12
								}
								ep3_child_castration_effect = yes
							}
							else = {
								ep3_youth_castration_effect = yes
							}
						}
					}

					torture_blind_castrate_disfigure_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
					}
				}

				# Demand Admin
				if = {
					limit = { scope:demand_admin = yes }
					scope:recipient = {
						change_to_administrative_effect = yes
					}
				}

				# Shared Torture effects
				if = {
					limit = {
						OR = {
							scope:disfigure = yes
							scope:blind = yes
							scope:castrate = yes
						}
					}
					scope:recipient.house ?= {
						change_house_relation_effect = {
							HOUSE = scope:actor.house
							VALUE = house_relation_damage_medium_value
							REASON = torture
							CHAR = scope:actor
							TARGET_CHAR = scope:recipient
							TITLE = scope:dummy_gender
						}
					}
				}

				# No Demands Added
				if = {
					limit = {
						scope:track = no
						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
						scope:disfigure = no
						scope:blind = no
						scope:castrate = no
						scope:demand_admin = no
					}
					# Notification to the imprisoner
					scope:actor = {
						send_interface_toast = {
							type = event_toast_effect_neutral
							title = recipient_released_from_prison
							left_icon = scope:recipient
							scope:recipient = {
								add_opinion = {
									modifier = released_from_prison
									target = scope:actor
								}
							}
						}
						house ?= {
							change_house_relation_effect = {
								HOUSE = scope:recipient.house
								VALUE = house_relation_improve_medium_value
								REASON = prison_released
								CHAR = scope:actor
								TARGET_CHAR = scope:recipient
								TITLE = scope:dummy_gender
							}
						}
						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
									OR = {
										has_struggle_phase_parameter = release_prisoner_diff_culture_gives_prestige
										has_struggle_phase_parameter = release_prisoner_diff_faith_gives_prestige
									}
								}
								is_diff_faith_or_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
								}
							}
						}
						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 }
							}
						}
					}

					POD_release_from_prison_no_demands_effect = yes
					
					# 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 = msg_legitimacy_gain
								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 is handled in follow-up events
						scope:disfigure = no
						scope:blind = no
						scope:castrate = no
					}
					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 = {
										scope:recipient = { release_from_prison = yes }
										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
		}
	}

	# PoD CfV: Neferu special option
	send_option = {
		flag = neferu_release
		localization = "NEFERU_RELEASE"
		is_shown = {
			scope:actor = character:790514 # Vamp only
			scope:actor = { is_ai = no }
			NOT = { scope:recipient.faith = scope:actor.faith }
		}
		is_valid = {
			# 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
					}
				}
			}
		}
	}
	
	# PoD CfV: Inquisitor option
	send_option = {
		flag = track
		localization = "RELEASE_TRACK"
		is_shown = {
			POD_inquisitor_on_unholy_trigger = { ACTOR = scope:actor RECIPIENT = scope:recipient }
		}
	}
	
	send_option = {
		flag = demand_conversion
		localization = "RELEASE_DEMAND_CONVERSION"
		is_shown = {
			scope:recipient.faith != scope:actor.faith
		}
		is_valid = {
			pod_can_convert_trigger = yes
			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_playable_character = yes
						}
						is_vassal_or_below_of = scope:actor
					}
				}
			}

			# Cannot ask Religious Heads to convert
			custom_description = {
				text = cannot_demand_religious_head_conversion
				NAND = {
					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
								}
							}
						}
					}
				}
			}
			NOT = { POD_inquisitor_on_unholy_trigger = { ACTOR = scope:actor RECIPIENT = scope:recipient } }
		}
		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_playable_character = no
							is_ruler = no
							gold > scope:actor.gold
							gold > scope:actor.medium_gold_value
							scope:actor.ai_greed > low_negative_ai_value
						}
						AND = {
							is_playable_character = no
							is_ruler = no
							gold > 0
							scope:actor = {
								has_banish_reason = scope:recipient
							}
						}
						AND = {
							is_playable_character = 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
								}
							}
						}
					}
				}
			}
			trigger_if = {
				limit = {
					scope:recipient = {
						is_playable_character = yes
					}
				}
				scope:recipient = {
					is_vassal_of = scope:actor
				}
			}
			trigger_else = {
				scope:recipient = {
					is_courtier_of = scope:actor
				}
			}
			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
				}
			}
			NOT = { POD_inquisitor_on_unholy_trigger = { ACTOR = scope:actor RECIPIENT = scope:recipient } }
		}
	}

	send_option = {
		flag = gain_hook
		localization = "RELEASE_GAIN_HOOK"
		is_shown = {
			POD_incompatible_splats_trigger = no
			
			trigger_if = {
				limit = {
					scope:actor = { is_ai = yes }
				}
				scope:recipient = {
					OR = {
						is_vassal_of = scope:actor
						liege ?= scope:actor
					}
				}
			}
		}
		is_valid = {
			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 = { take_vows_available_trigger = yes }

			POD_incompatible_splats_trigger = no
		}
		is_valid = {
			#Handle AI
			trigger_if = {
				limit = {
					scope:actor = { is_ai = yes }
				}
				#We're AI and Byzantium
				trigger_if = {
					limit = {
						scope:actor = {
							culture = { has_cultural_pillar = heritage_byzantine }
						}
					}
					scope:recipient = {
						is_ai = yes #Not gonna depose player characters, for now
						OR = {
							is_close_or_extended_family_of = scope:actor
							is_vassal_or_below_of = scope:actor #Weigh this for Byz AI in the modifiers below
							has_relation_rival = scope:actor
							is_courtier_of = scope:actor
						}
						NOT = {
							is_heir_of = scope:actor
						}
					}
					#Get rid of rivals despite potentially liking them
					trigger_if = {
						limit = {
							scope:recipient = { has_relation_rival = scope:actor }
						}
						always = yes
					}
					#Only get rid of family members if we dislike them
					trigger_else = {
						scope:actor = {
							opinion = {
								target = scope:recipient
								value <= medium_negative_opinion
							}
						}
					}
				}
				#We're not Byzantium but plain AI
				trigger_else = {
					scope:recipient = {
						is_ai = yes #Not gonna depose player characters, for now
						is_close_or_extended_family_of = scope:actor
						NOT = {
							is_heir_of = scope:actor
						}
					}
					scope:actor = {
						opinion = {
							target = scope:recipient
							value <= medium_negative_opinion
						}
					}
					custom_description = {
						text = "release_vows_invalid_not_your_court"
						object = scope:recipient
						subject = scope:actor
						OR = {
							scope:recipient = { is_courtier_of = scope:actor }
							scope:recruit = yes
						}
					}
				}
			}
			#Enhanced Take the Vows for Byzantium players -- who do we want to boot to a monastery far, far away?
			trigger_else_if = {
				limit = {
					scope:actor = {
						culture = { has_cultural_pillar = heritage_byzantine }
					}
				}
				scope:recipient = {
					is_ai = yes #Not gonna depose player characters, for now
					custom_description = {
						text = "release_byz_vows_invalid"
						object = scope:recipient
						subject = scope:actor
						OR = {
							is_close_or_extended_family_of = scope:actor
							is_vassal_or_below_of = scope:actor
							has_relation_rival = scope:actor
							is_courtier_of = scope:actor
						}
					}
				}
			}
			#Otherwise standard procedure Take the Vows requirements
			trigger_else = {
				scope:recipient = {
					is_ai = yes #Not gonna depose player characters, for now
				}
				scope:actor = { is_close_or_extended_family_of = scope:recipient } #Triggering I_AM_NOT instead of CHARACTER_IS_NOT makes the tooltip look less cursed
				custom_description = {
					text = "release_vows_invalid_not_your_court"
					object = scope:recipient
					subject = scope:actor
					OR = {
						scope:recipient = { 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 = {
						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
						betrothed ?= {
							is_female = yes
							matrilinear_betrothal = yes
						}
					}
					custom_description = {
						text = patrilinear_betrothal
						subject = scope:recipient
						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
			}
		}
		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 }
						}
					}
				}
			}
			POD_incompatible_splats_trigger = no
		}
	}

	send_option = {
		flag = disfigure
		localization = "RELEASE_DISFIGURE"
		is_shown = {
			always = no # CfV: disabled in PoD
			scope:actor = {
				government_allows = administrative
				culture = { has_cultural_tradition = tradition_ep3_palace_politics }
				# If they're our partner emperor, we should use the maiming interaction instead.
				liege_should_systematically_maim_co_ruler_trigger = no
			}
			scope:recipient = {
				is_adult = yes
			}
		}
		is_valid = {
			scope:recipient = {
				NOT = { has_trait = disfigured }
			}
			# Byzantines can't disfigure those not in their realm
			trigger_if = {
				limit = {
					scope:actor = {
						culture = { has_cultural_pillar = heritage_byzantine }
					}
				}
				scope:recipient = {
					custom_description = {
						text = "release_byz_disfigure_invalid"
						object = scope:recipient
						subject = scope:actor
						OR = {
							is_close_or_extended_family_of = scope:actor
							is_vassal_or_below_of = scope:actor
							has_relation_rival = scope:actor
							is_courtier_of = scope:actor
						}
					}
				}
			}
			custom_description = {
				text = "release_prisoner_disfigure_blind_castrate_condition"
				object = scope:recipient
				scope:blind = no
				scope:castrate = no
			}
		}
	}

	send_option = {
		flag = blind
		localization = "RELEASE_BLIND"
		is_shown = {
			always = no # CfV: disabled in PoD
			scope:actor = {
				is_adult = yes
				culture = { has_cultural_parameter = can_blind_prisoners }
				# If they're our partner emperor, we should use the maiming interaction instead.
				liege_should_systematically_maim_co_ruler_trigger = no
			}
			scope:recipient = {
				is_adult = yes
			}
		}
		is_valid = {
			scope:recipient = {
				NOT = { has_trait = blind }
			}
			custom_description = {
				text = "release_prisoner_disfigure_blind_castrate_condition"
				object = scope:recipient
				scope:disfigure = no
				scope:castrate = no
			}
		}
	}

	send_option = {
		flag = castrate
		localization = "RELEASE_CASTRATE"
		is_shown = {
			always = no # CfV: disabled in PoD
			scope:recipient = {
				is_imprisoned_by = scope:actor
				is_eunuch_trigger = no
				is_male = yes
			}
			scope:actor = {
				is_adult = yes
				culture = {
					has_cultural_parameter = can_castrate_prisoners
				}
				# If they're our partner emperor, we should use the maiming interaction instead.
				liege_should_systematically_maim_co_ruler_trigger = no
			}
		}
		is_valid = {
			scope:recipient = {
				is_eunuch_trigger = no
			}
			custom_description = {
				text = "release_prisoner_disfigure_blind_castrate_condition"
				object = scope:recipient
				scope:disfigure = no
				scope:blind = no
			}
		}
	}

	send_option = {
		flag = demand_admin
		localization = "RELEASE_DEMAND_ADMIN"
		is_shown = {
			scope:actor = { government_allows = administrative }
			scope:actor = scope:recipient.liege
			scope:recipient = { #Requirements match demand admin interaction
				highest_held_title_tier >= tier_county
				is_landed = yes
				is_ruler = yes
				NOT = { government_allows = administrative }
				NOT = {
					scope:recipient = { government_has_flag = government_is_tribal }
				}
				NOT = { scope:recipient ?= scope:recipient.faith.religious_head }
				NOT = { scope:recipient ?= scope:actor.diarch }
			}
		}
		is_valid = {
			scope:recipient = {
				NOT = { government_allows = administrative }
			}
		}
	}

	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
		scope:disfigure = no
		scope:blind = no
		scope:castrate = no
		scope:demand_admin = no
	}

	ai_accept = {
		base = 0
		modifier = {
			add = 100
			desc = "WANTS_FREEDOM_REASON"
		}
		POD_release_from_prison_ai_accept_modifier = yes
		# Basic modifiers
		modifier = {
			trigger = {
				has_trait = ambitious
			}
			add = -20
			desc = "RECIPIENT_IS_AMBITIOUS"
		}
		
		# Demand conversion
		modifier = {
			trigger = {
				scope:recipient = { ai_zeal <= 20 }
				scope:demand_conversion = yes
			}
			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
							}
						}
					}
					multiply = -1
				}
				else = {
					multiply = -2
				}
			}
			desc = "CONVERSION_NEGATIVE_REASON"
		}
		# Renounce claims
		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"
		}
		# Employ executioner
		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"
		}
		# Banish
		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
		}
		# Gain hook
		modifier = {
			add = {
				value = -50
				if = {
					limit = {
						scope:recipient = {
							ai_vengefulness > 0
						}
					}
					subtract = ai_vengefulness
				}
			}
			trigger = {
				scope:gain_hook = yes
			}
			desc = "GAIN_HOOK_NEGATIVE_REASON"
		}
		# Take vows
		modifier = {
			add = -30
			trigger = {
				scope:take_vows = yes
			}
			desc = "TAKE_VOWS_NEGATIVE_REASON"
		}
		modifier = {
			add = -30
			trigger = {
				scope:take_vows = yes
				has_trait = lustful
			}
			desc = "TAKE_VOWS_LUSTFUL_REASON"
		}
		modifier = {
			add = -30
			trigger = {
				scope:take_vows = yes
				has_trait = rakish
			}
			desc = "TAKE_VOWS_RAKISH_REASON"
		}
		modifier = {
			add = -30
			trigger = {
				scope:take_vows = yes
				has_trait = fornicator
			}
			desc = "TAKE_VOWS_FORNICATOR_REASON"
		}
		modifier = {
			add = -30
			trigger = {
				scope:take_vows = yes
				has_trait = seducer
			}
			desc = "TAKE_VOWS_SEDUCER_REASON"
		}
		modifier = {
			add = -30
			trigger = {
				scope:take_vows = yes
				has_trait = deviant
			}
			desc = "TAKE_VOWS_DEVIANT_REASON"
		}
		modifier = {
			add = {
				value = -15
				multiply = num_sinful_traits
			}
			trigger = {
				scope:take_vows = yes
				num_sinful_traits > 1
			}
			desc = "TAKE_VOWS_SINS_REASON"
		}
		modifier = {
			add = -30
			trigger = {
				scope:take_vows = yes
				has_trait = cynical
			}
			desc = "TAKE_VOWS_CYNICAL_REASON"
		}
		# Recruitment
		modifier = {
			add = -10
			trigger = {
				scope:recruit = yes
				NOT = {
					scope:actor = {
						culture = {
							has_cultural_parameter = can_recruit_prisoners_easily
						}
					}
				}
			}
			desc = "RECRUITMET_NEGATIVE_REASON"
		}
		# Disfigure
		modifier = {
			add = {
				value = -100
				if = {
					limit = {
						has_trait = beauty_good
					}
					multiply = 2
				}
			}
			trigger = {
				scope:disfigure = yes
				OR = {
					NOR = {
						has_trait = maimed
						has_trait = beauty_bad
						ai_sociability < -75
					}
					has_trait = beauty_good
				}
			}
			desc = "DISFIGURE_NEGATIVE_REASON"
		}
		modifier = {
			add = -75
			trigger = {
				scope:disfigure = yes
				OR = {
					has_trait = maimed
					has_trait = beauty_bad
					ai_sociability < -75
				}
				NOT = { has_trait = beauty_good }
			}
			desc = "DISFIGURE_NEGATIVE_REASON"
		}
		# Blind
		modifier = {
			add = -100
			trigger = {
				scope:blind = yes
				NOR = {
					has_trait = one_eyed
					has_trait = infirm
					age > 60 # I.e. they have poor eyesight already
				}
			}
			desc = "BLIND_NEGATIVE_REASON"
		}
		modifier = {
			add = -75
			trigger = {
				scope:blind = yes
				OR = {
					has_trait = one_eyed
					has_trait = infirm
					age > 60 # I.e. they have poor eyesight already
				}
			}
			desc = "BLIND_NEGATIVE_REASON"
		}
		# Castrate
		modifier = {
			add = -75
			trigger = {
				scope:castrate = yes
				any_child = { count > 0 }
				ai_boldness < -50
			}
			desc = "CASTRATE_NEGATIVE_REASON"
		}
		modifier = {
			add = -100
			trigger = {
				scope:castrate = yes
				any_child = { count > 0 }
				ai_boldness >= -50
			}
			desc = "CASTRATE_NEGATIVE_REASON"
		}
		modifier = {
			add = -100
			trigger = {
				scope:castrate = yes
				any_child = { count <= 0 }
			}
			desc = "CASTRATE_NO_CHILDREN_NEGATIVE_REASON"
		}
		modifier = {
			add = -100
			trigger = {
				scope:castrate = yes
				has_trait = lustful
			}
			desc = "TAKE_VOWS_LUSTFUL_REASON"
		}
		# Demand admin
		modifier = {
			add = -20
			trigger = {
				scope:demand_admin = yes
				OR = {
					culture = {
						OR = {
							# Historical cultures
							this = culture:greek
							any_parent_culture_or_above = {
								this = culture:greek
							}
							this = culture:han
							any_parent_culture_or_above = {
								this = culture:han
							}
							# Bureaucratic culture
							has_cultural_pillar = ethos_bureaucratic
						}
					}
					# Another admin government
					government_allows = administrative
				}
			}
			desc = "DEMAND_ADMIN_NEGATIVE_REASON"
		}
		modifier = {
			add = -50
			trigger = {
				scope:demand_admin = yes
				NOR = {
					culture = {
						OR = {
							# Historical cultures
							this = culture:greek
							any_parent_culture_or_above = {
								this = culture:greek
							}
							this = culture:han
							any_parent_culture_or_above = {
								this = culture:han
							}
							# Bureaucratic culture
							has_cultural_pillar = ethos_bureaucratic
						}
					}
					# Another admin government
					government_allows = administrative
				}
				culture = {
					NOR = {
						has_cultural_tradition = tradition_hereditary_hierarchy
						has_cultural_tradition = tradition_staunch_traditionalists
					}
				}
			}
			desc = "DEMAND_ADMIN_NEGATIVE_REASON"
		}
		modifier = {
			add = -100
			trigger = {
				scope:demand_admin = yes
				NOR = {
					culture = {
						OR = {
							# Historical cultures
							this = culture:greek
							any_parent_culture_or_above = {
								this = culture:greek
							}
							this = culture:han
							any_parent_culture_or_above = {
								this = culture:han
							}
							# Bureaucratic culture
							has_cultural_pillar = ethos_bureaucratic
						}
					}
					# Another admin government
					government_allows = administrative
				}
				culture = {
					OR = {
						has_cultural_tradition = tradition_hereditary_hierarchy
						has_cultural_tradition = tradition_staunch_traditionalists
					}
				}
			}
			desc = "DEMAND_ADMIN_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
				}
			}
		}
		
		criminal_splat_ai_accept_modifier = yes
		shunned_splat_ai_accept_modifier = yes
		virtuous_splat_ai_accept_modifier = yes
	}

	# 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:take_vows = yes
		}
		modifier = {
			add = 10
			scope:recruit = yes
		}
		modifier = {
			add = 30
			scope:disfigure = yes
		}
		modifier = {
			add = 20
			scope:blind = yes
		}
		modifier = {
			add = 50
			scope:castrate = 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_playable_character = 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_playable_character = 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_playable_character = 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_playable_character = 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
			scope:actor = {
				house_has_feud_relation_with_trigger = { TARGET = scope:recipient }

			}
		}
		#Byz AI can shove vassals off to remote monasteries - weigh that here
		modifier = {
			add = -10
			scope:take_vows = yes
			scope:actor = {
				culture = { has_cultural_pillar = heritage_byzantine }
			}
			scope:recipient = { is_vassal_or_below_of = scope:actor }
		}

		evaluate_action_increasing_house_unity = {
			VALUE = 100
		}
		#don't release prisoners that are tied with a prison break contract, we don't want it invalidating all the time
		modifier = {
			factor = 0
			scope:recipient = {
				has_character_flag = being_prisonbroken_by_laamp
			}
		}
	}
}

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_by_tier = {
		barony = 72
		county = 12
		duchy = 12
		kingdom = 12
		empire = 12
		hegemony = 12
	}

	ai_potential = {
		is_at_war = no
	}

	ai_will_do = {
		base = 0

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

		ai_value_modifier = {
			ai_compassion = -1
		}
		
		POD_execute_prisoner_ai_will_do_modifier = yes
		
		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
					holder ?= scope:recipient
				}
			}
		}
		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
					holder ?= scope:recipient
				}
			}
		}
		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
						holder ?= scope:recipient
					}
					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
				}
			}
		}

		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
				}
			}
		}

		#Nomads get the special beheading stuff
		modifier = {
			scope:actor = {
				mpo_keep_prisoners_heads_trigger = yes
				scope:recipient = {
					is_ruler = yes
					highest_held_title_tier >= tier_county
					is_adult = yes
				}
				NOT = {
					scope:recipient.top_liege ?= {
						current_military_strength > scope:actor.current_military_strength
						tier_difference = {
							target = scope:actor
							value >= -1
						}
					}
				}
			}
			NOT = {
				scope:actor.faith = { has_doctrine_parameter = human_sacrifice_active }
			}
			add = 10
		}
		#Boost further if actor if want to keep head
		modifier = {
			#want to keep head
			scope:actor = {
				mpo_keep_prisoners_heads_trigger = yes
			}
			scope:recipient = {
				highest_held_title_tier >= tier_kingdom
				is_adult = yes
			}
			NOT = {
				scope:actor.faith = { has_doctrine_parameter = human_sacrifice_active }
			}
			add = 20
		}
		#Boost further if actor wants to be scary
		modifier = {
			#want to keep head
			scope:actor = {
				mpo_keep_prisoners_heads_trigger = yes
				scope:recipient = {
					is_ruler = yes
					highest_held_title_tier >= tier_county
					is_adult = yes
				}
				OR = {
					has_trait = conqueror
					has_trait = greatest_of_khans
					is_gurkhan = yes
				}
			}
			NOT = {
				scope:actor.faith = { has_doctrine_parameter = human_sacrifice_active }
			}
			add = 30
		}

		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
				}
			}
		}
		modifier = {
			add = 200
			scope:actor.faith = {
				has_doctrine = tenet_extinction_of_dharma
			}
			scope:recipient.faith = {
				religion = root.faith.religion
				NOT = {
					has_doctrine = tenet_extinction_of_dharma
				}
			}
		}
		#don't kill prisoners that are tied with a prison break contract, we don't want it invalidating all the time
		modifier = {
			factor = 0
			scope:recipient = {
				has_character_flag = being_prisonbroken_by_laamp
			}
		}
	}

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

	is_valid_showing_failures_only = {
		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
						}
					}
				}
			}
		}

		# For use with co-ruler diarchs.
		scope:recipient = { is_imprisoned_by = scope:actor }
	}

	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 = {
		# If this is a co-ruler we're executing, tell us if we have alternatives.
		scope:actor = {
			if = {
				limit = {
					OR = {
						AND = {
							has_diarchy_active_parameter = diarchy_is_co_rulership
							diarch ?= scope:recipient
						}
						AND = {
							scope:recipient = { has_diarchy_active_parameter = diarchy_is_co_rulership }
							is_diarch_of_target = scope:recipient
						}
					}
				}
				# If the player doesn't have to execute their partner, point that out.
				if = {
					limit = { liege_can_maim_co_ruler_without_killing_them_trigger = yes }
					custom_tooltip = execute_prisoner_interaction.tt.can_maim_diarch
				}
				# Otherwise, if they're out diarch, we end it.
				if = {
					limit = { scope:actor.diarch = scope:recipient }
					end_diarchy = yes
					every_player = {
						limit = {
							NOR = {
								this = scope:actor
								this = scope:recipient
							}
							top_liege = scope:actor.top_liege
						}
						trigger_event = diarchy.8022
					}
				}
				# Else, usurp.
				else = {
					custom_description_no_bullet = {
						text = execute_prisoner_interaction_tt_co_emperor_usurpation
						object = scope:recipient
					}
					create_title_and_vassal_change = {
						type = usurped
						save_scope_as = change
					}
					scope:recipient = {
						every_held_title = {
							limit = {
								OR = {
									this = scope:recipient.capital_county
									this = scope:recipient.capital_county.duchy
									AND = {
										tier = tier_county
										this.duchy = scope:recipient.capital_county.duchy
									}
									tier >= scope:recipient.highest_held_title_tier
								}
							}
							change_title_holder = {
								holder = scope:actor
								change = scope:change
							}
						}
						every_vassal = {
							custom = custom.recipient_every_vassal
							change_liege = {
								LIEGE = scope:actor
								CHANGE = scope:change
							}
						}
						hidden_effect = {
							change_liege = {
								LIEGE = scope:actor
								CHANGE = scope:change
							}
						}
					}
					resolve_title_and_vassal_change = scope:change
					every_player = {
						limit = {
							NOR = {
								this = scope:actor
								this = scope:recipient
							}
							top_liege = scope:actor.top_liege
						}
						trigger_event = diarchy.8023
					}
				}
			}
			# Regardless, this is legit politics, so we don't deduct legitimacy for it.
			save_scope_value_as = {
				name = suppress_legitimacy_from_crime
				value = yes
			}
		}
		# Now, the rest of it.
		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
					}
				}
			}
			show_as_tooltip = {
				scope:actor = { POD_commit_murder_effect = yes }
			}
			
			# POD CfV:
			# Secondary effects and custom send options go in this scripted_effect
			# so that the vanilla file stays clean
			POD_execute_prisoner_effects = yes
			
			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 = {
								title_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 = {
					always = no # CfV: disabled in PoD
					NOT = { always = scope:execution_devour }
					scope:actor = {
						has_relation_rival = scope:recipient
						has_personality_malicious_trigger = yes
						has_royal_court = yes
						has_dlc_feature = court_artifacts
					}
					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 }
					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 }
					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 }
			}
			# Gallowsbait.
			scope:actor = {
				if = {
					limit = {
						has_government = landless_adventurer_government
						scope:recipient = {
							is_landless_adventurer = no
							is_ruler = yes
						}
					}
					if = {
						limit = { scope:recipient.highest_held_title_tier >= tier_empire }
						laamp_rewards_apply_criminal_xp_effect = {
							TRACK = marauder
							XP_MAX = gallowsbait_xp_massive_gain
							XP_MIN = gallowsbait_xp_massive_gain
						}
					}
					else_if = {
						limit = { scope:recipient.highest_held_title_tier >= tier_kingdom }
						laamp_rewards_apply_criminal_xp_effect = {
							TRACK = marauder
							XP_MAX = gallowsbait_xp_major_gain
							XP_MIN = gallowsbait_xp_major_gain
						}
					}
					else_if = {
						limit = { scope:recipient.highest_held_title_tier >= tier_duchy }
						laamp_rewards_apply_criminal_xp_effect = {
							TRACK = marauder
							XP_MAX = gallowsbait_xp_medium_gain
							XP_MIN = gallowsbait_xp_medium_gain
						}
					}
					else_if = {
						limit = { scope:recipient.highest_held_title_tier >= tier_barony }
						laamp_rewards_apply_criminal_xp_effect = {
							TRACK = marauder
							XP_MAX = gallowsbait_xp_minor_gain
							XP_MIN = gallowsbait_xp_minor_gain
						}
					}
					else = {
						laamp_rewards_apply_criminal_xp_effect = {
							TRACK = marauder
							XP_MAX = 2
							XP_MIN = 2
						}
					}
				}
			}

			# 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
						}
					}
				}
				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
						}
					}
				}
			}

			if = {
				limit = {
					scope:actor.faith = {
						has_doctrine = tenet_extinction_of_dharma
					}
					scope:recipient.faith = {
						religion = scope:actor.faith.religion
						NOT = {
							has_doctrine = tenet_extinction_of_dharma
						}
					}
				}
				if = {
					limit = {
						scope:recipient = {
							is_ruler = yes
							highest_held_title_tier = tier_county
						}
					}
					scope:actor = {
						add_piety = minor_piety_value
					}
				}
				else_if = {
					limit = {
						scope:recipient = {
							highest_held_title_tier = tier_duchy
						}
					}
					scope:actor = {
						add_piety = medium_piety_value
					}
				}
				else_if = {
					limit = {
						scope:recipient = {
							highest_held_title_tier = tier_kingdom
						}
					}
					scope:actor = {
						add_piety = major_piety_value
					}
				}
				else_if = {
					limit = {
						scope:recipient = {
							highest_held_title_tier = tier_empire
						}
					}
					scope:actor = {
						add_piety = massive_piety_value
					}
				}
				else_if = {
					limit = {
						scope:recipient = {
							highest_held_title_tier = tier_hegemony
						}
					}
					scope:actor = {
						add_piety = monumental_piety_value
					}
				}
				else = {
					scope:actor = {
						add_piety = miniscule_piety_value
					}
				}
			}
			if = {
				limit = {
					scope:execution_beheaded = yes
					scope:actor = {
						faith = {
							has_doctrine = tenet_cranial_trophies
						}
					}
					scope:recipient = {
						is_adult = yes
						is_faith_dominant_gender = yes
					}
				}
				tgp_cranial_trophies_beheading_effect = {
					KILLER = scope:actor
					DEAD = scope:recipient
				}
			}
			# Kill the target
			### PoD CfV:
			### disabled this part and moved it to the end
			### so it doesn't interfere with our scripts
			if = {
				limit = {
					always = no
					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_if = { limit = { always = no }
				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 }
							}
						}
					}
					POD_secondary_effects_from_cannibalism = yes
				}
			}

			if = {
				limit = { always = scope:execution_provisions }
				scope:actor = {
					# PoD CfV: nerfed
					add_dread = 5
					add_prestige = -50
				}
			}

			if = {
				limit = {
					always = scope:execution_burned
					scope:actor.faith = {
						has_doctrine = doctrine_pluralism_fundamentalist
						NOT = {
							has_doctrine = tenet_extinction_of_dharma
						}
						NAND = {
							scope:recipient.faith = faith:innocence
							scope:recipient = { has_trait = mortal }
							scope:recipient = { has_trait = orison_innocent }
						}
					}
				}
				scope:actor = {
					add_piety = miniscule_piety_value
				}
			}
			
			### PoD CfV:
			### moved this part to the end so it doesn't interfere with our scripts
			# Kill the target
			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
				}
			}

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

	options_heading = execution_options_heading

	send_option = {
		is_shown = {
			OR = {
				scope:actor.faith = scope:recipient.faith
				scope:recipient ?= { is_vampire_trigger = yes }
				scope:recipient ?= { has_trait = mortal }
				AND = { 
					exists = scope:recipient
					POD_incompatible_splats_trigger = yes
				}
				scope:actor = {
					mpo_keep_prisoners_heads_trigger = yes
				}
				scope:actor.faith = {
					has_doctrine = tenet_cranial_trophies
				}
			}
			NOT = {
				scope:actor.faith = { has_doctrine_parameter = human_sacrifice_active }
			}			
		}
		is_valid = {
			AND = { 
				exists = scope:recipient
				POD_damage_spirit_trigger = yes
			}
		}
		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 }
					is_nagaraja_trigger = yes 
				}
			}
		}
		is_valid = {
			trigger_if = {
				limit = { scope:actor = { POD_is_unholy_trigger = yes } }
				exists = scope:recipient
				custom_description = { 
					object = scope:recipient
					text = "blood_is_holy"
					scope:recipient = {
						NOR = {
							POD_has_true_faith_trigger = yes
							has_trait = orison_sanguine
						}
					}
				}
			}
			scope:actor = { POD_is_not_incorporeal_spirit = yes }
			scope:recipient ?= { POD_is_not_incorporeal_spirit = yes }
		}
		flag = execution_devour
		localization = "EXECUTION_DEVOUR"
	}

	send_option = {
		is_shown = {
			scope:recipient ?= { is_mortal_trigger = no }
			OR = {
				NOT = {
					scope:actor.faith = scope:recipient.faith
					scope:actor.faith = { has_doctrine_parameter = human_sacrifice_active }
					scope:actor.faith = { has_doctrine = tenet_pursuit_of_knowledge }
				}
				scope:recipient ?= { is_vampire_trigger = yes }
			}
		}
		is_valid = {
			AND = { 
				exists = scope:recipient
				POD_damage_spirit_trigger = yes
			}
		}
		flag = execution_burned
		localization = "EXECUTION_BURNED"
	}

	send_option = {
		is_shown = {
			scope:actor.faith = { has_doctrine_parameter = human_sacrifice_active }
		}
		is_valid = {
			AND = { 
				exists = scope:recipient
				POD_damage_spirit_trigger = yes
			}
		}
		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
					}
				}
			}
			AND = { 
				exists = scope:recipient
				POD_damage_spirit_trigger = yes
			}
		}
		flag = execution_public
		localization = "EXECUTION_PUBLIC"
	}

	send_option = {
		is_shown = {
			scope:actor = {
				employs_court_position = kennelperson_camp_officer
				any_court_position_holder = {
			        type = kennelperson_camp_officer
			        is_physically_able = yes
			    }
			}
		}
		flag = execution_kennel
		localization = "EXECUTION_KENNEL"
	}

	send_option = {
		is_shown = {
			scope:actor = {
				has_government = landless_adventurer_government
				has_perk = fear_tax_perk
			}
			scope:recipient = {
				POD_can_be_killed_physically_trigger = yes
			}
		}
		flag = execution_provisions
		localization = "EXECUTION_PROVISIONS"
	}

	##### CfV: PoD Execution Options

	send_option = {
		is_shown = {
			scope:actor = { is_ai = no }
			scope:actor = { is_vampire_trigger = yes }
			scope:recipient ?= { 
				is_vampire_trigger = yes
				POD_is_clone_trigger = no
				NOT = { has_character_modifier = control_puppet_modifier }
			}
		}
		is_valid = {
			custom_tooltip = {
				text = POD_journey_exsanguination_disabled
				scope:actor = { POD_is_in_travel_phase_trigger = no }
			}
		}
		flag = execution_diablerie
		localization = "EXECUTION_DIABLERIE"
	}

	send_option = {
		is_shown = {
			scope:actor = { is_ai = no }	
			scope:actor = { this = character:790247 }
			scope:actor = { completely_controls = title:c_halych }
			scope:recipient ?= { POD_is_clone_trigger = no }
		}
		is_valid = {
			AND = { 
				exists = scope:recipient
				POD_damage_spirit_trigger = yes
			}
		}
		flag = execution_yorak
		localization = "EXECUTION_YORAK"
	}

	send_option = {
		is_shown = {
			scope:actor = { is_ai = no }	
			scope:actor = { this = character:795059 }
			scope:recipient ?= { POD_is_clone_trigger = no }
		}
		is_valid = {
			AND = { 
				exists = scope:recipient
				POD_damage_spirit_trigger = yes
			}
		}
		flag = execution_shou
		localization = "EXECUTION_SHOU"
	}
	
	send_option = {
		is_shown = {
			scope:actor = { this = character:790113 }
			scope:actor = { is_ai = no }
			scope:recipient ?= { POD_is_clone_trigger = no }
		}
		is_valid = {
			AND = { 
				exists = scope:recipient
				POD_damage_spirit_trigger = yes
			}
		}
		flag = execution_darvag
		localization = "EXECUTION_DARVAG"
	}		

	send_option = {
		is_shown = {
			scope:recipient ?= { 
				POD_can_be_drained_as_prisoner_trigger = yes
				POD_is_clone_trigger = no
				trigger_if = {
					limit = { is_vampire_trigger = yes }
					# scope:actor = { is_vampire_trigger = no } # Diablerie
					# WRONG
				}
			}
			scope:actor = { 
				OR = { 
					POD_splat_can_feed_on_blood = yes
					faith = { has_doctrine = doctrine_fae_morality_unseelie }
				}
				POD_splat_feeds_via_cannibalism = no
			}
		}
		is_valid = {
			trigger_if = {
				limit = { scope:actor = { POD_is_unholy_trigger = yes } }
				exists = scope:recipient
				custom_description = { 
					object = scope:recipient
					text = "blood_is_holy"
					scope:recipient = {
						NOR = {
							POD_has_true_faith_trigger = yes
							has_trait = orison_sanguine
						}
					}
				}
			}
			custom_tooltip = {
				text = POD_journey_exsanguination_disabled
				scope:actor = { POD_is_in_travel_phase_trigger = no }
			}
		}
		flag = execution_exsanguination
		localization = "EXECUTION_EXSANGUINATION"
	}
	
	send_option = {
		is_shown = {
			scope:actor = { has_perk = absorb_the_mind_perk }
			scope:recipient ?= { 
				POD_is_not_robotic = yes
				NOT = { has_character_modifier = control_puppet_modifier }
			}
		}
		is_valid = {
			scope:actor = {
				POD_has_enough_splat_agnostic_energy_reserves = { AMOUNT = 6 }
				custom_tooltip = { 
					text = used_absorb_the_mind
					NOT = { any_memory = { has_memory_type = devore_mind_memory } }
				}
			}
		}
		flag = execution_absorb_the_mind
		localization = "EXECUTION_ABSORB_THE_MIND"
	}

	send_option = {
		is_shown = {
			scope:actor = { any_equipped_character_artifact = { has_variable = bean_nighe_caul } }
			scope:recipient ?= { NOT = { has_character_modifier = control_puppet_modifier } }
		}
		is_valid = {
			scope:actor = {
				POD_has_enough_splat_agnostic_energy_reserves = { AMOUNT = 6 }
			}
			scope:recipient ?= {
				can_convert_to_wraith_trigger = yes
			}
		}
		flag = execution_feed_the_caul
		localization = "EXECUTION_FEED_THE_CAUL"
	}


	send_option = {
		is_shown = {
			scope:actor = { POD_can_covert_to_wraith_trigger = yes }
			AND = { 
				exists = scope:recipient
				scope:recipient = {
					POD_is_clone_trigger = no
					can_convert_to_wraith_trigger = yes
					num_of_relation_possessesing_wraith = 0
				}
			}
		}
		is_valid = {
			AND = { 
				exists = scope:recipient
				custom_description = {
					object = scope:recipient
					text = convert_to_wraith_truefaith # elderly kukul junk, can be delete or keeped
					scope:recipient = {
						POD_has_true_faith_trigger = no
					}
				}
			}
		}
		flag = execution_convert_to_wraith
		localization = "EXECUTION_CONVERT_TO_WRAITH"
	}

	send_option = {
		is_shown = {
			scope:recipient ?= { has_trait = wraith }
			scope:actor = {
				OR = {
					has_perk = arcanoi_oubliette_perk
				}
			}
		}
		flag = execution_banish_to_tempest
		localization = "EXECUTION_BANISH_TO_TEMPEST"
	}

	send_option = {
		is_shown = {
			scope:actor = {
				OR = {
					scope:actor = { this = character:790320 } # Eater
					has_perk = obliviate_perk
				}
			}
		}
		flag = execution_unmaking
		localization = "EXECUTION_UNMAKING"
	}
	
	send_option = {
		is_shown = {
			scope:actor.faith = { has_doctrine_parameter = experiments_on_prisoners }
		}
		is_valid = {
			AND = { 
				exists = scope:recipient
				POD_damage_spirit_trigger = yes
			}
		}
		flag = execution_experiments
		localization = "EXECUTION_EXPERIMENTS"
	}	
	
	send_option = {
		is_shown = {
			scope:actor = { has_trait = asekh_sen }
			scope:recipient ?= { has_trait = mummy }
		}
		is_valid = {
			scope:actor = { NOT = { has_character_modifier = extra_life_4_modifier } }
		}
		flag = execution_fill_jars
		localization = "EXECUTION_FILL_JARS"
	}
	
	send_option = {
		is_shown = {
			scope:actor = { 
				has_perk = lore_manipulate_cohesion_perk
			}
		}
		is_valid = {
			AND = { 
				exists = scope:recipient
				POD_damage_spirit_trigger = yes
			}
		}
		flag = execution_evaporation
		localization = "EXECUTION_EVAPORATION"
	}

	send_option = {
		is_shown = {
			scope:actor = {
				is_demonologist_trigger = yes
				OR = {
					has_thrall_xp = {
						VALUE = 35
						COMPARATOR = ">="
					}
					has_diabolist_xp = {
						VALUE = 35
						COMPARATOR = ">="
					}
				}
				NOT = { has_trait = demon }
			}
			scope:recipient ?= { POD_has_guaranteed_resurrection = no }
		}
		is_valid = {
			AND = { 
				exists = scope:recipient
				POD_damage_spirit_trigger = yes
			}
		}
		flag = execution_sacrifice_to_demon
		localization = "EXECUTION_SACRIFICE_TO_DEMON"
	}

	send_option = {
		is_shown = {
			scope:actor = { 
				any_equipped_character_artifact = { has_variable = soultaker }
			}
		}
		is_valid = {
			AND = { 
				exists = scope:recipient
				scope:recipient = { 
					POD_is_not_robotic = yes
					NOT = { has_character_modifier = control_puppet_modifier } 
				}
			}
		}
		flag = execution_soultaker
		localization = "EXECUTION_SOULTAKER"
	}

	send_option = {
		is_shown = {
			scope:actor = { 
				any_directly_owned_province = {
					POD_is_colosseum_location_trigger = yes
				}
			}
		}
		flag = execution_colosseum
		localization = "EXECUTION_COLOSSEUM"
	}

	send_option = {
		is_shown = {
			scope:actor = {  has_perk = arcana_devour_soul_perk }
			scope:recipient = { has_trait = demon }
		}
		is_valid = { }
		flag = execution_demon_devour_soul
		localization = "EXECUTION_DEVOUR_SOUL"
	}

	send_option = {
		is_shown = {
			scope:actor = { 
				has_perk = demon_eating_techniquet_perk
			}
			scope:recipient = {
				has_trait = kueijin
			}
		}
		is_valid = {
			scope:actor = {
				POD_has_enough_splat_agnostic_energy_reserves = { AMOUNT = 6 }
			}
			custom_description = {
				object = scope:recipient
				text = "strong_mental_defenses_trigger"
				strong_mental_defenses_interaction_trigger = yes
			}
		}
		flag = execution_shih_devour_soul
		localization = "EXECUTION_DEVOUR_SOUL"
	}

	send_option = {
		is_shown = {
			scope:actor = { has_perk = sin_eating_perk }
			AND = { 
				exists = scope:recipient
				scope:recipient = {
					has_trait = wraith
				}
			}
		}
		is_valid = { AND = { exists = scope:recipient } }
		flag = execution_sin_eating
		localization = "EXECUTION_SIN_EATING"
	}
	send_option = {
		is_shown = {
			scope:actor = { has_perk = call_the_khaibit_perk }
			AND = { 
				exists = scope:recipient
				scope:recipient = {
					POD_is_clone_trigger = no
					can_convert_to_wraith_trigger = yes
					num_of_relation_possessesing_wraith = 0
				}
			}
		}
		is_valid = {
			AND = { 
				exists = scope:recipient
			}
		}
		flag = execution_call_khaibit
		localization = "EXECUTION_CALL_KHAIBIT"
	}
	send_option = {
		is_shown = {
			scope:actor = {
				OR = {
					has_perk = unmaking_perk
				}
			}
		}
		flag = execution_mummy_unmaking
		localization = "EXECUTION_UNMAKING"
	}
	
	##### CfV: End of PoD Execution Options
	
	send_options_exclusive = yes
	auto_accept = yes
}

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

	is_shown = {
		always = no # CfV PoD: replaced with more consistent debug interaction
		debug_only = yes
		scope:recipient = {
			is_imprisoned = no
		}
		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 = no
	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 }
		POD_torture_interaction_is_shown = yes
	}

	is_valid_showing_failures_only = {
		#scope:recipient = {
		#	NOT = {
		#		health <= 1.5 #Because torture would definitely kill them
		#	}
		#}
		scope:actor = {
			trigger_if = {
				limit = {
					domicile ?= { is_domicile_type = camp }
				}
				custom_tooltip = {
					text = laamp_torture_requires_tools_tt
					domicile = { has_domicile_parameter = camp_unlocks_torture_interaction }
				}
			}
		}
		scope:recipient = {
			custom_description = {
				text = "currently_being_tortured"
				NOT = { has_character_flag = is_being_tortured }
			}
		}
		# POD CfV: to make sure it shares a cooldown with POD_torture_all_prisoners_interaction
		scope:recipient = {
			NOT = { has_character_modifier = recently_tortured }
		}
		cannot_release_former_regent_whilst_old_regent_holds_power_trigger = {
			PRISONER = scope:recipient
			REGENT = scope:recipient.var:imprisoned_by_diarch
		}
		tgp_blocked_action_against_tenno_trigger = {
			ACTOR = scope:actor
			TARGET = scope:recipient
		}
	}

	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 = { POD_secondary_effects_from_torturing = yes }

		scope:recipient = {
			add_character_flag = {
				flag = is_being_tortured
				months = 6 # Players in MP can keep the event window open...
			}
		}
		scope:actor = { save_scope_as = bg_override_char }
		###EFFECT TOOLTIP###
		torture_interaction_actor_effect = yes
		show_as_tooltip = {
			scope:recipient = {
				add_character_modifier = {
					modifier = recently_tortured
					years = 5
				}
			}
		}
		if = {
			limit = {
				scope:actor = {
					domicile ?= { has_domicile_parameter = estate_torture_grants_influence }
				}
			}
			scope:actor = { custom_tooltip = estate_torture_grants_influence_desc }
		}

		###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 = lifestyle_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
			}
		}

		# House Relation
		scope:recipient.house ?= {
			change_house_relation_effect = {
				HOUSE = scope:actor.house
				VALUE = house_relation_damage_medium_value
				REASON = torture
				CHAR = scope:actor
				TARGET_CHAR = scope:recipient
				TITLE = scope:dummy_gender
			}
		}
	}

	auto_accept = yes

	# AI
	ai_targets = {
		ai_recipients = prisoners
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 36
		duchy = 24
		kingdom = 24
		empire = 12
		hegemony = 12
	}

	ai_potential = {
		always = yes
	}

	ai_will_do = {
		base = -50 # CfV

		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
			scope:actor = {
				house_has_feud_relation_with_trigger = { TARGET = scope:recipient }
			}
			add = 30
		}
		modifier = {
			scope:actor = {
				has_opinion_modifier = {
					modifier = tried_to_escape_from_prison_opinion
					target = scope:recipient
				}
			}
			add = 25
		}
	}
}

castrate_interaction = {
	interface_priority = 30
	icon = eunuch

	category = interaction_category_prison
	desc = castrate_interaction_desc

	is_shown = {
		scope:recipient = {
			is_imprisoned_by = scope:actor
			is_eunuch_trigger = no
			is_male = yes
		}
		scope:actor = {
			is_adult = yes
			OR = {
				culture = { has_cultural_parameter = can_castrate_prisoners }
				any_equipped_character_artifact = { has_variable = sets_emasculation }
				top_liege.primary_title = {
					has_variable = emulating_byz_punishment_var
				}
			}
			
			# If they're our partner emperor, we should use the maiming interaction instead.
			liege_should_systematically_maim_co_ruler_trigger = no
		}
	}

	is_valid_showing_failures_only = {
		POD_damage_spirit_trigger = yes
		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:recipient = {
			add_character_flag = {
				flag = is_being_tortured
				months = 6 # Players in MP can keep the event window open...
			}
			if = {
				limit = { scope:actor = { any_equipped_character_artifact = {  has_variable = sets_emasculation } } }
				POD_give_permanent_injury_effect = { TRAIT = eunuch_1 }
			}
		}

		blind_castrate_and_disfigure_effect = yes #Stress & dread

		show_as_tooltip = {
			scope:recipient = {
				if = {
					limit = {
						age < 12
					}
					ep3_child_castration_effect = yes
				}
				else = {
					ep3_youth_castration_effect = yes
				}
				release_from_prison = yes
			}
		}

		torture_blind_castrate_disfigure_opinion_effect = { VERB = castrated }

		scope:actor = {
			save_scope_as = bg_override_char
			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
		}

		# House Relation
		scope:recipient.house ?= {
			change_house_relation_effect = {
				HOUSE = scope:actor.house
				VALUE = house_relation_damage_medium_value
				REASON = torture
				CHAR = scope:actor
				TARGET_CHAR = scope:recipient
				TITLE = scope:dummy_gender
			}
		}
	}

	auto_accept = yes

	#ai_targets = {
	#	ai_recipients = prisoners
	#}

	#ai_potential = {
	#	always = no
	#}

	ai_will_do = {
		base = -50

		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
			scope:actor = {
				house_has_feud_relation_with_trigger = { TARGET = scope:recipient }
			}
			add = 30
		}
		modifier = {
			scope:actor = {
				has_opinion_modifier = {
					modifier = tried_to_escape_from_prison_opinion
					target = scope:recipient
				}
			}
			add = 25
		}
		#Cruel Latins are really into this
		modifier = {
			top_liege.primary_title = {
				has_variable = emulating_byz_punishment_var
			}
			add = 30
		}
	}

	ai_frequency = 0 # CfV: no AI castration
}

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 }
			has_POD_vamp_blood_trigger = no
		}
		scope:actor = {
			is_adult = yes
			OR = {
				culture = { has_cultural_parameter = can_blind_prisoners }
				top_liege.primary_title = {
					has_variable = emulating_byz_punishment_var
				}
			}
			# If they're our partner emperor, we should use the maiming interaction instead.
			liege_should_systematically_maim_co_ruler_trigger = no
		}
	}

	is_valid_showing_failures_only = {
		POD_damage_spirit_trigger = yes
		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:recipient = {
			add_character_flag = {
				flag = is_being_tortured
				months = 6 # Players in MP can keep the event window open...
			}
		}

		blind_castrate_and_disfigure_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_disfigure_opinion_effect = { VERB = blinded }

		scope:actor = {
			save_scope_as = bg_override_char
			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
			}
		}

		# House Relation
		scope:recipient.house ?= {
			change_house_relation_effect = {
				HOUSE = scope:actor.house
				VALUE = house_relation_damage_medium_value
				REASON = torture
				CHAR = scope:actor
				TARGET_CHAR = scope:recipient
				TITLE = scope:dummy_gender
			}
		}
	}

	auto_accept = yes

	ai_targets = {
		ai_recipients = prisoners
	}

	ai_potential = {
		always = yes
	}

	ai_will_do = {
		base = -50

		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
			scope:actor = {
				house_has_feud_relation_with_trigger = { TARGET = scope:recipient }
			}
			add = 30
		}
		modifier = {
			scope:actor = {
				has_opinion_modifier = {
					modifier = tried_to_escape_from_prison_opinion
					target = scope:recipient
				}
			}
			add = 25
		}
		#Cruel Latins are really into this
		modifier = {
			top_liege.primary_title = {
				has_variable = emulating_byz_punishment_var
			}
			add = 30
		}
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 144
		duchy = 48
		kingdom = 36
		empire = 12
		hegemony = 12
	}
}

prison_break_contract_interaction = {
	interface_priority = 30
	common_interaction = yes
	icon = prison

	category = interaction_category_prison

	desc = prison_break_contract_interaction_desc

	cooldown_against_recipient = { years = 1 }

	is_shown = {
		scope:actor = {
			any_character_active_contract = {
				task_contract_type = laamp_prison_break_contract
				OR = {
					var:task_contract_target = scope:recipient
					var:task_contract_object = scope:recipient
					var:task_contract_employer = scope:recipient
				}
			}
		}
	}

	redirect = {
		scope:actor = {
			random_character_active_contract = {
				task_contract_type = laamp_prison_break_contract
				limit = {
					OR = {
						var:task_contract_target = scope:recipient
						var:task_contract_object = scope:recipient
						var:task_contract_employer = scope:recipient
					}
				}
				var:task_contract_object = {
					save_scope_as = secondary_recipient
				}
				var:task_contract_target = {
					save_scope_as = recipient
				}
				var:task_contract_employer = {
					save_scope_as = secondary_actor
				}
			}
		}
	}

	is_highlighted = {
		always = yes
	}

	on_accept = {
		scope:actor = {
			start_scheme = {
				type = laamp_prison_break_scheme
				target_character = scope:recipient
			}
			random_scheme = {
				type = laamp_prison_break_scheme
				limit = {
					scheme_target_character = scope:recipient
				}
				save_scope_as = scheme
			}
			#save scopes for scheme start event
			scope:secondary_recipient = {
				save_scope_as = task_contract_object
			}
			scope:recipient = {
				save_scope_as = task_contract_target
			}
			scope:secondary_actor = {
				save_scope_as = task_contract_employer
			}
			trigger_event = laamp_extra_contract_schemes.0011
		}
	}

	auto_accept = yes
}

systematically_maim_character_interaction = {
	interface_priority = 30
	icon = torture_interaction
	category = interaction_category_diarch
	common_interaction = no
	desc = systematically_maim_character_interaction_desc

	is_shown = {
		scope:actor = { liege_should_systematically_maim_co_ruler_trigger = yes }
	}

	is_valid_showing_failures_only = {
		scope:actor = { is_adult = yes }
		scope:recipient = {
			custom_description = {
				text = "currently_being_tortured"
				NOT = { has_character_flag = is_being_tortured }
			}
		}
		scope:recipient = { is_imprisoned_by = scope:actor }
		# There's literally nothing left to remove.
		scope:recipient = {
			NAND = {
				OR = {
					is_eunuch_trigger = yes
					is_female = yes
				}
				has_trait = blind
				has_trait = disfigured
				has_trait = maimed
				has_trait = one_legged
			}
		}
	}

	send_option = {
		flag = maim_castrate
		is_valid = {
			scope:recipient = {
				NOR = {
					is_eunuch_trigger = yes
					is_female = yes
				}
			}
		}
		localization = maim_castrate_name
		current_description = maim_castrate
	}
	send_option = {
		flag = maim_blind
		is_valid = {
			scope:recipient = {
				NOT = { has_trait = blind }
			}
		}
		localization = maim_blind_name
		current_description = maim_blind

	}
	send_option = {
		flag = maim_face
		is_valid = {
			scope:recipient = {
				NOT = { has_trait = disfigured }
			}
		}
		localization = maim_face_name
		current_description = maim_face
	}
	send_option = {
		flag = maim_leg
		is_valid = {
			scope:recipient = {
				NOT = { has_trait = one_legged }
			}
		}
		localization = maim_leg_name
		current_description = maim_leg
	}
	send_option = {
		flag = maim_arm
		is_valid = {
			scope:recipient = {
				NOT = { has_trait = maimed }
			}
		}
		localization = maim_arm_name
		current_description = maim_arm
	}

	on_accept = {
		scope:recipient = {
			add_character_flag = {
				flag = is_being_tortured
				months = 6 # Players in MP can keep the event window open...
			}
		}

		# Stress & dread
		blind_castrate_and_disfigure_effect = yes
		# Our diarchy will be destroyed.
		save_scope_value_as = {
			name = destroy_diarchy
			value = yes
		}
		show_as_tooltip = {
			scope:actor = { maiming_destroy_diarchy_effect = yes }
		}

		# Let the enchoppening begin.
		## Castrate.
		if = {
			limit = { scope:maim_castrate = yes }
			show_as_tooltip = {
				scope:recipient = {
					if = {
						limit = {
							age < 12
						}
						ep3_child_castration_effect = yes
					}
					else = {
						ep3_youth_castration_effect = yes
					}
					release_from_prison = yes
				}
			}
			torture_blind_castrate_disfigure_opinion_effect = { VERB = castrated }
			scope:actor = {
				clear_designated_heir = yes
				trigger_event = {
					id = prison.1025
					days = 1
				}
			}
			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
			}
		}
		## Blind.
		if = {
			limit = { scope:maim_blind = yes }
			show_as_tooltip = {
				scope:recipient = {
					add_trait = blind
					release_from_prison = yes
				}
			}
			torture_blind_castrate_disfigure_opinion_effect = { VERB = blinded }
			scope:actor = {
				clear_designated_heir = yes
				# Merciful Blindings
				if = {
					limit = {
						culture = { has_cultural_parameter = merciful_blinding }
						OR = {
							has_execute_reason = scope:recipient
							has_banish_reason = scope:recipient
						}
					}
					add_piety = medium_piety_gain
				}
				trigger_event = {
					id = prison.1020
					days = 1
				}
			}
			# If actor's culture has Merciful Blindings, they lose less unity.
			if = {
				limit = {
					scope:actor.culture = { has_cultural_parameter = merciful_blinding }
				}
				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
				}
			}
		}
		## Disfigure.
		if = {
			limit = { scope:maim_face = yes }
			show_as_tooltip = {
				scope:recipient = {
					add_trait = disfigured
					release_from_prison = yes
				}
			}
			torture_blind_castrate_disfigure_opinion_effect = { VERB = disfigured }
			scope:actor = {
				clear_designated_heir = yes
				trigger_event = {
					id = prison.1030
					days = 1
				}
			}
			add_clan_unity_interaction_effect = {
				CHARACTER = scope:actor
				TARGET = scope:recipient
				VALUE = major_unity_loss
				DESC = clan_unity_maimed.desc
				REVERSE_NON_HOUSE_TARGET = no
			}
		}
		## Take off an arm.
		if = {
			limit = { scope:maim_arm = yes }
			show_as_tooltip = {
				scope:recipient = {
					#apply_maimed_trait_and_modifier_effect = yes
					release_from_prison = yes
				}
			}
			torture_blind_castrate_disfigure_opinion_effect = { VERB = maimed }
			scope:actor = {
				clear_designated_heir = yes
				save_scope_value_as = {
					name = maim_type
					value = flag:arm
				}
				trigger_event = {
					id = prison.1041
					days = 1
				}
			}
			add_clan_unity_interaction_effect = {
				CHARACTER = scope:actor
				TARGET = scope:recipient
				VALUE = major_unity_loss
				DESC = clan_unity_maimed.desc
				REVERSE_NON_HOUSE_TARGET = no
			}
		}
		## Take off a leg.
		if = {
			limit = { scope:maim_leg = yes }
			show_as_tooltip = {
				scope:recipient = {
					add_trait = one_legged
					release_from_prison = yes
				}
			}
			torture_blind_castrate_disfigure_opinion_effect = { VERB = maimed }
			scope:actor = {
				clear_designated_heir = yes
				save_scope_value_as = {
					name = maim_type
					value = flag:leg
				}
				trigger_event = {
					id = prison.1041
					days = 1
				}
			}
			add_clan_unity_interaction_effect = {
				CHARACTER = scope:actor
				TARGET = scope:recipient
				VALUE = major_unity_loss
				DESC = clan_unity_maimed.desc
				REVERSE_NON_HOUSE_TARGET = no
			}
		}
	}

	auto_accept = yes

	ai_targets = { ai_recipients = prisoners }

	ai_potential = {
		has_diarchy_active_parameter = diarchy_is_co_rulership
		liege_can_maim_co_ruler_without_killing_them_trigger = yes
	}

	ai_will_do = {
		base = -50

		modifier = {
			has_trait = sadistic
			add = 50
		}
		modifier = {
			has_trait = callous
			add = 40
		}
		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 = -1
		}
		#Scope:target has caused internal strife in the realm
		character_hates_scope_due_to_strife_modifier = { TARGET = scope:recipient }
		modifier = { # Family Feud
			scope:actor = {
				house_has_feud_relation_with_trigger = { TARGET = scope:recipient }
			}
			add = 30
		}
		modifier = {
			scope:actor = {
				has_opinion_modifier = {
					modifier = tried_to_escape_from_prison_opinion
					target = scope:recipient
				}
			}
			add = 25
		}
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 0
		duchy = 0
		kingdom = 60
		empire = 60
		hegemony = 60
	}
}
