﻿#Scripted effects relating to secrets

#####################################################################
# EFFECT LIST
#####################################################################
# !!! Remember to add all new effects with a short description here !!!

## ADD CKI_TRAIT XP TO RELEVANT SECRET REVEALS
#applies traits etc. when a secret is revealed
#SECRET = secret in question, POV = point of view i.e. who get this event
secret_exposed_owner_effects_effect = {

	$SECRET$ = {
		if = {
			limit = { #Checks to make sure the right target gets saved. Confusion might arise from the secret's "on_expose" effect since it sends the same event (secrets.0008) for both target and owner.
				exists = secret_target
				exists = scope:target
				scope:target = secret_owner
				NOT = { secret_owner = $POV$ } #To not mess up tooltips (in e.g. secrets.0108)
			}
			secret_owner = { save_scope_as = exposed_secret_target }
		}
		else_if = {
			limit = {
				exists = secret_target
			}
			secret_target = { save_scope_as = exposed_secret_target }
		}

		secret_owner = { save_scope_as = local_secret_owner }
	}

	###DEVIANT###
	if = {
		limit = { $SECRET$ = { secret_type = secret_deviant } }
		add_trait_only_force_tooltip_if_not_pov_effect = { TRAIT = deviant POV = $POV$ }
		remove_piety_level_for_shunned_or_criminal_trait_effect = { TRAIT = deviant }
	}
	###SODOMITE###
	else_if = {
		limit = {
			$SECRET$ = { secret_type = secret_homosexual }
			relation_with_character_is_sodomy_in_my_or_lieges_faith_trigger = { CHARACTER = this } #To check your own gender
		}
		add_trait_only_force_tooltip_if_not_pov_effect = { TRAIT = sodomite POV = $POV$ }
		remove_piety_level_for_shunned_or_criminal_trait_effect = { TRAIT = sodomite }
	}
	###CANNIBAL###
	else_if = {
		limit = { $SECRET$ = { secret_type = secret_cannibal } }
		add_trait_only_force_tooltip_if_not_pov_effect = { TRAIT = cannibal POV = $POV$ }
		remove_piety_level_for_shunned_or_criminal_trait_effect = { TRAIT = cannibal }
	}
	###NON-BELIEVER###
	else_if = {
		limit = { $SECRET$ = { secret_type = secret_non_believer } }
		add_character_modifier = {
			modifier = known_non_believer
			days = 3650
		}
		if = {
			limit = {
				OR = {
					has_trait = zealous
					has_character_flag = non_believer_lost_zealous
				}
			}
			remove_trait_only_force_tooltip_if_not_root_effect = { TRAIT = zealous }
			add_character_flag = {
				flag = non_believer_lost_zealous
				days = 5
			}
		}
		if = {
			limit = {
				OR = {
					number_of_personality_traits < personality_trait_limit
					has_character_flag =  non_believer_gained_cynical
				}
			}
			add_trait_only_force_tooltip_if_not_pov_effect = { TRAIT = cynical POV = $POV$ }
			add_character_flag = {
				flag = non_believer_gained_cynical
				days = 5
			}
		}
		add_piety_level = -1
	}
	###EMBEZZLER###
	else_if = {
		limit = {
			$SECRET$ = { secret_type = secret_embezzler }
			scope:secret_target = { is_alive = yes }
		}
		scope:secret_target = {
			# Apply appropriate criminal opinion.
			add_opinion = {
				target = scope:secret_owner
				modifier = embezzled_opinion
			}
		}
		scope:secret_owner = {add_cki_trait_negative_xp_effect = yes}
	}
	###INCEST###
	else_if = {
		limit = { $SECRET$ = { secret_type = secret_incest } }
		add_trait_only_force_tooltip_if_not_pov_effect = { TRAIT = incestuous POV = $POV$ }
		remove_piety_level_for_shunned_or_criminal_trait_effect = { TRAIT = incestuous }
	}
	###WITCH###
	else_if = {
		limit = { $SECRET$ = { secret_type = secret_witch } }
		add_trait_only_force_tooltip_if_not_pov_effect = { TRAIT = witch POV = $POV$ }
		remove_piety_level_for_shunned_or_criminal_trait_effect = { TRAIT = witch }
	}
	###LOVER###
	else_if = {
		limit = { $SECRET$ = { secret_type = secret_lover } }

		#Adds traits (adulterer, fornicator, sodomite, incestuous), removes devotion, sets opinions & rivalry
		extramarital_sex_exposure_consequences_with_target_effect = { TARGET = scope:exposed_secret_target SPOUSE_EVENT = no }
	}
	###DISPUTED HERITAGE###
	else_if = {
		limit = {
			$SECRET$ = {
				secret_type = secret_disputed_heritage
			}
		}

		# Child gains the Disputed Heritage trait
		scope:child = { add_trait = disputed_heritage }

		# Biological parents, if alive, suffer penalties from adultery.
		if = {
			limit = { scope:mother = { is_alive = yes } }
			scope:mother = {
				# Comprehensive effect which adds adulter/fornicator/incestuous traits, unfaithfulness & slept with wife opinions, and characters losing the appropriate number of piety level(s).
				expose_lover_secret_or_run_consequence_effect = {
					TARGET = scope:real_father
					EXPOSER = $POV$
				}
			}
		}
		else_if = { limit = { scope:real_father = { is_alive = yes } }
			# If the mother is dead, run this on the real_father instead (so it gets run somewhere). If the mother is alive, the real_father will have already suffered the penalties.
			scope:real_father = {
				expose_lover_secret_or_run_consequence_effect = {
					TARGET = scope:mother
					EXPOSER = $POV$
				}
			}
		}

		# Additional father opinion modifiers
 		hidden_effect = {
 			# Real father gains opinion of child
			if = {
				limit = {
					scope:real_father = { is_alive = yes }
				}
				scope:real_father = {
					add_opinion = {
						target = scope:child
						modifier = truly_of_my_blood_opinion
					}
				}
			}

		 	#Non-real father loses opinion of child
			if = {
				limit = {
					exists = scope:father
					scope:father = {
						is_alive = yes
					}
				}
				scope:father = {
					add_opinion = {
						target = scope:child
						modifier = uncertain_lineage_opinion
					}
				}
			}
		}
	}
	###UNKNOWN FATHER###
	else_if = {
		limit = {
			$SECRET$ = {
				secret_type = secret_unmarried_illegitimate_child
			}
		}
		# Set the correct Father for the child
		scope:child = {
			set_father = scope:real_father
			set_parent_house_effect = yes
			remove_inherited_descendent_traits_effect = yes
		}

		#Father becomes adulterer/fornicator (mother already suffered these penalties when she was discovered pregnant out of wedlock)
		scope:real_father = {
			if = {
				limit = { is_alive = yes }

				#Adds adulter/fornicator/incestuous traits, unfaithfulness & slept with wife opinions, removes piety levels
				expose_lover_secret_or_run_consequence_effect = {
					TARGET = scope:mother
					EXPOSER = $POV$
				}
			}
		}
	}

	###ATTEMPTED MURDERER###
	else_if = {
		limit = { $SECRET$ = { secret_type = secret_murder_attempt } }

		#Hide this for everyone else
		if = {
			limit = { root = scope:murderer }
			add_dread = 10
			hostile_scheme_exposure_legitimacy_effect = yes
			attempted_murder_opinion_effect = { VICTIM = scope:victim MURDERER = scope:murderer }
			scope:secret_owner = {add_cki_trait_negative_xp_effect = yes}
		}
	}
	###MURDERER###
	else_if = {
		limit = { $SECRET$ = { secret_type = secret_murder } }

 		#Traits, (crime) opinions, dread
		murder_consequences_known_or_exposed_effect = {
			MURDERER = scope:murderer
			VICTIM = scope:victim
			POV = $POV$
		}
		scope:secret_owner = {add_cki_trait_negative_xp_effect = yes}
	}
	else_if = {
		limit = {
			$SECRET$ = { secret_type = secret_coup_plotter }
			scope:secret_target = { is_alive = yes }
		}

		scope:secret_target = {
			# Apply appropriate criminal opinion.
			add_opinion = {
				target = scope:secret_owner
				modifier = coup_plotter_opinion
			}
		}
	}


	## Struggle Catalysts
	if = {
		limit = {
			scope:local_secret_owner = {
				is_semi_important_ruler_struggle_character = yes
				any_character_struggle	 = {
					involvement = involved
					phase_has_catalyst = catalyst_reveal_secret_important
				}
			}
		}
		scope:local_secret_owner = {
			every_character_struggle = {
				involvement = involved
				activate_struggle_catalyst = {
					catalyst = catalyst_reveal_secret_important
					character = scope:local_secret_owner
				}
			}
		}
	}
	if = {
		limit = {
			scope:local_secret_owner = {
				has_trait = fp3_struggle_supporter
				any_character_struggle	 = {
					involvement = involved
					phase_has_catalyst = catalyst_reveal_secret_supporter
				}
			}
		}
		scope:local_secret_owner = {
			every_character_struggle = {
				involvement = involved
				activate_struggle_catalyst = {
					catalyst = catalyst_reveal_secret_supporter
					character = scope:local_secret_owner
				}
				log_debug_variable_for_persian_struggle_effect = { VAR = unrest_catalyst_reveal_secret_supporter }
			}
		}
	}
	if = {
		limit = {
			scope:local_secret_owner = {
				has_trait = fp3_struggle_detractor
				any_character_struggle	 = {
					involvement = involved
					phase_has_catalyst = catalyst_reveal_secret_detractor
				}
			}
		}
		scope:local_secret_owner = {
			every_character_struggle = {
				involvement = involved
				activate_struggle_catalyst = {
					catalyst = catalyst_reveal_secret_detractor
					character = scope:local_secret_owner
				}
				log_debug_variable_for_persian_struggle_effect = { VAR = stabil_catalyst_reveal_secret_detractor }
			}
		}
	}
}