﻿#This effect has some small differences to the previous one since this one involves one extra person (the one you give a concubine to)
concubine_offer_on_accept_effect = {
	scope:secondary_recipient = {
		trigger_event = marriage_interaction.0040
		if = {
			# Victim is angry for being forced into concubinage.
			limit = {
				is_imprisoned = yes
			}
			add_character_flag = {
				flag = block_release_from_prison_event
				days = 3
			}
			release_from_prison = yes
			add_opinion = {
				target = scope:actor
				modifier = forced_me_concubine_marriage_opinion
			}

			# Family members of victim are also angry that you've forced them into concubinage.
			every_close_family_member = {
				if = {
					limit = { 
						this != scope:actor # Don't hate yourself.
					}
					add_opinion = {
						target = scope:actor
						modifier = forced_family_concubine_marriage_opinion
					}
					hidden_effect = {
						send_interface_message = {
							type = msg_family_became_concubine
							title = msg_close_family_member_offered_as_concubine_title
							right_icon = scope:actor
							left_icon = scope:secondary_actor
							show_as_tooltip = { scope:actor = { make_concubine = scope:secondary_actor } }
						}
					}

					# Family members are even *more* angry if they don't believe in concubines/polyamory (different from polygamy). Also if they don't accept same-sex relationships
					if = {
						limit = { 
							OR = {
								NOT = { faith = { has_doctrine = doctrine_concubines } }
								NOT = { faith = { has_doctrine = tenet_polyamory } }
								AND = {
									allowed_to_marry_same_sex_trigger = no
									scope:recipient = { sex_same_as = scope:secondary_recipient }
								}
							}
						}
						add_opinion = {
							target = scope:actor
							modifier = relative_in_blasphemous_union_opinion
						}
					}
				}
			}
					
			# Spouses, if any exist, are also furious.
			if = {
				limit = {
					is_married = yes
					#A check to make sure you haven't somehow married them during the consideration time
					NOT = { any_spouse = { this = scope:recipient } }
				}
				every_spouse = {
					add_opinion = {
						target = scope:actor
						modifier = forced_spouse_concubine_marriage_opinion
					}
					divorce = scope:secondary_recipient # no additional opinion hit, no scripted effect
					save_scope_value_as = { # For tooltips in the coming event
						name = was_spouse
						value = yes
					}
					trigger_event = marriage_interaction.0043
				}
			}
					
			# Stealing concubines pisses the former concubinist off.
			if = {
				limit = {
					is_concubine = yes
					#A check to make sure you haven't somehow gotten them as concubine during the consideration time
					NOT = { any_consort = { this = scope:recipient } }
				}
				this.concubinist = {
					if = {
						limit = {
							this != scope:actor
						}
						add_opinion = {
							target = scope:actor
							modifier = stole_concubine_opinion
						}
						remove_concubine = scope:secondary_recipient # no additional opinion hit, no scripted effect
						save_scope_value_as = { # For tooltips in the coming event
							name = was_concubine
							value = yes
						}
						trigger_event = marriage_interaction.0043
					}
					else = {
						remove_concubine = scope:secondary_recipient # no additional opinion hit, no scripted effect
					}
				}
			}

			# Break any betrothals which may exist (without additional opinion penalties).
			if = {
				limit = {
					exists = betrothed
					#A check to make sure you haven't somehow gotten betrothed to them during the consideration time
					betrothed != scope:recipient
				}
				betrothed = { trigger_event = marriage_interaction.0043 }
				break_betrothal = betrothed
			}

			# Having concubines means they're now no longer yours.
			if = {
				limit = { number_of_concubines > 0	}
				every_concubine = {
					scope:secondary_recipient = {
						remove_concubine = prev
					}
				}
			}
		}
		if = {
			limit = {
				is_concubine_of = scope:actor
			}
			scope:actor = {
				remove_concubine = scope:secondary_recipient
			}
		}
		remove_character_flag = has_been_offered_as_concubine
	}

	# Send us a notification about what we just did. If the secondary_recipient somehow ended up as a consort (spouse/concubine) or betrothed to recipient during the consideration time of this request we'll send a message about that instead (should only happen to AI tho)
	if = {
		limit = { #Invalidation message
			scope:secondary_recipient = {
				OR = {
					any_consort = { }
					exists = betrothed
				}
			}
		}
		scope:secondary_recipient = {
			# If they've somehow already become entangled with the recipient we tell this
			if = {
				limit = {
					OR = {
						is_consort_of = scope:recipient
						betrothed ?= scope:recipient
					}
				}
				scope:recipient = {
					save_scope_as = spouse
				}
			}
			# Else, if they've married or gotten betrothed to someone else, we say this
			else_if = {
				limit = {
					exists = betrothed
				}
				betrothed = {
					save_scope_as = spouse
				}
			}
			else = {
				random_consort = {
					limit = {
						this = scope:secondary_recipient.primary_spouse
					}
					alternative_limit = {
						always = yes
					}
					save_scope_as = spouse
				}
			}
		}
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = msg_concubine_offered_invalidated_title
				right_icon = scope:recipient
				left_icon = scope:secondary_recipient
				if = {
					limit = {
						scope:secondary_recipient = { is_consort_of = scope:spouse }
					}
					custom_tooltip = msg_concubine_offered_invalidated_consort
				}
				else = {
					custom_tooltip = msg_concubine_offered_invalidated_betrothed
				}
			}
		}
		scope:recipient = {
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = msg_concubine_offered_invalidated_recipient_title
				right_icon = scope:actor
				left_icon = scope:secondary_recipient
				if = {
					limit = {
						scope:secondary_recipient = { is_consort_of = scope:spouse }
					}
					custom_tooltip = msg_concubine_offered_invalidated_consort
				}
				else = {
					custom_tooltip = msg_concubine_offered_invalidated_betrothed
				}
			}
		}
	}
	else = { #Proper notification
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = msg_concubine_offered_title
				right_icon = scope:recipient
				left_icon = scope:secondary_recipient
				scope:recipient = {
					make_concubine = scope:secondary_recipient
					if = { #Scale opinion gain a bit depending on how cool the concubine is
						limit = {
							scope:secondary_recipient = {
								OR = {
									has_trait = beauty_good_2
									has_trait = beauty_good_3
									num_of_good_genetic_traits > 1
									has_relation_lover = scope:recipient
									has_relation_soulmate = scope:recipient
								}
								trigger_if = {
									limit = {
										is_female = yes
									}
									age < define:NChildbirth|MAX_FEMALE_REPRODUCTION_AGE
								}
							}
						}
						add_opinion = {
							target = scope:actor
							modifier = grateful_opinion
							opinion = 40
						}
					}
					else_if = {
						limit = {
							scope:secondary_recipient = {
								OR = {
									is_lowborn = no
									has_trait = beauty_good_1
									num_of_good_genetic_traits > 0
									has_relation_friend = scope:recipient
									has_relation_best_friend = scope:recipient
								}
								trigger_if = {
									limit = {
										is_female = yes
									}
									age < define:NChildbirth|MAX_FEMALE_REPRODUCTION_AGE
								}
							}
						}
						add_opinion = {
							target = scope:actor
							modifier = grateful_opinion
							opinion = 30
						}
					}
					else = {
						add_opinion = {
							target = scope:actor
							modifier = grateful_opinion
							opinion = 20
						}
					}
				}
			}
		}
	}
	#### MOD BEGIN ####
	scope:secondary_actor = {
		hidden_effect = {
			if = {
				limit = { scope:actor.dynasty = scope:secondary_actor.dynasty }
				remove_trait = concubine
				add_trait = concubine_elevated
			}
		}
	}
	#### MOD END ####
}

#### MOD BEGIN ####
concubine_request_on_accept_effect = {
	scope:secondary_recipient = {
		trigger_event = marriage_interaction.0040
		if = {
			# Victim is angry for being forced into concubinage.
			limit = {
				is_imprisoned = yes
			}
			add_character_flag = {
				flag = block_release_from_prison_event
				days = 3
			}
			release_from_prison = yes
			add_opinion = {
				target = scope:recipient
				modifier = forced_me_concubine_marriage_opinion
			}

			# Family members of victim are also angry that you've forced them into concubinage.
			every_close_family_member = {
				if = {
					limit = { 
						NOT = { this = scope:recipient } # Don't hate yourself.
					}
					add_opinion = {
						target = scope:recipient
						modifier = forced_family_concubine_marriage_opinion
					}
					hidden_effect = {
						send_interface_message = {
							type = msg_family_became_concubine
							title = msg_close_family_member_offered_as_concubine_title
							right_icon = scope:actor
							left_icon = scope:secondary_recipient
							show_as_tooltip = { scope:secondary_recipient = { make_concubine = scope:actor } }
						}
					}

					# Family members are even *more* angry if they don't believe in concubines/polyamory (different from polygamy). Also if they don't accept same-sex relationships
					if = {
						limit = { 
							OR = {
								NOT = { faith = { has_doctrine = doctrine_concubines } }
								NOT = { faith = { has_doctrine = tenet_polyamory } }
								AND = {
									allowed_to_marry_same_sex_trigger = no
									scope:actor = { sex_same_as = scope:secondary_recipient }
								}
							}
						}
						add_opinion = {
							target = scope:recipient
							modifier = relative_in_blasphemous_union_opinion
						}
					}
				}
			}
					
			# Spouses, if any exist, are also furious.
			if = {
				limit = {
					is_married = yes
					#A check to make sure you haven't somehow married them during the consideration time
					NOT = { any_spouse = { this = scope:actor } }
				}
				every_spouse = {
					add_opinion = {
						target = scope:recipient
						modifier = forced_spouse_concubine_marriage_opinion
					}
					divorce = scope:secondary_recipient # no additional opinion hit, no scripted effect
					save_scope_value_as = { # For tooltips in the coming event
						name = was_spouse
						value = yes
					}
					trigger_event = marriage_interaction.0043
				}
			}
					
			# Stealing concubines pisses the former concubinist off.
			if = {
				limit = {
					is_concubine = yes
					#A check to make sure you haven't somehow gotten them as concubine during the consideration time
					NOT = { any_consort = { this = scope:actor } }
				}
				this.concubinist = {
					if = {
						limit = {
							NOT = {
								this = scope:recipient
							}
						}
						add_opinion = {
							target = scope:recipient
							modifier = stole_concubine_opinion
						}
						remove_concubine = scope:secondary_recipient # no additional opinion hit, no scripted effect
						save_scope_value_as = { # For tooltips in the coming event
							name = was_concubine
							value = yes
						}
						trigger_event = marriage_interaction.0043
					}
					else = {
						remove_concubine = scope:secondary_recipient # no additional opinion hit, no scripted effect
					}
				}
			}

			# Break any betrothals which may exist (without additional opinion penalties).
			if = {
				limit = {
					exists = betrothed
					#A check to make sure you haven't somehow gotten betrothed to them during the consideration time
					NOT = { betrothed = scope:actor }
				}
				betrothed = { trigger_event = marriage_interaction.0043 }
				break_betrothal = betrothed
			}

			# Having concubines means they're now no longer yours.
			if = {
				limit = { number_of_concubines > 0	}
				every_concubine = {
					scope:secondary_recipient = {
						remove_concubine = prev
					}
				}
			}
		}
		if = {
			limit = {
				is_concubine_of = scope:recipient
			}
			scope:recipient = {
				remove_concubine = scope:secondary_recipient
			}
		}
		remove_character_flag = has_been_offered_as_concubine
	}

	# Send us a notification about what we just did. If the secondary_recipient somehow ended up as a consort (spouse/concubine) or betrothed to recipient during the consideration time of this request we'll send a message about that instead (should only happen to AI tho)
	if = {
		limit = { #Invalidation message
			scope:secondary_recipient = {
				OR = {
					any_spouse = { count >= 1 }
					exists = betrothed
				}
			}
		}
		scope:secondary_recipient = {
			# If they've somehow already become entangled with the recipient we tell this
			if = {
				limit = {
					OR = {
						is_consort_of = scope:actor
						AND = {
							exists = betrothed
							betrothed = scope:actor
						}
					}
				}
				scope:actor = {
					save_scope_as = spouse
				}
			}
			# Else, if they've married or gotten betrothed to someone else, we say this
			else_if = {
				limit = {
					exists = betrothed
				}
				betrothed = {
					save_scope_as = spouse
				}
			}
			else = {
				random_consort = {
					limit = {
						this = scope:secondary_recipient.primary_spouse
					}
					alternative_limit = {
						always = yes
					}
					save_scope_as = spouse
				}
			}
		}
		scope:recipient = {
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = msg_concubine_requested_invalidated_title
				right_icon = scope:actor
				left_icon = scope:secondary_recipient
				if = {
					limit = {
						scope:secondary_recipient = { is_consort_of = scope:spouse }
					}
					custom_tooltip = msg_concubine_offered_invalidated_consort
				}
				else = {
					custom_tooltip = msg_concubine_offered_invalidated_betrothed
				}
			}
		}
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = msg_concubine_requested_invalidated_recipient_title
				right_icon = scope:recipient
				left_icon = scope:secondary_recipient
				if = {
					limit = {
						scope:secondary_recipient = { is_consort_of = scope:spouse }
					}
					custom_tooltip = msg_concubine_offered_invalidated_consort
				}
				else = {
					custom_tooltip = msg_concubine_offered_invalidated_betrothed
				}
			}
		}
	}
	else = { #Proper notification
		scope:recipient = {
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = msg_concubine_requested_title
				right_icon = scope:actor
				left_icon = scope:secondary_recipient
				scope:actor = {
					make_concubine = scope:secondary_recipient
					if = { #Scale opinion gain a bit depending on how cool the concubine is
						limit = {
							scope:secondary_recipient = {
								OR = {
									has_trait = beauty_good_2
									has_trait = beauty_good_3
									num_of_good_genetic_traits > 1
									has_relation_lover = scope:actor
									has_relation_soulmate = scope:actor
								}
								trigger_if = {
									limit = {
										is_female = yes
									}
									age < define:NChildbirth|MAX_FEMALE_REPRODUCTION_AGE
								}
							}
						}
						add_opinion = {
							target = scope:recipient
							modifier = grateful_opinion
							opinion = 40
						}
					}
					else_if = {
						limit = {
							scope:secondary_recipient = {
								OR = {
									is_lowborn = no
									has_trait = beauty_good_1
									num_of_good_genetic_traits > 0
									has_relation_friend = scope:actor
									has_relation_best_friend = scope:actor
								}
								trigger_if = {
									limit = {
										is_female = yes
									}
									age < define:NChildbirth|MAX_FEMALE_REPRODUCTION_AGE
								}
							}
						}
						add_opinion = {
							target = scope:recipient
							modifier = grateful_opinion
							opinion = 30
						}
					}
					else = {
						add_opinion = {
							target = scope:recipient
							modifier = grateful_opinion
							opinion = 20
						}
					}
				}
			}
		}
	}
	scope:secondary_recipient = {
		hidden_effect = {
			if = {
				limit = { scope:recipient.dynasty = scope:secondary_recipient.dynasty }
				remove_trait = concubine
				add_trait = concubine_elevated
			}
		}
	}
}

concubine_truce_on_accept_effect = {
	$CONCUBINE$ = { save_scope_as = concubine }
	$ACTOR$ = { save_scope_as = concubinist }
	$CONCUBINE$ = {
		trigger_event = marriage_interaction.0040
		if = {
			# Victim is angry for being forced into concubinage.
			limit = {
				is_imprisoned = yes
			}
			add_character_flag = {
				flag = block_release_from_prison_event
				days = 3
			}
			release_from_prison = yes
			add_opinion = {
				target = $ACTOR$
				modifier = forced_me_concubine_marriage_opinion
			}

			# Family members of victim are also angry that you've forced them into concubinage.
			every_close_family_member = {
				if = {
					limit = { 
						NOT = { this = $ACTOR$ } # Don't hate yourself.
					}
					add_opinion = {
						target = $ACTOR$
						modifier = forced_family_concubine_marriage_opinion
					}
					hidden_effect = {
						send_interface_message = {
							type = msg_family_became_concubine
							title = msg_close_family_member_offered_as_concubine_title
							right_icon = $RECIPIENT$
							left_icon = $CONCUBINE$
							show_as_tooltip = { $CONCUBINE$ = { make_concubine = $RECIPIENT$ } }
						}
					}

					# Family members are even *more* angry if they don't believe in concubines/polyamory (different from polygamy). Also if they don't accept same-sex relationships
					if = {
						limit = { 
							OR = {
								NOT = { faith = { has_doctrine = doctrine_concubines } }
								NOT = { faith = { has_doctrine = tenet_polyamory } }
								AND = {
									allowed_to_marry_same_sex_trigger = no
									$RECIPIENT$ = { sex_same_as = $CONCUBINE$ }
								}
							}
						}
						add_opinion = {
							target = $ACTOR$
							modifier = relative_in_blasphemous_union_opinion
						}
					}
				}
			}
					
			# Spouses, if any exist, are also furious.
			if = {
				limit = {
					is_married = yes
					#A check to make sure you haven't somehow married them during the consideration time
					NOT = { any_spouse = { this = $RECIPIENT$ } }
				}
				every_spouse = {
					add_opinion = {
						target = $ACTOR$
						modifier = forced_spouse_concubine_marriage_opinion
					}
					divorce = $CONCUBINE$ # no additional opinion hit, no scripted effect
					save_scope_value_as = { # For tooltips in the coming event
						name = was_spouse
						value = yes
					}
					trigger_event = marriage_interaction.0043
				}
			}
					
			# Stealing concubines pisses the former concubinist off.
			if = {
				limit = {
					is_concubine = yes
					#A check to make sure you haven't somehow gotten them as concubine during the consideration time
					NOT = { any_consort = { this = $RECIPIENT$ } }
				}
				this.concubinist = {
					if = {
						limit = {
							NOT = {
								this = $ACTOR$
							}
						}
						add_opinion = {
							target = $ACTOR$
							modifier = stole_concubine_opinion
						}
						remove_concubine = $CONCUBINE$ # no additional opinion hit, no scripted effect
						save_scope_value_as = { # For tooltips in the coming event
							name = was_concubine
							value = yes
						}
						trigger_event = marriage_interaction.0043
					}
					else = {
						remove_concubine = $CONCUBINE$ # no additional opinion hit, no scripted effect
					}
				}
			}

			# Break any betrothals which may exist (without additional opinion penalties).
			if = {
				limit = {
					exists = betrothed
					#A check to make sure you haven't somehow gotten betrothed to them during the consideration time
					NOT = { betrothed = $RECIPIENT$ }
				}
				betrothed = { trigger_event = marriage_interaction.0043 }
				break_betrothal = betrothed
			}

			# Having concubines means they're now no longer yours.
			if = {
				limit = { number_of_concubines > 0	}
				every_concubine = {
					$CONCUBINE$ = {
						remove_concubine = prev
					}
				}
			}
		}
		if = {
			limit = {
				is_concubine_of = $ACTOR$
			}
			$ACTOR$ = {
				remove_concubine = $CONCUBINE$
			}
		}
		remove_character_flag = has_been_offered_as_concubine
	}

	# Send us a notification about what we just did. If the concubine somehow ended up as a consort (spouse/concubine) or betrothed to recipient during the consideration time of this request we'll send a message about that instead (should only happen to AI tho)
	if = {
		limit = { #Invalidation message
			$CONCUBINE$ = {
				OR = {
					any_spouse = { count >= 1 }
					exists = betrothed
				}
			}
		}
		$CONCUBINE$ = {
			# If they've somehow already become entangled with the recipient we tell this
			if = {
				limit = {
					OR = {
						is_consort_of = $RECIPIENT$
						AND = {
							exists = betrothed
							betrothed = $RECIPIENT$
						}
					}
				}
				$RECIPIENT$ = {
					save_scope_as = spouse
				}
			}
			# Else, if they've married or gotten betrothed to someone else, we say this
			else_if = {
				limit = {
					exists = betrothed
				}
				betrothed = {
					save_scope_as = spouse
				}
			}
			else = {
				random_consort = {
					limit = {
						this = $CONCUBINE$.primary_spouse
					}
					alternative_limit = {
						always = yes
					}
					save_scope_as = spouse
				}
			}
		}
		$ACTOR$ = {
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = msg_truce_concubine_invalidated_title
				right_icon = $RECIPIENT$
				left_icon = $CONCUBINE$
				if = {
					limit = {
						$CONCUBINE$ = { is_consort_of = scope:spouse }
					}
					custom_tooltip = msg_concubine_offered_invalidated_consort
				}
				else = {
					custom_tooltip = msg_concubine_offered_invalidated_betrothed
				}
			}
		}
		$RECIPIENT$ = {
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = msg_truce_concubine_invalidated_recipient_title
				right_icon = $ACTOR$
				left_icon = $CONCUBINE$
				if = {
					limit = {
						$CONCUBINE$ = { is_consort_of = scope:spouse }
					}
					custom_tooltip = msg_concubine_offered_invalidated_consort
				}
				else = {
					custom_tooltip = msg_concubine_offered_invalidated_betrothed
				}
			}
		}
	}
	else = { #Proper notification
		$ACTOR$ = {
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = msg_truce_concubine_title
				right_icon = $RECIPIENT$
				left_icon = $CONCUBINE$
				$RECIPIENT$ = {
					make_concubine = $CONCUBINE$
					if = { #Scale opinion gain a bit depending on how cool the concubine is
						limit = {
							$CONCUBINE$ = {
								OR = {
									has_trait = beauty_good_2
									has_trait = beauty_good_3
									num_of_good_genetic_traits > 1
									has_relation_lover = $RECIPIENT$
									has_relation_soulmate = $RECIPIENT$
								}
								trigger_if = {
									limit = {
										is_female = yes
									}
									age < define:NChildbirth|MAX_FEMALE_REPRODUCTION_AGE
								}
							}
						}
						add_opinion = {
							target = $ACTOR$
							modifier = grateful_opinion
							opinion = 40
						}
					}
					else_if = {
						limit = {
							$CONCUBINE$ = {
								OR = {
									is_lowborn = no
									has_trait = beauty_good_1
									num_of_good_genetic_traits > 0
									has_relation_friend = $RECIPIENT$
									has_relation_best_friend = $RECIPIENT$
								}
								trigger_if = {
									limit = {
										is_female = yes
									}
									age < define:NChildbirth|MAX_FEMALE_REPRODUCTION_AGE
								}
							}
						}
						add_opinion = {
							target = $ACTOR$
							modifier = grateful_opinion
							opinion = 30
						}
					}
					else = {
						add_opinion = {
							target = $ACTOR$
							modifier = grateful_opinion
							opinion = 20
						}
					}
				}
			}
		}
	}
	$CONCUBINE$ = {
		hidden_effect = {
			if = {
				limit = { $ACTOR$.dynasty = $CONCUBINE$.dynasty }
				remove_trait = concubine
				add_trait = concubine_elevated
			}
		}
	}
	$ACTOR$ = {
		show_as_tooltip = {
			add_truce_both_ways = {
				character = $RECIPIENT$
				days = 1825	# 5 years
				name = TRUCE_CONCUBINE_ACCEPTED
			}
		}
		hidden_effect = {
			add_truce_both_ways = {
				character = $RECIPIENT$
				days = 1825	# 5 years
				name = TRUCE_CONCUBINE_ACCEPTED
			}		
		}
	}
}
#### MOD END ####