﻿
# Wife takes husbands titles.  NOTE: As the game doesn't look at non-landed characters this is written inverted, with the husband as the actor.
regula_abice_maritus = {
	interface_priority = 69
	category = interaction_category_religion

	common_interaction = yes
	use_diplomatic_range = no
	ignores_pending_interaction_block = yes

	is_shown = {
		scope:recipient = {
			is_imprisoned = no
			is_landed = no
			scope:recipient.faith = {
				controls_holy_site_with_flag = regula_abice_maritus_active
			}
			piety >= 500
		}
		scope:actor = {
			is_ai = yes
			is_at_war = no
			is_spouse_of = scope:recipient
			is_male = yes
			is_ruler = yes
			NOT = { # Can't become head of a holy order. Mercenary company OK.
				any_held_title = {
					is_holy_order = yes
				}
			}
			NOT = { has_trait = magister_trait_group }
		}
	}

	is_valid_showing_failures_only = { # Not seen by player, but a custom_descriptor should be here.

	}

	cost = {
	}

	auto_accept = yes

	on_accept = {
		scope:actor = {
			create_title_and_vassal_change = {
				type = conquest
				save_scope_as = change
				add_claim_on_loss = no
			}
			every_held_title = {
				change_title_holder_include_vassals = {
					holder = scope:recipient
					change = scope:change
				}
			}
			resolve_title_and_vassal_change = scope:change
		}

		scope:actor = {
			scope:recipient = {
				add_piety = -500
				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:recipient.faith
							}
						}
					}
					scope:recipient.top_liege = {
						random_vassal_or_below = {
							limit = {
								has_government = theocracy_government
								primary_title.tier > tier_barony
								faith = scope:recipient.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
			}
			scope:actor = {
				add_opinion = {
					modifier = demanded_taking_vows
					target = scope:recipient
				}
				if = {
					limit = { gold > 0 }
					pay_short_term_gold = {
						target = scope:recipient
						gold = scope:actor.gold
					}
				}
				add_trait = devoted
				add_piety_level = 1
				if = {
					limit = { is_ruler = yes }
					depose = yes
				}
				if = {
					limit = {
						is_married = yes
					}
					every_spouse = {
						divorce = scope:actor
					}
				}
				if = {
					limit = {
						exists = betrothed
					}
					break_betrothal = betrothed
				}
				if = {
					limit = {
						is_concubine = yes
					}
					this.concubinist = {
						remove_concubine = scope:actor
					}
				}
				if = {
					limit = {
						number_of_concubines > 0
					}
					every_concubine = {
						scope:recipient = {
							remove_concubine = prev
						}
					}
				}
			}
		}
		if = { # Notify the player if this is particularly relevant.
			limit = {
				OR = {
					scope:recipient = {
						OR = {
							is_independent_ruler = yes
							top_liege = global_var:magister_character
						}
					}
					scope:actor = { # Fallback
						OR = {
							is_independent_ruler = yes
							top_liege = global_var:magister_character
						}
					}
				}
			}
			if = {
				limit = {
					global_var:magister_character.faith = {
						controls_holy_site = reg_alexandria
					}
				}
				global_var:magister_character = {
					send_interface_message = {  # Tells the player the outcome.
						type = event_spouse_task_good
						title = regula_abice_maritus_effect_title
						desc = regula_abice_maritus_effect.desc_mediterranean
						right_icon = scope:actor
						left_icon = scope:recipient
					}
				}
			}
			if = {
				limit = {
					global_var:magister_character.faith = {
						controls_holy_site = reg_toulouse
					}
				}
				global_var:magister_character = {
					send_interface_message = {  # Tells the player the outcome.
						type = event_spouse_task_good
						title = regula_abice_maritus_effect_title
						desc = regula_abice_maritus_effect.desc_european
						right_icon = scope:actor
						left_icon = scope:recipient
					}
				}
			}
			if = {
				limit = {
					global_var:magister_character.faith = {
						controls_holy_site = reg_tyre
					}
				}
				global_var:magister_character = {
					send_interface_message = {  # Tells the player the outcome.
						type = event_spouse_task_good
						title = regula_abice_maritus_effect_title
						desc = regula_abice_maritus_effect.desc_alexandrian
						right_icon = scope:actor
						left_icon = scope:recipient
					}
				}
			}
			if = {
				limit = {
					global_var:magister_character.faith = {
						controls_holy_site = reg_daura
					}
				}
				global_var:magister_character = {
					send_interface_message = {  # Tells the player the outcome.
						type = event_spouse_task_good
						title = regula_abice_maritus_effect_title
						desc = regula_abice_maritus_effect.desc_west_africa
						right_icon = scope:actor
						left_icon = scope:recipient
					}
				}
			}
		}
	}

	ai_targets = {
		ai_recipients = spouses
	}

	ai_targets = {
		ai_recipients = liege
	}

	ai_potential = {
		is_adult = yes
	}

	ai_frequency = 6

	ai_will_do = { # Better to link the effect to ai's piety than traits.  Way less balancing required.
		base = 100
	}
}

regula_fascinare_ai_interaction = {
	category = interaction_debug_main
	use_diplomatic_range = no
	ignores_pending_interaction_block = yes
	cooldown = { months = 48 }# Every 4 years

	
	is_shown = {
		scope:actor = {
			AND = {
				OR = {
					has_trait = paelex
#					has_trait = mulsa  ### Update - Too much?
					has_trait = domina
				}
				scope:actor.faith = {
					controls_holy_site_with_flag = holy_site_reg_mulsa_fascinare_flag
				}
			}
		}
		scope:recipient = {
			is_adult = yes 
			is_male = no
			NOR = {
				has_trait = paelex
				has_trait = mulsa
				has_trait = domina
				has_trait = contubernalis 
				has_trait = orba
			}
			is_imprisoned = no
		}
	}

	is_valid = {
		NOT = { scope:recipient = scope:actor }
		scope:actor = {
			OR = {
				has_trait = magister_trait_group
				has_trait = devoted_trait_group
			}
		}
	}

	ai_frequency = 24

	# ai_targets = {
	# 	ai_recipients = realm_characters # limited by is_shown to members of their court.
	# 	max = 10
	# }
	ai_targets = {
		ai_recipients = guests
		ai_recipients = courtiers
		ai_recipients = vassals ### UPDATE - Is this appropriate code?
	}

	ai_targets = {
		ai_recipients = dynasty
	}

	ai_target_quick_trigger = {
		adult = yes
		attracted_to_owner = yes
		owner_attracted = yes
	}

	on_accept = {
		scope:recipient = {
			add_trait = mulsa
			set_character_faith = global_var:magister_character.faith
		}
	}

	auto_accept = yes

	ai_will_do = {
		base = 100
	}
}

regula_instiga_discordia = {
	category = interaction_category_religion
	use_diplomatic_range = no
	ignores_pending_interaction_block = yes
	interface_priority = 71

	cooldown_against_recipient = { years = 2 } # Can run through all mulsa, but can't just repeatedly run the event against one mulsa.

	cost = {
		piety = {
			value = 50
		}
	}

	is_shown = {
		scope:actor = { has_trait = magister_trait_group }
		scope:recipient = { # Mulsa must be foreign.
			has_trait = devoted_trait_group
			is_independent_ruler = no
			OR = {
				is_ruler = yes
				is_married = yes
			}
			NOT = { is_spouse_of = scope:actor }
			NOT = { is_in_the_same_court_as_or_guest = scope:actor }
		}
		NOR = {
			scope:recipient.top_liege = scope:actor
			scope:recipient.liege = scope:actor
			scope:recipient = scope:actor
			scope:recipient = { is_imprisoned = yes }
		}
	}

	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 = {
			custom_description = {
				text = regula_instiga_discordia_in_progress_trigger
				can_start_scheme = {
					type = regula_instiga_discordia
					target = scope:recipient.primary_spouse
				}
			}
		}
	}

	desc = regula_instiga_discordia_interaction_desc

	auto_accept = yes

	on_accept = {
		scope:recipient = {
			if = {
				limit = {
					NOT = { has_trait = regula_gossip }
				}
				add_trait = regula_gossip
			}
			if = {
				limit = {
					is_ruler = no
					is_married = yes
				}
				scope:recipient.primary_spouse = {
					save_scope_as = target
				}
			}
			else = {
				scope:recipient.liege = {
					save_scope_as = target
				}
			}
		}

		scope:actor = {
			send_interface_toast = {
				title = start_regula_instiga_discordia_notification

				left_icon = scope:recipient
				right_icon = scope:target

				scope:recipient = {
					start_scheme = {
						type = regula_instiga_discordia
						target = scope:target
					}
				}
			}
		}
	}
	ai_will_do = {
		base = 100
	}
}


start_rapta_maritus = {
	interface_priority = 65
	category = interaction_category_religion

	send_name = START_SCHEME

	scheme = rapta_maritus
	ignores_pending_interaction_block = yes

	cooldown = { years = 3 }

	is_shown = {
		scope:actor = { has_trait = magister_trait_group }
		scope:recipient = {
			has_trait = devoted_trait_group
			is_married = yes
			NOT = { is_spouse_of = scope:actor }
			NOT = { is_vassal_or_below_of = scope:actor }
		}
		NOR = {
			scope:recipient = scope:actor
#			scope:recipient.primary_spouse = { is_imprisoned = no }
			scope:recipient = { is_imprisoned = yes }
		}
	}

	is_valid_showing_failures_only = {  # UPDATE - Need to add explanatory text. And a something that states they're still working.
		scope:actor = {
			custom_description = {
				text = magister_trait_4_required_trigger
				has_trait_rank = {
					trait = magister_trait_group
					rank >= 4
				}
			}
		}
		scope:recipient = {
			custom_description = {
				text = rapta_maritus_in_progress_trigger
				can_start_scheme = {
					type = rapta_maritus
					target = scope:recipient.primary_spouse
				}
			}
		}
	}

	cost = {
		piety = 75
	}

	desc = {
		triggered_desc = {
			trigger = {
				scope:actor = {
					can_start_scheme = {
						type = rapta_maritus
						target = scope:recipient.primary_spouse
					}
				}
			}
			desc = scheme_interaction_tt_rapta_maritus_approved
		}
	}

	on_accept = {
		custom_tooltip = rapta_maritus_tooltip
		scope:recipient = {
			stress_impact = {
				compassionate = medium_stress_impact_gain
				honest = minor_stress_impact_gain
				just = minor_stress_impact_gain
			}
			add_intrigue_skill = 3
			if = {
				limit = {
					NOR = {
						has_trait = sadistic
						has_trait = callous
					}
				}
				add_trait = callous
			}
			if = {
				limit = {
					NOT = { has_trait = cynical }
				}
				add_trait = cynical
			}
		}
		hidden_effect = {
			scope:actor = {
				send_interface_toast = {
					title = start_rapta_maritus_notification

					left_icon = scope:recipient
					right_icon = scope:recipient.primary_spouse

					scope:recipient = {
						start_scheme = {
							type = rapta_maritus
							target = scope:recipient.primary_spouse
						}
					}
				}
			}
		}
	}

	auto_accept = yes
}


revela_secretum = {
	category = interaction_category_religion
	use_diplomatic_range = no
	ignores_pending_interaction_block = yes
	interface_priority = 60

#	icon = "gfx/interface/icons/character_interactions/regula_character_interaction.dds"

	cooldown_against_recipient = { years = 2 } # Can run through all mulsa, but can't just repeatedly run the event against one mulsa.

	cost = {
		piety = {
			value = 50
		}
	}

	is_shown = {
		scope:actor = { has_trait = magister_trait_group }
		scope:recipient = { # Mulsa must be foreign.
			has_trait = devoted_trait_group
			is_independent_ruler = no
			NOT = { is_spouse_of = scope:actor }
			NOT = { is_in_the_same_court_as_or_guest = scope:actor }
		}
		NOR = {
			scope:recipient.top_liege = scope:actor
			scope:recipient.liege = scope:actor
			scope:recipient = scope:actor
			scope:recipient = { is_imprisoned = yes }
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			custom_description = {
				text = magister_trait_2_required_trigger
				has_trait_rank = {
					trait = magister_trait_group
					rank >= 2
				}
			}
		}
	}

	desc = revela_secretum_interaction_desc

	on_accept = {
		custom_tooltip = revela_secretum_interaction_tooltip
		scope:recipient = {
			save_scope_as = revela_recipient
			if = {
				limit = {
					any_secret = { # There's something to discover
						NOR = {
							is_known_by = scope:actor
							secret_target = scope:recipient
						}
					}
				}
				random_secret = {
					limit = {
						NOR = {
							is_known_by = scope:actor
							secret_target = scope:recipient
						} # Hilarious as it is, they shouldn't be revealing their own secrets.
					}
					weight = {
						base = -1
						modifier = {
							add = 5
							is_criminal_for = secret_owner
						}
					}
					save_scope_as = secret_to_reveal
				}
			}
		}
		if = {
			limit = {
				exists = scope:secret_to_reveal
			}
			scope:actor = {
				trigger_event = {
					id = revela_secretum.0001 # Move to decision
					days = { 2 10 }
				}
			}
		}
		else = {
			if = {
				limit = {
					scope:recipient = {
						has_perk = truth_is_relative_perk # Mulsa is inventive
					}
				}
				scope:recipient = {
					hidden_effect = {
						# Start by adding everyone that this character could trick to a list
						add_to_list = secret_setup
						every_spouse = {
							add_to_list = secret_setup
						}
						every_vassal_or_below = {
							add_to_list = secret_setup
						}
						every_close_family_member = {
							add_to_list = secret_setup
						}
						every_relation = {
							add_to_list = secret_setup
						}
						random_in_list = { # Target a vassal or liege. They must be of age.
							list = secret_setup
							limit = {
								NOR = {
									has_trait = devoted_trait_group
									is_adult = no
								}
							}
							save_scope_as = revela_target
							random = {
								chance = 20
								save_scope_value_as = {
									name = strong_hook_against_ruler
									value = yes
								}
							}
						}
					}
				}
				scope:actor = {
					trigger_event = {
						on_action = revela_secretum_fabricate_effect
						days = { 10 30 }
					}
				}
			}
			else = {
				scope:recipient = {
					hidden_effect = {
						# Start by adding everyone that this character could trick to a list
						add_to_list = secret_setup
						every_spouse = {
							add_to_list = secret_setup
						}
						every_vassal_or_below = {
							add_to_list = secret_setup
						}
						every_close_family_member = {
							add_to_list = secret_setup
						}
						every_relation = {
							add_to_list = secret_setup
						}
					random_in_list = { # Target a vassal or liege
						list = secret_setup
						limit = {
							NOR = {
								has_trait = devoted_trait_group
								is_adult = no
							}
						}
						save_scope_as = revela_target
							random = {
								chance = 20
								save_scope_value_as = {
									name = strong_hook_against_ruler
									value = yes
								}
							}
						}
					}
				}
				scope:actor = {
					trigger_event = {
						id = revela_secretum.0002 # Take nothing or alter mulsa.
						days = { 10 30 }
					}
				}
			}
		}
	}
	auto_accept = yes
}