﻿# This will grab the correct even for us, based on relation between
# scope:actor (Magister) and scope:recipient (new Paelex)
regula_domitans_event_selector = {
	effect = {
		regula_add_paelex_trait_effect = yes
	}
	first_valid_on_action = {
		regula_domitans_domina_event	# Domina
		regula_familia_paelex_event 	# Family Paelex events
		regula_default_paelex_event		# Paelex
	}
}

# Domina events
regula_domitans_domina_event = {
	trigger = {
		OR = {
			scope:actor = {
				is_married = no
			}
			scope:actor.primary_spouse = scope:recipient
		}
	}
	effect = {
		scope:actor = { regula_start_alternate_mutare_corpus_event = { MODE = domina } }
	}
}

# Familia Paelex events
# Note, these are special events, you can still have the Familia Paelex trait and not trigger an event here
# Currently have events for: Daughter, GrandDaughter and Great GrandDaughter
regula_familia_paelex_event = {
	trigger = {
		scope:recipient = {
			OR = {
				is_proneptis_eligible = yes
				is_neptis_eligible = yes
				is_filia_eligible = yes
			}
		}
	}
	effect = {
		if = { # Redirect towards daughter event(s).
			limit = {
				scope:recipient = {
					is_filia_eligible = yes
				}
			}
			scope:actor = {
				regula_start_alternate_mutare_corpus_event = {
					MODE = filia_domini
				}
			}
		}
		else_if = { # Redirect towards granddaughter event(s).
			limit = {
				scope:recipient = {
					is_neptis_eligible = yes
					scope:recipient.mother = {
						is_alive = yes
						is_regula_devoted_trigger = yes
					}
				}
			}
			scope:recipient.mother = {
				save_scope_as = third_mutare_attendee
			}
			scope:actor = {
				regula_start_alternate_mutare_corpus_event = {
					MODE = neptis_domini
				}
			}
		}
		else_if = { # Redirect towards great-granddaughter event(s).
			limit = {
				scope:recipient = {
					is_proneptis_eligible = yes
					scope:recipient.mother = {
						is_alive = yes
						is_regula_devoted_trigger = yes
					}
					scope:recipient.mother.mother = {
						is_alive = yes
						is_regula_devoted_trigger = yes
					}
				}
			}
			scope:recipient.mother = {
				save_scope_as = third_mutare_attendee
			}
			scope:recipient.mother.mother = {
				save_scope_as = fourth_mutare_attendee
			}
			scope:actor = {
				regula_start_alternate_mutare_corpus_event = {
					MODE = proneptis_domini
				}
			}
		}
		else = { # We fallback to normal paelex events if we fail a trigger for the above events 
			trigger_event = { on_action = regula_default_paelex_event }
		}
	}
}

# Paelex events
regula_default_paelex_event = {
	effect = {
		scope:actor = { 
			random_list = {
				200 = {
					regula_start_alternate_mutare_corpus_event = {
						MODE = paelex_smooth
					}
				}
				100 = {
					regula_start_alternate_mutare_corpus_event = {
						MODE = paelex_shatter
					}
				}
				100 = {
					regula_start_alternate_mutare_corpus_event = {
						MODE = paelex_monument
					}
				}
			}
		}
	}
}