﻿# Siphon Treasury (scheme)
celestial_siphon_treasury_interaction = {
	icon = icon_imperial_treasury
	category = interaction_category_hostile
	send_name = START_SCHEME
	scheme = celestial_siphon_treasury
	desc = celestial_siphon_treasury_interaction_desc
	common_interaction = yes

	interface_priority = 60
	target_type = title
	target_filter = recipient_domain_titles

	filter_tags = { dynastic_cycle }

	can_be_picked_title = {
		scope:target ?= scope:recipient.primary_title
	}
	has_valid_target_showing_failures_only = {
		scope:target ?= scope:recipient.primary_title
	}
	is_shown = {
		scope:actor = {
			has_treasury = yes
		}
		scope:recipient = {
			has_treasury = yes
			OR = {
				is_landed = yes
				tgp_is_any_minister = yes
			}
			top_liege = scope:actor.top_liege
		}
	}

	is_valid_showing_failures_only = {
		# has to have some treasury to steal from
		scope:recipient = {
			treasury > 0
		}
		# Cannot be at war
		NOT = {
			scope:actor = { is_at_war_with = scope:recipient }
		}
		trigger_if = {
			limit = { scope:actor = { has_variable = no_scheming_allowed_var } }
			custom_tooltip = {
				text = no_scheming_allowed_var_tt
				scope:actor.var:no_scheming_allowed_var != scope:recipient
			}
		}
	}

	can_send = {
		scope:actor = {
			custom_description = {
				text = "character_interactions_hostile_actions_disabled_delay"
				NOT = { has_character_flag = flag_hostile_actions_disabled_delay }
			}
		}
	}

	cooldown_against_recipient = { years = 5 }

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

	on_accept = {
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = siphon_treasury_notification
				left_icon = scope:recipient
				right_icon = scope:target
				# Success.
				if = {
					limit = { scope:agent_focus_success ?= yes }
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = celestial_siphon_treasury
						TARGET_TYPE = target_title
						TARGET_SCOPE = scope:recipient.primary_title
						# 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 = celestial_siphon_treasury
						TARGET_TYPE = target_title
						TARGET_SCOPE = scope:recipient.primary_title
						# 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 = celestial_siphon_treasury
						TARGET_TYPE = target_title
						TARGET_SCOPE = scope:recipient.primary_title
						# 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 = celestial_siphon_treasury
						TARGET_TYPE = target_title
						TARGET_SCOPE = scope:recipient.primary_title
						# 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 = stewardship }
			# Scheme bonuses from being the emperor/dominant family/powerful family
			if = {
				limit = {
					scope:recipient != scope:actor
				}
				ep3_actor_scheme_modifier_effect = yes
			}
			if = {
				limit = {
					exists = scope:new_scheme
				}
				scope:new_scheme = {
					set_variable = {
						name = embezzlement_stake
						value = 0
					}
					set_variable = {
						name = embezzlement_stake_initial
						value = scope:recipient.treasury_siphoned_value
					}
				}
			}
			else = {
				save_scope_as = scheme_owner
				scope:recipient = {
					save_scope_as = scheme_target
				}
				save_scope_value_as = {
					name = embezzlement_stake_tooltip
					value = scope:recipient.treasury_siphoned_value
				}
			}
			if = {
				limit = {
					scope:recipient = scope:actor
				}
				custom_tooltip = celestial_siphon_treasury_gain_gold_tt
			}
			else = {
				custom_tooltip = celestial_siphon_treasury_gain_gold_or_treasury_tt
			}
			show_as_tooltip = {
				if = {
					limit = {
						scope:recipient = {
							has_title = title:h_china
							this != scope:actor
						}
					}
					tgp_activate_catalyst_against_hegemon_effect = {
						HEGEMON = scope:recipient
						CATALYST = catalyst_governor_embezzlement
					}
				}
				else_if = {
					limit = {
						scope:actor = {
							has_title = title:h_china
						}
					}
					scope:actor = {
						add_legitimacy_effect = { LEGITIMACY = minor_legitimacy_loss }
					}
				}
			}

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

	auto_accept = yes

	# AI
	ai_targets = {
		ai_recipients = liege
		ai_recipients = top_liege
		ai_recipients = peer_vassals
		ai_recipients = vassals
		max = 10
	}
	ai_frequency_by_tier = {
		barony = 0
		county = 144
		duchy = 72
		kingdom = 144
		empire = 0
		hegemony = 0
	}

	ai_potential = {
		has_treasury = yes
		is_landed = yes
		#do it only when you are poor
		OR = {
			treasury < 0
			and = {
				ai_greed >= 100
				ai_honor < 0
			}
		}
		# Morally upright or generally content characters never embezzle.
		NOR = {
			any_scheme = {
				is_scheme_category = hostile
			}
			ai_honor >= 25
			has_trait = honest
			has_trait = generous
			has_trait = just
			has_trait = content
			has_trait = loyal
		}
	}

	ai_will_do = {
		# Embezzlement is serious, so you need actual reasons for it.
		base = -50

		# Additions.
		## Weight for opinion.
		opinion_modifier = {
			opinion_target = scope:recipient
			multiplier = -1
		}
		## Weight for personality.
		ai_value_modifier = {
			ai_boldness = 0.25
			ai_greed = 1
			ai_honor = -0.5
		}
		## Debt is a great motivator for theft.
		### Is slightly in debt.
		modifier = {
			add = 10
			debt_level = 1
		}
		### Is one year in debt.
		modifier = {
			add = 20
			debt_level = 2
		}
		### Is two years in debt.
		modifier = {
			add = 40
			debt_level = 3
		}
		### Is three years in debt.
		modifier = {
			add = 60
			debt_level = 4
		}
		### Is four years in debt.
		modifier = {
			add = 80
			debt_level = 5
		}
		### Is over five years in debt.
		modifier = {
			add = 100
			debt_level >= 6
		}
		## Certain traits can affect likelihood directly.
		### +++ Greedy.
		modifier = {
			add = 30
			has_trait = greedy
		}
		### ++ Deceitful.
		modifier = {
			add = 20
			has_trait = deceitful
		}
		### + Arbitrary.
		modifier = {
			add = 10
			has_trait = arbitrary
		}
		# focus on peer vassals more than on characters in your own hierarchy
		modifier = {
			add = -20
			scope:actor = {
				OR = {
					is_vassal_or_below_of = scope:recipient
					is_liege_or_above_of = scope:recipient
				}
			}
		}
		# The Hegemon shouldn't be targeted that often, unless actor in the discontent movement
		modifier = {
			add = -100
			scope:recipient = {
				has_title = title:h_china
			}
			situation:dynastic_cycle ?= {
				any_participant_group = {
					participant_group_type = conservative_movement
					NOT = {
						participant_group_has_character = scope:actor
					}
				}
			}
		}
		# Factors.
		## + Do pick on people we hate.
		modifier = {
			factor = 1.5
			should_prioritise_hostile_action_against_due_to_personal_relations_trigger = {
				ACTOR = scope:actor
				RECIPIENT = scope:recipient
			}
		}
		## Avoid doing it on fellow movement members
		modifier = {
			factor = {
				value = 0.25
				if = {
					limit = {
						is_in_pro_hegemon_or_hegemon_movement = yes
					}
					multiply = 0.5
				}
			}
			is_in_same_movement_as = { TARGET = scope:recipient }
		}
		## x0 Don't pick on our friends or allies.
		modifier = {
			factor = 0
			should_avoid_hostile_action_against_due_to_personal_relations_trigger = {
				ACTOR = scope:actor
				RECIPIENT = scope:recipient
			}
		}
		
		ttd_title_distance_ai_will_do_modifier = { CHARACTER = scope:actor TITLE = scope:target }
	}
}

# Request Mentorship
request_mentoring_interaction = {
	icon = mentor
	interface_priority = 20
	category = interaction_category_friendly
	common_interaction = yes
	name = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:actor = scope:recipient
				}
				desc = request_mentoring_interaction_mentee
			}
			desc = request_mentoring_interaction
		}
	}
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:actor = scope:recipient
				}
				desc = request_mentoring_interaction_mentee_desc
			}
			desc = request_mentoring_interaction_desc
		}
	}

	filter_tags = { dynastic_cycle celestial_ministry }

	is_shown = {
		has_tgp_dlc_trigger = yes
		scope:actor = {
			government_has_flag = government_is_celestial
		}
		scope:recipient = {
			top_liege = scope:actor.top_liege
			OR = {
				is_ruler = yes
				is_courtier_of = scope:actor
			}
		}
	}

	is_valid_showing_failures_only = {
		# Cannot be at war
		scope:actor = {
			NOT = { is_at_war_with = scope:recipient }
			is_incapable = no
			is_imprisoned = no
		}
		scope:recipient = {
			is_incapable = no
			is_imprisoned = no
		}
	}

	# Set up recipient list, i.e. the character you want to teach
	populate_recipient_list = {
		scope:actor = {
			house ?= {
				every_house_member = {
					limit = {
						government_allows = administrative
						trigger_if = { # If actor is house head, do it for all house members in the realm
							limit = {
								prev.house_head ?= scope:actor
							}
							top_liege = scope:actor.top_liege
						}
						trigger_else = { # Otherwise, do it only for house members in actor's own court/immediate children
							OR = {
								liege = scope:actor
								AND = {
									top_liege = scope:actor.top_liege
									any_parent = { this = scope:actor }
								}
							}
						}
						OR = {
							this = scope:actor # You can always make yourself a mentee
							is_ai = yes # But not other players
						}
						this != scope:recipient
					}
					add_to_list = characters
				}
			}
			every_courtier = {
				limit = {
					government_allows = administrative
					top_liege = scope:actor.top_liege
					this != scope:recipient
					NOT = { is_in_list = characters }
				}
				add_to_list = characters
			}
		}
	}

	# Send options
	# Merit
	send_option = {
		flag = merit
		is_valid = {
			trigger_if = {
				limit = { exists = scope:secondary_recipient }
				custom_tooltip = {
					text = lower_merit_level_than_recipient
					exists = scope:secondary_recipient
					scope:secondary_recipient.merit_level < scope:recipient.merit_level
				}
			}
			trigger_else = {
				custom_tooltip = {
					text = no_target_selected_tt
					exists = scope:secondary_recipient
				}
			}
		}
		localization = MENTOR_SCHEME_MERIT
	}
	# Confucian Education
	send_option = {
		flag = confucian_education
		is_valid = {
			scope:recipient = {
				has_trait = confucian_education
			}
			trigger_if = {
				limit = {
					scope:secondary_recipient ?= { has_trait = confucian_education }
				}
				scope:secondary_recipient = {
					custom_tooltip = {
						text = recipient_need_more_trait_xp
						has_trait_xp = {
							trait = confucian_education
							value < "scope:recipient.has_trait_xp(confucian_education)"
						}
					}
				}
			}
		}
		localization = MENTOR_SCHEME_CONFUCIAN
	}
	# Disabled Commander Trait Option - For when the target doesn't have any commander traits
	send_option = {
		flag = no_commander_traits
		is_shown = {
			scope:recipient = {
				number_of_commander_traits = 0
			}
		}
		is_valid = {
			custom_tooltip = {
				text = recipient_has_no_commander_traits
				always = no
			}
		}
		localization = MENTOR_SCHEME_NO_COMMANDER_TRAITS
	}
	# Commander Traits
	send_option = {
		flag = logistician
		is_shown = {
			scope:recipient = {
				has_trait = logistician
			}
		}
		is_valid = {
			scope:secondary_recipient ?= {
				trigger_if = {
					limit = {
						NOT = { has_trait = logistician }
					}
					number_of_commander_traits < 3
				}
				trigger_else = {
					custom_tooltip = {
						text = recipient_need_more_trait_xp
						has_trait_xp = {
							trait = logistician
							value < "scope:recipient.has_trait_xp(logistician)"
						}
					}
				}
				can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:actor.top_liege }
			}
		}
		localization = MENTOR_SCHEME_LOGISTICIAN
	}
	send_option = {
		flag = military_engineer
		is_shown = {
			scope:recipient = {
				has_trait = military_engineer
			}
		}
		is_valid = {
			scope:secondary_recipient ?= {
				trigger_if = {
					limit = {
						NOT = { has_trait = military_engineer }
					}
					number_of_commander_traits < 3
				}
				trigger_else = {
					custom_tooltip = {
						text = recipient_need_more_trait_xp
						has_trait_xp = {
							trait = military_engineer
							value < "scope:recipient.has_trait_xp(military_engineer)"
						}
					}
				}
				can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:actor.top_liege }
			}
		}
		localization = MENTOR_SCHEME_MILITARY_ENGINEER
	}
	send_option = {
		flag = aggressive_attacker
		is_shown = {
			scope:recipient = {
				has_trait = aggressive_attacker
			}
		}
		is_valid = {
			scope:secondary_recipient ?= {
				trigger_if = {
					limit = {
						NOT = { has_trait = aggressive_attacker }
					}
					number_of_commander_traits < 3
				}
				trigger_else = {
					custom_tooltip = {
						text = recipient_need_more_trait_xp
						has_trait_xp = {
							trait = aggressive_attacker
							value < "scope:recipient.has_trait_xp(aggressive_attacker)"
						}
					}
				}
				can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:actor.top_liege }
			}
		}
		localization = MENTOR_SCHEME_AGGRESSIVE_ATTACKER
	}
	send_option = {
		flag = unyielding_defender
		is_shown = {
			scope:recipient = {
				has_trait = unyielding_defender
			}
		}
		is_valid = {
			scope:secondary_recipient ?= {
				trigger_if = {
					limit = {
						NOT = { has_trait = unyielding_defender }
					}
					number_of_commander_traits < 3
				}
				trigger_else = {
					custom_tooltip = {
						text = recipient_need_more_trait_xp
						has_trait_xp = {
							trait = unyielding_defender
							value < "scope:recipient.has_trait_xp(unyielding_defender)"
						}
					}
				}
				can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:actor.top_liege }
			}
		}
		localization = MENTOR_SCHEME_UNYIELDING_DEFENDER
	}
	send_option = {
		flag = forder
		is_shown = {
			scope:recipient = {
				has_trait = forder
			}
		}
		is_valid = {
			scope:secondary_recipient ?= {
				trigger_if = {
					limit = {
						NOT = { has_trait = forder }
					}
					number_of_commander_traits < 3
				}
				trigger_else = {
					custom_tooltip = {
						text = recipient_need_more_trait_xp
						has_trait_xp = {
							trait = forder
							value < "scope:recipient.has_trait_xp(forder)"
						}
					}
				}
				can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:actor.top_liege }
			}
		}
		localization = MENTOR_SCHEME_FORDER
	}
	send_option = {
		flag = flexible_leader
		is_shown = {
			scope:recipient = {
				has_trait = flexible_leader
			}
		}
		is_valid = {
			scope:secondary_recipient ?= {
				trigger_if = {
					limit = {
						NOT = { has_trait = flexible_leader }
					}
					number_of_commander_traits < 3
				}
				trigger_else = {
					custom_tooltip = {
						text = recipient_need_more_trait_xp
						has_trait_xp = {
							trait = flexible_leader
							value < "scope:recipient.has_trait_xp(flexible_leader)"
						}
					}
				}
				can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:actor.top_liege }
			}
		}
		localization = MENTOR_SCHEME_FLEXIBLE_LEADER
	}
	send_option = {
		flag = desert_warrior
		is_shown = {
			scope:recipient = {
				has_trait = desert_warrior
			}
		}
		is_valid = {
			scope:secondary_recipient ?= {
				trigger_if = {
					limit = {
						NOT = { has_trait = desert_warrior }
					}
					number_of_commander_traits < 3
				}
				trigger_else = {
					custom_tooltip = {
						text = recipient_need_more_trait_xp
						has_trait_xp = {
							trait = desert_warrior
							value < "scope:recipient.has_trait_xp(desert_warrior)"
						}
					}
				}
				can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:actor.top_liege }
			}
		}
		localization = MENTOR_SCHEME_DESERT_WARRIOR
	}
	send_option = {
		flag = jungle_stalker
		is_shown = {
			scope:recipient = {
				has_trait = jungle_stalker
			}
		}
		is_valid = {
			scope:secondary_recipient ?= {
				trigger_if = {
					limit = {
						NOT = { has_trait = jungle_stalker }
					}
					number_of_commander_traits < 3
				}
				trigger_else = {
					custom_tooltip = {
						text = recipient_need_more_trait_xp
						has_trait_xp = {
							trait = jungle_stalker
							value < "scope:recipient.has_trait_xp(jungle_stalker)"
						}
					}
				}
				can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:actor.top_liege }
			}
		}
		localization = MENTOR_SCHEME_JUNGLE_STALKER
	}
	send_option = {
		flag = reaver
		is_shown = {
			scope:recipient = {
				has_trait = reaver
			}
		}
		is_valid = {
			scope:secondary_recipient ?= {
				trigger_if = {
					limit = {
						NOT = { has_trait = reaver }
					}
					number_of_commander_traits < 3
				}
				trigger_else = {
					custom_tooltip = {
						text = recipient_need_more_trait_xp
						has_trait_xp = {
							trait = reaver
							value < "scope:recipient.has_trait_xp(reaver)"
						}
					}
				}
				can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:actor.top_liege }
			}
		}
		localization = MENTOR_SCHEME_REAVER
	}
	send_option = {
		flag = reckless
		is_shown = {
			scope:recipient = {
				has_trait = reckless
			}
		}
		is_valid = {
			scope:secondary_recipient ?= {
				trigger_if = {
					limit = {
						NOT = { has_trait = reckless }
					}
					number_of_commander_traits < 3
				}
				trigger_else = {
					custom_tooltip = {
						text = recipient_need_more_trait_xp
						has_trait_xp = {
							trait = reckless
							value < "scope:recipient.has_trait_xp(reckless)"
						}
					}
				}
				can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:actor.top_liege }
			}
		}
		localization = MENTOR_SCHEME_RECKLESS
	}
	send_option = {
		flag = holy_warrior
		is_shown = {
			scope:recipient = {
				has_trait = holy_warrior
			}
		}
		is_valid = {
			scope:secondary_recipient ?= {
				trigger_if = {
					limit = {
						NOT = { has_trait = holy_warrior }
					}
					number_of_commander_traits < 3
				}
				trigger_else = {
					custom_tooltip = {
						text = recipient_need_more_trait_xp
						has_trait_xp = {
							trait = holy_warrior
							value < "scope:recipient.has_trait_xp(holy_warrior)"
						}
					}
				}
				can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:actor.top_liege }
				faith = scope:recipient.faith
			}
		}
		localization = MENTOR_SCHEME_HOLY_WARRIOR
	}
	send_option = {
		flag = open_terrain_expert
		is_shown = {
			scope:recipient = {
				has_trait = open_terrain_expert
			}
		}
		is_valid = {
			scope:secondary_recipient ?= {
				trigger_if = {
					limit = {
						NOT = { has_trait = open_terrain_expert }
					}
					number_of_commander_traits < 3
				}
				trigger_else = {
					custom_tooltip = {
						text = recipient_need_more_trait_xp
						has_trait_xp = {
							trait = open_terrain_expert
							value < "scope:recipient.has_trait_xp(open_terrain_expert)"
						}
					}
				}
				can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:actor.top_liege }
			}
		}
		localization = MENTOR_SCHEME_OPEN_TERRAIN_EXPERT
	}
	send_option = {
		flag = rough_terrain_expert
		is_shown = {
			scope:recipient = {
				has_trait = rough_terrain_expert
			}
		}
		is_valid = {
			scope:secondary_recipient ?= {
				trigger_if = {
					limit = {
						NOT = { has_trait = rough_terrain_expert }
					}
					number_of_commander_traits < 3
				}
				trigger_else = {
					custom_tooltip = {
						text = recipient_need_more_trait_xp
						has_trait_xp = {
							trait = rough_terrain_expert
							value < "scope:recipient.has_trait_xp(rough_terrain_expert)"
						}
					}
				}
				can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:actor.top_liege }
			}
		}
		localization = MENTOR_SCHEME_ROUGH_TERRAIN_EXPERT
	}
	send_option = {
		flag = forest_fighter
		is_shown = {
			scope:recipient = {
				has_trait = forest_fighter
			}
		}
		is_valid = {
			scope:secondary_recipient ?= {
				trigger_if = {
					limit = {
						NOT = { has_trait = forest_fighter }
					}
					number_of_commander_traits < 3
				}
				trigger_else = {
					custom_tooltip = {
						text = recipient_need_more_trait_xp
						has_trait_xp = {
							trait = forest_fighter
							value < "scope:recipient.has_trait_xp(forest_fighter)"
						}
					}
				}
				can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:actor.top_liege }
			}
		}
		localization = MENTOR_SCHEME_FOREST_FIGHTER
	}
	send_option = {
		flag = cautious_leader
		is_shown = {
			scope:recipient = {
				has_trait = cautious_leader
			}
		}
		is_valid = {
			scope:secondary_recipient ?= {
				trigger_if = {
					limit = {
						NOT = { has_trait = cautious_leader }
					}
					number_of_commander_traits < 3
				}
				trigger_else = {
					custom_tooltip = {
						text = recipient_need_more_trait_xp
						has_trait_xp = {
							trait = cautious_leader
							value < "scope:recipient.has_trait_xp(cautious_leader)"
						}
					}
				}
				can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:actor.top_liege }
			}
		}
		localization = MENTOR_SCHEME_CAUTIOUS_LEADER
	}
	send_option = {
		flag = organizer
		is_shown = {
			scope:recipient = {
				has_trait = organizer
			}
		}
		is_valid = {
			scope:secondary_recipient ?= {
				trigger_if = {
					limit = {
						NOT = { has_trait = organizer }
					}
					number_of_commander_traits < 3
				}
				trigger_else = {
					custom_tooltip = {
						text = recipient_need_more_trait_xp
						has_trait_xp = {
							trait = organizer
							value < "scope:recipient.has_trait_xp(organizer)"
						}
					}
				}
				can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:actor.top_liege }
			}
		}
		localization = MENTOR_SCHEME_ORGANIZER
	}
	send_option = {
		flag = winter_soldier
		is_shown = {
			scope:recipient = {
				has_trait = winter_soldier
			}
		}
		is_valid = {
			scope:secondary_recipient ?= {
				trigger_if = {
					limit = {
						NOT = { has_trait = winter_soldier }
					}
					number_of_commander_traits < 3
				}
				trigger_else = {
					custom_tooltip = {
						text = recipient_need_more_trait_xp
						has_trait_xp = {
							trait = winter_soldier
							value < "scope:recipient.has_trait_xp(winter_soldier)"
						}
					}
				}
				can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:actor.top_liege }
			}
		}
		localization = MENTOR_SCHEME_WINTER_SOLDIER
	}

	can_send = {
		custom_tooltip = {
			text = mentoring_no_option_selected
			OR = {
				scope:merit = yes
				scope:confucian_education = yes
				scope:logistician = yes
				scope:military_engineer = yes
				scope:aggressive_attacker = yes
				scope:unyielding_defender = yes
				scope:forder = yes
				scope:flexible_leader = yes
				scope:desert_warrior = yes
				scope:jungle_stalker = yes
				scope:reaver = yes
				scope:reckless = yes
				scope:holy_warrior = yes
				scope:open_terrain_expert = yes
				scope:rough_terrain_expert = yes
				scope:forest_fighter = yes
				scope:cautious_leader = yes
				scope:organizer = yes
				scope:winter_soldier = yes
			}
		}
		trigger_if = {
			limit = {
				exists = scope:secondary_recipient
			}
			scope:secondary_recipient = {
				is_physically_able = yes
			}
		}
	}

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

				left_icon = scope:secondary_recipient
				right_icon = scope:recipient

				scope:secondary_recipient = {
					start_scheme = {
						type = mentoring
						target_character = scope:recipient
					}
					if = {
						limit = {
							scope:merit ?= yes
							trigger_if = {
								limit = {	
									is_female = yes
								}
								top_liege ?= {	
									OR = {
										has_realm_law = male_only_law
										has_realm_law = male_preference_law
									}
								}
							}
							trigger_else = {
								top_liege ?= {	
									OR = {
										has_realm_law = female_only_law
										has_realm_law = female_preference_law
									}
								}
							}
						}
						custom_tooltip = mentoring_cannot_be_appointed_tt
					}
				}
				set_elder_relation_effect = {
					ELDER = scope:recipient
					DISCIPLE = scope:secondary_recipient
					MERIT = minor_merit_gain
				}
			}
		}

		scope:secondary_recipient = {
			if = {
				limit = {
					scope:merit = yes
				}
				random_scheme = {
					limit = { scheme_type = mentoring }
					set_variable = {
						name = mentoring_merit
						value = yes
					}
				}
				custom_tooltip = mentoring_merit_desc
			}
			if = {
				limit = {
					scope:confucian_education = yes
				}
				random_scheme = {
					limit = { scheme_type = mentoring }
					set_variable = {
						name = mentoring_confucian_education
						value = yes
					}
				}
				if = {
					limit = {
						has_trait = confucian_education
					}
					custom_tooltip = mentoring_confucian_education_desc
				}
				else = {
					show_as_tooltip = { add_trait = confucian_education }
				}
			}
			if = {
				limit = {
					scope:logistician = yes
				}
				random_scheme = {
					limit = { scheme_type = mentoring }
					set_variable = {
						name = mentoring_logistician
						value = yes
					}
				}
				if = {
					limit = {
						has_trait = logistician
					}
					custom_tooltip = mentoring_logistician_desc
				}
				else = {
					show_as_tooltip = { add_trait = logistician }
				}
			}
			if = {
				limit = {
					scope:military_engineer = yes
				}
				random_scheme = {
					limit = { scheme_type = mentoring }
					set_variable = {
						name = mentoring_military_engineer
						value = yes
					}
				}
				if = {
					limit = {
						has_trait = military_engineer
					}
					custom_tooltip = mentoring_military_engineer_desc
				}
				else = {
					show_as_tooltip = { add_trait = military_engineer }
				}
			}
			if = {
				limit = {
					scope:aggressive_attacker = yes
				}
				random_scheme = {
					limit = { scheme_type = mentoring }
					set_variable = {
						name = mentoring_aggressive_attacker
						value = yes
					}
				}
				if = {
					limit = {
						has_trait = aggressive_attacker
					}
					custom_tooltip = mentoring_aggressive_attacker_engineer_desc
				}
				else = {
					show_as_tooltip = { add_trait = aggressive_attacker }
				}
			}
			if = {
				limit = {
					scope:unyielding_defender = yes
				}
				random_scheme = {
					limit = { scheme_type = mentoring }
					set_variable = {
						name = mentoring_unyielding_defender
						value = yes
					}
				}
				if = {
					limit = {
						has_trait = unyielding_defender
					}
					custom_tooltip = mentoring_unyielding_defender_desc
				}
				else = {
					show_as_tooltip = { add_trait = unyielding_defender }
				}
			}
			if = {
				limit = {
					scope:forder = yes
				}
				random_scheme = {
					limit = { scheme_type = mentoring }
					set_variable = {
						name = mentoring_forder
						value = yes
					}
				}
				if = {
					limit = {
						has_trait = forder
					}
					custom_tooltip = mentoring_forder_desc
				}
				else = {
					show_as_tooltip = { add_trait = forder }
				}
			}
			if = {
				limit = {
					scope:flexible_leader = yes
				}
				random_scheme = {
					limit = { scheme_type = mentoring }
					set_variable = {
						name = mentoring_flexible_leader
						value = yes
					}
				}
				if = {
					limit = {
						has_trait = flexible_leader
					}
					custom_tooltip = mentoring_flexible_leader_desc
				}
				else = {
					show_as_tooltip = { add_trait = flexible_leader }
				}
			}
			if = {
				limit = {
					scope:desert_warrior = yes
				}
				random_scheme = {
					limit = { scheme_type = mentoring }
					set_variable = {
						name = mentoring_desert_warrior
						value = yes
					}
				}
				if = {
					limit = {
						has_trait = desert_warrior
					}
					custom_tooltip = mentoring_desert_warrior_desc
				}
				else = {
					show_as_tooltip = { add_trait = desert_warrior }
				}
			}
			if = {
				limit = {
					scope:jungle_stalker = yes
				}
				random_scheme = {
					limit = { scheme_type = mentoring }
					set_variable = {
						name = mentoring_jungle_stalker
						value = yes
					}
				}
				if = {
					limit = {
						has_trait = jungle_stalker
					}
					custom_tooltip = mentoring_jungle_stalker_desc
				}
				else = {
					show_as_tooltip = { add_trait = jungle_stalker }
				}
			}
			if = {
				limit = {
					scope:reaver = yes
				}
				random_scheme = {
					limit = { scheme_type = mentoring }
					set_variable = {
						name = mentoring_reaver
						value = yes
					}
				}
				if = {
					limit = {
						has_trait = reaver
					}
					custom_tooltip = mentoring_reaver_desc
				}
				else = {
					show_as_tooltip = { add_trait = reaver }
				}
			}
			if = {
				limit = {
					scope:reckless = yes
				}
				random_scheme = {
					limit = { scheme_type = mentoring }
					set_variable = {
						name = mentoring_reckless
						value = yes
					}
				}
				if = {
					limit = {
						has_trait = reckless
					}
					custom_tooltip = mentoring_reckless_desc
				}
				else = {
					show_as_tooltip = { add_trait = reckless }
				}
			}
			if = {
				limit = {
					scope:holy_warrior = yes
				}
				random_scheme = {
					limit = { scheme_type = mentoring }
					set_variable = {
						name = mentoring_holy_warrior
						value = yes
					}
				}
				if = {
					limit = {
						has_trait = holy_warrior
					}
					custom_tooltip = mentoring_holy_warrior_desc
				}
				else = {
					show_as_tooltip = { add_trait = holy_warrior }
				}
			}
			if = {
				limit = {
					scope:open_terrain_expert = yes
				}
				random_scheme = {
					limit = { scheme_type = mentoring }
					set_variable = {
						name = mentoring_open_terrain_expert
						value = yes
					}
				}
				if = {
					limit = {
						has_trait = open_terrain_expert
					}
					custom_tooltip = mentoring_open_terrain_expert_desc
				}
				else = {
					show_as_tooltip = { add_trait = open_terrain_expert }
				}
			}
			if = {
				limit = {
					scope:rough_terrain_expert = yes
				}
				random_scheme = {
					limit = { scheme_type = mentoring }
					set_variable = {
						name = mentoring_rough_terrain_expert
						value = yes
					}
				}
				if = {
					limit = {
						has_trait = rough_terrain_expert
					}
					custom_tooltip = mentoring_rough_terrain_expert_desc
				}
				else = {
					show_as_tooltip = { add_trait = rough_terrain_expert }
				}
			}
			if = {
				limit = {
					scope:forest_fighter = yes
				}
				random_scheme = {
					limit = { scheme_type = mentoring }
					set_variable = {
						name = mentoring_forest_fighter
						value = yes
					}
				}
				if = {
					limit = {
						has_trait = forest_fighter
					}
					custom_tooltip = mentoring_forest_fighter_desc
				}
				else = {
					show_as_tooltip = { add_trait = forest_fighter }
				}
			}
			if = {
				limit = {
					scope:cautious_leader = yes
				}
				random_scheme = {
					limit = { scheme_type = mentoring }
					set_variable = {
						name = mentoring_cautious_leader
						value = yes
					}
				}
				if = {
					limit = {
						has_trait = cautious_leader
					}
					custom_tooltip = mentoring_cautious_leader_desc
				}
				else = {
					show_as_tooltip = { add_trait = cautious_leader }
				}
			}
			if = {
				limit = {
					scope:organizer = yes
				}
				random_scheme = {
					limit = { scheme_type = mentoring }
					set_variable = {
						name = mentoring_organizer
						value = yes
					}
				}
				if = {
					limit = {
						has_trait = organizer
					}
					custom_tooltip = mentoring_organizer_desc
				}
				else = {
					show_as_tooltip = { add_trait = organizer }
				}
			}
			if = {
				limit = {
					scope:winter_soldier = yes
				}
				random_scheme = {
					limit = { scheme_type = mentoring }
					set_variable = {
						name = mentoring_winter_soldier
						value = yes
					}
				}
				if = {
					limit = {
						has_trait = winter_soldier
					}
					custom_tooltip = mentoring_winter_soldier_desc
				}
				else = {
					show_as_tooltip = { add_trait = winter_soldier }
				}
			}
		}
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 36
		duchy = 36
		kingdom = 36
		empire = 36
		hegemony = 36
	}

	ai_targets = {
		ai_recipients = courtiers
		ai_recipients = vassals
		ai_recipients = peer_vassals
		max = 10
	}
	ai_targets = {
		ai_recipients = situation_participant_group
		parameter = dynastic_cycle
		max = 10
	}

	ai_potential = {
		government_has_flag = government_is_celestial
		is_adult = yes
	}

	ai_will_do = {
		base = 0
	}

	ai_accept = {
		base = -10

		# Opinion
		opinion_modifier = {
			opinion_target = scope:actor
			who = scope:recipient
			multiplier = 0.5
		}
		opinion_modifier = {
			trigger = {
				scope:actor != scope:secondary_recipient
			}
			opinion_target = scope:secondary_recipient
			who = scope:recipient
			multiplier = 0.5
		}

		# Personality
		modifier = {
			has_trait = generous
			add = 10
			desc = INTERACTION_GENEROUS
		}
		modifier = {
			has_trait = gregarious
			add = 5
			desc = INTERACTION_GREGARIOUS
		}
		modifier = {
			has_trait = trusting
			add = 5
			desc = INTERACTION_TRUSTING
		}
		modifier = {
			has_trait = lazy
			add = -10
			desc = INTERACTION_LAZY
		}
		modifier = {
			has_trait = arbitrary
			add = -10
			desc = INTERACTION_ARBITRARY
		}
		modifier = {
			has_trait = paranoid
			add = -20
			desc = INTERACTION_PARANOID
		}

		# Other traits
		modifier = { # Scholars like to spread knowledge
			has_trait = scholar
			add = 10
			desc = TAKE_THE_VOWS_SCHOLAR
		}

		# You are in the same movement
		modifier = {
			is_in_same_movement_as = { TARGET = scope:actor }
			add = {
				value = 20
				if = {
					limit = {
						is_in_pro_hegemon_or_hegemon_movement = yes
					}
					multiply = 1.5
				}
			}
			desc = actor_and_recipient_in_same_movement
		}

		# Relations to actor
		modifier = {
			has_relation_friend = scope:actor
			add = 25
			desc = AI_YOUR_FRIEND
		}
		modifier = {
			has_relation_rival = scope:actor
			add = -50
			desc = AI_YOUR_RIVAL
		}
		modifier = { # Recipient is your elder and mentors you
			has_relation_disciple = scope:actor
			scope:secondary_recipient = scope:actor
			add = 30
			desc = AI_YOUR_ELDER
		}
		modifier = { # Recipient is your elder but mentors someone else
			has_relation_disciple = scope:actor
			scope:secondary_recipient != scope:actor
			add = 15
			desc = AI_YOUR_ELDER
		}
		modifier = {
			has_relation_elder = scope:actor
			add = 10
			desc = AI_YOUR_DISCIPLE
		}

		# Higher tier rulers are less likely to accept
		modifier = {
			primary_title.tier > scope:actor.primary_title.tier
			add = {
				value = -15
				multiply = {
					add = primary_title.tier
					subtract = scope:actor.primary_title.tier
				}
			}
			desc = actor_is_of_lower_tier_desc
		}
		
		ttd_medium_distance_ai_accept_modifier = yes
	}
}

# Movement Power Change (scheme)
celestial_movement_power_promote_interaction = {
	icon = icon_scheme_promote
	category = interaction_category_diplomacy
	send_name = START_SCHEME
	scheme = celestial_movement_power_promote
	desc = celestial_movement_power_promote_interaction_desc
	common_interaction = no
	filter_tags = { dynastic_cycle }

	interface_priority = 60

	is_shown = {
		scope:actor = {
			exists = var:movement_power
		}
		scope:recipient = {
			exists = var:movement_power
		}
		situation:dynastic_cycle ?= {
			any_participant_group = {
				NOR = {
					participant_group_type = hegemon_ruler
					participant_group_type = other_rulers
				}
				participant_group_has_character = scope:actor
			}
		}
		situation:dynastic_cycle ?= {
			any_participant_group = {
				NOR = {
					participant_group_type = hegemon_ruler
					participant_group_type = other_rulers
				}
				participant_group_has_character = scope:recipient
			}
		}
	}

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

	can_send = {
	}

	cooldown_against_recipient = { years = 3 }

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

	on_accept = {
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = celestial_movement_power_promote
				left_icon = scope:actor
				right_icon = scope:recipient
				# Success.
				if = {
					limit = { scope:agent_focus_success ?= yes }
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = celestial_movement_power_promote
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
						# Success.
						AGENT_1 = agent_proponent
						AGENT_2 = agent_sycophant
						AGENT_3 = agent_eunuch
						AGENT_4 = agent_intermediary
						# Speed.
						AGENT_5 = agent_herald
					}
				}
				# Speed.
				else_if = {
					limit = { scope:agent_focus_speed ?= yes }
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = celestial_movement_power_promote
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
						# Speed.
						AGENT_1 = agent_bureaucrat
						AGENT_2 = agent_political_socialite
						AGENT_3 = agent_gabbler
						AGENT_4 = agent_herald
						# Success.
						AGENT_5 = agent_sycophant
					}
				}
				# Balanced.
				else = {
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = celestial_movement_power_promote
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
						# Success.
						AGENT_1 = agent_proponent
						AGENT_2 = agent_sycophant
						AGENT_3 = agent_eunuch
						# Speed.
						AGENT_4 = agent_gabbler
						AGENT_5 = agent_herald
					}
				}
			}
			# Scheme progress bonus from education
			education_5_scheme_progress_effect = { SKILL = diplomacy }
			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 }
			}
		}
	}

	auto_accept = yes

	# AI
	ai_targets = {
		ai_recipients = situation_participant_group
		parameter = dynastic_cycle
		max = 10
	}
	ai_frequency_by_tier = {
		barony = 0
		county = 108
		duchy = 36
		kingdom = 36
		empire = 36
		hegemony = 36
	}

	ai_potential = {
		NOT = {
			any_scheme = {
				is_scheme_category = political
			}
		}
		NOR = {
			has_trait = deceitful
			has_trait = arrogant
			has_trait = disloyal
			has_title = title:h_china # the hegemon should rather not be doing this
		}
	}

	ai_will_do = {
		base = -50

		# Additions.
		## Weight for opinion.
		opinion_modifier = {
			opinion_target = scope:recipient
			multiplier = 0.5
		}
		## Weight for personality.
		ai_value_modifier = {
			ai_energy = -0.25
			ai_vengefulness = -1
			ai_honor = 0.5
		}
		## Certain traits can affect likelihood directly.
		### +++ Gregarious.
		modifier = {
			add = 50
			has_trait = gregarious
		}
		### ++ Compassionate.
		modifier = {
			add = 30
			has_trait = compassionate
		}
		### + Generous.
		modifier = {
			add = 10
			has_trait = generous
		}
		# focus on characters in your own hierarchy
		modifier = {
			add = 20
			scope:actor = {
				OR = {
					is_vassal_or_below_of = scope:recipient
					is_liege_or_above_of = scope:recipient
				}
			}
		}
		# focus on disciples
		modifier = {
			add = 50
			scope:actor = {
				has_relation_disciple = scope:recipient
			}
		}
		# or fellow disciples
		modifier = {
			add = 20
			scope:recipient = {
				any_relation = {
					type = elder
					any_relation = {
						type = disciple
						this = scope:actor
					}
				}
			}
		}
		# Factors.
		## Don't pick people we hate.
		modifier = {
			factor = 0
			should_prioritise_hostile_action_against_due_to_personal_relations_trigger = {
				ACTOR = scope:actor
				RECIPIENT = scope:recipient
			}
		}
		## Pick our friends or allies.
		modifier = {
			factor = 1.5
			should_avoid_hostile_action_against_due_to_personal_relations_trigger = {
				ACTOR = scope:actor
				RECIPIENT = scope:recipient
			}
		}
		
		ttd_minor_distance_ai_will_do_modifier = { CHARACTER_1 = scope:actor CHARACTER_2 = scope:recipient.top_liege }
	}
}

# Movement Power Change (scheme)
celestial_movement_power_slander_interaction = {
	icon = icon_scheme_slander
	category = interaction_category_diplomacy
	send_name = START_SCHEME
	scheme = celestial_movement_power_slander
	desc = celestial_movement_power_slander_interaction_desc
	common_interaction = no
	filter_tags = { dynastic_cycle }

	interface_priority = 60

	is_shown = {
		scope:actor = {
			exists = var:movement_power
		}
		scope:recipient = {
			exists = var:movement_power
			this != scope:actor
		}
		situation:dynastic_cycle ?= {
			any_participant_group = {
				NOR = {
					participant_group_type = hegemon_ruler
					participant_group_type = other_rulers
				}
				participant_group_has_character = scope:actor
			}
		}
		situation:dynastic_cycle ?= {
			any_participant_group = {
				NOR = {
					participant_group_type = hegemon_ruler
					participant_group_type = other_rulers
				}
				participant_group_has_character = scope:recipient
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			can_start_scheme = {
				type = celestial_movement_power_slander
				target_character = scope:recipient
			}
		}
		trigger_if = {
			limit = { scope:actor = { has_variable = no_scheming_allowed_var } }
			custom_tooltip = {
				text = no_scheming_allowed_var_tt
				scope:actor.var:no_scheming_allowed_var != scope:recipient
			}
		}
	}

	can_send = {
		scope:actor = {
			custom_description = {
				text = "character_interactions_hostile_actions_disabled_delay"
				NOT = { has_character_flag = flag_hostile_actions_disabled_delay }
			}
		}
	}

	cooldown_against_recipient = { years = 3 }

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

	on_accept = {
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = celestial_movement_power_slander
				left_icon = scope:actor
				right_icon = scope:recipient
				# Success.
				if = {
					limit = { scope:agent_focus_success ?= yes }
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = celestial_movement_power_slander
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
						# Success.
						AGENT_1 = agent_proponent
						AGENT_2 = agent_diplomat
						AGENT_3 = agent_eunuch
						AGENT_4 = agent_intermediary
						# Speed.
						AGENT_5 = agent_herald
					}
				}
				# Speed.
				else_if = {
					limit = { scope:agent_focus_speed ?= yes }
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = celestial_movement_power_slander
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
						# Speed.
						AGENT_1 = agent_bureaucrat
						AGENT_2 = agent_political_socialite
						AGENT_3 = agent_gabbler
						AGENT_4 = agent_herald
						# Success.
						AGENT_5 = agent_diplomat
					}
				}
				# Balanced.
				else = {
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = celestial_movement_power_slander
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
						# Success.
						AGENT_1 = agent_proponent
						AGENT_2 = agent_diplomat
						AGENT_3 = agent_eunuch
						# Speed.
						AGENT_4 = agent_gabbler
						AGENT_5 = agent_herald
					}
				}
			}
			# Scheme progress bonus from education
			education_5_scheme_progress_effect = { SKILL = diplomacy }
			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 }
			}
		}
	}

	auto_accept = yes

	# AI
	ai_targets = {
		ai_recipients = liege
		ai_recipients = top_liege
		ai_recipients = peer_vassals
		ai_recipients = vassals
		max = 10
	}
	ai_frequency_by_tier = {
		barony = 0
		county = 72
		duchy = 36
		kingdom = 12
		empire = 12
		hegemony = 12
	}

	ai_potential = {
		# Morally upright or generally content characters never slander.
		NOR = {
			any_scheme = {
				is_scheme_category = political
			}
			has_trait = honest
			has_trait = generous
			has_trait = just
			has_trait = content
			has_trait = loyal
			has_title = title:h_china # the hegemon should rather not be doing this
		}
	}

	ai_will_do = {
		base = -50

		# Additions.
		## Weight for opinion.
		opinion_modifier = {
			opinion_target = scope:recipient
			multiplier = -1
		}
		## Weight for personality.
		ai_value_modifier = {
			ai_energy = 0.25
			ai_vengefulness = 1
			ai_honor = -0.5
		}
		## Certain traits can affect likelihood directly.
		### +++ Deceitful.
		modifier = {
			add = 50
			has_trait = deceitful
		}
		### ++ Arbitrary.
		modifier = {
			add = 30
			has_trait = arbitrary
		}
		### + Vengeful.
		modifier = {
			add = 10
			has_trait = vengeful
		}
		# focus on peer vassals more than on characters in your own hierarchy
		modifier = {
			add = -20
			scope:actor = {
				OR = {
					is_vassal_or_below_of = scope:recipient
					is_liege_or_above_of = scope:recipient
				}
			}
		}
		# Factors.
		## + Do pick on people we hate.
		modifier = {
			factor = 1.5
			should_prioritise_hostile_action_against_due_to_personal_relations_trigger = {
				ACTOR = scope:actor
				RECIPIENT = scope:recipient
			}
		}
		## Don't do it on fellow movement members
		modifier = {
			factor = 0
			is_in_same_movement_as = { TARGET = scope:recipient }
		}
		## x0 Don't pick on our friends or allies.
		modifier = {
			factor = 0
			should_avoid_hostile_action_against_due_to_personal_relations_trigger = {
				ACTOR = scope:actor
				RECIPIENT = scope:recipient
			}
		}
		
		ttd_minor_distance_ai_will_do_modifier = { CHARACTER_1 = scope:actor CHARACTER_2 = scope:recipient.top_liege }
	}
}

censor_find_secrets_interaction = {
	icon = secret
	interface_priority = 50
	category = interaction_category_hostile
	common_interaction = yes
	desc = {
		triggered_desc = {
			trigger = {
				scope:actor = {
					has_title = title:e_minister_censor
					has_council_position = councillor_spymaster
				}
			}
			desc = censor_find_secrets_interaction_desc
		}
		triggered_desc = {
			trigger = {
				scope:actor = {
					has_title = title:e_minister_of_justice
					has_council_position = minister_justice
				}
			}
			desc = censor_find_secrets_interaction_desc_justice
		}
	}
	is_shown = {
		scope:actor = {
			OR = {
				AND = {
					has_title = title:e_minister_censor
					has_council_position = councillor_spymaster
				}
				AND = {
					has_title = title:e_minister_of_justice
					has_council_position = minister_justice
				}
			}
			top_liege = {
				tgp_has_access_to_ministry_trigger = yes
			}
		}
		scope:recipient = {
			this != scope:actor
			this != scope:actor.top_liege
			is_vassal_or_below_of = scope:actor.top_liege
		}
	}
	is_valid_showing_failures_only = {
		scope:actor = {
			is_imprisoned = no
		}
		scope:recipient = {
			is_imprisoned = no
		}
	}

	auto_accept = yes

	on_accept = {
		scope:actor = {
			begin_scheme_with_agents_effect = {
				SCHEME_TYPE = celestial_minister_find_secrets_scheme
				TARGET_TYPE = target_character
				TARGET_SCOPE = scope:recipient
				# Success.
				AGENT_1 = agent_diplomat
				AGENT_2 = agent_shill
				AGENT_3 = agent_gabbler
				# Speed.
				AGENT_4 = agent_theologian
				# Secrecy.
				AGENT_5 = agent_justiciar
			}
		}
	}
	ai_will_do = {
		base = 100
		
		ttd_minor_distance_ai_will_do_modifier = { CHARACTER_1 = scope:actor CHARACTER_2 = scope:recipient }
	}
	ai_frequency_by_tier = {
		barony = 0
		county = 0
		duchy = 0
		kingdom = 0
		empire = 48 #The Censor title is empire tier
		hegemony = 0
	}
	ai_targets = {
		ai_recipients = peer_vassals
		max = 20
	}
	ai_potential = {
		is_at_war = no
		NOT = {
			any_scheme = {
				is_scheme_category = political
			}
		}
	}	
}
