﻿# Turn our charmed spouse (who has a county or higher) into a Paelex, they should be a Mulsa
# scope:recipient is our target being turned from Mulsa into a Paelex
# scope:actor should be the Magister
# Effects are:
# 	On scope:recipient
#		- Iterate Domitans Tribunal counter
#		- Remove Mulsa trait
#		- Set to bisexual
#		- Create memory of being dominated by the scope:actor
#		- Child of the book pregnancy effect (if they are pregnant, run regula_paelex_event.1040)
#		- Break up with male lovers and all soulmates (not including scope:actor)
#		- Break up with any spouses/concubinists/betrothals (not including scope:actor)
#	On scope:actor
#		- Marry scope:recipient
#		- Run an on_action for Domitans effect, use 
#			regula_start_alternate_mutare_corpus_event = {
#				MODE = paelex_monument
#			}
#			With different modes depending on scope:recipient
regula_make_paelex_interaction_effect = {

	# Iterate Domitans Tribunal counter
	change_global_variable = {
		name = regula_domitans_tally
		add = 1
	}

	scope:recipient = {
		# Remove Mulsa trait
		remove_trait = mulsa
		remove_trait = tropaeum
		
		# Sex to bisexual
		set_sexuality = bisexual

		# Create memory of being dominated by the scope:actor
		create_character_memory = {
			type = regula_memory_domitans_tribunal
			participants = { magister = global_var:magister_character }
		}

		# Domitans pregnancy trigger
		hidden_effect = {
			if = {
				limit = { is_pregnant = yes }
				trigger_event = regula_paelex_event.1040
			}
		}

		# Break up with male lovers (not including Magister)
		# This also includes soulmates
		every_relation = {
			type = lover
			limit = {
				AND = {
					NOT = { this = scope:actor }
					is_male = yes	# Female lovers are ok!
				}
			}
			lover_breakup_effect = {
				BREAKER = scope:recipient
				LOVER = this
			}
		}

		# Spouses, if any exist, are also furious.
		if = {
			limit = {
				is_married = yes
			}
			if = {
				limit = {
					NOT = {
						is_consort_of = scope:actor
					}
				}
				every_spouse = {
					show_as_tooltip = {
						if = {   
							### Husband understands if they're also Magisterian.
							limit = { is_regula_trigger = no }
							add_opinion = {
								target = scope:actor
								modifier = forced_spouse_concubine_marriage_opinion
							}
						}
						divorce = scope:recipient # no additional opinion hit, no scripted effect
					}
					trigger_event = marriage_interaction.0041	# Tells Husband you have taken wife as concubine
				}
			}
		}
	
		# Stealing concubines pisses the former concubinist off.
		if = {
			limit = {
				is_concubine = yes
				NOT = { is_concubine_of = scope:actor }
			}
			this.concubinist = {
				show_as_tooltip = {
					if = {
						### Husband understands if they're also Magisterian.
						limit = { is_regula_trigger = no }
						add_opinion = {
							target = scope:actor
							modifier = stole_concubine_opinion
						}
						remove_concubine = scope:recipient # no additional opinion hit, no scripted effect
					}
				}
				trigger_event = marriage_interaction.0041	# Tells Concubinist you have taken wife as concubine
			}
		}
		
		# Break any betrothals which may exist (without additional opinion penalties).
		# Its ok to break Magister betrothal because you marry them after
		if = {
			limit = { exists = betrothed }
			betrothed = { trigger_event = marriage_interaction.0041 }
			break_betrothal = betrothed
		}
	}

	scope:actor = {
		# Marry scope:recipient
		marry = scope:recipient

		# Run Domitans event, which is really just a Mutare Corpus event with custom text (and a specific trait)
		trigger_event = { on_action = regula_domitans_event_selector }
	}
}

# Add the correct Paelex trait, depending on scope:actor relation to scope:recipient
regula_add_paelex_trait_effect = {

	# Domina (scope:recipient is Primary Spouse)
	if = {
		limit = { scope:actor.primary_spouse = scope:recipient }
		scope:recipient = {
			add_trait_force_tooltip = domina
		}
	}
	# Domina (scope:actor is not married yet)
	else_if = {
		limit = {
			scope:actor = {
				is_married = no
			}
		}
		scope:recipient = {
			add_trait_force_tooltip = domina
		}
	}
	# Family Paelex (scope:recipient is in scope:actor dynasty)
	else_if = {
		limit = { 
			scope:actor.dynasty = {
				any_dynasty_member = {
					this = scope:recipient
				}
			}
		}
		scope:recipient = {
			add_trait_force_tooltip = familia_paelex
		}
	}
	# Normal Paelex
	else = {
		scope:recipient = {
			add_trait_force_tooltip = paelex
		}
	}
}