﻿# Verifies the magister is alive and has not converted away
magister_alive_trigger = {
	global_var:magister_character ?= {
		is_alive = yes
		is_regula_trigger = yes
	}
}

# Is this character a Magister?
is_magister = {
	custom_description = {
		text = regula_is_magister
		has_trait = magister_trait_group
	}
}

# Tests whether a given faith is a regula faith.
#
# Note: Only works in the context of a faith, not a religion.
#
# scope = the faith being tested
is_regula_faith_trigger = {
	has_doctrine = tenet_regula_magister
}

# Verifies that the current scope 'is regula' by testing whether it's held faith is regula.
#
# scope = any scope which has a 'faith'. Typically county or character.
is_regula_trigger = {
	custom_description = {
		text = regula_is_regula_faith
		faith = { is_regula_faith_trigger = yes }
	}
}

# Verifies is the latest (non heretical, outdated) version of the regula
is_canon_regula_trigger = {
	magister_alive_trigger = yes
	has_faith = global_var:magister_character.faith
	is_regula_trigger = yes
}

# scope = character
is_regula_holy_order_character_trigger = {
	and = {
		primary_title = {
			is_holy_order = yes
		}
		is_regula_trigger = yes
	}
}

# Holy site effect triggers
# flag = holy_site_regula_virus_flag
# flag = holy_site_reg_offspring_flag
# flag = regula_abice_maritus_active
# flag = holy_site_reg_sanctifica_serva_flag
# flag = holy_site_reg_mulsa_fascinare_flag
# Scope should be faith for all of these or character for the triggers which
# start with 'character'.

character_has_regula_holy_effect_regula_virus = {
	OR = {
		faith = {
			has_regula_holy_effect_regula_virus = yes
		}
		secret_faith ?= {
			has_regula_holy_effect_regula_virus = yes
		}
	}
}

has_regula_holy_effect_regula_virus = {
	OR = {
		controls_holy_site_with_flag = holy_site_regula_virus_flag
		has_holy_site_override_regula_virus = yes
	}
}

character_has_regula_holy_effect_female_offspring = {
	OR = {
		faith = {
			has_regula_holy_effect_female_offspring = yes
		}
		secret_faith ?= {
			has_regula_holy_effect_female_offspring = yes
		}
	}
}

has_regula_holy_effect_female_offspring = {
	OR = {
		controls_holy_site_with_flag = holy_site_reg_offspring_flag
		has_holy_site_override_female_offspring = yes
	}
}

character_has_regula_holy_effect_abice_martius = {
	OR = {
		faith = {
			has_regula_holy_effect_abice_martius = yes
		}
		secret_faith ?= {
			has_regula_holy_effect_abice_martius = yes
		}
	}
}

has_regula_holy_effect_abice_martius = {
	OR = {
		controls_holy_site_with_flag = regula_abice_maritus_active
		has_holy_site_override_abdice_martius = yes
	}
}

character_has_regula_holy_effect_sanctifica_serva = {
	OR = {
		faith = {
			has_regula_holy_effect_sanctifica_serva = yes
		}
		secret_faith ?= {
			has_regula_holy_effect_sanctifica_serva = yes
		}
	}
}

has_regula_holy_effect_sanctifica_serva = {
	OR = {
		controls_holy_site_with_flag = holy_site_reg_sanctifica_serva_flag
		has_holy_site_override_sanctifica_serva = yes
	}
}

character_has_regula_holy_effect_mulsa_fascinare = {
	OR = {
		faith = {
			has_regula_holy_effect_mulsa_fascinare = yes
		}
		secret_faith ?= {
			has_regula_holy_effect_mulsa_fascinare = yes
		}
	}
}

has_regula_holy_effect_mulsa_fascinare = {
	OR = {
		controls_holy_site_with_flag = holy_site_reg_mulsa_fascinare_flag
		has_holy_site_override_mulsa_fascinare = yes
	}
}

# Checks for characters under influence of the Magister
is_regula_devoted_trigger = {
	OR = {
		is_regula_leader_devoted_trigger = yes

		# Basic charmed characters
		has_trait = mulsa
		has_trait = tropaeum

		# Special charmed characters
		has_trait = orba
		has_trait = contubernalis
		has_trait = retired_paelex
		has_trait = regula_undying
	}
}

# Checks for characters that have been dominated by the Magister
# These are charmed characters that are landed rulers
is_regula_leader_devoted_trigger = {
	custom_description = {
		text = regula_is_devoted_paelex
		OR = {
			has_trait = domina
			has_trait = familia_paelex
			has_trait = paelex
		}
	}
}

# Checks for characters that can become Familia Paelex - Filia
# Just child of Magister
is_filia_eligible = {
	any_parent = {
		global_var:magister_character = this
	}
}

# Checks for characters that can become Familia Paelex - Neptis
# Grandchild, through either male/female parents
is_neptis_eligible = {
	any_parent = {
		is_filia_eligible = yes
	}
}

# Checks for characters that can become Proneptis Domini
# Great Grandchild
is_proneptis_eligible = {
	any_parent = {
		is_neptis_eligible = yes
	}
}