namespace = bp1_yearly

scripted_trigger appropriate_family_memory = {
	has_memory_category = family
	has_memory_category = positive
	any_memory_participant = {
		house ?= root.house
		NOT = {
			has_relation_rival = root
		}
		trigger_if = {
			limit = {
				is_alive = no
				exists = killer
			}
			killer != root
		}
	}
}

# Reflect over a family memory
bp1_yearly.4000 = {
	type = character_event
	content_source = dlc_006
	title = bp1_yearly.4000.t
	desc = {
		desc = bp1_yearly.4000.desc
		first_valid = {
			triggered_desc = {
				trigger = { 
					scope:family_memory_participant = { is_alive = yes }
				}
				desc = bp1_yearly.4000.desc.alive
			}
			desc = bp1_yearly.4000.desc.dead
		}
		desc = bp1_yearly.4000.desc_end
	}
	
	theme = family

	override_background = {
		trigger = {
			is_landed = yes
		}
		reference = corridor_day
	}
	override_background = {
		trigger = {
			is_landed = no
		}
		reference = bp1_bonfire
	}
	override_background = {
		trigger = {
			has_government = nomad_government
		}
		reference = mpo_campfire_steppe
	}
	
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = { 
				scope:family_memory_participant = { is_alive = yes }
			}
  			animation = happiness
  		}
		triggered_animation = {
			trigger = { 
				scope:family_memory_participant = { is_alive = no }
			}
  			animation = grief
  		}
	}
	
	right_portrait = {
		character = scope:family_memory_participant
		triggered_animation = {
			trigger = { 
				scope:family_memory_participant = { is_alive = yes }
			}
  			animation = happiness
  		}
		triggered_animation = {
			trigger = { 
				scope:family_memory_participant = { is_alive = no }
			}
  			animation = pain
  		}
	}
	
	cooldown = { years = 5 }
	
	trigger = {
		has_bp1_dlc_trigger = yes
		exists = root.house
		stress > 0
		NOR = {
			# Not a psychopath
			has_trait = callous
			has_trait = sadistic
		}
		any_memory = {
			appropriate_family_memory = yes
		}
	}
	
	immediate = {		
		random_memory = {
			limit = {
				appropriate_family_memory = yes
			}
			save_scope_as = family_memory
			random_memory_participant = {
				limit = {
					house ?= root.house
					NOT = {
						has_relation_rival = root
					}
					trigger_if = {
						limit = {
							is_alive = no
							exists = killer
						}
						killer != root
					}
				}
				save_scope_as = family_memory_participant
			}
		}
	}
	
	option = {
		name = bp1_yearly.4000.family_first
		trait = family_first
		trigger = {
			has_trait = family_first
		}
		dynasty = { add_dynasty_prestige = minor_dynasty_prestige_gain }
		stress_impact = {
			base = minor_stress_impact_loss
			#honest = minor_stress_impact_gain
			#compassionate = minor_stress_impact_gain
		}
		ai_chance = {
			base = 1000
		}
	}
	
	option = {
		name = bp1_yearly.4000.a
		trigger = {
			scope:family_memory_participant = {
				is_alive = no
			}
		}
		stress_impact = {
			base = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
		}
	}
	
	option = {
		name = bp1_yearly.4000.b
		trigger = {
			scope:family_memory_participant = {
				is_alive = yes
			}
		}
		stress_impact = {
			base = miniscule_stress_impact_loss
		}
		ai_chance = {
			base = 100
		}
	}
	
	option = {
		name = bp1_yearly.4000.c
		trigger = {
			scope:family_memory_participant = {
				is_alive = no
			}
		}
		duel = {
			skill = diplomacy
			value = 10
			50 = {
				desc = bp1_yearly.4000.c.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				save_scope_as = success_poem
				trigger_event = bp1_yearly.4001
				show_as_tooltip = {
					add_stress = minor_stress_impact_loss
					every_close_family_member = {
						custom = yearly_persian.1101.every_family
						limit = { this != root }
						add_opinion = {
							modifier = pleased_opinion
							opinion = 30
							target = root
						}
					}
				}
			}
			50 = {
				desc = bp1_yearly.4000.c.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				save_scope_as = fail_poem
				trigger_event = bp1_yearly.4001
				show_as_tooltip = {
					add_stress = medium_stress_impact_gain
				}
			}
		}
		stress_impact = {
			shy = major_stress_impact_gain
			cynical = medium_stress_impact_gain
			arrogant = minor_stress_impact_gain
			deceitful = minor_stress_impact_gain
			lazy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = shy
					has_trait = cynical
				}
			}
		}
	}
	
	option = {
		name = bp1_yearly.4000.d
		trigger = {
			scope:family_memory_participant = {
				is_alive = yes
			}
		}
		pay_short_term_gold = {
			target = scope:family_memory_participant
			gold = minor_gold_value
		}
		scope:family_memory_participant = {
			progress_towards_friend_effect = {
				CHARACTER = root
				OPINION = 0
				REASON = friend_gift_house
			}
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 30
			}
		}
		
		stress_impact = {
			base = minor_stress_impact_loss
			greedy = major_stress_impact_gain
			arrogant = minor_stress_impact_gain
			arbitrary = minor_stress_impact_gain
		}
		ai_chance = {
			base = 25
			modifier = {
				factor = 0
				gold < major_gold_value
			}
			modifier = {
				factor = 0
				OR = {
					has_trait = greedy
					has_trait = honest
					has_trait = arbitrary
				}
			}
		}
	}
}

# Family poem
bp1_yearly.4001 = {
	type = character_event
	content_source = dlc_006
	title = bp1_yearly.4000.t
	desc = {
		desc = bp1_yearly.4001.desc
		first_valid = {
			triggered_desc = {
				trigger = { 
					exists = scope:success_poem
				}
				desc = bp1_yearly.4001.desc.success_poem
			}
			desc = bp1_yearly.4001.desc.fail_poem
		}
	}
	
	theme = family
	
	override_background = { reference = corridor_day }
	
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = { 
				exists = scope:success_poem
			}
  			animation = chancellor
  		}
		triggered_animation = {
			trigger = { 
				exists = scope:fail_poem
			}
  			animation = stress
  		}
	}
	
	right_portrait = {
		character = scope:family_memory_participant
		triggered_animation = {
			trigger = { 
				scope:family_memory_participant = { is_alive = yes }
			}
  			animation = happiness
  		}
		triggered_animation = {
			trigger = { 
				scope:family_memory_participant = { is_alive = no }
			}
  			animation = pain
  		}
	}
	
	immediate = {
		select_poem_subject_gender_effect = {
			SUBJECT = flag:specific
			SUBJECT_TARGET = scope:family_memory_participant
		}
		select_poem_theme_mourning_effect = yes
	}
	
	option = {
		name = bp1_yearly.4001.a
		trigger = {
			exists = scope:success_poem
		}
		add_stress = minor_stress_impact_loss
		every_close_family_member = {
			custom = yearly_persian.1101.every_family
			limit = { this != root }
			add_opinion = {
				modifier = pleased_opinion
				opinion = 30
				target = root
			}
		}
		if = {
			limit = {
				NOT = {
					has_trait = lifestyle_poet
				}
			}
			random = {
				chance = 20
				add_trait = lifestyle_poet
			}
		}
	}
	
	option = {
		name = bp1_yearly.4001.b
		trigger = {
			exists = scope:fail_poem
		}
		add_stress = medium_stress_impact_gain
	}
}

scripted_trigger appropriate_mother = {
	mother ?= {
		appropriate_other_parent_trigger = yes
	}
}

scripted_trigger appropriate_father = {
	father ?= {
		appropriate_other_parent_trigger = yes
	}
}

scripted_trigger disliked_guardian_trigger = {
	NOR = {
		this = scope:child_other_parent
		has_relation_friend = scope:child_other_parent
		has_relation_lover = scope:child_other_parent
		reverse_opinion = {
			target = scope:child_other_parent
			value >= 60
		}
	}
	OR = {
		has_relation_rival = scope:child_other_parent
		reverse_opinion = {
			target = scope:child_other_parent
			value <= -30
		}
		has_trait = intellect_bad
		learning < 8
		AND = {
			has_trait = sadistic
			scope:child_other_parent = {
				NOT = {
					has_trait = sadistic
				}
			}
		}
	}
}

scripted_trigger appropriate_other_parent_trigger = {
	this != root
	is_spouse_of = root
	is_courtier_of = root
	is_available_ai_adult = yes
	save_temporary_scope_as = child_other_parent
	OR = {
		any_relation = {
			type = friend
			OR = {
				desired_guardian_trigger = yes
				any_courtier = {
					desired_guardian_trigger = yes
				}
				any_councillor = {
					desired_guardian_trigger = yes
				}
			}
		}
		any_relation = {
			type = lover
			OR = {
				desired_guardian_trigger = yes
				any_courtier = {
					desired_guardian_trigger = yes
				}
				any_councillor = {
					desired_guardian_trigger = yes
				}
			}
		}
		any_close_family_member = {
			desired_guardian_trigger = yes
		}
		root = {
			any_courtier = {
				desired_guardian_trigger = yes
			}
		}
		root = {
			any_councillor = {
				desired_guardian_trigger = yes
			}
		}
	}
}

scripted_trigger desired_guardian_trigger = {
	is_physically_able_adult = yes
	num_of_relation_ward < 2
	OR = {
		is_ruler = yes
		exists = liege
	}
	reverse_opinion = {
		target = scope:child_other_parent
		value >= 30
	}
	NOR = {
		this = root
		this = scope:child_other_parent
		has_trait = sadistic
		has_relation_rival = scope:child_other_parent
		reverse_opinion = {
			target = scope:child_other_parent
			value <= -30
		}
		has_trait = intellect_bad
		learning < 8
	}
	OR = {
		learning >= 12
		has_trait = intellect_good
		has_relation_friend = scope:child_other_parent
		has_relation_lover = scope:child_other_parent
	}
}

scripted_trigger appropriate_guardian_child_trigger = {
	age <= 12
	is_physically_able = yes
	exists = liege
	NOT = {
		has_character_flag = replaced_guardian
	}
	OR = {
		AND = {
			OR = {
				root.faith = { has_doctrine = doctrine_gender_male_dominated }
				NOR = {
					root.faith = { has_doctrine = doctrine_gender_male_dominated }
					root.faith = { has_doctrine = doctrine_gender_female_dominated }
				}
			}
			appropriate_mother = yes
			any_relation = { type = guardian }
			any_relation = {
				type = guardian
				disliked_guardian_trigger = yes
			}
		}
		AND = {
			OR = {
				root.faith = { has_doctrine = doctrine_gender_female_dominated }
				NOR = {
					root.faith = { has_doctrine = doctrine_gender_male_dominated }
					root.faith = { has_doctrine = doctrine_gender_female_dominated }
				}
			}
			appropriate_father = yes
			any_relation = { type = guardian }
			any_relation = {
				type = guardian
				disliked_guardian_trigger = yes
			}
		}
	}
}

scripted_effect select_new_guardian_effect = {
	every_relation = {
		type = friend
		if = {
			limit = {
				desired_guardian_trigger = yes
			}
			add_to_list = proposed_guardians
		}
		every_courtier = {
			limit = {
				desired_guardian_trigger = yes
			}
			add_to_list = proposed_guardians
		}
		every_councillor = {
			limit = {
				desired_guardian_trigger = yes
			}
			add_to_list = proposed_guardians
		}
	}
	every_relation = {
		type = lover
		if = {
			limit = {
				desired_guardian_trigger = yes
			}
			add_to_list = proposed_guardians
		}
		every_courtier = {
			limit = {
				desired_guardian_trigger = yes
			}
			add_to_list = proposed_guardians
		}
		every_councillor = {
			limit = {
				desired_guardian_trigger = yes
			}
			add_to_list = proposed_guardians
		}
	}
	every_close_family_member = {
		limit = {
			desired_guardian_trigger = yes
		}
		add_to_list = proposed_guardians
	}
	root = {
		every_courtier = {
			limit = {
				desired_guardian_trigger = yes
			}
			add_to_list = proposed_guardians
		}
		every_councillor = {
			limit = {
				desired_guardian_trigger = yes
			}
			add_to_list = proposed_guardians
		}
	}
	random_in_list = {
		list = proposed_guardians
		weight = {
			base = 1
			modifier = {
				add = 5
				OR = {
					has_relation_friend = scope:child_other_parent
					has_relation_lover = scope:child_other_parent
				}
			}
			modifier = {
				add = 5
				this.dynasty = scope:child_other_parent.dynasty
			}
			modifier = {
				add = 2
				has_education_rank_4_trigger = yes
			}
			modifier = {
				add = 1
				has_education_rank_3_trigger = yes
			}
		}
		save_scope_as = proposed_guardian
	}
}

# Spouse demands their child gets a better guardian
bp1_yearly.4010 = {
	type = character_event
	content_source = dlc_006
	title = bp1_yearly.4010.t
	desc = {
		desc = bp1_yearly.4010.desc
		first_valid = {
			triggered_desc = {
				trigger = { 
					scope:current_guardian = {
						this = root
					}
				}
				desc = bp1_yearly.4010.desc.root
			}
			desc = bp1_yearly.4010.desc.other
		}
		desc = bp1_yearly.4010.desc_end
	}
	
	theme = family
	
	override_background = { reference = throne_room }
	
	left_portrait = {
		character = scope:parent_that_want_guardian_change
		animation = worry
	}
	
	right_portrait = {
		character = scope:child_to_change_guardian
		animation = personality_irrational
	}
	
	lower_left_portrait = scope:proposed_guardian
	lower_right_portrait = scope:current_guardian
	
	cooldown = { years = 5 }
	
	trigger = {
		trigger_if = {
			limit = {
				is_ai = yes
			}
			has_trait = family_first
		}
		has_bp1_dlc_trigger = yes
		any_child = {
			appropriate_guardian_child_trigger = yes
		}
	}
	
	immediate = {
		random_child = {
			limit = {
				appropriate_guardian_child_trigger = yes
			}
			save_scope_as = child_to_change_guardian
			if = {
				limit = {
					OR = {
						root.faith = { has_doctrine = doctrine_gender_male_dominated }
						NOR = {
							root.faith = { has_doctrine = doctrine_gender_male_dominated }
							root.faith = { has_doctrine = doctrine_gender_female_dominated }
						}
					}
					appropriate_mother = yes
					any_relation = { type = guardian }
					any_relation = {
						type = guardian
						disliked_guardian_trigger = yes
					}
				}
				mother = {
					save_scope_as = parent_that_want_guardian_change
				}
			}
			else = {
				father = {
					save_scope_as = parent_that_want_guardian_change
				}
			}
			random_relation = {
				type = guardian
				save_scope_as = current_guardian
			}
			scope:parent_that_want_guardian_change = {
				save_temporary_scope_as = child_other_parent
				select_new_guardian_effect = yes
			}
		}
		
		scope:child_to_change_guardian = {
			save_scope_as = ward
			scope:proposed_guardian = { save_scope_as = guardian }
			scope:child_to_change_guardian.liege = { save_scope_as = ward_liege }
			scope:proposed_guardian.liege = { save_scope_as = guardian_liege }
		}
		hidden_effect = {
			scope:parent_that_want_guardian_change = {
				progress_towards_rival_effect = {
					CHARACTER = scope:current_guardian
					REASON = rival_guardian_change
					OPINION = 0
				}
				add_opinion = {
					target = scope:current_guardian
					modifier = annoyed_opinion
					opinion = -30
				}
				random = { # Become full-on rivals
					chance = 25
					progress_towards_rival_effect = {
						CHARACTER = scope:current_guardian
						REASON = rival_guardian_change
						OPINION = 0
					}
				}
			}
		}
	}
	
	option = {
		name = bp1_yearly.4010.c
		trait = family_first
		trigger = {
			has_trait = family_first
		}
		custom_tooltip = bp1_yearly.4010.c_effect
		hidden_effect = {
			scope:child_to_change_guardian = {
				education_point_acquisition_effect = yes
				education_point_acquisition_effect = yes
			}
		}
		scope:parent_that_want_guardian_change = {
			add_opinion = {
				target = root
				modifier = relieved_opinion
				opinion = 30
			}
		}
		ai_chance = {
			base = 1000
		}
	}
	
	option = { # Agree to switch guardians
		name = bp1_yearly.4010.a
		
		remove_guardian_effect = {
			GUARDIAN = scope:current_guardian
			WARD = scope:child_to_change_guardian
			RETURN_WARD = no
			HIDE_OPINION = yes
		}
		if = {
			limit = {
				scope:child_to_change_guardian.liege != root
				scope:current_guardian = {
					is_ruler = no
				}
			}
			scope:child_to_change_guardian.liege = {
				add_opinion = {
					modifier = insulted_opinion
					target = root
					opinion = -30
				}
			}
		}
		scope:current_guardian = {
			if = {
				limit = {
					this != root
				}
				add_opinion = {
					modifier = insult_opinion
					target = root
					opinion = -30
				}
			}
		}

		educate_child_event_effect = yes

		hidden_effect = {
			send_interface_message = {
				type = event_childhood_neutral
				title = educate_child_interaction_notification
				left_icon = scope:guardian
				right_icon = scope:ward
				show_as_tooltip = {
					educate_child_event_effect = yes
				}
			}
		}
		
		scope:parent_that_want_guardian_change = {
			add_opinion = {
				target = root
				modifier = relieved_opinion
				opinion = 30
			}
		}
		
		scope:child_to_change_guardian = {
			random = {
				chance = {
					value = 0
					add = scope:proposed_guardian.learning
					multiply = 4
				}
				custom_tooltip = bp1_yearly.4010.a_effect
				hidden_effect = {
					education_point_acquisition_effect = yes
				}
			}
		}
		
		hidden_effect = {
			scope:proposed_guardian = {
				add_character_flag = replaced_guardian
				if = { # Chance of ulterior motives
					limit = {
						can_add_hook = {
							type = loyalty_hook
							target = scope:child_to_change_guardian
						}
					}
					random = {
						chance = {
							value = 0
							add = scope:proposed_guardian.intrigue
							multiply = 2
						}
						add_hook = {
							type = loyalty_hook
							target = scope:child_to_change_guardian
						}
					}
				}
			}
		}
		
		stress_impact = {
			arrogant = medium_stress_impact_gain
			stubborn = medium_stress_impact_gain
			paranoid = medium_stress_impact_gain
		}
		ai_chance = {
			base = 75
			modifier = {
				factor = 0
				OR = {
					has_trait = arrogant
					has_trait = stubborn
					has_trait = paranoid
				}
			}
		}
	}
	
	option = {
		name = bp1_yearly.4010.b
		name = {
			trigger = { scope:current_guardian = { this != root } }
			text = bp1_yearly.4010.b
		}
		name = {
			trigger = { scope:current_guardian = { this = root } }
			text = bp1_yearly.4010.b_alt
		}
		
		scope:parent_that_want_guardian_change = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -25
			}
		}
		stress_impact = {
			trusting = massive_stress_impact_gain
			compassionate = medium_stress_impact_gain
			fickle = medium_stress_impact_gain
		}
		ai_chance = {
			base = 25
			modifier = {
				factor = 0
				OR = {
					has_trait = trusting
					has_trait = compassionate
					has_trait = fickle
				}
			}
		}
	}
}

bp1_yearly.4020 = { # Friend commissions a piece of poetry commemorating one of your victories
	type = character_event
	content_source = dlc_006
	title = bp1_yearly.4020.t
	desc = bp1_yearly.4020.desc
	
	theme = friend_relation
	
	override_background = { reference = garden }
	
	left_portrait = {
		character = root
		animation = happiness
	}
	
	right_portrait = {
		character = scope:poetry_friend
		animation = chancellor
	}
	
	artifact = { # To display the artifact in the event-window
	    target = scope:newly_created_artifact
	    position = lower_center_portrait
	}
	
	lower_right_portrait = scope:war_memory_participant
	
	cooldown = { years = 25 }
	
	trigger = {
		has_bp1_dlc_trigger = yes
		any_relation = {
			type = friend
			is_available_ai_adult = yes
			OR = {
				has_trait = lifestyle_poet
				diplomacy >= 8
			}
			save_temporary_scope_as = friend_check
		}
		any_memory = {
			memory_type = war_won
			NOT = {
				any_memory_participant = {
					this = scope:friend_check
				}
			}
			any_memory_participant = {
				this != root
			}
		}
	}
	
	immediate = {
		random_relation = {
			type = friend
			limit = {
				is_available_ai_adult = yes
				OR = {
					has_trait = lifestyle_poet
					diplomacy >= 8
				}
			}
			weight = {
				base = 1
				modifier = {
					add = 100
					has_trait = lifestyle_poet
				}
				modifier = {
					add = 10
					is_of_major_interest_to_root_trigger = yes
				}
				modifier = {
					add = 5
					is_of_minor_interest_to_root_trigger = yes
				}
				modifier = {
					add = diplomacy
				}
			}
			if = {
				limit = {
					NOT = {
						has_trait = lifestyle_poet
					}
				}
				random = {
					chance = {
						value = diplomacy
						multiply = 2
					}
					add_trait = lifestyle_poet
				}
			}
			save_scope_as = poetry_friend
		}	
		random_memory = {
			memory_type = war_won
			limit = {
				NOT = {
					any_memory_participant = {
						this = scope:poetry_friend
					}
				}
				any_memory_participant = {
					this != root
				}
			}
			save_scope_as = war_memory
			random_memory_participant = {
				limit = {
					NOR = {
						this = scope:poetry_friend
						this = root
					}
				}
				save_scope_as = war_memory_participant
			}
		}
		scope:poetry_friend = {
			select_poem_subject_gender_effect = {
				SUBJECT = flag:specific
				SUBJECT_TARGET = root
			}
			select_poem_theme_strife_effect = yes
		}
		hidden_effect_new_object = {
			create_artifact_poetry_effect = { OWNER = root }
			scope:newly_created_artifact = {
				save_scope_as = poetry_artifact
			}
		}
	}
	
	option = {
		name = bp1_yearly.4020.a
		
		trigger = {
			has_royal_court = yes
		}
		
		scope:poetry_friend = {
			if = {
				limit = {
					can_set_relation_best_friend_trigger = { CHARACTER = root }
				}
				set_relation_best_friend = { reason = best_friend_poetry copy_reason = friend target = root }
			}
			add_opinion = {
				target = root
				modifier = flattered_opinion
				opinion = 30
			}
		}
		
		custom_tooltip = bp1_yearly.4020.a_effect
		
		remove_short_term_gold = minor_gold_value
		
		hidden_effect_new_object = {
			scope:newly_created_artifact = {
				add_scaled_artifact_modifier_grandeur_small_effect = yes
				
				reforge_artifact = {
					type = pedestal
				}
			}
		}
		
		stress_impact = {
			greedy = minor_stress_impact_gain
			shy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				gold < major_gold_value
			}
			modifier = {
				factor = 0
				OR = {
					has_trait = greedy
					has_trait = shy
				}
			}
		}
	}
	
	option = {
		name = bp1_yearly.4020.b
		
		scope:poetry_friend = {
			add_opinion = {
				target = root
				modifier = friendliness_opinion
				opinion = 15
			}
		}
		
		custom_tooltip = bp1_yearly.4020.b_effect
		
		ai_chance = {
			base = 100
		}
	}
	
	option = {
		name = bp1_yearly.4020.c
		
		trigger = {
			exists = scope:war_memory_participant
			scope:war_memory_participant = {
				is_alive = yes
			}
		}
		
		add_prestige = major_prestige_gain
		
		scope:war_memory_participant = {
			progress_towards_rival_effect = {
				CHARACTER = root
				REASON = rival_war_memory
				OPINION = 0
			}
			add_opinion = {
				target = root
				modifier = annoyed_opinion
				opinion = -30
			}
		}
		
		custom_tooltip = bp1_yearly.4020.b_effect
		
		stress_impact = {
			forgiving = massive_stress_impact_gain
			compassionate = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = forgiving
					has_trait = compassionate
				}
			}
		}
	}
	
	option = {
		name = bp1_yearly.4020.d
		
		destroy_artifact = scope:newly_created_artifact
		
		add_piety = major_piety_gain
		
		scope:poetry_friend = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -15
			}
		}
		
		stress_impact = {
			arrogant = massive_stress_impact_gain
			cynical = medium_stress_impact_gain
			ambitious = minor_stress_impact_gain
		}
		ai_chance = {
			base = 25
			modifier = {
				factor = 0
				OR = {
					has_trait = arrogant
					has_trait = cynical
					has_trait = ambitious
				}
			}
		}
	}
}

scripted_trigger marriage_rival_trigger = {
	is_available_ai_adult = yes
	is_married = no
	is_concubine = no
	can_marry_trigger = yes
	OR = {
		is_male = yes
		age <= 40
	}
	
	OR = {
		has_trait = seducer
		has_trait = schemer
		has_trait = diplomat
		has_trait = lustful
		has_trait = vengeful
		has_trait = ambitious
		has_trait = beauty_good
		has_trait = physique_good
		intrigue >= 10
		diplomacy >= 10
	}
	
	NOR = {
		has_trait = honest
		AND = {
			exists = dynasty
			exists = root.dynasty
			dynasty = root.dynasty
		}
		is_child_of = root
		is_grandchild_of = root
		is_great_grandchild_of = root
	}
	
	save_temporary_scope_as = rival_check
}

scripted_trigger appopriate_vassal_trigger = {
	primary_title.tier >= tier_county
	is_available_ai_adult = yes
	OR = {
		AND = {
			exists = scope:rival_check
			is_attracted_to_gender_of = scope:rival_check
		}
		AND = {
			exists = scope:marriage_rival
			is_attracted_to_gender_of = scope:marriage_rival
		}
	}
	OR = {
		AND = {
			exists = scope:rival_check
			could_marry_character_trigger = { CHARACTER = scope:rival_check }
		}
		AND = {
			exists = scope:marriage_rival
			could_marry_character_trigger = { CHARACTER = scope:marriage_rival }
		}
	}
	
	NOR = {
		has_trait = content
		has_trait = chaste
		has_trait = loyal
		AND = {
			exists = scope:rival_check
			this = scope:rival_check
		}
		AND = {
			exists = scope:marriage_rival
			this = scope:marriage_rival
		}
		AND = {
			exists = dynasty
			exists = root.dynasty
			dynasty = root.dynasty
		}
		has_relation_rival = root
		has_relation_friend = root
		has_relation_lover = root
		is_child_of = root
		is_grandchild_of = root
		is_great_grandchild_of = root
		AND = {
			primary_spouse ?= {
				OR = {
					is_child_of = root
					is_grandchild_of = root
					is_great_grandchild_of = root
					AND = {
						exists = dynasty
						exists = root.dynasty
						dynasty = root.dynasty
					}
				}
			}
		}
		AND = {
			betrothed ?= {
				OR = {
					is_child_of = root
					is_grandchild_of = root
					is_great_grandchild_of = root
					AND = {
						exists = dynasty
						exists = root.dynasty
						dynasty = root.dynasty
					}
				}
			}
		}
	}
}

bp1_yearly.4030 = { # Rival nestles their way into marrying one of your vassals, turns them disloyal
	type = character_event
	content_source = dlc_006
	title = bp1_yearly.4030.t
	desc = {
		desc = bp1_yearly.4030.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:spurned_partner
				}
				desc = bp1_yearly.4030.desc_bond_broken
			}
			desc = bp1_yearly.4030.desc_no_broken_bonds
		}
		desc = bp1_yearly.4030.desc_end
	}
	
	theme = rival_relation
	
	override_background = { reference = throne_room }
	
	left_portrait = {
		character = scope:marriage_rival
		animation = scheme
	}
	
	right_portrait = {
		character = scope:marriage_vassal
		animation = flirtation
	}
	
	lower_right_portrait = scope:spurned_partner
	
	cooldown = { years = 25 }
	
	trigger = {
		has_bp1_dlc_trigger = yes
		any_relation = {
			type = rival
			marriage_rival_trigger = yes
		}
		any_vassal = {
			appopriate_vassal_trigger = yes
		}
	}
	
	immediate = {
		random_relation = {
			type = rival
			limit = {
				marriage_rival_trigger = yes
			}
			weight = {
				base = 1
				modifier = {
					add = 10
					is_of_major_interest_to_root_trigger = yes
				}
				modifier = {
					add = 5
					is_of_minor_interest_to_root_trigger = yes
				}
			}
			save_scope_as = marriage_rival
		}
		random_vassal = {
			limit = {
				appopriate_vassal_trigger = yes
			}
			weight = {
				base = 1
				modifier = {
					add = 1000
					is_married = no
				}
				modifier = {
					add = 10
					is_of_major_interest_to_root_trigger = yes
				}
				modifier = {
					add = 5
					is_of_minor_interest_to_root_trigger = yes
				}
			}
			save_scope_as = marriage_vassal
		}
		
		scope:marriage_vassal = {
			if = {
				limit = {
					is_married = yes
				}
				primary_spouse = {
					save_scope_as = spurned_partner
					hidden_effect = {
						add_opinion = {
							modifier = divorced_me_opinion
							target = scope:marriage_vassal
						}
					}
				}
				divorce = primary_spouse
			}
			else_if = {
				limit = {
					is_betrothed = yes
				}
				betrothed = {
					save_scope_as = spurned_partner
					hidden_effect = {
						add_opinion = {
							modifier = broke_betrothal_opinion
							target = scope:marriage_vassal
						}
					}
				}
				break_betrothal = betrothed
			}
			
			if = {
				limit = {
					is_female = yes
					scope:marriage_rival = {
						is_lowborn = yes
					}
				}
				marry_matrilineal = scope:marriage_rival
			}
			else = {
				marry = scope:marriage_rival
			}
			add_trait = disloyal
			add_opinion = {
				modifier = distrustful
				target = root
			}
		}
	}
	
	option = {
		name = bp1_yearly.4030.a
		
		duel = {
			skill = diplomacy
			value = scope:marriage_vassal.diplomacy

			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}

				desc = bp1_yearly.4030.a.success
				
				send_interface_toast = {
					title = bp1_yearly.4030.a.success
					left_icon = scope:marriage_vassal
					scope:marriage_vassal = {
						remove_opinion = {
							target = root
							modifier = distrustful
						}
						remove_trait = disloyal
						add_trait_force_tooltip = loyal
					}
				}
			}
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}

				desc = bp1_yearly.4030.a.failure
				
				send_interface_toast = {
					title = bp1_yearly.4030.a.failure
					left_icon = scope:marriage_vassal
					scope:marriage_vassal = {
						progress_towards_rival_effect = {
							CHARACTER = root
							REASON = rival_seduced_vassal
							OPINION = 0
						}
					}
				}
			}
		}
		
		stress_impact = {
			shy = medium_stress_impact_gain
			forgiving = medium_stress_impact_gain
			content = minor_stress_impact_gain
			humble = minor_stress_impact_gain
			trusting = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = greedy
					has_trait = forgiving
				}
			}
		}
	}
	
	option = {
		name = bp1_yearly.4030.b
		
		trigger = {
			exists = scope:spurned_partner
		}
		
		duel = {
			skill = learning
			value = scope:marriage_vassal.learning

			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}

				desc = bp1_yearly.4030.b.success
				
				send_interface_toast = {
					title = bp1_yearly.4030.b.success
					left_icon = scope:marriage_vassal
					scope:marriage_vassal = {
						remove_opinion = {
							target = root
							modifier = distrustful
						}
						remove_trait = disloyal
						add_piety_level = -2
						divorce = scope:marriage_rival
					}
				}
			}
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}

				desc = bp1_yearly.4030.b.failure
				
				send_interface_toast = {
					title = bp1_yearly.4030.b.failure
					left_icon = scope:marriage_vassal
					scope:marriage_vassal = {
						progress_towards_rival_effect = {
							CHARACTER = root
							REASON = rival_seduced_vassal
							OPINION = 0
						}
					}
				}
			}
		}
		
		stress_impact = {
			cynical = medium_stress_impact_gain
			arrogant = medium_stress_impact_gain
			content = minor_stress_impact_gain
			trusting = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = cynical
					has_trait = arrogant
				}
			}
		}
	}
	
	option = {
		name = bp1_yearly.4030.c
		
		trigger = {
			exists = scope:spurned_partner
		}
		
		scope:spurned_partner = {
			scope:marriage_vassal = { save_scope_as = relationship_reason_involved_character }
			progress_towards_friend_effect = {
				CHARACTER = root
				OPINION = 0
				REASON = friend_supported_me_against_spouse
			}
			clear_saved_scope = relationship_reason_involved_character
			if = {
				limit = {
					can_set_relation_rival_trigger = { CHARACTER = scope:marriage_rival }
				}
				set_relation_rival = {
					target = scope:marriage_rival
					reason = rival_abandoned_marriage
				}
			}
			if = {
				limit = {
					can_set_relation_rival_trigger = { CHARACTER = scope:marriage_vassal }
				}
				set_relation_rival = {
					target = scope:marriage_vassal
					reason = rival_abandoned_marriage
				}
			}
			add_opinion = {
				opinion = -40
				modifier = hate_opinion
				target = scope:marriage_rival
			}
			add_opinion = {
				opinion = -40
				modifier = hate_opinion
				target = scope:marriage_vassal
			}
		}
		if = {
			limit = {
				can_add_hook = {
					target = scope:spurned_partner
					type = loyalty_hook
				}
			}
			add_hook = {
				target = scope:spurned_partner
				type = loyalty_hook
			}
		}
		
		stress_impact = {
			honest = medium_stress_impact_gain
			paranoid = medium_stress_impact_gain
			shy = minor_stress_impact_gain
			impatient = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = honest
					has_trait = paranoid
				}
			}
		}
	}
	
	option = {
		name = bp1_yearly.4030.d
		
		stress_impact = {
			brave = medium_stress_impact_gain
			wrathful = medium_stress_impact_gain
			vengeful = medium_stress_impact_gain
			diligent = minor_stress_impact_gain
			impatient = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = brave
					has_trait = wrathful
					has_trait = vengeful
				}
			}
		}
	}
}

bp1_yearly.4040 = { # Kindly grandmother won't stop feeding you snacks; suffer the consequences of overeating, or break her heart?
	type = character_event
	content_source = dlc_006
	title = bp1_yearly.4040.t
	desc = {
		random_valid = {
			triggered_desc = { # Intro desc
				trigger = {
					scope:kindly_grandmother = {
						is_alive = yes
					}
					exists = var:food_fed_by_grandmother
					var:food_fed_by_grandmother <= 1
				}
				desc = bp1_yearly.4040.desc.intro.1
			}
			triggered_desc = { # Another snack? Nice!
				trigger = {
					scope:kindly_grandmother = {
						is_alive = yes
					}
					exists = var:food_fed_by_grandmother
					var:food_fed_by_grandmother <= 2
					var:food_fed_by_grandmother > 1
				}
				desc = bp1_yearly.4040.desc.intro.2
			}
			triggered_desc = { # It's getting a bit much
				trigger = {
					scope:kindly_grandmother = {
						is_alive = yes
					}
					exists = var:food_fed_by_grandmother
					var:food_fed_by_grandmother <= 4
					var:food_fed_by_grandmother > 2
				}
				desc = bp1_yearly.4040.desc.feeding.1
			}
			triggered_desc = { # It's getting a bit much
				trigger = {
					scope:kindly_grandmother = {
						is_alive = yes
					}
					exists = var:food_fed_by_grandmother
					var:food_fed_by_grandmother <= 4
					var:food_fed_by_grandmother > 2
				}
				desc = bp1_yearly.4040.desc.feeding.2
			}
			triggered_desc = { # It's getting insane
				trigger = {
					scope:kindly_grandmother = {
						is_alive = yes
					}
					exists = var:food_fed_by_grandmother
					var:food_fed_by_grandmother > 4
				}
				desc = bp1_yearly.4040.desc.feeding.3
			}
			triggered_desc = { # It's getting insane
				trigger = {
					scope:kindly_grandmother = {
						is_alive = yes
					}
					exists = var:food_fed_by_grandmother
					var:food_fed_by_grandmother > 4
				}
				desc = bp1_yearly.4040.desc.feeding.4
			}
			triggered_desc = { # It's getting insane
				trigger = {
					scope:kindly_grandmother = {
						is_alive = no
					}
				}
				desc = bp1_yearly.4040.desc.dead
			}
		}
	}
	
	theme = family
	
	override_background = { reference = bp1_kitchen_western }
	
	left_portrait = {
		character = root
		
		triggered_animation = {
			trigger = { 
				scope:kindly_grandmother = {
					is_alive = yes
				}
				exists = var:food_fed_by_grandmother
				var:food_fed_by_grandmother <= 1
			}
  			animation = ecstasy
  		}
		
		triggered_animation = {
			trigger = { 
				scope:kindly_grandmother = {
					is_alive = yes
				}
				exists = var:food_fed_by_grandmother
				var:food_fed_by_grandmother <= 2
				var:food_fed_by_grandmother > 1
			}
  			animation = happiness
  		}
		
		triggered_animation = {
			trigger = { 
				scope:kindly_grandmother = {
					is_alive = yes
				}
				var:food_fed_by_grandmother <= 4
				var:food_fed_by_grandmother > 2
			}
  			animation = worry
  		}
		
		triggered_animation = {
			trigger = { 
				scope:kindly_grandmother = {
					is_alive = yes
				}
				exists = var:food_fed_by_grandmother
				var:food_fed_by_grandmother > 4
			}
  			animation = disbelief
  		}
		
		triggered_animation = {
			trigger = { 
				scope:kindly_grandmother = {
					is_alive = no
				}
			}
  			animation = grief
  		}
	}
	
	right_portrait = {
		character = scope:kindly_grandmother
		
		triggered_animation = {
			trigger = { 
				scope:kindly_grandmother = {
					is_alive = yes
				}
			}
  			animation = love
  		}
		
		triggered_animation = {
			trigger = { 
				scope:kindly_grandmother = {
					is_alive = no
				}
			}
  			animation = pain
  		}
	}
	
	lower_right_portrait = scope:spurned_partner
	
	trigger = {
		has_bp1_dlc_trigger = yes
		age >= 6
		OR = {
			exists = scope:kindly_grandmother
			AND = {
				NOT = {
					has_character_flag = had_grandmother_event
				}
				any_close_family_member = {
					is_available_ai_adult = yes
					OR = {
						is_grandparent_of = root
						is_great_grandparent_of = root
					}
					ai_rationality <= 0
					ai_compassion >= 0
					is_ruler = no
					is_married = no
					is_concubine = no
					NOR = {
						has_trait = sadistic
						has_trait = callous
						has_relation_rival = root
					}
				}
			}
		}
	}
	
	immediate = {
		set_favorite_treat_effect = yes
		add_character_flag = had_grandmother_event
		if = {
			limit = {
				NOT = {
					exists = scope:kindly_grandmother
				}
			}
			random_close_family_member = {
				limit = {
					is_available_ai_adult = yes
					OR = {
						is_grandparent_of = root
						is_great_grandparent_of = root
					}
					ai_rationality <= 0
					ai_compassion >= 0
					is_ruler = no
					is_married = no
					is_concubine = no
					NOR = {
						has_trait = sadistic
						has_trait = callous
						has_relation_rival = root
					}
				}
				save_scope_as = kindly_grandmother
			}
		}
		hidden_effect = {
			if = {
				limit = {
					scope:kindly_grandmother = {
						is_alive = yes
						is_ruler = no
						NOT = {
							is_courtier_of = root
						}
					}
				}
				add_courtier = scope:kindly_grandmother
			}
			if = {
				limit = {
					NOT = { has_variable = food_fed_by_grandmother }
				}
				set_variable = {
					name = food_fed_by_grandmother
					value = 1
				}
			}
		}
	}
	
	option = {
		name = bp1_yearly.4040.family_first
		
		trait = family_first
		trigger = {
			has_trait = family_first
			scope:kindly_grandmother = {
				is_alive = yes
			}
		}
		
		add_stress = medium_stress_impact_loss
		
		scope:kindly_grandmother = {
			add_opinion = {
				target = root
				modifier = love_opinion
				opinion = 50
			}
		}
		
		ai_chance = {
			base = 100
		}
	}
	
	option = {
		name = bp1_yearly.4040.dead
		
		add_stress = miniscule_stress_impact_gain
		
		trigger = {
			scope:kindly_grandmother = {
				is_alive = no
			}
		}
		
		ai_chance = {
			base = 100
		}
	}
	
	option = {
		name = bp1_yearly.4040.a
		fallback = yes
		
		trigger = {
			exists = var:food_fed_by_grandmother
			var:food_fed_by_grandmother <= 1
		}
		
		hidden_effect = {
			change_current_weight = 20
			change_variable = {
				name = food_fed_by_grandmother
				add = 1
			}
			trigger_event = {
				id = bp1_yearly.4040
				days = { 50 150 }
			}
		}
		
		scope:kindly_grandmother = {
			add_opinion = {
				target = root
				modifier = love_opinion
				opinion = 20
			}
		}
		
		stress_impact = {
			base = medium_stress_impact_loss
			temperate = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				has_trait = temperate
			}
		}
	}
	
	option = {
		name = bp1_yearly.4040.b
		
		trigger = {
			exists = var:food_fed_by_grandmother
			var:food_fed_by_grandmother <= 1
		}
		
		scope:kindly_grandmother = {
			add_stress = minor_stress_impact_gain
			if = {
				limit = {
					has_opinion_modifier = {
						target = root
						modifier = love_opinion
					}
				}
				remove_opinion = {
					target = root
					modifier = love_opinion
				}
			}
		}
		
		stress_impact = {
			compassionate = medium_stress_impact_gain
			trusting = medium_stress_impact_gain
			gregarious = medium_stress_impact_gain
			comfort_eater = medium_stress_impact_gain
			gluttonous = medium_stress_impact_gain
			greedy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			modifier = {
				factor = 0
				OR = {
					has_trait = compassionate
					has_trait = trusting
					has_trait = gregarious
					has_trait = comfort_eater
					has_trait = gluttonous
					has_trait = greedy
				}
			}
		}
	}
	
	option = {
		name = bp1_yearly.4040.c
		
		trigger = {
			scope:kindly_grandmother = {
				is_alive = yes
			}
			exists = var:food_fed_by_grandmother
			var:food_fed_by_grandmother <= 4
			var:food_fed_by_grandmother > 1
		}
		
		hidden_effect = {
			change_current_weight = 20
			change_variable = {
				name = food_fed_by_grandmother
				add = 1
			}
			trigger_event = {
				id = bp1_yearly.4040
				days = { 50 150 }
			}
		}
		
		scope:kindly_grandmother = {
			add_opinion = {
				target = root
				modifier = love_opinion
				opinion = 20
			}
		}
		
		stress_impact = {
			base = minor_stress_impact_loss
			temperate = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				has_trait = temperate
			}
		}
	}
	
	option = {
		name = bp1_yearly.4040.d
		
		trigger = {
			scope:kindly_grandmother = {
				is_alive = yes
			}
			exists = var:food_fed_by_grandmother
			var:food_fed_by_grandmother <= 4
			var:food_fed_by_grandmother > 1
		}
		
		scope:kindly_grandmother = {
			add_stress = {
				value = medium_stress_impact_gain
				multiply = root.var:food_fed_by_grandmother
			}
			if = {
				limit = {
					has_opinion_modifier = {
						target = root
						modifier = love_opinion
					}
				}
				remove_opinion = {
					target = root
					modifier = love_opinion
				}
			}
		}
		
		stress_impact = {
			comfort_eater = medium_stress_impact_gain
			gluttonous = medium_stress_impact_gain
			compassionate = minor_stress_impact_gain
			trusting = minor_stress_impact_gain
			gregarious = minor_stress_impact_gain
			greedy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			modifier = {
				factor = 0
				OR = {
					has_trait = comfort_eater
					has_trait = gluttonous
				}
			}
		}
	}
	
	option = {
		name = bp1_yearly.4040.e
		
		trigger = {
			scope:kindly_grandmother = {
				is_alive = yes
			}
			exists = var:food_fed_by_grandmother
			var:food_fed_by_grandmother > 4
		}
		
		hidden_effect = {
			change_current_weight = 20
			change_variable = {
				name = food_fed_by_grandmother
				add = 1
			}
			trigger_event = {
				id = bp1_yearly.4040
				days = { 50 150 }
			}
		}
		
		scope:kindly_grandmother = {
			add_opinion = {
				target = root
				modifier = love_opinion
				opinion = 20
			}
		}
		
		stress_impact = {
			base = -1
			temperate = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				has_trait = temperate
			}
		}
	}
	
	option = {
		name = bp1_yearly.4040.f
		
		trigger = {
			scope:kindly_grandmother = {
				is_alive = yes
			}
			exists = var:food_fed_by_grandmother
			var:food_fed_by_grandmother > 4
		}
		
		scope:kindly_grandmother = {
			add_stress = {
				value = medium_stress_impact_gain
				multiply = root.var:food_fed_by_grandmother
			}
			if = {
				limit = {
					has_opinion_modifier = {
						target = root
						modifier = love_opinion
					}
				}
				remove_opinion = {
					target = root
					modifier = love_opinion
				}
			}
			add_opinion = {
				target = root
				modifier = heartbroken_opinion
				opinion = -50
			}
		}
		
		stress_impact = {
			comfort_eater = medium_stress_impact_gain
			gluttonous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50
			modifier = {
				factor = 0
				OR = {
					has_trait = comfort_eater
					has_trait = gluttonous
				}
			}
		}
	}
}
