﻿ingratiate_family = {
	# Basic Setup
	skill = diplomacy
	desc = ingratiate_family_desc_general
	success_desc = "INGRATIATE_FAMILY_SUCCESS_DESC"
	icon = icon_ingratiate_family
	illustration = "gfx/interface/illustrations/event_scenes/corridor.dds"
	category = political
	target_type = character
	is_secret = no
	is_basic = yes
	
	# Parameters
	speed_per_skill_point = -2.5
	spymaster_speed_per_skill_point = 0	
	uses_resistance = no
	base_progress_goal = 365
	base_maximum_success = 95
	minimum_success = 5
	
	# Core Triggers
	allow = {
		is_adult = yes
		scope:target = {
			is_adult = yes
			is_imprisoned = no
			exists = house
			house != scope:owner.house
			top_liege = scope:owner.top_liege
		}
	}

	valid = {
		custom_tooltip = {
			text = ingratiate_family_living_quarters_building_tt
			domicile ?= { has_domicile_parameter = estate_unlock_ingratiate_family_interaction }
		}
		is_imprisoned = no
		is_incapable = no
		NOT = { is_at_war_with = scope:target }
		any_held_title = { is_noble_family_title = yes }
		house.house_head ?= this
		scope:target = {
			is_adult = yes
			is_imprisoned = no
			any_held_title = { is_noble_family_title = yes }
			house.house_head ?= this
			in_diplomatic_range = scope:owner
			NOR = {
				has_opinion_modifier = {
					modifier = ingratiate_family_opinion
					target = scope:owner
				}
				has_relation_rival = scope:owner
				has_relation_friend = scope:owner
			}
			top_liege.primary_title = prev.top_liege.primary_title # This hides the tooltip
		}
	}

	odds_prediction = {
		add = base_odds_prediction_target_is_char_value
		add = odds_skill_contribution_diplomacy_value
		add = odds_ingratiate_family_scheme_misc_value
		min = 0
	}

	# Base Chances
	base_success_chance = {
		base = 15
		modifier = {
			add = {
				value = scope:owner.diplomacy
				multiply = 2
				floor = yes
			}
			desc = SCHEME_YOUR_DIPLOMACY
		}

		opinion_modifier = {
			who = scope:target
			opinion_target = scope:owner
			multiplier = 0.25
		}
		
		#SCHEME OWNER#
		#Language
		modifier = {
			add = 5
			desc = YOU_SPEAK_THE_LANGUAGE
			scope:owner = { knows_language_of_culture = scope:target.culture }
		}
		modifier = {
			add = 8
			scope:owner = { has_trait = diplomat }
			desc = SCHEME_BEFRIEND_MY_LIFESTYLE
		}

		#Rank tier difference (landed target/target whose liege doesn't care)
		modifier = { #3 or more higher rank
			trigger = { personal_scheme_should_not_evaluate_tier_differences_trigger = yes }
			add = 50
			desc = "HIGHER_RANK_THAN_SCHEME_TARGET"
			scope:target = {
				personal_scheme_success_compare_target_liege_tier_trigger = no
				NOT = {
					is_theocratic_lessee = yes
				}
			}
			scope:owner = {
				tier_difference = {
					target = scope:target
					value >= 3
				}
			}
		}
		modifier = { #2 higher rank
			trigger = { personal_scheme_should_not_evaluate_tier_differences_trigger = yes }
			add = 25
			desc = "HIGHER_RANK_THAN_SCHEME_TARGET"
			scope:target = {
				personal_scheme_success_compare_target_liege_tier_trigger = no
				NOT = {
					is_theocratic_lessee = yes
				}
			}
			scope:owner = {
				tier_difference = {
					target = scope:target
					value = 2
				}
			}
		}
		modifier = { #1 higher rank
			trigger = { personal_scheme_should_not_evaluate_tier_differences_trigger = yes }
			add = 10
			desc = "HIGHER_RANK_THAN_SCHEME_TARGET"
			scope:target = {
				personal_scheme_success_compare_target_liege_tier_trigger = no
				NOT = {
					is_theocratic_lessee = yes
				}
			}
			scope:owner = {
				tier_difference = {
					target = scope:target
					value = 1
				}
			}
		}
		modifier = { #1 lower rank
			trigger = { personal_scheme_should_not_evaluate_tier_differences_trigger = yes }
			add = -10
			desc = "LOWER_RANK_THAN_SCHEME_TARGET"
			scope:target = {
				personal_scheme_success_compare_target_liege_tier_trigger = no
			}
			scope:owner = {
				tier_difference = {
					target = scope:target
					value = -1
				}
			}
		}
		modifier = { #2 lower rank
			trigger = { personal_scheme_should_not_evaluate_tier_differences_trigger = yes }
			add = -25
			desc = "LOWER_RANK_THAN_SCHEME_TARGET"
			scope:target = {
				personal_scheme_success_compare_target_liege_tier_trigger = no
			}
			scope:owner = {
				tier_difference = {
					target = scope:target
					value = -2
				}
			}
		}
		modifier = { #3 or less lower rank
			trigger = { personal_scheme_should_not_evaluate_tier_differences_trigger = yes }
			add = -50
			desc = "LOWER_RANK_THAN_SCHEME_TARGET"
			scope:target = {
				personal_scheme_success_compare_target_liege_tier_trigger = no
			}
			scope:owner = {
				tier_difference = {
					target = scope:target
					value <= -3
				}
			}
		}

		# Diarchs are better at schemes within their liege's realm
		diarch_scheming_within_realm_bonus_modifier = yes

		#Religious Heads
		modifier = {
			add = -50
			desc = "SCHEME_VS_RELIGIOUS_HEAD"
			scope:target = {
				faith = scope:owner.faith
				faith = {
					religious_head ?= {
			 			this = scope:target
			 		}
				}
			}
		}

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

		#Family Feud
		house_feud_sway_scheme_success_modifier = yes

		# Modifiers
		modifier = {
			scope:owner = { has_character_modifier = poet_for_diplo_schemes_modifier }
			desc = poet_for_diplo_schemes_modifier
			add = 15
		}

		modifier = {
			scope:owner.house = { is_dominant_family = yes }
			add = 25
			desc = YOUR_FAMILY_IS_DOMINANT
		}

		modifier = {
			exists = scope:owner.house
			exists = scope:target.house
			add = {
				value = scope:owner.house.house_power_score
				subtract = scope:target.house.house_power_score
				divide = 3
			}
			desc = RELATIVE_FAMILY_RATING
		}
		modifier = {
			add = {
				value = scope:owner.dynasty.dynasty_prestige_level
				subtract = scope:target.dynasty.dynasty_prestige_level
				multiply = 10
			}
			desc = RELATIVE_FAMILY_RENOWN
		}
		modifier = {
			scope:owner.dynasty = scope:target.dynasty
			add = 15
			desc = OPINION_SAME_DYNASTY
		}
		# house_head_request_interaction
		modifier = {
			add = political_scheme_variable_list_value
			scope:owner = {
				has_variable_list = supporting_political_schemes
			}
			desc = HOUSE_HEAD_SCHEME_SUPPORT_DESC
		}
		modifier = {
			add = -10
			scope:owner = { has_character_modifier = political_schemes_distracted_modifier }
			desc = political_schemes_distracted_modifier
		}

		# Distance Penalty
		ttd_domicile_distance_success_chance_modifier = yes
	}

	# On Actions
	on_phase_completed = {
		ingratiate_family_scheme_prep_effect = yes
	}

	on_invalidated = {
		scheme_target_character = { save_scope_as = target }
		scheme_owner = {
			save_scope_as = owner
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = ingratiate_family_invalidated_title
				left_icon = scope:target
				if = {
					limit = {
						scope:target = { is_alive = no }
					}
					custom_tooltip = ingratiate_family_invalidated_dead 
				}
				else_if = {	
					limit = { is_at_war_with = scope:target }
					custom_tooltip = ingratiate_family_invalidated_war 
				}
				else_if = {
					limit = {
						NOT = { scope:target = { in_diplomatic_range = scope:owner } }
					}
					custom_description_no_bullet = {
						object = scope:target
						text = scheme_target_not_in_diplomatic_range
					}
				}
			}
		}
	}
}
