learn_language = {
	# Basic Setup
	skill = learning
	desc = learn_language_desc_general
	success_desc = "LEARN_LANGUAGE_SUCCESS_DESC"
	icon = icon_scheme_learn_language
	illustration = "gfx/interface/illustrations/event_scenes/corridor.dds"
	target_type = character
	is_secret = no
	is_basic = yes
	cooldown = { months = 2 }
	
	# Parameters
	speed_per_skill_point = t1_spsp_owner_value
	spymaster_speed_per_skill_point = 0
	uses_resistance = no
	base_progress_goal = 730
	base_maximum_success = 95
	minimum_success = 5
	
	# Core Triggers
	allow = {
		age >= 6
		NOR = {
			culture = { # You can't learn your own native language
				has_same_culture_language = scope:target.culture
			}
			knows_language_of_culture = scope:target.culture
			custom_description = { # Should not be able to target the same language twice
				object = scope:target
				text = scheme_target_same_language_as_existing_scheme
				any_scheme = {
					type = learn_language
					scheme_target_character = {
						culture = { # You can't learn the same language with two different schemes
							has_same_culture_language = scope:target.culture
						}
					}
				}
			}
		}

		scope:target = {
			age >= 10
		}
		is_imprisoned = no

		#AI blockers
		trigger_if = {
			limit = { is_ai = yes }

			scope:target = {
				trigger_if = { #So players don't get spammed by AI's
					limit = {
						is_ai = no
					}
					NOT = {
						any_targeting_scheme = {
							scheme_type = learn_language
						}
					}
				}
			}
		}
	}
	valid = {
		is_incapable = no
		NOT = {
			has_character_modifier = partially_mute_modifier
		}
		NOT = {
			knows_language_of_culture = scope:target.culture
		}
		scope:target = {
			OR = {
				exists = location
				in_diplomatic_range = scope:owner
			}
		}
	}

	# Prediction (abysmal/low/medium/high/excellent)
	# scope:owner - Character starting the scheme
	# scope:target - Whatever the scheme is targeting
	odds_prediction = {
		add = base_odds_prediction_target_is_char_value
		add = odds_skill_contribution_learning_value
		add = odds_learn_language_scheme_misc_value
		min = 0
	}

	# Base Chances
	base_success_chance = {
		base = 0
		
		modifier = {
			add = {
				value = scope:owner.learning
				multiply = 3
			}
			desc = SCHEME_LEARNING_MODIFIER
			scope:owner.learning > 0
		}
		
		modifier = {
			add = {
				value = scope:owner.piety_level
				multiply = 10
			}
			desc = SCHEME_PIETY_LEVEL_MODIFIER
			scope:owner.piety_level > 0
			scope:owner.culture = {
				has_cultural_parameter = language_success_chance_per_piety_level
			}
		}
		
		modifier = {
			add = scope:owner.cp:councillor_court_chaplain.learning
			desc = SCHEME_CHAPLAIN_HELP_LEARNING_MODIFIER
			exists = scope:owner.cp:councillor_court_chaplain
			scope:owner.cp:councillor_court_chaplain.learning > 0
		}
		
		modifier = {
			add = {
				value = 5
				multiply = {
					value = scope:owner.num_of_known_languages
					subtract = 1
				}
			}
			desc = SCHEME_KNOWN_LANGUAGES_MODIFIER
			scope:owner.num_of_known_languages > 1
		}
		
		modifier = {
			add = {
				value = 30
				subtract = scope:owner.age
				multiply = 2
			}
			desc = SCHEME_YOUTH_MODIFIER
			scope:owner.age < 30
		}
		
		modifier = {
			add = 25
			desc = SCHEME_HERITAGE_MODIFIER
			scope:target.culture = {
				has_same_culture_heritage = scope:owner.culture
			}
		}
		
		modifier = {
			add = 10
			desc = SAME_LANGUAGE_ORIGIN
			scope:target.culture = {
				has_cultural_parameter = goidelic_group_language_param
			}
			scope:owner.culture = {
				has_cultural_parameter = goidelic_group_language_param
			}
		}
		modifier = {
			add = 10
			desc = SAME_LANGUAGE_ORIGIN
			scope:target.culture = {
				has_cultural_parameter = anglic_group_language_param
			}
			scope:owner.culture = {
				has_cultural_parameter = anglic_group_language_param
			}
		}
		modifier = {
			add = 10
			desc = SAME_LANGUAGE_ORIGIN
			scope:target.culture = {
				has_cultural_parameter = brythonic_group_language_param
			}
			scope:owner.culture = {
				has_cultural_parameter = brythonic_group_language_param
			}
		}
		modifier = {
			add = 10
			desc = SAME_LANGUAGE_ORIGIN
			scope:target.culture = {
				has_cultural_parameter = french_group_language_param
			}
			scope:owner.culture = {
				has_cultural_parameter = french_group_language_param
			}
		}
		modifier = {
			add = 10
			desc = SAME_LANGUAGE_ORIGIN
			scope:target.culture = {
				has_cultural_parameter = middle_german_group_language_param
			}
			scope:owner.culture = {
				has_cultural_parameter = middle_german_group_language_param
			}
		}
		modifier = {
			add = 10
			desc = SAME_LANGUAGE_ORIGIN
			scope:target.culture = {
				has_cultural_parameter = east_hispanic_group_language_param
			}
			scope:owner.culture = {
				has_cultural_parameter = east_hispanic_group_language_param
			}
		}
		modifier = {
			add = 10
			desc = SAME_LANGUAGE_ORIGIN
			scope:target.culture = {
				has_cultural_parameter = occitanic_group_language_param
			}
			scope:owner.culture = {
				has_cultural_parameter = occitanic_group_language_param
			}
		}
		modifier = {
			add = 10
			desc = SAME_LANGUAGE_ORIGIN
			scope:target.culture = {
				has_cultural_parameter = lausatian_group_language_param
			}
			scope:owner.culture = {
				has_cultural_parameter = lausatian_group_language_param
			}
		}
		modifier = {
			add = 10
			desc = SAME_LANGUAGE_ORIGIN
			scope:target.culture = {
				has_cultural_parameter = west_hispanic_group_language_param
			}
			scope:owner.culture = {
				has_cultural_parameter = west_hispanic_group_language_param
			}
		}
		modifier = {
			add = 10
			desc = SAME_LANGUAGE_ORIGIN
			scope:target.culture = {
				has_cultural_parameter = basque_group_language_param
			}
			scope:owner.culture = {
				has_cultural_parameter = basque_group_language_param
			}
		}
		modifier = {
			add = 10
			desc = SAME_LANGUAGE_ORIGIN
			scope:target.culture = {
				has_cultural_parameter = middle_hispanic_group_language_param
			}
			scope:owner.culture = {
				has_cultural_parameter = middle_hispanic_group_language_param
			}
		}
		modifier = {
			add = 10
			desc = SAME_LANGUAGE_ORIGIN
			scope:target.culture = {
				has_cultural_parameter = italo_dalmatian_group_language_param
			}
			scope:owner.culture = {
				has_cultural_parameter = italo_dalmatian_group_language_param
			}
		}
		modifier = {
			add = 10
			desc = SAME_LANGUAGE_ORIGIN
			scope:target.culture = {
				has_cultural_parameter = albanian_group_language_param
			}
			scope:owner.culture = {
				has_cultural_parameter = albanian_group_language_param
			}
		}
		modifier = {
			add = 10
			desc = SAME_LANGUAGE_ORIGIN
			scope:target.culture = {
				has_cultural_parameter = low_german_group_language_param
			}
			scope:owner.culture = {
				has_cultural_parameter = low_german_group_language_param
			}
		}
		modifier = {
			add = 10
			desc = SAME_LANGUAGE_ORIGIN
			scope:target.culture = {
				has_cultural_parameter = high_german_group_language_param
			}
			scope:owner.culture = {
				has_cultural_parameter = high_german_group_language_param
			}
		}
		modifier = {
			add = 10
			desc = SAME_LANGUAGE_ORIGIN
			scope:target.culture = {
				has_cultural_parameter = hewbrew_group_language_param
			}
			scope:owner.culture = {
				has_cultural_parameter = hewbrew_group_language_param
			}
		}
		modifier = {
			add = 10
			desc = SAME_LANGUAGE_ORIGIN
			scope:target.culture = {
				has_cultural_parameter = gallo_italian_group_language_param
			}
			scope:owner.culture = {
				has_cultural_parameter = gallo_italian_group_language_param
			}
		}
		modifier = {
			add = 10
			desc = SAME_LANGUAGE_ORIGIN
			scope:target.culture = {
				has_cultural_parameter = arabic_group_language_param
			}
			scope:owner.culture = {
				has_cultural_parameter = arabic_group_language_param
			}
		}
		modifier = {
			add = 10
			desc = SAME_LANGUAGE_ORIGIN
			scope:target.culture = {
				has_cultural_parameter = sardic_group_language_param
			}
			scope:owner.culture = {
				has_cultural_parameter = sardic_group_language_param
			}
		}
		modifier = {
			add = 10
			desc = SAME_LANGUAGE_ORIGIN
			scope:target.culture = {
				has_cultural_parameter = rhaeto_romance_group_language_param
			}
			scope:owner.culture = {
				has_cultural_parameter = rhaeto_romance_group_language_param
			}
		}
		modifier = {
			add = 10
			desc = SAME_LANGUAGE_ORIGIN
			scope:target.culture = {
				has_cultural_parameter = greek_group_language_param
			}
			scope:owner.culture = {
				has_cultural_parameter = greek_group_language_param
			}
		}
		modifier = {
			add = 10
			desc = SAME_LANGUAGE_ORIGIN
			scope:target.culture = {
				has_cultural_parameter = east_north_germanic_group_language_param
			}
			scope:owner.culture = {
				has_cultural_parameter = east_north_germanic_group_language_param
			}
		}
		modifier = {
			add = 10
			desc = SAME_LANGUAGE_ORIGIN
			scope:target.culture = {
				has_cultural_parameter = west_north_germanic_group_language_param
			}
			scope:owner.culture = {
				has_cultural_parameter = west_north_germanic_group_language_param
			}
		}
		modifier = {
			add = 10
			desc = SAME_LANGUAGE_ORIGIN
			scope:target.culture = {
				has_cultural_parameter = frisian_language_param
			}
			scope:owner.culture = {
				has_cultural_parameter = frisian_language_param
			}
		}
		modifier = {
			add = 10
			desc = SAME_LANGUAGE_ORIGIN
			scope:target.culture = {
				has_cultural_parameter = south_slavic_group_language_param
			}
			scope:owner.culture = {
				has_cultural_parameter = south_slavic_group_language_param
			}
		}
		modifier = {
			add = 10
			desc = SAME_LANGUAGE_ORIGIN
			scope:target.culture = {
				has_cultural_parameter = west_slavic_group_language_param
			}
			scope:owner.culture = {
				has_cultural_parameter = west_slavic_group_language_param
			}
		}
		modifier = {
			add = 10
			desc = SAME_LANGUAGE_ORIGIN
			scope:target.culture = {
				has_cultural_parameter = low_franconian_group_language_param
			}
			scope:owner.culture = {
				has_cultural_parameter = low_franconian_group_language_param
			}
		}
		modifier = {
			add = 10
			desc = SAME_LANGUAGE_ORIGIN
			scope:target.culture = {
				has_cultural_parameter = far_west_indo_aryan_group_language_param
			}
			scope:owner.culture = {
				has_cultural_parameter = far_west_indo_aryan_group_language_param
			}
		}
		modifier = {
			add = 10
			desc = SAME_LANGUAGE_ORIGIN
			scope:target.culture = {
				has_cultural_parameter = oghuz_group_language_param
			}
			scope:owner.culture = {
				has_cultural_parameter = oghuz_group_language_param
			}
		}
		modifier = {
			add = 10
			desc = SAME_LANGUAGE_ORIGIN
			scope:target.culture = {
				has_cultural_parameter = kipchak_bulgar_group_language_param
			}
			scope:owner.culture = {
				has_cultural_parameter = kipchak_bulgar_group_language_param
			}
		}
		modifier = {
			add = 10
			desc = SAME_LANGUAGE_ORIGIN
			scope:target.culture = {
				has_cultural_parameter = daco_romanian_group_language_param
			}
			scope:owner.culture = {
				has_cultural_parameter = daco_romanian_group_language_param
			}
		}
		modifier = {
			add = 10
			desc = SAME_LANGUAGE_ORIGIN
			scope:target.culture = {
				has_cultural_parameter = ugric_group_language_param
			}
			scope:owner.culture = {
				has_cultural_parameter = ugric_group_language_param
			}
		}
		modifier = {
			add = 10
			desc = SAME_LANGUAGE_ORIGIN
			scope:target.culture = {
				has_cultural_parameter = east_slavic_group_language_param
			}
			scope:owner.culture = {
				has_cultural_parameter = east_slavic_group_language_param
			}
		}
		modifier = {
			add = 10
			desc = SAME_LANGUAGE_ORIGIN
			scope:target.culture = {
				has_cultural_parameter = baltic_group_language_param
			}
			scope:owner.culture = {
				has_cultural_parameter = baltic_group_language_param
			}
		}
		modifier = {
			add = 10
			desc = SAME_LANGUAGE_ORIGIN
			scope:target.culture = {
				has_cultural_parameter = finnic_group_language_param
			}
			scope:owner.culture = {
				has_cultural_parameter = finnic_group_language_param
			}
		}
		modifier = {
			add = 10
			desc = SAME_SPRACHBUND
			scope:target.culture = {
				has_cultural_parameter = latin_sprachbund_language_param
			}
			scope:owner.culture = {
				has_cultural_parameter = latin_sprachbund_language_param
			}
		}
		modifier = {
			add = 10
			desc = SAME_SPRACHBUND
			scope:target.culture = {
				has_cultural_parameter = greek_sprachbund_language_param
			}
			scope:owner.culture = {
				has_cultural_parameter = greek_sprachbund_language_param
			}
		}
		modifier = {
			add = 10
			desc = SAME_SPRACHBUND
			scope:target.culture = {
				has_cultural_parameter = fusha_sprachbund_language_param
			}
			scope:owner.culture = {
				has_cultural_parameter = fusha_sprachbund_language_param
			}
		}
		modifier = {
			add = 50
			desc = SCHEME_LOYAL_SOLDIERS_MODIFIER
			scope:owner = {
				culture = {
					has_cultural_parameter = extra_learn_language_success_chance_vs_liege
				}
				any_liege_or_above = {
					this = scope:target
				}
			}
		}

		modifier = { #For others learning the language of someone with tradition
			add = 50
			desc = SCHEME_SCHOLAR_OFFICIALS_MODIFIER
			scope:target.culture = {
				has_cultural_parameter = learn_language_success_chance_for_others
			}
		}

		
		
		modifier = {
			add = 30
			desc = SCHEME_CULTURE_BLENDING_MODIFIER
			scope:owner = {
				culture = {
					has_cultural_parameter = learns_more_languages
				}
			}
		}

		#Intellect good
		modifier = {
			desc = "scheme_intellect_good_1"
			scope:owner = { has_trait = intellect_good_1 }
			add = 10
		}
		
		modifier = {
			desc = "scheme_intellect_good_2"
			scope:owner = { has_trait = intellect_good_2 }
			add = 20
		}
		
		modifier = {
			desc = "scheme_intellect_good_3"
			scope:owner = { has_trait = intellect_good_3 }
			add = 30
		}
		
		modifier = {
			scope:target = { has_trait = stubborn }
			desc = "SCHEME_TRAIT_STUBBORN"
			add = 10
		}
		
		modifier = {
			scope:target = { has_trait = ambitious }
			desc = "SCHEME_TRAIT_AMBITIOUS"
			add = 5
		}
		
		#Paranoid value is added automatically because of trait	parameter enemy_personal_scheme_success_chance_add 
		
		# Lifestyles

		# Dynasty Kin Personal Scheme Success Chance on Dynasty Perk
		modifier = {
			add = kin_legacy_4_success_chance
			desc = KIN_LEGACY_DESC
			exists = scope:owner.dynasty
			scope:owner.dynasty = {
				has_dynasty_perk = kin_legacy_4
			}
			scope:target.dynasty = scope:owner.dynasty
		}

		# House Personal Scheme Success Chance on Cultural Parameter
		modifier = {
			add = cultural_house_personal_scheme_success_chance
			desc = KIN_PARAMETER_DESC
			exists = scope:owner.house
			exists = scope:target.house
			scope:owner.culture = {
				has_cultural_parameter = cultural_house_personal_scheme_success_chance
			}
			scope:target.house = scope:owner.house
		}

		# Pedagogy Perk
		modifier = {
			add = 25
			desc = LEARN_LANGUAGE_PEDAGOGY_PERK_DESC
			scope:owner = {
				has_perk = pedagogy_perk
			}
		}

		# Thicker Than Water Perk
		modifier = {
			add = thicker_than_water_bonus
			desc = BEFRIEND_THICKER_THAN_WATER_PERK_DESC
			scope:owner = {
				has_perk = thicker_than_water_perk
			}
			scope:target = {
				is_close_or_extended_family_of = scope:owner
			}
		}

		# Modifiers
		# house_head_request_interaction
		modifier = {
			add = personal_scheme_variable_list_value
			scope:owner = {
				has_variable_list = supporting_personal_schemes
			}
			desc = HOUSE_HEAD_SCHEME_SUPPORT_DESC
		}
		modifier = {
			add = -10
			scope:owner = { has_character_modifier = personal_schemes_distracted_modifier }
			desc = personal_schemes_distracted_modifier
		}
		# Estate
		modifier = {
			scope:owner.domicile ?= {
				has_domicile_parameter = increased_success_personal_schemes_1
			}
			add = estate_increased_personal_scheme_success_1_value
		}
		modifier = {
			scope:owner.domicile ?= {
				has_domicile_parameter = increased_success_personal_schemes_2
			}
			add = estate_increased_personal_scheme_success_2_value
		}
		modifier = {
			scope:owner.domicile ?= {
				has_domicile_parameter = increased_success_personal_schemes_3
			}
			add = estate_increased_personal_scheme_success_3_value
		}

		# Personal Scheme Shared
		personal_scheme_base_success_chance_modifiers = yes
	}

	# On Actions
	on_phase_completed = {
		# Grab our scopes.
		save_scope_as = scheme
		scheme_target_character = { save_scope_as = target }
		scheme_owner = { save_scope_as = owner }
		scope:scheme = {
			random = {
				chance = scope:scheme.scheme_success_chance

				save_scope_value_as = {
					name = scheme_successful
					value = yes
				}
			}
			scope:owner = {
				if = {
					limit = {
						exists = scope:scheme_successful
					}
					trigger_event = {
						on_action = learn_language_success
					}
				}
				else = {
					trigger_event = {
						on_action = learn_language_failure
					}	
				}
			}
		}
	}
	on_monthly = {
		save_scope_as = scheme
		scheme_target_character = { save_scope_as = target }
		scheme_owner = {
			save_scope_as = owner
			trigger_event = { on_action = learn_language_ongoing }
		}
	}
	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 = learn_language_invalidated
					custom_tooltip = learn_language_invalidated_dead_desc
					left_icon = scope:target
				}
			}
		}
		else_if = {
			limit = {
				scope:owner = {
					#OR = {
						culture = { # You can't learn your own native language
							has_same_culture_language = scope:target.culture
						}
						#knows_language_of_culture = scope:target.culture
					#}
				}
			}
			scope:owner = {
				send_interface_toast = {
					title = learn_language_invalidated
					custom_tooltip = learn_language_invalidated_cannot_learn_language_desc
					left_icon = scope:target
				}
			}
		}

		if = {
			limit = {
				scope:target = { 
					NOT = { in_diplomatic_range = scope:owner }
				}
			}
			scope:owner = {
				send_interface_toast = {
					title = learn_language_invalidated_title
					left_icon = scope:target
					custom_description_no_bullet = {
						object = scope:target
						text = scheme_target_not_in_diplomatic_range
					}
				}
			}
		}
		
		scope:owner = {
			if = {
				limit = {
					is_alive = yes
					scope:target = {
						OR = {
							is_alive = no
							NOT = { in_diplomatic_range = scope:owner }
						}
					}
					NOR = {
						culture = { # You can't learn your own native language
							has_same_culture_language = scope:target.culture
						}
						knows_language_of_culture = scope:target.culture
					}
				}
				set_variable = {
					name = language_progress
					value = prev.scheme_progress
				}
				trigger_event = learn_language_outcome.3000
			}
		}
	}
}
