﻿##########################################
# Regula Character Interactions (Powers) #
######################################################
# This file has the interactions that we can do as the Magister
# "Powers" are interactions that involve fantasy elements, such as magic, hypnotism etc
##
# Regula Power Interactions
## regula_covert_conversion_interaction - Show Book, this is the secret conversion method used before freeing the keeper of souls.
## regula_fascinare_interaction - Starts a Fascinare (Charm) scheme against the target female. Hypnotise into a willing servant! This scheme can also be used by AI.
## regula_make_paelex_interaction - Turn a landed Mulsa into a Paelex. They will marry you (leaving their husband if they have one) and you get a free Mutare Corpus event to improve them.
## regula_retire_paelex_interaction - A more graceful way of removing a Paelex, they will be "retired", which lets them abdicate for their heir. Can also be done on Mulsa
## regula_astringere_interaction - Establish "hooks" over a target female, turning them into a puppet. Gives you a strong hook and also stresses the target.
## regula_astringere_activation_interaction - Given a puppet female, give yourself a hook on them, if you dont have one.
## regula_astringere_removal_interaction - Take away control of a puppet female, making her lose the trait and your strong (puppet) hook on her.
## regula_mutare_corpus_interaction - Improve a charmed female. Multiple choices, can increase traits, heal her mentally or physically and/or make her pregnant.
## regula_exhaurire_vitale_interaction - Drain piety from a charmed female target, or spend piety to take traits or years of life (+health) from target. 
## regula_sanctifica_serva_interaction - Turn a charmed female into an Avatar. Greatly increases stats and turns them into an immortal being.
## regula_curo_privignos_interaction - This adds special interactions you can have with stepchildren (Children born before you made their mother a Paelex). Interactions include, but are not limited to: adding the stepchild to your dynasty, forcing them join a convent, having them killed, etc. A new trait is also added called Magistri Privignos (Stepchild of the Master). It gives small buffs. Similar, but weaker than Child of the Book. -Added by CashinCheckin
## regula_beguile_interaction - An interaction that lets you travel to a landed female (charmed or non-charmed) so that you can Beguile them, engaging in a event that allows you to "duel" them for 
######################################################

# Show Book (Secret Conversion)
regula_covert_conversion_interaction = {
	category = interaction_category_religion
	common_interaction = yes

	interface_priority = 20

	ai_maybe = yes
	ai_min_reply_days = 7
	ai_max_reply_days = 14
	can_send_despite_rejection = yes
	ai_accept_negotiation = yes
	popup_on_receive = yes

	desc = {
		desc = regula_covert_conversion_interaction_desc
		desc = line_break
		triggered_desc = {
			trigger = {
				NOT = { scope:recipient = { is_imprisoned_by = scope:actor } }
			}
			desc = might_ask_for_something_in_return_warning
		}
	}

	is_shown = {
		scope:actor = {
			is_ai = no
			any_secret = {
				secret_type = regula_covert_conversion
			}
		}

		# We can show the book to
		# - Family members (including all consorts)
		# - Vassals
		# - Our Liege
		# - People in our court (or guest)
		# - Special relationship (eg friend)
		scope:recipient = {
			# Only adult females can be charmed (and cant be in prison)
			is_male = no
			is_adult = yes
			is_imprisoned = no

			OR = {
				# Family Members and consorts
				is_close_or_extended_family_of = scope:actor
				is_consort_of = scope:actor
				
				# Vassal/Liege
				is_vassal_or_below_of = scope:actor
				is_liege_or_above_of = scope:actor

				# Courtier/Guest
				is_in_the_same_court_as_or_guest = scope:actor

				# Special relationsips
				has_relation_friend = scope:actor
				has_relation_best_friend = scope:actor
				has_relation_lover = scope:actor
				has_relation_soulmate = scope:actor
			}
		}
	}

	is_valid = {
		NOT = { scope:recipient = scope:actor }
	}

	is_valid_showing_failures_only = {
		scope:recipient = {
			custom_description = {
				text = regula_already_spellbound_trigger
				NOT = {
					any_secret = {
						secret_type = regula_covert_conversion
					}
				}
			}
		}
	}

	cost = {
		prestige = 50
	}

	on_decline_summary = stop_attacker_vassal_war_decline_summary

	cooldown_against_recipient = { months = 6 }

	auto_accept = {
		# Use trigger statements as otherwise custom description (tooltip) won't work
		trigger_if = {
			limit = {
				scope:recipient = {
					is_spouse_of = scope:actor
					is_ai = yes
				}
			}
			custom_description = {
				text = "recipient_is_spouse"
				subject = scope:actor
				object = scope:recipient
			}
		}
		trigger_else = {
			custom_description = {
				text = "spending_hook"
				subject = scope:actor
				object = scope:recipient
				scope:hook = yes
			}
		}
	}


	redirect = {
		scope:recipient = {
			save_scope_as = target
		}
	}

	on_accept = {
		custom_tooltip = regula_covert_conversion_interaction_tooltip
		scope:actor = {
			if = {
				limit = {
					primary_spouse = scope:recipient
				}
				trigger_event = {
					id = regula_initialize_event.0004
				}
			}
			else = {
				trigger_event = {
					id = regula_initialize_event.0005
				}
			}
		}
	}

	on_decline = {
		scope:recipient = {
			hidden_effect = {
				random_list = {
					80 = { # They ask for gold.
						ai_value_modifier = {
							ai_greed = 0.5
						}
						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:actor = {
							if = {
								limit = {
									scope:recipient.primary_spouse = scope:actor
								}
								trigger_event = {
									id = regula_initialize_event.0004
								}
							}
							else = {
								trigger_event = {
									id = regula_initialize_event.0006
								}
							}
						}
					}
					20 = { # Full refuse
						modifier = {
							add = 10
							has_trait = impatient
						}
						modifier = {
							add = 20
							has_trait = shy
						}
						modifier = {
							add = 20
							has_trait = reclusive
						}
						modifier = {
							add = 10
							has_trait = lazy
						}
						scope:actor = {
							trigger_event = {
								id = regula_initialize_event.0007
							}
						}
					}
					5 = { # They sound the alarm
						modifier = {
							add = 10
							has_trait = deceitful
						}
						modifier = {
							add = 10
							has_trait = paranoid
						}
						modifier = {
							add = 10
							has_trait = celibate
						}
						modifier = {
							add = 25
							has_trait = crusader_king
						}
						scope:actor = {
							random_secret = {
								limit = {
									secret_owner = scope:actor
									secret_type = regula_covert_conversion
								}
								expose_secret = scope:recipient
							}
						}
					}
				}
			}
			custom_tooltip = regula_covert_conversion_interaction_failure
			show_as_tooltip = {
				#Negative opinions
				add_opinion = {
					target = scope:actor
					modifier = regula_covert_conversion_interaction_failure_opinion
				}
			}
		}
	}

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

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

	send_options_exclusive = no

	ai_will_do = {
		base = 0
	}

	ai_accept = {
		base = 25

		#Diplomacy based
		compare_modifier = {
			desc = "sway_my_diplomacy"
			target = scope:actor
			value = diplomacy
			multiplier = 4
		}

		modifier = {
			desc = "SCHEME_SCHEMER_TRAIT"
			scope:actor = { has_trait = seducer }
			add = 25
		}

		#Beauty good
		modifier = {
			desc = "scheme_beauty_good_1"
			scope:actor = { has_trait = beauty_good_1 }
			add = 10
		}
		modifier = {
			desc = "scheme_beauty_good_2"
			scope:actor = { has_trait = beauty_good_2 }
			add = 15
		}
		modifier = {
			desc = "scheme_beauty_good_3"
			scope:actor = { has_trait = beauty_good_3 }
			add = 20
		}

		#Physique good
		modifier = {
			desc = "scheme_physique_good_1"
			scope:actor = { has_trait = physique_good_1 }
			add = 5
		}
		modifier = {
			desc = "scheme_physique_good_2"
			scope:actor = { has_trait = physique_good_2 }
			add = 10
		}
		modifier = {
			desc = "scheme_physique_good_3"
			scope:actor = { has_trait = physique_good_3 }
			add = 15
		}

		#Beauty bad
		modifier = {
			desc = "scheme_beauty_bad_1"
			scope:actor = { has_trait = beauty_bad_1 }
			add = -10
		}
		modifier = {
			desc = "scheme_beauty_bad_2"
			scope:actor = { has_trait = beauty_bad_2 }
			add = -15
		}
		modifier = {
			desc = "scheme_beauty_bad_3"
			scope:actor = { has_trait = beauty_bad_3 }
			add = -20
		}

		modifier = {
			desc = "SCHEME_BEFRIEND_MY_GREGARIOUSNESS"
			scope:actor = { has_trait = gregarious }
			add = 25
		}

		#Sexuality
		modifier = {
			desc = "SCHEME_SEDUCE_WRONG_GENDER"
			scope:actor = {
				NOR = {
					is_attracted_to_gender_of = scope:recipient
					has_perk = unshackled_lust_perk # Removed by the Unshackled Lust Perk
				}
			}
			add = -25
		}


		#TARGET#
		#Lustful/hedonist
		modifier = {
			desc = "SCHEME_REVELER"
			scope:recipient = { has_trait = lifestyle_reveler }
			add = 15
		}
		modifier = {
			desc = "SCHEME_LUSTFUL_TRAIT"
			scope:recipient = { has_trait = lustful }
			add = 30
		}
		modifier = {
			desc = "REGULA_SCHEME_SEDUCER_TRAIT"
			scope:recipient = { has_trait = seducer }
			add = 50
		}

		modifier = {
			desc = "SCHEME_BEFRIEND_THEIR_GREGARIOUSNESS"
			scope:actor = { has_trait = gregarious }
			add = 50
		}


		#Chaste/shy
		modifier = {
			desc = "SCHEME_CHASTE_TRAIT"
			scope:recipient = { has_trait = chaste }
			add = -10
		}
		modifier = {
			desc = "SCHEME_SHY_TRAIT"
			scope:recipient = { has_trait = shy }
			add = -20
		}
		modifier = {
			desc = "REGULA_SCHEME_RECLUSIVE_TRAIT"
			scope:recipient = { has_trait = reclusive }
			add = 50
		}


		#Opinion of actor
		opinion_modifier = {
			desc = regula_covert_conversion_interaction_their_opinion
			who = scope:recipient
			opinion_target = scope:actor
			min = -25
			max = 25
			multiplier = 0.75
		}

		#Target is actor's spouse
		modifier = { #
			trigger = { scope:actor = { is_consort_of = scope:recipient } }
			scope:recipient = {
				NOT = { has_relation_rival = scope:actor }
			}
			add = 25
			desc = "AI_YOUR_SPOUSE"
		}
		#Target is actor's lover/soulmate.
		modifier = {
			add = 50
			OR = {
				has_relation_lover = scope:actor
				has_relation_soulmate = scope:actor
			}
			desc = "AI_YOUR_LOVER"
		}
		#Target is actor's friend/best friend.
		modifier = {
			add = 25
			OR = {
				has_relation_friend = scope:actor
				has_relation_best_friend = scope:actor
			}
			desc = "AI_YOUR_FRIEND"
		}
		#Target is actor's rival/nemesis.
		modifier = {
			add = -50
			OR = {
				has_relation_rival = scope:recipient
				has_relation_nemesis = scope:recipient
			}
			has_relation_rival = scope:recipient
			desc = "AI_YOUR_RIVAL"
		}
		#Trait similarity to actor
		compatibility_modifier = {
			who = scope:recipient
			compatibility_target = scope:actor
			min = -15
			max = 30
			multiplier = 2
		}

		#Rank tier difference (landed target/target whose liege doesn't care)
		modifier = { #3 or more higher rank
			trigger = { scope:actor = { NOT = { is_consort_of = scope:recipient } } } # Your spouse doesn't care if you're a different rank than them.
			add = 40
			desc = "HIGHER_RANK_THAN_SCHEME_TARGET"
			scope:recipient = {
				personal_scheme_success_compare_target_liege_tier_trigger = no
				NOT = {
					is_theocratic_lessee = yes
				}
			}
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value >= 3
				}
			}
		}
		modifier = { #2 higher rank
			trigger = { scope:actor = { NOT = { is_consort_of = scope:recipient } } } # Your spouse doesn't care if you're a different rank than them.
			add = 20
			desc = "HIGHER_RANK_THAN_SCHEME_TARGET"
			scope:recipient = {
				personal_scheme_success_compare_target_liege_tier_trigger = no
				NOT = {
					is_theocratic_lessee = yes
				}
			}
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = 2
				}
			}
		}
		modifier = { #1 higher rank
			trigger = { scope:actor = { NOT = { is_consort_of = scope:recipient } } } # Your spouse doesn't care if you're a different rank than them.
			add = 10
			desc = "HIGHER_RANK_THAN_SCHEME_TARGET"
			scope:recipient = {
				personal_scheme_success_compare_target_liege_tier_trigger = no
				NOT = {
					is_theocratic_lessee = yes
				}
			}
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = 1
				}
			}
		}

		#Extra rank bonus/penalty if target is arrogant/ambitious
		modifier = {
			trigger = { scope:actor = { NOT = { is_consort_of = scope:recipient } } } # No 'social climbing' if you're already their spouse!
			desc = SCHEME_SOCIAL_CLIMBER_RANK_BONUS
			add = 20
			scope:recipient = {
				OR = {
					has_trait = arrogant
					has_trait = ambitious
					has_trait = greedy
				}
				NOT = {
					is_theocratic_lessee = yes
				}
			}
			OR = {
				AND = {
					scope:recipient = { personal_scheme_success_compare_target_liege_tier_trigger = yes }
					scope:actor.highest_held_title_tier > scope:recipient.liege.highest_held_title_tier
				}
				AND = {
					scope:recipient = { personal_scheme_success_compare_target_liege_tier_trigger = no }
					scope:actor.highest_held_title_tier > scope:recipient.highest_held_title_tier
				}
			}
		}
		modifier = {
			trigger = { scope:actor = { NOT = { is_consort_of = scope:recipient } } } # No 'social climbing' if you're already their spouse!
			desc = regula_covert_conversion_interaction_social_climber_rank_penalty
			add = -10
			scope:recipient = {
				OR = {
					has_trait = arrogant
					has_trait = ambitious
					has_trait = greedy
				}
			}
			OR = {
				AND = {
					scope:recipient = { personal_scheme_success_compare_target_liege_tier_trigger = yes }
					scope:actor.highest_held_title_tier < scope:recipient.liege.highest_held_title_tier
				}
				AND = {
					scope:recipient = { personal_scheme_success_compare_target_liege_tier_trigger = no }
					scope:actor.highest_held_title_tier < scope:recipient.highest_held_title_tier
				}
			}
		}

		# Dynasty Kin Personal Scheme Success Chance on Dynasty Perk
		modifier = {
			add = kin_legacy_4_success_chance
			desc = KIN_LEGACY_DESC
			exists = scope:actor.dynasty
			scope:actor.dynasty = {
				has_dynasty_perk = kin_legacy_4
			}
			scope:recipient.dynasty = scope:actor.dynasty
		}

		# Thicker Than Water Perk
		modifier = {
			add = thicker_than_water_bonus
			desc = BEFRIEND_THICKER_THAN_WATER_PERK_DESC
			scope:actor = {
				has_perk = thicker_than_water_perk
			}
			scope:recipient = {
				is_close_or_extended_family_of = scope:actor
			}
		}

		modifier = {
			desc = might_ask_for_something_in_return_warning_line_break
			add = 0
		}
	}
}

# Start fascinare scheme.
# Now also used by AI characters to Charm on behalf of Magister
regula_fascinare_interaction = {
	icon = regula_fascinare_interaction
	category = interaction_category_religion
	interface_priority = 150
	scheme = regula_fascinare

	desc = regula_fascinare_interaction_desc
	send_name = START_SCHEME
	ignores_pending_interaction_block = yes
	
	cost = {
		piety = regula_fascinare_cost
	}

	# AI
	# Focus on targetting family, then court then vassals
	ai_targets = {
		ai_recipients = family
		ai_recipients = dynasty
		max = 10
	}

	ai_targets = {
		ai_recipients = guests
		ai_recipients = courtiers
		max = 10

	}

	ai_targets = {
		ai_recipients = vassals
		ai_recipients = peer_vassals
		max = 5
	}

	# Consider a few neighbouring rulers
	ai_targets = {
		ai_recipients = neighboring_rulers
		max = 3
	}
	# We don't want this to grow ludicrously large in big realms
	ai_targets = {
		ai_recipients = realm_characters
		max = 10
	}
	ai_target_quick_trigger = {
		adult = yes
	}
	ai_frequency = 12

	ai_potential = {
		is_adult = yes
		is_regula_leader_devoted_trigger = yes
	}

	ai_will_do = {
		base = 5
		
		modifier = {
			add = 50
			scope:actor = {
				has_focus = intrigue_temptation_focus
			}
		}
		
		modifier = {
			add = 25
			exists = scope:actor.dynasty
			scope:actor.dynasty = {
				has_dynasty_perk = fp1_adventure_legacy_2
			}
		}
		
		modifier = {
			add = 30
			scope:actor = {
				has_trait = lustful
			}
		}

		modifier = { # ( ͡° ͜ʖ ͡°)
			add = 30
			is_deviant_trigger = yes
		}
		
		modifier = {
			add = 25
			scope:actor = {
				is_close_or_extended_family_of = scope:recipient
			}
		}
		
		modifier = { # Charming the spouse of your rival is good drama...
			add = 25
			scope:recipient = {
				exists = primary_spouse
				primary_spouse = {
					OR = {
						has_relation_rival = scope:actor
						has_relation_nemesis = scope:actor
					}
				}
			}
		}

		modifier = {
			factor = 1.25
			scope:recipient = {
				number_of_personality_traits_in_common = {
					target = scope:actor
					value >= 1
				}
			}
		}

		modifier = {
			factor = 1.5
			scope:recipient = {
				number_of_personality_traits_in_common = {
					target = scope:actor
					value >= 2
				}
			}
		}

		modifier = {
			factor = 2
			scope:recipient = {
				number_of_personality_traits_in_common = {
					target = scope:actor
					value >= 3
				}
			}
		}

		modifier = {
			factor = 1.5
			scope:recipient = {
				is_playable_character = yes
			}
		}

		modifier = {
			factor = 1.25
			scope:recipient = {
				OR = {
					has_trait = lustful
					has_trait = beauty_good
					has_trait = physique_good
					has_trait = fecund
					has_trait = pure_blooded
				}
			}
		}

		modifier = {
			factor = 0.75
			scope:recipient = {
				is_lowborn = yes
			}
		}
		
		modifier = {
			factor = 0.2
			scope:recipient = {
				is_ai = yes
				any_targeting_scheme = {
					scheme_type = regula_fascinare
				}
			}
		}
		
		modifier = { #
			factor = 0.1
			scope:recipient = {
				is_ai = yes
				has_trait = chaste
			}
		}

		modifier = { # Family Feud
			add = 50
			exists = scope:actor.house
			exists = scope:recipient.primary_spouse.house
			scope:actor = {
				house.house_head = {
					any_owned_story = {
						story_type = story_cycle_house_feud
						has_variable = house_feud_house
						var:house_feud_house = scope:recipient.primary_spouse.house
					}
				}
				has_opinion_modifier = {
					modifier = house_feud_opinion
					target = scope:recipient.primary_spouse.house.house_head
				}
			}
		}
	}

	is_shown = {
		NOT = { scope:actor = scope:recipient }
		scope:actor = {
			OR = {
				has_trait = magister_trait_group    # Player must be Magister
				# Or a Leader Devoted with Fascinare holy site effect
				AND = {
					is_regula_leader_devoted_trigger = yes
					character_has_regula_holy_effect_mulsa_fascinare = yes
				}
			}
		}
		scope:recipient = {
			is_adult = yes
			is_male = no
			is_regula_devoted_trigger = no
			is_imprisoned = no
		}
	}

	is_valid = {
		scope:actor = {
			OR = {
				has_trait = magister_trait_group    # Player must be Magister
				# Or a Leader Devoted with Fascinare holy site effect
				AND = {
					is_regula_leader_devoted_trigger = yes
					character_has_regula_holy_effect_mulsa_fascinare = yes
				}
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			custom_description = {
				text = magister_trait_2_required_trigger
				NOT = { has_trait = magister_1 }
			}
			NOT = { is_at_war_with = scope:recipient }
			can_start_scheme = {
				type = regula_fascinare
				target_character = scope:recipient
			}
		}
		# Limit range for landless adventurers
		trigger_if = {
			limit = {
				scope:actor = {
					is_landless_adventurer = yes
				}
			}
			#Has to be used instead of diplo range checks in laamp to landed interactions
			ep3_laamp_diplo_range_trigger = {
				TARGET = scope:recipient
				LAAMP = scope:actor
			}
		}
	}

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

				left_icon = scope:actor					
				right_icon = scope:recipient

				begin_scheme_basic_effect = {
					SCHEME_TYPE = regula_fascinare
					TARGET_TYPE = target_character
					TARGET_SCOPE = scope:recipient
				}

				# seduce_interaction_stress_effect = yes
			}
		}
	}
	
	auto_accept = yes
}

# Make landed Mulsa a Paelex.
regula_make_paelex_interaction = {
	category = interaction_category_vassal
	common_interaction = yes
	desc = regula_make_paelex_interaction_desc
	interface_priority = 20

	is_shown = {
		scope:actor = {
			has_trait = magister_trait_group
		}
		scope:recipient = {
			is_ai = yes
			# Basic charmed characters can be turned into a Paelex (or Famili Paelex/Domina)
			OR = {
				has_trait = mulsa
				has_trait = tropaeum
			}
			OR = {
			is_vassal_or_below_of = scope:actor
			is_independent_ruler = yes
			}
			NOT = { scope:recipient = scope:actor }

			# Check consanguinity doctrine
			NOT = {
				relation_with_character_is_incestuous_in_faith_trigger = {
					FAITH = scope:recipient.faith
					CHARACTER = scope:actor
				}
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:recipient = {
			highest_held_title_tier >= tier_county
			is_imprisoned = no #Will make alternate event for this.
		}
	}

	auto_accept = yes

	on_accept = {
		regula_make_paelex_interaction_effect = yes
	}

	ai_will_do = {
		base = 0
	}
}

# Retire a Paelex/Domina
# Also works on any Famuli (so including a mulsa or tropaeum)
regula_retire_paelex_interaction = {
	category = interaction_category_vassal
	common_interaction = no
	desc = regula_retire_paelex_interaction_desc
	interface_priority = 100

	use_diplomatic_range = yes
	ignores_pending_interaction_block = yes

	# Only show if we are Magister
	# And the target is a valid famuli
	is_shown = {
		scope:actor = {
			has_trait = magister_trait_group
		}
		scope:recipient = {
			is_ai = yes
			is_regula_devoted_trigger = yes
			NOT = { has_trait = regula_undying }
			is_vassal_or_below_of = scope:actor
			is_adult = yes
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			NOT = { is_at_war_with = scope:recipient }
		}
		scope:recipient = {
			is_busy_in_events_localised = yes
		}
	}

	send_options_exclusive = no
	send_option = {
		is_valid = {
			scope:actor = {
				custom_description = {
					text = magister_trait_4_required_trigger
					has_trait_rank = {
						trait = magister_trait_group
						rank >= 4
					}
				}
			}
			scope:recipient = {
				is_vassal_of = scope:actor
			}
		}
		flag = revoke_titles
		localization = regula_retire_paelex_interaction_revoke_titles
	}

	# They have to have a female primary heir
	can_send = {
		custom_tooltip = {
			text = regula_retire_paelex_interaction_no_heir_trigger
			OR = {
				scope:revoke_titles = yes
				trigger_if = {
					limit = {
						exists = scope:recipient.primary_heir
					}
					scope:recipient.primary_heir = {
						is_female = yes
					}
				}
			}
		}
	}

	cost = {
		piety = {
			value = regula_famuli_retire_base_cost

			# Add titles if option selected
			if = {
				limit = { scope:revoke_titles = yes }
				add = regula_retire_famuli_revoke_titles_cost
			}

			# Apply discount multiplier
			add = regula_famuli_retire_cost_discount_cost
		}
	}

	auto_accept = yes

	on_accept = {

		scope:recipient = {
			if = {
				limit = { is_consort_of = scope:actor }
				divorce = scope:actor
			}
			remove_trait = mulsa
			remove_trait = tropaeum
			remove_trait = domina
			remove_trait = familia_paelex
			remove_trait = paelex
			add_trait_force_tooltip = retired_paelex
		}

		if = {
			limit = { scope:revoke_titles = yes }
			create_title_and_vassal_change = {
				type = revoked
				save_scope_as = change
			}
			scope:recipient = {
				every_held_title = {
					limit = {
						tier >= tier_county
					}
					change_title_holder_include_vassals = {
						holder = scope:actor
						change = scope:change
					}
				}
			}
			resolve_title_and_vassal_change = scope:change
			scope:recipient = {
				every_traveling_family_member = {
					scope:actor = { add_courtier = prev }
					hidden_effect = {
						return_to_court = yes
					}
				}
			}
		}
		else = {
			scope:recipient.primary_heir = {
				save_scope_as = new_ruler
			}

			scope:recipient = {
				depose = yes
			}

			scope:new_ruler = {
				appoint_court_position = {
					recipient = scope:recipient
					court_position = retired_paelex_court_position
				}
			}
		}
	}

	ai_will_do = {
		base = 0
	}
}

# Turn target into puppet
regula_astringere_interaction = {
	category = interaction_category_hostile
	common_interaction = no
	interface_priority = 90

	desc = regula_astringere_interaction_desc

	cost = {
		piety = 150
	}
	is_shown = {
		scope:recipient = {
			has_trait = devoted_trait_group
			NOT = { has_trait = sigillum }
			is_imprisoned = no # Alternate event for Magister's captives.
		}
		scope:actor = {
			has_trait = magister_trait_group
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			custom_description = {
				text = magister_trait_3_required_trigger
				has_trait_rank = {
					trait = magister_trait_group
					rank >= 3
				}
			}
		}
	}

	auto_accept = yes

	on_accept = {
		show_as_tooltip = {
			scope:recipient = {
				add_trait = sigillum
				add_stress = medium_stress_gain
			}
			scope:actor = {
				add_hook = {
					target = scope:recipient
					type = regula_sigillum_hook
				}
				add_tyranny = 3
				add_dread = 5
			}
		}
		scope:actor = {
			trigger_event = {
				id = regula_astringere_outcome_event.1001
				days = { 7 14 }
			}
		}
	}

	ai_will_do = {
		base = 0
	}
}

# Add a strong hook to a puppeted target
regula_astringere_activation_interaction = {
	category = interaction_category_hostile
	common_interaction = no
	interface_priority = 91
	icon = hook_strong

	desc = regula_astringere_activation_interaction_desc

	is_shown = {
		scope:recipient = {
			has_trait = devoted_trait_group
			has_trait = sigillum
			OR = {
				is_imprisoned = no
				is_imprisoned_by = scope:actor
			}
		}
		scope:actor = {
			has_trait = magister_trait_group
			NOT = { has_strong_usable_hook = scope:recipient }
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			custom_description = {
				text = magister_trait_4_required_trigger
				has_trait_rank = {
					trait = magister_trait_group
					rank >= 4
				}
			}
		}
	}

	auto_accept = yes

	on_accept = {
		# Target gains stress
		scope:recipient = {
			add_stress = medium_stress_gain
		}
		# We remove the hook and re-add it, not sure if you can force "refresh" a hook
		scope:actor = {
			hidden_effect = {
				remove_hook = {
					target = scope:recipient
					type = regula_sigillum_hook
				}
			}
			add_hook_no_toast = {
				target = scope:recipient
				type = regula_sigillum_hook
			}
		}
	}

	ai_will_do = {
		base = 0
	}
}

# Remove control over puppet
regula_astringere_removal_interaction = {
	category = interaction_category_hostile
	common_interaction = no
	interface_priority = 92
	icon = religious

	desc = regula_astringere_removal_interaction_desc

	is_shown = {
		scope:recipient = {
			has_trait = devoted_trait_group
			has_trait = sigillum
			OR = {
				is_imprisoned = no # Alternate event for Magister's captives.
				is_imprisoned_by = scope:actor
			}
		}
		scope:actor = {
			has_trait = magister_trait_group
		}
	}

	auto_accept = yes

	on_accept = {
		scope:recipient = {
			remove_trait = sigillum
			add_stress = minor_stress_loss
		}
		scope:actor = {
			remove_hook = {
				target = scope:recipient
				type = regula_sigillum_hook
			}
			add_piety = 75
		}
	}

	ai_will_do = {
		base = 0
	}
}

############################
# Mutare Corpus Interactions
############################

# Spend piety to improve your devoted
# Standard version with three year cooldown
regula_mutare_corpus_interaction = {
	category = interaction_category_religion
	common_interaction = yes
	desc = regula_mutare_corpus_interaction_desc
	interface_priority = 21
	icon = icon_personal

	cooldown_against_recipient = { years = 3 }

	is_shown = {
		scope:actor = {
			has_trait = magister_trait_group
			dynasty ?= {
				NOT = { has_dynasty_perk = regula_legacy_4 }
			}
		}
		scope:recipient = {
			is_ai = yes
			has_trait = devoted_trait_group
		}
	}

	auto_accept = yes

	on_accept = {
		scope:actor = {
			trigger_event = {
				id = regula_mutare_corpus_event.0001
			}
		}
		scope:recipient = {
			custom_tooltip = regula_mutare_corpus_interaction_tooltip
		}
	}

	cost = {
		piety = regula_mutare_corpus_interaction_piety_cost
	}

	ai_will_do = {
		base = 0
	}
}

# Spend piety to improve your devoted
# This is the no cooldown version
regula_mutare_corpus_no_cooldown_interaction = {
	category = interaction_category_religion
	common_interaction = yes
	desc = regula_mutare_corpus_interaction_desc
	interface_priority = 21
	icon = icon_personal

	is_shown = {
		scope:actor = {
			has_trait = magister_trait_group
			dynasty ?= {
				has_dynasty_perk = regula_legacy_4
			}
		}
		scope:recipient = {
			is_ai = yes
			has_trait = devoted_trait_group
		}
	}

	auto_accept = yes

	on_accept = {
		scope:actor = {
			trigger_event = {
				id = regula_mutare_corpus_event.0001
			}
		}
		scope:recipient = {
			custom_tooltip = regula_mutare_corpus_interaction_tooltip
		}
	}

	cost = {
		piety = regula_mutare_corpus_interaction_piety_cost
	}

	ai_will_do = {
		base = 0
	}
}

# Spend piety to improve your devoted (cosmetic effects only)
regula_mutare_corpus_cosmetic_interaction = {
	category = interaction_category_religion
	common_interaction = yes
	desc = regula_mutare_corpus_cosmetic_interaction_desc
	interface_priority = 21
	icon = icon_personal

	is_shown = {
		scope:actor = {
			has_trait = magister_trait_group
		}
		scope:recipient = {
			is_ai = yes
			has_trait = devoted_trait_group
		}
		has_game_rule = carn_dt_enabled
	}

	auto_accept = yes

	on_accept = {
		scope:actor = {
			trigger_event = {
				id = regula_mutare_corpus_event.0002
			}
		}
		scope:recipient = {
			custom_tooltip = regula_mutare_corpus_cosmetic_interaction_tooltip
		}
	}

	cost = {
		piety = regula_mutare_corpus_cosmetic_interaction_piety_cost
	}

	ai_will_do = {
		base = 0
	}
}

############################

# Drain life from your devoted
regula_exhaurire_vitale_interaction = {
	category = interaction_category_religion
	common_interaction = yes
	desc = regula_exhaurire_vitale_interaction_desc
	interface_priority = 21
	icon = religious

	cooldown = { years = 2 }

	is_shown = {
		scope:actor = {
			has_trait = magister_trait_group
		}
		scope:recipient = {
			is_ai = yes
			has_trait = devoted_trait_group
		}
	}

	on_accept = {
		scope:actor = {
			trigger_event = {
				id = regula_exhaurire_vitale_event.0001
			}
		}
		scope:recipient = {
			custom_tooltip = regula_exhaurire_vitale_interaction_tooltip
		}
	}

	auto_accept = yes

	ai_will_do = {
		base = 0
	}
}

### Create Avatar
regula_sanctifica_serva_interaction = {
	category = interaction_category_religion
	common_interaction = no
	desc = regula_sanctifica_serva_interaction_desc
	interface_priority = 20

	is_shown = {
		scope:actor = {
			has_trait = magister_trait_group
			character_has_regula_holy_effect_sanctifica_serva = yes
		}
		scope:recipient = {
			NOT = { has_trait = regula_undying }
		}
	}

	is_valid_showing_failures_only = {
		scope:recipient = {
			is_pregnant = no
			is_available = yes
			is_regula_leader_devoted_trigger = yes
			NOT = { has_trait = regula_undying }
		}
		scope:actor = {
			is_available = yes
			custom_description = {
				text = magister_trait_6_required_trigger
				has_trait_rank = {
					trait = magister_trait_group
					rank >= 6
				}
			}
			custom_description = {
				text = sanctifica_serva_health_trigger
				health >= 3
			}
			custom_description = {
				text = sanctifica_serva_in_progress_trigger
				NOT = { has_variable = regula_sanctifica_serva_in_progress }
			}
		}
	}

	auto_accept = yes

	cost = {
		piety  = regula_sanctifica_serva_interaction_piety_cost
		prestige = regula_sanctifica_serva_interaction_prestige_cost
	}

	on_accept = {
		show_as_tooltip = {
			scope:recipient = {
				regula_turn_character_into_one_with_book = yes
			}
			scope:actor = {
				add_character_modifier = {
					modifier = regula_sanctifica_serva_penalty
					years = 5
				}
			}
		}

		custom_tooltip = regula_sanctifica_serva_interaction_tooltip
		scope:actor = {
			set_variable = regula_sanctifica_serva_in_progress
			trigger_event = regula_holy_site_event.1001
		}
	}
	ai_will_do = {
		base = 0
	}
}

#Curo Privignos - Manage Stepchildren - Stepchild interaction
regula_curo_privignos_interaction = {
	category = interaction_category_friendly
	common_interaction = no
	desc = regula_curo_privignos_interaction_desc
	interface_priority = 21

	is_shown = {
		NOT = { scope:actor = scope:recipient }
		scope:actor = {
			has_trait = magister_trait_group
		}
		scope:recipient = {
			character_is_valid_curo_privignos_target_trigger = {
				ACTOR = scope:actor
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:recipient = {
			is_imprisoned = no
		}
		scope:recipient = {
			character_is_valid_curo_privignos_target_show_failures_trigger = {
				ACTOR = scope:actor
			}
		}
	}

	auto_accept = yes

	on_accept = {
		scope:recipient = {
			custom_tooltip = regula_curo_privignos_interaction_tooltip
		}
		scope:actor = {
			trigger_event = {
					id = regula_curo_privignos_event.0001
				}
		}
	}
}

# Beguile a character into giving you stuff
# Similar to Beguile Intent
regula_beguile_interaction = {
	category = interaction_category_diplomacy
	common_interaction = no
	desc = regula_beguile_interaction_desc

	cooldown_against_recipient = { years = 3 }
	
	is_shown = {
		NOT = { scope:recipient = scope:actor }
		scope:actor = {
			has_trait = magister_trait_group
		}
		scope:recipient = {
			is_ai = yes
			is_adult = yes
			is_male = no
			is_landed = yes
			highest_held_title_tier > tier_barony
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			is_travelling = no
		}
		scope:recipient = {
			is_imprisoned = no
			is_travelling = no
		}
	}

	on_accept = {
		scope:recipient = {
			custom_tooltip = regula_beguile_interaction_tooltip
		}
		if = {
			limit = { 
				scope:actor = {
					is_at_same_location = scope:recipient
				}
			}
			scope:actor = {
				trigger_event = regula_decipere_interaction_events.0001
			}
		}
		else = {
			scope:actor = {
				start_travel_plan = {
					destination = scope:recipient.capital_province
					on_arrival_event = regula_decipere_interaction_events.0001
					on_arrival_destinations = all_but_last
					on_travel_planner_cancel_event = regula_decipere_interaction_events.0002
				}
			}
		}
	}

	cost = {
		prestige = regula_beguile_interaction_prestige_cost
	}

	auto_accept = yes
}