﻿might_cheat_on_partner_trigger = {

	### Regula devoted don't cheat.
	trigger_if = {
		limit = { has_trait = devoted_trait_group }
		always = no
	}

	trigger_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.
			NOT = { faith = { has_doctrine_parameter = no_unfaithfulness_penalty_active } }
		}

		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
			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

					AND = {
						# Dishonorable and callous enough to not care about current partners (regardless of opinion).
						ai_compassion <= high_negative_ai_value
						ai_honor <= high_negative_ai_value
					}
					AND = {
						# Needs aren't getting met
						is_deviant_trigger = yes
						$PARTNER$ = { is_deviant_trigger = no }
					}
				}

				# Otherwise, they need to not be honorable and not have a strong like of this partner
				AND = {
					ai_honor < high_positive_ai_value
					trigger_if = {
						limit = {
							is_consort_of = $PARTNER$
						}
						opinion = {
							target = $PARTNER$
							value <= high_positive_opinion # 60 for spouses/concubines
						}
					}
					trigger_else = {
						opinion = {
							target = $PARTNER$
							value <= very_high_positive_opinion # 80 for lovers
						}
					}
				}

				# Might also cheat if they just dislike their partner, regardless of honor
				AND = {
					opinion = {
						target = $PARTNER$
						value < neutral_opinion # -1 or lower for spouses, concubines, or lovers
					}
				}
			}
		}
	}
	trigger_else = { always = yes } # Having an extramarital relationship with someone else would not count as cheating on this person.
}

### This should shut down the random lover events.
can_set_relation_lover_trigger = {
	is_adult = yes
	NOT = { this = $CHARACTER$ }
	is_attracted_to_gender_of = $CHARACTER$
	$CHARACTER$ = {
		is_adult = yes
		is_attracted_to_gender_of = prev
	}
	NOT = { has_relation_lover = $CHARACTER$ }

	# Devoted and Magister can have each other as lovers but nobody else
	NOR = {
		AND = {
			NOT = {
				$CHARACTER$ = {
					OR = {
						has_trait = magister_trait_group
						has_trait = devoted_trait_group
					}
				}
			}
			has_trait = devoted_trait_group
		}
		AND = {
			$CHARACTER$ = {
				OR = {
					has_trait = devoted_trait_group
				}
			}
			NOR = {
				has_trait = magister_trait_group
				has_trait = devoted_trait_group
			}
		}
	}
}

can_set_relation_soulmate_trigger = {
	is_adult = yes
	NOT = { this = $CHARACTER$ }
	is_attracted_to_gender_of = $CHARACTER$
	$CHARACTER$ = {
		is_adult = yes
		is_attracted_to_gender_of = prev
	}
	NOR = {
		has_relation_rival = $CHARACTER$
		has_relation_nemesis = $CHARACTER$
		AND = {
			NOT = {
				$CHARACTER$ = {
					OR = {
						has_trait = magister_trait_group
						has_trait = devoted_trait_group
					}
				}
			}
			has_trait = devoted_trait_group
		}
		AND = {
			$CHARACTER$ = {
				OR = {
					has_trait = devoted_trait_group
				}
			}
			NOR = {
				has_trait = magister_trait_group
				has_trait = devoted_trait_group
			}
		}
	}
	num_of_relation_soulmate = 0
	$CHARACTER$ = { num_of_relation_soulmate = 0 }
}
