﻿namespace = pam_generic_events

# Gain Religious Scholar
pam_generic_events.0001 = {
	type = character_event
	title = pam_generic_events.0001.t
	desc = pam_generic_events.0001.desc
	theme = christian

	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		character = scope:chaplain
		animation = reading
	}

	cooldown = { years = 20 }

	trigger = {
		is_available = yes
		age >= 10
		NOT = { has_trait = lifestyle_scholar }
		cp:councillor_court_chaplain ?= {
			opinion = {
				target = root
				value > 10
			}
		}
	}
	
	weight_multiplier = {
		base = 1
		modifier = {
			government_is_religious_trigger = yes
			add = 0.25
		}
	}

	immediate = {
		cp:councillor_court_chaplain = { save_scope_as = chaplain }
	}

	option = { # Get trait
		name = pam_generic_events.0001.a
		add_trait = lifestyle_scholar

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_zeal = 0.5
			}
			modifier = {
				government_is_religious_trigger = yes
				factor = 2
			}
		}
	}

	option = { # I'm good ty
		name = pam_generic_events.0001.b

		ai_chance = {
			base = 100
			modifier = {
				has_trait = cynical
				factor = 0
			}
		}
	}
}

# Child doubts their goodness
scripted_trigger pam_generic_events_0002_valid_child_trigger = {
	is_alive = yes
	is_courtier_of = root
	NOT = { has_relation_rival = root }
	rite = root.rite
	age > 5
	age < 19
	basic_is_available_ai = yes
	OR = {
		num_sinful_traits > 0
		spiritual_fulfillment < 0
	}
}

pam_generic_events.0002 = {
	type = character_event
	title = pam_generic_events.0002.t
	desc = {
		desc = pam_generic_events.0002.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:sinful_trait }
				desc = pam_generic_events.0002.desc.sin
			}
			desc = pam_generic_events.0002.desc.sp
		}
		desc = pam_generic_events.0002.desc.outro
	}
	theme = christian
	override_background = { reference = bedchamber }
	widgets = {
		widget = { gui = event_window_widget_vfx_background_night_scene container = foreground_shader_vfx_container }
		widget = { gui = event_window_widget_vfx_left_character_night_scene container = foreground_shader_vfx_container }
		widget = { gui = event_window_widget_vfx_right_character_night_scene container = foreground_shader_vfx_container }
	}

	left_portrait = {
		character = root
		animation = worry
		outfit_tags = { nightgown }
	}
	right_portrait = {
		character = scope:doubting_child
		animation = crying
		outfit_tags = { nightgown }
	}

	cooldown = { years = 10 }

	trigger = {
		has_pam_dlc_trigger = yes
		is_available = yes
		any_child = {
			pam_generic_events_0002_valid_child_trigger = yes
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = 0.25
			has_trait = compassionate
		}
	}

	immediate = {
		random_child = {
			limit = {
				pam_generic_events_0002_valid_child_trigger = yes
			}
			weight = {
				base = 1
				modifier = {
					add = 2
					num_sinful_traits > 0
				}
				modifier = {
					add = 1
					spiritual_fulfillment < 0
				}
			}
			save_scope_as = doubting_child
			if = {
				limit = { num_sinful_traits > 0 }
				random_character_trait = {
					limit = {
						scope:doubting_child.rite = {
							trait_is_sin_rite = prev
						}
					}
					save_scope_as = sinful_trait
				}
			}
		}
	}

	option = { # Urge them to cast off the sin
		name = pam_generic_events.0002.a
		trigger = {
			scope:doubting_child = {
				num_sinful_traits > 0
			}
		}
		scope:doubting_child = {
			flip_sinful_trait_effect = yes
			stress_and_fulfillment_impact = {
				base = massive_stress_impact_gain
			}
		}
		change_spiritual_fulfillment = minor_spiritual_fulfillment_value
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_zeal = 0.5
			}
			modifier = {
				factor = 2
				has_trait = zealous
			}
			modifier = {
				factor = 0
				has_trait = compassionate
			}
		}
	}

	option = { # Comfort them
		name = pam_generic_events.0002.b
		progress_towards_friend_effect = {
			CHARACTER = scope:doubting_child
			REASON = friend_comforted_child_doubts
			OPINION = default_friend_opinion
		}
		stress_and_fulfillment_impact = {
			compassionate = minor_stress_impact_loss
			callous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 0.5
			}
			modifier = {
				factor = 2
				has_trait = compassionate
			}
			modifier = {
				factor = 0
				has_trait = callous
			}
		}
	}

	option = { # Pray together
		name = pam_generic_events.0002.c
		add_piety = medium_piety_gain
		scope:doubting_child = {
			add_piety = minor_piety_gain
		}
		stress_and_fulfillment_impact = {
			zealous = minor_stress_impact_loss
			cynical = minor_stress_impact_gain
		}
		ai_chance = {
			base = 75
			ai_value_modifier = {
				ai_zeal = 0.5
			}
			modifier = {
				factor = 2
				has_trait = zealous
			}
			modifier = {
				factor = 0
				has_trait = cynical
			}
		}
	}
}
# Spouse worries about your sinful ways
scripted_trigger pam_generic_events_0003_valid_spouse_trigger = {
	is_available_ai_adult = yes
	NOT = { has_same_sinful_trait = root }
}

pam_generic_events.0003 = {
	type = character_event
	title = pam_generic_events.0003.t
	desc = pam_generic_events.0003.desc
	theme = christian
	override_background = { reference = garden }
	widgets = {
		widget = { gui = event_window_widget_vfx_background_night_scene container = foreground_shader_vfx_container }
		widget = { gui = event_window_widget_vfx_left_character_night_scene container = foreground_shader_vfx_container }
		widget = { gui = event_window_widget_vfx_right_character_night_scene container = foreground_shader_vfx_container }
	}

	left_portrait = {
		character = root
		triggered_animation = {
			trigger = { has_trait = arrogant }
			animation = dismissal
		}
		animation = sadness
	}
	right_portrait = {
		character = scope:worried_spouse
		animation = stress
	}

	cooldown = { years = 10 }

	trigger = {
		has_pam_dlc_trigger = yes
		is_available = yes
		num_sinful_traits > 0
		primary_spouse ?= {
			pam_generic_events_0003_valid_spouse_trigger = yes
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = 0.25
			primary_spouse ?= { has_trait = zealous }
		}
		modifier = {
			add = 0.25
			num_sinful_traits >= 2
		}
	}

	immediate = {
		primary_spouse = { save_scope_as = worried_spouse }
		random_character_trait = {
			limit = {
				root.rite = {
					trait_is_sin_rite = prev
				}
			}
			save_scope_as = sinful_trait
		}
	}

	option = { # Promise pilgrimage and change
		name = pam_generic_events.0003.a
		add_character_modifier = pilgrimage_promised_modifier
		progress_towards_lover_effect = {
			CHARACTER = scope:worried_spouse
			REASON = lover_promised_to_change_ways
			OPINION = default_lover_opinion
		}
		change_spiritual_fulfillment = minor_spiritual_fulfillment_value
		scope:worried_spouse = {
			if = {
				limit = { is_playable_character = yes }	# Only playable characters have spiritual fulfillment
				change_spiritual_fulfillment = minor_spiritual_fulfillment_value
			}
		}
		stress_and_fulfillment_impact = {
			compassionate = minor_stress_impact_loss
			zealous = minor_stress_impact_loss
			cynical = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 0.25
				ai_zeal = 0.25
			}
			modifier = {
				factor = 2
				has_trait = compassionate
			}
			modifier = {
				factor = 0
				has_trait = cynical
			}
		}
	}

	option = { # Double down
		name = pam_generic_events.0003.b
		change_spiritual_fulfillment = medium_spiritual_fulfillment_value
		add_dread = medium_dread_gain
		progress_towards_rival_effect = {
			CHARACTER = scope:worried_spouse
			REASON = rival_embraced_sinful_ways
			OPINION = default_rival_opinion
		}
		stress_and_fulfillment_impact = {
			arrogant = minor_stress_impact_loss
			callous = minor_stress_impact_loss
			humble = minor_stress_impact_gain
			compassionate = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = 0.5
				ai_honor = -0.25
			}
			modifier = {
				factor = 2
				has_trait = arrogant
			}
			modifier = {
				factor = 0
				has_trait = humble
			}
		}
	}

	option = { # Tell them to chill
		name = pam_generic_events.0003.c
		scope:worried_spouse = {
			add_opinion = {
				target = root
				modifier = annoyed_opinion
				opinion = -5
			}
		}
		stress_and_fulfillment_impact = {
			callous = minor_stress_impact_loss
			compassionate = minor_stress_impact_gain
		}
		ai_chance = {
			base = 75
			ai_value_modifier = {
				ai_sociability = -0.25
			}
			modifier = {
				factor = 2
				has_trait = callous
			}
			modifier = {
				factor = 0
				has_trait = compassionate
			}
		}
	}
}

# Friend/chaplain comforts you after a family death
scripted_trigger pam_generic_events_0004_recent_family_death_memory_trigger = {
	OR = {
		has_memory_type = relative_died
		has_memory_type = spouse_died
	}
	memory_age_years < 5
	exists = memory_participant:dead_relation
}

pam_generic_events.0004 = {
	type = character_event
	title = pam_generic_events.0004.t
	desc = pam_generic_events.0004.desc
	theme = christian
	override_background = { reference = temple }
	widgets = {
		widget = { gui = event_window_widget_vfx_left_character_flickering_candlelight_dark container = foreground_shader_vfx_container }
		widget = { gui = event_window_widget_vfx_background_night_scene container = foreground_shader_vfx_container }
		widget = { gui = event_window_widget_vfx_fog container = foreground_shader_vfx_container }
		widget = { gui = event_window_widget_vfx_left_character_night_scene container = foreground_shader_vfx_container }
		widget = { gui = event_window_widget_vfx_right_character_night_scene container = foreground_shader_vfx_container }
	}

	left_portrait = {
		character = root
		animation = sadness
	}
	right_portrait = {
		character = scope:comforter
		animation = personality_compassionate
		outfit_tags = { no_headgear }
		camera = camera_event_right_away_3_4
	}
	lower_center_portrait = {
		trigger = { exists = scope:deceased }
		character = scope:deceased
		animate_if_dead = yes
	}

	cooldown = { years = 10 }

	trigger = {
		has_pam_dlc_trigger = yes
		is_available = yes
		age >= 10
		any_memory = {
			pam_generic_events_0004_recent_family_death_memory_trigger = yes
		}
		OR = {
			any_relation = {
				type = friend
				is_available_ai_adult = yes
			}
			cp:councillor_court_chaplain ?= {
				is_available_ai_adult = yes
			}
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = 0.5
			any_relation = {
				type = friend
			}
		}
		modifier = {
			add = 0.25
			any_secret = {
				type = secret_murder
				secret_target = {
					is_alive = no
					OR = {
						is_close_family_of = root
						is_spouse_of_even_if_dead = root
					}
				}
			}
		}
	}

	immediate = {
		# Prefer mourning someone you secretly murdered
		if = {
			limit = {
				any_secret = {
					type = secret_murder
					secret_target ?= {
						is_alive = no
						time_since_death = { years <= 5 }
						OR = {
							is_close_family_of = root
							is_spouse_of_even_if_dead = root
						}
					}
				}
			}
			random_secret = {
				type = secret_murder
				limit = {
					secret_target = {
						is_alive = no
						time_since_death = { years <= 5 }
						OR = {
							is_close_family_of = root
							is_spouse_of_even_if_dead = root
						}
					}
				}
				save_scope_as = murder_secret
				secret_target = { save_scope_as = deceased }
			}
		}
		else_if = {
			limit = { NOT = { exists = scope:deceased } }
			random_memory = {
				limit = {
					pam_generic_events_0004_recent_family_death_memory_trigger = yes
				}
				memory_participant:dead_relation = {
					save_scope_as = deceased
				}
			}
		}
		if = {
			limit = {
				any_relation = {
					type = best_friend
					is_available_ai_adult = yes
				}
			}
			random_relation = {
				type = best_friend
				limit = { is_available_ai_adult = yes }
				save_scope_as = comforter
			}
		}
		else_if = {
			limit = {
				any_relation = {
					type = friend
					is_available_ai_adult = yes
				}
			}
			random_relation = {
				type = friend
				limit = { is_available_ai_adult = yes }
				save_scope_as = comforter
			}
		}
		else = {
			cp:councillor_court_chaplain = { save_scope_as = comforter }
		}
	}

	option = { # Confess the murder
		name = pam_generic_events.0004.a
		trigger = {
			exists = scope:murder_secret
		}
		add_internal_flag = special
		scope:murder_secret = { remove_secret = yes }
		stress_and_fulfillment_impact = {
			base = massive_stress_impact_gain
			humble = minor_stress_impact_loss
			callous = minor_stress_impact_gain
			sadistic = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_zeal = 0.5
				ai_compassion = 0.25
			}
			modifier = {
				factor = 2
				has_trait = humble
			}
			modifier = {
				factor = 0
				has_trait = callous
			}
			modifier = {
				factor = 0
				has_trait = sadistic
			}
		}
	}

	option = { # Quote scripture
		name = pam_generic_events.0004.b
		trigger = {
			OR = {
				has_trait = lifestyle_scholar
				has_trait = theologian
			}
		}
		add_scholar_trait_or_xp_effect = { VALUE = 10 }
		change_spiritual_fulfillment = minor_spiritual_fulfillment_value
		stress_and_fulfillment_impact = {
			zealous = minor_stress_impact_loss
			cynical = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = 0.5
			}
			modifier = {
				factor = 2
				has_trait = zealous
			}
			modifier = {
				factor = 0
				has_trait = cynical
			}
		}
	}

	option = { # Pray together
		name = pam_generic_events.0004.c
		trigger = {
			NOR = {
				has_trait = lifestyle_scholar
				has_trait = theologian
			}
		}
		add_piety = minor_piety_gain
		scope:comforter = {
			add_piety = minor_piety_gain
		}
		stress_and_fulfillment_impact = {
			zealous = minor_stress_impact_loss
			cynical = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = 0.5
			}
			modifier = {
				factor = 2
				has_trait = zealous
			}
			modifier = {
				factor = 0
				has_trait = cynical
			}
		}
	}

	option = { # Drink together
		name = pam_generic_events.0004.d
		stress_and_fulfillment_impact = {
			base = medium_stress_impact_loss
			drunkard = medium_stress_impact_loss
			gregarious = medium_stress_impact_loss
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_sociability = 0.25
			}
			modifier = {
				factor = 2
				has_trait = drunkard
			}
			modifier = {
				factor = 0
				has_trait = temperate
			}
		}
	}
}

# Loyal vassal offers to thrash the clerical region holder after your excommunication
scripted_trigger pam_generic_events_0005_loyal_vassal_trigger = {
	is_available_ai_adult = yes
	is_travelling = no
	opinion = {
		target = root
		value > 0
	}
	NOT = { this = root.capital_county.clerical_region_title.holder }
}

pam_generic_events.0005 = {
	type = character_event
	title = pam_generic_events.0005.t
	desc = pam_generic_events.0005.desc
	theme = christian
	override_background = { reference = council_chamber }

	left_portrait = {
		character = root
		animation = shock
	}
	right_portrait = {
		character = scope:loyal_vassal
		animation = aggressive_sword
	}
	lower_center_portrait = {
		character = scope:clerical_holder
	}

	cooldown = { years = 10 }

	trigger = {
		has_pam_dlc_trigger = yes
		is_available_adult = yes
		has_trait = excommunicated
		exists = capital_county.clerical_region_title.holder
		capital_county.clerical_region_title.holder = {
			is_ai = yes
			this != root
		}
		any_vassal = {
			pam_generic_events_0005_loyal_vassal_trigger = yes
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = 0.5
			any_vassal = {
				count >= 3
				pam_generic_events_0005_loyal_vassal_trigger = yes
			}
		}
	}

	immediate = {
		capital_county.clerical_region_title = {
			save_scope_as = clerical_region
			holder = { save_scope_as = clerical_holder }
		}
		random_vassal = {
			limit = { pam_generic_events_0005_loyal_vassal_trigger = yes }
			weight = {
				base = 1
				modifier = {
					add = 50
					opinion = {
						target = root
						value >= 50
					}
				}
			}
			save_scope_as = loyal_vassal
		}
	}

	option = { # Send them
		name = pam_generic_events.0005.a
		custom_tooltip = pam_generic_events.0005.a.tt
		scope:loyal_vassal = {
			start_travel_plan = {
				destination = scope:clerical_holder.capital_province
				return_trip = yes
				on_arrival_event = pam_generic_events.0006
				on_arrival_destinations = last
			}
		}
		stress_and_fulfillment_impact = {
			wrathful = minor_stress_impact_loss
			vengeful = minor_stress_impact_loss
			compassionate = minor_stress_impact_gain
			forgiving = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = 0.5
				ai_vengefulness = 0.5
			}
			modifier = {
				factor = 2
				has_trait = wrathful
			}
			modifier = {
				factor = 0
				has_trait = compassionate
			}
		}
	}

	option = { # Scheme instead
		name = pam_generic_events.0005.b
		custom_tooltip = pam_generic_events.0005.b.tt
		set_variable = {
			name = pam_generic_0005_murder_target
			value = scope:clerical_holder
			years = 15
		}
		stress_and_fulfillment_impact = {
			deceitful = minor_stress_impact_loss
			honest = minor_stress_impact_gain
			compassionate = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_rationality = 0.5
				ai_vengefulness = 0.25
			}
			modifier = {
				factor = 2
				has_trait = deceitful
			}
			modifier = {
				factor = 2
				intrigue >= high_skill_rating
			}
		}
	}

	option = { # Turn the other cheek
		name = pam_generic_events.0005.c
		custom_tooltip = pam_generic_events.0005.c.tt
		custom_tooltip = pam_generic_events.0005.c.tt2
		set_variable = {
			name = pam_turned_the_other_cheek_var
			years = 10
		}
		stress_and_fulfillment_impact = {
			compassionate = minor_stress_impact_loss
			humble = minor_stress_impact_loss
			forgiving = minor_stress_impact_loss
			wrathful = minor_stress_impact_gain
			vengeful = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = 0.5
				ai_zeal = 0.25
			}
			modifier = {
				factor = 2
				has_trait = compassionate
			}
			modifier = {
				factor = 2
				has_trait = humble
			}
			modifier = {
				factor = 0
				has_trait = wrathful
			}
		}
	}
}

# Letter: your vassal reports the beating
pam_generic_events.0006 = { # Needed so the event triggers for the liege
	hidden = yes
	
	trigger = {
		scope:clerical_holder = { is_alive = yes }
	}
	
	immediate = {
		save_scope_as = sender
		liege = {
			capital_county.clerical_region_title = {
				holder = { save_scope_as = clerical_holder }
			}
		}
	}
	
	option = { ai_chance = { base = 100 } }
	
	after = {
		liege = {
			trigger_event = {
				id = pam_generic_events.0007
				days = 1
			}
		}
	}
}

pam_generic_events.0007 = {
	type = letter_event
	opening = {
		desc = pam_generic_events.0007.opening
	}
	desc = pam_generic_events.0007.desc
	sender = {
		character = scope:sender
		animation = happiness
	}

	immediate = {
		scope:clerical_holder = {
			increase_wounds_no_death_effect = { REASON = fight }
		}
	}

	option = {
		name = pam_generic_events.0007.a
		add_dread = medium_dread_gain
		every_vassal = {
			limit = {
				has_vassal_stance = belligerent
			}
			custom = every_belligerent_vassal
			add_opinion = {
				modifier = impressed_opinion
				opinion = 15
				target = root
			}
		}
	}
}

# You hear the voice of god telling you how virtuous you are
pam_generic_events.0008 = {
	type = character_event
	title = pam_generic_events.0008.t
	desc = pam_generic_events.0008.desc
	theme = christian
	override_background = { reference = corridor_night }
	widgets = {
		widget = { gui = event_window_widget_vfx_background_night_scene container = foreground_shader_vfx_container }
		widget = { gui = event_window_widget_vfx_fog container = foreground_shader_vfx_container }
		widget = { gui = event_window_widget_vfx_left_character_night_scene container = foreground_shader_vfx_container }
	}

	left_portrait = {
		character = root
		animation = sick
	}

	cooldown = { years = 10 }

	trigger = {
		has_pam_dlc_trigger = yes
		is_available_adult = yes
		OR = {
			religion = religion:catholic_religion
			religion = religion:protestant_religion
			religion = religion:eastern_orthodox_religion
			religion = religion:oriental_orthodox_religion
		}
		num_virtuous_traits > 0
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = 1
			OR = {
				has_trait = possessed
				has_trait = witch
			}
		}
	}

	immediate = {
		random_character_trait = {
			limit = {
				root.rite = {
					trait_is_virtue_rite = prev
				}
			}
			save_scope_as = virtuous_trait
		}
	}

	option = { # Possessed
		name = pam_generic_events.0008.a
		trigger = {
			OR = {
				has_trait = possessed_1
				has_trait = possessed_genetic
			}
		}
		change_spiritual_fulfillment = medium_spiritual_fulfillment_value
		add_character_modifier = pam_religious_delirium_modifier
		stress_and_fulfillment_impact = {
			zealous = minor_stress_impact_loss
			cynical = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = 0.5
			}
		}
	}

	option = { # Neither possessed nor witch: believe it is God
		name = pam_generic_events.0008.b
		trigger = {
			NOR = {
				has_trait = possessed_1
				has_trait = possessed_genetic
				has_trait = witch
			}
		}
		change_spiritual_fulfillment = medium_spiritual_fulfillment_value
		if = {
			limit = { is_ai = no }
			random = {
				chance = 5
				add_trait = possessed_1
			}
		}
		stress_and_fulfillment_impact = {
			zealous = minor_stress_impact_loss
			cynical = minor_stress_impact_gain
		}
		ai_chance = {
			base = 75
			ai_value_modifier = {
				ai_zeal = 0.5
			}
			modifier = {
				factor = 2
				has_trait = zealous
			}
			modifier = {
				factor = 0
				has_trait = cynical
			}
		}
	}

	option = { # Witch
		name = pam_generic_events.0008.c
		trigger = {
			has_trait = witch
			NOR = {
				has_trait = possessed_1
				has_trait = possessed_genetic
			}
		}
		add_character_modifier = pam_religious_delirium_modifier
		random = {
			chance = 10
			add_trait = possessed_1
		}
		stress_and_fulfillment_impact = {
			zealous = minor_stress_impact_loss
			cynical = minor_stress_impact_gain
		}
		ai_chance = {
			base = 75
			ai_value_modifier = {
				ai_zeal = 0.25
			}
		}
	}

	option = { # I know exactly what this is
		name = pam_generic_events.0008.d
		trigger = { learning >= high_skill_rating }
		show_as_unavailable = {
			learning < high_skill_rating
		}
		if = {
			limit = { NOT = { has_trait = lifestyle_physician } }
			add_trait = lifestyle_physician
		}
		else = {
			add_trait_xp = {
				trait = lifestyle_physician
				value = 10
			}
		}
		stress_and_fulfillment_impact = {
			base = medium_stress_impact_loss
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 0.5
			}
		}
	}

	option = { # Speculate it was the food
		name = pam_generic_events.0008.e
		trigger = { learning < high_skill_rating }
		add_learning_lifestyle_xp = minor_lifestyle_xp
		stress_and_fulfillment_impact = {
			cynical = minor_stress_impact_loss
			zealous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_rationality = 0.25
			}
		}
	}

	option = { # Pray
		name = pam_generic_events.0008.f
		add_piety = minor_piety_gain
		stress_and_fulfillment_impact = {
			zealous = minor_stress_impact_loss
			cynical = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_zeal = 0.5
			}
			modifier = {
				factor = 2
				has_trait = zealous
			}
		}
	}
}

# Clergy member has a hellish nightmare
scripted_trigger pam_generic_events_0009_comforting_courtier_trigger = {
	is_available_ai_adult = yes
	opinion = {
		target = root
		value > 0
	}
}

pam_generic_events.0009 = {
	type = character_event
	title = pam_generic_events.0009.t
	desc = pam_generic_events.0009.desc
	theme = christian
	override_background = { reference = bedchamber }
	widgets = {
		widget = { gui = event_window_widget_vfx_background_night_scene container = foreground_shader_vfx_container }
		widget = { gui = event_window_widget_vfx_left_character_night_scene container = foreground_shader_vfx_container }
	}

	left_portrait = {
		character = root
		animation = mental_anguish
		outfit_tags = { nightgown }
	}
	
	lower_right_portrait = {
		trigger = { exists = scope:comforting_courtier }
		character = scope:comforting_courtier
	}

	cooldown = { years = 10 }

	trigger = {
		has_pam_dlc_trigger = yes
		is_available_adult = yes
		OR = {
			religion = religion:catholic_religion
			religion = religion:protestant_religion
			religion = religion:eastern_orthodox_religion
			religion = religion:oriental_orthodox_religion
		}
		pam_is_clergy_ruler_trigger = yes
		num_sinful_traits > 0
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = 0.25
			has_trait = flagellant
		}
		modifier = {
			add = 0.25
			has_trait = zealous
		}
	}

	immediate = {
		random_character_trait = {
			limit = {
				root.rite = {
					trait_is_sin_rite = prev
				}
			}
			save_scope_as = sinful_trait
		}
		if = {
			limit = {
				any_courtier = {
					pam_generic_events_0009_comforting_courtier_trigger = yes
				}
			}
			random_courtier = {
				limit = {
					pam_generic_events_0009_comforting_courtier_trigger = yes
				}
				save_scope_as = comforting_courtier
			}
		}
	}

	option = { # Already flagellant: scourge yourself
		name = pam_generic_events.0009.a
		trigger = { has_trait = flagellant }
		change_spiritual_fulfillment = medium_spiritual_fulfillment_value
		stress_and_fulfillment_impact = {
			base = minor_stress_impact_loss
			zealous = minor_stress_impact_loss
			cynical = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = 0.5
			}
		}
	}

	option = { # Not flagellant: take up the scourge
		name = pam_generic_events.0009.b
		trigger = {
			NOT = { has_trait = flagellant }
		}
		add_trait = flagellant
		change_spiritual_fulfillment = medium_spiritual_fulfillment_value
		if = {
			limit = {
				NOT = { knows_tenet = tenet_mortification_of_the_flesh }
			}
			add_known_tenet = tenet_mortification_of_the_flesh
		}
		stress_and_fulfillment_impact = {
			base = minor_stress_impact_loss
			zealous = minor_stress_impact_loss
			cynical = minor_stress_impact_gain
		}
		ai_chance = {
			base = 75
			ai_value_modifier = {
				ai_zeal = 0.5
			}
			modifier = {
				factor = 2
				has_trait = zealous
			}
			modifier = {
				factor = 0
				has_trait = cynical
			}
		}
	}

	option = { # Seek refuge in the scriptures
		name = pam_generic_events.0009.c
		trigger = { learning >= high_skill_rating }
		add_scholar_trait_or_xp_effect = { VALUE = 10 }
		stress_and_fulfillment_impact = {
			base = minor_stress_impact_gain
			zealous = minor_stress_impact_loss
			diligent = minor_stress_impact_loss
			cynical = minor_stress_impact_gain
		}
		ai_chance = {
			base = 75
			ai_value_modifier = {
				ai_zeal = 0.25
			}
			modifier = {
				factor = 2
				has_trait = lifestyle_scholar
			}
		}
	}

	option = { # Seek refuge in a friend
		name = pam_generic_events.0009.d
		trigger = { exists = scope:comforting_courtier }
		progress_towards_friend_effect = {
			CHARACTER = scope:comforting_courtier
			REASON = friend_comforted_hell_nightmare_reason
			OPINION = default_friend_opinion
		}
		stress_and_fulfillment_impact = {
			base = minor_stress_impact_gain
			gregarious = minor_stress_impact_loss
			shy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_sociability = 0.5
				ai_compassion = 0.25
			}
			modifier = {
				factor = 2
				has_trait = gregarious
			}
			modifier = {
				factor = 0
				has_trait = shy
			}
		}
	}

	option = { # Go back to sleep
		name = pam_generic_events.0009.e
		stress_and_fulfillment_impact = {
			base = minor_stress_impact_loss
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_energy = -0.25
			}
			modifier = {
				factor = 2
				has_trait = lazy
			}
		}
	}
}

# Meet a same-faith ruler hunting while travelling through their holding
scripted_trigger pam_generic_events_0010_hunting_ruler_trigger = {
	is_available_ai_adult = yes
	faith = root.faith
	location = root.location
	NOR = {
		this = root
		has_relation_rival = root
	}
}

pam_generic_events.0010 = {
	type = character_event
	title = pam_generic_events.0010.t
	desc = pam_generic_events.0010.desc
	theme = travel
	override_background = { reference = terrain }

	left_portrait = {
		character = root
		animation = contemplating
	}
	right_portrait = {
		character = scope:hunting_ruler
		animation = horse_surveying
	}

	cooldown = { years = 10 }

	trigger = {
		has_pam_dlc_trigger = yes
		is_available_travelling_adult = yes
		is_location_valid_for_travel_event_on_land = yes
		exists = location.province_owner
		location.province_owner = {
			pam_generic_events_0010_hunting_ruler_trigger = yes
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = 0.25
			has_trait = lifestyle_hunter
		}
		modifier = {
			add = 0.25
			has_trait = zealous
		}
	}

	immediate = {
		location = {
			province_owner = { save_scope_as = hunting_ruler }
		}
	}

	option = { # Pop off as a hunter
		name = pam_generic_events.0010.a
		trigger = { has_trait = lifestyle_hunter }
		add_prestige = minor_prestige_gain
		add_trait_xp = {
			trait = lifestyle_hunter
			track = hunter
			value = 10
		}
		stress_and_fulfillment_impact = {
			lifestyle_hunter = minor_stress_impact_loss
			arrogant = minor_stress_impact_loss
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 0.25
			}
		}
	}

	option = { # Praise their hunting
		name = pam_generic_events.0010.b
		duel = {
			skill = diplomacy
			target = scope:hunting_ruler
			50 = {
				desc = pam_generic_events.0010.b.success
				compare_modifier = {
					value = {
						value = scope:duel_value
						add = {
							value = "scope:hunting_ruler.opinion(root)"
							multiply = 0.25
						}
					}
					multiplier = 3.5
					min = -49
				}
				send_interface_toast = {
					type = event_toast_effect_good
					title = pam_generic_events.0010.b.toast.success
					left_icon = scope:hunting_ruler
					right_icon = root
					progress_towards_friend_effect = {
						CHARACTER = scope:hunting_ruler
						REASON = friend_praised_hunting_reason
						OPINION = default_friend_opinion
					}
					if = {
						limit = {
							scope:hunting_ruler = {
								NOT = { is_vassal_of = root }
								highest_held_title_tier >= tier_county
							}
						}
						custom_tooltip = pam_generic_events.0010.b.tt
						scope:hunting_ruler = {
							set_variable = {
								name = pam_praised_hunting_alliance_var
								value = root
								years = 10
							}
						}
					}
				}
			}
			50 = {
				desc = pam_generic_events.0010.b.failure
				compare_modifier = {
					value = {
						value = scope:duel_value
						add = {
							value = "scope:hunting_ruler.opinion(root)"
							multiply = 0.25
						}
					}
					multiplier = -3.5
					min = -49
				}
				send_interface_toast = {
					type = event_toast_effect_neutral
					title = pam_generic_events.0010.b.toast.failure
					left_icon = scope:hunting_ruler
					right_icon = root
					scope:hunting_ruler = {
						add_opinion = {
							target = root
							modifier = annoyed_opinion
							opinion = -5
						}
					}
				}
			}
		}
		stress_and_fulfillment_impact = {
			gregarious = minor_stress_impact_loss
			humble = minor_stress_impact_loss
			arrogant = minor_stress_impact_gain
		}
		ai_chance = {
			base = 75
			ai_value_modifier = {
				ai_sociability = 0.5
				ai_compassion = 0.25
			}
			modifier = {
				factor = 2
				has_trait = gregarious
			}
		}
	}

	option = { # Praise God
		name = pam_generic_events.0010.c
		add_piety = minor_piety_gain
		stress_and_fulfillment_impact = {
			zealous = minor_stress_impact_loss
			cynical = minor_stress_impact_gain
		}
		ai_chance = {
			base = 75
			ai_value_modifier = {
				ai_zeal = 0.5
			}
			modifier = {
				factor = 2
				has_trait = zealous
			}
			modifier = {
				factor = 0
				has_trait = cynical
			}
		}
	}

	option = { # Ask for an escort
		name = pam_generic_events.0010.d
		trigger = {
			current_travel_plan = {
				NOT = { has_travel_plan_modifier = travel_guide_modifier }
			}
		}
		current_travel_plan = {
			add_travel_plan_modifier = travel_guide_modifier
		}
		stress_and_fulfillment_impact = {
			greedy = minor_stress_impact_loss
			humble = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_greed = 0.25
				ai_rationality = 0.25
			}
		}
	}
}

# Scold a courtier for their sins
scripted_trigger pam_generic_events_0011_valid_sinner_trigger = {
	basic_is_available_ai = yes
	age >= 16
	this != root
	any_character_trait = {
		has_trait_category = personality
		NOT = { root = { has_trait = prev } }
		root.rite = { trait_is_sin_rite = prev }
	}
}

pam_generic_events.0011 = {
	type = character_event
	title = pam_generic_events.0011.t
	desc = pam_generic_events.0011.desc
	theme = christian
	override_background = { reference = study }

	left_portrait = {
		character = root
		triggered_animation = {
			trigger = {
				NOR = {
					has_trait = calm
					has_trait = compassionate
				}
			}
			animation = condemnation
		}
		animation = disapproval
	}
	right_portrait = {
		character = scope:sinful_courtier
		triggered_animation = {
			trigger = {
				OR = {
					has_trait = arrogant
					has_trait = wrathful
				}
			}
			animation = dismissal
		}
		animation = shame
	}

	cooldown = { years = 10 }

	trigger = {
		has_pam_dlc_trigger = yes
		is_available_adult = yes
		OR = { # Someone that'd care
			pam_is_clergy_ruler_trigger = yes
			has_trait = theologian
			has_trait = lifestyle_scholar
			has_trait = zealous
		}
		any_courtier = { pam_generic_events_0011_valid_sinner_trigger = yes }
	}

	weight_multiplier = {
		base = 1
		modifier = {
			add = 0.25
			pam_is_clergy_ruler_trigger = yes
		}
		modifier = {
			add = 0.25
			has_trait = zealous
		}
	}

	immediate = {
		if = {
			limit = {
				any_child = { pam_generic_events_0011_valid_sinner_trigger = yes }
			}
			random_child = {
				limit = { pam_generic_events_0011_valid_sinner_trigger = yes }
				save_scope_as = sinful_courtier
			}
		}
		else_if = {
			limit = {
				primary_spouse ?= { pam_generic_events_0011_valid_sinner_trigger = yes }
			}
			primary_spouse = { save_scope_as = sinful_courtier }
		}
		else_if = {
			limit = {
				any_close_family_member = {
					is_courtier_of = root
					pam_generic_events_0011_valid_sinner_trigger = yes
				}
			}
			random_close_family_member = {
				limit = {
					is_courtier_of = root
					pam_generic_events_0011_valid_sinner_trigger = yes
				}
				save_scope_as = sinful_courtier
			}
		}
		else_if = {
			limit = {
				any_councillor = { pam_generic_events_0011_valid_sinner_trigger = yes }
			}
			random_councillor = {
				limit = { pam_generic_events_0011_valid_sinner_trigger = yes }
				save_scope_as = sinful_courtier
			}
		}
		else_if = {
			limit = {
				any_court_position_holder = { pam_generic_events_0011_valid_sinner_trigger = yes }
			}
			random_court_position_holder = {
				limit = { pam_generic_events_0011_valid_sinner_trigger = yes }
				save_scope_as = sinful_courtier
			}
		}
		else = {
			random_courtier = {
				limit = { pam_generic_events_0011_valid_sinner_trigger = yes }
				save_scope_as = sinful_courtier
			}
		}
		scope:sinful_courtier = {
			random_character_trait = {
				limit = {
					has_trait_category = personality
					NOT = { root = { has_trait = prev } }
					root.rite = { trait_is_sin_rite = prev }
				}
				save_scope_as = sinful_trait
			}
			assign_quirk_effect = yes
		}
	}

	option = { # High dread: force them to flip
		name = pam_generic_events.0011.a
		trigger = { dread >= high_dread }
		scope:sinful_courtier = {
			flip_sinful_trait_effect = yes
			stress_and_fulfillment_impact = {
				base = major_stress_impact_gain
			}
		}
		progress_towards_rival_effect = {
			CHARACTER = scope:sinful_courtier
			REASON = rival_called_out_sin
			OPINION = default_rival_opinion
		}
		stress_and_fulfillment_impact = {
			sadistic = minor_stress_impact_loss
			callous = minor_stress_impact_loss
			compassionate = minor_stress_impact_gain
			forgiving = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_vengefulness = 0.5
				ai_compassion = -0.5
			}
			modifier = {
				factor = 2
				has_trait = callous
			}
			modifier = {
				factor = 0
				has_trait = compassionate
			}
		}
	}

	option = { # Learning duel: make them understand
		name = pam_generic_events.0011.b
		duel = {
			skill = learning
			target = scope:sinful_courtier
			50 = {
				desc = pam_generic_events.0011.b.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				send_interface_toast = {
					type = event_toast_effect_good
					title = pam_generic_events.0011.b.toast.success
					left_icon = scope:sinful_courtier
					right_icon = root
					change_spiritual_fulfillment = minor_spiritual_fulfillment_value
					add_scholar_trait_or_xp_effect = { VALUE = 5 }
					scope:sinful_courtier = {
						flip_sinful_trait_effect = yes
						stress_and_fulfillment_impact = {
							base = major_stress_impact_gain
						}
					}
				}
			}
			50 = {
				desc = pam_generic_events.0011.b.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				send_interface_toast = {
					type = event_toast_effect_neutral
					title = pam_generic_events.0011.b.toast.failure
					left_icon = scope:sinful_courtier
					right_icon = root
					scope:sinful_courtier = {
						add_opinion = {
							target = root
							modifier = annoyed_opinion
							opinion = -10
						}
					}
				}
			}
		}
		stress_and_fulfillment_impact = {
			zealous = minor_stress_impact_loss
			theologian = minor_stress_impact_loss
			diligent = minor_stress_impact_loss
			cynical = minor_stress_impact_gain
		}
		ai_chance = {
			base = 75
			ai_value_modifier = {
				ai_zeal = 0.35
				ai_rationality = 0.35
			}
			modifier = {
				factor = 2
				OR = {
					has_trait = lifestyle_scholar
					has_trait = theologian
				}
			}
		}
	}

	option = { # Diplomacy duel: gently change their ways
		name = pam_generic_events.0011.c
		duel = {
			skill = diplomacy
			target = scope:sinful_courtier
			50 = {
				desc = pam_generic_events.0011.c.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				send_interface_toast = {
					type = event_toast_effect_good
					title = pam_generic_events.0011.c.toast.success
					left_icon = scope:sinful_courtier
					right_icon = root
					change_spiritual_fulfillment = medium_spiritual_fulfillment_value
					scope:sinful_courtier = {
						add_opinion = {
							target = root
							modifier = pleased_opinion
							opinion = 20
						}
					}
				}
			}
			50 = {
				desc = pam_generic_events.0011.c.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				send_interface_toast = {
					type = event_toast_effect_neutral
					title = pam_generic_events.0011.c.toast.failure
					left_icon = scope:sinful_courtier
					right_icon = root
					scope:sinful_courtier = {
						add_opinion = {
							target = root
							modifier = annoyed_opinion
							opinion = -5
						}
					}
				}
			}
		}
		stress_and_fulfillment_impact = {
			gregarious = minor_stress_impact_loss
			compassionate = minor_stress_impact_loss
			shy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 75
			ai_value_modifier = {
				ai_sociability = 0.5
				ai_compassion = 0.25
			}
			modifier = {
				factor = 2
				has_trait = gregarious
			}
		}
	}

	option = { # Actually it's not that bad
		name = pam_generic_events.0011.d
		scope:sinful_courtier = {
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 15
			}
		}
		stress_and_fulfillment_impact = {
			cynical = minor_stress_impact_loss
			compassionate = minor_stress_impact_loss
			forgiving = minor_stress_impact_loss
			zealous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = 0.5
				ai_zeal = -0.5
			}
			modifier = {
				factor = 2
				OR = {
					has_trait = cynical
					has_trait = forgiving
				}
			}
			modifier = {
				factor = 0
				has_trait = zealous
			}
		}
	}
}
