﻿gpt_invite_to_court_interaction = {
	category = interaction_category_vassal
	icon = guest
	
	desc = invite_to_court_interaction_desc
	
	is_shown = {
		scope:actor = {
			is_ai = no
		}
		scope:recipient = {
			is_betrothed = yes
			is_adult = no
			NOR = {
				is_courtier_of = scope:actor
				is_foreign_court_guest = yes
				AND = {
					exists = host
					host = scope:actor
				}
				is_ruler = yes
			}
		}
	}

	is_valid_showing_failures_only = {
		custom_tooltip = {
			scope:recipient = {
				OR = {
					NOT = { exists = liege }
					NOT = { has_variable = invite_to_court_cooldown }
				}
			}
			text = INVITE_TO_COURT_COOLDOWN
		}	
	 #	can_recruit_character_to_court_trigger = {
	 #		RECRUITER = scope:actor
	 #		RECRUITEE = scope:recipient
	 #	}
	}
	
	#Pay som gold to persuade a wandering character to come to your court
	send_option = {
		is_shown = {
			exists = scope:recipient
		}
		flag = cover_travel_expenses
		localization = COVER_TRAVEL_EXPENSES
	}
	send_option = { # EP3 Influence
		is_shown = { # Actor must have a government that uses influence 
			scope:actor = {
				government_has_flag = government_has_influence
			}
		}
		is_valid = {
			# Actor has enough influence
			scope:actor = { influence >= medium_influence_value }
			# Both characters are within the same top realm
			scope:recipient.top_liege = scope:actor.top_liege
		}
		flag = influence_send_option
		localization = TRADE_INFLUENCE_FOR_BETTER_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

	cost = {
		influence = {
			value = 0
			if = {
				limit = { scope:influence_send_option = yes }
				add = scope:actor.medium_influence_value
				desc = INFLUENCE_INTERACTION_ACCEPTANCE_SEND_OPTION
			}
		}
	}

	on_accept = {
		hidden_effect = {
			scope:recipient = {
				set_variable = {
					name = invite_to_court_cooldown
					years = 5
				}
			}		
		
			if = {
				limit = {
					exists = scope:recipient.liege
				}
				scope:recipient.liege = {
					send_interface_message = {
						type = event_generic_neutral
						title = msg_courtier_left_court_interaction_title
						
						right_icon = scope:recipient

						show_as_tooltip = {
							remove_courtier_or_guest = scope:recipient
						}
					}
				}
			}
		}
		
		scope:actor = {
			send_interface_message = {
				type = event_generic_neutral
				title = invite_to_court_interaction_notification
				right_icon = scope:recipient

				scope:recipient = {
					scope:actor = { add_courtier = prev }
					hidden_effect = {
						return_to_court = yes
					}
				}

				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 = -50

		modifier = {
 			is_betrothed = yes
			is_adult = no
 			add = 160
 			desc = GPT_IS_BETROTHED
 		}

 		#Opinions
 	 #	opinion_modifier = {
 	 #		trigger = {
 	 #			exists = scope:recipient.liege
 	 #			is_courtier_of = liege
 	 #		}
 	 #		opinion_target = scope:recipient.liege
 	 #		multiplier = -0.5
 	 #		step = 5
 	 #		max = 50
 	 #	}
 		opinion_modifier = {
 			opinion_target = scope:actor
 			multiplier = 1
 			step = 5
 			max = 100
 		}
		
		# Stooge modifier
		modifier = {
 			scope:recipient = { has_variable = non_recruitable_var }
			scope:recipient.var:non_recruitable_var = scope:actor
 			add = -200
 			desc = AI_STOOGE
 		}

 		#Current roles
 		modifier = {
 			is_knight = yes
 			add = -20
 			desc = AI_MY_LIEGES_KNIGHT
 		}
 		modifier = {
 			is_commanding_army = yes
 			add = -30
 			desc = AI_MY_LIEGES_COMMANDER
 		}
 		modifier = {
 			is_councillor = yes
 			add = -40
 			desc = AI_ON_THE_COUNCIL
 		}
		
		modifier = {		
			trigger = { scope:recipient = { has_court_position = court_physician_court_position } }			
 			add = -20
 			desc = AI_COURT_PHYSICIAN
 		}

 		#Relations & relatives (with actor)
 		modifier = {
 			has_relation_lover = scope:actor
 			add = 100
 			desc = AI_YOUR_LOVER
 		}

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

 		modifier = {
 			is_child_of = scope:actor
 			add = 160
 			desc = AI_YOUR_CHILD
 		}

 		modifier = {
 			this.dynasty.dynast = scope:actor
 			add = 30
 			desc = AI_YOU_ARE_THE_DYNAST
 		}

 		modifier = {
 			this.house.house_head = scope:actor
 			add = 60
 			desc = AI_YOU_ARE_THE_HOUSE_HEAD
 		}
		
		modifier = {
 			this.top_liege = scope:actor
 			add = 60
 			desc = AI_YOU_ARE_THE_SOVEREIGN
 		}
		
		modifier = {
 			NOT = { is_child_of = scope:actor }
 			NOT = { is_close_family_of = scope:actor }
			is_extended_family_of = scope:actor
 			add = 30
 			desc = AI_YOUR_RELATIVE
 		}

 		modifier = {
 			NOT = { is_child_of = scope:actor }
 			is_close_family_of = scope:actor
 			add = 75
 			desc = AI_YOUR_RELATIVE
 		}

 		modifier = {
 			is_spouse_of = scope:actor
 			add = 160
 			desc = AI_YOUR_SPOUSE
 		}

 		#Relations & relatives (with host)
 		modifier = {
 			exists = liege
 			has_relation_lover = liege
 			add = -100
 			desc = AI_THEIR_LOVER
 		}

 		modifier = {
 			exists = liege
 			has_relation_friend = liege
 			add = -75
 			desc = AI_THEIR_FRIEND
 		}

 		modifier = {
 			exists = liege
 			is_child_of = liege
 			add = -160
 			desc = AI_THEIR_CHILD
 		}

 		modifier = {
 			exists = liege
 			NOT = { is_child_of = liege }
 			is_close_family_of = liege
 			add = -75
 			desc = AI_THEIR_RELATIVE
 		}

 		#Family (at location)
 		modifier = {
 			exists = location
 			any_consort_not_in_traveling_family_trigger = yes
 			desc = AI_LEAVING_MY_SPOUSE
 			add = -100
 		}

 		modifier = {
 			exists = location
 			any_child_not_in_traveling_family_trigger = yes
 			desc = AI_LEAVING_MY_CHILD
 			add = -100
 		}

 		modifier = {
 			add = -50
 			desc = AI_MARRIED_MATRILINIALLY
 			is_married = yes
 			is_male = yes
 			any_spouse = {
 				matrilinear_marriage = yes
 				host = scope:recipient.host
 			}
 		}

 		modifier = {
 			add = -50
 			desc = AI_MARRIED_PATRILINIALLY
 			is_married = yes
 			is_female = yes
 			any_spouse = {
 				patrilinear_marriage = yes
 				host = scope:recipient.host
 			}
 		}

 		modifier = {
 			add = -50
 			desc = AI_INSPIRED
 			exists = inspiration
			inspiration = {
				NOT = {
					exists = inspiration_sponsor
				}
			}
 		}

 		modifier = {
 			add = -500
 			desc = AI_SPONSORED_INSPIRATION
 			exists = inspiration
			inspiration = {
				exists = inspiration_sponsor
			}
 		}

 		modifier = {
 			add = -500
 			desc = AI_WANDERLUST
			is_child_of = scope:actor
 			has_character_modifier = lust_for_adventure
 		}
		
 		modifier = {
 			add = -180
 			desc = ELUDING_CASTRATOR
 			is_adult = no
 			any_memory = {
				has_memory_type = family_castration_fled_memory
				memory_participant:castrator ?= {
					this = scope:actor
				}
			}
 		}

 		modifier = {
 			liege ?= { is_landed = yes }
 			scope:actor = { is_landed = no }
 			add = -50
 			desc = AI_MY_LIEGE_IS_LANDED
 		}
		
		#Wandering characters (who aren't doing anything else)
		modifier = {
 			add = {
				value = 10
				add = scope:actor.diplomacy
				
				if = {
					limit = {
						faith = scope:actor.faith
					}
					add = 10
				}
				else_if = {
					limit = {
						faith = { #Same religion - But faith should not be considered Hostile or Evil
							religion = scope:actor.faith.religion
							faith_hostility_level = {
								target = scope:actor.faith
								value < 2
							}
						}
					}
					add = 5
				}
				if = {
					limit = {
						culture = scope:actor.culture
					}
					add = 10
				}
				else_if = {
					limit = {
						culture = {
							has_same_culture_heritage = scope:actor.culture
						}
					}
					add = 5
				}
				if = {
					limit = {
						OR = {
							has_trait = content
							has_trait = lazy
							has_trait = trusting
						}
					}
					add = 10
				}
			}
 			desc = AI_CAN_BE_PERSUADED_TO_STAY
			
			is_pool_guest = no
			location.province_owner = {
				OR = {
					any_liege_or_above = { this = scope:actor }
					this = scope:actor
				}
			}
			NOR = {
				has_relation_rival = scope:actor
				exists = liege
				is_child_of = scope:actor
				has_character_modifier = lust_for_adventure
			}
 		}
		
		modifier = {
			add = {
				value = 20
				if = {
					limit = {
						has_trait = greedy
					}
					multiply = 1.5
				}
				else_if = {
					limit = {
						has_trait = generous
					}
					multiply = 0.5
				}
			}
			scope:cover_travel_expenses = yes
			desc = AI_TRAVEL_EXPENSES
		}

 		# Amenities impact
 		## Actor's amenities increases acceptance
 		modifier = {
 			add = {
 				value = 10
 				if = {
 					limit = {
 						scope:actor = {
			 				has_royal_court = yes
							has_dlc_feature = royal_court
			 				amenity_level = { target = court_lodging_standards value >=  high_amenity_level }
			 			}
 					}
 			 		add = 10
 				}
 				if = {
 					limit = {
 						scope:actor = {
			 				amenity_level = { target = court_lodging_standards value >=  very_high_amenity_level }
			 			}
 					}
 			 		add = 10
 				}
 				if = {
 					limit = {
 						scope:actor = {
			 				amenity_level = { target = court_lodging_standards value >=  max_amenity_level }
			 			}
 					}
 			 		add = 20
 				}
 			}
 			desc = AI_COURT_LODGING_STANDARDS_QUALITY
			scope:actor = {
			 	has_royal_court = yes
				has_dlc_feature = royal_court
				amenity_level = { target = court_lodging_standards value >=  medium_amenity_level }
			}
 		}
		## Target's liege amenities decreases acceptance 
 		modifier = {
 			add = {
 				value = -10
				if = {
					limit = {
						liege = {
							amenity_level = { target = court_lodging_standards value >=  high_amenity_level } 
						}
					}
					add = -10
				}
				if = {
					limit = {
						liege = {
							amenity_level = { target = court_lodging_standards value >=  very_high_amenity_level } 
						}
					}
					add = -10
				}
				if = {
					limit = {
						liege = {
							amenity_level = { target = court_lodging_standards value >=  max_amenity_level } 
						}
					}
					add = -20
				}
 			}
 			desc = AI_LIEGE_COURT_LODGING_STANDARDS_QUALITY
			exists = liege
			is_courtier_of = liege
			liege = {
				has_royal_court = yes
				has_dlc_feature = royal_court
				amenity_level = { target = court_lodging_standards value >=  medium_amenity_level }
			}
 		}
		
 		modifier = {
 			add = {
				value = scope:actor.house.house_unity_value
				multiply = 0.5
			}
 			desc = AI_HOUSE_UNITY
			scope:actor = { government_has_flag = government_is_clan }
			exists = house
			exists = scope:actor.house
			house = scope:actor.house
			house = {
				OR = {
					has_house_unity_stage = harmonious
					has_house_unity_stage = friendly
				}
			}
 		}

 		modifier = {
			add = 25
			scope:influence_send_option = yes
			desc = INFLUENCE_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 }
	 			}
	 		}
 		}
		
		# Event modifiers
		
		# El Cid
		modifier = {
 			has_variable = cid_1010_no_invite_var
			var:cid_1010_no_invite_var = scope:actor
 			add = -200
 			desc = cid_1010_no_invite_var_desc
 		}
	}

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