﻿### EP3 Scheme Interactions

# Slander
start_slander_interaction = {
	icon = icon_scheme_slander
	interface_priority = 95
	common_interaction = yes
	category = interaction_category_admin

	send_name = START_SCHEME

	scheme = slander
	ignores_pending_interaction_block = yes

	ai_targets = {
		ai_recipients = peer_vassals
		max = 10
	}
	ai_frequency = 36
	
	is_shown = {
		scope:actor = {
			is_adult = yes
			is_imprisoned = no
			government_allows = administrative
		}
		scope:recipient = {
			NOT = { this = scope:actor }
			government_allows = administrative
			top_liege = scope:actor.top_liege
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			can_start_scheme = {
				type = slander
				target_character = scope:recipient
			}
		}
		scope:recipient = {
			NOT = { has_strong_hook = scope:actor }
			is_independent_ruler = no
		}
	}

	desc = {
		triggered_desc = {
			trigger = {
				scope:actor = {
					can_start_scheme = {
						type = slander
						target_character = scope:recipient
					}
				}
			}
			desc = scheme_interaction_tt_slander_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_slander_interaction.tt.agent_focus_balance
	}
	## Focused on Success Chance.
	send_option = {
		flag = agent_focus_success
		current_description = start_slander_interaction.tt.agent_focus_success
	}
	## Focused on Speed.
	send_option = {
		flag = agent_focus_speed
		current_description = start_slander_interaction.tt.agent_focus_speed
	}
	## Focused on Secrecy.
	send_option = {
		flag = agent_focus_secrecy
		current_description = start_slander_interaction.tt.agent_focus_secrecy
	}

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

				left_icon = scope:actor					
				right_icon = scope:recipient

				# Success.
				if = {
					limit = { scope:agent_focus_success ?= yes }
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = slander
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
						# Success.
						AGENT_1 = agent_intermediary
						AGENT_2 = agent_sycophant
						AGENT_3 = agent_sycophant
						# Speed.
						AGENT_4 = agent_political_socialite
						# Secrecy.
						AGENT_5 = agent_courtesan
					}
				}
				# Speed.
				else_if = {
					limit = { scope:agent_focus_speed ?= yes }
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = slander
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
						# Speed.
						AGENT_1 = agent_political_socialite
						AGENT_2 = agent_political_socialite
						AGENT_3 = agent_bureaucrat
						# Success.
						AGENT_4 = agent_sycophant
						# Secrecy.
						AGENT_5 = agent_courtesan
					}
				}
				# Secrecy.
				else_if = {
					limit = { scope:agent_focus_secrecy ?= yes }
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = slander
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
						# Secrecy.
						AGENT_1 = agent_courtesan
						AGENT_2 = agent_amanuensis
						AGENT_3 = agent_eunuch
						# Success.
						AGENT_4 = agent_sycophant
						# Speed.
						AGENT_5 = agent_political_socialite
					}
				}
				# Balanced.
				else = {
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = slander
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
						# Success.
						AGENT_1 = agent_sycophant
						AGENT_2 = agent_intermediary
						# Speed.
						AGENT_3 = agent_political_socialite
						AGENT_4 = agent_bureaucrat
						# Secrecy.
						AGENT_5 = agent_courtesan
					}
				}
			}
			# Scheme bonuses from being the emperor/dominant family/powerful family
			ep3_actor_scheme_modifier_effect = yes

			stress_impact = {
				compassionate = minor_stress_impact_gain
				honest = minor_stress_impact_gain
				just = minor_stress_impact_gain
			}
		}
		scope:recipient = { custom_tooltip = slander_modifier_tt }
	}

	ai_potential = {
		OR = {
			primary_title.tier >= tier_duchy
			AND = {
				this = house.house_head
				is_landless_administrative = yes
			}
		}
		NOT = {
			any_scheme = {
				is_scheme_category = hostile
			}
		}
	}
	
	auto_accept = yes

	ai_will_do = {
		base = 5

		#Competing candidate
		modifier = {
			scope:recipient = { is_competing_for_same_title_as = { CHARACTER = scope:actor } }
			add = 30
		}
		modifier = {
			scope:recipient = { is_winning_competing_for_same_title_as = { CHARACTER = scope:actor } }
			add = 50
		}

		# More likely against powerful or dominant families
		modifier = {
			scope:recipient.house ?= {
				OR = {
					is_powerful_family = yes
					is_dominant_family = yes
				}
			}
			add = 20
		}

		#Personality
		modifier = {
			has_trait = ambitious
			add = 15
		}
		modifier = {
			has_trait = deceitful
			add = 15
		}
		modifier = {
			has_trait = honest
			add = -15
		}
		modifier = {
			has_trait = compassionate
			add = -15
		}
		modifier = {
			has_trait = content
			add = -15
		}

		# House & Family
		modifier = {
			is_close_family_of = scope:recipient
			add = -20
		}
		modifier = {
			house = scope:recipient.house
			add = -50
		}
		modifier = {
			house.house_head = scope:recipient
			add = -50
		}

		#Feuds
		modifier = {
			house.house_head ?= {
				any_owned_story = {
					story_type = story_cycle_house_feud
					has_variable = house_feud_house
					var:house_feud_house = scope:recipient.house
				}
			}
			add = 50
		}

		# Relationships
		modifier = {
			add = 25
			has_any_mild_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}
		modifier = {
			add = 50
			has_any_moderate_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}
		modifier = {
			add = 100
			has_any_worst_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}
		modifier = {
			add = -25
			has_any_mild_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}
		modifier = {
			add = -50
			has_any_moderate_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}
		modifier = {
			factor = 0
			has_any_best_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}
	}
}

# Promote
start_promote_interaction = {
	icon = icon_scheme_promote
	interface_priority = 50
	category = interaction_category_admin

	send_name = START_SCHEME

	scheme = promote
	ignores_pending_interaction_block = yes

	ai_targets = {
		ai_recipients = self
 	}
	ai_targets = {
		ai_recipients = spouses
	}
	ai_targets = {
		ai_recipients = children
		max = 10
	}
	ai_targets = {
		ai_recipients = family
		max = 10
	}
	ai_targets = {
		ai_recipients = dynasty
		max = 10
	}
	ai_frequency = 60
	
	is_shown = {
		scope:actor = {
			is_adult = yes
			is_imprisoned = no
			government_allows = administrative
		}
		scope:recipient = {
			government_allows = administrative
			top_liege = scope:actor.top_liege
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			can_start_scheme = {
				type = promote
				target_character = scope:recipient
			}
		}
		scope:recipient = {
			is_adult = yes
			custom_tooltip = {
				text = is_in_line_of_succession
				any_heir_title = {
					exists = this
				}
			}
		}
	}

	desc = {
		triggered_desc = {
			trigger = {
				scope:actor = {
					can_start_scheme = {
						type = promote
						target_character = scope:recipient
					}
				}
			}
			desc = scheme_interaction_tt_promote_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_promote_interaction.tt.agent_focus_balance
	}
	## Focused on Success Chance.
	send_option = {
		flag = agent_focus_success
		current_description = start_promote_interaction.tt.agent_focus_success
	}
	## Focused on Speed.
	send_option = {
		flag = agent_focus_speed
		current_description = start_promote_interaction.tt.agent_focus_speed
	}

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

				left_icon = scope:actor					
				right_icon = scope:recipient

				# Success.
				if = {
					limit = { scope:agent_focus_success ?= yes }
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = promote
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
						# Success.
						AGENT_1 = agent_intermediary
						AGENT_2 = agent_proponent
						AGENT_3 = agent_proponent
						AGENT_4 = agent_sycophant
						# Speed.
						AGENT_5 = agent_political_socialite
					}
				}
				# Speed.
				else_if = {
					limit = { scope:agent_focus_speed ?= yes }
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = promote
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
						# Speed.
						AGENT_1 = agent_political_socialite
						AGENT_2 = agent_political_socialite
						AGENT_3 = agent_bureaucrat
						AGENT_4 = agent_bureaucrat
						# Success.
						AGENT_5 = agent_proponent
					}
				}
				# Balanced.
				else = {
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = promote
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
						# Success.
						AGENT_1 = agent_proponent
						AGENT_2 = agent_intermediary
						AGENT_3 = agent_sycophant
						# Speed.
						AGENT_4 = agent_political_socialite
						AGENT_5 = agent_bureaucrat
					}
				}
			}
			# Scheme bonuses from being the emperor/dominant family/powerful family
			ep3_actor_scheme_modifier_effect = yes
		}
		scope:recipient = { custom_tooltip = promote_scheme_success_tt }
	}

	ai_potential = {
		OR = {
			primary_title.tier >= tier_duchy
			AND = {
				this = house.house_head
				is_landless_administrative = yes
			}
		}
		NOT = {
			any_scheme = {
				is_scheme_category = hostile
			}
		}
	}
	
	auto_accept = yes

	ai_will_do = {
		base = 0

		#Competing candidate
		modifier = {
			scope:recipient = { is_competing_for_same_title_as = { CHARACTER = scope:actor } }
			add = -50
		}

		modifier = {
			scope:recipient = { is_winning_competing_for_same_title_as = { CHARACTER = scope:actor } }
			add = -75
		}

		#Personality
		modifier = {
			has_trait = gregarious
			add = 15
		}

		modifier = {
			has_trait = honest
			add = -10
		}

		modifier = {
			has_trait = shy
			add = -10
		}

		modifier = {
			has_trait = ambitious
			add = 20
		}

		# House & Family
		modifier = {
			is_close_family_of = scope:recipient
			add = 30
		}

		modifier = {
			is_parent_of = scope:recipient
			add = 50
		}

		modifier = {
			house = scope:recipient.house
			add = 50
		}

		modifier = {
			house.house_head = scope:recipient
			add = 50
		}

		#Feuds
		modifier = {
			house.house_head ?= {
				any_owned_story = {
					story_type = story_cycle_house_feud
					has_variable = house_feud_house
					var:house_feud_house = scope:recipient.house
				}
			}
			add = -100
		}

		# Relationships
		modifier = {
			add = -25
			has_any_mild_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}

		modifier = {
			add = -50
			has_any_moderate_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}

		modifier = {
			add = -100
			has_any_worst_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}

		modifier = {
			add = 25
			has_any_mild_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}

		modifier = {
			add = 50
			has_any_moderate_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}

		modifier = {
			add = 100
			has_any_best_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}
	}
}

# Generate Claim - used in laamp_help_fabricate_claim_contract landless adventurer task contract
start_generate_claim_interaction = {
	icon = icon_scheme_generate_claim
	interface_priority = 50
	category = interaction_category_laamp

	target_type = title
	target_filter = recipient_de_jure_titles

	can_be_picked_title = {
		scope:target = {
			custom_description = {
				text = adventurer_not_famous_trigger_tt
				value = scope:target.tier
				OR = {
					tier <= scope:actor.prestige_level
					tier = tier_county
				}
			}
			is_noble_family_title = no
			is_landless_type_title = no
		}
	}

	send_name = START_SCHEME

	scheme = generate_claim

	is_shown = {
		scope:actor = {
			any_character_active_contract = {
				has_task_contract_type = laamp_help_fabricate_claim_contract
				var:task_contract_target = scope:recipient
			}
		}
		NOT = {
			scope:recipient = scope:actor
		}
		scope:recipient = { is_landed = yes }
	}

	is_valid_showing_failures_only = {
	}

	desc = {
		triggered_desc = {
			trigger = {
				scope:recipient = {
					any_held_title = {
						scope:actor = {
							NOT = { has_claim_on = prev }
						}
						is_noble_family_title = no
						target_is_de_facto_liege_or_above = scope:actor.top_liege.primary_title
						tier >= tier_duchy
						save_temporary_scope_as = target
					}
				}
				scope:actor = {
					can_start_scheme = {
						type = generate_claim
						target_title = scope:target
					}
				}
			}
			desc = scheme_interaction_tt_generate_claim_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_generate_claim_interaction.tt.agent_focus_balance
	}
	## Focused on Success Chance.
	send_option = {
		flag = agent_focus_success
		current_description = start_generate_claim_interaction.tt.agent_focus_success
	}
	## Focused on Speed.
	send_option = {
		flag = agent_focus_speed
		current_description = start_generate_claim_interaction.tt.agent_focus_speed
	}
	## Focused on Secrecy.
	send_option = {
		flag = agent_focus_secrecy
		current_description = start_generate_claim_interaction.tt.agent_focus_secrecy
	}

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

				left_icon = scope:actor					
				right_icon = scope:recipient

				if = {
					limit = {
						any_character_active_contract = {
							has_task_contract_type = laamp_help_fabricate_claim_contract
							var:task_contract_target ?= scope:recipient
						}
					}
					random_character_active_contract = {
						limit = {
							has_task_contract_type = laamp_help_fabricate_claim_contract
							var:task_contract_target ?= scope:recipient
						}
						save_scope_as = scheme_contract
					}
					# Success.
					if = {
						limit = { scope:agent_focus_success ?= yes }
						begin_contract_scheme_with_agents_effect = {
							SCHEME_TYPE = generate_claim
							TARGET_TYPE = target_title
							TARGET_SCOPE = scope:target
							TASK_CONTRACT = scope:scheme_contract
							# Success.
							AGENT_1 = agent_scribe
							AGENT_2 = agent_scribe
							AGENT_3 = agent_diplomat
							# Speed.
							AGENT_4 = agent_justiciar_speed
							# Secrecy.
							AGENT_5 = agent_decoy
						}
					}
					# Speed.
					else_if = {
						limit = { scope:agent_focus_speed ?= yes }
						begin_contract_scheme_with_agents_effect = {
							SCHEME_TYPE = generate_claim
							TARGET_TYPE = target_title
							TARGET_SCOPE = scope:target
							TASK_CONTRACT = scope:scheme_contract
							# Speed.
							AGENT_1 = agent_justiciar_speed
							AGENT_2 = agent_infiltrator
							AGENT_3 = agent_socialite
							# Success.
							AGENT_4 = agent_scribe
							# Secrecy.
							AGENT_5 = agent_decoy
						}
					}
					# Secrecy.
					else_if = {
						limit = { scope:agent_focus_secrecy ?= yes }
						begin_contract_scheme_with_agents_effect = {
							SCHEME_TYPE = generate_claim
							TARGET_TYPE = target_title
							TARGET_SCOPE = scope:target
							TASK_CONTRACT = scope:scheme_contract
							# Secrecy.
							AGENT_1 = agent_decoy
							AGENT_2 = agent_decoy
							AGENT_3 = agent_alibi
							# Success.
							AGENT_4 = agent_scribe
							# Speed.
							AGENT_5 = agent_justiciar_speed
						}
					}
					# Balanced.
					else = {
						begin_contract_scheme_with_agents_effect = {
							SCHEME_TYPE = generate_claim
							TARGET_TYPE = target_title
							TARGET_SCOPE = scope:target
							TASK_CONTRACT = scope:scheme_contract
							# Success.
							AGENT_1 = agent_scribe
							AGENT_2 = agent_diplomat
							# Speed.
							AGENT_3 = agent_justiciar_speed
							AGENT_4 = agent_socialite
							# Secrecy.
							AGENT_5 = agent_decoy
						}
					}
				}
				else = {
					# Success.
					if = {
						limit = { scope:agent_focus_success ?= yes }
						begin_scheme_with_agents_effect = {
							SCHEME_TYPE = generate_claim
							TARGET_TYPE = target_title
							TARGET_SCOPE = scope:target
							# Success.
							AGENT_1 = agent_scribe
							AGENT_2 = agent_scribe
							AGENT_3 = agent_diplomat
							# Speed.
							AGENT_4 = agent_justiciar_speed
							# Secrecy.
							AGENT_5 = agent_decoy
						}
					}
					# Speed.
					else_if = {
						limit = { scope:agent_focus_speed ?= yes }
						begin_scheme_with_agents_effect = {
							SCHEME_TYPE = generate_claim
							TARGET_TYPE = target_title
							TARGET_SCOPE = scope:target
							# Speed.
							AGENT_1 = agent_justiciar_speed
							AGENT_2 = agent_infiltrator
							AGENT_3 = agent_socialite
							# Success.
							AGENT_4 = agent_scribe
							# Secrecy.
							AGENT_5 = agent_decoy
						}
					}
					# Secrecy.
					else_if = {
						limit = { scope:agent_focus_secrecy ?= yes }
						begin_scheme_with_agents_effect = {
							SCHEME_TYPE = generate_claim
							TARGET_TYPE = target_title
							TARGET_SCOPE = scope:target
							# Secrecy.
							AGENT_1 = agent_decoy
							AGENT_2 = agent_decoy
							AGENT_3 = agent_alibi
							# Success.
							AGENT_4 = agent_scribe
							# Speed.
							AGENT_5 = agent_justiciar_speed
						}
					}
					# Balanced.
					else = {
						begin_scheme_with_agents_effect = {
							SCHEME_TYPE = generate_claim
							TARGET_TYPE = target_title
							TARGET_SCOPE = scope:target
							# Success.
							AGENT_1 = agent_scribe
							AGENT_2 = agent_diplomat
							# Speed.
							AGENT_3 = agent_justiciar_speed
							AGENT_4 = agent_socialite
							# Secrecy.
							AGENT_5 = agent_decoy
						}
					}
				}
			}
		}
	}

	auto_accept = yes

	ai_will_do = {
		base = 5

		#Not a governor already
		modifier = {
			is_governor = no
			add = 30
		}

		#Personality
		modifier = {
			has_trait = ambitious
			add = 15
		}

		modifier = {
			has_trait = deceitful
			add = 15
		}

		modifier = {
			has_trait = honest
			add = -10
		}

		# House & Family
		modifier = {
			is_close_family_of = scope:recipient
			add = -10
		}

		#Feuds
		modifier = {
			house.house_head ?= {
				any_owned_story = {
					story_type = story_cycle_house_feud
					has_variable = house_feud_house
					var:house_feud_house = scope:recipient.house
				}
			}
			add = 50
		}

		# Relationships
		modifier = {
			add = 25
			has_any_mild_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}

		modifier = {
			add = 50
			has_any_moderate_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}

		modifier = {
			add = 100
			has_any_worst_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}

		modifier = {
			add = -25
			has_any_mild_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}

		modifier = {
			add = -50
			has_any_moderate_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}

		modifier = {
			factor = 0
			has_any_best_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}
	}
}

# Challenge Status
start_challenge_status_interaction = {
	icon = icon_scheme_challenge_status
	interface_priority = 80
	category = interaction_category_admin

	send_name = START_SCHEME

	scheme = challenge_status
	ignores_pending_interaction_block = yes

	ai_targets = {
		ai_recipients = peer_vassals
		max = 5
	}

	ai_frequency = 120
	
	is_shown = {
		scope:actor = {
			government_allows = administrative
		}
		scope:recipient != scope:actor
		scope:recipient = {
			government_allows = administrative
			top_liege = scope:actor.top_liege
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			is_adult = yes
			is_imprisoned = no
			can_start_scheme = {
				type = challenge_status
				target_character = scope:recipient
			}
		}
	}

	desc = {
		triggered_desc = {
			trigger = {
				scope:actor = {
					can_start_scheme = {
						type = challenge_status
						target_character = scope:recipient
					}
				}
			}
			desc = scheme_interaction_tt_challenge_status_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_challenge_status_interaction.tt.agent_focus_balance
	}
	## Focused on Success Chance.
	send_option = {
		flag = agent_focus_success
		current_description = start_challenge_status_interaction.tt.agent_focus_success
	}
	## Focused on Speed.
	send_option = {
		flag = agent_focus_speed
		current_description = start_challenge_status_interaction.tt.agent_focus_speed
	}

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

				left_icon = scope:actor
				right_icon = scope:recipient

				# Success.
				if = {
					limit = { scope:agent_focus_success ?= yes }
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = challenge_status
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
						# Success.
						AGENT_1 = agent_proponent
						AGENT_2 = agent_intermediary
						AGENT_3 = agent_sycophant
						# Speed.
						AGENT_4 = agent_political_socialite
						AGENT_5 = agent_bureaucrat
					}
				}
				# Speed.
				else_if = {
					limit = { scope:agent_focus_speed ?= yes }
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = challenge_status
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
						# Success.
						AGENT_1 = agent_proponent
						AGENT_2 = agent_intermediary
						# Speed.
						AGENT_3 = agent_political_socialite
						AGENT_4 = agent_bureaucrat
						AGENT_5 = agent_bureaucrat
					}
				}
				# Balanced.
				else = {
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = challenge_status
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
						# Success.
						AGENT_1 = agent_proponent
						AGENT_2 = agent_intermediary
						# Speed.
						AGENT_3 = agent_political_socialite
						AGENT_4 = agent_bureaucrat
						# Secrecy.
						AGENT_5 = agent_amanuensis
					}
				}
			}
			# Scheme bonuses from being the emperor/dominant family/powerful family
			ep3_actor_scheme_modifier_effect = yes
			custom_tooltip = challenge_status_success_actor_tt
		}
		scope:recipient = {
			save_scope_as = target
			custom_tooltip = challenge_status_success_recipient_tt
		}
	}

	ai_potential = {
		NOT = {
			any_scheme = {
				is_scheme_category = political
			}
		}
		government_allows = administrative
	}
	
	auto_accept = yes

	ai_will_do = {
		base = 5

		#Personality
		modifier = {
			has_trait = vengeful
			add = 15
		}

		modifier = {
			has_trait = deceitful
			add = 15
		}

		modifier = {
			has_trait = honest
			add = -10
		}

		# House & Family
		modifier = {
			is_close_family_of = scope:recipient
			add = -50
		}
		modifier = {
			house = scope:recipient.house
			add = -30
		}

		#Feuds
		modifier = {
			house.house_head ?= {
				any_owned_story = {
					story_type = story_cycle_house_feud
					has_variable = house_feud_house
					var:house_feud_house = scope:recipient.house
				}
			}
			add = 50
		}

		# Relationships
		modifier = {
			add = 25
			has_any_mild_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}

		modifier = {
			add = 50
			has_any_moderate_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}

		modifier = {
			add = 100
			has_any_worst_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}

		modifier = {
			add = -25
			has_any_mild_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}

		modifier = {
			add = -50
			has_any_moderate_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}

		modifier = {
			factor = 0
			has_any_best_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}
	}
}

# Expand Power Base
start_expand_power_base_interaction = {
	icon = icon_scheme_expand_power_base
	common_interaction = yes
	interface_priority = 70
	category = interaction_category_admin

	send_name = START_SCHEME

	scheme = expand_power_base
	ignores_pending_interaction_block = yes

	cooldown = { years = 10 }

	ai_frequency = 48
	ai_targets = {
		ai_recipients = self
	}
	
	is_shown = {
		scope:actor = {
			is_adult = yes
			is_imprisoned = no
			government_allows = administrative
			this = scope:recipient
			exists = house.house_head
			house.house_head = {
				any_held_title = {
					is_noble_family_title = yes
				}
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			can_start_scheme = {
				type = expand_power_base
				target_character = scope:actor
			}
		}
	}

	desc = scheme_interaction_tt_expand_power_base_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_expand_power_base_interaction.tt.agent_focus_balance
	}
	## Focused on Success Chance.
	send_option = {
		flag = agent_focus_success
		current_description = start_expand_power_base_interaction.tt.agent_focus_success
	}
	## Focused on Speed.
	send_option = {
		flag = agent_focus_speed
		current_description = start_expand_power_base_interaction.tt.agent_focus_speed
	}

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

				left_icon = scope:actor

				# Success.
				if = {
					limit = { scope:agent_focus_success ?= yes }
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = expand_power_base
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:actor
						# Success.
						AGENT_1 = agent_intermediary
						AGENT_2 = agent_proponent
						AGENT_3 = agent_proponent
						AGENT_4 = agent_sycophant
						# Speed.
						AGENT_5 = agent_bureaucrat
					}
				}
				# Speed.
				else_if = {
					limit = { scope:agent_focus_speed ?= yes }
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = expand_power_base
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:actor
						# Speed.
						AGENT_1 = agent_political_socialite
						AGENT_2 = agent_political_socialite
						AGENT_3 = agent_bureaucrat
						AGENT_4 = agent_bureaucrat
						# Success.
						AGENT_5 = agent_intermediary
					}
				}
				# Balanced.
				else = {
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = expand_power_base
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:actor
						# Success.
						AGENT_1 = agent_intermediary
						AGENT_2 = agent_proponent
						AGENT_3 = agent_sycophant
						# Speed.
						AGENT_4 = agent_political_socialite
						AGENT_5 = agent_bureaucrat
					}
				}
			}
			# Scheme progress bonus from education
			education_5_scheme_progress_effect = { SKILL = stewardship }
			# Scheme bonuses from being the emperor/dominant family/powerful family
			ep3_actor_scheme_modifier_effect = yes

			custom_tooltip = expand_power_base_effect_tt
		}
	}
	
	auto_accept = yes

	ai_will_do = {
		base = 0
		# The more I'm investing, the more I want my cap to increase
		modifier = {
			add = {
				value = 0
				every_succession_appointment_invested_candidate = {
					add = 5
				}
			}
		}

		#Not a governor
		modifier = {
			is_governor = no
			add = 30
		}

		#Personality
		modifier = {
			has_trait = ambitious
			add = 20
		}
	}
}

# Depose Scheme
start_depose_interaction = {
	icon = icon_scheme_depose
	interface_priority = 50
	category = interaction_category_admin

	send_name = START_SCHEME

	scheme = depose
	ignores_pending_interaction_block = yes

	ai_targets = {
		ai_recipients = liege
		max = 1
	}
	ai_frequency = 60
	
	is_shown = {
		has_ep3_dlc_trigger = yes
		scope:actor = { government_allows = administrative }
		scope:recipient = {
			government_allows = administrative
			primary_title.tier >= tier_empire # Target has to be the emperor
			this != scope:actor
			top_liege.primary_title = scope:actor.top_liege.primary_title # This hides the tooltip
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			is_adult = yes
			is_imprisoned = no
			custom_tooltip = {
				text = house_head_powerful_dominant_family_trigger
				house = {
					# Must be a powerful or dominant family
					OR = {
						is_powerful_family = yes
						is_dominant_family = yes
					}
				}
				# Must be the house head
				house.house_head = scope:actor
			}
			# Must not be from the same House as the Emperor 
			NOT = { house = scope:actor.top_liege.house }
			can_start_scheme = {
				type = depose
				target_character = scope:recipient
			}
		}
		scope:recipient = {
			NOT = { has_strong_hook = scope:actor }
		}
	}

	desc = scheme_interaction_tt_depose_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_depose_interaction.tt.agent_focus_balance
	}
	## Focused on Success Chance.
	send_option = {
		flag = agent_focus_success
		current_description = start_depose_interaction.tt.agent_focus_success
	}
	## Focused on Speed.
	send_option = {
		flag = agent_focus_speed
		current_description = start_depose_interaction.tt.agent_focus_speed
	}
	## Focused on Secrecy.
	send_option = {
		flag = agent_focus_secrecy
		current_description = start_depose_interaction.tt.agent_focus_secrecy
	}

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

				left_icon = scope:actor					
				right_icon = scope:recipient

				# Success.
				if = {
					limit = { scope:agent_focus_success ?= yes }
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = depose
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
						# Success.
						AGENT_1 = agent_intermediary
						AGENT_2 = agent_proponent
						AGENT_3 = agent_sycophant
						# Speed.
						AGENT_4 = agent_political_socialite
						# Secrecy.
						AGENT_5 = agent_courtesan
					}
				}
				# Speed.
				else_if = {
					limit = { scope:agent_focus_speed ?= yes }
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = depose
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
						# Speed.
						AGENT_1 = agent_political_socialite
						AGENT_2 = agent_political_socialite
						AGENT_3 = agent_bureaucrat
						# Success.
						AGENT_4 = agent_proponent
						# Secrecy.
						AGENT_5 = agent_courtesan
					}
				}
				# Secrecy.
				else_if = {
					limit = { scope:agent_focus_secrecy ?= yes }
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = depose
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
						# Secrecy.
						AGENT_1 = agent_courtesan
						AGENT_2 = agent_amanuensis
						AGENT_3 = agent_eunuch_speed
						# Success.
						AGENT_4 = agent_proponent
						# Speed.
						AGENT_5 = agent_political_socialite
					}
				}
				# Balanced.
				else = {
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = depose
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
						# Success.
						AGENT_1 = agent_intermediary
						AGENT_2 = agent_proponent
						# Speed.
						AGENT_3 = agent_political_socialite
						AGENT_4 = agent_bureaucrat
						# Secrecy.
						AGENT_5 = agent_courtesan
					}
				}
			}
			# Scheme bonuses from being the emperor/dominant family/powerful family
			ep3_actor_scheme_modifier_effect = yes

			stress_impact = {
				compassionate = minor_stress_impact_gain
				honest = minor_stress_impact_gain
				just = minor_stress_impact_gain
				loyal = major_stress_impact_gain
			}
		}
	}

	ai_potential = {
		OR = {
			primary_title.tier >= tier_duchy
			AND = {
				this = house.house_head
				is_landless_administrative = yes
			}
		}
		NOT = {
			any_scheme = {
				is_scheme_category = hostile
			}
		}
	}
	
	auto_accept = yes

	ai_will_do = {
		base = 0

		# Dominant Family
		modifier = {
			house = { is_dominant_family = yes }
			add = 50
		}

		#Personality
		modifier = {
			has_trait = ambitious
			add = 15
		}
		modifier = {
			has_trait = deceitful
			add = 15
		}
		modifier = {
			has_trait = honest
			add = -15
		}
		modifier = {
			has_trait = compassionate
			add = -15
		}
		modifier = {
			has_trait = just
			add = -10
		}

		#Feuds
		modifier = {
			house.house_head ?= {
				any_owned_story = {
					story_type = story_cycle_house_feud
					has_variable = house_feud_house
					var:house_feud_house = scope:recipient.house
				}
			}
			add = 50
		}

		# Relationships
		modifier = {
			add = 25
			has_any_mild_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}

		modifier = {
			add = 50
			has_any_moderate_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}

		modifier = {
			add = 100
			has_any_worst_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}

		modifier = {
			add = -25
			has_any_mild_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}

		modifier = {
			add = -50
			has_any_moderate_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}

		modifier = {
			factor = 0
			has_any_best_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}

		# House & Family
		modifier = { # Family and house members never want to depose each other
			OR = {
				is_close_family_of = scope:recipient
				AND = {
					exists = house
					NOT = { scope:recipient.house ?= house }
				}
			}
			NOR = { # Unless they are...
				has_trait = ambitious
				has_trait = greedy
				has_trait = deceitful
			}
			factor = 0
		}
		
		# Only depose if you dislike the target
		modifier = {
			opinion = { target = scope:recipient value > -30 }
			factor = 0
		}

		# EP3 Dynasty Legacy Perk Malus
		modifier = {
			add = -70
			scope:target.dynasty ?= { has_dynasty_perk = ep3_administrative_legacy_5 }
		}
	}
}

# Foster Legitimacy
start_foster_legitimacy_interaction = {
	icon = icon_scheme_foster_legitimacy
	interface_priority = 55
	common_interaction = yes
	category = interaction_category_admin

	send_name = START_SCHEME

	scheme = foster_legitimacy_scheme
	ignores_pending_interaction_block = yes

	ai_targets = {
		ai_recipients = liege
	}

	ai_frequency = 60
	
	is_shown = {
		scope:actor = {
			is_adult = yes
			is_imprisoned = no
			government_allows = administrative
		}

		NOT = {
			scope:recipient = scope:actor
		}

		scope:recipient = {
			this = scope:actor.liege
			is_adult = yes
			government_allows = administrative
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			can_start_scheme = {
				type = foster_legitimacy_scheme
				target_character = scope:recipient
			}
		}
	}

	desc = {
		triggered_desc = {
			trigger = {
				scope:actor = {
					can_start_scheme = {
						type = foster_legitimacy_scheme
						target_character = scope:recipient
					}
				}
			}
			desc = scheme_interaction_tt_foster_legitimacy_approved
		}
	}

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

				left_icon = scope:actor					
				right_icon = scope:recipient

				begin_scheme_basic_effect = {
					SCHEME_TYPE = foster_legitimacy_scheme
					TARGET_TYPE = target_character
					TARGET_SCOPE = scope:recipient
				}
			}
			# Scheme progress bonus from education
			education_5_scheme_progress_effect = { SKILL = diplomacy }
			# Scheme bonuses from being the emperor/dominant family/powerful family
			ep3_actor_scheme_modifier_effect = yes

			custom_tooltip = foster_legitimacy_positive_outcome_actor_tt
			custom_tooltip = foster_legitimacy_negative_outcome_tt
		}
		scope:recipient = {
			custom_tooltip = foster_legitimacy_positive_outcome_recipient_tt
		}
	}

	ai_potential = {
		is_governor = yes
		trigger_if = {
			limit = { exists = scope:recipient }
			opinion = {
				target = scope:recipient
				value > 0
			}
		}
		# Only try to foster legitimacy if they don't meet your expectations
		scope:recipient ?= {
			NOT = { meets_legitimacy_expectation_of = scope:actor }
		}
	}
	
	auto_accept = yes

	ai_will_do = {
		base = 0 # So the AI doesn't mess with your Legitimacy too often

		# Legitimacy Levels
		modifier = {
			scope:recipient.legitimacy_level >= 4
			add = -50
		}

		#Personality
		modifier = {
			has_lifestyle = diplomacy_lifestyle
			add = 15
		}
		
		modifier = {
			has_trait = loyal
			add = 15
		}
		
		modifier = {
			has_trait = disloyal
			add = -25
		}

		modifier = {
			has_trait = deceitful
			add = -15
		}

		# House & Family, but you need to get along
		modifier = {
			is_close_family_of = scope:recipient
			has_any_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
			add = 25
		}
		
		modifier = {
			house = scope:recipient.house
			has_any_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
			add = 15
		}

		# Relationships
		modifier = {
			add = -25
			has_any_mild_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}

		modifier = {
			add = -50
			has_any_moderate_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}

		modifier = {
			add = -100
			has_any_worst_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}
	}
}

# Damage Legitimacy
start_damage_legitimacy_interaction = {
	icon = icon_scheme_damage_legitimacy
	interface_priority = 50
	common_interaction = yes
	category = interaction_category_admin

	send_name = START_SCHEME

	scheme = damage_legitimacy_scheme
	ignores_pending_interaction_block = yes

	ai_targets = {
		ai_recipients = liege
	}

	ai_frequency = 60
	
	is_shown = {
		scope:actor = {
			is_adult = yes
			is_imprisoned = no
			government_allows = administrative
		}

		NOT = {
			scope:recipient = scope:actor
		}

		scope:recipient = {
			this = scope:actor.liege
			is_adult = yes
			government_allows = administrative
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			can_start_scheme = {
				type = damage_legitimacy_scheme
				target_character = scope:recipient
			}
		}
	}

	desc = {
		triggered_desc = {
			trigger = {
				scope:actor = {
					can_start_scheme = {
						type = damage_legitimacy_scheme
						target_character = scope:recipient
					}
				}
			}
			desc = scheme_interaction_tt_damage_legitimacy_approved
		}
	}

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

				left_icon = scope:actor					
				right_icon = scope:recipient

				begin_scheme_basic_effect = {
					SCHEME_TYPE = damage_legitimacy_scheme
					TARGET_TYPE = target_character
					TARGET_SCOPE = scope:recipient
				}
			}
			# Scheme progress bonus from education
			education_5_scheme_progress_effect = { SKILL = intrigue }
			# Scheme bonuses from being the emperor/dominant family/powerful family
			ep3_actor_scheme_modifier_effect = yes

			custom_tooltip = damage_legitimacy_negative_outcome_tt

			stress_impact = {
				loyal = major_stress_impact_gain
				honest = medium_stress_impact_gain
			}
		}
		scope:recipient = {
			custom_tooltip = damage_legitimacy_positive_outcome_tt
		}
	}

	ai_potential = {
		is_governor = yes
	}
	
	auto_accept = yes

	ai_will_do = {
		base = 0 # So the AI doesn't mess with your Legitimacy too often

		#Personality
		modifier = {
			has_lifestyle = intrigue_lifestyle
			add = 15
		}
		
		modifier = {
			has_trait = disloyal
			add = 15
		}
		
		modifier = {
			has_trait = deceitful
			add = 15
		}
		
		modifier = {
			has_trait = loyal
			add = -25
		}

		modifier = {
			has_trait = honest
			add = -15
		}
		
		# Relationships
		modifier = {
			add = -25
			has_any_moderate_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}
		
		modifier = {
			add = -50
			has_any_best_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}
		
		modifier = {
			add = 25
			has_any_mild_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}

		modifier = {
			add = 50
			has_any_moderate_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}

		modifier = {
			add = 75
			has_any_worst_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}
	}
}

# Dispute Border
start_dispute_border_interaction = {
	icon = icon_dispute_border
	interface_priority = 75
	category = interaction_category_admin 
	send_name = START_SCHEME 
	scheme = dispute_border
	ignores_pending_interaction_block = yes 
	ai_targets = { ai_recipients = peer_vassals } 
	ai_frequency = 60

	cooldown_against_recipient = { years = 5 }

	target_type = title
	target_filter = recipient_realm_titles

	can_be_picked_title = {
		scope:target = {
			ep3_boundary_dispute_county_trigger = {
				OWNER = scope:actor
				TARGET = scope:recipient
			}
		}
	}

	is_shown = {
		scope:actor = { is_governor = yes }
		scope:recipient = {
			this != scope:actor
			is_alive = yes
			top_liege = scope:actor.top_liege
			is_governor = yes
			in_diplomatic_range = scope:actor
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			is_available_adult = yes
			trigger_if = {
				limit = { exists = scope:target }
				can_start_scheme = {
					type = dispute_border
					target_title = scope:target
				}
			}
			custom_tooltip = {
				text = dispute_border_county_neighbour_tt
				character_is_realm_neighbor = scope:recipient
			}
			is_in_civil_war = no
			custom_tooltip = {
				text = admin_vassal_border_limit_desc
				top_liege ?= {
					NOT = { has_realm_law_flag = admin_vassal_border_limit }
				}
			}
			trigger_if = {
				limit = {
					top_liege ?= {
						NOT = { has_realm_law_flag = admin_vassal_border_limit }
						has_realm_law_flag = admin_vassal_border_restricted
					}
				}
				custom_tooltip = {
					text = interaction_must_be_powerful_or_dominant_family_tt
					house = {
						OR = {
							is_powerful_family = yes
							is_dominant_family = yes
						}
					}
				}
			}
		}
		scope:recipient = {
			is_in_civil_war = no
		}
	}

	desc = start_dispute_border_interaction_desc

	cost = {
		influence = {
			add = scope:actor.massive_influence_gain
		}
	}

	# Scheme Starter Packages
	options_heading = schemes.t.agent_packages
	send_options_exclusive = yes
	## Focused on Success Chance.
	send_option = {
		flag = agent_focus_success
		current_description = start_dispute_border_interaction.tt.agent_focus_success
	}
	## Focused on Speed.
	send_option = {
		flag = agent_focus_speed
		current_description = start_dispute_border_interaction.tt.agent_focus_speed
	}

	on_accept = {
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = start_dispute_border_notification
				left_icon = scope:recipient					
				right_icon = scope:target
				scope:recipient = {
					send_interface_toast = {
						type = event_toast_effect_bad
						title = start_dispute_border_notification
						left_icon = scope:actor					
						right_icon = scope:target
						scope:actor = {
							# Success.
							if = {
								limit = { scope:agent_focus_success ?= yes }
								begin_scheme_with_agents_effect = {
									SCHEME_TYPE = dispute_border
									TARGET_TYPE = target_title
									TARGET_SCOPE = scope:target
									# Success.
									AGENT_1 = agent_intermediary
									AGENT_2 = agent_proponent
									AGENT_3 = agent_sycophant
									# Speed.
									AGENT_4 = agent_political_socialite
									AGENT_5 = agent_bureaucrat
								}
							}
							# Speed.
							else = {
								begin_scheme_with_agents_effect = {
									SCHEME_TYPE = dispute_border
									TARGET_TYPE = target_title
									TARGET_SCOPE = scope:target
									# Success.
									AGENT_1 = agent_intermediary
									AGENT_2 = agent_proponent
									# Speed.
									AGENT_3 = agent_political_socialite
									AGENT_4 = agent_bureaucrat
									AGENT_5 = agent_bureaucrat
								}
							}
						}
					}
				}
			}
			random_scheme = {
				limit = {
					scheme_type = dispute_border
					scheme_target_title = scope:target
				}
				set_variable = {
					name = target_character
					value = scope:recipient
				}
			}
			# Scheme progress bonus from education
			education_5_scheme_progress_effect = { SKILL = diplomacy }
			# Scheme bonuses from being the emperor/dominant family/powerful family
			ep3_actor_scheme_modifier_effect = yes

			custom_tooltip = boundary_dispute_outcome_tt

			stress_impact = {
				content = medium_stress_impact_gain
			}
		}
		scope:recipient = {
			if = {
				limit = { is_ai = yes }
				add_opinion = {
					target = scope:actor
					modifier = attempted_dispute_border_opinion
				}
			}
		}
	}

	ai_potential = {
		NOT = {
			any_scheme = { is_scheme_category = political }
		}
		is_governor = yes
	}
	
	auto_accept = yes

	ai_will_do = {
		base = 0
		#Personality
		modifier = {
			has_trait = ambitious
			add = 15
		}
		modifier = {
			has_trait = content
			add = -15
		}
		# Land
		modifier = {
			scope:recipient = {
				any_sub_realm_county = {
					OR = {
						duchy.holder = scope:actor
						kingdom.holder = scope:actor
					}
				}
			}
		}
		# Relationships
		modifier = {
			add = -25
			has_any_moderate_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}
		modifier = {
			add = -50
			has_any_best_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}
		modifier = {
			add = 15
			has_any_mild_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}
		modifier = {
			add = 25
			has_any_moderate_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}
		modifier = {
			add = 50
			has_any_worst_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}
		# House
		modifier = {
			add = -50
			scope:recipient.house ?= scope:actor.house
		}
	}
}

# Subsume Province
start_subsume_province_interaction = {
	icon = icon_subsume_province
	common_interaction = yes
	interface_priority = 50
	category = interaction_category_admin 
	send_name = START_SCHEME 
	scheme = subsume_province
	ignores_pending_interaction_block = yes 
	ai_targets = { ai_recipients = peer_vassals } 
	ai_frequency = 60

	cooldown = { years = 5 }

	target_type = title
	target_filter = recipient_de_jure_titles

	can_be_picked_title = {
		scope:actor = {
			can_start_scheme = {
				type = subsume_province
				target_title = scope:target
			}
		}
	}

	has_valid_target_showing_failures_only = {
		scope:target = {
			tier = tier_duchy
			exists = holder
			holder = scope:recipient
		}
	}

	desc = start_subsume_province_interaction_desc

	is_shown = {
		scope:actor = { is_governor = yes }
		scope:recipient = {
			is_alive = yes
			top_liege = scope:actor.top_liege
			is_governor = yes
			NOR = { 
				this = scope:actor 
				scope:actor.house = scope:recipient.house
			}
			in_diplomatic_range = scope:actor
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			is_available_adult = yes
			trigger_if = {
				limit = { exists = scope:target }
				can_start_scheme = {
					type = subsume_province
					target_title = scope:target
				}
			}
			trigger_if = {
				limit = {
					top_liege ?= {
						NOT = { has_realm_law_flag = admin_vassal_border_limit }
					}
				}
				custom_tooltip = {
					text = interaction_must_be_powerful_or_dominant_family_tt
					house = {
						OR = {
							is_powerful_family = yes
							is_dominant_family = yes
						}
					}
				}
			}
			is_in_civil_war = no
			custom_tooltip = {
				text = admin_vassal_border_limit_desc
				top_liege ?= {
					NOT = { has_realm_law_flag = admin_vassal_border_limit }
				}
			}
		}
		scope:recipient = {
			custom_tooltip = {
				text = subsume_province_neighboring_duchy_tt
				any_sub_realm_county = {
					any_neighboring_county = {
						county_held_or_vassal_to_target_trigger = { TARGET = scope:actor }
					}
				}
			}
			custom_tooltip = {
				text = subsume_province_recipient_scheming_against_you_tt
				NOT = {
					is_scheming_against = {
						type = subsume_province
						target = scope:actor
					}
				}
			}
			custom_tooltip = {
				text = subsume_province_recipient_house_power_or_gov_efficiency_tt
				OR = {
					governor_efficiency_presented <= -25
					AND = {
						trigger_if = {
							limit = { house = { is_powerful_family = yes } }
							scope:actor.house = { is_dominant_family = yes }
						}
						house = { is_dominant_family = no }
					}
				}
			}
			is_in_civil_war = no
			NOT = { is_diarch_of_target = liege }
		}
	}

	is_highlighted = { scope:recipient.governor_efficiency_presented <= -25 }
	should_use_extra_icon = { scope:recipient.governor_efficiency_presented <= -25 }
	extra_icon = "gfx/interface/icons/character_interactions/icon_damage_efficiency.dds"

	cost = {
		influence = {
			add = {
				value = scope:actor.massive_influence_gain
				multiply = 4
			}
		}
	}

	# Scheme Starter Packages
	options_heading = schemes.t.agent_packages
	send_options_exclusive = yes
	## Focused on Success Chance.
	send_option = {
		flag = agent_focus_success
		current_description = start_subsume_province_interaction.tt.agent_focus_success
	}
	## Focused on Speed.
	send_option = {
		flag = agent_focus_speed
		current_description = start_subsume_province_interaction.tt.agent_focus_speed
	}

	on_accept = {
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = start_subsume_province_notification
				left_icon = scope:recipient					
				right_icon = scope:target
				scope:recipient = {
					send_interface_toast = {
						type = event_toast_effect_bad
						title = start_subsume_province_notification
						left_icon = scope:actor					
						right_icon = scope:target
						scope:actor = {
							# Success.
							if = {
								limit = { scope:agent_focus_success ?= yes }
								begin_scheme_with_agents_effect = {
									SCHEME_TYPE = subsume_province
									TARGET_TYPE = target_title
									TARGET_SCOPE = scope:target
									# Success.
									AGENT_1 = agent_intermediary
									AGENT_2 = agent_proponent
									AGENT_3 = agent_proponent
									# Speed.
									AGENT_4 = agent_political_socialite
									AGENT_5 = agent_political_socialite
								}
							}
							# Speed.
							else = {
								begin_scheme_with_agents_effect = {
									SCHEME_TYPE = subsume_province
									TARGET_TYPE = target_title
									TARGET_SCOPE = scope:target
									# Success.
									AGENT_1 = agent_intermediary
									AGENT_2 = agent_proponent
									# Speed.
									AGENT_3 = agent_political_socialite
									AGENT_4 = agent_political_socialite
									AGENT_5 = agent_political_socialite
								}
							}
						}
					}
				}
			}
			random_scheme = {
				limit = {
					scheme_type = subsume_province
					scheme_target_title = scope:target
				}
				set_variable = {
					name = target_character
					value = scope:recipient
				}
			}
			# Scheme progress bonus from education
			education_5_scheme_progress_effect = { SKILL = diplomacy }
			# Scheme bonuses from being the emperor/dominant family/powerful family
			ep3_actor_scheme_modifier_effect = yes
			custom_tooltip = subsume_province_scheme_success_outcome_tt
			stress_impact = {
				content = medium_stress_impact_gain
			}
		}
		scope:recipient = {
			if = {
				limit = { is_ai = yes }
				add_opinion = {
					target = scope:actor
					modifier = attempted_subsume_province_opinion
				}
			}
		}
	}

	ai_potential = {
		NOT = {
			any_scheme = { is_scheme_category = political }
		}
		is_governor = yes
	}
	
	auto_accept = yes

	ai_will_do = {
		base = 0

		#Personality
		modifier = {
			has_trait = ambitious
			add = 15
		}
		modifier = {
			has_trait = content
			add = -15
		}
		# Land
		modifier = {
			scope:recipient = {
				any_sub_realm_county = {
					OR = {
						duchy.holder = scope:actor
						kingdom.holder = scope:actor
					}
				}
			}
		}
		# Relationships
		modifier = {
			add = -25
			has_any_moderate_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}
		modifier = {
			add = -50
			has_any_best_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}
		modifier = {
			add = 15
			has_any_mild_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}
		modifier = {
			add = 25
			has_any_moderate_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}
		modifier = {
			add = 50
			has_any_worst_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}
		# House
		modifier = {
			add = -50
			scope:recipient.house ?= scope:actor.house
		}
	}
}

# Found Despotate
start_found_despotate_interaction = {
	icon = icon_found_despotate
	interface_priority = 60
	common_interaction = yes
	category = interaction_category_admin 
	send_name = START_SCHEME 
	scheme = found_despotate
	ignores_pending_interaction_block = yes  
	ai_frequency = 60
	ai_targets = { ai_recipients = self }

	target_type = title
	target_filter = secondary_recipient_de_jure_titles

	can_be_picked_title = {
		scope:target ?= {
			custom_tooltip = {
				text = found_despotate_existing_scheme_tt
				NOT = {
					scope:actor.top_liege = {
						any_vassal = {
							any_scheme = {
								scheme_type = found_despotate
								scheme_target_title = scope:target
							}
						}
					}
				}
			}
			trigger_if = {
				limit = { tier = tier_kingdom }
				custom_tooltip = {
					text = found_despotate_hold_duchy_tt
					any_direct_de_jure_vassal_title = { holder = scope:actor }
				}
				custom_tooltip = {
					text = found_despotate_hold_county_tt
					any_de_jure_county = { holder = scope:actor }
				}
			}
			is_landless_type_title = no
			NOT = { holder ?= scope:actor }
			is_title_created = no
			scope:recipient.top_liege = { completely_controls = scope:target }
		}
	}
	
	has_valid_target_showing_failures_only = {
		scope:target = {
			tier = tier_kingdom
		}
	}
	
	# We do this via redirects because recipient_de_jure_titles did not turn up for work today.
	redirect = {
		scope:actor = {
			top_liege ?= { save_scope_as = secondary_recipient }
			if = {
				limit = { 
					exists = primary_title.kingdom
					primary_title.tier = tier_duchy
				}
				primary_title.kingdom = { save_scope_as = target }
			}
		}
	}

	cooldown = { years = 5 }

	is_shown = {
		scope:actor = { is_governor = yes }
		scope:recipient = scope:actor
	}

	is_valid_showing_failures_only = {
		#If kingdom primary title kingdom has more than one duchy, needs to have two duchies
		trigger_if = {
			limit = {
				scope:actor = {
					is_ruler = yes
					primary_title.kingdom = {
						any_in_de_jure_hierarchy = {
							count >= 2
							tier = tier_duchy
							is_landless_type_title = no
						}
					}
				}
			}
			custom_tooltip = {
				text = 2_or_more_governorships_tt
				scope:actor = {
					any_held_title = {
						count >= 2
						tier = tier_duchy
						is_landless_type_title = no
					}
				}
				
			}
		}
		scope:actor = {
			is_adult = yes
			is_imprisoned = no
			highest_held_title_tier < tier_kingdom
			custom_tooltip = {
				text = interaction_must_be_powerful_or_dominant_family_tt
				exists = house
				house = {
					OR = {
						is_powerful_family = yes
						is_dominant_family = yes
					}
				}
			}
			custom_tooltip = {
				text = influence_level_3_tt
				influence_level >= 3
			}
		}
		scope:secondary_recipient.primary_title ?= {
			any_direct_de_jure_vassal_title = {
				tier = tier_kingdom
				is_landless_type_title = no
				custom_tooltip = {
					text = found_despotate_hold_duchy_tt
					any_direct_de_jure_vassal_title = { holder = scope:actor }
				}
				NOT = { holder ?= scope:actor }
				is_title_created = no
			}
		}
		custom_tooltip = {
			text = found_despotate_existing_scheme_tt
			NOT = {
				scope:actor.top_liege = {
					any_vassal = {
						any_scheme = {
							scheme_type = found_despotate
							scheme_target_title = scope:actor.primary_title.kingdom
						}
					}
				}
			}
		}
		custom_tooltip = {
			text = found_despotate_percent_controlled_tt
			scope:actor.primary_title.kingdom = {
				any_de_jure_county = {
					percent >= 0.25
					county_held_or_vassal_to_target_trigger = { TARGET = scope:actor }
				}
			}
		}
		trigger_if = {
			limit = {
				exists = scope:target
				scope:actor.liege.diarch ?= {
					any_held_title = {
						any_this_title_or_de_jure_above = { this = scope:target }
					}
				}
			}
			scope:actor.liege.diarch = {
				NOT = { is_diarch_of_target = liege }
			}
		}
	}

	desc = start_found_despotate_interaction_desc

	cost = {
		influence = {
			add = scope:actor.massive_influence_value
		}
	}

	# Scheme Starter Packages
	options_heading = schemes.t.agent_packages
	send_options_exclusive = yes
	## Focused on Success Chance.
	send_option = {
		flag = agent_focus_success
		current_description = start_found_despotate_interaction.tt.agent_focus_success
	}
	## Focused on Speed.
	send_option = {
		flag = agent_focus_speed
		current_description = start_found_despotate_interaction.tt.agent_focus_speed
	}

	on_accept = {
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = start_found_despotate_notification
				left_icon = scope:recipient					
				right_icon = scope:target
				scope:recipient = {
					send_interface_toast = {
						type = event_toast_effect_bad
						title = start_found_despotate_notification
						left_icon = scope:actor					
						right_icon = scope:target
						scope:actor = {
							# Success.
							if = {
								limit = { scope:agent_focus_success ?= yes }
								begin_scheme_with_agents_effect = {
									SCHEME_TYPE = found_despotate
									TARGET_TYPE = target_title
									TARGET_SCOPE = scope:target
									# Success.
									AGENT_1 = agent_intermediary
									AGENT_2 = agent_proponent
									AGENT_3 = agent_sycophant
									# Speed.
									AGENT_4 = agent_political_socialite
									AGENT_5 = agent_political_socialite
								}
							}
							# Speed.
							else = {
								begin_scheme_with_agents_effect = {
									SCHEME_TYPE = found_despotate
									TARGET_TYPE = target_title
									TARGET_SCOPE = scope:target
									# Success.
									AGENT_1 = agent_intermediary
									AGENT_2 = agent_proponent
									# Speed.
									AGENT_3 = agent_political_socialite
									AGENT_4 = agent_political_socialite
									AGENT_5 = agent_political_socialite
								}
							}
						}
					}
				}
			}
			# Scheme progress bonus from education
			education_5_scheme_progress_effect = { SKILL = diplomacy }
			# Scheme bonuses from being the emperor/dominant family/powerful family
			ep3_actor_scheme_modifier_effect = yes

			custom_tooltip = found_despotate_success_tt

			stress_impact = {
				content = minor_stress_impact_gain
				humble = minor_stress_impact_gain
			}
		}
	}

	ai_potential = {
		has_trait = ambitious
		is_governor = yes
		NOR = {
			has_trait = content
			any_scheme = { is_scheme_category = political }
		}
	}
	
	auto_accept = yes

	ai_will_do = {
		base = 15
	}
}

# Raid Estate
start_raid_estate_interaction = {
	icon = icon_raid_estate
	interface_priority = 90
	category = interaction_category_admin
	send_name = START_SCHEME 
	scheme = raid_estate
	ignores_pending_interaction_block = yes  
	ai_frequency = 60

	ai_targets = { ai_recipients = liege }
	ai_targets = {
		ai_recipients = peer_vassals
		max = 20
	}
	ai_targets = {
		ai_recipients = vassals
		max = 20
	}

	cooldown = { years = 5 }

	highlighted_reason = start_raid_estate_interaction_HIGHLIGHTED

	is_highlighted = { scope:actor.var:raid_estate_permission ?= scope:recipient.house }

	is_shown = {
		scope:actor = { government_allows = administrative }
		scope:recipient.house.house_head ?= {
			exists = house
			NOT = { house = scope:actor.house }
			top_liege = scope:actor.top_liege
			government_allows = administrative
			any_held_title = { is_noble_family_title = yes }
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			is_available_adult = yes
			custom_tooltip = {
				text = raid_estate_noble_family_tt
				any_held_title = { is_noble_family_title = yes }
				house.house_head ?= this
			}
		}
		scope:recipient.house.house_head ?= {
			custom_tooltip = {
				text = raid_estate_noble_family_target_tt
				any_held_title = { is_noble_family_title = yes }
			}
			custom_tooltip = {
				text = raid_estate_estate_tt
				domicile ?= { is_domicile_type = estate }
			}
		}
	}

	desc = start_raid_estate_interaction_desc

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

	on_accept = {
		scope:recipient = { 
			custom_tooltip = raid_estate_kill_maim_imprison_house_members_tt
			custom_tooltip = raid_estate_destroy_buildings_tt
			custom_tooltip = raid_estate_house_modifier_tt
			random_held_title = {
				limit = { is_noble_family_title = yes }
				save_scope_as = target_title
			}
		}
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = start_raid_estate_notification
				left_icon = scope:recipient					
				right_icon = scope:target_title
				# Success.
				if = {
					limit = { scope:agent_focus_success ?= yes }
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = raid_estate
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
						# Success.
						AGENT_1 = agent_scout
						AGENT_2 = agent_scout
						AGENT_3 = agent_muscle
						# Speed.
						AGENT_4 = agent_infiltrator
						# Secrecy.
						AGENT_5 = agent_lookout
					}
				}
				# Speed.
				else_if = {
					limit = { scope:agent_focus_speed ?= yes }
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = raid_estate
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
						# Speed.
						AGENT_1 = agent_infiltrator
						AGENT_2 = agent_infiltrator
						AGENT_3 = agent_footpad
						# Success.
						AGENT_4 = agent_scout
						# Secrecy.
						AGENT_5 = agent_lookout
					}
				}
				# Secrecy.
				else_if = {
					limit = { scope:agent_focus_secrecy ?= yes }
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = raid_estate
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
						# Secrecy.
						AGENT_1 = agent_lookout
						AGENT_2 = agent_lookout
						AGENT_3 = agent_alibi
						# Success.
						AGENT_4 = agent_scout
						# Speed.
						AGENT_5 = agent_infiltrator
					}
				}
				# Balanced.
				else = {
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = raid_estate
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
						# Success.
						AGENT_1 = agent_scout
						AGENT_2 = agent_muscle
						# Speed.
						AGENT_3 = agent_infiltrator
						AGENT_4 = agent_footpad
						# Secrecy.
						AGENT_5 = agent_lookout
					}
				}
			}
			# Scheme progress bonus from education
			education_5_scheme_progress_effect = { SKILL = intrigue }
			# Scheme bonuses from being the emperor/dominant family/powerful family
			ep3_actor_scheme_modifier_effect = yes

			custom_tooltip = raid_estate_gain_coin_tt
			if = {
				limit = {
					has_relation_rival = scope:recipient
				}
				custom_tooltip = raid_estate_nemesis_relation_tt
			}
			else = {
				custom_tooltip = raid_estate_rival_relation_tt
			}

			stress_impact = {
				content = medium_stress_impact_gain
			}
			if = {
				limit = {
					has_relation_nemesis = scope:recipient
				}
				stress_impact = { base = major_stress_impact_loss }
			}
			else_if = {
				limit = {
					has_relation_rival = scope:recipient
				}
				stress_impact = { base = medium_stress_impact_loss }
			}
		}
	}

	ai_potential = {
		NOT = {
			any_scheme = { is_hostile = yes }
		}
		any_held_title = { is_noble_family_title = yes }
	}
	
	auto_accept = yes

	ai_will_do = {
		base = -20
		#Personality
		modifier = {
			has_trait = vengeful
			add = 15
		}
		modifier = {
			has_trait = forgiving
			add = -15
		}
		modifier = {
			has_trait = brave
			add = 15
		}
		modifier = {
			has_trait = craven
			add = -15
		}
		# Relationships
		modifier = {
			add = -25
			has_any_moderate_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}
		modifier = {
			add = -50
			has_any_best_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}
		modifier = {
			add = 15
			has_any_mild_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}
		modifier = {
			add = 25
			has_any_moderate_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}
		modifier = {
			add = 50
			has_any_worst_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}
		modifier = {
			scope:recipient.house = scope:actor.top_liege.house
			add = -25
		}
		opinion_modifier = {
			who = scope:actor
			opinion_target = scope:recipient
			multiplier = -0.25
		}
	}
}

# Teach Governor - AKA Mentor in Governance/mentor_in_governance
start_teach_governor_interaction = {
	icon = icon_teach_governor
	interface_priority = 50
	category = interaction_category_admin
	send_name = START_SCHEME 
	scheme = teach_governor
	ai_targets = {
		ai_recipients = peer_vassals
		max = 20
	}
	ai_targets = {
		ai_recipients = vassals
		max = 10
	}

	ai_frequency = 60

	notification_text = TEACH_GOVERNOR_NOTIFICATION
	ai_min_reply_days = 4
	ai_max_reply_days = 9

	cooldown_against_recipient = { years = 15 }

	is_shown = {
		scope:actor = { government_allows = administrative }
		scope:recipient != scope:actor
		scope:recipient = {
			is_alive = yes
			top_liege = scope:actor.top_liege
			in_diplomatic_range = scope:actor
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			can_start_scheme = {
				type = teach_governor
				target_character = scope:recipient
			}
			custom_tooltip = {
				text = teach_governor_maximum_xp_tt
				scope:recipient = { has_trait_xp = { trait = governor value < 95 } }
			}
			custom_tooltip = {
				text = teach_governor_minimum_xp_tt
				scope:recipient = {
					trigger_if = {
						limit = { has_trait_xp = { trait = governor value >= 100 } }
						scope:actor = { has_trait_xp = { trait = governor value >= 75 } }
					}
					trigger_else_if = {
						limit = { has_trait_xp = { trait = governor value >= 75 } }
						scope:actor = { has_trait_xp = { trait = governor value >= 50 } }
					}
					trigger_else_if = {
						limit = { has_trait_xp = { trait = governor value >= 50 } }
						scope:actor = { has_trait_xp = { trait = governor value >= 25 } }
					}
					trigger_else = { always = yes }
				}
			}
		}
	}

	desc = start_teach_governor_interaction_desc

	cost = {
		influence = { add = scope:actor.minor_influence_gain }
	}

	on_accept = {
		scope:actor = {
			custom_tooltip = teach_governor_actor_reward_tt
			stress_impact = {
				humble = minor_stress_impact_gain
				lazy = medium_stress_impact_gain
			}
			trigger_event = scheme_critical_moments.8045
		}
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = start_teach_governor_notification
				left_icon = scope:recipient					
				right_icon = scope:recipient.primary_title
				scope:recipient = {
					send_interface_toast = {
						type = event_toast_effect_bad
						title = start_teach_governor_notification
						left_icon = scope:actor					
						right_icon = scope:actor.primary_title
						scope:actor = {
							begin_scheme_basic_effect = {
								SCHEME_TYPE = teach_governor
								TARGET_TYPE = target_character
								TARGET_SCOPE = scope:recipient
							}
						}
					}
				}
			}
			# Scheme progress bonus from education
			education_5_scheme_progress_effect = { SKILL = stewardship }
			# Scheme bonuses from being the emperor/dominant family/powerful family
			ep3_actor_scheme_modifier_effect = yes
		}
		scope:recipient = {
			if = {
				limit = { is_ai = yes }
				add_opinion = {
					target = scope:actor
					modifier = mentoring_governor_opinion
				}
			}
			custom_tooltip = teach_governor_recipient_reward_tt
		}
	}

	on_decline = {
		scope:actor = {
			if = {
				limit = { is_ai = yes }
				add_opinion = {
					target = scope:recipient
					modifier = insulted_opinion
					opinion = -10
				}
			}
			else = { trigger_event = scheme_critical_moments.8046 }
		}
	}

	ai_potential = {
		NOR = {
			has_trait = lazy
			scheme_generic_ai_blocker_trigger = yes
		}
		is_governor = yes
	}

	ai_accept = {
		base = 0
		opinion_modifier = {
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 0.25
		}
		# Experience
		modifier = {
			desc = RELATIVE_GOVERNOR_EFFICIENCY
			add = {
				value = ep3_actor_recipient_governor_trait_level_diff_value
				subtract = 1
				multiply = 15
			}
		}
		modifier = { # If you are from a powerful family, and they are not, they are more likely to accept
			scope:actor.house ?= { is_powerful_family = yes }
			house ?= {
				is_powerful_family = no
				is_dominant_family = no
			}
			add = 15
			desc = your_house_is_powerful_reason
		}
		modifier = { # If you are from a dominant family, and they are not, they are more likely to accept
			scope:actor.house ?= { is_dominant_family = yes }
			house ?= { is_dominant_family = no }
			add = 25
			desc = your_house_is_dominant_reason
		}
		modifier = { # If they are from a powerful family, and you are not, they are more likely to refuse
			house ?= { is_powerful_family = yes }
			scope:actor.house ?= {
				is_powerful_family = no
				is_dominant_family = no
			}
			add = -15
			desc = their_house_is_powerful_reason
		}
		modifier = { # If they are from a dominant family, and you are not, they are more likely to refuse
			house ?= { is_dominant_family = yes }
			scope:actor.house ?= { is_dominant_family = no }
			add = -25
			desc = their_house_is_dominant_reason
		}
		modifier = { # Difference in influence level
			influence_level != scope:actor.influence_level
			add = {
				add = {
					add = 10
					multiply = scope:recipient.influence_level
				}
				subtract = {
					add = 10
					multiply = scope:actor.influence_level
				}
			}
			desc = difference_in_influence_level_reason
		}
		modifier = {
			scope:actor = {
				exists = house
			}
			scope:recipient = {
				exists = house
			}
			exists = scope:actor.house.house_head.top_liege
			house.house_head.top_liege ?= scope:actor.house.house_head.top_liege
			add = {
				value = scope:actor.house.house_power_score
				subtract = scope:recipient.house.house_power_score
				divide = 4
				floor = yes
			}
			desc = RELATIVE_FAMILY_RATING
		}
		# Relations
		modifier = { # Friend
			desc = offer_vassalization_interaction_aibehavior_friend_tt
			has_relation_friend = scope:actor
			NOT = { has_relation_best_friend = scope:actor }
			add = 15
		}
		modifier = { # Best Friend
			desc = offer_vassalization_interaction_aibehavior_best_friend_tt
			has_relation_best_friend = scope:actor
			add = 30
		}
		modifier = { # Rival 
			desc = offer_vassalization_interaction_aibehavior_rival_tt
			has_relation_rival = scope:actor
			NOT = { has_relation_nemesis = scope:actor }
			add = -25
		}
		modifier = { # Nemesis
			desc = offer_vassalization_interaction_aibehavior_nemesis_tt
			has_relation_nemesis = scope:actor
			add = -50
		}
		modifier = {
			is_close_family_of = scope:actor
			add = 50
			desc = CLOSE_FAMILY_REASON
		}
		modifier = {
			is_extended_family_of = scope:actor
			add = 25
			desc = EXTENDED_FAMILY_REASON
		}
		modifier = {
			NOR = {
				is_close_family_of = scope:actor
				is_extended_family_of = scope:actor
			}
			house ?= scope:actor.house
			add = 5
			desc = YOU_ARE_MY_HOUSE_MEMBER
		}
		#Age
		modifier = {
			desc = AGE_DIFFERENCE
			add = {
				value = scope:actor.age
				add = {
					value = scope:recipient.age
					multiply = -1
				}
			}
		}
		# Traits
		modifier = {
			has_trait = ambitious
			add = 10
			desc = INTERACTION_AMBITIOUS
		}
		modifier = {
			has_trait = diligent
			add = 10
			desc = INTERACTION_DILIGENT
		}
		modifier = {
			has_trait = humble
			add = 10
			desc = INTERACTION_HUMBLE
		}
		modifier = {
			has_trait = content
			add = -10
			desc = INTERACTION_CONTENT
		}
		modifier = {
			has_trait = lazy
			add = -10
			desc = INTERACTION_LAZY
		}
		modifier = {
			has_trait = arrogant
			add = -10
			desc = INTERACTION_ARROGANT
		}
		#Feuds
		modifier = {
			house.house_head ?= {
				any_owned_story = {
					story_type = story_cycle_house_feud
					has_variable = house_feud_house
					var:house_feud_house = scope:actor.house
				}
			}
			add = -50
		}
	}

	ai_will_do = {
		base = -25
		#Personality
		modifier = {
			has_trait = diligent
			add = 15
		}
		modifier = {
			has_trait = generous
			add = 15
		}
		modifier = {
			has_trait = lazy
			add = -15
		}
		modifier = {
			has_trait = greedy
			add = -15
		}
		# Relationships
		modifier = {
			add = 25
			has_any_moderate_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}
		modifier = {
			add = 50
			has_any_best_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}
		modifier = {
			add = -15
			has_any_mild_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}
		modifier = {
			add = -25
			has_any_moderate_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}
		modifier = {
			add = -50
			has_any_worst_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}
		# House
		modifier = {
			add = 5
			scope:recipient.house ?= scope:actor.house
		}
		# Family
		modifier = {
			add = 10
			scope:actor = { is_parent_of = scope:recipient }
		}
		modifier = {
			add = 5
			scope:actor = { is_close_family_of = scope:recipient }
		}
		#Feuds
		modifier = {
			house.house_head ?= {
				any_owned_story = {
					story_type = story_cycle_house_feud
					has_variable = house_feud_house
					var:house_feud_house = scope:recipient.house
				}
			}
			add = -50
		}
	}
}

# Ingratiate Family
start_ingratiate_family_interaction = {
	icon = icon_ingratiate_family
	interface_priority = 50
	category = interaction_category_admin
	send_name = START_SCHEME
	scheme = ingratiate_family
	ignores_pending_interaction_block = yes

	ai_targets = {
		ai_recipients = peer_vassals
		max = 20
	}
	ai_frequency = 36
	
	is_shown = {
		scope:actor = {
			is_adult = yes
			is_imprisoned = no
			is_incapable = no
			any_held_title = { is_noble_family_title = yes }
			house.house_head ?= this
		}
		scope:recipient = {
			is_adult = yes
			is_imprisoned = no
			is_incapable = no
			any_held_title = { is_noble_family_title = yes }
			house.house_head ?= this
			NOT = { house = scope:actor.house }
			top_liege = scope:actor.top_liege
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			can_start_scheme = {
				type = ingratiate_family
				target_character = scope:recipient
			}
		}
	}
 	
 	desc = start_ingratiate_family_interaction_desc

	on_accept = {
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = start_ingratiate_family_notification
				left_icon = scope:recipient

				begin_scheme_basic_effect = {
					SCHEME_TYPE = ingratiate_family
					TARGET_TYPE = target_character
					TARGET_SCOPE = scope:recipient
				}
				scope:recipient = {
					if = {
						limit = { is_ai = yes }
						add_opinion = {
							modifier = ingratiating_family_opinion
							target = scope:actor
						}
					}
				}
				show_as_tooltip = {
					stress_impact = {
						arrogant = minor_stress_impact_gain
						shy = minor_stress_impact_gain
					}
				}
			}
			
			if = { # I am the emperor
				limit = { scope:actor.highest_held_title_tier >= tier_empire }
				custom_tooltip = {
					text = admin_emperor_scheme_modifier_tt
					random_scheme = {
						limit = {
							scheme_type = ingratiate_family
							scheme_target_character	= scope:recipient
						}
						add_scheme_modifier = { type = admin_emperor_scheme_modifier }
					}
				}
			}
			else_if = { # I am a dominant family
				limit = {
					scope:actor.house ?= { is_dominant_family = yes }
				}
				custom_tooltip = {
					text = admin_dominant_family_scheme_modifier_tt
					random_scheme = {
						limit = {
							scheme_type = ingratiate_family
							scheme_target_character	= scope:recipient
						}
						add_scheme_modifier = { type = admin_dominant_family_scheme_modifier }
					}
				}
				if = {
					limit = { scope:recipient.highest_held_title_tier >= tier_empire }
					custom_tooltip = {
						text = admin_target_emperor_scheme_modifier_tt
						random_scheme = {
							limit = {
								scheme_type = ingratiate_family
								scheme_target_character	= scope:recipient
							}
							add_scheme_modifier = { type = admin_target_emperor_scheme_modifier }
						}
					}
				}
			}
			else_if = { # I am a powerful family
				limit = {
					scope:actor.house ?= { is_powerful_family = yes }
				}
				custom_tooltip = {
					text = admin_powerful_family_scheme_modifier_tt
					random_scheme = {
						limit = {
							scheme_type = ingratiate_family
							scheme_target_character	= scope:recipient
						}
						add_scheme_modifier = { type = admin_powerful_family_scheme_modifier }
					}
				}
				if = {
					limit = { scope:recipient.highest_held_title_tier >= tier_empire }
					custom_tooltip = {
						text = admin_target_emperor_scheme_modifier_tt
						random_scheme = {
							limit = {
								scheme_type = ingratiate_family
								scheme_target_character	= scope:recipient
							}
							add_scheme_modifier = { type = admin_target_emperor_scheme_modifier }
						}
					}
				}
				else_if = {
					limit = { scope:recipient.house ?= { is_dominant_family = yes } }
					custom_tooltip = {
						text = admin_target_dominant_family_scheme_modifier_tt
						random_scheme = {
							limit = {
								scheme_type = ingratiate_family
								scheme_target_character	= scope:recipient
							}
							add_scheme_modifier = { type = admin_target_dominant_family_scheme_modifier }
						}
					}
				}
			}
			else = { # I am NOT a powerful or dominant family or the emperor
				if = {
					limit = { scope:recipient.highest_held_title_tier >= tier_empire }
					custom_tooltip = {
						text = admin_target_emperor_scheme_modifier_tt
						random_scheme = {
							limit = {
								scheme_type = ingratiate_family
								scheme_target_character	= scope:recipient
							}
							add_scheme_modifier = { type = admin_target_emperor_scheme_modifier }
						}
					}
				}
				else_if = {
					limit = { scope:recipient.house ?= { is_dominant_family = yes } }
					custom_tooltip = {
						text = admin_target_dominant_family_scheme_modifier_tt
						random_scheme = {
							limit = {
								scheme_type = ingratiate_family
								scheme_target_character	= scope:recipient
							}
							add_scheme_modifier = { type = admin_target_dominant_family_scheme_modifier }
						}
					}
				}
				else_if = {
					limit = { scope:recipient.house ?= { is_powerful_family = yes } }
					custom_tooltip = {
						text = admin_target_powerful_family_scheme_modifier_tt
						random_scheme = {
							limit = {
								scheme_type = ingratiate_family
								scheme_target_character	= scope:recipient
							}
							add_scheme_modifier = { type = admin_target_powerful_family_scheme_modifier }
						}	
					}
				}
			}

			custom_tooltip = ingratiate_family_success_actor_tt
			stress_impact = {
				arrogant = minor_stress_impact_gain
				shy = minor_stress_impact_gain
			}
		}
		scope:recipient = {
			custom_tooltip = ingratiate_family_success_recipient_tt
		}
	}

	ai_potential = {
		NOT = {
			any_scheme = {
				is_scheme_category = hostile
			}
		}
	}
	
	auto_accept = yes

	ai_will_do = {
		base = 5

		#Competing candidate
		modifier = {
			scope:recipient = { is_competing_for_same_title_as = { CHARACTER = scope:actor } }
			add = -50
		}

		modifier = {
			scope:recipient = { is_winning_competing_for_same_title_as = { CHARACTER = scope:actor } }
			add = -75
		}

		#Personality
		modifier = {
			has_trait = ambitious
			add = 15
		}

		modifier = {
			has_trait = deceitful
			add = 15
		}

		modifier = {
			has_trait = honest
			add = -15
		}

		# Culture
		modifier = {
			culture != scope:actor.culture
			"culture.cultural_acceptance(scope:recipient.culture)" < 50
			add = {
				value = 50
				subtract = "culture.cultural_acceptance(scope:recipient.culture)"
				multiply = -0.25
				round = yes
			}
			desc = CULTURAL_ACCEPTANCE
		}

		# Faith
		modifier = {
			faith = {
				faith_hostility_level = {
					target = scope:recipient.faith
					value >= faith_astray_level
				}
			}
			add = {
				value = "faith.faith_hostility_level(scope:recipient.faith)"
				multiply = -10
			}
			desc = FAITH_HOSTILITY_LEVEL
		}

		# House & Family
		modifier = {
			is_close_family_of = scope:recipient
			add = -20
		}

		#Feuds
		modifier = {
			house.house_head ?= {
				any_owned_story = {
					story_type = story_cycle_house_feud
					has_variable = house_feud_house
					var:house_feud_house = scope:recipient.house
				}
			}
			add = -50
		}

		# Relationships
		modifier = {
			add = -25
			has_any_mild_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}

		modifier = {
			add = -50
			has_any_moderate_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}

		modifier = {
			factor = 0
			has_any_worst_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}

		modifier = {
			add = 25
			has_any_mild_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}

		modifier = {
			add = 50
			has_any_moderate_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}

		modifier = {
			add = 100
			has_any_best_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
		}
	}
}
