﻿namespace = relation_upgrade

# 0001-0999 - Tournament (Sean)
# 1001-1999 - Shite Party (Ewan)
# 2001-2099 - Character is very passionate about something (lover/soulmate), Mathilda
# 2100-2199 - Throw diseased corpses at your (potential) rival (Linnea)


#########################
# Tournament Troubles 	#
# by Sean Hughes		#
# 0001-0100				#
#########################

scripted_trigger relation_upgrade_0001_has_two_options_trigger = {
	calc_true_if = {
		amount >= 2
		exists = scope:option_rival
		exists = scope:option_friend
		exists = scope:option_lover
		exists = scope:option_drink
		exists = scope:option_food
		exists = scope:option_prowess
		exists = scope:option_gossip
		exists = scope:option_book
	}
}

scripted_trigger relation_upgrade_0001_is_valid_participant_trigger = {
	is_available = yes
	top_liege = root.top_liege
	OR = {
		upgrade_ready_potential_rival_to_rival_trigger = { CHARACTER = root }
		upgrade_ready_rival_to_nemesis_trigger = { CHARACTER = root }

		AND = {
			upgrade_ready_potential_lover_to_lover_trigger = { CHARACTER = root }
			might_cheat_on_every_partner_trigger = yes
			# We have to check this here so that it's nestled into the base trigger without affecting the other relations.
			root = { might_cheat_on_every_partner_trigger = yes }
		}

		upgrade_ready_potential_friend_to_friend_trigger = { CHARACTER = root }
		upgrade_ready_friend_to_best_friend_trigger = { CHARACTER = root }
	}
	NOT = { has_character_flag = was_the_target_in_any_relation_upgrade_event }

	trigger_if = {
		limit = {
			exists = scope:first
		}
		this != scope:first
	}
	trigger_if = {
		limit = {
			exists = scope:second
		}
		this != scope:second
	}
}

scripted_effect relation_upgrade_0001_rival_effect = {
	if = {
		limit = {
			has_relation_rival = $RIVAL$
		}
		set_relation_nemesis = {
			target = $RIVAL$
			copy_reason = rival
			reason = rival_tourney_troubles
		}
	}
	else = {
		set_relation_rival = {
			target = $RIVAL$
			reason = rival_tourney_troubles
		}
	}
}

scripted_effect relation_upgrade_0001_friend_effect = {
	if = {
		limit = {
			has_relation_friend = $FRIEND$
		}
		set_relation_best_friend = { reason = best_friend_bonded_at_tourney copy_reason = friend target = $FRIEND$ }
	}
	else = {
		set_relation_friend = { reason = friend_bonded_at_tourney target = $FRIEND$ }
	}
}

relation_upgrade.0001 = {
	type = character_event
	title = relation_upgrade.0001.t
	desc = {
		desc = relation_upgrade.0001.desc.opening
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:first
					exists = scope:rival
					scope:first = scope:rival
				}
				desc = relation_upgrade.0001.desc.rival
			}
			triggered_desc = {
				trigger = {
					exists = scope:first
					exists = scope:friend
					scope:first = scope:friend
				}
				desc = relation_upgrade.0001.desc.friend
			}
			triggered_desc = {
				trigger = {
					exists = scope:first
					exists = scope:lover
					scope:first = scope:lover
				}
				desc = relation_upgrade.0001.desc.lover
			}
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:second
					exists = scope:friend
					scope:second = scope:friend
				}
				desc = relation_upgrade.0001.desc.second_friend
			}
			triggered_desc = {
				trigger = {
					exists = scope:second
					exists = scope:lover
					scope:second = scope:lover
				}
				desc = relation_upgrade.0001.desc.second_lover
			}
		}
		triggered_desc = {
			trigger = { NOT = { exists = scope:second }}
			desc = relation_upgrade.0001.desc.second_bridge
		}
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:option_gossip }
				desc = relation_upgrade.0001.desc.gossip
			}
			triggered_desc = {
				trigger = { exists = scope:option_drink }
				desc = relation_upgrade.0001.desc.drink
			}
			triggered_desc = {
				trigger = { exists = scope:option_food }
				desc = relation_upgrade.0001.desc.food
			}
			triggered_desc = {
				trigger = { exists = scope:option_prowess }
				desc = relation_upgrade.0001.desc.prowess
			}
			triggered_desc = {
				trigger = { exists = scope:option_book }
				desc = relation_upgrade.0001.desc.book
			}
		}

	}
	theme = party
	override_background = {
		reference = army_camp
	}
	left_portrait = {
		character = scope:first
		triggered_animation = {
			trigger = {	exists = scope:rival }
			animation = dismissal
		}
		triggered_animation = {
			trigger = { NOT = { exists = scope:rival } }
			animation = boredom
		}
	}
	right_portrait = {
		character = scope:second
		animation = boredom
	}

	trigger = {
		is_landed = yes
		is_available_adult = yes
		any_relation = {
			type = potential_rival
			type = rival
			type = potential_friend
			type = friend
			type = potential_lover
			
			relation_upgrade_0001_is_valid_participant_trigger = yes
			save_temporary_scope_as = relation_upgrade_check
		}
		NOT = { has_character_flag = had_any_relation_upgrade_event }
		OR = {
			NOT = { exists = var:had_relation_upgrade_0001 }
			AND = {
				exists = var:had_relation_upgrade_0001
				NOT = { var:had_relation_upgrade_0001 = scope:relation_upgrade_check }
			}
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = -0.5
			exists = var:had_relation_upgrade_0001
		}
	}

	immediate = {
		add_character_flag = {
			flag = had_any_relation_upgrade_event
			years = 15
		}
		if = { # Antagonize rival.
			limit = {
				relation_upgrade_0001_has_two_options_trigger = no
				any_relation = {
					type = potential_rival
					type = rival
					relation_upgrade_0001_is_valid_participant_trigger = yes
					OR = {
						upgrade_ready_potential_rival_to_rival_trigger = { CHARACTER = root }
						upgrade_ready_rival_to_nemesis_trigger = { CHARACTER = root }
					}
				}
			}
			random_relation = {
				type = potential_rival
				type = rival
				limit = { # If this event has popped before it wasn't about this character
					exists = root.var:had_relation_upgrade_0001
					NOT = { this = root.var:had_relation_upgrade_0001 }
					relation_upgrade_0001_is_valid_participant_trigger = yes
					OR = {
						upgrade_ready_rival_to_nemesis_trigger = { CHARACTER = root }
						upgrade_ready_potential_rival_to_rival_trigger = { CHARACTER = root }
					}
				}
				alternative_limit = {
					has_relation_rival = root # Favor picking actual rivals.
					relation_upgrade_0001_is_valid_participant_trigger = yes
					upgrade_ready_rival_to_nemesis_trigger = { CHARACTER = root }
				}
				alternative_limit = {
					relation_upgrade_0001_is_valid_participant_trigger = yes
					upgrade_ready_potential_rival_to_rival_trigger = { CHARACTER = root }
				}
				save_scope_as = rival # For options/loc
				save_scope_as = first # For portraits
				root = {			
					save_scope_value_as = {
						name = option_rival
						value = yes
					}
					set_variable = { #Unop: This variable must be on the root scope, not the selected char
						name = had_relation_upgrade_0001
						value = scope:rival
						years = 20
					}
				}
			}
		}
		if = { # Sit and chat with friend.
			limit = {
				relation_upgrade_0001_has_two_options_trigger = no
				any_relation = {
					type = potential_friend
					type = friend
					relation_upgrade_0001_is_valid_participant_trigger = yes
					OR = {
						upgrade_ready_potential_friend_to_friend_trigger = { CHARACTER = root }
						upgrade_ready_friend_to_best_friend_trigger = { CHARACTER = root }
					}
				}
			}
			random_relation = {
				type = potential_friend
				type = friend
				limit = { # If this event has popped before it wasn't about this character
					exists = root.var:had_relation_upgrade_0001
					NOT = { this = root.var:had_relation_upgrade_0001 }
					relation_upgrade_0001_is_valid_participant_trigger = yes
					OR = {
						upgrade_ready_potential_friend_to_friend_trigger = { CHARACTER = root }
						upgrade_ready_friend_to_best_friend_trigger = { CHARACTER = root }
					}
				}
				alternative_limit = {
					has_relation_friend = root # Favor picking actual friends.
					relation_upgrade_0001_is_valid_participant_trigger = yes
					upgrade_ready_friend_to_best_friend_trigger = { CHARACTER = root }
				}
				alternative_limit = {
					relation_upgrade_0001_is_valid_participant_trigger = yes
					upgrade_ready_potential_friend_to_friend_trigger = { CHARACTER = root }
				}
				save_scope_as = friend # For options/loc
				if = { # For portraits
					limit = { NOT = { exists = scope:first } }
					save_scope_as = first
				}
				else = {
					save_scope_as = second
				}
				root = {
					save_scope_value_as = {
						name = option_friend
						value = yes
					}
					set_variable = { #Unop: This variable must be on the root scope, not the selected char
						name = had_relation_upgrade_0001
						value = scope:friend
						years = 20
					}
				}
			}
		}
		if = { # Sneak away with lover
			limit = {
				relation_upgrade_0001_has_two_options_trigger = no
				any_relation = {
					type = potential_lover
					relation_upgrade_0001_is_valid_participant_trigger = yes
					upgrade_ready_potential_lover_to_lover_trigger = { CHARACTER = root }
				}
			}
			random_relation = {
				type = potential_lover
				limit = { # If this event has popped before it wasn't about this character
					exists = root.var:had_relation_upgrade_0001
					NOT = { this = root.var:had_relation_upgrade_0001 }
					relation_upgrade_0001_is_valid_participant_trigger = yes
					upgrade_ready_potential_lover_to_lover_trigger = { CHARACTER = root }
				}
				alternative_limit = {
					relation_upgrade_0001_is_valid_participant_trigger = yes
					upgrade_ready_potential_lover_to_lover_trigger = { CHARACTER = root }
				}
				save_scope_as = lover # For options/loc
				if = { # For portraits
					limit = { NOT = { exists = scope:first } }
					save_scope_as = first
				}
				else = {
					save_scope_as = second
				}
				root = {
					save_scope_value_as = {
						name = option_lover
						value = yes
					}
					set_variable = { #Unop: This variable must be on the root scope, not the selected char
						name = had_relation_upgrade_0001
						value = scope:lover
						years = 20
					}
				}
			}
		}
		if = { # Listen for gossip
			limit = {
				relation_upgrade_0001_has_two_options_trigger = no
				OR = {
					intrigue >= high_skill_rating
					has_trait = deceitful
					has_trait = paranoid
					has_trait = ambitious
					has_trait_rank = {
						trait = education_intrigue
						rank >= 2
					}
				}
				NOR = {
					intrigue < mediocre_skill_rating
					has_trait = trusting
					has_trait = honest
					has_trait = just
				}
				liege = {
					any_vassal = {
						this != root
					}
				}
			}
			save_scope_value_as = {
				name = option_gossip
				value = yes
			}
		}
		if = { # Feast to reduce stress.
			limit = {
				relation_upgrade_0001_has_two_options_trigger = no
				NOT = { has_trait = drunkard } # Has it's own option.
				OR = {
					has_trait = gluttonous
					has_trait = comfort_eater
				}
			}
			save_scope_value_as = {
				name = option_food
				value = yes
			}
		}
		if = { # Drink to reduce stress.
			limit = {
				relation_upgrade_0001_has_two_options_trigger = no
				OR = {
					has_trait = drunkard
					can_be_drunkard = yes
				}
			}
			save_scope_value_as = {
				name = option_drink
				value = yes
			}
		}
		if = { # Show off prowess.
			limit = {
				relation_upgrade_0001_has_two_options_trigger = no
				prowess >= decent_skill_rating
				NOR = {
					has_trait = shy
					has_trait = humble
				}
			}
			save_scope_value_as = {
				name = option_prowess
				value = yes
			}
		}
		if = { # Read holy book. Fallback-ish option.
			limit = {
				relation_upgrade_0001_has_two_options_trigger = no
			}
			save_scope_value_as = {
				name = option_book
				value = yes
			}
		}

		add_to_variable_list = {
			name = had_relation_upgrade_0001
			target = flag:lifestyle_diplomat
		}
	}

	# Option 1: Push (potential) rival into the water trough.
	option = {
		name = relation_upgrade.0001.rival
		trigger = { exists = scope:option_rival }

		scope:rival = {
			add_prestige = medium_prestige_loss
			hidden_effect = {
				add_character_flag = {
					flag = was_the_target_in_any_relation_upgrade_event
					years = 15
				}
			}
		}
		if = { # If target is an AI, they always 'auto-accept' and upgrade the relation.
			limit = {
				scope:rival = {
					is_ai = yes
				}
			}
			relation_upgrade_0001_rival_effect = {
				RIVAL = scope:rival
			}
		}
		else = { # If target is another player, they can decide to upgrade the relation or not.
			show_as_tooltip = {
				random_list = {
					1 = {
						desc = relation_upgrade.0011.rival.accept.toast
						show_chance = no
						relation_upgrade_0001_rival_effect = {
							RIVAL = scope:rival
						}
					}
					1 = {
						desc = relation_upgrade.0011.rival.decline.toast
						show_chance = no
					}
				}
			}
			hidden_effect = {
				save_scope_as = source
				scope:rival = {
					trigger_event = {
						id = relation_upgrade.0011
						days = 1
					}
				}
			}
		}
		add_prestige = medium_prestige_gain
		stress_impact = {
			base = medium_stress_loss

			# Stress Loss
			sadistic = medium_stress_loss
			vengeful = medium_stress_loss
			wrathful = medium_stress_loss
			arbitrary = minor_stress_loss
			impatient = minor_stress_loss

			# Stress Gain
			compassionate = major_stress_gain
			just = medium_stress_gain
		}
	}

	# Option 2: Spend some time socializing with your (potential) friend.
	option = {
		name = relation_upgrade.0001.friend
		trigger = { exists = scope:option_friend }
		scope:friend = {
			hidden_effect = {
				add_character_flag = {
					flag = was_the_target_in_any_relation_upgrade_event
					years = 15
				}
			}
		}

		if = { # If target is an AI, they always 'auto-accept' and upgrade the relation.
			limit = {
				scope:friend = {
					is_ai = yes
				}
			}
			relation_upgrade_0001_friend_effect = {
				FRIEND = scope:friend
			}
		}
		else = { # If target is another player, they can decide to upgrade the relation or not.
			show_as_tooltip = {
				random_list = {
					1 = {
						desc = relation_upgrade.0011.friend.accept.toast
						show_chance = no
						relation_upgrade_0001_friend_effect = {
							FRIEND = scope:friend
						}
					}
					1 = {
						desc = relation_upgrade.0011.friend.decline.toast
						show_chance = no
					}
				}
			}
			hidden_effect = {
				save_scope_as = source
				scope:friend = {
					trigger_event = {
						id = relation_upgrade.0011
						days = 1
					}
				}
			}
		}

		stress_impact = {
			shy = minor_stress_gain
			gregarious = minor_stress_loss
		}
	}

	# Option 3: Sneak off with your (potential) lover.
	option = {
		name = relation_upgrade.0001.lover
		trigger = { exists = scope:option_lover }
		scope:lover = {
			hidden_effect = {
				add_character_flag = {
					flag = was_the_target_in_any_relation_upgrade_event
					years = 15
				}
			}
		}

		if = { # If target is an AI, they always 'auto-accept' and upgrade the relation.
			limit = {
				scope:lover = {
					is_ai = yes
				}
			}
			had_sex_with_effect = {
				CHARACTER = scope:lover
				PREGNANCY_CHANCE = pregnancy_chance
	 		}
			progress_towards_lover_effect = {
				CHARACTER = scope:lover
				REASON = lover_tourney_upgrade
				OPINION = 0
			}
			# Stress gain/loss is handled by the 'had_sex_with' effect.
		}
		else = { # If target is another player, they can decide to upgrade the relation or not.
			show_as_tooltip = {
				random_list = {
					1 = {
						desc = relation_upgrade.0011.lover.accept.toast
						show_chance = no
						had_sex_with_effect = {
							CHARACTER = scope:lover
							PREGNANCY_CHANCE = pregnancy_chance
				 		}
						progress_towards_lover_effect = {
							CHARACTER = scope:lover
							REASON = lover_tourney_upgrade_opposite
							OPINION = 0
						}
					}
					1 = {
						desc = relation_upgrade.0011.lover.decline.toast
						show_chance = no
					}
				}
			}
			hidden_effect = {
				save_scope_as = source
				scope:lover = {
					trigger_event = {
						id = relation_upgrade.0011
						days = 1
					}
				}
			}
		}
	}
	
	# Option 4: Indulge in drink
	option = {
		name = relation_upgrade.0001.drink
		trigger = { exists = scope:option_drink }

		stress_impact = {
			base = medium_stress_impact_loss
			drunkard = minor_stress_impact_loss
		}
		if = {
			limit = {
				NOT = { has_trait = drunkard }
			}
			random = {
				chance = 10
				add_trait = drunkard
			}
		}
	}

	# Option 5: Indulge in food
	option = {
		name = relation_upgrade.0001.food
		trigger = { exists = scope:option_food }

		stress_impact = {
			base = minor_stress_impact_loss
			gluttonous = minor_stress_impact_loss
			comfort_eater = minor_stress_impact_loss
			greedy = minor_stress_impact_loss
		}
	}

	# Option 6: Show off to win admiration and respect
	option = {
		name = relation_upgrade.0001.prowess
		trigger = { exists = scope:option_prowess }

		skill = prowess
		add_prestige = medium_prestige_gain
	}

	# Option 7: Listen for gossip
	option = {
		name = relation_upgrade.0001.gossip
		trigger = { exists = scope:option_gossip }

		custom_tooltip = relation_upgrade.0001.gossip.tt
		hidden_effect = {
			liege = {
				random_vassal = {
					# Prefer vassals who actually have a secret we don't know.
					limit = {
						this != root
						any_secret = {
							NOT = { is_known_by = root }
						}
					}
					# But in a pinch, anyone will do.
					alternative_limit = {
						this != root
					}
					save_scope_as = gossip_target
				}
			}
			scope:gossip_target = {
				# If the gossip target doesn't have any secrets to reveal, fabricate one.
				if = {
					limit = {
						NOT = {		
							any_secret = {
								NOT = { is_known_by = root }
							}
						}
					}
					random_list = {
						1 = {
							trigger = {
								NOT = { has_trait = chaste}
								is_deviant_trigger = no
								secret_deviant_is_valid_trigger = { OWNER = this }
							}
							add_secret = {
								type = secret_deviant
							}
						}
						1 = {
							trigger = {
								is_cannibal_trigger = no
								secret_cannibal_is_valid_trigger = { OWNER = this }
							}
							add_secret = {
								type = secret_cannibal
							}
						}
						1 = {
							trigger = {
								NOT = { any_secret = { type = secret_non_believer }}
								secret_non_believer_is_valid_trigger = { OWNER = this }
							}
							add_secret = {
								type = secret_non_believer
							}
						}
					}
				}
				# Reveal a random unknown secret to us.
				random_secret = {
					limit = {
						NOT = { is_known_by = root}
					}
					reveal_to = root
				}
			}
		}
	}

	# Option 8: Read your holy book in peace and quiet.
	option = {
		name = relation_upgrade.0001.book
		trigger = { exists = scope:option_book }

		add_piety = medium_piety_gain
		stress_impact = {
			zealous = minor_stress_loss
			reclusive = minor_stress_loss
			gregarious = minor_stress_gain
			cynical = minor_stress_gain
		}
	}

	## Opt-Out.
	option = {
		name = relation_upgrade.0001.opt_out
		trigger = {
			calc_true_if = {
				amount <= 2
				exists = scope:option_rival
				exists = scope:option_friend
				exists = scope:option_lover
				exists = scope:option_drink
				exists = scope:option_food
				exists = scope:option_gossip
				exists = scope:option_prowess
				exists = scope:option_book
			}
		}
		stress_impact = {
			base = minor_stress_impact_loss
		}
	}
}

relation_upgrade.0011 = {
	type = character_event
	title = relation_upgrade.0011.t
	desc = {
		desc = relation_upgrade.0001.desc.opening
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:rival
					this = scope:rival
				}
				desc = relation_upgrade.0011.desc.rival
			}
			triggered_desc = {
				trigger = {
					exists = scope:friend
					this = scope:friend
				}
				desc = relation_upgrade.0011.desc.friend
			}
			triggered_desc = {
				trigger = {
					exists = scope:lover
					this = scope:lover
				}
				desc = relation_upgrade.0011.desc.lover
			}
		}
	}
	theme = party
	override_background = {
		reference = army_camp
	}
	left_portrait = {
		character = scope:source
		triggered_animation = {
			trigger = {
				exists = scope:rival
				this = scope:rival
			}
			animation = schadenfreude
		}
		triggered_animation = {
			trigger = {
				exists = scope:friend
				this = scope:friend
			}
			animation = happiness
		}
		triggered_animation = {
			trigger = {
				exists = scope:friend
				this = scope:friend
			}
			animation = admiration
		}
	}

	immediate = {
		if = {
			limit = {
				exists = scope:rival
				this = scope:rival
			}
			show_as_tooltip = { add_prestige = medium_prestige_loss }
		}
	}

	# Escalate Rivalry
	option = {
		trigger = {
			exists = scope:rival
			this = scope:rival
		}
		name = relation_upgrade.0011.rival.accept

		show_as_tooltip = {
			relation_upgrade_0001_rival_effect = {
				RIVAL = scope:source
			}
		}
		hidden_effect = {
			scope:source = {	
				send_interface_toast = {
					title = relation_upgrade.0011.rival.accept.toast
		 			left_icon = scope:rival
		 			relation_upgrade_0001_rival_effect = {
						RIVAL = scope:rival
					}
		 		}
			}
		}
		
	}

	# Descalate Rivalry
	option = {
		trigger = {
			exists = scope:rival
			this = scope:rival
		}
		name = relation_upgrade.0011.rival.decline

		show_as_tooltip = {	
			if = {
				limit = {
					has_relation_potential_rival = scope:source
				}
				remove_relation_potential_rival = scope:source
			}
			else_if = {
				limit = {
					has_relation_rival = scope:source
				}
				remove_relation_rival = scope:source
			}
		}
		hidden_effect = {
			scope:source = {	
				send_interface_toast = {
					title = relation_upgrade.0011.rival.decline.toast
		 			left_icon = scope:rival

		 			if = {
						limit = {
							has_relation_potential_rival = scope:rival
						}
						remove_relation_potential_rival = scope:rival
					}
					else_if = {
						limit = {
							has_relation_rival = scope:rival
						}
						remove_relation_rival = scope:rival
					}
		 		}
			}
		}
	}

	# Improve Friendship
	option = {
		trigger = {
			exists = scope:friend
			this = scope:friend
		}
		name = relation_upgrade.0011.friend.accept

		show_as_tooltip = {
			relation_upgrade_0001_friend_effect = {
				FRIEND = scope:source
			}
		}
		hidden_effect = {
			scope:source = {	
				send_interface_toast = {
					title = relation_upgrade.0011.friend.accept.toast
		 			left_icon = scope:friend
		 			relation_upgrade_0001_friend_effect = {
						FRIEND = scope:friend
					}
		 		}
			}
		}
		
	}

	# Harm Friendship
	option = {
		trigger = {
			exists = scope:friend
			this = scope:friend
		}
		name = relation_upgrade.0011.friend.decline

		show_as_tooltip = {	
			if = {
				limit = {
					has_relation_potential_friend = scope:source
				}
				remove_relation_potential_friend = scope:source
			}
		}
		hidden_effect = {
			scope:source = {	
				send_interface_toast = {
					title = relation_upgrade.0011.friend.decline.toast
		 			left_icon = scope:friend
		 		}

		 		if = {
					limit = {
						has_relation_potential_friend = scope:friend
					}
					remove_relation_potential_friend = scope:friend
				}
			}
		}
	}

	# Become Lovers
	option = {
		trigger = {
			exists = scope:lover
			this = scope:lover
		}
		name = relation_upgrade.0011.lover.accept

		show_as_tooltip = {
			had_sex_with_effect = {
				CHARACTER = scope:source
				PREGNANCY_CHANCE = pregnancy_chance
	 		}
			progress_towards_lover_effect = {
				CHARACTER = scope:source
				REASON = lover_tourney_upgrade_opposite
				OPINION = 0
			}
		}
		hidden_effect = {
			scope:source = {	
				send_interface_toast = {
					title = relation_upgrade.0011.lover.accept.toast
		 			left_icon = scope:lover
		 			
		 			had_sex_with_effect = {
						CHARACTER = scope:lover
						PREGNANCY_CHANCE = pregnancy_chance
			 		}
					progress_towards_lover_effect = {
						CHARACTER = scope:lover
						REASON = lover_tourney_upgrade_opposite
						OPINION = 0
					}
		 		}
			}
		}
	}

	# Squash Potential Lover Status
	option = {
		trigger = {
			exists = scope:lover
			this = scope:lover
		}
		name = relation_upgrade.0011.lover.decline

		show_as_tooltip = {	
			if = {
				limit = {
					has_relation_potential_lover = scope:source
				}
				remove_relation_potential_lover = scope:source
			}
		}
		hidden_effect = {
			scope:source = {	
				send_interface_toast = {
					title = relation_upgrade.0011.lover.decline.toast
		 			left_icon = scope:lover
		 		}

		 		if = {
					limit = {
						has_relation_potential_lover = scope:lover
					}
					remove_relation_potential_lover = scope:lover
				}
			}
		}
	}

}



##################################################
# A Night to Forget
# by Ewan Cowhig Croft
# 1001
##################################################

scripted_trigger suitable_host_trigger = {
	is_available_ai_adult = yes
	#The host should be unimportant to the player, typically.
	NOR = {
		has_relation_potential_friend = root
		has_relation_friend = root
		has_relation_potential_lover = root
		has_relation_lover = root
		has_relation_potential_rival = root
		has_relation_rival = root
	}
	#Somewhat believable that they'd throw a bad party.
	diplomacy <= mediocre_skill_rating
}
scripted_trigger viable_positive_relation_trigger = {
	always = yes
	is_available_ai_adult = yes
	#Must be at least a little cordial.
	opinion = {
		target = root
		value >= low_positive_opinion
	}
	NOT = { has_character_flag = was_the_target_in_any_relation_upgrade_event }
}
scripted_trigger viable_potential_rival_trigger = {
	is_available_ai_adult = yes
	#Must be somewhat annoyed with the prospective rival.
	opinion = {
		target = root
		value <= low_negative_opinion
	}
	NOT = { has_character_flag = was_the_target_in_any_relation_upgrade_event }
}
scripted_trigger can_have_reveller_option_trigger = {
	OR = {
		#Natural party animals.
		has_trait = lifestyle_reveler
		has_trait = gregarious
		ai_sociability >= medium_positive_ai_value

		#Taking pity on the host.
		AND = {
			opinion = {
				target = scope:terrible_party_host
				value >= low_positive_opinion
			}
			OR = {
				has_trait = generous
				has_trait = patient
				has_trait = compassionate
				has_trait = forgiving
				ai_compassion >= medium_positive_ai_value
			}
		}

		#Taking pity on a relative.
		AND = {
			OR = {
				opinion = {
					target = scope:terrible_party_host
					value >= neutral_opinion
				}
				has_trait = family_first
			}
			scope:terrible_party_host = {
				dynasty = root.dynasty
			}
		}
	}
}
scripted_trigger can_have_burn_the_building_trigger = {
	OR = {
		#Appropriate trait requirements.
		has_trait = lunatic_1
		has_trait = sadistic
		has_trait = vengeful
		has_trait = callous

		#Or just having a bad enough day.
		calc_true_if = {
			amount >= 2

			has_trait = wrathful
			has_trait = impatient
			has_trait = arbitrary
			has_trait = fickle
		}
	}
}
scripted_trigger can_have_meet_new_person_trigger = {
	can_set_relation_potential_friend_trigger = { CHARACTER = root }
	
	#You must have something to talk about with the person.
	number_of_personality_traits_in_common = {
		target = root
		value >= 2
	}
	opinion = {
		target = root
		value >= low_positive_opinion
	}
}

#	You attend a terrible party.
#		by Ewan Cowhig Croft
relation_upgrade.1001 = {
	type = character_event
	title = relation_upgrade.1001.t
	desc = {
		desc = relation_upgrade.1001.desc.intro
		triggered_desc = {
			trigger = { has_character_flag = relation_upgrade_potential_friend }
			desc = relation_upgrade.1001.desc.friend
		}
		triggered_desc = {
			trigger = { has_character_flag = relation_upgrade_potential_lover }
			desc = relation_upgrade.1001.desc.lover
		}
		triggered_desc = {
			trigger = { has_character_flag = relation_upgrade_potential_rival }
			desc = relation_upgrade.1001.desc.rival
		}
		desc = relation_upgrade.1001.desc.outro
	}
	theme = party
	left_portrait = {
		character = scope:left_portrait
		animation = admiration
	}
	right_portrait = {
		character = scope:potential_rival
		animation = disgust
	}
	lower_center_portrait = scope:centre_portrait

	trigger = {
		is_available_at_peace_adult = yes
		is_landed = yes
		any_courtier_or_guest = { suitable_host_trigger = yes }
		OR = {
			any_relation = {
				type = potential_friend
				viable_positive_relation_trigger = yes
				count >= 1
				save_temporary_scope_as = relation_upgrade_check
			}
			any_relation = {
				type = potential_lover
				viable_positive_relation_trigger = yes
				count >= 1
				save_temporary_scope_as = relation_upgrade_check
			}
			any_relation = {
				type = potential_rival
				viable_potential_rival_trigger = yes
				count >= 1
				save_temporary_scope_as = relation_upgrade_check
			}
		}
		NOT = { has_character_flag = had_any_relation_upgrade_event }
		OR = {
			NOT = { exists = var:had_relation_upgrade_1001 }
			AND = {
				exists = var:had_relation_upgrade_1001
				NOT = { var:had_relation_upgrade_1001 = scope:relation_upgrade_check }
			}
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = -0.5
			exists = var:had_relation_upgrade_1001
		}
	}

	immediate = {
		add_character_flag = {
			flag = had_any_relation_upgrade_event
			years = 15
		}
		play_music_cue = "mx_cue_meadandwine"

		save_scope_as = party_root	#For loc & reply events.

		##ORGANISE POTENTIAL RELATIONS
		#Gather potential friends.
		every_relation = {
			type = potential_friend
			limit = { viable_positive_relation_trigger = yes }
			add_to_list = potential_friends_list
		}
		#Gather potential lovers.
		every_relation = {
			type = potential_lover
			limit = { viable_positive_relation_trigger = yes }
			add_to_list = potential_lovers_list
		}
		#Gather potential rivals.
		every_relation = {
			type = potential_rival
			limit = { viable_potential_rival_trigger = yes }
			add_to_list = potential_rivals_list
		}
		#Select a good potential friend.
		if = {
			limit = {
				any_in_list = {
					list = potential_friends_list
					count >= 1
				}
			}
			random_in_list = {
				list = potential_friends_list
				limit = {
					exists = root.var:had_relation_upgrade_1001
					NOT = { this = root.var:had_relation_upgrade_1001 }
				}
				alternative_limit = {
					always = yes
				}
				#Weight up some interesting characters from amongst your courtiers, if at all possible.
				weight = {
					base = 100
					modifier = {
						add = 100
						is_claimant = yes
					}
					modifier = {
						add = 100
						is_councillor = yes
					}
					modifier = {
						add = 50
						OR = {
							diplomacy >= high_skill_rating
							martial >= high_skill_rating
							stewardship >= high_skill_rating
							intrigue >= high_skill_rating
							learning >= high_skill_rating
							prowess >= high_skill_rating
						}
					}
				}
				save_scope_as = potential_friend
				set_variable = {
					name = had_relation_upgrade_1001
					value = scope:potential_friend
					years = 20
				}
			}
		}
		#Select a good potential lover.
		if = {
			limit = {
				any_in_list = {
					list = potential_lovers_list
					count >= 1
				}
			}
			random_in_list = {
				list = potential_lovers_list
				limit = {
					exists = root.var:had_relation_upgrade_1001
					NOT = { this = root.var:had_relation_upgrade_1001 }
				}
				alternative_limit = {
					always = yes
				}
				#Weight up some interesting characters from amongst your courtiers, if at all possible.
				weight = {
					base = 100
					modifier = {
						add = 100
						is_claimant = yes
					}
					modifier = {
						add = 100
						is_councillor = yes
					}
					modifier = {
						add = 50
						OR = {
							diplomacy >= high_skill_rating
							martial >= high_skill_rating
							stewardship >= high_skill_rating
							intrigue >= high_skill_rating
							learning >= high_skill_rating
							prowess >= high_skill_rating
						}
					}
				}
				save_scope_as = potential_lover
				set_variable = {
					name = had_relation_upgrade_1001
					value = scope:potential_lover
					years = 20
				}
			}
		}
		#Select a good potential rival.
		if = {
			limit = {
				any_in_list = {
					list = potential_rivals_list
					count >= 1
				}
			}
			random_in_list = {
				list = potential_rivals_list
				limit = {
					exists = root.var:had_relation_upgrade_1001
					NOT = { this = root.var:had_relation_upgrade_1001 }
				}
				alternative_limit = {
					always = yes
				}
				#Weight up some interesting characters from amongst your courtiers, if at all possible.
				weight = {
					base = 100
					modifier = {
						add = 100
						is_claimant = yes
					}
					modifier = {
						add = 100
						is_councillor = yes
					}
					modifier = {
						add = 50
						OR = {
							diplomacy >= high_skill_rating
							martial >= high_skill_rating
							stewardship >= high_skill_rating
							intrigue >= high_skill_rating
							learning >= high_skill_rating
							prowess >= high_skill_rating
						}
					}
				}
				save_scope_as = potential_rival
				set_variable = {
					name = had_relation_upgrade_1001
					value = scope:potential_rival
					years = 20
				}
			}
		}

		#ORGANISE PARTY GOERS
		random_courtier_or_guest = {
			limit = { suitable_host_trigger = yes }
			save_scope_as = terrible_party_host
		}
		every_courtier_or_guest = {
			limit = {
				is_available_ai_adult = yes
				NOR = {
					#Filter out anyone who might skip.
					has_trait = shy
					ai_sociability <= low_negative_ai_value
					#And remove the host from this list to.
					this = scope:terrible_party_host
				}
			}
			add_to_list = party_goers
		}

		##DETERMINE AVAILABLE RELATION OPTIONS & DESCS
		#If we have all three potential relations present, randomise which we get.
		if = {
			limit = {
				exists = scope:potential_friend
				exists = scope:potential_lover
				exists = scope:potential_rival
			}
			random_list = {
				33 = { add_character_flag = relation_upgrade_potential_friend }
				33 = { add_character_flag = relation_upgrade_potential_lover }
				33 = { add_character_flag = relation_upgrade_potential_rival }
			}
			random_list = {
				33 = {
					trigger = {
						NOT = { has_character_flag = relation_upgrade_potential_friend }
					}
					add_character_flag = relation_upgrade_potential_friend
				}
				33 = {
					trigger = {
						NOT = { has_character_flag = relation_upgrade_potential_lover }
					}
					add_character_flag = relation_upgrade_potential_lover
				}
				33 = {
					trigger = {
						NOT = { has_character_flag = relation_upgrade_potential_rival }
					}
					add_character_flag = relation_upgrade_potential_rival
				}
			}
		}
		#Otherwise, just add character flags for the existing scopes.
		else = {
			if = {
				limit = { exists = scope:potential_friend }
				add_character_flag = relation_upgrade_potential_friend
			}
			if = {
				limit = { exists = scope:potential_lover }
				add_character_flag = relation_upgrade_potential_lover
			}
			if = {
				limit = { exists = scope:potential_rival }
				add_character_flag = relation_upgrade_potential_rival
			}
		}

		##ORGANISE PORTRAITS
		#If only friend exists, give them the main slot.
		if = {
			limit = {
				has_character_flag = relation_upgrade_potential_friend
				NOT = { has_character_flag = relation_upgrade_potential_lover }
			}
			scope:potential_friend = { save_scope_as = left_portrait }
		}
		#If both exist, assign friend main slot & lover secondary slot.
		if = {
			limit = {
				has_character_flag = relation_upgrade_potential_friend
				has_character_flag = relation_upgrade_potential_lover
			}
			scope:potential_friend = { save_scope_as = left_portrait }
			scope:potential_lover = { save_scope_as = centre_portrait }
		}
		#Otherwise, assuming the lover is around, make them the main slot.
		else_if = {
			limit = { has_character_flag = relation_upgrade_potential_lover }
			scope:potential_lover = { save_scope_as = left_portrait }
		}

		##DETERMINE AVAILABLE RANDOM OPTIONS & DESCS
		#Grab two options if we only have one potential relation.
		if = {
			limit = {
				calc_true_if = {
					amount <= 1

					has_character_flag = relation_upgrade_potential_friend
					has_character_flag = relation_upgrade_potential_lover
					has_character_flag = relation_upgrade_potential_rival
				}
			}
			random_list = {
				20 = {	#Get this party started!
					trigger = { can_have_reveller_option_trigger = yes }
					add_character_flag = relation_upgrade_reveller
				}
				20 = {	#Set fire to the tavern.
					trigger = { can_have_burn_the_building_trigger = yes }
					add_character_flag = relation_upgrade_burn_building
				}
				20 = {	#Make the best of the situation.
					#Fallback: anyone can try to make the best of things.
					add_character_flag = relation_upgrade_make_best_of_it
				}
				20 = {	#Try talking to someone totally new.
					trigger = {
						any_in_list = {
							list = party_goers
							can_have_meet_new_person_trigger = yes
						}
					}
					add_character_flag = relation_upgrade_meet_new_person
				}
				20 = {	#Denounce the host and leave.
					#Fallback: anyone can blame someone else.
					add_character_flag = relation_upgrade_denounce_host
				}
			}
			random_list = {
				20 = {	#Get this party started!
					trigger = {
						can_have_reveller_option_trigger = yes
						NOT = { has_character_flag = relation_upgrade_reveller }
					}
					add_character_flag = relation_upgrade_reveller
				}
				20 = {	#Set fire to the tavern.
					trigger = {
						can_have_burn_the_building_trigger = yes
						NOT = { has_character_flag = relation_upgrade_burn_building }
					}
					add_character_flag = relation_upgrade_burn_building
				}
				20 = {	#Make the best of the situation.
					trigger = {
						NOT = { has_character_flag = relation_upgrade_make_best_of_it }
					}
					add_character_flag = relation_upgrade_make_best_of_it
				}
				20 = {	#Try talking to someone totally new.
					trigger = {
						any_in_list = {
							list = party_goers
							can_have_meet_new_person_trigger = yes
						}
						NOT = { has_character_flag = relation_upgrade_meet_new_person }
					}
					add_character_flag = relation_upgrade_meet_new_person
				}
				20 = {	#Denounce the host and leave.
					trigger = {
						#Fallback: anyone can try to make the best of things.
						NOT = { has_character_flag = relation_upgrade_denounce_host }
					}
					add_character_flag = relation_upgrade_denounce_host
				}
			}
		}
		#Otherwise, grab one option.
		else = {
			random_list = {
				20 = {	#Get this party started!
					trigger = { can_have_reveller_option_trigger = yes }
					add_character_flag = relation_upgrade_reveller
				}
				20 = {	#Set fire to the tavern.
					trigger = { can_have_burn_the_building_trigger = yes }
					add_character_flag = relation_upgrade_burn_building
				}
				20 = {	#Make the best of the situation.
					#Fallback: anyone can try to make the best of things.
					add_character_flag = relation_upgrade_make_best_of_it
				}
				20 = {	#Try talking to someone totally new.
					trigger = {
						any_in_list = {
							list = party_goers
							can_have_meet_new_person_trigger = yes
						}
					}
					add_character_flag = relation_upgrade_meet_new_person
				}
				20 = {	#Denounce the host and leave.
					#Fallback: anyone can try to make the best of things.
					add_character_flag = relation_upgrade_denounce_host
				}
			}
		}
	}

	#Friendship upgrade: hang out with someone you already know a little.
	option = {
		name = relation_upgrade.1001.a
		trigger = { has_character_flag = relation_upgrade_potential_friend }
		
		#Let the player know that the other character may accept or reject them.
		custom_tooltip = relation_upgrade.1001.a.tt
		#Send an event to the potential relation.
		scope:potential_friend = {
			trigger_event = {
				id = relation_upgrade.1002
				days = 3
			}
			hidden_effect = {
				add_character_flag = {
					flag = was_the_target_in_any_relation_upgrade_event
					years = 15
				}
			}
		}

		stress_impact = { shy = minor_stress_impact_gain }
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_energy = 0.25
				ai_sociability = 0.75
			}
			modifier = {	#Weight down for stress.
				add = -20
				has_trait = shy
			}
		}
	}
	
	#Lover upgrade: attempt to get closer to someone you fancy a bit.
	option = {
		name = relation_upgrade.1001.b
		trigger = { has_character_flag = relation_upgrade_potential_lover }

		#Let the player know that the other character may accept or reject them.
		custom_tooltip = relation_upgrade.1001.b.tt
		#Send an event to the potential relation.
		scope:potential_lover = {
			trigger_event = {
				id = relation_upgrade.1003
				days = 3
			}
			hidden_effect = {
				add_character_flag = {
					flag = was_the_target_in_any_relation_upgrade_event
					years = 15
				}
			}
		}

		stress_impact = { chaste = minor_stress_impact_gain }
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_energy = 0.25
				ai_sociability = 0.25
				ai_compassion = 0.5
			}
			modifier = {	#Weight down for stress.
				add = -20
				has_trait = chaste
			}
		}
	}
	
	#Rival upgrade: and sod this one party member in particular.
	option = {
		name = relation_upgrade.1001.c
		trigger = { has_character_flag = relation_upgrade_potential_rival }
		
		#Let the player know that the other character may accept or reject them.
		custom_tooltip = relation_upgrade.1001.c.tt
		#Send an event to the potential relation.
		scope:potential_rival = {
			trigger_event = {
				id = relation_upgrade.1004
				days = 3
			}
			hidden_effect = {
				add_character_flag = {
					flag = was_the_target_in_any_relation_upgrade_event
					years = 15
				}
			}
		}

		stress_impact = { forgiving = medium_stress_impact_gain }
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_vengefulness = 0.5
				ai_compassion = -0.5
			}
			modifier = {	#Weight down for stress.
				add = -20
				has_trait = forgiving
			}
		}
	}

	#Reveller: attempt to liven things up.
	option = {
		name = relation_upgrade.1001.d
		trigger = { has_character_flag = relation_upgrade_reveller }
		
		#Do you have this because of a trait?
		trait = lifestyle_reveler
		trait = gregarious

		#See if you can start a decent dance!
		duel = {
			skill = diplomacy
			value = very_high_skill_rating
			50 = {	#You fix the shitty party!
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = relation_upgrade.1001.d.tt_success
				send_interface_toast = {
					title = relation_upgrade.1001.d.tt_success
					left_icon = scope:terrible_party_host
					if = {
						limit = {
							can_add_hook = {
								target = scope:terrible_party_host
								type = favor_hook
							}
						}
						add_hook = {
							target = scope:terrible_party_host
							type = favor_hook
							days = default_favor_duration
						}
					}
					scope:terrible_party_host = {
						add_opinion = {
							target = root
							modifier = grateful_opinion
							opinion = 40
						}
					}
					every_in_list = {
						list = party_goers
						custom = relation_upgrade.1001.d.tt_success.list
						add_opinion = {
							target = root
							modifier = impressed_opinion
							opinion = 20
						}
					}
				}
			}
			50 = {	#How in the hell did you make things _worse_?
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = relation_upgrade.1001.d.tt_fail
				send_interface_toast = {	
					title = relation_upgrade.1001.d.tt_fail
					left_icon = scope:terrible_party_host
					scope:terrible_party_host = {
						add_opinion = {
							target = root
							modifier = insulted_opinion
							opinion = -30
						}
					}
					add_prestige = minor_prestige_loss
				}
			}
		}

		stress_impact = { shy = medium_stress_impact_gain }
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 0.25
				ai_sociability = 0.75
				ai_vengefulness = -0.25
			}
			modifier = {	#Weight down for stress.
				add = -20
				has_trait = shy
			}
		}
	}

	#Sadist/Lunatic: set fire to the building.
	option = {
		name = relation_upgrade.1001.e
		trigger = {
			has_character_flag = relation_upgrade_burn_building
			#Exclude this event if any of the potential upgrades are players.
			NOR = {
				AND = {
					exists = scope:potential_friend
					scope:potential_friend = { is_ai = no }
				}
				AND = {
					exists = scope:potential_lover
					scope:potential_lover = { is_ai = no }
				}
				AND = {
					exists = scope:potential_rival
					scope:potential_rival = { is_ai = no }
				}
			}
		}

		#Do you have this because of a trait?
		trait = lunatic_1
		trait = eccentric
		trait = sadistic
		trait = vengeful
		trait = callous
		
		#Wound the host, who grows suspicious.
		add_dread = medium_dread_gain
		scope:terrible_party_host = {
			increase_wounds_effect = { REASON = burned }
			add_opinion = {
				target = root
				modifier = suspicion_opinion
				opinion = -40
			}
			#Terrible_party_host is likely to remember this.
			hidden_effect = {
				if = {
					limit = {
						can_set_relation_potential_rival_trigger = { CHARACTER = root }
					}
					set_relation_potential_rival = root
					hidden_effect = {
						add_character_flag = {
							flag = was_the_target_in_any_relation_upgrade_event
							years = 15
						}
					}
				}
			}
		}
		#Wound your potential friend, if they exist, removing the potentiality.
		if = {
			limit = { exists = scope:potential_friend }
			scope:potential_friend = {
				increase_wounds_effect = { REASON = burned }
				add_opinion = {
					target = root
					modifier = suspicion_opinion
					opinion = -10
				}
			}
			hidden_effect = { 
				remove_relation_potential_friend = scope:potential_friend 
				add_character_flag = {
					flag = was_the_target_in_any_relation_upgrade_event
					years = 15
				}
			}
		}
		#Wound your potential lover, if they exist, removing the potentiality.
		if = {
			limit = { exists = scope:potential_lover }
			scope:potential_lover = {
				increase_wounds_effect = { REASON = burned }
				add_opinion = {
					target = root
					modifier = suspicion_opinion
					opinion = -10
				}
			}
			hidden_effect = { 
				remove_relation_potential_lover = scope:potential_lover 
				add_character_flag = {
					flag = was_the_target_in_any_relation_upgrade_event
					years = 15
				}
			}
		}
		#Confirm your rivalry, if a potential exists.
		if = {
			limit = { exists = scope:potential_rival }
			scope:potential_rival = {
				increase_wounds_effect = { REASON = burned }
				hidden_effect = {
					add_character_flag = {
						flag = was_the_target_in_any_relation_upgrade_event
						years = 15
					}
				}
			}
			progress_towards_rival_effect = {
				REASON = rival_burned_at_party
				CHARACTER = scope:potential_rival
				OPINION = -30
			}
		}
		#Wound the attendees, who remain suspicious.
		every_in_list = {
			list = party_goers
			custom = relation_upgrade.1001.e.list
			increase_wounds_effect = { REASON = burned }
			add_opinion = {
				target = root
				modifier = suspicion_opinion
				opinion = -20
			}
		}

		stress_impact = {
			base = major_stress_impact_loss

			compassionate = medium_stress_impact_gain
			forgiving = medium_stress_impact_gain
			patient = medium_stress_impact_gain
			calm = medium_stress_impact_gain

			eccentric = medium_stress_impact_loss
			impatient = medium_stress_impact_loss
			callous = medium_stress_impact_loss
			sadistic = medium_stress_impact_loss
			vengeful = medium_stress_impact_loss
			wrathful = medium_stress_impact_loss
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_energy = 0.25
				ai_vengefulness = 0.5
				ai_compassion = -0.5
				ai_honor = -0.5
				ai_rationality = -0.5
			}
			modifier = {	#Weight down for stress.
				add = -20
				has_trait = compassionate
			}
			modifier = {	#Weight down for stress.
				add = -20
				has_trait = forgiving
			}
			modifier = {	#Weight down for stress.
				add = -20
				has_trait = patient
			}
			modifier = {	#Weight down for stress.
				add = -20
				has_trait = calm
			}
		}
	}

	#Alternate: make the best of it.
	option = {
		name = relation_upgrade.1001.f
		trigger = { has_character_flag = relation_upgrade_make_best_of_it }

		#You grin and bear the drudgery.
		add_character_modifier = {
			modifier = inured_to_boredom_modifier
			years = 5
		}

		stress_impact = {
			base = medium_stress_impact_gain

			arrogant = minor_stress_impact_gain
			callous = minor_stress_impact_gain

			gregarious = minor_stress_impact_loss
			lifestyle_reveler = minor_stress_impact_loss
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 0.25
				ai_energy = 0.25
				ai_honor = 0.5
				ai_vengefulness = -0.25
			}
			modifier = {	#Weight down for stress.
				add = -10
				has_trait = arrogant
			}
			modifier = {	#Weight down for stress.
				add = -10
				has_trait = callous
			}
		}
	}

	#Alternate: try talking to someone totally new.
	option = {
		name = relation_upgrade.1001.g
		trigger = { has_character_flag = relation_upgrade_meet_new_person }

		#You strike up a conversation with someone totally different.
		random_in_list = {
			list = party_goers
			limit = { can_have_meet_new_person_trigger = yes }
			#Weight up some interesting characters from amongst your courtiers, if at all possible.
			weight = {
				base = 100
				modifier = {
					add = 100
					is_claimant = yes
				}
				modifier = {
					add = 100
					is_councillor = yes
				}
				modifier = {
					add = 50
					OR = {
						diplomacy >= high_skill_rating
						martial >= high_skill_rating
						stewardship >= high_skill_rating
						intrigue >= high_skill_rating
						learning >= high_skill_rating
						prowess >= high_skill_rating
					}
				}
			}
			set_relation_potential_friend = root
			hidden_effect = {
				add_character_flag = {
					flag = was_the_target_in_any_relation_upgrade_event
					years = 15
				}
			}
		}

		stress_impact = { shy = medium_stress_impact_gain }
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_sociability = 0.75
				ai_energy = 0.25
			}
			modifier = {	#Weight down for stress.
				add = -20
				has_trait = shy
			}
		}
	}

	#Alternate: denounce the host and leave.
	option = {
		name = relation_upgrade.1001.h
		trigger = { has_character_flag = relation_upgrade_denounce_host }
		
		#Credit where credit is due: this party suuuuuucks.
		add_prestige = minor_prestige_gain
		#The host is, understandably, humiliated.
		scope:terrible_party_host = {
			add_opinion = {
				target = root
				modifier = humiliated_opinion
				opinion = -30
			}
		}
		#Everyone was thinking it. Only you said it.
		every_in_list = {
			list = party_goers
			custom = relation_upgrade.1001.h.list
			add_opinion = {
				target = root
				modifier = impressed_opinion
				opinion = 15
			}
		}
		
		stress_impact = {
			compassionate = minor_stress_impact_gain
			humble = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_vengefulness = 0.5
				ai_boldness = 0.25
				ai_compassion = -0.25
			}
			modifier = {	#Weight down for stress.
				add = -10
				has_trait = compassionate
			}
			modifier = {	#Weight down for stress.
				add = -20
				has_trait = humble
			}
		}
	}

	#Opt out: quietly exit the party.
	option = {
		name = relation_upgrade.1001.i
		add_prestige = miniscule_prestige_loss
		stress_impact = {
			gregarious = minor_stress_impact_gain
			shy = medium_stress_impact_loss
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_sociability = -0.75
				ai_energy = -0.25
			}
			modifier = {	#Weight down for stress.
				add = -10
				has_trait = gregarious
			}
		}
	}

	after = {
		#Cleanup the flags.
		remove_character_flag = relation_upgrade_potential_friend
		remove_character_flag = relation_upgrade_potential_lover
		remove_character_flag = relation_upgrade_potential_rival
		remove_character_flag = relation_upgrade_reveller
		remove_character_flag = relation_upgrade_burn_building
		remove_character_flag = relation_upgrade_make_best_of_it
		remove_character_flag = relation_upgrade_meet_new_person
		remove_character_flag = relation_upgrade_denounce_host
	}
}

#	A potential friend is given the choice to accept your offer of friendship.
relation_upgrade.1002 = {
	type = character_event
	title = relation_upgrade.1002.t
	desc = relation_upgrade.1002.desc
	theme = party
	left_portrait = {
		character = scope:party_root
		animation = admiration
	}

	trigger = {
		#Just double check that the original sender still exists.
		scope:party_root = { is_alive = yes }
	}

	immediate = { play_music_cue = "mx_cue_meadandwine" }

	#Accept: huzzah for friendship!
	option = {
		name = relation_upgrade.1002.a

		#Friends!
		show_as_tooltip = {
			progress_towards_friend_effect = {
				CHARACTER = scope:party_root
				OPINION = 20
				REASON = friend_saved_troubled_guest_reverse
			}
		}
		#Notify the original character.
		hidden_effect = {
			scope:party_root = {
				send_interface_toast = {
					title = relation_upgrade.1002.a.tt
					left_icon = scope:potential_friend
					progress_towards_friend_effect = {
						CHARACTER = scope:potential_friend
						OPINION = 20
						REASON = friend_saved_troubled_guest_reverse
					}
				}
			}
		}

		stress_impact = { shy = minor_stress_impact_gain }
		ai_chance = { base = 100 }	#The AI should always pick this.
	}
	
	#Reject: politely but firmly.
	option = {
		name = relation_upgrade.1002.b

		#You upset the person a little, but they understand.
		show_as_tooltip = {
			remove_relation_potential_friend = scope:party_root
			scope:party_root = {
				add_opinion = {
					target = scope:potential_friend
					modifier = respect_opinion
					opinion = 10
				}
			}
		}
		#Notify the original character.
		hidden_effect = {
			scope:party_root = {
				send_interface_toast = {
					title = relation_upgrade.1002.b.tt
					left_icon = scope:potential_friend
					remove_relation_potential_friend = scope:potential_friend
				}
				#Give a little bonus opinion.
				add_opinion = {
					target = scope:potential_friend
					modifier = respect_opinion
					opinion = 10
				}
			}
		}

		stress_impact = { gregarious = minor_stress_impact_gain }
		ai_chance = { base = 0 }	#AI should never pick this option.
	}
	
	#Reject: blame them for the terrible party atmosphere.
	option = {
		name = relation_upgrade.1002.c

		#Your unexpected pettiness removes the potentiality.
		add_prestige = medium_prestige_gain
		show_as_tooltip = {
			remove_relation_potential_friend = scope:party_root
			scope:party_root = {
				add_opinion = {
					target = scope:potential_friend
					modifier = hurt_opinion
					opinion = -30
				}
			}
		}
		#Notify the original character.
		hidden_effect = {
			scope:party_root = {
				send_interface_toast = {
					title = relation_upgrade.1002.c.tt
					left_icon = scope:potential_friend
					remove_relation_potential_friend = scope:potential_friend
				}
				#And deduct some opinion.
				add_opinion = {
					target = scope:potential_friend
					modifier = hurt_opinion
					opinion = -30
				}
			}
		}

		stress_impact = { forgiving = minor_stress_impact_gain }
		ai_chance = { base = 0 }	#AI should never pick this option.
	}
}

#	A potential lover can accept your advances or not.
relation_upgrade.1003 = {
	type = character_event
	title = relation_upgrade.1003.t
	desc = relation_upgrade.1003.desc
	theme = party
	left_portrait = {
		character = scope:party_root
		animation = flirtation
	}

	trigger = {
		#Just double check that the original sender still exists.
		scope:party_root = { is_alive = yes }
	}

	immediate = { play_music_cue = "mx_cue_meadandwine" }

	#Accept: why, hello there...
	option = {
		name = relation_upgrade.1003.a

		#Relationship is confirmed.
		show_as_tooltip = {
			progress_towards_lover_effect = {
				CHARACTER = scope:party_root
				REASON = lover_party_upgrade
				OPINION = 10
			}
		}
		#Inform original character.
		hidden_effect = {
			scope:party_root = {
				send_interface_toast = {
					title = relation_upgrade.1003.a.tt
					left_icon = scope:potential_lover
					progress_towards_lover_effect = {
						CHARACTER = scope:potential_lover
						REASON = lover_party_upgrade
						OPINION = 10
					}
				}
			}
		}

		stress_impact = { chaste = minor_stress_impact_gain }
		ai_chance = { base = 100 }	#The AI should always pick this.
	}
	
	#Reject: I prefer you as a friend.
	option = {
		name = relation_upgrade.1003.b
		trigger = {
			can_set_relation_potential_friend_trigger = { CHARACTER = scope:party_root }
		}

		#Notice that the potential lover relationship becomes a potential friendship instead.
		custom_tooltip = relation_upgrade.1003.b.tt_custom_relation
		set_relation_potential_friend = scope:party_root
		#Inform original character.
		hidden_effect = {
			scope:party_root = {
				send_interface_toast = {
					title = relation_upgrade.1003.b.tt
					left_icon = scope:potential_lover
					remove_relation_potential_lover = scope:potential_lover
				}
			}
		}
		
		stress_impact = { shy = minor_stress_impact_gain }
		ai_chance = { base = 0 }	#AI should never pick this option.
	}
	
	#Reject: I remain aloof, but appealing.
	option = {
		name = relation_upgrade.1003.c
		
		#Gain positive-ish character modifier.
		add_character_modifier = {
			modifier = aloof_but_alluring_modifier
			years = 5
		}
		#Notice that the potential lover relationship will be removed.
		show_as_tooltip = {
			remove_relation_potential_lover = scope:party_root
			scope:party_root = {
				add_opinion = {
					modifier = hurt_opinion
					target = scope:potential_lover
					opinion = -10
				}
			}
		}
		#Inform original character.
		hidden_effect = {
			scope:party_root = {
				send_interface_toast = {
					title = relation_upgrade.1003.c.tt
					left_icon = scope:potential_lover
					remove_relation_potential_lover = scope:potential_lover
				}
				#And deduct some opinion.
				add_opinion = {
					modifier = hurt_opinion
					target = scope:potential_lover
					opinion = -10
				}
			}
		}

		stress_impact = { lustful = minor_stress_impact_gain }
		ai_chance = { base = 0 }	#AI should never pick this option.
	}
}

#	A potential rival is informed of your escapades.
relation_upgrade.1004 = {
	type = character_event
	title = relation_upgrade.1004.t
	desc = relation_upgrade.1004.desc
	theme = party
	left_portrait = {
		character = scope:party_root
		animation = schadenfreude
	}

	trigger = {
		#Just double check that the original sender still exists.
		scope:party_root = { is_alive = yes }
	}

	immediate = { play_music_cue = "mx_cue_meadandwine" }

	#Accept: knave!
	option = {
		name = relation_upgrade.1004.a

		#Inform that the rivalry will be confirmed.
		show_as_tooltip = {
			progress_towards_rival_effect = {
				REASON = rival_party_home_truths
				CHARACTER = scope:party_root
				OPINION = 0
			}
		}
		add_prestige = medium_prestige_gain
		#Send a toast to party_root to let them know what's up.
		hidden_effect = {
			scope:party_root = {
				send_interface_toast = {
					title = relation_upgrade.1004.a.tt
					left_icon = scope:potential_rival
					progress_towards_rival_effect = {
						REASON = rival_party_home_truths
						CHARACTER = scope:potential_rival
						OPINION = -10
					}
				}
			}
		}
		
		stress_impact = {
			compassionate = minor_stress_impact_gain
			forgiving = medium_stress_impact_gain
			
			callous = minor_stress_impact_loss
			sadistic = medium_stress_impact_loss
			vengeful = major_stress_impact_loss
		}
		ai_chance = { base = 100 }	#The AI should always pick this.
	}
	
	#Reject: this is beneath me.
	option = {
		name = relation_upgrade.1004.b

		#Inform that the rivalry will be removed.
		show_as_tooltip = { remove_relation_potential_rival = scope:party_root }
		add_prestige = medium_prestige_loss
		#Send a toast to party_root to let them know what's up.
		hidden_effect = {
			scope:party_root = {
				send_interface_toast = {
					title = relation_upgrade.1004.b.tt
					left_icon = scope:potential_rival
					remove_relation_potential_rival = scope:potential_rival
				}
			}
		}
		
		stress_impact = {
			humble = miniscule_stress_impact_loss
			compassionate = miniscule_stress_impact_loss
			forgiving = minor_stress_impact_loss

			arrogant = miniscule_stress_impact_gain
			paranoid = minor_stress_impact_gain
			vengeful = medium_stress_impact_gain
		}
		ai_chance = { base = 0 }	#AI should never pick this option.
	}
	
	#Reject: I will offer an olive branch.
	option = {
		name = relation_upgrade.1004.c
		trigger = {
			scope:party_root = { is_ai = no }
		}
		
		#Gain prestige for your magnanimity.
		add_prestige = minor_prestige_gain
		#Remove the rivalry.
		remove_relation_potential_rival = scope:party_root
		#Increment friendship, if possible.
		progress_towards_friend_effect = {
			CHARACTER = scope:party_root
			OPINION = 30
			REASON = friend_formal_offer
		}

		stress_impact = {
			base = medium_stress_impact_gain

			humble = minor_stress_impact_loss
			trusting = minor_stress_impact_loss
			compassionate = minor_stress_impact_loss
			forgiving = medium_stress_impact_loss

			arrogant = minor_stress_impact_gain
			stubborn = medium_stress_impact_gain
			paranoid = medium_stress_impact_gain
			vengeful = major_stress_impact_gain
		}
		ai_chance = { base = 0 }	#AI should never pick this option.
	}
}



################################################
# Character is very passionate about something #
# lover, soulmate								#
# by Mathilda Bjarnehed							#
################################################


scripted_trigger relation_upgrade_2001_potential_lover_trigger = {
	upgrade_ready_potential_lover_to_lover_trigger = { CHARACTER = root }
	is_available = yes
	NOT = { has_character_flag = was_the_target_in_any_relation_upgrade_event }
}

scripted_trigger relation_upgrade_2001_lover_trigger = {
	upgrade_ready_lover_to_soulmate_trigger = { CHARACTER = root }
	NOT = { has_relation_soulmate = root }
	is_available = yes
	NOT = { has_character_flag = was_the_target_in_any_relation_upgrade_event }
}

scripted_trigger relation_upgrade_2001_random_list_trigger = {
	NOR = {
		relation_upgrade_2001_lover_trigger_skill_topic_trigger = { SKILL = diplomacy }
		relation_upgrade_2001_lover_trigger_skill_topic_trigger = { SKILL = martial }
		prowess >= high_skill_rating
		relation_upgrade_2001_lover_trigger_skill_topic_trigger = { SKILL = stewardship }
		relation_upgrade_2001_lover_trigger_skill_topic_trigger = { SKILL = intrigue }
		relation_upgrade_2001_lover_trigger_skill_topic_trigger = { SKILL = learning }
		has_trait = lifestyle_hunter
		has_trait = gluttonous
		has_trait = comfort_eater
	}
}

scripted_trigger relation_upgrade_2001_lover_trigger_skill_topic_trigger = {
	OR = {
		has_education_$SKILL$_trigger = yes
		has_lifestyle = $SKILL$_lifestyle
		$SKILL$ >= decent_skill_rating
	}
}

scripted_effect relation_upgrade_2001_listen_and_learn_effect = {
	if = {
		limit = { scope:listen_and_learn = flag:diplomacy }
		add_diplomacy_lifestyle_xp = massive_lifestyle_xp
	}
	else_if = {
		limit = { scope:listen_and_learn = flag:martial }
		add_martial_lifestyle_xp = massive_lifestyle_xp
	}
	else_if = {
		limit = { scope:listen_and_learn = flag:stewardship }
		add_stewardship_lifestyle_xp = massive_lifestyle_xp
	}
	else_if = {
		limit = { scope:listen_and_learn = flag:intrigue }
		add_intrigue_lifestyle_xp = massive_lifestyle_xp
	}
	else_if = {
		limit = { scope:listen_and_learn = flag:learning }
		add_learning_lifestyle_xp = massive_lifestyle_xp
	}
	else_if = {
		limit = { scope:listen_and_learn = flag:hunting }
		add_trait_xp = {
			trait = lifestyle_hunter
			track = hunter
			value = major_trait_xp
		}
	}
	else_if = {
		limit = { scope:listen_and_learn = flag:cooking }
		add_character_modifier = {
			modifier = amateur_cook_modifier
		}
	}
}

relation_upgrade.2001 = { #by Mathilda Bjarnehed
	type = character_event
	title = relation_upgrade.2001.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { has_relation_potential_lover = scope:lover_1 }
				desc = {
					first_valid = {
						triggered_desc = {
							trigger = { location = scope:lover_1_location }
							desc = relation_upgrade.2001.lover_dinner.desc
						}
						desc = relation_upgrade.2001.lover_party.desc
					}
					desc = relation_upgrade.2001.lover.desc
				}
			}
			desc = relation_upgrade.2001.soulmate.desc
		}
		first_valid = {
			triggered_desc = {
				trigger = { scope:relates_to_subject = yes }
				desc = relation_upgrade.2001.relates.desc
			}
			desc = relation_upgrade.2001.does_not_relate.desc
		}
	} 	
	theme = love
	override_icon = {
		trigger = { has_relation_potential_lover = scope:lover_1 }
		reference = "gfx/interface/icons/event_types/type_seduction.dds"
	}
	override_background = {
		trigger = { has_relation_potential_lover = scope:lover_1 }
		reference = feast
	}
	left_portrait = {
		character = scope:lover_1
		animation = happiness
	}
	
	trigger = {
		is_landed = yes
		is_available_adult = yes
		OR = {
			any_relation = {
				type = potential_lover
				relation_upgrade_2001_potential_lover_trigger = yes
				exists = location
				save_temporary_scope_as = relation_upgrade_check
			}
			any_relation = {
				type = lover
				relation_upgrade_2001_lover_trigger = yes
				exists = location
				save_temporary_scope_as = relation_upgrade_check
			}
		}
		NOT = { has_character_flag = had_any_relation_upgrade_event }
		OR = {
			NOT = { exists = var:had_relation_upgrade_2001 }
			AND = {
				exists = var:had_relation_upgrade_2001
				NOT = { var:had_relation_upgrade_2001 = scope:relation_upgrade_check }
			}
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = -0.5
			exists = var:had_relation_upgrade_2001
		}
	}

	immediate = {
		add_character_flag = {
			flag = had_any_relation_upgrade_event
			years = 15
		}
		# Prio: lover -> soulmate
		random_relation = {
			type = lover
			limit = {
				relation_upgrade_2001_lover_trigger = yes
				exists = root.var:had_relation_upgrade_2001
				NOT = { this = root.var:had_relation_upgrade_2001 }
			}
			alternative_limit = {
				relation_upgrade_2001_lover_trigger = yes
			}
			weight = {
				base = 1
				opinion_modifier = {
					opinion_target = root
				}
				opinion_modifier = {
					who = root
					opinion_target = this
				}
				compatibility_modifier = {
					compatibility_target = root
				}
				ai_value_modifier = {
					ai_honor = 0.5
					ai_compassion = 0.5
				}
			}
			save_scope_as = lover_1
			set_variable = {
				name = had_relation_upgrade_2001
				value = scope:lover_1
				years = 20
			}
		}

		if = {
			limit = {
				NOT = { exists = scope:lover_1 }
			}
			# No lover? potential lover -> lover
			random_relation = {
				type = potential_lover
				limit = {
					relation_upgrade_2001_potential_lover_trigger = yes
					exists = root.var:had_relation_upgrade_2001
					NOT = { this = root.var:had_relation_upgrade_2001 }
				}
				alternative_limit = {
					relation_upgrade_2001_potential_lover_trigger = yes
				}
				weight = {
					base = 1
					opinion_modifier = {
						opinion_target = root
					}
					opinion_modifier = {
						who = root
						opinion_target = this
					}
					compatibility_modifier = {
						compatibility_target = root
					}
					ai_value_modifier = {
						ai_honor = 0.5
						ai_compassion = 0.5
					}
				}
				save_scope_as = lover_1
				set_variable = {
					name = had_relation_upgrade_2001
					value = scope:lover_1
					years = 20
				}
			}
		}

		scope:lover_1 = {
			if = {
				limit = { exists = scope:host }
				host = { capital_province = { save_scope_as = lover_1_location } }
			}
			else = { location = { save_scope_as = lover_1_location } }
		}

		save_scope_as = lover_2

		# What are they talking about?
		scope:lover_1 = {
			random_list = {
				# Something diplomacy-y
				5 = {
					trigger = {
						or = {
							relation_upgrade_2001_lover_trigger_skill_topic_trigger = { SKILL = diplomacy }
							relation_upgrade_2001_random_list_trigger = yes
						}
					}
					modifier = {
						add = { value = this.diplomacy }
					}
					modifier = {
						root = { has_lifestyle = diplomacy_lifestyle }
						add = 10
					}

					save_scope_value_as = {
						name = listen_and_learn
						value = flag:diplomacy
					}

					#Pick the exact subject
					random_list = {
						1 = { set_variable = { name = subject_of_interest days = 30 value = flag:court_politics } }
						1 = { set_variable = { name = subject_of_interest days = 30 value = flag:court_alliances } }
					}

					# Can you relate?
					if = {
						limit = { root = { relation_upgrade_2001_lover_trigger_skill_topic_trigger = { SKILL = diplomacy } } }
						save_scope_value_as = {
							name = relates_to_subject
							value = yes
						}
					}
				}
				# Something martial-y
				5 = {
					trigger = {
						OR = {
							relation_upgrade_2001_lover_trigger_skill_topic_trigger = { SKILL = martial }
							prowess >= high_skill_rating
							relation_upgrade_2001_random_list_trigger = yes
						}
					}
					modifier = {
						add = { value = this.martial }
					}
					modifier = {
						root = { has_lifestyle = martial_lifestyle }
						add = 10
					}

					save_scope_value_as = {
						name = listen_and_learn
						value = flag:martial
					}

					#Pick the exact subject
					random_list = {
						1 = { set_variable = { name = subject_of_interest days = 30 value = flag:education_conversation_subject_martial_2 } }
						1 = { set_variable = { name = subject_of_interest days = 30 value = flag:troop_compositions } }
						1 = { set_variable = { name = subject_of_interest days = 30 value = flag:military_strategies } }
						1 = {
							trigger = {
								OR = {
									prowess >= high_skill_rating
									has_focus_or_focus_trait_trigger = { FOCUS = martial_chivalry_focus }
								}
							}
							set_variable = { name = subject_of_interest days = 30 value = flag:sword_practise }
						}
					}


					# Can you relate?
					if = {
						limit = {
							root = {
								OR = {
									relation_upgrade_2001_lover_trigger_skill_topic_trigger = { SKILL = martial }
									prowess >= high_skill_rating
								}
							}
						}
						save_scope_value_as = {
							name = relates_to_subject
							value = yes
						}
					}
				}
				# Something stewardship-y
				5 = {
					trigger = {
						OR = {
							relation_upgrade_2001_lover_trigger_skill_topic_trigger = { SKILL = stewardship }
							relation_upgrade_2001_random_list_trigger = yes
						}
					}
					modifier = {
						add = { value = this.stewardship }
					}
					modifier = {
						root = { has_lifestyle = stewardship_lifestyle }
						add = 10
					}

					save_scope_value_as = {
						name = listen_and_learn
						value = flag:stewardship
					}

					#Pick the exact subject
					random_list = {
						1 = { set_variable = { name = subject_of_interest days = 30 value = flag:trade_routes } }
						1 = { set_variable = { name = subject_of_interest days = 30 value = flag:tax_levels } }
						1 = { set_variable = { name = subject_of_interest days = 30 value = flag:herhis_investments } }
						1 = {
							trigger = {
								OR = {
									has_trait = just
									has_focus = stewardship_domain_focus
								}
							}
							set_variable = { name = subject_of_interest days = 30 value = flag:lawmaking }
						}
					}

					# Can you relate?
					if = {
						limit = { root = { relation_upgrade_2001_lover_trigger_skill_topic_trigger = { SKILL = stewardship } } }
						save_scope_value_as = {
							name = relates_to_subject
							value = yes
						}
					}
				}
				# Something intrigue-y
				5 = {
					trigger = {
						OR = {
							relation_upgrade_2001_lover_trigger_skill_topic_trigger = { SKILL = intrigue }
							relation_upgrade_2001_random_list_trigger = yes
						}
					}
					modifier = {
						add = { value = this.intrigue }
					}
					modifier = {
						root = { has_lifestyle = intrigue_lifestyle }
						add = 10
					}

					save_scope_value_as = {
						name = listen_and_learn
						value = flag:intrigue
					}

					#Pick the exact subject
					random_list = {
						1 = {
							trigger = {
								OR = {
									has_focus = intrigue_skulduggery_focus
									intrigue >= high_skill_rating
								}
							}
							set_variable = { name = subject_of_interest days = 30 value = flag:poisons }
						}
						1 = { set_variable = { name = subject_of_interest days = 30 value = flag:the_rumors_at_court } }
					}

					# Can you relate?
					if = {
						limit = { root = { relation_upgrade_2001_lover_trigger_skill_topic_trigger = { SKILL = intrigue } } }
						save_scope_value_as = {
							name = relates_to_subject
							value = yes
						}
					}
				}
				# Something learning-y
				5 = {
					trigger = {
						OR = {
							relation_upgrade_2001_lover_trigger_skill_topic_trigger = { SKILL = learning }
							relation_upgrade_2001_random_list_trigger = yes
						}
					}
					modifier = {
						add = { value = this.learning }
					}
					modifier = {
						root = { has_lifestyle = learning_lifestyle }
						add = 10
					}

					save_scope_value_as = {
						name = listen_and_learn
						value = flag:learning
					}

					#Pick the exact subject
					random_list = {
						1 = {
							trigger = {
								OR = {
									ai_zeal >= 0
									has_focus = learning_theology_focus
								}
							}
							set_variable = { name = subject_of_interest days = 30 value = flag:education_conversation_subject_learning_1 }
						}
						1 = { set_variable = { name = subject_of_interest days = 30 value = flag:herhis_tome_collection } }
					}

					# Can you relate?
					if = {
						limit = { root = { relation_upgrade_2001_lover_trigger_skill_topic_trigger = { SKILL = learning } } }
						save_scope_value_as = {
							name = relates_to_subject
							value = yes
						}
					}
				}
				# Hunting
				20 = {
					trigger = {
						OR = {
							has_trait = lifestyle_hunter
							relation_upgrade_2001_random_list_trigger = yes
						}
					}

					save_scope_value_as = {
						name = listen_and_learn
						value = flag:hunting
					}

					set_variable = { name = subject_of_interest days = 30 value = flag:herhis_best_hunting_kills }

					# Can you relate?
					if = {
						limit = { has_trait = lifestyle_hunter }
						save_scope_value_as = {
							name = relates_to_subject
							value = yes
						}
					}
				}
				# Food
				20 = {
					trigger = {
						OR = {
							has_trait = gluttonous
							has_trait = comfort_eater
							relation_upgrade_2001_random_list_trigger = yes
						}
					}

					save_scope_value_as = {
						name = listen_and_learn
						value = flag:cooking
					}

					set_variable = { name = subject_of_interest days = 30 value = flag:herhis_favorite_food }

					# Can you relate?
					if = {
						limit = {
							root = {
								has_trait = gluttonous
								has_trait = comfort_eater
							}
						}
						save_scope_value_as = {
							name = relates_to_subject
							value = yes
						}
					}
				}
			}
		}

		if = {
			limit = { NOT = { exists = scope:relates_to_subject } }
			save_scope_value_as = {
				name = relates_to_subject
				value = no
			}
		}
	}

	# Become lovers!
	option = {
		trigger = { has_relation_potential_lover = scope:lover_1 }
		name = relation_upgrade.2001.a

		show_as_tooltip = {
			random_list = {
				1 = {
					desc = relation_upgrade.2001.a.success
					show_chance = no
					set_relation_lover = { reason = lover_dinner_love target = scope:lover_1 province = scope:lover_1_location }
				}
				1 = {
					desc = relation_upgrade.2001.a.failure
					show_chance = no
					relation_upgrade_2001_listen_and_learn_effect = yes
				}
			}
		}

		scope:lover_1 = { 
			trigger_event = relation_upgrade.2002 
			hidden_effect = {
				add_character_flag = {
					flag = was_the_target_in_any_relation_upgrade_event
					years = 15
				}
			}
		}

		stress_impact = {
			fickle = medium_stress_impact_gain
			chaste = medium_stress_impact_gain
		}

		ai_chance = {
			base = 50

			opinion_modifier = {
				opinion_target = scope:lover_1
			}
			ai_value_modifier = {
				ai_compassion = 1
				ai_sociability = 1
				min = -30
			}
			modifier = {
				OR = {
					has_trait = fickle
					has_trait = chaste
				}
				add = -40
			}
		}
	}

	# Become soulmates!
	option = {
		trigger = { has_relation_lover = scope:lover_1 }
		name = relation_upgrade.2001.b

		show_as_tooltip = {
			random_list = {
				1 = {
					desc = relation_upgrade.2001.b.success
					show_chance = no
					set_relation_soulmate = { reason = soulmate_passionate_interests copy_reason = lover target = scope:lover_1 province = scope:lover_1_location }
				}
				1 = {
					desc = relation_upgrade.2001.b.failure
					show_chance = no
					relation_upgrade_2001_listen_and_learn_effect = yes
				}
			}
		}

		scope:lover_1 = { 
			trigger_event = relation_upgrade.2002 
			hidden_effect = {
				add_character_flag = {
					flag = was_the_target_in_any_relation_upgrade_event
					years = 15
				}
			}
		}

		stress_impact = {
			fickle = medium_stress_impact_gain
		}

		ai_chance = {
			base = 100

			opinion_modifier = {
				opinion_target = scope:lover_1
			}
			ai_value_modifier = {
				ai_compassion = 1
				ai_sociability = 1
				min = -30
			}
			modifier = {
				has_trait = fickle
				add = -40
			}
		}
	}
	
	# Just listen and learn
	option = {
		name = relation_upgrade.2001.c

		relation_upgrade_2001_listen_and_learn_effect = yes

		hidden_effect = { # You don't care about this person obviously
			if = {
				limit = { has_relation_potential_lover = scope:lover_1 }
				remove_relation_potential_lover = scope:lover_1
				add_character_flag = {
					flag = was_the_target_in_any_relation_upgrade_event
					years = 15
				}
			}
		}

		ai_chance = {
			base = 20
		}
	}
}


# (Potential) lover gets to answers, do they want to upgrade?
relation_upgrade.2002 = { #by Mathilda Bjarnehed
	type = character_event
	title = relation_upgrade.2001.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { has_relation_potential_lover = scope:lover_1 }
				desc = {
					first_valid = {
						triggered_desc = {
							trigger = { scope:lover_2.location = scope:lover_1_location }
							desc = relation_upgrade.2002.lover_dinner.desc
						}
						desc = relation_upgrade.2002.lover_party.desc
					}
					desc = relation_upgrade.2002.lover.desc
				}
			}
			desc = relation_upgrade.2002.soulmate.desc
		}
	} 	
	theme = love
	override_icon = {
		trigger = { has_relation_potential_lover = scope:lover_2 }
		reference = "gfx/interface/icons/event_types/type_seduction.dds"
	}
	override_background = {
		trigger = { has_relation_potential_lover = scope:lover_2 }
		reference = feast
	}
	left_portrait = {
		character = scope:lover_2
		animation = admiration
	}

	# Yes lovers!
	option = {
		trigger = { has_relation_potential_lover = scope:lover_2 }
		name = relation_upgrade.2001.a
	
	  	show_as_tooltip = { set_relation_lover = scope:lover_2 }

	  	scope:lover_2 = { trigger_event = relation_upgrade.2003 }

	  	stress_impact = {
			fickle = medium_stress_impact_gain
			chaste = medium_stress_impact_gain
		}

	  	ai_chance = {
			base = 50

			opinion_modifier = {
				opinion_target = scope:lover_2
			}
			ai_value_modifier = {
				ai_compassion = 1
				ai_sociability = 0.5
				min = -30
			}
			modifier = {
				OR = {
					has_trait = fickle
					has_trait = chaste
				}
				add = -40
			}
		}
	}

	# Yes soulmates!
	option = {
		trigger = { has_relation_lover = scope:lover_2 }
		name = relation_upgrade.2001.b
	
	  	show_as_tooltip = { set_relation_soulmate = { reason = soulmate_passionate_interests copy_reason = lover target = scope:lover_2 province = scope:lover_1_location } }

	  	scope:lover_2 = { trigger_event = relation_upgrade.2003 }

	  	stress_impact = {
			fickle = medium_stress_impact_gain
		}

	  	ai_chance = {
			base = 100

			opinion_modifier = {
				opinion_target = scope:lover_2
			}
			ai_value_modifier = {
				ai_compassion = 1
				ai_sociability = 0.5
				min = -30
			}
			modifier = {
				has_trait = fickle
				add = -40
			}
		}
	}
	
	# No thank you
	option = {
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = { has_relation_potential_lover = scope:lover_2 }
						desc = relation_upgrade.2002.c.lover
					}
					desc = relation_upgrade.2002.c.soulmate
				}
			}
		}		
		
		relation_upgrade_2001_listen_and_learn_effect = yes

		scope:lover_2 = { trigger_event = relation_upgrade.2004 }

		hidden_effect = { # You don't care about this person obviously
			if = {
				limit = { has_relation_potential_lover = scope:lover_2 }
				remove_relation_potential_lover = scope:lover_2
			}
		}

		ai_chance = {
			base = 20
		}
	}
}

# They said yes!
relation_upgrade.2003 = { #by Mathilda Bjarnehed
	type = character_event
	title = relation_upgrade.2001.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { has_relation_potential_lover = scope:lover_1 }
				desc = relation_upgrade.2003.lover.desc
			}
			desc = {
				desc = relation_upgrade.2003.soulmate_start.desc
				desc = relation_upgrade.2003.soulmate_end.desc
			}
		}
	}
	theme = love
	override_icon = {
		trigger = { has_relation_potential_lover = scope:lover_1 }
		reference = "gfx/interface/icons/event_types/type_seduction.dds"
	}
	override_background = {
		trigger = { has_relation_potential_lover = scope:lover_1 }
		reference = feast
	}
	left_portrait = {
		character = scope:lover_1
		triggered_animation = {
			trigger = { has_relation_potential_lover = scope:lover_1 }
			animation = flirtation
		}
		animation = love
	}

	trigger = { # In case something happened in MP
		OR = {
			AND = {
				has_relation_potential_lover = scope:lover_1
				can_set_relation_lover_trigger = { CHARACTER = scope:lover_1 }
			}
			AND = {
				has_relation_lover = scope:lover_1
				can_set_relation_soulmate_trigger = { CHARACTER = scope:lover_1 }
			}
		}
	}

	immediate = {
		top_liege = {
			primary_title = { save_scope_as = realm }
		}
	}

	# Become lovers!
	option = {
		trigger = { has_relation_potential_lover = scope:lover_1 }
		name = relation_upgrade.2003.a

		set_relation_lover = { reason = lover_dinner_love target = scope:lover_1 province = scope:lover_1_location }
	}

	# Become soulmates!
	option = {
		trigger = { has_relation_lover = scope:lover_1 }
		name = relation_upgrade.2003.b

		set_relation_soulmate = { reason = soulmate_passionate_interests copy_reason = lover target = scope:lover_1 province = scope:lover_1_location }
	}
}

# They said no...
relation_upgrade.2004 = { #by Mathilda Bjarnehed
	type = character_event
	title = relation_upgrade.2001.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { has_relation_lover = scope:lover_1 }
				desc = {
					desc = relation_upgrade.2003.soulmate_start.desc
					desc = relation_upgrade.2004.soulmate_end.desc
				}
			}
			desc = relation_upgrade.2004.lover.desc
		}
	}
	theme = love
	override_icon = {
		trigger = { has_relation_potential_lover = scope:lover_1 }
		reference = "gfx/interface/icons/event_types/type_seduction.dds"
	}
	override_background = {
		trigger = { has_relation_potential_lover = scope:lover_1 }
		reference = feast
	}
	left_portrait = {
		character = scope:lover_1
		animation = happiness
	}

	option = {
		name = relation_upgrade.2004.a

		relation_upgrade_2001_listen_and_learn_effect = yes
	}
}





#####################################################
# Throw diseased corpses at your (potential) rival 	#
# rival, nemesis									#
# by Linnéa Thimrén									#
#####################################################

scripted_trigger relation_upgrade_2101_rival_trigger = {
	upgrade_ready_potential_rival_to_rival_trigger = { CHARACTER = root }
	OR = {
		reverse_opinion = { # yes, even if the player's opinion is hidden
			target = root
			value <= low_negative_opinion
		}
		opinion = {
			target = root
			value <= low_negative_opinion
		}
	}
}

scripted_trigger relation_upgrade_2101_nemesis_trigger = {
	upgrade_ready_rival_to_nemesis_trigger = { CHARACTER = root }
	OR = {
		reverse_opinion = { # yes, even if the player's opinion is hidden
			target = root
			value <= low_negative_opinion
		}
		opinion = {
			target = root
			value <= low_negative_opinion
		}
	}
}

relation_upgrade.2101 = {
	type = character_event
	title = relation_upgrade.2101.t
	desc = {
		desc = {
			desc = relation_upgrade.2101.desc_opening
			first_valid = {
				triggered_desc = {
					trigger = {
						exists = scope:physician
					}
					desc = relation_upgrade.2101.desc_opening_physician
				}
				desc = relation_upgrade.2101.desc_opening_other
			}
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:peasant = { has_trait = bubonic_plague }
				}
				desc = relation_upgrade.2101.desc_bubonic_plague
			}
			desc = relation_upgrade.2101.desc_smallpox
		}
		desc = relation_upgrade.2101.desc_ending
	}
	theme = rival_relation
	override_background = {
		reference = physicians_study
	}
	left_portrait = scope:rival
	right_portrait = scope:peasant
	lower_right_portrait = scope:physician
	
	trigger = {
		is_landed = yes
		is_available_adult = yes
		exists = capital_province
		OR = {
			any_relation = {
				type = potential_rival
				relation_upgrade_2101_rival_trigger = yes
				exists = capital_province
				NOT = { has_character_flag = was_the_target_in_any_relation_upgrade_event }
				save_temporary_scope_as = relation_upgrade_check
			}
			any_relation = {
				type = rival
				relation_upgrade_2101_nemesis_trigger = yes
				exists = capital_province
				NOT = { has_character_flag = was_the_target_in_any_relation_upgrade_event }
				save_temporary_scope_as = relation_upgrade_check
			}
		}
		NOT = { has_character_flag = had_any_relation_upgrade_event }
		OR = {
			NOT = { exists = var:had_relation_upgrade_2101 }
			AND = {
				exists = var:had_relation_upgrade_2101
				NOT = { var:had_relation_upgrade_2101 = scope:relation_upgrade_check }
			}
		}
	}

	weight_multiplier = {
		base = 0.5
		modifier = {
			add = -0.3
			exists = var:had_relation_upgrade_2101
		}
	}

	immediate = {
		add_character_flag = {
			flag = had_any_relation_upgrade_event
			years = 15
		}
		save_scope_as = corpse_rival
		capital_province = { barony = { save_scope_as = capital } }
		save_court_physician_as_effect = { SCOPE_NAME = physician }
		if = {
			limit = {
				any_relation = {
					type = rival
					relation_upgrade_2101_nemesis_trigger = yes
					exists = capital_province
				}
			}
			random_relation = {
				type = rival
				limit = {
					exists = root.var:had_relation_upgrade_2101
					NOT = { this = root.var:had_relation_upgrade_2101 }
					relation_upgrade_2101_nemesis_trigger = yes
					exists = capital_province
				}
				alternative_limit = {
					relation_upgrade_2101_nemesis_trigger = yes
					exists = capital_province
				}
				save_scope_as = rival

				set_variable = {
					name = had_relation_upgrade_2101
					value = scope:rival
					years = 20
				}
				capital_province = { barony = { save_scope_as = rival_capital } }
			}
		}
		else = {
			random_relation = {
				type = potential_rival
				limit = {
					exists = root.var:had_relation_upgrade_2101
					NOT = { this = root.var:had_relation_upgrade_2101 }
					relation_upgrade_2101_rival_trigger = yes
					exists = capital_province
				}
				alternative_limit = {
					relation_upgrade_2101_rival_trigger = yes
					exists = capital_province
				}
				save_scope_as = rival
				set_variable = {
					name = had_relation_upgrade_2101
					value = scope:rival
					years = 20
				}
				capital_province = { barony = { save_scope_as = rival_capital } }
			}
		}
		hidden_effect = { #To create, and kill, a peasant
			#Is bubonic plague in the realm?
			if = {
				limit = {
					liege = {
						any_realm_county = {
							any_county_province_epidemic = {
								epidemic_type.epidemic_trait = trait:bubonic_plague
							}
						}
					}
				}
				liege = {
					create_character = {
						template = servant_character
						dynasty = none
						location = root.capital_province
						gender_female_chance = 50
						trait = bubonic_plague
						save_scope_as = peasant
					}
					scope:peasant = {
						death = {
							death_reason = death_bubonic_plague
						}
					}
				}
			}
			#Else - go with smallpox!
			else = {
				create_character = {
					template = servant_character
					dynasty = none
					location = root.capital_province
					gender_female_chance = 50
					trait = smallpox
					save_scope_as = peasant
				}
				scope:peasant = {
					death = {
						death_reason = death_smallpox
					}
				}
			}
		}

		#To save possible courtier to maybe gain the disease
		hidden_effect = {
			if = {
				limit = {
					any_courtier = {
						NOR = {
							has_trait = bubonic_plague
							has_trait = smallpox
						}
					}
				}
				random_courtier = {
					limit = {
						NOR = {
							has_trait = bubonic_plague
							has_trait = smallpox
						}
					}
					save_scope_as = your_courtier_to_infect
				}
			}
		}
	}

	option = { #Launch the corpse!
		name = relation_upgrade.2101.a
		custom_tooltip = relation_upgrade.2101.a_tt
		scope:rival = {
			if = {
				limit = {
					OR = {
						is_courtier_of = root
						is_foreign_court_or_pool_guest_of = root
						any_vassal = {
							this = root
						}
					}
				}
				add_opinion = {
					target = root
					modifier = treachery_opinion
					opinion = -40
				}
			}
			else = {
				add_opinion = {
					target = root
					modifier = hate_opinion
					opinion = -40
				}
			}
			hidden_effect = {
				add_character_flag = {
					flag = was_the_target_in_any_relation_upgrade_event
					years = 15
				}
			}
		}
		show_as_tooltip = { #Actually applied in the response event
			if = {
				limit = {
					scope:rival = {
						is_ai = yes #ai will always say yes to the relationship
					}
				}
				if = {
					limit = {
						has_relation_potential_rival = scope:rival
						can_set_relation_rival_trigger = { CHARACTER = scope:rival }
					}
					set_relation_rival = scope:rival #No reason given since this is show_as_tooltip
				}
				else = {
					set_relation_nemesis = scope:rival #No reason given since this is show_as_tooltip
				}
			}
			else = { #players get a choice
				if = {
					limit = {
						has_relation_potential_rival = scope:rival
						can_set_relation_rival_trigger = { CHARACTER = scope:rival }
					}
					custom_tooltip = relation_upgrade.2101.a_tt_rival
				}
				else = {
					custom_tooltip = relation_upgrade.2101.a_tt_nemesis
				}
			}
		}
		scope:rival = {
			trigger_event = {
				id = relation_upgrade.2102
				days = 3
			}
		}
		stress_impact = {
			forgiving = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
			calm = medium_stress_impact_gain
			sadistic = major_stress_impact_loss
			vengeful = major_stress_impact_loss
		}
	}

	option = { #I'll study the corpse instead
		name = relation_upgrade.2101.b
		add_character_modifier = {
			modifier = studying_corpses_modifier
			years = 5
		}
		if = {
			limit = {
				exists = scope:your_courtier_to_infect
			}
			random = {
				chance = 10
				custom_tooltip = relation_upgrade.2101.b_tt
				hidden_effect = {
					if = {
						limit = {
							scope:peasant = { has_trait = bubonic_plague }
						}
						scope:your_courtier_to_infect = {
							contract_disease_effect = { DISEASE = bubonic_plague TREATMENT_EVENT = yes }
						}
					}
					else = {
						scope:your_courtier_to_infect = {
							contract_disease_effect = { DISEASE = smallpox TREATMENT_EVENT = yes }
						}
					}
				}
			}
		}
		else = {
			random = {
				chance = 10
				send_interface_toast = {
					title = relation_upgrade.2101.b_tt_2
					left_icon = root
					scope:capital.county = {
						add_county_modifier = {
							modifier = disease_spreading_modifier
							years = 5
						}
					}
				}
			}
		}
		stress_impact = {
			impatient = minor_stress_impact_gain
			vengeful = major_stress_impact_gain
			arrogant = minor_stress_impact_gain
			wrathful = major_stress_impact_gain
			sadistic = major_stress_impact_gain
		}
	}

	option = { #Bury them
		name = relation_upgrade.2101.c
		add_piety = minor_piety_gain

		stress_impact = {
			compassionate = medium_stress_impact_loss
			vengeful = minor_stress_impact_gain
			wrathful = minor_stress_impact_gain
			sadistic = minor_stress_impact_gain
		}
	}
}


#Event for the (potential) rival
relation_upgrade.2102 = {
	type = character_event
	title = relation_upgrade.2101.t
	desc = {
		desc = relation_upgrade.2102.desc_opening
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:peasant = { has_trait = bubonic_plague }
				}
				desc = relation_upgrade.2102.desc_bubonic_plague
			}
			desc = relation_upgrade.2102.desc_smallpox
		}
		desc = relation_upgrade.2102.desc_ending
	}
	theme = rival_relation
	override_background = {
		reference = physicians_study
	}
	left_portrait = scope:corpse_rival
	right_portrait = scope:peasant

	immediate = {
		#To save possible courtier to maybe gain the disease
		hidden_effect = {
			if = {
				limit = {
					any_courtier = {
						NOR = {
							has_trait = bubonic_plague
							has_trait = smallpox
						}
					}
				}
				random_courtier = {
					limit = {
						NOR = {
							has_trait = bubonic_plague
							has_trait = smallpox
						}
					}
					save_scope_as = their_courtier_to_infect
				}
			}
		}
	}

	option = { #Go for rivalry
		name = relation_upgrade.2102.a

		scope:corpse_rival = {
			add_opinion = {
				target = root
				modifier = hate_opinion
				opinion = -20
			}
			hidden_effect = {
				add_character_flag = {
					flag = was_the_target_in_any_relation_upgrade_event
					years = 15
				}
			}
		}

		if = {
			limit = {
				has_relation_potential_rival = scope:corpse_rival
				can_set_relation_rival_trigger = { CHARACTER = scope:corpse_rival }
			}
			set_relation_rival = {
				target = scope:corpse_rival
				reason = rival_catapulted_corpse
			}
		}
		else = {
			set_relation_nemesis = {
				target = scope:corpse_rival
				copy_reason = rival
				reason = nemesis_catapulted_corpses
			}
		}

		if = {
			limit = {
				exists = scope:their_courtier_to_infect
			}
			random = {
				chance = 40
				custom_tooltip = relation_upgrade.2101.b_tt
				hidden_effect = {
					scope:corpse_rival = {
						send_interface_toast = { #To send update to original rival
							title = relation_upgrade.2102.tt
							left_icon = scope:their_courtier_to_infect
							scope:their_courtier_to_infect = {
								if = {
									limit = {
										scope:peasant = { has_trait = bubonic_plague }
									}
									contract_disease_effect = { DISEASE = bubonic_plague TREATMENT_EVENT = yes }
								}
								else = {
									contract_disease_effect = { DISEASE = smallpox TREATMENT_EVENT = yes }
								}
							}
						}
					}
				}
			}
		}
		else = {
			random = {
				chance = 40
				send_interface_toast = {
					title = relation_upgrade.2101.b_tt_2
					left_icon = root
					scope:rival_capital.county = {
						add_county_modifier = {
							modifier = disease_spreading_modifier
							years = 5
						}
					}
				}
				hidden_effect = { #To update original rival
					scope:corpse_rival = {
						send_interface_toast = {
							title = relation_upgrade.2101.b_tt_2
							left_icon = scope:rival
							show_as_tooltip = {
								scope:rival_capital.county = {
									add_county_modifier = {
										modifier = disease_spreading_modifier
										years = 5
									}
								}
							}
						}
					}
				}
			}
		}

		ai_chance = { #ai always goes for relationship
			base = 100
		}
		stress_impact = {
			sadistic = medium_stress_impact_loss
			vengeful = medium_stress_impact_loss
			forgiving = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
			calm = minor_stress_impact_gain
		}
	}

	option = { #Study the corpse
		name = relation_upgrade.2102.b

		add_character_modifier = {
			modifier = studying_corpses_modifier
			years = 5
		}
		if = {
			limit = {
				exists = scope:their_courtier_to_infect
			}
			random = {
				chance = 50
				custom_tooltip = relation_upgrade.2101.b_tt
				hidden_effect = {
					scope:corpse_rival = {
						send_interface_toast = { #To send update to original rival
							title = relation_upgrade.2102.tt
							left_icon = scope:their_courtier_to_infect
							scope:their_courtier_to_infect = {
								if = {
									limit = {
										scope:peasant = { has_trait = bubonic_plague }
									}
									contract_disease_effect = { DISEASE = bubonic_plague TREATMENT_EVENT = yes }
								}
								else = {
									contract_disease_effect = { DISEASE = smallpox TREATMENT_EVENT = yes }
								}
							}
						}
					}
				}
			}
		}
		else = {
			random = {
				chance = 50
				send_interface_toast = {
					title = relation_upgrade.2101.b_tt_2
					left_icon = root
					scope:rival_capital.county = {
						add_county_modifier = {
							modifier = disease_spreading_modifier
							years = 5
						}
					}
				}
				hidden_effect = { #To update original rival
					scope:corpse_rival = {
						send_interface_toast = {
							title = relation_upgrade.2101.b_tt_2
							left_icon = scope:rival
							show_as_tooltip = {
								scope:rival_capital.county = {
									add_county_modifier = {
										modifier = disease_spreading_modifier
										years = 5
									}
								}
							}
						}
					}
				}
			}
		}

		hidden_effect = { #Remove potential relationship so we don't bother players about the same relationship over and over
			if = {
				limit = {
					has_relation_potential_rival = scope:corpse_rival
				}
				remove_relation_potential_rival = scope:corpse_rival
			}
		}
		ai_chance = { #ai always goes for relationship
			base = 0
		}
		stress_impact = {
			brave = minor_stress_impact_gain
			vengeful = medium_stress_impact_gain
			arrogant = medium_stress_impact_gain
			wrathful = major_stress_impact_gain
			sadistic = medium_stress_impact_gain
		}
	}

	option = { #Bury them
		name = relation_upgrade.2101.c
		add_piety = minor_piety_gain
		random = {
			chance = 40
			send_interface_toast = {
				title = relation_upgrade.2102.b_tt_2
				left_icon = root
				scope:rival_capital.county = {
					add_county_modifier = {
						modifier = disease_spreading_modifier
						years = 10
					}
				}
			}
		}
		ai_chance = { #ai always goes for relationship
			base = 0
		}
		stress_impact = {
			compassionate = medium_stress_impact_loss
			brave = minor_stress_impact_gain
			vengeful = medium_stress_impact_gain
			arrogant = medium_stress_impact_gain
			wrathful = major_stress_impact_gain
			sadistic = medium_stress_impact_gain
		}
	}
}

#####################################################
# Vengeful character gains a rival 					#
# (or has the Cultural Parameter)					#
# by Alexander Oltner								#
#####################################################

relation_upgrade.3000 = {
	type = character_event
	title = relation_upgrade.3000.t
	desc = relation_upgrade.3000.desc
	theme = rival_relation
	left_portrait = {
		character = root
		animation = rage
	}
	right_portrait = {
		character = scope:rival_to_be
		animation = dismissal
	}
	
	trigger = {
		NOT = { has_character_flag = had_event_relation_upgrade_3000 }
		is_available_adult = yes
		any_relation = {
			type = potential_rival
			is_available_ai_adult = yes
		}
		OR = {
			has_trait = vengeful
			culture = {
				has_cultural_parameter = rivalries_more_common
			}
		}
		NOR = {
			has_trait = forgiving
			has_trait = calm
		}
		num_of_relation_rival <= 2
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = 3
			culture = {
				has_cultural_parameter = rivalries_more_common
			}
		}
	}

	immediate = {
		add_character_flag = {
			flag = had_event_relation_upgrade_3000
			days = 1825
		}
		random_relation = {
			type = potential_rival
			limit = {
				is_available_ai_adult = yes
			}
			save_scope_as = rival_to_be
		}
	}

	option = {
		name = relation_upgrade.3000.a
		set_relation_rival = {
			target = scope:rival_to_be
			reason = rival_bad_chemistry
		}
		add_character_modifier = {
			modifier = driven_by_vengeance_modifier
			years = 10
		}
	}

	option = {
		name = relation_upgrade.3000.b
		remove_relation_potential_rival = scope:rival_to_be
		add_stress = 150
	}
}
