
#Triggers revolving around secrets

#has_secret_unknown_by_root_trigger
#Being_blackmailed_by_root_trigger
#is_blackmailable_secret_trigger
#secret_is_always_interesting_trigger





has_secret_unknown_by_root_trigger = {
	any_secret = {
		NOT = {
			is_known_by = root
		}
	}
}

being_blackmailed_by_root_trigger = {
	root = {
		OR = {
			has_hook_of_type = {
				target = prev
				type = weak_blackmail_hook
			}
			has_hook_of_type = {
				target = prev
				type = strong_blackmail_hook
			}
		}
	}
}

is_blackmailable_secret_trigger = { #Should not include is known
	$PARTICIPANT$ = { save_temporary_scope_as = is_blackmailable_secret_participant }
	$BLACKMAILER$ = { save_temporary_scope_as = is_blackmailable_secret_blackmailer }
	is_shunned_or_criminal_for = scope:is_blackmailable_secret_participant
	can_be_exposed_by = scope:is_blackmailable_secret_blackmailer
	#Can we actually add a hook of the correct type
	trigger_if = {
		limit = { is_shunned_for = scope:is_blackmailable_secret_participant }
		custom_description = {
			text = "already_has_a_superior_hook"
			subject = scope:is_blackmailable_secret_blackmailer
			object = scope:is_blackmailable_secret_participant
			scope:is_blackmailable_secret_blackmailer = {
				can_add_hook = {
					type = weak_blackmail_hook
					target = scope:is_blackmailable_secret_participant
				}
			}
		}
	}
	trigger_if = {
		limit = { is_criminal_for = scope:is_blackmailable_secret_participant }
		custom_description = {
			text = "already_has_a_superior_hook"
			subject = scope:is_blackmailable_secret_blackmailer
			object = scope:is_blackmailable_secret_participant
			scope:is_blackmailable_secret_blackmailer = {
				can_add_hook = {
					type = strong_blackmail_hook
					target = scope:is_blackmailable_secret_participant
				}
			}
		}
	}
	#Some things you can't blackmail others about
	custom_description = {
		text = "cant_blackmail_another_witch"
		subject = scope:is_blackmailable_secret_blackmailer
		NAND = {
			secret_type = secret_witch
			scope:is_blackmailable_secret_blackmailer = { is_witch_trigger = yes }
		}
	}
	trigger_if = {
		limit = { secret_type = secret_lover }
		custom_description = {
			text = cannot_blackmail_own_lover_secret
			NOT = { secret_target = scope:is_blackmailable_secret_blackmailer }
		}
	}
	trigger_if = {
		limit = {
			secret_type = secret_unmarried_illegitimate_child
		}
		custom_description = {
			text = cannot_blackmail_over_own_bastard
			NOT = { secret_target = scope:is_blackmailable_secret_blackmailer }
		}
	}
	trigger_if = {
		limit = {
			secret_type = secret_disputed_heritage
		}
		custom_description = {
			text = cannot_blackmail_over_own_bastard
			NOT = {
				secret_target = {
					OR = {
						mother = scope:is_blackmailable_secret_blackmailer
						real_father = scope:is_blackmailable_secret_blackmailer
					}
				}
			}
		}
	}
}


secret_is_always_interesting_trigger = { #Even if they can't be used for blackmail
	OR = {
		secret_type = secret_lover
		secret_type = secret_murder
		secret_type = secret_murder_attempt
		secret_type = secret_disputed_heritage
		secret_type = secret_unmarried_illegitimate_child
	}
}


#Checks whether a secret would incriminate its secret target if known
	#Parameters:
	# TARGET
secret_is_incriminating_trigger = {
	OR = {
		exists = secret_target
		any_secret_participant = {
			count >= 1
		}
	}
	OR = {
		AND = {
			secret_type = secret_lover
			secret_target = $TARGET$
		}
		AND = {
			secret_type = secret_disputed_heritage
			OR = {
				secret_target = $TARGET$
				secret_target.mother = $TARGET$
				any_secret_participant = {
					this = $TARGET$
				}
			}
		}
		AND = {
			secret_type = secret_unmarried_illegitimate_child
			OR = {
				secret_target = $TARGET$
				secret_target.mother = $TARGET$
				any_secret_participant = {
					this = $TARGET$
				}
			}
		}
	}
}



###Expose secret triggers###

block_exposed_secret_general_notifications = { #Because you're already getting your own, special event
	OR = {
		#Is one of the involved parties
		this = scope:secret_exposer
		this = scope:exposed_secret_character
		this = scope:exposed_secret_owner
		AND = {
			exists = scope:exposed_secret_target
			this = scope:exposed_secret_target
		}
		#For lover secret: No events for spouses or lovers, they get infidelity_confrontation.1000 instead
		trigger_if = {
			limit = { scope:secret = { secret_type = secret_lover } }
			OR = {
				is_spouse_of = scope:exposed_secret_owner
				has_relation_lover = scope:exposed_secret_owner
				is_spouse_of = scope:exposed_secret_target
				has_relation_lover = scope:exposed_secret_target
			}
		}
		#For bastard secrets: No events for child mother and real father
		trigger_else_if = {
			limit = {
				scope:secret = {
					OR = {
						secret_type = secret_disputed_heritage
						secret_type = secret_unmarried_illegitimate_child
					}
				}
			}
			OR = {
				scope:exposed_secret_target.mother = scope:show_me #mother
				scope:exposed_secret_target.real_father = scope:show_me #real father
			}
		}
		trigger_else = { } #Just to avoid errors
	}
}


show_me_exposed_secret_event_trigger = {
	expose_secret_scope_saving_trigger = { SECRET = $SECRET$ CHARACTER = $CHARACTER$ } #Saves show_me, exposed_secret_character, exposed_secret_owner & exposed_secret_target
	block_exposed_secret_general_notifications = no #Isn't the owner/target/exposer or other involved character
	#Is someone who cares
	OR = {
		is_spouse_of_even_if_dead = scope:exposed_secret_character
		is_close_family_of = scope:exposed_secret_character
		AND = {
			exists = scope:exposed_secret_character.player_heir
			scope:exposed_secret_character = { player_heir = scope:show_me }
		}
		AND = {
			scope:exposed_secret_character = { exists = liege }
			scope:exposed_secret_character = { liege = scope:show_me }
		}
		AND = { #For bastards, fathers also care
			$SECRET$ = { secret_type = secret_disputed_heritage }
			exists = scope:father
			this = scope:father
		}
	}
}

show_me_exposed_secret_feed_message_trigger = {
	expose_secret_scope_saving_trigger = { SECRET = $SECRET$ CHARACTER = $CHARACTER$ } #Saves show_me, exposed_secret_character, exposed_secret_owner & exposed_secret_target
	block_exposed_secret_general_notifications = no #Isn't the owner/target/exposer or other involved character
	NOT = { show_me_exposed_secret_event_trigger = { SECRET = $SECRET$ CHARACTER = $CHARACTER$ } } #I.e. hasn't already been notified
}

expose_secret_scope_saving_trigger = { #Because we save the same scopes in two triggers that need to be the same
	save_temporary_scope_as = show_me
	$CHARACTER$ = {
		save_temporary_scope_as = exposed_secret_character #Most of the time this is owner, but for secrets with targets/other involved parties it can also be them
	}
	$SECRET$ = {
		secret_owner = { save_temporary_scope_as = exposed_secret_owner }
		trigger_if = {
			limit = { exists = secret_target }
			secret_target = { save_temporary_scope_as = exposed_secret_target }
		}
	}
}

###Triggers for give_random_likely_secret_effect

give_random_likely_secret_murder_attempt_victim_trigger = {
	is_ai = yes
	save_temporary_scope_as = victim
	scope:murderer = {
		NOT = {
			any_secret = {
				secret_type = secret_murder_attempt
				secret_target = scope:victim
			}
		}
	}
}

give_random_likely_secret_lover_trigger = {
	is_adult = yes
	is_ai = yes
	NOT = { any_relation = { type = lover this = scope:lover_1 } }
	NOT = { is_spouse_of = scope:lover_1 }
	NOT = { has_trait = celibate }
	opinion = {
		target = scope:lover_1
		value >= 20
	}
	reverse_opinion = {
		target = scope:lover_1
		value >= 20
	}
	save_temporary_scope_as = lover_2
	possible_mutual_interest_trigger = { CHARACTER_1 = scope:lover_1 CHARACTER_2 = scope:lover_2 }
}

give_random_likely_secret_incestous_lover_trigger = {
	is_adult = yes
	is_ai = yes
	NOT = { any_relation = { type = lover this = scope:lover_1 } }
	NOT = { is_spouse_of = scope:lover_1 }
	OR = {
		save_temporary_scope_as = lover_2
		possible_mutual_interest_trigger = { CHARACTER_1 = scope:lover_1 CHARACTER_2 = scope:lover_2 }
		AND = {
			matching_gender_and_sexuality_trigger = { CHARACTER_1 = scope:lover_1 CHARACTER_2 = scope:lover_2 }
			opinion = {
				target = scope:lover_1
				value >= 40
			}
			reverse_opinion = {
				target = scope:lover_1
				value >= 40
			}
		}
	}
}


#Simple Check if a given Secret Type is blackmailable
	# NOTE THAT THIS CAN ONLY EVER CORRECTLY EVALUATE SECRETS THAT THE TARGET DOES NOT ALREADY HAVE
	# ALSO NOTE THAT IT WILL ONLY EVER RETURN TRUE FOR SECRETS THAT ARE NOT RELIANT ON HAVING A VALID TARGET
secret_type_is_blackmailable_simple_trigger = {
	# TYPE
	# TARGET

	save_temporary_scope_value_as = {
		name = type_flag
		value = flag:$TYPE$
	}

	trigger_if = {
		limit = {
			scope:type_flag = flag:secret_deviant
		}
		secret_deviant_is_valid_trigger = {
			OWNER = $TARGET$
		}
		OR = {
			secret_deviant_is_shunned_trigger = {
				OWNER = $TARGET$
			}
			secret_deviant_is_criminal_trigger = {
				OWNER = $TARGET$
			}
		}
	}
	trigger_else_if = {
		limit = {
			scope:type_flag = flag:secret_homosexual
		}
		secret_homosexual_is_valid_trigger = {
			OWNER = $TARGET$
		}
		OR = {
			secret_homosexual_is_shunned_trigger = {
				OWNER = $TARGET$
			}
			secret_homosexual_is_criminal_trigger = {
				OWNER = $TARGET$
			}
		}
	}
	trigger_else_if = {
		limit = {
			scope:type_flag = flag:secret_cannibal
		}
		secret_cannibal_is_valid_trigger = {
			OWNER = $TARGET$
		}
		OR = {
			secret_cannibal_is_shunned_trigger = {
				OWNER = $TARGET$
			}
			secret_cannibal_is_criminal_trigger = {
				OWNER = $TARGET$
			}
		}
	}
	trigger_else_if = {
		limit = {
			scope:type_flag = flag:secret_non_believer
		}
		secret_non_believer_is_valid_trigger = {
			OWNER = $TARGET$
		}
		OR = {
			secret_non_believer_is_shunned_trigger = {
				OWNER = $TARGET$
			}
			secret_non_believer_is_criminal_trigger = {
				OWNER = $TARGET$
			}
		}
	}
	trigger_else_if = {
		limit = {
			scope:type_flag = flag:secret_incest
		}
		secret_incest_is_valid_trigger = {
			OWNER = $TARGET$
		}
		OR = {
			secret_incest_is_shunned_trigger = {
				OWNER = $TARGET$
			}
			secret_incest_is_criminal_trigger = {
				OWNER = $TARGET$
			}
		}
	}
	trigger_else_if = {
		limit = {
			scope:type_flag = flag:secret_witch
		}
		secret_witch_is_valid_trigger = {
			OWNER = $TARGET$
		}
		OR = {
			secret_witch_is_shunned_trigger = {
				OWNER = $TARGET$
			}
			secret_witch_is_criminal_trigger = {
				OWNER = $TARGET$
			}
		}
		NOT = {
			$BLACKMAILER$ = { is_witch_trigger = yes }
		}
	}
	trigger_else = { #Murder stuff, Bastard secrets, etc.
		always = no
	}
}


random_blackmailable_secret_can_be_added_simple_trigger = {
	$TARGET$ = { save_temporary_scope_as = target }
	NOT = { has_game_rule = fake_news_off }
	OR = {
		has_game_rule = fake_news_on
		$BLACKMAILER$ = { has_perk = truth_is_relative_perk }
	}
	OR = {
		AND = {
			secret_type_is_blackmailable_simple_trigger = {
				TYPE = secret_deviant
				TARGET = scope:target
				BLACKMAILER = $BLACKMAILER$
			}
			scope:target = {
				NOT = {
					any_secret = {
						secret_type = secret_deviant
					}
				}
			}
		}
		AND = {
			secret_type_is_blackmailable_simple_trigger = {
				TYPE = secret_homosexual
				TARGET = scope:target
				BLACKMAILER = $BLACKMAILER$
			}
			scope:target = {
				NOT = {
					any_secret = {
						secret_type = secret_homosexual
					}
				}
			}
		}
		AND = {
			secret_type_is_blackmailable_simple_trigger = {
				TYPE = secret_cannibal
				TARGET = scope:target
				BLACKMAILER = $BLACKMAILER$
			}
			scope:target = {
				NOT = {
					any_secret = {
						secret_type = secret_cannibal
					}
				}
			}
		}
		AND = {
			secret_type_is_blackmailable_simple_trigger = {
				TYPE = secret_non_believer
				TARGET = scope:target
				BLACKMAILER = $BLACKMAILER$
			}
			scope:target = {
				NOT = {
					any_secret = {
						secret_type = secret_non_believer
					}
				}
			}
		}
		AND = {
			secret_type_is_blackmailable_simple_trigger = {
				TYPE = secret_incest
				TARGET = scope:target
				BLACKMAILER = $BLACKMAILER$
			}
			scope:target = {
				NOT = {
					any_secret = {
						secret_type = secret_incest
					}
				}
			}
		}
		AND = {
			secret_type_is_blackmailable_simple_trigger = {
				TYPE = secret_witch
				TARGET = scope:target
				BLACKMAILER = $BLACKMAILER$
			}
			scope:target = {
				NOT = {
					any_secret = {
						secret_type = secret_witch
					}
				}
			}
		}
	}
}