﻿# Add general actions here, if any.

offer_vassalization_interaction = {
	category = interaction_category_vassal
	icon = icon_vassal

	desc = offer_vassalization_interaction_desc

	ai_targets = {
		ai_recipients = neighboring_rulers
	}
	ai_target_quick_trigger = {
		adult = yes
	}
	ai_frequency_by_tier = {
		barony = 0
		county = 0
		duchy = 12
		kingdom = 12
		empire = 12
		hegemony = 12
	}

	is_available = {
		is_landed = yes
		trigger_if = {
			limit = { is_ai = yes }
			highest_held_title_tier > tier_county
			this = top_liege
			vassal_limit_available > 1
			is_adult = yes
		}
	}

	is_shown = {
		scope:recipient = {
			this != scope:actor
			is_playable_character = yes
			OR = {
				AND = {
					top_liege ?= this
					is_tributary = no
				}
				is_tributary_of_suzerain_or_above = scope:actor
			}
			trigger_if = {
				limit = {
					scope:actor = {
						NOT = { government_has_flag = government_is_mandala }
					}
				}
				highest_held_title_tier < scope:actor.highest_held_title_tier
			}
			NOR = {
				government_has_flag = cannot_be_vassal_or_liege
				government_has_flag = government_is_herder
			}
		}
		# Temujin cannot make Jamukha his subject once he leaves him
		NOT = {
			scope:actor = {
				has_variable = had_mpo_temujin_flavor_0010
				var:had_mpo_temujin_flavor_0010 ?= scope:recipient
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			trigger_if = {
				limit = { is_confederation_member = yes }
				exists = house.house_confederation
			}
			trigger_if = {
				limit = {
					has_title = title:h_china
				}
#				situation:dynastic_cycle ?= {
#					NOT = {
#						situation_current_phase = situation_dynastic_cycle_phase_instability
#					}
#					trigger_if = {
#						limit = {
#							situation_current_phase = situation_dynastic_cycle_phase_stability_advancement
#						}
#						scope:recipient = {
#							custom_tooltip = {
#								text = recipient_is_not_celestial_desc
#								government_has_flag = government_is_celestial
#							}
#						}
#					}
#				}
			}
		}
		scope:recipient = {
			is_at_war = no
			is_confederation_member = no

			custom_description = {
				text = was_recently_granted_independence
				NOT = {
					has_opinion_modifier = {
						modifier = granted_independence_opinion
						target = scope:actor
					}
				}
			}
			trigger_if = {
				limit = { is_tributary = yes }
				custom_tooltip = {
					text = was_recently_granted_independence
					scope:recipient.suzerain = scope:actor
				}	
			}
			trigger_if = {
				limit = {
					scope:actor = { government_has_flag = government_is_mandala }
				}
				highest_held_title_tier < scope:actor.highest_held_title_tier
			}
		}
	}

	greeting = positive
	notification_text = OFFER_VASSALIZATION_INTERACTION_NOTIFICATION

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

	ai_min_reply_days = 5
	ai_max_reply_days = 10

	ai_accept = {
		base = -50

		# Military power difference modifier.
		offer_vassalization_interaction_ai_acceptance_general = yes

		#ALL these modifiers are also used in impress_intent_vassalization_acceptance_value, keep them synced


		# OBEDIENCE
		modifier = {
			desc = obedient_interaction_reason
			trigger = {
				is_obedient_to = scope:actor
			}
			add = 20
		}

		modifier = {
			desc = tenet_love_thy_neighbour_boon_reason
			trigger = {
				scope:actor = { has_personal_tenet_flag = tenet_love_thy_neighbour_vassalage_acceptance }
			}
			add = 15
		}

		modifier = { #Has no Available Vassal Limit
			desc = offer_vassalization_interaction_aibehavior_vassal_limit_tt
			trigger = {
				scope:actor = {
					vassal_limit_available < 1
				}
			}
			add = {
				value = -1000
			}
		}

		# GOVERNMENT
			modifier = { # I am Tribal and you are not
				desc = interaction_tribal_vs_nontribal
				trigger = {
					scope:recipient = {
						government_has_flag = government_is_tribal
					}
					scope:actor = {
						NOT = { government_has_flag = government_is_tribal }
					}
				}
				add = -20
			}
			modifier = { # You are Tribal and I am not
				desc = interaction_nontribal_vs_tribal
				trigger = {
					scope:actor = {
						government_has_flag = government_is_tribal
					}
					scope:recipient = {
						NOT = { government_has_flag = government_is_tribal }
					}
				}
				add = -20
			}
			modifier = { # I am Nomadic and you are Nomadic
				desc = interaction_is_nomadic
				trigger = {
					scope:recipient = {
						government_has_flag = government_is_nomadic
					}
					scope:actor = {
						government_has_flag = government_is_nomadic
					}
				}
				add = -50
			}
			modifier = { # I am Nomadic and you are not
				desc = interaction_nomadic_vs_nonnomadic
				trigger = {
					scope:recipient = {
						government_has_flag = government_is_nomadic
					}
					scope:actor = {
						NOT = { government_has_flag = government_is_nomadic }
					}
				}
				add = -75
			}
			modifier = { # You are Nomadic and I am not
				desc = interaction_nonnomadic_vs_nomadic
				trigger = {
					scope:actor = {
						government_has_flag = government_is_nomadic
					}
					scope:recipient = {
						NOT = { government_has_flag = government_is_nomadic }
					}
				}
				add = -75
			}

		modifier = { #Military Strength
			desc = offer_vassalization_interaction_aibehavior_power_tt
	  	  	add = {
				value = 1
				subtract = {
					value = scope:recipient.max_military_strength # Intended for recipient to use max, to avoid having vassalizations become too easy for weakened realms
					divide = { value = scope:actor.current_military_strength min = 1 }
				}
				multiply = 20
				ceiling = yes
	  		}
		}

		# TRAITS/PERSONALITY
			modifier = { # Ambitious
				desc = TAKE_THE_VOWS_AMBITIOUS
				trigger = {
					scope:recipient = {
						has_trait = ambitious
					}
				}
				add = -20
			}
			modifier = { # Paranoid
				desc = INTERACTION_PARANOID
				trigger = {
					scope:recipient = {
						has_trait = paranoid
					}
				}
				add = -20
			}
			modifier = { # Arrogant
				desc = INTERACTION_ARROGANT
				trigger = {
					scope:recipient = {
						has_trait = arrogant
					}
				}
				add = -20
			}

			modifier = { # Fickle
				desc = INTERACTION_FICKLE
				trigger = {
					scope:recipient = {
						has_trait = fickle
					}
				}
				add = -10
			}

			modifier = { # Stubborn
				desc = INTERACTION_STUBBORN
				trigger = {
					scope:recipient = {
						has_trait = stubborn
					}
				}
				add = -10
			}

			modifier = { # Trusting
				desc = TAKE_THE_VOWS_TRUSTING
				trigger = {
					scope:recipient = {
						has_trait = trusting
					}
				}
				add = 5
			}

			modifier = { # Content
				desc = INTERACTION_CONTENT
				trigger = {
					scope:recipient = {
						has_trait = content
					}
				}
				add = 5
			}

		# CONTRACT OPTIONS
			modifier = {
				add = 60
				scope:recipient = {	government_has_flag = government_is_feudal }
				scope:religious_exemption = yes
				desc = CONTRACT_RELIGIOUS_EXEMPTION_REASON
			}
			modifier = {
				add = 30
				scope:recipient = {	government_has_flag = government_is_clan }
				scope:religious_exemption_clan = yes
				desc = CONTRACT_RELIGIOUS_EXEMPTION_REASON
			}
			modifier = {
				add = 30
				scope:recipient = {	government_has_flag = government_is_feudal }
				scope:low_obligations = yes
				desc = CONTRACT_LOW_TAXES_REASON
			}
			modifier = {
				add = -40
				scope:recipient = {	government_has_flag = government_is_feudal }
				scope:high_obligations = yes
				desc = CONTRACT_HIGH_TAXES_REASON
			}

		#ALL these modifiers are also used in impress_intent_vassalization_acceptance_value, keep them synced

		#Mandala
			#Mandala Tributaries should not want to be vassals
			modifier = {
				scope:recipient = { is_tributary_of = scope:actor }
				scope:actor = { government_has_flag = government_is_mandala }
				add = -35
				desc = is_tributary_of_me_mandala
			}

			modifier = {
				scope:recipient = { government_has_flag = government_is_mandala }
				scope:actor = { government_has_flag = government_is_mandala }
				add = -25
				desc = is_mandala_government
			}

			#Your Radiance
			modifier = {
				scope:actor = { has_mandala_capital_trigger = yes }
				add = scope:actor.mandala_radiance_value
				desc = actor_positive_mandala_radiance
			}

			#Tributary Realm Size
			subject_realm_size_lose_weight_modifier = {
				DEVARAJA = scope:actor
				SUBJECT = scope:recipient
			}
			
			#Do they like you?
			opinion_modifier = { 
				trigger = {
					scope:actor = { government_has_flag = government_is_mandala }
				}
				who = scope:recipient
				opinion_target = scope:actor
				multiplier = 1
			}
	}

	# Low starting obligations
	send_option = {
		is_shown = {
			scope:recipient = {
				government_has_flag = government_is_feudal
			}
		}
		flag = low_obligations
		localization = low_obligations
	}

	# Medium starting obligations
	send_option = {
		is_shown = {
			scope:recipient = {
				government_has_flag = government_is_feudal
			}
		}
		flag = normal_obligations								# If selected then scope:flag_name will be set to yes
		localization = normal_obligations				# Loc_key for option label
		starts_enabled = { always = yes }				# Trigger for whether this should be on when the window opens. If not defined, defaults to off

	}

	# High starting obligations
	send_option = {
		is_shown = {
			scope:recipient = {
				government_has_flag = government_is_feudal
			}
		}
		flag = high_obligations								# If selected then scope:flag_name will be set to yes
		localization = high_obligations					# Loc_key for option label
	}

	# Low starting obligations + religious exemption
	send_option = {
		is_shown = {
			scope:recipient = {
				government_has_flag = government_is_feudal
			}
		}
		is_valid = {
			scope:recipient.faith != scope:actor.faith
		}
		flag = religious_exemption
		localization = religious_exemption
	}

	# Religious exemption, for clans
	send_option = {
		is_shown = {
			scope:recipient = {
				government_has_flag = government_is_clan
			}
		}
		is_valid = {
			scope:recipient.faith != scope:actor.faith
		}
		flag = religious_exemption_clan
		localization = religious_exemption
	}

	# Nothing, for clans
	send_option = {
		is_shown = {
			scope:recipient = {
				government_has_flag = government_is_clan
			}
		}
		is_valid = {
			always = yes
		}
		flag = no_exemption_clan
		localization = no_exemption
	}

	send_option = { # EP3 Influence
		is_shown = {
			scope:actor = {
				government_has_flag = government_has_influence
			}
		}
		is_valid = {
			scope:actor = { influence >= medium_influence_value }
		}
		flag = influence_send_option
		localization = TRADE_INFLUENCE_FOR_BETTER_AI_ACCEPTANCE
	}
	send_option = { # EP3 Influence - give you an option doesn't cost influence when there's nothing to pick
		is_shown = {
			scope:actor = {
				government_has_flag = government_has_influence
			}
			scope:recipient = {
				NOR = {
					government_has_flag = government_is_feudal
					government_has_flag = government_is_clan
				}
			}
		}
		flag = offer_nothing
		localization = offer_nothing
	}

	send_options_exclusive = yes

	on_accept = {
		offer_vassalization_interaction_effect = yes
		scope:actor = {
			trigger_event = char_interaction.0001

			## Remove bonus, it's been used
			if = {
				limit = { has_character_modifier = event_bonus_to_vassal_accept }
				remove_character_modifier = event_bonus_to_vassal_accept
			}

#			if = { # FP3
#				limit = { any_character_struggle = { has_struggle_phase_parameter = offer_vassalization_removes_disloyalty } }
#				scope:recipient = { remove_trait = disloyal }
#			}
		}
	}

	on_decline = {
		scope:actor = {
			trigger_event = char_interaction.0002
		}
	}

	ai_will_do = {
		base = 100

		# AI prefers to receive higher obligations from their vassals when possible.
		modifier = {
			factor = 3
			scope:normal_obligations = yes
		}

		modifier = {
			factor = 4
			scope:high_obligations = yes
		}

		# Cynical rulers are happy to offer religious protection to potential vassals, but only when it makes them accept a vassalization offer they would otherwise refuse.
		# Zealous rulers become increasingly reluctant to offer religious protection, as they want to enforce religious homogeneity in their realm.
		modifier = {
			add = {
				value = ai_zeal
				multiply = -2
				max = 1
			}
			scope:religious_exemption = yes
		}


		modifier = { # If the recipient is a player, do not bother sending
			factor = 0
			scope:recipient = {
				is_ai = no
			}
		}
	}
}

offer_fealty_interaction = {
	category = interaction_category_vassal
	icon = icon_liege

	desc = offer_fealty_interaction_desc

	is_available = {
		is_landed = yes
		top_liege ?= this # You have to be independent - This check exists to prevent a lot of edge-cases where you can change liege
		is_confederation_member = no
		NOT = { government_has_flag = cannot_be_vassal_or_liege }
	}

	is_shown = {
		scope:recipient = {
			this != scope:actor
			is_landed = yes
			top_liege ?= this # Target has to be independent
		}
		scope:actor.highest_held_title_tier < scope:recipient.highest_held_title_tier
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			is_imprisoned = no
			is_at_war = no
		}
		scope:recipient = {
			custom_description = {
				text = "offer_fealty_neighboring_condition"
				subject = scope:recipient
				OR = {
					any_neighboring_and_across_water_top_liege_realm_owner = { this = scope:actor }
					any_held_title = {
						is_de_jure_liege_or_above_target = scope:actor.capital_barony
					}
				}
			}
			#making sure that if this gov types got land you won't be able to swear fealty to them
			NOR = {
				government_has_flag = government_is_landless_adventurer
				government_has_flag = government_is_holy_order
				government_has_flag = government_is_mercenary
			}
		}
	}

	greeting = positive
	notification_text = OFFER_FEALTY_INTERACTION_NOTIFICATION

	ai_min_reply_days = 5
	ai_max_reply_days = 10

	ai_accept = {
		base = 50
		# MAIN
		# Heretic/Infidel modifier.
		# Tier difference modifier.
		# Dejure modifier.
		# Distant/Remote Realm modifier.

		# MINOR
		# Rivalry modifier.
		# Same Dynasty modifier.
		# Cultural/Cultural Group modifiers.
		# Claimant modifier.

		# OPINION SCALES
		# Personality modifier.
		# Compare Opinion modifier.

		modifier = { # Different faith, no pluralism.
			desc = offer_vassalization_interaction_aibehavior_differentfaith_tt
			trigger = {
				scope:actor = {
					NOR = { # Of two different faiths AND the potential vassal's faith is not pluralistic.
						faith = scope:recipient.faith
						rite = { rite_has_doctrine = doctrine_pluralism_pluralistic }
					}
				}
			}
			add = {
				value = -25
				if = {
					limit = {
						scope:actor.faith = {
							faith_hostility_level = {
								target = scope:recipient.faith
								value >= faith_hostile_level
							}
						}
					}
					add = -10
				}
				if = {
					limit = {
						scope:actor.faith = {
							faith_hostility_level = {
								target = scope:recipient.faith
								value >= faith_evil_level
							}
						}
					}
					add = -25
				}
			}
		}

		modifier = { # I am a King!
			desc = offer_fealty_interaction_aibehavior_hightier_tt
			trigger = {
				scope:actor = {
					highest_held_title_tier >= tier_kingdom
				}
			}
			add = -10
		}
		modifier = { # Wide difference in rank
			desc = offer_vassalization_interaction_aibehavior_widetitletier_tt
			trigger = {
				scope:actor = {
					tier_difference = {
						target = scope:recipient
						value > 1
					}
				}
			}
			add = 20
		}
		modifier = { # They are my Rightful Liege
			desc = offer_vassalization_interaction_aibehavior_rightfulvassaltitleholder_tt
			trigger = {
				scope:recipient = { is_rightful_liege_of = scope:actor }
			}
			add = 25
		}
		modifier = { # Distant Realm.
			desc = offer_vassalization_interaction_aibehavior_distantrealm_tt
			trigger = {
				scope:actor = {
					NOT = {
						any_neighboring_top_liege_realm_owner = { this = scope:recipient }
					}
					# landless ruler count as within realm
					trigger_if = {
						limit = { is_landed = no }
						NOT = { capital_county.holder = { target_is_same_character_or_above = scope:actor } }
					}
					capital_province = { squared_distance = { target = scope:recipient.capital_province value < 200000 } }
				}
			}
			add = -15
		}
		modifier = { # Remote Realm.
			desc = offer_vassalization_interaction_aibehavior_remoterealm_tt
			trigger = {
				scope:actor = {
					NOT = {
						any_neighboring_top_liege_realm_owner = { this = scope:recipient }
					}
					# landless ruler count as within realm
					trigger_if = {
						limit = { is_landed = no }
						NOT = { capital_county.holder = { target_is_same_character_or_above = scope:actor } }
					}
					capital_province = { squared_distance = { target = scope:recipient.capital_province value >= 200000 } }
				}
			}
			add = -25
		}

		# MINOR
		modifier = { # Rivalry modifier.
			desc = offer_vassalization_interaction_aibehavior_rival_tt
			trigger = {
				scope:recipient = {
					has_relation_rival = scope:actor
					NOT = { has_relation_nemesis = scope:actor }
				}
			}
			add = -10
		}
		modifier = { # Nemesis modifier.
			desc = offer_vassalization_interaction_aibehavior_nemesis_tt
			trigger = {
				scope:recipient = {
					has_relation_nemesis = scope:actor
				}
			}
			add = -100
		}
		modifier = { # Same Dynasty modifier.
			desc = offer_vassalization_interaction_aibehavior_dynasty_tt
			trigger = {
				scope:recipient = {
					dynasty = scope:actor.dynasty
				}
			}
			add = 10
		}

		modifier = { # Cultural Acceptance
			add = -5
			desc = cultural_acceptance_interaction_reason
			trigger = {
				scope:actor = {
					NOT = { has_same_culture_as = scope:recipient }
					culture = {
						cultural_acceptance = { target = scope:recipient.culture value < 50 }
					}
				}
			}
		}

		modifier = { # Same language
			add = 5
			desc = speaks_same_language_interaction_reason
			trigger = {
				scope:actor = {
					knows_language_of_culture = scope:recipient.culture
				}
			}
		}

		modifier = { # Claimant modifier.
			desc = offer_vassalization_interaction_aibehavior_claimant_tt
			trigger = {
				scope:actor.primary_title = {
					scope:recipient = {
						has_claim_on = prev
					}
				}
			}
			add = -15
		}

		# PERSONALITY
		ai_value_modifier = {
			ai_greed = 0.75
			min = 0
		}

		# OPINION INFLUENCE
		opinion_modifier = { # Compare Opinion modifier.
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 0.5
		}

		# CONTRACT OPTIONS
		modifier = {
			add = {
				value = -10
				if = {
					limit = { scope:recipient = { has_trait = zealous } }
					add = -30
				}
				else_if = {
					limit = { scope:recipient = { has_trait = cynical } }
					add = 30
				}
			}
			scope:actor = {	government_has_flag = government_is_feudal }
			scope:religious_taxation = yes
			desc = CONTRACT_RELIGIOUS_TAXATION_REASON
		}
		modifier = {
			add = -40
			scope:actor = {	government_has_flag = government_is_feudal }
			scope:low_obligations = yes
			desc = CONTRACT_LOW_TAXES_REASON
		}
		modifier = {
			add = 40
			scope:actor = {	government_has_flag = government_is_feudal }
			scope:high_obligations = yes
			desc = CONTRACT_HIGH_TAXES_REASON
		}
		modifier = {
			add = {
				value = -10
				if = {
					limit = { scope:recipient = { has_trait = zealous } }
					add = -30
				}
				else_if = {
					limit = { scope:recipient = { has_trait = cynical } }
					add = 30
				}
			}
			scope:actor = {	government_has_flag = government_is_clan }
			scope:religious_exemption_clan = yes
			desc = CONTRACT_RELIGIOUS_EXEMPTION_REASON
		}
		# EP3
		modifier = { # cowed from an emperor's impressive visit
			add = 10
			desc = cowed_from_visit_interaction_reason
			trigger = {
				scope:actor = {
					has_character_flag = cowed_increased_vassalization_acceptance
				}
			}
		}
		#Confederation wants same-culture rulers
		modifier = {
			add = 100
			desc = CONFEDERATION_CULTURE_REASON
			scope:recipient = {
				is_confederation_member = yes
				culture = {
					this = scope:actor.culture
				}
			}
		}

		#Greatest of Khans and Mongol Emperor would prefer submission with tribute
		modifier = {
			add = -150
			desc = GOK_PREFER_SUBMISSION
			scope:recipient = {
				highest_held_title_tier >= tier_empire
				any_owned_story = {
					OR = {
						story_type = story_mongol_invasion
						story_type = story_greatest_of_khans
					}
				}
			}
		}
		#Just refused to be transferred to me
		modifier = {
			add = -75
			desc = refused_transfer_reason
			scope:actor = {
				var:refused_transfer_target ?= {
					this = scope:recipient
				}
			}
		}
		#I promised church to stop being your liege
		modifier = {
			add = -200
			desc = refused_transfer_liege_reason
			scope:actor = {
				var:refused_transfer_liege ?= {
					this = scope:recipient
				}
			}
		}
	}

	# Low starting obligations
	send_option = {
		is_shown = {
			scope:actor = {
				government_has_flag = government_is_feudal
			}
		}
		flag = low_obligations
		localization = low_obligations
	}

	# Medium starting obligations
	send_option = {
		is_shown = {
			scope:actor = {
				government_has_flag = government_is_feudal
			}
		}
		flag = normal_obligations
		localization = normal_obligations
		starts_enabled = { always = yes }

	}

	# High starting obligations
	send_option = {
		is_shown = {
			scope:actor = {
				government_has_flag = government_is_feudal
			}
		}
		flag = high_obligations
		localization = high_obligations
	}

	# Medium-high starting obligations + religious protection
	send_option = {
		is_shown = {
			scope:actor = {
				government_has_flag = government_is_feudal
			}
		}
		is_valid = {
			scope:recipient.faith != scope:actor.faith
		}
		flag = religious_taxation
		localization = religious_taxation
	}

	# Religious exemption, for clans
	send_option = {
		is_shown = {
			scope:actor = {
				government_has_flag = government_is_clan
			}
		}
		is_valid = {
			scope:recipient.faith != scope:actor.faith
		}
		flag = religious_exemption_clan
		localization = religious_exemption
	}

	# Nothing, for clans
	send_option = {
		is_shown = {
			scope:actor = {
				government_has_flag = government_is_clan
			}
		}
		is_valid = {
			always = yes
		}
		flag = no_exemption_clan
		localization = no_exemption
	}

	send_options_exclusive = yes

	on_accept = {
		offer_fealty_interaction_effect = yes

		scope:actor = {
			trigger_event = char_interaction.0010
			if = {
				limit = {
					government_has_mechanic = administrative
					scope:recipient = { NOT = { government_has_mechanic = administrative } }
				}
				custom_tooltip = will_change_from_administrative_tt
				custom_tooltip = will_lose_administrative_government_type_tt
			}
			if = {
				limit = {
					scope:recipient = {
						is_confederation_member = yes
					}
				}
				if = {
					limit = {
						government_has_flag = government_is_nomadic
					}
					add_character_modifier = {
						modifier = mpo_confederation_member_modifier
						years = 5
					}
					every_vassal_or_below = {
						limit = {
							highest_held_title_tier >= tier_county
							government_has_flag = government_is_nomadic
						}
						add_character_modifier = {
							modifier = mpo_confederation_member_modifier
							years = 5
						}
					}
				}

				add_character_flag = {
					flag = new_confederate
					years = 3
				}
				every_vassal_or_below = {
					limit = {
						highest_held_title_tier >= tier_county
					}
					add_character_flag = {
						flag = new_confederate
						years = 3
					}
				}
			}

			# If you have a suzerain, they will get a lower opinion of you for not paying tribute anymore
			suzerain ?= {
				if = {
					limit = {
						this != scope:actor
						this != scope:recipient
					}
					add_opinion = {
						modifier = tributary_ceased_payments_opinion
						target = scope:actor
					}
				}
			}
		}
		scope:recipient = {
			if = {
				limit = {
					has_imprisonment_reason = scope:actor
				}
				consume_imprisonment_reasons = scope:actor
			}
			if = {
				limit = {
					has_revoke_title_reason = scope:actor
				}
				consume_revoke_title_reason = scope:actor
			}
			if = {
				limit = {
					has_banish_reason = scope:actor
				}
				consume_banish_reasons = scope:actor
			}
			if = {
				limit = {
					has_execute_reason = scope:actor
				}
				consume_execute_reasons = scope:actor
			}
		}
	}

	on_intermediary_accept = {
	}

	on_decline = {
		scope:actor = {
			trigger_event = char_interaction.0011
		}
	}
}

force_vote_in_succession_election_interaction = {
	category = interaction_category_uncategorized
	hidden = yes
	special_interaction = force_vote_in_succession_election
	icon = scroll_scales

	greeting = positive
	notification_text = FORCE_VOTE_INTERACTION_NOTIFICATION
	force_notification = yes

	desc = force_vote_in_succession_election_interaction_desc

	auto_accept = yes

	is_valid_showing_failures_only = {
		custom_description = {
			text = must_have_usable_hook_blocker
			subject = scope:actor
			object = scope:recipient

			scope:actor = {
				has_usable_hook = scope:recipient
			}
		}
	}

	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	on_accept = {
		scope:actor = {
			send_interface_message = {
				type = event_title_good
				title = force_vote_in_succession_election_interaction
				right_icon = scope:recipient

				show_as_tooltip = {
					scope:actor = {
						use_hook = scope:recipient
						custom_tooltip = msg_force_vote_in_succession_election_message
					}
				}
			}
			hidden_effect = {
				use_hook = scope:recipient
			}
		}

		# If we're a clan this interaction affects unity
		add_clan_unity_interaction_effect = {
			CHARACTER = scope:actor
			TARGET = scope:recipient
			VALUE = minor_unity_gain
			DESC = clan_unity_voted.desc
			REVERSE_NON_HOUSE_TARGET = no
		}
	}
}

set_primary_spouse_interaction = {
	category = interaction_category_diplomacy
	desc = set_primary_spouse_interaction_desc
	icon = icon_marriage

	auto_accept = yes

	is_available = {
		trigger_if = {
			limit = { is_ai = yes }
			any_spouse = {
				count >= 2
			}
		}
	}

	is_shown = {
		scope:actor = {
			is_spouse_of = scope:recipient
		}
		scope:actor.primary_spouse != scope:recipient
	}
	is_valid_showing_failures_only = {
		scope:recipient = {
			NOT = {
				has_trait = incapable
			}
		}
	}

	on_accept = {
		scope:actor.primary_spouse = {
			if = {
				limit = {
					has_opinion_modifier = {
						target = scope:actor
						modifier = spouse_made_primary_opinion
					}
				}
				remove_opinion = {
					modifier = spouse_made_primary_opinion
					target = scope:actor
				}
			}
			add_opinion = {
				target = scope:actor
				modifier = spouse_made_secondary_opinion
			}
			hidden_effect = {
				send_interface_toast = {
					type = event_toast_effect_bad
					title = set_primary_spouse_interaction_toast
					left_icon = scope:actor
					right_icon = scope:recipient

					custom_tooltip = set_primary_spouse_interaction_toast_removed
				}
			}
		}
		scope:actor = {
			if = {
				limit = {
					scope:actor.primary_spouse = {
						is_lowborn = no
					}
					scope:recipient = {
						is_lowborn = yes
					}
				}
				add_legitimacy = {
					value = medium_legitimacy_loss
					multiply = scope:actor.primary_title.tier
				}
				every_vassal_or_below = {
					limit = { has_vassal_stance = courtly }
					custom = every_courtly_vassal
					add_opinion = {
						modifier = married_lowborn_opinion
						target = scope:actor
						opinion = -50
					}
				}
				every_vassal_or_below = {
					limit = { has_vassal_stance = glory_hound }
					custom = every_glory_hound_vassal
					add_opinion = {
						modifier = married_lowborn_opinion
						target = scope:actor
						opinion = -30
					}
				}
			}
			set_primary_spouse = scope:recipient
			hidden_effect = {
				send_interface_toast = {
					type = event_toast_effect_neutral
					title = set_primary_spouse_interaction_toast
					left_icon = scope:actor
					right_icon = scope:recipient

					custom_tooltip = set_primary_spouse_interaction_toast_changed
				}
			}
		}
		scope:recipient = {
			hidden_effect = {
				send_interface_toast = {
					type = event_toast_effect_good
					title = set_primary_spouse_interaction_toast
					left_icon = scope:actor
					right_icon = scope:recipient

					custom_tooltip = set_primary_spouse_interaction_toast_added
				}
			}

			if = {
				limit = {
					has_opinion_modifier = {
						target = scope:actor
						modifier = spouse_made_secondary_opinion
					}
				}
				remove_opinion = {
					modifier = spouse_made_secondary_opinion
					target = scope:actor
				}
			}
			add_opinion = {
				target = scope:actor
				modifier = spouse_made_primary_opinion
			}
		}
	}

	ai_targets = {
		ai_recipients = spouses
	}
	ai_target_quick_trigger = {
		adult = yes
	}
	ai_frequency_by_tier = {
		barony = 0
		county = 0
		duchy = 72
		kingdom = 72
		empire = 72
		hegemony = 72
	}

	ai_will_do = {
		base = 0

		modifier = {
			add = 100
			scope:recipient = {
				is_lowborn = no
				sum_of_all_skills_value > scope:actor.primary_spouse.sum_of_all_skills_value
			}
			scope:actor = {
				NOR = {
					has_relation_friend = scope:actor.primary_spouse
					has_relation_lover = scope:actor.primary_spouse
				}
			}
		}
	}
}

grant_independence_interaction = {
	category = interaction_category_vassal
	force_notification = yes
	greeting = positive
	notification_text = GRANT_INDEPENDENCE_INTERACTION_NOTIFICATION
	icon = independence
	interface_priority = 120

	desc = grant_independence_interaction_desc

	is_shown = {
		scope:puppet_or_actor ?= {
			trigger_if = {
				limit = { is_confederation_member = yes }
				exists = house.house_confederation
			}
		}
		scope:recipient = {
			is_vassal_of = scope:puppet_or_actor
			is_landed = yes
		}
		scope:recipient != scope:puppet_or_actor
	}

	is_valid_showing_failures_only = {
		NOT = { scope:puppet_or_actor = { is_at_war_with = scope:recipient } }
		scope:puppet_or_actor = {
			top_liege = this
			is_at_war = no
			custom_description = {
				text = is_at_war_with_another_vassal
				object = scope:recipient
				NOT = {
					scope:puppet_or_actor = {
						any_vassal_or_below = {
							is_at_war_with = scope:recipient
						}
					}
				}
			}
			custom_description = {
				text = is_de_jure_vassal_check
				object = scope:recipient

				trigger_if = { # Admin rulers can grant tribal vassals independence regardless of de jure
					limit = {
						scope:puppet_or_actor = { government_has_mechanic = administrative }
						scope:recipient = { government_has_flag = government_is_tribal }
					}
					# Always possible
				}
				trigger_else = {
					NOT = { #Cannot be used against de jure vassals
						scope:recipient.primary_title = {
							any_this_title_or_de_jure_above = {
								holder = scope:puppet_or_actor
							}
						}
					}
				}

			}
			custom_tooltip = {
				text = can_only_remove_diarch_by_elevating_them.tt
				NOT = { scope:recipient ?= scope:puppet_or_actor.diarch }
			}
		}
		tgp_blocked_action_against_tenno_trigger = {
			ACTOR = scope:puppet_or_actor
			TARGET = scope:recipient
		}
	}

	auto_accept = yes

	on_accept = {
		if = { # The puppet action cooldown is paced on the puppeteer, so it is shared across all their puppets
			limit = {
				exists = scope:is_puppet_action
				scope:is_puppet_action = yes
			}
			scope:actor = {
				add_character_flag = { flag = pam_puppet_grant_independence_cooldown years = 5 }
			}
		}

		scope:puppet_or_actor = {
			stress_and_fulfillment_impact = {
				ambitious = medium_stress_impact_gain
				arrogant = minor_stress_impact_gain
				greedy = minor_stress_impact_gain
			}
			hidden_effect = {
				send_interface_toast = {
					type = event_toast_effect_neutral
					title = grant_vassal_independence_interaction_toast
					left_icon = scope:actor
					right_icon = scope:recipient

					custom_tooltip = grant_vassal_independence_interaction_toast_desc

					# Struggle Parameter
#					if = {
#						limit = {
#							exists = dynasty
#							NOT = {
#								any_held_title = {
# 									is_de_jure_liege_or_above_target = scope:recipient.primary_title
#								}
#							}
#							any_character_struggle = {
#								involvement = involved
#								has_struggle_phase_parameter = granting_independence_to_non_dejure_gives_renown
#							}
#						}
#						dynasty = {
#							add_dynasty_prestige = medium_dynasty_prestige_value
#						}
#					}
				}
			}
		}

		hidden_effect = {
			if = {
				limit = {
					scope:is_puppet_action ?= yes
				}
				scope:actor = {
					send_interface_toast = {
						type = event_toast_effect_neutral
						title = grant_vassal_independence_interaction_toast
						left_icon = scope:puppet_or_actor
						right_icon = scope:recipient

						custom_tooltip = grant_vassal_independence_interaction_toast_desc
					}
				}
			}
		}

		scope:recipient = {
			#Send notifications
			if = {
				limit = {
					any_liege_or_above = {
						is_ai = no
						this != scope:puppet_or_actor
					}
				}
				every_liege_or_above = {
					limit = {
						is_ai = no
						this != scope:puppet_or_actor
					}
					trigger_event = vassal_interaction.0023
				}
			}
			if = {
				limit = {
					any_liege_or_above = {
						any_vassal = {
							is_ai = no
							NOR = {
								this = scope:recipient
								this = scope:puppet_or_actor
							}
						}
					}
				}
				every_liege_or_above = {
					limit = {
						any_vassal = {
							is_ai = no
							NOR = {
								this = scope:recipient
								this = scope:puppet_or_actor
							}
						}
					}
					every_vassal = {
						limit = {
							is_ai = no
							this != scope:recipient
						}
						trigger_event = {
							id = vassal_interaction.0022
							days = 3
						}
					}
				}
			}

			add_opinion = {
				target = scope:puppet_or_actor
				modifier = granted_independence_opinion
			}

			add_truce_both_ways = {
				character = scope:puppet_or_actor
				days = 3650
				name = TRUCE_GRANT_INDEPENDENCE
			}

			create_title_and_vassal_change = {
				type = independency
				save_scope_as = change
				add_claim_on_loss = yes
			}
			becomes_independent = {
				change = scope:change
			}

			resolve_title_and_vassal_change = scope:change
		}

		# Struggle Catalysts.
#		scope:puppet_or_actor = {
#			if = {
#				limit = {
#					catalyst_gave_independence_to_powerful_diff_faith_culture_vassal_preliminary_trigger = {
#						CHAR1 = scope:puppet_or_actor
#						CHAR2 = scope:recipient
#					}
#					any_character_struggle = {
#						involvement = involved
#						activate_struggle_catalyst_secondary_character_involvement_either_trigger = {
#							CATALYST = catalyst_gave_independence_to_powerful_diff_faith_culture_vassal
#							CHAR = scope:recipient
#						}
#					}
#				}
#				every_character_struggle = {
#					involvement = involved
#					limit = {
#						activate_struggle_catalyst_secondary_character_involvement_either_trigger = {
#							CATALYST = catalyst_gave_independence_to_powerful_diff_faith_culture_vassal
#							CHAR = scope:recipient
#						}
#					}
#					activate_struggle_catalyst = {
#						catalyst = catalyst_gave_independence_to_powerful_diff_faith_culture_vassal
#						character = scope:puppet_or_actor
#					}
#				}
#			}
#
#			if = {
#				limit = {
#					NOT = {
#						any_held_title = {
#							is_de_jure_liege_or_above_target = scope:recipient.primary_title
#						}
#					}
#					any_character_struggle = {
#						involvement = involved
#						activate_struggle_catalyst_secondary_character_involvement_either_trigger = {
#							CATALYST = catalyst_independence_from_non_dejure_vassal
#							CHAR = scope:recipient
#						}
#					}
#				}
#				every_character_struggle = {
#					involvement = involved
#					limit = {
#						activate_struggle_catalyst_secondary_character_involvement_either_trigger = {
#							CATALYST = catalyst_independence_from_non_dejure_vassal
#							CHAR = scope:recipient
#						}
#					}
#					activate_struggle_catalyst = {
#						catalyst = catalyst_independence_from_non_dejure_vassal
#						character = scope:puppet_or_actor
#					}
#				}
#			}
#		}

		# Grant independence to non de_jure


		# If we're a clan this interaction affects unity
		add_clan_unity_interaction_effect = {
			CHARACTER = scope:puppet_or_actor
			TARGET = scope:recipient
			VALUE = medium_unity_loss
			DESC = clan_unity_grant_independence.desc
			REVERSE_NON_HOUSE_TARGET = no
		}
	}

	ai_will_do = {
		base = 0 #The AI should never do this!

		# Except in the context of Struggle
#		modifier = {
#			scope:recipient = {
#				any_character_struggle = {
#					involvement = involved
#				}
#			}
#			scope:puppet_or_actor = {
#				any_character_struggle = {
#					involvement = involved
#				}
#				NOT = {
#					any_held_title = {
#						is_de_jure_liege_or_above_target = scope:recipient.primary_title
#					}
#				}
#			}
#			add = {
#				value = 0
#				if = {
#					limit = {
#						scope:puppet_or_actor = {
#							any_character_struggle = {
#								phase_has_catalyst = catalyst_independence_from_non_dejure_vassal
#							}
#							has_character_flag = agenda_towards_escalation
#						}
#					}
#					add = -50
#				}
#				else_if = {
#					limit = {
#						scope:puppet_or_actor = {
#							any_character_struggle = {
#								phase_has_catalyst = catalyst_independence_from_non_dejure_vassal
#							}
#						}
#					}
#					add = 100
#				}
#			}
#		}

		# Unity modifiers
		evaluate_action_decreasing_house_unity = {
			VALUE = 10
		}
	}
}

expose_secret_interaction = {
	interface_priority = 120
	common_interaction = no
	category = interaction_category_hostile
	interface = blackmail
	icon = secret

	desc = expose_secret_interaction_desc

	is_shown = {
		exists = scope:puppet_or_actor
		scope:recipient = {
			any_secret = {
				is_known_by = scope:puppet_or_actor
			}
			this != scope:puppet_or_actor
			age > 10
		}
	}

	is_valid_showing_failures_only = {
	}

	on_accept = {
		scope:puppet_or_actor = {
			if = {
				limit = {
					is_landless_adventurer = yes
					has_perk = court_of_shadows_perk
				}
				add_prestige = {
					value = 100
					multiply = {
						value = scope:recipient.highest_held_title_tier
						add = 1
					}
					min = 50
				}
			}
			if = {
				limit = {
					exists = scope:target
				}
				scope:target = {
					expose_secret = scope:puppet_or_actor
				}
			}
			else = {
				every_known_secret = {
					limit = {
						secret_owner = scope:recipient
					}
					expose_secret = scope:puppet_or_actor
				}
			}
#			if = {
#				limit = {
#					has_title = title:e_minister_of_justice
#					top_participant_group:dynastic_cycle ?= {
#						NOT = { participant_group_type = other_rulers }
#					}
#					OR = {
#						scope:recipient = {
#							top_participant_group:dynastic_cycle ?= {
#								NOT = { participant_group_type = other_rulers }
#							}
#						}
#						scope:target.secret_target = {
#							top_participant_group:dynastic_cycle ?= {
#								NOT = { participant_group_type = other_rulers }
#							}
#						}
#					}
#				}
#				add_merit_if_relevant_effect = {
#					MERIT = minor_merit_value
#				}
#				if = {
#					limit = {
#						government_has_flag = government_has_influence
#					}
#					change_influence = {
#						value = minor_influence_gain
#						multiply = scope:recipient.highest_held_title_tier
#					}
#				}
#				situation:dynastic_cycle = {
#					if = {
#						limit = {
#							situation_top_has_catalyst = catalyst_minister_exposed_secret
#						}
#						trigger_situation_catalyst = {
#							catalyst = catalyst_minister_exposed_secret
#							character = scope:puppet_or_actor
#						}
#					}
#				}
#			}
			# Only get stressed/SP penalties if you don't have the parameter
			if = {
				limit = {
					NOT = { sp_hostile_schemes_except_murder_no_stress_or_fulfillment_trigger = yes }
				}
				stress_and_fulfillment_impact = {
					honest = minor_stress_impact_loss
					just = minor_stress_impact_loss
					shy = miniscule_stress_impact_gain
				}
			}
		}

		# recipient gets the penalties even if they have the parameter
		scope:recipient = {
			stress_and_fulfillment_impact = {
				honest = minor_stress_impact_loss
				just = minor_stress_impact_loss
				deceitful = minor_stress_impact_gain
			}
		}

		# If we're a clan this interaction affects unity
		add_clan_unity_interaction_effect = {
			CHARACTER = scope:puppet_or_actor
			TARGET = scope:recipient
			VALUE = major_unity_loss
			DESC = clan_unity_secret_exposure.desc
			REVERSE_NON_HOUSE_TARGET = no
		}
	}

	auto_accept = yes

	ai_will_do = {
		base = 0

		# Struggle
#		modifier = {
#			scope:recipient = {
#				any_character_struggle = {
#					involvement = involved
#				}
#				is_important_or_vip_struggle_character = yes
#			}
#			scope:puppet_or_actor = {
#				any_character_struggle = {
#					involvement = involved
#				}
#			}
#			add = {
#				value = 0
#				if = {
#					limit = {
#						scope:puppet_or_actor = {
#							any_character_struggle = {
#								phase_has_catalyst = catalyst_reveal_secret_important
#							}
#							has_character_flag = agenda_towards_escalation
#						}
#					}
#					add = 200
#				}
#				else_if = {
#					limit = {
#						scope:puppet_or_actor = {
#							any_character_struggle = {
#								phase_has_catalyst = catalyst_reveal_secret_important
#							}
#						}
#					}
#					add = -100
#				}
#			}
#		}
#		modifier = {
#			scope:recipient = {
#				any_character_struggle = {
#					involvement = involved
#				}
#				has_trait = fp3_struggle_supporter
#			}
#			scope:puppet_or_actor = {
#				any_character_struggle = {
#					involvement = involved
#				}
#			}
#			add = {
#				value = 0
#				if = {
#					limit = {
#						scope:puppet_or_actor = {
#							any_character_struggle = {
#								phase_has_catalyst = catalyst_reveal_secret_supporter
#							}
#							has_trait = fp3_struggle_detractor
#						}
#					}
#					add = 200
#				}
#				else_if = {
#					limit = {
#						scope:puppet_or_actor = {
#							any_character_struggle = {
#								phase_has_catalyst = catalyst_reveal_secret_supporter
#							}
#						}
#					}
#					add = -100
#				}
#			}
#		}
#		modifier = {
#			scope:recipient = {
#				any_character_struggle = {
#					involvement = involved
#				}
#				has_trait = fp3_struggle_detractor
#			}
#			scope:puppet_or_actor = {
#				any_character_struggle = {
#					involvement = involved
#				}
#			}
#			add = {
#				value = 0
#				if = {
#					limit = {
#						scope:puppet_or_actor = {
#							any_character_struggle = {
#								phase_has_catalyst = catalyst_reveal_secret_detractor
#							}
#							has_trait = fp3_struggle_supporter
#						}
#					}
#					add = 200
#				}
#				else_if = {
#					limit = {
#						scope:puppet_or_actor = {
#							any_character_struggle = {
#								phase_has_catalyst = catalyst_reveal_secret_detractor
#							}
#						}
#					}
#					add = -100
#				}
#			}
#		}

		# Unity modifiers
		evaluate_action_decreasing_house_unity = {
			VALUE = 100
		}
	}
}


