regula_covert_conversion = {
    category = religious

    is_valid = {
		scope:secret_owner = {
			NOT = { faith = { religion_tag = regula_religion } }
		}
	}

	is_shunned = { 
	}

	is_criminal = {
        scope:secret_owner = {
			is_male = yes
		}
	}

	on_expose = {
		save_scope_as = secret
		
		secret_owner = {
			save_scope_as = owner
		}
		if = {
			limit = { exists = secret_target }
			secret_target = { save_scope_as = target }
		}

		#Save spouses, close family members, liege and anyone whom I am primary heir of
		scope:owner = {
			save_list_targets_for_secret_exposure_events_effect = { SECRET = scope:secret CHARACTER = scope:owner }
		}

		#Send the notification event
		every_in_list = {
			list = send_exposed_secret_event_list

			trigger_event = secrets.0107

		}

		### Sending feed messages to other characters who care ###
		scope:owner = {
			#Save secret knowers and extended family members for feed messages
			save_list_targets_for_secret_exposure_feed_messages_effect = { SECRET = scope:secret CHARACTER = scope:owner }
		}

		every_in_list = {
			list = send_exposed_secret_feed_message_list
			save_scope_as = secret_expose_feed_message_scope

			send_interface_message = {
				type = secret_exposed_message
				left_icon = scope:owner
				title = secret_exposed_notification_effect_message
				desc = secret_exposed_notification_effect_message_witch

				if = {
					limit = { has_hook_from_secret = scope:secret }
					if = {
						limit = {
							has_hook_of_type = {
								target = scope:owner
								type = weak_blackmail_hook
							}
						}
						remove_hook = {
							target = scope:owner
							type = weak_blackmail_hook
						}
					}
					else_if = {
						limit = {
							has_hook_of_type = {
								target = scope:owner
								type = strong_blackmail_hook
							}
						}
						remove_hook = {
							target = scope:owner
							type = strong_blackmail_hook
						}
					}
				}
			}
		}

		### Send toast to exposer ###
		if = {
			limit = {
				trigger_if = {
					limit = { exists = scope:target }
					NOR = {
						scope:secret_exposer = scope:target
						scope:secret_exposer = scope:owner
					}
				}
				trigger_else = {
					NOT = { scope:secret_exposer = scope:owner }
				}
			}
			scope:secret_exposer = {
				save_scope_as = secret_expose_feed_message_scope
				send_interface_toast = {
					left_icon = scope:owner
					title = secret_exposed_notification_effect_message

					custom_tooltip = secret_exposed_notification_effect_message_witch.i_exposed

					if = {
						limit = { has_hook_from_secret = scope:secret }
						remove_hook = {
							target = scope:owner
							type = weak_blackmail_hook
						}
					}
				}
			}
		}

		scope:secret_owner = {
			if = {
				limit = {
					NOT = {
						this = scope:secret_exposer
					}
					is_male = yes # The house of cards only comes down when the PC is revealed.
				}
				trigger_event = regula_initialize_event.0008
			}
			else = {  ### UPDATE - This doesn't work.
				global_var:regula_secret_keeper = {
					random_targeting_secret = {
						limit = {
							secret_type = regula_covert_conversion
							secret_owner = {
								is_male = yes
							}
						}
						scope:secreties.secret_owner = {
							save_scope_as = truetrial
						}
					}
				}
				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
						}
						scope:proto_magister = {
							send_interface_message = {
								type = secret_exposed_message
								left_icon = scope:owner
								title = regula_covert_conversion_exposed_message
								desc = regula_covert_conversion_exposed_message_desc
				
								if = {
									limit = { has_hook_from_secret = scope:secret }
									if = {
										limit = {
											has_hook_of_type = {
												target = scope:owner
												type = weak_blackmail_hook
											}
										}
										remove_hook = {
											target = scope:owner
											type = weak_blackmail_hook
										}
									}
									else_if = {
										limit = {
											has_hook_of_type = {
												target = scope:owner
												type = strong_blackmail_hook
											}
										}
										remove_hook = {
											target = scope:owner
											type = strong_blackmail_hook
										}
									}
								}
								reverse_add_opinion = {
									target = scope:owner
									modifier = hate_opinion
									opinion = -20
								}
							}
						}
					}
				}
			}
		}
	}
}