
namespace = peasant_affair

#Events for the peasant affair Story Cycle


#Save and/or create child
peasant_affair.0001 = {
	hidden = yes

	trigger = {
		scope:story.var:peasant_character = { is_alive = yes }
	}

	immediate = {
		save_scope_as = story_owner
		if = {
			limit = { exists = capital_province }
			capital_province = { save_scope_as = location }
		}
		else = {
			location = { save_scope_as = location }
		}
		scope:story = {
			if = {
				limit = {
					exists = var:child_age_variable
				}
				create_character = {
					location = scope:location
					age = var:child_age_variable
					gender_female_chance = 50
					trait = bastard
					mother = var:peasant_character
					real_father = scope:story.story_owner
					faith = var:peasant_character.faith
					#culture/dynasty etc. same as var:peasant_character
					save_scope_as = peasant_child
				}
				set_variable = {
					name = peasant_child
					value = scope:peasant_child
				}
				var:peasant_character = {
					add_secret = {
						type = secret_unmarried_illegitimate_child
						target = scope:peasant_child
						save_scope_as = peasant_child_secret
					}
				}
			}
			else_if = {
				limit = {
					scope:story_owner = {
						any_child = {
							real_father = {
								this = scope:story.var:peasant_character
							}
						}
					}
				}
				scope:story_owner = {
					random_child = {
						limit = {
							real_father = {
								this = scope:story.var:peasant_character
							}
						}
						save_scope_as = peasant_child
						scope:story = {
							set_variable = {
								name = peasant_child
								value = scope:peasant_child
							}
						}
					}
				}
			}
		}
	}
	
	after = {
		if = {
			limit = {
				exists = scope:peasant_child_secret
				exists = scope:peasant_child
			}
			scope:peasant_child_secret = {
				reveal_to = scope:peasant_child
			}
		}
	}
}


###########################
# PEASANT SHOWS UP AT COURT
# 1001-1999
###########################

#The peasant shows up at court
#by Linnéa Thimrén
peasant_affair.1001 = {
	type = character_event
	title = peasant_affair.1001.t
	desc = {
		desc = peasant_affair.1001.desc_opening
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:peasant_child
					scope:peasant_child = {
						is_in_the_same_court_as = root
					}
				}
				desc = peasant_affair.1001.desc_child
			}
			triggered_desc = {
				trigger = {
					exists = scope:peasant_child
				}
				desc = peasant_affair.1001.desc_their_child
			}
			triggered_desc = {
				trigger = {
					exists = scope:story.var:rakish_night
				}
				desc = peasant_affair.1001.desc_rakish_night
			}
			desc = peasant_affair.1001.desc
		}
	}
	theme = seduction
	override_background = {
		event_background = throne_room
	}
	left_portrait = scope:peasant_character
	right_portrait = scope:peasant_child

	trigger = {
		scope:story.var:peasant_character = {
			is_alive = yes
			is_ruler = no
		}
		is_ruler = yes
	}

	immediate = {
		remove_character_flag = is_looking_for_peasant
		scope:story = {
			var:peasant_character = {
				save_scope_as = peasant_character
			}
			if = {
				limit = {
					exists = var:peasant_child
				}
				var:peasant_child = {
					save_scope_as = peasant_child
				}
				if = {
					limit = {
						var:peasant_child.mother = var:peasant_character
						var:peasant_character = {
							any_secret = {
								secret_type = secret_unmarried_illegitimate_child
								secret_target = scope:story.var:peasant_child
							}
						}
					}
					var:peasant_character = {
						random_secret = {
							limit = {
								secret_type = secret_unmarried_illegitimate_child
								secret_target = {
									this = scope:story.var:peasant_child
								}
							}
							save_scope_as = peasant_child_secret
							reveal_to = root
						}
					}
				}
				if = {
					limit = {
						var:peasant_child.real_father = var:peasant_character
						root = {
							any_secret = {
								OR = {
									secret_type = secret_unmarried_illegitimate_child
									secret_type = secret_disputed_heritage
								}
								secret_target = scope:story.var:peasant_child
							}
						}
					}
					root = {
						random_secret = {
							limit = {
								OR = {
									secret_type = secret_unmarried_illegitimate_child
									secret_type = secret_disputed_heritage
								}
								secret_target = scope:story.var:peasant_child
							}
							save_scope_as = peasant_child_secret
							reveal_to = scope:story.var:peasant_character
						}
					}
				}
			}
		}
		if = {
			limit = {
				is_married = yes
			}
			random_spouse = {
				save_scope_as = spouse
			}
		}
	}

	option = { #you're welcome to stay
		name = {
			trigger = {
				NOR = {
					opinion = {
						target = scope:peasant_character
						value <= 0
					}
					has_trait = callous
					has_trait = arrogant
				}
			}
			text = peasant_affair.1001.a_1
		}
		name = {
			trigger = {
				OR = {
					opinion = {
						target = scope:peasant_character
						value <= 0
					}
					has_trait = callous
					has_trait = arrogant
				}
			}
			text = peasant_affair.1001.a_2
		}
		add_courtier = scope:peasant_character
		add_character_flag = peasant_appeared_at_court
		if = {
			limit = {
				exists = scope:peasant_child
				scope:peasant_child = {
					NOT = { is_in_the_same_court_as = root }
				}
			}
			add_courtier = scope:peasant_child
		}
		scope:peasant_character = {
			add_opinion = {
				modifier = kindness_opinion
				target = root
				opinion = 20
			}
		}
		if = {
			limit = {
				is_married = no
			}
			stress_impact = {
				lustful = medium_stress_impact_loss
			}
		}
		else = {
			stress_impact = {
				base = medium_stress_impact_gain
				lustful = medium_stress_impact_loss
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_honor = -0.2
				ai_zeal = -0.2
			}
			modifier = {
				add = 20
				is_married = no
			}
			opinion_modifier = { #Less likely the more you like your spouse
				trigger = {
					exists = scope:spouse
				}
				who = root
				opinion_target = scope:spouse
				multiplier = -0.2
				step = 5
			}
			opinion_modifier = { #More likely the more you like the peasant
				who = root
				opinion_target = scope:peasant_character
				multiplier = 0.7
				step = 5
			}
			modifier = {
				add = 10
				OR = {
					has_trait = lustful
					has_trait = callous
					has_trait = fickle
					has_trait = compassionate
				}
			}
		}
	}

	option = { #Add them to court and reveal your secret child secret
		name = peasant_affair.1001.b
		trigger = {
			exists = scope:peasant_child
			scope:peasant_child = {
				is_in_the_same_court_as = root
			}
		}
		if = {
			limit = {
				exists = scope:peasant_child_secret
			}
			scope:peasant_child_secret = {
				expose_secret = root
			}
		}
		add_character_flag = peasant_appeared_at_court
		add_courtier = scope:peasant_character
		scope:peasant_character = {
			add_opinion = {
				modifier = kindness_opinion
				target = root
				opinion = 40
			}
		}
		if = {
			limit = {
				is_married = no
			}
			stress_impact = {
				lustful = medium_stress_impact_loss
			}
		}
		else = {
			stress_impact = {
				base = major_stress_impact_gain
				lustful = medium_stress_impact_loss
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_honor = -0.5
				ai_zeal = -0.2
			}
			modifier = {
				add = 20
				is_married = no
			}
			opinion_modifier = { #Less likely the more you like your spouse
				trigger = {
					exists = scope:spouse
				}
				who = root
				opinion_target = scope:spouse
				multiplier = -0.5
				step = 5
			}
			opinion_modifier = { #More likely the more you like the peasant
				who = root
				opinion_target = scope:peasant_character
				multiplier = 0.7
				step = 5
			}
			modifier = {
				add = 10
				OR = {
					has_trait = lustful
					has_trait = callous
					has_trait = fickle
					has_trait = compassionate
				}
			}
		}
	}

	option = { #Reject them
		name = peasant_affair.1001.c
		scope:peasant_character = {
			add_opinion = {
				modifier = refusal_opinion
				target = root
				opinion = -40
			}
		}
		scope:story = {
			end_story = yes
		}
		if = {
			limit = {
				is_married = no
			}
			stress_impact = {
				compassionate = medium_stress_impact_gain
				lustful = medium_stress_impact_gain
				just = medium_stress_impact_gain
				chaste = medium_stress_impact_loss
			}
		}
		else = {
			stress_impact = {
				base = major_stress_impact_loss
				compassionate = medium_stress_impact_gain
				lustful = medium_stress_impact_gain
				just = medium_stress_impact_gain
				chaste = medium_stress_impact_loss
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_honor = 0.5
				ai_zeal = 0.2
			}
			opinion_modifier = { #More likely the more you like your spouse
				trigger = {
					exists = scope:spouse
				}
				who = root
				opinion_target = scope:spouse
				multiplier = 0.5
				step = 5
			}
			opinion_modifier = { #Less likely the more you like the peasant
				who = root
				opinion_target = scope:peasant_character
				multiplier = -0.5
				step = 5
			}
			modifier = {
				add = 10
				has_trait = chaste
			}
		}
	}
}



###########################
# YOU LOOK FOR THE PEASANT
# 2001-2999
###########################

#You start looking for the peasant
#by Linnéa Thimrén
peasant_affair.2001 = {
	type = character_event
	title = peasant_affair.2001.t
	desc = {
		desc = peasant_affair.2001.desc_opening
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:story.var:rakish_night
				}
				desc = peasant_affair.2001.desc_rakish_night
			}
			triggered_desc = {
				trigger = {
					exists = scope:peasant_child
					scope:peasant_child = {
						real_father = {
							this = scope:peasant_character
						}
					}
				}
				desc = peasant_affair.2001.desc_known_father
			}
			desc = peasant_affair.2001.desc_unknown_peasant
			triggered_desc = {
				trigger = {
					any_child = {
						real_father = {
							this = scope:peasant_character
						}
					}
				}
				desc = peasant_affair.2001.desc_child
			}
		}
	}
	
	theme = seduction
	left_portrait = scope:peasant_character
	right_portrait = scope:peasant_child

	trigger = {
		NOT = { has_character_flag = peasant_affair_already_looking }
		exists = scope:story
	}

	immediate = {
		scope:story = {
			var:peasant_character = {
				save_scope_as = peasant_character
			}
			if = {
				limit = {
					exists = var:peasant_child
					var:peasant_child = {
						is_in_the_same_court_as = root
					}
				}
				var:peasant_child = {
					save_scope_as = peasant_child
				}
			}
		}
		if = {
			limit = {
				exists = primary_spouse
			}
			primary_spouse = {
				save_scope_as = spouse
			}
		}
	}

	option = { #I must find them!
		name = peasant_affair.2001.a
		custom_tooltip = peasant_affair.2001.a.tt
		trigger_event = {
			id = peasant_affair.2002
			days = { 30 90 }
		}
		add_character_flag = peasant_affair_already_looking
		if = {
			limit = {
				is_married = no
			}
			stress_impact = {
				lustful = medium_stress_impact_loss
				chaste = medium_stress_impact_gain
			}
		}
		else = {
			stress_impact = {
				base = medium_stress_impact_gain
				lustful = medium_stress_impact_loss
				chaste = medium_stress_impact_gain
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_honor = -0.2
				ai_zeal = -0.2
			}
			modifier = {
				add = 20
				is_married = no
			}
			opinion_modifier = { #Less likely the more you like your spouse
				trigger = {
					exists = scope:spouse
				}
				who = root
				opinion_target = scope:spouse
				multiplier = -0.5
				step = 5
			}
			opinion_modifier = { #More likely the more you like the peasant
				who = root
				opinion_target = scope:peasant_character
				multiplier = 0.7
				step = 5
			}
			modifier = {
				add = 10
				OR = {
					has_trait = lustful
					has_trait = callous
					has_trait = fickle
					has_trait = compassionate
				}
			}
		}
	}

	option = { #End the search
		name = peasant_affair.2001.b
		trigger = {
			NOT = {
				OR = {
					has_trait = zealous
					has_trait = celibate
				}
			}
		}

		scope:story = {
			end_story = yes
		}

		if = {
			limit = {
				is_married = no
			}
			stress_impact = {
				lustful = medium_stress_impact_gain
				chaste = medium_stress_impact_loss
			}
		}
		else = {
			stress_impact = {
				base = medium_stress_impact_loss
				lustful = medium_stress_impact_gain
				chaste = medium_stress_impact_loss
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_honor = 0.2
				ai_zeal = 0.2
			}
			modifier = {
				add = 20
				is_married = yes
			}
			opinion_modifier = { #More likely the more you like your spouse
				trigger = {
					exists = scope:spouse
				}
				who = root
				opinion_target = scope:spouse
				multiplier = 0.5
				step = 5
			}
			opinion_modifier = { #Less likely the more you like the peasant
				who = root
				opinion_target = scope:peasant_character
				multiplier = -0.5
				step = 5
			}
			modifier = {
				add = 10
				has_trait = chaste
			}
		}
	}

	option = { #End the search
		name = peasant_affair.2001.c
		trigger = {
			OR = {
				has_trait = zealous
				has_trait = celibate
			}
		}
		trait = zealous
		trait = celibate

		add_piety = medium_piety_gain
		scope:story = {
			end_story = yes
		}
		if = {
			limit = {
				is_married = no
			}
			stress_impact = {
				lustful = medium_stress_impact_gain
				chaste = medium_stress_impact_loss
			}
		}
		else = {
			stress_impact = {
				base = medium_stress_impact_loss
				lustful = medium_stress_impact_gain
				chaste = medium_stress_impact_loss
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_honor = 0.2
				ai_zeal = 0.2
			}
			modifier = {
				add = 20
				is_married = yes
			}
			opinion_modifier = { #More likely the more you like your spouse
				trigger = {
					exists = scope:spouse
				}
				who = root
				opinion_target = scope:spouse
				multiplier = 0.5
				step = 5
			}
			opinion_modifier = { #Less likely the more you like the peasant
				who = root
				opinion_target = scope:peasant_character
				multiplier = -0.5
				step = 5
			}
			modifier = {
				add = 10
				has_trait = chaste
			}
		}
	}
}

#The search goes on
#by Linnéa Thimrén
peasant_affair.2002 = {
	type = character_event
	title = peasant_affair.2001.t
	desc = {
		desc = peasant_affair.2002.desc_opening
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:peasant_child
				}
				desc = peasant_affair.2002.desc_child
			}
			desc = peasant_affair.2002.desc
		}
	}
	
	theme = seduction
	override_background = {
		event_background = throne_room
	}
	left_portrait = scope:councillor
	right_portrait = scope:peasant_child

	trigger = {
		exists = scope:story
	}

	on_trigger_fail = {
		trigger_event = peasant_affair.2004
	}

	immediate = {
		random_councillor = {
			save_scope_as = councillor
		}
		scope:story = {
			var:peasant_character = {
				save_scope_as = peasant_character
			}
			if = {
				limit = {
					exists = var:peasant_child
					var:peasant_child = {
						is_in_the_same_court_as = root
					}
				}
				var:peasant_child = {
					save_scope_as = peasant_child
				}
			}
		}
		if = {
			limit = {
				has_character_flag = peasant_affair_already_looking
			}
			remove_character_flag = peasant_affair_already_looking
		}
		if = {
			limit = {
				exists = primary_spouse
			}
			primary_spouse = {
				save_scope_as = spouse
			}
		}
	}

	option = { #Continue searching for them
		name = peasant_affair.2002.a
		remove_short_term_gold = medium_gold_value
		stress_impact = {
			stubborn = medium_stress_impact_loss
			greedy = medium_stress_impact_gain
		}
		trigger_event = {
			id = peasant_affair.2003
			days = { 30 90 }
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = -0.2
				ai_zeal = -0.2
			}
			modifier = {
				add = 20
				is_married = no
			}
			opinion_modifier = { #Less likely the more you like your spouse
				trigger = {
					exists = scope:spouse
				}
				who = root
				opinion_target = scope:spouse
				multiplier = -0.5
				step = 5
			}
			opinion_modifier = { #More likely the more you like the peasant
				who = root
				opinion_target = scope:peasant_character
				multiplier = 0.7
				step = 5
			}
			modifier = {
				add = 10
				OR = {
					has_trait = lustful
					has_trait = stubborn
					has_trait = patient
				}
			}
		}
	}

	option = { #End the search
		name = peasant_affair.2002.b
		scope:story = {
			end_story = yes
		}
		stress_impact = {
			arrogant = medium_stress_impact_loss
		}
		ai_chance = {
			base = 0
			ai_value_modifier = {
				ai_honor = 0.2
				ai_zeal = 0.2
			}
			modifier = {
				add = 20
				is_married = no
			}
			opinion_modifier = { #More likely the more you like your spouse
				trigger = {
					exists = scope:spouse
				}
				who = root
				opinion_target = scope:spouse
				multiplier = 0.5
				step = 5
			}
			opinion_modifier = { #Less likely the more you like the peasant
				who = root
				opinion_target = scope:peasant_character
				multiplier = -0.7
				step = 5
			}
			modifier = {
				add = 10
				OR = {
					has_trait = lustful
					has_trait = stubborn
				}
			}
		}
	}
}


#They are found!
#by Linnéa Thimrén
peasant_affair.2003 = {
	type = character_event
	title = peasant_affair.2001.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:peasant_character = {
						is_alive = no
					}
					exists = scope:peasant_child
					scope:peasant_child = {
						NOT = { is_in_the_same_court_as = root }
					}
				}
				desc = peasant_affair.2003.desc_dead_brought_child
			}
			triggered_desc = {
				trigger = {
					scope:peasant_character = {
						is_alive = no
					}
					OR = {
						NOT = { exists = scope:peasant_child }
						AND = {
							exists = scope:peasant_child
							scope:peasant_child = {
								is_in_the_same_court_as = root
							}
						}
					}
				}
				desc = peasant_affair.2003.desc_dead
			}
			desc = {
				desc = peasant_affair.2003.desc_opening
				first_valid = {
					triggered_desc = {
						trigger = {
							reverse_opinion = {
								target = scope:peasant_character
								value <= -10
							}
						}
						desc = {
							first_valid = {
								triggered_desc = {
									trigger = {
										exists = scope:peasant_child
										scope:peasant_child = {
											NOT = { is_in_the_same_court_as = root }
										}
									}
									desc = peasant_affair.2003.desc_dislike_their_child
								}
								desc = peasant_affair.2003.desc_dislike
							}
						}
					}
					desc = {
						first_valid = {
							triggered_desc = {
								trigger = {
									exists = scope:peasant_child
									scope:peasant_child = {
										NOT = { is_in_the_same_court_as = root }
									}
								}
								desc = peasant_affair.2003.desc_their_child
							}
							desc = peasant_affair.2003.desc
						}
					}
				}
			}
		}
	}
	
	theme = seduction
	override_background = {
		event_background = throne_room
	}
	left_portrait = {
		character = scope:peasant_character
		triggered_animation = {
			trigger = {
				reverse_opinion = {
					target = scope:peasant_character
					value <= -10
				}
			}
			animation = anger
		}
		triggered_animation = {
			trigger = {
				reverse_opinion = {
					target = scope:peasant_character
					value > -10
				}
			}
			animation = happiness
		}
	}
	right_portrait = scope:peasant_child

	trigger = {
		exists = scope:story.var:peasant_character
		scope:story.var:peasant_character = {
			is_alive = yes
			is_ruler = no
		}
		is_landed = yes
	}

	immediate = {
		remove_character_flag = is_looking_for_peasant
		scope:story = {
			if = {
				limit = {
					NOT = { exists = scope:peasant_child }
					exists = var:peasant_child
				}
				var:peasant_child = {
					save_scope_as = peasant_child
				}
			}
			if = {
				limit = { exists = scope:peasant_child }
				if = {
					limit = {
						var:peasant_child.mother = var:peasant_character
						var:peasant_character = {
							any_secret = {
								secret_type = secret_unmarried_illegitimate_child
								secret_target = scope:story.var:peasant_child
							}
						}
					}
					var:peasant_character = {
						random_secret = {
							limit = {
								secret_type = secret_unmarried_illegitimate_child
								secret_target = {
									this = scope:story.var:peasant_child
								}
							}
							save_scope_as = peasant_child_secret
							reveal_to_without_events_effect = { CHARACTER = root }
						}
					}
				}
				if = {
					limit = {
						var:peasant_child.real_father = var:peasant_character
						root = {
							any_secret = {
								OR = {
									secret_type = secret_unmarried_illegitimate_child
									secret_type = secret_disputed_heritage
								}
								secret_target = scope:story.var:peasant_child
							}
						}
					}
					root = {
						random_secret = {
							limit = {
								OR = {
									secret_type = secret_unmarried_illegitimate_child
									secret_type = secret_disputed_heritage
								}
								secret_target = scope:story.var:peasant_child
							}
							save_scope_as = peasant_child_secret
							reveal_to_without_events_effect = { CHARACTER = scope:story.var:peasant_character }
						}
					}
				}
			}
		}
	}

	option = { #Add them to court
		name = {
			trigger = { scope:peasant_character = { is_alive = yes } }
			text = peasant_affair.2003.a_alive
		}
		name = {
			trigger = {
				scope:peasant_character = { is_alive = no }
				exists = scope:peasant_child
				scope:peasant_child = {
					NOT = { is_in_the_same_court_as = root }
				}
			}
			text = peasant_affair.2003.a_dead
		}
		trigger = {
			is_ruler = yes
			OR = {
				scope:peasant_character = { is_alive = yes }
				AND = {
					exists = scope:peasant_child
					scope:peasant_child = {
						NOT = { is_in_the_same_court_as = root }
					}
				}
			}
		}
		add_character_flag = peasant_appeared_at_court
		if = {
			limit = {
				scope:peasant_character = {
					is_alive = yes
				}
			}
			add_courtier = scope:peasant_character
			if = {
				limit = {
					reverse_opinion = {
						target = scope:peasant_character
						value <= -10
					}
				}
				scope:peasant_character = {
					add_opinion = {
						modifier = hate_opinion
						target = root
						opinion = -20
					}
				}
			}
			else = {
				scope:peasant_character = {
					add_opinion = {
						modifier = kindness_opinion
						target = root
						opinion = 20
					}
				}
			}
		}
		if = {
			limit = {
				exists = scope:peasant_child
				scope:peasant_child = {
					is_alive = yes
					NOT = { is_in_the_same_court_as = root }
				}
			}
			add_courtier = scope:peasant_child
		}
		ai_chance = {
			base = 100
		}
	}

	option = { #Add them to court and reveal your child
		name = peasant_affair.2003.b
		trigger = {
			scope:peasant_character = { is_alive = yes }
			exists = scope:peasant_child
			scope:peasant_child = {
				is_in_the_same_court_as = root
			}
		}
		add_courtier = scope:peasant_character
		scope:peasant_character = {
			add_opinion = {
				modifier = kindness_opinion
				target = root
				opinion = 40
			}
		}
		if = {
			limit = {
				any_secret = {
					OR = {
						secret_type = secret_unmarried_illegitimate_child
						secret_type = secret_disputed_heritage
					}
				}
			}
			random_secret = {
				limit = {
					OR = {
						secret_type = secret_unmarried_illegitimate_child
						secret_type = secret_disputed_heritage
					}
					secret_target = scope:peasant_child
				}
				expose_secret = root
			}
		}
	}

	option = { #Imprison them!
		name = peasant_affair.2003.c
		custom_tooltip = peasant_affair.2003.c.tt
		scope:peasant_character = {
			add_opinion = {
				modifier = cruelty_opinion
				target = root
				opinion = -20
			}
		}
		imprison = {
			target = scope:peasant_character
			type = dungeon
		}
		hidden_effect = {
			scope:story = {
				end_story = yes
			}
		}
		stress_impact = {
			base = minor_stress_impact_loss
			compassionate = medium_stress_impact_gain
			just = medium_stress_impact_gain
		}
		ai_chance = {
			base = 0
			modifier = {
				add = 100
				calc_true_if = {
					amount >= 2
					has_trait = paranoid
					has_trait = sadistic
					has_trait = callous
				}
			}
		}
	}

	option = { #Send the child away
		name = peasant_affair.2003.d
		trigger = {
			scope:peasant_character = { is_alive = no }
			exists = scope:peasant_child
			scope:peasant_child = {
				NOT = { is_in_the_same_court_as = root }
			}
		}
		custom_tooltip = peasant_affair.2003.d.tt
		hidden_effect = {
			scope:story = {
				end_story = yes
			}
		}
		stress_impact = {
			compassionate = medium_stress_impact_gain
			generous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 50
			modifier = {
				add = 50
				NOT = { #more likely if you have no kids
					any_child = { count >= 1 }
				}
			}
		}
	}

	option = { #Lament their fate
		name = peasant_affair.2003.e
		trigger = {
			scope:peasant_character = { is_alive = no }
			exists = scope:peasant_child
			scope:peasant_child = {
				is_in_the_same_court_as = root
			}
		}
		hidden_effect = {
			scope:story = {
				end_story = yes
			}
		}
		stress_impact = {
			base = medium_stress_impact_gain
			callous = minor_stress_impact_loss
		}
		ai_chance = {
			base = 50
		}
	}

	option = { #Take the child away from them
		name = peasant_affair.2003.f
		trigger = {
			scope:peasant_character = { is_alive = yes }
			exists = scope:peasant_child
			scope:peasant_child = {
				NOT = { is_in_the_same_court_as = root }
			}
			reverse_opinion = {
				target = scope:peasant_character
				value <= -10
			}
			OR = {
				has_trait = paranoid
				has_trait = sadistic
				has_trait = callous
			}
		}
		trait = paranoid
		trait = sadistic
		trait = callous
		add_courtier = scope:peasant_child
		scope:peasant_character = {
			add_opinion = {
				modifier = hate_opinion
				target = root
				opinion = -40
			}
		}
		hidden_effect = {
			scope:story = {
				end_story = yes
			}
		}
		stress_impact = {
			base = medium_stress_impact_gain
			compassionate = minor_stress_impact_gain
			paranoid = medium_stress_impact_loss
			sadistic = medium_stress_impact_loss
			callous = medium_stress_impact_loss
			wrathful = medium_stress_impact_loss
			vengeful = medium_stress_impact_loss
		}
		ai_chance = {
			base = 50
			modifier = {
				add = 50
				OR = {
					has_trait = callous
					has_trait = sadistic
					has_trait = greedy
					has_trait = wrathful
					has_trait = vengeful
				}
			}
			modifier = {
				add = 40
				NOT = { #more likely if you have no kids
					any_child = { count >= 1 }
				}
			}
		}
	}

	option = { #Let them go
		name = peasant_affair.2003.g
		trigger = {
			scope:peasant_character = { is_alive = yes }
			reverse_opinion = {
				target = scope:peasant_character
				value <= 0
			}
		}
		scope:peasant_character = {
			add_opinion = {
				modifier = kindness_opinion
				target = root
				opinion = 20
			}
		}
		hidden_effect = {
			scope:story = {
				end_story = yes
			}
		}
		stress_impact = {
			just = minor_stress_impact_loss
			humble = minor_stress_impact_loss
			compassionate = minor_stress_impact_loss
			sadistic = medium_stress_impact_gain
			wrathful = medium_stress_impact_gain
			vengeful = minor_stress_impact_gain
			callous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
		}
	}
}


#The story has ended, you never found the peasant
#by Linnéa Thimrén
peasant_affair.2004 = {
	type = character_event
	title = peasant_affair.2001.t
	desc = {
		desc = peasant_affair.2004.desc_opening
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:peasant_child
				}
				desc = peasant_affair.2002.desc_child
			}
			desc = peasant_affair.2002.desc
		}
	}
	
	theme = seduction
	override_background = {
		event_background = throne_room
	}
	left_portrait = scope:councillor
	right_portrait = scope:peasant_child


	immediate = {
		random_councillor = {
			save_scope_as = councillor
		}
		if = {
			limit = {
				has_character_flag = peasant_affair_already_looking
			}
			remove_character_flag = peasant_affair_already_looking
		}
	}

	option = { #Aw darn it
		name = peasant_affair.2004.a
		
	}
}

###########################
# PEASANT AT COURT
# 3001-3999
###########################

# A Peasant mother wants you to acknowledge the child as yours
peasant_affair.3001 = {
	type = character_event
	title = peasant_affair.3001.t
	desc = {
		desc = peasant_affair.3001.available_desc
		triggered_desc = {
			trigger = {
				exists = scope:other_spouse
			}
			desc = peasant_affair.3001.unavailable_desc
		}
	}
	theme = bastardy
	left_portrait = scope:peasant_character
	lower_left_portrait = scope:peasant_child
	right_portrait = scope:other_spouse
	
	trigger = {
		scope:story = {
			exists = var:peasant_child
			var:peasant_child = {
				has_trait = bastard
				NOT = { father = root }
			}
			NOT = { exists = var:acknowledged_child }
		}
	}

	immediate = {
		save_scope_as = actor
		scope:story = {
			var:peasant_child = {
				save_scope_as = peasant_child
				save_scope_as = recipient
			}
			var:peasant_character = {
				save_scope_as = peasant_character
				if = {
					limit = {
						any_secret = {
							OR = {
								secret_type = secret_disputed_heritage
								secret_type = secret_unmarried_illegitimate_child
							}
							secret_target = scope:peasant_child
						}
					}
					random_secret = {
						limit = {
							OR = {
								secret_type = secret_disputed_heritage
								secret_type = secret_unmarried_illegitimate_child
							}
							secret_target = scope:peasant_child	
						}
						save_scope_as = child_secret
					}
				}
			}
		}
		if = {
			limit = {
				is_married = yes
				exists = primary_spouse
				NOT = {
					any_consort = {
						this = scope:peasant_character
					}
				}
			}
			primary_spouse = {
				save_scope_as = other_spouse
			}
		}
	}


	#Of course I will acknowledge the child as mine, and legitimize!
	option = {
		name = peasant_affair.3001.a
		if = {
			limit = {
				exists = scope:child_secret
			}
			set_variable = {
				name = do_not_notify_me_of_bastard_secret_reveal
				value = yes
				days = 3
			}
			scope:child_secret = {
				expose_secret = root
			}
		}
		show_as_tooltip = { #All the opinions
			scope:peasant_child = {
				add_trait = legitimized_bastard
				set_house = root.house
				add_opinion = {
					target = ROOT
					modifier = legitimized_me_opinion
				}
				random_parent = {
					limit = { NOT = { this = root } }
					add_opinion = {
						target = root
						modifier = legitimized_my_child_opinion
					}
				}
			}
			every_spouse = {
				limit = {
					NOT = { any_child = { this = scope:peasant_child } }
				}
				add_opinion = {
					target = root
					modifier = legitimized_a_bastard_opinion
				}
			}
			if = {
				limit = {
					any_child = {
						is_adult = yes
						NOT = { this = scope:peasant_child }
						NOR = {
							has_trait = bastard
							has_trait = legitimized_bastard
							opinion = {
								value >= 40
								target = scope:peasant_child
							}
						}
					}
				}
				every_child = {
					limit = {
						is_adult = yes
						NOT = { this = scope:peasant_child }
						NOR = {
							has_trait = bastard
							has_trait = legitimized_bastard
							opinion = {
								value >= 40
								target = scope:peasant_child
							}
						}
					}
					custom = every_child_adult_non_bastard_dislike
					add_opinion = {
						target = root
						modifier = legitimized_a_bastard_opinion
					}
				}
			}
		}
		hidden_effect = {
			scope:recipient = {
				trigger_event = bastard_interaction.0001
				random_parent = {
					limit = { NOT = { this = scope:actor } }
					trigger_event = bastard_interaction.0003
				}
			}
			scope:actor = {
				trigger_event = bastard_interaction.0002

				every_spouse = {
					limit = {
						NOT = { any_child = { this = scope:recipient } }
					}
					scope:peasant_child = { save_scope_as = legitimized_bastard }
					trigger_event = bastard_interaction.0004
				}
				every_child = {
					limit = {
						is_adult = yes
						NOT = { this = scope:recipient }
					}
					trigger_event = bastard_interaction.0005
				}
			}
		}
		scope:story = {
			set_variable = {
				name = acknowledged_child
				value = yes
			}
		}
		ai_chance = {
			base = 20
			opinion_modifier = {
				opinion_target = scope:peasant_character
				multiplier = 0.5
			}
			opinion_modifier = {
				opinion_target = scope:peasant_child
				multiplier = 0.5
			}
			modifier = { #Significantly increase chance if you do not have children who are valid heirs!
				trigger = {
					is_ruler = yes
					any_child = { count >= 1 }
				}
				add = 80
				NOT = {
					any_child = {
						is_heir_of = root
					}
				}
			}
			ai_value_modifier = {
				ai_compassion = 0.5
				ai_honor = 0.5
			}
		}
	}

	#It is my child, but I will not legitimze it
	option = {
		name = peasant_affair.3001.b
		trigger = {
			exists = scope:child_secret
		}
		scope:child_secret = {
			expose_secret = root
		}
		scope:story = {
			set_variable = {
				name = acknowledged_child
				value = yes
			}
		}
		ai_chance = {
			base = 100
			modifier = {
				add = 50
				any_child = {
					count < 1
				}
			}
			modifier = {
				add = 30
				any_child = {
					count < 2
				}
			}
			opinion_modifier = {
				opinion_target = scope:peasant_character
				multiplier = 0.5
			}
			opinion_modifier = {
				opinion_target = scope:peasant_child
				multiplier = 0.5
			}
			ai_value_modifier = {
				ai_honor = 1
			}
		}
	}

	option = { # I acknowledge the child as mine
		name = peasant_affair.3001.c
		trigger = {
			NOT = { exists = scope:child_secret }
			scope:peasant_child = {
				NOT = { father = root }
				real_father = root
			}

		}
		scope:peasant_child = {
			set_father = root
		}
		scope:story = {
			set_variable = {
				name = acknowledged_child
				value = yes
			}
		}
		ai_chance = {
			base = 100
			modifier = {
				add = 50
				any_child = {
					count < 1
				}
			}
			modifier = {
				add = 30
				any_child = {
					count < 2
				}
			}
			ai_value_modifier = {
				ai_honor = 1
			}
		}
	}

	#No
	option = {
		name = peasant_affair.3001.d
		custom_tooltip = peasant_affair.3001.d.tt
		reverse_add_opinion = {
			modifier = peasant_affair_rejected_acknowledgement_opinion
			target = root
		}
		scope:story = {
			set_variable = {
				name = acknowledged_child
				value = no
			}
		}
		ai_chance = {
			base = 100
			modifier = {
				add = 200
				is_married = yes
			}
			opinion_modifier = {
				opinion_target = scope:other_spouse
				trigger = {
					exists = scope:other_spouse
				}
			}
		}
	}
}


################################
# Peasant Father wants you to acknowledge the child as his
################################

peasant_affair.3002 = {
	type = character_event
	title = peasant_affair.3002.t
	desc = {
		desc = peasant_affair.3002.available_desc
		triggered_desc = {
			trigger = {
				exists = scope:other_spouse
			}
			desc = peasant_affair.3002.unavailable_desc
		}
	}
	left_portrait = scope:peasant_character
	lower_left_portrait = scope:peasant_child
	right_portrait = scope:other_spouse
	theme = bastardy
	
	trigger = {
		scope:story = {
			exists = var:peasant_child
			var:peasant_child = {
				real_father = scope:story.var:peasant_character
				NOT = { father = scope:story.var:peasant_character }
			}
			NOT = { has_variable = acknowledged_child }
		}
	}

	immediate = {
		scope:story = {
			var:peasant_character = {
				save_scope_as = peasant_character
			}
			var:peasant_child = {
				save_scope_as = peasant_child
			}
		}
		if = {
			limit = {
				exists = primary_spouse
			}
			primary_spouse = {
				save_scope_as = other_spouse
			}
		}
		random_secret = {
			limit = {
				OR = {
					secret_type = secret_unmarried_illegitimate_child
					secret_type = secret_disputed_heritage
				}
				secret_target = scope:peasant_child
			}
			save_scope_as = child_secret
		}
	}

	#Yes
	option = {
		name = peasant_affair.3002.a
		trigger = {
			exists = scope:child_secret
		}
		scope:child_secret = {
			expose_secret = root
		}
		scope:story = {
			set_variable = {
				name = acknowledged_child
				value = yes
			}
		}
		ai_chance = {
			base = 100
			opinion_modifier = {
				opinion_target = scope:peasant_character
				multiplier = 0.5
			}
			opinion_modifier = {
				opinion_target = scope:peasant_child
				multiplier = 0.5
			}
			ai_value_modifier = {
				ai_honor = 1
			}
		}
	}

	#Yes - fallback in case secrets have gone wrong
	option = {
		name = peasant_affair.3002.a
		trigger = {
			NOT = {
				exists = scope:child_secret
			}
		}
		scope:peasant_child = {
			set_father = real_father
		}
		scope:story = {
			set_variable = {
				name = acknowledged_child
				value = yes
			}
		}
		ai_chance = {
			base = 100
			opinion_modifier = {
				opinion_target = scope:peasant_character
				multiplier = 0.5
			}
			opinion_modifier = {
				opinion_target = scope:peasant_child
				multiplier = 0.5
			}
			ai_value_modifier = {
				ai_honor = 1
			}
		}
	}

	#No
	option = {
		name = peasant_affair.3002.b
		custom_tooltip = peasant_affair.3001.d.tt
		reverse_add_opinion = {
			modifier = peasant_affair_rejected_acknowledgement_opinion
			target = root
		}
		scope:story = {
			set_variable = {
				name = acknowledged_child
				value = no
			}
		}
		ai_chance = {
			base = 100
			modifier = {
				add = 200
				is_married = yes
			}
			opinion_modifier = {
				trigger = {
					exists = scope:other_spouse
				}
				opinion_target = scope:other_spouse
			}
		}
	}
}



##################################
# Peasant wants to be your lover
##################################
peasant_affair.3003 = {
	type = character_event
	title = peasant_affair.3003.t
	desc = peasant_affair.3003.desc
	theme = love
	left_portrait = {
		character = scope:peasant_character
		animation = flirtation
	}
	
	trigger = {
		OR = {
			is_married = yes
			scope:story.var:peasant_character = { is_married = yes }
		}
		NOT = {
			scope:story.var:peasant_character = {
				is_consort_of = root
			}
		}
		can_set_relation_lover_trigger = { CHARACTER = scope:story.var:peasant_character }
		scope:story = { NOT = { has_variable = had_lover_request_event } }
	}

	weight_multiplier = {
		base = 1
		modifier = {
			factor = 0.2
			scope:story.var:peasant_character = {
				opinion = {
					target = root
					value < 10
				}
			}
		}
	}

	immediate = {
		scope:story = {
			var:peasant_character = {
				save_scope_as = peasant_character
			}
			set_variable = {
				name = had_lover_request_event
				value = yes
			}
		}
		if = {
			limit = {
				exists = primary_spouse
			}
			primary_spouse = {
				save_scope_as = spouse
			}
		}
	}

	#Yes, of course!
	option = {
		name = peasant_affair.3003.a
		set_relation_lover = scope:peasant_character
		stress_impact = {
			paranoid = minor_stress_impact_gain
			honest = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = -0.8
				ai_greed = 0.5
				ai_boldness = 0.5
			}
			modifier = {
				add = 100
				has_opinion_modifier = {
					target = scope:peasant_character
					modifier = love_opinion
				}
			}
			opinion_modifier = {
				opinion_target = scope:peasant_character
				multiplier = 1
			}
		}
	}

	#Nope
	option = {
		name = peasant_affair.3003.b
		reverse_add_opinion = {
			modifier = peasant_affair_rejected_lover_opinion
			target = scope:peasant_character
		}
		stress_impact = {
			lustful = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 0.2
			}
			modifier = {
				trigger = {
					exists = scope:spouse
				}
				add = 100
				has_opinion_modifier = {
					target = scope:spouse
					modifier = love_opinion
				}
			}
			opinion_modifier = {
				trigger = {
					exists = scope:spouse
				}
				opinion_target = scope:spouse
				multiplier = 1
			}
		}
	}
}

###############################
# Peasant wants to marry you
###############################
peasant_affair.3004 = {
	type = character_event
	title = peasant_affair.3004.t
	desc = peasant_affair.3004.desc
	theme = love
	left_portrait = scope:peasant_character
	right_portrait = scope:peasant_child
	
	trigger = {
		can_marry_character_trigger = {
			CHARACTER = scope:story.var:peasant_character
		}
		scope:story.var:peasant_character = {
			can_marry_character_trigger = {
				CHARACTER = root
			}
		}
		scope:story = { NOT = { has_variable = had_marriage_request_event } }
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = 2
			has_relation_lover = scope:story.var:peasant_character
		}
		modifier = {
			factor = 0.2
			scope:story.var:peasant_character = {
				opinion = {
					target = root
					value < 10
				}
			}
		}
	}

	immediate = {
		scope:story = {
			var:peasant_character = {
				save_scope_as = peasant_character
				if = {
					limit = { root = { is_ai = no }	}
					assign_quirk_effect = yes
				}
			}
			if = {
				limit = {
					exists = var:peasant_child
				}
				var:peasant_child = {
					save_scope_as = peasant_child
				}
			}
			set_variable = {
				name = had_marriage_request_event
				value = yes
			}
		}
	}

	#Yes, of course!
	option = {
		name = peasant_affair.3004.a
		if = {
			limit = {
				is_female = yes
			}
			marry_matrilineal_if_possible = { CHARACTER = scope:peasant_character }
		}
		else = {
			marry = scope:peasant_character
		}
	}

	#We can be lovers instead
	option = {
		name = peasant_affair.3004.b
		trigger = {
			can_set_relation_lover_trigger = { CHARACTER = scope:peasant_character }
		}
		set_relation_lover = scope:peasant_character
	}

	#We can be lovers instead
	option = {
		name = peasant_affair.3004.c
		trigger = {
			allowed_more_concubines = yes
		}
		make_concubine = scope:peasant_character
	}

	#Nope
	option = {
		name = peasant_affair.3004.d
		reverse_add_opinion = {
			target = scope:peasant_character
			modifier = peasant_affair_rejected_lover_opinion
		}
	}
}