﻿
start_abduct = {
	icon = icon_scheme_abduct
	interface_priority = 70
	category = interaction_category_hostile

	send_name = START_SCHEME

	scheme = abduct
	ignores_pending_interaction_block = yes

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

		NOR = {
			scope:recipient = scope:actor
			scope:recipient = { is_imprisoned_by = scope:actor }
		}
		#exists = scope:recipient.court_owner

		NAND = { # Game Rules!
			has_game_rule = no_players_multiplayer_murder_schemes
			scope:actor = {
				is_ai = no
			}
			scope:recipient = {
				is_ai = no
			}
		}

		NAND = {
			has_game_rule = no_player_families_multiplayer_murder_schemes
			scope:actor = {
				is_ai = no
			}
			scope:recipient = {
				OR = {
					is_ai = no
					any_close_family_member = {
						AND = {
							is_ai = no
							this != scope:actor
						}
					}
				}
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			can_start_scheme = {
				type = abduct
				target_character = scope:recipient
			}
		}
		scope:recipient = { NOT = { has_strong_hook = scope:actor } }
		#limit range for landless adventurers
		trigger_if = {
			limit = {
				scope:actor = {
					has_government = landless_adventurer_government
				}
			}
			#Has to be used instead of diplo range checks in laamp to landed interactions
			ep3_laamp_diplo_range_trigger = {
				TARGET = scope:recipient
				LAAMP = scope:actor
			}
		}
		trigger_if = {
			limit = { scope:actor = { has_variable = no_scheming_allowed_var } }
			custom_tooltip = {
				text = no_scheming_allowed_var_tt
				scope:actor.var:no_scheming_allowed_var != scope:recipient
			}
		}
	}

	desc = {
		triggered_desc = {
			trigger = {
				scope:actor = {
					can_start_scheme = {
						type = abduct
						target_character = scope:recipient
					}
				}
			}
			desc = scheme_interaction_tt_abduct_approved
		}
	}

	# Scheme Starter Packages
	options_heading = schemes.t.agent_packages
	send_options_exclusive = yes
	## Balanced agents.
	send_option = {
		flag = agent_focus_balance
		current_description = start_abduct.tt.agent_focus_balance
	}
	## Focused on Success Chance.
	send_option = {
		flag = agent_focus_success
		current_description = start_abduct.tt.agent_focus_success
	}
	## Focused on Speed.
	send_option = {
		flag = agent_focus_speed
		current_description = start_abduct.tt.agent_focus_speed
	}
	## Focused on Secrecy.
	send_option = {
		flag = agent_focus_secrecy
		current_description = start_abduct.tt.agent_focus_secrecy
	}

	on_accept = {
		scope:actor = {
			stress_impact = {
				compassionate = medium_stress_impact_gain
				honest = minor_stress_impact_gain
				just = minor_stress_impact_gain
			}
		}
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = start_abduct_notification

				left_icon = scope:actor
				right_icon = scope:recipient

				# Success.
				if = {
					limit = { scope:agent_focus_success ?= yes }
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = abduct
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
						# Success.
						AGENT_1 = agent_thug
						AGENT_2 = agent_thug
						AGENT_3 = agent_muscle
						# Speed.
						AGENT_4 = agent_footpad
						# Secrecy.
						AGENT_5 = agent_lookout
					}
				}
				# Speed.
				else_if = {
					limit = { scope:agent_focus_speed ?= yes }
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = abduct
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
						# Speed.
						AGENT_1 = agent_footpad
						AGENT_2 = agent_footpad
						AGENT_3 = agent_infiltrator
						# Success.
						AGENT_4 = agent_thug
						# Secrecy.
						AGENT_5 = agent_lookout
					}
				}
				# Secrecy.
				else_if = {
					limit = { scope:agent_focus_secrecy ?= yes }
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = abduct
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
						# Secrecy.
						AGENT_1 = agent_lookout
						AGENT_2 = agent_lookout
						AGENT_3 = agent_decoy
						# Success.
						AGENT_4 = agent_thug
						# Speed.
						AGENT_5 = agent_footpad
					}
				}
				# Balanced.
				else = {
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = abduct
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
						# Success.
						AGENT_1 = agent_thug
						AGENT_2 = agent_muscle
						# Speed.
						AGENT_3 = agent_footpad
						AGENT_4 = agent_infiltrator
						# Secrecy.
						AGENT_5 = agent_lookout
					}
				}
			}
		}
	}

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

	ai_potential = {
		liege ?= { has_diarchy_active_parameter = diarchy_is_co_rulership }
		is_diarch = yes
		is_ruler = yes
		ai_diarch_would_maim_execute_superior_if_got_chance_trigger = { LIEGE = liege }
	}

	ai_will_do = {
		# They shouldn't always do this.
		base = -100

		# Obvious factor.
		opinion_modifier = {
			opinion_target = scope:recipient
			multiplier = -1
		}
		ai_value_modifier = { ai_honor = -1 }
		# Traits.
		## Disloyal.
		modifier = {
			add = 100
			has_trait = disloyal
		}
		## Ambitious.
		modifier = {
			add = 75
			has_trait = ambitious
		}
		## Arrogant.
		modifier = {
			add = 25
			has_trait = arrogant
		}
		## Fickle.
		modifier = {
			add = 25
			has_trait = fickle
		}
		## Callous.
		modifier = {
			add = 25
			has_trait = callous
		}
		## Compassionate.
		modifier = {
			add = -50
			has_trait = compassionate
		}
		## Humble.
		modifier = {
			add = -50
			has_trait = humble
		}
		## Content.
		modifier = {
			add = -100
			has_trait = content
		}
		## Loyal.
		modifier = {
			add = -300
			has_trait = loyal
		}
		# Time as a diarch — the longer they've been waiting, the more eager they are.
		modifier = {
			add = {
				value = years_as_diarch
				multiply = 2
			}
			always = yes
		}

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

	auto_accept = yes
}

befriend_interaction = {
	icon = icon_scheme_befriend
	category = interaction_category_friendly

	interface_priority = 90
	scheme = befriend

	send_name = START_SCHEME
	ignores_pending_interaction_block = yes

	ai_targets = {
		ai_recipients = liege
		ai_recipients = neighboring_rulers
	}
	ai_targets = {
		ai_recipients = vassals
		ai_recipients = peer_vassals
		chance = 0.25
	}

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

	is_shown = {
		scope:actor = {
			can_use_befriend_scheme_trigger = { TARGET = scope:recipient }
		}
		scope:actor != scope:recipient
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			can_start_scheme = {
				type = befriend
				target_character = scope:recipient
			}
		}
		#limit range for landless adventurers
		trigger_if = {
			limit = {
				scope:actor = {
					has_government = landless_adventurer_government
				}
			}
			#Has to be used instead of diplo range checks in laamp to landed interactions
			ep3_laamp_diplo_range_trigger = {
				TARGET = scope:recipient
				LAAMP = scope:actor
			}
		}
	}

	cost = {
		prestige = {
			value = 0
			if = {
				limit = {
					scope:actor = {
						government_has_flag = government_is_nomadic
						NOR = {
							has_perk = befriend_perk
							AND = {
								exists = dynasty
								dynasty = {
									has_dynasty_perk = fp1_adventure_legacy_5
								}
								target_is_vassal_or_below = scope:recipient
							}
							culture = { has_cultural_parameter = automatic_befriend_access }
							any_character_struggle = {
								involvement = involved
								has_struggle_phase_parameter = struggle_unlocks_befriend_schemes_for_everyone
							}
							AND = {
								government_has_flag = government_is_clan
								is_in_same_clan_as_trigger = { CHARACTER = scope:recipient }
								house = { has_house_unity_stage = harmonious }
							}
						}
					}
				}
				add = scope:actor.minor_prestige_value
				if = {
					limit = {
						scope:recipient = {
							is_vassal_of = scope:actor
						}
					}
					add = scope:actor.miniscule_prestige_value
				}
				if = {
					limit = {
						scope:actor = {
							is_vassal_of = scope:recipient
						}
					}
					add = scope:actor.minor_prestige_value
				}
			}
		}
	}

	desc = {
		triggered_desc = {
			trigger = {
				scope:actor = {
					NOT = { is_at_war_with = scope:recipient }
					can_start_scheme = {
						type = befriend
						target_character = scope:recipient
					}
				}
			}
			desc = scheme_interaction_tt_befriend_approved
		}
	}

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

				left_icon = scope:actor
				right_icon = scope:recipient

				begin_scheme_basic_effect = {
					SCHEME_TYPE = befriend
					TARGET_TYPE = target_character
					TARGET_SCOPE = scope:recipient
				}
			}
		}
		if = { #Stubborness effect
			limit = {
				scope:recipient = {
					has_trait = stubborn
				}
			}
			scope:actor = {
				random_scheme = {
					type = befriend
					limit = {
						scheme_target_character = scope:recipient
					}
					scheme_target_character = {
						random_list = {
							20 = {
								set_variable = {
									name = recipient_stubborness_scheme
									value = -5
								}
							}
							20 = {
								set_variable = {
									name = recipient_stubborness_scheme
									value = -10
								}
							}
							20 = {
								set_variable = {
									name = recipient_stubborness_scheme
									value = -15
								}
							}
							20 = {
								set_variable = {
									name = recipient_stubborness_scheme
									value = -20
								}
							}
							20 = {
								set_variable = {
									name = recipient_stubborness_scheme
									value = -25
								}
							}
						}
					}
				}
			}
		}
	}

	ai_potential = {
		OR = {
			has_perk = befriend_perk # Unlocked by the Befriend Perk
			dynasty ?= {
				has_dynasty_perk = fp1_adventure_legacy_5
			}
			culture = { has_cultural_parameter = automatic_befriend_access }
			any_character_struggle = {
				involvement = involved
				has_struggle_phase_parameter = struggle_unlocks_befriend_schemes_for_everyone
			}
			house ?= { has_house_aspiration_parameter = aspect_of_serenity }
		}
		NOR = {
			has_trait = shy
			has_trait = callous
			any_scheme = {
				OR = {
					scheme_type = befriend
					#scheme_type = sway # We allow the AI to override Sway with Befriend
					scheme_type = seduce
					scheme_type = courting
					scheme_type = elope
					scheme_type = learn_language
					scheme_type = teach_governor
				}
			}
			AND = { # No one cares about City barons
				is_lowborn = yes
				primary_title.tier <= tier_barony
			}
		}
	}

	auto_accept = yes

	ai_will_do = {
		base = 50

		modifier = { # Try to befriend those who you might want to vassalize
			add = 30
			scope:actor = {
				top_liege = this
				primary_title.tier >= tier_county
				NOT = {
					any_targeting_faction = {
						exists = yes
						OR = {
							faction_is_type = liberty_faction
							faction_is_type = claimant_faction
							faction_is_type = independence_faction
						}
					}
				}
			}
			scope:recipient = {
				top_liege = this
				is_playable_character = yes
				primary_title.tier < scope:actor.primary_title.tier
				OR = {
					faith.religion = scope:actor.faith.religion
					AND = {
						faith = {
							has_doctrine = doctrine_pluralism_pluralistic
						}
						scope:actor.faith = {
							has_doctrine = doctrine_pluralism_pluralistic
						}
					}
				}
			}
		}

		modifier = {
			factor = 0.1
			scope:actor = {
				opinion = {
					target = scope:recipient
					value < -50
				}
			}
		}

		modifier = {
			factor = 0.1
			scope:recipient = {
				opinion = {
					target = scope:actor
					value > 50
				}
			}
		}

		modifier = {
			factor = 0.5
			scope:recipient = {
				number_of_personality_traits_in_common = {
					target = scope:actor
					value < 2
				}
			}
		}

		modifier = {
			factor = 0.1
			scope:recipient = {
				number_of_personality_traits_in_common = {
					target = scope:actor
					value < 1
				}
			}
		}

		# Struggle
		modifier = {
			scope:actor = {
				any_character_struggle = {
					involvement = involved
					is_struggle_type = iberian_struggle
					phase_has_catalyst = catalyst_became_friend_lover_with_character
				}
			}
			scope:recipient = {
				any_character_struggle = {
					involvement = involved
					is_struggle_type = iberian_struggle
					phase_has_catalyst = catalyst_became_friend_lover_with_character
				}
			}
			add = {
				value = 0
				if = {
					limit = {
						scope:actor = {
							has_character_flag = agenda_towards_deescalation
							trait_compatibility = {
								target = scope:recipient
								value >= low_positive_trait_compatibility
							}
						}
						scope:recipient = {
							has_character_flag = agenda_towards_deescalation
						}
					}
					add = 200
				}
				else_if = {
					limit = {
						scope:actor = {
							has_character_flag = agenda_towards_deescalation
							trait_compatibility = {
								target = scope:recipient
								value >= low_positive_trait_compatibility
							}
						}
					}
					add = 50
				}
				else_if = {
					limit = {
						scope:actor = {
							has_character_flag = agenda_towards_escalation
						}
					}
					add = -200
				}
				else = {
					add = 10
				}
			}
		}

		modifier = {
			factor = 25
			OR = {
				has_focus = diplomacy_family_focus
				house ?= { has_house_aspiration_parameter = aspect_of_serenity }
			}	
		}

		modifier = {
			factor = 2
			scope:recipient.liege = scope:actor
		}

		modifier = {
			factor = 0.5
			scope:recipient.faith != scope:actor.faith
		}

		modifier = {
			factor = 0.25
			scope:actor = {
				is_ruler = yes
				tier_difference = {
					target = scope:recipient
					value > 2
				}
			}
		}
		modifier = {
			factor = 0.35
			scope:actor = {
				has_personality_malicious_trigger = yes
			}
		}
		modifier = {
			factor = 2
			scope:actor = {
				OR = {
					has_trait = gregarious
					has_trait = diplomat
					has_trait = family_first
					has_trait = august
				}
			}
		}
		modifier = {
			factor = 1.5
			scope:actor = {
				num_of_relation_friend < 3
			}
		}
		modifier = { #Better to Court rather than befriend.
			factor = 0.25
			scope:actor = {
				is_spouse_of = scope:recipient
			}
		}
		modifier = {
			factor = 0.75
			scope:recipient = {
				is_child_of = scope:actor
			}
		}
		modifier = {
			factor = 2
			scope:actor = {
				is_child_of = scope:recipient
			}
		}
		modifier = {
			factor = 2
			scope:actor = { #Friends of friends
				any_relation = {
					type = friend
					any_relation = {
						type = friend
						this = scope:recipient
					}
				}
			}
		}
		modifier = {
			factor = 0.25
			scope:recipient = {
				any_claim = {
					this = scope:actor.primary_title
				}
			}
		}

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



sway_interaction = {
	icon = icon_scheme_sway
	category = interaction_category_friendly
	common_interaction = yes

	send_name = START_SCHEME

	interface_priority = 75

	scheme = sway
	ignores_pending_interaction_block = yes

	ai_targets = {
		ai_recipients = liege
		ai_recipients = neighboring_rulers
		max = 10
	}
	ai_targets = {
		ai_recipients = vassals
		ai_recipients = peer_vassals
		max = 10
	}
	ai_targets = {
		ai_recipients = councillors
	}
	ai_frequency_by_tier = {
		barony = 0
		county = 120
		duchy = 24
		kingdom = 6
		empire = 6
		hegemony = 6
	}

	is_shown = {
		scope:actor != scope:recipient
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			can_start_scheme = {
				type = sway
				target_character = scope:recipient
			}
		}
		#limit range for landless adventurers
		trigger_if = {
			limit = {
				scope:actor = {
					has_government = landless_adventurer_government
				}
			}
			#Has to be used instead of diplo range checks in laamp to landed interactions
			ep3_laamp_diplo_range_trigger = {
				TARGET = scope:recipient
				LAAMP = scope:actor
			}
		}
	}

	desc = scheme_interaction_tt_sway_approved

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

				left_icon = scope:actor
				right_icon = scope:recipient

				begin_scheme_basic_effect = {
					SCHEME_TYPE = sway
					TARGET_TYPE = target_character
					TARGET_SCOPE = scope:recipient
				}
			}
		}
	}

	ai_potential = {
		NOR = {
			scheme_generic_ai_blocker_trigger = yes
			primary_title = {
				is_mercenary_company = yes
			}
		}
		#Don't override Befriend with Sway?
		trigger_if = {
			limit = {
				OR = {
					AND = {
						has_royal_court = yes
						has_dlc_feature = royal_court
						has_court_type = court_diplomatic
						court_grandeur_current_level >= 10
					}
					AND = {
						dynasty ?= { has_dynasty_perk = glory_legacy_5 }
						has_royal_court = yes
						has_dlc_feature = royal_court
						has_court_type = court_diplomatic
						court_grandeur_current_level >= 10
					}
				}
			}
			always = yes
		}
		trigger_else = {
			NOT = {
				any_scheme = { scheme_type = befriend }
			}
		}
	}

	auto_accept = yes

	ai_will_do = {
		base = 10

		modifier = { # Prefer seducing if you've got the focus for it
			add = -20
			scope:actor = {
				has_focus = intrigue_temptation_focus
			}
		}

		modifier = {
			add = 10
			scope:recipient = {
				is_vassal_of = scope:actor
			}
		}

		modifier = { # Try to sway those who you might want to vassalize
			add = 30
			scope:actor = {
				top_liege = this
				primary_title.tier >= tier_county
				NOT = {
					any_targeting_faction = {
						exists = yes
						OR = {
							faction_is_type = liberty_faction
							faction_is_type = claimant_faction
							faction_is_type = independence_faction
						}
					}
				}
			}
			scope:recipient = {
				top_liege = this
				is_playable_character = yes
				primary_title.tier < scope:actor.primary_title.tier
				OR = {
					faith.religion = scope:actor.faith.religion
					AND = {
						faith = {
							has_doctrine = doctrine_pluralism_pluralistic
						}
						scope:actor.faith = {
							has_doctrine = doctrine_pluralism_pluralistic
						}
					}
				}
			}
		}

		modifier = {
			add = 10
			scope:recipient = {
				joined_faction ?= {
					faction_target = scope:actor
					faction_is_type = liberty_faction
					faction_is_at_war = no
				}
			}
		}

		modifier = {
			add = 20
			scope:recipient = {
				joined_faction ?= {
					faction_target = scope:actor
					faction_is_type = claimant_faction
					faction_is_at_war = no
				}
			}
		}

		modifier = {
			add = 30
			scope:recipient = {
				joined_faction ?= {
					faction_target = scope:actor
					faction_is_type = independence_faction
					faction_is_at_war = no
				}
			}
		}

		modifier = {
			factor = 2
			scope:recipient = {
				is_a_faction_leader = yes
				is_vassal_of = scope:actor
			}
		}

		modifier = {
			factor = 3
			scope:recipient = {
				is_vassal_of = scope:actor
				opinion = {
					target = scope:actor
					value < 0
				}
			}
		}

		modifier = {
			factor = 4
			scope:recipient = {
				is_powerful_vassal_of = scope:actor
				opinion = {
					target = scope:actor
					value < 0
				}
			}
		}

		modifier = {
			factor = 0.5
			scope:recipient.faith != scope:actor.faith
		}

		modifier = {
			factor = 0.25
			scope:actor = {
				is_ruler = yes
				tier_difference = {
					target = scope:recipient
					value > 2
				}
			}
			scope:recipient = {
				is_theocratic_lessee = no
			}
		}
		modifier = {
			factor = 0.5
			scope:actor = {
				has_personality_malicious_trigger = yes
			}
		}
		modifier = {
			factor = 2
			scope:actor = {
				OR = {
					has_trait = gregarious
					has_trait = diplomat
					has_trait = family_first
					has_trait = august
				}
			}
		}
		modifier = {
			factor = 0.75
			scope:recipient = {
				is_child_of = scope:actor
			}
		}
		modifier = {
			factor = 2
			scope:actor = {
				is_child_of = scope:recipient
			}
		}
		modifier = {
			factor = 0.25
			scope:recipient = {
				any_claim = {
					this = scope:actor.primary_title
				}
			}
		}
		modifier = { # Butter up the realm priest
			factor = 10
			scope:recipient = {
				is_theocratic_lessee = yes
				opinion = {
					target = scope:actor
					value <= 50
				}
			}
		}
		modifier = { # Try to make your tax collectors like you
			factor = 10
			scope:actor = {
				government_has_flag = government_is_clan
			}
			scope:recipient = {
				is_tax_collector = yes
				opinion = {
					target = scope:actor
					value <= 50
				}
			}
		}

		modifier = { # No point in swaying if opinion is already at 100
			factor = 0
			scope:recipient = {
				opinion = {
					target = scope:actor
					value >= 100
				}
			}
		}

		modifier = { # If they are unlanded, they have to be a realm priest or spymaster, or in the case for clan rulers, a tax collector
			factor = 0
			scope:recipient = {
				is_ruler = no
				NOR = {
					is_theocratic_lessee = yes
					has_council_position = councillor_spymaster
					AND = {
						is_tax_collector = yes
						scope:actor = { government_has_flag = government_is_clan }
					}
				}
			}
		}

		modifier = { # Ignore rivals unless forgiving
			factor = 0
			scope:actor = {
				has_relation_rival = scope:recipient
				NOT = { has_trait = forgiving }
			}
		}

		modifier = { # Ignore non-councillor barons
			factor = 0
			scope:recipient = {
				primary_title.tier = tier_barony
				is_councillor = no
			}
		}

		modifier = { # Ignore neighboring Kings+
			factor = 0
			scope:recipient = {
				top_liege = this
				is_playable_character = yes
				primary_title.tier >= tier_kingdom
			}
		}

		modifier = { # Ignore neighboring Herders
			factor = 0
			scope:recipient = {
				government_has_flag = government_is_herder
			}
		}
		
		ttd_medium_distance_ai_will_do_modifier = { CHARACTER_1 = scope:actor CHARACTER_2 = scope:recipient }
	}
}

learn_language_interaction = {
	icon = icon_scheme_learn_language
	category = interaction_category_friendly
	common_interaction = yes

	send_name = START_SCHEME

	interface_priority = 42
	scheme = learn_language
	ignores_pending_interaction_block = yes

	ai_targets = {
		ai_recipients = liege
		ai_recipients = head_of_faith
		ai_recipients = spouses
		ai_recipients = scripted_relations
	}
	ai_targets = {
		ai_recipients = vassals
		ai_recipients = peer_vassals
		max = 10
	}
	ai_targets = {
		ai_recipients = neighboring_rulers
		max = 5
	}
	ai_frequency_by_tier = {
		barony = 0
		county = 72
		duchy = 48
		kingdom = 12
		empire = 12
		hegemony = 12
	}

	is_shown = {
		scope:actor = {
			NOT = {
				culture = {
					has_same_culture_language = scope:recipient.culture
				}
			}
		}
		scope:actor != scope:recipient
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			can_start_scheme = {
				type = learn_language
				target_character = scope:recipient
			}
		}
		#limit range for landless adventurers
		trigger_if = {
			limit = {
				scope:actor = {
					has_government = landless_adventurer_government
				}
			}
			#Has to be used instead of diplo range checks in laamp to landed interactions
			ep3_laamp_diplo_range_trigger = {
				TARGET = scope:recipient
				LAAMP = scope:actor
			}
		}
	}

	desc = scheme_interaction_tt_learn_language_approved

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

				left_icon = scope:actor
				right_icon = scope:recipient

				begin_scheme_basic_effect = {
					SCHEME_TYPE = learn_language
					TARGET_TYPE = target_character
					TARGET_SCOPE = scope:recipient
				}
			}
		}
	}

	ai_potential = {
		primary_title.tier >= tier_county
		NOR = {
			has_trait = lazy
			has_trait = paranoid
			scheme_generic_ai_blocker_trigger = yes
			primary_title = {
				is_mercenary_company = yes
			}
		}
	}

	auto_accept = yes

	ai_will_do = {
		base = 0

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

		modifier = { # Focus on befriending if that's the path you've chosen
			add = -50
			scope:actor = {
				has_perk = befriend_perk
			}
		}

		modifier = { # Prefer seducing if you've got the focus for it
			add = -20
			scope:actor = {
				has_focus = intrigue_temptation_focus
			}
		}

		modifier = {
			add = 50
			scope:actor = {
				has_perk = open_minded_perk
			}
		}

		modifier = {
			add = 50
			scope:actor = {
				culture = {
					has_cultural_parameter = rulers_want_to_learn_languages_of_coreligionists
				}
			}
			scope:actor.religion = scope:recipient.religion
		}

		modifier = {
			add = 25
			scope:actor = {
				has_trait = curious
			}
		}

		modifier = {
			add = 50
			scope:actor = {
				is_adult = no
			}
		}

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

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

		modifier = {
			add = 10
			scope:recipient = {
				has_relation_potential_friend = scope:actor
			}
		}

		modifier = {
			add = 5
			scope:recipient = {
				is_close_family_of = scope:actor
				is_ruler = yes
			}
		}

		modifier = { # Muslims want to learn arabic
			add = 25
			scope:actor = {
				faith.religion = religion:islam_religion
				NOT = {
					knows_language = language_arabic
				}
			}
			scope:recipient = {
				culture = {
					has_cultural_pillar = language_arabic
				}
			}
		}

		modifier = { # Catholic clergy/pious people want to learn latin
			add = 50
			scope:actor = {
				faith = faith:catholic
				OR = {
					has_trait = zealous
					has_trait = humble
					is_clergy = yes
				}
				NOT = {
					knows_language = language_latin
				}
			}
			scope:recipient = {
				culture = {
					has_cultural_pillar = language_latin
				}
			}
		}

		modifier = { # Catholic clergy/pious people want to learn Italian
			add = 50
			scope:actor = {
				faith = faith:catholic
				OR = {
					has_trait = zealous
					has_trait = humble
					is_clergy = yes
				}
				NOT = {
					knows_language = language_italian
				}
			}
			scope:recipient = {
				culture = {
					has_cultural_pillar = language_italian
				}
			}
		}

		modifier = { # Clergy/pious people want to learn their HoF's language
			add = 50
			scope:actor = {
				exists = faith.religious_head
				OR = {
					has_trait = zealous
					is_clergy = yes
				}
				NOT = { knows_language_of_culture = scope:actor.faith.religious_head.culture }
			}
			scope:recipient = { knows_language_of_culture = scope:actor.faith.religious_head.culture }
		}

		modifier = { # Coptic/Orthodox clergy/pious people want to learn greek
			add = 50
			scope:actor = {
				OR = {
					faith = faith:orthodox
					faith = faith:coptic
				}
				OR = {
					has_trait = zealous
					has_trait = humble
					is_clergy = yes
				}
				NOT = {
					knows_language = language_greek
				}
			}
			scope:recipient = {
				culture = {
					has_cultural_pillar = language_greek
				}
			}
		}

		modifier = { # Nestorian clergy/pious people want to learn aramaic
			add = 50
			scope:actor = {
				faith = faith:nestorian
				OR = {
					has_trait = zealous
					has_trait = humble
					is_clergy = yes
				}
				NOT = {
					knows_language = language_aramaic
				}
			}
			scope:recipient = {
				culture = {
					has_cultural_pillar = language_aramaic
				}
			}
		}

		modifier = {
			add = 20
			scope:actor = {
				has_focus = diplomacy_foreign_affairs_focus
				any_neighboring_realm_same_rank_owner = {
					this = scope:recipient
				}
			}
		}

		modifier = {
			add = 20
			scope:actor = {
				OR = {
					has_focus = learning_scholarship_focus
					has_focus = stewardship_duty_focus
				}
			}
			scope:recipient = {
				is_vassal_of = scope:actor
			}
		}

		modifier = {
			add = 10
			exists = scope:actor.capital_county
			scope:recipient.culture = {
				has_same_culture_language = scope:actor.capital_county.culture
			}
		}

		modifier = {
			add = 100
			scope:actor.culture = {
				has_cultural_tradition = tradition_loyal_soldiers
			}
			top_liege != this
			scope:actor = {
				liege = scope:recipient
			}
		}

		modifier = {
			factor = 2
			scope:recipient = {
				is_powerful_vassal_of = scope:actor
			}
		}

		modifier = {
			factor = 2
			scope:actor = {
				learning >= 12
			}
		}

		modifier = {
			factor = 0.5
			scope:actor = {
				learning <= 6
			}
		}

		modifier = {
			factor = 0

			scope:actor.num_of_known_languages >= 5
			scope:actor = {
				NOR = {
					has_perk = pedagogy_perk
					has_trait = intellect_good_2
					has_trait = intellect_good_3
					age < 25
				}
			}
		}

		modifier = {
			factor = 0

			scope:actor.num_of_known_languages >= language_soft_cap
		}
		
		ttd_medium_distance_ai_will_do_modifier = { CHARACTER_1 = scope:actor CHARACTER_2 = scope:recipient }
	}
}

