﻿abduct = {
	# Basic Setup
	skill = intrigue
	desc = "abduct_desc_general"
	success_desc = "ABDUCT_SUCCESS_DESC"
	discovery_desc = "ABDUCT_DISCOVERY_DESC"
	icon = icon_scheme_abduct
	illustration = "gfx/interface/illustrations/event_scenes/corridor.dds"
	category = hostile
	target_type = character
	is_secret = yes
	maximum_breaches = 5
	cooldown = { years = 10 }

	# Parameters
	speed_per_skill_point = t2_spsp_owner_value
	speed_per_target_skill_point = t2_spsp_target_value
	base_progress_goal = t2_base_phase_length_value
	maximum_secrecy = 85
	base_maximum_success = t2_base_max_success_value
	phases_per_agent_charge = 1
	success_chance_growth_per_skill_point = t2_scgpsp_value

	# Core Triggers
	allow = {
		OR = {
			has_perk = kidnapper_perk # Scheme unlocked by the Kidnapper Perk
			domicile ?= { has_domicile_parameter = camp_unlocks_abduct_scheme }
			AND = {
				any_character_struggle = {
					involvement = involved
					has_struggle_phase_parameter = unlocks_abduct_for_all
					is_secondary_character_involvement_involved_trigger = {
						CHAR = scope:target
					}
				}
			}
		}

		is_adult = yes
		is_playable_character = yes
		is_imprisoned = no
	}
	valid = {
		is_playable_character = yes
		is_ruler = yes
		is_incapable = no
		custom_description = { #If they're your kid you need special traits to do it
			text = abduct_own_children_block
			object = scope:target

			trigger_if = {
				limit = {
					is_parent_of = scope:target
				}
				has_trait_with_flag = can_murder_own_children
			}
		}
		scope:target = {
			is_imprisoned = no
			is_hostage = no
			exists = location
			in_diplomatic_range = scope:owner
		}
		# Special AI exceptions
		NOT = {
			scope:owner = {
				is_ai = yes
				has_opinion_modifier = {
					target = scope:target
					modifier = repentant_opinion
				}
			}
		}
		trigger_if = {
			limit = { has_variable = no_scheming_allowed_var }
			custom_tooltip = {
				text = no_scheming_allowed_var_tt
				var:no_scheming_allowed_var != scope:target
			}
		}
	}

	# Agents
	agent_leave_threshold = -25
	agent_join_chance = {
		base = 0

		ai_agent_join_chance_basic_suite_modifier = yes
		ai_agent_join_chance_hostile_grievous_modifier = yes
	}
	agent_groups_owner_perspective = { courtiers guests scripted_relations }
	agent_groups_target_character_perspective = { courtiers vassals }
	valid_agent = { is_valid_agent_standard_trigger = yes }

	odds_prediction = {
		add = hostile_scheme_base_odds_prediction_target_is_char_value
		add = odds_skill_contribution_intrigue_value
		add = agent_groups_owner_perspective_value
		add = agent_groups_target_character_perspective_value
		add = odds_abduct_scheme_misc_value 
		min = 0
	}
	
	# Base Chances
	base_success_chance = {
		base = 0
		scheme_type_skill_success_chance_modifier = { SKILL = INTRIGUE }

		hostile_scheme_base_chance_modifier = yes

		# Countermeasures.
		apply_calculated_scheme_success_chance_adjustments_modifier = yes

		# You found their escape tunnel
		modifier = {
			add = 100
			desc = "SCHEME_DISCOVERED_ESCAPE_TUNNEL"
			scope:owner = {
				exists = var:discovered_escape_tunnel_of
				var:discovered_escape_tunnel_of = scope:target
			}
		}
		
		# Spiritual Head of Faith
		modifier = {
			add = -50
			desc = "SCHEME_VS_SPIRITUAL_HOF"
			scope:target = {
				faith = scope:owner.faith
				faith = {
					has_doctrine = doctrine_spiritual_head
				}
				faith = {
					religious_head ?= {
			 			this = scope:target
			 		}
				}
			}
		}

		# Sponsored Inspiration
		modifier = {
			add = -25
			desc = target_has_sponsored_inspiration
			scope:target = {
				inspiration ?= { exists = inspiration_sponsor }
			}
		}

		# Family Feud
		house_feud_hostile_scheme_success_modifier = yes

		# Various penalties
		first_valid = {
			modifier = { # Foreign Rulers are very hard to kidnap
				add = -75
				desc = "sway_foreign_target"
				scope:target = {
					is_ruler = yes
					scope:target.top_liege != scope:owner.top_liege
				}
			}
			modifier = { # Foreign subjects less so
				add = -40
				desc = "sway_foreign_target"
				scope:target = {
					exists = liege_or_court_owner #Unop: Do not protect wandering characters
					is_foreign_court_or_pool_guest = no
					scope:target.top_liege != scope:owner.top_liege
				}
			}
			modifier = { # Rulers are harder to kidnap
				add = -50
				desc = "FABRICATE_HOOK_RULER_TARGET"
				scope:target = {
					is_ruler = yes
					scope:target.top_liege = scope:owner.top_liege
				}
			}
		}

		# At War
		first_valid = {
			modifier = {
				add = -500
				desc = "SCHEME_AT_WAR"
				scope:target = {
					is_at_war_with = scope:owner
				}
			}
			modifier = {
				add = -350
				scope:target = {
					is_playable_character = no
					this != top_liege
					any_liege_or_above = {
						is_at_war_with = scope:owner
					}
				}
				desc = "SCHEME_AT_WAR_WITH_LIEGE"
			}
			modifier = {
				add = -250
				scope:target = {
					is_playable_character = yes
					this != top_liege
					any_liege_or_above = {
						is_at_war_with = scope:owner
					}
				}
				desc = "SCHEME_AT_WAR_WITH_LIEGE"
			}
		}

		# Diarchs are better at schemes within their liege's realm
		diarch_scheming_within_realm_bonus_modifier = yes
		
		# You have a secret tunnel yourself
		modifier = {
			add = 25
			desc = "SCHEME_SECRET_DOMICILE_TUNNEL"
			scope:owner = {
				exists = var:ep3_secret_tunnels_var
			}
		}

		# Tailor
		modifier = {
			add = 10
			scope:owner = {
				has_character_modifier = tournament_tailor_mixup_scheme_modifier
				exists = var:tailor_mixup_house
				exists = scope:target.house
				var:tailor_mixup_house = scope:target.house
			}
			desc = "tournament_tailor_mixup_scheme_modifier_value"
		}
	}
	base_secrecy = {
		add = secrecy_base_value
		add = countermeasure_apply_secrecy_maluses_value
	}

	# On Actions
	on_start = {
		set_variable = {
			name = apply_countermeasures
			value = flag:calculating
		}
		add_scheme_starting_opportunities_intrigue_effect = yes
		# Fallback agents — a balanced config if you start the scheme from script.
		if = {
			limit = {
				scheme_owner = {
					NOT = { has_variable = agents_added }
				}
			}
			add_agent_slot = agent_thug
			add_agent_slot = agent_thug
			add_agent_slot = agent_muscle
			add_agent_slot = agent_footpad
			add_agent_slot = agent_lookout
		}
	}
	on_phase_completed = {
		suppress_scheme_follow_up_event_till_input_given_effect = yes
		abduct_scheme_prep_effect = yes
		cap_schemes_and_fire_reminders_effect = yes
	}
	on_hud_click  = { abduct_scheme_prep_effect = yes }
	on_semiyearly = {
		if = {
			limit = {
				scheme_owner = { is_ai = yes }
			}
			abduct_scheme_prep_effect = yes
			purge_ai_scheme_slots_effect = yes
		}
	}
	on_monthly = {
		hostile_scheme_monthly_discovery_chance_effect = yes

		if = {
			limit = {
				NOT = { exists = scope:discovery_event_happening }
			}
			scheme_owner = {
				trigger_event = {
					on_action = abduct_ongoing
					days = { 1 30 }
				}
			}
		}
	}
	on_invalidated = {
		scheme_target_character = {
			save_scope_as = target
		}
		scheme_owner = {
			save_scope_as = owner
		}
		if = {
			limit = {
				scope:target = { is_alive = no }
			}
			scope:owner = {
				send_interface_toast = {
					title = abduct_scheme_invalidated_title
					left_icon = scope:target
					custom_description_no_bullet = {
						object = scope:target
						text = scheme_target_died
					}
				}
			}
		}
		else_if = {
			limit = {
				scope:target = {
					is_imprisoned = yes
					imprisoner = scope:owner
				}
				scope:owner = {
					NOT = { has_character_flag = is_in_event_abduct_outcome_0001 } #You probably abducted them
				}
			}
			scope:owner = {
				send_interface_message = {
					title = abduct_scheme_invalidated_title
					type = abduct_invalidated_i_imprisoned_message
					desc = abduct_scheme_i_imprisoned_them_message
					left_icon = scope:target
				}
			}
		}
		else_if = {
			limit = {
				scope:target = {
					is_imprisoned = yes
					imprisoner != scope:owner
				}
			}
			scope:target.imprisoner = {
				save_scope_as = other_imprisoner
			}
			scope:owner = {
				send_interface_toast = {
					title = abduct_scheme_invalidated_title
					left_icon = scope:target
					right_icon = scope:other_imprisoner
					custom_description_no_bullet = {
						subject = scope:other_imprisoner
						object = scope:target
						text = scheme_target_imprisoned_by_other
					}
				}
			}
		}
		else_if = {
			limit = {
				scope:target = {
					NOT = { in_diplomatic_range = scope:owner }
				}
			}
			scope:owner = {
				send_interface_toast = {
					title = abduct_scheme_invalidated_title
					left_icon = scope:target
					custom_description_no_bullet = {
						object = scope:target
						text = scheme_target_not_in_diplomatic_range
					}
				}
			}
		}
	}
}
