﻿# Interaction used to convert people when you reform or create a faith
ask_for_conversion_interaction = {
	category = interaction_category_religion
	special_interaction = request_conversion_interaction
	popup_on_receive = yes

	desc = compel_conversion_interaction_desc

	hidden = yes

	is_shown = {
		scope:actor.faith != scope:recipient.faith
		scope:recipient.liege ?= scope:actor
		NOT = { scope:recipient = { government_has_flag = government_is_landless_minority } }
		NOT = { scope:recipient = { culture = { has_cultural_parameter = cannot_convert_diasporia } } }
	}

	is_valid_showing_failures_only = {
		valid_ask_for_conversion_conditions_trigger = yes
	}

	ai_accept = {
		base = 0

		celestial_hierarchy_acceptance_modifier = {
			ACTOR = scope:actor
			RECIPIENT = scope:recipient
		}

		religion_demand_conversion_default_modifier = yes
		religion_demand_conversion_christian_situation_modifier = yes

		# We add a few extra modifiers if you have a state faith, to make the initial conversion rate more immersive and plausible
		modifier = {
			scope:actor = {
				government_allows = state_faith

				# If you fulfill a minimum amount of the below triggers, we consider that you hold enough sway within the realm to make it easier for others to abandon the state faith
				calc_true_if = {
					amount >= 4

					diplomacy >= excellent_skill_level
					learning >= excellent_skill_level
					has_trait = august # You finished the August lifestyle tree
					has_trait = theologian # You finished the Theologian lifestyle tree
					AND = {
						top_liege = this
						legitimacy_level >= 4
					}
					influence_level >= 3
					house = {
						OR = {
							is_dominant_family = yes
							is_powerful_family = yes
						}
					}
				}
			}
			add = {
				value = 50
				if = {
					limit = {
						scope:actor.influence_level = 5
					}
					add = 50
				}
				else_if = {
					limit = {
						scope:actor.influence_level >= 4
					}
					add = 25
				}
				if = {
					limit = {
						scope:actor = {
							top_liege = this
							legitimacy_level >= 5
						}
					}
					add = 50
				}
			}
			desc = STATE_FAITH_CREATE_FAITH_REASON
		}
		modifier = { # If you have the prophet perk, let's increase acceptance equal to half your diplomacy and learning
			scope:actor = {
				government_allows = state_faith
				has_perk = prophet_perk
			}
			add = {
				value = scope:actor.learning
				add = scope:actor.diplomacy
				multiply = 0.5
			}
			desc = HAS_PERK_PROPHET_REASON
		}

	}

	ai_min_reply_days = 1
	ai_max_reply_days = 5

	on_accept = {
		new_faith_created_conversion_effect = yes

		# If we're a clan this interaction affects unity
		accept_faith_conversion_add_clan_unity_effect = yes

		# If character is converting to the state faith, we add influence
		state_faith_conversion_add_piety_effect = yes

		# Piety gain from Struggle Phase
#		scope:actor = {
#			if = {
#				limit = {
#					any_character_struggle = {
#						involvement = involved
#						has_struggle_phase_parameter = piety_from_converting_involved_rulers
#						is_secondary_character_involvement_involved_trigger = {
#							CHAR = scope:recipient
#						}
#					}
#				}
#				add_piety = medium_piety_gain
#			}
#		}

		conversion_tenet_acts_of_the_apostles_effect = yes

		# If you have the Mendicant Preaching personal tenet we give you SP
		conversion_tenet_mendicant_preachers_effect = yes
	}

	on_decline = {
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_bad
				title = ask_for_conversion_decline_notification
				right_icon = scope:recipient
			}
		}

		# If we're a clan this interaction affects unity
		refuse_faith_conversion_add_clan_unity_effect = yes

		state_faith_refuse_conversion_add_piety_effect = yes
	}

	#Use hook
	send_option = {
		is_valid = {
			always = no # Only here to ensure that religion_demand_conversion_default_modifier doesn't error
		}
		flag = hook
		localization = SCHEME_HOOK
	}
	send_options_exclusive = no
}

ask_for_conversion_courtier_interaction = {
	category = interaction_category_religion
	icon = religious

	special_interaction = request_conversion_interaction
	ai_maybe = yes
	can_send_despite_rejection = yes

	desc = {
		desc = ask_for_conversion_interaction_desc
		triggered_desc = {
			trigger = {
				scope:actor = {
					refusing_conversion_is_crime_trigger = {
						CHARACTER = scope:recipient
					}
				}
				scope:recipient = {
					target_is_liege_or_above = scope:actor
				}
			}
			desc = demand_conversion_vassal_ruler_is_crime
		}
	}

	ai_targets = {
		ai_recipients = courtiers
		chance = 0.25
	}
	ai_target_quick_trigger = {
		adult = yes
	}
	ai_frequency_by_tier = {
		barony = 0
		county = 36
		duchy = 12
		kingdom = 12
		empire = 12
		hegemony = 12
	}

	is_available = {
		trigger_if = {
			limit = { is_ai = yes }
			is_adult = yes
		}
	}

	is_shown = {
		scope:actor.faith != scope:recipient.faith
		scope:recipient = { is_courtier_of = scope:actor }
		scope:recipient = { is_ruler = no }
		scope:recipient = { is_imprisoned = no }
		NOT = { scope:recipient = { government_has_flag = government_is_landless_minority } }
	}

	cooldown_against_recipient = { years = 15 }

	is_valid_showing_failures_only = {
		valid_demand_conversion_conditions_trigger = yes
	}

	ai_accept = {
		base = 0

		celestial_hierarchy_acceptance_modifier = {
			ACTOR = scope:actor
			RECIPIENT = scope:recipient
		}

		# Increase base chance
		modifier = {
			add = 50
			desc = EDUCATE_CHILD_ACTOR_IS_MY_LIEGE
		}
		religion_demand_conversion_default_modifier = yes
		religion_demand_conversion_christian_situation_modifier = yes
	}

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

	ai_min_reply_days = 1
	ai_max_reply_days = 5

	on_accept = {
		demand_conversion_interaction_effect = yes
		hidden_effect = {
			scope:actor = {
				send_interface_message = {
					type = event_religious_good
					title = ask_for_conversion_courtier_interaction.tt
					left_icon = scope:recipient
					scope:recipient = {
						show_as_tooltip = { demand_conversion_interaction_effect = yes }
					}
				}
			}
		}
		if = {
			limit = { scope:hook = yes }
			scope:actor = {
				if = {
					limit = {
						has_usable_hook = scope:recipient
					}
					use_hook = scope:recipient
				}
			}
			scope:recipient = {
				save_scope_value_as = {
					name = forcibly_converted
					value = yes
				}
			}
		}

		# If we're a clan this interaction affects unity
		accept_faith_conversion_add_clan_unity_effect = yes

		# If character is converting to the state faith, we add influence
		state_faith_conversion_add_piety_effect = yes

#		scope:actor = {
#			if = {
#				limit = {
#					any_character_struggle = {
#						involvement = involved
#						has_struggle_phase_parameter = piety_from_converting_involved_rulers
#						is_secondary_character_involvement_involved_trigger = {
#							CHAR = scope:recipient
#						}
#					}
#				}
#				add_piety = medium_piety_gain
#			}
#		}

		conversion_tenet_acts_of_the_apostles_effect = yes

		# If you have the Mendicant Preaching personal tenet we give you SP
		conversion_tenet_mendicant_preachers_effect = yes
	}

	on_decline = {
		#Negative opinions
		scope:recipient = {
			if = {
				limit = {
					scope:actor = {
						refusing_conversion_is_crime_trigger = {
							CHARACTER = scope:recipient
						}
					}
					scope:recipient = {
						target_is_liege_or_above = scope:actor
					}
				}
				reverse_add_opinion = {
					target = scope:actor
					modifier = illegal_resisted_conversion_opinion
					years = 10
				}
			}
			else = {
				add_opinion = {
					modifier = demanded_my_conversion_opinion
					target = scope:actor
					opinion = -10
				}
			}
		}
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_bad
				title = ask_for_conversion_decline_notification
				left_icon = scope:recipient
			}
		}

		# If we're a clan this interaction affects unity
		refuse_faith_conversion_add_clan_unity_effect = yes

		state_faith_refuse_conversion_add_piety_effect = yes
	}

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

	# Use hook
	send_option = {
		is_valid = {
			scope:actor = {
				has_usable_hook = scope:recipient
			}
			NOT = {
				scope:recipient = { is_imprisoned_by = scope:actor }
			}
		}
		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_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
			custom_tooltip = {
				text = not_same_realm_tt
				scope:recipient.top_liege = scope:actor.top_liege
			}
		}
		flag = influence_send_option
		localization = TRADE_INFLUENCE_FOR_BETTER_AI_ACCEPTANCE
	}
	send_options_exclusive = no


	ai_will_do = {
		base = 100

		modifier = { # The AI will only use a Hook if they couldn't otherwise do this
			scope:hook = yes
			add = -1
		}

		modifier = { # The AI doesn't really want to convert Diasporic culture courtiers
			scope:recipient = {
				faith.religion = religion:judaism_religion
				culture = {
					has_cultural_tradition = tradition_diasporic
				}
			}
			factor = 0
		}

		modifier = { # Do not convert Righteous faith subjects, unless disturbingly zealous
			factor = 0
			scope:actor = {
				ai_zeal < 100
				rite = {
					rite_hostility_level = {
						target = scope:recipient.rite
						value <= faith_fully_accepted_level
					}
				}
			}
		}

		modifier = { # Astray faiths require specific circumstances to demand conversion of
			factor = 0
			scope:actor = {
				has_tolerant_faith_or_culture_trigger = yes
				ai_zeal < 100
				rite = {
					rite_hostility_level = {
						target = scope:recipient.rite
						value <= faith_astray_level
					}
				}
			}
			NOT = {
				scope:recipient = {
					is_close_family_of = scope:actor
				}
			}
		}

		modifier = { # Astray faiths require specific circumstances to demand conversion of
			factor = 0
			scope:actor = {
				rite = { rite_has_doctrine = doctrine_pluralism_fundamentalist }
				ai_zeal < -10
				rite = {
					rite_hostility_level = {
						target = scope:recipient.rite
						value <= faith_astray_level
					}
				}
			}
			NOT = {
				scope:recipient = {
					is_close_family_of = scope:actor
				}
			}
		}

		modifier = { # Astray faiths require specific circumstances to demand conversion of
			factor = 0
			scope:actor = {
				NOR = {
					rite = { rite_has_doctrine = doctrine_pluralism_fundamentalist }
					has_tolerant_faith_or_culture_trigger = yes
				}
				ai_zeal < 25
				rite = {
					rite_hostility_level = {
						target = scope:recipient.rite
						value <= faith_astray_level
					}
				}
			}
			NOT = {
				scope:recipient = {
					is_close_family_of = scope:actor
				}
			}
		}

		modifier = { # Rulers with State Faith won't try to convert people with rites that are astray or better
			factor = 0
			scope:actor = {
				government_allows = state_faith
				primary_title.state_rite ?= {
					rite_hostility_level = {
						target = scope:recipient.rite
						value <= faith_astray_level
					}
				}
			}
		}
	}
}

# House head demand conversion
demand_conversion_interaction = {
	icon = religious
	category = interaction_category_religion
	popup_on_receive = yes
	pause_on_receive = yes
	can_send_despite_rejection = yes
	ai_maybe = yes

	notification_text = HOUSE_HEAD_DEMAND_CONVERSION

	is_shown = {
		scope:puppet_or_actor ?= {
			this != scope:recipient
			is_house_head = yes
			faith != scope:recipient.faith
			OR = {
				house ?= scope:recipient.house
				AND = { # House Bloc
					house.house_confederation ?= {
						scope:recipient.house.house_confederation ?= this
						has_cohesion_level_parameter = bloc_members_join_leaders_faith
					}
				}
			}
		}
		NOT = {
			scope:recipient = { # Use the vassal-liege interaction instead.
				is_ruler = yes
				target_is_liege_or_above = scope:puppet_or_actor
			}
		}
		scope:recipient = { # To avoid you converting someone's entire family, and then asking them. Restricting it to landed rulers at least gives them a chance to create their own cadet house.
			is_ruler = yes
		}
		NOT = { scope:recipient = { government_has_flag = government_is_landless_minority } }
		
		NOT = { scope:recipient = { culture = { has_cultural_parameter = cannot_convert_diasporia } } }
	}

	cooldown_against_recipient = { years = 15 }

	desc = {
		desc = demand_conversion_interaction_desc
		triggered_desc = {
			trigger = {
				scope:puppet_or_actor = {
					refusing_conversion_is_crime_trigger = {
						CHARACTER = scope:recipient
					}
				}
				scope:recipient = {
					target_is_liege_or_above = scope:puppet_or_actor
				}
			}
			desc = demand_conversion_vassal_ruler_is_crime
		}
	}

	is_valid_showing_failures_only = {
		valid_demand_conversion_conditions_trigger = yes
		trigger_if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				influence >= demand_conversion_influence_cost_value
			}
		}
	}

	cost = {
		influence = {
			value = demand_conversion_influence_cost_value
			if = {
				limit = { scope:is_puppet_action ?= yes }
				multiply = 0
			}
		}
	}

	on_accept = {
		if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				if = {
					limit = { demand_conversion_influence_cost_value > 0 }
					change_influence = {
						value = {
							value = demand_conversion_influence_cost_value
							max = influence
							multiply = -1
						}
					}
				}
			}
		}
		demand_conversion_interaction_effect = yes
		if = {
			limit = { scope:hook = yes }
			scope:puppet_or_actor = {
				use_hook = scope:recipient
			}
			scope:recipient = {
				save_scope_value_as = {
					name = forcibly_converted
					value = yes
				}
			}
		}
		scope:puppet_or_actor = {
			trigger_event = char_interaction.0181
		}

#		scope:puppet_or_actor = {
#			if = {
#				limit = {
#					any_character_struggle = {
#						involvement = involved
#						has_struggle_phase_parameter = piety_from_converting_involved_rulers
#						is_secondary_character_involvement_involved_trigger = {
#							CHAR = scope:recipient
#						}
#					}
#				}
#				add_piety = medium_piety_gain
#			}
#		}

		# If we're a clan this interaction affects unity
		accept_faith_conversion_add_clan_unity_effect = yes

		# If character is converting to the state faith, we add influence
		state_faith_conversion_add_piety_effect = yes

		conversion_tenet_acts_of_the_apostles_effect = yes

		# If you have the Mendicant Preaching personal tenet we give you SP
		conversion_tenet_mendicant_preachers_effect = yes
	}

	on_decline = {
		scope:recipient = {
			execute_decision = create_cadet_branch_decision
			show_as_tooltip = { create_cadet_branch = {} }
		}
		#Negative opinions
		scope:recipient = {
			if = {
				limit = {
					scope:puppet_or_actor = {
						refusing_conversion_is_crime_trigger = {
							CHARACTER = scope:recipient
						}
					}
					scope:recipient = {
						target_is_liege_or_above = scope:puppet_or_actor
					}
				}
				reverse_add_opinion = {
					target = scope:puppet_or_actor
					modifier = illegal_resisted_conversion_opinion
					years = 10
				}
			}
			else = {
				add_opinion = {
					modifier = demanded_my_conversion_opinion
					target = scope:puppet_or_actor
					opinion = -10
				}
			}
		}
		scope:puppet_or_actor = {
			trigger_event = char_interaction.0182
		}

		# If we're a clan this interaction affects unity
		refuse_faith_conversion_add_clan_unity_effect = yes

		state_faith_refuse_conversion_add_piety_effect = yes
	}

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

	#For loc
	on_auto_accept = {
		scope:recipient = {
			save_scope_value_as = {
				name = forcibly_converted
				value = yes
			}
		}
	}

	ai_accept = {
		base = 0

		celestial_hierarchy_acceptance_modifier = {
			ACTOR = scope:puppet_or_actor
			RECIPIENT = scope:recipient
		}

		# Increase base chance
		modifier = {
			add = 50
			desc = EDUCATE_CHILD_ACTOR_IS_MY_LIEGE
		}
		modifier = {
			add = 100
			NOT = {
				scope:recipient = {
					can_execute_decision = create_cadet_branch_decision
				}
			}
			desc = ASK_FOR_CONVERSION_CAN_NOT_CREATE_CADET_BRANCH
		}
		modifier = {
			add = -10
			scope:recipient = {
				can_execute_decision = create_cadet_branch_decision
			}
			desc = ASK_FOR_CONVERSION_CAN_CREATE_CADET_BRANCH
		}
		religion_demand_conversion_default_modifier = yes
		religion_demand_conversion_christian_situation_modifier = yes
	}

	can_send_despite_rejection = yes
	force_notification = yes

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

	send_option = { # EP3 Influence
		is_shown = { # Actor must have a government that uses influence
			scope:puppet_or_actor ?= {
				government_has_flag = government_has_influence
			}
		}
		is_valid = {
			# Actor has enough influence
			scope:puppet_or_actor = { influence >= medium_influence_value }
			# Both characters are within the same top realm
			custom_tooltip = {
				text = not_same_realm_tt
				scope:recipient.top_liege = scope:puppet_or_actor.top_liege
			}
		}
		flag = influence_send_option
		localization = TRADE_INFLUENCE_FOR_BETTER_AI_ACCEPTANCE
	}
	send_options_exclusive = no
}

demand_conversion_vassal_ruler_interaction = {
	category = interaction_category_religion
	icon = religious
	notification_text = LIEGE_DEMAND_CONVERSION

	ai_maybe = yes
	ai_min_reply_days = 4
	ai_max_reply_days = 9
	can_send_despite_rejection = yes
	ai_accept_negotiation = yes
	popup_on_receive = yes

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

	desc = {
		desc = ask_for_conversion_interaction_desc
		desc = line_break
		triggered_desc = {
			trigger = {
				NOT = { scope:recipient = { is_imprisoned_by = scope:puppet_or_actor } }
			}
			desc = might_ask_for_something_in_return_warning
		}
		triggered_desc = {
			trigger = {
				scope:puppet_or_actor = {
					refusing_conversion_is_crime_trigger = {
						CHARACTER = scope:recipient
					}
				}
			}
			desc = demand_conversion_vassal_ruler_is_crime
		}
	}

	on_decline_summary = stop_attacker_vassal_war_decline_summary

	is_available = {
		trigger_if = {
			limit = { is_ai = yes }
			is_adult = yes
		}
	}

	is_shown = {
		scope:puppet_or_actor ?= {
			NOT = { faith = scope:recipient.faith }
		}
		scope:recipient = {
			OR = {
				target_is_liege_or_above = scope:puppet_or_actor
				is_tributary_of = scope:puppet_or_actor
			}
			is_ai = yes
			is_ruler = yes
		}
		NOT = { scope:recipient = { government_has_flag = government_is_landless_minority } }
		NOT = { scope:recipient = { culture = { has_cultural_parameter = cannot_convert_diasporia } } }
	}

	cooldown_against_recipient = { years = 15 }

	is_valid_showing_failures_only = {
		valid_demand_conversion_conditions_trigger = yes
		trigger_if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				influence >= demand_conversion_influence_cost_value
			}
		}
		trigger_if = {
			limit = {
				scope:puppet_or_actor.domicile ?= {
					domicile_uses_culture_and_faith = yes
				}
				scope:recipient = {
					is_ruler = yes
					government_has_flag = government_is_in_steppe
				}
			}
			custom_tooltip = {
				text = nomads_must_inspire_tt
				always = no
			}
		}
	}

	auto_accept = {
		custom_description = {
			text = "spending_hook"
			subject = scope:puppet_or_actor
			object = scope:recipient
			scope:hook = yes
			scope:puppet_or_actor = { has_strong_hook = scope:recipient }
			NOT = { scope:recipient = { has_character_flag = ai_will_not_convert } }
		}
	}

	on_send = {
		pam_tax_nonbelievers_conversion_concession_effect = yes
	}

	cost = {
		influence = {
			value = demand_conversion_influence_cost_value
			if = {
				limit = { scope:is_puppet_action ?= yes }
				multiply = 0
			}
		}
	}

	on_accept = {
		if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				if = {
					limit = { demand_conversion_influence_cost_value > 0 }
					change_influence = {
						value = {
							value = demand_conversion_influence_cost_value
							max = influence
							multiply = -1
						}
					}
				}
			}
		}
		scope:puppet_or_actor = {
			trigger_event = religious_interaction.2002
		}
		demand_conversion_vassal_ruler_interaction_effect = yes

		# If we're a clan this interaction affects unity
		accept_faith_conversion_add_clan_unity_effect = yes

		# If character is converting to the state faith, we add influence
		state_faith_conversion_add_piety_effect = yes

#		scope:puppet_or_actor = {
#			if = {
#				limit = {
#					any_character_struggle = {
#						involvement = involved
#						has_struggle_phase_parameter = piety_from_converting_involved_rulers
#						is_secondary_character_involvement_involved_trigger = {
#							CHAR = scope:recipient
#						}
#					}
#				}
#				add_piety = medium_piety_gain
#			}
#		}

		conversion_tenet_acts_of_the_apostles_effect = yes

		# If you have the Mendicant Preaching personal tenet we give you SP
		conversion_tenet_mendicant_preachers_effect = yes
	}

	on_decline = {
		scope:recipient = {
			hidden_effect = {
				random_list = {
					80 = { # Conditional acceptance
						modifier = {
							factor = 0 # Heresiarchs never agree to convert
							scope:recipient = {
								has_trait = heresiarch
							}
						}
						ai_value_modifier = {
							ai_greed = 0.5
						}
						random_list = {
							10 = { #They ask for gold
								modifier = {
									add = 50 # More likely to ask for gold if they're poor
									scope:recipient.short_term_gold < medium_gold_value
								}
								modifier = {
									add = { # Much more likely to ask for gold involved in one of their own wars (they want to win).
										value = 50
										if = {
											# Especially true if they're in debt!
											limit = { gold < 0 }
											add = 150
										}
									}
									is_at_war = yes
									any_character_war = {
										is_war_leader = scope:recipient
									}
								}
								scope:puppet_or_actor = {
									trigger_event = {
										id = religious_interaction.2011
									}
								}
							}
							50 = { #They ask for a favor
								trigger = {
									exists = scope:recipient.capital_county
									NOT = { has_hook = scope:puppet_or_actor }
								}
								# Direct feudal vassals appreciate favors more (they can improve their contract).
								modifier = {
									add = {
										value = 50
										# This goes double for your Powerful Vassals. A better contract is likely to be much more important than a short-term payout.
										if = {
											limit = { is_powerful_vassal_of = scope:puppet_or_actor }
											add = 100
										}
									}
									this.liege = scope:puppet_or_actor
									government_has_flag = government_is_feudal
								}
								scope:puppet_or_actor = {
									trigger_event = {
										id = religious_interaction.2012
									}
								}
							}
							40 = { # They ask to study the faith first
							    trigger = {
							        # Must not already know the faith well
							        knows_rite_level = {
							            target = scope:puppet_or_actor.rite
							            value < 0.9
							        }
							        can_start_scheme = {
							            type = study_faith
							            target_character = scope:puppet_or_actor
							        }
							    }
							    # Higher weight if they would suffer severe penalties
							    modifier = {
							        add = 300
							        knows_rite_level = {
							            target = scope:puppet_or_actor.rite
							            value < 0.7
							        }
							    }
							    # Scholarly/theologian types prefer this
							    modifier = {
							        add = 10
							        has_trait = erudite
							    }
							    modifier = {
							        add = 10
							        has_trait = theologian
							    }
							    modifier = {
							        add = 10
							        OR = {
							        	has_trait = education_learning_3
							        	has_trait = education_learning_4
							        	has_trait = education_learning_5
							        }
							    }
							    modifier = {
							        add = 10
							        learning >= 12
							    }
							    scope:puppet_or_actor = {
							        trigger_event = {
							            id = religious_interaction.2015
							        }
							    }
							}
						}

					}
					20 = { # Full refuse
						modifier = {
							add = 20
							scope:recipient.demand_conversion_likelihood_calculation < 40
						}
						modifier = {
							add = 20
							scope:recipient.demand_conversion_likelihood_calculation < 20
						}
						modifier = {
							add = 50
							scope:recipient.demand_conversion_likelihood_calculation < 0
						}
						scope:puppet_or_actor = {
							trigger_event = {
								id = religious_interaction.2003
							}
						}
					}
				}
			}
			custom_tooltip = demand_conversion_vassal_ruler_does_not_convert
			show_as_tooltip = {
				#Negative opinions
				add_opinion = {
					modifier = demanded_my_conversion_opinion
					target = scope:puppet_or_actor
					opinion = -10
				}
				scope:puppet_or_actor = {
					if = {
						limit = {
							refusing_conversion_is_crime_trigger = {
								CHARACTER = scope:recipient
							}
						}
						custom_tooltip = action_can_lawfully_imprison_label
					}
				}
				# If appropriate, give 'em piety.
				give_piety_for_clinging_to_state_faith_effect = yes
			}
		}

		# If we're a clan this interaction affects unity
		refuse_faith_conversion_add_clan_unity_effect = yes
	}

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

	send_option = { # EP3 Influence
		is_shown = { # Actor must have a government that uses influence
			scope:puppet_or_actor ?= {
				government_has_flag = government_has_influence
			}
		}
		is_valid = {
			# Actor has enough influence
			scope:puppet_or_actor = { influence >= medium_influence_value }
			# Both characters are within the same top realm
			custom_tooltip = {
				text = not_same_realm_tt
				scope:recipient.top_liege = scope:puppet_or_actor.top_liege
			}
		}
		flag = influence_send_option
		localization = TRADE_INFLUENCE_FOR_BETTER_AI_ACCEPTANCE
	}

	send_option = {
		is_shown = {
			scope:puppet_or_actor = {
				has_personal_tenet_flag = tax_nonbelievers_conversion_concession
			}
			scope:recipient = {
				is_vassal_of = scope:puppet_or_actor
			}
		}
		is_valid = {
			scope:puppet_or_actor = {
				gold >= medium_gold_value
			}
		}
		starts_enabled = {
			scope:puppet_or_actor = {
				scope:actor = { is_ai = yes }
				short_term_gold >= medium_gold_value
			}
			scope:recipient.demand_conversion_likelihood_calculation < 70
		}
		flag = tax_nonbelievers_conversion_concession
		localization = pam_tax_nonbelievers_conversion_concession_option
		current_description = pam_tax_nonbelievers_conversion_concession_option_desc
	}
	send_options_exclusive = no

	ai_will_do = {
		base = 100

		modifier = { # Make sure the AI uses hooks for this as it's % based
			scope:hook = yes
			add = 1
		}
		modifier = {
			scope:tax_nonbelievers_conversion_concession = yes
			scope:recipient.demand_conversion_likelihood_calculation < 70
			add = 1
		}

		modifier = {
			factor = 0
			scope:recipient.demand_conversion_likelihood_calculation < 10
			NOT = {
				scope:puppet_or_actor = {
					refusing_conversion_is_crime_trigger = {
						CHARACTER = scope:recipient
					}
				}
			}
		}

		modifier = {
			factor = 0
			scope:recipient.demand_conversion_likelihood_calculation < 70
			scope:puppet_or_actor = {
				gold < demand_conversion_bribe_size
			}
		}

		modifier = {
			factor = 0
			scope:recipient.demand_conversion_likelihood_calculation < 90
			scope:puppet_or_actor = {
				culture = {
					has_cultural_parameter = less_likely_to_force_conversion
				}
			}
		}

		modifier = { # Do not convert Righteous faith subjects, unless disturbingly zealous
			factor = 0
			scope:puppet_or_actor = {
				ai_zeal < 100
				rite = {
					rite_hostility_level = {
						target = scope:recipient.rite
						value <= faith_fully_accepted_level
					}
				}
			}
			NOT = { # If the subject has one of your holy sites, always try to convert
				scope:puppet_or_actor.faith = {
					any_holy_site = {
						holy_site_county ?= {
							holder ?= {
								OR = {
									this = scope:recipient
									is_vassal_or_below_of = scope:recipient
								}
							}
						}
					}
				}
			}
		}

		modifier = { # Astray faiths require specific circumstances to demand conversion of
			factor = 0
			scope:puppet_or_actor = {
				has_tolerant_faith_or_culture_trigger = yes
				ai_zeal < 100
				rite = {
					rite_hostility_level = {
						target = scope:recipient.rite
						value <= faith_astray_level
					}
				}
			}
			NOT = { # If the subject has one of your holy sites, always try to convert
				scope:puppet_or_actor.faith = {
					any_holy_site = {
						holy_site_county ?= {
							holder ?= {
								OR = {
									this = scope:recipient
									is_vassal_or_below_of = scope:recipient
								}
							}
						}
					}
				}
			}
			NOT = {
				scope:recipient = {
					is_close_family_of = scope:puppet_or_actor
				}
			}
		}

		modifier = { # Astray faiths require specific circumstances to demand conversion of
			factor = 0
			scope:puppet_or_actor = {
				rite = { rite_has_doctrine = doctrine_pluralism_fundamentalist }
				ai_zeal < -10
				rite = {
					rite_hostility_level = {
						target = scope:recipient.rite
						value <= faith_astray_level
					}
				}
			}
			NOT = { # If the subject has one of your holy sites, always try to convert
				scope:puppet_or_actor.faith = {
					any_holy_site = {
						holy_site_county ?= {
							holder ?= {
								OR = {
									this = scope:recipient
									is_vassal_or_below_of = scope:recipient
								}
							}
						}
					}
				}
			}
			NOT = {
				scope:recipient = {
					is_close_family_of = scope:puppet_or_actor
				}
			}
		}

		modifier = { # Astray faiths require specific circumstances to demand conversion of
			factor = 0
			scope:puppet_or_actor = {
				NOR = {
					rite = { rite_has_doctrine = doctrine_pluralism_fundamentalist }
					has_tolerant_faith_or_culture_trigger = yes
				}
				ai_zeal < 25
				rite = {
					rite_hostility_level = {
						target = scope:recipient.rite
						value <= faith_astray_level
					}
				}
			}
			NOT = { # If the subject has one of your holy sites, always try to convert
				scope:puppet_or_actor.faith = {
					any_holy_site = {
						holy_site_county ?= {
							holder ?= {
								OR = {
									this = scope:recipient
									is_vassal_or_below_of = scope:recipient
								}
							}
						}
					}
				}
			}
		}

		modifier = { # Rulers with state faith won't try to convert people with rites that are astray or better
			factor = 0
			scope:puppet_or_actor = {
				government_allows = state_faith
				primary_title.state_rite ?= {
					rite_hostility_level = {
						target = scope:recipient.rite
						value <= faith_astray_level
					}
				}
			}
		}
	}
	ai_accept = {
		base = 0

		celestial_hierarchy_acceptance_modifier = {
			ACTOR = scope:puppet_or_actor
			RECIPIENT = scope:recipient
		}

		# Increase base chance
		modifier = {
			add = 50
			desc = EDUCATE_CHILD_ACTOR_IS_MY_LIEGE
		}
		religion_demand_conversion_default_modifier = yes
		religion_demand_conversion_christian_situation_modifier = yes

		modifier = {
			desc = might_ask_for_something_in_return_warning_line_break
			add = 0
		}
		modifier = {
			add = 25
			scope:tax_nonbelievers_conversion_concession = yes
			desc = pam_tax_nonbelievers_conversion_acceptance_reason
		}
	}
}

demand_conversion_player_ruler_interaction = {
	category = interaction_category_religion
	desc = ask_for_conversion_interaction_desc
	notification_text = LIEGE_DEMAND_CONVERSION
	popup_on_receive = yes
	pause_on_receive = yes
	icon = religious

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

	is_available = {
		trigger_if = {
			limit = { is_ai = yes }
			is_adult = yes
		}
	}

	is_shown = {
		scope:puppet_or_actor ?= {
			NOT = { faith = scope:recipient.faith }
		}
		scope:recipient = {
			is_ai = no
			target_is_liege_or_above = scope:puppet_or_actor
		}
		NOT = { scope:recipient = { government_has_flag = government_is_landless_minority } }
		NOT = { scope:recipient = { culture = { has_cultural_parameter = cannot_convert_diasporia } } }
	}

	cooldown_against_recipient = { years = 15 }

	is_valid_showing_failures_only = {
		valid_demand_conversion_conditions_trigger = yes
	}

	send_option = {
		is_valid = {
			scope:puppet_or_actor = {
				has_strong_usable_hook = scope:recipient
			}
		}
		flag = demand_conversion_hook
		localization = GENERIC_SPEND_A_HOOK
	}
	should_use_extra_icon = {
		scope:puppet_or_actor = { has_strong_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"


	send_options_exclusive = no

	auto_accept = {
		custom_description = {
			text = "spending_hook"
			subject = scope:puppet_or_actor
			object = scope:recipient
			scope:demand_conversion_hook = yes
		}
	}

	# Runs in addition to on_accept when auto-accepted, so no conversion effects here
	on_auto_accept = {
		scope:recipient = {
			save_scope_value_as = {
				name = forcibly_converted
				value = yes
			}
			trigger_event = religious_interaction.2021
		}
	}

	on_accept = {
		# Do conversion
		demand_conversion_player_ruler_interaction_effect = yes
		scope:puppet_or_actor = {
			trigger_event = char_interaction.0190
		}

		# If we're a clan this interaction affects unity
		accept_faith_conversion_add_clan_unity_effect = yes

		# If character is converting to the state faith, we add influence
		state_faith_conversion_add_piety_effect = yes

#		scope:puppet_or_actor = {
#			if = {
#				limit = {
#					any_character_struggle = {
#						involvement = involved
#						has_struggle_phase_parameter = piety_from_converting_involved_rulers
#						is_secondary_character_involvement_involved_trigger = {
#							CHAR = scope:recipient
#						}
#					}
#				}
#				add_piety = medium_piety_gain
#			}
#		}

		conversion_tenet_acts_of_the_apostles_effect = yes

		# If you have the Mendicant Preaching personal tenet we give you SP
		conversion_tenet_mendicant_preachers_effect = yes
	}

	on_decline = {
		scope:puppet_or_actor = {
			#Crime if relevant
			if = {
				limit = {
					refusing_conversion_is_crime_trigger = {
						CHARACTER = scope:recipient
					}
				}
				add_opinion = {
					target = scope:recipient
					modifier = illegal_resisted_conversion_opinion
					years = 15
				}
			}
			else = {
				add_opinion = {
					target = scope:recipient
					modifier = resisted_conversion_opinion
					years = 15
				}
			}
			trigger_event = char_interaction.0191
		}

		# If we're a clan this interaction affects unity
		refuse_faith_conversion_add_clan_unity_effect = yes

		state_faith_refuse_conversion_add_piety_effect = yes
	}

	ai_will_do = {
		base = 100

		modifier = {
			scope:hook = yes
			add = 1
		}

		modifier = {
			# Deliberately no crime exemption here, unlike the vassal variant: don't hound zealous players
			factor = 0
			scope:recipient.demand_conversion_likelihood_calculation < 10
		}

		modifier = { # Do not convert Righteous faith subjects, unless disturbingly zealous
			factor = 0
			scope:puppet_or_actor = {
				ai_zeal < 100
				rite = {
					rite_hostility_level = {
						target = scope:recipient.rite
						value <= faith_fully_accepted_level
					}
				}
			}
			NOT = { # If the subject has one of your holy sites, always try to convert
				scope:puppet_or_actor.faith = {
					any_holy_site = {
						holy_site_county ?= {
							holder ?= {
								OR = {
									this = scope:recipient
									is_vassal_or_below_of = scope:recipient
								}
							}
						}
					}
				}
			}
		}

		modifier = { # Astray faiths require specific circumstances to demand conversion of
			factor = 0
			scope:puppet_or_actor = {
				has_tolerant_faith_or_culture_trigger = yes
				ai_zeal < 100
				rite = {
					rite_hostility_level = {
						target = scope:recipient.rite
						value <= faith_astray_level
					}
				}
			}
			NOT = { # If the subject has one of your holy sites, always try to convert
				scope:puppet_or_actor.faith = {
					any_holy_site = {
						holy_site_county ?= {
							holder ?= {
								OR = {
									this = scope:recipient
									is_vassal_or_below_of = scope:recipient
								}
							}
						}
					}
				}
			}
			NOT = {
				scope:recipient = {
					is_close_family_of = scope:puppet_or_actor
				}
			}
		}

		modifier = { # Astray faiths require specific circumstances to demand conversion of
			factor = 0
			scope:puppet_or_actor = {
				rite = { rite_has_doctrine = doctrine_pluralism_fundamentalist }
				ai_zeal < -10
				rite = {
					rite_hostility_level = {
						target = scope:recipient.rite
						value <= faith_astray_level
					}
				}
			}
			NOT = { # If the subject has one of your holy sites, always try to convert
				scope:puppet_or_actor.faith = {
					any_holy_site = {
						holy_site_county ?= {
							holder ?= {
								OR = {
									this = scope:recipient
									is_vassal_or_below_of = scope:recipient
								}
							}
						}
					}
				}
			}
			NOT = {
				scope:recipient = {
					is_close_family_of = scope:puppet_or_actor
				}
			}
		}

		modifier = { # Astray faiths require specific circumstances to demand conversion of
			factor = 0
			scope:puppet_or_actor = {
				NOR = {
					rite = { rite_has_doctrine = doctrine_pluralism_fundamentalist }
					has_tolerant_faith_or_culture_trigger = yes
				}
				ai_zeal < 25
				rite = {
					rite_hostility_level = {
						target = scope:recipient.rite
						value <= faith_astray_level
					}
				}
			}
			NOT = { # If the subject has one of your holy sites, always try to convert
				scope:puppet_or_actor.faith = {
					any_holy_site = {
						holy_site_county ?= {
							holder ?= {
								OR = {
									this = scope:recipient
									is_vassal_or_below_of = scope:recipient
								}
							}
						}
					}
				}
			}
			NOT = {
				scope:recipient = {
					is_close_family_of = scope:puppet_or_actor
				}
			}
		}

		modifier = { # Rulers with state faith won't try to convert people with rites that are astray or better
			factor = 0
			scope:puppet_or_actor = {
				government_allows = state_faith
				primary_title.state_rite ?= {
					rite_hostility_level = {
						target = scope:recipient.rite
						value <= faith_astray_level
					}
				}
			}
		}
	}
}

# Compel Conversion
demand_conversion_minister_rites_interaction = {
	category = interaction_category_religion
	icon = religious
	notification_text = CONVERT_TO_RELIGION

	ai_maybe = yes
	ai_min_reply_days = 4
	ai_max_reply_days = 9
	can_send_despite_rejection = no
	popup_on_receive = yes

	desc = {
		desc = ask_for_conversion_interaction_desc
		desc = line_break
		desc = demand_conversion_vassal_ruler_is_crime
	}

	on_decline_summary = stop_attacker_vassal_war_decline_summary

	is_shown = {
		scope:puppet_or_actor ?= {
			is_ai = no
			has_title = title:e_minister_of_rites
			scope:recipient = {
				top_liege ?= scope:puppet_or_actor.top_liege
				this != top_liege
				rite ?= {
					OR = {
						rite_hostility_level = {
							target = scope:puppet_or_actor.rite
							value >= faith_hostile_level
						}
						rite_hostility_level = {
							target = scope:puppet_or_actor.top_liege.rite
							value >= faith_hostile_level
						}
					}
				}
				is_ai = yes
				is_ruler = yes
			}
		}
		NOT = { scope:recipient = { government_has_flag = government_is_landless_minority } }
	}

	cooldown_against_recipient = { years = 15 }

	is_valid_showing_failures_only = {
		valid_demand_conversion_conditions_trigger = yes
		trigger_if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				treasury >= demand_conversion_minister_rites_treasury_cost_value
			}
		}
	}

	on_send = {
	}

	cost = {
		treasury = {
			value = demand_conversion_minister_rites_treasury_cost_value
			if = {
				limit = { scope:is_puppet_action ?= yes }
				multiply = 0
			}
		}
	}

	on_accept = {
		if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				if = {
					limit = { demand_conversion_minister_rites_treasury_cost_value > 0 }
					remove_treasury = {
						value = demand_conversion_minister_rites_treasury_cost_value
					}
				}
			}
		}
		switch = {
			trigger = yes
			scope:convert_to_minister_faith = {
				scope:puppet_or_actor.rite = {
					save_scope_as = conversion_rite
				}
			}
			scope:convert_to_top_liege_faith = {
				scope:puppet_or_actor.top_liege.rite = {
					save_scope_as = conversion_rite
				}
			}
			scope:convert_to_realm_capital_faith = {
				scope:puppet_or_actor.top_liege.capital_county.rite = {
					save_scope_as = conversion_rite
				}
			}
		}
		scope:puppet_or_actor = {
			trigger_event = religious_interaction.2002
		}
		demand_conversion_vassal_ruler_interaction_effect = yes

		# If we're a clan this interaction affects unity
		accept_faith_conversion_add_clan_unity_effect = yes

		show_as_tooltip = {
			scope:puppet_or_actor = {
				change_influence = {
					value = minor_influence_gain
					multiply = scope:recipient.primary_title.tier
				}
				add_piety = {
					value = minor_piety_gain
					multiply = scope:recipient.primary_title.tier
				}
			}
		}

		conversion_tenet_acts_of_the_apostles_effect = yes

		# If you have the Mendicant Preaching personal tenet we give you SP
		conversion_tenet_mendicant_preachers_effect = yes
	}

	on_decline = {
		switch = {
			trigger = yes
			scope:convert_to_minister_faith = {
				scope:puppet_or_actor.rite = {
					save_scope_as = conversion_rite
				}
			}
			scope:convert_to_top_liege_faith = {
				scope:puppet_or_actor.top_liege.rite = {
					save_scope_as = conversion_rite
				}
			}
			scope:convert_to_realm_capital_faith = {
				scope:puppet_or_actor.top_liege.capital_county.rite = {
					save_scope_as = conversion_rite
				}
			}
		}
		scope:recipient = {
			hidden_effect = {
				random_list = {
					80 = { # Conditional acceptance
						modifier = {
							factor = 0 # Heresiarchs never agree to convert
							scope:recipient = {
								has_trait = heresiarch
							}
						}
						ai_value_modifier = {
							ai_greed = 0.5
						}
						random_list = {
							50 = { #They ask for gold
								modifier = {
									add = 50 # More likely to ask for gold if they're poor
									scope:recipient.short_term_gold < medium_gold_value
								}
								modifier = {
									add = { # Much more likely to ask for gold involved in one of their own wars (they want to win).
										value = 50
										if = {
											# Especially true if they're in debt!
											limit = { gold < 0 }
											add = 150
										}
									}
									is_at_war = yes
									any_character_war = {
										is_war_leader = scope:recipient
									}
								}
								scope:puppet_or_actor = {
									trigger_event = {
										id = religious_interaction.2011
									}
								}
							}
							500 = { #They ask for a favor
								trigger = {
									exists = scope:recipient.capital_county
									NOT = { has_hook = scope:puppet_or_actor }
								}
								# Direct feudal vassals appreciate favors more (they can improve their contract).
								modifier = {
									add = {
										value = 50
										# This goes double for your Powerful Vassals. A better contract is likely to be much more important than a short-term payout.
										if = {
											limit = { is_powerful_vassal_of = scope:puppet_or_actor }
											add = 100
										}
									}
									this.liege = scope:puppet_or_actor
									government_has_flag = government_is_feudal
								}
								scope:puppet_or_actor = {
									trigger_event = {
										id = religious_interaction.2012
									}
								}
							}
						}

					}
					20 = { # Full refuse
						modifier = {
							add = 20
							scope:recipient.demand_conversion_likelihood_calculation < 40
						}
						modifier = {
							add = 20
							scope:recipient.demand_conversion_likelihood_calculation < 20
						}
						modifier = {
							add = 50
							scope:recipient.demand_conversion_likelihood_calculation < 0
						}
						scope:puppet_or_actor = {
							trigger_event = {
								id = religious_interaction.2003
							}
						}
					}
				}
			}
			custom_tooltip = demand_conversion_vassal_ruler_does_not_convert
			show_as_tooltip = {
				#Negative opinions
				add_opinion = {
					modifier = compelled_me_to_convert_opinion
					target = scope:puppet_or_actor
					opinion = -10
				}
				scope:puppet_or_actor = {
					if = {
						limit = {
							refusing_conversion_is_crime_trigger = {
								CHARACTER = scope:recipient
							}
						}
						custom_tooltip = action_can_lawfully_imprison_label
					}
				}
				# If appropriate, give 'em piety.
				give_piety_for_clinging_to_state_faith_effect = yes
			}
		}
	}

	# Use hook
	send_option = {
		flag = convert_to_minister_faith
		localization = MINISTER_FAITH
	}

	send_option = {
		is_shown = {
			scope:puppet_or_actor.top_liege.faith != scope:puppet_or_actor.faith
		}
		flag = convert_to_top_liege_faith
		localization = TOP_LIEGE_FAITH
	}

	send_option = {
		is_shown = {
			scope:puppet_or_actor.top_liege.capital_county.faith = {
				NOR = {
					this = scope:puppet_or_actor.top_liege.faith
					this = scope:puppet_or_actor.faith
				}
			}
		}
		flag = convert_to_realm_capital_faith
		localization = CAPITAL_FAITH
	}

	ai_accept = {
		base = 0
		# Increase base chance

		celestial_hierarchy_acceptance_modifier = {
			ACTOR = scope:puppet_or_actor
			RECIPIENT = scope:recipient
		}

		modifier = {
			add = 50
			desc = ACTOR_IS_MINISTER_OF_RITES
		}
		modifier = {
			add = 25
			trigger = {
				scope:puppet_or_actor.top_liege = {
					OR = {
						has_realm_law = celestial_bureaucracy_0
						has_realm_law = celestial_bureaucracy_1
					}
				}
			}
			desc = IMPRESSED_BY_AUTHORITY
		}
		modifier = {
			add = 50
			trigger = {
				scope:puppet_or_actor.top_liege = {
					has_realm_law = celestial_bureaucracy_2
				}
			}
			desc = OVERWHELMED_BY_AUTHORITY
		}
		modifier = {
			add = 75
			trigger = {
				scope:puppet_or_actor.top_liege = {
					has_realm_law = celestial_bureaucracy_3
				}
			}
			desc = OVERWHELMED_BY_AUTHORITY
		}
		modifier = {
			add = 25
			trigger = {
				scope:puppet_or_actor = {
					has_hook = scope:recipient
				}
			}
			desc = HAS_A_HOOK
		}
		religion_demand_conversion_default_modifier = yes
		religion_demand_conversion_christian_situation_modifier = yes
		modifier = {
			desc = might_ask_for_something_in_return_warning_line_break
			add = 0
		}
	}
}

convert_to_religion_interaction = {
	category = interaction_category_religion
	icon = religious


	desc = convert_to_religion_interaction_desc

	notification_text = CONVERT_TO_RELIGION
	ignores_pending_interaction_block = yes

	is_shown = {
		scope:puppet_or_actor ?= {
			NOT = { faith = scope:recipient.faith }
			is_landless_ruler = no
			# They're your overlord
			OR = {
				target_is_liege_or_above = scope:recipient
				is_tributary_of = scope:recipient
			}
			# And you've never HumSac'd a tolerated HoF.
			NAND = {
				has_variable_list = humsacd_hofs
				is_target_in_variable_list = {
					name = humsacd_hofs
					target = scope:recipient.faith
				}
			}
		}
		NOT = { scope:actor = { government_has_flag = government_is_landless_minority } }
		OR = {
			is_ai = no
			NOT = { scope:actor = { culture = { has_cultural_parameter = cannot_convert_diasporia } } }
		}
	}

	is_valid_showing_failures_only = {
	}

	auto_accept = yes

	ai_min_reply_days = 1
	ai_max_reply_days = 5

	on_send = {
		# Show conversion preview - this can be canceled, but it's fine since the conversion is voluntary
		## If we have a valid state faith, we go there.
		if = {
			limit = {
				scope:puppet_or_actor = {
					government_allows = state_faith
				}
				scope:puppet_or_actor.top_liege.primary_title.state_rite ?= scope:recipient.rite
			}
			decision:adopt_state_faith = {
				open_view_data = {
					view = decision_detail
					player = scope:puppet_or_actor
				}
			}
		}
		## Otherwise, go to the usual place.
		else = {
			scope:recipient.rite = {
				open_view_data = {
					view = faith_conversion
					player = scope:puppet_or_actor # interaction effects are executed for all clients, make sure to open the window only for the actor
				}
			}
		}
	}

	on_accept = {
		custom_tooltip = {
			text = open_faith_conversion_view_tt
		}
	}

	ai_accept = {
		base = 0
	}

	ai_will_do = {
		base = 0
	}
}

convert_to_religion_adventurer_interaction = {
	category = interaction_category_religion
	icon = religious


	desc = convert_to_religion_interaction_desc

	notification_text = CONVERT_TO_RELIGION
	ignores_pending_interaction_block = yes

	is_available = {
		has_government = landless_adventurer_government
	}

	is_shown = {
		scope:actor.faith != scope:recipient.faith
		scope:actor = {
			# They're either your friend or your spouse
			OR = {
				target_is_liege_or_above = scope:recipient
				any_consort = {
					this = scope:recipient
				}
				any_relation = {
					type = friend
					this = scope:recipient
				}
			}
			# And you've never HumSac'd a tolerated HoF.
			NAND = {
				has_variable_list = humsacd_hofs
				is_target_in_variable_list = {
					name = humsacd_hofs
					target = scope:recipient.faith
				}
			}
		}
	}

	is_valid_showing_failures_only = {
	}

	auto_accept = yes

	ai_min_reply_days = 1
	ai_max_reply_days = 5

	on_accept = {
		scope:actor = {
			hidden_effect = { faith = { save_scope_as = old_faith } }
			set_character_faith = scope:recipient.faith
			trigger_event = {
				on_action = on_faith_conversion
			}
		}
	}

	ai_accept = {
		base = 0
	}

	ai_will_do = {
		base = 0
	}
}

convert_at_war_interaction = {
	category = interaction_category_religion
	icon = religious


	desc = convert_at_war_interaction_desc

	notification_text = CONVERT_AT_WAR_INTERACTION_NOTIFICATION

	is_available = {
		trigger_if = {
			limit = { is_ai = yes }
			ai_zeal < 100
			OR = {
				faith ?= {
					OR = {
						has_doctrine_parameter = unreformed
						fervor <= 25
					}
				}
				rite ?= { rite_has_parameter = unattractive_for_character_conversions }
			}
		}
	}

	is_shown = {
		scope:puppet_or_actor ?= {
			NOT = { faith = scope:recipient.faith }
			any_character_war = {
				primary_defender ?= scope:puppet_or_actor
				using_non_ghw_holy_war_cb_trigger = yes
				primary_attacker ?= scope:recipient
			}
			NOR = {
				government_has_flag = government_is_holy_order
				#They can convert
				scope:puppet_or_actor.faith.religious_head ?= scope:puppet_or_actor
				#They're neither your liege nor your spouse (so this isn't shown with convert_to_religion_interaction)
				target_is_liege_or_above = scope:recipient
				any_spouse = {
					this = scope:recipient
				}
				# And you've never HumSac'd a tolerated HoF.
				AND = {
					has_variable_list = humsacd_hofs
					is_target_in_variable_list = {
						name = humsacd_hofs
						target = scope:recipient.faith
					}
				}
			}
		}
	}


	is_valid_showing_failures_only = {
	}


	ai_accept = {
		base = 100 #Ai always says yes
	}

	ai_min_reply_days = 1
	ai_max_reply_days = 3

	cooldown_against_recipient = { years = 10 }

	on_accept = {
		scope:puppet_or_actor = {
			show_as_tooltip = { convert_at_war_interaction_effect = yes }
			trigger_event = religious_interaction.2500
		}
	}

	on_decline = {
		scope:puppet_or_actor = {
			show_as_tooltip = {
				add_piety_level = -1
				stress_and_fulfillment_impact = { zealous = major_stress_impact_gain }
			}
			trigger_event = religious_interaction.2501
		}
	}

	ai_targets = {
		ai_recipients = primary_war_enemies
	}

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

	ai_will_do = {
		base = 0

		ai_value_modifier = {
			who = scope:puppet_or_actor
			ai_zeal = -1
			ai_boldness = -0.5
			max = 40
		}
		modifier = {
			scope:puppet_or_actor = {
				any_character_war = {
					primary_attacker = scope:recipient
					primary_defender = scope:puppet_or_actor
					attacker_war_score >= 30
				}
			}
			add = 5
		}
		modifier = {
			scope:puppet_or_actor = {
				any_character_war = {
					primary_attacker = scope:recipient
					primary_defender = scope:puppet_or_actor
					attacker_war_score >= 50
				}
			}
			add = 10
		}
		modifier = {
			scope:puppet_or_actor = {
				any_character_war = {
					primary_attacker = scope:recipient
					primary_defender = scope:puppet_or_actor
					attacker_war_score >= 80
				}
			}
			add = 15
		}
		modifier = {
			scope:puppet_or_actor.faith = {
				fervor < 50
			}
			scope:recipient.faith = {
				fervor >= 50
			}
			add = 5
		}
		modifier = {
			scope:puppet_or_actor.faith = {
				fervor <= 25
			}
			scope:recipient.faith = {
				fervor >= 50
			}
			add = 5
		}
		modifier = {
			scope:puppet_or_actor.faith = {
				fervor <= 25
			}
			scope:recipient.faith = {
				fervor >= 75
			}
			add = 5
		}
		modifier = {
			scope:puppet_or_actor.faith = {
				fervor >= 75
			}
			add = -10
		}
		modifier = {
			scope:puppet_or_actor.faith = {
				fervor >= 50
			}
			add = -5
		}
		modifier = {
			scope:recipient.faith = {
				fervor <= 25
			}
			add = -10
		}
		modifier = {
			scope:recipient.faith = {
				fervor <= 15
			}
			add = -20
		}
		modifier = {
			scope:recipient.faith = {
				fervor <= 10
			}
			add = -30
		}
		modifier = {
			scope:recipient.faith.fervor < scope:puppet_or_actor.faith.fervor
			factor = 0
		}
		modifier = { # Big rulers shouldn't convert arbitrarily
			scope:puppet_or_actor = {
				highest_held_title_tier >= tier_kingdom
				sub_realm_size >= 10
				NOT = {
					has_trait = lunatic
				}
			}
			factor = 0
		}
	}
}


####################
# Communion tenets #
# by Sean Hughes	#
####################

seek_indulgences_interaction = {
	icon = letter_of_indulgence
	category = interaction_category_religion
	interface_priority = 110

	desc = seek_indulgences_interaction_desc

	notification_text = RELIGIOUS_HEAD_SEEK_INDULGENCES
	greeting = positive
	ai_maybe = yes

	is_available = {
		trigger_if = {
			limit = {
				is_ai = yes
			}
			NOR = {
				has_trait = cynical
				has_character_flag = hof_request_cooldown
			}
			short_term_gold >= head_of_faith_gold_value
		}
	}

	is_shown = {
		scope:recipient != scope:puppet_or_actor
		scope:puppet_or_actor ?= {
			is_playable_character = yes
			faith ?= {
				OR = {
					has_doctrine = doctrine_spiritual_head
					has_doctrine = doctrine_temporal_head
					has_doctrine_parameter = has_clerical_regions
				}
				faith_has_sacraments_central_trigger = yes
			}
			rite ?= {
				NOT = {
					rite_has_parameter = no_seek_indulgences
				}
			}
			seek_indulgences_show_recipient_trigger = yes
			this != religious_head_or_challenger
		}
		scope:recipient = {
			faith = scope:puppet_or_actor.faith
			# Antipope uses petition_antipope_indulgences_interaction instead
			trigger_if = {
				limit = { has_pam_dlc_trigger = yes }
				pam_is_antipope_trigger = no
			}
		}
		# Those under an antipope seek indulgences from them instead of the real Head of Faith
		trigger_if = {
			limit = {
				scope:recipient ?= scope:puppet_or_actor.faith.religious_head
			}
			scope:puppet_or_actor ?= { is_following_religious_head_challenger = no }
		}
	}

	cooldown = { years = 5 }

	is_valid_showing_failures_only = {
		scope:actor = {
			seek_indulgences_recipient_trigger = yes
			trigger_if = {
				limit = {
					has_trait = kinslayer_3
					trait_is_shunned_or_criminal_in_rite_trigger = { RITE = rite TRAIT = trait:kinslayer_3 GENDER_CHARACTER = scope:actor }
				}
				gold >= seek_indulgences_major_criminal_trait_value
			}
			trigger_else_if = {
				limit = {
					OR = {
						AND = {
							has_trait = kinslayer_2
							trait_is_shunned_or_criminal_in_rite_trigger = { RITE = rite TRAIT = trait:kinslayer_2 GENDER_CHARACTER = scope:actor }
						}
						AND = {
							has_trait = witch
							trait_is_shunned_or_criminal_in_rite_trigger = { RITE = rite TRAIT = trait:witch GENDER_CHARACTER = scope:actor }
						}
						AND = {
							has_trait = deviant
							trait_is_shunned_or_criminal_in_rite_trigger = { RITE = rite TRAIT = trait:deviant GENDER_CHARACTER = scope:actor }
						}
						AND = {
							has_trait = sodomite
							trait_is_shunned_or_criminal_in_rite_trigger = { RITE = rite TRAIT = trait:sodomite GENDER_CHARACTER = scope:actor }
						}
					}
				}
				gold >= seek_indulgences_medium_criminal_trait_value
			}
			trigger_else_if = {
				limit = {
					OR = {
						AND = {
							has_trait = kinslayer_1
							trait_is_shunned_or_criminal_in_rite_trigger = { RITE = rite TRAIT = trait:kinslayer_1 GENDER_CHARACTER = scope:actor }
						}
						AND = {
							has_trait = fornicator
							trait_is_shunned_or_criminal_in_rite_trigger = { RITE = rite TRAIT = trait:fornicator GENDER_CHARACTER = scope:actor }
						}
						AND = {
							has_trait = adulterer
							trait_is_shunned_or_criminal_in_rite_trigger = { RITE = rite TRAIT = trait:adulterer GENDER_CHARACTER = scope:actor }
						}
					}
				}
				gold >= seek_indulgences_minor_criminal_trait_value
			}
			trigger_else = {
				gold >= seek_indulgences_buy_piety_value
			}
			trigger_if = {
				limit = { has_pam_dlc_trigger = yes }
				custom_tooltip = {
					text = actor_is_antipope_sponsor_tt
					pam_is_antipope_sponsor_trigger = no
				}
			}
			pam_not_antipope_when_recipient_is_hof_tt = { CHARACTER = scope:actor }
			custom_description = {
				text = "seek_indulgences_excommunicated"
				NOT = { has_trait = excommunicated }
			}
		}
		scope:actor = {
			custom_tooltip = {
				text = HOF_INTERACTION_UNREFORMED_FAITH
				NOT = {
					faith = { has_doctrine_parameter = unreformed }
				}
			}
			NOT = {
				is_at_war_with = scope:recipient
			}
		}
		scope:actor = {
			NOT = {
				has_character_modifier = promised_pilgrimage_to_clergy_modifier
			}
		}
	}

	ai_accept = {
		base = 75

		celestial_hierarchy_acceptance_modifier = {
			ACTOR = scope:actor
			RECIPIENT = scope:recipient
		}

		seek_indulgences_acceptance_modifier = yes

		modifier = {
			add = pam_offer_pilgrimage_acceptance_value
			scope:offer_pilgrimage = yes
			desc = OFFER_PILGRIMAGE_INTERACTION_OPTION_REASON
		}
	}

	send_options_exclusive = no

	send_option = {
		is_shown = {
			has_pam_dlc_trigger = yes
			pam_offer_pilgrimage_option_shown_trigger = { ACTOR = scope:actor }
		}
		is_valid = {
			pam_offer_pilgrimage_option_valid_trigger = { ACTOR = scope:actor }
		}
		flag = offer_pilgrimage
		localization = OFFER_PILGRIMAGE_INTERACTION_OPTION
	}

	ai_min_reply_days = 1
	ai_max_reply_days = 5

	can_send = {
		# Anti-spam AI blockers
		ai_religious_request_blocker_trigger = { INTERACTION = seek_indulgences_interaction }
	}

	on_send = {
		# Anti-spam AI blockers
		ai_religious_request_blocker_effect = { INTERACTION = seek_indulgences_interaction }
	}

	on_accept = {
		show_as_tooltip = {
			seek_indulgences_interaction_effect = yes
		}
		scope:actor = {
			trigger_event = religious_interaction.1010
		}
		pam_offer_pilgrimage_effect = {
			ACTOR = scope:actor
			CLERIC = scope:recipient
		}

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

	on_decline = {

		scope:actor = {
			show_as_tooltip = {
				seek_indulgences_refusal_effect = yes
			}

			trigger_event = religious_interaction.1011
		}


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

	# AI will do

	ai_targets = {
		ai_recipients = head_of_faith
		ai_recipients = realm_priest_superior
		ai_recipients = superior
		ai_recipients = realm_priest_top_superior
		ai_recipients = councillors
	}

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

	ai_will_do = {
		base = -25

		ai_value_modifier = { # +50 to -50
			who = scope:actor
			ai_zeal = 0.5
		}

		modifier = {
			add = 50
			scope:actor = {
				piety < 0
			}
		}

		modifier = {
			add = 75
			scope:actor = {
				piety_level < 0
			}
		}

		modifier = {
			add = 50
			scope:actor = {
				piety < major_piety_value
				short_term_gold >= head_of_faith_gold_value
				short_term_gold >= monumental_gold_value
			}
		}

		modifier = {
			add = -25
			scope:actor = {
				piety > major_piety_value
				piety_level > 0
			}
		}
		#high chance of success
		modifier = {
			add = 25
			scope:recipient = {
				OR = {
					scope:actor.puppet:theological_agent_puppet ?= scope:recipient
					scope:recipient.rite = {
						rite_has_parameter = increases_seek_indulgences_acceptance
					}
					ai_greed >= 100
					ai_vengefulness <= -100
					opinion = {
						target = scope:actor
						value >= 100
					}
				}
			}
		}
		#Lowered chance of success
		modifier = {
			factor = 0.5
			scope:recipient = {
				OR = {
					opinion = {
						target = scope:actor
						value < -25
					}
					ai_greed <= -50
					ai_vengefulness >= 50
					rite = {
						has_tenet_status = { tenet = tenet_vows_of_poverty status = permitted }
					}
					rite = {
						has_tenet_status = { tenet = tenet_communal_possessions status = permitted }
					}
					NOT = {
						exists = scope:actor.puppet:theological_agent_puppet
					}
					AND = {
						scope:actor = {
							NOT = { rite = scope:recipient.rite }
						}
						scope:recipient = {
							rite_fulfillment_score = {
								target = scope:actor.rite
								value < 25
							}
						}
					}
				}
			}
		}

		#badly lowered chance of success
		modifier = {
			factor = 0
			scope:recipient = {
				OR = {
					opinion = {
						target = scope:actor
						value < -50
					}
					ai_greed <= -80
					ai_vengefulness >= 80
					rite = {
						has_tenet_status = { tenet = tenet_confession status = prohibited }
					}
					AND = {
						scope:actor = {
							NOT = { rite = scope:recipient.rite }
						}
						any_tenet = {
							scope:actor.rite = {
								has_tenet_status = {
									tenet = prev
									status = core
								}
							}
							scope:recipient.rite = {
								has_tenet_status = {
									tenet = prev
									status = prohibited
								}
							}
						}
					}
					AND = {
						scope:actor = {
							NOT = { rite = scope:recipient.rite }
						}
						any_tenet = {
							scope:actor.rite = {
								has_tenet_status = {
									tenet = prev
									status = permitted
								}
							}
							scope:recipient.rite = {
								has_tenet_status = {
									tenet = prev
									status = prohibited
								}
							}
						}
					}
				}
			}
		}

		evaluate_action_increasing_house_unity = {
			VALUE = 50
		}
	}
}

declaration_of_repentance_interaction = {
	icon = religious
	category = interaction_category_religion

	desc = {
		desc = declaration_of_repentance_interaction_desc
		triggered_desc = {
			trigger = { scope:puppet_or_actor = { has_hook = scope:recipient } }
			desc = declaration_of_repentance_interaction_desc_hook
		}
	}

	notification_text = RELIGIOUS_HEAD_DECLARATION_OF_REPENTANCE

	is_shown = {
		scope:puppet_or_actor ?= {
			has_trait = excommunicated
			faith ?= {
				faith_has_sacraments_central_trigger = yes
			}
		}
		scope:recipient != scope:puppet_or_actor
		scope:puppet_or_actor ?= {
			broader_clergy_show_hof_or_superior_interactions_trigger = yes
		}
		# With PAM, hide Declaration of Repentance when the player must petition Rome instead (kings+, or pope_excom).
		scope:puppet_or_actor ?= {
			trigger_if = {
				limit = {
					scope:actor = { is_ai = no }
					has_pam_dlc_trigger = yes
					faith = { petition_head_of_faith_faith_qualifies_trigger = yes }
				}
				need_hof_for_clergy_interaction_trigger = no
				NOR = {
					petition_head_of_faith_repentance_requires_petition_trigger = yes
					# An archbishop or higher answers only to the Head of Faith
					AND = {
						religious_head_or_challenger ?= scope:recipient
						pam_is_archbishop_or_higher_trigger = no
					}
				}
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:puppet_or_actor ?= {
			trigger_if = {
				limit = {
					highest_held_title_tier >= tier_empire
					exists = religious_head_or_challenger
					faith = {
						has_doctrine = doctrine_spiritual_head
					}
				}
				custom_tooltip = {
					text = recipient_not_hof_for_emperor_tt
					religious_head_or_challenger = scope:recipient
				}
			}
			NOT = {
				has_character_modifier = recent_excommunication
			}
			NOT = {
				is_at_war_with = scope:recipient
			}
			NOT = {
				has_character_modifier = promised_pilgrimage_to_clergy_modifier
			}
			trigger_if = {
				limit = {
					government_has_flag = government_is_theocracy
				}
				piety_level >= 2
			}
			pam_valid_excommunication_target_trigger = { EXCOMMUNICATOR = scope:recipient }
		}
		scope:recipient = {
			highest_held_title_tier >= tier_duchy
		}
	}

	send_option = {
		is_valid = {
			scope:puppet_or_actor ?= {
				has_usable_hook = scope:recipient
			}
		}
		flag = declaration_hook
		localization = DECLARATION_OF_REPENTANCE_HOOK
	}
	send_option = {
		is_shown = {
			has_pam_dlc_trigger = yes
			pam_offer_pilgrimage_option_shown_trigger = { ACTOR = scope:puppet_or_actor }
		}
		is_valid = {
			pam_offer_pilgrimage_option_valid_trigger = { ACTOR = scope:puppet_or_actor }
		}
		flag = offer_pilgrimage
		localization = OFFER_PILGRIMAGE_INTERACTION_OPTION
	}
	should_use_extra_icon = {
		scope:puppet_or_actor ?= { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	send_options_exclusive = no

	auto_accept = {
		custom_description = {
			text = "spending_hook"
			subject = scope:puppet_or_actor
			object = scope:recipient
			scope:declaration_hook = yes
			scope:puppet_or_actor = { has_strong_hook = scope:recipient }
		}
	}

	ai_accept = {
		base = 25

		celestial_hierarchy_acceptance_modifier = {
			ACTOR = scope:puppet_or_actor
			RECIPIENT = scope:recipient
		}

		modifier = {
			scope:declaration_hook = yes
			add = 20
			desc = SCHEME_WEAK_HOOK_USED
		}
		modifier = {
			add = pam_offer_pilgrimage_acceptance_value
			scope:offer_pilgrimage = yes
			desc = OFFER_PILGRIMAGE_INTERACTION_OPTION_REASON
		}
		modifier = {
			add = 20
			desc = pam_turned_the_other_cheek_accept_reason
			trigger = {
				scope:puppet_or_actor = { has_variable = pam_turned_the_other_cheek_var }
			}
		}
		modifier = {
			desc = AI_SIMPLE_OPINION_REASON
			trigger = {
				scope:recipient ?= { is_alive = yes }
				scope:puppet_or_actor ?= { is_alive = yes }
			}
			add = {
				value = "scope:recipient.opinion(scope:puppet_or_actor)"
			}
		}
		modifier = { # Same language
			add = 5
			desc = speaks_same_language_interaction_reason
			trigger = {
				scope:puppet_or_actor ?= {
					knows_language_of_culture = scope:recipient.culture
				}
			}
		}
		modifier = {
			add = {
				add = 10
				multiply = scope:puppet_or_actor.num_virtuous_traits
			}
			trigger = {
				scope:puppet_or_actor ?= {
					num_virtuous_traits > 0
				}
			}
			desc = DECLARATION_OF_REPENTANCE_VIRTUES
		}
		modifier = {
			add = {
				add = -10
				multiply = scope:puppet_or_actor.num_sinful_traits
			}
			trigger = {
				scope:puppet_or_actor ?= {
					num_sinful_traits > 0
				}
			}
			desc = DECLARATION_OF_REPENTANCE_SINS
		}
		modifier = {
			desc = RELIGIOUS_HEAD_INTERACTION_PARAGON
			add = 15
			trigger = {
				scope:puppet_or_actor ?= {
					has_trait = paragon
				}
			}
		}
		modifier = {
			desc = RELIGIOUS_HEAD_INTERACTION_CONSECRATED_BLOOD
			add = 5
			trigger = {
				scope:puppet_or_actor ?= {
					has_trait = consecrated_blood
				}
			}
		}
		modifier = {
			desc = RELIGIOUS_HEAD_INTERACTION_UNPLEDGED_GHW
			add = -25
			trigger = {
				scope:puppet_or_actor ?= { is_alive = yes }
				scope:recipient ?= {
					has_opinion_modifier = {
						target = scope:puppet_or_actor
						modifier = unpledged_from_ghw_opinion
					}
				}
			}
		}
		modifier = {
			add = 20
			desc = I_AM_LIEGE_TOP_LIEGE
			trigger = {
				scope:puppet_or_actor ?= { is_alive = yes }
				scope:recipient ?= {
					is_landed = no
					OR = {
						liege ?= scope:puppet_or_actor
						top_liege ?= scope:puppet_or_actor
					}
				}
			}
		}
		modifier = {
			add = 10
			desc = I_AM_LIEGE_TOP_LIEGE
			trigger = {
				scope:puppet_or_actor ?= { is_alive = yes }
				scope:recipient ?= {
					is_landed = yes
					OR = {
						liege ?= scope:puppet_or_actor
						top_liege ?= scope:puppet_or_actor
					}
				}
			}
		}

		# AI only: local bishops heavily refuse to lift a Pope excommunication (players are routed to petition Rome instead).
		modifier = {
			add = -200
			desc = EXCOMMUNICATED_BY_HOF
			trigger = {
				scope:puppet_or_actor ?= {
					has_character_flag = pope_excom
					NOT = {
						religious_head_or_challenger ?= scope:recipient
					}
				}
			}
		}
		secular_to_ecclesiastical_pam_factors_acceptance_modifier = yes

		evaluate_action_increasing_house_unity = {
			VALUE = 50
		}

		evaluate_action_decreasing_house_unity = {
			VALUE = -100
		}
	}

	ai_min_reply_days = 1
	ai_max_reply_days = 5

	on_accept = {
		declaration_of_repentance_interaction_effect = yes

		scope:puppet_or_actor = {
			#Letter event to inform character that their excommunication has been lifted.
			trigger_event = {
				id = religious_interaction.1024
			}
		}

		non_pope_lifting_excommunication_penalty_effect = yes

		pam_offer_pilgrimage_effect = {
			ACTOR = scope:puppet_or_actor
			CLERIC = scope:recipient
		}

		# 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_gain
			DESC = clan_unity_repentance.desc
			REVERSE_NON_HOUSE_TARGET = no
		}
	}

	on_decline = {
		scope:puppet_or_actor = {

			#Letter event to inform character the pope refused to lift the excommunication.
			trigger_event = {
				id = religious_interaction.1025
			}
		}

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

	# AI will do

	ai_targets = {
		ai_recipients = head_of_faith
		ai_recipients = realm_priest_superior
		ai_recipients = superior
		ai_recipients = councillors
	}

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

	ai_will_do = {
		base = 100
		#Shouldn't bother the pope unless important or it was his excommunication
		modifier = {
			add = -90
			scope:puppet_or_actor = {
				NOR = {
					has_character_flag = pope_excom
				}
				need_hof_for_clergy_interaction_trigger = no
				religious_head_or_challenger ?= scope:recipient
			}
		}
	}
}

excommunicate_interaction = {
	category = interaction_category_hostile
	common_interaction = yes #suppress error
	icon = excommunication

	desc = excommunicate_interaction_desc

	is_available = {
		trigger_if = {
			limit = { is_ai = yes }
			piety >= major_piety_value
			is_adult = yes
		}
	}

	is_shown = {
		scope:puppet_or_actor ?= {
			this != scope:recipient
			#Pope or Bishop
			is_clergy = yes
			is_ruler = yes
			faith ?= {
				this = scope:recipient.faith
				faith_has_sacraments_central_trigger = yes
				trigger_if = {
					limit = { religious_head ?= scope:puppet_or_actor }
					has_doctrine = doctrine_spiritual_head
				}
				NOT = { religious_head ?= scope:recipient }
			}
		}
	}

	is_valid_showing_failures_only = {
		NOR = {
			scope:recipient = {
				has_character_modifier = excommunication_recently_lifted
			}
			scope:puppet_or_actor.faith.great_holy_war ?= {
				has_pledged_attacker = scope:recipient
			}
		}
		scope:puppet_or_actor = {
			highest_held_title_tier >= tier_duchy
			piety >= excommunication_piety_cost_value
			custom_tooltip = {
				text = HOF_INTERACTION_UNREFORMED_FAITH
				NOT = {
					faith = { has_doctrine_parameter = unreformed }
				}
			}
			NOT = {
				has_trait = excommunicated
			}
		}
		scope:recipient = { NOT = { has_strong_hook = scope:puppet_or_actor } }
		custom_tooltip = {
			text = cannot_take_overt_hostile_actions_against_diarch.tt
			NOT = { scope:recipient ?= scope:puppet_or_actor.diarch }
		}
		scope:recipient = {
			custom_tooltip = {
				text = cannot_excommunicate_antipope_protected_tt
				NOT = {
					pam_antipope_protected_from_excommunication_trigger = { EXCOMMUNICATOR = scope:puppet_or_actor }
				}
			}
			NOT = {
				has_trait = excommunicated
			}
			pam_valid_excommunication_target_trigger = { EXCOMMUNICATOR = scope:puppet_or_actor }
		}
	}

	auto_accept = yes

	cost = {
		piety = {
			value = excommunication_piety_cost_value
			if = {
				limit = { scope:is_puppet_action ?= yes }
				multiply = 0
			}
			#Peace of God makes excommunication against aggressors easier
			if = {
				limit = {
					scope:puppet_or_actor ?= {
						rite = {
							rite_has_parameter = tenet_peace_of_god_excommunication
						}
						scope:puppet_or_actor = {
							has_opinion_modifier = {
								modifier = declared_war
								target = scope:recipient
							}
						}
					}
				}
				multiply = 0
			}
		}
	}

	on_accept = {
		if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				add_piety = {
					value = {
						value = excommunication_piety_cost_value
						max = piety
						multiply = -1
					}
				}
			}
		}
		scope:puppet_or_actor = {
			if = {
				limit = {
					any_character_situation = {
						situation_type = the_christian_church
					}
					situation:the_christian_church ?= {
						situation_top_has_catalyst = catalyst_excommunicate
					}
				}
				if = {
					limit = {
						scope:recipient = {
							highest_held_title_tier >= tier_kingdom
						}
					}
					situation:the_christian_church = { trigger_situation_catalyst = catalyst_excommunicate }
				}
				else = {
					situation:the_christian_church = { trigger_situation_catalyst = catalyst_excommunicate_minor }
				}
			}
		}
		excommunicate_character = {
			EXCOMMUNICATOR = scope:puppet_or_actor
			REQUESTING_CHARACTER = scope:puppet_or_actor
			TARGET_CHARACTER = scope:recipient
		}

		scope:recipient = {
			# Letter arrives a few days later; gives time for the trait to land before the player reads it.
			trigger_event = {
				id = religious_interaction.1021
				days = 5
			}
		}

		# 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_excommunication.desc
			REVERSE_NON_HOUSE_TARGET = no
		}
	}

	# AI will do

	ai_target_quick_trigger = {
		adult = yes
	}

	ai_targets = {
		ai_recipients = scripted_relations
		ai_recipients = primary_war_enemies
	}

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

	ai_will_do = {
		base = 50

		ai_value_modifier = { # +50 to -50
			who = scope:puppet_or_actor
			ai_vengefulness = 0.5
		}

		modifier = {
			factor = 0
			scope:recipient = {
				NOR = {
					has_relation_rival = scope:puppet_or_actor
					has_relation_nemesis = scope:puppet_or_actor
					is_at_war_with = scope:puppet_or_actor
					has_character_flag = executed_own_hof_unlawfully
					has_character_flag = executed_senior_cleric_unlawfully
					AND = {
						empire_faith_gate_enabled_trigger = yes
						has_contested_empire_trigger = yes
						faith_has_existing_empire_holder_trigger = yes
						faith = scope:puppet_or_actor.faith
						efg_contested_empire_grace_period_elapsed_trigger = yes
					}
					AND = {
						scope:puppet_or_actor = {
							has_personal_tenet_flag = tenet_peace_of_god_personal_excommunicate_aggressors
						}
						pam_peace_of_god_coreligionist_aggressor_trigger = yes
					}
				}
			}
		}

		modifier = {
			add = 50
			scope:recipient = { has_character_flag = executed_own_hof_unlawfully }
		}

		modifier = {
			add = 25
			scope:recipient = { has_character_flag = executed_senior_cleric_unlawfully }
		}

		modifier = {
			add = 40
			scope:puppet_or_actor = {
				has_personal_tenet_flag = tenet_peace_of_god_personal_excommunicate_aggressors
			}
			scope:recipient = {
				pam_peace_of_god_coreligionist_aggressor_trigger = yes
			}
		}

		modifier = {
			add = 10
			empire_faith_gate_enabled_trigger = yes
			scope:recipient = {
				has_contested_empire_trigger = yes
				faith_has_existing_empire_holder_trigger = yes
				faith = scope:puppet_or_actor.faith
				efg_contested_empire_grace_period_elapsed_trigger = yes
			}
		}

		modifier = {
			factor = 0
			scope:recipient = {
				involved_activity ?= {
					has_activity_type = activity_coronation
					activity_host = prev
				}
			}
		}
	}
}

lift_excommunication_interaction = {
	category = interaction_category_religion
	icon = excommunication

	common_interaction = yes

	desc = lift_excommunication_interaction_desc

	is_available = {
		trigger_if = {
			limit = { is_ai = yes }
			piety >= major_piety_value
			is_adult = yes
		}
	}

	is_shown = {
		scope:puppet_or_actor ?= {
			#Pope or Bishop
			OR = {
				AND = {
					is_clergy = yes
					is_ruler = yes
				}
				religious_head_or_challenger ?= scope:puppet_or_actor
			}
			NOT = {
				religious_head_or_challenger ?= scope:recipient
			}
		}
		scope:puppet_or_actor.faith ?= {
			has_doctrine = doctrine_spiritual_head
			faith_has_sacraments_central_trigger = yes
			this = scope:recipient.faith
		}
		scope:recipient = {
			has_trait = excommunicated
			this != scope:puppet_or_actor
		}
	}

	cost = {
		piety = {
			value = lift_excommunication_interaction_cost_value
			if = {
				limit = { scope:is_puppet_action ?= yes }
				multiply = 0
			}
		}
	}

	is_valid_showing_failures_only = {
		trigger_if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				piety >= lift_excommunication_interaction_cost_value
			}
		}
		scope:puppet_or_actor = {
			highest_held_title_tier >= tier_duchy
			NOT = {
				is_at_war_with = scope:recipient
			}
			custom_tooltip = {
				text = HOF_INTERACTION_UNREFORMED_FAITH
				NOT = {
					faith = { has_doctrine_parameter = unreformed }
				}
			}
		}
		scope:recipient = {
			pam_valid_excommunication_target_trigger = { EXCOMMUNICATOR = scope:puppet_or_actor }
		}
	}

	auto_accept = yes
	force_notification = yes
	notification_text = religious_interaction.1024
	#answer_accept_key = religious_interaction.1024.positive

	on_accept = {
		if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				add_piety = {
					value = {
						value = lift_excommunication_interaction_cost_value
						max = piety
						multiply = -1
					}
				}
			}
		}
		lift_character_excommunication_effect = {
			TARGET_CHARACTER = scope:recipient
			REQUESTING_CHARACTER = scope:puppet_or_actor
		}
		scope:puppet_or_actor = {
			if = {
				limit = {
					NOT = {
						this = scope:recipient
					}
					any_character_situation = {
						situation_type = the_christian_church
					}
					situation:the_christian_church ?= {
						situation_top_has_catalyst = catalyst_lift_excommunication
					}
				}
				if = {
					limit = {
						scope:recipient = {
							highest_held_title_tier >= tier_kingdom
						}
					}
					situation:the_christian_church = { trigger_situation_catalyst = catalyst_lift_excommunication }
				}
				else = {
					situation:the_christian_church = { trigger_situation_catalyst = catalyst_lift_excommunication_minor }
				}
			}
		}

		# 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_gain
			DESC = clan_unity_excommunication_lifted
			REVERSE_NON_HOUSE_TARGET = no
		}
	}

	# AI will do

	ai_target_quick_trigger = {
		adult = yes
	}

	ai_targets = {
		ai_recipients = scripted_relations
		ai_recipients = war_allies
	}

	ai_targets = {
		ai_recipients = neighboring_rulers
		max = 10
	}

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

	ai_will_do = {
		base = 10

		ai_value_modifier = { # +50 to -50
			who = scope:puppet_or_actor
			ai_compassion = 0.5
		}

		modifier = {
			add = 25
			desc = pam_turned_the_other_cheek_accept_reason
			scope:recipient = { has_variable = pam_turned_the_other_cheek_var }
		}

		modifier = {
			add = 20
			scope:puppet_or_actor = { # PAM - Concord phase
				top_participant_group:the_christian_church ?= {
					has_participant_group_parameter = the_christian_church_more_likely_to_lift_excommunications
				}
				opinion = {
					target = scope:recipient
					value >= high_positive_opinion
				}
			}
		}

		modifier = {
			factor = 0
			scope:puppet_or_actor = {
				has_character_flag = pope_excom
			}
			NOT = {
				scope:puppet_or_actor.religious_head_or_challenger ?= scope:puppet_or_actor
			}
		}

		modifier = {
			factor = 0
			scope:recipient = {
				NOR = { # Only do this for friends
					has_relation_friend = scope:puppet_or_actor
					has_relation_best_friend = scope:puppet_or_actor
					is_allied_to = scope:puppet_or_actor
					has_variable = pam_turned_the_other_cheek_var
					scope:puppet_or_actor = { # Unless you are in the Concord phase
						top_participant_group:the_christian_church ?= {
							has_participant_group_parameter = the_christian_church_more_likely_to_lift_excommunications
						}
						opinion = { # And the actor likes the guy
							target = scope:recipient
							value >= high_positive_opinion
						}
					}
				}
			}
		}
	}
}

request_excommunication_interaction = {
	category = interaction_category_hostile
	icon = excommunication
	interface_priority = 30

	desc = request_excommunication_interaction_desc
	redirect = {
		#excommunication victim needs to be made secondary recipient
		scope:recipient = {
			save_scope_as = secondary_recipient
		}
		scope:puppet_or_actor = {
			petition_head_of_faith_save_religious_authority_effect = { SCOPE = excommunication_petition_authority }
		}

		# Are we looking for a territorial cleric or going to the target's shared Head of Faith?
		if = {
			limit = {
				OR = {
					scope:secondary_recipient = {
						need_hof_for_clergy_interaction_trigger = no
					}
					trigger_if = {
						limit = { exists = scope:excommunication_petition_authority }
						NOT = {
							scope:secondary_recipient = {
								petition_head_of_faith_religious_authority_is_trigger = {
									CHARACTER = scope:excommunication_petition_authority
								}
							}
						}
					}
					trigger_else = { always = yes }
				}
			}
			#Is it a ruler or just some regular joe?
			if = {
				limit = {
					scope:secondary_recipient = {
						is_ruler = yes
					}
				}
				pam_redirect_request_excommunication_ruler_effect = yes
			}
			else_if = {
				limit = {
					exists = scope:secondary_recipient.liege
				}
				pam_redirect_request_excommunication_courtier_effect = yes
			}
			else = {
				pam_redirect_request_excommunication_wanderer_effect = yes
			}
		}
		else = {
			scope:excommunication_petition_authority ?= {
				save_scope_as = recipient
			}
		}
		
		#Still hasn't been set
		#stop errors from the above process failing, this should be blocked anyway
		if = {
			limit = {
				scope:secondary_recipient = scope:recipient
			}
			clear_saved_scope = recipient
		}
	}

	cooldown_against_recipient = { years = 3 }

	notification_text = RELIGIOUS_HEAD_REQUEST_EXCOMMUNICATION

	is_available = {
		trigger_if = {
			limit = { is_ai = yes }
			piety >= major_piety_value
			is_adult = yes
			NOT = { has_character_flag = hof_request_cooldown }
			faith ?= { faith_has_sacraments_central_trigger = yes }
		}
	}

	is_shown = {
		scope:puppet_or_actor.faith ?= {
			faith_has_sacraments_central_trigger = yes
			OR = {
				petition_head_of_faith_faith_qualifies_trigger = yes
				has_doctrine_parameter = has_clerical_regions
				AND = {
					has_doctrine = doctrine_spiritual_head
					exists = religious_head
				}
				any_faith_ruler = {
					government_has_flag = government_is_theocracy
					highest_held_title_tier >= tier_duchy
				}
			}
			this = scope:secondary_recipient.faith
		}
		NOR = {
			scope:puppet_or_actor ?= scope:secondary_recipient
			scope:puppet_or_actor.faith.religious_head ?= scope:puppet_or_actor
			scope:puppet_or_actor.faith.religious_head ?= scope:secondary_recipient
			AND = {
				NOT = { exists = scope:puppet_or_actor.faith.religious_head }
				OR = {
					scope:secondary_recipient.rite.head_of_rite ?= scope:puppet_or_actor
					scope:secondary_recipient.rite.head_of_rite ?= scope:secondary_recipient
				}
			}
		}
	}

	is_valid_showing_failures_only = {
		# The local path still needs a valid territorial cleric.
		trigger_if = {
			limit = {
				NOT = {
					scope:secondary_recipient = {
						petition_head_of_faith_religious_authority_is_trigger = {
							CHARACTER = scope:recipient
						}
					}
				}
			}
			custom_tooltip = {
				text = no_valid_excommunicator_tt
				scope:puppet_or_actor.faith = {
					any_faith_subordinate = {
						highest_held_title_tier >= tier_duchy
						save_temporary_scope_as = cleric_temp
						pam_valid_excommunication_target_trigger = { EXCOMMUNICATOR = scope:cleric_temp }
					}
				}
			}
			scope:secondary_recipient.highest_held_title_tier < tier_empire
		}
		# additional checks if not requested through puppet...
		trigger_if = {
			limit = { NOT = { scope:puppet_or_actor ?= scope:actor } }
			scope:secondary_recipient = {
				NOT = { has_strong_hook = scope:puppet_or_actor }
			}
			trigger_if = {
				limit = {
					petition_head_of_faith_excommunication_target_requires_petition_trigger = yes
					NOT = { scope:excommunication_hook = yes }
				}
				scope:puppet_or_actor = {
					piety >= massive_piety_value
				}
			}
			trigger_else = {
				scope:puppet_or_actor = {
					piety >= request_excommunication_piety_cost_value
				}
			}
		}

		# Excommunication target
		scope:secondary_recipient = {
			NOR = {
				has_trait = excommunicated
				has_character_modifier = excommunication_recently_lifted
			}
			age >= 12
		}
		scope:puppet_or_actor = {
			NOT = { has_trait = excommunicated }
			custom_tooltip = {
				text = HOF_INTERACTION_UNREFORMED_FAITH
				NOT = {
					faith = { has_doctrine_parameter = unreformed }
				}
			}
			NOT = {
				is_at_war_with = scope:recipient
			}
		}

		custom_tooltip = {
			text = cannot_take_overt_hostile_actions_against_diarch.tt
			NOT = { scope:recipient ?= scope:puppet_or_actor.diarch }
		}
		scope:secondary_recipient = {
			custom_tooltip = {
				text = cannot_excommunicate_antipope_protected_tt
				NOT = {
					pam_antipope_protected_from_excommunication_trigger = { EXCOMMUNICATOR = scope:recipient }
				}
			}
		}
		scope:puppet_or_actor = {
			NOT = {
				has_character_modifier = promised_pilgrimage_to_clergy_modifier
			}
		}
		#Can you just do it yourself?
		trigger_if = {
			limit = {
				scope:puppet_or_actor = {
					government_has_flag = government_is_theocracy
					highest_held_title_tier >= tier_duchy
				}
			}
			scope:secondary_recipient = {
				custom_tooltip = {
					text = can_excommunicate_directly
					NOT = {
						pam_valid_excommunication_target_trigger = { EXCOMMUNICATOR = scope:puppet_or_actor }
					}
				}
			}
		}
		trigger_if = {
			limit = {
				scope:secondary_recipient = {
					government_has_flag = government_is_theocracy
				}
			}
			custom_tooltip = {
				text = secondary_recipient_must_have_superior_tt
				scope:secondary_recipient = {
					OR = {
						AND = {
							exists = superior
						}
						any_liege_or_above = {
							government_has_flag = government_is_theocracy
							faith = scope:secondary_recipient.faith
							NOT = {
								this = scope:puppet_or_actor
							}
						}
					}
				}
			}
		}
		trigger_if = {
			limit = {
				has_pam_dlc_trigger = yes
			}
			scope:puppet_or_actor = {
				clergy_interaction_generic_piety_level_or_puppet_req_trigger = yes
			}
		}
	}

	send_option = {
		is_valid = {
			# either the actor or their puppet has a hook on the hof
			or = {
				scope:secondary_actor ?= {
					has_usable_hook = scope:recipient
				}
				scope:puppet_or_actor = {
					has_usable_hook = scope:recipient
				}
			}
		}
		flag = excommunication_hook
		localization = EXCOMMUNICATION_HOOK
	}
	should_use_extra_icon = {
		scope:puppet_or_actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	send_options_exclusive = no

	auto_accept = {
		trigger_if = {
			limit = {
				petition_head_of_faith_excommunication_target_requires_petition_trigger = yes
			}
			petition_head_of_faith_excommunication_target_requires_petition_trigger = yes
		}
		trigger_else = {
			custom_description = {
				text = "spending_hook"
				subject = scope:puppet_or_actor
				object = scope:recipient
				scope:excommunication_hook = yes
				scope:puppet_or_actor = { has_strong_hook = scope:recipient }
			}
		}
	}

	ai_accept = {
		base = -50

		celestial_hierarchy_acceptance_modifier = {
			ACTOR = scope:puppet_or_actor
			RECIPIENT = scope:recipient
		}

		modifier = { # By God Alone - Secular Faith: the petitioner holds the ear of the clergy
			add = 25
			desc = pam_sf_ear_of_clergy_accept_reason
			trigger = {
				scope:puppet_or_actor = { has_character_modifier = pam_sf_ear_of_clergy_modifier }
			}
		}

		modifier = {
			scope:excommunication_hook = yes
			add = 50
			desc = SCHEME_WEAK_HOOK_USED
		}
		modifier = {
			empire_faith_gate_enabled_trigger = yes
			scope:secondary_recipient ?= {
				has_contested_empire_trigger = yes
				faith_has_existing_empire_holder_trigger = yes
				faith = scope:puppet_or_actor.faith
			}
			add = 25
			desc = EXCOMMUNICATION_CONTESTED_EMPIRE
		}
		modifier = {
			scope:secondary_recipient ?= { has_character_flag = executed_own_hof_unlawfully }
			add = 50
			desc = EXCOMMUNICATION_EXECUTED_HOF_CRIME
		}
		modifier = {
			scope:secondary_recipient ?= { has_character_flag = executed_senior_cleric_unlawfully }
			add = 25
			desc = EXCOMMUNICATION_EXECUTED_SENIOR_CLERIC_CRIME
		}
		modifier = {
			scope:secondary_recipient ?= { has_character_flag = executed_own_hof_lawfully }
			add = 15
			desc = EXCOMMUNICATION_EXECUTED_HOF
		}
		opinion_modifier = {
			who = scope:recipient
			opinion_target = scope:puppet_or_actor
			multiplier = 1
		}
		opinion_modifier = {
			who = scope:recipient
			opinion_target = scope:secondary_recipient #Excommunication target
			multiplier = -1
			min = 0
		}
		modifier = {
			add = -100
			scope:recipient = {
				opinion = {
					value > 0
					target = scope:secondary_recipient #Excommunication target
				}
			}
			desc = EXCOMMUNICATION_OPINION
		}
		modifier = {
			add = {
				add = -10
				multiply = scope:secondary_recipient.num_virtuous_traits
			}
			scope:secondary_recipient.num_virtuous_traits > 0
			desc = EXCOMMUNICATION_VIRTUES
		}
		modifier = {
			add = {
				add = 10
				multiply = scope:secondary_recipient.num_sinful_traits
			}
			scope:secondary_recipient.num_sinful_traits > 0
			desc = EXCOMMUNICATION_SINS
		}
		modifier = {
			desc = RELIGIOUS_HEAD_INTERACTION_PARAGON
			add = 15
			scope:puppet_or_actor = {
				has_trait = paragon
			}
		}
		modifier = {
			desc = RELIGIOUS_HEAD_INTERACTION_CONSECRATED_BLOOD
			add = 5
			scope:puppet_or_actor = {
				has_trait = consecrated_blood
			}
		}
		modifier = {
			add = 20
			scope:puppet_or_actor = { # PAM - Reform phase
				top_participant_group:the_christian_church ?= {
					has_participant_group_parameter = the_christian_church_more_likely_to_accept_request_excommunications
				}
			}
			desc = the_christian_church_phase_value_tt
		}
		modifier = {
			add = 100
			scope:puppet_or_actor.puppet:theological_agent_puppet ?= scope:recipient
			desc = IS_YOUR_PUPPET
		}
		secular_to_ecclesiastical_pam_factors_acceptance_modifier = yes
	}

	ai_min_reply_days = 1
	ai_max_reply_days = 5

	can_send = {
		# Anti-spam AI blockers
		ai_religious_request_blocker_trigger = { INTERACTION = request_excommunication_interaction }
	}

	on_send = {
		# Anti-spam AI blockers
		ai_religious_request_blocker_effect = { INTERACTION = request_excommunication_interaction }
	}

	on_accept = {
		#If you are trying to excommunicate a duke or below, then it's a simple process of talking to the correct clergy above them
		if = {
			limit = {
				OR = {
					AND = {
						scope:secondary_recipient.highest_held_title_tier < tier_empire
						has_pam_dlc_trigger = no
					}
					#otherwise kings and above you must travel to rome to request excommunication
					AND = {
						scope:secondary_recipient.highest_held_title_tier < tier_kingdom
						has_pam_dlc_trigger = yes
					}
				}
			}
			if = {
				limit = {
					scope:secondary_recipient = { is_alive = yes }
				}
				if = {
					limit = { scope:excommunication_hook = yes }
					scope:puppet_or_actor = {
						use_hook = scope:recipient
					}
				}

				scope:puppet_or_actor = {
					#Spend piety for the excommunication.
					#Peace of God makes it free against aggressors though
					if = {
						limit = {
							NAND = {
								rite = {
									rite_has_parameter = tenet_peace_of_god_excommunication
								}
								has_opinion_modifier = {
									modifier = declared_war
									target = scope:secondary_recipient
								}
							}
						}
						add_piety = {
							value = {
								value = request_excommunication_piety_cost_value
								max = piety
								multiply = -1
							}
						}
					}				

					#Letter event to inform character the pope agreed to their request.
					trigger_event = {
						id = religious_interaction.1022
					}
					if = {
						limit = {
							any_character_situation = {
								situation_type = the_christian_church
							}
							situation:the_christian_church ?= {
								situation_top_has_catalyst = catalyst_request_excommunication
							}
						}
						if = {
							limit = {
								scope:secondary_recipient = {
									highest_held_title_tier >= tier_kingdom
								}
							}
							situation:the_christian_church = { trigger_situation_catalyst = catalyst_request_excommunication }
						}
						else = {
							situation:the_christian_church = { trigger_situation_catalyst = catalyst_request_excommunication_minor }
						}
					}
				}
				excommunicate_character = {
					EXCOMMUNICATOR = scope:recipient
					TARGET_CHARACTER = scope:secondary_recipient
					REQUESTING_CHARACTER = scope:puppet_or_actor
				}
				scope:secondary_recipient = {
					# Excommunication letter (same 5-day delay as direct papal excommunication).
					trigger_event = {
						id = religious_interaction.1020
						days = 5
					}
				}
				# 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_request_excommunication.desc
					REVERSE_NON_HOUSE_TARGET = no
				}
				hof_request_accept_consequences_effect = {
					HOF = scope:recipient
				}
			}
		}
		# King+ targets require a petition trip to Rome (same pattern as lifting a papal excommunication).
		else = {
			scope:puppet_or_actor = {
				save_scope_as = excom_request
			}
			custom_tooltip = petition_head_of_faith_excommunication_setup_interaction_accept_tt
			petition_head_of_faith_prepare_petition_effect = {
				TYPE = request_excommunication
				HOOK = excommunication_hook
				PIETY_VALUE = massive_piety_value
			}
		}	
	}

	on_decline = {
		hof_request_refuse_consequences_effect = {
			HOF = scope:recipient
			REQUESTER = scope:puppet_or_actor
		}
		scope:puppet_or_actor = {
			#Letter event to inform character the pope refused their request.
			trigger_event = {
				id = religious_interaction.1023
			}
		}

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

	# AI will do

	ai_target_quick_trigger = {
		adult = yes
	}

	ai_targets = {
		ai_recipients = scripted_relations
		ai_recipients = primary_war_enemies
	}

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

	ai_will_do = {
		base = 25

		ai_value_modifier = { # +50 to -50
			who = scope:puppet_or_actor
			ai_vengefulness = 0.5
		}

		modifier = {
			factor = 0
			scope:secondary_recipient = {
				NOR = {
					has_relation_rival = scope:puppet_or_actor
					has_relation_nemesis = scope:puppet_or_actor
					is_at_war_with = scope:puppet_or_actor
					has_character_flag = executed_own_hof_unlawfully
					has_character_flag = executed_senior_cleric_unlawfully
					AND = {
						empire_faith_gate_enabled_trigger = yes
						has_contested_empire_trigger = yes
						faith_has_existing_empire_holder_trigger = yes
						faith = scope:puppet_or_actor.faith
					}
				}
			}
		}

		modifier = {
			add = 50
			scope:secondary_recipient = { has_character_flag = executed_own_hof_unlawfully }
		}

		modifier = {
			add = 25
			scope:secondary_recipient = { has_character_flag = executed_senior_cleric_unlawfully }
		}

		#Clergy can do it themselves to lower tier rulers
		modifier = {
			scope:puppet_or_actor = {
				is_clergy = yes
				highest_held_title_tier >= tier_duchy
			}
			scope:secondary_recipient = {
				highest_held_title_tier < tier_kingdom
			}
			factor = 0
		}

		modifier = {
			add = 10
			empire_faith_gate_enabled_trigger = yes
			scope:puppet_or_actor = {
				has_contested_empire_trigger = yes
				faith_has_existing_empire_holder_trigger = yes
			}
			scope:secondary_recipient = {
				has_contested_empire_trigger = yes
				faith_has_existing_empire_holder_trigger = yes
				faith = scope:puppet_or_actor.faith
			}
		}
	}
}

### End Communion tenets ###

#Ask to take the vows to join Military Order
#by Linnéa Thimrén & Bianca Savazzi
send_to_holy_order_interaction = {
	category = interaction_category_friendly
	icon = holy_order

	ai_maybe = yes
	ai_min_reply_days = 4
	ai_max_reply_days = 9
	#can_send_despite_rejection = yes
	popup_on_receive = yes
	pause_on_receive = yes

	common_interaction = yes
	cooldown_against_recipient = { years = 10 }

	desc = send_to_holy_order_interaction_desc

	on_decline_summary = {
		triggered_desc = {
			trigger = { NOT = { scope:actor = scope:puppet_or_actor } }
			desc = take_vows_decline_summary_puppeteer
		}
		triggered_desc = {
			trigger = { scope:actor = scope:puppet_or_actor }
			desc = take_vows_decline_summary
		}
	}

	greeting = negative
	notification_text = REQUEST_VOWS_NOTIFICATION_TEXT

	is_available = {
		trigger_if = {
			limit = { is_ai = yes }
			piety >= major_piety_value
			is_adult = yes
		}
	}

	is_shown = {
		scope:puppet_or_actor.faith ?= {
			any_faith_holy_order = { #Your faith must have a Military Order
				leader = {
					government_has_flag = government_is_military_holy_order
				}
			}
		}
		exists = scope:puppet_or_actor
		scope:recipient = {
			OR = {
				is_courtier_of = scope:puppet_or_actor
				is_child_of = scope:puppet_or_actor
			}
			NOR = {
				has_trait = devoted
				has_trait = order_member
			}
		}
		NOT = { #Not your bishop
			scope:puppet_or_actor ?= {
				any_learning_councillor = { this = scope:recipient }
			}
		}
	}

	is_valid_showing_failures_only = {
		trigger_if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				piety >= scope:recipient.ask_to_take_vows_piety_cost
			}
		}
		trigger_if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				dynasty ?= { dynasty_prestige >= take_vows_dynasty_prestige_cost_value }
			}
		}
		scope:recipient = {
			is_courtier_of = scope:puppet_or_actor
			#Triggers that applies to both Monastery or Military Order requirements
			can_take_religious_vows_trigger = yes

			can_be_warrior_trigger = { ARMY_OWNER = scope:recipient }
			custom_description = {
				text = TAKE_VOWS_INTERACTION_MARTIAL_EDUCATION
				object = scope:recipient
				OR = {
					prowess > low_skill_rating
					has_education_martial_trigger = yes
				}
			}
			custom_description = { #At least one Military Order whose leader you're not a rival of
				text = not_rival_leader_check
				object = scope:recipient
				scope:puppet_or_actor.faith = {
					any_faith_holy_order = {
						leader = {
							NOT = { has_relation_rival = scope:recipient }
						}
					}
				}
			}
		}
		custom_tooltip = {
			text = cannot_take_overt_hostile_actions_against_diarch.tt
			NOT = { scope:recipient ?= scope:puppet_or_actor.diarch }
		}
		scope:puppet_or_actor = {
			NOT = {
				has_character_modifier = promised_pilgrimage_to_clergy_modifier
			}
		}
	}

	#Use hook
	auto_accept = {
		custom_description = {
			text = "spending_hook"
			subject = scope:puppet_or_actor
			object = scope:recipient
			scope:hook = yes
			scope:puppet_or_actor = { has_strong_hook = scope:recipient }
		}
	}

	send_option = {
		is_valid = {
			scope:puppet_or_actor = {
				has_usable_hook = scope:recipient
			}
		}
		flag = hook
		localization = SCHEME_HOOK
	}
	#DEMAND that they take the vows
	send_option = {
		is_shown = {
			scope:actor = { is_ai = no }
		}
		is_valid = {
			scope:recipient.liege ?= scope:puppet_or_actor
			scope:puppet_or_actor = {
				custom_tooltip = {
					text = parent_or_dynast_tt
					OR = {
						is_parent_of = scope:recipient
						AND = {
							exists = scope:puppet_or_actor.dynasty
							is_dynast = yes
							scope:recipient.dynasty ?= scope:puppet_or_actor.dynasty
						}
					}
				}
			}
		}
		flag = demand
		localization = INTERACTION_DEMAND_VOWS
	}

	should_use_extra_icon = {
		scope:puppet_or_actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	send_options_exclusive = no

	cost = {
		piety = {
			value = scope:recipient.ask_to_take_vows_piety_cost
			if = {
				limit = { scope:is_puppet_action ?= yes }
				multiply = 0
			}
		}
		renown = {
			value = take_vows_dynasty_prestige_cost_value
			if = {
				limit = { scope:is_puppet_action ?= yes }
				multiply = 0
			}
		}
	}

	on_send = {
		scope:recipient = {
			set_variable = {
				name = vows_piety_spent
				value = ask_to_take_vows_piety_cost
				days = 10
			}
		}
	}

	on_accept = {
		if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				add_piety = {
					value = {
						add = scope:recipient.ask_to_take_vows_piety_cost
						max = piety
						multiply = -1
					}
				}
				if = {
					limit = { take_vows_dynasty_prestige_cost_value > 0 }
					dynasty ?= {
						add_dynasty_prestige = {
							value = {
								value = take_vows_dynasty_prestige_cost_value
								multiply = -1
							}
						}
					}
				}
			}
		}
		scope:puppet_or_actor = {
			if = {
				limit = { scope:hook = yes }
				use_hook = scope:recipient
			}

			#You demanded compliance as parent or dynasty head... you get it, but at a cost
			if = {
				limit = {
					scope:demand = yes
				}
				scope:puppet_or_actor = {
					show_as_tooltip = {
						take_vows_demand_effect = yes
					}
				}
			}

			# Legitimacy loss if you're doing this to your children
			if = {
				limit = {
					scope:recipient = { is_primary_heir_of = scope:puppet_or_actor }
				}
				add_legitimacy = {
					value = minor_legitimacy_loss
					multiply = scope:puppet_or_actor.primary_title.tier
				}
			}
			else_if = {
				limit = {
					scope:recipient = { is_heir_of = scope:puppet_or_actor }
				}
				add_legitimacy = {
					value = miniscule_legitimacy_loss
					multiply = scope:puppet_or_actor.primary_title.tier
				}
			}

			trigger_event = holy_order.0001
			show_as_tooltip = {
				send_child_to_holy_order_tooltip_effect = yes
				scope:recipient = { kick_from_court_interaction_warning_tooltip_effect = yes }
				take_vows_faith_opinion_effect = yes
			}
		}
		hidden_effect = {
			scope:recipient = {
				remove_variable = vows_piety_spent
			}
		}

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

	on_decline = {
		scope:puppet_or_actor = {
			#You demanded compliance as parent or dynasty head... you get it, but at a cost
			if = {
				limit = {
					scope:demand = yes
				}
				scope:puppet_or_actor = {
					show_as_tooltip = {
						take_vows_demand_effect = yes
					}
				}
			}
		}
		scope:recipient = {
			add_opinion = {
				target = scope:puppet_or_actor
				modifier = asked_me_to_take_vows_opinion
				years = 10
			}
		}
		#Letter event informing the character about the rejection.
		scope:puppet_or_actor = {
			trigger_event = {
				id = religious_interaction.1031
			}
		}

		# Refund piety cost
		show_as_tooltip = {
			scope:puppet_or_actor = {
				add_piety_no_experience = {
					value = scope:recipient.ask_to_take_vows_piety_cost
				}
			}
		}
		hidden_effect = {
			if = {
				limit = {
					scope:recipient = {
						has_variable = vows_piety_spent
 					}
				}
				scope:puppet_or_actor = {
					add_piety_no_experience = {
						value = scope:recipient.var:vows_piety_spent
 					}
 				}
				scope:recipient = {
					remove_variable = vows_piety_spent
				}
 			}
 		}

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

	auto_accept = no

	ai_accept = {
		base = 0 # Try to make it 0 for most interactions

		celestial_hierarchy_acceptance_modifier = {
			ACTOR = scope:puppet_or_actor
			RECIPIENT = scope:recipient
		}

		modifier = {
			scope:hook = yes
			add = 50
			desc = SCHEME_WEAK_HOOK_USED
		}
		modifier = {
			add = 50
			scope:demand = yes
			desc = liege_demands_vow_taking
		}
		modifier = {
			add = 25
			scope:puppet_or_actor = { has_character_modifier = pam_oblate_patron_modifier }
			desc = pam_oblate_patron_reason
		}
		opinion_modifier = { # Opinion Factor
			who = scope:recipient
			opinion_target = scope:puppet_or_actor
			multiplier = 0.25
			desc = AI_SIMPLE_OPINION_REASON
		}
		modifier = {
			add = ai_zeal
			ai_zeal < 0
			desc = TAKE_THE_VOWS_SKEPTIC
		}
		modifier = {
			add = {
				value = ai_zeal
				divide = 2
			}
			ai_zeal > 0
			desc = TAKE_THE_VOWS_ZEALOUS
		}
		modifier = {
			add = {
				value = ai_zeal
				multiply = ai_boldness
				divide = 100
				min = 10
			}
			ai_zeal > 0
			ai_boldness > 0
			desc = TAKE_THE_VOWS_FIGHT_FOR_FAITH
		}
		modifier = {
			add = {
				value = ai_boldness
			}
			ai_boldness < 0
			desc = TAKE_THE_VOWS_AFRAID_TO_DIE
		}
		modifier = {
			add = {
				value = ai_greed
				multiply = -1
			}
			ai_greed > 0
			desc = TAKE_THE_VOWS_GREED
		}
		modifier = {
			add = 50
			exists = scope:puppet_or_actor.cp:councillor_court_chaplain
			scope:recipient = {
				OR = {
					has_relation_lover = scope:puppet_or_actor.cp:councillor_court_chaplain
					has_relation_friend = scope:puppet_or_actor.cp:councillor_court_chaplain
					has_secret_relation_lover = scope:puppet_or_actor.cp:councillor_court_chaplain
					has_relation_soulmate = scope:puppet_or_actor.cp:councillor_court_chaplain
					has_relation_best_friend = scope:puppet_or_actor.cp:councillor_court_chaplain
					opinion = {
						target = scope:puppet_or_actor.cp:councillor_court_chaplain
						value >= very_high_positive_opinion
					}
				}
			}
			desc = TAKE_THE_VOWS_INSPIRING_COURT_CHAPLAIN
		}
		modifier = {
			add = 50
			scope:recipient = {
				OR = {
					any_relation = {
						type = friend
						is_clergy = yes
					}
					any_relation = {
						type = best_friend
						is_clergy = yes
					}
					any_relation = {
						type = lover
						is_clergy = yes
					}
					any_relation = {
						type = soulmate
						is_clergy = yes
					}
					any_secret = {
						type = secret_lover
						secret_target = {
							is_clergy = yes
						}
					}
				}
			}
			desc = TAKE_THE_VOWS_INSPIRING_CLERGY
		}

		modifier = {
			add = {
				add = 20
				multiply = scope:recipient.num_virtuous_traits
			}
			scope:recipient.num_virtuous_traits > 0
			desc = TAKE_THE_VOWS_VIRTUOUS
		}

		modifier = {
			add = {
				add = -20
				multiply = scope:recipient.num_sinful_traits
			}
			scope:recipient.num_sinful_traits > 0
			desc = TAKE_THE_VOWS_SINFUL
		}
		modifier = { # Has fought for the faith before
			add = 20
			scope:recipient = {
				has_trait = holy_warrior
			}
			desc = TAKE_THE_VOWS_HOLY_WARRIOR
		}

		modifier = {
			add = 25
			scope:recipient = {
				has_trait = temperate
			}
			desc = TAKE_THE_VOWS_TEMPERATE
		}

		modifier = {
			add = 25
			scope:recipient = {
				has_trait = content
			}
			desc = TAKE_THE_VOWS_CONTENT
		}
		modifier = {
			add = 25
			scope:recipient = {
				has_trait = humble
			}
			desc = TAKE_THE_VOWS_HUMBLE
		}

		#Negative Personality Modifiers
		modifier = {
			add = -500
			scope:recipient = {
				has_trait = pregnant
			}
			desc = TAKE_THE_VOWS_PREGNANT
		}
		modifier = {
			add = -500
			scope:recipient = {
				has_trait = ambitious
			}
			desc = TAKE_THE_VOWS_AMBITIOUS
		}

		modifier = {
			add = -50
			scope:recipient = {
				OR = {
					is_married = yes
					exists = betrothed
				}
			}
			desc = TAKE_THE_VOWS_MARRIED_OR_BETROTHED
		}

		modifier = {
			add = -150
			scope:recipient = {
				is_primary_heir_of = scope:puppet_or_actor
			}
			desc = TAKE_THE_VOWS_PRIMARY_HEIR
		}

		modifier = {
			add = -75
			scope:recipient = {
				NOT = {
					is_primary_heir_of = scope:puppet_or_actor
				}
			}
			scope:puppet_or_actor.primary_title = {
				place_in_line_of_succession = {
					target = prev
					value = 2
				}
			}
			desc = TAKE_THE_VOWS_SECOND_HEIR
		}

		modifier = {
			add = -50
			scope:recipient = {
				NOT = {
					is_primary_heir_of = scope:puppet_or_actor
				}
			}
			scope:puppet_or_actor.primary_title = {
				place_in_line_of_succession = {
					target = prev
					value = 3
				}
			}
			desc = TAKE_THE_VOWS_THIRD_HEIR
		}

		modifier = {
			add = -25
			scope:recipient = {
				NOT = {
					is_primary_heir_of = scope:puppet_or_actor
				}
			}
			scope:puppet_or_actor.primary_title = {
				place_in_line_of_succession = {
					target = prev
					value >= 4
					value <= 10
				}
			}
			desc = TAKE_THE_VOWS_HEIR
		}

		modifier = {
			add = -100
			scope:recipient = {
				NOT = { is_heir_of = scope:puppet_or_actor }
				any_heir_title = {
					exists = holder
					holder != scope:puppet_or_actor
				}
				NOT = {
					is_primary_heir_of = scope:puppet_or_actor
				}
			}
			desc = TAKE_THE_VOWS_HEIR_TO_OTHER_TITLE
		}

		modifier = {
			add = -50
			scope:recipient = {
				NOT = { is_heir_of = scope:puppet_or_actor }
				any_parent = {
					any_held_title = {
						place_in_line_of_succession = {
							target = scope:recipient
							value < 5
						}
						NOT = {
							place_in_line_of_succession = {
								target = scope:recipient
								value < 2
							}
						}
					}
				}
				NOT = {
					is_primary_heir_of = scope:puppet_or_actor
				}
			}
			desc = TAKE_THE_VOWS_IN_LINE_TO_OTHER_TITLE
		}

		modifier = { #Rivalry modifier.
			desc = offer_vassalization_interaction_aibehavior_rival_tt
			trigger = {
				scope:recipient = {
					has_relation_rival = scope:puppet_or_actor
					NOT = { has_relation_nemesis = scope:puppet_or_actor }
				}
			}
			add = -50
		}
		modifier = { #Nemesis modifier.
			desc = offer_vassalization_interaction_aibehavior_nemesis_tt
			trigger = {
				scope:recipient = {
					has_relation_nemesis = scope:puppet_or_actor
				}
			}
			add = -100
		}

		#Dread modifiers
		modifier = {
			add = intimidated_halved_reason_value
			scope:recipient = {
				has_dread_level_towards = {
					target = scope:puppet_or_actor
					level = 1
				}
			}
			desc = INTIMIDATED_REASON
		}
		modifier = {
			add = cowed_halved_reason_value
			scope:recipient = {
				has_dread_level_towards = {
					target = scope:puppet_or_actor
					level = 2
				}
			}
			desc = COWED_REASON
		}

		# PAM - Concord Phase
		modifier = {
			add = 25
			situation:the_christian_church ?= {
				any_participant_group = { # Both characters are involved in the situation
					any_situation_group_participant = {
						this = scope:puppet_or_actor
					}
					trigger_if = {
						limit = { scope:recipient = { is_ruler = yes } }
						any_situation_group_participant = {
							this = scope:recipient
						}
					}
				}
				has_situation_top_phase_parameter = the_christian_church_better_take_the_vows_acceptance
			}
			desc = pam_the_christian_church_better_take_the_vows_acceptance_desc
		}
	}

	# AI will do

	ai_target_quick_trigger = {
		adult = yes
	}

	ai_targets = {
		ai_recipients = courtiers
		max = 5
	}

	ai_targets = {
		ai_recipients = family
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 144
		duchy = 72
		kingdom = 24
		empire = 24
		hegemony = 24
	}

	ai_will_do = {
		base = 0

		modifier = { # The AI will always use a Hook
			scope:hook = yes
			add = 1
		}

		modifier = { # Try to send rivals
			add = 100
			scope:puppet_or_actor = {
				OR = {
					has_relation_rival = scope:recipient
					has_relation_nemesis = scope:recipient
				}
			}
		}

		modifier = { # Try to send people who would make poor heirs
			add = 20
			scope:recipient = {
				OR = {
					character_considered_morally_dubious_trigger = { RITE = scope:puppet_or_actor.rite }
					has_trait = drunkard
					has_trait = hashishiyah
					has_trait = flagellant
					has_trait = reclusive
					num_of_bad_genetic_traits = 1
					num_sinful_traits = 1
				}
				scope:puppet_or_actor.primary_title = {
					place_in_line_of_succession = {
						target = prev
						value <= 7
					}
				}
			}
		}
		modifier = { # Try to send people who would make terrible heirs
			add = 50
			scope:recipient = {
				OR = {
					character_considered_wicked_trigger = { RITE = scope:puppet_or_actor.rite }
					has_trait = maimed
					num_of_bad_genetic_traits >= 2
					num_sinful_traits >= 2
				}
				scope:puppet_or_actor.primary_title = {
					place_in_line_of_succession = {
						target = prev
						value <= 7
					}
				}
			}
		}

		modifier = { # Try to send people who would make poor heirs
			add = 25
			scope:recipient = {
				is_adult = yes
				calc_true_if = {
					amount >= 3

					diplomacy < 8
					stewardship < 8
					martial < 8
					intrigue < 8
					learning < 8
				}
				scope:puppet_or_actor.primary_title = {
					place_in_line_of_succession = {
						target = prev
						value <= 7
					}
				}
			}
		}

		modifier = { # Sending one of your heirs is almost customary
			add = 100
			scope:puppet_or_actor = {
				any_child = {
					count >= 3
				}
				NOT = {
					any_child = {
						OR = {
							has_trait = devoted
							has_trait = order_member
						}
					}
				}
			}
			scope:recipient = {
				is_child_of = scope:puppet_or_actor
				has_education_martial_trigger = yes
			}
		}

		modifier = { # Zealous characters generally want to send characters to the Military Order
			add = 50
			scope:puppet_or_actor = {
				ai_zeal >= high_positive_ai_value
			}
			scope:recipient = {
				has_education_martial_trigger = yes
			}
		}

		modifier = { # Greedy characters want to rid their court of potential threats
			add = 50
			scope:puppet_or_actor = {
				ai_greed >= medium_positive_ai_value
				any_child = { }
			}
			scope:recipient = {
				NOT = {
					is_child_of = scope:puppet_or_actor
				}
				any_claim = {
					holder ?= scope:puppet_or_actor
				}
			}
		}
		#No holy order allowing rulers of recipient's culture
		modifier = {
			NOT = {
				faith = {
					any_faith_holy_order = {
						leader = {
							government_has_flag = government_is_military_holy_order
							OR = {
								NOT = {
									has_realm_law = cultural_holy_order_succession_law
								}
								culture = {
									has_same_culture_heritage = scope:recipient.culture
								}
							}
						}
					}
				}
			}
			factor = 0.2
		}

		modifier = { # The AI doesn't ask married/betrothed people
			factor = 0
			scope:recipient = {
				OR = {
					exists = betrothed
					is_married = yes
				}
			}
		}

		modifier = { # Never ask Primary Heir
			factor = 0
			scope:recipient = {
				is_primary_heir_of = scope:puppet_or_actor
			}
		}

		modifier = { # Only care about family
			factor = 0
			scope:recipient = {
				NOT = {
					is_close_or_extended_family_of = scope:puppet_or_actor
				}
			}
		}
	}
}


#Ask to take the vows to become a generic monk
#by Linnéa Thimrén & Bianca Savazzi
take_vows_interaction = {
	category = interaction_category_vassal
	icon = religious

	ai_maybe = yes
	ai_min_reply_days = 4
	ai_max_reply_days = 9
	#can_send_despite_rejection = yes
	popup_on_receive = yes
	pause_on_receive = yes

	common_interaction = yes
	cooldown_against_recipient = { years = 10 }

	desc = take_vows_interaction_desc

	on_decline_summary = {
		triggered_desc = {
			trigger = { NOT = { scope:actor = scope:puppet_or_actor } }
			desc = take_vows_decline_summary_puppeteer
		}
		triggered_desc = {
			trigger = { scope:actor = scope:puppet_or_actor }
			desc = take_vows_decline_summary
		}
	}

	greeting = negative
	notification_text = REQUEST_VOWS_NOTIFICATION_TEXT

	is_available = {
		trigger_if = {
			limit = { is_ai = yes }
			piety >= major_piety_value
			is_adult = yes
		}
	}

	is_shown = {
		#Only for when there are no monastic orders to send char to
		scope:puppet_or_actor ?= {
			faith ?= {
				religious_head ?= scope:puppet_or_actor
				NOT = {
					any_faith_holy_order = {
						take_the_vows_valid_monastic_order_trigger = { CHARACTER = scope:puppet_or_actor }
					}
				}
			}
			take_vows_available_trigger = yes
			NOT = {
				any_learning_councillor = { this = scope:recipient }
			}
		}
		scope:recipient = {
			is_courtier_of = scope:puppet_or_actor
			NOR = {
				has_trait = devoted
				has_trait = order_member
			}
		}
	}

	is_valid_showing_failures_only = {
		trigger_if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				piety >= scope:recipient.ask_to_take_vows_piety_cost
			}
		}
		trigger_if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				dynasty ?= { dynasty_prestige >= take_vows_dynasty_prestige_cost_value }
			}
		}
		scope:recipient = {
			age >= 10
			is_courtier_of = scope:puppet_or_actor
			can_take_religious_vows_trigger = yes #Triggers that applies to both Monastery or Military Order requirements
		}
		custom_tooltip = {
			text = cannot_take_overt_hostile_actions_against_diarch.tt
			NOT = { scope:recipient ?= scope:puppet_or_actor.diarch }
		}
		scope:puppet_or_actor = {
			NOT = {
				has_character_modifier = promised_pilgrimage_to_clergy_modifier
			}
		}
	}

	#Use hook
	auto_accept = {
		trigger_if = {
			limit = { scope:simony_paid_vows = yes }
			custom_description = {
				text = PAM_TAKE_VOWS_GOLD_AUTO_ACCEPT
				object = scope:recipient
				always = yes
			}
		}
		trigger_else = {
			custom_description = {
				text = "spending_hook"
				subject = scope:puppet_or_actor
				object = scope:recipient
				scope:hook = yes
				scope:puppet_or_actor = { has_strong_hook = scope:recipient }
			}
		}
	}

	send_option = {
		is_valid = {
			scope:puppet_or_actor = {
				has_usable_hook = scope:recipient
			}
		}
		flag = hook
		localization = SCHEME_HOOK
	}
	#DEMAND that they take the vows
	#TODO_PAM_JC TIT-69874 improvement jira to unlock this for AI and add logic. On other "join an order" type interactions as well
	send_option = {
		is_shown = {
			scope:actor = { is_ai = no }
		}
		is_valid = {
			scope:recipient.liege ?= scope:puppet_or_actor
			scope:puppet_or_actor = {
				custom_tooltip = {
					text = parent_or_dynast_tt
					OR = {
						is_parent_of = scope:recipient
						AND = {
							exists = scope:puppet_or_actor.dynasty
							is_dynast = yes
							scope:recipient.dynasty ?= scope:puppet_or_actor.dynasty
						}
					}
				}
			}
		}
		flag = demand
		localization = INTERACTION_DEMAND_VOWS
	}
	send_option = {
		is_shown = {
			scope:actor = {
				is_ai = no
			}
		}
		is_valid = {
			custom_tooltip = {
				text = PAM_TAKE_VOWS_GOLD_OPTION_REQUIRES_SIMONY
				scope:puppet_or_actor = {
					rite = {
						rite_has_parameter = tenet_simony_paid_vows
					}
				}
			}
			scope:puppet_or_actor = {
				gold >= major_gold_value
			}
		}
		flag = simony_paid_vows
		localization = PAM_TAKE_VOWS_GOLD_OPTION
	}
	should_use_extra_icon = {
		scope:puppet_or_actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	send_options_exclusive = no

	cost = {
		piety = {
			value = scope:recipient.ask_to_take_vows_piety_cost
			if = {
				limit = { scope:is_puppet_action ?= yes }
				multiply = 0
			}
		}
		renown = {
			value = take_vows_dynasty_prestige_cost_value
			if = {
				limit = { scope:is_puppet_action ?= yes }
				multiply = 0
			}
		}
		gold = {
			value = 0
			if = {
				limit = { scope:simony_paid_vows = yes }
				add = scope:puppet_or_actor.major_gold_value
			}
		}
	}

	on_send = {
		scope:recipient = {
			set_variable = {
				name = vows_piety_spent
				value = ask_to_take_vows_piety_cost
				days = 10
 			}
 		}
 	}

	on_accept = {
		if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				add_piety = {
					value = {
						add = scope:recipient.ask_to_take_vows_piety_cost
						max = piety
						multiply = -1
					}
				}
				if = {
					limit = { take_vows_dynasty_prestige_cost_value > 0 }
					dynasty ?= {
						add_dynasty_prestige = {
							value = {
								value = take_vows_dynasty_prestige_cost_value
								multiply = -1
							}
						}
					}
				}
			}
		}
		scope:puppet_or_actor = {
			if = {
				limit = { scope:hook = yes }
				use_hook = scope:recipient
			}

			#You demanded compliance as parent or dynasty head... you get it, but at a cost
			if = {
				limit = {
					scope:demand = yes
				}
				scope:puppet_or_actor = {
					show_as_tooltip = {
						take_vows_demand_effect = yes
					}
				}
			}

			# Legitimacy loss if you're doing this to your children
			if = {
				limit = {
					has_legitimacy = yes
					scope:recipient = { is_primary_heir_of = scope:puppet_or_actor }
				}
				if = {
					limit = {
						hyperdulia_take_the_vows_trigger = yes
					}
					add_legitimacy = {
						value = miniscule_legitimacy_gain
						multiply = scope:puppet_or_actor.primary_title.tier
					}
				}
				else = {
					add_legitimacy = {
						value = minor_legitimacy_loss
						multiply = scope:puppet_or_actor.primary_title.tier
					}
				}
			}
			else_if = {
				limit = {
					has_legitimacy = yes
					scope:recipient = { is_heir_of = scope:puppet_or_actor }
				}
				if = {
					limit = {
						hyperdulia_take_the_vows_trigger = yes
					}
					add_legitimacy = {
						value = minor_legitimacy_gain
						multiply = scope:puppet_or_actor.primary_title.tier
					}
				}
				else = {
					add_legitimacy = {
						value = miniscule_legitimacy_loss
						multiply = scope:puppet_or_actor.primary_title.tier
					}
				}
			}
			else_if = {
				limit = {
					has_legitimacy = yes
					hyperdulia_take_the_vows_trigger = yes
				}
				add_legitimacy = {
					value = medium_legitimacy_gain
					multiply = scope:puppet_or_actor.primary_title.tier
				}
			}

			if = {
				limit = { scope:simony_paid_vows = yes }
				scope:recipient = {
					add_character_flag = { flag = pam_simony_paid_vows days = 1 }
				}
			}
			show_as_tooltip = {
				send_child_to_clergy_effect = yes
			}
			scope:recipient = {
				if = {
					limit = {
						scope:puppet_or_actor.top_liege = {
							any_vassal_or_below = {
								government_has_flag = government_is_theocracy
								primary_title.tier > tier_barony
								faith = scope:puppet_or_actor.faith
							}
						}
					}
					scope:puppet_or_actor.top_liege = {
						random_vassal_or_below = {
							limit = {
								government_has_flag = government_is_theocracy
								primary_title.tier > tier_barony
								faith = scope:puppet_or_actor.faith
							}
							save_scope_as = theocratic_travel_target
						}
					}
					scope:theocratic_travel_target = {
						add_courtier = scope:recipient
					}
				}
				else_if = {
					limit = {
						exists = scope:puppet_or_actor.capital_province
					}
					move_to_pool_at = scope:puppet_or_actor.capital_province
				}
				kick_from_court_interaction_warning_tooltip_effect = yes
			}
			trigger_event = holy_order.0002
			take_vows_faith_opinion_effect = yes
			if = {
				limit = {
					house = {
						has_house_aspiration_parameter = humility_take_the_vows_bonus
					}
				}
				add_piety_experience = 100
				add_character_modifier = {
					modifier = tgp_humility_take_the_vows_bonus_modifier
					years = 10
				}
			}
		}

		hidden_effect = {
			scope:recipient = {
				remove_variable = vows_piety_spent
			}
		}

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

	on_decline = {
		scope:puppet_or_actor = {
			#You demanded compliance as parent or dynasty head... you get it, but at a cost
			if = {
				limit = {
					scope:demand = yes
				}
				scope:puppet_or_actor = {
					show_as_tooltip = {
						take_vows_demand_effect = yes
					}
				}
			}
		}
		scope:recipient = {
			add_opinion = {
				target = scope:puppet_or_actor
				modifier = asked_me_to_take_vows_opinion
				years = 10
			}
		}
		#Letter event informing the character about the rejection.
		scope:puppet_or_actor = {
			trigger_event = {
				id = religious_interaction.1031
			}
		}

		# Refund piety cost
		show_as_tooltip = {
			scope:puppet_or_actor = {
				add_piety_no_experience = {
					value = scope:recipient.ask_to_take_vows_piety_cost
				}
			}
		}
		# Refund piety cost
		hidden_effect = {
			if = {
				limit = {
					scope:recipient = {
						has_variable = vows_piety_spent
 					}
 				}
				scope:puppet_or_actor = {
					add_piety_no_experience = {
						value = scope:recipient.var:vows_piety_spent
 					}
				}
				scope:recipient = {
					remove_variable = vows_piety_spent
 				}
 			}
 		}

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

	auto_accept = no

	ai_accept = {
		base = 0 # Try to make it 0 for most interactions

		celestial_hierarchy_acceptance_modifier = {
			ACTOR = scope:puppet_or_actor
			RECIPIENT = scope:recipient
		}

		modifier = {
			scope:hook = yes
			add = 50
			desc = SCHEME_WEAK_HOOK_USED
		}
		modifier = {
			add = 50
			scope:demand = yes
			desc = liege_demands_vow_taking
		}
		modifier = {
			add = 25
			scope:puppet_or_actor = { has_character_modifier = pam_oblate_patron_modifier }
			desc = pam_oblate_patron_reason
		}

		modifier = { # Has cloister
			scope:puppet_or_actor.domicile ?= { has_domicile_parameter = estate_cloister_take_vows }
			add = { value = scope:puppet_or_actor.learning add = scope:puppet_or_actor.diplomacy multiply = 0.5 }
			desc = estate_cloister_take_vows_reason
		}
		opinion_modifier = { # Opinion Factor
			who = scope:recipient
			opinion_target = scope:puppet_or_actor
			multiplier = 0.25
			desc = AI_SIMPLE_OPINION_REASON
		}
		modifier = {
			add = ai_zeal
			ai_zeal < 0
			desc = TAKE_THE_VOWS_SKEPTIC
		}
		modifier = {
			add = {
				value = ai_zeal
				divide = 2
			}
			ai_zeal > 0
			desc = TAKE_THE_VOWS_ZEALOUS
		}
		modifier = {
			add = {
				value = ai_greed
				multiply = -1
			}
			ai_greed > 0
			desc = TAKE_THE_VOWS_GREED
		}
		modifier = {
			add = {
				value = ai_boldness
				multiply = -1
			}
			ai_boldness < 0
			desc = TAKE_THE_VOWS_COWARDLINESS
		}
		modifier = {
			add = {
				value = ai_boldness
				multiply = -0.5
			}
			ai_boldness > 0
			desc = TAKE_THE_VOWS_BOLDNESS
		}
		modifier = {
			add = 50
			scope:recipient = {
				age >= 45
				is_visibly_fertile = no
				NOT = {
					any_heir_title = {
						exists = holder
					}
				}
			}
			desc = TAKE_THE_VOWS_RETIRE_IN_CHURCH
		}
		modifier = {
			add = 50
			exists = scope:puppet_or_actor.cp:councillor_court_chaplain
			scope:recipient = {
				OR = {
					has_relation_lover = scope:puppet_or_actor.cp:councillor_court_chaplain
					has_relation_friend = scope:puppet_or_actor.cp:councillor_court_chaplain
					has_secret_relation_lover = scope:puppet_or_actor.cp:councillor_court_chaplain
					has_relation_soulmate = scope:puppet_or_actor.cp:councillor_court_chaplain
					has_relation_best_friend = scope:puppet_or_actor.cp:councillor_court_chaplain
					opinion = {
						target = scope:puppet_or_actor.cp:councillor_court_chaplain
						value >= very_high_positive_opinion
					}
				}
			}
			desc = TAKE_THE_VOWS_INSPIRING_COURT_CHAPLAIN
		}
		modifier = {
			add = 50
			scope:recipient = {
				OR = {
					any_relation = {
						type = friend
						is_clergy = yes
					}
					any_relation = {
						type = best_friend
						is_clergy = yes
					}
					any_relation = {
						type = lover
						is_clergy = yes
					}
					any_relation = {
						type = soulmate
						is_clergy = yes
					}
					any_relation = {
						type = crush
						is_clergy = yes
					}
					any_secret = {
						type = secret_lover
						secret_target = {
							is_clergy = yes
						}
					}
				}
			}
			desc = TAKE_THE_VOWS_INSPIRING_CLERGY
		}
		modifier = {
			add = 50
			scope:recipient = {
				has_education_learning_trigger = yes
			}
			desc = TAKE_THE_VOWS_LEARNING_EDUCATION
		}

		modifier = {
			add = {
				add = 20
				multiply = scope:recipient.num_virtuous_traits
			}
			scope:recipient.num_virtuous_traits > 0
			desc = TAKE_THE_VOWS_VIRTUOUS
		}

		modifier = {
			add = {
				add = -20
				multiply = scope:recipient.num_sinful_traits
			}
			scope:recipient.num_sinful_traits > 0
			desc = TAKE_THE_VOWS_SINFUL
		}

		#Positive Personality Modifiers
		modifier = { # Wants to help people
			add = {
				value = ai_compassion
				divide = 2
			}
			scope:recipient = {
				ai_compassion > 0
				has_trait = lifestyle_physician
			}
			desc = TAKE_THE_VOWS_PHYSICIAN_WANTS_TO_HELP
		}
		modifier = {
			add = 1200
			scope:recipient = {
				has_trait = reclusive
			}
			desc = TAKE_THE_VOWS_RECLUSIVE
		}
		modifier = {
			add = 25
			scope:recipient = {
				has_trait = curious
			}
			desc = TAKE_THE_VOWS_CURIOUS
		}
		modifier = {
			add = 50
			scope:recipient = {
				has_trait = pensive
			}
			desc = TAKE_THE_VOWS_PENSIVE
		}
		modifier = { # Loves books & knowledge!
			add = 20
			scope:recipient = {
				has_trait = lifestyle_mystic
			}
			desc = TAKE_THE_VOWS_MYSTIC
		}
		modifier = { # Loves books & knowledge!
			add = 20
			scope:recipient = {
				has_trait = erudite
			}
			desc = TAKE_THE_VOWS_ERUDITE
		}
		modifier = { # Loves books & knowledge!
			add = 20
			scope:recipient = {
				has_trait = theologian
			}
			desc = TAKE_THE_VOWS_THEOLOGIAN
		}
		modifier = { # Plants!
			add = 20
			scope:recipient = {
				has_trait = lifestyle_herbalist
			}
			desc = TAKE_THE_VOWS_HERBALIST
		}
		modifier = {
			add = 25
			scope:recipient = {
				has_trait = temperate
			}
			desc = TAKE_THE_VOWS_TEMPERATE
		}
		modifier = {
			add = 100
			scope:recipient = {
				has_trait = celibate
			}
			desc = TAKE_THE_VOWS_CELIBATE
		}
		modifier = {
			add = 40
			scope:recipient = {
				has_trait = chaste
			}
			desc = TAKE_THE_VOWS_CHASTE
		}
		modifier = {
			add = 25
			scope:recipient = {
				has_trait = content
			}
			desc = TAKE_THE_VOWS_CONTENT
		}
		modifier = {
			add = 25
			scope:recipient = {
				has_trait = humble
			}
			desc = TAKE_THE_VOWS_HUMBLE
		}
		modifier = {
			add = 10
			scope:recipient = {
				has_trait = drunkard
			}
			desc = TAKE_THE_VOWS_DRUNKARD
		}
		modifier = {
			add = 10
			scope:recipient = {
				has_trait = hashishiyah
			}
			desc = TAKE_THE_VOWS_HASHISHIYAH
		}
		modifier = {
			add = 50
			scope:recipient = {
				has_trait = trusting
			}
			desc = TAKE_THE_VOWS_TRUSTING
		}

		#Negative Personality Modifiers
		modifier = {
			add = -50
			scope:recipient = {
				has_trait = rowdy
			}
			desc = TAKE_THE_VOWS_ROWDY
		}
		modifier = {
			add = -25
			scope:recipient = {
				has_trait = bossy
			}
			desc = TAKE_THE_VOWS_BOSSY
		}
		modifier = {
			add = -20
			scope:recipient = {
				has_trait = gluttonous
			}
			desc = TAKE_THE_VOWS_GLUTTONOUS
		}
		modifier = {
			add = -20
			scope:recipient = {
				has_trait = lustful
			}
			desc = TAKE_THE_VOWS_LUSTFUL
		}
		modifier = {
			add = -500
			scope:recipient = {
				has_trait = pregnant
			}
			desc = TAKE_THE_VOWS_PREGNANT
		}
		modifier = {
			add = -500
			scope:recipient = {
				has_trait = ambitious
			}
			desc = TAKE_THE_VOWS_AMBITIOUS
		}

		modifier = {
			add = -50
			scope:recipient = {
				OR = {
					is_married = yes
					exists = betrothed
				}
			}
			desc = TAKE_THE_VOWS_MARRIED_OR_BETROTHED
		}

		modifier = {
			add = -150
			scope:recipient = {
				is_primary_heir_of = scope:puppet_or_actor
			}
			desc = TAKE_THE_VOWS_PRIMARY_HEIR
		}

		modifier = {
			add = -75
			scope:recipient = {
				NOT = {
					is_primary_heir_of = scope:puppet_or_actor
				}
			}
			scope:puppet_or_actor.primary_title = {
				place_in_line_of_succession = {
					target = prev
					value = 2
				}
			}
			desc = TAKE_THE_VOWS_SECOND_HEIR
		}

		modifier = {
			add = -50
			scope:recipient = {
				NOT = {
					is_primary_heir_of = scope:puppet_or_actor
				}
			}
			scope:puppet_or_actor.primary_title = {
				place_in_line_of_succession = {
					target = prev
					value = 3
				}
			}
			desc = TAKE_THE_VOWS_THIRD_HEIR
		}

		modifier = {
			add = -25
			scope:recipient = {
				NOT = {
					is_primary_heir_of = scope:puppet_or_actor
				}
			}
			scope:puppet_or_actor.primary_title = {
				place_in_line_of_succession = {
					target = prev
					value >= 4
					value <= 10
				}
			}
			desc = TAKE_THE_VOWS_HEIR
		}

		modifier = {
			add = -100
			scope:recipient = {
				NOT = { is_heir_of = scope:puppet_or_actor }
				any_heir_title = {
					exists = holder
					holder != scope:puppet_or_actor
				}
				NOT = {
					is_primary_heir_of = scope:puppet_or_actor
				}
			}
			desc = TAKE_THE_VOWS_HEIR_TO_OTHER_TITLE
		}

		modifier = {
			add = -50
			scope:recipient = {
				NOT = { is_heir_of = scope:puppet_or_actor }
				any_parent = {
					any_held_title = {
						place_in_line_of_succession = {
							target = scope:recipient
							value < 5
						}
						NOT = {
							place_in_line_of_succession = {
								target = scope:recipient
								value < 2
							}
						}
					}
				}
				NOT = {
					is_primary_heir_of = scope:puppet_or_actor
				}
			}
			desc = TAKE_THE_VOWS_IN_LINE_TO_OTHER_TITLE
		}

		modifier = { #Rivalry modifier.
			desc = offer_vassalization_interaction_aibehavior_rival_tt
			trigger = {
				scope:recipient = {
					has_relation_rival = scope:puppet_or_actor
					NOT = { has_relation_nemesis = scope:puppet_or_actor }
				}
			}
			add = -50
		}
		modifier = { #Nemesis modifier.
			desc = offer_vassalization_interaction_aibehavior_nemesis_tt
			trigger = {
				scope:recipient = {
					has_relation_nemesis = scope:puppet_or_actor
				}
			}
			add = -100
		}

		#Dread modifiers
		modifier = {
			add = 25
			scope:recipient = {
				has_dread_level_towards = {
					target = scope:puppet_or_actor
					level = 1
				}
			}
			desc = INTIMIDATED_REASON
		}
		modifier = {
			add = 50
			scope:recipient = {
				has_dread_level_towards = {
					target = scope:puppet_or_actor
					level = 2
				}
			}
			desc = COWED_REASON
		}

		# Culture Tradition modifiers

		modifier = {
			add = {
				value = 25
				if = {
					limit = {
						scope:recipient = {
							is_adult = no
							is_child_of = scope:puppet_or_actor
						}
					}
					add = 100
				}
			}
			scope:puppet_or_actor.culture = { has_cultural_parameter = monastic_expectations }
			desc = MONASTIC_EXPECTATIONS_REASON
		}

		# PAM - Concord Phase
		modifier = {
			add = 25
			situation:the_christian_church ?= {
				any_participant_group = { # Both characters are involved in the situation
					any_situation_group_participant = {
						this = scope:puppet_or_actor
					}
					trigger_if = {
						limit = { scope:recipient = { is_ruler = yes } }
						any_situation_group_participant = {
							this = scope:recipient
						}
					}
				}
				has_situation_top_phase_parameter = the_christian_church_better_take_the_vows_acceptance
			}
			desc = pam_the_christian_church_better_take_the_vows_acceptance_desc
		}
	}

	# AI will do

	ai_target_quick_trigger = {
		adult = yes
	}

	ai_targets = {
		ai_recipients = courtiers
		max = 5
	}

	ai_targets = {
		ai_recipients = children
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 144
		duchy = 72
		kingdom = 24
		empire = 24
		hegemony = 24
	}

	ai_will_do = {
		base = 0

		modifier = {
			add = -50
			scope:puppet_or_actor = {
				OR = {
					legitimacy_level = 0
					legitimacy_level = 1
				}
			}
			scope:recipient = { is_primary_heir_of = scope:puppet_or_actor }
		}

		modifier = { # The AI will always use a Hook
			scope:hook = yes
			add = 1
		}

		modifier = { # Try to send rivals
			add = 100
			scope:puppet_or_actor = {
				OR = {
					has_relation_rival = scope:recipient
					has_relation_nemesis = scope:recipient
				}
			}
		}

		modifier = { # Try to send people who would make poor heirs
			add = 20
			scope:recipient = {
				OR = {
					character_considered_morally_dubious_trigger = { RITE = scope:puppet_or_actor.rite }
					has_trait = drunkard
					has_trait = hashishiyah
					has_trait = flagellant
					has_trait = reclusive
					num_of_bad_genetic_traits = 1
					num_sinful_traits = 1
				}
				scope:puppet_or_actor.primary_title = {
					place_in_line_of_succession = {
						target = prev
						value <= 7
					}
				}
			}
		}
		modifier = { # Try to send people who would make terrible heirs
			add = 50
			scope:recipient = {
				OR = {
					character_considered_wicked_trigger = { RITE = scope:puppet_or_actor.rite }
					has_trait = maimed
					num_of_bad_genetic_traits >= 2
					num_sinful_traits >= 2
				}
				scope:puppet_or_actor.primary_title = {
					place_in_line_of_succession = {
						target = prev
						value <= 7
					}
				}
			}
		}

		modifier = { # Try to send people who would make poor heirs
			add = 25
			scope:recipient = {
				is_adult = yes
				calc_true_if = {
					amount >= 3

					diplomacy < 8
					stewardship < 8
					martial < 8
					intrigue < 8
					learning < 8
				}
				scope:puppet_or_actor.primary_title = {
					place_in_line_of_succession = {
						target = prev
						value <= 7
					}
				}
			}
		}

		modifier = { # Sending one of your heirs is almost customary
			add = 100
			scope:puppet_or_actor = {
				any_child = {
					count >= 3
				}
				NOT = {
					any_child = {
						OR = {
							has_trait = devoted
							has_trait = order_member
						}
					}
				}
			}
			scope:recipient = {
				is_child_of = scope:puppet_or_actor
				has_education_learning_trigger = yes
			}
		}

		modifier = { # Zealous characters generally want to send characters to the clergy
			add = 50
			scope:puppet_or_actor = {
				ai_zeal >= high_positive_ai_value
			}
			scope:recipient = {
				has_education_learning_trigger = yes
			}
		}

		modifier = { # Greedy characters want to rid their court of potential threats
			add = 50
			scope:puppet_or_actor = {
				ai_greed >= medium_positive_ai_value
				any_child = { }
			}
			scope:recipient = {
				NOT = {
					is_child_of = scope:puppet_or_actor
				}
				any_claim = {
					holder ?= scope:puppet_or_actor
				}
			}
		}

		modifier = { # The AI doesn't ask married/betrothed people
			factor = 0
			scope:recipient = {
				OR = {
					exists = betrothed
					is_married = yes
				}
			}
		}

		modifier = { # Never ask Primary Heir
			factor = 0
			scope:recipient = {
				is_primary_heir_of = scope:puppet_or_actor
			}
		}

		modifier = { # Only care about family
			factor = 0
			scope:recipient = {
				NOT = {
					is_close_or_extended_family_of = scope:puppet_or_actor
				}
			}
		}

		modifier = {
			factor = 0
			scope:recipient.liege ?= { is_ai = no }
		}
	}
}

### End Monasticism tenets ###

#########################
# Temporal Condemnation
# by Petter Vilberg
#########################

temporal_condemnation_interaction = {
	category = interaction_category_religion
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:puppet_or_actor.faith = faith:quranist }
				desc = temporal_condemnation_interaction_desc_fasiq
			}
			desc = temporal_condemnation_interaction_desc
		}
	}
	icon = religious

	is_shown = {
		scope:puppet_or_actor != scope:recipient
		scope:puppet_or_actor.rite ?= {
			rite_has_parameter = temporal_condemnation_enabled
		}
		scope:recipient = {
			liege ?= scope:puppet_or_actor
			is_playable_character = yes
			is_ruler = yes
		}
	}

	cooldown = { years = 5 }

	is_valid = {
		scope:puppet_or_actor = {
			piety >= medium_piety_value
		}
	}

	is_valid_showing_failures_only = {
		scope:recipient.religion = scope:puppet_or_actor.religion
		custom_description = {
			text = temporal_condemnation_has_been_condemned
			object = scope:recipient
			scope:recipient = {
				NOT = {
					has_character_modifier = temporal_condemnation_modifier
				}
			}
		}
		NAND = {
			exists = scope:puppet_or_actor.faith.great_holy_war
			scope:puppet_or_actor.faith.great_holy_war = {
				has_pledged_attacker = scope:recipient
			}
		}
		scope:recipient = {
			is_adult = yes
		}
		scope:recipient = { NOT = { has_strong_hook = scope:puppet_or_actor } }
	}

	auto_accept = yes
	force_notification = yes
	notification_text = temporal_condemnation_interaction.notification

	on_accept = {
		scope:puppet_or_actor = {
			add_piety = medium_piety_loss
		}

		scope:puppet_or_actor = {
			duel = {
				skill = learning
				value = religious_legal_pronouncement_learning_requirement
				50 = {
					desc = temporal_condemnation_interaction_success
					compare_modifier = {
						value = scope:duel_value
						multiplier = 3
						min = -45
					}
					modifier = {
						add = 25
						scope:puppet_or_actor = {
							has_personal_tenet_flag = tenet_religious_law_condemnation_bonus
						}
					}
					scope:puppet_or_actor = {
						add_opinion = {
							target = scope:recipient
							modifier = temporal_condemnation_opinion
							years = 10
						}
						custom_tooltip = temporal_condemnation_revoke_reason
						hidden_effect = {
							send_interface_toast = {
								type = event_toast_effect_good
								title = temporal_condemnation_interaction.tt
								left_icon = scope:recipient
								show_as_tooltip = { custom_tooltip = temporal_condemnation_got_revoke_reason }
								if = {
									limit = {
										has_personal_tenet_flag = tenet_religious_law_scholar_trait
									}
									add_trait_xp = {
										trait = lifestyle_scholar
										value = 20
									}
								}
							}
						}
						stress_and_fulfillment_impact = {
							cynical = minor_stress_impact_gain
						}
					}
					if = {
						limit = {
							scope:is_puppet_action ?= yes
							scope:actor != scope:recipient
						}
						scope:actor = {
							send_interface_toast = {
								type = event_toast_effect_good
								title = temporal_condemnation_interaction.tt_puppeteer
								left_icon = scope:puppet_or_actor
								right_icon = scope:recipient
							}
						}
					}
					scope:recipient = {
						add_character_modifier = {
							modifier = temporal_condemnation_modifier
							years = 15
						}
						add_opinion = {
							target = scope:puppet_or_actor
							modifier = temporal_condemnation_condemned_me_opinion
						}
						send_interface_toast = {
							type = event_toast_effect_bad
							title = temporal_condemnation_interaction.recipient_success
							left_icon = scope:puppet_or_actor
							custom_tooltip = temporal_condemnation_interaction.recipient_success_desc
						}
					}

					# 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_gain
						DESC = clan_unity_condemn_sins.desc
						REVERSE_NON_HOUSE_TARGET = no
					}
				}
				50 = {
					desc = temporal_condemnation_interaction_failure
					compare_modifier = {
						value = scope:duel_value
						multiplier = -3
						min = -45
					}
					scope:puppet_or_actor = {
						send_interface_toast = {
							type = event_toast_effect_bad
							title = temporal_condemnation_interaction.failure
							left_icon = scope:recipient
							custom_tooltip = temporal_condemnation_interaction.failure_desc
						}
					}
					if = {
						limit = {
							scope:is_puppet_action ?= yes
							scope:actor != scope:recipient
						}
						scope:actor = {
							send_interface_toast = {
								type = event_toast_effect_bad
								title = temporal_condemnation_interaction.failure
								left_icon = scope:recipient
								custom_tooltip = temporal_condemnation_interaction.failure_desc
							}
						}
					}
				}
			}
		}
	}
}

#########################
# Host Honored Guest
# by Sean Hughes
#########################

host_honored_guest_interaction = {
	icon = religious
	category = interaction_category_friendly

	desc = host_honored_guest_interaction_desc

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

	cooldown = { years = 1 }

	is_available = {
		trigger_if = {
			limit = { is_ai = yes }
			piety >= major_piety_value
		}
	}

	is_shown = {
		scope:recipient != scope:puppet_or_actor
		scope:puppet_or_actor ?= {
			rite ?= {
				rite_has_parameter = host_honored_guests_active
			}
			is_playable_character = yes
			is_adult = yes
		}
	}

	is_valid_showing_failures_only = {
		# Target faith is Hostile.
		custom_description = {
			text = host_honored_guest_is_hostile
			object = scope:recipient
			NOT = {
				scope:recipient = {
					rite = {
						rite_hostility_level = {
							target = scope:puppet_or_actor.rite
							value = faith_hostile_level
						}
					}
				}
			}
		}
		# Target faith is Evil.
		custom_description = {
			text = host_honored_guest_is_evil
			object = scope:recipient
			NOT = {
				scope:recipient = {
					rite = {
						rite_hostility_level = {
							target = scope:puppet_or_actor.rite
							value = faith_evil_level
						}
					}
				}
			}
		}
		# Target is sick
		custom_description = {
			text = host_honored_guest_is_unwell
			object = scope:recipient
			scope:recipient = {
				is_healthy = yes
			}
		}
		# Target is commanding an army
		custom_description = {
			text = host_honored_guest_is_commanding
			object = scope:recipient
			scope:recipient = {
				is_commanding_army = no
			}
		}
		# Target is imprisoned
		custom_description = {
			text = host_honored_guest_is_imprisoned
			object = scope:recipient
			scope:recipient = {
				is_imprisoned = no
			}
		}
		# At war with target
		custom_description = {
			text = host_honored_guest_is_at_war
			object = scope:recipient
			scope:recipient = {
				NOT = { is_at_war_with = scope:puppet_or_actor }
			}
		}
		# Is my courtier
		custom_description = {
			text = host_honored_guest_is_my_courtier
			object = scope:recipient
			scope:recipient = {
				NOT = { is_courtier_of = scope:puppet_or_actor }
			}
		}
	}

	auto_accept = yes
	force_notification = yes
	notification_text = host_honored_guest_interaction.notification
	#answer_accept_key = host_honored_guest_interaction.response

	on_accept = {
		scope:puppet_or_actor = {
			stress_and_fulfillment_impact = {
				cynical = minor_stress_impact_gain
				shy = minor_stress_impact_gain
			}
		}
		scope:recipient = {
			hidden_effect = {
				send_interface_toast = {
					type = event_toast_effect_good
					title = host_honored_guest_interaction_recipient.notification
					left_icon = scope:puppet_or_actor
				}
			}
			# Spend piety based on recipient's tier.
			scope:puppet_or_actor = {
				add_piety = {
					value = 0
					subtract = scope:recipient.tier_scaled_piety_value
				}
			}

			# Increase opinion of recipient.
			add_opinion = {
				modifier = pleased_opinion
				target = scope:puppet_or_actor
				opinion = {
					value = 20

					# Zealous characters more likely to appreciate the religious ceremony (if of your faith)
					if = {
						limit = {
							has_trait = zealous
							faith = scope:puppet_or_actor.faith
						}
						add = 10
					}
					# Cynical characters, or characters who do not believe in the hospitality ritual, are less likely to be appreciative.
					else_if = {
						limit = {
							OR = {
								has_trait = cynical
								NOT = {
									rite = {
										rite_has_parameter = host_honored_guests_active
									}
								}
							}
						}
						subtract = 10
					}

					# But arrogant characters like it more regardless.
					if = {
						limit = {
							has_trait = arrogant
						}
						add = 10
					}
				}
			}
		}

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

	ai_will_do = {
		base = 0

		modifier = {
			add = 100
			scope:recipient = {
				OR = {
					is_powerful_vassal_of = scope:puppet_or_actor
					liege = root
				}
				opinion = {
					target = scope:puppet_or_actor
					value = {-15 0 }
				}
			}
		}

		modifier = {
			add = 75
			scope:recipient = {
				OR = {
					is_powerful_vassal_of = scope:puppet_or_actor
					liege = root
				}
				opinion = {
					target = scope:puppet_or_actor
					value = { 0 20 }
				}
			}
		}

		modifier = {
			add = 40
			scope:recipient = {
				OR = {
					is_powerful_vassal_of = scope:puppet_or_actor
					liege = root
				}
				opinion = {
					target = scope:puppet_or_actor
					value = { 20 60 }
				}
			}
		}

		modifier = {
			add = 10
			scope:recipient = {
				OR = {
					is_powerful_vassal_of = scope:puppet_or_actor
					liege = root
				}
				opinion = {
					target = scope:puppet_or_actor
					value = { 60 100 }
				}
			}
		}
	}
}

# Spiritual Head of Faith Actions

hof_ask_for_gold_interaction = {
	icon = icon_clergy_ask_money
	category = interaction_category_religion
	common_interaction = yes

	desc = hof_ask_for_gold_interaction_desc

	notification_text = RECIPIENT_HOF_ASK_FOR_GOLD

	ai_targets = {
		ai_recipients = head_of_faith
		ai_recipients = religious_head_challenger
		ai_recipients = realm_priest_superior
		ai_recipients = superior
		ai_recipients = realm_priest_top_superior
		ai_recipients = councillors
	}
	ai_target_quick_trigger = {
		adult = yes
	}
	ai_frequency_by_tier = {
		barony = 0
		county = 36
		duchy = 24
		kingdom = 6
		empire = 6
		hegemony = 6
	}

	cooldown_against_recipient = { years = 3 }

	redirect = {
		scope:actor = {
			spiritual_hof_or_realm_priest_superior_recipient_redirect_effect = yes
		}
	}

	is_available = {
		trigger_if = {
			limit = {
				is_ai = yes
			}
			piety >= major_piety_value
			NOR = {
				has_trait = excommunicated
				has_character_flag = hof_request_cooldown
			}
			OR = {
				is_landed = yes
				government_has_mechanic = theocracy
			}
		}
	}

	is_shown = {
		scope:recipient != scope:puppet_or_actor
		scope:puppet_or_actor ?= {
			faith ?= {
				OR = {
					has_doctrine = doctrine_spiritual_head
					has_doctrine_parameter = has_clerical_regions
				}
			}
			is_playable_character = yes
			NOT = {
				# Ecclesiasticals have the 'request_ecclesiastical_treasury_interaction' instead
				government_has_flag = government_is_ecclesiastical
			}
			broader_clergy_show_hof_or_superior_interactions_trigger = yes
		}
		scope:recipient = {
			faith = scope:puppet_or_actor.faith
			# Antipope uses petition_antipope_gold_interaction instead
			trigger_if = {
				limit = { has_pam_dlc_trigger = yes }
				pam_is_antipope_trigger = no
			}
		}
		# Those under an antipope ask them for gold instead of the real Head of Faith
		trigger_if = {
			limit = {
				scope:recipient ?= scope:puppet_or_actor.faith.religious_head
			}
			scope:puppet_or_actor ?= { is_following_religious_head_challenger = no }
		}
	}

	is_valid_showing_failures_only = {
		scope:recipient = {
			trigger_if = {
				limit = {
					has_treasury = yes
				}
				treasury >= hof_ask_for_gold_request_value
			}
			trigger_else = {
				gold >= hof_ask_for_gold_request_value
			}
		}

		scope:actor = {
			spiritual_hof_or_realm_priest_superior_recipient_trigger = yes
			piety >= major_piety_value
			trigger_if = {
				limit = {
					has_pam_dlc_trigger = yes
				}
				clergy_interaction_generic_piety_level_or_puppet_req_trigger = yes
			}
			NOR = {
				has_trait = excommunicated
				is_at_war_with = scope:recipient
				has_character_modifier = promised_pilgrimage_to_clergy_modifier
			}
			custom_tooltip = {
				text = HOF_INTERACTION_UNREFORMED_FAITH
				NOT = {
					faith = { has_doctrine_parameter = unreformed }
				}
			}
			pam_antipope_clerical_request_trigger = { RECIPIENT = scope:recipient }
		}
	}

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

	ai_accept = {
		base = -40

		celestial_hierarchy_acceptance_modifier = {
			ACTOR = scope:actor
			RECIPIENT = scope:recipient
		}

		modifier = {
			add = 25
			scope:influence_send_option = yes
			desc = INFLUENCE_INTERACTION_ACCEPTANCE_SEND_OPTION
		}

		modifier = {
			add = pam_offer_pilgrimage_acceptance_value
			scope:offer_pilgrimage = yes
			desc = OFFER_PILGRIMAGE_INTERACTION_OPTION_REASON
		}

		ask_for_gold_acceptance_modifier = yes
	}

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

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

	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
			custom_tooltip = {
				text = not_same_realm_tt
				scope:recipient.top_liege = scope:actor.top_liege
			}
		}
		flag = influence_send_option
		localization = TRADE_INFLUENCE_FOR_BETTER_AI_ACCEPTANCE
	}

	send_option = {
		is_shown = {
			has_pam_dlc_trigger = yes
			pam_offer_pilgrimage_option_shown_trigger = { ACTOR = scope:actor }
		}
		is_valid = {
			pam_offer_pilgrimage_option_valid_trigger = { ACTOR = scope:actor }
		}
		flag = offer_pilgrimage
		localization = OFFER_PILGRIMAGE_INTERACTION_OPTION
	}

	send_options_exclusive = no

	ai_min_reply_days = 1
	ai_max_reply_days = 5

	can_send = {
		# Anti-spam AI blockers
		ai_religious_request_blocker_trigger = { INTERACTION = hof_ask_for_gold_interaction }
	}

	on_send = {
		# Anti-spam AI blockers
		ai_religious_request_blocker_effect = { INTERACTION = hof_ask_for_gold_interaction }
	}

	on_accept = {
		hof_ask_for_gold_interaction_effect = yes

		pam_offer_pilgrimage_effect = {
			ACTOR = scope:actor
			CLERIC = scope:recipient
		}

		scope:actor = {
			trigger_event = religious_interaction.3
		}
	}

	on_decline = {
		scope:recipient = {
			add_piety = miniscule_piety_loss
		}
		scope:actor = {
			show_as_tooltip = {
				hof_ask_for_gold_refusal_effect = yes
			}
			trigger_event = religious_interaction.32
		}
	}

	ai_will_do = {
		base = 0

		modifier = { # The AI will only use a Hook if they couldn't otherwise do this
			scope:hook = yes
			add = -1
		}
		#Make AI clerics do this less - they should use Request Treasury Funds instead
		modifier = {
			is_clergy = yes
			add = -25
		}
		modifier = { # Counts get a bad 'exchange rate' due to their low income.
			highest_held_title_tier < tier_county
			scope:recipient.treasury_or_gold < 3000
			add = -50
		}
		modifier = { # Dukes are also somewhat reluctant to request gold if not independent.
			highest_held_title_tier = tier_duchy
			top_liege != this
			scope:recipient.treasury_or_gold < 3000
			add = -25
		}
		modifier = { # dont spam on player HoF
			scope:recipient = {
				is_ai = no
				faith.religious_head ?= this
			}
			add = -50
		}

		modifier = { # I am low on money while at war
			add = 50
			scope:actor = {
				is_at_war = yes
				gold < medium_gold_value
			}
		}
		modifier = { # I am in debt
			add = 50
			scope:actor = {
				gold < 0
			}
			#Pope demanding hook in return
			NOT = {
				scope:recipient = {
					OR = {
						ai_honor < 0
						ai_zeal < low_negative_ai_value
					}
				}
			}
		}
		modifier = { # I am badly in debt
			add = 50
			scope:actor = {
				gold < massive_gold_value_negative
			}
		}
		modifier = { # Piety to burn, and no reason to keep it.
			add = 25
			scope:actor = {
				piety > massive_piety_value
				NOR = {
					has_character_modifier = vow_of_poverty_modifier
					has_trait = generous
				}
			}
		}
		modifier = { # Or when greedy
			add = scope:actor.ai_greed
			scope:actor = {
				ai_greed > 0
			}
		}

		modifier = { # If the Pope has overflowing coffers, it'd be rather impious to NOT ask him to give some to a fellow, poor and struggling christian!
			add = {
				value = scope:recipient.treasury_or_gold
				subtract = 1000
				divide = 100
				max = 50
			}
			scope:actor = {
				OR = {
					ai_has_economical_boom_personality = yes
					piety > major_piety_value
					AND = {
						ai_has_warlike_personality = yes
						war_chest_gold < war_chest_gold_maximum
					}
				}
			}
			scope:recipient.treasury_or_gold >= 1000
		}

		modifier = { #That's _my_ piety
			add = -100
			scope:actor = { ai_has_builder_or_pious_builder_personality = yes }
		}

		modifier = { #Go on! Git!
			add = -100
			scope:actor = { government_has_flag = government_is_mandala }
		}
	}
}

hof_ask_for_claim_interaction = {
	category = interaction_category_diplomacy
	icon = icon_clergy_claim_title
	interface_priority = 35

	desc = hof_ask_for_claim_interaction_desc
	notification_text = hof_ask_for_claim_interaction_notification
	target_type = title
	target_filter = secondary_recipient_domain_titles
	redirect = {
		if = {
			limit = {
				exists = scope:actor.religious_head_or_challenger
			}
			scope:recipient = {
				save_scope_as = secondary_recipient
			}
			scope:actor.religious_head_or_challenger = {
				save_scope_as = recipient
			}
		}
	}

	has_valid_target_showing_failures_only = {
		scope:target = {
			tier >= tier_county
			is_landless_type_title = no
		}
		trigger_if = { # Admin can't request claim on other admin titles, only the top liege's primary title is up for grabs
			limit = {
				scope:secondary_recipient = {
					government_has_mechanic = administrative
					top_liege = this
				}
				scope:actor = {
					government_has_mechanic = administrative
				}
			}
			scope:target = {
				this = scope:secondary_recipient.primary_title
			}
		}
	}

	cooldown_against_recipient = { years = 3 }

	is_available = {
		trigger_if = {
			limit = { is_ai = yes }
			piety >= major_piety_value
			exists = religious_head_or_challenger
			is_playable_character = yes
			OR = {
				ai_greed >= 50
				ai_has_warlike_personality = yes
			}
			NOR = {
				has_trait = excommunicated
				has_character_flag = hof_request_cooldown
			}
		}
		NOT = {
			has_character_modifier = promised_pilgrimage_to_clergy_modifier
		}
	}

	is_shown = {
		#Pam DLC has new version
		has_pam_dlc_trigger = no
		exists = scope:actor.religious_head_or_challenger
		scope:actor != scope:actor.religious_head_or_challenger
		scope:recipient.religious_head_or_challenger ?= scope:actor.religious_head_or_challenger
		scope:actor.faith ?= scope:secondary_recipient.faith
		NOR = {
			scope:actor = scope:secondary_recipient
			scope:secondary_recipient ?= scope:recipient
		}
		scope:actor.faith ?= {
			has_doctrine = doctrine_spiritual_head
		}
		scope:secondary_recipient ?= {
			is_landed_or_landless_administrative = yes
			primary_title ?= { tier >= tier_county }
			NOT = { government_has_flag = government_is_holy_order }
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			pam_antipope_clerical_request_trigger = { RECIPIENT = scope:recipient }
		}
		pam_not_promised_pilgrimage_trigger = { ACTOR = scope:actor }
		trigger_if = { # Can't request on titles you already have a pressed claim on
			limit = {
				exists = scope:target
				scope:actor = {
					has_strong_claim_on = scope:target
				}
			}
			custom_description = {
				text = "hof_ask_for_claim_has_pressed_claim_already"
				always = no
			}
		}
		trigger_if = { # Can't request claims on baronies
			limit = {
				OR = {
					scope:recipient.highest_held_title_tier = tier_barony
					AND = {
						exists = scope:target
						scope:target = {
							tier = tier_barony
						}
					}
				}
			}
			custom_description = {
				text = "hof_ask_for_claim_no_baronies"
				always = no
			}
		}
		trigger_if = { # Can't request claims on theocratic lessees or theocracies (= Prince-Bishops)
			limit = {
				scope:secondary_recipient = {
					government_has_flag = government_is_theocracy
				}
			}
			custom_description = {
				text = "hof_ask_for_claim_theocratic_lessee"
				always = no
			}
		}
		trigger_if = { # Admin can't request claims on other admin titles
			limit = {
				scope:secondary_recipient = {
					government_has_mechanic = administrative
					NOT = { top_liege = this }
				}
				scope:actor = {
					government_has_mechanic = administrative
				}
			}
			custom_description = {
				text = "hof_ask_for_claim_on_admin_titles"
				always = no
			}
		}
		scope:actor = { # Variable piety cost depending on tier
			trigger_if = {
				limit = {
					exists = scope:target
				}
				piety >= claim_piety_value
			}
			custom_description = {
				text = "hof_ask_for_claim_excommunicated"
				NOT = { has_trait = excommunicated }
			}
			NOT = {
				is_at_war_with = scope:recipient
			}
		}
		scope:actor = {
			custom_tooltip = {
				text = HOF_INTERACTION_UNREFORMED_FAITH
				NOT = {
					faith = { has_doctrine_parameter = unreformed }
				}
			}
		}
		scope:secondary_recipient = { NOT = { has_strong_hook = scope:actor } }
		# Ceremonial Monarchs cannot do this
		scope:actor = { tgp_is_ceremonial_liege_trigger = no }
	}

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

	ai_targets = {
		ai_recipients = neighboring_rulers
		ai_recipients = peer_vassals
		ai_recipients = liege
	}
	ai_frequency_by_tier = {
		barony = 0
		county = 108
		duchy = 36
		kingdom = 12
		empire = 12
		hegemony = 12
	}

	ai_will_do = {
		base = 0

		modifier = {
			add = scope:actor.ai_greed
		}

		modifier = {
			add = scope:target.tier
		}

		modifier = {
			add = 500
			has_variable = conqueror
			NOR = {
				has_relation_friend = scope:secondary_recipient
				has_relation_lover = scope:secondary_recipient
			}
		}

		modifier = {
			add = -100
			scope:actor = {
				OR = {
					has_relation_friend = scope:secondary_recipient
					has_relation_lover = scope:secondary_recipient
					opinion = {
						target = scope:secondary_recipient
						value >= high_positive_opinion
					}
				}
			}
		}

		modifier = {
			factor = 0
			NOT = {
				scope:target = {
					is_neighbor_to_realm = scope:actor
				}
			}
		}
	}

	ai_accept = {
		base = 0 # Should be 0 for all interactions

		celestial_hierarchy_acceptance_modifier = {
			ACTOR = scope:actor
			RECIPIENT = scope:recipient
		}

		modifier = { # By God Alone - Secular Faith: the petitioner holds the ear of the clergy
			add = 25
			desc = pam_sf_ear_of_clergy_accept_reason
			trigger = {
				scope:actor = { has_character_modifier = pam_sf_ear_of_clergy_modifier }
			}
		}

		modifier = {
			scope:claim_hook ?= yes
			add = 100
			desc = SCHEME_WEAK_HOOK_USED
		}

		modifier = {
			add = -100
			desc = BASE_RELUCTANCE
		}

		modifier = { # Very difficult to claim Kingdoms/Empires when already King/Emperor
			add = -100
			desc = I_AM_ALREADY_HIGH_TIER
			scope:actor.primary_title ?= {
				tier >= tier_kingdom
			}
			scope:target = {
				tier >= tier_kingdom
			}
		}

		modifier = { # Characters with a pressed claim on a kingdom or empire already has a reduced chance of getting a claim on a kingdom or empire
			add = -50
			desc = I_ALREADY_HAVE_A_KINGDOM_OR_EMPIRE_CLAIM
			scope:actor = {
				any_claim = {
					pressed = yes
					tier >= tier_kingdom
				}
			}
			scope:target = {
				tier >= tier_kingdom
			}
		}

		opinion_modifier = { # More likely if Recipient likes Actor
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 0.5
			desc = AI_OPINION_REASON
		}

		modifier = { # Same language
			add = 5
			desc = speaks_same_language_interaction_reason
			trigger = {
				scope:actor = {
					knows_language_of_culture = scope:recipient.culture
				}
			}
		}
		modifier = { # Easier claims from HoF during instability
			add = 25
			desc = CHRISTIAN_CHURCH_PHASE_REASON
			situation:the_christian_church ?= {
				situation_participant_group:christian_regular_main_power_rulers = {
					participant_group_has_character = scope:actor
					has_participant_group_parameter = the_christian_church_easier_claims_from_hof
				}
			}
		}
		modifier = { # Unlikely if recipient likes Secondary Recipient
			desc = AI_OPINION_RECIPIENT_REASON
			add = {
				if = {
					limit = {
						scope:recipient != scope:secondary_recipient
					}
					subtract = "scope:recipient.opinion(scope:secondary_recipient)"
				}
			}
		}

		modifier = { # Less likely the lower their tier is compared to you
			add = {
				add = -10
				if = {
					limit = {
						scope:actor = {
							tier_difference = {
								target = scope:secondary_recipient
								value >= 2
							}
						}
					}
					add = -10
				}
				if = {
					limit = {
						scope:actor = {
							tier_difference = {
								target = scope:secondary_recipient
								value >= 3
							}
						}
					}
					add = -10
				}
			}
			desc = THEY_ARE_LOWER_TIER
			scope:actor = {
				tier_difference = {
					target = scope:secondary_recipient
					value >= 1
				}
			}
		}

		modifier = { # Penalty for asking claims on your own vassals
			add = -50
			desc = THEY_ARE_YOUR_VASSAL
			scope:actor = {
				any_vassal_or_below = {
					this = scope:secondary_recipient
				}
			}
		}

		modifier = { # Bonus for adults to ask on children
			add = 25
			desc = THEY_ARE_A_CHILD
			scope:secondary_recipient = {
				is_adult = no
			}
			scope:actor = {
				is_adult = yes
			}
		}

		modifier = { # Penalty for children to ask on adults
			add = -25
			desc = I_AM_A_CHILD
			scope:secondary_recipient = {
				is_adult = yes
			}
			scope:actor = {
				is_adult = no
			}
		}

		modifier = { # Bonus for men if a woman under male preference
			add = 15
			desc = THEY_ARE_FEMALE_WHEN_MALE_IS_PREFERRED
			scope:secondary_recipient = {
				is_adult = yes
				is_female = yes
			}
			scope:actor = {
				is_adult = yes
				is_female = no
				rite = {
					rite_has_doctrine = doctrine_gender_male_dominated
				}
			}
		}

		modifier = { # Bonus for women if a man under female preference
			add = 15
			desc = THEY_ARE_MALE_WHEN_FEMALE_IS_PREFERRED
			scope:secondary_recipient = {
				is_adult = yes
				is_female = no
			}
			scope:actor = {
				is_adult = yes
				is_female = yes
				rite = {
					rite_has_doctrine = doctrine_gender_female_dominated
				}
			}
		}

		modifier = { # Penalty for women to ask claims on men under male preference
			add = -15
			desc = I_AM_FEMALE_WHEN_MALE_IS_PREFERRED
			scope:actor = {
				is_adult = yes
				is_female = yes
				rite = {
					rite_has_doctrine = doctrine_gender_male_dominated
				}
			}
			scope:secondary_recipient = {
				is_adult = yes
				is_female = no
			}
		}

		modifier = { # Penalty for men to ask claims on women under female preference
			add = -15
			desc = I_AM_MALE_WHEN_FEMALE_IS_PREFERRED
			scope:actor = {
				is_adult = yes
				is_female = no
				rite = {
					rite_has_doctrine = doctrine_gender_female_dominated
				}
			}
			scope:secondary_recipient = {
				is_adult = yes
				is_female = yes
			}
		}

		modifier = { # They are Excommunicated
			add = 25
			desc = THEY_ARE_EXCOMMUNICATED
			scope:secondary_recipient = {
				has_trait = excommunicated
			}
		}

		modifier = { # I am Adulterer/Fornicator
			add = -25
			desc = I_AM_ADULTERER
			scope:actor = {
				OR = {
					AND = {
						has_trait = fornicator
						trait_is_shunned_or_criminal_in_rite_trigger = { RITE = rite TRAIT = trait:fornicator GENDER_CHARACTER = scope:actor }
					}
					AND = {
						has_trait = adulterer
						trait_is_shunned_or_criminal_in_rite_trigger = { RITE = rite TRAIT = trait:adulterer GENDER_CHARACTER = scope:actor }
					}
				}
			}
		}

		modifier = { # They are Adulterer/Fornicator
			add = 15
			desc = THEY_ARE_ADULTERER
			scope:secondary_recipient = {
				OR = {
					AND = {
						has_trait = fornicator
						trait_is_shunned_or_criminal_in_rite_trigger = { RITE = rite TRAIT = trait:fornicator GENDER_CHARACTER = scope:secondary_recipient }
					}
					AND = {
						has_trait = adulterer
						trait_is_shunned_or_criminal_in_rite_trigger = { RITE = rite TRAIT = trait:adulterer GENDER_CHARACTER = scope:secondary_recipient }
					}
				}
			}
		}

		modifier = { # I am Incestous
			add = -50
			desc = I_AM_INCESTOUS
			scope:actor = {
				NOT = { scope:recipient = { rite = { rite_has_doctrine = doctrine_consanguinity_unrestricted } } }
				has_trait = incestuous
			}
		}

		modifier = { # I am a Murderer
			add = -50
			desc = I_AM_MURDERER
			scope:actor = {
				has_trait = murderer
			}
		}

		modifier = { # They are a Murderer
			add = 15
			desc = THEY_ARE_MURDERER
			scope:secondary_recipient = {
				has_trait = murderer
			}
		}

		modifier = { # They are Incestous
			add = 15
			desc = THEY_ARE_INCESTOUS
			scope:secondary_recipient = {
				NOT = { scope:recipient = { rite = { rite_has_doctrine = doctrine_consanguinity_unrestricted } } }
				has_trait = incestuous
			}
		}

		modifier = { # I am a Kinslayer
			add = -50
			desc = I_AM_A_KINSLAYER
			scope:actor = {
				OR = {
					AND = {
						has_trait = kinslayer_1
						trait_is_shunned_or_criminal_in_rite_trigger = { RITE = rite TRAIT = trait:kinslayer_1 GENDER_CHARACTER = scope:actor }
					}
					AND = {
						has_trait = kinslayer_2
						trait_is_shunned_or_criminal_in_rite_trigger = { RITE = rite TRAIT = trait:kinslayer_2 GENDER_CHARACTER = scope:actor }
					}
					AND = {
						has_trait = kinslayer_3
						trait_is_shunned_or_criminal_in_rite_trigger = { RITE = rite TRAIT = trait:kinslayer_3 GENDER_CHARACTER = scope:actor }
					}
				}
			}
		}

		modifier = { # They are a Kinslayer
			add = 15
			desc = THEY_ARE_A_KINSLAYER
			scope:secondary_recipient = {
				OR = {
					AND = {
						has_trait = kinslayer_1
						trait_is_shunned_or_criminal_in_rite_trigger = { RITE = rite TRAIT = trait:kinslayer_1 GENDER_CHARACTER = scope:secondary_recipient }
					}
					AND = {
						has_trait = kinslayer_2
						trait_is_shunned_or_criminal_in_rite_trigger = { RITE = rite TRAIT = trait:kinslayer_2 GENDER_CHARACTER = scope:secondary_recipient }
					}
					AND = {
						has_trait = kinslayer_3
						trait_is_shunned_or_criminal_in_rite_trigger = { RITE = rite TRAIT = trait:kinslayer_3 GENDER_CHARACTER = scope:secondary_recipient }
					}
				}
			}
		}

		modifier = { # They are of the same dynasty as the Head of Faith
			add = -50
			desc = THEY_ARE_MY_DYNASTY_MEMBER
			scope:recipient = {
				is_lowborn = no
				dynasty = scope:secondary_recipient.dynasty
				NOR = {
					house = scope:secondary_recipient.house
					is_close_or_extended_family_of = scope:actor
					is_cousin_of = scope:actor
					is_child_of = scope:actor
					scope:recipient.dynasty = scope:actor.dynasty
				}
			}
		}

		modifier = { # You are of the same dynasty as the Head of Faith
			add = 10
			desc = YOU_ARE_MY_DYNASTY_MEMBER
			scope:recipient = {
				is_lowborn = no
				dynasty = scope:actor.dynasty
				NOR = {
					is_close_or_extended_family_of = scope:actor
					is_cousin_of = scope:actor
					is_child_of = scope:actor
					scope:recipient.dynasty = scope:secondary_recipient.dynasty
				}
			}
		}

		modifier = { # They are of the same house as the Head of Faith
			add = -50
			desc = THEY_ARE_MY_HOUSE_MEMBER
			scope:recipient = {
				is_lowborn = no
				house = scope:secondary_recipient.house
				NOR = {
					house = scope:actor.house
					is_close_or_extended_family_of = scope:actor
					is_cousin_of = scope:actor
					is_child_of = scope:actor
					scope:recipient.house = scope:actor.house
				}
			}
		}

		modifier = { # You are of the same house as the Head of Faith
			add = 10
			desc = YOU_ARE_MY_HOUSE_MEMBER
			scope:recipient = {
				is_lowborn = no
				house = scope:actor.house
				NOR = {
					is_close_or_extended_family_of = scope:actor
					is_cousin_of = scope:actor
					is_child_of = scope:actor
					scope:recipient.house = scope:secondary_recipient.house
				}
			}
		}

		modifier = { # Related to the Head of Faith
			add = 25
			desc = YOU_ARE_MY_RELATIVE
			scope:recipient = {
				OR = {
					is_close_or_extended_family_of = scope:actor
					is_cousin_of = scope:actor
				}
				NOT = { is_child_of = scope:actor }
			}
		}

		modifier = { # Parent of the Head of Faith
			add = 50
			desc = YOU_ARE_MY_PARENT
			scope:recipient = {
				is_child_of = scope:actor
			}
		}

		modifier = { # Friend of the Head of Faith
			add = 15
			desc = WE_ARE_FRIENDS
			scope:recipient = {
				has_relation_friend = scope:actor
			}
		}

		modifier = { # Best Friend of the Head of Faith
			add = 20
			desc = WE_ARE_BEST_FRIENDS
			scope:recipient = {
				has_relation_best_friend = scope:actor
			}
		}

		modifier = { # Lover of the Head of Faith
			add = 10
			desc = WE_ARE_LOVERS
			scope:recipient = {
				has_relation_lover = scope:actor
			}
		}

		modifier = { # Rival of the Head of Faith
			add = -100
			desc = WE_ARE_RIVALS
			scope:recipient = {
				has_relation_rival = scope:actor
			}
		}

		modifier = { # Nemesis of the Head of Faith
			add = -500
			desc = WE_ARE_NEMESES
			scope:recipient = {
				has_relation_nemesis = scope:actor
			}
		}

		modifier = {
			add = {
				add = 5
				multiply = scope:actor.num_virtuous_traits
			}
			scope:actor.num_virtuous_traits > 0
			desc = I_AM_VIRTUOUS
		}

		modifier = {
			add = {
				add = -10
				multiply = scope:secondary_recipient.num_virtuous_traits
			}
			scope:secondary_recipient.num_virtuous_traits > 0
			desc = THEY_ARE_VIRTUOUS
		}

		modifier = {
			add = {
				add = -20
				multiply = scope:actor.num_sinful_traits
			}
			scope:actor.num_sinful_traits > 0
			desc = I_AM_SINFUL
		}

		modifier = {
			add = {
				add = 10
				multiply = scope:secondary_recipient.num_sinful_traits
			}
			scope:secondary_recipient.num_sinful_traits > 0
			desc = THEY_ARE_SINFUL
		}
		modifier = {
			desc = RELIGIOUS_HEAD_INTERACTION_SAVIOR
			add = 15
			scope:actor = {
				has_trait = savior
			}
		}
		modifier = {
			desc = RELIGIOUS_HEAD_INTERACTION_DIVINE_BLOOD
			add = 5
			scope:actor = {
				has_trait = divine_blood
			}
		}
		modifier = {
			desc = RELIGIOUS_HEAD_INTERACTION_PARAGON
			add = 15
			scope:actor = {
				has_trait = paragon
			}
		}
		modifier = {
			desc = RELIGIOUS_HEAD_INTERACTION_CONSECRATED_BLOOD
			add = 5
			scope:actor = {
				has_trait = consecrated_blood
			}
		}
		modifier = {
			add = 25
			scope:influence_send_option = yes
			desc = INFLUENCE_INTERACTION_ACCEPTANCE_SEND_OPTION
		}
	}

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

	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
			custom_tooltip = {
				text = not_same_realm_tt
				scope:recipient.top_liege = scope:actor.top_liege
			}
		}
		flag = influence_send_option
		localization = TRADE_INFLUENCE_FOR_BETTER_AI_ACCEPTANCE
	}
	send_option = {
		is_shown = {
			scope:actor != scope:recipient
		}
		is_valid = {
			scope:actor = {
				has_usable_hook = scope:recipient
			}
		}
		flag = claim_hook
		localization = GENERIC_SPEND_A_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

	ai_min_reply_days = 1
	ai_max_reply_days = 5

	can_send = {
		# Anti-spam AI blockers
		ai_religious_request_blocker_trigger = { INTERACTION = hof_ask_for_claim_interaction }
	}

	on_send = {
		# Anti-spam AI blockers
		ai_religious_request_blocker_effect = { INTERACTION = hof_ask_for_claim_interaction }
	}

	on_accept = {
		hof_ask_for_claim_interaction_effect = yes
		hof_request_accept_consequences_effect = {
			HOF = scope:recipient
		}
		scope:secondary_recipient = {
			trigger_event = religious_interaction.5
		}
		scope:actor = {
			trigger_event = religious_interaction.4
		}

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

	on_decline = {
		hof_request_refuse_consequences_effect = {
			HOF = scope:recipient
			REQUESTER = scope:actor
		}
		scope:actor = {
			trigger_event = religious_interaction.42
		}
	}
}

#This interaction is referenced in code! If it's renamed you have to ping a coder
hof_redirect_great_holy_war_interaction = {
	hidden = yes

	target_type = title
	target_filter = secondary_recipient_de_jure_titles
	redirect = {
		scope:recipient = {
			save_scope_as = secondary_recipient
		}
		scope:actor.faith.religious_head = {
			save_scope_as = recipient
		}
	}

	auto_accept = yes

	is_shown = {
		#exists = scope:actor.faith.religious_head #Called by Autonomous Faiths too.
		exists = scope:actor.faith.great_holy_war
		scope:actor.rite ?= { is_hostile_enough_for_holy_war_trigger = { RITE = scope:secondary_recipient.rite } }
		scope:secondary_recipient ?= { top_liege = this }
		NOT = { exists = scope:actor.faith.great_holy_war.ghw_war }
		scope:target != scope:actor.faith.great_holy_war.ghw_target_title #Do not show the title already targeted in the list.
	}

	can_be_picked_title = {
		scope:target.tier = tier_kingdom
		scope:target != scope:actor.faith.great_holy_war.ghw_target_title #Do not show the title already targeted in the list.
	}

	is_valid_showing_failures_only = {
		scope:actor = { piety >= faith.great_holy_war.var:redirect_cost }
		scope:actor.faith.great_holy_war = { days_until_ghw_launch >= 100 } #No last minute changes.
	}

	has_valid_target_showing_failures_only = {
		exists = scope:target
		scope:target.tier = tier_kingdom
		scope:target != scope:actor.faith.great_holy_war.ghw_target_title #Do not show the title already targeted in the list.
	}

	cost = {
		piety = scope:actor.faith.great_holy_war.var:redirect_cost
	}

	on_accept = {
		scope:actor.faith.great_holy_war = {
			#Toast for attackers
			every_pledged_attacker = {
				limit = {
					is_ai = no
				}
				send_interface_toast = {
					type = event_toast_effect_good
					title = hof_redirected_ghw.0001.desc
					left_icon = scope:actor
					right_icon = scope:secondary_recipient
				}
			}
			#Event for former defenders.
			every_pledged_defender = {
				limit = {
					is_ai = no
				}
				add_to_temporary_list = former_defenders
			}
		}
		scope:actor = {
			faith.great_holy_war = {
				save_scope_as = the_ghw
				set_great_holy_war_target = { target_character = scope:secondary_recipient target_title = scope:target }
				#Old defenders that are no longer in the area are notified.
				every_in_list = {
					list = former_defenders
					limit = {
						is_ai = no
						NOT = {
							scope:actor.faith.great_holy_war = { has_pledged_defender = prev }
						}
					}
					trigger_event = great_holy_war.0081
				}
				#New defenders are notified.
				every_pledged_defender = {
					limit = {
						is_ai = no
					}
					trigger_event = { id = great_holy_war.0082 }
				}
				change_variable = {
					name = redirect_cost
					multiply = 2
				}
				set_variable = {
					name = last_redirector
					value = scope:actor
				}
			}
			hidden_effect = {
				scope:actor.faith = { save_scope_as = the_faith }
				scope:target = { save_scope_as = target_kingdom }
				scope:secondary_recipient = {
					save_scope_as = target_character
					faith = { save_scope_as = target_faith }
				}
				every_ruler = { #Defenders Pledge to the Crusade again. (AI only)
					limit = {
						faith = scope:target_character.faith
						is_ai = yes
						is_playable_character = yes
						highest_held_title_tier >= tier_county
						NOT = {
							scope:actor.faith.great_holy_war = { has_pledged_defender = prev }
						}
					}
					trigger_event = { id = great_holy_war.0021 days = { 25 150 } } #AI counterpledging. Unlike attackers, defenders should be selected much faster during the preparation phase and then stop.
				}
				scope:target_character = {
					faith = {
						every_faith_holy_order = {
							trigger_event = { id = great_holy_war.0091 days = { 25 60 } } #Military Order counterpledging
						}
					}
				}
				scope:actor.faith.great_holy_war = { #Recalculate Recipient.
					faith = { save_scope_as = the_faith }
					ghw_target_title = { save_scope_as = target_kingdom }
					if = { #If Pope died in the meantime.
						limit = {
							OR = {
								NOT = {
									exists = scope:the_faith.great_holy_war.ghw_war_declarer
								}
								NOT = {
									scope:the_faith.great_holy_war.ghw_war_declarer = { is_alive = yes }
								}
							}
						}
						scope:the_faith = { ghw_set_new_war_declarer_effect = yes }
					}
					scope:the_faith.great_holy_war.ghw_war_declarer = { save_scope_as = ghw_sponsor }
					#Check and set sponsor if needed.
					undirected_ghw_recipient_selection_effect = yes
				}
			}
		}
	}

	ai_will_do = {
		base = 0
	}
}

select_ghw_beneficiary_interaction = {
	category = interaction_category_religion
	icon = religious


	populate_recipient_list = {
		scope:recipient = {
			#Any member of your own house. Lowborn clerics have none, hence the safe scope switches below.
			house ?= {
				every_house_member = {
					limit = {
						# Cannot select them self as beneficiary
						this != scope:recipient
					}
					add_to_list = characters
				}
			}
			#Any nearby family member who is of your dynasty, even if they're a separate house.
			every_close_or_extended_family_member = {
				limit = {
					dynasty ?= scope:recipient.dynasty
					NOT = { house ?= scope:recipient.house }
				}
				add_to_list = characters
			}
			#And then any landless heads of minor houses in your dynasty.
			dynasty ?= {
				every_dynasty_member = {
					limit = {
						this = this.house.house_head
						NOR = {
							this.house = scope:recipient.house
							any_close_or_extended_family_member = { this = scope:recipient }
						}
						is_ruler = no
					}
					add_to_list = characters
				}
			}
			#Whoever called the war has no dynastic stake in its spoils, so their own court supplies the candidates.
			if = {
				limit = { faith.great_holy_war.ghw_war_declarer ?= scope:recipient }
				every_courtier_or_guest = {
					limit = {
						is_adult = yes
						is_ruler = no
					}
					add_to_list = characters
				}
			}
			# If you're a laamp, add you too.
			if = {
				limit = { government_has_flag = government_is_landless_adventurer }
				add_to_list = characters
			}
		}
	}

	auto_accept = yes

	is_shown = {
		exists = scope:puppet_or_actor.faith.great_holy_war
		scope:puppet_or_actor ?= {
			exists = faith.great_holy_war
			this = scope:recipient
			is_pledged_ghw_attacker = yes
		}
		#The AI Caliph has its beneficiary assigned by event, but a player who called the war picks their own.
		trigger_if = {
			limit = { scope:actor = { is_ai = yes } }
			NOT = { scope:recipient.faith.great_holy_war.ghw_war_declarer ?= scope:puppet_or_actor }
		}
	}

	can_be_picked = {
		is_adult = yes
		is_ruler = no
		faith = scope:puppet_or_actor.faith
		custom_tooltip = {
			text = ghw_heir_to_a_title
			NOT = {
				any_heir_title = {} # Not heir to anything
			}
		}
		custom_tooltip = {
			text = ghw_married_to_a_ruler
			OR = { #Either not married, or not married to a ruler.
				is_married = no
				NOT = {
					any_spouse = {
						is_ruler = yes
					}
				}
			}
		}
		custom_tooltip = {
			text = ghw_devoted_to_their_faith
			NOR = { # not dedicated to a religious career
				has_trait = devoted
				has_trait = order_member
			}
		}
	}

	has_valid_target_showing_failures_only = {
		scope:secondary_recipient = {
			NOR = {
				has_trait = excommunicated
				has_trait = incapable
				has_trait = devoted
				has_trait_with_flag = debilitating_illness
				custom_description = {
					text = "ghw_recipient_must_not_be_realm_priest"
					rite = {
						rite_has_doctrine = doctrine_theocracy_temporal
					}
					has_council_position = councillor_court_chaplain
				}
			}
			faith = scope:puppet_or_actor.faith
			is_adult = yes
			trigger_if = {
				limit = {
					NOT = { government_has_flag = government_is_landless_adventurer }
				}
				is_ruler = no
			}
			custom_tooltip = {
				text = ghw_heir_to_a_title
				NOT = {
					any_heir_title = {} # Not heir to anything
				}
			}
			custom_tooltip = {
				text = ghw_married_to_a_ruler
				OR = { #Either not married, or not married to a ruler.
					is_married = no
					NOT = {
						any_spouse = {
							is_ruler = yes
						}
					}
				}
			}
		}
	}

	on_accept = {
		scope:puppet_or_actor = {
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = select_ghw_beneficiary_interaction_notification

				right_icon = scope:secondary_recipient

				set_beneficiary = scope:secondary_recipient
			}
		}
		if = {
			limit = {
				scope:is_puppet_action ?= yes
				scope:actor != scope:recipient
			}
			scope:actor = {
				send_interface_toast = {
					type = event_toast_effect_neutral
					title = select_ghw_beneficiary_interaction_notification_puppeteer
					left_icon = scope:puppet_or_actor
					right_icon = scope:secondary_recipient
				}
			}
		}
	}
	ai_will_do = {
		base = 0 #Assigned directly by event for the AI.
	}
}

sun_trial_interaction = {
	interface_priority = 30
	icon = religious

	category = interaction_category_prison

	is_shown = {
		scope:actor = { rite = { rite_has_parameter = trial_by_sun_active } }
		scope:recipient = {
			is_imprisoned_by = scope:actor
			is_adult = yes
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			has_imprisonment_reason = scope:recipient
		}
	}


	on_accept = {
		scope:actor = {
			save_scope_as = imprisoner

			sun_trial_interaction_piety_effect = yes
		}

		scope:recipient = {
			save_scope_as = prisoner
			show_as_tooltip = {
				#Prisoner has a random outcome (toast sent through prisoner's events)
				random_list = {
					desc = outcome_in_a_few_days
					50 = { #they die without consequences! (must match event religious_interaction.2100)
						sun_trial_death_modifier = yes
						desc = sun_trial_interaction.success.tt
						sun_trial_death_effect = yes
					}
					50 = { #they are freed and super cool! (must match event religious_interaction.2100)
						sun_trial_survival_modifier = yes
						desc = sun_trial_interaction.failure.tt
						sun_trial_survival_effect = yes
					}
				}
			}
			hidden_effect = { #Nudge towards rivalry
				if = {
					limit = {
						NOR = {
							has_relation_rival = scope:actor
							has_relation_potential_rival = scope:actor
						}
					}
					set_relation_potential_rival = scope:actor
				}
			}
			#Event for outcome
			trigger_event = {
				id = religious_interaction.2100
			}
		}

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

	auto_accept = yes
}

#########################
# Literalism tenets
# by Ewan Cowhig Croft
#########################

#Engage in literalist debate.
#by Ewan Cowhig Croft
literalist_debate_interaction = {
	icon = religious
	category = interaction_category_religion
	desc = literalist_debate_interaction_desc

	is_shown = {
		scope:puppet_or_actor != scope:recipient
		scope:puppet_or_actor.rite ?= {
			rite_has_parameter = literalist_debate_enabled
		}
		scope:recipient = {
			is_playable_character = yes
			OR = {
				liege ?= scope:puppet_or_actor	#You may debate direct vassals.
				liege ?= scope:puppet_or_actor.liege	#You may debate vassals with whom you share a liege.
				scope:puppet_or_actor.liege ?= scope:recipient	#You may debate your direct liege.
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:puppet_or_actor = {
			is_available_adult = yes
			NOT = {
				is_at_war_with = scope:recipient
			}
		}
		scope:recipient = {
			faith = scope:puppet_or_actor.faith
			is_available_adult = yes
			NOT = { has_strong_hook = scope:puppet_or_actor }
		}
		custom_description = {
			text = literalist_debate_interaction_has_been_debated
			object = scope:recipient
			scope:recipient = {
				NOT = { has_character_modifier = used_literalist_debate_modifier } #To prevent back and forth & back-to-back challenges
				NOT = { has_character_modifier = literally_debated_modifier }
			}
		}
		custom_description = {
			text = literalist_debate_timing
			scope:puppet_or_actor = {
				NOT = { has_character_modifier = used_literalist_debate_modifier }
			}
		}
	}

	auto_accept = yes

	on_accept = {
		hidden_effect = {
			scope:puppet_or_actor = {
				add_character_modifier = {
					modifier = used_literalist_debate_modifier
					years = 2
				}
			}
			scope:recipient = {
				trigger_event = { id = religious_interaction.2400 }
				add_character_modifier = {
					modifier = literally_debated_modifier
					years = 10
				}
			}
		}
		if = {
			limit = { scope:actor = scope:puppet_or_actor }
			custom_tooltip = literalist_debate_interaction.tt_modifiers
		}
		else = {
			custom_tooltip = literalist_debate_interaction.tt_modifiers_puppeteer
		}
		scope:puppet_or_actor = {
			stress_and_fulfillment_impact = {
				cynical = minor_stress_impact_gain
			}
			if = {
				limit = { scope:actor = scope:puppet_or_actor }
				custom_tooltip = literalist_debate_interaction.tt_winnings_actor
			}
			else = {
				custom_tooltip = literalist_debate_interaction.tt_winnings_actor_puppeteer
			}
		}
		scope:recipient = {
			if = {
				limit = { scope:actor = scope:puppet_or_actor }
				custom_tooltip = literalist_debate_interaction.tt_winnings_recipient
			}
			else = {
				custom_tooltip = literalist_debate_interaction.tt_winnings_recipient_puppeteer
			}
		}

		# 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_literalist_debate.desc
			REVERSE_NON_HOUSE_TARGET = no
		}
	}
}

attempt_conversion_of_local_ruler_interaction = {
	category = interaction_category_laamp
	icon = religious

	ai_maybe = yes
	ai_min_reply_days = 1
	ai_max_reply_days = 3
	popup_on_receive = yes
	common_interaction = yes

	desc = attempt_conversion_of_local_ruler_interaction_desc

	is_shown = {
		scope:puppet_or_actor ?= {
			OR = {
				has_personal_tenet_flag = tenet_mendicant_preachers_local_conversion
				AND = {
					has_perk = prophet_perk
					has_government = landless_adventurer_government
				}
			}
		}
		scope:recipient = {
			is_ai = yes
			is_ruler = yes
			is_landed = yes
		}
		scope:puppet_or_actor ?= {
			NOT = { faith = scope:recipient.faith }
		}
	}

	is_highlighted = {
		scope:puppet_or_actor = {
			is_character_interaction_potentially_accepted = {
				recipient = scope:recipient
				interaction = attempt_conversion_of_local_ruler_interaction
			}
		}
	}

	cooldown_against_recipient = { years = 15 }

	can_send = {
		trigger_if = {
			limit = {
				scope:puppet_or_actor ?= { has_government = landless_adventurer_government }
			}
			custom_tooltip = {
				text = must_be_in_domain_tt
				scope:recipient = {
					OR = {
						capital_province ?= scope:puppet_or_actor.domicile.domicile_location
						any_held_title = {
							title_tier = county
							any_county_province = {
								this = scope:puppet_or_actor.domicile.domicile_location
							}
						}
					}
				}
			}
		}
		trigger_else = {
			custom_tooltip = {
				text = must_be_in_same_county_tt
				scope:puppet_or_actor.location.county.holder ?= scope:recipient
			}
		}
	}

	# Use Stress
	send_option = {
		flag = piety
		localization = USE_PIETY
	}
	send_option = {
		flag = stress
		localization = USE_STRESS
	}
	send_option = {
		is_valid = {
			scope:puppet_or_actor.intrigue >= scope:recipient.intrigue
		}
		flag = lie
		localization = USE_INTRIGUE
	}
	send_option = {
		is_valid = {
			scope:puppet_or_actor.domicile ?= {
				provisions >= {
					value = 300
					multiply = scope:recipient.highest_held_title_tier
				}
			}
			NOR = {
				scope:recipient = { has_trait = arbitrary }
				scope:recipient = { has_trait = sadistic }
				scope:recipient = { has_trait = callous }
			}
		}
		flag = provisions
		localization = USE_PROVISIONS
	}
	send_option = {
		is_valid = {
			scope:puppet_or_actor = {
				gold >= scope:recipient.medium_gold_value
			}
			NOR = {
				scope:recipient = { has_trait = generous }
				scope:recipient = { has_trait = humble }
			}
		}
		flag = gold
		localization = USE_GOLD
	}
	send_option = {
		is_valid = {
			scope:puppet_or_actor = {
				has_usable_hook = scope:recipient
			}
			NOT = {
				scope:recipient = { is_imprisoned_by = scope:puppet_or_actor }
			}
		}
		flag = hook
		localization = SCHEME_HOOK
	}
	send_options_exclusive = no
	should_use_extra_icon = {
		scope:puppet_or_actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	is_valid_showing_failures_only = {
		trigger_if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				piety >= attempt_conversion_of_local_ruler_piety_cost_value
			}
		}
		scope:recipient = {
			is_available = yes
		}
		valid_demand_conversion_conditions_trigger = yes
	}

	on_send = {
	}

	cost = {
		piety = {
			value = attempt_conversion_of_local_ruler_piety_cost_value
			if = {
				limit = { scope:is_puppet_action ?= yes }
				multiply = 0
			}
		}
	}

	on_accept = {
		if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				add_piety = {
					value = {
						value = attempt_conversion_of_local_ruler_piety_cost_value
						max = piety
						multiply = -1
					}
				}
			}
		}
		scope:puppet_or_actor = {
			trigger_event = religious_interaction.2002
			show_as_tooltip = {
				if = {
					limit = {
						has_government = landless_adventurer_government
						scope:recipient.highest_held_title_tier >= tier_barony
					}
					faith = {
						change_fervor = {
							value = {
								add = trivial_fervor_value
								multiply = scope:recipient.highest_held_title_tier
							}
							desc = imperial_capital_sacked_fervor_gain
						}
					}
					add_prestige = {
						value = 200
						multiply = scope:recipient.highest_held_title_tier
						if = {
							limit = {
								scope:recipient.highest_held_title_tier >= tier_kingdom
							}
							multiply = 2
						}
					}
				}
			}
			if = {
				limit = {
					scope:stress = yes
				}
				add_stress = medium_stress_impact_gain
			}
			if = {
				limit = {
					scope:lie = yes
				}
				stress_and_fulfillment_impact = {
					honest = medium_stress_impact_gain
					forgiving = medium_stress_impact_gain
					compassionate = minor_stress_impact_gain
					just = minor_stress_impact_gain
				}
			}
			if = {
				limit = {
					scope:gold = yes
				}
				pay_short_term_gold = {
					target = scope:recipient
					gold = scope:recipient.medium_gold_value
				}
			}
			if = {
				limit = {
					scope:provisions = yes
				}
				domicile ?= {
					change_provisions = {
						value = 300
						multiply = scope:recipient.highest_held_title_tier
						multiply = -1
					}
				}
			}
		}
		demand_conversion_interaction_effect = yes
		scope:recipient = {
			if = {
				limit = {
					scope:lie = yes
				}
				stress_and_fulfillment_impact = {
					base = minor_stress_impact_gain
					paranoid = medium_stress_impact_gain
					trusting = medium_stress_impact_gain
				}
			}
			custom_tooltip = {
				text = will_not_convert_away_tt
				add_character_flag = ai_will_not_convert
			}
			add_opinion = {
				modifier = showed_me_the_light_opinion
				target = scope:puppet_or_actor
				opinion = 40
			}
			if = {
				limit = {
					top_liege != this
					liege ?= {
						faith != scope:puppet_or_actor.faith
					}
				}
				liege = {
					add_opinion = {
						modifier = annoyed_opinion
						target = scope:puppet_or_actor
						opinion = -20
					}
				}
			}
		}

#		scope:puppet_or_actor = {
#			if = {
#				limit = {
#					any_character_struggle = {
#						involvement = involved
#						has_struggle_phase_parameter = piety_from_converting_involved_rulers
#						is_secondary_character_involvement_involved_trigger = {
#							CHAR = scope:recipient
#						}
#					}
#				}
#				add_piety = medium_piety_gain
#			}
#		}

		conversion_tenet_acts_of_the_apostles_effect = yes

		# If you have the Mendicant Preaching personal tenet we give you SP
		conversion_tenet_mendicant_preachers_effect = yes
	}

	on_decline = {
		scope:puppet_or_actor = {
			trigger_event = {
				id = religious_interaction.2003
			}
			if = {
				limit = {
					scope:stress = yes
				}
				add_stress = medium_stress_impact_gain
			}
			if = {
				limit = {
					scope:lie = yes
				}
				stress_and_fulfillment_impact = {
					honest = medium_stress_impact_gain
					forgiving = medium_stress_impact_gain
					compassionate = minor_stress_impact_gain
					just = minor_stress_impact_gain
				}
			}
			if = {
				limit = {
					scope:gold = yes
				}
				pay_short_term_gold = {
					target = scope:recipient
					gold = scope:recipient.medium_gold_value
				}
			}
			if = {
				limit = {
					scope:provisions = yes
				}
				domicile ?= {
					change_provisions = {
						value = 300
						multiply = scope:recipient.highest_held_title_tier
						multiply = -1
					}
				}
			}
		}
		scope:recipient = {
			if = {
				limit = {
					scope:lie = yes
				}
				stress_and_fulfillment_impact = {
					base = minor_stress_impact_gain
					paranoid = medium_stress_impact_gain
					trusting = medium_stress_impact_gain
				}
			}
			show_as_tooltip = {
				#Negative opinions
				add_opinion = {
					modifier = unwanted_religious_conversion_opinion
					target = scope:puppet_or_actor
				}
				if = {
					limit = {
						top_liege != this
						liege ?= {
							faith != scope:puppet_or_actor.faith
						}
					}
					liege = {
						add_opinion = {
							modifier = religious_rebel_opinion
							target = scope:puppet_or_actor
						}
					}
				}
			}
		}
	}

	ai_accept = {
		base = 0

		celestial_hierarchy_acceptance_modifier = {
			ACTOR = scope:puppet_or_actor
			RECIPIENT = scope:recipient
		}

		modifier = {
			desc = SCHEME_WEAK_HOOK_USED
			add = 20
			scope:hook = yes
		}
		modifier = {
			desc = ASK_FOR_CONVERSION_RECIPIENT_INTRIGUE
			scope:lie = yes
			add = {
				value = scope:puppet_or_actor.intrigue
				subtract = scope:recipient.intrigue
				min = 1
			}
		}
		modifier = {
			add = 20
			scope:piety = yes
			desc = USING_PIETY
		}
		modifier = {
			add = 20
			scope:stress = yes
			desc = USING_STRESS
		}
		modifier = {
			add = 20
			scope:gold = yes
			desc = USING_GOLD
		}
		modifier = {
			add = 20
			scope:provisions = yes
			desc = USING_PROVISIONS
		}
 		modifier = {
			scope:recipient = {
				has_trait = trusting
			}
 			add = 20
 			desc = DEMAND_SUBMISSION_RECIPIENT_IS_TRUSTING
 		}
 		modifier = {
			scope:recipient = {
				has_relation_lover = scope:puppet_or_actor
			}
 			add = 25
 			desc = AI_YOUR_LOVER
 		}
 		modifier = {
			scope:recipient = {
				has_relation_friend = scope:puppet_or_actor
			}
 			add = 25
 			desc = AI_YOUR_FRIEND
 		}
 		modifier = {
			scope:recipient = {
				is_child_of = scope:puppet_or_actor
			}
 			add = 50
 			desc = AI_YOUR_CHILD
 		}
		modifier = {
			add = {
				value = scope:puppet_or_actor.piety_level
				multiply = 10
			}
			scope:puppet_or_actor = {
				piety_level > 1
			}
			desc = ASK_FOR_CONVERSION_ACTOR_IS_PIOUS
		}
		modifier = {
			add = {
				value = scope:recipient.highest_held_title_tier
				subtract = 2
				multiply = -25
				if = {
					limit = {
						scope:recipient.highest_held_title_tier >= tier_duchy
					}
					multiply = 2
				}
			}
			scope:recipient.highest_held_title_tier >= tier_duchy
			desc = ASK_FOR_CONVERSION_RECIPIENT_TIER
		}
		modifier = {
			add = -25
			scope:recipient = {
				top_liege != this
				faith = liege.faith
				rite = {
					rite_hostility_level = {
						target = scope:puppet_or_actor.rite
						value >= faith_hostile_level
					}
				}
			}
			desc = ASK_FOR_CONVERSION_RECIPIENT_CRIME
		}
		modifier = {
			add = -50
			scope:recipient = {
				rite = {
					rite_hostility_level = {
						target = scope:puppet_or_actor.rite
						value >= faith_astray_level
					}
					rite_hostility_level = {
						target = scope:puppet_or_actor.rite
						value < faith_hostile_level
					}
				}
			}
			desc = ASK_FOR_CONVERSION_RECIPIENT_ASTRAY
		}
		modifier = {
			add = -75
			scope:recipient = {
				rite = {
					rite_hostility_level = {
						target = scope:puppet_or_actor.rite
						value >= faith_hostile_level
					}
					rite_hostility_level = {
						target = scope:puppet_or_actor.rite
						value < faith_evil_level
					}
				}
			}
			desc = ASK_FOR_CONVERSION_RECIPIENT_HOSTILE
		}
		modifier = {
			add = -100
			scope:recipient = {
				rite = {
					rite_hostility_level = {
						target = scope:puppet_or_actor.rite
						value >= faith_evil_level
					}
				}
			}
			desc = ASK_FOR_CONVERSION_RECIPIENT_EVIL
		}
		religion_demand_conversion_default_modifier = yes
	}
}

#########################
# Exaltation of Pain tenet
#########################

revel_in_pain_interaction = {
	icon = religious
	category = interaction_category_religion
	desc = revel_in_pain_interaction_desc

	use_diplomatic_range = yes

	greeting = positive
	notification_text = REVEL_IN_PAIN_INTERACTION_NOTIFICATION

	is_available = {
		has_personal_tenet_flag = self_mutilation_active
		trigger_if = {
			limit = { is_ai = yes }
			OR = {
				has_trait = zealous
				has_trait = sadistic
			}
			NOR = {
				has_trait = craven
				has_trait = wounded_1
				has_trait = wounded_2
			}
			is_at_war = no
		}
	}

	is_shown = {
		NOT = { scope:actor = scope:recipient }
		scope:actor = {
			OR = {
				has_relation_friend = scope:recipient
				has_relation_lover = scope:recipient
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			is_adult = yes
			is_available = yes
			custom_tooltip = {
				text = actor_is_severely_injured_tt
				NOT = { has_trait = wounded_2 }
			}
		}
		scope:recipient = {
			custom_tooltip = {
				text = recipient_involved_in_revel_in_pain_recently_tt
				NOT = { has_character_flag = involved_in_revel_in_pain_recently }
			}
			is_adult = yes
			NOT = { has_trait = craven }
			has_personal_tenet_flag = self_mutilation_active
			NOT = { is_at_war_with = scope:actor }
			custom_tooltip = {
				text = recipient_is_severely_injured_tt
				NOT = { has_trait = wounded_2 }
			}
			custom_tooltip = {
				text = recipient_not_in_the_same_location_tt
				location = scope:actor.location
			}
			is_available = yes
		}
	}

	auto_accept = {
		scope:recipient = { is_ai = yes }
	}

	on_accept = {
		scope:actor = {
			trigger_event = religious_interaction.2600
			show_as_tooltip = { revel_in_pain_effect = yes }
		}
		scope:recipient = {
			if = {
				limit = { is_ai = no }
				trigger_event = religious_interaction.2600
				show_as_tooltip = {
					revel_in_pain_effect = yes
					revel_in_pain_opinion_effect = yes
				}
			}
			else = {
				revel_in_pain_effect = yes
				revel_in_pain_opinion_effect = yes
			}
		}
	}

	on_decline = {
		scope:actor = {
			trigger_event = religious_interaction.2610
		}
	}

	ai_targets = {
		ai_recipients = family
		ai_recipients = scripted_relations
		ai_recipients = vassals
		ai_recipients = courtiers
		max = 5
	}

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

	ai_will_do = {
		base = 0
		modifier = {
			add = ai_boldness
		}
		modifier = {
			has_trait = flagellant
			add = 25
		}
	}
}

exaltation_of_pain_wound_courtier_interaction = {
	icon = wound
	category = interaction_category_religion
	desc = exaltation_of_pain_wound_courtier_interaction_desc

	cooldown = { years = 3 }

	greeting = negative
	notification_text = EXALTATION_OF_PAIN_WOUND_COURTIER_NOTIFICATION

	is_available = {
		has_personal_tenet_flag = tenet_exaltation_of_pain_wound_courtier_interaction
		trigger_if = {
			limit = { is_ai = yes }
			OR = {
				has_trait = zealous
				has_trait = sadistic
				has_trait = flagellant
			}
			is_at_war = no
		}
	}

	is_shown = {
		NOT = { scope:actor = scope:recipient }
		scope:recipient = {
			is_courtier_of = scope:actor
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			is_adult = yes
			is_available = yes
		}
		scope:recipient = {
			is_ruler = no
			is_available = yes
			custom_tooltip = {
				text = exaltation_of_pain_recipient_too_unwell_tt
				NOR = {
					has_trait = incapable
					health <= 2.5
					has_trait_rank = {
						trait = wounded
						rank >= 2
					}
				}
			}
		}
	}

	auto_accept = yes

	on_accept = {
		scope:actor = {
			if = {
				limit = { is_ai = no }
				show_as_tooltip = {
					exaltation_of_pain_wound_courtier_effect = {
						ACTOR = scope:actor
						TARGET = scope:recipient
					}
				}
				trigger_event = religious_interaction.2620
			}
			else = {
				if = {
					limit = { scope:recipient = { is_ai = no } }
					scope:recipient = {
						trigger_event = religious_interaction.2620
					}
				}
				else = {
					exaltation_of_pain_wound_courtier_effect = {
						ACTOR = scope:actor
						TARGET = scope:recipient
					}
				}
			}
		}
	}

	ai_targets = {
		ai_recipients = courtiers
	}

	ai_target_quick_trigger = {
		adult = yes
	}

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

	ai_will_do = {
		base = -100
		# Let players choose any valid courtier; keep the AI away from characters whose loss harms the realm.
		modifier = {
			factor = 0
			scope:recipient = {
				is_close_or_extended_family_of = scope:actor
			}
		}
		modifier = {
			factor = 0
			scope:recipient = {
				is_heir_of = scope:actor
			}
		}
		modifier = {
			factor = 0
			scope:recipient = {
				is_councillor_of = scope:actor
			}
		}
		modifier = {
			factor = 0
			scope:recipient = {
				is_knight_of = scope:actor
			}
		}
		modifier = {
			factor = 0
			scope:recipient = {
				has_any_court_position = yes
			}
		}
		ai_value_modifier = {
			ai_compassion = tiny_chance_impact_negative_ai_value
		}
		opinion_modifier = {
			opinion_target = scope:recipient
			multiplier = -0.5
		}
		modifier = {
			add = ai_zeal
			has_trait = zealous
		}
		modifier = {
			add = 25
			OR = {
				has_trait = flagellant
				has_trait = sadistic
			}
		}
	}
}

debug_force_next_realm_priest_interaction = {
	icon = religious
	category = interaction_debug_pam
	common_interaction = yes

	auto_accept = yes

	populate_recipient_list = {
		scope:actor = {
			every_courtier = {
				limit = {
					faith = scope:recipient.faith
				}

				add_to_list = characters
			}
		}
	}

	is_shown = {
		debug_only = yes
		scope:puppet_or_actor ?= {
			OR = {
				religion = religion:protestant_religion
				religion = religion:catholic_religion
				religion = religion:eastern_orthodox_religion
				religion = religion:oriental_orthodox_religion
			}
		}
	}

	on_accept = {
		scope:recipient = {
			council_task:councillor_court_chaplain = {
				force_next_councillor = scope:secondary_recipient
			}
		}
	}
}

#Ask to take the vows to join an actual monastic order
#By Friar Jason Cantalini
take_monastic_vows_interaction = {
	category = interaction_category_vassal
	icon = religious
	filter_tags = { holy_order }

	ai_maybe = yes
	ai_min_reply_days = 4
	ai_max_reply_days = 9
	#Commented out on other version, so commented out here
	#can_send_despite_rejection = yes
	popup_on_receive = yes
	pause_on_receive = yes
	common_interaction = yes

	populate_recipient_list = {
		scope:puppet_or_actor.faith = {
			every_faith_holy_order = {
				limit = {
					take_the_vows_valid_monastic_order_trigger = { CHARACTER = scope:puppet_or_actor }
				}
				leader = {
					add_to_list = characters
				}
			}
		}
	}

	cooldown_against_recipient = { years = 10 }

	desc = take_monastic_vows_interaction_desc

	on_decline_summary = {
		triggered_desc = {
			trigger = { NOT = { scope:actor = scope:puppet_or_actor } }
			desc = take_vows_decline_summary_puppeteer
		}
		triggered_desc = {
			trigger = { scope:actor = scope:puppet_or_actor }
			desc = take_vows_decline_summary
		}
	}

	greeting = negative
	notification_text = REQUEST_MONASTIC_VOWS_NOTIFICATION_TEXT
	prompt = TAKE_THE_VOWS_SELECT_HOLY_ORDER_LEADER


	is_available = {
		trigger_if = {
			limit = { is_ai = yes }
			piety >= major_piety_value
			is_adult = yes
		}
	}

	is_shown = {
		#have a monastic order to send char to
		 scope:puppet_or_actor ?= {
            faith ?= {
                any_faith_holy_order = {
                    take_the_vows_valid_monastic_order_trigger = { CHARACTER = scope:puppet_or_actor }
                }
            }
			#Not your bishop
			NOT = {	any_learning_councillor = { this = scope:recipient } }
			take_vows_available_trigger = yes
        }
		scope:recipient = {
			is_courtier_of = scope:puppet_or_actor
			NOR = {
				has_trait = devoted
				has_trait = order_member
			}
		}
		trigger_if = {
			limit = {
				scope:actor = {
					is_ai = yes
				}
			}
			scope:recipient = {
				is_close_or_extended_family_of = scope:puppet_or_actor
				NOR = {
					exists = betrothed
					is_married = yes
					is_primary_heir_of = scope:puppet_or_actor
				}
			}
		}
	}

	is_valid_showing_failures_only = {
		trigger_if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				piety >= scope:recipient.ask_to_take_vows_piety_cost
			}
		}
		trigger_if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				dynasty ?= { dynasty_prestige >= take_vows_dynasty_prestige_cost_value }
			}
		}
		scope:recipient = {
			age >= 10
			is_courtier_of = scope:puppet_or_actor
			can_take_religious_vows_trigger = yes #Triggers that applies to both Monastery or Military Order requirements
		}
		custom_tooltip = {
			text = cannot_take_overt_hostile_actions_against_diarch.tt
			NOT = { scope:recipient ?= scope:puppet_or_actor.diarch }
		}
		scope:puppet_or_actor = {
			NOT = {
				has_character_modifier = promised_pilgrimage_to_clergy_modifier
			}
		}
		trigger_if = {
			limit = {
				scope:secondary_recipient ?= {
					has_realm_law = female_monastic_holy_order_succession_law
				}
			}
			custom_tooltip = {
				text = female_monastic_order_not_female_tt
				scope:recipient = {
    				is_female = yes
    			}
			}
		}
		trigger_if = {
			limit = {
				scope:secondary_recipient ?= {
					has_realm_law = male_monastic_holy_order_succession_law
				}
			}
			custom_tooltip = {
				text = male_monastic_order_not_male_tt
				scope:recipient = {
    				is_male = yes
    			}
			}
		}
	}

	#Use hook
	auto_accept = {
		trigger_if = {
			limit = { scope:simony_paid_vows = yes }
			custom_description = {
				text = PAM_TAKE_VOWS_GOLD_AUTO_ACCEPT
				object = scope:recipient
				always = yes
			}
		}
		trigger_else = {
			custom_description = {
				text = "spending_hook"
				subject = scope:puppet_or_actor
				object = scope:recipient
				scope:hook = yes
				scope:puppet_or_actor = { has_strong_hook = scope:recipient }
			}
		}
	}

	send_option = {
		is_valid = {
			scope:puppet_or_actor = {
				has_usable_hook = scope:recipient
			}
		}
		flag = hook
		localization = SCHEME_HOOK
	}
	#DEMAND that they take the vows
	send_option = {
		is_valid = {
			scope:recipient.liege ?= scope:puppet_or_actor
			scope:puppet_or_actor = {
				#AI can't be trusted with the ramifications of this
				scope:actor = { is_ai = no }
				custom_tooltip = {
					text = parent_or_dynast_tt
					OR = {
						is_parent_of = scope:recipient
						AND = {
							exists = scope:puppet_or_actor.dynasty
							is_dynast = yes
							scope:recipient.dynasty ?= scope:puppet_or_actor.dynasty
						}
					}
				}

			}
		}
		flag = demand
		localization = INTERACTION_DEMAND_VOWS
	}
	send_option = {
		is_shown = {
			scope:actor = {
				is_ai = no
			}
		}
		is_valid = {
			custom_tooltip = {
				text = PAM_TAKE_VOWS_GOLD_OPTION_REQUIRES_SIMONY
				scope:puppet_or_actor = {
					rite = {
						rite_has_parameter = tenet_simony_paid_vows
					}
				}
			}
			scope:puppet_or_actor = {
				gold >= major_gold_value
			}
		}
		flag = simony_paid_vows
		localization = PAM_TAKE_VOWS_GOLD_OPTION
	}
	should_use_extra_icon = {
		scope:puppet_or_actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	send_options_exclusive = no

	cost = {
		piety = {
			value = scope:recipient.ask_to_take_vows_piety_cost
			if = {
				limit = { scope:is_puppet_action ?= yes }
				multiply = 0
			}
		}
		renown = {
			value = take_vows_dynasty_prestige_cost_value
			if = {
				limit = { scope:is_puppet_action ?= yes }
				multiply = 0
			}
		}
		gold = {
			value = 0
			if = {
				limit = { scope:simony_paid_vows = yes }
				add = scope:puppet_or_actor.major_gold_value
			}
		}
	}

	on_send = {
		scope:secondary_recipient = {
			save_scope_as = archabbot
		}
		scope:recipient = {
			set_variable = {
				name = vows_piety_spent
				value = ask_to_take_vows_piety_cost
				days = 10
 			}
 		}
 	}

	on_accept = {
		if = {
			limit = { scope:is_puppet_action ?= yes }
			scope:puppet_or_actor = {
				add_piety = {
					value = {
						add = scope:recipient.ask_to_take_vows_piety_cost
						max = piety
						multiply = -1
					}
				}
				if = {
					limit = { take_vows_dynasty_prestige_cost_value > 0 }
					dynasty ?= {
						add_dynasty_prestige = {
							value = {
								value = take_vows_dynasty_prestige_cost_value
								multiply = -1
							}
						}
					}
				}
			}
		}
		scope:secondary_recipient = {
			save_scope_as = archabbot
		}
		scope:puppet_or_actor = {
			if = {
				limit = { scope:hook = yes }
				use_hook = scope:recipient
			}

			#You demanded compliance as parent or dynasty head... you get it, but at a cost
			if = {
				limit = {
					scope:demand = yes
				}
				scope:puppet_or_actor = {
					show_as_tooltip = {
						take_vows_demand_effect = yes
					}
				}
			}

			show_as_tooltip = {
				send_child_to_monastic_order_effect = yes
			}
			take_vows_faith_opinion_effect = yes
			reverse_add_opinion = {
                target = scope:archabbot
                modifier = pleased_opinion
                opinion = 25
            }
			scope:recipient = {
				if = {
					limit = {
						OR = {
							scope:demand ?= yes
							AND = {
								is_imprisoned_by = scope:puppet_or_actor
								OR = {
									is_heir_of = scope:puppet_or_actor
									any_claim = {
										exists = this
									}
								}
							}
						}
					}
					add_opinion = {
						modifier = forced_taking_vows
						target = scope:puppet_or_actor
					}
				}
				else = {
					add_opinion = {
						modifier = demanded_taking_vows
						target = scope:puppet_or_actor
					}
				}
				kick_from_court_interaction_warning_tooltip_effect = yes
			}
			trigger_event = holy_order.2020
		}

		hidden_effect = {
			scope:recipient = {
				remove_variable = vows_piety_spent
			}
		}

		# If we're a clan this interaction affects unity
		add_clan_unity_interaction_effect = {
			CHARACTER = scope:puppet_or_actor
			TARGET = scope:recipient
			VALUE = minor_unity_gain
			DESC = clan_unity_take_vows.desc
			REVERSE_NON_HOUSE_TARGET = no
		}
		scope:recipient = {
			if = {
				limit = {
					is_adult = no
					has_focus = education_learning
				}
				custom_tooltip = take_vows_improve_education_learning_tt
			}
			if = {
				limit = {
					is_adult = no
					has_focus = education_stewardship
				}
				custom_tooltip = take_vows_improve_education_stewardship_tt
			}
		}
		scope:puppet_or_actor = {
			if = {
				limit = {
					faith = {
						any_faith_holy_order = {
							leader = scope:secondary_recipient
							holy_order_patron = scope:puppet_or_actor
						}
					}
				}
				custom_tooltip = take_vows_patron_boost_monk_xp_tt
			}
		}
	}

	on_decline = {
		scope:puppet_or_actor = {
			#You demanded compliance as parent or dynasty head... you get it, but at a cost
			if = {
				limit = {
					scope:demand = yes
				}
				scope:puppet_or_actor = {
					show_as_tooltip = {
						take_vows_demand_effect = yes
					}
				}
			}
		}
		scope:recipient = {
			add_opinion = {
				target = scope:puppet_or_actor
				modifier = asked_me_to_take_vows_opinion
				years = 10
			}
		}
		#Letter event informing the character about the rejection.
		scope:puppet_or_actor = {
			trigger_event = {
				id = religious_interaction.1031
			}
		}

		# Refund piety cost
		show_as_tooltip = {
			scope:puppet_or_actor = {
				add_piety_no_experience = {
					value = scope:recipient.ask_to_take_vows_piety_cost
				}
			}
		}
		# Refund piety cost
		hidden_effect = {
			if = {
				limit = {
					scope:recipient = {
						has_variable = vows_piety_spent
 					}
 				}
				scope:puppet_or_actor = {
					add_piety_no_experience = {
						value = scope:recipient.var:vows_piety_spent
 					}
				}
				scope:recipient = {
					remove_variable = vows_piety_spent
 				}
 			}
 		}

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

	auto_accept = no

	ai_accept = {
		base = 0 # Try to make it 0 for most interactions

		modifier = {
			scope:hook = yes
			add = 50
			desc = SCHEME_WEAK_HOOK_USED
		}
		modifier = {
			add = 50
			scope:demand = yes
			desc = liege_demands_vow_taking
		}
		opinion_modifier = { # Opinion Factor
			who = scope:recipient
			opinion_target = scope:puppet_or_actor
			multiplier = 0.25
			desc = AI_SIMPLE_OPINION_REASON
		}
		modifier = {
			add = ai_zeal
			ai_zeal < 0
			desc = TAKE_THE_VOWS_SKEPTIC
		}
		modifier = {
			add = {
				value = ai_zeal
				divide = 2
			}
			ai_zeal > 0
			desc = TAKE_THE_VOWS_ZEALOUS
		}
		modifier = {
			add = {
				value = ai_greed
				multiply = -1
			}
			ai_greed > 0
			desc = TAKE_THE_VOWS_GREED
		}
		modifier = {
			add = {
				value = ai_boldness
				multiply = -1
			}
			ai_boldness < 0
			desc = TAKE_THE_VOWS_COWARDLINESS
		}
		modifier = {
			add = {
				value = ai_boldness
				multiply = -0.5
			}
			ai_boldness > 0
			desc = TAKE_THE_VOWS_BOLDNESS
		}
		modifier = {
			add = 20
			dynasty ?= scope:puppet_or_actor.dynasty
			scope:puppet_or_actor.faith = {
				any_faith_holy_order = {
					leader = scope:secondary_recipient
					holy_order_patron = scope:puppet_or_actor
				}
			}
			desc = TAKE_THE_VOWS_MONASTIC_PATRON
		}
		modifier = {
			add = 5
			scope:puppet_or_actor.faith = {
				any_faith_holy_order = {
					leader = scope:secondary_recipient
					any_leased_title = {
						county.holder ?= scope:puppet_or_actor
					}
				}
			}
			desc = TAKE_THE_VOWS_NEAR_ORDER
		}
		modifier = {
			add = -15
			NOT = {
				scope:puppet_or_actor.faith = {
					any_faith_holy_order = {
						leader = scope:secondary_recipient
						any_leased_title = {
							county.holder.top_liege ?= {
								this = scope:puppet_or_actor.top_liege
							}
						}
					}
				}
			}
			desc = TAKE_THE_VOWS_DISTANT_ORDER
		}
		modifier = {
			add = 70
			scope:recipient = {
				age >= 45
				is_visibly_fertile = no
				NOT = {
					any_heir_title = {
						exists = holder
					}
				}
			}
			desc = TAKE_THE_VOWS_RETIRE_IN_CHURCH
		}
		modifier = {
			add = 50
			exists = scope:puppet_or_actor.cp:councillor_court_chaplain
			scope:recipient = {
				OR = {
					has_relation_lover = scope:puppet_or_actor.cp:councillor_court_chaplain
					has_relation_friend = scope:puppet_or_actor.cp:councillor_court_chaplain
					has_secret_relation_lover = scope:puppet_or_actor.cp:councillor_court_chaplain
					has_relation_soulmate = scope:puppet_or_actor.cp:councillor_court_chaplain
					has_relation_best_friend = scope:puppet_or_actor.cp:councillor_court_chaplain
					opinion = {
						target = scope:puppet_or_actor.cp:councillor_court_chaplain
						value >= very_high_positive_opinion
					}
				}
			}
			desc = TAKE_THE_VOWS_INSPIRING_COURT_CHAPLAIN
		}
		modifier = {
			add = 50
			scope:recipient = {
				OR = {
					any_relation = {
						type = friend
						is_clergy = yes
					}
					any_relation = {
						type = best_friend
						is_clergy = yes
					}
					any_relation = {
						type = lover
						is_clergy = yes
					}
					any_relation = {
						type = soulmate
						is_clergy = yes
					}
					any_relation = {
						type = crush
						is_clergy = yes
					}
					any_secret = {
						type = secret_lover
						secret_target = {
							is_clergy = yes
						}
					}
				}
			}
			desc = TAKE_THE_VOWS_INSPIRING_CLERGY
		}
		modifier = {
			add = 50
			scope:recipient = {
				has_education_learning_trigger = yes
			}
			desc = TAKE_THE_VOWS_LEARNING_EDUCATION
		}

		modifier = {
			add = {
				add = 20
				multiply = scope:recipient.num_virtuous_traits
			}
			scope:recipient.num_virtuous_traits > 0
			desc = TAKE_THE_VOWS_VIRTUOUS
		}

		modifier = {
			add = {
				add = -20
				multiply = scope:recipient.num_sinful_traits
			}
			scope:recipient.num_sinful_traits > 0
			desc = TAKE_THE_VOWS_SINFUL
		}

		#Positive Personality Modifiers
		modifier = { # Wants to help people
			add = {
				value = ai_compassion
				divide = 2
			}
			scope:recipient = {
				ai_compassion > 0
				has_trait = lifestyle_physician
			}
			desc = TAKE_THE_VOWS_PHYSICIAN_WANTS_TO_HELP
		}
		modifier = {
			add = 1200
			scope:recipient = {
				has_trait = reclusive
			}
			desc = TAKE_THE_VOWS_RECLUSIVE
		}
		modifier = {
			add = 25
			scope:recipient = {
				has_trait = curious
			}
			desc = TAKE_THE_VOWS_CURIOUS
		}
		modifier = {
			add = 50
			scope:recipient = {
				has_trait = pensive
			}
			desc = TAKE_THE_VOWS_PENSIVE
		}
		modifier = { # Loves books & knowledge!
			add = 20
			scope:recipient = {
				has_trait = lifestyle_mystic
			}
			desc = TAKE_THE_VOWS_MYSTIC
		}
		modifier = { # Loves books & knowledge!
			add = 20
			scope:recipient = {
				has_trait = erudite
			}
			desc = TAKE_THE_VOWS_ERUDITE
		}
		modifier = { # Loves books & knowledge!
			add = 20
			scope:recipient = {
				has_trait = theologian
			}
			desc = TAKE_THE_VOWS_THEOLOGIAN
		}
		modifier = { # Plants!
			add = 20
			scope:recipient = {
				has_trait = lifestyle_herbalist
			}
			desc = TAKE_THE_VOWS_HERBALIST
		}
		modifier = {
			add = 25
			scope:recipient = {
				has_trait = temperate
			}
			desc = TAKE_THE_VOWS_TEMPERATE
		}
		modifier = {
			add = 100
			scope:recipient = {
				has_trait = celibate
			}
			desc = TAKE_THE_VOWS_CELIBATE
		}
		modifier = {
			add = 40
			scope:recipient = {
				has_trait = chaste
			}
			desc = TAKE_THE_VOWS_CHASTE
		}
		modifier = {
			add = 25
			scope:recipient = {
				has_trait = content
			}
			desc = TAKE_THE_VOWS_CONTENT
		}
		modifier = {
			add = 25
			scope:recipient = {
				has_trait = humble
			}
			desc = TAKE_THE_VOWS_HUMBLE
		}
		modifier = {
			add = 10
			scope:recipient = {
				has_trait = drunkard
			}
			desc = TAKE_THE_VOWS_DRUNKARD
		}
		modifier = {
			add = 10
			scope:recipient = {
				has_trait = hashishiyah
			}
			desc = TAKE_THE_VOWS_HASHISHIYAH
		}
		modifier = {
			add = 50
			scope:recipient = {
				has_trait = trusting
			}
			desc = TAKE_THE_VOWS_TRUSTING
		}

		#Negative Personality Modifiers
		modifier = {
			add = -50
			scope:recipient = {
				has_trait = rowdy
			}
			desc = TAKE_THE_VOWS_ROWDY
		}
		modifier = {
			add = -25
			scope:recipient = {
				has_trait = bossy
			}
			desc = TAKE_THE_VOWS_BOSSY
		}
		modifier = {
			add = -20
			scope:recipient = {
				has_trait = gluttonous
			}
			desc = TAKE_THE_VOWS_GLUTTONOUS
		}
		modifier = {
			add = -20
			scope:recipient = {
				has_trait = lustful
			}
			desc = TAKE_THE_VOWS_LUSTFUL
		}
		modifier = {
			add = -500
			scope:recipient = {
				has_trait = pregnant
			}
			desc = TAKE_THE_VOWS_PREGNANT
		}
		modifier = {
			add = -500
			scope:recipient = {
				has_trait = ambitious
			}
			desc = TAKE_THE_VOWS_AMBITIOUS
		}

		modifier = {
			add = -50
			scope:recipient = {
				OR = {
					is_married = yes
					exists = betrothed
				}
			}
			desc = TAKE_THE_VOWS_MARRIED_OR_BETROTHED
		}

		modifier = {
			add = -150
			scope:recipient = {
				is_primary_heir_of = scope:puppet_or_actor
			}
			desc = TAKE_THE_VOWS_PRIMARY_HEIR
		}

		modifier = {
			add = -75
			scope:recipient = {
				NOT = {
					is_primary_heir_of = scope:puppet_or_actor
				}
			}
			scope:puppet_or_actor.primary_title = {
				place_in_line_of_succession = {
					target = prev
					value = 2
				}
			}
			desc = TAKE_THE_VOWS_SECOND_HEIR
		}

		modifier = {
			add = -50
			scope:recipient = {
				NOT = {
					is_primary_heir_of = scope:puppet_or_actor
				}
			}
			scope:puppet_or_actor.primary_title = {
				place_in_line_of_succession = {
					target = prev
					value = 3
				}
			}
			desc = TAKE_THE_VOWS_THIRD_HEIR
		}

		modifier = {
			add = -25
			scope:recipient = {
				NOT = {
					is_primary_heir_of = scope:puppet_or_actor
				}
			}
			scope:puppet_or_actor.primary_title = {
				place_in_line_of_succession = {
					target = prev
					value >= 4
					value <= 10
				}
			}
			desc = TAKE_THE_VOWS_HEIR
		}

		modifier = {
			add = -100
			scope:recipient = {
				NOT = { is_heir_of = scope:puppet_or_actor }
				any_heir_title = {
					exists = holder
					holder != scope:puppet_or_actor
				}
				NOT = {
					is_primary_heir_of = scope:puppet_or_actor
				}
			}
			desc = TAKE_THE_VOWS_HEIR_TO_OTHER_TITLE
		}

		modifier = {
			add = -50
			scope:recipient = {
				NOT = { is_heir_of = scope:puppet_or_actor }
				any_parent = {
					any_held_title = {
						place_in_line_of_succession = {
							target = scope:recipient
							value < 5
						}
						NOT = {
							place_in_line_of_succession = {
								target = scope:recipient
								value < 2
							}
						}
					}
				}
				NOT = {
					is_primary_heir_of = scope:puppet_or_actor
				}
			}
			desc = TAKE_THE_VOWS_IN_LINE_TO_OTHER_TITLE
		}

		modifier = { #Rivalry modifier.
			desc = offer_vassalization_interaction_aibehavior_rival_tt
			trigger = {
				scope:recipient = {
					has_relation_rival = scope:puppet_or_actor
					NOT = { has_relation_nemesis = scope:puppet_or_actor }
				}
			}
			add = -50
		}
		modifier = { #Nemesis modifier.
			desc = offer_vassalization_interaction_aibehavior_nemesis_tt
			trigger = {
				scope:recipient = {
					has_relation_nemesis = scope:puppet_or_actor
				}
			}
			add = -100
		}

		#Dread modifiers
		modifier = {
			add = 25
			scope:recipient = {
				has_dread_level_towards = {
					target = scope:puppet_or_actor
					level = 1
				}
			}
			desc = INTIMIDATED_REASON
		}
		modifier = {
			add = 50
			scope:recipient = {
				has_dread_level_towards = {
					target = scope:puppet_or_actor
					level = 2
				}
			}
			desc = COWED_REASON
		}

		# Culture Tradition modifiers

		modifier = {
			add = {
				value = 25
				if = {
					limit = {
						scope:recipient = {
							is_adult = no
							is_child_of = scope:puppet_or_actor
						}
					}
					add = 100
				}
			}
			scope:puppet_or_actor.culture = { has_cultural_parameter = monastic_expectations }
			desc = MONASTIC_EXPECTATIONS_REASON
		}

		# PAM - Concord Phase
		modifier = {
			add = 25
			situation:the_christian_church ?= {
				any_participant_group = { # Both characters are involved in the situation
					any_situation_group_participant = {
						this = scope:puppet_or_actor
					}
					trigger_if = {
						limit = { scope:recipient = { is_ruler = yes } }
						any_situation_group_participant = {
							this = scope:recipient
						}
					}
				}
				has_situation_top_phase_parameter = the_christian_church_better_take_the_vows_acceptance
			}
			desc = pam_the_christian_church_better_take_the_vows_acceptance_desc
		}
	}

	# AI will do

	ai_target_quick_trigger = {
		adult = yes
	}

	ai_targets = {
		ai_recipients = courtiers
		max = 5
	}

	ai_targets = {
		ai_recipients = children
		max = 5
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 144
		duchy = 72
		kingdom = 24
		empire = 24
		hegemony = 24
	}

	ai_will_do = {
		base = 0

		modifier = {
			add = -50
			scope:puppet_or_actor = {
				OR = {
					legitimacy_level = 0
					legitimacy_level = 1
				}
			}
			scope:recipient = { is_primary_heir_of = scope:puppet_or_actor }
		}

		modifier = { # The AI will always use a Hook
			scope:hook = yes
			add = 1
		}

		modifier = { # Try to send rivals
			add = 100
			scope:puppet_or_actor = {
				OR = {
					has_relation_rival = scope:recipient
					has_relation_nemesis = scope:recipient
				}
			}
		}
		modifier = { # Has cloister to send the child to
			scope:puppet_or_actor.domicile ?= { has_domicile_parameter = estate_cloister_take_vows }
			add = {
				value = scope:puppet_or_actor.learning
				add = scope:puppet_or_actor.diplomacy
				multiply = 0.5
			}
			desc = demand_child_as_monk_ai_priest_cloister
		}
		modifier = { # Try to send people who would make poor heirs
			add = 20
			scope:recipient = {
				is_child_of = scope:actor
				OR = {
					character_considered_morally_dubious_trigger = { RITE = scope:puppet_or_actor.rite }
					has_trait = drunkard
					has_trait = hashishiyah
					has_trait = flagellant
					has_trait = reclusive
					num_of_bad_genetic_traits = 1
					num_sinful_traits = 1
				}
				scope:puppet_or_actor.primary_title = {
					place_in_line_of_succession = {
						target = prev
						value <= 7
					}
				}
			}
		}
		modifier = { # Try to send people who would make terrible heirs
			add = 50
			scope:recipient = {
				is_child_of = scope:actor
				OR = {
					character_considered_wicked_trigger = { RITE = scope:puppet_or_actor.rite }
					has_trait = maimed
					num_of_bad_genetic_traits >= 2
					num_sinful_traits >= 2
				}
				scope:puppet_or_actor.primary_title = {
					place_in_line_of_succession = {
						target = prev
						value <= 7
					}
				}
			}
		}

		modifier = { # Try to send people who would make poor heirs
			add = 25
			scope:recipient = {
				is_child_of = scope:actor
				calc_true_if = {
					amount >= 3

					diplomacy < 8
					stewardship < 8
					martial < 8
					intrigue < 8
					learning < 8
				}
				scope:puppet_or_actor.primary_title = {
					place_in_line_of_succession = {
						target = prev
						value <= 7
					}
				}
			}
		}

		modifier = { # Sending one of your heirs is almost customary
			add = 100
			scope:recipient = {
				is_child_of = scope:puppet_or_actor
				has_education_learning_trigger = yes
			}
			scope:puppet_or_actor = {
				any_child = {
					count >= 3
				}
				NOT = {
					any_child = {
						OR = {
							has_trait = devoted
							has_trait = order_member
						}
					}
				}
			}
		}

		modifier = { # is not patron of the order
			add = -10
			NOT = {
				scope:secondary_recipient.holy_order ?= {
					holy_order_patron = scope:puppet_or_actor
				}
			}
		}
		modifier = { # order is in domain
			add = 20
			scope:secondary_recipient.holy_order ?= {
				any_leased_title = {
					county.holder = scope:puppet_or_actor
				}
			}
		}
		modifier = { # order is not in realm or de jure kingdom
			add = -20
			scope:secondary_recipient.holy_order ?= {
				NOR = {
					any_leased_title = {
						county.holder.top_liege = scope:puppet_or_actor.top_liege
					}
					any_leased_title = {
						kingdom ?= scope:puppet_or_actor.capital_county.kingdom
					}
				}
			}
		}
		modifier = { # order is not in diplomatic range
			add = -50
			scope:secondary_recipient = {
				NOT = {
					in_diplomatic_range = scope:puppet_or_actor
				}
			}
		}
		modifier = { # is patron of the order
			add = 30
			scope:secondary_recipient.holy_order ?= {
				holy_order_patron = scope:puppet_or_actor
			}
		}

		modifier = { # Zealous characters generally want to send characters to the clergy
			add = 50
			scope:puppet_or_actor = {
				ai_zeal >= high_positive_ai_value
			}
			scope:recipient = {
				has_education_learning_trigger = yes
			}
		}

		modifier = { # Greedy characters want to rid their court of potential threats
			add = 50
			scope:puppet_or_actor = {
				ai_greed >= medium_positive_ai_value
				any_child = { }
			}
			scope:recipient = {
				NOT = {
					is_child_of = scope:puppet_or_actor
				}
				any_claim = {
					holder ?= scope:puppet_or_actor
				}
			}
		}

		#if you have personal tenet and are religion nerd
		modifier = {
			add = 20
			exists = scope:secondary_recipient.holy_order.order_tenet
			any_personal_tenet = {
				this = scope:secondary_recipient.holy_order.order_tenet
			}
			OR = {
				piety_level >= 3
				has_education_learning_trigger = yes
				rite.head_of_rite ?= this
			}
		}

		#if you have personal tenet
		modifier = {
			add = 10
			exists = scope:secondary_recipient.holy_order.order_tenet
			any_personal_tenet = {
				this = scope:secondary_recipient.holy_order.order_tenet
			}
		}

		modifier = {
			factor = 1.25
			exists = capital_county.kingdom
			exists = scope:secondary_recipient.capital_county.kingdom
			capital_county.kingdom = scope:secondary_recipient.capital_county.kingdom
		}

		modifier = {
			factor = 0.1
			exists = scope:secondary_recipient
			rite != scope:secondary_recipient.rite
		}

		modifier = {
			factor = 0.1
			OR = {
				#Don't want to send to faraway orders
				NOT = {
					scope:secondary_recipient.holy_order = {
						any_leased_title = {
							trigger_if = {
								limit = {
									exists = scope:target
								}
								empire = scope:target.empire
							}
							trigger_else = {
								empire = scope:puppet_or_actor.capital_county.empire
							}
						}
					}
				}
				#You think their tenet is bad and dumb
				AND = {
					exists = scope:secondary_recipient.holy_order.order_tenet
					NOR = {
						scope:puppet_or_actor = {
							any_personal_tenet = {
								this = scope:secondary_recipient.holy_order.order_tenet
							}
							any_desired_tenet = {
								selection_count = 30
								only_positive = yes
								threshold = 1
								this = scope:secondary_recipient.holy_order.order_tenet
							}
						}
					}
				}
			}
		}
	}
}

#Donate to Monastic Orders in exchange for spiritual fulfillment
#By Brother Jason
monastic_donation_interaction = {
	category = interaction_category_religion
	icon = request_funding_interaction
	filter_tags = { holy_order }

	ai_min_reply_days = 3
	ai_max_reply_days = 6
	common_interaction = yes

	cooldown_against_recipient = { years = 5 }

	desc = monastic_donation_interaction_desc

	greeting = positive
	notification_text = MONASTIC_DONATION_NOTIFICATION_TEXT


	is_available = {
		trigger_if = {
			limit = { is_ai = yes }
			short_term_gold > major_gold_value
			spiritual_fulfillment < 0
		}
	}

	is_shown = {
		scope:puppet_or_actor ?= {
			faith ?= {
				any_faith_holy_order = {
					leader = scope:recipient
				}
			}
			NOT = {
				government_has_flag = government_is_monastic_holy_order
			}
		}
		scope:recipient = {
			is_ruler = yes
			in_diplomatic_range = scope:puppet_or_actor
			government_has_flag = government_is_monastic_holy_order
		}
	}

	is_valid_showing_failures_only = {
		scope:puppet_or_actor = {
			is_imprisoned = no
			trigger_if = {
				limit = {
					has_treasury = yes
					government_has_flag = government_is_theocracy
				}
				treasury >= monastic_donation_treasury_value
			}
			trigger_else = {
				gold >= monastic_donation_value
			}
			
		}
		#Monastic holding's leases are all in realms actor is at war with
		custom_tooltip = {
			text = monastic_holdings_in_hostile_realms_tt
			scope:puppet_or_actor.faith = {
				any_faith_holy_order = {
					leader = scope:recipient
					any_leased_title = {
						NOT = {
							county.holder = {
								OR = {
									is_at_war_with = scope:puppet_or_actor
									any_liege_or_above = {
										is_at_war_with = scope:puppet_or_actor
									}
								}
							}
						}
					}
				}
			}
		}
		#Holdings are all too far away
		custom_tooltip = {
			text = monastic_holdings_too_distant_tt
			scope:puppet_or_actor.faith = {
				any_faith_holy_order = {
					leader = scope:recipient
					holy_order_range_trigger = { CHARACTER = scope:puppet_or_actor }
				}
			}
		}
		scope:puppet_or_actor = {
			NOT = {
				has_character_modifier = promised_pilgrimage_to_clergy_modifier
			}
		}
	}
	# Use hook
	send_option = {
		is_valid = {
			scope:puppet_or_actor = {
				has_usable_hook = scope:recipient
			}
			NOT = {
				scope:recipient = { is_imprisoned_by = scope:puppet_or_actor }
			}
		}
		flag = hook
		localization = SCHEME_HOOK
	}

	#Use hook
	auto_accept = {
		custom_description = {
			text = "spending_hook"
			subject = scope:puppet_or_actor
			object = scope:recipient
			scope:hook = yes
			scope:puppet_or_actor = { has_strong_hook = scope:recipient }
		}
	}


	#Humiliate self
	send_option = {
		is_valid = {
			custom_tooltip = {
				text = low_piety_or_spiritual_fulfillment_tt
				scope:puppet_or_actor = {
					OR = {
						piety_level = 0
						has_fulfillment_parameter = sp_ceremonial_humbling
					}
				}
			}
			scope:puppet_or_actor = {
				trigger_if = {
					limit = {
						scope:actor = { is_ai = yes }
					}
					OR = {
						AND = {
							prestige >= monumental_prestige_value
							has_fulfillment_parameter = sp_ceremonial_humbling
						}
						spiritual_fulfillment <= spiritual_fulfillment_minus_3
					}
				}
			}

		}
		flag = ceremonial_humbling
		localization = INTERACTION_CEREMONIAL_HUMBLING
	}
	#HUGE DONATION
	send_option = {
		is_valid = {
			scope:puppet_or_actor = {
				trigger_if = {
					limit = {
						has_treasury = yes
						government_has_flag = government_is_theocracy
					}
					treasury >= monastic_huge_donation_treasury_value
				}
				trigger_else = {
					gold >= monastic_huge_donation_value
				}
				#AI further restrictions
				trigger_if = {
					limit = {
						scope:actor = { is_ai = yes }
					}
					trigger_if = {
						limit = {
							has_treasury = yes
							government_has_flag = government_is_theocracy
						}
						short_term_treasury >= monastic_huge_donation_treasury_value
					}
					trigger_else = {
						short_term_gold >= monastic_huge_donation_value
					}
					spiritual_fulfillment < spiritual_fulfillment_minus_1
				}
			}
		}
		flag = huge_donation
		localization = INTERACTION_HUGE_DONATION
	}
	should_use_extra_icon = {
		scope:puppet_or_actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	send_options_exclusive = no

	cost = {
	}

	on_send = {
 	}

	on_accept = {
		show_as_tooltip = {
			donate_to_monastic_order_effect = yes
			scope:recipient = {
				custom_tooltip = monk_can_use_money_for_actions_tt
			}
		}
		scope:puppet_or_actor = {
			trigger_event = {
				id = holy_order.2030
			}
		}
	}

	on_decline = {
		#Letter event informing you about decline
		scope:puppet_or_actor = {
			trigger_event = {
				id = holy_order.2031
			}
		}
 	}

	auto_accept = no

	ai_accept = {
		base = 0 # Try to make it 0 for most interactions

		celestial_hierarchy_acceptance_modifier = {
			ACTOR = scope:puppet_or_actor
			RECIPIENT = scope:recipient
		}

		modifier = {
			scope:hook = yes
			add = 100
			desc = SCHEME_WEAK_HOOK_USED
		}
		modifier = {
			add = 50
			scope:huge_donation = yes
			desc = monastic_huge_donation_acceptance
		}
		modifier = {
			add = 150
			scope:ceremonial_humbling = yes
			desc = monastic_humbling_acceptance
		}
		opinion_modifier = { # Opinion Factor
			who = scope:recipient
			opinion_target = scope:puppet_or_actor
			multiplier = 0.25
			desc = AI_SIMPLE_OPINION_REASON
		}
		#Personality
		modifier = {
			add = {
				value = scope:puppet_or_actor.ai_zeal
				divide = 5
			}
			ai_zeal != 0
			desc = INTERACTION_AI_ZEAL
		}
		modifier = {
			ai_greed > 0
			add = ai_greed
			desc = INTERACTION_RECIPIENT_AI_GREED_HIGH
		}
		#Relationship stuff

		#Close family member
		modifier = {
			is_close_family_of = scope:puppet_or_actor
			add = 50
			desc = is_close_family_reason
		}
		#House member
		modifier = {
			exists = scope:puppet_or_actor.house
			house ?= scope:puppet_or_actor.house
			add = 50
			desc = AI_SAME_HOUSE_REASON
		}
		modifier = {
			exists = scope:puppet_or_actor.house
			NOT = { house ?= scope:puppet_or_actor.house }
			dynasty ?= scope:puppet_or_actor.dynasty
			add = 20
			desc = AI_SAME_DYNASTY_REASON
		}
		#You are house head
		modifier = {
			exists = scope:puppet_or_actor.house
			house.house_head ?= scope:puppet_or_actor
			add = 50
			desc = AI_YOU_ARE_THE_HOUSE_HEAD
		}
		modifier = {
			exists = scope:puppet_or_actor.house
			NOT = { house.house_head ?= scope:puppet_or_actor }
			dynasty.dynast ?= scope:puppet_or_actor
			add = 25
			desc = AI_YOU_ARE_THE_DYNAST
		}
		#Leases holdings from char
		modifier = {
			faith = {
				any_faith_holy_order = {
					leader = scope:recipient
					any_leased_title = {
						county.holder = scope:puppet_or_actor
					}
				}
			}
			add = 25
			desc = INTERACTION_LEASES_HOLDINGS
		}
		#Shared rite
		modifier = {
			add = 25
			exists = scope:puppet_or_actor.rite
			scope:recipient.rite ?= scope:puppet_or_actor.rite
			desc = I_HAVE_THE_SAME_RITE
		}
		modifier = {
			add = -25
			exists = scope:puppet_or_actor.rite
			exists = scope:recipient.rite
			# Same medium_rite_divergence step the donor uses
			scope:puppet_or_actor.rite = {
				"divergence(scope:recipient.rite)" >= medium_rite_divergence_value
			}
			desc = I_HAVE_A_DIFFERENT_RITE
		}
		#The donor's rite forbids the very tenet the order was founded on
		modifier = {
			add = -100
			exists = scope:recipient.holy_order.order_tenet
			scope:puppet_or_actor.rite ?= {
				has_tenet_status = {
					tenet = scope:recipient.holy_order.order_tenet
					status = prohibited
				}
			}
			desc = MONASTIC_DONATION_ORDER_TENET_PROHIBITED
		}
		#Rival
		modifier = {
			has_relation_rival = scope:puppet_or_actor
			add = -200
			desc = ARTIFACT_RIVAL_REASON
		}

		#Your tier (thus your power and size of donation)
		modifier = {
			scope:puppet_or_actor = {
				highest_held_title_tier >= tier_duchy
			}
			add = {
				value = scope:puppet_or_actor.highest_held_title_tier
				subtract = 2
				multiply = 20
			}
			desc = TITLE_TIER_REASON
		}

		#Piety level
		modifier = {
			scope:puppet_or_actor = {
				piety_level >= 2
			}
			add = {
				value = scope:puppet_or_actor.piety_level
				subtract = 1
				multiply = 20
			}
			desc = I_AM_PIOUS
		}
		modifier = {
			scope:puppet_or_actor = {
				piety_level < 1
			}
			add = -50
			desc = I_AM_SINFUL
		}

		#Very pious traits
		modifier = {
			scope:puppet_or_actor = {
				OR = {
					has_trait = saint
					has_trait = herald
					has_trait = saoshyant_descendant
					has_trait = order_member
					has_trait = faith_warrior
					has_trait = saoshyant
					has_trait = paragon
					has_trait = savior
					has_trait = crusader_king
				}
			}
			add = 100
			desc = VERY_PIOUS_TRAITS_REASON
		}

		#Pious traits
		modifier = {
			scope:puppet_or_actor = {
				OR = {
					has_trait = zealous
					has_trait = theologian
					has_trait = divine_blood
					has_trait = consecrated_blood
					has_trait = sayyid
				}
			}
			add = 30
			desc = PIOUS_TRAITS_REASON
		}

		#Sinful traits
		modifier = {
			scope:puppet_or_actor = {
				OR = {
					has_any_shunned_trait_in_rite_trigger = {
						CHARACTER = scope:puppet_or_actor
						RITE = scope:recipient.rite
					}
					has_trait = bastard
					has_trait = gallowsbait
					has_trait = decadent
				}
			}
			add = -30
			desc = SINFUL_TRAITS_REASON
		}
		#Major sinful traits
		modifier = {
			scope:puppet_or_actor = {
				OR = {
					has_any_criminal_trait_in_rite_trigger = {
						CHARACTER = scope:puppet_or_actor
						RITE = scope:recipient.rite
					}
					has_trait = despoiler_of_byzantium
					has_trait = incestuous
					has_trait = murderer
				}
			}
			add = -100
			desc = VERY_SINFUL_TRAITS_REASON
		}
		#Excommunicated
		modifier = {
			scope:puppet_or_actor = {
				has_trait = excommunicated
			}
			add = -300
			desc = EXCOMMUNICATED_REASON
		}
		#Same rite
		modifier = {
			scope:puppet_or_actor.rite = scope:recipient.rite
			add = 30
			desc = MONASTIC_SAME_RITE_REASON
		}
		#Heretical rite
		modifier = {
			scope:puppet_or_actor.rite = {
				"divergence(scope:recipient.rite)" >= scope:recipient.faith.heresy_threshold
			}
			add = -100
			desc = MONASTIC_HERETICAL_RITE_REASON
		}
		#Personally holds the order's tenet
		modifier = {
			exists = scope:recipient.holy_order.order_tenet
			scope:puppet_or_actor = {
				any_personal_tenet = {
					this = scope:recipient.holy_order.order_tenet
				}
			}
			add = 20
			desc = MONASTIC_ORDER_TENET_REASON
		}
	}

	# AI will do

	ai_target_quick_trigger = {
		adult = yes
	}
	
	ai_targets = {
		ai_recipients = neighboring_rulers
		ai_recipients = faith_holy_order_leaders
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 48
		duchy = 24
		kingdom = 12
		empire = 12
		hegemony = 12
	}

	ai_will_do = {
		base = 0

		modifier = { # is not patron of the order
			add = -25
			NOT = {
				faith = {
					any_faith_holy_order = {
						leader = scope:recipient
						holy_order_patron = scope:puppet_or_actor
					}
				}
			}
		}
		modifier = { # order is in domain
			add = 20
			faith = {
				any_faith_holy_order = {
					leader = scope:recipient
					any_leased_title = {
						county.holder = scope:puppet_or_actor
					}
				}
			}
		}
		modifier = { # order is not in realm or de jure kingdom
			add = -40
			faith = {
				any_faith_holy_order = {
					leader = scope:recipient
					NOR = {
						any_leased_title = {
							county.holder.top_liege = scope:puppet_or_actor.top_liege
						}
						any_leased_title = {
							kingdom ?= scope:puppet_or_actor.capital_county.kingdom
						}
					}
				}
			}
		}
		modifier = { # order is not in diplomatic range
			add = -75
			scope:recipient = {
				NOT = {
					in_diplomatic_range = scope:puppet_or_actor
				}
			}
		}
		modifier = { # is patron of the order
			add = 30
			faith = {
				any_faith_holy_order = {
					leader = scope:recipient
					holy_order_patron = scope:puppet_or_actor
				}
			}
		}

		modifier = { # Zealous characters
			add = 25
			scope:puppet_or_actor = {
				ai_zeal >= high_positive_ai_value
			}
		}

		modifier = {
			add = 50
			scope:puppet_or_actor = {
				spiritual_fulfillment < spiritual_fulfillment_minus_1
			}
		}

		modifier = {
			add = 100
			scope:puppet_or_actor = {
				spiritual_fulfillment < spiritual_fulfillment_minus_2
			}
		}

		modifier = {
			add = 100
			scope:puppet_or_actor = {
				spiritual_fulfillment <= spiritual_fulfillment_minus_3
			}
		}

		modifier = {
			factor = 1.25
			capital_county.kingdom = scope:recipient.capital_county.kingdom
		}

		modifier = {
			factor = 0.5
			ai_greed >= low_positive_ai_value
		}

		#if you have personal tenet and are religion nerd
		modifier = {
			add = 20
			exists = scope:recipient.holy_order.order_tenet
			any_personal_tenet = {
				this = scope:recipient.holy_order.order_tenet
			}
			OR = {
				piety_level >= 3
				has_education_learning_trigger = yes
				rite.head_of_rite ?= this
			}
		}

		modifier = {
			factor = 0.1
			OR = {
				has_trait = cynical
				ai_greed >= high_positive_ai_value
				#Don't want to donate to faraway orders
				NOT = {
					scope:recipient.holy_order = {
						any_leased_title = {
							trigger_if = {
								limit = {
									exists = scope:target
								}
								empire = scope:target.empire
							}
							trigger_else = {
								empire = scope:puppet_or_actor.capital_county.empire
							}
						}
					}
				}
				#You think their tenet is bad and dumb
				AND = {
					exists = scope:recipient.holy_order.order_tenet
					scope:puppet_or_actor ?= {
						NOR = {
							scope:puppet_or_actor = {
								any_personal_tenet = {
									this = scope:recipient.holy_order.order_tenet
								}
								any_desired_tenet = {
									selection_count = 30
									only_positive = yes
									threshold = 1
									this = scope:recipient.holy_order.order_tenet
								}
							}
						}
					}
				}
			}
		}

		modifier = { # shares the order's rite
			add = 25
			scope:puppet_or_actor.rite = scope:recipient.rite
		}
		modifier = { # rite has diverged from the order's
			add = -20
			scope:puppet_or_actor.rite = {
				"divergence(scope:recipient.rite)" >= medium_rite_divergence_value
			}
		}
		modifier = { # order is heretical to the donor, by the donor's own threshold
			factor = 0.1
			scope:puppet_or_actor.rite = {
				"divergence(scope:recipient.rite)" >= scope:puppet_or_actor.faith.heresy_threshold
			}
		}
	}
}

#Lease an additional holding to Monastic Order
# by Secular Canon Jason Cantalini
lease_title_to_existing_monastic_order_interaction = {
	category = interaction_category_religion
	icon = icon_scheme_study_faith
	target_type = title
	target_source = puppet_or_actor
	target_filter = domain_titles_including_leases
	# No barony-only filter exists, so hide the counties and duchies this one also offers
	show_all_targets = no
	filter_tags = { holy_order }

	ai_min_reply_days = 3
	ai_max_reply_days = 6
	common_interaction = yes

	desc = lease_title_to_existing_monastic_order_interaction_desc

	greeting = positive
	notification_text = MONASTIC_ORDER_LEASE_NOTIFICATION_TEXT


	is_available = {
		trigger_if = {
			limit = { is_ai = yes }
			any_held_title = {
			 	count >= 2
			 	tier = tier_county
			 	any_county_province = {
			 		has_holding_type = church_holding
			 		barony ?= {
			 			trigger_if = {
							limit = {
								exists = barony.lessee
							}
							NOT = {
								barony.lessee = {
									government_has_flag = government_is_monastic_holy_order
								}
							}
						}
			 		}
			 	}
			}
			#either needs spiritual fulfillment or a monastic holy order to patron
			OR = {
				spiritual_fulfillment < 0
				AND = {
					highest_held_title_tier >= tier_kingdom
					NOT = {
						any_patroned_holy_order = {
							leader = {
								government_has_flag = government_is_monastic_holy_order
							}
						}
					}
				}
			}
			is_imprisoned = no
		}
	}

	is_shown = {
		scope:puppet_or_actor ?= {
			highest_held_title_tier >= tier_county
			is_landed = yes
		}
		scope:puppet_or_actor.faith ?= {
			any_faith_holy_order = {
				leader = scope:recipient
			}
		}
		scope:recipient = {
			is_ruler = yes
			in_diplomatic_range = scope:puppet_or_actor
			government_has_flag = government_is_monastic_holy_order
		}
	}

	can_be_picked_title = {
		scope:target = {
			tier = tier_barony
			title_province = {
				has_holding_type = church_holding
			}
			trigger_if = {
				limit = {
					exists = lessee
				}
				custom_tooltip = {
					text = already_has_monastic_lease_tt
					NOT = {
						lessee = {
							government_has_flag = government_is_monastic_holy_order
						}
					}
				}
			}
			is_landless_type_title = no
		}
	}

	is_valid_showing_failures_only = {
		scope:puppet_or_actor = {
			is_imprisoned = no
		}
		custom_tooltip = {
			text = no_valid_temple_holdings_to_lease_tt
			scope:puppet_or_actor = {
				any_held_title = {
					tier = tier_county
					any_county_province = {
						has_holding_type = church_holding
						NOT = {
							is_county_capital = yes
						}
						trigger_if = {
							limit = {
								exists = barony.lessee
							}
							NOT = {
								barony.lessee = {
									government_has_flag = government_is_monastic_holy_order
								}
							}
						}
					}
				}
			}
		}
		#Monastic holding's leases are all in realms actor is at war with
		custom_tooltip = {
			text = monastic_holdings_in_hostile_realms_tt
			scope:puppet_or_actor.faith = {
				any_faith_holy_order = {
					leader = scope:recipient
					any_leased_title = {
						NOT = {
							county.holder = {
								OR = {
									is_at_war_with = scope:puppet_or_actor
									any_liege_or_above = {
										is_at_war_with = scope:puppet_or_actor
									}
								}
							}
						}
					}
				}
			}
		}
	}
	# Use hook
	send_option = {
		is_valid = {
			scope:puppet_or_actor = {
				has_usable_hook = scope:recipient
			}
			NOT = {
				scope:recipient = { is_imprisoned_by = scope:puppet_or_actor }
			}
		}
		flag = hook
		localization = SCHEME_HOOK
	}

	#Use hook
	auto_accept = {
		custom_description = {
			text = "spending_hook"
			subject = scope:puppet_or_actor
			object = scope:recipient
			scope:hook = yes
			scope:puppet_or_actor = { has_strong_hook = scope:recipient }
		}
	}
	#Make lavish donations to the abbey
	send_option = {
		is_valid = {
			scope:puppet_or_actor = {
				gold >= monastic_donation_value
				trigger_if = {
					limit = {
						scope:actor = { is_ai = yes }
					}
					short_term_gold >= monastic_donation_value
					spiritual_fulfillment < spiritual_fulfillment_minus_1
				}
			}
		}
		flag = huge_donation
		localization = INTERACTION_LEASE_DONATION
	}
	should_use_extra_icon = {
		scope:puppet_or_actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	send_options_exclusive = no

	cost = {
	}

	on_send = {
 	}

	on_accept = {
		# Must search puppet_or_actor.faith like is_valid, or a different-faith barony finds no order
		scope:puppet_or_actor.faith = {
			random_faith_holy_order = {
				limit = {
					leader = scope:recipient
				}
				save_scope_as = monastic_order
			}
		}
		scope:target.county = {
			save_scope_as = target_county
		}
		show_as_tooltip = {
			lease_to_monastic_order_interaction_effect = yes
			scope:recipient = {
				custom_tooltip = monk_can_use_lease_for_actions_tt
				custom_tooltip = monk_can_use_lease_region_for_actions_tt
			}
		}
		scope:puppet_or_actor = {
			trigger_event = {
				id = holy_order.2040
			}
		}
	}

	on_decline = {
		#Letter event informing you about decline
		scope:puppet_or_actor = {
			trigger_event = {
				id = holy_order.2041
			}
		}
 	}

	auto_accept = no

	ai_accept = {
		base = 50 # Try to make it 0 for most interactions

		celestial_hierarchy_acceptance_modifier = {
			ACTOR = scope:puppet_or_actor
			RECIPIENT = scope:recipient
		}

		modifier = {
			scope:hook = yes
			add = 100
			desc = SCHEME_WEAK_HOOK_USED
		}
		modifier = {
			add = 50
			scope:huge_donation = yes
			desc = monastic_huge_donation_acceptance
		}
		opinion_modifier = { # Opinion Factor
			who = scope:recipient
			opinion_target = scope:puppet_or_actor
			multiplier = 0.25
			desc = AI_SIMPLE_OPINION_REASON
		}
		#Personality
		modifier = {
			add = {
				value = scope:puppet_or_actor.ai_zeal
				divide = 5
			}
			desc = INTERACTION_AI_ZEAL
		}
		modifier = {
			ai_greed > 0
			add = ai_greed
			desc = INTERACTION_RECIPIENT_AI_GREED_HIGH
		}
		#Relationship stuff

		#Close family member
		modifier = {
			is_close_family_of = scope:puppet_or_actor
			add = 50
			desc = is_close_family_reason
		}
		#House member
		modifier = {
			exists = scope:puppet_or_actor.house
			house ?= scope:puppet_or_actor.house
			add = 50
			desc = AI_SAME_HOUSE_REASON
		}
		modifier = {
			exists = scope:puppet_or_actor.house
			NOT = { house ?= scope:puppet_or_actor.house }
			dynasty ?= scope:puppet_or_actor.dynasty
			add = 20
			desc = AI_SAME_DYNASTY_REASON
		}
		#You are house head
		modifier = {
			exists = scope:puppet_or_actor.house
			house.house_head ?= scope:puppet_or_actor
			add = 50
			desc = AI_YOU_ARE_THE_HOUSE_HEAD
		}
		modifier = {
			exists = scope:puppet_or_actor.house
			NOT = { house.house_head ?= scope:puppet_or_actor }
			dynasty.dynast ?= scope:puppet_or_actor
			add = 25
			desc = AI_YOU_ARE_THE_DYNAST
		}
		#Leases holdings from char
		modifier = {
			faith = {
				any_faith_holy_order = {
					leader = scope:recipient
					any_leased_title = {
						county.holder = scope:puppet_or_actor
					}
				}
			}
			add = 10
			desc = INTERACTION_LEASES_HOLDINGS
		}
		#Rival
		modifier = {
			has_relation_rival = scope:puppet_or_actor
			add = -200
			desc = ARTIFACT_RIVAL_REASON
		}

		#Your tier (thus your power and size of donation)
		modifier = {
			scope:puppet_or_actor = {
				highest_held_title_tier >= tier_duchy
			}
			add = {
				value = scope:puppet_or_actor.highest_held_title_tier
				subtract = 2
				multiply = 10
			}
			desc = TITLE_TIER_REASON
		}

		#Piety level
		modifier = {
			scope:puppet_or_actor = {
				piety_level >= 2
			}
			add = {
				value = scope:puppet_or_actor.piety_level
				subtract = 1
				multiply = 20
			}
			desc = I_AM_PIOUS
		}
		modifier = {
			scope:puppet_or_actor = {
				piety_level < 1
			}
			add = -50
			desc = I_AM_SINFUL
		}
		#Order is weak
		modifier = {
			scope:recipient = {
				faith = {
					any_faith_holy_order = {
						leader = scope:recipient
						num_leased_titles = 3
					}
				}
			}
			add = 25
			desc = SMALL_ORDER_REASON
		}
		modifier = {
			scope:recipient = {
				faith = {
					any_faith_holy_order = {
						leader = scope:recipient
						num_leased_titles = 2
					}
				}
			}
			add = 50
			desc = SMALL_ORDER_REASON
		}
		modifier = {
			scope:recipient = {
				faith = {
					any_faith_holy_order = {
						leader = scope:recipient
						num_leased_titles = 1
					}
				}
			}
			add = 100
			desc = SMALL_ORDER_REASON
		}

		#Very pious traits
		modifier = {
			scope:puppet_or_actor = {
				OR = {
					has_trait = saint
					has_trait = herald
					has_trait = saoshyant_descendant
					has_trait = order_member
					has_trait = faith_warrior
					has_trait = saoshyant
					has_trait = paragon
					has_trait = savior
					has_trait = crusader_king
				}
			}
			add = 100
			desc = VERY_PIOUS_TRAITS_REASON
		}

		#Pious traits
		modifier = {
			scope:puppet_or_actor = {
				OR = {
					has_trait = zealous
					has_trait = theologian
					has_trait = divine_blood
					has_trait = consecrated_blood
					has_trait = sayyid
				}
			}
			add = 30
			desc = PIOUS_TRAITS_REASON
		}

		#Sinful traits
		modifier = {
			scope:puppet_or_actor = {
				OR = {
					has_any_shunned_trait_in_rite_trigger = {
						CHARACTER = scope:puppet_or_actor
						RITE = scope:recipient.rite
					}
					has_trait = bastard
					has_trait = gallowsbait
					has_trait = decadent
				}
			}
			add = -30
			desc = SINFUL_TRAITS_REASON
		}
		#Major sinful traits
		modifier = {
			scope:puppet_or_actor = {
				OR = {
					has_any_criminal_trait_in_rite_trigger = {
						CHARACTER = scope:puppet_or_actor
						RITE = scope:recipient.rite
					}
					has_trait = despoiler_of_byzantium
					has_trait = incestuous
					has_trait = murderer
				}
			}
			add = -100
			desc = VERY_SINFUL_TRAITS_REASON
		}
		#Excommunicated
		modifier = {
			scope:puppet_or_actor = {
				has_trait = excommunicated
			}
			add = -300
			desc = EXCOMMUNICATED_REASON
		}
		#Same rite
		modifier = {
			scope:puppet_or_actor.rite = scope:recipient.rite
			add = 30
			desc = MONASTIC_SAME_RITE_REASON
		}
		#Heretical rite
		modifier = {
			scope:puppet_or_actor.rite = {
				"divergence(scope:recipient.rite)" >= scope:recipient.faith.heresy_threshold
			}
			add = -100
			desc = MONASTIC_HERETICAL_RITE_REASON
		}
		#Personally holds the order's tenet
		modifier = {
			exists = scope:recipient.holy_order.order_tenet
			scope:puppet_or_actor = {
				any_personal_tenet = {
					this = scope:recipient.holy_order.order_tenet
				}
			}
			add = 20
			desc = MONASTIC_ORDER_TENET_REASON
		}
	}

	# AI will do

	ai_target_quick_trigger = {
		adult = yes
	}
	
	ai_targets = {
		ai_recipients = neighboring_rulers
		ai_recipients = faith_holy_order_leaders
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 120
		duchy = 48
		kingdom = 24
		empire = 24
		hegemony = 24
	}

	ai_will_do = {
		base = 0

		modifier = { # is patron of the order
			add = 20
			scope:recipient.holy_order.holy_order_patron ?= scope:puppet_or_actor
			highest_held_title_tier >= tier_duchy
		}
		modifier = { # order is out of range
			add = 10
			scope:puppet_or_actor.faith = {
				any_faith_holy_order = {
					leader = scope:recipient
					NOT = { holy_order_range_trigger = { CHARACTER = scope:puppet_or_actor } }
				}
			}
		}

		modifier = { # Zealous characters
			add = 25
			scope:puppet_or_actor = {
				ai_zeal >= high_positive_ai_value
			}
		}

		modifier = {
			add = 25
			scope:puppet_or_actor = {
				spiritual_fulfillment < spiritual_fulfillment_minus_1
			}
		}

		modifier = {
			add = 50
			scope:puppet_or_actor = {
				spiritual_fulfillment < spiritual_fulfillment_minus_2
			}
		}

		modifier = {
			add = 100
			scope:puppet_or_actor = {
				spiritual_fulfillment <= spiritual_fulfillment_minus_3
			}
		}

		#if you have personal tenet and are religion nerd
		modifier = {
			add = 10
			exists = scope:recipient.holy_order.order_tenet
			any_personal_tenet = {
				this = scope:recipient.holy_order.order_tenet
			}
			OR = {
				piety_level >= 3
				has_education_learning_trigger = yes
				rite.head_of_rite ?= this
			}
		}

		modifier = {
			factor = 1.25
			capital_county.kingdom = scope:recipient.capital_county.kingdom
		}

		modifier = {
			factor = 0.5
			scope:puppet_or_actor = {
				OR = {
					ai_greed >= low_positive_ai_value
					domain_size <= 3
				}
			}
		}

		#Don't want to lease to faraway orders if there are closer ones that vibe
		modifier = {
			factor = 0.25
			NOT = {
				scope:recipient.holy_order = {
					any_leased_title = {
						trigger_if = {
							limit = {
								exists = scope:target
							}
							empire = scope:target.empire
						}
						trigger_else = {
							empire = scope:puppet_or_actor.capital_county.empire
						}
					}
				}
			}
			faith = {
				any_faith_holy_order = {
					any_leased_title = {
						trigger_if = {
							limit = {
								exists = scope:target
							}
							empire = scope:target.empire
						}
						trigger_else = {
							empire = scope:puppet_or_actor.capital_county.empire
						}
					}
					leader.rite ?= scope:puppet_or_actor.rite
					order_tenet ?= {
						save_temporary_scope_as = order_tenet_temp
					}
					scope:puppet_or_actor ?= {
						OR = {
							any_personal_tenet = {
								this = scope:order_tenet_temp
							}
							any_desired_tenet = {
								selection_count = 97
								only_positive = yes
								threshold = 1
								this = scope:order_tenet_temp
							}
						}
					}
				}
			}
		}

		modifier = {
			factor = 0.1
			scope:puppet_or_actor = {
				OR = {
					has_trait = cynical
					ai_greed >= high_positive_ai_value
					domain_size <= 2
					#You think their tenet is bad and dumb
					AND = {
						exists = scope:recipient.holy_order.order_tenet
						NOR = {
							scope:puppet_or_actor = {
								any_personal_tenet = {
									this = scope:recipient.holy_order.order_tenet
								}
								any_desired_tenet = {
									selection_count = 30
									only_positive = yes
									threshold = 1
									this = scope:recipient.holy_order.order_tenet
								}
							}
						}
					}
				}
			}
		}	
		modifier = { # shares the order's rite
			add = 20
			scope:puppet_or_actor.rite = scope:recipient.rite
		}
		modifier = { # rite has diverged from the order's
			add = -15
			scope:puppet_or_actor.rite = {
				"divergence(scope:recipient.rite)" >= medium_rite_divergence_value
			}
		}
		modifier = { # order is heretical to the lessor, by the lessor's own threshold
			factor = 0.1
			scope:puppet_or_actor.rite = {
				"divergence(scope:recipient.rite)" >= scope:puppet_or_actor.faith.heresy_threshold
			}
		}
	}
}

offer_bedside_support_interaction = {
	icon = religious
	category = interaction_category_friendly

	desc = offer_bedside_support_interaction_desc

	cooldown_against_recipient = { years = 1 }

	is_available = {
		rite ?= {
			rite_has_parameter = tenet_sacred_childbirth_offer_bedside_support
		}		
	}

	is_shown = {
		NOT = { scope:actor = scope:recipient }
		scope:recipient = {
			is_pregnant = yes
			OR = {
				is_courtier_of = scope:actor
				is_close_or_extended_family_of = scope:actor
				is_vassal_or_below_of = scope:actor
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			is_adult = yes
			is_available = yes
		}
		scope:recipient = {
			is_available = yes
		}
	}

	cost = {
		piety = minor_piety_value
	}

	auto_accept = yes

	on_accept = {
		scope:recipient = {
			hidden_effect = {
				if = {
					limit = {
						has_variable = {
							name = birth_child_will_become_sickly
							name = birth_mother_will_become_ill
						}
					}
					random = {
						chance = pam_bedside_support_avert_chance_value
						remove_character_flag = birth_child_will_become_sickly
						remove_character_flag = birth_mother_will_become_ill
						add_character_flag = {
							flag = birth_will_go_smoothly
							days = 270
						}
						save_scope_value_as = {
							name = bedside_support_averted
							value = yes
						}
					}
				}
			}
			send_interface_toast = {
				type = event_toast_effect_good
				title = offer_bedside_support_interaction_notification
				left_icon = scope:actor
				right_icon = scope:recipient
				add_opinion = {
					modifier = pleased_opinion
					target = scope:actor
					opinion = 15
				}
				add_stress = medium_stress_loss
			}
		}
		scope:actor = {
			if = {
				limit = { exists = scope:bedside_support_averted }
				send_interface_toast = {
					type = event_toast_effect_good
					title = offer_bedside_support_interaction_actor_averted_notification
					left_icon = scope:actor
					right_icon = scope:recipient
					add_piety = medium_piety_gain
					change_spiritual_fulfillment = minor_spiritual_fulfillment_value
				}
			}
			else = {
				send_interface_toast = {
					type = event_toast_effect_neutral
					title = offer_bedside_support_interaction_actor_notification
					left_icon = scope:actor
					right_icon = scope:recipient
					change_spiritual_fulfillment = minor_spiritual_fulfillment_value
				}
			}
		}
	}

	ai_targets = {
		ai_recipients = courtiers
	}

	ai_target_quick_trigger = {
		adult = yes
	}

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

	ai_will_do = {
		base = 60

		modifier = {
			factor = 0
			scope:actor = { is_at_war = yes }
		}
	}
}

#Get Monastic Order to spread tenet
#By Mother Superior Jasonetta Cantalini
monastic_espouse_beliefs_interaction = {
	category = interaction_category_religion
	icon = devoted
	filter_tags = { holy_order }
	common_interaction = yes
	use_diplomatic_range = no

	desc = monastic_espouse_beliefs_interaction_desc

	is_available = {
		can_have_theological_agent_puppet_trigger = yes
	}

	is_shown = {
		scope:recipient = {
			faith = scope:puppet_or_actor.faith
			this != scope:puppet_or_actor
			government_has_flag = government_is_monastic_holy_order
			exists = holy_order
			exists = holy_order.order_tenet
		}
	}

	cooldown = { years = 1 }

	is_valid_showing_failures_only = {
		scope:actor = {
			is_incapable = no
		}
		scope:recipient = {
			custom_tooltip = {
				text = recipient_clerical_puppet_req_tt
				puppeteer ?= scope:actor
			}
			
			is_physically_able_adult = yes
			custom_tooltip = {
				text = espoused_order_beliefs_recently
				NOT = {
					has_character_flag = mon_tenet_cooldown
				}
			}
			gold >= monastic_tenet_espousing_minimum_value

			custom_tooltip = {
				text = order_espousing_targets_exist_tt
				scope:recipient.holy_order = {
					#Spread Tenet to AI characters as personal tenet
					any_leased_title = {
						OR = {
							#leases' duchies' counties
							duchy ?= {
								any_de_jure_county_holder = {
									pam_monastic_tenet_spread_target_trigger = { ORDER_LEADER = scope:recipient }
								}
							}
							#Neighboring counties to leases
							county ?= {
								any_neighboring_county = {
									holder ?= {
										pam_monastic_tenet_spread_target_trigger = { ORDER_LEADER = scope:recipient }
									}
								}
							}
						}
					}
				}
			}
		}
	}

	cost = {
		piety = {
			value = 0
			if = {
				limit = {
					scope:recipient.holy_order = {
						num_leased_titles > 1
					}
				}
				scope:recipient.holy_order = {
					every_leased_title = {
						add = {
							value = scope:actor.miniscule_piety_value
							divide = 2
						}
					}
				}
			}
		}
	}

	auto_accept = yes

	on_accept = {
		scope:recipient = {
			remove_short_term_gold = monastic_tenet_espousing_minimum_value
			hidden_effect = {
				monastic_belief_spreading_targeting_effect = yes
			}
			monastic_tenet_espousing_effect = yes
			custom_tooltip = monastic_tenet_espousing_info_tt
		}
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 180
		duchy = 36
		kingdom = 12
		empire = 12
		hegemony = 12
	}
	ai_targets = {
		ai_recipients = puppets
	}
	ai_will_do = {
		base = 10
		modifier = {
			add = scope:actor.ai_zeal
		}
		modifier = {
			scope:actor = {
				any_personal_tenet = {
					this = scope:recipient.holy_order.order_tenet
				}
			}
			add = 50
		}
		modifier = {
			add = {
				value = scope:actor.piety_level
				multiply = 10
			}
			scope:actor.piety_level > 2
		}
		modifier = {
			factor = 0
			scope:actor = {
				NOR = {
					rite = scope:recipient.rite
					any_personal_tenet = {
						this = scope:recipient.holy_order.order_tenet
					}
				}	
			}
		}
		modifier = {
			factor = 0
			#You think their tenet is bad and dumb
			exists = scope:recipient.holy_order.order_tenet
			NOR = {
				scope:puppet_or_actor = {
					any_personal_tenet = {
						this = scope:recipient.holy_order.order_tenet
					}
					any_desired_tenet = {
						selection_count = 30
						only_positive = yes
						threshold = 1
						this = scope:recipient.holy_order.order_tenet
					}
				}
			}
		}
	}
}
