regula_initialize_magister_effect = {
	set_global_variable = {
		name = magister_character
		value = root
	}
    set_variable = {
		name = regula_fascinare_tally
		value = 0
	}
	set_variable = {
		name = regula_domitans_tally
		value = 0
	}
	set_variable = {
		name = regula_contubernalis_tally
		value = 0
	}
	set_variable = {
		name = regula_domination_war_tally
		value = 0
	}
    set_variable = {
		name = regula_servitude_war_tally
		value = 0
	}
    set_variable = {
		name = regula_potestas_queen_tally
		value = 0
	}
}

regula_first_secret_conversion = {
	regula_create_placeholder_character_effect = { WHO = root }
	scope:created_character = { save_scope_as = regula_placeholder }
	set_global_variable = {
		name = regula_secret_keeper
		value = scope:regula_placeholder
	}
	# set_global_variable = {
	# 	name = proto_magister_character
	# 	value = root
	# }
	add_secret = {
		type = regula_covert_conversion
		target = global_var:regula_secret_keeper
	}
	global_var:regula_secret_keeper = { # Two can keep a secret, if one is dead.
		death = {
			death_reason = death_vanished
		}
	}
}

regula_secret_conversion = {
	add_secret = {
		type = regula_covert_conversion
		target = global_var:regula_secret_keeper
	}
    add_realm_law_skip_effects = regula_covert_vassal_succession_law
	random_secret = {
		limit = {
			secret_type = regula_covert_conversion
			NOT = { is_known_by = scope:actor }
		}
		reveal_to = scope:actor
	}
}


regula_secret_reboot = {
	add_secret = {
		type = regula_covert_conversion
		target = global_var:regula_secret_keeper
	}
	every_vassal_or_below = {  ### Update: Non-functional
		limit = {
			any_secret = {
				secret_type = regula_covert_conversion
			}
		}
		random_secret = {
			limit = {
				secret_type = regula_covert_conversion
				NOT = { is_known_by = scope:actor }
			}
			reveal_to = scope:actor
		}
		every_courtier_or_guest = {
			limit = {
				any_secret = {
					secret_type = regula_covert_conversion
				}
			}
			random_secret = {
				limit = {
					secret_type = regula_covert_conversion
					NOT = { is_known_by = scope:actor }
				}
				reveal_to = scope:actor
			}
		}
	}
	every_courtier_or_guest = {
		limit = {
			any_secret = {
				secret_type = regula_covert_conversion
			}
		}
		random_secret = {
			limit = {
				secret_type = regula_covert_conversion
				NOT = { is_known_by = scope:actor }
			}
			reveal_to = scope:actor
		}
	}
	# global_var:regula_secret_keeper = {
	# 	random_targeting_secret = {
	# 		limit = {
	# 			secret_type = regula_covert_conversion
	# 			secret_owner = {
	# 				is_male = yes
	# 			}
	# 		}
	# 		save_scope_as = regula_secret
	# 		scope:regula_secret.secret_owner = {
	# 			save_scope_as = proto_magister
	# 		}
	# 	}
	# 	every_targeting_secret = {
	# 		limit = {
	# 		}
	# 		reveal_to = scope:proto_magister
	# 	}
	# }
}

regula_secret_conversion_reveal_effect = {
	every_held_title = {
		limit = { 
			tier = tier_county 
		}
		set_county_faith = faith:regula_default
	}
	demand_conversion_interaction_effect = yes
	every_vassal_or_below = {
		if = {
			limit = {
				any_secret = {
					secret_type = regula_covert_conversion
				}
			}
			set_character_faith = faith:regula_default
			add_character_modifier = {
				modifier = regula_initial_spellbound
			}
			add_trait = mulsa
			demand_conversion_interaction_effect = yes
			every_held_title = {
				limit = { 
					tier = tier_county 
				}
				set_county_faith = faith:regula_default
			}	
		}
		every_courtier_or_guest = {
			limit = {
				any_secret = {
					secret_type = regula_covert_conversion
				}
			}
			set_character_faith = faith:regula_default
			add_trait = mulsa
			demand_conversion_interaction_effect = yes
			every_held_title = {
				limit = { 
					tier = tier_county 
				}
				set_county_faith = faith:regula_default
			}	
		}
	}
	every_courtier_or_guest = {
		limit = {
			any_secret = {
				secret_type = regula_covert_conversion
			}
		}
		set_character_faith = faith:regula_default
		add_trait = mulsa
		demand_conversion_interaction_effect = yes
		every_held_title = {
			limit = { 
				tier = tier_county 
			}
			set_county_faith = faith:regula_default
		}	
	}
}