﻿imprison_interaction = {
	interface_priority = 120
	common_interaction = yes

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

	desc = imprison_interaction_desc

	greeting = negative
	notification_text = REQUEST_ARREST_NOTIFICATION_TEXT
	pre_answer_maybe_key = ANSWER_MIGHT_SUCCEED
	pre_answer_no_key = ANSWER_CANT_SUCCEED
	pre_answer_yes_key = ANSWER_WILL_SUCCEED
	pre_answer_maybe_breakdown_key = ANSWER_SUM_CHANCE

	on_decline_summary = imprison_decline_summary
	
	ai_potential = {
		NOT = { has_realm_law = tribal_authority_0 }
		is_imprisoned = no
	}

	is_shown = {
		NOT = { scope:actor = scope:recipient }
		scope:actor = {
			basic_allowed_to_imprison_character_trigger = {
				CHARACTER = scope:recipient
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:recipient = {
			is_diplomatically_available = yes
		}
		scope:actor = {
			allowed_to_imprison_character_trigger = {
				CHARACTER = scope:recipient
			}
		}
		scope:actor = {
			NOT = { has_realm_law = tribal_authority_0 }
		}

		scope:actor = {
			is_imprisoned = no
		}
		custom_description = {
			text = cannot_imprison_almohad_leader
			subject = scope:recipient
			NOT = { scope:recipient = { has_character_modifier = almohad_leader_modifier } }
		}
	}

	can_send = {
		scope:actor = {
			custom_description = {
				text = "character_interactions_hostile_actions_disabled_delay"
				NOT = { has_character_flag = flag_hostile_actions_disabled_delay }
			}
		}
	}
	
	is_highlighted = {
		scope:recipient = {
			is_imprisoned = no
		}
		scope:actor = {
			has_imprisonment_reason = scope:recipient
		}
	}

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

	send_options_exclusive = no

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

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

	on_accept = {
		if = {
			limit = { scope:hook = yes }
			scope:actor = { use_hook = scope:recipient }
		}
		illegal_imprisonment_dread_effect = yes
		imprison_court_chaplain_consequences_effect = yes
		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 = {
			if = { #If they recently revoked your title, or asked for your excommunication, they become your rival
				limit = {
					OR = {
						has_opinion_modifier = {
							target = scope:actor
							modifier = revoked_title
						}
						AND = {
							exists = var:requested_my_excommunication
							var:requested_my_excommunication = scope:actor
						}
					}
					NOT = {
						has_relation_rival = scope:actor
					}
				}
				hidden_effect = {
					if = {
						limit = {
							has_relation_potential_rival = scope:actor
						}
						remove_relation_potential_rival = scope:actor
					}
				}
				set_relation_rival = scope:actor
			}
			else = {
				hidden_effect = {
					progress_towards_rival_effect = {
						CHARACTER = scope:actor
						OPINION = no
					}
				}
			}
		}
		scope:actor = {
			trigger_event = char_interaction.0231
			if = {
				limit = {
					has_imprisonment_reason = scope:recipient
				}
				stress_impact = {
					compassionate = minor_stress_impact_gain
					forgiving = minor_stress_impact_gain
				}
			}
			else = {
				stress_impact = {
					just = medium_stress_impact_gain
					compassionate = medium_stress_impact_gain
				}
				if = {
					limit = { exists = scope:retaliating_faction}
					scope:retaliating_faction = {
						imprisonment_retribution_start_faction_war_if_valid = yes
					}
				}
			}
		}
		if = {
			limit = {
				scope:actor = { has_character_flag = flag_hostile_actions_disabled_delay }
			}
			scope:actor = { remove_character_flag = flag_hostile_actions_disabled_delay }
		}
	}
		
	on_decline = {
		illegal_imprisonment_dread_effect = yes
		scope:recipient = {
			#If target is count or higher, start war.
			if = {
				limit = {
					is_landed = yes
					primary_title.tier > tier_barony
				}
				if = {
					limit = {
						is_a_faction_member = yes
						liege = scope:actor
						joined_faction = {
							faction_target = scope:actor
							NOT = { faction_is_type = populist_faction }
						}
					}
					joined_faction = {
						save_scope_as = retaliating_faction # For loc
						imprisonment_retribution_start_faction_war_if_valid = yes
					}
					hidden_effect = {
						if = {
							limit = { NOT = { exists = joined_faction.faction_war } }
							war_for_imprison_effect = yes
						}
					}
				}
				else = {
					war_for_imprison_effect = yes
				}
			}
			#If target is a baron or unlanded, have them escape.
			else = {
				if = { #To block them from being instantly rehired
					limit = {
						is_councillor_of = scope:actor
						can_be_fired_from_council_trigger = { COURT_OWNER = scope:actor }
					}
					set_variable = {
						name = escaped_imprisonment_from
						value = scope:actor
						years = 20
					}
				}
				imprison_court_chaplain_consequences_effect = yes
				if = {
					limit = {
						is_landed = yes
					}
					custom_tooltip = deposed_and_become_wanderer
					hidden_effect = { 
						depose_effect = yes  ###Imperial mod
						move_to_pool = yes
					}
				}
				if = {
					limit = {
						is_landed = no
						trigger_if = {
							limit = {
								is_councillor = yes
							}
							can_be_fired_from_council_trigger = { COURT_OWNER = scope:recipient.liege }
						}
					}
					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
				}
			}
		}
		scope:actor = {
			if = {
				limit = {
					scope:recipient = {
						OR = {
							is_landed = no
							AND = {
								is_landed = 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 }
		}
	}

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

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

		modifier = {
			add = 30
			scope:hook = yes
			desc = SCHEME_HOOK_USED
		}
		opinion_modifier = { # Opinion Factor
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 0.5
			desc = AI_OPINION_REASON
		}
		ai_value_modifier = {
			who = scope:recipient
			ai_boldness = -0.5
			trigger = {
				scope:recipient = { NOT = { ai_boldness = 0 } }
			}
		}
		modifier = {
			add = 20
			scope:actor = {
				has_realm_law_flag = vassal_refusal_is_treason
			}
			desc = AI_REFUSAL_IS_TREASON
		}
		modifier = {
			add = 50
			scope:actor = {
				has_perk = prison_feudal_complex_perk
			}
			desc = AI_PRISON_FEUDAL_COMPLEX_PERK
		}
		modifier = { #I am a King!
			desc = offer_vassalization_interaction_aibehavior_amkingtier_tt
			scope:recipient = { highest_held_title_tier = tier_kingdom }
			add = -40
		}
		modifier = { #Courtiers.
			desc = AI_REFUSAL_COURTIER
			scope:recipient = { is_ruler = no }
			add = 50
		}
		modifier = { #Rank difference.
			desc = AI_REFUSAL_RANK_DIFFERENCE
			scope:recipient = {
				is_ruler = yes
				highest_held_title_tier < tier_kingdom
			}
			add = {
				value = -15
				if = {
					limit = {
						scope:actor = {
							tier_difference = {
								target = scope:recipient
								value >= 2
							}
						}
					}
					add = 5
				}
				if = {
					limit = {
						scope:actor = {
							tier_difference = {
								target = scope:recipient
								value >= 3
							}
						}
					}
					add = 5
				}
				if = { #King asking Baron, modifier becomes positive.
					limit = {
						scope:actor = {
							tier_difference = {
								target = scope:recipient
								value >= 4
							}
						}
					}
					add = 10
				}
			}
		}
		ai_value_modifier = {
			who = scope:recipient
			ai_honor = 0.75
			trigger = {
				scope:recipient = { #If AI is honorable and the law compels to obey the liege, AI will be more likely to obey.
					ai_honor > 0
				}
				scope:actor = {
					has_realm_law_flag = vassal_refusal_is_treason
				}
			}
		}
		modifier = {
			add = 25
			scope:recipient = {
				target_is_liege_or_above = scope:actor
				has_dread_level_towards = {
					target = scope:actor
					level = 1
				}
			}
			desc = INTIMIDATED_REASON
		}
		modifier = {
			add = 50
			scope:recipient = {
				target_is_liege_or_above = scope:actor
				has_dread_level_towards = {
					target = scope:actor
					level = 2
				}
			}
			desc = COWED_REASON
		}
		
		modifier = {
			add = 10
			scope:recipient = {
				NOT = { target_is_liege_or_above = scope:actor }
				has_dread_level_towards = {
					target = scope:actor
					level = 1
				}
			}
			desc = INTIMIDATED_REASON
		}
		modifier = {
			add = 20
			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.max_military_strength
					divide = { value = scope:actor.max_military_strength min = 1 }
					}
				multiply = 100
				min = -1000
				max = 1000
			}
		}
		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
		}
	}

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

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

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

		modifier = { # Avoid Tyranny wars at inopportune times
			add = -190
			scope:actor = {
				ai_rationality >= medium_negative_ai_value
				is_at_war = yes
			}
			scope:recipient = {
				is_landed = yes
			}
		}

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

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

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

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

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

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

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

	is_valid_showing_failures_only = {
		scope:recipient = { is_diplomatically_available = yes }
		scope:recipient = {
			custom_description = {
				text = "currently_being_tortured"
				NOT = { has_character_flag = is_being_tortured }
			}
		}
	}
	
	on_accept = {
		scope:recipient = {
			hidden_effect = {
				change_prison_type = dungeon
			}
			trigger_event = prison_notification.1001
			custom_tooltip = MOVE_PRISONER_TO_DUNGEON
			scope:recipient = {
				custom_tooltip = IMPRISONMENT_RELATIVES_EFFECT_MOVE_TO_DUNGEON
				hidden_effect = {
					every_close_or_extended_family_member = {
						limit = {
							NOT = { 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_generic_neutral
					title = msg_move_prisoner_to_dungeon
					right_icon = scope:recipient
					custom_tooltip = MOVE_PRISONER_TO_DUNGEON
				}
			}
		}
	}
	
	auto_accept = yes
	
	# AI
	ai_targets = {
		ai_recipients = prisoners
	}
	ai_frequency = 12

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

		modifier = {
			add = 100
			scope:actor.ai_compassion < medium_positive_ai_value
			scope:actor = {
				opinion = {
					target = scope:recipient
					value <= high_negative_opinion
				}
			}
		}
	}
}
	
move_to_house_arrest_interaction = {
	interface_priority = 30
	category = interaction_category_prison
	desc = move_to_house_arrest_interaction_desc

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

	is_valid_showing_failures_only = {
		scope:recipient = { is_diplomatically_available = yes }
		scope:recipient = {
			custom_description = {
				text = "currently_being_tortured"
				NOT = { has_character_flag = is_being_tortured }
			}
		}
	}
	
	on_accept = {
		scope:recipient = {
			hidden_effect = {
				change_prison_type = house_arrest
				trigger_event = prison_notification.1002
			}
			custom_tooltip = MOVE_PRISONER_TO_HOUSE_ARREST
			scope:recipient = {
				custom_tooltip = IMPRISONMENT_RELATIVES_EFFECT_MOVE_TO_HOUSE_ARREST
				hidden_effect = {
					every_close_or_extended_family_member = {
						limit = {
							NOT = { 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_generic_neutral
					title = msg_move_prisoner_to_house_arrest
					right_icon = scope:recipient
					custom_tooltip = MOVE_PRISONER_TO_HOUSE_ARREST
				}
			}
		}
	}
	
	auto_accept = yes
}

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

	desc = ransom_interaction_desc

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

	is_valid_showing_failures_only = {
		scope:recipient = { is_diplomatically_available = yes } #Payer
		scope:secondary_recipient = { is_diplomatically_available = yes } #Prisoner
		scope:secondary_recipient = {
			custom_description = {
				text = "currently_being_tortured"
				NOT = { has_character_flag = is_being_tortured }
			}
		}
	}
	
	on_accept = {
		if = {
			limit = { scope:secondary_recipient = { is_imprisoned_by = scope:actor } } # To prevent simultaneous release-shenanigans
			scope:secondary_recipient = {
				save_scope_as = prisoner
			}
			scope:actor = {
				save_scope_as = imprisoner
				trigger_event = char_interaction.0130
			}
			scope:recipient = {
				save_scope_as = payer
			}
			ransom_interaction_effect = yes
		}
	}

	on_decline = {
		scope:actor = {
			trigger_event = char_interaction.0131
		}
	}
	
	# Pay me what they're worth!
	send_option = {
		is_shown = {
			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:recipient = {
				gold < scope:secondary_recipient.ransom_cost_value
				gold > 0
			}
		}
		flag = current_gold
		localization = "RANSOM_CURRENT_GOLD_OPTION"
	}
	
	send_option = {
		is_valid = {
			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 = {
				can_add_hook = { #To match the hook added through ransom_interaction_effect
					target = scope:recipient
					type = favor_hook
				}
			}
		}
		flag = favor
		localization = "RANSOM_FAVOR_OPTION"
	}
	
	localization_values = {
		RANSOM_COST = scope:secondary_recipient.ransom_cost_value
		CURRENT_GOLD = scope:recipient.gold
	}
	
	ai_accept = {
		base = 0
		modifier = { # Greedy characters can have their greed get the better of them...
			add = { 
				value = scope:recipient.ai_greed
				multiply = -0.5 
			}
			scope:recipient.ai_greed >= medium_positive_ai_value
			scope:gold = yes
			NOT = {
				scope:recipient = scope:secondary_recipient
			}		
			desc = AI_VALUE_MODIFIER_GREED
		}
		modifier = { # Generous characters are more willing to pay
			add = { 
				value = scope:recipient.ai_greed
				multiply = -0.10 
			}
			scope:gold = yes
			NOT = {
				scope:recipient = scope:secondary_recipient
			}
			scope:recipient.ai_greed <= medium_negative_ai_value 
			desc = AI_VALUE_MODIFIER_GENEROUS
		}
		modifier = {
			add = -10
			NOT = { scope:recipient = scope:secondary_recipient }
			scope:recipient = {
				NOR = {
					is_spouse_of = scope:secondary_recipient
					is_close_or_extended_family_of = scope:secondary_recipient
					has_relation_lover = scope:secondary_recipient
					has_relation_friend = scope:secondary_recipient
					has_secret_relation_lover = scope:secondary_recipient
					has_relation_soulmate = scope:secondary_recipient
					has_relation_best_friend = scope:secondary_recipient
					is_parent_of = scope:secondary_recipient
				}
			}
			desc = "UNIMPORTANT_CHAR_REASON"
		}
		modifier = {
			add = 100
			scope:recipient = scope:secondary_recipient
			desc = "WANTS_FREEDOM_REASON"
		}
		modifier = { # Acceptance boon for lovers, friends, etc
			add = 25
			NOT = { scope:recipient = scope:secondary_recipient }
			scope:recipient = {
				OR = {
					is_spouse_of = scope:secondary_recipient
					is_close_or_extended_family_of = scope:secondary_recipient
					has_relation_lover = scope:secondary_recipient
					has_relation_friend = scope:secondary_recipient
					has_secret_relation_lover = scope:secondary_recipient
				}
				NOR = {
					has_relation_soulmate = scope:secondary_recipient
					has_relation_best_friend = scope:secondary_recipient
					is_parent_of = scope:secondary_recipient
				}
			}
			desc = "DEAR_TO_ME_REASON"
		}
		modifier = { # Massive acceptance boon for Soulmates and Best Friends
			add = 200
			scope:recipient = {
				OR = {
					has_relation_soulmate = scope:secondary_recipient
					has_relation_best_friend = scope:secondary_recipient
					is_parent_of = scope:secondary_recipient
				}
				NOR = {
					is_spouse_of = scope:secondary_recipient
					AND = {
						NOT = {
							is_parent_of = scope:secondary_recipient
						}
						is_close_or_extended_family_of = scope:secondary_recipient
					}
					has_relation_lover = scope:secondary_recipient
					has_relation_friend = scope:secondary_recipient
					has_secret_relation_lover = scope:secondary_recipient
				}
			}
			desc = "DEAR_TO_ME_REASON"
		}
		modifier = { # Say no to rivals
			add = -200
			scope:recipient = {
				has_relation_rival = scope:secondary_recipient
			}
			desc = "RIVAL_TO_ME_REASON"
		}
		modifier = { # Say no to rivals
			add = -500
			scope:recipient = {
				has_relation_nemesis = scope:secondary_recipient
			}
			desc = "NEMESIS_TO_ME_REASON"
		}
		modifier = {
			add = 10
			scope:recipient = {
				NOR = {
					this = scope:secondary_recipient
					is_spouse_of = scope:secondary_recipient
					is_close_or_extended_family_of = scope:secondary_recipient
					has_relation_lover = scope:secondary_recipient
					has_relation_soulmate = scope:secondary_recipient
					has_secret_relation_lover = scope:secondary_recipient
				}
				NOR = {
					has_relation_rival = scope:secondary_recipient
					has_relation_nemesis = scope:secondary_recipient
				}
			}
			scope:recipient.dynasty = scope:secondary_recipient.dynasty
			desc = "MY_DYNASTY_REASON"
		}
		modifier = { # An Intimidated recipient is significantly more likely to accept an offer from the liege
			add = 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
		}
	}
	
	# AI
	ai_targets = {
		ai_recipients = prisoners
	}
	ai_frequency = 6

	ai_potential = {
		always = yes
	}

	ai_will_do = {
		base = 0
		
		modifier = {
			add = 100
			OR = {
				scope: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
			scope:gold = yes
		}
		
		modifier = {
			add = -100
			has_relation_rival = scope:secondary_recipient
		}
		
		modifier = {
			add = -300
			has_relation_nemesis = scope:secondary_recipient
		}
		
		modifier = {
			add = 100
			scope:favor = yes
			scope:recipient = {
				OR = {
					is_vassal_of = scope:actor
					AND = {
						exists = liege
						liege = scope:actor
					}
				}
			}
		}
		
		modifier = {
			factor = 0
			is_at_war = yes
		}
	}
}

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

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

	desc = pay_ransom_interaction_desc

	greeting = positive
	notification_text = PAY_RANSOM_PROPOSAL
	
	is_shown = {
		exists = scope:recipient
		scope:secondary_recipient = {
			exists = liege
			liege = scope:actor
			is_imprisoned_by = scope:recipient
		}
		NOT = {
			scope:actor = scope:recipient
		}
	}

	is_valid_showing_failures_only = {
		scope:recipient = { is_diplomatically_available = yes } #Imprisoner
		scope:secondary_recipient = { is_diplomatically_available = yes } #Prisoner
		scope:recipient = {
			custom_description = {
				text = "currently_being_tortured"
				NOT = { has_character_flag = is_being_tortured }
			}
		}
	}
	
	on_accept = {
		if = {
			limit = { scope:secondary_recipient = { is_imprisoned_by = scope:recipient } }
			scope:secondary_recipient = {
				save_scope_as = prisoner
			}
			scope:actor = {
				save_scope_as = payer
				trigger_event = char_interaction.0140
			}
			scope:recipient = {
				save_scope_as = imprisoner
			}
			ransom_interaction_effect = yes
			if = {
				limit = { scope:hook = yes }
				scope:actor = {
					use_hook = scope:recipient
				}
			}
		}
	}

	on_decline = {
		scope:actor = {
			trigger_event = char_interaction.0141
		}
	}
	
	send_option = {
		is_valid = {
			exists = scope:recipient
			scope:actor = {
				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 = {
			exists = scope:recipient
			scope:actor = {
				gold < scope:secondary_recipient.ransom_cost_value
				gold > 0
			}
		}
		flag = current_gold
		localization = "RANSOM_CURRENT_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_FAVOR_OPTION"
	}

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

	send_options_exclusive = no
	
	localization_values = {
		RANSOM_COST = scope:secondary_recipient.ransom_cost_value
		CURRENT_GOLD = scope:actor.gold
	}
	
	ai_accept = {
		base = 0
		modifier = {
			add = 50
			scope:gold = yes
			desc = "GOLD_POSITIVE_REASON"
		}
		modifier = {
			add = 15
			scope:current_gold = yes
			scope:actor = {
				gold >= scope:secondary_recipient.half_ransom_cost_value
			}
			desc = "GOLD_POSITIVE_REASON"
		}
		modifier = {
			add = 50
			scope:favor = yes
			scope:recipient.top_liege = scope:actor.top_liege
			desc = "FAVOR_POSITIVE_REASON"
		}
		modifier = {
			add = 0
			scope:favor = yes
			NOT = { scope:recipient.top_liege = scope:actor.top_liege }
			desc = "NO_USE_FOR_A_FAVOR_REASON"
		}
		modifier = { # 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"
		}
		#opinion_modifier = { # A lot more likely if Recipient likes Actor
		#	who = scope:recipient
		#	opinion_target = scope:actor
		#	multiplier = 1.0
		#	desc = AI_OPINION_REASON
		#}
		#opinion_modifier = { # A lot more likely if Recipient likes secondary_recipient/prisoner
		#	who = scope:recipient
		#	opinion_target = scope:secondary_recipient
		#	multiplier = 1.0
		#	desc = AI_OPINION_REASON
		#}
		modifier = {
			scope:hook = yes
			add = 100
			desc = SCHEME_WEAK_HOOK_USED
		}
		modifier = { # An Intimidated recipient is significantly more likely to accept an offer from the liege
			add = 40
			trigger = {
				scope:recipient = {
					target_is_liege_or_above = scope:actor
					has_dread_level_towards = {
						target = scope:actor
						level = 1
					}
				}
			}
			desc = INTIMIDATED_REASON
		}

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

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

	ai_potential = {
		gold >= 25
	}

	ai_target_quick_trigger = {
		prison = yes
	}

	ai_will_do = {
		base = 0
		
		modifier = {
			add = 100
			OR = {
				scope:gold = yes
				AND = {
					scope:actor = {
						gold >= 25
					}
					scope:secondary_recipient = {
						time_in_prison = { years > 1 }
					}
					scope:current_gold = yes
				}
			}
		}
		
		modifier = {
			add = -100
			has_relation_rival = scope:secondary_recipient
		}
		
		modifier = {
			add = -300
			has_relation_nemesis = scope:secondary_recipient
		}
		
		modifier = {
			add = 100
			scope:favor = yes
			scope:recipient = {
				OR = {
					is_vassal_of = scope:actor
					AND = {
						exists = liege
						liege = scope:actor
					}
				}
			}
		}
		
		modifier = { # Ransom your primary heir first
			add = 10
			OR = {
				scope:gold = yes
				AND = {
					scope:actor = {
						gold >= 25
					}
					scope:secondary_recipient = {
						time_in_prison = { years > 1 }
					}
					scope:current_gold = yes
				}
				AND = {
					scope:favor = yes
					scope:recipient = {
						OR = {
							is_vassal_of = scope:actor
							AND = {
								exists = liege
								liege = scope:actor
							}
						}
					}
				}
			}
			scope:secondary_recipient = {
				is_primary_heir_of = scope:actor
			}
		}
		
		modifier = { # Only ransom people you care about... unless you're very compassionate
			factor = 0
			scope:secondary_recipient = {
				NOR = {
					is_heir_of = scope:actor
					is_child_of = scope:actor
					is_consort_of = scope:actor
					has_relation_best_friend = scope:actor
					has_relation_friend = scope:actor
					has_relation_lover = scope:actor
					has_secret_relation_lover = scope:actor
				}
			}
			ai_compassion < high_positive_ai_value
		}
		
		modifier = { # Don't give away prisoners for free
			factor = 0
			NOR = {
				scope:favor = yes
				scope:gold = yes
				scope:current_gold = yes
			}
		}
		
		modifier = { # Don't annoy players
			factor = 0
			scope:recipient = {
				is_ai = no
				is_at_war = yes
			}
		}
	}
}

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

	greeting = positive
	notification_text = PAY_RANSOM_PROPOSAL_PERSONAL

	desc = ransom_me_interaction_desc
	
	is_shown = {
		scope:actor = {
			is_imprisoned_by = scope:recipient
		}
	}

	is_valid_showing_failures_only = {
		scope:recipient = { is_diplomatically_available = yes } #Imprisoner
		scope:actor = { is_diplomatically_available = yes } #Prisoner
		scope:recipient = {
			custom_description = {
				text = "currently_being_tortured"
				NOT = { has_character_flag = is_being_tortured }
			}
		}
	}
	
	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
				trigger_event = char_interaction.0150
			}
			ransom_interaction_effect = yes
			if = {
				limit = { always = scope:hook }
				scope:actor = {
					use_hook = scope:recipient
				}
			}
		}
	}

	on_decline = {
		scope:actor = {
			trigger_event = char_interaction.0151
		}
	}
	
	send_option = {
		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 = {
			scope:actor = {
				gold < ransom_cost
				gold > 0
			}
		}
		flag = current_gold
		localization = "RANSOM_CURRENT_GOLD_OPTION"
	}
	
	send_option = {
		is_valid = {
			scope:recipient = {
				can_add_hook = { #To match the hook added through ransom_interaction_effect
					target = scope:actor
					type = favor_hook
				}
			}
		}
		flag = favor
		localization = "RANSOM_FAVOR_OPTION"
	}

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

	send_options_exclusive = no
	
	localization_values = {
		RANSOM_COST = scope:actor.ransom_cost_value
		CURRENT_GOLD = scope:actor.gold
	}
	
	ai_accept = {
		base = 0
		modifier = {
			add = 50
			scope:gold = yes
			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
			NOT = {
				scope:gold = yes
			}
			OR = {
				NOT = { scope:recipient.top_liege = scope:actor.top_liege }
				scope:recipient.ai_greed >= medium_positive_ai_value
			}
			desc = "NO_USE_FOR_A_FAVOR_REASON"
		}
		
		#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 rivals
			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 = 40
			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 = 100
			trigger = {
				scope:recipient = {
					target_is_liege_or_above = scope:actor
					has_dread_level_towards = {
						target = scope:actor
						level = 2
					}
				}
			}
			desc = COWED_REASON
		}
	}

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

	ai_potential = {
		always = yes
	}

	ai_will_do = {
		base = 100
	}
}

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

	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:retire = no
				}
				desc = RELEASE_PRISONER_OFFER
			}
			desc = RELEASE_PRISONER_OFFER_CONDITIONAL
		}
	}
	
	is_shown = {
		scope:recipient = {
			is_imprisoned_by = scope:actor
		}
	}

	is_valid_showing_failures_only = {
		scope:recipient = { is_diplomatically_available = yes } #Prisoner
		scope:recipient = {
			custom_description = {
				text = "currently_being_tortured"
				NOT = { has_character_flag = is_being_tortured }
			}
		}
	}
	
	on_accept = {
		if = {
			limit = { scope:recipient = { is_imprisoned_by = scope:actor } }
			scope:recipient = {
				# Demand Conversion
				if = {
					limit = {
						scope:demand_conversion = yes
					}
					set_character_faith = scope:actor.faith
					add_opinion = {
						modifier = demanded_conversion
						target = scope:actor
					}
				}
				
				# Banish Landed Character
				if = {
					limit = {
						scope:banish = yes
						scope:recipient = { is_landed = yes	}
					}
					banish = yes
					if = {
						limit = {
							NOT = {
								scope:actor = {
									has_banish_reason = scope:recipient
								}
							}
						}
						scope:actor = { add_tyranny = banishment_tyranny_gain }
					}
					add_opinion = {
						modifier = banished_me
						target = scope:actor
					}
				}
				# Banish Unlanded Character
				else_if = {
					limit = {
						AND = {
							scope:banish = yes
							scope:recipient = {
								is_landed = no
								is_pool_character = no # It is possible for them to end up in the pool between the interaction being sent, and it being accepted
							}
						}
					}
					if = {
						limit = {
							this.gold > 0
						}
						pay_short_term_gold = { target = scope:actor gold = this.gold }
					}
					banish = yes				
					add_opinion = {
						modifier = banished_me
						target = scope:actor
					}
				}
				# 'Banish' Pool Character
				else_if = {
					limit = {
						AND = {
							scope:banish = yes
							scope:recipient = {
								is_landed = no
								is_pool_character = yes # They'll just leave for the pool
							}
						}
					}
					if = {
						limit = {
							this.gold > 0
						}
						pay_short_term_gold = { target = scope:actor gold = this.gold }
					}		
					add_opinion = {
						modifier = banished_me
						target = scope:actor
					}
				}
				
				# Recruit Character
				if = {
					limit = {
						scope:recruit = yes
					}
					add_opinion = {
						modifier = demanded_recruitment
						target = scope:actor
					}
					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
					}
					add_opinion = {
						modifier = demanded_taking_vows
						target = scope:actor
					}
					add_trait = devoted
					if = { # Also depose them from held titles
						limit = { is_ruler = yes }
						depose_effect = yes  ###Imperial mod
					}
				}
				
				# Retire
				if = {
					limit = {
						scope:retire = yes
					}
					custom_description = {
						text = retire_decision_TOOLTIP
						retire_effect = yes
					}
					add_opinion = {
						modifier = forced_retirement
						target = scope:actor
					}
				}
				
				# No Demands Added
				if = {
					limit = {
						scope:demand_conversion = no
						scope:renounce_claims = no
						scope:banish = no
						scope:gain_hook = no
						scope:take_vows = no
						scope:recruit = no
					}
					# Notification to the imprisoner
					scope:actor = {
						send_interface_toast = {
							title = recipient_released_from_prison
							scope:recipient = {
								add_opinion = {
									modifier = released_from_prison
									target = scope:actor
								}
							}
						}
						scope:actor = {
							add_dread = minor_dread_loss
							stress_impact = {
								sadistic = medium_stress_impact_gain
								callous = minor_stress_impact_gain
							}
						}
					}
				}
				else = {
					scope:actor = {
						trigger_event = char_interaction.0160
					}
				}

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

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

	on_decline = {
		scope:actor = {
			trigger_event = char_interaction.0161
		}
	}
	
	send_option = {
		flag = demand_conversion
		localization = "RELEASE_DEMAND_CONVERSION"
		is_valid = {
			trigger_if = {
				limit = {
					scope:actor = { is_ai = yes }
				}
				scope:recipient = {
					OR = {
						is_close_or_extended_family_of = scope:actor
						is_vassal_of = scope:actor
					}
				}
			}
			NOT = {
				scope:recipient.faith = scope:actor.faith
			}
			# Cannot ask Religious Heads to convert
			custom_description = {
				text = cannot_demand_religious_head_conversion
				subject = scope:actor
				NOT = {
					AND = {
						exists = scope:recipient.faith.religious_head
						scope:recipient.faith.religious_head = scope:recipient
					}
				}
			}
		}
	}
	
	send_option = {
		flag = renounce_claims
		localization = RELEASE_RENOUNCE_CLAIMS
		is_shown = {
			custom_description = {
				text = "release_renounce_claims"
				subject = scope:recipient
				scope:recipient = {
					any_claim = {
						explicit = yes
						save_temporary_scope_as = temp_claim
						OR = {
							holder = scope:actor
							AND = {
								NOT = { prev = { target_is_liege_or_above = scope:actor } }
								trigger_if = {
									limit = {
										exists = holder
									}
									holder = { target_is_liege_or_above = scope:actor }
								}
							}
							scope:actor = {
								any_held_title = {
									is_de_jure_liege_or_above_target = scope:temp_claim
								}
							}
						}
					}
				}
			}
		}
		current_description = {
			desc = RELEASE_RENOUNCE_CLAIMS_DESC
		}
	}
	
	send_option = {
		flag = banish
		localization = "RELEASE_BANISH"
		is_shown = {
			trigger_if = {
				limit = {
					scope:actor = { is_ai = yes }
				}
				scope:recipient = {
					OR = {
						AND = {
							is_landed = no
							is_ruler = no
							gold > scope:actor.gold
							gold > scope:actor.medium_gold_value
							scope:actor.ai_greed > low_negative_ai_value
						}
						AND = {
							is_landed = no
							is_ruler = no
							gold > 0
							scope:actor = {
								has_banish_reason = scope:recipient
							}
						}
						AND = {
							is_landed = no
							is_ruler = no
							gold > 100
							scope:actor.ai_greed >= high_positive_ai_value
						}
						AND = {
							scope:actor = {
								has_banish_reason = scope:recipient
							}
							scope:actor = {
								opinion = {
									target = scope:recipient
									value <= medium_negative_opinion
								}
							}
						}
					}
				}
			}
			trigger_if = {
				limit = {
					scope:recipient = {
						is_landed = 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
			}
			custom_description = {
				text = "release_banish_invalid_retire"
				object = scope:recipient
				scope:retire = no
			}
			scope:recruit = no #Should be impossible to have both but just in case
			NOT = {
				scope:recipient = {
					is_spouse_of = scope:actor	
				}
			}
			#scope:recipient = {
			#	trigger_if = {
			#		limit = { exists = liege }
			#		liege = scope:actor
			#	}
			#	is_pool_character = no
			#}
		}
	}
	
	send_option = {
		flag = retire
		localization = "RELEASE_RETIRE"
		is_shown = {
			scope:recipient = {
				OR = {
					has_government = patrician_government
					has_government = military_command
				}	
				is_ruler = yes
				is_vassal_or_below_of = scope:actor				
			}	
		}
		is_valid = {
			scope:recipient = {
				can_retire_military_command_trigger = yes
			}
			custom_description = {
				text = "release_retire_invalid_take_vows"
				object = scope:recipient
				scope:take_vows = no
			}
			custom_description = {
				text = "release_banish_invalid_retire"
				object = scope:recipient
				scope:banish = no
			}
		}
	}
	
	send_option = {
		flag = gain_hook
		localization = "RELEASE_GAIN_HOOK"
		is_valid = {
			trigger_if = {
				limit = {
					scope:actor = { is_ai = yes }
				}
				scope:recipient = {
					OR = {
						is_vassal_of = scope:actor
						AND = {
							exists = liege
							liege = scope:actor
						}
					}
				}
			}
			scope:actor = {
				can_add_hook = {
					type = favor_hook #Matches the hook added in the on_accept
					target = scope:recipient
				}
			}
		}
	}
	
	
	send_option = {
		flag = take_vows
		localization = "RELEASE_TAKE_VOWS"
		is_shown = {
			scope:actor.faith = {
				has_doctrine_parameter = take_vows_active
			}
		}
		is_valid = {
			trigger_if = {
				limit = {
					scope:actor = { is_ai = yes }
				}
				scope:recipient = {
					is_close_or_extended_family_of = scope:actor
					NOT = {
						is_heir_of = scope:actor
					}
				}
				scope:actor = {
					opinion = {
						target = scope:recipient
						value <= medium_negative_opinion
					}
				}
			}
			scope:recipient = {
				is_courtier_of = scope:actor
			}
			custom_description = {
				text = "release_vows_invalid_not_your_faith"
				object = scope:recipient
				subject = scope:actor
				trigger_if = {
					limit = {
						NOT = { scope:recipient.faith = scope:actor.faith }
					}
					scope:demand_conversion = yes
				}
			}
			custom_description = {
				text = "release_banish_invalid_take_vows"
				object = scope:recipient
				scope:banish = no
			}
			custom_description = {
				text = "release_banish_invalid_retire"
				object = scope:recipient
				scope:retire = no
			}
			scope:recipient = {
				is_married = no
				NOR = {
					has_trait = excommunicated
					has_trait = devoted
				}
			}
		}
	}
	
	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_adult = yes
				is_ruler = no
				NOT = { is_courtier_of = scope:actor }
			}
		}
	}
	
	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:retire = no
	}
	
	ai_accept = {
		base = 0
		modifier = {
			add = 100
			desc = "WANTS_FREEDOM_REASON"
		}
		modifier = {
			trigger = {
				scope:recipient = { ai_zeal <= 20 }
				scope:demand_conversion = yes
			}
			add = -20
			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"
		}
		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 = -75
			trigger = {
				scope:renounce_claims = yes
				ai_greed >= 26
				ai_greed < 51
			}
			desc = "RENOUNCE_CLAIMS_REASON"
		}
		modifier = {
			add = -95
			trigger = {
				scope:renounce_claims = yes
				ai_greed >= 51
			}
			desc = "RENOUNCE_CLAIMS_REASON"
		}
		modifier = {
			add = -50
			trigger = {
				scope:banish = yes
			}
			desc = "BANISH_NEGATIVE_REASON"
		}
		modifier = {
			add = {
				value = -120
				add = {
					value = scope:recipient.ai_greed
					multiply = -0.3
					min = -30
					max = 30
				}
				add = {
					value = scope:recipient.ai_energy
					multiply = -0.3
					min = -30
					max = 30
				}
				if = {
					limit = { scope:recipient = { stress >= medium_stress } }
					add = 15
				}
				if = {
					limit = { age >= 60 }
					add = 15
				}
				if = {
					limit = { has_trait = depressed }
					add = 15
				}
				if = {
					limit = { has_trait = incapable }
					add = 25
				}
				if = {
					limit = { has_slow_disease_type_trigger = yes }
					add = 10
				}
				if = {
					limit = { 
						OR = {
							has_trait = maimed
							has_trait = infirm
							has_trait = blind
						}
					}
					add = 10
				}
			}	
			trigger = {
				scope:retire = yes
			}
			desc = "RETIRE_NEGATIVE_REASON"
		}
		modifier = {
			add = {
				value = -50
				if = {
					limit = {
						scope:recipient = {
							ai_vengefulness > 0
						}
					}
					subtract = ai_vengefulness
				}
			}
			trigger = {
				scope:gain_hook = yes
			}
			desc = "GAIN_HOOK_NEGATIVE_REASON"
		}
		modifier = {
			add = -30
			trigger = {
				scope:take_vows = yes
			}
			desc = "TAKE_VOWS_NEGATIVE_REASON"
		}
		modifier = {
			add = -10
			trigger = {
				scope:recruit = yes
			}
			desc = "RECRUITMET_NEGATIVE_REASON"
		}
	}
	
	# AI
	ai_targets = {
		ai_recipients = prisoners
	}
	ai_frequency = 1

	ai_potential = {
		always = 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:retire = yes
			scope:recipient = {
				is_vassal_of = scope:actor
				opinion = { target = scope:actor value < -30 }
				reverse_opinion = { target = scope:actor value < 50 }
			}
		}
		modifier = {
			add = 50
			scope:banish = yes
		}
		modifier = {
			add = 30
			scope:take_vows = yes
		}
		modifier = {
			add = 10
			scope:recruit = yes
		}
		modifier = { # Rivals can rot
			add = -40
			scope:actor = {
				NOT = {
					has_trait = forgiving
				}
			}
			scope:recipient = {
				OR = {
					has_relation_rival = scope:actor
					has_relation_nemesis = scope:actor
					scope:recipient = {
						is_spouse_of = scope:actor
						exposed_cheating_on_spouse_trigger = { SPOUSE = scope:actor }
					}
				}
			}
		}
		modifier = { # Rivals can rot FOREVER if vengeful
			add = -100
			scope:actor = {
				NOT = {
					has_trait = forgiving
				}
			}
			scope:actor.ai_vengefulness >= very_high_positive_ai_value
			scope:recipient = {
				OR = {
					has_relation_rival = scope:actor
					has_relation_nemesis = scope:actor
					scope:recipient = {
						is_spouse_of = scope:actor
						exposed_cheating_on_spouse_trigger = { SPOUSE = scope:actor }
					}
				}
			}
		}
		modifier = { # Compassionate characters don't want to keep children in their dungeon for too long
			add = 10
			scope:actor = {
				is_at_war = no
				ai_compassion >= low_positive_ai_value
			}
			scope:recipient = {
				is_adult = no
				time_in_prison = { years > 1 }
			}
		}
		modifier = { # Very compassionate characters tend to release prisoners
			add = 10
			scope:actor = {
				is_at_war = no
				ai_compassion >= very_high_positive_ai_value
			}
			scope:recipient = {
				time_in_prison = { years > 1 }
			}
		}
		modifier = { # Somewhat compassionate characters tend to keep people in their dungeon for a while
			add = 10
			scope:actor = {
				is_at_war = no
				ai_compassion >= medium_positive_ai_value
			}
			scope:recipient = {
				is_landed = no
				time_in_prison = { years > 3 }
			}
		}
		modifier = { # Only truly discompassionate characters will have their dungeon full of hapless victims after 5 years
			add = 10
			scope:actor = {
				is_at_war = no
				ai_compassion >= low_negative_ai_value
			}
			scope:recipient = {
				is_landed = no
				time_in_prison = { years > 5 }
			}
		}
		modifier = { # Most AI characters will let family out...
			add = 10
			scope:actor = {
				is_at_war = no
				OR = {
					ai_compassion >= very_high_positive_ai_value
					AND = {
						ai_compassion >= high_negative_ai_value
						opinion = {
							target = scope:recipient
							value >= low_negative_opinion
						}
					}
				}
			}
			scope:recipient = {
				time_in_prison = { years > 1 }
				is_landed = no
				is_close_family_of = scope:actor
			}
		}
		modifier = { # Almost all will let their own children out
			add = 40
			scope:actor = {
				is_at_war = no
				ai_compassion >= very_high_negative_ai_value
			}
			scope:recipient = {
				is_landed = no
				is_child_of = scope:actor
			}
		}
	}
}

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

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

	is_valid_showing_failures_only = {
		scope:recipient = { is_diplomatically_available = yes } #Prisoner
		scope:recipient = { NOT = { has_strong_hook = scope:actor } }
		scope:recipient = {
			custom_description = {
				text = "currently_being_tortured"
				NOT = { has_character_flag = is_being_tortured }
			}
		}
	}
	
	on_accept = {
		if = {
			limit = { scope:recipient = { is_imprisoned_by = scope:actor } }
			if = {
				limit = {
					scope:recipient = { is_ai = no }
					scope:actor = { is_ai = yes }
				}
				scope:recipient = { trigger_event = char_interaction.0170 } # Give players a chance to see what's about to happen
				show_as_tooltip = {
					execute_prisoner_effect = {
						VICTIM = scope:recipient
						EXECUTIONER = scope:actor
					}
				}
			}
			else = {
				scope:recipient = { trigger_event = char_interaction.0171 }
				execute_prisoner_effect = {
					VICTIM = scope:recipient
					EXECUTIONER = scope:actor
				}
			}

			if = {
				limit = { always = scope:execution_devour }
				scope:actor = {
					stress_impact = {
						base = medium_stress_impact_loss
						compassionate = minor_stress_impact_gain
						forgiving = minor_stress_impact_gain
					}
					random = {
						chance = 20
						show_as_tooltip = { add_trait = ill }
						hidden_effect = {
							trigger_event = {
								id = health.1001
								days = { 3 10 }
							}
						}
					}
				}
			}
			else = {
				if = {
					limit = {
						scope:actor = {
							has_execute_reason = scope:recipient
						}
					}
					scope:actor = {			
						stress_impact = {
							compassionate = medium_stress_impact_gain
							forgiving = minor_stress_impact_gain
						}
					}
				}
				else = {
					scope:actor = {			
						stress_impact = {
							compassionate = medium_stress_impact_gain
							just = medium_stress_impact_gain
						}
					}
				}
			}

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

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

	options_heading = execution_options_heading

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

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

	send_option = {
		is_shown = {
			NOT = {
				scope:actor.faith = scope:recipient.faith
			}
		}
		flag = execution_burned
		localization = "EXECUTION_BURNED"
	}
	
	
	
	send_options_exclusive = yes
	auto_accept = yes
}

debug_imprison_simple_interaction = {
	use_diplomatic_range = no
	category = interaction_debug_main
	common_interaction = yes
	ignores_pending_interaction_block = yes

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

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

	auto_accept = yes
}

torture_interaction = {
	interface_priority = 30
	common_interaction = yes

	category = interaction_category_prison

	desc = torture_interaction_desc

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

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

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

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

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

		###EVENTS###
		hidden_effect = {
			#Torture method for descs
			random_list = {
				3 = { save_scope_value_as = { name = torture_method value = flag:rack } }
				3 = { save_scope_value_as = { name = torture_method value = flag:whip } }
				1 = { save_scope_value_as = { name = torture_method value = flag:rats } }
			}

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

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

	auto_accept = yes

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

	ai_will_do = {
		base = -25

		modifier = {
			has_trait = sadistic
			add = 30
		}
		ai_value_modifier = {
			ai_compassion = tiny_chance_impact_negative_ai_value #Adds +50 for highly uncompassionate characters, -50 for highly compassionate characters
		}
		opinion_modifier = {
			opinion_target = scope:recipient
			multiplier = -0.25
		}
	}	
}

castrate_interaction = {
	interface_priority = 30

	category = interaction_category_prison

	desc = castrate_interaction_desc

	is_shown = {
		scope:recipient = {
			is_imprisoned_by = scope:actor
			NOT = { has_trait = eunuch }
			is_male = yes
		}
		scope:actor = {
			is_adult = yes
			OR = {
				has_culture_group = culture_group:byzantine_group
				has_culture = culture:ethiopian
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:recipient = {
			custom_description = {
				text = "currently_being_tortured"
				NOT = { has_character_flag = is_being_tortured }
			}
		}
	}

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

		blind_and_castrate_actor_effect = yes #Stress & dread

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

		torture_blind_castrate_opinion_effect = { VERB = castrated }

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

	auto_accept = yes

	ai_targets = {
		ai_recipients = prisoners
	}

	ai_potential = {
		always = yes
	}

	ai_will_do = {
		base = -20

		modifier = {
			has_trait = sadistic
			add = 20
		}
		modifier = {
			add = 20
			faith = { has_doctrine = tenet_exaltation_of_pain }
			NOT = { has_trait = cynical }
		}
		
		#Opinion
		modifier = {
			add = -100
			opinion = { target = scope:recipient value >= 25 }
			NOT = { has_trait = lunatic }
		}
		opinion_modifier = {
			opinion_target = scope:recipient
			multiplier = -0.25
		}
		
		#Compassion
		ai_value_modifier = {
			ai_compassion = tiny_chance_impact_negative_ai_value #Adds +50 for highly uncompassionate characters, -50 for highly compassionate characters
		}

		#Trying to inspire fear
		modifier = { 
			add = 20
			OR = {
				ai_vengefulness >= high_positive_ai_value
				ai_boldness >= high_positive_ai_value
				has_focus = martial_authority_focus
			}
		}
		modifier = {
			add = -20
			OR =  {
				has_relation_lover = scope:recipient
				is_consort_of = scope:recipient
				is_spouse_of = scope:recipient
			}	
		}			
		modifier = { #enemy has my close relative
			add = -30
			any_primary_war_enemy = {
				dynasty = scope:recipient.dynasty
				is_close_family_of = scope:recipient
				any_prisoner = {
					is_close_family_of = scope:actor
					dynasty = scope:actor.dynasty
				}
			}
		}
		modifier = { #can win the war
			add = -1000
			any_primary_war_enemy = {
				this = scope:recipient
			}
		}
		modifier = { #can get a ransom
			add = {
				value = -10
				if = {
					limit = { ai_greed >= high_positive_ai_value }
					multiply = 2.5
				}
			}				
			#has_game_rule = { name = punishment_release_prisoner value = on }
			scope:recipient = {
				OR = {
					highest_held_title_tier >= tier_barony
					any_parent = { highest_held_title_tier >= tier_county }
				}
				NAND = { 
					is_ruler = no
					liege = { this = scope:actor }
				}	
			}	
			NOT = { has_trait = sadistic }
			NOT = { has_trait = lunatic }
			NAND = { #already rich anyway
				scope:recipient = { highest_held_title_tier < tier_kingdom }
				gold >= 400
			}
		}
		#has a claim on my title
		modifier = { 
			add = 25
			scope:recipient = {
				OR = {
					any_claim = { holder = { this = scope:actor } }
					any_parent = { any_claim = { holder = { this = scope:actor } } }
				}	
				NOT = { is_child_of = scope:actor }
				NOT = { is_grandchild_of = scope:actor }
			}	
		}
		modifier = { #a good way to remove enemies without gaining kinslayer
			add = 20
			OR = {
				AND = {
					scope:actor.dynasty = scope:recipient.dynasty
					faith = { has_doctrine = doctrine_kinslaying_any_dynasty_member_crime }
				}
				AND = {
					is_close_or_extended_family_of = scope:recipient
					faith = { has_doctrine = doctrine_kinslaying_extended_family_crime }
				}
				AND = {
					is_close_family_of = scope:recipient
					faith = { has_doctrine = doctrine_kinslaying_close_kin_crime }
				}
			}
			scope:recipient = {
				OR = {
					any_claim = { holder = { this = scope:actor } }
					any_parent = { any_claim = { holder = { this = scope:actor } } }
				}	
				NOT = { is_child_of = scope:actor }
				NOT = { is_grandchild_of = scope:actor }
			}	
		}
		modifier = {
			add = 25
			scope:recipient = {
				any_pretender_title = {
					current_heir = { this = scope:actor }
				}	
			}		
		}
		modifier = { #would prefer an execution
			add = -20
			has_execute_reason = scope:recipient
		}
	}

	ai_frequency = 36
}

blind_interaction = {
	interface_priority = 30

	category = interaction_category_prison

	desc = blind_interaction_desc

	is_shown = {
		scope:recipient = {
			is_imprisoned_by = scope:actor
			NOT = { has_trait = blind }
		}
		scope:actor = {
			is_adult = yes
			has_culture_group = culture_group:byzantine_group
		}
	}

	is_valid_showing_failures_only = {
		scope:recipient = {
			custom_description = {
				text = "currently_being_tortured"
				NOT = { has_character_flag = is_being_tortured }
			}
		}
	}

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

		blind_and_castrate_actor_effect = yes #Stress & dread

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

		torture_blind_castrate_opinion_effect = { VERB = blinded }

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

	auto_accept = yes

	ai_targets = {
		ai_recipients = prisoners
	}

	ai_potential = {
		always = yes
	}

	ai_will_do = {
		base = -20

		modifier = {
			has_trait = sadistic
			add = 20
		}
		modifier = {
			add = 20
			faith = { has_doctrine = tenet_exaltation_of_pain }
			NOT = { has_trait = cynical }
		}
		
		#Opinion
		modifier = {
			add = -100
			opinion = { target = scope:recipient value >= 25 }
			NOT = { has_trait = lunatic }
		}
		opinion_modifier = {
			opinion_target = scope:recipient
			multiplier = -0.25
		}
		
		#Compassion
		ai_value_modifier = {
			ai_compassion = tiny_chance_impact_negative_ai_value #Adds +50 for highly uncompassionate characters, -50 for highly compassionate characters
		}

		#Trying to inspire fear
		modifier = { 
			add = 20
			OR = {
				ai_vengefulness >= high_positive_ai_value
				ai_boldness >= high_positive_ai_value
				has_focus = martial_authority_focus
			}
		}
		modifier = {
			add = -20
			OR = {
				has_relation_lover = scope:recipient
				is_consort_of = scope:recipient
				is_spouse_of = scope:recipient
			}	
		}			
		modifier = { #enemy has my close relative
			add = -30
			any_primary_war_enemy = {
				dynasty = scope:recipient.dynasty
				is_close_family_of = scope:recipient
				any_prisoner = {
					is_close_family_of = scope:actor
					dynasty = scope:actor.dynasty
				}
			}
		}
		modifier = { #can win the war
			add = -1000
			any_primary_war_enemy = {
				this = scope:recipient
			}
		}
		modifier = { #can get a ransom
			add = {
				value = -10
				if = {
					limit = { ai_greed >= high_positive_ai_value }
					multiply = 2.5
				}
			}				
			#has_game_rule = { name = punishment_release_prisoner value = on }
			scope:recipient = {
				OR = {
					highest_held_title_tier >= tier_barony
					any_parent = { highest_held_title_tier >= tier_county }
				}
				NAND = { 
					is_ruler = no
					liege = { this = scope:actor }
				}	
			}	
			NOT = { has_trait = sadistic }
			NOT = { has_trait = lunatic }
			NAND = { #already rich anyway
				scope:recipient = { highest_held_title_tier < tier_kingdom }
				gold >= 400
			}
		}
		#has a claim on my title
		modifier = { 
			add = 25
			scope:recipient = {
				OR = {
					any_claim = { holder = { this = scope:actor } }
					any_parent = { any_claim = { holder = { this = scope:actor } } }
				}	
				NOT = { is_child_of = scope:actor }
				NOT = { is_grandchild_of = scope:actor }
			}	
		}
		modifier = { #a good way to remove enemies without gaining kinslayer
			add = 20
			OR = {
				AND = {
					scope:actor.dynasty = scope:recipient.dynasty
					faith = { has_doctrine = doctrine_kinslaying_any_dynasty_member_crime }
				}
				AND = {
					is_close_or_extended_family_of = scope:recipient
					faith = { has_doctrine = doctrine_kinslaying_extended_family_crime }
				}
				AND = {
					is_close_family_of = scope:recipient
					faith = { has_doctrine = doctrine_kinslaying_close_kin_crime }
				}
			}
			scope:recipient = {
				OR = {
					any_claim = { holder = { this = scope:actor } }
					any_parent = { any_claim = { holder = { this = scope:actor } } }
				}
				NOT = { is_child_of = scope:actor }
				NOT = { is_grandchild_of = scope:actor }
			}	
		}
		modifier = {
			add = 25
			scope:recipient = {
				any_pretender_title = {
					current_heir = { this = scope:actor }
				}	
			}		
		}
		modifier = { #would prefer an execution
			add = -20
			has_execute_reason = scope:recipient
		}
	}

	ai_frequency = 36
}