﻿#########################################
# Regula Character Interactions (Court) #
######################################################
# This file has the interactions that we can do as the Magister
# "Court" interactions are those that mainly reolve around political actions, and aren't too "magical" in nature
##
# Regula Court Interactions
## regula_bestow_titles_interaction - Alternate way to give/setup landed titles for charmed female vassals during "Secret" phase of Regula religion (Before freeing keeper of souls).
## regula_titulum_novis_interaction - Alternate way to revoke titles from charmed female vassals. Costs piety but does not upset the vassal losing the title.
## regula_docere_cultura_interaction - Make a charmed vassal change her domain culture into the Magisters culture
## regula_summon_to_court_interaction - Summon a charmed courtier to your court.
## regula_break_betrothal_courtier_interaction - Force a charmed courtier to break their betrothal.
## regula_divorce_spouse_interaction - Force a charmed women to divorce their husband.
## regula_forge_inheritance_law_interaction - Change the inheritance law for a male vassal to prefer female heirs. Used during "Secret" phase of Regula religion.
## regula_form_alliance_interaction - Form an alliance with a charmed female ruler.
## regula_potestas_non_transfunde_interaction - Vassalise a foreign charmed female ruler, remember their primary title must be lower then yours!
## regula_join_servitude_war_interaction - Join an ongoing servitude war.
## regula_enact_abice_maritus_interaction - Make the charmed wife of a male vassal take her husbands titles. (by forcing him to abdicate and become a monk)
## regula_demand_reveal_crypto_regula_interaction - Make a charmed, crypto-regula character reveal (and convert to) their regula religion.
######################################################

# Bestow Title
regula_bestow_titles_interaction = {
	category = interaction_category_vassal
	common_interaction = yes
	desc = regula_bestow_titles_interaction_desc
	icon = grant_titles_interaction

	auto_accept = yes

	target_type = title
	target_filter = actor_domain_titles

	is_shown = {
		scope:actor = {
			is_landless_adventurer = no
			any_secret = {
				secret_type = regula_covert_conversion
			}
		}
		NOT = {
			scope:actor.faith = {
				has_dominant_ruling_gender = scope:recipient
			}
		}
		scope:recipient = {
			is_landed = no
			OR = {
				# is_vassal_or_below_of = scope:actor
				# primary_spouse = scope:actor
				liege ?= {
					OR = {
						is_vassal_or_below_of = scope:actor
						this = scope:actor
					}
				}
				AND = {
					is_in_the_same_court_as_or_guest = scope:actor
					is_imprisoned = no
				}
			}
		}
	}

	cost = {
		prestige = {
			if = {
				limit = { always = scope:swing_prestige }
				value = 150
			}
		}
		piety = {
			if = {
				limit = { always = scope:swing_piety }
				value = 100
			}
		}
		gold = {
			if = {
				limit = { always = scope:swing_gold }
				value = 50
			}
		}
	}

	# Prestige
	send_option = {
		starts_enabled = { scope:actor.prestige >= 150 }
		flag = swing_prestige
		localization = SWING_PRESTIGE
		current_description = SWING_PRESTIGE_DESC
	}
	# Piety
	send_option = {
		starts_enabled = { scope:actor.piety >= 100 }
		flag = swing_piety
		localization = SWING_PIETY
		current_description = SWING_PIETY_DESC
	}
	# Gold
	send_option = {
		starts_enabled = { scope:actor.gold >= 50 }
		flag = swing_gold
		localization = SWING_GOLD
		current_description = SWING_GOLD_DESC
	}


	can_be_picked_title = {
		scope:target = {
			custom_tooltip = {
				text = GRANT_TITLES_BECOME_INDEPENDENT
				NOT = { tier = scope:actor.primary_title.tier }
			}
			custom_tooltip = {
				text = GRANT_TITLE_CANT_GIVE_REASON_PRIMARY
				NOT = { this = scope:actor.primary_title }
			}
		}
	}

	on_accept = {
		custom_tooltip = regula_bestow_titles_interaction_tooltip

		scope:recipient = {
			create_title_and_vassal_change = {
				type = granted
				save_scope_as = change
				add_claim_on_loss = yes
			}
			scope:target = {
				change_title_holder_include_vassals = {
					holder = scope:recipient
					change = scope:change
				}
			}
			resolve_title_and_vassal_change = scope:change
			add_opinion = {
				target = scope:actor
				modifier = received_title_barony
			}
		}
	}

	ai_will_do = {
		base = 0
	}
}

# Revoke Title
regula_titulum_novis_interaction = {
	category = interaction_category_vassal
	common_interaction = yes
	notification_text = REVOKE_TITLE_PROPOSAL

	desc = regula_titulum_novis_interaction_desc

	special_interaction = revoke_title_interaction
	interface = revoke_title
	target_type = title
	target_filter = recipient_domain_titles
	can_send_despite_rejection = yes
	popup_on_receive = yes
	pause_on_receive = yes
	icon = debug_take_title

	interface_priority = 60
	ai_min_reply_days = 4
	ai_max_reply_days = 9

	# actor character revoking the titles
	# recipient character losing the titles
	auto_accept = yes

	is_shown = {
		scope:actor = {
			has_trait = magister_trait_group
		}
		scope:recipient = {
			is_landed = yes
			target_is_liege_or_above = scope:actor
			OR = {
				has_trait = retired_paelex
				has_trait = devoted_trait_group
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			NOR =  {
				is_at_war_with = scope:recipient
			}
		}
		scope:recipient = {
			OR = {
				has_trait = retired_paelex
				has_trait = devoted_trait_group
			}
			is_vassal_of = scope:actor
			is_busy_in_events_localised = yes
		}
		scope:actor = {
			custom_description = {
				text = magister_trait_4_required_trigger
				has_trait_rank = {
					trait = magister_trait_group
					rank >= 4
				}
			}
		}
	}

	can_send = {
		scope:actor = {
			custom_description = {
				text = "character_interactions_hostile_actions_disabled_delay"
				NOT = { has_character_flag = flag_hostile_actions_disabled_delay }
			}
		}
	}

	# Highlighted in the interaction menu when right-clicking a character
	is_highlighted = {
		OR = {
			scope:actor = {
				has_revoke_title_reason = scope:recipient
			}
			scope:recipient = {
					any_held_title = {
					scope:actor = {
						has_claim_on = prev
					}
				}
				NOT = {
					any_ally = {
						this = scope:actor
					}
				}
			}
		}
	}

	can_be_picked_title = {
		scope:actor = {
			piety >= scope:target.regula_titulum_novis_cost
		}
		scope:target = {
			is_contested = no
		}
	}

	send_options_exclusive = no

	on_send = {
		scope:actor = {
			add_character_flag = {
				flag = flag_hostile_actions_disabled_delay
				days = 10
			}
		}
	}

	on_accept = {
		regula_titulum_novis_interaction_effect = yes

		save_scope_value_as = {
			name = revoke_title_interaction
			value = yes
		}

		scope:actor = {
			trigger_event = regula_interaction_event.0001
		}

		if = {
			limit = {
				scope:actor = { has_character_flag = flag_hostile_actions_disabled_delay }
			}
			scope:actor = { remove_character_flag = flag_hostile_actions_disabled_delay }
		}
	}

	ai_will_do = {
		base = 0
	}
}

# Teach Culture
regula_docere_cultura_interaction = {
	category = interaction_category_diplomacy
	common_interaction = no
	desc = regula_docere_cultura_interaction_desc
	icon = icon_culture
	interface_priority = 70

	is_shown = {
		scope:recipient = {
			has_trait = devoted_trait_group
			is_ruler = yes
			is_vassal_or_below_of = scope:actor
			highest_held_title_tier >= tier_county
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			custom_description = {
				text = magister_trait_3_required_trigger
				has_trait_rank = {
					trait = magister_trait_group
					rank >= 3
				}
			}
		}
		scope:recipient = {
			has_trait = devoted_trait_group
			is_vassal_or_below_of = scope:actor
			is_ruler = yes
			is_busy_in_events_localised = yes

			# Check if we even need to do this
			custom_description = {
				text = regula_docere_cultura_trigger
				regula_docere_cultura_total_cost > 0
			}
		}
	}

	cost = {
		prestige = {
			value = 0
			add = {
				value = scope:recipient.regula_docere_cultura_characters_cost
				desc = regula_docere_cultura_character_cost
			}
			add = {
				value = scope:recipient.regula_docere_cultura_titles_cost
				desc = regula_docere_cultura_title_cost
			}
		}
	}

	on_accept = {
		scope:recipient = {
			custom_tooltip = regula_docere_cultura_tooltip
		}
		scope:actor = {
			trigger_event = {
				id = regula_interaction_event.0002
			}
		}
	}

	auto_accept = yes

	ai_will_do = {
		base = 0
	}
}

# Summon to Court
regula_summon_to_court_interaction = {
	category = interaction_category_vassal
	common_interaction = no
	desc = regula_summon_to_court_interaction_desc
	interface_priority = 18
	icon = guest


	is_shown = {
		scope:actor = {
			has_trait = magister_trait_group
		}
		scope:recipient = {
			has_trait = devoted_trait_group
			NOR = {
				is_courtier_of = scope:actor
				is_imprisoned = yes
				is_hostage = yes
				AND = {
					exists = host
					host = scope:actor
				}
				is_ruler = yes
			}
		}

		# # Only show this option if we can't invite them normally
		NOT = {
			scope:actor = {
				is_character_interaction_potentially_accepted = {
					recipient = scope:recipient
					interaction = invite_to_court_interaction
				}
			}
		}
	}

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

	cost = {
		piety = {
			if = {
				limit = {
					scope:recipient = {
						OR = {
							has_opinion_modifier = {
								modifier = attempted_imprisonment_opinion
								target = scope:actor
							}
							has_opinion_modifier = {
								modifier = treasonous_imprison_refusal
								target = scope:actor
							}
							AND = {
								exists = var:escaped_imprisonment_from
								var:escaped_imprisonment_from = scope:actor
							}
						}
					}
				}
				value = 250
			}
			else = {
				value = 125
			}
		}
	}

	on_accept = {
		custom_tooltip = regula_summon_to_court_interaction_tooltip
		hidden_effect = {
			if = {
				limit = {
					exists = scope:recipient.liege
				}
				scope:recipient.liege = {
					send_interface_message = {
						type = event_generic_neutral
						title = msg_courtier_left_court_interaction_title

						right_icon = scope:recipient

						show_as_tooltip = {
							remove_courtier_or_guest = scope:recipient
						}
					}
				}
			}
		}

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

				# Add recipient as courter
				scope:actor = { add_courtier = scope:recipient }
				scope:recipient = {
					hidden_effect = {
						return_to_court = yes
					}
				}

				# Also add recipients kids if they are not yet adults or other checks (eg hostage/landed)
				scope:recipient = {
					every_child = {
						limit = {
							NOR = {
								is_courtier_of = scope:actor
								is_imprisoned = yes
								is_hostage = yes
								AND = {
									exists = host
									host = scope:actor
								}
								is_ruler = yes
							}
							is_adult = no
						}
						scope:actor = { add_courtier = prev }
						hidden_effect = {
							return_to_court = yes
						}
					}
				}

				scope:actor = {
					stress_impact = {
						shy = minor_stress_impact_gain
						chaste = medium_stress_impact_gain
						paranoid = medium_stress_impact_gain
						lustful = minor_stress_impact_loss
						gregarious = minor_stress_impact_loss
					}
				}
			}
		}
	}

	auto_accept = yes

	ai_will_do = {
		base = 0
	}
}

# Break Betrothal
regula_break_betrothal_courtier_interaction = {
	category = interaction_category_diplomacy
	common_interaction = no
	interface_priority = 98

	desc = regula_divorce_spouse_interaction_desc

	cost = {
		piety = 50
	}
	is_shown = {
		scope:actor = {
			has_trait = magister_trait_group
		}
		scope:recipient = {
			has_trait = devoted_trait_group
			is_imprisoned = no # Alternate event for Magister's captives.
			is_betrothed = yes
			is_ruler = no
		}
		NOT = {
			scope:recipient.betrothed = scope:actor
		}
	}

	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 = {
		custom_tooltip = regula_break_betrothal_courtier_interaction_tooltip
		scope:recipient = {
			break_betrothal = scope:recipient.betrothed
		}
	}

	ai_will_do = {
		base = 0
	}
}

# Force Courtier divorce
regula_divorce_spouse_interaction = {
	category = interaction_category_diplomacy
	common_interaction = no
	interface_priority = 85

	desc = regula_divorce_spouse_interaction_desc

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

	is_valid_showing_failures_only = {
		scope:actor = {
			custom_description = {
				text = magister_trait_3_required_trigger
				has_trait_rank = {
					trait = magister_trait_group
					rank >= 3
				}
			}
		}
		custom_description = {
			text = regula_courtier_spouse_ruler_trigger
			scope:recipient = {
				AND = {
					is_married = yes
					scope:recipient.primary_spouse = {
						is_ruler = no
					}
				}
			}
		}
	}

	auto_accept = yes

	on_accept = {
		custom_tooltip = regula_divorce_spouse_interaction_tooltip
		scope:recipient = {
			every_spouse = {
				scope:recipient = {
					divorce = prev
				}
				if = {
					limit = {
						has_relation_lover = scope:recipient
					}
					lover_breakup_effect = {
						BREAKER = scope:recipient
						LOVER = this
					}
					set_relation_rival = scope:recipient
				}
			}
		}
	}

	ai_will_do = {
		base = 0
	}
}

# Forge Inheritance law
regula_forge_inheritance_law_interaction = {

	icon = scroll_scales
	common_interaction = no
	interface_priority = 100
	category = interaction_category_diplomacy
	ignores_pending_interaction_block = yes

	scheme = regula_forge_inheritance_law

	desc = regula_forge_inheritance_law_interaction_desc
	send_name = START_REGULA_FORGE_INHERITANCE_LAW

	ai_frequency = 0 # Every 2 years.

	is_shown = {
		NOT = { scope:recipient = scope:actor }
		scope:actor = {
			is_ai = no
			OR = {
				any_secret = {
					secret_type = regula_covert_conversion
				}
				is_regula_trigger = yes
			}
		}

		scope:recipient = {
			is_ruler = yes
			in_diplomatic_range = scope:actor
			NOR = {
				has_realm_law = regula_covert_vassal_succession_law
				has_realm_law = regula_vassal_succession_law
				has_realm_law = paelex_default_succession_law
				has_realm_law = paelex_regula_succession_law
				has_realm_law = paelex_young_blood_succession_law
				has_realm_law = paelex_good_breeding_succession_law
				has_realm_law = paelex_talented_succession_law
				has_realm_law = female_preference_law
				has_realm_law = female_only_law
			}
			NOT = { has_realm_law = bishop_theocratic_succession_law }
			NOT = {  # The law is applied by default when a character's primed.
				any_secret = {
					secret_type = regula_covert_conversion
				}
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			can_start_scheme = {
				type = regula_forge_inheritance_law
				target_character = scope:recipient
			}
		}
		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
			}
		}
	}

	# Scheme Starter Packages
	options_heading = schemes.t.agent_packages
	send_options_exclusive = yes
	## Balanced agents.
	send_option = {
		flag = agent_focus_balance
		current_description = fabricate_hook_interaction.tt.agent_focus_balance
	}
	## Focused on Success Chance.
	send_option = {
		flag = agent_focus_success
		current_description = fabricate_hook_interaction.tt.agent_focus_success
	}
	## Focused on Speed.
	send_option = {
		flag = agent_focus_speed
		current_description = fabricate_hook_interaction.tt.agent_focus_speed
	}

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

				left_icon = scope:actor					
				right_icon = scope:recipient

				# Success.
				if = {
					limit = { scope:agent_focus_success ?= yes }
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = regula_forge_inheritance_law
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
						# Success.
						AGENT_1 = agent_shill
						AGENT_2 = agent_diplomat
						AGENT_3 = agent_scribe
						# Speed.
						AGENT_4 = agent_herald
						# Secrecy.
						AGENT_5 = agent_justiciar
					}
				}
				# Speed.
				else_if = {
					limit = { scope:agent_focus_speed ?= yes }
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = regula_forge_inheritance_law
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
						# Speed.
						AGENT_1 = agent_infiltrator
						AGENT_2 = agent_socialite
						AGENT_3 = agent_herald
						# Success.
						AGENT_4 = agent_scribe
						# Secrecy.
						AGENT_5 = agent_justiciar
					}
				}
				# Balanced.
				else = {
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = regula_forge_inheritance_law
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
						# Success.
						AGENT_1 = agent_diplomat
						AGENT_2 = agent_scribe
						# Speed.
						AGENT_3 = agent_socialite
						AGENT_4 = agent_herald
						# Secrecy.
						AGENT_5 = agent_justiciar
					}
				}
			}
		}
	}

	auto_accept = yes

	ai_will_do = {
		base = 0
	}
}

# Ally to a foreign ruler.
regula_form_alliance_interaction = {
	category = interaction_category_diplomacy
	common_interaction = yes
	icon = alliance

	ai_min_reply_days = 4
	ai_max_reply_days = 9

	send_name = regula_form_alliance_interaction

	interface_priority = 180
	desc = regula_form_alliance_interaction_desc

	greeting = positive
	notification_text = NEGOTIATE_ALLIANCE_NOTIFICATION

	is_shown = {
		scope:actor = {
			has_trait = magister_trait_group
		}
		exists = scope:actor.faith.religious_head
		NOR = {
			scope:actor = scope:recipient
			scope:actor.faith.religious_head = scope:recipient
		}
		scope:actor.faith = {
			this = scope:recipient.faith
		}
		scope:actor.faith.religious_head = scope:actor
		scope:recipient = {
			NOT = { this = scope:actor }
			NOT = { is_allied_to = scope:actor }
			is_ruler = yes
			is_independent_ruler = yes
			is_male = no
			highest_held_title_tier >= 2
		}
		scope:actor = {
			is_ruler = yes
			is_regula_trigger = yes
			OR = {
				is_ai = no
				highest_held_title_tier >= 2
			}
			tier_difference = {
					target = scope:recipient
					value >= 0
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:recipient = {
			is_landed = yes
			is_available = yes
		}
		scope:actor = {
			is_landed = yes
			is_available = yes
			NOT = {
				is_at_war_with = scope:recipient
			}
			scope:actor = {
				custom_description = {
					text = magister_trait_4_required_trigger
					has_trait_rank = {
						trait = magister_trait_group
						rank >= 4
					}
				}
			}
		}
		scope:recipient = { is_available = yes }
	}

	cost = {
		prestige = 250
	}

	on_auto_accept = {

	}

	on_accept = {
		save_scope_value_as = { #So that we can show the opinion gain in the response event
			name = perk_alliance_interaction
			value = yes
		}
		scope:recipient = {

		}

		#Set up alliance, because of Pontifex Carnalis interactions
		scope:actor = {
			custom_tooltip = negotiate_alliance_effect_recipient_tooltip
			trigger_event = regula_alliance_event.0001
			create_alliance = {
				target = scope:recipient
				allied_through_owner = scope:actor
				allied_through_target = scope:recipient
			}
		}
		scope:recipient = { # This opinion modifier controls the interaction, and is removed when breaking the alliance in any way (though on_actions)
			add_opinion = {
				modifier = perk_negotiated_alliance_opinion
				target = scope:actor
			}
		}
	}

	on_decline = {

	}

	auto_accept = yes

	ai_will_do = {
		base = 0
	}
}

# Vassalise a foreign ruler.
regula_potestas_non_transfunde_interaction = {
	category = interaction_category_vassal
	common_interaction = yes
	interface_priority = 60
	desc = regula_potestas_non_transfunde_interaction_desc
	icon = icon_vassal

	is_shown = {
		scope:actor = {
			has_trait = magister_trait_group
			is_landless_adventurer = no
		}
		scope:recipient = {
			NOT = { this = scope:actor }
			is_male = no # Leaving the door open for futas, etc.
			is_landed = yes
			is_independent_ruler = yes
			highest_held_title_tier < scope:actor.highest_held_title_tier
			NOT = { government_has_flag = can_not_be_vassal_or_liege }
		}

		scope:recipient = {
			OR = { # Devoted (implied secret faith) or shared faith
				is_regula_devoted_trigger = yes
				faith = scope:actor.faith
				AND = {
					secret_faith ?= scope:actor.faith
					any_secret = {
						OR = {
							secret_type = secret_crypto_religionist
							secret_type = regula_crypto_religionist_secret
						}
						is_known_by = scope:actor
					}
				}
			}
		}
	}

	# Checks which show failures
	# Must have enough prestige
	# Target must be adult, not at war with us
	# Also they must be available and not have a strong hook on us
	# Then Magister must have required piety level
	is_valid_showing_failures_only = {
		scope:actor = { 
			prestige >= scope:recipient.regula_potestas_non_transfunde_cost
		}
		
		scope:recipient = {
			is_adult = yes
		}

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

		scope:recipient = { is_available = yes }
		scope:recipient = { NOT = { has_strong_hook = scope:actor } }
		scope:actor = {
			custom_description = {
				text = magister_trait_5_required_trigger
				has_trait_rank = {
					trait = magister_trait_group
					rank >= 5
				}
			}
		}
	}

	cost = {
		prestige = scope:recipient.regula_potestas_non_transfunde_cost
	}

	auto_accept = yes

	on_accept = {
		custom_tooltip = regula_potestas_non_transfunde_interaction_tooltip
		create_title_and_vassal_change = {
			type = swear_fealty
			save_scope_as = change
		}
		scope:recipient = {
			change_liege = {
				liege = scope:actor
				change = scope:change
			}
		}
		resolve_title_and_vassal_change = scope:change
		if = {
			limit = {
				scope:recipient = {
					highest_held_title_tier = tier_kingdom
				}
			}
			change_global_variable = {
				name = regula_potestas_queen_tally
				add = 3
			}
		}
		else_if = {
			limit = {
				scope:recipient = {
					highest_held_title_tier = tier_duchy
				}
			}
			change_global_variable = {
				name = regula_potestas_queen_tally
				add = 2
			}
		}
		else_if = {
			limit = {
				scope:recipient = {
					highest_held_title_tier = tier_county
				}
			}
			change_global_variable = {
				name = regula_potestas_queen_tally
				add = 1
			}
		}
	}

	ai_will_do = {
		base = 0
	}
}

# Join an ongoing servitude war.
regula_join_servitude_war_interaction = {
	category = interaction_category_hostile
	common_interaction = yes
	interface = interfere_in_war
	special_interaction = interfere_in_war_interaction
	popup_on_receive = yes
	desc = regula_join_servitude_war_interaction_desc
	icon = declare_war_interaction

	greeting = positive
	notification_text = regula_join_servitude_war_interaction_notification

	is_shown = {
		scope:actor = {
			has_trait = magister_trait_group
			NOT = { is_at_war_with = scope:recipient }
		}

		scope:recipient = {
			regula_faction_is_servitude_faction_leader = yes
			NOT = {
				any_ally = {
					has_trait = magister_trait_group
				}
			}
			joined_faction ?= {
				faction_is_at_war = yes
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			NOT = { has_truce = scope:recipient }
		}
	}

	can_be_picked = {
		exists = scope:target
		scope:target = {
			is_war_leader = scope:recipient
			primary_attacker = {
				regula_faction_is_servitude_faction_leader = yes
			}
		}

		joiner_not_already_in_another_war_with_any_target_war_participants_trigger = {
			WARRIOR = scope:recipient
			JOINER = scope:actor
		}

		can_join_war_liege_vassal_check_trigger = { WARRIOR = scope:recipient JOINER = scope:actor }
	}

	on_accept = {
		scope:target = {
			if = {
				limit = {
					is_attacker = scope:recipient
				}
				add_attacker = scope:actor
			}
			else = {
				add_defender = scope:actor
			}
		}
		scope:actor = {
			stress_impact = {
				craven = medium_stress_impact_gain
				shy = minor_stress_impact_gain
			}
		}
	}

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

	auto_accept = yes

	ai_accept = {
		base = 100 # everyone wants help
	}
}

# Trigger title transfer to wife.
regula_enact_abice_maritus_interaction = {
	interface_priority = 100
	category = interaction_category_diplomacy
	common_interaction = yes
	desc = regula_enact_abice_maritus_interaction_desc
	icon = religious_claim

	use_diplomatic_range = yes
	ignores_pending_interaction_block = yes

	is_shown = {
		NOT = { scope:recipient = scope:actor }
		scope:actor = {
			has_trait = magister_trait_group
		}
		scope:recipient = {
			OR = {
				is_regula_trigger = yes
				is_crypto_regula_trigger = yes
			}
			is_married = yes
			is_imprisoned = no
			is_male = no
			scope:recipient.primary_spouse = {
				is_ruler = yes
			}
			NOT = { is_consort_of = scope:actor }
			scope:recipient.primary_spouse = {
				NOT = { # Can't become head of a holy order. Mercenary company OK.
					any_held_title = {
						is_holy_order = yes
					}
				}
			}
		}
	}

	cost = {
		piety = {
			value = 0
			add = {
				value = regula_abice_maritus_cost
				desc = CB_SIZE_OF_TARGET_REALM_COST
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			piety >= regula_abice_maritus_cost
			custom_description = {
				text = magister_trait_5_required_trigger
				has_trait_rank = {
					trait = magister_trait_group
					rank >= 5
				}
			}
		}
	}

	auto_accept = yes

	on_accept = {
		scope:recipient.primary_spouse = {
			create_title_and_vassal_change = {
				type = usurped
				save_scope_as = change
				add_claim_on_loss = no
			}
			every_held_title = {
				limit = {
					is_capital_barony = no
				}

				change_title_holder_include_vassals = {
					holder = scope:recipient
					change = scope:change
				}
			}
			resolve_title_and_vassal_change = scope:change
			if = {
				limit = { gold > 0 }
				pay_short_term_gold = {
					target = scope:recipient
					gold = scope:recipient.primary_spouse.gold
				}
			}
		}

		scope:recipient.primary_spouse = {
			add_opinion = {
				modifier = demanded_taking_vows
				target = scope:recipient
			}
			add_trait = devoted
			add_piety_level = 1
			if = {
				limit = { is_ruler = yes }
				depose = yes
			}
			if = {
				limit = {
					is_married = yes
				}
				every_spouse = {
					divorce = scope:recipient.primary_spouse
				}
			}
			if = {
				limit = {
					exists = betrothed
				}
				break_betrothal = betrothed
			}
			if = {
				limit = {
					is_concubine = yes
				}
				this.concubinist = {
					remove_concubine = scope:recipient.primary_spouse
				}
			}
			if = {
				limit = {
					number_of_concubines > 0
				}
				every_concubine = {
					scope:recipient = {
						remove_concubine = prev
					}
				}
			}

			if = {
				limit = {
					scope:recipient.top_liege = { # This is going to be of limited utility for foreign Mulsa.
						any_vassal_or_below = {
							has_government = theocracy_government
							primary_title.tier > tier_barony
							faith = scope:actor.faith
						}
					}
				}
				scope:recipient.top_liege = {
					random_vassal_or_below = {
						limit = {
							has_government = theocracy_government
							primary_title.tier > tier_barony
							faith = scope:actor.faith
						}
						save_scope_as = theocratic_travel_target
					}
				}
				visit_court_of = scope:theocratic_travel_target
			}
			else_if = {
				limit = {
					exists = scope:recipient.capital_province
				}
				move_to_pool_at = scope:recipient.capital_province
			}
			kick_from_court_interaction_warning_tooltip_effect = yes
		}
	}

	ai_will_do = {
		base = 0
	}
}

# Demand a charmed, crypto-regula character publicly convert.
regula_demand_reveal_crypto_regula_interaction = {
	category = interaction_category_religion
	desc = regula_demand_reveal_crypto_regula_interaction_desc
	icon = religious

	auto_accept = yes

	is_shown = {
		scope:actor = {
			has_trait = magister_trait_group
		}
		scope:recipient = {
			is_regula_devoted_trigger = yes
			is_crypto_regula_trigger = yes
		}
	}

	is_valid = {
		scope:actor = {
			has_trait = magister_trait_group
		}
		scope:recipient = {
			is_regula_devoted_trigger = yes
			is_crypto_regula_trigger = yes
		}
	}

	on_accept = {
		scope:recipient = {
			regula_force_convert_to_secret_faith_effect = yes
		}
	}


	ai_will_do = {
		base = 0
	}
}
