﻿## Vanilla ##
set_primary_spouse_interaction = {
	category = interaction_category_diplomacy
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:actor.faith.religion != religion:islam_religion
				}
				desc = set_primary_spouse_interaction_desc
			}
			desc = set_primary_spouse_interaction_islam_desc
		}
	}
	icon = icon_marriage

	auto_accept = yes

	is_shown = {
		scope:actor = {
			is_spouse_of = scope:recipient
		}
		scope:actor.primary_spouse != scope:recipient
	}
	is_valid_showing_failures_only = {
		scope:recipient = {
			NOT = {
				has_trait = incapable
			}
		}
		custom_tooltip = {
			text = switched_primary_spouse_flag_desc
			scope:actor = {
				NOT = { has_character_flag = switched_primary_spouse_flag }
			}
		}
	}

	on_accept = {
		set_primary_spouse_effect = yes
		scope:actor = {
			custom_tooltip = set_primary_spouse_effect_tooltip
			add_character_flag = {
				flag = switched_primary_spouse_flag
				years = 1
			}
			add_character_flag = {
				flag = recently_set_primary_spouse_flag
				years = 3
			}
		}
	}

	ai_targets = {
		ai_recipients = spouses
	}
	ai_target_quick_trigger = {
		adult = yes
	}
	ai_frequency_by_tier = {
		barony = 0
		county = 0
		duchy = 144
		kingdom = 72
		empire = 72
		hegemony = 72
	}

	ai_potential = {
		any_spouse = {
			count >= 2
		}
	}

	ai_will_do = {
		base = 0

		modifier = {
			scope:recipient = {
				has_character_flag = flag_new_consort
			}
			add = -25
		}
		modifier = { #Don't switch away from GC
			add = -75
			scope:actor = {
				employs_high_consort_court_position_trigger = yes
			}
			scope:recipient = {
				NOT = { 
					is_high_consort_trigger = {
						LIEGE = scope:actor
					}
				}
			}
		}
		modifier = { # Skills
			add = 25
			scope:recipient = {
				is_lowborn = no
				sum_of_all_skills_value > scope:actor.primary_spouse.sum_of_all_skills_value
			}
			scope:actor = {
				NOR = {
					has_relation_friend = scope:actor.primary_spouse
					has_relation_best_friend = scope:actor.primary_spouse
					has_relation_lover = scope:actor.primary_spouse
					has_relation_soulmate = scope:actor.primary_spouse
				}
			}
		}
		modifier = { #AI does it if current primary_spouse is hated and another spouse is preferred.
			add = 25
			scope:actor = {
				opinion = {
					target = scope:actor.primary_spouse
					value <= -50
				}
				opinion = {
					target = scope:recipient 
					value >= 1
				}
			}
		}
		modifier = { #The current PS comes from the high nobility
			add = -25
			scope:actor.primary_spouse = {
				any_close_family_member = {
					highest_held_title_tier >= tier_county
					OR = {
						is_councillor_of = scope:actor
						tier_difference = {
							target = scope:actor
							value >= 0
						}
					}	
				}
			}
		}
		modifier = { #The current PS comes from the high nobility
			add = -25
			scope:actor.primary_spouse = {
				any_close_family_member = {
					highest_held_title_tier >= tier_county
					OR = {
						is_powerful_vassal_of = scope:actor
						tier_difference = {
							target = scope:actor
							value >= 1
						}
					}	
				}
			}
		}
		modifier = { #The current PS comes from the high nobility
			add = -25
			scope:actor.primary_spouse = {
				any_close_family_member = {
					is_liege_or_above_of = scope:actor
				}
			}
		}
		modifier = { # Same dynasty
			add = -25
			scope:actor = {
				exists = dynasty
				primary_spouse ?= {
					dynasty ?= scope:actor.dynasty
				}
			}
		}
		modifier = { # Same house
			add = -25
			scope:actor = {
				exists = house
				primary_spouse ?= {
					house ?= scope:actor.house
				}
			}
		}
		modifier = { #Nobility
			add = -25
			scope:recipient = {
				is_lowborn = yes
			}
			scope:actor.primary_spouse = {
				is_lowborn = no
			}
		}
		modifier = { #The recipient comes from the high nobility
			add = 25
			scope:recipient = {
				any_close_family_member = {
					highest_held_title_tier >= tier_county
					OR = {
						is_councillor_of = scope:actor
						tier_difference = {
							target = scope:actor
							value >= 0
						}
					}	
				}
			}
		}
		modifier = { #The recipient comes from the high nobility
			add = 25
			scope:recipient = {
				any_close_family_member = {
					highest_held_title_tier >= tier_county
					OR = {
						is_powerful_vassal_of = scope:actor
						tier_difference = {
							target = scope:actor
							value >= 1
						}
					}	
				}
			}
		}
		modifier = { #The recipient comes from the high nobility
			add = 25
			scope:recipient = {
				any_close_family_member = {
					is_liege_or_above_of = scope:actor
				}
			}
		}
		modifier = { #Relations
			add = 20
			scope:actor = {
				OR = {
					has_relation_friend = scope:recipient
					has_relation_best_friend = scope:recipient
					has_relation_lover = scope:recipient
					has_relation_soulmate = scope:recipient
				}
			}
		}
		modifier = { # Same dynasty
			add = 25
			scope:actor = {
				exists = dynasty
				scope:recipient.dynasty ?= scope:actor.dynasty
			}
		}
		modifier = { # Same house
			add = 25
			scope:actor = {
				exists = house
				scope:recipient.house ?= scope:actor.house
			}
		}
		modifier = { #Relations
			add = -50
			scope:actor = {
				OR = {
					has_relation_friend = scope:actor.primary_spouse
					has_relation_best_friend = scope:actor.primary_spouse
					has_relation_lover = scope:actor.primary_spouse
					has_relation_soulmate = scope:actor.primary_spouse
				}
			}
		}
		modifier = { #Relations
			add = 50
			scope:actor = {
				OR = {
					has_relation_rival = scope:actor.primary_spouse
					has_relation_nemesis = scope:actor.primary_spouse
				}
			}
		}
		modifier = { #Children
			add = -35
			scope:actor.primary_spouse = {
				any_child = {
					is_player_heir_of = scope:actor
				}
			}
		}
		modifier = { #Favor
			add = -15
			scope:actor.primary_spouse = {
				harem_politics_unfavored_consort_trigger = no
			}
		}
		modifier = { #Favor
			add = -10
			scope:actor.primary_spouse = {
				harem_politics_favored_consort_trigger = yes
			}
		}
		modifier = { #Favor
			add = -15
			scope:actor.primary_spouse = {
				harem_politics_beloved_consort_trigger = yes
			}
		}
		modifier = { #Favor
			add = 10
			scope:recipient = {
				harem_politics_beloved_consort_trigger = yes
			}
		}
		modifier = { #Recently did it
			add = -75
			scope:actor = {
				has_character_flag = recently_set_primary_spouse_flag
				NOT = { has_trait = fickle }
			}
		}
		modifier = { #Recently did it
			add = 25
			scope:actor = {
				has_character_flag = recently_set_primary_spouse_flag
				has_trait = fickle
			}
			scope:recipient = {
				has_character_modifier = demoted_primary_spouse_modifier
			}
		}
		modifier = {
			factor = 0
			scope:recipient = {
				harem_politics_forgotten_consort_trigger = yes
			}
		}
		modifier = {
			factor = 0
			scope:actor = {
				OR = {
					has_trait = forgiving
					has_trait = compassionate
				}
			}
		}
		modifier = {
			factor = 0.5
			scope:recipient = {
				harem_politics_unfavored_consort_trigger = yes
			}
		}
		modifier = {
			factor = 0.5
			scope:actor = {
				has_trait = stubborn
			}
		}
	}
}

## Harem Politics ##

promote_grand_consort_interaction = {
	category = interaction_category_diplomacy
	desc = promote_grand_consort_interaction_desc
	icon = icon_declare_me_regent

	auto_accept = yes

	is_shown = {
		scope:actor = {
			is_ai = no
			trigger_if = {
				limit = {
					has_treasury = yes
				}
				treasury > tiny_gold_value_static_max
			}
			trigger_else = {
				gold > tiny_gold_value_static_max
			}
			can_appoint_char_to_court_position = {
				CHAR = scope:recipient
				COURT_POS = grand_consort_court_position
			}
			can_have_four_consorts_trigger = no
		}
		scope:recipient = {
			is_courtier_of = scope:actor
			is_consort_of = scope:actor
		}
	}
	is_valid_showing_failures_only = {
		scope:actor = { 
			can_appoint_char_to_court_position = {
				CHAR = scope:recipient
				COURT_POS = grand_consort_court_position
			}
		}
	}

	on_accept = {
		scope:actor = {
			appoint_court_position = {
				recipient = scope:recipient
				court_position = grand_consort_court_position
			}
		}
	}
}

elevate_high_consort_interaction = {
	category = interaction_category_diplomacy
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:recipient = {
						is_female = yes
					}
				}
				desc = elevate_high_consort_interaction_female_desc
			}
			desc = elevate_high_consort_interaction_male_desc
		}
	}
	icon = icon_declare_me_regent

	auto_accept = yes

	is_shown = {
		scope:actor = {
			this != scope:recipient
			is_ai = no
			trigger_if = {
				limit = {
					has_treasury = yes
				}
				treasury > tiny_gold_value_static_max
			}
			trigger_else = {
				gold > tiny_gold_value_static_max
			}
			OR = {
				can_appoint_char_to_court_position = {
					CHAR = scope:recipient
					COURT_POS = grand_consort_court_position
				}
				can_appoint_char_to_court_position = {
					CHAR = scope:recipient
					COURT_POS = pure_consort_court_position
				}
				can_appoint_char_to_court_position = {
					CHAR = scope:recipient
					COURT_POS = virtuous_consort_court_position
				}
				can_appoint_char_to_court_position = {
					CHAR = scope:recipient
					COURT_POS = worthy_consort_court_position
				}

			}
		}
		scope:recipient = {
			is_courtier_of = scope:actor
			is_consort_of = scope:actor
		}
	}
	is_valid_showing_failures_only = {
		scope:actor = {
			OR = {
				can_appoint_char_to_court_position = {
					CHAR = scope:recipient
					COURT_POS = grand_consort_court_position
				}
				can_appoint_char_to_court_position = {
					CHAR = scope:recipient
					COURT_POS = pure_consort_court_position
				}
				can_appoint_char_to_court_position = {
					CHAR = scope:recipient
					COURT_POS = virtuous_consort_court_position
				}
				can_appoint_char_to_court_position = {
					CHAR = scope:recipient
					COURT_POS = worthy_consort_court_position
				}

			}
		}
	}

	on_accept = {
		scope:actor = {
			custom_tooltip = elevate_high_consort_interaction_tooltip
			trigger_event = consort_events.2000
		}
	}
}

revoke_grand_consort_interaction = {
	category = interaction_category_diplomacy
	desc = revoke_grand_consort_interaction_desc
	icon = icon_dismiss_temporary_regency

	auto_accept = yes

	is_shown = {
		scope:recipient = {
			is_high_consort_trigger = {
				LIEGE = scope:actor
			}
			is_courtier_of = scope:actor
			is_consort_of = scope:actor
		}
		scope:actor = {
			is_ai = no
		}
	}
	is_valid_showing_failures_only = {
	}

	on_accept = {
		calyver_revoke_high_consort_court_position_effect = {
			LIEGE = scope:actor
			CONSORT = scope:recipient
		}
	}
}


#Favor modifiers
boost_favor_consort_interaction = {
	category = interaction_category_diplomacy
	desc = boost_favor_consort_interaction_desc
	icon = icon_personal

	cost = {
		prestige = {
			value = 0
			#Costly if recipient is forgotten or already favored
			if = {
				limit = {
					scope:recipient = {
						OR = {	
							var:favor < unfavored_consort_lower_limit
							var:favor >= favorite_consort_lower_limit
						}
					}
				}
				add = major_prestige_value
			}
			#Cheaper if unfavored
			else_if = {
				limit = {
					scope:recipient = {
						var:favor < neutral_consort_lower_limit
					}
				}
				add = minor_prestige_value
			}
			#A bit cheaper if neutral
			else = {
				add = medium_prestige_value
			}
		}
	}

	auto_accept = yes

	is_shown = {
		scope:actor = {
			is_ai = no
			is_physically_able = yes
			any_consort = {
				is_courtier_of = scope:actor
				is_alive = yes
				is_incapable = no
				OR = {
					is_imprisoned_by = scope:actor
					is_imprisoned = no
				}
				has_variable = favor
				count >= 4
			}
		}
		scope:recipient = {
			has_variable = favor
			is_consort_of = scope:actor
			is_courtier_of = scope:actor
			is_demoted_consort_trigger = no
		}
	}
	is_valid_showing_failures_only = {
		scope:recipient = { 
			is_available = yes
		}
		#Is not already favored
		custom_tooltip = {
			text = already_favored_recipient
			scope:recipient = {
				NOR = {
					has_character_modifier = beloved_consort_modifier
					has_character_modifier = favor_boost_modifier
				}
			}
		}
		#Has not favored someone already
		custom_tooltip = {
			text = already_favored_consort
			scope:actor = {
				NOT = {
					has_character_flag = already_favored_consort_flag
				}
			}
		}
		#Has recently unfavored this consort
		custom_tooltip = {
			text = recently_unfavored_consort_desc
			scope:recipient = {
				NOT = {
					has_character_flag = recently_unfavored_consort
				}
			}
		}
		#The GC is balancing favor
		custom_tooltip = {
			text = grand_consort_balancing_favor
			scope:actor = {
				NOT = {
					any_courtier = {
						has_court_position = grand_consort_court_position
						has_character_flag = gc_balancing_favor_flag
					}
				}
			}
		}
	}

	on_accept = {
		scope:recipient = {
			calyver_favor_minor_gain_effect = yes
			add_character_modifier = {
				modifier = favor_boost_modifier
				years = 3
			}
			if = {
				limit = {
					hp_accepts_harems = yes
					NOT = {
						has_opinion_modifier = {
							modifier = forced_me_concubine_marriage_opinion
							target = scope:actor
						}
					}
				}
				if = {
					limit = { 
						OR = {
							has_trait = arrogant
							has_trait = greedy
							has_trait = ambitious
						}
					}
					add_opinion = {
						target = scope:actor
						modifier = grateful_opinion
						opinion = 20
					}
				}
				else_if = {
					limit = { 
						harem_politics_evil_consort_trigger = yes
					}
					add_opinion = {
						target = scope:actor
						modifier = grateful_opinion
						opinion = 15
					}
				}
				else = {
					add_opinion = {
						target = scope:actor
						modifier = grateful_opinion
						opinion = 10
					}
				}
			}
			custom_tooltip = jealous_consorts_tooltip
		}
		scope:actor = {
			add_character_flag = {
				flag = already_favored_consort_flag
				years = 3
			}
			hidden_effect = {
				send_interface_toast = {
					type = event_generic_good
					title = boosted_consort_favor_t
					left_icon = scope:recipient

					show_as_tooltip = {
						scope:recipient = {
							add_character_modifier = {
								modifier = favor_boost_modifier
								years = 3
							}
							if = {
								limit = {
									scope:recipient = {
										hp_accepts_harems = yes
										NOT = {
											has_opinion_modifier = {
												modifier = forced_me_concubine_marriage_opinion
												target = scope:actor
											}
										}
									}
								}
								if = {
									limit = { 
										scope:recipient = {
											OR = {
												has_trait = arrogant
												has_trait = greedy
												has_trait = ambitious
											}
										}
									}
									add_opinion = {
										target = scope:actor
										modifier = grateful_opinion
										opinion = 20
									}
								}
								else_if = {
									limit = { 
										scope:recipient = {
											harem_politics_evil_consort_trigger = yes
										}
									}
									add_opinion = {
										target = scope:actor
										modifier = grateful_opinion
										opinion = 15
									}
								}
								else = {
									add_opinion = {
										target = scope:actor
										modifier = grateful_opinion
										opinion = 10
									}
								}
							}
						}
					}
				}
				#Other consorts will get jealous
				every_consort = {
					limit = {
						NOT = {
							this = scope:recipient
						}
						hp_accepts_harems = yes
						NOR = {
							has_opinion_modifier = {
								modifier = forced_me_concubine_marriage_opinion
								target = scope:actor
							}
							has_sexuality = homosexual
							has_sexuality = asexual

							has_relation_rival = scope:actor
							has_relation_nemesis = scope:actor
						}
						is_courtier_of = scope:actor
						is_incapable = no
						is_imprisoned = no
					}
					#Beloved ones will feel threatened
					if = {
						limit = {
							has_character_modifier = beloved_consort_modifier
							NOR = {
								has_trait = content
								has_trait = humble
								has_trait = forgiving
							}
						}
						add_opinion = {
							target = scope:recipient
							modifier = jealousy_opinion
							opinion = -10
						}
					}
					#Favored ones too
					else_if = {
						limit = {
							OR = {	
								has_character_modifier = favored_consort_modifier
								has_trait = arrogant
								has_trait = greedy
								has_trait = ambitious
							}
						}
						add_opinion = {
							target = scope:recipient
							modifier = jealousy_opinion
							opinion = -5
						}
					}
					#Evil ones are resentful, and just consorts know that favor monopoly isn't fair
					if = {
						limit = {
							OR = {	
								harem_politics_evil_consort_trigger = yes
								has_trait = just
							}
						}
						add_opinion = {
							target = scope:recipient
							modifier = jealousy_opinion
							opinion = -5
						}
					}
					if = {
						limit = {
							OR = {	
								has_character_flag = recently_unfavored_consort
								has_character_modifier = unfavored_consort_modifier
								has_character_modifier = forgotten_consort_modifier
							}
							NOR = {
								has_trait = content
								has_trait = temperate
								has_trait = calm
								has_trait = forgiving
								has_trait = compassionate
							}
						}
						add_opinion = {
							target = scope:recipient
							modifier = jealousy_opinion
							opinion = -5
						}
					}
				}
				random_list = {
					25 = { #Your consorts protest this favor
						modifier = { #Traits
							scope:recipient = { has_trait = beauty_good_2 }
							add = 10
						}
						modifier = { #Traits
							scope:recipient = { has_trait = beauty_good_3 }
							add = 20
						}
						modifier = { #High favor
							scope:recipient = { var:favor >= favorite_consort_lower_limit }
							add = 20
						}
						modifier = {
							scope:recipient = { 
								has_opinion_modifier = {
									modifier = forced_me_concubine_marriage_opinion
									target = scope:actor
								}
							}
							add = 15
						}

						#The GC
						#High aptitude
						modifier = {
							scope:actor = {
								employs_court_position = grand_consort_court_position
								any_court_position_holder = {
									type = grand_consort_court_position
									aptitude:grand_consort_court_position >= 3
									has_character_flag = gc_promoting_harmony
								}
							}
							add = -7
						}
						modifier = {
							scope:actor = {
								employs_court_position = grand_consort_court_position
								any_court_position_holder = {
									type = grand_consort_court_position
									aptitude:grand_consort_court_position >= 4
									has_character_flag = gc_promoting_harmony
								}
							}
							add = -6
						}
						modifier = {
							scope:actor = {
								employs_court_position = grand_consort_court_position
								any_court_position_holder = {
									type = grand_consort_court_position
									aptitude:grand_consort_court_position = 5
									has_character_flag = gc_promoting_harmony
								}
							}
							add = -5
						}
						#Low aptitude
						modifier = {
							scope:actor = {
								employs_court_position = grand_consort_court_position
								any_court_position_holder = {
									type = grand_consort_court_position
									aptitude:grand_consort_court_position <= 2
									has_character_flag = gc_promoting_harmony
								}
							}
							add = -2
						}
						modifier = {
							scope:actor = {
								employs_court_position = grand_consort_court_position
								any_court_position_holder = {
									type = grand_consort_court_position
									aptitude:grand_consort_court_position = 1
									has_character_flag = gc_promoting_harmony
								}
							}
							add = 1
						}

						trigger_event = {
							id = harem_politics.0027
							days = { 7 365 }
						}
					}
					25 = { #Nothing
						#The GC
						#High aptitude
						modifier = {
							scope:actor = {
								employs_court_position = grand_consort_court_position
								any_court_position_holder = {
									type = grand_consort_court_position
									aptitude:grand_consort_court_position >= 3
									has_character_flag = gc_promoting_harmony
								}
							}
							add = 5
						}
						modifier = {
							scope:actor = {
								employs_court_position = grand_consort_court_position
								any_court_position_holder = {
									type = grand_consort_court_position
									aptitude:grand_consort_court_position >= 4
									has_character_flag = gc_promoting_harmony
								}
							}
							add = 6
						}
						modifier = {
							scope:actor = {
								employs_court_position = grand_consort_court_position
								any_court_position_holder = {
									type = grand_consort_court_position
									aptitude:grand_consort_court_position = 5
									has_character_flag = gc_promoting_harmony
								}
							}
							add = 7
						}
						#Low aptitude
						modifier = {
							scope:actor = {
								employs_court_position = grand_consort_court_position
								any_court_position_holder = {
									type = grand_consort_court_position
									aptitude:grand_consort_court_position <= 2
									has_character_flag = gc_promoting_harmony
								}
							}
							add = -2
						}
						modifier = {
							scope:actor = {
								employs_court_position = grand_consort_court_position
								any_court_position_holder = {
									type = grand_consort_court_position
									aptitude:grand_consort_court_position = 1
									has_character_flag = gc_promoting_harmony
								}
							}
							add = -2
						}
					}
				}
			}
		}
	}
}

stop_favor_boost_consort_interaction = {
	category = interaction_category_diplomacy
	desc = stop_favor_boost_consort_interaction_desc
	icon = icon_personal

	auto_accept = yes

	is_shown = {
		scope:recipient = {
			has_character_modifier = favor_boost_modifier
		}
		scope:actor = {
			is_ai = no
		}
	}

	on_accept = {
		calyver_stop_favor_boost_effect = {
			HAREM_LIEGE = scope:actor
			CONSORT = scope:recipient
		}
	}
}

# Summon to Chambers
summon_to_chambers_interaction = {
	category = interaction_category_friendly
	desc = summon_to_chambers_interaction_desc
	icon = seducer

	interface_priority = 80
	common_interaction = yes

	auto_accept = yes

	is_shown = {
		scope:actor = {
			is_landed_or_landless_administrative = yes
			any_consort = {
				is_valid_for_favor_system_trigger = { HAREM_LIEGE = scope:actor }
				is_imprisoned = no
				count >= 3
			}
			NOR = {
				has_trait = celibate
				has_trait = eunuch
				has_trait = pregnant
				has_trait = devoted
				has_trait_with_flag = illness
				has_trait_with_flag = debilitating_illness
				has_trait = wounded
			}
			exists = location
		}
		scope:recipient = {
			is_consort_of = scope:actor
			is_valid_for_favor_system_trigger = { HAREM_LIEGE = scope:actor }
			NOR = {
				has_trait = pregnant
				has_trait_with_flag = illness
				has_trait_with_flag = debilitating_illness
				has_trait = wounded
			}
			location ?= scope:actor.location
		}
	}
	is_valid_showing_failures_only = {
		scope:actor = {
			is_available = yes
			is_physically_able = yes
			is_healthy = yes
		}
		scope:recipient = { 
			is_available = yes
			is_physically_able = yes
			is_healthy = yes
		}
		custom_tooltip = {
			text = already_summoned_recipient
			scope:actor = {
				NOT = {
					has_character_flag = summoned_to_chambers_flag
				}
			}
		}
		custom_tooltip = {
			text = rejected_from_bed_recipient
			scope:recipient = {
				NOT = {
					has_character_modifier = rejected_from_marriage_bed_modifier
				}
			}
		}
		custom_tooltip = {
			text = indisposed_recipient_opinion
			scope:actor = {
				NOT = {
					has_opinion_modifier = {
						modifier = indisposed_consort_opinion
						target = scope:recipient
					}
				}
			}
		}
	}

	on_accept = {
		scope:actor = {
			add_character_flag = {
				flag = summoned_to_chambers_flag
				days = 12
			}
			random_list = {
				86 = { # Success
					opinion_modifier = { # Opinion of you
						who = scope:recipient
						opinion_target = scope:actor
						multiplier = 0.2
					}
					compatibility_modifier = {
						who = scope:recipient
						compatibility_target = scope:actor
						min = -25
						max = 25
						multiplier = 0.2
					}
					# Experience
					modifier = {
						scope:recipient = {
							any_child = {
								even_if_dead = yes
								count > 0
							}
						}
						add = 5
					}
					# Traits
					modifier = {
						scope:recipient = {
							has_trait = ambitious
						}
						add = 20
					}
					modifier = {
						scope:recipient = {
							has_trait = greedy
						}
						add = 10
					}
					modifier = {
						scope:recipient = {
							has_trait = arrogant
						}
						add = 10
					}
					# Relationships
					modifier = {
						OR = {
							has_relation_soulmate = scope:recipient
							has_relation_lover = scope:recipient
						}
						add = 50
					}
					modifier = {
						OR = {
							has_relation_best_friend = scope:recipient
							has_relation_friend = scope:recipient
						}
						add = 20
					}
					# Marital duties - rank
					modifier = {
						scope:actor.primary_spouse ?= scope:recipient
						add = 15
					}
					modifier = {
						scope:recipient = {
							is_high_consort_trigger = {
								LIEGE = scope:actor
							}
						}
						add = 10
					}
					modifier = {
						scope:recipient = {
							is_spouse_of = scope:actor
							NOR = {
								this = scope:actor.primary_spouse
								is_high_consort_trigger = {
									LIEGE = scope:actor
								}
							}
						}
						add = 5
					}
					# Attraction
					modifier = {
						scope:recipient = {
							is_attracted_to_gender_of = scope:actor
						}
						add = 10
					}
					modifier = {
						scope:actor = {
							is_attracted_to_gender_of = scope:recipient
						}
						add = 5
					}
					# If they were recently scolded, they'll do their best to please their liege
					modifier = {
						has_character_flag = flag_scolded_consort
						add = 5
					}
					modifier = {
						scope:actor = {
							has_trait = lustful
						}
						add = 10
					}
					modifier = {
						scope:actor = {
							has_trait = gregarious
						}
						add = 10
					}
					modifier = {
						scope:recipient = {
							has_trait = lustful
						}
						add = 10
					}
					modifier = {
						scope:recipient = {
							has_trait = gregarious
						}
						add = 10
					}
					modifier = {
						scope:actor = {
							has_trait = seducer
						}
						add = 20
					}
					modifier = {
						scope:recipient = {
							has_trait = seducer
						}
						add = 10
					}
					show_as_tooltip = {
						had_sex_with_effect = {
							CHARACTER = scope:recipient
							PREGNANCY_CHANCE = pregnancy_chance
						}
					}
					trigger_event = {
						id = consort_events.0037
						days = { 3 5 }
					}
				}
				10 = { # Failure
					opinion_modifier = { # Opinion of you
						who = scope:recipient
						opinion_target = scope:actor
						multiplier = -0.25
					}
					compatibility_modifier = {
						who = scope:recipient
						compatibility_target = scope:actor
						min = -25
						max = 25
						multiplier = -0.25
					}
					# Little experience
					modifier = {
						scope:recipient = {
							any_child = {
								even_if_dead = yes
								count = 0
							}
						}
						add = 20
					}
					modifier = {
						scope:actor = {
							any_child = {
								even_if_dead = yes
								count = 0
							}
						}
						add = 10
					}
					modifier = {
						scope:recipient = {
							age <= 20
						}
						add = 25
					}
					modifier = {
						scope:actor = {
							age <= 20
						}
						add = 10
					}
					modifier = {
						scope:recipient = {
							has_character_flag = flag_new_consort
						}
						add = 10
					}
					# Traits
					modifier = {
						scope:recipient = {
							has_trait = craven
						}
						add = 15
					}
					modifier = {
						scope:recipient = {
							has_trait = shy
						}
						add = 20
					}
					modifier = {
						scope:recipient = {
							has_trait = chaste
						}
						add = 30
					}
					modifier = {
						scope:actor = {
							has_trait = craven
						}
						add = 5
					}
					modifier = {
						scope:actor = {
							has_trait = shy
						}
						add = 10
					}
					modifier = {
						scope:actor = {
							has_trait = chaste
						}
						add = 15
					}
					# Relationships
					modifier = {
						scope:recipient = {
							has_opinion_modifier = {
								modifier = forced_me_concubine_marriage_opinion
								target = scope:actor
							}
						}
						add = 20
					}
					modifier = {
						has_relation_nemesis = scope:actor
						add = 50
					}
					modifier = {
						has_relation_rival = scope:actor
						add = 30
					}
					# Attraction
					modifier = {
						scope:recipient = {
							NOT = {
								is_attracted_to_gender_of = scope:actor
							}
						}
						add = 30
					}
					modifier = {
						scope:actor = {
							NOT = {
								is_attracted_to_gender_of = scope:recipient
							}
						}
						add = 15
					}
					custom_tooltip = summon_to_chambers_failure_tooltip
					trigger_event = {
						id = consort_events.0038
						days = { 3 5 }
					}
				}
				2 = { # Accident
					trigger = {
						scope:actor = {
							harem_politics_accident_event_trigger = yes
						}
					}
					modifier = {
						scope:actor.highest_held_title_tier >= tier_kingdom
						add = 3
					}
					modifier = {
						scope:recipient = {
							OR = {
								has_relation_lover = scope:actor
								has_relation_friend = scope:actor
								has_character_modifier = favored_consort_modifier
							}
						}
						add = -2
					}
					modifier = {
						scope:recipient = {
							OR = {
								has_relation_soulmate = scope:actor
								has_relation_best_friend = scope:actor
								has_character_modifier = beloved_consort_modifier
							}
						}
						add = -5
					}
					modifier = { # Favor
						add = -2
						scope:recipient = {
							has_character_modifier = favor_boost_modifier
						}
					}
					modifier = {
						scope:recipient = {
							any_close_family_member = {
								OR = {
									is_powerful_vassal_of = scope:actor
									is_councillor_of = scope:actor
									is_liege_or_above_of = scope:actor
									tier_difference = {
										target = scope:actor
										value >= 0
									}
								}
							}
						}
						add = -10
					}
					modifier = {
						any_court_position_holder = {
							type = grand_consort_court_position
							aptitude:grand_consort_court_position = 1
						}
						add = 2
					}
					modifier = {
						any_court_position_holder = {
							type = grand_consort_court_position
							aptitude:grand_consort_court_position <= 2
						}
						add = 1
					}
					modifier = {
						any_court_position_holder = {
							type = grand_consort_court_position
							aptitude:grand_consort_court_position >= 3
							has_character_flag = gc_promoting_harmony
						}
						add = -2
					}
					modifier = {
						any_court_position_holder = {
							type = grand_consort_court_position
							aptitude:grand_consort_court_position >= 4
							has_character_flag = gc_promoting_harmony
						}
						add = -2
					}
					modifier = {
						has_character_modifier = poisonous_court_modifier
						add = 25
					}
					custom_tooltip = summon_to_chambers_accident_tooltip
					trigger_event = {
						id = consort_events.0039
						days = { 3 5 }
					}
				}
				2 = { # A pregnant consort miscarries
					trigger = {
						scope:actor = {
							harem_politics_miscarriage_event_trigger = yes
						}
					}
					modifier = {
						any_consort = {
							has_trait = pregnant
							NOT = {
								has_character_flag = birth_will_go_smoothly
							}
						}
						add = 2
					}
					trigger_event = {
						id = consort_events.0043
						days = { 3 5 }
					}
				}
			}
		}
	}

	ai_targets = {
		ai_recipients = courtiers
		max = 2
	}
	ai_target_quick_trigger = {
		adult = yes
	}
	ai_frequency_by_tier = {
		barony = 0
		county = 120
		duchy = 60
		kingdom = 60
		empire = 60
		hegemony = 60
	}

	ai_potential = {
		any_child = {
			is_alive = yes
			NOR = {
				has_trait = bastard
				has_trait = eunuch
				has_trait = devoted
				has_trait = disinherited
			}
			count < 4
		}
		age > 30
	}

	ai_will_do = {
		base = 0

		modifier = {
			scope:actor = {
				any_child = {
					is_alive = yes
					NOR = {
						has_trait = bastard
						has_trait = eunuch
						has_trait = devoted
					}
					count < 4
				}
			}
			add = 35
		}
		modifier = {
			scope:actor = {
				any_child = {
					is_alive = yes
					character_gender_can_inherit_from_trigger = { CHARACTER = scope:actor }
					NOR = {
						has_trait = bastard
						has_trait = eunuch
						has_trait = devoted
						has_trait = disinherited
					}
					count < 3
				}
			}
			add = 25
		}
		modifier = {
			scope:actor = {
				OR = {
					has_relation_rival = scope:recipient
					has_relation_nemesis = scope:recipient
				}
			}
			add = -35
		}
		modifier = {
			scope:actor = {
				OR = {
					has_relation_lover = scope:recipient
					has_relation_friend = scope:recipient
				}
			}
			add = 15
		}
		modifier = {
			scope:actor = {
				OR = {
					has_relation_soulmate = scope:recipient
					has_relation_best_friend = scope:recipient
				}
			}
			add = 25
		}
		modifier = {
			scope:actor = {
				NOT = {
					is_attracted_to_gender_of = scope:recipient
				}
			}
			add = -20
		}
		modifier = { # Infertility
			add = -15
			scope:actor = {
				fertility > 0.1
			}
			scope:recipient = {
				fertility < 0.1
			}
		}
	}
}

# Harem Window
check_harem_window_interaction = {
	category = interaction_category_friendly
	desc = check_harem_window_interaction_desc
	icon = icon_dynasty

	interface_priority = 90
	common_interaction = yes

	needs_confirmation = { always = no }  # Skip confirmation popup, open decision directly

	is_shown = {
		scope:actor = {
			is_ai = no
			can_execute_decision = check_harem_decision
		}
		scope:recipient = {
			OR = {
				is_active_harem_member_trigger = {
					LIEGE = scope:actor
				}
				this = scope:actor
			}
		}
	}
	is_valid_showing_failures_only = {
		custom_tooltip = {
			text = grand_consort_tasks_consort_limit_tooltip
			scope:actor = {
				any_consort = {
					is_courtier_of = scope:actor
					count >= 3
				}
			}
		}
	}

	on_send = {
		open_view_data = {
			view = decision_detail
			data = decision:check_harem_decision
			player = scope:actor
		}
	}
	
	# No on_accept needed since we're opening the decision window in on_send
	# The decision window will handle the actual execution
	
	ai_will_do = {
		base = 0
	}
}

# Bestow Name
# bestow_name_interaction = {
# 	category = interaction_category_diplomacy
# 	desc = bestow_name_interaction_desc
# 	icon = concubine_icon

# 	auto_accept = yes

# 	is_shown = {
# 		scope:recipient = {
# 			is_concubine_of = scope:actor
# 			NOT = {
# 				has_opinion_modifier = {
# 					modifier = bestowed_name_opinion
# 					target = scope:actor
# 				}
# 			}
# 			culture != scope:actor.culture
# 		}
# 		scope:actor.religion = religion:islam_religion
# 	}

# 	on_accept = {
# 		scope:actor = {
# 			trigger_event = consort_events.2000
# 		}
# 		show_as_tooltip = {
# 			scope:recipient = {
# 				calyver_favor_micro_gain_effect = yes
# 				if = {
# 					limit = {
# 						OR = {
# 							accepts_harems = yes
# 							has_trait = ambitious
# 							has_trait = arrogant
# 							has_trait = greedy
# 						}
# 					}
# 					add_opinion_modifier = {
# 						modifier = bestowed_name_opinion
# 						target = scope:actor
# 						opinion = 5
# 					}
# 				}
# 				else = {
# 					add_opinion_modifier = {
# 						modifier = bestowed_name_opinion
# 						target = scope:actor
# 					}
# 				}
# 			}
# 		}
# 	}

# 	ai_targets = {
# 		ai_recipients = courtiers
# 	}
# 	ai_frequency = 72

# 	ai_potential = {
# 		any_concubine = {
# 			count >= 1
# 		}
# 	}

# 	ai_will_do = {
# 		base = 35

# 		modifier = {
# 			scope:actor = {
# 				has_relation_potential_lover = scope:recipient
# 			}
# 			add = 15
# 		}
# 		modifier = {
# 			scope:actor = {
# 				OR = {
# 					has_relation_friend = scope:recipient
# 					has_relation_lover = scope:recipient
# 					scope:recipient = {
# 						OR = {	
# 							has_character_modifier = favored_consort_modifier
# 							any_child = {
# 								even_if_dead = yes
# 								is_child_of = scope:actor
# 								count >= 1
# 							}
# 						}
# 					}
# 				}
# 			}
# 			add = 25
# 		}
# 		modifier = {
# 			scope:actor = {
# 				OR = {
# 					has_relation_best_friend = scope:recipient
# 					has_relation_soulmate = scope:recipient
# 					scope:recipient = {
# 						OR = {
# 							has_character_modifier = favored_consort_modifier
# 							has_character_modifier = beloved_consort_modifier
# 						}
# 					}
# 				}
# 			}
# 			add = 75
# 		}

# 		modifier = {
# 			scope:recipient = {
# 				has_character_flag = flag_new_consort
# 			}
# 			add = 10
# 		}
# 		modifier = {
# 			scope:recipient = {
# 				has_relation_potential_rival = scope:actor
# 			}
# 			add = -10
# 		}
# 		modifier = {
# 			scope:recipient = {
# 				OR = {	
# 					has_relation_rival = scope:actor
# 					has_character_modifier = unfavored_consort_modifier
# 				}
# 			}
# 			add = -15
# 		}
# 		modifier = {
# 			scope:recipient = {
# 				OR = {
# 					has_relation_nemesis = scope:actor
# 					has_character_modifier = forgotten_consort_modifier
# 				}
# 			}
# 			add = -20
# 		}

# 		opinion_modifier = {
# 			opinion_target = scope:recipient
# 			multiplier = 0.5
# 		}
# 	}
# }

# Debug - switch to player
switch_to_player_interaction = {
	category = interaction_category_diplomacy
	desc = switch_to_player_interaction_desc
	icon = icon_scheme_challenge_status

	use_diplomatic_range = no
	ignores_pending_interaction_block = yes
	common_interaction = yes
	auto_accept = yes

	is_shown = {
		debug_only = yes
		scope:actor = {
			is_ai = no
		}
		scope:recipient = {
			this != scope:actor
			is_ai = yes
			is_playable_character = yes
		}
	}

	can_send = {
		scope:actor = {
			is_ai = no
		}
	}

	on_accept = {
		scope:actor = {
			save_scope_as = harem_liege
			set_player_character = scope:recipient
		}
	}
	ai_will_do = 0
}

#Bestow Nobility#
# bestow_nobility_interaction = {
# 	category = interaction_category_diplomacy
# 	desc = bestow_nobility_interaction_desc
# 	icon = icon_personal #Check

# 	cost = {
# 		prestige = major_prestige_value
# 		gold = major_gold_value
# 	}

# 	auto_accept = yes

# 	is_shown = {
# 		debug_only = yes
# 		scope:actor = {
# 			is_physically_able = yes
# 			is_landed_or_landless_administrative = yes
# 			is_lowborn = no
# 		}
# 		scope:recipient = {
# 			is_lowborn = yes
# 			OR = {
# 				is_consort_of = scope:actor
# 				is_knight_of = scope:actor
# 				any_court_position_employer = scope:actor
# 				is_councillor_of = scope:actor
# 				any_close_family_member = {
# 					is_consort_of = scope:actor
# 				}
# 			}
# 			is_courtier_of = scope:actor
# 			trigger_if = {
# 				limit = {
# 					NOT = {
# 						character_gender_can_inherit_from_trigger = { CHARACTER = scope:actor }
# 					}
# 				}
# 				is_consort_of = scope:actor
# 			}
# 			trigger_else = {
# 				character_gender_can_inherit_from_trigger = { CHARACTER = scope:actor }
# 			}
# 		}
# 	}
# 	is_valid_showing_failures_only = {
# 		scope:recipient = { 
# 			is_available = yes
# 		}
# 	}

# 	on_accept = {
# 		scope:actor = {
# 			save_scope_value_as = {
# 				name = target_gold
# 				value = major_gold_value
# 				divide = 2
# 			}
# 		}
# 		scope:recipient = {
# 			if = {
# 				limit = {
# 					is_consort_of = scope:actor
# 					NOT = {
# 						character_gender_can_inherit_from_trigger = { CHARACTER = scope:actor }
# 					}
# 					any_close_family_member = {
# 						NOT = {
# 							is_child_of = scope:actor
# 						}
# 						character_gender_can_inherit_from_trigger = { CHARACTER = scope:actor }
# 						OR = {
# 							any_liege_or_above = {
# 								this = scope:actor
# 							}
# 							AND = {
# 								exists = scope:actor.top_liege
# 								top_liege ?= scope:actor.top_liege
# 							}
# 						}
# 						is_lowborn = yes
# 					}
# 				}
# 				random_close_family_member = {
# 					limit = {
# 						NOT = {
# 							is_child_of = scope:actor
# 						}
# 						character_gender_can_inherit_from_trigger = { CHARACTER = scope:actor }
# 						OR = {
# 							any_liege_or_above = {
# 								this = scope:actor
# 							}
# 							AND = {
# 								exists = scope:actor.top_liege
# 								top_liege ?= scope:actor.top_liege
# 							}
# 						}
# 						is_lowborn = yes
# 					}
# 					weight = {
# 						base = 1
# 						modifier = {
# 							is_parent_of = scope:recipient
# 							add = 49
# 						}
# 						modifier = {
# 							is_sibling_of = scope:recipient
# 							add = 24
# 						}
# 					}
# 					save_scope_as = target
# 				}
# 			}
# 			else = {
# 				save_scope_as = target
# 			}
# 		}
# 		scope:target = {
# 			if = {
# 				limit = {
# 					is_knight_of = scope:actor
# 				}
# 			}
# 			if = {
# 				limit = {
# 					is_councillor_of = scope:actor
# 				}
# 			}
# 			if = {
# 				limit = {
# 					any_court_position_employer = scope:actor
# 				}
# 			}
# 			hidden_effect = {
# 				scope:consort_relative = {
# 					add_short_term_gold = target_gold
# 					create_dynamic_title = {
# 						tier = duchy
# 						name = NEW_CREATED_TITLE_NAME
# 					}
# 					create_title_and_vassal_change = {
# 						type = created
# 						save_scope_as = change
# 						add_claim_on_loss = no
# 					}
# 					scope:new_title = {
# 						set_capital_county = scope:actor.capital_county
# 						set_landless_title = yes
# 						set_destroy_on_gain_same_tier = yes
# 						set_no_automatic_claims = yes
# 						set_can_be_named_after_dynasty = no
# 						change_title_holder = {
# 							holder = prev
# 							change = scope:change
# 						}
# 					}
# 					resolve_title_and_vassal_change = scope:change
# 					scope:new_title = {
# 						generate_coa = yes
# 					}
# 					destroy_title = scope:new_title
# 					if = { #Promote their relatives too
# 						limit = {
# 							any_close_family_member = {
# 								is_lowborn = yes
# 							}
# 						}
# 						every_close_family_member = {
# 							limit = {
# 								is_lowborn = yes
# 							}
# 							add_to_list = target_relatives_list
# 						}
# 					}
# 					if = { #And consorts
# 						limit = {
# 							NOT = {
# 								this = scope:recipient
# 							}
# 							any_consort = {
# 								is_lowborn = yes
# 								is_parent_of = scope:recipient
# 							}
# 						}
# 						every_consort = {
# 							limit = {
# 								is_lowborn = yes
# 								is_parent_of = scope:recipient
# 							}
# 							add_to_list = target_relatives_list
# 						}
# 					}
# 					if = {
# 						limit = {
# 							any_in_list = {
# 								list = target_relatives_list
# 								count >= 1
# 							}
# 						}
# 						every_in_list = {
# 							list = target_relatives_list
# 							limit = {
# 								is_lowborn = yes
# 							}
# 							set_house = scope:target.house
# 						}
# 					}
# 					if = { #Add their relatives to court
# 						limit = {
# 							any_close_family_member = {
# 								NOT = {
# 									is_courtier_of = scope:actor
# 								}
# 								OR = {
# 									top_liege ?= scope:actor
# 									NOR = {
# 										is_councillor = yes
# 										has_any_court_position = yes
# 										any_consort = {
# 											is_landed = yes
# 										}
# 									}
# 								}
# 							}
# 						}
# 						every_close_family_member = {
# 							limit = {
# 								NOT = {
# 									is_courtier_of = scope:actor
# 								}
# 								OR = {
# 									top_liege ?= scope:actor
# 									NOR = {
# 										is_councillor = yes
# 										has_any_court_position = yes
# 										any_consort = {
# 											is_landed = yes
# 										}
# 									}
# 								}
# 							}
# 							add_to_list = relatives_to_add_list
# 						}
# 					}
# 					if = { #And consorts
# 						limit = {
# 							any_consort = {
# 								NOT = {
# 									is_courtier_of = scope:actor
# 								}
# 								OR = {
# 									top_liege ?= scope:actor
# 									NOR = {
# 										is_councillor = yes
# 										has_any_court_position = yes
# 										any_consort = {
# 											is_landed = yes
# 										}
# 									}
# 								}
# 							}
# 						}
# 						every_consort = {
# 							limit = {
# 								NOT = {
# 									is_courtier_of = scope:actor
# 								}
# 								OR = {
# 									top_liege ?= scope:actor
# 									NOR = {
# 										is_councillor = yes
# 										has_any_court_position = yes
# 										any_consort = {
# 											is_landed = yes
# 										}
# 									}
# 								}
# 							}
# 							add_to_list = relatives_to_add_list
# 						}
# 					}
# 					if = {
# 						limit = {
# 							any_in_list = {
# 								list = relatives_to_add_list
# 								count >= 1
# 							}
# 						}
# 						every_in_list = {
# 							list = relatives_to_add_list
# 							scope:actor = {
# 								add_courtier = prev
# 							}
# 						}
# 					}
# 				}
# 				scope:actor = {
# 					add_courtier = scope:target
# 					# every_consort = {
# 					# 	limit = {
# 					# 		AND = {
# 					# 			NOR = {
# 					# 				this = scope:consort
# 					# 				any_close_or_extended_family_member = {
# 					# 					this = scope:consort
# 					# 				}
# 					# 				has_relation_best_friend = scope:consort
# 					# 				has_relation_friend = scope:consort
# 					# 				has_relation_lover = scope:consort
# 					# 				has_relation_soulmate = scope:consort
# 					# 			}
# 					# 			harem_politics_evil_consort_trigger = yes
# 					# 		}
# 					# 	}
# 					# 	add_opinion = {
# 					# 		target = scope:consort
# 					# 		modifier = envy_consort_opinion
# 					# 	}
# 					# }
# 				}
# 				# scope:consort = {
# 				# 	send_interface_toast = {
# 				# 		type = event_generic_good
# 				# 		title = good_consort_visit_t
# 				# 		right_icon = scope:harem_liege
# 				# 		left_icon = scope:consort_relative
# 				# 		show_as_tooltip = {
# 				# 			calyver_favor_medium_gain_effect = yes
# 				# 		}
# 				# 		scope:consort_relative = {
# 				# 			add_opinion = {
# 				# 				target = scope:consort
# 				# 				modifier = grateful_opinion
# 				# 				opinion = 10
# 				# 			}
# 				# 			show_as_tooltip = {
# 				# 				set_house = scope:consort_relative.house
# 				# 				if = {
# 				# 					limit = {
# 				# 						exists = scope:consort.house
# 				# 						house ?= scope:consort.house
# 				# 					}
# 				# 					scope:consort = {
# 				# 						set_house = scope:consort_relative.house
# 				# 					}
# 				# 				}
# 				# 			}
# 				# 		}
# 				# 	}
# 				# }
# 			}
# 		}
# 	}
# }