﻿# On action for a character which evaluates whether a crypto regula character
# should reveal themselves.
#
# scope = the character who might reveal.
maybe_reveal_crypto_regula_on_action = {
	trigger = {
		is_crypto_regula_trigger = yes
	}
	effect = {
		regula_maybe_convert_to_secret_faith_effect = yes
	}
}

# On action for a character which evaluates whether crypto regula vassals,
# courtiers, and consorts should reveal themselves.
#
# scope = the character whose vassals might reveal.
maybe_reveal_crypto_regula_from_liege_on_action = {
	effect = {
		every_vassal = {
			limit = {
				is_crypto_regula_trigger = yes
			}
			regula_maybe_convert_to_secret_faith_effect = yes
		}
		every_courtier = {
			limit = {
				is_crypto_regula_trigger = yes
			}
			regula_maybe_convert_to_secret_faith_effect = yes
		}
		every_consort = {
			limit = {
				is_crypto_regula_trigger = yes
			}
			regula_maybe_convert_to_secret_faith_effect = yes
		}
	}
}

# On action which triggers when a character gains a vassal, potentially
# causing that character to reveal their crypto regula faith.
#
# scope:vassal = vassal being gained
crypto_regula_on_vassal_gained = {
	effect = {
		scope:vassal = {
			if = {
				limit = {
					is_crypto_regula_trigger = yes
				}
				regula_maybe_convert_to_secret_faith_effect = yes
			}
		}
	}
}

# Called from code once a year for all characters, at a random point that year (individually for each character)
# Root is the character
random_yearly_everyone_pulse = {
	on_actions = {
		maybe_reveal_crypto_regula_on_action
	}
}

# Code on-action: character changes faith. Not called when a character gets a faith on birth, creation, and similar
# Root is the character
# scope:old_faith is the faith they used to have
on_character_faith_change = {
	on_actions = {
		maybe_reveal_crypto_regula_from_liege_on_action
	}
}

# A character gains a vassal
# root = character gaining vassal
# scope:vassal = vassal being gained
# scope:old_liege = the previous liege of the vassal. Might be the null character (vassal used to be a non-ruler or independent), so make sure to use "exists" checks where relevant
on_vassal_gained = {
	on_actions = {
		crypto_regula_on_vassal_gained
	}
}

# Fires when a character leaves a court. Not fired when leaving due to death or similar
# Will still fire even if on_join_court is firing (fires just before it)
# Root is the character
# scope:old_employer is their old employer
on_leave_court = {
	on_actions = {
		maybe_reveal_crypto_regula_on_action
	}
}
