﻿seduce = {
	# Basic Setup
	skill = intrigue
	desc = seduce_desc_general
	success_desc = "SEDUCE_SUCCESS_DESC"
	icon = icon_scheme_seduce
	illustration = "gfx/interface/illustrations/event_scenes/corridor.dds"
	target_type = character
	is_secret = yes
	maximum_breaches = 5
	is_basic = yes
	
	# Travel Triggers (default no)
	freeze_scheme_when_traveling = yes
	freeze_scheme_when_traveling_target = yes

	# Parameters
	speed_per_skill_point = -2.5
	spymaster_speed_per_skill_point = 0	
	base_progress_goal = 365
	base_maximum_success = 95
	minimum_success = 5
	
	allow = {
		is_adult = yes
		trigger_if = {
			limit = { is_landless_adventurer = no }
			is_travelling = no
		}
		scope:target = {
			is_adult = yes
			trigger_if = {
				limit = {
					scope:owner = { is_landless_adventurer = no }
				}
				is_travelling = no
			}
		}

		# Mutual attraction is a hard limit because this scheme implies real romantic feelings and we don't model romantic attraction separately from sexual attraction
		OR = {
			is_ai = no	#Players may override their character's sexuality for the purposes of cynical seductions.
			scope:owner = { is_attracted_to_gender_of = scope:target }	
		}
				
		# Have I been blocked from targeting this character?
		custom_description = { #Permanent
			text = seduce_blocked
			object = scope:target

			NOT = {
				scope:target = {
					has_opinion_modifier = {
						modifier = seduce_permanent_blocker_opinion
						target = scope:owner
					}
				}
			}
		}

		# Time-limited blocker
		custom_description = {
			text = seduce_cooldown
			object = scope:target

			NOT = {
				scope:target = {
					has_opinion_modifier = {
						modifier = seduce_regular_cooldown_opinion
						target = scope:owner
					}
				}
			}
		}

		# 10 year general target blocker
		custom_description = {
			text = seduce_general_10_year_cooldown
			subject = scope:target

			NOT = {
				scope:target = {
					 has_character_flag = block_seduce_attempts
				}
			}
		}

		# They're not interested
		custom_description = {
			text = no_attraction_due_to_gender
			object = scope:target
			subject = scope:owner
			scope:target = { is_attracted_to_gender_of = scope:owner  }
		}

		is_below_ai_lover_soft_cap_trigger = yes
		trigger_if = {
			limit = { is_ai = yes }

			trigger_if = {
				limit = {
					OR = {
						is_married = yes
						num_of_relation_lover > 0
						exists = betrothed
					}
				}
				might_cheat_on_every_partner_trigger = yes
			}

			scope:target = {
				is_below_ai_lover_soft_cap_trigger = yes
				trigger_if = { # Block AI from seducing lowborn nobodies in the players court
					limit = {
						liege ?= { is_ai = no }
						NOR = {
							is_courtier_of = scope:owner
							is_foreign_court_or_pool_guest_of = scope:owner
						}
					}
					OR = {
						is_lowborn = no
						is_playable_character = yes
					}
				}
				trigger_if = { #So players don't get spammed by AI seduction
					limit = {
						is_ai = no
					}
					NOT = {
						any_targeting_scheme = {
							scheme_type = seduce
						}
					}
				}
			}
		}

		NOT = { scope:owner = { has_character_flag = is_party_baron } } # The Party Baron wants friends, not lovers!
	}
	valid = {
		is_incapable = no
		#seducing done by or to minors is not allowed.
		scope:owner = {
			is_adult = yes
		}
		scope:target = {
			is_adult = yes
		}
		#HARD-BLOCK: Incest Target is too young
		NOT = { 
			custom_description = { 
				text = SCHEME_SEDUCE_UNWILLING_INCEST_TOO_YOUNG
				object = scope:target
				guaranteed_under_20_incest_rejection_trigger = {
					TARGET = scope:target
					SEDUCER = scope:owner
				}
			}
		}
		
		#we're already lovers
		NOT = {
			custom_description = {
				text = "seduce_already_lover"
				object = scope:target
				has_relation_lover = scope:target
				NOT = { has_relation_soulmate = scope:target }
			}
		}

		#We're already soulmates
		scope:owner = {
			NOT = {
				custom_description = {
					text = "romance_already_soulmate"
					object = scope:target
					has_relation_soulmate = scope:target
				}
			}
		}

		#You've been kicked out of bed
		custom_description = { 
			text = seduce_blocked
			object = scope:target
			NOT = {
				scope:owner = {
					has_character_modifier = rejected_from_marriage_bed_modifier
					is_spouse_of = scope:target 
				}
			}
		}

		# They can't consent
		NOT = { scope:target = { has_trait = intellect_bad_3 } } # Implies a mental development level akin to an average child
		NOT = { scope:target = { has_trait = incapable } } # Bed-ridden at best, but in many cases comatose or in a vegetative state

		# One of you is celibate
		NOT = { has_trait = celibate }
		scope:target = { NOT = { has_trait = celibate } }
		
		# One of you is imprisoned
		is_imprisoned = no
		scope:target = {
			is_imprisoned = no
		}

		# You're too far away
		scope:target = {
			OR = {
				exists = location
				in_diplomatic_range = scope:owner
			}
		}
	}

	use_secrecy = {
		use_seduce_secrecy_trigger = {
			TARGET = scope:target
			OWNER = scope:owner
		}
	}

	odds_prediction = {
		add = lmf_odds_skill_contribution_intrigue_value
		add = lmf_odds_seduce_scheme_misc_value
		add = lmf_base_seduce_odds_prediction_target_is_char_value
		add = {
			value = 0
			desc = "possessed_by_lust_demon_modifier"
			if = {
				limit = {
					scope:owner = {
						has_character_modifier = possessed_by_lust_demon_modifier
					}
					scope:target = { ai_zeal > medium_positive_ai_value }
				}
				add = scope:target.ai_zeal
			}
		}
		min = 0
	}

	base_success_chance = {
		base = 0
		lmf_seduce_intrigue_success_chance_modifier = yes

		# Countermeasures.
		apply_opportunistic_scheme_success_chance_adjustments_modifier = yes
		
		# You got a wedding night memento
		modifier = {
			add = 20
			desc = "SCHEME_WNIGHT_SEDUCE_MEMENTO"
			scope:owner = {
				exists = var:wnight_seduce_memento_var
				var:wnight_seduce_memento_var = scope:target
			}
		}

		#Lust demon rep makes people wanna help you out... sexually
		modifier = {
			add = scope:target.ai_zeal
			desc = "SCHEME_LUST_DEMON_MODIFIER"
			scope:owner = {
				has_character_modifier = possessed_by_lust_demon_modifier
			}
			scope:target = {
				ai_zeal > medium_positive_ai_value
			}
		}
		
		#Language
		modifier = {
			add = -5
			desc = YOU_DONT_SPEAK_THE_LANGUAGE
			scope:owner = {
				NOT = { knows_language_of_culture = scope:target.culture }
			}
		}
		modifier = {
			add = -5
			desc = THEY_DONT_SPEAK_THE_LANGUAGE
			scope:target = {
				NOT = { knows_language_of_culture = scope:owner.culture }
			}
		}
		
		# Home Advantage perk bonus against own Courtiers and Guests
		modifier = {
			desc = SEDUCE_COURTIER_GUEST_PERK_BONUS
			scope:owner = { has_perk = home_advantage_perk }
			scope:target = {
				OR = {
					is_courtier_of = scope:owner
					is_pool_guest_of = scope:owner
					is_foreign_court_guest_of = scope:owner
				}
			}
			add = home_advantage_perk_bonus
		}
		
		# Smooth Operator perk bonus
		modifier = {
			desc = SEDUCE_PERK_BONUS
			scope:owner = { has_perk = smooth_operator_perk }
			always = yes
			add = smooth_operator_perk_bonus
		}
		
		# Legacy Bonus
		modifier = {
			desc = LEGACY_PERK_BONUS
			scope:owner = {
				dynasty ?= {
					has_dynasty_perk = fp1_adventure_legacy_2
				}
			}
			always = yes
			add = fp1_adventure_legacy_2_success_chance_seduction
		}

		# Seducer
		modifier = {
			desc = "SCHEME_SCHEMER_TRAIT"
			scope:owner = { has_trait = seducer }
			add = 25
		}

		#Beauty good
		modifier = {
			desc = "scheme_beauty_good_1"
			scope:owner = { has_trait = beauty_good_1 }
			add = 10
		}
		modifier = {
			desc = "scheme_beauty_good_2"
			scope:owner = { has_trait = beauty_good_2 }
			add = 15
		}
		modifier = {
			desc = "scheme_beauty_good_3"
			scope:owner = { has_trait = beauty_good_3 }
			add = 20
		}

		#Physique good
		modifier = {
			desc = "scheme_physique_good_1"
			scope:owner = { has_trait = physique_good_1 }
			add = 5
		}
		modifier = {
			desc = "scheme_physique_good_2"
			scope:owner = { has_trait = physique_good_2 }
			add = 10
		}
		modifier = {
			desc = "scheme_physique_good_3"
			scope:owner = { has_trait = physique_good_3 }
			add = 15
		}

		#Beauty bad
		modifier = {
			desc = "scheme_beauty_bad_1"
			scope:owner = { has_trait = beauty_bad_1 }
			add = -10
		}
		modifier = {
			desc = "scheme_beauty_bad_2"
			scope:owner = { has_trait = beauty_bad_2 }
			add = -15
		}
		modifier = {
			desc = "scheme_beauty_bad_3"
			scope:owner = { has_trait = beauty_bad_3 }
			add = -20
		}

		#Venereal diseases
		modifier = {
			desc = "scheme_great_pox"
			scope:owner = { has_trait = great_pox }
			add = -50
		}
		modifier = {
			desc = "scheme_lovers_pox"
			scope:owner = { has_trait = lovers_pox }
			add = -25
		}
		modifier = {
			desc = "scheme_early_great_pox"
			scope:owner = { has_trait = early_great_pox }
			add = -25
		}

		#Sexuality
		modifier = {
			desc = SCHEME_SEDUCE_WRONG_GENDER
			scope:owner = {
				NOR = {
					is_attracted_to_gender_of = scope:target
					has_perk = unshackled_lust_perk # Removed by the Unshackled Lust Perk
				}
			}
			add = -25
		}

		#Events
		modifier = {
			desc = scheme_promoter_of_courtly_love
			scope:owner.liege ?= {
				has_character_modifier = promoter_of_courtly_love_modifier
			}
			scope:owner.location = scope:owner.liege.location
			add = 20
		}
		modifier = {
			desc = scheme_detractor_of_courtly_love
			scope:owner.liege ?= {
				has_character_modifier = detractor_of_courtly_love_modifier
			}
			scope:owner.location = scope:owner.liege.location
			add = -20
		}
		modifier = {
			desc = scheme_family_widow_seduce_romance
			scope:owner ?= {
				var:family_widow_forbidden_divorce ?= scope:target
			}
			add = 20
		}

		#TARGET#
		# Cowardice
		modifier = {
			desc = "SCHEME_SEDUCE_TOO_COWARDLY"
			scope:target.ai_boldness < low_negative_ai_value
			add = -10
		}

		# Reveler
		modifier = {
			desc = "SCHEME_REVELER"
			scope:target = { has_trait = lifestyle_reveler }
			add = 5
		}
		
		# Lustful
		modifier = {
			desc = "SCHEME_LUSTFUL_TRAIT"
			scope:target = { has_trait = lustful }
			add = 20
		}
		
		# Eager
		modifier = {
			desc = "SCHEME_EAGER_TO_BE_SEDUCED"
			scope:target = {
				OR = {
					has_trait = seducer
					has_trait = rakish		
					is_deviant_trigger = yes
					has_focus = intrigue_temptation_focus
					faith = { trait_is_virtue = lustful }
					has_trait = maiden
				}
				NOR = {
					has_trait = chaste
					has_trait = celibate
				}
			}
			add = 10
		}
		
		# Drunkard
		modifier = {
			desc = "SCHEME_DRUNKARD_TRAIT"
			scope:target = { has_trait = drunkard }
			add = 5
		}

		#Chaste/shy
		modifier = {
			desc = "SCHEME_CHASTE_TRAIT"
			scope:target = {
				has_trait = chaste
				NOT = { is_consort_of = scope:owner }
				trait_is_shunned_or_criminal_in_faith_trigger = { TRAIT = trait:fornicator FAITH = scope:target.faith GENDER_CHARACTER = scope:target }
			}
			add = {
				value = 25
				if = {
					limit = { scope:target.ai_zeal > 25 }
					value = scope:target.ai_zeal
				}
				multiply = -1
				if = {
					limit = {
						trait_is_criminal_in_faith_trigger = { TRAIT = trait:fornicator FAITH = scope:target.faith GENDER_CHARACTER = scope:target }
					}
					multiply = 2
				}
			}
		}
		modifier = {
			desc = "SCHEME_CHASTE_TRAIT"
			scope:target = {
				has_trait = chaste
				OR = {
					is_consort_of = scope:owner
					NOT = { trait_is_shunned_or_criminal_in_faith_trigger = { TRAIT = trait:fornicator FAITH = scope:target.faith GENDER_CHARACTER = scope:target } }
				}
			}
			add = -10
		}
		
		# Celibate
		modifier = {
			desc = "SCHEME_CELIBATE_TRAIT"
			scope:target = { has_trait = celibate }
			add = -25
		}

		# Shy
		modifier = {
			desc = "SCHEME_SHY_TRAIT"
			scope:target = { has_trait = shy }
			add = -10
		}
		
		# Reclusive
		modifier = {
			desc = "SCHEME_RECLUSIVE_TRAIT"
			scope:target = { has_trait = reclusive }
			add = -10
		}
		
		# Depressed
		modifier = {
			desc = "SCHEME_DEPRESSED_TRAIT"
			scope:target = { has_trait = depressed }
			add = -5
		}
		
		# Honest
		modifier = {
			desc = "SCHEME_HONEST_TRAIT"
			scope:target = {
				has_trait = honest
				OR = {
					AND = {
						is_betrothed = yes
						NOT = { betrothed = scope:owner }
					}
					AND = {
						is_married = yes
						NOT = { is_consort_of = scope:owner }
					}
					AND = {
						num_of_relation_lover > 0
						NOR = {
							is_consort_of = scope:owner
							has_relation_lover = scope:owner
						}
					}
					AND = {
						is_ruler = no
						exists = liege
						is_close_family_of = scope:target.liege
					}
				}
			}
			add = -10
		}

		# Pious clergy
		modifier = {
			desc = THEY_ARE_CELIBATE_CLERGY
			scope:target = {
				OR = {
					is_clergy = yes
					has_council_position = councillor_court_chaplain
				}
				ai_zeal >= 0
				faith = {
					NOR = {
						has_doctrine_parameter = clergy_can_marry
						trait_is_virtue = lustful
					}
				}
			}
			add = {
				value = 20
				if = {
					limit = { scope:target.ai_zeal > 20 }
					value = scope:target.ai_zeal
				}
				multiply = -0.5
			}
		}

		#Opinion of owner
		opinion_modifier = {
			who = scope:target
			opinion_target = scope:owner
			min = -50
			max = 50
			multiplier = 1.5
			step = 5
		}

		#Target is owner's spouse
		modifier = { #
			trigger = {
				scope:target = {
					is_consort_of = scope:owner
					NOT = { has_relation_rival = scope:owner }
				}
			}
			add = 20
			desc = "SCHEME_SEDUCE_SPOUSE_BONUS"
		}

		# Too honorable for adultery
		modifier = {
			trigger = {
				scope:target = {
					is_married = yes
					OR = {
						ai_honor > 0
						ai_boldness < 0
					}
					NOT = { is_consort_of = scope:owner }
					trait_is_criminal_in_faith_trigger = { TRAIT = trait:adulterer FAITH = scope:target.faith GENDER_CHARACTER = scope:target }
				}
			}
			add = {
				value = 40
				if = {
					limit = { scope:target.ai_honor > 40 }
					value = scope:target.ai_honor
				}
				if = {
					limit = {
						scope:target.ai_cowardice > scope:target.ai_honor
						scope:target.ai_cowardice > 40
					}
					value = scope:target.ai_cowardice
				}
				multiply = -0.5
				round = yes
			}
			desc = "SCHEME_SEDUCE_UNWILLING_TO_COMMIT_ADULTERY"
		}
		modifier = {
			trigger = {
				scope:target = {
					is_married = yes
					ai_honor > 0
					NOT = { is_consort_of = scope:owner }
					trait_is_shunned_in_faith_trigger = { TRAIT = trait:adulterer FAITH = scope:target.faith GENDER_CHARACTER = scope:target }
				}
			}
			add = {
				value = 20
				if = {
					limit = { scope:target.ai_honor > 20 }
					value = scope:target.ai_honor
				}
				multiply = -0.5
				round = yes
			}
			desc = "SCHEME_SEDUCE_UNWILLING_TO_COMMIT_ADULTERY"
		}
		
		# Too honorable for fornicator
		modifier = {
			trigger = {
				scope:target = {
					is_married = no
					OR = {
						ai_honor > 0
						ai_boldness < 0
					}
					trait_is_criminal_in_faith_trigger = { TRAIT = trait:fornicator FAITH = scope:target.faith GENDER_CHARACTER = scope:target }
				}
			}
			add = {
				value = 40
				if = {
					limit = { scope:target.ai_honor > 40 }
					value = scope:target.ai_honor
				}
				if = {
					limit = {
						scope:target.ai_cowardice > scope:target.ai_honor
						scope:target.ai_cowardice > 40
					}
					value = scope:target.ai_cowardice
				}
				multiply = -0.5
				round = yes
			}
			desc = "SCHEME_SEDUCE_UNWILLING_TO_FORNICATE"
		}
		modifier = {
			trigger = {
				scope:target = {
					is_married = no
					ai_honor > 0
					trait_is_shunned_in_faith_trigger = { TRAIT = trait:fornicator FAITH = scope:target.faith GENDER_CHARACTER = scope:target }
				}
			}
			add = {
				value = 20
				if = {
					limit = { scope:target.ai_honor > 20 }
					value = scope:target.ai_honor
				}
				multiply = -0.5
				round = yes
			}
			desc = "SCHEME_SEDUCE_UNWILLING_TO_FORNICATE"
		}
		
		# Doesn't want to become a sodomite
		modifier = {
			trigger = {
				scope:target = {
					relation_with_character_is_sodomy_in_my_or_lieges_faith_trigger = { CHARACTER = scope:owner }
					trait_is_shunned_or_criminal_in_faith_trigger = { TRAIT = trait:sodomite FAITH = scope:target.faith GENDER_CHARACTER = scope:target }
					NOR = {
						freely_accepts_sodomy_with_trigger = { CHARACTER = scope:owner }
						has_perk = unshackled_lust_perk
					}
				}
			}
			add = {
				value = 40
				if = {
					limit = { scope:target.ai_honor > 40 }
					value = scope:target.ai_honor
				}
				if = {
					limit = {
						scope:target.ai_cowardice > scope:target.ai_honor
						scope:target.ai_cowardice > 40
						trait_is_criminal_in_faith_trigger = { TRAIT = trait:sodomite FAITH = scope:target.faith GENDER_CHARACTER = scope:target }
					}
					value = scope:target.ai_cowardice
				}
				multiply = -0.5
				round = yes
			}
			desc = "SCHEME_SEDUCE_UNWILLING_TO_SODOMITE"
		}
		
		# Doesn't want to be a lesbian
		modifier = {
			trigger = {
				scope:target = {
					is_female = yes
					relation_with_character_is_samesex_forbidden_in_my_or_lieges_faith_trigger = { CHARACTER = scope:owner }
					ai_honor > 0
				}
			}
			add = {
				value = 20
				if = {
					limit = { scope:target.ai_honor > 20 }
					value = scope:target.ai_honor
				}
				multiply = -0.5
				round = yes
			}
			desc = "SCHEME_SEDUCE_UNWILLING_LESBIAN"
		}		
		
		# Unwilling to cheat on spouse
		modifier = {
			trigger = {
				scope:target = {
					is_married = yes
					NOT = { is_consort_of = scope:owner }
					any_spouse = {
						save_temporary_scope_as = partner
						scope:target = {
							NOT = {
								might_cheat_on_partner_trigger = { PARTNER = scope:partner }
							}
						}
					}
				}
			}
			add = {
				value = -50
				if = {
					limit = {
						scope:target = {
							any_spouse = { has_relation_soulmate = scope:target }
						}
					}
					multiply = 5
				}
				if = {
					limit = {
						scope:owner = { is_ai = yes }
					}
					multiply = 3
				}
			}
			desc = "SCHEME_SEDUCE_UNWILLING_CHEAT_SPOUSE"
		}
		
		# Unwilling to cheat on betrothed
		modifier = {
			trigger = {
				scope:target = {
					is_married = no
					is_betrothed = yes
					NOR = {
						betrothed = scope:owner
						might_cheat_on_partner_trigger = { PARTNER = scope:target.betrothed }
					}
				}
			}
			add = {
				value = -25
				if = {
					limit = {
						scope:target = { has_relation_soulmate = scope:target.betrothed }
					}
					multiply = 10
				}
				if = {
					limit = {
						scope:owner = { is_ai = yes }
					}
					multiply = 2
				}
			}
			desc = "SCHEME_SEDUCE_UNWILLING_CHEAT_BETROTHED"
		}

		# Unwilling to cheat on lover
		modifier = {
			desc = "SCHEME_SEDUCE_UNWILLING_CHEAT_LOVER"
			add = {
				value = -25
				if = {
					limit = {
						scope:target = {
							any_relation = {
								type = soulmate
								NOR = {
									is_spouse_of = scope:target
									betrothed ?= scope:target
								}
							}
						}
					}
					multiply = 10
				}
				if = {
					limit = {
						scope:owner = { is_ai = yes }
					}
					multiply = 2
				}
			}
			scope:target = {
				any_relation = {
					type = lover
					NOR = {
						is_spouse_of = scope:target
						betrothed ?= scope:target
					}
					save_temporary_scope_as = partner
					scope:target = {
						NOT = {
							might_cheat_on_partner_trigger = { PARTNER = scope:partner }
						}
					}
				}
			}
		}

		# Willing to cheat on spouse, but has high opinion of them
		modifier = {
			trigger = {
				scope:target = {
					is_married = yes
					NOT = { is_consort_of = scope:owner }
					primary_spouse ?= { save_temporary_scope_as = target_spouse }
					might_cheat_on_partner_trigger = { PARTNER = scope:target_spouse }
					opinion = { target = scope:target_spouse value > low_positive_opinion }
				}
			}
			# Branching logic for opinion checks, to save performance
			add = {
				value = 0
				scope:target = {
					if = { # Hard block for AI seducers, they don't need the granularity and opinion checks are expensive performance-wise. 
						limit = { scope:owner = { is_ai = yes }}
						add = -1000
					}
					else_if = { # Players get scaling penalties depending on how high their target's opinion is of their primary spouse.
						limit = {
							has_relation_soulmate = scope:target_spouse
						}
						add = -250
					}
					else_if = {
						limit = {
							opinion = {
								target = scope:target_spouse
								value >= high_positive_opinion
							}
						}
						if = {
							limit = {
								opinion = {
									target = scope:target_spouse
									value < very_high_positive_opinion
								}
							}
							# Opinion between 80 and 100
							add = -50
						}
						else = {
							# Opinion between 60 and 80
							add = -35
						}
					}
					else = {
						if = {
							limit = {
								opinion = {
									target = scope:target_spouse
									value >= medium_positive_opinion
								}
							}
							# Opinion between 40 and 60
							add = -25
						}
						else = {
							# Opinion between 0 and 40 (technically -100 and 40 but at below 0 we shouldn't be in this trigger block at all since 'might_cheat_on_partner_trigger' will have passed).
							add = -10
						}
					}
				}
			}
			desc = "SCHEME_SEDUCE_SPOUSE_OPINION_PENALTY"
		}

		# Willing to cheat on betrothed, but has high opinion of them
		modifier = {
			trigger = {
				scope:target = {
					is_married = no
					is_betrothed = yes
					exists = betrothed
					NOT = { betrothed = scope:owner }
					betrothed = { save_temporary_scope_as = target_spouse }
					might_cheat_on_partner_trigger = { PARTNER = scope:target_spouse }
					opinion = { target = scope:target_spouse value > medium_positive_opinion }
				}
			}
			# Branching logic for opinion checks, to save performance
			add = {
				value = 0
				scope:target = {
					if = { # Hard block for AI seducers, they don't need the granularity and opinion checks are expensive performance-wise. 
						limit = { scope:owner = { is_ai = yes }}
						add = -1000
					}
					else_if = { # Players get scaling penalties depending on how high their target's opinion is of their primary spouse.
						limit = {
							has_relation_soulmate = scope:target_spouse
						}
						add = -250
					}
					else_if = {
						limit = {
							opinion = {
								target = scope:target_spouse
								value >= high_positive_opinion
							}
						}
						if = {
							limit = {
								opinion = {
									target = scope:target_spouse
									value < very_high_positive_opinion
								}
							}
							# Opinion between 80 and 100
							add = -30
						}
						else = {
							# Opinion between 60 and 80
							add = -20
						}
					}
					else = {
						add = -10
					}
				}
			}
			desc = "SCHEME_SEDUCE_BETROTHED_OPINION_PENALTY"
		}

		# Willing to cheat on spouse, has low opinion of them
		modifier = {
			trigger = {
				scope:target = {
					is_married = yes
					NOT = { is_consort_of = scope:owner }
					primary_spouse ?= { save_temporary_scope_as = target_spouse }
					might_cheat_on_partner_trigger = { PARTNER = scope:target_spouse }
					opinion = { target = scope:target_spouse value < low_negative_opinion }
				}
			}
			add = {
				value = 10
				if = {
					limit = {
						scope:target = {
							opinion = {
								target = scope:target_spouse
								value <= high_negative_opinion
							}
						}
					}
					add = 20
				}
				else_if = {
					limit = {
						scope:target = {
							opinion = {
								target = scope:target_spouse
								value <= medium_negative_opinion
							}
						}
					}
					add = 10
				}
			}
			desc = "SCHEME_SEDUCE_SPOUSE_OPINION_BONUS"
		}

		#Does their spouse have a strong hook on them?
		modifier = {
			trigger = {
				scope:target = {
					exists = primary_spouse
					NOT = { is_consort_of = scope:owner }
					primary_spouse = { has_strong_hook = scope:target }
				}
			}
			add = -100
			desc = SCHEME_SEDUCE_SPOUSE_STRONG_HOOK_PENALTY
		}

		# Intended for marriage
		modifier = {
			trigger = {
				scope:target = {
					is_married = no
					is_betrothed = no
					is_ruler = no
					can_marry_trigger = yes
					age < 25
					NOR = {
						num_of_relation_lover > 0
						is_close_family_of = scope:owner
						likely_to_take_lover_trigger = yes
						has_trait = impatient
					}
					exists = liege
					is_close_family_of = scope:target.liege
				}
			}
			add = -10
			desc = "SCHEME_SEDUCE_MUST_MARRY"
		}
		
		# Trait similarity to owner
		compatibility_modifier = {
			who = scope:target
			compatibility_target = scope:owner
			min = -30
			max = 30
			multiplier = 2
		}

		# Rank tier difference (landed target/target whose liege doesn't care)
		modifier = { #3 or more higher rank
			trigger = { personal_scheme_should_not_evaluate_tier_differences_trigger = yes }
			add = 40
			desc = "HIGHER_RANK_THAN_SCHEME_TARGET"
			scope:target = {
				personal_scheme_success_compare_target_liege_tier_trigger = no
				NOT = {
					is_theocratic_lessee = yes
				}
			}
			scope:owner = {
				tier_difference = {
					target = scope:target
					value >= 3
				}
			}
		}
		modifier = { #2 higher rank
			trigger = { personal_scheme_should_not_evaluate_tier_differences_trigger = yes }
			add = 20
			desc = "HIGHER_RANK_THAN_SCHEME_TARGET"
			scope:target = {
				personal_scheme_success_compare_target_liege_tier_trigger = no
				NOT = {
					is_theocratic_lessee = yes
				}
			}
			scope:owner = {
				tier_difference = {
					target = scope:target
					value = 2
				}
			}
		}
		modifier = { #1 higher rank
			trigger = { personal_scheme_should_not_evaluate_tier_differences_trigger = yes }
			add = 10
			desc = "HIGHER_RANK_THAN_SCHEME_TARGET"
			scope:target = {
				personal_scheme_success_compare_target_liege_tier_trigger = no
				NOT = {
					is_theocratic_lessee = yes
				}
			}
			scope:owner = {
				tier_difference = {
					target = scope:target
					value = 1
				}
			}
		}
		modifier = { #1 lower rank
			trigger = {
				scope:owner = {
					NOT = { is_consort_of = scope:target } # Your spouse doesn't care if you're a different rank than them.
					NOT = { has_perk = subtle_desire_perk }
				}
			}
			add = -15
			desc = "LOWER_RANK_THAN_SCHEME_TARGET"
			scope:target = {
				personal_scheme_success_compare_target_liege_tier_trigger = no
			}
			scope:owner = {
				tier_difference = {
					target = scope:target
					value = -1
				}
			}
		}
		modifier = { #2 lower rank
			trigger = {
				scope:owner = {
					NOT = { is_consort_of = scope:target } # Your spouse doesn't care if you're a different rank than them.
					NOT = { has_perk = subtle_desire_perk }
				}
			}
			add = -30
			desc = "LOWER_RANK_THAN_SCHEME_TARGET"
			scope:target = {
				personal_scheme_success_compare_target_liege_tier_trigger = no
			}
			scope:owner = {
				tier_difference = {
					target = scope:target
					value = -2
				}
			}
		}
		modifier = { #3 or less lower rank
			trigger = {
				scope:owner = {
					NOT = { is_consort_of = scope:target } # Your spouse doesn't care if you're a different rank than them.
					NOT = { has_perk = subtle_desire_perk }
				}
			}
			add = -60
			desc = "LOWER_RANK_THAN_SCHEME_TARGET"
			scope:target = {
				personal_scheme_success_compare_target_liege_tier_trigger = no
			}
			scope:owner = {
				tier_difference = {
					target = scope:target
					value <= -3
				}
			}
		}

		#Rank tier difference (unlanded character)
		modifier = { #3 or more higher rank
			trigger = { personal_scheme_should_not_evaluate_tier_differences_trigger = yes }
			add = 50
			desc = "HIGHER_RANK_THAN_SCHEME_TARGET_LIEGE"
			scope:target = {
				personal_scheme_success_compare_target_liege_tier_trigger = yes
				NOT = {
					is_theocratic_lessee = yes
				}
			}
			scope:owner = {
				tier_difference = {
					target = scope:target.liege
					value >= 3
				}
			}
		}
		modifier = { #2 higher rank
			trigger = { personal_scheme_should_not_evaluate_tier_differences_trigger = yes }
			add = 25
			desc = "HIGHER_RANK_THAN_SCHEME_TARGET_LIEGE"
			scope:target = {
				personal_scheme_success_compare_target_liege_tier_trigger = yes
				NOT = {
					is_theocratic_lessee = yes
				}
			}
			scope:owner = {
				tier_difference = {
					target = scope:target.liege
					value = 2
				}
			}
		}
		modifier = { #1 higher rank
			trigger = { personal_scheme_should_not_evaluate_tier_differences_trigger = yes }
			add = 10
			desc = "HIGHER_RANK_THAN_SCHEME_TARGET_LIEGE"
			scope:target = {
				personal_scheme_success_compare_target_liege_tier_trigger = yes
				NOT = {
					is_theocratic_lessee = yes
				}
			}
			scope:owner = {
				tier_difference = {
					target = scope:target.liege
					value = 1
				}
			}
		}
		modifier = { #1 lower rank
			trigger = { 
				scope:owner = {
					personal_scheme_should_not_evaluate_tier_differences_trigger = yes
					NOT = { has_perk = subtle_desire_perk }
				}
			}
			add = -15
			desc = "LOWER_RANK_THAN_SCHEME_TARGET_LIEGE"
			scope:target = {
				personal_scheme_success_compare_target_liege_tier_trigger = yes
			}
			scope:owner = {
				tier_difference = {
					target = scope:target.liege
					value = -1
				}
			}
		}
		modifier = { #2 lower rank
			trigger = { 
				scope:owner = {
					personal_scheme_should_not_evaluate_tier_differences_trigger = yes
					NOT = { has_perk = subtle_desire_perk }
				}
			}
			add = -30
			desc = "LOWER_RANK_THAN_SCHEME_TARGET_LIEGE"
			scope:target = {
				personal_scheme_success_compare_target_liege_tier_trigger = yes
			}
			scope:owner = {
				tier_difference = {
					target = scope:target.liege
					value = -2
				}
			}
		}
		modifier = { #3 or less lower rank
			trigger = { 
				scope:owner = {
					personal_scheme_should_not_evaluate_tier_differences_trigger = yes
					NOT = { has_perk = subtle_desire_perk }
				}
			}
			add = -60
			desc = "LOWER_RANK_THAN_SCHEME_TARGET_LIEGE"
			scope:target = {
				personal_scheme_success_compare_target_liege_tier_trigger = yes
			}
			scope:owner = {
				tier_difference = {
					target = scope:target.liege
					value <= -3
				}
			}
		}

		#Extra rank bonus/penalty if target is arrogant/ambitious
		modifier = {
			trigger = { scope:owner = { NOT = { is_consort_of = scope:target } } } # No 'social climbing' if you're already their spouse!
			desc = SCHEME_SOCIAL_CLIMBER_RANK_BONUS
			add = 10
			scope:target = {
				OR = {
					has_trait = arrogant
					has_trait = ambitious
					has_trait = greedy
				}
				NOT = {
					is_theocratic_lessee = yes
				}
			}
			OR = {
				AND = {
					scope:target = { personal_scheme_success_compare_target_liege_tier_trigger = yes }
					scope:owner.highest_held_title_tier > scope:target.liege.highest_held_title_tier
				}
				AND = {
					scope:target = { personal_scheme_success_compare_target_liege_tier_trigger = no }
					scope:owner.highest_held_title_tier > scope:target.highest_held_title_tier
				}
			}
		}
		modifier = {
			trigger = { scope:owner = { NOT = { is_consort_of = scope:target } } } # No 'social climbing' if you're already their spouse!
			desc = SCHEME_SOCIAL_CLIMBER_RANK_PENALTY
			add = -10
			scope:target = {
				OR = {
					has_trait = arrogant
					has_trait = ambitious
					has_trait = greedy
				}
			}
			OR = {
				AND = {
					scope:target = { personal_scheme_success_compare_target_liege_tier_trigger = yes }
					scope:owner.highest_held_title_tier < scope:target.liege.highest_held_title_tier
				}
				AND = {
					scope:target = { personal_scheme_success_compare_target_liege_tier_trigger = no }
					scope:owner.highest_held_title_tier < scope:target.highest_held_title_tier
				}
			}
		}

		# Diarchs are better at schemes within their liege's realm
		diarch_scheming_within_realm_bonus_modifier = yes

		#Religious Heads
		modifier = {
			add = -50
			desc = "SCHEME_VS_RELIGIOUS_HEAD"
			scope:target = {
				faith = scope:owner.faith
				faith = {
					religious_head ?= {
						this = scope:target
					}
				}
			}
		}

		#Taboo
		modifier = { #Incest is taboo (norms & consequences)
			add = -25
			desc = SCHEME_SEDUCE_TABOO_INCEST
			scope:target = {
				relation_with_character_is_incestuous_in_my_or_lieges_faith_trigger = { CHARACTER = scope:owner }
			}
			scope:owner = { # The Subtle Desire Perk nullifies this
				NOT = { has_perk = subtle_desire_perk }
			}
		}
		modifier = { #Character is not willing to engage in incest with scope:owner
			add = {
				if = {
					limit = { scope:target = { is_close_family_of = scope:owner } }
					value = -40
				}
				else_if = {
					limit = { scope:target = { is_extended_family_of = scope:owner } }
					value = -15
				}
				if = {
					limit = { scope:target = { is_deviant_trigger = yes } }
					add = 15
				}
			}
			desc = SCHEME_SEDUCE_UNWILLING_INCEST
			scope:target = {
				NOT = { is_consort_of = scope:owner }
				is_close_or_extended_family_of = scope:owner
				NOR = {
					accepts_incest_with_trigger = { CHARACTER = scope:owner } #100% fine with incest with owner
					scope:owner = { has_perk = subtle_desire_perk }  # The Subtle Desire Perk nullifies this
					guaranteed_under_20_incest_rejection_trigger = { # handled by hard block modifier
						TARGET = scope:target
						SEDUCER = scope:owner
					}
				}
			}
		}
		modifier = { #Incest hard block
			add = -1000
			desc = SCHEME_SEDUCE_UNWILLING_INCEST
			guaranteed_under_20_incest_rejection_trigger = {
				TARGET = scope:target
				SEDUCER = scope:owner
			}
		}

		# Dynasty Kin Personal Scheme Success Chance on Dynasty Perk
		modifier = {
			add = kin_legacy_4_success_chance
			desc = KIN_LEGACY_DESC
			scope:owner.dynasty ?= {
				has_dynasty_perk = kin_legacy_4
			}
			scope:target.dynasty = scope:owner.dynasty
		}

		# House Personal Scheme Success Chance on Cultural Parameter
		modifier = {
			add = cultural_house_personal_scheme_success_chance
			desc = KIN_PARAMETER_DESC
			exists = scope:owner.house
			exists = scope:target.house
			scope:owner.culture = {
				has_cultural_parameter = cultural_house_personal_scheme_success_chance
			}
			scope:target.house = scope:owner.house
		}

		# Charmer Accolade
		modifier = {
			add = accolade_seduction_vulnerability_value
			desc = ACCOLADE_COURT_SEDUCTION_VULNERABILITY_DESC
			scope:target = {
				host ?= {
					any_active_accolade = {
						accolade_parameter = accolade_court_seduction_vulnerability
					}
				}
			}
		}

		# Modifiers
		modifier = {
			scope:owner = { has_character_modifier = poet_for_seduction_schemes_modifier }
			desc = poet_for_seduction_schemes_modifier
			add = 20
		}
		
		modifier = {
			scope:target = {
				court_owner ?= {
					has_character_flag = keeper_of_the_harem_maintaining_decorum
				}
				is_consort_of = scope:target.court_owner
				NOT = {
					is_consort_of = scope:owner
				}
			}
			add = -50
		}

		# Personal Scheme Shared
		personal_scheme_base_success_chance_modifiers = yes
		
		# Same Location Bonus
		modifier = {
			add = 10
			desc = SAME_LOCATION_BONUS_DESC
			exists = global_var:travel_the_distance_is_loaded
			scope:owner = { is_in_the_same_court_as = scope:target }
		}

		# Distance Penalty
		ttd_major_distance_pentalty_modifier = yes
	}

	base_secrecy = {
		add = secrecy_base_value
		add = countermeasure_apply_secrecy_maluses_value
	}
	
	# On Actions
	on_start = {
		set_variable = {
			name = apply_countermeasures
			value = flag:opportunistic
		}
		#Handle incest hard reject
		save_scope_as = scheme
		scheme_owner = { save_scope_as = owner }
		scheme_target_character = { save_scope_as = target }

		if = {
			limit = {
				scope:target = {
					is_close_or_extended_family_of = scope:owner
					NOT = { is_consort_of = scope:owner }
				}
			}
			scope:target = {
				trigger_event = {
					id = seduce_outcome.8101 #Hard reject event, ai weights on options determine yes/no
					days = { 7 14 }
				}
			}
		}
		else_if = {
			limit = {
				scope:target = {
					house_has_feud_relation_with_trigger = { TARGET = scope:owner }
				}
			}
			scope:target = {
				trigger_event = {
					id = bp1_house_feud.0700 #Hard reject event, ai weights on options determine yes/no
					days = { 7 14 }
				}
			}
		}
	}
	on_phase_completed = {
		# Grab our scopes.
		save_scope_as = scheme
		scheme_target_character = { save_scope_as = target }
		scheme_owner = { save_scope_as = owner }
		# Set up a block for the inappropriate cheating error?
		save_scope_value_as = {
			name = ignore_cheating_error_check
			value = yes
		}
		# Proceed to rolls.
		scope:scheme.scheme_owner = {
			#Do I want to proceed to a roll?
			if = {
				limit = {
					is_ai = no
					use_seduce_secrecy_trigger = {
						TARGET = scope:target
						OWNER = scope:owner
					}
				}
				trigger_event = seduce_outcome.0001
			}
			else_if = {
				limit = {
					is_ai = yes
					OR = {
						is_married = yes
						num_of_relation_lover > 0
						exists = betrothed
					}
					might_cheat_on_every_partner_trigger = no
				}
				scope:scheme = { end_scheme = yes }
			}
			#Jump straight to roll
			else = {
				trigger_event = seduce_outcome.0002
			}
		}
	}
	on_monthly = {
		save_scope_as = scheme
		scheme_owner = { save_scope_as = owner }
		scheme_target_character = { save_scope_as = target }

		hostile_scheme_monthly_discovery_chance_effect = yes

		#Milestone 1 event
		if = {
			limit = {
				scheme_progress < scheme_progress_50
				NOR = {
					has_scheme_modifier = seduce_success_1_modifier
					has_scheme_modifier = seduce_failure_1_modifier
					has_variable = declined_seduce_milestone_1_event
				}
				scheme_owner = {
					is_available = yes
				}
				scheme_target_character = {
					is_available = yes
				}
				player_target_available_for_personal_scheme_ongoing_events_trigger = {
					OWNER = scope:owner
					TARGET = scope:target
				}
			}
			scheme_owner = {
				trigger_event = { on_action = seduce_ongoing_milestone_1 }
			}
		}
		#Milestone 2 event
		else_if = {
			limit = {
				scheme_progress >= scheme_progress_50
				NOR = {
					has_scheme_modifier = seduce_success_2_modifier
					has_scheme_modifier = seduce_failure_2_modifier
					has_variable = declined_seduce_milestone_2_event
				}
				scheme_owner = {
					is_available = yes
				}
				scheme_target_character = {
					is_available = yes
				}
				player_target_available_for_personal_scheme_ongoing_events_trigger = {
					OWNER = scope:owner
					TARGET = scope:target
				}
			}
			scheme_owner = {
				trigger_event = { on_action = seduce_ongoing_milestone_2 }
			}
		}
	}
	on_invalidated = {
		save_scope_as = scheme
		scheme_target_character = {
			save_scope_as = target
		}
		scheme_owner = {
			save_scope_as = owner
		}
		if = {
			limit = {
				scope:target = { is_alive = no }
			}
			scope:owner = {
				trigger_event = seduce_outcome.0005
			}
		}
		#I am already their lover!
		if = {
			limit = {
				NOT = { scheme_progress = scope:scheme.scheme_phase_duration }
				scope:owner = { has_relation_lover = scope:target }
			}
			scope:owner = {
				trigger_event = seduce_outcome.0004
			}
		}
		else_if = { #fallback invalidation
			limit = {
				OR = {
					#We're already soulmates
					scope:owner = {
						has_relation_soulmate = scope:target
					}

					#We're already lovers
					scope:owner = {
						has_relation_lover = scope:target
					}

					#You've been kicked out of bed
					scope:owner = {
						has_character_modifier = rejected_from_marriage_bed_modifier
						is_spouse_of = scope:target 
					}
						
					scope:owner = {  has_trait = celibate  }
					scope:target = {  has_trait = celibate }
					
					scope:owner = { is_imprisoned = yes }
					scope:target = { is_imprisoned = yes }

					scope:target = {
						NOR = {
							exists = location
							in_diplomatic_range = scope:owner
						}
					}
				}
			}
			scope:owner = {
				send_interface_toast = {
					type = event_toast_effect_neutral
					title = seduce
					left_icon = scope:target
					custom_tooltip = seduce_invalid
				}
			}
		}

		if = {
			limit = {
				scope:target = { 
					NOT = { in_diplomatic_range = scope:owner } 
				}
			}
			scope:owner = {
				send_interface_toast = {
					type = event_toast_effect_neutral
					title = seduce_invalidated_title
					left_icon = scope:target
					custom_description_no_bullet = {
						object = scope:target
						text = scheme_target_not_in_diplomatic_range
					}
				}
			}
		}
	}
}

