﻿namespace = diplomacy_family

# Diplomacy (Family) Events:
	#0007		: An Opportune Moment (Convince an eletor to vote for your chosen heir), by Mathilda Bjarnehed
	#0008 - 0011: A Flaw of Character (Attempt to get rid of one of your heir's negative personality traits), by Mathilda Bjarnehed
 	#2100 - 2199: The Quarrel (Two members of your family are fighting), by Petter Vilberg
 	#2200 		: Pick Best Friend from selection.
 	#2250 - 2254: Jealous relative vs lover's spouse.
 	#2300 - 2301: Problematic Dynasty Member.

 # Diplomay (Family) Special Events:
 	#2200 - 2299: Successor's Squabble (One of your powerful vassals dislikes your heir), by Sean Hughes

#############################
# An Opportune Moment		#
# 0007						#
# by Mathilda Bjarnehed		#
#############################

scripted_trigger diplomacy_family_0007_election_title_trigger = {
	save_temporary_scope_as = election_title
	has_order_of_succession = election
	any_election_candidate = {
		has_election_vote_of = {
			who = root
			title = scope:election_title
		}
		save_temporary_scope_as = election_candidate
		scope:election_title = {
			
			any_elector = {
				diplomacy_family_0007_elector_trigger = { CANDIDATE = scope:election_candidate TITLE = scope:election_title }
			}
		}
	}
}

scripted_trigger diplomacy_family_0007_elector_trigger = {
	is_available_ai_adult = yes
	opinion = {
		target = root
		value >= 10
	}
	save_temporary_scope_as = election_elector
	NOT = {
		$CANDIDATE$ = {
			has_election_vote_of = {
				who = scope:election_elector
				title = $TITLE$
			}
		}
	}
}

diplomacy_family.0007 = {
	type = character_event
	title = diplomacy_family.0007.t
	desc = diplomacy_family.0007.desc
	theme = diplomacy_family_focus
	override_background = {
		event_background = feast
	}
	left_portrait = {
		character = scope:voter
		animation = happiness
	}
	
	trigger = {
		NOT = { has_character_flag = had_event_diplomacy_family_0007 }
		any_held_title = {
			diplomacy_family_0007_election_title_trigger = yes
		}
	}

	weight_multiplier = {
		base = 0.5

		modifier = {
			add = 1.5

			any_held_title = {
				save_temporary_scope_as = election_title
				has_order_of_succession = election
				NOT = { # More likely if the current projected election winner is not your preferred candidate.
					current_heir = {
						has_election_vote_of = {
							who = root
							title = scope:election_title
						}
					}
				}
			}
		}

		upweight_for_focus_modifier = { FOCUS = diplomacy_family_focus }
	}

	immediate = {
		add_character_flag = {
			flag = had_event_diplomacy_family_0007
			years = 5
		}
		if = {
			limit = {
				is_ai = no
			}
			add_character_flag = {
				flag = had_recent_lifestyle_ongoing_event_diplomacy
				years = ongoing_lifestyle_event_delay
			}
		}
		else = {
			add_character_flag = {
				flag = had_recent_lifestyle_ongoing_event
				years = ongoing_lifestyle_event_delay
			}
		}
		#Pick a title
		random_held_title = {
			limit = {
				diplomacy_family_0007_election_title_trigger = yes
				save_temporary_scope_as = elector_title
				root = { primary_title = scope:elector_title }
			}
			alternative_limit = {
				diplomacy_family_0007_election_title_trigger = yes
				tier = tier_empire
			}
			alternative_limit = {
				diplomacy_family_0007_election_title_trigger = yes
				tier = tier_kingdom
			}
			alternative_limit = {
				diplomacy_family_0007_election_title_trigger = yes
				tier = tier_duchy
			}
			alternative_limit = {
				diplomacy_family_0007_election_title_trigger = yes
				tier = tier_county
			}
			save_scope_as = title

			random_election_candidate = {
				limit = {
					has_election_vote_of = {
						who = root
						title = scope:title
					}
				}
				save_scope_as = candidate
			}

			random_elector = {
				limit = { diplomacy_family_0007_elector_trigger = { CANDIDATE = scope:candidate TITLE = scope:title } }
				save_scope_as = voter
			}
		}
	}

	#Convince them about candidate's advantages
	option = {
		name = diplomacy_family.0007.a
		
		duel = {
			target = scope:voter
			skill = diplomacy
			16 = {		
				compare_modifier = {
					value = scope:duel_value
					multiplier = 0.5
					min = -15
				}
				desc = diplomacy_family.0007.a.success.tt
				send_interface_toast = {
					left_icon = scope:voter
					title = diplomacy_family.0007.a.success.tt
					scope:voter = {
						force_vote_as = {
							target = root
							years = 20
						}
					}
				}
			}
			12 = {		
				compare_modifier = {
					value = scope:duel_value
					multiplier = -0.5
					min = -11
				}
				desc = diplomacy_family.0007.a.failure.tt
				send_interface_toast = {
					left_icon = scope:voter
					title = diplomacy_family.0007.a.failure.tt
					add_prestige = minor_prestige_loss
				}
			}
		}
	}
	
	#Offer them a favor in return
	option = {
		name = diplomacy_family.0007.c
		trigger = {
			NOT = {
				scope:voter = {
					has_hook = root
				}
			}
		}

		scope:voter = {
			force_vote_as = {
				target = root
				years = 20
			}
			add_hook = {
				target = root
				type = favor_hook
			}
		}

		stress_impact = {
			paranoid = medium_stress_gain
			stubborn = minor_stress_gain
		}
	}

	#Bribe them
	option = {
		trigger = {
			scope:voter = { ai_greed >= -10 }
			OR = {
				short_term_gold >= medium_gold_value_check
				is_ai = no
			}
		}
		name = diplomacy_family.0007.b

		if = {
			limit = { scope:voter = { ai_greed >= 20 } }

			pay_short_term_gold = {
				target = scope:voter
				gold = minor_gold_value
			}
		}
		else = {
			pay_short_term_gold = {
				target = scope:voter
				gold = medium_gold_value
			}
		}
		scope:voter = {
			force_vote_as = {
				target = root
				years = 20
			}
		}
		
		stress_impact = {
			greedy = medium_stress_gain
			honest = minor_stress_gain
			just = minor_stress_gain
		}
	}
}	


#############################
# A Flaw of Character		#
# 0008 - 0011				#
# by Mathilda Bjarnehed		#
#############################

scripted_trigger diplomacy_family_0008_uncompassionate_trigger = {
	OR = {
		has_trait = lazy
		has_trait = callous
		has_trait = greedy
		has_trait = arrogant
		has_trait = deceitful
		has_trait = sadistic
		has_trait = vengeful
	}
}

scripted_trigger diplomacy_family_0008_dishonorable_trigger = {
	OR = {
		has_trait = arbitrary
		has_trait = callous
		has_trait = greedy
		has_trait = arrogant
		has_trait = deceitful
		has_trait = sadistic
		has_trait = vengeful
	}
}

scripted_trigger diplomacy_family_0008_greedy_trigger = {
	OR = {
		has_trait = lazy
		has_trait = gluttonous
		has_trait = greedy
	}
}

scripted_trigger diplomacy_family_0008_unenergetic_trigger = {
	OR = {
		has_trait = lazy
		has_trait = craven
	}
}

scripted_trigger diplomacy_family_0008_vengeful_trigger = {
	OR = {
		has_trait = stubborn
		has_trait = vengeful
	}
}

scripted_trigger diplomacy_family_0008_disagreeable_trigger = {
	is_available_ai_adult = yes
	NOT = { has_character_flag = statecraft_improved_heir }
	OR = {
		diplomacy_family_0008_uncompassionate_trigger = yes
		diplomacy_family_0008_dishonorable_trigger = yes
		diplomacy_family_0008_greedy_trigger = yes
		diplomacy_family_0008_unenergetic_trigger = yes
		diplomacy_family_0008_vengeful_trigger = yes
	}
	opinion = {
		target = root
		value > 0
	}
}


#Heir is disagreeable, coach them?
diplomacy_family.0008 = {
	type = character_event
	title = diplomacy_family.0008.t
	desc = {
		desc = diplomacy_family.0008.start.desc
		random_valid = {
			triggered_desc = {
				trigger = { scope:disagreeable_heir = { has_trait = lazy } }
				desc = diplomacy_family.0008.lazy.desc
			}
			triggered_desc = {
				trigger = { scope:disagreeable_heir = { has_trait = craven } }
				desc = diplomacy_family.0008.craven.desc
			}
			triggered_desc = {
				trigger = { scope:disagreeable_heir = { has_trait = arbitrary } }
				desc = diplomacy_family.0008.arbitrary.desc
			}
			triggered_desc = {
				trigger = { scope:disagreeable_heir = { has_trait = callous } }
				desc = diplomacy_family.0008.callous.desc
			}
			triggered_desc = {
				trigger = { scope:disagreeable_heir = { has_trait = stubborn } }
				desc = diplomacy_family.0008.stubborn.desc
			}
			triggered_desc = {
				trigger = { scope:disagreeable_heir = { has_trait = gluttonous } }
				desc = diplomacy_family.0008.gluttonous.desc
			}
			triggered_desc = {
				trigger = { scope:disagreeable_heir = { has_trait = greedy } }
				desc = diplomacy_family.0008.greedy.desc
			}
			triggered_desc = {
				trigger = { scope:disagreeable_heir = { has_trait = arrogant } }
				desc = diplomacy_family.0008.arrogant.desc
			}
			triggered_desc = {
				trigger = { scope:disagreeable_heir = { has_trait = deceitful } }
				desc = diplomacy_family.0008.deceitful.desc
			}
			triggered_desc = {
				trigger = { scope:disagreeable_heir = { has_trait = vengeful } }
				desc = diplomacy_family.0008.vengeful.desc
			}
		}
		first_valid = {
			triggered_desc = { #will they be able to manage my vassals? 
				trigger = { 
					any_vassal = { 
						NOT = { this = scope:disagreeable_heir }
					} 
				}
				desc = diplomacy_family.0008.end.desc
			}
			#will they manage in my stead?
			desc = diplomacy_family.0008.end_no_vassals.desc
		}
	}
	theme = diplomacy_family_focus
	override_background = {
		event_background = throne_room
	}
	left_portrait = scope:disagreeable_heir
	
	trigger = {
		NOT = { has_character_flag = had_event_diplomacy_family_0008 }
		exists = player_heir
		player_heir = {
			diplomacy_family_0008_disagreeable_trigger = yes
		}
	}

	weight_multiplier = {
		base = 1
		upweight_for_focus_modifier = { FOCUS = diplomacy_family_focus }
	}


	immediate = {
		add_character_flag = {
			flag = had_event_diplomacy_family_0008
			days = 1825
		}
		if = {
			limit = {
				is_ai = no
			}
			add_character_flag = {
				flag = had_recent_lifestyle_ongoing_event_diplomacy
				years = ongoing_lifestyle_event_delay
			}
		}
		else = {
			add_character_flag = {
				flag = had_recent_lifestyle_ongoing_event
				years = ongoing_lifestyle_event_delay
			}
		}
		player_heir = {
			save_scope_as = disagreeable_heir
		}

	}

	#Yes! I will deal with this
	option = {
		name = diplomacy_family.0008.a
		custom_tooltip = diplomacy_family.0008.a.tt

		hidden_effect = {
			trigger_event = { id = diplomacy_family.0009 days = 2 }
		}
	}

	# Put a PR spin on it instead.
	option = {
		name = diplomacy_family.0008.b
		if = {
			limit = { 
				any_vassal = { 
					NOT = { this = scope:disagreeable_heir }
				}  
			}
			every_vassal = {
				custom = diplomacy_family.0008.b.custom
				limit = { NOT = { this = scope:disagreeable_heir } }
				add_opinion = {
					modifier = respect_opinion
					target = scope:disagreeable_heir
					opinion = 10
				}
			}
		}

		scope:disagreeable_heir = {
			add_opinion = {
				modifier = respect_opinion
				target = root
				opinion = 10
			}
		}
	}

	#No, I will focus on myself
	option = {
		name = diplomacy_family.0008.c

		add_character_modifier = {
			modifier = statecraft_well_mannered_modifier
			years = 5
		}
	}
}

#what lesson shall I teach them?
diplomacy_family.0009 = {
	type = character_event
	title = diplomacy_family.0008.t
	desc = {
		first_valid = {
			#First attempt
			triggered_desc = {
				trigger = { NOT = { has_character_flag = disagreeable_heir_second_attempt } }
				desc = diplomacy_family.0009.desc
			}
			#Second attempt (comes in two versions, wrong/right lesson)
			desc = {
				#Start
				first_valid = {
					triggered_desc = {
						trigger = {
							scope:lesson_outcome_flag = flag:failure_wrong_lesson
						}
						desc = diplomacy_family.0009.wronglessonstart.desc
					}
					triggered_desc = {
						trigger = {
							scope:lesson_outcome_flag = flag:failure_right_lesson
						}
						desc = diplomacy_family.0009.rightlessonstart.desc
					}
				}
				#Lesson appropriate piece
				first_valid = {
					triggered_desc = {
						trigger = {
							exists = scope:lesson_type_flag
							scope:lesson_type_flag = flag:compassion
						}
						desc = diplomacy_family.0009.compassion.desc
					}
					triggered_desc = {
						trigger = {
							exists = scope:lesson_type_flag
							scope:lesson_type_flag = flag:honor
						}
						desc = diplomacy_family.0009.honor.desc
					}
					triggered_desc = {
						trigger = {
							exists = scope:lesson_type_flag
							scope:lesson_type_flag = flag:greed
						}
						desc = diplomacy_family.0009.greed.desc
					}
					triggered_desc = {
						trigger = {
							exists = scope:lesson_type_flag
							scope:lesson_type_flag = flag:energy
						}
						desc = diplomacy_family.0009.energy.desc
					}
					triggered_desc = {
						trigger = {
							exists = scope:lesson_type_flag
							scope:lesson_type_flag = flag:vengefulness
						}
						desc = diplomacy_family.0009.vengefulness.desc
					}
				}
				#End
				first_valid = {
					triggered_desc = {
						trigger = {
							exists = scope:lesson_type_flag
							scope:lesson_outcome_flag = flag:failure_wrong_lesson
						}
						desc = diplomacy_family.0009.wronglessonend.desc
					}
					triggered_desc = {
						trigger = {
							exists = scope:lesson_type_flag
							scope:lesson_outcome_flag = flag:failure_right_lesson
						}
						desc = diplomacy_family.0009.rightlessonend.desc
					}
				}
			}
		}
	}
	theme = diplomacy_family_focus
	override_background = {
		trigger = {
			trigger_if = {
				limit = { exists = scope:lesson_type_flag }
				OR = {
					scope:lesson_type_flag = flag:honor
					scope:lesson_type_flag = flag:energy
					scope:lesson_type_flag = flag:vengefulness
				}
			}
			trigger_else = {
				always = yes
			}
		}
		event_background = throne_room
	}
	override_background = {
		trigger = {
			exists = scope:lesson_type_flag
			OR = {
				scope:lesson_type_flag = flag:compassion
				scope:lesson_type_flag = flag:greed
			}
		}
		event_background = alley_day
	}
	left_portrait = scope:disagreeable_heir
	
	trigger = {
		scope:disagreeable_heir = {
			is_alive = yes
		}
	}
	on_trigger_fail = {
		remove_character_flag = disagreeable_heir_second_attempt
	}

	immediate = {
		hidden_effect = {
			#Sets the 4 options
			add_character_flag = compassion_option
			add_character_flag = honor_option
			add_character_flag = greed_option
			add_character_flag = energy_option
			add_character_flag = vengefulness_option

			random_list = {
				1 = {
					trigger = { scope:disagreeable_heir = { diplomacy_family_0008_uncompassionate_trigger = no } }
					remove_character_flag = compassion_option
				}
				1 = {
					trigger = { scope:disagreeable_heir = { diplomacy_family_0008_dishonorable_trigger = no } }
					remove_character_flag = honor_option
				}
				1 = {
					trigger = { scope:disagreeable_heir = { diplomacy_family_0008_greedy_trigger = no } }
					remove_character_flag = greed_option
				}
				1 = {
					trigger = { scope:disagreeable_heir = { diplomacy_family_0008_unenergetic_trigger = no } }
					remove_character_flag = energy_option
				}
				1 = {
					trigger = { scope:disagreeable_heir = { diplomacy_family_0008_vengeful_trigger = no } }
					remove_character_flag = vengefulness_option
				}
			}

			#Check if this is the second attempt
			if = {
				limit = { exists = scope:lesson_outcome_flag }
				add_character_flag = {
					flag = disagreeable_heir_second_attempt
					days = 100
				}
			}
		}
	}

	#Exercise in compassion
	option = {
		trigger = { has_character_flag = compassion_option }
		name = diplomacy_family.0009.a
		flavor = diplomacy_family.0009.a.tt

		diplomacy_family_0008_appropriate_lesson_effect = { LESSON_TYPE = compassion }

		stress_impact = {
			callous = medium_stress_impact_gain
			sadistic = medium_stress_impact_gain
			greedy = minor_stress_impact_gain
		}
	}

	#Exercise in honor
	option = {
		trigger = { has_character_flag = honor_option }
		name = diplomacy_family.0009.b
		flavor = diplomacy_family.0009.b.tt

		diplomacy_family_0008_appropriate_lesson_effect = { LESSON_TYPE = honor }

		stress_impact = {
			arbitrary = medium_stress_impact_gain
			sadistic = medium_stress_impact_gain
			callous = minor_stress_impact_gain
			deceitful = minor_stress_impact_gain
		}
	}
	
	#Exercise in selflessness
	option = {
		trigger = { has_character_flag = greed_option }
		name = diplomacy_family.0009.c
		flavor = diplomacy_family.0009.c.tt

		diplomacy_family_0008_appropriate_lesson_effect = { LESSON_TYPE = greed }

		stress_impact = {
			greedy = medium_stress_impact_gain
			gluttonous = minor_stress_impact_gain
			ambitious = minor_stress_impact_gain
		}
	}

	#Exercise in action
	option = {
		trigger = { has_character_flag = energy_option }
		name = diplomacy_family.0009.d
		flavor = diplomacy_family.0009.d.tt

		diplomacy_family_0008_appropriate_lesson_effect = { LESSON_TYPE = energy }

		stress_impact = {
			content = minor_stress_impact_gain
			craven = minor_stress_impact_gain
			lazy = minor_stress_impact_gain
		}
	}

	#Exercise in forgiveness
	option = {
		trigger = { has_character_flag = vengefulness_option }
		name = diplomacy_family.0009.e
		flavor = diplomacy_family.0009.e.tt

		diplomacy_family_0008_appropriate_lesson_effect = { LESSON_TYPE = vengefulness }

		stress_impact = {
			vengeful = medium_stress_impact_gain
			stubborn = medium_stress_impact_gain
			paranoid = minor_stress_impact_gain
		}
	}

	#Firing the correct follow-up event
	after = {
		hidden_effect = {
			if = {
				limit = {
					exists = scope:lesson_outcome_flag
					scope:lesson_outcome_flag = flag:success
				}
				trigger_event = { id = diplomacy_family.0010 days = { 10 30 } } #Success
			}

			else_if = {
				limit = {
					exists = scope:lesson_outcome_flag
					OR = {
						scope:lesson_outcome_flag = flag:failure_wrong_lesson
						scope:lesson_outcome_flag = flag:failure_right_lesson
					}
					NOT = { has_character_flag = disagreeable_heir_second_attempt }
				}

				trigger_event = { id = diplomacy_family.0009 days = { 10 30 } } #You struggle and try again
			}

			else_if = {
				limit = {
					exists = scope:lesson_outcome_flag
					OR = {
						scope:lesson_outcome_flag = flag:failure_wrong_lesson
						scope:lesson_outcome_flag = flag:failure_right_lesson
					}
					has_character_flag = disagreeable_heir_second_attempt
				}
				trigger_event = { id = diplomacy_family.0011 days = { 10 30 } } #Failure
			}

			remove_character_flag = compassion_option
			remove_character_flag = honor_option
			remove_character_flag = greed_option
			remove_character_flag = energy_option
			remove_character_flag = vengefulness_option
		}
	}
}


#Your lesson changed them!
diplomacy_family.0010 = {
	type = character_event
	title = diplomacy_family.0010.t
	desc = {
		desc = diplomacy_family.0010.start.desc
		first_valid = {
			triggered_desc = {
				trigger = { scope:lesson_type_flag = flag:compassion }
				desc = diplomacy_family.0010.compassion.desc
			}
			triggered_desc = {
				trigger = { scope:lesson_type_flag = flag:honor }
				desc = diplomacy_family.0010.honor.desc
			}
			triggered_desc = {
				trigger = { scope:lesson_type_flag = flag:greed }
				desc = diplomacy_family.0010.greed.desc
			}
			triggered_desc = {
				trigger = { scope:lesson_type_flag = flag:energy }
				desc = diplomacy_family.0010.energy.desc
			}
			triggered_desc = {
				trigger = { scope:lesson_type_flag = flag:vengefulness }
				desc = diplomacy_family.0010.vengefulness.desc
			}
		}
		first_valid = {
			triggered_desc = {
				trigger = { scope:remove_trait_flag = flag:lazy }
				desc = diplomacy_family.0010.lazy.desc
			}
			triggered_desc = {
				trigger = { scope:remove_trait_flag = flag:craven }
				desc = diplomacy_family.0010.craven.desc
			}
			triggered_desc = {
				trigger = { scope:remove_trait_flag = flag:arbitrary }
				desc = diplomacy_family.0010.arbitrary.desc
			}
			triggered_desc = {
				trigger = { scope:remove_trait_flag = flag:callous }
				desc = diplomacy_family.0010.callous.desc
			}
			triggered_desc = {
				trigger = { scope:remove_trait_flag = flag:stubborn }
				desc = diplomacy_family.0010.stubborn.desc
			}
			triggered_desc = {
				trigger = { scope:remove_trait_flag = flag:gluttonous }
				desc = diplomacy_family.0010.gluttonous.desc
			}
			triggered_desc = {
				trigger = { scope:remove_trait_flag = flag:greedy }
				desc = diplomacy_family.0010.greedy.desc
			}
			triggered_desc = {
				trigger = { scope:remove_trait_flag = flag:arrogant }
				desc = diplomacy_family.0010.arrogant.desc
			}
			triggered_desc = {
				trigger = { scope:remove_trait_flag = flag:deceitful }
				desc = diplomacy_family.0010.deceitful.desc
			}
			triggered_desc = {
				trigger = { scope:remove_trait_flag = flag:sadistic }
				desc = diplomacy_family.0010.sadistic.desc
			}
			triggered_desc = {
				trigger = { scope:remove_trait_flag = flag:vengeful }
				desc = diplomacy_family.0010.vengeful.desc
			}
		}
		desc = diplomacy_family.0010.end.desc
	}
	theme = diplomacy_family_focus
	override_background = {
		trigger = {
			OR = {
				scope:lesson_type_flag = flag:honor
				scope:lesson_type_flag = flag:energy
				scope:lesson_type_flag = flag:vengefulness
			}
		}
		event_background = throne_room
	}
	override_background = {
		trigger = {
			OR = {
				scope:lesson_type_flag = flag:compassion
				scope:lesson_type_flag = flag:greed
			}
		}
		event_background = alley_day
	}
	left_portrait = {
		character = scope:disagreeable_heir		
		triggered_animation = {
			trigger = { scope:lesson_type_flag = flag:compassion }
			animation = personality_compassionate
		}
		triggered_animation = {
			trigger = { scope:lesson_type_flag = flag:honor }
			animation = personality_honorable
		}
		triggered_animation = {
			trigger = { scope:lesson_type_flag = flag:greed }
			animation = personality_content
		}
		triggered_animation = {
			trigger = { scope:lesson_type_flag = flag:energy }
			animation = personality_bold
		}
		triggered_animation = {
			trigger = { scope:lesson_type_flag = flag:vengefulness }
			animation = personality_forgiving
		}
	}

	trigger = {
		scope:disagreeable_heir = {
			is_alive = yes
		}
	}
	on_trigger_fail = {
		remove_character_flag = disagreeable_heir_second_attempt
	}

	immediate = {
		hidden_effect = {
			remove_character_flag = disagreeable_heir_second_attempt

			random_dummy_gender_effect = yes

			#Pick the trait to remove
			random_list = {
				1 = {
					trigger = { scope:lesson_type_flag = flag:compassion }
					random_list = {
						1 = {
							trigger = { scope:disagreeable_heir = { has_trait = lazy } }
							save_scope_value_as = {
								name = remove_trait_flag
								value = flag:lazy
							}
						}
						1 = {
							trigger = { scope:disagreeable_heir = { has_trait = callous } }
							save_scope_value_as = {
								name = remove_trait_flag
								value = flag:callous
							}
						}
						1 = {
							trigger = { scope:disagreeable_heir = { has_trait = greedy } }
							save_scope_value_as = {
								name = remove_trait_flag
								value = flag:greedy
							}
						}
						1 = {
							trigger = { scope:disagreeable_heir = { has_trait = arrogant } }
							save_scope_value_as = {
								name = remove_trait_flag
								value = flag:arrogant
							}
						}
						1 = {
							trigger = { scope:disagreeable_heir = { has_trait = deceitful } }
							save_scope_value_as = {
								name = remove_trait_flag
								value = flag:deceitful
							}
						}
						1 = {
							trigger = { scope:disagreeable_heir = { has_trait = sadistic } }
							save_scope_value_as = {
								name = remove_trait_flag
								value = flag:sadistic
							}
						}
						1 = {
							trigger = { scope:disagreeable_heir = { has_trait = vengeful } }
							save_scope_value_as = {
								name = remove_trait_flag
								value = flag:vengeful
							}
						}
					}
				}
				1 = {
					trigger = { scope:lesson_type_flag = flag:honor }
					random_list = {
						1 = {
							trigger = { scope:disagreeable_heir = { has_trait = arbitrary } }
							save_scope_value_as = {
								name = remove_trait_flag
								value = flag:arbitrary
							}
						}
						1 = {
							trigger = { scope:disagreeable_heir = { has_trait = callous } }
							save_scope_value_as = {
								name = remove_trait_flag
								value = flag:callous
							}
						}
						1 = {
							trigger = { scope:disagreeable_heir = { has_trait = greedy } }
							save_scope_value_as = {
								name = remove_trait_flag
								value = flag:greedy
							}
						}
						1 = {
							trigger = { scope:disagreeable_heir = { has_trait = arrogant } }
							save_scope_value_as = {
								name = remove_trait_flag
								value = flag:arrogant
							}
						}
						1 = {
							trigger = { scope:disagreeable_heir = { has_trait = deceitful } }
							save_scope_value_as = {
								name = remove_trait_flag
								value = flag:deceitful
							}
						}
						1 = {
							trigger = { scope:disagreeable_heir = { has_trait = sadistic } }
							save_scope_value_as = {
								name = remove_trait_flag
								value = flag:sadistic
							}
						}
						1 = {
							trigger = { scope:disagreeable_heir = { has_trait = vengeful } }
							save_scope_value_as = {
								name = remove_trait_flag
								value = flag:vengeful
							}
						}
					}
				}
				1 = {
					trigger = { scope:lesson_type_flag = flag:greed }
					random_list = {
						1 = {
							trigger = { scope:disagreeable_heir = { has_trait = lazy } }
							save_scope_value_as = {
								name = remove_trait_flag
								value = flag:lazy
							}
						}
						1 = {
							trigger = { scope:disagreeable_heir = { has_trait = gluttonous } }
							save_scope_value_as = {
								name = remove_trait_flag
								value = flag:gluttonous
							}
						}
						1 = {
							trigger = { scope:disagreeable_heir = { has_trait = greedy } }
							save_scope_value_as = {
								name = remove_trait_flag
								value = flag:greedy
							}
						}
					}
				}
				1 = {
					trigger = { scope:lesson_type_flag = flag:energy }
					random_list = {
						1 = {
							trigger = { scope:disagreeable_heir = { has_trait = lazy } }
							save_scope_value_as = {
								name = remove_trait_flag
								value = flag:lazy
							}
						}
						1 = {
							trigger = { scope:disagreeable_heir = { has_trait = craven } }
							save_scope_value_as = {
								name = remove_trait_flag
								value = flag:craven
							}
						}
					}
				}
				1 = {
					trigger = { scope:lesson_type_flag = flag:vengefulness }
					random_list = {
						1 = {
							trigger = { scope:disagreeable_heir = { has_trait = stubborn } }
							save_scope_value_as = {
								name = remove_trait_flag
								value = flag:stubborn
							}
						}
						1 = {
							trigger = { scope:disagreeable_heir = { has_trait = vengeful } }
							save_scope_value_as = {
								name = remove_trait_flag
								value = flag:vengeful
							}
						}
					}
				}
			}
		}
	}

	#Trait removed
	option = {
		name = diplomacy_family.0010.a

		scope:disagreeable_heir = {
			add_character_flag = statecraft_improved_heir

			if = {
				limit = { scope:remove_trait_flag = flag:lazy }
				remove_trait = lazy
			}
			if = {
				limit = { scope:remove_trait_flag = flag:craven }
				remove_trait = craven
			}
			if = {
				limit = { scope:remove_trait_flag = flag:arbitrary }
				remove_trait = arbitrary
			}
			if = {
				limit = { scope:remove_trait_flag = flag:callous }
				remove_trait = callous
			}
			if = {
				limit = { scope:remove_trait_flag = flag:stubborn }
				remove_trait = stubborn
			}
			if = {
				limit = { scope:remove_trait_flag = flag:gluttonous }
				remove_trait = gluttonous
			}
			if = {
				limit = { scope:remove_trait_flag = flag:greedy }
				remove_trait = greedy
			}
			if = {
				limit = { scope:remove_trait_flag = flag:arrogant }
				remove_trait = arrogant
			}
			if = {
				limit = { scope:remove_trait_flag = flag:deceitful }
				remove_trait = deceitful
			}
			if = {
				limit = { scope:remove_trait_flag = flag:sadistic }
				remove_trait = sadistic
			}
			if = {
				limit = { scope:remove_trait_flag = flag:vengeful }
				remove_trait = vengeful
			}
			random_list = {
				1 = { # Possible Replacement Trait 1
					trigger = {
						NOR = {
							has_trait = stubborn
							has_trait = fickle
						}
					}
					add_trait = fickle
				}
				1 = { # Possible Replacement Trait 2
					trigger = {
						NOR = {
							has_trait = arrogant
							has_trait = humble
						}
					}
					add_trait = humble
				}
				1 = { # Possible Replacement Trait 3
					trigger = {
						NOR = {
							has_trait = paranoid
							has_trait = trusting
						}
					}
					add_trait = trusting
				}
				1 = { # Fallback Trait 1
					trigger = {
						OR = {
							has_trait = stubborn
							has_trait = fickle
						}
						NOR = {
							has_trait = sadistic
							has_trait = callous
							has_trait = compassionate
						}
					}
					add_trait = compassionate
				}
				1 = { # Fallback Trait 2
					trigger = {
						OR = {
							has_trait = arrogant
							has_trait = humble
							has_trait = trusting
							has_trait = paranoid
							AND = { # Trait Set from Fallback Trait 1
								OR = {
									has_trait = stubborn
									has_trait = fickle
								}
								OR = {
									has_trait = sadistic
									has_trait = callous
									has_trait = compassionate
								}
							}
						}
						NOR = {
							has_trait = gregarious
							has_trait = shy
						}
					}
					add_trait = shy
				}

			}
		}
	}

	#Get the good trait but spend stress
	option = {
		name = diplomacy_family.0010.c

		stress_impact = {
			base = major_stress_impact_gain
			lazy = minor_stress_impact_gain
			diligent = minor_stress_impact_loss

		}
		scope:disagreeable_heir = { add_character_flag = statecraft_improved_heir }

		#Remove
		if = {
			limit = { scope:remove_trait_flag = flag:lazy }
			scope:disagreeable_heir = { remove_trait = lazy }
			scope:disagreeable_heir = { add_trait_force_tooltip = diligent }
		}
		if = {
			limit = { scope:remove_trait_flag = flag:craven }
			scope:disagreeable_heir = { remove_trait = craven }
			scope:disagreeable_heir = { add_trait_force_tooltip = brave }
		}
		if = {
			limit = { scope:remove_trait_flag = flag:arbitrary }
			scope:disagreeable_heir = { remove_trait = arbitrary }
			scope:disagreeable_heir = { add_trait_force_tooltip = just }
		}
		if = {
			limit = { scope:remove_trait_flag = flag:callous }
			scope:disagreeable_heir = { remove_trait = callous }
			scope:disagreeable_heir = { add_trait_force_tooltip = compassionate }
		}
		if = {
			limit = { scope:remove_trait_flag = flag:stubborn }
			scope:disagreeable_heir = { remove_trait = stubborn }
			scope:disagreeable_heir = { add_trait_force_tooltip = fickle }
		}
		if = {
			limit = { scope:remove_trait_flag = flag:gluttonous }
			scope:disagreeable_heir = { remove_trait = gluttonous }
			scope:disagreeable_heir = { add_trait_force_tooltip = temperate }
		}
		if = {
			limit = { scope:remove_trait_flag = flag:greedy }
			scope:disagreeable_heir = { remove_trait = greedy }
			scope:disagreeable_heir = { add_trait_force_tooltip = generous }
		}
		if = {
			limit = { scope:remove_trait_flag = flag:arrogant }
			scope:disagreeable_heir = { remove_trait = arrogant }
			scope:disagreeable_heir = { add_trait_force_tooltip = humble }
		}
		if = {
			limit = { scope:remove_trait_flag = flag:deceitful }
			scope:disagreeable_heir = { remove_trait = deceitful }
			scope:disagreeable_heir = { add_trait_force_tooltip = honest }
		}
		if = {
			limit = { scope:remove_trait_flag = flag:sadistic }
			scope:disagreeable_heir = { remove_trait = sadistic }
			 scope:disagreeable_heir = { add_trait_force_tooltip = compassionate }
		}
		if = {
			limit = { scope:remove_trait_flag = flag:vengeful }
			scope:disagreeable_heir = { remove_trait = vengeful }
			scope:disagreeable_heir = { add_trait_force_tooltip = forgiving }
		}
	}

	#Keep trait
	option = {
		name = diplomacy_family.0010.b
		add_diplomacy_lifestyle_xp = medium_lifestyle_experience

	}
}

#Failure
diplomacy_family.0011 = {
	type = character_event
	title = diplomacy_family.0011.t
	desc = {
		desc = diplomacy_family.0011.start.desc
		random_valid = {
			triggered_desc = {
				trigger = { scope:disagreeable_heir = { has_trait = lazy } }
				desc = diplomacy_family.0008.lazy.desc
			}
			triggered_desc = {
				trigger = { scope:disagreeable_heir = { has_trait = craven } }
				desc = diplomacy_family.0008.craven.desc
			}
			triggered_desc = {
				trigger = { scope:disagreeable_heir = { has_trait = arbitrary } }
				desc = diplomacy_family.0008.arbitrary.desc
			}
			triggered_desc = {
				trigger = { scope:disagreeable_heir = { has_trait = callous } }
				desc = diplomacy_family.0008.callous.desc
			}
			triggered_desc = {
				trigger = { scope:disagreeable_heir = { has_trait = stubborn } }
				desc = diplomacy_family.0008.stubborn.desc
			}
			triggered_desc = {
				trigger = { scope:disagreeable_heir = { has_trait = gluttonous } }
				desc = diplomacy_family.0008.gluttonous.desc
			}
			triggered_desc = {
				trigger = { scope:disagreeable_heir = { has_trait = greedy } }
				desc = diplomacy_family.0008.greedy.desc
			}
			triggered_desc = {
				trigger = { scope:disagreeable_heir = { has_trait = arrogant } }
				desc = diplomacy_family.0008.arrogant.desc
			}
			triggered_desc = {
				trigger = { scope:disagreeable_heir = { has_trait = deceitful } }
				desc = diplomacy_family.0008.deceitful.desc
			}
			triggered_desc = {
				trigger = { scope:disagreeable_heir = { has_trait = vengeful } }
				desc = diplomacy_family.0008.vengeful.desc
			}
		}
		desc = diplomacy_family.0011.end.desc
	}
	theme = diplomacy_family_focus
	override_background = {
		trigger = {
			OR = {
				scope:lesson_type_flag = flag:honor
				scope:lesson_type_flag = flag:energy
				scope:lesson_type_flag = flag:vengefulness
			}
		}
		event_background = throne_room
	}
	override_background = {
		trigger = {
			OR = {
				scope:lesson_type_flag = flag:compassion
				scope:lesson_type_flag = flag:greed
			}
		}
		event_background = alley_day
	}
	left_portrait = scope:disagreeable_heir

	trigger = {
		scope:disagreeable_heir = {
			is_alive = yes
		}
	}
	on_trigger_fail = {
		remove_character_flag = disagreeable_heir_second_attempt
	}
	
	immediate = {
		hidden_effect = { remove_character_flag = disagreeable_heir_second_attempt }
	}

	option = {
		name = diplomacy_family.0011.a
	}
}


#############################
# Family Quarrel			#
# 2100 - 2199				#
# by Petter Vilberg			#
#############################

# Basic AI requirements
scripted_trigger diplomacy_family_2100_valid_target_trigger = {
	is_alive = yes
	is_available_ai_adult = yes
	NOT = { has_trait = humble }
	NOT = { this = root }
}

scripted_trigger diplomacy_family_2100_family_1_trigger = {
	# Must meet basic requirements
	diplomacy_family_2100_valid_target_trigger = yes

	# Must be another family member who meets the basic requirements
	save_temporary_scope_as = family_1
	any_close_family_member = {
		diplomacy_family_2100_family_2_trigger = yes
	}
}

scripted_trigger diplomacy_family_2100_family_2_trigger = {
	# Must meet basic requirements
	diplomacy_family_2100_valid_target_trigger = yes

	# Must have a mutual dislike with the first family member.
	opinion = {
		target = scope:family_1
		value < 20
	}
	reverse_opinion = {
		target = scope:family_1
		value < 20
	}
}

# Hidden setup event
diplomacy_family.2100 = {
	hidden = yes

	trigger = {
		NOT = {
			has_character_flag = had_diplomacy_family_2100
		}
		any_close_family_member = {
			diplomacy_family_2100_family_1_trigger = yes #Also contains the family_2 trigger
			save_temporary_scope_as = family_1
		}
		any_close_family_member = {
			diplomacy_family_2100_family_2_trigger = yes
		}
	}

	weight_multiplier = {
		base = 1
		upweight_for_focus_modifier = { FOCUS = diplomacy_family_focus }
	}

	immediate = {
		add_character_flag = {
			flag = had_diplomacy_family_2100
			years = 5
		}

		# Get first family member
		random_close_family_member = {
			limit = {
				diplomacy_family_2100_family_1_trigger = yes
			}
			weight = {
				base = 1
				modifier = {
					add = 2
					is_of_major_interest_trigger = {
						CHARACTER = root
					}
				}
				modifier = {
					add = 1
					is_of_minor_interest_trigger = {
						CHARACTER = root
					}
				}
				modifier = {
					add = 1
					root = {
						has_relation_oaf = prev
					}
				}
			}
			save_scope_as = family_1

			# Get second family member
			random_close_family_member = {
				limit = {
					diplomacy_family_2100_family_2_trigger = yes
				}
				weight = {
					base = 1
					modifier = {
						add = 2
						is_of_major_interest_trigger = {
							CHARACTER = root
						}
					}
					modifier = {
						add = 1
						is_of_minor_interest_trigger = {
							CHARACTER = root
						}
					}
					modifier = {
						add = 1
						root = {
							has_relation_oaf = prev
						}
					}
				}
				save_scope_as = family_2
			}
		}

		#Chance of one of them becoming your oaf if you have none
		if = {
			limit = {
				num_of_relation_oaf < 1
			}
			random = {
				chance = 75
				random_list = {
					1 = {
						set_relation_oaf = scope:family_1
					}
					1 = {
						set_relation_oaf = scope:family_2
					}
				}
			}
		}

		#Debugging
		if = {
			limit = {
				NOR = {
					exists = scope:family_1
					exists = scope:family_2
				}
			}
			debug_log_scopes = yes
		}
		if = {
			limit = {
				exists = scope:family_1
				exists = scope:family_2
			}
			trigger_event = diplomacy_family.2101
		}
	}
}


#Two family members are fighting - intervene or not?
diplomacy_family.2101 = {
	type = character_event
	title = diplomacy_family.2101.t
	desc = diplomacy_family.2101.desc
	
	left_portrait = {
		character = scope:family_1
		animation = anger
	}
	right_portrait = {
		character = scope:family_2
		animation = disapproval
	}
	theme = diplomacy_family_focus

	option = { #Lets talk to them
		name = diplomacy_family.2101.a

		custom_tooltip = diplomacy_family.2101.a.tt
		trigger_event = {
			id = diplomacy_family.2102
			days = { 2 3 }
		}
	}

	option = { #I cannot deal with this
		name = diplomacy_family.2101.b

		if = {
			limit = {
				has_trait = diligent
			}
			stress_impact = {
				diligent = medium_stress_impact_gain
				shy = minor_stress_impact_loss
				gregarious = minor_stress_impact_loss
			}
		}
		else = {
			stress_impact = {
				base = minor_stress_impact_loss
				shy = minor_stress_impact_loss
				gregarious = medium_stress_impact_gain
			}
		}
		
	}
}

#How do you resolve the argument?
diplomacy_family.2102 = {
	type = character_event
	title = diplomacy_family.2101.t
	desc = diplomacy_family.2102.desc
	left_portrait = {
		character = scope:family_1
		animation = stress
	}
	right_portrait = {
		character = scope:family_2
		animation = disapproval
	}
	theme = diplomacy_family_focus

	trigger = {
		scope:family_1 = {
			is_alive = yes
		}
		scope:family_2 = {
			is_alive = yes
		}
	}
	
	# Option A: Side with Family #1
	option = {
		name = diplomacy_family.2102.a

		scope:family_1 = {
			add_opinion = {
				modifier = pleased_opinion
				target = root
				opinion = 15
			}
		}
		progress_towards_friend_effect = {
			CHARACTER = scope:family_1
			OPINION = no
		}
		scope:family_2 = {
			add_opinion = {
				modifier = angry_opinion
				target = root
				opinion = -15
			}
		}

		stress_impact = {
			just = minor_stress_impact_gain
		}

		ai_chance = {
			base = 0

			modifier = {
				add = 250
				scope:family_1.highest_held_title_tier > scope:family_2.highest_held_title_tier
			}
			modifier = {
				add = 500
				opinion = {
					target = scope:family_1
					value >= 20
				}
			}
		}
	}

	# Option B: Side with Family #2
	option = {
		name = diplomacy_family.2102.b

		scope:family_2 = {
			add_opinion = {
				modifier = pleased_opinion
				target = root
				opinion = 15
			}
		}
		progress_towards_friend_effect = {
			CHARACTER = scope:family_2
			OPINION = no
		}
		scope:family_1 = {
			add_opinion = {
				modifier = angry_opinion
				target = root
				opinion = -15
			}
		}

		stress_impact = {
			just = minor_stress_impact_gain
		}

		ai_chance = {
			base = 0

			modifier = {
				add = 250
				scope:family_2.highest_held_title_tier > scope:family_1.highest_held_title_tier
			}
			modifier = {
				add = 500
				opinion = {
					target = scope:family_2
					value >= 20
				}
			}
		}
	}

	# Option C: Chastise them both!
	option = {
		name = diplomacy_family.2102.c

		duel = {
			skill = diplomacy
			value = decent_skill_rating

			50 = {
				desc = diplomacy_family.2102.c.success

				# Base skill challenge
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}

				# Harder if the characters are Vengeful
				compare_modifier = {
					value = scope:family_1.ai_vengefulness
					multiplier = -0.5
					max = 10 # Slightly easier if Forgiving, but capped.
				}
				compare_modifier = {
					value = scope:family_2.ai_vengefulness
					multiplier = -0.5
					max = 10 # Slightly easier if Forgiving, but capped.
				}

				
				# The harder the challenge was, the more experience you gain
				if = {
					limit = {
						scope:family_1 = {
							OR = {
								has_trait = arrogant
								ai_vengefulness >= 50
							}
						}
						scope:family_2 = {
							OR = {
								has_trait = arrogant
								ai_vengefulness >= 50
							}
						}
					}
					add_diplomacy_lifestyle_xp = massive_lifestyle_experience
				}
				else_if = {
					limit = {
						OR = {
							scope:family_1 = {
								OR = {
									has_trait = arrogant
									ai_vengefulness >= 50
								}
							}
							scope:family_2 = {
								OR = {
									has_trait = arrogant
									ai_vengefulness >= 50
								}
							}
						}
					}
					add_diplomacy_lifestyle_xp = major_lifestyle_experience
				}
				else = {
					add_diplomacy_lifestyle_xp = medium_lifestyle_experience
				}
				
				# The family members respect your ability to smooth things over.
				scope:family_1 = {
					add_opinion = {
						modifier = respect_opinion
						target = root
						opinion = 15
					}
				}
				scope:family_2 = {
					add_opinion = {
						modifier = respect_opinion
						target = root
						opinion = 15
					}
				}

				# The two family members also like each other more.
				hidden_effect = {
					scope:family_1 = {
						add_opinion = {
							modifier = friendliness_opinion
							target = scope:family_2
							opinion = 30
						}
					}
					scope:family_2 = {
						add_opinion = {
							modifier = friendliness_opinion
							target = scope:family_1
							opinion = 30
						}
					}
				}
			}
			50 = {
				desc = diplomacy_family.2102.c.failure

				# Base skill challenge
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}

				# Harder if the characters are Arrogant
				modifier = {
					add = 25
					scope:family_1 = {
						has_trait = arrogant
					}
				}
				modifier = {
					add = 25
					scope:family_2 = {
						has_trait = arrogant
					}
				}

				# You only manage to insult the two family members.
				scope:family_1 = {
					add_opinion = {
						modifier = insult_opinion
						target = root
						opinion = -15
					}
				}
				scope:family_2 = {
					add_opinion = {
						modifier = insult_opinion
						target = root
						opinion = -15
					}
				}
			}
		}

		ai_chance = {
			base = 50

			ai_value_modifier = {
				ai_compassion = 100
			}

			# Rational characters know when they have a good chance of winning the duel
			compare_modifier = {
				trigger = {
					ai_rationality >= 10
				}
				value = {
					value = diplomacy
					add = -12
				}
				multiplier = 1000 # -10,000 at 0 Diplomacy, +0 at 10 Diplomacy, +10,000 at 20 Diplomacy
			}
		}
	}

	# Option D: Side with yourself!
	option = {
		name = diplomacy_family.2102.d
		flavor = diplomacy_family.2102.d.flavor

		add_diplomacy_lifestyle_xp = minor_lifestyle_experience
		add_prestige = medium_prestige_gain

		scope:family_1 = {
			add_opinion = {
				modifier = insult_opinion
				target = root
				opinion = -15
			}
		}
		scope:family_2 = {
			add_opinion = {
				modifier = insult_opinion
				target = root
				opinion = -15
			}
		}

		stress_impact = {
			humble = medium_stress_impact_gain
			content = minor_stress_impact_gain
		}

		ai_chance = {
			base = 50

			ai_value_modifier = {
				ai_vengefulness = 50
				ai_boldness = 100
			}

			modifier = {
				add = 500
				has_trait = arrogant
			}
		}
	}
}

###########################################################
# Events converted from the old Progress Event system.
# These events are all challenging event chains which should reward a perk point or some other significant benefit for successfully completing them.
namespace = diplomacy_family_special

#############################
# Successor's Squabble		#
# 2200-2300					#
# by Sean Hughes			#
#############################

scripted_trigger diplomacy_family_special_2200_is_valid_vassal_trigger = {
	is_available_healthy_ai_adult = yes
	highest_held_title_tier > 1
	opinion = {
		target = root.player_heir
		value < 25
	}
	NOT = {
		has_relation_rival = root.player_heir
		has_relation_friend = root.player_heir
	}
}

#Heir comes to you upset about a dispite between him and a vassal.
diplomacy_family_special.2200 = {
	type = character_event
	title = diplomacy_family_special.2200.t
	desc = {
		desc = diplomacy_family_special.2200.desc
		first_valid = {
			triggered_desc = {
				trigger = { sex_same_as = scope:heir }
				desc = diplomacy_family_special.2200.same_sex_title.desc
			}
			triggered_desc = {
				trigger = { exists = primary_spouse }
				desc = diplomacy_family_special.2200.opposite_sex_title.desc
			}
			desc = diplomacy_family_special.2200.ruler.desc
		}
		desc = diplomacy_family_special.2200.end.desc
	}
	theme = diplomacy_family_focus
	override_background = {
		event_background = sitting_room
	}
	left_portrait = {
		character = scope:heir
		animation = disapproval
	}
	right_portrait = scope:vassal
	
	trigger = {
		has_focus = diplomacy_family_focus
		NOT = { has_character_flag = is_in_diplomacy_family_special_event }
		NOT = { has_character_flag = had_diplomacy_family_special_2200_this_lifetime }

		exists = player_heir
		exists = primary_heir
		player_heir = {
			this = root.primary_heir
			is_available_healthy_ai_adult = yes
		}
		any_vassal = {
			diplomacy_family_special_2200_is_valid_vassal_trigger = yes
		}
	}

	weight_multiplier = {
		base = 0.25
		modifier = {
			add = 1.5
			any_vassal = {
				diplomacy_family_special_2200_is_valid_vassal_trigger = yes
				number_of_opposing_personality_traits = {
					target = root.player_heir
					value >= 1
				}
			}
		}
	}

	immediate = {
		#Flag us as being in this event chain.
		add_character_flag = {
			flag = is_in_diplomacy_family_special_event
			days = 100
		}
		add_character_flag = had_diplomacy_family_special_2200_this_lifetime

		#Grab your heir.
		player_heir = {
			save_scope_as = heir
		}

		#Grab a vassal who doesn't like your heir (ideally one with conflicting personality traits).
		random_vassal = {
			limit = {
				diplomacy_family_special_2200_is_valid_vassal_trigger = yes
				number_of_opposing_personality_traits = {
					target = scope:heir
					value >= 1
				}
			}
			alternative_limit = {
				diplomacy_family_special_2200_is_valid_vassal_trigger = yes
			}

			weight = {
				base = 50
				compare_modifier = {
					value = age
					multiplier = -0.5
					min = -49
				}

				compare_modifier = {
					factor = highest_held_title_tier
					multiplier = 10
				}
				modifier = {
					is_powerful_vassal = yes
					factor = 10
				}
			}

			save_scope_as = vassal
		}

		#Set a flag on our heir based on which trait of our heir's that our vassal dislikes.
		personality_check_opposing_bad_ruler_traits_effect = {
			CHAR1 = player_heir
			CHAR2 = scope:vassal
			STRICT = no
		}
	}

	#Decide to talk to our heir about the problem.
	option = {
		name = diplomacy_family_special.2200.a

		custom_tooltip = diplomacy_family_special.2200.a.tt
		trigger_event = {
			id = diplomacy_family_special.2201
			days = { 7 14 }
		}
		
		stress_impact = {
			lazy = minor_stress_impact_gain
			callous = minor_stress_impact_gain
			sadistic = minor_stress_impact_gain
		}

		ai_chance = {
			base = 33
			ai_value_modifier = {
				ai_compassion = 200
				ai_energy = 100
			}
		}
	}

	#Decide to talk to our vassal about the problem.
	option = {
		name = diplomacy_family_special.2200.b

		custom_tooltip = diplomacy_family_special.2200.b.tt
		trigger_event = {
			id = diplomacy_family_special.2202
			days = { 7 14 }
		}

		stress_impact = {
			shy = medium_stress_impact_gain
			lazy = minor_stress_impact_gain
			forgiving = minor_stress_impact_gain
			craven = minor_stress_impact_gain
		}

		ai_chance = {
			base = 33
			ai_value_modifier = {
				ai_boldness = 200
				ai_energy = 100
			}
		}
	}
	
	#Pass on this event chain.
	option = {
		name = diplomacy_family_special.2200.c

		add_prestige = medium_prestige_gain
		scope:heir = {
			add_opinion = {
				modifier = refusal_opinion
				target = root
				opinion = -10
			}
		}

		stress_impact = {
			compassionate = medium_stress_impact_gain
			gregarious = minor_stress_impact_gain
			forgiving = minor_stress_impact_gain
			diligent = minor_stress_impact_gain
		}

		ai_chance = {
			base = 33
			ai_value_modifier = {
				ai_compassion = -200
				ai_energy = -100
			}
		}
	}
}

#Talk to heir about resolving the problem.
diplomacy_family_special.2201 = {
	type = character_event
	title = diplomacy_family_special.2200.t
	desc = diplomacy_family_special.2201.desc
	theme = diplomacy_family_focus
	left_portrait = {
		character = scope:heir
		animation = stress
	}
	right_portrait = scope:vassal

	trigger = {
		scope:heir = {
			is_alive = yes
		}
		scope:vassal = {
			is_alive = yes
		}
	}

	#Diplomacy challenge to form friendship bonds between heir and vassal.
	option = {
		name = diplomacy_family_special.2201.a
		duel = {
			skill = diplomacy
			target = scope:heir
			desc = outcome_in_a_few_days

			50 = {		
				compare_modifier = {
					value = scope:duel_value
					multiplier = 2.5
					min = -24
				}
				opinion_modifier = {
					opinion_target = root
					who = scope:heir
					multiplier = 0.25
				}
				desc = diplomacy_family_special.2201.a.success
				show_as_tooltip = {
					add_diplomacy_lifestyle_xp = medium_lifestyle_experience
					scope:heir = {
						add_opinion = {
							target = scope:vassal
							modifier = friendliness_opinion
							opinion = 30
						}
						reverse_add_opinion = {
							target = scope:vassal
							modifier = friendliness_opinion
							opinion = 30
						}
					}
				}
				trigger_event = {
					id = diplomacy_family_special.2212
					days = { 5 7 }
				}
			}
			50 = {		
				compare_modifier = {
					value = scope:duel_value
					multiplier = -2.5
					min = -24
				}
				opinion_modifier = {
					opinion_target = root
					who = scope:heir
					multiplier = -0.25
				}
				desc = diplomacy_family_special.2201.a.failure
				show_as_tooltip = {
					add_diplomacy_lifestyle_xp = minor_lifestyle_experience
					scope:vassal = {
						add_opinion = {
							target = scope:heir
							modifier = respect_opinion
							opinion = -15
						}
					}
				}
				trigger_event = {
					id = diplomacy_family_special.2213
					days = { 5 7 }
				}
			}
		}

		ai_chance = {
			base = 33
			ai_value_modifier = {
				ai_compassion = 200
				ai_energy = 100
			}

			# Intelligent AIs know when they have good odds of winning a duel.
			compare_modifier = {
				trigger = {
					ai_rationality >= 10
				}
				value = diplomacy
				multiplier = 500
			}
			compare_modifier = {
				trigger = {
					ai_rationality >= 10
				}
				value = scope:heir.diplomacy
				multiplier = -500
			}
		}			
	}

	#Learning duel to see if heir is willing to change their personality for you.
	option = {
		name = diplomacy_family_special.2201.b

		#Only display if there is an actual personality dispuite between your vassal
		trigger = {
			scope:heir = {
				personality_has_any_trait_flag_trigger = yes
			}
		}

		duel = {
			skill = learning
			target = scope:heir
			desc = outcome_in_a_few_days
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 2.5
					min = -24
				}
				opinion_modifier = {
					opinion_target = root
					who = scope:heir
					multiplier = 0.25
				}
				modifier = {
					scope:heir = {
						has_trait = fickle
					}
					add = 20
				}

				desc = diplomacy_family_special.2201.b.success
				show_as_tooltip = {
					add_diplomacy_lifestyle_xp = medium_lifestyle_experience
				}
				custom_tooltip = diplomacy_family_special.2201.b.success.tt
				trigger_event = {
					id = diplomacy_family_special.2220
					days = { 5 7 }
				}


			}
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -2.5
					min = -24
				}
				opinion_modifier = {
					opinion_target = root
					who = scope:heir
					multiplier = -0.25
				}
				modifier = {
					scope:heir = {
						has_trait = stubborn
					}
					add = 20
				}

				desc = diplomacy_family_special.2201.b.failure
				show_as_tooltip = {
					add_diplomacy_lifestyle_xp = minor_lifestyle_experience
				}
				custom_tooltip = diplomacy_family_special.2201.b.failure.tt
				trigger_event = {
					id = diplomacy_family_special.2221
					days = { 5 7 }
				}
			}
		}

		ai_chance = {
			base = 33
			ai_value_modifier = {
				ai_rationality = 200
				ai_energy = 100
			}

			# Intelligent AIs know when they have good odds of winning a duel.
			compare_modifier = {
				trigger = {
					ai_rationality >= 10
				}
				value = learning
				multiplier = 500
			}
			compare_modifier = {
				trigger = {
					ai_rationality >= 10
				}
				value = scope:heir.learning
				multiplier = -500
			}
		}			
	}
	
	#Throw vassal under bus for opinion boost with your heir.
	option = {
		name = diplomacy_family_special.2201.c
		reverse_add_opinion = {
			modifier = angry_opinion
			target = scope:vassal
			opinion = -20
		}
		reverse_add_opinion = {
			modifier = kindness_opinion
			target = scope:heir
			opinion = 20
		}
		add_dread = minor_dread_gain

		hidden_effect = {
			remove_character_flag = is_in_diplomacy_family_special_event
		}

		stress_impact = {
			compassionate = minor_stress_impact_gain
			forgiving = minor_stress_impact_gain
		}

		ai_chance = {
			base = 33
			ai_value_modifier = {
				ai_vengefulness = 200
				ai_boldness = 200
				ai_rationality = -50
			}
		}
	}
}

#Talk to vassal about resolving the problem.
diplomacy_family_special.2202 = {
	type = character_event
	title = diplomacy_family_special.2200.t
	desc = diplomacy_family_special.2202.desc
	theme = diplomacy_family_focus
	left_portrait = scope:heir
	right_portrait = {
		character = scope:vassal
		triggered_animation = {
			trigger = { ai_boldness > 0 }
			animation = personality_bold
		}
		animation = worry
	}

	trigger = {
		scope:heir = {
			is_alive = yes
		}
		scope:vassal = {
			is_alive = yes
		}
	}

	#Diplomacy challenge to form friendship bonds between heir and vasal.
	option = {
		name = diplomacy_family_special.2202.a
		duel = {
			skill = diplomacy
			target = scope:vassal
			desc = outcome_in_a_few_days
			40 = {
				desc = diplomacy_family_special.2202.a.success	
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -24
				}
				opinion_modifier = {
					opinion_target = root
					who = scope:heir
					multiplier = 0.15
				}
				compare_modifier = {
					value = scope:heir.num_virtuous_traits
					multiplier = 10
				}
				
				show_as_tooltip = {
					add_diplomacy_lifestyle_xp = medium_lifestyle_experience
					scope:heir = {
						add_opinion = {
							target = scope:vassal
							modifier = friendliness_opinion
							opinion = 30
						}
						reverse_add_opinion = {
							target = scope:vassal
							modifier = friendliness_opinion
							opinion = 30
						}
					}
				}

				trigger_event = {
					id = diplomacy_family_special.2210
					days = { 5 7 }
				}
			}
			60 = {
				desc = diplomacy_family_special.2202.a.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -44
				}
				opinion_modifier = {
					opinion_target = root
					who = scope:heir
					multiplier = -0.15
				}				

				show_as_tooltip = {
					add_diplomacy_lifestyle_xp = minor_lifestyle_experience
					scope:vassal = {
						add_opinion = {
							target = root
							modifier = respect_opinion
							opinion = -15
						}
					}
				}

				trigger_event = {
					id = diplomacy_family_special.2211
					days = { 5 7 }
				}
			}
		}

		ai_chance = {
			base = 33
			ai_value_modifier = {
				ai_compassion = 200
				ai_energy = 100
			}

			# Intelligent AIs know when they have good odds of winning a duel.
			compare_modifier = {
				trigger = {
					ai_rationality >= 10
				}
				value = diplomacy
				multiplier = 500
			}
			compare_modifier = {
				trigger = {
					ai_rationality >= 10
				}
				value = scope:vassal.diplomacy
				multiplier = -500
			}
		}				
	}

	#Throw your heir under the bus for a relationship bonus with the vassal.
	option = {
		name = diplomacy_family_special.2202.b
		reverse_add_opinion = {
			modifier = pleased_opinion
			target = scope:vassal
			opinion = 30
		}
		reverse_add_opinion = {
			modifier = angry_opinion
			target = scope:heir
			opinion = -30
		}
		scope:heir = {
			add_prestige = medium_prestige_loss
		}

		hidden_effect = {
			remove_character_flag = is_in_diplomacy_family_special_event
		}

		stress_impact = {
			compassionate = medium_stress_impact_gain
			patient = minor_stress_impact_gain
		}

		ai_chance = {
			base = 33
			ai_value_modifier = {
				ai_greed = 200
				ai_boldness = 100
				ai_compassion = -100
			}
		}
	}
	
	#Gain dread at the cost of opinion with the vassal.
	option = {
		name = diplomacy_family_special.2202.c

		add_dread = medium_dread_gain
		reverse_add_opinion = {
			modifier = pleased_opinion
			target = scope:heir
			opinion = 15
		}
		reverse_add_opinion = {
			modifier = scared_opinion
			target = scope:vassal
			opinion = -30
		}

		hidden_effect = {
			remove_character_flag = is_in_diplomacy_family_special_event
		}

		stress_impact = {
			compassionate = medium_stress_impact_gain
			forgiving = medium_stress_impact_gain
			just = minor_stress_impact_gain
			humble = minor_stress_impact_gain
		}

		ai_chance = {
			base = 33
			ai_value_modifier = {
				ai_boldness = 200
				ai_vengefulness = 200
				ai_compassion = -100
			}
		}		
	}
}

#Vassal is receptive to resolving differences with heir.
diplomacy_family_special.2210 = {
	type = character_event
	title = diplomacy_family_special.2200.t
	desc = diplomacy_family_special.2210.desc
	theme = diplomacy_family_focus
	left_portrait = scope:heir
	right_portrait = scope:vassal

	trigger = {
		scope:heir = {
			is_alive = yes
		}
		scope:heir = {
			is_alive = yes
		}
	}

	immediate = {
		scope:heir = {
			add_opinion = {
				target = scope:vassal
				modifier = friendliness_opinion
				opinion = 30
			}
			reverse_add_opinion = {
				target = scope:vassal
				modifier = friendliness_opinion
				opinion = 30
			}
		}
	}

	option = {
		name = diplomacy_family_special.2210.a
		
		add_diplomacy_lifestyle_xp = medium_lifestyle_experience
		hidden_effect = {
			scope:heir = {
				if = {
					limit = {
						can_set_relation_potential_friend_trigger = { CHARACTER = scope:vassal }
					}
					set_relation_potential_friend = scope:vassal
				}
			}
		}
		trigger_event = {
				id = diplomacy_family_special.2230
				days = { 730 1460 }
		}
	}

	after = {
		remove_character_flag = is_in_diplomacy_family_special_event
	}
}

#Vassal refuses to resolve differences with heir.
diplomacy_family_special.2211 = {
	type = character_event
	title = diplomacy_family_special.2200.t
	desc = diplomacy_family_special.2211.desc
	theme = diplomacy_family_focus
	left_portrait = scope:heir
	right_portrait = {
		character = scope:vassal
		animation = disapproval
	}

	trigger = {
		scope:heir = {
			is_alive = yes
		}
		scope:vassal = {
			is_alive = yes
		}
	}

	immediate = {
		scope:vassal = {
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = -15
			}
		}
	}

	option = {
		name = diplomacy_family_special.2211.a

		add_diplomacy_lifestyle_xp = minor_lifestyle_experience
	}

	after = {
		remove_character_flag = is_in_diplomacy_family_special_event
	}
}

#Heir is receptive to resolving differences with vassal.
diplomacy_family_special.2212 = {
	type = character_event
	title = diplomacy_family_special.2200.t
	desc = diplomacy_family_special.2212.desc
	theme = diplomacy_family_focus
	
	left_portrait = scope:heir
	right_portrait = scope:vassal

	trigger = {
		scope:heir = {
			is_alive = yes
		}
		scope:vassal = {
			is_alive = yes
		}
	}

	immediate = {
		scope:heir = {
			add_opinion = {
				target = scope:vassal
				modifier = friendliness_opinion
				opinion = 30
			}
			reverse_add_opinion = {
				target = scope:vassal
				modifier = friendliness_opinion
				opinion = 30
			}
		}
	}

	option = {
		name = diplomacy_family_special.2212.a

		add_diplomacy_lifestyle_xp = medium_lifestyle_experience

		hidden_effect = {
			scope:heir = {
				if = {
					limit = {
						can_set_relation_potential_friend_trigger = { CHARACTER = scope:vassal }
					}
					set_relation_potential_friend = scope:vassal
				}
			}
		}
		trigger_event = {
			id = diplomacy_family_special.2230
			days = { 730 1460 }
		}
	}

	after = {
		remove_character_flag = is_in_diplomacy_family_special_event
	}
}

#Heir refuses to resolve differences with vassal.
diplomacy_family_special.2213 = {
	type = character_event
	title = diplomacy_family_special.2200.t
	desc = diplomacy_family_special.2213.desc
	theme = diplomacy_family_focus
	left_portrait = {
		character = scope:heir
		animation = disapproval
	}
	right_portrait = scope:vassal

	trigger = {
		scope:heir = {
			is_alive = yes
		}
		scope:vassal = {
			is_alive = yes
		}
	}

	immediate = {
		scope:vassal = {
			add_opinion = {
				modifier = respect_opinion
				target = scope:heir
				opinion = -15
			}
		}
	}

	option = {
		name = diplomacy_family_special.2213.a

		add_diplomacy_lifestyle_xp = minor_lifestyle_experience

		hidden_effect = {
			remove_character_flag = is_in_diplomacy_family_special_event
		}
	}
}


#Heir agrees to try and change their personality.
diplomacy_family_special.2220 = {
	type = character_event
	title = diplomacy_family_special.2200.t
	desc = diplomacy_family_special.2220.desc
	theme = diplomacy_family_focus
	left_portrait = scope:heir

	trigger = {
		scope:heir = {
			is_alive = yes
		}
	}


	option = {
		name = diplomacy_family_special.2220.a

		add_diplomacy_lifestyle_xp = medium_lifestyle_experience
		custom_tooltip = diplomacy_family_special.2220.a.tt

		trigger_event = {
			id = diplomacy_family_special.2232
			days = { 730 1460 }
		}
	}

	after = {
		remove_character_flag = is_in_diplomacy_family_special_event
	}
}

#Heir refuses to behave differently.
diplomacy_family_special.2221 = {
	type = character_event
	title = diplomacy_family_special.2200.t
	desc = diplomacy_family_special.2221.desc
	theme = diplomacy_family_focus
	left_portrait = {
		character = scope:heir
		animation = disapproval
	}

	trigger = {
		scope:heir = {
			is_alive = yes
		}
	}

	option = {
		name = diplomacy_family_special.2221.a

		add_diplomacy_lifestyle_xp = minor_lifestyle_experience
		custom_tooltip = diplomacy_family_special.2201.b.failure.tt
	}

	after = {
		remove_character_flag = is_in_diplomacy_family_special_event
	}
}

#Ping event to forge a friendship if conditions are valid.
diplomacy_family_special.2230 = {
	type = character_event
	hidden = yes

	#Abort if conditons are not met.
	option = {}

	#If heir & vassal are still on good terms, forge a friendship between them.
	option = {
		trigger = {
			scope:heir = {
				opinion = {
					target = scope:vassal
					value >= 15
				}
				reverse_opinion = {
					target = scope:vassal
					value >= 15
				}
				has_relation_potential_friend = scope:vassal
			}
		}
		exclusive = yes

		trigger_event = diplomacy_family_special.2231
	}
}

#Friendship develops between heir & vassal.
diplomacy_family_special.2231 = {
	type = character_event
	title = diplomacy_family_special.2200.t
	desc = diplomacy_family_special.2231.desc
	theme = diplomacy_family_focus
	left_portrait = scope:heir
	right_portrait = scope:vassal

	trigger = {
		scope:heir = {
			is_alive = yes
		}
		scope:vassal = {
			is_alive = yes
		}
	}

	option = {
		name = diplomacy_family_special.2231.a
		hidden_effect = {
			if = {
				limit = { has_relation_potential_rival = scope:vassal }
				remove_relation_potential_rival = scope:vassal
			}
			if = {
				limit = { has_relation_rival = scope:vassal }
				remove_relation_rival = scope:vassal
			}
		}
		scope:heir = {
			if = {
				limit = { can_set_relation_friend_trigger = { CHARACTER = scope:vassal } }
				set_relation_friend = scope:vassal
			}
		}
	}
}

#Ping event to give your heir a new personality trait if conditions are still valid.
diplomacy_family_special.2232 = {
	type = character_event
	hidden = yes

	#Abort if conditons are not met.
	option = {}

	#If we can acquire our new personality trait, then do so.
	option = {
		trigger = {
			scope:heir = { personality_can_trait_shift = yes }
		}
		exclusive = yes
		trigger_event = diplomacy_family_special.2233
	}
}

#Heir develops new personality trait.
diplomacy_family_special.2233 = {
	type = character_event
	title = diplomacy_family_special.2200.t
	desc = diplomacy_family_special.2233.desc
	theme = diplomacy_family_focus
	
	left_portrait = scope:heir

	trigger = {
		scope:heir = {
			is_alive = yes
		}
	}

	option = {
		name = diplomacy_family_special.2233.a

		scope:heir = {
			personality_shift_effect = yes
		}
	}
}

#################################
# Pick Best Friend 				#
# 2200							#
# by Flavio Verna, script rewrite by Mathilda Bjarnehed 				
#################################

scripted_trigger diplomacy_family_2200_valid_friend_trigger = {
	is_ai = yes
	can_set_relation_best_friend_trigger = { CHARACTER = root }
}

diplomacy_family.2200 = {
	type = character_event
	title = diplomacy_family.2200.t
	desc = diplomacy_family.2200.desc
	theme = diplomacy_family_focus
	left_portrait = {
		character = root
		animation = happiness
	}
	lower_left_portrait = scope:friend_1
	lower_center_portrait = scope:friend_2
	lower_right_portrait = scope:friend_3

	trigger = {
		is_adult = yes
		NOT = { has_character_flag = had_diplomacy_family_2200_event }
		any_relation = {
			type = friend
			count = 3
			diplomacy_family_2200_valid_friend_trigger = yes
		}
	}

	weight_multiplier = {
		base = 1
		upweight_for_focus_modifier = { FOCUS = diplomacy_family_focus }
		modifier = {
			add = -0.25
			num_of_relation_friend <= 5
		}
	}

	immediate = {
		save_scope_as = ruler
		hidden_effect = {
			add_character_flag = {
				flag = had_diplomacy_family_2200_event
				days = 1825
			}

			while = {
				limit = { NOT = { exists = scope:friend_3 } }

				random_relation = {
					type = friend
					limit = {
						diplomacy_family_2200_valid_friend_trigger = yes
						trigger_if = {
							limit = { exists = scope:friend_1 }
							NOT = { this = scope:friend_1 }
						}
						trigger_if = {
							limit = { exists = scope:friend_2 }
							NOT = { this = scope:friend_2 }
						}
					}
					weight = {
						base = 1
						
						#Do we get along
						opinion_modifier = {
							opinion_target = root
						}
						compatibility_modifier = {
							compatibility_target = root
						}

						#Are they skilled
						modifier = {
							add = {
								value = diplomacy
								multiply = 2
								add = intrigue
								add = learning
								add = martial
								add = stewardship
							}
						}

						#Are they landed
						modifier = {
							add = {
								value = highest_held_title_tier
								multiply = 30
							}
						}
					}
					if = {
						limit = { NOT = { exists = scope:friend_1 } }
						save_scope_as = friend_1
					}
					else_if = {
						limit = { NOT = { exists = scope:friend_2 } }
						save_scope_as = friend_2
					}
					else = {
						save_scope_as = friend_3
					}
				}
			}
		}
	}


	option = {
		name = diplomacy_family.2200.a
		if = {
			limit = {
				scope:friend_1 = {
					is_ai = yes
				}
			}
			set_relation_best_friend = scope:friend_1
		}
		else = {
			custom_tooltip = diplomacy_family.2200.a.tt
			scope:friend_1 = { trigger_event = diplomacy_family.2201 }
		}
		ai_chance = {
			factor = 20
			compatibility_modifier = {
				who = scope:ruler
				compatibility_target = scope:friend_1
				min = -20
				max = 80
				multiplier = 3
			}
		}
	}
	option = {
		name = diplomacy_family.2200.b
		
		if = {
			limit = {
				scope:friend_2 = {
					is_ai = yes
				}
			}
			set_relation_best_friend = scope:friend_2
		}
		else = {
			custom_tooltip = diplomacy_family.2200.b.tt
			scope:friend_2 = { trigger_event = diplomacy_family.2201 }
		}
			
		ai_chance = {
			factor = 20
			compatibility_modifier = {
				who = scope:ruler
				compatibility_target = scope:friend_2
				min = -20
				max = 80
				multiplier = 3
			}
		}
	}
	option = {
		name = diplomacy_family.2200.c
		
		if = {
			limit = {
				scope:friend_3 = {
					is_ai = yes
				}
			}
			set_relation_best_friend = scope:friend_3
		}
		else = {
			custom_tooltip = diplomacy_family.2200.c.tt
			scope:friend_3 = { trigger_event = diplomacy_family.2201 }
		}
		
		ai_chance = {
			factor = 20
			compatibility_modifier = {
				who = scope:ruler
				compatibility_target = scope:friend_3
				min = -20
				max = 80
				multiplier = 3
			}
		}
	}
	option = {
		name = diplomacy_family.2200.d

		add_diplomacy_lifestyle_xp = medium_lifestyle_xp

		ai_chance = {
			factor = 0
		}
	}
}

# Event for friend, in case new best friend is a player.
diplomacy_family.2201 = {
	type = character_event
	title = diplomacy_family.2200.t
	desc = diplomacy_family.2201.desc
	theme = diplomacy_family_focus
	
	left_portrait = scope:ruler

	immediate = { save_scope_as = chosen_friend }

	option = {
		name = diplomacy_family.2201.a

		scope:ruler = {
			send_interface_toast = {
				left_icon = scope:chosen_friend
				set_relation_best_friend = scope:ruler
				title = diplomacy_family.2201.a.tt
			}
		}
	}

	option = {
		name = diplomacy_family.2201.b
		scope:ruler = {
			send_interface_toast = {
				left_icon = scope:chosen_friend
				title = diplomacy_family.2201.b.tt
			}
		}
	}
}



#################################
# Marriage vs Incest			#
# 2250 - 2254					#
# by Flavio Verna 				#
#################################

scripted_trigger diplomacy_family_2250_lover_trigger = {
	house = root.house
	is_married = yes
	is_ai = yes
	NOT = { is_spouse_of = root }
	primary_spouse = { is_ai = yes }
}

# When marriage gets in the way of incest...
diplomacy_family.2250 = {
	type = character_event
	title = diplomacy_family.2250.t
	desc = {
		desc = diplomacy_family.2250.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = {
					NOR = {
						relation_with_character_is_incestuous_in_faith_trigger = { CHARACTER = scope:lover FAITH = root.faith }
						AND = {
							exists = scope:spouse.dynasty
							scope:ruler.dynasty = scope:spouse.dynasty
						}
					}
				}
				desc = diplomacy_family.2250.desc.legal.pure
			}
			triggered_desc = {
				trigger = {
					NOT = {
						relation_with_character_is_incestuous_in_faith_trigger = { CHARACTER = scope:lover FAITH = root.faith }
					}
					AND = {
						exists = scope:spouse.dynasty
						scope:ruler.dynasty = scope:spouse.dynasty
					}
				}
				desc = diplomacy_family.2250.desc.legal.same
			}
			triggered_desc = {
				trigger = { relation_with_character_is_incestuous_in_faith_trigger = { CHARACTER = scope:lover FAITH = root.faith } }
				desc = diplomacy_family.2250.desc.illegal
			}
		}
	}
	theme = diplomacy_family_focus
	
	left_portrait = scope:lover
	right_portrait = scope:spouse

	trigger = {
		is_adult = yes
		is_ruler = yes
		NOT = { has_character_flag = had_diplomacy_family_2250_event }
		NOT = { has_character_flag = is_in_diplomacy_family_special_event }
		any_relation = {
			type = lover
			diplomacy_family_2250_lover_trigger = yes
		}
	}

	weight_multiplier = {
		base = 1
		upweight_for_focus_modifier = { FOCUS = diplomacy_family_focus }
		modifier = {
			add = 0.25
			# Increased chance if not even sinful.
			any_relation = {
				type = lover
				diplomacy_family_2250_lover_trigger = yes
				NOT = { relation_with_character_is_incestuous_in_faith_trigger = { CHARACTER = root FAITH = root.faith } }
			}
		}
	}

	immediate = {
		hidden_effect = {
			add_character_flag = {
				flag = had_diplomacy_family_2250_event
				years = 15
			}
			save_scope_as = ruler
			random_relation = {
				type = lover
				limit = {
					diplomacy_family_2250_lover_trigger = yes
					any_child = {
						even_if_dead = yes
						count = 0
					}
					NOT = { relation_with_character_is_incestuous_in_faith_trigger = { CHARACTER = root FAITH = root.faith } } # Prioritize acceptable ones.
				}
				alternative_limit = {
					diplomacy_family_2250_lover_trigger = yes
					NOT = { # No child comes from outside the secret romance.
						any_child = {
							even_if_dead = yes
							trigger_if = {
								limit = { scope:ruler = { is_female = no } }
								NOT = {
									real_father = scope:ruler
								}
							}
							trigger_if = {
								limit = { scope:ruler = { is_female = yes } }
								NOT = {
									mother = scope:ruler
								}
							}
						}
					}
					NOT = { relation_with_character_is_incestuous_in_faith_trigger = { CHARACTER = root FAITH = root.faith } } # Prioritize acceptable ones.
				}
				alternative_limit = {
					diplomacy_family_2250_lover_trigger = yes
					NOT = { relation_with_character_is_incestuous_in_faith_trigger = { CHARACTER = root FAITH = root.faith } } # Prioritize acceptable ones.
				}
				alternative_limit = {
					diplomacy_family_2250_lover_trigger = yes
				}
				save_scope_as = lover
				primary_spouse = { save_scope_as = spouse }
			}
			if = {
				limit = {
					exists = root.house.house_head
				}
				root.house.house_head = {
					save_scope_as = house_head
				}
			}
		}
	}

	# Intimidate Lover's Spouse
	# Start Plot to Kill
	# Demand Annullment of marriage (House Head)
	# Do Nothing.

	option = { # Intimidate Lover's Spouse
		name = diplomacy_family.2250.a
		if = {
			limit = {
				NOT = {
					has_relation_rival = scope:spouse
				}
			}
			set_relation_rival = scope:spouse
		}
		else = {
			add_opinion = {
				modifier = took_my_lover_opinion
				target = scope:spouse
			}
		}
		duel = {
			desc = diplomacy_family.2250.a.tt
			target = scope:spouse
			skill = prowess
			12 = {		
				compare_modifier = {
					value = scope:duel_value
					multiplier = 0.75
				}
					compare_modifier = {
						value = root.dread
						multiplier = 0.5
					}
				modifier = { # Much less likely to intimidate a greater ruler.
					add = -8
					highest_held_title_tier < scope:spouse.highest_held_title_tier
				}
				desc = diplomacy_family.2250.a.success.duel
				show_as_tooltip = {
					add_diplomacy_lifestyle_xp = major_lifestyle_experience
					scope:spouse = {
						add_character_modifier = {
							modifier = jealous_relative_modifier
							years = 5
						}
						stress_impact = {
							base = massive_stress_impact_gain
						}
					}
					stress_impact = {
						base = medium_stress_impact_loss
						compassionate = minor_stress_impact_gain
					}
				}
				trigger_event = diplomacy_family.2251
			}
			8 = {
				desc = diplomacy_family.2250.a.failure.duel
				if = {
				 	limit = { # If relation is incestuous, also involve the lover.
				 		relation_with_character_is_incestuous_in_faith_trigger = { CHARACTER = scope:lover FAITH = root.faith }
				 	}
					show_as_tooltip = {
						remove_relation_lover = scope:lover
						reverse_add_opinion = {
							modifier = shamed_me_opinion
							target = scope:lover
						}
						add_opinion = {
							modifier = lover_abandoned_me_opinion
							target = scope:lover
						}
						stress_impact = {
							base = medium_stress_impact_gain
							callous = minor_stress_impact_loss
						}
					}
					trigger_event = diplomacy_family.2252
				}
				else = { # Otherwise just simple rejection.
					send_interface_toast = {
						left_icon = scope:lover
						right_icon = scope:spouse
						title = diplomacy_family.2250.a.failure.tt
						add_diplomacy_lifestyle_xp = minor_lifestyle_experience
						stress_impact = {
							base = medium_stress_impact_gain
							callous = minor_stress_impact_loss
						}
					}
				}
			}
		}
		ai_chance = {
			factor = 20
			modifier = {
				add = 20
				has_trait = honest
			}
			modifier = {
				add = 20
				has_trait = wrathful
			}
			modifier = {
				add = 20
				has_trait = arrogant
			}
		}
	}
	option = { # Start plot to assassinate spouse.
		name = {
			trigger = {
				any_scheme = {
					scheme_type = murder
					scheme_target = scope:spouse
				}
			}
			text = diplomacy_family.2250.b.a
		}
		name = {
			trigger = {
				can_start_scheme = {
					type = murder
					target = scope:spouse
				}
			}
			text = diplomacy_family.2250.b.b
		}
		trigger = {
			OR = {
				any_scheme = {
					scheme_type = murder
					scheme_target = scope:spouse
				}
				can_start_scheme = {
					type = murder
					target = scope:spouse
				}
			}
		}
		add_diplomacy_lifestyle_xp = miniscule_lifestyle_experience
		if = {
			limit = {
				NOT = {
					any_scheme = {
						scheme_type = murder
						scheme_target = scope:spouse
					}
				}
			}
			start_scheme = {
				target = scope:spouse
				type = murder
			}
		}
		custom_tooltip = diplomacy_family.2250.b.tt
		hidden_effect = {
			random_scheme = {
				limit = {
					scheme_type = murder
					scheme_target = scope:spouse
				}
				add_scheme_modifier = {
					type = vengeful_lover_kin_modifier
				}
				save_scope_as = murder_scheme
			}
		}
		if = {
			limit = { # Spouse joins in automatically.
				scope:lover = {
					OR = {
						has_personality_malicious_trigger = yes
						opinion = {
							target = scope:spouse
							value <= medium_negative_opinion
						}
					}
				}
			}
			custom_tooltip = diplomacy_family.2250.b.spouse_joining
			if = {
				limit = {
					exists = scope:murder_scheme # Will not exist before th option is picked.
				}
				scope:lover = {
					force_add_to_scheme = {
						scheme = scope:murder_scheme
						years = 15
					}
				}
			}
		}
		else = {
			custom_tooltip = diplomacy_family.2250.b.spouse_refusing
			hidden_effect = {
				scope:lover = {
					set_variable = {
						name = murder_scheme_disinterest
						value = scope:spouse
						days = 300
					}
				}
			}
		}
		ai_chance = {
			factor = 5
			modifier = {
				add = 50
				has_trait = sadistic
			}
			modifier = {
				add = 20
				has_trait = deceitful
			}
			modifier = {
				add = 10
				has_trait = craven
			}
		}
	}
	option = { # Tell the House Head // Act as the House Head.
		name = {
			trigger = { NOT = { root = scope:house_head } }
			text = diplomacy_family.2250.c.a
		}
		name = {
			trigger = { root = scope:house_head }
			text = diplomacy_family.2250.c.b
		}
		flavor = diplomacy_family.2250.c.flavor	
		trigger = {
			exists = scope:house_head
			NOT = { relation_with_character_is_incestuous_in_faith_trigger = { CHARACTER = scope:lover FAITH = root.faith } } # Only if it's not incestuous.
			OR = { # And the current spouse must be an outsider.
				NOT = {
					exists = scope:spouse.dynasty
				}
				AND = {
					exists = scope:spouse.dynasty
					NOT = {
						scope:spouse.dynasty = scope:ruler.dynasty
					}
				}
			}
			scope:house_head.faith = { # And if the House Head interaction conditions are met for spouse and lover.
				has_doctrine = doctrine_divorce_approval
			}
			NAND = {
				exists = scope:house_head.faith.religious_head
				scope:house_head.faith = {
					has_doctrine = doctrine_spiritual_head
				}
			}
			scope:lover = { is_diplomatically_available = yes }
			scope:spouse = { is_diplomatically_available = yes }
			NOT = {
				scope:spouse = { has_strong_hook = scope:house_head }
			}
		}
		add_diplomacy_lifestyle_xp = medium_lifestyle_experience
		root.dynasty = { add_dynasty_prestige = miniscule_dynasty_prestige_loss }
		if = {
			limit = {
				 scope:house_head = {
					can_add_hook = {
						type = favor_hook
						target = scope:ruler
		 			}
	 			}
 			}
			scope:house_head = {
				add_hook = {
					type = favor_hook
					target = scope:ruler
				}
			}
 		}
		scope:lover = {
			divorce_effect = {
				DIVORCER = scope:lover
				DIVORCEE = scope:spouse
			}
		}
		scope:spouse = {
			add_opinion = {
				modifier = forced_divorce_opinion
				target = scope:ruler
			}
			every_close_or_extended_family_member = {
				custom = all_family_members
				limit = {
					NOR = {
						this = scope:ruler
						this = scope:house_head
						this = scope:lover
					}
				}
				add_opinion = {
					modifier = divorced_close_kin
					target = scope:ruler
				}
			}
		}
		# How does the lover react?
		hidden_effect = {
			if = {
				limit = { # If she hates the previous spouse...
					scope:lover = {
						opinion = {
							target = scope:spouse
							value <= low_negative_opinion
						}
						opinion = {
							target = scope:ruler
							value > neutral_opinion
						}
					}
				}
				trigger_event = diplomacy_family.2253
			}
			else = { # Lover is upset by dynastic meddling.
				trigger_event = diplomacy_family.2254
			}
		}
		ai_chance = {
			factor = 25
			modifier = {
				add = 20
				has_trait = craven
			}
			modifier = {
				add = 10
				has_trait = shy
			}
		}
	}

	option = { # Nothing.
		name = diplomacy_family.2250.d
		stress_impact = {
			base = minor_stress_impact_gain
			arrogant = minor_stress_impact_gain
			lustful = medium_stress_impact_gain
			humble = minor_stress_impact_loss
		}
		ai_chance = {
			factor = 5
		}
	}
}

# Successfully cowered the spouse.
diplomacy_family.2251 = {
	type = character_event
	title = diplomacy_family.2250.t
	desc = diplomacy_family.2251.desc
	theme = diplomacy_family_focus
	left_portrait = {
		character = scope:lover
		animation = fear
	}
	right_portrait = scope:spouse

	immediate = {
		add_diplomacy_lifestyle_xp = medium_lifestyle_experience
		scope:spouse = {
			add_character_modifier = {
				modifier = jealous_relative_modifier
				years = 5
			}
			stress_impact = {
				base = medium_stress_impact_gain
			}
		}
	}
	option = {
		name = diplomacy_family.2251.a
		stress_impact = {
			base = medium_stress_impact_loss
			compassionate = minor_stress_impact_gain
		}
	}
}

# Failed to cower the spouse and caused the lover to get upset.
diplomacy_family.2252 = {
	type = character_event
	title = diplomacy_family.2250.t
	desc = diplomacy_family.2252.desc
	theme = diplomacy_family_focus
	left_portrait = {
		character = scope:lover
		animation = angry
	}
	right_portrait = scope:spouse

	immediate = {
		remove_relation_lover = scope:lover
		reverse_add_opinion = {
			modifier = shamed_me_opinion
			target = scope:lover
		}
		add_opinion = {
			modifier = lover_abandoned_me_opinion
			target = scope:lover
		}
	}
	option = {
		name = diplomacy_family.2252.a
		stress_impact = {
			base = medium_stress_impact_gain
			callous = minor_stress_impact_loss
		}
	}
}

# Lover is happy to be rid of spouse and thanks ruler.
diplomacy_family.2253 = {
	type = character_event
	title = diplomacy_family.2250.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { NOT = { root = scope:house_head } }
				desc = diplomacy_family.2253.desc.a
			}
			triggered_desc = {
				trigger = { root = scope:house_head }
				desc = diplomacy_family.2253.desc.b
			}
		}
	}
	theme = diplomacy_family_focus
	left_portrait = {
		character = scope:lover
		animation = love
	}
	right_portrait = {
		character = scope:spouse
		animation = sadness
	}

	option = { # Let's marry!
		name = diplomacy_family.2253.a
		trigger = {
			NOT = { relation_with_character_is_incestuous_in_faith_trigger = { CHARACTER = scope:lover FAITH = root.faith } }
			can_marry_character_trigger = { CHARACTER = scope:lover }
		}
		if = {
			limit = { is_female = no }
			root = { marry = scope:lover }
		}
		if = {
			limit = { is_female = yes }
			root = { marry_matrilineal = scope:lover }
		}
	}

	option = { # Good.
		name = diplomacy_family.2253.b
		root.dynasty = { add_dynasty_prestige = minor_dynasty_prestige_gain }
	}
}

# Lover is upset over the break-up.
diplomacy_family.2254 = {
	type = character_event
	title = diplomacy_family.2250.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { NOT = { root = scope:house_head } }
				desc = diplomacy_family.2254.desc.a
			}
			triggered_desc = {
				trigger = { root = scope:house_head }
				desc = diplomacy_family.2254.desc.b
			}
		}
	}
	theme = diplomacy_family_focus
	
	left_portrait = {
		character = scope:lover
		animation = rage
	}
	right_portrait = {
		character = scope:spouse
		animation = sadness
	}

	option = { # Smooth deflection.
		name = diplomacy_family.2254.a
		trigger = {
			diplomacy >= medium_skill_rating
		}
		skill = diplomacy
		add_prestige = minor_prestige_loss
		root.dynasty = { add_dynasty_prestige = miniscule_dynasty_prestige_gain }
	}

	option = { # I see...
		name = diplomacy_family.2254.b
		root.dynasty = { add_dynasty_prestige = medium_dynasty_prestige_loss }
		remove_relation_lover = scope:lover
		reverse_add_opinion = {
			modifier = shamed_me_opinion
			target = scope:lover
		}
	}
}

#################################
# Problematic Dynasty Member	#
# 2300 - 2301					#
# by Flavio Verna 				#
#################################

scripted_trigger diplomacy_family_2300_relative_trigger = {
	NOT = { this = root }
	NOT = { is_dynast = yes }
	NOT = { is_house_head = yes }
	is_adult = yes
	age <= 25
	prestige_level < 3
	OR = {
		probably_unintelligent_trigger = yes
		AND = {
			diplomacy <= mediocre_skill_rating
			martial <= mediocre_skill_rating
			stewardship <= mediocre_skill_rating
			intrigue <= mediocre_skill_rating
			learning <= mediocre_skill_rating
		}
		has_trait = hunchbacked
		has_trait = dwarf
		AND = {
			root = {
				NOR = {
					has_trait = bastard
					has_trait = legitimized_bastard
					is_parent_of = prev
				}
			}
			OR = {
				has_trait = bastard
				has_trait = legitimized_bastard
			}
		}
	}
}
scripted_trigger diplomacy_family_2300_agent_trigger = {
	is_available_ai_adult = yes
	is_imprisoned = no
	NOR = {
		this = root
		this = scope:bad_relative
	}
	opinion = {
		target = scope:bad_relative
		value <= neutral_opinion
	}
	opinion = {
		target = root
		value >= neutral_opinion
	}
	is_valid_as_agent_in_scheme = scope:murder_scheme
	has_personality_benevolent_trigger = no
}

# Concerned about a disappointing family member.
diplomacy_family.2300 = {
	type = character_event
	title = diplomacy_family.2300.t
	desc = {
		desc = diplomacy_family.2300.desc.intro
		random_valid = {
			triggered_desc = {
				trigger = {
					scope:bad_relative = {
						probably_unintelligent_trigger = yes
					}
				}
				desc = diplomacy_family.2300.desc.a
			}
			triggered_desc = {
				trigger = {
					scope:bad_relative = {
						diplomacy <= mediocre_skill_rating
						martial <= mediocre_skill_rating
						stewardship <= mediocre_skill_rating
						intrigue <= mediocre_skill_rating
						learning <= mediocre_skill_rating
					}
				}
				desc = diplomacy_family.2300.desc.b
			}
			triggered_desc = {
				trigger = {
					scope:bad_relative = {
						OR = {
							has_trait = hunchbacked
							has_trait = dwarf
						}
					}
				}
				desc = diplomacy_family.2300.desc.c
			}
			triggered_desc = {
				trigger = {
					exists = scope:bad_parent
					scope:bad_relative = {
						OR = {
							has_trait = bastard
							has_trait = legitimized_bastard
						}
					}
				}
				desc = diplomacy_family.2300.desc.d
			}
		}
	}
	theme = diplomacy_family_focus
	left_portrait = scope:bad_relative

	trigger = {
		is_adult = yes
		is_ruler = yes
		NOT = { has_character_flag = had_diplomacy_family_2300_event }
		NOT = { has_character_flag = is_in_diplomacy_family_special_event }
		probably_unintelligent_trigger = no
		has_personality_benevolent_trigger = no
		calc_true_if = {
			amount >= 2
			diplomacy >= mediocre_skill_rating
			martial >= mediocre_skill_rating
			stewardship >= mediocre_skill_rating
			intrigue >= mediocre_skill_rating
			learning >= mediocre_skill_rating
		}
		exists = dynasty
		dynasty = {
			any_dynasty_member = {
				diplomacy_family_2300_relative_trigger = yes
			}
		}
	}

	weight_multiplier = {
		base = 1
		upweight_for_focus_modifier = { FOCUS = diplomacy_family_focus }
		modifier = {
			add = 0.1
			has_personality_malicious_trigger = yes
		}
	}

	immediate = {
		hidden_effect = {
			add_character_flag = {
				flag = had_diplomacy_family_2300_event
				years = 5
			}
			save_scope_as = ruler
			dynasty = {
				random_dynasty_member = {
					limit = {
						diplomacy_family_2300_relative_trigger = yes
						exists = root.player_heir
						this = root.player_heir
						diplomacy <= mediocre_skill_rating
						martial <= mediocre_skill_rating
						stewardship <= mediocre_skill_rating
						intrigue <= mediocre_skill_rating
						learning <= mediocre_skill_rating
					}
					alternative_limit = {
						diplomacy_family_2300_relative_trigger = yes
						diplomacy <= mediocre_skill_rating
						martial <= mediocre_skill_rating
						stewardship <= mediocre_skill_rating
						intrigue <= mediocre_skill_rating
						learning <= mediocre_skill_rating
					}
					alternative_limit = {
						diplomacy_family_2300_relative_trigger = yes
					}
					weight = {
						base = 1
						modifier = {
							add = 5
							OR = {
								has_trait = bastard
								has_trait = legitimized_bastard
							}
						}
						modifier = {
							add = 5
							OR = {
								has_trait = hunchbacked
								has_trait = dwarf
							}
						}
						modifier = {
							add = 5
							probably_unintelligent_trigger = yes
						}
						modifier = {
							add = 5
							prestige_level < 2
						}
						modifier = {
							add = 5
							has_relation_rival = root
						}
						modifier = {
							add = -1
							diplomacy >= decent_skill_rating
						}
						modifier = {
							add = -1
							martial >= decent_skill_rating
						}
						modifier = {
							add = -1
							stewardship >= decent_skill_rating
						}
						modifier = {
							add = -1
							intrigue >= decent_skill_rating
						}
						modifier = {
							add = -1
							learning >= decent_skill_rating
						}
					}
					save_scope_as = bad_relative
				}
			}
		}
		if = { # For flavor purposes only, pick the dynastic parent of the relative, if illegitimate.
			limit = {
				exists = scope:bad_relative.father
				scope:bad_relative.father.dynasty = root.dynasty
			}
			scope:bad_relative.father = { save_scope_as = bad_parent }
		}
		if = { # For flavor purposes only, pick the dynastic parent of the relative, if illegitimate.
			limit = {
				exists = scope:bad_relative.mother
				scope:bad_relative.mother.dynasty = root.dynasty
			}
			scope:bad_relative.mother = { save_scope_as = bad_parent }
		}
	}

	# Try to improve them.
	# Plot their death.
	# Denounce/Disinherit if Dynast.
	# Do nothing.

	option = { # Try to improve them.
		name = diplomacy_family.2300.a
		trigger = {
			OR = {
				diplomacy >= scope:bad_relative.diplomacy
				martial >= scope:bad_relative.martial
				stewardship >= scope:bad_relative.stewardship
				intrigue >= scope:bad_relative.intrigue
				learning >= scope:bad_relative.learning
			}
		}
		duel = {
			skill = learning
			value = average_skill_rating
			16 = {		
				compare_modifier = {
					value = scope:duel_value
					multiplier = 0.5
					min = -15
				}
				desc = diplomacy_family.2300.a.success.tt
				show_as_tooltip = {
					add_diplomacy_lifestyle_xp = medium_lifestyle_experience
					custom_tooltip = diplomacy_family.2300.a.success.effect.tt
				}
				trigger_event = diplomacy_family.2301
			}
			12 = {		
				compare_modifier = {
					value = scope:duel_value
					multiplier = -0.5
					min = -11
				}
				desc = diplomacy_family.2300.a.failure.tt
				send_interface_toast = {
					left_icon = scope:bad_relative
					title = diplomacy_family.2300.a.failure.toast
					dynasty = {
						add_dynasty_prestige = minor_dynasty_prestige_loss
					}
				}
			}
		}
		stress_impact = {
			base = minor_stress_gain
			shy = minor_stress_gain
			wrathful = minor_stress_gain
			patient = minor_stress_loss
		}
		ai_chance = {
			base = 50
			ai_compassion_target_modifier = { VALUE = 50 }
			ai_vengefulness_target_modifier = { VALUE = -50 }
			modifier = {
				add = -20
				has_trait = lazy #Just kill him...
			}
			modifier = {
				add = 30
				is_parent_of = scope:bad_relative
			}
		}
	}

	option = { # Plot their death.
		name = {
			trigger = {
				any_scheme = {
					scheme_type = murder
					scheme_target = scope:bad_relative
				}
			}
			text = diplomacy_family.2300.b.a
		}
		name = {
			trigger = {
				can_start_scheme = {
					type = murder
					target = scope:bad_relative
				}
			}
			text = diplomacy_family.2300.b.b
		}
		trigger = {
			OR = {
				any_scheme = {
					scheme_type = murder
					scheme_target = scope:bad_relative
				}
				can_start_scheme = {
					type = murder
					target = scope:bad_relative
				}
			}
		}
		add_diplomacy_lifestyle_xp = miniscule_lifestyle_experience
		if = {
			limit = {
				NOT = {
					any_scheme = {
						scheme_type = murder
						scheme_target = scope:bad_relative
					}
				}
			}
			start_scheme = {
				target = scope:bad_relative
				type = murder
			}
		}
		custom_tooltip = diplomacy_family.2250.b.tt
		hidden_effect = {
			random_scheme = {
				limit = {
					scheme_type = murder
					scheme_target = scope:bad_relative
				}
				add_scheme_modifier = {
					type = trimming_dynasty_modifier
				}
				save_scope_as = murder_scheme
			}
		}
		if = {
			limit = {
				exists = scope:murder_scheme
				dynasty = {
					any_dynasty_member = {
						diplomacy_family_2300_agent_trigger = yes
					}
				}
			}
			dynasty = {
				every_dynasty_member = {
					limit = {
						diplomacy_family_2300_agent_trigger = yes
					}
					force_add_to_scheme = {
						scheme = scope:murder_scheme
						years = 10
					}
				}
			}
		}
		stress_impact = {
			compassionate = medium_stress_gain
		}
		ai_chance = {
			base = 75
			ai_compassion_target_modifier = { VALUE = -75 }
			ai_vengefulness_target_modifier = { VALUE = 50 }
			modifier = {
				add = -10
				is_parent_of = scope:bad_relative
			}
		}
	}
	option = { # Denounce/Disinherit if Dynast.
		name = diplomacy_family.2300.c
		trigger = {
			is_dynast = yes
			root.faith = scope:bad_relative.faith
			scope:bad_relative = {
				NOR = {
					has_trait = bastard
					has_trait = disinherited
				}
				is_diplomatically_available = yes
				NOT = { has_strong_hook = root }
			}
		}
		flavor = diplomacy_family.2300.c.flavor	
		add_diplomacy_lifestyle_xp = minor_lifestyle_experience
		scope:bad_relative = {
			add_trait = disinherited
			add_opinion = {
				modifier = disinherited_opinion
				target = scope:ruler
			}
			if = {
				limit = {
					NOT = { is_close_family_of = scope:ruler }
				}
				house = {
					every_house_member = {
						limit = {
							NOT = { house = scope:ruler.house }
						}
						custom = all_house_members
						add_opinion = {
							modifier = disinherited_house_member_opinion
							target = scope:ruler
						}
					}
				}
				
			}
		}
		scope:ruler.dynasty = { # Thee tree is being trimmed, so prestige is gained rather than lost.
			add_dynasty_prestige = medium_dynasty_prestige_gain
		}
		ai_chance = {
			base = 75
			ai_compassion_target_modifier = { VALUE = -20 }
			ai_vengefulness_target_modifier = { VALUE = 50 }
		}
	}

	option = { # Do nothing.
		name = diplomacy_family.2300.d
		reverse_add_opinion = {
			modifier = kindness_opinion
			target = scope:bad_relative
			opinion = 10
		}
		stress_impact = {
			callous = minor_stress_gain
			sadistic = medium_stress_gain
		}
		ai_chance = {
			base = 50
			ai_compassion_target_modifier = { VALUE = 50 }
			ai_vengefulness_target_modifier = { VALUE = -50 }
		}
	}
}

# Successfully improved on the bad relative.
diplomacy_family.2301 = {
	type = character_event
	title = diplomacy_family.2300.t
	desc = diplomacy_family.2301.desc
	theme = diplomacy_family_focus
	
	left_portrait = scope:bad_relative

	immediate = {
		hidden_effect = {
			random_list = {
				10 = {
					trigger = {
						diplomacy >= scope:bad_relative.diplomacy
					}
					add_character_flag = flag_diplomacy_family_2301_diplomacy
				}
				10 = {
					trigger = {
						martial >= scope:bad_relative.martial
					}
					add_character_flag = flag_diplomacy_family_2301_martial
				}
				10 = {
					trigger = {
						stewardship >= scope:bad_relative.stewardship
					}
					add_character_flag = flag_diplomacy_family_2301_stewardship
				}
				10 = {
					trigger = {
						intrigue >= scope:bad_relative.intrigue
					}
					add_character_flag = flag_diplomacy_family_2301_intrigue
				}
				10 = {
					trigger = {
						learning >= scope:bad_relative.learning
					}
					add_character_flag = flag_diplomacy_family_2301_learning
				}
			}
		}
	}

	option = {
		name = diplomacy_family.2301.a
		add_diplomacy_lifestyle_xp = medium_lifestyle_experience
		if = {
			limit = {
				has_character_flag = flag_diplomacy_family_2301_diplomacy
			}
			scope:bad_relative = {
				add_diplomacy_skill = 3
			}
		}
		else_if = {
			limit = {
				has_character_flag = flag_diplomacy_family_2301_martial
			}
			scope:bad_relative = {
				add_martial_skill = 3
			}
		}
		else_if = {
			limit = {
				has_character_flag = flag_diplomacy_family_2301_stewardship
			}
			scope:bad_relative = {
				add_stewardship_skill = 3
			}
		}
		else_if = {
			limit = {
				has_character_flag = flag_diplomacy_family_2301_intrigue
			}
			scope:bad_relative = {
				add_intrigue_skill = 3
			}
		}
		else_if = {
			limit = {
				has_character_flag = flag_diplomacy_family_2301_learning
			}
			scope:bad_relative = {
				add_learning_skill = 3
			}
		}
		if = {
			limit = {
				has_character_flag = flag_diplomacy_family_2301_diplomacy
			}
			remove_character_flag = flag_diplomacy_family_2301_diplomacy
		}
		else_if = {
			limit = {
				has_character_flag = flag_diplomacy_family_2301_martial
			}
			remove_character_flag = flag_diplomacy_family_2301_martial
		}
		else_if = {
			limit = {
				has_character_flag = flag_diplomacy_family_2301_stewardship
			}
			remove_character_flag = flag_diplomacy_family_2301_stewardship
		}
		else_if = {
			limit = {
				has_character_flag = flag_diplomacy_family_2301_intrigue
			}
			remove_character_flag = flag_diplomacy_family_2301_intrigue
		}
		else_if = {
			limit = {
				has_character_flag = flag_diplomacy_family_2301_learning
			}
			remove_character_flag = flag_diplomacy_family_2301_learning
		}
	}
}

