﻿
###TRIGGER LIST

###SEDUCE SCHEME##
# use_seduce_secrecy_trigger


###SEXUAL ORITENTATION###
# attracted_to_same_gender_trigger_trigger
# attracted_to_opposite_gender_trigger_trigger
# attracted_to_all_genders_trigger
# matching_gender_and_sexuality_trigger

###INCEST###
# accepts_incest_with_trigger
# accepts_incest_with_each_other_trigger
# likely_to_commit_incest_trigger
# likely_to_commit_incest_with_trigger

###ATTRACTION###
# possibly_interested_in_root_trigger
# possible_mutual_interest_trigger
# object_of_importance_exist_trigger

### CHEATING ####
# might_cheat_on_partner_trigger - If scope would at all be willing to cheat, baseline that must be passed
# might_cheat_on_every_partner_trigger - checks might_cheat_on_partner_trigger on every partner
# dislikes_partner_cheating_trigger	


### PREGNANCY & STDs ###
# possible_pregnancy_after_sex_with_character_trigger - requries root and other character


###SEDUCE SCHEME TRIGGERS###

use_seduce_secrecy_trigger = {
	$OWNER$ ?= { is_alive = yes }
	$TARGET$ ?= { is_alive = yes }
	$TARGET$ = {
		NOR = {
			is_consort_of = $OWNER$
			is_courtier_of = $OWNER$
		}
	}
}


court_allow_owner_opt_out_trigger = {
	NAND = {
		is_ai = yes
		scope:target = { is_ai = no }
	}
}

###SEXUAL ORIENTATION TRIGGERS###
has_sexual_orientation_trigger = {
	OR = {
		has_sexuality = heterosexual
		has_sexuality = bisexual
		has_sexuality = homosexual
		has_sexuality = asexual
	}
}

attracted_to_same_gender_trigger = {
	OR = {
		has_sexuality = bisexual
		has_sexuality = homosexual
	}
}

attracted_to_opposite_gender_trigger = {
	OR = {
		has_sexuality = bisexual
		has_sexuality = heterosexual
	}
}

attracted_to_all_genders_trigger = {
	has_sexuality = bisexual
}


#Needs CHARACTER_1 and CHARACTER_2
matching_gender_and_sexuality_trigger = {
	$CHARACTER_1$ = { is_attracted_to_gender_of = $CHARACTER_2$ }
	$CHARACTER_2$ = { is_attracted_to_gender_of = $CHARACTER_1$ }	
}






###ATTRACTION###

possibly_interested_in_root_trigger = {
	OR = {
		AND = { #Is not related to Root, or has an indicator that they would be interested anyways
			NOR = {
				any_sibling = {
					this = root
				}
				any_parent = {
					this = root
				}
				any_child = {
					this = root
				}
			}
			OR = {
				has_relation_crush = root
				has_relation_lover = root
				has_relation_potential_lover = root
				AND = {
					is_attracted_to_men = yes
					root = { is_male = yes }
				}
				AND = {
					is_attracted_to_women = yes
					root = { is_female = yes }
				}
			}
		}
		AND = {
			OR = {
				any_sibling = {
					this = root
				}
				any_parent = {
					this = root
				}
				any_child = {
					this = root
				}
			}
			OR = {
				has_relation_crush = root
				has_relation_lover = root
				has_relation_potential_lover = root
			}
		}
	}
}

possibly_interested_in_character_trigger = {
	OR = {
		AND = { #Is not related to Root, or has an indicator that they would be interested anyways
			NOR = {
				any_sibling = {
					this = $CHARACTER$
				}
				any_parent = {
					this = $CHARACTER$
				}
				any_child = {
					this = $CHARACTER$
				}
			}
			OR = {
				has_relation_crush = $CHARACTER$
				has_relation_lover = $CHARACTER$
				has_relation_potential_lover = $CHARACTER$
				AND = {
					is_attracted_to_men = yes
					$CHARACTER$ = { is_male = yes }
				}
				AND = {
					is_attracted_to_women = yes
					$CHARACTER$ = { is_female = yes }
				}
			}
		}
		AND = {
			OR = {
				any_sibling = {
					this = $CHARACTER$
				}
				any_parent = {
					this = $CHARACTER$
				}
				any_child = {
					this = $CHARACTER$
				}
			}
			OR = {
				has_relation_crush = $CHARACTER$
				has_relation_lover = $CHARACTER$
				has_relation_potential_lover = $CHARACTER$
			}
		}
	}
}

possible_mutual_interest_trigger = {
	NOT ={ $CHARACTER_1$ = $CHARACTER_2$ } #Cannot be an event target for yourself
	$CHARACTER_1$ = {	
		OR = { #Not related etc.
			AND = {
				NOT = {
					any_sibling = {
						this = $CHARACTER_2$
					}
				}
				NOT = {
					any_parent = {
						this = $CHARACTER_2$
					}
				}
				NOT = {
					any_child = {
						this = $CHARACTER_2$
					}
				}
			}
			has_relation_crush = $CHARACTER_2$
			has_relation_lover = $CHARACTER_2$
			has_opinion_modifier = {
				modifier = love_opinion
				target = $CHARACTER_2$
			}
		}
	}
	$CHARACTER_2$ = {	
		OR = {
			AND = { #Not related etc.
				NOT = {
					any_sibling = {
						this = $CHARACTER_1$
					}
				}
				NOT = {
					any_parent = {
						this = $CHARACTER_1$
					}
				}
				NOT = {
					any_child = {
						this = $CHARACTER_1$
					}
				}
			}
			has_relation_crush = $CHARACTER_1$
			has_relation_lover = $CHARACTER_1$
			has_opinion_modifier = {
				modifier = love_opinion
				target = $CHARACTER_1$
			}
		}
	}
	$CHARACTER_1$ = {	
		OR = {
			AND = {
				is_attracted_to_men = yes
				$CHARACTER_2$ = { is_male = yes }
			}
			AND = {
				is_attracted_to_women = yes
				$CHARACTER_2$ = { is_female = yes }
			}
		}
	}
	$CHARACTER_2$ = {	
		OR = {
			AND = {
				is_attracted_to_men = yes
				$CHARACTER_1$ = { is_male = yes }
			}
			AND = {
				is_attracted_to_women = yes
				$CHARACTER_1$ = { is_female = yes }
			}
		}
	}
}


#To check if either of two lovers have a object of importance saved
	#Use LOVER to slot in the non-scope character!
object_of_importance_exist_trigger = {
	save_temporary_scope_as = original_scope
	OR = {
		AND = {
			has_variable_list = lover_object_of_importance
			variable_list_size = {
				name = lover_object_of_importance
				value = 2
			}
			is_target_in_variable_list = {
				name = lover_object_of_importance
				target = $LOVER$
			}
		}
		AND = {
			has_variable_list = lover_object_of_importance_2
			variable_list_size = {
				name = lover_object_of_importance_2
				value = 2
			}
			is_target_in_variable_list = {
				name = lover_object_of_importance_2
				target = $LOVER$
			}
		}
		$LOVER$ = {
			has_variable_list = lover_object_of_importance
			variable_list_size = {
				name = lover_object_of_importance
				value = 2
			}
			is_target_in_variable_list = {
				name = lover_object_of_importance
				target = scope:original_scope
			}
		}
		$LOVER$ = {
			has_variable_list = lover_object_of_importance_2
			variable_list_size = {
				name = lover_object_of_importance_2
				value = 2
			}
			is_target_in_variable_list = {
				name = lover_object_of_importance_2
				target = scope:original_scope
			}
		}
	}
}


might_cheat_on_partner_trigger = {
	NOT = { has_trait = celibate }
	is_eunuch_trigger = no
	trigger_if = {
		limit = { is_ai = no }
		# Players always have the option to cheat - we check this here so that we don't constantly need to OR it when using might_cheat_on_every_partner_trigger.
		always = yes
	}
	trigger_if = {
		limit = {
			$PARTNER$ = {
				government_has_flag = government_is_nomadic 
			}
		}
		NOT = {
			$PARTNER$ = {
				domicile ?= {
					has_domicile_parameter = nomad_yurt_spouse_will_not_cheat
				}
			}
		}
	}
	trigger_else_if = {
		limit = {
			# If $PARTNER$ isn't actually my partner, it's not cheating!
			OR = {
				has_relation_lover = $PARTNER$
				is_consort_of = $PARTNER$ # Includes both spouses and concubines
			}
			# Additionally, in faiths with the Polyamory doctrine, extramarital relationships aren't considered to be cheating on partners.
			# Additionally, some cultures do not have scruples about extramarital relationships.
			accepts_adultery_without_penalty_trigger = no
		}
		
		NOT = { has_trait = loyal } # Loyal people never cheat

		# Soulmates never cheat, unless they're Lustful/Seducer and have low Honor
		trigger_if = {
			limit = { has_relation_soulmate = $PARTNER$ }
			ai_honor <= medium_negative_ai_value
			calc_true_if = {
				amount >= 2
				has_trait = lustful
				has_trait = seducer
				has_focus = intrigue_temptation_focus
			}
		}
		# Non-soulmates have slightly more complex criteria
		trigger_else = {
			OR = {
				# Having one of these things that makes characters always willing to cheat:
				OR = {
					has_trait = lustful
					has_trait = seducer
					has_focus = intrigue_temptation_focus
					# Dishonorable and callous enough to not care about current partners (regardless of opinion).
					AND = {
						ai_compassion <= high_negative_ai_value
						ai_honor <= high_negative_ai_value 
					}
					# Needs aren't getting met.
					AND = {
						is_deviant_trigger = yes
						$PARTNER$ = { is_deviant_trigger = no }
					}
					# Rakish character that's about to have a mental breakdown.
					AND = {
						has_trait = rakish
						stress_level >= 2
					}
				}

				# Calc for honour.
				## Characters with really lacking honour might cheat even at decently opinion positive levels.
				trigger_if = {
					limit = { ai_honor <= high_negative_ai_value }
					# Consorts (spouses, concubines).
					trigger_if = {
						limit = { is_consort_of = $PARTNER$ }
						opinion = {
							target = $PARTNER$
							value <= medium_positive_opinion
						}
					}
					# Lovers.
					trigger_else = {
						opinion = {
							target = $PARTNER$
							value <= high_positive_opinion
						}
					}
				}
				## Characters with at least some honour require much less happy relationships.
				trigger_else_if = {
					limit = { ai_honor <= medium_positive_ai_value }
					# Consorts (spouses, concubines).
					trigger_if = {
						limit = { is_consort_of = $PARTNER$ }
						# Consorts (spouses, concubines) 
						opinion = {
							target = $PARTNER$
							value <= neutral_opinion
						}
					}
					# Lovers.
					trigger_else = {
						opinion = {
							target = $PARTNER$
							value <= low_positive_opinion # 80 for lovers
						}
					}
				}
				## Finally, characters might also cheat if they just dislike their partner enough, regardless of honor.
				trigger_else = {
					opinion = {
						target = $PARTNER$
						value <= high_negative_opinion
					}
				}
			}
		}
	}
	# Having an extramarital relationship with someone else would not count as cheating on this person.
	trigger_else = { always = yes }
}

might_cheat_on_every_partner_trigger = {
	save_temporary_scope_as = potential_cheater
	is_eunuch_trigger = no
	NOT = { has_trait = celibate }
	any_spouse = {
		count = all
		save_temporary_scope_as = partner2
		scope:potential_cheater = { might_cheat_on_partner_trigger = { PARTNER = scope:partner2 } }
	}
	any_relation = {
		type = lover
		count = all
		save_temporary_scope_as = partner3
		scope:potential_cheater = { might_cheat_on_partner_trigger = { PARTNER = scope:partner3 } }
	}
}


dislikes_partner_cheating_trigger = {
	trigger_if = {
		limit = {
			OR = {
				has_relation_lover = $PARTNER$
				is_consort_of = $PARTNER$
			}
		}
		$PARTNER$ = { save_temporary_scope_as = cheating_trigger_partner }
		save_temporary_scope_as = cheating_trigger_root
		OR = {
			AND = {
				has_relation_soulmate = $PARTNER$ # Soulmates are exclusive
				accepts_adultery_without_penalty_trigger = no
			}
			AND = {  # Feels slighted
				is_consort_of = $PARTNER$
				trait_is_shunned_or_criminal_in_faith_trigger = {
					TRAIT = adulterer
					FAITH = scope:cheating_trigger_root.faith
					GENDER_CHARACTER = scope:cheating_trigger_partner
				}
				OR = {
					ai_honor >= 0
					ai_zeal >= 0
					has_trait = arrogant
					ai_vengefulness <= 0
				}
			}
			opinion = { # Loves partner
				target = $PARTNER$
				value >= high_positive_opinion
			}
		}
		NAND = { # Sexually liberal characters don't mind, unless you're exclusive
			sexually_liberal_trigger = yes
			NOT = { has_relation_soulmate = $PARTNER$ }
		}
	}
	trigger_else = { always = no } # Partner isn't my partner, so I don't care
}

#Would a soulmate expect you to be exclusively with them?
soulmate_relation_is_exclusive_trigger = {
	accepts_adultery_without_penalty_trigger = no
}

sexually_liberal_trigger = {
	OR = {
		is_deviant_trigger = yes
		has_trait = lustful
		has_trait = seducer
		faith = { trait_is_virtue = lustful }
		AND = {
			exists = scope:activity
			has_activity_intent = lechery_intent
		}
	}
	NOR = {
		has_trait = chaste
		has_trait = celibate
	}
}

has_lustful_adjacent_trait_trigger = {
	OR = {
		is_deviant_trigger = yes
		has_trait = lustful
		has_trait = seducer
		has_trait = rakish
		faith = { trait_is_virtue = lustful }
		AND = {
			exists = scope:activity
			has_activity_intent = lechery_intent
		}
	}
	NOR = {
		has_trait = chaste
		has_trait = celibate
	}
}

#Can this character ever have an affair? Counts both inability and whether sex outside marriage is counted as religiously problematic for them.
eligible_for_affairs_trigger = {
	NOR = {
		has_trait = celibate
		#Technically (and, historically, frequently) eunuchs can still have affairs, they just aren't able to impregnate.
		OR = {
			accepts_adultery_without_penalty_trigger = yes
			trait_is_shunned_or_criminal_in_faith_trigger = {
				TRAIT = adulterer
				FAITH = root.faith
				GENDER_CHARACTER = root
			}
			trait_is_shunned_or_criminal_in_faith_trigger = {
				TRAIT = fornicator
				FAITH = root.faith
				GENDER_CHARACTER = root
			}
		}
	}
}


freely_accepts_sodomy_with_trigger = { #Will ignore sodomy consequences (because there are none or they have done this before)
	OR = {
		NOT = { relation_with_character_is_sodomy_in_my_or_lieges_faith_trigger = { CHARACTER = $CHARACTER$ } }
		has_trait = deviant
		has_trait = sodomite
		any_secret = { type = secret_homosexual }
	}
}

# 100% fine with incest with CHARACTER. Important: There are also other factors to attraction! This isn't 100% acceptance of romantic/sexual relationship.
accepts_incest_with_trigger = {
	OR = {
		NOT = { is_close_or_extended_family_of = $CHARACTER$ } #Actually no incest here!
		is_incestuous_trigger = yes
		has_relation_potential_lover = $CHARACTER$
		has_relation_lover = $CHARACTER$
	}
	save_temporary_scope_as = incest_evaluation
	NOT = { #under 20 trigger is a HARD limit
		guaranteed_under_20_incest_rejection_trigger = {
			TARGET = scope:incest_evaluation
			SEDUCER = $CHARACTER$
		}
	}
}

accepts_incest_with_each_other_trigger = {
	$CHARACTER_2$ = {
		accepts_incest_with_trigger = {
			CHARACTER = $CHARACTER_1$
		}
	}
	$CHARACTER_1$ = {
		accepts_incest_with_trigger = {
			CHARACTER = $CHARACTER_2$
		}
	}
}

#Is likely to be okay with incest broadly
likely_to_commit_incest_trigger = {
	OR = {
		AND = {
			sexually_liberal_trigger = yes
			OR = {
				# Doesn't care much about social taboo
				has_trait = callous
				has_trait = cynical
				has_trait = eccentric
				# Lack of contact with other members of their attracted sex
				has_trait = reclusive
				has_trait = shy
				# They think they can get away with it
				has_trait = deceitful
			}
		}
		# A bit of a weirdo
		is_deviant_trigger = yes
		# I've incested before, I will incest again!
		is_incestuous_trigger = yes
		# Trauma
		stress_level >= 2
	}
	save_temporary_scope_as = incest_evaluation
	NOT = { #under 20 trigger is a HARD limit
		guaranteed_under_20_incest_rejection_trigger = {
			TARGET = scope:incest_evaluation
			SEDUCER = $CHARACTER$
		}
	}
}

likely_to_commit_incest_with_trigger = {
	OR = {
		NOT = { # Not incest
			$CHARACTER_1$ = {
				relation_with_character_is_incestuous_in_my_faith_trigger = { CHARACTER = $CHARACTER_2$ }
			}
		}
		$CHARACTER_1$ = {
			OR = {
				AND = {
					sexually_liberal_trigger = yes
					OR = {
						# Doesn't care much about social taboo
						has_trait = callous
						has_trait = cynical
						has_trait = eccentric
						# Lack of contact with other members of their attracted sex
						has_trait = reclusive
						has_trait = shy
						# They think they can get away with it
						has_trait = deceitful
					}
					# Only if the other character is also likely to accept in this case
					$CHARACTER_2$ = {
						sexually_liberal_trigger = yes
						OR = {
							# Doesn't care much about social taboo
							has_trait = callous
							has_trait = cynical
							has_trait = eccentric
							# Lack of contact with other members of their attracted sex
							has_trait = reclusive
							has_trait = shy
							# Deceitful trigger not present here because CHARACTER_1 is assumed to be the instigator, CHARACTER_2 doesn't necessarily actively want this, so getting away with it wouldn't motivate them into doing it
							is_incestuous_trigger = yes
							is_deviant_trigger = yes
						}
					}
				}
				# A bit of a weirdo
				is_deviant_trigger = yes
				# I've incested before, I will incest again!
				is_incestuous_trigger = yes
				# Shared trauma
				AND = {
					any_relation = {
						type = rival
						has_relation_rival = $CHARACTER_2$
					}
					stress_level >= 1
				}
			}
			save_temporary_scope_as = incest_evaluation
			NOT = { #under 20 trigger is a HARD limit
				guaranteed_under_20_incest_rejection_trigger = {
					TARGET = scope:incest_evaluation
					SEDUCER = $CHARACTER_1$
				}
			}
		}
	}
}

guaranteed_under_20_incest_rejection_trigger = {
	$TARGET$ = {
		NOT = { is_consort_of = $SEDUCER$ }
		is_close_or_extended_family_of = $SEDUCER$
		age < 20
		age < $SEDUCER$.age
		is_ai = yes #Players are allowed to choose
	}
}

### PREGNANCY & STDs ###
possible_pregnancy_after_sex_with_character_trigger = {
	trigger_if = {
		limit = { 
			is_male = yes 
			$CHARACTER$ = { is_female = yes }
		}
		is_visibly_fertile = yes
		fertility >= 0.1

		$CHARACTER$ ={ 
			is_visibly_fertile = yes
			fertility >= 0.1
			is_pregnant = no
		}
	}

	trigger_if = {
		limit = { 
			is_female = yes 
			$CHARACTER$ = { is_male = yes }
		}
		is_visibly_fertile = yes
		fertility >= 0.1
		is_pregnant = no
			
		$CHARACTER$ = {
			is_visibly_fertile = yes
			fertility >= 0.1
		}
	}
}

accepts_adultery_without_penalty_trigger = {
	OR = {
		faith = { has_doctrine_parameter = no_unfaithfulness_penalty_active }
		culture = { has_cultural_parameter = adultery_always_accepted }
		AND = {
			government_has_flag = government_is_mandala
			house ?= { has_house_power_parameter = aspect_of_creation }
		}
	}
}
