﻿#travel around the map to look for new contracts
visit_court_interaction = {
	category = interaction_category_diplomacy
	
	interface_priority = 100
	common_interaction = yes
	use_diplomatic_range = yes

	icon = icon_contract_escort #Check
	
	desc = visit_court_interaction_desc
	
	is_shown = {

		scope:actor = {
			is_landed = no
			is_ruler = no
			is_ai = no
			NOR = {
				this = scope:recipient
				is_courtier_of = scope:recipient
				is_foreign_court_or_pool_guest_of = scope:recipient
			}
			can_leave_court_trigger = yes
		}
		scope:recipient = { 
			highest_held_title_tier >= tier_barony
			exists = capital_province 
			is_landless_adventurer = no
		}
	}

	is_valid_showing_failures_only = {
		scope:recipient = {
			is_travelling = no
			is_imprisoned = no
			# They can't be in isolation - test it
			NOT = {
				has_character_modifier = isolating_modifier
			}
			capital_county = { 
				NOT = {
					has_county_modifier = isolate_capital_decision_modifier 
				}
			}
		}
		custom_tooltip = {
			text = quit_court_reason
			scope:recipient = {
				NOR = {
					has_opinion_modifier = {
						target = scope:actor
						modifier = quit_court_opinion
					}
					has_opinion_modifier = {
						target = scope:actor
						modifier = quit_court_important_courtier_opinion
					}
				}
			}
		}
		# They can't go to places if they were dismissed
		#custom_tooltip = {
		#	text = the_wake_1
		#	NOT = {
		#		is_laamp_exiled_from_province_trigger = {
		#			PROVINCE = scope:recipient.capital_province
		#			LAAMP = scope:actor
		#		}
		#	}
		#}
	}

	on_accept = {
		scope:recipient.capital_province = {
			save_scope_as = relocation_destination
		}
		show_as_tooltip = {
			scope:actor = {
				if = {
					limit = {
						exists = host
					}
					host = {
						remove_courtier_or_guest = scope:actor
					}
					if = {
						limit = {
							is_courtier_of = host
						}
						if = {
							limit = {
								OR = {
									is_knight_of = court_owner
									is_councillor_of = court_owner
									any_court_position_employer = { this = court_owner }
								}
							}
							add_prestige = minor_prestige_loss
							court_owner = {
								add_opinion = {
									target = scope:actor
									modifier = quit_court_important_courtier_opinion
								}
							}
						}
						else = {
							court_owner = {
								add_opinion = {
									target = scope:actor
									modifier = quit_court_opinion
								}
							}
						}
					}
				}
			}
		}
		scope:actor = {
			# Check
			#show_as_tooltip = {
			#	domicile = {
			#		move_domicile = scope:relocation_destination
			#	}
			#}
			start_travel_plan = {
				destination = scope:relocation_destination
				on_start_on_action = on_travel_court_guest_start # Check
				on_arrival_on_action = on_travel_court_guest_end # Check
				on_travel_planner_cancel_on_action = petition_liege_travel_planner_exit
				on_arrival_destinations = last
				return_trip = no # One way
			}
		}
	}

	auto_accept = yes
}

request_to_join_court_interaction = {
	category = interaction_category_diplomacy
	icon = guest
	
	desc = invite_to_court_interaction_desc # Check

	greeting = positive
	notification_text = REQUEST_TO_JOIN_COURT_NOTIFICATION
	
	is_shown = {
		scope:actor = {
			is_ruler = no
			is_foreign_court_or_pool_guest_of = scope:recipient
			is_ai = no
		}
		scope:recipient = {
			is_ruler = yes
			basic_is_available = yes
			# Diplomatic range
		}
	}

	is_valid_showing_failures_only = {
		can_recruit_character_to_court_trigger = {
			RECRUITER = scope:recipient
			RECRUITEE = scope:actor
		}
		# Must not have an isolated capital if actor is not a guest
	}
	
	#Pay som gold to persuade a wandering character to come to your court
	send_option = {
		is_shown = {
			exists = scope:actor
		}
		is_valid = {
			scope:actor = { 
				gold >= join_court_value 
			}
		}
		flag = gold_bribe_flag
		localization = COVER_ACCOMODATION 
	}
	
	send_option = { # EP3 Influence
		is_shown = { # Actor must have a government that uses influence 
			scope:recipient = {
				government_has_flag = government_has_influence
			}
		}
		is_valid = {
			# Actor has enough influence
			scope:actor = { 
				influence >= miniscule_influence_value 
				# Both characters are within the same top realm
				OR = {	
					is_pool_guest_of = scope:recipient
					AND = {	
						is_foreign_court_guest_of = scope:recipient
						top_liege = scope:recipient.top_liege
					}
				}
			}
		}
		flag = low_influence_send_option
		localization = LEVERAGE_SOME_INFLUENCE_FOR_BETTER_AI_ACCEPTANCE
	}
	send_option = { # EP3 Influence - Check
		is_shown = { # Actor must have a government that uses influence 
			scope:recipient = {
				government_has_flag = government_has_influence
			}
		}
		is_valid = {
			# Actor has enough influence
			scope:actor = { 
				influence >= minor_influence_value 
				# Both characters are within the same top realm
				OR = {	
					is_pool_guest_of = scope:recipient
					AND = {	
						is_foreign_court_guest_of = scope:recipient
						top_liege = scope:recipient.top_liege
					}
				}
			}
		}
		flag = medium_influence_send_option
		localization = LEVERAGE_INFLUENCE_FOR_BETTER_AI_ACCEPTANCE
	}

	send_option = { #Prestige
		is_shown = {
			exists = scope:actor
		}
		is_valid = {
			scope:actor = { 
				prestige >= miniscule_prestige_value 
			}
		}
		flag = prestige_leverage_flag
		localization = LEVERAGE_PRESTIGE_AI_ACCEPTANCE
	}

	send_option = { #Piety
		is_shown = {
			exists = scope:actor
		}
		is_valid = {
			scope:actor = { 
				piety >= miniscule_piety_value 
				faith = scope:recipient.faith
			}
		}
		flag = piety_leverage_flag
		localization = LEVERAGE_PIETY_AI_ACCEPTANCE
	}

	send_option = {
		is_valid = {
			scope:actor = {
				has_usable_hook = scope:recipient
			}
		}
		flag = hook
		localization = SCHEME_HOOK
	}
	should_use_extra_icon = {
		scope:actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	send_options_exclusive = no

	can_send = {
		custom_description = { # Exploit prevention
			text = "has_sent_interaction_already"
			subject = scope:recipient
			scope:actor = {
				NOT = { exists = var:currently_requesting_to_join_court }
			}
		}
	}

	on_send = {
		hidden_effect = {
			# Block sending another interaction while rejection event is active
			scope:actor = {
				set_variable = {
					name = currently_requesting_to_join_court
					value = scope:recipient
					days = 30
				}
			}
		}
	}

	on_accept = {
		hidden_effect = {	
		
			#If the actor isn't a guest, and don't live in the same province, then travel to recipient's court
			#if = {
			#	limit = {
			#		exists = scope:actor.location
			#		exists = scope:recipient.capital_province 
			#		scope:actor.location = {
			#			NOT = {
			#				this = scope:recipient.capital_location
			#			}
			#		}
			#	}
			#}
			#if = {
			#	limit = {
			#		exists = scope:actor.liege
			#		scope:actor.liege = {
			#			NOT = {
			#				this = scope:recipient
			#			}
			#		}
			#	}
			#	scope:actor.liege = {
			#		send_interface_message = {
			#			type = event_generic_neutral
			#			title = msg_courtier_left_court_interaction_title
			#			
			#			right_icon = scope:actor
			#
			#			show_as_tooltip = {
			#				remove_courtier_or_guest = scope:actor
			#			}
			#		}
			#	}
			#}

			scope:recipient = {
				#send_interface_message = {
				#	type = event_generic_neutral
				#	title = invite_to_court_interaction_notification
				#	right_icon = scope:recipient
				#
				#	scope:actor = {
				#		every_traveling_family_member = {
				#			scope:recipient = { add_courtier = prev }
				#			hidden_effect = {
				#				return_to_court = yes
				#			}
				#		}
				#	}
				#
				#	#Check
				#	if = {
				#		limit = { always = scope:hook }
				#		scope:actor = {
				#			use_hook = scope:recipient
				#		}
				#	}
				#}
				#add_courtier = scope:actor
	
				send_interface_message = {
					type = event_generic_neutral
					title = msg_recruited_guest_to_court_interaction_title
					left_icon = scope:actor
					stress_impact = {
						shy = minor_stress_impact_gain
						paranoid = minor_stress_impact_gain
					}
					show_as_tooltip = {
						#list = recruiting_family
						#scope:actor = {
						#	add_courtier ?= prev
						#}
						#remove_variable = last_visited_ruler # Even though it times out automatically, removing it here saves cycles for performance.
						#add_opinion = {
						#	target = scope:actor
						#	opinion = 50
						#	modifier = grateful_opinion
						#}
						add_courtier = scope:actor
						
						#Bribes
						#Gold
						if = {
							limit = { always = scope:gold_bribe_flag }
							scope:actor = {
								pay_short_term_gold = {
									gold = join_court_value
									target = scope:recipient
								}
								stress_impact = {
									greedy = minor_stress_impact_gain
								}
							}
						}

						#Influence
						if = {
							limit = { always = scope:low_influence_send_option }
							scope:actor = { change_influence = miniscule_influence_loss }
						}
						if = {
							limit = { always = scope:medium_influence_send_option }
							scope:actor = { change_influence = minor_influence_loss }
						}

						#Prestige
						if = {
							limit = { always = scope:prestige_leverage_flag }
							scope:actor = { add_prestige = miniscule_prestige_loss }
						}

						#Piety
						if = {
							limit = { always = scope:piety_leverage_flag }
							scope:actor = { add_piety = miniscule_piety_loss }
						}

						if = {
							limit = { always = scope:hook }
							scope:actor = {
								use_hook = scope:recipient
							}
						}
					}
				}
			}
		}

		scope:actor = {
			send_interface_message = {
				type = event_generic_neutral
				title = msg_joined_court_interaction_title
				left_icon = scope:recipient
				scope:recipient = {
					add_courtier = scope:actor
				}
				stress_impact = {
					shy = minor_stress_impact_gain
				}

				#Bribes
				#Gold
				if = {
					limit = { always = scope:gold_bribe_flag }
					scope:actor = {
						pay_short_term_gold = {
							gold = join_court_value
							target = scope:recipient
						}
						stress_impact = {
							greedy = minor_stress_impact_gain
						}
					}
				}

				#Influence
				if = {
					limit = { always = scope:low_influence_send_option }
					scope:actor = { change_influence = miniscule_influence_loss }
				}
				if = {
					limit = { always = scope:medium_influence_send_option }
					scope:actor = { change_influence = minor_influence_loss }
				}

				#Prestige
				if = {
					limit = { always = scope:prestige_leverage_flag }
					scope:actor = { add_prestige = miniscule_prestige_loss }
				}

				#Piety
				if = {
					limit = { always = scope:piety_leverage_flag }
					scope:actor = { add_piety = miniscule_piety_loss }
				}

				if = {
					limit = { always = scope:hook }
					scope:actor = {
						use_hook = scope:recipient
					}
				}
			}
		}
		
		
		#if = {
		#	limit = { always = scope:cover_travel_expenses }
		#	scope:actor = {
		#		pay_short_term_gold = {
		#			gold = {
		#				value = bribe_value
		#				multiply = 0.5
		#			}
		#			target = scope:recipient
		#		}
		#		stress_impact = {
		#			greedy = minor_stress_impact_gain
		#		}
		#	}
		#}
	}

	ai_accept = {
 		base = -5

		#Rank
		modifier = {
			scope:recipient = {
				is_landed = yes
				highest_held_title_tier > tier_barony
			}
			add = {
				value = -5
				if = { #Dukes
					limit = {
						scope:recipient = {
							highest_held_title_tier > tier_county
						}
					}
					add = -10
				}
				if = { #Kings
					limit = {
						scope:recipient = {
							highest_held_title_tier > tier_duchy
						}
					}
					add = -10
				}
				if = { #Emperors
					limit = {
						scope:recipient = {
							highest_held_title_tier > tier_kingdom
						}
					}
					add = -10
				}
			}
			desc = AI_REFUSAL_RANK_DIFFERENCE
		}

 		#Opinions
 		opinion_modifier = {
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 0.15
			desc = AI_OPINION_REASON
		}

		#Traits
		modifier = {
			scope:recipient = {
				has_trait = shy
			}
			add = -25
			desc = AI_SHY
		}
		modifier = {
			scope:recipient = {
				has_trait = paranoid
			}
			add = -25
			desc = AI_PARANOID
		}
		modifier = {
			scope:recipient = {
				has_trait = gregarious
			}
			add = 10
			desc = AI_GREGARIOUS
		}

		modifier = {
			exists = scope:actor.dynasty
			scope:recipient = {
				dynasty ?= scope:actor.dynasty
				has_trait = denounced
			}
			add = -20
			desc = AI_DENOUNCED
		}

 		#Relations
		modifier = {
			has_relation_soulmate = scope:actor
			add = 200
			desc = AI_YOUR_SOULMATE
		}
 		modifier = {
 			has_relation_lover = scope:actor
 			add = 100
 			desc = AI_YOUR_LOVER
 		}

		modifier = {
			has_relation_best_friend = scope:actor
			add = 150
			desc = AI_YOUR_BEST_FRIEND
		}
 		modifier = {
 			has_relation_friend = scope:actor
 			add = 75
 			desc = AI_YOUR_FRIEND
 		}

		modifier = {
			has_relation_nemesis = scope:actor
			add = -150
			desc = AI_YOUR_NEMESIS
		}
 		modifier = {
 			has_relation_rival = scope:actor
 			add = -75
 			desc = AI_YOUR_RIVAL
 		}

		#Relatives
 		modifier = {
 			is_child_of = scope:actor
 			add = 100
 			desc = AI_YOUR_CHILD
 		}
		modifier = {
			is_parent_of = scope:actor
			add = 75
			desc = AI_YOUR_PARENT
		}
		modifier = {
			NOR = { 
				is_child_of = scope:actor 
				is_parent_of = scope:actor
			}
		   	is_sibling_of = scope:actor
			add = 50
			desc = AI_YOUR_SIBLING
		}
		modifier = {
			NOR = { 
				is_child_of = scope:actor 
				is_parent_of = scope:actor
				is_sibling_of = scope:actor
			}
			is_close_or_extended_family_of = scope:actor
			add = {
				value = 15
				if = {
					limit = {
						is_close_family_of = scope:actor
					}
					add = 10
				}
			}
			desc = AI_YOUR_RELATIVE
		}


		modifier = {
			exists = scope:actor.house
			scope:recipient.house ?= scope:actor.house
			add = 10
			desc = IS_SAME_HOUSE_REASON
		}
		modifier = {
			exists = scope:actor.dynasty
			scope:recipient.dynasty ?= scope:actor.dynasty
			add = 5
			desc = IS_SAME_DYNASTY_REASON
		}
		
 		modifier = {
 			this.dynasty.dynast = scope:actor
 			add = 30
 			desc = AI_YOU_ARE_THE_DYNAST
 		}
 		modifier = {
 			this.house.house_head = scope:actor
 			add = 30
 			desc = AI_YOU_ARE_THE_HOUSE_HEAD
 		}

 		modifier = {
 			is_spouse_of = scope:actor
 			add = 100
 			desc = AI_YOUR_SPOUSE
 		}
		modifier = {
			any_concubine = {
				this = scope:actor
			}
			add = 50
			desc = AI_YOUR_CONCUBINIST
		}

		#Criminal
		modifier = {
			scope:recipient = {
				has_imprisonment_reason = scope:actor
				NOT = {
					has_trait = forgiving
				}
			}
			add = {
				value = -10
				if = {
					limit = {
						scope:recipient = {
							has_trait = just
						}
					}
					multiply = 2
				}
			}
			desc = AI_CRIMINAL
		}

		#Prestige
		modifier = {
			scope:actor = {
				OR = {
					prestige_level = 0
					prestige_level >= 2
				}
			}
			add = {
				value = 0
				if = {
					limit = {
						scope:actor = {
							prestige_level = 0
						}
					}
					add = -10
				}
				if = {
					limit = {
						scope:actor = {
							prestige_level >= 2
						}
					}
					add = 5
				}
				if = {
					limit = {
						scope:actor = {
							prestige_level >= 3
						}
					}
					add = 5
				}
				if = {
					limit = {
						scope:actor = {
							prestige_level >= 4
						}
					}
					add = 5
				}
				if = {
					limit = {
						scope:actor = {
							prestige_level >= 5
						}
					}
					add = 5
				}
			}
			desc = AI_YOUR_PRESTIGE
		}

		#Dynasty's level of splendor
		modifier = {
			scope:actor = {
				dynasty ?= { dynasty_prestige_level >= 3 }
			}
			add = {
				value = 5
				if = {
					limit = {
						scope:actor.dynasty = { dynasty_prestige_level >= 5 }
					}
					add = 5
				}
				if = {
					limit = {
						scope:actor.dynasty = { dynasty_prestige_level >= 8 }
					}
					add = 5
				}
				if = {
					limit = {
						scope:actor.dynasty = { dynasty_prestige_level = 10 }
					}
					add = 5
				}
			}
			desc = AI_DYNASTY_PRESTIGE_REASON
		}

		#Level of devotion (if not cynical)
		modifier = {
			scope:actor = {
				OR = {
					piety_level = 0
					piety_level >= 2
				}
			}
			scope:recipient = {
				NOT = {
					has_trait = cynical
				}
			}
			add = {
				value = 0
				if = {
					limit = {
						scope:actor = {
							piety_level = 0
						}
					}
					add = -10
				}
				if = {
					limit = {
						scope:actor = {
							piety_level >= 2
						}
					}
					add = 5
				}
				if = {
					limit = {
						scope:actor = {
							piety_level >= 3
						}
					}
					add = 5
				}
				if = {
					limit = {
						scope:actor = {
							piety_level >= 4
						}
					}
					add = 5
				}
				if = {
					limit = {
						scope:actor = {
							piety_level >= 5
						}
					}
					add = 5
				}
				if = {
					limit = {
						scope:recipient = {
							has_trait = zealous
						}
					}
					multiply = 2
				}
			}
			desc = AI_DEVOTION
		}

		#Lowborn
		modifier = {
			scope:actor = {
				is_lowborn = yes
			}
			scope:recipient = {
				OR = {	
					is_lowborn = no
					has_trait = arbitrary
				}
				NOT = {
					has_trait = humble
				}
			}
			add = {
				value = -10
				if = {
					limit = {
						scope:recipient = {
							has_trait = arrogant
						}
					}
					multiply = 2
				}
			}
			desc = AI_LOWBORN
		}

		#Skills - potential knight
		modifier = {
			scope:actor = {
				OR = {
					diplomacy < mediocre_skill_rating
					diplomacy >= high_skill_rating

					stewardship < mediocre_skill_rating
					stewardship >= high_skill_rating

					martial < mediocre_skill_rating
					martial >= high_skill_rating

					intrigue < mediocre_skill_rating
					intrigue >= high_skill_rating

					learning < mediocre_skill_rating
					learning >= high_skill_rating
				}
			}
			add = {
				value = 0

				#Terrible
				if = { #Diplomacy
					limit = {
						scope:actor = {
							diplomacy < low_skill_rating
						}
					}
					add = -5
				}
				if = { #Stewardship
					limit = {
						scope:actor = {
							stewardship < low_skill_rating
						}
					}
					add = -5
				}
				if = { #Martial
					limit = {
						scope:actor = {
							martial < low_skill_rating
						}
					}
					add = -5
				}
				if = { #Intrigue
					limit = {
						scope:actor = {
							intrigue < low_skill_rating
						}
					}
					add = -5
				}
				if = { #Learning
					limit = {
						scope:actor = {
							learning < low_skill_rating
						}
					}
					add = -5
				}

				#Mediocre
				if = { #Diplomacy
					limit = {
						scope:actor = {
							diplomacy < mediocre_skill_rating
						}
					}
					add = -5
				}
				if = { #Stewardship
					limit = {
						scope:actor = {
							stewardship < mediocre_skill_rating
						}
					}
					add = -5
				}
				if = { #Martial
					limit = {
						scope:actor = {
							martial < mediocre_skill_rating
						}
					}
					add = -5
				}
				if = { #Intrigue
					limit = {
						scope:actor = {
							intrigue < mediocre_skill_rating
						}
					}
					add = -5
				}
				if = { #Learning
					limit = {
						scope:actor = {
							learning < mediocre_skill_rating
						}
					}
					add = -5
				}

				#High
				if = { #Diplomacy
					limit = {
						scope:actor = {
							diplomacy >= high_skill_rating
						}
					}
					add = 5
				}
				if = { #Stewardship
					limit = {
						scope:actor = {
							stewardship >= high_skill_rating
						}
					}
					add = 5
				}
				if = { #Martial
					limit = {
						scope:actor = {
							martial >= high_skill_rating
						}
					}
					add = 5
				}
				if = { #Intrigue
					limit = {
						scope:actor = {
							intrigue >= high_skill_rating
						}
					}
					add = 5
				}
				if = { #Learning
					limit = {
						scope:actor = {
							learning >= high_skill_rating
						}
					}
					add = 5
				}

				#Very high
				if = { #Diplomacy
					limit = {
						scope:actor = {
							diplomacy >= very_high_skill_rating
						}
					}
					add = 5
				}
				if = { #Stewardship
					limit = {
						scope:actor = {
							stewardship >= very_high_skill_rating
						}
					}
					add = 5
				}
				if = { #Martial
					limit = {
						scope:actor = {
							martial >= very_high_skill_rating
						}
					}
					add = 5
				}
				if = { #Intrigue
					limit = {
						scope:actor = {
							intrigue >= very_high_skill_rating
						}
					}
					add = 5
				}
				if = { #Learning
					limit = {
						scope:actor = {
							learning >= very_high_skill_rating
						}
					}
					add = 5
				}

				#Extremely high
				if = { #Diplomacy
					limit = {
						scope:actor = {
							diplomacy >= extremely_high_skill_rating
						}
					}
					add = 5
				}
				if = { #Stewardship
					limit = {
						scope:actor = {
							stewardship >= extremely_high_skill_rating
						}
					}
					add = 5
				}
				if = { #Martial
					limit = {
						scope:actor = {
							martial >= extremely_high_skill_rating
						}
					}
					add = 5
				}
				if = { #Intrigue
					limit = {
						scope:actor = {
							intrigue >= extremely_high_skill_rating
						}
					}
					add = 5
				}
				if = { #Learning
					limit = {
						scope:actor = {
							learning >= extremely_high_skill_rating
						}
					}
					add = 5
				}
			}
			desc = AI_SKILLS
		}

		modifier = {
			scope:actor = {
				can_be_combatant_based_on_gender_trigger = {
					ARMY_OWNER = scope:recipient
				}
				OR = {
					prowess < mediocre_skill_rating
					prowess >= high_skill_rating
				}
			}
			add = {
				value = 0
				#Terrible
				if = {
					limit = {
						scope:actor = {
							prowess < low_skill_rating
						}
					}
					add = -5
				}

				#Mediocre
				if = {
					limit = {
						scope:actor = {
							prowess < mediocre_skill_rating
						}
					}
					add = -5
				}

				#High
				if = {
					limit = {
						scope:actor = {
							prowess >= high_skill_rating
						}
					}
					add = 5
				}

				#Very high
				if = { #Diplomacy
					limit = {
						scope:actor = {
							prowess >= very_high_skill_rating
						}
					}
					add = 5
				}

				#Extremely high
				if = { #Diplomacy
					limit = {
						scope:actor = {
							prowess >= extremely_high_skill_rating
						}
					}
					add = 5
				}
			}
			desc = AI_PROWESS
		}

		#Virtuous traits (if not cynical)
		modifier = {
			scope:actor = {
				num_virtuous_traits >= 1
			}
			scope:recipient = {
				NOT = {
					has_trait = cynical
				}
			}
			add = {
				value = 5
				if = {
					limit = {
						scope:actor = {
							num_virtuous_traits >= 2
						}
					}
					add = 5
				}
				if = {
					limit = {
						scope:actor = {
							num_virtuous_traits >= 3
						}
					}
					add = 5
				}
				if = {
					limit = {
						scope:recipient = {
							has_trait = zealous
						}
					}
					multiply = 2
				}
			}
			desc = AI_VIRTUOUS_TRAITS
		}

		#Sinful traits (if not cynical)
		modifier = {
			scope:actor = {
				num_sinful_traits >= 1
			}
			scope:recipient = {
				NOT = {
					has_trait = cynical
				}
			}
			add = {
				value = -5
				if = {
					limit = {
						scope:actor = {
							num_sinful_traits >= 2
						}
					}
					add = -5
				}
				if = {
					limit = {
						scope:actor = {
							num_sinful_traits >= 3
						}
					}
					add = -5
				}
				if = {
					limit = {
						scope:recipient = {
							has_trait = zealous
						}
					}
					multiply = 2
				}
			}
			desc = AI_SINFUL_TRAITS
		}

		#Congenital traits - good and bad
		#Good genetics
		modifier = {
			scope:actor = {
				OR = {
					has_trait = intellect_good
					has_trait = physique_good
					has_trait = beauty_good
				}
			}
			add = {
				value = 0
				if = {
					limit = {
						scope:actor = {
							has_trait = intellect_good_1
						}
					}
					add = 5
				}
				if = {
					limit = {
						scope:actor = {
							has_trait = intellect_good_2
						}
					}
					add = 10
				}
				if = {
					limit = {
						scope:actor = {
							has_trait = intellect_good_3
						}
					}
					add = 15
				}

				if = {
					limit = {
						scope:actor = {
							has_trait = physique_good_1
						}
					}
					add = 5
				}
				if = {
					limit = {
						scope:actor = {
							has_trait = physique_good_2
						}
					}
					add = 10
				}
				if = {
					limit = {
						scope:actor = {
							has_trait = physique_good_3
						}
					}
					add = 15
				}

				if = {
					limit = {
						scope:actor = {
							has_trait = beauty_good_1
						}
					}
					add = 5
				}
				if = {
					limit = {
						scope:actor = {
							has_trait = beauty_good_2
						}
					}
					add = 10
				}
				if = {
					limit = {
						scope:actor = {
							has_trait = beauty_good_3
						}
					}
					add = 15
				}
			}
			desc = AI_GOOD_GENETICS
		}

		#Bad genetics
		modifier = {
			scope:actor = {
				OR = {
					has_trait = intellect_bad
					has_trait = physique_bad
					has_trait = beauty_bad
				}
			}
			add = {
				value = 0
				if = {
					limit = {
						scope:actor = {
							has_trait = intellect_bad_1
						}
					}
					add = -5
				}
				if = {
					limit = {
						scope:actor = {
							has_trait = intellect_bad_2
						}
					}
					add = -10
				}
				if = {
					limit = {
						scope:actor = {
							has_trait = intellect_bad_3
						}
					}
					add = -15
				}

				if = {
					limit = {
						scope:actor = {
							has_trait = physique_bad_1
						}
					}
					add = -5
				}
				if = {
					limit = {
						scope:actor = {
							has_trait = physique_bad_2
						}
					}
					add = -10
				}
				if = {
					limit = {
						scope:actor = {
							has_trait = physique_bad_3
						}
					}
					add = -15
				}

				if = {
					limit = {
						scope:actor = {
							has_trait = beauty_bad_1
						}
					}
					add = -5
				}
				if = {
					limit = {
						scope:actor = {
							has_trait = beauty_bad_2
						}
					}
					add = -10
				}
				if = {
					limit = {
						scope:actor = {
							has_trait = beauty_bad_3
						}
					}
					add = -15
				}
			}
			desc = AI_BAD_GENETICS
		}

		#Culture and culture acceptance
		modifier = { # Cultural Acceptance
			scope:actor = {
				NOT = { has_same_culture_as = scope:recipient }
				culture = {
					cultural_acceptance = { target = scope:recipient.culture value <= 70 }
				}
			}
			add = {
				value = -5
				if = {
					limit = {
						scope:actor.culture = {
							cultural_acceptance = { target = scope:recipient.culture value <= 10 }
						}
					}
					add = -5
				}
				if = {
					limit = {
						scope:actor.culture = {
							cultural_acceptance = { target = scope:recipient.culture value <= 20 }
						}
					}
					add = -5
				}
				if = {
					limit = {
						scope:actor.culture = {
							cultural_acceptance = { target = scope:recipient.culture value <= 30 }
						}
					}
					add = -5
				}
				if = {
					limit = {
						scope:actor.culture = {
							cultural_acceptance = { target = scope:recipient.culture value <= 40 }
						}
					}
					add = -5
				}
				if = {
					limit = {
						scope:actor.culture = {
							cultural_acceptance = { target = scope:recipient.culture value <= 50 }
						}
					}
					add = -5
				}
				if = {
					limit = {
						scope:actor.culture = {
							cultural_acceptance = { target = scope:recipient.culture value <= 60 }
						}
					}
					add = -5
				}
			}
			desc = cultural_acceptance_interaction_reason
		}

		modifier = { #Same culture
			scope:actor.culture = scope:recipient.culture
			add = 5
			desc = AI_CULTURE
		}

		#Faith, views on different faiths, religious families, and ai_zeal (non-cynical)
		modifier = { #Different faith, no pluralism.
			desc = offer_vassalization_interaction_aibehavior_differentfaith_tt
			scope:recipient = {
				NOR = { #Of two different faiths AND the potential vassal's faith is not pluralistic.
					faith = scope:actor.faith
					faith = { has_doctrine = doctrine_pluralism_pluralistic }
					has_trait = cynical
				}
				faith = {
					faith_hostility_level = {
						target = scope:actor.faith
						value > faith_fully_accepted_level
					}
				}
			}
			add = {
				value = -20
				if = {
					limit = {
						scope:recipient.faith = {
							faith_hostility_level = {
								target = scope:actor.faith
								value >= faith_hostile_level
							}
						}
					}
					add = -10
				}
				if = {
					limit = {
						scope:recipient.faith = {
							faith_hostility_level = {
								target = scope:actor.faith
								value >= faith_evil_level
							}
						}
					}
					add = -10
				}
				if = {
					limit = {
						scope:recipient = {
							has_trait = zealous
						}
					}
					multiply = 2
				}
			}
		}

		modifier = { #Different faith, pluralism.
			desc = offer_vassalization_interaction_aibehavior_differentfaith_tt
			scope:recipient = {
				NOR = {
					faith = scope:actor.faith
					has_trait = cynical
				}
				NOT = {
					scope:actor.faith = { has_doctrine = doctrine_pluralism_pluralistic }
				}
				faith = { 
					has_doctrine = doctrine_pluralism_pluralistic 
					faith_hostility_level = {
						target = scope:actor.faith
						value > faith_fully_accepted_level
					}
				}
			}
			add = {
				value = -10
				if = {
					limit = {
						scope:recipient.faith = {
							faith_hostility_level = {
								target = scope:actor.faith
								value >= faith_hostile_level
							}
						}
					}
					add = -5
				}
				if = {
					limit = {
						scope:recipient.faith = {
							faith_hostility_level = {
								target = scope:actor.faith
								value >= faith_evil_level
							}
						}
					}
					add = -5
				}
				if = {
					limit = {
						scope:recipient = {
							has_trait = zealous
						}
					}
					multiply = 2
				}
			}
		}

		modifier = { #Different faith, both have pluralism.
			desc = offer_vassalization_interaction_aibehavior_differentfaith_tt
			scope:recipient = {
				NOR = {
					faith = scope:actor.faith
					has_trait = cynical
				}
				scope:actor.faith = { has_doctrine = doctrine_pluralism_pluralistic }
				faith = { 
					has_doctrine = doctrine_pluralism_pluralistic 
					faith_hostility_level = {
						target = scope:actor.faith
						value > faith_fully_accepted_level
					}
				}
			}
			add = {
				value = -5
				if = {
					limit = {
						scope:recipient.faith = {
							faith_hostility_level = {
								target = scope:actor.faith
								value >= faith_hostile_level
							}
						}
					}
					add = -5
				}
				if = {
					limit = {
						scope:recipient.faith = {
							faith_hostility_level = {
								target = scope:actor.faith
								value >= faith_evil_level
							}
						}
					}
					add = -5
				}
				if = {
					limit = {
						scope:recipient = {
							has_trait = zealous
						}
					}
					multiply = 2
				}
			}
		}

		modifier = { #Same faith
			scope:recipient = {
				faith = scope:actor.faith
				NOT = {
					has_trait = cynical
				}
			}
			add = 5
			desc = AI_FAITH
		}

 		#Inspiration - check
		#modifier = {
 		#	add = -50
 		#	desc = AI_INSPIRED
 		#	exists = inspiration
		#	inspiration = {
		#		NOT = {
		#			exists = inspiration_sponsor
		#		}
		#	}
 		#}
		
 		#House unity
		modifier = {
 			add = {
				value = scope:actor.house.house_unity_value
				multiply = 0.25
			}
 			desc = AI_HOUSE_UNITY
			exists = scope:actor.house
			scope:recipient = {
				government_has_flag = government_is_clan
				house ?= {
					scope:actor.house
					OR = {
						has_house_unity_stage = harmonious
						has_house_unity_stage = friendly
					}
				}
			}
 		}
		modifier = {
			add = {
			   value = scope:actor.house.house_unity_value
			   multiply = -0.25
		   }
			desc = AI_HOUSE_UNITY
		   exists = scope:actor.house
		   scope:recipient = {
			   government_has_flag = government_is_clan
			   house ?= {
				   scope:actor.house
				   OR = {
					   has_house_unity_stage = competitive
					   has_house_unity_stage = antagonistic
				   }
			   }
		   }
		}

		#Bribes
		#Gold
		modifier = {
			add = {
				value = 15
				if = {
					limit = {
						scope:recipient = {
							has_trait = greedy
						}
					}
					multiply = 2
				}
				if = {
					limit = {
						scope:recipient = {
							gold <= 0
						}
					}
					multiply = 2
				}
				if = {
					limit = {
						scope:recipient = {
							debt_level >= 1
						}
					}
					multiply = 1.2
				}
				if = {
					limit = {
						scope:recipient = {
							debt_level >= 3
						}
					}
					multiply = 1.2
				}
				if = {
					limit = {
						scope:recipient = {
							debt_level >= 6
						}
					}
					multiply = 1.2
				}
				if = {
					limit = {
						scope:recipient = {
							debt_level >= 9
						}
					}
					multiply = 1.2
				}
			}
			scope:gold_bribe_flag = yes
			desc = COVERING_ACCOMODATION
		}

		#Influence
 		modifier = {
			add = {
				value = 20
				if = {
					limit = {
						scope:medium_influence_send_option = yes
					}
					add = 10
				}
			}
			OR = {
				scope:low_influence_send_option = yes
				scope:medium_influence_send_option = yes
			}
			desc = INFLUENCE_INTERACTION_ACCEPTANCE_SEND_OPTION
		}

		#Prestige
		modifier = {
			add = 15
			scope:prestige_leverage_flag = yes
			desc = PRESTIGE_INTERACTION_ACCEPTANCE_SEND_OPTION
		}

		#Piety
		modifier = {
			add = {
				value = 10
				if = {
					limit = {
						scope:recipient = {
							has_trait = zealous
						}
					}
					multiply = 1.2
				}
				if = {
					limit = {
						scope:recipient = {
							government_has_flag = government_is_theocracy
						}
					}
					multiply = 1.5
				}
			}
			scope:piety_leverage_flag = yes
			scope:recipient = {
				faith = scope:actor.faith
				NOT = {
					has_trait = cynical
				}
			}
			desc = PIETY_INTERACTION_ACCEPTANCE_SEND_OPTION
		}

 		#modifier = {
 		#	add = -1000
 		#	desc = MALUS_TO_RECRUITMENT_FOR_IMPERIAL_EUNUCHS
 		#	scope:recipient = {
 		#		is_eunuch_trigger = yes
	 	#		liege = {
	 	#			government_allows = administrative
	 	#			primary_title.tier = tier_empire
	 	#			culture = { has_cultural_parameter = can_appoint_chief_eunuch }
	 	#		}
	 	#	}
 		#}
	}

	auto_accept = {
		custom_description = {
			text = "spending_hook"
			subject = scope:actor
			object = scope:recipient
			scope:hook = yes
		}
	}
}

#To check:
##Not available if their capital is being sieged
##The trip is cancelled if the owner gets sick, the capital is closed, or something...